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/bundle.d.ts
CHANGED
|
@@ -729,6 +729,8 @@ declare const writeWithDrain: (stream: Writable) => (chunk: any) => Promise<void
|
|
|
729
729
|
|
|
730
730
|
declare const delay: (ms: number) => Promise<unknown>;
|
|
731
731
|
|
|
732
|
+
declare function getRFC3339Date(date: Date): string;
|
|
733
|
+
|
|
732
734
|
declare const urlQueryEncode: (inputUrl: string) => string;
|
|
733
735
|
|
|
734
|
-
export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
|
|
736
|
+
export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths, delay, getRFC3339Date, urlQueryEncode, writeWithDrain };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -40,6 +40,21 @@ const writeWithDrain = (stream) => {
|
|
|
40
40
|
|
|
41
41
|
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
42
|
|
|
43
|
+
function getRFC3339Date(date) {
|
|
44
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
45
|
+
const year = date.getFullYear();
|
|
46
|
+
const month = pad(date.getMonth() + 1);
|
|
47
|
+
const day = pad(date.getDate());
|
|
48
|
+
const hour = pad(date.getHours());
|
|
49
|
+
const min = pad(date.getMinutes());
|
|
50
|
+
const tzOffset = -date.getTimezoneOffset();
|
|
51
|
+
const sign = tzOffset >= 0 ? "+" : "-";
|
|
52
|
+
const absOffset = Math.abs(tzOffset);
|
|
53
|
+
const offsetHour = pad(Math.floor(absOffset / 60));
|
|
54
|
+
const offsetMin = pad(absOffset % 60);
|
|
55
|
+
return `${year}-${month}-${day}T${hour}:${min}${sign}${offsetHour}:${offsetMin}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
const urlQueryEncode = (inputUrl) => {
|
|
44
59
|
try {
|
|
45
60
|
const url = new URL(inputUrl);
|
|
@@ -520,7 +535,7 @@ class TildaFormatter {
|
|
|
520
535
|
const mappedCategories = {};
|
|
521
536
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
522
537
|
const csvStream = new CSVStream({
|
|
523
|
-
delimiter: "
|
|
538
|
+
delimiter: " ",
|
|
524
539
|
emptyFieldValue: "",
|
|
525
540
|
lineSeparator: "\n"
|
|
526
541
|
});
|
|
@@ -539,6 +554,15 @@ class TildaFormatter {
|
|
|
539
554
|
"External ID",
|
|
540
555
|
"Parent UID"
|
|
541
556
|
]);
|
|
557
|
+
const characteristics = /* @__PURE__ */ new Set();
|
|
558
|
+
products.forEach((product) => {
|
|
559
|
+
product.properties?.forEach(({ key }) => {
|
|
560
|
+
characteristics.add(key);
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
characteristics.forEach((charKey) => {
|
|
564
|
+
columns.add(`Characteristics:${charKey}`);
|
|
565
|
+
});
|
|
542
566
|
csvStream.setColumns(columns);
|
|
543
567
|
for (const product of products) {
|
|
544
568
|
const row = {
|
|
@@ -547,7 +571,7 @@ class TildaFormatter {
|
|
|
547
571
|
Category: mappedCategories[product.categoryId],
|
|
548
572
|
Title: product.title,
|
|
549
573
|
Text: product.description,
|
|
550
|
-
Photo: product.images?.join("
|
|
574
|
+
Photo: product.images?.map(urlQueryEncode).join(","),
|
|
551
575
|
Price: product.price,
|
|
552
576
|
"Price Old": product.oldPrice,
|
|
553
577
|
Quantity: product.count,
|
|
@@ -555,6 +579,9 @@ class TildaFormatter {
|
|
|
555
579
|
"External ID": product.variantId,
|
|
556
580
|
"Parent UID": product.parentId
|
|
557
581
|
};
|
|
582
|
+
product.properties?.forEach(({ key, value }) => {
|
|
583
|
+
row[`Characteristics:${key}`] = value;
|
|
584
|
+
});
|
|
558
585
|
await csvStream.addRow(row);
|
|
559
586
|
}
|
|
560
587
|
csvStream.writableStream.end();
|
|
@@ -818,7 +845,7 @@ class YMLFormatter {
|
|
|
818
845
|
format: true,
|
|
819
846
|
indentBy: " "
|
|
820
847
|
});
|
|
821
|
-
const date = (/* @__PURE__ */ new Date())
|
|
848
|
+
const date = getRFC3339Date(/* @__PURE__ */ new Date());
|
|
822
849
|
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
823
850
|
result.write('<yml_catalog date="' + date + '">\n');
|
|
824
851
|
result.write("<shop>\n");
|
|
@@ -851,6 +878,7 @@ class YMLFormatter {
|
|
|
851
878
|
const offerWriter = writeWithDrain(offerStream);
|
|
852
879
|
offerStream.pipe(result, { end: false });
|
|
853
880
|
for (const product of products) {
|
|
881
|
+
if (product.price === 0) continue;
|
|
854
882
|
const offer = builder.build({ offer: this.getOffer(product) });
|
|
855
883
|
await offerWriter(offer + "\n");
|
|
856
884
|
}
|
|
@@ -875,7 +903,7 @@ class YMLFormatter {
|
|
|
875
903
|
return categories.map((cat) => ({
|
|
876
904
|
"@_id": cat.id,
|
|
877
905
|
"@_parentId": cat.parentId ?? "",
|
|
878
|
-
"#text": cat.name
|
|
906
|
+
"#text": cat.name || `\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F #${cat.id}`
|
|
879
907
|
}));
|
|
880
908
|
}
|
|
881
909
|
getOffer(product) {
|
|
@@ -941,13 +969,13 @@ class YMLFormatter {
|
|
|
941
969
|
dimensions: product.dimensions,
|
|
942
970
|
boxCount: product.boxCount,
|
|
943
971
|
disabled: product.disabled,
|
|
944
|
-
age: product.age
|
|
972
|
+
age: product.age ? {
|
|
945
973
|
"@_unit": product.age.unit,
|
|
946
974
|
"#text": product.age.value
|
|
947
|
-
},
|
|
948
|
-
"tn-ved-codes": product.codesTN?.length
|
|
975
|
+
} : void 0,
|
|
976
|
+
"tn-ved-codes": product.codesTN?.length ? {
|
|
949
977
|
"tn-ved-code": product.codesTN
|
|
950
|
-
},
|
|
978
|
+
} : void 0,
|
|
951
979
|
relatedProduct: product.relatedProducts,
|
|
952
980
|
gender: product.gender
|
|
953
981
|
};
|
|
@@ -1056,6 +1084,7 @@ exports.GoodsExporter = GoodsExporter;
|
|
|
1056
1084
|
exports.Vat = Vat;
|
|
1057
1085
|
exports.buildCategoryPaths = buildCategoryPaths;
|
|
1058
1086
|
exports.delay = delay;
|
|
1087
|
+
exports.getRFC3339Date = getRFC3339Date;
|
|
1059
1088
|
exports.urlQueryEncode = urlQueryEncode;
|
|
1060
1089
|
exports.writeWithDrain = writeWithDrain;
|
|
1061
1090
|
//# sourceMappingURL=index.cjs.map
|