@samva/webhooks 0.13.0 → 0.15.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.
@@ -1,3 +1,6 @@
1
+ import type { WebhookEvent } from "./types.gen.js";
2
+ export { isKnownEvent } from "./decoder.gen.js";
3
+ export type { SamvaWebhookEvent, WebhookEvent, UnknownWebhookEvent } from "./types.gen.js";
1
4
  /**
2
5
  * Header carrying the delivery's unique message ID. Retries of the same delivery reuse it, so it
3
6
  * is the key for deduplicating deliveries you have already handled.
@@ -17,15 +20,6 @@ export declare const WEBHOOK_SIGNATURE_HEADER = "webhook-signature";
17
20
  * rejected with {@link WebhookTimestampError}.
18
21
  */
19
22
  export declare const DEFAULT_TOLERANCE_SECONDS = 300;
20
- /** The event envelope carried in a verified delivery's body. */
21
- export interface SamvaWebhookEvent {
22
- /** Event type, such as `message.delivered`. Branch on it before reading `data`. */
23
- readonly type: string;
24
- /** When the event occurred, as an ISO 8601 string. Distinct from the delivery's signing time. */
25
- readonly timestamp: string;
26
- /** Event-specific payload. Its shape depends on `type`; validate it before use. */
27
- readonly data: unknown;
28
- }
29
23
  /** A delivery whose signature, timestamp, and envelope all checked out. */
30
24
  export interface VerifiedWebhook {
31
25
  /**
@@ -34,7 +28,7 @@ export interface VerifiedWebhook {
34
28
  * replay tolerance.
35
29
  */
36
30
  readonly id: string;
37
- readonly event: SamvaWebhookEvent;
31
+ readonly event: WebhookEvent;
38
32
  }
39
33
  /** The three signing headers of a delivery, each present and non-empty, read verbatim. */
40
34
  export interface WebhookHeaders {
@@ -117,7 +111,8 @@ export declare const signWebhook: (input: {
117
111
  *
118
112
  * Checks, in order: all three headers are present and non-empty; the timestamp is integer Unix seconds within
119
113
  * `toleranceSeconds` of `nowMilliseconds`; some `v1` entry in the signature header matches, using
120
- * a constant-time comparison; the body is a Samva event envelope. The replay window rejects stale
114
+ * a constant-time comparison; the body has a valid envelope and known event payloads match their schema. Unknown event types pass
115
+ * through with untyped data. The replay window rejects stale
121
116
  * deliveries but does not detect a repeat inside it; deduplicate on the returned `id`.
122
117
  *
123
118
  * Rejects with {@link InvalidWebhookHeadersError}, {@link WebhookTimestampError},
package/dist/protocol.js CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as WebhookTimestampError, a as encodeWebhookSignature, c as signWebhook, d as webhookSignedContent, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, s as readWebhookHeaders, t as DEFAULT_TOLERANCE_SECONDS, u as verifyWebhookAtWithPublicKeys, v as WebhookVerificationError } from "./protocol-BGKUmvlI.js";
2
- export { DEFAULT_TOLERANCE_SECONDS, InvalidWebhookHeadersError, InvalidWebhookSecretError, MalformedWebhookPayloadError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCryptoError, WebhookSignatureError, WebhookTimestampError, WebhookVerificationError, encodeWebhookSignature, generateWebhookSecret, readWebhookHeaders, signWebhook, verifyWebhookAt, verifyWebhookAtWithPublicKeys, webhookSignedContent };
1
+ import { _ as WebhookTimestampError, a as encodeWebhookSignature, c as signWebhook, d as webhookSignedContent, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, s as readWebhookHeaders, t as DEFAULT_TOLERANCE_SECONDS, u as verifyWebhookAtWithPublicKeys, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-CLrYczjc.js";
2
+ export { DEFAULT_TOLERANCE_SECONDS, InvalidWebhookHeadersError, InvalidWebhookSecretError, MalformedWebhookPayloadError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCryptoError, WebhookSignatureError, WebhookTimestampError, WebhookVerificationError, encodeWebhookSignature, generateWebhookSecret, isKnownEvent, readWebhookHeaders, signWebhook, verifyWebhookAt, verifyWebhookAtWithPublicKeys, webhookSignedContent };