@sinch/functions-runtime 0.3.3 → 0.3.5
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 +23 -7
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -161,6 +161,7 @@ function setupJsonParsing(app, options = {}) {
|
|
|
161
161
|
import { createRequire as createRequire2 } from "module";
|
|
162
162
|
import { pathToFileURL } from "url";
|
|
163
163
|
import * as nodePath from "path";
|
|
164
|
+
import * as nodeFs from "fs";
|
|
164
165
|
var requireCjs2 = createRequire2(import.meta.url);
|
|
165
166
|
var LANDING_PAGE_HTML = `<!DOCTYPE html>
|
|
166
167
|
<html lang="en">
|
|
@@ -349,7 +350,11 @@ function buildBaseContext(req, config = {}) {
|
|
|
349
350
|
environment: config.environment || "development",
|
|
350
351
|
variables: config.variables
|
|
351
352
|
},
|
|
352
|
-
cache: noOpCache
|
|
353
|
+
cache: noOpCache,
|
|
354
|
+
assets: (filename) => {
|
|
355
|
+
const filePath = nodePath.join(process.cwd(), "assets", filename);
|
|
356
|
+
return nodeFs.promises.readFile(filePath, "utf-8");
|
|
357
|
+
}
|
|
353
358
|
};
|
|
354
359
|
}
|
|
355
360
|
async function handleVoiceCallback(functionName, userFunction, context, callbackData, logger) {
|
|
@@ -409,10 +414,11 @@ async function handleCustomEndpoint(functionName, userFunction, context, request
|
|
|
409
414
|
function createApp(options = {}) {
|
|
410
415
|
const express = requireCjs2("express");
|
|
411
416
|
const app = express();
|
|
412
|
-
|
|
413
|
-
|
|
417
|
+
const staticDir = options.staticDir ?? (nodeFs.existsSync("./public") ? "./public" : void 0);
|
|
418
|
+
if (staticDir) {
|
|
419
|
+
app.use(express.static(staticDir, {
|
|
414
420
|
index: false,
|
|
415
|
-
// Don't serve index.html for /,
|
|
421
|
+
// Don't serve index.html for /, we handle that below
|
|
416
422
|
dotfiles: "ignore"
|
|
417
423
|
}));
|
|
418
424
|
}
|
|
@@ -453,6 +459,13 @@ function setupRequestHandler(app, options = {}) {
|
|
|
453
459
|
return;
|
|
454
460
|
}
|
|
455
461
|
}
|
|
462
|
+
if (req.method === "GET" && req.path === "/" && !landingPageEnabled) {
|
|
463
|
+
const indexPath = nodePath.join(process.cwd(), "public", "index.html");
|
|
464
|
+
if (nodeFs.existsSync(indexPath)) {
|
|
465
|
+
res.type("html").sendFile(indexPath);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
456
469
|
try {
|
|
457
470
|
const functionName = extractFunctionName(req.baseUrl, req.body);
|
|
458
471
|
logger(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${req.method} ${req.path} -> ${functionName}`);
|
|
@@ -927,7 +940,7 @@ async function configureConversationWebhooks(tunnelUrl, config) {
|
|
|
927
940
|
console.log("\u{1F4A1} Conversation API not fully configured - skipping webhook setup");
|
|
928
941
|
return;
|
|
929
942
|
}
|
|
930
|
-
const webhookUrl = `${tunnelUrl}/
|
|
943
|
+
const webhookUrl = `${tunnelUrl}/webhook`;
|
|
931
944
|
console.log(`\u{1F4AC} Conversation webhook URL: ${webhookUrl}`);
|
|
932
945
|
const sinchClient = new SinchClient2({
|
|
933
946
|
projectId,
|
|
@@ -1189,8 +1202,11 @@ var TunnelClient = class {
|
|
|
1189
1202
|
* Configure all webhooks (Voice, Conversation, ElevenLabs)
|
|
1190
1203
|
*/
|
|
1191
1204
|
async configureWebhooks() {
|
|
1192
|
-
const
|
|
1193
|
-
const
|
|
1205
|
+
const hasNewFormat = "AUTO_CONFIGURE" in process.env;
|
|
1206
|
+
const autoEnabled = process.env.AUTO_CONFIGURE === "true";
|
|
1207
|
+
const sinchServices = (process.env.SINCH_SERVICES ?? "").split(",").map((s) => s.trim());
|
|
1208
|
+
const autoConfigVoice = hasNewFormat ? autoEnabled && sinchServices.includes("voice") : process.env.AUTO_CONFIGURE_VOICE !== "false" && !!process.env.VOICE_APPLICATION_KEY;
|
|
1209
|
+
const autoConfigConversation = hasNewFormat ? autoEnabled && sinchServices.includes("conversation") : process.env.AUTO_CONFIGURE_CONVERSATION !== "false" && !!process.env.CONVERSATION_APP_ID;
|
|
1194
1210
|
if (autoConfigVoice && process.env.VOICE_APPLICATION_KEY) {
|
|
1195
1211
|
await this.configureVoiceWebhooks();
|
|
1196
1212
|
}
|