@webitel/api-services 26.8.11 → 26.8.13

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": "26.8.11",
3
+ "version": "26.8.13",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -214,6 +214,7 @@ const knownSortShape = new Set([
214
214
  'listPhones',
215
215
  'listVariables',
216
216
  'searchData',
217
+ 'searchDevice',
217
218
  'searchOAuthService',
218
219
  'searchType',
219
220
  'searchTypes',
@@ -0,0 +1,45 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ const createLink = vi.fn(() =>
4
+ Promise.resolve({
5
+ data: {},
6
+ }),
7
+ );
8
+
9
+ vi.mock('../../../../gen-wire', async (importOriginal) => ({
10
+ ...(await importOriginal<Record<string, unknown>>()),
11
+ getCaseLinks: () => ({
12
+ createLink,
13
+ }),
14
+ }));
15
+
16
+ const { CreateLinkQueryParams } = await import('../../../../gen-wire');
17
+ const { CaseLinksAPI } = await import('../caseLinks');
18
+
19
+ /**
20
+ * [WTEL-10338](https://webitel.atlassian.net/browse/WTEL-10338)
21
+ *
22
+ * `addLink` derived its field allowlist from `CreateLinkParams` — the schema
23
+ * for this endpoint's path param (`case_etag`) — instead of
24
+ * `CreateLinkQueryParams` (`input.url`, `input.name`, ...). `sanitizeToWire`
25
+ * then dropped every field, so the request always went out with no query
26
+ * params and the backend rejected it with "url is required".
27
+ */
28
+ describe('CaseLinksAPI.add', () => {
29
+ it('sends url and name as query params', async () => {
30
+ await CaseLinksAPI.add({
31
+ parentId: '1354',
32
+ input: {
33
+ url: 'https://example.com',
34
+ name: 'Example link',
35
+ },
36
+ });
37
+
38
+ const [, params] = createLink.mock.calls[0];
39
+ expect(params).toMatchObject({
40
+ 'input.url': 'https://example.com',
41
+ 'input.name': 'Example link',
42
+ });
43
+ expect(CreateLinkQueryParams.strict().safeParse(params).success).toBe(true);
44
+ });
45
+ });
@@ -1,6 +1,6 @@
1
1
  import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
2
  import {
3
- CreateLinkParams,
3
+ CreateLinkQueryParams,
4
4
  getCaseLinks,
5
5
  ListLinksQueryParams,
6
6
  UpdateLink2Body,
@@ -60,8 +60,11 @@ const getLinksList = async ({
60
60
  }
61
61
  };
62
62
 
63
- const createLinkFieldsToSend =
64
- getShallowFieldsToSendFromZodSchema(CreateLinkParams);
63
+ // `CreateLinkParams` (the path-param schema, just `case_etag`) looks like the right
64
+ // name here but isn't: the fields actually sent for this call are the query params.
65
+ const createLinkFieldsToSend = getShallowFieldsToSendFromZodSchema(
66
+ CreateLinkQueryParams,
67
+ );
65
68
 
66
69
  const addLink = async ({
67
70
  parentId,
@@ -221,6 +221,13 @@ const updateCase = async ({ itemInstance }: AddItemParams) => {
221
221
  const response = await casesService.updateCase(etag, item, {
222
222
  fields: caseFieldsToSend,
223
223
  });
224
+
225
+ if (!response.data?.case) {
226
+ return await getCase({
227
+ itemId: String(etag),
228
+ });
229
+ }
230
+
224
231
  return applyTransform(response.data.case, [
225
232
  snakeToCamel([
226
233
  'custom',
@@ -274,6 +281,13 @@ const patchCase = async ({
274
281
  const response = await casesService.updateCase2(String(etag), body, {
275
282
  fields: caseFieldsToSend,
276
283
  });
284
+
285
+ if (!response.data?.case) {
286
+ return await getCase({
287
+ itemId: String(etag),
288
+ });
289
+ }
290
+
277
291
  return applyTransform(response.data.case, [
278
292
  snakeToCamel([
279
293
  'custom',
@@ -165,29 +165,27 @@ const getDevicesLookup = (params: Parameters<typeof getDevicesList>[0]) =>
165
165
  });
166
166
 
167
167
  const getDeviceHistory = async ({ parentId, from, to, ...rest }: ApiParams) => {
168
+ // `SearchDeviceAuditQueryParams` (device audit history) declares neither a
169
+ // text search nor `time_to` — only `time_from`/`time_till`. Sending `search`
170
+ // (or its old `q` alias) and `timeTo` used to pass sanitize()'s allowlist and
171
+ // then get silently dropped by the backend: no error, filters just did nothing.
168
172
  const historyFieldsToSend = [
169
173
  'page',
170
174
  'size',
171
- 'search',
172
175
  'fields',
173
176
  'id',
174
177
  'timeFrom',
175
- 'timeTo',
178
+ 'timeTill',
176
179
  ];
177
180
 
178
181
  const requestParams = applyTransform(
179
182
  {
180
183
  ...rest,
181
184
  timeFrom: from,
182
- timeTo: to,
185
+ timeTill: to,
183
186
  },
184
187
  [
185
188
  merge(getDefaultGetParams()),
186
- starToSearch('search'),
187
- (params) => ({
188
- ...params,
189
- q: params.search,
190
- }),
191
189
  sanitize(historyFieldsToSend),
192
190
  camelToSnake(),
193
191
  ],
@@ -6,6 +6,7 @@ import {
6
6
  applyTransform,
7
7
  camelToSnake,
8
8
  merge,
9
+ mergeEach,
9
10
  notify,
10
11
  sanitizeToWire,
11
12
  snakeToCamel,
@@ -32,6 +33,10 @@ const preRequestHandler = (parentId: ApiId) => (item: ApiParams) => ({
32
33
  queueId: parentId,
33
34
  });
34
35
 
36
+ const defaultBucket = () => ({
37
+ priority: 0,
38
+ });
39
+
35
40
  const getQueueBucketsList = async (params: ApiParams) => {
36
41
  const { page, size, search, sort, fields, id, parentId } = applyTransform(
37
42
  params,
@@ -59,7 +64,9 @@ const getQueueBucketsList = async (params: ApiParams) => {
59
64
  merge(getDefaultGetListResponse()),
60
65
  ]);
61
66
  return {
62
- items,
67
+ items: applyTransform(items, [
68
+ mergeEach(defaultBucket()),
69
+ ]),
63
70
  next,
64
71
  };
65
72
  } catch (err) {
@@ -80,6 +87,7 @@ const getQueueBucket = async ({
80
87
  );
81
88
  return applyTransform(response.data, [
82
89
  snakeToCamel(),
90
+ merge(defaultBucket()),
83
91
  ]);
84
92
  } catch (err) {
85
93
  throw applyTransform(err, [
@@ -104,6 +112,7 @@ const addQueueBucket = async ({
104
112
  );
105
113
  return applyTransform(response.data, [
106
114
  snakeToCamel(),
115
+ merge(defaultBucket()),
107
116
  ]);
108
117
  } catch (err) {
109
118
  throw applyTransform(err, [
@@ -130,6 +139,7 @@ const updateQueueBucket = async ({
130
139
  );
131
140
  return applyTransform(response.data, [
132
141
  snakeToCamel(),
142
+ merge(defaultBucket()),
133
143
  ]);
134
144
  } catch (err) {
135
145
  throw applyTransform(err, [
@@ -155,6 +165,7 @@ const patchQueueBucket = async ({
155
165
  );
156
166
  return applyTransform(response.data, [
157
167
  snakeToCamel(),
168
+ merge(defaultBucket()),
158
169
  ]);
159
170
  } catch (err) {
160
171
  throw applyTransform(err, [