@mailoo/market 1.35.9 → 1.35.12

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.
Files changed (37) hide show
  1. package/README.md +75 -1
  2. package/dist/{chunk-XNBHH43H.js → chunk-2J36VBGL.js} +1 -1
  3. package/dist/chunk-2J36VBGL.js.map +1 -0
  4. package/dist/{chunk-PJDNAZNK.js → chunk-CX4M5GD7.js} +2 -2
  5. package/dist/{env-config-CQz63aDi.d.ts → env-config-J1_nA7bY.d.ts} +1 -1
  6. package/dist/{env-config-DVw_uCsO.d.cts → env-config-kbRYTCf1.d.cts} +1 -1
  7. package/dist/{index-BgSGIULu.d.cts → index-y6hzxIwx.d.cts} +18 -1
  8. package/dist/{index-BgSGIULu.d.ts → index-y6hzxIwx.d.ts} +18 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/node/index.cjs.map +1 -1
  14. package/dist/node/index.d.cts +2 -2
  15. package/dist/node/index.d.ts +2 -2
  16. package/dist/node/index.js +1 -1
  17. package/dist/routes/index.cjs.map +1 -1
  18. package/dist/routes/index.d.cts +2 -2
  19. package/dist/routes/index.d.ts +2 -2
  20. package/dist/routes/index.js +2 -2
  21. package/dist/server/index.cjs.map +1 -1
  22. package/dist/server/index.d.cts +3 -3
  23. package/dist/server/index.d.ts +3 -3
  24. package/dist/server/index.js +2 -2
  25. package/dist/server/index.node.cjs.map +1 -1
  26. package/dist/server/index.node.d.cts +3 -3
  27. package/dist/server/index.node.d.ts +3 -3
  28. package/dist/server/index.node.js +2 -2
  29. package/dist/wholesale-price-list/index.cjs +1068 -0
  30. package/dist/wholesale-price-list/index.cjs.map +1 -0
  31. package/dist/wholesale-price-list/index.d.cts +327 -0
  32. package/dist/wholesale-price-list/index.d.ts +327 -0
  33. package/dist/wholesale-price-list/index.js +1006 -0
  34. package/dist/wholesale-price-list/index.js.map +1 -0
  35. package/package.json +12 -2
  36. package/dist/chunk-XNBHH43H.js.map +0 -1
  37. /package/dist/{chunk-PJDNAZNK.js.map → chunk-CX4M5GD7.js.map} +0 -0
@@ -0,0 +1,1068 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/wholesale-price-list/index.ts
31
+ var wholesale_price_list_exports = {};
32
+ __export(wholesale_price_list_exports, {
33
+ PRICE_LIST_BANNER_ROW_COUNT: () => PRICE_LIST_BANNER_ROW_COUNT,
34
+ PRICE_LIST_DATA_ROW_HEIGHT_PT: () => PRICE_LIST_DATA_ROW_HEIGHT_PT,
35
+ PRICE_LIST_DEFAULT_PHOTO_PX: () => PRICE_LIST_DEFAULT_PHOTO_PX,
36
+ PRICE_LIST_PHOTO_COL_CHARS: () => PRICE_LIST_PHOTO_COL_CHARS,
37
+ buildCurrencyTotalSumIfFormula: () => buildCurrencyTotalSumIfFormula,
38
+ buildLineSumFormula: () => buildLineSumFormula,
39
+ buildPriceListLayout: () => buildPriceListLayout,
40
+ buildTotalSumFormula: () => buildTotalSumFormula,
41
+ buildWholesalePriceListXlsx: () => buildWholesalePriceListXlsx,
42
+ coerceUnitPrice: () => coerceUnitPrice,
43
+ createPriceListGoogleClients: () => createPriceListGoogleClients,
44
+ excelColumnLetter: () => excelColumnLetter,
45
+ fetchAbsoluteUrlBytes: () => fetchAbsoluteUrlBytes,
46
+ formatGeneratedLabel: () => formatGeneratedLabel,
47
+ googleSheetsImageFormula: () => googleSheetsImageFormula,
48
+ isAnonymousHttpImageUrl: () => isAnonymousHttpImageUrl,
49
+ isMailooApiKeyedImageUrl: () => isMailooApiKeyedImageUrl,
50
+ mediaIdFromMailooPublicImageUrl: () => mediaIdFromMailooPublicImageUrl,
51
+ normalizePreviewSquare: () => normalizePreviewSquare,
52
+ priceListFilename: () => priceListFilename,
53
+ priceListFilenameDate: () => priceListFilenameDate,
54
+ rasterizeLogo: () => rasterizeLogo,
55
+ renderPriceListGoogleSheet: () => renderPriceListGoogleSheet,
56
+ renderPriceListXlsx: () => renderPriceListXlsx,
57
+ resolvePriceListLabels: () => resolvePriceListLabels,
58
+ validatePriceListInput: () => validatePriceListInput
59
+ });
60
+ module.exports = __toCommonJS(wholesale_price_list_exports);
61
+
62
+ // src/wholesale-price-list/labels.ts
63
+ var BUILTIN = {
64
+ en: {
65
+ title: "Price list",
66
+ photo: "Photo",
67
+ category: "Category",
68
+ product: "Product",
69
+ variant: "Variant",
70
+ packaging: "Packaging",
71
+ price: "Price",
72
+ onRequest: "on request",
73
+ link: "Link",
74
+ linkText: "Open",
75
+ quantity: "Quantity",
76
+ sum: "Sum",
77
+ total: "Total",
78
+ generated: "Generated: {date}",
79
+ filenamePrefix: "price-list"
80
+ },
81
+ ru: {
82
+ title: "\u041F\u0440\u0430\u0439\u0441-\u043B\u0438\u0441\u0442",
83
+ photo: "\u0424\u043E\u0442\u043E",
84
+ category: "\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F",
85
+ product: "\u0422\u043E\u0432\u0430\u0440",
86
+ variant: "\u0412\u0430\u0440\u0438\u0430\u043D\u0442",
87
+ packaging: "\u0423\u043F\u0430\u043A\u043E\u0432\u043A\u0430",
88
+ price: "\u0426\u0435\u043D\u0430",
89
+ onRequest: "\u043F\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0443",
90
+ link: "\u0421\u0441\u044B\u043B\u043A\u0430",
91
+ linkText: "\u041E\u0442\u043A\u0440\u044B\u0442\u044C",
92
+ quantity: "\u041A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E",
93
+ sum: "\u0421\u0443\u043C\u043C\u0430",
94
+ total: "\u0418\u0442\u043E\u0433\u043E",
95
+ generated: "\u0421\u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u043E: {date}",
96
+ filenamePrefix: "price-list"
97
+ },
98
+ hy: {
99
+ title: "\u0533\u0576\u0561\u0581\u0578\u0582\u0581\u0561\u056F",
100
+ photo: "\u053C\u0578\u0582\u057D\u0561\u0576\u056F\u0561\u0580",
101
+ category: "\u053F\u0561\u057F\u0565\u0563\u0578\u0580\u056B\u0561",
102
+ product: "\u0531\u057A\u0580\u0561\u0576\u0584",
103
+ variant: "\u054F\u0561\u0580\u0562\u0565\u0580\u0561\u056F",
104
+ packaging: "\u0553\u0561\u0569\u0565\u0569\u0561\u057E\u0578\u0580\u0578\u0582\u0574",
105
+ price: "\u0533\u056B\u0576",
106
+ onRequest: "\u0568\u057D\u057F \u0570\u0561\u0580\u0581\u0574\u0561\u0576",
107
+ link: "\u0540\u0572\u0578\u0582\u0574",
108
+ linkText: "\u0532\u0561\u0581\u0565\u056C",
109
+ quantity: "\u0554\u0561\u0576\u0561\u056F",
110
+ sum: "\u0533\u0578\u0582\u0574\u0561\u0580",
111
+ total: "\u0538\u0576\u0564\u0561\u0574\u0565\u0576\u0568",
112
+ generated: "\u054D\u057F\u0565\u0572\u056E\u057E\u0561\u056E \u0567\u055D {date}",
113
+ filenamePrefix: "price-list"
114
+ },
115
+ de: {
116
+ title: "Preisliste",
117
+ photo: "Foto",
118
+ category: "Kategorie",
119
+ product: "Produkt",
120
+ variant: "Variante",
121
+ packaging: "Verpackung",
122
+ price: "Preis",
123
+ onRequest: "auf Anfrage",
124
+ link: "Link",
125
+ linkText: "\xD6ffnen",
126
+ quantity: "Menge",
127
+ sum: "Summe",
128
+ total: "Gesamt",
129
+ generated: "Erstellt: {date}",
130
+ filenamePrefix: "price-list"
131
+ },
132
+ es: {
133
+ title: "Lista de precios",
134
+ photo: "Foto",
135
+ category: "Categor\xEDa",
136
+ product: "Producto",
137
+ variant: "Variante",
138
+ packaging: "Embalaje",
139
+ price: "Precio",
140
+ onRequest: "bajo petici\xF3n",
141
+ link: "Enlace",
142
+ linkText: "Abrir",
143
+ quantity: "Cantidad",
144
+ sum: "Suma",
145
+ total: "Total",
146
+ generated: "Generado: {date}",
147
+ filenamePrefix: "price-list"
148
+ }
149
+ };
150
+ var BUILTIN_LOCALES = /* @__PURE__ */ new Set(["hy", "ru", "en", "de", "es"]);
151
+ function resolvePriceListLabels(locale, overrides) {
152
+ const code = locale.trim().toLowerCase();
153
+ const base = BUILTIN_LOCALES.has(code) ? BUILTIN[code] : BUILTIN.en;
154
+ return { ...base, ...overrides };
155
+ }
156
+ function formatGeneratedLabel(template, generatedAt, locale, timeZone) {
157
+ const d = new Date(generatedAt);
158
+ if (Number.isNaN(d.getTime())) {
159
+ throw new Error(`header.generatedAt is not a valid ISO date: ${generatedAt}`);
160
+ }
161
+ const tz = timeZone && timeZone.trim() !== "" ? timeZone.trim() : "UTC";
162
+ const date = new Intl.DateTimeFormat(locale, {
163
+ dateStyle: "medium",
164
+ timeStyle: "short",
165
+ timeZone: tz
166
+ }).format(d);
167
+ return template.replace(/\{date\}/g, date);
168
+ }
169
+ function priceListFilenameDate(generatedAt, timeZone) {
170
+ const d = new Date(generatedAt);
171
+ if (Number.isNaN(d.getTime())) {
172
+ throw new Error(`header.generatedAt is not a valid ISO date: ${generatedAt}`);
173
+ }
174
+ const tz = timeZone && timeZone.trim() !== "" ? timeZone.trim() : "UTC";
175
+ const parts = new Intl.DateTimeFormat("en-US", {
176
+ timeZone: tz,
177
+ year: "numeric",
178
+ month: "2-digit",
179
+ day: "2-digit"
180
+ }).formatToParts(d);
181
+ const y = parts.find((p) => p.type === "year")?.value;
182
+ const m = parts.find((p) => p.type === "month")?.value;
183
+ const day = parts.find((p) => p.type === "day")?.value;
184
+ if (!y || !m || !day) {
185
+ throw new Error(`Failed to format filename date for timeZone=${tz}`);
186
+ }
187
+ return `${y}-${m}-${day}`;
188
+ }
189
+ function priceListFilename(locale, generatedAt, prefix, timeZone) {
190
+ const date = priceListFilenameDate(generatedAt, timeZone);
191
+ return `${prefix}-${locale}-${date}.xlsx`;
192
+ }
193
+
194
+ // src/wholesale-price-list/unit-price.ts
195
+ function coerceUnitPrice(value) {
196
+ if (value === null) return null;
197
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
198
+ return null;
199
+ }
200
+ return value;
201
+ }
202
+
203
+ // src/wholesale-price-list/layout.ts
204
+ var PRICE_LIST_DEFAULT_PHOTO_PX = 120;
205
+ var PRICE_LIST_DATA_ROW_HEIGHT_PT = 96;
206
+ var PRICE_LIST_PHOTO_COL_CHARS = 18;
207
+ var PRICE_LIST_BANNER_ROW_COUNT = 3;
208
+ function excelColumnLetter(index1Based) {
209
+ if (!Number.isInteger(index1Based) || index1Based < 1) {
210
+ throw new Error(`Invalid column index: ${index1Based}`);
211
+ }
212
+ let n = index1Based;
213
+ let s = "";
214
+ while (n > 0) {
215
+ const rem = (n - 1) % 26;
216
+ s = String.fromCharCode(65 + rem) + s;
217
+ n = Math.floor((n - 1) / 26);
218
+ }
219
+ return s;
220
+ }
221
+ function validatePriceListInput(input) {
222
+ if (!input || typeof input !== "object") {
223
+ throw new Error("PriceListInput is required");
224
+ }
225
+ if (typeof input.locale !== "string" || input.locale.trim() === "") {
226
+ throw new Error("locale is required");
227
+ }
228
+ if (!input.header || typeof input.header !== "object") {
229
+ throw new Error("header is required");
230
+ }
231
+ if (typeof input.header.siteName !== "string" || input.header.siteName.trim() === "") {
232
+ throw new Error("header.siteName is required");
233
+ }
234
+ if (typeof input.header.contacts !== "string") {
235
+ throw new Error("header.contacts must be a string");
236
+ }
237
+ if (typeof input.header.generatedAt !== "string" || Number.isNaN(new Date(input.header.generatedAt).getTime())) {
238
+ throw new Error("header.generatedAt must be a valid ISO date string");
239
+ }
240
+ if (!Array.isArray(input.rows)) {
241
+ throw new Error("rows must be an array");
242
+ }
243
+ for (let i = 0; i < input.rows.length; i++) {
244
+ const row = input.rows[i];
245
+ if (typeof row.productId !== "string" || row.productId.trim() === "") {
246
+ throw new Error(`rows[${i}].productId is required`);
247
+ }
248
+ if (typeof row.product !== "string" || row.product.trim() === "") {
249
+ throw new Error(`rows[${i}].product is required`);
250
+ }
251
+ if (typeof row.productUrl !== "string" || row.productUrl.trim() === "") {
252
+ throw new Error(`rows[${i}].productUrl is required`);
253
+ }
254
+ row.unitPrice = coerceUnitPrice(
255
+ typeof row.unitPrice === "number" || row.unitPrice === null ? row.unitPrice : Number.NaN
256
+ );
257
+ }
258
+ if (input.photoSizePx !== void 0 && (!Number.isInteger(input.photoSizePx) || input.photoSizePx < 32)) {
259
+ throw new Error("photoSizePx must be an integer >= 32");
260
+ }
261
+ }
262
+ function buildPriceListLayout(input) {
263
+ validatePriceListInput(input);
264
+ const labels = resolvePriceListLabels(input.locale, input.labels);
265
+ const photoSizePx = input.photoSizePx ?? PRICE_LIST_DEFAULT_PHOTO_PX;
266
+ const headerRow = PRICE_LIST_BANNER_ROW_COUNT + 1;
267
+ const firstDataRow = headerRow + 1;
268
+ const totalRow = firstDataRow + input.rows.length;
269
+ const keys = [
270
+ { key: "photo", header: labels.photo },
271
+ { key: "category", header: labels.category },
272
+ { key: "product", header: labels.product },
273
+ { key: "variant", header: labels.variant },
274
+ { key: "packaging", header: labels.packaging },
275
+ { key: "price", header: labels.price },
276
+ { key: "link", header: labels.link },
277
+ { key: "quantity", header: labels.quantity },
278
+ { key: "sum", header: labels.sum },
279
+ { key: "currencyHidden", header: "" }
280
+ ];
281
+ const columns = keys.map((c, i) => ({
282
+ key: c.key,
283
+ header: c.header,
284
+ index: i + 1,
285
+ letter: excelColumnLetter(i + 1)
286
+ }));
287
+ const letter = (key) => {
288
+ const col = columns.find((c) => c.key === key);
289
+ if (!col) throw new Error(`Missing column ${key}`);
290
+ return col.letter;
291
+ };
292
+ return {
293
+ locale: input.locale,
294
+ photoSizePx,
295
+ dataRowHeightPt: PRICE_LIST_DATA_ROW_HEIGHT_PT,
296
+ photoColWidthChars: PRICE_LIST_PHOTO_COL_CHARS,
297
+ headerRow,
298
+ firstDataRow,
299
+ totalRow,
300
+ columns,
301
+ priceColLetter: letter("price"),
302
+ quantityColLetter: letter("quantity"),
303
+ sumColLetter: letter("sum"),
304
+ currencyColLetter: letter("currencyHidden"),
305
+ linkColLetter: letter("link")
306
+ };
307
+ }
308
+
309
+ // src/wholesale-price-list/fetch-url.ts
310
+ async function fetchAbsoluteUrlBytes(url) {
311
+ const trimmed = url.trim();
312
+ if (!/^https?:\/\//i.test(trimmed)) return null;
313
+ try {
314
+ const res = await fetch(trimmed);
315
+ if (!res.ok) return null;
316
+ const buf = new Uint8Array(await res.arrayBuffer());
317
+ return buf.byteLength > 0 ? buf : null;
318
+ } catch {
319
+ return null;
320
+ }
321
+ }
322
+ function isMailooApiKeyedImageUrl(url) {
323
+ try {
324
+ const u = new URL(url.trim());
325
+ return u.pathname.includes("/api/v1/images/public/content");
326
+ } catch {
327
+ return false;
328
+ }
329
+ }
330
+ function mediaIdFromMailooPublicImageUrl(url) {
331
+ try {
332
+ const u = new URL(url.trim());
333
+ if (!u.pathname.includes("/api/v1/images/public/content")) return null;
334
+ const id = u.searchParams.get("id")?.trim();
335
+ return id || null;
336
+ } catch {
337
+ return null;
338
+ }
339
+ }
340
+ function isAnonymousHttpImageUrl(url) {
341
+ const trimmed = url.trim();
342
+ if (!/^https?:\/\//i.test(trimmed)) return false;
343
+ if (isMailooApiKeyedImageUrl(trimmed)) return false;
344
+ return true;
345
+ }
346
+
347
+ // src/wholesale-price-list/sum-formula.ts
348
+ function buildLineSumFormula(args) {
349
+ const { layout, row } = args;
350
+ const q = `${layout.quantityColLetter}${row}`;
351
+ const p = `${layout.priceColLetter}${row}`;
352
+ return `IFERROR(IF(N(${q})<=0,"",IF(NOT(ISNUMBER(${p})),"",${q}*${p})),"")`;
353
+ }
354
+ function buildTotalSumFormula(args) {
355
+ const { layout, firstDataRow, lastDataRow } = args;
356
+ if (lastDataRow < firstDataRow) return "0";
357
+ const range = `${layout.sumColLetter}${firstDataRow}:${layout.sumColLetter}${lastDataRow}`;
358
+ return `SUM(${range})`;
359
+ }
360
+ function buildCurrencyTotalSumIfFormula(args) {
361
+ const { layout, firstDataRow, lastDataRow, currency } = args;
362
+ if (lastDataRow < firstDataRow) return "0";
363
+ if (!currency || currency.includes('"')) {
364
+ throw new Error("currency for SUMIF must be a non-empty string without quotes");
365
+ }
366
+ const sumRange = `${layout.sumColLetter}${firstDataRow}:${layout.sumColLetter}${lastDataRow}`;
367
+ const curRange = `${layout.currencyColLetter}${firstDataRow}:${layout.currencyColLetter}${lastDataRow}`;
368
+ return `SUMIF(${curRange},"${currency}",${sumRange})`;
369
+ }
370
+
371
+ // src/wholesale-price-list/preview-image.ts
372
+ var import_sharp = __toESM(require("sharp"), 1);
373
+ async function normalizePreviewSquare(input, sizePx = PRICE_LIST_DEFAULT_PHOTO_PX) {
374
+ if (!Number.isInteger(sizePx) || sizePx < 32) {
375
+ throw new Error("sizePx must be an integer >= 32");
376
+ }
377
+ if (input.byteLength === 0) {
378
+ throw new Error("Empty preview image");
379
+ }
380
+ return (0, import_sharp.default)(Buffer.from(input), {
381
+ limitInputPixels: 268435456,
382
+ failOn: "error"
383
+ }).rotate().resize({
384
+ width: sizePx,
385
+ height: sizePx,
386
+ fit: "contain",
387
+ background: { r: 255, g: 255, b: 255, alpha: 1 }
388
+ }).png().toBuffer();
389
+ }
390
+ async function rasterizeLogo(input, opts) {
391
+ if (input.byteLength === 0) {
392
+ throw new Error("Empty logo image");
393
+ }
394
+ const widthPx = opts?.widthPx ?? 120;
395
+ const heightPx = opts?.heightPx ?? 40;
396
+ if (!Number.isInteger(widthPx) || widthPx < 16) {
397
+ throw new Error("logo widthPx must be an integer >= 16");
398
+ }
399
+ if (!Number.isInteger(heightPx) || heightPx < 16) {
400
+ throw new Error("logo heightPx must be an integer >= 16");
401
+ }
402
+ try {
403
+ return await (0, import_sharp.default)(Buffer.from(input), {
404
+ limitInputPixels: 268435456,
405
+ failOn: "error",
406
+ density: 288
407
+ }).resize({
408
+ width: widthPx,
409
+ height: heightPx,
410
+ fit: "contain",
411
+ background: { r: 255, g: 255, b: 255, alpha: 0 }
412
+ }).png().toBuffer();
413
+ } catch (e) {
414
+ const msg = e instanceof Error ? e.message : String(e);
415
+ throw new Error(
416
+ `Failed to rasterize logo (SVG/PNG/JPEG/WebP required): ${msg}`
417
+ );
418
+ }
419
+ }
420
+ function googleSheetsImageFormula(url, sizePx) {
421
+ const safe = url.replace(/"/g, '""');
422
+ return `=IMAGE("${safe}",4,${sizePx},${sizePx})`;
423
+ }
424
+
425
+ // src/wholesale-price-list/build-xlsx.ts
426
+ var import_exceljs = __toESM(require("exceljs"), 1);
427
+ async function resolvePreviewBytes(input, rowIndex) {
428
+ const row = input.rows[rowIndex];
429
+ if (row.previewImageBytes && row.previewImageBytes.byteLength > 0) {
430
+ return row.previewImageBytes;
431
+ }
432
+ if (input.loadPreviewImage) {
433
+ return input.loadPreviewImage({
434
+ previewMediaId: row.previewMediaId,
435
+ previewImageUrl: row.previewImageUrl
436
+ });
437
+ }
438
+ const url = row.previewImageUrl?.trim();
439
+ if (url && isAnonymousHttpImageUrl(url)) {
440
+ return fetchAbsoluteUrlBytes(url);
441
+ }
442
+ return null;
443
+ }
444
+ async function resolveLogoBytes(input) {
445
+ if (input.header.logoBytes && input.header.logoBytes.byteLength > 0) {
446
+ return input.header.logoBytes;
447
+ }
448
+ const url = input.header.logoUrl?.trim();
449
+ if (!url) return null;
450
+ if (input.loadLogo) return input.loadLogo(url);
451
+ if (isAnonymousHttpImageUrl(url)) return fetchAbsoluteUrlBytes(url);
452
+ return null;
453
+ }
454
+ function uniqueCurrencies(input) {
455
+ const set = /* @__PURE__ */ new Set();
456
+ for (const row of input.rows) {
457
+ const c = row.currency?.trim();
458
+ if (c) set.add(c);
459
+ }
460
+ return [...set].sort();
461
+ }
462
+ async function renderPriceListXlsx(input) {
463
+ validatePriceListInput(input);
464
+ const labels = resolvePriceListLabels(input.locale, input.labels);
465
+ const layout = buildPriceListLayout(input);
466
+ const title = labels.title;
467
+ const currencies = uniqueCurrencies(input);
468
+ const multiCurrency = currencies.length > 1;
469
+ const workbook = new import_exceljs.default.Workbook();
470
+ workbook.creator = "Mailoo";
471
+ workbook.created = new Date(input.header.generatedAt);
472
+ const sheetName = `${input.header.siteName}`.slice(0, 31) || title.slice(0, 31);
473
+ const sheet = workbook.addWorksheet(sheetName, {
474
+ properties: { defaultRowHeight: layout.dataRowHeightPt },
475
+ views: [{ state: "frozen", ySplit: layout.headerRow }],
476
+ pageSetup: {
477
+ orientation: "landscape",
478
+ fitToPage: true,
479
+ fitToWidth: 1,
480
+ fitToHeight: 0
481
+ }
482
+ });
483
+ for (const col of layout.columns) {
484
+ let width = 16;
485
+ if (col.key === "photo") width = layout.photoColWidthChars;
486
+ else if (col.key === "link") width = 14;
487
+ else if (col.key === "quantity" || col.key === "sum" || col.key === "price")
488
+ width = 12;
489
+ else if (col.key === "currencyHidden") width = 0;
490
+ else if (col.key === "product") width = 28;
491
+ sheet.getColumn(col.index).width = width;
492
+ if (col.key === "currencyHidden") {
493
+ sheet.getColumn(col.index).hidden = true;
494
+ }
495
+ }
496
+ sheet.getCell("A1").value = input.header.siteName;
497
+ sheet.getCell("A1").font = { bold: true, size: 16 };
498
+ sheet.mergeCells(1, 1, 1, Math.min(5, layout.columns.length));
499
+ sheet.getCell("A2").value = input.header.contacts;
500
+ sheet.getCell("A2").alignment = { wrapText: true, vertical: "top" };
501
+ const contactLines = input.header.contacts.split(/\r?\n/).length;
502
+ sheet.getRow(2).height = Math.max(36, contactLines * 14);
503
+ sheet.getCell("A3").value = formatGeneratedLabel(
504
+ labels.generated,
505
+ input.header.generatedAt,
506
+ input.locale,
507
+ input.header.timeZone
508
+ );
509
+ sheet.getCell("A3").font = { italic: true, size: 10 };
510
+ const logoBytes = await resolveLogoBytes(input);
511
+ if (logoBytes) {
512
+ const png = await rasterizeLogo(logoBytes);
513
+ const imageId = workbook.addImage({
514
+ buffer: png,
515
+ extension: "png"
516
+ });
517
+ sheet.addImage(imageId, {
518
+ tl: { col: 5, row: 0 },
519
+ ext: { width: 120, height: 40 },
520
+ editAs: "oneCell"
521
+ });
522
+ }
523
+ const headerRow = sheet.getRow(layout.headerRow);
524
+ headerRow.font = { bold: true };
525
+ headerRow.height = 22;
526
+ for (const col of layout.columns) {
527
+ if (col.key === "currencyHidden") continue;
528
+ headerRow.getCell(col.index).value = col.header;
529
+ }
530
+ sheet.autoFilter = {
531
+ from: { row: layout.headerRow, column: 1 },
532
+ to: {
533
+ row: layout.headerRow,
534
+ column: layout.columns.find((c) => c.key === "sum").index
535
+ }
536
+ };
537
+ const sheetCells = [];
538
+ const previewImageUrls = [];
539
+ const lastDataRow = input.rows.length === 0 ? layout.firstDataRow - 1 : layout.firstDataRow + input.rows.length - 1;
540
+ for (let i = 0; i < input.rows.length; i++) {
541
+ const row = input.rows[i];
542
+ const excelRow = layout.firstDataRow + i;
543
+ const sheetRow = sheet.getRow(excelRow);
544
+ sheetRow.height = layout.dataRowHeightPt;
545
+ const photoCol = layout.columns.find((c) => c.key === "photo");
546
+ const catCol = layout.columns.find((c) => c.key === "category");
547
+ const prodCol = layout.columns.find((c) => c.key === "product");
548
+ const varCol = layout.columns.find((c) => c.key === "variant");
549
+ const packCol = layout.columns.find((c) => c.key === "packaging");
550
+ const priceCol = layout.columns.find((c) => c.key === "price");
551
+ const linkCol = layout.columns.find((c) => c.key === "link");
552
+ const qtyCol = layout.columns.find((c) => c.key === "quantity");
553
+ const sumCol = layout.columns.find((c) => c.key === "sum");
554
+ const curCol = layout.columns.find((c) => c.key === "currencyHidden");
555
+ sheetRow.getCell(catCol.index).value = row.category ?? "";
556
+ sheetRow.getCell(prodCol.index).value = row.product;
557
+ sheetRow.getCell(varCol.index).value = row.variant ?? "";
558
+ sheetRow.getCell(packCol.index).value = row.packaging ?? "";
559
+ if (row.unitPrice === null) {
560
+ sheetRow.getCell(priceCol.index).value = labels.onRequest;
561
+ } else {
562
+ sheetRow.getCell(priceCol.index).value = row.unitPrice;
563
+ sheetRow.getCell(priceCol.index).numFmt = "#,##0.00";
564
+ }
565
+ sheetRow.getCell(linkCol.index).value = {
566
+ text: labels.linkText,
567
+ hyperlink: row.productUrl
568
+ };
569
+ sheetCells.push({
570
+ a1: `${linkCol.letter}${excelRow}`,
571
+ value: labels.linkText,
572
+ formula: `HYPERLINK("${row.productUrl.replace(/"/g, '""')}","${labels.linkText.replace(/"/g, '""')}")`
573
+ });
574
+ sheetRow.getCell(qtyCol.index).value = null;
575
+ const sumFormula = buildLineSumFormula({ layout, row: excelRow });
576
+ sheetRow.getCell(sumCol.index).value = { formula: sumFormula };
577
+ sheetRow.getCell(sumCol.index).numFmt = "#,##0.00";
578
+ sheetCells.push({
579
+ a1: `${sumCol.letter}${excelRow}`,
580
+ value: null,
581
+ formula: sumFormula
582
+ });
583
+ sheetRow.getCell(curCol.index).value = row.currency?.trim() || "";
584
+ sheetRow.getCell(qtyCol.index).dataValidation = {
585
+ type: "whole",
586
+ operator: "greaterThanOrEqual",
587
+ formulae: [0],
588
+ allowBlank: true,
589
+ showErrorMessage: true,
590
+ errorTitle: labels.quantity,
591
+ error: ">= 0"
592
+ };
593
+ const previewBytes = await resolvePreviewBytes(input, i);
594
+ const candidateUrl = row.previewImageUrl?.trim() || null;
595
+ const sheetsSafeUrl = candidateUrl && isAnonymousHttpImageUrl(candidateUrl) ? candidateUrl : null;
596
+ previewImageUrls.push(sheetsSafeUrl);
597
+ if (previewBytes) {
598
+ const png = await normalizePreviewSquare(
599
+ previewBytes,
600
+ layout.photoSizePx
601
+ );
602
+ const imageId = workbook.addImage({
603
+ buffer: png,
604
+ extension: "png"
605
+ });
606
+ sheet.addImage(imageId, {
607
+ tl: { col: photoCol.index - 1, row: excelRow - 1 },
608
+ ext: { width: layout.photoSizePx, height: layout.photoSizePx },
609
+ editAs: "oneCell"
610
+ });
611
+ } else if (sheetsSafeUrl) {
612
+ sheetCells.push({
613
+ a1: `${photoCol.letter}${excelRow}`,
614
+ value: null,
615
+ formula: googleSheetsImageFormula(sheetsSafeUrl, layout.photoSizePx)
616
+ });
617
+ }
618
+ }
619
+ const totalExcelRow = layout.totalRow;
620
+ const qtyColIdx = layout.columns.find((c) => c.key === "quantity").index;
621
+ const sumColIdx = layout.columns.find((c) => c.key === "sum").index;
622
+ sheet.getRow(totalExcelRow).getCell(qtyColIdx).value = labels.total;
623
+ sheet.getRow(totalExcelRow).getCell(qtyColIdx).font = { bold: true };
624
+ if (!multiCurrency) {
625
+ const totalFormula = buildTotalSumFormula({
626
+ layout,
627
+ firstDataRow: layout.firstDataRow,
628
+ lastDataRow
629
+ });
630
+ sheet.getRow(totalExcelRow).getCell(sumColIdx).value = {
631
+ formula: totalFormula
632
+ };
633
+ sheet.getRow(totalExcelRow).getCell(sumColIdx).font = { bold: true };
634
+ sheet.getRow(totalExcelRow).getCell(sumColIdx).numFmt = "#,##0.00";
635
+ sheetCells.push({
636
+ a1: `${layout.sumColLetter}${totalExcelRow}`,
637
+ value: null,
638
+ formula: totalFormula
639
+ });
640
+ } else {
641
+ let offset = 0;
642
+ for (const currency of currencies) {
643
+ const r = totalExcelRow + offset;
644
+ sheet.getRow(r).getCell(qtyColIdx).value = offset === 0 ? `${labels.total} (${currency})` : currency;
645
+ sheet.getRow(r).getCell(qtyColIdx).font = { bold: true };
646
+ const f = buildCurrencyTotalSumIfFormula({
647
+ layout,
648
+ firstDataRow: layout.firstDataRow,
649
+ lastDataRow,
650
+ currency
651
+ });
652
+ sheet.getRow(r).getCell(sumColIdx).value = { formula: f };
653
+ sheet.getRow(r).getCell(sumColIdx).font = { bold: true };
654
+ sheet.getRow(r).getCell(sumColIdx).numFmt = "#,##0.00";
655
+ sheetCells.push({
656
+ a1: `${layout.sumColLetter}${r}`,
657
+ value: null,
658
+ formula: f
659
+ });
660
+ offset += 1;
661
+ }
662
+ }
663
+ const buffer = Buffer.from(await workbook.xlsx.writeBuffer());
664
+ const filename = priceListFilename(
665
+ input.locale,
666
+ input.header.generatedAt,
667
+ labels.filenamePrefix,
668
+ input.header.timeZone
669
+ );
670
+ const sheetModel = {
671
+ title,
672
+ locale: input.locale,
673
+ layout,
674
+ cells: sheetCells,
675
+ previewImageUrls,
676
+ logoUrl: input.header.logoUrl?.trim() || null
677
+ };
678
+ return {
679
+ buffer,
680
+ filename,
681
+ contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
682
+ layout,
683
+ sheetModel
684
+ };
685
+ }
686
+ var buildWholesalePriceListXlsx = renderPriceListXlsx;
687
+
688
+ // src/wholesale-price-list/google-sheets.ts
689
+ var SCOPES = [
690
+ "https://www.googleapis.com/auth/spreadsheets",
691
+ "https://www.googleapis.com/auth/drive"
692
+ ];
693
+ function parseServiceAccountJson(raw) {
694
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
695
+ return raw;
696
+ }
697
+ if (typeof raw !== "string" || !raw.trim()) {
698
+ throw new Error("serviceAccountJson is required");
699
+ }
700
+ try {
701
+ const parsed = JSON.parse(raw);
702
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
703
+ throw new Error("not an object");
704
+ }
705
+ return parsed;
706
+ } catch {
707
+ throw new Error("serviceAccountJson must be valid JSON object");
708
+ }
709
+ }
710
+ async function createPriceListGoogleClients(serviceAccountJson) {
711
+ const credentials = parseServiceAccountJson(serviceAccountJson);
712
+ const { google } = await import("googleapis");
713
+ const auth = new google.auth.GoogleAuth({
714
+ credentials,
715
+ scopes: SCOPES
716
+ });
717
+ return {
718
+ sheets: google.sheets({
719
+ version: "v4",
720
+ auth
721
+ }),
722
+ drive: google.drive({
723
+ version: "v3",
724
+ auth
725
+ })
726
+ };
727
+ }
728
+ async function resolvePreviewBytes2(input, rowIndex) {
729
+ const row = input.rows[rowIndex];
730
+ if (row.previewImageBytes && row.previewImageBytes.byteLength > 0) {
731
+ return row.previewImageBytes;
732
+ }
733
+ if (input.loadPreviewImage) {
734
+ return input.loadPreviewImage({
735
+ previewMediaId: row.previewMediaId,
736
+ previewImageUrl: row.previewImageUrl
737
+ });
738
+ }
739
+ const url = row.previewImageUrl?.trim();
740
+ if (url && isAnonymousHttpImageUrl(url)) {
741
+ return fetchAbsoluteUrlBytes(url);
742
+ }
743
+ return null;
744
+ }
745
+ async function resolveLogoBytes2(input) {
746
+ if (input.header.logoBytes && input.header.logoBytes.byteLength > 0) {
747
+ return input.header.logoBytes;
748
+ }
749
+ const url = input.header.logoUrl?.trim();
750
+ if (!url) return null;
751
+ if (input.loadLogo) return input.loadLogo(url);
752
+ if (isAnonymousHttpImageUrl(url)) return fetchAbsoluteUrlBytes(url);
753
+ return null;
754
+ }
755
+ async function uploadPngPublic(drive, name, png, folderId) {
756
+ const created = await drive.files.create({
757
+ requestBody: {
758
+ name,
759
+ mimeType: "image/png",
760
+ parents: folderId ? [folderId] : void 0
761
+ },
762
+ media: { mimeType: "image/png", body: Buffer.from(png) },
763
+ fields: "id",
764
+ supportsAllDrives: true
765
+ });
766
+ const fileId = created.data.id;
767
+ if (!fileId) throw new Error("Drive file create returned no id");
768
+ await drive.permissions.create({
769
+ fileId,
770
+ requestBody: { role: "reader", type: "anyone" },
771
+ supportsAllDrives: true
772
+ });
773
+ return `https://drive.google.com/uc?export=view&id=${encodeURIComponent(fileId)}`;
774
+ }
775
+ function colWidthPixels(layout, key) {
776
+ if (key === "photo") return Math.round(layout.photoSizePx * 1.15);
777
+ if (key === "product") return 180;
778
+ if (key === "link" || key === "quantity" || key === "sum" || key === "price")
779
+ return 100;
780
+ if (key === "currencyHidden") return 1;
781
+ return 120;
782
+ }
783
+ async function renderPriceListGoogleSheet(input, options) {
784
+ validatePriceListInput(input);
785
+ const labels = resolvePriceListLabels(input.locale, input.labels);
786
+ const layout = buildPriceListLayout(input);
787
+ const clients = options.clients ?? await createPriceListGoogleClients(options.serviceAccountJson);
788
+ const { sheets, drive } = clients;
789
+ const title = `${input.header.siteName} \u2014 ${labels.title} (${input.locale})`.slice(
790
+ 0,
791
+ 100
792
+ );
793
+ const created = await sheets.spreadsheets.create({
794
+ requestBody: {
795
+ properties: { title },
796
+ sheets: [
797
+ {
798
+ properties: {
799
+ title: labels.title.slice(0, 100),
800
+ gridProperties: {
801
+ frozenRowCount: layout.headerRow
802
+ }
803
+ }
804
+ }
805
+ ]
806
+ },
807
+ fields: "spreadsheetId,spreadsheetUrl"
808
+ });
809
+ const spreadsheetId = created.data.spreadsheetId;
810
+ const spreadsheetUrl = created.data.spreadsheetUrl;
811
+ if (!spreadsheetId || !spreadsheetUrl) {
812
+ throw new Error("Sheets create returned no spreadsheetId/url");
813
+ }
814
+ const meta = await sheets.spreadsheets.get({
815
+ spreadsheetId,
816
+ fields: "sheets.properties"
817
+ });
818
+ const sheetId = meta.data.sheets?.[0]?.properties?.sheetId;
819
+ if (sheetId == null) throw new Error("Missing sheetId");
820
+ if (options.driveFolderId?.trim()) {
821
+ const file = await drive.files.get({
822
+ fileId: spreadsheetId,
823
+ fields: "parents",
824
+ supportsAllDrives: true
825
+ });
826
+ const prevParents = (file.data.parents ?? []).join(",");
827
+ await drive.files.update({
828
+ fileId: spreadsheetId,
829
+ addParents: options.driveFolderId.trim(),
830
+ removeParents: prevParents || void 0,
831
+ supportsAllDrives: true,
832
+ fields: "id,parents"
833
+ });
834
+ }
835
+ if (options.shareWithEmail?.trim()) {
836
+ await drive.permissions.create({
837
+ fileId: spreadsheetId,
838
+ requestBody: {
839
+ type: "user",
840
+ role: "writer",
841
+ emailAddress: options.shareWithEmail.trim()
842
+ },
843
+ sendNotificationEmail: false,
844
+ supportsAllDrives: true
845
+ });
846
+ }
847
+ const folderId = options.driveFolderId?.trim() || null;
848
+ let logoImageUrl = null;
849
+ const logoBytes = await resolveLogoBytes2(input);
850
+ if (logoBytes) {
851
+ const png = await rasterizeLogo(logoBytes);
852
+ logoImageUrl = await uploadPngPublic(
853
+ drive,
854
+ `price-list-logo-${input.locale}.png`,
855
+ png,
856
+ folderId
857
+ );
858
+ } else {
859
+ const candidate = input.header.logoUrl?.trim() || null;
860
+ if (candidate && !/\.svg(\?|$)/i.test(candidate) && isAnonymousHttpImageUrl(candidate)) {
861
+ logoImageUrl = candidate;
862
+ }
863
+ }
864
+ const generated = formatGeneratedLabel(
865
+ labels.generated,
866
+ input.header.generatedAt,
867
+ input.locale,
868
+ input.header.timeZone
869
+ );
870
+ const lastColLetter = layout.columns.find((c) => c.key === "sum").letter;
871
+ const values = [];
872
+ const bannerRow1 = Array(layout.columns.length).fill("");
873
+ bannerRow1[0] = input.header.siteName;
874
+ if (logoImageUrl) {
875
+ bannerRow1[5] = googleSheetsImageFormula(logoImageUrl, 40);
876
+ }
877
+ values.push(bannerRow1);
878
+ values.push([
879
+ input.header.contacts,
880
+ ...Array(layout.columns.length - 1).fill("")
881
+ ]);
882
+ values.push([generated, ...Array(layout.columns.length - 1).fill("")]);
883
+ values.push(
884
+ layout.columns.map((c) => c.key === "currencyHidden" ? "" : c.header)
885
+ );
886
+ const currencies = /* @__PURE__ */ new Set();
887
+ for (let i = 0; i < input.rows.length; i++) {
888
+ const row = input.rows[i];
889
+ const excelRow = layout.firstDataRow + i;
890
+ const line = Array(layout.columns.length).fill("");
891
+ const photoIdx = layout.columns.findIndex((c) => c.key === "photo");
892
+ let imageUrl = null;
893
+ const bytes = await resolvePreviewBytes2(input, i);
894
+ if (bytes) {
895
+ const png = await normalizePreviewSquare(bytes, layout.photoSizePx);
896
+ imageUrl = await uploadPngPublic(
897
+ drive,
898
+ `price-list-${row.productId}-${row.variantId ?? "p"}.png`,
899
+ png,
900
+ folderId
901
+ );
902
+ } else {
903
+ const candidate = row.previewImageUrl?.trim() || null;
904
+ if (candidate && isAnonymousHttpImageUrl(candidate)) {
905
+ imageUrl = candidate;
906
+ }
907
+ }
908
+ if (imageUrl && photoIdx >= 0) {
909
+ line[photoIdx] = googleSheetsImageFormula(imageUrl, layout.photoSizePx);
910
+ }
911
+ line[layout.columns.findIndex((c) => c.key === "category")] = row.category ?? "";
912
+ line[layout.columns.findIndex((c) => c.key === "product")] = row.product;
913
+ line[layout.columns.findIndex((c) => c.key === "variant")] = row.variant ?? "";
914
+ line[layout.columns.findIndex((c) => c.key === "packaging")] = row.packaging ?? "";
915
+ const priceIdx = layout.columns.findIndex((c) => c.key === "price");
916
+ if (row.unitPrice === null) {
917
+ line[priceIdx] = labels.onRequest;
918
+ } else {
919
+ line[priceIdx] = String(row.unitPrice);
920
+ }
921
+ const linkIdx = layout.columns.findIndex((c) => c.key === "link");
922
+ line[linkIdx] = `=HYPERLINK("${row.productUrl.replace(/"/g, '""')}","${labels.linkText.replace(/"/g, '""')}")`;
923
+ const qtyIdx = layout.columns.findIndex((c) => c.key === "quantity");
924
+ line[qtyIdx] = "";
925
+ const sumIdx = layout.columns.findIndex((c) => c.key === "sum");
926
+ line[sumIdx] = `=${buildLineSumFormula({ layout, row: excelRow })}`;
927
+ const curIdx = layout.columns.findIndex((c) => c.key === "currencyHidden");
928
+ const cur = row.currency?.trim() || "";
929
+ line[curIdx] = cur;
930
+ if (cur) currencies.add(cur);
931
+ values.push(line);
932
+ }
933
+ const currencyList = [...currencies].sort();
934
+ const multi = currencyList.length > 1;
935
+ if (!multi) {
936
+ const totalLine = Array(layout.columns.length).fill("");
937
+ totalLine[layout.columns.findIndex((c) => c.key === "quantity")] = labels.total;
938
+ const lastData = input.rows.length === 0 ? layout.firstDataRow - 1 : layout.firstDataRow + input.rows.length - 1;
939
+ totalLine[layout.columns.findIndex((c) => c.key === "sum")] = `=${buildTotalSumFormula({
940
+ layout,
941
+ firstDataRow: layout.firstDataRow,
942
+ lastDataRow: lastData
943
+ })}`;
944
+ values.push(totalLine);
945
+ } else {
946
+ const lastData = layout.firstDataRow + input.rows.length - 1;
947
+ for (let i = 0; i < currencyList.length; i++) {
948
+ const currency = currencyList[i];
949
+ const totalLine = Array(layout.columns.length).fill("");
950
+ totalLine[layout.columns.findIndex((c) => c.key === "quantity")] = i === 0 ? `${labels.total} (${currency})` : currency;
951
+ totalLine[layout.columns.findIndex((c) => c.key === "sum")] = `=${buildCurrencyTotalSumIfFormula({
952
+ layout,
953
+ firstDataRow: layout.firstDataRow,
954
+ lastDataRow: lastData,
955
+ currency
956
+ })}`;
957
+ values.push(totalLine);
958
+ }
959
+ }
960
+ await sheets.spreadsheets.values.update({
961
+ spreadsheetId,
962
+ range: `A1:${lastColLetter}${values.length}`,
963
+ valueInputOption: "USER_ENTERED",
964
+ requestBody: { values }
965
+ });
966
+ const requests = [];
967
+ for (const col of layout.columns) {
968
+ requests.push({
969
+ updateDimensionProperties: {
970
+ range: {
971
+ sheetId,
972
+ dimension: "COLUMNS",
973
+ startIndex: col.index - 1,
974
+ endIndex: col.index
975
+ },
976
+ properties: {
977
+ pixelSize: colWidthPixels(layout, col.key),
978
+ hiddenByUser: col.key === "currencyHidden"
979
+ },
980
+ fields: "pixelSize,hiddenByUser"
981
+ }
982
+ });
983
+ }
984
+ if (input.rows.length > 0) {
985
+ requests.push({
986
+ updateDimensionProperties: {
987
+ range: {
988
+ sheetId,
989
+ dimension: "ROWS",
990
+ startIndex: layout.firstDataRow - 1,
991
+ endIndex: layout.firstDataRow - 1 + input.rows.length
992
+ },
993
+ properties: { pixelSize: 130 },
994
+ fields: "pixelSize"
995
+ }
996
+ });
997
+ }
998
+ requests.push({
999
+ setBasicFilter: {
1000
+ filter: {
1001
+ range: {
1002
+ sheetId,
1003
+ startRowIndex: layout.headerRow - 1,
1004
+ endRowIndex: layout.headerRow + input.rows.length,
1005
+ startColumnIndex: 0,
1006
+ endColumnIndex: layout.columns.find((c) => c.key === "sum").index
1007
+ }
1008
+ }
1009
+ }
1010
+ });
1011
+ if (input.rows.length > 0) {
1012
+ const qtyCol = layout.columns.find((c) => c.key === "quantity").index - 1;
1013
+ requests.push({
1014
+ setDataValidation: {
1015
+ range: {
1016
+ sheetId,
1017
+ startRowIndex: layout.firstDataRow - 1,
1018
+ endRowIndex: layout.firstDataRow - 1 + input.rows.length,
1019
+ startColumnIndex: qtyCol,
1020
+ endColumnIndex: qtyCol + 1
1021
+ },
1022
+ rule: {
1023
+ condition: {
1024
+ type: "NUMBER_GREATER_THAN_EQ",
1025
+ values: [{ userEnteredValue: "0" }]
1026
+ },
1027
+ strict: true,
1028
+ showCustomUi: true
1029
+ }
1030
+ }
1031
+ });
1032
+ }
1033
+ await sheets.spreadsheets.batchUpdate({
1034
+ spreadsheetId,
1035
+ requestBody: { requests }
1036
+ });
1037
+ return { spreadsheetId, spreadsheetUrl };
1038
+ }
1039
+ // Annotate the CommonJS export names for ESM import in node:
1040
+ 0 && (module.exports = {
1041
+ PRICE_LIST_BANNER_ROW_COUNT,
1042
+ PRICE_LIST_DATA_ROW_HEIGHT_PT,
1043
+ PRICE_LIST_DEFAULT_PHOTO_PX,
1044
+ PRICE_LIST_PHOTO_COL_CHARS,
1045
+ buildCurrencyTotalSumIfFormula,
1046
+ buildLineSumFormula,
1047
+ buildPriceListLayout,
1048
+ buildTotalSumFormula,
1049
+ buildWholesalePriceListXlsx,
1050
+ coerceUnitPrice,
1051
+ createPriceListGoogleClients,
1052
+ excelColumnLetter,
1053
+ fetchAbsoluteUrlBytes,
1054
+ formatGeneratedLabel,
1055
+ googleSheetsImageFormula,
1056
+ isAnonymousHttpImageUrl,
1057
+ isMailooApiKeyedImageUrl,
1058
+ mediaIdFromMailooPublicImageUrl,
1059
+ normalizePreviewSquare,
1060
+ priceListFilename,
1061
+ priceListFilenameDate,
1062
+ rasterizeLogo,
1063
+ renderPriceListGoogleSheet,
1064
+ renderPriceListXlsx,
1065
+ resolvePriceListLabels,
1066
+ validatePriceListInput
1067
+ });
1068
+ //# sourceMappingURL=index.cjs.map