@samva/webhooks 0.35.0 → 0.37.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.
@@ -67,29 +67,12 @@ export interface VerifyWebhookInput {
67
67
  /** The current time in Unix milliseconds, as `Date.now()` returns it. */
68
68
  readonly nowMilliseconds: number;
69
69
  }
70
- /**
71
- * Signature scheme version inside a `webhook-signature` entry: `v1` is HMAC-SHA256 with the
72
- * endpoint's shared secret; `v2` is RSASSA-PKCS1-v1_5 with SHA-256, checked against a public key.
73
- */
74
- export type WebhookSignatureVersion = "v1" | "v2";
75
70
  /**
76
71
  * Creates a random `whsec_`-prefixed signing secret from the runtime's secure random source.
77
72
  * Samva issues each endpoint's secret for you; use this to sign test deliveries with
78
73
  * {@link signWebhook}.
79
74
  */
80
75
  export declare const generateWebhookSecret: () => string;
81
- /**
82
- * Builds the bytes every signature version covers: `<id>.<timestamp>.<body>`. Use it to verify a
83
- * signature with your own crypto code; {@link verifyWebhookAt} and
84
- * {@link verifyWebhookAtWithPublicKeys} build it for you.
85
- */
86
- export declare const webhookSignedContent: (input: {
87
- readonly id: string;
88
- readonly timestamp: string;
89
- readonly body: string | Uint8Array;
90
- }) => Uint8Array;
91
- /** Formats raw signature bytes as one `<version>,<base64>` entry of the `webhook-signature` header. */
92
- export declare const encodeWebhookSignature: (version: WebhookSignatureVersion, signature: Uint8Array) => string;
93
76
  /**
94
77
  * Computes the `v1` HMAC-SHA256 signature Samva sends, formatted as one `webhook-signature`
95
78
  * entry. Use it to produce signed test deliveries for your handler.
@@ -120,18 +103,6 @@ export declare const signWebhook: (input: {
120
103
  * {@link MalformedWebhookPayloadError}, or {@link WebhookCryptoError}.
121
104
  */
122
105
  export declare const verifyWebhookAt: (input: VerifyWebhookInput) => Promise<VerifiedWebhook>;
123
- /**
124
- * Verifies a `v2` (RSASSA-PKCS1-v1_5, SHA-256) delivery against one or more public keys, each a
125
- * Base64-encoded SPKI DER key. Pass several keys during a key rotation; the delivery verifies when
126
- * any `v2` signature entry matches any key.
127
- *
128
- * Header, timestamp, and envelope checks match {@link verifyWebhookAt}. Keys that fail to import
129
- * are skipped. Rejects with {@link WebhookSignatureError} when `publicKeys` is empty or nothing
130
- * matches, and {@link WebhookCryptoError} when none of the keys imports.
131
- */
132
- export declare const verifyWebhookAtWithPublicKeys: (input: Omit<VerifyWebhookInput, "secret"> & {
133
- readonly publicKeys: ReadonlyArray<string>;
134
- }) => Promise<VerifiedWebhook>;
135
106
  /**
136
107
  * Reads the three signing headers from a Fetch API `Headers` object, for code that needs a header
137
108
  * value, such as the timestamp, before or beside verification. Throws
package/dist/protocol.js CHANGED
@@ -1 +1 @@
1
- export { t as DEFAULT_TOLERANCE_SECONDS, f as InvalidWebhookHeadersError, p as InvalidWebhookSecretError, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, r as WEBHOOK_SIGNATURE_HEADER, i as WEBHOOK_TIMESTAMP_HEADER, h as WebhookCryptoError, g as WebhookSignatureError, _ as WebhookTimestampError, v as WebhookVerificationError, a as encodeWebhookSignature, o as generateWebhookSecret, y as isKnownEvent, s as readWebhookHeaders, c as signWebhook, l as verifyWebhookAt, u as verifyWebhookAtWithPublicKeys, d as webhookSignedContent } from "./protocol-D6py4UMl.js";
1
+ export { t as DEFAULT_TOLERANCE_SECONDS, l as InvalidWebhookHeadersError, u as InvalidWebhookSecretError, d as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, r as WEBHOOK_SIGNATURE_HEADER, i as WEBHOOK_TIMESTAMP_HEADER, f as WebhookCryptoError, p as WebhookSignatureError, m as WebhookTimestampError, h as WebhookVerificationError, a as generateWebhookSecret, g as isKnownEvent, o as readWebhookHeaders, s as signWebhook, c as verifyWebhookAt } from "./protocol-IJ8lllqW.js";
@@ -810,6 +810,26 @@ export declare const DomainWarmingUpdatedEventSchema: Schema.StructWithRest<Sche
810
810
  readonly updatedAt: Schema.String;
811
811
  }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
812
812
  }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
813
+ export declare const EmailSendingPausedEventSchema: Schema.StructWithRest<Schema.Struct<{
814
+ readonly type: Schema.Literal<"email.sending.paused">;
815
+ readonly timestamp: Schema.String;
816
+ readonly data: Schema.StructWithRest<Schema.Struct<{
817
+ readonly organizationId: Schema.String;
818
+ readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
819
+ readonly channel: Schema.Literal<"email">;
820
+ readonly occurredAt: Schema.String;
821
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
822
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
823
+ export declare const EmailSendingResumedEventSchema: Schema.StructWithRest<Schema.Struct<{
824
+ readonly type: Schema.Literal<"email.sending.resumed">;
825
+ readonly timestamp: Schema.String;
826
+ readonly data: Schema.StructWithRest<Schema.Struct<{
827
+ readonly organizationId: Schema.String;
828
+ readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
829
+ readonly channel: Schema.Literal<"email">;
830
+ readonly occurredAt: Schema.String;
831
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
832
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
813
833
  export declare const TemplateRegistrationUpdatedEventSchema: Schema.StructWithRest<Schema.Struct<{
814
834
  readonly type: Schema.Literal<"template.registration.updated">;
815
835
  readonly timestamp: Schema.String;
@@ -982,15 +1002,45 @@ export declare const MailboxActionPendingApprovalEventSchema: Schema.StructWithR
982
1002
  readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
983
1003
  readonly action: Schema.StructWithRest<Schema.Struct<{
984
1004
  readonly id: Schema.String;
985
- readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall"]>;
1005
+ readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall", "handoff"]>;
1006
+ readonly reviewRound: Schema.Int;
986
1007
  readonly state: Schema.optionalKey<Schema.Literal<"approvalRequired">>;
987
- readonly decision: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{
988
- readonly outcome: Schema.Literals<readonly ["allow", "requireApproval", "deny"]>;
989
- readonly reason: Schema.Union<readonly [Schema.String, Schema.Null]>;
990
- readonly policyId: Schema.Union<readonly [Schema.String, Schema.Null]>;
991
- readonly source: Schema.Union<readonly [Schema.Literals<readonly ["grant", "installation", "policy"]>, Schema.Null]>;
992
- readonly decidedAt: Schema.String;
993
- }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
1008
+ readonly decision: Schema.StructWithRest<Schema.Struct<{
1009
+ readonly id: Schema.String;
1010
+ readonly reviewRound: Schema.Int;
1011
+ readonly requirement: Schema.Literals<readonly ["run", "model", "person", "never"]>;
1012
+ readonly decider: Schema.Literals<readonly ["rule", "model", "person", "agent"]>;
1013
+ readonly outcome: Schema.Literals<readonly ["allow", "hold", "refuse"]>;
1014
+ readonly reason: Schema.String;
1015
+ readonly scopes: Schema.$Array<Schema.StructWithRest<Schema.Struct<{
1016
+ readonly kind: Schema.Literals<readonly ["organization", "mailbox", "agent", "apiKey"]>;
1017
+ readonly id: Schema.String;
1018
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
1019
+ readonly rule: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
1020
+ readonly scope: Schema.StructWithRest<Schema.Struct<{
1021
+ readonly kind: Schema.Literals<readonly ["organization", "mailbox", "agent", "apiKey"]>;
1022
+ readonly id: Schema.String;
1023
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
1024
+ readonly index: Schema.Int;
1025
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
1026
+ readonly guard: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.Null]>>;
1027
+ readonly guardReason: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.Null]>>;
1028
+ readonly resolution: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
1029
+ readonly by: Schema.String;
1030
+ readonly at: Schema.String;
1031
+ readonly as: Schema.Literals<readonly ["approved", "edited", "denied", "alwaysAllowed"]>;
1032
+ readonly diff: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
1033
+ readonly text: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
1034
+ readonly before: Schema.Union<readonly [Schema.String, Schema.Null]>;
1035
+ readonly after: Schema.Union<readonly [Schema.String, Schema.Null]>;
1036
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
1037
+ readonly html: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
1038
+ readonly before: Schema.Union<readonly [Schema.String, Schema.Null]>;
1039
+ readonly after: Schema.Union<readonly [Schema.String, Schema.Null]>;
1040
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
1041
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
1042
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
1043
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
994
1044
  readonly threadId: Schema.Union<readonly [Schema.String, Schema.Null]>;
995
1045
  readonly reason: Schema.Union<readonly [Schema.String, Schema.Null]>;
996
1046
  readonly proposedBy: Schema.StructWithRest<Schema.Struct<{
@@ -1021,7 +1071,8 @@ export declare const MailboxActionResolvedEventSchema: Schema.StructWithRest<Sch
1021
1071
  readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
1022
1072
  readonly action: Schema.StructWithRest<Schema.Struct<{
1023
1073
  readonly id: Schema.String;
1024
- readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall"]>;
1074
+ readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall", "handoff"]>;
1075
+ readonly reviewRound: Schema.Int;
1025
1076
  readonly threadId: Schema.Union<readonly [Schema.String, Schema.Null]>;
1026
1077
  readonly proposedBy: Schema.StructWithRest<Schema.Struct<{
1027
1078
  readonly kind: Schema.Literals<readonly ["user", "apiKey", "extension", "externalAgent", "samvaAgent", "system"]>;
@@ -1987,6 +2038,24 @@ export declare const SamvaWebhookEventSchema: Schema.Union<readonly [Schema.Stru
1987
2038
  }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>;
1988
2039
  readonly updatedAt: Schema.String;
1989
2040
  }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
2041
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.StructWithRest<Schema.Struct<{
2042
+ readonly type: Schema.Literal<"email.sending.paused">;
2043
+ readonly timestamp: Schema.String;
2044
+ readonly data: Schema.StructWithRest<Schema.Struct<{
2045
+ readonly organizationId: Schema.String;
2046
+ readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2047
+ readonly channel: Schema.Literal<"email">;
2048
+ readonly occurredAt: Schema.String;
2049
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
2050
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.StructWithRest<Schema.Struct<{
2051
+ readonly type: Schema.Literal<"email.sending.resumed">;
2052
+ readonly timestamp: Schema.String;
2053
+ readonly data: Schema.StructWithRest<Schema.Struct<{
2054
+ readonly organizationId: Schema.String;
2055
+ readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2056
+ readonly channel: Schema.Literal<"email">;
2057
+ readonly occurredAt: Schema.String;
2058
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
1990
2059
  }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.StructWithRest<Schema.Struct<{
1991
2060
  readonly type: Schema.Literal<"template.registration.updated">;
1992
2061
  readonly timestamp: Schema.String;
@@ -2154,15 +2223,45 @@ export declare const SamvaWebhookEventSchema: Schema.Union<readonly [Schema.Stru
2154
2223
  readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2155
2224
  readonly action: Schema.StructWithRest<Schema.Struct<{
2156
2225
  readonly id: Schema.String;
2157
- readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall"]>;
2226
+ readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall", "handoff"]>;
2227
+ readonly reviewRound: Schema.Int;
2158
2228
  readonly state: Schema.optionalKey<Schema.Literal<"approvalRequired">>;
2159
- readonly decision: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{
2160
- readonly outcome: Schema.Literals<readonly ["allow", "requireApproval", "deny"]>;
2161
- readonly reason: Schema.Union<readonly [Schema.String, Schema.Null]>;
2162
- readonly policyId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2163
- readonly source: Schema.Union<readonly [Schema.Literals<readonly ["grant", "installation", "policy"]>, Schema.Null]>;
2164
- readonly decidedAt: Schema.String;
2165
- }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
2229
+ readonly decision: Schema.StructWithRest<Schema.Struct<{
2230
+ readonly id: Schema.String;
2231
+ readonly reviewRound: Schema.Int;
2232
+ readonly requirement: Schema.Literals<readonly ["run", "model", "person", "never"]>;
2233
+ readonly decider: Schema.Literals<readonly ["rule", "model", "person", "agent"]>;
2234
+ readonly outcome: Schema.Literals<readonly ["allow", "hold", "refuse"]>;
2235
+ readonly reason: Schema.String;
2236
+ readonly scopes: Schema.$Array<Schema.StructWithRest<Schema.Struct<{
2237
+ readonly kind: Schema.Literals<readonly ["organization", "mailbox", "agent", "apiKey"]>;
2238
+ readonly id: Schema.String;
2239
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>;
2240
+ readonly rule: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
2241
+ readonly scope: Schema.StructWithRest<Schema.Struct<{
2242
+ readonly kind: Schema.Literals<readonly ["organization", "mailbox", "agent", "apiKey"]>;
2243
+ readonly id: Schema.String;
2244
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
2245
+ readonly index: Schema.Int;
2246
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
2247
+ readonly guard: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.Null]>>;
2248
+ readonly guardReason: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.Null]>>;
2249
+ readonly resolution: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
2250
+ readonly by: Schema.String;
2251
+ readonly at: Schema.String;
2252
+ readonly as: Schema.Literals<readonly ["approved", "edited", "denied", "alwaysAllowed"]>;
2253
+ readonly diff: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
2254
+ readonly text: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
2255
+ readonly before: Schema.Union<readonly [Schema.String, Schema.Null]>;
2256
+ readonly after: Schema.Union<readonly [Schema.String, Schema.Null]>;
2257
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
2258
+ readonly html: Schema.optionalKey<Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
2259
+ readonly before: Schema.Union<readonly [Schema.String, Schema.Null]>;
2260
+ readonly after: Schema.Union<readonly [Schema.String, Schema.Null]>;
2261
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
2262
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
2263
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>, Schema.Null]>>;
2264
+ }>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
2166
2265
  readonly threadId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2167
2266
  readonly reason: Schema.Union<readonly [Schema.String, Schema.Null]>;
2168
2267
  readonly proposedBy: Schema.StructWithRest<Schema.Struct<{
@@ -2192,7 +2291,8 @@ export declare const SamvaWebhookEventSchema: Schema.Union<readonly [Schema.Stru
2192
2291
  readonly namespaceId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2193
2292
  readonly action: Schema.StructWithRest<Schema.Struct<{
2194
2293
  readonly id: Schema.String;
2195
- readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall"]>;
2294
+ readonly type: Schema.Literals<readonly ["sendMessage", "reply", "updateDraft", "createNote", "assignThread", "changeThreadState", "call", "extensionRequest", "toolCall", "handoff"]>;
2295
+ readonly reviewRound: Schema.Int;
2196
2296
  readonly threadId: Schema.Union<readonly [Schema.String, Schema.Null]>;
2197
2297
  readonly proposedBy: Schema.StructWithRest<Schema.Struct<{
2198
2298
  readonly kind: Schema.Literals<readonly ["user", "apiKey", "extension", "externalAgent", "samvaAgent", "system"]>;