@voucherify/sdk 2.0.3 → 2.0.6

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,63 @@
1
+ import { RewardRedemptionParams } from './Rewards';
2
+ import { GiftRedemptionParams } from './Gift';
3
+ import { OrdersCreateResponse } from './Orders';
4
+ import { ApplicableToResultList } from './ApplicableTo';
5
+ import { DiscountVouchersTypes, DiscountVouchersEffectTypes, DiscountUnitVouchersEffectTypes } from './DiscountVoucher';
6
+ import { SimpleProduct, SimpleSku } from './Products';
7
+ import { LoyaltyPointsTransfer } from './Loyalties';
8
+ declare type ExpandOption = 'order' | 'redeemable' | 'redemption';
9
+ export interface StackableOptions {
10
+ expand: ExpandOption[];
11
+ }
12
+ export declare type StackableRedeemableObject = 'promotion_stack' | 'promotion_tier' | 'voucher';
13
+ export interface StackableRedeemableParams {
14
+ object: StackableRedeemableObject;
15
+ id: string;
16
+ reward?: RewardRedemptionParams;
17
+ gift?: GiftRedemptionParams;
18
+ }
19
+ export declare type StackableRedeemableResponseStatus = 'APPLICABLE' | 'INAPPLICABLE' | 'SKIPPED';
20
+ export interface StackableRedeemableResultDiscountUnit {
21
+ effect: DiscountUnitVouchersEffectTypes;
22
+ unit_off: number;
23
+ unit_type: string;
24
+ sku?: SimpleSku;
25
+ product?: SimpleProduct;
26
+ }
27
+ export interface StackableRedeemableResultDiscount {
28
+ type: DiscountVouchersTypes;
29
+ effect: DiscountVouchersEffectTypes;
30
+ amount_off?: number;
31
+ percent_off?: number;
32
+ amount_limit?: number;
33
+ fixed_amount?: number;
34
+ unit_off?: number;
35
+ unit_type?: string;
36
+ sku?: SimpleSku;
37
+ product?: SimpleProduct;
38
+ units?: StackableRedeemableResultDiscountUnit[];
39
+ }
40
+ export interface StackableRedeemableResultGift {
41
+ credits?: number;
42
+ }
43
+ export interface StackableRedeemableResultLoyaltyCard {
44
+ points?: number;
45
+ transfers?: LoyaltyPointsTransfer[];
46
+ }
47
+ export interface StackableRedeemableResultResponse {
48
+ discount?: StackableRedeemableResultDiscount;
49
+ gift?: StackableRedeemableResultGift;
50
+ loyalty_card?: StackableRedeemableResultLoyaltyCard;
51
+ error?: any;
52
+ }
53
+ export interface StackableRedeemableResponse {
54
+ status: StackableRedeemableResponseStatus;
55
+ id: string;
56
+ object: StackableRedeemableObject;
57
+ order?: OrdersCreateResponse;
58
+ applicable_to?: ApplicableToResultList;
59
+ inapplicable_to?: ApplicableToResultList;
60
+ result?: StackableRedeemableResultResponse;
61
+ metadata?: Record<string, any>;
62
+ }
63
+ export {};
@@ -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
 
@@ -1273,12 +1328,60 @@ class Segments {
1273
1328
 
1274
1329
  }
1275
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
+
1361
+ class MetadataSchemas {
1362
+ constructor(client) {
1363
+ this.client = void 0;
1364
+ this.client = client;
1365
+ }
1366
+
1367
+ list() {
1368
+ return this.client.get('/metadata-schemas');
1369
+ }
1370
+
1371
+ get(schemaName) {
1372
+ return this.client.get(`/metadata-schemas/${encode(schemaName)}`);
1373
+ }
1374
+
1375
+ }
1376
+
1377
+ // apiLimitsHandler: ApiLimitsHandler
1276
1378
  // campaigns: Campaigns
1277
1379
  // consents: Consents
1278
1380
  // customers: Customers
1279
1381
  // distributions: Distributions
1280
1382
  // events: Events
1281
1383
  // loyalties: Loyalties
1384
+ // metadataSchemas: MetadataSchemas
1282
1385
  // orders: Orders
1283
1386
  // products: Products
1284
1387
  // promotions: Promotions
@@ -1301,7 +1404,7 @@ function VoucherifyServerSide(options) {
1301
1404
  let headers = {
1302
1405
  'X-App-Id': options.applicationId,
1303
1406
  'X-App-Token': options.secretKey,
1304
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.3"}`,
1407
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.6"}`,
1305
1408
  'Content-Type': 'application/json'
1306
1409
  };
1307
1410
 
@@ -1347,6 +1450,8 @@ function VoucherifyServerSide(options) {
1347
1450
  const loyalties = new Loyalties(client);
1348
1451
  const segments = new Segments(client);
1349
1452
  const validationRules = new ValidationRules(client);
1453
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1454
+ const metadataSchemas = new MetadataSchemas(client);
1350
1455
  return {
1351
1456
  vouchers,
1352
1457
  campaigns,
@@ -1363,7 +1468,9 @@ function VoucherifyServerSide(options) {
1363
1468
  segments,
1364
1469
  validationRules,
1365
1470
  events,
1366
- asyncActions
1471
+ asyncActions,
1472
+ apiLimitsHandler,
1473
+ metadataSchemas
1367
1474
  };
1368
1475
  }
1369
1476
 
@@ -1516,6 +1623,22 @@ class ClientSide {
1516
1623
  updateConsents(idOrSourceId, consents) {
1517
1624
  return this.client.put(`/customers/${encode(idOrSourceId)}/consents`, consents);
1518
1625
  }
1626
+ /**
1627
+ * @see https://docs.voucherify.io/reference/validate-stackable-discounts-client-side
1628
+ */
1629
+
1630
+
1631
+ validateStackable(params) {
1632
+ return this.client.post(`/validations`, params);
1633
+ }
1634
+ /**
1635
+ * @see https://docs.voucherify.io/reference/redeem-stackable-discounts-client-side
1636
+ */
1637
+
1638
+
1639
+ redeemStackable(params) {
1640
+ return this.client.post(`/redemptions`, params);
1641
+ }
1519
1642
 
1520
1643
  }
1521
1644
 
@@ -1530,7 +1653,7 @@ function VoucherifyClientSide(options) {
1530
1653
  let headers = {
1531
1654
  'X-Client-Application-Id': options.clientApplicationId,
1532
1655
  'X-Client-Token': options.clientSecretKey,
1533
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.3"}`
1656
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.6"}`
1534
1657
  };
1535
1658
 
1536
1659
  if (environment().startsWith('Node')) {
@@ -1550,5 +1673,5 @@ function VoucherifyClientSide(options) {
1550
1673
  return new ClientSide(client, options.trackingId);
1551
1674
  }
1552
1675
 
1553
- export { VoucherifyClientSide, VoucherifyServerSide };
1676
+ export { DiscountVouchersTypesEnum, VoucherifyClientSide, VoucherifyServerSide };
1554
1677
  //# sourceMappingURL=voucherifysdk.esm.js.map