@voucherify/sdk 2.2.5 → 2.3.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.
- package/CHANGELOG.md +37 -0
- package/README.md +91 -1
- package/dist/Campaigns.d.ts +13 -0
- package/dist/Categories.d.ts +26 -0
- package/dist/Customers.d.ts +5 -0
- package/dist/Products.d.ts +9 -0
- package/dist/RequestController.d.ts +3 -1
- package/dist/VoucherifyClientSide.d.ts +4 -0
- package/dist/VoucherifyServerSide.d.ts +6 -0
- package/dist/Vouchers.d.ts +5 -0
- package/dist/types/Categories.d.ts +24 -0
- package/dist/voucherifysdk.esm.js +152 -11
- package/dist/voucherifysdk.esm.js.map +1 -1
- package/dist/voucherifysdk.umd.development.js +156 -15
- 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 +10 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('axios'), require('qs')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'axios', 'qs'], factory) :
|
|
4
|
-
(global = global || self, factory(global.VoucherifySDK = {}, global.axios, global.Qs));
|
|
5
|
-
}(this, (function (exports, axios, Qs) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('axios'), require('qs'), require('form-data')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'axios', 'qs', 'form-data'], factory) :
|
|
4
|
+
(global = global || self, factory(global.VoucherifySDK = {}, global.axios, global.Qs, global.FormData));
|
|
5
|
+
}(this, (function (exports, axios, Qs, FormData) { 'use strict';
|
|
6
6
|
|
|
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
|
+
FormData = FormData && Object.prototype.hasOwnProperty.call(FormData, 'default') ? FormData['default'] : FormData;
|
|
9
10
|
|
|
10
11
|
(function (DiscountVouchersTypesEnum) {
|
|
11
12
|
DiscountVouchersTypesEnum["AMOUNT"] = "AMOUNT";
|
|
@@ -62,7 +63,8 @@
|
|
|
62
63
|
basePath,
|
|
63
64
|
baseURL,
|
|
64
65
|
headers,
|
|
65
|
-
exposeErrorCause
|
|
66
|
+
exposeErrorCause,
|
|
67
|
+
timeoutMs
|
|
66
68
|
}) {
|
|
67
69
|
this.baseURL = void 0;
|
|
68
70
|
this.basePath = void 0;
|
|
@@ -71,12 +73,14 @@
|
|
|
71
73
|
this.lastResponseHeaders = void 0;
|
|
72
74
|
this.isLastResponseHeadersSet = void 0;
|
|
73
75
|
this.exposeErrorCause = void 0;
|
|
76
|
+
this.timeoutMs = void 0;
|
|
74
77
|
this.basePath = basePath;
|
|
75
78
|
this.baseURL = baseURL;
|
|
76
79
|
this.headers = headers;
|
|
77
80
|
this.exposeErrorCause = exposeErrorCause;
|
|
78
81
|
this.lastResponseHeaders = {};
|
|
79
82
|
this.isLastResponseHeadersSet = false;
|
|
83
|
+
this.timeoutMs = timeoutMs;
|
|
80
84
|
this.request = axios.create({
|
|
81
85
|
baseURL: `${this.baseURL}/${this.basePath}/`,
|
|
82
86
|
headers: this.headers,
|
|
@@ -119,7 +123,8 @@
|
|
|
119
123
|
params,
|
|
120
124
|
paramsSerializer: function (params) {
|
|
121
125
|
return Qs.stringify(params);
|
|
122
|
-
}
|
|
126
|
+
},
|
|
127
|
+
timeout: this.timeoutMs
|
|
123
128
|
});
|
|
124
129
|
this.setLastResponseHeaders(response.headers);
|
|
125
130
|
return response.data;
|
|
@@ -131,7 +136,8 @@
|
|
|
131
136
|
paramsSerializer: function (params) {
|
|
132
137
|
return Qs.stringify(params);
|
|
133
138
|
},
|
|
134
|
-
headers
|
|
139
|
+
headers,
|
|
140
|
+
timeout: this.timeoutMs
|
|
135
141
|
});
|
|
136
142
|
this.setLastResponseHeaders(response.headers);
|
|
137
143
|
return response.data;
|
|
@@ -139,7 +145,8 @@
|
|
|
139
145
|
|
|
140
146
|
async put(path, body, params) {
|
|
141
147
|
const response = await this.request.put(path, body, {
|
|
142
|
-
params
|
|
148
|
+
params,
|
|
149
|
+
timeout: this.timeoutMs
|
|
143
150
|
});
|
|
144
151
|
this.setLastResponseHeaders(response.headers);
|
|
145
152
|
return response.data;
|
|
@@ -147,7 +154,8 @@
|
|
|
147
154
|
|
|
148
155
|
async delete(path, params) {
|
|
149
156
|
const response = await this.request.delete(path, {
|
|
150
|
-
params
|
|
157
|
+
params,
|
|
158
|
+
timeout: this.timeoutMs
|
|
151
159
|
});
|
|
152
160
|
this.setLastResponseHeaders(response.headers);
|
|
153
161
|
return response.data;
|
|
@@ -308,6 +316,35 @@
|
|
|
308
316
|
list(params = {}) {
|
|
309
317
|
return this.client.get('/campaigns', params);
|
|
310
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
async importVouchersCSV(campaignId, filePath) {
|
|
325
|
+
assert(environment().startsWith('Node'), `Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment`);
|
|
326
|
+
const fs = (await import('fs')).default;
|
|
327
|
+
const fileStream = fs.createReadStream(filePath);
|
|
328
|
+
const form = new FormData();
|
|
329
|
+
form.append('file', fileStream);
|
|
330
|
+
return this.client.post(`/campaigns/${campaignId}/importCSV`, form);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* @see https://docs.voucherify.io/reference/enable-campaign
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
enable(campaignId) {
|
|
338
|
+
return this.client.post(`/campaigns/${encode(campaignId)}/enable`, {});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* @see https://docs.voucherify.io/reference/disable-campaign
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
disable(campaignId) {
|
|
346
|
+
return this.client.post(`/campaigns/${encode(campaignId)}/disable`, {});
|
|
347
|
+
}
|
|
311
348
|
|
|
312
349
|
}
|
|
313
350
|
|
|
@@ -532,6 +569,19 @@
|
|
|
532
569
|
releaseValidationSession(code, sessionKey) {
|
|
533
570
|
return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
|
|
534
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* @see https://docs.voucherify.io/reference/import-vouchers-using-csv
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
async importCSV(filePath) {
|
|
578
|
+
assert(environment().startsWith('Node'), `Method "client.vouchers.importCSV(filePath)" is only for Node environment`);
|
|
579
|
+
const fs = (await import('fs')).default;
|
|
580
|
+
const fileStream = fs.createReadStream(filePath);
|
|
581
|
+
const form = new FormData();
|
|
582
|
+
form.append('file', fileStream);
|
|
583
|
+
return this.client.post('/vouchers/importCSV', form);
|
|
584
|
+
}
|
|
535
585
|
|
|
536
586
|
}
|
|
537
587
|
|
|
@@ -847,6 +897,19 @@
|
|
|
847
897
|
listActivities(customerId, params) {
|
|
848
898
|
return this.client.get(`/customers/${encode(customerId)}/activities`, params);
|
|
849
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* @see https://docs.voucherify.io/reference/import-customers-using-csv
|
|
902
|
+
*/
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
async importCSV(filePath) {
|
|
906
|
+
assert(environment().startsWith('Node'), `Method "client.customers.importCSV(filePath)" is only for Node environment`);
|
|
907
|
+
const fs = (await import('fs')).default;
|
|
908
|
+
const fileStream = fs.createReadStream(filePath);
|
|
909
|
+
const form = new FormData();
|
|
910
|
+
form.append('file', fileStream);
|
|
911
|
+
return this.client.post(`/customers/importCSV`, form);
|
|
912
|
+
}
|
|
850
913
|
|
|
851
914
|
}
|
|
852
915
|
|
|
@@ -1015,6 +1078,32 @@
|
|
|
1015
1078
|
listSkus(productId) {
|
|
1016
1079
|
return this.client.get(`/products/${encode(productId)}/skus`);
|
|
1017
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* @see https://docs.voucherify.io/reference/import-skus-using-csv
|
|
1083
|
+
*/
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
async importSkusCSV(filePath) {
|
|
1087
|
+
assert(environment().startsWith('Node'), `Method "client.products.importSkusCSV(filePath)" is only for Node environment`);
|
|
1088
|
+
const fs = (await import('fs')).default;
|
|
1089
|
+
const fileStream = fs.createReadStream(filePath);
|
|
1090
|
+
const form = new FormData();
|
|
1091
|
+
form.append('file', fileStream);
|
|
1092
|
+
return this.client.post(`/skus/importCSV`, form);
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* @see https://docs.voucherify.io/reference/import-products-using-csv
|
|
1096
|
+
*/
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
async importCSV(filePath) {
|
|
1100
|
+
assert(environment().startsWith('Node'), `Method "client.products.importCSV(filePath)" is only for Node environment`);
|
|
1101
|
+
const fs = (await import('fs')).default;
|
|
1102
|
+
const fileStream = fs.createReadStream(filePath);
|
|
1103
|
+
const form = new FormData();
|
|
1104
|
+
form.append('file', fileStream);
|
|
1105
|
+
return this.client.post(`/products/importCSV`, form);
|
|
1106
|
+
}
|
|
1018
1107
|
|
|
1019
1108
|
}
|
|
1020
1109
|
|
|
@@ -1431,6 +1520,54 @@
|
|
|
1431
1520
|
|
|
1432
1521
|
}
|
|
1433
1522
|
|
|
1523
|
+
class Categories {
|
|
1524
|
+
constructor(client) {
|
|
1525
|
+
this.client = void 0;
|
|
1526
|
+
this.client = client;
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* @see https://docs.voucherify.io/reference/list-categories
|
|
1530
|
+
*/
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
list() {
|
|
1534
|
+
return this.client.get('/categories');
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
* @see https://docs.voucherify.io/reference/create-category
|
|
1538
|
+
*/
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
create(createCategory) {
|
|
1542
|
+
return this.client.post('/categories', createCategory);
|
|
1543
|
+
}
|
|
1544
|
+
/**
|
|
1545
|
+
* @see https://docs.voucherify.io/reference/get-category
|
|
1546
|
+
*/
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
get(categoryId) {
|
|
1550
|
+
return this.client.get(`/categories/${encode(categoryId)}`);
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* @see https://docs.voucherify.io/reference/delete-category
|
|
1554
|
+
*/
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
delete(categoryId) {
|
|
1558
|
+
return this.client.delete(`/categories/${encode(categoryId)}`);
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* @see https://docs.voucherify.io/reference/update-category
|
|
1562
|
+
*/
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
update(categoryId, updateCategory) {
|
|
1566
|
+
return this.client.put(`/categories/${encode(categoryId)}`, updateCategory);
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1434
1571
|
// apiLimitsHandler: ApiLimitsHandler
|
|
1435
1572
|
// campaigns: Campaigns
|
|
1436
1573
|
// consents: Consents
|
|
@@ -1451,7 +1588,7 @@
|
|
|
1451
1588
|
// }
|
|
1452
1589
|
|
|
1453
1590
|
function VoucherifyServerSide(options) {
|
|
1454
|
-
var _options$apiUrl, _options$exposeErrorC;
|
|
1591
|
+
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
1455
1592
|
|
|
1456
1593
|
assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
|
|
1457
1594
|
assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
|
|
@@ -1461,7 +1598,7 @@
|
|
|
1461
1598
|
let headers = {
|
|
1462
1599
|
'X-App-Id': options.applicationId,
|
|
1463
1600
|
'X-App-Token': options.secretKey,
|
|
1464
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.
|
|
1601
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.3.0"}`,
|
|
1465
1602
|
'Content-Type': 'application/json'
|
|
1466
1603
|
};
|
|
1467
1604
|
|
|
@@ -1487,12 +1624,14 @@
|
|
|
1487
1624
|
basePath: 'v1',
|
|
1488
1625
|
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
1489
1626
|
headers,
|
|
1490
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
|
|
1627
|
+
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
1628
|
+
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
1491
1629
|
});
|
|
1492
1630
|
const asyncActions = new AsyncActions(client);
|
|
1493
1631
|
const balance = new Balance(client);
|
|
1494
1632
|
const vouchers = new Vouchers(client, balance);
|
|
1495
1633
|
const campaigns = new Campaigns(client);
|
|
1634
|
+
const categories = new Categories(client);
|
|
1496
1635
|
const exportsNamespace = new Exports(client);
|
|
1497
1636
|
const events = new Events(client);
|
|
1498
1637
|
const distributions = new Distributions(client, exportsNamespace);
|
|
@@ -1513,6 +1652,7 @@
|
|
|
1513
1652
|
return {
|
|
1514
1653
|
vouchers,
|
|
1515
1654
|
campaigns,
|
|
1655
|
+
categories,
|
|
1516
1656
|
distributions,
|
|
1517
1657
|
validations,
|
|
1518
1658
|
redemptions,
|
|
@@ -1701,7 +1841,7 @@
|
|
|
1701
1841
|
}
|
|
1702
1842
|
|
|
1703
1843
|
function VoucherifyClientSide(options) {
|
|
1704
|
-
var _options$apiUrl, _options$exposeErrorC;
|
|
1844
|
+
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
1705
1845
|
|
|
1706
1846
|
assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
|
|
1707
1847
|
assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
|
|
@@ -1711,7 +1851,7 @@
|
|
|
1711
1851
|
let headers = {
|
|
1712
1852
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
1713
1853
|
'X-Client-Token': options.clientSecretKey,
|
|
1714
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.
|
|
1854
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.3.0"}`
|
|
1715
1855
|
};
|
|
1716
1856
|
|
|
1717
1857
|
if (environment().startsWith('Node')) {
|
|
@@ -1727,7 +1867,8 @@
|
|
|
1727
1867
|
basePath: 'client/v1',
|
|
1728
1868
|
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
1729
1869
|
headers,
|
|
1730
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
|
|
1870
|
+
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
1871
|
+
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
1731
1872
|
});
|
|
1732
1873
|
return new ClientSide(client, options.trackingId);
|
|
1733
1874
|
}
|