@fonoster/apiserver 0.5.5 → 0.6.1-alpha.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.
Files changed (224) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/applications/buildService.d.ts +29 -0
  4. package/dist/applications/buildService.js +44 -0
  5. package/dist/applications/createApplication.d.ts +6 -0
  6. package/dist/applications/createApplication.js +57 -0
  7. package/dist/applications/createGetFnUtil.d.ts +33 -0
  8. package/dist/applications/createGetFnUtil.js +32 -0
  9. package/dist/applications/deleteApplication.d.ts +6 -0
  10. package/dist/applications/deleteApplication.js +26 -0
  11. package/dist/applications/getApplication.d.ts +6 -0
  12. package/dist/applications/getApplication.js +47 -0
  13. package/dist/applications/hostOrHostPortSchema.d.ts +3 -0
  14. package/dist/applications/hostOrHostPortSchema.js +34 -0
  15. package/dist/applications/index.d.ts +1 -0
  16. package/dist/applications/index.js +23 -0
  17. package/dist/applications/listApplications.d.ts +6 -0
  18. package/dist/applications/listApplications.js +69 -0
  19. package/dist/applications/types.d.ts +27 -0
  20. package/dist/applications/types.js +2 -0
  21. package/dist/applications/updateApplication.d.ts +8 -0
  22. package/dist/applications/updateApplication.js +57 -0
  23. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +3 -0
  24. package/dist/applications/utils/applicationWithEncodedStruct.js +23 -0
  25. package/dist/applications/utils/convertToApplicationData.d.ts +4 -0
  26. package/dist/applications/utils/convertToApplicationData.js +38 -0
  27. package/dist/applications/utils/getApplicationValidationSchema.d.ts +64 -0
  28. package/dist/applications/utils/getApplicationValidationSchema.js +64 -0
  29. package/dist/applications/utils/prepareForValidation.d.ts +3 -0
  30. package/dist/applications/utils/prepareForValidation.js +36 -0
  31. package/dist/applications/utils/validOrThrow.d.ts +3 -0
  32. package/dist/applications/utils/validOrThrow.js +15 -0
  33. package/dist/calls/ListCallsRequestSchema.d.ts +28 -0
  34. package/dist/calls/ListCallsRequestSchema.js +58 -0
  35. package/dist/calls/buildService.d.ts +26 -0
  36. package/dist/calls/buildService.js +58 -0
  37. package/dist/calls/createCall.d.ts +6 -0
  38. package/dist/calls/createCall.js +64 -0
  39. package/dist/calls/createCallPublisher.d.ts +7 -0
  40. package/dist/calls/createCallPublisher.js +47 -0
  41. package/dist/calls/createFetchCalls.d.ts +3 -0
  42. package/dist/calls/createFetchCalls.js +87 -0
  43. package/dist/calls/createFetchSingleCall.d.ts +3 -0
  44. package/dist/calls/createFetchSingleCall.js +48 -0
  45. package/dist/calls/createTrackCallSubscriber.d.ts +6 -0
  46. package/dist/calls/createTrackCallSubscriber.js +53 -0
  47. package/dist/calls/getCall.d.ts +6 -0
  48. package/dist/calls/getCall.js +60 -0
  49. package/dist/calls/index.d.ts +1 -0
  50. package/dist/calls/index.js +23 -0
  51. package/dist/calls/influxdb.d.ts +2 -0
  52. package/dist/calls/influxdb.js +29 -0
  53. package/dist/calls/listCalls.d.ts +6 -0
  54. package/dist/calls/listCalls.js +52 -0
  55. package/dist/calls/runCallManager.d.ts +8 -0
  56. package/dist/calls/runCallManager.js +82 -0
  57. package/dist/calls/trackCall.d.ts +14 -0
  58. package/dist/calls/trackCall.js +64 -0
  59. package/dist/calls/types.d.ts +96 -0
  60. package/dist/calls/types.js +42 -0
  61. package/dist/core/allowList.d.ts +2 -0
  62. package/dist/core/allowList.js +31 -0
  63. package/dist/core/db.d.ts +13 -0
  64. package/dist/core/db.js +29 -0
  65. package/dist/core/filesServer.d.ts +5 -0
  66. package/dist/{ari_proxy.js → core/filesServer.js} +24 -20
  67. package/dist/core/identityConfig.d.ts +21 -0
  68. package/dist/core/identityConfig.js +43 -0
  69. package/dist/core/loadServices.d.ts +8 -0
  70. package/dist/core/loadServices.js +43 -0
  71. package/dist/core/notFoundError.d.ts +6 -0
  72. package/dist/core/notFoundError.js +27 -0
  73. package/dist/core/removeSwaggerNotice.d.ts +2 -0
  74. package/dist/core/removeSwaggerNotice.js +34 -0
  75. package/dist/core/routrConfig.d.ts +5 -0
  76. package/dist/core/routrConfig.js +27 -0
  77. package/dist/core/runServices.d.ts +2 -0
  78. package/dist/core/runServices.js +97 -0
  79. package/dist/core/seed.js +76 -0
  80. package/dist/core/services.d.ts +438 -0
  81. package/dist/core/services.js +53 -0
  82. package/dist/core/upsertDefaultPeer.d.ts +3 -0
  83. package/dist/core/upsertDefaultPeer.js +92 -0
  84. package/dist/envs.d.ts +46 -6
  85. package/dist/envs.js +95 -8
  86. package/dist/events/createInfluxDbPub.d.ts +13 -0
  87. package/dist/events/createInfluxDbPub.js +54 -0
  88. package/dist/events/nats.d.ts +10 -0
  89. package/dist/events/nats.js +85 -0
  90. package/dist/events/types.d.ts +8 -0
  91. package/dist/events/types.js +20 -0
  92. package/dist/index.js +53 -122
  93. package/dist/secrets/buildService.d.ts +37 -0
  94. package/dist/secrets/buildService.js +44 -0
  95. package/dist/secrets/createGetFnUtil.d.ts +16 -0
  96. package/dist/secrets/createGetFnUtil.js +46 -0
  97. package/dist/secrets/createSecret.d.ts +7 -0
  98. package/dist/secrets/createSecret.js +57 -0
  99. package/dist/secrets/deleteSecret.d.ts +8 -0
  100. package/dist/secrets/deleteSecret.js +44 -0
  101. package/dist/secrets/getSecret.d.ts +6 -0
  102. package/dist/secrets/getSecret.js +43 -0
  103. package/dist/secrets/index.d.ts +1 -0
  104. package/dist/secrets/index.js +23 -0
  105. package/dist/secrets/listSecrets.d.ts +7 -0
  106. package/dist/secrets/listSecrets.js +62 -0
  107. package/dist/secrets/types.d.ts +32 -0
  108. package/dist/secrets/types.js +2 -0
  109. package/dist/secrets/updateSecret.d.ts +8 -0
  110. package/dist/secrets/updateSecret.js +53 -0
  111. package/dist/utils/index.d.ts +1 -0
  112. package/dist/utils/index.js +35 -0
  113. package/dist/utils/makeCheckNumberPreconditions.d.ts +6 -0
  114. package/dist/utils/makeCheckNumberPreconditions.js +49 -0
  115. package/dist/voice/ChannelVarNotFoundError.d.ts +5 -0
  116. package/dist/voice/ChannelVarNotFoundError.js +10 -0
  117. package/dist/voice/MethodNotImplementedError.d.ts +4 -0
  118. package/dist/voice/MethodNotImplementedError.js +27 -0
  119. package/dist/voice/VoiceClientImpl.d.ts +42 -0
  120. package/dist/voice/VoiceClientImpl.js +192 -0
  121. package/dist/voice/VoiceDispatcher.d.ts +17 -0
  122. package/dist/voice/VoiceDispatcher.js +99 -0
  123. package/dist/voice/VoiceServiceClientConst.d.ts +3 -0
  124. package/dist/voice/VoiceServiceClientConst.js +53 -0
  125. package/dist/voice/connectToAri.d.ts +2 -0
  126. package/dist/voice/connectToAri.js +80 -0
  127. package/dist/voice/createExternalMediaConfig.d.ts +9 -0
  128. package/dist/voice/createExternalMediaConfig.js +35 -0
  129. package/dist/voice/handlers/Answer.d.ts +5 -0
  130. package/dist/voice/handlers/Answer.js +25 -0
  131. package/dist/voice/handlers/Hangup.d.ts +5 -0
  132. package/dist/voice/handlers/Hangup.js +26 -0
  133. package/dist/voice/handlers/Mute.d.ts +4 -0
  134. package/dist/voice/handlers/Mute.js +28 -0
  135. package/dist/voice/handlers/Play.d.ts +4 -0
  136. package/dist/voice/handlers/Play.js +34 -0
  137. package/dist/voice/handlers/PlayDtmf.d.ts +4 -0
  138. package/dist/voice/handlers/PlayDtmf.js +28 -0
  139. package/dist/voice/handlers/PlaybackControl.d.ts +4 -0
  140. package/dist/voice/handlers/PlaybackControl.js +28 -0
  141. package/dist/voice/handlers/Record.d.ts +4 -0
  142. package/dist/voice/handlers/Record.js +59 -0
  143. package/dist/voice/handlers/Say.d.ts +4 -0
  144. package/dist/voice/handlers/Say.js +46 -0
  145. package/dist/voice/handlers/StasisEnd.d.ts +4 -0
  146. package/dist/voice/handlers/StasisEnd.js +28 -0
  147. package/dist/voice/handlers/Unmute.d.ts +4 -0
  148. package/dist/voice/handlers/Unmute.js +28 -0
  149. package/dist/voice/handlers/awaitForPlaybackFinished.d.ts +3 -0
  150. package/dist/voice/handlers/awaitForPlaybackFinished.js +25 -0
  151. package/dist/voice/handlers/awaitForRecordingFinished.d.ts +5 -0
  152. package/dist/voice/handlers/awaitForRecordingFinished.js +54 -0
  153. package/dist/voice/handlers/dial/Dial.d.ts +5 -0
  154. package/dist/voice/handlers/dial/Dial.js +72 -0
  155. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +6 -0
  156. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +30 -0
  157. package/dist/voice/handlers/dial/handleDialEvents.d.ts +5 -0
  158. package/dist/voice/handlers/dial/handleDialEvents.js +55 -0
  159. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +3 -0
  160. package/dist/voice/handlers/dial/handleStasisEnd.js +20 -0
  161. package/dist/voice/handlers/dial/handleStasisStart.d.ts +9 -0
  162. package/dist/voice/handlers/dial/handleStasisStart.js +54 -0
  163. package/dist/voice/handlers/dial/recordChannel.d.ts +4 -0
  164. package/dist/voice/handlers/dial/recordChannel.js +46 -0
  165. package/dist/voice/handlers/gather/Gather.d.ts +3 -0
  166. package/dist/voice/handlers/gather/Gather.js +73 -0
  167. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +8 -0
  168. package/dist/voice/handlers/gather/getTimeoutPromise.js +19 -0
  169. package/dist/voice/handlers/withErrorHandling.d.ts +4 -0
  170. package/dist/voice/handlers/withErrorHandling.js +36 -0
  171. package/dist/voice/integrations/ApplicationNotFoundError.d.ts +4 -0
  172. package/dist/voice/integrations/ApplicationNotFoundError.js +28 -0
  173. package/dist/voice/integrations/findIntegrationsCredentials.d.ts +3 -0
  174. package/dist/voice/integrations/findIntegrationsCredentials.js +7 -0
  175. package/dist/voice/integrations/getSttConfig.d.ts +7 -0
  176. package/dist/voice/integrations/getSttConfig.js +10 -0
  177. package/dist/voice/integrations/getTtsConfig.d.ts +7 -0
  178. package/dist/voice/integrations/getTtsConfig.js +11 -0
  179. package/dist/voice/integrations/index.d.ts +1 -0
  180. package/dist/voice/integrations/index.js +35 -0
  181. package/dist/voice/integrations/makeCreateContainer.d.ts +4 -0
  182. package/dist/voice/integrations/makeCreateContainer.js +89 -0
  183. package/dist/voice/integrations/types.d.ts +15 -0
  184. package/dist/voice/integrations/types.js +2 -0
  185. package/dist/voice/makeCreateVoiceClient.d.ts +9 -0
  186. package/dist/voice/makeCreateVoiceClient.js +78 -0
  187. package/dist/voice/makeGetChannelVar.d.ts +4 -0
  188. package/dist/voice/makeGetChannelVar.js +26 -0
  189. package/dist/voice/stt/AbstractSpeechToText.d.ts +15 -0
  190. package/dist/voice/stt/AbstractSpeechToText.js +19 -0
  191. package/dist/voice/stt/Google.d.ts +20 -0
  192. package/dist/voice/stt/Google.js +99 -0
  193. package/dist/voice/stt/SpeechToTextFactory.d.ts +9 -0
  194. package/dist/voice/stt/SpeechToTextFactory.js +41 -0
  195. package/dist/voice/stt/types.d.ts +25 -0
  196. package/dist/voice/stt/types.js +2 -0
  197. package/dist/voice/transcribeOnConnection.d.ts +5 -0
  198. package/dist/voice/transcribeOnConnection.js +27 -0
  199. package/dist/voice/tts/AbstractTextToSpeech.d.ts +18 -0
  200. package/dist/voice/tts/AbstractTextToSpeech.js +82 -0
  201. package/dist/voice/tts/Azure.d.ts +30 -0
  202. package/dist/voice/tts/Azure.js +128 -0
  203. package/dist/voice/tts/Google.d.ts +25 -0
  204. package/dist/voice/tts/Google.js +116 -0
  205. package/dist/voice/tts/TextToSpeechFactory.d.ts +9 -0
  206. package/dist/voice/tts/TextToSpeechFactory.js +43 -0
  207. package/dist/voice/tts/computeFilename.d.ts +7 -0
  208. package/dist/voice/tts/computeFilename.js +39 -0
  209. package/dist/voice/tts/flattenObject.d.ts +2 -0
  210. package/dist/voice/tts/flattenObject.js +39 -0
  211. package/dist/voice/tts/isSsml.d.ts +2 -0
  212. package/dist/voice/tts/isSsml.js +26 -0
  213. package/dist/voice/tts/types.d.ts +7 -0
  214. package/dist/voice/tts/types.js +2 -0
  215. package/dist/voice/types/ari.d.ts +21 -0
  216. package/dist/voice/types/ari.js +43 -0
  217. package/dist/voice/types/index.d.ts +2 -0
  218. package/dist/voice/types/index.js +36 -0
  219. package/dist/voice/types/voice.d.ts +34 -0
  220. package/dist/voice/types/voice.js +2 -0
  221. package/package.json +45 -36
  222. package/dist/upsert_peer.d.ts +0 -1
  223. package/dist/upsert_peer.js +0 -63
  224. /package/dist/{ari_proxy.d.ts → core/seed.d.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createTrackCallSubscriber = void 0;
16
+ /*
17
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
18
+ * http://github.com/fonoster/fonoster
19
+ *
20
+ * This file is part of Fonoster
21
+ *
22
+ * Licensed under the MIT License (the "License");
23
+ * you may not use this file except in compliance with
24
+ * the License. You may obtain a copy of the License at
25
+ *
26
+ * https://opensource.org/licenses/MIT
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ const events_1 = __importDefault(require("events"));
35
+ const nats_1 = require("nats");
36
+ const envs_1 = require("../envs");
37
+ function createTrackCallSubscriber(natsUrl) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const nc = yield (0, nats_1.connect)({ servers: natsUrl });
40
+ return () => {
41
+ const events = new events_1.default();
42
+ const subscription = nc.subscribe(envs_1.CALLS_TRACK_CALL_SUBJECT);
43
+ subscription.callback = (err, msg) => {
44
+ if (err) {
45
+ events.emit("error", err);
46
+ }
47
+ events.emit("status", msg.json());
48
+ };
49
+ return { events };
50
+ };
51
+ });
52
+ }
53
+ exports.createTrackCallSubscriber = createTrackCallSubscriber;
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { CallDetailRecord, GetCallRequest, InfluxDBClient } from "./types";
3
+ declare function getCall(influx: InfluxDBClient): (call: {
4
+ request: GetCallRequest;
5
+ }, callback: (error: GrpcErrorMessage, response?: CallDetailRecord) => void) => Promise<void>;
6
+ export { getCall };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getCall = void 0;
13
+ /*
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const common_1 = require("@fonoster/common");
32
+ const identity_1 = require("@fonoster/identity");
33
+ const logger_1 = require("@fonoster/logger");
34
+ const zod_1 = require("zod");
35
+ const createFetchSingleCall_1 = require("./createFetchSingleCall");
36
+ const notFoundError_1 = require("../core/notFoundError");
37
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
+ const GetCallRequestSchema = zod_1.z.object({
39
+ ref: zod_1.z.string({ message: "Invalid call reference" })
40
+ });
41
+ function getCall(influx) {
42
+ const fetchSingleCall = (0, createFetchSingleCall_1.createFetchSingleCall)(influx);
43
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
44
+ try {
45
+ const { ref } = call.request;
46
+ GetCallRequestSchema.parse({ ref });
47
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
48
+ logger.verbose("call to getCall", { accessKeyId, ref });
49
+ const response = yield fetchSingleCall(accessKeyId, ref);
50
+ if (!response) {
51
+ throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
52
+ }
53
+ callback(null, response);
54
+ }
55
+ catch (error) {
56
+ (0, common_1.handleError)(error, callback);
57
+ }
58
+ });
59
+ }
60
+ exports.getCall = getCall;
@@ -0,0 +1 @@
1
+ export { buildService as buildCallsService } from "./buildService";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCallsService = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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
+ var buildService_1 = require("./buildService");
23
+ Object.defineProperty(exports, "buildCallsService", { enumerable: true, get: function () { return buildService_1.buildService; } });
@@ -0,0 +1,2 @@
1
+ declare const influxdb: import("@influxdata/influxdb-client").QueryApi;
2
+ export { influxdb };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.influxdb = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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 influxdb_client_1 = require("@influxdata/influxdb-client");
23
+ const envs_1 = require("../envs");
24
+ const client = new influxdb_client_1.InfluxDB({
25
+ url: envs_1.INFLUXDB_URL,
26
+ token: envs_1.INFLUXDB_TOKEN
27
+ });
28
+ const influxdb = client.getQueryApi(envs_1.INFLUXDB_ORG);
29
+ exports.influxdb = influxdb;
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { InfluxDBClient, ListCallsRequest, ListCallsResponse } from "./types";
3
+ declare function listCalls(influx: InfluxDBClient): (call: {
4
+ request: ListCallsRequest;
5
+ }, callback: (error: GrpcErrorMessage, response?: ListCallsResponse) => void) => Promise<void>;
6
+ export { listCalls };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.listCalls = void 0;
13
+ /*
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const common_1 = require("@fonoster/common");
32
+ const identity_1 = require("@fonoster/identity");
33
+ const logger_1 = require("@fonoster/logger");
34
+ const createFetchCalls_1 = require("./createFetchCalls");
35
+ const ListCallsRequestSchema_1 = require("./ListCallsRequestSchema");
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ function listCalls(influx) {
38
+ const fetchCalls = (0, createFetchCalls_1.createFetchCalls)(influx);
39
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
+ try {
41
+ const parsedRequest = ListCallsRequestSchema_1.ListCallsRequestSchema.parse(call.request);
42
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
43
+ logger.verbose("call to listCalls", { parsedRequest, accessKeyId });
44
+ const result = yield fetchCalls(accessKeyId, parsedRequest);
45
+ callback(null, result);
46
+ }
47
+ catch (error) {
48
+ (0, common_1.handleError)(error, callback);
49
+ }
50
+ });
51
+ }
52
+ exports.listCalls = listCalls;
@@ -0,0 +1,8 @@
1
+ type CallManagerConfig = {
2
+ natsUrl: string;
3
+ ariProxyUrl: string;
4
+ ariUsername: string;
5
+ ariPassword: string;
6
+ };
7
+ declare function createCreateCallSubscriber(config: CallManagerConfig): Promise<void>;
8
+ export { createCreateCallSubscriber };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createCreateCallSubscriber = void 0;
16
+ /*
17
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
18
+ * http://github.com/fonoster/fonoster
19
+ *
20
+ * This file is part of Fonoster
21
+ *
22
+ * Licensed under the MIT License (the "License");
23
+ * you may not use this file except in compliance with
24
+ * the License. You may obtain a copy of the License at
25
+ *
26
+ * https://opensource.org/licenses/MIT
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ const logger_1 = require("@fonoster/logger");
35
+ const ari_client_1 = __importDefault(require("ari-client"));
36
+ const nats_1 = require("nats");
37
+ const envs_1 = require("../envs");
38
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
39
+ function createCreateCallSubscriber(config) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const { natsUrl, ariProxyUrl, ariUsername, ariPassword } = config;
42
+ try {
43
+ logger.verbose("connecting to nats", { natsUrl });
44
+ const nc = yield (0, nats_1.connect)({ servers: natsUrl });
45
+ logger.verbose("subscribing to call create subject", {
46
+ subject: envs_1.CALLS_CREATE_SUBJECT
47
+ });
48
+ const subscription = nc.subscribe(envs_1.CALLS_CREATE_SUBJECT, {
49
+ queue: envs_1.DEFAULT_NATS_QUEUE_GROUP
50
+ });
51
+ logger.verbose("connecting to ari", { ariProxyUrl });
52
+ const ariConn = yield ari_client_1.default.connect(ariProxyUrl, ariUsername, ariPassword);
53
+ subscription.callback = (err, msg) => __awaiter(this, void 0, void 0, function* () {
54
+ if (err) {
55
+ logger.error(err);
56
+ }
57
+ const { ref, from, to, appRef } = msg.json();
58
+ logger.info("received a new call request", Object.assign({ callRef: ref }, msg.json()));
59
+ // eslint-disable-next-line new-cap
60
+ const channel = ariConn.Channel();
61
+ channel
62
+ .originate({
63
+ context: envs_1.ASTERISK_CONTEXT,
64
+ extension: envs_1.ASTERISK_EXTENSION,
65
+ endpoint: `PJSIP/${envs_1.ASTERISK_TRUNK}/sip:${to}@${envs_1.ASTERISK_SYSTEM_DOMAIN}`,
66
+ variables: {
67
+ "PJSIP_HEADER(add,X-DOD-Number)": from,
68
+ INGRESS_NUMBER: from,
69
+ APP_REF: appRef
70
+ }
71
+ })
72
+ .catch((err) => {
73
+ logger.error("error creating call", { err });
74
+ });
75
+ });
76
+ }
77
+ catch (e) {
78
+ logger.error("error connecting to ari", { e });
79
+ }
80
+ });
81
+ }
82
+ exports.createCreateCallSubscriber = createCreateCallSubscriber;
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ import { TrackCallSubscriber } from "./types";
3
+ declare const TrackCallRequestSchema: z.ZodObject<{
4
+ ref: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ ref?: string;
7
+ }, {
8
+ ref?: string;
9
+ }>;
10
+ type TrackCallRequest = z.infer<typeof TrackCallRequestSchema>;
11
+ declare function trackCall(subs: TrackCallSubscriber): (call: {
12
+ request: TrackCallRequest;
13
+ }) => void;
14
+ export { trackCall };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackCall = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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 logger_1 = require("@fonoster/logger");
23
+ const grpc_js_1 = require("@grpc/grpc-js");
24
+ const zod_1 = require("zod");
25
+ const types_1 = require("./types");
26
+ const FINAL_STATUSES = [
27
+ types_1.CallStatus.COMPLETED,
28
+ types_1.CallStatus.FAILED,
29
+ types_1.CallStatus.BUSY,
30
+ types_1.CallStatus.NO_ANSWER,
31
+ types_1.CallStatus.CANCELED,
32
+ types_1.CallStatus.REJECTED,
33
+ types_1.CallStatus.TIMEOUT,
34
+ types_1.CallStatus.UNKNOWN
35
+ ];
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ const TrackCallRequestSchema = zod_1.z.object({
38
+ ref: zod_1.z.string()
39
+ });
40
+ function trackCall(subs) {
41
+ return (call) => {
42
+ const stream = call;
43
+ const { events } = subs;
44
+ const { ref } = call.request;
45
+ logger.verbose("call to trackCall", { ref });
46
+ stream.write({ ref, status: types_1.CallStatus.QUEUED });
47
+ events.on("status", (data) => {
48
+ logger.verbose("tracked call status change", Object.assign({}, data));
49
+ if (data instanceof Error) {
50
+ logger.error("tracked call status change error", Object.assign({}, data));
51
+ stream.write({ code: grpc_js_1.status.INTERNAL, message: data.message });
52
+ stream.end();
53
+ return;
54
+ }
55
+ if (data.ref === ref) {
56
+ stream.write(data);
57
+ if (FINAL_STATUSES.includes(data.status)) {
58
+ stream.end();
59
+ }
60
+ }
61
+ });
62
+ };
63
+ }
64
+ exports.trackCall = trackCall;
@@ -0,0 +1,96 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { ParameterizedQuery } from "@influxdata/influxdb-client";
3
+ declare const CALL_DETAIL_RECORD_MEASUREMENT = "cdr";
4
+ declare enum CallType {
5
+ PROGRAMMABLE = "PROGRAMMABLE",
6
+ SIP_TRUNKING = "SIP_TRUNKING"
7
+ }
8
+ declare enum HangupCause {
9
+ NORMAL_CLEARING = "NORMAL_CLEARING",
10
+ CALL_REJECTED = "CALL_REJECTED",
11
+ UNALLOCATED = "UNALLOCATED",
12
+ NO_USER_RESPONSE = "NO_USER_RESPONSE",
13
+ NO_ROUTE_DESTINATION = "NO_ROUTE_DESTINATION",
14
+ NO_ANSWER = "NO_ANSWER",
15
+ USER_BUSY = "USER_BUSY",
16
+ NOT_ACCEPTABLE_HERE = "NOT_ACCEPTABLE_HERE",
17
+ SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
18
+ INVALID_NUMBER_FORMAT = "INVALID_NUMBER_FORMAT"
19
+ }
20
+ declare enum CallStatus {
21
+ QUEUED = "QUEUED",
22
+ RINGING = "RINGING",
23
+ IN_PROGRESS = "IN_PROGRESS",
24
+ COMPLETED = "COMPLETED",
25
+ FAILED = "FAILED",
26
+ BUSY = "BUSY",
27
+ NO_ANSWER = "NO_ANSWER",
28
+ CANCELED = "CANCELED",
29
+ REJECTED = "REJECTED",
30
+ TIMEOUT = "TIMEOUT",
31
+ UNKNOWN = "UNKNOWN"
32
+ }
33
+ declare enum CallDirection {
34
+ INBOUND = "INBOUND",
35
+ OUTBOUND = "OUTBOUND"
36
+ }
37
+ type CallDetailRecord = {
38
+ ref: string;
39
+ type: CallType;
40
+ status: CallStatus;
41
+ hangupCause: HangupCause;
42
+ from: string;
43
+ to: string;
44
+ duration: number;
45
+ direction: CallDirection;
46
+ startedAt: number;
47
+ endedAt: number;
48
+ };
49
+ type ListCallsRequest = {
50
+ after?: string;
51
+ before?: string;
52
+ type?: CallType;
53
+ status?: CallStatus;
54
+ hangupCause?: HangupCause;
55
+ from?: string;
56
+ to?: string;
57
+ pageSize?: number;
58
+ pageToken?: string;
59
+ };
60
+ type ListCallsResponse = {
61
+ nextPageToken?: string;
62
+ items: CallDetailRecord[];
63
+ };
64
+ type GetCallRequest = {
65
+ ref: string;
66
+ };
67
+ type InfluxDBClient = {
68
+ collectRows(query: ParameterizedQuery): Promise<unknown[]>;
69
+ };
70
+ type CreateCallRequest = {
71
+ from: string;
72
+ to: string;
73
+ appRef?: string;
74
+ };
75
+ type CreateCallResponse = {
76
+ ref: string;
77
+ };
78
+ type CallPublisher = {
79
+ publishCall: (event: CreateCallRequest & {
80
+ ref: string;
81
+ }) => void;
82
+ };
83
+ type TrackCallResponse = {
84
+ ref: string;
85
+ status: CallStatus;
86
+ };
87
+ type CallStream = {
88
+ write: (data: TrackCallResponse | GrpcErrorMessage) => void;
89
+ end: () => void;
90
+ };
91
+ type TrackCallSubscriber = {
92
+ events: {
93
+ on: (event: string, cb: (data: TrackCallResponse | Error) => void) => void;
94
+ };
95
+ };
96
+ export { CALL_DETAIL_RECORD_MEASUREMENT, CallDetailRecord, ListCallsRequest, ListCallsResponse, GetCallRequest, CallType, CallStatus, CallDirection, InfluxDBClient, CreateCallRequest, CreateCallResponse, CallPublisher, TrackCallResponse, CallStream, TrackCallSubscriber, HangupCause };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HangupCause = exports.CallDirection = exports.CallStatus = exports.CallType = exports.CALL_DETAIL_RECORD_MEASUREMENT = void 0;
4
+ const CALL_DETAIL_RECORD_MEASUREMENT = "cdr";
5
+ exports.CALL_DETAIL_RECORD_MEASUREMENT = CALL_DETAIL_RECORD_MEASUREMENT;
6
+ var CallType;
7
+ (function (CallType) {
8
+ CallType["PROGRAMMABLE"] = "PROGRAMMABLE";
9
+ CallType["SIP_TRUNKING"] = "SIP_TRUNKING";
10
+ })(CallType || (exports.CallType = CallType = {}));
11
+ var HangupCause;
12
+ (function (HangupCause) {
13
+ HangupCause["NORMAL_CLEARING"] = "NORMAL_CLEARING";
14
+ HangupCause["CALL_REJECTED"] = "CALL_REJECTED";
15
+ HangupCause["UNALLOCATED"] = "UNALLOCATED";
16
+ HangupCause["NO_USER_RESPONSE"] = "NO_USER_RESPONSE";
17
+ HangupCause["NO_ROUTE_DESTINATION"] = "NO_ROUTE_DESTINATION";
18
+ HangupCause["NO_ANSWER"] = "NO_ANSWER";
19
+ HangupCause["USER_BUSY"] = "USER_BUSY";
20
+ HangupCause["NOT_ACCEPTABLE_HERE"] = "NOT_ACCEPTABLE_HERE";
21
+ HangupCause["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
22
+ HangupCause["INVALID_NUMBER_FORMAT"] = "INVALID_NUMBER_FORMAT";
23
+ })(HangupCause || (exports.HangupCause = HangupCause = {}));
24
+ var CallStatus;
25
+ (function (CallStatus) {
26
+ CallStatus["QUEUED"] = "QUEUED";
27
+ CallStatus["RINGING"] = "RINGING";
28
+ CallStatus["IN_PROGRESS"] = "IN_PROGRESS";
29
+ CallStatus["COMPLETED"] = "COMPLETED";
30
+ CallStatus["FAILED"] = "FAILED";
31
+ CallStatus["BUSY"] = "BUSY";
32
+ CallStatus["NO_ANSWER"] = "NO_ANSWER";
33
+ CallStatus["CANCELED"] = "CANCELED";
34
+ CallStatus["REJECTED"] = "REJECTED";
35
+ CallStatus["TIMEOUT"] = "TIMEOUT";
36
+ CallStatus["UNKNOWN"] = "UNKNOWN";
37
+ })(CallStatus || (exports.CallStatus = CallStatus = {}));
38
+ var CallDirection;
39
+ (function (CallDirection) {
40
+ CallDirection["INBOUND"] = "INBOUND";
41
+ CallDirection["OUTBOUND"] = "OUTBOUND";
42
+ })(CallDirection || (exports.CallDirection = CallDirection = {}));
@@ -0,0 +1,2 @@
1
+ declare const allowList: string[];
2
+ export { allowList };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allowList = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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 allowList = [
23
+ "/grpc.health.v1.Health/Check",
24
+ "/fonoster.identity.v1beta2.Identity/CreateUser",
25
+ "/fonoster.identity.v1beta2.Identity/CreateWorkspace",
26
+ "/fonoster.identity.v1beta2.Identity/ExchangeApiKey",
27
+ "/fonoster.identity.v1beta2.Identity/ExchangeCredentials",
28
+ "/fonoster.identity.v1beta2.Identity/ExchangeRefreshToken",
29
+ "/fonoster.identity.v1beta2.Identity/GetPublicKey"
30
+ ];
31
+ exports.allowList = allowList;
@@ -0,0 +1,13 @@
1
+ declare const prisma: import("@prisma/client/runtime/library").DynamicClientExtensionThis<import(".prisma/client").Prisma.TypeMap<import("@prisma/client/runtime/library").InternalArgs & {
2
+ result: {};
3
+ model: {};
4
+ query: {};
5
+ client: {};
6
+ }>, import(".prisma/client").Prisma.TypeMapCb, {
7
+ result: {};
8
+ model: {};
9
+ query: {};
10
+ client: {};
11
+ }>;
12
+ type Prisma = typeof prisma;
13
+ export { prisma, Prisma };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prisma = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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 client_1 = require("@prisma/client");
23
+ const prisma_field_encryption_1 = require("prisma-field-encryption");
24
+ const envs_1 = require("../envs");
25
+ // We encrypt all fields marked with /// encrypted in the schema
26
+ const prisma = new client_1.PrismaClient().$extends((0, prisma_field_encryption_1.fieldEncryptionExtension)({
27
+ encryptionKey: envs_1.CLOAK_ENCRYPTION_KEY
28
+ }));
29
+ exports.prisma = prisma;
@@ -0,0 +1,5 @@
1
+ declare function filesServer(params: {
2
+ pathToFiles: string;
3
+ port: number;
4
+ }): void;
5
+ export { filesServer };