@ecomweb/storefront-kit 0.14.0 → 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/dist/api/response.js.map +1 -1
- package/dist/auth/context.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 +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/server.js.map +1 -1
- package/dist/config/version-check.js.map +1 -1
- package/dist/config.d.ts +11 -3
- 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/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 +2 -2
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
|
/**
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["/**\n * The storefront's request middleware (`proxy.ts`): store routing and the\n * checks that run before a page renders.\n *\n * Import from `@ecomweb/storefront-kit/middleware` in the storefront's\n * `proxy.ts` (or `middleware.ts`).\n *\n * @packageDocumentation\n */\nexport {\n createStorefrontMiddleware,\n storefrontMiddlewareConfig,\n} from \"./middleware/create-storefront-middleware\";\n"],"mappings":"AASA;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/orders/shipment-tracking.ts"],"sourcesContent":["import type { Order, OrderShipmentSummary, ShipmentStatus } from \"@ecomweb/sdk\";\n\n/** The API's SHIPMENT_STATUS_LABEL_VI, copied exactly so badge and events agree. */\nexport const SHIPMENT_STATUS_LABELS: Record<ShipmentStatus, string> = {\n booked: \"Đã tạo vận đơn\",\n picked_up: \"Đã lấy hàng\",\n in_transit: \"Đang vận chuyển\",\n out_for_delivery: \"Đang giao hàng\",\n delivered: \"Đã giao\",\n failed: \"Giao hàng thất bại\",\n returned: \"Đã hoàn hàng\",\n cancelled: \"Đã hủy\",\n};\n\nexport const TRACKING_MESSAGES = {\n title: \"Vận chuyển\",\n trackingNumber: \"Mã vận đơn\",\n trackLink: \"Theo dõi đơn hàng\",\n handedToCarrier: \"Đơn đã được giao cho hãng vận chuyển\",\n noEvents: \"Chưa có cập nhật từ hãng vận chuyển\",\n eventFallback: \"Cập nhật vận chuyển\",\n} as const;\n\nexport interface ShipmentTrackingView {\n carrierName: string | null;\n carrierLogoUrl: string | null;\n serviceName: string | null;\n trackingNumber: string | null;\n trackLink: string | null;\n statusLabel: string | null;\n events: OrderShipmentSummary[\"events\"];\n}\n\nconst CANCELLABLE_STATUSES = [\"pending\", \"confirmed\", \"processing\"];\nconst ENDED_STATUSES: string[] = [\"cancelled\", \"failed\", \"returned\"];\n\nfunction httpLinkOrNull(link: string | null | undefined): string | null {\n return link && /^https?:\\/\\//i.test(link.trim()) ? link.trim() : null;\n}\n\nfunction labelOrNull(status: string | null | undefined): string | null {\n if (!status) return null;\n return Object.prototype.hasOwnProperty.call(SHIPMENT_STATUS_LABELS, status)\n ? SHIPMENT_STATUS_LABELS[status as ShipmentStatus]\n : null;\n}\n\nexport function deriveShipmentTracking(\n order: Order,\n): ShipmentTrackingView | null {\n const shipment = order.shipment;\n // An explicit `shipment: null` means the API decided there is nothing to show\n // (e.g. a cancelled waybill); the order's own fields are only a fallback for\n // an older API that does not send `shipment` at all.\n if (shipment === null) return null;\n if (shipment) {\n return {\n carrierName: shipment.carrier_name ?? null,\n carrierLogoUrl: httpLinkOrNull(shipment.carrier_logo_url),\n serviceName: shipment.service_name ?? null,\n trackingNumber: shipment.tracking_number ?? null,\n trackLink: httpLinkOrNull(shipment.track_link),\n statusLabel: labelOrNull(shipment.status),\n events: shipment.events ?? [],\n };\n }\n if (order.shipping_carrier || order.tracking_number) {\n return {\n carrierName: order.shipping_carrier ?? null,\n carrierLogoUrl: null,\n serviceName: null,\n trackingNumber: order.tracking_number ?? null,\n trackLink: null,\n statusLabel: null,\n events: [],\n };\n }\n return null;\n}\n\nexport function canCustomerCancel(order: Order): boolean {\n if (typeof order.can_cancel === \"boolean\") return order.can_cancel;\n return CANCELLABLE_STATUSES.includes(order.order_status);\n}\n\nexport function isHandedToCarrier(order: Order): boolean {\n const status = order.shipment?.status;\n return !!status && !ENDED_STATUSES.includes(status);\n}\n\n/**\n * True only for a carrier-booked shipment. The API also sends `order.shipment`\n * for a manual shipment (carrier and tracking number typed by the merchant),\n * with `status: null` and no events; that one has no carrier timeline to show.\n */\nexport function isCarrierShipment(order: Order): boolean {\n return order.shipment?.status != null;\n}\n\n/**\n * The text of one tracking event. A blank label falls back to the event's own\n * status label when it carries a known one, else to neutral copy -- never the\n * shipment's current status, which is not what that event reported.\n */\nexport function shipmentEventLabel(event: {\n label?: string | null;\n status?: string | null;\n}): string {\n const label = event.label?.trim();\n if (label) return label;\n return labelOrNull(event.status) ?? TRACKING_MESSAGES.eventFallback;\n}\n"],"mappings":"AAGO,MAAM,yBAAyD;AAAA,EACpE,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AACb;AAEO,MAAM,oBAAoB;AAAA,EAC/B,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,eAAe;AACjB;AAYA,MAAM,uBAAuB,CAAC,WAAW,aAAa,YAAY;AAClE,MAAM,iBAA2B,CAAC,aAAa,UAAU,UAAU;AAEnE,SAAS,eAAe,MAAgD;AACtE,SAAO,QAAQ,gBAAgB,KAAK,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI;AACnE;AAEA,SAAS,YAAY,QAAkD;AACrE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,UAAU,eAAe,KAAK,wBAAwB,MAAM,IACtE,uBAAuB,MAAwB,IAC/C;AACN;
|
|
1
|
+
{"version":3,"sources":["../../src/orders/shipment-tracking.ts"],"sourcesContent":["import type { Order, OrderShipmentSummary, ShipmentStatus } from \"@ecomweb/sdk\";\n\n/** The API's SHIPMENT_STATUS_LABEL_VI, copied exactly so badge and events agree. */\nexport const SHIPMENT_STATUS_LABELS: Record<ShipmentStatus, string> = {\n booked: \"Đã tạo vận đơn\",\n picked_up: \"Đã lấy hàng\",\n in_transit: \"Đang vận chuyển\",\n out_for_delivery: \"Đang giao hàng\",\n delivered: \"Đã giao\",\n failed: \"Giao hàng thất bại\",\n returned: \"Đã hoàn hàng\",\n cancelled: \"Đã hủy\",\n};\n\nexport const TRACKING_MESSAGES = {\n title: \"Vận chuyển\",\n trackingNumber: \"Mã vận đơn\",\n trackLink: \"Theo dõi đơn hàng\",\n handedToCarrier: \"Đơn đã được giao cho hãng vận chuyển\",\n noEvents: \"Chưa có cập nhật từ hãng vận chuyển\",\n eventFallback: \"Cập nhật vận chuyển\",\n} as const;\n\nexport interface ShipmentTrackingView {\n carrierName: string | null;\n carrierLogoUrl: string | null;\n serviceName: string | null;\n trackingNumber: string | null;\n trackLink: string | null;\n statusLabel: string | null;\n events: OrderShipmentSummary[\"events\"];\n}\n\nconst CANCELLABLE_STATUSES = [\"pending\", \"confirmed\", \"processing\"];\nconst ENDED_STATUSES: string[] = [\"cancelled\", \"failed\", \"returned\"];\n\nfunction httpLinkOrNull(link: string | null | undefined): string | null {\n return link && /^https?:\\/\\//i.test(link.trim()) ? link.trim() : null;\n}\n\nfunction labelOrNull(status: string | null | undefined): string | null {\n if (!status) return null;\n return Object.prototype.hasOwnProperty.call(SHIPMENT_STATUS_LABELS, status)\n ? SHIPMENT_STATUS_LABELS[status as ShipmentStatus]\n : null;\n}\n\n/**\n * Builds the shipment details to show for an order: carrier, tracking number,\n * tracking link, status and events. Uses the order's `shipment` when the API\n * sends one and falls back to the order's carrier and tracking fields for an\n * older API.\n *\n * @param order - The order to read.\n * @returns The shipment view, or `null` when there is nothing to show.\n */\nexport function deriveShipmentTracking(\n order: Order,\n): ShipmentTrackingView | null {\n const shipment = order.shipment;\n // An explicit `shipment: null` means the API decided there is nothing to show\n // (e.g. a cancelled waybill); the order's own fields are only a fallback for\n // an older API that does not send `shipment` at all.\n if (shipment === null) return null;\n if (shipment) {\n return {\n carrierName: shipment.carrier_name ?? null,\n carrierLogoUrl: httpLinkOrNull(shipment.carrier_logo_url),\n serviceName: shipment.service_name ?? null,\n trackingNumber: shipment.tracking_number ?? null,\n trackLink: httpLinkOrNull(shipment.track_link),\n statusLabel: labelOrNull(shipment.status),\n events: shipment.events ?? [],\n };\n }\n if (order.shipping_carrier || order.tracking_number) {\n return {\n carrierName: order.shipping_carrier ?? null,\n carrierLogoUrl: null,\n serviceName: null,\n trackingNumber: order.tracking_number ?? null,\n trackLink: null,\n statusLabel: null,\n events: [],\n };\n }\n return null;\n}\n\n/**\n * Tells whether the shopper may still cancel the order. Follows the API's\n * `can_cancel` flag when present, else the order status.\n *\n * @param order - The order to check.\n * @returns `true` when the order can be cancelled.\n */\nexport function canCustomerCancel(order: Order): boolean {\n if (typeof order.can_cancel === \"boolean\") return order.can_cancel;\n return CANCELLABLE_STATUSES.includes(order.order_status);\n}\n\n/**\n * Tells whether the order's shipment has been handed to a carrier and is not\n * cancelled, failed or returned.\n *\n * @param order - The order to check.\n * @returns `true` while the shipment is with a carrier.\n */\nexport function isHandedToCarrier(order: Order): boolean {\n const status = order.shipment?.status;\n return !!status && !ENDED_STATUSES.includes(status);\n}\n\n/**\n * True only for a carrier-booked shipment. The API also sends `order.shipment`\n * for a manual shipment (carrier and tracking number typed by the merchant),\n * with `status: null` and no events; that one has no carrier timeline to show.\n */\nexport function isCarrierShipment(order: Order): boolean {\n return order.shipment?.status != null;\n}\n\n/**\n * The text of one tracking event. A blank label falls back to the event's own\n * status label when it carries a known one, else to neutral copy -- never the\n * shipment's current status, which is not what that event reported.\n */\nexport function shipmentEventLabel(event: {\n label?: string | null;\n status?: string | null;\n}): string {\n const label = event.label?.trim();\n if (label) return label;\n return labelOrNull(event.status) ?? TRACKING_MESSAGES.eventFallback;\n}\n"],"mappings":"AAGO,MAAM,yBAAyD;AAAA,EACpE,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AACb;AAEO,MAAM,oBAAoB;AAAA,EAC/B,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,eAAe;AACjB;AAYA,MAAM,uBAAuB,CAAC,WAAW,aAAa,YAAY;AAClE,MAAM,iBAA2B,CAAC,aAAa,UAAU,UAAU;AAEnE,SAAS,eAAe,MAAgD;AACtE,SAAO,QAAQ,gBAAgB,KAAK,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI;AACnE;AAEA,SAAS,YAAY,QAAkD;AACrE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,UAAU,eAAe,KAAK,wBAAwB,MAAM,IACtE,uBAAuB,MAAwB,IAC/C;AACN;AAWO,SAAS,uBACd,OAC6B;AAC7B,QAAM,WAAW,MAAM;AAIvB,MAAI,aAAa,KAAM,QAAO;AAC9B,MAAI,UAAU;AACZ,WAAO;AAAA,MACL,aAAa,SAAS,gBAAgB;AAAA,MACtC,gBAAgB,eAAe,SAAS,gBAAgB;AAAA,MACxD,aAAa,SAAS,gBAAgB;AAAA,MACtC,gBAAgB,SAAS,mBAAmB;AAAA,MAC5C,WAAW,eAAe,SAAS,UAAU;AAAA,MAC7C,aAAa,YAAY,SAAS,MAAM;AAAA,MACxC,QAAQ,SAAS,UAAU,CAAC;AAAA,IAC9B;AAAA,EACF;AACA,MAAI,MAAM,oBAAoB,MAAM,iBAAiB;AACnD,WAAO;AAAA,MACL,aAAa,MAAM,oBAAoB;AAAA,MACvC,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,gBAAgB,MAAM,mBAAmB;AAAA,MACzC,WAAW;AAAA,MACX,aAAa;AAAA,MACb,QAAQ,CAAC;AAAA,IACX;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,kBAAkB,OAAuB;AACvD,MAAI,OAAO,MAAM,eAAe,UAAW,QAAO,MAAM;AACxD,SAAO,qBAAqB,SAAS,MAAM,YAAY;AACzD;AASO,SAAS,kBAAkB,OAAuB;AACvD,QAAM,SAAS,MAAM,UAAU;AAC/B,SAAO,CAAC,CAAC,UAAU,CAAC,eAAe,SAAS,MAAM;AACpD;AAOO,SAAS,kBAAkB,OAAuB;AACvD,SAAO,MAAM,UAAU,UAAU;AACnC;AAOO,SAAS,mBAAmB,OAGxB;AACT,QAAM,QAAQ,MAAM,OAAO,KAAK;AAChC,MAAI,MAAO,QAAO;AAClB,SAAO,YAAY,MAAM,MAAM,KAAK,kBAAkB;AACxD;","names":[]}
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport type { StoreConfigurationInfo } from \"@ecomweb/sdk\";\nimport { AuthProvider, useAuth } from \"./auth/context\";\nimport { CartProvider } from \"./cart/server-context\";\nimport { NoticeProvider, type NoticeHandler } from \"./notices\";\nimport { StoreProvider } from \"./store/store-context\";\nimport {\n setBrowserStorePreviewToken,\n setStorePreviewRenewer,\n} from \"./api/store-preview-header\";\n\n/**\n * How often a preview host's preview token is renewed: half of its 1 h, so\n * a long editor session never sends an expired one.\n */\nconst STORE_PREVIEW_RENEW_MS = 30 * 60 * 1000;\n\nexport interface StorefrontKitProviderProps {\n store: StoreConfigurationInfo;\n /** The ref the cart is scoped to; defaults to `store.ref`. */\n storeRef?: string;\n /** Receives the kit's notices (item added, request failed, …). */\n onNotice?: NoticeHandler;\n /**\n * The store preview token the browser's kit clients send as\n * `X-Store-Preview` (`readStorePreviewToken()` on the server). The layout\n * passes it only while the store is coming soon, else null.\n *\n * Why the browser gets it: the preview cookie stays httpOnly, but without\n * the token the client-side fetches on the home, collection and product\n * pages would get the API's 403 during a preview. It is one of three\n * tokens: the store preview cookie's (the dashboard's preview link), a\n * theme preview host's (`p-<slug>`, from the host lookup), or the theme\n * preview cookie's (`?preview_theme=` on the store's own host). Each is\n * read-only (the API opens GET and HEAD only) and bound to one store.\n * Merchant scripts are off during a store preview, so they never see it.\n */\n storePreviewToken?: string | null;\n /**\n * Fetches a fresh `storePreviewToken`, such as by re-rendering the layout.\n * The app passes it only on a theme preview host, whose token lasts 1 h:\n * the layout does not re-render on client navigation, so the first\n * render's token would run out in a long editor session. While both are\n * set, the kit calls it every 30 minutes, and when a read is refused with\n * `STORE_COMING_SOON` (at most once a minute). A link preview's 24 h\n * cookie is not renewed.\n */\n onStorePreviewRenew?: () => void;\n children: ReactNode;\n}\n\nfunction IdentityCart({\n storeRef,\n children,\n}: {\n storeRef: string;\n children: ReactNode;\n}) {\n const { user } = useAuth();\n return (\n <CartProvider storeRef={storeRef} userId={user?.id}>\n {children}\n </CartProvider>\n );\n}\n\n/**\n * The kit's providers in their required order: auth reads the store, and the\n * cart reads the signed-in identity from auth.\n */\nexport function StorefrontKitProvider({\n store,\n storeRef,\n onNotice,\n storePreviewToken,\n onStorePreviewRenew,\n children,\n}: StorefrontKitProviderProps) {\n // In the render body, not an effect: React renders this before any child\n // effect runs, so the first client fetch already carries the token. A\n // render without one clears it; until then it stays set (store-preview-\n // header.ts). A no-op on the server.\n setBrowserStorePreviewToken(storePreviewToken ?? null);\n\n // The latest callback, so an app that passes a new function on every\n // render does not restart the 30 minute timer each time.\n const renewRef = useRef(onStorePreviewRenew);\n renewRef.current = onStorePreviewRenew;\n const renews = !!storePreviewToken && !!onStorePreviewRenew;\n useEffect(() => {\n if (!renews) return;\n const renew = () => renewRef.current?.();\n setStorePreviewRenewer(renew);\n const timer = setInterval(renew, STORE_PREVIEW_RENEW_MS);\n return () => {\n clearInterval(timer);\n setStorePreviewRenewer(null);\n };\n }, [renews]);\n\n return (\n <StoreProvider store={store}>\n <NoticeProvider onNotice={onNotice}>\n <AuthProvider>\n <IdentityCart storeRef={storeRef ?? store.ref}>\n {children}\n </IdentityCart>\n </AuthProvider>\n </NoticeProvider>\n </StoreProvider>\n );\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport type { StoreConfigurationInfo } from \"@ecomweb/sdk\";\nimport { AuthProvider, useAuth } from \"./auth/context\";\nimport { CartProvider } from \"./cart/server-context\";\nimport { NoticeProvider, type NoticeHandler } from \"./notices\";\nimport { StoreProvider } from \"./store/store-context\";\nimport {\n setBrowserStorePreviewToken,\n setStorePreviewRenewer,\n} from \"./api/store-preview-header\";\n\n/**\n * How often a preview host's preview token is renewed: half of its 1 h, so\n * a long editor session never sends an expired one.\n */\nconst STORE_PREVIEW_RENEW_MS = 30 * 60 * 1000;\n\n/** Props of {@link StorefrontKitProvider}. */\nexport interface StorefrontKitProviderProps {\n store: StoreConfigurationInfo;\n /** The ref the cart is scoped to; defaults to `store.ref`. */\n storeRef?: string;\n /** Receives the kit's notices (item added, request failed, …). */\n onNotice?: NoticeHandler;\n /**\n * The store preview token the browser's kit clients send as\n * `X-Store-Preview` (`readStorePreviewToken()` on the server). The layout\n * passes it only while the store is coming soon, else null.\n *\n * Why the browser gets it: the preview cookie stays httpOnly, but without\n * the token the client-side fetches on the home, collection and product\n * pages would get the API's 403 during a preview. It is one of three\n * tokens: the store preview cookie's (the dashboard's preview link), a\n * theme preview host's (`p-<slug>`, from the host lookup), or the theme\n * preview cookie's (`?preview_theme=` on the store's own host). Each is\n * read-only (the API opens GET and HEAD only) and bound to one store.\n * Merchant scripts are off during a store preview, so they never see it.\n */\n storePreviewToken?: string | null;\n /**\n * Fetches a fresh `storePreviewToken`, such as by re-rendering the layout.\n * The app passes it only on a theme preview host, whose token lasts 1 h:\n * the layout does not re-render on client navigation, so the first\n * render's token would run out in a long editor session. While both are\n * set, the kit calls it every 30 minutes, and when a read is refused with\n * `STORE_COMING_SOON` (at most once a minute). A link preview's 24 h\n * cookie is not renewed.\n */\n onStorePreviewRenew?: () => void;\n children: ReactNode;\n}\n\nfunction IdentityCart({\n storeRef,\n children,\n}: {\n storeRef: string;\n children: ReactNode;\n}) {\n const { user } = useAuth();\n return (\n <CartProvider storeRef={storeRef} userId={user?.id}>\n {children}\n </CartProvider>\n );\n}\n\n/**\n * The kit's providers in their required order: auth reads the store, and the\n * cart reads the signed-in identity from auth.\n */\nexport function StorefrontKitProvider({\n store,\n storeRef,\n onNotice,\n storePreviewToken,\n onStorePreviewRenew,\n children,\n}: StorefrontKitProviderProps) {\n // In the render body, not an effect: React renders this before any child\n // effect runs, so the first client fetch already carries the token. A\n // render without one clears it; until then it stays set (store-preview-\n // header.ts). A no-op on the server.\n setBrowserStorePreviewToken(storePreviewToken ?? null);\n\n // The latest callback, so an app that passes a new function on every\n // render does not restart the 30 minute timer each time.\n const renewRef = useRef(onStorePreviewRenew);\n renewRef.current = onStorePreviewRenew;\n const renews = !!storePreviewToken && !!onStorePreviewRenew;\n useEffect(() => {\n if (!renews) return;\n const renew = () => renewRef.current?.();\n setStorePreviewRenewer(renew);\n const timer = setInterval(renew, STORE_PREVIEW_RENEW_MS);\n return () => {\n clearInterval(timer);\n setStorePreviewRenewer(null);\n };\n }, [renews]);\n\n return (\n <StoreProvider store={store}>\n <NoticeProvider onNotice={onNotice}>\n <AuthProvider>\n <IdentityCart storeRef={storeRef ?? store.ref}>\n {children}\n </IdentityCart>\n </AuthProvider>\n </NoticeProvider>\n </StoreProvider>\n );\n}\n"],"mappings":";AA+DI;AA7DJ,SAAS,WAAW,cAA8B;AAElD,SAAS,cAAc,eAAe;AACtC,SAAS,oBAAoB;AAC7B,SAAS,sBAA0C;AACnD,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAMP,MAAM,yBAAyB,KAAK,KAAK;AAqCzC,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AACF,GAGG;AACD,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,SACE,oBAAC,gBAAa,UAAoB,QAAQ,MAAM,IAC7C,UACH;AAEJ;AAMO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA+B;AAK7B,8BAA4B,qBAAqB,IAAI;AAIrD,QAAM,WAAW,OAAO,mBAAmB;AAC3C,WAAS,UAAU;AACnB,QAAM,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AACxC,YAAU,MAAM;AACd,QAAI,CAAC,OAAQ;AACb,UAAM,QAAQ,MAAM,SAAS,UAAU;AACvC,2BAAuB,KAAK;AAC5B,UAAM,QAAQ,YAAY,OAAO,sBAAsB;AACvD,WAAO,MAAM;AACX,oBAAc,KAAK;AACnB,6BAAuB,IAAI;AAAA,IAC7B;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,SACE,oBAAC,iBAAc,OACb,8BAAC,kBAAe,UACd,8BAAC,gBACC,8BAAC,gBAAa,UAAU,YAAY,MAAM,KACvC,UACH,GACF,GACF,GACF;AAEJ;","names":[]}
|
|
@@ -46,6 +46,10 @@ declare const serverConfigSchema: z.ZodObject<{
|
|
|
46
46
|
storeTrafficLogPerMinute: z.ZodNumber;
|
|
47
47
|
}, z.core.$strip>;
|
|
48
48
|
type ServerConfig = z.infer<typeof serverConfigSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when the storefront's environment variables are missing or invalid.
|
|
51
|
+
* The message names the variable behind every bad field.
|
|
52
|
+
*/
|
|
49
53
|
declare class ConfigError extends Error {
|
|
50
54
|
constructor(message: string);
|
|
51
55
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
import { CurrentIdentity } from '@ecomweb/sdk';
|
|
3
|
-
import { E as EnvSource, S as ServerConfig } from './schema-
|
|
3
|
+
import { E as EnvSource, S as ServerConfig } from './schema-DIF0CZNV.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -46,6 +46,14 @@ declare function requireSession(storeRef: string, redirectTo: string): Promise<C
|
|
|
46
46
|
|
|
47
47
|
/** Parses the variables of the mode `env` selects (see resolveMode). */
|
|
48
48
|
declare function parseServerConfig(env: EnvSource): ServerConfig;
|
|
49
|
+
/**
|
|
50
|
+
* The server's parsed configuration, read from the environment on the first
|
|
51
|
+
* call and cached. Server-only: import it from `@ecomweb/storefront-kit/server`
|
|
52
|
+
* in server code, never in a client component.
|
|
53
|
+
*
|
|
54
|
+
* @returns The validated server config.
|
|
55
|
+
* @throws ConfigError when a required variable is missing or invalid.
|
|
56
|
+
*/
|
|
49
57
|
declare function serverConfig(): ServerConfig;
|
|
50
58
|
|
|
51
59
|
/**
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-only route handlers and helpers: the auth routes, the backend proxy,\n * session checks and the server config.\n *\n * Import from `@ecomweb/storefront-kit/server` in route handlers and server\n * components only; the entry imports `server-only` and fails in a client\n * bundle.\n *\n * @packageDocumentation\n */\nimport \"server-only\";\n\nexport {\n createAuthRoutes,\n createBackendProxy,\n requireSession,\n} from \"./server/routes\";\nexport type {\n CustomerIdentity,\n RouteContext,\n RouteHandler,\n} from \"./server/routes\";\nexport { hasCustomerSession } from \"./auth/session\";\nexport { parseServerConfig, serverConfig } from \"./config/server\";\nexport { resolveRootStoreRef } from \"./store-scope/root\";\nexport { readThemePreviewToken } from \"./theme/read-preview-token\";\nexport { readStorePreviewToken } from \"./stores/read-store-preview-token\";\nexport { readPreviewHostSlug } from \"./theme/read-preview-host\";\nexport { externalThemeRedirectFor } from \"./theme/external-storefront\";\nexport { resolveComingSoonStore } from \"./stores/resolve-coming-soon\";\n"],"mappings":"AAUA,OAAO;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AACtC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;","names":[]}
|