@voucherify/sdk 2.0.2 → 2.0.5

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.
@@ -0,0 +1,17 @@
1
+ export declare type ValidationSessionType = 'LOCK';
2
+ export declare type ValidationSessionTTLUnit = 'DAYS' | 'HOURS' | 'MICROSECONDS' | 'MILLISECONDS' | 'MINUTES' | 'NANOSECONDS' | 'SECONDS';
3
+ export interface ValidationSessionParams {
4
+ key?: string;
5
+ type?: ValidationSessionType;
6
+ ttl?: number;
7
+ ttl_unit?: ValidationSessionTTLUnit;
8
+ }
9
+ export interface ValidationSessionResponse {
10
+ key: string;
11
+ type: ValidationSessionType;
12
+ ttl: number;
13
+ ttl_unit: ValidationSessionTTLUnit;
14
+ }
15
+ export interface ValidationSessionReleaseParams {
16
+ key: string;
17
+ }
@@ -1,3 +1,4 @@
1
+ import { ApplicableToResultList } from './ApplicableTo';
1
2
  export interface ValidationRulesCreate {
2
3
  name: string;
3
4
  error?: {
@@ -25,11 +26,7 @@ export interface ValidationRulesCreateResponse {
25
26
  export interface ValidationRulesValidateResponse {
26
27
  valid: boolean;
27
28
  rule_id: string;
28
- applicable_to: {
29
- data: any[];
30
- object: 'list';
31
- total: number;
32
- };
29
+ applicable_to: ApplicableToResultList;
33
30
  }
34
31
  export declare type ValidationRulesGetResponse = ValidationRulesCreateResponse & {
35
32
  assignments_count?: string;
@@ -1,5 +1,9 @@
1
- import { DiscountAmount, DiscountPercent, DiscountUnit } from './Vouchers';
2
- import { OrdersItem } from './Orders';
1
+ import { DiscountAmount, DiscountPercent, DiscountUnit } from './DiscountVoucher';
2
+ import { CustomersCreateBody } from './Customers';
3
+ import { StackableOptions, StackableRedeemableParams, StackableRedeemableResponse } from './Stackable';
4
+ import { ValidationSessionParams, ValidationSessionResponse } from './ValidateSession';
5
+ import { ApplicableToResultList } from './ApplicableTo';
6
+ import { OrdersItem, OrdersCreate, OrdersCreateResponse } from './Orders';
3
7
  import { PromotionsValidateParams } from './Promotions';
4
8
  export interface ValidationsValidateVoucherParams {
5
9
  customer?: {
@@ -23,23 +27,10 @@ export interface ValidationsValidateVoucherParams {
23
27
  reward?: {
24
28
  id: string;
25
29
  };
26
- session?: {
27
- type: 'LOCK';
28
- key?: string;
29
- ttl?: number;
30
- ttl_unit?: 'MILLISECONDS' | 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS';
31
- };
30
+ session?: ValidationSessionParams;
32
31
  }
33
32
  export interface ValidationsValidateVoucherResponse {
34
- applicable_to?: {
35
- object: 'list';
36
- total: number;
37
- data?: {
38
- id: string;
39
- object: 'product';
40
- source_id?: string;
41
- }[];
42
- };
33
+ applicable_to?: ApplicableToResultList;
43
34
  campaign?: string;
44
35
  campaign_id?: string;
45
36
  metadata?: Record<string, any>;
@@ -62,5 +53,20 @@ export interface ValidationsValidateVoucherResponse {
62
53
  };
63
54
  tracking_id: string;
64
55
  }
56
+ export interface ValidationsValidateStackableParams {
57
+ options?: StackableOptions;
58
+ redeemables: StackableRedeemableParams[];
59
+ session?: ValidationSessionParams;
60
+ order?: OrdersCreate;
61
+ customer?: CustomersCreateBody;
62
+ metadata?: Record<string, any>;
63
+ }
64
+ export interface ValidationValidateStackableResponse {
65
+ valid: boolean;
66
+ tracking_id?: string;
67
+ session?: ValidationSessionResponse;
68
+ order?: OrdersCreateResponse;
69
+ redeemables?: StackableRedeemableResponse[];
70
+ }
65
71
  export declare type ValidationsValidateCode = PromotionsValidateParams;
66
72
  export declare type ValidationsValidateContext = ValidationsValidateVoucherParams;
@@ -1,5 +1,6 @@
1
1
  import { OrdersGetResponse } from './Orders';
2
2
  import { SimpleCustomer } from './Customers';
3
+ import { DiscountUnit, DiscountAmount, DiscountPercent } from './DiscountVoucher';
3
4
  export declare type VoucherType = 'GIFT' | 'DISCOUNT' | 'LOYALTY_CARD' | 'LUCKY_DRAW';
4
5
  export interface SimpleVoucher {
5
6
  code_config?: {
@@ -20,21 +21,6 @@ export interface SimpleVoucher {
20
21
  quantity: number;
21
22
  };
22
23
  }
23
- export interface DiscountUnit {
24
- type?: 'UNIT';
25
- unit_off?: number;
26
- effect?: 'ADD_MISSING_ITEMS' | 'ADD_NEW_ITEMS';
27
- unit_type?: string;
28
- }
29
- export interface DiscountAmount {
30
- type?: 'AMOUNT';
31
- amount_off?: number;
32
- }
33
- export interface DiscountPercent {
34
- type?: 'PERCENT';
35
- percent_off?: number;
36
- amount_limit?: number;
37
- }
38
24
  export interface VouchersResponse {
39
25
  id: string;
40
26
  code: string;
@@ -17,3 +17,8 @@ export * from './Exports';
17
17
  export * from './Orders';
18
18
  export * from './Consents';
19
19
  export * from './Events';
20
+ export * from './Stackable';
21
+ export * from './Gift';
22
+ export * from './ValidateSession';
23
+ export * from './ApplicableTo';
24
+ export * from './DiscountVoucher';
@@ -1,6 +1,15 @@
1
1
  import axios from 'axios';
2
2
  import Qs from 'qs';
3
3
 
4
+ var DiscountVouchersTypesEnum;
5
+
6
+ (function (DiscountVouchersTypesEnum) {
7
+ DiscountVouchersTypesEnum["AMOUNT"] = "AMOUNT";
8
+ DiscountVouchersTypesEnum["PERCENT"] = "PERCENT";
9
+ DiscountVouchersTypesEnum["UNIT"] = "UNIT";
10
+ DiscountVouchersTypesEnum["FIXED"] = "FIXED";
11
+ })(DiscountVouchersTypesEnum || (DiscountVouchersTypesEnum = {}));
12
+
4
13
  /**
5
14
  * @internal
6
15
  */
@@ -35,9 +44,13 @@ class RequestController {
35
44
  this.basePath = void 0;
36
45
  this.headers = void 0;
37
46
  this.request = void 0;
47
+ this.lastResponseHeaders = void 0;
48
+ this.isLastResponseHeadersSet = void 0;
38
49
  this.basePath = basePath;
39
50
  this.baseURL = baseURL;
40
51
  this.headers = headers;
52
+ this.lastResponseHeaders = {};
53
+ this.isLastResponseHeadersSet = false;
41
54
  this.request = axios.create({
42
55
  baseURL: `${this.baseURL}/${this.basePath}/`,
43
56
  headers: this.headers,
@@ -57,6 +70,19 @@ class RequestController {
57
70
  });
58
71
  }
59
72
 
73
+ isLastReponseHeadersSet() {
74
+ return this.isLastResponseHeadersSet;
75
+ }
76
+
77
+ getLastResponseHeaders() {
78
+ return this.lastResponseHeaders;
79
+ }
80
+
81
+ setLastResponseHeaders(headers) {
82
+ this.lastResponseHeaders = headers;
83
+ this.isLastResponseHeadersSet = true;
84
+ }
85
+
60
86
  setBaseUrl(baseURL) {
61
87
  this.baseURL = baseURL;
62
88
  this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
@@ -69,6 +95,7 @@ class RequestController {
69
95
  return Qs.stringify(params);
70
96
  }
71
97
  });
98
+ this.setLastResponseHeaders(response.headers);
72
99
  return response.data;
73
100
  }
74
101
 
@@ -80,6 +107,7 @@ class RequestController {
80
107
  },
81
108
  headers
82
109
  });
110
+ this.setLastResponseHeaders(response.headers);
83
111
  return response.data;
84
112
  }
85
113
 
@@ -87,6 +115,7 @@ class RequestController {
87
115
  const response = await this.request.put(path, body, {
88
116
  params
89
117
  });
118
+ this.setLastResponseHeaders(response.headers);
90
119
  return response.data;
91
120
  }
92
121
 
@@ -94,6 +123,7 @@ class RequestController {
94
123
  const response = await this.request.delete(path, {
95
124
  params
96
125
  });
126
+ this.setLastResponseHeaders(response.headers);
97
127
  return response.data;
98
128
  }
99
129
 
@@ -502,6 +532,14 @@ class Validations {
502
532
 
503
533
  return this.validateVoucher(code, context);
504
534
  }
535
+ /**
536
+ * @see https://docs.voucherify.io/reference/validate-stacked-discounts-1
537
+ */
538
+
539
+
540
+ validateStackable(params) {
541
+ return this.client.post(`/validations`, params);
542
+ }
505
543
 
506
544
  }
507
545
 
@@ -518,6 +556,14 @@ class Redemptions {
518
556
  redeem(code, body = {}) {
519
557
  return this.client.post(`/vouchers/${encode(code)}/redemption`, body);
520
558
  }
559
+ /**
560
+ * @see https://docs.voucherify.io/reference/redeem-stacked-discounts
561
+ */
562
+
563
+
564
+ redeemStackable(params) {
565
+ return this.client.post(`/redemptions`, params);
566
+ }
521
567
  /**
522
568
  * @see https://docs.voucherify.io/reference/get-redemption
523
569
  */
@@ -570,6 +616,15 @@ class Redemptions {
570
616
 
571
617
  return this.client.post(`/redemptions/${encode(redemptionId)}/rollback`, payload, queryParams);
572
618
  }
619
+ /**
620
+ * @see https://docs.voucherify.io/reference/rollback-stackable-redemptions
621
+ * Types of params and queryParams WILL be changed in future - please do not depend on it!
622
+ */
623
+
624
+
625
+ rollbackStackable(parentRedemptionId, params, queryParams) {
626
+ return this.client.post(`/redemptions/${encode(parentRedemptionId)}/rollbacks`, params, queryParams);
627
+ }
573
628
 
574
629
  }
575
630
 
@@ -750,6 +805,14 @@ class Customers {
750
805
  updateConsents(idOrSourceId, consents) {
751
806
  return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
752
807
  }
808
+ /**
809
+ * @see https://docs.voucherify.io/reference/get-customer-activities
810
+ */
811
+
812
+
813
+ listActivities(customerId, params) {
814
+ return this.client.get(`/customers/${encode(customerId)}/activities`, params);
815
+ }
753
816
 
754
817
  }
755
818
 
@@ -1265,6 +1328,36 @@ class Segments {
1265
1328
 
1266
1329
  }
1267
1330
 
1331
+ class ApiLimitsHandler {
1332
+ constructor(requestController) {
1333
+ this.requestController = void 0;
1334
+ this.requestController = requestController;
1335
+ }
1336
+
1337
+ getLastResponseHeadersFromController() {
1338
+ return this.requestController.getLastResponseHeaders();
1339
+ }
1340
+
1341
+ areLimitsAvailable() {
1342
+ return this.requestController.isLastReponseHeadersSet();
1343
+ }
1344
+
1345
+ getRateLimit() {
1346
+ var _this$getLastResponse;
1347
+
1348
+ const rateLimit = (_this$getLastResponse = this.getLastResponseHeadersFromController()['x-rate-limit-limit']) != null ? _this$getLastResponse : 0;
1349
+ return parseInt(rateLimit, 10);
1350
+ }
1351
+
1352
+ getRateLimitRemaining() {
1353
+ var _this$getLastResponse2;
1354
+
1355
+ const rateLimitRemaining = (_this$getLastResponse2 = this.getLastResponseHeadersFromController()['x-rate-limit-remaining']) != null ? _this$getLastResponse2 : 0;
1356
+ return parseInt(rateLimitRemaining, 10);
1357
+ }
1358
+
1359
+ }
1360
+
1268
1361
  // campaigns: Campaigns
1269
1362
  // consents: Consents
1270
1363
  // customers: Customers
@@ -1293,7 +1386,7 @@ function VoucherifyServerSide(options) {
1293
1386
  let headers = {
1294
1387
  'X-App-Id': options.applicationId,
1295
1388
  'X-App-Token': options.secretKey,
1296
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.2"}`,
1389
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.5"}`,
1297
1390
  'Content-Type': 'application/json'
1298
1391
  };
1299
1392
 
@@ -1339,6 +1432,7 @@ function VoucherifyServerSide(options) {
1339
1432
  const loyalties = new Loyalties(client);
1340
1433
  const segments = new Segments(client);
1341
1434
  const validationRules = new ValidationRules(client);
1435
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1342
1436
  return {
1343
1437
  vouchers,
1344
1438
  campaigns,
@@ -1355,7 +1449,8 @@ function VoucherifyServerSide(options) {
1355
1449
  segments,
1356
1450
  validationRules,
1357
1451
  events,
1358
- asyncActions
1452
+ asyncActions,
1453
+ apiLimitsHandler
1359
1454
  };
1360
1455
  }
1361
1456
 
@@ -1508,6 +1603,22 @@ class ClientSide {
1508
1603
  updateConsents(idOrSourceId, consents) {
1509
1604
  return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
1510
1605
  }
1606
+ /**
1607
+ * @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
1608
+ */
1609
+
1610
+
1611
+ validateStackable(params) {
1612
+ return this.client.post(`/validations`, params);
1613
+ }
1614
+ /**
1615
+ * @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
1616
+ */
1617
+
1618
+
1619
+ redeemStackable(params) {
1620
+ return this.client.post(`/redemptions`, params);
1621
+ }
1511
1622
 
1512
1623
  }
1513
1624
 
@@ -1522,7 +1633,7 @@ function VoucherifyClientSide(options) {
1522
1633
  let headers = {
1523
1634
  'X-Client-Application-Id': options.clientApplicationId,
1524
1635
  'X-Client-Token': options.clientSecretKey,
1525
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.2"}`
1636
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.5"}`
1526
1637
  };
1527
1638
 
1528
1639
  if (environment().startsWith('Node')) {
@@ -1542,5 +1653,5 @@ function VoucherifyClientSide(options) {
1542
1653
  return new ClientSide(client, options.trackingId);
1543
1654
  }
1544
1655
 
1545
- export { VoucherifyClientSide, VoucherifyServerSide };
1656
+ export { DiscountVouchersTypesEnum, VoucherifyClientSide, VoucherifyServerSide };
1546
1657
  //# sourceMappingURL=voucherifysdk.esm.js.map