@suprsend/node-sdk 1.9.1 → 1.11.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/object.js ADDED
@@ -0,0 +1,902 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = exports._Object = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
+ var _utils = require("./utils");
15
+ var _signature = _interopRequireDefault(require("./signature"));
16
+ var _axios = _interopRequireDefault(require("axios"));
17
+ var _object_helper = _interopRequireDefault(require("./object_helper"));
18
+ 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; } } }; }
19
+ 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); }
20
+ 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; }
21
+ 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; }
22
+ 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; }
23
+ var ObjectsApi = /*#__PURE__*/function () {
24
+ function ObjectsApi(config) {
25
+ (0, _classCallCheck2["default"])(this, ObjectsApi);
26
+ this.config = config;
27
+ this.listUrl = this.create_list_url();
28
+ this.headers = this.common_headers();
29
+ }
30
+ (0, _createClass2["default"])(ObjectsApi, [{
31
+ key: "create_list_url",
32
+ value: function create_list_url() {
33
+ return "".concat(this.config.base_url, "v1/object/");
34
+ }
35
+ }, {
36
+ key: "common_headers",
37
+ value: function common_headers() {
38
+ return {
39
+ 'Content-Type': 'application/json; charset=utf-8',
40
+ 'User-Agent': this.config.user_agent
41
+ };
42
+ }
43
+ }, {
44
+ key: "dynamic_headers",
45
+ value: function dynamic_headers() {
46
+ return {
47
+ 'Date': new Date().toISOString() // Adjust to your header date format
48
+ };
49
+ }
50
+ }, {
51
+ key: "validate_object_entity_string",
52
+ value: function validate_object_entity_string(entityId) {
53
+ if (!(0, _utils.is_string)(entityId)) {
54
+ throw new _utils.InputValueError("object entity must be a string");
55
+ }
56
+ entityId = entityId.trim();
57
+ if (!entityId) {
58
+ throw new _utils.InputValueError("object entity must be passed");
59
+ }
60
+ return entityId;
61
+ }
62
+ }, {
63
+ key: "list",
64
+ value: function () {
65
+ var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(objectType) {
66
+ var options,
67
+ params,
68
+ validatedType,
69
+ encodedType,
70
+ url,
71
+ headers,
72
+ signature,
73
+ response,
74
+ _args = arguments;
75
+ return _regenerator["default"].wrap(function _callee$(_context) {
76
+ while (1) {
77
+ switch (_context.prev = _context.next) {
78
+ case 0:
79
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
80
+ params = new URLSearchParams(options).toString();
81
+ validatedType = this.validate_object_entity_string(objectType);
82
+ encodedType = encodeURIComponent(validatedType);
83
+ url = "".concat(this.listUrl).concat(encodedType, "/?").concat(params);
84
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
85
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
86
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
87
+ _context.prev = 8;
88
+ _context.next = 11;
89
+ return _axios["default"].get(url, {
90
+ headers: headers
91
+ });
92
+ case 11:
93
+ response = _context.sent;
94
+ return _context.abrupt("return", response.data);
95
+ case 15:
96
+ _context.prev = 15;
97
+ _context.t0 = _context["catch"](8);
98
+ throw new _utils.SuprsendApiError(_context.t0);
99
+ case 18:
100
+ case "end":
101
+ return _context.stop();
102
+ }
103
+ }
104
+ }, _callee, this, [[8, 15]]);
105
+ }));
106
+ function list(_x) {
107
+ return _list.apply(this, arguments);
108
+ }
109
+ return list;
110
+ }()
111
+ }, {
112
+ key: "detail_url",
113
+ value: function () {
114
+ var _detail_url = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(objectType, objectId) {
115
+ var validatedType, encodedType, validatedId, encodedId;
116
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
117
+ while (1) {
118
+ switch (_context2.prev = _context2.next) {
119
+ case 0:
120
+ validatedType = this.validate_object_entity_string(objectType);
121
+ encodedType = encodeURIComponent(validatedType);
122
+ validatedId = this.validate_object_entity_string(objectId);
123
+ encodedId = encodeURIComponent(validatedId);
124
+ return _context2.abrupt("return", "".concat(this.listUrl).concat(encodedType, "/").concat(encodedId, "/"));
125
+ case 5:
126
+ case "end":
127
+ return _context2.stop();
128
+ }
129
+ }
130
+ }, _callee2, this);
131
+ }));
132
+ function detail_url(_x2, _x3) {
133
+ return _detail_url.apply(this, arguments);
134
+ }
135
+ return detail_url;
136
+ }()
137
+ }, {
138
+ key: "get",
139
+ value: function () {
140
+ var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(objectType, objectId) {
141
+ var url, headers, signature, response;
142
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
143
+ while (1) {
144
+ switch (_context3.prev = _context3.next) {
145
+ case 0:
146
+ _context3.next = 2;
147
+ return this.detail_url(objectType, objectId);
148
+ case 2:
149
+ url = _context3.sent;
150
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
151
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
152
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
153
+ _context3.prev = 6;
154
+ _context3.next = 9;
155
+ return _axios["default"].get(url, {
156
+ headers: headers
157
+ });
158
+ case 9:
159
+ response = _context3.sent;
160
+ return _context3.abrupt("return", response.data);
161
+ case 13:
162
+ _context3.prev = 13;
163
+ _context3.t0 = _context3["catch"](6);
164
+ throw new _utils.SuprsendApiError(_context3.t0);
165
+ case 16:
166
+ case "end":
167
+ return _context3.stop();
168
+ }
169
+ }
170
+ }, _callee3, this, [[6, 13]]);
171
+ }));
172
+ function get(_x4, _x5) {
173
+ return _get.apply(this, arguments);
174
+ }
175
+ return get;
176
+ }()
177
+ }, {
178
+ key: "upsert",
179
+ value: function () {
180
+ var _upsert = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(objectType, objectId, objectPayload) {
181
+ var url, headers, contentText, signature, response;
182
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
183
+ while (1) {
184
+ switch (_context4.prev = _context4.next) {
185
+ case 0:
186
+ _context4.next = 2;
187
+ return this.detail_url(objectType, objectId);
188
+ case 2:
189
+ url = _context4.sent;
190
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
191
+ contentText = JSON.stringify(objectPayload);
192
+ signature = (0, _signature["default"])(url, "POST", contentText, headers, this.config.workspace_secret);
193
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
194
+ _context4.prev = 7;
195
+ _context4.next = 10;
196
+ return _axios["default"].post(url, contentText, {
197
+ headers: headers
198
+ });
199
+ case 10:
200
+ response = _context4.sent;
201
+ return _context4.abrupt("return", response.data);
202
+ case 14:
203
+ _context4.prev = 14;
204
+ _context4.t0 = _context4["catch"](7);
205
+ throw new _utils.SuprsendApiError(_context4.t0);
206
+ case 17:
207
+ case "end":
208
+ return _context4.stop();
209
+ }
210
+ }
211
+ }, _callee4, this, [[7, 14]]);
212
+ }));
213
+ function upsert(_x6, _x7, _x8) {
214
+ return _upsert.apply(this, arguments);
215
+ }
216
+ return upsert;
217
+ }()
218
+ }, {
219
+ key: "edit",
220
+ value: function () {
221
+ var _edit = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(objectType, objectId, editPayload) {
222
+ var url, headers, contentText, signature, response;
223
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
224
+ while (1) {
225
+ switch (_context5.prev = _context5.next) {
226
+ case 0:
227
+ _context5.next = 2;
228
+ return this.detail_url(objectType, objectId);
229
+ case 2:
230
+ url = _context5.sent;
231
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
232
+ contentText = JSON.stringify(editPayload);
233
+ signature = (0, _signature["default"])(url, "PATCH", contentText, headers, this.config.workspace_secret);
234
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
235
+ _context5.prev = 7;
236
+ _context5.next = 10;
237
+ return _axios["default"].patch(url, contentText, {
238
+ headers: headers
239
+ });
240
+ case 10:
241
+ response = _context5.sent;
242
+ return _context5.abrupt("return", response.data);
243
+ case 14:
244
+ _context5.prev = 14;
245
+ _context5.t0 = _context5["catch"](7);
246
+ throw new _utils.SuprsendApiError(_context5.t0);
247
+ case 17:
248
+ case "end":
249
+ return _context5.stop();
250
+ }
251
+ }
252
+ }, _callee5, this, [[7, 14]]);
253
+ }));
254
+ function edit(_x9, _x10, _x11) {
255
+ return _edit.apply(this, arguments);
256
+ }
257
+ return edit;
258
+ }()
259
+ }, {
260
+ key: "delete",
261
+ value: function () {
262
+ var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(objectType, objectId) {
263
+ var url, headers, signature, response;
264
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
265
+ while (1) {
266
+ switch (_context6.prev = _context6.next) {
267
+ case 0:
268
+ _context6.next = 2;
269
+ return this.detail_url(objectType, objectId);
270
+ case 2:
271
+ url = _context6.sent;
272
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
273
+ signature = (0, _signature["default"])(url, "DELETE", "", headers, this.config.workspace_secret);
274
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
275
+ _context6.prev = 6;
276
+ _context6.next = 9;
277
+ return _axios["default"]["delete"](url, {
278
+ headers: headers
279
+ });
280
+ case 9:
281
+ response = _context6.sent;
282
+ return _context6.abrupt("return", response.data);
283
+ case 13:
284
+ _context6.prev = 13;
285
+ _context6.t0 = _context6["catch"](6);
286
+ throw new _utils.SuprsendApiError(_context6.t0);
287
+ case 16:
288
+ case "end":
289
+ return _context6.stop();
290
+ }
291
+ }
292
+ }, _callee6, this, [[6, 13]]);
293
+ }));
294
+ function _delete(_x12, _x13) {
295
+ return _delete2.apply(this, arguments);
296
+ }
297
+ return _delete;
298
+ }()
299
+ }, {
300
+ key: "bulk_ops_url",
301
+ value: function () {
302
+ var _bulk_ops_url = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(objectType) {
303
+ var validatedType, encodedType;
304
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
305
+ while (1) {
306
+ switch (_context7.prev = _context7.next) {
307
+ case 0:
308
+ validatedType = this.validate_object_entity_string(objectType);
309
+ encodedType = encodeURIComponent(validatedType);
310
+ return _context7.abrupt("return", "".concat(this.config.base_url, "v1/bulk/object/").concat(encodedType, "/"));
311
+ case 3:
312
+ case "end":
313
+ return _context7.stop();
314
+ }
315
+ }
316
+ }, _callee7, this);
317
+ }));
318
+ function bulk_ops_url(_x14) {
319
+ return _bulk_ops_url.apply(this, arguments);
320
+ }
321
+ return bulk_ops_url;
322
+ }()
323
+ }, {
324
+ key: "bulk_delete",
325
+ value: function () {
326
+ var _bulk_delete = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(objectType, payload) {
327
+ var url, headers, contentText, signature, response;
328
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
329
+ while (1) {
330
+ switch (_context8.prev = _context8.next) {
331
+ case 0:
332
+ _context8.next = 2;
333
+ return this.bulk_ops_url(objectType);
334
+ case 2:
335
+ url = _context8.sent;
336
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
337
+ contentText = JSON.stringify(payload);
338
+ signature = (0, _signature["default"])(url, "DELETE", contentText, headers, this.config.workspace_secret);
339
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
340
+ _context8.prev = 7;
341
+ _context8.next = 10;
342
+ return _axios["default"]["delete"](url, {
343
+ headers: headers,
344
+ data: payload
345
+ });
346
+ case 10:
347
+ response = _context8.sent;
348
+ return _context8.abrupt("return", response.data);
349
+ case 14:
350
+ _context8.prev = 14;
351
+ _context8.t0 = _context8["catch"](7);
352
+ throw new _utils.SuprsendApiError(_context8.t0);
353
+ case 17:
354
+ case "end":
355
+ return _context8.stop();
356
+ }
357
+ }
358
+ }, _callee8, this, [[7, 14]]);
359
+ }));
360
+ function bulk_delete(_x15, _x16) {
361
+ return _bulk_delete.apply(this, arguments);
362
+ }
363
+ return bulk_delete;
364
+ }()
365
+ }, {
366
+ key: "get_subscriptions",
367
+ value: function () {
368
+ var _get_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(objectType, objectId) {
369
+ var options,
370
+ params,
371
+ url,
372
+ subscription_url,
373
+ headers,
374
+ signature,
375
+ response,
376
+ _args9 = arguments;
377
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
378
+ while (1) {
379
+ switch (_context9.prev = _context9.next) {
380
+ case 0:
381
+ options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
382
+ params = new URLSearchParams(options).toString();
383
+ _context9.next = 4;
384
+ return this.detail_url(objectType, objectId);
385
+ case 4:
386
+ url = _context9.sent;
387
+ subscription_url = "".concat(url, "subscription/?").concat(params);
388
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
389
+ signature = (0, _signature["default"])(subscription_url, "GET", "", headers, this.config.workspace_secret);
390
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
391
+ _context9.prev = 9;
392
+ _context9.next = 12;
393
+ return _axios["default"].get(subscription_url, {
394
+ headers: headers
395
+ });
396
+ case 12:
397
+ response = _context9.sent;
398
+ return _context9.abrupt("return", response.data);
399
+ case 16:
400
+ _context9.prev = 16;
401
+ _context9.t0 = _context9["catch"](9);
402
+ throw new _utils.SuprsendApiError(_context9.t0);
403
+ case 19:
404
+ case "end":
405
+ return _context9.stop();
406
+ }
407
+ }
408
+ }, _callee9, this, [[9, 16]]);
409
+ }));
410
+ function get_subscriptions(_x17, _x18) {
411
+ return _get_subscriptions.apply(this, arguments);
412
+ }
413
+ return get_subscriptions;
414
+ }()
415
+ }, {
416
+ key: "create_subscriptions",
417
+ value: function () {
418
+ var _create_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(objectType, objectId, subscriptions) {
419
+ var url, subscription_url, headers, contentText, signature, response;
420
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
421
+ while (1) {
422
+ switch (_context10.prev = _context10.next) {
423
+ case 0:
424
+ _context10.next = 2;
425
+ return this.detail_url(objectType, objectId);
426
+ case 2:
427
+ url = _context10.sent;
428
+ subscription_url = "".concat(url, "subscription/");
429
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
430
+ contentText = JSON.stringify(subscriptions);
431
+ signature = (0, _signature["default"])(subscription_url, "POST", contentText, headers, this.config.workspace_secret);
432
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
433
+ _context10.prev = 8;
434
+ _context10.next = 11;
435
+ return _axios["default"].post(subscription_url, contentText, {
436
+ headers: headers
437
+ });
438
+ case 11:
439
+ response = _context10.sent;
440
+ return _context10.abrupt("return", response.data);
441
+ case 15:
442
+ _context10.prev = 15;
443
+ _context10.t0 = _context10["catch"](8);
444
+ throw new _utils.SuprsendApiError(_context10.t0);
445
+ case 18:
446
+ case "end":
447
+ return _context10.stop();
448
+ }
449
+ }
450
+ }, _callee10, this, [[8, 15]]);
451
+ }));
452
+ function create_subscriptions(_x19, _x20, _x21) {
453
+ return _create_subscriptions.apply(this, arguments);
454
+ }
455
+ return create_subscriptions;
456
+ }()
457
+ }, {
458
+ key: "delete_subscriptions",
459
+ value: function () {
460
+ var _delete_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(objectType, objectId, subscriptions) {
461
+ var url, subscription_url, headers, contentText, signature, response;
462
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
463
+ while (1) {
464
+ switch (_context11.prev = _context11.next) {
465
+ case 0:
466
+ _context11.next = 2;
467
+ return this.detail_url(objectType, objectId);
468
+ case 2:
469
+ url = _context11.sent;
470
+ subscription_url = "".concat(url, "subscription/");
471
+ headers = _objectSpread(_objectSpread({}, this.headers), this.dynamic_headers());
472
+ contentText = JSON.stringify(subscriptions);
473
+ signature = (0, _signature["default"])(subscription_url, "DELETE", contentText, headers, this.config.workspace_secret);
474
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
475
+ _context11.prev = 8;
476
+ _context11.next = 11;
477
+ return _axios["default"]["delete"](subscription_url, {
478
+ headers: headers,
479
+ data: subscriptions
480
+ });
481
+ case 11:
482
+ response = _context11.sent;
483
+ return _context11.abrupt("return", response.data);
484
+ case 15:
485
+ _context11.prev = 15;
486
+ _context11.t0 = _context11["catch"](8);
487
+ throw new _utils.SuprsendApiError(_context11.t0);
488
+ case 18:
489
+ case "end":
490
+ return _context11.stop();
491
+ }
492
+ }
493
+ }, _callee11, this, [[8, 15]]);
494
+ }));
495
+ function delete_subscriptions(_x22, _x23, _x24) {
496
+ return _delete_subscriptions.apply(this, arguments);
497
+ }
498
+ return delete_subscriptions;
499
+ }()
500
+ }, {
501
+ key: "get_instance",
502
+ value: function get_instance(object_type, object_id) {
503
+ if (!(0, _utils.is_string)(object_type)) {
504
+ throw new _utils.InputValueError("object_type must be a string");
505
+ }
506
+ object_type = object_type.trim();
507
+ if (!object_type) {
508
+ throw new _utils.InputValueError("object_type must be passed");
509
+ }
510
+ if (!(0, _utils.is_string)(object_id)) {
511
+ throw new _utils.InputValueError("object_id must be a string");
512
+ }
513
+ object_id = object_id.trim();
514
+ if (!object_id) {
515
+ throw new _utils.InputValueError("object_id must be passed");
516
+ }
517
+ return new _Object(this.config, object_type, object_id);
518
+ }
519
+ }]);
520
+ return ObjectsApi;
521
+ }();
522
+ var _Object = /*#__PURE__*/function () {
523
+ function _Object(config, object_type, object_id) {
524
+ (0, _classCallCheck2["default"])(this, _Object);
525
+ this.config = config;
526
+ this.object_type = object_type;
527
+ this.object_id = object_id;
528
+ this.__url = this.__get_url();
529
+ this.__super_props = this.__super_properties();
530
+ this.__errors = [];
531
+ this.__info = [];
532
+ this.operations = [];
533
+ this._helper = new _object_helper["default"]();
534
+ }
535
+ (0, _createClass2["default"])(_Object, [{
536
+ key: "__get_url",
537
+ value: function __get_url() {
538
+ return "".concat(this.config.base_url, "v1/object/").concat(this.object_type, "/").concat(this.object_id, "/");
539
+ }
540
+ }, {
541
+ key: "__get_headers",
542
+ value: function __get_headers() {
543
+ return {
544
+ "Content-Type": "application/json; charset=utf-8",
545
+ Date: new Date().toUTCString(),
546
+ "User-Agent": this.config.user_agent
547
+ };
548
+ }
549
+ }, {
550
+ key: "__super_properties",
551
+ value: function __super_properties() {
552
+ return {
553
+ $ss_sdk_version: this.config.user_agent
554
+ };
555
+ }
556
+ }, {
557
+ key: "validate_body",
558
+ value: function validate_body() {
559
+ if (!(0, _utils.is_empty)(this.__info)) {
560
+ var msg = "[object_type: ".concat(this.object_type, ", ").concat(this.object_id, "]").concat(this.__info.join("\n"));
561
+ console.log("WARNING: ".concat(msg));
562
+ }
563
+ if (!(0, _utils.is_empty)(this.__errors)) {
564
+ var _msg = "[object_type: ".concat(this.object_type, ", ").concat(this.object_id, "]").concat(this.__errors.join("\n"));
565
+ console.log("ERROR: ".concat(_msg));
566
+ }
567
+ }
568
+ }, {
569
+ key: "save",
570
+ value: function () {
571
+ var _save = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12() {
572
+ var headers, payload, content_text, signature, response;
573
+ return _regenerator["default"].wrap(function _callee12$(_context12) {
574
+ while (1) {
575
+ switch (_context12.prev = _context12.next) {
576
+ case 0:
577
+ this.validate_body();
578
+ headers = this.__get_headers(); //
579
+ payload = {
580
+ operations: this.operations
581
+ };
582
+ content_text = JSON.stringify(payload);
583
+ signature = (0, _signature["default"])(this.__url, "PATCH", content_text, headers, this.config.workspace_secret);
584
+ headers['Authorization'] = "".concat(this.config.workspace_key, ":").concat(signature);
585
+ _context12.prev = 6;
586
+ _context12.next = 9;
587
+ return _axios["default"].patch(this.__url, content_text, {
588
+ headers: headers
589
+ });
590
+ case 9:
591
+ response = _context12.sent;
592
+ return _context12.abrupt("return", response.data);
593
+ case 13:
594
+ _context12.prev = 13;
595
+ _context12.t0 = _context12["catch"](6);
596
+ throw new _utils.SuprsendApiError(_context12.t0);
597
+ case 16:
598
+ case "end":
599
+ return _context12.stop();
600
+ }
601
+ }
602
+ }, _callee12, this, [[6, 13]]);
603
+ }));
604
+ function save() {
605
+ return _save.apply(this, arguments);
606
+ }
607
+ return save;
608
+ }()
609
+ }, {
610
+ key: "_collect_payload",
611
+ value: function _collect_payload() {
612
+ var resp = this._helper.get_identity_events();
613
+ if (!(0, _utils.is_empty)(resp["errors"])) {
614
+ this.__errors = [].concat((0, _toConsumableArray2["default"])(this.__errors), (0, _toConsumableArray2["default"])(resp["errors"]));
615
+ }
616
+ if (!(0, _utils.is_empty)(resp["info"])) {
617
+ this.__info = [].concat((0, _toConsumableArray2["default"])(this.__info), (0, _toConsumableArray2["default"])(resp["info"]));
618
+ }
619
+ if (!(0, _utils.is_empty)(resp["payload"])) {
620
+ this.operations.push(resp["payload"]);
621
+ }
622
+ }
623
+ }, {
624
+ key: "append",
625
+ value: function append(key, value) {
626
+ var caller = "append";
627
+ if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
628
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
629
+ return;
630
+ }
631
+ if ((0, _utils.is_string)(key)) {
632
+ if (!value) {
633
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
634
+ return;
635
+ } else {
636
+ this._helper._append_kv(key, value, {}, caller);
637
+ this._collect_payload();
638
+ }
639
+ } else {
640
+ for (var item in key) {
641
+ this._helper._append_kv(item, key[item], key, caller);
642
+ }
643
+ this._collect_payload();
644
+ }
645
+ }
646
+ }, {
647
+ key: "set",
648
+ value: function set(key, value) {
649
+ var caller = "set";
650
+ if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
651
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
652
+ return;
653
+ }
654
+ if ((0, _utils.is_string)(key)) {
655
+ if (value === null || value === undefined) {
656
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
657
+ return;
658
+ } else {
659
+ this._helper._set_kv(key, value, {}, caller);
660
+ this._collect_payload();
661
+ }
662
+ } else {
663
+ for (var item in key) {
664
+ this._helper._set_kv(item, key[item], key, caller);
665
+ }
666
+ this._collect_payload();
667
+ }
668
+ }
669
+ }, {
670
+ key: "set_once",
671
+ value: function set_once(key, value) {
672
+ var caller = "set_once";
673
+ if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
674
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
675
+ return;
676
+ }
677
+ if ((0, _utils.is_string)(key)) {
678
+ if (value === null || value === undefined) {
679
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
680
+ return;
681
+ } else {
682
+ this._helper._set_once_kv(key, value, {}, caller);
683
+ this._collect_payload();
684
+ }
685
+ } else {
686
+ for (var item in key) {
687
+ this._helper._set_once_kv(item, key[item], key, caller);
688
+ }
689
+ this._collect_payload();
690
+ }
691
+ }
692
+ }, {
693
+ key: "increment",
694
+ value: function increment(key, value) {
695
+ var caller = "increment";
696
+ if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
697
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
698
+ return;
699
+ }
700
+ if ((0, _utils.is_string)(key)) {
701
+ if (value === null || value === undefined) {
702
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
703
+ return;
704
+ } else {
705
+ this._helper._increment_kv(key, value, {}, caller);
706
+ this._collect_payload();
707
+ }
708
+ } else {
709
+ for (var item in key) {
710
+ this._helper._increment_kv(item, key[item], key, caller);
711
+ }
712
+ this._collect_payload();
713
+ }
714
+ }
715
+ }, {
716
+ key: "remove",
717
+ value: function remove(key, value) {
718
+ var caller = "remove";
719
+ if (!(0, _utils.is_string)(key) && !(0, _utils.is_object)(key)) {
720
+ this.__errors.push("[".concat(caller, "] arg1 must be either string or a dict"));
721
+ return;
722
+ }
723
+ if ((0, _utils.is_string)(key)) {
724
+ if (!value) {
725
+ this.__errors.push("[".concat(caller, "] if arg1 is a string, then arg2 must be passed"));
726
+ return;
727
+ } else {
728
+ this._helper._remove_kv(key, value, {}, caller);
729
+ this._collect_payload();
730
+ }
731
+ } else {
732
+ for (var item in key) {
733
+ this._helper._remove_kv(item, key[item], key, caller);
734
+ }
735
+ this._collect_payload();
736
+ }
737
+ }
738
+ }, {
739
+ key: "unset",
740
+ value: function unset(key) {
741
+ var caller = "unset";
742
+ if (!(0, _utils.is_string)(key) && !Array.isArray(key)) {
743
+ this.__errors.push("[".concat(caller, "] key must be either string or array"));
744
+ return;
745
+ }
746
+ if ((0, _utils.is_string)(key)) {
747
+ this._helper._unset_k(key, caller);
748
+ this._collect_payload();
749
+ } else {
750
+ var _iterator = _createForOfIteratorHelper(key),
751
+ _step;
752
+ try {
753
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
754
+ var item = _step.value;
755
+ this._helper._unset_k(item, caller);
756
+ }
757
+ } catch (err) {
758
+ _iterator.e(err);
759
+ } finally {
760
+ _iterator.f();
761
+ }
762
+ this._collect_payload();
763
+ }
764
+ }
765
+ }, {
766
+ key: "set_preferred_language",
767
+ value: function set_preferred_language(lang_code) {
768
+ var caller = "set_preferred_language";
769
+ this._helper._set_preferred_language(lang_code, caller);
770
+ this._collect_payload();
771
+ }
772
+ }, {
773
+ key: "set_timezone",
774
+ value: function set_timezone(timezone) {
775
+ var caller = "set_timezone";
776
+ this._helper._set_timezone(timezone, caller);
777
+ this._collect_payload();
778
+ }
779
+ }, {
780
+ key: "add_email",
781
+ value: function add_email(email) {
782
+ var caller = "add_email";
783
+ this._helper._add_email(email, caller);
784
+ this._collect_payload();
785
+ }
786
+ }, {
787
+ key: "remove_email",
788
+ value: function remove_email(email) {
789
+ var caller = "remove_email";
790
+ this._helper._remove_email(email, caller);
791
+ this._collect_payload();
792
+ }
793
+ }, {
794
+ key: "add_sms",
795
+ value: function add_sms(mobile_no) {
796
+ var caller = "add_sms";
797
+ this._helper._add_sms(mobile_no, caller);
798
+ this._collect_payload();
799
+ }
800
+ }, {
801
+ key: "remove_sms",
802
+ value: function remove_sms(mobile_no) {
803
+ var caller = "remove_sms";
804
+ this._helper._remove_sms(mobile_no, caller);
805
+ this._collect_payload();
806
+ }
807
+ }, {
808
+ key: "add_whatsapp",
809
+ value: function add_whatsapp(mobile_no) {
810
+ var caller = "add_whatsapp";
811
+ this._helper._add_whatsapp(mobile_no, caller);
812
+ this._collect_payload();
813
+ }
814
+ }, {
815
+ key: "remove_whatsapp",
816
+ value: function remove_whatsapp(mobile_no) {
817
+ var caller = "remove_whatsapp";
818
+ this._helper._remove_whatsapp(mobile_no, caller);
819
+ this._collect_payload();
820
+ }
821
+ }, {
822
+ key: "add_androidpush",
823
+ value: function add_androidpush(push_token) {
824
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fcm";
825
+ var caller = "add_androidpush";
826
+ this._helper._add_androidpush(push_token, provider, caller);
827
+ this._collect_payload();
828
+ }
829
+ }, {
830
+ key: "remove_androidpush",
831
+ value: function remove_androidpush(push_token) {
832
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fcm";
833
+ var caller = "remove_androidpush";
834
+ this._helper._remove_androidpush(push_token, provider, caller);
835
+ this._collect_payload();
836
+ }
837
+ }, {
838
+ key: "add_iospush",
839
+ value: function add_iospush(push_token) {
840
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "apns";
841
+ var caller = "add_iospush";
842
+ this._helper._add_iospush(push_token, provider, caller);
843
+ this._collect_payload();
844
+ }
845
+ }, {
846
+ key: "remove_iospush",
847
+ value: function remove_iospush(push_token) {
848
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "apns";
849
+ var caller = "remove_iospush";
850
+ this._helper._remove_iospush(push_token, provider, caller);
851
+ this._collect_payload();
852
+ }
853
+ }, {
854
+ key: "add_webpush",
855
+ value: function add_webpush(push_token) {
856
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "vapid";
857
+ var caller = "add_webpush";
858
+ this._helper._add_webpush(push_token, provider, caller);
859
+ this._collect_payload();
860
+ }
861
+ }, {
862
+ key: "remove_webpush",
863
+ value: function remove_webpush(push_token) {
864
+ var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "vapid";
865
+ var caller = "remove_webpush";
866
+ this._helper._remove_webpush(push_token, provider, caller);
867
+ this._collect_payload();
868
+ }
869
+ }, {
870
+ key: "add_slack",
871
+ value: function add_slack(value) {
872
+ var caller = "add_slack";
873
+ this._helper._add_slack(value, caller);
874
+ this._collect_payload();
875
+ }
876
+ }, {
877
+ key: "remove_slack",
878
+ value: function remove_slack(value) {
879
+ var caller = "remove_slack";
880
+ this._helper._remove_slack(value, caller);
881
+ this._collect_payload();
882
+ }
883
+ }, {
884
+ key: "add_ms_teams",
885
+ value: function add_ms_teams(value) {
886
+ var caller = "add_ms_teams";
887
+ this._helper._add_ms_teams(value, caller);
888
+ this._collect_payload();
889
+ }
890
+ }, {
891
+ key: "remove_ms_teams",
892
+ value: function remove_ms_teams(value) {
893
+ var caller = "remove_ms_teams";
894
+ this._helper._remove_ms_teams(value, caller);
895
+ this._collect_payload();
896
+ }
897
+ }]);
898
+ return _Object;
899
+ }();
900
+ exports._Object = _Object;
901
+ var _default = ObjectsApi;
902
+ exports["default"] = _default;