@primitivedotdev/sdk 0.24.0 → 0.25.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/api/generated/sdk.gen.js +29 -17
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.js +6 -0
- package/dist/api/verify-signature.js +198 -0
- package/dist/{api-BjzvA2Fy.js → api-CoP5vKPK.js} +170 -19
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/errors-C53fe686.d.ts +245 -0
- package/dist/errors-x91I_yEt.js +287 -0
- package/dist/{index-CDlwyxdp.d.ts → index-Dbx9udpX.d.ts} +2 -210
- package/dist/{index-QTYQpSFt.d.ts → index-DdITDPea.d.ts} +105 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/openapi/openapi.generated.js +21 -1
- package/dist/openapi/operations.generated.js +15 -3
- package/dist/webhook/errors.js +224 -0
- package/dist/webhook/index.d.ts +2 -2
- package/dist/webhook/index.js +2 -2
- package/dist/{webhook-rUjGV6Zu.js → webhook-DJkfUnFZ.js} +2 -220
- package/oclif.manifest.json +23 -2
- package/package.json +1 -1
- package/dist/received-email-D6tKtWwW.js +0 -69
- package/dist/received-email-DNjpq_Wt.d.ts +0 -37
|
@@ -28,7 +28,7 @@ export const pollCliLogin = (options) => (options.client ?? client).post({
|
|
|
28
28
|
url: '/cli/login/poll',
|
|
29
29
|
...options,
|
|
30
30
|
headers: {
|
|
31
|
-
'Content-Type': 'application/json',
|
|
31
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
32
32
|
...options.headers
|
|
33
33
|
}
|
|
34
34
|
});
|
|
@@ -64,7 +64,7 @@ export const updateAccount = (options) => (options.client ?? client).patch({
|
|
|
64
64
|
url: '/account',
|
|
65
65
|
...options,
|
|
66
66
|
headers: {
|
|
67
|
-
'Content-Type': 'application/json',
|
|
67
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
68
68
|
...options.headers
|
|
69
69
|
}
|
|
70
70
|
});
|
|
@@ -143,7 +143,7 @@ export const addDomain = (options) => (options.client ?? client).post({
|
|
|
143
143
|
url: '/domains',
|
|
144
144
|
...options,
|
|
145
145
|
headers: {
|
|
146
|
-
'Content-Type': 'application/json',
|
|
146
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
147
147
|
...options.headers
|
|
148
148
|
}
|
|
149
149
|
});
|
|
@@ -169,7 +169,7 @@ export const updateDomain = (options) => (options.client ?? client).patch({
|
|
|
169
169
|
url: '/domains/{id}',
|
|
170
170
|
...options,
|
|
171
171
|
headers: {
|
|
172
|
-
'Content-Type': 'application/json',
|
|
172
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
173
173
|
...options.headers
|
|
174
174
|
}
|
|
175
175
|
});
|
|
@@ -327,7 +327,7 @@ export const replyToEmail = (options) => (options.client ?? client).post({
|
|
|
327
327
|
url: '/emails/{id}/reply',
|
|
328
328
|
...options,
|
|
329
329
|
headers: {
|
|
330
|
-
'Content-Type': 'application/json',
|
|
330
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
331
331
|
...options.headers
|
|
332
332
|
}
|
|
333
333
|
});
|
|
@@ -405,7 +405,7 @@ export const createEndpoint = (options) => (options.client ?? client).post({
|
|
|
405
405
|
url: '/endpoints',
|
|
406
406
|
...options,
|
|
407
407
|
headers: {
|
|
408
|
-
'Content-Type': 'application/json',
|
|
408
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
409
409
|
...options.headers
|
|
410
410
|
}
|
|
411
411
|
});
|
|
@@ -434,7 +434,7 @@ export const updateEndpoint = (options) => (options.client ?? client).patch({
|
|
|
434
434
|
url: '/endpoints/{id}',
|
|
435
435
|
...options,
|
|
436
436
|
headers: {
|
|
437
|
-
'Content-Type': 'application/json',
|
|
437
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
438
438
|
...options.headers
|
|
439
439
|
}
|
|
440
440
|
});
|
|
@@ -475,7 +475,7 @@ export const createFilter = (options) => (options.client ?? client).post({
|
|
|
475
475
|
url: '/filters',
|
|
476
476
|
...options,
|
|
477
477
|
headers: {
|
|
478
|
-
'Content-Type': 'application/json',
|
|
478
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
479
479
|
...options.headers
|
|
480
480
|
}
|
|
481
481
|
});
|
|
@@ -497,7 +497,7 @@ export const updateFilter = (options) => (options.client ?? client).patch({
|
|
|
497
497
|
url: '/filters/{id}',
|
|
498
498
|
...options,
|
|
499
499
|
headers: {
|
|
500
|
-
'Content-Type': 'application/json',
|
|
500
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
501
501
|
...options.headers
|
|
502
502
|
}
|
|
503
503
|
});
|
|
@@ -590,7 +590,7 @@ export const sendEmail = (options) => (options.client ?? client).post({
|
|
|
590
590
|
url: '/send-mail',
|
|
591
591
|
...options,
|
|
592
592
|
headers: {
|
|
593
|
-
'Content-Type': 'application/json',
|
|
593
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
594
594
|
...options.headers
|
|
595
595
|
}
|
|
596
596
|
});
|
|
@@ -683,7 +683,7 @@ export const createFunction = (options) => (options.client ?? client).post({
|
|
|
683
683
|
url: '/functions',
|
|
684
684
|
...options,
|
|
685
685
|
headers: {
|
|
686
|
-
'Content-Type': 'application/json',
|
|
686
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
687
687
|
...options.headers
|
|
688
688
|
}
|
|
689
689
|
});
|
|
@@ -739,7 +739,7 @@ export const updateFunction = (options) => (options.client ?? client).put({
|
|
|
739
739
|
url: '/functions/{id}',
|
|
740
740
|
...options,
|
|
741
741
|
headers: {
|
|
742
|
-
'Content-Type': 'application/json',
|
|
742
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
743
743
|
...options.headers
|
|
744
744
|
}
|
|
745
745
|
});
|
|
@@ -747,8 +747,14 @@ export const updateFunction = (options) => (options.client ?? client).put({
|
|
|
747
747
|
* Send a test invocation
|
|
748
748
|
*
|
|
749
749
|
* Sends a real test email from a Primitive-controlled sender to a
|
|
750
|
-
*
|
|
751
|
-
*
|
|
750
|
+
* local-part on one of the org's verified inbound domains. By
|
|
751
|
+
* default the recipient is a synthetic
|
|
752
|
+
* `__primitive_function_test+<random>@<domain>` address that
|
|
753
|
+
* every handler's catch-all routing receives identically; pass
|
|
754
|
+
* `local_part` to override and exercise routing logic that
|
|
755
|
+
* branches on a specific recipient (the common pattern when one
|
|
756
|
+
* function handles multiple inboxes like `summarize@` and
|
|
757
|
+
* `action@`). The function fires through the normal MX delivery
|
|
752
758
|
* path, so reply / send-mail calls from inside the handler
|
|
753
759
|
* against the inbound's `email.id` work the same as in
|
|
754
760
|
* production. Returns immediately after the send is queued; the
|
|
@@ -758,12 +764,18 @@ export const updateFunction = (options) => (options.client ?? client).put({
|
|
|
758
764
|
* Requires that the function is currently `deployed`. Returns 422
|
|
759
765
|
* if the function is in `pending` or `failed` state, or if the
|
|
760
766
|
* org has no verified inbound domain to receive the test mail.
|
|
767
|
+
* Returns 400 if `local_part` is set to a value that does not
|
|
768
|
+
* match the local-part character set.
|
|
761
769
|
*
|
|
762
770
|
*/
|
|
763
771
|
export const testFunction = (options) => (options.client ?? client).post({
|
|
764
772
|
security: [{ scheme: 'bearer', type: 'http' }],
|
|
765
773
|
url: '/functions/{id}/test',
|
|
766
|
-
...options
|
|
774
|
+
...options,
|
|
775
|
+
headers: {
|
|
776
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
777
|
+
...options.headers
|
|
778
|
+
}
|
|
767
779
|
});
|
|
768
780
|
/**
|
|
769
781
|
* List a function's secrets
|
|
@@ -804,7 +816,7 @@ export const createFunctionSecret = (options) => (options.client ?? client).post
|
|
|
804
816
|
url: '/functions/{id}/secrets',
|
|
805
817
|
...options,
|
|
806
818
|
headers: {
|
|
807
|
-
'Content-Type': 'application/json',
|
|
819
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
808
820
|
...options.headers
|
|
809
821
|
}
|
|
810
822
|
});
|
|
@@ -838,7 +850,7 @@ export const setFunctionSecret = (options) => (options.client ?? client).put({
|
|
|
838
850
|
url: '/functions/{id}/secrets/{key}',
|
|
839
851
|
...options,
|
|
840
852
|
headers: {
|
|
841
|
-
'Content-Type': 'application/json',
|
|
853
|
+
...(options.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
842
854
|
...options.headers
|
|
843
855
|
}
|
|
844
856
|
});
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { f as WebhookVerificationError, p as WebhookVerificationErrorCode } from "../errors-C53fe686.js";
|
|
2
|
+
import { $ as pollCliLogin, $a as StorageStats, $i as ReplayDeliveryError, $n as DownloadRawEmailErrors, $o as Config, $r as GetWebhookSecretError, $t as CreateFunctionSecretData, A as deleteEmail, Aa as SendMailInput, Ai as ListFunctionSecretsData, An as DeleteFunctionResponses, Ao as UpdateEndpointResponse, Ar as GetEmailResponse, At as CliLogoutResponse, B as getFunction, Ba as SentEmailSummary, Bi as ListSentEmailsData, Bn as DiscardEmailContentError, Bo as UpdateFunctionErrors, Br as GetSendPermissionsResponse, Bt as CreateFilterData, C as addDomain, Ca as SearchEmailsResponse, Ci as ListEndpointsResponses, Cn as DeleteFilterErrors, Co as UpdateDomainInput, Cr as GetAccountError, Ct as AddDomainResponses, D as createFunction, Da as SendEmailErrors, Di as ListFiltersErrors, Dn as DeleteFunctionError, Do as UpdateEndpointError, Dr as GetEmailData, Dt as CliLogoutError, E as createFilter, Ea as SendEmailError, Ei as ListFiltersError, En as DeleteFunctionData, Eo as UpdateEndpointData, Er as GetAccountResponses, Et as CliLogoutData, F as discardEmailContent, Fa as SendPermissionRule, Fi as ListFunctionsData, Fn as DeleteFunctionSecretResponses, Fo as UpdateFilterInput, Fr as GetFunctionResponse, Ft as CreateEndpointError, G as listDeliveries, Ga as SetFunctionSecretResponse, Gi as PaginationMeta, Gn as DomainVerifyResult, Go as VerifyDomainData, Gr as GetSentEmailResponse, Gt as CreateFilterResponses, H as getSentEmail, Ha as SetFunctionSecretError, Hi as ListSentEmailsErrors, Hn as DiscardEmailContentResponse, Ho as UpdateFunctionResponse, Hr as GetSentEmailData, Ht as CreateFilterErrors, I as downloadAttachments, Ia as SendPermissionYourDomain, Ii as ListFunctionsError, In as DeliveryStatus, Io as UpdateFilterResponse, Ir as GetFunctionResponses, It as CreateEndpointErrors, J as listEndpoints, Ja as StartCliLoginError, Ji as PollCliLoginErrors, Jn as DownloadAttachmentsErrors, Jo as VerifyDomainResponse, Jr as GetStorageStatsError, Jt as CreateFunctionErrors, K as listDomains, Ka as SetFunctionSecretResponses, Ki as PollCliLoginData, Kn as DownloadAttachmentsData, Ko as VerifyDomainError, Kr as GetSentEmailResponses, Kt as CreateFunctionData, L as downloadRawEmail, La as SendPermissionsMeta, Li as ListFunctionsErrors, Ln as DeliverySummary, Lo as UpdateFilterResponses, Lr as GetSendPermissionsData, Lt as CreateEndpointInput, M as deleteFilter, Ma as SendPermissionAddress, Mi as ListFunctionSecretsErrors, Mn as DeleteFunctionSecretError, Mo as UpdateFilterData, Mr as GetFunctionData, Mt as CliLogoutResult, N as deleteFunction, Na as SendPermissionAnyRecipient, Ni as ListFunctionSecretsResponse, Nn as DeleteFunctionSecretErrors, No as UpdateFilterError, Nr as GetFunctionError, Nt as ClientOptions, O as createFunctionSecret, Oa as SendEmailResponse, Oi as ListFiltersResponse, On as DeleteFunctionErrors, Oo as UpdateEndpointErrors, Or as GetEmailError, Ot as CliLogoutErrors, P as deleteFunctionSecret, Pa as SendPermissionManagedZone, Pi as ListFunctionSecretsResponses, Pn as DeleteFunctionSecretResponse, Po as UpdateFilterErrors, Pr as GetFunctionErrors, Pt as CreateEndpointData, Q as listSentEmails, Qa as StartCliLoginResponses, Qi as ReplayDeliveryData, Qn as DownloadRawEmailError, Qo as ClientOptions$1, Qr as GetWebhookSecretData, Qt as CreateFunctionResult, R as getAccount, Ra as SentEmailDetail, Ri as ListFunctionsResponse, Rn as DiscardContentResult, Ro as UpdateFunctionData, Rr as GetSendPermissionsError, Rt as CreateEndpointResponse, S as Options, Sa as SearchEmailsErrors, Si as ListEndpointsResponse, Sn as DeleteFilterError, So as UpdateDomainErrors, Sr as GetAccountData, St as AddDomainResponse, T as createEndpoint, Ta as SendEmailData, Ti as ListFiltersData, Tn as DeleteFilterResponses, To as UpdateDomainResponses, Tr as GetAccountResponse, Tt as CliLoginStartResult, U as getStorageStats, Ua as SetFunctionSecretErrors, Ui as ListSentEmailsResponse, Un as DiscardEmailContentResponses, Uo as UpdateFunctionResponses, Ur as GetSentEmailError, Ut as CreateFilterInput, V as getSendPermissions, Va as SetFunctionSecretData, Vi as ListSentEmailsError, Vn as DiscardEmailContentErrors, Vo as UpdateFunctionInput, Vr as GetSendPermissionsResponses, Vt as CreateFilterError, W as getWebhookSecret, Wa as SetFunctionSecretInput, Wi as ListSentEmailsResponses, Wn as Domain, Wo as VerifiedDomain, Wr as GetSentEmailErrors, Wt as CreateFilterResponse, X as listFunctionSecrets, Xa as StartCliLoginInput, Xi as PollCliLoginResponse, Xn as DownloadAttachmentsResponses, Xo as WebhookSecret, Xr as GetStorageStatsResponse, Xt as CreateFunctionResponse, Y as listFilters, Ya as StartCliLoginErrors, Yi as PollCliLoginInput, Yn as DownloadAttachmentsResponse, Yo as VerifyDomainResponses, Yr as GetStorageStatsErrors, Yt as CreateFunctionInput, Z as listFunctions, Za as StartCliLoginResponse, Zi as PollCliLoginResponses, Zn as DownloadRawEmailData, Zo as Client, Zr as GetStorageStatsResponses, Zt as CreateFunctionResponses, _ as createPrimitiveClient, _a as RotateWebhookSecretErrors, _i as ListEmailsResponse, _n as DeleteEndpointError, _o as UpdateAccountInput, _r as FunctionListItem, _t as AccountUpdated, a as PrimitiveApiClientOptions, aa as ReplayEmailWebhooksErrors, ai as ListDeliveriesError, an as Cursor, ao as TestEndpointResponses, ar as EmailSearchFacets, as as Auth, at as sendEmail, b as VerifyOptions, ba as SearchEmailsData, bi as ListEndpointsError, bn as DeleteEndpointResponses, bo as UpdateDomainData, br as GateDenial, bt as AddDomainErrors, c as PrimitiveClient, ca as ReplayResult, ci as ListDeliveriesResponses, cn as DeleteDomainErrors, co as TestFunctionErrors, cr as EmailSearchResult, ct as testEndpoint, d as RequestOptions$1, da as ReplyToEmailErrors, di as ListDomainsErrors, dn as DeleteEmailData, do as TestInvocationResult, dr as EmailWebhookStatus, dt as updateDomain, ea as ReplayDeliveryErrors, ei as GetWebhookSecretErrors, en as CreateFunctionSecretError, eo as SuccessEnvelope, er as DownloadRawEmailResponse, es as CreateClientConfig, et as replayDelivery, f as SendInput, fa as ReplyToEmailResponse, fi as ListDomainsResponse, fn as DeleteEmailError, fo as TestResult, fr as Endpoint, ft as updateEndpoint, g as createPrimitiveApiClient, ga as RotateWebhookSecretError, gi as ListEmailsErrors, gn as DeleteEndpointData, go as UpdateAccountErrors, gr as FunctionDetail, gt as Account, h as client, ha as RotateWebhookSecretData, hi as ListEmailsError, hn as DeleteEmailResponses, ho as UpdateAccountError, hr as FunctionDeployStatus, ht as verifyDomain, i as PrimitiveApiClient, ia as ReplayEmailWebhooksError, ii as ListDeliveriesData, in as CreateFunctionSecretResponses, io as TestEndpointResponse, ir as EmailSearchFacetBucket, is as ResponseStyle, it as searchEmails, j as deleteEndpoint, ja as SendMailResult, ji as ListFunctionSecretsError, jn as DeleteFunctionSecretData, jo as UpdateEndpointResponses, jr as GetEmailResponses, jt as CliLogoutResponses, k as deleteDomain, ka as SendEmailResponses, ki as ListFiltersResponses, kn as DeleteFunctionResponse, ko as UpdateEndpointInput, kr as GetEmailErrors, kt as CliLogoutInput, l as PrimitiveClientOptions, la as ReplyToEmailData, li as ListDomainsData, ln as DeleteDomainResponse, lo as TestFunctionResponse, lr as EmailStatus, lt as testFunction, m as SendThreadInput, ma as ResourceId, mi as ListEmailsData, mn as DeleteEmailResponse, mo as UpdateAccountData, mr as Filter, mt as updateFunction, n as DEFAULT_API_BASE_URL_2, na as ReplayDeliveryResponses, ni as GetWebhookSecretResponses, nn as CreateFunctionSecretInput, no as TestEndpointError, nr as EmailDetail, ns as RequestOptions, nt as replyToEmail, o as PrimitiveApiError, oa as ReplayEmailWebhooksResponse, oi as ListDeliveriesErrors, on as DeleteDomainData, oo as TestFunctionData, or as EmailSearchHighlights, ot as setFunctionSecret, p as SendResult, pa as ReplyToEmailResponses, pi as ListDomainsResponses, pn as DeleteEmailErrors, po as UnverifiedDomain, pr as ErrorResponse, pt as updateFilter, q as listEmails, qa as StartCliLoginData, qi as PollCliLoginError, qn as DownloadAttachmentsError, qo as VerifyDomainErrors, qr as GetStorageStatsData, qt as CreateFunctionError, r as ForwardInput, ra as ReplayEmailWebhooksData, ri as Limit, rn as CreateFunctionSecretResponse, ro as TestEndpointErrors, rr as EmailDetailReply, rs as RequestResult, rt as rotateWebhookSecret, s as PrimitiveApiErrorDetails, sa as ReplayEmailWebhooksResponses, si as ListDeliveriesResponse, sn as DeleteDomainError, so as TestFunctionError, sr as EmailSearchMeta, st as startCliLogin, t as DEFAULT_API_BASE_URL_1, ta as ReplayDeliveryResponse, ti as GetWebhookSecretResponse, tn as CreateFunctionSecretErrors, to as TestEndpointData, tr as DownloadRawEmailResponses, ts as Options$1, tt as replayEmailWebhooks, u as ReplyInput, ua as ReplyToEmailError, ui as ListDomainsError, un as DeleteDomainResponses, uo as TestFunctionResponses, ur as EmailSummary, ut as updateAccount, v as operations, va as RotateWebhookSecretResponse, vi as ListEmailsResponses, vn as DeleteEndpointErrors, vo as UpdateAccountResponse, vr as FunctionSecretListItem, vt as AddDomainData, w as cliLogout, wa as SearchEmailsResponses, wi as ListEnvelope, wn as DeleteFilterResponse, wo as UpdateDomainResponse, wr as GetAccountErrors, wt as CliLoginPollResult, x as verifyWebhookSignature, xa as SearchEmailsError, xi as ListEndpointsErrors, xn as DeleteFilterData, xo as UpdateDomainError, xr as GateFix, xt as AddDomainInput, y as PRIMITIVE_SIGNATURE_HEADER, ya as RotateWebhookSecretResponses, yi as ListEndpointsData, yn as DeleteEndpointResponse, yo as UpdateAccountResponses, yr as FunctionSecretWriteResult, yt as AddDomainError, z as getEmail, za as SentEmailStatus, zi as ListFunctionsResponses, zn as DiscardEmailContentData, zo as UpdateFunctionError, zr as GetSendPermissionsErrors, zt as CreateEndpointResponses } from "../index-DdITDPea.js";
|
|
3
|
+
export { Account, AccountUpdated, AddDomainData, AddDomainError, AddDomainErrors, AddDomainInput, AddDomainResponse, AddDomainResponses, Auth, CliLoginPollResult, CliLoginStartResult, CliLogoutData, CliLogoutError, CliLogoutErrors, CliLogoutInput, CliLogoutResponse, CliLogoutResponses, CliLogoutResult, ClientOptions, CreateClientConfig, CreateEndpointData, CreateEndpointError, CreateEndpointErrors, CreateEndpointInput, CreateEndpointResponse, CreateEndpointResponses, CreateFilterData, CreateFilterError, CreateFilterErrors, CreateFilterInput, CreateFilterResponse, CreateFilterResponses, CreateFunctionData, CreateFunctionError, CreateFunctionErrors, CreateFunctionInput, CreateFunctionResponse, CreateFunctionResponses, CreateFunctionResult, CreateFunctionSecretData, CreateFunctionSecretError, CreateFunctionSecretErrors, CreateFunctionSecretInput, CreateFunctionSecretResponse, CreateFunctionSecretResponses, Cursor, DEFAULT_API_BASE_URL_1, DEFAULT_API_BASE_URL_2, DeleteDomainData, DeleteDomainError, DeleteDomainErrors, DeleteDomainResponse, DeleteDomainResponses, DeleteEmailData, DeleteEmailError, DeleteEmailErrors, DeleteEmailResponse, DeleteEmailResponses, DeleteEndpointData, DeleteEndpointError, DeleteEndpointErrors, DeleteEndpointResponse, DeleteEndpointResponses, DeleteFilterData, DeleteFilterError, DeleteFilterErrors, DeleteFilterResponse, DeleteFilterResponses, DeleteFunctionData, DeleteFunctionError, DeleteFunctionErrors, DeleteFunctionResponse, DeleteFunctionResponses, DeleteFunctionSecretData, DeleteFunctionSecretError, DeleteFunctionSecretErrors, DeleteFunctionSecretResponse, DeleteFunctionSecretResponses, DeliveryStatus, DeliverySummary, DiscardContentResult, DiscardEmailContentData, DiscardEmailContentError, DiscardEmailContentErrors, DiscardEmailContentResponse, DiscardEmailContentResponses, Domain, DomainVerifyResult, DownloadAttachmentsData, DownloadAttachmentsError, DownloadAttachmentsErrors, DownloadAttachmentsResponse, DownloadAttachmentsResponses, DownloadRawEmailData, DownloadRawEmailError, DownloadRawEmailErrors, DownloadRawEmailResponse, DownloadRawEmailResponses, EmailDetail, EmailDetailReply, EmailSearchFacetBucket, EmailSearchFacets, EmailSearchHighlights, EmailSearchMeta, EmailSearchResult, EmailStatus, EmailSummary, EmailWebhookStatus, Endpoint, ErrorResponse, Filter, ForwardInput, FunctionDeployStatus, FunctionDetail, FunctionListItem, FunctionSecretListItem, FunctionSecretWriteResult, GateDenial, GateFix, GetAccountData, GetAccountError, GetAccountErrors, GetAccountResponse, GetAccountResponses, GetEmailData, GetEmailError, GetEmailErrors, GetEmailResponse, GetEmailResponses, GetFunctionData, GetFunctionError, GetFunctionErrors, GetFunctionResponse, GetFunctionResponses, GetSendPermissionsData, GetSendPermissionsError, GetSendPermissionsErrors, GetSendPermissionsResponse, GetSendPermissionsResponses, GetSentEmailData, GetSentEmailError, GetSentEmailErrors, GetSentEmailResponse, GetSentEmailResponses, 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, ListFunctionSecretsData, ListFunctionSecretsError, ListFunctionSecretsErrors, ListFunctionSecretsResponse, ListFunctionSecretsResponses, ListFunctionsData, ListFunctionsError, ListFunctionsErrors, ListFunctionsResponse, ListFunctionsResponses, ListSentEmailsData, ListSentEmailsError, ListSentEmailsErrors, ListSentEmailsResponse, ListSentEmailsResponses, Options, PRIMITIVE_SIGNATURE_HEADER, PaginationMeta, PollCliLoginData, PollCliLoginError, PollCliLoginErrors, PollCliLoginInput, PollCliLoginResponse, PollCliLoginResponses, 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, ReplyToEmailData, ReplyToEmailError, ReplyToEmailErrors, ReplyToEmailResponse, ReplyToEmailResponses, RequestOptions$1 as RequestOptions, ResourceId, ResponseStyle, RotateWebhookSecretData, RotateWebhookSecretError, RotateWebhookSecretErrors, RotateWebhookSecretResponse, RotateWebhookSecretResponses, SearchEmailsData, SearchEmailsError, SearchEmailsErrors, SearchEmailsResponse, SearchEmailsResponses, SendEmailData, SendEmailError, SendEmailErrors, SendEmailResponse, SendEmailResponses, SendInput, SendMailInput, SendMailResult, SendPermissionAddress, SendPermissionAnyRecipient, SendPermissionManagedZone, SendPermissionRule, SendPermissionYourDomain, SendPermissionsMeta, SendResult, SendThreadInput, SentEmailDetail, SentEmailStatus, SentEmailSummary, SetFunctionSecretData, SetFunctionSecretError, SetFunctionSecretErrors, SetFunctionSecretInput, SetFunctionSecretResponse, SetFunctionSecretResponses, StartCliLoginData, StartCliLoginError, StartCliLoginErrors, StartCliLoginInput, StartCliLoginResponse, StartCliLoginResponses, StorageStats, SuccessEnvelope, TestEndpointData, TestEndpointError, TestEndpointErrors, TestEndpointResponse, TestEndpointResponses, TestFunctionData, TestFunctionError, TestFunctionErrors, TestFunctionResponse, TestFunctionResponses, TestInvocationResult, 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, UpdateFunctionData, UpdateFunctionError, UpdateFunctionErrors, UpdateFunctionInput, UpdateFunctionResponse, UpdateFunctionResponses, VerifiedDomain, VerifyDomainData, VerifyDomainError, VerifyDomainErrors, VerifyDomainResponse, VerifyDomainResponses, VerifyOptions as VerifyWebhookSignatureOptions, WebhookSecret, WebhookVerificationError, WebhookVerificationErrorCode, addDomain, cliLogout, client, createEndpoint, createFilter, createFunction, createFunctionSecret, createPrimitiveApiClient, createPrimitiveClient, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, deleteFunction, deleteFunctionSecret, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getFunction, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listFunctionSecrets, listFunctions, listSentEmails, operations, pollCliLogin, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, searchEmails, sendEmail, setFunctionSecret, startCliLogin, testEndpoint, testFunction, updateAccount, updateDomain, updateEndpoint, updateFilter, updateFunction, verifyDomain, verifyWebhookSignature };
|
package/dist/api/index.js
CHANGED
|
@@ -398,3 +398,9 @@ export function client(options = {}) {
|
|
|
398
398
|
}
|
|
399
399
|
export const operations = generatedOperations;
|
|
400
400
|
export * from "./generated/index.js";
|
|
401
|
+
// Web Crypto verifier for in-handler webhook verification. Mirrors
|
|
402
|
+
// the surface of `verifyWebhookSignature` from `@primitivedotdev/sdk`
|
|
403
|
+
// (the Node version) but implements HMAC-SHA256 with `crypto.subtle`
|
|
404
|
+
// so it can be bundled into a Primitive Function without pulling in
|
|
405
|
+
// a `node:crypto` polyfill.
|
|
406
|
+
export { PRIMITIVE_SIGNATURE_HEADER, verifyWebhookSignature, WebhookVerificationError, } from "./verify-signature.js";
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workers-safe webhook signature verification.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `verifyWebhookSignature` from `@primitivedotdev/sdk` but
|
|
5
|
+
* implements the HMAC-SHA256 step with the Web Crypto API
|
|
6
|
+
* (`crypto.subtle`) instead of `node:crypto`. The Node version is
|
|
7
|
+
* still the right choice for server-side handlers running on Node
|
|
8
|
+
* (it's measurably faster and supports Buffer bodies); this one
|
|
9
|
+
* exists so a Primitive Function handler can bundle the verifier
|
|
10
|
+
* without dragging in a `node:crypto` polyfill that inflates the
|
|
11
|
+
* deploy artifact past the size cap.
|
|
12
|
+
*
|
|
13
|
+
* Available natively in Workers, Node 22+, browsers, Deno, and Bun.
|
|
14
|
+
* Zero polyfill weight, zero new runtime dependencies.
|
|
15
|
+
*
|
|
16
|
+
* Surface contract matches the Node verifier exactly: same input
|
|
17
|
+
* shape, same `WebhookVerificationError` class, same set of error
|
|
18
|
+
* codes. Existing callers can swap the import path with no other
|
|
19
|
+
* code changes:
|
|
20
|
+
*
|
|
21
|
+
* // Node (existing):
|
|
22
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk';
|
|
23
|
+
*
|
|
24
|
+
* // Workers / in-handler (this file):
|
|
25
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk/api';
|
|
26
|
+
*/
|
|
27
|
+
import { WebhookVerificationError } from "../webhook/errors.js";
|
|
28
|
+
// Header name carrying the timestamp + signature. Must match the
|
|
29
|
+
// constant of the same name in `../webhook/signing.ts`. Kept in two
|
|
30
|
+
// places intentionally so this file has no dependency on the Node
|
|
31
|
+
// signing module (which would drag `node:crypto` into the bundle).
|
|
32
|
+
export const PRIMITIVE_SIGNATURE_HEADER = "Primitive-Signature";
|
|
33
|
+
// Re-export so consumers can `import { verifyWebhookSignature,
|
|
34
|
+
// WebhookVerificationError } from '@primitivedotdev/sdk/api'`
|
|
35
|
+
// without a second import statement against `/webhook`.
|
|
36
|
+
export { WebhookVerificationError } from "../webhook/errors.js";
|
|
37
|
+
// 5 minute max-age tolerance matches `webhook/signing.ts`.
|
|
38
|
+
const DEFAULT_TOLERANCE_SECONDS = 5 * 60;
|
|
39
|
+
// 60 second future tolerance for clock skew.
|
|
40
|
+
const FUTURE_TOLERANCE_SECONDS = 60;
|
|
41
|
+
// HMAC-SHA256 hex digest is 64 characters. Accept either case to
|
|
42
|
+
// stay byte-for-byte compatible with the Node verifier in
|
|
43
|
+
// `../webhook/signing.ts`, which uses the same pattern with the `/i`
|
|
44
|
+
// flag. Canonical Primitive signers emit lowercase, but tolerating
|
|
45
|
+
// uppercase keeps third-party signers (and tests that hand-build
|
|
46
|
+
// fixtures) from silently failing through to SIGNATURE_MISMATCH.
|
|
47
|
+
const HEX_PATTERN = /^[0-9a-f]+$/i;
|
|
48
|
+
const HEX_LENGTH = 64;
|
|
49
|
+
const UNIX_SECONDS_PATTERN = /^\d{1,10}$/;
|
|
50
|
+
function parseSignatureHeader(signatureHeader) {
|
|
51
|
+
if (!signatureHeader || typeof signatureHeader !== "string") {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const parts = signatureHeader.split(",");
|
|
55
|
+
let timestamp = null;
|
|
56
|
+
const signatures = [];
|
|
57
|
+
for (const part of parts) {
|
|
58
|
+
const idx = part.indexOf("=");
|
|
59
|
+
if (idx === -1)
|
|
60
|
+
continue;
|
|
61
|
+
const key = part.slice(0, idx).trim();
|
|
62
|
+
const value = part.slice(idx + 1).trim();
|
|
63
|
+
if (!key || !value)
|
|
64
|
+
continue;
|
|
65
|
+
if (key === "t") {
|
|
66
|
+
if (!UNIX_SECONDS_PATTERN.test(value))
|
|
67
|
+
continue;
|
|
68
|
+
const parsed = Number(value);
|
|
69
|
+
if (Number.isSafeInteger(parsed)) {
|
|
70
|
+
timestamp = parsed;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (key === "v1") {
|
|
74
|
+
signatures.push(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (timestamp === null || signatures.length === 0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return { timestamp, signatures };
|
|
81
|
+
}
|
|
82
|
+
function isValidHex(str) {
|
|
83
|
+
return str.length === HEX_LENGTH && HEX_PATTERN.test(str);
|
|
84
|
+
}
|
|
85
|
+
function arrayBufferToHex(buffer) {
|
|
86
|
+
const bytes = new Uint8Array(buffer);
|
|
87
|
+
let hex = "";
|
|
88
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
89
|
+
// biome-ignore lint/style/noNonNullAssertion: bytes[i] is always defined for valid index
|
|
90
|
+
hex += bytes[i].toString(16).padStart(2, "0");
|
|
91
|
+
}
|
|
92
|
+
return hex;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Constant-time comparison of two equal-length hex strings. Returns
|
|
96
|
+
* false if lengths differ (intentionally not a security issue: lengths
|
|
97
|
+
* are public). Iterates the full length regardless of mismatch so the
|
|
98
|
+
* timing signal does not reveal the position of the first divergence.
|
|
99
|
+
*/
|
|
100
|
+
function timingSafeEqualHex(a, b) {
|
|
101
|
+
if (a.length !== b.length)
|
|
102
|
+
return false;
|
|
103
|
+
let diff = 0;
|
|
104
|
+
for (let i = 0; i < a.length; i++) {
|
|
105
|
+
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
106
|
+
}
|
|
107
|
+
return diff === 0;
|
|
108
|
+
}
|
|
109
|
+
async function computeHmacHex(secret, payload) {
|
|
110
|
+
const encoder = new TextEncoder();
|
|
111
|
+
const keyData = encoder.encode(secret);
|
|
112
|
+
const key = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
113
|
+
const signature = await crypto.subtle.sign("HMAC", key, encoder.encode(payload));
|
|
114
|
+
return arrayBufferToHex(signature);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Verify a webhook signature using the Web Crypto API.
|
|
118
|
+
*
|
|
119
|
+
* Throws `WebhookVerificationError` on failure with a specific error
|
|
120
|
+
* code matching the Node verifier's set. Returns `true` on success.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import {
|
|
125
|
+
* verifyWebhookSignature,
|
|
126
|
+
* WebhookVerificationError,
|
|
127
|
+
* PRIMITIVE_SIGNATURE_HEADER,
|
|
128
|
+
* } from '@primitivedotdev/sdk/api';
|
|
129
|
+
*
|
|
130
|
+
* export default {
|
|
131
|
+
* async fetch(request: Request, env: { PRIMITIVE_WEBHOOK_SECRET: string }) {
|
|
132
|
+
* const rawBody = await request.text();
|
|
133
|
+
* try {
|
|
134
|
+
* await verifyWebhookSignature({
|
|
135
|
+
* rawBody,
|
|
136
|
+
* signatureHeader: request.headers.get(PRIMITIVE_SIGNATURE_HEADER) ?? '',
|
|
137
|
+
* secret: env.PRIMITIVE_WEBHOOK_SECRET,
|
|
138
|
+
* });
|
|
139
|
+
* } catch (err) {
|
|
140
|
+
* if (err instanceof WebhookVerificationError) {
|
|
141
|
+
* return new Response('invalid signature', { status: 401 });
|
|
142
|
+
* }
|
|
143
|
+
* throw err;
|
|
144
|
+
* }
|
|
145
|
+
* // ... process the webhook
|
|
146
|
+
* },
|
|
147
|
+
* };
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export async function verifyWebhookSignature(opts) {
|
|
151
|
+
const { rawBody, signatureHeader, secret, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS, nowSeconds, } = opts;
|
|
152
|
+
// `secret` is typed as `string` here (Node verifier also accepts
|
|
153
|
+
// Buffer, but Buffer isn't a thing in Workers and we deliberately
|
|
154
|
+
// don't include it in the Web Crypto API surface). `!secret` already
|
|
155
|
+
// catches undefined, null, and "" cleanly; no extra type guard
|
|
156
|
+
// needed.
|
|
157
|
+
if (!secret) {
|
|
158
|
+
throw new WebhookVerificationError("MISSING_SECRET", "Webhook secret is required but was empty or not provided");
|
|
159
|
+
}
|
|
160
|
+
const parsed = parseSignatureHeader(signatureHeader);
|
|
161
|
+
if (!parsed) {
|
|
162
|
+
throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", "Invalid Primitive-Signature header format. Expected: t={timestamp},v1={signature}");
|
|
163
|
+
}
|
|
164
|
+
const { timestamp, signatures } = parsed;
|
|
165
|
+
const now = nowSeconds ?? Math.floor(Date.now() / 1000);
|
|
166
|
+
const age = now - timestamp;
|
|
167
|
+
if (age > toleranceSeconds) {
|
|
168
|
+
throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", `Webhook timestamp too old (${age}s). Max age is ${toleranceSeconds}s.`);
|
|
169
|
+
}
|
|
170
|
+
if (age < -FUTURE_TOLERANCE_SECONDS) {
|
|
171
|
+
throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", "Webhook timestamp is too far in the future. Check server clock sync.");
|
|
172
|
+
}
|
|
173
|
+
const signedPayloadString = `${timestamp}.${rawBody}`;
|
|
174
|
+
const expectedHex = await computeHmacHex(secret, signedPayloadString);
|
|
175
|
+
// Walk every provided signature so a key-rotation header carrying
|
|
176
|
+
// [old, new] still verifies once the new key is live. Constant-time
|
|
177
|
+
// comparison per candidate so a partial-match attacker can't binary
|
|
178
|
+
// search hex characters by timing.
|
|
179
|
+
//
|
|
180
|
+
// Lowercase the candidate before comparing: HEX_PATTERN accepts
|
|
181
|
+
// either case (to match the Node verifier, which decodes via
|
|
182
|
+
// `Buffer.from(str, "hex")` and is case-insensitive), but
|
|
183
|
+
// expectedHex from `arrayBufferToHex` is always lowercase.
|
|
184
|
+
// Comparing raw `charCodeAt` would treat "AB" and "ab" as
|
|
185
|
+
// different and silently fail through to SIGNATURE_MISMATCH.
|
|
186
|
+
let anyMatch = false;
|
|
187
|
+
for (const candidate of signatures) {
|
|
188
|
+
if (!isValidHex(candidate))
|
|
189
|
+
continue;
|
|
190
|
+
if (timingSafeEqualHex(candidate.toLowerCase(), expectedHex)) {
|
|
191
|
+
anyMatch = true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!anyMatch) {
|
|
195
|
+
throw new WebhookVerificationError("SIGNATURE_MISMATCH", "Webhook signature did not match. The body may have been modified in transit, or the secret may be out of date.");
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|