@suprsend/node-sdk 1.8.2 → 1.9.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.
package/dist/workflow.js CHANGED
@@ -27,6 +27,7 @@ var Workflow = /*#__PURE__*/function () {
27
27
  }
28
28
  this.body = body;
29
29
  this.idempotency_key = kwargs === null || kwargs === void 0 ? void 0 : kwargs.idempotency_key;
30
+ this.tenant_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.tenant_id;
30
31
  this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id;
31
32
  }
32
33
  (0, _createClass2["default"])(Workflow, [{
@@ -62,6 +63,9 @@ var Workflow = /*#__PURE__*/function () {
62
63
  if (this.idempotency_key) {
63
64
  this.body["$idempotency_key"] = this.idempotency_key;
64
65
  }
66
+ if (this.tenant_id) {
67
+ this.body["tenant_id"] = this.tenant_id;
68
+ }
65
69
  if (this.brand_id) {
66
70
  this.body["brand_id"] = this.brand_id;
67
71
  }
@@ -79,6 +83,9 @@ var Workflow = /*#__PURE__*/function () {
79
83
  if (this.idempotency_key) {
80
84
  body_dict["$idempotency_key"] = this.idempotency_key;
81
85
  }
86
+ if (this.tenant_id) {
87
+ body_dict["tenant_id"] = this.tenant_id;
88
+ }
82
89
  if (this.brand_id) {
83
90
  body_dict["brand_id"] = this.brand_id;
84
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/node-sdk",
3
- "version": "1.8.2",
3
+ "version": "1.9.1",
4
4
  "description": "Suprsend Node SDK to trigger workflow from backend",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,7 +25,7 @@
25
25
  "types": "types/index.d.ts",
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.16.3",
28
- "axios": "^0.27.2",
28
+ "axios": "^1.6.0",
29
29
  "jsonschema": "^1.4.0",
30
30
  "lodash": "^4.17.21",
31
31
  "mime-types": "^2.1.34",
package/src/event.js CHANGED
@@ -32,6 +32,7 @@ export default class Event {
32
32
  this.event_name = event_name;
33
33
  this.properties = properties;
34
34
  this.idempotency_key = kwargs?.idempotency_key;
35
+ this.tenant_id = kwargs?.tenant_id;
35
36
  this.brand_id = kwargs?.brand_id;
36
37
 
37
38
  // default values
@@ -128,6 +129,9 @@ export default class Event {
128
129
  if (this.idempotency_key) {
129
130
  event_dict["$idempotency_key"] = this.idempotency_key;
130
131
  }
132
+ if (this.tenant_id) {
133
+ event_dict["tenant_id"] = this.tenant_id;
134
+ }
131
135
  if (this.brand_id) {
132
136
  event_dict["brand_id"] = this.brand_id;
133
137
  }
@@ -150,6 +154,9 @@ export default class Event {
150
154
  if (this.idempotency_key) {
151
155
  event_dict["$idempotency_key"] = this.idempotency_key;
152
156
  }
157
+ if (this.tenant_id) {
158
+ event_dict["tenant_id"] = this.tenant_id;
159
+ }
153
160
  if (this.brand_id) {
154
161
  event_dict["brand_id"] = this.brand_id;
155
162
  }
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ import SubscriberFactory from "./subscriber";
8
8
  import BulkSubscribersFactory from "./subscribers_bulk";
9
9
  import { SubscriberListsApi, SubscriberListBroadcast } from "./subscriber_list";
10
10
  import BrandsApi from "./brands";
11
+ import TenantsApi from "./tenant";
11
12
  import { DEFAULT_UAT_URL, DEFAULT_URL } from "./constants";
12
13
 
13
14
  const package_json = require("../package.json");
@@ -33,6 +34,8 @@ class Suprsend {
33
34
  this._user = new SubscriberFactory(this);
34
35
 
35
36
  this.brands = new BrandsApi(this);
37
+ this.tenants = new TenantsApi(this);
38
+
36
39
  this.subscriber_lists = new SubscriberListsApi(this);
37
40
 
38
41
  this._validate();
@@ -11,6 +11,11 @@
11
11
  "maxLength": 255,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "tenant_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "tenant id for workflow to be run in context of a tenant"
18
+ },
14
19
  "brand_id": {
15
20
  "type": ["string", "null"],
16
21
  "maxLength": 64,
@@ -11,6 +11,11 @@
11
11
  "maxLength": 255,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "tenant_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "tenant id for workflow to be run in context of a tenant"
18
+ },
14
19
  "brand_id": {
15
20
  "type": ["string", "null"],
16
21
  "maxLength": 64,
@@ -44,7 +49,8 @@
44
49
  "whatsapp",
45
50
  "slack",
46
51
  "inbox",
47
- "messenger"
52
+ "messenger",
53
+ "ms_teams"
48
54
  ]
49
55
  },
50
56
  "minItems": 0,
@@ -11,6 +11,11 @@
11
11
  "maxLength": 255,
12
12
  "description": "unique id provided by client for request"
13
13
  },
14
+ "tenant_id": {
15
+ "type": ["string", "null"],
16
+ "maxLength": 64,
17
+ "description": "tenant id for workflow to be run in context of a tenant"
18
+ },
14
19
  "brand_id": {
15
20
  "type": ["string", "null"],
16
21
  "maxLength": 64,
@@ -124,6 +129,40 @@
124
129
  },
125
130
  "additionalProperties": false
126
131
  },
132
+ "ms_teams_setting": {
133
+ "type": "object",
134
+ "properties": {
135
+ "tenant_id": {
136
+ "type": "string",
137
+ "description": "ms teams tenant id"
138
+ },
139
+ "service_url": {
140
+ "type": "string",
141
+ "format": "uri",
142
+ "pattern": "^https://smba.trafficmanager.net/",
143
+ "description": "service webhook url. e.g https://smba.trafficmanager.net/XXXXXXXXXX"
144
+ },
145
+ "conversation_id": {
146
+ "type": "string",
147
+ "description": "ms team conversation id"
148
+ },
149
+ "user_id": {
150
+ "type": "string",
151
+ "description": "ms team user id"
152
+ },
153
+ "incoming_webhook": {
154
+ "type": "object",
155
+ "properties": {
156
+ "url": {
157
+ "type": "string",
158
+ "format": "uri",
159
+ "description": "incoming webhook url. e.g https://XXXXX.webhook.office.com/webhookb2/XXXXXXXXXX@XXXXXXXXXX/IncomingWebhook/XXXXXXXXXX/XXXXXXXXXX"
160
+ }
161
+ }
162
+ }
163
+ },
164
+ "additionalProperties": false
165
+ },
127
166
  "androidpush_settings": {
128
167
  "type": "object",
129
168
  "properties": {
@@ -171,6 +210,10 @@
171
210
  "type": ["string", "null"],
172
211
  "description": "distinct_id: Id which uniquely identifies a user in your app"
173
212
  },
213
+ "$preferred_language": {
214
+ "type": ["string", "null"],
215
+ "description": "preferred_language: 2-letter language code in ISO 639-1 Alpha-2 code format. e.g en (for English)"
216
+ },
174
217
  "$channels": {
175
218
  "type": "array",
176
219
  "items": {
@@ -184,7 +227,8 @@
184
227
  "whatsapp",
185
228
  "slack",
186
229
  "inbox",
187
- "messenger"
230
+ "messenger",
231
+ "ms_teams"
188
232
  ]
189
233
  },
190
234
  "minItems": 0,
@@ -290,6 +334,18 @@
290
334
  }
291
335
  ]
292
336
  },
337
+ "$ms_teams": {
338
+ "oneOf": [
339
+ { "$ref": "#/definitions/ms_teams_setting" },
340
+ {
341
+ "type": "array",
342
+ "uniqueItems": false,
343
+ "maxItems": 10,
344
+ "minItems": 1,
345
+ "items": { "$ref": "#/definitions/ms_teams_setting" }
346
+ }
347
+ ]
348
+ },
293
349
  "$inbox": {
294
350
  "oneOf": [
295
351
  { "$ref": "#/definitions/non_empty_string" },
@@ -315,8 +371,7 @@
315
371
  ]
316
372
  }
317
373
  },
318
- "required": [],
319
- "additionalProperties": false
374
+ "required": []
320
375
  },
321
376
  "delivery_setting": {
322
377
  "type": "object",
@@ -349,7 +404,8 @@
349
404
  "whatsapp",
350
405
  "slack",
351
406
  "inbox",
352
- "messenger"
407
+ "messenger",
408
+ "ms_teams"
353
409
  ]
354
410
  },
355
411
  "minItems": 0,
package/src/subscriber.js CHANGED
@@ -208,6 +208,78 @@ export class Subscriber {
208
208
  }
209
209
  }
210
210
 
211
+ set(key, value) {
212
+ const caller = "set";
213
+ if (!is_string(key) && !is_object(key)) {
214
+ this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
215
+ return;
216
+ }
217
+ if (is_string(key)) {
218
+ if (value === null || value === undefined) {
219
+ this.__errors.push(
220
+ `[${caller}] if arg1 is a string, then arg2 must be passed`
221
+ );
222
+ return;
223
+ } else {
224
+ this._helper._set_kv(key, value, {}, caller);
225
+ this._collect_event();
226
+ }
227
+ } else {
228
+ for (let item in key) {
229
+ this._helper._set_kv(item, key[item], key, caller);
230
+ }
231
+ this._collect_event();
232
+ }
233
+ }
234
+
235
+ set_once(key, value) {
236
+ const caller = "set_once";
237
+ if (!is_string(key) && !is_object(key)) {
238
+ this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
239
+ return;
240
+ }
241
+ if (is_string(key)) {
242
+ if (value === null || value === undefined) {
243
+ this.__errors.push(
244
+ `[${caller}] if arg1 is a string, then arg2 must be passed`
245
+ );
246
+ return;
247
+ } else {
248
+ this._helper._set_once_kv(key, value, {}, caller);
249
+ this._collect_event();
250
+ }
251
+ } else {
252
+ for (let item in key) {
253
+ this._helper._set_once_kv(item, key[item], key, caller);
254
+ }
255
+ this._collect_event();
256
+ }
257
+ }
258
+
259
+ increment(key, value) {
260
+ const caller = "increment";
261
+ if (!is_string(key) && !is_object(key)) {
262
+ this.__errors.push(`[${caller}] arg1 must be either string or a dict`);
263
+ return;
264
+ }
265
+ if (is_string(key)) {
266
+ if (value === null || value === undefined) {
267
+ this.__errors.push(
268
+ `[${caller}] if arg1 is a string, then arg2 must be passed`
269
+ );
270
+ return;
271
+ } else {
272
+ this._helper._increment_kv(key, value, {}, caller);
273
+ this._collect_event();
274
+ }
275
+ } else {
276
+ for (let item in key) {
277
+ this._helper._increment_kv(item, key[item], key, caller);
278
+ }
279
+ this._collect_event();
280
+ }
281
+ }
282
+
211
283
  remove(key, value) {
212
284
  const caller = "remove";
213
285
  if (!is_string(key) && !is_object(key)) {
@@ -339,6 +411,18 @@ export class Subscriber {
339
411
  this._collect_event();
340
412
  }
341
413
 
414
+ add_ms_teams(value) {
415
+ const caller = "add_ms_teams";
416
+ this._helper._add_ms_teams(value, caller);
417
+ this._collect_event();
418
+ }
419
+
420
+ remove_ms_teams(value) {
421
+ const caller = "remove_ms_teams";
422
+ this._helper._remove_ms_teams(value, caller);
423
+ this._collect_event();
424
+ }
425
+
342
426
  add_slack_email(value) {
343
427
  console.warn(
344
428
  "add_slack_email() method has been deprecated. use add_slack() instead"
@@ -16,6 +16,7 @@ const IDENT_KEY_IOSPUSH = "$iospush";
16
16
  const IDENT_KEY_WHATSAPP = "$whatsapp";
17
17
  const IDENT_KEY_WEBPUSH = "$webpush";
18
18
  const IDENT_KEY_SLACK = "$slack";
19
+ const IDENT_KEY_MS_TEAMS = "$ms_teams";
19
20
 
20
21
  const IDENT_KEYS_ALL = [
21
22
  IDENT_KEY_EMAIL,
@@ -25,6 +26,7 @@ const IDENT_KEYS_ALL = [
25
26
  IDENT_KEY_WHATSAPP,
26
27
  IDENT_KEY_WEBPUSH,
27
28
  IDENT_KEY_SLACK,
29
+ IDENT_KEY_MS_TEAMS,
28
30
  ];
29
31
 
30
32
  const KEY_PUSHVENDOR = "$pushvendor";
@@ -81,6 +83,10 @@ export default class _SubscriberInternalHelper {
81
83
 
82
84
  this.__dict_set = {};
83
85
 
86
+ this.__dict_set_once = {};
87
+
88
+ this.__dict_increment = {};
89
+
84
90
  this.__dict_append = {};
85
91
 
86
92
  this.__dict_remove = {};
@@ -93,6 +99,8 @@ export default class _SubscriberInternalHelper {
93
99
 
94
100
  reset() {
95
101
  this.__dict_set = {};
102
+ this.__dict_set_once = {};
103
+ this.__dict_increment = {};
96
104
  this.__dict_append = {};
97
105
  this.__dict_remove = {};
98
106
  this.__list_unset = [];
@@ -116,6 +124,12 @@ export default class _SubscriberInternalHelper {
116
124
  if (!is_empty(this.__dict_set)) {
117
125
  event["$set"] = this.__dict_set;
118
126
  }
127
+ if (!is_empty(this.__dict_set_once)) {
128
+ event["$set_once"] = this.__dict_set_once;
129
+ }
130
+ if (!is_empty(this.__dict_increment)) {
131
+ event["$add"] = this.__dict_increment;
132
+ }
119
133
  if (!is_empty(this.__dict_append)) {
120
134
  event["$append"] = this.__dict_append;
121
135
  }
@@ -174,6 +188,42 @@ export default class _SubscriberInternalHelper {
174
188
  }
175
189
  }
176
190
 
191
+ _set_kv(key, value, args = {}, caller = "set") {
192
+ const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
193
+ if (!is_k_valid) {
194
+ return;
195
+ } else {
196
+ const is_k_valid = this.__validate_key_prefix(validated_key, caller);
197
+ if (is_k_valid) {
198
+ this.__dict_set[validated_key] = value;
199
+ }
200
+ }
201
+ }
202
+
203
+ _set_once_kv(key, value, args = {}, caller = "set_once") {
204
+ const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
205
+ if (!is_k_valid) {
206
+ return;
207
+ } else {
208
+ const is_k_valid = this.__validate_key_prefix(validated_key, caller);
209
+ if (is_k_valid) {
210
+ this.__dict_set_once[validated_key] = value;
211
+ }
212
+ }
213
+ }
214
+
215
+ _increment_kv(key, value, args = {}, caller = "increment") {
216
+ const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
217
+ if (!is_k_valid) {
218
+ return;
219
+ } else {
220
+ const is_k_valid = this.__validate_key_prefix(validated_key, caller);
221
+ if (is_k_valid) {
222
+ this.__dict_increment[validated_key] = value;
223
+ }
224
+ }
225
+ }
226
+
177
227
  _remove_kv(key, value, args = {}, caller = "remove") {
178
228
  const [validated_key, is_k_valid] = this.__validate_key_basic(key, caller);
179
229
  if (!is_k_valid) {
@@ -229,6 +279,9 @@ export default class _SubscriberInternalHelper {
229
279
  case IDENT_KEY_SLACK:
230
280
  this._add_slack(value, caller);
231
281
  break;
282
+ case IDENT_KEY_MS_TEAMS:
283
+ this._add_ms_teams(value, caller);
284
+ break;
232
285
  default:
233
286
  break;
234
287
  }
@@ -258,6 +311,9 @@ export default class _SubscriberInternalHelper {
258
311
  case IDENT_KEY_SLACK:
259
312
  this._remove_slack(val, caller);
260
313
  break;
314
+ case IDENT_KEY_MS_TEAMS:
315
+ this._remove_ms_teams(val, caller);
316
+ break;
261
317
  default:
262
318
  break;
263
319
  }
@@ -540,4 +596,36 @@ export default class _SubscriberInternalHelper {
540
596
  }
541
597
  this.__dict_remove[IDENT_KEY_SLACK] = validated_value;
542
598
  }
599
+
600
+ __check_ms_teams_dict(value, caller) {
601
+ const msg = "value must be a valid dict/json with proper keys";
602
+ if (!(value && value instanceof Object)) {
603
+ this.__errors.push(`[${caller}] ${msg}`);
604
+ return [value, false];
605
+ } else {
606
+ return [value, true];
607
+ }
608
+ }
609
+
610
+ _add_ms_teams(value, caller) {
611
+ const [validated_value, is_valid] = this.__check_ms_teams_dict(
612
+ value,
613
+ caller
614
+ );
615
+ if (!is_valid) {
616
+ return;
617
+ }
618
+ this.__dict_append[IDENT_KEY_MS_TEAMS] = validated_value;
619
+ }
620
+
621
+ _remove_ms_teams(value, caller) {
622
+ const [validated_value, is_valid] = this.__check_ms_teams_dict(
623
+ value,
624
+ caller
625
+ );
626
+ if (!is_valid) {
627
+ return;
628
+ }
629
+ this.__dict_remove[IDENT_KEY_MS_TEAMS] = validated_value;
630
+ }
543
631
  }