@primitivedotdev/sdk 0.8.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/dist/{address-parser-CfPHs3mE.js → address-parser-BYn8oW5r.js} +1 -3
- package/dist/api/index.d.ts +1 -3
- package/dist/{api-BH8PnmHs.js → api-COSr-Fqm.js} +56 -83
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/contract/index.d.ts +6 -9
- package/dist/contract/index.js +28 -17
- package/dist/{index-CuuP1JkG.d.ts → index-CbEivn3S.d.ts} +7 -31
- package/dist/{index-D9lanVFt.d.ts → index-DVow4Fjd.d.ts} +49 -54
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -8
- package/dist/oclif/api-command.js +89 -1
- package/dist/openapi/index.d.ts +8 -3
- package/dist/openapi/openapi.generated.js +1 -2
- package/dist/openapi/operations.generated.js +239 -0
- package/dist/parser/index.d.ts +4 -19
- package/dist/parser/index.js +7 -18
- package/dist/{received-email-Q6Cha3wc.js → received-email-D6tKtWwW.js} +2 -4
- package/dist/{received-email-C67Z7Dha.d.ts → received-email-DNjpq_Wt.d.ts} +4 -3
- package/dist/{types-CIOzt1FY.d.ts → types-9vXGZjPd.d.ts} +3 -19
- package/dist/webhook/index.d.ts +3 -3
- package/dist/webhook/index.js +3 -5
- package/dist/{webhook-2TALcBQz.js → webhook-zkN4wUTs.js} +107 -84
- package/oclif.manifest.json +9 -9
- package/package.json +2 -2
- package/dist/chunk-Cl8Af3a2.js +0 -11
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import addressparser from "nodemailer/lib/addressparser/index.js";
|
|
2
2
|
import isEmail from "validator/lib/isEmail.js";
|
|
3
|
-
|
|
4
3
|
//#region src/parser/address-parser.ts
|
|
5
4
|
const MAX_HEADER_LENGTH = 998;
|
|
6
5
|
const IS_EMAIL_OPTIONS = {
|
|
@@ -108,6 +107,5 @@ function parseFromHeaderLoose(header) {
|
|
|
108
107
|
}
|
|
109
108
|
return null;
|
|
110
109
|
}
|
|
111
|
-
|
|
112
110
|
//#endregion
|
|
113
|
-
export {
|
|
111
|
+
export { parseFromHeaderLoose as n, parseFromHeader as t };
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../received-email-C67Z7Dha.js";
|
|
3
|
-
import { Account, AccountUpdated, AddDomainData, AddDomainError, AddDomainErrors, AddDomainInput, AddDomainResponse, AddDomainResponses, Auth, Client, ClientOptions, ClientOptions$1, Config, CreateClientConfig, CreateEndpointData, CreateEndpointError, CreateEndpointErrors, CreateEndpointInput, CreateEndpointResponse, CreateEndpointResponses, CreateFilterData, CreateFilterError, CreateFilterErrors, CreateFilterInput, CreateFilterResponse, CreateFilterResponses, Cursor, DEFAULT_BASE_URL$1 as DEFAULT_BASE_URL, DeleteDomainData, DeleteDomainError, DeleteDomainErrors, DeleteDomainResponse, DeleteDomainResponses, DeleteEmailData, DeleteEmailError, DeleteEmailErrors, DeleteEmailResponse, DeleteEmailResponses, DeleteEndpointData, DeleteEndpointError, DeleteEndpointErrors, DeleteEndpointResponse, DeleteEndpointResponses, DeleteFilterData, DeleteFilterError, DeleteFilterErrors, DeleteFilterResponse, DeleteFilterResponses, DeliveryStatus, DeliverySummary, Domain, DomainVerifyResult, DownloadAttachmentsData, DownloadAttachmentsError, DownloadAttachmentsErrors, DownloadAttachmentsResponse, DownloadAttachmentsResponses, DownloadRawEmailData, DownloadRawEmailError, DownloadRawEmailErrors, DownloadRawEmailResponse, DownloadRawEmailResponses, EmailDetail, EmailSummary, Endpoint, ErrorResponse, Filter, ForwardInput, GateDenial, GateFix, GetAccountData, GetAccountError, GetAccountErrors, GetAccountResponse, GetAccountResponses, GetEmailData, GetEmailError, GetEmailErrors, GetEmailResponse, GetEmailResponses, GetStorageStatsData, GetStorageStatsError, GetStorageStatsErrors, GetStorageStatsResponse, GetStorageStatsResponses, GetWebhookSecretData, GetWebhookSecretError, GetWebhookSecretErrors, GetWebhookSecretResponse, GetWebhookSecretResponses, Limit, ListDeliveriesData, ListDeliveriesError, ListDeliveriesErrors, ListDeliveriesResponse, ListDeliveriesResponses, ListDomainsData, ListDomainsError, ListDomainsErrors, ListDomainsResponse, ListDomainsResponses, ListEmailsData, ListEmailsError, ListEmailsErrors, ListEmailsResponse, ListEmailsResponses, ListEndpointsData, ListEndpointsError, ListEndpointsErrors, ListEndpointsResponse, ListEndpointsResponses, ListEnvelope, ListFiltersData, ListFiltersError, ListFiltersErrors, ListFiltersResponse, ListFiltersResponses, Options, Options$1, PaginationMeta, PrimitiveApiClient$1 as PrimitiveApiClient, PrimitiveApiClientOptions, PrimitiveApiError$1 as PrimitiveApiError, PrimitiveApiErrorDetails, PrimitiveClient$1 as PrimitiveClient, PrimitiveClientOptions, ReplayDeliveryData, ReplayDeliveryError, ReplayDeliveryErrors, ReplayDeliveryResponse, ReplayDeliveryResponses, ReplayEmailWebhooksData, ReplayEmailWebhooksError, ReplayEmailWebhooksErrors, ReplayEmailWebhooksResponse, ReplayEmailWebhooksResponses, ReplayResult, ReplyInput, RequestOptions, RequestResult, ResourceId, ResponseStyle, RotateWebhookSecretData, RotateWebhookSecretError, RotateWebhookSecretErrors, RotateWebhookSecretResponse, RotateWebhookSecretResponses, SendEmailData, SendEmailError, SendEmailErrors, SendEmailResponse, SendEmailResponses, SendInput, SendMailInput, SendMailResult, SendResult, SendThreadInput, SentEmailStatus, StorageStats, SuccessEnvelope, TestEndpointData, TestEndpointError, TestEndpointErrors, TestEndpointResponse, TestEndpointResponses, TestResult, UnverifiedDomain, UpdateAccountData, UpdateAccountError, UpdateAccountErrors, UpdateAccountInput, UpdateAccountResponse, UpdateAccountResponses, UpdateDomainData, UpdateDomainError, UpdateDomainErrors, UpdateDomainInput, UpdateDomainResponse, UpdateDomainResponses, UpdateEndpointData, UpdateEndpointError, UpdateEndpointErrors, UpdateEndpointInput, UpdateEndpointResponse, UpdateEndpointResponses, UpdateFilterData, UpdateFilterError, UpdateFilterErrors, UpdateFilterInput, UpdateFilterResponse, UpdateFilterResponses, VerifiedDomain, VerifyDomainData, VerifyDomainError, VerifyDomainErrors, VerifyDomainResponse, VerifyDomainResponses, WebhookSecret, addDomain$1 as addDomain, client$1 as client, createEndpoint$1 as createEndpoint, createFilter$1 as createFilter, createPrimitiveApiClient$1 as createPrimitiveApiClient, createPrimitiveClient$1 as createPrimitiveClient, deleteDomain$1 as deleteDomain, deleteEmail$1 as deleteEmail, deleteEndpoint$1 as deleteEndpoint, deleteFilter$1 as deleteFilter, downloadAttachments$1 as downloadAttachments, downloadRawEmail$1 as downloadRawEmail, getAccount$1 as getAccount, getEmail$1 as getEmail, getStorageStats$1 as getStorageStats, getWebhookSecret$1 as getWebhookSecret, listDeliveries$1 as listDeliveries, listDomains$1 as listDomains, listEmails$1 as listEmails, listEndpoints$1 as listEndpoints, listFilters$1 as listFilters, operations$1 as operations, replayDelivery$1 as replayDelivery, replayEmailWebhooks$1 as replayEmailWebhooks, rotateWebhookSecret$1 as rotateWebhookSecret, sendEmail$1 as sendEmail, testEndpoint$1 as testEndpoint, updateAccount$1 as updateAccount, updateDomain$1 as updateDomain, updateEndpoint$1 as updateEndpoint, updateFilter$1 as updateFilter, verifyDomain$1 as verifyDomain } from "../index-D9lanVFt.js";
|
|
1
|
+
import { $ as AddDomainResponses, $n as ReplayDeliveryResponses, $r as VerifiedDomain, $t as GateDenial, A as getWebhookSecret, An as ListDomainsResponse, Ar as UpdateAccountError, At as DeleteFilterError, B as testEndpoint, Bn as ListEndpointsResponse, Br as UpdateDomainResponses, Bt as DownloadAttachmentsErrors, C as deleteEndpoint, Cn as ListDeliveriesError, Cr as TestEndpointError, Ct as DeleteEmailResponses, D as getAccount, Dn as ListDomainsData, Dr as TestResult, Dt as DeleteEndpointResponse, E as downloadRawEmail, En as ListDeliveriesResponses, Er as TestEndpointResponses, Et as DeleteEndpointErrors, F as listFilters, Fn as ListEmailsResponse, Fr as UpdateDomainData, Ft as DeliverySummary, G as verifyDomain, Gn as ListFiltersErrors, Gr as UpdateEndpointResponse, Gt as DownloadRawEmailErrors, H as updateDomain, Hn as ListEnvelope, Hr as UpdateEndpointError, Ht as DownloadAttachmentsResponses, I as replayDelivery, In as ListEmailsResponses, Ir as UpdateDomainError, It as Domain, J as AddDomainData, Jn as PaginationMeta, Jr as UpdateFilterError, Jt as EmailDetail, K as Account, Kn as ListFiltersResponse, Kr as UpdateEndpointResponses, Kt as DownloadRawEmailResponse, L as replayEmailWebhooks, Ln as ListEndpointsData, Lr as UpdateDomainErrors, Lt as DomainVerifyResult, M as listDomains, Mn as ListEmailsData, Mr as UpdateAccountInput, Mt as DeleteFilterResponse, N as listEmails, Nn as ListEmailsError, Nr as UpdateAccountResponse, Nt as DeleteFilterResponses, O as getEmail, On as ListDomainsError, Or as UnverifiedDomain, Ot as DeleteEndpointResponses, P as listEndpoints, Pn as ListEmailsErrors, Pr as UpdateAccountResponses, Pt as DeliveryStatus, Q as AddDomainResponse, Qn as ReplayDeliveryResponse, Qr as UpdateFilterResponses, Qt as Filter, R as rotateWebhookSecret, Rn as ListEndpointsError, Rr as UpdateDomainInput, Rt as DownloadAttachmentsData, S as deleteEmail, Sn as ListDeliveriesData, Sr as TestEndpointData, St as DeleteEmailResponse, T as downloadAttachments, Tn as ListDeliveriesResponse, Tr as TestEndpointResponse, Tt as DeleteEndpointError, U as updateEndpoint, Un as ListFiltersData, Ur as UpdateEndpointErrors, Ut as DownloadRawEmailData, V as updateAccount, Vn as ListEndpointsResponses, Vr as UpdateEndpointData, Vt as DownloadAttachmentsResponse, W as updateFilter, Wn as ListFiltersError, Wr as UpdateEndpointInput, Wt as DownloadRawEmailError, X as AddDomainErrors, Xn as ReplayDeliveryError, Xr as UpdateFilterInput, Xt as Endpoint, Y as AddDomainError, Yn as ReplayDeliveryData, Yr as UpdateFilterErrors, Yt as EmailSummary, Z as AddDomainInput, Zn as ReplayDeliveryErrors, Zr as UpdateFilterResponse, Zt as ErrorResponse, _ as Options, _n as GetWebhookSecretError, _r as SendMailInput, _t as DeleteDomainResponse, a as PrimitiveApiError, ai as WebhookSecret, an as GetAccountResponses, ar as ReplayResult, at as CreateEndpointResponse, b as createFilter, bn as GetWebhookSecretResponses, br as StorageStats, bt as DeleteEmailError, c as PrimitiveClientOptions, ci as Config, cn as GetEmailErrors, cr as RotateWebhookSecretError, ct as CreateFilterError, d as SendResult, di as RequestOptions, dn as GetStorageStatsData, dr as RotateWebhookSecretResponses, dt as CreateFilterResponse, ei as VerifyDomainData, en as GateFix, er as ReplayEmailWebhooksData, et as ClientOptions, f as SendThreadInput, fi as RequestResult, fn as GetStorageStatsError, fr as SendEmailData, ft as CreateFilterResponses, g as operations, gn as GetWebhookSecretData, gr as SendEmailResponses, gt as DeleteDomainErrors, h as createPrimitiveClient, hn as GetStorageStatsResponses, hr as SendEmailResponse, ht as DeleteDomainError, i as PrimitiveApiClientOptions, ii as VerifyDomainResponses, in as GetAccountResponse, ir as ReplayEmailWebhooksResponses, it as CreateEndpointInput, j as listDeliveries, jn as ListDomainsResponses, jr as UpdateAccountErrors, jt as DeleteFilterErrors, k as getStorageStats, kn as ListDomainsErrors, kr as UpdateAccountData, kt as DeleteFilterData, l as ReplyInput, li as CreateClientConfig, ln as GetEmailResponse, lr as RotateWebhookSecretErrors, lt as CreateFilterErrors, m as createPrimitiveApiClient, mi as Auth, mn as GetStorageStatsResponse, mr as SendEmailErrors, mt as DeleteDomainData, n as ForwardInput, ni as VerifyDomainErrors, nn as GetAccountError, nr as ReplayEmailWebhooksErrors, nt as CreateEndpointError, o as PrimitiveApiErrorDetails, oi as Client, on as GetEmailData, or as ResourceId, ot as CreateEndpointResponses, p as client, pi as ResponseStyle, pn as GetStorageStatsErrors, pr as SendEmailError, pt as Cursor, q as AccountUpdated, qn as ListFiltersResponses, qr as UpdateFilterData, qt as DownloadRawEmailResponses, r as PrimitiveApiClient, ri as VerifyDomainResponse, rn as GetAccountErrors, rr as ReplayEmailWebhooksResponse, rt as CreateEndpointErrors, s as PrimitiveClient, si as ClientOptions$1, sn as GetEmailError, sr as RotateWebhookSecretData, st as CreateFilterData, t as DEFAULT_BASE_URL, ti as VerifyDomainError, tn as GetAccountData, tr as ReplayEmailWebhooksError, tt as CreateEndpointData, u as SendInput, ui as Options$1, un as GetEmailResponses, ur as RotateWebhookSecretResponse, ut as CreateFilterInput, v as addDomain, vn as GetWebhookSecretErrors, vr as SendMailResult, vt as DeleteDomainResponses, w as deleteFilter, wn as ListDeliveriesErrors, wr as TestEndpointErrors, wt as DeleteEndpointData, x as deleteDomain, xn as Limit, xr as SuccessEnvelope, xt as DeleteEmailErrors, y as createEndpoint, yn as GetWebhookSecretResponse, yr as SentEmailStatus, yt as DeleteEmailData, z as sendEmail, zn as ListEndpointsErrors, zr as UpdateDomainResponse, zt as DownloadAttachmentsError } from "../index-DVow4Fjd.js";
|
|
4
2
|
export { Account, AccountUpdated, AddDomainData, AddDomainError, AddDomainErrors, AddDomainInput, AddDomainResponse, AddDomainResponses, Auth, ClientOptions, CreateClientConfig, CreateEndpointData, CreateEndpointError, CreateEndpointErrors, CreateEndpointInput, CreateEndpointResponse, CreateEndpointResponses, CreateFilterData, CreateFilterError, CreateFilterErrors, CreateFilterInput, CreateFilterResponse, CreateFilterResponses, Cursor, DEFAULT_BASE_URL, DeleteDomainData, DeleteDomainError, DeleteDomainErrors, DeleteDomainResponse, DeleteDomainResponses, DeleteEmailData, DeleteEmailError, DeleteEmailErrors, DeleteEmailResponse, DeleteEmailResponses, DeleteEndpointData, DeleteEndpointError, DeleteEndpointErrors, DeleteEndpointResponse, DeleteEndpointResponses, DeleteFilterData, DeleteFilterError, DeleteFilterErrors, DeleteFilterResponse, DeleteFilterResponses, DeliveryStatus, DeliverySummary, Domain, DomainVerifyResult, DownloadAttachmentsData, DownloadAttachmentsError, DownloadAttachmentsErrors, DownloadAttachmentsResponse, DownloadAttachmentsResponses, DownloadRawEmailData, DownloadRawEmailError, DownloadRawEmailErrors, DownloadRawEmailResponse, DownloadRawEmailResponses, EmailDetail, EmailSummary, Endpoint, ErrorResponse, Filter, ForwardInput, GateDenial, GateFix, GetAccountData, GetAccountError, GetAccountErrors, GetAccountResponse, GetAccountResponses, GetEmailData, GetEmailError, GetEmailErrors, GetEmailResponse, GetEmailResponses, GetStorageStatsData, GetStorageStatsError, GetStorageStatsErrors, GetStorageStatsResponse, GetStorageStatsResponses, GetWebhookSecretData, GetWebhookSecretError, GetWebhookSecretErrors, GetWebhookSecretResponse, GetWebhookSecretResponses, Limit, ListDeliveriesData, ListDeliveriesError, ListDeliveriesErrors, ListDeliveriesResponse, ListDeliveriesResponses, ListDomainsData, ListDomainsError, ListDomainsErrors, ListDomainsResponse, ListDomainsResponses, ListEmailsData, ListEmailsError, ListEmailsErrors, ListEmailsResponse, ListEmailsResponses, ListEndpointsData, ListEndpointsError, ListEndpointsErrors, ListEndpointsResponse, ListEndpointsResponses, ListEnvelope, ListFiltersData, ListFiltersError, ListFiltersErrors, ListFiltersResponse, ListFiltersResponses, Options, PaginationMeta, PrimitiveApiClient, PrimitiveApiClientOptions, PrimitiveApiError, PrimitiveApiErrorDetails, PrimitiveClient, PrimitiveClientOptions, Client as PrimitiveGeneratedApiClient, ClientOptions$1 as PrimitiveGeneratedApiClientOptions, Config as PrimitiveGeneratedApiConfig, Options$1 as PrimitiveGeneratedApiOptions, RequestOptions as PrimitiveGeneratedApiRequestOptions, RequestResult as PrimitiveGeneratedApiRequestResult, ReplayDeliveryData, ReplayDeliveryError, ReplayDeliveryErrors, ReplayDeliveryResponse, ReplayDeliveryResponses, ReplayEmailWebhooksData, ReplayEmailWebhooksError, ReplayEmailWebhooksErrors, ReplayEmailWebhooksResponse, ReplayEmailWebhooksResponses, ReplayResult, ReplyInput, ResourceId, ResponseStyle, RotateWebhookSecretData, RotateWebhookSecretError, RotateWebhookSecretErrors, RotateWebhookSecretResponse, RotateWebhookSecretResponses, SendEmailData, SendEmailError, SendEmailErrors, SendEmailResponse, SendEmailResponses, SendInput, SendMailInput, SendMailResult, SendResult, SendThreadInput, SentEmailStatus, StorageStats, SuccessEnvelope, TestEndpointData, TestEndpointError, TestEndpointErrors, TestEndpointResponse, TestEndpointResponses, TestResult, UnverifiedDomain, UpdateAccountData, UpdateAccountError, UpdateAccountErrors, UpdateAccountInput, UpdateAccountResponse, UpdateAccountResponses, UpdateDomainData, UpdateDomainError, UpdateDomainErrors, UpdateDomainInput, UpdateDomainResponse, UpdateDomainResponses, UpdateEndpointData, UpdateEndpointError, UpdateEndpointErrors, UpdateEndpointInput, UpdateEndpointResponse, UpdateEndpointResponses, UpdateFilterData, UpdateFilterError, UpdateFilterErrors, UpdateFilterInput, UpdateFilterResponse, UpdateFilterResponses, VerifiedDomain, VerifyDomainData, VerifyDomainError, VerifyDomainErrors, VerifyDomainResponse, VerifyDomainResponses, WebhookSecret, addDomain, client, createEndpoint, createFilter, createPrimitiveApiClient, createPrimitiveClient, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, downloadAttachments, downloadRawEmail, getAccount, getEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, operations, replayDelivery, replayEmailWebhooks, rotateWebhookSecret, sendEmail, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatAddress } from "./received-email-
|
|
3
|
-
|
|
1
|
+
import { t as __exportAll } from "./chunk-pbuEa-1d.js";
|
|
2
|
+
import { r as formatAddress } from "./received-email-D6tKtWwW.js";
|
|
4
3
|
//#region src/api/generated/core/bodySerializer.gen.ts
|
|
5
4
|
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
6
|
-
|
|
7
5
|
//#endregion
|
|
8
6
|
//#region src/api/generated/core/serverSentEvents.gen.ts
|
|
9
|
-
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url
|
|
7
|
+
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
10
8
|
let lastEventId;
|
|
11
9
|
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
12
10
|
const createStream = async function* () {
|
|
@@ -28,8 +26,7 @@ function createSseClient({ onRequest, onSseError, onSseEvent, responseTransforme
|
|
|
28
26
|
};
|
|
29
27
|
let request = new Request(url, requestInit);
|
|
30
28
|
if (onRequest) request = await onRequest(url, requestInit);
|
|
31
|
-
const
|
|
32
|
-
const response = await _fetch(request);
|
|
29
|
+
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
33
30
|
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
34
31
|
if (!response.body) throw new Error("No body in SSE response");
|
|
35
32
|
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
@@ -91,15 +88,12 @@ function createSseClient({ onRequest, onSseError, onSseEvent, responseTransforme
|
|
|
91
88
|
} catch (error) {
|
|
92
89
|
onSseError?.(error);
|
|
93
90
|
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
94
|
-
|
|
95
|
-
await sleep(backoff);
|
|
91
|
+
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
};
|
|
99
|
-
|
|
100
|
-
return { stream };
|
|
95
|
+
return { stream: createStream() };
|
|
101
96
|
}
|
|
102
|
-
|
|
103
97
|
//#endregion
|
|
104
98
|
//#region src/api/generated/core/pathSerializer.gen.ts
|
|
105
99
|
const separatorArrayExplode = (style) => {
|
|
@@ -128,12 +122,12 @@ const separatorObjectExplode = (style) => {
|
|
|
128
122
|
};
|
|
129
123
|
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
130
124
|
if (!explode) {
|
|
131
|
-
const joinedValues
|
|
125
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
132
126
|
switch (style) {
|
|
133
|
-
case "label": return `.${joinedValues
|
|
134
|
-
case "matrix": return `;${name}=${joinedValues
|
|
135
|
-
case "simple": return joinedValues
|
|
136
|
-
default: return `${name}=${joinedValues
|
|
127
|
+
case "label": return `.${joinedValues}`;
|
|
128
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
129
|
+
case "simple": return joinedValues;
|
|
130
|
+
default: return `${name}=${joinedValues}`;
|
|
137
131
|
}
|
|
138
132
|
}
|
|
139
133
|
const separator = separatorArrayExplode(style);
|
|
@@ -163,12 +157,12 @@ const serializeObjectParam = ({ allowReserved, explode, name, style, value, valu
|
|
|
163
157
|
allowReserved ? v : encodeURIComponent(v)
|
|
164
158
|
];
|
|
165
159
|
});
|
|
166
|
-
const joinedValues
|
|
160
|
+
const joinedValues = values.join(",");
|
|
167
161
|
switch (style) {
|
|
168
|
-
case "form": return `${name}=${joinedValues
|
|
169
|
-
case "label": return `.${joinedValues
|
|
170
|
-
case "matrix": return `;${name}=${joinedValues
|
|
171
|
-
default: return joinedValues
|
|
162
|
+
case "form": return `${name}=${joinedValues}`;
|
|
163
|
+
case "label": return `.${joinedValues}`;
|
|
164
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
165
|
+
default: return joinedValues;
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
168
|
const separator = separatorObjectExplode(style);
|
|
@@ -179,7 +173,6 @@ const serializeObjectParam = ({ allowReserved, explode, name, style, value, valu
|
|
|
179
173
|
})).join(separator);
|
|
180
174
|
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
181
175
|
};
|
|
182
|
-
|
|
183
176
|
//#endregion
|
|
184
177
|
//#region src/api/generated/core/utils.gen.ts
|
|
185
178
|
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
@@ -248,18 +241,12 @@ const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
|
248
241
|
};
|
|
249
242
|
function getValidRequestBody(options) {
|
|
250
243
|
const hasBody = options.body !== void 0;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if ("serializedBody" in options) {
|
|
254
|
-
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
255
|
-
return hasSerializedBody ? options.serializedBody : null;
|
|
256
|
-
}
|
|
244
|
+
if (hasBody && options.bodySerializer) {
|
|
245
|
+
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
257
246
|
return options.body !== "" ? options.body : null;
|
|
258
247
|
}
|
|
259
248
|
if (hasBody) return options.body;
|
|
260
|
-
return void 0;
|
|
261
249
|
}
|
|
262
|
-
|
|
263
250
|
//#endregion
|
|
264
251
|
//#region src/api/generated/core/auth.gen.ts
|
|
265
252
|
const getAuthToken = async (auth, callback) => {
|
|
@@ -269,10 +256,9 @@ const getAuthToken = async (auth, callback) => {
|
|
|
269
256
|
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
270
257
|
return token;
|
|
271
258
|
};
|
|
272
|
-
|
|
273
259
|
//#endregion
|
|
274
260
|
//#region src/api/generated/client/utils.gen.ts
|
|
275
|
-
const createQuerySerializer = ({ parameters = {}
|
|
261
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
276
262
|
const querySerializer = (queryParams) => {
|
|
277
263
|
const search = [];
|
|
278
264
|
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
@@ -328,14 +314,13 @@ const getParseAs = (contentType) => {
|
|
|
328
314
|
"video/"
|
|
329
315
|
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
330
316
|
if (cleanContent.startsWith("text/")) return "text";
|
|
331
|
-
return;
|
|
332
317
|
};
|
|
333
318
|
const checkForExistence = (options, name) => {
|
|
334
319
|
if (!name) return false;
|
|
335
320
|
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
336
321
|
return false;
|
|
337
322
|
};
|
|
338
|
-
const setAuthParams = async ({ security
|
|
323
|
+
const setAuthParams = async ({ security, ...options }) => {
|
|
339
324
|
for (const auth of security) {
|
|
340
325
|
if (checkForExistence(options, auth.name)) continue;
|
|
341
326
|
const token = await getAuthToken(auth, options.auth);
|
|
@@ -349,7 +334,6 @@ const setAuthParams = async ({ security,...options }) => {
|
|
|
349
334
|
case "cookie":
|
|
350
335
|
options.headers.append("Cookie", `${name}=${token}`);
|
|
351
336
|
break;
|
|
352
|
-
case "header":
|
|
353
337
|
default:
|
|
354
338
|
options.headers.set(name, token);
|
|
355
339
|
break;
|
|
@@ -444,14 +428,13 @@ const createConfig = (override = {}) => ({
|
|
|
444
428
|
querySerializer: defaultQuerySerializer,
|
|
445
429
|
...override
|
|
446
430
|
});
|
|
447
|
-
|
|
448
431
|
//#endregion
|
|
449
432
|
//#region src/api/generated/client/client.gen.ts
|
|
450
433
|
const createClient = (config = {}) => {
|
|
451
434
|
let _config = mergeConfigs(createConfig(), config);
|
|
452
435
|
const getConfig = () => ({ ..._config });
|
|
453
|
-
const setConfig = (config
|
|
454
|
-
_config = mergeConfigs(_config, config
|
|
436
|
+
const setConfig = (config) => {
|
|
437
|
+
_config = mergeConfigs(_config, config);
|
|
455
438
|
return getConfig();
|
|
456
439
|
};
|
|
457
440
|
const interceptors = createInterceptors();
|
|
@@ -471,10 +454,9 @@ const createClient = (config = {}) => {
|
|
|
471
454
|
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
472
455
|
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
473
456
|
const resolvedOpts = opts;
|
|
474
|
-
const url = buildUrl(resolvedOpts);
|
|
475
457
|
return {
|
|
476
458
|
opts: resolvedOpts,
|
|
477
|
-
url
|
|
459
|
+
url: buildUrl(resolvedOpts)
|
|
478
460
|
};
|
|
479
461
|
};
|
|
480
462
|
const request = async (options) => {
|
|
@@ -484,26 +466,26 @@ const createClient = (config = {}) => {
|
|
|
484
466
|
...opts,
|
|
485
467
|
body: getValidRequestBody(opts)
|
|
486
468
|
};
|
|
487
|
-
let request
|
|
488
|
-
for (const fn of interceptors.request.fns) if (fn) request
|
|
469
|
+
let request = new Request(url, requestInit);
|
|
470
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
489
471
|
const _fetch = opts.fetch;
|
|
490
472
|
let response;
|
|
491
473
|
try {
|
|
492
|
-
response = await _fetch(request
|
|
493
|
-
} catch (error
|
|
494
|
-
let finalError
|
|
495
|
-
for (const fn of interceptors.error.fns) if (fn) finalError
|
|
496
|
-
finalError
|
|
497
|
-
if (opts.throwOnError) throw finalError
|
|
474
|
+
response = await _fetch(request);
|
|
475
|
+
} catch (error) {
|
|
476
|
+
let finalError = error;
|
|
477
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, void 0, request, opts);
|
|
478
|
+
finalError = finalError || {};
|
|
479
|
+
if (opts.throwOnError) throw finalError;
|
|
498
480
|
return opts.responseStyle === "data" ? void 0 : {
|
|
499
|
-
error: finalError
|
|
500
|
-
request
|
|
481
|
+
error: finalError,
|
|
482
|
+
request,
|
|
501
483
|
response: void 0
|
|
502
484
|
};
|
|
503
485
|
}
|
|
504
|
-
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request
|
|
486
|
+
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
505
487
|
const result = {
|
|
506
|
-
request
|
|
488
|
+
request,
|
|
507
489
|
response
|
|
508
490
|
};
|
|
509
491
|
if (response.ok) {
|
|
@@ -522,7 +504,6 @@ const createClient = (config = {}) => {
|
|
|
522
504
|
case "stream":
|
|
523
505
|
emptyData = response.body;
|
|
524
506
|
break;
|
|
525
|
-
case "json":
|
|
526
507
|
default:
|
|
527
508
|
emptyData = {};
|
|
528
509
|
break;
|
|
@@ -566,7 +547,7 @@ const createClient = (config = {}) => {
|
|
|
566
547
|
} catch {}
|
|
567
548
|
const error = jsonError ?? textError;
|
|
568
549
|
let finalError = error;
|
|
569
|
-
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, response, request
|
|
550
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, response, request, opts);
|
|
570
551
|
finalError = finalError || {};
|
|
571
552
|
if (opts.throwOnError) throw finalError;
|
|
572
553
|
return opts.responseStyle === "data" ? void 0 : {
|
|
@@ -585,10 +566,10 @@ const createClient = (config = {}) => {
|
|
|
585
566
|
body: opts.body,
|
|
586
567
|
headers: opts.headers,
|
|
587
568
|
method,
|
|
588
|
-
onRequest: async (url
|
|
589
|
-
let request
|
|
590
|
-
for (const fn of interceptors.request.fns) if (fn) request
|
|
591
|
-
return request
|
|
569
|
+
onRequest: async (url, init) => {
|
|
570
|
+
let request = new Request(url, init);
|
|
571
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
572
|
+
return request;
|
|
592
573
|
},
|
|
593
574
|
serializedBody: getValidRequestBody(opts),
|
|
594
575
|
url
|
|
@@ -626,15 +607,12 @@ const createClient = (config = {}) => {
|
|
|
626
607
|
trace: makeMethodFn("TRACE")
|
|
627
608
|
};
|
|
628
609
|
};
|
|
629
|
-
|
|
630
610
|
//#endregion
|
|
631
611
|
//#region src/api/generated/client.gen.ts
|
|
632
612
|
const client$1 = createClient(createConfig({ baseUrl: "https://www.primitive.dev/api/v1" }));
|
|
633
|
-
|
|
634
613
|
//#endregion
|
|
635
614
|
//#region src/api/generated/sdk.gen.ts
|
|
636
|
-
var sdk_gen_exports = {
|
|
637
|
-
__export(sdk_gen_exports, {
|
|
615
|
+
var sdk_gen_exports = /* @__PURE__ */ __exportAll({
|
|
638
616
|
addDomain: () => addDomain,
|
|
639
617
|
createEndpoint: () => createEndpoint,
|
|
640
618
|
createFilter: () => createFilter,
|
|
@@ -1110,7 +1088,6 @@ const sendEmail = (options) => (options.client ?? client$1).post({
|
|
|
1110
1088
|
...options.headers
|
|
1111
1089
|
}
|
|
1112
1090
|
});
|
|
1113
|
-
|
|
1114
1091
|
//#endregion
|
|
1115
1092
|
//#region src/api/index.ts
|
|
1116
1093
|
const DEFAULT_BASE_URL = "https://www.primitive.dev/api/v1";
|
|
@@ -1122,7 +1099,6 @@ const MAX_TO_HEADER_LENGTH = 320;
|
|
|
1122
1099
|
function createDefaultAuth(apiKey) {
|
|
1123
1100
|
return (security) => {
|
|
1124
1101
|
if (security.type === "http" && security.scheme === "bearer") return apiKey;
|
|
1125
|
-
return void 0;
|
|
1126
1102
|
};
|
|
1127
1103
|
}
|
|
1128
1104
|
function validateAddressHeader(field, value) {
|
|
@@ -1218,7 +1194,7 @@ function parseRetryAfterHeader(response) {
|
|
|
1218
1194
|
var PrimitiveApiClient = class {
|
|
1219
1195
|
client;
|
|
1220
1196
|
constructor(options = {}) {
|
|
1221
|
-
const { apiKey, auth, baseUrl = DEFAULT_BASE_URL
|
|
1197
|
+
const { apiKey, auth, baseUrl = DEFAULT_BASE_URL, ...config } = options;
|
|
1222
1198
|
this.client = createClient(createConfig({
|
|
1223
1199
|
...config,
|
|
1224
1200
|
auth: auth ?? createDefaultAuth(apiKey),
|
|
@@ -1235,19 +1211,18 @@ var PrimitiveApiClient = class {
|
|
|
1235
1211
|
var PrimitiveClient = class extends PrimitiveApiClient {
|
|
1236
1212
|
async send(input) {
|
|
1237
1213
|
validateSendInput(input);
|
|
1238
|
-
const body = {
|
|
1239
|
-
from: input.from,
|
|
1240
|
-
to: input.to,
|
|
1241
|
-
subject: input.subject,
|
|
1242
|
-
...input.bodyText !== void 0 ? { body_text: input.bodyText } : {},
|
|
1243
|
-
...input.bodyHtml !== void 0 ? { body_html: input.bodyHtml } : {},
|
|
1244
|
-
...input.thread?.inReplyTo ? { in_reply_to: input.thread.inReplyTo } : {},
|
|
1245
|
-
...input.thread?.references?.length ? { references: input.thread.references } : {},
|
|
1246
|
-
...input.wait !== void 0 ? { wait: input.wait } : {},
|
|
1247
|
-
...input.waitTimeoutMs !== void 0 ? { wait_timeout_ms: input.waitTimeoutMs } : {}
|
|
1248
|
-
};
|
|
1249
1214
|
const result = await sendEmail({
|
|
1250
|
-
body
|
|
1215
|
+
body: {
|
|
1216
|
+
from: input.from,
|
|
1217
|
+
to: input.to,
|
|
1218
|
+
subject: input.subject,
|
|
1219
|
+
...input.bodyText !== void 0 ? { body_text: input.bodyText } : {},
|
|
1220
|
+
...input.bodyHtml !== void 0 ? { body_html: input.bodyHtml } : {},
|
|
1221
|
+
...input.thread?.inReplyTo ? { in_reply_to: input.thread.inReplyTo } : {},
|
|
1222
|
+
...input.thread?.references?.length ? { references: input.thread.references } : {},
|
|
1223
|
+
...input.wait !== void 0 ? { wait: input.wait } : {},
|
|
1224
|
+
...input.waitTimeoutMs !== void 0 ? { wait_timeout_ms: input.waitTimeoutMs } : {}
|
|
1225
|
+
},
|
|
1251
1226
|
...input.idempotencyKey ? { headers: { "Idempotency-Key": input.idempotencyKey } } : {},
|
|
1252
1227
|
client: this.client,
|
|
1253
1228
|
responseStyle: "fields"
|
|
@@ -1295,7 +1270,7 @@ var PrimitiveClient = class extends PrimitiveApiClient {
|
|
|
1295
1270
|
}
|
|
1296
1271
|
};
|
|
1297
1272
|
function buildForwardText(email, intro) {
|
|
1298
|
-
|
|
1273
|
+
return [
|
|
1299
1274
|
...intro ? [intro.trim(), ""] : [],
|
|
1300
1275
|
"---------- Forwarded message ----------",
|
|
1301
1276
|
`From: ${formatAddress(email.sender)}`,
|
|
@@ -1305,8 +1280,7 @@ function buildForwardText(email, intro) {
|
|
|
1305
1280
|
...email.thread.messageId ? [`Message-ID: ${email.thread.messageId}`] : [],
|
|
1306
1281
|
"",
|
|
1307
1282
|
email.text ?? ""
|
|
1308
|
-
];
|
|
1309
|
-
return lines.join("\n").trimEnd();
|
|
1283
|
+
].join("\n").trimEnd();
|
|
1310
1284
|
}
|
|
1311
1285
|
function mapSendResult(result) {
|
|
1312
1286
|
return {
|
|
@@ -1333,6 +1307,5 @@ function client(options = {}) {
|
|
|
1333
1307
|
return new PrimitiveClient(options);
|
|
1334
1308
|
}
|
|
1335
1309
|
const operations = sdk_gen_exports;
|
|
1336
|
-
|
|
1337
1310
|
//#endregion
|
|
1338
|
-
export {
|
|
1311
|
+
export { sendEmail as A, listDomains as C, replayDelivery as D, listFilters as E, updateFilter as F, verifyDomain as I, updateAccount as M, updateDomain as N, replayEmailWebhooks as O, updateEndpoint as P, listDeliveries as S, listEndpoints as T, downloadRawEmail as _, client as a, getStorageStats as b, operations as c, createFilter as d, deleteDomain as f, downloadAttachments as g, deleteFilter as h, PrimitiveClient as i, testEndpoint as j, rotateWebhookSecret as k, addDomain as l, deleteEndpoint as m, PrimitiveApiClient as n, createPrimitiveApiClient as o, deleteEmail as p, PrimitiveApiError as r, createPrimitiveClient as s, DEFAULT_BASE_URL as t, createEndpoint as u, getAccount as v, listEmails as w, getWebhookSecret as x, getEmail as y };
|
|
@@ -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,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
3
|
-
import { SignResult, StandardWebhooksSignResult, WEBHOOK_VERSION$1 as WEBHOOK_VERSION, signStandardWebhooksPayload$1 as signStandardWebhooksPayload, signWebhookPayload$1 as signWebhookPayload } from "../index-CuuP1JkG.js";
|
|
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";
|
|
4
3
|
|
|
5
4
|
//#region src/contract/contract.d.ts
|
|
6
|
-
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
7
|
-
|
|
8
5
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
9
6
|
declare const RAW_EMAIL_INLINE_THRESHOLD = 262144;
|
|
10
7
|
/** Parsed content input when parsing succeeded. */
|
|
@@ -143,8 +140,7 @@ declare function generateEventId(endpoint_id: string, email_id: string): string;
|
|
|
143
140
|
* ```
|
|
144
141
|
*/
|
|
145
142
|
declare function buildEmailReceivedEvent(input: EmailReceivedEventInput, options?: {
|
|
146
|
-
/** Override the attempted-at timestamp, typically for tests. */
|
|
147
|
-
attempted_at?: string;
|
|
143
|
+
/** Override the attempted-at timestamp, typically for tests. */attempted_at?: string;
|
|
148
144
|
}): EmailReceivedEvent;
|
|
149
145
|
/**
|
|
150
146
|
* Input for building an `EmailReceivedEvent` directly from parser output.
|
|
@@ -222,5 +218,6 @@ interface BuildEventFromParsedDataOptions {
|
|
|
222
218
|
* @throws Error if `smtpRcptTo` is empty.
|
|
223
219
|
* @throws WebhookValidationError if the assembled event fails schema validation.
|
|
224
220
|
*/
|
|
225
|
-
declare function buildEventFromParsedData(params: BuildEventFromParsedDataOptions): EmailReceivedEvent;
|
|
226
|
-
|
|
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,9 +1,25 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../received-email-Q6Cha3wc.js";
|
|
3
|
-
import { WEBHOOK_VERSION, signStandardWebhooksPayload, signWebhookPayload, validateEmailReceivedEvent } from "../webhook-2TALcBQz.js";
|
|
1
|
+
import { E as signStandardWebhooksPayload, L as validateEmailReceivedEvent, M as signWebhookPayload, d as WEBHOOK_VERSION } from "../webhook-zkN4wUTs.js";
|
|
4
2
|
import { createHash } from "node:crypto";
|
|
5
|
-
|
|
6
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
|
+
*/
|
|
7
23
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
|
8
24
|
const RAW_EMAIL_INLINE_THRESHOLD = 262144;
|
|
9
25
|
/**
|
|
@@ -42,8 +58,7 @@ function validateTimestamp(timestamp, fieldName) {
|
|
|
42
58
|
*/
|
|
43
59
|
function generateEventId(endpoint_id, email_id) {
|
|
44
60
|
const hashInput = `email.received:${WEBHOOK_VERSION}:${endpoint_id}:${email_id}`;
|
|
45
|
-
|
|
46
|
-
return `evt_${hash}`;
|
|
61
|
+
return `evt_${createHash("sha256").update(hashInput).digest("hex")}`;
|
|
47
62
|
}
|
|
48
63
|
/**
|
|
49
64
|
* Build an `EmailReceivedEvent` from producer-side input.
|
|
@@ -94,13 +109,12 @@ function generateEventId(endpoint_id, email_id) {
|
|
|
94
109
|
*/
|
|
95
110
|
function buildEmailReceivedEvent(input, options) {
|
|
96
111
|
const event_id = generateEventId(input.endpoint_id, input.email_id);
|
|
97
|
-
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();
|
|
98
113
|
const raw_size_bytes = input.raw_bytes.length;
|
|
99
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`);
|
|
100
115
|
const raw_sha256 = createHash("sha256").update(input.raw_bytes).digest("hex");
|
|
101
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`);
|
|
102
|
-
const
|
|
103
|
-
const rawContent = shouldInline ? {
|
|
117
|
+
const rawContent = raw_size_bytes <= 262144 ? {
|
|
104
118
|
included: true,
|
|
105
119
|
encoding: "base64",
|
|
106
120
|
max_inline_bytes: RAW_EMAIL_INLINE_THRESHOLD,
|
|
@@ -158,7 +172,7 @@ function buildEmailReceivedEvent(input, options) {
|
|
|
158
172
|
attachments: [],
|
|
159
173
|
attachments_download_url: null
|
|
160
174
|
};
|
|
161
|
-
|
|
175
|
+
return validateEmailReceivedEvent({
|
|
162
176
|
id: event_id,
|
|
163
177
|
event: "email.received",
|
|
164
178
|
version: WEBHOOK_VERSION,
|
|
@@ -193,8 +207,7 @@ function buildEmailReceivedEvent(input, options) {
|
|
|
193
207
|
analysis: input.analysis,
|
|
194
208
|
auth: input.auth
|
|
195
209
|
}
|
|
196
|
-
};
|
|
197
|
-
return validateEmailReceivedEvent(event);
|
|
210
|
+
});
|
|
198
211
|
}
|
|
199
212
|
/**
|
|
200
213
|
* Build an `EmailReceivedEvent` from parsed email data plus delivery metadata.
|
|
@@ -241,7 +254,7 @@ function buildEventFromParsedData(params) {
|
|
|
241
254
|
references: parsed.references,
|
|
242
255
|
attachments: parsed.attachments
|
|
243
256
|
};
|
|
244
|
-
|
|
257
|
+
return buildEmailReceivedEvent({
|
|
245
258
|
email_id: params.emailId,
|
|
246
259
|
endpoint_id: params.endpointId,
|
|
247
260
|
message_id: params.messageId,
|
|
@@ -263,9 +276,7 @@ function buildEventFromParsedData(params) {
|
|
|
263
276
|
parsed: parsedInput,
|
|
264
277
|
auth: params.auth,
|
|
265
278
|
analysis: params.analysis
|
|
266
|
-
};
|
|
267
|
-
return buildEmailReceivedEvent(input, params.buildOptions);
|
|
279
|
+
}, params.buildOptions);
|
|
268
280
|
}
|
|
269
|
-
|
|
270
281
|
//#endregion
|
|
271
|
-
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,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReceivedEmail } from "./received-email-
|
|
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";
|
|
3
3
|
import { ErrorObject } from "ajv";
|
|
4
4
|
|
|
5
5
|
//#region src/webhook/errors.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Verification error definitions.
|
|
8
|
-
* Use these for documentation, dashboards, and i18n.
|
|
9
|
-
*/
|
|
10
6
|
/**
|
|
11
7
|
* Verification error definitions.
|
|
12
8
|
* Use these for documentation, dashboards, and i18n.
|
|
@@ -211,7 +207,8 @@ declare class RawEmailDecodeError extends PrimitiveWebhookError {
|
|
|
211
207
|
readonly code: RawEmailDecodeErrorCode;
|
|
212
208
|
readonly suggestion: string;
|
|
213
209
|
constructor(code: RawEmailDecodeErrorCode, message?: string);
|
|
214
|
-
}
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
215
212
|
//#region src/validation.d.ts
|
|
216
213
|
interface ValidationSuccess<T> {
|
|
217
214
|
success: true;
|
|
@@ -224,7 +221,6 @@ interface ValidationFailure {
|
|
|
224
221
|
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
225
222
|
declare function validateEmailReceivedEvent(input: unknown): EmailReceivedEvent;
|
|
226
223
|
declare function safeValidateEmailReceivedEvent(input: unknown): ValidationResult<EmailReceivedEvent>;
|
|
227
|
-
|
|
228
224
|
//#endregion
|
|
229
225
|
//#region src/webhook/download-tokens.d.ts
|
|
230
226
|
/**
|
|
@@ -313,7 +309,6 @@ type VerifyDownloadTokenResult = {
|
|
|
313
309
|
* @returns Whether the token is valid, plus a reason on failure.
|
|
314
310
|
*/
|
|
315
311
|
declare function verifyDownloadToken(params: VerifyDownloadTokenOptions): VerifyDownloadTokenResult;
|
|
316
|
-
|
|
317
312
|
//#endregion
|
|
318
313
|
//#region src/webhook/signing.d.ts
|
|
319
314
|
/**
|
|
@@ -406,7 +401,6 @@ declare function signWebhookPayload(rawBody: string | Buffer, secret: string | B
|
|
|
406
401
|
* ```
|
|
407
402
|
*/
|
|
408
403
|
declare function verifyWebhookSignature(opts: VerifyOptions): true;
|
|
409
|
-
|
|
410
404
|
//#endregion
|
|
411
405
|
//#region src/webhook/standard-webhooks.d.ts
|
|
412
406
|
/**
|
|
@@ -458,15 +452,6 @@ interface StandardWebhooksVerifyOptions {
|
|
|
458
452
|
/** Override current time for testing (unix seconds) */
|
|
459
453
|
nowSeconds?: number;
|
|
460
454
|
}
|
|
461
|
-
/**
|
|
462
|
-
* Prepare a Standard Webhooks secret for HMAC computation.
|
|
463
|
-
*
|
|
464
|
-
* Strips the "whsec_" prefix if present, then base64-decodes the remainder
|
|
465
|
-
* to produce the raw HMAC key bytes.
|
|
466
|
-
*
|
|
467
|
-
* @internal
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
455
|
/**
|
|
471
456
|
* Sign a webhook payload using the Standard Webhooks format.
|
|
472
457
|
*
|
|
@@ -482,7 +467,6 @@ declare function signStandardWebhooksPayload(rawBody: string | Buffer, secret: s
|
|
|
482
467
|
* Throws `WebhookVerificationError` on failure with a specific error code.
|
|
483
468
|
*/
|
|
484
469
|
declare function verifyStandardWebhooksSignature(opts: StandardWebhooksVerifyOptions): true;
|
|
485
|
-
|
|
486
470
|
//#endregion
|
|
487
471
|
//#region src/schema.generated.d.ts
|
|
488
472
|
/**
|
|
@@ -1274,7 +1258,8 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
1274
1258
|
readonly description: "DKIM signature verification result for a single signature.";
|
|
1275
1259
|
};
|
|
1276
1260
|
};
|
|
1277
|
-
};
|
|
1261
|
+
};
|
|
1262
|
+
//#endregion
|
|
1278
1263
|
//#region src/webhook/auth.d.ts
|
|
1279
1264
|
/**
|
|
1280
1265
|
* Validate email authentication and compute a verdict.
|
|
@@ -1336,7 +1321,6 @@ declare const emailReceivedEventJsonSchema: {
|
|
|
1336
1321
|
* ```
|
|
1337
1322
|
*/
|
|
1338
1323
|
declare function validateEmailAuth(auth: EmailAuth): ValidateEmailAuthResult;
|
|
1339
|
-
|
|
1340
1324
|
//#endregion
|
|
1341
1325
|
//#region src/webhook/version.d.ts
|
|
1342
1326
|
/**
|
|
@@ -1352,15 +1336,8 @@ declare function validateEmailAuth(auth: EmailAuth): ValidateEmailAuthResult;
|
|
|
1352
1336
|
* need to handle version-specific behavior.
|
|
1353
1337
|
*/
|
|
1354
1338
|
declare const WEBHOOK_VERSION = "2025-12-14";
|
|
1355
|
-
|
|
1356
1339
|
//#endregion
|
|
1357
1340
|
//#region src/webhook/index.d.ts
|
|
1358
|
-
/**
|
|
1359
|
-
* Valid webhook version format (YYYY-MM-DD date string).
|
|
1360
|
-
* The SDK accepts any valid date-formatted version, not just the current one,
|
|
1361
|
-
* for forward and backward compatibility.
|
|
1362
|
-
*/
|
|
1363
|
-
|
|
1364
1341
|
/**
|
|
1365
1342
|
* Parse a webhook payload, returning typed events for known types
|
|
1366
1343
|
* and UnknownEvent for future event types.
|
|
@@ -1646,6 +1623,5 @@ declare function decodeRawEmail(event: EmailReceivedEvent, options?: DecodeRawEm
|
|
|
1646
1623
|
* ```
|
|
1647
1624
|
*/
|
|
1648
1625
|
declare function verifyRawEmailDownload(downloaded: Buffer | ArrayBuffer | Uint8Array, event: EmailReceivedEvent): Buffer;
|
|
1649
|
-
|
|
1650
1626
|
//#endregion
|
|
1651
|
-
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 };
|