@webitel/api-services 26.12.21 → 26.12.23

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 (103) 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/emailProfiles/emailProfiles.ts +6 -19
  13. package/src/api/clients/gateways/__tests__/gateways.spec.ts +138 -0
  14. package/src/api/clients/gateways/gateways.ts +60 -52
  15. package/src/api/clients/importTemplates/importTemplates.ts +36 -21
  16. package/src/api/clients/index.ts +2 -0
  17. package/src/api/clients/storagePolicies/storagePolicies.ts +24 -36
  18. package/src/api/clients/triggers/triggerJobs.ts +22 -12
  19. package/src/api/clients/triggers/triggers.ts +12 -37
  20. package/src/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.ts +10 -0
  21. package/src/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.ts +8 -0
  22. package/src/enums/GatewayRegisterState/GatewayRegisterState.ts +17 -0
  23. package/src/enums/StorageType/StorageType.ts +10 -0
  24. package/src/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.ts +15 -0
  25. package/src/enums/index.ts +10 -0
  26. package/src/locale/en/en.ts +8 -0
  27. package/src/locale/es/es.ts +8 -0
  28. package/src/locale/kz/kz.ts +8 -0
  29. package/src/locale/pl/pl.ts +8 -0
  30. package/src/locale/ro/ro.ts +8 -0
  31. package/src/locale/ru/ru.ts +8 -0
  32. package/src/locale/uk/uk.ts +8 -0
  33. package/src/locale/uz/uz.ts +8 -0
  34. package/src/locale/vi/vi.ts +8 -0
  35. package/src/scripts/convertDuration/__tests__/convertDurationWithMilliseconds.spec.ts +19 -0
  36. package/src/scripts/convertDuration/convertDurationWithMilliseconds.ts +18 -0
  37. package/src/scripts/index.ts +2 -0
  38. package/src/validations/_shared/ip.validations.ts +10 -0
  39. package/src/validations/backendProfile/__tests__/backendProfile.validations.spec.ts +104 -0
  40. package/src/validations/backendProfile/backendProfile.validations.ts +79 -0
  41. package/src/validations/chatGateway/__tests__/chatGateway.validations.spec.ts +189 -0
  42. package/src/validations/chatGateway/chatGateway.validations.ts +452 -0
  43. package/src/validations/cognitiveProfile/__tests__/cognitiveProfile.validations.spec.ts +83 -0
  44. package/src/validations/cognitiveProfile/cognitiveProfile.validations.ts +74 -0
  45. package/src/validations/device/device.validations.ts +2 -8
  46. package/src/validations/emailProfile/__tests__/emailProfile.validations.spec.ts +105 -0
  47. package/src/validations/emailProfile/emailProfile.validations.ts +113 -0
  48. package/src/validations/gateway/__tests__/gateway.validations.spec.ts +168 -0
  49. package/src/validations/gateway/gateway.validations.ts +138 -0
  50. package/src/validations/importTemplate/__tests__/importTemplate.validations.spec.ts +77 -0
  51. package/src/validations/importTemplate/importTemplate.validations.ts +56 -0
  52. package/src/validations/index.ts +8 -0
  53. package/src/validations/storagePolicy/__tests__/storagePolicy.validations.spec.ts +52 -0
  54. package/src/validations/storagePolicy/storagePolicy.validations.ts +36 -0
  55. package/src/validations/trigger/__tests__/trigger.validations.spec.ts +92 -0
  56. package/src/validations/trigger/trigger.validations.ts +82 -0
  57. package/types/.tsbuildinfo +1 -1
  58. package/types/api/clients/_shared/appUrls.d.ts +11 -0
  59. package/types/api/clients/chatGateways/chatGatewayChannels.d.ts +62 -0
  60. package/types/api/clients/chatGateways/chatGateways.d.ts +4 -4
  61. package/types/api/clients/chatGateways/defaults/chatGatewayProviderDefaults.d.ts +21 -0
  62. package/types/api/clients/chatGateways/defaults/defaultChatGateway.d.ts +3 -1
  63. package/types/api/clients/chatGateways/defaults/webChatGateway.d.ts +5 -4
  64. package/types/api/clients/cognitiveProfiles/cognitiveProfiles.d.ts +1 -1
  65. package/types/api/clients/cognitiveProfiles/defaults/cognitiveProfileDefaults.d.ts +13 -0
  66. package/types/api/clients/importTemplates/importTemplates.d.ts +2 -2
  67. package/types/api/clients/index.d.ts +2 -0
  68. package/types/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.d.ts +8 -0
  69. package/types/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.d.ts +6 -0
  70. package/types/enums/GatewayRegisterState/GatewayRegisterState.d.ts +15 -0
  71. package/types/enums/StorageType/StorageType.d.ts +9 -0
  72. package/types/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.d.ts +13 -0
  73. package/types/enums/index.d.ts +6 -1
  74. package/types/locale/en/en.d.ts +7 -0
  75. package/types/locale/es/es.d.ts +7 -0
  76. package/types/locale/index.d.ts +63 -0
  77. package/types/locale/kz/kz.d.ts +7 -0
  78. package/types/locale/pl/pl.d.ts +7 -0
  79. package/types/locale/ro/ro.d.ts +7 -0
  80. package/types/locale/ru/ru.d.ts +7 -0
  81. package/types/locale/uk/uk.d.ts +7 -0
  82. package/types/locale/uz/uz.d.ts +7 -0
  83. package/types/locale/vi/vi.d.ts +7 -0
  84. package/types/scripts/convertDuration/convertDurationWithMilliseconds.d.ts +6 -0
  85. package/types/scripts/index.d.ts +2 -1
  86. package/types/validations/_shared/ip.validations.d.ts +4 -0
  87. package/types/validations/backendProfile/backendProfile.validations.d.ts +24 -0
  88. package/types/validations/chatGateway/chatGateway.validations.d.ts +165 -0
  89. package/types/validations/cognitiveProfile/cognitiveProfile.validations.d.ts +28 -0
  90. package/types/validations/emailProfile/emailProfile.validations.d.ts +36 -0
  91. package/types/validations/gateway/gateway.validations.d.ts +48 -0
  92. package/types/validations/importTemplate/importTemplate.validations.d.ts +62 -0
  93. package/types/validations/index.d.ts +8 -0
  94. package/types/validations/storagePolicy/storagePolicy.validations.d.ts +26 -0
  95. package/types/validations/trigger/trigger.validations.d.ts +38 -0
  96. package/src/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.ts +0 -12
  97. package/src/api/clients/gateways/defaults/defaultGateway.ts +0 -9
  98. package/src/api/clients/gateways/defaults/registerGateway.ts +0 -12
  99. package/src/api/clients/gateways/defaults/trunkingGateway.ts +0 -16
  100. package/types/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.d.ts +0 -12
  101. package/types/api/clients/gateways/defaults/defaultGateway.d.ts +0 -8
  102. package/types/api/clients/gateways/defaults/registerGateway.d.ts +0 -13
  103. package/types/api/clients/gateways/defaults/trunkingGateway.d.ts +0 -16
@@ -1,4 +1,5 @@
1
1
  import { getTriggerService } from '../../../gen-wire';
2
+ import { normalizeDatetimeRange } from '../../../scripts';
2
3
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
4
  import {
4
5
  applyTransform,
@@ -9,21 +10,29 @@ import {
9
10
  } from '../../transformers';
10
11
  import type { ApiParams } from '../_shared/types';
11
12
 
13
+ /**
14
+ * [Claude] The params are the trigger logs datalist's filters: `startedAt` is
15
+ * a date range filter (a relative value or `{ from, to }`), `duration` a
16
+ * from-to range and `triggerJobState` the picked run states. The ranges are
17
+ * protobuf nested messages, so they only bind as dotted keys.
18
+ */
12
19
  const getTriggerJobsList = async (params: ApiParams) => {
13
20
  const {
14
21
  parentId,
15
22
  page,
16
23
  size,
17
- q,
24
+ search,
18
25
  sort,
19
26
  fields,
20
- startedAtFrom,
21
- startedAtTo,
22
- durationFrom,
23
- durationTo,
24
- result,
27
+ startedAt,
28
+ duration,
29
+ triggerJobState,
25
30
  } = applyTransform(params, [
26
31
  merge(getDefaultGetParams()),
32
+ ({ startedAt, ...rest }) => ({
33
+ ...rest,
34
+ startedAt: normalizeDatetimeRange(startedAt),
35
+ }),
27
36
  starToSearch('search'),
28
37
  ]);
29
38
 
@@ -33,14 +42,15 @@ const getTriggerJobsList = async (params: ApiParams) => {
33
42
  {
34
43
  page,
35
44
  size,
36
- q,
45
+ // [Claude] the generated param is `q`; `search` is what the datalist store sends
46
+ q: search,
37
47
  sort,
38
48
  fields,
39
- 'started_at.from': startedAtFrom,
40
- 'started_at.to': startedAtTo,
41
- 'duration.from': durationFrom,
42
- 'duration.to': durationTo,
43
- state: result,
49
+ 'started_at.from': startedAt?.from,
50
+ 'started_at.to': startedAt?.to,
51
+ 'duration.from': duration?.from,
52
+ 'duration.to': duration?.to,
53
+ state: triggerJobState,
44
54
  },
45
55
  );
46
56
  const { items, next } = applyTransform(response.data, [
@@ -1,3 +1,5 @@
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { triggerSchema } from '@webitel/api-services/validations';
1
3
  import deepCopy from 'deep-copy';
2
4
  import { getTriggerService } from '../../../gen-wire';
3
5
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
@@ -28,29 +30,13 @@ const doNotConvertKeys = [
28
30
  'variables',
29
31
  ];
30
32
 
31
- const fieldsToSend = [
32
- 'description',
33
- 'enabled',
34
- 'id',
35
- 'name',
36
- 'schema',
37
- 'timeout',
38
- 'timezone',
39
- 'type',
40
- 'variables',
41
- 'expression',
42
- 'event',
43
- 'object',
44
- ];
33
+ /** [Claude] the card schema's fields */
34
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(triggerSchema);
45
35
 
46
- /**
47
- * The form binds `variables` as a `{ key, value }[]`, the API takes a map.
48
- * `type`, `event` and `object` are bound as lookup objects; only the value
49
- * goes over the wire.
50
- */
36
+ /** The form binds `variables` as a `{ key, value }[]`, the API takes a map. */
51
37
  const preRequestHandler = (item: ApiParams) => {
52
38
  const copy = deepCopy(item);
53
- copy.variables = copy.variables.reduce(
39
+ copy.variables = (copy.variables ?? []).reduce(
54
40
  (variables: ApiParams, variable: ApiParams) => {
55
41
  if (!variable.key) return variables;
56
42
  variables[variable.key] = variable.value;
@@ -58,12 +44,7 @@ const preRequestHandler = (item: ApiParams) => {
58
44
  },
59
45
  {},
60
46
  );
61
- return {
62
- ...copy,
63
- type: copy?.type?.value ?? copy?.type,
64
- event: copy?.event?.value ?? copy?.event,
65
- object: copy?.object?.value ?? copy?.object,
66
- };
47
+ return copy;
67
48
  };
68
49
 
69
50
  const getTriggersList = async (params: ApiParams) => {
@@ -117,11 +98,6 @@ const getTriggersList = async (params: ApiParams) => {
117
98
  }
118
99
  };
119
100
 
120
- /**
121
- * Returns `type`, `event` and `object` as raw enum values. Mapping them onto
122
- * localized lookup entries is the caller's job — the labels are app-side i18n
123
- * keys.
124
- */
125
101
  const getTrigger = async ({ itemId: id }: GetItemParams) => {
126
102
  const defaultObject = {
127
103
  timeout: 0,
@@ -130,12 +106,11 @@ const getTrigger = async ({ itemId: id }: GetItemParams) => {
130
106
 
131
107
  const responseHandler = (response: ApiParams) => {
132
108
  const copy = deepCopy(response);
133
- if (response.variables) {
134
- copy.variables = Object.keys(copy.variables).map((key) => ({
135
- key,
136
- value: copy.variables[key],
137
- }));
138
- }
109
+ // [Claude] a trigger without variables gets the default `{}`, which the form needs as `[]` too
110
+ copy.variables = Object.keys(copy.variables ?? {}).map((key) => ({
111
+ key,
112
+ value: copy.variables[key],
113
+ }));
139
114
  return copy;
140
115
  };
141
116
 
@@ -0,0 +1,10 @@
1
+ /** [Claude] the chat service page where a channel is set up, opened in a popup */
2
+ export const ChatGatewayChannelSetup = {
3
+ Facebook: 'pages=setup',
4
+ Instagram: 'instagram=setup',
5
+ Whatsapp: 'whatsapp=setup',
6
+ TelegramApp: 'auth',
7
+ } as const;
8
+
9
+ export type ChatGatewayChannelSetup =
10
+ (typeof ChatGatewayChannelSetup)[keyof typeof ChatGatewayChannelSetup];
@@ -0,0 +1,8 @@
1
+ export const GatewayIpAclProtocol = {
2
+ Any: 'any',
3
+ Udp: 'udp',
4
+ Tcp: 'tcp',
5
+ } as const;
6
+
7
+ export type GatewayIpAclProtocol =
8
+ (typeof GatewayIpAclProtocol)[keyof typeof GatewayIpAclProtocol];
@@ -0,0 +1,17 @@
1
+ /** [Claude] gateway `rState`: FreeSWITCH sofia registration states, in their numeric order */
2
+ export const GatewayRegisterState = {
3
+ Unregistered: 0,
4
+ Trying: 1,
5
+ Register: 2,
6
+ Registered: 3,
7
+ Unregister: 4,
8
+ Failed: 5,
9
+ FailWait: 6,
10
+ Expired: 7,
11
+ NoReg: 8,
12
+ Down: 9,
13
+ Timeout: 10,
14
+ } as const;
15
+
16
+ export type GatewayRegisterState =
17
+ (typeof GatewayRegisterState)[keyof typeof GatewayRegisterState];
@@ -0,0 +1,10 @@
1
+ /** [Claude] the `type` of a file storage backend ("storage" in the admin ui) */
2
+ export const StorageType = {
3
+ Local: 'local',
4
+ S3: 's3',
5
+ Backblaze: 'backblaze',
6
+ Dropbox: 'dropbox',
7
+ Drive: 'drive',
8
+ } as const;
9
+
10
+ export type StorageType = (typeof StorageType)[keyof typeof StorageType];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Difference between MessangerType enum and WebchatAlternativeChannel:
3
+ * MessangerType - backend fields naming, provider
4
+ * WebchatAlternativeChannel - front-end only "simple" channel naming
5
+ */
6
+ export const WebchatAlternativeChannel = {
7
+ Viber: 'viber',
8
+ Whatsapp: 'whatsapp',
9
+ Telegram: 'telegram',
10
+ Messenger: 'messenger',
11
+ Email: 'email',
12
+ } as const;
13
+
14
+ export type WebchatAlternativeChannel =
15
+ (typeof WebchatAlternativeChannel)[keyof typeof WebchatAlternativeChannel];
@@ -2,8 +2,11 @@ import { AgentStatus } from './AgentStatus/AgentStatus';
2
2
  import { CallReportingStatus } from './CallReportingStatus/CallReportingStatus';
3
3
  import { ChannelState } from './ChannelState/ChannelState';
4
4
  import { ChannelType } from './ChannelType/ChannelType';
5
+ import { ChatGatewayChannelSetup } from './ChatGatewayChannelSetup/ChatGatewayChannelSetup';
5
6
  import { ChatGatewayProvider } from './ChatGatewayProvider/ChatGatewayPrivider';
6
7
  import { FormatDateMode } from './FormatDateMode/FormatDateMode';
8
+ import { GatewayIpAclProtocol } from './GatewayIpAclProtocol/GatewayIpAclProtocol';
9
+ import { GatewayRegisterState } from './GatewayRegisterState/GatewayRegisterState';
7
10
  import { MemberStopCause } from './MemberStopCause/MemberStopCause';
8
11
  import { QueuePeriod } from './QueuePeriod/QueuePeriod';
9
12
  import {
@@ -14,6 +17,7 @@ import { QueueType, QueueTypeName } from './QueueType/QueueType';
14
17
  import { RelativeDatetimeValue } from './RelativeDatetimeValue/RelativeDatetimeValue';
15
18
  import { ResourceCidType } from './ResourceCidType/ResourceCidType';
16
19
  import { ResourceIgnoreEarlyMedia } from './ResourceIgnoreEarlyMedia/ResourceIgnoreEarlyMedia';
20
+ import { StorageType } from './StorageType/StorageType';
17
21
  import { TimeBaseScore } from './TimeBaseScore/TimeBaseScore';
18
22
  import { TtsGoogleVoiceList } from './TtsGoogleVoice/TtsGoogleVoice';
19
23
  import { TtsMicrosoftVoice } from './TtsMicrosoftVoice/TtsMicrosoftVoice';
@@ -21,6 +25,7 @@ import { TtsTextType } from './TtsTextType/TtsTextType';
21
25
  import { TypesResourceStrategy } from './TypesResourceStrategy/TypesResourceStrategy';
22
26
  import { UrlProtocol } from './UrlProtocol/UrlProtocol';
23
27
  import { UserPresenceStatus } from './UserPresenceStatus/UserPresenceStatus';
28
+ import { WebchatAlternativeChannel } from './WebchatAlternativeChannel/WebchatAlternativeChannel';
24
29
 
25
30
  export type { TtsGoogleVoice } from './TtsGoogleVoice/TtsGoogleVoice';
26
31
  export {
@@ -28,8 +33,11 @@ export {
28
33
  CallReportingStatus,
29
34
  ChannelState,
30
35
  ChannelType,
36
+ ChatGatewayChannelSetup,
31
37
  ChatGatewayProvider,
32
38
  FormatDateMode,
39
+ GatewayIpAclProtocol,
40
+ GatewayRegisterState,
33
41
  MemberStopCause,
34
42
  QueuePeriod,
35
43
  QueueStrategy,
@@ -39,6 +47,7 @@ export {
39
47
  RelativeDatetimeValue,
40
48
  ResourceCidType,
41
49
  ResourceIgnoreEarlyMedia,
50
+ StorageType,
42
51
  TimeBaseScore,
43
52
  TtsGoogleVoiceList,
44
53
  TtsMicrosoftVoice,
@@ -46,4 +55,5 @@ export {
46
55
  TypesResourceStrategy,
47
56
  UrlProtocol,
48
57
  UserPresenceStatus,
58
+ WebchatAlternativeChannel,
49
59
  };
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Password contains forbidden characters. Reserved URI symbols, whitespace, and special characters like (! * ' ( ) & $) are not allowed.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `File contains invalid numbers. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "La contraseña contiene caracteres no permitidos. No se permiten símbolos reservados de URI, espacios en blanco ni caracteres especiales como (! * ' ( ) & $).",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `El archivo contiene números incorrectos. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Құпия сөзде рұқсат етілмеген таңбалар бар. Резервтелген URI таңбалары, бос орындар және (! * ' ( ) & $) сияқты арнайы таңбаларды пайдалануға болмайды.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Файлда қате нөмірлер бар. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Hasło zawiera niedozwolone znaki. Zarezerwowane symbole URI, spacje oraz znaki specjalne takie jak (! * ' ( ) & $) są niedozwolone.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Plik zawiera nieprawidłowe numery. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Parola conține caractere interzise. Simbolurile URI rezervate, spațiile și caracterele speciale precum (! * ' ( ) & $) nu sunt permise.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Fișierul conține numere incorecte. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Пароль содержит запрещенные символы. Зарезервированные символы URI, пробелы, спецсимволы !*'()&$ не поддерживаются.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Файл содержит некорректные номера. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Пароль містить заборонені символи. Зарезервовані символи URI, пробіли, спецсимволи !*'()&$ не підтримуються.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Файл містить некоректні номери. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Parolda ruxsat etilmagan belgilar mavjud. Rezervlangan URI belgilari, bo'sh joylar va (! * ' ( ) & $) kabi maxsus belgilardan foydalanish mumkin emas.",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Faylda noto'g'ri raqamlar mavjud. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -2,6 +2,14 @@ import type { MessageContext } from 'vue-i18n';
2
2
 
3
3
  export default {
4
4
  backendErrors: {
5
+ sip: {
6
+ gateway: {
7
+ password: {
8
+ invalid:
9
+ "Mật khẩu chứa ký tự không hợp lệ. Không được phép dùng các ký hiệu URI dành riêng, khoảng trắng và ký tự đặc biệt như (! * ' ( ) & $).",
10
+ },
11
+ },
12
+ },
5
13
  ccOutboundResource: {
6
14
  validatePhoneNumber: ({ linked }: MessageContext) =>
7
15
  `Tệp chứa số không hợp lệ. ${linked('validation.phoneNumberSymbolsValidator')}`,
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import convertDurationWithMilliseconds from '../convertDurationWithMilliseconds';
4
+
5
+ describe('convertDurationWithMilliseconds', () => {
6
+ it('formats hours, minutes, seconds and milliseconds', () => {
7
+ expect(convertDurationWithMilliseconds(3_723_456)).toBe('01:02:03.456');
8
+ });
9
+
10
+ it('pads milliseconds to three digits', () => {
11
+ expect(convertDurationWithMilliseconds(1_005)).toBe('00:00:01.005');
12
+ });
13
+
14
+ it('shows zero for a missing or invalid duration', () => {
15
+ expect(convertDurationWithMilliseconds()).toBe('00:00:00.000');
16
+ expect(convertDurationWithMilliseconds(Number.NaN)).toBe('00:00:00.000');
17
+ expect(convertDurationWithMilliseconds(-10)).toBe('00:00:00.000');
18
+ });
19
+ });
@@ -0,0 +1,18 @@
1
+ import convertDuration from './convertDuration';
2
+
3
+ /**
4
+ * [Claude] A duration given in milliseconds, as `HH:MM:SS.mmm`. A missing or
5
+ * invalid one (e.g. a run that has not stopped yet) shows as zero.
6
+ */
7
+ const convertDurationWithMilliseconds = (duration?: number) => {
8
+ const milliseconds = Number.isFinite(duration)
9
+ ? Math.max(0, Math.floor(duration as number))
10
+ : 0;
11
+
12
+ const time = convertDuration(Math.floor(milliseconds / 1000));
13
+ const rest = `${milliseconds % 1000}`.padStart(3, '0');
14
+
15
+ return `${time}.${rest}`;
16
+ };
17
+
18
+ export default convertDurationWithMilliseconds;
@@ -1,4 +1,5 @@
1
1
  import convertDuration from './convertDuration/convertDuration';
2
+ import convertDurationWithMilliseconds from './convertDuration/convertDurationWithMilliseconds';
2
3
  import { minToSec, secToMin } from './convertTimeUnits/convertTimeUnits';
3
4
  import downloadFile from './downloadFile/downloadFile';
4
5
  import { FileFormat } from './downloadFile/types/fileFormat.types';
@@ -16,6 +17,7 @@ export type {
16
17
  } from './normalizeDatetime/normalizeDatetime';
17
18
  export {
18
19
  convertDuration,
20
+ convertDurationWithMilliseconds,
19
21
  downloadFile,
20
22
  FileFormat,
21
23
  isRelativeDatetimeValue,
@@ -0,0 +1,10 @@
1
+ /** [Claude] IPv4 without anchors, so it can be embedded into bigger patterns (e.g. a SIP host) */
2
+ export const ipv4Pattern =
3
+ '(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])';
4
+
5
+ const ipv4Regex = new RegExp(`^${ipv4Pattern}$`);
6
+
7
+ /** [Claude] format rule only: an empty value passes; loopback and 0.0.0.0 are rejected */
8
+ export const isIp = (value?: string) =>
9
+ !value ||
10
+ (value !== '127.0.0.1' && value !== '0.0.0.0' && ipv4Regex.test(value));
@@ -0,0 +1,104 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { backendProfileSchema } from '../backendProfile.validations';
5
+
6
+ const issuePaths = (
7
+ result: ReturnType<typeof backendProfileSchema.safeParse>,
8
+ ) => result.error?.issues.map(({ path }) => path.join('.')) ?? [];
9
+
10
+ const filledS3 = {
11
+ name: 'storage',
12
+ type: 's3',
13
+ properties: {
14
+ keyId: 'key',
15
+ accessKey: 'secret',
16
+ bucketName: 'bucket',
17
+ region: 'eu-central-1',
18
+ endpoint: 'amazonaws.com',
19
+ },
20
+ };
21
+
22
+ describe('backendProfileSchema', () => {
23
+ it('seeds a new storage as an aws s3 bucket', () => {
24
+ expect(getDefaultsFromZodSchema(backendProfileSchema, {})).toMatchObject({
25
+ name: '',
26
+ type: 's3',
27
+ maxSize: 0,
28
+ expireDays: 0,
29
+ priority: 0,
30
+ properties: {
31
+ keyId: '',
32
+ accessKey: '',
33
+ bucketName: '',
34
+ region: '',
35
+ endpoint: 'amazonaws.com',
36
+ pathPattern: '$DOMAIN/$Y/$M/$D',
37
+ },
38
+ });
39
+ });
40
+
41
+ it('requires name and s3 settings for a new storage', () => {
42
+ const paths = issuePaths(
43
+ backendProfileSchema.safeParse(
44
+ getDefaultsFromZodSchema(backendProfileSchema, {}),
45
+ ),
46
+ );
47
+
48
+ expect(paths).toEqual(
49
+ expect.arrayContaining([
50
+ 'name',
51
+ 'properties.keyId',
52
+ 'properties.accessKey',
53
+ 'properties.bucketName',
54
+ 'properties.region',
55
+ ]),
56
+ );
57
+ });
58
+
59
+ it('does not require the access key for an existing storage', () => {
60
+ const paths = issuePaths(
61
+ backendProfileSchema.safeParse({
62
+ ...filledS3,
63
+ id: '1',
64
+ properties: {
65
+ ...filledS3.properties,
66
+ accessKey: '',
67
+ },
68
+ }),
69
+ );
70
+
71
+ expect(paths).not.toContain('properties.accessKey');
72
+ });
73
+
74
+ it('does not require s3 settings for other storage types', () => {
75
+ const result = backendProfileSchema.safeParse({
76
+ id: '1',
77
+ name: 'local',
78
+ type: 'local',
79
+ properties: {
80
+ directory: '/data',
81
+ },
82
+ });
83
+
84
+ expect(result.success).toBe(true);
85
+ });
86
+
87
+ it('rejects negative numbers and reads maxSize given as a string', () => {
88
+ const result = backendProfileSchema.safeParse({
89
+ ...filledS3,
90
+ maxSize: '10',
91
+ expireDays: -1,
92
+ });
93
+
94
+ expect(issuePaths(result)).toEqual([
95
+ 'expireDays',
96
+ ]);
97
+ expect(
98
+ backendProfileSchema.safeParse({
99
+ ...filledS3,
100
+ maxSize: '10',
101
+ }).data?.maxSize,
102
+ ).toBe(10);
103
+ });
104
+ });
@@ -0,0 +1,79 @@
1
+ import type { StorageBackendProfile } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+
4
+ import { StorageType } from '../../enums';
5
+ import { i18nIssue } from '../_shared/i18nIssue';
6
+ import type { ZodShape } from '../types';
7
+
8
+ /** [Claude] number inputs give numbers, the api gives `maxSize` as a string */
9
+ const nonNegativeNumberSchema = z.coerce.number().min(0).default(0);
10
+
11
+ /**
12
+ * [Claude] S3 settings, seeded for a new storage: only S3 can be created.
13
+ * The keys of other storage types pass through untouched.
14
+ */
15
+ const backendProfilePropertiesSchema = z
16
+ .object({
17
+ keyId: z.string().optional().default(''),
18
+ accessKey: z.string().optional().default(''),
19
+ bucketName: z.string().optional().default(''),
20
+ region: z.string().optional().default(''),
21
+ endpoint: z.string().optional().default('amazonaws.com'),
22
+ pathPattern: z.string().optional().default('$DOMAIN/$Y/$M/$D'),
23
+ })
24
+ .passthrough();
25
+
26
+ const requiredS3Properties = [
27
+ 'keyId',
28
+ 'bucketName',
29
+ 'region',
30
+ 'endpoint',
31
+ ] as const;
32
+
33
+ /**
34
+ * [Claude] Storage (backend profile) card schema.
35
+ *
36
+ * Access key is required only when creating (`id` absent): an empty key on
37
+ * update means "keep the current one".
38
+ */
39
+ export const backendProfileSchema = z
40
+ .object<ZodShape<StorageBackendProfile>>({
41
+ id: z.string().optional(),
42
+ name: z.string().min(1).default(''),
43
+ type: z.string().default(StorageType.S3),
44
+ maxSize: nonNegativeNumberSchema,
45
+ expireDays: nonNegativeNumberSchema,
46
+ priority: nonNegativeNumberSchema,
47
+ disabled: z.boolean().optional(),
48
+ // [Claude] `.prefault`, not `.default`: zod 4's `.default({})` would skip the s3 defaults
49
+ properties: backendProfilePropertiesSchema.prefault({}),
50
+ })
51
+ .passthrough()
52
+ .superRefine((profile, ctx) => {
53
+ if (profile.type !== StorageType.S3) return;
54
+
55
+ const properties = profile.properties as z.infer<
56
+ typeof backendProfilePropertiesSchema
57
+ >;
58
+ const required = [
59
+ ...requiredS3Properties,
60
+ ...(profile.id
61
+ ? []
62
+ : [
63
+ 'accessKey' as const,
64
+ ]),
65
+ ];
66
+
67
+ for (const key of required) {
68
+ if (!properties?.[key]) {
69
+ ctx.addIssue({
70
+ code: 'custom',
71
+ path: [
72
+ 'properties',
73
+ key,
74
+ ],
75
+ ...i18nIssue('required'),
76
+ });
77
+ }
78
+ }
79
+ });