@suprsend/node-sdk 1.2.0 → 1.4.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/README.md +1 -1
- package/dist/constants.js +2 -2
- package/dist/event.js +15 -29
- package/dist/events_bulk.js +13 -27
- package/dist/index.js +4 -6
- package/dist/request_json/list_broadcast.json +19 -0
- package/dist/subscriber.js +30 -92
- package/dist/subscriber_helper.js +43 -76
- package/dist/{subscribers_list.js → subscriber_list.js} +94 -61
- package/dist/subscribers_bulk.js +35 -63
- package/dist/workflow.js +15 -30
- package/dist/workflows_bulk.js +13 -28
- package/package.json +1 -1
- package/src/constants.js +2 -2
- package/src/event.js +10 -20
- package/src/events_bulk.js +11 -20
- package/src/index.js +3 -8
- package/src/request_json/list_broadcast.json +19 -0
- package/src/subscriber.js +27 -63
- package/src/subscriber_helper.js +36 -77
- package/src/{subscribers_list.js → subscriber_list.js} +53 -53
- package/src/subscribers_bulk.js +15 -28
- package/src/workflow.js +10 -20
- package/src/workflows_bulk.js +11 -21
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
14
14
|
} from "./constants";
|
|
15
15
|
|
|
16
|
-
class
|
|
16
|
+
class SubscriberListBroadcast {
|
|
17
17
|
constructor(body, kwargs = {}) {
|
|
18
18
|
if (!(body instanceof Object)) {
|
|
19
19
|
throw new SuprsendError("broadcast body must be a json/dictionary");
|
|
@@ -43,7 +43,7 @@ class SubscribersListBroadcast {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
class
|
|
46
|
+
class SubscriberListsApi {
|
|
47
47
|
constructor(config) {
|
|
48
48
|
this.config = config;
|
|
49
49
|
this.subscriber_list_url = `${this.config.base_url}v1/subscriber_list/`;
|
|
@@ -241,56 +241,56 @@ class SubscribersListApi {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
244
|
+
async broadcast(broadcast_instance) {
|
|
245
|
+
if (!(broadcast_instance instanceof SubscriberListBroadcast)) {
|
|
246
|
+
throw new SuprsendError(
|
|
247
|
+
"argument must be an instance of suprsend.SubscriberListBroadcast"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
const [broadcast_body, body_size] = broadcast_instance.get_final_json(
|
|
251
|
+
this.config
|
|
252
|
+
);
|
|
253
|
+
const headers = { ...this.__headers, ...this.__dynamic_headers() };
|
|
254
|
+
const content_text = JSON.stringify(broadcast_body);
|
|
255
|
+
|
|
256
|
+
const signature = get_request_signature(
|
|
257
|
+
this.broadcast_url,
|
|
258
|
+
"POST",
|
|
259
|
+
content_text,
|
|
260
|
+
headers,
|
|
261
|
+
this.config.workspace_secret
|
|
262
|
+
);
|
|
263
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
const response = await axios.post(this.broadcast_url, content_text, {
|
|
267
|
+
headers,
|
|
268
|
+
});
|
|
269
|
+
const ok_response = Math.floor(response.status / 100) == 2;
|
|
270
|
+
if (ok_response) {
|
|
271
|
+
return {
|
|
272
|
+
success: true,
|
|
273
|
+
status: "success",
|
|
274
|
+
status_code: response.status,
|
|
275
|
+
message: response.statusText,
|
|
276
|
+
};
|
|
277
|
+
} else {
|
|
278
|
+
return {
|
|
279
|
+
success: false,
|
|
280
|
+
status: "fail",
|
|
281
|
+
status_code: response.status,
|
|
282
|
+
message: response.statusText,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
} catch (err) {
|
|
286
|
+
return {
|
|
287
|
+
success: false,
|
|
288
|
+
status: "fail",
|
|
289
|
+
status_code: err.status || 500,
|
|
290
|
+
message: err.message,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
export {
|
|
296
|
+
export { SubscriberListsApi, SubscriberListBroadcast };
|
package/src/subscribers_bulk.js
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
|
|
3
3
|
IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
4
4
|
BODY_MAX_APPARENT_SIZE_IN_BYTES,
|
|
5
|
-
BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
|
|
6
5
|
MAX_IDENTITY_EVENTS_IN_BULK_API,
|
|
7
6
|
} from "./constants";
|
|
8
7
|
import get_request_signature from "./signature";
|
|
@@ -34,16 +33,7 @@ class _BulkSubscribersChunk {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
__get_url() {
|
|
37
|
-
|
|
38
|
-
if (this.config.include_signature_param) {
|
|
39
|
-
if (this.config.auth_enabled) {
|
|
40
|
-
url_template = url_template + "?verify=true";
|
|
41
|
-
} else {
|
|
42
|
-
url_template = url_template + "?verify=false";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const url_formatted = `${this.config.base_url}${url_template}`;
|
|
46
|
-
return url_formatted;
|
|
36
|
+
return `${this.config.base_url}event/`;
|
|
47
37
|
}
|
|
48
38
|
|
|
49
39
|
__common_headers() {
|
|
@@ -100,17 +90,16 @@ class _BulkSubscribersChunk {
|
|
|
100
90
|
async trigger() {
|
|
101
91
|
const headers = { ...this.__headers, ...this.__dynamic_headers() };
|
|
102
92
|
const content_text = JSON.stringify(this.__chunk);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
93
|
+
|
|
94
|
+
const signature = get_request_signature(
|
|
95
|
+
this.__url,
|
|
96
|
+
"POST",
|
|
97
|
+
content_text,
|
|
98
|
+
headers,
|
|
99
|
+
this.config.workspace_secret
|
|
100
|
+
);
|
|
101
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
102
|
+
|
|
114
103
|
try {
|
|
115
104
|
const response = await axios.post(this.__url, content_text, { headers });
|
|
116
105
|
const ok_response = Math.floor(response.status / 100) == 2;
|
|
@@ -175,11 +164,9 @@ class BulkSubscribers {
|
|
|
175
164
|
if (warnings_list) {
|
|
176
165
|
this.response.warnings = [...this.response.warnings, ...warnings_list];
|
|
177
166
|
}
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.__pending_records.push([ev_json, body_size]);
|
|
182
|
-
}
|
|
167
|
+
const ev = sub.get_events();
|
|
168
|
+
const [ev_json, body_size] = sub.validate_event_size(ev);
|
|
169
|
+
this.__pending_records.push([ev_json, body_size]);
|
|
183
170
|
}
|
|
184
171
|
}
|
|
185
172
|
|
|
@@ -204,7 +191,7 @@ class BulkSubscribers {
|
|
|
204
191
|
}
|
|
205
192
|
for (let sub of subscribers) {
|
|
206
193
|
if (!sub) {
|
|
207
|
-
|
|
194
|
+
continue;
|
|
208
195
|
}
|
|
209
196
|
if (!(sub instanceof Subscriber)) {
|
|
210
197
|
throw new SuprsendError(
|
package/src/workflow.js
CHANGED
|
@@ -71,16 +71,7 @@ export class _WorkflowTrigger {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
_get_url() {
|
|
74
|
-
|
|
75
|
-
if (this.config.include_signature_param) {
|
|
76
|
-
if (this.config.auth_enabled) {
|
|
77
|
-
url_template = url_template + "?verify=true";
|
|
78
|
-
} else {
|
|
79
|
-
url_template = url_template + "?verify=false";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const url_formatted = `${this.config.base_url}${this.config.workspace_key}${url_template}`;
|
|
83
|
-
return url_formatted;
|
|
74
|
+
return `${this.config.base_url}${this.config.workspace_key}/trigger/`;
|
|
84
75
|
}
|
|
85
76
|
|
|
86
77
|
_get_headers() {
|
|
@@ -103,16 +94,15 @@ export class _WorkflowTrigger {
|
|
|
103
94
|
async send(workflow_body) {
|
|
104
95
|
const headers = this._get_headers();
|
|
105
96
|
const content_text = JSON.stringify(workflow_body);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
97
|
+
|
|
98
|
+
const signature = get_request_signature(
|
|
99
|
+
this.url,
|
|
100
|
+
"POST",
|
|
101
|
+
content_text,
|
|
102
|
+
headers,
|
|
103
|
+
this.config.workspace_secret
|
|
104
|
+
);
|
|
105
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
116
106
|
|
|
117
107
|
try {
|
|
118
108
|
const response = await axios.post(this.url, content_text, { headers });
|
package/src/workflows_bulk.js
CHANGED
|
@@ -36,16 +36,7 @@ class _BulkWorkflowsChunk {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
__get_url() {
|
|
39
|
-
|
|
40
|
-
if (this.config.include_signature_param) {
|
|
41
|
-
if (this.config.auth_enabled) {
|
|
42
|
-
url_template = url_template + "?verify=true";
|
|
43
|
-
} else {
|
|
44
|
-
url_template = url_template + "?verify=false";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const url_formatted = `${this.config.base_url}${this.config.workspace_key}${url_template}`;
|
|
48
|
-
return url_formatted;
|
|
39
|
+
return `${this.config.base_url}${this.config.workspace_key}/trigger/`;
|
|
49
40
|
}
|
|
50
41
|
|
|
51
42
|
__common_headers() {
|
|
@@ -105,17 +96,16 @@ class _BulkWorkflowsChunk {
|
|
|
105
96
|
async trigger() {
|
|
106
97
|
const headers = { ...this.__headers, ...this.__dynamic_headers() };
|
|
107
98
|
const content_text = JSON.stringify(this.__chunk);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
99
|
+
|
|
100
|
+
const signature = get_request_signature(
|
|
101
|
+
this.__url,
|
|
102
|
+
"POST",
|
|
103
|
+
content_text,
|
|
104
|
+
headers,
|
|
105
|
+
this.config.workspace_secret
|
|
106
|
+
);
|
|
107
|
+
headers["Authorization"] = `${this.config.workspace_key}:${signature}`;
|
|
108
|
+
|
|
119
109
|
try {
|
|
120
110
|
const response = await axios.post(this.__url, content_text, { headers });
|
|
121
111
|
const ok_response = Math.floor(response.status / 100) == 2;
|