@voucherify/sdk 2.9.2 → 2.9.3
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/dist/voucherifysdk.cjs +2 -0
- package/dist/voucherifysdk.cjs.map +1 -0
- package/dist/voucherifysdk.d.mts +5252 -0
- package/dist/voucherifysdk.d.ts +5252 -0
- package/dist/voucherifysdk.esm.js +2 -2261
- package/dist/voucherifysdk.esm.js.map +1 -1
- package/package.json +12 -8
- package/CHANGELOG.md +0 -663
- package/dist/ApiLimitsHandler.d.ts +0 -10
- package/dist/AsyncActions.d.ts +0 -15
- package/dist/Balance.d.ts +0 -12
- package/dist/Campaigns.d.ts +0 -58
- package/dist/Categories.d.ts +0 -26
- package/dist/ClientSide.d.ts +0 -53
- package/dist/Consents.d.ts +0 -10
- package/dist/Customers.d.ts +0 -72
- package/dist/Distributions.d.ts +0 -22
- package/dist/Events.d.ts +0 -10
- package/dist/Exports.d.ts +0 -22
- package/dist/Loyalties.d.ts +0 -159
- package/dist/MetadataSchemas.d.ts +0 -14
- package/dist/Orders.d.ts +0 -27
- package/dist/ProductCollections.d.ts +0 -26
- package/dist/Products.d.ts +0 -63
- package/dist/PromotionTiers.d.ts +0 -34
- package/dist/Promotions.d.ts +0 -18
- package/dist/PromotionsStacks.d.ts +0 -30
- package/dist/Qualifications.d.ts +0 -10
- package/dist/Redemptions.d.ts +0 -35
- package/dist/RequestController.d.ts +0 -29
- package/dist/Rewards.d.ts +0 -43
- package/dist/Segments.d.ts +0 -22
- package/dist/ValidationRules.d.ts +0 -43
- package/dist/Validations.d.ts +0 -17
- package/dist/VoucherifyClientSide.d.ts +0 -86
- package/dist/VoucherifyError.d.ts +0 -20
- package/dist/VoucherifyServerSide.d.ts +0 -131
- package/dist/Vouchers.d.ts +0 -78
- package/dist/helpers.d.ts +0 -18
- package/dist/index.d.ts +0 -25
- package/dist/types/ApplicableTo.d.ts +0 -30
- package/dist/types/AsyncActions.d.ts +0 -21
- package/dist/types/Balance.d.ts +0 -16
- package/dist/types/Campaigns.d.ts +0 -120
- package/dist/types/Categories.d.ts +0 -38
- package/dist/types/ClientSide.d.ts +0 -134
- package/dist/types/Consents.d.ts +0 -33
- package/dist/types/Customers.d.ts +0 -361
- package/dist/types/DiscountVoucher.d.ts +0 -93
- package/dist/types/Distributions.d.ts +0 -144
- package/dist/types/Events.d.ts +0 -17
- package/dist/types/Exports.d.ts +0 -149
- package/dist/types/Gift.d.ts +0 -3
- package/dist/types/Loyalties.d.ts +0 -1057
- package/dist/types/MetadataSchemas.d.ts +0 -33
- package/dist/types/Orders.d.ts +0 -195
- package/dist/types/ProductCollections.d.ts +0 -96
- package/dist/types/Products.d.ts +0 -106
- package/dist/types/PromotionTiers.d.ts +0 -127
- package/dist/types/Promotions.d.ts +0 -108
- package/dist/types/PromotionsStacks.d.ts +0 -71
- package/dist/types/Qualifications.d.ts +0 -86
- package/dist/types/Redemptions.d.ts +0 -205
- package/dist/types/Rewards.d.ts +0 -219
- package/dist/types/Segments.d.ts +0 -32
- package/dist/types/Stackable.d.ts +0 -101
- package/dist/types/UtilityTypes.d.ts +0 -3
- package/dist/types/ValidateSession.d.ts +0 -17
- package/dist/types/ValidationError.d.ts +0 -7
- package/dist/types/ValidationRules.d.ts +0 -93
- package/dist/types/Validations.d.ts +0 -98
- package/dist/types/Vouchers.d.ts +0 -364
- package/dist/types/index.d.ts +0 -25
- package/dist/voucherifysdk.umd.development.js +0 -2270
- package/dist/voucherifysdk.umd.development.js.map +0 -1
- package/dist/voucherifysdk.umd.production.min.js +0 -2
- package/dist/voucherifysdk.umd.production.min.js.map +0 -1
|
@@ -1,2261 +1,2 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
import FormData from 'form-data';
|
|
4
|
-
|
|
5
|
-
var DiscountVouchersTypesEnum;
|
|
6
|
-
|
|
7
|
-
(function (DiscountVouchersTypesEnum) {
|
|
8
|
-
DiscountVouchersTypesEnum["AMOUNT"] = "AMOUNT";
|
|
9
|
-
DiscountVouchersTypesEnum["PERCENT"] = "PERCENT";
|
|
10
|
-
DiscountVouchersTypesEnum["UNIT"] = "UNIT";
|
|
11
|
-
DiscountVouchersTypesEnum["FIXED"] = "FIXED";
|
|
12
|
-
})(DiscountVouchersTypesEnum || (DiscountVouchersTypesEnum = {}));
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
class VoucherifyError extends Error {
|
|
18
|
-
constructor(statusCode, body, axiosError) {
|
|
19
|
-
var _body, _body2;
|
|
20
|
-
|
|
21
|
-
body = (_body = body) != null ? _body : {};
|
|
22
|
-
const message = ((_body2 = body) == null ? void 0 : _body2.message) || generateMessage(body, statusCode);
|
|
23
|
-
super(message);
|
|
24
|
-
this.code = void 0;
|
|
25
|
-
this.key = void 0;
|
|
26
|
-
this.details = void 0;
|
|
27
|
-
this.request_id = void 0;
|
|
28
|
-
this.resource_id = void 0;
|
|
29
|
-
this.resource_type = void 0;
|
|
30
|
-
this.related_object_ids = void 0;
|
|
31
|
-
this.related_object_type = void 0;
|
|
32
|
-
this.related_object_total = void 0;
|
|
33
|
-
this.error = void 0;
|
|
34
|
-
this.cause = void 0;
|
|
35
|
-
this.code = body.code;
|
|
36
|
-
this.key = body.key;
|
|
37
|
-
this.details = body.details;
|
|
38
|
-
this.request_id = body.request_id;
|
|
39
|
-
this.resource_id = body.resource_id;
|
|
40
|
-
this.resource_type = body.resource_type;
|
|
41
|
-
this.related_object_ids = body.related_object_ids;
|
|
42
|
-
this.related_object_type = body.related_object_type;
|
|
43
|
-
this.related_object_total = body.related_object_total;
|
|
44
|
-
this.error = body.error;
|
|
45
|
-
this.cause = axiosError;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function generateMessage(body, statusCode) {
|
|
51
|
-
body = typeof body === 'string' ? body : JSON.stringify(body, null, 2);
|
|
52
|
-
return `Unexpected status code: ${statusCode} - Details: ${body}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
class RequestController {
|
|
60
|
-
constructor({
|
|
61
|
-
basePath,
|
|
62
|
-
baseURL,
|
|
63
|
-
headers,
|
|
64
|
-
exposeErrorCause,
|
|
65
|
-
timeoutMs
|
|
66
|
-
}) {
|
|
67
|
-
this.baseURL = void 0;
|
|
68
|
-
this.basePath = void 0;
|
|
69
|
-
this.headers = void 0;
|
|
70
|
-
this.request = void 0;
|
|
71
|
-
this.lastResponseHeaders = void 0;
|
|
72
|
-
this.isLastResponseHeadersSet = void 0;
|
|
73
|
-
this.exposeErrorCause = void 0;
|
|
74
|
-
this.timeoutMs = void 0;
|
|
75
|
-
this.basePath = basePath;
|
|
76
|
-
this.baseURL = baseURL;
|
|
77
|
-
this.headers = headers;
|
|
78
|
-
this.exposeErrorCause = exposeErrorCause;
|
|
79
|
-
this.lastResponseHeaders = {};
|
|
80
|
-
this.isLastResponseHeadersSet = false;
|
|
81
|
-
this.timeoutMs = timeoutMs;
|
|
82
|
-
this.request = axios.create({
|
|
83
|
-
baseURL: `${this.baseURL}/${this.basePath}/`,
|
|
84
|
-
allowAbsoluteUrls: false,
|
|
85
|
-
headers: this.headers,
|
|
86
|
-
responseType: 'json'
|
|
87
|
-
});
|
|
88
|
-
this.request.interceptors.response.use(void 0, error => {
|
|
89
|
-
var _error$response;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Handle any HTTP response error (status code outside of 2xx) as a VoucherifyError
|
|
93
|
-
*/
|
|
94
|
-
if (error != null && (_error$response = error.response) != null && _error$response.status) {
|
|
95
|
-
return Promise.reject(new VoucherifyError(error.response.status, error.response.data, this.exposeErrorCause === true ? error : undefined));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return Promise.reject(error);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
isLastReponseHeadersSet() {
|
|
103
|
-
return this.isLastResponseHeadersSet;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getLastResponseHeaders() {
|
|
107
|
-
return this.lastResponseHeaders;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setLastResponseHeaders(headers) {
|
|
111
|
-
const result = {};
|
|
112
|
-
|
|
113
|
-
for (const key in headers) {
|
|
114
|
-
result[key] = String(headers[key]);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.lastResponseHeaders = result;
|
|
118
|
-
this.isLastResponseHeadersSet = true;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
setBaseUrl(baseURL) {
|
|
122
|
-
this.baseURL = baseURL;
|
|
123
|
-
this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async get(path, params) {
|
|
127
|
-
const response = await this.request.get(path, {
|
|
128
|
-
params,
|
|
129
|
-
paramsSerializer: function (params) {
|
|
130
|
-
return Qs.stringify(params);
|
|
131
|
-
},
|
|
132
|
-
timeout: this.timeoutMs
|
|
133
|
-
});
|
|
134
|
-
this.setLastResponseHeaders(response.headers);
|
|
135
|
-
return response.data;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async post(path, body, params, headers) {
|
|
139
|
-
const response = await this.request.post(path, body, {
|
|
140
|
-
params,
|
|
141
|
-
paramsSerializer: function (params) {
|
|
142
|
-
return Qs.stringify(params);
|
|
143
|
-
},
|
|
144
|
-
headers,
|
|
145
|
-
timeout: this.timeoutMs
|
|
146
|
-
});
|
|
147
|
-
this.setLastResponseHeaders(response.headers);
|
|
148
|
-
return response.data;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async put(path, body, params) {
|
|
152
|
-
const response = await this.request.put(path, body, {
|
|
153
|
-
params,
|
|
154
|
-
timeout: this.timeoutMs
|
|
155
|
-
});
|
|
156
|
-
this.setLastResponseHeaders(response.headers);
|
|
157
|
-
return response.data;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async delete(path, params) {
|
|
161
|
-
const response = await this.request.delete(path, {
|
|
162
|
-
params,
|
|
163
|
-
timeout: this.timeoutMs
|
|
164
|
-
});
|
|
165
|
-
this.setLastResponseHeaders(response.headers);
|
|
166
|
-
return response.data;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function encode(value = '') {
|
|
172
|
-
return encodeURIComponent(value);
|
|
173
|
-
}
|
|
174
|
-
function isString(value) {
|
|
175
|
-
return typeof value === 'string';
|
|
176
|
-
}
|
|
177
|
-
function isOptionalString(value) {
|
|
178
|
-
return value == null || isString(value);
|
|
179
|
-
}
|
|
180
|
-
function isObject(value) {
|
|
181
|
-
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
182
|
-
}
|
|
183
|
-
function isOptionalObject(value) {
|
|
184
|
-
return value == null || isObject(value);
|
|
185
|
-
}
|
|
186
|
-
function environment() {
|
|
187
|
-
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
|
|
188
|
-
return 'Browser'; // eslint-disable-next-line no-restricted-globals
|
|
189
|
-
} else if (typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope') {
|
|
190
|
-
return 'WebWorker';
|
|
191
|
-
} else if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) {
|
|
192
|
-
return `Node.js-${process.version}`;
|
|
193
|
-
} else if (typeof window !== 'undefined' && window.name === 'nodejs' || navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom')) {
|
|
194
|
-
return 'JsDom';
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return 'Unknown';
|
|
198
|
-
}
|
|
199
|
-
function assert(condition, message) {
|
|
200
|
-
if (condition) return;
|
|
201
|
-
throw new Error(message);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Return an object containing all properties of `obj` excluding the ones in `keys` array
|
|
205
|
-
* e.g:
|
|
206
|
-
* ```javascript
|
|
207
|
-
* omit({ a: 1, b: 2, c: 3, d: 4 }, ['b', 'd']) // output: { a: 1, c: 3 }
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
function omit(obj, keys) {
|
|
212
|
-
return Object.fromEntries(Object.entries(obj).filter(([propertyKey]) => {
|
|
213
|
-
return !keys.includes(propertyKey);
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
class AsyncActions {
|
|
218
|
-
constructor(client) {
|
|
219
|
-
this.client = void 0;
|
|
220
|
-
this.client = client;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @see https://docs.voucherify.io/reference/get-async-actions-1
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
get(asyncActionId) {
|
|
228
|
-
return this.client.get(`/async-actions/${encode(asyncActionId)}`);
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* @see https://docs.voucherify.io/reference/list-async-actions
|
|
232
|
-
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
list(params) {
|
|
236
|
-
return this.client.get('/async-actions', params);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
class CampaignsQualifications {
|
|
242
|
-
constructor(client) {
|
|
243
|
-
this.client = void 0;
|
|
244
|
-
this.client = client;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
examine(body = {}, params) {
|
|
248
|
-
return this.client.post('/campaigns/qualification', body, params);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
class Campaigns {
|
|
254
|
-
constructor(client) {
|
|
255
|
-
this.client = void 0;
|
|
256
|
-
this.qualifications = void 0;
|
|
257
|
-
this.client = client;
|
|
258
|
-
this.qualifications = new CampaignsQualifications(this.client);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* @see https://docs.voucherify.io/reference/create-campaign
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
create(campaign) {
|
|
266
|
-
return this.client.post('/campaigns', campaign);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* @see https://docs.voucherify.io/reference/update-campaign
|
|
270
|
-
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
update(nameOrId, campaign) {
|
|
274
|
-
return this.client.put(`/campaigns/${encode(nameOrId)}`, campaign);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* @see https://docs.voucherify.io/reference/get-campaign
|
|
278
|
-
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
get(name) {
|
|
282
|
-
return this.client.get(`/campaigns/${encode(name)}`);
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* @see https://docs.voucherify.io/reference/delete-campaign
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
delete(name, params = {}) {
|
|
290
|
-
return this.client.delete(`/campaigns/${encode(name)}`, params);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* @see https://docs.voucherify.io/reference/add-voucher-to-campaign
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
addVoucher(name, body = {}, params = {}) {
|
|
298
|
-
return this.client.post(`/campaigns/${encode(name)}/vouchers`, body, params);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* @see https://docs.voucherify.io/reference/add-voucher-with-certain-code-to-campaign
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
addCertainVoucher(name, code, body = {}) {
|
|
306
|
-
return this.client.post(`/campaigns/${encode(name)}/vouchers/${encode(code)}`, body);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* @see https://docs.voucherify.io/reference/import-vouchers
|
|
310
|
-
*/
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
importVouchers(campaignName, vouchers) {
|
|
314
|
-
return this.client.post(`/campaigns/${encode(campaignName)}/import`, vouchers);
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* @see https://docs.voucherify.io/reference/list-campaigns
|
|
318
|
-
*/
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
list(params = {}) {
|
|
322
|
-
return this.client.get('/campaigns', params);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
async importVouchersCSV(campaignId, filePath) {
|
|
330
|
-
assert(environment().startsWith('Node'), `Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment`);
|
|
331
|
-
const fs = (await import('fs')).default;
|
|
332
|
-
const fileStream = fs.createReadStream(filePath);
|
|
333
|
-
const form = new FormData();
|
|
334
|
-
form.append('file', fileStream);
|
|
335
|
-
const headers = {
|
|
336
|
-
'Content-Type': 'multipart/form-data'
|
|
337
|
-
};
|
|
338
|
-
return this.client.post(`/campaigns/${campaignId}/importCSV`, form, undefined, headers);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* @see https://docs.voucherify.io/reference/enable-campaign
|
|
342
|
-
*/
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
enable(campaignId) {
|
|
346
|
-
return this.client.post(`/campaigns/${encode(campaignId)}/enable`, {});
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* @see https://docs.voucherify.io/reference/disable-campaign
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
disable(campaignId) {
|
|
354
|
-
return this.client.post(`/campaigns/${encode(campaignId)}/disable`, {});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
class DistributionsPublications {
|
|
360
|
-
constructor(client) {
|
|
361
|
-
this.client = void 0;
|
|
362
|
-
this.client = client;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* @see https://docs.voucherify.io/reference/list-publications
|
|
366
|
-
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
list(params = {}) {
|
|
370
|
-
return this.client.get('/publications', params);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* @see https://docs.voucherify.io/reference/create-publication
|
|
374
|
-
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
create(params) {
|
|
378
|
-
return this.client.post('/publications', params);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
class Distributions {
|
|
384
|
-
constructor(client, exports) {
|
|
385
|
-
this.client = void 0;
|
|
386
|
-
this.exports = void 0;
|
|
387
|
-
this.publications = void 0;
|
|
388
|
-
this.client = client;
|
|
389
|
-
this.exports = exports;
|
|
390
|
-
this.publications = new DistributionsPublications(this.client);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
class Exports {
|
|
396
|
-
constructor(client) {
|
|
397
|
-
this.client = void 0;
|
|
398
|
-
this.client = client;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* @see https://docs.voucherify.io/reference/create-export
|
|
402
|
-
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
create(exportResource) {
|
|
406
|
-
return this.client.post('/exports', exportResource);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* @see https://docs.voucherify.io/reference/list-exports
|
|
410
|
-
*/
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
list(query = {}) {
|
|
414
|
-
return this.client.get('/exports', query);
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* @see https://docs.voucherify.io/reference/get-export
|
|
418
|
-
*/
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
get(exportResourceId) {
|
|
422
|
-
return this.client.get(`/exports/${encode(exportResourceId)}`);
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* @see https://docs.voucherify.io/reference/delete-export
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
delete(exportResourceId) {
|
|
430
|
-
return this.client.delete(`/exports/${encode(exportResourceId)}`);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
class Events {
|
|
436
|
-
constructor(client) {
|
|
437
|
-
this.client = void 0;
|
|
438
|
-
this.client = client;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* @see https://docs.voucherify.io/reference/track-custom-event-client-side
|
|
442
|
-
*/
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
create(eventName, params) {
|
|
446
|
-
params = { ...params,
|
|
447
|
-
event: eventName
|
|
448
|
-
};
|
|
449
|
-
return this.client.post('/events', params);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
class Balance {
|
|
455
|
-
constructor(client) {
|
|
456
|
-
this.client = void 0;
|
|
457
|
-
this.client = client;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Add Gift Voucher Balance
|
|
461
|
-
* This method gives a possibility to add balance to an existing gift voucher.
|
|
462
|
-
* @see https://docs.voucherify.io/reference/add-gift-voucher-balance
|
|
463
|
-
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
create(code, params) {
|
|
467
|
-
return this.client.post(`/vouchers/${encode(code)}/balance`, params);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
class VouchersQualification {
|
|
473
|
-
constructor(client) {
|
|
474
|
-
this.client = void 0;
|
|
475
|
-
this.client = client;
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* The method can be used for sending a request to display all vouchers qualified to the given customer and context (e.g., order, loyalty reward). A checking logic won't run among coupons from bulk unique codes campaigns. For campaigns with multiple unique codes, you should run a dedicated function for searching for qualified campaigns.
|
|
479
|
-
* As a sample use case, you can imagine a requirement of displaying below cart the coupons eligible to a customer. The customer can take and apply the proposed voucher.
|
|
480
|
-
*
|
|
481
|
-
* @see https://docs.voucherify.io/reference/push-qualification-request
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
examine(body, params = {}) {
|
|
486
|
-
return this.client.post('/vouchers/qualification', body, params);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
class Vouchers {
|
|
492
|
-
constructor(client, balance) {
|
|
493
|
-
this.client = void 0;
|
|
494
|
-
this.balance = void 0;
|
|
495
|
-
this.qualifications = void 0;
|
|
496
|
-
this.client = client;
|
|
497
|
-
this.balance = balance;
|
|
498
|
-
this.qualifications = new VouchersQualification(this.client);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* @see https://docs.voucherify.io/reference/create-voucher
|
|
502
|
-
*/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
create(voucher) {
|
|
506
|
-
return this.client.post(`/vouchers/${encode(voucher.code)}`, voucher);
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* @see https://docs.voucherify.io/reference/vouchers-get
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
get(code) {
|
|
514
|
-
return this.client.get(`/vouchers/${encode(code)}`);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* @see https://docs.voucherify.io/reference/update-voucher
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
update(voucher) {
|
|
522
|
-
return this.client.put(`/vouchers/${encode(voucher.code)}`, voucher);
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* @see https://docs.voucherify.io/reference/delete-voucher
|
|
526
|
-
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
delete(code, params = {}) {
|
|
530
|
-
return this.client.delete(`/vouchers/${encode(code)}`, params);
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* @see https://docs.voucherify.io/reference/list-vouchers
|
|
534
|
-
*/
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
list(params = {}) {
|
|
538
|
-
return this.client.get('/vouchers', params);
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* @see https://docs.voucherify.io/reference/enable-voucher
|
|
542
|
-
*/
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
enable(code) {
|
|
546
|
-
return this.client.post(`/vouchers/${encode(code)}/enable`, {});
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* @see https://docs.voucherify.io/reference/disable-voucher
|
|
550
|
-
*/
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
disable(code) {
|
|
554
|
-
return this.client.post(`/vouchers/${encode(code)}/disable`, {});
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* @see https://docs.voucherify.io/reference/import-vouchers-1
|
|
558
|
-
*/
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
import(vouchers) {
|
|
562
|
-
return this.client.post('/vouchers/import', vouchers);
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* @see https://docs.voucherify.io/reference/aaupdate-vouchers-metadata-in-bulk
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
bulkUpdateMetadata(params) {
|
|
570
|
-
return this.client.post('/vouchers/metadata/async', params);
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* @see https://docs.voucherify.io/reference/aa-update-vouchers-in-bulk
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
bulkUpdate(vouchers) {
|
|
578
|
-
return this.client.post('/vouchers/bulk/async', vouchers);
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* @see https://docs.voucherify.io/reference/release-validation-session
|
|
582
|
-
*/
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
releaseValidationSession(code, sessionKey) {
|
|
586
|
-
return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
|
|
587
|
-
}
|
|
588
|
-
/**
|
|
589
|
-
* @see https://docs.voucherify.io/reference/import-vouchers-using-csv
|
|
590
|
-
*/
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
async importCSV(filePath) {
|
|
594
|
-
assert(environment().startsWith('Node'), `Method "client.vouchers.importCSV(filePath)" is only for Node environment`);
|
|
595
|
-
const fs = (await import('fs')).default;
|
|
596
|
-
const fileStream = fs.createReadStream(filePath);
|
|
597
|
-
const form = new FormData();
|
|
598
|
-
form.append('file', fileStream);
|
|
599
|
-
const headers = {
|
|
600
|
-
'Content-Type': 'multipart/form-data'
|
|
601
|
-
};
|
|
602
|
-
return this.client.post('/vouchers/importCSV', form, undefined, headers);
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* @see https://docs.voucherify.io/reference/list-voucher-transactions
|
|
606
|
-
*/
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
listTransactions(code, params) {
|
|
610
|
-
return this.client.get(`/vouchers/${encode(code)}/transactions`, params);
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* @see https://docs.voucherify.io/reference/export-voucher-transactions
|
|
614
|
-
*/
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
exportTransactions(code, body) {
|
|
618
|
-
return this.client.post(`/vouchers/${encode(code)}/transactions/export`, body);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
class Validations {
|
|
624
|
-
constructor(client, promotions) {
|
|
625
|
-
this.client = void 0;
|
|
626
|
-
this.promotions = void 0;
|
|
627
|
-
this.client = client;
|
|
628
|
-
this.promotions = promotions;
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* @see https://docs.voucherify.io/reference/validate-voucher
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
validateVoucher(code, params = {}) {
|
|
636
|
-
return this.client.post(`/vouchers/${encode(code)}/validate`, params);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
validate(code, context = {}) {
|
|
640
|
-
if (isObject(code)) {
|
|
641
|
-
return this.promotions.validate(code);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return this.validateVoucher(code, context);
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* @see https://docs.voucherify.io/reference/validate-stacked-discounts-1
|
|
648
|
-
*/
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
validateStackable(params) {
|
|
652
|
-
return this.client.post(`/validations`, params);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
class Redemptions {
|
|
658
|
-
constructor(client) {
|
|
659
|
-
this.client = void 0;
|
|
660
|
-
this.client = client;
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* @see https://docs.voucherify.io/reference/redeem-voucher
|
|
664
|
-
*/
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
redeem(code, body = {}) {
|
|
668
|
-
return this.client.post(`/vouchers/${encode(code)}/redemption`, body);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* @see https://docs.voucherify.io/reference/redeem-stacked-discounts
|
|
672
|
-
*/
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
redeemStackable(params) {
|
|
676
|
-
return this.client.post(`/redemptions`, params);
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* @see https://docs.voucherify.io/reference/get-redemption
|
|
680
|
-
*/
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
get(redemptionId) {
|
|
684
|
-
return this.client.get(`/redemptions/${encode(redemptionId)}`);
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* @see https://docs.voucherify.io/reference/list-redemptions
|
|
688
|
-
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
list(params = {}) {
|
|
692
|
-
return this.client.get('/redemptions', params);
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* @see https://docs.voucherify.io/reference/vouchers-redemptions
|
|
696
|
-
*/
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
getForVoucher(code) {
|
|
700
|
-
return this.client.get(`/vouchers/${encode(code)}/redemption`);
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* @see https://docs.voucherify.io/reference/rollback-redemption
|
|
704
|
-
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
rollback(redemptionId, params) {
|
|
708
|
-
let queryParams = {};
|
|
709
|
-
let payload = {};
|
|
710
|
-
|
|
711
|
-
if (isString(params)) {
|
|
712
|
-
queryParams.reason = params;
|
|
713
|
-
} else if (isObject(params)) {
|
|
714
|
-
const {
|
|
715
|
-
reason,
|
|
716
|
-
tracking_id: trackingId,
|
|
717
|
-
customer
|
|
718
|
-
} = params;
|
|
719
|
-
queryParams = {
|
|
720
|
-
reason: reason ? reason : undefined,
|
|
721
|
-
tracking_id: trackingId ? trackingId : undefined
|
|
722
|
-
};
|
|
723
|
-
payload = {
|
|
724
|
-
customer
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
return this.client.post(`/redemptions/${encode(redemptionId)}/rollback`, payload, queryParams);
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* @see https://docs.voucherify.io/reference/rollback-stackable-redemptions
|
|
732
|
-
* Types of params and queryParams WILL be changed in future - please do not depend on it!
|
|
733
|
-
*/
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
rollbackStackable(parentRedemptionId, params, queryParams) {
|
|
737
|
-
return this.client.post(`/redemptions/${encode(parentRedemptionId)}/rollbacks`, params, queryParams);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
class PromotionTiers {
|
|
743
|
-
constructor(client) {
|
|
744
|
-
this.client = void 0;
|
|
745
|
-
this.client = client;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* @see https://docs.voucherify.io/reference/list-promotion-tiers
|
|
749
|
-
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
listAll(params = {}) {
|
|
753
|
-
return this.client.get('/promotions/tiers', params);
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* @see https://docs.voucherify.io/reference/get-promotions
|
|
757
|
-
*/
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
list(promotionId) {
|
|
761
|
-
return this.client.get(`/promotions/${encode(promotionId)}/tiers`);
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* @see https://docs.voucherify.io/reference/get-promotion-tier
|
|
765
|
-
*/
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
get(tierId) {
|
|
769
|
-
return this.client.get(`/promotions/tiers/${encode(tierId)}`);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* @see https://docs.voucherify.io/reference/add-promotion-tier-to-campaign
|
|
773
|
-
*/
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
create(promotionId, params) {
|
|
777
|
-
return this.client.post(`/promotions/${encode(promotionId)}/tiers`, params);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* @see https://docs.voucherify.io/reference/redeem-promotion
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
redeem(promotionsTierId, params) {
|
|
785
|
-
return this.client.post(`/promotions/tiers/${encode(promotionsTierId)}/redemption`, params);
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* @see https://docs.voucherify.io/reference/update-promotion
|
|
789
|
-
*/
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
update(params) {
|
|
793
|
-
return this.client.put(`/promotions/tiers/${encode(params.id)}`, params);
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* @see https://docs.voucherify.io/reference/delete-promotion
|
|
797
|
-
*/
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
delete(promotionsTierId) {
|
|
801
|
-
return this.client.delete(`/promotions/tiers/${encode(promotionsTierId)}`);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
class Promotions {
|
|
807
|
-
constructor(client, tiers, stack) {
|
|
808
|
-
this.client = void 0;
|
|
809
|
-
this.tiers = void 0;
|
|
810
|
-
this.stack = void 0;
|
|
811
|
-
this.client = client;
|
|
812
|
-
this.tiers = tiers;
|
|
813
|
-
this.stack = stack;
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* @see https://docs.voucherify.io/reference/create-promotion-campaign
|
|
817
|
-
*/
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
create(promotionCampaign) {
|
|
821
|
-
return this.client.post('/campaigns', promotionCampaign);
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* @see https://docs.voucherify.io/reference/validate-promotions-1
|
|
825
|
-
*/
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
validate(body, params) {
|
|
829
|
-
return this.client.post('/promotions/validation', body, params);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
class Customers {
|
|
835
|
-
constructor(client) {
|
|
836
|
-
this.client = void 0;
|
|
837
|
-
this.client = client;
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* @see https://docs.voucherify.io/reference/create-customer
|
|
841
|
-
*/
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
create(customer) {
|
|
845
|
-
return this.client.post('/customers', customer);
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* @see https://docs.voucherify.io/reference/read-customer
|
|
849
|
-
*/
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
get(customerId) {
|
|
853
|
-
return this.client.get(`/customers/${encode(customerId)}`);
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* @see https://docs.voucherify.io/reference/list-customers
|
|
857
|
-
*/
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
list(params) {
|
|
861
|
-
return this.client.get('/customers', params);
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
* Standard list customers API has limitation of available pages to be shown equal to 100. To cover cases when you would like to fetch more, you must use scroll capabilities.
|
|
865
|
-
*
|
|
866
|
-
* ```javascript
|
|
867
|
-
* async function () {
|
|
868
|
-
* for await (const customer of voucherify.customers.scroll(params)) {
|
|
869
|
-
* console.log('Customer', customer)
|
|
870
|
-
* }
|
|
871
|
-
* }
|
|
872
|
-
* ```
|
|
873
|
-
*/
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
async *scroll(params) {
|
|
877
|
-
var _params$starting_afte;
|
|
878
|
-
|
|
879
|
-
let startingAfter = (_params$starting_afte = params.starting_after) != null ? _params$starting_afte : params.order === 'created_at' ? '1970-01-01T00:00:00Z' : '2200-01-01T00:00:00Z';
|
|
880
|
-
let response = await this.client.get('/customers', Object.assign({}, params, {
|
|
881
|
-
starting_after: startingAfter
|
|
882
|
-
}));
|
|
883
|
-
|
|
884
|
-
while (true) {
|
|
885
|
-
if (response.customers.length === 0) break;
|
|
886
|
-
|
|
887
|
-
for (const customer of response.customers) {
|
|
888
|
-
if (params.order === 'created_at') {
|
|
889
|
-
startingAfter = startingAfter > customer.created_at ? startingAfter : customer.created_at;
|
|
890
|
-
} else {
|
|
891
|
-
startingAfter = startingAfter < customer.created_at ? startingAfter : customer.created_at;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
yield customer;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
if (!response.has_more) break;
|
|
898
|
-
response = await this.client.get('/customers', Object.assign({}, params, {
|
|
899
|
-
starting_after: startingAfter
|
|
900
|
-
}));
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* @see https://docs.voucherify.io/reference/update-customer
|
|
905
|
-
*/
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
update(customer) {
|
|
909
|
-
const id = 'id' in customer ? customer.id : customer.source_id;
|
|
910
|
-
const customerWithoutId = omit(customer, ['id']);
|
|
911
|
-
return this.client.put(`/customers/${encode(id)}`, customerWithoutId);
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* @see https://docs.voucherify.io/reference/update-customers-in-bulk
|
|
915
|
-
*/
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
updateInBulk(customers) {
|
|
919
|
-
return this.client.post(`/customers/bulk/async`, customers);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* @see https://docs.voucherify.io/reference/update-customers-metadata-in-bulk
|
|
923
|
-
*/
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
updateMetadataInBulk(sourceIdsAndMetadata) {
|
|
927
|
-
return this.client.post(`/customers/metadata/async`, sourceIdsAndMetadata);
|
|
928
|
-
}
|
|
929
|
-
/**
|
|
930
|
-
* @see https://docs.voucherify.io/reference/delete-customer
|
|
931
|
-
*/
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
delete(customerId) {
|
|
935
|
-
return this.client.delete(`/customers/${encode(customerId)}`);
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* @see https://docs.voucherify.io/reference/delete-customer-permanently
|
|
939
|
-
*/
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
deletePermanently(customerId) {
|
|
943
|
-
return this.client.post(`/customers/${encode(customerId)}/permanent-deletion`, {});
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* @see https://docs.voucherify.io/reference/list-customer-activity
|
|
947
|
-
*/
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
listActivity(customerIdOrSourceId, params) {
|
|
951
|
-
return this.client.get(`/customers/${encode(customerIdOrSourceId)}/activity`, params);
|
|
952
|
-
}
|
|
953
|
-
/**
|
|
954
|
-
* @deprecated This method is deprecated. We’re removing this method in next major version.
|
|
955
|
-
*/
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
updateConsents(idOrSourceId, consents) {
|
|
959
|
-
return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* @deprecated This method is deprecated in favor of the `listActivity` method. We’re removing this method in next major version.
|
|
963
|
-
*/
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
listActivities(customerId, params) {
|
|
967
|
-
return this.client.get(`/customers/${encode(customerId)}/activities`, params);
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* @see https://docs.voucherify.io/reference/import-customers-using-csv
|
|
971
|
-
*/
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
async importCSV(filePath) {
|
|
975
|
-
assert(environment().startsWith('Node'), `Method "client.customers.importCSV(filePath)" is only for Node environment`);
|
|
976
|
-
const fs = (await import('fs')).default;
|
|
977
|
-
const fileStream = fs.createReadStream(filePath);
|
|
978
|
-
const form = new FormData();
|
|
979
|
-
form.append('file', fileStream);
|
|
980
|
-
const headers = {
|
|
981
|
-
'Content-Type': 'multipart/form-data'
|
|
982
|
-
};
|
|
983
|
-
return this.client.post(`/customers/importCSV`, form, undefined, headers);
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* @see https://docs.voucherify.io/reference/list-customer-redeemables
|
|
987
|
-
*/
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
listRedeemables(id, params) {
|
|
991
|
-
return this.client.get(`/customers/${encode(id)}/redeemables`, params);
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
class Consents {
|
|
997
|
-
constructor(client) {
|
|
998
|
-
this.client = void 0;
|
|
999
|
-
this.client = client;
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* @deprecated This method is deprecated. We’re removing this method in next major version.
|
|
1003
|
-
*/
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
list() {
|
|
1007
|
-
return this.client.get('/consents');
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
class Orders {
|
|
1013
|
-
constructor(client) {
|
|
1014
|
-
this.client = void 0;
|
|
1015
|
-
this.client = client;
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* @see https://docs.voucherify.io/reference/create-order
|
|
1019
|
-
*/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
create(order) {
|
|
1023
|
-
return this.client.post('/orders', order);
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* @see https://docs.voucherify.io/reference/get-order
|
|
1027
|
-
*/
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
get(orderId) {
|
|
1031
|
-
return this.client.get(`/orders/${encode(orderId)}`);
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* @see https://docs.voucherify.io/reference/update-order
|
|
1035
|
-
*/
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
update(order) {
|
|
1039
|
-
return this.client.put(`/orders/${encode(order.id || order.source_id)}`, omit(order, ['id']));
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* @see https://docs.voucherify.io/reference/list-orders
|
|
1043
|
-
*/
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
list(params = {}) {
|
|
1047
|
-
return this.client.get('/orders', params);
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
* @see https://docs.voucherify.io/reference/import-orders
|
|
1051
|
-
*/
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
import(orders) {
|
|
1055
|
-
return this.client.post('/orders/import', orders);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
class Products {
|
|
1061
|
-
constructor(client) {
|
|
1062
|
-
this.client = void 0;
|
|
1063
|
-
this.client = client;
|
|
1064
|
-
}
|
|
1065
|
-
/**
|
|
1066
|
-
* @see https://docs.voucherify.io/reference/create-product
|
|
1067
|
-
*/
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
create(product) {
|
|
1071
|
-
return this.client.post('/products', product);
|
|
1072
|
-
}
|
|
1073
|
-
/**
|
|
1074
|
-
* @see https://docs.voucherify.io/reference/get-product
|
|
1075
|
-
*/
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
get(productId) {
|
|
1079
|
-
return this.client.get(`/products/${encode(productId)}`);
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* @see https://docs.voucherify.io/reference/update-product
|
|
1083
|
-
*/
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
update(product) {
|
|
1087
|
-
return this.client.put(`/products/${encode(product.id || product.source_id)}`, omit(product, ['id']));
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* @see https://docs.voucherify.io/reference/async-update-products-metadata-in-bulk
|
|
1091
|
-
*/
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
bulkUpdateMetadata(products) {
|
|
1095
|
-
return this.client.post('/products/metadata/async', products);
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* @see https://docs.voucherify.io/reference/post-products-in-bulk
|
|
1099
|
-
*/
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
bulkUpdate(products) {
|
|
1103
|
-
return this.client.post('/products/bulk/async', products);
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* @see https://docs.voucherify.io/reference/delete-product
|
|
1107
|
-
*/
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
delete(productId, params) {
|
|
1111
|
-
return this.client.delete(`/products/${encode(productId)}`, params);
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* @see https://docs.voucherify.io/reference/list-products
|
|
1115
|
-
*/
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
list(params) {
|
|
1119
|
-
return this.client.get('/products', params);
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* @see https://docs.voucherify.io/reference/create-sku
|
|
1123
|
-
*/
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
createSku(productId, sku) {
|
|
1127
|
-
return this.client.post(`/products/${encode(productId)}/skus`, sku);
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* @see https://docs.voucherify.io/reference/get-sku-v20210726
|
|
1131
|
-
*/
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
getSku(skuId) {
|
|
1135
|
-
return this.client.get(`/skus/${encode(skuId)}`);
|
|
1136
|
-
}
|
|
1137
|
-
/**
|
|
1138
|
-
* @see https://docs.voucherify.io/reference/update-sku
|
|
1139
|
-
*/
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
updateSku(productId, sku) {
|
|
1143
|
-
return this.client.put(`/products/${encode(productId)}/skus/${encode(sku.id || sku.source_id)}`, omit(sku, ['id']));
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* @see https://docs.voucherify.io/reference/delete-sku
|
|
1147
|
-
*/
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
deleteSku(productId, skuId, params) {
|
|
1151
|
-
return this.client.delete(`/products/${encode(productId)}/skus/${encode(skuId)}`, params);
|
|
1152
|
-
}
|
|
1153
|
-
/**
|
|
1154
|
-
* @see https://docs.voucherify.io/reference/list-skus
|
|
1155
|
-
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
listSkus(productId) {
|
|
1159
|
-
return this.client.get(`/products/${encode(productId)}/skus`);
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* @see https://docs.voucherify.io/reference/import-skus-using-csv
|
|
1163
|
-
*/
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
async importSkusCSV(filePath) {
|
|
1167
|
-
assert(environment().startsWith('Node'), `Method "client.products.importSkusCSV(filePath)" is only for Node environment`);
|
|
1168
|
-
const fs = (await import('fs')).default;
|
|
1169
|
-
const fileStream = fs.createReadStream(filePath);
|
|
1170
|
-
const form = new FormData();
|
|
1171
|
-
form.append('file', fileStream);
|
|
1172
|
-
const headers = {
|
|
1173
|
-
'Content-Type': 'multipart/form-data'
|
|
1174
|
-
};
|
|
1175
|
-
return this.client.post(`/skus/importCSV`, form, undefined, headers);
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* @see https://docs.voucherify.io/reference/import-products-using-csv
|
|
1179
|
-
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
async importCSV(filePath) {
|
|
1183
|
-
assert(environment().startsWith('Node'), `Method "client.products.importCSV(filePath)" is only for Node environment`);
|
|
1184
|
-
const fs = (await import('fs')).default;
|
|
1185
|
-
const fileStream = fs.createReadStream(filePath);
|
|
1186
|
-
const form = new FormData();
|
|
1187
|
-
form.append('file', fileStream);
|
|
1188
|
-
const headers = {
|
|
1189
|
-
'Content-Type': 'multipart/form-data'
|
|
1190
|
-
};
|
|
1191
|
-
return this.client.post(`/products/importCSV`, form, undefined, headers);
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
class Rewards {
|
|
1197
|
-
constructor(client) {
|
|
1198
|
-
this.client = void 0;
|
|
1199
|
-
this.client = client;
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* @see https://docs.voucherify.io/reference/list-rewards
|
|
1203
|
-
*/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
list(params = {}) {
|
|
1207
|
-
return this.client.get('/rewards', params);
|
|
1208
|
-
}
|
|
1209
|
-
/**
|
|
1210
|
-
* @see https://docs.voucherify.io/reference/create-reward
|
|
1211
|
-
*/
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
create(reward) {
|
|
1215
|
-
return this.client.post('/rewards', reward);
|
|
1216
|
-
}
|
|
1217
|
-
/**
|
|
1218
|
-
* @see https://docs.voucherify.io/reference/get-reward
|
|
1219
|
-
*/
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
get(rewardId) {
|
|
1223
|
-
return this.client.get(`/rewards/${encode(rewardId)}`);
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* @see https://docs.voucherify.io/reference/update-reward
|
|
1227
|
-
*/
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
update(reward) {
|
|
1231
|
-
return this.client.put(`/rewards/${encode(reward.id)}`, omit(reward, ['id']));
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* @see https://docs.voucherify.io/reference/delete-reward
|
|
1235
|
-
*/
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
delete(rewardId) {
|
|
1239
|
-
return this.client.delete(`/rewards/${encode(rewardId)}`);
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* @see https://docs.voucherify.io/reference/get-reward-assignment
|
|
1243
|
-
*/
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
getAssignment(rewardId, assignmentId) {
|
|
1247
|
-
return this.client.get(`/rewards/${encode(rewardId)}/assignments/${encode(assignmentId)}`);
|
|
1248
|
-
}
|
|
1249
|
-
/**
|
|
1250
|
-
* @see https://docs.voucherify.io/reference/list-reward-assignments
|
|
1251
|
-
*/
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
listAssignments(rewardId, params = {}) {
|
|
1255
|
-
return this.client.get(`/rewards/${encode(rewardId)}/assignments`, params);
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* @see https://docs.voucherify.io/reference/create-reward-assignment
|
|
1259
|
-
*/
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
createAssignment(rewardId, assignment) {
|
|
1263
|
-
return this.client.post(`/rewards/${encode(rewardId)}/assignments`, assignment);
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* @see https://docs.voucherify.io/reference/update-reward-assignment
|
|
1267
|
-
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
updateAssignment(rewardId, assignment) {
|
|
1271
|
-
return this.client.put(`/rewards/${encode(rewardId)}/assignments/${encode(assignment.id)}`, omit(assignment, ['id']));
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
deleteAssignment(rewardId, assignmentId) {
|
|
1275
|
-
return this.client.delete(`/rewards/${encode(rewardId)}/assignments/${encode(assignmentId)}`);
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
class Loyalties {
|
|
1281
|
-
constructor(client) {
|
|
1282
|
-
this.client = void 0;
|
|
1283
|
-
this.client = client;
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-programs
|
|
1287
|
-
*/
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
list(params = {}) {
|
|
1291
|
-
return this.client.get('/loyalties', params);
|
|
1292
|
-
}
|
|
1293
|
-
/**
|
|
1294
|
-
* @see https://docs.voucherify.io/reference/create-loyalty-program
|
|
1295
|
-
*/
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
create(campaign) {
|
|
1299
|
-
return this.client.post('/loyalties', campaign);
|
|
1300
|
-
}
|
|
1301
|
-
/**
|
|
1302
|
-
* @see https://docs.voucherify.io/reference/get-loyalty-program
|
|
1303
|
-
*/
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
get(campaignId) {
|
|
1307
|
-
return this.client.get(`/loyalties/${encode(campaignId)}`);
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* @see https://docs.voucherify.io/reference/update-loyalty-program
|
|
1311
|
-
*/
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
update(campaign) {
|
|
1315
|
-
return this.client.put(`/loyalties/${encode(campaign.id)}`, omit(campaign, ['id']));
|
|
1316
|
-
}
|
|
1317
|
-
/**
|
|
1318
|
-
* @see https://docs.voucherify.io/reference/delete-loyalty-program
|
|
1319
|
-
*/
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
delete(campaignId, params) {
|
|
1323
|
-
return this.client.delete(`/loyalties/${encode(campaignId)}`, params);
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* @see https://docs.voucherify.io/reference/list-reward-assignments-1
|
|
1327
|
-
*/
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
listRewardAssignments(campaignId, params = {}) {
|
|
1331
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/rewards`, params);
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* @see https://docs.voucherify.io/reference/create-reward-assignment-1
|
|
1335
|
-
*/
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
createRewardAssignments(campaignId, assignment) {
|
|
1339
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/rewards`, assignment);
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* @see https://docs.voucherify.io/reference/update-reward-assignment-1
|
|
1343
|
-
*/
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
updateRewardAssignment(campaignId, assignment) {
|
|
1347
|
-
return this.client.put(`/loyalties/${encode(campaignId)}/rewards/${assignment.id}`, omit(assignment, ['id']));
|
|
1348
|
-
}
|
|
1349
|
-
/**
|
|
1350
|
-
* @see https://docs.voucherify.io/reference/delete-reward-assignment-1
|
|
1351
|
-
*/
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
deleteRewardAssignment(campaignId, assignmentId) {
|
|
1355
|
-
return this.client.delete(`/loyalties/${encode(campaignId)}/rewards/${assignmentId}`);
|
|
1356
|
-
}
|
|
1357
|
-
/**
|
|
1358
|
-
* @see https://docs.voucherify.io/reference/get-reward-assignment-2
|
|
1359
|
-
*/
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
getRewardAssignment(campaignId, assignmentId) {
|
|
1363
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/rewards/${encode(assignmentId)}`);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* @see https://docs.voucherify.io/reference/list-earning-rules
|
|
1367
|
-
*/
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
listEarningRules(campaignId, params = {}) {
|
|
1371
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/earning-rules`, params);
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* @see https://docs.voucherify.io/reference/create-earning-rule
|
|
1375
|
-
*/
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
createEarningRule(campaignId, earningRules) {
|
|
1379
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/earning-rules`, earningRules);
|
|
1380
|
-
}
|
|
1381
|
-
/**
|
|
1382
|
-
* @see https://docs.voucherify.io/reference/update-earning-rule
|
|
1383
|
-
*/
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
updateEarningRule(campaignId, earningRule) {
|
|
1387
|
-
return this.client.put(`/loyalties/${encode(campaignId)}/earning-rules/${earningRule.id}`, omit(earningRule, ['id']));
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
|
-
* @see https://docs.voucherify.io/reference/delete-earning-rule
|
|
1391
|
-
*/
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
deleteEarningRule(campaignId, earningRuleId) {
|
|
1395
|
-
return this.client.delete(`/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}`);
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* @see https://docs.voucherify.io/reference/get-earning-rule
|
|
1399
|
-
*/
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
getEarningRule(campaignId, earningRuleId) {
|
|
1403
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/earning-rules/${encode(earningRuleId)}`);
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* @see https://docs.voucherify.io/reference/enable-earning-rule
|
|
1407
|
-
*/
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
enableEarningRule(campaignId, earningRuleId) {
|
|
1411
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}/enable`, {});
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* @see https://docs.voucherify.io/reference/disable-earning-rule
|
|
1415
|
-
*/
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
disableEarningRule(campaignId, earningRuleId) {
|
|
1419
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}/disable`, {});
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* @see https://docs.voucherify.io/reference/list-members
|
|
1423
|
-
*/
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
listMembers(campaignId, params) {
|
|
1427
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/members`, params);
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* @see https://docs.voucherify.io/reference/create-member
|
|
1431
|
-
*/
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
createMember(campaignId, member) {
|
|
1435
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/members`, member);
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* @see https://docs.voucherify.io/reference/get-member
|
|
1439
|
-
* @see https://docs.voucherify.io/reference/get-member-1
|
|
1440
|
-
*/
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
getMember(campaignId, memberId) {
|
|
1444
|
-
return this.client.get(campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}` : `/loyalties/members/${memberId}`);
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* @see https://docs.voucherify.io/reference/list-member-activity
|
|
1448
|
-
* @see https://docs.voucherify.io/reference/list-member-activity-1
|
|
1449
|
-
*/
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
listMemberActivity(campaignId, memberId, params) {
|
|
1453
|
-
return this.client.get(campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/activity` : `/loyalties/members/${memberId}/activity`, params);
|
|
1454
|
-
}
|
|
1455
|
-
/**
|
|
1456
|
-
* @deprecated This method is deprecated in favor of the `listMemberActivity` method. We’re removing this method in next major version.
|
|
1457
|
-
*/
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
getMemberActivities(campaignId, memberId) {
|
|
1461
|
-
return this.client.get(campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/activities` : `/loyalties/members/${memberId}/activities`);
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* @see https://docs.voucherify.io/reference/list-member-rewards
|
|
1465
|
-
*/
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
listMemberRewards(memberId, params) {
|
|
1469
|
-
return this.client.get(`/loyalties/members/${encode(memberId)}/rewards`, params);
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance
|
|
1473
|
-
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
|
|
1474
|
-
*/
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
addOrRemoveCardBalance(memberId, balance, campaignId) {
|
|
1478
|
-
return this.client.post(campaignId ? `/loyalties/${encode(campaignId)}/members/${memberId}/balance` : `/loyalties/members/${memberId}/balance`, balance);
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* @see https://docs.voucherify.io/reference/add-remove-loyalty-card-balance-1
|
|
1482
|
-
*/
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
addPoints(campaignId, memberId, balance) {
|
|
1486
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/members/${memberId}/balance`, balance);
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* @see https://docs.voucherify.io/reference/transfer-points
|
|
1490
|
-
*/
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
transferPoints(campaignId, memberId, loyaltiesTransferPoints) {
|
|
1494
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transfers`, loyaltiesTransferPoints);
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* @see https://docs.voucherify.io/reference/get-points-expiration
|
|
1498
|
-
*/
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
getPointsExpiration(campaignId, memberId, params) {
|
|
1502
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/members/${memberId}/points-expiration`, params);
|
|
1503
|
-
}
|
|
1504
|
-
/**
|
|
1505
|
-
* @see https://docs.voucherify.io/reference/redeem-loyalty-card
|
|
1506
|
-
*/
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
redeemReward(campaignId, memberId, params) {
|
|
1510
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/members/${encode(memberId)}/redemption`, params);
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-tier-rewards
|
|
1514
|
-
*/
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
listLoyaltyTierRewards(campaignId, tierId) {
|
|
1518
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}/rewards`);
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-card-transactions
|
|
1522
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-card-transactions-1
|
|
1523
|
-
*/
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
listCardTransactions(memberId, campaignId, params) {
|
|
1527
|
-
return this.client.get(campaignId ? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions` : `/loyalties/members/${encode(memberId)}/transactions`, params);
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* @see https://docs.voucherify.io/reference/export-loyalty-card-transactions
|
|
1531
|
-
* @see https://docs.voucherify.io/reference/export-loyalty-card-transactions-1
|
|
1532
|
-
*/
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
exportCardTransactions(memberId, campaignId, params = {}) {
|
|
1536
|
-
return this.client.post(campaignId ? `/loyalties/${encode(campaignId)}/members/${encode(memberId)}/transactions/export` : `/loyalties/members/${encode(memberId)}/transactions/export`, params);
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* @see https://docs.voucherify.io/reference/get-reward-details
|
|
1540
|
-
*/
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
getRewardDetails(campaignId, assignmentId) {
|
|
1544
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/reward-assignments/${encode(assignmentId)}/reward`);
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-tiers
|
|
1548
|
-
*/
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
listTiers(campaignId, params) {
|
|
1552
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/tiers`, params);
|
|
1553
|
-
}
|
|
1554
|
-
/**
|
|
1555
|
-
* @see https://docs.voucherify.io/reference/get-loyalty-tier
|
|
1556
|
-
*/
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
getTier(campaignId, tierId) {
|
|
1560
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}`);
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* @see https://docs.voucherify.io/reference/create-loyalty-tiers
|
|
1564
|
-
*/
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
createTiers(campaignId, tiers) {
|
|
1568
|
-
return this.client.post(`/loyalties/${encode(campaignId)}/tiers`, tiers);
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* @see https://docs.voucherify.io/reference/list-loyalty-tier-earning-rules
|
|
1572
|
-
*/
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
listLoyaltyTierEarningRules(campaignId, tierId, params) {
|
|
1576
|
-
return this.client.get(`/loyalties/${encode(campaignId)}/tiers/${encode(tierId)}/earning-rules`, params);
|
|
1577
|
-
}
|
|
1578
|
-
/**
|
|
1579
|
-
* @see https://docs.voucherify.io/reference/get-member-loyalty-tier
|
|
1580
|
-
*/
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
listMemberLoyaltyTiers(memberId) {
|
|
1584
|
-
return this.client.get(`/loyalties/members/${encode(memberId)}/tiers`);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
class ValidationRules {
|
|
1590
|
-
constructor(client) {
|
|
1591
|
-
this.client = void 0;
|
|
1592
|
-
this.client = client;
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* @see https://docs.voucherify.io/reference/create-validation-rules
|
|
1596
|
-
*/
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
create(validationRule) {
|
|
1600
|
-
return this.client.post('/validation-rules', validationRule);
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* @see https://docs.voucherify.io/reference/get-validation-rules
|
|
1604
|
-
*/
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
get(validationRuleId) {
|
|
1608
|
-
return this.client.get(`/validation-rules/${encode(validationRuleId)}`);
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
* @see https://docs.voucherify.io/reference/update-validation-rules
|
|
1612
|
-
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
update(validationRule) {
|
|
1616
|
-
return this.client.put(`/validation-rules/${encode(validationRule.id)}`, omit(validationRule, ['id']));
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* @see https://docs.voucherify.io/reference/delete-validation-rules
|
|
1620
|
-
*/
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
delete(validationRuleId) {
|
|
1624
|
-
return this.client.delete(`/validation-rules/${encode(validationRuleId)}`);
|
|
1625
|
-
}
|
|
1626
|
-
/**
|
|
1627
|
-
* @see https://docs.voucherify.io/reference/create-validation-rules-assignment
|
|
1628
|
-
*/
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
createAssignment(validationRuleId, assignment) {
|
|
1632
|
-
return this.client.post(`/validation-rules/${encode(validationRuleId)}/assignments`, assignment);
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* @see https://docs.voucherify.io/reference/delete-validation-rules-assignment
|
|
1636
|
-
*/
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
deleteAssignment(validationRuleId, assignmentId) {
|
|
1640
|
-
return this.client.delete(`/validation-rules/${encode(validationRuleId)}/assignments/${encode(assignmentId)}`);
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
validate(validationRuleId, params = {}) {
|
|
1644
|
-
return this.client.post(`/validation-rules/${encode(validationRuleId)}/validation`, params);
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* @see https://docs.voucherify.io/reference/list-validation-rules
|
|
1648
|
-
*/
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
list(params = {}) {
|
|
1652
|
-
return this.client.get('/validation-rules', params);
|
|
1653
|
-
}
|
|
1654
|
-
/**
|
|
1655
|
-
* @see https://docs.voucherify.io/reference/list-validation-rules-assignments
|
|
1656
|
-
*/
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
listRulesAssignments(params = {}) {
|
|
1660
|
-
return this.client.get(`/validation-rules-assignments`, params);
|
|
1661
|
-
}
|
|
1662
|
-
/**
|
|
1663
|
-
* @see https://docs.voucherify.io/reference/list-validation-rule-assignments
|
|
1664
|
-
*/
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
listAssignments(validationRuleId, params = {}) {
|
|
1668
|
-
return this.client.get(`/validation-rules/${encode(validationRuleId)}/assignments`, params);
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
class Segments {
|
|
1674
|
-
constructor(client) {
|
|
1675
|
-
this.client = void 0;
|
|
1676
|
-
this.client = client;
|
|
1677
|
-
}
|
|
1678
|
-
/**
|
|
1679
|
-
* @see https://docs.voucherify.io/reference/create-segment
|
|
1680
|
-
*/
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
create(segment) {
|
|
1684
|
-
return this.client.post('/segments', segment);
|
|
1685
|
-
}
|
|
1686
|
-
/**
|
|
1687
|
-
* @see https://docs.voucherify.io/reference/get-segment
|
|
1688
|
-
*/
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
get(segmentId) {
|
|
1692
|
-
return this.client.get(`/segments/${encode(segmentId)}`);
|
|
1693
|
-
}
|
|
1694
|
-
/**
|
|
1695
|
-
* @see https://docs.voucherify.io/reference/delete-segment
|
|
1696
|
-
*/
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
delete(segmentId) {
|
|
1700
|
-
return this.client.delete(`/segments/${encode(segmentId)}`);
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* @see https://docs.voucherify.io/reference/list-segments
|
|
1704
|
-
*/
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
list(customerId) {
|
|
1708
|
-
return this.client.get(`/customers/${encode(customerId)}/segments`);
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
class ApiLimitsHandler {
|
|
1714
|
-
constructor(requestController) {
|
|
1715
|
-
this.requestController = void 0;
|
|
1716
|
-
this.requestController = requestController;
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
getLastResponseHeadersFromController() {
|
|
1720
|
-
return this.requestController.getLastResponseHeaders();
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
areLimitsAvailable() {
|
|
1724
|
-
return this.requestController.isLastReponseHeadersSet();
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
getRateLimit() {
|
|
1728
|
-
var _this$getLastResponse;
|
|
1729
|
-
|
|
1730
|
-
const rateLimit = (_this$getLastResponse = this.getLastResponseHeadersFromController()['x-rate-limit-limit']) != null ? _this$getLastResponse : 0;
|
|
1731
|
-
return parseInt(rateLimit, 10);
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
getRateLimitRemaining() {
|
|
1735
|
-
var _this$getLastResponse2;
|
|
1736
|
-
|
|
1737
|
-
const rateLimitRemaining = (_this$getLastResponse2 = this.getLastResponseHeadersFromController()['x-rate-limit-remaining']) != null ? _this$getLastResponse2 : 0;
|
|
1738
|
-
return parseInt(rateLimitRemaining, 10);
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
getRetryAfter() {
|
|
1742
|
-
var _this$getLastResponse3;
|
|
1743
|
-
|
|
1744
|
-
const retryAfter = (_this$getLastResponse3 = this.getLastResponseHeadersFromController()['retry-after']) != null ? _this$getLastResponse3 : 0;
|
|
1745
|
-
return parseInt(retryAfter, 10);
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
class MetadataSchemas {
|
|
1751
|
-
constructor(client) {
|
|
1752
|
-
this.client = void 0;
|
|
1753
|
-
this.client = client;
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* @see https://docs.voucherify.io/reference/list-metadata-schemas
|
|
1757
|
-
*/
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
list() {
|
|
1761
|
-
return this.client.get('/metadata-schemas');
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* @see https://docs.voucherify.io/reference/get-metadata-schema
|
|
1765
|
-
*/
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
get(schemaName) {
|
|
1769
|
-
return this.client.get(`/metadata-schemas/${encode(schemaName)}`);
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
class Categories {
|
|
1775
|
-
constructor(client) {
|
|
1776
|
-
this.client = void 0;
|
|
1777
|
-
this.client = client;
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* @see https://docs.voucherify.io/reference/list-categories
|
|
1781
|
-
*/
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
list(params = {}) {
|
|
1785
|
-
return this.client.get('/categories', params);
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* @see https://docs.voucherify.io/reference/create-category
|
|
1789
|
-
*/
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
create(createCategory) {
|
|
1793
|
-
return this.client.post('/categories', createCategory);
|
|
1794
|
-
}
|
|
1795
|
-
/**
|
|
1796
|
-
* @see https://docs.voucherify.io/reference/get-category
|
|
1797
|
-
*/
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
get(categoryId) {
|
|
1801
|
-
return this.client.get(`/categories/${encode(categoryId)}`);
|
|
1802
|
-
}
|
|
1803
|
-
/**
|
|
1804
|
-
* @see https://docs.voucherify.io/reference/delete-category
|
|
1805
|
-
*/
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
delete(categoryId) {
|
|
1809
|
-
return this.client.delete(`/categories/${encode(categoryId)}`);
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* @see https://docs.voucherify.io/reference/update-category
|
|
1813
|
-
*/
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
update(categoryId, updateCategory) {
|
|
1817
|
-
return this.client.put(`/categories/${encode(categoryId)}`, updateCategory);
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
class PromotionsStacks {
|
|
1823
|
-
constructor(client) {
|
|
1824
|
-
this.client = void 0;
|
|
1825
|
-
this.client = client;
|
|
1826
|
-
}
|
|
1827
|
-
/**
|
|
1828
|
-
* @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
|
|
1829
|
-
*/
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
listInCampaign(campaignId) {
|
|
1833
|
-
return this.client.get(`/promotions/${campaignId}/stacks`);
|
|
1834
|
-
}
|
|
1835
|
-
/**
|
|
1836
|
-
* @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
|
|
1837
|
-
*/
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
createInCampaign(campaignId, body) {
|
|
1841
|
-
return this.client.post(`/promotions/${campaignId}/stacks`, body);
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* @see https://docs.voucherify.io/reference/delete-promotion-stack
|
|
1845
|
-
*/
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
delete(campaignId, stackId) {
|
|
1849
|
-
return this.client.delete(`/promotions/${campaignId}/stacks/${stackId}`);
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* @see https://docs.voucherify.io/reference/get-promotion-stack
|
|
1853
|
-
*/
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
get(campaignId, stackId) {
|
|
1857
|
-
return this.client.get(`/promotions/${campaignId}/stacks/${stackId}`);
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
|
-
* @see https://docs.voucherify.io/reference/update-promotion-stack
|
|
1861
|
-
*/
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
update(campaignId, stackId, body) {
|
|
1865
|
-
return this.client.put(`/promotions/${campaignId}/stacks/${stackId}`, body);
|
|
1866
|
-
}
|
|
1867
|
-
/**
|
|
1868
|
-
* @see https://docs.voucherify.io/reference/list-promotion-stacks-in-campaign
|
|
1869
|
-
*/
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
list(params) {
|
|
1873
|
-
return this.client.get(`/promotions/stacks`, params);
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
class ProductCollections {
|
|
1879
|
-
constructor(client) {
|
|
1880
|
-
this.client = void 0;
|
|
1881
|
-
this.client = client;
|
|
1882
|
-
}
|
|
1883
|
-
/**
|
|
1884
|
-
* @see https://docs.voucherify.io/reference/create-product-collection
|
|
1885
|
-
*/
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
create(productCollection) {
|
|
1889
|
-
return this.client.post(`/product-collections`, productCollection);
|
|
1890
|
-
}
|
|
1891
|
-
/**
|
|
1892
|
-
* @see https://docs.voucherify.io/reference/list-product-collections
|
|
1893
|
-
*/
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
list(params) {
|
|
1897
|
-
return this.client.get(`/product-collections`, params);
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* @see https://docs.voucherify.io/reference/delete-product-collection
|
|
1901
|
-
*/
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
delete(productCollectionId) {
|
|
1905
|
-
return this.client.delete(`/product-collections/${encode(productCollectionId)}`);
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* @see https://docs.voucherify.io/reference/get-product-collection
|
|
1909
|
-
*/
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
get(productCollectionId) {
|
|
1913
|
-
return this.client.get(`/product-collections/${encode(productCollectionId)}`);
|
|
1914
|
-
}
|
|
1915
|
-
/**
|
|
1916
|
-
* @see https://docs.voucherify.io/reference/list-products-in-collection
|
|
1917
|
-
*/
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
listProducts(productCollectionId, params) {
|
|
1921
|
-
return this.client.get(`/product-collections/${encode(productCollectionId)}/products`, params);
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
class Qualifications {
|
|
1927
|
-
constructor(client) {
|
|
1928
|
-
this.client = void 0;
|
|
1929
|
-
this.client = client;
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* @see https://docs.voucherify.io/reference/check-eligibility
|
|
1933
|
-
*/
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
checkEligibility(body) {
|
|
1937
|
-
return this.client.post('/qualifications', body);
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
// apiLimitsHandler: ApiLimitsHandler
|
|
1943
|
-
// campaigns: Campaigns
|
|
1944
|
-
// consents: Consents
|
|
1945
|
-
// customers: Customers
|
|
1946
|
-
// distributions: Distributions
|
|
1947
|
-
// events: Events
|
|
1948
|
-
// loyalties: Loyalties
|
|
1949
|
-
// metadataSchemas: MetadataSchemas
|
|
1950
|
-
// orders: Orders
|
|
1951
|
-
// products: Products
|
|
1952
|
-
// promotions: Promotions
|
|
1953
|
-
// redemptions: Redemptions
|
|
1954
|
-
// rewards: Rewards
|
|
1955
|
-
// segments: Segments
|
|
1956
|
-
// validationRules: ValidationRules
|
|
1957
|
-
// validations: Validations
|
|
1958
|
-
// vouchers: Vouchers
|
|
1959
|
-
// }
|
|
1960
|
-
|
|
1961
|
-
function VoucherifyServerSide(options) {
|
|
1962
|
-
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
1963
|
-
|
|
1964
|
-
assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
|
|
1965
|
-
assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
|
|
1966
|
-
assert(isString(options.secretKey), 'VoucherifyServerSide: "options.secretKey" is required');
|
|
1967
|
-
assert(isOptionalString(options.apiVersion), 'VoucherifyServerSide: expected "options.apiVersion" to be a string');
|
|
1968
|
-
assert(isOptionalString(options.channel), 'VoucherifyServerSide: expected "options.channel" to be a string');
|
|
1969
|
-
let headers = {
|
|
1970
|
-
'X-App-Id': options.applicationId,
|
|
1971
|
-
'X-App-Token': options.secretKey,
|
|
1972
|
-
'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.9.2"}`,
|
|
1973
|
-
'Content-Type': 'application/json'
|
|
1974
|
-
};
|
|
1975
|
-
|
|
1976
|
-
if (options.apiVersion) {
|
|
1977
|
-
headers['X-Voucherify-API-Version'] = options.apiVersion;
|
|
1978
|
-
}
|
|
1979
|
-
|
|
1980
|
-
if (isObject(options.customHeaders)) {
|
|
1981
|
-
headers = Object.assign({}, headers, options.customHeaders);
|
|
1982
|
-
}
|
|
1983
|
-
/**
|
|
1984
|
-
* The option `dangerouslySetSecretKeyInBrowser` is explicitly long and not suggested in the thrown error because
|
|
1985
|
-
* we don't want the user to enable this option without going through the documentation and understanding the risks
|
|
1986
|
-
* of exposing a their secretKey
|
|
1987
|
-
*/
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
if (!environment().startsWith('Node')) {
|
|
1991
|
-
assert(options.dangerouslySetSecretKeyInBrowser === true, `VoucherifyServerSide: you're exposing your secretKey to a ${environment().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
const client = new RequestController({
|
|
1995
|
-
basePath: 'v1',
|
|
1996
|
-
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
1997
|
-
headers,
|
|
1998
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
1999
|
-
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
2000
|
-
});
|
|
2001
|
-
const asyncActions = new AsyncActions(client);
|
|
2002
|
-
const balance = new Balance(client);
|
|
2003
|
-
const vouchers = new Vouchers(client, balance);
|
|
2004
|
-
const campaigns = new Campaigns(client);
|
|
2005
|
-
const categories = new Categories(client);
|
|
2006
|
-
const exportsNamespace = new Exports(client);
|
|
2007
|
-
const events = new Events(client);
|
|
2008
|
-
const distributions = new Distributions(client, exportsNamespace);
|
|
2009
|
-
const promotionTiers = new PromotionTiers(client);
|
|
2010
|
-
const promotionStack = new PromotionsStacks(client);
|
|
2011
|
-
const promotions = new Promotions(client, promotionTiers, promotionStack);
|
|
2012
|
-
const validations = new Validations(client, promotions);
|
|
2013
|
-
const redemptions = new Redemptions(client);
|
|
2014
|
-
const qualifications = new Qualifications(client);
|
|
2015
|
-
const customers = new Customers(client);
|
|
2016
|
-
const consents = new Consents(client);
|
|
2017
|
-
const orders = new Orders(client);
|
|
2018
|
-
const products = new Products(client);
|
|
2019
|
-
const productCollections = new ProductCollections(client);
|
|
2020
|
-
const rewards = new Rewards(client);
|
|
2021
|
-
const loyalties = new Loyalties(client);
|
|
2022
|
-
const segments = new Segments(client);
|
|
2023
|
-
const validationRules = new ValidationRules(client);
|
|
2024
|
-
const apiLimitsHandler = new ApiLimitsHandler(client);
|
|
2025
|
-
const metadataSchemas = new MetadataSchemas(client);
|
|
2026
|
-
return {
|
|
2027
|
-
vouchers,
|
|
2028
|
-
campaigns,
|
|
2029
|
-
categories,
|
|
2030
|
-
distributions,
|
|
2031
|
-
validations,
|
|
2032
|
-
redemptions,
|
|
2033
|
-
promotions,
|
|
2034
|
-
customers,
|
|
2035
|
-
consents,
|
|
2036
|
-
orders,
|
|
2037
|
-
products,
|
|
2038
|
-
productCollections,
|
|
2039
|
-
qualifications,
|
|
2040
|
-
rewards,
|
|
2041
|
-
loyalties,
|
|
2042
|
-
segments,
|
|
2043
|
-
validationRules,
|
|
2044
|
-
events,
|
|
2045
|
-
asyncActions,
|
|
2046
|
-
apiLimitsHandler,
|
|
2047
|
-
metadataSchemas
|
|
2048
|
-
};
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
class ClientSide {
|
|
2052
|
-
constructor(client, trackingId) {
|
|
2053
|
-
this.client = void 0;
|
|
2054
|
-
this.trackingId = void 0;
|
|
2055
|
-
this.client = client;
|
|
2056
|
-
this.trackingId = trackingId;
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
setIdentity(identity) {
|
|
2060
|
-
this.trackingId = identity;
|
|
2061
|
-
}
|
|
2062
|
-
/**
|
|
2063
|
-
* @see https://docs.voucherify.io/reference/vouchers-validate
|
|
2064
|
-
*/
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
validate(params) {
|
|
2068
|
-
var _query$customer, _query$customer2;
|
|
2069
|
-
|
|
2070
|
-
assert(isObject(params) || isString(params), 'client.validate: expected "params" argument to be an object or a string');
|
|
2071
|
-
const query = {};
|
|
2072
|
-
|
|
2073
|
-
if (isString(params)) {
|
|
2074
|
-
query.code = params;
|
|
2075
|
-
} else {
|
|
2076
|
-
query.code = params.code;
|
|
2077
|
-
query.item = params.items;
|
|
2078
|
-
query.amount = params.amount;
|
|
2079
|
-
query.metadata = params.metadata;
|
|
2080
|
-
query.order = {
|
|
2081
|
-
metadata: params.orderMetadata
|
|
2082
|
-
};
|
|
2083
|
-
query.customer = params.customer;
|
|
2084
|
-
query.tracking_id = params.tracking_id || this.trackingId;
|
|
2085
|
-
query.session_type = params.session_type;
|
|
2086
|
-
query.session_key = params.session_key;
|
|
2087
|
-
query.session_ttl = params.session_ttl;
|
|
2088
|
-
query.session_ttl_unit = params.session_ttl_unit;
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
if (!!query.code) {
|
|
2092
|
-
query.code = query.code.replace(/[\r\n\t\f\v]/g, '').trim();
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
assert(isOptionalObject(query == null ? void 0 : query.customer), 'client.validate: expected "params.customer" to be an object');
|
|
2096
|
-
assert(isOptionalString(query == null ? void 0 : (_query$customer = query.customer) == null ? void 0 : _query$customer.source_id), 'client.validate: expected "params.customer.source_id" to be a string'); // prettier-ignore
|
|
2097
|
-
|
|
2098
|
-
assert(isOptionalObject(query == null ? void 0 : (_query$customer2 = query.customer) == null ? void 0 : _query$customer2.metadata), 'client.validate: expected "params.customer.metadata" to be an object'); // prettier-ignore
|
|
2099
|
-
|
|
2100
|
-
const path = query.code ? '/validate' : '/promotions/validation';
|
|
2101
|
-
return this.client.get(path, query);
|
|
2102
|
-
}
|
|
2103
|
-
/**
|
|
2104
|
-
* @see https://docs.voucherify.io/reference/redeem-voucher-client-side
|
|
2105
|
-
*/
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
redeem(code, payload = {}) {
|
|
2109
|
-
var _payload$customer, _payload$customer$sou;
|
|
2110
|
-
|
|
2111
|
-
assert(isString(code), 'client.redeem - please provide a valid Voucher code');
|
|
2112
|
-
code = code.replace(/[\r\n\t\f\v]/g, '').trim();
|
|
2113
|
-
payload.customer = (_payload$customer = payload.customer) != null ? _payload$customer : {};
|
|
2114
|
-
payload.customer.source_id = (_payload$customer$sou = payload.customer.source_id) != null ? _payload$customer$sou : this.trackingId;
|
|
2115
|
-
return this.client.post('/redeem', payload, {
|
|
2116
|
-
code
|
|
2117
|
-
});
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* @see https://docs.voucherify.io/reference/create-publication
|
|
2121
|
-
*/
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
publish(campaign, payload = {}, queryParams = {}) {
|
|
2125
|
-
var _payload$customer2, _payload$customer$sou2, _payload$customer3, _payload$channel, _preparedPayload$cust;
|
|
2126
|
-
|
|
2127
|
-
assert(isObject(payload), 'client.publish - expected payload to be an object');
|
|
2128
|
-
const preparedPayload = {};
|
|
2129
|
-
preparedPayload.customer = (_payload$customer2 = payload.customer) != null ? _payload$customer2 : {};
|
|
2130
|
-
preparedPayload.customer.source_id = (_payload$customer$sou2 = (_payload$customer3 = payload.customer) == null ? void 0 : _payload$customer3.source_id) != null ? _payload$customer$sou2 : this.trackingId;
|
|
2131
|
-
preparedPayload.channel = (_payload$channel = payload.channel) != null ? _payload$channel : 'Voucherify.js'; // @todo - removed hard-coded channel
|
|
2132
|
-
|
|
2133
|
-
assert(isString((_preparedPayload$cust = preparedPayload.customer) == null ? void 0 : _preparedPayload$cust.source_id), 'client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client');
|
|
2134
|
-
queryParams.campaign = campaign.replace(/[\r\n\t\f\v]/g, '').trim();
|
|
2135
|
-
return this.client.post('/publish', preparedPayload, queryParams);
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* @see https://docs.voucherify.io/reference/track-custom-event-client-side
|
|
2139
|
-
*/
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
track(event_name, customer, metadata, referral, loyalty) {
|
|
2143
|
-
var _customer$source_id, _payload$customer4;
|
|
2144
|
-
|
|
2145
|
-
assert(isString(event_name), 'client.track - expected event name to be an string');
|
|
2146
|
-
assert(isObject(customer), 'client.track - expected customer to be an object');
|
|
2147
|
-
const payload = {
|
|
2148
|
-
event: event_name,
|
|
2149
|
-
metadata: metadata != null ? metadata : {},
|
|
2150
|
-
customer: customer,
|
|
2151
|
-
referral: referral != null ? referral : undefined,
|
|
2152
|
-
loyalty: loyalty != null ? loyalty : undefined
|
|
2153
|
-
};
|
|
2154
|
-
payload.customer.source_id = (_customer$source_id = customer.source_id) != null ? _customer$source_id : this.trackingId;
|
|
2155
|
-
assert(isString((_payload$customer4 = payload.customer) == null ? void 0 : _payload$customer4.source_id), 'client.track - expected payload to contain customer source id or to have tracking id set up by Voucherify client');
|
|
2156
|
-
return this.client.post('/events', payload);
|
|
2157
|
-
}
|
|
2158
|
-
/**
|
|
2159
|
-
* @see https://docs.voucherify.io/reference/list-vouchers
|
|
2160
|
-
*/
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
listVouchers(params = {}) {
|
|
2164
|
-
const query = {};
|
|
2165
|
-
query.campaign = params.campaign;
|
|
2166
|
-
query.category = params.category;
|
|
2167
|
-
query.page = params.page;
|
|
2168
|
-
query.limit = params.limit;
|
|
2169
|
-
query.customer = params.customer;
|
|
2170
|
-
query.created_at = params.created_at;
|
|
2171
|
-
query.updated_at = params.updated_at;
|
|
2172
|
-
return this.client.get('/vouchers', query);
|
|
2173
|
-
}
|
|
2174
|
-
/**
|
|
2175
|
-
* @see https://docs.voucherify.io/reference/create-customer
|
|
2176
|
-
*/
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
createCustomer(customer, enableDoubleOptIn) {
|
|
2180
|
-
return this.client.post('/customers', customer, {}, enableDoubleOptIn ? {
|
|
2181
|
-
'X-Voucherify-Double-Opt-In': true
|
|
2182
|
-
} : {});
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* @see https://docs.voucherify.io/reference/get-consent-client-side
|
|
2186
|
-
*/
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
listConsents() {
|
|
2190
|
-
return this.client.get('/consents');
|
|
2191
|
-
}
|
|
2192
|
-
/**
|
|
2193
|
-
* @see https://docs.voucherify.io/reference/update-customers-consents-client
|
|
2194
|
-
*/
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
updateConsents(idOrSourceId, consents) {
|
|
2198
|
-
return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
|
|
2199
|
-
}
|
|
2200
|
-
/**
|
|
2201
|
-
* @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
|
|
2202
|
-
*/
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
validateStackable(params) {
|
|
2206
|
-
return this.client.post(`/validations`, params);
|
|
2207
|
-
}
|
|
2208
|
-
/**
|
|
2209
|
-
* @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
|
|
2210
|
-
*/
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
redeemStackable(params) {
|
|
2214
|
-
return this.client.post(`/redemptions`, params);
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* @see https://docs.voucherify.io/reference/check-eligibility
|
|
2218
|
-
*/
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
qualifications(body) {
|
|
2222
|
-
return this.client.post('/qualifications', body);
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
}
|
|
2226
|
-
|
|
2227
|
-
function VoucherifyClientSide(options) {
|
|
2228
|
-
var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
|
|
2229
|
-
|
|
2230
|
-
assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
|
|
2231
|
-
assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
|
|
2232
|
-
assert(isString(options.clientSecretKey), 'VoucherifyCustomer: "options.clientSecretKey" is required');
|
|
2233
|
-
assert(isOptionalString(options.apiUrl), 'VoucherifyCustomer: expected "options.baseUrl" to be a string');
|
|
2234
|
-
assert(isOptionalString(options.trackingId), 'VoucherifyCustomer: expected "options.trackingId" to be a string');
|
|
2235
|
-
let headers = {
|
|
2236
|
-
'X-Client-Application-Id': options.clientApplicationId,
|
|
2237
|
-
'X-Client-Token': options.clientSecretKey,
|
|
2238
|
-
'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.9.2"}`
|
|
2239
|
-
};
|
|
2240
|
-
|
|
2241
|
-
if (environment().startsWith('Node')) {
|
|
2242
|
-
assert(isString(options.origin), 'VoucherifyCustomer: "options.origin" is required in Node.js');
|
|
2243
|
-
headers['origin'] = options.origin;
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
if (isObject(options.customHeaders)) {
|
|
2247
|
-
headers = Object.assign({}, headers, options.customHeaders);
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
const client = new RequestController({
|
|
2251
|
-
basePath: 'client/v1',
|
|
2252
|
-
baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
|
|
2253
|
-
headers,
|
|
2254
|
-
exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
|
|
2255
|
-
timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
|
|
2256
|
-
});
|
|
2257
|
-
return new ClientSide(client, options.trackingId);
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
export { DiscountVouchersTypesEnum, VoucherifyClientSide, VoucherifyServerSide };
|
|
2261
|
-
//# sourceMappingURL=voucherifysdk.esm.js.map
|
|
1
|
+
var fe=Object.defineProperty;var be=(i,e,t)=>e in i?fe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>be(i,typeof e!="symbol"?e+"":e,t);var Ce=(o=>(o.AMOUNT="AMOUNT",o.PERCENT="PERCENT",o.UNIT="UNIT",o.FIXED="FIXED",o))(Ce||{});import Se from"axios";import ee from"qs";var f=class extends Error{constructor(t,r,o){r=r!=null?r:{};let n=(r==null?void 0:r.message)||Pe(r,t);super(n);l(this,"code");l(this,"key");l(this,"details");l(this,"request_id");l(this,"resource_id");l(this,"resource_type");l(this,"related_object_ids");l(this,"related_object_type");l(this,"related_object_total");l(this,"error");l(this,"cause");this.code=r.code,this.key=r.key,this.details=r.details,this.request_id=r.request_id,this.resource_id=r.resource_id,this.resource_type=r.resource_type,this.related_object_ids=r.related_object_ids,this.related_object_type=r.related_object_type,this.related_object_total=r.related_object_total,this.error=r.error,this.cause=o}};function Pe(i,e){return i=typeof i=="string"?i:JSON.stringify(i,null,2),`Unexpected status code: ${e} - Details: ${i}`}var y=class{constructor({basePath:e,baseURL:t,headers:r,exposeErrorCause:o,timeoutMs:n}){l(this,"baseURL");l(this,"basePath");l(this,"headers");l(this,"request");l(this,"lastResponseHeaders");l(this,"isLastResponseHeadersSet");l(this,"exposeErrorCause");l(this,"timeoutMs");this.basePath=e,this.baseURL=t,this.headers=r,this.exposeErrorCause=o,this.lastResponseHeaders={},this.isLastResponseHeadersSet=!1,this.timeoutMs=n,this.request=Se.create({baseURL:`${this.baseURL}/${this.basePath}/`,allowAbsoluteUrls:!1,headers:this.headers,responseType:"json"}),this.request.interceptors.response.use(void 0,c=>{var g;return(g=c==null?void 0:c.response)!=null&&g.status?Promise.reject(new f(c.response.status,c.response.data,this.exposeErrorCause===!0?c:void 0)):Promise.reject(c)})}isLastReponseHeadersSet(){return this.isLastResponseHeadersSet}getLastResponseHeaders(){return this.lastResponseHeaders}setLastResponseHeaders(e){let t={};for(let r in e)t[r]=String(e[r]);this.lastResponseHeaders=t,this.isLastResponseHeadersSet=!0}setBaseUrl(e){this.baseURL=e,this.request.defaults.baseURL=`${e}/${this.basePath}/`}async get(e,t){let r=await this.request.get(e,{params:t,paramsSerializer:function(o){return ee.stringify(o)},timeout:this.timeoutMs});return this.setLastResponseHeaders(r.headers),r.data}async post(e,t,r,o){let n=await this.request.post(e,t,{params:r,paramsSerializer:function(c){return ee.stringify(c)},headers:o,timeout:this.timeoutMs});return this.setLastResponseHeaders(n.headers),n.data}async put(e,t,r){let o=await this.request.put(e,t,{params:r,timeout:this.timeoutMs});return this.setLastResponseHeaders(o.headers),o.data}async delete(e,t){let r=await this.request.delete(e,{params:t,timeout:this.timeoutMs});return this.setLastResponseHeaders(r.headers),r.data}};function s(i=""){return encodeURIComponent(i)}function u(i){return typeof i=="string"}function T(i){return i==null||u(i)}function d(i){return typeof i=="object"&&!Array.isArray(i)&&i!==null}function Y(i){return i==null||d(i)}function p(){return typeof window!="undefined"&&typeof window.document!="undefined"?"Browser":typeof self=="object"&&self.constructor&&self.constructor.name==="DedicatedWorkerGlobalScope"?"WebWorker":typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null?`Node.js-${process.version}`:typeof window!="undefined"&&window.name==="nodejs"||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")?"JsDom":"Unknown"}function a(i,e){if(!i)throw new Error(e)}function m(i,e){return Object.fromEntries(Object.entries(i).filter(([t])=>!e.includes(t)))}var b=class{constructor(e){this.client=e}get(e){return this.client.get(`/async-actions/${s(e)}`)}list(e){return this.client.get("/async-actions",e)}};import Le from"form-data";var F=class{constructor(e){this.client=e}examine(e={},t){return this.client.post("/campaigns/qualification",e,t)}},C=class{constructor(e){this.client=e;l(this,"qualifications");this.qualifications=new F(this.client)}create(e){return this.client.post("/campaigns",e)}update(e,t){return this.client.put(`/campaigns/${s(e)}`,t)}get(e){return this.client.get(`/campaigns/${s(e)}`)}delete(e,t={}){return this.client.delete(`/campaigns/${s(e)}`,t)}addVoucher(e,t={},r={}){return this.client.post(`/campaigns/${s(e)}/vouchers`,t,r)}addCertainVoucher(e,t,r={}){return this.client.post(`/campaigns/${s(e)}/vouchers/${s(t)}`,r)}importVouchers(e,t){return this.client.post(`/campaigns/${s(e)}/import`,t)}list(e={}){return this.client.get("/campaigns",e)}async importVouchersCSV(e,t){a(p().startsWith("Node"),'Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment');let o=(await import("fs")).default.createReadStream(t),n=new Le;n.append("file",o);let c={"Content-Type":"multipart/form-data"};return this.client.post(`/campaigns/${e}/importCSV`,n,void 0,c)}enable(e){return this.client.post(`/campaigns/${s(e)}/enable`,{})}disable(e){return this.client.post(`/campaigns/${s(e)}/disable`,{})}};var X=class{constructor(e){this.client=e}list(e={}){return this.client.get("/publications",e)}create(e){return this.client.post("/publications",e)}},P=class{constructor(e,t){this.client=e;this.exports=t;l(this,"publications");this.publications=new X(this.client)}};var S=class{constructor(e){this.client=e}create(e){return this.client.post("/exports",e)}list(e={}){return this.client.get("/exports",e)}get(e){return this.client.get(`/exports/${s(e)}`)}delete(e){return this.client.delete(`/exports/${s(e)}`)}};var L=class{constructor(e){this.client=e}create(e,t){return t={...t,event:e},this.client.post("/events",t)}};var _=class{constructor(e){this.client=e}create(e,t){return this.client.post(`/vouchers/${s(e)}/balance`,t)}};import _e from"form-data";var K=class{constructor(e){this.client=e}examine(e,t={}){return this.client.post("/vouchers/qualification",e,t)}},A=class{constructor(e,t){this.client=e;this.balance=t;l(this,"qualifications");this.qualifications=new K(this.client)}create(e){return this.client.post(`/vouchers/${s(e.code)}`,e)}get(e){return this.client.get(`/vouchers/${s(e)}`)}update(e){return this.client.put(`/vouchers/${s(e.code)}`,e)}delete(e,t={}){return this.client.delete(`/vouchers/${s(e)}`,t)}list(e={}){return this.client.get("/vouchers",e)}enable(e){return this.client.post(`/vouchers/${s(e)}/enable`,{})}disable(e){return this.client.post(`/vouchers/${s(e)}/disable`,{})}import(e){return this.client.post("/vouchers/import",e)}bulkUpdateMetadata(e){return this.client.post("/vouchers/metadata/async",e)}bulkUpdate(e){return this.client.post("/vouchers/bulk/async",e)}releaseValidationSession(e,t){return this.client.delete(`/vouchers/${s(e)}/sessions/${s(t)}`)}async importCSV(e){a(p().startsWith("Node"),'Method "client.vouchers.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new _e;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/vouchers/importCSV",o,void 0,n)}listTransactions(e,t){return this.client.get(`/vouchers/${s(e)}/transactions`,t)}exportTransactions(e,t){return this.client.post(`/vouchers/${s(e)}/transactions/export`,t)}};var x=class{constructor(e,t){this.client=e;this.promotions=t}validateVoucher(e,t={}){return this.client.post(`/vouchers/${s(e)}/validate`,t)}validate(e,t={}){return d(e)?this.promotions.validate(e):this.validateVoucher(e,t)}validateStackable(e){return this.client.post("/validations",e)}};var $=class{constructor(e){this.client=e}redeem(e,t={}){return this.client.post(`/vouchers/${s(e)}/redemption`,t)}redeemStackable(e){return this.client.post("/redemptions",e)}get(e){return this.client.get(`/redemptions/${s(e)}`)}list(e={}){return this.client.get("/redemptions",e)}getForVoucher(e){return this.client.get(`/vouchers/${s(e)}/redemption`)}rollback(e,t){let r={},o={};if(u(t))r.reason=t;else if(d(t)){let{reason:n,tracking_id:c,customer:g}=t;r={reason:n||void 0,tracking_id:c||void 0},o={customer:g}}return this.client.post(`/redemptions/${s(e)}/rollback`,o,r)}rollbackStackable(e,t,r){return this.client.post(`/redemptions/${s(e)}/rollbacks`,t,r)}};var v=class{constructor(e){this.client=e}listAll(e={}){return this.client.get("/promotions/tiers",e)}list(e){return this.client.get(`/promotions/${s(e)}/tiers`)}get(e){return this.client.get(`/promotions/tiers/${s(e)}`)}create(e,t){return this.client.post(`/promotions/${s(e)}/tiers`,t)}redeem(e,t){return this.client.post(`/promotions/tiers/${s(e)}/redemption`,t)}update(e){return this.client.put(`/promotions/tiers/${s(e.id)}`,e)}delete(e){return this.client.delete(`/promotions/tiers/${s(e)}`)}};var V=class{constructor(e,t,r){this.client=e;this.tiers=t;this.stack=r}create(e){return this.client.post("/campaigns",e)}validate(e,t){return this.client.post("/promotions/validation",e,t)}};import Ae from"form-data";var q=class{constructor(e){this.client=e}create(e){return this.client.post("/customers",e)}get(e){return this.client.get(`/customers/${s(e)}`)}list(e){return this.client.get("/customers",e)}async*scroll(e){var o;let t=(o=e.starting_after)!=null?o:e.order==="created_at"?"1970-01-01T00:00:00Z":"2200-01-01T00:00:00Z",r=await this.client.get("/customers",Object.assign({},e,{starting_after:t}));for(;r.customers.length!==0;){for(let n of r.customers)e.order==="created_at"?t=t>n.created_at?t:n.created_at:t=t<n.created_at?t:n.created_at,yield n;if(!r.has_more)break;r=await this.client.get("/customers",Object.assign({},e,{starting_after:t}))}}update(e){let t="id"in e?e.id:e.source_id,r=m(e,["id"]);return this.client.put(`/customers/${s(t)}`,r)}updateInBulk(e){return this.client.post("/customers/bulk/async",e)}updateMetadataInBulk(e){return this.client.post("/customers/metadata/async",e)}delete(e){return this.client.delete(`/customers/${s(e)}`)}deletePermanently(e){return this.client.post(`/customers/${s(e)}/permanent-deletion`,{})}listActivity(e,t){return this.client.get(`/customers/${s(e)}/activity`,t)}updateConsents(e,t){return this.client.put(`/customers/${s(e)}/consents`,t)}listActivities(e,t){return this.client.get(`/customers/${s(e)}/activities`,t)}async importCSV(e){a(p().startsWith("Node"),'Method "client.customers.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new Ae;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/customers/importCSV",o,void 0,n)}listRedeemables(e,t){return this.client.get(`/customers/${s(e)}/redeemables`,t)}};var k=class{constructor(e){this.client=e}list(){return this.client.get("/consents")}};var w=class{constructor(e){this.client=e}create(e){return this.client.post("/orders",e)}get(e){return this.client.get(`/orders/${s(e)}`)}update(e){return this.client.put(`/orders/${s(e.id||e.source_id)}`,m(e,["id"]))}list(e={}){return this.client.get("/orders",e)}import(e){return this.client.post("/orders/import",e)}};import te from"form-data";var E=class{constructor(e){this.client=e}create(e){return this.client.post("/products",e)}get(e){return this.client.get(`/products/${s(e)}`)}update(e){return this.client.put(`/products/${s(e.id||e.source_id)}`,m(e,["id"]))}bulkUpdateMetadata(e){return this.client.post("/products/metadata/async",e)}bulkUpdate(e){return this.client.post("/products/bulk/async",e)}delete(e,t){return this.client.delete(`/products/${s(e)}`,t)}list(e){return this.client.get("/products",e)}createSku(e,t){return this.client.post(`/products/${s(e)}/skus`,t)}getSku(e){return this.client.get(`/skus/${s(e)}`)}updateSku(e,t){return this.client.put(`/products/${s(e)}/skus/${s(t.id||t.source_id)}`,m(t,["id"]))}deleteSku(e,t,r){return this.client.delete(`/products/${s(e)}/skus/${s(t)}`,r)}listSkus(e){return this.client.get(`/products/${s(e)}/skus`)}async importSkusCSV(e){a(p().startsWith("Node"),'Method "client.products.importSkusCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new te;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/skus/importCSV",o,void 0,n)}async importCSV(e){a(p().startsWith("Node"),'Method "client.products.importCSV(filePath)" is only for Node environment');let r=(await import("fs")).default.createReadStream(e),o=new te;o.append("file",r);let n={"Content-Type":"multipart/form-data"};return this.client.post("/products/importCSV",o,void 0,n)}};var U=class{constructor(e){this.client=e}list(e={}){return this.client.get("/rewards",e)}create(e){return this.client.post("/rewards",e)}get(e){return this.client.get(`/rewards/${s(e)}`)}update(e){return this.client.put(`/rewards/${s(e.id)}`,m(e,["id"]))}delete(e){return this.client.delete(`/rewards/${s(e)}`)}getAssignment(e,t){return this.client.get(`/rewards/${s(e)}/assignments/${s(t)}`)}listAssignments(e,t={}){return this.client.get(`/rewards/${s(e)}/assignments`,t)}createAssignment(e,t){return this.client.post(`/rewards/${s(e)}/assignments`,t)}updateAssignment(e,t){return this.client.put(`/rewards/${s(e)}/assignments/${s(t.id)}`,m(t,["id"]))}deleteAssignment(e,t){return this.client.delete(`/rewards/${s(e)}/assignments/${s(t)}`)}};var B=class{constructor(e){this.client=e}list(e={}){return this.client.get("/loyalties",e)}create(e){return this.client.post("/loyalties",e)}get(e){return this.client.get(`/loyalties/${s(e)}`)}update(e){return this.client.put(`/loyalties/${s(e.id)}`,m(e,["id"]))}delete(e,t){return this.client.delete(`/loyalties/${s(e)}`,t)}listRewardAssignments(e,t={}){return this.client.get(`/loyalties/${s(e)}/rewards`,t)}createRewardAssignments(e,t){return this.client.post(`/loyalties/${s(e)}/rewards`,t)}updateRewardAssignment(e,t){return this.client.put(`/loyalties/${s(e)}/rewards/${t.id}`,m(t,["id"]))}deleteRewardAssignment(e,t){return this.client.delete(`/loyalties/${s(e)}/rewards/${t}`)}getRewardAssignment(e,t){return this.client.get(`/loyalties/${s(e)}/rewards/${s(t)}`)}listEarningRules(e,t={}){return this.client.get(`/loyalties/${s(e)}/earning-rules`,t)}createEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules`,t)}updateEarningRule(e,t){return this.client.put(`/loyalties/${s(e)}/earning-rules/${t.id}`,m(t,["id"]))}deleteEarningRule(e,t){return this.client.delete(`/loyalties/${s(e)}/earning-rules/${t}`)}getEarningRule(e,t){return this.client.get(`/loyalties/${s(e)}/earning-rules/${s(t)}`)}enableEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules/${t}/enable`,{})}disableEarningRule(e,t){return this.client.post(`/loyalties/${s(e)}/earning-rules/${t}/disable`,{})}listMembers(e,t){return this.client.get(`/loyalties/${s(e)}/members`,t)}createMember(e,t){return this.client.post(`/loyalties/${s(e)}/members`,t)}getMember(e,t){return this.client.get(e?`/loyalties/${s(e)}/members/${t}`:`/loyalties/members/${t}`)}listMemberActivity(e,t,r){return this.client.get(e?`/loyalties/${s(e)}/members/${t}/activity`:`/loyalties/members/${t}/activity`,r)}getMemberActivities(e,t){return this.client.get(e?`/loyalties/${s(e)}/members/${t}/activities`:`/loyalties/members/${t}/activities`)}listMemberRewards(e,t){return this.client.get(`/loyalties/members/${s(e)}/rewards`,t)}addOrRemoveCardBalance(e,t,r){return this.client.post(r?`/loyalties/${s(r)}/members/${e}/balance`:`/loyalties/members/${e}/balance`,t)}addPoints(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${t}/balance`,r)}transferPoints(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${s(t)}/transfers`,r)}getPointsExpiration(e,t,r){return this.client.get(`/loyalties/${s(e)}/members/${t}/points-expiration`,r)}redeemReward(e,t,r){return this.client.post(`/loyalties/${s(e)}/members/${s(t)}/redemption`,r)}listLoyaltyTierRewards(e,t){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}/rewards`)}listCardTransactions(e,t,r){return this.client.get(t?`/loyalties/${s(t)}/members/${s(e)}/transactions`:`/loyalties/members/${s(e)}/transactions`,r)}exportCardTransactions(e,t,r={}){return this.client.post(t?`/loyalties/${s(t)}/members/${s(e)}/transactions/export`:`/loyalties/members/${s(e)}/transactions/export`,r)}getRewardDetails(e,t){return this.client.get(`/loyalties/${s(e)}/reward-assignments/${s(t)}/reward`)}listTiers(e,t){return this.client.get(`/loyalties/${s(e)}/tiers`,t)}getTier(e,t){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}`)}createTiers(e,t){return this.client.post(`/loyalties/${s(e)}/tiers`,t)}listLoyaltyTierEarningRules(e,t,r){return this.client.get(`/loyalties/${s(e)}/tiers/${s(t)}/earning-rules`,r)}listMemberLoyaltyTiers(e){return this.client.get(`/loyalties/members/${s(e)}/tiers`)}};var D=class{constructor(e){this.client=e}create(e){return this.client.post("/validation-rules",e)}get(e){return this.client.get(`/validation-rules/${s(e)}`)}update(e){return this.client.put(`/validation-rules/${s(e.id)}`,m(e,["id"]))}delete(e){return this.client.delete(`/validation-rules/${s(e)}`)}createAssignment(e,t){return this.client.post(`/validation-rules/${s(e)}/assignments`,t)}deleteAssignment(e,t){return this.client.delete(`/validation-rules/${s(e)}/assignments/${s(t)}`)}validate(e,t={}){return this.client.post(`/validation-rules/${s(e)}/validation`,t)}list(e={}){return this.client.get("/validation-rules",e)}listRulesAssignments(e={}){return this.client.get("/validation-rules-assignments",e)}listAssignments(e,t={}){return this.client.get(`/validation-rules/${s(e)}/assignments`,t)}};var I=class{constructor(e){this.client=e}create(e){return this.client.post("/segments",e)}get(e){return this.client.get(`/segments/${s(e)}`)}delete(e){return this.client.delete(`/segments/${s(e)}`)}list(e){return this.client.get(`/customers/${s(e)}/segments`)}};var O=class{constructor(e){this.requestController=e}getLastResponseHeadersFromController(){return this.requestController.getLastResponseHeaders()}areLimitsAvailable(){return this.requestController.isLastReponseHeadersSet()}getRateLimit(){var t;let e=(t=this.getLastResponseHeadersFromController()["x-rate-limit-limit"])!=null?t:0;return parseInt(e,10)}getRateLimitRemaining(){var t;let e=(t=this.getLastResponseHeadersFromController()["x-rate-limit-remaining"])!=null?t:0;return parseInt(e,10)}getRetryAfter(){var t;let e=(t=this.getLastResponseHeadersFromController()["retry-after"])!=null?t:0;return parseInt(e,10)}};var M=class{constructor(e){this.client=e}list(){return this.client.get("/metadata-schemas")}get(e){return this.client.get(`/metadata-schemas/${s(e)}`)}};var N=class{constructor(e){this.client=e}list(e={}){return this.client.get("/categories",e)}create(e){return this.client.post("/categories",e)}get(e){return this.client.get(`/categories/${s(e)}`)}delete(e){return this.client.delete(`/categories/${s(e)}`)}update(e,t){return this.client.put(`/categories/${s(e)}`,t)}};var j=class{constructor(e){this.client=e}listInCampaign(e){return this.client.get(`/promotions/${e}/stacks`)}createInCampaign(e,t){return this.client.post(`/promotions/${e}/stacks`,t)}delete(e,t){return this.client.delete(`/promotions/${e}/stacks/${t}`)}get(e,t){return this.client.get(`/promotions/${e}/stacks/${t}`)}update(e,t,r){return this.client.put(`/promotions/${e}/stacks/${t}`,r)}list(e){return this.client.get("/promotions/stacks",e)}};var Q=class{constructor(e){this.client=e}create(e){return this.client.post("/product-collections",e)}list(e){return this.client.get("/product-collections",e)}delete(e){return this.client.delete(`/product-collections/${s(e)}`)}get(e){return this.client.get(`/product-collections/${s(e)}`)}listProducts(e,t){return this.client.get(`/product-collections/${s(e)}/products`,t)}};var H=class{constructor(e){this.client=e}checkEligibility(e){return this.client.post("/qualifications",e)}};function cs(i){var z,J,Z;a(d(i),'VoucherifyServerSide: the "options" argument must be an object'),a(u(i.applicationId),'VoucherifyServerSide: "options.applicationId" is required'),a(u(i.secretKey),'VoucherifyServerSide: "options.secretKey" is required'),a(T(i.apiVersion),'VoucherifyServerSide: expected "options.apiVersion" to be a string'),a(T(i.channel),'VoucherifyServerSide: expected "options.channel" to be a string');let e={"X-App-Id":i.applicationId,"X-App-Token":i.secretKey,"X-Voucherify-Channel":i.channel||`${p()}-SDK-v2.9.3`,"Content-Type":"application/json"};i.apiVersion&&(e["X-Voucherify-API-Version"]=i.apiVersion),d(i.customHeaders)&&(e=Object.assign({},e,i.customHeaders)),p().startsWith("Node")||a(i.dangerouslySetSecretKeyInBrowser===!0,`VoucherifyServerSide: you're exposing your secretKey to a ${p().toLowerCase()} environment. This is generally considered a bad practice. Did you mean to use 'VoucherifyClientSide'?`);let t=new y({basePath:"v1",baseURL:(z=i.apiUrl)!=null?z:"https://api.voucherify.io",headers:e,exposeErrorCause:(J=i.exposeErrorCause)!=null?J:!1,timeoutMs:(Z=i.timeoutMs)!=null?Z:0}),r=new b(t),o=new _(t),n=new A(t,o),c=new C(t),g=new N(t),R=new S(t),h=new L(t),se=new P(t,R),re=new v(t),ie=new j(t),W=new V(t,re,ie),oe=new x(t,W),ne=new $(t),ae=new H(t),le=new q(t),ce=new k(t),ue=new w(t),pe=new E(t),me=new Q(t),de=new U(t),ge=new B(t),Te=new I(t),Re=new D(t),ye=new O(t),he=new M(t);return{vouchers:n,campaigns:c,categories:g,distributions:se,validations:oe,redemptions:ne,promotions:W,customers:le,consents:ce,orders:ue,products:pe,productCollections:me,qualifications:ae,rewards:de,loyalties:ge,segments:Te,validationRules:Re,events:h,asyncActions:r,apiLimitsHandler:ye,metadataSchemas:he}}var G=class{constructor(e,t){this.client=e;this.trackingId=t}setIdentity(e){this.trackingId=e}validate(e){var o,n;a(d(e)||u(e),'client.validate: expected "params" argument to be an object or a string');let t={};u(e)?t.code=e:(t.code=e.code,t.item=e.items,t.amount=e.amount,t.metadata=e.metadata,t.order={metadata:e.orderMetadata},t.customer=e.customer,t.tracking_id=e.tracking_id||this.trackingId,t.session_type=e.session_type,t.session_key=e.session_key,t.session_ttl=e.session_ttl,t.session_ttl_unit=e.session_ttl_unit),t.code&&(t.code=t.code.replace(/[\r\n\t\f\v]/g,"").trim()),a(Y(t==null?void 0:t.customer),'client.validate: expected "params.customer" to be an object'),a(T((o=t==null?void 0:t.customer)==null?void 0:o.source_id),'client.validate: expected "params.customer.source_id" to be a string'),a(Y((n=t==null?void 0:t.customer)==null?void 0:n.metadata),'client.validate: expected "params.customer.metadata" to be an object');let r=t.code?"/validate":"/promotions/validation";return this.client.get(r,t)}redeem(e,t={}){var r,o;return a(u(e),"client.redeem - please provide a valid Voucher code"),e=e.replace(/[\r\n\t\f\v]/g,"").trim(),t.customer=(r=t.customer)!=null?r:{},t.customer.source_id=(o=t.customer.source_id)!=null?o:this.trackingId,this.client.post("/redeem",t,{code:e})}publish(e,t={},r={}){var n,c,g,R,h;a(d(t),"client.publish - expected payload to be an object");let o={};return o.customer=(n=t.customer)!=null?n:{},o.customer.source_id=(g=(c=t.customer)==null?void 0:c.source_id)!=null?g:this.trackingId,o.channel=(R=t.channel)!=null?R:"Voucherify.js",a(u((h=o.customer)==null?void 0:h.source_id),"client.publish - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),r.campaign=e.replace(/[\r\n\t\f\v]/g,"").trim(),this.client.post("/publish",o,r)}track(e,t,r,o,n){var g,R;a(u(e),"client.track - expected event name to be an string"),a(d(t),"client.track - expected customer to be an object");let c={event:e,metadata:r!=null?r:{},customer:t,referral:o!=null?o:void 0,loyalty:n!=null?n:void 0};return c.customer.source_id=(g=t.source_id)!=null?g:this.trackingId,a(u((R=c.customer)==null?void 0:R.source_id),"client.track - expected payload to contain customer source id or to have tracking id set up by Voucherify client"),this.client.post("/events",c)}listVouchers(e={}){let t={};return t.campaign=e.campaign,t.category=e.category,t.page=e.page,t.limit=e.limit,t.customer=e.customer,t.created_at=e.created_at,t.updated_at=e.updated_at,this.client.get("/vouchers",t)}createCustomer(e,t){return this.client.post("/customers",e,{},t?{"X-Voucherify-Double-Opt-In":!0}:{})}listConsents(){return this.client.get("/consents")}updateConsents(e,t){return this.client.put(`/customers/${s(e)}/consents`,t)}validateStackable(e){return this.client.post("/validations",e)}redeemStackable(e){return this.client.post("/redemptions",e)}qualifications(e){return this.client.post("/qualifications",e)}};function Rs(i){var r,o,n;a(d(i),'VoucherifyCustomer: expected "options" argument to be an object'),a(u(i.clientApplicationId),'VoucherifyCustomer: "options.clientApplicationId" is required'),a(u(i.clientSecretKey),'VoucherifyCustomer: "options.clientSecretKey" is required'),a(T(i.apiUrl),'VoucherifyCustomer: expected "options.baseUrl" to be a string'),a(T(i.trackingId),'VoucherifyCustomer: expected "options.trackingId" to be a string');let e={"X-Client-Application-Id":i.clientApplicationId,"X-Client-Token":i.clientSecretKey,"X-Voucherify-Channel":`${p()}-ClientSide-SDK-v2.9.3`};p().startsWith("Node")&&(a(u(i.origin),'VoucherifyCustomer: "options.origin" is required in Node.js'),e.origin=i.origin),d(i.customHeaders)&&(e=Object.assign({},e,i.customHeaders));let t=new y({basePath:"client/v1",baseURL:(r=i.apiUrl)!=null?r:"https://api.voucherify.io",headers:e,exposeErrorCause:(o=i.exposeErrorCause)!=null?o:!1,timeoutMs:(n=i.timeoutMs)!=null?n:0});return new G(t,i.trackingId)}export{Ce as DiscountVouchersTypesEnum,Rs as VoucherifyClientSide,cs as VoucherifyServerSide};
|
|
2
|
+
//# sourceMappingURL=voucherifysdk.esm.js.map
|