@webitel/api-services 0.1.65 → 0.1.66

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,10 +1,14 @@
1
- import { GroupsApiFactory } from 'webitel-sdk';
2
1
  import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
2
+ AddContactsToGroupsBody,
3
+ CreateGroupBody,
4
+ getGroups,
5
+ ListGroupsQueryParams,
6
+ UpdateGroupBody,
7
+ } from '@webitel/api-services/gen';
8
+ import { ContactsGroupType } from '@webitel/api-services/gen/models';
9
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
10
+
11
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
8
12
  import {
9
13
  applyTransform,
10
14
  camelToSnake,
@@ -25,32 +29,19 @@ import type {
25
29
  UpdateItemParams,
26
30
  } from '../_shared/types';
27
31
 
28
- const instance = getDefaultInstance();
29
- const configuration = getDefaultOpenAPIConfig();
30
-
31
- const contactGroupsService = GroupsApiFactory(configuration, '', instance);
32
-
33
32
  const baseUrl = '/contacts/groups';
34
33
 
35
- const fieldsToSend = [
36
- 'name',
37
- 'description',
38
- 'enabled',
39
- 'type',
40
- 'default_group',
41
- ];
34
+ const groupFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateGroupBody);
35
+
36
+ const appendStaticType = (item: ApiParams) => ({
37
+ ...item,
38
+ type: item.type ?? ContactsGroupType.Static,
39
+ });
42
40
 
43
41
  const getContactGroupsList = async (params: ApiParams) => {
44
- const fieldsToSend = [
45
- 'page',
46
- 'size',
47
- 'q',
48
- 'sort',
49
- 'fields',
50
- 'type',
51
- 'enabled',
52
- 'id',
53
- ];
42
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
43
+ ListGroupsQueryParams,
44
+ );
54
45
  const defaultObject = {
55
46
  enabled: false,
56
47
  };
@@ -58,26 +49,22 @@ const getContactGroupsList = async (params: ApiParams) => {
58
49
  const { page, size, fields, sort, id, q, name, type, enabled } =
59
50
  applyTransform(params, [
60
51
  merge(getDefaultGetParams()),
61
- (params) => ({
62
- ...params,
63
- q: params.search,
64
- }),
65
- sanitize(fieldsToSend),
52
+ sanitize(listFieldsToSend),
66
53
  camelToSnake(),
67
54
  ]);
68
55
 
69
56
  try {
70
- const response = await contactGroupsService.listGroups(
57
+ const response = await getGroups().listGroups({
71
58
  page,
72
59
  size,
73
60
  fields,
74
61
  sort,
75
62
  id,
76
- q,
63
+ q: q || params.search,
77
64
  name,
78
65
  type,
79
66
  enabled,
80
- );
67
+ });
81
68
  const { items, next } = applyTransform(response.data, [
82
69
  merge(getDefaultGetListResponse()),
83
70
  ]);
@@ -96,13 +83,10 @@ const getContactGroupsList = async (params: ApiParams) => {
96
83
  };
97
84
 
98
85
  const getContactGroup = async ({ itemId: id }: GetItemParams) => {
99
- const itemResponseHandler = (item: ApiParams) => item.group;
86
+ const itemResponseHandler = (item: { group: unknown }) => item.group;
100
87
 
101
88
  try {
102
- const response = await contactGroupsService.locateGroup(
103
- String(id),
104
- fieldsToSend,
105
- );
89
+ const response = await getGroups().locateGroup(String(id));
106
90
  return applyTransform(response.data, [
107
91
  snakeToCamel(),
108
92
  itemResponseHandler,
@@ -115,14 +99,17 @@ const getContactGroup = async ({ itemId: id }: GetItemParams) => {
115
99
  };
116
100
 
117
101
  const addStaticContactGroup = async ({ itemInstance }: AddItemParams) => {
102
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateGroupBody);
103
+
118
104
  const item = applyTransform(itemInstance, [
119
- camelToSnake(),
120
105
  sanitize(fieldsToSend),
106
+ camelToSnake(),
121
107
  ]);
122
108
  try {
123
- const response = await contactGroupsService.createGroup(item);
109
+ const response = await getGroups().createGroup(item);
124
110
  return applyTransform(response.data, [
125
111
  snakeToCamel(),
112
+ appendStaticType,
126
113
  ]);
127
114
  } catch (err) {
128
115
  throw applyTransform(err, [
@@ -135,14 +122,25 @@ const addContactsToGroups = async ({
135
122
  contactIds,
136
123
  groupIds,
137
124
  }: {
138
- contactIds: string[];
139
- groupIds: string[];
125
+ contactIds: ApiId[];
126
+ groupIds: ApiId[];
140
127
  }) => {
141
- try {
142
- const response = await contactGroupsService.addContactsToGroups({
128
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
129
+ AddContactsToGroupsBody,
130
+ );
131
+
132
+ const item = applyTransform(
133
+ {
143
134
  groupIds,
144
135
  contactIds,
145
- });
136
+ },
137
+ [
138
+ sanitize(fieldsToSend),
139
+ ],
140
+ );
141
+
142
+ try {
143
+ const response = await getGroups().addContactsToGroups(item);
146
144
  return applyTransform(response.data, [
147
145
  snakeToCamel(),
148
146
  ]);
@@ -158,13 +156,12 @@ const removeContactsFromGroup = async ({
158
156
  contactIds,
159
157
  }: {
160
158
  id: ApiId;
161
- contactIds: string[];
159
+ contactIds: ApiId[];
162
160
  }) => {
163
161
  try {
164
- const response = await contactGroupsService.removeContactsFromGroup(
165
- String(id),
166
- contactIds,
167
- );
162
+ const response = await getGroups().removeContactsFromGroup(String(id), {
163
+ contactIds: contactIds.map(String),
164
+ });
168
165
  return applyTransform(response.data, []);
169
166
  } catch (err) {
170
167
  throw applyTransform(err, [
@@ -178,14 +175,15 @@ const updateStaticContactGroup = async ({
178
175
  itemId: id,
179
176
  }: UpdateItemParams) => {
180
177
  const item = applyTransform(itemInstance, [
178
+ sanitize(groupFieldsToSend),
181
179
  camelToSnake(),
182
- sanitize(fieldsToSend),
183
180
  ]);
184
181
 
185
182
  try {
186
- const response = await contactGroupsService.updateGroup(String(id), item);
183
+ const response = await getGroups().updateGroup(String(id), item);
187
184
  return applyTransform(response.data, [
188
185
  snakeToCamel(),
186
+ appendStaticType,
189
187
  ]);
190
188
  } catch (err) {
191
189
  throw applyTransform(err, [
@@ -196,14 +194,15 @@ const updateStaticContactGroup = async ({
196
194
 
197
195
  const patchStaticContactGroup = async ({ id, changes }: PatchItemParams) => {
198
196
  const item = applyTransform(changes, [
197
+ sanitize(groupFieldsToSend),
199
198
  camelToSnake(),
200
- sanitize(fieldsToSend),
201
199
  ]);
202
200
 
203
201
  try {
204
- const response = await contactGroupsService.updateGroup2(String(id), item);
202
+ const response = await getGroups().updateGroup2(String(id), item);
205
203
  return applyTransform(response.data, [
206
204
  snakeToCamel(),
205
+ appendStaticType,
207
206
  ]);
208
207
  } catch (err) {
209
208
  throw applyTransform(err, [
@@ -214,7 +213,7 @@ const patchStaticContactGroup = async ({ id, changes }: PatchItemParams) => {
214
213
 
215
214
  const deleteStaticContactGroup = async ({ id }: DeleteItemParams) => {
216
215
  try {
217
- const response = await contactGroupsService.deleteGroup(String(id));
216
+ const response = await getGroups().deleteGroup(String(id));
218
217
  return applyTransform(response.data, []);
219
218
  } catch (err) {
220
219
  throw applyTransform(err, [
@@ -0,0 +1,179 @@
1
+ import {
2
+ CreateConditionBody,
3
+ getDynamicConditions,
4
+ ListConditionsQueryParams,
5
+ UpdateCondition2Body,
6
+ UpdateConditionBody,
7
+ } from '@webitel/api-services/gen';
8
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
9
+
10
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
11
+ import {
12
+ applyTransform,
13
+ camelToSnake,
14
+ merge,
15
+ notify,
16
+ sanitize,
17
+ snakeToCamel,
18
+ } from '../../transformers';
19
+
20
+ const conditionFieldsToSend =
21
+ getShallowFieldsToSendFromZodSchema(CreateConditionBody);
22
+
23
+ const getConditionsList = async ({
24
+ parentId,
25
+ ...params
26
+ }: {
27
+ parentId: string;
28
+ [key: string]: unknown;
29
+ }) => {
30
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
31
+ ListConditionsQueryParams,
32
+ );
33
+
34
+ const { page, size, fields, sort, id, q } = applyTransform(params, [
35
+ merge(getDefaultGetParams()),
36
+ sanitize(listFieldsToSend),
37
+ camelToSnake(),
38
+ ]);
39
+
40
+ try {
41
+ const response = await getDynamicConditions().listConditions(parentId, {
42
+ page,
43
+ size,
44
+ fields,
45
+ sort,
46
+ id,
47
+ q: q || params.search,
48
+ });
49
+ const { items, next } = applyTransform(response.data, [
50
+ merge(getDefaultGetListResponse()),
51
+ ]);
52
+ return {
53
+ items: applyTransform(items, []),
54
+ next,
55
+ };
56
+ } catch (err) {
57
+ throw applyTransform(err, [
58
+ notify,
59
+ ]);
60
+ }
61
+ };
62
+
63
+ const getCondition = async ({ itemId: id }: { itemId: string }) => {
64
+ const itemResponseHandler = (item: { condition: unknown }) => item.condition;
65
+
66
+ try {
67
+ const response = await getDynamicConditions().locateCondition(id, {
68
+ fields: conditionFieldsToSend,
69
+ });
70
+ return applyTransform(response.data, [
71
+ snakeToCamel(),
72
+ itemResponseHandler,
73
+ ]);
74
+ } catch (err) {
75
+ throw applyTransform(err, [
76
+ notify,
77
+ ]);
78
+ }
79
+ };
80
+
81
+ const addCondition = async ({
82
+ itemInstance,
83
+ parentId,
84
+ }: {
85
+ itemInstance: Record<string, unknown>;
86
+ parentId: string;
87
+ }) => {
88
+ const item = applyTransform(itemInstance, [
89
+ sanitize(conditionFieldsToSend),
90
+ camelToSnake(),
91
+ ]);
92
+
93
+ try {
94
+ const response = await getDynamicConditions().createCondition(
95
+ parentId,
96
+ item,
97
+ );
98
+ return applyTransform(response.data, [
99
+ snakeToCamel(),
100
+ ]);
101
+ } catch (err) {
102
+ throw applyTransform(err, [
103
+ notify,
104
+ ]);
105
+ }
106
+ };
107
+
108
+ const updateCondition = async ({
109
+ itemInstance,
110
+ itemId: id,
111
+ }: {
112
+ itemInstance: Record<string, unknown>;
113
+ itemId: string;
114
+ }) => {
115
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateConditionBody);
116
+
117
+ const item = applyTransform(itemInstance, [
118
+ sanitize(fieldsToSend),
119
+ camelToSnake(),
120
+ ]);
121
+
122
+ try {
123
+ const response = await getDynamicConditions().updateCondition(id, item);
124
+ return applyTransform(response.data, [
125
+ snakeToCamel(),
126
+ ]);
127
+ } catch (err) {
128
+ throw applyTransform(err, [
129
+ notify,
130
+ ]);
131
+ }
132
+ };
133
+
134
+ const patchCondition = async ({
135
+ changes,
136
+ itemId: id,
137
+ }: {
138
+ changes: Record<string, unknown>;
139
+ itemId: string;
140
+ }) => {
141
+ const fieldsToSend =
142
+ getShallowFieldsToSendFromZodSchema(UpdateCondition2Body);
143
+
144
+ const item = applyTransform(changes, [
145
+ sanitize(fieldsToSend),
146
+ camelToSnake(),
147
+ ]);
148
+
149
+ try {
150
+ const response = await getDynamicConditions().updateCondition2(id, item);
151
+ return applyTransform(response.data, [
152
+ snakeToCamel(),
153
+ ]);
154
+ } catch (err) {
155
+ throw applyTransform(err, [
156
+ notify,
157
+ ]);
158
+ }
159
+ };
160
+
161
+ const deleteCondition = async ({ id }: { id: string }) => {
162
+ try {
163
+ const response = await getDynamicConditions().deleteCondition(id);
164
+ return applyTransform(response.data, []);
165
+ } catch (err) {
166
+ throw applyTransform(err, [
167
+ notify,
168
+ ]);
169
+ }
170
+ };
171
+
172
+ export const DynamicConditionsAPI = {
173
+ getList: getConditionsList,
174
+ get: getCondition,
175
+ add: addCondition,
176
+ update: updateCondition,
177
+ patch: patchCondition,
178
+ delete: deleteCondition,
179
+ };
@@ -0,0 +1,191 @@
1
+ import {
2
+ CreateDynamicGroupBody,
3
+ getDynamicGroups,
4
+ ListDynamicGroupsQueryParams,
5
+ UpdateDynamicGroup2Body,
6
+ UpdateDynamicGroupBody,
7
+ } from '@webitel/api-services/gen';
8
+ import { ContactsGroupType } from '@webitel/api-services/gen/models';
9
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
10
+
11
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
12
+ import {
13
+ applyTransform,
14
+ camelToSnake,
15
+ merge,
16
+ notify,
17
+ sanitize,
18
+ snakeToCamel,
19
+ } from '../../transformers';
20
+
21
+ const dynamicGroupFieldsToSend = getShallowFieldsToSendFromZodSchema(
22
+ UpdateDynamicGroupBody,
23
+ );
24
+
25
+ const appendDynamicType = (item: Record<string, unknown>) => ({
26
+ ...item,
27
+ type: item.type ?? ContactsGroupType.Dynamic,
28
+ });
29
+
30
+ const getDynamicGroupsList = async (params: Record<string, unknown>) => {
31
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
32
+ ListDynamicGroupsQueryParams,
33
+ );
34
+
35
+ const { page, size, fields, sort, id, q, name } = applyTransform(params, [
36
+ merge(getDefaultGetParams()),
37
+ sanitize(listFieldsToSend),
38
+ camelToSnake(),
39
+ ]);
40
+
41
+ try {
42
+ const response = await getDynamicGroups().listDynamicGroups({
43
+ page,
44
+ size,
45
+ fields,
46
+ sort,
47
+ id,
48
+ q,
49
+ name,
50
+ });
51
+ const { items, next } = applyTransform(response.data, [
52
+ merge(getDefaultGetListResponse()),
53
+ ]);
54
+ return {
55
+ items: applyTransform(items, []),
56
+ next,
57
+ };
58
+ } catch (err) {
59
+ throw applyTransform(err, [
60
+ notify,
61
+ ]);
62
+ }
63
+ };
64
+
65
+ const getDynamicGroup = async ({ itemId: id }: { itemId: string }) => {
66
+ const itemResponseHandler = (item: { group: unknown }) => item.group;
67
+
68
+ try {
69
+ const response = await getDynamicGroups().locateDynamicGroup(id);
70
+ return applyTransform(response.data, [
71
+ snakeToCamel(),
72
+ itemResponseHandler,
73
+ appendDynamicType,
74
+ ]);
75
+ } catch (err) {
76
+ throw applyTransform(err, [
77
+ notify,
78
+ ]);
79
+ }
80
+ };
81
+
82
+ const addDynamicGroup = async ({
83
+ itemInstance,
84
+ }: {
85
+ itemInstance: Record<string, unknown>;
86
+ }) => {
87
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
88
+ CreateDynamicGroupBody,
89
+ );
90
+
91
+ const item = applyTransform(itemInstance, [
92
+ sanitize(fieldsToSend),
93
+ camelToSnake(),
94
+ ]);
95
+
96
+ try {
97
+ const response = await getDynamicGroups().createDynamicGroup(item);
98
+ return applyTransform(response.data, [
99
+ snakeToCamel(),
100
+ appendDynamicType,
101
+ ]);
102
+ } catch (err) {
103
+ throw applyTransform(err, [
104
+ notify,
105
+ ]);
106
+ }
107
+ };
108
+
109
+ const updateDynamicGroup = async ({
110
+ itemInstance,
111
+ itemId: id,
112
+ }: {
113
+ itemInstance: Record<string, unknown>;
114
+ itemId: string;
115
+ }) => {
116
+ const item = applyTransform(itemInstance, [
117
+ sanitize(dynamicGroupFieldsToSend),
118
+ camelToSnake(),
119
+ ]);
120
+
121
+ try {
122
+ const response = await getDynamicGroups().updateDynamicGroup(id, item);
123
+ return applyTransform(response.data, [
124
+ snakeToCamel(),
125
+ appendDynamicType,
126
+ ]);
127
+ } catch (err) {
128
+ throw applyTransform(err, [
129
+ notify,
130
+ ]);
131
+ }
132
+ };
133
+
134
+ const patchDynamicGroup = async ({
135
+ changes,
136
+ itemId: id,
137
+ }: {
138
+ changes: Record<string, unknown>;
139
+ itemId: string;
140
+ }) => {
141
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
142
+ UpdateDynamicGroup2Body,
143
+ );
144
+
145
+ const item = applyTransform(changes, [
146
+ sanitize(fieldsToSend),
147
+ camelToSnake(),
148
+ ]);
149
+
150
+ try {
151
+ const response = await getDynamicGroups().updateDynamicGroup2(id, item);
152
+ return applyTransform(response.data, [
153
+ snakeToCamel(),
154
+ appendDynamicType,
155
+ ]);
156
+ } catch (err) {
157
+ throw applyTransform(err, [
158
+ notify,
159
+ ]);
160
+ }
161
+ };
162
+
163
+ const deleteDynamicGroup = async ({ id }: { id: string }) => {
164
+ try {
165
+ const response = await getDynamicGroups().deleteDynamicGroup(id);
166
+ return applyTransform(response.data, []);
167
+ } catch (err) {
168
+ throw applyTransform(err, [
169
+ notify,
170
+ ]);
171
+ }
172
+ };
173
+
174
+ const getLookup = (params: Record<string, unknown>) =>
175
+ getDynamicGroupsList({
176
+ ...params,
177
+ fields: params.fields || [
178
+ 'id',
179
+ 'name',
180
+ ],
181
+ });
182
+
183
+ export const DynamicGroupsAPI = {
184
+ getList: getDynamicGroupsList,
185
+ get: getDynamicGroup,
186
+ add: addDynamicGroup,
187
+ update: updateDynamicGroup,
188
+ patch: patchDynamicGroup,
189
+ delete: deleteDynamicGroup,
190
+ getLookup,
191
+ };
@@ -20,6 +20,8 @@ export * from './chatGateways/chatGateways';
20
20
  export * from './communications/communications';
21
21
  export * from './configurations/configurations';
22
22
  export * from './contactGroups/contactGroups';
23
+ export * from './dynamicConditions/dynamicConditions';
24
+ export * from './dynamicGroups/dynamicGroups';
23
25
  export * from './emails/emails';
24
26
  export * from './fileServices/fileServices';
25
27
  export * from './flows/flow';
@@ -0,0 +1,34 @@
1
+ import type { ContactsGroup } from '@webitel/api-services/gen/models';
2
+ import { ContactsGroupType } from '@webitel/api-services/gen/models';
3
+ import { z } from 'zod';
4
+ import {
5
+ lookupSchema,
6
+ requiredLookupSchema,
7
+ } from '../_shared/lookup.validations';
8
+ import type { ZodShape } from '../types';
9
+
10
+ const baseSchema = {
11
+ name: z.string().min(1),
12
+ description: z.string().optional(),
13
+ enabled: z.boolean().optional(),
14
+ type: z.string().optional(),
15
+ };
16
+
17
+ const staticSchema = z.object<ZodShape<ContactsGroup>>({
18
+ ...baseSchema,
19
+ defaultGroup: lookupSchema.optional(),
20
+ });
21
+
22
+ const dynamicSchema = z.object<ZodShape<ContactsGroup>>({
23
+ ...baseSchema,
24
+ defaultGroup: requiredLookupSchema,
25
+ });
26
+
27
+ export const contactGroupSchema = z.discriminatedUnion('type', [
28
+ staticSchema.extend({
29
+ type: z.literal(ContactsGroupType.Static),
30
+ }),
31
+ dynamicSchema.extend({
32
+ type: z.literal(ContactsGroupType.Dynamic),
33
+ }),
34
+ ]);
@@ -0,0 +1,15 @@
1
+ import type { ContactsDynamicCondition } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import {
4
+ lookupSchema,
5
+ requiredLookupSchema,
6
+ } from '../_shared/lookup.validations';
7
+ import type { ZodShape } from '../types';
8
+
9
+ export const contactGroupConditionSchema = z.object<
10
+ ZodShape<ContactsDynamicCondition>
11
+ >({
12
+ expression: z.string().min(1),
13
+ group: requiredLookupSchema,
14
+ assignee: lookupSchema.optional(),
15
+ });
@@ -1,3 +1,4 @@
1
+ export * from './_shared/lookup.validations';
1
2
  export * from './auditForm/auditForm.validations';
2
3
  export * from './bucket/bucket.validations';
3
4
  export * from './calendar/calendar.validations';
@@ -5,6 +6,8 @@ export * from './casePriority/casePriority.validations';
5
6
  export * from './caseSource/caseSource.validations';
6
7
  export * from './caseStatus/caseStatus.validations';
7
8
  export * from './caseStatusCondition/caseStatusCondition.validations';
9
+ export * from './contactGroup/contactGroup.validations';
10
+ export * from './contactGroupCondition/contactGroupCondition.validations';
8
11
  export * from './OAuth/OAuth.validations';
9
12
  export * from './onlineSkill/onlineSkill.validations';
10
13
  export * from './types';