goods-exporter 1.2.13 → 1.3.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 CHANGED
@@ -725,6 +725,10 @@ declare class GoodsExporter<Context extends object | undefined> {
725
725
 
726
726
  declare const buildCategoryPaths: (categories: Category[]) => Map<number, Category[]>;
727
727
 
728
+ declare const writeWithDrain: (stream: Writable) => (chunk: any) => Promise<void>;
729
+
730
+ declare const delay: (ms: number) => Promise<unknown>;
731
+
728
732
  declare const urlQueryEncode: (inputUrl: string) => string;
729
733
 
730
- export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths, urlQueryEncode };
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 };
@@ -1,14 +1,62 @@
1
1
  'use strict';
2
2
 
3
+ var events = require('events');
3
4
  var stream$3 = require('stream');
4
5
  var pkg = require('exceljs');
5
6
  var jsonStreamStringify = require('json-stream-stringify');
6
7
  var fastXmlParser = require('fast-xml-parser');
7
8
  var fs = require('fs');
8
9
 
10
+ const buildCategoryPaths = (categories) => {
11
+ const idToCategory = /* @__PURE__ */ new Map();
12
+ categories.forEach((category) => {
13
+ idToCategory.set(category.id, category);
14
+ });
15
+ const categoryPaths = /* @__PURE__ */ new Map();
16
+ categories.forEach((category) => {
17
+ const path = [];
18
+ let currentCategory = category;
19
+ while (currentCategory) {
20
+ path.unshift(currentCategory);
21
+ if (currentCategory.parentId !== void 0) {
22
+ currentCategory = idToCategory.get(currentCategory.parentId);
23
+ } else {
24
+ currentCategory = void 0;
25
+ }
26
+ }
27
+ categoryPaths.set(category.id, path);
28
+ });
29
+ return categoryPaths;
30
+ };
31
+
32
+ const writeWithDrain = (stream) => {
33
+ return async (chunk) => {
34
+ const canWrite = stream.write(chunk);
35
+ if (!canWrite) {
36
+ await events.once(stream, "drain");
37
+ }
38
+ };
39
+ };
40
+
41
+ const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
42
+
43
+ const urlQueryEncode = (inputUrl) => {
44
+ try {
45
+ const url = new URL(inputUrl);
46
+ url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
47
+ return url.toString();
48
+ } catch (error) {
49
+ console.error("Invalid URL:", error);
50
+ return "";
51
+ }
52
+ };
53
+
9
54
  var __defProp$b = Object.defineProperty;
10
55
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
56
+ var __publicField$b = (obj, key, value) => {
57
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
58
+ return value;
59
+ };
12
60
  class CSVStream {
13
61
  constructor({ delimiter, lineSeparator, emptyFieldValue }) {
14
62
  __publicField$b(this, "stream", new stream$3.PassThrough());
@@ -16,11 +64,15 @@ class CSVStream {
16
64
  __publicField$b(this, "lineSeparator", "\n");
17
65
  __publicField$b(this, "emptyFieldValue", "");
18
66
  __publicField$b(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;
67
+ __publicField$b(this, "writer", writeWithDrain(this.stream));
68
+ if (delimiter !== void 0)
69
+ this.delimiter = delimiter;
70
+ if (lineSeparator !== void 0)
71
+ this.lineSeparator = lineSeparator;
72
+ if (emptyFieldValue !== void 0)
73
+ this.emptyFieldValue = emptyFieldValue;
22
74
  }
23
- getWritableStream() {
75
+ get writableStream() {
24
76
  return this.stream;
25
77
  }
26
78
  setColumns(columns) {
@@ -29,12 +81,11 @@ class CSVStream {
29
81
  Array.from(this.columns).join(this.delimiter) + this.lineSeparator
30
82
  );
31
83
  }
32
- addRow(items) {
33
- this.stream.write(
34
- Array.from(this.columns).map(
35
- (key) => items[key] === void 0 ? this.emptyFieldValue : items[key] + ""
36
- ).join(this.delimiter) + this.lineSeparator
37
- );
84
+ async addRow(items) {
85
+ const data = Array.from(this.columns).map(
86
+ (key) => items[key] === void 0 ? this.emptyFieldValue : items[key] + ""
87
+ ).join(this.delimiter) + this.lineSeparator;
88
+ await this.writer(data);
38
89
  }
39
90
  }
40
91
 
@@ -51,7 +102,10 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
51
102
 
52
103
  var __defProp$a = Object.defineProperty;
53
104
  var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
54
- var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
105
+ var __publicField$a = (obj, key, value) => {
106
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
107
+ return value;
108
+ };
55
109
  class CSVFormatter {
56
110
  constructor() {
57
111
  __publicField$a(this, "formatterName", "CSV");
@@ -65,7 +119,7 @@ class CSVFormatter {
65
119
  emptyFieldValue: "",
66
120
  lineSeparator: "\n"
67
121
  });
68
- csvStream.getWritableStream().pipe(writableStream);
122
+ csvStream.writableStream.pipe(writableStream);
69
123
  const columns = /* @__PURE__ */ new Set([
70
124
  "url",
71
125
  "productId",
@@ -96,11 +150,12 @@ class CSVFormatter {
96
150
  ]);
97
151
  products.forEach((product) => {
98
152
  Object.entries(product).forEach(([key, value]) => {
99
- if (value) columns.add(key);
153
+ if (value)
154
+ columns.add(key);
100
155
  });
101
156
  });
102
157
  csvStream.setColumns(columns);
103
- products.forEach((product) => {
158
+ for (const product of products) {
104
159
  const row = {
105
160
  ...product,
106
161
  category: mappedCategories[product.categoryId],
@@ -116,15 +171,18 @@ class CSVFormatter {
116
171
  timeDeliveryMin: product.timeDelivery?.min,
117
172
  timeDeliveryMax: product.timeDelivery?.max
118
173
  };
119
- csvStream.addRow(row);
120
- });
121
- csvStream.getWritableStream().end();
174
+ await csvStream.addRow(row);
175
+ }
176
+ csvStream.writableStream.end();
122
177
  }
123
178
  }
124
179
 
125
180
  var __defProp$9 = Object.defineProperty;
126
181
  var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
127
- var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
182
+ var __publicField$9 = (obj, key, value) => {
183
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
184
+ return value;
185
+ };
128
186
  const { stream: stream$2 } = pkg;
129
187
  class ExcelFormatter {
130
188
  constructor() {
@@ -164,7 +222,8 @@ class ExcelFormatter {
164
222
  ]);
165
223
  products.forEach((product) => {
166
224
  Object.entries(product).forEach(([key, value]) => {
167
- if (value) columns.add(key);
225
+ if (value)
226
+ columns.add(key);
168
227
  });
169
228
  });
170
229
  const workbook = new stream$2.xlsx.WorkbookWriter({
@@ -200,7 +259,10 @@ class ExcelFormatter {
200
259
 
201
260
  var __defProp$8 = Object.defineProperty;
202
261
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
203
- var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
262
+ var __publicField$8 = (obj, key, value) => {
263
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
264
+ return value;
265
+ };
204
266
  const { stream: stream$1 } = pkg;
205
267
  class InsalesFormatter {
206
268
  constructor() {
@@ -230,7 +292,8 @@ class InsalesFormatter {
230
292
  const categories2 = {};
231
293
  const categoryList = new Array();
232
294
  function addCategory(categoryId) {
233
- if (categoryId === void 0) return;
295
+ if (categoryId === void 0)
296
+ return;
234
297
  const category = mappedCategories[categoryId];
235
298
  if (category) {
236
299
  categoryList.push(category.name);
@@ -293,7 +356,7 @@ class InsalesFormatter {
293
356
  header: column,
294
357
  key: column
295
358
  }));
296
- products.forEach((product) => {
359
+ for (const product of products) {
297
360
  const externalId = `${product.productId}-${product.variantId}`;
298
361
  const row = {
299
362
  "\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
@@ -313,7 +376,7 @@ class InsalesFormatter {
313
376
  "\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.dimensions,
314
377
  \u0412\u0435\u0441: product.weight,
315
378
  "\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435": product.available,
316
- \u041D\u0414\u0421: product.vat.toString(),
379
+ \u041D\u0414\u0421: product.vat?.toString(),
317
380
  "\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430": product.currency.toString(),
318
381
  "\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,
319
382
  \u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
@@ -325,7 +388,7 @@ class InsalesFormatter {
325
388
  "\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430": product.keywords?.join(",")
326
389
  };
327
390
  worksheet.addRow(row).commit();
328
- });
391
+ }
329
392
  worksheet.commit();
330
393
  await workbook.commit();
331
394
  }
@@ -333,7 +396,10 @@ class InsalesFormatter {
333
396
 
334
397
  var __defProp$7 = Object.defineProperty;
335
398
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
336
- var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
399
+ var __publicField$7 = (obj, key, value) => {
400
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
401
+ return value;
402
+ };
337
403
  class JSONFormatter {
338
404
  constructor() {
339
405
  __publicField$7(this, "formatterName", "JSON");
@@ -351,7 +417,10 @@ class JSONFormatter {
351
417
 
352
418
  var __defProp$6 = Object.defineProperty;
353
419
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
354
- var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
420
+ var __publicField$6 = (obj, key, value) => {
421
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
422
+ return value;
423
+ };
355
424
  class SimpleJSONFormatter {
356
425
  constructor() {
357
426
  __publicField$6(this, "formatterName", "JSON");
@@ -360,16 +429,19 @@ class SimpleJSONFormatter {
360
429
  async format(writableStream, products, categories, brands, _) {
361
430
  const groupedProduct = /* @__PURE__ */ new Map();
362
431
  products.forEach((product) => {
363
- if (product.parentId !== void 0) return;
432
+ if (product.parentId !== void 0)
433
+ return;
364
434
  groupedProduct.set(product.variantId, {
365
435
  ...product,
366
436
  children: []
367
437
  });
368
438
  });
369
439
  products.forEach((product) => {
370
- if (product.parentId === void 0) return;
440
+ if (product.parentId === void 0)
441
+ return;
371
442
  const parent = groupedProduct.get(product.parentId);
372
- if (!parent) return;
443
+ if (!parent)
444
+ return;
373
445
  parent.children.push(product);
374
446
  });
375
447
  const stream = new jsonStreamStringify.JsonStreamStringify({
@@ -383,7 +455,10 @@ class SimpleJSONFormatter {
383
455
 
384
456
  var __defProp$5 = Object.defineProperty;
385
457
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
386
- var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
458
+ var __publicField$5 = (obj, key, value) => {
459
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
460
+ return value;
461
+ };
387
462
  const { stream } = pkg;
388
463
  class TgShopFormatter {
389
464
  constructor() {
@@ -461,7 +536,10 @@ class TgShopFormatter {
461
536
 
462
537
  var __defProp$4 = Object.defineProperty;
463
538
  var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
464
- var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
539
+ var __publicField$4 = (obj, key, value) => {
540
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
541
+ return value;
542
+ };
465
543
  class TildaFormatter {
466
544
  constructor() {
467
545
  __publicField$4(this, "formatterName", "Tilda");
@@ -475,7 +553,7 @@ class TildaFormatter {
475
553
  emptyFieldValue: "",
476
554
  lineSeparator: "\n"
477
555
  });
478
- csvStream.getWritableStream().pipe(writableStream);
556
+ csvStream.writableStream.pipe(writableStream);
479
557
  const columns = /* @__PURE__ */ new Set([
480
558
  "SKU",
481
559
  "Brand",
@@ -491,7 +569,7 @@ class TildaFormatter {
491
569
  "Parent UID"
492
570
  ]);
493
571
  csvStream.setColumns(columns);
494
- products.forEach((product) => {
572
+ for (const product of products) {
495
573
  const row = {
496
574
  SKU: product.vendorCode,
497
575
  Brand: product.vendor,
@@ -506,48 +584,18 @@ class TildaFormatter {
506
584
  "External ID": product.variantId,
507
585
  "Parent UID": product.parentId
508
586
  };
509
- csvStream.addRow(row);
510
- });
511
- csvStream.getWritableStream().end();
512
- }
513
- }
514
-
515
- const buildCategoryPaths = (categories) => {
516
- const idToCategory = /* @__PURE__ */ new Map();
517
- categories.forEach((category) => {
518
- idToCategory.set(category.id, category);
519
- });
520
- const categoryPaths = /* @__PURE__ */ new Map();
521
- categories.forEach((category) => {
522
- const path = [];
523
- let currentCategory = category;
524
- while (currentCategory) {
525
- path.unshift(currentCategory);
526
- if (currentCategory.parentId !== void 0) {
527
- currentCategory = idToCategory.get(currentCategory.parentId);
528
- } else {
529
- currentCategory = void 0;
530
- }
587
+ await csvStream.addRow(row);
531
588
  }
532
- categoryPaths.set(category.id, path);
533
- });
534
- return categoryPaths;
535
- };
536
-
537
- const urlQueryEncode = (inputUrl) => {
538
- try {
539
- const url = new URL(inputUrl);
540
- url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
541
- return url.toString();
542
- } catch (error) {
543
- console.error("Invalid URL:", error);
544
- return "";
589
+ csvStream.writableStream.end();
545
590
  }
546
- };
591
+ }
547
592
 
548
593
  var __defProp$3 = Object.defineProperty;
549
594
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
550
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
595
+ var __publicField$3 = (obj, key, value) => {
596
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
597
+ return value;
598
+ };
551
599
  class WooCommerceFormatter {
552
600
  constructor() {
553
601
  __publicField$3(this, "formatterName", "WooCommerce");
@@ -591,7 +639,8 @@ class WooCommerceFormatter {
591
639
  });
592
640
  }
593
641
  createAttribute(data) {
594
- if (!data?.name || data.id === void 0) return;
642
+ if (!data?.name || data.id === void 0)
643
+ return;
595
644
  const attributeStartName = "Attribute";
596
645
  const attribute = {};
597
646
  attribute[`${attributeStartName} ${data.id} name`] = data.name;
@@ -638,7 +687,8 @@ class WooCommerceFormatter {
638
687
  visible: 0,
639
688
  global: 0
640
689
  });
641
- if (!attribute) return;
690
+ if (!attribute)
691
+ return;
642
692
  Object.entries(attribute).forEach(
643
693
  ([key2, value2]) => paramAttributes[key2] = value2
644
694
  );
@@ -671,7 +721,8 @@ class WooCommerceFormatter {
671
721
  values: value,
672
722
  global: 0
673
723
  });
674
- if (!attribute) return;
724
+ if (!attribute)
725
+ return;
675
726
  Object.entries(attribute).forEach(
676
727
  ([key2, value2]) => propertyAttributes[key2] = value2
677
728
  );
@@ -683,24 +734,25 @@ class WooCommerceFormatter {
683
734
  }
684
735
  removeVisibleFromAttributes(params) {
685
736
  Object.entries(params).forEach(([key]) => {
686
- if (key.includes("visible")) params[key] = "";
737
+ if (key.includes("visible"))
738
+ params[key] = "";
687
739
  });
688
740
  }
689
741
  async format(writableStream, products, categories, _, __) {
690
- const categoriePaths = buildCategoryPaths(categories ?? []);
742
+ const categoryPaths = buildCategoryPaths(categories ?? []);
691
743
  const csvStream = new CSVStream({
692
744
  delimiter: ";",
693
745
  emptyFieldValue: "",
694
746
  lineSeparator: "\n"
695
747
  });
696
- csvStream.getWritableStream().pipe(writableStream);
748
+ csvStream.writableStream.pipe(writableStream);
697
749
  const columns = new Set(this.DEFAULT_COLUMNS);
698
750
  const attributes = this.extractAttributes(products);
699
751
  const variationsByParentId = /* @__PURE__ */ new Map();
700
752
  const imagesByParentId = /* @__PURE__ */ new Map();
701
753
  const sizesByParentId = /* @__PURE__ */ new Map();
702
754
  const variations = products.map((product, index) => {
703
- const pathsArray = categoriePaths.get(product.categoryId)?.map((category) => category.name);
755
+ const pathsArray = categoryPaths.get(product.categoryId)?.map((category) => category.name);
704
756
  const price = product.price ? product.price : "";
705
757
  let row = {
706
758
  ID: product.variantId,
@@ -756,7 +808,8 @@ class WooCommerceFormatter {
756
808
  const productParams = attributes.params.get(product.SKU) ?? {};
757
809
  const productProperties = attributes.properties.get(product.SKU) ?? {};
758
810
  Object.entries(productParams).forEach(([key]) => {
759
- if (key.includes("visible")) productParams[key] = 0;
811
+ if (key.includes("visible"))
812
+ productParams[key] = 0;
760
813
  });
761
814
  if (currentParent) {
762
815
  Object.entries(productParams).forEach(([key, value]) => {
@@ -773,19 +826,24 @@ class WooCommerceFormatter {
773
826
  });
774
827
  const variableProducts = Array.from(parentProducts.values());
775
828
  csvStream.setColumns(columns);
776
- variableProducts.forEach((parentProduct) => {
777
- csvStream.addRow(parentProduct);
778
- variationsByParentId.get(parentProduct.ID)?.forEach((variationProduct) => {
779
- csvStream.addRow(variationProduct);
780
- });
781
- });
782
- csvStream.getWritableStream().end();
829
+ for (const parentProduct of variableProducts) {
830
+ await csvStream.addRow(parentProduct);
831
+ for (const variationProduct of variationsByParentId.get(
832
+ parentProduct.ID
833
+ ) ?? []) {
834
+ await csvStream.addRow(variationProduct);
835
+ }
836
+ }
837
+ csvStream.writableStream.end();
783
838
  }
784
839
  }
785
840
 
786
841
  var __defProp$2 = Object.defineProperty;
787
842
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
788
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
843
+ var __publicField$2 = (obj, key, value) => {
844
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
845
+ return value;
846
+ };
789
847
  class YMLFormatter {
790
848
  constructor() {
791
849
  __publicField$2(this, "formatterName", "YMl");
@@ -804,36 +862,38 @@ class YMLFormatter {
804
862
  result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
805
863
  result.write('<yml_catalog date="' + date + '">\n');
806
864
  result.write("<shop>\n");
865
+ const resultWriter = writeWithDrain(result);
807
866
  if (options?.shopName) {
808
- result.write(builder.build({ name: options.shopName }));
809
- result.write("\n");
867
+ await resultWriter(builder.build({ name: options.shopName }));
868
+ await resultWriter("\n");
810
869
  }
811
870
  if (options?.companyName) {
812
- result.write(builder.build({ company: options.companyName }));
813
- result.write("\n");
871
+ await resultWriter(builder.build({ company: options.companyName }));
872
+ await resultWriter("\n");
814
873
  }
815
874
  if (categories) {
816
- result.write(
875
+ await resultWriter(
817
876
  builder.build({
818
877
  // tagname: "categories",
819
878
  categories: { category: this.getCategories(categories) }
820
879
  })
821
880
  );
822
- result.write("\n");
881
+ await resultWriter("\n");
823
882
  }
824
883
  if (brands) {
825
- result.write(
884
+ await resultWriter(
826
885
  builder.build({ brands: { brand: this.getBrands(brands) } })
827
886
  );
828
- result.write("\n");
887
+ await resultWriter("\n");
829
888
  }
830
- result.write("<offers>\n");
889
+ await resultWriter("<offers>\n");
831
890
  const offerStream = new stream$3.PassThrough();
891
+ const offerWriter = writeWithDrain(offerStream);
832
892
  offerStream.pipe(result, { end: false });
833
- products.forEach((product) => {
893
+ for (const product of products) {
834
894
  const offer = builder.build({ offer: this.getOffer(product) });
835
- offerStream.write(offer + "\n");
836
- });
895
+ await offerWriter(offer + "\n");
896
+ }
837
897
  offerStream.end();
838
898
  offerStream.on("end", () => {
839
899
  result.write("</offers>\n");
@@ -843,7 +903,8 @@ class YMLFormatter {
843
903
  });
844
904
  }
845
905
  getBrands(brands) {
846
- if (!brands) return [];
906
+ if (!brands)
907
+ return [];
847
908
  return brands.map((brand) => ({
848
909
  "@_id": brand.id,
849
910
  "@_url": brand.coverURL ?? "",
@@ -851,7 +912,8 @@ class YMLFormatter {
851
912
  }));
852
913
  }
853
914
  getCategories(categories) {
854
- if (!categories) return [];
915
+ if (!categories)
916
+ return [];
855
917
  return categories.map((cat) => ({
856
918
  "@_id": cat.id,
857
919
  "@_parentId": cat.parentId ?? "",
@@ -943,7 +1005,10 @@ class YMLFormatter {
943
1005
 
944
1006
  var __defProp$1 = Object.defineProperty;
945
1007
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
946
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1008
+ var __publicField$1 = (obj, key, value) => {
1009
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1010
+ return value;
1011
+ };
947
1012
  class XMLFormatter extends YMLFormatter {
948
1013
  constructor() {
949
1014
  super(...arguments);
@@ -967,7 +1032,10 @@ const Formatters = {
967
1032
 
968
1033
  var __defProp = Object.defineProperty;
969
1034
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
970
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1035
+ var __publicField = (obj, key, value) => {
1036
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1037
+ return value;
1038
+ };
971
1039
  class GoodsExporter {
972
1040
  constructor(context) {
973
1041
  this.context = context;
@@ -1035,5 +1103,7 @@ exports.Formatters = Formatters;
1035
1103
  exports.GoodsExporter = GoodsExporter;
1036
1104
  exports.Vat = Vat;
1037
1105
  exports.buildCategoryPaths = buildCategoryPaths;
1106
+ exports.delay = delay;
1038
1107
  exports.urlQueryEncode = urlQueryEncode;
1108
+ exports.writeWithDrain = writeWithDrain;
1039
1109
  //# sourceMappingURL=index.cjs.map