@suprsend/node-sdk 1.1.2 → 1.3.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 -2
- package/dist/event.js +15 -29
- package/dist/events_bulk.js +13 -27
- package/dist/index.js +9 -2
- package/dist/request_json/list_broadcast.json +70 -0
- package/dist/subscriber.js +30 -92
- package/dist/subscriber_helper.js +43 -76
- package/dist/subscribers_bulk.js +35 -63
- package/dist/subscribers_list.js +484 -0
- package/dist/utils.js +32 -1
- 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 +6 -3
- package/src/request_json/list_broadcast.json +70 -0
- package/src/subscriber.js +27 -63
- package/src/subscriber_helper.js +36 -77
- package/src/subscribers_bulk.js +15 -28
- package/src/subscribers_list.js +296 -0
- package/src/utils.js +26 -1
- package/src/workflow.js +10 -20
- package/src/workflows_bulk.js +11 -21
|
@@ -40,13 +40,9 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
40
40
|
this.distinct_id = distinct_id;
|
|
41
41
|
this.workspace_key = workspace_key;
|
|
42
42
|
this.__dict_set = {};
|
|
43
|
-
this.__set_count = 0;
|
|
44
43
|
this.__dict_append = {};
|
|
45
|
-
this.__append_count = 0;
|
|
46
44
|
this.__dict_remove = {};
|
|
47
|
-
this.__remove_count = 0;
|
|
48
45
|
this.__list_unset = [];
|
|
49
|
-
this.__unset_count = 0;
|
|
50
46
|
this.__errors = [];
|
|
51
47
|
this.__info = [];
|
|
52
48
|
}
|
|
@@ -55,13 +51,9 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
55
51
|
key: "reset",
|
|
56
52
|
value: function reset() {
|
|
57
53
|
this.__dict_set = {};
|
|
58
|
-
this.__set_count = 0;
|
|
59
54
|
this.__dict_append = {};
|
|
60
|
-
this.__append_count = 0;
|
|
61
55
|
this.__dict_remove = {};
|
|
62
|
-
this.__remove_count = 0;
|
|
63
56
|
this.__list_unset = [];
|
|
64
|
-
this.__unset_count = 0;
|
|
65
57
|
this.__errors = [];
|
|
66
58
|
this.__info = [];
|
|
67
59
|
}
|
|
@@ -73,11 +65,7 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
73
65
|
var ret_val = {
|
|
74
66
|
errors: this.__errors,
|
|
75
67
|
info: this.__info,
|
|
76
|
-
event: evt
|
|
77
|
-
set: this.__set_count,
|
|
78
|
-
append: this.__append_count,
|
|
79
|
-
remove: this.__remove_count,
|
|
80
|
-
unset: this.__unset_count
|
|
68
|
+
event: evt
|
|
81
69
|
};
|
|
82
70
|
this.reset();
|
|
83
71
|
return ret_val;
|
|
@@ -85,38 +73,25 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
85
73
|
}, {
|
|
86
74
|
key: "__form_event",
|
|
87
75
|
value: function __form_event() {
|
|
88
|
-
|
|
89
|
-
var event = {
|
|
90
|
-
$insert_id: (0, _utils.uuid)(),
|
|
91
|
-
$time: (0, _utils.epoch_milliseconds)(),
|
|
92
|
-
env: this.workspace_key,
|
|
93
|
-
distinct_id: this.distinct_id
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (!(0, _utils.is_empty)(this.__dict_set)) {
|
|
97
|
-
event["$set"] = this.__dict_set;
|
|
98
|
-
this.__set_count += 1;
|
|
99
|
-
}
|
|
76
|
+
var event = {};
|
|
100
77
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
78
|
+
if (!(0, _utils.is_empty)(this.__dict_set)) {
|
|
79
|
+
event["$set"] = this.__dict_set;
|
|
80
|
+
}
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
82
|
+
if (!(0, _utils.is_empty)(this.__dict_append)) {
|
|
83
|
+
event["$append"] = this.__dict_append;
|
|
84
|
+
}
|
|
110
85
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
86
|
+
if (!(0, _utils.is_empty)(this.__dict_remove)) {
|
|
87
|
+
event["$remove"] = this.__dict_remove;
|
|
88
|
+
}
|
|
115
89
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return;
|
|
90
|
+
if (!(0, _utils.is_empty)(this.__list_unset)) {
|
|
91
|
+
event["$unset"] = this.__list_unset;
|
|
119
92
|
}
|
|
93
|
+
|
|
94
|
+
return event;
|
|
120
95
|
}
|
|
121
96
|
}, {
|
|
122
97
|
key: "__validate_key_basic",
|
|
@@ -235,46 +210,36 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
235
210
|
}, {
|
|
236
211
|
key: "__add_identity",
|
|
237
212
|
value: function __add_identity(key, value, args, caller) {
|
|
213
|
+
var new_caller = "".concat(caller, ":").concat(key);
|
|
214
|
+
|
|
238
215
|
switch (key) {
|
|
239
216
|
case IDENT_KEY_EMAIL:
|
|
240
|
-
this._add_email(value,
|
|
217
|
+
this._add_email(value, new_caller);
|
|
241
218
|
|
|
242
219
|
break;
|
|
243
220
|
|
|
244
221
|
case IDENT_KEY_SMS:
|
|
245
|
-
this._add_sms(value,
|
|
222
|
+
this._add_sms(value, new_caller);
|
|
246
223
|
|
|
247
224
|
break;
|
|
248
225
|
|
|
249
226
|
case IDENT_KEY_WHATSAPP:
|
|
250
|
-
this._add_whatsapp(value,
|
|
227
|
+
this._add_whatsapp(value, new_caller);
|
|
251
228
|
|
|
252
229
|
break;
|
|
253
230
|
|
|
254
231
|
case IDENT_KEY_ANDROIDPUSH:
|
|
255
|
-
this._add_androidpush(value, args[KEY_PUSHVENDOR],
|
|
256
|
-
|
|
257
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
258
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
259
|
-
}
|
|
232
|
+
this._add_androidpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
260
233
|
|
|
261
234
|
break;
|
|
262
235
|
|
|
263
236
|
case IDENT_KEY_IOSPUSH:
|
|
264
|
-
this._add_iospush(value, args[KEY_PUSHVENDOR],
|
|
265
|
-
|
|
266
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
267
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
268
|
-
}
|
|
237
|
+
this._add_iospush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
269
238
|
|
|
270
239
|
break;
|
|
271
240
|
|
|
272
241
|
case IDENT_KEY_WEBPUSH:
|
|
273
|
-
this._add_webpush(value, args[KEY_PUSHVENDOR],
|
|
274
|
-
|
|
275
|
-
if (this.__dict_append[KEY_PUSHVENDOR]) {
|
|
276
|
-
args[KEY_PUSHVENDOR] = this.__dict_append[KEY_PUSHVENDOR];
|
|
277
|
-
}
|
|
242
|
+
this._add_webpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
278
243
|
|
|
279
244
|
break;
|
|
280
245
|
|
|
@@ -290,46 +255,36 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
290
255
|
}, {
|
|
291
256
|
key: "__remove_identity",
|
|
292
257
|
value: function __remove_identity(key, value, args, caller) {
|
|
258
|
+
var new_caller = "".concat(caller, ":").concat(key);
|
|
259
|
+
|
|
293
260
|
switch (key) {
|
|
294
261
|
case IDENT_KEY_EMAIL:
|
|
295
|
-
this._remove_email(value,
|
|
262
|
+
this._remove_email(value, new_caller);
|
|
296
263
|
|
|
297
264
|
break;
|
|
298
265
|
|
|
299
266
|
case IDENT_KEY_SMS:
|
|
300
|
-
this._remove_sms(value,
|
|
267
|
+
this._remove_sms(value, new_caller);
|
|
301
268
|
|
|
302
269
|
break;
|
|
303
270
|
|
|
304
271
|
case IDENT_KEY_WHATSAPP:
|
|
305
|
-
this._remove_whatsapp(value,
|
|
272
|
+
this._remove_whatsapp(value, new_caller);
|
|
306
273
|
|
|
307
274
|
break;
|
|
308
275
|
|
|
309
276
|
case IDENT_KEY_ANDROIDPUSH:
|
|
310
|
-
this._remove_androidpush(value, args[KEY_PUSHVENDOR],
|
|
311
|
-
|
|
312
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
313
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
314
|
-
}
|
|
277
|
+
this._remove_androidpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
315
278
|
|
|
316
279
|
break;
|
|
317
280
|
|
|
318
281
|
case IDENT_KEY_IOSPUSH:
|
|
319
|
-
this._remove_iospush(value, args[KEY_PUSHVENDOR],
|
|
320
|
-
|
|
321
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
322
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
323
|
-
}
|
|
282
|
+
this._remove_iospush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
324
283
|
|
|
325
284
|
break;
|
|
326
285
|
|
|
327
286
|
case IDENT_KEY_WEBPUSH:
|
|
328
|
-
this._remove_webpush(value, args[KEY_PUSHVENDOR],
|
|
329
|
-
|
|
330
|
-
if (this.__dict_remove[KEY_PUSHVENDOR]) {
|
|
331
|
-
args[KEY_PUSHVENDOR] = this.__dict_remove[KEY_PUSHVENDOR];
|
|
332
|
-
}
|
|
287
|
+
this._remove_webpush(value, args[KEY_PUSHVENDOR], new_caller);
|
|
333
288
|
|
|
334
289
|
break;
|
|
335
290
|
|
|
@@ -527,6 +482,10 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
527
482
|
provider = "fcm";
|
|
528
483
|
}
|
|
529
484
|
|
|
485
|
+
if (typeof provider === "string") {
|
|
486
|
+
provider = provider.toLocaleLowerCase();
|
|
487
|
+
}
|
|
488
|
+
|
|
530
489
|
if (!["fcm", "xiaomi", "oppo"].includes(provider)) {
|
|
531
490
|
this.__errors.push("[".concat(caller, "] unsupported androidpush provider ").concat(provider));
|
|
532
491
|
|
|
@@ -590,6 +549,10 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
590
549
|
provider = "apns";
|
|
591
550
|
}
|
|
592
551
|
|
|
552
|
+
if (typeof provider === "string") {
|
|
553
|
+
provider = provider.toLocaleLowerCase();
|
|
554
|
+
}
|
|
555
|
+
|
|
593
556
|
if (!["apns"].includes(provider)) {
|
|
594
557
|
this.__errors.push("[".concat(caller, "] unsupported iospush provider ").concat(provider));
|
|
595
558
|
|
|
@@ -650,6 +613,10 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
650
613
|
provider = "vapid";
|
|
651
614
|
}
|
|
652
615
|
|
|
616
|
+
if (typeof provider === "string") {
|
|
617
|
+
provider = provider.toLocaleLowerCase();
|
|
618
|
+
}
|
|
619
|
+
|
|
653
620
|
if (!["vapid"].includes(provider)) {
|
|
654
621
|
this.__errors.push("[".concat(caller, "] unsupported webpush provider ").concat(provider));
|
|
655
622
|
|
package/dist/subscribers_bulk.js
CHANGED
|
@@ -75,18 +75,7 @@ var _BulkSubscribersChunk = /*#__PURE__*/function () {
|
|
|
75
75
|
(0, _createClass2["default"])(_BulkSubscribersChunk, [{
|
|
76
76
|
key: "__get_url",
|
|
77
77
|
value: function __get_url() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (this.config.include_signature_param) {
|
|
81
|
-
if (this.config.auth_enabled) {
|
|
82
|
-
url_template = url_template + "?verify=true";
|
|
83
|
-
} else {
|
|
84
|
-
url_template = url_template + "?verify=false";
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var url_formatted = "".concat(this.config.base_url).concat(url_template);
|
|
89
|
-
return url_formatted;
|
|
78
|
+
return "".concat(this.config.base_url, "event/");
|
|
90
79
|
}
|
|
91
80
|
}, {
|
|
92
81
|
key: "__common_headers",
|
|
@@ -155,20 +144,16 @@ var _BulkSubscribersChunk = /*#__PURE__*/function () {
|
|
|
155
144
|
switch (_context.prev = _context.next) {
|
|
156
145
|
case 0:
|
|
157
146
|
headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
|
|
158
|
-
content_text = JSON.stringify(this.__chunk);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_context.prev = 3;
|
|
166
|
-
_context.next = 6;
|
|
147
|
+
content_text = JSON.stringify(this.__chunk);
|
|
148
|
+
signature = (0, _signature["default"])(this.__url, "POST", content_text, headers, this.config.workspace_secret);
|
|
149
|
+
headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
|
|
150
|
+
_context.prev = 4;
|
|
151
|
+
_context.next = 7;
|
|
167
152
|
return _axios["default"].post(this.__url, content_text, {
|
|
168
153
|
headers: headers
|
|
169
154
|
});
|
|
170
155
|
|
|
171
|
-
case
|
|
156
|
+
case 7:
|
|
172
157
|
response = _context.sent;
|
|
173
158
|
ok_response = Math.floor(response.status / 100) == 2;
|
|
174
159
|
|
|
@@ -198,12 +183,12 @@ var _BulkSubscribersChunk = /*#__PURE__*/function () {
|
|
|
198
183
|
};
|
|
199
184
|
}
|
|
200
185
|
|
|
201
|
-
_context.next =
|
|
186
|
+
_context.next = 16;
|
|
202
187
|
break;
|
|
203
188
|
|
|
204
|
-
case
|
|
205
|
-
_context.prev =
|
|
206
|
-
_context.t0 = _context["catch"](
|
|
189
|
+
case 12:
|
|
190
|
+
_context.prev = 12;
|
|
191
|
+
_context.t0 = _context["catch"](4);
|
|
207
192
|
error_status = _context.t0.status || 500;
|
|
208
193
|
return _context.abrupt("return", {
|
|
209
194
|
status: "fail",
|
|
@@ -221,12 +206,12 @@ var _BulkSubscribersChunk = /*#__PURE__*/function () {
|
|
|
221
206
|
})
|
|
222
207
|
});
|
|
223
208
|
|
|
224
|
-
case
|
|
209
|
+
case 16:
|
|
225
210
|
case "end":
|
|
226
211
|
return _context.stop();
|
|
227
212
|
}
|
|
228
213
|
}
|
|
229
|
-
}, _callee, this, [[
|
|
214
|
+
}, _callee, this, [[4, 12]]);
|
|
230
215
|
}));
|
|
231
216
|
|
|
232
217
|
function trigger() {
|
|
@@ -269,27 +254,14 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
269
254
|
this.response.warnings = [].concat((0, _toConsumableArray2["default"])(this.response.warnings), (0, _toConsumableArray2["default"])(warnings_list));
|
|
270
255
|
}
|
|
271
256
|
|
|
272
|
-
var
|
|
273
|
-
|
|
274
|
-
var _iterator2 = _createForOfIteratorHelper(ev_arr),
|
|
275
|
-
_step2;
|
|
257
|
+
var ev = sub.get_events();
|
|
276
258
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
259
|
+
var _sub$validate_event_s = sub.validate_event_size(ev),
|
|
260
|
+
_sub$validate_event_s2 = (0, _slicedToArray2["default"])(_sub$validate_event_s, 2),
|
|
261
|
+
ev_json = _sub$validate_event_s2[0],
|
|
262
|
+
body_size = _sub$validate_event_s2[1];
|
|
280
263
|
|
|
281
|
-
|
|
282
|
-
_sub$validate_event_s2 = (0, _slicedToArray2["default"])(_sub$validate_event_s, 2),
|
|
283
|
-
ev_json = _sub$validate_event_s2[0],
|
|
284
|
-
body_size = _sub$validate_event_s2[1];
|
|
285
|
-
|
|
286
|
-
this.__pending_records.push([ev_json, body_size]);
|
|
287
|
-
}
|
|
288
|
-
} catch (err) {
|
|
289
|
-
_iterator2.e(err);
|
|
290
|
-
} finally {
|
|
291
|
-
_iterator2.f();
|
|
292
|
-
}
|
|
264
|
+
this.__pending_records.push([ev_json, body_size]);
|
|
293
265
|
}
|
|
294
266
|
} catch (err) {
|
|
295
267
|
_iterator.e(err);
|
|
@@ -306,14 +278,14 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
306
278
|
|
|
307
279
|
var entries = this.__pending_records.slice(start_idx).entries();
|
|
308
280
|
|
|
309
|
-
var
|
|
310
|
-
|
|
281
|
+
var _iterator2 = _createForOfIteratorHelper(entries),
|
|
282
|
+
_step2;
|
|
311
283
|
|
|
312
284
|
try {
|
|
313
|
-
for (
|
|
314
|
-
var
|
|
315
|
-
rel_idx =
|
|
316
|
-
rec =
|
|
285
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
286
|
+
var _step2$value = (0, _slicedToArray2["default"])(_step2.value, 2),
|
|
287
|
+
rel_idx = _step2$value[0],
|
|
288
|
+
rec = _step2$value[1];
|
|
317
289
|
|
|
318
290
|
var is_added = curr_chunk.try_to_add_into_chunk(rec[0], rec[1]);
|
|
319
291
|
|
|
@@ -326,9 +298,9 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
326
298
|
}
|
|
327
299
|
}
|
|
328
300
|
} catch (err) {
|
|
329
|
-
|
|
301
|
+
_iterator2.e(err);
|
|
330
302
|
} finally {
|
|
331
|
-
|
|
303
|
+
_iterator2.f();
|
|
332
304
|
}
|
|
333
305
|
}
|
|
334
306
|
}, {
|
|
@@ -346,7 +318,7 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
346
318
|
var sub = _subscribers[_i];
|
|
347
319
|
|
|
348
320
|
if (!sub) {
|
|
349
|
-
|
|
321
|
+
continue;
|
|
350
322
|
}
|
|
351
323
|
|
|
352
324
|
if (!(sub instanceof _subscriber.Subscriber)) {
|
|
@@ -367,7 +339,7 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
367
339
|
key: "save",
|
|
368
340
|
value: function () {
|
|
369
341
|
var _save = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
370
|
-
var
|
|
342
|
+
var _iterator3, _step3, _step3$value, c_idx, ch;
|
|
371
343
|
|
|
372
344
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
373
345
|
while (1) {
|
|
@@ -377,18 +349,18 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
377
349
|
|
|
378
350
|
this.__chunkify();
|
|
379
351
|
|
|
380
|
-
|
|
352
|
+
_iterator3 = _createForOfIteratorHelper(this.chunks.entries());
|
|
381
353
|
_context2.prev = 3;
|
|
382
354
|
|
|
383
|
-
|
|
355
|
+
_iterator3.s();
|
|
384
356
|
|
|
385
357
|
case 5:
|
|
386
|
-
if ((
|
|
358
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
387
359
|
_context2.next = 13;
|
|
388
360
|
break;
|
|
389
361
|
}
|
|
390
362
|
|
|
391
|
-
|
|
363
|
+
_step3$value = (0, _slicedToArray2["default"])(_step3.value, 2), c_idx = _step3$value[0], ch = _step3$value[1];
|
|
392
364
|
|
|
393
365
|
if (this.config.req_log_level > 0) {
|
|
394
366
|
console.log("DEBUG: triggering api call for chunk: ".concat(c_idx));
|
|
@@ -414,12 +386,12 @@ var BulkSubscribers = /*#__PURE__*/function () {
|
|
|
414
386
|
_context2.prev = 15;
|
|
415
387
|
_context2.t0 = _context2["catch"](3);
|
|
416
388
|
|
|
417
|
-
|
|
389
|
+
_iterator3.e(_context2.t0);
|
|
418
390
|
|
|
419
391
|
case 18:
|
|
420
392
|
_context2.prev = 18;
|
|
421
393
|
|
|
422
|
-
|
|
394
|
+
_iterator3.f();
|
|
423
395
|
|
|
424
396
|
return _context2.finish(18);
|
|
425
397
|
|