@fonoster/apiserver 0.7.56 → 0.8.0

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.
@@ -75,15 +75,18 @@ const services_1 = __importDefault(require("./services"));
75
75
  const runCallManager_1 = require("../calls/runCallManager");
76
76
  const envs_1 = require("../envs");
77
77
  const connectToAri_1 = require("../voice/connectToAri");
78
+ const authz_1 = require("@fonoster/authz");
78
79
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
79
80
  const authorization = (0, identity_1.createAuthInterceptor)(envs_1.IDENTITY_PUBLIC_KEY, allowList_1.allowList);
81
+ const checkMethodAuthorized = (0, authz_1.createCheckMethodAuthorized)(`${envs_1.AUTHZ_SERVICE_HOST}:${envs_1.AUTHZ_SERVICE_PORT}`, envs_1.AUTHZ_SERVICE_METHODS);
80
82
  function runServices() {
81
83
  return __awaiter(this, void 0, void 0, function* () {
82
84
  const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
83
85
  const credentials = yield (0, common_1.getServerCredentials)({});
84
- const server = new grpc.Server({
85
- interceptors: [authorization]
86
- });
86
+ const interceptors = envs_1.AUTHZ_SERVICE_ENABLED
87
+ ? [authorization, checkMethodAuthorized]
88
+ : [authorization];
89
+ const server = new grpc.Server({ interceptors });
87
90
  // Add the health check service to the server
88
91
  healthImpl.addToServer(server);
89
92
  // Load the remaining services
package/dist/envs.d.ts CHANGED
@@ -21,6 +21,10 @@ export declare const IDENTITY_PRIVATE_KEY: string;
21
21
  export declare const IDENTITY_PUBLIC_KEY: string;
22
22
  export declare const IDENTITY_REFRESH_TOKEN_EXPIRES_IN: string;
23
23
  export declare const IDENTITY_WORKSPACE_INVITATION_FAIL_URL: string;
24
+ export declare const AUTHZ_SERVICE_ENABLED: boolean;
25
+ export declare const AUTHZ_SERVICE_HOST: string;
26
+ export declare const AUTHZ_SERVICE_PORT: string | number;
27
+ export declare const AUTHZ_SERVICE_METHODS: string[];
24
28
  export declare const INFLUXDB_BUCKET: string;
25
29
  export declare const INFLUXDB_ORG: string;
26
30
  export declare const INFLUXDB_PASSWORD: string;
package/dist/envs.js CHANGED
@@ -4,7 +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.TWILIO_PHONE_NUMBER = exports.TWILIO_AUTH_TOKEN = exports.TWILIO_ACCOUNT_SID = exports.TEMPLATES_DIR = 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.INFLUXDB_BUCKET = 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_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;
7
+ exports.TEMPLATES_DIR = 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.INFLUXDB_BUCKET = 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_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 = void 0;
8
9
  /*
9
10
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
10
11
  * http://github.com/fonoster/fonoster
@@ -88,6 +89,16 @@ if (e.IDENTITY_OAUTH2_GITHUB_ENABLED === "true") {
88
89
  "IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET"
89
90
  ]);
90
91
  }
92
+ if (e.AUTHZ_SERVICE_ENABLED === "true") {
93
+ (0, common_1.assertEnvsAreSet)(["AUTHZ_SERVICE_HOST"]);
94
+ }
95
+ // Authz configurations
96
+ exports.AUTHZ_SERVICE_ENABLED = e.AUTHZ_SERVICE_ENABLED === "true";
97
+ exports.AUTHZ_SERVICE_HOST = e.AUTHZ_SERVICE_HOST;
98
+ exports.AUTHZ_SERVICE_PORT = e.AUTHZ_SERVICE_PORT || 50071;
99
+ exports.AUTHZ_SERVICE_METHODS = e.AUTHZ_SERVICE_METHODS
100
+ ? e.AUTHZ_SERVICE_METHODS.split(",")
101
+ : ["/fonoster.calls.v1beta2.Calls/CreateCall"];
91
102
  // InfluxDB configurations
92
103
  exports.INFLUXDB_BUCKET = e.INFLUXDB_INIT_BUCKET;
93
104
  exports.INFLUXDB_ORG = e.INFLUXDB_INIT_ORG;
package/dist/index.js CHANGED
File without changes
@@ -135,7 +135,7 @@ class VoiceClientImpl {
135
135
  const snoopChannel = yield this.ari.channels.snoopChannel({
136
136
  app: common_1.STASIS_APP_NAME,
137
137
  channelId: this.config.sessionRef,
138
- snoopId: "snoop-" + this.config.sessionRef,
138
+ snoopId: `snoop-${this.config.sessionRef}`,
139
139
  spy: "in"
140
140
  });
141
141
  const bridge = this.ari.Bridge();
@@ -84,7 +84,7 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
84
84
  synthesize(text, options) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
86
  logger.verbose(`synthesize [input: ${text}, isSsml=${(0, isSsml_1.isSsml)(text)} options: ${JSON.stringify(options)}]`);
87
- const { voice } = this.engineConfig.config;
87
+ const { voice, model } = this.engineConfig.config;
88
88
  const ref = this.createMediaReference();
89
89
  const chunks = (0, textChunksByFirstNaturalPause_1.textChunksByFirstNaturalPause)(text);
90
90
  const stream = new stream_1.Readable({ read() { } });
@@ -105,8 +105,8 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
105
105
  }
106
106
  }
107
107
  observeQueue();
108
- chunks.forEach((textChunk, index) => {
109
- this.doSynthesize(textChunk, voice)
108
+ chunks.forEach((text, index) => {
109
+ this.doSynthesize({ text, voice, model })
110
110
  .then((synthesizedText) => {
111
111
  results[index] = synthesizedText;
112
112
  })
@@ -117,13 +117,14 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
117
117
  return { ref, stream };
118
118
  });
119
119
  }
120
- doSynthesize(text, voice) {
120
+ doSynthesize(params) {
121
121
  return __awaiter(this, void 0, void 0, function* () {
122
+ const { text, voice, model } = params;
122
123
  const response = yield this.client.generate({
123
124
  stream: true,
124
125
  voice,
125
126
  text,
126
- model_id: "eleven_turbo_v2_5",
127
+ model_id: model !== null && model !== void 0 ? model : "eleven_flash_v2_5",
127
128
  output_format: "pcm_16000"
128
129
  });
129
130
  return (yield (0, streamToBuffer_1.streamToBuffer)(response));
@@ -1,7 +1,7 @@
1
1
  import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
2
2
  type EngineConstructor<T> = new (options: T) => AbstractTextToSpeech<string>;
3
3
  declare class TextToSpeechFactory {
4
- private static engines;
4
+ private static readonly engines;
5
5
  static registerEngine<T>(name: string, ctor: EngineConstructor<T>): void;
6
6
  static getEngine<T>(engineName: string, config: T): AbstractTextToSpeech<string>;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.7.56",
3
+ "version": "0.8.0",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -21,12 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@deepgram/sdk": "^3.5.1",
24
- "@fonoster/common": "^0.7.56",
25
- "@fonoster/identity": "^0.7.56",
26
- "@fonoster/logger": "^0.7.56",
27
- "@fonoster/sipnet": "^0.7.56",
28
- "@fonoster/streams": "^0.7.56",
29
- "@fonoster/types": "^0.7.56",
24
+ "@fonoster/authz": "^0.8.0",
25
+ "@fonoster/common": "^0.8.0",
26
+ "@fonoster/identity": "^0.8.0",
27
+ "@fonoster/logger": "^0.8.0",
28
+ "@fonoster/sipnet": "^0.8.0",
29
+ "@fonoster/streams": "^0.8.0",
30
+ "@fonoster/types": "^0.8.0",
30
31
  "@google-cloud/speech": "^6.6.0",
31
32
  "@google-cloud/text-to-speech": "^5.3.0",
32
33
  "@grpc/grpc-js": "~1.10.6",
@@ -72,5 +73,5 @@
72
73
  "@types/uuid": "^10.0.0",
73
74
  "@types/validator": "^13.12.0"
74
75
  },
75
- "gitHead": "f918235ae68a49970b45022637347f673ca63941"
76
+ "gitHead": "9d8a6fc044fe23f4f75356c142d1ca412db5af15"
76
77
  }