@voucherify/sdk 2.0.3 → 2.0.6
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 +86 -0
- package/dist/ApiLimitsHandler.d.ts +9 -0
- package/dist/ClientSide.d.ts +8 -0
- package/dist/MetadataSchemas.d.ts +8 -0
- package/dist/Redemptions.d.ts +9 -0
- package/dist/RequestController.d.ts +5 -0
- package/dist/Validations.d.ts +4 -0
- package/dist/VoucherifyServerSide.d.ts +4 -0
- package/dist/types/ApplicableTo.d.ts +15 -0
- package/dist/types/ClientSide.d.ts +12 -13
- package/dist/types/DiscountVoucher.d.ts +27 -0
- package/dist/types/Gift.d.ts +3 -0
- package/dist/types/Loyalties.d.ts +4 -0
- package/dist/types/MetadataSchemas.d.ts +33 -0
- package/dist/types/Orders.d.ts +10 -0
- package/dist/types/Products.d.ts +10 -0
- package/dist/types/PromotionTiers.d.ts +3 -4
- package/dist/types/Promotions.d.ts +1 -1
- package/dist/types/Redemptions.d.ts +63 -13
- package/dist/types/Rewards.d.ts +5 -0
- package/dist/types/Stackable.d.ts +63 -0
- package/dist/types/ValidateSession.d.ts +17 -0
- package/dist/types/ValidationRules.d.ts +2 -5
- package/dist/types/Validations.d.ts +23 -17
- package/dist/types/Vouchers.d.ts +1 -15
- package/dist/types/index.d.ts +5 -0
- package/dist/voucherifysdk.esm.js +127 -4
- package/dist/voucherifysdk.esm.js.map +1 -1
- package/dist/voucherifysdk.umd.development.js +124 -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
|
@@ -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
|
|
|
@@ -1279,12 +1332,60 @@
|
|
|
1279
1332
|
|
|
1280
1333
|
}
|
|
1281
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
|
|
1282
1382
|
// campaigns: Campaigns
|
|
1283
1383
|
// consents: Consents
|
|
1284
1384
|
// customers: Customers
|
|
1285
1385
|
// distributions: Distributions
|
|
1286
1386
|
// events: Events
|
|
1287
1387
|
// loyalties: Loyalties
|
|
1388
|
+
// metadataSchemas: MetadataSchemas
|
|
1288
1389
|
// orders: Orders
|
|
1289
1390
|
// products: Products
|
|
1290
1391
|
// promotions: Promotions
|
|
@@ -1307,7 +1408,7 @@
|
|
|
1307
1408
|
let headers = {
|
|
1308
1409
|
'X-App-Id': options.applicationId,
|
|
1309
1410
|
'X-App-Token': options.secretKey,
|
|
1310
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.
|
|
1411
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.6"}`,
|
|
1311
1412
|
'Content-Type': 'application/json'
|
|
1312
1413
|
};
|
|
1313
1414
|
|
|
@@ -1353,6 +1454,8 @@
|
|
|
1353
1454
|
const loyalties = new Loyalties(client);
|
|
1354
1455
|
const segments = new Segments(client);
|
|
1355
1456
|
const validationRules = new ValidationRules(client);
|
|
1457
|
+
const apiLimitsHandler = new ApiLimitsHandler(client);
|
|
1458
|
+
const metadataSchemas = new MetadataSchemas(client);
|
|
1356
1459
|
return {
|
|
1357
1460
|
vouchers,
|
|
1358
1461
|
campaigns,
|
|
@@ -1369,7 +1472,9 @@
|
|
|
1369
1472
|
segments,
|
|
1370
1473
|
validationRules,
|
|
1371
1474
|
events,
|
|
1372
|
-
asyncActions
|
|
1475
|
+
asyncActions,
|
|
1476
|
+
apiLimitsHandler,
|
|
1477
|
+
metadataSchemas
|
|
1373
1478
|
};
|
|
1374
1479
|
}
|
|
1375
1480
|
|
|
@@ -1522,6 +1627,22 @@
|
|
|
1522
1627
|
updateConsents(idOrSourceId, consents) {
|
|
1523
1628
|
return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
|
|
1524
1629
|
}
|
|
1630
|
+
/**
|
|
1631
|
+
* @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
|
|
1632
|
+
*/
|
|
1633
|
+
|
|
1634
|
+
|
|
1635
|
+
validateStackable(params) {
|
|
1636
|
+
return this.client.post(`/validations`, params);
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
|
|
1640
|
+
*/
|
|
1641
|
+
|
|
1642
|
+
|
|
1643
|
+
redeemStackable(params) {
|
|
1644
|
+
return this.client.post(`/redemptions`, params);
|
|
1645
|
+
}
|
|
1525
1646
|
|
|
1526
1647
|
}
|
|
1527
1648
|
|
|
@@ -1536,7 +1657,7 @@
|
|
|
1536
1657
|
let headers = {
|
|
1537
1658
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
1538
1659
|
'X-Client-Token': options.clientSecretKey,
|
|
1539
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.
|
|
1660
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.6"}`
|
|
1540
1661
|
};
|
|
1541
1662
|
|
|
1542
1663
|
if (environment().startsWith('Node')) {
|