@sinch/functions-runtime 0.7.2 → 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
@@ -994,10 +994,23 @@ export interface IFunctionStorage {
994
994
  * @param callId - The call the recording belongs to
995
995
  * @param format - Lowercase file extension, `mp3` or `wav`
996
996
  */
997
+ /**
998
+ * The presigned PUT URL for `recordings/<callId>.<format>`: the same URL the host swaps in for
999
+ * `recordToFunctions()`. Use it to pass your own `startRecording({ destinationUrl })` (or any
1000
+ * recording command) the function's storage as the destination. Optional like
1001
+ * `getRecordingDestination`; the built-in dev and production storage both provide it.
1002
+ *
1003
+ * @param callId - The call the recording belongs to
1004
+ * @param format - `mp3` (default) or `wav`, any case
1005
+ * @throws On an unsupported format, or when no URL can be produced (dev without a tunnel)
1006
+ */
1007
+ recordingUrl?(callId: string, format?: string): Promise<string>;
997
1008
  getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
998
1009
  }
999
1010
  /** Where the dev runtime receives Sinch's recording upload (`PUT <path><callId>.<format>`). */
1000
1011
  export declare const RECORDING_RECEIVER_PATH = "/_sinch/recording/";
1012
+ /** Lowercase a recording format and reject anything but `mp3` or `wav`. */
1013
+ export declare function normalizeRecordingFormat(format: string): "mp3" | "wav";
1001
1014
  /**
1002
1015
  * The storage key for a call's recording, `recordings/<callId>.<format>`, with anything outside
1003
1016
  * `[\w-]` in the callId replaced so it cannot leave `recordings/`.
@@ -3842,8 +3855,6 @@ export declare function getProtectionMode(config?: Record<string, unknown>): Web
3842
3855
  export declare function createSecurityOptions(config?: Record<string, unknown>): SecurityOptions;
3843
3856
  /** How far the `x-timestamp` header may sit from now before the request is treated as a replay. */
3844
3857
  export declare const VOICE_TIMESTAMP_SKEW_MS: number;
3845
- /** Warning emitted once per process while no service secret is configured. */
3846
- export declare const VOICE_MISSING_SECRET_WARNING: string;
3847
3858
  /** The parts of an inbound webhook the signature covers. */
3848
3859
  export interface VoiceSignedRequest {
3849
3860
  /** HTTP method, always `POST` for a webhook. */
@@ -3898,16 +3909,12 @@ export interface VoiceGateOptions {
3898
3909
  /** Environment to read credentials from. Defaults to `process.env`. */
3899
3910
  env?: NodeJS.ProcessEnv;
3900
3911
  }
3901
- /** Clear the once-per-process warning latch. @internal */
3902
- export declare function resetVoiceSignatureWarning(): void;
3903
3912
  /**
3904
3913
  * Decide whether a Voice v2 webhook may proceed.
3905
3914
  *
3906
- * Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks, with one deliberate
3907
- * exception: when the mode says validate but `VOICE_SERVICE_SECRET` is unset, the request is
3908
- * allowed and a single warning is logged. Deploying sets `VOICE_SERVICE_SECRET` from the
3909
- * function's voice service, so the gate is unverified only for local runs and for a deploy that
3910
- * 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.
3911
3918
  *
3912
3919
  * @param request - The request as delivered, raw body included
3913
3920
  * @param options - Protection mode, environment and clock
@@ -4014,6 +4021,8 @@ export declare const NOTIFICATION_EVENTS: readonly [
4014
4021
  ];
4015
4022
  /** The export a Voice v2 `call.*` event is delivered to @internal */
4016
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";
4017
4026
  export type VoiceV1Callback = (typeof VOICE_V1_CALLBACKS)[number];
4018
4027
  export type NotificationEvent = (typeof NOTIFICATION_EVENTS)[number];
4019
4028
  /**
@@ -4036,6 +4045,13 @@ export declare function isNotificationEvent(functionName: string): functionName
4036
4045
  * @internal
4037
4046
  */
4038
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";
4039
4055
  /**
4040
4056
  * Collect the parts of an Express request the Voice v2 signature covers.
4041
4057
  *
@@ -4119,7 +4135,7 @@ export declare function handleVoiceWebhook(userFunction: SinchFunction, context:
4119
4135
  * whose `destinationUrl` is {@link RECORD_TO_FUNCTIONS_SENTINEL}. This walks the finished
4120
4136
  * webhook body (the command can sit inside any nested flow), asks the storage for a URL for the
4121
4137
  * exact key `recordings/<callId>.<format>`, and writes it in. Where that is impossible — no
4122
- * callId, storage without `getRecordingDestination`, or it throws — the command is removed and
4138
+ * callId, storage with neither `recordingUrl` nor `getRecordingDestination`, or it throws — the command is removed and
4123
4139
  * a warning logged, so the placeholder never reaches Sinch.
4124
4140
  * @internal
4125
4141
  */
@@ -5772,6 +5788,41 @@ export declare function sessionCookieHeader(user: string, password: string): str
5772
5788
  export declare function clearedSessionCookieHeader(): string;
5773
5789
  /** Whether the `Cookie` header carries a valid session for this credential pair. */
5774
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;
5775
5826
  /**
5776
5827
  * Set the credential values to redact, from `env`. Call it once the environment is final, and
5777
5828
  * again whenever a credential in it changes. Calling it with no credentials (`{}`) turns
@@ -6023,6 +6074,8 @@ export declare class LocalStorage implements IFunctionStorage {
6023
6074
  * `PUT /_sinch/recording/:file` receiver (RECORDING_RECEIVER_PATH) over the tunnel, which writes into `recordings/`.
6024
6075
  */
6025
6076
  getRecordingDestination(callId: string, format: "mp3" | "wav"): Promise<string>;
6077
+ /** The URL `recordToFunctions()` records to; see {@link IFunctionStorage.recordingUrl}. */
6078
+ recordingUrl(callId: string, format?: string): Promise<string>;
6026
6079
  write(key: string, data: string | Buffer): Promise<void>;
6027
6080
  read(key: string): Promise<Buffer>;
6028
6081
  list(prefix?: string): Promise<string[]>;
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,
@@ -116,6 +117,7 @@ import {
116
117
  isTextMessage,
117
118
  isVoiceV1Callback,
118
119
  isVoiceWebhook,
120
+ normalizeRecordingFormat,
119
121
  onCall,
120
122
  parseJson,
121
123
  realtimeAgent,
@@ -124,7 +126,6 @@ import {
124
126
  redactSecrets,
125
127
  renderLoginPage,
126
128
  resetSinchClients,
127
- resetVoiceSignatureWarning,
128
129
  resolveAgentStreamUrl,
129
130
  rewriteRecordingSentinels,
130
131
  safeCut,
@@ -146,15 +147,17 @@ import {
146
147
  validateBasicAuth,
147
148
  validateVoiceSignature,
148
149
  validateVoiceV1Request,
150
+ verifyConversationWebhook,
149
151
  verifyVoiceWebhook,
150
152
  voiceRelay
151
- } from "./chunk-KGCIUPCT.js";
153
+ } from "./chunk-ZM72YQUN.js";
152
154
  export {
153
155
  AGENT_HEADER_TOKEN,
154
156
  AGENT_STREAM_PATH,
155
157
  AceSvamlBuilder,
156
158
  AgentProvider,
157
159
  AgentSipHelper,
160
+ CONVERSATION_WEBHOOK_HANDLER,
158
161
  Client,
159
162
  CommandBuilder,
160
163
  ConversationController,
@@ -176,10 +179,10 @@ export {
176
179
  SESSION_COOKIE_NAME,
177
180
  SecretsLoader,
178
181
  TUNNEL_PUBLIC_URL_ENV,
182
+ TUNNEL_VOICE_SIGNED_PATH_ENV,
179
183
  TemplateRender,
180
184
  TunnelClient,
181
185
  UniversalConfig,
182
- VOICE_MISSING_SECRET_WARNING,
183
186
  VOICE_TIMESTAMP_SKEW_MS,
184
187
  VOICE_V1_CALLBACKS,
185
188
  VOICE_WEBHOOK_HANDLER,
@@ -265,6 +268,7 @@ export {
265
268
  isTextMessage,
266
269
  isVoiceV1Callback,
267
270
  isVoiceWebhook,
271
+ normalizeRecordingFormat,
268
272
  onCall,
269
273
  parseJson,
270
274
  parseJson as parseJsonLenient,
@@ -274,7 +278,6 @@ export {
274
278
  redactSecrets,
275
279
  renderLoginPage,
276
280
  resetSinchClients,
277
- resetVoiceSignatureWarning,
278
281
  resolveAgentStreamUrl,
279
282
  rewriteRecordingSentinels,
280
283
  safeCut,
@@ -298,6 +301,7 @@ export {
298
301
  validateBasicAuth,
299
302
  validateVoiceSignature,
300
303
  validateVoiceV1Request,
304
+ verifyConversationWebhook,
301
305
  verifyVoiceWebhook,
302
306
  voiceRelay
303
307
  };
@@ -266,6 +266,17 @@ interface IFunctionStorage {
266
266
  * @param callId - The call the recording belongs to
267
267
  * @param format - Lowercase file extension, `mp3` or `wav`
268
268
  */
269
+ /**
270
+ * The presigned PUT URL for `recordings/<callId>.<format>`: the same URL the host swaps in for
271
+ * `recordToFunctions()`. Use it to pass your own `startRecording({ destinationUrl })` (or any
272
+ * recording command) the function's storage as the destination. Optional like
273
+ * `getRecordingDestination`; the built-in dev and production storage both provide it.
274
+ *
275
+ * @param callId - The call the recording belongs to
276
+ * @param format - `mp3` (default) or `wav`, any case
277
+ * @throws On an unsupported format, or when no URL can be produced (dev without a tunnel)
278
+ */
279
+ recordingUrl?(callId: string, format?: string): Promise<string>;
269
280
  getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
270
281
  }
271
282
  interface ClientContext {
package/dist/voice/v2.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  toWebhookRequest,
43
43
  tool,
44
44
  voiceRelay
45
- } from "../chunk-KGCIUPCT.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.2",
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": {