@sinch/functions-runtime 0.7.3 → 0.7.4

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/index.d.ts CHANGED
@@ -3855,8 +3855,6 @@ export declare function getProtectionMode(config?: Record<string, unknown>): Web
3855
3855
  export declare function createSecurityOptions(config?: Record<string, unknown>): SecurityOptions;
3856
3856
  /** How far the `x-timestamp` header may sit from now before the request is treated as a replay. */
3857
3857
  export declare const VOICE_TIMESTAMP_SKEW_MS: number;
3858
- /** Warning emitted once per process while no service secret is configured. */
3859
- export declare const VOICE_MISSING_SECRET_WARNING: string;
3860
3858
  /** The parts of an inbound webhook the signature covers. */
3861
3859
  export interface VoiceSignedRequest {
3862
3860
  /** HTTP method, always `POST` for a webhook. */
@@ -3911,16 +3909,12 @@ export interface VoiceGateOptions {
3911
3909
  /** Environment to read credentials from. Defaults to `process.env`. */
3912
3910
  env?: NodeJS.ProcessEnv;
3913
3911
  }
3914
- /** Clear the once-per-process warning latch. @internal */
3915
- export declare function resetVoiceSignatureWarning(): void;
3916
3912
  /**
3917
3913
  * Decide whether a Voice v2 webhook may proceed.
3918
3914
  *
3919
- * Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks, with one deliberate
3920
- * exception: when the mode says validate but `VOICE_SERVICE_SECRET` is unset, the request is
3921
- * allowed and a single warning is logged. Deploying sets `VOICE_SERVICE_SECRET` from the
3922
- * function's voice service, so the gate is unverified only for local runs and for a deploy that
3923
- * could not read the service.
3915
+ * Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks. When the mode says validate
3916
+ * but `VOICE_SERVICE_SECRET` is unset, the request is rejected: the gate fails closed, because
3917
+ * an unsigned webhook cannot be told from a forged one.
3924
3918
  *
3925
3919
  * @param request - The request as delivered, raw body included
3926
3920
  * @param options - Protection mode, environment and clock
@@ -4027,6 +4021,8 @@ export declare const NOTIFICATION_EVENTS: readonly [
4027
4021
  ];
4028
4022
  /** The export a Voice v2 `call.*` event is delivered to @internal */
4029
4023
  export declare const VOICE_WEBHOOK_HANDLER = "voiceWebhook";
4024
+ /** The export a Conversation API callback is delivered to (`/webhook/conversation`) @internal */
4025
+ export declare const CONVERSATION_WEBHOOK_HANDLER = "conversationWebhook";
4030
4026
  export type VoiceV1Callback = (typeof VOICE_V1_CALLBACKS)[number];
4031
4027
  export type NotificationEvent = (typeof NOTIFICATION_EVENTS)[number];
4032
4028
  /**
@@ -4049,6 +4045,13 @@ export declare function isNotificationEvent(functionName: string): functionName
4049
4045
  * @internal
4050
4046
  */
4051
4047
  export declare function isVoiceWebhook(body: unknown): body is WebhookRequest;
4048
+ /**
4049
+ * Env var the tunnel client sets to the path of the voice webhook URL it registered on the
4050
+ * voice service (`/ingress`, no query). Its presence is what makes the Voice v2 signature
4051
+ * check use that path instead of the request's own. Unset outside `sinch functions dev`.
4052
+ * @internal
4053
+ */
4054
+ export declare const TUNNEL_VOICE_SIGNED_PATH_ENV = "SINCH_TUNNEL_VOICE_SIGNED_PATH";
4052
4055
  /**
4053
4056
  * Collect the parts of an Express request the Voice v2 signature covers.
4054
4057
  *
@@ -5785,6 +5788,41 @@ export declare function sessionCookieHeader(user: string, password: string): str
5785
5788
  export declare function clearedSessionCookieHeader(): string;
5786
5789
  /** Whether the `Cookie` header carries a valid session for this credential pair. */
5787
5790
  export declare function hasValidSessionCookie(cookieHeader: string | undefined, user: string, password: string): boolean;
5791
+ /** The parts of an inbound Conversation callback the signature covers. */
5792
+ export interface ConversationSignedRequest {
5793
+ /**
5794
+ * Request headers, names lowercased. The array case is there for the `IncomingHttpHeaders`
5795
+ * type: Node joins a repeated custom header with `, `, and only `set-cookie` is an array.
5796
+ */
5797
+ headers: Record<string, string | string[] | undefined>;
5798
+ /**
5799
+ * Raw request body, exactly as delivered. `undefined` when the host could not capture the raw
5800
+ * bytes, which is a validation failure with its own reason rather than a signature mismatch.
5801
+ */
5802
+ rawBody?: string;
5803
+ }
5804
+ /** How the caller's webhook protection mode and environment reach the gate. */
5805
+ export interface ConversationGateOptions {
5806
+ /** Protection mode, from `WEBHOOK_PROTECTION` (legacy `PROTECT_VOICE_CALLBACKS`). */
5807
+ mode: WebhookProtectionMode;
5808
+ /** Whether the host is running outside production. */
5809
+ isDevelopment: boolean;
5810
+ /** Environment to read the webhook secret from. Defaults to `process.env`. */
5811
+ env?: NodeJS.ProcessEnv;
5812
+ }
5813
+ /**
5814
+ * Decide whether a Conversation API callback may proceed.
5815
+ *
5816
+ * Gated by the same `WEBHOOK_PROTECTION` modes as the Voice callbacks. When the mode says
5817
+ * validate but `CONVERSATION_WEBHOOK_SECRET` is unset, the request is rejected: the gate fails
5818
+ * closed, because an unsigned webhook cannot be told from a forged one.
5819
+ *
5820
+ * @param request - The request as delivered, raw body included
5821
+ * @param options - Protection mode and environment
5822
+ * @returns Whether the request may proceed, with a log-safe reason when it may not. The reason
5823
+ * names a header or the failed step, never a header value, the body or the secret.
5824
+ */
5825
+ export declare function verifyConversationWebhook(request: ConversationSignedRequest, options: ConversationGateOptions): VoiceSignatureResult;
5788
5826
  /**
5789
5827
  * Set the credential values to redact, from `env`. Call it once the environment is final, and
5790
5828
  * again whenever a credential in it changes. Calling it with no credentials (`{}`) turns
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  AceSvamlBuilder,
9
9
  AgentProvider,
10
10
  AgentSipHelper,
11
+ CONVERSATION_WEBHOOK_HANDLER,
11
12
  Client,
12
13
  CommandBuilder,
13
14
  ConversationController,
@@ -29,10 +30,10 @@ import {
29
30
  SESSION_COOKIE_NAME,
30
31
  SecretsLoader,
31
32
  TUNNEL_PUBLIC_URL_ENV,
33
+ TUNNEL_VOICE_SIGNED_PATH_ENV,
32
34
  TemplateRender,
33
35
  TunnelClient,
34
36
  UniversalConfig,
35
- VOICE_MISSING_SECRET_WARNING,
36
37
  VOICE_TIMESTAMP_SKEW_MS,
37
38
  VOICE_V1_CALLBACKS,
38
39
  VOICE_WEBHOOK_HANDLER,
@@ -125,7 +126,6 @@ import {
125
126
  redactSecrets,
126
127
  renderLoginPage,
127
128
  resetSinchClients,
128
- resetVoiceSignatureWarning,
129
129
  resolveAgentStreamUrl,
130
130
  rewriteRecordingSentinels,
131
131
  safeCut,
@@ -147,15 +147,17 @@ import {
147
147
  validateBasicAuth,
148
148
  validateVoiceSignature,
149
149
  validateVoiceV1Request,
150
+ verifyConversationWebhook,
150
151
  verifyVoiceWebhook,
151
152
  voiceRelay
152
- } from "./chunk-KCLRM3MM.js";
153
+ } from "./chunk-ZM72YQUN.js";
153
154
  export {
154
155
  AGENT_HEADER_TOKEN,
155
156
  AGENT_STREAM_PATH,
156
157
  AceSvamlBuilder,
157
158
  AgentProvider,
158
159
  AgentSipHelper,
160
+ CONVERSATION_WEBHOOK_HANDLER,
159
161
  Client,
160
162
  CommandBuilder,
161
163
  ConversationController,
@@ -177,10 +179,10 @@ export {
177
179
  SESSION_COOKIE_NAME,
178
180
  SecretsLoader,
179
181
  TUNNEL_PUBLIC_URL_ENV,
182
+ TUNNEL_VOICE_SIGNED_PATH_ENV,
180
183
  TemplateRender,
181
184
  TunnelClient,
182
185
  UniversalConfig,
183
- VOICE_MISSING_SECRET_WARNING,
184
186
  VOICE_TIMESTAMP_SKEW_MS,
185
187
  VOICE_V1_CALLBACKS,
186
188
  VOICE_WEBHOOK_HANDLER,
@@ -276,7 +278,6 @@ export {
276
278
  redactSecrets,
277
279
  renderLoginPage,
278
280
  resetSinchClients,
279
- resetVoiceSignatureWarning,
280
281
  resolveAgentStreamUrl,
281
282
  rewriteRecordingSentinels,
282
283
  safeCut,
@@ -300,6 +301,7 @@ export {
300
301
  validateBasicAuth,
301
302
  validateVoiceSignature,
302
303
  validateVoiceV1Request,
304
+ verifyConversationWebhook,
303
305
  verifyVoiceWebhook,
304
306
  voiceRelay
305
307
  };
package/dist/voice/v2.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  toWebhookRequest,
43
43
  tool,
44
44
  voiceRelay
45
- } from "../chunk-KCLRM3MM.js";
45
+ } from "../chunk-ZM72YQUN.js";
46
46
  export {
47
47
  Client,
48
48
  CommandBuilder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinch/functions-runtime",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Node.js SDK and local development runtime for Sinch Functions: voice, messaging and HTTP serverless functions",
5
5
  "type": "module",
6
6
  "exports": {