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