@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,64 @@
1
+ import { z } from "zod";
2
+ declare function getApplicationValidationSchema(request: {
3
+ ttsEngineName: string;
4
+ sttEngineName: string;
5
+ }): z.ZodObject<{
6
+ name: z.ZodString;
7
+ type: z.ZodNativeEnum<{
8
+ PROGRAMMABLE_VOICE: "PROGRAMMABLE_VOICE";
9
+ }>;
10
+ appEndpoint: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string, string>;
11
+ textToSpeech: z.ZodUndefined | z.ZodObject<{
12
+ productRef: z.ZodString;
13
+ config: any;
14
+ }, "strip", z.ZodTypeAny, {
15
+ [x: string]: any;
16
+ productRef?: unknown;
17
+ config?: unknown;
18
+ }, {
19
+ [x: string]: any;
20
+ productRef?: unknown;
21
+ config?: unknown;
22
+ }>;
23
+ speechToText: z.ZodUndefined | z.ZodObject<{
24
+ productRef: z.ZodString;
25
+ config: any;
26
+ }, "strip", z.ZodTypeAny, {
27
+ [x: string]: any;
28
+ productRef?: unknown;
29
+ config?: unknown;
30
+ }, {
31
+ [x: string]: any;
32
+ productRef?: unknown;
33
+ config?: unknown;
34
+ }>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ name?: string;
37
+ type?: "PROGRAMMABLE_VOICE";
38
+ textToSpeech?: {
39
+ [x: string]: any;
40
+ productRef?: unknown;
41
+ config?: unknown;
42
+ };
43
+ speechToText?: {
44
+ [x: string]: any;
45
+ productRef?: unknown;
46
+ config?: unknown;
47
+ };
48
+ appEndpoint?: string;
49
+ }, {
50
+ name?: string;
51
+ type?: "PROGRAMMABLE_VOICE";
52
+ textToSpeech?: {
53
+ [x: string]: any;
54
+ productRef?: unknown;
55
+ config?: unknown;
56
+ };
57
+ speechToText?: {
58
+ [x: string]: any;
59
+ productRef?: unknown;
60
+ config?: unknown;
61
+ };
62
+ appEndpoint?: string;
63
+ }>;
64
+ export { getApplicationValidationSchema };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getApplicationValidationSchema = 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 zod_1 = require("zod");
24
+ const Google_1 = require("../../voice/stt/Google");
25
+ const Azure_1 = require("../../voice/tts/Azure");
26
+ const Google_2 = require("../../voice/tts/Google");
27
+ const hostOrHostPortSchema_1 = require("../hostOrHostPortSchema");
28
+ const validators = {
29
+ ttsConfigValidators: {
30
+ "tts.google": Google_2.Google.getConfigValidationSchema,
31
+ "tts.azure": Azure_1.Azure.getConfigValidationSchema
32
+ },
33
+ ttsCredentialsValidators: {
34
+ "tts.google": Google_2.Google.getCredentialsValidationSchema,
35
+ "tts.azure": Azure_1.Azure.getCredentialsValidationSchema
36
+ },
37
+ sttConfigValidators: {
38
+ "stt.google": Google_1.Google.getConfigValidationSchema
39
+ },
40
+ sttCredentialsValidators: {
41
+ "stt.google": Google_1.Google.getCredentialsValidationSchema
42
+ }
43
+ };
44
+ function getApplicationValidationSchema(request) {
45
+ const { ttsEngineName, sttEngineName } = request;
46
+ return zod_1.z.object({
47
+ name: zod_1.z.string(),
48
+ type: zod_1.z.nativeEnum(client_1.ApplicationType),
49
+ appEndpoint: hostOrHostPortSchema_1.hostOrHostPortSchema,
50
+ textToSpeech: ttsEngineName
51
+ ? zod_1.z.object({
52
+ productRef: zod_1.z.string(),
53
+ config: validators.ttsConfigValidators[ttsEngineName]()
54
+ })
55
+ : zod_1.z.undefined(),
56
+ speechToText: sttEngineName
57
+ ? zod_1.z.object({
58
+ productRef: zod_1.z.string(),
59
+ config: validators.sttConfigValidators[sttEngineName]()
60
+ })
61
+ : zod_1.z.undefined()
62
+ });
63
+ }
64
+ exports.getApplicationValidationSchema = getApplicationValidationSchema;
@@ -0,0 +1,3 @@
1
+ import { Application, CreateApplicationRequest, UpdateApplicationRequest } from "@fonoster/common";
2
+ declare function prepareForValidation(request: CreateApplicationRequest | UpdateApplicationRequest): Application;
3
+ export { prepareForValidation };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareForValidation = void 0;
4
+ const client_1 = require("@prisma/client");
5
+ const pb_util_1 = require("pb-util");
6
+ function prepareForValidation(request) {
7
+ const type = request.type || client_1.ApplicationType.PROGRAMMABLE_VOICE;
8
+ const result = {
9
+ ref: request.ref, // Only for UpdateApplicationRequest
10
+ name: request.name,
11
+ type,
12
+ appEndpoint: request.appEndpoint
13
+ };
14
+ const createProperty = (property) => {
15
+ return property
16
+ ? {
17
+ productRef: property.productRef,
18
+ credentials: property.credentials
19
+ ? pb_util_1.struct.decode(property.credentials)
20
+ : undefined,
21
+ config: property.config ? pb_util_1.struct.decode(property.config) : null
22
+ }
23
+ : undefined;
24
+ };
25
+ if (request.textToSpeech) {
26
+ result.textToSpeech = createProperty(request.textToSpeech);
27
+ }
28
+ if (request.speechToText) {
29
+ result.speechToText = createProperty(request.speechToText);
30
+ }
31
+ if (request.intelligence) {
32
+ result.intelligence = createProperty(request.intelligence);
33
+ }
34
+ return result;
35
+ }
36
+ exports.prepareForValidation = prepareForValidation;
@@ -0,0 +1,3 @@
1
+ import { CreateApplicationRequest, UpdateApplicationRequest } from "@fonoster/common";
2
+ declare function validOrThrow(request: CreateApplicationRequest | UpdateApplicationRequest): void;
3
+ export { validOrThrow };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validOrThrow = void 0;
4
+ const getApplicationValidationSchema_1 = require("./getApplicationValidationSchema");
5
+ const prepareForValidation_1 = require("./prepareForValidation");
6
+ function validOrThrow(request) {
7
+ var _a, _b;
8
+ const data = (0, prepareForValidation_1.prepareForValidation)(request);
9
+ const schema = (0, getApplicationValidationSchema_1.getApplicationValidationSchema)({
10
+ ttsEngineName: (_a = request.textToSpeech) === null || _a === void 0 ? void 0 : _a.productRef,
11
+ sttEngineName: (_b = request.speechToText) === null || _b === void 0 ? void 0 : _b.productRef
12
+ });
13
+ schema.parse(data);
14
+ }
15
+ exports.validOrThrow = validOrThrow;
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import { CallStatus, CallType, HangupCause } from "./types";
3
+ declare const ListCallsRequestSchema: z.ZodObject<{
4
+ after: z.ZodNullable<z.ZodOptional<z.ZodString>>;
5
+ before: z.ZodNullable<z.ZodOptional<z.ZodString>>;
6
+ pageSize: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
7
+ type: z.ZodNullable<z.ZodOptional<z.ZodNativeEnum<typeof CallType>>>;
8
+ hangupCause: z.ZodNullable<z.ZodOptional<z.ZodNativeEnum<typeof HangupCause>>>;
9
+ status: z.ZodNullable<z.ZodOptional<z.ZodNativeEnum<typeof CallStatus>>>;
10
+ pageToken: z.ZodNullable<z.ZodOptional<z.ZodString>>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ type?: CallType;
13
+ status?: CallStatus;
14
+ pageSize?: number;
15
+ pageToken?: string;
16
+ after?: string;
17
+ before?: string;
18
+ hangupCause?: HangupCause;
19
+ }, {
20
+ type?: CallType;
21
+ status?: CallStatus;
22
+ pageSize?: number;
23
+ pageToken?: string;
24
+ after?: string;
25
+ before?: string;
26
+ hangupCause?: HangupCause;
27
+ }>;
28
+ export { ListCallsRequestSchema };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListCallsRequestSchema = 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 zod_1 = require("zod");
23
+ const types_1 = require("./types");
24
+ const ListCallsRequestSchema = zod_1.z.object({
25
+ after: zod_1.z
26
+ .string()
27
+ .datetime({ offset: true, message: "The date must be a valid ISO 8601" })
28
+ .optional()
29
+ .nullable(),
30
+ before: zod_1.z
31
+ .string()
32
+ .datetime({ offset: true, message: "The date must be a valid ISO 8601" })
33
+ .optional()
34
+ .nullable(),
35
+ pageSize: zod_1.z
36
+ .number({ message: "Invalid pageSize value" })
37
+ .optional()
38
+ .nullable(),
39
+ type: zod_1.z
40
+ .nativeEnum(types_1.CallType, {
41
+ message: "Invalid call type"
42
+ })
43
+ .optional()
44
+ .nullable(),
45
+ hangupCause: zod_1.z
46
+ .nativeEnum(types_1.HangupCause, { message: "Invalid hangup cause" })
47
+ .optional()
48
+ .nullable(),
49
+ status: zod_1.z
50
+ .nativeEnum(types_1.CallStatus, { message: "Invalid call status" })
51
+ .optional()
52
+ .nullable(),
53
+ pageToken: zod_1.z
54
+ .string({ message: "The pageToken must be a string" })
55
+ .optional()
56
+ .nullable()
57
+ });
58
+ exports.ListCallsRequestSchema = ListCallsRequestSchema;
@@ -0,0 +1,26 @@
1
+ import { InfluxDBClient } from "./types";
2
+ declare function buildService(influxdb: InfluxDBClient): Promise<{
3
+ definition: {
4
+ serviceName: string;
5
+ pckg: string;
6
+ version: string;
7
+ proto: string;
8
+ };
9
+ handlers: {
10
+ createCall: (call: {
11
+ request: import("./types").CreateCallRequest;
12
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("./types").CreateCallResponse) => void) => Promise<void>;
13
+ listCalls: (call: {
14
+ request: import("./types").ListCallsRequest;
15
+ }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("./types").ListCallsResponse) => void) => Promise<void>;
16
+ getCall: (call: {
17
+ request: import("./types").GetCallRequest;
18
+ }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("./types").CallDetailRecord) => void) => Promise<void>;
19
+ trackCall: (call: {
20
+ request: {
21
+ ref?: string;
22
+ };
23
+ }) => void;
24
+ };
25
+ }>;
26
+ export { buildService };
@@ -0,0 +1,58 @@
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.buildService = 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 createCall_1 = require("./createCall");
32
+ const createCallPublisher_1 = require("./createCallPublisher");
33
+ const createTrackCallSubscriber_1 = require("./createTrackCallSubscriber");
34
+ const getCall_1 = require("./getCall");
35
+ const listCalls_1 = require("./listCalls");
36
+ const trackCall_1 = require("./trackCall");
37
+ const envs_1 = require("../envs");
38
+ function buildService(influxdb) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const trackCallSubscriber = yield (0, createTrackCallSubscriber_1.createTrackCallSubscriber)(envs_1.NATS_URL);
41
+ const callPublisher = yield (0, createCallPublisher_1.createCallPublisher)(envs_1.NATS_URL);
42
+ return {
43
+ definition: {
44
+ serviceName: "Calls",
45
+ pckg: "calls",
46
+ version: "v1beta2",
47
+ proto: "calls.proto"
48
+ },
49
+ handlers: {
50
+ createCall: (0, createCall_1.createCall)(callPublisher),
51
+ listCalls: (0, listCalls_1.listCalls)(influxdb),
52
+ getCall: (0, getCall_1.getCall)(influxdb),
53
+ trackCall: (0, trackCall_1.trackCall)(trackCallSubscriber())
54
+ }
55
+ };
56
+ });
57
+ }
58
+ exports.buildService = buildService;
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { CallPublisher, CreateCallRequest, CreateCallResponse } from "./types";
3
+ declare function createCall(publisher: CallPublisher): (call: {
4
+ request: CreateCallRequest;
5
+ }, callback: (error?: GrpcErrorMessage, response?: CreateCallResponse) => void) => Promise<void>;
6
+ export { createCall };
@@ -0,0 +1,64 @@
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.createCall = 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 uuid_1 = require("uuid");
35
+ const zod_1 = require("zod");
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ const CreateCallRequestSchema = zod_1.z.object({
38
+ from: zod_1.z.string(),
39
+ to: zod_1.z.string(),
40
+ appRef: zod_1.z.string()
41
+ });
42
+ function createCall(publisher) {
43
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
44
+ try {
45
+ const { from, to, appRef } = call.request;
46
+ CreateCallRequestSchema.parse(call.request);
47
+ const ref = (0, uuid_1.v4)();
48
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
49
+ logger.verbose("call to createCall", {
50
+ accessKeyId,
51
+ ref,
52
+ from,
53
+ to,
54
+ appRef
55
+ });
56
+ publisher.publishCall({ ref, from, to, appRef });
57
+ callback(null, { ref });
58
+ }
59
+ catch (error) {
60
+ (0, common_1.handleError)(error, callback);
61
+ }
62
+ });
63
+ }
64
+ exports.createCall = createCall;
@@ -0,0 +1,7 @@
1
+ import { CreateCallRequest } from "./types";
2
+ declare function createCallPublisher(natsUrl: string): Promise<{
3
+ publishCall: (request: CreateCallRequest & {
4
+ ref: string;
5
+ }) => Promise<void>;
6
+ }>;
7
+ export { createCallPublisher };
@@ -0,0 +1,47 @@
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.createCallPublisher = 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 logger_1 = require("@fonoster/logger");
32
+ const nats_1 = require("nats");
33
+ const envs_1 = require("../envs");
34
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
35
+ function createCallPublisher(natsUrl) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ logger.verbose("connecting to nats", { natsUrl });
38
+ const nc = yield (0, nats_1.connect)({ servers: natsUrl });
39
+ return {
40
+ publishCall: (request) => __awaiter(this, void 0, void 0, function* () {
41
+ logger.verbose("publishing call", { ref: request.ref });
42
+ nc.publish(envs_1.CALLS_CREATE_SUBJECT, JSON.stringify(request));
43
+ })
44
+ };
45
+ });
46
+ }
47
+ exports.createCallPublisher = createCallPublisher;
@@ -0,0 +1,3 @@
1
+ import { InfluxDBClient, ListCallsRequest, ListCallsResponse } from "./types";
2
+ declare function createFetchCalls(influxdb: InfluxDBClient): (accessKeyId: string, request: ListCallsRequest) => Promise<ListCallsResponse>;
3
+ export { createFetchCalls };
@@ -0,0 +1,87 @@
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.createFetchCalls = 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 logger_1 = require("@fonoster/logger");
32
+ const influxdb_client_1 = require("@influxdata/influxdb-client");
33
+ const types_1 = require("./types");
34
+ const envs_1 = require("../envs");
35
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
+ function createFetchCalls(influxdb) {
37
+ return (accessKeyId, request) => __awaiter(this, void 0, void 0, function* () {
38
+ const { after, before, type, from, to, status, hangupCause, pageSize, pageToken } = request;
39
+ const accessKeyIdFilter = accessKeyId
40
+ ? (0, influxdb_client_1.flux) `and r.accessKeyId == "${accessKeyId}"`
41
+ : (0, influxdb_client_1.flux) ``;
42
+ const typeFilter = type ? (0, influxdb_client_1.flux) `and r.type == "${type}"` : (0, influxdb_client_1.flux) ``;
43
+ const fromFilter = from ? (0, influxdb_client_1.flux) `and r.from == "${from}"` : (0, influxdb_client_1.flux) ``;
44
+ const toFilter = to ? (0, influxdb_client_1.flux) `and r.to == "${to}"` : (0, influxdb_client_1.flux) ``;
45
+ const statusFilter = status ? (0, influxdb_client_1.flux) `and r.status == "${status}"` : (0, influxdb_client_1.flux) ``;
46
+ const hangupCauseFilter = hangupCause
47
+ ? (0, influxdb_client_1.flux) `and r.hangupCause == "${hangupCause}"`
48
+ : (0, influxdb_client_1.flux) ``;
49
+ const pageTokenFilter = pageToken
50
+ ? (0, influxdb_client_1.flux) `|> filter(fn: (r) => r.startedAtParsed < int(v: ${pageToken}))`
51
+ : (0, influxdb_client_1.flux) ``;
52
+ const limit = (0, influxdb_client_1.flux) `|> limit(n: ${pageSize || 50})`;
53
+ const parsedAfter = after ? new Date(after).getTime() / 1000 : (0, influxdb_client_1.flux) `-30d`;
54
+ const parsedBefore = before
55
+ ? new Date(before).getTime() / 1000
56
+ : new Date().getTime() / 1000;
57
+ const query = (0, influxdb_client_1.flux) `from(bucket: "${envs_1.INFLUXDB_BUCKET}")
58
+ |> range(start: ${parsedAfter})
59
+ |> pivot(rowKey: ["ref"], columnKey: ["_field"], valueColumn: "_value")
60
+ |> map(fn: (r) => ({
61
+ r with
62
+ duration: (int(v: r.endedAt) - int(v: r.startedAt)) / 1000,
63
+ startedAtParsed: int(v: r.startedAt) / 1000,
64
+ }))
65
+ |> filter(fn: (r) =>
66
+ r._measurement == "${types_1.CALL_DETAIL_RECORD_MEASUREMENT}"
67
+ and r.startedAtParsed < ${parsedBefore}
68
+ ${accessKeyIdFilter}
69
+ ${typeFilter}
70
+ ${fromFilter}
71
+ ${toFilter}
72
+ ${statusFilter}
73
+ ${hangupCauseFilter})
74
+ |> group()
75
+ |> sort(columns: ["startedAtParsed"], desc: true)
76
+ ${pageTokenFilter}
77
+ ${limit}`;
78
+ logger.verbose("list calls request", { accessKeyId, after, before });
79
+ const items = (yield influxdb.collectRows(query));
80
+ const nextPageToken = items.length > 0 ? items[items.length - 1].startedAt : "";
81
+ return {
82
+ nextPageToken: nextPageToken + "",
83
+ items
84
+ };
85
+ });
86
+ }
87
+ exports.createFetchCalls = createFetchCalls;
@@ -0,0 +1,3 @@
1
+ import { CallDetailRecord, InfluxDBClient } from "./types";
2
+ declare function createFetchSingleCall(influxdb: InfluxDBClient): (accessKeyId: string, ref: string) => Promise<CallDetailRecord>;
3
+ export { createFetchSingleCall };
@@ -0,0 +1,48 @@
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.createFetchSingleCall = 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 influxdb_client_1 = require("@influxdata/influxdb-client");
32
+ const types_1 = require("./types");
33
+ const envs_1 = require("../envs");
34
+ function createFetchSingleCall(influxdb) {
35
+ return (accessKeyId, ref) => __awaiter(this, void 0, void 0, function* () {
36
+ // TODO: Look into best practices for range and limit
37
+ const query = (0, influxdb_client_1.flux) `from(bucket: "${envs_1.INFLUXDB_BUCKET}")
38
+ |> range(start: -360d)
39
+ |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
40
+ |> filter(fn: (r) => r._measurement == "${types_1.CALL_DETAIL_RECORD_MEASUREMENT}")
41
+ |> filter(fn: (r) => r.ref == ${ref} and r.accessKeyId == "${accessKeyId}")
42
+ |> sort(columns: ["_time"], desc: true)
43
+ |> limit(n: 1)`;
44
+ const items = (yield influxdb.collectRows(query));
45
+ return items.length > 0 ? items[0] : null;
46
+ });
47
+ }
48
+ exports.createFetchSingleCall = createFetchSingleCall;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from "events";
3
+ declare function createTrackCallSubscriber(natsUrl: string): Promise<() => {
4
+ events: EventEmitter<[never]>;
5
+ }>;
6
+ export { createTrackCallSubscriber };