@voucherify/sdk 2.0.4 → 2.0.7
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/CHANGELOG.md +18 -0
- package/README.md +53 -0
- package/dist/ApiLimitsHandler.d.ts +9 -0
- package/dist/MetadataSchemas.d.ts +8 -0
- package/dist/RequestController.d.ts +5 -0
- package/dist/VoucherifyServerSide.d.ts +4 -0
- package/dist/types/DiscountVoucher.d.ts +2 -0
- package/dist/types/MetadataSchemas.d.ts +33 -0
- package/dist/types/Orders.d.ts +2 -0
- package/dist/types/Validations.d.ts +3 -0
- package/dist/voucherifysdk.esm.js +76 -3
- package/dist/voucherifysdk.esm.js.map +1 -1
- package/dist/voucherifysdk.umd.development.js +76 -3
- package/dist/voucherifysdk.umd.development.js.map +1 -1
- package/dist/voucherifysdk.umd.production.min.js +1 -1
- package/dist/voucherifysdk.umd.production.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,12 +1332,60 @@
|
|
|
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
|
+
|
|
1365
|
+
class MetadataSchemas {
|
|
1366
|
+
constructor(client) {
|
|
1367
|
+
this.client = void 0;
|
|
1368
|
+
this.client = client;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
list() {
|
|
1372
|
+
return this.client.get('/metadata-schemas');
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
get(schemaName) {
|
|
1376
|
+
return this.client.get(`/metadata-schemas/${encode(schemaName)}`);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// apiLimitsHandler: ApiLimitsHandler
|
|
1314
1382
|
// campaigns: Campaigns
|
|
1315
1383
|
// consents: Consents
|
|
1316
1384
|
// customers: Customers
|
|
1317
1385
|
// distributions: Distributions
|
|
1318
1386
|
// events: Events
|
|
1319
1387
|
// loyalties: Loyalties
|
|
1388
|
+
// metadataSchemas: MetadataSchemas
|
|
1320
1389
|
// orders: Orders
|
|
1321
1390
|
// products: Products
|
|
1322
1391
|
// promotions: Promotions
|
|
@@ -1339,7 +1408,7 @@
|
|
|
1339
1408
|
let headers = {
|
|
1340
1409
|
'X-App-Id': options.applicationId,
|
|
1341
1410
|
'X-App-Token': options.secretKey,
|
|
1342
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.
|
|
1411
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.7"}`,
|
|
1343
1412
|
'Content-Type': 'application/json'
|
|
1344
1413
|
};
|
|
1345
1414
|
|
|
@@ -1385,6 +1454,8 @@
|
|
|
1385
1454
|
const loyalties = new Loyalties(client);
|
|
1386
1455
|
const segments = new Segments(client);
|
|
1387
1456
|
const validationRules = new ValidationRules(client);
|
|
1457
|
+
const apiLimitsHandler = new ApiLimitsHandler(client);
|
|
1458
|
+
const metadataSchemas = new MetadataSchemas(client);
|
|
1388
1459
|
return {
|
|
1389
1460
|
vouchers,
|
|
1390
1461
|
campaigns,
|
|
@@ -1401,7 +1472,9 @@
|
|
|
1401
1472
|
segments,
|
|
1402
1473
|
validationRules,
|
|
1403
1474
|
events,
|
|
1404
|
-
asyncActions
|
|
1475
|
+
asyncActions,
|
|
1476
|
+
apiLimitsHandler,
|
|
1477
|
+
metadataSchemas
|
|
1405
1478
|
};
|
|
1406
1479
|
}
|
|
1407
1480
|
|
|
@@ -1584,7 +1657,7 @@
|
|
|
1584
1657
|
let headers = {
|
|
1585
1658
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
1586
1659
|
'X-Client-Token': options.clientSecretKey,
|
|
1587
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.
|
|
1660
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.7"}`
|
|
1588
1661
|
};
|
|
1589
1662
|
|
|
1590
1663
|
if (environment().startsWith('Node')) {
|