Docs@skmtc/core

Webhooks

FUNCTION

toWebhookEntry

@skmtc/core 0.63.4

Creates a configured webhook generator entry.

Sibling of toOasOperationEntry for the OpenAPI 3.1 webhook subject. Webhooks have inverted semantics (handler/receiver, not client call), so they are a distinct subject - never routed through an operation generator. The enrichment routing is [id][name][method][variant], mirroring the operation [id][path][method][variant] with the webhook name in the path slot.

Signature

import { toWebhookEntry } from '@skmtc/core'

toWebhookEntry<EnrichmentType = undefined>(
  args: ToWebhookConfigArgs<EnrichmentType>
): WebhookEntry<EnrichmentType>

Parameters

args, ToWebhookConfigArgs<EnrichmentType> required
id, string required
projections, readonly DeclaredProjection[]

Every projection class this generator can insert: its own, and each one of another generator that it inserts. Core reads only their statics. See DeclaredProjection. Optional.

transform, (args: TransformWebhookArgs) => void required
toEnrichmentSchema, () => v.GenericSchema<EnrichmentType> required
isSupported, (args: IsSupportedWebhookArgs) => boolean
supportsVariant, () => boolean

Optional: whether this generator entry supports variants. Defaults to a function returning false when omitted.

toPreviewModule, (args: ToWebhookPreviewModuleArgs) => PreviewModule
toEnrichmentRequest, <RequestedEnrichment extends EnrichmentType>(webhook: OasWebhook) => EnrichmentRequest<RequestedEnrichment> | undefined
toEnrichmentDefaults, (args: ToWebhookEnrichmentsArgs) => EnrichmentType | undefined
Basic webhook entry
import { toWebhookEntry } from '@skmtc/core';

const webhookEntry = toWebhookEntry({
  id: 'webhook-handlers',
  transform: ({ context, webhook }) => {
    context.insertWebhook({ projection: MyHandler, webhook });
  }
});

Returns

WebhookEntry<EnrichmentType>