@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.
- package/package.json +1 -1
- package/src/api/clients/_shared/appUrls.ts +11 -0
- package/src/api/clients/chatGateways/__tests__/chatGatewayChannels.spec.ts +84 -0
- package/src/api/clients/chatGateways/__tests__/chatGateways.spec.ts +115 -0
- package/src/api/clients/chatGateways/chatGatewayChannels.ts +162 -0
- package/src/api/clients/chatGateways/chatGateways.ts +66 -25
- package/src/api/clients/chatGateways/defaults/chatGatewayProviderDefaults.ts +91 -0
- package/src/api/clients/chatGateways/defaults/defaultChatGateway.ts +3 -1
- package/src/api/clients/chatGateways/defaults/webChatGateway.ts +8 -5
- package/src/api/clients/cognitiveProfiles/cognitiveProfiles.ts +8 -32
- package/src/api/clients/cognitiveProfiles/defaults/cognitiveProfileDefaults.ts +39 -0
- package/src/api/clients/emailProfiles/emailProfiles.ts +6 -19
- package/src/api/clients/gateways/__tests__/gateways.spec.ts +138 -0
- package/src/api/clients/gateways/gateways.ts +60 -52
- package/src/api/clients/importTemplates/importTemplates.ts +36 -21
- package/src/api/clients/index.ts +2 -0
- package/src/api/clients/storagePolicies/storagePolicies.ts +24 -36
- package/src/api/clients/triggers/triggerJobs.ts +22 -12
- package/src/api/clients/triggers/triggers.ts +12 -37
- package/src/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.ts +10 -0
- package/src/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.ts +8 -0
- package/src/enums/GatewayRegisterState/GatewayRegisterState.ts +17 -0
- package/src/enums/StorageType/StorageType.ts +10 -0
- package/src/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.ts +15 -0
- package/src/enums/index.ts +10 -0
- package/src/locale/en/en.ts +8 -0
- package/src/locale/es/es.ts +8 -0
- package/src/locale/kz/kz.ts +8 -0
- package/src/locale/pl/pl.ts +8 -0
- package/src/locale/ro/ro.ts +8 -0
- package/src/locale/ru/ru.ts +8 -0
- package/src/locale/uk/uk.ts +8 -0
- package/src/locale/uz/uz.ts +8 -0
- package/src/locale/vi/vi.ts +8 -0
- package/src/scripts/convertDuration/__tests__/convertDurationWithMilliseconds.spec.ts +19 -0
- package/src/scripts/convertDuration/convertDurationWithMilliseconds.ts +18 -0
- package/src/scripts/index.ts +2 -0
- package/src/validations/_shared/ip.validations.ts +10 -0
- package/src/validations/backendProfile/__tests__/backendProfile.validations.spec.ts +104 -0
- package/src/validations/backendProfile/backendProfile.validations.ts +79 -0
- package/src/validations/chatGateway/__tests__/chatGateway.validations.spec.ts +189 -0
- package/src/validations/chatGateway/chatGateway.validations.ts +452 -0
- package/src/validations/cognitiveProfile/__tests__/cognitiveProfile.validations.spec.ts +83 -0
- package/src/validations/cognitiveProfile/cognitiveProfile.validations.ts +74 -0
- package/src/validations/device/device.validations.ts +2 -8
- package/src/validations/emailProfile/__tests__/emailProfile.validations.spec.ts +105 -0
- package/src/validations/emailProfile/emailProfile.validations.ts +113 -0
- package/src/validations/gateway/__tests__/gateway.validations.spec.ts +168 -0
- package/src/validations/gateway/gateway.validations.ts +138 -0
- package/src/validations/importTemplate/__tests__/importTemplate.validations.spec.ts +77 -0
- package/src/validations/importTemplate/importTemplate.validations.ts +56 -0
- package/src/validations/index.ts +8 -0
- package/src/validations/storagePolicy/__tests__/storagePolicy.validations.spec.ts +52 -0
- package/src/validations/storagePolicy/storagePolicy.validations.ts +36 -0
- package/src/validations/trigger/__tests__/trigger.validations.spec.ts +92 -0
- package/src/validations/trigger/trigger.validations.ts +82 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/_shared/appUrls.d.ts +11 -0
- package/types/api/clients/chatGateways/chatGatewayChannels.d.ts +62 -0
- package/types/api/clients/chatGateways/chatGateways.d.ts +4 -4
- package/types/api/clients/chatGateways/defaults/chatGatewayProviderDefaults.d.ts +21 -0
- package/types/api/clients/chatGateways/defaults/defaultChatGateway.d.ts +3 -1
- package/types/api/clients/chatGateways/defaults/webChatGateway.d.ts +5 -4
- package/types/api/clients/cognitiveProfiles/cognitiveProfiles.d.ts +1 -1
- package/types/api/clients/cognitiveProfiles/defaults/cognitiveProfileDefaults.d.ts +13 -0
- package/types/api/clients/importTemplates/importTemplates.d.ts +2 -2
- package/types/api/clients/index.d.ts +2 -0
- package/types/enums/ChatGatewayChannelSetup/ChatGatewayChannelSetup.d.ts +8 -0
- package/types/enums/GatewayIpAclProtocol/GatewayIpAclProtocol.d.ts +6 -0
- package/types/enums/GatewayRegisterState/GatewayRegisterState.d.ts +15 -0
- package/types/enums/StorageType/StorageType.d.ts +9 -0
- package/types/enums/WebchatAlternativeChannel/WebchatAlternativeChannel.d.ts +13 -0
- package/types/enums/index.d.ts +6 -1
- package/types/locale/en/en.d.ts +7 -0
- package/types/locale/es/es.d.ts +7 -0
- package/types/locale/index.d.ts +63 -0
- package/types/locale/kz/kz.d.ts +7 -0
- package/types/locale/pl/pl.d.ts +7 -0
- package/types/locale/ro/ro.d.ts +7 -0
- package/types/locale/ru/ru.d.ts +7 -0
- package/types/locale/uk/uk.d.ts +7 -0
- package/types/locale/uz/uz.d.ts +7 -0
- package/types/locale/vi/vi.d.ts +7 -0
- package/types/scripts/convertDuration/convertDurationWithMilliseconds.d.ts +6 -0
- package/types/scripts/index.d.ts +2 -1
- package/types/validations/_shared/ip.validations.d.ts +4 -0
- package/types/validations/backendProfile/backendProfile.validations.d.ts +24 -0
- package/types/validations/chatGateway/chatGateway.validations.d.ts +165 -0
- package/types/validations/cognitiveProfile/cognitiveProfile.validations.d.ts +28 -0
- package/types/validations/emailProfile/emailProfile.validations.d.ts +36 -0
- package/types/validations/gateway/gateway.validations.d.ts +48 -0
- package/types/validations/importTemplate/importTemplate.validations.d.ts +62 -0
- package/types/validations/index.d.ts +8 -0
- package/types/validations/storagePolicy/storagePolicy.validations.d.ts +26 -0
- package/types/validations/trigger/trigger.validations.d.ts +38 -0
- package/src/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.ts +0 -12
- package/src/api/clients/gateways/defaults/defaultGateway.ts +0 -9
- package/src/api/clients/gateways/defaults/registerGateway.ts +0 -12
- package/src/api/clients/gateways/defaults/trunkingGateway.ts +0 -16
- package/types/api/clients/chatGateways/enums/WebchatAlternativeChannel.enum.d.ts +0 -12
- package/types/api/clients/gateways/defaults/defaultGateway.d.ts +0 -8
- package/types/api/clients/gateways/defaults/registerGateway.d.ts +0 -13
- package/types/api/clients/gateways/defaults/trunkingGateway.d.ts +0 -16
|
@@ -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
|
+
});
|
package/src/validations/index.ts
CHANGED
|
@@ -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';
|
|
@@ -37,7 +40,10 @@ export * from './contactGroupCondition/contactGroupCondition.validations';
|
|
|
37
40
|
export * from './contactPhone/contactPhone.validations';
|
|
38
41
|
export * from './device/device.validations';
|
|
39
42
|
export * from './dialplan/dialplan.validations';
|
|
43
|
+
export * from './emailProfile/emailProfile.validations';
|
|
40
44
|
export * from './flow/flow.validations';
|
|
45
|
+
export * from './gateway/gateway.validations';
|
|
46
|
+
export * from './importTemplate/importTemplate.validations';
|
|
41
47
|
export * from './license/licenseImport.validations';
|
|
42
48
|
export * from './OAuth/OAuth.validations';
|
|
43
49
|
export * from './onlineSkill/onlineSkill.validations';
|
|
@@ -63,11 +69,13 @@ export * from './shiftTemplate/shiftTemplate.validations';
|
|
|
63
69
|
export * from './skill/skill.validations';
|
|
64
70
|
export * from './sla/sla.validations';
|
|
65
71
|
export * from './slaCondition/slaCondition.validations';
|
|
72
|
+
export * from './storagePolicy/storagePolicy.validations';
|
|
66
73
|
export * from './team/team.validations';
|
|
67
74
|
export * from './teamAgent/teamAgent.validations';
|
|
68
75
|
export * from './teamFlow/teamFlow.validations';
|
|
69
76
|
export * from './teamHook/teamHook.validations';
|
|
70
77
|
export * from './textToSpeech/textToSpeech.validations';
|
|
78
|
+
export * from './trigger/trigger.validations';
|
|
71
79
|
export * from './typeExtension/typeExtension.validations';
|
|
72
80
|
export * from './types';
|
|
73
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
|
+
});
|