@webitel/api-services 26.8.57 → 26.8.58
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/enums/UrlProtocol/UrlProtocol.ts +7 -0
- package/src/enums/index.ts +2 -0
- package/src/validations/case/case.validations.ts +35 -1
- package/src/validations/caseLink/__tests__/caseLink.validations.spec.ts +52 -0
- package/src/validations/caseLink/caseLink.validations.ts +24 -0
- package/src/validations/index.ts +1 -0
- package/types/.tsbuildinfo +1 -1
- package/types/enums/UrlProtocol/UrlProtocol.d.ts +6 -0
- package/types/enums/index.d.ts +2 -1
- package/types/validations/case/case.validations.d.ts +3 -2
- package/types/validations/caseLink/caseLink.validations.d.ts +8 -0
- package/types/validations/index.d.ts +1 -0
package/package.json
CHANGED
package/src/enums/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { QueueType, QueueTypeName } from './QueueType/QueueType';
|
|
|
10
10
|
import { RelativeDatetimeValue } from './RelativeDatetimeValue/RelativeDatetimeValue';
|
|
11
11
|
import { TimeBaseScore } from './TimeBaseScore/TimeBaseScore';
|
|
12
12
|
import { TypesResourceStrategy } from './TypesResourceStrategy/TypesResourceStrategy';
|
|
13
|
+
import { UrlProtocol } from './UrlProtocol/UrlProtocol';
|
|
13
14
|
import { UserPresenceStatus } from './UserPresenceStatus/UserPresenceStatus';
|
|
14
15
|
|
|
15
16
|
export {
|
|
@@ -24,5 +25,6 @@ export {
|
|
|
24
25
|
RelativeDatetimeValue,
|
|
25
26
|
TimeBaseScore,
|
|
26
27
|
TypesResourceStrategy,
|
|
28
|
+
UrlProtocol,
|
|
27
29
|
UserPresenceStatus,
|
|
28
30
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { WebitelCasesCase } from '@webitel/api-services/gen/models';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
+
import { i18nIssue } from '../_shared/i18nIssue';
|
|
4
5
|
import { lookupSchema } from '../_shared/lookup.validations';
|
|
5
6
|
|
|
6
7
|
const lookupShape = () => lookupSchema.passthrough().default({});
|
|
@@ -28,6 +29,39 @@ export const caseSchema = z.object({
|
|
|
28
29
|
reporter: lookupShape(),
|
|
29
30
|
service: lookupShape(),
|
|
30
31
|
statusCondition: statusConditionShape(),
|
|
31
|
-
closeReason:
|
|
32
|
+
closeReason: lookupSchema.passthrough().nullish(),
|
|
32
33
|
closeResult: z.string().default(''),
|
|
33
34
|
} satisfies Partial<Record<keyof WebitelCasesCase, z.ZodType>>);
|
|
35
|
+
|
|
36
|
+
export const refineCaseCloseFields = (
|
|
37
|
+
data: Pick<
|
|
38
|
+
z.infer<typeof caseSchema>,
|
|
39
|
+
'statusCondition' | 'closeReason' | 'closeResult'
|
|
40
|
+
>,
|
|
41
|
+
ctx: z.RefinementCtx,
|
|
42
|
+
) => {
|
|
43
|
+
if (!data.statusCondition?.final) return;
|
|
44
|
+
|
|
45
|
+
if (!data.closeReason?.id)
|
|
46
|
+
ctx.addIssue({
|
|
47
|
+
code: 'custom',
|
|
48
|
+
path: data.closeReason
|
|
49
|
+
? [
|
|
50
|
+
'closeReason',
|
|
51
|
+
'id',
|
|
52
|
+
]
|
|
53
|
+
: [
|
|
54
|
+
'closeReason',
|
|
55
|
+
],
|
|
56
|
+
...i18nIssue('required'),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (!data.closeResult)
|
|
60
|
+
ctx.addIssue({
|
|
61
|
+
code: 'custom',
|
|
62
|
+
path: [
|
|
63
|
+
'closeResult',
|
|
64
|
+
],
|
|
65
|
+
...i18nIssue('required'),
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { caseLinkSchema } from '../caseLink.validations';
|
|
4
|
+
|
|
5
|
+
const getIssues = (url: string) =>
|
|
6
|
+
caseLinkSchema.safeParse({
|
|
7
|
+
url,
|
|
8
|
+
}).error?.issues ?? [];
|
|
9
|
+
|
|
10
|
+
describe('caseLinkSchema', () => {
|
|
11
|
+
it.each([
|
|
12
|
+
'https://webitel.com',
|
|
13
|
+
'http://webitel.com/path?query=1',
|
|
14
|
+
'ftp://files.webitel.com',
|
|
15
|
+
])('accepts %s', (url) => {
|
|
16
|
+
expect(getIssues(url)).toEqual([]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('requires a url', () => {
|
|
20
|
+
const issues = getIssues('');
|
|
21
|
+
|
|
22
|
+
expect(issues).toHaveLength(1);
|
|
23
|
+
expect(issues[0].code).toBe('too_small');
|
|
24
|
+
expect(issues[0].path).toEqual([
|
|
25
|
+
'url',
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it.each([
|
|
30
|
+
'webitel',
|
|
31
|
+
'webitel.com',
|
|
32
|
+
'mailto:support@webitel.com',
|
|
33
|
+
'javascript:alert(1)',
|
|
34
|
+
])('rejects %s as not a url', (url) => {
|
|
35
|
+
const issues = getIssues(url);
|
|
36
|
+
|
|
37
|
+
expect(issues).toHaveLength(1);
|
|
38
|
+
expect(issues[0].code).toBe('custom');
|
|
39
|
+
expect(issues[0].params).toEqual({
|
|
40
|
+
i18nKey: 'url',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('keeps the link text optional', () => {
|
|
45
|
+
expect(
|
|
46
|
+
caseLinkSchema.safeParse({
|
|
47
|
+
url: 'https://webitel.com',
|
|
48
|
+
name: 'Webitel',
|
|
49
|
+
}).success,
|
|
50
|
+
).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WebitelCasesInputCaseLink } from '@webitel/api-services/gen/models';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { UrlProtocol } from '../../enums';
|
|
5
|
+
import { i18nIssue } from '../_shared/i18nIssue';
|
|
6
|
+
import type { ZodShape } from '../types';
|
|
7
|
+
|
|
8
|
+
const isValidUrl = (value: string) => {
|
|
9
|
+
try {
|
|
10
|
+
return Object.values<string>(UrlProtocol).includes(new URL(value).protocol);
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const caseLinkSchema = z.object<ZodShape<WebitelCasesInputCaseLink>>({
|
|
17
|
+
url: z
|
|
18
|
+
.string()
|
|
19
|
+
.min(1)
|
|
20
|
+
.refine((value) => !value || isValidUrl(value), i18nIssue('url')),
|
|
21
|
+
name: z.string().optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type CaseLink = z.infer<typeof caseLinkSchema>;
|
package/src/validations/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './caseClose/caseClose.validations';
|
|
|
14
14
|
export * from './caseCloseReason/caseCloseReason.validations';
|
|
15
15
|
export * from './caseCloseReasonGroup/caseCloseReasonGroup.validations';
|
|
16
16
|
export * from './caseExportOptions/caseExportOptions.validations';
|
|
17
|
+
export * from './caseLink/caseLink.validations';
|
|
17
18
|
export * from './casePriority/casePriority.validations';
|
|
18
19
|
export * from './caseService/caseService.validations';
|
|
19
20
|
export * from './caseServiceCatalog/caseServiceCatalog.validations';
|