@fonoster/apiserver 0.7.4 → 0.7.5

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 (62) 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 +4 -2
  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 +4 -2
  14. package/dist/applications/utils/getApplicationValidationSchema.js +2 -2
  15. package/dist/calls/buildService.d.ts +6 -6
  16. package/dist/calls/createCall.d.ts +3 -4
  17. package/dist/calls/createCall.js +22 -27
  18. package/dist/calls/getCall.d.ts +3 -3
  19. package/dist/calls/getCall.js +10 -15
  20. package/dist/calls/listCalls.d.ts +3 -3
  21. package/dist/calls/listCalls.js +8 -12
  22. package/dist/calls/makeTrackCall.d.ts +2 -2
  23. package/dist/calls/makeTrackCall.js +1 -2
  24. package/dist/calls/types.d.ts +1 -1
  25. package/dist/calls/types.js +1 -1
  26. package/dist/core/db.d.ts +1 -1
  27. package/dist/core/services.d.ts +105 -146
  28. package/dist/envs.d.ts +33 -33
  29. package/dist/envs.js +40 -40
  30. package/dist/events/createInfluxDbPub.d.ts +1 -1
  31. package/dist/events/nats.js +0 -1
  32. package/dist/events/types.d.ts +1 -1
  33. package/dist/secrets/buildService.d.ts +10 -12
  34. package/dist/secrets/createSecret.d.ts +2 -3
  35. package/dist/secrets/createSecret.js +10 -14
  36. package/dist/secrets/deleteSecret.d.ts +2 -3
  37. package/dist/secrets/deleteSecret.js +4 -2
  38. package/dist/secrets/getSecret.d.ts +2 -3
  39. package/dist/secrets/getSecret.js +4 -2
  40. package/dist/secrets/listSecrets.d.ts +2 -3
  41. package/dist/secrets/listSecrets.js +12 -16
  42. package/dist/secrets/updateSecret.d.ts +2 -5
  43. package/dist/secrets/updateSecret.js +4 -2
  44. package/dist/voice/handlers/Say.js +0 -1
  45. package/dist/voice/handlers/Stream.js +0 -1
  46. package/dist/voice/handlers/StreamGather.js +0 -1
  47. package/dist/voice/handlers/gather/Gather.js +0 -1
  48. package/dist/voice/handlers/index.d.ts +5 -5
  49. package/dist/voice/handlers/index.js +5 -5
  50. package/dist/voice/integrations/types.d.ts +1 -1
  51. package/dist/voice/stt/Google.d.ts +1 -1
  52. package/dist/voice/stt/Google.js +1 -1
  53. package/dist/voice/stt/types.d.ts +6 -6
  54. package/dist/voice/tts/Google.d.ts +1 -1
  55. package/dist/voice/tts/Google.js +1 -1
  56. package/dist/voice/tts/types.d.ts +1 -1
  57. package/dist/voice/types/voice.d.ts +1 -1
  58. package/package.json +8 -8
  59. package/dist/applications/hostOrHostPortSchema.d.ts +0 -3
  60. package/dist/applications/hostOrHostPortSchema.js +0 -34
  61. package/dist/calls/ListCallsRequestSchema.d.ts +0 -25
  62. 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.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
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,6 +28,7 @@ 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 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");
@@ -35,10 +36,11 @@ const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedSt
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, common_1.withErrorHandling)((0, identity_1.withAccess)(fn, (ref) => getFn(ref)));
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?: 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.withErrorHandling)(fn);
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,7 +37,7 @@ 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 fn = (call) => __awaiter(this, void 0, void 0, function* () {
40
41
  const { type, ref: applicationRef } = call.request;
41
42
  const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
42
43
  (0, validOrThrow_1.validOrThrow)(call.request);
@@ -70,5 +71,6 @@ function updateApplication(prisma) {
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
  }
@@ -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,7 +27,6 @@ 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
30
  // TODO: We need a way to add this values dynamically
31
31
  const validators = {
32
32
  ttsConfigValidators: {
@@ -53,7 +53,7 @@ function getApplicationValidationSchema(request) {
53
53
  return zod_1.z.object({
54
54
  name: zod_1.z.string(),
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,14 +8,14 @@ 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
20
  request: {
21
21
  ref?: string;
@@ -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?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
8
7
  export { createCall };
@@ -35,39 +35,34 @@ const uuid_1 = require("uuid");
35
35
  const zod_1 = require("zod");
36
36
  const notFoundError_1 = require("../core/notFoundError");
37
37
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
- const CreateCallRequestSchema = zod_1.z.object({
38
+ const createCallRequestSchema = zod_1.z.object({
39
39
  from: zod_1.z.string(),
40
40
  to: zod_1.z.string(),
41
41
  appRef: zod_1.z.string(),
42
42
  timeout: zod_1.z.number().optional()
43
43
  });
44
44
  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);
45
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
46
+ const { request } = call;
47
+ const { from, to, appRef, timeout } = request;
48
+ const ref = (0, uuid_1.v4)();
49
+ logger.verbose("call to createCall", Object.assign(Object.assign({}, request), { ref }));
50
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
51
+ const app = yield prisma.application.findUnique({
52
+ where: { ref: appRef, accessKeyId }
53
+ });
54
+ if (!app) {
55
+ throw (0, notFoundError_1.notFoundError)(`Application with ref ${appRef} not found`);
71
56
  }
57
+ publisher.publishCall({
58
+ ref,
59
+ from,
60
+ to,
61
+ appRef,
62
+ accessKeyId,
63
+ timeout: timeout || 60
64
+ });
65
+ callback(null, { ref });
72
66
  });
67
+ return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, createCallRequestSchema));
73
68
  }
@@ -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?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { getCall };
@@ -35,25 +35,20 @@ const zod_1 = require("zod");
35
35
  const createFetchSingleCall_1 = require("./createFetchSingleCall");
36
36
  const notFoundError_1 = require("../core/notFoundError");
37
37
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
38
- const GetCallRequestSchema = zod_1.z.object({
38
+ const getCallRequestSchema = zod_1.z.object({
39
39
  ref: zod_1.z.string({ message: "Invalid call reference" })
40
40
  });
41
41
  function getCall(influx) {
42
42
  const fetchSingleCall = (0, createFetchSingleCall_1.createFetchSingleCall)(influx);
43
- return (call, callback) => __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const { ref } = call.request;
46
- GetCallRequestSchema.parse({ ref });
47
- const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
48
- logger.verbose("call to getCall", { accessKeyId, ref });
49
- const response = yield fetchSingleCall(accessKeyId, ref);
50
- if (!response) {
51
- throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
52
- }
53
- callback(null, response);
54
- }
55
- catch (error) {
56
- (0, common_1.handleError)(error, callback);
43
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
44
+ const { ref } = call.request;
45
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
46
+ logger.verbose("call to getCall", { accessKeyId, ref });
47
+ const response = yield fetchSingleCall(accessKeyId, ref);
48
+ if (!response) {
49
+ throw (0, notFoundError_1.notFoundError)(`Call not found: ${ref}`);
57
50
  }
51
+ callback(null, response);
58
52
  });
53
+ return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, getCallRequestSchema));
59
54
  }
@@ -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?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { listCalls };
@@ -29,23 +29,19 @@ exports.listCalls = listCalls;
29
29
  * limitations under the License.
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
+ const listCallsRequestSchema_1 = require("@fonoster/common/src/validators/listCallsRequestSchema");
32
33
  const identity_1 = require("@fonoster/identity");
33
34
  const logger_1 = require("@fonoster/logger");
34
35
  const createFetchCalls_1 = require("./createFetchCalls");
35
- const ListCallsRequestSchema_1 = require("./ListCallsRequestSchema");
36
36
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
37
37
  function listCalls(influx) {
38
38
  const fetchCalls = (0, createFetchCalls_1.createFetchCalls)(influx);
39
- return (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
- try {
41
- const parsedRequest = ListCallsRequestSchema_1.ListCallsRequestSchema.parse(call.request);
42
- const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
43
- logger.verbose("call to listCalls", { parsedRequest, accessKeyId });
44
- const result = yield fetchCalls(accessKeyId, parsedRequest);
45
- callback(null, result);
46
- }
47
- catch (error) {
48
- (0, common_1.handleError)(error, callback);
49
- }
39
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
+ const { request } = call;
41
+ const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
42
+ logger.verbose("call to listCalls", { request, accessKeyId });
43
+ const result = yield fetchCalls(accessKeyId, request);
44
+ callback(null, result);
50
45
  });
46
+ return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, listCallsRequestSchema_1.listCallsRequestSchema));
51
47
  }
@@ -1,13 +1,13 @@
1
1
  import { NatsConnection } from "nats";
2
2
  import { z } from "zod";
3
- declare const TrackCallRequestSchema: z.ZodObject<{
3
+ declare const trackCallRequestSchema: z.ZodObject<{
4
4
  ref: z.ZodString;
5
5
  }, "strip", z.ZodTypeAny, {
6
6
  ref?: string;
7
7
  }, {
8
8
  ref?: string;
9
9
  }>;
10
- type TrackCallRequest = z.infer<typeof TrackCallRequestSchema>;
10
+ type TrackCallRequest = z.infer<typeof trackCallRequestSchema>;
11
11
  declare function makeTrackCall(nc: NatsConnection): (call: {
12
12
  request: TrackCallRequest;
13
13
  }) => void;
@@ -24,13 +24,12 @@ const logger_1 = require("@fonoster/logger");
24
24
  const zod_1 = require("zod");
25
25
  const envs_1 = require("../envs");
26
26
  const FINAL_STATUSES = [
27
- common_1.DialStatus.ANSWER,
28
27
  common_1.DialStatus.BUSY,
29
28
  common_1.DialStatus.FAILED,
30
29
  common_1.DialStatus.NOANSWER
31
30
  ];
32
31
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
33
- const TrackCallRequestSchema = zod_1.z.object({
32
+ const trackCallRequestSchema = zod_1.z.object({
34
33
  ref: zod_1.z.string()
35
34
  });
36
35
  function makeTrackCall(nc) {
@@ -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 };