@suprsend/node-sdk 1.11.0 → 1.12.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.
@@ -0,0 +1,576 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _utils = require("./utils");
13
+ var _signature = _interopRequireDefault(require("./signature"));
14
+ var _axios = _interopRequireDefault(require("axios"));
15
+ var _object_edit = _interopRequireDefault(require("./object_edit"));
16
+ var ObjectsApi = /*#__PURE__*/function () {
17
+ function ObjectsApi(config) {
18
+ (0, _classCallCheck2["default"])(this, ObjectsApi);
19
+ this.config = config;
20
+ this.list_url = "".concat(this.config.base_url, "v1/object/");
21
+ }
22
+ (0, _createClass2["default"])(ObjectsApi, [{
23
+ key: "get_headers",
24
+ value: function get_headers() {
25
+ return {
26
+ "Content-Type": "application/json; charset=utf-8",
27
+ "User-Agent": this.config.user_agent,
28
+ Date: new Date().toISOString() // Adjust to your header date format
29
+ };
30
+ }
31
+ }, {
32
+ key: "validate_object_type",
33
+ value: function validate_object_type(object_type) {
34
+ if (!(0, _utils.is_string)(object_type)) {
35
+ throw new _utils.InputValueError("object_type must be a string");
36
+ }
37
+ object_type = object_type.trim();
38
+ if (!object_type) {
39
+ throw new _utils.InputValueError("missing object_type");
40
+ }
41
+ return object_type;
42
+ }
43
+ }, {
44
+ key: "validate_object_id",
45
+ value: function validate_object_id(object_id) {
46
+ if (!(0, _utils.is_string)(object_id)) {
47
+ throw new _utils.InputValueError("object_id must be a string");
48
+ }
49
+ object_id = object_id.trim();
50
+ if (!object_id) {
51
+ throw new _utils.InputValueError("missing object_id");
52
+ }
53
+ return object_id;
54
+ }
55
+ }, {
56
+ key: "list",
57
+ value: function () {
58
+ var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(object_type) {
59
+ var options,
60
+ params,
61
+ validated_type,
62
+ encoded_type,
63
+ url,
64
+ headers,
65
+ signature,
66
+ response,
67
+ _args = arguments;
68
+ return _regenerator["default"].wrap(function _callee$(_context) {
69
+ while (1) {
70
+ switch (_context.prev = _context.next) {
71
+ case 0:
72
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
73
+ params = new URLSearchParams(options).toString();
74
+ validated_type = this.validate_object_type(object_type);
75
+ encoded_type = encodeURIComponent(validated_type);
76
+ url = "".concat(this.list_url).concat(encoded_type, "/?").concat(params);
77
+ headers = this.get_headers();
78
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
79
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
80
+ _context.prev = 8;
81
+ _context.next = 11;
82
+ return _axios["default"].get(url, {
83
+ headers: headers
84
+ });
85
+ case 11:
86
+ response = _context.sent;
87
+ return _context.abrupt("return", response.data);
88
+ case 15:
89
+ _context.prev = 15;
90
+ _context.t0 = _context["catch"](8);
91
+ throw new _utils.SuprsendApiError(_context.t0);
92
+ case 18:
93
+ case "end":
94
+ return _context.stop();
95
+ }
96
+ }
97
+ }, _callee, this, [[8, 15]]);
98
+ }));
99
+ function list(_x) {
100
+ return _list.apply(this, arguments);
101
+ }
102
+ return list;
103
+ }()
104
+ }, {
105
+ key: "detail_url",
106
+ value: function detail_url(object_type, object_id) {
107
+ var validated_type = this.validate_object_type(object_type);
108
+ var encoded_type = encodeURIComponent(validated_type);
109
+ var validated_id = this.validate_object_id(object_id);
110
+ var encoded_id = encodeURIComponent(validated_id);
111
+ return "".concat(this.list_url).concat(encoded_type, "/").concat(encoded_id, "/");
112
+ }
113
+ }, {
114
+ key: "get",
115
+ value: function () {
116
+ var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(object_type, object_id) {
117
+ var url, headers, signature, response;
118
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
119
+ while (1) {
120
+ switch (_context2.prev = _context2.next) {
121
+ case 0:
122
+ url = this.detail_url(object_type, object_id);
123
+ headers = this.get_headers();
124
+ signature = (0, _signature["default"])(url, "GET", "", headers, this.config.workspace_secret);
125
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
126
+ _context2.prev = 4;
127
+ _context2.next = 7;
128
+ return _axios["default"].get(url, {
129
+ headers: headers
130
+ });
131
+ case 7:
132
+ response = _context2.sent;
133
+ return _context2.abrupt("return", response.data);
134
+ case 11:
135
+ _context2.prev = 11;
136
+ _context2.t0 = _context2["catch"](4);
137
+ throw new _utils.SuprsendApiError(_context2.t0);
138
+ case 14:
139
+ case "end":
140
+ return _context2.stop();
141
+ }
142
+ }
143
+ }, _callee2, this, [[4, 11]]);
144
+ }));
145
+ function get(_x2, _x3) {
146
+ return _get.apply(this, arguments);
147
+ }
148
+ return get;
149
+ }()
150
+ }, {
151
+ key: "upsert",
152
+ value: function () {
153
+ var _upsert = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(object_type, object_id) {
154
+ var object_payload,
155
+ url,
156
+ headers,
157
+ content_text,
158
+ signature,
159
+ response,
160
+ _args3 = arguments;
161
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
162
+ while (1) {
163
+ switch (_context3.prev = _context3.next) {
164
+ case 0:
165
+ object_payload = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
166
+ url = this.detail_url(object_type, object_id);
167
+ headers = this.get_headers();
168
+ content_text = JSON.stringify(object_payload || {});
169
+ signature = (0, _signature["default"])(url, "POST", content_text, headers, this.config.workspace_secret);
170
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
171
+ _context3.prev = 6;
172
+ _context3.next = 9;
173
+ return _axios["default"].post(url, content_text, {
174
+ headers: headers
175
+ });
176
+ case 9:
177
+ response = _context3.sent;
178
+ return _context3.abrupt("return", response.data);
179
+ case 13:
180
+ _context3.prev = 13;
181
+ _context3.t0 = _context3["catch"](6);
182
+ throw new _utils.SuprsendApiError(_context3.t0);
183
+ case 16:
184
+ case "end":
185
+ return _context3.stop();
186
+ }
187
+ }
188
+ }, _callee3, this, [[6, 13]]);
189
+ }));
190
+ function upsert(_x4, _x5) {
191
+ return _upsert.apply(this, arguments);
192
+ }
193
+ return upsert;
194
+ }()
195
+ }, {
196
+ key: "edit",
197
+ value: function () {
198
+ var _edit = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(object_type, object_id) {
199
+ var edit_payload,
200
+ url,
201
+ payload,
202
+ edit_instance,
203
+ content_text,
204
+ headers,
205
+ signature,
206
+ response,
207
+ _args4 = arguments;
208
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
209
+ while (1) {
210
+ switch (_context4.prev = _context4.next) {
211
+ case 0:
212
+ edit_payload = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
213
+ if (object_type instanceof _object_edit["default"]) {
214
+ edit_instance = object_type;
215
+ edit_instance.validate_body();
216
+ url = this.detail_url(edit_instance.get_object_type(), edit_instance.get_object_id());
217
+ payload = edit_instance.get_payload();
218
+ } else {
219
+ url = this.detail_url(object_type, object_id);
220
+ payload = edit_payload;
221
+ }
222
+ content_text = JSON.stringify(payload || {});
223
+ headers = this.get_headers();
224
+ signature = (0, _signature["default"])(url, "PATCH", content_text, headers, this.config.workspace_secret);
225
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
226
+ _context4.prev = 6;
227
+ _context4.next = 9;
228
+ return _axios["default"].patch(url, content_text, {
229
+ headers: headers
230
+ });
231
+ case 9:
232
+ response = _context4.sent;
233
+ return _context4.abrupt("return", response.data);
234
+ case 13:
235
+ _context4.prev = 13;
236
+ _context4.t0 = _context4["catch"](6);
237
+ throw new _utils.SuprsendApiError(_context4.t0);
238
+ case 16:
239
+ case "end":
240
+ return _context4.stop();
241
+ }
242
+ }
243
+ }, _callee4, this, [[6, 13]]);
244
+ }));
245
+ function edit(_x6, _x7) {
246
+ return _edit.apply(this, arguments);
247
+ }
248
+ return edit;
249
+ }()
250
+ }, {
251
+ key: "delete",
252
+ value: function () {
253
+ var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(object_type, object_id) {
254
+ var url, headers, signature, response;
255
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
256
+ while (1) {
257
+ switch (_context5.prev = _context5.next) {
258
+ case 0:
259
+ url = this.detail_url(object_type, object_id);
260
+ headers = this.get_headers();
261
+ signature = (0, _signature["default"])(url, "DELETE", "", headers, this.config.workspace_secret);
262
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
263
+ _context5.prev = 4;
264
+ _context5.next = 7;
265
+ return _axios["default"]["delete"](url, {
266
+ headers: headers
267
+ });
268
+ case 7:
269
+ response = _context5.sent;
270
+ if (!(response.status >= 200 && response.status < 300)) {
271
+ _context5.next = 12;
272
+ break;
273
+ }
274
+ return _context5.abrupt("return", {
275
+ success: true,
276
+ status_code: response.status
277
+ });
278
+ case 12:
279
+ throw new _utils.SuprsendApiError(response.statusText);
280
+ case 13:
281
+ _context5.next = 18;
282
+ break;
283
+ case 15:
284
+ _context5.prev = 15;
285
+ _context5.t0 = _context5["catch"](4);
286
+ throw new _utils.SuprsendApiError(_context5.t0);
287
+ case 18:
288
+ case "end":
289
+ return _context5.stop();
290
+ }
291
+ }
292
+ }, _callee5, this, [[4, 15]]);
293
+ }));
294
+ function _delete(_x8, _x9) {
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 _callee6(object_type) {
303
+ var validatedType, encodedType;
304
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
305
+ while (1) {
306
+ switch (_context6.prev = _context6.next) {
307
+ case 0:
308
+ validatedType = this.validate_object_type(object_type);
309
+ encodedType = encodeURIComponent(validatedType);
310
+ return _context6.abrupt("return", "".concat(this.config.base_url, "v1/bulk/object/").concat(encodedType, "/"));
311
+ case 3:
312
+ case "end":
313
+ return _context6.stop();
314
+ }
315
+ }
316
+ }, _callee6, this);
317
+ }));
318
+ function bulk_ops_url(_x10) {
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 _callee7(object_type, payload) {
327
+ var url, headers, content_text, signature, response;
328
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
329
+ while (1) {
330
+ switch (_context7.prev = _context7.next) {
331
+ case 0:
332
+ _context7.next = 2;
333
+ return this.bulk_ops_url(object_type);
334
+ case 2:
335
+ url = _context7.sent;
336
+ headers = this.get_headers();
337
+ payload = payload || {};
338
+ content_text = JSON.stringify(payload);
339
+ signature = (0, _signature["default"])(url, "DELETE", content_text, headers, this.config.workspace_secret);
340
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
341
+ _context7.prev = 8;
342
+ _context7.next = 11;
343
+ return _axios["default"]["delete"](url, {
344
+ headers: headers,
345
+ data: payload
346
+ });
347
+ case 11:
348
+ response = _context7.sent;
349
+ if (!(response.status >= 200 && response.status < 300)) {
350
+ _context7.next = 16;
351
+ break;
352
+ }
353
+ return _context7.abrupt("return", {
354
+ success: true,
355
+ status_code: response.status
356
+ });
357
+ case 16:
358
+ throw new _utils.SuprsendApiError(response.statusText);
359
+ case 17:
360
+ _context7.next = 22;
361
+ break;
362
+ case 19:
363
+ _context7.prev = 19;
364
+ _context7.t0 = _context7["catch"](8);
365
+ throw new _utils.SuprsendApiError(_context7.t0);
366
+ case 22:
367
+ case "end":
368
+ return _context7.stop();
369
+ }
370
+ }
371
+ }, _callee7, this, [[8, 19]]);
372
+ }));
373
+ function bulk_delete(_x11, _x12) {
374
+ return _bulk_delete.apply(this, arguments);
375
+ }
376
+ return bulk_delete;
377
+ }()
378
+ }, {
379
+ key: "get_subscriptions",
380
+ value: function () {
381
+ var _get_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(object_type, object_id) {
382
+ var options,
383
+ params,
384
+ url,
385
+ subscription_url,
386
+ headers,
387
+ signature,
388
+ response,
389
+ _args8 = arguments;
390
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
391
+ while (1) {
392
+ switch (_context8.prev = _context8.next) {
393
+ case 0:
394
+ options = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : {};
395
+ params = new URLSearchParams(options).toString();
396
+ url = this.detail_url(object_type, object_id);
397
+ subscription_url = "".concat(url, "subscription/?").concat(params);
398
+ headers = this.get_headers();
399
+ signature = (0, _signature["default"])(subscription_url, "GET", "", headers, this.config.workspace_secret);
400
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
401
+ _context8.prev = 7;
402
+ _context8.next = 10;
403
+ return _axios["default"].get(subscription_url, {
404
+ headers: headers
405
+ });
406
+ case 10:
407
+ response = _context8.sent;
408
+ return _context8.abrupt("return", response.data);
409
+ case 14:
410
+ _context8.prev = 14;
411
+ _context8.t0 = _context8["catch"](7);
412
+ throw new _utils.SuprsendApiError(_context8.t0);
413
+ case 17:
414
+ case "end":
415
+ return _context8.stop();
416
+ }
417
+ }
418
+ }, _callee8, this, [[7, 14]]);
419
+ }));
420
+ function get_subscriptions(_x13, _x14) {
421
+ return _get_subscriptions.apply(this, arguments);
422
+ }
423
+ return get_subscriptions;
424
+ }()
425
+ }, {
426
+ key: "create_subscriptions",
427
+ value: function () {
428
+ var _create_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(object_type, object_id, subscriptions) {
429
+ var url, subscription_url, headers, content_text, signature, response;
430
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
431
+ while (1) {
432
+ switch (_context9.prev = _context9.next) {
433
+ case 0:
434
+ url = this.detail_url(object_type, object_id);
435
+ subscription_url = "".concat(url, "subscription/");
436
+ headers = this.get_headers();
437
+ subscriptions = subscriptions || {};
438
+ content_text = JSON.stringify(subscriptions);
439
+ signature = (0, _signature["default"])(subscription_url, "POST", content_text, headers, this.config.workspace_secret);
440
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
441
+ _context9.prev = 7;
442
+ _context9.next = 10;
443
+ return _axios["default"].post(subscription_url, content_text, {
444
+ headers: headers
445
+ });
446
+ case 10:
447
+ response = _context9.sent;
448
+ return _context9.abrupt("return", response.data);
449
+ case 14:
450
+ _context9.prev = 14;
451
+ _context9.t0 = _context9["catch"](7);
452
+ throw new _utils.SuprsendApiError(_context9.t0);
453
+ case 17:
454
+ case "end":
455
+ return _context9.stop();
456
+ }
457
+ }
458
+ }, _callee9, this, [[7, 14]]);
459
+ }));
460
+ function create_subscriptions(_x15, _x16, _x17) {
461
+ return _create_subscriptions.apply(this, arguments);
462
+ }
463
+ return create_subscriptions;
464
+ }()
465
+ }, {
466
+ key: "delete_subscriptions",
467
+ value: function () {
468
+ var _delete_subscriptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(object_type, object_id, subscriptions) {
469
+ var url, subscription_url, headers, content_text, signature, response;
470
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
471
+ while (1) {
472
+ switch (_context10.prev = _context10.next) {
473
+ case 0:
474
+ url = this.detail_url(object_type, object_id);
475
+ subscription_url = "".concat(url, "subscription/");
476
+ headers = this.get_headers();
477
+ subscriptions = subscriptions || {};
478
+ content_text = JSON.stringify(subscriptions);
479
+ signature = (0, _signature["default"])(subscription_url, "DELETE", content_text, headers, this.config.workspace_secret);
480
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
481
+ _context10.prev = 7;
482
+ _context10.next = 10;
483
+ return _axios["default"]["delete"](subscription_url, {
484
+ headers: headers,
485
+ data: subscriptions
486
+ });
487
+ case 10:
488
+ response = _context10.sent;
489
+ if (!(response.status >= 200 && response.status < 300)) {
490
+ _context10.next = 15;
491
+ break;
492
+ }
493
+ return _context10.abrupt("return", {
494
+ success: true,
495
+ status_code: response.status
496
+ });
497
+ case 15:
498
+ throw new _utils.SuprsendApiError(response.statusText);
499
+ case 16:
500
+ _context10.next = 21;
501
+ break;
502
+ case 18:
503
+ _context10.prev = 18;
504
+ _context10.t0 = _context10["catch"](7);
505
+ throw new _utils.SuprsendApiError(_context10.t0);
506
+ case 21:
507
+ case "end":
508
+ return _context10.stop();
509
+ }
510
+ }
511
+ }, _callee10, this, [[7, 18]]);
512
+ }));
513
+ function delete_subscriptions(_x18, _x19, _x20) {
514
+ return _delete_subscriptions.apply(this, arguments);
515
+ }
516
+ return delete_subscriptions;
517
+ }()
518
+ }, {
519
+ key: "get_objects_subscribed_to",
520
+ value: function () {
521
+ var _get_objects_subscribed_to = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(object_type, object_id) {
522
+ var options,
523
+ params,
524
+ url,
525
+ subscription_url,
526
+ headers,
527
+ signature,
528
+ response,
529
+ _args11 = arguments;
530
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
531
+ while (1) {
532
+ switch (_context11.prev = _context11.next) {
533
+ case 0:
534
+ options = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : {};
535
+ params = new URLSearchParams(options).toString();
536
+ url = this.detail_url(object_type, object_id);
537
+ subscription_url = "".concat(url, "subscribed_to/object/?").concat(params);
538
+ headers = this.get_headers();
539
+ signature = (0, _signature["default"])(subscription_url, "GET", "", headers, this.config.workspace_secret);
540
+ headers["Authorization"] = "".concat(this.config.workspace_key, ":").concat(signature);
541
+ _context11.prev = 7;
542
+ _context11.next = 10;
543
+ return _axios["default"].get(subscription_url, {
544
+ headers: headers
545
+ });
546
+ case 10:
547
+ response = _context11.sent;
548
+ return _context11.abrupt("return", response.data);
549
+ case 14:
550
+ _context11.prev = 14;
551
+ _context11.t0 = _context11["catch"](7);
552
+ throw new _utils.SuprsendApiError(_context11.t0);
553
+ case 17:
554
+ case "end":
555
+ return _context11.stop();
556
+ }
557
+ }
558
+ }, _callee11, this, [[7, 14]]);
559
+ }));
560
+ function get_objects_subscribed_to(_x21, _x22) {
561
+ return _get_objects_subscribed_to.apply(this, arguments);
562
+ }
563
+ return get_objects_subscribed_to;
564
+ }()
565
+ }, {
566
+ key: "get_instance",
567
+ value: function get_instance(object_type, object_id) {
568
+ var validated_type = this.validate_object_type(object_type);
569
+ var validated_id = this.validate_object_id(object_id);
570
+ return new _object_edit["default"](this.config, validated_type, validated_id);
571
+ }
572
+ }]);
573
+ return ObjectsApi;
574
+ }();
575
+ exports["default"] = ObjectsApi;
576
+ module.exports = exports.default;
@@ -128,7 +128,8 @@ var Subscriber = /*#__PURE__*/function () {
128
128
  if (is_part_of_bulk) {
129
129
  console.log(err_msg);
130
130
  } else {
131
- throw new _utils.InputValueError(err_msg);
131
+ // throw new InputValueError(err_msg);
132
+ console.log(err_msg);
132
133
  }
133
134
  }
134
135
  return this.__warnings_list;