@sinch/functions-runtime 0.3.4 → 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
package/dist/index.d.ts
CHANGED
|
@@ -812,6 +812,8 @@ export interface FunctionContext {
|
|
|
812
812
|
sms?: SmsService;
|
|
813
813
|
/** Sinch Numbers SDK client (if available) */
|
|
814
814
|
numbers?: NumbersService;
|
|
815
|
+
/** Read a file from the assets/ directory (private, not served over HTTP) */
|
|
816
|
+
assets(filename: string): Promise<string>;
|
|
815
817
|
}
|
|
816
818
|
/**
|
|
817
819
|
* Application credentials structure
|
package/dist/index.js
CHANGED
|
@@ -896,6 +896,7 @@ function setupJsonParsing(app, options = {}) {
|
|
|
896
896
|
import { createRequire as createRequire2 } from "module";
|
|
897
897
|
import { pathToFileURL } from "url";
|
|
898
898
|
import * as nodePath from "path";
|
|
899
|
+
import * as nodeFs from "fs";
|
|
899
900
|
var requireCjs2 = createRequire2(import.meta.url);
|
|
900
901
|
var LANDING_PAGE_HTML = `<!DOCTYPE html>
|
|
901
902
|
<html lang="en">
|
|
@@ -1084,7 +1085,11 @@ function buildBaseContext(req, config = {}) {
|
|
|
1084
1085
|
environment: config.environment || "development",
|
|
1085
1086
|
variables: config.variables
|
|
1086
1087
|
},
|
|
1087
|
-
cache: noOpCache
|
|
1088
|
+
cache: noOpCache,
|
|
1089
|
+
assets: (filename) => {
|
|
1090
|
+
const filePath = nodePath.join(process.cwd(), "assets", filename);
|
|
1091
|
+
return nodeFs.promises.readFile(filePath, "utf-8");
|
|
1092
|
+
}
|
|
1088
1093
|
};
|
|
1089
1094
|
}
|
|
1090
1095
|
async function handleVoiceCallback(functionName, userFunction, context, callbackData, logger) {
|
|
@@ -1144,10 +1149,11 @@ async function handleCustomEndpoint(functionName, userFunction, context, request
|
|
|
1144
1149
|
function createApp(options = {}) {
|
|
1145
1150
|
const express = requireCjs2("express");
|
|
1146
1151
|
const app = express();
|
|
1147
|
-
|
|
1148
|
-
|
|
1152
|
+
const staticDir = options.staticDir ?? (nodeFs.existsSync("./public") ? "./public" : void 0);
|
|
1153
|
+
if (staticDir) {
|
|
1154
|
+
app.use(express.static(staticDir, {
|
|
1149
1155
|
index: false,
|
|
1150
|
-
// Don't serve index.html for /,
|
|
1156
|
+
// Don't serve index.html for /, we handle that below
|
|
1151
1157
|
dotfiles: "ignore"
|
|
1152
1158
|
}));
|
|
1153
1159
|
}
|
|
@@ -1188,6 +1194,13 @@ function setupRequestHandler(app, options = {}) {
|
|
|
1188
1194
|
return;
|
|
1189
1195
|
}
|
|
1190
1196
|
}
|
|
1197
|
+
if (req.method === "GET" && req.path === "/" && !landingPageEnabled) {
|
|
1198
|
+
const indexPath = nodePath.join(process.cwd(), "public", "index.html");
|
|
1199
|
+
if (nodeFs.existsSync(indexPath)) {
|
|
1200
|
+
res.type("html").sendFile(indexPath);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1191
1204
|
try {
|
|
1192
1205
|
const functionName = extractFunctionName(req.baseUrl, req.body);
|
|
1193
1206
|
logger(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${req.method} ${req.path} -> ${functionName}`);
|
|
@@ -1644,7 +1657,7 @@ async function configureConversationWebhooks(tunnelUrl, config) {
|
|
|
1644
1657
|
console.log("\u{1F4A1} Conversation API not fully configured - skipping webhook setup");
|
|
1645
1658
|
return;
|
|
1646
1659
|
}
|
|
1647
|
-
const webhookUrl = `${tunnelUrl}/
|
|
1660
|
+
const webhookUrl = `${tunnelUrl}/webhook`;
|
|
1648
1661
|
console.log(`\u{1F4AC} Conversation webhook URL: ${webhookUrl}`);
|
|
1649
1662
|
const sinchClient = new SinchClient2({
|
|
1650
1663
|
projectId,
|
|
@@ -1906,8 +1919,11 @@ var TunnelClient = class {
|
|
|
1906
1919
|
* Configure all webhooks (Voice, Conversation, ElevenLabs)
|
|
1907
1920
|
*/
|
|
1908
1921
|
async configureWebhooks() {
|
|
1909
|
-
const
|
|
1910
|
-
const
|
|
1922
|
+
const hasNewFormat = "AUTO_CONFIGURE" in process.env;
|
|
1923
|
+
const autoEnabled = process.env.AUTO_CONFIGURE === "true";
|
|
1924
|
+
const sinchServices = (process.env.SINCH_SERVICES ?? "").split(",").map((s) => s.trim());
|
|
1925
|
+
const autoConfigVoice = hasNewFormat ? autoEnabled && sinchServices.includes("voice") : process.env.AUTO_CONFIGURE_VOICE !== "false" && !!process.env.VOICE_APPLICATION_KEY;
|
|
1926
|
+
const autoConfigConversation = hasNewFormat ? autoEnabled && sinchServices.includes("conversation") : process.env.AUTO_CONFIGURE_CONVERSATION !== "false" && !!process.env.CONVERSATION_APP_ID;
|
|
1911
1927
|
if (autoConfigVoice && process.env.VOICE_APPLICATION_KEY) {
|
|
1912
1928
|
await this.configureVoiceWebhooks();
|
|
1913
1929
|
}
|