@voucherify/sdk 2.0.4 → 2.0.7

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,23 @@
1
1
  # @voucherify/sdk
2
2
 
3
+ ## 2.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7913a06`](https://github.com/voucherifyio/voucherify-js-sdk/commit/7913a06bb3ab6c79bcbfae8ddbff0bcc8329dd73) [#127](https://github.com/voucherifyio/voucherify-js-sdk/pull/127) Thanks [@Irene350](https://github.com/Irene350)! - Improving Validate Voucher response type
8
+
9
+ ## 2.0.6
10
+
11
+ ### Patch Changes
12
+
13
+ - [`f8241b7`](https://github.com/voucherifyio/voucherify-js-sdk/commit/f8241b709097f53e29427ba4f4260073375ec91c) [#125](https://github.com/voucherifyio/voucherify-js-sdk/pull/125) Thanks [@darekg11](https://github.com/darekg11)! - Added support for metadata-schemas API. Allowing to list all metadata schemas in project or retrieve single one via get method by providing schema name
14
+
15
+ ## 2.0.5
16
+
17
+ ### Patch Changes
18
+
19
+ - [`a7811e7`](https://github.com/voucherifyio/voucherify-js-sdk/commit/a7811e7e2939efe7a4c59c004dbc9591fcd73030) [#121](https://github.com/voucherifyio/voucherify-js-sdk/pull/121) Thanks [@jkaliszuk](https://github.com/jkaliszuk)! - Added logic that allow to storage lastResponseHeaders data and get apiLimit through ApiLimitsHandler
20
+
3
21
  ## 2.0.4
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -66,6 +66,10 @@ Server side:
66
66
  <a href="#events">Events</a>
67
67
  |
68
68
  <a href="#async-actions">Async Actions</a>
69
+ |
70
+ <a href="#metadata-schemas">Metadata Schemas</a>
71
+ |
72
+ <a href="#api-limits-handler">Api Limits Handler</a>
69
73
  </p>
70
74
 
71
75
  <p align="center">
@@ -1108,6 +1112,7 @@ Check [customer object](https://docs.voucherify.io/v1/reference#the-customer-obj
1108
1112
 
1109
1113
 
1110
1114
  ### Async Actions
1115
+
1111
1116
  Methods are provided within `client.asyncActions.*` namespace.
1112
1117
 
1113
1118
  - [Get Async Action](#get-async-action)
@@ -1124,6 +1129,54 @@ client.asyncActions.list()
1124
1129
  client.asyncActions.list(params)
1125
1130
  ```
1126
1131
 
1132
+ ---
1133
+
1134
+ ### Metadata Schemas
1135
+
1136
+ Methods are provided within `client.metadataSchemas.*` namespace.
1137
+
1138
+ - [List Metadata Schemas](#list-metadata-schemas)
1139
+ - [Get Metadata Schema by schema name](#get-metadata-schema-by-schema-name)
1140
+
1141
+ #### List Metadata Schemas
1142
+ ```javascript
1143
+ client.metadataSchemas.list()
1144
+ ```
1145
+
1146
+ #### Get Metadata Schema by schema name
1147
+ ```javascript
1148
+ client.metadataSchemas.get(schemaName)
1149
+ ```
1150
+
1151
+ ### Api Limits Handler
1152
+
1153
+ Methods are provided within `client.apiLimitsHandler.*` namespace.
1154
+
1155
+ - [Are Limits Available](#are-limits-available)
1156
+ - [Get Rate Limit](#get-rate-limit)
1157
+ - [Get Rate Limit Remaining](#get-rate-limit-remaining)
1158
+
1159
+ #### Are Limits Available
1160
+ ```javascript
1161
+ client.apiLimitsHandler.areLimitsAvailable()
1162
+ ```
1163
+
1164
+ This method should be called each time beforehand [Get Rate Limit](#get-rate-limit) or [Get Rate Limit Remaining](#get-rate-limit-remaining) to ensure limit data are available.
1165
+
1166
+ #### Get Rate Limit
1167
+ ```javascript
1168
+ if(client.apiLimitsHandler.areLimitsAvailable()){
1169
+ client.apiLimitsHandler.getRateLimit()
1170
+ }
1171
+ ```
1172
+
1173
+ #### Get Rate Limit Remaining
1174
+ ```javascript
1175
+ if(client.apiLimitsHandler.areLimitsAvailable()){
1176
+ client.apiLimitsHandler.getRateLimitRemaining()
1177
+ }
1178
+ ```
1179
+
1127
1180
  ---
1128
1181
 
1129
1182
  # 💅 Client Side
@@ -0,0 +1,9 @@
1
+ import { RequestController } from './RequestController';
2
+ export declare class ApiLimitsHandler {
3
+ private readonly requestController;
4
+ constructor(requestController: RequestController);
5
+ private getLastResponseHeadersFromController;
6
+ areLimitsAvailable(): boolean;
7
+ getRateLimit(): number;
8
+ getRateLimitRemaining(): number;
9
+ }
@@ -0,0 +1,8 @@
1
+ import * as T from './types/MetadataSchemas';
2
+ import type { RequestController } from './RequestController';
3
+ export declare class MetadataSchemas {
4
+ private client;
5
+ constructor(client: RequestController);
6
+ list(): Promise<T.MetadataSchemasListResponse>;
7
+ get(schemaName: string): Promise<T.MetadataSchema>;
8
+ }
@@ -11,7 +11,12 @@ export declare class RequestController {
11
11
  private basePath;
12
12
  private headers;
13
13
  private request;
14
+ private lastResponseHeaders;
15
+ private isLastResponseHeadersSet;
14
16
  constructor({ basePath, baseURL, headers }: RequestControllerOptions);
17
+ isLastReponseHeadersSet(): boolean;
18
+ getLastResponseHeaders(): Record<string, string>;
19
+ private setLastResponseHeaders;
15
20
  setBaseUrl(baseURL: string): void;
16
21
  get<T>(path: string, params?: Record<string, any>): Promise<T>;
17
22
  post<T>(path: string, body: Record<string, any>, params?: Record<string, any>, headers?: Record<string, any>): Promise<T>;
@@ -14,6 +14,8 @@ import { Rewards } from './Rewards';
14
14
  import { Loyalties } from './Loyalties';
15
15
  import { ValidationRules } from './ValidationRules';
16
16
  import { Segments } from './Segments';
17
+ import { ApiLimitsHandler } from './ApiLimitsHandler';
18
+ import { MetadataSchemas } from './MetadataSchemas';
17
19
  export interface VoucherifyServerSideOptions {
18
20
  /**
19
21
  * Optionally, you can add `apiUrl` to the client options if you want to use Voucherify running in a specific region.
@@ -108,4 +110,6 @@ export declare function VoucherifyServerSide(options: VoucherifyServerSideOption
108
110
  validationRules: ValidationRules;
109
111
  events: Events;
110
112
  asyncActions: AsyncActions;
113
+ apiLimitsHandler: ApiLimitsHandler;
114
+ metadataSchemas: MetadataSchemas;
111
115
  };
@@ -19,9 +19,11 @@ export interface DiscountUnit {
19
19
  export interface DiscountAmount {
20
20
  type?: DiscountVouchersTypesEnum.AMOUNT;
21
21
  amount_off?: number;
22
+ effect?: DiscountAmountVouchersEffectTypes;
22
23
  }
23
24
  export interface DiscountPercent {
24
25
  type?: DiscountVouchersTypesEnum.PERCENT;
25
26
  percent_off?: number;
26
27
  amount_limit?: number;
28
+ effect?: DiscountPercentVouchersEffectTypes;
27
29
  }
@@ -0,0 +1,33 @@
1
+ interface MetadataSchemaProperty {
2
+ type: string;
3
+ array: boolean;
4
+ deleted?: boolean;
5
+ optional: boolean;
6
+ objectType?: string;
7
+ eq?: (string | number)[];
8
+ ne?: (string | number)[];
9
+ lt?: number;
10
+ lte?: number;
11
+ gt?: number;
12
+ gte?: number;
13
+ minLength?: number;
14
+ maxLength?: number;
15
+ exactLength?: number;
16
+ }
17
+ export interface MetadataSchema {
18
+ id: string;
19
+ related_object: string;
20
+ properties: Record<string, MetadataSchemaProperty>;
21
+ allow_defined_only?: boolean;
22
+ created_at: string;
23
+ updated_at?: string;
24
+ object: 'metadata_schema';
25
+ }
26
+ export interface MetadataSchemasListResponse {
27
+ object: 'list';
28
+ total: number;
29
+ data_ref: 'schemas';
30
+ schemas: MetadataSchema[];
31
+ }
32
+ export declare type MetadataSchemasGetResponse = MetadataSchema;
33
+ export {};
@@ -7,6 +7,8 @@ export interface OrdersItem {
7
7
  quantity?: number;
8
8
  price?: number;
9
9
  amount?: number;
10
+ discount_amount?: number;
11
+ applied_discount_amount?: number;
10
12
  product?: {
11
13
  override?: boolean;
12
14
  name?: string;
@@ -31,6 +31,7 @@ export interface ValidationsValidateVoucherParams {
31
31
  }
32
32
  export interface ValidationsValidateVoucherResponse {
33
33
  applicable_to?: ApplicableToResultList;
34
+ inapplicable_to?: ApplicableToResultList;
34
35
  campaign?: string;
35
36
  campaign_id?: string;
36
37
  metadata?: Record<string, any>;
@@ -51,6 +52,8 @@ export interface ValidationsValidateVoucherResponse {
51
52
  total_amount: number;
52
53
  items?: OrdersItem[];
53
54
  };
55
+ start_date?: string;
56
+ expiration_date?: string;
54
57
  tracking_id: string;
55
58
  }
56
59
  export interface ValidationsValidateStackableParams {
@@ -44,9 +44,13 @@ class RequestController {
44
44
  this.basePath = void 0;
45
45
  this.headers = void 0;
46
46
  this.request = void 0;
47
+ this.lastResponseHeaders = void 0;
48
+ this.isLastResponseHeadersSet = void 0;
47
49
  this.basePath = basePath;
48
50
  this.baseURL = baseURL;
49
51
  this.headers = headers;
52
+ this.lastResponseHeaders = {};
53
+ this.isLastResponseHeadersSet = false;
50
54
  this.request = axios.create({
51
55
  baseURL: `${this.baseURL}/${this.basePath}/`,
52
56
  headers: this.headers,
@@ -66,6 +70,19 @@ class RequestController {
66
70
  });
67
71
  }
68
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
+
69
86
  setBaseUrl(baseURL) {
70
87
  this.baseURL = baseURL;
71
88
  this.request.defaults.baseURL = `${baseURL}/${this.basePath}/`;
@@ -78,6 +95,7 @@ class RequestController {
78
95
  return Qs.stringify(params);
79
96
  }
80
97
  });
98
+ this.setLastResponseHeaders(response.headers);
81
99
  return response.data;
82
100
  }
83
101
 
@@ -89,6 +107,7 @@ class RequestController {
89
107
  },
90
108
  headers
91
109
  });
110
+ this.setLastResponseHeaders(response.headers);
92
111
  return response.data;
93
112
  }
94
113
 
@@ -96,6 +115,7 @@ class RequestController {
96
115
  const response = await this.request.put(path, body, {
97
116
  params
98
117
  });
118
+ this.setLastResponseHeaders(response.headers);
99
119
  return response.data;
100
120
  }
101
121
 
@@ -103,6 +123,7 @@ class RequestController {
103
123
  const response = await this.request.delete(path, {
104
124
  params
105
125
  });
126
+ this.setLastResponseHeaders(response.headers);
106
127
  return response.data;
107
128
  }
108
129
 
@@ -1307,12 +1328,60 @@ class Segments {
1307
1328
 
1308
1329
  }
1309
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
1310
1378
  // campaigns: Campaigns
1311
1379
  // consents: Consents
1312
1380
  // customers: Customers
1313
1381
  // distributions: Distributions
1314
1382
  // events: Events
1315
1383
  // loyalties: Loyalties
1384
+ // metadataSchemas: MetadataSchemas
1316
1385
  // orders: Orders
1317
1386
  // products: Products
1318
1387
  // promotions: Promotions
@@ -1335,7 +1404,7 @@ function VoucherifyServerSide(options) {
1335
1404
  let headers = {
1336
1405
  'X-App-Id': options.applicationId,
1337
1406
  'X-App-Token': options.secretKey,
1338
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.4"}`,
1407
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.0.7"}`,
1339
1408
  'Content-Type': 'application/json'
1340
1409
  };
1341
1410
 
@@ -1381,6 +1450,8 @@ function VoucherifyServerSide(options) {
1381
1450
  const loyalties = new Loyalties(client);
1382
1451
  const segments = new Segments(client);
1383
1452
  const validationRules = new ValidationRules(client);
1453
+ const apiLimitsHandler = new ApiLimitsHandler(client);
1454
+ const metadataSchemas = new MetadataSchemas(client);
1384
1455
  return {
1385
1456
  vouchers,
1386
1457
  campaigns,
@@ -1397,7 +1468,9 @@ function VoucherifyServerSide(options) {
1397
1468
  segments,
1398
1469
  validationRules,
1399
1470
  events,
1400
- asyncActions
1471
+ asyncActions,
1472
+ apiLimitsHandler,
1473
+ metadataSchemas
1401
1474
  };
1402
1475
  }
1403
1476
 
@@ -1580,7 +1653,7 @@ function VoucherifyClientSide(options) {
1580
1653
  let headers = {
1581
1654
  'X-Client-Application-Id': options.clientApplicationId,
1582
1655
  'X-Client-Token': options.clientSecretKey,
1583
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.4"}`
1656
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.0.7"}`
1584
1657
  };
1585
1658
 
1586
1659
  if (environment().startsWith('Node')) {