@suprsend/node-sdk 1.11.1 → 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.
Files changed (48) hide show
  1. package/dist/constants.js +2 -8
  2. package/dist/event.js +2 -2
  3. package/dist/events_bulk.js +2 -2
  4. package/dist/index.js +25 -2
  5. package/dist/object_edit.js +352 -0
  6. package/dist/object_edit_internal_helper.js +395 -0
  7. package/dist/objects_api.js +527 -0
  8. package/dist/request_json/workflow.json +7 -29
  9. package/dist/request_json/workflow_trigger.json +7 -29
  10. package/dist/subscriber.js +12 -28
  11. package/dist/subscriber_helper.js +40 -363
  12. package/dist/subscriber_list.js +2 -2
  13. package/dist/user_edit.js +412 -0
  14. package/dist/user_edit_internal_helper.js +363 -0
  15. package/dist/users_api.js +535 -0
  16. package/dist/users_edit_bulk.js +312 -0
  17. package/dist/workflow.js +2 -2
  18. package/dist/workflow_request.js +2 -2
  19. package/dist/workflow_trigger_bulk.js +2 -2
  20. package/dist/workflows_bulk.js +2 -2
  21. package/package.json +1 -1
  22. package/src/constants.js +0 -4
  23. package/src/event.js +4 -5
  24. package/src/events_bulk.js +3 -5
  25. package/src/index.js +9 -1
  26. package/src/object_edit.js +308 -0
  27. package/src/object_edit_internal_helper.js +332 -0
  28. package/src/objects_api.js +320 -0
  29. package/src/request_json/workflow.json +7 -29
  30. package/src/request_json/workflow_trigger.json +7 -29
  31. package/src/subscriber.js +10 -21
  32. package/src/subscriber_helper.js +41 -365
  33. package/src/subscriber_list.js +4 -4
  34. package/src/user_edit.js +360 -0
  35. package/src/user_edit_internal_helper.js +297 -0
  36. package/src/users_api.js +301 -0
  37. package/src/users_edit_bulk.js +211 -0
  38. package/src/workflow.js +4 -5
  39. package/src/workflow_request.js +4 -4
  40. package/src/workflow_trigger_bulk.js +2 -4
  41. package/src/workflows_bulk.js +3 -5
  42. package/types/index.d.ts +168 -13
  43. package/dist/language_codes.js +0 -197
  44. package/dist/object.js +0 -919
  45. package/dist/object_helper.js +0 -659
  46. package/src/language_codes.js +0 -188
  47. package/src/object.js +0 -621
  48. package/src/object_helper.js +0 -593
@@ -0,0 +1,412 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _utils = require("./utils");
12
+ var _user_edit_internal_helper = _interopRequireDefault(require("./user_edit_internal_helper"));
13
+ var _constants = require("./constants");
14
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17
+ var UserEdit = /*#__PURE__*/function () {
18
+ function UserEdit(config, distinct_id) {
19
+ (0, _classCallCheck2["default"])(this, UserEdit);
20
+ this.config = config;
21
+ this.distinct_id = distinct_id;
22
+ this.__errors = [];
23
+ this.__info = [];
24
+ this.operations = [];
25
+ this._helper = new _user_edit_internal_helper["default"]();
26
+ this.__warnings_list = [];
27
+ }
28
+ (0, _createClass2["default"])(UserEdit, [{
29
+ key: "warnings",
30
+ get: function get() {
31
+ return this.__info;
32
+ }
33
+ }, {
34
+ key: "errors",
35
+ get: function get() {
36
+ return this.__errors;
37
+ }
38
+ }, {
39
+ key: "get_payload",
40
+ value: function get_payload() {
41
+ return {
42
+ operations: this.operations
43
+ };
44
+ }
45
+ }, {
46
+ key: "get_async_payload",
47
+ value: function get_async_payload() {
48
+ return {
49
+ $schema: "2",
50
+ $insert_id: (0, _utils.uuid)(),
51
+ $time: (0, _utils.epoch_milliseconds)(),
52
+ env: this.config.workspace_key,
53
+ distinct_id: this.distinct_id,
54
+ $user_operations: this.operations,
55
+ properties: {
56
+ $ss_sdk_version: this.config.user_agent
57
+ }
58
+ };
59
+ }
60
+ }, {
61
+ key: "as_json_async",
62
+ value: function as_json_async() {
63
+ return {
64
+ distinct_id: this.distinct_id,
65
+ $user_operations: this.operations,
66
+ warnings: this.__warnings_list
67
+ };
68
+ }
69
+ }, {
70
+ key: "validate_payload_size",
71
+ value: function validate_payload_size(payload) {
72
+ var apparent_size = (0, _utils.get_apparent_identity_event_size)(payload);
73
+ if (apparent_size > _constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
74
+ throw new _utils.InputValueError("User Payload size too big - ".concat(apparent_size, " Bytes, ") + "must not cross ".concat(_constants.IDENTITY_SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE));
75
+ }
76
+ return [payload, apparent_size];
77
+ }
78
+ }, {
79
+ key: "validate_body",
80
+ value: function validate_body() {
81
+ this.__warnings_list = [];
82
+ if (!(0, _utils.is_empty)(this.__info)) {
83
+ var msg = "[distinct_id: ".concat(this.distinct_id, "]") + this.__info.join("\n");
84
+ this.__warnings_list.push(msg);
85
+ console.log("WARNING: ".concat(msg));
86
+ }
87
+ if (!(0, _utils.is_empty)(this.__errors)) {
88
+ var _msg = "[distinct_id: ".concat(this.distinct_id, "]") + this.__errors.join("\n");
89
+ this.__warnings_list.push(_msg);
90
+ console.log("ERROR: ".concat(_msg));
91
+ }
92
+ return this.__warnings_list;
93
+ }
94
+ }, {
95
+ key: "_collect_operation",
96
+ value: function _collect_operation() {
97
+ var resp = this._helper.get_operation_result();
98
+ if (!(0, _utils.is_empty)(resp["errors"])) {
99
+ this.__errors = [].concat((0, _toConsumableArray2["default"])(this.__errors), (0, _toConsumableArray2["default"])(resp["errors"]));
100
+ }
101
+ if (!(0, _utils.is_empty)(resp["info"])) {
102
+ this.__info = [].concat((0, _toConsumableArray2["default"])(this.__info), (0, _toConsumableArray2["default"])(resp["info"]));
103
+ }
104
+ if (!(0, _utils.is_empty)(resp["operation"])) {
105
+ this.operations.push(resp["operation"]);
106
+ }
107
+ }
108
+ }, {
109
+ key: "append",
110
+ value: function append(arg1) {
111
+ var arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
112
+ var caller = "append";
113
+ if (!(0, _utils.is_string)(arg1) && !(0, _utils.is_object)(arg1)) {
114
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
115
+ return;
116
+ }
117
+ if ((0, _utils.is_string)(arg1)) {
118
+ if (!arg2) {
119
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
120
+ return;
121
+ } else {
122
+ this._helper._append_kv(arg1, arg2, {}, caller);
123
+ this._collect_operation();
124
+ }
125
+ } else {
126
+ for (var item in arg1) {
127
+ this._helper._append_kv(item, arg1[item], arg1, caller);
128
+ }
129
+ this._collect_operation();
130
+ }
131
+ }
132
+ }, {
133
+ key: "set",
134
+ value: function set(arg1) {
135
+ var arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
136
+ var caller = "set";
137
+ if (!(0, _utils.is_string)(arg1) && !(0, _utils.is_object)(arg1)) {
138
+ this.__errors.push("[".concat(caller, "] arg1 must be String or a dict"));
139
+ return;
140
+ }
141
+ if (typeof arg1 === "string") {
142
+ if (arg2 === null || arg2 === undefined) {
143
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
144
+ return;
145
+ } else {
146
+ this._helper._set_kv(arg1, arg2, caller);
147
+ this._collect_operation();
148
+ }
149
+ } else {
150
+ for (var item in arg1) {
151
+ this._helper._set_kv(item, arg1[item], arg1, caller);
152
+ }
153
+ this._collect_operation();
154
+ }
155
+ }
156
+ }, {
157
+ key: "set_once",
158
+ value: function set_once(arg1) {
159
+ var arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
160
+ var caller = "set_once";
161
+ if (!(0, _utils.is_string)(arg1) && !(0, _utils.is_object)(arg1)) {
162
+ this.__errors.push("[".concat(caller, "] arg1 must be String or a dict"));
163
+ return;
164
+ }
165
+ if ((0, _utils.is_string)(arg1)) {
166
+ if (arg2 === null || arg2 === undefined) {
167
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
168
+ return;
169
+ } else {
170
+ this._helper._set_once_kv(arg1, arg2, caller);
171
+ this._collect_operation();
172
+ }
173
+ } else {
174
+ for (var item in arg1) {
175
+ this._helper._set_once_kv(item, arg1[item], arg1, caller);
176
+ }
177
+ this._collect_operation();
178
+ }
179
+ }
180
+ }, {
181
+ key: "increment",
182
+ value: function increment(arg1) {
183
+ var arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
184
+ var caller = "increment";
185
+ if (!(0, _utils.is_string)(arg1) && !(0, _utils.is_object)(arg1)) {
186
+ this.__errors.push("[".concat(caller, "] arg1 must be String or a dict"));
187
+ return;
188
+ }
189
+ if ((0, _utils.is_string)(arg1)) {
190
+ if (arg2 === null || arg2 === undefined) {
191
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
192
+ return;
193
+ } else {
194
+ this._helper._increment_kv(arg1, arg2, caller);
195
+ this._collect_operation();
196
+ }
197
+ } else {
198
+ for (var item in arg1) {
199
+ this._helper._increment_kv(item, arg1[item], arg1, caller);
200
+ }
201
+ this._collect_operation();
202
+ }
203
+ }
204
+ }, {
205
+ key: "remove",
206
+ value: function remove(arg1) {
207
+ var arg2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
208
+ var caller = "remove";
209
+ if (!(0, _utils.is_string)(arg1) && !(0, _utils.is_object)(arg1)) {
210
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
211
+ return;
212
+ }
213
+ if ((0, _utils.is_string)(arg1)) {
214
+ if (arg2 === null || arg2 === undefined) {
215
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
216
+ return;
217
+ } else {
218
+ this._helper._remove_kv(arg1, arg2, {}, caller);
219
+ this._collect_operation();
220
+ }
221
+ } else {
222
+ for (var item in arg1) {
223
+ this._helper._remove_kv(item, arg1[item], arg1, caller);
224
+ }
225
+ this._collect_operation();
226
+ }
227
+ }
228
+ }, {
229
+ key: "unset",
230
+ value: function unset(key) {
231
+ var caller = "unset";
232
+ if (!(0, _utils.is_string)(key) && !Array.isArray(key)) {
233
+ this.__errors.push("[".concat(caller, "] key must be either String or List[string]"));
234
+ return;
235
+ }
236
+ if ((0, _utils.is_string)(key)) {
237
+ this._helper._unset_k(key, caller);
238
+ this._collect_operation();
239
+ } else {
240
+ var _iterator = _createForOfIteratorHelper(key),
241
+ _step;
242
+ try {
243
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
244
+ var k = _step.value;
245
+ this._helper._unset_k(k, caller);
246
+ }
247
+ } catch (err) {
248
+ _iterator.e(err);
249
+ } finally {
250
+ _iterator.f();
251
+ }
252
+ this._collect_operation();
253
+ }
254
+ }
255
+
256
+ // ------------------------ Preferred language
257
+ }, {
258
+ key: "set_preferred_language",
259
+ value: function set_preferred_language(lang_code) {
260
+ var caller = "set_preferred_language";
261
+ this._helper._set_preferred_language(lang_code, caller);
262
+ this._collect_operation();
263
+ }
264
+
265
+ // ------------------------ Timezone
266
+ }, {
267
+ key: "set_timezone",
268
+ value: function set_timezone(timezone) {
269
+ var caller = "set_timezone";
270
+ this._helper._set_timezone(timezone, caller);
271
+ this._collect_operation();
272
+ }
273
+
274
+ // ------------------------ Email
275
+ }, {
276
+ key: "add_email",
277
+ value: function add_email(value) {
278
+ var caller = "add_email";
279
+ this._helper._add_email(value, caller);
280
+ this._collect_operation();
281
+ }
282
+ }, {
283
+ key: "remove_email",
284
+ value: function remove_email(value) {
285
+ var caller = "remove_email";
286
+ this._helper._remove_email(value, caller);
287
+ this._collect_operation();
288
+ }
289
+
290
+ // ------------------------ SMS
291
+ }, {
292
+ key: "add_sms",
293
+ value: function add_sms(value) {
294
+ var caller = "add_sms";
295
+ this._helper._add_sms(value, caller);
296
+ this._collect_operation();
297
+ }
298
+ }, {
299
+ key: "remove_sms",
300
+ value: function remove_sms(value) {
301
+ var caller = "remove_sms";
302
+ this._helper._remove_sms(value, caller);
303
+ this._collect_operation();
304
+ }
305
+
306
+ // ------------------------ Whatsapp
307
+ }, {
308
+ key: "add_whatsapp",
309
+ value: function add_whatsapp(value) {
310
+ var caller = "add_whatsapp";
311
+ this._helper._add_whatsapp(value, caller);
312
+ this._collect_operation();
313
+ }
314
+ }, {
315
+ key: "remove_whatsapp",
316
+ value: function remove_whatsapp(value) {
317
+ var caller = "remove_whatsapp";
318
+ this._helper._remove_whatsapp(value, caller);
319
+ this._collect_operation();
320
+ }
321
+
322
+ // ------------------------ Androidpush
323
+ }, {
324
+ key: "add_androidpush",
325
+ value: function add_androidpush(value) {
326
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
327
+ var caller = "add_androidpush";
328
+ this._helper._add_androidpush(value, provider, caller);
329
+ this._collect_operation();
330
+ }
331
+ }, {
332
+ key: "remove_androidpush",
333
+ value: function remove_androidpush(value) {
334
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
335
+ var caller = "remove_androidpush";
336
+ this._helper._remove_androidpush(value, provider, caller);
337
+ this._collect_operation();
338
+ }
339
+
340
+ // ------------------------ Iospush [providers: apns]
341
+ }, {
342
+ key: "add_iospush",
343
+ value: function add_iospush(value) {
344
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
345
+ var caller = "add_iospush";
346
+ this._helper._add_iospush(value, provider, caller);
347
+ this._collect_operation();
348
+ }
349
+ }, {
350
+ key: "remove_iospush",
351
+ value: function remove_iospush(value) {
352
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
353
+ var caller = "remove_iospush";
354
+ this._helper._remove_iospush(value, provider, caller);
355
+ this._collect_operation();
356
+ }
357
+
358
+ // ------------------------ Webpush [providers: vapid]
359
+ }, {
360
+ key: "add_webpush",
361
+ value: function add_webpush(value) {
362
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
363
+ var caller = "add_webpush";
364
+ this._helper._add_webpush(value, provider, caller);
365
+ this._collect_operation();
366
+ }
367
+ }, {
368
+ key: "remove_webpush",
369
+ value: function remove_webpush(value) {
370
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
371
+ var caller = "remove_webpush";
372
+ this._helper._remove_webpush(value, provider, caller);
373
+ this._collect_operation();
374
+ }
375
+
376
+ // ------------------------ Slack
377
+ }, {
378
+ key: "add_slack",
379
+ value: function add_slack(value) {
380
+ var caller = "add_slack";
381
+ this._helper._add_slack(value, caller);
382
+ this._collect_operation();
383
+ }
384
+ }, {
385
+ key: "remove_slack",
386
+ value: function remove_slack(value) {
387
+ var caller = "remove_slack";
388
+ this._helper._remove_slack(value, caller);
389
+ this._collect_operation();
390
+ }
391
+
392
+ // ------------------------ MS Teams
393
+ }, {
394
+ key: "add_ms_teams",
395
+ value: function add_ms_teams(value) {
396
+ var caller = "add_ms_teams";
397
+ this._helper._add_ms_teams(value, caller);
398
+ this._collect_operation();
399
+ }
400
+ }, {
401
+ key: "remove_ms_teams",
402
+ value: function remove_ms_teams(value) {
403
+ var caller = "remove_ms_teams";
404
+ this._helper._remove_ms_teams(value, caller);
405
+ this._collect_operation();
406
+ }
407
+ }]);
408
+ return UserEdit;
409
+ }();
410
+ var _default = UserEdit;
411
+ exports["default"] = _default;
412
+ module.exports = exports.default;