@primitivedotdev/sdk 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, ParsedDataComplete, ParsedDataFailed, ParsedError, RawContentDownloadOnly, RawContentInline, WebhookAttachment } from "../types-C6M6oCRS.js";
2
- import { SignResult, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, signWebhookPayload$1 as signWebhookPayload } from "../index-C9pON-wY.js";
2
+ import { SignResult, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, signWebhookPayload$1 as signWebhookPayload } from "../index-pNcbeqPI.js";
3
3
 
4
4
  //#region src/contract/contract.d.ts
5
5
  /** Maximum raw email size for inline inclusion (256 KB). */
@@ -1,4 +1,4 @@
1
- import { WEBHOOK_VERSION, signWebhookPayload, validateEmailReceivedEvent } from "../webhook-h24dbQEE.js";
1
+ import { WEBHOOK_VERSION, signWebhookPayload, validateEmailReceivedEvent } from "../webhook-Cz3QsQnS.js";
2
2
  import { createHash } from "node:crypto";
3
3
 
4
4
  //#region src/contract/contract.ts
@@ -242,8 +242,12 @@ declare function safeValidateEmailReceivedEvent(input: unknown): ValidationResul
242
242
  */
243
243
  /** Header name for incoming webhook signature */
244
244
  declare const PRIMITIVE_SIGNATURE_HEADER = "Primitive-Signature";
245
+ /** Legacy header name kept for backward compatibility with older servers */
246
+ declare const LEGACY_SIGNATURE_HEADER = "MyMX-Signature";
245
247
  /** Header name to confirm webhook was processed (prevents retries) */
246
248
  declare const PRIMITIVE_CONFIRMED_HEADER = "X-Primitive-Confirmed";
249
+ /** Legacy confirmed header name kept for backward compatibility */
250
+ declare const LEGACY_CONFIRMED_HEADER = "X-MyMX-Confirmed";
247
251
  /**
248
252
  * Result from signing a webhook payload
249
253
  */
@@ -1350,6 +1354,7 @@ declare function handleWebhook(options: HandleWebhookOptions): EmailReceivedEven
1350
1354
  */
1351
1355
  declare function confirmedHeaders(): {
1352
1356
  "X-Primitive-Confirmed": "true";
1357
+ "X-MyMX-Confirmed": "true";
1353
1358
  };
1354
1359
  /**
1355
1360
  * Check if the download URL for a webhook event has expired.
@@ -1471,4 +1476,4 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
1471
1476
  declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
1472
1477
 
1473
1478
  //#endregion
1474
- export { DecodeRawEmailOptions, HandleWebhookOptions, PAYLOAD_ERRORS as PAYLOAD_ERRORS$1, PRIMITIVE_CONFIRMED_HEADER as PRIMITIVE_CONFIRMED_HEADER$1, PRIMITIVE_SIGNATURE_HEADER as PRIMITIVE_SIGNATURE_HEADER$1, PrimitiveWebhookError as PrimitiveWebhookError$1, RAW_EMAIL_ERRORS as RAW_EMAIL_ERRORS$1, RawEmailDecodeError as RawEmailDecodeError$1, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS as VERIFICATION_ERRORS$1, VerifyOptions, WEBHOOK_VERSION as WEBHOOK_VERSION$1, WebhookErrorCode, WebhookHeaders, WebhookPayloadError as WebhookPayloadError$1, WebhookPayloadErrorCode, WebhookValidationError as WebhookValidationError$1, WebhookValidationErrorCode, WebhookVerificationError as WebhookVerificationError$1, WebhookVerificationErrorCode, confirmedHeaders as confirmedHeaders$1, decodeRawEmail as decodeRawEmail$1, emailReceivedEventJsonSchema as emailReceivedEventJsonSchema$1, getDownloadTimeRemaining as getDownloadTimeRemaining$1, handleWebhook as handleWebhook$1, isDownloadExpired as isDownloadExpired$1, isEmailReceivedEvent as isEmailReceivedEvent$1, isRawIncluded as isRawIncluded$1, parseWebhookEvent as parseWebhookEvent$1, safeValidateEmailReceivedEvent as safeValidateEmailReceivedEvent$1, signWebhookPayload as signWebhookPayload$1, validateEmailAuth as validateEmailAuth$1, validateEmailReceivedEvent as validateEmailReceivedEvent$1, verifyRawEmailDownload as verifyRawEmailDownload$1, verifyWebhookSignature as verifyWebhookSignature$1 };
1479
+ export { DecodeRawEmailOptions, HandleWebhookOptions, LEGACY_CONFIRMED_HEADER as LEGACY_CONFIRMED_HEADER$1, LEGACY_SIGNATURE_HEADER as LEGACY_SIGNATURE_HEADER$1, PAYLOAD_ERRORS as PAYLOAD_ERRORS$1, PRIMITIVE_CONFIRMED_HEADER as PRIMITIVE_CONFIRMED_HEADER$1, PRIMITIVE_SIGNATURE_HEADER as PRIMITIVE_SIGNATURE_HEADER$1, PrimitiveWebhookError as PrimitiveWebhookError$1, RAW_EMAIL_ERRORS as RAW_EMAIL_ERRORS$1, RawEmailDecodeError as RawEmailDecodeError$1, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS as VERIFICATION_ERRORS$1, VerifyOptions, WEBHOOK_VERSION as WEBHOOK_VERSION$1, WebhookErrorCode, WebhookHeaders, WebhookPayloadError as WebhookPayloadError$1, WebhookPayloadErrorCode, WebhookValidationError as WebhookValidationError$1, WebhookValidationErrorCode, WebhookVerificationError as WebhookVerificationError$1, WebhookVerificationErrorCode, confirmedHeaders as confirmedHeaders$1, decodeRawEmail as decodeRawEmail$1, emailReceivedEventJsonSchema as emailReceivedEventJsonSchema$1, getDownloadTimeRemaining as getDownloadTimeRemaining$1, handleWebhook as handleWebhook$1, isDownloadExpired as isDownloadExpired$1, isEmailReceivedEvent as isEmailReceivedEvent$1, isRawIncluded as isRawIncluded$1, parseWebhookEvent as parseWebhookEvent$1, safeValidateEmailReceivedEvent as safeValidateEmailReceivedEvent$1, signWebhookPayload as signWebhookPayload$1, validateEmailAuth as validateEmailAuth$1, validateEmailReceivedEvent as validateEmailReceivedEvent$1, verifyRawEmailDownload as verifyRawEmailDownload$1, verifyWebhookSignature as verifyWebhookSignature$1 };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { AuthConfidence$1 as AuthConfidence, AuthVerdict$1 as AuthVerdict, DkimResult$1 as DkimResult, DkimSignature, DmarcPolicy$1 as DmarcPolicy, DmarcResult$1 as DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType$1 as EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict$1 as ForwardVerdict, ForwardVerification, KnownWebhookEvent, ParsedData, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedStatus$1 as ParsedStatus, RawContent, RawContentDownloadOnly, RawContentInline, SpfResult$1 as SpfResult, UnknownEvent, ValidateEmailAuthResult, WebhookAttachment, WebhookEvent } from "./types-C6M6oCRS.js";
2
- import { DecodeRawEmailOptions, HandleWebhookOptions, PAYLOAD_ERRORS$1 as PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER$1 as PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER$1 as PRIMITIVE_SIGNATURE_HEADER, PrimitiveWebhookError$1 as PrimitiveWebhookError, RAW_EMAIL_ERRORS$1 as RAW_EMAIL_ERRORS, RawEmailDecodeError$1 as RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyOptions, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, WebhookErrorCode, WebhookHeaders, WebhookPayloadError$1 as WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError$1 as WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError$1 as WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders$1 as confirmedHeaders, decodeRawEmail$1 as decodeRawEmail, emailReceivedEventJsonSchema$1 as emailReceivedEventJsonSchema, getDownloadTimeRemaining$1 as getDownloadTimeRemaining, handleWebhook$1 as handleWebhook, isDownloadExpired$1 as isDownloadExpired, isEmailReceivedEvent$1 as isEmailReceivedEvent, isRawIncluded$1 as isRawIncluded, parseWebhookEvent$1 as parseWebhookEvent, safeValidateEmailReceivedEvent$1 as safeValidateEmailReceivedEvent, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyWebhookSignature$1 as verifyWebhookSignature } from "./index-C9pON-wY.js";
3
- export { AuthConfidence, AuthVerdict, DecodeRawEmailOptions, DkimResult, DkimSignature, DmarcPolicy, DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict, ForwardVerification, HandleWebhookOptions, KnownWebhookEvent, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedData, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawContent, RawContentDownloadOnly, RawContentInline, RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, SpfResult, UnknownEvent, VERIFICATION_ERRORS, ValidateEmailAuthResult, VerifyOptions, WEBHOOK_VERSION, WebhookAttachment, WebhookErrorCode, WebhookEvent, WebhookHeaders, WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
2
+ import { DecodeRawEmailOptions, HandleWebhookOptions, LEGACY_CONFIRMED_HEADER$1 as LEGACY_CONFIRMED_HEADER, LEGACY_SIGNATURE_HEADER$1 as LEGACY_SIGNATURE_HEADER, PAYLOAD_ERRORS$1 as PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER$1 as PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER$1 as PRIMITIVE_SIGNATURE_HEADER, PrimitiveWebhookError$1 as PrimitiveWebhookError, RAW_EMAIL_ERRORS$1 as RAW_EMAIL_ERRORS, RawEmailDecodeError$1 as RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyOptions, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, WebhookErrorCode, WebhookHeaders, WebhookPayloadError$1 as WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError$1 as WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError$1 as WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders$1 as confirmedHeaders, decodeRawEmail$1 as decodeRawEmail, emailReceivedEventJsonSchema$1 as emailReceivedEventJsonSchema, getDownloadTimeRemaining$1 as getDownloadTimeRemaining, handleWebhook$1 as handleWebhook, isDownloadExpired$1 as isDownloadExpired, isEmailReceivedEvent$1 as isEmailReceivedEvent, isRawIncluded$1 as isRawIncluded, parseWebhookEvent$1 as parseWebhookEvent, safeValidateEmailReceivedEvent$1 as safeValidateEmailReceivedEvent, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyWebhookSignature$1 as verifyWebhookSignature } from "./index-pNcbeqPI.js";
3
+ export { AuthConfidence, AuthVerdict, DecodeRawEmailOptions, DkimResult, DkimSignature, DmarcPolicy, DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict, ForwardVerification, 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, SignResult, SpfResult, UnknownEvent, VERIFICATION_ERRORS, ValidateEmailAuthResult, VerifyOptions, WEBHOOK_VERSION, WebhookAttachment, WebhookErrorCode, WebhookEvent, WebhookHeaders, WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature } from "./webhook-h24dbQEE.js";
1
+ import { 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, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature } from "./webhook-Cz3QsQnS.js";
2
2
 
3
- export { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
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, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
@@ -47,6 +47,7 @@ interface ParsedEmailWithAttachments {
47
47
  */
48
48
  declare function parseEmailWithAttachments(emlBuffer: Buffer, options?: {
49
49
  generateAttachmentId?: () => string;
50
+ skipHtmlSanitization?: boolean;
50
51
  }): Promise<ParsedEmailWithAttachments>;
51
52
  /**
52
53
  * Normalize a Content-Type to lowercase media type without parameters.
@@ -182,4 +183,8 @@ declare function toCanonicalHeaders(parsed: ParsedEmailWithAttachments): {
182
183
  };
183
184
 
184
185
  //#endregion
185
- export { AttachmentMetadata, BundleResult, ParsedAttachment, ParsedEmail, ParsedEmailWithAttachments, attachmentMetadataToWebhookAttachments, bundleAttachments, extractAttachmentMetadata, getAttachmentsStorageKey, normalizeContentType, parseEmail, parseEmailWithAttachments, sanitizeFilename, sha256Hex, toCanonicalHeaders, toParsedDataComplete, toWebhookAttachments };
186
+ //#region src/parser/sanitize-html.d.ts
187
+ declare function sanitizeHtml(html: string): string;
188
+
189
+ //#endregion
190
+ export { AttachmentMetadata, BundleResult, ParsedAttachment, ParsedEmail, ParsedEmailWithAttachments, attachmentMetadataToWebhookAttachments, bundleAttachments, extractAttachmentMetadata, getAttachmentsStorageKey, normalizeContentType, parseEmail, parseEmailWithAttachments, sanitizeFilename, sanitizeHtml, sha256Hex, toCanonicalHeaders, toParsedDataComplete, toWebhookAttachments };
@@ -1,5 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { PassThrough } from "node:stream";
3
+ import DOMPurify from "isomorphic-dompurify";
3
4
 
4
5
  //#region src/parser/attachment-bundler.ts
5
6
  async function loadArchiver() {
@@ -104,6 +105,122 @@ function getAttachmentsStorageKey(emailId, sha256) {
104
105
  return `attachments/${emailId}_${hash8}.tar.gz`;
105
106
  }
106
107
 
108
+ //#endregion
109
+ //#region src/parser/sanitize-html.ts
110
+ const ALLOWED_TAGS = [
111
+ "div",
112
+ "span",
113
+ "p",
114
+ "br",
115
+ "hr",
116
+ "b",
117
+ "i",
118
+ "u",
119
+ "strong",
120
+ "em",
121
+ "small",
122
+ "sub",
123
+ "sup",
124
+ "s",
125
+ "strike",
126
+ "h1",
127
+ "h2",
128
+ "h3",
129
+ "h4",
130
+ "h5",
131
+ "h6",
132
+ "ul",
133
+ "ol",
134
+ "li",
135
+ "dl",
136
+ "dt",
137
+ "dd",
138
+ "table",
139
+ "thead",
140
+ "tbody",
141
+ "tfoot",
142
+ "tr",
143
+ "th",
144
+ "td",
145
+ "colgroup",
146
+ "col",
147
+ "caption",
148
+ "a",
149
+ "img",
150
+ "blockquote",
151
+ "pre",
152
+ "code",
153
+ "address",
154
+ "center",
155
+ "font",
156
+ "big"
157
+ ];
158
+ const ALLOWED_ATTRS = [
159
+ "class",
160
+ "id",
161
+ "dir",
162
+ "lang",
163
+ "href",
164
+ "title",
165
+ "target",
166
+ "rel",
167
+ "src",
168
+ "alt",
169
+ "width",
170
+ "height",
171
+ "border",
172
+ "cellpadding",
173
+ "cellspacing",
174
+ "align",
175
+ "valign",
176
+ "bgcolor",
177
+ "colspan",
178
+ "rowspan",
179
+ "span",
180
+ "color",
181
+ "size",
182
+ "face"
183
+ ];
184
+ const ALLOWED_URI_REGEXP = /^(data:|mailto:|#)/i;
185
+ function sanitizeHtml(html) {
186
+ DOMPurify.addHook("uponSanitizeAttribute", (_node, data) => {
187
+ if (data.attrName.startsWith("on")) data.keepAttr = false;
188
+ if (data.attrName === "style") data.keepAttr = false;
189
+ });
190
+ DOMPurify.addHook("afterSanitizeAttributes", (node) => {
191
+ if (node.tagName === "A") {
192
+ const target = node.getAttribute("target");
193
+ if (target === "_blank") node.setAttribute("rel", "noopener noreferrer");
194
+ }
195
+ });
196
+ const result = DOMPurify.sanitize(html, {
197
+ ALLOWED_TAGS,
198
+ ALLOWED_ATTR: ALLOWED_ATTRS,
199
+ ALLOW_DATA_ATTR: false,
200
+ ALLOW_UNKNOWN_PROTOCOLS: false,
201
+ ALLOWED_URI_REGEXP,
202
+ FORBID_TAGS: [
203
+ "style",
204
+ "script",
205
+ "iframe",
206
+ "object",
207
+ "embed",
208
+ "form",
209
+ "input",
210
+ "button",
211
+ "select",
212
+ "textarea",
213
+ "link",
214
+ "meta",
215
+ "base",
216
+ "svg",
217
+ "math"
218
+ ]
219
+ });
220
+ DOMPurify.removeAllHooks();
221
+ return result;
222
+ }
223
+
107
224
  //#endregion
108
225
  //#region src/parser/attachment-parser.ts
109
226
  async function loadMailparser$1() {
@@ -169,7 +286,7 @@ async function parseEmailWithAttachments(emlBuffer, options) {
169
286
  });
170
287
  }
171
288
  let bodyHtml = null;
172
- if (parsed.html && typeof parsed.html === "string") bodyHtml = parsed.html;
289
+ if (parsed.html && typeof parsed.html === "string") bodyHtml = options?.skipHtmlSanitization ? parsed.html : sanitizeHtml(parsed.html);
173
290
  return {
174
291
  bodyText: parsed.text ?? null,
175
292
  bodyHtml,
@@ -435,4 +552,4 @@ function requireNonEmptyHeader(value, headerName) {
435
552
  }
436
553
 
437
554
  //#endregion
438
- export { attachmentMetadataToWebhookAttachments, bundleAttachments, extractAttachmentMetadata, getAttachmentsStorageKey, normalizeContentType, parseEmail, parseEmailWithAttachments, sanitizeFilename, sha256Hex, toCanonicalHeaders, toParsedDataComplete, toWebhookAttachments };
555
+ export { attachmentMetadataToWebhookAttachments, bundleAttachments, extractAttachmentMetadata, getAttachmentsStorageKey, normalizeContentType, parseEmail, parseEmailWithAttachments, sanitizeFilename, sanitizeHtml, sha256Hex, toCanonicalHeaders, toParsedDataComplete, toWebhookAttachments };
@@ -1,3 +1,3 @@
1
1
  import { AuthConfidence$1 as AuthConfidence, AuthVerdict$1 as AuthVerdict, DkimResult$1 as DkimResult, DkimSignature, DmarcPolicy$1 as DmarcPolicy, DmarcResult$1 as DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType$1 as EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict$1 as ForwardVerdict, ForwardVerification, KnownWebhookEvent, ParsedData, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedStatus$1 as ParsedStatus, RawContent, RawContentDownloadOnly, RawContentInline, SpfResult$1 as SpfResult, UnknownEvent, ValidateEmailAuthResult, WebhookAttachment, WebhookEvent } from "../types-C6M6oCRS.js";
2
- import { DecodeRawEmailOptions, HandleWebhookOptions, PAYLOAD_ERRORS$1 as PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER$1 as PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER$1 as PRIMITIVE_SIGNATURE_HEADER, PrimitiveWebhookError$1 as PrimitiveWebhookError, RAW_EMAIL_ERRORS$1 as RAW_EMAIL_ERRORS, RawEmailDecodeError$1 as RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyOptions, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, WebhookErrorCode, WebhookHeaders, WebhookPayloadError$1 as WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError$1 as WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError$1 as WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders$1 as confirmedHeaders, decodeRawEmail$1 as decodeRawEmail, emailReceivedEventJsonSchema$1 as emailReceivedEventJsonSchema, getDownloadTimeRemaining$1 as getDownloadTimeRemaining, handleWebhook$1 as handleWebhook, isDownloadExpired$1 as isDownloadExpired, isEmailReceivedEvent$1 as isEmailReceivedEvent, isRawIncluded$1 as isRawIncluded, parseWebhookEvent$1 as parseWebhookEvent, safeValidateEmailReceivedEvent$1 as safeValidateEmailReceivedEvent, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyWebhookSignature$1 as verifyWebhookSignature } from "../index-C9pON-wY.js";
3
- export { AuthConfidence, AuthVerdict, DecodeRawEmailOptions, DkimResult, DkimSignature, DmarcPolicy, DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict, ForwardVerification, HandleWebhookOptions, KnownWebhookEvent, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedData, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawContent, RawContentDownloadOnly, RawContentInline, RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, SpfResult, UnknownEvent, VERIFICATION_ERRORS, ValidateEmailAuthResult, VerifyOptions, WEBHOOK_VERSION, WebhookAttachment, WebhookErrorCode, WebhookEvent, WebhookHeaders, WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
2
+ import { DecodeRawEmailOptions, HandleWebhookOptions, LEGACY_CONFIRMED_HEADER$1 as LEGACY_CONFIRMED_HEADER, LEGACY_SIGNATURE_HEADER$1 as LEGACY_SIGNATURE_HEADER, PAYLOAD_ERRORS$1 as PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER$1 as PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER$1 as PRIMITIVE_SIGNATURE_HEADER, PrimitiveWebhookError$1 as PrimitiveWebhookError, RAW_EMAIL_ERRORS$1 as RAW_EMAIL_ERRORS, RawEmailDecodeError$1 as RawEmailDecodeError, RawEmailDecodeErrorCode, SignResult, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyOptions, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, WebhookErrorCode, WebhookHeaders, WebhookPayloadError$1 as WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError$1 as WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError$1 as WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders$1 as confirmedHeaders, decodeRawEmail$1 as decodeRawEmail, emailReceivedEventJsonSchema$1 as emailReceivedEventJsonSchema, getDownloadTimeRemaining$1 as getDownloadTimeRemaining, handleWebhook$1 as handleWebhook, isDownloadExpired$1 as isDownloadExpired, isEmailReceivedEvent$1 as isEmailReceivedEvent, isRawIncluded$1 as isRawIncluded, parseWebhookEvent$1 as parseWebhookEvent, safeValidateEmailReceivedEvent$1 as safeValidateEmailReceivedEvent, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyWebhookSignature$1 as verifyWebhookSignature } from "../index-pNcbeqPI.js";
3
+ export { AuthConfidence, AuthVerdict, DecodeRawEmailOptions, DkimResult, DkimSignature, DmarcPolicy, DmarcResult, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EventType, ForwardAnalysis, ForwardOriginalSender, ForwardResult, ForwardResultAttachmentAnalyzed, ForwardResultAttachmentSkipped, ForwardResultInline, ForwardVerdict, ForwardVerification, 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, SignResult, SpfResult, UnknownEvent, VERIFICATION_ERRORS, ValidateEmailAuthResult, VerifyOptions, WEBHOOK_VERSION, WebhookAttachment, WebhookErrorCode, WebhookEvent, WebhookHeaders, WebhookPayloadError, WebhookPayloadErrorCode, WebhookValidationError, WebhookValidationErrorCode, WebhookVerificationError, WebhookVerificationErrorCode, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
@@ -1,3 +1,3 @@
1
- import { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature } from "../webhook-h24dbQEE.js";
1
+ import { 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, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature } from "../webhook-Cz3QsQnS.js";
2
2
 
3
- export { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
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, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
@@ -1,10 +1,5 @@
1
- import { createRequire } from "module";
2
1
  import { createHash, createHmac, timingSafeEqual } from "node:crypto";
3
2
 
4
- //#region rolldown:runtime
5
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
6
-
7
- //#endregion
8
3
  //#region src/generated/email-received-event.validator.generated.ts
9
4
  var email_received_event_validator_generated_default = validate10;
10
5
  const schema12 = {
@@ -190,9 +185,8 @@ const schema12 = {
190
185
  const pattern0 = new RegExp("^evt_[a-f0-9]{64}$", "u");
191
186
  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");
192
187
  const pattern4 = new RegExp("^https://", "u");
193
- const formats0 = __require("ajv-formats/dist/formats").fullFormats["date-time"];
194
- const formats4 = __require("ajv-formats/dist/formats").fullFormats.uri;
195
- const func2 = __require("ajv/dist/runtime/ucs2length").default;
188
+ 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)$/;
189
+ 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;
196
190
  const pattern2 = new RegExp("^[a-fA-F0-9]{64}$", "u");
197
191
  function validate12(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
198
192
  let vErrors = null;
@@ -1810,7 +1804,7 @@ function validate15(data, { instancePath = "", parentData, parentDataProperty, r
1810
1804
  else vErrors.push(err66);
1811
1805
  errors++;
1812
1806
  }
1813
- if (!formats4(data28)) {
1807
+ if (!formats4.test(data28)) {
1814
1808
  const err67 = {
1815
1809
  instancePath: instancePath + "/attachments_download_url",
1816
1810
  schemaPath: "#/properties/attachments_download_url/format",
@@ -4855,7 +4849,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
4855
4849
  if (data3.attempted_at !== void 0) {
4856
4850
  let data6 = data3.attempted_at;
4857
4851
  if (typeof data6 === "string") {
4858
- if (!formats0.validate(data6)) {
4852
+ if (!formats0.test(data6)) {
4859
4853
  const err17 = {
4860
4854
  instancePath: instancePath + "/delivery/attempted_at",
4861
4855
  schemaPath: "#/properties/delivery/properties/attempted_at/format",
@@ -5009,7 +5003,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
5009
5003
  if (data7.received_at !== void 0) {
5010
5004
  let data9 = data7.received_at;
5011
5005
  if (typeof data9 === "string") {
5012
- if (!formats0.validate(data9)) {
5006
+ if (!formats0.test(data9)) {
5013
5007
  const err29 = {
5014
5008
  instancePath: instancePath + "/email/received_at",
5015
5009
  schemaPath: "#/properties/email/properties/received_at/format",
@@ -5252,7 +5246,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
5252
5246
  if (data15.from !== void 0) {
5253
5247
  let data18 = data15.from;
5254
5248
  if (typeof data18 === "string") {
5255
- if (func2(data18) < 1) {
5249
+ if (data18.length < 1) {
5256
5250
  const err47 = {
5257
5251
  instancePath: instancePath + "/email/headers/from",
5258
5252
  schemaPath: "#/properties/email/properties/headers/properties/from/minLength",
@@ -5280,7 +5274,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
5280
5274
  if (data15.to !== void 0) {
5281
5275
  let data19 = data15.to;
5282
5276
  if (typeof data19 === "string") {
5283
- if (func2(data19) < 1) {
5277
+ if (data19.length < 1) {
5284
5278
  const err49 = {
5285
5279
  instancePath: instancePath + "/email/headers/to",
5286
5280
  schemaPath: "#/properties/email/properties/headers/properties/to/minLength",
@@ -5413,7 +5407,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
5413
5407
  else vErrors.push(err57);
5414
5408
  errors++;
5415
5409
  }
5416
- if (!formats4(data24)) {
5410
+ if (!formats4.test(data24)) {
5417
5411
  const err58 = {
5418
5412
  instancePath: instancePath + "/email/content/download/url",
5419
5413
  schemaPath: "#/properties/email/properties/content/properties/download/properties/url/format",
@@ -5441,7 +5435,7 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
5441
5435
  if (data23.expires_at !== void 0) {
5442
5436
  let data25 = data23.expires_at;
5443
5437
  if (typeof data25 === "string") {
5444
- if (!formats0.validate(data25)) {
5438
+ if (!formats0.test(data25)) {
5445
5439
  const err60 = {
5446
5440
  instancePath: instancePath + "/email/content/download/expires_at",
5447
5441
  schemaPath: "#/properties/email/properties/content/properties/download/properties/expires_at/format",
@@ -6024,8 +6018,12 @@ function hashSecret(secret) {
6024
6018
  }
6025
6019
  /** Header name for incoming webhook signature */
6026
6020
  const PRIMITIVE_SIGNATURE_HEADER = "Primitive-Signature";
6021
+ /** Legacy header name kept for backward compatibility with older servers */
6022
+ const LEGACY_SIGNATURE_HEADER = "MyMX-Signature";
6027
6023
  /** Header name to confirm webhook was processed (prevents retries) */
6028
6024
  const PRIMITIVE_CONFIRMED_HEADER = "X-Primitive-Confirmed";
6025
+ /** Legacy confirmed header name kept for backward compatibility */
6026
+ const LEGACY_CONFIRMED_HEADER = "X-MyMX-Confirmed";
6029
6027
  /** Default max age for webhook requests (5 minutes) */
6030
6028
  const DEFAULT_TOLERANCE_SECONDS = 5 * 60;
6031
6029
  /** Future clock skew tolerance (1 minute) */
@@ -7424,17 +7422,30 @@ function isEmailReceivedEvent(event) {
7424
7422
  return false;
7425
7423
  }
7426
7424
  }
7425
+ const SIGNATURE_HEADER_NAMES = ["primitive-signature", "mymx-signature"];
7427
7426
  /**
7428
7427
  * Extract signature header from various header formats.
7428
+ * Checks for Primitive-Signature first, then falls back to the legacy
7429
+ * MyMX-Signature for backward compatibility with older servers.
7429
7430
  */
7430
7431
  function getSignatureHeader(headers) {
7431
- if (headers instanceof Headers) return headers.get("primitive-signature") ?? "";
7432
+ if (headers instanceof Headers) {
7433
+ for (const name of SIGNATURE_HEADER_NAMES) {
7434
+ const value = headers.get(name);
7435
+ if (value) return value;
7436
+ }
7437
+ return "";
7438
+ }
7432
7439
  const obj = headers;
7433
- const key = Object.keys(obj).find((k) => k.toLowerCase() === "primitive-signature");
7434
- if (!key) return "";
7435
- const value = obj[key];
7436
- if (Array.isArray(value)) return value[0] ?? "";
7437
- return value ?? "";
7440
+ const keys = Object.keys(obj);
7441
+ for (const name of SIGNATURE_HEADER_NAMES) {
7442
+ const key = keys.find((k) => k.toLowerCase() === name);
7443
+ if (!key) continue;
7444
+ const value = obj[key];
7445
+ if (Array.isArray(value)) return value[0] ?? "";
7446
+ if (value) return value;
7447
+ }
7448
+ return "";
7438
7449
  }
7439
7450
  /**
7440
7451
  * Verify, parse, and validate a webhook in one call.
@@ -7521,7 +7532,10 @@ function handleWebhook(options) {
7521
7532
  * ```
7522
7533
  */
7523
7534
  function confirmedHeaders() {
7524
- return { [PRIMITIVE_CONFIRMED_HEADER]: "true" };
7535
+ return {
7536
+ [PRIMITIVE_CONFIRMED_HEADER]: "true",
7537
+ [LEGACY_CONFIRMED_HEADER]: "true"
7538
+ };
7525
7539
  }
7526
7540
  /**
7527
7541
  * Check if the download URL for a webhook event has expired.
@@ -7658,4 +7672,4 @@ function verifyRawEmailDownload(downloaded, event) {
7658
7672
  }
7659
7673
 
7660
7674
  //#endregion
7661
- export { AuthConfidence, AuthVerdict, DkimResult, DmarcPolicy, DmarcResult, EventType, ForwardVerdict, PAYLOAD_ERRORS, PRIMITIVE_CONFIRMED_HEADER, PRIMITIVE_SIGNATURE_HEADER, ParsedStatus, PrimitiveWebhookError, RAW_EMAIL_ERRORS, RawEmailDecodeError, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
7675
+ 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, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyWebhookSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitivedotdev/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Official Primitive Node.js SDK — webhook, contract, and parser modules",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -62,17 +62,19 @@
62
62
  },
63
63
  "homepage": "https://primitive.dev",
64
64
  "engines": {
65
- "node": ">=20"
65
+ "node": ">=22"
66
66
  },
67
67
  "dependencies": {
68
68
  "ajv": "^8.17.1",
69
69
  "ajv-formats": "^3.0.1",
70
70
  "archiver": "^7.0.1",
71
+ "isomorphic-dompurify": "^3.8.0",
71
72
  "mailparser": "^3.9.0"
72
73
  },
73
74
  "devDependencies": {
74
75
  "@biomejs/biome": "^2.4.10",
75
76
  "@types/archiver": "^7.0.0",
77
+ "@types/dompurify": "^3.2.0",
76
78
  "@types/json-schema": "^7.0.15",
77
79
  "@types/mailparser": "^3.4.6",
78
80
  "@types/node": "^22.10.2",