@webitel/api-services 0.1.31 → 0.1.33
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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getEmails } from '@webitel/api-services/gen';
|
|
2
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
3
|
+
import {
|
|
4
|
+
applyTransform,
|
|
5
|
+
camelToSnake,
|
|
6
|
+
merge,
|
|
7
|
+
mergeEach,
|
|
8
|
+
notify,
|
|
9
|
+
sanitize,
|
|
10
|
+
snakeToCamel,
|
|
11
|
+
starToSearch,
|
|
12
|
+
} from '../../transformers';
|
|
13
|
+
|
|
14
|
+
const getList = async (params) => {
|
|
15
|
+
const defaultObject = {
|
|
16
|
+
primary: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const fieldsToSend = [
|
|
20
|
+
'parentId',
|
|
21
|
+
'page',
|
|
22
|
+
'size',
|
|
23
|
+
'q',
|
|
24
|
+
'sort',
|
|
25
|
+
'fields',
|
|
26
|
+
'id',
|
|
27
|
+
];
|
|
28
|
+
const { parentId, page, size, q, sort, fields, id } = applyTransform(params, [
|
|
29
|
+
sanitize(fieldsToSend),
|
|
30
|
+
merge(getDefaultGetParams()),
|
|
31
|
+
starToSearch('q'),
|
|
32
|
+
]);
|
|
33
|
+
try {
|
|
34
|
+
const response = await getEmails().listEmails(
|
|
35
|
+
parentId,
|
|
36
|
+
page,
|
|
37
|
+
size,
|
|
38
|
+
q,
|
|
39
|
+
sort,
|
|
40
|
+
[
|
|
41
|
+
'etag',
|
|
42
|
+
...fields,
|
|
43
|
+
],
|
|
44
|
+
id,
|
|
45
|
+
);
|
|
46
|
+
const { data, next } = applyTransform(response.data, [
|
|
47
|
+
snakeToCamel(),
|
|
48
|
+
merge(getDefaultGetListResponse()),
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
items: applyTransform(data, [
|
|
52
|
+
mergeEach(defaultObject),
|
|
53
|
+
]),
|
|
54
|
+
next,
|
|
55
|
+
};
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw applyTransform(err, [
|
|
58
|
+
notify,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const get = async ({ itemId, parentId }) => {
|
|
64
|
+
const fields = [
|
|
65
|
+
'email',
|
|
66
|
+
'primary',
|
|
67
|
+
'etag',
|
|
68
|
+
'type',
|
|
69
|
+
];
|
|
70
|
+
try {
|
|
71
|
+
const response = await getEmails().locateEmail(parentId, itemId, fields);
|
|
72
|
+
return applyTransform(response.data, [
|
|
73
|
+
snakeToCamel(),
|
|
74
|
+
]);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
throw applyTransform(err, [
|
|
77
|
+
notify,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const fieldsToSend = [
|
|
83
|
+
'email',
|
|
84
|
+
'type',
|
|
85
|
+
'primary',
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const add = async ({ contactId, emails, params, options }) => {
|
|
89
|
+
const item = applyTransform(emails, [
|
|
90
|
+
camelToSnake(),
|
|
91
|
+
]);
|
|
92
|
+
console.log(item);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const response = await getEmails().mergeEmails(
|
|
96
|
+
contactId,
|
|
97
|
+
item,
|
|
98
|
+
params,
|
|
99
|
+
options,
|
|
100
|
+
);
|
|
101
|
+
return applyTransform(response.data, [
|
|
102
|
+
snakeToCamel(),
|
|
103
|
+
]);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
throw applyTransform(err, [
|
|
106
|
+
notify,
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const update = async ({ itemInstance, etag: id, parentId }) => {
|
|
111
|
+
const item = applyTransform(itemInstance, [
|
|
112
|
+
sanitize(fieldsToSend),
|
|
113
|
+
camelToSnake(),
|
|
114
|
+
]);
|
|
115
|
+
try {
|
|
116
|
+
const response = await getEmails().updateEmail(parentId, id, item);
|
|
117
|
+
return applyTransform(response.data, [
|
|
118
|
+
snakeToCamel(),
|
|
119
|
+
]);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throw applyTransform(err, [
|
|
122
|
+
notify,
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const patch = async ({ parentId, changes, etag }) => {
|
|
128
|
+
const body = applyTransform(changes, [
|
|
129
|
+
sanitize(fieldsToSend),
|
|
130
|
+
camelToSnake(),
|
|
131
|
+
]);
|
|
132
|
+
try {
|
|
133
|
+
const response = await getEmails().updateEmail(parentId, etag, body);
|
|
134
|
+
return applyTransform(response.data, [
|
|
135
|
+
snakeToCamel(),
|
|
136
|
+
]);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
throw applyTransform(err, [
|
|
139
|
+
notify,
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const deleteItem = async ({ id, etag, parentId }) => {
|
|
145
|
+
try {
|
|
146
|
+
const response = await getEmails().deleteEmail(parentId, etag);
|
|
147
|
+
return applyTransform(response.data, []);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
throw applyTransform(err, [
|
|
150
|
+
notify,
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const EmailsAPI = {
|
|
156
|
+
getList,
|
|
157
|
+
get,
|
|
158
|
+
add,
|
|
159
|
+
update,
|
|
160
|
+
patch,
|
|
161
|
+
delete: deleteItem,
|
|
162
|
+
};
|
package/src/api/clients/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './chatGateways/chatGateways';
|
|
|
19
19
|
export * from './communications/communications';
|
|
20
20
|
export * from './configurations/configurations';
|
|
21
21
|
export * from './contactGroups/contactGroups';
|
|
22
|
+
export * from './emails/emails';
|
|
22
23
|
export * from './fileServices/fileServices';
|
|
23
24
|
export * from './flows/flow';
|
|
24
25
|
export * from './gateways/gateways';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const EmailsAPI: {
|
|
2
|
+
getList: (params: any) => Promise<{
|
|
3
|
+
items: any;
|
|
4
|
+
next: any;
|
|
5
|
+
}>;
|
|
6
|
+
get: ({ itemId, parentId }: {
|
|
7
|
+
itemId: any;
|
|
8
|
+
parentId: any;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
add: ({ contactId, emails, params, options }: {
|
|
11
|
+
contactId: any;
|
|
12
|
+
emails: any;
|
|
13
|
+
params: any;
|
|
14
|
+
options: any;
|
|
15
|
+
}) => Promise<any>;
|
|
16
|
+
update: ({ itemInstance, etag: id, parentId }: {
|
|
17
|
+
itemInstance: any;
|
|
18
|
+
etag: any;
|
|
19
|
+
parentId: any;
|
|
20
|
+
}) => Promise<any>;
|
|
21
|
+
patch: ({ parentId, changes, etag }: {
|
|
22
|
+
parentId: any;
|
|
23
|
+
changes: any;
|
|
24
|
+
etag: any;
|
|
25
|
+
}) => Promise<any>;
|
|
26
|
+
delete: ({ id, etag, parentId }: {
|
|
27
|
+
id: any;
|
|
28
|
+
etag: any;
|
|
29
|
+
parentId: any;
|
|
30
|
+
}) => Promise<any>;
|
|
31
|
+
};
|
|
@@ -19,6 +19,7 @@ export * from './chatGateways/chatGateways';
|
|
|
19
19
|
export * from './communications/communications';
|
|
20
20
|
export * from './configurations/configurations';
|
|
21
21
|
export * from './contactGroups/contactGroups';
|
|
22
|
+
export * from './emails/emails';
|
|
22
23
|
export * from './fileServices/fileServices';
|
|
23
24
|
export * from './flows/flow';
|
|
24
25
|
export * from './gateways/gateways';
|