@webitel/api-services 26.12.22 → 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 (27) hide show
  1. package/package.json +1 -1
  2. package/src/api/clients/emailProfiles/emailProfiles.ts +6 -19
  3. package/src/api/clients/importTemplates/importTemplates.ts +36 -21
  4. package/src/api/clients/storagePolicies/storagePolicies.ts +24 -36
  5. package/src/api/clients/triggers/triggerJobs.ts +22 -12
  6. package/src/api/clients/triggers/triggers.ts +12 -37
  7. package/src/scripts/convertDuration/__tests__/convertDurationWithMilliseconds.spec.ts +19 -0
  8. package/src/scripts/convertDuration/convertDurationWithMilliseconds.ts +18 -0
  9. package/src/scripts/index.ts +2 -0
  10. package/src/validations/emailProfile/__tests__/emailProfile.validations.spec.ts +105 -0
  11. package/src/validations/emailProfile/emailProfile.validations.ts +113 -0
  12. package/src/validations/importTemplate/__tests__/importTemplate.validations.spec.ts +77 -0
  13. package/src/validations/importTemplate/importTemplate.validations.ts +56 -0
  14. package/src/validations/index.ts +4 -0
  15. package/src/validations/storagePolicy/__tests__/storagePolicy.validations.spec.ts +52 -0
  16. package/src/validations/storagePolicy/storagePolicy.validations.ts +36 -0
  17. package/src/validations/trigger/__tests__/trigger.validations.spec.ts +92 -0
  18. package/src/validations/trigger/trigger.validations.ts +82 -0
  19. package/types/.tsbuildinfo +1 -1
  20. package/types/api/clients/importTemplates/importTemplates.d.ts +2 -2
  21. package/types/scripts/convertDuration/convertDurationWithMilliseconds.d.ts +6 -0
  22. package/types/scripts/index.d.ts +2 -1
  23. package/types/validations/emailProfile/emailProfile.validations.d.ts +36 -0
  24. package/types/validations/importTemplate/importTemplate.validations.d.ts +62 -0
  25. package/types/validations/index.d.ts +4 -0
  26. package/types/validations/storagePolicy/storagePolicy.validations.d.ts +26 -0
  27. package/types/validations/trigger/trigger.validations.d.ts +38 -0
@@ -0,0 +1,77 @@
1
+ import { StorageImportSourceType } from '@webitel/api-services/gen/models';
2
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import {
6
+ type ImportTemplateCard,
7
+ importTemplateSchema,
8
+ } from '../importTemplate.validations';
9
+
10
+ const issuePaths = (
11
+ result: ReturnType<typeof importTemplateSchema.safeParse>,
12
+ ) => result.error?.issues.map(({ path }) => path.join('.')) ?? [];
13
+
14
+ const defaults = () => getDefaultsFromZodSchema(importTemplateSchema, {});
15
+
16
+ describe('importTemplateSchema', () => {
17
+ it('seeds a new template as a utf-8, comma-separated dialer import', () => {
18
+ expect(defaults()).toMatchObject({
19
+ name: '',
20
+ sourceType: StorageImportSourceType.Dialer,
21
+ parameters: {
22
+ charset: {
23
+ value: 'utf-8',
24
+ },
25
+ separator: ',',
26
+ skipHeaders: true,
27
+ clearMembers: false,
28
+ mappings: {
29
+ name: '',
30
+ destination: [],
31
+ code: [],
32
+ variables: [],
33
+ },
34
+ },
35
+ });
36
+ });
37
+
38
+ it('requires name, source, separator and the name, destination and code columns', () => {
39
+ const template = defaults() as ImportTemplateCard;
40
+ template.parameters.separator = '';
41
+
42
+ expect(issuePaths(importTemplateSchema.safeParse(template))).toEqual(
43
+ expect.arrayContaining([
44
+ 'name',
45
+ 'source.id',
46
+ 'parameters.separator',
47
+ 'parameters.mappings.name',
48
+ 'parameters.mappings.destination',
49
+ 'parameters.mappings.code',
50
+ ]),
51
+ );
52
+ });
53
+
54
+ it('accepts a filled template', () => {
55
+ const result = importTemplateSchema.safeParse({
56
+ ...(defaults() as object),
57
+ name: 'import',
58
+ source: {
59
+ id: 1,
60
+ name: 'queue',
61
+ },
62
+ parameters: {
63
+ mappings: {
64
+ name: 'Name',
65
+ destination: [
66
+ 'Phone',
67
+ ],
68
+ code: [
69
+ 'Type',
70
+ ],
71
+ },
72
+ },
73
+ });
74
+
75
+ expect(result.success).toBe(true);
76
+ });
77
+ });
@@ -0,0 +1,56 @@
1
+ import {
2
+ StorageImportSourceType,
3
+ type StorageImportTemplate,
4
+ } from '@webitel/api-services/gen/models';
5
+ import { z } from 'zod';
6
+
7
+ import { filledLookupSchema } from '../_shared/lookup.validations';
8
+
9
+ /**
10
+ * [Claude] CSV column names for each dialer member field: a single column for
11
+ * a plain field, a list of columns for a multi-value one.
12
+ */
13
+ const importTemplateMappingsSchema = z.object({
14
+ name: z.string().min(1).default(''),
15
+ timezoneId: z.string().optional().default(''),
16
+ priority: z.string().optional().default(''),
17
+ expireAt: z.string().optional().default(''),
18
+ bucketId: z.string().optional().default(''),
19
+ agentId: z.string().optional().default(''),
20
+ variables: z.array(z.string()).default([]),
21
+ destination: z.array(z.string()).min(1).default([]),
22
+ commPriority: z.array(z.string()).default([]),
23
+ code: z.array(z.string()).min(1).default([]),
24
+ description: z.array(z.string()).default([]),
25
+ dtmf: z.array(z.string()).default([]),
26
+ });
27
+
28
+ const importTemplateParametersSchema = z.object({
29
+ charset: z
30
+ .object({
31
+ name: z.string(),
32
+ value: z.string(),
33
+ })
34
+ .default({
35
+ name: 'UTF-8',
36
+ value: 'utf-8',
37
+ }),
38
+ separator: z.string().min(1).default(','),
39
+ skipHeaders: z.boolean().default(true),
40
+ clearMembers: z.boolean().default(false),
41
+ // [Claude] `.prefault`, not `.default`: zod 4's `.default({})` would skip the nested defaults
42
+ mappings: importTemplateMappingsSchema.prefault({}),
43
+ });
44
+
45
+ export type ImportTemplateCard = Omit<StorageImportTemplate, 'parameters'> & {
46
+ parameters?: z.infer<typeof importTemplateParametersSchema>;
47
+ };
48
+
49
+ export const importTemplateSchema = z.object({
50
+ id: z.number().optional(),
51
+ name: z.string().min(1).default(''),
52
+ description: z.string().optional().default(''),
53
+ source: filledLookupSchema.prefault({}),
54
+ sourceType: z.string().default(StorageImportSourceType.Dialer),
55
+ parameters: importTemplateParametersSchema.prefault({}),
56
+ });
@@ -40,8 +40,10 @@ export * from './contactGroupCondition/contactGroupCondition.validations';
40
40
  export * from './contactPhone/contactPhone.validations';
41
41
  export * from './device/device.validations';
42
42
  export * from './dialplan/dialplan.validations';
43
+ export * from './emailProfile/emailProfile.validations';
43
44
  export * from './flow/flow.validations';
44
45
  export * from './gateway/gateway.validations';
46
+ export * from './importTemplate/importTemplate.validations';
45
47
  export * from './license/licenseImport.validations';
46
48
  export * from './OAuth/OAuth.validations';
47
49
  export * from './onlineSkill/onlineSkill.validations';
@@ -67,11 +69,13 @@ export * from './shiftTemplate/shiftTemplate.validations';
67
69
  export * from './skill/skill.validations';
68
70
  export * from './sla/sla.validations';
69
71
  export * from './slaCondition/slaCondition.validations';
72
+ export * from './storagePolicy/storagePolicy.validations';
70
73
  export * from './team/team.validations';
71
74
  export * from './teamAgent/teamAgent.validations';
72
75
  export * from './teamFlow/teamFlow.validations';
73
76
  export * from './teamHook/teamHook.validations';
74
77
  export * from './textToSpeech/textToSpeech.validations';
78
+ export * from './trigger/trigger.validations';
75
79
  export * from './typeExtension/typeExtension.validations';
76
80
  export * from './types';
77
81
  export * from './user/user.validations';
@@ -0,0 +1,52 @@
1
+ import { StorageUploadFileChannel } from '@webitel/api-services/gen/models';
2
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import { storagePolicySchema } from '../storagePolicy.validations';
6
+
7
+ const issuePaths = (result: ReturnType<typeof storagePolicySchema.safeParse>) =>
8
+ result.error?.issues.map(({ path }) => path.join('.')) ?? [];
9
+
10
+ const defaults = () => getDefaultsFromZodSchema(storagePolicySchema, {});
11
+
12
+ describe('storagePolicySchema', () => {
13
+ it('seeds a new policy as enabled and not encrypted', () => {
14
+ expect(defaults()).toMatchObject({
15
+ name: '',
16
+ enabled: true,
17
+ encrypt: false,
18
+ channels: [],
19
+ mimeTypes: [],
20
+ retentionDays: 0,
21
+ speedDownload: 0,
22
+ speedUpload: 0,
23
+ maxUploadSize: 0,
24
+ });
25
+ });
26
+
27
+ it('requires name, channels and mime types', () => {
28
+ expect(issuePaths(storagePolicySchema.safeParse(defaults()))).toEqual([
29
+ 'name',
30
+ 'channels',
31
+ 'mimeTypes',
32
+ ]);
33
+ });
34
+
35
+ it('accepts the int64 strings the api returns for speeds and size', () => {
36
+ const result = storagePolicySchema.safeParse({
37
+ ...defaults(),
38
+ name: 'policy',
39
+ channels: [
40
+ StorageUploadFileChannel.CallChannel,
41
+ ],
42
+ mimeTypes: [
43
+ 'audio/mpeg',
44
+ ],
45
+ speedDownload: '100',
46
+ speedUpload: '200',
47
+ maxUploadSize: '300',
48
+ });
49
+
50
+ expect(result.success).toBe(true);
51
+ });
52
+ });
@@ -0,0 +1,36 @@
1
+ import type { StorageFilePolicy } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+
4
+ import type { ZodShape } from '../types';
5
+
6
+ /** [Claude] the api keeps speeds and the upload size as int64 strings, the form edits them as numbers */
7
+ export type StoragePolicyCard = Omit<
8
+ StorageFilePolicy,
9
+ 'speedDownload' | 'speedUpload' | 'maxUploadSize'
10
+ > & {
11
+ speedDownload?: string | number;
12
+ speedUpload?: string | number;
13
+ maxUploadSize?: string | number;
14
+ };
15
+
16
+ const sizeSchema = z
17
+ .union([
18
+ z.string(),
19
+ z.number(),
20
+ ])
21
+ .optional()
22
+ .default(0);
23
+
24
+ export const storagePolicySchema = z.object<ZodShape<StorageFilePolicy>>({
25
+ id: z.number().optional(),
26
+ name: z.string().min(1).default(''),
27
+ description: z.string().optional().default(''),
28
+ enabled: z.boolean().default(true),
29
+ encrypt: z.boolean().default(false),
30
+ channels: z.array(z.string()).min(1).default([]),
31
+ mimeTypes: z.array(z.string()).min(1).default([]),
32
+ retentionDays: z.number().min(0).optional().default(0),
33
+ speedDownload: sizeSchema,
34
+ speedUpload: sizeSchema,
35
+ maxUploadSize: sizeSchema,
36
+ });
@@ -0,0 +1,92 @@
1
+ import {
2
+ EngineTriggerEventType,
3
+ EngineTriggerObjectType,
4
+ EngineTriggerType,
5
+ } from '@webitel/api-services/gen/models';
6
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
7
+ import { describe, expect, it } from 'vitest';
8
+
9
+ import { triggerSchema } from '../trigger.validations';
10
+
11
+ const issuePaths = (result: ReturnType<typeof triggerSchema.safeParse>) =>
12
+ result.error?.issues.map(({ path }) => path.join('.')) ?? [];
13
+
14
+ const defaults = () => getDefaultsFromZodSchema(triggerSchema, {});
15
+
16
+ const named = {
17
+ name: 'trigger',
18
+ schema: {
19
+ id: '1',
20
+ name: 'flow',
21
+ },
22
+ };
23
+
24
+ describe('triggerSchema', () => {
25
+ it('seeds a new trigger as an hourly cron', () => {
26
+ expect(defaults()).toMatchObject({
27
+ name: '',
28
+ enabled: true,
29
+ type: EngineTriggerType.Cron,
30
+ timeout: 60,
31
+ variables: [],
32
+ expression: '0 */1 12 * * *',
33
+ object: EngineTriggerObjectType.Cases,
34
+ });
35
+ });
36
+
37
+ it('requires name, flow and the timezone of a cron trigger', () => {
38
+ expect(issuePaths(triggerSchema.safeParse(defaults()))).toEqual(
39
+ expect.arrayContaining([
40
+ 'name',
41
+ 'schema.id',
42
+ 'timezone.id',
43
+ ]),
44
+ );
45
+ });
46
+
47
+ it('requires the object and the event of an event trigger, not the cron settings', () => {
48
+ const paths = issuePaths(
49
+ triggerSchema.safeParse({
50
+ ...defaults(),
51
+ ...named,
52
+ type: EngineTriggerType.Event,
53
+ object: '',
54
+ }),
55
+ );
56
+
57
+ expect(paths).toEqual([
58
+ 'object',
59
+ 'event',
60
+ ]);
61
+ });
62
+
63
+ it('accepts a filled event trigger and an emptied timeout', () => {
64
+ const result = triggerSchema.safeParse({
65
+ ...defaults(),
66
+ ...named,
67
+ type: EngineTriggerType.Event,
68
+ event: EngineTriggerEventType.Create,
69
+ timeout: null,
70
+ });
71
+
72
+ expect(result.success).toBe(true);
73
+ });
74
+
75
+ it('rejects a negative timeout', () => {
76
+ expect(
77
+ issuePaths(
78
+ triggerSchema.safeParse({
79
+ ...defaults(),
80
+ ...named,
81
+ timezone: {
82
+ id: 1,
83
+ name: 'UTC',
84
+ },
85
+ timeout: -1,
86
+ }),
87
+ ),
88
+ ).toEqual([
89
+ 'timeout',
90
+ ]);
91
+ });
92
+ });
@@ -0,0 +1,82 @@
1
+ import {
2
+ type EngineTrigger,
3
+ EngineTriggerObjectType,
4
+ EngineTriggerType,
5
+ } from '@webitel/api-services/gen/models';
6
+ import { z } from 'zod';
7
+
8
+ import { i18nIssue } from '../_shared/i18nIssue';
9
+ import { isFilled } from '../_shared/isFilled';
10
+ import {
11
+ filledLookupSchema,
12
+ flexibleLookupSchema,
13
+ } from '../_shared/lookup.validations';
14
+ import {
15
+ type VariablePair,
16
+ variablePairSchema,
17
+ } from '../_shared/variablePair.validations';
18
+
19
+ /** [Claude] the card's trigger: `variables` is the editable pair list, the api takes a map */
20
+ export type TriggerCard = Omit<EngineTrigger, 'variables'> & {
21
+ variables?: VariablePair[];
22
+ };
23
+
24
+ /**
25
+ * [Claude] Trigger card schema.
26
+ *
27
+ * A cron trigger runs on a schedule, so it needs the expression and its
28
+ * timezone; an event trigger runs on an object's event, so it needs both of
29
+ * those. Whether the expression is a valid cron is left to the app, which
30
+ * has the cron parser.
31
+ */
32
+ export const triggerSchema = z
33
+ .object({
34
+ id: z
35
+ .union([
36
+ z.string(),
37
+ z.number(),
38
+ ])
39
+ .optional(),
40
+ name: z.string().min(1).default(''),
41
+ description: z.string().optional().default(''),
42
+ enabled: z.boolean().default(true),
43
+ type: z.string().min(1).default(EngineTriggerType.Cron),
44
+ // [Claude] `.prefault`, not `.default`: zod 4's `.default({})` would skip the required check
45
+ schema: filledLookupSchema.prefault({}),
46
+ // [Claude] an emptied number input gives `null`, which is allowed here
47
+ timeout: z.number().min(0).nullable().optional().default(60),
48
+ variables: z.array(variablePairSchema).default([]),
49
+ expression: z.string().optional().default('0 */1 12 * * *'),
50
+ timezone: flexibleLookupSchema.optional().default({}),
51
+ object: z.string().optional().default(EngineTriggerObjectType.Cases),
52
+ event: z.string().optional().default(''),
53
+ })
54
+ .passthrough()
55
+ .superRefine((trigger, ctx) => {
56
+ const requireField = (path: string, value: unknown) => {
57
+ if (isFilled(value)) return;
58
+ ctx.addIssue({
59
+ code: 'custom',
60
+ // [Claude] an object field gets a nested status in regle, so its issue goes on `id`
61
+ path:
62
+ path === 'timezone'
63
+ ? [
64
+ path,
65
+ 'id',
66
+ ]
67
+ : [
68
+ path,
69
+ ],
70
+ ...i18nIssue('required'),
71
+ });
72
+ };
73
+
74
+ if (trigger.type === EngineTriggerType.Cron) {
75
+ requireField('expression', trigger.expression);
76
+ requireField('timezone', trigger.timezone);
77
+ }
78
+ if (trigger.type === EngineTriggerType.Event) {
79
+ requireField('object', trigger.object);
80
+ requireField('event', trigger.event);
81
+ }
82
+ });