@samva/webhooks 0.29.1 → 0.31.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/AGENTS.md +1 -1
- package/README.md +8 -6
- package/dist/effect.js +3 -4
- package/dist/{json-schemas.gen-kztbWC65.js → json-schemas.gen-Bqz0To0S.js} +2 -3
- package/dist/promise.js +3 -4
- package/dist/{protocol-D6Od0Usw.js → protocol-Dxbwh-ml.js} +4 -7
- package/dist/protocol.js +1 -2
- package/dist/schemas.gen.js +1 -2
- package/package.json +8 -8
package/AGENTS.md
CHANGED
|
@@ -5,7 +5,7 @@ webhook. Verification requires the untouched request body and the endpoint signi
|
|
|
5
5
|
expose that secret to browser code.
|
|
6
6
|
|
|
7
7
|
Effect applications can import the typed adapter from `@samva/webhooks/effect` and install the
|
|
8
|
-
optional peer `effect`
|
|
8
|
+
optional peer `effect` from the `^4.0.4` range this package's `peerDependencies` names.
|
|
9
9
|
|
|
10
10
|
Import only package subpaths declared in `package.json`. The delivery, queue, persistence, retry,
|
|
11
11
|
and endpoint-management implementation is not part of this package.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Samva is the email API for your app: transactional and campaign sending, inbound
|
|
|
5
5
|
Verify signed Samva webhook deliveries in Node.js, Bun, Cloudflare Workers, and other Web
|
|
6
6
|
Crypto-compatible runtimes.
|
|
7
7
|
|
|
8
|
-
```ts
|
|
8
|
+
```ts sdk-typecheck-skip="Handler fragment uses the incoming request and application persistence and suppression functions"
|
|
9
9
|
import { isKnownEvent, verifyRequest } from "@samva/webhooks";
|
|
10
10
|
|
|
11
11
|
const verified = await verifyRequest(request, process.env.SAMVA_WEBHOOK_SECRET!);
|
|
@@ -22,13 +22,15 @@ request body and keep the signing secret on the server.
|
|
|
22
22
|
Effect applications can use the optional Effect entrypoint:
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import { Effect } from "effect";
|
|
26
25
|
import * as Webhooks from "@samva/webhooks/effect";
|
|
26
|
+
import { Effect } from "effect";
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
export async function verifyEvent(request: Request, secret: string) {
|
|
29
|
+
const program = Webhooks.verifyRequest(request, secret).pipe(
|
|
30
|
+
Effect.map((verified) => verified.event),
|
|
31
|
+
);
|
|
32
|
+
return Effect.runPromise(program);
|
|
33
|
+
}
|
|
32
34
|
```
|
|
33
35
|
|
|
34
36
|
Install the `effect` version this package lists in `peerDependencies` when using that entrypoint.
|
package/dist/effect.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { _ as WebhookTimestampError, c as signWebhook, 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, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-
|
|
2
|
-
import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-
|
|
1
|
+
import { _ as WebhookTimestampError, c as signWebhook, 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, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Dxbwh-ml.js";
|
|
2
|
+
import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-Bqz0To0S.js";
|
|
3
3
|
import { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, FlowRegistrationUpdatedEventSchema, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WebhookCreatedEventSchema, WebhookDeletedEventSchema, WebhookTestEventSchema, WebhookUpdatedEventSchema, WhatsappNumberConnectedEventSchema } from "./schemas.gen.js";
|
|
4
4
|
import { Clock, Effect } from "effect";
|
|
5
|
-
|
|
5
|
+
// src/effect.ts
|
|
6
6
|
/**
|
|
7
7
|
* Fails with the verification errors `verifyWebhookAt` rejects with. Any other rejection, such as
|
|
8
8
|
* a `TypeError` from input that violates the declared types, is a defect rather than a failed
|
|
@@ -74,7 +74,6 @@ const verifyRequest = Effect.fn("Webhooks.verifyRequest")(function* (request, se
|
|
|
74
74
|
nowMilliseconds
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
-
//#endregion
|
|
78
77
|
export { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DEFAULT_TOLERANCE_SECONDS, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, FlowRegistrationUpdatedEventSchema, InvalidWebhookHeadersError, InvalidWebhookSecretError, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MalformedWebhookPayloadError, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCreatedEventSchema, WebhookCryptoError, WebhookDeletedEventSchema, WebhookEventJsonSchemas, WebhookSignatureError, WebhookTestEventSchema, WebhookTimestampError, WebhookUpdatedEventSchema, WebhookVerificationError, WhatsappNumberConnectedEventSchema, generateWebhookSecret, isKnownEvent, signWebhook, verify, verifyRequest };
|
|
79
78
|
|
|
80
79
|
//# sourceMappingURL=effect.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/json-schemas.gen.ts
|
|
2
2
|
const WebhookEventJsonSchemas = {
|
|
3
3
|
"message.sent": {
|
|
4
4
|
type: "object",
|
|
@@ -4445,7 +4445,6 @@ const WebhookEventJsonSchemas = {
|
|
|
4445
4445
|
additionalProperties: true
|
|
4446
4446
|
}
|
|
4447
4447
|
};
|
|
4448
|
-
//#endregion
|
|
4449
4448
|
export { WebhookEventJsonSchemas as t };
|
|
4450
4449
|
|
|
4451
|
-
//# sourceMappingURL=json-schemas.gen-
|
|
4450
|
+
//# sourceMappingURL=json-schemas.gen-Bqz0To0S.js.map
|
package/dist/promise.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as WebhookTimestampError, c as signWebhook, 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, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-
|
|
2
|
-
import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-
|
|
3
|
-
|
|
1
|
+
import { _ as WebhookTimestampError, c as signWebhook, 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, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Dxbwh-ml.js";
|
|
2
|
+
import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-Bqz0To0S.js";
|
|
3
|
+
// src/promise.ts
|
|
4
4
|
/**
|
|
5
5
|
* Verifies a Samva webhook delivery from its body and header values, then returns its ID and
|
|
6
6
|
* parsed event.
|
|
@@ -112,7 +112,6 @@ const safeVerify = async (options) => {
|
|
|
112
112
|
throw error;
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
//#endregion
|
|
116
115
|
export { DEFAULT_TOLERANCE_SECONDS, InvalidWebhookHeadersError, InvalidWebhookSecretError, MalformedWebhookPayloadError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCryptoError, WebhookEventJsonSchemas, WebhookSignatureError, WebhookTimestampError, WebhookVerificationError, generateWebhookSecret, isKnownEvent, safeVerify, signWebhook, verify, verifyRequest };
|
|
117
116
|
|
|
118
117
|
//# sourceMappingURL=promise.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/decoder.gen.ts
|
|
2
2
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
3
|
const validate0 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate3(value["data"]));
|
|
4
4
|
const validate1 = (value) => typeof value === "string" && value === "message.sent";
|
|
@@ -422,8 +422,7 @@ const validateEvent = (value) => {
|
|
|
422
422
|
default: return true;
|
|
423
423
|
}
|
|
424
424
|
};
|
|
425
|
-
|
|
426
|
-
//#region src/errors.ts
|
|
425
|
+
// src/errors.ts
|
|
427
426
|
/**
|
|
428
427
|
* Base class for every failure this package reports while verifying a webhook delivery.
|
|
429
428
|
*
|
|
@@ -509,8 +508,7 @@ var WebhookCryptoError = class extends WebhookVerificationError {
|
|
|
509
508
|
super("WebhookCryptoError", options);
|
|
510
509
|
}
|
|
511
510
|
};
|
|
512
|
-
|
|
513
|
-
//#region src/protocol.ts
|
|
511
|
+
// src/protocol.ts
|
|
514
512
|
/**
|
|
515
513
|
* Header carrying the delivery's unique message ID. Retries of the same delivery reuse it, so it
|
|
516
514
|
* is the key for deduplicating deliveries you have already handled.
|
|
@@ -746,7 +744,6 @@ const readWebhookHeaders = (headers) => requireHeaders({
|
|
|
746
744
|
timestamp: headers.get(WEBHOOK_TIMESTAMP_HEADER),
|
|
747
745
|
signature: headers.get(WEBHOOK_SIGNATURE_HEADER)
|
|
748
746
|
});
|
|
749
|
-
//#endregion
|
|
750
747
|
export { WebhookTimestampError as _, encodeWebhookSignature as a, signWebhook as c, webhookSignedContent as d, InvalidWebhookHeadersError as f, WebhookSignatureError as g, WebhookCryptoError as h, WEBHOOK_TIMESTAMP_HEADER as i, verifyWebhookAt as l, MalformedWebhookPayloadError as m, WEBHOOK_ID_HEADER as n, generateWebhookSecret as o, InvalidWebhookSecretError as p, WEBHOOK_SIGNATURE_HEADER as r, readWebhookHeaders as s, DEFAULT_TOLERANCE_SECONDS as t, verifyWebhookAtWithPublicKeys as u, WebhookVerificationError as v, isKnownEvent as y };
|
|
751
748
|
|
|
752
|
-
//# sourceMappingURL=protocol-
|
|
749
|
+
//# sourceMappingURL=protocol-Dxbwh-ml.js.map
|
package/dist/protocol.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
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 };
|
|
1
|
+
export { t as DEFAULT_TOLERANCE_SECONDS, f as InvalidWebhookHeadersError, p as InvalidWebhookSecretError, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, r as WEBHOOK_SIGNATURE_HEADER, i as WEBHOOK_TIMESTAMP_HEADER, h as WebhookCryptoError, g as WebhookSignatureError, _ as WebhookTimestampError, v as WebhookVerificationError, a as encodeWebhookSignature, o as generateWebhookSecret, y as isKnownEvent, s as readWebhookHeaders, c as signWebhook, l as verifyWebhookAt, u as verifyWebhookAtWithPublicKeys, d as webhookSignedContent } from "./protocol-Dxbwh-ml.js";
|
package/dist/schemas.gen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
|
|
2
|
+
// src/schemas.gen.ts
|
|
3
3
|
const MessageSentEventSchema = Schema.StructWithRest(Schema.Struct({
|
|
4
4
|
type: Schema.Literal("message.sent"),
|
|
5
5
|
timestamp: Schema.String,
|
|
@@ -1689,7 +1689,6 @@ const SamvaWebhookEventSchema = Schema.Union([
|
|
|
1689
1689
|
MailboxMessageFailedEventSchema,
|
|
1690
1690
|
JourneyWebhookEventSchema
|
|
1691
1691
|
]);
|
|
1692
|
-
//#endregion
|
|
1693
1692
|
export { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, FlowRegistrationUpdatedEventSchema, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WebhookCreatedEventSchema, WebhookDeletedEventSchema, WebhookTestEventSchema, WebhookUpdatedEventSchema, WhatsappNumberConnectedEventSchema };
|
|
1694
1693
|
|
|
1695
1694
|
//# sourceMappingURL=schemas.gen.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samva/webhooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Runtime-neutral verification for Samva webhook deliveries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"samva",
|
|
@@ -59,24 +59,24 @@
|
|
|
59
59
|
"build": "tsdown && tsc --project tsconfig.build.json",
|
|
60
60
|
"prepack": "bun run build",
|
|
61
61
|
"test": "bun run test:generation && vitest run --root ../.. --project packages packages/webhooks/tests",
|
|
62
|
-
"typecheck": "
|
|
62
|
+
"typecheck": "effect-tsgo tsrs --noEmit",
|
|
63
63
|
"generate": "bun run --filter @samva/openapi build && bun run scripts/generate.ts",
|
|
64
64
|
"test:generation": "bun run --filter @samva/openapi build && bun run scripts/generate.ts --check",
|
|
65
65
|
"test:bundle": "bun run build && bun run scripts/check-bundle.ts"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@effect/
|
|
68
|
+
"@effect/tsgo": "0.63.0",
|
|
69
|
+
"@effect/vitest": "4.0.6",
|
|
69
70
|
"@samva/openapi": "0.0.0",
|
|
70
71
|
"ajv": "^8.20.0",
|
|
71
72
|
"ajv-formats": "^3.0.1",
|
|
72
|
-
"effect": "4.0.
|
|
73
|
-
"
|
|
74
|
-
"tsdown": "^0.22.13",
|
|
73
|
+
"effect": "4.0.6",
|
|
74
|
+
"tsdown": "0.23.1",
|
|
75
75
|
"typescript": "^7.0.2",
|
|
76
|
-
"vitest": "
|
|
76
|
+
"vitest": "5.0.3"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"effect": "4.0.
|
|
79
|
+
"effect": "^4.0.4"
|
|
80
80
|
},
|
|
81
81
|
"peerDependenciesMeta": {
|
|
82
82
|
"effect": {
|