@voucherify/sdk 2.0.4 → 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.
@@ -48,9 +48,13 @@
48
48
  this.basePath = void 0;
49
49
  this.headers = void 0;
50
50
  this.request = void 0;
51
+ this.lastResponseHeaders = void 0;
52
+ this.isLastResponseHeadersSet = void 0;
51
53
  this.basePath = basePath;
52
54
  this.baseURL = baseURL;
53
55
  this.headers = headers;
56
+ this.lastResponseHeaders = {};
57
+ this.isLastResponseHeadersSet = false;
54
58
  this.request = axios.create({
55
59
  baseURL: `${this.baseURL}/${this.basePath}/`,
56
60
  headers: this.headers,
@@ -70,6 +74,19 @@
70
74
  });
71
75
  }
72
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
+
73
90
  setBaseUrl(baseURL) {
74
91
  this.baseURL = baseURL;
75
92
  this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
@@ -82,6 +99,7 @@
82
99
  return Qs.stringify(params);
83
100
  }
84
101
  });
102
+ this.setLastResponseHeaders(response.headers);
85
103
  return response.data;
86
104
  }
87
105
 
@@ -93,6 +111,7 @@
93
111
  },
94
112
  headers
95
113
  });
114
+ this.setLastResponseHeaders(response.headers);
96
115
  return response.data;
97
116
  }
98
117
 
@@ -100,6 +119,7 @@
100
119
  const response = await this.request.put(path, body, {
101
120
  params
102
121
  });
122
+ this.setLastResponseHeaders(response.headers);
103
123
  return response.data;
104
124
  }
105
125
 
@@ -107,6 +127,7 @@
107
127
  const response = await this.request.delete(path, {
108
128
  params
109
129
  });
130
+ this.setLastResponseHeaders(response.headers);
110
131
  return response.data;
111
132
  }
112
133
 
@@ -1311,6 +1332,36 @@
1311
1332
 
1312
1333
  }
1313
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
+
1314
1365
  // campaigns: Campaigns
1315
1366
  // consents: Consents
1316
1367
  // customers: Customers
@@ -1339,7 +1390,7 @@
1339
1390
  let headers = {
1340
1391
  'X-App-Id': options.applicationId,
1341
1392
  'X-App-Token': options.secretKey,
1342
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.4"}`,
1393
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.5"}`,
1343
1394
  'Content-Type': 'application/json'
1344
1395
  };
1345
1396
 
@@ -1385,6 +1436,7 @@
1385
1436
  const loyalties = new Loyalties(client);
1386
1437
  const segments = new Segments(client);
1387
1438
  const validationRules = new ValidationRules(client);
1439
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1388
1440
  return {
1389
1441
  vouchers,
1390
1442
  campaigns,
@@ -1401,7 +1453,8 @@
1401
1453
  segments,
1402
1454
  validationRules,
1403
1455
  events,
1404
- asyncActions
1456
+ asyncActions,
1457
+ apiLimitsHandler
1405
1458
  };
1406
1459
  }
1407
1460
 
@@ -1584,7 +1637,7 @@
1584
1637
  let headers = {
1585
1638
  'X-Client-Application-Id': options.clientApplicationId,
1586
1639
  'X-Client-Token': options.clientSecretKey,
1587
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.4"}`
1640
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.5"}`
1588
1641
  };
1589
1642
 
1590
1643
  if (environment().startsWith('Node')) {