@webitel/api-services 26.8.55 → 26.8.56
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/index.ts +1 -0
- package/src/api/clients/logs/logs.ts +13 -7
- package/src/api/clients/userTokens/userTokens.ts +147 -0
- package/src/utils/formatDate.ts +16 -3
- package/src/validations/index.ts +1 -0
- package/src/validations/userToken/userToken.validations.ts +5 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/index.d.ts +1 -0
- package/types/api/clients/userTokens/userTokens.d.ts +11 -0
- package/types/utils/formatDate.d.ts +1 -1
- package/types/validations/index.d.ts +1 -0
- package/types/validations/userToken/userToken.validations.d.ts +4 -0
package/package.json
CHANGED
package/src/api/clients/index.ts
CHANGED
|
@@ -96,6 +96,7 @@ export * from './triggers/triggerJobs';
|
|
|
96
96
|
export * from './triggers/triggers';
|
|
97
97
|
export * from './userSettings/userSettings';
|
|
98
98
|
export * from './users/users';
|
|
99
|
+
export * from './userTokens/userTokens';
|
|
99
100
|
export * from './variables/variables';
|
|
100
101
|
export * from './workingConditions/workingConditions';
|
|
101
102
|
export * from './workspaceWidgets/workspaceWidgets';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getLoggerService } from '../../../gen-wire';
|
|
2
|
+
import { normalizeDatetimeRange } from '../../../scripts';
|
|
2
3
|
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
3
4
|
import {
|
|
4
5
|
applyTransform,
|
|
@@ -26,8 +27,7 @@ const getLogsByUserList = async (params: ApiParams) => {
|
|
|
26
27
|
'fields',
|
|
27
28
|
'action',
|
|
28
29
|
'object',
|
|
29
|
-
'
|
|
30
|
-
'to',
|
|
30
|
+
'date',
|
|
31
31
|
'userIp',
|
|
32
32
|
];
|
|
33
33
|
|
|
@@ -40,12 +40,15 @@ const getLogsByUserList = async (params: ApiParams) => {
|
|
|
40
40
|
fields,
|
|
41
41
|
action,
|
|
42
42
|
object,
|
|
43
|
-
|
|
44
|
-
to,
|
|
43
|
+
date,
|
|
45
44
|
userIp,
|
|
46
45
|
} = applyTransform(params, [
|
|
47
46
|
sanitize(fieldsToSend),
|
|
48
47
|
merge(getDefaultGetParams()),
|
|
48
|
+
({ date, ...rest }) => ({
|
|
49
|
+
...rest,
|
|
50
|
+
date: normalizeDatetimeRange(date),
|
|
51
|
+
}),
|
|
49
52
|
starToSearch('search'),
|
|
50
53
|
]);
|
|
51
54
|
|
|
@@ -58,12 +61,15 @@ const getLogsByUserList = async (params: ApiParams) => {
|
|
|
58
61
|
// the generated param is `q`; `search` is what the datalist store sends
|
|
59
62
|
q: search,
|
|
60
63
|
sort: sort || DEFAULT_SORT,
|
|
61
|
-
fields
|
|
64
|
+
fields: fields && [
|
|
65
|
+
...fields,
|
|
66
|
+
'config_id',
|
|
67
|
+
],
|
|
62
68
|
object_id: object,
|
|
63
69
|
action,
|
|
64
70
|
user_ip: userIp,
|
|
65
|
-
date_from: from,
|
|
66
|
-
date_to: to,
|
|
71
|
+
date_from: date?.from,
|
|
72
|
+
date_to: date?.to,
|
|
67
73
|
},
|
|
68
74
|
);
|
|
69
75
|
const { items, next } = applyTransform(response.data, [
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { userTokenSchema } from '@webitel/api-services/validations';
|
|
3
|
+
import { getUserAccessTokens } from '../../../gen-wire';
|
|
4
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
5
|
+
import {
|
|
6
|
+
applyTransform,
|
|
7
|
+
camelToSnake,
|
|
8
|
+
merge,
|
|
9
|
+
notify,
|
|
10
|
+
sanitizeToWire,
|
|
11
|
+
snakeToCamel,
|
|
12
|
+
starToSearch,
|
|
13
|
+
} from '../../transformers';
|
|
14
|
+
import type {
|
|
15
|
+
ApiParams,
|
|
16
|
+
NestedAddItemParams,
|
|
17
|
+
NestedDeleteItemParams,
|
|
18
|
+
NestedGetItemParams,
|
|
19
|
+
NestedUpdateItemParams,
|
|
20
|
+
} from '../_shared/types';
|
|
21
|
+
|
|
22
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(userTokenSchema);
|
|
23
|
+
|
|
24
|
+
const getUserTokensList = async (params: ApiParams) => {
|
|
25
|
+
const { page, size, search, sort, fields, parentId } = applyTransform(
|
|
26
|
+
params,
|
|
27
|
+
[
|
|
28
|
+
merge(getDefaultGetParams()),
|
|
29
|
+
starToSearch('search'),
|
|
30
|
+
],
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const response = await getUserAccessTokens().listUserAccessToken(
|
|
35
|
+
String(parentId),
|
|
36
|
+
{
|
|
37
|
+
page,
|
|
38
|
+
size,
|
|
39
|
+
q: search,
|
|
40
|
+
sort: sort
|
|
41
|
+
? [
|
|
42
|
+
sort,
|
|
43
|
+
]
|
|
44
|
+
: undefined,
|
|
45
|
+
fields,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
const { items, next } = applyTransform(response.data, [
|
|
49
|
+
snakeToCamel(),
|
|
50
|
+
merge(getDefaultGetListResponse()),
|
|
51
|
+
]);
|
|
52
|
+
return {
|
|
53
|
+
items,
|
|
54
|
+
next,
|
|
55
|
+
};
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw applyTransform(err, [
|
|
58
|
+
notify,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getUserToken = async ({ parentId, itemId: id }: NestedGetItemParams) => {
|
|
64
|
+
try {
|
|
65
|
+
const response = await getUserAccessTokens().getUserAccessToken(
|
|
66
|
+
String(parentId),
|
|
67
|
+
String(id),
|
|
68
|
+
);
|
|
69
|
+
return applyTransform(response.data, [
|
|
70
|
+
snakeToCamel(),
|
|
71
|
+
]);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
throw applyTransform(err, [
|
|
74
|
+
notify,
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const addUserToken = async ({
|
|
80
|
+
parentId,
|
|
81
|
+
itemInstance,
|
|
82
|
+
}: NestedAddItemParams) => {
|
|
83
|
+
const item = applyTransform(itemInstance, [
|
|
84
|
+
sanitizeToWire(fieldsToSend),
|
|
85
|
+
camelToSnake(),
|
|
86
|
+
]);
|
|
87
|
+
try {
|
|
88
|
+
const response = await getUserAccessTokens().addUserAccessToken(
|
|
89
|
+
String(parentId),
|
|
90
|
+
item,
|
|
91
|
+
);
|
|
92
|
+
return applyTransform(response.data, [
|
|
93
|
+
snakeToCamel(),
|
|
94
|
+
]);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
throw applyTransform(err, [
|
|
97
|
+
notify,
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const updateUserToken = async ({
|
|
103
|
+
parentId,
|
|
104
|
+
itemId: id,
|
|
105
|
+
itemInstance,
|
|
106
|
+
}: NestedUpdateItemParams) => {
|
|
107
|
+
const item = applyTransform(itemInstance, [
|
|
108
|
+
sanitizeToWire(fieldsToSend),
|
|
109
|
+
camelToSnake(),
|
|
110
|
+
]);
|
|
111
|
+
try {
|
|
112
|
+
const response = await getUserAccessTokens().updateUserAccessToken(
|
|
113
|
+
String(parentId),
|
|
114
|
+
String(id),
|
|
115
|
+
item,
|
|
116
|
+
);
|
|
117
|
+
return applyTransform(response.data, [
|
|
118
|
+
snakeToCamel(),
|
|
119
|
+
]);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throw applyTransform(err, [
|
|
122
|
+
notify,
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const deleteUserToken = async ({ parentId, id }: NestedDeleteItemParams) => {
|
|
128
|
+
try {
|
|
129
|
+
const response = await getUserAccessTokens().deleteUserAccessToken(
|
|
130
|
+
String(parentId),
|
|
131
|
+
String(id),
|
|
132
|
+
);
|
|
133
|
+
return applyTransform(response.data, []);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
throw applyTransform(err, [
|
|
136
|
+
notify,
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const UserTokensAPI = {
|
|
142
|
+
getList: getUserTokensList,
|
|
143
|
+
get: getUserToken,
|
|
144
|
+
add: addUserToken,
|
|
145
|
+
update: updateUserToken,
|
|
146
|
+
delete: deleteUserToken,
|
|
147
|
+
};
|
package/src/utils/formatDate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { uk } from 'date-fns/locale';
|
|
2
|
-
import { formatInTimeZone } from 'date-fns-tz';
|
|
2
|
+
import { formatInTimeZone, toDate } from 'date-fns-tz';
|
|
3
3
|
|
|
4
4
|
import type { FormatDateMode } from '../enums/FormatDateMode/FormatDateMode';
|
|
5
5
|
|
|
@@ -27,8 +27,19 @@ const formatStringMap = {
|
|
|
27
27
|
datetimeShort: 'Pp', // dd.MM.yyyy, HH:mm (13.11.2025, 15:53)
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
function normalizeDate(date: string | number | Date): string | number | Date {
|
|
31
|
+
if (
|
|
32
|
+
typeof date === 'string' &&
|
|
33
|
+
/^\d+$/.test(date) &&
|
|
34
|
+
Number.isNaN(toDate(date).getTime())
|
|
35
|
+
) {
|
|
36
|
+
return +date;
|
|
37
|
+
}
|
|
38
|
+
return date;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
export function formatDate(
|
|
31
|
-
date: string | number | Date,
|
|
42
|
+
date: string | number | Date | null | undefined,
|
|
32
43
|
to: (typeof FormatDateMode)[keyof typeof FormatDateMode],
|
|
33
44
|
{
|
|
34
45
|
timezone = undefined,
|
|
@@ -36,9 +47,11 @@ export function formatDate(
|
|
|
36
47
|
timezone?: string;
|
|
37
48
|
} = {},
|
|
38
49
|
): string {
|
|
50
|
+
if (date === null || date === undefined || date === '') return '';
|
|
51
|
+
|
|
39
52
|
const timeZone = timezone ?? getUserTimeZone();
|
|
40
53
|
|
|
41
|
-
return formatInTimeZone(date, timeZone, formatStringMap[to], {
|
|
54
|
+
return formatInTimeZone(normalizeDate(date), timeZone, formatStringMap[to], {
|
|
42
55
|
locale: uk,
|
|
43
56
|
});
|
|
44
57
|
}
|
package/src/validations/index.ts
CHANGED
|
@@ -45,4 +45,5 @@ export * from './slaCondition/slaCondition.validations';
|
|
|
45
45
|
export * from './typeExtension/typeExtension.validations';
|
|
46
46
|
export * from './types';
|
|
47
47
|
export * from './user/user.validations';
|
|
48
|
+
export * from './userToken/userToken.validations';
|
|
48
49
|
export * from './variable/variable.validations';
|