@webitel/api-services 26.8.29 → 26.8.31
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.
- package/package.json +1 -1
- package/src/api/clients/media/media.ts +1 -1
- package/src/validations/_shared/__tests__/phoneNumber.validations.spec.ts +55 -0
- package/src/validations/_shared/phoneNumber.validations.ts +27 -0
- package/src/validations/index.ts +1 -0
- package/src/validations/queueMember/memberCommunication.validations.ts +20 -5
- package/types/.tsbuildinfo +1 -1
- package/types/validations/_shared/phoneNumber.validations.d.ts +8 -0
- package/types/validations/index.d.ts +1 -0
- package/types/validations/queueMember/memberCommunication.validations.d.ts +28 -0
package/package.json
CHANGED
|
@@ -86,7 +86,7 @@ export const downloadMedia = async (id: ApiId) => {
|
|
|
86
86
|
|
|
87
87
|
export const downloadFile = async (id: ApiId, fileName = '') => {
|
|
88
88
|
const accessToken = localStorage.getItem('access-token'); // after auth token variable is null
|
|
89
|
-
const url =
|
|
89
|
+
const url = `/storage/file/${id}/download?access_token=${accessToken}`;
|
|
90
90
|
|
|
91
91
|
try {
|
|
92
92
|
const response = await instance.get(url, {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { phoneNumberSchema } from '../phoneNumber.validations';
|
|
4
|
+
|
|
5
|
+
const symbolsIssue = expect.objectContaining({
|
|
6
|
+
code: 'custom',
|
|
7
|
+
params: {
|
|
8
|
+
i18nKey: 'phoneNumberSymbolsValidator',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('phoneNumberSchema', () => {
|
|
13
|
+
it.each([
|
|
14
|
+
'380000000000',
|
|
15
|
+
'+380000000000',
|
|
16
|
+
'sip',
|
|
17
|
+
'SIP',
|
|
18
|
+
'user_name',
|
|
19
|
+
'1-800-FLOWERS',
|
|
20
|
+
"a.b!c~d*e'f(g)",
|
|
21
|
+
'+(044)123-45-67',
|
|
22
|
+
])('accepts %j', (value) => {
|
|
23
|
+
expect(phoneNumberSchema.safeParse(value).success).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it.each([
|
|
27
|
+
'+',
|
|
28
|
+
'++380',
|
|
29
|
+
'380+',
|
|
30
|
+
'38+0',
|
|
31
|
+
'380 000',
|
|
32
|
+
' 380',
|
|
33
|
+
'380\n',
|
|
34
|
+
'user@host',
|
|
35
|
+
'#123',
|
|
36
|
+
'1/2',
|
|
37
|
+
'a,b',
|
|
38
|
+
'номер',
|
|
39
|
+
])('rejects %j with the symbols issue', (value) => {
|
|
40
|
+
const result = phoneNumberSchema.safeParse(value);
|
|
41
|
+
|
|
42
|
+
expect(result.success).toBe(false);
|
|
43
|
+
expect(result.error?.issues).toEqual([
|
|
44
|
+
symbolsIssue,
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('reports only required for an empty value', () => {
|
|
49
|
+
const result = phoneNumberSchema.safeParse('');
|
|
50
|
+
|
|
51
|
+
expect(result.success).toBe(false);
|
|
52
|
+
expect(result.error?.issues).toHaveLength(1);
|
|
53
|
+
expect(result.error?.issues[0].code).toBe('too_small');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { i18nIssue } from './i18nIssue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Dialable number charset: latin letters, digits and `+ - _ . ! ~ * ' ( )`;
|
|
7
|
+
* `+` only as a leading sign. Shared by all phone-shaped fields (member
|
|
8
|
+
* destination, resource number, csv imports).
|
|
9
|
+
*
|
|
10
|
+
* [WTEL-9678](https://webitel.atlassian.net/browse/WTEL-9678),
|
|
11
|
+
* [WTEL-10374](https://webitel.atlassian.net/browse/WTEL-10374)
|
|
12
|
+
*/
|
|
13
|
+
const phoneNumberPattern = /^\+?[A-Za-z0-9\-_.!~*'()]+$/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Required phone-shaped value.
|
|
17
|
+
*
|
|
18
|
+
* `refine`, not `regex`: only a `custom` issue passes `params.i18nKey` to the ui.
|
|
19
|
+
* Empty string passes the refinement, so a blank field reports only `required`.
|
|
20
|
+
*/
|
|
21
|
+
export const phoneNumberSchema = z
|
|
22
|
+
.string()
|
|
23
|
+
.min(1)
|
|
24
|
+
.refine(
|
|
25
|
+
(value) => value === '' || phoneNumberPattern.test(value),
|
|
26
|
+
i18nIssue('phoneNumberSymbolsValidator'),
|
|
27
|
+
);
|
package/src/validations/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './_shared/clearableNumber.validations';
|
|
|
2
2
|
export * from './_shared/duration.validations';
|
|
3
3
|
export * from './_shared/i18nIssue';
|
|
4
4
|
export * from './_shared/lookup.validations';
|
|
5
|
+
export * from './_shared/phoneNumber.validations';
|
|
5
6
|
export * from './_shared/variablePair.validations';
|
|
6
7
|
export * from './adjunctType/adjunctType.validations';
|
|
7
8
|
export * from './auditForm/auditForm.validations';
|
|
@@ -4,16 +4,21 @@ import {
|
|
|
4
4
|
filledLookupSchema,
|
|
5
5
|
flexibleLookupSchema,
|
|
6
6
|
} from '../_shared/lookup.validations';
|
|
7
|
+
import { phoneNumberSchema } from '../_shared/phoneNumber.validations';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* NB the character class allows a literal `|` as well as digits and `w`/`W` —
|
|
12
|
-
* `[\d|w|W]` was almost certainly meant to be `[\dwW]`. Preserved as-is:
|
|
13
|
-
* tightening it would start rejecting values that save today.
|
|
10
|
+
* Copied as-is from admin's `digitsDtmfOnly`. NB `[\d|w|W]` also allows `|`
|
|
11
|
+
* (likely meant `[\dwW]`); kept so values that save today stay valid.
|
|
14
12
|
*/
|
|
15
13
|
const dtmfPattern = /^[\d|w|W]*$/;
|
|
16
14
|
|
|
15
|
+
/**
|
|
16
|
+
* One way to reach a queue member.
|
|
17
|
+
*
|
|
18
|
+
* `destination` is only checked for non-empty: its format depends on the
|
|
19
|
+
* channel, which `type` does not carry. For phone channels use
|
|
20
|
+
* `phoneMemberCommunicationSchema`.
|
|
21
|
+
*/
|
|
17
22
|
export const memberCommunicationSchema = z.object({
|
|
18
23
|
destination: z.string().min(1),
|
|
19
24
|
type: filledLookupSchema,
|
|
@@ -23,3 +28,13 @@ export const memberCommunicationSchema = z.object({
|
|
|
23
28
|
resource: flexibleLookupSchema.optional(),
|
|
24
29
|
description: z.string().optional(),
|
|
25
30
|
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Communication for a `Phone` channel: `destination` is dialed, so it must be
|
|
34
|
+
* a valid number. A full schema because regle validates against object schemas.
|
|
35
|
+
*
|
|
36
|
+
* [WTEL-10374](https://webitel.atlassian.net/browse/WTEL-10374)
|
|
37
|
+
*/
|
|
38
|
+
export const phoneMemberCommunicationSchema = memberCommunicationSchema.extend({
|
|
39
|
+
destination: phoneNumberSchema,
|
|
40
|
+
});
|