@fonoster/apiserver 0.5.5 → 0.6.1

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 +43 -0
  5. package/dist/applications/createApplication.d.ts +6 -0
  6. package/dist/applications/createApplication.js +56 -0
  7. package/dist/applications/createGetFnUtil.d.ts +33 -0
  8. package/dist/applications/createGetFnUtil.js +31 -0
  9. package/dist/applications/deleteApplication.d.ts +6 -0
  10. package/dist/applications/deleteApplication.js +25 -0
  11. package/dist/applications/getApplication.d.ts +6 -0
  12. package/dist/applications/getApplication.js +46 -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 +68 -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 +56 -0
  23. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +3 -0
  24. package/dist/applications/utils/applicationWithEncodedStruct.js +22 -0
  25. package/dist/applications/utils/convertToApplicationData.d.ts +4 -0
  26. package/dist/applications/utils/convertToApplicationData.js +37 -0
  27. package/dist/applications/utils/getApplicationValidationSchema.d.ts +64 -0
  28. package/dist/applications/utils/getApplicationValidationSchema.js +63 -0
  29. package/dist/applications/utils/prepareForValidation.d.ts +3 -0
  30. package/dist/applications/utils/prepareForValidation.js +35 -0
  31. package/dist/applications/utils/validOrThrow.d.ts +3 -0
  32. package/dist/applications/utils/validOrThrow.js +14 -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 +57 -0
  37. package/dist/calls/createCall.d.ts +6 -0
  38. package/dist/calls/createCall.js +63 -0
  39. package/dist/calls/createCallPublisher.d.ts +7 -0
  40. package/dist/calls/createCallPublisher.js +46 -0
  41. package/dist/calls/createFetchCalls.d.ts +3 -0
  42. package/dist/calls/createFetchCalls.js +86 -0
  43. package/dist/calls/createFetchSingleCall.d.ts +3 -0
  44. package/dist/calls/createFetchSingleCall.js +47 -0
  45. package/dist/calls/createTrackCallSubscriber.d.ts +5 -0
  46. package/dist/calls/createTrackCallSubscriber.js +52 -0
  47. package/dist/calls/getCall.d.ts +6 -0
  48. package/dist/calls/getCall.js +59 -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 +51 -0
  55. package/dist/calls/runCallManager.d.ts +8 -0
  56. package/dist/calls/runCallManager.js +81 -0
  57. package/dist/calls/trackCall.d.ts +14 -0
  58. package/dist/calls/trackCall.js +63 -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} +23 -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 +432 -0
  81. package/dist/core/services.js +53 -0
  82. package/dist/core/upsertDefaultPeer.d.ts +3 -0
  83. package/dist/core/upsertDefaultPeer.js +88 -0
  84. package/dist/envs.d.ts +46 -6
  85. package/dist/envs.js +94 -8
  86. package/dist/events/createInfluxDbPub.d.ts +13 -0
  87. package/dist/events/createInfluxDbPub.js +53 -0
  88. package/dist/events/nats.d.ts +10 -0
  89. package/dist/events/nats.js +84 -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 +31 -0
  94. package/dist/secrets/buildService.js +43 -0
  95. package/dist/secrets/createGetFnUtil.d.ts +16 -0
  96. package/dist/secrets/createGetFnUtil.js +45 -0
  97. package/dist/secrets/createSecret.d.ts +7 -0
  98. package/dist/secrets/createSecret.js +56 -0
  99. package/dist/secrets/deleteSecret.d.ts +8 -0
  100. package/dist/secrets/deleteSecret.js +43 -0
  101. package/dist/secrets/getSecret.d.ts +6 -0
  102. package/dist/secrets/getSecret.js +42 -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 +61 -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 +52 -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 +48 -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 +41 -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 +79 -0
  127. package/dist/voice/createExternalMediaConfig.d.ts +9 -0
  128. package/dist/voice/createExternalMediaConfig.js +34 -0
  129. package/dist/voice/handlers/Answer.d.ts +5 -0
  130. package/dist/voice/handlers/Answer.js +24 -0
  131. package/dist/voice/handlers/Hangup.d.ts +5 -0
  132. package/dist/voice/handlers/Hangup.js +25 -0
  133. package/dist/voice/handlers/Mute.d.ts +4 -0
  134. package/dist/voice/handlers/Mute.js +27 -0
  135. package/dist/voice/handlers/Play.d.ts +4 -0
  136. package/dist/voice/handlers/Play.js +33 -0
  137. package/dist/voice/handlers/PlayDtmf.d.ts +4 -0
  138. package/dist/voice/handlers/PlayDtmf.js +27 -0
  139. package/dist/voice/handlers/PlaybackControl.d.ts +4 -0
  140. package/dist/voice/handlers/PlaybackControl.js +27 -0
  141. package/dist/voice/handlers/Record.d.ts +4 -0
  142. package/dist/voice/handlers/Record.js +58 -0
  143. package/dist/voice/handlers/Say.d.ts +4 -0
  144. package/dist/voice/handlers/Say.js +45 -0
  145. package/dist/voice/handlers/StasisEnd.d.ts +4 -0
  146. package/dist/voice/handlers/StasisEnd.js +27 -0
  147. package/dist/voice/handlers/Unmute.d.ts +4 -0
  148. package/dist/voice/handlers/Unmute.js +27 -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 +53 -0
  153. package/dist/voice/handlers/dial/Dial.d.ts +5 -0
  154. package/dist/voice/handlers/dial/Dial.js +71 -0
  155. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +6 -0
  156. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +29 -0
  157. package/dist/voice/handlers/dial/handleDialEvents.d.ts +5 -0
  158. package/dist/voice/handlers/dial/handleDialEvents.js +54 -0
  159. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +3 -0
  160. package/dist/voice/handlers/dial/handleStasisEnd.js +19 -0
  161. package/dist/voice/handlers/dial/handleStasisStart.d.ts +9 -0
  162. package/dist/voice/handlers/dial/handleStasisStart.js +53 -0
  163. package/dist/voice/handlers/dial/recordChannel.d.ts +4 -0
  164. package/dist/voice/handlers/dial/recordChannel.js +45 -0
  165. package/dist/voice/handlers/gather/Gather.d.ts +3 -0
  166. package/dist/voice/handlers/gather/Gather.js +72 -0
  167. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +8 -0
  168. package/dist/voice/handlers/gather/getTimeoutPromise.js +18 -0
  169. package/dist/voice/handlers/withErrorHandling.d.ts +4 -0
  170. package/dist/voice/handlers/withErrorHandling.js +35 -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 +6 -0
  175. package/dist/voice/integrations/getSttConfig.d.ts +7 -0
  176. package/dist/voice/integrations/getSttConfig.js +9 -0
  177. package/dist/voice/integrations/getTtsConfig.d.ts +7 -0
  178. package/dist/voice/integrations/getTtsConfig.js +10 -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 +88 -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 +77 -0
  187. package/dist/voice/makeGetChannelVar.d.ts +4 -0
  188. package/dist/voice/makeGetChannelVar.js +25 -0
  189. package/dist/voice/stt/AbstractSpeechToText.d.ts +14 -0
  190. package/dist/voice/stt/AbstractSpeechToText.js +19 -0
  191. package/dist/voice/stt/Google.d.ts +19 -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 +4 -0
  198. package/dist/voice/transcribeOnConnection.js +26 -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 +38 -0
  209. package/dist/voice/tts/flattenObject.d.ts +2 -0
  210. package/dist/voice/tts/flattenObject.js +38 -0
  211. package/dist/voice/tts/isSsml.d.ts +2 -0
  212. package/dist/voice/tts/isSsml.js +25 -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 +33 -0
  220. package/dist/voice/types/voice.js +2 -0
  221. package/package.json +46 -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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Fonoster Inc
3
+ Copyright (c) 2024 Fonoster Inc
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ <a href="https://gitpod.io/#https://github.com/fonoster/fonoster"> <img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod" />
2
+
3
+ This module is part of the [Fonoster](https://fonoster.com) project. By itself, it does not do much. It is intended to be used as a dependency for other modules. For more information about the project, please visit [https://github.com/fonoster/fonoster](https://github.com/fonoster/fonoster).
@@ -0,0 +1,29 @@
1
+ import { Prisma } from "../core/db";
2
+ declare function buildService(prisma: Prisma): {
3
+ definition: {
4
+ serviceName: string;
5
+ pckg: string;
6
+ version: string;
7
+ proto: string;
8
+ };
9
+ handlers: {
10
+ createApplication: (call: {
11
+ request: import("@fonoster/common").CreateApplicationRequest;
12
+ }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").CreateApplicationResponse) => void) => Promise<void>;
13
+ getApplication: (call: {
14
+ request: import("@fonoster/common").GetApplicationRequest;
15
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").Application) => void) => Promise<void>;
16
+ listApplications: (call: {
17
+ request: import("@fonoster/common").ListApplicationsRequest;
18
+ }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").ListApplicationsResponse) => void) => Promise<void>;
19
+ deleteApplication: (call: {
20
+ request: import("@fonoster/common").DeleteApplicationRequest;
21
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").BaseApiObject) => void) => Promise<void>;
22
+ updateApplication: (call: {
23
+ request: import("@fonoster/common").UpdateApplicationRequest;
24
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: {
25
+ ref: string;
26
+ }) => void) => Promise<void>;
27
+ };
28
+ };
29
+ export { buildService };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildService = buildService;
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 createApplication_1 = require("./createApplication");
23
+ const deleteApplication_1 = require("./deleteApplication");
24
+ const getApplication_1 = require("./getApplication");
25
+ const listApplications_1 = require("./listApplications");
26
+ const updateApplication_1 = require("./updateApplication");
27
+ function buildService(prisma) {
28
+ return {
29
+ definition: {
30
+ serviceName: "Applications",
31
+ pckg: "applications",
32
+ version: "v1beta2",
33
+ proto: "applications.proto"
34
+ },
35
+ handlers: {
36
+ createApplication: (0, createApplication_1.createApplication)(prisma),
37
+ getApplication: (0, getApplication_1.getApplication)(prisma),
38
+ listApplications: (0, listApplications_1.listApplications)(prisma),
39
+ deleteApplication: (0, deleteApplication_1.deleteApplication)(prisma),
40
+ updateApplication: (0, updateApplication_1.updateApplication)(prisma)
41
+ }
42
+ };
43
+ }
@@ -0,0 +1,6 @@
1
+ import { CreateApplicationRequest, CreateApplicationResponse, GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../core/db";
3
+ declare function createApplication(prisma: Prisma): (call: {
4
+ request: CreateApplicationRequest;
5
+ }, callback: (error: GrpcErrorMessage, response?: CreateApplicationResponse) => void) => Promise<void>;
6
+ export { createApplication };
@@ -0,0 +1,56 @@
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.createApplication = createApplication;
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 convertToApplicationData_1 = require("./utils/convertToApplicationData");
35
+ const validOrThrow_1 = require("./utils/validOrThrow");
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ function createApplication(prisma) {
38
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
+ const { type } = call.request;
40
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
41
+ try {
42
+ logger.verbose("call to createApplication", {
43
+ accessKeyId,
44
+ type
45
+ });
46
+ (0, validOrThrow_1.validOrThrow)(call.request);
47
+ const result = yield prisma.application.create({
48
+ data: Object.assign(Object.assign({}, (0, convertToApplicationData_1.convertToApplicationData)(call.request)), { accessKeyId })
49
+ });
50
+ return callback(null, { ref: result.ref });
51
+ }
52
+ catch (error) {
53
+ (0, common_1.handleError)(error, callback);
54
+ }
55
+ });
56
+ }
@@ -0,0 +1,33 @@
1
+ import { Prisma } from "../core/db";
2
+ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
3
+ extended: {
4
+ accessKeyId: string;
5
+ };
6
+ textToSpeech: {
7
+ ref: string;
8
+ config: import(".prisma/client").Prisma.JsonValue;
9
+ applicationRef: string;
10
+ productRef: string;
11
+ };
12
+ speechToText: {
13
+ ref: string;
14
+ config: import(".prisma/client").Prisma.JsonValue;
15
+ applicationRef: string;
16
+ productRef: string;
17
+ };
18
+ intelligence: {
19
+ ref: string;
20
+ config: import(".prisma/client").Prisma.JsonValue;
21
+ applicationRef: string;
22
+ productRef: string;
23
+ credentials: string;
24
+ };
25
+ name: string;
26
+ type: "PROGRAMMABLE_VOICE";
27
+ ref: string;
28
+ accessKeyId: string;
29
+ createdAt: Date;
30
+ updatedAt: Date;
31
+ appEndpoint: string;
32
+ }>;
33
+ export { createGetFnUtil };
@@ -0,0 +1,31 @@
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.createGetFnUtil = createGetFnUtil;
13
+ const notFoundError_1 = require("../core/notFoundError");
14
+ function createGetFnUtil(prisma) {
15
+ return (ref) => __awaiter(this, void 0, void 0, function* () {
16
+ const response = yield prisma.application.findUnique({
17
+ where: { ref },
18
+ include: {
19
+ textToSpeech: true,
20
+ speechToText: true,
21
+ intelligence: true
22
+ }
23
+ });
24
+ if (!response) {
25
+ throw (0, notFoundError_1.notFoundError)("Application not found");
26
+ }
27
+ return Object.assign(Object.assign({}, response), { extended: {
28
+ accessKeyId: response.accessKeyId
29
+ } });
30
+ });
31
+ }
@@ -0,0 +1,6 @@
1
+ import { DeleteApplicationRequest } from "@fonoster/common";
2
+ import { Prisma } from "../core/db";
3
+ declare function deleteApplication(prisma: Prisma): (call: {
4
+ request: DeleteApplicationRequest;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").BaseApiObject) => void) => Promise<void>;
6
+ export { deleteApplication };
@@ -0,0 +1,25 @@
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.deleteApplication = deleteApplication;
13
+ const identity_1 = require("@fonoster/identity");
14
+ const logger_1 = require("@fonoster/logger");
15
+ const createGetFnUtil_1 = require("./createGetFnUtil");
16
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
17
+ function deleteApplication(prisma) {
18
+ const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
19
+ return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
20
+ const { ref } = call.request;
21
+ logger.verbose("call to deleteApplication", { ref });
22
+ yield prisma.application.delete({ where: { ref } });
23
+ return { ref };
24
+ }), (ref) => getFn(ref));
25
+ }
@@ -0,0 +1,6 @@
1
+ import { Application, GetApplicationRequest } from "@fonoster/common";
2
+ import { Prisma } from "../core/db";
3
+ declare function getApplication(prisma: Prisma): (call: {
4
+ request: GetApplicationRequest;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: Application) => void) => Promise<void>;
6
+ export { getApplication };
@@ -0,0 +1,46 @@
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.getApplication = getApplication;
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 createGetFnUtil_1 = require("./createGetFnUtil");
35
+ const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
36
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
+ function getApplication(prisma) {
38
+ const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
39
+ return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
40
+ const { ref } = call.request;
41
+ logger.verbose("call to getApplication", { ref });
42
+ const result = yield getFn(ref);
43
+ const resultWithParsedDate = (0, common_1.datesMapper)(result);
44
+ return result ? (0, applicationWithEncodedStruct_1.applicationWithEncodedStruct)(resultWithParsedDate) : null;
45
+ }), (ref) => getFn(ref));
46
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ declare const hostOrHostPortSchema: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string, string>;
3
+ export { hostOrHostPortSchema };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hostOrHostPortSchema = 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 hostOrHostPortSchema = zod_1.z
24
+ .string()
25
+ .optional()
26
+ .nullable()
27
+ .refine((value) => {
28
+ const hostRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*|(\d{1,3}\.){3}\d{1,3})$/;
29
+ const hostPortRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*|(\d{1,3}\.){3}\d{1,3}):\d{1,5}$/;
30
+ return hostRegex.test(value) || hostPortRegex.test(value);
31
+ }, {
32
+ message: "Invalid format. Expected 'host' or 'host:port'"
33
+ });
34
+ exports.hostOrHostPortSchema = hostOrHostPortSchema;
@@ -0,0 +1 @@
1
+ export { buildService as buildApplicationsService } from "./buildService";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildApplicationsService = 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, "buildApplicationsService", { enumerable: true, get: function () { return buildService_1.buildService; } });
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage, ListApplicationsRequest, ListApplicationsResponse } from "@fonoster/common";
2
+ import { Prisma } from "../core/db";
3
+ declare function listApplications(prisma: Prisma): (call: {
4
+ request: ListApplicationsRequest;
5
+ }, callback: (error: GrpcErrorMessage, response?: ListApplicationsResponse) => void) => Promise<void>;
6
+ export { listApplications };
@@ -0,0 +1,68 @@
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.listApplications = listApplications;
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 applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
35
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
+ function listApplications(prisma) {
37
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
38
+ var _a;
39
+ const { pageSize, pageToken } = call.request;
40
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
41
+ logger.verbose("call to getApplication", {
42
+ accessKeyId,
43
+ pageSize,
44
+ pageToken
45
+ });
46
+ try {
47
+ const result = yield prisma.application.findMany({
48
+ where: { accessKeyId },
49
+ include: {
50
+ textToSpeech: true,
51
+ speechToText: true,
52
+ intelligence: true
53
+ },
54
+ take: pageSize,
55
+ skip: pageToken ? 1 : 0,
56
+ cursor: pageToken ? { ref: pageToken } : undefined
57
+ });
58
+ const items = result.map(applicationWithEncodedStruct_1.applicationWithEncodedStruct);
59
+ callback(null, {
60
+ items,
61
+ nextPageToken: (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
62
+ });
63
+ }
64
+ catch (error) {
65
+ (0, common_1.handleError)(error, callback);
66
+ }
67
+ });
68
+ }
@@ -0,0 +1,27 @@
1
+ import { ApplicationType } from "@prisma/client";
2
+ type ApplicationData = {
3
+ ref?: string;
4
+ name: string;
5
+ type: ApplicationType;
6
+ appEndpoint: string;
7
+ textToSpeech?: {
8
+ create: {
9
+ productRef: string;
10
+ config: Record<string, unknown>;
11
+ };
12
+ };
13
+ speechToText?: {
14
+ create: {
15
+ productRef: string;
16
+ config: Record<string, unknown>;
17
+ };
18
+ };
19
+ intelligence?: {
20
+ create: {
21
+ productRef: string;
22
+ credentials: string;
23
+ config: Record<string, unknown>;
24
+ };
25
+ };
26
+ };
27
+ export { ApplicationData };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { UpdateApplicationRequest } from "@fonoster/common";
2
+ import { Prisma } from "../core/db";
3
+ declare function updateApplication(prisma: Prisma): (call: {
4
+ request: UpdateApplicationRequest;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: {
6
+ ref: string;
7
+ }) => void) => Promise<void>;
8
+ export { updateApplication };
@@ -0,0 +1,56 @@
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.updateApplication = updateApplication;
13
+ const identity_1 = require("@fonoster/identity");
14
+ const logger_1 = require("@fonoster/logger");
15
+ const createGetFnUtil_1 = require("./createGetFnUtil");
16
+ const convertToApplicationData_1 = require("./utils/convertToApplicationData");
17
+ const validOrThrow_1 = require("./utils/validOrThrow");
18
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
19
+ function updateApplication(prisma) {
20
+ const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
21
+ return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
22
+ const { type, ref: applicationRef } = call.request;
23
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
24
+ (0, validOrThrow_1.validOrThrow)(call.request);
25
+ logger.verbose("call to updateApplication", {
26
+ accessKeyId,
27
+ type
28
+ });
29
+ // TODO: Revisit to see if needs optimization
30
+ yield prisma.$transaction([
31
+ prisma.textToSpeech.deleteMany({
32
+ where: {
33
+ applicationRef
34
+ }
35
+ }),
36
+ prisma.speechToText.deleteMany({
37
+ where: {
38
+ applicationRef
39
+ }
40
+ }),
41
+ prisma.intelligence.deleteMany({
42
+ where: {
43
+ applicationRef
44
+ }
45
+ }),
46
+ prisma.application.update({
47
+ where: {
48
+ ref: applicationRef,
49
+ accessKeyId
50
+ },
51
+ data: (0, convertToApplicationData_1.convertToApplicationData)(call.request)
52
+ })
53
+ ]);
54
+ return { ref: applicationRef };
55
+ }), (ref) => getFn(ref));
56
+ }
@@ -0,0 +1,3 @@
1
+ import { Application } from "@fonoster/common";
2
+ declare function applicationWithEncodedStruct(application: any): Application;
3
+ export { applicationWithEncodedStruct };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applicationWithEncodedStruct = applicationWithEncodedStruct;
4
+ const pb_util_1 = require("pb-util");
5
+ function applicationWithEncodedStruct(application) {
6
+ const encodeConfig = (property) => {
7
+ return (property === null || property === void 0 ? void 0 : property.config) ? pb_util_1.struct.encode(property.config) : null;
8
+ };
9
+ const result = Object.assign({}, application);
10
+ if (application.textToSpeech) {
11
+ result.textToSpeech = Object.assign(Object.assign({}, application.textToSpeech), { config: encodeConfig(application.textToSpeech) });
12
+ }
13
+ if (application.speechToText) {
14
+ result.speechToText = Object.assign(Object.assign({}, application.speechToText), { config: encodeConfig(application.speechToText) });
15
+ }
16
+ if (application.intelligence) {
17
+ const intelligenceCopy = application.intelligence;
18
+ delete intelligenceCopy.credentials;
19
+ result.intelligence = Object.assign(Object.assign({}, intelligenceCopy), { config: encodeConfig(intelligenceCopy) });
20
+ }
21
+ return result; // Return the modified object
22
+ }
@@ -0,0 +1,4 @@
1
+ import { CreateApplicationRequest, UpdateApplicationRequest } from "@fonoster/common";
2
+ import { ApplicationData } from "../types";
3
+ declare function convertToApplicationData(request: CreateApplicationRequest | UpdateApplicationRequest): ApplicationData;
4
+ export { convertToApplicationData };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToApplicationData = convertToApplicationData;
4
+ const client_1 = require("@prisma/client");
5
+ const pb_util_1 = require("pb-util");
6
+ function convertToApplicationData(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
+ create: {
18
+ productRef: property.productRef,
19
+ credentials: property.credentials
20
+ ? JSON.stringify(pb_util_1.struct.decode(property.credentials))
21
+ : undefined,
22
+ config: property.config ? pb_util_1.struct.decode(property.config) : null
23
+ }
24
+ }
25
+ : undefined;
26
+ };
27
+ if (request.textToSpeech) {
28
+ result.textToSpeech = createProperty(request.textToSpeech);
29
+ }
30
+ if (request.speechToText) {
31
+ result.speechToText = createProperty(request.speechToText);
32
+ }
33
+ if (request.intelligence) {
34
+ result.intelligence = createProperty(request.intelligence);
35
+ }
36
+ return result;
37
+ }