@fonoster/apiserver 0.7.57 → 0.8.4
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/applications/utils/convertToApplicationData.js +0 -1
- package/dist/core/identityConfig.js +14 -0
- package/dist/core/runServices.js +6 -3
- package/dist/envs.d.ts +6 -0
- package/dist/envs.js +14 -1
- package/dist/voice/VoiceClientImpl.js +24 -1
- package/dist/voice/tts/ElevenLabs.js +2 -3
- package/dist/voice/tts/TextToSpeechFactory.d.ts +1 -1
- package/dist/voice/tts/types.d.ts +0 -1
- package/package.json +9 -8
|
@@ -19,7 +19,21 @@ exports.identityConfig = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
const common_1 = require("@fonoster/common");
|
|
22
23
|
const envs_1 = require("../envs");
|
|
24
|
+
if (envs_1.IDENTITY_USER_VERIFICATION_REQUIRED) {
|
|
25
|
+
(0, common_1.assertEnvsAreSet)([
|
|
26
|
+
"TWILIO_ACCOUNT_SID",
|
|
27
|
+
"TWILIO_AUTH_TOKEN",
|
|
28
|
+
"TWILIO_PHONE_NUMBER"
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
if (envs_1.IDENTITY_OAUTH2_GITHUB_ENABLED) {
|
|
32
|
+
(0, common_1.assertEnvsAreSet)([
|
|
33
|
+
"IDENTITY_OAUTH2_GITHUB_CLIENT_ID",
|
|
34
|
+
"IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET"
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
23
37
|
const identityConfig = {
|
|
24
38
|
issuer: envs_1.IDENTITY_ISSUER,
|
|
25
39
|
audience: envs_1.IDENTITY_AUDIENCE,
|
package/dist/core/runServices.js
CHANGED
|
@@ -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
|
|
85
|
-
|
|
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
|
@@ -15,12 +15,18 @@ export declare const IDENTITY_ACCESS_TOKEN_EXPIRES_IN: string;
|
|
|
15
15
|
export declare const IDENTITY_AUDIENCE: string;
|
|
16
16
|
export declare const IDENTITY_ID_TOKEN_EXPIRES_IN: string;
|
|
17
17
|
export declare const IDENTITY_ISSUER: string;
|
|
18
|
+
export declare const IDENTITY_USER_VERIFICATION_REQUIRED: boolean;
|
|
19
|
+
export declare const IDENTITY_OAUTH2_GITHUB_ENABLED: boolean;
|
|
18
20
|
export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_ID: string;
|
|
19
21
|
export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET: string;
|
|
20
22
|
export declare const IDENTITY_PRIVATE_KEY: string;
|
|
21
23
|
export declare const IDENTITY_PUBLIC_KEY: string;
|
|
22
24
|
export declare const IDENTITY_REFRESH_TOKEN_EXPIRES_IN: string;
|
|
23
25
|
export declare const IDENTITY_WORKSPACE_INVITATION_FAIL_URL: string;
|
|
26
|
+
export declare const AUTHZ_SERVICE_ENABLED: boolean;
|
|
27
|
+
export declare const AUTHZ_SERVICE_HOST: string;
|
|
28
|
+
export declare const AUTHZ_SERVICE_PORT: string | number;
|
|
29
|
+
export declare const AUTHZ_SERVICE_METHODS: string[];
|
|
24
30
|
export declare const INFLUXDB_BUCKET: string;
|
|
25
31
|
export declare const INFLUXDB_ORG: string;
|
|
26
32
|
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.
|
|
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.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_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 = exports.SMTP_SENDER = void 0;
|
|
8
9
|
/*
|
|
9
10
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
10
11
|
* http://github.com/fonoster/fonoster
|
|
@@ -76,6 +77,8 @@ exports.IDENTITY_ACCESS_TOKEN_EXPIRES_IN = e.IDENTITY_ACCESS_TOKEN_EXPIRES_IN ||
|
|
|
76
77
|
exports.IDENTITY_AUDIENCE = e.IDENTITY_AUDIENCE || "api";
|
|
77
78
|
exports.IDENTITY_ID_TOKEN_EXPIRES_IN = e.IDENTITY_ID_TOKEN_EXPIRES_IN || "15m";
|
|
78
79
|
exports.IDENTITY_ISSUER = e.IDENTITY_ISSUER || "https://fonoster.local";
|
|
80
|
+
exports.IDENTITY_USER_VERIFICATION_REQUIRED = e.IDENTITY_USER_VERIFICATION_REQUIRED === "true";
|
|
81
|
+
exports.IDENTITY_OAUTH2_GITHUB_ENABLED = e.IDENTITY_OAUTH2_GITHUB_ENABLED === "true";
|
|
79
82
|
exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = e.IDENTITY_OAUTH2_GITHUB_CLIENT_ID;
|
|
80
83
|
exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = e.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET;
|
|
81
84
|
exports.IDENTITY_PRIVATE_KEY = fs_1.default.readFileSync(IDENTITY_PRIVATE_KEY_PATH, "utf8");
|
|
@@ -88,6 +91,16 @@ if (e.IDENTITY_OAUTH2_GITHUB_ENABLED === "true") {
|
|
|
88
91
|
"IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET"
|
|
89
92
|
]);
|
|
90
93
|
}
|
|
94
|
+
if (e.AUTHZ_SERVICE_ENABLED === "true") {
|
|
95
|
+
(0, common_1.assertEnvsAreSet)(["AUTHZ_SERVICE_HOST"]);
|
|
96
|
+
}
|
|
97
|
+
// Authz configurations
|
|
98
|
+
exports.AUTHZ_SERVICE_ENABLED = e.AUTHZ_SERVICE_ENABLED === "true";
|
|
99
|
+
exports.AUTHZ_SERVICE_HOST = e.AUTHZ_SERVICE_HOST;
|
|
100
|
+
exports.AUTHZ_SERVICE_PORT = e.AUTHZ_SERVICE_PORT || 50071;
|
|
101
|
+
exports.AUTHZ_SERVICE_METHODS = e.AUTHZ_SERVICE_METHODS
|
|
102
|
+
? e.AUTHZ_SERVICE_METHODS.split(",")
|
|
103
|
+
: ["/fonoster.calls.v1beta2.Calls/CreateCall"];
|
|
91
104
|
// InfluxDB configurations
|
|
92
105
|
exports.INFLUXDB_BUCKET = e.INFLUXDB_INIT_BUCKET;
|
|
93
106
|
exports.INFLUXDB_ORG = e.INFLUXDB_INIT_ORG;
|
|
@@ -72,6 +72,8 @@ const transcribeOnConnection_1 = require("./transcribeOnConnection");
|
|
|
72
72
|
const types_1 = require("./types");
|
|
73
73
|
const createExternalMediaConfig_1 = require("./utils/createExternalMediaConfig");
|
|
74
74
|
const VoiceServiceClientConstructor_1 = require("./utils/VoiceServiceClientConstructor");
|
|
75
|
+
const envs_1 = require("../envs");
|
|
76
|
+
const authz_1 = require("@fonoster/authz");
|
|
75
77
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
76
78
|
class VoiceClientImpl {
|
|
77
79
|
constructor(params, filesServer) {
|
|
@@ -86,6 +88,27 @@ class VoiceClientImpl {
|
|
|
86
88
|
}
|
|
87
89
|
connect() {
|
|
88
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
// TODO: We should improve the error handling here. As it is now,
|
|
92
|
+
// it always returns true or throws an error we should return a boolean and throw an error only if the
|
|
93
|
+
// connection is not possible or other critical error
|
|
94
|
+
if (envs_1.AUTHZ_SERVICE_ENABLED) {
|
|
95
|
+
try {
|
|
96
|
+
const authz = new authz_1.AuthzClient(`${envs_1.AUTHZ_SERVICE_HOST}:${envs_1.AUTHZ_SERVICE_PORT}`);
|
|
97
|
+
yield authz.checkSessionAuthorized({
|
|
98
|
+
accessKeyId: this.config.accessKeyId
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
const { sessionRef: channelId } = this.config;
|
|
103
|
+
const { ari } = this;
|
|
104
|
+
logger.verbose("rejected unauthorized session", { channelId });
|
|
105
|
+
yield ari.channels.answer({ channelId });
|
|
106
|
+
yield ari.channels.play({ channelId, media: "sound:unavailable" });
|
|
107
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
108
|
+
yield ari.channels.hangup({ channelId });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
89
112
|
this.grpcClient = new VoiceServiceClientConstructor_1.VoiceServiceClientConstructor(this.config.endpoint, grpc.credentials.createInsecure());
|
|
90
113
|
const metadata = new grpc.Metadata();
|
|
91
114
|
metadata.add("accessKeyId", this.config.accessKeyId);
|
|
@@ -135,7 +158,7 @@ class VoiceClientImpl {
|
|
|
135
158
|
const snoopChannel = yield this.ari.channels.snoopChannel({
|
|
136
159
|
app: common_1.STASIS_APP_NAME,
|
|
137
160
|
channelId: this.config.sessionRef,
|
|
138
|
-
snoopId:
|
|
161
|
+
snoopId: `snoop-${this.config.sessionRef}`,
|
|
139
162
|
spy: "in"
|
|
140
163
|
});
|
|
141
164
|
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() { } });
|
|
@@ -106,7 +106,7 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
|
106
106
|
}
|
|
107
107
|
observeQueue();
|
|
108
108
|
chunks.forEach((text, index) => {
|
|
109
|
-
this.doSynthesize({ text, voice, model
|
|
109
|
+
this.doSynthesize({ text, voice, model })
|
|
110
110
|
.then((synthesizedText) => {
|
|
111
111
|
results[index] = synthesizedText;
|
|
112
112
|
})
|
|
@@ -120,7 +120,6 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
|
120
120
|
doSynthesize(params) {
|
|
121
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
122
|
const { text, voice, model } = params;
|
|
123
|
-
console.log("xxxxxxxx doSynthesize", text, voice, model);
|
|
124
123
|
const response = yield this.client.generate({
|
|
125
124
|
stream: true,
|
|
126
125
|
voice,
|
|
@@ -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.
|
|
3
|
+
"version": "0.8.4",
|
|
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/
|
|
25
|
-
"@fonoster/
|
|
26
|
-
"@fonoster/
|
|
27
|
-
"@fonoster/
|
|
28
|
-
"@fonoster/
|
|
29
|
-
"@fonoster/
|
|
24
|
+
"@fonoster/authz": "^0.8.4",
|
|
25
|
+
"@fonoster/common": "^0.8.4",
|
|
26
|
+
"@fonoster/identity": "^0.8.4",
|
|
27
|
+
"@fonoster/logger": "^0.8.4",
|
|
28
|
+
"@fonoster/sipnet": "^0.8.4",
|
|
29
|
+
"@fonoster/streams": "^0.8.4",
|
|
30
|
+
"@fonoster/types": "^0.8.4",
|
|
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": "
|
|
76
|
+
"gitHead": "230bf0c9b793e5de49ffeb30ee1bd62226f55cba"
|
|
76
77
|
}
|