@voucherify/sdk 2.2.4 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @voucherify/sdk
2
2
 
3
+ ## 2.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a266c2a`](https://github.com/voucherifyio/voucherify-js-sdk/commit/a266c2a9a4a1942e2b6d8ef54021e04d36ddb02c) [#223](https://github.com/voucherifyio/voucherify-js-sdk/pull/223) Thanks [@darekg11](https://github.com/darekg11)! - Add optional timeoutMs option to VoucherifyServerSide and VoucherifyClientSide classes defiing timeout in miliseconds after which Axios is going to abort the request. By default this is equal to 0 meaining that there is no timeout beside default Voucherify's Load balancer timeout which is set to 3 minutes
8
+
9
+ ## 2.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [`d5751ea`](https://github.com/voucherifyio/voucherify-js-sdk/commit/d5751ea57c46f32275c4630bd4d2b6d41f3506b2) [#216](https://github.com/voucherifyio/voucherify-js-sdk/pull/216) Thanks [@Davies-Owen](https://github.com/Davies-Owen)! - add amount_off_formula, percent_off_formula, unit_off_formula, and fixed_amount_formula fields to Voucher types: DiscountAmount, DiscountPercent, DiscountUnit, DiscountFixed, VoucherDiscount, and StackableRedeemableResultDiscount
14
+
3
15
  ## 2.2.4
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -131,6 +131,7 @@ const client = VoucherifyServerSide({
131
131
  apiVersion: 'v2018-08-01', // optional
132
132
  channel: 'e-commerce', // optional
133
133
  customHeaders: { "MY_CUSTOM_HEADER": "my_value" } // optional
134
+ timeoutMs: 10000 // optional
134
135
  })
135
136
  ```
136
137
 
@@ -1214,6 +1215,7 @@ const client = VoucherifyClientSide({
1214
1215
  apiUrl: 'https://<region>.api.voucherify.io', // optional
1215
1216
  origin: 'example.com', // read more below
1216
1217
  customHeaders: { "MY_CUSTOM_HEADER": "my_value" } // optional
1218
+ timeoutMs: 10000 // optional
1217
1219
  })
1218
1220
  ```
1219
1221
 
@@ -3,6 +3,7 @@ export interface RequestControllerOptions {
3
3
  basePath: string;
4
4
  headers: Record<string, any>;
5
5
  exposeErrorCause: boolean;
6
+ timeoutMs: number;
6
7
  }
7
8
  /**
8
9
  * @internal
@@ -15,7 +16,8 @@ export declare class RequestController {
15
16
  private lastResponseHeaders;
16
17
  private isLastResponseHeadersSet;
17
18
  private exposeErrorCause;
18
- constructor({ basePath, baseURL, headers, exposeErrorCause }: RequestControllerOptions);
19
+ private timeoutMs;
20
+ constructor({ basePath, baseURL, headers, exposeErrorCause, timeoutMs }: RequestControllerOptions);
19
21
  isLastReponseHeadersSet(): boolean;
20
22
  getLastResponseHeaders(): Record<string, string>;
21
23
  private setLastResponseHeaders;
@@ -78,5 +78,9 @@ export interface VoucherifyClientSideOptions {
78
78
  * The original Axios error will be included in cause property of VoucherifyError
79
79
  */
80
80
  exposeErrorCause?: boolean;
81
+ /**
82
+ * Optionally, you can set timeout in miliseconds. After this time request will be aborted. By default Voucherify's API has timeout value of 3 minutes.
83
+ */
84
+ timeoutMs?: number;
81
85
  }
82
86
  export declare function VoucherifyClientSide(options: VoucherifyClientSideOptions): ClientSide;
@@ -98,6 +98,10 @@ export interface VoucherifyServerSideOptions {
98
98
  * The original Axios error will be included in cause property of VoucherifyError
99
99
  */
100
100
  exposeErrorCause?: boolean;
101
+ /**
102
+ * Optionally, you can set timeout in miliseconds. After this time request will be aborted. By default Voucherify's API has timeout value of 3 minutes.
103
+ */
104
+ timeoutMs?: number;
101
105
  }
102
106
  export declare function VoucherifyServerSide(options: VoucherifyServerSideOptions): {
103
107
  vouchers: Vouchers;
@@ -23,6 +23,7 @@ interface SimpleProductDiscountUnit {
23
23
  export interface DiscountUnit {
24
24
  type?: DiscountVouchersTypesEnum.UNIT;
25
25
  unit_off?: number;
26
+ unit_off_formula?: string;
26
27
  effect?: DiscountUnitVouchersEffectTypes;
27
28
  unit_type?: string;
28
29
  product?: SimpleProductDiscountUnit;
@@ -31,17 +32,20 @@ export interface DiscountUnit {
31
32
  export interface DiscountAmount {
32
33
  type?: DiscountVouchersTypesEnum.AMOUNT;
33
34
  amount_off?: number;
35
+ amount_off_formula?: string;
34
36
  effect?: DiscountAmountVouchersEffectTypes;
35
37
  }
36
38
  export interface DiscountPercent {
37
39
  type?: DiscountVouchersTypesEnum.PERCENT;
38
40
  percent_off?: number;
41
+ percent_off_formula?: string;
39
42
  amount_limit?: number;
40
43
  effect?: DiscountPercentVouchersEffectTypes;
41
44
  }
42
45
  export interface DiscountFixed {
43
46
  type?: DiscountVouchersTypesEnum.FIXED;
44
47
  fixed_amount?: number;
48
+ fixed_amount_formula?: string;
45
49
  effect?: DiscountFixedVouchersEffectTypes;
46
50
  }
47
51
  export {};
@@ -4,9 +4,12 @@ declare type OrderType = 'id' | '-id' | 'voucher_code' | '-voucher_code' | 'trac
4
4
  export interface VoucherDiscount {
5
5
  type: 'UNIT' | 'AMOUNT' | 'DISCOUNT';
6
6
  unit_off?: number;
7
+ unit_off_formula?: string;
7
8
  effect?: string;
8
9
  amount_off?: number;
10
+ amount_off_formula?: string;
9
11
  percent_off?: number;
12
+ percent_off_formula?: string;
10
13
  amount_limit?: number;
11
14
  }
12
15
  interface DistributionsPublicationsVoucher {
@@ -29,10 +29,14 @@ export interface StackableRedeemableResultDiscount {
29
29
  type: DiscountVouchersTypes;
30
30
  effect: DiscountVouchersEffectTypes;
31
31
  amount_off?: number;
32
+ amount_off_formula?: string;
32
33
  percent_off?: number;
34
+ percent_off_formula?: string;
33
35
  amount_limit?: number;
34
36
  fixed_amount?: number;
37
+ fixed_amount_formula?: string;
35
38
  unit_off?: number;
39
+ unit_off_formula?: string;
36
40
  unit_type?: string;
37
41
  sku?: SimpleSku;
38
42
  product?: SimpleProduct;
@@ -58,7 +58,8 @@ class RequestController {
58
58
  basePath,
59
59
  baseURL,
60
60
  headers,
61
- exposeErrorCause
61
+ exposeErrorCause,
62
+ timeoutMs
62
63
  }) {
63
64
  this.baseURL = void 0;
64
65
  this.basePath = void 0;
@@ -67,12 +68,14 @@ class RequestController {
67
68
  this.lastResponseHeaders = void 0;
68
69
  this.isLastResponseHeadersSet = void 0;
69
70
  this.exposeErrorCause = void 0;
71
+ this.timeoutMs = void 0;
70
72
  this.basePath = basePath;
71
73
  this.baseURL = baseURL;
72
74
  this.headers = headers;
73
75
  this.exposeErrorCause = exposeErrorCause;
74
76
  this.lastResponseHeaders = {};
75
77
  this.isLastResponseHeadersSet = false;
78
+ this.timeoutMs = timeoutMs;
76
79
  this.request = axios.create({
77
80
  baseURL: `${this.baseURL}/${this.basePath}/`,
78
81
  headers: this.headers,
@@ -115,7 +118,8 @@ class RequestController {
115
118
  params,
116
119
  paramsSerializer: function (params) {
117
120
  return Qs.stringify(params);
118
- }
121
+ },
122
+ timeout: this.timeoutMs
119
123
  });
120
124
  this.setLastResponseHeaders(response.headers);
121
125
  return response.data;
@@ -127,7 +131,8 @@ class RequestController {
127
131
  paramsSerializer: function (params) {
128
132
  return Qs.stringify(params);
129
133
  },
130
- headers
134
+ headers,
135
+ timeout: this.timeoutMs
131
136
  });
132
137
  this.setLastResponseHeaders(response.headers);
133
138
  return response.data;
@@ -135,7 +140,8 @@ class RequestController {
135
140
 
136
141
  async put(path, body, params) {
137
142
  const response = await this.request.put(path, body, {
138
- params
143
+ params,
144
+ timeout: this.timeoutMs
139
145
  });
140
146
  this.setLastResponseHeaders(response.headers);
141
147
  return response.data;
@@ -143,7 +149,8 @@ class RequestController {
143
149
 
144
150
  async delete(path, params) {
145
151
  const response = await this.request.delete(path, {
146
- params
152
+ params,
153
+ timeout: this.timeoutMs
147
154
  });
148
155
  this.setLastResponseHeaders(response.headers);
149
156
  return response.data;
@@ -1447,7 +1454,7 @@ class MetadataSchemas {
1447
1454
  // }
1448
1455
 
1449
1456
  function VoucherifyServerSide(options) {
1450
- var _options$apiUrl, _options$exposeErrorC;
1457
+ var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
1451
1458
 
1452
1459
  assert(isObject(options), 'VoucherifyServerSide: the "options" argument must be an object');
1453
1460
  assert(isString(options.applicationId), 'VoucherifyServerSide: "options.applicationId" is required');
@@ -1457,7 +1464,7 @@ function VoucherifyServerSide(options) {
1457
1464
  let headers = {
1458
1465
  'X-App-Id': options.applicationId,
1459
1466
  'X-App-Token': options.secretKey,
1460
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.2.4"}`,
1467
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.2.6"}`,
1461
1468
  'Content-Type': 'application/json'
1462
1469
  };
1463
1470
 
@@ -1483,7 +1490,8 @@ function VoucherifyServerSide(options) {
1483
1490
  basePath: 'v1',
1484
1491
  baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
1485
1492
  headers,
1486
- exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
1493
+ exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
1494
+ timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
1487
1495
  });
1488
1496
  const asyncActions = new AsyncActions(client);
1489
1497
  const balance = new Balance(client);
@@ -1697,7 +1705,7 @@ class ClientSide {
1697
1705
  }
1698
1706
 
1699
1707
  function VoucherifyClientSide(options) {
1700
- var _options$apiUrl, _options$exposeErrorC;
1708
+ var _options$apiUrl, _options$exposeErrorC, _options$timeoutMs;
1701
1709
 
1702
1710
  assert(isObject(options), 'VoucherifyCustomer: expected "options" argument to be an object');
1703
1711
  assert(isString(options.clientApplicationId), 'VoucherifyCustomer: "options.clientApplicationId" is required');
@@ -1707,7 +1715,7 @@ function VoucherifyClientSide(options) {
1707
1715
  let headers = {
1708
1716
  'X-Client-Application-Id': options.clientApplicationId,
1709
1717
  'X-Client-Token': options.clientSecretKey,
1710
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.2.4"}`
1718
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.2.6"}`
1711
1719
  };
1712
1720
 
1713
1721
  if (environment().startsWith('Node')) {
@@ -1723,7 +1731,8 @@ function VoucherifyClientSide(options) {
1723
1731
  basePath: 'client/v1',
1724
1732
  baseURL: (_options$apiUrl = options.apiUrl) != null ? _options$apiUrl : 'https://api.voucherify.io',
1725
1733
  headers,
1726
- exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false
1734
+ exposeErrorCause: (_options$exposeErrorC = options.exposeErrorCause) != null ? _options$exposeErrorC : false,
1735
+ timeoutMs: (_options$timeoutMs = options.timeoutMs) != null ? _options$timeoutMs : 0
1727
1736
  });
1728
1737
  return new ClientSide(client, options.trackingId);
1729
1738
  }