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