@primitivedotdev/sdk 1.7.0 → 1.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 +83 -0
- package/dist/api/index.d.ts +4 -4
- package/dist/api/index.js +3 -3
- package/dist/{api-ClLMDF81.js → api-CwpE8_17.js} +178 -1
- package/dist/contract/index.d.ts +2 -2
- package/dist/contract/index.js +1 -1
- package/dist/{errors-DyuAXctD.d.ts → errors-bXUNXAlf.d.ts} +1 -1
- package/dist/{index-iZWfb98V.d.ts → index-BDnY9HH-.d.ts} +30 -48
- package/dist/{index-BnbrY8kp.d.ts → index-DZ7eZB3M.d.ts} +680 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/openapi/index.js +1 -1
- package/dist/{operations.generated-DQIrhCT5.js → operations.generated-03WHPOSm.js} +1508 -57
- package/dist/parser/index.d.ts +1 -1
- package/dist/{types-QT2ss9ho.d.ts → types-BjnIxPED.d.ts} +97 -2
- package/dist/webhook/index.d.ts +4 -4
- package/dist/webhook/index.js +2 -2
- package/dist/{webhook-CwjCyFv-.js → webhook-CiIPtegj.js} +155 -26
- package/dist/x402/index.d.ts +136 -1
- package/dist/x402/index.js +178 -2
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as WebhookEvent, P as ValidateEmailAuthResult, d as EmailAuth, f as EmailReceivedEvent } from "./types-
|
|
2
|
-
import { m as ReceivedEmail, u as WebhookValidationError } from "./errors-
|
|
1
|
+
import { I as WebhookEvent, P as ValidateEmailAuthResult, d as EmailAuth, f as EmailReceivedEvent } from "./types-BjnIxPED.js";
|
|
2
|
+
import { m as ReceivedEmail, u as WebhookValidationError } from "./errors-bXUNXAlf.js";
|
|
3
3
|
|
|
4
4
|
//#region src/validation.d.ts
|
|
5
5
|
interface ValidationSuccess<T> {
|
|
@@ -1454,20 +1454,7 @@ declare const WEBHOOK_VERSION = "2025-12-14";
|
|
|
1454
1454
|
* }
|
|
1455
1455
|
* ```
|
|
1456
1456
|
*/
|
|
1457
|
-
declare function parseWebhookEvent(input: unknown): WebhookEvent;
|
|
1458
|
-
/**
|
|
1459
|
-
* Type guard to check if a webhook event is an EmailReceivedEvent.
|
|
1460
|
-
*
|
|
1461
|
-
* @example
|
|
1462
|
-
* ```typescript
|
|
1463
|
-
* const event = parseWebhookEvent(payload);
|
|
1464
|
-
* if (isEmailReceivedEvent(event)) {
|
|
1465
|
-
* // TypeScript knows event is EmailReceivedEvent
|
|
1466
|
-
* console.log(event.email.headers.subject);
|
|
1467
|
-
* }
|
|
1468
|
-
* ```
|
|
1469
|
-
*/
|
|
1470
|
-
declare function isEmailReceivedEvent(event: WebhookEvent | unknown): event is EmailReceivedEvent;
|
|
1457
|
+
declare function parseWebhookEvent(input: unknown, eventType?: string | null): WebhookEvent;
|
|
1471
1458
|
/**
|
|
1472
1459
|
* Request headers in any common format.
|
|
1473
1460
|
*
|
|
@@ -1505,44 +1492,39 @@ interface HandleWebhookOptions {
|
|
|
1505
1492
|
toleranceSeconds?: number;
|
|
1506
1493
|
}
|
|
1507
1494
|
/**
|
|
1508
|
-
*
|
|
1495
|
+
* The header that names the webhook event for ALL event families
|
|
1496
|
+
* (`email.*`, `payment.*`, `interaction.*`). It is the primary discriminator
|
|
1497
|
+
* the parser keys on, because the stored body is sent verbatim with no envelope.
|
|
1498
|
+
*/
|
|
1499
|
+
declare const WEBHOOK_EVENT_HEADER = "X-Webhook-Event";
|
|
1500
|
+
/**
|
|
1501
|
+
* Read the `X-Webhook-Event` header value (case-insensitive). Returns null when
|
|
1502
|
+
* the header is absent.
|
|
1503
|
+
*/
|
|
1504
|
+
declare function getEventHeader(headers: WebhookHeaders): string | null;
|
|
1505
|
+
/**
|
|
1506
|
+
* Verify, then parse any webhook event into a typed value.
|
|
1509
1507
|
*
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
* 3. Validates the payload against the canonical JSON schema
|
|
1514
|
-
* 4. Returns a fully typed EmailReceivedEvent
|
|
1508
|
+
* Unlike {@link handleWebhook}, this returns the full {@link WebhookEvent}
|
|
1509
|
+
* union, so it handles `payment.*` and `interaction.x402.*` events in addition
|
|
1510
|
+
* to `email.*`. The flow is:
|
|
1515
1511
|
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* @throws {WebhookValidationError} If schema validation fails
|
|
1512
|
+
* 1. Verify the signature over the RAW body (works for every event family).
|
|
1513
|
+
* 2. Parse the JSON body.
|
|
1514
|
+
* 3. Classify on the `X-Webhook-Event` HEADER (the primary discriminator),
|
|
1515
|
+
* returning a typed event for known types and an UnknownEvent for the rest.
|
|
1521
1516
|
*
|
|
1522
1517
|
* @example
|
|
1523
1518
|
* ```typescript
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1528
|
-
*
|
|
1529
|
-
*
|
|
1530
|
-
* headers: req.headers,
|
|
1531
|
-
* secret: process.env.PRIMITIVE_WEBHOOK_SECRET,
|
|
1532
|
-
* });
|
|
1533
|
-
*
|
|
1534
|
-
* console.log('Email from:', event.email.headers.from);
|
|
1535
|
-
* res.json({ received: true });
|
|
1536
|
-
* } catch (err) {
|
|
1537
|
-
* if (err instanceof PrimitiveWebhookError) {
|
|
1538
|
-
* console.error(`[${err.code}] ${err.message}`);
|
|
1539
|
-
* return res.status(400).json({ error: err.code });
|
|
1540
|
-
* }
|
|
1541
|
-
* throw err;
|
|
1542
|
-
* }
|
|
1543
|
-
* });
|
|
1519
|
+
* const event = handleWebhookEvent({ body, headers, secret });
|
|
1520
|
+
* if (isPaymentSettledEvent(event)) {
|
|
1521
|
+
* // typed PaymentSettledEvent
|
|
1522
|
+
* } else if (isInteractionX402Event(event)) {
|
|
1523
|
+
* // typed interaction.x402.* event
|
|
1524
|
+
* }
|
|
1544
1525
|
* ```
|
|
1545
1526
|
*/
|
|
1527
|
+
declare function handleWebhookEvent(options: HandleWebhookOptions): WebhookEvent;
|
|
1546
1528
|
declare function handleWebhook(options: HandleWebhookOptions): EmailReceivedEvent;
|
|
1547
1529
|
interface ReceiveRequestOptions {
|
|
1548
1530
|
secret: string;
|
|
@@ -1706,4 +1688,4 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
|
|
|
1706
1688
|
*/
|
|
1707
1689
|
declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
|
|
1708
1690
|
//#endregion
|
|
1709
|
-
export {
|
|
1691
|
+
export { PRIMITIVE_SIGNATURE_HEADER as A, safeValidateEmailReceivedEvent as B, StandardWebhooksSignResult as C, LEGACY_CONFIRMED_HEADER as D, verifyStandardWebhooksSignature as E, GenerateDownloadTokenOptions as F, VerifyDownloadTokenOptions as I, VerifyDownloadTokenResult as L, VerifyOptions as M, signWebhookPayload as N, LEGACY_SIGNATURE_HEADER as O, verifyWebhookSignature as P, generateDownloadToken as R, STANDARD_WEBHOOK_TIMESTAMP_HEADER as S, signStandardWebhooksPayload as T, validateEmailReceivedEvent as V, WEBHOOK_VERSION as _, WebhookHeaders as a, STANDARD_WEBHOOK_ID_HEADER as b, getDownloadTimeRemaining as c, handleWebhookEvent as d, isDownloadExpired as f, verifyRawEmailDownload as g, receive as h, WEBHOOK_EVENT_HEADER as i, SignResult as j, PRIMITIVE_CONFIRMED_HEADER as k, getEventHeader as l, parseWebhookEvent as m, HandleWebhookOptions as n, confirmedHeaders as o, isRawIncluded as p, ReceiveRequestOptions as r, decodeRawEmail as s, DecodeRawEmailOptions as t, handleWebhook as u, validateEmailAuth as v, StandardWebhooksVerifyOptions as w, STANDARD_WEBHOOK_SIGNATURE_HEADER as x, emailReceivedEventJsonSchema as y, verifyDownloadToken as z };
|