@primitivedotdev/sdk 0.25.0 → 0.25.1
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/api/index.d.ts +3 -2
- package/dist/api/index.js +6 -0
- package/dist/api/verify-signature.js +198 -0
- package/dist/{api-C3X14uId.js → api-CoP5vKPK.js} +141 -2
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/errors-C53fe686.d.ts +245 -0
- package/dist/errors-x91I_yEt.js +287 -0
- package/dist/{index-CDlwyxdp.d.ts → index-Dbx9udpX.d.ts} +2 -210
- package/dist/{index-jLAAV6Sq.d.ts → index-DdITDPea.d.ts} +82 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/webhook/errors.js +224 -0
- package/dist/webhook/index.d.ts +2 -2
- package/dist/webhook/index.js +2 -2
- package/dist/{webhook-rUjGV6Zu.js → webhook-DJkfUnFZ.js} +2 -220
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/received-email-D6tKtWwW.js +0 -69
- package/dist/received-email-DNjpq_Wt.d.ts +0 -37
|
@@ -1,214 +1,6 @@
|
|
|
1
1
|
import { N as WebhookEvent, j as ValidateEmailAuthResult, l as EmailAuth, u as EmailReceivedEvent } from "./types-9vXGZjPd.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ErrorObject } from "ajv";
|
|
2
|
+
import { m as ReceivedEmail, u as WebhookValidationError } from "./errors-C53fe686.js";
|
|
4
3
|
|
|
5
|
-
//#region src/webhook/errors.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Verification error definitions.
|
|
8
|
-
* Use these for documentation, dashboards, and i18n.
|
|
9
|
-
*/
|
|
10
|
-
declare const VERIFICATION_ERRORS: {
|
|
11
|
-
readonly INVALID_SIGNATURE_HEADER: {
|
|
12
|
-
readonly message: "Missing or malformed Primitive-Signature header";
|
|
13
|
-
readonly suggestion: "Check that you're reading the correct header (Primitive-Signature) and it's being passed correctly from your web framework.";
|
|
14
|
-
};
|
|
15
|
-
readonly TIMESTAMP_OUT_OF_RANGE: {
|
|
16
|
-
readonly message: "Timestamp is too old (possible replay attack)";
|
|
17
|
-
readonly suggestion: "This could indicate a replay attack, network delay, or server clock drift. Check your server's time is synced.";
|
|
18
|
-
};
|
|
19
|
-
readonly SIGNATURE_MISMATCH: {
|
|
20
|
-
readonly message: "Signature doesn't match expected value";
|
|
21
|
-
readonly suggestion: "Verify the webhook secret matches and you're using the raw request body (not re-serialized JSON).";
|
|
22
|
-
};
|
|
23
|
-
readonly MISSING_SECRET: {
|
|
24
|
-
readonly message: "No webhook secret was provided";
|
|
25
|
-
readonly suggestion: "Pass your webhook secret from the Primitive dashboard. Check that the environment variable is set.";
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Payload parsing error definitions.
|
|
30
|
-
* Use these for documentation, dashboards, and i18n.
|
|
31
|
-
*/
|
|
32
|
-
declare const PAYLOAD_ERRORS: {
|
|
33
|
-
readonly PAYLOAD_NULL: {
|
|
34
|
-
readonly message: "Webhook payload is null";
|
|
35
|
-
readonly suggestion: "Ensure you're passing the parsed JSON body, not null. Check your framework's body parsing middleware.";
|
|
36
|
-
};
|
|
37
|
-
readonly PAYLOAD_UNDEFINED: {
|
|
38
|
-
readonly message: "Webhook payload is undefined";
|
|
39
|
-
readonly suggestion: "The payload was not provided. Make sure you're passing the request body to the handler.";
|
|
40
|
-
};
|
|
41
|
-
readonly PAYLOAD_WRONG_TYPE: {
|
|
42
|
-
readonly message: "Webhook payload must be an object";
|
|
43
|
-
readonly suggestion: "The payload should be a parsed JSON object. Check that you're not passing a string or other primitive.";
|
|
44
|
-
};
|
|
45
|
-
readonly PAYLOAD_IS_ARRAY: {
|
|
46
|
-
readonly message: "Webhook payload is an array, expected object";
|
|
47
|
-
readonly suggestion: "Primitive webhooks are single event objects, not arrays. Check the payload structure.";
|
|
48
|
-
};
|
|
49
|
-
readonly PAYLOAD_MISSING_EVENT: {
|
|
50
|
-
readonly message: "Webhook payload missing 'event' field";
|
|
51
|
-
readonly suggestion: "All webhook payloads must have an 'event' field. This may not be a valid Primitive webhook.";
|
|
52
|
-
};
|
|
53
|
-
readonly PAYLOAD_UNKNOWN_EVENT: {
|
|
54
|
-
readonly message: "Unknown webhook event type";
|
|
55
|
-
readonly suggestion: "This event type is not recognized. You may need to update your SDK or handle unknown events gracefully.";
|
|
56
|
-
};
|
|
57
|
-
readonly PAYLOAD_EMPTY_BODY: {
|
|
58
|
-
readonly message: "Request body is empty";
|
|
59
|
-
readonly suggestion: "The request body was empty. Ensure the webhook is sending data and your framework is parsing it correctly.";
|
|
60
|
-
};
|
|
61
|
-
readonly JSON_PARSE_FAILED: {
|
|
62
|
-
readonly message: "Failed to parse JSON body";
|
|
63
|
-
readonly suggestion: "The request body is not valid JSON. Check the raw body content and Content-Type header.";
|
|
64
|
-
};
|
|
65
|
-
readonly INVALID_ENCODING: {
|
|
66
|
-
readonly message: "Invalid body encoding";
|
|
67
|
-
readonly suggestion: "The request body encoding is not supported. Primitive webhooks use UTF-8 encoded JSON.";
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Raw email decode error definitions.
|
|
72
|
-
* Use these for documentation, dashboards, and i18n.
|
|
73
|
-
*/
|
|
74
|
-
declare const RAW_EMAIL_ERRORS: {
|
|
75
|
-
readonly NOT_INCLUDED: {
|
|
76
|
-
readonly message: "Raw email content not included inline";
|
|
77
|
-
readonly suggestion: "Use the download URL at event.email.content.download.url to fetch the raw email.";
|
|
78
|
-
};
|
|
79
|
-
readonly INVALID_BASE64: {
|
|
80
|
-
readonly message: "Raw email content is not valid base64";
|
|
81
|
-
readonly suggestion: "The raw email data is malformed. Fetch the raw email from the download URL or regenerate the webhook payload.";
|
|
82
|
-
};
|
|
83
|
-
readonly HASH_MISMATCH: {
|
|
84
|
-
readonly message: "SHA-256 hash verification failed";
|
|
85
|
-
readonly suggestion: "The raw email data may be corrupted. Try downloading from the URL instead.";
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* All error codes that can be thrown by the SDK.
|
|
90
|
-
*/
|
|
91
|
-
type WebhookErrorCode = WebhookVerificationErrorCode | WebhookPayloadErrorCode | WebhookValidationErrorCode | RawEmailDecodeErrorCode;
|
|
92
|
-
type RawEmailDecodeErrorCode = keyof typeof RAW_EMAIL_ERRORS;
|
|
93
|
-
/**
|
|
94
|
-
* Base class for all Primitive webhook errors.
|
|
95
|
-
*
|
|
96
|
-
* Catch this to handle any error from the SDK in a single catch block.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* import { handleWebhook, PrimitiveWebhookError } from '@primitivedotdev/sdk';
|
|
101
|
-
*
|
|
102
|
-
* try {
|
|
103
|
-
* const event = handleWebhook({ body, headers, secret });
|
|
104
|
-
* } catch (err) {
|
|
105
|
-
* if (err instanceof PrimitiveWebhookError) {
|
|
106
|
-
* console.error(`[${err.code}] ${err.message}`);
|
|
107
|
-
* return res.status(400).json({ error: err.code });
|
|
108
|
-
* }
|
|
109
|
-
* throw err;
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
declare abstract class PrimitiveWebhookError extends Error {
|
|
114
|
-
/** Programmatic error code for monitoring and handling */
|
|
115
|
-
abstract readonly code: WebhookErrorCode;
|
|
116
|
-
/** Actionable guidance for fixing the issue */
|
|
117
|
-
abstract readonly suggestion: string;
|
|
118
|
-
/**
|
|
119
|
-
* Formats the error for logging/display.
|
|
120
|
-
*/
|
|
121
|
-
toString(): string;
|
|
122
|
-
/**
|
|
123
|
-
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
124
|
-
*/
|
|
125
|
-
toJSON(): {
|
|
126
|
-
name: string;
|
|
127
|
-
code: WebhookErrorCode;
|
|
128
|
-
message: string;
|
|
129
|
-
suggestion: string;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Error codes for webhook verification failures.
|
|
134
|
-
* Derived from VERIFICATION_ERRORS keys.
|
|
135
|
-
*/
|
|
136
|
-
type WebhookVerificationErrorCode = keyof typeof VERIFICATION_ERRORS;
|
|
137
|
-
/**
|
|
138
|
-
* Error thrown when webhook signature verification fails.
|
|
139
|
-
*
|
|
140
|
-
* Use the `code` property to programmatically handle specific error cases.
|
|
141
|
-
*/
|
|
142
|
-
declare class WebhookVerificationError extends PrimitiveWebhookError {
|
|
143
|
-
readonly code: WebhookVerificationErrorCode;
|
|
144
|
-
readonly suggestion: string;
|
|
145
|
-
constructor(code: WebhookVerificationErrorCode, message?: string, suggestion?: string);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Error codes for webhook payload parsing failures.
|
|
149
|
-
* Derived from PAYLOAD_ERRORS keys.
|
|
150
|
-
*/
|
|
151
|
-
type WebhookPayloadErrorCode = keyof typeof PAYLOAD_ERRORS;
|
|
152
|
-
/**
|
|
153
|
-
* Error thrown when webhook payload parsing fails (lightweight parser).
|
|
154
|
-
*
|
|
155
|
-
* Use the `code` property for programmatic handling and monitoring.
|
|
156
|
-
* The `suggestion` property contains actionable guidance for fixing the issue.
|
|
157
|
-
*/
|
|
158
|
-
declare class WebhookPayloadError extends PrimitiveWebhookError {
|
|
159
|
-
readonly code: WebhookPayloadErrorCode;
|
|
160
|
-
readonly suggestion: string;
|
|
161
|
-
/** Original error if this wraps another error (e.g., JSON.parse failure) */
|
|
162
|
-
readonly cause?: Error;
|
|
163
|
-
constructor(code: WebhookPayloadErrorCode, message?: string, suggestion?: string, cause?: Error);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Error code for schema validation failures.
|
|
167
|
-
*/
|
|
168
|
-
type WebhookValidationErrorCode = "SCHEMA_VALIDATION_FAILED";
|
|
169
|
-
/**
|
|
170
|
-
* Error thrown when schema validation fails.
|
|
171
|
-
*/
|
|
172
|
-
declare class WebhookValidationError extends PrimitiveWebhookError {
|
|
173
|
-
readonly code: WebhookValidationErrorCode;
|
|
174
|
-
readonly suggestion: string;
|
|
175
|
-
/** The specific field path that failed (e.g., "email.headers.from") */
|
|
176
|
-
readonly field: string;
|
|
177
|
-
/** Original schema validation errors for advanced debugging */
|
|
178
|
-
readonly validationErrors: readonly ErrorObject[];
|
|
179
|
-
/** Number of additional validation errors beyond the first */
|
|
180
|
-
readonly additionalErrorCount: number;
|
|
181
|
-
constructor(field: string, message: string, suggestion: string, validationErrors: readonly ErrorObject[]);
|
|
182
|
-
/**
|
|
183
|
-
* Formats the error for logging/display.
|
|
184
|
-
* Includes error count and suggestion.
|
|
185
|
-
*/
|
|
186
|
-
toString(): string;
|
|
187
|
-
/**
|
|
188
|
-
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
189
|
-
*/
|
|
190
|
-
toJSON(): {
|
|
191
|
-
name: string;
|
|
192
|
-
code: "SCHEMA_VALIDATION_FAILED";
|
|
193
|
-
field: string;
|
|
194
|
-
message: string;
|
|
195
|
-
suggestion: string;
|
|
196
|
-
additionalErrorCount: number;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Error thrown when raw email decoding or verification fails.
|
|
201
|
-
*
|
|
202
|
-
* Use the `code` property to determine the failure reason:
|
|
203
|
-
* - `NOT_INCLUDED`: Raw email not inline, must download from URL
|
|
204
|
-
* - `HASH_MISMATCH`: SHA-256 verification failed, content may be corrupted
|
|
205
|
-
*/
|
|
206
|
-
declare class RawEmailDecodeError extends PrimitiveWebhookError {
|
|
207
|
-
readonly code: RawEmailDecodeErrorCode;
|
|
208
|
-
readonly suggestion: string;
|
|
209
|
-
constructor(code: RawEmailDecodeErrorCode, message?: string);
|
|
210
|
-
}
|
|
211
|
-
//#endregion
|
|
212
4
|
//#region src/validation.d.ts
|
|
213
5
|
interface ValidationSuccess<T> {
|
|
214
6
|
success: true;
|
|
@@ -1624,4 +1416,4 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
|
|
|
1624
1416
|
*/
|
|
1625
1417
|
declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
|
|
1626
1418
|
//#endregion
|
|
1627
|
-
export { VerifyOptions as A,
|
|
1419
|
+
export { VerifyOptions as A, signStandardWebhooksPayload as C, PRIMITIVE_CONFIRMED_HEADER as D, LEGACY_SIGNATURE_HEADER as E, VerifyDownloadTokenResult as F, generateDownloadToken as I, verifyDownloadToken as L, verifyWebhookSignature as M, GenerateDownloadTokenOptions as N, PRIMITIVE_SIGNATURE_HEADER as O, VerifyDownloadTokenOptions as P, safeValidateEmailReceivedEvent as R, StandardWebhooksVerifyOptions as S, LEGACY_CONFIRMED_HEADER as T, emailReceivedEventJsonSchema as _, confirmedHeaders as a, STANDARD_WEBHOOK_TIMESTAMP_HEADER as b, handleWebhook as c, isRawIncluded as d, parseWebhookEvent as f, validateEmailAuth as g, WEBHOOK_VERSION as h, WebhookHeaders as i, signWebhookPayload as j, SignResult as k, isDownloadExpired as l, verifyRawEmailDownload as m, HandleWebhookOptions as n, decodeRawEmail as o, receive as p, ReceiveRequestOptions as r, getDownloadTimeRemaining as s, DecodeRawEmailOptions as t, isEmailReceivedEvent as u, STANDARD_WEBHOOK_ID_HEADER as v, verifyStandardWebhooksSignature as w, StandardWebhooksSignResult as x, STANDARD_WEBHOOK_SIGNATURE_HEADER as y, validateEmailReceivedEvent as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as ReceivedEmail } from "./errors-C53fe686.js";
|
|
2
2
|
|
|
3
3
|
//#region src/api/generated/core/auth.gen.d.ts
|
|
4
4
|
type AuthToken = string | undefined;
|
|
@@ -4192,6 +4192,86 @@ declare const deleteFunctionSecret: <ThrowOnError extends boolean = false>(optio
|
|
|
4192
4192
|
*/
|
|
4193
4193
|
declare const setFunctionSecret: <ThrowOnError extends boolean = false>(options: Options<SetFunctionSecretData, ThrowOnError>) => RequestResult<SetFunctionSecretResponses, SetFunctionSecretErrors, ThrowOnError, "fields">;
|
|
4194
4194
|
//#endregion
|
|
4195
|
+
//#region src/api/verify-signature.d.ts
|
|
4196
|
+
/**
|
|
4197
|
+
* Workers-safe webhook signature verification.
|
|
4198
|
+
*
|
|
4199
|
+
* Mirrors `verifyWebhookSignature` from `@primitivedotdev/sdk` but
|
|
4200
|
+
* implements the HMAC-SHA256 step with the Web Crypto API
|
|
4201
|
+
* (`crypto.subtle`) instead of `node:crypto`. The Node version is
|
|
4202
|
+
* still the right choice for server-side handlers running on Node
|
|
4203
|
+
* (it's measurably faster and supports Buffer bodies); this one
|
|
4204
|
+
* exists so a Primitive Function handler can bundle the verifier
|
|
4205
|
+
* without dragging in a `node:crypto` polyfill that inflates the
|
|
4206
|
+
* deploy artifact past the size cap.
|
|
4207
|
+
*
|
|
4208
|
+
* Available natively in Workers, Node 22+, browsers, Deno, and Bun.
|
|
4209
|
+
* Zero polyfill weight, zero new runtime dependencies.
|
|
4210
|
+
*
|
|
4211
|
+
* Surface contract matches the Node verifier exactly: same input
|
|
4212
|
+
* shape, same `WebhookVerificationError` class, same set of error
|
|
4213
|
+
* codes. Existing callers can swap the import path with no other
|
|
4214
|
+
* code changes:
|
|
4215
|
+
*
|
|
4216
|
+
* // Node (existing):
|
|
4217
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk';
|
|
4218
|
+
*
|
|
4219
|
+
* // Workers / in-handler (this file):
|
|
4220
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk/api';
|
|
4221
|
+
*/
|
|
4222
|
+
declare const PRIMITIVE_SIGNATURE_HEADER = "Primitive-Signature";
|
|
4223
|
+
interface VerifyOptions {
|
|
4224
|
+
/**
|
|
4225
|
+
* The raw request body string. MUST be the exact bytes Primitive
|
|
4226
|
+
* signed; re-serializing parsed JSON produces a different string
|
|
4227
|
+
* and the verification will fail.
|
|
4228
|
+
*/
|
|
4229
|
+
rawBody: string;
|
|
4230
|
+
/** Value of the `Primitive-Signature` header. */
|
|
4231
|
+
signatureHeader: string;
|
|
4232
|
+
/** Webhook signing secret. Auto-injected into Function handlers as `env.PRIMITIVE_WEBHOOK_SECRET`. */
|
|
4233
|
+
secret: string;
|
|
4234
|
+
/** Max age in seconds (default: 300). */
|
|
4235
|
+
toleranceSeconds?: number;
|
|
4236
|
+
/** Override current time for testing (unix seconds). */
|
|
4237
|
+
nowSeconds?: number;
|
|
4238
|
+
}
|
|
4239
|
+
/**
|
|
4240
|
+
* Verify a webhook signature using the Web Crypto API.
|
|
4241
|
+
*
|
|
4242
|
+
* Throws `WebhookVerificationError` on failure with a specific error
|
|
4243
|
+
* code matching the Node verifier's set. Returns `true` on success.
|
|
4244
|
+
*
|
|
4245
|
+
* @example
|
|
4246
|
+
* ```typescript
|
|
4247
|
+
* import {
|
|
4248
|
+
* verifyWebhookSignature,
|
|
4249
|
+
* WebhookVerificationError,
|
|
4250
|
+
* PRIMITIVE_SIGNATURE_HEADER,
|
|
4251
|
+
* } from '@primitivedotdev/sdk/api';
|
|
4252
|
+
*
|
|
4253
|
+
* export default {
|
|
4254
|
+
* async fetch(request: Request, env: { PRIMITIVE_WEBHOOK_SECRET: string }) {
|
|
4255
|
+
* const rawBody = await request.text();
|
|
4256
|
+
* try {
|
|
4257
|
+
* await verifyWebhookSignature({
|
|
4258
|
+
* rawBody,
|
|
4259
|
+
* signatureHeader: request.headers.get(PRIMITIVE_SIGNATURE_HEADER) ?? '',
|
|
4260
|
+
* secret: env.PRIMITIVE_WEBHOOK_SECRET,
|
|
4261
|
+
* });
|
|
4262
|
+
* } catch (err) {
|
|
4263
|
+
* if (err instanceof WebhookVerificationError) {
|
|
4264
|
+
* return new Response('invalid signature', { status: 401 });
|
|
4265
|
+
* }
|
|
4266
|
+
* throw err;
|
|
4267
|
+
* }
|
|
4268
|
+
* // ... process the webhook
|
|
4269
|
+
* },
|
|
4270
|
+
* };
|
|
4271
|
+
* ```
|
|
4272
|
+
*/
|
|
4273
|
+
declare function verifyWebhookSignature(opts: VerifyOptions): Promise<true>;
|
|
4274
|
+
//#endregion
|
|
4195
4275
|
//#region src/api/index.d.ts
|
|
4196
4276
|
declare const DEFAULT_API_BASE_URL_1 = "https://www.primitive.dev/api/v1";
|
|
4197
4277
|
declare const DEFAULT_API_BASE_URL_2 = "https://api.primitive.dev/v1";
|
|
@@ -4347,4 +4427,4 @@ declare function createPrimitiveClient(options?: PrimitiveClientOptions): Primit
|
|
|
4347
4427
|
declare function client(options?: PrimitiveClientOptions): PrimitiveClient;
|
|
4348
4428
|
declare const operations: typeof sdk_gen_d_exports;
|
|
4349
4429
|
//#endregion
|
|
4350
|
-
export {
|
|
4430
|
+
export { pollCliLogin as $, StorageStats as $a, ReplayDeliveryError as $i, DownloadRawEmailErrors as $n, Config as $o, GetWebhookSecretError as $r, CreateFunctionSecretData as $t, deleteEmail as A, SendMailInput as Aa, ListFunctionSecretsData as Ai, DeleteFunctionResponses as An, UpdateEndpointResponse as Ao, GetEmailResponse as Ar, CliLogoutResponse as At, getFunction as B, SentEmailSummary as Ba, ListSentEmailsData as Bi, DiscardEmailContentError as Bn, UpdateFunctionErrors as Bo, GetSendPermissionsResponse as Br, CreateFilterData as Bt, addDomain as C, SearchEmailsResponse as Ca, ListEndpointsResponses as Ci, DeleteFilterErrors as Cn, UpdateDomainInput as Co, GetAccountError as Cr, AddDomainResponses as Ct, createFunction as D, SendEmailErrors as Da, ListFiltersErrors as Di, DeleteFunctionError as Dn, UpdateEndpointError as Do, GetEmailData as Dr, CliLogoutError as Dt, createFilter as E, SendEmailError as Ea, ListFiltersError as Ei, DeleteFunctionData as En, UpdateEndpointData as Eo, GetAccountResponses as Er, CliLogoutData as Et, discardEmailContent as F, SendPermissionRule as Fa, ListFunctionsData as Fi, DeleteFunctionSecretResponses as Fn, UpdateFilterInput as Fo, GetFunctionResponse as Fr, CreateEndpointError as Ft, listDeliveries as G, SetFunctionSecretResponse as Ga, PaginationMeta as Gi, DomainVerifyResult as Gn, VerifyDomainData as Go, GetSentEmailResponse as Gr, CreateFilterResponses as Gt, getSentEmail as H, SetFunctionSecretError as Ha, ListSentEmailsErrors as Hi, DiscardEmailContentResponse as Hn, UpdateFunctionResponse as Ho, GetSentEmailData as Hr, CreateFilterErrors as Ht, downloadAttachments as I, SendPermissionYourDomain as Ia, ListFunctionsError as Ii, DeliveryStatus as In, UpdateFilterResponse as Io, GetFunctionResponses as Ir, CreateEndpointErrors as It, listEndpoints as J, StartCliLoginError as Ja, PollCliLoginErrors as Ji, DownloadAttachmentsErrors as Jn, VerifyDomainResponse as Jo, GetStorageStatsError as Jr, CreateFunctionErrors as Jt, listDomains as K, SetFunctionSecretResponses as Ka, PollCliLoginData as Ki, DownloadAttachmentsData as Kn, VerifyDomainError as Ko, GetSentEmailResponses as Kr, CreateFunctionData as Kt, downloadRawEmail as L, SendPermissionsMeta as La, ListFunctionsErrors as Li, DeliverySummary as Ln, UpdateFilterResponses as Lo, GetSendPermissionsData as Lr, CreateEndpointInput as Lt, deleteFilter as M, SendPermissionAddress as Ma, ListFunctionSecretsErrors as Mi, DeleteFunctionSecretError as Mn, UpdateFilterData as Mo, GetFunctionData as Mr, CliLogoutResult as Mt, deleteFunction as N, SendPermissionAnyRecipient as Na, ListFunctionSecretsResponse as Ni, DeleteFunctionSecretErrors as Nn, UpdateFilterError as No, GetFunctionError as Nr, ClientOptions as Nt, createFunctionSecret as O, SendEmailResponse as Oa, ListFiltersResponse as Oi, DeleteFunctionErrors as On, UpdateEndpointErrors as Oo, GetEmailError as Or, CliLogoutErrors as Ot, deleteFunctionSecret as P, SendPermissionManagedZone as Pa, ListFunctionSecretsResponses as Pi, DeleteFunctionSecretResponse as Pn, UpdateFilterErrors as Po, GetFunctionErrors as Pr, CreateEndpointData as Pt, listSentEmails as Q, StartCliLoginResponses as Qa, ReplayDeliveryData as Qi, DownloadRawEmailError as Qn, ClientOptions$1 as Qo, GetWebhookSecretData as Qr, CreateFunctionResult as Qt, getAccount as R, SentEmailDetail as Ra, ListFunctionsResponse as Ri, DiscardContentResult as Rn, UpdateFunctionData as Ro, GetSendPermissionsError as Rr, CreateEndpointResponse as Rt, Options as S, SearchEmailsErrors as Sa, ListEndpointsResponse as Si, DeleteFilterError as Sn, UpdateDomainErrors as So, GetAccountData as Sr, AddDomainResponse as St, createEndpoint as T, SendEmailData as Ta, ListFiltersData as Ti, DeleteFilterResponses as Tn, UpdateDomainResponses as To, GetAccountResponse as Tr, CliLoginStartResult as Tt, getStorageStats as U, SetFunctionSecretErrors as Ua, ListSentEmailsResponse as Ui, DiscardEmailContentResponses as Un, UpdateFunctionResponses as Uo, GetSentEmailError as Ur, CreateFilterInput as Ut, getSendPermissions as V, SetFunctionSecretData as Va, ListSentEmailsError as Vi, DiscardEmailContentErrors as Vn, UpdateFunctionInput as Vo, GetSendPermissionsResponses as Vr, CreateFilterError as Vt, getWebhookSecret as W, SetFunctionSecretInput as Wa, ListSentEmailsResponses as Wi, Domain as Wn, VerifiedDomain as Wo, GetSentEmailErrors as Wr, CreateFilterResponse as Wt, listFunctionSecrets as X, StartCliLoginInput as Xa, PollCliLoginResponse as Xi, DownloadAttachmentsResponses as Xn, WebhookSecret as Xo, GetStorageStatsResponse as Xr, CreateFunctionResponse as Xt, listFilters as Y, StartCliLoginErrors as Ya, PollCliLoginInput as Yi, DownloadAttachmentsResponse as Yn, VerifyDomainResponses as Yo, GetStorageStatsErrors as Yr, CreateFunctionInput as Yt, listFunctions as Z, StartCliLoginResponse as Za, PollCliLoginResponses as Zi, DownloadRawEmailData as Zn, Client as Zo, GetStorageStatsResponses as Zr, CreateFunctionResponses as Zt, createPrimitiveClient as _, RotateWebhookSecretErrors as _a, ListEmailsResponse as _i, DeleteEndpointError as _n, UpdateAccountInput as _o, FunctionListItem as _r, AccountUpdated as _t, PrimitiveApiClientOptions as a, ReplayEmailWebhooksErrors as aa, ListDeliveriesError as ai, Cursor as an, TestEndpointResponses as ao, EmailSearchFacets as ar, Auth as as, sendEmail as at, VerifyOptions as b, SearchEmailsData as ba, ListEndpointsError as bi, DeleteEndpointResponses as bn, UpdateDomainData as bo, GateDenial as br, AddDomainErrors as bt, PrimitiveClient as c, ReplayResult as ca, ListDeliveriesResponses as ci, DeleteDomainErrors as cn, TestFunctionErrors as co, EmailSearchResult as cr, testEndpoint as ct, RequestOptions as d, ReplyToEmailErrors as da, ListDomainsErrors as di, DeleteEmailData as dn, TestInvocationResult as do, EmailWebhookStatus as dr, updateDomain as dt, ReplayDeliveryErrors as ea, GetWebhookSecretErrors as ei, CreateFunctionSecretError as en, SuccessEnvelope as eo, DownloadRawEmailResponse as er, CreateClientConfig as es, replayDelivery as et, SendInput as f, ReplyToEmailResponse as fa, ListDomainsResponse as fi, DeleteEmailError as fn, TestResult as fo, Endpoint as fr, updateEndpoint as ft, createPrimitiveApiClient as g, RotateWebhookSecretError as ga, ListEmailsErrors as gi, DeleteEndpointData as gn, UpdateAccountErrors as go, FunctionDetail as gr, Account as gt, client as h, RotateWebhookSecretData as ha, ListEmailsError as hi, DeleteEmailResponses as hn, UpdateAccountError as ho, FunctionDeployStatus as hr, verifyDomain as ht, PrimitiveApiClient as i, ReplayEmailWebhooksError as ia, ListDeliveriesData as ii, CreateFunctionSecretResponses as in, TestEndpointResponse as io, EmailSearchFacetBucket as ir, ResponseStyle as is, searchEmails as it, deleteEndpoint as j, SendMailResult as ja, ListFunctionSecretsError as ji, DeleteFunctionSecretData as jn, UpdateEndpointResponses as jo, GetEmailResponses as jr, CliLogoutResponses as jt, deleteDomain as k, SendEmailResponses as ka, ListFiltersResponses as ki, DeleteFunctionResponse as kn, UpdateEndpointInput as ko, GetEmailErrors as kr, CliLogoutInput as kt, PrimitiveClientOptions as l, ReplyToEmailData as la, ListDomainsData as li, DeleteDomainResponse as ln, TestFunctionResponse as lo, EmailStatus as lr, testFunction as lt, SendThreadInput as m, ResourceId as ma, ListEmailsData as mi, DeleteEmailResponse as mn, UpdateAccountData as mo, Filter as mr, updateFunction as mt, DEFAULT_API_BASE_URL_2 as n, ReplayDeliveryResponses as na, GetWebhookSecretResponses as ni, CreateFunctionSecretInput as nn, TestEndpointError as no, EmailDetail as nr, RequestOptions$1 as ns, replyToEmail as nt, PrimitiveApiError as o, ReplayEmailWebhooksResponse as oa, ListDeliveriesErrors as oi, DeleteDomainData as on, TestFunctionData as oo, EmailSearchHighlights as or, setFunctionSecret as ot, SendResult as p, ReplyToEmailResponses as pa, ListDomainsResponses as pi, DeleteEmailErrors as pn, UnverifiedDomain as po, ErrorResponse as pr, updateFilter as pt, listEmails as q, StartCliLoginData as qa, PollCliLoginError as qi, DownloadAttachmentsError as qn, VerifyDomainErrors as qo, GetStorageStatsData as qr, CreateFunctionError as qt, ForwardInput as r, ReplayEmailWebhooksData as ra, Limit as ri, CreateFunctionSecretResponse as rn, TestEndpointErrors as ro, EmailDetailReply as rr, RequestResult as rs, rotateWebhookSecret as rt, PrimitiveApiErrorDetails as s, ReplayEmailWebhooksResponses as sa, ListDeliveriesResponse as si, DeleteDomainError as sn, TestFunctionError as so, EmailSearchMeta as sr, startCliLogin as st, DEFAULT_API_BASE_URL_1 as t, ReplayDeliveryResponse as ta, GetWebhookSecretResponse as ti, CreateFunctionSecretErrors as tn, TestEndpointData as to, DownloadRawEmailResponses as tr, Options$1 as ts, replayEmailWebhooks as tt, ReplyInput as u, ReplyToEmailError as ua, ListDomainsError as ui, DeleteDomainResponses as un, TestFunctionResponses as uo, EmailSummary as ur, updateAccount as ut, operations as v, RotateWebhookSecretResponse as va, ListEmailsResponses as vi, DeleteEndpointErrors as vn, UpdateAccountResponse as vo, FunctionSecretListItem as vr, AddDomainData as vt, cliLogout as w, SearchEmailsResponses as wa, ListEnvelope as wi, DeleteFilterResponse as wn, UpdateDomainResponse as wo, GetAccountErrors as wr, CliLoginPollResult as wt, verifyWebhookSignature as x, SearchEmailsError as xa, ListEndpointsErrors as xi, DeleteFilterData as xn, UpdateDomainError as xo, GateFix as xr, AddDomainInput as xt, PRIMITIVE_SIGNATURE_HEADER as y, RotateWebhookSecretResponses as ya, ListEndpointsData as yi, DeleteEndpointResponse as yn, UpdateAccountResponses as yo, FunctionSecretWriteResult as yr, AddDomainError as yt, getEmail as z, SentEmailStatus as za, ListFunctionsResponses as zi, DiscardEmailContentData as zn, UpdateFunctionError as zo, GetSendPermissionsErrors as zr, CreateEndpointResponses as zt };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as UnknownEvent, C as ParsedDataFailed, D as RawContentDownloadOnly, E as RawContent, M as WebhookAttachment, N as WebhookEvent, O as RawContentInline, S as ParsedDataComplete, T as ParsedStatus, _ as ForwardResultInline, a as DmarcPolicy, b as KnownWebhookEvent, c as EmailAnalysis, d as EventType, f as ForwardAnalysis, g as ForwardResultAttachmentSkipped, h as ForwardResultAttachmentAnalyzed, i as DkimSignature, j as ValidateEmailAuthResult, k as SpfResult, l as EmailAuth, m as ForwardResult, n as AuthVerdict, o as DmarcResult, p as ForwardOriginalSender, r as DkimResult, s as EmailAddress, t as AuthConfidence, u as EmailReceivedEvent, v as ForwardVerdict, w as ParsedError, x as ParsedData, y as ForwardVerification } from "./types-9vXGZjPd.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { _ as createPrimitiveClient, c as PrimitiveClient, f as SendInput, h as client, l as PrimitiveClientOptions, m as SendThreadInput, o as PrimitiveApiError, p as SendResult, r as ForwardInput, u as ReplyInput } from "./index-
|
|
4
|
-
import { A as VerifyOptions,
|
|
2
|
+
import { _ as buildForwardSubject, a as RawEmailDecodeErrorCode, b as normalizeReceivedEmail, c as WebhookPayloadError, d as WebhookValidationErrorCode, f as WebhookVerificationError, g as ReceivedEmailThread, h as ReceivedEmailAddress, i as RawEmailDecodeError, l as WebhookPayloadErrorCode, m as ReceivedEmail, n as PrimitiveWebhookError, o as VERIFICATION_ERRORS, p as WebhookVerificationErrorCode, r as RAW_EMAIL_ERRORS, s as WebhookErrorCode, t as PAYLOAD_ERRORS, u as WebhookValidationError, v as buildReplySubject, x as parseHeaderAddress, y as formatAddress } from "./errors-C53fe686.js";
|
|
3
|
+
import { _ as createPrimitiveClient, c as PrimitiveClient, f as SendInput, h as client, l as PrimitiveClientOptions, m as SendThreadInput, o as PrimitiveApiError, p as SendResult, r as ForwardInput, u as ReplyInput } from "./index-DdITDPea.js";
|
|
4
|
+
import { A as VerifyOptions, C as signStandardWebhooksPayload, D as PRIMITIVE_CONFIRMED_HEADER, E as LEGACY_SIGNATURE_HEADER, F as VerifyDownloadTokenResult, I as generateDownloadToken, L as verifyDownloadToken, M as verifyWebhookSignature, N as GenerateDownloadTokenOptions, O as PRIMITIVE_SIGNATURE_HEADER, P as VerifyDownloadTokenOptions, R as safeValidateEmailReceivedEvent, S as StandardWebhooksVerifyOptions, T as LEGACY_CONFIRMED_HEADER, _ as emailReceivedEventJsonSchema, a as confirmedHeaders, b as STANDARD_WEBHOOK_TIMESTAMP_HEADER, c as handleWebhook, d as isRawIncluded, f as parseWebhookEvent, g as validateEmailAuth, h as WEBHOOK_VERSION, i as WebhookHeaders, j as signWebhookPayload, k as SignResult, l as isDownloadExpired, m as verifyRawEmailDownload, n as HandleWebhookOptions, o as decodeRawEmail, p as receive, r as ReceiveRequestOptions, s as getDownloadTimeRemaining, t as DecodeRawEmailOptions, u as isEmailReceivedEvent, v as STANDARD_WEBHOOK_ID_HEADER, w as verifyStandardWebhooksSignature, x as StandardWebhooksSignResult, y as STANDARD_WEBHOOK_SIGNATURE_HEADER, z as validateEmailReceivedEvent } from "./index-Dbx9udpX.js";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
7
|
declare const primitive: {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as PrimitiveClient, c as createPrimitiveClient, i as PrimitiveApiError, o as client } from "./api-
|
|
3
|
-
import { A as PRIMITIVE_CONFIRMED_HEADER,
|
|
1
|
+
import { a as VERIFICATION_ERRORS, c as WebhookVerificationError, d as formatAddress, f as normalizeReceivedEmail, i as RawEmailDecodeError, l as buildForwardSubject, n as PrimitiveWebhookError, o as WebhookPayloadError, p as parseHeaderAddress, r as RAW_EMAIL_ERRORS, s as WebhookValidationError, t as PAYLOAD_ERRORS, u as buildReplySubject } from "./errors-x91I_yEt.js";
|
|
2
|
+
import { a as PrimitiveClient, c as createPrimitiveClient, i as PrimitiveApiError, o as client } from "./api-CoP5vKPK.js";
|
|
3
|
+
import { A as PRIMITIVE_CONFIRMED_HEADER, C as STANDARD_WEBHOOK_ID_HEADER, D as verifyStandardWebhooksSignature, E as signStandardWebhooksPayload, F as verifyDownloadToken, I as safeValidateEmailReceivedEvent, L as validateEmailReceivedEvent, M as signWebhookPayload, N as verifyWebhookSignature, O as LEGACY_CONFIRMED_HEADER, P as generateDownloadToken, S as emailReceivedEventJsonSchema, T as STANDARD_WEBHOOK_TIMESTAMP_HEADER, _ as DmarcResult, a as isDownloadExpired, b as ParsedStatus, c as parseWebhookEvent, d as WEBHOOK_VERSION, f as validateEmailAuth, g as DmarcPolicy, h as DkimResult, i as handleWebhook, j as PRIMITIVE_SIGNATURE_HEADER, k as LEGACY_SIGNATURE_HEADER, l as receive, m as AuthVerdict, n as decodeRawEmail, o as isEmailReceivedEvent, p as AuthConfidence, r as getDownloadTimeRemaining, s as isRawIncluded, t as confirmedHeaders, u as verifyRawEmailDownload, v as EventType, w as STANDARD_WEBHOOK_SIGNATURE_HEADER, x as SpfResult, y as ForwardVerdict } from "./webhook-DJkfUnFZ.js";
|
|
4
4
|
//#region src/index.ts
|
|
5
5
|
const primitive = {
|
|
6
6
|
client,
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// -----------------------------------------------------------------------------
|
|
2
|
+
// Error Definitions (Single Source of Truth)
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
/**
|
|
5
|
+
* Verification error definitions.
|
|
6
|
+
* Use these for documentation, dashboards, and i18n.
|
|
7
|
+
*/
|
|
8
|
+
export const VERIFICATION_ERRORS = {
|
|
9
|
+
INVALID_SIGNATURE_HEADER: {
|
|
10
|
+
message: "Missing or malformed Primitive-Signature header",
|
|
11
|
+
suggestion: "Check that you're reading the correct header (Primitive-Signature) and it's being passed correctly from your web framework.",
|
|
12
|
+
},
|
|
13
|
+
TIMESTAMP_OUT_OF_RANGE: {
|
|
14
|
+
message: "Timestamp is too old (possible replay attack)",
|
|
15
|
+
suggestion: "This could indicate a replay attack, network delay, or server clock drift. Check your server's time is synced.",
|
|
16
|
+
},
|
|
17
|
+
SIGNATURE_MISMATCH: {
|
|
18
|
+
message: "Signature doesn't match expected value",
|
|
19
|
+
suggestion: "Verify the webhook secret matches and you're using the raw request body (not re-serialized JSON).",
|
|
20
|
+
},
|
|
21
|
+
MISSING_SECRET: {
|
|
22
|
+
message: "No webhook secret was provided",
|
|
23
|
+
suggestion: "Pass your webhook secret from the Primitive dashboard. Check that the environment variable is set.",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Payload parsing error definitions.
|
|
28
|
+
* Use these for documentation, dashboards, and i18n.
|
|
29
|
+
*/
|
|
30
|
+
export const PAYLOAD_ERRORS = {
|
|
31
|
+
PAYLOAD_NULL: {
|
|
32
|
+
message: "Webhook payload is null",
|
|
33
|
+
suggestion: "Ensure you're passing the parsed JSON body, not null. Check your framework's body parsing middleware.",
|
|
34
|
+
},
|
|
35
|
+
PAYLOAD_UNDEFINED: {
|
|
36
|
+
message: "Webhook payload is undefined",
|
|
37
|
+
suggestion: "The payload was not provided. Make sure you're passing the request body to the handler.",
|
|
38
|
+
},
|
|
39
|
+
PAYLOAD_WRONG_TYPE: {
|
|
40
|
+
message: "Webhook payload must be an object",
|
|
41
|
+
suggestion: "The payload should be a parsed JSON object. Check that you're not passing a string or other primitive.",
|
|
42
|
+
},
|
|
43
|
+
PAYLOAD_IS_ARRAY: {
|
|
44
|
+
message: "Webhook payload is an array, expected object",
|
|
45
|
+
suggestion: "Primitive webhooks are single event objects, not arrays. Check the payload structure.",
|
|
46
|
+
},
|
|
47
|
+
PAYLOAD_MISSING_EVENT: {
|
|
48
|
+
message: "Webhook payload missing 'event' field",
|
|
49
|
+
suggestion: "All webhook payloads must have an 'event' field. This may not be a valid Primitive webhook.",
|
|
50
|
+
},
|
|
51
|
+
PAYLOAD_UNKNOWN_EVENT: {
|
|
52
|
+
message: "Unknown webhook event type",
|
|
53
|
+
suggestion: "This event type is not recognized. You may need to update your SDK or handle unknown events gracefully.",
|
|
54
|
+
},
|
|
55
|
+
PAYLOAD_EMPTY_BODY: {
|
|
56
|
+
message: "Request body is empty",
|
|
57
|
+
suggestion: "The request body was empty. Ensure the webhook is sending data and your framework is parsing it correctly.",
|
|
58
|
+
},
|
|
59
|
+
JSON_PARSE_FAILED: {
|
|
60
|
+
message: "Failed to parse JSON body",
|
|
61
|
+
suggestion: "The request body is not valid JSON. Check the raw body content and Content-Type header.",
|
|
62
|
+
},
|
|
63
|
+
INVALID_ENCODING: {
|
|
64
|
+
message: "Invalid body encoding",
|
|
65
|
+
suggestion: "The request body encoding is not supported. Primitive webhooks use UTF-8 encoded JSON.",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Raw email decode error definitions.
|
|
70
|
+
* Use these for documentation, dashboards, and i18n.
|
|
71
|
+
*/
|
|
72
|
+
export const RAW_EMAIL_ERRORS = {
|
|
73
|
+
NOT_INCLUDED: {
|
|
74
|
+
message: "Raw email content not included inline",
|
|
75
|
+
suggestion: "Use the download URL at event.email.content.download.url to fetch the raw email.",
|
|
76
|
+
},
|
|
77
|
+
INVALID_BASE64: {
|
|
78
|
+
message: "Raw email content is not valid base64",
|
|
79
|
+
suggestion: "The raw email data is malformed. Fetch the raw email from the download URL or regenerate the webhook payload.",
|
|
80
|
+
},
|
|
81
|
+
HASH_MISMATCH: {
|
|
82
|
+
message: "SHA-256 hash verification failed",
|
|
83
|
+
suggestion: "The raw email data may be corrupted. Try downloading from the URL instead.",
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Base class for all Primitive webhook errors.
|
|
88
|
+
*
|
|
89
|
+
* Catch this to handle any error from the SDK in a single catch block.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { handleWebhook, PrimitiveWebhookError } from '@primitivedotdev/sdk';
|
|
94
|
+
*
|
|
95
|
+
* try {
|
|
96
|
+
* const event = handleWebhook({ body, headers, secret });
|
|
97
|
+
* } catch (err) {
|
|
98
|
+
* if (err instanceof PrimitiveWebhookError) {
|
|
99
|
+
* console.error(`[${err.code}] ${err.message}`);
|
|
100
|
+
* return res.status(400).json({ error: err.code });
|
|
101
|
+
* }
|
|
102
|
+
* throw err;
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export class PrimitiveWebhookError extends Error {
|
|
107
|
+
/**
|
|
108
|
+
* Formats the error for logging/display.
|
|
109
|
+
*/
|
|
110
|
+
toString() {
|
|
111
|
+
return `${this.name} [${this.code}]: ${this.message}\n\nSuggestion: ${this.suggestion}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
115
|
+
*/
|
|
116
|
+
toJSON() {
|
|
117
|
+
return {
|
|
118
|
+
name: this.name,
|
|
119
|
+
code: this.code,
|
|
120
|
+
message: this.message,
|
|
121
|
+
suggestion: this.suggestion,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Error thrown when webhook signature verification fails.
|
|
127
|
+
*
|
|
128
|
+
* Use the `code` property to programmatically handle specific error cases.
|
|
129
|
+
*/
|
|
130
|
+
export class WebhookVerificationError extends PrimitiveWebhookError {
|
|
131
|
+
code;
|
|
132
|
+
suggestion;
|
|
133
|
+
constructor(code, message, suggestion) {
|
|
134
|
+
super(message ?? VERIFICATION_ERRORS[code].message);
|
|
135
|
+
this.name = "WebhookVerificationError";
|
|
136
|
+
this.code = code;
|
|
137
|
+
this.suggestion = suggestion ?? VERIFICATION_ERRORS[code].suggestion;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Error thrown when webhook payload parsing fails (lightweight parser).
|
|
142
|
+
*
|
|
143
|
+
* Use the `code` property for programmatic handling and monitoring.
|
|
144
|
+
* The `suggestion` property contains actionable guidance for fixing the issue.
|
|
145
|
+
*/
|
|
146
|
+
export class WebhookPayloadError extends PrimitiveWebhookError {
|
|
147
|
+
code;
|
|
148
|
+
suggestion;
|
|
149
|
+
/** Original error if this wraps another error (e.g., JSON.parse failure) */
|
|
150
|
+
cause;
|
|
151
|
+
constructor(code, message, suggestion, cause) {
|
|
152
|
+
super(message ?? PAYLOAD_ERRORS[code].message);
|
|
153
|
+
this.name = "WebhookPayloadError";
|
|
154
|
+
this.code = code;
|
|
155
|
+
this.suggestion = suggestion ?? PAYLOAD_ERRORS[code].suggestion;
|
|
156
|
+
this.cause = cause;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Error thrown when schema validation fails.
|
|
161
|
+
*/
|
|
162
|
+
export class WebhookValidationError extends PrimitiveWebhookError {
|
|
163
|
+
code = "SCHEMA_VALIDATION_FAILED";
|
|
164
|
+
suggestion;
|
|
165
|
+
/** The specific field path that failed (e.g., "email.headers.from") */
|
|
166
|
+
field;
|
|
167
|
+
/** Original schema validation errors for advanced debugging */
|
|
168
|
+
validationErrors;
|
|
169
|
+
/** Number of additional validation errors beyond the first */
|
|
170
|
+
additionalErrorCount;
|
|
171
|
+
constructor(field, message, suggestion, validationErrors) {
|
|
172
|
+
super(message);
|
|
173
|
+
this.name = "WebhookValidationError";
|
|
174
|
+
this.field = field;
|
|
175
|
+
this.suggestion = suggestion;
|
|
176
|
+
this.validationErrors = validationErrors;
|
|
177
|
+
this.additionalErrorCount = Math.max(0, validationErrors.length - 1);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Formats the error for logging/display.
|
|
181
|
+
* Includes error count and suggestion.
|
|
182
|
+
*/
|
|
183
|
+
toString() {
|
|
184
|
+
let output = `${this.name} [${this.code}]: ${this.message}`;
|
|
185
|
+
if (this.additionalErrorCount > 0) {
|
|
186
|
+
output += ` (and ${this.additionalErrorCount} more validation error${this.additionalErrorCount > 1 ? "s" : ""})`;
|
|
187
|
+
}
|
|
188
|
+
output += `\n\nSuggestion: ${this.suggestion}`;
|
|
189
|
+
return output;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Serializes cleanly for structured logging (Datadog, CloudWatch, etc.)
|
|
193
|
+
*/
|
|
194
|
+
toJSON() {
|
|
195
|
+
return {
|
|
196
|
+
name: this.name,
|
|
197
|
+
code: this.code,
|
|
198
|
+
field: this.field,
|
|
199
|
+
message: this.message,
|
|
200
|
+
suggestion: this.suggestion,
|
|
201
|
+
additionalErrorCount: this.additionalErrorCount,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// -----------------------------------------------------------------------------
|
|
206
|
+
// Raw Email Decode Errors
|
|
207
|
+
// -----------------------------------------------------------------------------
|
|
208
|
+
/**
|
|
209
|
+
* Error thrown when raw email decoding or verification fails.
|
|
210
|
+
*
|
|
211
|
+
* Use the `code` property to determine the failure reason:
|
|
212
|
+
* - `NOT_INCLUDED`: Raw email not inline, must download from URL
|
|
213
|
+
* - `HASH_MISMATCH`: SHA-256 verification failed, content may be corrupted
|
|
214
|
+
*/
|
|
215
|
+
export class RawEmailDecodeError extends PrimitiveWebhookError {
|
|
216
|
+
code;
|
|
217
|
+
suggestion;
|
|
218
|
+
constructor(code, message) {
|
|
219
|
+
super(message ?? RAW_EMAIL_ERRORS[code].message);
|
|
220
|
+
this.name = "RawEmailDecodeError";
|
|
221
|
+
this.code = code;
|
|
222
|
+
this.suggestion = RAW_EMAIL_ERRORS[code].suggestion;
|
|
223
|
+
}
|
|
224
|
+
}
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { A as UnknownEvent, C as ParsedDataFailed, D as RawContentDownloadOnly, E as RawContent, M as WebhookAttachment, N as WebhookEvent, O as RawContentInline, S as ParsedDataComplete, T as ParsedStatus, _ as ForwardResultInline, a as DmarcPolicy, b as KnownWebhookEvent, c as EmailAnalysis, d as EventType, f as ForwardAnalysis, g as ForwardResultAttachmentSkipped, h as ForwardResultAttachmentAnalyzed, i as DkimSignature, j as ValidateEmailAuthResult, k as SpfResult, l as EmailAuth, m as ForwardResult, n as AuthVerdict, o as DmarcResult, p as ForwardOriginalSender, r as DkimResult, s as EmailAddress, t as AuthConfidence, u as EmailReceivedEvent, v as ForwardVerdict, w as ParsedError, x as ParsedData, y as ForwardVerification } from "../types-9vXGZjPd.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { A as VerifyOptions,
|
|
2
|
+
import { _ as buildForwardSubject, a as RawEmailDecodeErrorCode, b as normalizeReceivedEmail, c as WebhookPayloadError, d as WebhookValidationErrorCode, f as WebhookVerificationError, g as ReceivedEmailThread, h as ReceivedEmailAddress, i as RawEmailDecodeError, l as WebhookPayloadErrorCode, m as ReceivedEmail, n as PrimitiveWebhookError, o as VERIFICATION_ERRORS, p as WebhookVerificationErrorCode, r as RAW_EMAIL_ERRORS, s as WebhookErrorCode, t as PAYLOAD_ERRORS, u as WebhookValidationError, v as buildReplySubject, x as parseHeaderAddress, y as formatAddress } from "../errors-C53fe686.js";
|
|
3
|
+
import { A as VerifyOptions, C as signStandardWebhooksPayload, D as PRIMITIVE_CONFIRMED_HEADER, E as LEGACY_SIGNATURE_HEADER, F as VerifyDownloadTokenResult, I as generateDownloadToken, L as verifyDownloadToken, M as verifyWebhookSignature, N as GenerateDownloadTokenOptions, O as PRIMITIVE_SIGNATURE_HEADER, P as VerifyDownloadTokenOptions, R as safeValidateEmailReceivedEvent, S as StandardWebhooksVerifyOptions, T as LEGACY_CONFIRMED_HEADER, _ as emailReceivedEventJsonSchema, a as confirmedHeaders, b as STANDARD_WEBHOOK_TIMESTAMP_HEADER, c as handleWebhook, d as isRawIncluded, f as parseWebhookEvent, g as validateEmailAuth, h as WEBHOOK_VERSION, i as WebhookHeaders, j as signWebhookPayload, k as SignResult, l as isDownloadExpired, m as verifyRawEmailDownload, n as HandleWebhookOptions, o as decodeRawEmail, p as receive, r as ReceiveRequestOptions, s as getDownloadTimeRemaining, t as DecodeRawEmailOptions, u as isEmailReceivedEvent, v as STANDARD_WEBHOOK_ID_HEADER, w as verifyStandardWebhooksSignature, x as StandardWebhooksSignResult, y as STANDARD_WEBHOOK_SIGNATURE_HEADER, z as validateEmailReceivedEvent } from "../index-Dbx9udpX.js";
|
|
4
4
|
export { AuthConfidence, AuthVerdict, DecodeRawEmailOptions, DkimResult, DkimSignature, DmarcPolicy, DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict, ForwardVerification, GenerateDownloadTokenOptions, HandleWebhookOptions, KnownWebhookEvent, LEGACY_CONFIRMED_HEADER, LEGACY_SIGNATURE_HEADER, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedData, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawContent, RawContentDownloadOnly, RawContentInline, RawEmailDecodeError, RawEmailDecodeErrorCode, ReceiveRequestOptions, ReceivedEmail, ReceivedEmailAddress, ReceivedEmailThread, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, SpfResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, UnknownEvent, VERIFICATION_ERRORS, ValidateEmailAuthResult, VerifyDownloadTokenOptions, VerifyDownloadTokenResult, VerifyOptions, WEBHOOK_VERSION, WebhookAttachment, WebhookErrorCode, WebhookEvent, WebhookHeaders, WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError, WebhookVerificationErrorCode, buildForwardSubject, buildReplySubject, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, formatAddress, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, normalizeReceivedEmail, parseHeaderAddress, parseWebhookEvent, receive, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|