@primitivedotdev/sdk 0.25.0 → 0.25.2
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/index.js +1 -1
- package/dist/api/generated/sdk.gen.js +19 -0
- 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-C3X14uId.js → api-Cfj_U9RX.js} +164 -2
- 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-jLAAV6Sq.d.ts → index-DISHEO_u.d.ts} +204 -3
- package/dist/{index-CDlwyxdp.d.ts → index-Dbx9udpX.d.ts} +2 -210
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/openapi/openapi.generated.js +144 -0
- package/dist/openapi/operations.generated.js +110 -0
- 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 +73 -1
- package/package.json +1 -1
- package/dist/received-email-D6tKtWwW.js +0 -69
- package/dist/received-email-DNjpq_Wt.d.ts +0 -37
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
export { addDomain, cliLogout, createEndpoint, createFilter, createFunction, createFunctionSecret, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, deleteFunction, deleteFunctionSecret, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getFunction, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listFunctions, listFunctionSecrets, listSentEmails, pollCliLogin, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, searchEmails, sendEmail, setFunctionSecret, startCliLogin, testEndpoint, testFunction, updateAccount, updateDomain, updateEndpoint, updateFilter, updateFunction, verifyDomain } from './sdk.gen.js';
|
|
2
|
+
export { addDomain, cliLogout, createEndpoint, createFilter, createFunction, createFunctionSecret, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, deleteFunction, deleteFunctionSecret, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getFunction, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listFunctionLogs, listFunctions, listFunctionSecrets, listSentEmails, pollCliLogin, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, searchEmails, sendEmail, setFunctionSecret, startCliLogin, testEndpoint, testFunction, updateAccount, updateDomain, updateEndpoint, updateFilter, updateFunction, verifyDomain } from './sdk.gen.js';
|
|
@@ -854,3 +854,22 @@ export const setFunctionSecret = (options) => (options.client ?? client).put({
|
|
|
854
854
|
...options.headers
|
|
855
855
|
}
|
|
856
856
|
});
|
|
857
|
+
/**
|
|
858
|
+
* List a function's execution logs
|
|
859
|
+
*
|
|
860
|
+
* Returns the most recent `function_logs` rows for the function,
|
|
861
|
+
* newest first. Each row is a single `console.log` / `console.error`
|
|
862
|
+
* invocation captured from the running handler.
|
|
863
|
+
*
|
|
864
|
+
* Page through history with the opaque `cursor` returned as
|
|
865
|
+
* `next_cursor`; pass it back as the `cursor` query param on the
|
|
866
|
+
* next call. `next_cursor` is `null` when there are no further
|
|
867
|
+
* rows. The cursor format is an implementation detail and should
|
|
868
|
+
* not be parsed by callers.
|
|
869
|
+
*
|
|
870
|
+
*/
|
|
871
|
+
export const listFunctionLogs = (options) => (options.client ?? client).get({
|
|
872
|
+
security: [{ scheme: 'bearer', type: 'http' }],
|
|
873
|
+
url: '/functions/{id}/logs',
|
|
874
|
+
...options
|
|
875
|
+
});
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
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, 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, WebhookSecret, 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 };
|
|
1
|
+
import { f as WebhookVerificationError, p as WebhookVerificationErrorCode } from "../errors-C53fe686.js";
|
|
2
|
+
import { $ as listSentEmails, $a as SetFunctionSecretResponses, $i as PollCliLoginData, $n as DownloadRawEmailError, $o as VerifyDomainError, $r as GetStorageStatsResponses, $t as CreateFunctionResult, A as deleteEmail, Aa as SearchEmailsResponse, Ai as ListFiltersResponse, An as DeleteFunctionResponse, Ao as UpdateDomainInput, Ar as GetEmailError, At as CliLogoutInput, B as getFunction, Ba as SendPermissionAnyRecipient, Bi as ListFunctionSecretsResponse, Bn as DiscardEmailContentData, Bo as UpdateFilterError, Br as GetSendPermissionsError, Bt as CreateEndpointResponses, C as addDomain, Ca as RotateWebhookSecretError, Ci as ListEndpointsErrors, Cn as DeleteFilterError, Co as UpdateAccountErrors, Cr as GateFix, Ct as AddDomainResponse, D as createFunction, Da as SearchEmailsData, Di as ListFiltersData, Dn as DeleteFunctionData, Do as UpdateDomainData, Dr as GetAccountResponse, Dt as CliLogoutData, E as createFilter, Ea as RotateWebhookSecretResponses, Ei as ListEnvelope, En as DeleteFilterResponses, Eo as UpdateAccountResponses, Er as GetAccountErrors, Et as CliLoginStartResult, F as discardEmailContent, Fa as SendEmailResponse, Fi as ListFunctionLogsResponse, Fn as DeleteFunctionSecretResponse, Fo as UpdateEndpointErrors, Fr as GetFunctionError, Ft as CreateEndpointData, G as listDeliveries, Ga as SentEmailDetail, Gi as ListFunctionsResponse, Gn as Domain, Go as UpdateFunctionData, Gr as GetSentEmailError, Gt as CreateFilterResponse, H as getSentEmail, Ha as SendPermissionRule, Hi as ListFunctionsData, Hn as DiscardEmailContentErrors, Ho as UpdateFilterInput, Hr as GetSendPermissionsResponse, Ht as CreateFilterError, I as downloadAttachments, Ia as SendEmailResponses, Ii as ListFunctionLogsResponses, In as DeleteFunctionSecretResponses, Io as UpdateEndpointInput, Ir as GetFunctionErrors, It as CreateEndpointError, J as listEndpoints, Ja as SetFunctionSecretData, Ji as ListSentEmailsError, Jn as DownloadAttachmentsError, Jo as UpdateFunctionInput, Jr as GetSentEmailResponses, Jt as CreateFunctionError, K as listDomains, Ka as SentEmailStatus, Ki as ListFunctionsResponses, Kn as DomainVerifyResult, Ko as UpdateFunctionError, Kr as GetSentEmailErrors, Kt as CreateFilterResponses, L as downloadRawEmail, La as SendMailInput, Li as ListFunctionSecretsData, Ln as DeliveryStatus, Lo as UpdateEndpointResponse, Lr as GetFunctionResponse, Lt as CreateEndpointErrors, M as deleteFilter, Ma as SendEmailData, Mi as ListFunctionLogsData, Mn as DeleteFunctionSecretData, Mo as UpdateDomainResponses, Mr as GetEmailResponse, Mt as CliLogoutResponses, N as deleteFunction, Na as SendEmailError, Ni as ListFunctionLogsError, Nn as DeleteFunctionSecretError, No as UpdateEndpointData, Nr as GetEmailResponses, Nt as CliLogoutResult, O as createFunctionSecret, Oa as SearchEmailsError, Oi as ListFiltersError, On as DeleteFunctionError, Oo as UpdateDomainError, Or as GetAccountResponses, Ot as CliLogoutError, P as deleteFunctionSecret, Pa as SendEmailErrors, Pi as ListFunctionLogsErrors, Pn as DeleteFunctionSecretErrors, Po as UpdateEndpointError, Pr as GetFunctionData, Pt as ClientOptions, Q as listFunctions, Qa as SetFunctionSecretResponse, Qi as PaginationMeta, Qn as DownloadRawEmailData, Qo as VerifyDomainData, Qr as GetStorageStatsResponse, Qt as CreateFunctionResponses, R as getAccount, Ra as SendMailResult, Ri as ListFunctionSecretsError, Rn as DeliverySummary, Ro as UpdateEndpointResponses, Rr as GetFunctionResponses, Rt as CreateEndpointInput, S as Options, Sa as RotateWebhookSecretData, Si as ListEndpointsError, Sn as DeleteFilterData, So as UpdateAccountError, Sr as GateDenial, St as AddDomainInput, T as createEndpoint, Ta as RotateWebhookSecretResponse, Ti as ListEndpointsResponses, Tn as DeleteFilterResponse, To as UpdateAccountResponse, Tr as GetAccountError, Tt as CliLoginPollResult, U as getStorageStats, Ua as SendPermissionYourDomain, Ui as ListFunctionsError, Un as DiscardEmailContentResponse, Uo as UpdateFilterResponse, Ur as GetSendPermissionsResponses, Ut as CreateFilterErrors, V as getSendPermissions, Va as SendPermissionManagedZone, Vi as ListFunctionSecretsResponses, Vn as DiscardEmailContentError, Vo as UpdateFilterErrors, Vr as GetSendPermissionsErrors, Vt as CreateFilterData, W as getWebhookSecret, Wa as SendPermissionsMeta, Wi as ListFunctionsErrors, Wn as DiscardEmailContentResponses, Wo as UpdateFilterResponses, Wr as GetSentEmailData, Wt as CreateFilterInput, X as listFunctionLogs, Xa as SetFunctionSecretErrors, Xi as ListSentEmailsResponse, Xn as DownloadAttachmentsResponse, Xo as UpdateFunctionResponses, Xr as GetStorageStatsError, Xt as CreateFunctionInput, Y as listFilters, Ya as SetFunctionSecretError, Yi as ListSentEmailsErrors, Yn as DownloadAttachmentsErrors, Yo as UpdateFunctionResponse, Yr as GetStorageStatsData, Yt as CreateFunctionErrors, Z as listFunctionSecrets, Za as SetFunctionSecretInput, Zi as ListSentEmailsResponses, Zn as DownloadAttachmentsResponses, Zo as VerifiedDomain, Zr as GetStorageStatsErrors, Zt as CreateFunctionResponse, _ as createPrimitiveClient, _a as ReplyToEmailError, _i as ListEmailsError, _n as DeleteEndpointData, _o as TestFunctionResponses, _r as FunctionDetail, _t as Account, a as PrimitiveApiClientOptions, aa as ReplayDeliveryData, ai as Limit, an as CreateFunctionSecretResponses, ao as StartCliLoginResponses, ar as EmailSearchFacetBucket, as as ClientOptions$1, at as searchEmails, b as VerifyOptions, ba as ReplyToEmailResponses, bi as ListEmailsResponses, bn as DeleteEndpointResponse, bo as UnverifiedDomain, br as FunctionSecretListItem, bt as AddDomainError, c as PrimitiveClient, ca as ReplayDeliveryResponse, ci as ListDeliveriesErrors, cn as DeleteDomainError, co as TestEndpointData, cr as EmailSearchMeta, cs as Options$1, ct as startCliLogin, d as RequestOptions$1, da as ReplayEmailWebhooksError, di as ListDomainsData, dn as DeleteDomainResponses, do as TestEndpointResponse, dr as EmailSummary, ds as ResponseStyle, dt as updateAccount, ea as PollCliLoginError, ei as GetWebhookSecretData, en as CreateFunctionSecretData, eo as StartCliLoginData, er as DownloadRawEmailErrors, es as VerifyDomainErrors, et as pollCliLogin, f as SendInput, fa as ReplayEmailWebhooksErrors, fi as ListDomainsError, fn as DeleteEmailData, fo as TestEndpointResponses, fr as EmailWebhookStatus, fs as Auth, ft as updateDomain, g as createPrimitiveApiClient, ga as ReplyToEmailData, gi as ListEmailsData, gn as DeleteEmailResponses, go as TestFunctionResponse, gr as FunctionDeployStatus, gt as verifyDomain, h as client, ha as ReplayResult, hi as ListDomainsResponses, hn as DeleteEmailResponse, ho as TestFunctionErrors, hr as Filter, ht as updateFunction, i as PrimitiveApiClient, ia as PollCliLoginResponses, ii as GetWebhookSecretResponses, in as CreateFunctionSecretResponse, io as StartCliLoginResponse, ir as EmailDetailReply, is as Client, it as rotateWebhookSecret, j as deleteEndpoint, ja as SearchEmailsResponses, ji as ListFiltersResponses, jn as DeleteFunctionResponses, jo as UpdateDomainResponse, jr as GetEmailErrors, jt as CliLogoutResponse, k as deleteDomain, ka as SearchEmailsErrors, ki as ListFiltersErrors, kn as DeleteFunctionErrors, ko as UpdateDomainErrors, kr as GetEmailData, kt as CliLogoutErrors, l as PrimitiveClientOptions, la as ReplayDeliveryResponses, li as ListDeliveriesResponse, ln as DeleteDomainErrors, lo as TestEndpointError, lr as EmailSearchResult, ls as RequestOptions, lt as testEndpoint, m as SendThreadInput, ma as ReplayEmailWebhooksResponses, mi as ListDomainsResponse, mn as DeleteEmailErrors, mo as TestFunctionError, mr as ErrorResponse, mt as updateFilter, n as DEFAULT_API_BASE_URL_2, na as PollCliLoginInput, ni as GetWebhookSecretErrors, nn as CreateFunctionSecretErrors, no as StartCliLoginErrors, nr as DownloadRawEmailResponses, ns as VerifyDomainResponses, nt as replayEmailWebhooks, o as PrimitiveApiError, oa as ReplayDeliveryError, oi as ListDeliveriesData, on as Cursor, oo as StorageStats, or as EmailSearchFacets, os as Config, ot as sendEmail, p as SendResult, pa as ReplayEmailWebhooksResponse, pi as ListDomainsErrors, pn as DeleteEmailError, po as TestFunctionData, pr as Endpoint, pt as updateEndpoint, q as listEmails, qa as SentEmailSummary, qi as ListSentEmailsData, qn as DownloadAttachmentsData, qo as UpdateFunctionErrors, qr as GetSentEmailResponse, qt as CreateFunctionData, r as ForwardInput, ra as PollCliLoginResponse, ri as GetWebhookSecretResponse, rn as CreateFunctionSecretInput, ro as StartCliLoginInput, rr as EmailDetail, rs as WebhookSecret, rt as replyToEmail, s as PrimitiveApiErrorDetails, sa as ReplayDeliveryErrors, si as ListDeliveriesError, sn as DeleteDomainData, so as SuccessEnvelope, sr as EmailSearchHighlights, ss as CreateClientConfig, st as setFunctionSecret, t as DEFAULT_API_BASE_URL_1, ta as PollCliLoginErrors, ti as GetWebhookSecretError, tn as CreateFunctionSecretError, to as StartCliLoginError, tr as DownloadRawEmailResponse, ts as VerifyDomainResponse, tt as replayDelivery, u as ReplyInput, ua as ReplayEmailWebhooksData, ui as ListDeliveriesResponses, un as DeleteDomainResponse, uo as TestEndpointErrors, ur as EmailStatus, us as RequestResult, ut as testFunction, v as operations, va as ReplyToEmailErrors, vi as ListEmailsErrors, vn as DeleteEndpointError, vo as TestInvocationResult, vr as FunctionListItem, vt as AccountUpdated, w as cliLogout, wa as RotateWebhookSecretErrors, wi as ListEndpointsResponse, wn as DeleteFilterErrors, wo as UpdateAccountInput, wr as GetAccountData, wt as AddDomainResponses, x as verifyWebhookSignature, xa as ResourceId, xi as ListEndpointsData, xn as DeleteEndpointResponses, xo as UpdateAccountData, xr as FunctionSecretWriteResult, xt as AddDomainErrors, y as PRIMITIVE_SIGNATURE_HEADER, ya as ReplyToEmailResponse, yi as ListEmailsResponse, yn as DeleteEndpointErrors, yo as TestResult, yr as FunctionLogRow, yt as AddDomainData, z as getEmail, za as SendPermissionAddress, zi as ListFunctionSecretsErrors, zn as DiscardContentResult, zo as UpdateFilterData, zr as GetSendPermissionsData, zt as CreateEndpointResponse } from "../index-DISHEO_u.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, FunctionLogRow, 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, ListFunctionLogsData, ListFunctionLogsError, ListFunctionLogsErrors, ListFunctionLogsResponse, ListFunctionLogsResponses, 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, listFunctionLogs, 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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-pbuEa-1d.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as WebhookVerificationError, d as formatAddress } from "./errors-x91I_yEt.js";
|
|
3
3
|
//#region src/api/generated/core/bodySerializer.gen.ts
|
|
4
4
|
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
5
5
|
//#endregion
|
|
@@ -640,6 +640,7 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
|
|
|
640
640
|
listEmails: () => listEmails,
|
|
641
641
|
listEndpoints: () => listEndpoints,
|
|
642
642
|
listFilters: () => listFilters,
|
|
643
|
+
listFunctionLogs: () => listFunctionLogs,
|
|
643
644
|
listFunctionSecrets: () => listFunctionSecrets,
|
|
644
645
|
listFunctions: () => listFunctions,
|
|
645
646
|
listSentEmails: () => listSentEmails,
|
|
@@ -1650,6 +1651,167 @@ const setFunctionSecret = (options) => (options.client ?? client$1).put({
|
|
|
1650
1651
|
...options.headers
|
|
1651
1652
|
}
|
|
1652
1653
|
});
|
|
1654
|
+
/**
|
|
1655
|
+
* List a function's execution logs
|
|
1656
|
+
*
|
|
1657
|
+
* Returns the most recent `function_logs` rows for the function,
|
|
1658
|
+
* newest first. Each row is a single `console.log` / `console.error`
|
|
1659
|
+
* invocation captured from the running handler.
|
|
1660
|
+
*
|
|
1661
|
+
* Page through history with the opaque `cursor` returned as
|
|
1662
|
+
* `next_cursor`; pass it back as the `cursor` query param on the
|
|
1663
|
+
* next call. `next_cursor` is `null` when there are no further
|
|
1664
|
+
* rows. The cursor format is an implementation detail and should
|
|
1665
|
+
* not be parsed by callers.
|
|
1666
|
+
*
|
|
1667
|
+
*/
|
|
1668
|
+
const listFunctionLogs = (options) => (options.client ?? client$1).get({
|
|
1669
|
+
security: [{
|
|
1670
|
+
scheme: "bearer",
|
|
1671
|
+
type: "http"
|
|
1672
|
+
}],
|
|
1673
|
+
url: "/functions/{id}/logs",
|
|
1674
|
+
...options
|
|
1675
|
+
});
|
|
1676
|
+
//#endregion
|
|
1677
|
+
//#region src/api/verify-signature.ts
|
|
1678
|
+
/**
|
|
1679
|
+
* Workers-safe webhook signature verification.
|
|
1680
|
+
*
|
|
1681
|
+
* Mirrors `verifyWebhookSignature` from `@primitivedotdev/sdk` but
|
|
1682
|
+
* implements the HMAC-SHA256 step with the Web Crypto API
|
|
1683
|
+
* (`crypto.subtle`) instead of `node:crypto`. The Node version is
|
|
1684
|
+
* still the right choice for server-side handlers running on Node
|
|
1685
|
+
* (it's measurably faster and supports Buffer bodies); this one
|
|
1686
|
+
* exists so a Primitive Function handler can bundle the verifier
|
|
1687
|
+
* without dragging in a `node:crypto` polyfill that inflates the
|
|
1688
|
+
* deploy artifact past the size cap.
|
|
1689
|
+
*
|
|
1690
|
+
* Available natively in Workers, Node 22+, browsers, Deno, and Bun.
|
|
1691
|
+
* Zero polyfill weight, zero new runtime dependencies.
|
|
1692
|
+
*
|
|
1693
|
+
* Surface contract matches the Node verifier exactly: same input
|
|
1694
|
+
* shape, same `WebhookVerificationError` class, same set of error
|
|
1695
|
+
* codes. Existing callers can swap the import path with no other
|
|
1696
|
+
* code changes:
|
|
1697
|
+
*
|
|
1698
|
+
* // Node (existing):
|
|
1699
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk';
|
|
1700
|
+
*
|
|
1701
|
+
* // Workers / in-handler (this file):
|
|
1702
|
+
* import { verifyWebhookSignature } from '@primitivedotdev/sdk/api';
|
|
1703
|
+
*/
|
|
1704
|
+
const PRIMITIVE_SIGNATURE_HEADER = "Primitive-Signature";
|
|
1705
|
+
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
1706
|
+
const FUTURE_TOLERANCE_SECONDS = 60;
|
|
1707
|
+
const HEX_PATTERN = /^[0-9a-f]+$/i;
|
|
1708
|
+
const HEX_LENGTH = 64;
|
|
1709
|
+
const UNIX_SECONDS_PATTERN = /^\d{1,10}$/;
|
|
1710
|
+
function parseSignatureHeader(signatureHeader) {
|
|
1711
|
+
if (!signatureHeader || typeof signatureHeader !== "string") return null;
|
|
1712
|
+
const parts = signatureHeader.split(",");
|
|
1713
|
+
let timestamp = null;
|
|
1714
|
+
const signatures = [];
|
|
1715
|
+
for (const part of parts) {
|
|
1716
|
+
const idx = part.indexOf("=");
|
|
1717
|
+
if (idx === -1) continue;
|
|
1718
|
+
const key = part.slice(0, idx).trim();
|
|
1719
|
+
const value = part.slice(idx + 1).trim();
|
|
1720
|
+
if (!key || !value) continue;
|
|
1721
|
+
if (key === "t") {
|
|
1722
|
+
if (!UNIX_SECONDS_PATTERN.test(value)) continue;
|
|
1723
|
+
const parsed = Number(value);
|
|
1724
|
+
if (Number.isSafeInteger(parsed)) timestamp = parsed;
|
|
1725
|
+
} else if (key === "v1") signatures.push(value);
|
|
1726
|
+
}
|
|
1727
|
+
if (timestamp === null || signatures.length === 0) return null;
|
|
1728
|
+
return {
|
|
1729
|
+
timestamp,
|
|
1730
|
+
signatures
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
function isValidHex(str) {
|
|
1734
|
+
return str.length === HEX_LENGTH && HEX_PATTERN.test(str);
|
|
1735
|
+
}
|
|
1736
|
+
function arrayBufferToHex(buffer) {
|
|
1737
|
+
const bytes = new Uint8Array(buffer);
|
|
1738
|
+
let hex = "";
|
|
1739
|
+
for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
|
|
1740
|
+
return hex;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Constant-time comparison of two equal-length hex strings. Returns
|
|
1744
|
+
* false if lengths differ (intentionally not a security issue: lengths
|
|
1745
|
+
* are public). Iterates the full length regardless of mismatch so the
|
|
1746
|
+
* timing signal does not reveal the position of the first divergence.
|
|
1747
|
+
*/
|
|
1748
|
+
function timingSafeEqualHex(a, b) {
|
|
1749
|
+
if (a.length !== b.length) return false;
|
|
1750
|
+
let diff = 0;
|
|
1751
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1752
|
+
return diff === 0;
|
|
1753
|
+
}
|
|
1754
|
+
async function computeHmacHex(secret, payload) {
|
|
1755
|
+
const encoder = new TextEncoder();
|
|
1756
|
+
const keyData = encoder.encode(secret);
|
|
1757
|
+
const key = await crypto.subtle.importKey("raw", keyData, {
|
|
1758
|
+
name: "HMAC",
|
|
1759
|
+
hash: "SHA-256"
|
|
1760
|
+
}, false, ["sign"]);
|
|
1761
|
+
return arrayBufferToHex(await crypto.subtle.sign("HMAC", key, encoder.encode(payload)));
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Verify a webhook signature using the Web Crypto API.
|
|
1765
|
+
*
|
|
1766
|
+
* Throws `WebhookVerificationError` on failure with a specific error
|
|
1767
|
+
* code matching the Node verifier's set. Returns `true` on success.
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```typescript
|
|
1771
|
+
* import {
|
|
1772
|
+
* verifyWebhookSignature,
|
|
1773
|
+
* WebhookVerificationError,
|
|
1774
|
+
* PRIMITIVE_SIGNATURE_HEADER,
|
|
1775
|
+
* } from '@primitivedotdev/sdk/api';
|
|
1776
|
+
*
|
|
1777
|
+
* export default {
|
|
1778
|
+
* async fetch(request: Request, env: { PRIMITIVE_WEBHOOK_SECRET: string }) {
|
|
1779
|
+
* const rawBody = await request.text();
|
|
1780
|
+
* try {
|
|
1781
|
+
* await verifyWebhookSignature({
|
|
1782
|
+
* rawBody,
|
|
1783
|
+
* signatureHeader: request.headers.get(PRIMITIVE_SIGNATURE_HEADER) ?? '',
|
|
1784
|
+
* secret: env.PRIMITIVE_WEBHOOK_SECRET,
|
|
1785
|
+
* });
|
|
1786
|
+
* } catch (err) {
|
|
1787
|
+
* if (err instanceof WebhookVerificationError) {
|
|
1788
|
+
* return new Response('invalid signature', { status: 401 });
|
|
1789
|
+
* }
|
|
1790
|
+
* throw err;
|
|
1791
|
+
* }
|
|
1792
|
+
* // ... process the webhook
|
|
1793
|
+
* },
|
|
1794
|
+
* };
|
|
1795
|
+
* ```
|
|
1796
|
+
*/
|
|
1797
|
+
async function verifyWebhookSignature(opts) {
|
|
1798
|
+
const { rawBody, signatureHeader, secret, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS, nowSeconds } = opts;
|
|
1799
|
+
if (!secret) throw new WebhookVerificationError("MISSING_SECRET", "Webhook secret is required but was empty or not provided");
|
|
1800
|
+
const parsed = parseSignatureHeader(signatureHeader);
|
|
1801
|
+
if (!parsed) throw new WebhookVerificationError("INVALID_SIGNATURE_HEADER", "Invalid Primitive-Signature header format. Expected: t={timestamp},v1={signature}");
|
|
1802
|
+
const { timestamp, signatures } = parsed;
|
|
1803
|
+
const age = (nowSeconds ?? Math.floor(Date.now() / 1e3)) - timestamp;
|
|
1804
|
+
if (age > toleranceSeconds) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", `Webhook timestamp too old (${age}s). Max age is ${toleranceSeconds}s.`);
|
|
1805
|
+
if (age < -FUTURE_TOLERANCE_SECONDS) throw new WebhookVerificationError("TIMESTAMP_OUT_OF_RANGE", "Webhook timestamp is too far in the future. Check server clock sync.");
|
|
1806
|
+
const expectedHex = await computeHmacHex(secret, `${timestamp}.${rawBody}`);
|
|
1807
|
+
let anyMatch = false;
|
|
1808
|
+
for (const candidate of signatures) {
|
|
1809
|
+
if (!isValidHex(candidate)) continue;
|
|
1810
|
+
if (timingSafeEqualHex(candidate.toLowerCase(), expectedHex)) anyMatch = true;
|
|
1811
|
+
}
|
|
1812
|
+
if (!anyMatch) 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.");
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1653
1815
|
//#endregion
|
|
1654
1816
|
//#region src/api/index.ts
|
|
1655
1817
|
const DEFAULT_API_BASE_URL_1 = "https://www.primitive.dev/api/v1";
|
|
@@ -1939,4 +2101,4 @@ function client(options = {}) {
|
|
|
1939
2101
|
}
|
|
1940
2102
|
const operations = sdk_gen_exports;
|
|
1941
2103
|
//#endregion
|
|
1942
|
-
export {
|
|
2104
|
+
export { testFunction as $, getSendPermissions as A, listFunctionSecrets as B, deleteFunctionSecret as C, getAccount as D, downloadRawEmail as E, listDomains as F, replayEmailWebhooks as G, listSentEmails as H, listEmails as I, searchEmails as J, replyToEmail as K, listEndpoints as L, getStorageStats as M, getWebhookSecret as N, getEmail as O, listDeliveries as P, testEndpoint as Q, listFilters as R, deleteFunction as S, downloadAttachments as T, pollCliLogin as U, listFunctions as V, replayDelivery as W, setFunctionSecret as X, sendEmail as Y, startCliLogin as Z, createFunctionSecret as _, PrimitiveClient as a, verifyDomain as at, deleteEndpoint as b, createPrimitiveClient as c, verifyWebhookSignature as d, updateAccount as et, addDomain as f, createFunction as g, createFilter as h, PrimitiveApiError as i, updateFunction as it, getSentEmail as j, getFunction as k, operations as l, createEndpoint as m, DEFAULT_API_BASE_URL_2 as n, updateEndpoint as nt, client as o, cliLogout as p, rotateWebhookSecret as q, PrimitiveApiClient as r, updateFilter as rt, createPrimitiveApiClient as s, DEFAULT_API_BASE_URL_1 as t, updateDomain as tt, PRIMITIVE_SIGNATURE_HEADER as u, deleteDomain as v, discardEmailContent as w, deleteFilter as x, deleteEmail as y, listFunctionLogs as z };
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-
|
|
2
|
+
import { C as signStandardWebhooksPayload, h as WEBHOOK_VERSION, j as signWebhookPayload, k as SignResult, x as StandardWebhooksSignResult } from "../index-Dbx9udpX.js";
|
|
3
3
|
|
|
4
4
|
//#region src/contract/contract.d.ts
|
|
5
5
|
/** Maximum raw email size for inline inclusion (256 KB). */
|
package/dist/contract/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as signStandardWebhooksPayload, L as validateEmailReceivedEvent, M as signWebhookPayload, d as WEBHOOK_VERSION } from "../webhook-
|
|
1
|
+
import { E as signStandardWebhooksPayload, L as validateEmailReceivedEvent, M as signWebhookPayload, d as WEBHOOK_VERSION } from "../webhook-DJkfUnFZ.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
//#region src/contract/contract.ts
|
|
4
4
|
/**
|