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