@webitel/api-services 0.1.67 → 0.1.69

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.67",
3
+ "version": "0.1.69",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,10 +1,12 @@
1
- import { CloseReasonGroupsApiFactory } from 'webitel-sdk';
2
1
  import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
2
+ CreateCloseReasonGroupBody,
3
+ getCloseReasonGroups,
4
+ ListCloseReasonGroupsQueryParams,
5
+ UpdateCloseReasonGroupBody,
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,48 +23,26 @@ import type {
21
23
  UpdateItemParams,
22
24
  } from '../_shared/types';
23
25
 
24
- const instance = getDefaultInstance();
25
- const configuration = getDefaultOpenAPIConfig();
26
-
27
- const closeReasonGroupsService = CloseReasonGroupsApiFactory(
28
- configuration,
29
- '',
30
- instance,
31
- );
32
-
33
- const fieldsToSend = [
34
- 'name',
35
- 'description',
36
- ];
37
-
38
26
  const getCloseReasonGroupsList = async (params: ApiParams) => {
39
- const fieldsToSend = [
40
- 'page',
41
- 'size',
42
- 'q',
43
- 'sort',
44
- 'fields',
45
- 'id',
46
- ];
27
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
28
+ ListCloseReasonGroupsQueryParams,
29
+ );
47
30
 
48
31
  const { page, size, fields, sort, id, q } = applyTransform(params, [
49
32
  merge(getDefaultGetParams()),
50
- (params) => ({
51
- ...params,
52
- q: params.search,
53
- }),
54
33
  sanitize(fieldsToSend),
55
34
  camelToSnake(),
56
35
  ]);
36
+
57
37
  try {
58
- const response = await closeReasonGroupsService.listCloseReasonGroups(
38
+ const response = await getCloseReasonGroups().listCloseReasonGroups({
59
39
  page,
60
40
  size,
61
41
  fields,
62
42
  sort,
63
43
  id,
64
- q,
65
- );
44
+ q: q || params.search,
45
+ });
66
46
  const { items, next } = applyTransform(response.data, [
67
47
  merge(getDefaultGetListResponse()),
68
48
  ]);
@@ -77,15 +57,12 @@ const getCloseReasonGroupsList = async (params: ApiParams) => {
77
57
  }
78
58
  };
79
59
 
80
- const getCloseReasonGroups = async ({ itemId: id }: GetItemParams) => {
81
- const itemResponseHandler = (item: ApiParams) => {
82
- return item.closeReasonGroup;
83
- };
60
+ const getCloseReasonGroup = async ({ itemId: id }: GetItemParams) => {
61
+ const itemResponseHandler = (item: ApiParams) => item.closeReasonGroup;
84
62
 
85
63
  try {
86
- const response = await closeReasonGroupsService.locateCloseReasonGroup(
64
+ const response = await getCloseReasonGroups().locateCloseReasonGroup(
87
65
  String(id),
88
- fieldsToSend,
89
66
  );
90
67
  return applyTransform(response.data, [
91
68
  snakeToCamel(),
@@ -98,14 +75,17 @@ const getCloseReasonGroups = async ({ itemId: id }: GetItemParams) => {
98
75
  }
99
76
  };
100
77
 
101
- const addCloseReasonGroups = async ({ itemInstance }: AddItemParams) => {
78
+ const addCloseReasonGroup = async ({ itemInstance }: AddItemParams) => {
79
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
80
+ CreateCloseReasonGroupBody,
81
+ );
82
+
102
83
  const item = applyTransform(itemInstance, [
103
- camelToSnake(),
104
84
  sanitize(fieldsToSend),
85
+ camelToSnake(),
105
86
  ]);
106
87
  try {
107
- const response =
108
- await closeReasonGroupsService.createCloseReasonGroup(item);
88
+ const response = await getCloseReasonGroups().createCloseReasonGroup(item);
109
89
  return applyTransform(response.data, [
110
90
  snakeToCamel(),
111
91
  ]);
@@ -116,16 +96,21 @@ const addCloseReasonGroups = async ({ itemInstance }: AddItemParams) => {
116
96
  }
117
97
  };
118
98
 
119
- const updateCloseReasonGroups = async ({
99
+ const updateCloseReasonGroup = async ({
120
100
  itemInstance,
121
101
  itemId: id,
122
102
  }: UpdateItemParams) => {
103
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
104
+ UpdateCloseReasonGroupBody,
105
+ );
106
+
123
107
  const item = applyTransform(itemInstance, [
124
- camelToSnake(),
125
108
  sanitize(fieldsToSend),
109
+ camelToSnake(),
126
110
  ]);
111
+
127
112
  try {
128
- const response = await closeReasonGroupsService.updateCloseReasonGroup(
113
+ const response = await getCloseReasonGroups().updateCloseReasonGroup(
129
114
  String(id),
130
115
  item,
131
116
  );
@@ -139,9 +124,9 @@ const updateCloseReasonGroups = async ({
139
124
  }
140
125
  };
141
126
 
142
- const deleteCloseReasonGroups = async ({ id }: DeleteItemParams) => {
127
+ const deleteCloseReasonGroup = async ({ id }: DeleteItemParams) => {
143
128
  try {
144
- const response = await closeReasonGroupsService.deleteCloseReasonGroup(
129
+ const response = await getCloseReasonGroups().deleteCloseReasonGroup(
145
130
  String(id),
146
131
  );
147
132
  return applyTransform(response.data, []);
@@ -165,9 +150,9 @@ const getCloseReasonGroupsLookup = async (
165
150
 
166
151
  export const CaseCloseReasonGroupsAPI = {
167
152
  getList: getCloseReasonGroupsList,
168
- get: getCloseReasonGroups,
169
- add: addCloseReasonGroups,
170
- update: updateCloseReasonGroups,
171
- delete: deleteCloseReasonGroups,
153
+ get: getCloseReasonGroup,
154
+ add: addCloseReasonGroup,
155
+ update: updateCloseReasonGroup,
156
+ delete: deleteCloseReasonGroup,
172
157
  getLookup: getCloseReasonGroupsLookup,
173
158
  };
@@ -1,10 +1,12 @@
1
- import { CloseReasonsApiFactory } from 'webitel-sdk';
2
1
  import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
2
+ CreateCloseReasonBody,
3
+ getCloseReasons,
4
+ ListCloseReasonsQueryParams,
5
+ UpdateCloseReasonBody,
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,
@@ -15,49 +17,33 @@ import {
15
17
  } from '../../transformers';
16
18
  import type { ApiId, ApiParams, UpdateItemParams } from '../_shared/types';
17
19
 
18
- const instance = getDefaultInstance();
19
- const configuration = getDefaultOpenAPIConfig();
20
-
21
- const closeReasonsService = CloseReasonsApiFactory(configuration, '', instance);
22
-
23
- const fieldsToSend = [
24
- 'name',
25
- 'description',
26
- ];
27
-
28
20
  const getCloseReasonsList = async ({
29
21
  parentId,
30
22
  ...rest
31
23
  }: {
32
24
  parentId: ApiId;
33
25
  } & ApiParams) => {
34
- const fieldsToSend = [
35
- 'page',
36
- 'size',
37
- 'q',
38
- 'sort',
39
- 'fields',
40
- 'id',
41
- ];
26
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
27
+ ListCloseReasonsQueryParams,
28
+ );
42
29
 
43
30
  const { page, size, fields, sort, id, q } = applyTransform(rest, [
44
31
  merge(getDefaultGetParams()),
45
- (params) => ({
46
- ...params,
47
- q: params.search,
48
- }),
49
32
  sanitize(fieldsToSend),
50
33
  camelToSnake(),
51
34
  ]);
35
+
52
36
  try {
53
- const response = await closeReasonsService.listCloseReasons(
37
+ const response = await getCloseReasons().listCloseReasons(
54
38
  String(parentId),
55
- page,
56
- size,
57
- fields,
58
- sort,
59
- id,
60
- q,
39
+ {
40
+ page,
41
+ size,
42
+ fields,
43
+ sort,
44
+ id,
45
+ q: q || rest.search,
46
+ },
61
47
  );
62
48
  const { items, next } = applyTransform(response.data, [
63
49
  merge(getDefaultGetListResponse()),
@@ -82,12 +68,10 @@ const getCloseReason = async ({
82
68
  parentId: ApiId;
83
69
  itemId: ApiId;
84
70
  }) => {
85
- const itemResponseHandler = (item: ApiParams) => {
86
- return item.closeReason;
87
- };
71
+ const itemResponseHandler = (item: ApiParams) => item.closeReason;
88
72
 
89
73
  try {
90
- const response = await closeReasonsService.locateCloseReason(
74
+ const response = await getCloseReasons().locateCloseReason(
91
75
  String(parentId),
92
76
  String(id),
93
77
  );
@@ -109,13 +93,17 @@ const addCloseReason = async ({
109
93
  itemInstance: ApiParams;
110
94
  parentId: ApiId;
111
95
  }) => {
96
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
97
+ CreateCloseReasonBody,
98
+ );
99
+
112
100
  const item = applyTransform(itemInstance, [
113
- camelToSnake(),
114
101
  sanitize(fieldsToSend),
102
+ camelToSnake(),
115
103
  ]);
116
104
 
117
105
  try {
118
- const response = await closeReasonsService.createCloseReason(
106
+ const response = await getCloseReasons().createCloseReason(
119
107
  String(parentId),
120
108
  item,
121
109
  );
@@ -133,13 +121,18 @@ const updateCloseReason = async ({
133
121
  itemInstance,
134
122
  itemId: id,
135
123
  }: UpdateItemParams) => {
124
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
125
+ UpdateCloseReasonBody,
126
+ );
127
+
136
128
  const item = applyTransform(itemInstance, [
129
+ sanitize(fieldsToSend),
137
130
  camelToSnake(),
138
131
  ]);
139
132
 
140
133
  try {
141
- const response = await closeReasonsService.updateCloseReason(
142
- itemInstance.id,
134
+ const response = await getCloseReasons().updateCloseReason(
135
+ String(itemInstance.closeReasonGroupId),
143
136
  String(id),
144
137
  item,
145
138
  );
@@ -161,7 +154,7 @@ const deleteCloseReason = async ({
161
154
  parentId: ApiId;
162
155
  }) => {
163
156
  try {
164
- const response = await closeReasonsService.deleteCloseReason(
157
+ const response = await getCloseReasons().deleteCloseReason(
165
158
  String(parentId),
166
159
  String(id),
167
160
  );
@@ -1,10 +1,12 @@
1
- import { CatalogsApiFactory } from 'webitel-sdk';
2
1
  import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
2
+ CreateCatalogBody,
3
+ getCatalogs,
4
+ ListCatalogsQueryParams,
5
+ UpdateCatalogBody,
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,
@@ -22,11 +24,6 @@ import type {
22
24
  UpdateItemParams,
23
25
  } from '../_shared/types';
24
26
 
25
- const instance = getDefaultInstance();
26
- const configuration = getDefaultOpenAPIConfig();
27
-
28
- const catalogsService = CatalogsApiFactory(configuration, '', instance);
29
-
30
27
  const fieldsToSend = [
31
28
  'id',
32
29
  'name',
@@ -60,44 +57,38 @@ const servicesFieldsToSend = [
60
57
  ];
61
58
 
62
59
  const getCatalogsList = async (params: ApiParams) => {
63
- const fieldsToSend = [
64
- 'page',
65
- 'size',
66
- 'q',
67
- 'sort',
68
- 'fields',
69
- 'id',
70
- 'state',
71
- 'hasSubservices',
72
- ];
60
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
61
+ ListCatalogsQueryParams,
62
+ );
73
63
 
74
- const { page, size, fields, sort, id, q, state, has_subservices } =
64
+ const { page, size, fields, sort, id, query, state, has_subservices } =
75
65
  applyTransform(params, [
76
66
  merge(getDefaultGetParams()),
77
67
  starToSearch('search'),
78
68
  (params) => ({
79
69
  ...params,
80
- q: params.search,
70
+ query: params.search,
81
71
  }),
82
72
  sanitize(fieldsToSend),
83
73
  camelToSnake(),
84
74
  ]);
75
+
85
76
  try {
86
- const response = await catalogsService.listCatalogs(
77
+ const response = await getCatalogs().listCatalogs({
87
78
  page,
88
79
  size,
89
- [
80
+ fields: [
90
81
  ...fields,
91
82
  'services',
92
83
  ],
93
84
  sort,
94
85
  id,
95
- q,
86
+ query,
96
87
  state,
97
- '100', // Implemented depth 100 for load all subservices in one request
98
- servicesFieldsToSend,
99
- has_subservices,
100
- );
88
+ depth: '100', // Implemented depth 100 for load all subservices in one request
89
+ subFields: servicesFieldsToSend,
90
+ hasSubservices: has_subservices,
91
+ });
101
92
  const { items, next } = applyTransform(response.data, [
102
93
  merge(getDefaultGetListResponse()),
103
94
  ]);
@@ -115,16 +106,13 @@ const getCatalogsList = async (params: ApiParams) => {
115
106
  };
116
107
 
117
108
  const getCatalog = async ({ itemId: id }: GetItemParams) => {
118
- const itemResponseHandler = (item: ApiParams) => {
119
- return item.catalog;
120
- };
109
+ const itemResponseHandler = (item: ApiParams) => item.catalog;
121
110
 
122
111
  try {
123
- const response = await catalogsService.locateCatalog(
124
- String(id),
125
- fieldsToSend,
126
- servicesFieldsToSend,
127
- );
112
+ const response = await getCatalogs().locateCatalog(String(id), {
113
+ fields: fieldsToSend,
114
+ subFields: servicesFieldsToSend,
115
+ });
128
116
  return applyTransform(response.data, [
129
117
  snakeToCamel(),
130
118
  itemResponseHandler,
@@ -137,25 +125,14 @@ const getCatalog = async ({ itemId: id }: GetItemParams) => {
137
125
  };
138
126
 
139
127
  const addCatalog = async ({ itemInstance }: AddItemParams) => {
140
- const fieldsToSend = [
141
- 'name',
142
- 'description',
143
- 'prefix',
144
- 'code',
145
- 'state',
146
- 'sla',
147
- 'status',
148
- 'close_reason_group',
149
- 'default_priority',
150
- 'teams',
151
- 'skills',
152
- ];
128
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateCatalogBody);
129
+
153
130
  const item = applyTransform(itemInstance, [
154
- camelToSnake(),
155
131
  sanitize(fieldsToSend),
132
+ camelToSnake(),
156
133
  ]);
157
134
  try {
158
- const response = await catalogsService.createCatalog(item);
135
+ const response = await getCatalogs().createCatalog(item);
159
136
  return applyTransform(response.data, [
160
137
  snakeToCamel(),
161
138
  ]);
@@ -170,25 +147,14 @@ const updateCatalog = async ({
170
147
  itemInstance,
171
148
  itemId: id,
172
149
  }: UpdateItemParams) => {
173
- const fieldsToSend = [
174
- 'name',
175
- 'description',
176
- 'prefix',
177
- 'code',
178
- 'state',
179
- 'sla',
180
- 'status',
181
- 'close_reason_group',
182
- 'default_priority',
183
- 'teams',
184
- 'skills',
185
- ];
150
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateCatalogBody);
151
+
186
152
  const item = applyTransform(itemInstance, [
187
- camelToSnake(),
188
153
  sanitize(fieldsToSend),
154
+ camelToSnake(),
189
155
  ]);
190
156
  try {
191
- const response = await catalogsService.updateCatalog(String(id), item);
157
+ const response = await getCatalogs().updateCatalog(String(id), item);
192
158
  return applyTransform(response.data, [
193
159
  snakeToCamel(),
194
160
  ]);
@@ -206,11 +172,11 @@ const patchCatalog = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
206
172
  'state',
207
173
  ];
208
174
  const item = applyTransform(itemInstance, [
209
- camelToSnake(),
210
175
  sanitize(fieldsToSend),
176
+ camelToSnake(),
211
177
  ]);
212
178
  try {
213
- const response = await catalogsService.updateCatalog2(String(id), item);
179
+ const response = await getCatalogs().updateCatalog2(String(id), item);
214
180
  return applyTransform(response.data, [
215
181
  snakeToCamel(),
216
182
  ]);
@@ -223,7 +189,7 @@ const patchCatalog = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
223
189
 
224
190
  const deleteCatalog = async ({ id }: DeleteItemParams) => {
225
191
  try {
226
- const response = await catalogsService.deleteCatalog([
192
+ const response = await getCatalogs().deleteCatalog([
227
193
  String(id),
228
194
  ]);
229
195
  return applyTransform(response.data, []);