@voucherify/sdk 2.2.6 → 2.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @voucherify/sdk
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`644aa84`](https://github.com/voucherifyio/voucherify-js-sdk/commit/644aa8479843b8625192aa295eb07aa19ba651d7) [#227](https://github.com/voucherifyio/voucherify-js-sdk/pull/227) Thanks [@marcin-slezak](https://github.com/marcin-slezak)! - Added support for missing CSV import endpoints ([(examples of usage available in readme.md)](..%2F..%2Fpackages%2Fsdk%2FREADME.md)):
8
+ - `POST /skus/importCSV`
9
+ - `POST /products/importCSV`
10
+ - `POST /vouchers/importCSV`
11
+ - `POST /customers/importCSV`
12
+ - `POST /campaigns/campaignId/importCSV`
13
+ - Added form-data `4.0.0` to SDK package
14
+
15
+ * [`7720e31`](https://github.com/voucherifyio/voucherify-js-sdk/commit/7720e31baea0db19a7543ae12661fab77176e5ff) [#228](https://github.com/voucherifyio/voucherify-js-sdk/pull/228) Thanks [@marcin-slezak](https://github.com/marcin-slezak)! - Add missing methods covering Categories and Campaigns API.
16
+ - Added support for new endpoints [(examples of usage available in readme.md)](..%2F..%2Fpackages%2Fsdk%2FREADME.md):
17
+ - `POST /campaigns/campaignId/enable`,
18
+ - `POST /campaigns/campaignId/disable`,
19
+ - `GET, POST DELETE /categories`,
20
+ - `GET PUT /categories/id`.
21
+ - New exported types/interfaces in `Categories.ts`:
22
+ - `ListCategories`,
23
+ - `CategoryObject`,
24
+ - `CreateCategory`,
25
+ - `ResponseCreateCategory`,
26
+ - `ResponseUpdateCategory`,
27
+ - `UpdateCategoryRequest`.
28
+
29
+ - [`52e7f5e`](https://github.com/voucherifyio/voucherify-js-sdk/commit/52e7f5e8d4ea6be4ba1b9d0550cba3ec3d893672) [#221](https://github.com/voucherifyio/voucherify-js-sdk/pull/221) Thanks [@p-zielinski](https://github.com/p-zielinski)! - Implementing the following changes:
30
+ - Update axios from `0.21.4` to `0.27.2` in SDK package
31
+ - Added dotenv `16.3.1` to SDK package dev dependencies.
32
+ - Added frame for integration tests [(more info available in README.md, section "🧪 SDK Tests")](..%2F..%2FREADME.md)
33
+
3
34
  ## 2.2.6
4
35
 
5
36
  ### Patch Changes
package/README.md CHANGED
@@ -154,6 +154,7 @@ Methods are provided within `client.vouchers.*` namespace.
154
154
  - [Update Vouchers Metadata in bulk](#update-vouchers-metadata-in-bulk)
155
155
  - [Update Vouchers in bulk](#update-vouchers-in-bulk)
156
156
  - [Release Validation Session](#release-validation-session)
157
+ - [Import Vouchers using CSV](#import-vouchers-using-csv)
157
158
 
158
159
  #### [Create Voucher](https://docs.voucherify.io/reference/create-voucher)
159
160
 
@@ -237,6 +238,12 @@ client.vouchers.bulkUpdate(vouchers)
237
238
  client.vouchers.releaseValidationSession(code, sessionKey)
238
239
  ```
239
240
 
241
+ #### [Import Vouchers using CSV](https://docs.voucherify.io/reference/import-vouchers-using-csv)
242
+
243
+ ```javascript
244
+ client.vouchers.importCSV(filePath)
245
+ ```
246
+
240
247
  ---
241
248
 
242
249
  ### Campaigns
@@ -249,7 +256,10 @@ Methods are provided within `client.campaigns.*` namespace.
249
256
  - [Add Voucher to Campaign](#add-voucher-to-campaign)
250
257
  - [Import Vouchers to Campaign](#import-vouchers-to-campaign)
251
258
  - [List Campaigns](#list-campaigns)
259
+ - [Import Vouchers using CSV](#import-vouchers-using-csv)
252
260
  - [Examine Campaigns Qualification](#examine-campaigns-qualification)
261
+ - [Enable campaign](#enable-campaign)
262
+ - [Disable campaign](#disable-campaign)
253
263
 
254
264
  #### [Create Campaign](https://docs.voucherify.io/reference/create-campaign)
255
265
 
@@ -307,13 +317,30 @@ client.campaigns.list()
307
317
  client.campaigns.list(params)
308
318
  ```
309
319
 
320
+ #### [Import Vouchers to Campaign by CSV](https://docs.voucherify.io/reference/import-vouchers-to-campaign-using-csv)
321
+
322
+ ```javascript
323
+ client.campaigns.importVouchersCSV(campaignId, filePath)
324
+ ```
325
+
326
+ #### [Enable campaign](https://docs.voucherify.io/reference/enable-campaign)
327
+
328
+ ```javascript
329
+ client.campaigns.enable(campaignId)
330
+ ```
331
+
332
+ #### [Disable campaign](https://docs.voucherify.io/reference/disable-campaign)
333
+
334
+ ```javascript
335
+ client.campaigns.disable(campaignId)
336
+ ```
337
+
310
338
  #### [Examine Campaigns Qualification](https://docs.voucherify.io/reference/create-qualification-request)
311
339
 
312
340
  ```javascript
313
341
  client.campaigns.qualifications.examine(body)
314
342
  client.campaigns.qualifications.examine(body, params)
315
343
  ```
316
-
317
344
  ---
318
345
 
319
346
  ### Distributions
@@ -359,6 +386,46 @@ client.distributions.publications.list(params)
359
386
  client.distributions.publications.create(params)
360
387
  ```
361
388
 
389
+ ### Categories
390
+
391
+ Methods are provided within `client.categories.*` namespace.
392
+
393
+ - [Create Category](#create-category)
394
+ - [Update Category](#update-category)
395
+ - [Get Category](#get-category)
396
+ - [Delete Category](#delete-category)
397
+ - [List Categories](#list-categories)
398
+
399
+ #### [Create Category](https://docs.voucherify.io/reference/create-category)
400
+
401
+ ```javascript
402
+ client.categories.create(params)
403
+ ```
404
+
405
+ #### [Update Category](https://docs.voucherify.io/reference/update-category)
406
+
407
+ ```javascript
408
+ client.categories.update(categoryId, params)
409
+ ```
410
+
411
+ #### [Get Category](https://docs.voucherify.io/reference/get-category)
412
+
413
+ ```javascript
414
+ client.categories.get(categoryId)
415
+ ```
416
+
417
+ #### [Delete Category](https://docs.voucherify.io/reference/delete-category)
418
+
419
+ ```javascript
420
+ client.categories.delete(categoryId)
421
+ ```
422
+
423
+ #### [List Categories](https://docs.voucherify.io/reference/list-categories)
424
+
425
+ ```javascript
426
+ client.categories.list()
427
+ ```
428
+
362
429
  ---
363
430
 
364
431
  ### Validations
@@ -547,6 +614,7 @@ Methods are provided within `client.customers.*` namespace.
547
614
  - [List Customers](#list-customers)
548
615
  - [Update Customer's Consents](#update-customers-consents)
549
616
  - [List Customer's Activities](#list-customers-activities)
617
+ - [Import and Update Customers using CSV](#import-and-update-customers-using-csv)
550
618
 
551
619
  #### [Create Customer](https://docs.voucherify.io/reference/create-customer)
552
620
 
@@ -628,6 +696,12 @@ client.customers.listActivities(customerId)
628
696
  client.customers.listActivities(customerId, params)
629
697
  ```
630
698
 
699
+ #### [Import and Update Customers using CSV](https://docs.voucherify.io/reference/import-customers-using-csv)
700
+
701
+ ```javascript
702
+ client.customers.importCSV(filePath)
703
+ ```
704
+
631
705
  ---
632
706
 
633
707
  ### Consents
@@ -707,6 +781,8 @@ Methods are provided within `client.products.*` namespace.
707
781
  - [Update SKU](#update-sku)
708
782
  - [Delete SKU](#delete-sku)
709
783
  - [List all product SKUs](#list-all-product-skus)
784
+ - [Import SKUs using CSV](#import-skus-using-csv)
785
+ - [Import Products using CSV](#import-products-using-csv)
710
786
 
711
787
  #### [Create Product](https://docs.voucherify.io/reference/create-product)
712
788
 
@@ -781,6 +857,18 @@ client.products.deleteSku(productId, skuId, { force: true })
781
857
  client.products.listSkus(productId)
782
858
  ```
783
859
 
860
+ #### [Import SKUs using CSV](https://docs.voucherify.io/reference/import-skus-using-csv)
861
+
862
+ ```javascript
863
+ client.products.importSkusCSV(filePath)
864
+ ```
865
+
866
+ #### [Import Products using CSV](https://docs.voucherify.io/reference/import-products-using-csv)
867
+
868
+ ```javascript
869
+ client.products.importCSV(filePath)
870
+ ```
871
+
784
872
  ---
785
873
 
786
874
  ### Rewards
@@ -1,4 +1,5 @@
1
1
  import * as T from './types/Campaigns';
2
+ import * as AAT from './types/AsyncActions';
2
3
  import type { RequestController } from './RequestController';
3
4
  declare class CampaignsQualifications {
4
5
  private client;
@@ -41,5 +42,17 @@ export declare class Campaigns {
41
42
  * @see https://docs.voucherify.io/reference/list-campaigns
42
43
  */
43
44
  list(params?: T.CampaignsListParams): Promise<T.CampaignsListResponse>;
45
+ /**
46
+ * @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
47
+ */
48
+ importVouchersCSV(campaignId: string, filePath: string): Promise<AAT.AsyncActionCreateResponse>;
49
+ /**
50
+ * @see https://docs.voucherify.io/reference/enable-campaign
51
+ */
52
+ enable(campaignId: string): Promise<{}>;
53
+ /**
54
+ * @see https://docs.voucherify.io/reference/disable-campaign
55
+ */
56
+ disable(campaignId: string): Promise<{}>;
44
57
  }
45
58
  export {};
@@ -0,0 +1,26 @@
1
+ import * as T from './types/Categories';
2
+ import type { RequestController } from './RequestController';
3
+ export declare class Categories {
4
+ private client;
5
+ constructor(client: RequestController);
6
+ /**
7
+ * @see https://docs.voucherify.io/reference/list-categories
8
+ */
9
+ list(): Promise<T.ListCategories>;
10
+ /**
11
+ * @see https://docs.voucherify.io/reference/create-category
12
+ */
13
+ create(createCategory: T.CreateCategory): Promise<T.ResponseCreateCategory>;
14
+ /**
15
+ * @see https://docs.voucherify.io/reference/get-category
16
+ */
17
+ get(categoryId: string): Promise<T.CategoryObject>;
18
+ /**
19
+ * @see https://docs.voucherify.io/reference/delete-category
20
+ */
21
+ delete(categoryId: string): Promise<{}>;
22
+ /**
23
+ * @see https://docs.voucherify.io/reference/update-category
24
+ */
25
+ update(categoryId: string, updateCategory: T.UpdateCategoryRequest): Promise<T.ResponseUpdateCategory>;
26
+ }
@@ -1,4 +1,5 @@
1
1
  import * as T from './types/Customers';
2
+ import * as AAT from './types/AsyncActions';
2
3
  import type { RequestController } from './RequestController';
3
4
  declare class Customers {
4
5
  private client;
@@ -43,5 +44,9 @@ declare class Customers {
43
44
  * @see https://docs.voucherify.io/reference/get-customer-activities
44
45
  */
45
46
  listActivities(customerId: string, params?: T.CustomerActivitiesListQueryParams): Promise<T.CustomerActivitiesListResponse>;
47
+ /**
48
+ * @see https://docs.voucherify.io/reference/import-customers-using-csv
49
+ */
50
+ importCSV(filePath: string): Promise<AAT.AsyncActionCreateResponse>;
46
51
  }
47
52
  export { Customers };
@@ -1,4 +1,5 @@
1
1
  import * as T from './types/Products';
2
+ import * as AAT from './types/AsyncActions';
2
3
  import type { RequestController } from './RequestController';
3
4
  export declare class Products {
4
5
  private client;
@@ -51,4 +52,12 @@ export declare class Products {
51
52
  * @see https://docs.voucherify.io/reference/list-skus
52
53
  */
53
54
  listSkus(productId: string): Promise<T.ProductsListSkus>;
55
+ /**
56
+ * @see https://docs.voucherify.io/reference/import-skus-using-csv
57
+ */
58
+ importSkusCSV(filePath: string): Promise<AAT.AsyncActionCreateResponse>;
59
+ /**
60
+ * @see https://docs.voucherify.io/reference/import-products-using-csv
61
+ */
62
+ importCSV(filePath: string): Promise<AAT.AsyncActionCreateResponse>;
54
63
  }
@@ -16,6 +16,7 @@ import { ValidationRules } from './ValidationRules';
16
16
  import { Segments } from './Segments';
17
17
  import { ApiLimitsHandler } from './ApiLimitsHandler';
18
18
  import { MetadataSchemas } from './MetadataSchemas';
19
+ import { Categories } from './Categories';
19
20
  export interface VoucherifyServerSideOptions {
20
21
  /**
21
22
  * Optionally, you can add `apiUrl` to the client options if you want to use Voucherify running in a specific region.
@@ -106,6 +107,7 @@ export interface VoucherifyServerSideOptions {
106
107
  export declare function VoucherifyServerSide(options: VoucherifyServerSideOptions): {
107
108
  vouchers: Vouchers;
108
109
  campaigns: Campaigns;
110
+ categories: Categories;
109
111
  distributions: Distributions;
110
112
  validations: Validations;
111
113
  redemptions: Redemptions;
@@ -1,4 +1,5 @@
1
1
  import * as T from './types/Vouchers';
2
+ import * as AAT from './types/AsyncActions';
2
3
  import type { RequestController } from './RequestController';
3
4
  import type { Balance } from './Balance';
4
5
  declare class VouchersQualification {
@@ -61,5 +62,9 @@ export declare class Vouchers {
61
62
  * @see https://docs.voucherify.io/reference/release-validation-session
62
63
  */
63
64
  releaseValidationSession(code: string, sessionKey: string): Promise<unknown>;
65
+ /**
66
+ * @see https://docs.voucherify.io/reference/import-vouchers-using-csv
67
+ */
68
+ importCSV(filePath: string): Promise<AAT.AsyncActionCreateResponse>;
64
69
  }
65
70
  export {};
@@ -0,0 +1,24 @@
1
+ export interface ListCategories {
2
+ object: 'list';
3
+ data_ref: 'data';
4
+ data: CategoryObject[];
5
+ total: number;
6
+ }
7
+ export declare type CategoryObject = ResponseCreateCategory & {
8
+ updated_at?: string;
9
+ };
10
+ export interface CreateCategory {
11
+ name: string;
12
+ hierarchy: number;
13
+ }
14
+ export interface ResponseCreateCategory {
15
+ id: string;
16
+ name: string;
17
+ hierarchy: number;
18
+ created_at: string;
19
+ object: 'category';
20
+ }
21
+ export declare type ResponseUpdateCategory = ResponseCreateCategory & {
22
+ updated_at: string;
23
+ };
24
+ export declare type UpdateCategoryRequest = CreateCategory;
@@ -1,5 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import Qs from 'qs';
3
+ import FormData from 'form-data';
3
4
 
4
5
  var DiscountVouchersTypesEnum;
5
6
 
@@ -311,6 +312,35 @@ class Campaigns {
311
312
  list(params = {}) {
312
313
  return this.client.get('/campaigns', params);
313
314
  }
315
+ /**
316
+ * @see https://api.voucherify.io/v1/campaigns/{campaignId}/importCSV
317
+ */
318
+
319
+
320
+ async importVouchersCSV(campaignId, filePath) {
321
+ assert(environment().startsWith('Node'), `Method "client.campaigns.importVouchersCSV(campaignId, filePath)" is only for Node environment`);
322
+ const fs = (await import('fs')).default;
323
+ const fileStream = fs.createReadStream(filePath);
324
+ const form = new FormData();
325
+ form.append('file', fileStream);
326
+ return this.client.post(`/campaigns/${campaignId}/importCSV`, form);
327
+ }
328
+ /**
329
+ * @see https://docs.voucherify.io/reference/enable-campaign
330
+ */
331
+
332
+
333
+ enable(campaignId) {
334
+ return this.client.post(`/campaigns/${encode(campaignId)}/enable`, {});
335
+ }
336
+ /**
337
+ * @see https://docs.voucherify.io/reference/disable-campaign
338
+ */
339
+
340
+
341
+ disable(campaignId) {
342
+ return this.client.post(`/campaigns/${encode(campaignId)}/disable`, {});
343
+ }
314
344
 
315
345
  }
316
346
 
@@ -535,6 +565,19 @@ class Vouchers {
535
565
  releaseValidationSession(code, sessionKey) {
536
566
  return this.client.delete(`/vouchers/${encode(code)}/sessions/${encode(sessionKey)}`);
537
567
  }
568
+ /**
569
+ * @see https://docs.voucherify.io/reference/import-vouchers-using-csv
570
+ */
571
+
572
+
573
+ async importCSV(filePath) {
574
+ assert(environment().startsWith('Node'), `Method "client.vouchers.importCSV(filePath)" is only for Node environment`);
575
+ const fs = (await import('fs')).default;
576
+ const fileStream = fs.createReadStream(filePath);
577
+ const form = new FormData();
578
+ form.append('file', fileStream);
579
+ return this.client.post('/vouchers/importCSV', form);
580
+ }
538
581
 
539
582
  }
540
583
 
@@ -850,6 +893,19 @@ class Customers {
850
893
  listActivities(customerId, params) {
851
894
  return this.client.get(`/customers/${encode(customerId)}/activities`, params);
852
895
  }
896
+ /**
897
+ * @see https://docs.voucherify.io/reference/import-customers-using-csv
898
+ */
899
+
900
+
901
+ async importCSV(filePath) {
902
+ assert(environment().startsWith('Node'), `Method "client.customers.importCSV(filePath)" is only for Node environment`);
903
+ const fs = (await import('fs')).default;
904
+ const fileStream = fs.createReadStream(filePath);
905
+ const form = new FormData();
906
+ form.append('file', fileStream);
907
+ return this.client.post(`/customers/importCSV`, form);
908
+ }
853
909
 
854
910
  }
855
911
 
@@ -1018,6 +1074,32 @@ class Products {
1018
1074
  listSkus(productId) {
1019
1075
  return this.client.get(`/products/${encode(productId)}/skus`);
1020
1076
  }
1077
+ /**
1078
+ * @see https://docs.voucherify.io/reference/import-skus-using-csv
1079
+ */
1080
+
1081
+
1082
+ async importSkusCSV(filePath) {
1083
+ assert(environment().startsWith('Node'), `Method "client.products.importSkusCSV(filePath)" is only for Node environment`);
1084
+ const fs = (await import('fs')).default;
1085
+ const fileStream = fs.createReadStream(filePath);
1086
+ const form = new FormData();
1087
+ form.append('file', fileStream);
1088
+ return this.client.post(`/skus/importCSV`, form);
1089
+ }
1090
+ /**
1091
+ * @see https://docs.voucherify.io/reference/import-products-using-csv
1092
+ */
1093
+
1094
+
1095
+ async importCSV(filePath) {
1096
+ assert(environment().startsWith('Node'), `Method "client.products.importCSV(filePath)" is only for Node environment`);
1097
+ const fs = (await import('fs')).default;
1098
+ const fileStream = fs.createReadStream(filePath);
1099
+ const form = new FormData();
1100
+ form.append('file', fileStream);
1101
+ return this.client.post(`/products/importCSV`, form);
1102
+ }
1021
1103
 
1022
1104
  }
1023
1105
 
@@ -1434,6 +1516,54 @@ class MetadataSchemas {
1434
1516
 
1435
1517
  }
1436
1518
 
1519
+ class Categories {
1520
+ constructor(client) {
1521
+ this.client = void 0;
1522
+ this.client = client;
1523
+ }
1524
+ /**
1525
+ * @see https://docs.voucherify.io/reference/list-categories
1526
+ */
1527
+
1528
+
1529
+ list() {
1530
+ return this.client.get('/categories');
1531
+ }
1532
+ /**
1533
+ * @see https://docs.voucherify.io/reference/create-category
1534
+ */
1535
+
1536
+
1537
+ create(createCategory) {
1538
+ return this.client.post('/categories', createCategory);
1539
+ }
1540
+ /**
1541
+ * @see https://docs.voucherify.io/reference/get-category
1542
+ */
1543
+
1544
+
1545
+ get(categoryId) {
1546
+ return this.client.get(`/categories/${encode(categoryId)}`);
1547
+ }
1548
+ /**
1549
+ * @see https://docs.voucherify.io/reference/delete-category
1550
+ */
1551
+
1552
+
1553
+ delete(categoryId) {
1554
+ return this.client.delete(`/categories/${encode(categoryId)}`);
1555
+ }
1556
+ /**
1557
+ * @see https://docs.voucherify.io/reference/update-category
1558
+ */
1559
+
1560
+
1561
+ update(categoryId, updateCategory) {
1562
+ return this.client.put(`/categories/${encode(categoryId)}`, updateCategory);
1563
+ }
1564
+
1565
+ }
1566
+
1437
1567
  // apiLimitsHandler: ApiLimitsHandler
1438
1568
  // campaigns: Campaigns
1439
1569
  // consents: Consents
@@ -1464,7 +1594,7 @@ function VoucherifyServerSide(options) {
1464
1594
  let headers = {
1465
1595
  'X-App-Id': options.applicationId,
1466
1596
  'X-App-Token': options.secretKey,
1467
- 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.2.6"}`,
1597
+ 'X-Voucherify-Channel': options.channel || `${environment()}-SDK-v${"2.3.0"}`,
1468
1598
  'Content-Type': 'application/json'
1469
1599
  };
1470
1600
 
@@ -1497,6 +1627,7 @@ function VoucherifyServerSide(options) {
1497
1627
  const balance = new Balance(client);
1498
1628
  const vouchers = new Vouchers(client, balance);
1499
1629
  const campaigns = new Campaigns(client);
1630
+ const categories = new Categories(client);
1500
1631
  const exportsNamespace = new Exports(client);
1501
1632
  const events = new Events(client);
1502
1633
  const distributions = new Distributions(client, exportsNamespace);
@@ -1517,6 +1648,7 @@ function VoucherifyServerSide(options) {
1517
1648
  return {
1518
1649
  vouchers,
1519
1650
  campaigns,
1651
+ categories,
1520
1652
  distributions,
1521
1653
  validations,
1522
1654
  redemptions,
@@ -1715,7 +1847,7 @@ function VoucherifyClientSide(options) {
1715
1847
  let headers = {
1716
1848
  'X-Client-Application-Id': options.clientApplicationId,
1717
1849
  'X-Client-Token': options.clientSecretKey,
1718
- 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.2.6"}`
1850
+ 'X-Voucherify-Channel': `${environment()}-ClientSide-SDK-v${"2.3.0"}`
1719
1851
  };
1720
1852
 
1721
1853
  if (environment().startsWith('Node')) {