@fonoster/voice 0.7.18 → 0.7.25

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.
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
54
54
  * limitations under the License.
55
55
  */
56
56
  const common_1 = require("@fonoster/common");
57
+ const identity_1 = require("@fonoster/identity");
57
58
  const logger_1 = require("@fonoster/logger");
58
59
  const grpc = __importStar(require("@grpc/grpc-js"));
59
60
  const deepmerge_1 = __importDefault(require("deepmerge"));
@@ -71,20 +72,20 @@ class VoiceServer {
71
72
  try {
72
73
  const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
73
74
  const credentials = yield (0, common_1.getServerCredentials)({});
74
- const server = new grpc.Server();
75
- // FIXME: Must re-implement without dependency on identity package
76
- // if (this.config.skipIdentity) {
77
- // server = new grpc.Server();
78
- // } else {
79
- // // Get the public key from the identity service
80
- // const response = await getPublicKeyClient(this.config.identityAddress);
81
- // const authorization = createAuthInterceptor(response.publicKey, [
82
- // "/grpc.health.v1.Health/Check"
83
- // ]);
84
- // server = new grpc.Server({
85
- // interceptors: [authorization]
86
- // });
87
- // }
75
+ let server;
76
+ if (this.config.skipIdentity) {
77
+ server = new grpc.Server();
78
+ }
79
+ else {
80
+ // Get the public key from the identity service
81
+ const response = yield (0, identity_1.getPublicKeyClient)(this.config.identityAddress);
82
+ const authorization = (0, identity_1.createAuthInterceptor)(response.publicKey, [
83
+ "/grpc.health.v1.Health/Check"
84
+ ]);
85
+ server = new grpc.Server({
86
+ interceptors: [authorization]
87
+ });
88
+ }
88
89
  server.addService(serviceDefinition_1.serviceDefinition, {
89
90
  createSession: (0, createSession_1.createSession)(handler)
90
91
  });
@@ -27,8 +27,16 @@ class Dial extends Verb_1.Verb {
27
27
  getValidationSchema() {
28
28
  return zod_1.z.object({
29
29
  destination: zod_1.z.string(),
30
- timeout: zod_1.z.number().int().positive().optional(),
31
- recordDirection: zod_1.z.nativeEnum(common_1.DialRecordDirection).optional()
30
+ timeout: zod_1.z
31
+ .number()
32
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
33
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
34
+ .optional(),
35
+ recordDirection: zod_1.z
36
+ .nativeEnum(common_1.DialRecordDirection, {
37
+ message: "Invalid record direction."
38
+ })
39
+ .optional()
32
40
  });
33
41
  }
34
42
  }
@@ -25,14 +25,32 @@ const Verb_1 = require("./Verb");
25
25
  class Gather extends Verb_1.Verb {
26
26
  getValidationSchema() {
27
27
  return zod_1.z.object({
28
- source: zod_1.z.nativeEnum(common_1.GatherSource).optional(),
28
+ source: zod_1.z
29
+ .nativeEnum(common_1.GatherSource, {
30
+ message: "Invalid gather source."
31
+ })
32
+ .optional(),
29
33
  finishOnKey: zod_1.z
30
34
  .string()
31
- .regex(/^[0-9*#]+$/)
32
- .length(1)
35
+ .regex(/^[0-9*#]+$/, { message: common_1.Messages.VALID_DTMF })
36
+ .length(1, { message: common_1.Messages.MUST_BE_A_SINGLE_CHARACTER })
37
+ .optional(),
38
+ timeout: zod_1.z
39
+ .number()
40
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
41
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
33
42
  .optional(),
34
- timeout: zod_1.z.number().int().positive().optional(),
35
- maxDigits: zod_1.z.number().int().positive().optional()
43
+ maxDigits: zod_1.z
44
+ .number({
45
+ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE
46
+ })
47
+ .int({
48
+ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE
49
+ })
50
+ .positive({
51
+ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE
52
+ })
53
+ .optional()
36
54
  });
37
55
  }
38
56
  }
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Play = 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 common_1 = require("@fonoster/common");
4
23
  const zod_1 = require("zod");
5
24
  const Verb_1 = require("./Verb");
6
25
  class Play extends Verb_1.Verb {
7
26
  getValidationSchema() {
8
27
  return zod_1.z.object({
9
- url: zod_1.z.string().url(),
10
- playbackRef: zod_1.z.string().optional()
28
+ url: zod_1.z.string().url({ message: common_1.Messages.VALID_URL }),
29
+ playbackRef: zod_1.z.string().uuid({ message: common_1.Messages.VALID_UUID }).optional()
11
30
  });
12
31
  }
13
32
  }
@@ -1,12 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlayDtmf = 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 common_1 = require("@fonoster/common");
4
23
  const zod_1 = require("zod");
5
24
  const Verb_1 = require("./Verb");
6
25
  class PlayDtmf extends Verb_1.Verb {
7
26
  getValidationSchema() {
8
27
  return zod_1.z.object({
9
- digits: zod_1.z.string().regex(/^[0-9*#]+$/)
28
+ digits: zod_1.z.string().regex(/^[0-9*#]+$/, { message: common_1.Messages.VALID_DTMF })
10
29
  });
11
30
  }
12
31
  }
@@ -25,8 +25,10 @@ const Verb_1 = require("./Verb");
25
25
  class PlaybackControl extends Verb_1.Verb {
26
26
  getValidationSchema() {
27
27
  return zod_1.z.object({
28
- playbackRef: zod_1.z.string(),
29
- action: zod_1.z.nativeEnum(common_1.PlaybackControlAction)
28
+ playbackRef: zod_1.z.string().uuid({ message: common_1.Messages.VALID_UUID }),
29
+ action: zod_1.z.nativeEnum(common_1.PlaybackControlAction, {
30
+ message: "Invalid playback control action"
31
+ })
30
32
  });
31
33
  }
32
34
  }
@@ -1,18 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Record = 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 common_1 = require("@fonoster/common");
4
23
  const zod_1 = require("zod");
5
24
  const Verb_1 = require("./Verb");
6
25
  class Record extends Verb_1.Verb {
7
26
  getValidationSchema() {
8
27
  return zod_1.z.object({
9
- maxDuration: zod_1.z.number().int().positive().optional(),
10
- maxSilence: zod_1.z.number().int().positive().optional(),
28
+ maxDuration: zod_1.z
29
+ .number()
30
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
31
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
32
+ .optional(),
33
+ maxSilence: zod_1.z
34
+ .number()
35
+ .int({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
36
+ .positive({ message: common_1.Messages.POSITIVE_INTEGER_MESSAGE })
37
+ .optional(),
11
38
  beep: zod_1.z.boolean().optional(),
12
39
  finishOnKey: zod_1.z
13
40
  .string()
14
- .regex(/^[0-9*#]+$/)
15
- .length(1)
41
+ .regex(/^[0-9*#]+$/, { message: common_1.Messages.VALID_DTMF })
42
+ .length(1, {
43
+ message: common_1.Messages.MUST_BE_A_SINGLE_CHARACTER
44
+ })
16
45
  .optional()
17
46
  });
18
47
  }
package/dist/verbs/Say.js CHANGED
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Say = 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 common_1 = require("@fonoster/common");
4
23
  const zod_1 = require("zod");
5
24
  const Verb_1 = require("./Verb");
6
25
  class Say extends Verb_1.Verb {
7
26
  getValidationSchema() {
8
27
  return zod_1.z.object({
9
28
  text: zod_1.z.string().min(1),
10
- playbackRef: zod_1.z.string().optional()
29
+ playbackRef: zod_1.z.string().uuid({ message: common_1.Messages.VALID_UUID }).optional()
11
30
  });
12
31
  }
13
32
  }
@@ -26,8 +26,14 @@ const Verb_1 = require("./Verb");
26
26
  class StartStream extends Verb_1.Verb {
27
27
  getValidationSchema() {
28
28
  return zod_1.z.object({
29
- direction: zod_1.z.nativeEnum(common_1.StreamDirection).optional().nullable(),
30
- format: zod_1.z.nativeEnum(common_1.StreamAudioFormat).optional().nullable()
29
+ direction: zod_1.z
30
+ .nativeEnum(common_1.StreamDirection, { message: "Invalid stream direction" })
31
+ .optional(),
32
+ format: zod_1.z
33
+ .nativeEnum(common_1.StreamAudioFormat, {
34
+ message: "Invalid stream audio direction"
35
+ })
36
+ .optional()
31
37
  });
32
38
  }
33
39
  }
@@ -35,7 +41,7 @@ exports.StartStream = StartStream;
35
41
  class StopStream extends Verb_1.Verb {
36
42
  getValidationSchema() {
37
43
  return zod_1.z.object({
38
- streamRef: zod_1.z.string()
44
+ streamRef: zod_1.z.string().uuid({ message: common_1.Messages.VALID_UUID })
39
45
  });
40
46
  }
41
47
  }
@@ -26,7 +26,9 @@ const Verb_1 = require("./Verb");
26
26
  class StartStreamGather extends Verb_1.Verb {
27
27
  getValidationSchema() {
28
28
  return zod_1.z.object({
29
- source: zod_1.z.optional(zod_1.z.nativeEnum(common_1.StreamGatherSource))
29
+ source: zod_1.z.optional(zod_1.z.nativeEnum(common_1.StreamGatherSource, {
30
+ message: "Invalid stream gather source."
31
+ }))
30
32
  });
31
33
  }
32
34
  }
@@ -34,7 +36,7 @@ exports.StartStreamGather = StartStreamGather;
34
36
  class StopStreamGather extends Verb_1.Verb {
35
37
  getValidationSchema() {
36
38
  return zod_1.z.object({
37
- sessionRef: zod_1.z.string()
39
+ sessionRef: zod_1.z.string().uuid({ message: common_1.Messages.VALID_UUID })
38
40
  });
39
41
  }
40
42
  }
@@ -5,7 +5,9 @@ const zod_validation_error_1 = require("zod-validation-error");
5
5
  function validateRequest(schema, data) {
6
6
  const parsedData = schema.safeParse(data);
7
7
  if (!parsedData.success) {
8
- throw (0, zod_validation_error_1.fromError)(parsedData.error);
8
+ throw (0, zod_validation_error_1.fromError)(parsedData.error, {
9
+ prefix: null
10
+ });
9
11
  }
10
12
  return parsedData.data;
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/voice",
3
- "version": "0.7.18",
3
+ "version": "0.7.25",
4
4
  "description": "Voice Server for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -21,8 +21,9 @@
21
21
  "fonoster": "./dist/index.js"
22
22
  },
23
23
  "dependencies": {
24
- "@fonoster/common": "^0.7.18",
25
- "@fonoster/logger": "^0.7.18",
24
+ "@fonoster/common": "^0.7.25",
25
+ "@fonoster/identity": "^0.7.25",
26
+ "@fonoster/logger": "^0.7.22",
26
27
  "@grpc/grpc-js": "~1.10.6",
27
28
  "deepmerge": "^4.3.1",
28
29
  "grpc-health-check": "^2.0.2",
@@ -43,5 +44,5 @@
43
44
  "bugs": {
44
45
  "url": "https://github.com/fonoster/fonoster/issues"
45
46
  },
46
- "gitHead": "4150dcb8086de182d0650df0c6d990ee76658058"
47
+ "gitHead": "f5dbfe479bd50b105ce3eb4b3c260503ef718f57"
47
48
  }