@sinch/functions-runtime 0.5.18 → 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/bin/sinch-runtime.js +1 -1
- package/dist/{chunk-VEB6FXNI.js → chunk-4GLU7JTD.js} +98 -41
- package/dist/chunk-4GLU7JTD.js.map +1 -0
- package/dist/index.d.ts +63 -16
- package/dist/index.js +1 -1
- package/dist/voice/v2.d.ts +19 -8
- package/dist/voice/v2.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-VEB6FXNI.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1887,11 +1887,17 @@ declare class MenuItemBuilder {
|
|
|
1887
1887
|
*
|
|
1888
1888
|
* Keys may be literal digits or regular expressions, and the platform evaluates them in
|
|
1889
1889
|
* definition order with first match winning — so the order these are written in is part of
|
|
1890
|
-
* the behaviour, not decoration. {@link build}
|
|
1891
|
-
*
|
|
1890
|
+
* the behaviour, not decoration. {@link build} emits `matches` tagged with that order so it
|
|
1891
|
+
* survives `JSON.stringify`, which would otherwise hoist integer-like keys first.
|
|
1892
1892
|
*
|
|
1893
|
-
*
|
|
1893
|
+
* The platform compiles every key as a regular expression (anchored, `^(?:key)$`), so a bare
|
|
1894
|
+
* metacharacter such as `*` or `+` is not a literal DTMF tone — it is an invalid pattern that
|
|
1895
|
+
* fails at deploy time. `match` rejects those up front instead. Escape a literal you mean, e.g.
|
|
1896
|
+
* `\*` for the star tone.
|
|
1897
|
+
*
|
|
1898
|
+
* @param pattern - Digits, `#`, or a regular expression source
|
|
1894
1899
|
* @param flow - Commands to run on a match
|
|
1900
|
+
* @throws If `pattern` does not compile as a regular expression
|
|
1895
1901
|
*/
|
|
1896
1902
|
match(pattern: string, flow: Flow): this;
|
|
1897
1903
|
/**
|
|
@@ -1900,11 +1906,7 @@ declare class MenuItemBuilder {
|
|
|
1900
1906
|
* @param flow - Commands to run
|
|
1901
1907
|
*/
|
|
1902
1908
|
onFail(flow: Flow): this;
|
|
1903
|
-
/**
|
|
1904
|
-
* Emit the menu.
|
|
1905
|
-
*
|
|
1906
|
-
* @throws If the `matches` keys cannot be serialised in the order they were written
|
|
1907
|
-
*/
|
|
1909
|
+
/** Emit the menu. */
|
|
1908
1910
|
build(): MenuItem;
|
|
1909
1911
|
}
|
|
1910
1912
|
/**
|
|
@@ -2188,6 +2190,12 @@ export interface Options {
|
|
|
2188
2190
|
keyId?: string;
|
|
2189
2191
|
/** Access Key Secret (Basic auth password). Defaults to `PROJECT_ID_API_SECRET`. */
|
|
2190
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;
|
|
2191
2199
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
2192
2200
|
host?: string;
|
|
2193
2201
|
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
|
|
@@ -2973,11 +2981,14 @@ export type NotifyHandler = (context: FunctionContext, callbackData: NotifyCallb
|
|
|
2973
2981
|
/**
|
|
2974
2982
|
* Voice API v2 webhook handler — the `voiceWebhook` export.
|
|
2975
2983
|
*
|
|
2976
|
-
* Receives the parsed CloudEvents body, not a `FunctionRequest
|
|
2977
|
-
* one URL, so there is nothing to route on inside the handler.
|
|
2978
|
-
*
|
|
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`.
|
|
2979
2990
|
*/
|
|
2980
|
-
export type VoiceWebhookHandler = (context: FunctionContext, event: WebhookRequest) => HandlerResult | Promise<HandlerResult>;
|
|
2991
|
+
export type VoiceWebhookHandler = (context: FunctionContext, event: WebhookRequest, request?: FunctionRequest) => HandlerResult | Promise<HandlerResult>;
|
|
2981
2992
|
/**
|
|
2982
2993
|
* Voice function export structure
|
|
2983
2994
|
*
|
|
@@ -3410,7 +3421,7 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
|
|
|
3410
3421
|
* `@sinch/agents` does — is emitted untouched.
|
|
3411
3422
|
* @internal
|
|
3412
3423
|
*/
|
|
3413
|
-
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>;
|
|
3414
3425
|
/**
|
|
3415
3426
|
* Handle custom endpoint execution
|
|
3416
3427
|
* @internal
|
|
@@ -4359,13 +4370,45 @@ export declare function extractCallerNumber(cli: string | undefined): string | u
|
|
|
4359
4370
|
export declare function attachVoiceClient<T extends object>(context: T, v1?: VoiceService): T & {
|
|
4360
4371
|
voice: VoiceClient;
|
|
4361
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
|
+
}
|
|
4362
4405
|
/**
|
|
4363
4406
|
* Build a `voiceWebhook` export from handlers keyed by call lifecycle stage.
|
|
4364
4407
|
*
|
|
4365
4408
|
* ```typescript
|
|
4366
4409
|
* export const voiceWebhook = onCall({
|
|
4367
|
-
* incoming: () => commands().answer().say('Thanks for calling').hangup(),
|
|
4368
|
-
* 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),
|
|
4369
4412
|
* });
|
|
4370
4413
|
* ```
|
|
4371
4414
|
*
|
|
@@ -4373,13 +4416,17 @@ export declare function attachVoiceClient<T extends object>(context: T, v1?: Voi
|
|
|
4373
4416
|
* that signature once `VOICE_SERVICE_SECRET` is set. While it is unset — Sinch does not expose
|
|
4374
4417
|
* a service's secret yet — the host logs one warning and delivers the event anyway.
|
|
4375
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
|
+
*
|
|
4376
4423
|
* The dispatch is `context.voice.onCall(handlers)`. That returns a wire `WebhookResponse`
|
|
4377
4424
|
* and the host emits the wire body itself, so `events.onHangup` is unwrapped back onto the
|
|
4378
4425
|
* plan here — left as-is the host's second mapping would drop it.
|
|
4379
4426
|
*
|
|
4380
4427
|
* @param handlers - Handlers keyed by lifecycle stage
|
|
4381
4428
|
*/
|
|
4382
|
-
export declare function onCall(handlers:
|
|
4429
|
+
export declare function onCall(handlers: VoiceCallHandlers): VoiceWebhookHandler;
|
|
4383
4430
|
/**
|
|
4384
4431
|
* Simple template renderer for HTML files
|
|
4385
4432
|
* Replaces {{variableName}} placeholders with actual values
|
package/dist/index.js
CHANGED
package/dist/voice/v2.d.ts
CHANGED
|
@@ -785,11 +785,17 @@ export declare class MenuItemBuilder {
|
|
|
785
785
|
*
|
|
786
786
|
* Keys may be literal digits or regular expressions, and the platform evaluates them in
|
|
787
787
|
* definition order with first match winning — so the order these are written in is part of
|
|
788
|
-
* the behaviour, not decoration. {@link build}
|
|
789
|
-
*
|
|
788
|
+
* the behaviour, not decoration. {@link build} emits `matches` tagged with that order so it
|
|
789
|
+
* survives `JSON.stringify`, which would otherwise hoist integer-like keys first.
|
|
790
790
|
*
|
|
791
|
-
*
|
|
791
|
+
* The platform compiles every key as a regular expression (anchored, `^(?:key)$`), so a bare
|
|
792
|
+
* metacharacter such as `*` or `+` is not a literal DTMF tone — it is an invalid pattern that
|
|
793
|
+
* fails at deploy time. `match` rejects those up front instead. Escape a literal you mean, e.g.
|
|
794
|
+
* `\*` for the star tone.
|
|
795
|
+
*
|
|
796
|
+
* @param pattern - Digits, `#`, or a regular expression source
|
|
792
797
|
* @param flow - Commands to run on a match
|
|
798
|
+
* @throws If `pattern` does not compile as a regular expression
|
|
793
799
|
*/
|
|
794
800
|
match(pattern: string, flow: Flow): this;
|
|
795
801
|
/**
|
|
@@ -798,11 +804,7 @@ export declare class MenuItemBuilder {
|
|
|
798
804
|
* @param flow - Commands to run
|
|
799
805
|
*/
|
|
800
806
|
onFail(flow: Flow): this;
|
|
801
|
-
/**
|
|
802
|
-
* Emit the menu.
|
|
803
|
-
*
|
|
804
|
-
* @throws If the `matches` keys cannot be serialised in the order they were written
|
|
805
|
-
*/
|
|
807
|
+
/** Emit the menu. */
|
|
806
808
|
build(): MenuItem;
|
|
807
809
|
}
|
|
808
810
|
/**
|
|
@@ -949,6 +951,12 @@ export interface Options {
|
|
|
949
951
|
keyId?: string;
|
|
950
952
|
/** Access Key Secret (Basic auth password). Defaults to `PROJECT_ID_API_SECRET`. */
|
|
951
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;
|
|
952
960
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
953
961
|
host?: string;
|
|
954
962
|
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
|
|
@@ -1076,9 +1084,12 @@ export declare const REDACTED = "[redacted]";
|
|
|
1076
1084
|
* ```
|
|
1077
1085
|
*/
|
|
1078
1086
|
export declare function redactCredentials<T>(body: T): T;
|
|
1087
|
+
/** `JSON.stringify`, but honouring any {@link tagOrder} tag found on nested objects. */
|
|
1088
|
+
declare function stringify(value: unknown): string;
|
|
1079
1089
|
|
|
1080
1090
|
export {
|
|
1081
1091
|
Headers$1 as Headers,
|
|
1092
|
+
stringify as stringifyOrdered,
|
|
1082
1093
|
};
|
|
1083
1094
|
|
|
1084
1095
|
export {};
|
package/dist/voice/v2.js
CHANGED
|
@@ -24,9 +24,10 @@ import {
|
|
|
24
24
|
redactCredentials,
|
|
25
25
|
resolveHandlerKey,
|
|
26
26
|
resolveWebhookName,
|
|
27
|
+
stringify,
|
|
27
28
|
toCallRequest,
|
|
28
29
|
toWebhookResponse
|
|
29
|
-
} from "../chunk-
|
|
30
|
+
} from "../chunk-4GLU7JTD.js";
|
|
30
31
|
export {
|
|
31
32
|
Client,
|
|
32
33
|
CommandBuilder,
|
|
@@ -49,6 +50,7 @@ export {
|
|
|
49
50
|
redactCredentials,
|
|
50
51
|
resolveHandlerKey,
|
|
51
52
|
resolveWebhookName,
|
|
53
|
+
stringify as stringifyOrdered,
|
|
52
54
|
toCallRequest,
|
|
53
55
|
toWebhookResponse
|
|
54
56
|
};
|
package/package.json
CHANGED