@voucherify/sdk 2.0.2 → 2.0.5

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.
@@ -7,6 +7,13 @@
7
7
  axios = axios && Object.prototype.hasOwnProperty.call(axios, 'default') ? axios['default'] : axios;
8
8
  Qs = Qs && Object.prototype.hasOwnProperty.call(Qs, 'default') ? Qs['default'] : Qs;
9
9
 
10
+ (function (DiscountVouchersTypesEnum) {
11
+ DiscountVouchersTypesEnum["AMOUNT"] = "AMOUNT";
12
+ DiscountVouchersTypesEnum["PERCENT"] = "PERCENT";
13
+ DiscountVouchersTypesEnum["UNIT"] = "UNIT";
14
+ DiscountVouchersTypesEnum["FIXED"] = "FIXED";
15
+ })(exports.DiscountVouchersTypesEnum || (exports.DiscountVouchersTypesEnum = {}));
16
+
10
17
  /**
11
18
  * @internal
12
19
  */
@@ -41,9 +48,13 @@
41
48
  this.basePath = void 0;
42
49
  this.headers = void 0;
43
50
  this.request = void 0;
51
+ this.lastResponseHeaders = void 0;
52
+ this.isLastResponseHeadersSet = void 0;
44
53
  this.basePath = basePath;
45
54
  this.baseURL = baseURL;
46
55
  this.headers = headers;
56
+ this.lastResponseHeaders = {};
57
+ this.isLastResponseHeadersSet = false;
47
58
  this.request = axios.create({
48
59
  baseURL: `${this.baseURL}/${this.basePath}/`,
49
60
  headers: this.headers,
@@ -63,6 +74,19 @@
63
74
  });
64
75
  }
65
76
 
77
+ isLastReponseHeadersSet() {
78
+ return this.isLastResponseHeadersSet;
79
+ }
80
+
81
+ getLastResponseHeaders() {
82
+ return this.lastResponseHeaders;
83
+ }
84
+
85
+ setLastResponseHeaders(headers) {
86
+ this.lastResponseHeaders = headers;
87
+ this.isLastResponseHeadersSet = true;
88
+ }
89
+
66
90
  setBaseUrl(baseURL) {
67
91
  this.baseURL = baseURL;
68
92
  this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
@@ -75,6 +99,7 @@
75
99
  return Qs.stringify(params);
76
100
  }
77
101
  });
102
+ this.setLastResponseHeaders(response.headers);
78
103
  return response.data;
79
104
  }
80
105
 
@@ -86,6 +111,7 @@
86
111
  },
87
112
  headers
88
113
  });
114
+ this.setLastResponseHeaders(response.headers);
89
115
  return response.data;
90
116
  }
91
117
 
@@ -93,6 +119,7 @@
93
119
  const response = await this.request.put(path, body, {
94
120
  params
95
121
  });
122
+ this.setLastResponseHeaders(response.headers);
96
123
  return response.data;
97
124
  }
98
125
 
@@ -100,6 +127,7 @@
100
127
  const response = await this.request.delete(path, {
101
128
  params
102
129
  });
130
+ this.setLastResponseHeaders(response.headers);
103
131
  return response.data;
104
132
  }
105
133
 
@@ -508,6 +536,14 @@
508
536
 
509
537
  return this.validateVoucher(code, context);
510
538
  }
539
+ /**
540
+ * @see https://docs.voucherify.io/reference/validate-stacked-discounts-1
541
+ */
542
+
543
+
544
+ validateStackable(params) {
545
+ return this.client.post(`/validations`, params);
546
+ }
511
547
 
512
548
  }
513
549
 
@@ -524,6 +560,14 @@
524
560
  redeem(code, body = {}) {
525
561
  return this.client.post(`/vouchers/${encode(code)}/redemption`, body);
526
562
  }
563
+ /**
564
+ * @see https://docs.voucherify.io/reference/redeem-stacked-discounts
565
+ */
566
+
567
+
568
+ redeemStackable(params) {
569
+ return this.client.post(`/redemptions`, params);
570
+ }
527
571
  /**
528
572
  * @see https://docs.voucherify.io/reference/get-redemption
529
573
  */
@@ -576,6 +620,15 @@
576
620
 
577
621
  return this.client.post(`/redemptions/${encode(redemptionId)}/rollback`, payload, queryParams);
578
622
  }
623
+ /**
624
+ * @see https://docs.voucherify.io/reference/rollback-stackable-redemptions
625
+ * Types of params and queryParams WILL be changed in future - please do not depend on it!
626
+ */
627
+
628
+
629
+ rollbackStackable(parentRedemptionId, params, queryParams) {
630
+ return this.client.post(`/redemptions/${encode(parentRedemptionId)}/rollbacks`, params, queryParams);
631
+ }
579
632
 
580
633
  }
581
634
 
@@ -756,6 +809,14 @@
756
809
  updateConsents(idOrSourceId, consents) {
757
810
  return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
758
811
  }
812
+ /**
813
+ * @see https://docs.voucherify.io/reference/get-customer-activities
814
+ */
815
+
816
+
817
+ listActivities(customerId, params) {
818
+ return this.client.get(`/customers/${encode(customerId)}/activities`, params);
819
+ }
759
820
 
760
821
  }
761
822
 
@@ -1271,6 +1332,36 @@
1271
1332
 
1272
1333
  }
1273
1334
 
1335
+ class ApiLimitsHandler {
1336
+ constructor(requestController) {
1337
+ this.requestController = void 0;
1338
+ this.requestController = requestController;
1339
+ }
1340
+
1341
+ getLastResponseHeadersFromController() {
1342
+ return this.requestController.getLastResponseHeaders();
1343
+ }
1344
+
1345
+ areLimitsAvailable() {
1346
+ return this.requestController.isLastReponseHeadersSet();
1347
+ }
1348
+
1349
+ getRateLimit() {
1350
+ var _this$getLastResponse;
1351
+
1352
+ const rateLimit = (_this$getLastResponse = this.getLastResponseHeadersFromController()['x-rate-limit-limit']) != null ? _this$getLastResponse : 0;
1353
+ return parseInt(rateLimit, 10);
1354
+ }
1355
+
1356
+ getRateLimitRemaining() {
1357
+ var _this$getLastResponse2;
1358
+
1359
+ const rateLimitRemaining = (_this$getLastResponse2 = this.getLastResponseHeadersFromController()['x-rate-limit-remaining']) != null ? _this$getLastResponse2 : 0;
1360
+ return parseInt(rateLimitRemaining, 10);
1361
+ }
1362
+
1363
+ }
1364
+
1274
1365
  // campaigns: Campaigns
1275
1366
  // consents: Consents
1276
1367
  // customers: Customers
@@ -1299,7 +1390,7 @@
1299
1390
  let headers = {
1300
1391
  'X-App-Id': options.applicationId,
1301
1392
  'X-App-Token': options.secretKey,
1302
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.2"}`,
1393
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.5"}`,
1303
1394
  'Content-Type': 'application/json'
1304
1395
  };
1305
1396
 
@@ -1345,6 +1436,7 @@
1345
1436
  const loyalties = new Loyalties(client);
1346
1437
  const segments = new Segments(client);
1347
1438
  const validationRules = new ValidationRules(client);
1439
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1348
1440
  return {
1349
1441
  vouchers,
1350
1442
  campaigns,
@@ -1361,7 +1453,8 @@
1361
1453
  segments,
1362
1454
  validationRules,
1363
1455
  events,
1364
- asyncActions
1456
+ asyncActions,
1457
+ apiLimitsHandler
1365
1458
  };
1366
1459
  }
1367
1460
 
@@ -1514,6 +1607,22 @@
1514
1607
  updateConsents(idOrSourceId, consents) {
1515
1608
  return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
1516
1609
  }
1610
+ /**
1611
+ * @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
1612
+ */
1613
+
1614
+
1615
+ validateStackable(params) {
1616
+ return this.client.post(`/validations`, params);
1617
+ }
1618
+ /**
1619
+ * @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
1620
+ */
1621
+
1622
+
1623
+ redeemStackable(params) {
1624
+ return this.client.post(`/redemptions`, params);
1625
+ }
1517
1626
 
1518
1627
  }
1519
1628
 
@@ -1528,7 +1637,7 @@
1528
1637
  let headers = {
1529
1638
  'X-Client-Application-Id': options.clientApplicationId,
1530
1639
  'X-Client-Token': options.clientSecretKey,
1531
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.2"}`
1640
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.5"}`
1532
1641
  };
1533
1642
 
1534
1643
  if (environment().startsWith('Node')) {