goods-exporter 0.5.2 → 0.5.5
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 +21 -21
- package/README.md +103 -102
- package/dist/bundle.d.ts +14 -1
- package/dist/cjs/index.cjs +142 -114
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +142 -114
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +85 -86
package/dist/cjs/index.cjs
CHANGED
|
@@ -4,28 +4,21 @@ var stream$3 = require('stream');
|
|
|
4
4
|
var pkg = require('exceljs');
|
|
5
5
|
var jsonStreamStringify = require('json-stream-stringify');
|
|
6
6
|
var fastXmlParser = require('fast-xml-parser');
|
|
7
|
-
var xml = require('xml');
|
|
8
7
|
var fs = require('fs');
|
|
9
8
|
|
|
10
|
-
var __defProp$
|
|
11
|
-
var __defNormalProp$
|
|
12
|
-
var __publicField$
|
|
13
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
9
|
+
var __defProp$9 = Object.defineProperty;
|
|
10
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
16
12
|
class CSVStream {
|
|
17
13
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
18
|
-
__publicField$
|
|
19
|
-
__publicField$
|
|
20
|
-
__publicField$
|
|
21
|
-
__publicField$
|
|
22
|
-
__publicField$
|
|
23
|
-
if (delimiter !== void 0)
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
this.lineSeparator = lineSeparator;
|
|
27
|
-
if (emptyFieldValue !== void 0)
|
|
28
|
-
this.emptyFieldValue = emptyFieldValue;
|
|
14
|
+
__publicField$9(this, "stream", new stream$3.PassThrough());
|
|
15
|
+
__publicField$9(this, "delimiter", ";");
|
|
16
|
+
__publicField$9(this, "lineSeparator", "\n");
|
|
17
|
+
__publicField$9(this, "emptyFieldValue", "");
|
|
18
|
+
__publicField$9(this, "columns", /* @__PURE__ */ new Set());
|
|
19
|
+
if (delimiter !== void 0) this.delimiter = delimiter;
|
|
20
|
+
if (lineSeparator !== void 0) this.lineSeparator = lineSeparator;
|
|
21
|
+
if (emptyFieldValue !== void 0) this.emptyFieldValue = emptyFieldValue;
|
|
29
22
|
}
|
|
30
23
|
getWritableStream() {
|
|
31
24
|
return this.stream;
|
|
@@ -55,16 +48,13 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
55
48
|
return Extension2;
|
|
56
49
|
})(Extension || {});
|
|
57
50
|
|
|
58
|
-
var __defProp$
|
|
59
|
-
var __defNormalProp$
|
|
60
|
-
var __publicField$
|
|
61
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
62
|
-
return value;
|
|
63
|
-
};
|
|
51
|
+
var __defProp$8 = Object.defineProperty;
|
|
52
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
64
54
|
class CSVFormatter {
|
|
65
55
|
constructor() {
|
|
66
|
-
__publicField$
|
|
67
|
-
__publicField$
|
|
56
|
+
__publicField$8(this, "formatterName", "CSV");
|
|
57
|
+
__publicField$8(this, "fileExtension", Extension.CSV);
|
|
68
58
|
}
|
|
69
59
|
async format(products, categories, _, __) {
|
|
70
60
|
const mappedCategories = {};
|
|
@@ -102,8 +92,7 @@ class CSVFormatter {
|
|
|
102
92
|
]);
|
|
103
93
|
products.forEach((product) => {
|
|
104
94
|
Object.entries(product).forEach(([key, value]) => {
|
|
105
|
-
if (value)
|
|
106
|
-
columns.add(key);
|
|
95
|
+
if (value) columns.add(key);
|
|
107
96
|
});
|
|
108
97
|
});
|
|
109
98
|
csvStream.setColumns(columns);
|
|
@@ -123,21 +112,19 @@ class CSVFormatter {
|
|
|
123
112
|
};
|
|
124
113
|
csvStream.addRow(row);
|
|
125
114
|
});
|
|
115
|
+
csvStream.getWritableStream().end();
|
|
126
116
|
return csvStream.getWritableStream();
|
|
127
117
|
}
|
|
128
118
|
}
|
|
129
119
|
|
|
130
|
-
var __defProp$
|
|
131
|
-
var __defNormalProp$
|
|
132
|
-
var __publicField$
|
|
133
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
134
|
-
return value;
|
|
135
|
-
};
|
|
120
|
+
var __defProp$7 = Object.defineProperty;
|
|
121
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
122
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
136
123
|
const { stream: stream$2 } = pkg;
|
|
137
124
|
class ExcelFormatter {
|
|
138
125
|
constructor() {
|
|
139
|
-
__publicField$
|
|
140
|
-
__publicField$
|
|
126
|
+
__publicField$7(this, "formatterName", "Excel");
|
|
127
|
+
__publicField$7(this, "fileExtension", Extension.XLSX);
|
|
141
128
|
}
|
|
142
129
|
async format(products, categories, _, __) {
|
|
143
130
|
const mappedCategories = {};
|
|
@@ -170,11 +157,13 @@ class ExcelFormatter {
|
|
|
170
157
|
]);
|
|
171
158
|
products.forEach((product) => {
|
|
172
159
|
Object.entries(product).forEach(([key, value]) => {
|
|
173
|
-
if (value)
|
|
174
|
-
columns.add(key);
|
|
160
|
+
if (value) columns.add(key);
|
|
175
161
|
});
|
|
176
162
|
});
|
|
177
|
-
const
|
|
163
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
164
|
+
const workbook = new stream$2.xlsx.WorkbookWriter({
|
|
165
|
+
stream: passThroughStream
|
|
166
|
+
});
|
|
178
167
|
const worksheet = workbook.addWorksheet("products");
|
|
179
168
|
worksheet.columns = Array.from(columns).map((column) => ({
|
|
180
169
|
key: column,
|
|
@@ -198,21 +187,19 @@ class ExcelFormatter {
|
|
|
198
187
|
});
|
|
199
188
|
worksheet.commit();
|
|
200
189
|
await workbook.commit();
|
|
201
|
-
|
|
190
|
+
passThroughStream.end();
|
|
191
|
+
return passThroughStream;
|
|
202
192
|
}
|
|
203
193
|
}
|
|
204
194
|
|
|
205
|
-
var __defProp$
|
|
206
|
-
var __defNormalProp$
|
|
207
|
-
var __publicField$
|
|
208
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
209
|
-
return value;
|
|
210
|
-
};
|
|
195
|
+
var __defProp$6 = Object.defineProperty;
|
|
196
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
197
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
211
198
|
const { stream: stream$1 } = pkg;
|
|
212
199
|
class InsalesFormatter {
|
|
213
200
|
constructor() {
|
|
214
|
-
__publicField$
|
|
215
|
-
__publicField$
|
|
201
|
+
__publicField$6(this, "formatterName", "Insales");
|
|
202
|
+
__publicField$6(this, "fileExtension", Extension.XLSX);
|
|
216
203
|
}
|
|
217
204
|
async format(products, categories, _, __) {
|
|
218
205
|
const mappedCategories = {};
|
|
@@ -237,8 +224,7 @@ class InsalesFormatter {
|
|
|
237
224
|
const categories2 = {};
|
|
238
225
|
const categoryList = new Array();
|
|
239
226
|
function addCategory(categoryId) {
|
|
240
|
-
if (categoryId === void 0)
|
|
241
|
-
return;
|
|
227
|
+
if (categoryId === void 0) return;
|
|
242
228
|
const category = mappedCategories[categoryId];
|
|
243
229
|
if (category) {
|
|
244
230
|
categoryList.push(category.name);
|
|
@@ -253,7 +239,10 @@ class InsalesFormatter {
|
|
|
253
239
|
});
|
|
254
240
|
return categories2;
|
|
255
241
|
};
|
|
256
|
-
const
|
|
242
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
243
|
+
const workbook = new stream$1.xlsx.WorkbookWriter({
|
|
244
|
+
stream: passThroughStream
|
|
245
|
+
});
|
|
257
246
|
const worksheet = workbook.addWorksheet("products");
|
|
258
247
|
const columns = /* @__PURE__ */ new Set([
|
|
259
248
|
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID",
|
|
@@ -337,36 +326,62 @@ class InsalesFormatter {
|
|
|
337
326
|
});
|
|
338
327
|
worksheet.commit();
|
|
339
328
|
await workbook.commit();
|
|
340
|
-
|
|
329
|
+
passThroughStream.end();
|
|
330
|
+
return passThroughStream;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
var __defProp$5 = Object.defineProperty;
|
|
335
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
336
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
337
|
+
class JSONFormatter {
|
|
338
|
+
constructor() {
|
|
339
|
+
__publicField$5(this, "formatterName", "JSON");
|
|
340
|
+
__publicField$5(this, "fileExtension", Extension.JSON);
|
|
341
|
+
}
|
|
342
|
+
async format(products, categories, brands, _) {
|
|
343
|
+
return new jsonStreamStringify.JsonStreamStringify({
|
|
344
|
+
categories,
|
|
345
|
+
brands,
|
|
346
|
+
products
|
|
347
|
+
});
|
|
341
348
|
}
|
|
342
349
|
}
|
|
343
350
|
|
|
344
351
|
var __defProp$4 = Object.defineProperty;
|
|
345
352
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
346
|
-
var __publicField$4 = (obj, key, value) =>
|
|
347
|
-
|
|
348
|
-
return value;
|
|
349
|
-
};
|
|
350
|
-
class JSONFormatter {
|
|
353
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
354
|
+
class SimpleJSONFormatter {
|
|
351
355
|
constructor() {
|
|
352
356
|
__publicField$4(this, "formatterName", "JSON");
|
|
353
357
|
__publicField$4(this, "fileExtension", Extension.JSON);
|
|
354
358
|
}
|
|
355
359
|
async format(products, categories, brands, _) {
|
|
360
|
+
const groupedProduct = /* @__PURE__ */ new Map();
|
|
361
|
+
products.forEach((product) => {
|
|
362
|
+
if (product.parentId !== void 0) return;
|
|
363
|
+
groupedProduct.set(product.variantId, {
|
|
364
|
+
...product,
|
|
365
|
+
children: []
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
products.forEach((product) => {
|
|
369
|
+
if (product.parentId === void 0) return;
|
|
370
|
+
const parent = groupedProduct.get(product.parentId);
|
|
371
|
+
if (!parent) return;
|
|
372
|
+
parent.children.push(product);
|
|
373
|
+
});
|
|
356
374
|
return new jsonStreamStringify.JsonStreamStringify({
|
|
357
375
|
categories,
|
|
358
376
|
brands,
|
|
359
|
-
products
|
|
377
|
+
products: Array.from(groupedProduct.values())
|
|
360
378
|
});
|
|
361
379
|
}
|
|
362
380
|
}
|
|
363
381
|
|
|
364
382
|
var __defProp$3 = Object.defineProperty;
|
|
365
383
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
366
|
-
var __publicField$3 = (obj, key, value) =>
|
|
367
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
368
|
-
return value;
|
|
369
|
-
};
|
|
384
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
370
385
|
const { stream } = pkg;
|
|
371
386
|
class TgShopFormatter {
|
|
372
387
|
constructor() {
|
|
@@ -391,7 +406,10 @@ class TgShopFormatter {
|
|
|
391
406
|
size: getParameter(product, "size")?.value,
|
|
392
407
|
priority: void 0
|
|
393
408
|
});
|
|
394
|
-
const
|
|
409
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
410
|
+
const workbook = new stream.xlsx.WorkbookWriter({
|
|
411
|
+
stream: passThroughStream
|
|
412
|
+
});
|
|
395
413
|
const categoryWorksheet = workbook.addWorksheet("categories");
|
|
396
414
|
const productsWorksheet = workbook.addWorksheet("offers");
|
|
397
415
|
categoryWorksheet.columns = [
|
|
@@ -437,16 +455,13 @@ class TgShopFormatter {
|
|
|
437
455
|
categoryWorksheet.commit();
|
|
438
456
|
productsWorksheet.commit();
|
|
439
457
|
await workbook.commit();
|
|
440
|
-
return
|
|
458
|
+
return passThroughStream;
|
|
441
459
|
}
|
|
442
460
|
}
|
|
443
461
|
|
|
444
462
|
var __defProp$2 = Object.defineProperty;
|
|
445
463
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
446
|
-
var __publicField$2 = (obj, key, value) =>
|
|
447
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
448
|
-
return value;
|
|
449
|
-
};
|
|
464
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
450
465
|
class TildaFormatter {
|
|
451
466
|
constructor() {
|
|
452
467
|
__publicField$2(this, "formatterName", "Tilda");
|
|
@@ -492,16 +507,14 @@ class TildaFormatter {
|
|
|
492
507
|
};
|
|
493
508
|
csvStream.addRow(row);
|
|
494
509
|
});
|
|
510
|
+
csvStream.getWritableStream().end();
|
|
495
511
|
return csvStream.getWritableStream();
|
|
496
512
|
}
|
|
497
513
|
}
|
|
498
514
|
|
|
499
515
|
var __defProp$1 = Object.defineProperty;
|
|
500
516
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
501
|
-
var __publicField$1 = (obj, key, value) =>
|
|
502
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
503
|
-
return value;
|
|
504
|
-
};
|
|
517
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
505
518
|
class YMLFormatter {
|
|
506
519
|
constructor() {
|
|
507
520
|
__publicField$1(this, "formatterName", "YMl");
|
|
@@ -511,54 +524,70 @@ class YMLFormatter {
|
|
|
511
524
|
const result = new stream$3.PassThrough();
|
|
512
525
|
const builder = new fastXmlParser.XMLBuilder({
|
|
513
526
|
ignoreAttributes: false,
|
|
514
|
-
cdataPropName: "__cdata"
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
_attr: { date: (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "") }
|
|
527
|
+
cdataPropName: "__cdata",
|
|
528
|
+
format: true,
|
|
529
|
+
indentBy: " "
|
|
518
530
|
});
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
531
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "");
|
|
532
|
+
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
533
|
+
result.write('<yml_catalog date="' + date + '">\n');
|
|
534
|
+
result.write("<shop>\n");
|
|
535
|
+
if (options?.shopName) {
|
|
536
|
+
result.write(builder.build({ name: options.shopName }));
|
|
537
|
+
result.write("\n");
|
|
538
|
+
}
|
|
539
|
+
if (options?.companyName) {
|
|
540
|
+
result.write(builder.build({ company: options.companyName }));
|
|
541
|
+
result.write("\n");
|
|
542
|
+
}
|
|
543
|
+
if (categories) {
|
|
544
|
+
result.write(
|
|
545
|
+
builder.build({
|
|
546
|
+
// tagname: "categories",
|
|
547
|
+
categories: { category: this.getCategories(categories) }
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
result.write("\n");
|
|
551
|
+
}
|
|
552
|
+
if (brands) {
|
|
553
|
+
result.write(
|
|
554
|
+
builder.build({ brands: { brand: this.getBrands(brands) } })
|
|
555
|
+
);
|
|
556
|
+
result.write("\n");
|
|
557
|
+
}
|
|
558
|
+
result.write("<offers>\n");
|
|
559
|
+
const offerStream = new stream$3.PassThrough();
|
|
560
|
+
offerStream.pipe(result, { end: false });
|
|
536
561
|
products.forEach((product) => {
|
|
537
|
-
|
|
562
|
+
const offer = builder.build({ offer: this.getOffer(product) });
|
|
563
|
+
offerStream.write(offer + "\n");
|
|
564
|
+
});
|
|
565
|
+
offerStream.end();
|
|
566
|
+
offerStream.on("end", () => {
|
|
567
|
+
result.write("</offers>\n");
|
|
568
|
+
result.write("</shop>\n");
|
|
569
|
+
result.write("</yml_catalog>\n");
|
|
570
|
+
result.end();
|
|
538
571
|
});
|
|
539
|
-
stream.pipe(result, { end: false });
|
|
540
|
-
offers.close();
|
|
541
|
-
shop.close();
|
|
542
|
-
ymlCatalog.close();
|
|
543
572
|
return result;
|
|
544
573
|
}
|
|
545
574
|
getBrands(brands) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
575
|
+
if (!brands) return [];
|
|
576
|
+
return brands.map((brand) => ({
|
|
577
|
+
"@_id": brand.id,
|
|
578
|
+
"@_url": brand.coverURL ?? "",
|
|
579
|
+
"#text": brand.name
|
|
551
580
|
}));
|
|
552
581
|
}
|
|
553
582
|
getCategories(categories) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
583
|
+
if (!categories) return [];
|
|
584
|
+
return categories.map((cat) => ({
|
|
585
|
+
"@_id": cat.id,
|
|
586
|
+
"@_parentId": cat.parentId ?? "",
|
|
587
|
+
"#text": cat.name
|
|
559
588
|
}));
|
|
560
589
|
}
|
|
561
|
-
|
|
590
|
+
getOffer(product) {
|
|
562
591
|
const result = {
|
|
563
592
|
"@_id": product.variantId,
|
|
564
593
|
name: product.title,
|
|
@@ -569,6 +598,7 @@ class YMLFormatter {
|
|
|
569
598
|
cofinance_price: product.cofinancePrice,
|
|
570
599
|
currencyId: product.currency,
|
|
571
600
|
categoryId: product.categoryId,
|
|
601
|
+
vendorId: product.vendorId,
|
|
572
602
|
vendor: product.vendor,
|
|
573
603
|
vendorCode: product.vendorCode,
|
|
574
604
|
picture: product.images,
|
|
@@ -642,15 +672,13 @@ const Formatters = {
|
|
|
642
672
|
YMLFormatter,
|
|
643
673
|
TgShopFormatter,
|
|
644
674
|
ExcelFormatter,
|
|
645
|
-
JSONFormatter
|
|
675
|
+
JSONFormatter,
|
|
676
|
+
SimpleJSONFormatter
|
|
646
677
|
};
|
|
647
678
|
|
|
648
679
|
var __defProp = Object.defineProperty;
|
|
649
680
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
650
|
-
var __publicField = (obj, key, value) =>
|
|
651
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
652
|
-
return value;
|
|
653
|
-
};
|
|
681
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
654
682
|
class GoodsExporter {
|
|
655
683
|
constructor() {
|
|
656
684
|
__publicField(this, "formatter", new Formatters.YMLFormatter());
|