@voucherify/sdk 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +1258 -0
  3. package/dist/AsyncActions.d.ts +15 -0
  4. package/dist/Balance.d.ts +12 -0
  5. package/dist/Campaigns.d.ts +45 -0
  6. package/dist/ClientSide.d.ts +40 -0
  7. package/dist/Consents.d.ts +10 -0
  8. package/dist/Customers.d.ts +43 -0
  9. package/dist/Distributions.d.ts +22 -0
  10. package/dist/Events.d.ts +7 -0
  11. package/dist/Exports.d.ts +18 -0
  12. package/dist/Loyalties.d.ts +82 -0
  13. package/dist/Orders.d.ts +22 -0
  14. package/dist/Products.d.ts +54 -0
  15. package/dist/PromotionTiers.d.ts +30 -0
  16. package/dist/Promotions.d.ts +16 -0
  17. package/dist/Redemptions.d.ts +26 -0
  18. package/dist/RequestController.d.ts +20 -0
  19. package/dist/Rewards.d.ts +39 -0
  20. package/dist/Segments.d.ts +22 -0
  21. package/dist/ValidationRules.d.ts +39 -0
  22. package/dist/Validations.d.ts +13 -0
  23. package/dist/VoucherifyClientSide.d.ts +76 -0
  24. package/dist/VoucherifyError.d.ts +6 -0
  25. package/dist/VoucherifyServerSide.d.ts +111 -0
  26. package/dist/Vouchers.d.ts +64 -0
  27. package/dist/helpers.d.ts +19 -0
  28. package/dist/index.d.ts +24 -0
  29. package/dist/types/AsyncActions.d.ts +18 -0
  30. package/dist/types/Balance.d.ts +14 -0
  31. package/dist/types/Campaigns.d.ts +117 -0
  32. package/dist/types/ClientSide.d.ts +135 -0
  33. package/dist/types/Consents.d.ts +33 -0
  34. package/dist/types/Customers.d.ts +113 -0
  35. package/dist/types/Distributions.d.ts +141 -0
  36. package/dist/types/Events.d.ts +17 -0
  37. package/dist/types/Exports.d.ts +30 -0
  38. package/dist/types/Loyalties.d.ts +462 -0
  39. package/dist/types/Orders.d.ts +61 -0
  40. package/dist/types/Products.d.ts +97 -0
  41. package/dist/types/PromotionTiers.d.ts +107 -0
  42. package/dist/types/Promotions.d.ts +90 -0
  43. package/dist/types/Redemptions.d.ts +150 -0
  44. package/dist/types/Rewards.d.ts +114 -0
  45. package/dist/types/Segments.d.ts +32 -0
  46. package/dist/types/ValidationRules.d.ts +74 -0
  47. package/dist/types/Validations.d.ts +66 -0
  48. package/dist/types/Vouchers.d.ts +227 -0
  49. package/dist/types/index.d.ts +19 -0
  50. package/dist/voucherifysdk.esm.js +1567 -0
  51. package/dist/voucherifysdk.esm.js.map +1 -0
  52. package/dist/voucherifysdk.umd.development.js +1578 -0
  53. package/dist/voucherifysdk.umd.development.js.map +1 -0
  54. package/dist/voucherifysdk.umd.production.min.js +2 -0
  55. package/dist/voucherifysdk.umd.production.min.js.map +1 -0
  56. package/package.json +48 -0
@@ -0,0 +1,1578 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('axios'), require('qs')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'axios', 'qs'], factory) :
4
+ (global = global || self, factory(global.VoucherifySDK = {}, global.axios, global.Qs));
5
+ }(this, (function (exports, axios, Qs) { 'use strict';
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
+
10
+ /**
11
+ * @internal
12
+ */
13
+ class VoucherifyError extends Error {
14
+ constructor(statusCode, body) {
15
+ var _body, _body2;
16
+
17
+ body = (_body = body) != null ? _body : {};
18
+ const message = ((_body2 = body) == null ? void 0 : _body2.message) || generateMessage(body, statusCode);
19
+ super(message);
20
+ Object.assign(this, body);
21
+ }
22
+
23
+ }
24
+
25
+ function generateMessage(body, statusCode) {
26
+ body = typeof body === 'string' ? body : JSON.stringify(body, null, 2);
27
+ return `Unexpected status code: ${statusCode} - Details: ${body}`;
28
+ }
29
+
30
+ /**
31
+ * @internal
32
+ */
33
+
34
+ class RequestController {
35
+ constructor({
36
+ basePath,
37
+ baseURL,
38
+ headers
39
+ }) {
40
+ this.baseURL = void 0;
41
+ this.basePath = void 0;
42
+ this.headers = void 0;
43
+ this.request = void 0;
44
+ this.basePath = basePath;
45
+ this.baseURL = baseURL;
46
+ this.headers = headers;
47
+ this.request = axios.create({
48
+ baseURL: `${this.baseURL}/${this.basePath}/`,
49
+ headers: this.headers,
50
+ responseType: 'json'
51
+ });
52
+ this.request.interceptors.response.use(void 0, error => {
53
+ var _error$response;
54
+
55
+ /**
56
+ * Handle any HTTP response error (status code outside of 2xx) as a VoucherifyError
57
+ */
58
+ if (error != null && (_error$response = error.response) != null && _error$response.status) {
59
+ return Promise.reject(new VoucherifyError(error.response.status, error.response.data));
60
+ }
61
+
62
+ return Promise.reject(error);
63
+ });
64
+ }
65
+
66
+ setBaseUrl(baseURL) {
67
+ this.baseURL = baseURL;
68
+ this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
69
+ }
70
+
71
+ async get(path, params) {
72
+ const response = await this.request.get(path, {
73
+ params,
74
+ paramsSerializer: function (params) {
75
+ return Qs.stringify(params, {
76
+ arrayFormat: 'brackets',
77
+ encode: false
78
+ });
79
+ }
80
+ });
81
+ return response.data;
82
+ }
83
+
84
+ async post(path, body, params, headers) {
85
+ const response = await this.request.post(path, body, {
86
+ params,
87
+ headers
88
+ });
89
+ return response.data;
90
+ }
91
+
92
+ async put(path, body, params) {
93
+ const response = await this.request.put(path, body, {
94
+ params
95
+ });
96
+ return response.data;
97
+ }
98
+
99
+ async delete(path, params) {
100
+ const response = await this.request.delete(path, {
101
+ params
102
+ });
103
+ return response.data;
104
+ }
105
+
106
+ }
107
+
108
+ function encode(value = '') {
109
+ return encodeURIComponent(value);
110
+ }
111
+ function isString(value) {
112
+ return typeof value === 'string';
113
+ }
114
+ function isOptionalString(value) {
115
+ return value == null || isString(value);
116
+ }
117
+ function isObject(value) {
118
+ return typeof value === 'object' && !Array.isArray(value) && value !== null;
119
+ }
120
+ function isOptionalObject(value) {
121
+ return value == null || isObject(value);
122
+ }
123
+ function environment() {
124
+ if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
125
+ return 'Browser'; // eslint-disable-next-line no-restricted-globals
126
+ } else if (typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope') {
127
+ return 'WebWorker';
128
+ } else if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) {
129
+ return `Node.js-${process.version}`;
130
+ } else if (typeof window !== 'undefined' && window.name === 'nodejs' || navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom')) {
131
+ return 'JsDom';
132
+ }
133
+
134
+ return 'Unknown';
135
+ }
136
+ function assert(condition, message) {
137
+ if (condition) return;
138
+ throw new Error(message);
139
+ }
140
+ function toQueryParams(obj) {
141
+ const entries = [];
142
+
143
+ function mapToEntries(prefix, record) {
144
+ Object.entries(record).map(([key, val]) => {
145
+ if (val == null) return void 0;
146
+
147
+ switch (typeof val) {
148
+ case 'string':
149
+ case 'number':
150
+ case 'boolean':
151
+ case 'bigint':
152
+ if (prefix) return entries.push([`${prefix}[${key}]`, encode(val.toString())]);
153
+ return entries.push([key, encode(val.toString())]);
154
+
155
+ case 'object':
156
+ if (prefix) return mapToEntries(`${prefix}[${key}]`, val);
157
+ return mapToEntries(key, val);
158
+
159
+ default:
160
+ return void 0;
161
+ }
162
+ });
163
+ }
164
+
165
+ mapToEntries(null, obj);
166
+ return Object.fromEntries(entries);
167
+ }
168
+ /**
169
+ * Return an object containing all properties of `obj` excluding the ones in `keys` array
170
+ * e.g:
171
+ * ```javascript
172
+ * omit({ a: 1, b: 2, c: 3, d: 4 }, ['b', 'd']) // output: { a: 1, c: 3 }
173
+ * ```
174
+ */
175
+
176
+ function omit(obj, keys) {
177
+ return Object.fromEntries(Object.entries(obj).filter(([propertyKey]) => {
178
+ return !keys.includes(propertyKey);
179
+ }));
180
+ }
181
+
182
+ class AsyncActions {
183
+ constructor(client) {
184
+ this.client = void 0;
185
+ this.client = client;
186
+ }
187
+ /**
188
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-async-actions-1
189
+ */
190
+
191
+
192
+ get(asyncActionId) {
193
+ return this.client.get(`/async-actions/${encode(asyncActionId)}`);
194
+ }
195
+ /**
196
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-async-actions
197
+ */
198
+
199
+
200
+ list(params) {
201
+ return this.client.get('/async-actions', params);
202
+ }
203
+
204
+ }
205
+
206
+ class CampaignsQualifications {
207
+ constructor(client) {
208
+ this.client = void 0;
209
+ this.client = client;
210
+ }
211
+
212
+ examine(body = {}, params) {
213
+ return this.client.post('/campaigns/qualification', body, params);
214
+ }
215
+
216
+ }
217
+
218
+ class Campaigns {
219
+ constructor(client) {
220
+ this.client = void 0;
221
+ this.qualifications = void 0;
222
+ this.client = client;
223
+ this.qualifications = new CampaignsQualifications(this.client);
224
+ }
225
+ /**
226
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-campaign
227
+ */
228
+
229
+
230
+ create(campaign) {
231
+ return this.client.post('/campaigns', campaign);
232
+ }
233
+ /**
234
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-campaign
235
+ */
236
+
237
+
238
+ update(nameOrId, campaign) {
239
+ return this.client.put(`/campaigns/${encode(nameOrId)}`, campaign);
240
+ }
241
+ /**
242
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-campaign
243
+ */
244
+
245
+
246
+ get(name) {
247
+ return this.client.get(`/campaigns/${encode(name)}`);
248
+ }
249
+ /**
250
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-campaign
251
+ */
252
+
253
+
254
+ delete(name, params = {}) {
255
+ return this.client.delete(`/campaigns/${encode(name)}`, params);
256
+ }
257
+ /**
258
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-voucher-to-campaign
259
+ */
260
+
261
+
262
+ addVoucher(name, body = {}, params = {}) {
263
+ return this.client.post(`/campaigns/${encode(name)}/vouchers`, body, params);
264
+ }
265
+ /**
266
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-voucher-with-certain-code-to-campaign
267
+ */
268
+
269
+
270
+ addCertainVoucher(name, code, body = {}) {
271
+ return this.client.post(`/campaigns/${encode(name)}/vouchers/${encode(code)}`, body);
272
+ }
273
+ /**
274
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#import-vouchers
275
+ */
276
+
277
+
278
+ importVouchers(campaignName, vouchers) {
279
+ return this.client.post(`/campaigns/${encode(campaignName)}/import`, vouchers);
280
+ }
281
+ /**
282
+ * @see https://docs.voucherify.io/v2017-04-20/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-campaigns
283
+ */
284
+
285
+
286
+ list(params = {}) {
287
+ return this.client.get('/campaigns', params);
288
+ }
289
+
290
+ }
291
+
292
+ class DistributionsPublications {
293
+ constructor(client) {
294
+ this.client = void 0;
295
+ this.client = client;
296
+ }
297
+ /**
298
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-publications
299
+ */
300
+
301
+
302
+ list(params = {}) {
303
+ return this.client.get('/publications', params);
304
+ }
305
+ /**
306
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-publication
307
+ */
308
+
309
+
310
+ create(params) {
311
+ return this.client.post('/publications', params);
312
+ }
313
+
314
+ }
315
+
316
+ class Distributions {
317
+ constructor(client, exports) {
318
+ this.client = void 0;
319
+ this.exports = void 0;
320
+ this.publications = void 0;
321
+ this.client = client;
322
+ this.exports = exports;
323
+ this.publications = new DistributionsPublications(this.client);
324
+ }
325
+
326
+ }
327
+
328
+ class Exports {
329
+ constructor(client) {
330
+ this.client = void 0;
331
+ this.client = client;
332
+ }
333
+ /**
334
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-export
335
+ */
336
+
337
+
338
+ create(exportResource) {
339
+ return this.client.post('/exports', exportResource);
340
+ }
341
+ /**
342
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-export
343
+ */
344
+
345
+
346
+ get(exportResourceId) {
347
+ return this.client.get(`/exports/${encode(exportResourceId)}`);
348
+ }
349
+ /**
350
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-export
351
+ */
352
+
353
+
354
+ delete(exportResourceId) {
355
+ return this.client.delete(`/exports/${encode(exportResourceId)}`);
356
+ }
357
+
358
+ }
359
+
360
+ class Events {
361
+ constructor(client) {
362
+ this.client = void 0;
363
+ this.client = client;
364
+ }
365
+
366
+ create(eventName, params) {
367
+ params = { ...params,
368
+ event: eventName
369
+ };
370
+ return this.client.post('/events', params);
371
+ }
372
+
373
+ }
374
+
375
+ class Balance {
376
+ constructor(client) {
377
+ this.client = void 0;
378
+ this.client = client;
379
+ }
380
+ /**
381
+ * Add Gift Voucher Balance
382
+ * This method gives a possibility to add balance to an existing gift voucher.
383
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq##add-gift-voucher-balance
384
+ */
385
+
386
+
387
+ create(code, params) {
388
+ return this.client.post(`/vouchers/${encode(code)}/balance`, params);
389
+ }
390
+
391
+ }
392
+
393
+ class VouchersQualification {
394
+ constructor(client) {
395
+ this.client = void 0;
396
+ this.client = client;
397
+ }
398
+ /**
399
+ * 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.
400
+ * 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.
401
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#push-qualification-request
402
+ */
403
+
404
+
405
+ examine(body, params = {}) {
406
+ return this.client.post('/vouchers/qualification', body, params);
407
+ }
408
+
409
+ }
410
+
411
+ class Vouchers {
412
+ constructor(client, balance) {
413
+ this.client = void 0;
414
+ this.balance = void 0;
415
+ this.qualifications = void 0;
416
+ this.client = client;
417
+ this.balance = balance;
418
+ this.qualifications = new VouchersQualification(this.client);
419
+ }
420
+ /**
421
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-voucher
422
+ */
423
+
424
+
425
+ create(voucher) {
426
+ return this.client.post(`/vouchers/${encode(voucher.code)}`, voucher);
427
+ }
428
+ /**
429
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-get
430
+ */
431
+
432
+
433
+ get(code) {
434
+ return this.client.get(`/vouchers/${encode(code)}`);
435
+ }
436
+ /**
437
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-voucher
438
+ */
439
+
440
+
441
+ update(voucher) {
442
+ return this.client.put(`/vouchers/${encode(voucher.code)}`, voucher);
443
+ }
444
+ /**
445
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-voucher
446
+ */
447
+
448
+
449
+ delete(code, params = {}) {
450
+ return this.client.delete(`/vouchers/${encode(code)}`, params);
451
+ }
452
+ /**
453
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-vouchers
454
+ */
455
+
456
+
457
+ list(params = {}) {
458
+ return this.client.get('/vouchers', params);
459
+ }
460
+ /**
461
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#enable-voucher
462
+ */
463
+
464
+
465
+ enable(code) {
466
+ return this.client.post(`/vouchers/${encode(code)}/enable`, {});
467
+ }
468
+ /**
469
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#disable-voucher
470
+ */
471
+
472
+
473
+ disable(code) {
474
+ return this.client.post(`/vouchers/${encode(code)}/disable`, {});
475
+ }
476
+ /**
477
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#import-vouchers-1
478
+ */
479
+
480
+
481
+ import(vouchers) {
482
+ return this.client.post('/vouchers/import', vouchers);
483
+ }
484
+ /**
485
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-vouchers-metadata-in-bulk
486
+ */
487
+
488
+
489
+ bulkUpdateMetadata(params) {
490
+ return this.client.post('/vouchers/metadata', params);
491
+ }
492
+ /**
493
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-vouchers-in-bulk
494
+ */
495
+
496
+
497
+ bulkUpdate(vouchers) {
498
+ return this.client.post('/vouchers/bulk', vouchers);
499
+ }
500
+ /**
501
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#release-validation-session
502
+ */
503
+
504
+
505
+ releaseValidationSession(code, sessionKey) {
506
+ return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
507
+ }
508
+
509
+ }
510
+
511
+ class Validations {
512
+ constructor(client, promotions) {
513
+ this.client = void 0;
514
+ this.promotions = void 0;
515
+ this.client = client;
516
+ this.promotions = promotions;
517
+ }
518
+ /**
519
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-voucher
520
+ */
521
+
522
+
523
+ validateVoucher(code, params = {}) {
524
+ return this.client.post(`/vouchers/${encode(code)}/validate`, params);
525
+ }
526
+
527
+ validate(code, context = {}) {
528
+ if (isObject(code)) {
529
+ return this.promotions.validate(code);
530
+ }
531
+
532
+ return this.validateVoucher(code, context);
533
+ }
534
+
535
+ }
536
+
537
+ class Redemptions {
538
+ constructor(client) {
539
+ this.client = void 0;
540
+ this.client = client;
541
+ }
542
+ /**
543
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-voucher
544
+ */
545
+
546
+
547
+ redeem(code, body = {}) {
548
+ return this.client.post(`/vouchers/${encode(code)}/redemption`, body);
549
+ }
550
+ /**
551
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-redemption
552
+ */
553
+
554
+
555
+ get(redemptionId) {
556
+ return this.client.get(`/redemptions/${encode(redemptionId)}`);
557
+ }
558
+ /**
559
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-redemptions
560
+ */
561
+
562
+
563
+ list(params = {}) {
564
+ return this.client.get('/redemptions', params);
565
+ }
566
+ /**
567
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-redemptions
568
+ */
569
+
570
+
571
+ getForVoucher(code) {
572
+ return this.client.get(`/vouchers/${encode(code)}/redemption`);
573
+ }
574
+ /**
575
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#rollback-redemption
576
+ */
577
+
578
+
579
+ rollback(redemptionId, params) {
580
+ let queryParams = {};
581
+ let payload = {};
582
+
583
+ if (isString(params)) {
584
+ queryParams.reason = params;
585
+ } else if (isObject(params)) {
586
+ const {
587
+ reason,
588
+ tracking_id: trackingId,
589
+ customer
590
+ } = params;
591
+ queryParams = {
592
+ reason: reason ? reason : undefined,
593
+ tracking_id: trackingId ? trackingId : undefined
594
+ };
595
+ payload = {
596
+ customer
597
+ };
598
+ }
599
+
600
+ return this.client.post(`/redemptions/${encode(redemptionId)}/rollback`, payload, queryParams);
601
+ }
602
+
603
+ }
604
+
605
+ class PromotionTiers {
606
+ constructor(client) {
607
+ this.client = void 0;
608
+ this.client = client;
609
+ }
610
+ /**
611
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-promotion-tiers
612
+ */
613
+
614
+
615
+ listAll(params = {}) {
616
+ return this.client.get('/promotions/tiers', params);
617
+ }
618
+ /**
619
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-promotions
620
+ */
621
+
622
+
623
+ list(promotionId) {
624
+ return this.client.get(`/promotions/${encode(promotionId)}/tiers`);
625
+ }
626
+ /**
627
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-promotion-tier-to-campaign
628
+ */
629
+
630
+
631
+ create(promotionId, params) {
632
+ return this.client.post(`/promotions/${encode(promotionId)}/tiers`, params);
633
+ }
634
+ /**
635
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-promotion
636
+ */
637
+
638
+
639
+ redeem(promotionsTierId, params) {
640
+ return this.client.post(`/promotions/tiers/${encode(promotionsTierId)}/redemption`, params);
641
+ }
642
+ /**
643
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion
644
+ */
645
+
646
+
647
+ update(params) {
648
+ return this.client.put(`/promotions/tiers/${encode(params.id)}`, params);
649
+ }
650
+ /**
651
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-promotion
652
+ */
653
+
654
+
655
+ delete(promotionsTierId) {
656
+ return this.client.delete(`/promotions/tiers/${encode(promotionsTierId)}`);
657
+ }
658
+
659
+ }
660
+
661
+ class Promotions {
662
+ constructor(client, tiers) {
663
+ this.client = void 0;
664
+ this.tiers = void 0;
665
+ this.client = client;
666
+ this.tiers = tiers;
667
+ }
668
+ /**
669
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-promotion-campaign
670
+ */
671
+
672
+
673
+ create(promotionCampaign) {
674
+ return this.client.post('/campaigns', promotionCampaign);
675
+ }
676
+ /**
677
+ * @see http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-promotions-1
678
+ */
679
+
680
+
681
+ validate(params) {
682
+ return this.client.post('/promotions/validation', params);
683
+ }
684
+
685
+ }
686
+
687
+ class Customers {
688
+ constructor(client) {
689
+ this.client = void 0;
690
+ this.client = client;
691
+ }
692
+ /**
693
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-customer
694
+ */
695
+
696
+
697
+ create(customer) {
698
+ return this.client.post('/customers', customer);
699
+ }
700
+ /**
701
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#read-customer
702
+ */
703
+
704
+
705
+ get(customerId) {
706
+ return this.client.get(`/customers/${encode(customerId)}`);
707
+ }
708
+ /**
709
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-customers
710
+ */
711
+
712
+
713
+ list(params) {
714
+ return this.client.get('/customers', params);
715
+ }
716
+ /**
717
+ * 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.
718
+ *
719
+ * ```javascript
720
+ * async function () {
721
+ * for await (const customer of voucherify.customers.scroll(params)) {
722
+ * console.log('Customer', customer)
723
+ * }
724
+ * }
725
+ * ```
726
+ */
727
+
728
+
729
+ async *scroll(params) {
730
+ var _params$starting_afte;
731
+
732
+ 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';
733
+ let response = await this.client.get('/customers', Object.assign({}, params, {
734
+ starting_after: startingAfter
735
+ }));
736
+
737
+ while (true) {
738
+ if (response.customers.length === 0) break;
739
+
740
+ for (const customer of response.customers) {
741
+ if (params.order === 'created_at') {
742
+ startingAfter = startingAfter > customer.created_at ? startingAfter : customer.created_at;
743
+ } else {
744
+ startingAfter = startingAfter < customer.created_at ? startingAfter : customer.created_at;
745
+ }
746
+
747
+ yield customer;
748
+ }
749
+
750
+ if (!response.has_more) break;
751
+ response = await this.client.get('/customers', Object.assign({}, params, {
752
+ starting_after: startingAfter
753
+ }));
754
+ }
755
+ }
756
+ /**
757
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-customer
758
+ */
759
+
760
+
761
+ update(customer) {
762
+ const id = 'id' in customer ? customer.id : customer.source_id;
763
+ const customerWithoutId = omit(customer, ['id']);
764
+ return this.client.put(`/customers/${encode(id)}`, customerWithoutId);
765
+ }
766
+ /**
767
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-customer
768
+ */
769
+
770
+
771
+ delete(customerId) {
772
+ return this.client.delete(`/customers/${encode(customerId)}`);
773
+ }
774
+ /**
775
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-customers-consents
776
+ */
777
+
778
+
779
+ updateConsents(idOrSourceId, consents) {
780
+ return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
781
+ }
782
+
783
+ }
784
+
785
+ class Consents {
786
+ constructor(client) {
787
+ this.client = void 0;
788
+ this.client = client;
789
+ }
790
+ /**
791
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-consents
792
+ */
793
+
794
+
795
+ list() {
796
+ return this.client.get('/consents');
797
+ }
798
+
799
+ }
800
+
801
+ class Orders {
802
+ constructor(client) {
803
+ this.client = void 0;
804
+ this.client = client;
805
+ }
806
+ /**
807
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-order
808
+ */
809
+
810
+
811
+ create(order) {
812
+ return this.client.post('/orders', order);
813
+ }
814
+ /**
815
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-order
816
+ */
817
+
818
+
819
+ get(orderId) {
820
+ return this.client.get(`/orders/${encode(orderId)}`);
821
+ }
822
+ /**
823
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-order
824
+ */
825
+
826
+
827
+ update(order) {
828
+ return this.client.put(`/orders/${encode(order.id || order.source_id)}`, omit(order, ['id']));
829
+ }
830
+ /**
831
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-orders
832
+ */
833
+
834
+
835
+ list(params = {}) {
836
+ return this.client.get('/orders', params);
837
+ }
838
+
839
+ }
840
+
841
+ class Products {
842
+ constructor(client) {
843
+ this.client = void 0;
844
+ this.client = client;
845
+ }
846
+ /**
847
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-product
848
+ */
849
+
850
+
851
+ create(product) {
852
+ return this.client.post('/products', product);
853
+ }
854
+ /**
855
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-product
856
+ */
857
+
858
+
859
+ get(productId) {
860
+ return this.client.get(`/products/${encode(productId)}`);
861
+ }
862
+ /**
863
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-product
864
+ */
865
+
866
+
867
+ update(product) {
868
+ return this.client.put(`/products/${encode(product.id || product.source_id)}`, omit(product, ['id']));
869
+ }
870
+ /**
871
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-products-metadata-in-bulk
872
+ */
873
+
874
+
875
+ bulkMetadataUpdate(products) {
876
+ return this.client.post('/products/metadata', products);
877
+ }
878
+ /**
879
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-products-in-bulk
880
+ */
881
+
882
+
883
+ bulkUpdate(products) {
884
+ return this.client.post('/products/bulk', products);
885
+ }
886
+ /**
887
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-product
888
+ */
889
+
890
+
891
+ delete(productId, params) {
892
+ return this.client.delete(`/products/${encode(productId)}`, params);
893
+ }
894
+ /**
895
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-products
896
+ */
897
+
898
+
899
+ list(params) {
900
+ return this.client.get('/products', params);
901
+ }
902
+ /**
903
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-sku
904
+ */
905
+
906
+
907
+ createSku(productId, sku) {
908
+ return this.client.post(`/products/${encode(productId)}/skus`, sku);
909
+ }
910
+ /**
911
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-sku
912
+ */
913
+
914
+
915
+ getSku(productId, skuId) {
916
+ return this.client.get(`/products/${encode(productId)}/skus/${encode(skuId)}`);
917
+ }
918
+ /**
919
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-sku
920
+ */
921
+
922
+
923
+ updateSku(productId, sku) {
924
+ return this.client.put(`/products/${encode(productId)}/skus/${encode(sku.id || sku.source_id)}`, omit(sku, ['id']));
925
+ }
926
+ /**
927
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-sku
928
+ */
929
+
930
+
931
+ deleteSku(productId, skuId, params) {
932
+ return this.client.delete(`/products/${encode(productId)}/skus/${encode(skuId)}`, params);
933
+ }
934
+ /**
935
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-skus
936
+ */
937
+
938
+
939
+ listSkus(productId) {
940
+ return this.client.get(`/products/${encode(productId)}/skus`);
941
+ }
942
+
943
+ }
944
+
945
+ class Rewards {
946
+ constructor(client) {
947
+ this.client = void 0;
948
+ this.client = client;
949
+ }
950
+ /**
951
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-rewards
952
+ */
953
+
954
+
955
+ list(params = {}) {
956
+ return this.client.get('/rewards', params);
957
+ }
958
+ /**
959
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-reward
960
+ */
961
+
962
+
963
+ create(reward) {
964
+ return this.client.post('/rewards', reward);
965
+ }
966
+ /**
967
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-reward
968
+ */
969
+
970
+
971
+ get(rewardId) {
972
+ return this.client.get(`/rewards/${encode(rewardId)}`);
973
+ }
974
+ /**
975
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-reward
976
+ */
977
+
978
+
979
+ update(reward) {
980
+ return this.client.put(`/rewards/${encode(reward.id)}`, omit(reward, ['id']));
981
+ }
982
+ /**
983
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-reward
984
+ */
985
+
986
+
987
+ delete(rewardId) {
988
+ return this.client.delete(`/rewards/${encode(rewardId)}`);
989
+ }
990
+ /**
991
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-reward-assignments
992
+ */
993
+
994
+
995
+ listAssignments(rewardId, params = {}) {
996
+ return this.client.get(`/rewards/${encode(rewardId)}/assignments`, params);
997
+ }
998
+ /**
999
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-reward-assignment
1000
+ */
1001
+
1002
+
1003
+ createAssignment(rewardId, assignment) {
1004
+ return this.client.post(`/rewards/${encode(rewardId)}/assignments`, assignment);
1005
+ }
1006
+ /**
1007
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-reward-assignment
1008
+ */
1009
+
1010
+
1011
+ updateAssignment(rewardId, assignment) {
1012
+ return this.client.put(`/rewards/${encode(rewardId)}/assignments/${encode(assignment.id)}`, omit(assignment, ['id']));
1013
+ }
1014
+
1015
+ deleteAssignment(rewardId, assignmentId) {
1016
+ return this.client.delete(`/rewards/${encode(rewardId)}/assignments/${encode(assignmentId)}`);
1017
+ }
1018
+
1019
+ }
1020
+
1021
+ class Loyalties {
1022
+ constructor(client) {
1023
+ this.client = void 0;
1024
+ this.client = client;
1025
+ }
1026
+ /**
1027
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-loyalty-programs
1028
+ */
1029
+
1030
+
1031
+ list(params = {}) {
1032
+ return this.client.get('/loyalties', params);
1033
+ }
1034
+ /**
1035
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-loyalty-program
1036
+ */
1037
+
1038
+
1039
+ create(campaign) {
1040
+ return this.client.post('/loyalties', campaign);
1041
+ }
1042
+ /**
1043
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-loyalty-program
1044
+ */
1045
+
1046
+
1047
+ get(campaignId) {
1048
+ return this.client.get(`/loyalties/${encode(campaignId)}`);
1049
+ }
1050
+ /**
1051
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-loyalty-program
1052
+ */
1053
+
1054
+
1055
+ update(campaign) {
1056
+ return this.client.put(`/loyalties/${encode(campaign.id)}`, omit(campaign, ['id']));
1057
+ }
1058
+ /**
1059
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-loyalty-program
1060
+ */
1061
+
1062
+
1063
+ delete(campaignId, params) {
1064
+ return this.client.delete(`/loyalties/${encode(campaignId)}`, params);
1065
+ }
1066
+ /**
1067
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-reward-assignments-1
1068
+ */
1069
+
1070
+
1071
+ listRewardAssignments(campaignId, params = {}) {
1072
+ return this.client.get(`/loyalties/${encode(campaignId)}/rewards`, params);
1073
+ }
1074
+ /**
1075
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-reward-assignment-1
1076
+ */
1077
+
1078
+
1079
+ createRewardAssignments(campaignId, assignment) {
1080
+ return this.client.post(`/loyalties/${encode(campaignId)}/rewards`, assignment);
1081
+ }
1082
+ /**
1083
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-reward-assignment-1
1084
+ */
1085
+
1086
+
1087
+ updateRewardAssignment(campaignId, assignment) {
1088
+ return this.client.put(`/loyalties/${encode(campaignId)}/rewards/${assignment.id}`, omit(assignment, ['id']));
1089
+ }
1090
+ /**
1091
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-reward-assignment-1
1092
+ */
1093
+
1094
+
1095
+ deleteRewardAssignment(campaignId, assignmentId) {
1096
+ return this.client.delete(`/loyalties/${encode(campaignId)}/rewards/${assignmentId}`);
1097
+ }
1098
+ /**
1099
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-earning-rules
1100
+ */
1101
+
1102
+
1103
+ listEarningRules(campaignId, params = {}) {
1104
+ return this.client.get(`/loyalties/${encode(campaignId)}/earning-rules`, params);
1105
+ }
1106
+ /**
1107
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-earning-rule
1108
+ */
1109
+
1110
+
1111
+ createEarningRule(campaignId, earningRules) {
1112
+ return this.client.post(`/loyalties/${encode(campaignId)}/earning-rules`, earningRules);
1113
+ }
1114
+ /**
1115
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-earning-rule
1116
+ */
1117
+
1118
+
1119
+ updateEarningRule(campaignId, earningRule) {
1120
+ return this.client.put(`/loyalties/${encode(campaignId)}/earning-rules/${earningRule.id}`, omit(earningRule, ['id']));
1121
+ }
1122
+ /**
1123
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-earning-rule
1124
+ */
1125
+
1126
+
1127
+ deleteEarningRule(campaignId, earningRuleId) {
1128
+ return this.client.delete(`/loyalties/${encode(campaignId)}/earning-rules/${earningRuleId}`);
1129
+ }
1130
+ /**
1131
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-members
1132
+ */
1133
+
1134
+
1135
+ listMembers(campaignId, params) {
1136
+ return this.client.get(`/loyalties/${encode(campaignId)}/members`, params);
1137
+ }
1138
+ /**
1139
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-member
1140
+ */
1141
+
1142
+
1143
+ createMember(campaignId, member) {
1144
+ return this.client.post(`/loyalties/${encode(campaignId)}/members`, member);
1145
+ }
1146
+ /**
1147
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-member
1148
+ */
1149
+
1150
+
1151
+ getMember(campaignId, memberId) {
1152
+ return this.client.get(`/loyalties/${encode(campaignId)}/members/${memberId}`);
1153
+ }
1154
+ /**
1155
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-member-activities
1156
+ */
1157
+
1158
+
1159
+ getMemberActivities(campaignId, memberId) {
1160
+ return this.client.get(`/loyalties/${encode(campaignId)}/members/${memberId}/activities`);
1161
+ }
1162
+ /**
1163
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-loyalty-card-balance
1164
+ */
1165
+
1166
+
1167
+ addPoints(campaignId, memberId, balance) {
1168
+ return this.client.post(`/loyalties/${encode(campaignId)}/members/${memberId}/balance`, balance);
1169
+ }
1170
+ /**
1171
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-loyalty-card
1172
+ */
1173
+
1174
+
1175
+ redeemReward(campaignId, memberId, params) {
1176
+ return this.client.post(`/loyalties/${encode(campaignId)}/members/${encode(memberId)}/redemption`, params);
1177
+ }
1178
+
1179
+ }
1180
+
1181
+ class ValidationRules {
1182
+ constructor(client) {
1183
+ this.client = void 0;
1184
+ this.client = client;
1185
+ }
1186
+ /**
1187
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-validation-rules
1188
+ */
1189
+
1190
+
1191
+ create(validationRule) {
1192
+ return this.client.post('/validation-rules', validationRule);
1193
+ }
1194
+ /**
1195
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-validation-rules
1196
+ */
1197
+
1198
+
1199
+ get(validationRuleId) {
1200
+ return this.client.get(`/validation-rules/${encode(validationRuleId)}`);
1201
+ }
1202
+ /**
1203
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-validation-rules
1204
+ */
1205
+
1206
+
1207
+ update(validationRule) {
1208
+ return this.client.put(`/validation-rules/${encode(validationRule.id)}`, omit(validationRule, ['id']));
1209
+ }
1210
+ /**
1211
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-validation-rules
1212
+ */
1213
+
1214
+
1215
+ delete(validationRuleId) {
1216
+ return this.client.delete(`/validation-rules/${encode(validationRuleId)}`);
1217
+ }
1218
+ /**
1219
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-validation-rules-assignment
1220
+ */
1221
+
1222
+
1223
+ createAssignment(validationRuleId, assignment) {
1224
+ return this.client.post(`/validation-rules/${encode(validationRuleId)}/assignments`, assignment);
1225
+ }
1226
+ /**
1227
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-validation-rules-assignment
1228
+ */
1229
+
1230
+
1231
+ deleteAssignment(validationRuleId, assignmentId) {
1232
+ return this.client.delete(`/validation-rules/${encode(validationRuleId)}/assignments/${encode(assignmentId)}`);
1233
+ }
1234
+
1235
+ validate(validationRuleId, params = {}) {
1236
+ return this.client.post(`/validation-rules/${encode(validationRuleId)}/validation`, params);
1237
+ }
1238
+ /**
1239
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-validation-rules
1240
+ */
1241
+
1242
+
1243
+ list(params = {}) {
1244
+ return this.client.get('/validation-rules', params);
1245
+ }
1246
+ /**
1247
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-validation-rule-assignments
1248
+ */
1249
+
1250
+
1251
+ listAssignments(validationRuleId, params = {}) {
1252
+ return this.client.get(`/validation-rules/${encode(validationRuleId)}/assignments`, params);
1253
+ }
1254
+
1255
+ }
1256
+
1257
+ class Segments {
1258
+ constructor(client) {
1259
+ this.client = void 0;
1260
+ this.client = client;
1261
+ }
1262
+ /**
1263
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-segment
1264
+ */
1265
+
1266
+
1267
+ create(segment) {
1268
+ return this.client.post('/segments', segment);
1269
+ }
1270
+ /**
1271
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-segment
1272
+ */
1273
+
1274
+
1275
+ get(segmentId) {
1276
+ return this.client.get(`/segments/${encode(segmentId)}`);
1277
+ }
1278
+ /**
1279
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-segment
1280
+ */
1281
+
1282
+
1283
+ delete(segmentId) {
1284
+ return this.client.delete(`/segments/${encode(segmentId)}`);
1285
+ }
1286
+ /**
1287
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-segments
1288
+ */
1289
+
1290
+
1291
+ list(customerId) {
1292
+ return this.client.get(`/customers/${encode(customerId)}/segments`);
1293
+ }
1294
+
1295
+ }
1296
+
1297
+ // campaigns: Campaigns
1298
+ // consents: Consents
1299
+ // customers: Customers
1300
+ // distributions: Distributions
1301
+ // events: Events
1302
+ // loyalties: Loyalties
1303
+ // orders: Orders
1304
+ // products: Products
1305
+ // promotions: Promotions
1306
+ // redemptions: Redemptions
1307
+ // rewards: Rewards
1308
+ // segments: Segments
1309
+ // validationRules: ValidationRules
1310
+ // validations: Validations
1311
+ // vouchers: Vouchers
1312
+ // }
1313
+
1314
+ function VoucherifyServerSide(options) {
1315
+ var _options$apiUrl;
1316
+
1317
+ assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
1318
+ assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
1319
+ assert(isString(options.secretKey), 'VoucherifyServerSide: "options.secretKey" is required');
1320
+ assert(isOptionalString(options.apiVersion), 'VoucherifyServerSide: expected "options.apiVersion" to be a string');
1321
+ assert(isOptionalString(options.channel), 'VoucherifyServerSide: expected "options.channel" to be a string');
1322
+ let headers = {
1323
+ 'X-App-Id': options.applicationId,
1324
+ 'X-App-Token': options.secretKey,
1325
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"1.2.0"}`,
1326
+ 'Content-Type': 'application/json'
1327
+ };
1328
+
1329
+ if (options.apiVersion) {
1330
+ headers['X-Voucherify-API-Version'] = options.apiVersion;
1331
+ }
1332
+
1333
+ if (isObject(options.customHeaders)) {
1334
+ headers = Object.assign({}, headers, options.customHeaders);
1335
+ }
1336
+ /**
1337
+ * The option `dangerouslySetSecretKeyInBrowser` is explicitly long and not suggested in the thrown error because
1338
+ * we don't want the user to enable this option without going through the documentation and understanding the risks
1339
+ * of exposing a their secretKey
1340
+ */
1341
+
1342
+
1343
+ if (!environment().startsWith('Node')) {
1344
+ 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'?`);
1345
+ }
1346
+
1347
+ const client = new RequestController({
1348
+ basePath: 'v1',
1349
+ baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
1350
+ headers
1351
+ });
1352
+ const asyncActions = new AsyncActions(client);
1353
+ const balance = new Balance(client);
1354
+ const vouchers = new Vouchers(client, balance);
1355
+ const campaigns = new Campaigns(client);
1356
+ const exportsNamespace = new Exports(client);
1357
+ const events = new Events(client);
1358
+ const distributions = new Distributions(client, exportsNamespace);
1359
+ const promotionTiers = new PromotionTiers(client);
1360
+ const promotions = new Promotions(client, promotionTiers);
1361
+ const validations = new Validations(client, promotions);
1362
+ const redemptions = new Redemptions(client);
1363
+ const customers = new Customers(client);
1364
+ const consents = new Consents(client);
1365
+ const orders = new Orders(client);
1366
+ const products = new Products(client);
1367
+ const rewards = new Rewards(client);
1368
+ const loyalties = new Loyalties(client);
1369
+ const segments = new Segments(client);
1370
+ const validationRules = new ValidationRules(client);
1371
+ return {
1372
+ vouchers,
1373
+ campaigns,
1374
+ distributions,
1375
+ validations,
1376
+ redemptions,
1377
+ promotions,
1378
+ customers,
1379
+ consents,
1380
+ orders,
1381
+ products,
1382
+ rewards,
1383
+ loyalties,
1384
+ segments,
1385
+ validationRules,
1386
+ events,
1387
+ asyncActions
1388
+ };
1389
+ }
1390
+
1391
+ class ClientSide {
1392
+ constructor(client, trackingId) {
1393
+ this.client = void 0;
1394
+ this.trackingId = void 0;
1395
+ this.client = client;
1396
+ this.trackingId = trackingId;
1397
+ }
1398
+
1399
+ setIdentity(identity) {
1400
+ this.trackingId = identity;
1401
+ }
1402
+ /**
1403
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq##vouchers-validate
1404
+ */
1405
+
1406
+
1407
+ validate(params) {
1408
+ var _query$customer, _query$customer2;
1409
+
1410
+ assert(isObject(params) || isString(params), 'client.validate: expected "params" argument to be an object or a string');
1411
+ const query = {};
1412
+
1413
+ if (isString(params)) {
1414
+ query.code = params;
1415
+ } else {
1416
+ query.code = params.code;
1417
+ query.item = params.items;
1418
+ query.amount = params.amount;
1419
+ query.metadata = params.metadata;
1420
+ query.order = {
1421
+ metadata: params.orderMetadata
1422
+ };
1423
+ query.customer = params.customer;
1424
+ query.tracking_id = this.trackingId;
1425
+ }
1426
+
1427
+ if (!!query.code) {
1428
+ query.code = query.code.replace(/[\r\n\t\f\v]/g, '').trim();
1429
+ }
1430
+
1431
+ assert(isOptionalObject(query == null ? void 0 : query.customer), 'client.validate: expected "params.customer" to be an object');
1432
+ 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
1433
+
1434
+ 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
1435
+
1436
+ const queryParams = toQueryParams(query);
1437
+ const path = query.code ? '/validate' : '/promotions/validation';
1438
+ return this.client.get(path, queryParams);
1439
+ }
1440
+ /**
1441
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-voucher-client-side
1442
+ */
1443
+
1444
+
1445
+ redeem(code, payload = {}) {
1446
+ var _payload$customer, _payload$customer$sou;
1447
+
1448
+ assert(isString(code), 'client.redeem - please provide a valid Voucher code');
1449
+ code = code.replace(/[\r\n\t\f\v]/g, '').trim();
1450
+ payload.customer = (_payload$customer = payload.customer) != null ? _payload$customer : {};
1451
+ payload.customer.source_id = (_payload$customer$sou = payload.customer.source_id) != null ? _payload$customer$sou : this.trackingId;
1452
+ return this.client.post('/redeem', payload, {
1453
+ code
1454
+ });
1455
+ }
1456
+ /**
1457
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-publication
1458
+ */
1459
+
1460
+
1461
+ publish(campaign, payload = {}, queryParams = {}) {
1462
+ var _payload$customer2, _payload$customer$sou2, _payload$customer3, _payload$channel, _preparedPayload$cust;
1463
+
1464
+ assert(isObject(payload), 'client.publish - expected payload to be an object');
1465
+ const preparedPayload = {};
1466
+ preparedPayload.customer = (_payload$customer2 = payload.customer) != null ? _payload$customer2 : {};
1467
+ preparedPayload.customer.source_id = (_payload$customer$sou2 = (_payload$customer3 = payload.customer) == null ? void 0 : _payload$customer3.source_id) != null ? _payload$customer$sou2 : this.trackingId;
1468
+ preparedPayload.channel = (_payload$channel = payload.channel) != null ? _payload$channel : 'Voucherify.js'; // @todo - removed hard-coded channel
1469
+
1470
+ 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');
1471
+ queryParams.campaign = campaign.replace(/[\r\n\t\f\v]/g, '').trim();
1472
+ return this.client.post('/publish', preparedPayload, queryParams);
1473
+ }
1474
+ /**
1475
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#track-custom-event-client-side
1476
+ */
1477
+
1478
+
1479
+ track(event_name, customer, metadata, referral, loyalty) {
1480
+ var _customer$source_id, _payload$customer4;
1481
+
1482
+ assert(isString(event_name), 'client.track - expected event name to be an string');
1483
+ assert(isObject(customer), 'client.track - expected customer to be an object');
1484
+ const payload = {
1485
+ event: event_name,
1486
+ metadata: metadata != null ? metadata : {},
1487
+ customer: customer,
1488
+ referral: referral != null ? referral : {},
1489
+ loyalty: loyalty != null ? loyalty : {}
1490
+ };
1491
+ payload.customer.source_id = (_customer$source_id = customer.source_id) != null ? _customer$source_id : this.trackingId;
1492
+ 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');
1493
+ return this.client.post('/events', payload);
1494
+ }
1495
+ /**
1496
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-vouchers
1497
+ */
1498
+
1499
+
1500
+ listVouchers(params = {}) {
1501
+ const query = {};
1502
+ query.campaign = params.campaign;
1503
+ query.category = params.category;
1504
+ query.page = params.page;
1505
+ query.limit = params.limit;
1506
+ query.customer = params.customer;
1507
+ query.created_at = params.created_at;
1508
+ query.updated_at = params.updated_at;
1509
+ const queryParams = toQueryParams(query);
1510
+ return this.client.get('/vouchers', queryParams);
1511
+ }
1512
+ /**
1513
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-customer
1514
+ */
1515
+
1516
+
1517
+ createCustomer(customer, enableDoubleOptIn) {
1518
+ return this.client.post('/customers', customer, {}, enableDoubleOptIn ? {
1519
+ 'X-Voucherify-Double-Opt-In': true
1520
+ } : {});
1521
+ }
1522
+ /**
1523
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-consent-client-side
1524
+ */
1525
+
1526
+
1527
+ listConsents() {
1528
+ return this.client.get('/consents');
1529
+ }
1530
+ /**
1531
+ * @see https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-customers-consents-client
1532
+ */
1533
+
1534
+
1535
+ updateConsents(idOrSourceId, consents) {
1536
+ return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
1537
+ }
1538
+
1539
+ }
1540
+
1541
+ function VoucherifyClientSide(options) {
1542
+ var _options$apiUrl;
1543
+
1544
+ assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
1545
+ assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
1546
+ assert(isString(options.clientSecretKey), 'VoucherifyCustomer: "options.clientSecretKey" is required');
1547
+ assert(isOptionalString(options.apiUrl), 'VoucherifyCustomer: expected "options.baseUrl" to be a string');
1548
+ assert(isOptionalString(options.trackingId), 'VoucherifyCustomer: expected "options.trackingId" to be a string');
1549
+ let headers = {
1550
+ 'X-Client-Application-Id': options.clientApplicationId,
1551
+ 'X-Client-Token': options.clientSecretKey,
1552
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"1.2.0"}`
1553
+ };
1554
+
1555
+ if (environment().startsWith('Node')) {
1556
+ assert(isString(options.origin), 'VoucherifyCustomer: "options.origin" is required in Node.js');
1557
+ headers['origin'] = options.origin;
1558
+ }
1559
+
1560
+ if (isObject(options.customHeaders)) {
1561
+ headers = Object.assign({}, headers, options.customHeaders);
1562
+ }
1563
+
1564
+ const client = new RequestController({
1565
+ basePath: 'client/v1',
1566
+ baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
1567
+ headers
1568
+ });
1569
+ return new ClientSide(client, options.trackingId);
1570
+ }
1571
+
1572
+ exports.VoucherifyClientSide = VoucherifyClientSide;
1573
+ exports.VoucherifyServerSide = VoucherifyServerSide;
1574
+
1575
+ Object.defineProperty(exports, '__esModule', { value: true });
1576
+
1577
+ })));
1578
+ //# sourceMappingURL=voucherifysdk.umd.development.js.map