@ecomweb/storefront-kit 0.13.1 → 0.14.1
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 +26 -0
- package/dist/api/response.js.map +1 -1
- package/dist/auth/context.js.map +1 -1
- package/dist/auth/sdk.js +6 -2
- package/dist/auth/sdk.js.map +1 -1
- package/dist/cart/server-context.js.map +1 -1
- package/dist/checkout/use-checkout.js.map +1 -1
- package/dist/client-info.js +7 -0
- package/dist/client-info.js.map +1 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/server.js.map +1 -1
- package/dist/config/version-check.js +94 -0
- package/dist/config/version-check.js.map +1 -0
- package/dist/config.d.ts +73 -4
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -1
- package/dist/currency.js.map +1 -1
- package/dist/index.d.ts +306 -1
- package/dist/index.js.map +1 -1
- package/dist/logging.js.map +1 -1
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js.map +1 -1
- package/dist/{mode-Lm9t4qzX.d.ts → mode-DXo-EhTJ.d.ts} +1 -1
- package/dist/orders/shipment-tracking.js.map +1 -1
- package/dist/provider.js.map +1 -1
- package/dist/{schema-Dg0ZflMW.d.ts → schema-DIF0CZNV.d.ts} +4 -0
- package/dist/sdk.js +5 -2
- package/dist/sdk.js.map +1 -1
- package/dist/server.d.ts +9 -1
- package/dist/server.js.map +1 -1
- package/dist/shipping/location-areas.js.map +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/store/store-context.js.map +1 -1
- package/dist/store-scope/index.js.map +1 -1
- package/dist/stores/basic-settings.js.map +1 -1
- package/dist/stores/cached.js.map +1 -1
- package/dist/theme/define.js.map +1 -1
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/settings-context.js.map +1 -1
- package/dist/theme/style.js.map +1 -1
- package/dist/theme.d.ts +33 -0
- package/package.json +5 -3
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E as EnvSource, P as PublicConfig } from './schema-
|
|
2
|
-
export { C as ConfigError, L as LogLevel, S as ServerConfig } from './schema-
|
|
3
|
-
export { S as StorefrontMode, r as resolveMode } from './mode-
|
|
1
|
+
import { E as EnvSource, P as PublicConfig } from './schema-DIF0CZNV.js';
|
|
2
|
+
export { C as ConfigError, L as LogLevel, S as ServerConfig } from './schema-DIF0CZNV.js';
|
|
3
|
+
export { S as StorefrontMode, r as resolveMode } from './mode-DXo-EhTJ.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/** Parses the variables of the mode `env` selects (see resolveMode). */
|
|
@@ -13,4 +13,73 @@ declare function resetPublicConfigForTests(): void;
|
|
|
13
13
|
*/
|
|
14
14
|
declare function publicConfig(): PublicConfig;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* This package's version, baked in at build time. `dev` when the source runs
|
|
18
|
+
* without the define (the API ignores a version that isn't semver).
|
|
19
|
+
*/
|
|
20
|
+
declare const KIT_VERSION: string;
|
|
21
|
+
/** The kit's token in `X-Ecomweb-Client`, put before the SDK's own. */
|
|
22
|
+
declare const KIT_CLIENT_TOKEN: string;
|
|
23
|
+
|
|
24
|
+
interface Advisory {
|
|
25
|
+
id?: string;
|
|
26
|
+
package?: string;
|
|
27
|
+
fixed_in?: string;
|
|
28
|
+
severity?: string;
|
|
29
|
+
summary?: string;
|
|
30
|
+
url?: string;
|
|
31
|
+
}
|
|
32
|
+
type ClientVersionStatus = "up_to_date" | "update_available" | "unsupported" | "security_update";
|
|
33
|
+
interface ClientVersionReport {
|
|
34
|
+
status: ClientVersionStatus;
|
|
35
|
+
/** The package judged: the kit, or the SDK when the kit is current. */
|
|
36
|
+
package: string;
|
|
37
|
+
installed: string;
|
|
38
|
+
latest?: string;
|
|
39
|
+
advisories: Advisory[];
|
|
40
|
+
upgradeGuideUrl?: string;
|
|
41
|
+
}
|
|
42
|
+
interface CheckClientVersionsOptions {
|
|
43
|
+
/** Next's config `phase`; the check runs only for `next build`. */
|
|
44
|
+
phase?: string;
|
|
45
|
+
/** The API base, `/api/v1` included. Defaults to production. */
|
|
46
|
+
apiUrl?: string;
|
|
47
|
+
env?: EnvSource;
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
fetch?: typeof fetch;
|
|
50
|
+
/** Where the warning goes; `console.warn` by default. */
|
|
51
|
+
warn?: (message: string) => void;
|
|
52
|
+
/** Overrides the baked-in versions (tests). */
|
|
53
|
+
installed?: {
|
|
54
|
+
kit?: string;
|
|
55
|
+
sdk?: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Turns a version report into the multi-line warning that
|
|
60
|
+
* {@link checkClientVersions} prints: the headline, one line per advisory and
|
|
61
|
+
* how to update.
|
|
62
|
+
*
|
|
63
|
+
* @param report - The report to describe.
|
|
64
|
+
* @returns The warning text, ready for `console.warn`.
|
|
65
|
+
*/
|
|
66
|
+
declare function formatClientVersionWarning(report: ClientVersionReport): string;
|
|
67
|
+
/**
|
|
68
|
+
* Checks the installed kit and SDK against the platform's supported versions
|
|
69
|
+
* and prints a warning when they are behind. For `next.config.mjs`:
|
|
70
|
+
*
|
|
71
|
+
* ```js
|
|
72
|
+
* export default async function config(phase) {
|
|
73
|
+
* await checkClientVersions({ phase, apiUrl: API_URL });
|
|
74
|
+
* return nextConfig;
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* Runs during `next build` only, once per build, and never fails or slows it
|
|
79
|
+
* beyond the timeout (2 s): any error is ignored. Off with
|
|
80
|
+
* `ECOMWEB_SKIP_VERSION_CHECK=1`. Returns the report, or null when it did not
|
|
81
|
+
* check.
|
|
82
|
+
*/
|
|
83
|
+
declare function checkClientVersions(options?: CheckClientVersionsOptions): Promise<ClientVersionReport | null>;
|
|
84
|
+
|
|
85
|
+
export { type CheckClientVersionsOptions, type ClientVersionReport, type ClientVersionStatus, EnvSource, KIT_CLIENT_TOKEN, KIT_VERSION, PublicConfig, checkClientVersions, formatClientVersionWarning, parsePublicConfig, publicConfig, resetPublicConfigForTests };
|
package/dist/config.js
CHANGED
|
@@ -5,8 +5,17 @@ import {
|
|
|
5
5
|
} from "./config/public.js";
|
|
6
6
|
import { resolveMode } from "./config/mode.js";
|
|
7
7
|
import { ConfigError } from "./config/schema.js";
|
|
8
|
+
import { KIT_CLIENT_TOKEN, KIT_VERSION } from "./client-info.js";
|
|
9
|
+
import {
|
|
10
|
+
checkClientVersions,
|
|
11
|
+
formatClientVersionWarning
|
|
12
|
+
} from "./config/version-check.js";
|
|
8
13
|
export {
|
|
9
14
|
ConfigError,
|
|
15
|
+
KIT_CLIENT_TOKEN,
|
|
16
|
+
KIT_VERSION,
|
|
17
|
+
checkClientVersions,
|
|
18
|
+
formatClientVersionWarning,
|
|
10
19
|
parsePublicConfig,
|
|
11
20
|
publicConfig,
|
|
12
21
|
resetPublicConfigForTests,
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["/**\n * Parsing and types for the storefront's configuration: public (client-safe)\n * settings, the deployment mode, the build-time version check and\n * `ConfigError`.\n *\n * Import from `@ecomweb/storefront-kit/config` in `next.config` and config\n * code. It has no React or server-only dependency.\n *\n * @packageDocumentation\n */\nexport {\n parsePublicConfig,\n publicConfig,\n // For specs that stub env per test (the config is memoized on first read).\n resetPublicConfigForTests,\n} from \"./config/public\";\nexport { resolveMode } from \"./config/mode\";\nexport type { StorefrontMode } from \"./config/mode\";\nexport { ConfigError } from \"./config/schema\";\nexport type {\n EnvSource,\n LogLevel,\n PublicConfig,\n ServerConfig,\n} from \"./config/schema\";\nexport { KIT_CLIENT_TOKEN, KIT_VERSION } from \"./client-info\";\nexport {\n checkClientVersions,\n formatClientVersionWarning,\n} from \"./config/version-check\";\nexport type {\n CheckClientVersionsOptions,\n ClientVersionReport,\n ClientVersionStatus,\n} from \"./config/version-check\";\n"],"mappings":"AAUA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,mBAAmB;AAE5B,SAAS,mBAAmB;AAO5B,SAAS,kBAAkB,mBAAmB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
|
package/dist/currency.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/currency.ts"],"sourcesContent":["import currencyJs from \"currency.js\";\n\nexport type SupportedCurrency = \"VND\" | \"USD\" | \"EUR\" | \"SGD\";\n\nexport function getDefaultLocale(currency: SupportedCurrency): string {\n switch (currency) {\n case \"USD\":\n case \"EUR\":\n case \"SGD\":\n return \"en-US\";\n case \"VND\":\n return \"vi-VN\";\n default:\n return \"vi-VN\";\n }\n}\n\n/**\n * House formatting convention, one table for every currency we price in.\n *\n * A locale bundles four decisions — group separator, decimal separator,\n * symbol, and symbol placement — behind one string, and we want them from\n * different places. `vi-VN` renders 10.234.000 ₫ with a space and the dong\n * sign; the house style is 10.234.000đ, tight and with the Latin d-stroke.\n * So the table is explicit.\n *\n * Numerals are uniform across currencies: dot groups, comma decimals. Only\n * the symbol, its placement, and the precision vary.\n *\n * VND 10.234.000đ USD $1.234,50\n * EUR €1.234,50 SGD S$1.234,50\n *\n * Keep this in sync with the same table in ecomweb-dashboard/lib/currency.ts\n * and the API's src/common/utils/currency.utils.ts. The pinned tests in each\n * repo exist to catch drift between the three.\n */\nconst CURRENCY_FORMATS = {\n VND: { symbol: \"đ\", precision: 0, suffix: true },\n USD: { symbol: \"$\", precision: 2, suffix: false },\n EUR: { symbol: \"€\", precision: 2, suffix: false },\n SGD: { symbol: \"S$\", precision: 2, suffix: false },\n} as const;\n\n/** Narrows an arbitrary stored code to a currency we can price in. */\nexport function isSupportedCurrency(\n code: unknown\n): code is SupportedCurrency {\n return (\n typeof code === \"string\" &&\n Object.prototype.hasOwnProperty.call(CURRENCY_FORMATS, code)\n );\n}\n\nfunction getCurrencyOptions(_locale: string, code: SupportedCurrency | string) {\n const format =\n CURRENCY_FORMATS[code as SupportedCurrency] ?? CURRENCY_FORMATS.VND;\n\n return {\n symbol: format.symbol,\n precision: format.precision,\n // Uniform numerals: 1.234.567,89 regardless of currency.\n separator: \".\",\n decimal: \",\",\n // The sign stays outermost: -10.234.000đ and -$19,99.\n pattern: format.suffix ? \"#!\" : \"!#\",\n negativePattern: format.suffix ? \"-#!\" : \"-!#\",\n } as const;\n}\n\n/**\n * Format an amount as money in the given currency.\n *\n * `locale` is retained for call-site compatibility but no longer affects the\n * output — the house convention in CURRENCY_FORMATS is uniform across\n * locales. It still matters to formatNumber, which is not currency.\n */\nexport function formatPrice(\n amount: number,\n locale: string = \"vi-VN\",\n code: SupportedCurrency | string = \"VND\"\n): string {\n const opts = getCurrencyOptions(locale, code);\n return currencyJs(amount, opts).format();\n}\n\nexport function formatNumber(amount: number, locale = \"vi-VN\"): string {\n // General number formatting (non-currency)\n return new Intl.NumberFormat(locale).format(amount);\n}\n\nexport function formatPriceRange(\n min?: number,\n max?: number,\n locale: string = \"vi-VN\",\n code: SupportedCurrency = \"VND\"\n): string {\n if (min == null && max == null) return \"\";\n if (max == null || min === max) return formatPrice(min || 0, locale, code);\n return `${formatPrice(min || 0, locale, code)} - ${formatPrice(max, locale, code)}`;\n}\n\n
|
|
1
|
+
{"version":3,"sources":["../src/currency.ts"],"sourcesContent":["import currencyJs from \"currency.js\";\n\nexport type SupportedCurrency = \"VND\" | \"USD\" | \"EUR\" | \"SGD\";\n\n/**\n * Picks the locale used to format prices in a currency: `en-US` for USD, EUR\n * and SGD, `vi-VN` for VND.\n *\n * @param currency - The store's currency code.\n * @returns A BCP 47 locale tag.\n */\nexport function getDefaultLocale(currency: SupportedCurrency): string {\n switch (currency) {\n case \"USD\":\n case \"EUR\":\n case \"SGD\":\n return \"en-US\";\n case \"VND\":\n return \"vi-VN\";\n default:\n return \"vi-VN\";\n }\n}\n\n/**\n * House formatting convention, one table for every currency we price in.\n *\n * A locale bundles four decisions — group separator, decimal separator,\n * symbol, and symbol placement — behind one string, and we want them from\n * different places. `vi-VN` renders 10.234.000 ₫ with a space and the dong\n * sign; the house style is 10.234.000đ, tight and with the Latin d-stroke.\n * So the table is explicit.\n *\n * Numerals are uniform across currencies: dot groups, comma decimals. Only\n * the symbol, its placement, and the precision vary.\n *\n * VND 10.234.000đ USD $1.234,50\n * EUR €1.234,50 SGD S$1.234,50\n *\n * Keep this in sync with the same table in ecomweb-dashboard/lib/currency.ts\n * and the API's src/common/utils/currency.utils.ts. The pinned tests in each\n * repo exist to catch drift between the three.\n */\nconst CURRENCY_FORMATS = {\n VND: { symbol: \"đ\", precision: 0, suffix: true },\n USD: { symbol: \"$\", precision: 2, suffix: false },\n EUR: { symbol: \"€\", precision: 2, suffix: false },\n SGD: { symbol: \"S$\", precision: 2, suffix: false },\n} as const;\n\n/** Narrows an arbitrary stored code to a currency we can price in. */\nexport function isSupportedCurrency(\n code: unknown\n): code is SupportedCurrency {\n return (\n typeof code === \"string\" &&\n Object.prototype.hasOwnProperty.call(CURRENCY_FORMATS, code)\n );\n}\n\nfunction getCurrencyOptions(_locale: string, code: SupportedCurrency | string) {\n const format =\n CURRENCY_FORMATS[code as SupportedCurrency] ?? CURRENCY_FORMATS.VND;\n\n return {\n symbol: format.symbol,\n precision: format.precision,\n // Uniform numerals: 1.234.567,89 regardless of currency.\n separator: \".\",\n decimal: \",\",\n // The sign stays outermost: -10.234.000đ and -$19,99.\n pattern: format.suffix ? \"#!\" : \"!#\",\n negativePattern: format.suffix ? \"-#!\" : \"-!#\",\n } as const;\n}\n\n/**\n * Format an amount as money in the given currency.\n *\n * `locale` is retained for call-site compatibility but no longer affects the\n * output — the house convention in CURRENCY_FORMATS is uniform across\n * locales. It still matters to formatNumber, which is not currency.\n */\nexport function formatPrice(\n amount: number,\n locale: string = \"vi-VN\",\n code: SupportedCurrency | string = \"VND\"\n): string {\n const opts = getCurrencyOptions(locale, code);\n return currencyJs(amount, opts).format();\n}\n\n/**\n * Formats a plain number with the locale's digit grouping, without a currency\n * symbol.\n *\n * @param amount - The number to format.\n * @param locale - BCP 47 locale tag; defaults to `vi-VN`.\n * @returns The formatted number.\n */\nexport function formatNumber(amount: number, locale = \"vi-VN\"): string {\n // General number formatting (non-currency)\n return new Intl.NumberFormat(locale).format(amount);\n}\n\n/**\n * Formats a price range such as a product's lowest and highest variant price.\n *\n * @param min - The lowest price.\n * @param max - The highest price.\n * @param locale - BCP 47 locale tag; defaults to `vi-VN`.\n * @param code - Currency code; defaults to `VND`.\n * @returns One formatted price when the two match or `max` is missing, `min - max` otherwise, and an empty string when both are missing.\n */\nexport function formatPriceRange(\n min?: number,\n max?: number,\n locale: string = \"vi-VN\",\n code: SupportedCurrency = \"VND\"\n): string {\n if (min == null && max == null) return \"\";\n if (max == null || min === max) return formatPrice(min || 0, locale, code);\n return `${formatPrice(min || 0, locale, code)} - ${formatPrice(max, locale, code)}`;\n}\n\n/**\n * Wraps a value in a currency.js object for safe money arithmetic (add,\n * subtract, multiply, format) without floating-point drift.\n *\n * @param value - The amount, as a number or numeric string.\n * @param locale - BCP 47 locale tag; defaults to `vi-VN`.\n * @param code - Currency code; defaults to `VND`.\n * @returns A currency.js value configured for that locale and currency.\n */\nexport const money = (\n value: number | string,\n locale: string = \"vi-VN\",\n code: SupportedCurrency = \"VND\"\n) => currencyJs(value as any, getCurrencyOptions(locale, code));\n\n// Format for inputs (no symbol), keeps separators consistent with currency options\n/**\n * Formats an amount with the currency's separators but no symbol, for price\n * inputs.\n *\n * @param amount - The amount to format.\n * @param locale - BCP 47 locale tag; defaults to `vi-VN`.\n * @param code - Currency code; defaults to `VND`.\n * @returns The formatted amount.\n */\nexport function formatPriceWithoutSymbol(\n amount: number,\n locale: string = \"vi-VN\",\n code: SupportedCurrency = \"VND\"\n): string {\n const base = getCurrencyOptions(locale, code);\n const opts = {\n ...base,\n symbol: \"\",\n pattern: \"#\",\n negativePattern: \"-#\",\n } as const;\n return currencyJs(amount, opts).format();\n}\n"],"mappings":"AAAA,OAAO,gBAAgB;AAWhB,SAAS,iBAAiB,UAAqC;AACpE,UAAQ,UAAU;AAAA,IAChB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAqBA,MAAM,mBAAmB;AAAA,EACvB,KAAK,EAAE,QAAQ,UAAK,WAAW,GAAG,QAAQ,KAAK;AAAA,EAC/C,KAAK,EAAE,QAAQ,KAAK,WAAW,GAAG,QAAQ,MAAM;AAAA,EAChD,KAAK,EAAE,QAAQ,UAAK,WAAW,GAAG,QAAQ,MAAM;AAAA,EAChD,KAAK,EAAE,QAAQ,MAAM,WAAW,GAAG,QAAQ,MAAM;AACnD;AAGO,SAAS,oBACd,MAC2B;AAC3B,SACE,OAAO,SAAS,YAChB,OAAO,UAAU,eAAe,KAAK,kBAAkB,IAAI;AAE/D;AAEA,SAAS,mBAAmB,SAAiB,MAAkC;AAC7E,QAAM,SACJ,iBAAiB,IAAyB,KAAK,iBAAiB;AAElE,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,WAAW,OAAO;AAAA;AAAA,IAElB,WAAW;AAAA,IACX,SAAS;AAAA;AAAA,IAET,SAAS,OAAO,SAAS,OAAO;AAAA,IAChC,iBAAiB,OAAO,SAAS,QAAQ;AAAA,EAC3C;AACF;AASO,SAAS,YACd,QACA,SAAiB,SACjB,OAAmC,OAC3B;AACR,QAAM,OAAO,mBAAmB,QAAQ,IAAI;AAC5C,SAAO,WAAW,QAAQ,IAAI,EAAE,OAAO;AACzC;AAUO,SAAS,aAAa,QAAgB,SAAS,SAAiB;AAErE,SAAO,IAAI,KAAK,aAAa,MAAM,EAAE,OAAO,MAAM;AACpD;AAWO,SAAS,iBACd,KACA,KACA,SAAiB,SACjB,OAA0B,OAClB;AACR,MAAI,OAAO,QAAQ,OAAO,KAAM,QAAO;AACvC,MAAI,OAAO,QAAQ,QAAQ,IAAK,QAAO,YAAY,OAAO,GAAG,QAAQ,IAAI;AACzE,SAAO,GAAG,YAAY,OAAO,GAAG,QAAQ,IAAI,CAAC,MAAM,YAAY,KAAK,QAAQ,IAAI,CAAC;AACnF;AAWO,MAAM,QAAQ,CACnB,OACA,SAAiB,SACjB,OAA0B,UACvB,WAAW,OAAc,mBAAmB,QAAQ,IAAI,CAAC;AAYvD,SAAS,yBACd,QACA,SAAiB,SACjB,OAA0B,OAClB;AACR,QAAM,OAAO,mBAAmB,QAAQ,IAAI;AAC5C,QAAM,OAAO;AAAA,IACX,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,iBAAiB;AAAA,EACnB;AACA,SAAO,WAAW,QAAQ,IAAI,EAAE,OAAO;AACzC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ type NoticeHandler = (notice: Notice) => void;
|
|
|
26
26
|
/** Report a notice to the app; a no-op outside a NoticeProvider. */
|
|
27
27
|
declare function useNotify(): NoticeHandler;
|
|
28
28
|
|
|
29
|
+
/** Props of {@link StorefrontKitProvider}. */
|
|
29
30
|
interface StorefrontKitProviderProps {
|
|
30
31
|
store: StoreConfigurationInfo;
|
|
31
32
|
/** The ref the cart is scoped to; defaults to `store.ref`. */
|
|
@@ -217,6 +218,33 @@ interface UseCheckoutOptions {
|
|
|
217
218
|
* Checkout without the UI: payment methods, shipping quotes, promotions,
|
|
218
219
|
* totals, placing the order and the payment-provider hand-off. The app
|
|
219
220
|
* renders the form and decides what to show for each PlaceOrderResult.
|
|
221
|
+
*
|
|
222
|
+
* Must run under {@link StorefrontKitProvider}, which supplies the store, auth
|
|
223
|
+
* and cart it reads.
|
|
224
|
+
*
|
|
225
|
+
* @param options - The address codes shipping is quoted for, and optional
|
|
226
|
+
* carrier quotes and gateway navigation ({@link UseCheckoutOptions}).
|
|
227
|
+
* @returns The cart `items`, `paymentMethods`, `shipping`, `promotion` and
|
|
228
|
+
* `totals` state, `stockIssues`, and `placeOrder` with the payment redirect
|
|
229
|
+
* helpers.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* "use client";
|
|
234
|
+
* import { useCheckout } from "@ecomweb/storefront-kit";
|
|
235
|
+
*
|
|
236
|
+
* export function PlaceOrderButton({ province, ward, form }) {
|
|
237
|
+
* const checkout = useCheckout({ province, ward });
|
|
238
|
+
* return (
|
|
239
|
+
* <button
|
|
240
|
+
* disabled={checkout.isSubmitting}
|
|
241
|
+
* onClick={() => checkout.placeOrder(form)}
|
|
242
|
+
* >
|
|
243
|
+
* Pay {checkout.totals.total}
|
|
244
|
+
* </button>
|
|
245
|
+
* );
|
|
246
|
+
* }
|
|
247
|
+
* ```
|
|
220
248
|
*/
|
|
221
249
|
declare function useCheckout({ province, ward, includeCarrierOptions, navigateToGateway, }: UseCheckoutOptions): {
|
|
222
250
|
items: CartItem[];
|
|
@@ -388,6 +416,13 @@ declare function useOrderLookup({ orderCode, email, phone, }: {
|
|
|
388
416
|
};
|
|
389
417
|
|
|
390
418
|
type SupportedCurrency = "VND" | "USD" | "EUR" | "SGD";
|
|
419
|
+
/**
|
|
420
|
+
* Picks the locale used to format prices in a currency: `en-US` for USD, EUR
|
|
421
|
+
* and SGD, `vi-VN` for VND.
|
|
422
|
+
*
|
|
423
|
+
* @param currency - The store's currency code.
|
|
424
|
+
* @returns A BCP 47 locale tag.
|
|
425
|
+
*/
|
|
391
426
|
declare function getDefaultLocale(currency: SupportedCurrency): string;
|
|
392
427
|
/**
|
|
393
428
|
* Format an amount as money in the given currency.
|
|
@@ -397,20 +432,98 @@ declare function getDefaultLocale(currency: SupportedCurrency): string;
|
|
|
397
432
|
* locales. It still matters to formatNumber, which is not currency.
|
|
398
433
|
*/
|
|
399
434
|
declare function formatPrice(amount: number, locale?: string, code?: SupportedCurrency | string): string;
|
|
435
|
+
/**
|
|
436
|
+
* Formats a plain number with the locale's digit grouping, without a currency
|
|
437
|
+
* symbol.
|
|
438
|
+
*
|
|
439
|
+
* @param amount - The number to format.
|
|
440
|
+
* @param locale - BCP 47 locale tag; defaults to `vi-VN`.
|
|
441
|
+
* @returns The formatted number.
|
|
442
|
+
*/
|
|
400
443
|
declare function formatNumber(amount: number, locale?: string): string;
|
|
444
|
+
/**
|
|
445
|
+
* Formats a price range such as a product's lowest and highest variant price.
|
|
446
|
+
*
|
|
447
|
+
* @param min - The lowest price.
|
|
448
|
+
* @param max - The highest price.
|
|
449
|
+
* @param locale - BCP 47 locale tag; defaults to `vi-VN`.
|
|
450
|
+
* @param code - Currency code; defaults to `VND`.
|
|
451
|
+
* @returns One formatted price when the two match or `max` is missing, `min - max` otherwise, and an empty string when both are missing.
|
|
452
|
+
*/
|
|
401
453
|
declare function formatPriceRange(min?: number, max?: number, locale?: string, code?: SupportedCurrency): string;
|
|
454
|
+
/**
|
|
455
|
+
* Wraps a value in a currency.js object for safe money arithmetic (add,
|
|
456
|
+
* subtract, multiply, format) without floating-point drift.
|
|
457
|
+
*
|
|
458
|
+
* @param value - The amount, as a number or numeric string.
|
|
459
|
+
* @param locale - BCP 47 locale tag; defaults to `vi-VN`.
|
|
460
|
+
* @param code - Currency code; defaults to `VND`.
|
|
461
|
+
* @returns A currency.js value configured for that locale and currency.
|
|
462
|
+
*/
|
|
402
463
|
declare const money: (value: number | string, locale?: string, code?: SupportedCurrency) => currencyJs;
|
|
464
|
+
/**
|
|
465
|
+
* Formats an amount with the currency's separators but no symbol, for price
|
|
466
|
+
* inputs.
|
|
467
|
+
*
|
|
468
|
+
* @param amount - The amount to format.
|
|
469
|
+
* @param locale - BCP 47 locale tag; defaults to `vi-VN`.
|
|
470
|
+
* @param code - Currency code; defaults to `VND`.
|
|
471
|
+
* @returns The formatted amount.
|
|
472
|
+
*/
|
|
403
473
|
declare function formatPriceWithoutSymbol(amount: number, locale?: string, code?: SupportedCurrency): string;
|
|
404
474
|
|
|
405
475
|
interface StoreContextData {
|
|
406
476
|
store: StoreConfigurationInfo;
|
|
407
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* The store this page belongs to, as `{ store }`.
|
|
480
|
+
*
|
|
481
|
+
* Must run under {@link StorefrontKitProvider} (or the kit's store provider).
|
|
482
|
+
*
|
|
483
|
+
* @returns The store context.
|
|
484
|
+
* @throws When used outside the provider.
|
|
485
|
+
*/
|
|
408
486
|
declare function useStore(): StoreContextData;
|
|
487
|
+
/**
|
|
488
|
+
* The store's configuration: ref, name, settings and config. Same as
|
|
489
|
+
* `useStore().store`.
|
|
490
|
+
*
|
|
491
|
+
* Must run under {@link StorefrontKitProvider}.
|
|
492
|
+
*
|
|
493
|
+
* @returns The store configuration.
|
|
494
|
+
* @throws When used outside the provider.
|
|
495
|
+
*/
|
|
409
496
|
declare function useStoreData(): StoreConfigurationInfo;
|
|
410
497
|
/** The store ref, or null outside a StoreProvider (e.g. a store-level 404). */
|
|
411
498
|
declare function useOptionalStoreId(): string | null;
|
|
499
|
+
/**
|
|
500
|
+
* The store's ref.
|
|
501
|
+
*
|
|
502
|
+
* Must run under {@link StorefrontKitProvider}.
|
|
503
|
+
*
|
|
504
|
+
* @returns The store ref.
|
|
505
|
+
* @throws When used outside the provider.
|
|
506
|
+
*/
|
|
412
507
|
declare function useStoreId(): string;
|
|
508
|
+
/**
|
|
509
|
+
* The store's currency code, `VND` when the store sets none or one the kit
|
|
510
|
+
* does not support.
|
|
511
|
+
*
|
|
512
|
+
* Must run under {@link StorefrontKitProvider}.
|
|
513
|
+
*
|
|
514
|
+
* @returns The currency code.
|
|
515
|
+
* @throws When used outside the provider.
|
|
516
|
+
*/
|
|
413
517
|
declare function useStoreCurrency(): SupportedCurrency;
|
|
518
|
+
/**
|
|
519
|
+
* The locale to format prices and numbers in for this store, from its
|
|
520
|
+
* currency.
|
|
521
|
+
*
|
|
522
|
+
* Must run under {@link StorefrontKitProvider}.
|
|
523
|
+
*
|
|
524
|
+
* @returns A BCP 47 locale tag.
|
|
525
|
+
* @throws When used outside the provider.
|
|
526
|
+
*/
|
|
414
527
|
declare function useStoreLocale(): string;
|
|
415
528
|
|
|
416
529
|
interface UsePublicAuthConfigResult {
|
|
@@ -486,7 +599,23 @@ declare class ApiClient implements AuthenticatedApiClient {
|
|
|
486
599
|
*/
|
|
487
600
|
declare const publicApiClient: ApiClient;
|
|
488
601
|
|
|
602
|
+
/**
|
|
603
|
+
* Returns the data of a successful API response.
|
|
604
|
+
*
|
|
605
|
+
* @param response - A response from an SDK call.
|
|
606
|
+
* @returns The response data.
|
|
607
|
+
* @throws ApiClientError when the response failed, with the API's message, status code and error code.
|
|
608
|
+
*/
|
|
489
609
|
declare function unwrap<T>(response: ApiResponse<T>): T;
|
|
610
|
+
/**
|
|
611
|
+
* Returns the data of a successful API response, or `null` when the API
|
|
612
|
+
* answered with one of the given status codes.
|
|
613
|
+
*
|
|
614
|
+
* @param response - A response from an SDK call.
|
|
615
|
+
* @param nullStatusCodes - Statuses that mean "nothing there"; defaults to `[404]`.
|
|
616
|
+
* @returns The response data, or `null` when not found.
|
|
617
|
+
* @throws ApiClientError on any other API error.
|
|
618
|
+
*/
|
|
490
619
|
declare function unwrapOrNull<T>(response: ApiResponse<T>, nullStatusCodes?: number[]): T | null;
|
|
491
620
|
|
|
492
621
|
interface AuthError {
|
|
@@ -518,6 +647,17 @@ interface AuthContextType {
|
|
|
518
647
|
signOut: () => Promise<void>;
|
|
519
648
|
refresh: () => Promise<void>;
|
|
520
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* The shopper's sign-in state and actions: `user`, `loading`, `isAnonymous`,
|
|
652
|
+
* `signIn`, `signUp`, `sendLoginCode`, `verifyOtp`, `signInWithGoogle`,
|
|
653
|
+
* `signInAnonymously`, `signOut` and `refresh`. The sign-in actions resolve to
|
|
654
|
+
* `{ error }` and do not throw.
|
|
655
|
+
*
|
|
656
|
+
* Must run under {@link StorefrontKitProvider}, which includes the auth provider.
|
|
657
|
+
*
|
|
658
|
+
* @returns The auth context.
|
|
659
|
+
* @throws When used outside the provider.
|
|
660
|
+
*/
|
|
521
661
|
declare function useAuth(): AuthContextType;
|
|
522
662
|
|
|
523
663
|
/** Maps a backend error code to Vietnamese copy. */
|
|
@@ -614,6 +754,28 @@ interface CartContextType extends CartState {
|
|
|
614
754
|
total: number;
|
|
615
755
|
}>;
|
|
616
756
|
}
|
|
757
|
+
/**
|
|
758
|
+
* The shopper's cart and the actions to change it: `items`, `itemCount`,
|
|
759
|
+
* `subtotal`, `total`, `discountAmount`, `isLoading`, `addItem`, `removeItem`,
|
|
760
|
+
* `updateQuantity`, `clearCart`, `refreshCart`, `mergeCarts` and
|
|
761
|
+
* `reorderItems`. Amounts are in the store's currency.
|
|
762
|
+
*
|
|
763
|
+
* Must run under {@link StorefrontKitProvider}, which includes the cart provider.
|
|
764
|
+
*
|
|
765
|
+
* @returns The cart context.
|
|
766
|
+
* @throws When used outside the provider.
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* ```tsx
|
|
770
|
+
* "use client";
|
|
771
|
+
* import { useCart } from "@ecomweb/storefront-kit";
|
|
772
|
+
*
|
|
773
|
+
* export function CartBadge() {
|
|
774
|
+
* const { itemCount, isLoading } = useCart();
|
|
775
|
+
* return <span>{isLoading ? "…" : itemCount}</span>;
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
617
779
|
declare function useCart(): CartContextType;
|
|
618
780
|
|
|
619
781
|
/**
|
|
@@ -780,8 +942,31 @@ interface ShipmentTrackingView {
|
|
|
780
942
|
statusLabel: string | null;
|
|
781
943
|
events: OrderShipmentSummary["events"];
|
|
782
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* Builds the shipment details to show for an order: carrier, tracking number,
|
|
947
|
+
* tracking link, status and events. Uses the order's `shipment` when the API
|
|
948
|
+
* sends one and falls back to the order's carrier and tracking fields for an
|
|
949
|
+
* older API.
|
|
950
|
+
*
|
|
951
|
+
* @param order - The order to read.
|
|
952
|
+
* @returns The shipment view, or `null` when there is nothing to show.
|
|
953
|
+
*/
|
|
783
954
|
declare function deriveShipmentTracking(order: Order): ShipmentTrackingView | null;
|
|
955
|
+
/**
|
|
956
|
+
* Tells whether the shopper may still cancel the order. Follows the API's
|
|
957
|
+
* `can_cancel` flag when present, else the order status.
|
|
958
|
+
*
|
|
959
|
+
* @param order - The order to check.
|
|
960
|
+
* @returns `true` when the order can be cancelled.
|
|
961
|
+
*/
|
|
784
962
|
declare function canCustomerCancel(order: Order): boolean;
|
|
963
|
+
/**
|
|
964
|
+
* Tells whether the order's shipment has been handed to a carrier and is not
|
|
965
|
+
* cancelled, failed or returned.
|
|
966
|
+
*
|
|
967
|
+
* @param order - The order to check.
|
|
968
|
+
* @returns `true` while the shipment is with a carrier.
|
|
969
|
+
*/
|
|
785
970
|
declare function isHandedToCarrier(order: Order): boolean;
|
|
786
971
|
/**
|
|
787
972
|
* True only for a carrier-booked shipment. The API also sends `order.shipment`
|
|
@@ -931,11 +1116,35 @@ type Fetcher = (storeRef: string, query: {
|
|
|
931
1116
|
level?: number;
|
|
932
1117
|
parent_code?: string;
|
|
933
1118
|
}) => Promise<LocationAreasResponse>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Loads the wards of a province. Results are cached per store and province,
|
|
1121
|
+
* and a failed request is not cached.
|
|
1122
|
+
*
|
|
1123
|
+
* @param storeRef - The store's ref.
|
|
1124
|
+
* @param provinceCode - The province to list wards for.
|
|
1125
|
+
* @param fetcher - Replaces the request that loads the areas (tests).
|
|
1126
|
+
* @returns The wards, or an empty list when `provinceCode` is empty.
|
|
1127
|
+
*/
|
|
934
1128
|
declare function loadWards(storeRef: string, provinceCode: string | undefined, fetcher?: Fetcher): Promise<LocationArea[]>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Loads the store's provinces for an address form. Needs no provider; the
|
|
1131
|
+
* list is cached per store.
|
|
1132
|
+
*
|
|
1133
|
+
* @param storeRef - The store's ref.
|
|
1134
|
+
* @returns `provinces`, the list loaded so far, and `loading`, `true` until the first request ends.
|
|
1135
|
+
*/
|
|
935
1136
|
declare function useProvinces(storeRef: string): {
|
|
936
1137
|
provinces: LocationArea[];
|
|
937
1138
|
loading: boolean;
|
|
938
1139
|
};
|
|
1140
|
+
/**
|
|
1141
|
+
* Loads the wards of the selected province for an address form. The list is
|
|
1142
|
+
* emptied while a new province loads. Needs no provider.
|
|
1143
|
+
*
|
|
1144
|
+
* @param storeRef - The store's ref.
|
|
1145
|
+
* @param provinceCode - The selected province; wards load only once it is set.
|
|
1146
|
+
* @returns `wards`, the list for that province, and `loading`.
|
|
1147
|
+
*/
|
|
939
1148
|
declare function useWards(storeRef: string, provinceCode: string | undefined): {
|
|
940
1149
|
wards: LocationArea[];
|
|
941
1150
|
loading: boolean;
|
|
@@ -1011,7 +1220,21 @@ interface ImageTransformOptions {
|
|
|
1011
1220
|
* - A bare object path is resolved within `defaultBucket`.
|
|
1012
1221
|
*/
|
|
1013
1222
|
declare function resolveTransformedImageUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions, defaultBucket?: "public-cdn"): string | null;
|
|
1223
|
+
/**
|
|
1224
|
+
* Builds the URL of a product image, optionally resized.
|
|
1225
|
+
*
|
|
1226
|
+
* @param imagePathOrUrl - The image's stored path or full URL.
|
|
1227
|
+
* @param opts - Size and format options.
|
|
1228
|
+
* @returns The image URL, or `null` when there is no image.
|
|
1229
|
+
*/
|
|
1014
1230
|
declare function resolveTransformedProductImageUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions): string | null;
|
|
1231
|
+
/**
|
|
1232
|
+
* Builds the URL of a store logo, optionally resized.
|
|
1233
|
+
*
|
|
1234
|
+
* @param imagePathOrUrl - The logo's stored path or full URL.
|
|
1235
|
+
* @param opts - Size and format options.
|
|
1236
|
+
* @returns The logo URL, or `null` when there is no logo.
|
|
1237
|
+
*/
|
|
1015
1238
|
declare function resolveTransformedStoreLogoUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions): string | null;
|
|
1016
1239
|
/**
|
|
1017
1240
|
* Null-safe wrapper for use directly in `src={...}`.
|
|
@@ -1021,10 +1244,34 @@ declare function resolveTransformedStoreLogoUrl(imagePathOrUrl: string | null |
|
|
|
1021
1244
|
*/
|
|
1022
1245
|
declare function resolveAssetSrc(url: string | null | undefined, opts?: ImageTransformOptions): string;
|
|
1023
1246
|
|
|
1247
|
+
/**
|
|
1248
|
+
* Finds the ref of the store a request serves. In single-store mode it is
|
|
1249
|
+
* `ECOMWEB_STORE_REF`; in multi-store mode it comes from the route's
|
|
1250
|
+
* `storeRef` param.
|
|
1251
|
+
*
|
|
1252
|
+
* @param params - The page's `params` promise; only read in multi-store mode.
|
|
1253
|
+
* @returns The store ref.
|
|
1254
|
+
*/
|
|
1024
1255
|
declare function resolveStoreRef(params?: Promise<{
|
|
1025
1256
|
storeRef?: string;
|
|
1026
1257
|
}>): Promise<string>;
|
|
1258
|
+
/**
|
|
1259
|
+
* Builds a page path for a store: `/store/<ref>/…` in multi-store mode, the
|
|
1260
|
+
* path from the site root in single-store mode.
|
|
1261
|
+
*
|
|
1262
|
+
* @param storeRef - The store's ref.
|
|
1263
|
+
* @param path - Path under the store, such as `/cart`; defaults to its home.
|
|
1264
|
+
* @returns The path to link to.
|
|
1265
|
+
*/
|
|
1027
1266
|
declare function storePath(storeRef: string, path?: string): string;
|
|
1267
|
+
/**
|
|
1268
|
+
* Builds the path of the storefront's own API routes for a store:
|
|
1269
|
+
* `/store/<ref>/api/…` in multi-store mode, `/api/…` in single-store mode.
|
|
1270
|
+
*
|
|
1271
|
+
* @param storeRef - The store's ref.
|
|
1272
|
+
* @param subpath - Route under the API prefix, such as `auth/session`.
|
|
1273
|
+
* @returns The path to request.
|
|
1274
|
+
*/
|
|
1028
1275
|
declare function storeApiPath(storeRef: string, subpath: string): string;
|
|
1029
1276
|
|
|
1030
1277
|
/**
|
|
@@ -1071,8 +1318,23 @@ interface BasicSettings {
|
|
|
1071
1318
|
policyLink: string | null;
|
|
1072
1319
|
};
|
|
1073
1320
|
}
|
|
1074
|
-
/**
|
|
1321
|
+
/**
|
|
1322
|
+
* Reads the store's terms and privacy links from its settings.
|
|
1323
|
+
*
|
|
1324
|
+
* @param store - A store with a `settings` object.
|
|
1325
|
+
* @returns The links, `null` where the store sets none.
|
|
1326
|
+
* @deprecated Read `store.settings.legal_links` directly.
|
|
1327
|
+
*/
|
|
1075
1328
|
declare function readBasicSettings(store: StoreLike): BasicSettings;
|
|
1329
|
+
/**
|
|
1330
|
+
* Turns a legal link into the URL to put in an anchor. A full URL is kept; a
|
|
1331
|
+
* path is made store-relative.
|
|
1332
|
+
*
|
|
1333
|
+
* @param link - The store's own link, or `null`.
|
|
1334
|
+
* @param fallbackPath - Path to use when the store sets no link.
|
|
1335
|
+
* @param toStoreUrl - Builds a store URL from a path, for example with {@link storePath}.
|
|
1336
|
+
* @returns The URL, or `#` when there is neither link nor fallback.
|
|
1337
|
+
*/
|
|
1076
1338
|
declare function resolveLegalHref(link: string | null, fallbackPath: string | null, toStoreUrl: (path: string) => string): string;
|
|
1077
1339
|
|
|
1078
1340
|
interface ThemeSettingsContextValue {
|
|
@@ -1087,6 +1349,14 @@ declare function ThemeSettingsProvider({ themeId, themeKey, settings, children,
|
|
|
1087
1349
|
}): react_jsx_runtime.JSX.Element;
|
|
1088
1350
|
/** Pass the theme's settings type: `useThemeSettings<MyThemeSettings>()`. */
|
|
1089
1351
|
declare function useThemeSettings<T = ThemeValues>(): T;
|
|
1352
|
+
/**
|
|
1353
|
+
* The id of the theme rendering the store.
|
|
1354
|
+
*
|
|
1355
|
+
* Must run under the theme settings provider the storefront's layout sets up.
|
|
1356
|
+
*
|
|
1357
|
+
* @returns The theme id.
|
|
1358
|
+
* @throws When used outside that provider.
|
|
1359
|
+
*/
|
|
1090
1360
|
declare function useThemeId(): string;
|
|
1091
1361
|
/** The theme id, or null outside a ThemeSettingsProvider (e.g. a store 404). */
|
|
1092
1362
|
declare function useOptionalThemeId(): string | null;
|
|
@@ -1147,6 +1417,13 @@ declare function RichText({ value }: RichTextProps): ReactElement | null;
|
|
|
1147
1417
|
|
|
1148
1418
|
/** A `:root{…}` rule from a theme's custom properties; null when empty. */
|
|
1149
1419
|
declare function themeStyleCss(vars: Record<string, string> | null | undefined): string | null;
|
|
1420
|
+
/**
|
|
1421
|
+
* Renders a theme's CSS custom properties as a `:root` style tag. Names that
|
|
1422
|
+
* are not `--custom-properties` and unsafe values are dropped.
|
|
1423
|
+
*
|
|
1424
|
+
* @param props.vars - The properties by name, for example from the theme's `styles` function.
|
|
1425
|
+
* @returns A `<style>` element, or `null` when no property is usable.
|
|
1426
|
+
*/
|
|
1150
1427
|
declare function ThemeStyle({ vars, }: {
|
|
1151
1428
|
vars: Record<string, string> | null | undefined;
|
|
1152
1429
|
}): react_jsx_runtime.JSX.Element | null;
|
|
@@ -1168,6 +1445,14 @@ declare function ThemePreviewBridge({ onRefresh }: {
|
|
|
1168
1445
|
onRefresh: () => void;
|
|
1169
1446
|
}): null;
|
|
1170
1447
|
|
|
1448
|
+
/**
|
|
1449
|
+
* Loads a store's configuration, settings and embedded scripts. Server-side;
|
|
1450
|
+
* calls with the same ref during one request share a single fetch.
|
|
1451
|
+
*
|
|
1452
|
+
* @param storeRef - The store's ref.
|
|
1453
|
+
* @param options - Accepted for compatibility and ignored; the full configuration is always fetched.
|
|
1454
|
+
* @returns The store, or `null` when it does not exist.
|
|
1455
|
+
*/
|
|
1171
1456
|
declare const getCachedStore: (storeRef: string, options?: {
|
|
1172
1457
|
includeConfig?: boolean;
|
|
1173
1458
|
includeSettings?: boolean;
|
|
@@ -1264,8 +1549,28 @@ declare const STORE_COMING_SOON_REDIRECT_PATH = "/coming-soon";
|
|
|
1264
1549
|
* - Honors `NEXT_PUBLIC_LOG_LEVEL` (client) or `LOG_LEVEL` (server)
|
|
1265
1550
|
*/
|
|
1266
1551
|
type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
1552
|
+
/**
|
|
1553
|
+
* Reads the configured log level: `NEXT_PUBLIC_LOG_LEVEL` in the browser or
|
|
1554
|
+
* `LOG_LEVEL` on the server, else `warn` in production and `debug` in
|
|
1555
|
+
* development.
|
|
1556
|
+
*
|
|
1557
|
+
* @returns The active log level.
|
|
1558
|
+
*/
|
|
1267
1559
|
declare function getLogLevel(): LogLevel;
|
|
1560
|
+
/**
|
|
1561
|
+
* Tells whether a message of one level is shown at the current level.
|
|
1562
|
+
*
|
|
1563
|
+
* @param currentLevel - The level the app is configured for.
|
|
1564
|
+
* @param messageLevel - The level of the message to print.
|
|
1565
|
+
* @returns `true` when the message should be printed; always `false` when the current level is `silent`.
|
|
1566
|
+
*/
|
|
1268
1567
|
declare function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel): boolean;
|
|
1568
|
+
/**
|
|
1569
|
+
* Silences the `console` methods below the log level by replacing them.
|
|
1570
|
+
* Calling it again with the same level does nothing.
|
|
1571
|
+
*
|
|
1572
|
+
* @param level - The level to apply; defaults to {@link getLogLevel}.
|
|
1573
|
+
*/
|
|
1269
1574
|
declare function applyConsoleFilter(level?: LogLevel): void;
|
|
1270
1575
|
|
|
1271
1576
|
export { type BankAccountView, type BankTransferDetails, COMING_SOON_STORE_DESCRIPTION, DEFAULT_REDIRECT, type Notice, type NoticeHandler, type NoticeKind, ORDER_PROGRESS_STEPS, type OrderHandoff, type OrderHandoffSummary, type OrderSuccessInfo, type PaymentConfirmationState, type PlaceOrderInput, type PlaceOrderResult, type PlacedOrder, RichText, type RichTextProps, SHIPMENT_STATUS_LABELS, SHIPPING_MESSAGES, STATUS_OPTIONS, STOCK_ISSUE_TOAST_DESCRIPTION, STORE_COMING_SOON_REDIRECT_PATH, STORE_PREVIEW_READ_ONLY_MESSAGE, SUSPENDED_STORE_METADATA, type ShipmentTrackingView, type ShippingOptionDisplay, StorefrontKitProvider, type StorefrontKitProviderProps, type SupportedCurrency, THEME_PREVIEW_FRAME_ATTR, THEME_PREVIEW_MESSAGE, TRACKING_MESSAGES, ThemePreviewBridge, ThemeSettingsProvider, ThemeStyle, type UseCheckoutOptions, applyConsoleFilter, buildStoreUrl, canCustomerCancel, comingSoonStoreMetadata, comingSoonStoreNameOf, createStoreSdk, deriveOrderProgress, deriveShipmentTracking, describeShippingOption, errorCopy, errorCopyFor, findProvinceByCodeOrName, findWardByCodeOrName, formatNumber, formatPrice, formatPriceRange, formatPriceWithoutSymbol, formatShippingAmount, formatShippingEstimate, getCachedStore, getDefaultLocale, getLogLevel, getMetaobject, getMetaobjects, getPasswordPolicyHints, getPaymentState, getPromotionDescription, isCarrierShipment, isHandedToCarrier, isStoreComingSoonError, isStoreSuspendedError, loadWards, metafield, metaobjectField, money, optionIdOf, pickBankTransfer, pollPaymentState, publicApiClient, quoteChangedOptionsFrom, readBasicSettings, readOrderHandoff, refFromPathname, resolveAssetSrc, resolveInitialState, resolveLegalHref, resolveStoreRef, resolveTransformedImageUrl, resolveTransformedProductImageUrl, resolveTransformedStoreLogoUrl, safeRedirectPath, sdk, searchTextFor, shipmentEventLabel, shouldLog, shouldPollForConfirmation, shouldShowBankTransferDetails, storeApiPath, storePath, themeStyleCss, unwrap, unwrapOrNull, useAuth, useBankTransferDetails, useCart, useCheckout, useNotify, useOptionalStoreId, useOptionalThemeId, useOptionalThemeKey, useOrderLookup, useOrderStatus, useProvinces, usePublicAuthConfig, useStore, useStoreCurrency, useStoreData, useStoreId, useStoreLocale, useThemeId, useThemeSettings, useWards, validatePasswordAgainstPolicy, withSuspendedStoreMetadataFallback };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Client-safe hooks, providers and helpers for building a storefront on\n * ecomweb: `StorefrontKitProvider`, `useCart`, `useAuth`, `useCheckout`,\n * the store hooks, and price and order formatting.\n *\n * Import from `@ecomweb/storefront-kit` in components and pages. Server-only\n * code lives in `@ecomweb/storefront-kit/server`.\n *\n * @packageDocumentation\n */\nexport { StorefrontKitProvider } from \"./provider\";\nexport type { StorefrontKitProviderProps } from \"./provider\";\nexport { useNotify } from \"./notices\";\nexport { useCheckout } from \"./checkout/use-checkout\";\nexport { useOrderLookup, useOrderStatus } from \"./orders/use-order-status\";\nexport {\n pickBankTransfer,\n shouldShowBankTransferDetails,\n useBankTransferDetails,\n} from \"./orders/bank-transfer\";\nexport type {\n BankAccountView,\n BankTransferDetails,\n} from \"./orders/bank-transfer\";\nexport type {\n PlacedOrder,\n PlaceOrderInput,\n PlaceOrderResult,\n UseCheckoutOptions,\n} from \"./checkout/use-checkout\";\nexport type { Notice, NoticeHandler, NoticeKind } from \"./notices\";\nexport {\n useOptionalStoreId,\n useStore,\n useStoreCurrency,\n useStoreData,\n useStoreId,\n useStoreLocale,\n} from \"./store/store-context\";\nexport { usePublicAuthConfig } from \"./auth/use-public-auth-config\";\nexport { publicApiClient } from \"./api/client\";\nexport { unwrap, unwrapOrNull } from \"./api/response\";\nexport { useAuth } from \"./auth/context\";\nexport { errorCopy, errorCopyFor } from \"./auth/error-copy\";\nexport {\n getPasswordPolicyHints,\n validatePasswordAgainstPolicy,\n} from \"./auth/password-policy\";\nexport { DEFAULT_REDIRECT, safeRedirectPath } from \"./auth/safe-redirect\";\nexport { useCart } from \"./cart/server-context\";\nexport { getPaymentState } from \"./checkout/get-payment-state\";\nexport { readOrderHandoff } from \"./checkout/order-handoff\";\nexport type {\n OrderHandoff,\n OrderHandoffSummary,\n} from \"./checkout/order-handoff\";\nexport { pollPaymentState } from \"./checkout/payment-state-poll\";\nexport { quoteChangedOptionsFrom } from \"./checkout/quote-changed\";\nexport { optionIdOf } from \"./shipping/option-id\";\nexport { STOCK_ISSUE_TOAST_DESCRIPTION } from \"./checkout/stock-issues\";\nexport {\n resolveInitialState,\n shouldPollForConfirmation,\n} from \"./checkout/success-state\";\nexport type { PaymentConfirmationState } from \"./checkout/success-state\";\nexport type { OrderSuccessInfo } from \"./checkout/types\";\nexport {\n formatNumber,\n formatPrice,\n formatPriceRange,\n formatPriceWithoutSymbol,\n getDefaultLocale,\n money,\n} from \"./currency\";\nexport type { SupportedCurrency } from \"./currency\";\nexport {\n ORDER_PROGRESS_STEPS,\n deriveOrderProgress,\n} from \"./orders/derive-progress\";\nexport { STATUS_OPTIONS } from \"./orders/types\";\nexport {\n SHIPMENT_STATUS_LABELS,\n TRACKING_MESSAGES,\n canCustomerCancel,\n deriveShipmentTracking,\n isCarrierShipment,\n isHandedToCarrier,\n shipmentEventLabel,\n} from \"./orders/shipment-tracking\";\nexport type { ShipmentTrackingView } from \"./orders/shipment-tracking\";\nexport { getPromotionDescription } from \"./promotions/utils\";\nexport { createStoreSdk, sdk } from \"./sdk\";\nexport {\n formatShippingAmount,\n describeShippingOption,\n type ShippingOptionDisplay,\n} from \"./shipping/format-shipping-option\";\nexport {\n loadWards,\n searchTextFor,\n useProvinces,\n useWards,\n} from \"./shipping/location-areas\";\nexport { SHIPPING_MESSAGES, formatShippingEstimate } from \"./shipping/messages\";\nexport {\n findProvinceByCodeOrName,\n findWardByCodeOrName,\n} from \"./shipping/utils\";\nexport {\n resolveAssetSrc,\n resolveTransformedImageUrl,\n resolveTransformedProductImageUrl,\n resolveTransformedStoreLogoUrl,\n} from \"./storage\";\nexport { resolveStoreRef, storeApiPath, storePath } from \"./store-scope\";\nexport { buildStoreUrl } from \"./store-scope/store-url\";\nexport { readBasicSettings, resolveLegalHref } from \"./stores/basic-settings\";\nexport { defineSchema, defineTheme } from \"./theme/define\";\nexport type {\n AnyThemeDefinition,\n BlogIndexSlotProps,\n BlogPostSlotProps,\n CollectionPageSlotProps,\n CollectionSearchParams,\n ContentPageSlotProps,\n NotFoundProps,\n ProductCardProps,\n ProductPageSlotProps,\n ThemeClientComponents,\n HomePageSlotProps,\n LayoutSlotProps,\n ThemeComponents,\n ThemeDefinition,\n ThemeInfo,\n ThemeSlot,\n ThemeSlotName,\n ThemeSlotProps,\n} from \"./theme/define\";\nexport {\n ThemeSettingsProvider,\n useOptionalThemeId,\n useOptionalThemeKey,\n useThemeId,\n useThemeSettings,\n} from \"./theme/settings-context\";\nexport { metafield, metaobjectField } from \"./metafields/readers\";\nexport { getMetaobject, getMetaobjects } from \"./metafields/metaobjects\";\nexport { RichText } from \"./metafields/rich-text\";\nexport type { RichTextProps } from \"./metafields/rich-text\";\nexport { ThemeStyle, themeStyleCss } from \"./theme/style\";\nexport {\n THEME_PREVIEW_FRAME_ATTR,\n THEME_PREVIEW_MESSAGE,\n ThemePreviewBridge,\n} from \"./theme/preview-bridge\";\nexport { getCachedStore } from \"./stores/cached\";\nexport {\n COMING_SOON_STORE_DESCRIPTION,\n comingSoonStoreMetadata,\n SUSPENDED_STORE_METADATA,\n withSuspendedStoreMetadataFallback,\n} from \"./stores/metadata\";\nexport { refFromPathname } from \"./stores/store-path\";\nexport { STORE_PREVIEW_READ_ONLY_MESSAGE } from \"./stores/store-preview-guard\";\nexport { isStoreSuspendedError } from \"./stores/store-suspension\";\nexport {\n comingSoonStoreNameOf,\n isStoreComingSoonError,\n STORE_COMING_SOON_REDIRECT_PATH,\n} from \"./stores/store-coming-soon\";\nexport { applyConsoleFilter, getLogLevel, shouldLog } from \"./logging\";\n"],"mappings":"AAUA,SAAS,6BAA6B;AAEtC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,sBAAsB;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,QAAQ,oBAAoB;AACrC,SAAS,eAAe;AACxB,SAAS,WAAW,oBAAoB;AACxC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AAKjC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,kBAAkB;AAC3B,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,+BAA+B;AACxC,SAAS,gBAAgB,WAAW;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB,8BAA8B;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,cAAc,iBAAiB;AACzD,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,cAAc,mBAAmB;AAqB1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,uBAAuB;AAC3C,SAAS,eAAe,sBAAsB;AAC9C,SAAS,gBAAgB;AAEzB,SAAS,YAAY,qBAAqB;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,uCAAuC;AAChD,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB,aAAa,iBAAiB;","names":[]}
|
package/dist/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["/**\n * Lightweight logging helpers: log levels + console filtering.\n * - Defaults to 'warn' in production and 'debug' in development\n * - Honors `NEXT_PUBLIC_LOG_LEVEL` (client) or `LOG_LEVEL` (server)\n */\n\nimport { publicConfig } from \"./config/public\";\nimport { serverLogLevel } from \"./config/log-level\";\n\nexport type LogLevel = \"silent\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\nconst levelOrder: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nexport function getLogLevel(): LogLevel {\n const envLevel =\n publicConfig().logLevel ?? serverLogLevel();\n\n if (envLevel && envLevel in levelOrder) return envLevel;\n\n return process.env.NODE_ENV === \"production\" ? \"warn\" : \"debug\";\n}\n\nexport function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel) {\n return (\n levelOrder[messageLevel] <= levelOrder[currentLevel] &&\n currentLevel !== \"silent\"\n );\n}\n\n/**\n * Replace noisy console methods based on configured level.\n * - Disables lower-priority methods while preserving warn/error by default.\n * - Safe to call multiple times; idempotent for the same level.\n */\nlet appliedLevel: LogLevel | null = null;\nexport function applyConsoleFilter(level: LogLevel = getLogLevel()) {\n if (appliedLevel === level) return; // avoid re-wrapping\n appliedLevel = level;\n\n const original = {\n log: console.log.bind(console),\n info: console.info ? console.info.bind(console) : console.log.bind(console),\n debug: console.debug\n ? console.debug.bind(console)\n : console.log.bind(console),\n warn: console.warn.bind(console),\n error: console.error.bind(console),\n } as const;\n\n const noop = () => {};\n\n console.debug = shouldLog(level, \"debug\") ? original.debug : noop;\n console.log = shouldLog(level, \"info\") ? original.log : noop;\n console.info = shouldLog(level, \"info\") ? original.info : noop;\n console.warn = shouldLog(level, \"warn\") ? original.warn : noop;\n console.error = shouldLog(level, \"error\") ? original.error : noop;\n}\n"],"mappings":"AAMA,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAI/B,MAAM,aAAuC;AAAA,EAC3C,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;
|
|
1
|
+
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["/**\n * Lightweight logging helpers: log levels + console filtering.\n * - Defaults to 'warn' in production and 'debug' in development\n * - Honors `NEXT_PUBLIC_LOG_LEVEL` (client) or `LOG_LEVEL` (server)\n */\n\nimport { publicConfig } from \"./config/public\";\nimport { serverLogLevel } from \"./config/log-level\";\n\nexport type LogLevel = \"silent\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\nconst levelOrder: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\n/**\n * Reads the configured log level: `NEXT_PUBLIC_LOG_LEVEL` in the browser or\n * `LOG_LEVEL` on the server, else `warn` in production and `debug` in\n * development.\n *\n * @returns The active log level.\n */\nexport function getLogLevel(): LogLevel {\n const envLevel =\n publicConfig().logLevel ?? serverLogLevel();\n\n if (envLevel && envLevel in levelOrder) return envLevel;\n\n return process.env.NODE_ENV === \"production\" ? \"warn\" : \"debug\";\n}\n\n/**\n * Tells whether a message of one level is shown at the current level.\n *\n * @param currentLevel - The level the app is configured for.\n * @param messageLevel - The level of the message to print.\n * @returns `true` when the message should be printed; always `false` when the current level is `silent`.\n */\nexport function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel) {\n return (\n levelOrder[messageLevel] <= levelOrder[currentLevel] &&\n currentLevel !== \"silent\"\n );\n}\n\n/**\n * Replace noisy console methods based on configured level.\n * - Disables lower-priority methods while preserving warn/error by default.\n * - Safe to call multiple times; idempotent for the same level.\n */\nlet appliedLevel: LogLevel | null = null;\n/**\n * Silences the `console` methods below the log level by replacing them.\n * Calling it again with the same level does nothing.\n *\n * @param level - The level to apply; defaults to {@link getLogLevel}.\n */\nexport function applyConsoleFilter(level: LogLevel = getLogLevel()) {\n if (appliedLevel === level) return; // avoid re-wrapping\n appliedLevel = level;\n\n const original = {\n log: console.log.bind(console),\n info: console.info ? console.info.bind(console) : console.log.bind(console),\n debug: console.debug\n ? console.debug.bind(console)\n : console.log.bind(console),\n warn: console.warn.bind(console),\n error: console.error.bind(console),\n } as const;\n\n const noop = () => {};\n\n console.debug = shouldLog(level, \"debug\") ? original.debug : noop;\n console.log = shouldLog(level, \"info\") ? original.log : noop;\n console.info = shouldLog(level, \"info\") ? original.info : noop;\n console.warn = shouldLog(level, \"warn\") ? original.warn : noop;\n console.error = shouldLog(level, \"error\") ? original.error : noop;\n}\n"],"mappings":"AAMA,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAI/B,MAAM,aAAuC;AAAA,EAC3C,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AASO,SAAS,cAAwB;AACtC,QAAM,WACJ,aAAa,EAAE,YAAY,eAAe;AAE5C,MAAI,YAAY,YAAY,WAAY,QAAO;AAE/C,SAAO,QAAQ,IAAI,aAAa,eAAe,SAAS;AAC1D;AASO,SAAS,UAAU,cAAwB,cAAwB;AACxE,SACE,WAAW,YAAY,KAAK,WAAW,YAAY,KACnD,iBAAiB;AAErB;AAOA,IAAI,eAAgC;AAO7B,SAAS,mBAAmB,QAAkB,YAAY,GAAG;AAClE,MAAI,iBAAiB,MAAO;AAC5B,iBAAe;AAEf,QAAM,WAAW;AAAA,IACf,KAAK,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC7B,MAAM,QAAQ,OAAO,QAAQ,KAAK,KAAK,OAAO,IAAI,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC1E,OAAO,QAAQ,QACX,QAAQ,MAAM,KAAK,OAAO,IAC1B,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC5B,MAAM,QAAQ,KAAK,KAAK,OAAO;AAAA,IAC/B,OAAO,QAAQ,MAAM,KAAK,OAAO;AAAA,EACnC;AAEA,QAAM,OAAO,MAAM;AAAA,EAAC;AAEpB,UAAQ,QAAQ,UAAU,OAAO,OAAO,IAAI,SAAS,QAAQ;AAC7D,UAAQ,MAAM,UAAU,OAAO,MAAM,IAAI,SAAS,MAAM;AACxD,UAAQ,OAAO,UAAU,OAAO,MAAM,IAAI,SAAS,OAAO;AAC1D,UAAQ,OAAO,UAAU,OAAO,MAAM,IAAI,SAAS,OAAO;AAC1D,UAAQ,QAAQ,UAAU,OAAO,OAAO,IAAI,SAAS,QAAQ;AAC/D;","names":[]}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { S as StorefrontMode } from './mode-
|
|
3
|
-
import './schema-
|
|
2
|
+
import { S as StorefrontMode } from './mode-DXo-EhTJ.js';
|
|
3
|
+
import './schema-DIF0CZNV.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|