@primitivedotdev/sdk 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -210
- package/dist/address-parser-BYn8oW5r.js +111 -0
- package/dist/api/generated/index.js +1 -1
- package/dist/api/generated/sdk.gen.js +17 -0
- package/dist/api/index.d.ts +2 -1877
- package/dist/api/index.js +255 -0
- package/dist/api-COSr-Fqm.js +1311 -0
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/contract/index.d.ts +6 -8
- package/dist/contract/index.js +28 -15
- package/dist/{index-DLmAI4UQ.d.ts → index-CbEivn3S.d.ts} +13 -30
- package/dist/index-DVow4Fjd.d.ts +2140 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +10 -3
- package/dist/oclif/api-command.js +89 -1
- package/dist/openapi/index.d.ts +8 -3
- package/dist/openapi/openapi.generated.js +412 -1
- package/dist/openapi/operations.generated.js +255 -0
- package/dist/parser/address-parser.js +129 -0
- package/dist/parser/index.d.ts +4 -19
- package/dist/parser/index.js +7 -122
- package/dist/received-email-D6tKtWwW.js +69 -0
- package/dist/received-email-DNjpq_Wt.d.ts +37 -0
- package/dist/{types-CKFmgitP.d.ts → types-9vXGZjPd.d.ts} +3 -19
- package/dist/types.generated.js +7 -0
- package/dist/types.js +53 -0
- package/dist/webhook/index.d.ts +4 -3
- package/dist/webhook/index.js +3 -3
- package/dist/webhook/received-email.js +82 -0
- package/dist/{webhook-COe5N_Uj.js → webhook-zkN4wUTs.js} +119 -81
- package/oclif.manifest.json +54 -8
- package/package.json +5 -2
- package/dist/chunk-Cl8Af3a2.js +0 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { C as ParsedDataFailed, D as RawContentDownloadOnly, M as WebhookAttachment, O as RawContentInline, S as ParsedDataComplete, c as EmailAnalysis, l as EmailAuth, s as EmailAddress, u as EmailReceivedEvent, w as ParsedError } from "../types-9vXGZjPd.js";
|
|
2
|
+
import { C as signStandardWebhooksPayload, h as WEBHOOK_VERSION, j as signWebhookPayload, k as SignResult, x as StandardWebhooksSignResult } from "../index-CbEivn3S.js";
|
|
3
3
|
|
|
4
4
|
//#region src/contract/contract.d.ts
|
|
5
|
-
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
6
|
-
|
|
7
5
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
8
6
|
declare const RAW_EMAIL_INLINE_THRESHOLD = 262144;
|
|
9
7
|
/** Parsed content input when parsing succeeded. */
|
|
@@ -142,8 +140,7 @@ declare function generateEventId(endpoint_id: string, email_id: string): string;
|
|
|
142
140
|
* ```
|
|
143
141
|
*/
|
|
144
142
|
declare function buildEmailReceivedEvent(input: EmailReceivedEventInput, options?: {
|
|
145
|
-
/** Override the attempted-at timestamp, typically for tests. */
|
|
146
|
-
attempted_at?: string;
|
|
143
|
+
/** Override the attempted-at timestamp, typically for tests. */attempted_at?: string;
|
|
147
144
|
}): EmailReceivedEvent;
|
|
148
145
|
/**
|
|
149
146
|
* Input for building an `EmailReceivedEvent` directly from parser output.
|
|
@@ -221,5 +218,6 @@ interface BuildEventFromParsedDataOptions {
|
|
|
221
218
|
* @throws Error if `smtpRcptTo` is empty.
|
|
222
219
|
* @throws WebhookValidationError if the assembled event fails schema validation.
|
|
223
220
|
*/
|
|
224
|
-
declare function buildEventFromParsedData(params: BuildEventFromParsedDataOptions): EmailReceivedEvent;
|
|
225
|
-
|
|
221
|
+
declare function buildEventFromParsedData(params: BuildEventFromParsedDataOptions): EmailReceivedEvent;
|
|
222
|
+
//#endregion
|
|
223
|
+
export { BuildEventFromParsedDataOptions, type EmailAddress, type EmailAnalysis, type EmailAuth, type EmailReceivedEvent, EmailReceivedEventInput, type ParsedDataComplete, type ParsedDataFailed, type ParsedError, ParsedInput, ParsedInputComplete, ParsedInputFailed, RAW_EMAIL_INLINE_THRESHOLD, type RawContentDownloadOnly, type RawContentInline, type SignResult, type StandardWebhooksSignResult, WEBHOOK_VERSION, type WebhookAttachment, buildEmailReceivedEvent, buildEventFromParsedData, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
package/dist/contract/index.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as signStandardWebhooksPayload, L as validateEmailReceivedEvent, M as signWebhookPayload, d as WEBHOOK_VERSION } from "../webhook-zkN4wUTs.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
|
|
4
3
|
//#region src/contract/contract.ts
|
|
4
|
+
/**
|
|
5
|
+
* Primitive Contract
|
|
6
|
+
*
|
|
7
|
+
* This module exposes the exact functions used by Primitive servers to construct
|
|
8
|
+
* webhook payloads. It serves two purposes:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Build-time type safety**: Primitive producer code can import these types
|
|
11
|
+
* and functions so schema changes surface as TypeScript errors instead of
|
|
12
|
+
* runtime contract drift.
|
|
13
|
+
*
|
|
14
|
+
* 2. **Debugging transparency**: If you receive a malformed payload, you can
|
|
15
|
+
* compare it against these exact types and builder functions to identify
|
|
16
|
+
* which side broke the contract.
|
|
17
|
+
*
|
|
18
|
+
* This package is also useful for building test fixtures that match real
|
|
19
|
+
* payloads exactly.
|
|
20
|
+
*
|
|
21
|
+
* @module @primitivedotdev/sdk/contract
|
|
22
|
+
*/
|
|
5
23
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
6
24
|
const RAW_EMAIL_INLINE_THRESHOLD = 262144;
|
|
7
25
|
/**
|
|
@@ -40,8 +58,7 @@ function validateTimestamp(timestamp, fieldName) {
|
|
|
40
58
|
*/
|
|
41
59
|
function generateEventId(endpoint_id, email_id) {
|
|
42
60
|
const hashInput = `email.received:${WEBHOOK_VERSION}:${endpoint_id}:${email_id}`;
|
|
43
|
-
|
|
44
|
-
return `evt_${hash}`;
|
|
61
|
+
return `evt_${createHash("sha256").update(hashInput).digest("hex")}`;
|
|
45
62
|
}
|
|
46
63
|
/**
|
|
47
64
|
* Build an `EmailReceivedEvent` from producer-side input.
|
|
@@ -92,13 +109,12 @@ function generateEventId(endpoint_id, email_id) {
|
|
|
92
109
|
*/
|
|
93
110
|
function buildEmailReceivedEvent(input, options) {
|
|
94
111
|
const event_id = generateEventId(input.endpoint_id, input.email_id);
|
|
95
|
-
const attempted_at = options?.attempted_at ? validateTimestamp(options.attempted_at, "attempted_at") : new Date().toISOString();
|
|
112
|
+
const attempted_at = options?.attempted_at ? validateTimestamp(options.attempted_at, "attempted_at") : (/* @__PURE__ */ new Date()).toISOString();
|
|
96
113
|
const raw_size_bytes = input.raw_bytes.length;
|
|
97
114
|
if (input.raw_size_bytes !== raw_size_bytes) throw new Error(`[@primitivedotdev/sdk/contract] Invalid raw_size_bytes: ${input.raw_size_bytes}. Expected ${raw_size_bytes} based on raw_bytes length`);
|
|
98
115
|
const raw_sha256 = createHash("sha256").update(input.raw_bytes).digest("hex");
|
|
99
116
|
if (input.raw_sha256 !== raw_sha256) throw new Error(`[@primitivedotdev/sdk/contract] Invalid raw_sha256: "${input.raw_sha256}". Expected ${raw_sha256} based on raw_bytes`);
|
|
100
|
-
const
|
|
101
|
-
const rawContent = shouldInline ? {
|
|
117
|
+
const rawContent = raw_size_bytes <= 262144 ? {
|
|
102
118
|
included: true,
|
|
103
119
|
encoding: "base64",
|
|
104
120
|
max_inline_bytes: RAW_EMAIL_INLINE_THRESHOLD,
|
|
@@ -156,7 +172,7 @@ function buildEmailReceivedEvent(input, options) {
|
|
|
156
172
|
attachments: [],
|
|
157
173
|
attachments_download_url: null
|
|
158
174
|
};
|
|
159
|
-
|
|
175
|
+
return validateEmailReceivedEvent({
|
|
160
176
|
id: event_id,
|
|
161
177
|
event: "email.received",
|
|
162
178
|
version: WEBHOOK_VERSION,
|
|
@@ -191,8 +207,7 @@ function buildEmailReceivedEvent(input, options) {
|
|
|
191
207
|
analysis: input.analysis,
|
|
192
208
|
auth: input.auth
|
|
193
209
|
}
|
|
194
|
-
};
|
|
195
|
-
return validateEmailReceivedEvent(event);
|
|
210
|
+
});
|
|
196
211
|
}
|
|
197
212
|
/**
|
|
198
213
|
* Build an `EmailReceivedEvent` from parsed email data plus delivery metadata.
|
|
@@ -239,7 +254,7 @@ function buildEventFromParsedData(params) {
|
|
|
239
254
|
references: parsed.references,
|
|
240
255
|
attachments: parsed.attachments
|
|
241
256
|
};
|
|
242
|
-
|
|
257
|
+
return buildEmailReceivedEvent({
|
|
243
258
|
email_id: params.emailId,
|
|
244
259
|
endpoint_id: params.endpointId,
|
|
245
260
|
message_id: params.messageId,
|
|
@@ -261,9 +276,7 @@ function buildEventFromParsedData(params) {
|
|
|
261
276
|
parsed: parsedInput,
|
|
262
277
|
auth: params.auth,
|
|
263
278
|
analysis: params.analysis
|
|
264
|
-
};
|
|
265
|
-
return buildEmailReceivedEvent(input, params.buildOptions);
|
|
279
|
+
}, params.buildOptions);
|
|
266
280
|
}
|
|
267
|
-
|
|
268
281
|
//#endregion
|
|
269
|
-
export { RAW_EMAIL_INLINE_THRESHOLD, WEBHOOK_VERSION, buildEmailReceivedEvent, buildEventFromParsedData, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
|
282
|
+
export { RAW_EMAIL_INLINE_THRESHOLD, WEBHOOK_VERSION, buildEmailReceivedEvent, buildEventFromParsedData, generateEventId, signStandardWebhooksPayload, signWebhookPayload };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { N as WebhookEvent, j as ValidateEmailAuthResult, l as EmailAuth, u as EmailReceivedEvent } from "./types-9vXGZjPd.js";
|
|
2
|
+
import { t as ReceivedEmail } from "./received-email-DNjpq_Wt.js";
|
|
2
3
|
import { ErrorObject } from "ajv";
|
|
3
4
|
|
|
4
5
|
//#region src/webhook/errors.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Verification error definitions.
|
|
7
|
-
* Use these for documentation, dashboards, and i18n.
|
|
8
|
-
*/
|
|
9
6
|
/**
|
|
10
7
|
* Verification error definitions.
|
|
11
8
|
* Use these for documentation, dashboards, and i18n.
|
|
@@ -210,7 +207,8 @@ declare class RawEmailDecodeError extends PrimitiveWebhookError {
|
|
|
210
207
|
readonly code: RawEmailDecodeErrorCode;
|
|
211
208
|
readonly suggestion: string;
|
|
212
209
|
constructor(code: RawEmailDecodeErrorCode, message?: string);
|
|
213
|
-
}
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
214
212
|
//#region src/validation.d.ts
|
|
215
213
|
interface ValidationSuccess<T> {
|
|
216
214
|
success: true;
|
|
@@ -223,7 +221,6 @@ interface ValidationFailure {
|
|
|
223
221
|
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
224
222
|
declare function validateEmailReceivedEvent(input: unknown): EmailReceivedEvent;
|
|
225
223
|
declare function safeValidateEmailReceivedEvent(input: unknown): ValidationResult<EmailReceivedEvent>;
|
|
226
|
-
|
|
227
224
|
//#endregion
|
|
228
225
|
//#region src/webhook/download-tokens.d.ts
|
|
229
226
|
/**
|
|
@@ -312,7 +309,6 @@ type VerifyDownloadTokenResult = {
|
|
|
312
309
|
* @returns Whether the token is valid, plus a reason on failure.
|
|
313
310
|
*/
|
|
314
311
|
declare function verifyDownloadToken(params: VerifyDownloadTokenOptions): VerifyDownloadTokenResult;
|
|
315
|
-
|
|
316
312
|
//#endregion
|
|
317
313
|
//#region src/webhook/signing.d.ts
|
|
318
314
|
/**
|
|
@@ -405,7 +401,6 @@ declare function signWebhookPayload(rawBody: string | Buffer, secret: string | B
|
|
|
405
401
|
* ```
|
|
406
402
|
*/
|
|
407
403
|
declare function verifyWebhookSignature(opts: VerifyOptions): true;
|
|
408
|
-
|
|
409
404
|
//#endregion
|
|
410
405
|
//#region src/webhook/standard-webhooks.d.ts
|
|
411
406
|
/**
|
|
@@ -457,15 +452,6 @@ interface StandardWebhooksVerifyOptions {
|
|
|
457
452
|
/** Override current time for testing (unix seconds) */
|
|
458
453
|
nowSeconds?: number;
|
|
459
454
|
}
|
|
460
|
-
/**
|
|
461
|
-
* Prepare a Standard Webhooks secret for HMAC computation.
|
|
462
|
-
*
|
|
463
|
-
* Strips the "whsec_" prefix if present, then base64-decodes the remainder
|
|
464
|
-
* to produce the raw HMAC key bytes.
|
|
465
|
-
*
|
|
466
|
-
* @internal
|
|
467
|
-
*/
|
|
468
|
-
|
|
469
455
|
/**
|
|
470
456
|
* Sign a webhook payload using the Standard Webhooks format.
|
|
471
457
|
*
|
|
@@ -481,7 +467,6 @@ declare function signStandardWebhooksPayload(rawBody: string | Buffer, secret: s
|
|
|
481
467
|
* Throws `WebhookVerificationError` on failure with a specific error code.
|
|
482
468
|
*/
|
|
483
469
|
declare function verifyStandardWebhooksSignature(opts: StandardWebhooksVerifyOptions): true;
|
|
484
|
-
|
|
485
470
|
//#endregion
|
|
486
471
|
//#region src/schema.generated.d.ts
|
|
487
472
|
/**
|
|
@@ -1273,7 +1258,8 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
1273
1258
|
readonly description: "DKIM signature verification result for a single signature.";
|
|
1274
1259
|
};
|
|
1275
1260
|
};
|
|
1276
|
-
};
|
|
1261
|
+
};
|
|
1262
|
+
//#endregion
|
|
1277
1263
|
//#region src/webhook/auth.d.ts
|
|
1278
1264
|
/**
|
|
1279
1265
|
* Validate email authentication and compute a verdict.
|
|
@@ -1335,7 +1321,6 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
1335
1321
|
* ```
|
|
1336
1322
|
*/
|
|
1337
1323
|
declare function validateEmailAuth(auth: EmailAuth): ValidateEmailAuthResult;
|
|
1338
|
-
|
|
1339
1324
|
//#endregion
|
|
1340
1325
|
//#region src/webhook/version.d.ts
|
|
1341
1326
|
/**
|
|
@@ -1351,15 +1336,8 @@ declare function validateEmailAuth(auth: EmailAuth): ValidateEmailAuthResult;
|
|
|
1351
1336
|
* need to handle version-specific behavior.
|
|
1352
1337
|
*/
|
|
1353
1338
|
declare const WEBHOOK_VERSION = "2025-12-14";
|
|
1354
|
-
|
|
1355
1339
|
//#endregion
|
|
1356
1340
|
//#region src/webhook/index.d.ts
|
|
1357
|
-
/**
|
|
1358
|
-
* Valid webhook version format (YYYY-MM-DD date string).
|
|
1359
|
-
* The SDK accepts any valid date-formatted version, not just the current one,
|
|
1360
|
-
* for forward and backward compatibility.
|
|
1361
|
-
*/
|
|
1362
|
-
|
|
1363
1341
|
/**
|
|
1364
1342
|
* Parse a webhook payload, returning typed events for known types
|
|
1365
1343
|
* and UnknownEvent for future event types.
|
|
@@ -1484,6 +1462,12 @@ interface HandleWebhookOptions {
|
|
|
1484
1462
|
* ```
|
|
1485
1463
|
*/
|
|
1486
1464
|
declare function handleWebhook(options: HandleWebhookOptions): EmailReceivedEvent;
|
|
1465
|
+
interface ReceiveRequestOptions {
|
|
1466
|
+
secret: string;
|
|
1467
|
+
toleranceSeconds?: number;
|
|
1468
|
+
}
|
|
1469
|
+
declare function receive(options: HandleWebhookOptions): ReceivedEmail;
|
|
1470
|
+
declare function receive(request: Request, options: ReceiveRequestOptions): Promise<ReceivedEmail>;
|
|
1487
1471
|
/**
|
|
1488
1472
|
* Returns headers for the optional "content discard" feature.
|
|
1489
1473
|
*
|
|
@@ -1639,6 +1623,5 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
|
|
|
1639
1623
|
* ```
|
|
1640
1624
|
*/
|
|
1641
1625
|
declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
|
|
1642
|
-
|
|
1643
1626
|
//#endregion
|
|
1644
|
-
export {
|
|
1627
|
+
export { VerifyOptions as A, PAYLOAD_ERRORS as B, signStandardWebhooksPayload as C, PRIMITIVE_CONFIRMED_HEADER as D, LEGACY_SIGNATURE_HEADER as E, VerifyDownloadTokenResult as F, VERIFICATION_ERRORS as G, RAW_EMAIL_ERRORS as H, generateDownloadToken as I, WebhookPayloadErrorCode as J, WebhookErrorCode as K, verifyDownloadToken as L, verifyWebhookSignature as M, GenerateDownloadTokenOptions as N, PRIMITIVE_SIGNATURE_HEADER as O, VerifyDownloadTokenOptions as P, WebhookVerificationErrorCode as Q, safeValidateEmailReceivedEvent as R, StandardWebhooksVerifyOptions as S, LEGACY_CONFIRMED_HEADER as T, RawEmailDecodeError as U, PrimitiveWebhookError as V, RawEmailDecodeErrorCode as W, WebhookValidationErrorCode as X, WebhookValidationError as Y, WebhookVerificationError as Z, emailReceivedEventJsonSchema as _, confirmedHeaders as a, STANDARD_WEBHOOK_TIMESTAMP_HEADER as b, handleWebhook as c, isRawIncluded as d, parseWebhookEvent as f, validateEmailAuth as g, WEBHOOK_VERSION as h, WebhookHeaders as i, signWebhookPayload as j, SignResult as k, isDownloadExpired as l, verifyRawEmailDownload as m, HandleWebhookOptions as n, decodeRawEmail as o, receive as p, WebhookPayloadError as q, ReceiveRequestOptions as r, getDownloadTimeRemaining as s, DecodeRawEmailOptions as t, isEmailReceivedEvent as u, STANDARD_WEBHOOK_ID_HEADER as v, verifyStandardWebhooksSignature as w, StandardWebhooksSignResult as x, STANDARD_WEBHOOK_SIGNATURE_HEADER as y, validateEmailReceivedEvent as z };
|