@fonoster/apiserver 0.8.45 → 0.8.47

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.
@@ -32,7 +32,6 @@ const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const convertToApplicationData_1 = require("./utils/convertToApplicationData");
34
34
  const validOrThrow_1 = require("./validation/validOrThrow");
35
- const envs_1 = require("../envs");
36
35
  const client_1 = require("@prisma/client");
37
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
37
  function createCreateApplication(prisma) {
@@ -46,9 +45,9 @@ function createCreateApplication(prisma) {
46
45
  });
47
46
  if (type === client_1.ApplicationType.AUTOPILOT && !request.endpoint) {
48
47
  logger.verbose("setting default endpoint for autopilot application", {
49
- autopilotEndpoint: envs_1.APISERVER_AUTOPILOT_ENDPOINT
48
+ autopilotEndpoint: common_1.AUTOPILOT_SPECIAL_LOCAL_ADDRESS
50
49
  });
51
- request.endpoint = envs_1.APISERVER_AUTOPILOT_ENDPOINT;
50
+ request.endpoint = common_1.AUTOPILOT_SPECIAL_LOCAL_ADDRESS;
52
51
  }
53
52
  (0, validOrThrow_1.validOrThrow)(request);
54
53
  const result = yield prisma.application.create({
@@ -35,7 +35,6 @@ const createGetFnUtil_1 = require("./createGetFnUtil");
35
35
  const convertToApplicationData_1 = require("./utils/convertToApplicationData");
36
36
  const validOrThrow_1 = require("./validation/validOrThrow");
37
37
  const identity_1 = require("@fonoster/identity");
38
- const envs_1 = require("../envs");
39
38
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
40
39
  function createUpdateApplication(prisma) {
41
40
  const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
@@ -45,9 +44,9 @@ function createUpdateApplication(prisma) {
45
44
  const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
46
45
  if (type === types_1.ApplicationType.AUTOPILOT && !request.endpoint) {
47
46
  logger.verbose("setting default endpoint for autopilot application", {
48
- autopilotEndpoint: envs_1.APISERVER_AUTOPILOT_ENDPOINT
47
+ autopilotEndpoint: common_1.AUTOPILOT_SPECIAL_LOCAL_ADDRESS
49
48
  });
50
- request.endpoint = envs_1.APISERVER_AUTOPILOT_ENDPOINT;
49
+ request.endpoint = common_1.AUTOPILOT_SPECIAL_LOCAL_ADDRESS;
51
50
  }
52
51
  (0, validOrThrow_1.validOrThrow)(request);
53
52
  logger.verbose("call to updateApplication", {
@@ -29,6 +29,7 @@ const allowList = [
29
29
  "/fonoster.identity.v1beta2.Identity/ExchangeRefreshToken",
30
30
  "/fonoster.identity.v1beta2.Identity/SendVerificationCode",
31
31
  "/fonoster.identity.v1beta2.Identity/VerifyCode",
32
- "/fonoster.identity.v1beta2.Identity/GetPublicKey"
32
+ "/fonoster.identity.v1beta2.Identity/GetPublicKey",
33
+ "/fonoster.voice.v1beta2.Voice/CreateSession"
33
34
  ];
34
35
  exports.allowList = allowList;
@@ -0,0 +1,13 @@
1
+ import { VoiceSessionStreamServer } from "@fonoster/common";
2
+ declare function buildWelcomeDemoService(): {
3
+ definition: {
4
+ readonly serviceName: "Voice";
5
+ readonly pckg: "voice";
6
+ readonly version: "v1beta2";
7
+ readonly proto: "voice.proto";
8
+ };
9
+ handlers: {
10
+ createSession: (voice: VoiceSessionStreamServer) => void;
11
+ };
12
+ };
13
+ export { buildWelcomeDemoService };
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildWelcomeDemoService = buildWelcomeDemoService;
4
+ /*
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const common_1 = require("@fonoster/common");
23
+ const logger_1 = require("@fonoster/logger");
24
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
25
+ const SERVICE_DEFINITION = {
26
+ serviceName: "Voice",
27
+ pckg: "voice",
28
+ version: "v1beta2",
29
+ proto: "voice.proto"
30
+ };
31
+ function buildWelcomeDemoService() {
32
+ return {
33
+ definition: SERVICE_DEFINITION,
34
+ handlers: {
35
+ createSession: (voice) => {
36
+ let sessionRef;
37
+ voice.on(common_1.StreamEvent.DATA, (params) => {
38
+ try {
39
+ const { request, sayResponse } = params;
40
+ if (request) {
41
+ const { callerNumber } = request;
42
+ sessionRef = request.sessionRef;
43
+ logger.verbose("welcome demo session started", {
44
+ sessionRef,
45
+ callerNumber
46
+ });
47
+ voice.write({
48
+ answerRequest: {
49
+ sessionRef: request.sessionRef
50
+ }
51
+ });
52
+ voice.write({
53
+ sayRequest: {
54
+ text: "Welcome to Fonoster! Your system is configured correctly and ready for voice application development. Goodbye!",
55
+ sessionRef: request.sessionRef
56
+ }
57
+ });
58
+ }
59
+ if (sayResponse && sessionRef) {
60
+ logger.verbose("hanging up welcome demo session", {
61
+ sessionRef
62
+ });
63
+ voice.write({
64
+ hangupRequest: {
65
+ sessionRef
66
+ }
67
+ });
68
+ }
69
+ }
70
+ catch (error) {
71
+ logger.error("error in welcome demo session", {
72
+ sessionRef,
73
+ error
74
+ });
75
+ if (sessionRef) {
76
+ voice.write({
77
+ hangupRequest: { sessionRef }
78
+ });
79
+ }
80
+ voice.end();
81
+ }
82
+ });
83
+ voice.once(common_1.StreamEvent.END, () => {
84
+ voice.end();
85
+ logger.verbose("welcome demo session ended", { sessionRef });
86
+ });
87
+ voice.on(common_1.StreamEvent.ERROR, (error) => {
88
+ logger.error("stream error in welcome demo session", {
89
+ sessionRef,
90
+ error
91
+ });
92
+ voice.end();
93
+ });
94
+ }
95
+ }
96
+ };
97
+ }
@@ -285,5 +285,15 @@ declare const services: Promise<[{
285
285
  request: unknown;
286
286
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
287
287
  };
288
+ }, {
289
+ definition: {
290
+ readonly serviceName: "Voice";
291
+ readonly pckg: "voice";
292
+ readonly version: "v1beta2";
293
+ readonly proto: "voice.proto";
294
+ };
295
+ handlers: {
296
+ createSession: (voice: import("@fonoster/common").VoiceSessionStreamServer) => void;
297
+ };
288
298
  }]>;
289
299
  export default services;
@@ -28,6 +28,7 @@ const calls_1 = require("../calls");
28
28
  const influxdb_1 = require("../calls/influxdb");
29
29
  const secrets_1 = require("../secrets");
30
30
  const utils_1 = require("../utils");
31
+ const buildWelcomeDemoService_1 = require("./buildWelcomeDemoService");
31
32
  const applicationsService = (0, applications_1.buildApplicationsService)(db_1.prisma);
32
33
  const secretsService = (0, secrets_1.buildSecretsService)(db_1.prisma);
33
34
  const callsService = (0, calls_1.buildCallsService)(influxdb_1.influxdb);
@@ -38,6 +39,7 @@ const credentialsService = (0, sipnet_1.buildCredentialsService)(routrConfig_1.r
38
39
  const trunksService = (0, sipnet_1.buildTrunksService)(routrConfig_1.routrConfig);
39
40
  const numbersService = (0, sipnet_1.buildNumbersService)(routrConfig_1.routrConfig, (0, utils_1.createCheckNumberPreconditions)(db_1.prisma));
40
41
  const aclsService = (0, sipnet_1.buildAclsService)(routrConfig_1.routrConfig);
42
+ const welcomeDemoService = (0, buildWelcomeDemoService_1.buildWelcomeDemoService)();
41
43
  const services = Promise.all([
42
44
  applicationsService,
43
45
  secretsService,
@@ -48,6 +50,7 @@ const services = Promise.all([
48
50
  aclsService,
49
51
  numbersService,
50
52
  trunksService,
51
- domainsService
53
+ domainsService,
54
+ welcomeDemoService
52
55
  ]);
53
56
  exports.default = services;
package/dist/envs.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export declare const APISERVER_BIND_ADDR: string;
2
2
  export declare const APISERVER_HOST: string;
3
- export declare const APISERVER_AUTOPILOT_ENDPOINT: string;
4
3
  export declare const APP_URL: string;
5
4
  export declare const ASTERISK_ARI_PROXY_URL: string;
6
5
  export declare const ASTERISK_ARI_SECRET: string;
package/dist/envs.js CHANGED
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SMTP_SECURE = exports.SMTP_PORT = exports.SMTP_HOST = exports.SMTP_AUTH_USER = exports.SMTP_AUTH_PASS = exports.ROUTR_DEFAULT_PEER_USERNAME = exports.ROUTR_DEFAULT_PEER_PASSWORD = exports.ROUTR_DEFAULT_PEER_NAME = exports.ROUTR_DEFAULT_PEER_AOR = exports.ROUTR_API_ENDPOINT = exports.OWNER_PASSWORD = exports.OWNER_NAME = exports.OWNER_EMAIL = exports.NATS_URL = exports.INTEGRATIONS_FILE = exports.INFLUXDB_USERNAME = exports.INFLUXDB_URL = exports.INFLUXDB_TOKEN = exports.INFLUXDB_PASSWORD = exports.INFLUXDB_ORG = exports.AUTHZ_SERVICE_METHODS = exports.AUTHZ_SERVICE_PORT = exports.AUTHZ_SERVICE_HOST = exports.AUTHZ_SERVICE_ENABLED = exports.IDENTITY_WORKSPACE_INVITATION_FAIL_URL = exports.IDENTITY_REFRESH_TOKEN_EXPIRES_IN = exports.IDENTITY_PUBLIC_KEY = exports.IDENTITY_PRIVATE_KEY = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = exports.IDENTITY_OAUTH2_GITHUB_ENABLED = exports.IDENTITY_USER_VERIFICATION_REQUIRED = exports.IDENTITY_ISSUER = exports.IDENTITY_ID_TOKEN_EXPIRES_IN = exports.IDENTITY_AUDIENCE = exports.IDENTITY_ACCESS_TOKEN_EXPIRES_IN = exports.HTTP_BRIDGE_PORT = exports.DEFAULT_NATS_QUEUE_GROUP = exports.CLOAK_ENCRYPTION_KEY = exports.CALLS_TRACK_CALL_SUBJECT = exports.CALLS_CREATE_SUBJECT = exports.ASTERISK_TRUNK = exports.ASTERISK_SYSTEM_DOMAIN = exports.ASTERISK_ARI_USERNAME = exports.ASTERISK_ARI_SECRET = exports.ASTERISK_ARI_PROXY_URL = exports.APP_URL = exports.APISERVER_AUTOPILOT_ENDPOINT = exports.APISERVER_HOST = exports.APISERVER_BIND_ADDR = void 0;
8
- exports.TWILIO_PHONE_NUMBER = exports.TWILIO_AUTH_TOKEN = exports.TWILIO_ACCOUNT_SID = exports.TEMPLATES_DIR = exports.SMTP_SENDER = void 0;
7
+ exports.SMTP_SENDER = exports.SMTP_SECURE = exports.SMTP_PORT = exports.SMTP_HOST = exports.SMTP_AUTH_USER = exports.SMTP_AUTH_PASS = exports.ROUTR_DEFAULT_PEER_USERNAME = exports.ROUTR_DEFAULT_PEER_PASSWORD = exports.ROUTR_DEFAULT_PEER_NAME = exports.ROUTR_DEFAULT_PEER_AOR = exports.ROUTR_API_ENDPOINT = exports.OWNER_PASSWORD = exports.OWNER_NAME = exports.OWNER_EMAIL = exports.NATS_URL = exports.INTEGRATIONS_FILE = exports.INFLUXDB_USERNAME = exports.INFLUXDB_URL = exports.INFLUXDB_TOKEN = exports.INFLUXDB_PASSWORD = exports.INFLUXDB_ORG = exports.AUTHZ_SERVICE_METHODS = exports.AUTHZ_SERVICE_PORT = exports.AUTHZ_SERVICE_HOST = exports.AUTHZ_SERVICE_ENABLED = exports.IDENTITY_WORKSPACE_INVITATION_FAIL_URL = exports.IDENTITY_REFRESH_TOKEN_EXPIRES_IN = exports.IDENTITY_PUBLIC_KEY = exports.IDENTITY_PRIVATE_KEY = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = exports.IDENTITY_OAUTH2_GITHUB_ENABLED = exports.IDENTITY_USER_VERIFICATION_REQUIRED = exports.IDENTITY_ISSUER = exports.IDENTITY_ID_TOKEN_EXPIRES_IN = exports.IDENTITY_AUDIENCE = exports.IDENTITY_ACCESS_TOKEN_EXPIRES_IN = exports.HTTP_BRIDGE_PORT = exports.DEFAULT_NATS_QUEUE_GROUP = exports.CLOAK_ENCRYPTION_KEY = exports.CALLS_TRACK_CALL_SUBJECT = exports.CALLS_CREATE_SUBJECT = exports.ASTERISK_TRUNK = exports.ASTERISK_SYSTEM_DOMAIN = exports.ASTERISK_ARI_USERNAME = exports.ASTERISK_ARI_SECRET = exports.ASTERISK_ARI_PROXY_URL = exports.APP_URL = exports.APISERVER_HOST = exports.APISERVER_BIND_ADDR = void 0;
8
+ exports.TWILIO_PHONE_NUMBER = exports.TWILIO_AUTH_TOKEN = exports.TWILIO_ACCOUNT_SID = exports.TEMPLATES_DIR = void 0;
9
9
  /*
10
10
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
11
11
  * http://github.com/fonoster/fonoster
@@ -56,7 +56,6 @@ const IDENTITY_PRIVATE_KEY_PATH = e.IDENTITY_PRIVATE_KEY_PATH || "/opt/fonoster/
56
56
  const IDENTITY_PUBLIC_KEY_PATH = e.IDENTITY_PUBLIC_KEY_PATH || "/opt/fonoster/keys/public.pem";
57
57
  exports.APISERVER_BIND_ADDR = e.APISERVER_BIND_ADDR || "0.0.0.0:50051";
58
58
  exports.APISERVER_HOST = e.APISERVER_HOST || "apiserver";
59
- exports.APISERVER_AUTOPILOT_ENDPOINT = e.APISERVER_AUTOPILOT_ENDPOINT || "autopilot:50061";
60
59
  // Frontend configurations
61
60
  exports.APP_URL = e.APP_URL;
62
61
  exports.ASTERISK_ARI_PROXY_URL = e.ASTERISK_ARI_PROXY_URL;
@@ -40,6 +40,8 @@ const getSttConfig_1 = require("./getSttConfig");
40
40
  const getTtsConfig_1 = require("./getTtsConfig");
41
41
  const SpeechToTextFactory_1 = require("../stt/SpeechToTextFactory");
42
42
  const TextToSpeechFactory_1 = require("../tts/TextToSpeechFactory");
43
+ const common_1 = require("@fonoster/common");
44
+ const envs_1 = require("../../envs");
43
45
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
44
46
  const integrationsConfigSchema = zod_1.z.array(zod_1.z.object({
45
47
  name: zod_1.z.string(),
@@ -78,10 +80,15 @@ function createCreateContainer(prisma, pathToIntegrations) {
78
80
  const sttConfig = (0, getSttConfig_1.getSttConfig)(integrations, app);
79
81
  const tts = TextToSpeechFactory_1.TextToSpeechFactory.getEngine(app.textToSpeech.productRef, ttsConfig);
80
82
  const stt = SpeechToTextFactory_1.SpeechToTextFactory.getEngine(app.speechToText.productRef, sttConfig);
83
+ const actualEndpoint = app.endpoint === common_1.AUTOPILOT_SPECIAL_LOCAL_ADDRESS
84
+ ? common_1.AUTOPILOT_INTERNAL_ADDRESS
85
+ : app.endpoint === common_1.WELCOME_DEMO_SPECIAL_LOCAL_ADDRESS
86
+ ? `${envs_1.APISERVER_HOST}:50051`
87
+ : app.endpoint;
81
88
  return {
82
89
  ref: appRef,
83
90
  accessKeyId: app.accessKeyId,
84
- endpoint: app.endpoint,
91
+ endpoint: actualEndpoint,
85
92
  tts,
86
93
  stt
87
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.8.45",
3
+ "version": "0.8.47",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@deepgram/sdk": "^3.5.1",
24
- "@fonoster/authz": "^0.8.45",
25
- "@fonoster/common": "^0.8.45",
26
- "@fonoster/identity": "^0.8.45",
27
- "@fonoster/logger": "^0.8.45",
28
- "@fonoster/sipnet": "^0.8.45",
29
- "@fonoster/streams": "^0.8.45",
30
- "@fonoster/types": "^0.8.45",
24
+ "@fonoster/authz": "^0.8.47",
25
+ "@fonoster/common": "^0.8.47",
26
+ "@fonoster/identity": "^0.8.47",
27
+ "@fonoster/logger": "^0.8.47",
28
+ "@fonoster/sipnet": "^0.8.47",
29
+ "@fonoster/streams": "^0.8.47",
30
+ "@fonoster/types": "^0.8.47",
31
31
  "@google-cloud/speech": "^6.6.0",
32
32
  "@google-cloud/text-to-speech": "^5.3.0",
33
33
  "@grpc/grpc-js": "~1.10.6",
@@ -73,5 +73,5 @@
73
73
  "@types/uuid": "^10.0.0",
74
74
  "@types/validator": "^13.12.0"
75
75
  },
76
- "gitHead": "5aabc6054bebd038f165d8614a2fd843dafdc1bb"
76
+ "gitHead": "33970ac7794e8e55333936ad3ad84f7260d5c138"
77
77
  }