@mailoo/market 1.35.10 → 1.35.13

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/wholesale-price-list/index.ts","../../src/wholesale-price-list/concurrency.ts","../../src/wholesale-price-list/labels.ts","../../src/wholesale-price-list/unit-price.ts","../../src/wholesale-price-list/layout.ts","../../src/wholesale-price-list/fetch-url.ts","../../src/wholesale-price-list/sum-formula.ts","../../src/wholesale-price-list/preview-image.ts","../../src/wholesale-price-list/build-xlsx.ts","../../src/wholesale-price-list/resolve-media.ts"],"sourcesContent":["/**\n * Server-only wholesale price-list generator (xlsx + sheet model).\n * Import from `@mailoo/market/wholesale-price-list` in Node / Route Handlers.\n * Do not import from browser or Next client components.\n *\n * Google Sheets lives in a separate subpath so `googleapis` stays out of\n * xlsx-only consumers:\n * `@mailoo/market/wholesale-price-list/google-sheets`\n *\n * Final v1 API (MAI-110): `renderPriceListXlsx(input: PriceListInput)`.\n *\n * AMS-28 (not in v1): row has no measurementUnit column yet.\n */\nexport type {\n PriceListBuiltinLocale,\n PriceListColumnKey,\n PriceListHeader,\n PriceListInput,\n PriceListLabelKey,\n PriceListLayout,\n PriceListRow,\n PriceListSheetModel,\n RenderPriceListXlsxResult,\n} from './types.js'\nexport {\n buildPriceListLayout,\n excelColumnLetter,\n resolvePreviewImageConcurrency,\n validatePriceListInput,\n PRICE_LIST_BANNER_ROW_COUNT,\n PRICE_LIST_DATA_ROW_HEIGHT_PT,\n PRICE_LIST_DEFAULT_PHOTO_PX,\n PRICE_LIST_PHOTO_COL_CHARS,\n} from './layout.js'\nexport {\n DEFAULT_PREVIEW_IMAGE_CONCURRENCY,\n mapWithConcurrency,\n} from './concurrency.js'\nexport {\n formatGeneratedLabel,\n priceListFilename,\n priceListFilenameDate,\n resolvePriceListLabels,\n} from './labels.js'\nexport { coerceUnitPrice } from './unit-price.js'\nexport {\n fetchAbsoluteUrlBytes,\n isAnonymousHttpImageUrl,\n isMailooApiKeyedImageUrl,\n mediaIdFromMailooPublicImageUrl,\n} from './fetch-url.js'\nexport {\n buildCurrencyTotalSumIfFormula,\n buildLineSumFormula,\n buildTotalSumFormula,\n} from './sum-formula.js'\nexport {\n googleSheetsImageFormula,\n normalizePreviewSquare,\n rasterizeLogo,\n tryNormalizePreviewSquare,\n tryRasterizeLogo,\n} from './preview-image.js'\nexport {\n buildWholesalePriceListXlsx,\n renderPriceListXlsx,\n} from './build-xlsx.js'\n","/** Default max concurrent preview image loads / rasterizations. */\nexport const DEFAULT_PREVIEW_IMAGE_CONCURRENCY = 6\n\n/**\n * Run `mapper` over `items` with at most `concurrency` in flight.\n * Result order matches `items` order.\n */\nexport async function mapWithConcurrency<T, R>(\n items: readonly T[],\n concurrency: number,\n mapper: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n if (!Number.isInteger(concurrency) || concurrency < 1) {\n throw new Error('concurrency must be an integer >= 1')\n }\n if (items.length === 0) return []\n const results = new Array<R>(items.length)\n let nextIndex = 0\n\n async function worker(): Promise<void> {\n for (;;) {\n const i = nextIndex\n nextIndex += 1\n if (i >= items.length) return\n results[i] = await mapper(items[i]!, i)\n }\n }\n\n const workerCount = Math.min(concurrency, items.length)\n await Promise.all(Array.from({ length: workerCount }, () => worker()))\n return results\n}\n","import type { PriceListBuiltinLocale, PriceListLabelKey } from './types.js'\n\nconst BUILTIN: Record<\n PriceListBuiltinLocale,\n Record<PriceListLabelKey, string>\n> = {\n en: {\n title: 'Price list',\n photo: 'Photo',\n category: 'Category',\n product: 'Product',\n variant: 'Variant',\n packaging: 'Packaging',\n price: 'Price',\n onRequest: 'on request',\n link: 'Link',\n linkText: 'Open',\n quantity: 'Quantity',\n sum: 'Sum',\n total: 'Total',\n generated: 'Generated: {date}',\n filenamePrefix: 'price-list',\n },\n ru: {\n title: 'Прайс-лист',\n photo: 'Фото',\n category: 'Категория',\n product: 'Товар',\n variant: 'Вариант',\n packaging: 'Упаковка',\n price: 'Цена',\n onRequest: 'по запросу',\n link: 'Ссылка',\n linkText: 'Открыть',\n quantity: 'Количество',\n sum: 'Сумма',\n total: 'Итого',\n generated: 'Сформировано: {date}',\n filenamePrefix: 'price-list',\n },\n hy: {\n title: 'Գնացուցակ',\n photo: 'Լուսանկար',\n category: 'Կատեգորիա',\n product: 'Ապրանք',\n variant: 'Տարբերակ',\n packaging: 'Փաթեթավորում',\n price: 'Գին',\n onRequest: 'ըստ հարցման',\n link: 'Հղում',\n linkText: 'Բացել',\n quantity: 'Քանակ',\n sum: 'Գումար',\n total: 'Ընդամենը',\n generated: 'Ստեղծված է՝ {date}',\n filenamePrefix: 'price-list',\n },\n de: {\n title: 'Preisliste',\n photo: 'Foto',\n category: 'Kategorie',\n product: 'Produkt',\n variant: 'Variante',\n packaging: 'Verpackung',\n price: 'Preis',\n onRequest: 'auf Anfrage',\n link: 'Link',\n linkText: 'Öffnen',\n quantity: 'Menge',\n sum: 'Summe',\n total: 'Gesamt',\n generated: 'Erstellt: {date}',\n filenamePrefix: 'price-list',\n },\n es: {\n title: 'Lista de precios',\n photo: 'Foto',\n category: 'Categoría',\n product: 'Producto',\n variant: 'Variante',\n packaging: 'Embalaje',\n price: 'Precio',\n onRequest: 'bajo petición',\n link: 'Enlace',\n linkText: 'Abrir',\n quantity: 'Cantidad',\n sum: 'Suma',\n total: 'Total',\n generated: 'Generado: {date}',\n filenamePrefix: 'price-list',\n },\n}\n\nconst BUILTIN_LOCALES = new Set<string>(['hy', 'ru', 'en', 'de', 'es'])\n\nexport function resolvePriceListLabels(\n locale: string,\n overrides?: Partial<Record<PriceListLabelKey, string>>,\n): Record<PriceListLabelKey, string> {\n const code = locale.trim().toLowerCase()\n const base = BUILTIN_LOCALES.has(code)\n ? BUILTIN[code as PriceListBuiltinLocale]\n : BUILTIN.en\n return { ...base, ...overrides }\n}\n\nexport function formatGeneratedLabel(\n template: string,\n generatedAt: string,\n locale: string,\n timeZone?: string | null,\n): string {\n const d = new Date(generatedAt)\n if (Number.isNaN(d.getTime())) {\n throw new Error(`header.generatedAt is not a valid ISO date: ${generatedAt}`)\n }\n const tz = timeZone && timeZone.trim() !== '' ? timeZone.trim() : 'UTC'\n const date = new Intl.DateTimeFormat(locale, {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: tz,\n }).format(d)\n return template.replace(/\\{date\\}/g, date)\n}\n\n/**\n * Calendar date for the filename in `timeZone` (IANA), falling back to UTC.\n * Parts are taken from Intl so midnight near zone offsets (e.g. Asia/Yerevan)\n * lands on the correct local YYYY-MM-DD.\n */\nexport function priceListFilenameDate(\n generatedAt: string,\n timeZone?: string | null,\n): string {\n const d = new Date(generatedAt)\n if (Number.isNaN(d.getTime())) {\n throw new Error(`header.generatedAt is not a valid ISO date: ${generatedAt}`)\n }\n const tz = timeZone && timeZone.trim() !== '' ? timeZone.trim() : 'UTC'\n const parts = new Intl.DateTimeFormat('en-US', {\n timeZone: tz,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).formatToParts(d)\n const y = parts.find((p) => p.type === 'year')?.value\n const m = parts.find((p) => p.type === 'month')?.value\n const day = parts.find((p) => p.type === 'day')?.value\n if (!y || !m || !day) {\n throw new Error(`Failed to format filename date for timeZone=${tz}`)\n }\n return `${y}-${m}-${day}`\n}\n\nexport function priceListFilename(\n locale: string,\n generatedAt: string,\n prefix: string,\n timeZone?: string | null,\n): string {\n const date = priceListFilenameDate(generatedAt, timeZone)\n return `${prefix}-${locale}-${date}.xlsx`\n}\n","/**\n * Soft-coerce unit prices for wholesale export.\n * Negative / NaN / non-finite → null (“on request”) so one bad row cannot\n * crash the whole workbook.\n */\nexport function coerceUnitPrice(value: number | null): number | null {\n if (value === null) return null\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {\n return null\n }\n return value\n}\n","import { DEFAULT_PREVIEW_IMAGE_CONCURRENCY } from './concurrency.js'\nimport { resolvePriceListLabels } from './labels.js'\nimport { coerceUnitPrice } from './unit-price.js'\nimport type {\n PriceListColumnKey,\n PriceListInput,\n PriceListLayout,\n PriceListRow,\n} from './types.js'\n\n/** ~120 px square → Excel column width in characters (approx). */\nexport const PRICE_LIST_DEFAULT_PHOTO_PX = 120\n/** Fixed data-row height so rows never jump without a photo (~130 px). */\nexport const PRICE_LIST_DATA_ROW_HEIGHT_PT = 96\nexport const PRICE_LIST_PHOTO_COL_CHARS = 18\n/** Rows above the column header: logo/name, contacts, generated. */\nexport const PRICE_LIST_BANNER_ROW_COUNT = 3\n\nexport function excelColumnLetter(index1Based: number): string {\n if (!Number.isInteger(index1Based) || index1Based < 1) {\n throw new Error(`Invalid column index: ${index1Based}`)\n }\n let n = index1Based\n let s = ''\n while (n > 0) {\n const rem = (n - 1) % 26\n s = String.fromCharCode(65 + rem) + s\n n = Math.floor((n - 1) / 26)\n }\n return s\n}\n\n/**\n * Validate input and return a normalized shallow copy.\n * Does **not** mutate the caller's `rows` (or `unitPrice` in place).\n * Soft-coerces negative / NaN / non-finite `unitPrice` → null (“on request”).\n */\nexport function validatePriceListInput(input: PriceListInput): PriceListInput {\n if (!input || typeof input !== 'object') {\n throw new Error('PriceListInput is required')\n }\n if (typeof input.locale !== 'string' || input.locale.trim() === '') {\n throw new Error('locale is required')\n }\n if (!input.header || typeof input.header !== 'object') {\n throw new Error('header is required')\n }\n if (\n typeof input.header.siteName !== 'string' ||\n input.header.siteName.trim() === ''\n ) {\n throw new Error('header.siteName is required')\n }\n if (typeof input.header.contacts !== 'string') {\n throw new Error('header.contacts must be a string')\n }\n if (\n typeof input.header.generatedAt !== 'string' ||\n Number.isNaN(new Date(input.header.generatedAt).getTime())\n ) {\n throw new Error('header.generatedAt must be a valid ISO date string')\n }\n if (!Array.isArray(input.rows)) {\n throw new Error('rows must be an array')\n }\n if (\n input.photoSizePx !== undefined &&\n (!Number.isInteger(input.photoSizePx) || input.photoSizePx < 32)\n ) {\n throw new Error('photoSizePx must be an integer >= 32')\n }\n if (\n input.previewImageConcurrency !== undefined &&\n (!Number.isInteger(input.previewImageConcurrency) ||\n input.previewImageConcurrency < 1)\n ) {\n throw new Error('previewImageConcurrency must be an integer >= 1')\n }\n\n const rows: PriceListRow[] = input.rows.map((row, i) => {\n if (typeof row.productId !== 'string' || row.productId.trim() === '') {\n throw new Error(`rows[${i}].productId is required`)\n }\n if (typeof row.product !== 'string' || row.product.trim() === '') {\n throw new Error(`rows[${i}].product is required`)\n }\n if (typeof row.productUrl !== 'string' || row.productUrl.trim() === '') {\n throw new Error(`rows[${i}].productUrl is required`)\n }\n return {\n ...row,\n unitPrice: coerceUnitPrice(\n typeof row.unitPrice === 'number' || row.unitPrice === null\n ? row.unitPrice\n : Number.NaN,\n ),\n }\n })\n\n return {\n ...input,\n rows,\n }\n}\n\nexport function resolvePreviewImageConcurrency(input: PriceListInput): number {\n return input.previewImageConcurrency ?? DEFAULT_PREVIEW_IMAGE_CONCURRENCY\n}\n\nexport function buildPriceListLayout(input: PriceListInput): PriceListLayout {\n const normalized = validatePriceListInput(input)\n const labels = resolvePriceListLabels(normalized.locale, normalized.labels)\n const photoSizePx = normalized.photoSizePx ?? PRICE_LIST_DEFAULT_PHOTO_PX\n const headerRow = PRICE_LIST_BANNER_ROW_COUNT + 1\n const firstDataRow = headerRow + 1\n const totalRow = firstDataRow + normalized.rows.length\n\n const keys: Array<{ key: PriceListColumnKey; header: string }> = [\n { key: 'photo', header: labels.photo },\n { key: 'category', header: labels.category },\n { key: 'product', header: labels.product },\n { key: 'variant', header: labels.variant },\n { key: 'packaging', header: labels.packaging },\n { key: 'price', header: labels.price },\n { key: 'link', header: labels.link },\n { key: 'quantity', header: labels.quantity },\n { key: 'sum', header: labels.sum },\n { key: 'currencyHidden', header: '' },\n ]\n\n const columns = keys.map((c, i) => ({\n key: c.key,\n header: c.header,\n index: i + 1,\n letter: excelColumnLetter(i + 1),\n }))\n\n const letter = (key: PriceListColumnKey) => {\n const col = columns.find((c) => c.key === key)\n if (!col) throw new Error(`Missing column ${key}`)\n return col.letter\n }\n\n return {\n locale: normalized.locale,\n photoSizePx,\n dataRowHeightPt: PRICE_LIST_DATA_ROW_HEIGHT_PT,\n photoColWidthChars: PRICE_LIST_PHOTO_COL_CHARS,\n headerRow,\n firstDataRow,\n totalRow,\n columns,\n priceColLetter: letter('price'),\n quantityColLetter: letter('quantity'),\n sumColLetter: letter('sum'),\n currencyColLetter: letter('currencyHidden'),\n linkColLetter: letter('link'),\n }\n}\n","/**\n * Best-effort fetch of absolute http(s) image bytes.\n * Used as the package default when callers omit loadPreviewImage / loadLogo.\n * Fail-soft: returns null on any network/HTTP error (do not throw).\n *\n * Do **not** rely on this for Mailoo `…/images/public/content?id=` URLs —\n * those require X-API-Key. Callers must load via media id / API key instead.\n */\nexport async function fetchAbsoluteUrlBytes(\n url: string,\n): Promise<Uint8Array | null> {\n const trimmed = url.trim()\n if (!/^https?:\\/\\//i.test(trimmed)) return null\n try {\n const res = await fetch(trimmed)\n if (!res.ok) return null\n const buf = new Uint8Array(await res.arrayBuffer())\n return buf.byteLength > 0 ? buf : null\n } catch {\n return null\n }\n}\n\n/**\n * Mailoo library image embed URLs need an API key — Google Sheets =IMAGE\n * cannot send headers. Never put these in =IMAGE(); upload to Drive instead.\n * Avatars (`/api/v1/public/avatars/…`) are anonymously readable and are OK.\n */\nexport function isMailooApiKeyedImageUrl(url: string): boolean {\n try {\n const u = new URL(url.trim())\n return u.pathname.includes('/api/v1/images/public/content')\n } catch {\n return false\n }\n}\n\n/** Extract `id` from Mailoo `…/images/public/content?id=` URLs. */\nexport function mediaIdFromMailooPublicImageUrl(url: string): string | null {\n try {\n const u = new URL(url.trim())\n if (!u.pathname.includes('/api/v1/images/public/content')) return null\n const id = u.searchParams.get('id')?.trim()\n return id || null\n } catch {\n return null\n }\n}\n\n/** URL safe to hand to Sheets =IMAGE (anonymous GET). */\nexport function isAnonymousHttpImageUrl(url: string): boolean {\n const trimmed = url.trim()\n if (!/^https?:\\/\\//i.test(trimmed)) return false\n if (isMailooApiKeyedImageUrl(trimmed)) return false\n return true\n}\n","import type { PriceListLayout } from './types.js'\n\n/**\n * Line sum: quantity × unit price.\n * Blank / non-positive quantity → blank. Non-numeric price (on request) → blank.\n */\nexport function buildLineSumFormula(args: {\n layout: PriceListLayout\n /** 1-based Excel row for this data line. */\n row: number\n}): string {\n const { layout, row } = args\n const q = `${layout.quantityColLetter}${row}`\n const p = `${layout.priceColLetter}${row}`\n return `IFERROR(IF(N(${q})<=0,\"\",IF(NOT(ISNUMBER(${p})),\"\",${q}*${p})),\"\")`\n}\n\nexport function buildTotalSumFormula(args: {\n layout: PriceListLayout\n firstDataRow: number\n lastDataRow: number\n}): string {\n const { layout, firstDataRow, lastDataRow } = args\n if (lastDataRow < firstDataRow) return '0'\n const range = `${layout.sumColLetter}${firstDataRow}:${layout.sumColLetter}${lastDataRow}`\n return `SUM(${range})`\n}\n\n/**\n * Per-currency total when the sheet mixes ISO codes.\n * `currency` is written into the formula as a quoted literal.\n */\nexport function buildCurrencyTotalSumIfFormula(args: {\n layout: PriceListLayout\n firstDataRow: number\n lastDataRow: number\n currency: string\n}): string {\n const { layout, firstDataRow, lastDataRow, currency } = args\n if (lastDataRow < firstDataRow) return '0'\n if (!currency || currency.includes('\"')) {\n throw new Error('currency for SUMIF must be a non-empty string without quotes')\n }\n const sumRange = `${layout.sumColLetter}${firstDataRow}:${layout.sumColLetter}${lastDataRow}`\n const curRange = `${layout.currencyColLetter}${firstDataRow}:${layout.currencyColLetter}${lastDataRow}`\n return `SUMIF(${curRange},\"${currency}\",${sumRange})`\n}\n","import sharp from 'sharp'\nimport { PRICE_LIST_DEFAULT_PHOTO_PX } from './layout.js'\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e)\n}\n\n/**\n * Fit image into a square canvas with white padding (contain), PNG output.\n * Used for xlsx embedded thumbnails so every photo cell is the same size.\n * SVG input is accepted (sharp rasterizes via librsvg / built-in).\n * Throws on empty input / invalid size; decode failures throw (callers that\n * must keep the file alive should catch — see render helpers).\n */\nexport async function normalizePreviewSquare(\n input: Uint8Array,\n sizePx: number = PRICE_LIST_DEFAULT_PHOTO_PX,\n): Promise<Buffer> {\n if (!Number.isInteger(sizePx) || sizePx < 32) {\n throw new Error('sizePx must be an integer >= 32')\n }\n if (input.byteLength === 0) {\n throw new Error('Empty preview image')\n }\n return sharp(Buffer.from(input), {\n limitInputPixels: 268_435_456,\n failOn: 'error',\n })\n .rotate()\n .resize({\n width: sizePx,\n height: sizePx,\n fit: 'contain',\n background: { r: 255, g: 255, b: 255, alpha: 1 },\n })\n .png()\n .toBuffer()\n}\n\n/**\n * Soft wrapper: returns null when sharp cannot decode (corrupt / unsupported).\n * Still throws on empty input / invalid sizePx (programmer errors).\n */\nexport async function tryNormalizePreviewSquare(\n input: Uint8Array,\n sizePx: number = PRICE_LIST_DEFAULT_PHOTO_PX,\n): Promise<{ png: Buffer | null; error: string | null }> {\n try {\n const png = await normalizePreviewSquare(input, sizePx)\n return { png, error: null }\n } catch (e) {\n const msg = errorMessage(e)\n if (msg.includes('Empty preview image') || msg.includes('sizePx must')) {\n throw e\n }\n return { png: null, error: msg }\n }\n}\n\n/**\n * Rasterize logo (SVG / PNG / JPEG / WebP) to a PNG suitable for the header\n * box (~120×40). Throws on empty / invalid size; decode failures throw\n * (render helpers catch so one bad logo does not kill the file).\n */\nexport async function rasterizeLogo(\n input: Uint8Array,\n opts?: { widthPx?: number; heightPx?: number },\n): Promise<Buffer> {\n if (input.byteLength === 0) {\n throw new Error('Empty logo image')\n }\n const widthPx = opts?.widthPx ?? 120\n const heightPx = opts?.heightPx ?? 40\n if (!Number.isInteger(widthPx) || widthPx < 16) {\n throw new Error('logo widthPx must be an integer >= 16')\n }\n if (!Number.isInteger(heightPx) || heightPx < 16) {\n throw new Error('logo heightPx must be an integer >= 16')\n }\n try {\n return await sharp(Buffer.from(input), {\n limitInputPixels: 268_435_456,\n failOn: 'error',\n density: 288,\n })\n .resize({\n width: widthPx,\n height: heightPx,\n fit: 'contain',\n background: { r: 255, g: 255, b: 255, alpha: 0 },\n })\n .png()\n .toBuffer()\n } catch (e) {\n throw new Error(\n `Failed to rasterize logo (SVG/PNG/JPEG/WebP required): ${errorMessage(e)}`,\n )\n }\n}\n\n/**\n * Soft wrapper: returns null when sharp cannot decode the logo.\n * Still throws on empty input / invalid dimensions.\n */\nexport async function tryRasterizeLogo(\n input: Uint8Array,\n opts?: { widthPx?: number; heightPx?: number },\n): Promise<{ png: Buffer | null; error: string | null }> {\n try {\n const png = await rasterizeLogo(input, opts)\n return { png, error: null }\n } catch (e) {\n const msg = errorMessage(e)\n if (\n msg.includes('Empty logo image') ||\n msg.includes('widthPx must') ||\n msg.includes('heightPx must')\n ) {\n throw e\n }\n return { png: null, error: msg }\n }\n}\n\n/** Google Sheets IMAGE formula, mode 4 = custom size (fixed cell look). */\nexport function googleSheetsImageFormula(url: string, sizePx: number): string {\n const safe = url.replace(/\"/g, '\"\"')\n return `=IMAGE(\"${safe}\",4,${sizePx},${sizePx})`\n}\n","import ExcelJS from 'exceljs'\nimport { mapWithConcurrency } from './concurrency.js'\nimport { isAnonymousHttpImageUrl } from './fetch-url.js'\nimport {\n formatGeneratedLabel,\n priceListFilename,\n resolvePriceListLabels,\n} from './labels.js'\nimport {\n buildPriceListLayout,\n resolvePreviewImageConcurrency,\n validatePriceListInput,\n} from './layout.js'\nimport {\n googleSheetsImageFormula,\n tryNormalizePreviewSquare,\n tryRasterizeLogo,\n} from './preview-image.js'\nimport { resolveLogoBytes, resolvePreviewBytes } from './resolve-media.js'\nimport {\n buildCurrencyTotalSumIfFormula,\n buildLineSumFormula,\n buildTotalSumFormula,\n} from './sum-formula.js'\nimport type {\n PriceListInput,\n PriceListSheetModel,\n RenderPriceListXlsxResult,\n} from './types.js'\n\nfunction uniqueCurrencies(input: PriceListInput): string[] {\n const set = new Set<string>()\n for (const row of input.rows) {\n const c = row.currency?.trim()\n if (c) set.add(c)\n }\n return [...set].sort()\n}\n\n/**\n * Render a wholesale price-list workbook.\n * Single price column; Sum = Quantity × Price; Total at bottom.\n */\nexport async function renderPriceListXlsx(\n input: PriceListInput,\n): Promise<RenderPriceListXlsxResult> {\n const normalized = validatePriceListInput(input)\n const warnings: string[] = []\n const labels = resolvePriceListLabels(normalized.locale, normalized.labels)\n const layout = buildPriceListLayout(normalized)\n const title = labels.title\n const currencies = uniqueCurrencies(normalized)\n const multiCurrency = currencies.length > 1\n const concurrency = resolvePreviewImageConcurrency(normalized)\n\n const workbook = new ExcelJS.Workbook()\n workbook.creator = 'Mailoo'\n workbook.created = new Date(normalized.header.generatedAt)\n const sheetName =\n `${normalized.header.siteName}`.slice(0, 31) || title.slice(0, 31)\n const sheet = workbook.addWorksheet(sheetName, {\n properties: { defaultRowHeight: layout.dataRowHeightPt },\n views: [{ state: 'frozen', ySplit: layout.headerRow }],\n pageSetup: {\n orientation: 'landscape',\n fitToPage: true,\n fitToWidth: 1,\n fitToHeight: 0,\n },\n })\n\n for (const col of layout.columns) {\n let width = 16\n if (col.key === 'photo') width = layout.photoColWidthChars\n else if (col.key === 'link') width = 14\n else if (col.key === 'quantity' || col.key === 'sum' || col.key === 'price')\n width = 12\n else if (col.key === 'currencyHidden') width = 0\n else if (col.key === 'product') width = 28\n sheet.getColumn(col.index).width = width\n if (col.key === 'currencyHidden') {\n sheet.getColumn(col.index).hidden = true\n }\n }\n\n // Banner: site name, contacts, generated\n sheet.getCell('A1').value = normalized.header.siteName\n sheet.getCell('A1').font = { bold: true, size: 16 }\n sheet.mergeCells(1, 1, 1, Math.min(5, layout.columns.length))\n\n sheet.getCell('A2').value = normalized.header.contacts\n sheet.getCell('A2').alignment = { wrapText: true, vertical: 'top' }\n const contactLines = normalized.header.contacts.split(/\\r?\\n/).length\n sheet.getRow(2).height = Math.max(36, contactLines * 14)\n\n sheet.getCell('A3').value = formatGeneratedLabel(\n labels.generated,\n normalized.header.generatedAt,\n normalized.locale,\n normalized.header.timeZone,\n )\n sheet.getCell('A3').font = { italic: true, size: 10 }\n\n const logoBytes = await resolveLogoBytes(normalized)\n if (logoBytes) {\n const { png, error } = await tryRasterizeLogo(logoBytes)\n if (png) {\n const imageId = workbook.addImage({\n buffer: png as unknown as ExcelJS.Buffer,\n extension: 'png',\n })\n sheet.addImage(imageId, {\n tl: { col: 5, row: 0 },\n ext: { width: 120, height: 40 },\n editAs: 'oneCell',\n })\n } else if (error) {\n warnings.push(`header.logo: ${error}`)\n }\n }\n\n // Column headers\n const headerRow = sheet.getRow(layout.headerRow)\n headerRow.font = { bold: true }\n headerRow.height = 22\n for (const col of layout.columns) {\n if (col.key === 'currencyHidden') continue\n headerRow.getCell(col.index).value = col.header\n }\n sheet.autoFilter = {\n from: { row: layout.headerRow, column: 1 },\n to: {\n row: layout.headerRow,\n column: layout.columns.find((c) => c.key === 'sum')!.index,\n },\n }\n\n const sheetCells: PriceListSheetModel['cells'] = []\n const previewImageUrls: Array<string | null> = []\n\n const lastDataRow =\n normalized.rows.length === 0\n ? layout.firstDataRow - 1\n : layout.firstDataRow + normalized.rows.length - 1\n\n type PreviewPrep = {\n png: Buffer | null\n sheetsSafeUrl: string | null\n warning: string | null\n }\n\n const previewPrep = await mapWithConcurrency(\n normalized.rows,\n concurrency,\n async (row, i): Promise<PreviewPrep> => {\n const candidateUrl = row.previewImageUrl?.trim() || null\n const sheetsSafeUrl =\n candidateUrl && isAnonymousHttpImageUrl(candidateUrl)\n ? candidateUrl\n : null\n try {\n const previewBytes = await resolvePreviewBytes(normalized, i)\n if (!previewBytes) {\n return { png: null, sheetsSafeUrl, warning: null }\n }\n const { png, error } = await tryNormalizePreviewSquare(\n previewBytes,\n layout.photoSizePx,\n )\n if (png) return { png, sheetsSafeUrl, warning: null }\n return {\n png: null,\n sheetsSafeUrl,\n warning: error\n ? `rows[${i}].previewImage: ${error}`\n : `rows[${i}].previewImage: undecodable`,\n }\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e)\n return {\n png: null,\n sheetsSafeUrl,\n warning: `rows[${i}].previewImage: ${msg}`,\n }\n }\n },\n )\n\n for (let i = 0; i < normalized.rows.length; i++) {\n const row = normalized.rows[i]!\n const excelRow = layout.firstDataRow + i\n const sheetRow = sheet.getRow(excelRow)\n sheetRow.height = layout.dataRowHeightPt\n\n const photoCol = layout.columns.find((c) => c.key === 'photo')!\n const catCol = layout.columns.find((c) => c.key === 'category')!\n const prodCol = layout.columns.find((c) => c.key === 'product')!\n const varCol = layout.columns.find((c) => c.key === 'variant')!\n const packCol = layout.columns.find((c) => c.key === 'packaging')!\n const priceCol = layout.columns.find((c) => c.key === 'price')!\n const linkCol = layout.columns.find((c) => c.key === 'link')!\n const qtyCol = layout.columns.find((c) => c.key === 'quantity')!\n const sumCol = layout.columns.find((c) => c.key === 'sum')!\n const curCol = layout.columns.find((c) => c.key === 'currencyHidden')!\n\n sheetRow.getCell(catCol.index).value = row.category ?? ''\n sheetRow.getCell(prodCol.index).value = row.product\n sheetRow.getCell(varCol.index).value = row.variant ?? ''\n sheetRow.getCell(packCol.index).value = row.packaging ?? ''\n\n if (row.unitPrice === null) {\n sheetRow.getCell(priceCol.index).value = labels.onRequest\n } else {\n sheetRow.getCell(priceCol.index).value = row.unitPrice\n sheetRow.getCell(priceCol.index).numFmt = '#,##0.00'\n }\n\n sheetRow.getCell(linkCol.index).value = {\n text: labels.linkText,\n hyperlink: row.productUrl,\n }\n sheetCells.push({\n a1: `${linkCol.letter}${excelRow}`,\n value: labels.linkText,\n formula: `HYPERLINK(\"${row.productUrl.replace(/\"/g, '\"\"')}\",\"${labels.linkText.replace(/\"/g, '\"\"')}\")`,\n })\n\n sheetRow.getCell(qtyCol.index).value = null\n const sumFormula = buildLineSumFormula({ layout, row: excelRow })\n sheetRow.getCell(sumCol.index).value = { formula: sumFormula }\n sheetRow.getCell(sumCol.index).numFmt = '#,##0.00'\n sheetCells.push({\n a1: `${sumCol.letter}${excelRow}`,\n value: null,\n formula: sumFormula,\n })\n\n sheetRow.getCell(curCol.index).value = row.currency?.trim() || ''\n\n sheetRow.getCell(qtyCol.index).dataValidation = {\n type: 'whole',\n operator: 'greaterThanOrEqual',\n formulae: [0],\n allowBlank: true,\n showErrorMessage: true,\n errorTitle: labels.quantity,\n error: '>= 0',\n }\n\n const prep = previewPrep[i]!\n previewImageUrls.push(prep.sheetsSafeUrl)\n if (prep.warning) warnings.push(prep.warning)\n if (prep.png) {\n const imageId = workbook.addImage({\n buffer: prep.png as unknown as ExcelJS.Buffer,\n extension: 'png',\n })\n sheet.addImage(imageId, {\n tl: { col: photoCol.index - 1, row: excelRow - 1 },\n ext: { width: layout.photoSizePx, height: layout.photoSizePx },\n editAs: 'oneCell',\n })\n } else if (prep.sheetsSafeUrl) {\n sheetCells.push({\n a1: `${photoCol.letter}${excelRow}`,\n value: null,\n formula: googleSheetsImageFormula(\n prep.sheetsSafeUrl,\n layout.photoSizePx,\n ),\n })\n }\n }\n\n // Total row\n const totalExcelRow = layout.totalRow\n const qtyColIdx = layout.columns.find((c) => c.key === 'quantity')!.index\n const sumColIdx = layout.columns.find((c) => c.key === 'sum')!.index\n sheet.getRow(totalExcelRow).getCell(qtyColIdx).value = labels.total\n sheet.getRow(totalExcelRow).getCell(qtyColIdx).font = { bold: true }\n\n if (!multiCurrency) {\n const totalFormula = buildTotalSumFormula({\n layout,\n firstDataRow: layout.firstDataRow,\n lastDataRow,\n })\n sheet.getRow(totalExcelRow).getCell(sumColIdx).value = {\n formula: totalFormula,\n }\n sheet.getRow(totalExcelRow).getCell(sumColIdx).font = { bold: true }\n sheet.getRow(totalExcelRow).getCell(sumColIdx).numFmt = '#,##0.00'\n sheetCells.push({\n a1: `${layout.sumColLetter}${totalExcelRow}`,\n value: null,\n formula: totalFormula,\n })\n } else {\n let offset = 0\n for (const currency of currencies) {\n const r = totalExcelRow + offset\n sheet.getRow(r).getCell(qtyColIdx).value =\n offset === 0 ? `${labels.total} (${currency})` : currency\n sheet.getRow(r).getCell(qtyColIdx).font = { bold: true }\n const f = buildCurrencyTotalSumIfFormula({\n layout,\n firstDataRow: layout.firstDataRow,\n lastDataRow,\n currency,\n })\n sheet.getRow(r).getCell(sumColIdx).value = { formula: f }\n sheet.getRow(r).getCell(sumColIdx).font = { bold: true }\n sheet.getRow(r).getCell(sumColIdx).numFmt = '#,##0.00'\n sheetCells.push({\n a1: `${layout.sumColLetter}${r}`,\n value: null,\n formula: f,\n })\n offset += 1\n }\n }\n\n const buffer = Buffer.from(await workbook.xlsx.writeBuffer())\n const filename = priceListFilename(\n normalized.locale,\n normalized.header.generatedAt,\n labels.filenamePrefix,\n normalized.header.timeZone,\n )\n\n const sheetModel: PriceListSheetModel = {\n title,\n locale: normalized.locale,\n layout,\n cells: sheetCells,\n previewImageUrls,\n logoUrl: normalized.header.logoUrl?.trim() || null,\n }\n\n return {\n buffer,\n filename,\n contentType:\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n layout,\n sheetModel,\n warnings,\n }\n}\n\n/** @deprecated Use `renderPriceListXlsx`. */\nexport const buildWholesalePriceListXlsx = renderPriceListXlsx\n","import {\n fetchAbsoluteUrlBytes,\n isAnonymousHttpImageUrl,\n} from './fetch-url.js'\nimport type { PriceListInput } from './types.js'\n\nexport async function resolvePreviewBytes(\n input: PriceListInput,\n rowIndex: number,\n): Promise<Uint8Array | null> {\n const row = input.rows[rowIndex]!\n if (row.previewImageBytes && row.previewImageBytes.byteLength > 0) {\n return row.previewImageBytes\n }\n if (input.loadPreviewImage) {\n return input.loadPreviewImage({\n previewMediaId: row.previewMediaId,\n previewImageUrl: row.previewImageUrl,\n })\n }\n const url = row.previewImageUrl?.trim()\n if (url && isAnonymousHttpImageUrl(url)) {\n return fetchAbsoluteUrlBytes(url)\n }\n return null\n}\n\nexport async function resolveLogoBytes(\n input: PriceListInput,\n): Promise<Uint8Array | null> {\n if (input.header.logoBytes && input.header.logoBytes.byteLength > 0) {\n return input.header.logoBytes\n }\n const url = input.header.logoUrl?.trim()\n if (!url) return null\n if (input.loadLogo) return input.loadLogo(url)\n if (isAnonymousHttpImageUrl(url)) return fetchAbsolu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K,KAAK;AAAA,EAChD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,aACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAGO,IAAM,8BAA8B;","names":["sharp","ExcelJS"]}
@@ -0,0 +1,138 @@
1
+ import { P as PriceListInput, a as PriceListLayout, b as PriceListLabelKey, R as RenderPriceListXlsxResult } from '../types-ClEuQGG0.cjs';
2
+ export { c as PriceListBuiltinLocale, d as PriceListColumnKey, e as PriceListHeader, f as PriceListRow, g as PriceListSheetModel } from '../types-ClEuQGG0.cjs';
3
+
4
+ /** ~120 px square → Excel column width in characters (approx). */
5
+ declare const PRICE_LIST_DEFAULT_PHOTO_PX = 120;
6
+ /** Fixed data-row height so rows never jump without a photo (~130 px). */
7
+ declare const PRICE_LIST_DATA_ROW_HEIGHT_PT = 96;
8
+ declare const PRICE_LIST_PHOTO_COL_CHARS = 18;
9
+ /** Rows above the column header: logo/name, contacts, generated. */
10
+ declare const PRICE_LIST_BANNER_ROW_COUNT = 3;
11
+ declare function excelColumnLetter(index1Based: number): string;
12
+ /**
13
+ * Validate input and return a normalized shallow copy.
14
+ * Does **not** mutate the caller's `rows` (or `unitPrice` in place).
15
+ * Soft-coerces negative / NaN / non-finite `unitPrice` → null (“on request”).
16
+ */
17
+ declare function validatePriceListInput(input: PriceListInput): PriceListInput;
18
+ declare function resolvePreviewImageConcurrency(input: PriceListInput): number;
19
+ declare function buildPriceListLayout(input: PriceListInput): PriceListLayout;
20
+
21
+ /** Default max concurrent preview image loads / rasterizations. */
22
+ declare const DEFAULT_PREVIEW_IMAGE_CONCURRENCY = 6;
23
+ /**
24
+ * Run `mapper` over `items` with at most `concurrency` in flight.
25
+ * Result order matches `items` order.
26
+ */
27
+ declare function mapWithConcurrency<T, R>(items: readonly T[], concurrency: number, mapper: (item: T, index: number) => Promise<R>): Promise<R[]>;
28
+
29
+ declare function resolvePriceListLabels(locale: string, overrides?: Partial<Record<PriceListLabelKey, string>>): Record<PriceListLabelKey, string>;
30
+ declare function formatGeneratedLabel(template: string, generatedAt: string, locale: string, timeZone?: string | null): string;
31
+ /**
32
+ * Calendar date for the filename in `timeZone` (IANA), falling back to UTC.
33
+ * Parts are taken from Intl so midnight near zone offsets (e.g. Asia/Yerevan)
34
+ * lands on the correct local YYYY-MM-DD.
35
+ */
36
+ declare function priceListFilenameDate(generatedAt: string, timeZone?: string | null): string;
37
+ declare function priceListFilename(locale: string, generatedAt: string, prefix: string, timeZone?: string | null): string;
38
+
39
+ /**
40
+ * Soft-coerce unit prices for wholesale export.
41
+ * Negative / NaN / non-finite → null (“on request”) so one bad row cannot
42
+ * crash the whole workbook.
43
+ */
44
+ declare function coerceUnitPrice(value: number | null): number | null;
45
+
46
+ /**
47
+ * Best-effort fetch of absolute http(s) image bytes.
48
+ * Used as the package default when callers omit loadPreviewImage / loadLogo.
49
+ * Fail-soft: returns null on any network/HTTP error (do not throw).
50
+ *
51
+ * Do **not** rely on this for Mailoo `…/images/public/content?id=` URLs —
52
+ * those require X-API-Key. Callers must load via media id / API key instead.
53
+ */
54
+ declare function fetchAbsoluteUrlBytes(url: string): Promise<Uint8Array | null>;
55
+ /**
56
+ * Mailoo library image embed URLs need an API key — Google Sheets =IMAGE
57
+ * cannot send headers. Never put these in =IMAGE(); upload to Drive instead.
58
+ * Avatars (`/api/v1/public/avatars/…`) are anonymously readable and are OK.
59
+ */
60
+ declare function isMailooApiKeyedImageUrl(url: string): boolean;
61
+ /** Extract `id` from Mailoo `…/images/public/content?id=` URLs. */
62
+ declare function mediaIdFromMailooPublicImageUrl(url: string): string | null;
63
+ /** URL safe to hand to Sheets =IMAGE (anonymous GET). */
64
+ declare function isAnonymousHttpImageUrl(url: string): boolean;
65
+
66
+ /**
67
+ * Line sum: quantity × unit price.
68
+ * Blank / non-positive quantity → blank. Non-numeric price (on request) → blank.
69
+ */
70
+ declare function buildLineSumFormula(args: {
71
+ layout: PriceListLayout;
72
+ /** 1-based Excel row for this data line. */
73
+ row: number;
74
+ }): string;
75
+ declare function buildTotalSumFormula(args: {
76
+ layout: PriceListLayout;
77
+ firstDataRow: number;
78
+ lastDataRow: number;
79
+ }): string;
80
+ /**
81
+ * Per-currency total when the sheet mixes ISO codes.
82
+ * `currency` is written into the formula as a quoted literal.
83
+ */
84
+ declare function buildCurrencyTotalSumIfFormula(args: {
85
+ layout: PriceListLayout;
86
+ firstDataRow: number;
87
+ lastDataRow: number;
88
+ currency: string;
89
+ }): string;
90
+
91
+ /**
92
+ * Fit image into a square canvas with white padding (contain), PNG output.
93
+ * Used for xlsx embedded thumbnails so every photo cell is the same size.
94
+ * SVG input is accepted (sharp rasterizes via librsvg / built-in).
95
+ * Throws on empty input / invalid size; decode failures throw (callers that
96
+ * must keep the file alive should catch — see render helpers).
97
+ */
98
+ declare function normalizePreviewSquare(input: Uint8Array, sizePx?: number): Promise<Buffer>;
99
+ /**
100
+ * Soft wrapper: returns null when sharp cannot decode (corrupt / unsupported).
101
+ * Still throws on empty input / invalid sizePx (programmer errors).
102
+ */
103
+ declare function tryNormalizePreviewSquare(input: Uint8Array, sizePx?: number): Promise<{
104
+ png: Buffer | null;
105
+ error: string | null;
106
+ }>;
107
+ /**
108
+ * Rasterize logo (SVG / PNG / JPEG / WebP) to a PNG suitable for the header
109
+ * box (~120×40). Throws on empty / invalid size; decode failures throw
110
+ * (render helpers catch so one bad logo does not kill the file).
111
+ */
112
+ declare function rasterizeLogo(input: Uint8Array, opts?: {
113
+ widthPx?: number;
114
+ heightPx?: number;
115
+ }): Promise<Buffer>;
116
+ /**
117
+ * Soft wrapper: returns null when sharp cannot decode the logo.
118
+ * Still throws on empty input / invalid dimensions.
119
+ */
120
+ declare function tryRasterizeLogo(input: Uint8Array, opts?: {
121
+ widthPx?: number;
122
+ heightPx?: number;
123
+ }): Promise<{
124
+ png: Buffer | null;
125
+ error: string | null;
126
+ }>;
127
+ /** Google Sheets IMAGE formula, mode 4 = custom size (fixed cell look). */
128
+ declare function googleSheetsImageFormula(url: string, sizePx: number): string;
129
+
130
+ /**
131
+ * Render a wholesale price-list workbook.
132
+ * Single price column; Sum = Quantity × Price; Total at bottom.
133
+ */
134
+ declare function renderPriceListXlsx(input: PriceListInput): Promise<RenderPriceListXlsxResult>;
135
+ /** @deprecated Use `renderPriceListXlsx`. */
136
+ declare const buildWholesalePriceListXlsx: typeof renderPriceListXlsx;
137
+
138
+ export { DEFAULT_PREVIEW_IMAGE_CONCURRENCY, PRICE_LIST_BANNER_ROW_COUNT, PRICE_LIST_DATA_ROW_HEIGHT_PT, PRICE_LIST_DEFAULT_PHOTO_PX, PRICE_LIST_PHOTO_COL_CHARS, PriceListInput, PriceListLabelKey, PriceListLayout, RenderPriceListXlsxResult, buildCurrencyTotalSumIfFormula, buildLineSumFormula, buildPriceListLayout, buildTotalSumFormula, buildWholesalePriceListXlsx, coerceUnitPrice, excelColumnLetter, fetchAbsoluteUrlBytes, formatGeneratedLabel, googleSheetsImageFormula, isAnonymousHttpImageUrl, isMailooApiKeyedImageUrl, mapWithConcurrency, mediaIdFromMailooPublicImageUrl, normalizePreviewSquare, priceListFilename, priceListFilenameDate, rasterizeLogo, renderPriceListXlsx, resolvePreviewImageConcurrency, resolvePriceListLabels, tryNormalizePreviewSquare, tryRasterizeLogo, validatePriceListInput };
@@ -0,0 +1,138 @@
1
+ import { P as PriceListInput, a as PriceListLayout, b as PriceListLabelKey, R as RenderPriceListXlsxResult } from '../types-ClEuQGG0.js';
2
+ export { c as PriceListBuiltinLocale, d as PriceListColumnKey, e as PriceListHeader, f as PriceListRow, g as PriceListSheetModel } from '../types-ClEuQGG0.js';
3
+
4
+ /** ~120 px square → Excel column width in characters (approx). */
5
+ declare const PRICE_LIST_DEFAULT_PHOTO_PX = 120;
6
+ /** Fixed data-row height so rows never jump without a photo (~130 px). */
7
+ declare const PRICE_LIST_DATA_ROW_HEIGHT_PT = 96;
8
+ declare const PRICE_LIST_PHOTO_COL_CHARS = 18;
9
+ /** Rows above the column header: logo/name, contacts, generated. */
10
+ declare const PRICE_LIST_BANNER_ROW_COUNT = 3;
11
+ declare function excelColumnLetter(index1Based: number): string;
12
+ /**
13
+ * Validate input and return a normalized shallow copy.
14
+ * Does **not** mutate the caller's `rows` (or `unitPrice` in place).
15
+ * Soft-coerces negative / NaN / non-finite `unitPrice` → null (“on request”).
16
+ */
17
+ declare function validatePriceListInput(input: PriceListInput): PriceListInput;
18
+ declare function resolvePreviewImageConcurrency(input: PriceListInput): number;
19
+ declare function buildPriceListLayout(input: PriceListInput): PriceListLayout;
20
+
21
+ /** Default max concurrent preview image loads / rasterizations. */
22
+ declare const DEFAULT_PREVIEW_IMAGE_CONCURRENCY = 6;
23
+ /**
24
+ * Run `mapper` over `items` with at most `concurrency` in flight.
25
+ * Result order matches `items` order.
26
+ */
27
+ declare function mapWithConcurrency<T, R>(items: readonly T[], concurrency: number, mapper: (item: T, index: number) => Promise<R>): Promise<R[]>;
28
+
29
+ declare function resolvePriceListLabels(locale: string, overrides?: Partial<Record<PriceListLabelKey, string>>): Record<PriceListLabelKey, string>;
30
+ declare function formatGeneratedLabel(template: string, generatedAt: string, locale: string, timeZone?: string | null): string;
31
+ /**
32
+ * Calendar date for the filename in `timeZone` (IANA), falling back to UTC.
33
+ * Parts are taken from Intl so midnight near zone offsets (e.g. Asia/Yerevan)
34
+ * lands on the correct local YYYY-MM-DD.
35
+ */
36
+ declare function priceListFilenameDate(generatedAt: string, timeZone?: string | null): string;
37
+ declare function priceListFilename(locale: string, generatedAt: string, prefix: string, timeZone?: string | null): string;
38
+
39
+ /**
40
+ * Soft-coerce unit prices for wholesale export.
41
+ * Negative / NaN / non-finite → null (“on request”) so one bad row cannot
42
+ * crash the whole workbook.
43
+ */
44
+ declare function coerceUnitPrice(value: number | null): number | null;
45
+
46
+ /**
47
+ * Best-effort fetch of absolute http(s) image bytes.
48
+ * Used as the package default when callers omit loadPreviewImage / loadLogo.
49
+ * Fail-soft: returns null on any network/HTTP error (do not throw).
50
+ *
51
+ * Do **not** rely on this for Mailoo `…/images/public/content?id=` URLs —
52
+ * those require X-API-Key. Callers must load via media id / API key instead.
53
+ */
54
+ declare function fetchAbsoluteUrlBytes(url: string): Promise<Uint8Array | null>;
55
+ /**
56
+ * Mailoo library image embed URLs need an API key — Google Sheets =IMAGE
57
+ * cannot send headers. Never put these in =IMAGE(); upload to Drive instead.
58
+ * Avatars (`/api/v1/public/avatars/…`) are anonymously readable and are OK.
59
+ */
60
+ declare function isMailooApiKeyedImageUrl(url: string): boolean;
61
+ /** Extract `id` from Mailoo `…/images/public/content?id=` URLs. */
62
+ declare function mediaIdFromMailooPublicImageUrl(url: string): string | null;
63
+ /** URL safe to hand to Sheets =IMAGE (anonymous GET). */
64
+ declare function isAnonymousHttpImageUrl(url: string): boolean;
65
+
66
+ /**
67
+ * Line sum: quantity × unit price.
68
+ * Blank / non-positive quantity → blank. Non-numeric price (on request) → blank.
69
+ */
70
+ declare function buildLineSumFormula(args: {
71
+ layout: PriceListLayout;
72
+ /** 1-based Excel row for this data line. */
73
+ row: number;
74
+ }): string;
75
+ declare function buildTotalSumFormula(args: {
76
+ layout: PriceListLayout;
77
+ firstDataRow: number;
78
+ lastDataRow: number;
79
+ }): string;
80
+ /**
81
+ * Per-currency total when the sheet mixes ISO codes.
82
+ * `currency` is written into the formula as a quoted literal.
83
+ */
84
+ declare function buildCurrencyTotalSumIfFormula(args: {
85
+ layout: PriceListLayout;
86
+ firstDataRow: number;
87
+ lastDataRow: number;
88
+ currency: string;
89
+ }): string;
90
+
91
+ /**
92
+ * Fit image into a square canvas with white padding (contain), PNG output.
93
+ * Used for xlsx embedded thumbnails so every photo cell is the same size.
94
+ * SVG input is accepted (sharp rasterizes via librsvg / built-in).
95
+ * Throws on empty input / invalid size; decode failures throw (callers that
96
+ * must keep the file alive should catch — see render helpers).
97
+ */
98
+ declare function normalizePreviewSquare(input: Uint8Array, sizePx?: number): Promise<Buffer>;
99
+ /**
100
+ * Soft wrapper: returns null when sharp cannot decode (corrupt / unsupported).
101
+ * Still throws on empty input / invalid sizePx (programmer errors).
102
+ */
103
+ declare function tryNormalizePreviewSquare(input: Uint8Array, sizePx?: number): Promise<{
104
+ png: Buffer | null;
105
+ error: string | null;
106
+ }>;
107
+ /**
108
+ * Rasterize logo (SVG / PNG / JPEG / WebP) to a PNG suitable for the header
109
+ * box (~120×40). Throws on empty / invalid size; decode failures throw
110
+ * (render helpers catch so one bad logo does not kill the file).
111
+ */
112
+ declare function rasterizeLogo(input: Uint8Array, opts?: {
113
+ widthPx?: number;
114
+ heightPx?: number;
115
+ }): Promise<Buffer>;
116
+ /**
117
+ * Soft wrapper: returns null when sharp cannot decode the logo.
118
+ * Still throws on empty input / invalid dimensions.
119
+ */
120
+ declare function tryRasterizeLogo(input: Uint8Array, opts?: {
121
+ widthPx?: number;
122
+ heightPx?: number;
123
+ }): Promise<{
124
+ png: Buffer | null;
125
+ error: string | null;
126
+ }>;
127
+ /** Google Sheets IMAGE formula, mode 4 = custom size (fixed cell look). */
128
+ declare function googleSheetsImageFormula(url: string, sizePx: number): string;
129
+
130
+ /**
131
+ * Render a wholesale price-list workbook.
132
+ * Single price column; Sum = Quantity × Price; Total at bottom.
133
+ */
134
+ declare function renderPriceListXlsx(input: PriceListInput): Promise<RenderPriceListXlsxResult>;
135
+ /** @deprecated Use `renderPriceListXlsx`. */
136
+ declare const buildWholesalePriceListXlsx: typeof renderPriceListXlsx;
137
+
138
+ export { DEFAULT_PREVIEW_IMAGE_CONCURRENCY, PRICE_LIST_BANNER_ROW_COUNT, PRICE_LIST_DATA_ROW_HEIGHT_PT, PRICE_LIST_DEFAULT_PHOTO_PX, PRICE_LIST_PHOTO_COL_CHARS, PriceListInput, PriceListLabelKey, PriceListLayout, RenderPriceListXlsxResult, buildCurrencyTotalSumIfFormula, buildLineSumFormula, buildPriceListLayout, buildTotalSumFormula, buildWholesalePriceListXlsx, coerceUnitPrice, excelColumnLetter, fetchAbsoluteUrlBytes, formatGeneratedLabel, googleSheetsImageFormula, isAnonymousHttpImageUrl, isMailooApiKeyedImageUrl, mapWithConcurrency, mediaIdFromMailooPublicImageUrl, normalizePreviewSquare, priceListFilename, priceListFilenameDate, rasterizeLogo, renderPriceListXlsx, resolvePreviewImageConcurrency, resolvePriceListLabels, tryNormalizePreviewSquare, tryRasterizeLogo, validatePriceListInput };