@primitivedotdev/sdk 0.4.0 → 0.5.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/contract/index.d.ts +82 -4
- package/dist/contract/index.js +72 -2
- package/dist/{index-D2OuDGVz.d.ts → index-DLmAI4UQ.d.ts} +95 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/parser/index.d.ts +1 -1
- package/dist/{types-C3ms4R0d.d.ts → types-CKFmgitP.d.ts} +2 -2
- package/dist/webhook/index.d.ts +3 -3
- package/dist/webhook/index.js +2 -2
- package/dist/{webhook-uSco6pyX.js → webhook-COe5N_Uj.js} +113 -17
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, ParsedDataComplete, ParsedDataFailed, ParsedError, RawContentDownloadOnly, RawContentInline, WebhookAttachment } from "../types-
|
|
2
|
-
import { SignResult, StandardWebhooksSignResult, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload } from "../index-
|
|
1
|
+
import { EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, ParsedDataComplete, ParsedDataFailed, ParsedError, RawContentDownloadOnly, RawContentInline, WebhookAttachment } from "../types-CKFmgitP.js";
|
|
2
|
+
import { SignResult, StandardWebhooksSignResult, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload } from "../index-DLmAI4UQ.js";
|
|
3
3
|
|
|
4
4
|
//#region src/contract/contract.d.ts
|
|
5
5
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
@@ -146,5 +146,83 @@ declare function buildEmailReceivedEvent(input: EmailReceivedEventInput, options
|
|
|
146
146
|
event_id?: string;
|
|
147
147
|
/** Override the attempted-at timestamp, typically for tests. */
|
|
148
148
|
attempted_at?: string;
|
|
149
|
-
}): EmailReceivedEvent;
|
|
150
|
-
|
|
149
|
+
}): EmailReceivedEvent;
|
|
150
|
+
/**
|
|
151
|
+
* Input for building an `EmailReceivedEvent` directly from parser output.
|
|
152
|
+
*/
|
|
153
|
+
interface BuildEventFromParsedDataOptions {
|
|
154
|
+
/** Unique email ID chosen by the producer. */
|
|
155
|
+
emailId: string;
|
|
156
|
+
/** ID of the webhook endpoint receiving this event. */
|
|
157
|
+
endpointId: string;
|
|
158
|
+
/** Raw RFC 5322 bytes. Used to compute sha256 and inline data. */
|
|
159
|
+
rawBytes: Buffer;
|
|
160
|
+
/** Parser output with attachments, body, and threading headers populated. */
|
|
161
|
+
parsed: ParsedDataComplete;
|
|
162
|
+
/** Message-ID header value, or null if the email had none. */
|
|
163
|
+
messageId: string | null;
|
|
164
|
+
/** From header value. */
|
|
165
|
+
sender: string;
|
|
166
|
+
/** To header value. */
|
|
167
|
+
recipient: string;
|
|
168
|
+
/** Subject header value, or null. */
|
|
169
|
+
subject: string | null;
|
|
170
|
+
/** ISO 8601 timestamp when the producer accepted the email. */
|
|
171
|
+
receivedAt: string;
|
|
172
|
+
/** SMTP HELO/EHLO hostname, or null if not captured. */
|
|
173
|
+
smtpHelo: string | null;
|
|
174
|
+
/** SMTP envelope MAIL FROM. */
|
|
175
|
+
smtpMailFrom: string;
|
|
176
|
+
/** SMTP envelope RCPT TO recipients. Must contain at least one entry. */
|
|
177
|
+
smtpRcptTo: [string, ...string[]];
|
|
178
|
+
/** Email authentication results (camelCase per the schema). */
|
|
179
|
+
auth: EmailAuth;
|
|
180
|
+
/** Email analysis block. */
|
|
181
|
+
analysis: EmailAnalysis;
|
|
182
|
+
/** HTTPS download URL for the raw email. Always populated. */
|
|
183
|
+
downloadUrl: string;
|
|
184
|
+
/** ISO 8601 expiry for the raw-email download URL. */
|
|
185
|
+
downloadExpiresAt: string;
|
|
186
|
+
/**
|
|
187
|
+
* Download URL for the attachments tarball.
|
|
188
|
+
* Must be null iff `parsed.attachments` is empty — mismatch throws.
|
|
189
|
+
*/
|
|
190
|
+
attachmentsDownloadUrl: string | null;
|
|
191
|
+
/** Delivery attempt number, starting at 1. */
|
|
192
|
+
attemptCount: number;
|
|
193
|
+
/** Original Date header value, or null. */
|
|
194
|
+
dateHeader?: string | null;
|
|
195
|
+
/** Optional overrides forwarded to `buildEmailReceivedEvent`. */
|
|
196
|
+
buildOptions?: {
|
|
197
|
+
event_id?: string;
|
|
198
|
+
attempted_at?: string;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Build an `EmailReceivedEvent` from parsed email data plus delivery metadata.
|
|
203
|
+
*
|
|
204
|
+
* Pure adapter: the caller supplies the raw bytes and the already-parsed
|
|
205
|
+
* data; this function computes sha256 and size, enforces the attachments
|
|
206
|
+
* invariant, and delegates to `buildEmailReceivedEvent` for schema
|
|
207
|
+
* validation. It never reads from disk, so it is safe to use in any
|
|
208
|
+
* runtime that has the data in memory.
|
|
209
|
+
*
|
|
210
|
+
* Inline vs. download-only behavior: when `rawBytes.length` is at or below
|
|
211
|
+
* `RAW_EMAIL_INLINE_THRESHOLD`, the event's `raw.data` is populated and
|
|
212
|
+
* `download.url` is still populated. Above the threshold, only `download.url`
|
|
213
|
+
* is populated. The download URL is always set regardless of inline status.
|
|
214
|
+
*
|
|
215
|
+
* Callers using the bundled parser can populate the header fields
|
|
216
|
+
* (`messageId`, `sender`, `recipient`, `subject`, `dateHeader`) directly
|
|
217
|
+
* from `toCanonicalHeaders(parsed)`. Accepting the flat fields rather than
|
|
218
|
+
* a canonical-headers object keeps this function usable by callers that
|
|
219
|
+
* do not use the bundled parser. A future release may add an optional
|
|
220
|
+
* canonical-headers parameter as an ergonomic alternative.
|
|
221
|
+
*
|
|
222
|
+
* @throws Error if `attachmentsDownloadUrl` disagrees with whether
|
|
223
|
+
* `parsed.attachments` is empty.
|
|
224
|
+
* @throws Error if `smtpRcptTo` is empty.
|
|
225
|
+
* @throws WebhookValidationError if the assembled event fails schema validation.
|
|
226
|
+
*/
|
|
227
|
+
declare function buildEventFromParsedData(params: BuildEventFromParsedDataOptions): EmailReceivedEvent; //#endregion
|
|
228
|
+
export { BuildEventFromParsedDataOptions, EmailAddress, EmailAnalysis, EmailAuth, EmailReceivedEvent, EmailReceivedEventInput, ParsedDataComplete, ParsedDataFailed, ParsedError, ParsedInput, ParsedInputComplete, ParsedInputFailed, RAW_EMAIL_INLINE_THRESHOLD, RawContentDownloadOnly, RawContentInline, SignResult, StandardWebhooksSignResult, WEBHOOK_VERSION, WebhookAttachment, buildEmailReceivedEvent, buildEventFromParsedData, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
package/dist/contract/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WEBHOOK_VERSION, signStandardWebhooksPayload, signWebhookPayload, validateEmailReceivedEvent } from "../webhook-
|
|
1
|
+
import { WEBHOOK_VERSION, signStandardWebhooksPayload, signWebhookPayload, validateEmailReceivedEvent } from "../webhook-COe5N_Uj.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
|
|
4
4
|
//#region src/contract/contract.ts
|
|
@@ -194,6 +194,76 @@ function buildEmailReceivedEvent(input, options) {
|
|
|
194
194
|
};
|
|
195
195
|
return validateEmailReceivedEvent(event);
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Build an `EmailReceivedEvent` from parsed email data plus delivery metadata.
|
|
199
|
+
*
|
|
200
|
+
* Pure adapter: the caller supplies the raw bytes and the already-parsed
|
|
201
|
+
* data; this function computes sha256 and size, enforces the attachments
|
|
202
|
+
* invariant, and delegates to `buildEmailReceivedEvent` for schema
|
|
203
|
+
* validation. It never reads from disk, so it is safe to use in any
|
|
204
|
+
* runtime that has the data in memory.
|
|
205
|
+
*
|
|
206
|
+
* Inline vs. download-only behavior: when `rawBytes.length` is at or below
|
|
207
|
+
* `RAW_EMAIL_INLINE_THRESHOLD`, the event's `raw.data` is populated and
|
|
208
|
+
* `download.url` is still populated. Above the threshold, only `download.url`
|
|
209
|
+
* is populated. The download URL is always set regardless of inline status.
|
|
210
|
+
*
|
|
211
|
+
* Callers using the bundled parser can populate the header fields
|
|
212
|
+
* (`messageId`, `sender`, `recipient`, `subject`, `dateHeader`) directly
|
|
213
|
+
* from `toCanonicalHeaders(parsed)`. Accepting the flat fields rather than
|
|
214
|
+
* a canonical-headers object keeps this function usable by callers that
|
|
215
|
+
* do not use the bundled parser. A future release may add an optional
|
|
216
|
+
* canonical-headers parameter as an ergonomic alternative.
|
|
217
|
+
*
|
|
218
|
+
* @throws Error if `attachmentsDownloadUrl` disagrees with whether
|
|
219
|
+
* `parsed.attachments` is empty.
|
|
220
|
+
* @throws Error if `smtpRcptTo` is empty.
|
|
221
|
+
* @throws WebhookValidationError if the assembled event fails schema validation.
|
|
222
|
+
*/
|
|
223
|
+
function buildEventFromParsedData(params) {
|
|
224
|
+
const { parsed, attachmentsDownloadUrl, smtpRcptTo } = params;
|
|
225
|
+
const hasAttachments = parsed.attachments.length > 0;
|
|
226
|
+
if (hasAttachments && attachmentsDownloadUrl === null) throw new Error(`[@primitivedotdev/sdk/contract] attachmentsDownloadUrl must be non-null when parsed.attachments has ${parsed.attachments.length} entries`);
|
|
227
|
+
if (!hasAttachments && attachmentsDownloadUrl !== null) throw new Error(`[@primitivedotdev/sdk/contract] attachmentsDownloadUrl must be null when parsed.attachments is empty (got: ${JSON.stringify(attachmentsDownloadUrl)})`);
|
|
228
|
+
if (smtpRcptTo.length === 0) throw new Error("[@primitivedotdev/sdk/contract] smtpRcptTo must contain at least one recipient");
|
|
229
|
+
const raw_size_bytes = params.rawBytes.length;
|
|
230
|
+
const raw_sha256 = createHash("sha256").update(params.rawBytes).digest("hex");
|
|
231
|
+
const parsedInput = {
|
|
232
|
+
status: "complete",
|
|
233
|
+
body_text: parsed.body_text,
|
|
234
|
+
body_html: parsed.body_html,
|
|
235
|
+
reply_to: parsed.reply_to,
|
|
236
|
+
cc: parsed.cc,
|
|
237
|
+
bcc: parsed.bcc,
|
|
238
|
+
in_reply_to: parsed.in_reply_to,
|
|
239
|
+
references: parsed.references,
|
|
240
|
+
attachments: parsed.attachments
|
|
241
|
+
};
|
|
242
|
+
const input = {
|
|
243
|
+
email_id: params.emailId,
|
|
244
|
+
endpoint_id: params.endpointId,
|
|
245
|
+
message_id: params.messageId,
|
|
246
|
+
sender: params.sender,
|
|
247
|
+
recipient: params.recipient,
|
|
248
|
+
subject: params.subject,
|
|
249
|
+
received_at: params.receivedAt,
|
|
250
|
+
smtp_helo: params.smtpHelo,
|
|
251
|
+
smtp_mail_from: params.smtpMailFrom,
|
|
252
|
+
smtp_rcpt_to: smtpRcptTo,
|
|
253
|
+
raw_bytes: params.rawBytes,
|
|
254
|
+
raw_sha256,
|
|
255
|
+
raw_size_bytes,
|
|
256
|
+
attempt_count: params.attemptCount,
|
|
257
|
+
date_header: params.dateHeader ?? null,
|
|
258
|
+
download_url: params.downloadUrl,
|
|
259
|
+
download_expires_at: params.downloadExpiresAt,
|
|
260
|
+
attachments_download_url: attachmentsDownloadUrl,
|
|
261
|
+
parsed: parsedInput,
|
|
262
|
+
auth: params.auth,
|
|
263
|
+
analysis: params.analysis
|
|
264
|
+
};
|
|
265
|
+
return buildEmailReceivedEvent(input, params.buildOptions);
|
|
266
|
+
}
|
|
197
267
|
|
|
198
268
|
//#endregion
|
|
199
|
-
export { RAW_EMAIL_INLINE_THRESHOLD, WEBHOOK_VERSION, buildEmailReceivedEvent, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
|
269
|
+
export { RAW_EMAIL_INLINE_THRESHOLD, WEBHOOK_VERSION, buildEmailReceivedEvent, buildEventFromParsedData, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmailAuth, EmailReceivedEvent, ValidateEmailAuthResult, WebhookEvent } from "./types-
|
|
1
|
+
import { EmailAuth, EmailReceivedEvent, ValidateEmailAuthResult, WebhookEvent } from "./types-CKFmgitP.js";
|
|
2
2
|
import { ErrorObject } from "ajv";
|
|
3
3
|
|
|
4
4
|
//#region src/webhook/errors.d.ts
|
|
@@ -224,6 +224,95 @@ type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
|
224
224
|
declare function validateEmailReceivedEvent(input: unknown): EmailReceivedEvent;
|
|
225
225
|
declare function safeValidateEmailReceivedEvent(input: unknown): ValidationResult<EmailReceivedEvent>;
|
|
226
226
|
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/webhook/download-tokens.d.ts
|
|
229
|
+
/**
|
|
230
|
+
* Signed download tokens.
|
|
231
|
+
*
|
|
232
|
+
* A download token is a self-describing bearer credential for fetching a
|
|
233
|
+
* specific email's raw bytes or attachment bundle from a per-deployment
|
|
234
|
+
* download endpoint. It binds:
|
|
235
|
+
*
|
|
236
|
+
* - `email_id` — the specific email the token authorizes.
|
|
237
|
+
* - `aud` — a caller-chosen audience label (e.g. the resource kind being
|
|
238
|
+
* downloaded). Tokens minted for one audience will not verify under another.
|
|
239
|
+
* - `exp` — an absolute expiration time (unix seconds).
|
|
240
|
+
*
|
|
241
|
+
* Format: `<base64url(payload)>.<base64url(signature)>` where `signature`
|
|
242
|
+
* is HMAC-SHA256 over the base64url-encoded payload using the shared secret.
|
|
243
|
+
*
|
|
244
|
+
* The audience is an opaque caller-chosen string. Both the issuer and the
|
|
245
|
+
* verifier must agree on the exact bytes; the SDK does not prescribe a
|
|
246
|
+
* convention. New integrations are encouraged to namespace audiences
|
|
247
|
+
* (e.g. `primitive:raw-download`).
|
|
248
|
+
*
|
|
249
|
+
* Tokens are stateless: verification needs only the shared secret. Keep
|
|
250
|
+
* expirations as short as operationally tolerable.
|
|
251
|
+
*/
|
|
252
|
+
/**
|
|
253
|
+
* Input for issuing a download token.
|
|
254
|
+
*/
|
|
255
|
+
interface GenerateDownloadTokenOptions {
|
|
256
|
+
/** The email ID the token authorizes. */
|
|
257
|
+
emailId: string;
|
|
258
|
+
/** Absolute expiration as unix seconds (not a TTL). */
|
|
259
|
+
expiresAt: number;
|
|
260
|
+
/** Caller-chosen audience label; the verifier must supply the same value. */
|
|
261
|
+
audience: string;
|
|
262
|
+
/** Shared HMAC secret. */
|
|
263
|
+
secret: string;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Issue a signed download token.
|
|
267
|
+
*
|
|
268
|
+
* The resulting token is `<base64url-payload>.<base64url-signature>`, where
|
|
269
|
+
* the payload is `{"email_id":"...","exp":...,"aud":"..."}` (snake_case,
|
|
270
|
+
* field order fixed) and the signature is HMAC-SHA256 of the base64url
|
|
271
|
+
* payload string using `secret`.
|
|
272
|
+
*
|
|
273
|
+
* @param params - Token inputs.
|
|
274
|
+
* @returns The signed token string.
|
|
275
|
+
*/
|
|
276
|
+
declare function generateDownloadToken(params: GenerateDownloadTokenOptions): string;
|
|
277
|
+
/**
|
|
278
|
+
* Input for verifying a download token.
|
|
279
|
+
*/
|
|
280
|
+
interface VerifyDownloadTokenOptions {
|
|
281
|
+
/** The token string to verify. */
|
|
282
|
+
token: string;
|
|
283
|
+
/** Expected email ID — must match the token payload exactly. */
|
|
284
|
+
emailId: string;
|
|
285
|
+
/** Expected audience — must match the token payload exactly. */
|
|
286
|
+
audience: string;
|
|
287
|
+
/** Shared HMAC secret. */
|
|
288
|
+
secret: string;
|
|
289
|
+
/** Override the current time (unix seconds) for deterministic tests. */
|
|
290
|
+
nowSeconds?: number;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Result of verifying a download token.
|
|
294
|
+
*
|
|
295
|
+
* On failure, `error` is a short human-readable reason suitable for logs.
|
|
296
|
+
* Do not surface it to untrusted clients — it may reveal which check failed.
|
|
297
|
+
*/
|
|
298
|
+
type VerifyDownloadTokenResult = {
|
|
299
|
+
valid: true;
|
|
300
|
+
} | {
|
|
301
|
+
valid: false;
|
|
302
|
+
error: string;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Verify a signed download token.
|
|
306
|
+
*
|
|
307
|
+
* Returns a discriminated-union result. The function never throws for
|
|
308
|
+
* verification failures — only malformed inputs at the crypto layer would
|
|
309
|
+
* surface. Callers should check `result.valid` and log `result.error`.
|
|
310
|
+
*
|
|
311
|
+
* @param params - Verification inputs.
|
|
312
|
+
* @returns Whether the token is valid, plus a reason on failure.
|
|
313
|
+
*/
|
|
314
|
+
declare function verifyDownloadToken(params: VerifyDownloadTokenOptions): VerifyDownloadTokenResult;
|
|
315
|
+
|
|
227
316
|
//#endregion
|
|
228
317
|
//#region src/webhook/signing.d.ts
|
|
229
318
|
/**
|
|
@@ -522,8 +611,8 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
522
611
|
readonly url: {
|
|
523
612
|
readonly type: "string";
|
|
524
613
|
readonly format: "uri";
|
|
525
|
-
readonly pattern: "^https
|
|
526
|
-
readonly description: "
|
|
614
|
+
readonly pattern: "^https?://";
|
|
615
|
+
readonly description: "URL to download the raw email as-is in RFC 5322 format. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network (e.g. `http://localhost:4001/...`). Receivers that want to refuse plaintext downloads should check the scheme explicitly.";
|
|
527
616
|
};
|
|
528
617
|
readonly expires_at: {
|
|
529
618
|
readonly type: "string";
|
|
@@ -734,8 +823,8 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
734
823
|
readonly attachments_download_url: {
|
|
735
824
|
readonly type: ["string", "null"];
|
|
736
825
|
readonly format: "uri";
|
|
737
|
-
readonly pattern: "^https
|
|
738
|
-
readonly description: "
|
|
826
|
+
readonly pattern: "^https?://";
|
|
827
|
+
readonly description: "URL to download all attachments as a tar.gz archive. Null if the email had no attachments. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network. URL expires - check the expiration before downloading.";
|
|
739
828
|
};
|
|
740
829
|
};
|
|
741
830
|
readonly required: ["status", "error", "body_text", "body_html", "reply_to", "cc", "bcc", "in_reply_to", "references", "attachments", "attachments_download_url"];
|
|
@@ -1552,4 +1641,4 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
|
|
|
1552
1641
|
declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
|
|
1553
1642
|
|
|
1554
1643
|
//#endregion
|
|
1555
|
-
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, STANDARD_WEBHOOK_ID_HEADER as STANDARD_WEBHOOK_ID_HEADER$1, STANDARD_WEBHOOK_SIGNATURE_HEADER as STANDARD_WEBHOOK_SIGNATURE_HEADER$1, STANDARD_WEBHOOK_TIMESTAMP_HEADER as STANDARD_WEBHOOK_TIMESTAMP_HEADER$1, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, 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, signStandardWebhooksPayload as signStandardWebhooksPayload$1, signWebhookPayload as signWebhookPayload$1, validateEmailAuth as validateEmailAuth$1, validateEmailReceivedEvent as validateEmailReceivedEvent$1, verifyRawEmailDownload as verifyRawEmailDownload$1, verifyStandardWebhooksSignature as verifyStandardWebhooksSignature$1, verifyWebhookSignature as verifyWebhookSignature$1 };
|
|
1644
|
+
export { DecodeRawEmailOptions, GenerateDownloadTokenOptions, 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, STANDARD_WEBHOOK_ID_HEADER as STANDARD_WEBHOOK_ID_HEADER$1, STANDARD_WEBHOOK_SIGNATURE_HEADER as STANDARD_WEBHOOK_SIGNATURE_HEADER$1, STANDARD_WEBHOOK_TIMESTAMP_HEADER as STANDARD_WEBHOOK_TIMESTAMP_HEADER$1, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, VERIFICATION_ERRORS as VERIFICATION_ERRORS$1, VerifyDownloadTokenOptions, VerifyDownloadTokenResult, 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, generateDownloadToken as generateDownloadToken$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, signStandardWebhooksPayload as signStandardWebhooksPayload$1, signWebhookPayload as signWebhookPayload$1, validateEmailAuth as validateEmailAuth$1, validateEmailReceivedEvent as validateEmailReceivedEvent$1, verifyDownloadToken as verifyDownloadToken$1, verifyRawEmailDownload as verifyRawEmailDownload$1, verifyStandardWebhooksSignature as verifyStandardWebhooksSignature$1, verifyWebhookSignature as verifyWebhookSignature$1 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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-
|
|
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, STANDARD_WEBHOOK_ID_HEADER$1 as STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER$1 as STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER$1 as STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, 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, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyStandardWebhooksSignature$1 as verifyStandardWebhooksSignature, verifyWebhookSignature$1 as verifyWebhookSignature } from "./index-
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, SpfResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, 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, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
|
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-CKFmgitP.js";
|
|
2
|
+
import { DecodeRawEmailOptions, GenerateDownloadTokenOptions, 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, STANDARD_WEBHOOK_ID_HEADER$1 as STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER$1 as STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER$1 as STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyDownloadTokenOptions, VerifyDownloadTokenResult, 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, generateDownloadToken$1 as generateDownloadToken, 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, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyDownloadToken$1 as verifyDownloadToken, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyStandardWebhooksSignature$1 as verifyStandardWebhooksSignature, verifyWebhookSignature$1 as verifyWebhookSignature } from "./index-DLmAI4UQ.js";
|
|
3
|
+
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, 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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature } from "./webhook-
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature } from "./webhook-COe5N_Uj.js";
|
|
2
2
|
|
|
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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, 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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ interface EmailReceivedEvent$1 {
|
|
|
132
132
|
*/
|
|
133
133
|
download: {
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* URL to download the raw email as-is in RFC 5322 format. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network (e.g. `http://localhost:4001/...`). Receivers that want to refuse plaintext downloads should check the scheme explicitly.
|
|
136
136
|
*/
|
|
137
137
|
url: string;
|
|
138
138
|
/**
|
|
@@ -263,7 +263,7 @@ interface ParsedDataComplete$1 {
|
|
|
263
263
|
*/
|
|
264
264
|
attachments: WebhookAttachment$1[];
|
|
265
265
|
/**
|
|
266
|
-
*
|
|
266
|
+
* URL to download all attachments as a tar.gz archive. Null if the email had no attachments. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network. URL expires - check the expiration before downloading.
|
|
267
267
|
*/
|
|
268
268
|
attachments_download_url: (string | null);
|
|
269
269
|
}
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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-
|
|
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, STANDARD_WEBHOOK_ID_HEADER$1 as STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER$1 as STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER$1 as STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, 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, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyStandardWebhooksSignature$1 as verifyStandardWebhooksSignature, verifyWebhookSignature$1 as verifyWebhookSignature } from "../index-
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, SpfResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, 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, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
|
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-CKFmgitP.js";
|
|
2
|
+
import { DecodeRawEmailOptions, GenerateDownloadTokenOptions, 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, STANDARD_WEBHOOK_ID_HEADER$1 as STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER$1 as STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER$1 as STANDARD_WEBHOOK_TIMESTAMP_HEADER, SignResult, StandardWebhooksSignResult, StandardWebhooksVerifyOptions, VERIFICATION_ERRORS$1 as VERIFICATION_ERRORS, VerifyDownloadTokenOptions, VerifyDownloadTokenResult, 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, generateDownloadToken$1 as generateDownloadToken, 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, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload, validateEmailAuth$1 as validateEmailAuth, validateEmailReceivedEvent$1 as validateEmailReceivedEvent, verifyDownloadToken$1 as verifyDownloadToken, verifyRawEmailDownload$1 as verifyRawEmailDownload, verifyStandardWebhooksSignature$1 as verifyStandardWebhooksSignature, verifyWebhookSignature$1 as verifyWebhookSignature } from "../index-DLmAI4UQ.js";
|
|
3
|
+
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, 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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
package/dist/webhook/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature } from "../webhook-
|
|
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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature } from "../webhook-COe5N_Uj.js";
|
|
2
2
|
|
|
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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, 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, STANDARD_WEBHOOK_ID_HEADER, STANDARD_WEBHOOK_SIGNATURE_HEADER, STANDARD_WEBHOOK_TIMESTAMP_HEADER, SpfResult, VERIFICATION_ERRORS, WEBHOOK_VERSION, WebhookPayloadError, WebhookValidationError, WebhookVerificationError, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
|
@@ -131,8 +131,8 @@ const schema12 = {
|
|
|
131
131
|
"url": {
|
|
132
132
|
"type": "string",
|
|
133
133
|
"format": "uri",
|
|
134
|
-
"pattern": "^https
|
|
135
|
-
"description": "
|
|
134
|
+
"pattern": "^https?://",
|
|
135
|
+
"description": "URL to download the raw email as-is in RFC 5322 format. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network (e.g. `http://localhost:4001/...`). Receivers that want to refuse plaintext downloads should check the scheme explicitly."
|
|
136
136
|
},
|
|
137
137
|
"expires_at": {
|
|
138
138
|
"type": "string",
|
|
@@ -184,7 +184,7 @@ const schema12 = {
|
|
|
184
184
|
};
|
|
185
185
|
const pattern0 = new RegExp("^evt_[a-f0-9]{64}$", "u");
|
|
186
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");
|
|
187
|
-
const pattern4 = new RegExp("^https
|
|
187
|
+
const pattern4 = new RegExp("^https?://", "u");
|
|
188
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
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;
|
|
190
190
|
const pattern2 = new RegExp("^[a-fA-F0-9]{64}$", "u");
|
|
@@ -749,8 +749,8 @@ const schema18 = {
|
|
|
749
749
|
"attachments_download_url": {
|
|
750
750
|
"type": ["string", "null"],
|
|
751
751
|
"format": "uri",
|
|
752
|
-
"pattern": "^https
|
|
753
|
-
"description": "
|
|
752
|
+
"pattern": "^https?://",
|
|
753
|
+
"description": "URL to download all attachments as a tar.gz archive. Null if the email had no attachments. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network. URL expires - check the expiration before downloading."
|
|
754
754
|
}
|
|
755
755
|
},
|
|
756
756
|
"required": [
|
|
@@ -1797,8 +1797,8 @@ function validate15(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
1797
1797
|
instancePath: instancePath + "/attachments_download_url",
|
|
1798
1798
|
schemaPath: "#/properties/attachments_download_url/pattern",
|
|
1799
1799
|
keyword: "pattern",
|
|
1800
|
-
params: { pattern: "^https
|
|
1801
|
-
message: "must match pattern \"^https
|
|
1800
|
+
params: { pattern: "^https?://" },
|
|
1801
|
+
message: "must match pattern \"^https?://\""
|
|
1802
1802
|
};
|
|
1803
1803
|
if (vErrors === null) vErrors = [err66];
|
|
1804
1804
|
else vErrors.push(err66);
|
|
@@ -5465,8 +5465,8 @@ function validate11(data, { instancePath = "", parentData, parentDataProperty, r
|
|
|
5465
5465
|
instancePath: instancePath + "/email/content/download/url",
|
|
5466
5466
|
schemaPath: "#/properties/email/properties/content/properties/download/properties/url/pattern",
|
|
5467
5467
|
keyword: "pattern",
|
|
5468
|
-
params: { pattern: "^https
|
|
5469
|
-
message: "must match pattern \"^https
|
|
5468
|
+
params: { pattern: "^https?://" },
|
|
5469
|
+
message: "must match pattern \"^https?://\""
|
|
5470
5470
|
};
|
|
5471
5471
|
if (vErrors === null) vErrors = [err57];
|
|
5472
5472
|
else vErrors.push(err57);
|
|
@@ -5961,10 +5961,10 @@ function formatValidationIssue(error, input) {
|
|
|
5961
5961
|
message: `Invalid version format: ${JSON.stringify(actualValue ?? "unknown")}`,
|
|
5962
5962
|
suggestion: "Version must be a date in YYYY-MM-DD format (e.g., \"2025-12-14\")."
|
|
5963
5963
|
};
|
|
5964
|
-
if (pattern === "^https
|
|
5964
|
+
if (pattern === "^https?://") return {
|
|
5965
5965
|
field,
|
|
5966
|
-
message: `Invalid value for ${field}: must be a valid
|
|
5967
|
-
suggestion: `Check that ${fromFieldLabel(field)} is a complete URL including the
|
|
5966
|
+
message: `Invalid value for ${field}: must be a valid http:// or https:// URL`,
|
|
5967
|
+
suggestion: `Check that ${fromFieldLabel(field)} is a complete URL including the http:// or https:// scheme.`
|
|
5968
5968
|
};
|
|
5969
5969
|
if (pattern === "^[a-fA-F0-9]{64}$") return {
|
|
5970
5970
|
field,
|
|
@@ -6043,6 +6043,102 @@ function safeValidateEmailReceivedEvent(input) {
|
|
|
6043
6043
|
};
|
|
6044
6044
|
}
|
|
6045
6045
|
|
|
6046
|
+
//#endregion
|
|
6047
|
+
//#region src/webhook/download-tokens.ts
|
|
6048
|
+
const BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
6049
|
+
/**
|
|
6050
|
+
* Issue a signed download token.
|
|
6051
|
+
*
|
|
6052
|
+
* The resulting token is `<base64url-payload>.<base64url-signature>`, where
|
|
6053
|
+
* the payload is `{"email_id":"...","exp":...,"aud":"..."}` (snake_case,
|
|
6054
|
+
* field order fixed) and the signature is HMAC-SHA256 of the base64url
|
|
6055
|
+
* payload string using `secret`.
|
|
6056
|
+
*
|
|
6057
|
+
* @param params - Token inputs.
|
|
6058
|
+
* @returns The signed token string.
|
|
6059
|
+
*/
|
|
6060
|
+
function generateDownloadToken(params) {
|
|
6061
|
+
const { emailId, expiresAt, audience, secret } = params;
|
|
6062
|
+
const payload = {
|
|
6063
|
+
email_id: emailId,
|
|
6064
|
+
exp: expiresAt,
|
|
6065
|
+
aud: audience
|
|
6066
|
+
};
|
|
6067
|
+
const payloadJson = JSON.stringify(payload);
|
|
6068
|
+
const payloadStr = Buffer.from(payloadJson, "utf8").toString("base64url");
|
|
6069
|
+
const signature = createHmac("sha256", secret).update(payloadStr).digest("base64url");
|
|
6070
|
+
return `${payloadStr}.${signature}`;
|
|
6071
|
+
}
|
|
6072
|
+
/**
|
|
6073
|
+
* Verify a signed download token.
|
|
6074
|
+
*
|
|
6075
|
+
* Returns a discriminated-union result. The function never throws for
|
|
6076
|
+
* verification failures — only malformed inputs at the crypto layer would
|
|
6077
|
+
* surface. Callers should check `result.valid` and log `result.error`.
|
|
6078
|
+
*
|
|
6079
|
+
* @param params - Verification inputs.
|
|
6080
|
+
* @returns Whether the token is valid, plus a reason on failure.
|
|
6081
|
+
*/
|
|
6082
|
+
function verifyDownloadToken(params) {
|
|
6083
|
+
const { token, emailId, audience, secret, nowSeconds } = params;
|
|
6084
|
+
if (typeof token !== "string" || token.length === 0) return {
|
|
6085
|
+
valid: false,
|
|
6086
|
+
error: "Token is empty"
|
|
6087
|
+
};
|
|
6088
|
+
const firstDot = token.indexOf(".");
|
|
6089
|
+
const lastDot = token.lastIndexOf(".");
|
|
6090
|
+
if (firstDot === -1 || firstDot !== lastDot) return {
|
|
6091
|
+
valid: false,
|
|
6092
|
+
error: "Token is malformed: expected one '.'"
|
|
6093
|
+
};
|
|
6094
|
+
const payloadStr = token.slice(0, firstDot);
|
|
6095
|
+
const providedSignature = token.slice(firstDot + 1);
|
|
6096
|
+
if (payloadStr.length === 0 || providedSignature.length === 0) return {
|
|
6097
|
+
valid: false,
|
|
6098
|
+
error: "Token is malformed: empty part"
|
|
6099
|
+
};
|
|
6100
|
+
const expectedSignature = createHmac("sha256", secret).update(payloadStr).digest("base64url");
|
|
6101
|
+
const providedBytes = Buffer.from(providedSignature, "base64url");
|
|
6102
|
+
const expectedBytes = Buffer.from(expectedSignature, "base64url");
|
|
6103
|
+
if (providedBytes.length !== expectedBytes.length || !timingSafeEqual(providedBytes, expectedBytes)) return {
|
|
6104
|
+
valid: false,
|
|
6105
|
+
error: "Invalid signature"
|
|
6106
|
+
};
|
|
6107
|
+
if (!BASE64URL_PATTERN.test(payloadStr)) return {
|
|
6108
|
+
valid: false,
|
|
6109
|
+
error: "Token payload is not valid base64url"
|
|
6110
|
+
};
|
|
6111
|
+
const decodedJson = Buffer.from(payloadStr, "base64url").toString("utf8");
|
|
6112
|
+
let payload;
|
|
6113
|
+
try {
|
|
6114
|
+
payload = JSON.parse(decodedJson);
|
|
6115
|
+
} catch {
|
|
6116
|
+
return {
|
|
6117
|
+
valid: false,
|
|
6118
|
+
error: "Token payload is not valid JSON"
|
|
6119
|
+
};
|
|
6120
|
+
}
|
|
6121
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload) || typeof payload.email_id !== "string" || typeof payload.aud !== "string" || typeof payload.exp !== "number") return {
|
|
6122
|
+
valid: false,
|
|
6123
|
+
error: "Token payload has wrong shape"
|
|
6124
|
+
};
|
|
6125
|
+
const { email_id, aud, exp } = payload;
|
|
6126
|
+
if (aud !== audience) return {
|
|
6127
|
+
valid: false,
|
|
6128
|
+
error: "Audience mismatch"
|
|
6129
|
+
};
|
|
6130
|
+
if (email_id !== emailId) return {
|
|
6131
|
+
valid: false,
|
|
6132
|
+
error: "Email ID mismatch"
|
|
6133
|
+
};
|
|
6134
|
+
const now = nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
6135
|
+
if (exp <= now) return {
|
|
6136
|
+
valid: false,
|
|
6137
|
+
error: "Token is expired"
|
|
6138
|
+
};
|
|
6139
|
+
return { valid: true };
|
|
6140
|
+
}
|
|
6141
|
+
|
|
6046
6142
|
//#endregion
|
|
6047
6143
|
//#region src/webhook/encoding.ts
|
|
6048
6144
|
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
@@ -6479,8 +6575,8 @@ const emailReceivedEventJsonSchema = {
|
|
|
6479
6575
|
"url": {
|
|
6480
6576
|
"type": "string",
|
|
6481
6577
|
"format": "uri",
|
|
6482
|
-
"pattern": "^https
|
|
6483
|
-
"description": "
|
|
6578
|
+
"pattern": "^https?://",
|
|
6579
|
+
"description": "URL to download the raw email as-is in RFC 5322 format. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network (e.g. `http://localhost:4001/...`). Receivers that want to refuse plaintext downloads should check the scheme explicitly."
|
|
6484
6580
|
},
|
|
6485
6581
|
"expires_at": {
|
|
6486
6582
|
"type": "string",
|
|
@@ -6689,8 +6785,8 @@ const emailReceivedEventJsonSchema = {
|
|
|
6689
6785
|
"attachments_download_url": {
|
|
6690
6786
|
"type": ["string", "null"],
|
|
6691
6787
|
"format": "uri",
|
|
6692
|
-
"pattern": "^https
|
|
6693
|
-
"description": "
|
|
6788
|
+
"pattern": "^https?://",
|
|
6789
|
+
"description": "URL to download all attachments as a tar.gz archive. Null if the email had no attachments. Managed Primitive always issues HTTPS. Self-host deployments may issue HTTP URLs that resolve inside the operator's network. URL expires - check the expiration before downloading."
|
|
6694
6790
|
}
|
|
6695
6791
|
},
|
|
6696
6792
|
"required": [
|
|
@@ -7907,4 +8003,4 @@ function verifyRawEmailDownload(downloaded, event) {
|
|
|
7907
8003
|
}
|
|
7908
8004
|
|
|
7909
8005
|
//#endregion
|
|
7910
|
-
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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
|
8006
|
+
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, confirmedHeaders, decodeRawEmail, emailReceivedEventJsonSchema, generateDownloadToken, getDownloadTimeRemaining, handleWebhook, isDownloadExpired, isEmailReceivedEvent, isRawIncluded, parseWebhookEvent, safeValidateEmailReceivedEvent, signStandardWebhooksPayload, signWebhookPayload, validateEmailAuth, validateEmailReceivedEvent, verifyDownloadToken, verifyRawEmailDownload, verifyStandardWebhooksSignature, verifyWebhookSignature };
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primitivedotdev/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Official Primitive Node.js SDK — webhook, api, openapi, contract, and parser modules",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -93,9 +93,9 @@
|
|
|
93
93
|
"test": "vitest run",
|
|
94
94
|
"test:coverage": "vitest run --coverage",
|
|
95
95
|
"test:watch": "vitest",
|
|
96
|
-
"typecheck": "pnpm generate && tsc --noEmit",
|
|
97
|
-
"lint": "biome check src/index.ts src/validation.ts src/types.ts src/webhook src/contract src/parser src/api/index.ts src/openapi/index.ts src/oclif tests/",
|
|
98
|
-
"lint:fix": "biome check --write src/index.ts src/validation.ts src/types.ts src/webhook src/contract src/parser src/api/index.ts src/openapi/index.ts src/oclif tests/",
|
|
96
|
+
"typecheck": "pnpm generate && tsc --noEmit -p tsconfig.typecheck.json",
|
|
97
|
+
"lint": "biome check --error-on-warnings src/index.ts src/validation.ts src/types.ts src/webhook src/contract src/parser src/api/index.ts src/openapi/index.ts src/oclif tests/",
|
|
98
|
+
"lint:fix": "biome check --write --error-on-warnings src/index.ts src/validation.ts src/types.ts src/webhook src/contract src/parser src/api/index.ts src/openapi/index.ts src/oclif tests/",
|
|
99
99
|
"prepack": "pnpm build && oclif manifest",
|
|
100
100
|
"postpack": "shx rm -f oclif.manifest.json",
|
|
101
101
|
"prepublishOnly": "pnpm build"
|