@webitel/api-services 26.12.30 → 26.12.32
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 +5 -1
- package/src/api/clients/_shared/types.ts +4 -5
- package/src/api/clients/fileServices/__tests__/fileServices.spec.ts +31 -0
- package/src/api/clients/fileServices/fileServices.ts +42 -0
- package/src/api/clients/flows/flow.ts +3 -0
- package/src/api/types/ApiModule.ts +43 -0
- package/src/api/types/index.ts +1 -0
- package/src/locale/en/en.ts +7 -0
- package/src/locale/es/es.ts +7 -0
- package/src/locale/kz/kz.ts +7 -0
- package/src/locale/pl/pl.ts +7 -0
- package/src/locale/ro/ro.ts +7 -0
- package/src/locale/ru/ru.ts +7 -0
- package/src/locale/uk/uk.ts +7 -0
- package/src/locale/uz/uz.ts +7 -0
- package/src/locale/vi/vi.ts +7 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/_shared/types.d.ts +3 -5
- package/types/api/clients/fileServices/fileServices.d.ts +6 -0
- package/types/api/types/ApiModule.d.ts +42 -0
- package/types/api/types/index.d.ts +1 -0
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/api-services",
|
|
3
|
-
"version": "26.12.
|
|
3
|
+
"version": "26.12.32",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -133,6 +133,10 @@
|
|
|
133
133
|
"types": "./types/api/axios/index.d.ts",
|
|
134
134
|
"import": "./src/api/axios/index.ts"
|
|
135
135
|
},
|
|
136
|
+
"./api/types": {
|
|
137
|
+
"types": "./types/api/types/index.d.ts",
|
|
138
|
+
"import": "./src/api/types/index.ts"
|
|
139
|
+
},
|
|
136
140
|
"./enums": {
|
|
137
141
|
"types": "./types/enums/index.d.ts",
|
|
138
142
|
"import": "./src/enums/index.ts"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Id } from '../../types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* TODO(types): payloads pass through `applyTransform` before reaching a
|
|
3
5
|
* generated client, so the generated request types don't apply here yet.
|
|
@@ -5,11 +7,8 @@
|
|
|
5
7
|
// biome-ignore lint/suspicious/noExplicitAny: see TODO above
|
|
6
8
|
export type ApiParams = Record<string, any>;
|
|
7
9
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
* ui-sdk and cannot import from it. tsc catches drift where the two meet.
|
|
11
|
-
*/
|
|
12
|
-
export type ApiId = string | number;
|
|
10
|
+
/** [Claude] same as `Id` from `api/types` (the `ApiModule` contract) */
|
|
11
|
+
export type ApiId = Id;
|
|
13
12
|
|
|
14
13
|
export interface GetItemParams {
|
|
15
14
|
itemId: ApiId;
|
|
@@ -149,3 +149,34 @@ describe('FileServicesAPI.getScreenRecordingsByCall', () => {
|
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
|
+
|
|
153
|
+
describe('FileServicesAPI.upload', () => {
|
|
154
|
+
it('posts the files as multipart to the entity upload url with the channel', async () => {
|
|
155
|
+
const file = new File(
|
|
156
|
+
[
|
|
157
|
+
'content',
|
|
158
|
+
],
|
|
159
|
+
'report.pdf',
|
|
160
|
+
{
|
|
161
|
+
type: 'application/pdf',
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
await FileServicesAPI.upload({
|
|
166
|
+
id: 42,
|
|
167
|
+
files: [
|
|
168
|
+
file,
|
|
169
|
+
],
|
|
170
|
+
channel: 'case',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(captured[0].method).toBe('post');
|
|
174
|
+
expect(captured[0].url).toBe('/storage/file/42/upload');
|
|
175
|
+
expect(sentParams()).toEqual({
|
|
176
|
+
channel: 'case',
|
|
177
|
+
});
|
|
178
|
+
const body = captured[0].data as FormData;
|
|
179
|
+
expect(body).toBeInstanceOf(FormData);
|
|
180
|
+
expect(body.get('report.pdf')).toBeInstanceOf(File);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
NormalizeDatetimeValueParam,
|
|
27
27
|
} from '../../../scripts';
|
|
28
28
|
import { normalizeDatetimeRange } from '../../../scripts';
|
|
29
|
+
import { getDefaultAxiosInstance } from '../../axios/genClient';
|
|
29
30
|
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
30
31
|
import {
|
|
31
32
|
applyTransform,
|
|
@@ -341,8 +342,49 @@ const getFilesListByCall = async (
|
|
|
341
342
|
}
|
|
342
343
|
};
|
|
343
344
|
|
|
345
|
+
/**
|
|
346
|
+
* [Claude] Uploads files to an entity's storage (e.g. a case), one multipart request.
|
|
347
|
+
* Hand-written: `/storage/file/{id}/upload` is absent from the OpenAPI spec orval reads.
|
|
348
|
+
* Was `cli.storeFile(id, files, null, channel)` from webitel-sdk, which opened a websocket just for this POST.
|
|
349
|
+
*/
|
|
350
|
+
const uploadFiles = async ({
|
|
351
|
+
id,
|
|
352
|
+
files,
|
|
353
|
+
channel,
|
|
354
|
+
}: {
|
|
355
|
+
id: ApiId;
|
|
356
|
+
files: File[];
|
|
357
|
+
/** [Claude] upload channel as the endpoint expects it, e.g. `case` */
|
|
358
|
+
channel?: string;
|
|
359
|
+
}) => {
|
|
360
|
+
const formData = new FormData();
|
|
361
|
+
for (const file of files) formData.append(file.name, file);
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
const response = await getDefaultAxiosInstance().post(
|
|
365
|
+
`/storage/file/${id}/upload`,
|
|
366
|
+
formData,
|
|
367
|
+
{
|
|
368
|
+
params: channel
|
|
369
|
+
? {
|
|
370
|
+
channel,
|
|
371
|
+
}
|
|
372
|
+
: undefined,
|
|
373
|
+
},
|
|
374
|
+
);
|
|
375
|
+
return applyTransform(response.data, [
|
|
376
|
+
snakeToCamel(),
|
|
377
|
+
]);
|
|
378
|
+
} catch (err) {
|
|
379
|
+
throw applyTransform(err, [
|
|
380
|
+
notify,
|
|
381
|
+
]);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
344
385
|
export const FileServicesAPI = {
|
|
345
386
|
getList: getFilesList,
|
|
387
|
+
upload: uploadFiles,
|
|
346
388
|
delete: deleteFiles,
|
|
347
389
|
getScreenRecordingsByUser,
|
|
348
390
|
deleteScreenRecordingsByUser,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
sanitizeToWire,
|
|
19
19
|
snakeToCamel,
|
|
20
20
|
starToSearch,
|
|
21
|
+
translateError,
|
|
21
22
|
} from '../../transformers';
|
|
22
23
|
import type {
|
|
23
24
|
AddItemParams,
|
|
@@ -146,6 +147,7 @@ const addFlow = async ({ itemInstance }: AddItemParams) => {
|
|
|
146
147
|
return fromResponseItem(response.data);
|
|
147
148
|
} catch (err) {
|
|
148
149
|
throw applyTransform(err, [
|
|
150
|
+
translateError,
|
|
149
151
|
notify,
|
|
150
152
|
]);
|
|
151
153
|
}
|
|
@@ -160,6 +162,7 @@ const updateFlow = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
|
|
|
160
162
|
return fromResponseItem(response.data);
|
|
161
163
|
} catch (err) {
|
|
162
164
|
throw applyTransform(err, [
|
|
165
|
+
translateError,
|
|
163
166
|
notify,
|
|
164
167
|
]);
|
|
165
168
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type Id = number | string;
|
|
2
|
+
|
|
3
|
+
export interface ApiModule<Entity> {
|
|
4
|
+
getList?: (params?: unknown) => Promise<{
|
|
5
|
+
items?: Entity[];
|
|
6
|
+
next?: boolean;
|
|
7
|
+
aggs?: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
getLookup?: (params?: unknown) => Promise<{
|
|
10
|
+
items?: Entity[];
|
|
11
|
+
next?: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
get?: (params: {
|
|
14
|
+
itemId?: Id | null;
|
|
15
|
+
/** preferred over itemId */
|
|
16
|
+
id?: Id | null;
|
|
17
|
+
parentId?: Id | null;
|
|
18
|
+
}) => Promise<Entity>;
|
|
19
|
+
add?: (params: {
|
|
20
|
+
itemInstance?: Entity;
|
|
21
|
+
parentId?: Id | null;
|
|
22
|
+
}) => Promise<Entity>;
|
|
23
|
+
update?: (params: {
|
|
24
|
+
itemId?: Id | null;
|
|
25
|
+
id?: Id;
|
|
26
|
+
itemInstance?: Entity;
|
|
27
|
+
parentId?: Id | null;
|
|
28
|
+
etag?: string;
|
|
29
|
+
}) => Promise<Entity>;
|
|
30
|
+
patch?: (params: {
|
|
31
|
+
id?: Id;
|
|
32
|
+
itemId?: Id | null;
|
|
33
|
+
changes?: Partial<Entity>;
|
|
34
|
+
parentId?: Id | null;
|
|
35
|
+
etag?: string;
|
|
36
|
+
}) => Promise<Entity>;
|
|
37
|
+
delete?: (params: {
|
|
38
|
+
itemId?: Id;
|
|
39
|
+
id?: Id;
|
|
40
|
+
parentId?: Id | null;
|
|
41
|
+
etag?: string;
|
|
42
|
+
}) => Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ApiModule, Id } from './ApiModule';
|
package/src/locale/en/en.ts
CHANGED
package/src/locale/es/es.ts
CHANGED
package/src/locale/kz/kz.ts
CHANGED
package/src/locale/pl/pl.ts
CHANGED
package/src/locale/ro/ro.ts
CHANGED
package/src/locale/ru/ru.ts
CHANGED
package/src/locale/uk/uk.ts
CHANGED
package/src/locale/uz/uz.ts
CHANGED