@webitel/api-services 0.1.66 → 0.1.67
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/slaConditions/slaConditions.ts +50 -66
- package/src/api/clients/slas/slas.ts +30 -43
- package/src/validations/_shared/duration.validations.ts +7 -0
- package/src/validations/index.ts +3 -0
- package/src/validations/sla/sla.validations.ts +49 -0
- package/src/validations/slaCondition/slaCondition.validations.ts +12 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/slaConditions/slaConditions.d.ts +5 -2
- package/types/validations/_shared/duration.validations.d.ts +2 -0
- package/types/validations/index.d.ts +3 -0
- package/types/validations/sla/sla.validations.d.ts +15 -0
- package/types/validations/slaCondition/slaCondition.validations.d.ts +13 -0
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { SLAConditionsApiFactory } from 'webitel-sdk';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
2
|
+
CreateSLAConditionBody,
|
|
3
|
+
getSlaconditions,
|
|
4
|
+
ListSLAConditionsQueryParams,
|
|
5
|
+
UpdateSLAConditionBody,
|
|
6
|
+
} from '@webitel/api-services/gen';
|
|
7
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
8
|
+
|
|
9
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
8
10
|
import {
|
|
9
11
|
applyTransform,
|
|
10
12
|
camelToSnake,
|
|
@@ -13,24 +15,7 @@ import {
|
|
|
13
15
|
sanitize,
|
|
14
16
|
snakeToCamel,
|
|
15
17
|
} from '../../transformers';
|
|
16
|
-
import type { ApiId, ApiParams
|
|
17
|
-
|
|
18
|
-
const instance = getDefaultInstance();
|
|
19
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
20
|
-
|
|
21
|
-
const slaConditionsService = SLAConditionsApiFactory(
|
|
22
|
-
configuration,
|
|
23
|
-
'',
|
|
24
|
-
instance,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const fieldsToSend = [
|
|
28
|
-
'name',
|
|
29
|
-
'priorities',
|
|
30
|
-
'sla_id',
|
|
31
|
-
'reaction_time',
|
|
32
|
-
'resolution_time',
|
|
33
|
-
];
|
|
18
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
34
19
|
|
|
35
20
|
const getConditionsList = async ({
|
|
36
21
|
parentId,
|
|
@@ -38,16 +23,9 @@ const getConditionsList = async ({
|
|
|
38
23
|
}: {
|
|
39
24
|
parentId: ApiId;
|
|
40
25
|
} & ApiParams) => {
|
|
41
|
-
const fieldsToSend =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'q',
|
|
45
|
-
'sort',
|
|
46
|
-
'fields',
|
|
47
|
-
'id',
|
|
48
|
-
'slaConditionId',
|
|
49
|
-
'priorityId',
|
|
50
|
-
];
|
|
26
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
27
|
+
ListSLAConditionsQueryParams,
|
|
28
|
+
);
|
|
51
29
|
|
|
52
30
|
const {
|
|
53
31
|
page,
|
|
@@ -60,25 +38,23 @@ const getConditionsList = async ({
|
|
|
60
38
|
priority_id: priorityId,
|
|
61
39
|
} = applyTransform(rest, [
|
|
62
40
|
merge(getDefaultGetParams()),
|
|
63
|
-
(params) => ({
|
|
64
|
-
...params,
|
|
65
|
-
q: params.search,
|
|
66
|
-
}),
|
|
67
41
|
sanitize(fieldsToSend),
|
|
68
42
|
camelToSnake(),
|
|
69
43
|
]);
|
|
70
44
|
|
|
71
45
|
try {
|
|
72
|
-
const response = await
|
|
46
|
+
const response = await getSlaconditions().listSLAConditions(
|
|
73
47
|
String(parentId),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
48
|
+
{
|
|
49
|
+
page,
|
|
50
|
+
size,
|
|
51
|
+
fields,
|
|
52
|
+
sort,
|
|
53
|
+
id,
|
|
54
|
+
q,
|
|
55
|
+
slaConditionId,
|
|
56
|
+
priorityId,
|
|
57
|
+
},
|
|
82
58
|
);
|
|
83
59
|
const { items, next } = applyTransform(response.data, [
|
|
84
60
|
merge(getDefaultGetListResponse()),
|
|
@@ -103,15 +79,12 @@ const getCondition = async ({
|
|
|
103
79
|
parentId: ApiId;
|
|
104
80
|
itemId: ApiId;
|
|
105
81
|
}) => {
|
|
106
|
-
const itemResponseHandler = (item: ApiParams) =>
|
|
107
|
-
return item.slaCondition;
|
|
108
|
-
};
|
|
82
|
+
const itemResponseHandler = (item: ApiParams) => item.slaCondition;
|
|
109
83
|
|
|
110
84
|
try {
|
|
111
|
-
const response = await
|
|
85
|
+
const response = await getSlaconditions().locateSLACondition(
|
|
112
86
|
String(parentId),
|
|
113
87
|
String(id),
|
|
114
|
-
fieldsToSend,
|
|
115
88
|
);
|
|
116
89
|
return applyTransform(response.data, [
|
|
117
90
|
snakeToCamel(),
|
|
@@ -124,19 +97,25 @@ const getCondition = async ({
|
|
|
124
97
|
}
|
|
125
98
|
};
|
|
126
99
|
|
|
127
|
-
const
|
|
100
|
+
const addCondition = async ({
|
|
128
101
|
itemInstance,
|
|
129
|
-
|
|
130
|
-
}:
|
|
102
|
+
parentId,
|
|
103
|
+
}: {
|
|
104
|
+
itemInstance: ApiParams;
|
|
105
|
+
parentId: ApiId;
|
|
106
|
+
}) => {
|
|
107
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
108
|
+
CreateSLAConditionBody,
|
|
109
|
+
);
|
|
110
|
+
|
|
131
111
|
const item = applyTransform(itemInstance, [
|
|
132
|
-
camelToSnake(),
|
|
133
112
|
sanitize(fieldsToSend),
|
|
113
|
+
camelToSnake(),
|
|
134
114
|
]);
|
|
135
115
|
|
|
136
116
|
try {
|
|
137
|
-
const response = await
|
|
138
|
-
|
|
139
|
-
String(id),
|
|
117
|
+
const response = await getSlaconditions().createSLACondition(
|
|
118
|
+
String(parentId),
|
|
140
119
|
item,
|
|
141
120
|
);
|
|
142
121
|
return applyTransform(response.data, [
|
|
@@ -149,21 +128,26 @@ const updateCondition = async ({
|
|
|
149
128
|
}
|
|
150
129
|
};
|
|
151
130
|
|
|
152
|
-
const
|
|
131
|
+
const updateCondition = async ({
|
|
153
132
|
itemInstance,
|
|
154
|
-
|
|
133
|
+
itemId: id,
|
|
155
134
|
}: {
|
|
156
135
|
itemInstance: ApiParams;
|
|
157
|
-
|
|
136
|
+
itemId: ApiId;
|
|
158
137
|
}) => {
|
|
138
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
139
|
+
UpdateSLAConditionBody,
|
|
140
|
+
);
|
|
141
|
+
|
|
159
142
|
const item = applyTransform(itemInstance, [
|
|
160
|
-
camelToSnake(),
|
|
161
143
|
sanitize(fieldsToSend),
|
|
144
|
+
camelToSnake(),
|
|
162
145
|
]);
|
|
163
146
|
|
|
164
147
|
try {
|
|
165
|
-
const response = await
|
|
166
|
-
String(
|
|
148
|
+
const response = await getSlaconditions().updateSLACondition(
|
|
149
|
+
String(itemInstance.slaId),
|
|
150
|
+
String(id),
|
|
167
151
|
item,
|
|
168
152
|
);
|
|
169
153
|
return applyTransform(response.data, [
|
|
@@ -184,7 +168,7 @@ const deleteCondition = async ({
|
|
|
184
168
|
parentId: ApiId;
|
|
185
169
|
}) => {
|
|
186
170
|
try {
|
|
187
|
-
const response = await
|
|
171
|
+
const response = await getSlaconditions().deleteSLACondition(
|
|
188
172
|
String(parentId),
|
|
189
173
|
String(id),
|
|
190
174
|
);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { SLAsApiFactory } from 'webitel-sdk';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
2
|
+
CreateSLABody,
|
|
3
|
+
getSlas,
|
|
4
|
+
ListSLAsQueryParams,
|
|
5
|
+
UpdateSLABody,
|
|
6
|
+
} from '@webitel/api-services/gen';
|
|
7
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
8
|
+
|
|
9
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
8
10
|
import {
|
|
9
11
|
applyTransform,
|
|
10
12
|
camelToSnake,
|
|
@@ -21,42 +23,24 @@ import type {
|
|
|
21
23
|
UpdateItemParams,
|
|
22
24
|
} from '../_shared/types';
|
|
23
25
|
|
|
24
|
-
const instance = getDefaultInstance();
|
|
25
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
26
|
-
|
|
27
|
-
const slaService = SLAsApiFactory(configuration, '', instance);
|
|
28
|
-
|
|
29
|
-
const fieldsToSend = [
|
|
30
|
-
'name',
|
|
31
|
-
'description',
|
|
32
|
-
'valid_from',
|
|
33
|
-
'valid_to',
|
|
34
|
-
'calendar',
|
|
35
|
-
'reaction_time',
|
|
36
|
-
'resolution_time',
|
|
37
|
-
];
|
|
38
|
-
|
|
39
26
|
const getSlasList = async (params: ApiParams) => {
|
|
40
|
-
const fieldsToSend =
|
|
41
|
-
'page',
|
|
42
|
-
'size',
|
|
43
|
-
'q',
|
|
44
|
-
'sort',
|
|
45
|
-
'fields',
|
|
46
|
-
'id',
|
|
47
|
-
];
|
|
27
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(ListSLAsQueryParams);
|
|
48
28
|
|
|
49
29
|
const { page, size, fields, sort, id, q } = applyTransform(params, [
|
|
50
30
|
merge(getDefaultGetParams()),
|
|
51
|
-
(params) => ({
|
|
52
|
-
...params,
|
|
53
|
-
q: params.search,
|
|
54
|
-
}),
|
|
55
31
|
sanitize(fieldsToSend),
|
|
56
32
|
camelToSnake(),
|
|
57
33
|
]);
|
|
34
|
+
|
|
58
35
|
try {
|
|
59
|
-
const response = await
|
|
36
|
+
const response = await getSlas().listSLAs({
|
|
37
|
+
page,
|
|
38
|
+
size,
|
|
39
|
+
fields,
|
|
40
|
+
sort,
|
|
41
|
+
id,
|
|
42
|
+
q: q || params.search,
|
|
43
|
+
});
|
|
60
44
|
const { items, next } = applyTransform(response.data, [
|
|
61
45
|
merge(getDefaultGetListResponse()),
|
|
62
46
|
]);
|
|
@@ -72,12 +56,10 @@ const getSlasList = async (params: ApiParams) => {
|
|
|
72
56
|
};
|
|
73
57
|
|
|
74
58
|
const getSla = async ({ itemId: id }: GetItemParams) => {
|
|
75
|
-
const itemResponseHandler = (item: ApiParams) =>
|
|
76
|
-
return item.sla;
|
|
77
|
-
};
|
|
59
|
+
const itemResponseHandler = (item: ApiParams) => item.sla;
|
|
78
60
|
|
|
79
61
|
try {
|
|
80
|
-
const response = await
|
|
62
|
+
const response = await getSlas().locateSLA(String(id));
|
|
81
63
|
return applyTransform(response.data, [
|
|
82
64
|
snakeToCamel(),
|
|
83
65
|
itemResponseHandler,
|
|
@@ -90,12 +72,14 @@ const getSla = async ({ itemId: id }: GetItemParams) => {
|
|
|
90
72
|
};
|
|
91
73
|
|
|
92
74
|
const addSla = async ({ itemInstance }: AddItemParams) => {
|
|
75
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateSLABody);
|
|
76
|
+
|
|
93
77
|
const item = applyTransform(itemInstance, [
|
|
94
|
-
camelToSnake(),
|
|
95
78
|
sanitize(fieldsToSend),
|
|
79
|
+
camelToSnake(),
|
|
96
80
|
]);
|
|
97
81
|
try {
|
|
98
|
-
const response = await
|
|
82
|
+
const response = await getSlas().createSLA(item);
|
|
99
83
|
return applyTransform(response.data, [
|
|
100
84
|
snakeToCamel(),
|
|
101
85
|
]);
|
|
@@ -107,12 +91,15 @@ const addSla = async ({ itemInstance }: AddItemParams) => {
|
|
|
107
91
|
};
|
|
108
92
|
|
|
109
93
|
const updateSla = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
|
|
94
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateSLABody);
|
|
95
|
+
|
|
110
96
|
const item = applyTransform(itemInstance, [
|
|
111
|
-
camelToSnake(),
|
|
112
97
|
sanitize(fieldsToSend),
|
|
98
|
+
camelToSnake(),
|
|
113
99
|
]);
|
|
100
|
+
|
|
114
101
|
try {
|
|
115
|
-
const response = await
|
|
102
|
+
const response = await getSlas().updateSLA(String(id), item);
|
|
116
103
|
return applyTransform(response.data, [
|
|
117
104
|
snakeToCamel(),
|
|
118
105
|
]);
|
|
@@ -125,7 +112,7 @@ const updateSla = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
|
|
|
125
112
|
|
|
126
113
|
const deleteSla = async ({ id }: DeleteItemParams) => {
|
|
127
114
|
try {
|
|
128
|
-
const response = await
|
|
115
|
+
const response = await getSlas().deleteSLA(String(id));
|
|
129
116
|
return applyTransform(response.data, []);
|
|
130
117
|
} catch (err) {
|
|
131
118
|
throw applyTransform(err, [
|
package/src/validations/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './_shared/duration.validations';
|
|
1
2
|
export * from './_shared/lookup.validations';
|
|
2
3
|
export * from './auditForm/auditForm.validations';
|
|
3
4
|
export * from './bucket/bucket.validations';
|
|
@@ -10,4 +11,6 @@ export * from './contactGroup/contactGroup.validations';
|
|
|
10
11
|
export * from './contactGroupCondition/contactGroupCondition.validations';
|
|
11
12
|
export * from './OAuth/OAuth.validations';
|
|
12
13
|
export * from './onlineSkill/onlineSkill.validations';
|
|
14
|
+
export * from './sla/sla.validations';
|
|
15
|
+
export * from './slaCondition/slaCondition.validations';
|
|
13
16
|
export * from './types';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { WebitelCasesSLA } from '@webitel/api-services/gen/models';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requiredDurationSchema } from '../_shared/duration.validations';
|
|
4
|
+
import { requiredLookupSchema } from '../_shared/lookup.validations';
|
|
5
|
+
import type { ZodShape } from '../types';
|
|
6
|
+
|
|
7
|
+
const MINUTE_IN_MS = 60000;
|
|
8
|
+
|
|
9
|
+
export const slaSchema = z
|
|
10
|
+
.object<ZodShape<WebitelCasesSLA>>({
|
|
11
|
+
name: z.string().min(1),
|
|
12
|
+
description: z.string().optional(),
|
|
13
|
+
calendar: requiredLookupSchema,
|
|
14
|
+
reactionTime: requiredDurationSchema(),
|
|
15
|
+
resolutionTime: requiredDurationSchema(),
|
|
16
|
+
validFrom: z
|
|
17
|
+
.union([
|
|
18
|
+
z.string(),
|
|
19
|
+
z.number(),
|
|
20
|
+
])
|
|
21
|
+
.nullish(),
|
|
22
|
+
validTo: z
|
|
23
|
+
.union([
|
|
24
|
+
z.string(),
|
|
25
|
+
z.number(),
|
|
26
|
+
])
|
|
27
|
+
.nullish(),
|
|
28
|
+
})
|
|
29
|
+
.superRefine((data, ctx) => {
|
|
30
|
+
if (!data.validFrom || !data.validTo) return;
|
|
31
|
+
|
|
32
|
+
const validFrom = Number(data.validFrom);
|
|
33
|
+
const validTo = Number(data.validTo);
|
|
34
|
+
|
|
35
|
+
if (Number.isNaN(validFrom) || Number.isNaN(validTo)) return;
|
|
36
|
+
|
|
37
|
+
if (validFrom > validTo - MINUTE_IN_MS) {
|
|
38
|
+
ctx.addIssue({
|
|
39
|
+
code: 'too_big',
|
|
40
|
+
origin: 'date',
|
|
41
|
+
maximum: validTo,
|
|
42
|
+
inclusive: false,
|
|
43
|
+
input: data.validFrom,
|
|
44
|
+
path: [
|
|
45
|
+
'validFrom',
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WebitelCasesSLACondition } from '@webitel/api-services/gen/models';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requiredDurationSchema } from '../_shared/duration.validations';
|
|
4
|
+
import { requiredLookupSchema } from '../_shared/lookup.validations';
|
|
5
|
+
import type { ZodShape } from '../types';
|
|
6
|
+
|
|
7
|
+
export const slaConditionSchema = z.object<ZodShape<WebitelCasesSLACondition>>({
|
|
8
|
+
name: z.string().min(1),
|
|
9
|
+
priorities: z.array(requiredLookupSchema).min(1),
|
|
10
|
+
reactionTime: requiredDurationSchema(),
|
|
11
|
+
resolutionTime: requiredDurationSchema(),
|
|
12
|
+
});
|