@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,5 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import Qs from 'qs';
|
|
3
|
+
import FormData from 'form-data';
|
|
3
4
|
|
|
4
5
|
var DiscountVouchersTypesEnum;
|
|
5
6
|
|
|
@@ -58,7 +59,8 @@ class RequestController {
|
|
|
58
59
|
basePath,
|
|
59
60
|
baseURL,
|
|
60
61
|
headers,
|
|
61
|
-
exposeErrorCause
|
|
62
|
+
exposeErrorCause,
|
|
63
|
+
timeoutMs
|
|
62
64
|
}) {
|
|
63
65
|
this.baseURL = void 0;
|
|
64
66
|
this.basePath = void 0;
|
|
@@ -67,12 +69,14 @@ class RequestController {
|
|
|
67
69
|
this.lastResponseHeaders = void 0;
|
|
68
70
|
this.isLastResponseHeadersSet = void 0;
|
|
69
71
|
this.exposeErrorCause = void 0;
|
|
72
|
+
this.timeoutMs = void 0;
|
|
70
73
|
this.basePath = basePath;
|
|
71
74
|
this.baseURL = baseURL;
|
|
72
75
|
this.headers = headers;
|
|
73
76
|
this.exposeErrorCause = exposeErrorCause;
|
|
74
77
|
this.lastResponseHeaders = {};
|
|
75
78
|
this.isLastResponseHeadersSet = false;
|
|
79
|
+
this.timeoutMs = timeoutMs;
|
|
76
80
|
this.request = axios.create({
|
|
77
81
|
baseURL: `${this.baseURL}/${this.basePath}/`,
|
|
78
82
|
headers: this.headers,
|
|
@@ -115,7 +119,8 @@ class RequestController {
|
|
|
115
119
|
params,
|
|
116
120
|
paramsSerializer: function (params) {
|
|
117
121
|
return Qs.stringify(params);
|
|
118
|
-
}
|
|
122
|
+
},
|
|
123
|
+
timeout: this.timeoutMs
|
|
119
124
|
});
|
|
120
125
|
this.setLastResponseHeaders(response.headers);
|
|
121
126
|
return response.data;
|
|
@@ -127,7 +132,8 @@ class RequestController {
|
|
|
127
132
|
paramsSerializer: function (params) {
|
|
128
133
|
return Qs.stringify(params);
|
|
129
134
|
},
|
|
130
|
-
headers
|
|
135
|
+
headers,
|
|
136
|
+
timeout: this.timeoutMs
|
|
131
137
|
});
|
|
132
138
|
this.setLastResponseHeaders(response.headers);
|
|
133
139
|
return response.data;
|
|
@@ -135,7 +141,8 @@ class RequestController {
|
|
|
135
141
|
|
|
136
142
|
async put(path, body, params) {
|
|
137
143
|
const response = await this.request.put(path, body, {
|
|
138
|
-
params
|
|
144
|
+
params,
|
|
145
|
+
timeout: this.timeoutMs
|
|
139
146
|
});
|
|
140
147
|
this.setLastResponseHeaders(response.headers);
|
|
141
148
|
return response.data;
|
|
@@ -143,7 +150,8 @@ class RequestController {
|
|
|
143
150
|
|
|
144
151
|
async delete(path, params) {
|
|
145
152
|
const response = await this.request.delete(path, {
|
|
146
|
-
params
|
|
153
|
+
params,
|
|
154
|
+
timeout: this.timeoutMs
|
|
147
155
|
});
|
|
148
156
|
this.setLastResponseHeaders(response.headers);
|
|
149
157
|
return response.data;
|
|
@@ -304,6 +312,35 @@ class Campaigns {
|
|
|
304
312
|
list(params = {}) {
|
|
305
313
|
return this.client.get('/campaigns', params);
|
|
306
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
async importVouchersCSV(campaignId, filePath) {
|
|
321
|
+
assert(environment().startsWith('Node'), `Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment`);
|
|
322
|
+
const fs = (await import('fs')).default;
|
|
323
|
+
const fileStream = fs.createReadStream(filePath);
|
|
324
|
+
const form = new FormData();
|
|
325
|
+
form.append('file', fileStream);
|
|
326
|
+
return this.client.post(`/campaigns/${campaignId}/importCSV`, form);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* @see https://docs.voucherify.io/reference/enable-campaign
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
enable(campaignId) {
|
|
334
|
+
return this.client.post(`/campaigns/${encode(campaignId)}/enable`, {});
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @see https://docs.voucherify.io/reference/disable-campaign
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
disable(campaignId) {
|
|
342
|
+
return this.client.post(`/campaigns/${encode(campaignId)}/disable`, {});
|
|
343
|
+
}
|
|
307
344
|
|
|
308
345
|
}
|
|
309
346
|
|
|
@@ -528,6 +565,19 @@ class Vouchers {
|
|
|
528
565
|
releaseValidationSession(code, sessionKey) {
|
|
529
566
|
return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
|
|
530
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* @see https://docs.voucherify.io/reference/import-vouchers-using-csv
|
|
570
|
+
*/
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
async importCSV(filePath) {
|
|
574
|
+
assert(environment().startsWith('Node'), `Method "client.vouchers.importCSV(filePath)" is only for Node environment`);
|
|
575
|
+
const fs = (await import('fs')).default;
|
|
576
|
+
const fileStream = fs.createReadStream(filePath);
|
|
577
|
+
const form = new FormData();
|
|
578
|
+
form.append('file', fileStream);
|
|
579
|
+
return this.client.post('/vouchers/importCSV', form);
|
|
580
|
+
}
|
|
531
581
|
|
|
532
582
|
}
|
|
533
583
|
|
|
@@ -843,6 +893,19 @@ class Customers {
|
|
|
843
893
|
listActivities(customerId, params) {
|
|
844
894
|
return this.client.get(`/customers/${encode(customerId)}/activities`, params);
|
|
845
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* @see https://docs.voucherify.io/reference/import-customers-using-csv
|
|
898
|
+
*/
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
async importCSV(filePath) {
|
|
902
|
+
assert(environment().startsWith('Node'), `Method "client.customers.importCSV(filePath)" is only for Node environment`);
|
|
903
|
+
const fs = (await import('fs')).default;
|
|
904
|
+
const fileStream = fs.createReadStream(filePath);
|
|
905
|
+
const form = new FormData();
|
|
906
|
+
form.append('file', fileStream);
|
|
907
|
+
return this.client.post(`/customers/importCSV`, form);
|
|
908
|
+
}
|
|
846
909
|
|
|
847
910
|
}
|
|
848
911
|
|
|
@@ -1011,6 +1074,32 @@ class Products {
|
|
|
1011
1074
|
listSkus(productId) {
|
|
1012
1075
|
return this.client.get(`/products/${encode(productId)}/skus`);
|
|
1013
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* @see https://docs.voucherify.io/reference/import-skus-using-csv
|
|
1079
|
+
*/
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
async importSkusCSV(filePath) {
|
|
1083
|
+
assert(environment().startsWith('Node'), `Method "client.products.importSkusCSV(filePath)" is only for Node environment`);
|
|
1084
|
+
const fs = (await import('fs')).default;
|
|
1085
|
+
const fileStream = fs.createReadStream(filePath);
|
|
1086
|
+
const form = new FormData();
|
|
1087
|
+
form.append('file', fileStream);
|
|
1088
|
+
return this.client.post(`/skus/importCSV`, form);
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* @see https://docs.voucherify.io/reference/import-products-using-csv
|
|
1092
|
+
*/
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
async importCSV(filePath) {
|
|
1096
|
+
assert(environment().startsWith('Node'), `Method "client.products.importCSV(filePath)" is only for Node environment`);
|
|
1097
|
+
const fs = (await import('fs')).default;
|
|
1098
|
+
const fileStream = fs.createReadStream(filePath);
|
|
1099
|
+
const form = new FormData();
|
|
1100
|
+
form.append('file', fileStream);
|
|
1101
|
+
return this.client.post(`/products/importCSV`, form);
|
|
1102
|
+
}
|
|
1014
1103
|
|
|
1015
1104
|
}
|
|
1016
1105
|
|
|
@@ -1427,6 +1516,54 @@ class MetadataSchemas {
|
|
|
1427
1516
|
|
|
1428
1517
|
}
|
|
1429
1518
|
|
|
1519
|
+
class Categories {
|
|
1520
|
+
constructor(client) {
|
|
1521
|
+
this.client = void 0;
|
|
1522
|
+
this.client = client;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* @see https://docs.voucherify.io/reference/list-categories
|
|
1526
|
+
*/
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
list() {
|
|
1530
|
+
return this.client.get('/categories');
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* @see https://docs.voucherify.io/reference/create-category
|
|
1534
|
+
*/
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
create(createCategory) {
|
|
1538
|
+
return this.client.post('/categories', createCategory);
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* @see https://docs.voucherify.io/reference/get-category
|
|
1542
|
+
*/
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
get(categoryId) {
|
|
1546
|
+
return this.client.get(`/categories/${encode(categoryId)}`);
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* @see https://docs.voucherify.io/reference/delete-category
|
|
1550
|
+
*/
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
delete(categoryId) {
|
|
1554
|
+
return this.client.delete(`/categories/${encode(categoryId)}`);
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* @see https://docs.voucherify.io/reference/update-category
|
|
1558
|
+
*/
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
update(categoryId, updateCategory) {
|
|
1562
|
+
return this.client.put(`/categories/${encode(categoryId)}`, updateCategory);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1430
1567
|
// apiLimitsHandler: ApiLimitsHandler
|
|
1431
1568
|
// campaigns: Campaigns
|
|
1432
1569
|
// consents: Consents
|
|
@@ -1447,7 +1584,7 @@ class MetadataSchemas {
|
|
|
1447
1584
|
// }
|
|
1448
1585
|
|
|
1449
1586
|
function VoucherifyServerSide(options) {
|
|
1450
|
-
var _options$apiUrl, _options$exposeErrorC;
|
|
1587
|
+
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
1451
1588
|
|
|
1452
1589
|
assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
|
|
1453
1590
|
assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
|
|
@@ -1457,7 +1594,7 @@ function VoucherifyServerSide(options) {
|
|
|
1457
1594
|
let headers = {
|
|
1458
1595
|
'X-App-Id': options.applicationId,
|
|
1459
1596
|
'X-App-Token': options.secretKey,
|
|
1460
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.
|
|
1597
|
+
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.3.0"}`,
|
|
1461
1598
|
'Content-Type': 'application/json'
|
|
1462
1599
|
};
|
|
1463
1600
|
|
|
@@ -1483,12 +1620,14 @@ function VoucherifyServerSide(options) {
|
|
|
1483
1620
|
basePath: 'v1',
|
|
1484
1621
|
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
1485
1622
|
headers,
|
|
1486
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
|
|
1623
|
+
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
1624
|
+
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
1487
1625
|
});
|
|
1488
1626
|
const asyncActions = new AsyncActions(client);
|
|
1489
1627
|
const balance = new Balance(client);
|
|
1490
1628
|
const vouchers = new Vouchers(client, balance);
|
|
1491
1629
|
const campaigns = new Campaigns(client);
|
|
1630
|
+
const categories = new Categories(client);
|
|
1492
1631
|
const exportsNamespace = new Exports(client);
|
|
1493
1632
|
const events = new Events(client);
|
|
1494
1633
|
const distributions = new Distributions(client, exportsNamespace);
|
|
@@ -1509,6 +1648,7 @@ function VoucherifyServerSide(options) {
|
|
|
1509
1648
|
return {
|
|
1510
1649
|
vouchers,
|
|
1511
1650
|
campaigns,
|
|
1651
|
+
categories,
|
|
1512
1652
|
distributions,
|
|
1513
1653
|
validations,
|
|
1514
1654
|
redemptions,
|
|
@@ -1697,7 +1837,7 @@ class ClientSide {
|
|
|
1697
1837
|
}
|
|
1698
1838
|
|
|
1699
1839
|
function VoucherifyClientSide(options) {
|
|
1700
|
-
var _options$apiUrl, _options$exposeErrorC;
|
|
1840
|
+
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
1701
1841
|
|
|
1702
1842
|
assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
|
|
1703
1843
|
assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
|
|
@@ -1707,7 +1847,7 @@ function VoucherifyClientSide(options) {
|
|
|
1707
1847
|
let headers = {
|
|
1708
1848
|
'X-Client-Application-Id': options.clientApplicationId,
|
|
1709
1849
|
'X-Client-Token': options.clientSecretKey,
|
|
1710
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.
|
|
1850
|
+
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.3.0"}`
|
|
1711
1851
|
};
|
|
1712
1852
|
|
|
1713
1853
|
if (environment().startsWith('Node')) {
|
|
@@ -1723,7 +1863,8 @@ function VoucherifyClientSide(options) {
|
|
|
1723
1863
|
basePath: 'client/v1',
|
|
1724
1864
|
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
1725
1865
|
headers,
|
|
1726
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
|
|
1866
|
+
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
1867
|
+
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
1727
1868
|
});
|
|
1728
1869
|
return new ClientSide(client, options.trackingId);
|
|
1729
1870
|
}
|