@suprsend/node-sdk 1.7.0 → 1.8.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/attachment.js +21 -12
- package/dist/bulk_response.js +24 -0
- package/dist/event.js +55 -19
- package/dist/events_bulk.js +63 -43
- package/dist/index.js +4 -4
- package/dist/subscriber.js +22 -8
- package/dist/subscriber_list.js +56 -5
- package/dist/subscribers_bulk.js +70 -48
- package/dist/utils.js +41 -3
- package/dist/workflow.js +34 -7
- package/dist/workflows_bulk.js +60 -46
- package/package.json +1 -1
- package/src/attachment.js +23 -11
- package/src/bulk_response.js +22 -0
- package/src/event.js +50 -14
- package/src/events_bulk.js +45 -32
- package/src/index.js +7 -5
- package/src/subscriber.js +20 -8
- package/src/subscriber_list.js +50 -3
- package/src/subscribers_bulk.js +50 -30
- package/src/utils.js +21 -2
- package/src/workflow.js +26 -6
- package/src/workflows_bulk.js +42 -34
- package/types/index.d.ts +5 -0
package/dist/attachment.js
CHANGED
|
@@ -19,21 +19,30 @@ function check_is_web_url() {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function get_attachment_json_for_file(file_path, file_name, ignore_if_error) {
|
|
22
|
-
|
|
22
|
+
try {
|
|
23
|
+
var abs_path = _path["default"].resolve((0, _utils.resolveTilde)(file_path));
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
var final_file_name = _path["default"].basename(abs_path);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (file_name && file_name.trim()) {
|
|
28
|
+
final_file_name = file_name.trim();
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
return {
|
|
32
|
+
filename: final_file_name,
|
|
33
|
+
contentType: _mimeTypes["default"].lookup(abs_path),
|
|
34
|
+
data: (0, _utils.base64Encode)(abs_path),
|
|
35
|
+
url: null,
|
|
36
|
+
ignore_if_error: ignore_if_error
|
|
37
|
+
};
|
|
38
|
+
} catch (ex) {
|
|
39
|
+
if (ignore_if_error) {
|
|
40
|
+
console.log("WARNING: ignoring error while processing attachment file.", ex);
|
|
41
|
+
return;
|
|
42
|
+
} else {
|
|
43
|
+
throw ex;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
function get_attachment_json_for_url(file_url, file_name, ignore_if_error) {
|
package/dist/bulk_response.js
CHANGED
|
@@ -52,6 +52,30 @@ var BulkResponse = /*#__PURE__*/function () {
|
|
|
52
52
|
var failed_recs = ch_resp.failed_records || [];
|
|
53
53
|
this.failed_records = [].concat((0, _toConsumableArray2["default"])(this.failed_records), (0, _toConsumableArray2["default"])(failed_recs));
|
|
54
54
|
}
|
|
55
|
+
}], [{
|
|
56
|
+
key: "empty_chunk_success_response",
|
|
57
|
+
value: function empty_chunk_success_response() {
|
|
58
|
+
return {
|
|
59
|
+
status: "success",
|
|
60
|
+
status_code: 200,
|
|
61
|
+
total: 0,
|
|
62
|
+
success: 0,
|
|
63
|
+
failure: 0,
|
|
64
|
+
failed_records: []
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "invalid_records_chunk_response",
|
|
69
|
+
value: function invalid_records_chunk_response(invalid_records) {
|
|
70
|
+
return {
|
|
71
|
+
status: "fail",
|
|
72
|
+
status_code: 500,
|
|
73
|
+
total: invalid_records.length,
|
|
74
|
+
success: 0,
|
|
75
|
+
failure: invalid_records.length,
|
|
76
|
+
failed_records: invalid_records
|
|
77
|
+
};
|
|
78
|
+
}
|
|
55
79
|
}]);
|
|
56
80
|
return BulkResponse;
|
|
57
81
|
}();
|
package/dist/event.js
CHANGED
|
@@ -43,26 +43,24 @@ var Event = /*#__PURE__*/function () {
|
|
|
43
43
|
this.event_name = event_name;
|
|
44
44
|
this.properties = properties;
|
|
45
45
|
this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
|
|
46
|
-
this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id; //
|
|
46
|
+
this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id; // default values
|
|
47
47
|
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.__validate_properties();
|
|
48
|
+
if (!this.properties) {
|
|
49
|
+
this.properties = {};
|
|
50
|
+
}
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
(0, _createClass2["default"])(Event, [{
|
|
56
54
|
key: "__validate_distinct_id",
|
|
57
55
|
value: function __validate_distinct_id() {
|
|
58
|
-
if (this.distinct_id
|
|
59
|
-
throw new _utils.
|
|
56
|
+
if (typeof this.distinct_id !== "string") {
|
|
57
|
+
throw new _utils.InputValueError("distinct_id must be a string. an Id which uniquely identify a user in your app");
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
var distinct_id = this.distinct_id.trim();
|
|
63
61
|
|
|
64
62
|
if (!distinct_id) {
|
|
65
|
-
throw new _utils.
|
|
63
|
+
throw new _utils.InputValueError("distinct_id missing");
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
this.distinct_id = distinct_id;
|
|
@@ -70,12 +68,8 @@ var Event = /*#__PURE__*/function () {
|
|
|
70
68
|
}, {
|
|
71
69
|
key: "__validate_properties",
|
|
72
70
|
value: function __validate_properties() {
|
|
73
|
-
if (!this.properties) {
|
|
74
|
-
this.properties = {};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
71
|
if (!(this.properties instanceof Object)) {
|
|
78
|
-
throw new _utils.
|
|
72
|
+
throw new _utils.InputValueError("properties must be a dictionary");
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
}, {
|
|
@@ -83,7 +77,7 @@ var Event = /*#__PURE__*/function () {
|
|
|
83
77
|
value: function __check_event_prefix(event_name) {
|
|
84
78
|
if (!RESERVED_EVENT_NAMES.includes(event_name)) {
|
|
85
79
|
if ((0, _utils.has_special_char)(event_name)) {
|
|
86
|
-
throw new _utils.
|
|
80
|
+
throw new _utils.InputValueError("event_names starting with [$,ss_] are reserved by SuprSend");
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
83
|
}
|
|
@@ -91,11 +85,15 @@ var Event = /*#__PURE__*/function () {
|
|
|
91
85
|
key: "__validate_event_name",
|
|
92
86
|
value: function __validate_event_name() {
|
|
93
87
|
if (!(0, _utils.is_string)(this.event_name)) {
|
|
94
|
-
throw new _utils.
|
|
88
|
+
throw new _utils.InputValueError("event_name must be a string");
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
var event_name = this.event_name.trim();
|
|
98
92
|
|
|
93
|
+
if (!event_name) {
|
|
94
|
+
throw new _utils.InputValueError("event_name missing");
|
|
95
|
+
}
|
|
96
|
+
|
|
99
97
|
this.__check_event_prefix(event_name);
|
|
100
98
|
|
|
101
99
|
this.event_name = event_name;
|
|
@@ -107,8 +105,19 @@ var Event = /*#__PURE__*/function () {
|
|
|
107
105
|
|
|
108
106
|
var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
109
107
|
var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
|
|
110
|
-
var ignore_if_error = (_kwargs$ignore_if_err = kwargs === null || kwargs === void 0 ? void 0 : kwargs.ignore_if_error) !== null && _kwargs$ignore_if_err !== void 0 ? _kwargs$ignore_if_err : false;
|
|
111
|
-
|
|
108
|
+
var ignore_if_error = (_kwargs$ignore_if_err = kwargs === null || kwargs === void 0 ? void 0 : kwargs.ignore_if_error) !== null && _kwargs$ignore_if_err !== void 0 ? _kwargs$ignore_if_err : false; // if properties is not a dict, not raising error while adding attachment.
|
|
109
|
+
|
|
110
|
+
if (!(this.properties instanceof Object)) {
|
|
111
|
+
console.log("WARNING: attachment cannot be added. please make sure properties is a dictionary. Event" + JSON.stringify(this.as_json()));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
|
|
116
|
+
|
|
117
|
+
if (!attachment) {
|
|
118
|
+
return;
|
|
119
|
+
} // --- add the attachment to properties->$attachments
|
|
120
|
+
|
|
112
121
|
|
|
113
122
|
if (!this.properties["$attachments"]) {
|
|
114
123
|
this.properties["$attachments"] = [];
|
|
@@ -120,6 +129,14 @@ var Event = /*#__PURE__*/function () {
|
|
|
120
129
|
key: "get_final_json",
|
|
121
130
|
value: function get_final_json(config) {
|
|
122
131
|
var is_part_of_bulk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
132
|
+
|
|
133
|
+
// --- validate
|
|
134
|
+
this.__validate_distinct_id();
|
|
135
|
+
|
|
136
|
+
this.__validate_event_name();
|
|
137
|
+
|
|
138
|
+
this.__validate_properties();
|
|
139
|
+
|
|
123
140
|
var super_props = {
|
|
124
141
|
$ss_sdk_version: config.user_agent
|
|
125
142
|
};
|
|
@@ -144,11 +161,30 @@ var Event = /*#__PURE__*/function () {
|
|
|
144
161
|
var apparent_size = (0, _utils.get_apparent_event_size)(event_dict, is_part_of_bulk);
|
|
145
162
|
|
|
146
163
|
if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
147
|
-
throw new _utils.
|
|
164
|
+
throw new _utils.InputValueError("Event size too big - ".concat(apparent_size, " Bytes,must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
return [event_dict, apparent_size];
|
|
151
168
|
}
|
|
169
|
+
}, {
|
|
170
|
+
key: "as_json",
|
|
171
|
+
value: function as_json() {
|
|
172
|
+
var event_dict = {
|
|
173
|
+
event: this.event_name,
|
|
174
|
+
distinct_id: this.distinct_id,
|
|
175
|
+
properties: this.properties
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
if (this.idempotency_key) {
|
|
179
|
+
event_dict["$idempotency_key"] = this.idempotency_key;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this.brand_id) {
|
|
183
|
+
event_dict["brand_id"] = this.brand_id;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return event_dict;
|
|
187
|
+
}
|
|
152
188
|
}]);
|
|
153
189
|
return Event;
|
|
154
190
|
}();
|
package/dist/events_bulk.js
CHANGED
|
@@ -124,7 +124,7 @@ var _BulkEventsChunk = /*#__PURE__*/function () {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
if (event_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
127
|
-
throw new _utils.
|
|
127
|
+
throw new _utils.InputValueError("Event properties too big - ".concat(event_size, " Bytes, must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
if (this.__running_size + event_size > _constants.BODY_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
@@ -195,7 +195,7 @@ var _BulkEventsChunk = /*#__PURE__*/function () {
|
|
|
195
195
|
_context.prev = 12;
|
|
196
196
|
_context.t0 = _context["catch"](4);
|
|
197
197
|
error_status = _context.t0.status || 500;
|
|
198
|
-
|
|
198
|
+
this.response = {
|
|
199
199
|
status: "fail",
|
|
200
200
|
status_code: error_status,
|
|
201
201
|
message: _context.t0.message,
|
|
@@ -209,7 +209,7 @@ var _BulkEventsChunk = /*#__PURE__*/function () {
|
|
|
209
209
|
code: error_status
|
|
210
210
|
};
|
|
211
211
|
})
|
|
212
|
-
}
|
|
212
|
+
};
|
|
213
213
|
|
|
214
214
|
case 16:
|
|
215
215
|
case "end":
|
|
@@ -236,30 +236,35 @@ var BulkEvents = /*#__PURE__*/function () {
|
|
|
236
236
|
this.__events = [];
|
|
237
237
|
this.__pending_records = [];
|
|
238
238
|
this.chunks = [];
|
|
239
|
-
this.response = new _bulk_response["default"]();
|
|
239
|
+
this.response = new _bulk_response["default"](); // invalid_record json: {"record": event-json, "error": error_str, "code": 500}
|
|
240
|
+
|
|
241
|
+
this.__invalid_records = [];
|
|
240
242
|
}
|
|
241
243
|
|
|
242
244
|
(0, _createClass2["default"])(BulkEvents, [{
|
|
243
245
|
key: "__validate_events",
|
|
244
246
|
value: function __validate_events() {
|
|
245
|
-
if (!this.__events) {
|
|
246
|
-
throw new _utils.SuprsendError("events list is empty in bulk request");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
247
|
var _iterator = _createForOfIteratorHelper(this.__events),
|
|
250
248
|
_step;
|
|
251
249
|
|
|
252
250
|
try {
|
|
253
251
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
254
252
|
var ev = _step.value;
|
|
255
|
-
var is_part_of_bulk = true;
|
|
256
253
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
ev_json = _ev$get_final_json2[0],
|
|
260
|
-
body_size = _ev$get_final_json2[1];
|
|
254
|
+
try {
|
|
255
|
+
var is_part_of_bulk = true;
|
|
261
256
|
|
|
262
|
-
|
|
257
|
+
var _ev$get_final_json = ev.get_final_json(this.config, is_part_of_bulk),
|
|
258
|
+
_ev$get_final_json2 = (0, _slicedToArray2["default"])(_ev$get_final_json, 2),
|
|
259
|
+
ev_json = _ev$get_final_json2[0],
|
|
260
|
+
body_size = _ev$get_final_json2[1];
|
|
261
|
+
|
|
262
|
+
this.__pending_records.push([ev_json, body_size]);
|
|
263
|
+
} catch (ex) {
|
|
264
|
+
var inv_rec = (0, _utils.invalid_record_json)(ev.as_json(), ex);
|
|
265
|
+
|
|
266
|
+
this.__invalid_records.push(inv_rec);
|
|
267
|
+
}
|
|
263
268
|
}
|
|
264
269
|
} catch (err) {
|
|
265
270
|
_iterator.e(err);
|
|
@@ -309,30 +314,24 @@ var BulkEvents = /*#__PURE__*/function () {
|
|
|
309
314
|
}
|
|
310
315
|
|
|
311
316
|
if (!events) {
|
|
312
|
-
|
|
317
|
+
return;
|
|
313
318
|
}
|
|
314
319
|
|
|
315
320
|
for (var _i = 0, _events = events; _i < _events.length; _i++) {
|
|
316
321
|
var ev = _events[_i];
|
|
317
322
|
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
}
|
|
323
|
+
if (ev && ev instanceof _event["default"]) {
|
|
324
|
+
var ev_copy = (0, _lodash.cloneDeep)(ev);
|
|
321
325
|
|
|
322
|
-
|
|
323
|
-
throw new _utils.SuprsendError("element must be an instance of suprsend.Event");
|
|
326
|
+
this.__events.push(ev_copy);
|
|
324
327
|
}
|
|
325
|
-
|
|
326
|
-
var ev_copy = (0, _lodash.cloneDeep)(ev);
|
|
327
|
-
|
|
328
|
-
this.__events.push(ev_copy);
|
|
329
328
|
}
|
|
330
329
|
}
|
|
331
330
|
}, {
|
|
332
331
|
key: "trigger",
|
|
333
332
|
value: function () {
|
|
334
333
|
var _trigger2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
335
|
-
var _iterator3, _step3, _step3$value, c_idx, ch;
|
|
334
|
+
var ch_response, _iterator3, _step3, _step3$value, c_idx, ch;
|
|
336
335
|
|
|
337
336
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
338
337
|
while (1) {
|
|
@@ -340,16 +339,26 @@ var BulkEvents = /*#__PURE__*/function () {
|
|
|
340
339
|
case 0:
|
|
341
340
|
this.__validate_events();
|
|
342
341
|
|
|
342
|
+
if (this.__invalid_records.length > 0) {
|
|
343
|
+
ch_response = _bulk_response["default"].invalid_records_chunk_response(this.__invalid_records);
|
|
344
|
+
this.response.merge_chunk_response(ch_response);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (!this.__pending_records.length) {
|
|
348
|
+
_context2.next = 25;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
|
|
343
352
|
this.__chunkify();
|
|
344
353
|
|
|
345
354
|
_iterator3 = _createForOfIteratorHelper(this.chunks.entries());
|
|
346
|
-
_context2.prev =
|
|
355
|
+
_context2.prev = 5;
|
|
347
356
|
|
|
348
357
|
_iterator3.s();
|
|
349
358
|
|
|
350
|
-
case
|
|
359
|
+
case 7:
|
|
351
360
|
if ((_step3 = _iterator3.n()).done) {
|
|
352
|
-
_context2.next =
|
|
361
|
+
_context2.next = 15;
|
|
353
362
|
break;
|
|
354
363
|
}
|
|
355
364
|
|
|
@@ -360,43 +369,54 @@ var BulkEvents = /*#__PURE__*/function () {
|
|
|
360
369
|
} // do api call
|
|
361
370
|
|
|
362
371
|
|
|
363
|
-
_context2.next =
|
|
372
|
+
_context2.next = 12;
|
|
364
373
|
return ch.trigger();
|
|
365
374
|
|
|
366
|
-
case
|
|
375
|
+
case 12:
|
|
367
376
|
// merge response
|
|
368
377
|
this.response.merge_chunk_response(ch.response);
|
|
369
378
|
|
|
370
|
-
case 11:
|
|
371
|
-
_context2.next = 5;
|
|
372
|
-
break;
|
|
373
|
-
|
|
374
379
|
case 13:
|
|
375
|
-
_context2.next =
|
|
380
|
+
_context2.next = 7;
|
|
376
381
|
break;
|
|
377
382
|
|
|
378
383
|
case 15:
|
|
379
|
-
_context2.
|
|
380
|
-
|
|
384
|
+
_context2.next = 20;
|
|
385
|
+
break;
|
|
386
|
+
|
|
387
|
+
case 17:
|
|
388
|
+
_context2.prev = 17;
|
|
389
|
+
_context2.t0 = _context2["catch"](5);
|
|
381
390
|
|
|
382
391
|
_iterator3.e(_context2.t0);
|
|
383
392
|
|
|
384
|
-
case
|
|
385
|
-
_context2.prev =
|
|
393
|
+
case 20:
|
|
394
|
+
_context2.prev = 20;
|
|
386
395
|
|
|
387
396
|
_iterator3.f();
|
|
388
397
|
|
|
389
|
-
return _context2.finish(
|
|
398
|
+
return _context2.finish(20);
|
|
399
|
+
|
|
400
|
+
case 23:
|
|
401
|
+
_context2.next = 26;
|
|
402
|
+
break;
|
|
403
|
+
|
|
404
|
+
case 25:
|
|
405
|
+
// if no records. i.e. invalid_records.length and pending_records.length both are 0
|
|
406
|
+
// then add empty success response
|
|
407
|
+
if (this.__invalid_records.length === 0) {
|
|
408
|
+
this.response.merge_chunk_response(_bulk_response["default"].empty_chunk_success_response());
|
|
409
|
+
}
|
|
390
410
|
|
|
391
|
-
case
|
|
411
|
+
case 26:
|
|
392
412
|
return _context2.abrupt("return", this.response);
|
|
393
413
|
|
|
394
|
-
case
|
|
414
|
+
case 27:
|
|
395
415
|
case "end":
|
|
396
416
|
return _context2.stop();
|
|
397
417
|
}
|
|
398
418
|
}
|
|
399
|
-
}, _callee2, this, [[
|
|
419
|
+
}, _callee2, this, [[5, 17, 20, 23]]);
|
|
400
420
|
}));
|
|
401
421
|
|
|
402
422
|
function trigger() {
|
package/dist/index.js
CHANGED
|
@@ -143,12 +143,12 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
143
143
|
var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
|
|
144
144
|
var ignore_if_error = (_kwargs$ignore_if_err = kwargs === null || kwargs === void 0 ? void 0 : kwargs.ignore_if_error) !== null && _kwargs$ignore_if_err !== void 0 ? _kwargs$ignore_if_err : false;
|
|
145
145
|
|
|
146
|
-
if (!body.data) {
|
|
146
|
+
if (!(body !== null && body !== void 0 && body.data)) {
|
|
147
147
|
body.data = {};
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
if (!body.data instanceof Object) {
|
|
151
|
-
throw new _utils.
|
|
150
|
+
if (!(body.data instanceof Object)) {
|
|
151
|
+
throw new _utils.InputValueError("data must be an object");
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
|
|
@@ -185,7 +185,7 @@ var Suprsend = /*#__PURE__*/function () {
|
|
|
185
185
|
key: "track_event",
|
|
186
186
|
value: function track_event(event) {
|
|
187
187
|
if (!(event instanceof _event["default"])) {
|
|
188
|
-
throw new _utils.
|
|
188
|
+
throw new _utils.InputValueError("argument must be an instance of suprsend.Event");
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
return this._eventcollector.collect(event);
|
package/dist/subscriber.js
CHANGED
|
@@ -50,13 +50,13 @@ var SubscriberFactory = /*#__PURE__*/function () {
|
|
|
50
50
|
key: "get_instance",
|
|
51
51
|
value: function get_instance(distinct_id) {
|
|
52
52
|
if (!(0, _utils.is_string)(distinct_id)) {
|
|
53
|
-
throw new _utils.
|
|
53
|
+
throw new _utils.InputValueError("distinct_id must be a string. an Id which uniquely identify a user in your app");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
distinct_id = distinct_id.trim();
|
|
57
57
|
|
|
58
58
|
if (!distinct_id) {
|
|
59
|
-
throw new _utils.
|
|
59
|
+
throw new _utils.InputValueError("distinct_id must be passed");
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return new Subscriber(this.config, distinct_id);
|
|
@@ -78,6 +78,7 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
78
78
|
this.__info = [];
|
|
79
79
|
this.user_operations = [];
|
|
80
80
|
this._helper = new _subscriber_helper["default"]();
|
|
81
|
+
this.__warnings_list = [];
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
(0, _createClass2["default"])(Subscriber, [{
|
|
@@ -114,13 +115,23 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
114
115
|
properties: this.__super_props
|
|
115
116
|
};
|
|
116
117
|
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "as_json",
|
|
120
|
+
value: function as_json() {
|
|
121
|
+
var event_dict = {
|
|
122
|
+
distinct_id: this.distinct_id,
|
|
123
|
+
$user_operations: this.user_operations,
|
|
124
|
+
warnings: this.__warnings_list
|
|
125
|
+
};
|
|
126
|
+
return event_dict;
|
|
127
|
+
}
|
|
117
128
|
}, {
|
|
118
129
|
key: "validate_event_size",
|
|
119
130
|
value: function validate_event_size(event_dict) {
|
|
120
131
|
var apparent_size = (0, _utils.get_apparent_identity_event_size)(event_dict);
|
|
121
132
|
|
|
122
133
|
if (apparent_size > _constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
123
|
-
throw new _utils.
|
|
134
|
+
throw new _utils.InputValueError("User Event size too big - ".concat(apparent_size, " Bytes, must not cross ").concat(_constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
return [event_dict, apparent_size];
|
|
@@ -129,28 +140,31 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
129
140
|
key: "validate_body",
|
|
130
141
|
value: function validate_body() {
|
|
131
142
|
var is_part_of_bulk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
132
|
-
|
|
143
|
+
this.__warnings_list = [];
|
|
133
144
|
|
|
134
145
|
if (!(0, _utils.is_empty)(this.__info)) {
|
|
135
146
|
var msg = "[distinct_id: ".concat(this.distinct_id, "]").concat(this.__info.join("\n"));
|
|
136
|
-
|
|
147
|
+
|
|
148
|
+
this.__warnings_list.push(msg);
|
|
149
|
+
|
|
137
150
|
console.log("WARNING: ".concat(msg));
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
if (!(0, _utils.is_empty)(this.__errors)) {
|
|
141
154
|
var _msg = "[distinct_id: ".concat(this.distinct_id, "] ").concat(this.__errors.join("\n"));
|
|
142
155
|
|
|
143
|
-
|
|
156
|
+
this.__warnings_list.push(_msg);
|
|
157
|
+
|
|
144
158
|
var err_msg = "ERROR: ".concat(_msg);
|
|
145
159
|
|
|
146
160
|
if (is_part_of_bulk) {
|
|
147
161
|
console.log(err_msg);
|
|
148
162
|
} else {
|
|
149
|
-
throw new _utils.
|
|
163
|
+
throw new _utils.InputValueError(err_msg);
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
|
|
153
|
-
return
|
|
167
|
+
return this.__warnings_list;
|
|
154
168
|
}
|
|
155
169
|
}, {
|
|
156
170
|
key: "save",
|
package/dist/subscriber_list.js
CHANGED
|
@@ -11,10 +11,10 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
11
11
|
|
|
12
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
13
|
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
14
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
15
|
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
18
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
19
|
|
|
20
20
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -27,6 +27,8 @@ var _axios = _interopRequireDefault(require("axios"));
|
|
|
27
27
|
|
|
28
28
|
var _constants = require("./constants");
|
|
29
29
|
|
|
30
|
+
var _attachment = _interopRequireDefault(require("./attachment"));
|
|
31
|
+
|
|
30
32
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
33
|
|
|
32
34
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -37,7 +39,7 @@ var SubscriberListBroadcast = /*#__PURE__*/function () {
|
|
|
37
39
|
(0, _classCallCheck2["default"])(this, SubscriberListBroadcast);
|
|
38
40
|
|
|
39
41
|
if (!(body instanceof Object)) {
|
|
40
|
-
throw new _utils.
|
|
42
|
+
throw new _utils.InputValueError("broadcast body must be a json/dictionary");
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
this.body = body;
|
|
@@ -46,6 +48,39 @@ var SubscriberListBroadcast = /*#__PURE__*/function () {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
(0, _createClass2["default"])(SubscriberListBroadcast, [{
|
|
51
|
+
key: "add_attachment",
|
|
52
|
+
value: function add_attachment(file_path) {
|
|
53
|
+
var _kwargs$ignore_if_err, _this$body, _this$body$data;
|
|
54
|
+
|
|
55
|
+
var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
56
|
+
var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
|
|
57
|
+
var ignore_if_error = (_kwargs$ignore_if_err = kwargs === null || kwargs === void 0 ? void 0 : kwargs.ignore_if_error) !== null && _kwargs$ignore_if_err !== void 0 ? _kwargs$ignore_if_err : false;
|
|
58
|
+
|
|
59
|
+
if (!((_this$body = this.body) !== null && _this$body !== void 0 && _this$body["data"])) {
|
|
60
|
+
this.body["data"] = {};
|
|
61
|
+
} // if body["data"] is not a dict, not raising error while adding attachment.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (!(this.body["data"] instanceof Object)) {
|
|
65
|
+
console.log("WARNING: attachment cannot be added. please make sure body['data'] is a dictionary. " + "SubscriberListBroadcast" + JSON.stringify(this.as_json()));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
|
|
70
|
+
|
|
71
|
+
if (!attachment) {
|
|
72
|
+
return;
|
|
73
|
+
} // --- add the attachment to body->data->$attachments
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (!((_this$body$data = this.body["data"]) !== null && _this$body$data !== void 0 && _this$body$data["$attachments"])) {
|
|
77
|
+
this.body["data"]["$attachments"] = [];
|
|
78
|
+
} // -----
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
this.body["data"]["$attachments"].push(attachment);
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
49
84
|
key: "get_final_json",
|
|
50
85
|
value: function get_final_json() {
|
|
51
86
|
this.body["$insert_id"] = (0, _utils.uuid)();
|
|
@@ -63,11 +98,27 @@ var SubscriberListBroadcast = /*#__PURE__*/function () {
|
|
|
63
98
|
var apparent_size = (0, _utils.get_apparent_list_broadcast_body_size)(this.body);
|
|
64
99
|
|
|
65
100
|
if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
|
|
66
|
-
throw new _utils.
|
|
101
|
+
throw new _utils.InputValueError("SubscriberListBroadcast body too big - ".concat(apparent_size, " Bytes, must not cross ").concat(_constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
|
|
67
102
|
}
|
|
68
103
|
|
|
69
104
|
return [this.body, apparent_size];
|
|
70
105
|
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "as_json",
|
|
108
|
+
value: function as_json() {
|
|
109
|
+
var body_dict = _objectSpread({}, this.body);
|
|
110
|
+
|
|
111
|
+
if (this.idempotency_key) {
|
|
112
|
+
body_dict["$idempotency_key"] = this.idempotency_key;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.brand_id) {
|
|
116
|
+
body_dict["brand_id"] = this.brand_id;
|
|
117
|
+
} // -----
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
return body_dict;
|
|
121
|
+
}
|
|
71
122
|
}]);
|
|
72
123
|
return SubscriberListBroadcast;
|
|
73
124
|
}();
|
|
@@ -444,7 +495,7 @@ var SubscriberListsApi = /*#__PURE__*/function () {
|
|
|
444
495
|
break;
|
|
445
496
|
}
|
|
446
497
|
|
|
447
|
-
throw new _utils.
|
|
498
|
+
throw new _utils.InputValueError("argument must be an instance of suprsend.SubscriberListBroadcast");
|
|
448
499
|
|
|
449
500
|
case 2:
|
|
450
501
|
_broadcast_instance$g = broadcast_instance.get_final_json(this.config), _broadcast_instance$g2 = (0, _slicedToArray2["default"])(_broadcast_instance$g, 2), broadcast_body = _broadcast_instance$g2[0], body_size = _broadcast_instance$g2[1];
|