@suprsend/node-sdk 1.8.1 → 1.9.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.
@@ -1,83 +1,60 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.SubscriberListsApi = exports.SubscriberListBroadcast = void 0;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
-
18
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
-
20
13
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
21
-
22
14
  var _utils = require("./utils");
23
-
24
15
  var _signature = _interopRequireDefault(require("./signature"));
25
-
26
16
  var _axios = _interopRequireDefault(require("axios"));
27
-
28
17
  var _constants = require("./constants");
29
-
30
18
  var _attachment = _interopRequireDefault(require("./attachment"));
31
-
32
19
  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; }
33
-
34
20
  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; }
35
-
36
21
  var SubscriberListBroadcast = /*#__PURE__*/function () {
37
22
  function SubscriberListBroadcast(body) {
38
23
  var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
39
24
  (0, _classCallCheck2["default"])(this, SubscriberListBroadcast);
40
-
41
25
  if (!(body instanceof Object)) {
42
26
  throw new _utils.InputValueError("broadcast body must be a json/dictionary");
43
27
  }
44
-
45
28
  this.body = body;
46
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;
47
31
  this.brand_id = kwargs === null || kwargs === void 0 ? void 0 : kwargs.brand_id;
48
32
  }
49
-
50
33
  (0, _createClass2["default"])(SubscriberListBroadcast, [{
51
34
  key: "add_attachment",
52
35
  value: function add_attachment(file_path) {
53
36
  var _kwargs$ignore_if_err, _this$body, _this$body$data;
54
-
55
37
  var kwargs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
56
38
  var file_name = kwargs === null || kwargs === void 0 ? void 0 : kwargs.file_name;
57
39
  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
40
  if (!((_this$body = this.body) !== null && _this$body !== void 0 && _this$body["data"])) {
60
41
  this.body["data"] = {};
61
- } // if body["data"] is not a dict, not raising error while adding attachment.
62
-
63
-
42
+ }
43
+ // if body["data"] is not a dict, not raising error while adding attachment.
64
44
  if (!(this.body["data"] instanceof Object)) {
65
45
  console.log("WARNING: attachment cannot be added. please make sure body['data'] is a dictionary. " + "SubscriberListBroadcast" + JSON.stringify(this.as_json()));
66
46
  return;
67
47
  }
68
-
69
48
  var attachment = (0, _attachment["default"])(file_path, file_name, ignore_if_error);
70
-
71
49
  if (!attachment) {
72
50
  return;
73
- } // --- add the attachment to body->data->$attachments
74
-
51
+ }
75
52
 
53
+ // --- add the attachment to body->data->$attachments
76
54
  if (!((_this$body$data = this.body["data"]) !== null && _this$body$data !== void 0 && _this$body$data["$attachments"])) {
77
55
  this.body["data"]["$attachments"] = [];
78
- } // -----
79
-
80
-
56
+ }
57
+ // -----
81
58
  this.body["data"]["$attachments"].push(attachment);
82
59
  }
83
60
  }, {
@@ -85,46 +62,42 @@ var SubscriberListBroadcast = /*#__PURE__*/function () {
85
62
  value: function get_final_json() {
86
63
  this.body["$insert_id"] = (0, _utils.uuid)();
87
64
  this.body["$time"] = (0, _utils.epoch_milliseconds)();
88
-
89
65
  if (this.idempotency_key) {
90
66
  this.body["$idempotency_key"] = this.idempotency_key;
91
67
  }
92
-
68
+ if (this.tenant_id) {
69
+ this.body["tenant_id"] = this.tenant_id;
70
+ }
93
71
  if (this.brand_id) {
94
72
  this.body["brand_id"] = this.brand_id;
95
73
  }
96
-
97
74
  this.body = (0, _utils.validate_list_broadcast_body_schema)(this.body);
98
75
  var apparent_size = (0, _utils.get_apparent_list_broadcast_body_size)(this.body);
99
-
100
76
  if (apparent_size > _constants.SINGLE_EVENT_MAX_APPARENT_SIZE_IN_BYTES) {
101
77
  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));
102
78
  }
103
-
104
79
  return [this.body, apparent_size];
105
80
  }
106
81
  }, {
107
82
  key: "as_json",
108
83
  value: function as_json() {
109
84
  var body_dict = _objectSpread({}, this.body);
110
-
111
85
  if (this.idempotency_key) {
112
86
  body_dict["$idempotency_key"] = this.idempotency_key;
113
87
  }
114
-
88
+ if (this.tenant_id) {
89
+ body_dict["tenant_id"] = this.tenant_id;
90
+ }
115
91
  if (this.brand_id) {
116
92
  body_dict["brand_id"] = this.brand_id;
117
- } // -----
118
-
119
-
93
+ }
94
+ // -----
120
95
  return body_dict;
121
96
  }
122
97
  }]);
123
98
  return SubscriberListBroadcast;
124
99
  }();
125
-
126
100
  exports.SubscriberListBroadcast = SubscriberListBroadcast;
127
-
128
101
  var SubscriberListsApi = /*#__PURE__*/function () {
129
102
  function SubscriberListsApi(config) {
130
103
  (0, _classCallCheck2["default"])(this, SubscriberListsApi);
@@ -136,7 +109,6 @@ var SubscriberListsApi = /*#__PURE__*/function () {
136
109
  success: true
137
110
  };
138
111
  }
139
-
140
112
  (0, _createClass2["default"])(SubscriberListsApi, [{
141
113
  key: "__common_headers",
142
114
  value: function __common_headers() {
@@ -158,13 +130,10 @@ var SubscriberListsApi = /*#__PURE__*/function () {
158
130
  if (typeof list_id != "string") {
159
131
  throw new _utils.SuprsendError("list_id must be a string");
160
132
  }
161
-
162
133
  var cleaned_list_id = list_id.trim();
163
-
164
134
  if (!cleaned_list_id) {
165
135
  throw new _utils.SuprsendError("missing list_id");
166
136
  }
167
-
168
137
  return list_id;
169
138
  }
170
139
  }, {
@@ -180,19 +149,14 @@ var SubscriberListsApi = /*#__PURE__*/function () {
180
149
  _context.next = 2;
181
150
  break;
182
151
  }
183
-
184
152
  throw new _utils.SuprsendError("missing payload");
185
-
186
153
  case 2:
187
154
  list_id = payload["list_id"];
188
-
189
155
  if (list_id) {
190
156
  _context.next = 5;
191
157
  break;
192
158
  }
193
-
194
159
  throw new _utils.SuprsendError("missing list_id in payload");
195
-
196
160
  case 5:
197
161
  list_id = this._validate_list_id(list_id);
198
162
  payload["list_id"] = list_id;
@@ -205,16 +169,13 @@ var SubscriberListsApi = /*#__PURE__*/function () {
205
169
  return _axios["default"].post(this.subscriber_list_url, content_text, {
206
170
  headers: headers
207
171
  });
208
-
209
172
  case 14:
210
173
  response = _context.sent;
211
174
  return _context.abrupt("return", response.data);
212
-
213
175
  case 18:
214
176
  _context.prev = 18;
215
177
  _context.t0 = _context["catch"](11);
216
178
  throw new _utils.SuprsendApiError(_context.t0);
217
-
218
179
  case 21:
219
180
  case "end":
220
181
  return _context.stop();
@@ -222,11 +183,9 @@ var SubscriberListsApi = /*#__PURE__*/function () {
222
183
  }
223
184
  }, _callee, this, [[11, 18]]);
224
185
  }));
225
-
226
186
  function create(_x) {
227
187
  return _create.apply(this, arguments);
228
188
  }
229
-
230
189
  return create;
231
190
  }()
232
191
  }, {
@@ -241,19 +200,18 @@ var SubscriberListsApi = /*#__PURE__*/function () {
241
200
  value: function () {
242
201
  var _get_all = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
243
202
  var kwargs,
244
- limit,
245
- offset,
246
- _this$cleaned_limit_o,
247
- _this$cleaned_limit_o2,
248
- cleaned_limit,
249
- cleaner_offset,
250
- final_url_obj,
251
- url,
252
- headers,
253
- signature,
254
- response,
255
- _args2 = arguments;
256
-
203
+ limit,
204
+ offset,
205
+ _this$cleaned_limit_o,
206
+ _this$cleaned_limit_o2,
207
+ cleaned_limit,
208
+ cleaner_offset,
209
+ final_url_obj,
210
+ url,
211
+ headers,
212
+ signature,
213
+ response,
214
+ _args2 = arguments;
257
215
  return _regenerator["default"].wrap(function _callee2$(_context2) {
258
216
  while (1) {
259
217
  switch (_context2.prev = _context2.next) {
@@ -274,16 +232,13 @@ var SubscriberListsApi = /*#__PURE__*/function () {
274
232
  return _axios["default"].get(url, {
275
233
  headers: headers
276
234
  });
277
-
278
235
  case 14:
279
236
  response = _context2.sent;
280
237
  return _context2.abrupt("return", response.data);
281
-
282
238
  case 18:
283
239
  _context2.prev = 18;
284
240
  _context2.t0 = _context2["catch"](11);
285
241
  throw new _utils.SuprsendApiError(_context2.t0);
286
-
287
242
  case 21:
288
243
  case "end":
289
244
  return _context2.stop();
@@ -291,11 +246,9 @@ var SubscriberListsApi = /*#__PURE__*/function () {
291
246
  }
292
247
  }, _callee2, this, [[11, 18]]);
293
248
  }));
294
-
295
249
  function get_all() {
296
250
  return _get_all.apply(this, arguments);
297
251
  }
298
-
299
252
  return get_all;
300
253
  }()
301
254
  }, {
@@ -322,16 +275,13 @@ var SubscriberListsApi = /*#__PURE__*/function () {
322
275
  return _axios["default"].get(url, {
323
276
  headers: headers
324
277
  });
325
-
326
278
  case 8:
327
279
  response = _context3.sent;
328
280
  return _context3.abrupt("return", response.data);
329
-
330
281
  case 12:
331
282
  _context3.prev = 12;
332
283
  _context3.t0 = _context3["catch"](5);
333
284
  throw new _utils.SuprsendApiError(_context3.t0);
334
-
335
285
  case 15:
336
286
  case "end":
337
287
  return _context3.stop();
@@ -339,11 +289,9 @@ var SubscriberListsApi = /*#__PURE__*/function () {
339
289
  }
340
290
  }, _callee3, this, [[5, 12]]);
341
291
  }));
342
-
343
292
  function get(_x2) {
344
293
  return _get.apply(this, arguments);
345
294
  }
346
-
347
295
  return get;
348
296
  }()
349
297
  }, {
@@ -356,24 +304,19 @@ var SubscriberListsApi = /*#__PURE__*/function () {
356
304
  switch (_context4.prev = _context4.next) {
357
305
  case 0:
358
306
  cleaned_list_id = this._validate_list_id(list_id);
359
-
360
307
  if (Array.isArray(distinct_ids)) {
361
308
  _context4.next = 3;
362
309
  break;
363
310
  }
364
-
365
311
  throw new _utils.SuprsendError("distinct_ids must be list of strings");
366
-
367
312
  case 3:
368
313
  if (!(distinct_ids.length === 0)) {
369
314
  _context4.next = 5;
370
315
  break;
371
316
  }
372
-
373
317
  return _context4.abrupt("return", this.non_error_default_response);
374
-
375
318
  case 5:
376
- url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "subscriber/add");
319
+ url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "subscriber/add/");
377
320
  headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
378
321
  content_text = JSON.stringify({
379
322
  distinct_ids: distinct_ids
@@ -385,16 +328,13 @@ var SubscriberListsApi = /*#__PURE__*/function () {
385
328
  return _axios["default"].post(url, content_text, {
386
329
  headers: headers
387
330
  });
388
-
389
331
  case 13:
390
332
  response = _context4.sent;
391
333
  return _context4.abrupt("return", response.data);
392
-
393
334
  case 17:
394
335
  _context4.prev = 17;
395
336
  _context4.t0 = _context4["catch"](10);
396
337
  throw new _utils.SuprsendApiError(_context4.t0);
397
-
398
338
  case 20:
399
339
  case "end":
400
340
  return _context4.stop();
@@ -402,11 +342,9 @@ var SubscriberListsApi = /*#__PURE__*/function () {
402
342
  }
403
343
  }, _callee4, this, [[10, 17]]);
404
344
  }));
405
-
406
345
  function add(_x3, _x4) {
407
346
  return _add.apply(this, arguments);
408
347
  }
409
-
410
348
  return add;
411
349
  }()
412
350
  }, {
@@ -414,37 +352,32 @@ var SubscriberListsApi = /*#__PURE__*/function () {
414
352
  value: function () {
415
353
  var _remove = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(list_id) {
416
354
  var distinct_ids,
417
- cleaned_list_id,
418
- url,
419
- headers,
420
- content_text,
421
- signature,
422
- response,
423
- _args5 = arguments;
355
+ cleaned_list_id,
356
+ url,
357
+ headers,
358
+ content_text,
359
+ signature,
360
+ response,
361
+ _args5 = arguments;
424
362
  return _regenerator["default"].wrap(function _callee5$(_context5) {
425
363
  while (1) {
426
364
  switch (_context5.prev = _context5.next) {
427
365
  case 0:
428
366
  distinct_ids = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : [];
429
367
  cleaned_list_id = this._validate_list_id(list_id);
430
-
431
368
  if (Array.isArray(distinct_ids)) {
432
369
  _context5.next = 4;
433
370
  break;
434
371
  }
435
-
436
372
  throw new _utils.SuprsendError("distinct_ids must be list of strings");
437
-
438
373
  case 4:
439
374
  if (!(distinct_ids.length === 0)) {
440
375
  _context5.next = 6;
441
376
  break;
442
377
  }
443
-
444
378
  return _context5.abrupt("return", this.non_error_default_response);
445
-
446
379
  case 6:
447
- url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "subscriber/remove");
380
+ url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "subscriber/remove/");
448
381
  headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
449
382
  content_text = JSON.stringify({
450
383
  distinct_ids: distinct_ids
@@ -456,16 +389,13 @@ var SubscriberListsApi = /*#__PURE__*/function () {
456
389
  return _axios["default"].post(url, content_text, {
457
390
  headers: headers
458
391
  });
459
-
460
392
  case 14:
461
393
  response = _context5.sent;
462
394
  return _context5.abrupt("return", response.data);
463
-
464
395
  case 18:
465
396
  _context5.prev = 18;
466
397
  _context5.t0 = _context5["catch"](11);
467
398
  throw new _utils.SuprsendApiError(_context5.t0);
468
-
469
399
  case 21:
470
400
  case "end":
471
401
  return _context5.stop();
@@ -473,96 +403,412 @@ var SubscriberListsApi = /*#__PURE__*/function () {
473
403
  }
474
404
  }, _callee5, this, [[11, 18]]);
475
405
  }));
476
-
477
406
  function remove(_x5) {
478
407
  return _remove.apply(this, arguments);
479
408
  }
480
-
481
409
  return remove;
482
410
  }()
483
411
  }, {
484
- key: "broadcast",
412
+ key: "delete",
485
413
  value: function () {
486
- var _broadcast = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(broadcast_instance) {
487
- var _broadcast_instance$g, _broadcast_instance$g2, broadcast_body, body_size, headers, content_text, signature, response, ok_response;
488
-
414
+ var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(list_id) {
415
+ var cleaned_list_id, content_text, url, headers, signature, response;
489
416
  return _regenerator["default"].wrap(function _callee6$(_context6) {
490
417
  while (1) {
491
418
  switch (_context6.prev = _context6.next) {
419
+ case 0:
420
+ cleaned_list_id = this._validate_list_id(list_id);
421
+ content_text = JSON.stringify({});
422
+ url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "delete/");
423
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
424
+ signature = (0, _signature["default"])(url, "PATCH", content_text, headers, this.config.workspace_secret);
425
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
426
+ _context6.prev = 6;
427
+ _context6.next = 9;
428
+ return _axios["default"].patch(url, content_text, {
429
+ headers: headers
430
+ });
431
+ case 9:
432
+ response = _context6.sent;
433
+ return _context6.abrupt("return", response.data);
434
+ case 13:
435
+ _context6.prev = 13;
436
+ _context6.t0 = _context6["catch"](6);
437
+ throw new _utils.SuprsendApiError(_context6.t0);
438
+ case 16:
439
+ case "end":
440
+ return _context6.stop();
441
+ }
442
+ }
443
+ }, _callee6, this, [[6, 13]]);
444
+ }));
445
+ function _delete(_x6) {
446
+ return _delete2.apply(this, arguments);
447
+ }
448
+ return _delete;
449
+ }()
450
+ }, {
451
+ key: "broadcast",
452
+ value: function () {
453
+ var _broadcast = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(broadcast_instance) {
454
+ var _broadcast_instance$g, _broadcast_instance$g2, broadcast_body, body_size, headers, content_text, signature, response, ok_response;
455
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
456
+ while (1) {
457
+ switch (_context7.prev = _context7.next) {
492
458
  case 0:
493
459
  if (broadcast_instance instanceof SubscriberListBroadcast) {
494
- _context6.next = 2;
460
+ _context7.next = 2;
495
461
  break;
496
462
  }
497
-
498
463
  throw new _utils.InputValueError("argument must be an instance of suprsend.SubscriberListBroadcast");
499
-
500
464
  case 2:
501
465
  _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];
502
466
  headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
503
467
  content_text = JSON.stringify(broadcast_body);
504
468
  signature = (0, _signature["default"])(this.broadcast_url, "POST", content_text, headers, this.config.workspace_secret);
505
469
  headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
506
- _context6.prev = 7;
507
- _context6.next = 10;
470
+ _context7.prev = 7;
471
+ _context7.next = 10;
508
472
  return _axios["default"].post(this.broadcast_url, content_text, {
509
473
  headers: headers
510
474
  });
511
-
512
475
  case 10:
513
- response = _context6.sent;
476
+ response = _context7.sent;
514
477
  ok_response = Math.floor(response.status / 100) == 2;
515
-
516
478
  if (!ok_response) {
517
- _context6.next = 16;
479
+ _context7.next = 16;
518
480
  break;
519
481
  }
520
-
521
- return _context6.abrupt("return", {
482
+ return _context7.abrupt("return", {
522
483
  success: true,
523
484
  status: "success",
524
485
  status_code: response.status,
525
486
  message: response.statusText
526
487
  });
527
-
528
488
  case 16:
529
- return _context6.abrupt("return", {
489
+ return _context7.abrupt("return", {
530
490
  success: false,
531
491
  status: "fail",
532
492
  status_code: response.status,
533
493
  message: response.statusText
534
494
  });
535
-
536
495
  case 17:
537
- _context6.next = 22;
496
+ _context7.next = 22;
538
497
  break;
539
-
540
498
  case 19:
541
- _context6.prev = 19;
542
- _context6.t0 = _context6["catch"](7);
543
- return _context6.abrupt("return", {
499
+ _context7.prev = 19;
500
+ _context7.t0 = _context7["catch"](7);
501
+ return _context7.abrupt("return", {
544
502
  success: false,
545
503
  status: "fail",
546
- status_code: _context6.t0.status || 500,
547
- message: _context6.t0.message
504
+ status_code: _context7.t0.status || 500,
505
+ message: _context7.t0.message
548
506
  });
549
-
550
507
  case 22:
551
508
  case "end":
552
- return _context6.stop();
509
+ return _context7.stop();
553
510
  }
554
511
  }
555
- }, _callee6, this, [[7, 19]]);
512
+ }, _callee7, this, [[7, 19]]);
556
513
  }));
557
-
558
- function broadcast(_x6) {
514
+ function broadcast(_x7) {
559
515
  return _broadcast.apply(this, arguments);
560
516
  }
561
-
562
517
  return broadcast;
563
518
  }()
519
+ }, {
520
+ key: "start_sync",
521
+ value: function () {
522
+ var _start_sync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(list_id) {
523
+ var cleaned_list_id, url, headers, content_text, signature, response;
524
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
525
+ while (1) {
526
+ switch (_context8.prev = _context8.next) {
527
+ case 0:
528
+ cleaned_list_id = this._validate_list_id(list_id);
529
+ url = "".concat(this.__subscriber_list_detail_url(cleaned_list_id), "start_sync/");
530
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
531
+ content_text = JSON.stringify({});
532
+ signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
533
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
534
+ _context8.prev = 6;
535
+ _context8.next = 9;
536
+ return _axios["default"].post(url, content_text, {
537
+ headers: headers
538
+ });
539
+ case 9:
540
+ response = _context8.sent;
541
+ return _context8.abrupt("return", response.data);
542
+ case 13:
543
+ _context8.prev = 13;
544
+ _context8.t0 = _context8["catch"](6);
545
+ throw new _utils.SuprsendApiError(_context8.t0);
546
+ case 16:
547
+ case "end":
548
+ return _context8.stop();
549
+ }
550
+ }
551
+ }, _callee8, this, [[6, 13]]);
552
+ }));
553
+ function start_sync(_x8) {
554
+ return _start_sync.apply(this, arguments);
555
+ }
556
+ return start_sync;
557
+ }()
558
+ }, {
559
+ key: "_validate_version_id",
560
+ value: function _validate_version_id(version_id) {
561
+ if (typeof version_id != "string") {
562
+ throw new _utils.SuprsendError("version_id must be a string");
563
+ }
564
+ var cleaned_version_id = version_id.trim();
565
+ if (!cleaned_version_id) {
566
+ throw new _utils.SuprsendError("missing version_id");
567
+ }
568
+ return version_id;
569
+ }
570
+ }, {
571
+ key: "__subscriber_list_url_with_version",
572
+ value: function __subscriber_list_url_with_version(list_id, version_id) {
573
+ return "".concat(this.config.base_url, "v1/subscriber_list/").concat(list_id, "/version/").concat(version_id, "/");
574
+ }
575
+ }, {
576
+ key: "get_version",
577
+ value: function () {
578
+ var _get_version = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(list_id, version_id) {
579
+ var cleaned_list_id, cleaned_version_id, url, headers, signature, response;
580
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
581
+ while (1) {
582
+ switch (_context9.prev = _context9.next) {
583
+ case 0:
584
+ cleaned_list_id = this._validate_list_id(list_id);
585
+ cleaned_version_id = this._validate_version_id(version_id);
586
+ url = this.__subscriber_list_url_with_version(cleaned_list_id, cleaned_version_id);
587
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
588
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
589
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
590
+ _context9.prev = 6;
591
+ _context9.next = 9;
592
+ return _axios["default"].get(url, {
593
+ headers: headers
594
+ });
595
+ case 9:
596
+ response = _context9.sent;
597
+ return _context9.abrupt("return", response.data);
598
+ case 13:
599
+ _context9.prev = 13;
600
+ _context9.t0 = _context9["catch"](6);
601
+ throw new _utils.SuprsendApiError(_context9.t0);
602
+ case 16:
603
+ case "end":
604
+ return _context9.stop();
605
+ }
606
+ }
607
+ }, _callee9, this, [[6, 13]]);
608
+ }));
609
+ function get_version(_x9, _x10) {
610
+ return _get_version.apply(this, arguments);
611
+ }
612
+ return get_version;
613
+ }()
614
+ }, {
615
+ key: "add_to_version",
616
+ value: function () {
617
+ var _add_to_version = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(list_id, version_id, distinct_ids) {
618
+ var cleaned_list_id, cleaned_version_id, url, headers, content_text, signature, response;
619
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
620
+ while (1) {
621
+ switch (_context10.prev = _context10.next) {
622
+ case 0:
623
+ cleaned_list_id = this._validate_list_id(list_id);
624
+ cleaned_version_id = this._validate_version_id(version_id);
625
+ if (Array.isArray(distinct_ids)) {
626
+ _context10.next = 4;
627
+ break;
628
+ }
629
+ throw new _utils.SuprsendError("distinct_ids must be list of strings");
630
+ case 4:
631
+ if (!(distinct_ids.length === 0)) {
632
+ _context10.next = 6;
633
+ break;
634
+ }
635
+ return _context10.abrupt("return", this.non_error_default_response);
636
+ case 6:
637
+ url = "".concat(this.__subscriber_list_url_with_version(cleaned_list_id, cleaned_version_id), "subscriber/add/");
638
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
639
+ content_text = JSON.stringify({
640
+ distinct_ids: distinct_ids
641
+ });
642
+ signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
643
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
644
+ _context10.prev = 11;
645
+ _context10.next = 14;
646
+ return _axios["default"].post(url, content_text, {
647
+ headers: headers
648
+ });
649
+ case 14:
650
+ response = _context10.sent;
651
+ return _context10.abrupt("return", response.data);
652
+ case 18:
653
+ _context10.prev = 18;
654
+ _context10.t0 = _context10["catch"](11);
655
+ throw new _utils.SuprsendApiError(_context10.t0);
656
+ case 21:
657
+ case "end":
658
+ return _context10.stop();
659
+ }
660
+ }
661
+ }, _callee10, this, [[11, 18]]);
662
+ }));
663
+ function add_to_version(_x11, _x12, _x13) {
664
+ return _add_to_version.apply(this, arguments);
665
+ }
666
+ return add_to_version;
667
+ }()
668
+ }, {
669
+ key: "remove_from_version",
670
+ value: function () {
671
+ var _remove_from_version = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(list_id, version_id) {
672
+ var distinct_ids,
673
+ cleaned_list_id,
674
+ cleaned_version_id,
675
+ url,
676
+ headers,
677
+ content_text,
678
+ signature,
679
+ response,
680
+ _args11 = arguments;
681
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
682
+ while (1) {
683
+ switch (_context11.prev = _context11.next) {
684
+ case 0:
685
+ distinct_ids = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : [];
686
+ cleaned_list_id = this._validate_list_id(list_id);
687
+ cleaned_version_id = this._validate_version_id(version_id);
688
+ if (Array.isArray(distinct_ids)) {
689
+ _context11.next = 5;
690
+ break;
691
+ }
692
+ throw new _utils.SuprsendError("distinct_ids must be list of strings");
693
+ case 5:
694
+ if (!(distinct_ids.length === 0)) {
695
+ _context11.next = 7;
696
+ break;
697
+ }
698
+ return _context11.abrupt("return", this.non_error_default_response);
699
+ case 7:
700
+ url = "".concat(this.__subscriber_list_url_with_version(cleaned_list_id, cleaned_version_id), "subscriber/remove/");
701
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
702
+ content_text = JSON.stringify({
703
+ distinct_ids: distinct_ids
704
+ });
705
+ signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
706
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
707
+ _context11.prev = 12;
708
+ _context11.next = 15;
709
+ return _axios["default"].post(url, content_text, {
710
+ headers: headers
711
+ });
712
+ case 15:
713
+ response = _context11.sent;
714
+ return _context11.abrupt("return", response.data);
715
+ case 19:
716
+ _context11.prev = 19;
717
+ _context11.t0 = _context11["catch"](12);
718
+ throw new _utils.SuprsendApiError(_context11.t0);
719
+ case 22:
720
+ case "end":
721
+ return _context11.stop();
722
+ }
723
+ }
724
+ }, _callee11, this, [[12, 19]]);
725
+ }));
726
+ function remove_from_version(_x14, _x15) {
727
+ return _remove_from_version.apply(this, arguments);
728
+ }
729
+ return remove_from_version;
730
+ }()
731
+ }, {
732
+ key: "finish_sync",
733
+ value: function () {
734
+ var _finish_sync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(list_id, version_id) {
735
+ var cleaned_list_id, cleaned_version_id, url, headers, content_text, signature, response;
736
+ return _regenerator["default"].wrap(function _callee12$(_context12) {
737
+ while (1) {
738
+ switch (_context12.prev = _context12.next) {
739
+ case 0:
740
+ cleaned_list_id = this._validate_list_id(list_id);
741
+ cleaned_version_id = this._validate_version_id(version_id);
742
+ url = "".concat(this.__subscriber_list_url_with_version(cleaned_list_id, cleaned_version_id), "finish_sync/");
743
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
744
+ content_text = JSON.stringify({});
745
+ signature = (0, _signature["default"])(url, "PATCH", content_text, headers, this.config.workspace_secret);
746
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
747
+ _context12.prev = 7;
748
+ _context12.next = 10;
749
+ return _axios["default"].patch(url, content_text, {
750
+ headers: headers
751
+ });
752
+ case 10:
753
+ response = _context12.sent;
754
+ return _context12.abrupt("return", response.data);
755
+ case 14:
756
+ _context12.prev = 14;
757
+ _context12.t0 = _context12["catch"](7);
758
+ throw new _utils.SuprsendApiError(_context12.t0);
759
+ case 17:
760
+ case "end":
761
+ return _context12.stop();
762
+ }
763
+ }
764
+ }, _callee12, this, [[7, 14]]);
765
+ }));
766
+ function finish_sync(_x16, _x17) {
767
+ return _finish_sync.apply(this, arguments);
768
+ }
769
+ return finish_sync;
770
+ }()
771
+ }, {
772
+ key: "delete_version",
773
+ value: function () {
774
+ var _delete_version = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(list_id, version_id) {
775
+ var cleaned_list_id, cleaned_version_id, url, headers, content_text, signature, response;
776
+ return _regenerator["default"].wrap(function _callee13$(_context13) {
777
+ while (1) {
778
+ switch (_context13.prev = _context13.next) {
779
+ case 0:
780
+ cleaned_list_id = this._validate_list_id(list_id);
781
+ cleaned_version_id = this._validate_version_id(version_id);
782
+ url = "".concat(this.__subscriber_list_url_with_version(cleaned_list_id, cleaned_version_id), "delete/");
783
+ headers = _objectSpread(_objectSpread({}, this.__headers), this.__dynamic_headers());
784
+ content_text = JSON.stringify({});
785
+ signature = (0, _signature["default"])(url, "PATCH", content_text, headers, this.config.workspace_secret);
786
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
787
+ _context13.prev = 7;
788
+ _context13.next = 10;
789
+ return _axios["default"].patch(url, content_text, {
790
+ headers: headers
791
+ });
792
+ case 10:
793
+ response = _context13.sent;
794
+ return _context13.abrupt("return", response.data);
795
+ case 14:
796
+ _context13.prev = 14;
797
+ _context13.t0 = _context13["catch"](7);
798
+ throw new _utils.SuprsendApiError(_context13.t0);
799
+ case 17:
800
+ case "end":
801
+ return _context13.stop();
802
+ }
803
+ }
804
+ }, _callee13, this, [[7, 14]]);
805
+ }));
806
+ function delete_version(_x18, _x19) {
807
+ return _delete_version.apply(this, arguments);
808
+ }
809
+ return delete_version;
810
+ }()
564
811
  }]);
565
812
  return SubscriberListsApi;
566
813
  }();
567
-
568
814
  exports.SubscriberListsApi = SubscriberListsApi;