Karta.Webhooks.Format (Karta v1.0.0)

The formats of webhook requests. A webhook's format is chosen when it is added and does not change; it decides the body, the headers and the signature of every request, and which event types the webhook can receive. Events, deliveries, retries, dead letters and replays are the same in every format.

  • :standard - Karta's own payload (Karta.Webhooks.Payload), signed as Standard Webhooks (Karta.Webhooks.Signature) with the webhook's whsec_ secret. Every event type.
  • :mailgun - Mailgun's webhook payload (Karta.Webhooks.Mailgun): signature and event-data, signed with the webhook's signing key.
  • :postal - Postal's webhook payload (Karta.Webhooks.Postal): event, timestamp, payload and uuid, signed with the key of the webhook's organisation (Karta.Webhooks.PostalKey); the webhook has no secret.
  • :sendgrid - SendGrid's Event Webhook (Karta.Webhooks.Sendgrid): an array of one event, signed with the webhook's ECDSA key pair; the private key is never shown, the public key always is (public_key/1).
  • :postmark - Postmark's webhooks (Karta.Webhooks.Postmark): one object per event by RecordType, not signed (a user name and password in the URL authenticate Karta); the webhook has no secret.

webhook.test (send_test) is sent in every format.

Summary

Functions

The formats, the default first.

A new secret for a webhook in this format: whsec_ and base64 for Standard Webhooks, 64 hexadecimal digits for Mailgun's signing key, an ECDSA private key (PEM) for SendGrid's; none for Postal's format, which the organisation's key signs, nor for Postmark's, which is not signed.

What the pages offer to choose from: subscribable_types/1, the messaging events only while the module is on.

True when the previous secret signs too for a while after a rotation; Mailgun's and SendGrid's requests have room for one signature only.

The body of the delivery's requests as far as it is the same in every request: Mailgun's signature is made for each request and left out.

The public key receivers verify the webhook's requests with, or nil (SendGrid's format only).

True when a webhook in this format receives events of this type (the test event included).

The headers and body of a request about the delivery's event (preloaded) to the webhook, made at now.

True when webhooks in this format have a secret of their own (that can be rotated).

True when the secret is shown (once, when it is made) to the webhook's owners: not SendGrid's private key, whose public key they get instead.

The event types a webhook in this format may name: types/1, and for Karta's own format, while the messaging module is on, the messaging events too (Karta.Webhooks.Catalogue.messaging_types/0), which a webhook receives only when it names them. With the module off they are not accepted.

The event types a webhook in this format can receive.

Functions

formats()

@spec formats() :: [atom()]

The formats, the default first.

new_secret(atom)

@spec new_secret(atom()) :: String.t() | nil

A new secret for a webhook in this format: whsec_ and base64 for Standard Webhooks, 64 hexadecimal digits for Mailgun's signing key, an ECDSA private key (PEM) for SendGrid's; none for Postal's format, which the organisation's key signs, nor for Postmark's, which is not signed.

offered_types(format)

@spec offered_types(atom()) :: [String.t()]

What the pages offer to choose from: subscribable_types/1, the messaging events only while the module is on.

overlap?(format)

@spec overlap?(atom()) :: boolean()

True when the previous secret signs too for a while after a rotation; Mailgun's and SendGrid's requests have room for one signature only.

preview(webhook, d)

The body of the delivery's requests as far as it is the same in every request: Mailgun's signature is made for each request and left out.

public_key(webhook)

@spec public_key(Karta.Webhooks.Webhook.t()) :: String.t() | nil

The public key receivers verify the webhook's requests with, or nil (SendGrid's format only).

renders?(format, type)

@spec renders?(atom(), String.t()) :: boolean()

True when a webhook in this format receives events of this type (the test event included).

request(webhook, delivery, now)

The headers and body of a request about the delivery's event (preloaded) to the webhook, made at now.

secret?(format)

@spec secret?(atom()) :: boolean()

True when webhooks in this format have a secret of their own (that can be rotated).

shows_secret?(format)

@spec shows_secret?(atom()) :: boolean()

True when the secret is shown (once, when it is made) to the webhook's owners: not SendGrid's private key, whose public key they get instead.

subscribable_types(format)

@spec subscribable_types(atom()) :: [String.t()]

The event types a webhook in this format may name: types/1, and for Karta's own format, while the messaging module is on, the messaging events too (Karta.Webhooks.Catalogue.messaging_types/0), which a webhook receives only when it names them. With the module off they are not accepted.

types(atom)

@spec types(atom()) :: [String.t()]

The event types a webhook in this format can receive.