@sinch/functions-runtime 0.5.19 → 0.5.20

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
@@ -2190,6 +2190,12 @@ export interface Options {
2190
2190
  keyId?: string;
2191
2191
  /** Access Key Secret (Basic auth password). Defaults to `PROJECT_ID_API_SECRET`. */
2192
2192
  keySecret?: string;
2193
+ /**
2194
+ * Voice service id to route outbound calls through, including which webhook handles them.
2195
+ * Defaults to `VOICE_SERVICE_ID`. Without one, calls go through the project's default
2196
+ * service instead of the one the function configured.
2197
+ */
2198
+ serviceId?: string;
2193
2199
  /** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
2194
2200
  host?: string;
2195
2201
  /** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
@@ -2975,11 +2981,14 @@ export type NotifyHandler = (context: FunctionContext, callbackData: NotifyCallb
2975
2981
  /**
2976
2982
  * Voice API v2 webhook handler — the `voiceWebhook` export.
2977
2983
  *
2978
- * Receives the parsed CloudEvents body, not a `FunctionRequest`: v2 posts one event shape to
2979
- * one URL, so there is nothing to route on inside the handler. Return a plan, a command list
2980
- * or a `commands()` builder and the host emits the wire body; return nothing for a `204`.
2984
+ * Receives the parsed CloudEvents body, not a `FunctionRequest`, as its routing argument: v2
2985
+ * posts one event shape to one URL, so there is nothing to route on inside the handler. The
2986
+ * raw `FunctionRequest` still reaches the handler as a third argument — headers, path, the
2987
+ * unparsed body — for the rare case a handler needs something the parsed event dropped.
2988
+ * Return a plan, a command list or a `commands()` builder and the host emits the wire body;
2989
+ * return nothing for a `204`.
2981
2990
  */
2982
- export type VoiceWebhookHandler = (context: FunctionContext, event: WebhookRequest) => HandlerResult | Promise<HandlerResult>;
2991
+ export type VoiceWebhookHandler = (context: FunctionContext, event: WebhookRequest, request?: FunctionRequest) => HandlerResult | Promise<HandlerResult>;
2983
2992
  /**
2984
2993
  * Voice function export structure
2985
2994
  *
@@ -3412,7 +3421,7 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
3412
3421
  * `@sinch/agents` does — is emitted untouched.
3413
3422
  * @internal
3414
3423
  */
3415
- export declare function handleVoiceWebhook(userFunction: SinchFunction, context: FunctionContext, event: WebhookRequest, logger?: (...args: unknown[]) => void): Promise<FormattedResponse>;
3424
+ export declare function handleVoiceWebhook(userFunction: SinchFunction, context: FunctionContext, event: WebhookRequest, request?: FunctionRequest, logger?: (...args: unknown[]) => void): Promise<FormattedResponse>;
3416
3425
  /**
3417
3426
  * Handle custom endpoint execution
3418
3427
  * @internal
@@ -4361,13 +4370,45 @@ export declare function extractCallerNumber(cli: string | undefined): string | u
4361
4370
  export declare function attachVoiceClient<T extends object>(context: T, v1?: VoiceService): T & {
4362
4371
  voice: VoiceClient;
4363
4372
  };
4373
+ /**
4374
+ * A single `onCall` handler slot.
4375
+ *
4376
+ * Same as `@sinch/voice-v2-preview`'s `WebhookHandler`, but the event is followed by the
4377
+ * function context and the raw `FunctionRequest` — every other runtime handler gets both, and
4378
+ * a v2 handler that wants `context.cache`, `context.messaging`, `context.storage`, etc. needs
4379
+ * them too. Event stays first so a handler written as `(event) => ...` before this widening
4380
+ * still compiles.
4381
+ */
4382
+ export type VoiceCallHandler = (event: WebhookRequest, context: FunctionContext, request?: FunctionRequest) => ReturnType<WebhookHandler>;
4383
+ /**
4384
+ * Handlers keyed by call lifecycle stage — the shape `onCall()` takes.
4385
+ *
4386
+ * Same slots as `@sinch/voice-v2-preview`'s `CallHandlers`, widened so each handler also
4387
+ * receives the function context (and the raw request) the way every other runtime handler
4388
+ * does. Named separately from `CallHandlers` — re-exported from this package as-is for anyone
4389
+ * calling `context.voice.onCall` directly — so the two shapes don't collide.
4390
+ */
4391
+ export interface VoiceCallHandlers {
4392
+ /** `call.incoming` — an inbound call arrived (the v1 ICE callback) */
4393
+ incoming?: VoiceCallHandler;
4394
+ /** `call.answered` — an outbound call was answered (the v1 ACE callback) */
4395
+ answered?: VoiceCallHandler;
4396
+ /** `call.menu` and `call.webhook.*` — a mid-call decision point (the v1 PIE callback) */
4397
+ manage?: VoiceCallHandler;
4398
+ /** `call.hangup` and `call.failed` — the call ended (the v1 DICE callback) */
4399
+ completed?: VoiceCallHandler;
4400
+ /** Handlers for `webhook` commands, keyed by the `webhookName` they were raised under. */
4401
+ webhooks?: Record<string, VoiceCallHandler>;
4402
+ /** Any event none of the above claims */
4403
+ fallback?: VoiceCallHandler;
4404
+ }
4364
4405
  /**
4365
4406
  * Build a `voiceWebhook` export from handlers keyed by call lifecycle stage.
4366
4407
  *
4367
4408
  * ```typescript
4368
4409
  * export const voiceWebhook = onCall({
4369
- * incoming: () => commands().answer().say('Thanks for calling').hangup(),
4370
- * completed: (event) => console.log('call ended', event.call.callId),
4410
+ * incoming: (event, context) => commands().answer().say('Thanks for calling').hangup(),
4411
+ * completed: (event, context) => console.log('call ended', event.call.callId),
4371
4412
  * });
4372
4413
  * ```
4373
4414
  *
@@ -4375,13 +4416,17 @@ export declare function attachVoiceClient<T extends object>(context: T, v1?: Voi
4375
4416
  * that signature once `VOICE_SERVICE_SECRET` is set. While it is unset — Sinch does not expose
4376
4417
  * a service's secret yet — the host logs one warning and delivers the event anyway.
4377
4418
  *
4419
+ * Each handler is bound to `context` (and the raw `request`, if the host passed one) before
4420
+ * being handed to `context.voice.onCall`, which only knows the narrower, context-free
4421
+ * `WebhookHandler` shape.
4422
+ *
4378
4423
  * The dispatch is `context.voice.onCall(handlers)`. That returns a wire `WebhookResponse`
4379
4424
  * and the host emits the wire body itself, so `events.onHangup` is unwrapped back onto the
4380
4425
  * plan here — left as-is the host's second mapping would drop it.
4381
4426
  *
4382
4427
  * @param handlers - Handlers keyed by lifecycle stage
4383
4428
  */
4384
- export declare function onCall(handlers: CallHandlers): VoiceWebhookHandler;
4429
+ export declare function onCall(handlers: VoiceCallHandlers): VoiceWebhookHandler;
4385
4430
  /**
4386
4431
  * Simple template renderer for HTML files
4387
4432
  * Replaces {{variableName}} placeholders with actual values
package/dist/index.js CHANGED
@@ -112,7 +112,7 @@ import {
112
112
  validateVoiceSignature,
113
113
  validateVoiceV1Request,
114
114
  verifyVoiceWebhook
115
- } from "./chunk-DX63ULIO.js";
115
+ } from "./chunk-4GLU7JTD.js";
116
116
  export {
117
117
  AceSvamlBuilder,
118
118
  AgentProvider,
@@ -951,6 +951,12 @@ export interface Options {
951
951
  keyId?: string;
952
952
  /** Access Key Secret (Basic auth password). Defaults to `PROJECT_ID_API_SECRET`. */
953
953
  keySecret?: string;
954
+ /**
955
+ * Voice service id to route outbound calls through, including which webhook handles them.
956
+ * Defaults to `VOICE_SERVICE_ID`. Without one, calls go through the project's default
957
+ * service instead of the one the function configured.
958
+ */
959
+ serviceId?: string;
954
960
  /** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
955
961
  host?: string;
956
962
  /** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
package/dist/voice/v2.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  stringify,
28
28
  toCallRequest,
29
29
  toWebhookResponse
30
- } from "../chunk-DX63ULIO.js";
30
+ } from "../chunk-4GLU7JTD.js";
31
31
  export {
32
32
  Client,
33
33
  CommandBuilder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinch/functions-runtime",
3
- "version": "0.5.19",
3
+ "version": "0.5.20",
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": {