Storeware Docs

Webhook router

Verify, finish installs and dispatch deliveries by topic.

import { ... } from '@storeware/plugin-sdk';

createWebhookRouter

function createWebhookRouter(options: { secret: SecretSource; onInstallGrant?: (install: { grant: string; installationId: string | null; storeId: string | null; }) => Promise<string>; before?: EventHandler; toleranceSeconds?: number; }): WebhookRouter

EventHandler

type EventHandler<T = unknown> = (event: StorewareEvent<T>) => void | Promise<void>;

DeliveryAddress

Which installation a delivery is for, read before it is verified.

NameTypeDescription
storeIdstring | null
installationIdstring | nullPresent on events about your app (app.*), absent on shop events.
namedInstallationId?string | nullThe installation the storeware-installation header names, which Storeware sends on every delivery. Not signed: naming the wrong one only picks a secret that fails.

SecretSource

Where the webhook secret comes from. One string for an app in one shop; otherwise a lookup by shop, because every installation has its own secret. Return nothing for a shop you hold no secret for.

type SecretSource = string | ((address: DeliveryAddress) => string | null | undefined | Promise<string | null | undefined>);

WebhookRouter

NameTypeDescription
on<T = unknown>(topic: string, handler: EventHandler<T>) => WebhookRouterHandles one topic, such as order.paid.v1.
onLifecycle(handler: EventHandler) => WebhookRouterHandles app.installed.v1, app.uninstalled.v1 and the other events about your app.
onCompliance(handler: EventHandler) => WebhookRouterHandles the requests the law obliges you to act on: a customer's data asked for, a customer erased, a shop's data to delete. Sent to [privacy] url when your manifest declares one.
onBilling(handler: EventHandler) => WebhookRouterHandles what happens to what a shop pays you: a plan approved, changed, declined or ended (app_subscription.*), a one-time charge accepted or declined (app_purchase.*), a period's usage near or at its cap (app_usage.*).
handle(request: Request) => Promise<Response>Verifies and dispatches one request. Works with any fetch-style server.

On this page