@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/bin/sinch-runtime.js +1 -1
- package/dist/{chunk-DX63ULIO.js → chunk-4GLU7JTD.js} +35 -15
- package/dist/{chunk-DX63ULIO.js.map → chunk-4GLU7JTD.js.map} +1 -1
- package/dist/index.d.ts +53 -8
- package/dist/index.js +1 -1
- package/dist/voice/v2.d.ts +6 -0
- package/dist/voice/v2.js +1 -1
- package/package.json +1 -1
|
@@ -59995,6 +59995,7 @@ var DEFAULT_HOST = "https://voice.api.sinch.com";
|
|
|
59995
59995
|
var FETCH_TIMEOUT_MS = 1e4;
|
|
59996
59996
|
var HttpTransport = class {
|
|
59997
59997
|
projectId;
|
|
59998
|
+
serviceId;
|
|
59998
59999
|
host;
|
|
59999
60000
|
fetchImpl;
|
|
60000
60001
|
// The Access Key pair is held in ECMAScript private fields, not TypeScript `private` ones.
|
|
@@ -60006,6 +60007,7 @@ var HttpTransport = class {
|
|
|
60006
60007
|
#keySecret;
|
|
60007
60008
|
constructor(options) {
|
|
60008
60009
|
this.projectId = options.projectId;
|
|
60010
|
+
this.serviceId = options.serviceId;
|
|
60009
60011
|
this.#keyId = options.keyId;
|
|
60010
60012
|
this.#keySecret = options.keySecret;
|
|
60011
60013
|
this.host = (options.host ?? DEFAULT_HOST).replace(/\/$/, "");
|
|
@@ -60021,7 +60023,8 @@ var HttpTransport = class {
|
|
|
60021
60023
|
return { transport: "HttpTransport", projectId: this.projectId, host: this.host };
|
|
60022
60024
|
}
|
|
60023
60025
|
async createCall(body) {
|
|
60024
|
-
const
|
|
60026
|
+
const path6 = this.serviceId ? `calls?serviceId=${encodeURIComponent(this.serviceId)}` : "calls";
|
|
60027
|
+
const response = await this.request("POST", path6, body);
|
|
60025
60028
|
return response;
|
|
60026
60029
|
}
|
|
60027
60030
|
async patchCall(target, commands2) {
|
|
@@ -60804,6 +60807,9 @@ var Client = class {
|
|
|
60804
60807
|
projectId: options.projectId ?? env.PROJECT_ID ?? context?.config?.projectId ?? "",
|
|
60805
60808
|
keyId: options.keyId ?? env.PROJECT_ID_API_KEY ?? "",
|
|
60806
60809
|
keySecret: options.keySecret ?? env.PROJECT_ID_API_SECRET ?? "",
|
|
60810
|
+
...(options.serviceId ?? env.VOICE_SERVICE_ID) !== void 0 && {
|
|
60811
|
+
serviceId: options.serviceId ?? env.VOICE_SERVICE_ID
|
|
60812
|
+
},
|
|
60807
60813
|
...options.host !== void 0 && { host: options.host },
|
|
60808
60814
|
...options.fetch !== void 0 && { fetch: options.fetch }
|
|
60809
60815
|
});
|
|
@@ -61221,9 +61227,23 @@ function attachVoiceClient(context, v1) {
|
|
|
61221
61227
|
});
|
|
61222
61228
|
return context;
|
|
61223
61229
|
}
|
|
61230
|
+
function bindHandler(handler, context, request) {
|
|
61231
|
+
return handler ? (event) => handler(event, context, request) : void 0;
|
|
61232
|
+
}
|
|
61224
61233
|
function onCall(handlers) {
|
|
61225
|
-
return async (context, event) => {
|
|
61226
|
-
const
|
|
61234
|
+
return async (context, event, request) => {
|
|
61235
|
+
const bind2 = (handler) => bindHandler(handler, context, request);
|
|
61236
|
+
const bound = {
|
|
61237
|
+
incoming: bind2(handlers.incoming),
|
|
61238
|
+
answered: bind2(handlers.answered),
|
|
61239
|
+
manage: bind2(handlers.manage),
|
|
61240
|
+
completed: bind2(handlers.completed),
|
|
61241
|
+
fallback: bind2(handlers.fallback),
|
|
61242
|
+
...handlers.webhooks && {
|
|
61243
|
+
webhooks: Object.fromEntries(Object.entries(handlers.webhooks).map(([name, handler]) => [name, (event2) => handler(event2, context, request)]))
|
|
61244
|
+
}
|
|
61245
|
+
};
|
|
61246
|
+
const response = await context.voice.onCall(bound)(event);
|
|
61227
61247
|
if (!response) {
|
|
61228
61248
|
return void 0;
|
|
61229
61249
|
}
|
|
@@ -61900,12 +61920,12 @@ async function handleVoiceV1Callback(functionName, userFunction, context, callba
|
|
|
61900
61920
|
}
|
|
61901
61921
|
return formatSvamlResponse(result2, functionName);
|
|
61902
61922
|
}
|
|
61903
|
-
async function handleVoiceWebhook(userFunction, context, event, logger) {
|
|
61923
|
+
async function handleVoiceWebhook(userFunction, context, event, request, logger) {
|
|
61904
61924
|
const handler = userFunction[VOICE_WEBHOOK_HANDLER];
|
|
61905
61925
|
if (!handler || typeof handler !== "function") {
|
|
61906
61926
|
throw new Error(`No export '${VOICE_WEBHOOK_HANDLER}' found for Voice v2 event '${event?.event}'. Export one built with onCall({ incoming: ... }), or drop VOICE_SERVICE_ID to stay on the v1 ice/ace/pie/dice callbacks.`);
|
|
61907
61927
|
}
|
|
61908
|
-
const result2 = await handler(context, event);
|
|
61928
|
+
const result2 = await handler(context, event, request);
|
|
61909
61929
|
if (logger) {
|
|
61910
61930
|
logger("Function result:", result2);
|
|
61911
61931
|
}
|
|
@@ -62084,6 +62104,14 @@ function setupRequestHandler(app, options = {}) {
|
|
|
62084
62104
|
onRequestStart({ functionName, req });
|
|
62085
62105
|
const context = buildContext(req);
|
|
62086
62106
|
const userFunction = await Promise.resolve(loadUserFunction());
|
|
62107
|
+
const request = {
|
|
62108
|
+
method: req.method,
|
|
62109
|
+
path: req.path,
|
|
62110
|
+
query: req.query,
|
|
62111
|
+
headers: req.headers,
|
|
62112
|
+
body: req.body,
|
|
62113
|
+
params: req.params
|
|
62114
|
+
};
|
|
62087
62115
|
let response;
|
|
62088
62116
|
if (isVoiceV1Callback(functionName)) {
|
|
62089
62117
|
const validation = validateVoiceV1Request(req.body);
|
|
@@ -62096,16 +62124,8 @@ function setupRequestHandler(app, options = {}) {
|
|
|
62096
62124
|
}
|
|
62097
62125
|
response = await handleVoiceV1Callback(functionName, userFunction, context, req.body, logger);
|
|
62098
62126
|
} else if (functionName === VOICE_WEBHOOK_HANDLER && isVoiceWebhook(req.body)) {
|
|
62099
|
-
response = await handleVoiceWebhook(userFunction, context, req.body, logger);
|
|
62127
|
+
response = await handleVoiceWebhook(userFunction, context, req.body, request, logger);
|
|
62100
62128
|
} else {
|
|
62101
|
-
const request = {
|
|
62102
|
-
method: req.method,
|
|
62103
|
-
path: req.path,
|
|
62104
|
-
query: req.query,
|
|
62105
|
-
headers: req.headers,
|
|
62106
|
-
body: req.body,
|
|
62107
|
-
params: req.params
|
|
62108
|
-
};
|
|
62109
62129
|
response = await handleCustomEndpoint(functionName, userFunction, context, request, logger);
|
|
62110
62130
|
}
|
|
62111
62131
|
res.status(response.statusCode);
|
|
@@ -71776,4 +71796,4 @@ serve-static/index.js:
|
|
|
71776
71796
|
* MIT Licensed
|
|
71777
71797
|
*)
|
|
71778
71798
|
*/
|
|
71779
|
-
//# sourceMappingURL=chunk-
|
|
71799
|
+
//# sourceMappingURL=chunk-4GLU7JTD.js.map
|