@suprsend/node-sdk 1.5.0 → 1.6.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/request_json/workflow.json +37 -7
- package/dist/subscriber.js +22 -0
- package/dist/subscriber_helper.js +2 -61
- package/package.json +1 -1
- package/src/request_json/workflow.json +37 -7
- package/src/subscriber.js +24 -0
- package/src/subscriber_helper.js +2 -47
- package/types/index.d.ts +4 -1
|
@@ -84,6 +84,20 @@
|
|
|
84
84
|
"slack_setting": {
|
|
85
85
|
"type": "object",
|
|
86
86
|
"properties": {
|
|
87
|
+
"access_token": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"pattern": "^xox",
|
|
90
|
+
"description": "Bot User OAuth Access Token with prefix xoxb-"
|
|
91
|
+
},
|
|
92
|
+
"channel_id": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"pattern": "^[cC][a-zA-Z0-9]+$",
|
|
95
|
+
"description": "slack channel id. the bot must be part of it",
|
|
96
|
+
"message": {
|
|
97
|
+
"required": "",
|
|
98
|
+
"pattern": "Slack Channel id format: CXXXXXXXXX"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
87
101
|
"user_id": {
|
|
88
102
|
"type": "string",
|
|
89
103
|
"pattern": "^[uUwW][a-zA-Z0-9]+$",
|
|
@@ -93,7 +107,20 @@
|
|
|
93
107
|
"pattern": "Slack Member id format: [U|W]XXXXXXXXX"
|
|
94
108
|
}
|
|
95
109
|
},
|
|
96
|
-
"email": {
|
|
110
|
+
"email": {
|
|
111
|
+
"$ref": "#/definitions/email_pattern"
|
|
112
|
+
},
|
|
113
|
+
"incoming_webhook": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": {
|
|
116
|
+
"url": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"format": "uri",
|
|
119
|
+
"pattern": "^https://hooks.slack.com/",
|
|
120
|
+
"description": "incoming webhook url. e.g https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
97
124
|
},
|
|
98
125
|
"additionalProperties": false
|
|
99
126
|
},
|
|
@@ -136,10 +163,13 @@
|
|
|
136
163
|
"user_setting": {
|
|
137
164
|
"type": "object",
|
|
138
165
|
"properties": {
|
|
166
|
+
"is_transient": {
|
|
167
|
+
"type": ["boolean", "null"],
|
|
168
|
+
"description": "indicates whether this is a transient user. Profiles are not created for such users."
|
|
169
|
+
},
|
|
139
170
|
"distinct_id": {
|
|
140
|
-
"type": "string",
|
|
141
|
-
"
|
|
142
|
-
"description": "distinct_id: Id which uniquely identify a user in your app"
|
|
171
|
+
"type": ["string", "null"],
|
|
172
|
+
"description": "distinct_id: Id which uniquely identifies a user in your app"
|
|
143
173
|
},
|
|
144
174
|
"$channels": {
|
|
145
175
|
"type": "array",
|
|
@@ -285,7 +315,7 @@
|
|
|
285
315
|
]
|
|
286
316
|
}
|
|
287
317
|
},
|
|
288
|
-
"required": [
|
|
318
|
+
"required": [],
|
|
289
319
|
"additionalProperties": false
|
|
290
320
|
},
|
|
291
321
|
"delivery_setting": {
|
|
@@ -299,7 +329,7 @@
|
|
|
299
329
|
"success": {
|
|
300
330
|
"type": "string",
|
|
301
331
|
"default": "seen",
|
|
302
|
-
"description": "possible values: seen/interaction/<user_defined_event>."
|
|
332
|
+
"description": "possible values: delivered/seen/interaction/<user_defined_event>."
|
|
303
333
|
},
|
|
304
334
|
"time_to_live": {
|
|
305
335
|
"type": "string",
|
|
@@ -323,7 +353,7 @@
|
|
|
323
353
|
]
|
|
324
354
|
},
|
|
325
355
|
"minItems": 0,
|
|
326
|
-
"description": "e.g ['email', 'sms']. Used if smart=true, notification on these channels must be sent,
|
|
356
|
+
"description": "e.g ['email', 'sms']. Used if smart=true, notification on these channels must be sent, irrespective of success metric outcome"
|
|
327
357
|
}
|
|
328
358
|
},
|
|
329
359
|
"required": [],
|
package/dist/subscriber.js
CHANGED
|
@@ -461,8 +461,27 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
461
461
|
this._collect_event();
|
|
462
462
|
}
|
|
463
463
|
}, {
|
|
464
|
+
key: "add_slack",
|
|
465
|
+
value: function add_slack(value) {
|
|
466
|
+
var caller = "add_slack";
|
|
467
|
+
|
|
468
|
+
this._helper._add_slack(value, caller);
|
|
469
|
+
|
|
470
|
+
this._collect_event();
|
|
471
|
+
}
|
|
472
|
+
}, {
|
|
473
|
+
key: "remove_slack",
|
|
474
|
+
value: function remove_slack(value) {
|
|
475
|
+
var caller = "remove_slack";
|
|
476
|
+
|
|
477
|
+
this._helper._remove_slack(value, caller);
|
|
478
|
+
|
|
479
|
+
this._collect_event();
|
|
480
|
+
}
|
|
481
|
+
}, {
|
|
464
482
|
key: "add_slack_email",
|
|
465
483
|
value: function add_slack_email(value) {
|
|
484
|
+
console.warn("add_slack_email() method has been deprecated. use add_slack() instead");
|
|
466
485
|
var caller = "add_slack_email";
|
|
467
486
|
|
|
468
487
|
this._helper._add_slack({
|
|
@@ -474,6 +493,7 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
474
493
|
}, {
|
|
475
494
|
key: "remove_slack_email",
|
|
476
495
|
value: function remove_slack_email(value) {
|
|
496
|
+
console.warn("remove_slack_email() method has been deprecated. use remove_slack() instead");
|
|
477
497
|
var caller = "remove_slack_email";
|
|
478
498
|
|
|
479
499
|
this._helper._remove_slack({
|
|
@@ -485,6 +505,7 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
485
505
|
}, {
|
|
486
506
|
key: "add_slack_userid",
|
|
487
507
|
value: function add_slack_userid(value) {
|
|
508
|
+
console.warn("add_slack_userid() method has been deprecated. use add_slack() instead");
|
|
488
509
|
var caller = "add_slack_userid";
|
|
489
510
|
|
|
490
511
|
this._helper._add_slack({
|
|
@@ -496,6 +517,7 @@ var Subscriber = /*#__PURE__*/function () {
|
|
|
496
517
|
}, {
|
|
497
518
|
key: "remove_slack_userid",
|
|
498
519
|
value: function remove_slack_userid(value) {
|
|
520
|
+
console.warn("remove_slack_userid() method has been deprecated. use remove_slack() instead");
|
|
499
521
|
var caller = "remove_slack_userid";
|
|
500
522
|
|
|
501
523
|
this._helper._remove_slack({
|
|
@@ -663,76 +663,17 @@ var _SubscriberInternalHelper = /*#__PURE__*/function () {
|
|
|
663
663
|
this.__dict_remove[IDENT_KEY_WEBPUSH] = value;
|
|
664
664
|
this.__dict_remove[KEY_PUSHVENDOR] = vendor;
|
|
665
665
|
}
|
|
666
|
-
}, {
|
|
667
|
-
key: "__validate_slack_userid",
|
|
668
|
-
value: function __validate_slack_userid(userid, caller) {
|
|
669
|
-
var _this$__check_ident_v9 = this.__check_ident_val_string(userid, caller),
|
|
670
|
-
_this$__check_ident_v10 = (0, _slicedToArray2["default"])(_this$__check_ident_v9, 2),
|
|
671
|
-
validated_userid = _this$__check_ident_v10[0],
|
|
672
|
-
is_valid = _this$__check_ident_v10[1];
|
|
673
|
-
|
|
674
|
-
if (!is_valid) {
|
|
675
|
-
return [validated_userid, false];
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
validated_userid = validated_userid.toUpperCase();
|
|
679
|
-
|
|
680
|
-
if (!validated_userid.startsWith("U") && !validated_userid.startsWith("W")) {
|
|
681
|
-
this.__errors.push("[".concat(caller, "] invalid value ").concat(validated_userid, ". Slack user/member_id starts with a U or W"));
|
|
682
|
-
|
|
683
|
-
return [validated_userid, false];
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
return [validated_userid, true];
|
|
687
|
-
}
|
|
688
666
|
}, {
|
|
689
667
|
key: "__check_slack_dict",
|
|
690
668
|
value: function __check_slack_dict(value, caller) {
|
|
691
|
-
var msg = "value must be a valid dict/json with
|
|
669
|
+
var msg = "value must be a valid dict/json with proper keys";
|
|
692
670
|
|
|
693
671
|
if (!(value && value instanceof Object)) {
|
|
694
672
|
this.__errors.push("[".concat(caller, "] ").concat(msg));
|
|
695
673
|
|
|
696
674
|
return [value, false];
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
var user_id = value.user_id;
|
|
700
|
-
var email = value.email;
|
|
701
|
-
|
|
702
|
-
if (user_id && user_id.trim()) {
|
|
703
|
-
user_id = user_id.trim();
|
|
704
|
-
|
|
705
|
-
var _this$__validate_slac = this.__validate_slack_userid(user_id, caller),
|
|
706
|
-
_this$__validate_slac2 = (0, _slicedToArray2["default"])(_this$__validate_slac, 2),
|
|
707
|
-
validated_user_id = _this$__validate_slac2[0],
|
|
708
|
-
is_valid = _this$__validate_slac2[1];
|
|
709
|
-
|
|
710
|
-
if (!is_valid) {
|
|
711
|
-
return [value, false];
|
|
712
|
-
} else {
|
|
713
|
-
return [{
|
|
714
|
-
user_id: validated_user_id
|
|
715
|
-
}, true];
|
|
716
|
-
}
|
|
717
|
-
} else if (email && email.trim()) {
|
|
718
|
-
email = email.trim();
|
|
719
|
-
|
|
720
|
-
var _this$__validate_emai5 = this.__validate_email(email, caller),
|
|
721
|
-
_this$__validate_emai6 = (0, _slicedToArray2["default"])(_this$__validate_emai5, 2),
|
|
722
|
-
validated_email = _this$__validate_emai6[0],
|
|
723
|
-
_is_valid = _this$__validate_emai6[1];
|
|
724
|
-
|
|
725
|
-
if (!_is_valid) {
|
|
726
|
-
return [value, false];
|
|
727
|
-
} else {
|
|
728
|
-
return [{
|
|
729
|
-
email: validated_email
|
|
730
|
-
}, true];
|
|
731
|
-
}
|
|
732
675
|
} else {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
return [value, false];
|
|
676
|
+
return [value, true];
|
|
736
677
|
}
|
|
737
678
|
}
|
|
738
679
|
}, {
|
package/package.json
CHANGED
|
@@ -84,6 +84,20 @@
|
|
|
84
84
|
"slack_setting": {
|
|
85
85
|
"type": "object",
|
|
86
86
|
"properties": {
|
|
87
|
+
"access_token": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"pattern": "^xox",
|
|
90
|
+
"description": "Bot User OAuth Access Token with prefix xoxb-"
|
|
91
|
+
},
|
|
92
|
+
"channel_id": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"pattern": "^[cC][a-zA-Z0-9]+$",
|
|
95
|
+
"description": "slack channel id. the bot must be part of it",
|
|
96
|
+
"message": {
|
|
97
|
+
"required": "",
|
|
98
|
+
"pattern": "Slack Channel id format: CXXXXXXXXX"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
87
101
|
"user_id": {
|
|
88
102
|
"type": "string",
|
|
89
103
|
"pattern": "^[uUwW][a-zA-Z0-9]+$",
|
|
@@ -93,7 +107,20 @@
|
|
|
93
107
|
"pattern": "Slack Member id format: [U|W]XXXXXXXXX"
|
|
94
108
|
}
|
|
95
109
|
},
|
|
96
|
-
"email": {
|
|
110
|
+
"email": {
|
|
111
|
+
"$ref": "#/definitions/email_pattern"
|
|
112
|
+
},
|
|
113
|
+
"incoming_webhook": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": {
|
|
116
|
+
"url": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"format": "uri",
|
|
119
|
+
"pattern": "^https://hooks.slack.com/",
|
|
120
|
+
"description": "incoming webhook url. e.g https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
97
124
|
},
|
|
98
125
|
"additionalProperties": false
|
|
99
126
|
},
|
|
@@ -136,10 +163,13 @@
|
|
|
136
163
|
"user_setting": {
|
|
137
164
|
"type": "object",
|
|
138
165
|
"properties": {
|
|
166
|
+
"is_transient": {
|
|
167
|
+
"type": ["boolean", "null"],
|
|
168
|
+
"description": "indicates whether this is a transient user. Profiles are not created for such users."
|
|
169
|
+
},
|
|
139
170
|
"distinct_id": {
|
|
140
|
-
"type": "string",
|
|
141
|
-
"
|
|
142
|
-
"description": "distinct_id: Id which uniquely identify a user in your app"
|
|
171
|
+
"type": ["string", "null"],
|
|
172
|
+
"description": "distinct_id: Id which uniquely identifies a user in your app"
|
|
143
173
|
},
|
|
144
174
|
"$channels": {
|
|
145
175
|
"type": "array",
|
|
@@ -285,7 +315,7 @@
|
|
|
285
315
|
]
|
|
286
316
|
}
|
|
287
317
|
},
|
|
288
|
-
"required": [
|
|
318
|
+
"required": [],
|
|
289
319
|
"additionalProperties": false
|
|
290
320
|
},
|
|
291
321
|
"delivery_setting": {
|
|
@@ -299,7 +329,7 @@
|
|
|
299
329
|
"success": {
|
|
300
330
|
"type": "string",
|
|
301
331
|
"default": "seen",
|
|
302
|
-
"description": "possible values: seen/interaction/<user_defined_event>."
|
|
332
|
+
"description": "possible values: delivered/seen/interaction/<user_defined_event>."
|
|
303
333
|
},
|
|
304
334
|
"time_to_live": {
|
|
305
335
|
"type": "string",
|
|
@@ -323,7 +353,7 @@
|
|
|
323
353
|
]
|
|
324
354
|
},
|
|
325
355
|
"minItems": 0,
|
|
326
|
-
"description": "e.g ['email', 'sms']. Used if smart=true, notification on these channels must be sent,
|
|
356
|
+
"description": "e.g ['email', 'sms']. Used if smart=true, notification on these channels must be sent, irrespective of success metric outcome"
|
|
327
357
|
}
|
|
328
358
|
},
|
|
329
359
|
"required": [],
|
package/src/subscriber.js
CHANGED
|
@@ -315,25 +315,49 @@ export class Subscriber {
|
|
|
315
315
|
this._collect_event();
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
add_slack(value) {
|
|
319
|
+
const caller = "add_slack";
|
|
320
|
+
this._helper._add_slack(value, caller);
|
|
321
|
+
this._collect_event();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
remove_slack(value) {
|
|
325
|
+
const caller = "remove_slack";
|
|
326
|
+
this._helper._remove_slack(value, caller);
|
|
327
|
+
this._collect_event();
|
|
328
|
+
}
|
|
329
|
+
|
|
318
330
|
add_slack_email(value) {
|
|
331
|
+
console.warn(
|
|
332
|
+
"add_slack_email() method has been deprecated. use add_slack() instead"
|
|
333
|
+
);
|
|
319
334
|
const caller = "add_slack_email";
|
|
320
335
|
this._helper._add_slack({ email: value }, caller);
|
|
321
336
|
this._collect_event();
|
|
322
337
|
}
|
|
323
338
|
|
|
324
339
|
remove_slack_email(value) {
|
|
340
|
+
console.warn(
|
|
341
|
+
"remove_slack_email() method has been deprecated. use remove_slack() instead"
|
|
342
|
+
);
|
|
325
343
|
const caller = "remove_slack_email";
|
|
326
344
|
this._helper._remove_slack({ email: value }, caller);
|
|
327
345
|
this._collect_event();
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
add_slack_userid(value) {
|
|
349
|
+
console.warn(
|
|
350
|
+
"add_slack_userid() method has been deprecated. use add_slack() instead"
|
|
351
|
+
);
|
|
331
352
|
const caller = "add_slack_userid";
|
|
332
353
|
this._helper._add_slack({ user_id: value }, caller);
|
|
333
354
|
this._collect_event();
|
|
334
355
|
}
|
|
335
356
|
|
|
336
357
|
remove_slack_userid(value) {
|
|
358
|
+
console.warn(
|
|
359
|
+
"remove_slack_userid() method has been deprecated. use remove_slack() instead"
|
|
360
|
+
);
|
|
337
361
|
const caller = "remove_slack_userid";
|
|
338
362
|
this._helper._remove_slack({ user_id: value }, caller);
|
|
339
363
|
this._collect_event();
|
package/src/subscriber_helper.js
CHANGED
|
@@ -515,58 +515,13 @@ export default class _SubscriberInternalHelper {
|
|
|
515
515
|
this.__dict_remove[KEY_PUSHVENDOR] = vendor;
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
-
__validate_slack_userid(userid, caller) {
|
|
519
|
-
let [validated_userid, is_valid] = this.__check_ident_val_string(
|
|
520
|
-
userid,
|
|
521
|
-
caller
|
|
522
|
-
);
|
|
523
|
-
if (!is_valid) {
|
|
524
|
-
return [validated_userid, false];
|
|
525
|
-
}
|
|
526
|
-
validated_userid = validated_userid.toUpperCase();
|
|
527
|
-
if (
|
|
528
|
-
!validated_userid.startsWith("U") &&
|
|
529
|
-
!validated_userid.startsWith("W")
|
|
530
|
-
) {
|
|
531
|
-
this.__errors.push(
|
|
532
|
-
`[${caller}] invalid value ${validated_userid}. Slack user/member_id starts with a U or W`
|
|
533
|
-
);
|
|
534
|
-
return [validated_userid, false];
|
|
535
|
-
}
|
|
536
|
-
return [validated_userid, true];
|
|
537
|
-
}
|
|
538
|
-
|
|
539
518
|
__check_slack_dict(value, caller) {
|
|
540
|
-
const msg =
|
|
541
|
-
"value must be a valid dict/json with one of these keys: [email, user_id]";
|
|
519
|
+
const msg = "value must be a valid dict/json with proper keys";
|
|
542
520
|
if (!(value && value instanceof Object)) {
|
|
543
521
|
this.__errors.push(`[${caller}] ${msg}`);
|
|
544
522
|
return [value, false];
|
|
545
|
-
}
|
|
546
|
-
let user_id = value.user_id;
|
|
547
|
-
let email = value.email;
|
|
548
|
-
if (user_id && user_id.trim()) {
|
|
549
|
-
user_id = user_id.trim();
|
|
550
|
-
let [validated_user_id, is_valid] = this.__validate_slack_userid(
|
|
551
|
-
user_id,
|
|
552
|
-
caller
|
|
553
|
-
);
|
|
554
|
-
if (!is_valid) {
|
|
555
|
-
return [value, false];
|
|
556
|
-
} else {
|
|
557
|
-
return [{ user_id: validated_user_id }, true];
|
|
558
|
-
}
|
|
559
|
-
} else if (email && email.trim()) {
|
|
560
|
-
email = email.trim();
|
|
561
|
-
let [validated_email, is_valid] = this.__validate_email(email, caller);
|
|
562
|
-
if (!is_valid) {
|
|
563
|
-
return [value, false];
|
|
564
|
-
} else {
|
|
565
|
-
return [{ email: validated_email }, true];
|
|
566
|
-
}
|
|
567
523
|
} else {
|
|
568
|
-
|
|
569
|
-
return [value, false];
|
|
524
|
+
return [value, true];
|
|
570
525
|
}
|
|
571
526
|
}
|
|
572
527
|
|
package/types/index.d.ts
CHANGED
|
@@ -94,6 +94,9 @@ declare namespace suprsend {
|
|
|
94
94
|
add_webpush(push_token: Dictionary, provider?: string): void;
|
|
95
95
|
remove_webpush(push_token: Dictionary, provider?: string): void;
|
|
96
96
|
|
|
97
|
+
add_slack(value: Dictionary): void;
|
|
98
|
+
remove_slack(value: Dictionary): void;
|
|
99
|
+
|
|
97
100
|
add_slack_email(email: string): void;
|
|
98
101
|
remove_slack_email(email: string): void;
|
|
99
102
|
|
|
@@ -154,7 +157,7 @@ declare namespace suprsend {
|
|
|
154
157
|
new (
|
|
155
158
|
workspace_env: string,
|
|
156
159
|
workspace_secret: string,
|
|
157
|
-
config
|
|
160
|
+
config?: { is_staging?: boolean }
|
|
158
161
|
): Suprsend;
|
|
159
162
|
|
|
160
163
|
get bulk_workflows(): BulkWorkflowsFactory;
|