@webitel/api-services 26.12.21 → 26.12.22

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 (80) hide show
  1. package/package.json +1 -1
  2. package/src/api/clients/_shared/appUrls.ts +11 -0
  3. package/src/api/clients/chatGateways/__tests__/chatGatewayChannels.spec.ts +84 -0
  4. package/src/api/clients/chatGateways/__tests__/chatGateways.spec.ts +115 -0
  5. package/src/api/clients/chatGateways/chatGatewayChannels.ts +162 -0
  6. package/src/api/clients/chatGateways/chatGateways.ts +66 -25
  7. package/src/api/clients/chatGateways/defaults/chatGatewayProviderDefaults.ts +91 -0
  8. package/src/api/clients/chatGateways/defaults/defaultChatGateway.ts +3 -1
  9. package/src/api/clients/chatGateways/defaults/webChatGateway.ts +8 -5
  10. package/src/api/clients/cognitiveProfiles/cognitiveProfiles.ts +8 -32
  11. package/src/api/clients/cognitiveProfiles/defaults/cognitiveProfileDefaults.ts +39 -0
  12. package/src/api/clients/gateways/__tests__/gateways.spec.ts +138 -0
  13. package/src/api/clients/gateways/gateways.ts +60 -52
  14. package/src/api/clients/index.ts +2 -0
  15. package/src/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.ts +10 -0
  16. package/src/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.ts +8 -0
  17. package/src/enums/GatewayRegisterState/GatewayRegisterState.ts +17 -0
  18. package/src/enums/StorageType/StorageType.ts +10 -0
  19. package/src/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.ts +15 -0
  20. package/src/enums/index.ts +10 -0
  21. package/src/locale/en/en.ts +8 -0
  22. package/src/locale/es/es.ts +8 -0
  23. package/src/locale/kz/kz.ts +8 -0
  24. package/src/locale/pl/pl.ts +8 -0
  25. package/src/locale/ro/ro.ts +8 -0
  26. package/src/locale/ru/ru.ts +8 -0
  27. package/src/locale/uk/uk.ts +8 -0
  28. package/src/locale/uz/uz.ts +8 -0
  29. package/src/locale/vi/vi.ts +8 -0
  30. package/src/validations/_shared/ip.validations.ts +10 -0
  31. package/src/validations/backendProfile/__tests__/backendProfile.validations.spec.ts +104 -0
  32. package/src/validations/backendProfile/backendProfile.validations.ts +79 -0
  33. package/src/validations/chatGateway/__tests__/chatGateway.validations.spec.ts +189 -0
  34. package/src/validations/chatGateway/chatGateway.validations.ts +452 -0
  35. package/src/validations/cognitiveProfile/__tests__/cognitiveProfile.validations.spec.ts +83 -0
  36. package/src/validations/cognitiveProfile/cognitiveProfile.validations.ts +74 -0
  37. package/src/validations/device/device.validations.ts +2 -8
  38. package/src/validations/gateway/__tests__/gateway.validations.spec.ts +168 -0
  39. package/src/validations/gateway/gateway.validations.ts +138 -0
  40. package/src/validations/index.ts +4 -0
  41. package/types/.tsbuildinfo +1 -1
  42. package/types/api/clients/_shared/appUrls.d.ts +11 -0
  43. package/types/api/clients/chatGateways/chatGatewayChannels.d.ts +62 -0
  44. package/types/api/clients/chatGateways/chatGateways.d.ts +4 -4
  45. package/types/api/clients/chatGateways/defaults/chatGatewayProviderDefaults.d.ts +21 -0
  46. package/types/api/clients/chatGateways/defaults/defaultChatGateway.d.ts +3 -1
  47. package/types/api/clients/chatGateways/defaults/webChatGateway.d.ts +5 -4
  48. package/types/api/clients/cognitiveProfiles/cognitiveProfiles.d.ts +1 -1
  49. package/types/api/clients/cognitiveProfiles/defaults/cognitiveProfileDefaults.d.ts +13 -0
  50. package/types/api/clients/index.d.ts +2 -0
  51. package/types/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.d.ts +8 -0
  52. package/types/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.d.ts +6 -0
  53. package/types/enums/GatewayRegisterState/GatewayRegisterState.d.ts +15 -0
  54. package/types/enums/StorageType/StorageType.d.ts +9 -0
  55. package/types/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.d.ts +13 -0
  56. package/types/enums/index.d.ts +6 -1
  57. package/types/locale/en/en.d.ts +7 -0
  58. package/types/locale/es/es.d.ts +7 -0
  59. package/types/locale/index.d.ts +63 -0
  60. package/types/locale/kz/kz.d.ts +7 -0
  61. package/types/locale/pl/pl.d.ts +7 -0
  62. package/types/locale/ro/ro.d.ts +7 -0
  63. package/types/locale/ru/ru.d.ts +7 -0
  64. package/types/locale/uk/uk.d.ts +7 -0
  65. package/types/locale/uz/uz.d.ts +7 -0
  66. package/types/locale/vi/vi.d.ts +7 -0
  67. package/types/validations/_shared/ip.validations.d.ts +4 -0
  68. package/types/validations/backendProfile/backendProfile.validations.d.ts +24 -0
  69. package/types/validations/chatGateway/chatGateway.validations.d.ts +165 -0
  70. package/types/validations/cognitiveProfile/cognitiveProfile.validations.d.ts +28 -0
  71. package/types/validations/gateway/gateway.validations.d.ts +48 -0
  72. package/types/validations/index.d.ts +4 -0
  73. package/src/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.ts +0 -12
  74. package/src/api/clients/gateways/defaults/defaultGateway.ts +0 -9
  75. package/src/api/clients/gateways/defaults/registerGateway.ts +0 -12
  76. package/src/api/clients/gateways/defaults/trunkingGateway.ts +0 -16
  77. package/types/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.d.ts +0 -12
  78. package/types/api/clients/gateways/defaults/defaultGateway.d.ts +0 -8
  79. package/types/api/clients/gateways/defaults/registerGateway.d.ts +0 -13
  80. package/types/api/clients/gateways/defaults/trunkingGateway.d.ts +0 -16
@@ -0,0 +1,168 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { gatewaySchema } from '../gateway.validations';
4
+
5
+ const issuePaths = (value: unknown) => {
6
+ const result = gatewaySchema.safeParse(value);
7
+ return result.success
8
+ ? []
9
+ : result.error.issues.map(({ path }) => path.join('.'));
10
+ };
11
+
12
+ const registerGateway = {
13
+ register: true,
14
+ name: 'reg',
15
+ account: 'sip:user@example.com',
16
+ password: 'secret',
17
+ proxy: 'sip.example.com',
18
+ expires: 600,
19
+ };
20
+
21
+ const trunkingGateway = {
22
+ register: false,
23
+ name: 'trunk',
24
+ proxy: '10.0.0.1',
25
+ host: 'sip:10.0.0.2:5060',
26
+ ipacl: [
27
+ {
28
+ ip: '10.0.0.3',
29
+ proto: 'udp',
30
+ port: 5060,
31
+ },
32
+ ],
33
+ };
34
+
35
+ describe('gatewaySchema', () => {
36
+ it('fills defaults for a new gateway', () => {
37
+ expect(gatewaySchema.parse(registerGateway)).toMatchObject({
38
+ enable: true,
39
+ schema: {},
40
+ ipacl: [],
41
+ });
42
+ });
43
+
44
+ describe('register', () => {
45
+ it('accepts a valid gateway', () => {
46
+ expect(issuePaths(registerGateway)).toEqual([]);
47
+ });
48
+
49
+ it('requires account, proxy and password on create', () => {
50
+ expect(
51
+ issuePaths({
52
+ register: true,
53
+ }),
54
+ ).toEqual([
55
+ 'proxy',
56
+ 'account',
57
+ 'password',
58
+ ]);
59
+ });
60
+
61
+ it('keeps the stored password on update', () => {
62
+ expect(
63
+ issuePaths({
64
+ ...registerGateway,
65
+ id: '1',
66
+ password: '',
67
+ }),
68
+ ).toEqual([]);
69
+ });
70
+
71
+ it.each([
72
+ 31,
73
+ 3601,
74
+ null,
75
+ ])('rejects expires %j', (expires) => {
76
+ expect(
77
+ issuePaths({
78
+ ...registerGateway,
79
+ expires,
80
+ }),
81
+ ).toEqual([
82
+ 'expires',
83
+ ]);
84
+ });
85
+
86
+ it('rejects a password with special symbols', () => {
87
+ expect(
88
+ issuePaths({
89
+ ...registerGateway,
90
+ password: 'pa$$ word',
91
+ }),
92
+ ).toEqual([
93
+ 'password',
94
+ ]);
95
+ });
96
+
97
+ it('does not require trunking fields', () => {
98
+ expect(
99
+ issuePaths({
100
+ ...registerGateway,
101
+ host: '',
102
+ }),
103
+ ).toEqual([]);
104
+ });
105
+ });
106
+
107
+ describe('trunking', () => {
108
+ it('accepts a valid gateway', () => {
109
+ expect(issuePaths(trunkingGateway)).toEqual([]);
110
+ });
111
+
112
+ it('requires host, proxy and every acl ip', () => {
113
+ expect(
114
+ issuePaths({
115
+ register: false,
116
+ ipacl: [
117
+ {
118
+ ip: '',
119
+ },
120
+ ],
121
+ }),
122
+ ).toEqual([
123
+ 'ipacl.0.ip',
124
+ 'proxy',
125
+ 'host',
126
+ ]);
127
+ });
128
+
129
+ it.each([
130
+ '127.0.0.1',
131
+ '0.0.0.0',
132
+ '10.0.0',
133
+ ])('rejects acl ip %j', (ip) => {
134
+ expect(
135
+ issuePaths({
136
+ ...trunkingGateway,
137
+ ipacl: [
138
+ {
139
+ ip,
140
+ },
141
+ ],
142
+ }),
143
+ ).toEqual([
144
+ 'ipacl.0.ip',
145
+ ]);
146
+ });
147
+
148
+ it('rejects a host that is neither ip nor fqdn', () => {
149
+ expect(
150
+ issuePaths({
151
+ ...trunkingGateway,
152
+ host: 'not a host',
153
+ }),
154
+ ).toEqual([
155
+ 'host',
156
+ ]);
157
+ });
158
+
159
+ it('does not check registration fields', () => {
160
+ expect(
161
+ issuePaths({
162
+ ...trunkingGateway,
163
+ expires: 0,
164
+ }),
165
+ ).toEqual([]);
166
+ });
167
+ });
168
+ });
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod';
2
+
3
+ import { GatewayIpAclProtocol } from '../../enums/GatewayIpAclProtocol/GatewayIpAclProtocol';
4
+
5
+ import { clearableNumberSchema } from '../_shared/clearableNumber.validations';
6
+ import { i18nIssue } from '../_shared/i18nIssue';
7
+ import { ipv4Pattern, isIp } from '../_shared/ip.validations';
8
+ import { isFilled } from '../_shared/isFilled';
9
+ import { lookupSchema } from '../_shared/lookup.validations';
10
+
11
+ const gatewayIpHostRegex = new RegExp(
12
+ `^(sips?:)?${ipv4Pattern}(:[0-9]{1,5})?$`,
13
+ );
14
+ const gatewayFqdnHostRegex =
15
+ /^(sips?:)?(?=.{1,254}$)((?=[a-z0-9-]{1,63}\.)(xn--+)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}/i;
16
+ const sipAccountRegex =
17
+ /^(sips?:)?([\w\-.!~*()&=+$,;?/]+)(?:@([\w\-.]+)(?::(\d{3,5}))?)?$/i;
18
+ const sipPasswordRegex = /^[A-Za-z0-9\-_.~]+$/;
19
+
20
+ /** [Claude] format rule only: an empty value passes, required is checked per gateway type */
21
+ const isGatewayHost = (value: string) =>
22
+ !value || gatewayIpHostRegex.test(value) || gatewayFqdnHostRegex.test(value);
23
+
24
+ const gatewayHostSchema = z
25
+ .string()
26
+ .optional()
27
+ .default('')
28
+ .refine(isGatewayHost, i18nIssue('gatewayHostValidator'));
29
+
30
+ export const gatewayIpAclSchema = z.object({
31
+ ip: z
32
+ .string()
33
+ .refine(isFilled, i18nIssue('required'))
34
+ .refine(isIp, i18nIssue('ipValidator')),
35
+ proto: z.enum(GatewayIpAclProtocol).default(GatewayIpAclProtocol.Any),
36
+ port: clearableNumberSchema,
37
+ });
38
+
39
+ export const GATEWAY_EXPIRES_MIN = 32;
40
+ export const GATEWAY_EXPIRES_MAX = 3600;
41
+
42
+ /** [Claude] checked only for a registration: trunks don't use expires and may come with 0 */
43
+ const expiresRangeSchema = z
44
+ .number()
45
+ .min(GATEWAY_EXPIRES_MIN)
46
+ .max(GATEWAY_EXPIRES_MAX);
47
+
48
+ /**
49
+ * [Claude] One schema for both gateway types, `register` tells them apart:
50
+ * a SIP registration needs account, password (on create) and expires,
51
+ * a SIP trunk needs host and an ip for every ACL entry.
52
+ */
53
+ export const gatewaySchema = z
54
+ .object({
55
+ id: z
56
+ .union([
57
+ z.string(),
58
+ z.number(),
59
+ ])
60
+ .optional(),
61
+ name: z.string().default(''),
62
+ register: z.boolean().default(false),
63
+ enable: z.boolean().default(true),
64
+ proxy: gatewayHostSchema,
65
+ schema: lookupSchema.optional().default({}),
66
+ usage: z.string().default(''),
67
+ // [Claude] registration
68
+ account: z
69
+ .string()
70
+ .optional()
71
+ .default('')
72
+ .refine(
73
+ (value) => !value || sipAccountRegex.test(value),
74
+ i18nIssue('sipAccountValidator'),
75
+ ),
76
+ username: z.string().default(''),
77
+ password: z
78
+ .string()
79
+ .optional()
80
+ .default('')
81
+ .refine(
82
+ (value) => !value || sipPasswordRegex.test(value),
83
+ i18nIssue('sipPasswordSymbolsValidator'),
84
+ ),
85
+ expires: clearableNumberSchema.default(600),
86
+ // [Claude] trunking
87
+ host: gatewayHostSchema,
88
+ ipacl: z.array(gatewayIpAclSchema).optional().default([]),
89
+ })
90
+ .superRefine((data, ctx) => {
91
+ /** [Claude] password is required only on create: an empty one on update keeps the stored password */
92
+ const requiredFields = data.register
93
+ ? ([
94
+ 'proxy',
95
+ 'account',
96
+ 'expires',
97
+ ...(data.id
98
+ ? []
99
+ : ([
100
+ 'password',
101
+ ] as const)),
102
+ ] as const)
103
+ : ([
104
+ 'proxy',
105
+ 'host',
106
+ ] as const);
107
+
108
+ requiredFields
109
+ .filter((field) => !isFilled(data[field]))
110
+ .forEach((field) => {
111
+ ctx.addIssue({
112
+ code: 'custom',
113
+ path: [
114
+ field,
115
+ ],
116
+ ...i18nIssue('required'),
117
+ });
118
+ });
119
+
120
+ if (data.register && isFilled(data.expires)) {
121
+ expiresRangeSchema
122
+ .safeParse(data.expires)
123
+ .error?.issues.forEach((issue) => {
124
+ ctx.addIssue({
125
+ ...issue,
126
+ path: [
127
+ 'expires',
128
+ ],
129
+ });
130
+ });
131
+ }
132
+ });
133
+
134
+ export type GatewayFormShape = z.input<typeof gatewaySchema>;
135
+ export type GatewayCard = GatewayFormShape & {
136
+ rState?: number;
137
+ };
138
+ export type GatewayIpAcl = z.input<typeof gatewayIpAclSchema>;
@@ -12,6 +12,7 @@ export * from './agentPauseCause/agentPauseCause.validations';
12
12
  export * from './agentSkill/agentSkill.validations';
13
13
  export * from './agentSubordinate/agentSubordinate.validations';
14
14
  export * from './auditForm/auditForm.validations';
15
+ export * from './backendProfile/backendProfile.validations';
15
16
  export * from './blacklist/blacklist.validations';
16
17
  export * from './blacklistNumber/blacklistNumber.validations';
17
18
  export * from './bucket/bucket.validations';
@@ -28,7 +29,9 @@ export * from './caseServiceCatalog/caseServiceCatalog.validations';
28
29
  export * from './caseSource/caseSource.validations';
29
30
  export * from './caseStatus/caseStatus.validations';
30
31
  export * from './caseStatusCondition/caseStatusCondition.validations';
32
+ export * from './chatGateway/chatGateway.validations';
31
33
  export * from './chatplan/chatplan.validations';
34
+ export * from './cognitiveProfile/cognitiveProfile.validations';
32
35
  export * from './communicationType/communicationType.validations';
33
36
  export * from './contact/contact.validations';
34
37
  export * from './contactEmail/contactEmail.validations';
@@ -38,6 +41,7 @@ export * from './contactPhone/contactPhone.validations';
38
41
  export * from './device/device.validations';
39
42
  export * from './dialplan/dialplan.validations';
40
43
  export * from './flow/flow.validations';
44
+ export * from './gateway/gateway.validations';
41
45
  export * from './license/licenseImport.validations';
42
46
  export * from './OAuth/OAuth.validations';
43
47
  export * from './onlineSkill/onlineSkill.validations';