@voltro/plugin-webhooks 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/errors.d.ts CHANGED
@@ -18,7 +18,7 @@ declare const WebhookDeliveryNotFound_base: Schema.TaggedErrorClass<WebhookDeliv
18
18
  /**
19
19
  * Thrown by `WebhooksService.emit` when the payload does not decode
20
20
  * against the outgoing event's declared `payload` schema (from its
21
- * `defineOutgoingEvent` descriptor). The emit is rejected BEFORE any
21
+ * declared event's `webhook:` block). The emit is rejected BEFORE any
22
22
  * delivery row is written or workflow triggered — a schema-violating
23
23
  * payload never reaches a subscriber.
24
24
  */
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ import { ColumnDefinition } from '@voltro/database';
4
4
  import { Context } from 'effect';
5
5
  import { DataStore } from '@voltro/database';
6
6
  import { Effect } from 'effect';
7
+ import { EventDescriptor } from '@voltro/protocol';
8
+ import { EventWebhookSpec } from '@voltro/protocol';
7
9
  import { FieldDefinitions } from '@voltro/database';
8
10
  import { Schema } from 'effect';
9
11
  import { Table } from '@voltro/database';
@@ -23,6 +25,24 @@ import { WorkflowInstance } from '@effect/workflow/WorkflowEngine';
23
25
  */
24
26
  export declare const acquireRateSlots: (store: DataStore, scopes: ReadonlyArray<RateScope>, now: number, windowMs?: number) => Promise<RateAcquireResult>;
25
27
 
28
+ /**
29
+ * Project a declared event onto the outgoing-event descriptor this plugin
30
+ * already understands.
31
+ *
32
+ * A projection rather than a second registry: every downstream consumer —
33
+ * the delivery workflow, the JSON-Schema export, the dashboard's event list —
34
+ * keeps reading ONE shape. Adding a parallel path for declared events would
35
+ * mean each of them handles two, which is how the two drift.
36
+ *
37
+ * The event's `name` becomes the webhook `id`, so a subscriber that registered
38
+ * for `orders.paid` keeps working across the migration and the dashboard shows
39
+ * one event rather than two spellings of it.
40
+ */
41
+ export declare const asOutgoingEvent: <Name extends string, Key, Payload>(descriptor: EventDescriptor<Name, never, never> & {
42
+ readonly payload: unknown;
43
+ readonly webhook?: EventWebhookSpec | undefined;
44
+ }) => OutgoingEventDescriptor<Payload> | undefined;
45
+
26
46
  /** What `recordDeliveryOutcome` did — surfaced so the workflow can log
27
47
  * the auto-disable transition. */
28
48
  export declare interface AutoDisableOutcome {
@@ -82,6 +102,22 @@ export declare interface CustomSignatureScheme {
82
102
  readonly verify: (rawBody: Uint8Array, secret: string, signatureHeader: string) => boolean;
83
103
  }
84
104
 
105
+ /** The structural slice of a `defineEvent` descriptor this plugin needs.
106
+ * Structural rather than an import so the plugin does not depend on a specific
107
+ * protocol version's class identity. */
108
+ export declare interface DeclaredEventLike {
109
+ readonly kind: 'event';
110
+ readonly name: string;
111
+ readonly payload: unknown;
112
+ readonly webhook?: {
113
+ readonly description?: string;
114
+ readonly version?: number;
115
+ readonly rateLimit?: {
116
+ readonly perMinute: number;
117
+ };
118
+ } | undefined;
119
+ }
120
+
85
121
  /** Default URL path for an incoming webhook when the descriptor
86
122
  * doesn't override. Stage 4's discovery walker uses this to
87
123
  * register routes. */
@@ -97,8 +133,6 @@ export declare const defaultRetryPolicy: () => RetryPolicy;
97
133
 
98
134
  export declare const defineIncomingWebhook: <Body>(spec: Omit<IncomingWebhookDescriptor<Body>, "_tag">) => IncomingWebhookDescriptor<Body>;
99
135
 
100
- export declare const defineOutgoingEvent: <Payload>(spec: Omit<OutgoingEventDescriptor<Payload>, "_tag">) => OutgoingEventDescriptor<Payload>;
101
-
102
136
  export declare const defineWebhookProvider: (spec: Omit<WebhookProviderDescriptor, "_tag">) => WebhookProviderDescriptor;
103
137
 
104
138
  /**
@@ -125,7 +159,8 @@ export declare const deliverWebhookWorkflow: Workflow.Workflow<"voltro.deliverWe
125
159
  }>, typeof Schema.Never>;
126
160
 
127
161
  declare interface DeliverWorkflowOptions {
128
- /** Discovered `defineOutgoingEvent` descriptors the workflow reads
162
+ /** Discovered outgoing events (declared events with a `webhook:` block,
163
+ * projected by `asOutgoingEvent`) — the workflow reads
129
164
  * the emitted event's `globalRateLimit` from here. Absent events
130
165
  * simply have no global limit. */
131
166
  readonly events?: ReadonlyArray<OutgoingEventDescriptor<unknown>>;
@@ -176,6 +211,11 @@ export declare const getIdempotencyCache: () => IdempotencyCache;
176
211
  /** GitHub-style: `X-Hub-Signature-256: sha256=hex` (no timestamp). */
177
212
  export declare const githubSignature: () => HmacSignatureScheme;
178
213
 
214
+ /** Does this declared event opt into outbound HTTP delivery? */
215
+ export declare const hasWebhookAudience: (descriptor: {
216
+ readonly webhook?: EventWebhookSpec | undefined;
217
+ }) => boolean;
218
+
179
219
  export declare type HmacAlgorithm = 'hmacSha256' | 'hmacSha1';
180
220
 
181
221
  export declare interface HmacSignatureScheme {
@@ -478,7 +518,7 @@ export declare const releaseRateSlot: (store: DataStore, key: string, bucket: nu
478
518
  * Default resolution is three-tiered: the subscriber's explicit
479
519
  * value wins, then the event descriptor's per-event defaults
480
520
  * (`defaultSigning` / `defaultRetry` / `version` from
481
- * `defineOutgoingEvent`), then the package-global defaults. */
521
+ * the declared event's `webhook:` block), then the package-global defaults. */
482
522
  export declare const resolveSubscribe: (input: SubscribeInput, event?: OutgoingEventDescriptor<unknown>) => {
483
523
  readonly id: string;
484
524
  readonly event: string;
@@ -868,7 +908,7 @@ export declare type WebhookId = string;
868
908
  /**
869
909
  * Thrown by `WebhooksService.emit` when the payload does not decode
870
910
  * against the outgoing event's declared `payload` schema (from its
871
- * `defineOutgoingEvent` descriptor). The emit is rejected BEFORE any
911
+ * declared event's `webhook:` block). The emit is rejected BEFORE any
872
912
  * delivery row is written or workflow triggered — a schema-violating
873
913
  * payload never reaches a subscriber.
874
914
  */
@@ -940,7 +980,7 @@ export declare class WebhooksService extends WebhooksService_base {
940
980
  declare const WebhooksService_base: Context.TagClass<WebhooksService, "@voltro/webhooks/WebhooksService", WebhooksServiceShape>;
941
981
 
942
982
  export declare interface WebhooksServiceOptions {
943
- /** Discovered `defineOutgoingEvent` descriptors. When present,
983
+ /** Discovered outgoing events (projected from declared events). When present,
944
984
  * `subscribe` resolves the event's `defaultSigning` /
945
985
  * `defaultRetry` / `version` before the package-global defaults,
946
986
  * and `emit` decodes the payload against the event's schema. */
@@ -950,13 +990,13 @@ export declare interface WebhooksServiceOptions {
950
990
  export declare interface WebhooksServiceShape {
951
991
  readonly subscribe: (input: SubscribeInput) => Promise<SubscribeResult>;
952
992
  /** Emit an event to every subscribed target. Accepts the event id
953
- * OR the `defineOutgoingEvent` descriptor itself — passing the
993
+ * OR the declared event itself — passing the
954
994
  * descriptor types `payload` against its schema at the call site.
955
995
  * Either way, when the descriptor is known (directly or via the
956
996
  * discovered-events registry) the payload is DECODED against its
957
997
  * schema and a mismatch throws `WebhookPayloadInvalid` before any
958
998
  * delivery is created. */
959
- readonly emit: <P>(event: string | OutgoingEventDescriptor<P>, payload: P) => Promise<EmitResult>;
999
+ readonly emit: <P>(event: string | OutgoingEventDescriptor<P> | DeclaredEventLike, payload: P) => Promise<EmitResult>;
960
1000
  /** Manual re-trigger for the dashboard's "Replay" button on a
961
1001
  * failed delivery row. Re-runs the workflow at attempt 1 with
962
1002
  * the original payload. */