@webitel/api-services 26.12.32 → 26.12.34
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/blacklists/blacklistNumbers.ts +5 -1
- package/src/api/clients/devices/devices.ts +9 -2
- package/src/api/clients/media/media.ts +15 -2
- package/src/api/clients/outboundResources/resourceDisplays.ts +5 -1
- package/src/api/clients/queues/queueMembers.ts +13 -1
- package/src/api/clients/users/users.ts +9 -2
- package/src/api/transformers/index.ts +2 -1
- package/src/api/transformers/notify/__tests__/notify.spec.ts +65 -0
- package/src/api/transformers/notify/__tests__/notifyServerError.spec.ts +43 -0
- package/src/api/transformers/notify/notify.transformer.ts +33 -2
- package/src/locale/en/en.ts +4 -0
- package/src/locale/es/es.ts +4 -0
- package/src/locale/kz/kz.ts +4 -0
- package/src/locale/pl/pl.ts +4 -0
- package/src/locale/ro/ro.ts +4 -0
- package/src/locale/ru/ru.ts +4 -0
- package/src/locale/uk/uk.ts +4 -0
- package/src/locale/uz/uz.ts +4 -0
- package/src/locale/vi/vi.ts +4 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/blacklists/blacklistNumbers.d.ts +2 -1
- package/types/api/clients/devices/devices.d.ts +3 -1
- package/types/api/clients/media/media.d.ts +4 -1
- package/types/api/clients/outboundResources/resourceDisplays.d.ts +2 -1
- package/types/api/clients/queues/queueMembers.d.ts +3 -1
- package/types/api/clients/users/users.d.ts +3 -1
- package/types/api/transformers/index.d.ts +2 -2
- package/types/api/transformers/notify/notify.transformer.d.ts +5 -0
- package/types/gen-wire/trigger-service/trigger-service.zod.d.ts +9 -9
- package/types/locale/en/en.d.ts +3 -0
- package/types/locale/es/es.d.ts +3 -0
- package/types/locale/index.d.ts +27 -0
- package/types/locale/kz/kz.d.ts +3 -0
- package/types/locale/pl/pl.d.ts +3 -0
- package/types/locale/ro/ro.d.ts +3 -0
- package/types/locale/ru/ru.d.ts +3 -0
- package/types/locale/uk/uk.d.ts +3 -0
- package/types/locale/uz/uz.d.ts +3 -0
- package/types/locale/vi/vi.d.ts +3 -0
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
camelToSnake,
|
|
6
6
|
merge,
|
|
7
7
|
notify,
|
|
8
|
+
notifyServerError,
|
|
8
9
|
sanitize,
|
|
9
10
|
snakeToCamel,
|
|
10
11
|
starToSearch,
|
|
@@ -125,9 +126,12 @@ const addBlacklistNumber = async ({
|
|
|
125
126
|
const addBlacklistNumberBulk = async ({
|
|
126
127
|
parentId,
|
|
127
128
|
items,
|
|
129
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
130
|
+
notifyNetworkError = true,
|
|
128
131
|
}: {
|
|
129
132
|
parentId: ApiId;
|
|
130
133
|
items: ApiParams[];
|
|
134
|
+
notifyNetworkError?: boolean;
|
|
131
135
|
}) => {
|
|
132
136
|
const body = {
|
|
133
137
|
items: items.map((item) =>
|
|
@@ -147,7 +151,7 @@ const addBlacklistNumberBulk = async ({
|
|
|
147
151
|
]);
|
|
148
152
|
} catch (err) {
|
|
149
153
|
throw applyTransform(err, [
|
|
150
|
-
notify,
|
|
154
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
151
155
|
]);
|
|
152
156
|
}
|
|
153
157
|
};
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
merge,
|
|
9
9
|
mergeEach,
|
|
10
10
|
notify,
|
|
11
|
+
notifyServerError,
|
|
11
12
|
sanitize,
|
|
12
13
|
snakeToCamel,
|
|
13
14
|
starToSearch,
|
|
@@ -114,7 +115,13 @@ const preRequestHandler = (item: ApiParams) => {
|
|
|
114
115
|
return copy;
|
|
115
116
|
};
|
|
116
117
|
|
|
117
|
-
const addDevice = async ({
|
|
118
|
+
const addDevice = async ({
|
|
119
|
+
itemInstance,
|
|
120
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
121
|
+
notifyNetworkError = true,
|
|
122
|
+
}: AddItemParams & {
|
|
123
|
+
notifyNetworkError?: boolean;
|
|
124
|
+
}) => {
|
|
118
125
|
const item = applyTransform(itemInstance, [
|
|
119
126
|
preRequestHandler,
|
|
120
127
|
sanitize(fieldsToSend),
|
|
@@ -127,7 +134,7 @@ const addDevice = async ({ itemInstance }: AddItemParams) => {
|
|
|
127
134
|
]);
|
|
128
135
|
} catch (err) {
|
|
129
136
|
throw applyTransform(err, [
|
|
130
|
-
notify,
|
|
137
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
131
138
|
]);
|
|
132
139
|
}
|
|
133
140
|
};
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
camelToSnake,
|
|
10
10
|
merge,
|
|
11
11
|
notify,
|
|
12
|
+
notifyServerError,
|
|
12
13
|
sanitize,
|
|
13
14
|
snakeToCamel,
|
|
14
15
|
starToSearch,
|
|
@@ -139,7 +140,18 @@ export const getMediaUrl = (
|
|
|
139
140
|
);
|
|
140
141
|
|
|
141
142
|
/** [Claude] All files in one request, one notification; fields named `file[n]` as the old dropzone upload sent them */
|
|
142
|
-
const uploadMedia = async (
|
|
143
|
+
const uploadMedia = async (
|
|
144
|
+
files: File[],
|
|
145
|
+
{
|
|
146
|
+
// [Claude] callers showing their own success toast (e.g. the media import, WTEL-10817) turn it off
|
|
147
|
+
notifySuccess = true,
|
|
148
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
149
|
+
notifyNetworkError = true,
|
|
150
|
+
}: {
|
|
151
|
+
notifySuccess?: boolean;
|
|
152
|
+
notifyNetworkError?: boolean;
|
|
153
|
+
} = {},
|
|
154
|
+
) => {
|
|
143
155
|
const formData = new FormData();
|
|
144
156
|
files.forEach((file, index) => {
|
|
145
157
|
formData.append(`file[${index}]`, file);
|
|
@@ -147,6 +159,7 @@ const uploadMedia = async (files: File[]) => {
|
|
|
147
159
|
|
|
148
160
|
try {
|
|
149
161
|
const response = await instance.post('/storage/media', formData);
|
|
162
|
+
if (!notifySuccess) return response.data;
|
|
150
163
|
return applyTransform(response.data, [
|
|
151
164
|
notify(({ callback }) =>
|
|
152
165
|
callback({
|
|
@@ -157,7 +170,7 @@ const uploadMedia = async (files: File[]) => {
|
|
|
157
170
|
]);
|
|
158
171
|
} catch (err) {
|
|
159
172
|
throw applyTransform(err, [
|
|
160
|
-
notify,
|
|
173
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
161
174
|
]);
|
|
162
175
|
}
|
|
163
176
|
};
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
camelToSnake,
|
|
19
19
|
merge,
|
|
20
20
|
notify,
|
|
21
|
+
notifyServerError,
|
|
21
22
|
sanitizeToWire,
|
|
22
23
|
snakeToCamel,
|
|
23
24
|
starToSearch,
|
|
@@ -201,7 +202,10 @@ const uploadResourceDisplays = async ({
|
|
|
201
202
|
file,
|
|
202
203
|
delimiter,
|
|
203
204
|
map,
|
|
205
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
206
|
+
notifyNetworkError = true,
|
|
204
207
|
}: {
|
|
208
|
+
notifyNetworkError?: boolean;
|
|
205
209
|
parentId: ApiId;
|
|
206
210
|
file: File;
|
|
207
211
|
delimiter: string;
|
|
@@ -224,7 +228,7 @@ const uploadResourceDisplays = async ({
|
|
|
224
228
|
} catch (err) {
|
|
225
229
|
throw applyTransform(err, [
|
|
226
230
|
translatePhoneNumberError,
|
|
227
|
-
notify,
|
|
231
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
228
232
|
]);
|
|
229
233
|
}
|
|
230
234
|
};
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
camelToSnake,
|
|
14
14
|
merge,
|
|
15
15
|
notify,
|
|
16
|
+
notifyServerError,
|
|
16
17
|
sanitizeToWire,
|
|
17
18
|
snakeToCamel,
|
|
18
19
|
starToSearch,
|
|
@@ -483,10 +484,16 @@ const addMembersBulk = async ({
|
|
|
483
484
|
parentId,
|
|
484
485
|
fileName,
|
|
485
486
|
items,
|
|
487
|
+
// [Claude] imports save in chunks and show one "imported" toast themselves, so they turn it off (WTEL-10817)
|
|
488
|
+
notifySuccess = true,
|
|
489
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
490
|
+
notifyNetworkError = true,
|
|
486
491
|
}: {
|
|
492
|
+
notifyNetworkError?: boolean;
|
|
487
493
|
parentId: ApiId;
|
|
488
494
|
fileName: string;
|
|
489
495
|
items: ApiParams[];
|
|
496
|
+
notifySuccess?: boolean;
|
|
490
497
|
}) => {
|
|
491
498
|
const body = {
|
|
492
499
|
parentId,
|
|
@@ -498,6 +505,11 @@ const addMembersBulk = async ({
|
|
|
498
505
|
String(parentId),
|
|
499
506
|
body,
|
|
500
507
|
);
|
|
508
|
+
if (!notifySuccess) {
|
|
509
|
+
return applyTransform(response.data, [
|
|
510
|
+
snakeToCamel(doNotConvertKeys),
|
|
511
|
+
]);
|
|
512
|
+
}
|
|
501
513
|
return applyTransform(response.data, [
|
|
502
514
|
snakeToCamel(doNotConvertKeys),
|
|
503
515
|
notify(({ callback }: ApiParams) =>
|
|
@@ -509,7 +521,7 @@ const addMembersBulk = async ({
|
|
|
509
521
|
]);
|
|
510
522
|
} catch (err) {
|
|
511
523
|
throw applyTransform(err, [
|
|
512
|
-
notify,
|
|
524
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
513
525
|
]);
|
|
514
526
|
}
|
|
515
527
|
};
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
merge,
|
|
16
16
|
mergeEach,
|
|
17
17
|
notify,
|
|
18
|
+
notifyServerError,
|
|
18
19
|
sanitize,
|
|
19
20
|
sanitizeToWire,
|
|
20
21
|
snakeToCamel,
|
|
@@ -205,7 +206,13 @@ const preRequestHandler = (item: ApiParams) => {
|
|
|
205
206
|
return copy;
|
|
206
207
|
};
|
|
207
208
|
|
|
208
|
-
const addUser = async ({
|
|
209
|
+
const addUser = async ({
|
|
210
|
+
itemInstance,
|
|
211
|
+
// [Claude] imports show their own localized error, so they turn off the toast for network errors (WTEL-11052)
|
|
212
|
+
notifyNetworkError = true,
|
|
213
|
+
}: AddItemParams & {
|
|
214
|
+
notifyNetworkError?: boolean;
|
|
215
|
+
}) => {
|
|
209
216
|
const item = applyTransform(itemInstance, [
|
|
210
217
|
preRequestHandler,
|
|
211
218
|
sanitize(fieldsToSend),
|
|
@@ -234,7 +241,7 @@ const addUser = async ({ itemInstance }: AddItemParams) => {
|
|
|
234
241
|
]);
|
|
235
242
|
} catch (err) {
|
|
236
243
|
throw applyTransform(err, [
|
|
237
|
-
notify,
|
|
244
|
+
notifyNetworkError ? notify : notifyServerError,
|
|
238
245
|
]);
|
|
239
246
|
}
|
|
240
247
|
};
|
|
@@ -5,7 +5,7 @@ import generateUrl from './generateUrl/generateUrl.transformer';
|
|
|
5
5
|
import log from './log/log.transformer';
|
|
6
6
|
import merge from './merge/merge.transformer';
|
|
7
7
|
import mergeEach from './mergeEach/mergeEach.transformer';
|
|
8
|
-
import notify from './notify/notify.transformer';
|
|
8
|
+
import notify, { notifyServerError } from './notify/notify.transformer';
|
|
9
9
|
import sanitize from './sanitize/sanitize.transformer';
|
|
10
10
|
import sanitizeToWire from './sanitizeToWire/sanitizeToWire.transformer';
|
|
11
11
|
import { skipIf } from './skipIf/skipIf';
|
|
@@ -23,6 +23,7 @@ export {
|
|
|
23
23
|
merge,
|
|
24
24
|
mergeEach,
|
|
25
25
|
notify,
|
|
26
|
+
notifyServerError,
|
|
26
27
|
sanitize,
|
|
27
28
|
sanitizeToWire,
|
|
28
29
|
skipIf,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AxiosError, type AxiosResponse } from 'axios';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createI18n } from 'vue-i18n';
|
|
4
|
+
|
|
5
|
+
import { config, setConfig } from '../../../../config/config';
|
|
6
|
+
import notify from '../notify.transformer';
|
|
7
|
+
|
|
8
|
+
// [Claude] https://webitel.atlassian.net/browse/WTEL-11052
|
|
9
|
+
describe('notify', () => {
|
|
10
|
+
const $emit = vi.fn();
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
config.eventBus = {
|
|
14
|
+
$emit,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
config.eventBus = null;
|
|
20
|
+
config.i18n = null;
|
|
21
|
+
$emit.mockReset();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('shows a localized connection error instead of the raw network error', () => {
|
|
25
|
+
setConfig({
|
|
26
|
+
i18n: createI18n({
|
|
27
|
+
legacy: false,
|
|
28
|
+
locale: 'uk',
|
|
29
|
+
messages: {},
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
notify(new AxiosError('Network Error', AxiosError.ERR_NETWORK));
|
|
34
|
+
|
|
35
|
+
expect($emit).toHaveBeenCalledWith('notification', {
|
|
36
|
+
type: 'error',
|
|
37
|
+
text: 'Помилка з’єднання',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('falls back to english connection error without i18n', () => {
|
|
42
|
+
notify(new AxiosError('Network Error', AxiosError.ERR_NETWORK));
|
|
43
|
+
|
|
44
|
+
expect($emit).toHaveBeenCalledWith('notification', {
|
|
45
|
+
type: 'error',
|
|
46
|
+
text: 'Connection error',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('keeps the server message when there is a response', () => {
|
|
51
|
+
const error = new AxiosError('Request failed', 'ERR_BAD_REQUEST');
|
|
52
|
+
error.response = {
|
|
53
|
+
data: {
|
|
54
|
+
detail: 'user already exists',
|
|
55
|
+
},
|
|
56
|
+
} as AxiosResponse;
|
|
57
|
+
|
|
58
|
+
notify(error);
|
|
59
|
+
|
|
60
|
+
expect($emit).toHaveBeenCalledWith('notification', {
|
|
61
|
+
type: 'error',
|
|
62
|
+
text: 'user already exists',
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AxiosError, type AxiosResponse } from 'axios';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { config } from '../../../../config/config';
|
|
5
|
+
import { notifyServerError } from '../notify.transformer';
|
|
6
|
+
|
|
7
|
+
// [Claude] https://webitel.atlassian.net/browse/WTEL-11052
|
|
8
|
+
describe('notifyServerError', () => {
|
|
9
|
+
const $emit = vi.fn();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
config.eventBus = {
|
|
13
|
+
$emit,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
config.eventBus = null;
|
|
19
|
+
$emit.mockReset();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('stays silent for a network error without a server response', () => {
|
|
23
|
+
const error = new AxiosError('Network Error', AxiosError.ERR_NETWORK);
|
|
24
|
+
|
|
25
|
+
expect(notifyServerError(error)).toBe(error);
|
|
26
|
+
expect($emit).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('notifies with the server message when there is a response', () => {
|
|
30
|
+
const error = new AxiosError('Request failed', 'ERR_BAD_REQUEST');
|
|
31
|
+
error.response = {
|
|
32
|
+
data: {
|
|
33
|
+
detail: 'user already exists',
|
|
34
|
+
},
|
|
35
|
+
} as AxiosResponse;
|
|
36
|
+
|
|
37
|
+
expect(notifyServerError(error)).toBe(error);
|
|
38
|
+
expect($emit).toHaveBeenCalledWith('notification', {
|
|
39
|
+
type: 'error',
|
|
40
|
+
text: 'user already exists',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
import type { Composer } from 'vue-i18n';
|
|
2
3
|
|
|
3
4
|
import { config as apiServicesConfig } from '../../../config/config';
|
|
4
5
|
import type { Transformer } from '../applyTransform';
|
|
@@ -7,6 +8,20 @@ type NotificationCallback = (payload: { type: string; text: unknown }) => void;
|
|
|
7
8
|
|
|
8
9
|
type StaticNotification = (payload: { callback: NotificationCallback }) => void;
|
|
9
10
|
|
|
11
|
+
const CONNECTION_ERROR_KEY = 'requestErrors.connection';
|
|
12
|
+
|
|
13
|
+
// [Claude] no server response (offline, DNS, timeout): the raw "AxiosError: Network Error" means nothing to a user (WTEL-11052)
|
|
14
|
+
const isConnectionError = (error: Error) => {
|
|
15
|
+
const { isAxiosError, response, code } = error as AxiosError;
|
|
16
|
+
return !!isAxiosError && !response && code !== AxiosError.ERR_CANCELED;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const translateConnectionError = () => {
|
|
20
|
+
const i18n = apiServicesConfig.i18n;
|
|
21
|
+
if (!i18n?.global) return 'Connection error';
|
|
22
|
+
return (i18n.global as Composer).t(CONNECTION_ERROR_KEY);
|
|
23
|
+
};
|
|
24
|
+
|
|
10
25
|
function notifyTransformer(notificationObject: StaticNotification): Transformer;
|
|
11
26
|
function notifyTransformer<T>(notificationObject: T): T;
|
|
12
27
|
function notifyTransformer(notificationObject: unknown): unknown {
|
|
@@ -45,7 +60,9 @@ function notifyTransformer(notificationObject: unknown): unknown {
|
|
|
45
60
|
response?.data?.translation ||
|
|
46
61
|
response?.data?.detail ||
|
|
47
62
|
response?.data?.message ||
|
|
48
|
-
notificationObject
|
|
63
|
+
(isConnectionError(notificationObject)
|
|
64
|
+
? translateConnectionError()
|
|
65
|
+
: notificationObject);
|
|
49
66
|
|
|
50
67
|
apiServicesConfig.eventBus?.$emit('notification', {
|
|
51
68
|
type: 'error',
|
|
@@ -55,4 +72,18 @@ function notifyTransformer(notificationObject: unknown): unknown {
|
|
|
55
72
|
return notificationObject;
|
|
56
73
|
}
|
|
57
74
|
|
|
75
|
+
/**
|
|
76
|
+
* [Claude] like notify, but silent for network errors (no server response, e.g. offline):
|
|
77
|
+
* for callers that show their own localized error, so the user doesn't also get "AxiosError: Network Error" (WTEL-11052)
|
|
78
|
+
*/
|
|
79
|
+
export const notifyServerError = <T>(error: T): T => {
|
|
80
|
+
if (
|
|
81
|
+
error instanceof Error &&
|
|
82
|
+
!(error as Error & Pick<AxiosError, 'response'>).response
|
|
83
|
+
) {
|
|
84
|
+
return error;
|
|
85
|
+
}
|
|
86
|
+
return notifyTransformer(error);
|
|
87
|
+
};
|
|
88
|
+
|
|
58
89
|
export default notifyTransformer;
|
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
package/src/locale/vi/vi.ts
CHANGED