denwa-web-shared 1.0.47 → 1.0.49

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.
@@ -424,6 +424,82 @@ const hslToHex = (h, s, l) => {
424
424
  };
425
425
  return `#${toHex(r2)}${toHex(g)}${toHex(b)}`;
426
426
  };
427
+ const uuidToStringId = (uuid2, length = 18) => {
428
+ const cleanUuid = uuid2.replace(/-/g, "");
429
+ return cleanUuid.slice(-length);
430
+ };
431
+ const uuidToNumericId = (uuid2, maxDigits = 18) => {
432
+ const hex = uuid2.replace(/-/g, "");
433
+ const safeHex = hex.slice(-14);
434
+ const num = parseInt(safeHex, 16);
435
+ let numStr = num.toString();
436
+ if (numStr.length < maxDigits) {
437
+ numStr = numStr.padStart(maxDigits, "0");
438
+ } else if (numStr.length > maxDigits) {
439
+ numStr = numStr.slice(-maxDigits);
440
+ }
441
+ return numStr;
442
+ };
443
+ const escapeXml = (str) => {
444
+ if (!str) return "";
445
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
446
+ };
447
+ const generateYandexFeedXML = ({
448
+ shopName,
449
+ shopCompany,
450
+ delivery,
451
+ categoriesData,
452
+ offersData,
453
+ host
454
+ }) => {
455
+ const url = `https://${host}`;
456
+ const offersXml = offersData.map((item) => {
457
+ var _a;
458
+ const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
459
+ const categoryId = typeof item.categoryId === "number" ? item.categoryId : uuidToNumericId(item.categoryId);
460
+ return `
461
+ <offer id="${id}" available="true">
462
+ <url>${escapeXml(`${url}${item.href}`)}</url>
463
+ <price>${item.price}</price>
464
+ <currencyId>RUR</currencyId>
465
+ <categoryId>${categoryId}</categoryId>
466
+ ${item.images.length ? item.images.map((item2) => `<picture>${escapeXml(item2.image1x)}</picture>`).join("") : ""}
467
+ <name>${escapeXml(item.name)}</name>
468
+ <vendor>${escapeXml(item.vendor)}</vendor>
469
+ <description>${escapeXml(item.description)}</description>
470
+ ${item.vendorCode && `<vendorCode>${escapeXml(item.vendorCode)}</vendorCode>`}
471
+ <pickup>${item.pickup}</pickup>
472
+ ${(_a = item.params) == null ? void 0 : _a.map((item2) => {
473
+ return `<param name="${item2.name}">${escapeXml(item2.value)}</param>`;
474
+ })}
475
+ </offer>
476
+ `;
477
+ }).join("");
478
+ const categoriesXml = categoriesData.map((item) => {
479
+ const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
480
+ const parentId = item.parentId ? ` parentId="${typeof item.parentId === "number" ? item.parentId : uuidToNumericId(item.parentId)}"` : "";
481
+ return `<category id="${id}"${parentId}>${escapeXml(item.name)}</category>`;
482
+ }).join("");
483
+ return `<?xml version="1.0" encoding="UTF-8"?>
484
+ <!DOCTYPE yml_catalog SYSTEM "shops.dtd">
485
+ <yml_catalog date="${(/* @__PURE__ */ new Date()).toISOString()}">
486
+ <shop>
487
+ <name>${escapeXml(shopName)}</name>
488
+ <company>${escapeXml(shopCompany)}</company>
489
+ <url>${url}</url>
490
+ <delivery>${delivery}</delivery>
491
+ <currencies>
492
+ <currency id="RUR" rate="1"/>
493
+ </currencies>
494
+ <categories>
495
+ ${categoriesXml}
496
+ </categories>
497
+ <offers>
498
+ ${offersXml}
499
+ </offers>
500
+ </shop>
501
+ </yml_catalog>`;
502
+ };
427
503
  function r(e) {
428
504
  var t, f, n = "";
429
505
  if ("string" == typeof e || "number" == typeof e) n += e;
@@ -7006,8 +7082,10 @@ exports.checkCorrectImageObject = checkCorrectImageObject;
7006
7082
  exports.cn = cn;
7007
7083
  exports.convertPhoneMask = convertPhoneMask;
7008
7084
  exports.createCityLink = createCityLink;
7085
+ exports.escapeXml = escapeXml;
7009
7086
  exports.generatePaginationArray = generatePaginationArray;
7010
7087
  exports.generatePlaceholderColor = generatePlaceholderColor;
7088
+ exports.generateYandexFeedXML = generateYandexFeedXML;
7011
7089
  exports.getByKey = getByKey;
7012
7090
  exports.getDateFormatter = getDateFormatter;
7013
7091
  exports.getImageData = getImageData;
@@ -7030,3 +7108,5 @@ exports.responseSchema = responseSchema;
7030
7108
  exports.serverFileSchema = serverFileSchema;
7031
7109
  exports.serverImageSchema = serverImageSchema;
7032
7110
  exports.updateTextByTemplate = updateTextByTemplate;
7111
+ exports.uuidToNumericId = uuidToNumericId;
7112
+ exports.uuidToStringId = uuidToStringId;
@@ -422,6 +422,82 @@ const hslToHex = (h, s, l) => {
422
422
  };
423
423
  return `#${toHex(r2)}${toHex(g)}${toHex(b)}`;
424
424
  };
425
+ const uuidToStringId = (uuid2, length = 18) => {
426
+ const cleanUuid = uuid2.replace(/-/g, "");
427
+ return cleanUuid.slice(-length);
428
+ };
429
+ const uuidToNumericId = (uuid2, maxDigits = 18) => {
430
+ const hex = uuid2.replace(/-/g, "");
431
+ const safeHex = hex.slice(-14);
432
+ const num = parseInt(safeHex, 16);
433
+ let numStr = num.toString();
434
+ if (numStr.length < maxDigits) {
435
+ numStr = numStr.padStart(maxDigits, "0");
436
+ } else if (numStr.length > maxDigits) {
437
+ numStr = numStr.slice(-maxDigits);
438
+ }
439
+ return numStr;
440
+ };
441
+ const escapeXml = (str) => {
442
+ if (!str) return "";
443
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
444
+ };
445
+ const generateYandexFeedXML = ({
446
+ shopName,
447
+ shopCompany,
448
+ delivery,
449
+ categoriesData,
450
+ offersData,
451
+ host
452
+ }) => {
453
+ const url = `https://${host}`;
454
+ const offersXml = offersData.map((item) => {
455
+ var _a;
456
+ const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
457
+ const categoryId = typeof item.categoryId === "number" ? item.categoryId : uuidToNumericId(item.categoryId);
458
+ return `
459
+ <offer id="${id}" available="true">
460
+ <url>${escapeXml(`${url}${item.href}`)}</url>
461
+ <price>${item.price}</price>
462
+ <currencyId>RUR</currencyId>
463
+ <categoryId>${categoryId}</categoryId>
464
+ ${item.images.length ? item.images.map((item2) => `<picture>${escapeXml(item2.image1x)}</picture>`).join("") : ""}
465
+ <name>${escapeXml(item.name)}</name>
466
+ <vendor>${escapeXml(item.vendor)}</vendor>
467
+ <description>${escapeXml(item.description)}</description>
468
+ ${item.vendorCode && `<vendorCode>${escapeXml(item.vendorCode)}</vendorCode>`}
469
+ <pickup>${item.pickup}</pickup>
470
+ ${(_a = item.params) == null ? void 0 : _a.map((item2) => {
471
+ return `<param name="${item2.name}">${escapeXml(item2.value)}</param>`;
472
+ })}
473
+ </offer>
474
+ `;
475
+ }).join("");
476
+ const categoriesXml = categoriesData.map((item) => {
477
+ const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
478
+ const parentId = item.parentId ? ` parentId="${typeof item.parentId === "number" ? item.parentId : uuidToNumericId(item.parentId)}"` : "";
479
+ return `<category id="${id}"${parentId}>${escapeXml(item.name)}</category>`;
480
+ }).join("");
481
+ return `<?xml version="1.0" encoding="UTF-8"?>
482
+ <!DOCTYPE yml_catalog SYSTEM "shops.dtd">
483
+ <yml_catalog date="${(/* @__PURE__ */ new Date()).toISOString()}">
484
+ <shop>
485
+ <name>${escapeXml(shopName)}</name>
486
+ <company>${escapeXml(shopCompany)}</company>
487
+ <url>${url}</url>
488
+ <delivery>${delivery}</delivery>
489
+ <currencies>
490
+ <currency id="RUR" rate="1"/>
491
+ </currencies>
492
+ <categories>
493
+ ${categoriesXml}
494
+ </categories>
495
+ <offers>
496
+ ${offersXml}
497
+ </offers>
498
+ </shop>
499
+ </yml_catalog>`;
500
+ };
425
501
  function r(e) {
426
502
  var t, f, n = "";
427
503
  if ("string" == typeof e || "number" == typeof e) n += e;
@@ -7005,8 +7081,10 @@ export {
7005
7081
  cn,
7006
7082
  convertPhoneMask,
7007
7083
  createCityLink,
7084
+ escapeXml,
7008
7085
  generatePaginationArray,
7009
7086
  generatePlaceholderColor,
7087
+ generateYandexFeedXML,
7010
7088
  getByKey,
7011
7089
  getDateFormatter,
7012
7090
  getImageData,
@@ -7028,5 +7106,7 @@ export {
7028
7106
  responseSchema,
7029
7107
  serverFileSchema,
7030
7108
  serverImageSchema,
7031
- updateTextByTemplate
7109
+ updateTextByTemplate,
7110
+ uuidToNumericId,
7111
+ uuidToStringId
7032
7112
  };
@@ -1,4 +1,4 @@
1
- import { IPaginate, PaginationResult } from '../types';
1
+ import { IPaginate, IPreparedServerImageWithAlt, PaginationResult } from '../types';
2
2
  import { PictureData } from '../types/picture-data';
3
3
  /**
4
4
  * @description Хелпер для генерации путей к адаптивным статичным изображениям (PictureData)
@@ -194,3 +194,59 @@ export declare const generatePlaceholderColor: (seed?: number | string) => strin
194
194
  * @returns Цвет в формате HEX (#RRGGBB)
195
195
  */
196
196
  export declare const hslToHex: (h: number, s: number, l: number) => string;
197
+ /**
198
+ * Преобразует UUID в короткий ID
199
+ * @param {string} uuid - UUID v4 строка (с дефисами или без)
200
+ * @param {number} length - нужная длина (по умолчанию 18)
201
+ * @returns {string} короткий ID без дефисов
202
+ */
203
+ export declare const uuidToStringId: (uuid: string, length?: number) => string;
204
+ /**
205
+ * Преобразует UUID в числовой ID
206
+ * @param {string} uuid - UUID v4 строка (с дефисами или без)
207
+ * @param {number} maxDigits - максимальное количество цифр в результате (по умолчанию 18)
208
+ * @returns {string} числовой ID в виде строки
209
+ */
210
+ export declare const uuidToNumericId: (uuid: string, maxDigits?: number) => string;
211
+ /**
212
+ * @description Экранирует XML-специальные символы в строке.
213
+ * @param str - Строка
214
+ */
215
+ export declare const escapeXml: (str: string) => string;
216
+ /**
217
+ * @description Генерирует XML-фид для яндекс товаров.
218
+ * @param shopName - Название магазина
219
+ * @param shopCompany - Компания
220
+ * @param delivery - Доставка
221
+ * @param categoriesData - Категории
222
+ * @param offersData - Товары
223
+ * @param host - Хост
224
+ * @response Готовый xml фид товаров
225
+ */
226
+ export declare const generateYandexFeedXML: ({ shopName, shopCompany, delivery, categoriesData, offersData, host, }: {
227
+ shopName: string;
228
+ shopCompany: string;
229
+ host: string;
230
+ delivery: boolean;
231
+ categoriesData: {
232
+ id: string | number;
233
+ name: string;
234
+ parentId?: string | number;
235
+ }[];
236
+ offersData: {
237
+ id: string | number;
238
+ categoryId: string | number;
239
+ name: string;
240
+ vendor: string;
241
+ vendorCode?: string | null;
242
+ description: string;
243
+ href: string;
244
+ images: IPreparedServerImageWithAlt[];
245
+ price: number;
246
+ pickup: boolean;
247
+ params?: {
248
+ name: string;
249
+ value: string;
250
+ }[];
251
+ }[];
252
+ }) => string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "denwa-web-shared",
3
3
  "private": false,
4
- "version": "1.0.47",
4
+ "version": "1.0.49",
5
5
  "type": "module",
6
6
  "author": "Denwa",
7
7
  "main": "dist/denwa-web-shared.cjs.js",