Options
All
  • Public
  • Public/Protected
  • All
Menu
description

Abstraction layer for webhooks that are executed from third-party data providers. This class contains methods to validate, process and format activities that are completed remotely, e.g. in Strava.

Note that this draft implementation is only compatible with Strava activities and a further iteration shall abstract out the events handling using OAuth Drivers.

since

v0.3.2

Hierarchy

  • WebHooksService

Index

Constructors

Properties

activitiesService: ActivitiesService
oauthService: OAuthService

Methods

  • This method handles incoming events from third-party data providers such as Strava or Apple Health.

    After a successful execution of processing an incoming event, this method will fire an internal event with the identifier: oauth.activity.created. This event can be caught to use the fulfilled (completed) activity details in other places.

    access

    public

    async

    Parameters

    • providerName: string

      The OAuth provider name. This is the name of the third-party data provider, e.g. "strava".

    • userAddress: string

      The dHealth Address of the account that belongs to the activity owner.

    • data: BasicWebHookEventRequest

      The activity's headers. Importantly, Strava does not share full activity details here.

    Returns Promise<ActivityDocument>

    The created document that was added to activities.

  • This method serves as an event listener for the internal event with identifier oauth.activity.created. The main purpose of this listener is to request activity details from a data provider.

    An example activity detail DTO can be found on the Strava documentation: https://developers.strava.com/docs/reference/#api-Activities-getActivityById

    Note that we do not store all fields that are returned by the /activities/:id endpoint. More fields may be interpreted in the future.

    Note that event listeners do not specify a return type. This is because their execution is asynchronous.

    access

    public

    async
    emits

    OnActivityDownloaded Given a successful activity details download from data provider (downloading success).

    throws

    {Error} Given missing OAuth authorization, unreachable/invalid Strava request or any other error occurs while requesting activity details.

    Parameters

    Returns Promise<void>

    No return is specified for an event listener to permit asynchronous behaviour.

  • Helper method that executes error handling. It prints the error message in the logs and updates the activities document's processingState field to ProcessingState.Failed.

    access

    private

    async

    Parameters

    • logger: LogService

      A logger instance to use only one and the same.

    • activity: ActivityDocument

      The activity that produced an error.

    • message: string

      The error message.

    • Optional stack: string

      (Optional) An optional error stack trace.

    Returns Promise<void>

Generated using TypeDoc