goods-exporter 1.4.0 → 1.4.2
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 +3 -1
- package/dist/cjs/index.cjs +37 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +37 -9
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -38,6 +38,21 @@ const writeWithDrain = (stream) => {
|
|
|
38
38
|
|
|
39
39
|
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
40
40
|
|
|
41
|
+
function getRFC3339Date(date) {
|
|
42
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
43
|
+
const year = date.getFullYear();
|
|
44
|
+
const month = pad(date.getMonth() + 1);
|
|
45
|
+
const day = pad(date.getDate());
|
|
46
|
+
const hour = pad(date.getHours());
|
|
47
|
+
const min = pad(date.getMinutes());
|
|
48
|
+
const tzOffset = -date.getTimezoneOffset();
|
|
49
|
+
const sign = tzOffset >= 0 ? "+" : "-";
|
|
50
|
+
const absOffset = Math.abs(tzOffset);
|
|
51
|
+
const offsetHour = pad(Math.floor(absOffset / 60));
|
|
52
|
+
const offsetMin = pad(absOffset % 60);
|
|
53
|
+
return `${year}-${month}-${day}T${hour}:${min}${sign}${offsetHour}:${offsetMin}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
const urlQueryEncode = (inputUrl) => {
|
|
42
57
|
try {
|
|
43
58
|
const url = new URL(inputUrl);
|
|
@@ -518,7 +533,7 @@ class TildaFormatter {
|
|
|
518
533
|
const mappedCategories = {};
|
|
519
534
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
520
535
|
const csvStream = new CSVStream({
|
|
521
|
-
delimiter: "
|
|
536
|
+
delimiter: " ",
|
|
522
537
|
emptyFieldValue: "",
|
|
523
538
|
lineSeparator: "\n"
|
|
524
539
|
});
|
|
@@ -537,6 +552,15 @@ class TildaFormatter {
|
|
|
537
552
|
"External ID",
|
|
538
553
|
"Parent UID"
|
|
539
554
|
]);
|
|
555
|
+
const characteristics = /* @__PURE__ */ new Set();
|
|
556
|
+
products.forEach((product) => {
|
|
557
|
+
product.properties?.forEach(({ key }) => {
|
|
558
|
+
characteristics.add(key);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
characteristics.forEach((charKey) => {
|
|
562
|
+
columns.add(`Characteristics:${charKey}`);
|
|
563
|
+
});
|
|
540
564
|
csvStream.setColumns(columns);
|
|
541
565
|
for (const product of products) {
|
|
542
566
|
const row = {
|
|
@@ -545,7 +569,7 @@ class TildaFormatter {
|
|
|
545
569
|
Category: mappedCategories[product.categoryId],
|
|
546
570
|
Title: product.title,
|
|
547
571
|
Text: product.description,
|
|
548
|
-
Photo: product.images?.join("
|
|
572
|
+
Photo: product.images?.map(urlQueryEncode).join(","),
|
|
549
573
|
Price: product.price,
|
|
550
574
|
"Price Old": product.oldPrice,
|
|
551
575
|
Quantity: product.count,
|
|
@@ -553,6 +577,9 @@ class TildaFormatter {
|
|
|
553
577
|
"External ID": product.variantId,
|
|
554
578
|
"Parent UID": product.parentId
|
|
555
579
|
};
|
|
580
|
+
product.properties?.forEach(({ key, value }) => {
|
|
581
|
+
row[`Characteristics:${key}`] = value;
|
|
582
|
+
});
|
|
556
583
|
await csvStream.addRow(row);
|
|
557
584
|
}
|
|
558
585
|
csvStream.writableStream.end();
|
|
@@ -816,7 +843,7 @@ class YMLFormatter {
|
|
|
816
843
|
format: true,
|
|
817
844
|
indentBy: " "
|
|
818
845
|
});
|
|
819
|
-
const date = (/* @__PURE__ */ new Date())
|
|
846
|
+
const date = getRFC3339Date(/* @__PURE__ */ new Date());
|
|
820
847
|
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
821
848
|
result.write('<yml_catalog date="' + date + '">\n');
|
|
822
849
|
result.write("<shop>\n");
|
|
@@ -849,6 +876,7 @@ class YMLFormatter {
|
|
|
849
876
|
const offerWriter = writeWithDrain(offerStream);
|
|
850
877
|
offerStream.pipe(result, { end: false });
|
|
851
878
|
for (const product of products) {
|
|
879
|
+
if (product.price === 0) continue;
|
|
852
880
|
const offer = builder.build({ offer: this.getOffer(product) });
|
|
853
881
|
await offerWriter(offer + "\n");
|
|
854
882
|
}
|
|
@@ -873,7 +901,7 @@ class YMLFormatter {
|
|
|
873
901
|
return categories.map((cat) => ({
|
|
874
902
|
"@_id": cat.id,
|
|
875
903
|
"@_parentId": cat.parentId ?? "",
|
|
876
|
-
"#text": cat.name
|
|
904
|
+
"#text": cat.name || `\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F #${cat.id}`
|
|
877
905
|
}));
|
|
878
906
|
}
|
|
879
907
|
getOffer(product) {
|
|
@@ -939,13 +967,13 @@ class YMLFormatter {
|
|
|
939
967
|
dimensions: product.dimensions,
|
|
940
968
|
boxCount: product.boxCount,
|
|
941
969
|
disabled: product.disabled,
|
|
942
|
-
age: product.age
|
|
970
|
+
age: product.age ? {
|
|
943
971
|
"@_unit": product.age.unit,
|
|
944
972
|
"#text": product.age.value
|
|
945
|
-
},
|
|
946
|
-
"tn-ved-codes": product.codesTN?.length
|
|
973
|
+
} : void 0,
|
|
974
|
+
"tn-ved-codes": product.codesTN?.length ? {
|
|
947
975
|
"tn-ved-code": product.codesTN
|
|
948
|
-
},
|
|
976
|
+
} : void 0,
|
|
949
977
|
relatedProduct: product.relatedProducts,
|
|
950
978
|
gender: product.gender
|
|
951
979
|
};
|
|
@@ -1046,5 +1074,5 @@ var Currency = /* @__PURE__ */ ((Currency2) => {
|
|
|
1046
1074
|
return Currency2;
|
|
1047
1075
|
})(Currency || {});
|
|
1048
1076
|
|
|
1049
|
-
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
|
|
1077
|
+
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, getRFC3339Date, urlQueryEncode, writeWithDrain };
|
|
1050
1078
|
//# sourceMappingURL=index.mjs.map
|