goods-exporter 1.2.12 → 1.3.1
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/dist/bundle.d.ts +10 -2
- package/dist/cjs/index.cjs +141 -70
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +140 -71
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { writeWithDrain as writeWithDrain$1 } from 'src/utils';
|
|
1
2
|
import { PassThrough } from 'stream';
|
|
2
3
|
import pkg from 'exceljs';
|
|
3
4
|
import { JsonStreamStringify } from 'json-stream-stringify';
|
|
5
|
+
import { once } from 'events';
|
|
4
6
|
import { XMLBuilder } from 'fast-xml-parser';
|
|
5
7
|
import fs from 'fs';
|
|
6
8
|
|
|
7
9
|
var __defProp$b = Object.defineProperty;
|
|
8
10
|
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField$b = (obj, key, value) =>
|
|
11
|
+
var __publicField$b = (obj, key, value) => {
|
|
12
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
10
15
|
class CSVStream {
|
|
11
16
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
12
17
|
__publicField$b(this, "stream", new PassThrough());
|
|
@@ -14,11 +19,15 @@ class CSVStream {
|
|
|
14
19
|
__publicField$b(this, "lineSeparator", "\n");
|
|
15
20
|
__publicField$b(this, "emptyFieldValue", "");
|
|
16
21
|
__publicField$b(this, "columns", /* @__PURE__ */ new Set());
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
22
|
+
__publicField$b(this, "writer", writeWithDrain$1(this.stream));
|
|
23
|
+
if (delimiter !== void 0)
|
|
24
|
+
this.delimiter = delimiter;
|
|
25
|
+
if (lineSeparator !== void 0)
|
|
26
|
+
this.lineSeparator = lineSeparator;
|
|
27
|
+
if (emptyFieldValue !== void 0)
|
|
28
|
+
this.emptyFieldValue = emptyFieldValue;
|
|
20
29
|
}
|
|
21
|
-
|
|
30
|
+
get writableStream() {
|
|
22
31
|
return this.stream;
|
|
23
32
|
}
|
|
24
33
|
setColumns(columns) {
|
|
@@ -27,12 +36,11 @@ class CSVStream {
|
|
|
27
36
|
Array.from(this.columns).join(this.delimiter) + this.lineSeparator
|
|
28
37
|
);
|
|
29
38
|
}
|
|
30
|
-
addRow(items) {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
39
|
+
async addRow(items) {
|
|
40
|
+
const data = Array.from(this.columns).map(
|
|
41
|
+
(key) => items[key] === void 0 ? this.emptyFieldValue : items[key] + ""
|
|
42
|
+
).join(this.delimiter) + this.lineSeparator;
|
|
43
|
+
await this.writer(data);
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
|
|
@@ -49,7 +57,10 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
49
57
|
|
|
50
58
|
var __defProp$a = Object.defineProperty;
|
|
51
59
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
-
var __publicField$a = (obj, key, value) =>
|
|
60
|
+
var __publicField$a = (obj, key, value) => {
|
|
61
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
62
|
+
return value;
|
|
63
|
+
};
|
|
53
64
|
class CSVFormatter {
|
|
54
65
|
constructor() {
|
|
55
66
|
__publicField$a(this, "formatterName", "CSV");
|
|
@@ -63,7 +74,7 @@ class CSVFormatter {
|
|
|
63
74
|
emptyFieldValue: "",
|
|
64
75
|
lineSeparator: "\n"
|
|
65
76
|
});
|
|
66
|
-
csvStream.
|
|
77
|
+
csvStream.writableStream.pipe(writableStream);
|
|
67
78
|
const columns = /* @__PURE__ */ new Set([
|
|
68
79
|
"url",
|
|
69
80
|
"productId",
|
|
@@ -94,11 +105,12 @@ class CSVFormatter {
|
|
|
94
105
|
]);
|
|
95
106
|
products.forEach((product) => {
|
|
96
107
|
Object.entries(product).forEach(([key, value]) => {
|
|
97
|
-
if (value)
|
|
108
|
+
if (value)
|
|
109
|
+
columns.add(key);
|
|
98
110
|
});
|
|
99
111
|
});
|
|
100
112
|
csvStream.setColumns(columns);
|
|
101
|
-
|
|
113
|
+
for (const product of products) {
|
|
102
114
|
const row = {
|
|
103
115
|
...product,
|
|
104
116
|
category: mappedCategories[product.categoryId],
|
|
@@ -114,15 +126,18 @@ class CSVFormatter {
|
|
|
114
126
|
timeDeliveryMin: product.timeDelivery?.min,
|
|
115
127
|
timeDeliveryMax: product.timeDelivery?.max
|
|
116
128
|
};
|
|
117
|
-
csvStream.addRow(row);
|
|
118
|
-
}
|
|
119
|
-
csvStream.
|
|
129
|
+
await csvStream.addRow(row);
|
|
130
|
+
}
|
|
131
|
+
csvStream.writableStream.end();
|
|
120
132
|
}
|
|
121
133
|
}
|
|
122
134
|
|
|
123
135
|
var __defProp$9 = Object.defineProperty;
|
|
124
136
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
125
|
-
var __publicField$9 = (obj, key, value) =>
|
|
137
|
+
var __publicField$9 = (obj, key, value) => {
|
|
138
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
126
141
|
const { stream: stream$2 } = pkg;
|
|
127
142
|
class ExcelFormatter {
|
|
128
143
|
constructor() {
|
|
@@ -162,7 +177,8 @@ class ExcelFormatter {
|
|
|
162
177
|
]);
|
|
163
178
|
products.forEach((product) => {
|
|
164
179
|
Object.entries(product).forEach(([key, value]) => {
|
|
165
|
-
if (value)
|
|
180
|
+
if (value)
|
|
181
|
+
columns.add(key);
|
|
166
182
|
});
|
|
167
183
|
});
|
|
168
184
|
const workbook = new stream$2.xlsx.WorkbookWriter({
|
|
@@ -198,7 +214,10 @@ class ExcelFormatter {
|
|
|
198
214
|
|
|
199
215
|
var __defProp$8 = Object.defineProperty;
|
|
200
216
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
201
|
-
var __publicField$8 = (obj, key, value) =>
|
|
217
|
+
var __publicField$8 = (obj, key, value) => {
|
|
218
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
219
|
+
return value;
|
|
220
|
+
};
|
|
202
221
|
const { stream: stream$1 } = pkg;
|
|
203
222
|
class InsalesFormatter {
|
|
204
223
|
constructor() {
|
|
@@ -228,7 +247,8 @@ class InsalesFormatter {
|
|
|
228
247
|
const categories2 = {};
|
|
229
248
|
const categoryList = new Array();
|
|
230
249
|
function addCategory(categoryId) {
|
|
231
|
-
if (categoryId === void 0)
|
|
250
|
+
if (categoryId === void 0)
|
|
251
|
+
return;
|
|
232
252
|
const category = mappedCategories[categoryId];
|
|
233
253
|
if (category) {
|
|
234
254
|
categoryList.push(category.name);
|
|
@@ -291,7 +311,7 @@ class InsalesFormatter {
|
|
|
291
311
|
header: column,
|
|
292
312
|
key: column
|
|
293
313
|
}));
|
|
294
|
-
|
|
314
|
+
for (const product of products) {
|
|
295
315
|
const externalId = `${product.productId}-${product.variantId}`;
|
|
296
316
|
const row = {
|
|
297
317
|
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
|
|
@@ -311,7 +331,7 @@ class InsalesFormatter {
|
|
|
311
331
|
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.dimensions,
|
|
312
332
|
\u0412\u0435\u0441: product.weight,
|
|
313
333
|
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435": product.available,
|
|
314
|
-
\u041D\u0414\u0421: product.vat
|
|
334
|
+
\u041D\u0414\u0421: product.vat?.toString(),
|
|
315
335
|
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430": product.currency.toString(),
|
|
316
336
|
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.parentId === void 0 ? product.images?.join(" ") : void 0,
|
|
317
337
|
\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
|
|
@@ -323,7 +343,7 @@ class InsalesFormatter {
|
|
|
323
343
|
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430": product.keywords?.join(",")
|
|
324
344
|
};
|
|
325
345
|
worksheet.addRow(row).commit();
|
|
326
|
-
}
|
|
346
|
+
}
|
|
327
347
|
worksheet.commit();
|
|
328
348
|
await workbook.commit();
|
|
329
349
|
}
|
|
@@ -331,7 +351,10 @@ class InsalesFormatter {
|
|
|
331
351
|
|
|
332
352
|
var __defProp$7 = Object.defineProperty;
|
|
333
353
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
334
|
-
var __publicField$7 = (obj, key, value) =>
|
|
354
|
+
var __publicField$7 = (obj, key, value) => {
|
|
355
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
356
|
+
return value;
|
|
357
|
+
};
|
|
335
358
|
class JSONFormatter {
|
|
336
359
|
constructor() {
|
|
337
360
|
__publicField$7(this, "formatterName", "JSON");
|
|
@@ -349,7 +372,10 @@ class JSONFormatter {
|
|
|
349
372
|
|
|
350
373
|
var __defProp$6 = Object.defineProperty;
|
|
351
374
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
352
|
-
var __publicField$6 = (obj, key, value) =>
|
|
375
|
+
var __publicField$6 = (obj, key, value) => {
|
|
376
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
377
|
+
return value;
|
|
378
|
+
};
|
|
353
379
|
class SimpleJSONFormatter {
|
|
354
380
|
constructor() {
|
|
355
381
|
__publicField$6(this, "formatterName", "JSON");
|
|
@@ -358,16 +384,19 @@ class SimpleJSONFormatter {
|
|
|
358
384
|
async format(writableStream, products, categories, brands, _) {
|
|
359
385
|
const groupedProduct = /* @__PURE__ */ new Map();
|
|
360
386
|
products.forEach((product) => {
|
|
361
|
-
if (product.parentId !== void 0)
|
|
387
|
+
if (product.parentId !== void 0)
|
|
388
|
+
return;
|
|
362
389
|
groupedProduct.set(product.variantId, {
|
|
363
390
|
...product,
|
|
364
391
|
children: []
|
|
365
392
|
});
|
|
366
393
|
});
|
|
367
394
|
products.forEach((product) => {
|
|
368
|
-
if (product.parentId === void 0)
|
|
395
|
+
if (product.parentId === void 0)
|
|
396
|
+
return;
|
|
369
397
|
const parent = groupedProduct.get(product.parentId);
|
|
370
|
-
if (!parent)
|
|
398
|
+
if (!parent)
|
|
399
|
+
return;
|
|
371
400
|
parent.children.push(product);
|
|
372
401
|
});
|
|
373
402
|
const stream = new JsonStreamStringify({
|
|
@@ -381,7 +410,10 @@ class SimpleJSONFormatter {
|
|
|
381
410
|
|
|
382
411
|
var __defProp$5 = Object.defineProperty;
|
|
383
412
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
384
|
-
var __publicField$5 = (obj, key, value) =>
|
|
413
|
+
var __publicField$5 = (obj, key, value) => {
|
|
414
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
415
|
+
return value;
|
|
416
|
+
};
|
|
385
417
|
const { stream } = pkg;
|
|
386
418
|
class TgShopFormatter {
|
|
387
419
|
constructor() {
|
|
@@ -459,7 +491,10 @@ class TgShopFormatter {
|
|
|
459
491
|
|
|
460
492
|
var __defProp$4 = Object.defineProperty;
|
|
461
493
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
462
|
-
var __publicField$4 = (obj, key, value) =>
|
|
494
|
+
var __publicField$4 = (obj, key, value) => {
|
|
495
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
496
|
+
return value;
|
|
497
|
+
};
|
|
463
498
|
class TildaFormatter {
|
|
464
499
|
constructor() {
|
|
465
500
|
__publicField$4(this, "formatterName", "Tilda");
|
|
@@ -473,7 +508,7 @@ class TildaFormatter {
|
|
|
473
508
|
emptyFieldValue: "",
|
|
474
509
|
lineSeparator: "\n"
|
|
475
510
|
});
|
|
476
|
-
csvStream.
|
|
511
|
+
csvStream.writableStream.pipe(writableStream);
|
|
477
512
|
const columns = /* @__PURE__ */ new Set([
|
|
478
513
|
"SKU",
|
|
479
514
|
"Brand",
|
|
@@ -489,7 +524,7 @@ class TildaFormatter {
|
|
|
489
524
|
"Parent UID"
|
|
490
525
|
]);
|
|
491
526
|
csvStream.setColumns(columns);
|
|
492
|
-
|
|
527
|
+
for (const product of products) {
|
|
493
528
|
const row = {
|
|
494
529
|
SKU: product.vendorCode,
|
|
495
530
|
Brand: product.vendor,
|
|
@@ -504,9 +539,9 @@ class TildaFormatter {
|
|
|
504
539
|
"External ID": product.variantId,
|
|
505
540
|
"Parent UID": product.parentId
|
|
506
541
|
};
|
|
507
|
-
csvStream.addRow(row);
|
|
508
|
-
}
|
|
509
|
-
csvStream.
|
|
542
|
+
await csvStream.addRow(row);
|
|
543
|
+
}
|
|
544
|
+
csvStream.writableStream.end();
|
|
510
545
|
}
|
|
511
546
|
}
|
|
512
547
|
|
|
@@ -532,6 +567,17 @@ const buildCategoryPaths = (categories) => {
|
|
|
532
567
|
return categoryPaths;
|
|
533
568
|
};
|
|
534
569
|
|
|
570
|
+
const writeWithDrain = (stream) => {
|
|
571
|
+
return async (chunk) => {
|
|
572
|
+
const canWrite = stream.write(chunk);
|
|
573
|
+
if (!canWrite) {
|
|
574
|
+
await once(stream, "drain");
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
580
|
+
|
|
535
581
|
const urlQueryEncode = (inputUrl) => {
|
|
536
582
|
try {
|
|
537
583
|
const url = new URL(inputUrl);
|
|
@@ -545,7 +591,10 @@ const urlQueryEncode = (inputUrl) => {
|
|
|
545
591
|
|
|
546
592
|
var __defProp$3 = Object.defineProperty;
|
|
547
593
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
548
|
-
var __publicField$3 = (obj, key, value) =>
|
|
594
|
+
var __publicField$3 = (obj, key, value) => {
|
|
595
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
596
|
+
return value;
|
|
597
|
+
};
|
|
549
598
|
class WooCommerceFormatter {
|
|
550
599
|
constructor() {
|
|
551
600
|
__publicField$3(this, "formatterName", "WooCommerce");
|
|
@@ -589,7 +638,8 @@ class WooCommerceFormatter {
|
|
|
589
638
|
});
|
|
590
639
|
}
|
|
591
640
|
createAttribute(data) {
|
|
592
|
-
if (!data?.name || data.id === void 0)
|
|
641
|
+
if (!data?.name || data.id === void 0)
|
|
642
|
+
return;
|
|
593
643
|
const attributeStartName = "Attribute";
|
|
594
644
|
const attribute = {};
|
|
595
645
|
attribute[`${attributeStartName} ${data.id} name`] = data.name;
|
|
@@ -636,7 +686,8 @@ class WooCommerceFormatter {
|
|
|
636
686
|
visible: 0,
|
|
637
687
|
global: 0
|
|
638
688
|
});
|
|
639
|
-
if (!attribute)
|
|
689
|
+
if (!attribute)
|
|
690
|
+
return;
|
|
640
691
|
Object.entries(attribute).forEach(
|
|
641
692
|
([key2, value2]) => paramAttributes[key2] = value2
|
|
642
693
|
);
|
|
@@ -669,7 +720,8 @@ class WooCommerceFormatter {
|
|
|
669
720
|
values: value,
|
|
670
721
|
global: 0
|
|
671
722
|
});
|
|
672
|
-
if (!attribute)
|
|
723
|
+
if (!attribute)
|
|
724
|
+
return;
|
|
673
725
|
Object.entries(attribute).forEach(
|
|
674
726
|
([key2, value2]) => propertyAttributes[key2] = value2
|
|
675
727
|
);
|
|
@@ -681,24 +733,25 @@ class WooCommerceFormatter {
|
|
|
681
733
|
}
|
|
682
734
|
removeVisibleFromAttributes(params) {
|
|
683
735
|
Object.entries(params).forEach(([key]) => {
|
|
684
|
-
if (key.includes("visible"))
|
|
736
|
+
if (key.includes("visible"))
|
|
737
|
+
params[key] = "";
|
|
685
738
|
});
|
|
686
739
|
}
|
|
687
740
|
async format(writableStream, products, categories, _, __) {
|
|
688
|
-
const
|
|
741
|
+
const categoryPaths = buildCategoryPaths(categories ?? []);
|
|
689
742
|
const csvStream = new CSVStream({
|
|
690
743
|
delimiter: ";",
|
|
691
744
|
emptyFieldValue: "",
|
|
692
745
|
lineSeparator: "\n"
|
|
693
746
|
});
|
|
694
|
-
csvStream.
|
|
747
|
+
csvStream.writableStream.pipe(writableStream);
|
|
695
748
|
const columns = new Set(this.DEFAULT_COLUMNS);
|
|
696
749
|
const attributes = this.extractAttributes(products);
|
|
697
750
|
const variationsByParentId = /* @__PURE__ */ new Map();
|
|
698
751
|
const imagesByParentId = /* @__PURE__ */ new Map();
|
|
699
752
|
const sizesByParentId = /* @__PURE__ */ new Map();
|
|
700
753
|
const variations = products.map((product, index) => {
|
|
701
|
-
const pathsArray =
|
|
754
|
+
const pathsArray = categoryPaths.get(product.categoryId)?.map((category) => category.name);
|
|
702
755
|
const price = product.price ? product.price : "";
|
|
703
756
|
let row = {
|
|
704
757
|
ID: product.variantId,
|
|
@@ -754,7 +807,8 @@ class WooCommerceFormatter {
|
|
|
754
807
|
const productParams = attributes.params.get(product.SKU) ?? {};
|
|
755
808
|
const productProperties = attributes.properties.get(product.SKU) ?? {};
|
|
756
809
|
Object.entries(productParams).forEach(([key]) => {
|
|
757
|
-
if (key.includes("visible"))
|
|
810
|
+
if (key.includes("visible"))
|
|
811
|
+
productParams[key] = 0;
|
|
758
812
|
});
|
|
759
813
|
if (currentParent) {
|
|
760
814
|
Object.entries(productParams).forEach(([key, value]) => {
|
|
@@ -771,19 +825,24 @@ class WooCommerceFormatter {
|
|
|
771
825
|
});
|
|
772
826
|
const variableProducts = Array.from(parentProducts.values());
|
|
773
827
|
csvStream.setColumns(columns);
|
|
774
|
-
|
|
775
|
-
csvStream.addRow(parentProduct);
|
|
776
|
-
variationsByParentId.get(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
828
|
+
for (const parentProduct of variableProducts) {
|
|
829
|
+
await csvStream.addRow(parentProduct);
|
|
830
|
+
for (const variationProduct of variationsByParentId.get(
|
|
831
|
+
parentProduct.ID
|
|
832
|
+
) ?? []) {
|
|
833
|
+
await csvStream.addRow(variationProduct);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
csvStream.writableStream.end();
|
|
781
837
|
}
|
|
782
838
|
}
|
|
783
839
|
|
|
784
840
|
var __defProp$2 = Object.defineProperty;
|
|
785
841
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
786
|
-
var __publicField$2 = (obj, key, value) =>
|
|
842
|
+
var __publicField$2 = (obj, key, value) => {
|
|
843
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
844
|
+
return value;
|
|
845
|
+
};
|
|
787
846
|
class YMLFormatter {
|
|
788
847
|
constructor() {
|
|
789
848
|
__publicField$2(this, "formatterName", "YMl");
|
|
@@ -802,36 +861,38 @@ class YMLFormatter {
|
|
|
802
861
|
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
803
862
|
result.write('<yml_catalog date="' + date + '">\n');
|
|
804
863
|
result.write("<shop>\n");
|
|
864
|
+
const resultWriter = writeWithDrain$1(result);
|
|
805
865
|
if (options?.shopName) {
|
|
806
|
-
|
|
807
|
-
|
|
866
|
+
await resultWriter(builder.build({ name: options.shopName }));
|
|
867
|
+
await resultWriter("\n");
|
|
808
868
|
}
|
|
809
869
|
if (options?.companyName) {
|
|
810
|
-
|
|
811
|
-
|
|
870
|
+
await resultWriter(builder.build({ company: options.companyName }));
|
|
871
|
+
await resultWriter("\n");
|
|
812
872
|
}
|
|
813
873
|
if (categories) {
|
|
814
|
-
|
|
874
|
+
await resultWriter(
|
|
815
875
|
builder.build({
|
|
816
876
|
// tagname: "categories",
|
|
817
877
|
categories: { category: this.getCategories(categories) }
|
|
818
878
|
})
|
|
819
879
|
);
|
|
820
|
-
|
|
880
|
+
await resultWriter("\n");
|
|
821
881
|
}
|
|
822
882
|
if (brands) {
|
|
823
|
-
|
|
883
|
+
await resultWriter(
|
|
824
884
|
builder.build({ brands: { brand: this.getBrands(brands) } })
|
|
825
885
|
);
|
|
826
|
-
|
|
886
|
+
await resultWriter("\n");
|
|
827
887
|
}
|
|
828
|
-
|
|
888
|
+
await resultWriter("<offers>\n");
|
|
829
889
|
const offerStream = new PassThrough();
|
|
890
|
+
const offerWriter = writeWithDrain$1(offerStream);
|
|
830
891
|
offerStream.pipe(result, { end: false });
|
|
831
|
-
|
|
892
|
+
for (const product of products) {
|
|
832
893
|
const offer = builder.build({ offer: this.getOffer(product) });
|
|
833
|
-
|
|
834
|
-
}
|
|
894
|
+
await offerWriter(offer + "\n");
|
|
895
|
+
}
|
|
835
896
|
offerStream.end();
|
|
836
897
|
offerStream.on("end", () => {
|
|
837
898
|
result.write("</offers>\n");
|
|
@@ -841,7 +902,8 @@ class YMLFormatter {
|
|
|
841
902
|
});
|
|
842
903
|
}
|
|
843
904
|
getBrands(brands) {
|
|
844
|
-
if (!brands)
|
|
905
|
+
if (!brands)
|
|
906
|
+
return [];
|
|
845
907
|
return brands.map((brand) => ({
|
|
846
908
|
"@_id": brand.id,
|
|
847
909
|
"@_url": brand.coverURL ?? "",
|
|
@@ -849,7 +911,8 @@ class YMLFormatter {
|
|
|
849
911
|
}));
|
|
850
912
|
}
|
|
851
913
|
getCategories(categories) {
|
|
852
|
-
if (!categories)
|
|
914
|
+
if (!categories)
|
|
915
|
+
return [];
|
|
853
916
|
return categories.map((cat) => ({
|
|
854
917
|
"@_id": cat.id,
|
|
855
918
|
"@_parentId": cat.parentId ?? "",
|
|
@@ -941,7 +1004,10 @@ class YMLFormatter {
|
|
|
941
1004
|
|
|
942
1005
|
var __defProp$1 = Object.defineProperty;
|
|
943
1006
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
944
|
-
var __publicField$1 = (obj, key, value) =>
|
|
1007
|
+
var __publicField$1 = (obj, key, value) => {
|
|
1008
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1009
|
+
return value;
|
|
1010
|
+
};
|
|
945
1011
|
class XMLFormatter extends YMLFormatter {
|
|
946
1012
|
constructor() {
|
|
947
1013
|
super(...arguments);
|
|
@@ -965,7 +1031,10 @@ const Formatters = {
|
|
|
965
1031
|
|
|
966
1032
|
var __defProp = Object.defineProperty;
|
|
967
1033
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
968
|
-
var __publicField = (obj, key, value) =>
|
|
1034
|
+
var __publicField = (obj, key, value) => {
|
|
1035
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1036
|
+
return value;
|
|
1037
|
+
};
|
|
969
1038
|
class GoodsExporter {
|
|
970
1039
|
constructor(context) {
|
|
971
1040
|
this.context = context;
|
|
@@ -1026,5 +1095,5 @@ var Currency = /* @__PURE__ */ ((Currency2) => {
|
|
|
1026
1095
|
return Currency2;
|
|
1027
1096
|
})(Currency || {});
|
|
1028
1097
|
|
|
1029
|
-
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, urlQueryEncode };
|
|
1098
|
+
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
|
|
1030
1099
|
//# sourceMappingURL=index.mjs.map
|