Class: WebHookDispatcher

WebHookDispatcher(endpointsByEvent, optionsopt)

Lightweight webhook dispatcher that posts JSON payloads to configured URLs.

Constructor

new WebHookDispatcher(endpointsByEvent, optionsopt)

Parameters:
Name Type Attributes Description
endpointsByEvent Object.<string, Array.<string>>

Mapping of event names to arrays of webhook URLs.

options Object <optional>
Properties
Name Type Attributes Description
fetch function <optional>

override for fetch (defaults to globalThis.fetch)

timeoutMs number <optional>

request timeout in milliseconds

Source:

Methods

(async) trigger(eventName, payload, headersopt) → {Promise.<{event: string, deliveries: Array.<{url: string, ok: boolean, status: (number|undefined), error: (string|undefined)}>}>}

Trigger a webhook event and POST the payload to all configured URLs.

Parameters:
Name Type Attributes Description
eventName string

The webhook event identifier.

payload Object

Payload to serialise as JSON.

headers Object <optional>

Additional HTTP headers for the request.

Source:
Returns:

Summary of delivery attempts (always resolves, never rejects).

Type
Promise.<{event: string, deliveries: Array.<{url: string, ok: boolean, status: (number|undefined), error: (string|undefined)}>}>