@fonoster/apiserver 0.7.4 → 0.7.7

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 (69) hide show
  1. package/README.md +2 -2
  2. package/dist/applications/buildService.d.ts +10 -12
  3. package/dist/applications/createApplication.d.ts +2 -3
  4. package/dist/applications/createApplication.js +13 -16
  5. package/dist/applications/createGetFnUtil.d.ts +3 -3
  6. package/dist/applications/deleteApplication.d.ts +2 -3
  7. package/dist/applications/deleteApplication.js +4 -2
  8. package/dist/applications/getApplication.d.ts +2 -3
  9. package/dist/applications/getApplication.js +5 -3
  10. package/dist/applications/listApplications.d.ts +2 -3
  11. package/dist/applications/listApplications.js +18 -22
  12. package/dist/applications/updateApplication.d.ts +2 -5
  13. package/dist/applications/updateApplication.js +8 -6
  14. package/dist/applications/utils/getApplicationValidationSchema.d.ts +1 -1
  15. package/dist/applications/utils/getApplicationValidationSchema.js +4 -4
  16. package/dist/calls/buildService.d.ts +8 -10
  17. package/dist/calls/createCall.d.ts +3 -4
  18. package/dist/calls/createCall.js +21 -33
  19. package/dist/calls/getCall.d.ts +3 -3
  20. package/dist/calls/getCall.js +9 -18
  21. package/dist/calls/listCalls.d.ts +3 -3
  22. package/dist/calls/listCalls.js +7 -12
  23. package/dist/calls/makeTrackCall.d.ts +2 -11
  24. package/dist/calls/makeTrackCall.js +2 -6
  25. package/dist/calls/types.d.ts +1 -1
  26. package/dist/calls/types.js +1 -1
  27. package/dist/core/db.d.ts +1 -1
  28. package/dist/core/seed.js +5 -5
  29. package/dist/core/services.d.ts +125 -168
  30. package/dist/envs.d.ts +33 -33
  31. package/dist/envs.js +40 -40
  32. package/dist/events/createInfluxDbPub.d.ts +1 -1
  33. package/dist/events/nats.js +0 -1
  34. package/dist/events/types.d.ts +1 -1
  35. package/dist/secrets/buildService.d.ts +10 -12
  36. package/dist/secrets/createSecret.d.ts +2 -3
  37. package/dist/secrets/createSecret.js +10 -14
  38. package/dist/secrets/deleteSecret.d.ts +2 -3
  39. package/dist/secrets/deleteSecret.js +5 -3
  40. package/dist/secrets/getSecret.d.ts +2 -3
  41. package/dist/secrets/getSecret.js +5 -3
  42. package/dist/secrets/listSecrets.d.ts +2 -3
  43. package/dist/secrets/listSecrets.js +12 -16
  44. package/dist/secrets/updateSecret.d.ts +2 -5
  45. package/dist/secrets/updateSecret.js +5 -2
  46. package/dist/utils/withErrorHandlingAndValidationAndAccess.d.ts +5 -0
  47. package/dist/{applications/hostOrHostPortSchema.js → utils/withErrorHandlingAndValidationAndAccess.js} +10 -14
  48. package/dist/voice/VoiceClientImpl.js +0 -4
  49. package/dist/voice/handlers/Say.js +0 -1
  50. package/dist/voice/handlers/Stream.js +0 -1
  51. package/dist/voice/handlers/StreamGather.js +0 -1
  52. package/dist/voice/handlers/gather/Gather.js +5 -3
  53. package/dist/voice/handlers/index.d.ts +5 -5
  54. package/dist/voice/handlers/index.js +5 -5
  55. package/dist/voice/handlers/utils/withErrorHandling.js +0 -1
  56. package/dist/voice/integrations/types.d.ts +1 -1
  57. package/dist/voice/stt/Google.d.ts +1 -1
  58. package/dist/voice/stt/Google.js +1 -1
  59. package/dist/voice/stt/SpeechToTextFactory.js +1 -1
  60. package/dist/voice/stt/types.d.ts +6 -6
  61. package/dist/voice/tts/Google.d.ts +1 -1
  62. package/dist/voice/tts/Google.js +1 -1
  63. package/dist/voice/tts/TextToSpeechFactory.js +1 -1
  64. package/dist/voice/tts/types.d.ts +1 -1
  65. package/dist/voice/types/voice.d.ts +1 -1
  66. package/package.json +8 -8
  67. package/dist/applications/hostOrHostPortSchema.d.ts +0 -3
  68. package/dist/calls/ListCallsRequestSchema.d.ts +0 -25
  69. package/dist/calls/ListCallsRequestSchema.js +0 -54
package/README.md CHANGED
@@ -1,3 +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" />
1
+ [![Discord](https://img.shields.io/discord/1016419835455996076?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/4QWgSz4hTC) ![GitHub](https://img.shields.io/github/license/fonoster/fonoster?color=%2347b96d) ![Twitter Follow](https://img.shields.io/twitter/follow/fonoster?style=social)
2
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).
3
+ This module is part of the [Fonoster](https://fonoster.com) open-source. 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).
@@ -8,22 +8,20 @@ declare function buildService(prisma: Prisma): {
8
8
  };
9
9
  handlers: {
10
10
  createApplication: (call: {
11
- request: import("@fonoster/types").CreateApplicationRequest;
12
- }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/types").BaseApiObject) => void) => Promise<void>;
11
+ request: unknown;
12
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
13
13
  getApplication: (call: {
14
- request: import("@fonoster/types").BaseApiObject;
15
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/types").Application) => void) => Promise<void>;
14
+ request: unknown;
15
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
16
16
  listApplications: (call: {
17
- request: import("@fonoster/types").ListApplicationsRequest;
18
- }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/types").ListApplicationsResponse) => void) => Promise<void>;
17
+ request: unknown;
18
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
19
19
  deleteApplication: (call: {
20
- request: import("@fonoster/types").BaseApiObject;
21
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/types").BaseApiObject) => void) => Promise<void>;
20
+ request: unknown;
21
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
22
22
  updateApplication: (call: {
23
- request: import("@fonoster/types").UpdateApplicationRequest;
24
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: {
25
- ref: string;
26
- }) => void) => Promise<void>;
23
+ request: unknown;
24
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
27
25
  };
28
26
  };
29
27
  export { buildService };
@@ -1,7 +1,6 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
- import { BaseApiObject, CreateApplicationRequest } from "@fonoster/types";
3
2
  import { Prisma } from "../core/db";
4
3
  declare function createApplication(prisma: Prisma): (call: {
5
- request: CreateApplicationRequest;
6
- }, callback: (error: GrpcErrorMessage, response?: BaseApiObject) => void) => Promise<void>;
4
+ request: unknown;
5
+ }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
6
  export { createApplication };
@@ -35,22 +35,19 @@ const convertToApplicationData_1 = require("./utils/convertToApplicationData");
35
35
  const validOrThrow_1 = require("./utils/validOrThrow");
36
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
37
  function createApplication(prisma) {
38
- return (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
- const { type } = call.request;
38
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
+ const { request } = call;
40
+ const { type } = request;
40
41
  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
- }
42
+ logger.verbose("call to createApplication", {
43
+ accessKeyId,
44
+ type
45
+ });
46
+ (0, validOrThrow_1.validOrThrow)(request);
47
+ const result = yield prisma.application.create({
48
+ data: Object.assign(Object.assign({}, (0, convertToApplicationData_1.convertToApplicationData)(request)), { accessKeyId })
49
+ });
50
+ callback(null, { ref: result.ref });
55
51
  });
52
+ return (0, common_1.withErrorHandling)(fn);
56
53
  }
@@ -5,20 +5,20 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
5
5
  };
6
6
  textToSpeech: {
7
7
  ref: string;
8
- config: import(".prisma/client").Prisma.JsonValue;
8
+ config: import("@prisma/client/runtime/library").JsonValue;
9
9
  applicationRef: string;
10
10
  productRef: string;
11
11
  };
12
12
  speechToText: {
13
13
  ref: string;
14
- config: import(".prisma/client").Prisma.JsonValue;
14
+ config: import("@prisma/client/runtime/library").JsonValue;
15
15
  applicationRef: string;
16
16
  productRef: string;
17
17
  };
18
18
  intelligence: {
19
19
  ref: string;
20
20
  credentials: string;
21
- config: import(".prisma/client").Prisma.JsonValue;
21
+ config: import("@prisma/client/runtime/library").JsonValue;
22
22
  applicationRef: string;
23
23
  productRef: string;
24
24
  };
@@ -1,6 +1,5 @@
1
- import { BaseApiObject } from "@fonoster/types";
2
1
  import { Prisma } from "../core/db";
3
2
  declare function deleteApplication(prisma: Prisma): (call: {
4
- request: BaseApiObject;
5
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: BaseApiObject) => void) => Promise<void>;
3
+ request: unknown;
4
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
5
  export { deleteApplication };
@@ -28,16 +28,18 @@ exports.deleteApplication = deleteApplication;
28
28
  * See the License for the specific language governing permissions and
29
29
  * limitations under the License.
30
30
  */
31
+ const common_1 = require("@fonoster/common");
31
32
  const identity_1 = require("@fonoster/identity");
32
33
  const logger_1 = require("@fonoster/logger");
33
34
  const createGetFnUtil_1 = require("./createGetFnUtil");
34
35
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
35
36
  function deleteApplication(prisma) {
36
37
  const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
37
- return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
38
+ const fn = (call) => __awaiter(this, void 0, void 0, function* () {
38
39
  const { ref } = call.request;
39
40
  logger.verbose("call to deleteApplication", { ref });
40
41
  yield prisma.application.delete({ where: { ref } });
41
42
  return { ref };
42
- }), (ref) => getFn(ref));
43
+ });
44
+ return (0, common_1.withErrorHandlingAndValidation)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)), common_1.Validators.baseApiObjectSchema);
43
45
  }
@@ -1,6 +1,5 @@
1
- import { Application, BaseApiObject } from "@fonoster/types";
2
1
  import { Prisma } from "../core/db";
3
2
  declare function getApplication(prisma: Prisma): (call: {
4
- request: BaseApiObject;
5
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: Application) => void) => Promise<void>;
3
+ request: unknown;
4
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
5
  export { getApplication };
@@ -28,17 +28,19 @@ exports.getApplication = getApplication;
28
28
  * See the License for the specific language governing permissions and
29
29
  * limitations under the License.
30
30
  */
31
- const identity_1 = require("@fonoster/identity");
31
+ const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const createGetFnUtil_1 = require("./createGetFnUtil");
34
34
  const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
35
+ const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
35
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
37
  function getApplication(prisma) {
37
38
  const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
38
- return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
39
+ const fn = (call) => __awaiter(this, void 0, void 0, function* () {
39
40
  const { ref } = call.request;
40
41
  logger.verbose("call to getApplication", { ref });
41
42
  const result = yield getFn(ref);
42
43
  return result ? (0, applicationWithEncodedStruct_1.applicationWithEncodedStruct)(result) : null;
43
- }), (ref) => getFn(ref));
44
+ });
45
+ return (0, withErrorHandlingAndValidationAndAccess_1.withErrorHandlingAndValidationAndAccess)(fn, (ref) => getFn(ref), common_1.Validators.baseApiObjectSchema);
44
46
  }
@@ -1,7 +1,6 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
- import { ListApplicationsRequest, ListApplicationsResponse } from "@fonoster/types";
3
2
  import { Prisma } from "../core/db";
4
3
  declare function listApplications(prisma: Prisma): (call: {
5
- request: ListApplicationsRequest;
6
- }, callback: (error: GrpcErrorMessage, response?: ListApplicationsResponse) => void) => Promise<void>;
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
6
  export { listApplications };
@@ -34,7 +34,7 @@ const logger_1 = require("@fonoster/logger");
34
34
  const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
35
35
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
36
36
  function listApplications(prisma) {
37
- return (call, callback) => __awaiter(this, void 0, void 0, function* () {
37
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
38
38
  var _a;
39
39
  const { pageSize, pageToken } = call.request;
40
40
  const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
@@ -43,26 +43,22 @@ function listApplications(prisma) {
43
43
  pageSize,
44
44
  pageToken
45
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
- }
46
+ const result = yield prisma.application.findMany({
47
+ where: { accessKeyId },
48
+ include: {
49
+ textToSpeech: true,
50
+ speechToText: true,
51
+ intelligence: true
52
+ },
53
+ take: pageSize,
54
+ skip: pageToken ? 1 : 0,
55
+ cursor: pageToken ? { ref: pageToken } : undefined
56
+ });
57
+ const items = result.map(applicationWithEncodedStruct_1.applicationWithEncodedStruct);
58
+ callback(null, {
59
+ items,
60
+ nextPageToken: (_a = result[result.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
61
+ });
67
62
  });
63
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
68
64
  }
@@ -1,8 +1,5 @@
1
- import { UpdateApplicationRequest } from "@fonoster/types";
2
1
  import { Prisma } from "../core/db";
3
2
  declare function updateApplication(prisma: Prisma): (call: {
4
- request: UpdateApplicationRequest;
5
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: {
6
- ref: string;
7
- }) => void) => Promise<void>;
3
+ request: unknown;
4
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
8
5
  export { updateApplication };
@@ -28,6 +28,7 @@ exports.updateApplication = updateApplication;
28
28
  * See the License for the specific language governing permissions and
29
29
  * limitations under the License.
30
30
  */
31
+ const common_1 = require("@fonoster/common");
31
32
  const identity_1 = require("@fonoster/identity");
32
33
  const logger_1 = require("@fonoster/logger");
33
34
  const createGetFnUtil_1 = require("./createGetFnUtil");
@@ -36,15 +37,15 @@ const validOrThrow_1 = require("./utils/validOrThrow");
36
37
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
38
  function updateApplication(prisma) {
38
39
  const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
39
- return (0, identity_1.withAccess)((call) => __awaiter(this, void 0, void 0, function* () {
40
- const { type, ref: applicationRef } = call.request;
40
+ const fn = (call) => __awaiter(this, void 0, void 0, function* () {
41
+ const { request } = call;
42
+ const { type, ref: applicationRef } = request;
41
43
  const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
42
- (0, validOrThrow_1.validOrThrow)(call.request);
44
+ (0, validOrThrow_1.validOrThrow)(request);
43
45
  logger.verbose("call to updateApplication", {
44
46
  accessKeyId,
45
47
  type
46
48
  });
47
- // TODO: Revisit to see if needs optimization
48
49
  yield prisma.$transaction([
49
50
  prisma.textToSpeech.deleteMany({
50
51
  where: {
@@ -66,9 +67,10 @@ function updateApplication(prisma) {
66
67
  ref: applicationRef,
67
68
  accessKeyId
68
69
  },
69
- data: (0, convertToApplicationData_1.convertToApplicationData)(call.request)
70
+ data: (0, convertToApplicationData_1.convertToApplicationData)(request)
70
71
  })
71
72
  ]);
72
73
  return { ref: applicationRef };
73
- }), (ref) => getFn(ref));
74
+ });
75
+ return (0, common_1.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
74
76
  }
@@ -7,7 +7,7 @@ declare function getApplicationValidationSchema(request: {
7
7
  type: z.ZodNativeEnum<{
8
8
  EXTERNAL: "EXTERNAL";
9
9
  }>;
10
- endpoint: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string, string>;
10
+ endpoint: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string>;
11
11
  textToSpeech: z.ZodUndefined | z.ZodObject<{
12
12
  productRef: z.ZodString;
13
13
  config: any;
@@ -19,6 +19,7 @@ exports.getApplicationValidationSchema = getApplicationValidationSchema;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ const common_1 = require("@fonoster/common");
22
23
  const client_1 = require("@prisma/client");
23
24
  const zod_1 = require("zod");
24
25
  const Deepgram_1 = require("../../voice/stt/Deepgram");
@@ -26,8 +27,7 @@ const Google_1 = require("../../voice/stt/Google");
26
27
  const Azure_1 = require("../../voice/tts/Azure");
27
28
  const Deepgram_2 = require("../../voice/tts/Deepgram");
28
29
  const Google_2 = require("../../voice/tts/Google");
29
- const hostOrHostPortSchema_1 = require("../hostOrHostPortSchema");
30
- // TODO: We need a way to add this values dynamically
30
+ const MAX_NAME_MESSAGE = "Name must contain at most 255 characters";
31
31
  const validators = {
32
32
  ttsConfigValidators: {
33
33
  "tts.google": Google_2.Google.getConfigValidationSchema,
@@ -51,9 +51,9 @@ const validators = {
51
51
  function getApplicationValidationSchema(request) {
52
52
  const { ttsEngineName, sttEngineName } = request;
53
53
  return zod_1.z.object({
54
- name: zod_1.z.string(),
54
+ name: zod_1.z.string().max(255, MAX_NAME_MESSAGE),
55
55
  type: zod_1.z.nativeEnum(client_1.ApplicationType),
56
- endpoint: hostOrHostPortSchema_1.hostOrHostPortSchema,
56
+ endpoint: common_1.hostOrHostPortSchema,
57
57
  textToSpeech: ttsEngineName
58
58
  ? zod_1.z.object({
59
59
  productRef: zod_1.z.string(),
@@ -8,19 +8,17 @@ declare function buildService(influxdb: InfluxDBClient): Promise<{
8
8
  };
9
9
  handlers: {
10
10
  createCall: (call: {
11
- request: import("@fonoster/types").CreateCallRequest;
12
- }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: import("@fonoster/common").BaseApiObject) => void) => Promise<void>;
11
+ request: unknown;
12
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
13
13
  listCalls: (call: {
14
- request: import("./types").ListCallsRequest;
15
- }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("./types").ListCallsResponse) => void) => Promise<void>;
14
+ request: unknown;
15
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
16
16
  getCall: (call: {
17
- request: import("./types").GetCallRequest;
18
- }, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: import("./types").CallDetailRecord) => void) => Promise<void>;
17
+ request: unknown;
18
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
19
19
  trackCall: (call: {
20
- request: {
21
- ref?: string;
22
- };
23
- }) => void;
20
+ request: unknown;
21
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
24
22
  };
25
23
  }>;
26
24
  export { buildService };
@@ -1,8 +1,7 @@
1
- import { BaseApiObject, GrpcErrorMessage } from "@fonoster/common";
2
- import { CreateCallRequest } from "@fonoster/types";
1
+ import { GrpcErrorMessage } from "@fonoster/common";
3
2
  import { CallPublisher } from "./types";
4
3
  import { Prisma } from "../core/db";
5
4
  declare function createCall(prisma: Prisma, publisher: CallPublisher): (call: {
6
- request: CreateCallRequest;
7
- }, callback: (error?: GrpcErrorMessage, response?: BaseApiObject) => void) => Promise<void>;
5
+ request: unknown;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
8
7
  export { createCall };
@@ -32,42 +32,30 @@ const common_1 = require("@fonoster/common");
32
32
  const identity_1 = require("@fonoster/identity");
33
33
  const logger_1 = require("@fonoster/logger");
34
34
  const uuid_1 = require("uuid");
35
- const zod_1 = require("zod");
36
35
  const notFoundError_1 = require("../core/notFoundError");
37
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
- const CreateCallRequestSchema = zod_1.z.object({
39
- from: zod_1.z.string(),
40
- to: zod_1.z.string(),
41
- appRef: zod_1.z.string(),
42
- timeout: zod_1.z.number().optional()
43
- });
44
37
  function createCall(prisma, publisher) {
45
- return (call, callback) => __awaiter(this, void 0, void 0, function* () {
46
- try {
47
- const { from, to, appRef, timeout } = call.request;
48
- const ref = (0, uuid_1.v4)();
49
- logger.verbose("call to createCall", Object.assign(Object.assign({}, call.request), { ref }));
50
- CreateCallRequestSchema.parse(call.request);
51
- const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
52
- const app = yield prisma.application.findUnique({
53
- where: { ref: appRef, accessKeyId }
54
- });
55
- if (!app) {
56
- throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`);
57
- }
58
- // TODO: Must validate that the from number exists and is owned by the user
59
- publisher.publishCall({
60
- ref,
61
- from,
62
- to,
63
- appRef,
64
- accessKeyId,
65
- timeout: timeout || 60
66
- });
67
- callback(null, { ref });
68
- }
69
- catch (error) {
70
- (0, common_1.handleError)(error, callback);
38
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
+ const { request } = call;
40
+ const { from, to, appRef, timeout } = request;
41
+ const ref = (0, uuid_1.v4)();
42
+ logger.verbose("call to createCall", Object.assign(Object.assign({}, request), { ref }));
43
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
44
+ const app = yield prisma.application.findUnique({
45
+ where: { ref: appRef, accessKeyId }
46
+ });
47
+ if (!app) {
48
+ throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`);
71
49
  }
50
+ publisher.publishCall({
51
+ ref,
52
+ from,
53
+ to,
54
+ appRef,
55
+ accessKeyId,
56
+ timeout: timeout || 60
57
+ });
58
+ callback(null, { ref });
72
59
  });
60
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createCallRequestSchema);
73
61
  }
@@ -1,6 +1,6 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
- import { CallDetailRecord, GetCallRequest, InfluxDBClient } from "./types";
2
+ import { InfluxDBClient } from "./types";
3
3
  declare function getCall(influx: InfluxDBClient): (call: {
4
- request: GetCallRequest;
5
- }, callback: (error: GrpcErrorMessage, response?: CallDetailRecord) => void) => Promise<void>;
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { getCall };
@@ -31,29 +31,20 @@ exports.getCall = getCall;
31
31
  const common_1 = require("@fonoster/common");
32
32
  const identity_1 = require("@fonoster/identity");
33
33
  const logger_1 = require("@fonoster/logger");
34
- const zod_1 = require("zod");
35
34
  const createFetchSingleCall_1 = require("./createFetchSingleCall");
36
35
  const notFoundError_1 = require("../core/notFoundError");
37
36
  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
37
  function getCall(influx) {
42
38
  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);
39
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
+ const { ref } = call.request;
41
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
42
+ logger.verbose("call to getCall", { accessKeyId, ref });
43
+ const response = yield fetchSingleCall(accessKeyId, ref);
44
+ if (!response) {
45
+ throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
57
46
  }
47
+ callback(null, response);
58
48
  });
49
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.getCallRequestSchema);
59
50
  }
@@ -1,6 +1,6 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
- import { InfluxDBClient, ListCallsRequest, ListCallsResponse } from "./types";
2
+ import { InfluxDBClient } from "./types";
3
3
  declare function listCalls(influx: InfluxDBClient): (call: {
4
- request: ListCallsRequest;
5
- }, callback: (error: GrpcErrorMessage, response?: ListCallsResponse) => void) => Promise<void>;
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { listCalls };
@@ -32,20 +32,15 @@ const common_1 = require("@fonoster/common");
32
32
  const identity_1 = require("@fonoster/identity");
33
33
  const logger_1 = require("@fonoster/logger");
34
34
  const createFetchCalls_1 = require("./createFetchCalls");
35
- const ListCallsRequestSchema_1 = require("./ListCallsRequestSchema");
36
35
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
36
  function listCalls(influx) {
38
37
  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
- }
38
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
+ const { request } = call;
40
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
41
+ logger.verbose("call to listCalls", { request, accessKeyId });
42
+ const result = yield fetchCalls(accessKeyId, request);
43
+ callback(null, result);
50
44
  });
45
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listCallsRequestSchema);
51
46
  }
@@ -1,14 +1,5 @@
1
1
  import { NatsConnection } from "nats";
2
- import { z } from "zod";
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
2
  declare function makeTrackCall(nc: NatsConnection): (call: {
12
- request: TrackCallRequest;
13
- }) => void;
3
+ request: unknown;
4
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
14
5
  export { makeTrackCall };
@@ -21,18 +21,13 @@ exports.makeTrackCall = makeTrackCall;
21
21
  */
22
22
  const common_1 = require("@fonoster/common");
23
23
  const logger_1 = require("@fonoster/logger");
24
- const zod_1 = require("zod");
25
24
  const envs_1 = require("../envs");
26
25
  const FINAL_STATUSES = [
27
- common_1.DialStatus.ANSWER,
28
26
  common_1.DialStatus.BUSY,
29
27
  common_1.DialStatus.FAILED,
30
28
  common_1.DialStatus.NOANSWER
31
29
  ];
32
30
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
33
- const TrackCallRequestSchema = zod_1.z.object({
34
- ref: zod_1.z.string()
35
- });
36
31
  function makeTrackCall(nc) {
37
32
  const trackingCallsMap = new Map();
38
33
  const subscription = nc.subscribe(envs_1.CALLS_TRACK_CALL_SUBJECT);
@@ -58,10 +53,11 @@ function makeTrackCall(nc) {
58
53
  stream.write({ ref, status });
59
54
  }
60
55
  };
61
- return (call) => {
56
+ const fn = (call) => {
62
57
  const stream = call;
63
58
  const { ref } = call.request;
64
59
  logger.verbose("call to trackCall", { ref });
65
60
  trackingCallsMap.set(ref, stream);
66
61
  };
62
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
67
63
  }
@@ -59,4 +59,4 @@ type TrackCallSubscriber = {
59
59
  on: (event: string, cb: (data: TrackCallResponse | Error) => void) => void;
60
60
  };
61
61
  };
62
- export { CALL_DETAIL_RECORD_MEASUREMENT, CallDetailRecord, ListCallsRequest, ListCallsResponse, GetCallRequest, CallType, CallStatus, CallDirection, InfluxDBClient, CreateCallRequest, CallPublisher, TrackCallResponse, CallStream, TrackCallSubscriber };
62
+ export { CALL_DETAIL_RECORD_MEASUREMENT, CallDetailRecord, CallDirection, CallPublisher, CallStatus, CallStream, CallType, CreateCallRequest, GetCallRequest, InfluxDBClient, ListCallsRequest, ListCallsResponse, TrackCallResponse, TrackCallSubscriber };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CallDirection = exports.CallStatus = exports.CallType = exports.CALL_DETAIL_RECORD_MEASUREMENT = void 0;
3
+ exports.CallType = exports.CallStatus = exports.CallDirection = exports.CALL_DETAIL_RECORD_MEASUREMENT = void 0;
4
4
  const types_1 = require("@fonoster/types");
5
5
  Object.defineProperty(exports, "CallDirection", { enumerable: true, get: function () { return types_1.CallDirection; } });
6
6
  Object.defineProperty(exports, "CallStatus", { enumerable: true, get: function () { return types_1.CallStatus; } });
package/dist/core/db.d.ts CHANGED
@@ -10,4 +10,4 @@ declare const prisma: import("@prisma/client/runtime/library").DynamicClientExte
10
10
  client: {};
11
11
  }, {}>;
12
12
  type Prisma = typeof prisma;
13
- export { prisma, Prisma };
13
+ export { Prisma, prisma };