@suprsend/node-sdk 1.12.0 → 1.13.0
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/dist/constants.js +2 -8
- package/dist/event.js +2 -2
- package/dist/events_bulk.js +2 -2
- package/dist/index.js +21 -0
- package/dist/object_edit.js +6 -12
- package/dist/object_edit_internal_helper.js +40 -301
- package/dist/objects_api.js +193 -242
- package/dist/request_json/workflow.json +7 -29
- package/dist/request_json/workflow_trigger.json +7 -29
- package/dist/subscriber.js +10 -27
- package/dist/subscriber_helper.js +33 -291
- package/dist/subscriber_list.js +2 -2
- package/dist/user_edit.js +412 -0
- package/dist/user_edit_internal_helper.js +363 -0
- package/dist/users_api.js +400 -98
- package/dist/users_edit_bulk.js +312 -0
- package/dist/workflow.js +2 -2
- package/dist/workflow_request.js +2 -2
- package/dist/workflow_trigger_bulk.js +2 -2
- package/dist/workflows_bulk.js +2 -2
- package/package.json +1 -1
- package/src/constants.js +0 -4
- package/src/event.js +4 -5
- package/src/events_bulk.js +3 -5
- package/src/index.js +6 -0
- package/src/object_edit.js +6 -6
- package/src/object_edit_internal_helper.js +37 -295
- package/src/objects_api.js +97 -93
- package/src/request_json/workflow.json +7 -29
- package/src/request_json/workflow_trigger.json +7 -29
- package/src/subscriber.js +8 -20
- package/src/subscriber_helper.js +34 -284
- package/src/subscriber_list.js +4 -4
- package/src/user_edit.js +360 -0
- package/src/user_edit_internal_helper.js +297 -0
- package/src/users_api.js +207 -27
- package/src/users_edit_bulk.js +211 -0
- package/src/workflow.js +4 -5
- package/src/workflow_request.js +4 -4
- package/src/workflow_trigger_bulk.js +2 -4
- package/src/workflows_bulk.js +3 -5
- package/types/index.d.ts +113 -8
- package/dist/language_codes.js +0 -197
- package/src/language_codes.js +0 -188
package/src/users_api.js
CHANGED
|
@@ -1,65 +1,212 @@
|
|
|
1
1
|
import get_request_signature from "./signature";
|
|
2
|
-
import { SuprsendApiError } from "./utils";
|
|
2
|
+
import { SuprsendApiError, InputValueError } from "./utils";
|
|
3
3
|
import axios from "axios";
|
|
4
|
+
import UserEdit from "./user_edit";
|
|
5
|
+
import BulkUsersEdit from "./users_edit_bulk";
|
|
4
6
|
|
|
5
7
|
export default class UsersApi {
|
|
6
8
|
constructor(config) {
|
|
7
9
|
this.config = config;
|
|
8
10
|
this.list_url = `${this.config.base_url}v1/user/`;
|
|
11
|
+
this.bulk_url = `${this.config.base_url}v1/bulk/user/`;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
__get_headers() {
|
|
12
15
|
return {
|
|
13
16
|
"Content-Type": "application/json; charset=utf-8",
|
|
14
17
|
"User-Agent": this.config.user_agent,
|
|
15
|
-
Date: new Date().toISOString(),
|
|
18
|
+
Date: new Date().toISOString(),
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
async list(options = null) {
|
|
23
|
+
const encoded_options = options
|
|
24
|
+
? new URLSearchParams(options).toString()
|
|
25
|
+
: "";
|
|
26
|
+
const url = `${this.list_url}${
|
|
27
|
+
encoded_options ? `?${encoded_options}` : ""
|
|
28
|
+
}`;
|
|
29
|
+
const headers = this.__get_headers();
|
|
30
|
+
|
|
31
|
+
// Signature and Authorization-header
|
|
32
|
+
const sig = get_request_signature(
|
|
33
|
+
url,
|
|
34
|
+
"GET",
|
|
35
|
+
"",
|
|
36
|
+
headers,
|
|
37
|
+
this.config.workspace_secret
|
|
38
|
+
);
|
|
39
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const resp = await axios.get(url, { headers });
|
|
43
|
+
return resp.data;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new SuprsendApiError(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_validate_distinct_id(distinct_id) {
|
|
50
|
+
if (!distinct_id || !distinct_id.trim()) {
|
|
21
51
|
throw new Error("missing distinct_id");
|
|
22
52
|
}
|
|
23
53
|
return distinct_id.trim();
|
|
24
54
|
}
|
|
25
55
|
|
|
26
56
|
detail_url(distinct_id) {
|
|
27
|
-
|
|
57
|
+
distinct_id = this._validate_distinct_id(distinct_id);
|
|
58
|
+
const distinct_id_encoded = encodeURIComponent(distinct_id);
|
|
59
|
+
return `${this.list_url}${distinct_id_encoded}/`;
|
|
28
60
|
}
|
|
29
61
|
|
|
30
62
|
async get(distinct_id) {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
63
|
+
const url = this.detail_url(distinct_id);
|
|
64
|
+
const headers = this.__get_headers();
|
|
65
|
+
|
|
66
|
+
// Signature and Authorization-header
|
|
67
|
+
const sig = get_request_signature(
|
|
35
68
|
url,
|
|
36
69
|
"GET",
|
|
37
70
|
"",
|
|
38
71
|
headers,
|
|
39
72
|
this.config.workspace_secret
|
|
40
73
|
);
|
|
41
|
-
headers["Authorization"] = `${this.config.workspace_key}:${
|
|
74
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
42
75
|
|
|
43
76
|
try {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
46
|
-
} catch (
|
|
77
|
+
const resp = await axios.get(url, { headers });
|
|
78
|
+
return resp.data;
|
|
79
|
+
} catch (error) {
|
|
47
80
|
throw new SuprsendApiError(err);
|
|
48
81
|
}
|
|
49
82
|
}
|
|
50
83
|
|
|
84
|
+
async upsert(distinct_id, payload = null) {
|
|
85
|
+
const url = this.detail_url(distinct_id);
|
|
86
|
+
payload = payload || {};
|
|
87
|
+
const headers = this.__get_headers();
|
|
88
|
+
const content_text = JSON.stringify(payload);
|
|
89
|
+
const sig = get_request_signature(
|
|
90
|
+
url,
|
|
91
|
+
"POST",
|
|
92
|
+
content_text,
|
|
93
|
+
headers,
|
|
94
|
+
this.config.workspace_secret
|
|
95
|
+
);
|
|
96
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const resp = await axios.post(url, content_text, { headers });
|
|
100
|
+
return resp.data;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new SuprsendApiError(err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async async_edit(edit_instance) {
|
|
107
|
+
if (!edit_instance) {
|
|
108
|
+
throw new InputValueError("instance is required");
|
|
109
|
+
}
|
|
110
|
+
edit_instance.validate_body();
|
|
111
|
+
const a_payload = edit_instance.get_async_payload();
|
|
112
|
+
edit_instance.validate_payload_size(a_payload);
|
|
113
|
+
|
|
114
|
+
const content_text = JSON.stringify(a_payload);
|
|
115
|
+
const url = `${this.config.base_url}event/`;
|
|
116
|
+
const headers = this.__get_headers();
|
|
117
|
+
const sig = get_request_signature(
|
|
118
|
+
url,
|
|
119
|
+
"POST",
|
|
120
|
+
content_text,
|
|
121
|
+
headers,
|
|
122
|
+
this.config.workspace_secret
|
|
123
|
+
);
|
|
124
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const resp = await axios.post(url, content_text, { headers });
|
|
128
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
status: "success",
|
|
132
|
+
status_code: resp.status,
|
|
133
|
+
message: resp.data,
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
throw new SuprsendApiError(resp.statusText);
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new SuprsendApiError(error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async edit(edit_ins_or_distinct_id, edit_payload) {
|
|
144
|
+
let payload, url;
|
|
145
|
+
if (edit_ins_or_distinct_id instanceof UserEdit) {
|
|
146
|
+
const edit_ins = edit_ins_or_distinct_id;
|
|
147
|
+
edit_ins.validate_body();
|
|
148
|
+
payload = edit_ins.get_payload();
|
|
149
|
+
url = this.detail_url(edit_ins.distinct_id);
|
|
150
|
+
} else {
|
|
151
|
+
const distinct_id = edit_ins_or_distinct_id;
|
|
152
|
+
payload = edit_payload || {};
|
|
153
|
+
url = this.detail_url(distinct_id);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const headers = this.__get_headers();
|
|
157
|
+
const content_text = JSON.stringify(payload);
|
|
158
|
+
// Signature and Authorization-header
|
|
159
|
+
const sig = get_request_signature(
|
|
160
|
+
url,
|
|
161
|
+
"PATCH",
|
|
162
|
+
content_text,
|
|
163
|
+
headers,
|
|
164
|
+
this.config.workspace_secret
|
|
165
|
+
);
|
|
166
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
const resp = await axios.patch(url, content_text, { headers });
|
|
170
|
+
return resp.data;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw new SuprsendApiError(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async merge(distinct_id, from_user_id) {
|
|
177
|
+
const url = `${this.detail_url(distinct_id)}merge/`;
|
|
178
|
+
const payload = { from_user_id: from_user_id };
|
|
179
|
+
const headers = this.__get_headers();
|
|
180
|
+
const content_text = JSON.stringify(payload);
|
|
181
|
+
const sig = get_request_signature(
|
|
182
|
+
url,
|
|
183
|
+
"POST",
|
|
184
|
+
content_text,
|
|
185
|
+
headers,
|
|
186
|
+
this.config.workspace_secret
|
|
187
|
+
);
|
|
188
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const resp = await axios.post(url, content_text, { headers });
|
|
192
|
+
return resp.data;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
throw new SuprsendApiError(error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
51
198
|
async delete(distinct_id) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
199
|
+
const url = this.detail_url(distinct_id);
|
|
200
|
+
const headers = this.__get_headers();
|
|
201
|
+
|
|
202
|
+
const sig = get_request_signature(
|
|
56
203
|
url,
|
|
57
204
|
"DELETE",
|
|
58
205
|
"",
|
|
59
206
|
headers,
|
|
60
207
|
this.config.workspace_secret
|
|
61
208
|
);
|
|
62
|
-
headers["Authorization"] = `${this.config.workspace_key}:${
|
|
209
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
63
210
|
|
|
64
211
|
try {
|
|
65
212
|
const response = await axios.delete(url, { headers });
|
|
@@ -68,17 +215,42 @@ export default class UsersApi {
|
|
|
68
215
|
} else {
|
|
69
216
|
throw new SuprsendApiError(response.statusText);
|
|
70
217
|
}
|
|
71
|
-
} catch (
|
|
72
|
-
throw new SuprsendApiError(
|
|
218
|
+
} catch (error) {
|
|
219
|
+
throw new SuprsendApiError(error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async bulk_delete(payload) {
|
|
224
|
+
payload = payload || {};
|
|
225
|
+
const url = this.bulk_url;
|
|
226
|
+
const headers = this.__get_headers();
|
|
227
|
+
const content_text = JSON.stringify(payload);
|
|
228
|
+
const sig = get_request_signature(
|
|
229
|
+
url,
|
|
230
|
+
"DELETE",
|
|
231
|
+
content_text,
|
|
232
|
+
headers,
|
|
233
|
+
this.config.workspace_secret
|
|
234
|
+
);
|
|
235
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
const resp = await axios.delete(url, { data: content_text, headers });
|
|
239
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
240
|
+
return { success: true, status_code: resp.status };
|
|
241
|
+
} else {
|
|
242
|
+
throw new SuprsendApiError(resp.statusText);
|
|
243
|
+
}
|
|
244
|
+
} catch (error) {
|
|
245
|
+
throw new SuprsendApiError(error);
|
|
73
246
|
}
|
|
74
247
|
}
|
|
75
248
|
|
|
76
249
|
async get_objects_subscribed_to(distinct_id, options = {}) {
|
|
77
|
-
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
78
250
|
const params = new URLSearchParams(options).toString();
|
|
79
|
-
const url = this.detail_url(
|
|
251
|
+
const url = this.detail_url(distinct_id);
|
|
80
252
|
const subscription_url = `${url}subscribed_to/object/?${params}`;
|
|
81
|
-
const headers = this.
|
|
253
|
+
const headers = this.__get_headers();
|
|
82
254
|
const signature = get_request_signature(
|
|
83
255
|
subscription_url,
|
|
84
256
|
"GET",
|
|
@@ -97,11 +269,10 @@ export default class UsersApi {
|
|
|
97
269
|
}
|
|
98
270
|
|
|
99
271
|
async get_lists_subscribed_to(distinct_id, options = {}) {
|
|
100
|
-
const validated_distinct_id = this.validate_distinct_id(distinct_id);
|
|
101
272
|
const params = new URLSearchParams(options).toString();
|
|
102
|
-
const url = this.detail_url(
|
|
273
|
+
const url = this.detail_url(distinct_id);
|
|
103
274
|
const subscription_url = `${url}subscribed_to/list/?${params}`;
|
|
104
|
-
const headers = this.
|
|
275
|
+
const headers = this.__get_headers();
|
|
105
276
|
const signature = get_request_signature(
|
|
106
277
|
subscription_url,
|
|
107
278
|
"GET",
|
|
@@ -118,4 +289,13 @@ export default class UsersApi {
|
|
|
118
289
|
throw new SuprsendApiError(err);
|
|
119
290
|
}
|
|
120
291
|
}
|
|
292
|
+
|
|
293
|
+
get_edit_instance(distinct_id) {
|
|
294
|
+
distinct_id = this._validate_distinct_id(distinct_id);
|
|
295
|
+
return new UserEdit(this.config, distinct_id);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
get_bulk_edit_instance() {
|
|
299
|
+
return new BulkUsersEdit(this.config);
|
|
300
|
+
}
|
|
121
301
|
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {
|
|
3
|
+
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
|
|
4
|
+
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
5
|
+
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
6
|
+
MAX_IDENTITY_EVENTS_IN_BULK_API,
|
|
7
|
+
} from "./constants";
|
|
8
|
+
import get_request_signature from "./signature";
|
|
9
|
+
import { invalid_record_json, uuid, InputValueError } from "./utils";
|
|
10
|
+
import { cloneDeep } from "lodash";
|
|
11
|
+
import BulkResponse from "./bulk_response";
|
|
12
|
+
import UserEdit from "./user_edit";
|
|
13
|
+
|
|
14
|
+
class _BulkUsersEditChunk {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this._chunk_apparent_size_in_bytes = BODY_MAX_APPARENT_SIZE_IN_BYTES;
|
|
17
|
+
this._max_records_in_chunk = MAX_IDENTITY_EVENTS_IN_BULK_API;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.__chunk = [];
|
|
20
|
+
this.__url = `${this.config.base_url}event/`;
|
|
21
|
+
this.__running_size = 0;
|
|
22
|
+
this.__running_length = 0;
|
|
23
|
+
this.response = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
__get_headers() {
|
|
27
|
+
return {
|
|
28
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
29
|
+
"User-Agent": this.config.user_agent,
|
|
30
|
+
Date: new Date().toUTCString(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
__add_event_to_chunk(event, event_size) {
|
|
35
|
+
this.__running_size += event_size;
|
|
36
|
+
this.__chunk.push(event);
|
|
37
|
+
this.__running_length += 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
__check_limit_reached() {
|
|
41
|
+
return (
|
|
42
|
+
this.__running_length >= this._max_records_in_chunk ||
|
|
43
|
+
this.__running_size >= this._chunk_apparent_size_in_bytes
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try_to_add_into_chunk(event, event_size) {
|
|
48
|
+
if (!event) return true;
|
|
49
|
+
if (this.__check_limit_reached()) return false;
|
|
50
|
+
|
|
51
|
+
if (event_size > IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
52
|
+
throw new InputValueError(
|
|
53
|
+
`Event too big - ${event_size} Bytes, ` +
|
|
54
|
+
`must not cross ${IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (this.__running_size + event_size > this._chunk_apparent_size_in_bytes) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.__add_event_to_chunk(event, event_size);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async trigger() {
|
|
67
|
+
const headers = this.__get_headers();
|
|
68
|
+
const content_text = JSON.stringify(this.__chunk);
|
|
69
|
+
|
|
70
|
+
const sig = get_request_signature(
|
|
71
|
+
this.__url,
|
|
72
|
+
"POST",
|
|
73
|
+
content_text,
|
|
74
|
+
headers,
|
|
75
|
+
this.config.workspace_secret
|
|
76
|
+
);
|
|
77
|
+
headers["Authorization"] = `${this.config.workspace_key}:${sig}`;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const resp = await axios.post(this.__url, content_text, { headers });
|
|
81
|
+
const ok_response = Math.floor(resp.status / 100) == 2;
|
|
82
|
+
if (ok_response) {
|
|
83
|
+
this.response = {
|
|
84
|
+
status: "success",
|
|
85
|
+
status_code: resp.status,
|
|
86
|
+
total: this.__chunk.length,
|
|
87
|
+
success: this.__chunk.length,
|
|
88
|
+
failure: 0,
|
|
89
|
+
failed_records: [],
|
|
90
|
+
};
|
|
91
|
+
} else {
|
|
92
|
+
this.response = {
|
|
93
|
+
status: "fail",
|
|
94
|
+
status_code: resp.status,
|
|
95
|
+
total: this.__chunk.length,
|
|
96
|
+
success: 0,
|
|
97
|
+
failure: this.__chunk.length,
|
|
98
|
+
failed_records: this.__chunk.map((item) => ({
|
|
99
|
+
record: item,
|
|
100
|
+
error: resp.statusText,
|
|
101
|
+
code: resp.status,
|
|
102
|
+
})),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
const error_status = err.status || 500;
|
|
107
|
+
this.response = {
|
|
108
|
+
status: "fail",
|
|
109
|
+
status_code: error_status,
|
|
110
|
+
total: this.__chunk.length,
|
|
111
|
+
success: 0,
|
|
112
|
+
failure: this.__chunk.length,
|
|
113
|
+
failed_records: this.__chunk.map((c) => ({
|
|
114
|
+
record: c,
|
|
115
|
+
error: error.message,
|
|
116
|
+
code: error_status,
|
|
117
|
+
})),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
class BulkUsersEdit {
|
|
124
|
+
constructor(config) {
|
|
125
|
+
this.config = config;
|
|
126
|
+
this.__users = [];
|
|
127
|
+
this.__pending_records = [];
|
|
128
|
+
this.__invalid_records = [];
|
|
129
|
+
this.chunks = [];
|
|
130
|
+
this.response = new BulkResponse();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
__validate_users() {
|
|
134
|
+
for (const u of this.__users) {
|
|
135
|
+
try {
|
|
136
|
+
const warnings_list = u.validate_body();
|
|
137
|
+
if (warnings_list) {
|
|
138
|
+
this.response.warnings = [
|
|
139
|
+
...this.response.warnings,
|
|
140
|
+
...warnings_list,
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
const pl = u.get_async_payload();
|
|
144
|
+
const [pl_json, pl_size] = u.validate_payload_size(pl);
|
|
145
|
+
this.__pending_records.push([pl_json, pl_size]);
|
|
146
|
+
} catch (ex) {
|
|
147
|
+
const inv_rec = invalid_record_json(u.as_json_async(), ex);
|
|
148
|
+
this.__invalid_records.push(inv_rec);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
__chunkify(start_idx = 0) {
|
|
154
|
+
const curr_chunk = new _BulkUsersEditChunk(this.config);
|
|
155
|
+
this.chunks.push(curr_chunk);
|
|
156
|
+
const entries = this.__pending_records.slice(start_idx).entries();
|
|
157
|
+
for (const [rel_idx, rec] of entries) {
|
|
158
|
+
const is_added = curr_chunk.try_to_add_into_chunk(rec[0], rec[1]);
|
|
159
|
+
if (!is_added) {
|
|
160
|
+
this.__chunkify(start_idx + rel_idx);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
append(...users) {
|
|
167
|
+
if (!users) return;
|
|
168
|
+
for (const u of users) {
|
|
169
|
+
if (u && u instanceof UserEdit) {
|
|
170
|
+
const u_copy = cloneDeep(u);
|
|
171
|
+
this.__users.push(u_copy);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async save() {
|
|
177
|
+
this.__validate_users();
|
|
178
|
+
|
|
179
|
+
if (this.__invalid_records.length > 0) {
|
|
180
|
+
const ch_response = BulkResponse.invalid_records_chunk_response(
|
|
181
|
+
this.__invalid_records
|
|
182
|
+
);
|
|
183
|
+
this.response.merge_chunk_response(ch_response);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (this.__pending_records.length > 0) {
|
|
187
|
+
this.__chunkify();
|
|
188
|
+
for (const [c_idx, ch] of this.chunks.entries()) {
|
|
189
|
+
if (this.config.req_log_level > 0) {
|
|
190
|
+
console.log(`DEBUG: triggering api call for chunk: ${c_idx}`);
|
|
191
|
+
}
|
|
192
|
+
// do api call
|
|
193
|
+
await ch.trigger();
|
|
194
|
+
// merge response
|
|
195
|
+
this.response.merge_chunk_response(ch.response);
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
// if no records. i.e. invalid_records.length and pending_records.length both are 0
|
|
199
|
+
// then add empty success response
|
|
200
|
+
if (this.__invalid_records.length === 0) {
|
|
201
|
+
this.response.merge_chunk_response(
|
|
202
|
+
BulkResponse.empty_chunk_success_response()
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return this.response;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export default BulkUsersEdit;
|
package/src/workflow.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import get_request_signature from "./signature";
|
|
3
3
|
import {
|
|
4
|
-
SuprsendError,
|
|
5
4
|
validate_workflow_body_schema,
|
|
6
5
|
get_apparent_workflow_body_size,
|
|
7
6
|
InputValueError,
|
|
8
7
|
} from "./utils";
|
|
9
8
|
import get_attachment_json from "./attachment";
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
11
|
+
BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
13
12
|
} from "./constants";
|
|
14
13
|
|
|
15
14
|
export default class Workflow {
|
|
@@ -68,9 +67,9 @@ export default class Workflow {
|
|
|
68
67
|
this.body,
|
|
69
68
|
is_part_of_bulk
|
|
70
69
|
); // review
|
|
71
|
-
if (apparent_size >
|
|
70
|
+
if (apparent_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
72
71
|
throw new InputValueError(
|
|
73
|
-
`workflow body too big - ${apparent_size} Bytes, must not cross ${
|
|
72
|
+
`workflow body too big - ${apparent_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
74
73
|
);
|
|
75
74
|
}
|
|
76
75
|
return [this.body, apparent_size];
|
package/src/workflow_request.js
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
} from "./utils";
|
|
6
6
|
import get_attachment_json from "./attachment";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
9
|
+
BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
10
10
|
} from "./constants";
|
|
11
11
|
|
|
12
12
|
export default class WorkflowTriggerRequest {
|
|
@@ -67,9 +67,9 @@ export default class WorkflowTriggerRequest {
|
|
|
67
67
|
this.body,
|
|
68
68
|
is_part_of_bulk
|
|
69
69
|
);
|
|
70
|
-
if (apparent_size >
|
|
70
|
+
if (apparent_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
71
71
|
throw new InputValueError(
|
|
72
|
-
`workflow body too big - ${apparent_size} Bytes, must not exceed ${
|
|
72
|
+
`workflow body too big - ${apparent_size} Bytes, must not exceed ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -5,8 +5,6 @@ import BulkResponse from "./bulk_response";
|
|
|
5
5
|
import { invalid_record_json, InputValueError } from "./utils";
|
|
6
6
|
import WorkflowTriggerRequest from "./workflow_request";
|
|
7
7
|
import {
|
|
8
|
-
SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
|
|
9
|
-
SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
10
8
|
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
11
9
|
BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
12
10
|
MAX_WORKFLOWS_IN_BULK_API,
|
|
@@ -58,9 +56,9 @@ export class _BulkWorkflowTriggerChunk {
|
|
|
58
56
|
if (this._check_limit_reached()) {
|
|
59
57
|
return false;
|
|
60
58
|
}
|
|
61
|
-
if (body_size >
|
|
59
|
+
if (body_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
62
60
|
throw new InputValueError(
|
|
63
|
-
`workflow body too big - ${body_size} Bytes, must not exceed ${
|
|
61
|
+
`workflow body too big - ${body_size} Bytes, must not exceed ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
64
62
|
);
|
|
65
63
|
}
|
|
66
64
|
if (
|
package/src/workflows_bulk.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
|
|
3
|
-
SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
4
2
|
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
5
3
|
BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
6
4
|
MAX_WORKFLOWS_IN_BULK_API,
|
|
7
5
|
ALLOW_ATTACHMENTS_IN_BULK_API,
|
|
8
6
|
} from "./constants";
|
|
9
|
-
import {
|
|
7
|
+
import { invalid_record_json, InputValueError } from "./utils";
|
|
10
8
|
import Workflow from "./workflow";
|
|
11
9
|
import { cloneDeep } from "lodash";
|
|
12
10
|
import axios from "axios";
|
|
@@ -77,9 +75,9 @@ class _BulkWorkflowsChunk {
|
|
|
77
75
|
if (this.__check_limit_reached()) {
|
|
78
76
|
return false;
|
|
79
77
|
}
|
|
80
|
-
if (body_size >
|
|
78
|
+
if (body_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
81
79
|
throw new InputValueError(
|
|
82
|
-
`workflow body too big - ${body_size} Bytes, must not cross ${
|
|
80
|
+
`workflow body too big - ${body_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
|
|
83
81
|
);
|
|
84
82
|
}
|
|
85
83
|
if (this.__running_size + body_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|