goods-exporter 1.4.2 → 1.4.3

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/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2023 German Bagdasaryan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- “Software”), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2023 German Bagdasaryan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ “Software”), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,106 +1,106 @@
1
- # goods-exporter
2
-
3
- [![npm version](https://img.shields.io/npm/v/goods-exporter)](https://www.npmjs.com/package/goods-exporter)
4
- ![npm](https://img.shields.io/npm/dm/goods-exporter)
5
- ![GitHub issues](https://img.shields.io/github/issues/Bagi4-source/goods-converter)
6
- [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
7
-
8
- A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
9
- export tasks with ease.
10
-
11
- [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
12
-
13
- ## Features
14
-
15
- - Export goods data to JSON, YML, CSV, and Excel formats.
16
- - Easily integrate into your JavaScript projects.
17
- - Compatible with Node.js version 16 and above.
18
- - Comprehensive TypeScript type definitions included.
19
- - Supports streams.
20
-
21
- ## Supported formats
22
-
23
- - YML (Yandex Market Language)
24
- - JSON
25
- - SimpleJSON (grouped)
26
- - CSV
27
- - Excel
28
- - TgShop
29
- - Insales
30
- - Tilda
31
- - WooCommerce
32
-
33
- ## Installation
34
-
35
- To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
36
-
37
- ```bash
38
- npm install goods-exporter --save
39
- # or
40
- yarn add goods-exporter
41
- ```
42
-
43
- ## Quick start
44
-
45
- ```typescript
46
- import { GoodsExporter, Product, Category, Formatters } from "../src";
47
- import { PassThrough } from "stream";
48
-
49
- // Create an instance of the GoodsExporter class.
50
- const exporter = new GoodsExporter();
51
-
52
- const products: Product[] = []; // Put your products;
53
- const categories: Category[] = [{ id: 1, name: "Обувь" }];
54
-
55
- // Call the data export method.
56
- const stream = new PassThrough();
57
- exporter.setExporter(() => stream);
58
- exporter.setFormatter(new Formatters.YMLFormatter());
59
- exporter.setTransformers([
60
- (products) => {
61
- return products.map((product) => ({
62
- ...product,
63
- price: product.price + 10000,
64
- images: product.images?.map((image) => image.replace("image", "pic")),
65
- }));
66
- },
67
- ]);
68
- await exporter.export(products, categories);
69
- ```
70
-
71
- ## Example
72
-
73
- ```typescript
74
- import fs from "fs"; // Import the 'fs' module for file writing.
75
-
76
- // Create an instance of the GoodsExporter class.
77
- const exporter = new GoodsExporter();
78
-
79
- // Define an object 'transformers' that contains data transformation functions.
80
- const transformers: Transformer[] = [
81
- (products) =>
82
- products.map((product) => ({
83
- ...product,
84
- price: product.price + 10000,
85
- })),
86
- (products) =>
87
- products.map((product) => ({
88
- ...product,
89
- images: product.images?.map((image) => image.replace("image", "pic")),
90
- })),
91
- ];
92
-
93
- // Set the formatter for exporting data to YML.
94
- exporter.setFormatter(new Formatters.YMLFormatter()); // or your own Formatter;
95
-
96
- // Set transformers based on the specified keys.
97
- exporter.setTransformers(transformers);
98
-
99
- // Set an exporter that saves the data to the "output.yml" file.
100
- exporter.setExporter(fs.createWriteStream("output.yml"));
101
- await exporter.export(products, categories);
102
- ```
103
-
104
- # Supported by [PoizonAPI](https://t.me/PoizonAPI)
105
-
106
- [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI)
1
+ # goods-exporter
2
+
3
+ [![npm version](https://img.shields.io/npm/v/goods-exporter)](https://www.npmjs.com/package/goods-exporter)
4
+ ![npm](https://img.shields.io/npm/dm/goods-exporter)
5
+ ![GitHub issues](https://img.shields.io/github/issues/Bagi4-source/goods-converter)
6
+ [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
7
+
8
+ A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
9
+ export tasks with ease.
10
+
11
+ [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
12
+
13
+ ## Features
14
+
15
+ - Export goods data to JSON, YML, CSV, and Excel formats.
16
+ - Easily integrate into your JavaScript projects.
17
+ - Compatible with Node.js version 16 and above.
18
+ - Comprehensive TypeScript type definitions included.
19
+ - Supports streams.
20
+
21
+ ## Supported formats
22
+
23
+ - YML (Yandex Market Language)
24
+ - JSON
25
+ - SimpleJSON (grouped)
26
+ - CSV
27
+ - Excel
28
+ - TgShop
29
+ - Insales
30
+ - Tilda
31
+ - WooCommerce
32
+
33
+ ## Installation
34
+
35
+ To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
36
+
37
+ ```bash
38
+ npm install goods-exporter --save
39
+ # or
40
+ yarn add goods-exporter
41
+ ```
42
+
43
+ ## Quick start
44
+
45
+ ```typescript
46
+ import { GoodsExporter, Product, Category, Formatters } from "../src";
47
+ import { PassThrough } from "stream";
48
+
49
+ // Create an instance of the GoodsExporter class.
50
+ const exporter = new GoodsExporter();
51
+
52
+ const products: Product[] = []; // Put your products;
53
+ const categories: Category[] = [{ id: 1, name: "Обувь" }];
54
+
55
+ // Call the data export method.
56
+ const stream = new PassThrough();
57
+ exporter.setExporter(() => stream);
58
+ exporter.setFormatter(new Formatters.YMLFormatter());
59
+ exporter.setTransformers([
60
+ (products) => {
61
+ return products.map((product) => ({
62
+ ...product,
63
+ price: product.price + 10000,
64
+ images: product.images?.map((image) => image.replace("image", "pic")),
65
+ }));
66
+ },
67
+ ]);
68
+ await exporter.export(products, categories);
69
+ ```
70
+
71
+ ## Example
72
+
73
+ ```typescript
74
+ import fs from "fs"; // Import the 'fs' module for file writing.
75
+
76
+ // Create an instance of the GoodsExporter class.
77
+ const exporter = new GoodsExporter();
78
+
79
+ // Define an object 'transformers' that contains data transformation functions.
80
+ const transformers: Transformer[] = [
81
+ (products) =>
82
+ products.map((product) => ({
83
+ ...product,
84
+ price: product.price + 10000,
85
+ })),
86
+ (products) =>
87
+ products.map((product) => ({
88
+ ...product,
89
+ images: product.images?.map((image) => image.replace("image", "pic")),
90
+ })),
91
+ ];
92
+
93
+ // Set the formatter for exporting data to YML.
94
+ exporter.setFormatter(new Formatters.YMLFormatter()); // or your own Formatter;
95
+
96
+ // Set transformers based on the specified keys.
97
+ exporter.setTransformers(transformers);
98
+
99
+ // Set an exporter that saves the data to the "output.yml" file.
100
+ exporter.setExporter(fs.createWriteStream("output.yml"));
101
+ await exporter.export(products, categories);
102
+ ```
103
+
104
+ # Supported by [PoizonAPI](https://t.me/PoizonAPI)
105
+
106
+ [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI)
package/dist/bundle.d.ts CHANGED
@@ -648,6 +648,12 @@ declare class JSONFormatter implements FormatterAbstract {
648
648
  format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<void>;
649
649
  }
650
650
 
651
+ declare class PriceFormatter implements FormatterAbstract {
652
+ formatterName: string;
653
+ fileExtension: Extension;
654
+ format(writableStream: Writable, products: Product[], _categories?: Category[], _brands?: Brand[], _?: FormatterOptions): Promise<void>;
655
+ }
656
+
651
657
  declare class SimpleJSONFormatter implements FormatterAbstract {
652
658
  formatterName: string;
653
659
  fileExtension: Extension;
@@ -704,6 +710,7 @@ declare const Formatters: {
704
710
  SimpleJSONFormatter: typeof SimpleJSONFormatter;
705
711
  XMLFormatter: typeof XMLFormatter;
706
712
  WooCommerceFormatter: typeof WooCommerceFormatter;
713
+ PriceFormatter: typeof PriceFormatter;
707
714
  };
708
715
 
709
716
  type Transformer<Context> = (products: Product[], context: Context) => Product[] | Promise<Product[]>;
@@ -66,17 +66,17 @@ const urlQueryEncode = (inputUrl) => {
66
66
  }
67
67
  };
68
68
 
69
- var __defProp$b = Object.defineProperty;
70
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
71
- var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
69
+ var __defProp$c = Object.defineProperty;
70
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
71
+ var __publicField$c = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
72
72
  class CSVStream {
73
73
  constructor({ delimiter, lineSeparator, emptyFieldValue }) {
74
- __publicField$b(this, "stream", new stream$3.PassThrough());
75
- __publicField$b(this, "delimiter", ";");
76
- __publicField$b(this, "lineSeparator", "\n");
77
- __publicField$b(this, "emptyFieldValue", "");
78
- __publicField$b(this, "columns", /* @__PURE__ */ new Set());
79
- __publicField$b(this, "writer", writeWithDrain(this.stream));
74
+ __publicField$c(this, "stream", new stream$3.PassThrough());
75
+ __publicField$c(this, "delimiter", ";");
76
+ __publicField$c(this, "lineSeparator", "\n");
77
+ __publicField$c(this, "emptyFieldValue", "");
78
+ __publicField$c(this, "columns", /* @__PURE__ */ new Set());
79
+ __publicField$c(this, "writer", writeWithDrain(this.stream));
80
80
  if (delimiter !== void 0) this.delimiter = delimiter;
81
81
  if (lineSeparator !== void 0) this.lineSeparator = lineSeparator;
82
82
  if (emptyFieldValue !== void 0) this.emptyFieldValue = emptyFieldValue;
@@ -109,13 +109,13 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
109
109
  return Extension2;
110
110
  })(Extension || {});
111
111
 
112
- var __defProp$a = Object.defineProperty;
113
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
114
- var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
112
+ var __defProp$b = Object.defineProperty;
113
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
114
+ var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
115
115
  class CSVFormatter {
116
116
  constructor() {
117
- __publicField$a(this, "formatterName", "CSV");
118
- __publicField$a(this, "fileExtension", Extension.CSV);
117
+ __publicField$b(this, "formatterName", "CSV");
118
+ __publicField$b(this, "fileExtension", Extension.CSV);
119
119
  }
120
120
  async format(writableStream, products, categories, _, __) {
121
121
  const mappedCategories = {};
@@ -182,14 +182,14 @@ class CSVFormatter {
182
182
  }
183
183
  }
184
184
 
185
- var __defProp$9 = Object.defineProperty;
186
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
187
- var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
185
+ var __defProp$a = Object.defineProperty;
186
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
187
+ var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
188
188
  const { stream: stream$2 } = pkg;
189
189
  class ExcelFormatter {
190
190
  constructor() {
191
- __publicField$9(this, "formatterName", "Excel");
192
- __publicField$9(this, "fileExtension", Extension.XLSX);
191
+ __publicField$a(this, "formatterName", "Excel");
192
+ __publicField$a(this, "fileExtension", Extension.XLSX);
193
193
  }
194
194
  async format(writableStream, products, categories, _, __) {
195
195
  const mappedCategories = {};
@@ -258,14 +258,14 @@ class ExcelFormatter {
258
258
  }
259
259
  }
260
260
 
261
- var __defProp$8 = Object.defineProperty;
262
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
263
- var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
261
+ var __defProp$9 = Object.defineProperty;
262
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
263
+ var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
264
264
  const { stream: stream$1 } = pkg;
265
265
  class InsalesFormatter {
266
266
  constructor() {
267
- __publicField$8(this, "formatterName", "Insales");
268
- __publicField$8(this, "fileExtension", Extension.XLSX);
267
+ __publicField$9(this, "formatterName", "Insales");
268
+ __publicField$9(this, "fileExtension", Extension.XLSX);
269
269
  }
270
270
  async format(writableStream, products, categories, _, __) {
271
271
  const mappedCategories = {};
@@ -395,13 +395,13 @@ class InsalesFormatter {
395
395
  }
396
396
  }
397
397
 
398
- var __defProp$7 = Object.defineProperty;
399
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
400
- var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
398
+ var __defProp$8 = Object.defineProperty;
399
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
400
+ var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
401
401
  class JSONFormatter {
402
402
  constructor() {
403
- __publicField$7(this, "formatterName", "JSON");
404
- __publicField$7(this, "fileExtension", Extension.JSON);
403
+ __publicField$8(this, "formatterName", "JSON");
404
+ __publicField$8(this, "fileExtension", Extension.JSON);
405
405
  }
406
406
  async format(writableStream, products, categories, brands, _) {
407
407
  const stream = new jsonStreamStringify.JsonStreamStringify({
@@ -413,6 +413,44 @@ class JSONFormatter {
413
413
  }
414
414
  }
415
415
 
416
+ var __defProp$7 = Object.defineProperty;
417
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
418
+ var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
419
+ class PriceFormatter {
420
+ constructor() {
421
+ __publicField$7(this, "formatterName", "Price");
422
+ __publicField$7(this, "fileExtension", Extension.JSON);
423
+ }
424
+ async format(writableStream, products, _categories, _brands, _) {
425
+ const priceMap = /* @__PURE__ */ new Map();
426
+ products.forEach((product) => {
427
+ const existing = priceMap.get(product.productId);
428
+ const sku = {
429
+ skuId: String(product.variantId),
430
+ price: product.price,
431
+ currency: product.currency
432
+ };
433
+ if (product.timeDelivery?.min !== void 0 || product.timeDelivery?.max !== void 0) {
434
+ sku.timeDelivery = {
435
+ min: product.timeDelivery.min ?? 0,
436
+ max: product.timeDelivery.max ?? 0
437
+ };
438
+ }
439
+ if (existing) {
440
+ existing.skus.push(sku);
441
+ } else {
442
+ priceMap.set(product.productId, {
443
+ productId: product.productId,
444
+ skus: [sku]
445
+ });
446
+ }
447
+ });
448
+ const result = Array.from(priceMap.values());
449
+ const stream = new jsonStreamStringify.JsonStreamStringify(result);
450
+ stream.pipe(writableStream);
451
+ }
452
+ }
453
+
416
454
  var __defProp$6 = Object.defineProperty;
417
455
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
418
456
  var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -1010,7 +1048,8 @@ const Formatters = {
1010
1048
  JSONFormatter,
1011
1049
  SimpleJSONFormatter,
1012
1050
  XMLFormatter,
1013
- WooCommerceFormatter
1051
+ WooCommerceFormatter,
1052
+ PriceFormatter
1014
1053
  };
1015
1054
 
1016
1055
  var __defProp = Object.defineProperty;