@primitivedotdev/sdk 0.8.0 → 0.10.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/README.md +22 -0
- package/dist/{address-parser-CfPHs3mE.js → address-parser-BYn8oW5r.js} +1 -3
- package/dist/api/generated/index.js +1 -1
- package/dist/api/generated/sdk.gen.js +26 -0
- package/dist/api/index.d.ts +2 -4
- package/dist/api/index.js +72 -33
- package/dist/{api-BH8PnmHs.js → api-CLLpjjWy.js} +142 -113
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/contract/index.d.ts +6 -9
- package/dist/contract/index.js +28 -17
- package/dist/{index-CuuP1JkG.d.ts → index-CbEivn3S.d.ts} +7 -31
- package/dist/{index-D9lanVFt.d.ts → index-K4KbjppU.d.ts} +266 -56
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -8
- package/dist/oclif/api-command.js +89 -1
- package/dist/openapi/index.d.ts +8 -3
- package/dist/openapi/openapi.generated.js +191 -5
- package/dist/openapi/operations.generated.js +288 -0
- package/dist/parser/index.d.ts +4 -19
- package/dist/parser/index.js +7 -18
- package/dist/{received-email-Q6Cha3wc.js → received-email-D6tKtWwW.js} +2 -4
- package/dist/{received-email-C67Z7Dha.d.ts → received-email-DNjpq_Wt.d.ts} +4 -3
- package/dist/{types-CIOzt1FY.d.ts → types-9vXGZjPd.d.ts} +3 -19
- package/dist/webhook/index.d.ts +3 -3
- package/dist/webhook/index.js +3 -5
- package/dist/{webhook-2TALcBQz.js → webhook-zkN4wUTs.js} +107 -84
- package/oclif.manifest.json +63 -9
- package/package.json +2 -2
- package/dist/chunk-Cl8Af3a2.js +0 -11
|
@@ -17,13 +17,6 @@
|
|
|
17
17
|
* via the `definition` "ForwardResult".
|
|
18
18
|
*/
|
|
19
19
|
type ForwardResult$1 = (ForwardResultInline$1 | ForwardResultAttachmentAnalyzed$1 | ForwardResultAttachmentSkipped$1);
|
|
20
|
-
/**
|
|
21
|
-
* Valid webhook version format (YYYY-MM-DD date string). The SDK accepts any valid date-formatted version, not just the current one, for forward and backward compatibility.
|
|
22
|
-
*
|
|
23
|
-
* This interface was referenced by `EmailReceivedEvent`'s JSON-Schema
|
|
24
|
-
* via the `definition` "WebhookVersion".
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
20
|
/**
|
|
28
21
|
* Webhook payload for the `email.received` event.
|
|
29
22
|
*
|
|
@@ -693,17 +686,9 @@ interface DkimSignature$1 {
|
|
|
693
686
|
* Optional in self-hosted environments.
|
|
694
687
|
*/
|
|
695
688
|
algo: (string | null);
|
|
696
|
-
}
|
|
689
|
+
}
|
|
690
|
+
//#endregion
|
|
697
691
|
//#region src/types.d.ts
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Webhook payload for the `email.received` event.
|
|
701
|
-
*
|
|
702
|
-
* This is delivered to your webhook endpoint when Primitive receives an email matching your domain configuration.
|
|
703
|
-
*
|
|
704
|
-
* This interface was referenced by `EmailReceivedEvent`'s JSON-Schema
|
|
705
|
-
* via the `definition` "EmailReceivedEvent".
|
|
706
|
-
*/
|
|
707
692
|
type EmailReceivedEvent = EmailReceivedEvent$1;
|
|
708
693
|
type EventType = EmailReceivedEvent["event"];
|
|
709
694
|
declare const EventType: {
|
|
@@ -814,6 +799,5 @@ interface UnknownEvent {
|
|
|
814
799
|
}
|
|
815
800
|
type KnownWebhookEvent = EmailReceivedEvent;
|
|
816
801
|
type WebhookEvent = KnownWebhookEvent | UnknownEvent;
|
|
817
|
-
|
|
818
802
|
//#endregion
|
|
819
|
-
export {
|
|
803
|
+
export { UnknownEvent as A, ParsedDataFailed as C, RawContentDownloadOnly as D, RawContent as E, WebhookAttachment as M, WebhookEvent as N, RawContentInline as O, ParsedDataComplete as S, ParsedStatus as T, ForwardResultInline as _, DmarcPolicy as a, KnownWebhookEvent as b, EmailAnalysis as c, EventType as d, ForwardAnalysis as f, ForwardResultAttachmentSkipped as g, ForwardResultAttachmentAnalyzed as h, DkimSignature as i, ValidateEmailAuthResult as j, SpfResult as k, EmailAuth as l, ForwardResult as m, AuthVerdict as n, DmarcResult as o, ForwardOriginalSender as p, DkimResult as r, EmailAddress as s, AuthConfidence as t, EmailReceivedEvent as u, ForwardVerdict as v, ParsedError as w, ParsedData as x, ForwardVerification as y };
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 buildReplySubject, c as parseHeaderAddress, i as buildForwardSubject, n as ReceivedEmailAddress, o as formatAddress, r as ReceivedEmailThread, s as normalizeReceivedEmail, t as ReceivedEmail } from "../received-email-DNjpq_Wt.js";
|
|
3
|
+
import { A as VerifyOptions, B as PAYLOAD_ERRORS, C as signStandardWebhooksPayload, D as PRIMITIVE_CONFIRMED_HEADER, E as LEGACY_SIGNATURE_HEADER, F as VerifyDownloadTokenResult, G as VERIFICATION_ERRORS, H as RAW_EMAIL_ERRORS, I as generateDownloadToken, J as WebhookPayloadErrorCode, K as WebhookErrorCode, L as verifyDownloadToken, M as verifyWebhookSignature, N as GenerateDownloadTokenOptions, O as PRIMITIVE_SIGNATURE_HEADER, P as VerifyDownloadTokenOptions, Q as WebhookVerificationErrorCode, R as safeValidateEmailReceivedEvent, S as StandardWebhooksVerifyOptions, T as LEGACY_CONFIRMED_HEADER, U as RawEmailDecodeError, V as PrimitiveWebhookError, W as RawEmailDecodeErrorCode, X as WebhookValidationErrorCode, Y as WebhookValidationError, Z as WebhookVerificationError, _ 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, q as WebhookPayloadError, 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-CbEivn3S.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 };
|
package/dist/webhook/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, LEGACY_CONFIRMED_HEADER, LEGACY_SIGNATURE_HEADER, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, 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 };
|
|
1
|
+
import { a as parseHeaderAddress, i as normalizeReceivedEmail, n as buildReplySubject, r as formatAddress, t as buildForwardSubject } from "../received-email-D6tKtWwW.js";
|
|
2
|
+
import { A as PRIMITIVE_CONFIRMED_HEADER, B as RAW_EMAIL_ERRORS, C as STANDARD_WEBHOOK_ID_HEADER, D as verifyStandardWebhooksSignature, E as signStandardWebhooksPayload, F as verifyDownloadToken, G as WebhookVerificationError, H as VERIFICATION_ERRORS, I as safeValidateEmailReceivedEvent, L as validateEmailReceivedEvent, M as signWebhookPayload, N as verifyWebhookSignature, O as LEGACY_CONFIRMED_HEADER, P as generateDownloadToken, R as PAYLOAD_ERRORS, S as emailReceivedEventJsonSchema, T as STANDARD_WEBHOOK_TIMESTAMP_HEADER, U as WebhookPayloadError, V as RawEmailDecodeError, W as WebhookValidationError, _ 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, z as PrimitiveWebhookError } from "../webhook-zkN4wUTs.js";
|
|
3
|
+
export { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, LEGACY_CONFIRMED_HEADER, LEGACY_SIGNATURE_HEADER, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, 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 };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { normalizeReceivedEmail } from "./received-email-
|
|
1
|
+
import { i as normalizeReceivedEmail } from "./received-email-D6tKtWwW.js";
|
|
2
2
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
3
|
-
|
|
4
3
|
//#region src/generated/email-received-event.validator.generated.ts
|
|
4
|
+
/**
|
|
5
|
+
* AUTO-GENERATED - DO NOT EDIT
|
|
6
|
+
* Run `pnpm generate:validator` to regenerate.
|
|
7
|
+
*/
|
|
5
8
|
var email_received_event_validator_generated_default = validate10;
|
|
6
9
|
const schema12 = {
|
|
7
10
|
"type": "object",
|
|
@@ -183,12 +186,12 @@ const schema12 = {
|
|
|
183
186
|
],
|
|
184
187
|
"description": "Webhook payload for the `email.received` event.\n\nThis is delivered to your webhook endpoint when Primitive receives an email matching your domain configuration."
|
|
185
188
|
};
|
|
186
|
-
const pattern0 = new RegExp("^evt_[a-f0-9]{64}$", "u");
|
|
187
|
-
const pattern1 = new RegExp("^(?:(?:\\d{4}-(?:(?:01|03|05|07|08|10|12)-(?:0[1-9]|[12]\\d|3[01])|(?:04|06|09|11)-(?:0[1-9]|[12]\\d|30)|02-(?:0[1-9]|1\\d|2[0-8])))|(?:(?:[02468][048]00|[13579][26]00|\\d{2}(?:0[48]|[2468][048]|[13579][26]))-02-29))$", "u");
|
|
188
|
-
const pattern4 = new RegExp("^https?://", "u");
|
|
189
|
+
const pattern0 = /* @__PURE__ */ new RegExp("^evt_[a-f0-9]{64}$", "u");
|
|
190
|
+
const pattern1 = /* @__PURE__ */ new RegExp("^(?:(?:\\d{4}-(?:(?:01|03|05|07|08|10|12)-(?:0[1-9]|[12]\\d|3[01])|(?:04|06|09|11)-(?:0[1-9]|[12]\\d|30)|02-(?:0[1-9]|1\\d|2[0-8])))|(?:(?:[02468][048]00|[13579][26]00|\\d{2}(?:0[48]|[2468][048]|[13579][26]))-02-29))$", "u");
|
|
191
|
+
const pattern4 = /* @__PURE__ */ new RegExp("^https?://", "u");
|
|
189
192
|
const formats0 = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])[T\t ](?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):?[0-5]\d)$/;
|
|
190
193
|
const formats4 = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
191
|
-
const pattern2 = new RegExp("^[a-fA-F0-9]{64}$", "u");
|
|
194
|
+
const pattern2 = /* @__PURE__ */ new RegExp("^[a-fA-F0-9]{64}$", "u");
|
|
192
195
|
function validate12(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
193
196
|
let vErrors = null;
|
|
194
197
|
let errors = 0;
|
|
@@ -5628,7 +5631,6 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
5628
5631
|
validate10.errors = vErrors;
|
|
5629
5632
|
return errors === 0;
|
|
5630
5633
|
}
|
|
5631
|
-
|
|
5632
5634
|
//#endregion
|
|
5633
5635
|
//#region src/webhook/errors.ts
|
|
5634
5636
|
/**
|
|
@@ -5847,7 +5849,6 @@ var RawEmailDecodeError = class extends PrimitiveWebhookError {
|
|
|
5847
5849
|
this.suggestion = RAW_EMAIL_ERRORS[code].suggestion;
|
|
5848
5850
|
}
|
|
5849
5851
|
};
|
|
5850
|
-
|
|
5851
5852
|
//#endregion
|
|
5852
5853
|
//#region src/validation.ts
|
|
5853
5854
|
const validateSchema = email_received_event_validator_generated_default;
|
|
@@ -5871,7 +5872,7 @@ function resolveValueAtPath(input, instancePath) {
|
|
|
5871
5872
|
current = current[key];
|
|
5872
5873
|
continue;
|
|
5873
5874
|
}
|
|
5874
|
-
return
|
|
5875
|
+
return;
|
|
5875
5876
|
}
|
|
5876
5877
|
return current;
|
|
5877
5878
|
}
|
|
@@ -5942,10 +5943,9 @@ function formatValidationIssue(error, input) {
|
|
|
5942
5943
|
}
|
|
5943
5944
|
case "format": {
|
|
5944
5945
|
const format = String(error.params.format ?? "unknown format");
|
|
5945
|
-
const humanFormat = format === "uri" ? "valid URI" : `valid ${format}`;
|
|
5946
5946
|
return {
|
|
5947
5947
|
field,
|
|
5948
|
-
message: `Invalid value for ${field}: must be a ${
|
|
5948
|
+
message: `Invalid value for ${field}: must be a ${format === "uri" ? "valid URI" : `valid ${format}`}`,
|
|
5949
5949
|
suggestion: field.endsWith("url") ? `Check that ${fromFieldLabel(field)} is a complete URL including the scheme.` : `Check the format of ${fromFieldLabel(field)} in the webhook payload.`
|
|
5950
5950
|
};
|
|
5951
5951
|
}
|
|
@@ -5980,10 +5980,9 @@ function formatValidationIssue(error, input) {
|
|
|
5980
5980
|
}
|
|
5981
5981
|
case "minItems": {
|
|
5982
5982
|
const limit = Number(error.params.limit ?? 0);
|
|
5983
|
-
const itemLabel = limit === 1 ? "item" : "items";
|
|
5984
5983
|
return {
|
|
5985
5984
|
field,
|
|
5986
|
-
message: `Invalid value for ${field}: must have at least ${limit} ${
|
|
5985
|
+
message: `Invalid value for ${field}: must have at least ${limit} ${limit === 1 ? "item" : "items"}`,
|
|
5987
5986
|
suggestion: `Add more entries to ${fromFieldLabel(field)} in the webhook payload.`
|
|
5988
5987
|
};
|
|
5989
5988
|
}
|
|
@@ -6000,22 +5999,16 @@ function formatValidationIssue(error, input) {
|
|
|
6000
5999
|
suggestion: `Check that ${fromFieldLabel(field)} meets the minimum length requirement.`
|
|
6001
6000
|
};
|
|
6002
6001
|
}
|
|
6003
|
-
case "minimum": {
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
return {
|
|
6014
|
-
field,
|
|
6015
|
-
message: `Invalid value for ${field}: must be <= ${limit}`,
|
|
6016
|
-
suggestion: `Check that ${fromFieldLabel(field)} stays within the maximum allowed value.`
|
|
6017
|
-
};
|
|
6018
|
-
}
|
|
6002
|
+
case "minimum": return {
|
|
6003
|
+
field,
|
|
6004
|
+
message: `Invalid value for ${field}: must be >= ${Number(error.params.limit ?? 0)}`,
|
|
6005
|
+
suggestion: `Check that ${fromFieldLabel(field)} meets the minimum allowed value.`
|
|
6006
|
+
};
|
|
6007
|
+
case "maximum": return {
|
|
6008
|
+
field,
|
|
6009
|
+
message: `Invalid value for ${field}: must be <= ${Number(error.params.limit ?? 0)}`,
|
|
6010
|
+
suggestion: `Check that ${fromFieldLabel(field)} stays within the maximum allowed value.`
|
|
6011
|
+
};
|
|
6019
6012
|
default: return {
|
|
6020
6013
|
field,
|
|
6021
6014
|
message: `Validation failed for ${field}: ${error.message ?? error.keyword}`,
|
|
@@ -6043,9 +6036,31 @@ function safeValidateEmailReceivedEvent(input) {
|
|
|
6043
6036
|
data: input
|
|
6044
6037
|
};
|
|
6045
6038
|
}
|
|
6046
|
-
|
|
6047
6039
|
//#endregion
|
|
6048
6040
|
//#region src/webhook/download-tokens.ts
|
|
6041
|
+
/**
|
|
6042
|
+
* Signed download tokens.
|
|
6043
|
+
*
|
|
6044
|
+
* A download token is a self-describing bearer credential for fetching a
|
|
6045
|
+
* specific email's raw bytes or attachment bundle from a per-deployment
|
|
6046
|
+
* download endpoint. It binds:
|
|
6047
|
+
*
|
|
6048
|
+
* - `email_id` — the specific email the token authorizes.
|
|
6049
|
+
* - `aud` — a caller-chosen audience label (e.g. the resource kind being
|
|
6050
|
+
* downloaded). Tokens minted for one audience will not verify under another.
|
|
6051
|
+
* - `exp` — an absolute expiration time (unix seconds).
|
|
6052
|
+
*
|
|
6053
|
+
* Format: `<base64url(payload)>.<base64url(signature)>` where `signature`
|
|
6054
|
+
* is HMAC-SHA256 over the base64url-encoded payload using the shared secret.
|
|
6055
|
+
*
|
|
6056
|
+
* The audience is an opaque caller-chosen string. Both the issuer and the
|
|
6057
|
+
* verifier must agree on the exact bytes; the SDK does not prescribe a
|
|
6058
|
+
* convention. New integrations are encouraged to namespace audiences
|
|
6059
|
+
* (e.g. `primitive:raw-download`).
|
|
6060
|
+
*
|
|
6061
|
+
* Tokens are stateless: verification needs only the shared secret. Keep
|
|
6062
|
+
* expirations as short as operationally tolerable.
|
|
6063
|
+
*/
|
|
6049
6064
|
const BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
6050
6065
|
/**
|
|
6051
6066
|
* Issue a signed download token.
|
|
@@ -6060,15 +6075,13 @@ const BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
|
6060
6075
|
*/
|
|
6061
6076
|
function generateDownloadToken(params) {
|
|
6062
6077
|
const { emailId, expiresAt, audience, secret } = params;
|
|
6063
|
-
const
|
|
6078
|
+
const payloadJson = JSON.stringify({
|
|
6064
6079
|
email_id: emailId,
|
|
6065
6080
|
exp: expiresAt,
|
|
6066
6081
|
aud: audience
|
|
6067
|
-
};
|
|
6068
|
-
const payloadJson = JSON.stringify(payload);
|
|
6082
|
+
});
|
|
6069
6083
|
const payloadStr = Buffer.from(payloadJson, "utf8").toString("base64url");
|
|
6070
|
-
|
|
6071
|
-
return `${payloadStr}.${signature}`;
|
|
6084
|
+
return `${payloadStr}.${createHmac("sha256", secret).update(payloadStr).digest("base64url")}`;
|
|
6072
6085
|
}
|
|
6073
6086
|
/**
|
|
6074
6087
|
* Verify a signed download token.
|
|
@@ -6132,16 +6145,17 @@ function verifyDownloadToken(params) {
|
|
|
6132
6145
|
valid: false,
|
|
6133
6146
|
error: "Email ID mismatch"
|
|
6134
6147
|
};
|
|
6135
|
-
|
|
6136
|
-
if (exp <= now) return {
|
|
6148
|
+
if (exp <= (nowSeconds ?? Math.floor(Date.now() / 1e3))) return {
|
|
6137
6149
|
valid: false,
|
|
6138
6150
|
error: "Token is expired"
|
|
6139
6151
|
};
|
|
6140
6152
|
return { valid: true };
|
|
6141
6153
|
}
|
|
6142
|
-
|
|
6143
6154
|
//#endregion
|
|
6144
6155
|
//#region src/webhook/encoding.ts
|
|
6156
|
+
/**
|
|
6157
|
+
* Buffer encoding utilities
|
|
6158
|
+
*/
|
|
6145
6159
|
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
6146
6160
|
/**
|
|
6147
6161
|
* Convert a Buffer to string with strict UTF-8 validation.
|
|
@@ -6162,15 +6176,28 @@ function bufferToString(buffer, label) {
|
|
|
6162
6176
|
throw new WebhookPayloadError("INVALID_ENCODING", `${label} contains invalid UTF-8 bytes`, `Ensure the ${label} is valid UTF-8 encoded text. If the data is binary, it should be base64 encoded first.`, err instanceof Error ? err : void 0);
|
|
6163
6177
|
}
|
|
6164
6178
|
}
|
|
6165
|
-
|
|
6166
6179
|
//#endregion
|
|
6167
6180
|
//#region src/webhook/signing.ts
|
|
6168
6181
|
/**
|
|
6182
|
+
* Webhook HMAC Signing (Stripe-style format)
|
|
6183
|
+
*
|
|
6184
|
+
* Implements HMAC-SHA256 signature for webhook security with timestamp validation.
|
|
6185
|
+
* Prevents replay attacks by including timestamp in signature.
|
|
6186
|
+
*
|
|
6187
|
+
* Header format:
|
|
6188
|
+
* Primitive-Signature: t=<unix_seconds>,v1=<hex_hmac_sha256>
|
|
6189
|
+
*
|
|
6190
|
+
* Signed payload format: "{timestamp}.{raw_body}"
|
|
6191
|
+
*
|
|
6192
|
+
* This format matches Stripe's webhook signature scheme, which is widely understood
|
|
6193
|
+
* and easy to implement in any language with ~15 lines of code.
|
|
6194
|
+
*/
|
|
6195
|
+
/**
|
|
6169
6196
|
* WeakMap cache for computed signatures.
|
|
6170
6197
|
* Only works for Buffer bodies (strings cannot be WeakMap keys).
|
|
6171
6198
|
* Automatically garbage collected when Buffer is no longer referenced.
|
|
6172
6199
|
*/
|
|
6173
|
-
const signatureCache = new WeakMap();
|
|
6200
|
+
const signatureCache = /* @__PURE__ */ new WeakMap();
|
|
6174
6201
|
/**
|
|
6175
6202
|
* Hash a secret for cache key comparison.
|
|
6176
6203
|
* @internal
|
|
@@ -6187,7 +6214,7 @@ const PRIMITIVE_CONFIRMED_HEADER = "X-Primitive-Confirmed";
|
|
|
6187
6214
|
/** Legacy confirmed header name kept for backward compatibility */
|
|
6188
6215
|
const LEGACY_CONFIRMED_HEADER = "X-MyMX-Confirmed";
|
|
6189
6216
|
/** Default max age for webhook requests (5 minutes) */
|
|
6190
|
-
const DEFAULT_TOLERANCE_SECONDS$1 =
|
|
6217
|
+
const DEFAULT_TOLERANCE_SECONDS$1 = 300;
|
|
6191
6218
|
/** Future clock skew tolerance (1 minute) */
|
|
6192
6219
|
const FUTURE_TOLERANCE_SECONDS$1 = 60;
|
|
6193
6220
|
/** Valid hex pattern for signature verification */
|
|
@@ -6208,8 +6235,7 @@ const UNIX_SECONDS_PATTERN = /^\d+$/;
|
|
|
6208
6235
|
*/
|
|
6209
6236
|
function signWebhookPayload(rawBody, secret, timestamp) {
|
|
6210
6237
|
const ts = timestamp ?? Math.floor(Date.now() / 1e3);
|
|
6211
|
-
const
|
|
6212
|
-
const signedPayloadString = `${ts}.${body}`;
|
|
6238
|
+
const signedPayloadString = `${ts}.${typeof rawBody === "string" ? rawBody : bufferToString(rawBody, "rawBody")}`;
|
|
6213
6239
|
const hmac = createHmac("sha256", secret);
|
|
6214
6240
|
hmac.update(signedPayloadString);
|
|
6215
6241
|
const v1 = hmac.digest("hex");
|
|
@@ -6288,8 +6314,7 @@ function verifyWebhookSignature(opts) {
|
|
|
6288
6314
|
const parsed = parseSignatureHeader(signatureHeader);
|
|
6289
6315
|
if (!parsed) throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", "Invalid Primitive-Signature header format. Expected: t={timestamp},v1={signature}");
|
|
6290
6316
|
const { timestamp, signatures } = parsed;
|
|
6291
|
-
const
|
|
6292
|
-
const age = now - timestamp;
|
|
6317
|
+
const age = (nowSeconds ?? Math.floor(Date.now() / 1e3)) - timestamp;
|
|
6293
6318
|
if (age > toleranceSeconds) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", `Webhook timestamp too old (${age}s). Max age is ${toleranceSeconds}s.`);
|
|
6294
6319
|
if (age < -FUTURE_TOLERANCE_SECONDS$1) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", "Webhook timestamp is too far in the future. Check server clock sync.");
|
|
6295
6320
|
const body = typeof rawBody === "string" ? rawBody : bufferToString(rawBody, "request body");
|
|
@@ -6318,13 +6343,10 @@ function verifyWebhookSignature(opts) {
|
|
|
6318
6343
|
}
|
|
6319
6344
|
for (const receivedHex of signatures) {
|
|
6320
6345
|
if (!isValidHex(receivedHex, 64)) continue;
|
|
6321
|
-
|
|
6322
|
-
const expectedBytes = Buffer.from(expectedHex, "hex");
|
|
6323
|
-
if (timingSafeEqual(receivedBytes, expectedBytes)) return true;
|
|
6346
|
+
if (timingSafeEqual(Buffer.from(receivedHex, "hex"), Buffer.from(expectedHex, "hex"))) return true;
|
|
6324
6347
|
}
|
|
6325
6348
|
const reserializationHint = detectReserializedBody(body);
|
|
6326
|
-
|
|
6327
|
-
throw new WebhookVerificationError("SIGNATURE_MISMATCH", message);
|
|
6349
|
+
throw new WebhookVerificationError("SIGNATURE_MISMATCH", reserializationHint ? `No valid signature found. ${reserializationHint}` : "No valid signature found. Verify the webhook secret matches and you're using the raw request body (not re-serialized JSON).");
|
|
6328
6350
|
}
|
|
6329
6351
|
/**
|
|
6330
6352
|
* Detect if a body looks like it was re-serialized by a framework.
|
|
@@ -6335,13 +6357,27 @@ function detectReserializedBody(body) {
|
|
|
6335
6357
|
if (/^\s*\{[\s\S]*\n\s{2,}/.test(body)) return "Request body appears re-serialized (pretty-printed). Use the raw request body before any JSON.parse() or JSON.stringify() calls.";
|
|
6336
6358
|
return null;
|
|
6337
6359
|
}
|
|
6338
|
-
|
|
6339
6360
|
//#endregion
|
|
6340
6361
|
//#region src/webhook/standard-webhooks.ts
|
|
6362
|
+
/**
|
|
6363
|
+
* Standard Webhooks Verification & Signing
|
|
6364
|
+
*
|
|
6365
|
+
* Implements the Standard Webhooks spec (standardwebhooks.com) for webhook
|
|
6366
|
+
* signature verification and payload signing.
|
|
6367
|
+
*
|
|
6368
|
+
* Header format:
|
|
6369
|
+
* webhook-id: <msg_id>
|
|
6370
|
+
* webhook-timestamp: <unix_seconds>
|
|
6371
|
+
* webhook-signature: v1,<base64_hmac_sha256> [v1,<base64_2> ...]
|
|
6372
|
+
*
|
|
6373
|
+
* Signed payload format: "{msg_id}.{timestamp}.{raw_body}"
|
|
6374
|
+
*
|
|
6375
|
+
* Secrets are base64-encoded, optionally prefixed with "whsec_".
|
|
6376
|
+
*/
|
|
6341
6377
|
const WHSEC_PREFIX = "whsec_";
|
|
6342
6378
|
const BASE64_PATTERN$1 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
6343
6379
|
/** Default max age for webhook requests (5 minutes) */
|
|
6344
|
-
const DEFAULT_TOLERANCE_SECONDS =
|
|
6380
|
+
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
6345
6381
|
/** Future clock skew tolerance (1 minute) */
|
|
6346
6382
|
const FUTURE_TOLERANCE_SECONDS = 60;
|
|
6347
6383
|
/** Standard Webhooks header names */
|
|
@@ -6362,7 +6398,7 @@ function prepareStandardWebhooksSecret(secret) {
|
|
|
6362
6398
|
return secret;
|
|
6363
6399
|
}
|
|
6364
6400
|
let keyStr = secret;
|
|
6365
|
-
if (keyStr.startsWith(WHSEC_PREFIX)) keyStr = keyStr.slice(
|
|
6401
|
+
if (keyStr.startsWith(WHSEC_PREFIX)) keyStr = keyStr.slice(6);
|
|
6366
6402
|
if (!keyStr || !BASE64_PATTERN$1.test(keyStr)) throw new WebhookVerificationError("MISSING_SECRET", "Standard Webhooks secret must be base64-encoded (optionally with whsec_ prefix)");
|
|
6367
6403
|
const decoded = Buffer.from(keyStr, "base64");
|
|
6368
6404
|
if (decoded.length === 0) throw new WebhookVerificationError("MISSING_SECRET", "Webhook secret is required but was empty or not provided");
|
|
@@ -6404,9 +6440,8 @@ function signStandardWebhooksPayload(rawBody, secret, msgId, timestamp) {
|
|
|
6404
6440
|
const key = prepareStandardWebhooksSecret(secret);
|
|
6405
6441
|
if (key.length === 0) throw new WebhookVerificationError("MISSING_SECRET", "Webhook secret is required but was empty or not provided");
|
|
6406
6442
|
const signedPayload = `${msgId}.${ts}.${body}`;
|
|
6407
|
-
const sig = createHmac("sha256", key).update(signedPayload).digest("base64");
|
|
6408
6443
|
return {
|
|
6409
|
-
signature: `v1,${
|
|
6444
|
+
signature: `v1,${createHmac("sha256", key).update(signedPayload).digest("base64")}`,
|
|
6410
6445
|
msgId,
|
|
6411
6446
|
timestamp: ts
|
|
6412
6447
|
};
|
|
@@ -6423,12 +6458,10 @@ function verifyStandardWebhooksSignature(opts) {
|
|
|
6423
6458
|
if (!timestampStr || !/^\d+$/.test(timestampStr)) throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", `Invalid webhook-timestamp header: "${timestampStr}". Expected a unix timestamp in seconds`);
|
|
6424
6459
|
const timestamp = Number(timestampStr);
|
|
6425
6460
|
if (!Number.isInteger(timestamp) || timestamp < 0) throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", `Invalid webhook-timestamp header: "${timestampStr}". Expected a unix timestamp in seconds`);
|
|
6426
|
-
const
|
|
6427
|
-
const age = now - timestamp;
|
|
6461
|
+
const age = (nowSeconds ?? Math.floor(Date.now() / 1e3)) - timestamp;
|
|
6428
6462
|
if (age > toleranceSeconds) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", `Webhook timestamp too old (${age}s). Max age is ${toleranceSeconds}s.`);
|
|
6429
6463
|
if (age < -FUTURE_TOLERANCE_SECONDS) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", "Webhook timestamp is too far in the future. Check server clock sync.");
|
|
6430
|
-
const
|
|
6431
|
-
const signedPayload = `${msgId}.${timestamp}.${body}`;
|
|
6464
|
+
const signedPayload = `${msgId}.${timestamp}.${typeof rawBody === "string" ? rawBody : bufferToString(rawBody, "request body")}`;
|
|
6432
6465
|
const expectedSig = createHmac("sha256", key).update(signedPayload).digest("base64");
|
|
6433
6466
|
const signatures = parseStandardWebhooksSignatures(signatureHeader);
|
|
6434
6467
|
if (signatures.length === 0) throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", "Invalid webhook-signature header format. Expected: \"v1,<base64>\"");
|
|
@@ -6440,7 +6473,6 @@ function verifyStandardWebhooksSignature(opts) {
|
|
|
6440
6473
|
}
|
|
6441
6474
|
throw new WebhookVerificationError("SIGNATURE_MISMATCH", "No valid signature found. Verify the webhook secret matches and you're using the raw request body (not re-serialized JSON).");
|
|
6442
6475
|
}
|
|
6443
|
-
|
|
6444
6476
|
//#endregion
|
|
6445
6477
|
//#region src/schema.generated.ts
|
|
6446
6478
|
const emailReceivedEventJsonSchema = {
|
|
@@ -7332,7 +7364,6 @@ const emailReceivedEventJsonSchema = {
|
|
|
7332
7364
|
}
|
|
7333
7365
|
}
|
|
7334
7366
|
};
|
|
7335
|
-
|
|
7336
7367
|
//#endregion
|
|
7337
7368
|
//#region src/types.ts
|
|
7338
7369
|
const EventType = { EmailReceived: "email.received" };
|
|
@@ -7381,7 +7412,6 @@ const AuthVerdict = {
|
|
|
7381
7412
|
Suspicious: "suspicious",
|
|
7382
7413
|
Unknown: "unknown"
|
|
7383
7414
|
};
|
|
7384
|
-
|
|
7385
7415
|
//#endregion
|
|
7386
7416
|
//#region src/webhook/auth.ts
|
|
7387
7417
|
/**
|
|
@@ -7578,7 +7608,6 @@ function validateEmailAuth(auth) {
|
|
|
7578
7608
|
reasons: ["Unable to determine email authenticity"]
|
|
7579
7609
|
};
|
|
7580
7610
|
}
|
|
7581
|
-
|
|
7582
7611
|
//#endregion
|
|
7583
7612
|
//#region src/webhook/version.ts
|
|
7584
7613
|
/**
|
|
@@ -7594,10 +7623,13 @@ function validateEmailAuth(auth) {
|
|
|
7594
7623
|
* need to handle version-specific behavior.
|
|
7595
7624
|
*/
|
|
7596
7625
|
const WEBHOOK_VERSION = "2025-12-14";
|
|
7597
|
-
|
|
7598
7626
|
//#endregion
|
|
7599
7627
|
//#region src/webhook/parsing.ts
|
|
7600
7628
|
/**
|
|
7629
|
+
* JSON parsing utilities with helpful error messages.
|
|
7630
|
+
* @internal
|
|
7631
|
+
*/
|
|
7632
|
+
/**
|
|
7601
7633
|
* Parse a raw body string/Buffer into JSON with helpful error messages.
|
|
7602
7634
|
*
|
|
7603
7635
|
* Handles:
|
|
@@ -7618,12 +7650,10 @@ function parseJsonBody(rawBody) {
|
|
|
7618
7650
|
return JSON.parse(cleanBody);
|
|
7619
7651
|
} catch (e) {
|
|
7620
7652
|
const jsonError = e;
|
|
7621
|
-
const
|
|
7622
|
-
const position = positionMatch?.[1];
|
|
7653
|
+
const position = jsonError.message.match(/position\s*(\d+)/i)?.[1];
|
|
7623
7654
|
throw new WebhookPayloadError("JSON_PARSE_FAILED", "Failed to parse webhook body as JSON", position ? `Invalid JSON at position ${position}. Check your web framework isn't truncating the request body.` : `Invalid JSON: ${jsonError.message}. Check the raw request body is valid JSON.`, jsonError);
|
|
7624
7655
|
}
|
|
7625
7656
|
}
|
|
7626
|
-
|
|
7627
7657
|
//#endregion
|
|
7628
7658
|
//#region src/webhook/index.ts
|
|
7629
7659
|
const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
@@ -7818,17 +7848,13 @@ function handleWebhook(options) {
|
|
|
7818
7848
|
secret,
|
|
7819
7849
|
toleranceSeconds
|
|
7820
7850
|
});
|
|
7821
|
-
else {
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
});
|
|
7829
|
-
}
|
|
7830
|
-
const parsed = parseJsonBody(body);
|
|
7831
|
-
return validateEmailReceivedEvent(parsed);
|
|
7851
|
+
else verifyWebhookSignature({
|
|
7852
|
+
rawBody: body,
|
|
7853
|
+
signatureHeader: getSignatureHeader(headers),
|
|
7854
|
+
secret,
|
|
7855
|
+
toleranceSeconds
|
|
7856
|
+
});
|
|
7857
|
+
return validateEmailReceivedEvent(parseJsonBody(body));
|
|
7832
7858
|
}
|
|
7833
7859
|
function receive(input, options) {
|
|
7834
7860
|
if (input instanceof Request) return receiveFromRequest(input, options);
|
|
@@ -7836,9 +7862,8 @@ function receive(input, options) {
|
|
|
7836
7862
|
}
|
|
7837
7863
|
async function receiveFromRequest(request, options) {
|
|
7838
7864
|
if (!options?.secret) throw new WebhookVerificationError("MISSING_SECRET", "Webhook secret is required but was empty or not provided");
|
|
7839
|
-
const body = Buffer.from(await request.arrayBuffer());
|
|
7840
7865
|
return normalizeReceivedEmail(handleWebhook({
|
|
7841
|
-
body,
|
|
7866
|
+
body: Buffer.from(await request.arrayBuffer()),
|
|
7842
7867
|
headers: request.headers,
|
|
7843
7868
|
secret: options.secret,
|
|
7844
7869
|
toleranceSeconds: options.toleranceSeconds
|
|
@@ -7900,8 +7925,7 @@ function confirmedHeaders() {
|
|
|
7900
7925
|
* ```
|
|
7901
7926
|
*/
|
|
7902
7927
|
function isDownloadExpired(event, now = Date.now()) {
|
|
7903
|
-
|
|
7904
|
-
return now >= expiresAt;
|
|
7928
|
+
return now >= new Date(event.email.content.download.expires_at).getTime();
|
|
7905
7929
|
}
|
|
7906
7930
|
/**
|
|
7907
7931
|
* Get the time remaining (in milliseconds) before the download URL expires.
|
|
@@ -8016,6 +8040,5 @@ function verifyRawEmailDownload(downloaded, event) {
|
|
|
8016
8040
|
if (hash !== expected.toLowerCase()) throw new RawEmailDecodeError("HASH_MISMATCH", `SHA-256 hash mismatch. Expected: ${expected}, got: ${hash}. The downloaded content may be corrupted.`);
|
|
8017
8041
|
return buffer;
|
|
8018
8042
|
}
|
|
8019
|
-
|
|
8020
8043
|
//#endregion
|
|
8021
|
-
export {
|
|
8044
|
+
export { PRIMITIVE_CONFIRMED_HEADER as A, RAW_EMAIL_ERRORS as B, STANDARD_WEBHOOK_ID_HEADER as C, verifyStandardWebhooksSignature as D, signStandardWebhooksPayload as E, verifyDownloadToken as F, WebhookVerificationError as G, VERIFICATION_ERRORS as H, safeValidateEmailReceivedEvent as I, validateEmailReceivedEvent as L, signWebhookPayload as M, verifyWebhookSignature as N, LEGACY_CONFIRMED_HEADER as O, generateDownloadToken as P, PAYLOAD_ERRORS as R, emailReceivedEventJsonSchema as S, STANDARD_WEBHOOK_TIMESTAMP_HEADER as T, WebhookPayloadError as U, RawEmailDecodeError as V, WebhookValidationError as W, DmarcResult as _, isDownloadExpired as a, ParsedStatus as b, parseWebhookEvent as c, WEBHOOK_VERSION as d, validateEmailAuth as f, DmarcPolicy as g, DkimResult as h, handleWebhook as i, PRIMITIVE_SIGNATURE_HEADER as j, LEGACY_SIGNATURE_HEADER as k, receive as l, AuthVerdict as m, decodeRawEmail as n, isEmailReceivedEvent as o, AuthConfidence as p, getDownloadTimeRemaining as r, isRawIncluded as s, confirmedHeaders as t, verifyRawEmailDownload as u, EventType as v, STANDARD_WEBHOOK_SIGNATURE_HEADER as w, SpfResult as x, ForwardVerdict as y, PrimitiveWebhookError as z };
|