Simplify your webhook distribution infrastructure to a single line of code.
Installation and guides are available in the docs
- Install from npm:
npm install --save webhooker-client - Require the module and create a client:
const Webhooker = require('webhooker-client')
const client = Webhooker.withKey('My Key')- Send a message to your subscribers:
client.send({
tenant: 'account.1',
type: 'task.created',
payloads: {
json: { id: 123, name: 'foo' },
},
})- WebhookerClient
The API client used to send requests to the webhooker api
- Config
- Message
Represents a message sent within the Webhooker system
- SignedMessage ⇐ `Message`
Represents a message within the webhooker system that should generate signatures when sending to the API
- WebhookerCallback : function
The callback provided to methods that utilise the Webhooker api. When a WebhookerCallback is accepted, it can instead be omitted to cause the called function to return a Promise
- MessageObject : Object
An easily constructed version of the MessagePayload object using a js-native naming scheme for payloads, as compared to the request body names. This type will usually be the one accepted by the public API, and MessagePayload will usually be the type used internally
- MessagePayload : Object
The body parameters for a WebhookerClient send request
- TenantKey : string
The non-unique user specified identifier for a single subsciption endpoint. Multiple subscriptions can have the same tenant key, and a request will be sent to all subscriptions that have tenant keys matching the one specified with the API request
The API client used to send requests to the webhooker api
Kind: global class
- WebhookerClient
- new WebhookerClient(config)
- instance
- .send(message, [callback]) ⇒ Promise
- static
Create a new Webhooker client.
| Param | Type | Description |
|---|---|---|
| config | Config |
A config object that provides API information to the client. Can be used to customise the domain, in case it differs from the standard webhooker api |
Send a message payload to Webhooker, which will then send the payload to the matching subscribers
Kind: instance method of WebhookerClient
Returns: Promise - A promise that will resolve when the request has
completed. If there was an error, the promise will be rejected.
Otherwise it will be resolved with the server response. Only returned
when callback is null or undefined
| Param | Type | Description |
|---|---|---|
| message | Message / MessageObject |
|
| [callback] | WebhookerCallback |
A callback that will be triggered when the request has completed. If this is omitted, the function will instead return a promise |
Create a new Webhooker client with default parameters and the specified api key
Kind: static method of WebhookerClient
| Param | Type |
|---|---|
| apiKey | string |
Kind: global class
Create a new configuration object
| Param | Type | Description |
|---|---|---|
| apiKey | string | The api key to send with webhooker requests |
| domain | string | The domain name to send webhooker requests to |
Create a new configuration object with the default webhooker domain
Kind: static method of Config
| Param | Type | Description |
|---|---|---|
| apiKey | string | The api key to send with webhooker requests |
Represents a message sent within the Webhooker system
Kind: global class
- Message
- new Message(id, tenant, type, payloads, [signatureType])
- instance
- .id(id) ⇒
Message - .tenant(tenant) ⇒
Message - .type(type) ⇒
Message - .json(json) ⇒
Message - .xml(xml) ⇒
Message - .isSent() ⇒ boolean
- .toPayload() ⇒
MessagePayload
- .id(id) ⇒
- static
Create a new message
| Param | Type | Default | Description |
|---|---|---|---|
| id | string / null | The message identifier. Can be null for unsent messages | |
| tenant | TenantKey |
The tenant key that will be used to filter this message | |
| type | string | The event name/type that this message will be sent as | |
| payloads | Object | An object containing the payloads to send | |
| [payloads.json] | string / Object / Array | The string encoded json body, or an object to be serialised | |
| [payloads.xml] | string | The string encoded xml body | |
| [signatureType] | string / false | "'SHA256'" |
message.id(id) ⇒ Message
Fluently set the id of the message instance
Kind: instance method of Message
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| id | string / null | The identifier of this message within the Webhooker system. This method should generally not be used outside of the SDK, but may prove useful for hydrating a serialised Message instance |
message.tenant(tenant) ⇒ Message
Fluently set the tenant key of the message instance
Kind: instance method of Message
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| tenant | TenantKey |
The user defined subscription identifier that that this message will be sent to |
message.type(type) ⇒ Message
Fluently set the type of the message instance
Kind: instance method of Message
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| type | string | The event name that will be sent with this message (e.g. task.created or my-system-notification) |
message.json(json) ⇒ Message
Fluently set the JSON payload of the message instance
Kind: instance method of Message
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| json | string / Object / Array | A JSON compatible payload to be sent. This can either be something that will stringify (Object or Array) or it can be a pre-stringified payload. |
message.xml(xml) ⇒ Message
Fluently set the XML payload of the message instance
Kind: instance method of Message
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| xml | string | An XML string taht will be sent as the payload of this message |
Check to see if this message has been succesfully sent
Kind: instance method of Message
Returns: boolean - whether or not this message has been sent, as
indicated by the existence of an ID. If an ID has been manually set on
an unsent message, this method will falsly report that the message has
been sent - only sent messages should have an ID
message.toPayload() ⇒ MessagePayload
Turns this message into a raw payload object that can be used as the body of a WebhookClient send request
Kind: instance method of Message
Returns: MessagePayload - The formatted payload that conforms to the
Webhooker HTTP api spec
The key used for the stringified XML body in the request payload
Kind: static property of Message
The key used for the stringified JSON body in the request payload
Kind: static property of Message
Message.from(params) ⇒ Message
Hydrate a new unsent message from the provided portable object
Kind: static method of Message
Returns: Message - The Message instance that represents the provided object
| Param | Type | Description |
|---|---|---|
| params | MessageObject |
The basic object containing message parameters |
Message.builder() ⇒ Message
Create a new blank Message as a builder interface. The message will have no defaults set, and by default will not create signatures
Kind: static method of Message
Returns: Message - A blank message with no properties. Will not pass
validation by default unless values are set on it
SignedMessage ⇐ Message
Represents a message within the webhooker system that should generate signatures when sending to the API
Kind: global class
Extends: Message
- SignedMessage ⇐
Message- new SignedMessage(id, tenant, type, payloads, [signingKey], [signingAlgo])
- .signingKey(signingKey) ⇒
SignedMessage - .signingHash(signingAlgo) ⇒
SignedMessage - .toPayload() ⇒
MessagePayload - .id(id) ⇒
Message - .tenant(tenant) ⇒
Message - .type(type) ⇒
Message - .json(json) ⇒
Message - .xml(xml) ⇒
Message - .isSent() ⇒ boolean
Create a new SignedMessage
| Param | Type | Default | Description |
|---|---|---|---|
| id | int / null | The message identifier. Can be null for unsent messages | |
| tenant | TenantKey |
The tenant key that will be used to filter this message | |
| type | string | The event name/type that this message will be sent as | |
| payloads | Object | An object containing the payloads to send | |
| [payloads.json] | string / Object / Array | The string encoded json body, or an object to be serialised | |
| [payloads.xml] | string | The string encoded xml body | |
| [signingKey] | string | The key used to sign the payloads. This should be something known to the recipient so that they can verify that the payload has not been tampered with. It is recommended that this value is also not related to your Webhooker account in any way | |
| [signingAlgo] | string | "sha256" |
The algorithm to use when creating message signatures. Will default to a sha-256 signature. If an explicit false is passed as this parameter, no signatures will be created |
signedMessage.signingKey(signingKey) ⇒ SignedMessage
Fluently set the key used to sign the request payloads
Kind: instance method of SignedMessage
Returns: SignedMessage - This message instance
| Param | Type | Description |
|---|---|---|
| signingKey | string | The key used to sign request payloads. It is recommended that this value is also not related to your Webhooker account in any way |
signedMessage.signingHash(signingAlgo) ⇒ SignedMessage
Fluently set the algorithm used to sign the request payloads
Kind: instance method of SignedMessage
Returns: SignedMessage - This message instance
| Param | Type | Description |
|---|---|---|
| signingAlgo | string | The algorithm used to create the HMAC signature. It should be a value found in crypto.getHashes() |
signedMessage.toPayload() ⇒ MessagePayload
Turns this message into a raw payload object that can be used as the body of a WebhookClient send request. Signatures will be generated for the json and xml payloads when present.
Kind: instance method of SignedMessage
Overrides: toPayload
Returns: MessagePayload - The formatted payload that conforms to the
Webhooker HTTP api spec
signedMessage.id(id) ⇒ Message
Fluently set the id of the message instance
Kind: instance method of SignedMessage
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| id | string / null | The identifier of this message within the Webhooker system. This method should generally not be used outside of the SDK, but may prove useful for hydrating a serialised Message instance |
signedMessage.tenant(tenant) ⇒ Message
Fluently set the tenant key of the message instance
Kind: instance method of SignedMessage
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| tenant | TenantKey |
The user defined subscription identifier that that this message will be sent to |
signedMessage.type(type) ⇒ Message
Fluently set the type of the message instance
Kind: instance method of SignedMessage
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| type | string | The event name that will be sent with this message (e.g. task.created or my-system-notification) |
signedMessage.json(json) ⇒ Message
Fluently set the JSON payload of the message instance
Kind: instance method of SignedMessage
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| json | string / Object / Array | A JSON compatible payload to be sent. This can either be something that will stringify (Object or Array) or it can be a pre-stringified payload. |
signedMessage.xml(xml) ⇒ Message
Fluently set the XML payload of the message instance
Kind: instance method of SignedMessage
Returns: Message - This message instance
| Param | Type | Description |
|---|---|---|
| xml | string | An XML string taht will be sent as the payload of this message |
Check to see if this message has been succesfully sent
Kind: instance method of SignedMessage
Returns: boolean - whether or not this message has been sent, as
indicated by the existence of an ID. If an ID has been manually set on
an unsent message, this method will falsly report that the message has
been sent - only sent messages should have an ID
The callback provided to methods that utilise the Webhooker api. When a WebhookerCallback is accepted, it can instead be omitted to cause the called function to return a Promise
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| err | Error | If there was an error, this value will be the corresponding error object. Otherwise, it will be nul |
| response | Object | The api response from webhooker. This will contain different information depending on the request being made |
An easily constructed version of the MessagePayload object using a js-native naming scheme for payloads, as compared to the request body names. This type will usually be the one accepted by the public API, and MessagePayload will usually be the type used internally
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| tenant | TenantKey |
The tenant key that will be used to filter this message |
| type | string | The event name that the message will be sent as (e.g. task.created) |
| payload | Object | A map of webhook message payload types to their respective stringified contents |
| payload.json | string | A string encoded json payload |
| payload.xml | string | A string encoded xml payload |
The body parameters for a WebhookerClient send request
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| tenant | TenantKey |
The tenant key that will be used to filter this message |
| type | string | The event name that the message will be sent as (e.g. task.created) |
| payload | Object | A mapping of MIME type to serialised payload. Valid MIME types include application/json and application/xml |
| payload.application/json | string | A string encoded json payload |
| payload.application/xml | string | A string encoded xml payload |
The non-unique user specified identifier for a single subsciption endpoint. Multiple subscriptions can have the same tenant key, and a request will be sent to all subscriptions that have tenant keys matching the one specified with the API request
Kind: global typedef