@mailoo/market 1.35.12 → 1.35.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -12
- package/dist/chunk-SNYTGUGW.js +484 -0
- package/dist/chunk-SNYTGUGW.js.map +1 -0
- package/dist/types-ClEuQGG0.d.cts +144 -0
- package/dist/types-ClEuQGG0.d.ts +144 -0
- package/dist/wholesale-price-list/google-sheets/index.cjs +819 -0
- package/dist/wholesale-price-list/google-sheets/index.cjs.map +1 -0
- package/dist/wholesale-price-list/google-sheets/index.d.cts +99 -0
- package/dist/wholesale-price-list/google-sheets/index.d.ts +99 -0
- package/dist/wholesale-price-list/google-sheets/index.js +381 -0
- package/dist/wholesale-price-list/google-sheets/index.js.map +1 -0
- package/dist/wholesale-price-list/index.cjs +170 -416
- package/dist/wholesale-price-list/index.cjs.map +1 -1
- package/dist/wholesale-price-list/index.d.cts +41 -230
- package/dist/wholesale-price-list/index.d.ts +41 -230
- package/dist/wholesale-price-list/index.js +116 -787
- package/dist/wholesale-price-list/index.js.map +1 -1
- package/package.json +14 -3
|
@@ -1,136 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Entry: `renderPriceListXlsx(input)` from
|
|
5
|
-
* `@mailoo/market/wholesale-price-list` (Node / Route Handler only).
|
|
6
|
-
*
|
|
7
|
-
* v1: one unit-price column, no quantity tiers, no min-order column.
|
|
8
|
-
* Quantity breaks / MOQ are deferred (AMS-28).
|
|
9
|
-
*/
|
|
10
|
-
/** Built-in label locales. Other `locale` strings still work; labels fall back to en. */
|
|
11
|
-
type PriceListBuiltinLocale = 'hy' | 'ru' | 'en' | 'de' | 'es';
|
|
12
|
-
type PriceListHeader = {
|
|
13
|
-
siteName: string;
|
|
14
|
-
/**
|
|
15
|
-
* Absolute logo URL, or null. SVG is accepted — the generator rasterizes
|
|
16
|
-
* to PNG for xlsx embed (and for Sheets when bytes are available).
|
|
17
|
-
*/
|
|
18
|
-
logoUrl: string | null;
|
|
19
|
-
/** Optional pre-fetched logo bytes (svg / png / jpeg / webp). */
|
|
20
|
-
logoBytes?: Uint8Array | null;
|
|
21
|
-
/**
|
|
22
|
-
* Contact block as a single pre-formatted string (may contain newlines).
|
|
23
|
-
* Pre-Form: from `MARKET_PRICE_LIST_CONTACTS`. Mailoo admin: see package README —
|
|
24
|
-
* MARKET config has no contacts field yet.
|
|
25
|
-
*/
|
|
26
|
-
contacts: string;
|
|
27
|
-
/** ISO-8601 instant. */
|
|
28
|
-
generatedAt: string;
|
|
29
|
-
/**
|
|
30
|
-
* IANA time zone for the “Generated: …” display (e.g. `Asia/Yerevan`).
|
|
31
|
-
* Omitted → format in UTC.
|
|
32
|
-
*/
|
|
33
|
-
timeZone?: string | null;
|
|
34
|
-
};
|
|
35
|
-
type PriceListRow = {
|
|
36
|
-
productId: string;
|
|
37
|
-
/** null = product has no variants (one row for the product). */
|
|
38
|
-
variantId: string | null;
|
|
39
|
-
category: string | null;
|
|
40
|
-
product: string;
|
|
41
|
-
variant: string | null;
|
|
42
|
-
packaging: string | null;
|
|
43
|
-
/**
|
|
44
|
-
* Unit price in the price measurement unit.
|
|
45
|
-
* `null` / negative / NaN / non-finite → cell shows localized “on request”;
|
|
46
|
-
* Sum stays blank (row still renders; does not fail the whole file).
|
|
47
|
-
*
|
|
48
|
-
* AMS-28 (not in v1): row currently has no `measurementUnit` column —
|
|
49
|
-
* packaging / unit labels stay in `packaging` only.
|
|
50
|
-
*/
|
|
51
|
-
unitPrice: number | null;
|
|
52
|
-
/** ISO 4217; null = unknown (still summed in a single Total when alone). */
|
|
53
|
-
currency: string | null;
|
|
54
|
-
/** Absolute storefront PDP (`?variant=` when variantId set). */
|
|
55
|
-
productUrl: string;
|
|
56
|
-
previewMediaId: string | null;
|
|
57
|
-
/**
|
|
58
|
-
* Absolute cover URL. Used for Sheets `=IMAGE` only when anonymously
|
|
59
|
-
* fetchable (not Mailoo `…/images/public/content?id=` which needs an API key).
|
|
60
|
-
* Prefer `previewImageBytes` / `loadPreviewImage` for xlsx embed.
|
|
61
|
-
*/
|
|
62
|
-
previewImageUrl: string | null;
|
|
63
|
-
/** Optional pre-fetched cover bytes for xlsx embed. */
|
|
64
|
-
previewImageBytes?: Uint8Array | null;
|
|
65
|
-
};
|
|
66
|
-
type PriceListInput = {
|
|
67
|
-
/** One language per file; row/header strings are already localized by the caller. */
|
|
68
|
-
locale: string;
|
|
69
|
-
header: PriceListHeader;
|
|
70
|
-
rows: PriceListRow[];
|
|
71
|
-
/** Optional overrides of built-in hy/ru/en/de/es strings. */
|
|
72
|
-
labels?: Partial<Record<PriceListLabelKey, string>>;
|
|
73
|
-
/**
|
|
74
|
-
* Fetch cover bytes when `previewImageBytes` is omitted.
|
|
75
|
-
* Return null to leave the photo blank.
|
|
76
|
-
* When omitted, the package tries an anonymous GET of `previewImageUrl`
|
|
77
|
-
* (skips Mailoo API-keyed embed URLs).
|
|
78
|
-
*/
|
|
79
|
-
loadPreviewImage?: (args: {
|
|
80
|
-
previewMediaId: string | null;
|
|
81
|
-
previewImageUrl: string | null;
|
|
82
|
-
}) => Promise<Uint8Array | null>;
|
|
83
|
-
/**
|
|
84
|
-
* Fetch logo bytes when `logoBytes` omitted but `logoUrl` set.
|
|
85
|
-
* When omitted, the package tries an anonymous GET of `logoUrl`.
|
|
86
|
-
*/
|
|
87
|
-
loadLogo?: (logoUrl: string) => Promise<Uint8Array | null>;
|
|
88
|
-
/** Square thumbnail edge in px (default 120). */
|
|
89
|
-
photoSizePx?: number;
|
|
90
|
-
};
|
|
91
|
-
type PriceListLabelKey = 'title' | 'photo' | 'category' | 'product' | 'variant' | 'packaging' | 'price' | 'onRequest' | 'link' | 'linkText' | 'quantity' | 'sum' | 'total' | 'generated' | 'filenamePrefix';
|
|
92
|
-
type PriceListColumnKey = 'photo' | 'category' | 'product' | 'variant' | 'packaging' | 'price' | 'link' | 'quantity' | 'sum' | 'currencyHidden';
|
|
93
|
-
type PriceListLayout = {
|
|
94
|
-
locale: string;
|
|
95
|
-
photoSizePx: number;
|
|
96
|
-
/** Fixed data-row height in Excel points (~96 pt ≈ 130 px). */
|
|
97
|
-
dataRowHeightPt: number;
|
|
98
|
-
photoColWidthChars: number;
|
|
99
|
-
/** 1-based Excel row of visible column headers. */
|
|
100
|
-
headerRow: number;
|
|
101
|
-
firstDataRow: number;
|
|
102
|
-
totalRow: number;
|
|
103
|
-
columns: Array<{
|
|
104
|
-
key: PriceListColumnKey;
|
|
105
|
-
header: string;
|
|
106
|
-
index: number;
|
|
107
|
-
letter: string;
|
|
108
|
-
}>;
|
|
109
|
-
priceColLetter: string;
|
|
110
|
-
quantityColLetter: string;
|
|
111
|
-
sumColLetter: string;
|
|
112
|
-
currencyColLetter: string;
|
|
113
|
-
linkColLetter: string;
|
|
114
|
-
};
|
|
115
|
-
type PriceListSheetModel = {
|
|
116
|
-
title: string;
|
|
117
|
-
locale: string;
|
|
118
|
-
layout: PriceListLayout;
|
|
119
|
-
cells: Array<{
|
|
120
|
-
a1: string;
|
|
121
|
-
value: string | number | null;
|
|
122
|
-
formula?: string;
|
|
123
|
-
}>;
|
|
124
|
-
previewImageUrls: Array<string | null>;
|
|
125
|
-
logoUrl: string | null;
|
|
126
|
-
};
|
|
127
|
-
type RenderPriceListXlsxResult = {
|
|
128
|
-
buffer: Buffer;
|
|
129
|
-
filename: string;
|
|
130
|
-
contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
131
|
-
layout: PriceListLayout;
|
|
132
|
-
sheetModel: PriceListSheetModel;
|
|
133
|
-
};
|
|
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';
|
|
134
3
|
|
|
135
4
|
/** ~120 px square → Excel column width in characters (approx). */
|
|
136
5
|
declare const PRICE_LIST_DEFAULT_PHOTO_PX = 120;
|
|
@@ -140,9 +9,23 @@ declare const PRICE_LIST_PHOTO_COL_CHARS = 18;
|
|
|
140
9
|
/** Rows above the column header: logo/name, contacts, generated. */
|
|
141
10
|
declare const PRICE_LIST_BANNER_ROW_COUNT = 3;
|
|
142
11
|
declare function excelColumnLetter(index1Based: number): string;
|
|
143
|
-
|
|
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;
|
|
144
19
|
declare function buildPriceListLayout(input: PriceListInput): PriceListLayout;
|
|
145
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
|
+
|
|
146
29
|
declare function resolvePriceListLabels(locale: string, overrides?: Partial<Record<PriceListLabelKey, string>>): Record<PriceListLabelKey, string>;
|
|
147
30
|
declare function formatGeneratedLabel(template: string, generatedAt: string, locale: string, timeZone?: string | null): string;
|
|
148
31
|
/**
|
|
@@ -209,16 +92,38 @@ declare function buildCurrencyTotalSumIfFormula(args: {
|
|
|
209
92
|
* Fit image into a square canvas with white padding (contain), PNG output.
|
|
210
93
|
* Used for xlsx embedded thumbnails so every photo cell is the same size.
|
|
211
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).
|
|
212
97
|
*/
|
|
213
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
|
+
}>;
|
|
214
107
|
/**
|
|
215
108
|
* Rasterize logo (SVG / PNG / JPEG / WebP) to a PNG suitable for the header
|
|
216
|
-
* box (~120×40).
|
|
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).
|
|
217
111
|
*/
|
|
218
112
|
declare function rasterizeLogo(input: Uint8Array, opts?: {
|
|
219
113
|
widthPx?: number;
|
|
220
114
|
heightPx?: number;
|
|
221
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
|
+
}>;
|
|
222
127
|
/** Google Sheets IMAGE formula, mode 4 = custom size (fixed cell look). */
|
|
223
128
|
declare function googleSheetsImageFormula(url: string, sizePx: number): string;
|
|
224
129
|
|
|
@@ -230,98 +135,4 @@ declare function renderPriceListXlsx(input: PriceListInput): Promise<RenderPrice
|
|
|
230
135
|
/** @deprecated Use `renderPriceListXlsx`. */
|
|
231
136
|
declare const buildWholesalePriceListXlsx: typeof renderPriceListXlsx;
|
|
232
137
|
|
|
233
|
-
|
|
234
|
-
type PriceListGoogleSheetsClient = {
|
|
235
|
-
spreadsheets: {
|
|
236
|
-
create: (args: {
|
|
237
|
-
requestBody: unknown;
|
|
238
|
-
fields?: string;
|
|
239
|
-
}) => Promise<{
|
|
240
|
-
data: {
|
|
241
|
-
spreadsheetId?: string | null;
|
|
242
|
-
spreadsheetUrl?: string | null;
|
|
243
|
-
};
|
|
244
|
-
}>;
|
|
245
|
-
get: (args: {
|
|
246
|
-
spreadsheetId: string;
|
|
247
|
-
fields?: string;
|
|
248
|
-
}) => Promise<{
|
|
249
|
-
data: {
|
|
250
|
-
sheets?: Array<{
|
|
251
|
-
properties?: {
|
|
252
|
-
sheetId?: number | null;
|
|
253
|
-
} | null;
|
|
254
|
-
}> | null;
|
|
255
|
-
};
|
|
256
|
-
}>;
|
|
257
|
-
values: {
|
|
258
|
-
update: (args: {
|
|
259
|
-
spreadsheetId: string;
|
|
260
|
-
range: string;
|
|
261
|
-
valueInputOption?: string;
|
|
262
|
-
requestBody: {
|
|
263
|
-
values: string[][];
|
|
264
|
-
};
|
|
265
|
-
}) => Promise<unknown>;
|
|
266
|
-
};
|
|
267
|
-
batchUpdate: (args: {
|
|
268
|
-
spreadsheetId: string;
|
|
269
|
-
requestBody: {
|
|
270
|
-
requests: unknown[];
|
|
271
|
-
};
|
|
272
|
-
}) => Promise<unknown>;
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
/** Structural Drive client surface used by this module (no googleapis types). */
|
|
276
|
-
type PriceListGoogleDriveClient = {
|
|
277
|
-
files: {
|
|
278
|
-
create: (args: unknown) => Promise<{
|
|
279
|
-
data: {
|
|
280
|
-
id?: string | null;
|
|
281
|
-
};
|
|
282
|
-
}>;
|
|
283
|
-
get: (args: {
|
|
284
|
-
fileId: string;
|
|
285
|
-
fields?: string;
|
|
286
|
-
supportsAllDrives?: boolean;
|
|
287
|
-
}) => Promise<{
|
|
288
|
-
data: {
|
|
289
|
-
parents?: string[] | null;
|
|
290
|
-
};
|
|
291
|
-
}>;
|
|
292
|
-
update: (args: unknown) => Promise<unknown>;
|
|
293
|
-
};
|
|
294
|
-
permissions: {
|
|
295
|
-
create: (args: unknown) => Promise<unknown>;
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
type PriceListGoogleClients = {
|
|
299
|
-
sheets: PriceListGoogleSheetsClient;
|
|
300
|
-
drive: PriceListGoogleDriveClient;
|
|
301
|
-
};
|
|
302
|
-
type PriceListGoogleSheetsOptions = {
|
|
303
|
-
/** Raw service-account JSON string (or already-parsed object). */
|
|
304
|
-
serviceAccountJson: string | Record<string, unknown>;
|
|
305
|
-
/** Optional Drive folder id; SA must have write access to the folder. */
|
|
306
|
-
driveFolderId?: string | null;
|
|
307
|
-
/** Optional email to share the new spreadsheet with (writer). */
|
|
308
|
-
shareWithEmail?: string | null;
|
|
309
|
-
/** Injected Google clients (tests). When omitted, built from serviceAccountJson. */
|
|
310
|
-
clients?: PriceListGoogleClients;
|
|
311
|
-
};
|
|
312
|
-
type RenderPriceListGoogleSheetResult = {
|
|
313
|
-
spreadsheetId: string;
|
|
314
|
-
spreadsheetUrl: string;
|
|
315
|
-
};
|
|
316
|
-
declare function createPriceListGoogleClients(serviceAccountJson: string | Record<string, unknown>): Promise<PriceListGoogleClients>;
|
|
317
|
-
/**
|
|
318
|
-
* Create a Google Spreadsheet with the same structure as the xlsx export.
|
|
319
|
-
* Photos/logo for =IMAGE:
|
|
320
|
-
* 1) When bytes are available → upload PNG to Drive (`uc?export=view&id=…`)
|
|
321
|
-
* with anyone-reader (Sheets can fetch without an API key).
|
|
322
|
-
* 2) Else only anonymously fetchable http(s) URLs (never Mailoo
|
|
323
|
-
* `…/images/public/content?id=` which requires X-API-Key).
|
|
324
|
-
*/
|
|
325
|
-
declare function renderPriceListGoogleSheet(input: PriceListInput, options: PriceListGoogleSheetsOptions): Promise<RenderPriceListGoogleSheetResult>;
|
|
326
|
-
|
|
327
|
-
export { PRICE_LIST_BANNER_ROW_COUNT, PRICE_LIST_DATA_ROW_HEIGHT_PT, PRICE_LIST_DEFAULT_PHOTO_PX, PRICE_LIST_PHOTO_COL_CHARS, type PriceListBuiltinLocale, type PriceListColumnKey, type PriceListGoogleClients, type PriceListGoogleDriveClient, type PriceListGoogleSheetsClient, type PriceListGoogleSheetsOptions, type PriceListHeader, type PriceListInput, type PriceListLabelKey, type PriceListLayout, type PriceListRow, type PriceListSheetModel, type RenderPriceListGoogleSheetResult, type RenderPriceListXlsxResult, buildCurrencyTotalSumIfFormula, buildLineSumFormula, buildPriceListLayout, buildTotalSumFormula, buildWholesalePriceListXlsx, coerceUnitPrice, createPriceListGoogleClients, excelColumnLetter, fetchAbsoluteUrlBytes, formatGeneratedLabel, googleSheetsImageFormula, isAnonymousHttpImageUrl, isMailooApiKeyedImageUrl, mediaIdFromMailooPublicImageUrl, normalizePreviewSquare, priceListFilename, priceListFilenameDate, rasterizeLogo, renderPriceListGoogleSheet, renderPriceListXlsx, resolvePriceListLabels, validatePriceListInput };
|
|
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 };
|