@suprsend/node-sdk 1.12.0 → 1.13.1

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 (44) 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 +21 -0
  5. package/dist/object_edit.js +6 -12
  6. package/dist/object_edit_internal_helper.js +40 -301
  7. package/dist/objects_api.js +193 -242
  8. package/dist/request_json/workflow.json +7 -29
  9. package/dist/request_json/workflow_trigger.json +7 -29
  10. package/dist/subscriber.js +10 -27
  11. package/dist/subscriber_helper.js +33 -291
  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 +400 -98
  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 +6 -0
  26. package/src/object_edit.js +6 -6
  27. package/src/object_edit_internal_helper.js +37 -295
  28. package/src/objects_api.js +97 -93
  29. package/src/request_json/workflow.json +7 -29
  30. package/src/request_json/workflow_trigger.json +7 -29
  31. package/src/subscriber.js +8 -20
  32. package/src/subscriber_helper.js +34 -284
  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 +208 -28
  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 +113 -8
  43. package/dist/language_codes.js +0 -197
  44. package/src/language_codes.js +0 -188
@@ -1,5 +1,4 @@
1
- import { is_object, has_special_char, is_empty, is_string } from "./utils";
2
- import ALL_LANG_CODES from "./language_codes";
1
+ import { is_empty, is_string } from "./utils";
3
2
 
4
3
  // ---------- Identity keys
5
4
  const IDENT_KEY_EMAIL = "$email";
@@ -26,48 +25,6 @@ const KEY_ID_PROVIDER = "$id_provider";
26
25
  const KEY_PREFERRED_LANGUAGE = "$preferred_language";
27
26
  const KEY_TIMEZONE = "$timezone";
28
27
 
29
- const OTHER_RESERVED_KEYS = [
30
- "$messenger",
31
- "$inbox",
32
- KEY_ID_PROVIDER,
33
- "$device_id",
34
- "$insert_id",
35
- "$time",
36
- "$set",
37
- "$set_once",
38
- "$add",
39
- "$append",
40
- "$remove",
41
- "$unset",
42
- "$identify",
43
- "$anon_id",
44
- "$identified_id",
45
- KEY_PREFERRED_LANGUAGE,
46
- KEY_TIMEZONE,
47
- "$notification_delivered",
48
- "$notification_dismiss",
49
- "$notification_clicked",
50
- ];
51
-
52
- const SUPER_PROPERTY_KEYS = [
53
- "$app_version_string",
54
- "$app_build_number",
55
- "$brand",
56
- "$carrier",
57
- "$manufacturer",
58
- "$model",
59
- "$os",
60
- "$ss_sdk_version",
61
- "$insert_id",
62
- "$time",
63
- ];
64
-
65
- const ALL_RESERVED_KEYS = [
66
- ...SUPER_PROPERTY_KEYS,
67
- ...OTHER_RESERVED_KEYS,
68
- ...IDENT_KEYS_ALL,
69
- ];
70
-
71
28
  export default class _SubscriberInternalHelper {
72
29
  constructor(distinct_id, workspace_key) {
73
30
  this.distinct_id = distinct_id;
@@ -149,18 +106,6 @@ export default class _SubscriberInternalHelper {
149
106
  return [key, true];
150
107
  }
151
108
 
152
- __validate_key_prefix(key, caller) {
153
- if (!ALL_RESERVED_KEYS.includes(key)) {
154
- if (has_special_char(key)) {
155
- this.__info.push(
156
- `[${caller}] skipping key: ${key}. key starting with [$,ss_] are reserved`
157
- );
158
- return false;
159
- }
160
- }
161
- return true;
162
- }
163
-
164
109
  __is_identity_key(key) {
165
110
  return IDENT_KEYS_ALL.includes(key);
166
111
  }
@@ -173,10 +118,7 @@ export default class _SubscriberInternalHelper {
173
118
  if (this.__is_identity_key(validated_key)) {
174
119
  this.__add_identity(validated_key, value, args, caller);
175
120
  } else {
176
- const is_k_valid = this.__validate_key_prefix(validated_key, caller);
177
- if (is_k_valid) {
178
- this.__dict_append[validated_key] = value;
179
- }
121
+ this.__dict_append[validated_key] = value;
180
122
  }
181
123
  }
182
124
 
@@ -185,10 +127,7 @@ export default class _SubscriberInternalHelper {
185
127
  if (!is_k_valid) {
186
128
  return;
187
129
  } else {
188
- const is_k_valid = this.__validate_key_prefix(validated_key, caller);
189
- if (is_k_valid) {
190
- this.__dict_set[validated_key] = value;
191
- }
130
+ this.__dict_set[validated_key] = value;
192
131
  }
193
132
  }
194
133
 
@@ -197,10 +136,7 @@ export default class _SubscriberInternalHelper {
197
136
  if (!is_k_valid) {
198
137
  return;
199
138
  } else {
200
- const is_k_valid = this.__validate_key_prefix(validated_key, caller);
201
- if (is_k_valid) {
202
- this.__dict_set_once[validated_key] = value;
203
- }
139
+ this.__dict_set_once[validated_key] = value;
204
140
  }
205
141
  }
206
142
 
@@ -209,10 +145,7 @@ export default class _SubscriberInternalHelper {
209
145
  if (!is_k_valid) {
210
146
  return;
211
147
  } else {
212
- const is_k_valid = this.__validate_key_prefix(validated_key, caller);
213
- if (is_k_valid) {
214
- this.__dict_increment[validated_key] = value;
215
- }
148
+ this.__dict_increment[validated_key] = value;
216
149
  }
217
150
  }
218
151
 
@@ -224,10 +157,7 @@ export default class _SubscriberInternalHelper {
224
157
  if (this.__is_identity_key(validated_key)) {
225
158
  this.__remove_identity(validated_key, value, args, caller);
226
159
  } else {
227
- const is_k_valid = this.__validate_key_prefix(validated_key, caller);
228
- if (is_k_valid) {
229
- this.__dict_remove[validated_key] = value;
230
- }
160
+ this.__dict_remove[validated_key] = value;
231
161
  }
232
162
  }
233
163
 
@@ -240,10 +170,6 @@ export default class _SubscriberInternalHelper {
240
170
  }
241
171
 
242
172
  _set_preferred_language(lang_code, caller) {
243
- if (!ALL_LANG_CODES.includes(lang_code)) {
244
- this.__info.push(`[${caller}] invalid value ${lang_code}`);
245
- return;
246
- }
247
173
  this.__dict_set[KEY_PREFERRED_LANGUAGE] = lang_code;
248
174
  }
249
175
 
@@ -315,249 +241,73 @@ export default class _SubscriberInternalHelper {
315
241
  }
316
242
  }
317
243
 
318
- __check_ident_val_string(value, caller) {
319
- const message = "value must be a string with proper value";
320
- if (!is_string(value)) {
321
- this.__errors.push(`[${caller}] ${message}`);
322
- return [value, false];
323
- }
324
- value = value.trim();
325
- if (!value) {
326
- this.__errors.push(`[${caller}] ${message}`);
327
- return [value, false];
328
- }
329
- return [value, true];
330
- }
331
-
332
244
  _add_email(email, caller) {
333
- const [value, is_valid] = this.__check_ident_val_string(email, caller);
334
- if (!is_valid) {
335
- return;
336
- }
337
- this.__dict_append[IDENT_KEY_EMAIL] = value;
245
+ this.__dict_append[IDENT_KEY_EMAIL] = email;
338
246
  }
339
247
 
340
248
  _remove_email(email, caller) {
341
- const [value, is_valid] = this.__check_ident_val_string(email, caller);
342
- if (!is_valid) {
343
- return;
344
- }
345
- this.__dict_remove[IDENT_KEY_EMAIL] = value;
249
+ this.__dict_remove[IDENT_KEY_EMAIL] = email;
346
250
  }
347
251
 
348
252
  _add_sms(mobile_no, caller) {
349
- const [value, is_valid] = this.__check_ident_val_string(mobile_no, caller);
350
- if (!is_valid) {
351
- return;
352
- }
353
- this.__dict_append[IDENT_KEY_SMS] = value;
253
+ this.__dict_append[IDENT_KEY_SMS] = mobile_no;
354
254
  }
355
255
 
356
256
  _remove_sms(mobile_no, caller) {
357
- const [value, is_valid] = this.__check_ident_val_string(mobile_no, caller);
358
- if (!is_valid) {
359
- return;
360
- }
361
- this.__dict_remove[IDENT_KEY_SMS] = value;
257
+ this.__dict_remove[IDENT_KEY_SMS] = mobile_no;
362
258
  }
363
259
 
364
260
  _add_whatsapp(mobile_no, caller) {
365
- const [value, is_valid] = this.__check_ident_val_string(mobile_no, caller);
366
- if (!is_valid) {
367
- return;
368
- }
369
- this.__dict_append[IDENT_KEY_WHATSAPP] = value;
261
+ this.__dict_append[IDENT_KEY_WHATSAPP] = mobile_no;
370
262
  }
371
263
 
372
264
  _remove_whatsapp(mobile_no, caller) {
373
- const [value, is_valid] = this.__check_ident_val_string(mobile_no, caller);
374
- if (!is_valid) {
375
- return;
376
- }
377
- this.__dict_remove[IDENT_KEY_WHATSAPP] = value;
265
+ this.__dict_remove[IDENT_KEY_WHATSAPP] = mobile_no;
378
266
  }
379
267
 
380
- // android push methods
381
- __check_androidpush_value(value, provider, caller) {
382
- const [push_token, is_valid] = this.__check_ident_val_string(value, caller);
383
- if (!is_valid) {
384
- return [push_token, provider, false];
385
- }
386
- if (!provider) {
387
- provider = "";
388
- }
389
- if (typeof provider === "string") {
390
- provider = provider.toLocaleLowerCase();
391
- }
392
- return [push_token, provider, true];
268
+ _add_androidpush(push_token, provider, caller) {
269
+ this.__dict_append[IDENT_KEY_ANDROIDPUSH] = push_token;
270
+ this.__dict_append[KEY_ID_PROVIDER] = provider;
393
271
  }
394
272
 
395
- _add_androidpush(push_token, provider = "fcm", caller) {
396
- const [value, vendor, is_valid] = this.__check_androidpush_value(
397
- push_token,
398
- provider,
399
- caller
400
- );
401
- if (!is_valid) {
402
- return;
403
- }
404
- this.__dict_append[IDENT_KEY_ANDROIDPUSH] = value;
405
- this.__dict_append[KEY_ID_PROVIDER] = vendor;
406
- }
407
-
408
- _remove_androidpush(push_token, provider = "fcm") {
409
- const caller = "remove_androidpush";
410
- const [value, vendor, is_valid] = this.__check_androidpush_value(
411
- push_token,
412
- provider,
413
- caller
414
- );
415
- if (!is_valid) {
416
- return;
417
- }
418
- this.__dict_remove[IDENT_KEY_ANDROIDPUSH] = value;
419
- this.__dict_remove[KEY_ID_PROVIDER] = vendor;
273
+ _remove_androidpush(push_token, provider) {
274
+ this.__dict_remove[IDENT_KEY_ANDROIDPUSH] = push_token;
275
+ this.__dict_remove[KEY_ID_PROVIDER] = provider;
420
276
  }
421
277
 
422
- // ios push methods
423
- __check_iospush_value(value, provider, caller) {
424
- const [push_token, is_valid] = this.__check_ident_val_string(value, caller);
425
- if (!is_valid) {
426
- return [push_token, provider, false];
427
- }
428
- if (!provider) {
429
- provider = "";
430
- }
431
- if (typeof provider === "string") {
432
- provider = provider.toLocaleLowerCase();
433
- }
434
- return [push_token, provider, true];
278
+ _add_iospush(push_token, provider, caller) {
279
+ this.__dict_append[IDENT_KEY_IOSPUSH] = push_token;
280
+ this.__dict_append[KEY_ID_PROVIDER] = provider;
435
281
  }
436
282
 
437
- _add_iospush(push_token, provider = "apns", caller) {
438
- const [value, vendor, is_valid] = this.__check_iospush_value(
439
- push_token,
440
- provider,
441
- caller
442
- );
443
- if (!is_valid) {
444
- return;
445
- }
446
- this.__dict_append[IDENT_KEY_IOSPUSH] = value;
447
- this.__dict_append[KEY_ID_PROVIDER] = vendor;
448
- }
449
-
450
- _remove_iospush(push_token, provider = "apns", caller) {
451
- const [value, vendor, is_valid] = this.__check_iospush_value(
452
- push_token,
453
- provider,
454
- caller
455
- );
456
- if (!is_valid) {
457
- return;
458
- }
459
- this.__dict_remove[IDENT_KEY_IOSPUSH] = value;
460
- this.__dict_remove[KEY_ID_PROVIDER] = vendor;
461
- }
462
-
463
- // web push methods
464
- __check_webpush_dict(value, provider, caller) {
465
- if (!is_object(value)) {
466
- this.__errors.push(
467
- `[${caller}] value must be a valid dict representing webpush-token`
468
- );
469
- return [value, provider, false];
470
- }
471
- if (!provider) {
472
- provider = "";
473
- }
474
- if (typeof provider === "string") {
475
- provider = provider.toLocaleLowerCase();
476
- }
477
- return [value, provider, true];
478
- }
479
-
480
- _add_webpush(push_token, provider = "vapid", caller) {
481
- const [value, vendor, is_valid] = this.__check_webpush_dict(
482
- push_token,
483
- provider,
484
- caller
485
- );
486
- if (!is_valid) {
487
- return;
488
- }
489
- this.__dict_append[IDENT_KEY_WEBPUSH] = value;
490
- this.__dict_append[KEY_ID_PROVIDER] = vendor;
283
+ _remove_iospush(push_token, provider, caller) {
284
+ this.__dict_remove[IDENT_KEY_IOSPUSH] = push_token;
285
+ this.__dict_remove[KEY_ID_PROVIDER] = provider;
491
286
  }
492
287
 
493
- _remove_webpush(push_token, provider = "vapid", caller) {
494
- const [value, vendor, is_valid] = this.__check_webpush_dict(
495
- push_token,
496
- provider,
497
- caller
498
- );
499
- if (!is_valid) {
500
- return;
501
- }
502
- this.__dict_remove[IDENT_KEY_WEBPUSH] = value;
503
- this.__dict_remove[KEY_ID_PROVIDER] = vendor;
288
+ _add_webpush(push_token, provider, caller) {
289
+ this.__dict_append[IDENT_KEY_WEBPUSH] = push_token;
290
+ this.__dict_append[KEY_ID_PROVIDER] = provider;
504
291
  }
505
292
 
506
- __check_slack_dict(value, caller) {
507
- const msg = "value must be a valid dict/json with proper keys";
508
- if (!(value && value instanceof Object)) {
509
- this.__errors.push(`[${caller}] ${msg}`);
510
- return [value, false];
511
- } else {
512
- return [value, true];
513
- }
293
+ _remove_webpush(push_token, provider, caller) {
294
+ this.__dict_remove[IDENT_KEY_WEBPUSH] = push_token;
295
+ this.__dict_remove[KEY_ID_PROVIDER] = provider;
514
296
  }
515
297
 
516
298
  _add_slack(value, caller) {
517
- const [validated_value, is_valid] = this.__check_slack_dict(value, caller);
518
- if (!is_valid) {
519
- return;
520
- }
521
- this.__dict_append[IDENT_KEY_SLACK] = validated_value;
299
+ this.__dict_append[IDENT_KEY_SLACK] = value;
522
300
  }
523
301
 
524
302
  _remove_slack(value, caller) {
525
- const [validated_value, is_valid] = this.__check_slack_dict(value, caller);
526
- if (!is_valid) {
527
- return;
528
- }
529
- this.__dict_remove[IDENT_KEY_SLACK] = validated_value;
530
- }
531
-
532
- __check_ms_teams_dict(value, caller) {
533
- const msg = "value must be a valid dict/json with proper keys";
534
- if (!(value && value instanceof Object)) {
535
- this.__errors.push(`[${caller}] ${msg}`);
536
- return [value, false];
537
- } else {
538
- return [value, true];
539
- }
303
+ this.__dict_remove[IDENT_KEY_SLACK] = value;
540
304
  }
541
305
 
542
306
  _add_ms_teams(value, caller) {
543
- const [validated_value, is_valid] = this.__check_ms_teams_dict(
544
- value,
545
- caller
546
- );
547
- if (!is_valid) {
548
- return;
549
- }
550
- this.__dict_append[IDENT_KEY_MS_TEAMS] = validated_value;
307
+ this.__dict_append[IDENT_KEY_MS_TEAMS] = value;
551
308
  }
552
309
 
553
310
  _remove_ms_teams(value, caller) {
554
- const [validated_value, is_valid] = this.__check_ms_teams_dict(
555
- value,
556
- caller
557
- );
558
- if (!is_valid) {
559
- return;
560
- }
561
- this.__dict_remove[IDENT_KEY_MS_TEAMS] = validated_value;
311
+ this.__dict_remove[IDENT_KEY_MS_TEAMS] = value;
562
312
  }
563
313
  }
@@ -10,8 +10,8 @@ import {
10
10
  import get_request_signature from "./signature";
11
11
  import axios from "axios";
12
12
  import {
13
- SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES,
14
- SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
13
+ BODY_MAX_APPARENT_SIZE_IN_BYTES,
14
+ BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE,
15
15
  } from "./constants";
16
16
  import get_attachment_json from "./attachment";
17
17
 
@@ -73,9 +73,9 @@ class SubscriberListBroadcast {
73
73
  }
74
74
  this.body = validate_list_broadcast_body_schema(this.body);
75
75
  const apparent_size = get_apparent_list_broadcast_body_size(this.body);
76
- if (apparent_size > SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
76
+ if (apparent_size > BODY_MAX_APPARENT_SIZE_IN_BYTES) {
77
77
  throw new InputValueError(
78
- `SubscriberListBroadcast body too big - ${apparent_size} Bytes, must not cross ${SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
78
+ `SubscriberListBroadcast body too big - ${apparent_size} Bytes, must not cross ${BODY_MAX_APPARENT_SIZE_IN_BYTES_READABLE}`
79
79
  );
80
80
  }
81
81
  return [this.body, apparent_size];