@ecomweb/storefront-kit 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +25 -1
  2. package/bin/check-client-bundle-lib.d.mts +16 -0
  3. package/bin/check-client-bundle-lib.mjs +58 -0
  4. package/bin/check-client-bundle.d.mts +11 -0
  5. package/bin/check-client-bundle.mjs +8 -0
  6. package/dist/api/client.js +39 -0
  7. package/dist/api/client.js.map +1 -1
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/proxy-guard.js +29 -0
  10. package/dist/api/proxy-guard.js.map +1 -0
  11. package/dist/api/proxy-routes.js +126 -0
  12. package/dist/api/proxy-routes.js.map +1 -0
  13. package/dist/api/proxy.js +17 -4
  14. package/dist/api/proxy.js.map +1 -1
  15. package/dist/api/response.js.map +1 -1
  16. package/dist/api/server-sdk.js +41 -0
  17. package/dist/api/server-sdk.js.map +1 -0
  18. package/dist/api/store-preview-header.js.map +1 -1
  19. package/dist/auth/context.js.map +1 -1
  20. package/dist/auth/sdk.js +15 -5
  21. package/dist/auth/sdk.js.map +1 -1
  22. package/dist/auth/session-refresh.js +7 -4
  23. package/dist/auth/session-refresh.js.map +1 -1
  24. package/dist/cart/api.js.map +1 -1
  25. package/dist/cart/server-context.js.map +1 -1
  26. package/dist/checkout/get-payment-state.js +4 -8
  27. package/dist/checkout/get-payment-state.js.map +1 -1
  28. package/dist/checkout/initiate-gateway-payment.js +5 -7
  29. package/dist/checkout/initiate-gateway-payment.js.map +1 -1
  30. package/dist/checkout/order-handoff.js.map +1 -1
  31. package/dist/checkout/payment-redirect.js.map +1 -1
  32. package/dist/checkout/use-checkout.js.map +1 -1
  33. package/dist/client-info.js +1 -1
  34. package/dist/config/public.js +2 -0
  35. package/dist/config/public.js.map +1 -1
  36. package/dist/config/schema.js +16 -4
  37. package/dist/config/schema.js.map +1 -1
  38. package/dist/config/secret-guard.js +20 -0
  39. package/dist/config/secret-guard.js.map +1 -0
  40. package/dist/config/server.js +15 -8
  41. package/dist/config/server.js.map +1 -1
  42. package/dist/config/version-check.js.map +1 -1
  43. package/dist/config.d.ts +22 -4
  44. package/dist/config.js +2 -0
  45. package/dist/config.js.map +1 -1
  46. package/dist/currency.js.map +1 -1
  47. package/dist/index.d.ts +331 -69
  48. package/dist/index.js.map +1 -1
  49. package/dist/logging.js.map +1 -1
  50. package/dist/middleware/create-storefront-middleware.js +14 -3
  51. package/dist/middleware/create-storefront-middleware.js.map +1 -1
  52. package/dist/middleware.d.ts +2 -2
  53. package/dist/middleware.js.map +1 -1
  54. package/dist/{mode-Lm9t4qzX.d.ts → mode-oVZCQxrc.d.ts} +1 -1
  55. package/dist/orders/api-client.js +3 -3
  56. package/dist/orders/api-client.js.map +1 -1
  57. package/dist/orders/bank-transfer.js +1 -1
  58. package/dist/orders/bank-transfer.js.map +1 -1
  59. package/dist/orders/shipment-tracking.js.map +1 -1
  60. package/dist/orders/use-order-status.js +2 -2
  61. package/dist/orders/use-order-status.js.map +1 -1
  62. package/dist/promotions/use-promotion-validation.js +2 -2
  63. package/dist/promotions/use-promotion-validation.js.map +1 -1
  64. package/dist/provider.js.map +1 -1
  65. package/dist/request/served-store.js +5 -0
  66. package/dist/request/served-store.js.map +1 -0
  67. package/dist/{schema-Dg0ZflMW.d.ts → schema-B3nAYiwT.d.ts} +5 -1
  68. package/dist/sdk.js +3 -3
  69. package/dist/sdk.js.map +1 -1
  70. package/dist/server/routes.js +16 -9
  71. package/dist/server/routes.js.map +1 -1
  72. package/dist/server.d.ts +46 -5
  73. package/dist/server.js +2 -0
  74. package/dist/server.js.map +1 -1
  75. package/dist/shipping/location-areas.js.map +1 -1
  76. package/dist/shipping/use-shipping-calculation.js +2 -2
  77. package/dist/shipping/use-shipping-calculation.js.map +1 -1
  78. package/dist/storage.js.map +1 -1
  79. package/dist/store/store-context.js.map +1 -1
  80. package/dist/store-scope/index.js.map +1 -1
  81. package/dist/stores/basic-settings.js.map +1 -1
  82. package/dist/stores/cached.js.map +1 -1
  83. package/dist/theme/define.js.map +1 -1
  84. package/dist/theme/index.js.map +1 -1
  85. package/dist/theme/settings-context.js.map +1 -1
  86. package/dist/theme/style.js.map +1 -1
  87. package/dist/theme.d.ts +33 -0
  88. package/package.json +6 -2
  89. package/dist/api/server-client.js +0 -162
  90. package/dist/api/server-client.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -2,7 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode, ReactElement } from 'react';
4
4
  import * as _ecomweb_sdk from '@ecomweb/sdk';
5
- import { StoreConfigurationInfo, StorePaymentMethod, OrderWithItems, PublicAuthConfig, CurrentIdentity, PasswordPolicy, ShippingOption, OrderStatus, Order, CreateOrderRequest, ShipmentStatus, OrderShipmentSummary, LocationAreasResponse, LocationArea, StoreConfig, ThemeValues, WithMetafields, StorefrontMetafields, ResolvedMetaobjectRef, ResolvedMetaobjectStub, StorefrontMetaobjectEntry, MetaobjectListParams, MetaobjectListResult, RichTextRoot } from '@ecomweb/sdk';
5
+ import { StoreConfigurationInfo, StorePaymentMethod, OrderWithItems, PublicAuthConfig, CurrentIdentity, PasswordPolicy, ShippingOption, OrderStatus, Order, CreateOrderRequest, ShipmentStatus, OrderShipmentSummary, EcomwebServerSdk, EcomwebSdk, LocationAreasResponse, LocationArea, StoreConfig, ThemeValues, WithMetafields, StorefrontMetafields, ResolvedMetaobjectRef, ResolvedMetaobjectStub, StorefrontMetaobjectEntry, MetaobjectListParams, MetaobjectListResult, RichTextRoot } from '@ecomweb/sdk';
6
+ export { EcomwebSdk, EcomwebServerSdk } from '@ecomweb/sdk';
6
7
  import currencyJs from 'currency.js';
7
8
  import { AxiosRequestConfig, AxiosInstance } from 'axios';
8
9
  export { AnyThemeDefinition, BlogIndexSlotProps, BlogPostSlotProps, CollectionPageSlotProps, CollectionSearchParams, ContentPageSlotProps, HomePageSlotProps, LayoutSlotProps, NotFoundProps, ProductCardProps, ProductPageSlotProps, ThemeClientComponents, ThemeComponents, ThemeDefinition, ThemeInfo, ThemeSlot, ThemeSlotName, ThemeSlotProps, defineSchema, defineTheme } from './theme.js';
@@ -26,6 +27,7 @@ type NoticeHandler = (notice: Notice) => void;
26
27
  /** Report a notice to the app; a no-op outside a NoticeProvider. */
27
28
  declare function useNotify(): NoticeHandler;
28
29
 
30
+ /** Props of {@link StorefrontKitProvider}. */
29
31
  interface StorefrontKitProviderProps {
30
32
  store: StoreConfigurationInfo;
31
33
  /** The ref the cart is scoped to; defaults to `store.ref`. */
@@ -217,6 +219,33 @@ interface UseCheckoutOptions {
217
219
  * Checkout without the UI: payment methods, shipping quotes, promotions,
218
220
  * totals, placing the order and the payment-provider hand-off. The app
219
221
  * renders the form and decides what to show for each PlaceOrderResult.
222
+ *
223
+ * Must run under {@link StorefrontKitProvider}, which supplies the store, auth
224
+ * and cart it reads.
225
+ *
226
+ * @param options - The address codes shipping is quoted for, and optional
227
+ * carrier quotes and gateway navigation ({@link UseCheckoutOptions}).
228
+ * @returns The cart `items`, `paymentMethods`, `shipping`, `promotion` and
229
+ * `totals` state, `stockIssues`, and `placeOrder` with the payment redirect
230
+ * helpers.
231
+ *
232
+ * @example
233
+ * ```tsx
234
+ * "use client";
235
+ * import { useCheckout } from "@ecomweb/storefront-kit";
236
+ *
237
+ * export function PlaceOrderButton({ province, ward, form }) {
238
+ * const checkout = useCheckout({ province, ward });
239
+ * return (
240
+ * <button
241
+ * disabled={checkout.isSubmitting}
242
+ * onClick={() => checkout.placeOrder(form)}
243
+ * >
244
+ * Pay {checkout.totals.total}
245
+ * </button>
246
+ * );
247
+ * }
248
+ * ```
220
249
  */
221
250
  declare function useCheckout({ province, ward, includeCarrierOptions, navigateToGateway, }: UseCheckoutOptions): {
222
251
  items: CartItem[];
@@ -388,6 +417,13 @@ declare function useOrderLookup({ orderCode, email, phone, }: {
388
417
  };
389
418
 
390
419
  type SupportedCurrency = "VND" | "USD" | "EUR" | "SGD";
420
+ /**
421
+ * Picks the locale used to format prices in a currency: `en-US` for USD, EUR
422
+ * and SGD, `vi-VN` for VND.
423
+ *
424
+ * @param currency - The store's currency code.
425
+ * @returns A BCP 47 locale tag.
426
+ */
391
427
  declare function getDefaultLocale(currency: SupportedCurrency): string;
392
428
  /**
393
429
  * Format an amount as money in the given currency.
@@ -397,20 +433,98 @@ declare function getDefaultLocale(currency: SupportedCurrency): string;
397
433
  * locales. It still matters to formatNumber, which is not currency.
398
434
  */
399
435
  declare function formatPrice(amount: number, locale?: string, code?: SupportedCurrency | string): string;
436
+ /**
437
+ * Formats a plain number with the locale's digit grouping, without a currency
438
+ * symbol.
439
+ *
440
+ * @param amount - The number to format.
441
+ * @param locale - BCP 47 locale tag; defaults to `vi-VN`.
442
+ * @returns The formatted number.
443
+ */
400
444
  declare function formatNumber(amount: number, locale?: string): string;
445
+ /**
446
+ * Formats a price range such as a product's lowest and highest variant price.
447
+ *
448
+ * @param min - The lowest price.
449
+ * @param max - The highest price.
450
+ * @param locale - BCP 47 locale tag; defaults to `vi-VN`.
451
+ * @param code - Currency code; defaults to `VND`.
452
+ * @returns One formatted price when the two match or `max` is missing, `min - max` otherwise, and an empty string when both are missing.
453
+ */
401
454
  declare function formatPriceRange(min?: number, max?: number, locale?: string, code?: SupportedCurrency): string;
455
+ /**
456
+ * Wraps a value in a currency.js object for safe money arithmetic (add,
457
+ * subtract, multiply, format) without floating-point drift.
458
+ *
459
+ * @param value - The amount, as a number or numeric string.
460
+ * @param locale - BCP 47 locale tag; defaults to `vi-VN`.
461
+ * @param code - Currency code; defaults to `VND`.
462
+ * @returns A currency.js value configured for that locale and currency.
463
+ */
402
464
  declare const money: (value: number | string, locale?: string, code?: SupportedCurrency) => currencyJs;
465
+ /**
466
+ * Formats an amount with the currency's separators but no symbol, for price
467
+ * inputs.
468
+ *
469
+ * @param amount - The amount to format.
470
+ * @param locale - BCP 47 locale tag; defaults to `vi-VN`.
471
+ * @param code - Currency code; defaults to `VND`.
472
+ * @returns The formatted amount.
473
+ */
403
474
  declare function formatPriceWithoutSymbol(amount: number, locale?: string, code?: SupportedCurrency): string;
404
475
 
405
476
  interface StoreContextData {
406
477
  store: StoreConfigurationInfo;
407
478
  }
479
+ /**
480
+ * The store this page belongs to, as `{ store }`.
481
+ *
482
+ * Must run under {@link StorefrontKitProvider} (or the kit's store provider).
483
+ *
484
+ * @returns The store context.
485
+ * @throws When used outside the provider.
486
+ */
408
487
  declare function useStore(): StoreContextData;
488
+ /**
489
+ * The store's configuration: ref, name, settings and config. Same as
490
+ * `useStore().store`.
491
+ *
492
+ * Must run under {@link StorefrontKitProvider}.
493
+ *
494
+ * @returns The store configuration.
495
+ * @throws When used outside the provider.
496
+ */
409
497
  declare function useStoreData(): StoreConfigurationInfo;
410
498
  /** The store ref, or null outside a StoreProvider (e.g. a store-level 404). */
411
499
  declare function useOptionalStoreId(): string | null;
500
+ /**
501
+ * The store's ref.
502
+ *
503
+ * Must run under {@link StorefrontKitProvider}.
504
+ *
505
+ * @returns The store ref.
506
+ * @throws When used outside the provider.
507
+ */
412
508
  declare function useStoreId(): string;
509
+ /**
510
+ * The store's currency code, `VND` when the store sets none or one the kit
511
+ * does not support.
512
+ *
513
+ * Must run under {@link StorefrontKitProvider}.
514
+ *
515
+ * @returns The currency code.
516
+ * @throws When used outside the provider.
517
+ */
413
518
  declare function useStoreCurrency(): SupportedCurrency;
519
+ /**
520
+ * The locale to format prices and numbers in for this store, from its
521
+ * currency.
522
+ *
523
+ * Must run under {@link StorefrontKitProvider}.
524
+ *
525
+ * @returns A BCP 47 locale tag.
526
+ * @throws When used outside the provider.
527
+ */
414
528
  declare function useStoreLocale(): string;
415
529
 
416
530
  interface UsePublicAuthConfigResult {
@@ -470,6 +584,13 @@ declare class ApiClient implements AuthenticatedApiClient {
470
584
  private setupInterceptors;
471
585
  private handleResponse;
472
586
  private handleError;
587
+ /**
588
+ * The direct, publishable-key client cannot call a private route: the API
589
+ * would refuse it, so refuse here, before the network. Logs the matched
590
+ * route pattern, never the raw path (it can carry a review token or an
591
+ * order code).
592
+ */
593
+ private refusePrivateRoute;
473
594
  get<T>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
474
595
  post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
475
596
  put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
@@ -486,7 +607,23 @@ declare class ApiClient implements AuthenticatedApiClient {
486
607
  */
487
608
  declare const publicApiClient: ApiClient;
488
609
 
610
+ /**
611
+ * Returns the data of a successful API response.
612
+ *
613
+ * @param response - A response from an SDK call.
614
+ * @returns The response data.
615
+ * @throws ApiClientError when the response failed, with the API's message, status code and error code.
616
+ */
489
617
  declare function unwrap<T>(response: ApiResponse<T>): T;
618
+ /**
619
+ * Returns the data of a successful API response, or `null` when the API
620
+ * answered with one of the given status codes.
621
+ *
622
+ * @param response - A response from an SDK call.
623
+ * @param nullStatusCodes - Statuses that mean "nothing there"; defaults to `[404]`.
624
+ * @returns The response data, or `null` when not found.
625
+ * @throws ApiClientError on any other API error.
626
+ */
490
627
  declare function unwrapOrNull<T>(response: ApiResponse<T>, nullStatusCodes?: number[]): T | null;
491
628
 
492
629
  interface AuthError {
@@ -518,6 +655,17 @@ interface AuthContextType {
518
655
  signOut: () => Promise<void>;
519
656
  refresh: () => Promise<void>;
520
657
  }
658
+ /**
659
+ * The shopper's sign-in state and actions: `user`, `loading`, `isAnonymous`,
660
+ * `signIn`, `signUp`, `sendLoginCode`, `verifyOtp`, `signInWithGoogle`,
661
+ * `signInAnonymously`, `signOut` and `refresh`. The sign-in actions resolve to
662
+ * `{ error }` and do not throw.
663
+ *
664
+ * Must run under {@link StorefrontKitProvider}, which includes the auth provider.
665
+ *
666
+ * @returns The auth context.
667
+ * @throws When used outside the provider.
668
+ */
521
669
  declare function useAuth(): AuthContextType;
522
670
 
523
671
  /** Maps a backend error code to Vietnamese copy. */
@@ -614,6 +762,28 @@ interface CartContextType extends CartState {
614
762
  total: number;
615
763
  }>;
616
764
  }
765
+ /**
766
+ * The shopper's cart and the actions to change it: `items`, `itemCount`,
767
+ * `subtotal`, `total`, `discountAmount`, `isLoading`, `addItem`, `removeItem`,
768
+ * `updateQuantity`, `clearCart`, `refreshCart`, `mergeCarts` and
769
+ * `reorderItems`. Amounts are in the store's currency.
770
+ *
771
+ * Must run under {@link StorefrontKitProvider}, which includes the cart provider.
772
+ *
773
+ * @returns The cart context.
774
+ * @throws When used outside the provider.
775
+ *
776
+ * @example
777
+ * ```tsx
778
+ * "use client";
779
+ * import { useCart } from "@ecomweb/storefront-kit";
780
+ *
781
+ * export function CartBadge() {
782
+ * const { itemCount, isLoading } = useCart();
783
+ * return <span>{isLoading ? "…" : itemCount}</span>;
784
+ * }
785
+ * ```
786
+ */
617
787
  declare function useCart(): CartContextType;
618
788
 
619
789
  /**
@@ -690,26 +860,13 @@ interface PollPaymentStateOptions {
690
860
  declare function pollPaymentState(options: PollPaymentStateOptions): Promise<PollOutcome>;
691
861
 
692
862
  /**
693
- * TEMPORARY adapter standing in for `sdk.payments.getPaymentState`.
694
- *
695
- * `sdk.payments` was added by this plan's Task 2
696
- * (`ecomweb-contracts` branch `feat/payment-client-methods`, commit `58c2c76`),
697
- * but that SDK PR is not yet merged to `main`, and this repo's lockfile
698
- * pins an older `@ecomweb/sdk` commit that has no `payments` module at all
699
- * — see `lib/checkout/initiate-gateway-payment.ts` for the full story
700
- * (same pinned commit, same missing module). Running
701
- * `pnpm update @ecomweb/sdk` here is explicitly out of scope for this task
702
- * — it is a deliberate later step in the plan.
703
- *
704
- * This function mirrors `PaymentsApi.getPaymentState()`'s request/response
705
- * shape exactly (same path, same result shape) so that once the SDK bump
706
- * lands, the fix is: delete this file, delete this import in
707
- * `payment-state-poll`'s caller, and call
708
- * `sdk.payments.getPaymentState(...)` instead — the call site already reads
709
- * as if it were doing that today.
863
+ * Reads where a payment stands for an order, from the browser, through the
864
+ * store's backend proxy (`createStoreSdk`), which adds the secret key. Browser
865
+ * only: the proxied SDK uses a relative URL. On a server use `getServerSdk()`.
710
866
  *
711
- * FOLLOW-UP: delete this file once `@ecomweb/sdk` is bumped past
712
- * `feat/payment-client-methods` and exposes `sdk.payments.getPaymentState`.
867
+ * @param storeRef - the store's ref
868
+ * @param order_code - the order's code
869
+ * @returns the payment state of the order
713
870
  */
714
871
  declare function getPaymentState(storeRef: string, order_code: string): Promise<PaymentStateResult>;
715
872
 
@@ -752,7 +909,7 @@ declare const publicOrdersApi: {
752
909
  * `isAuth` comes from the caller's auth context — this module is not a
753
910
  * component and must not read context or an httpOnly cookie itself.
754
911
  *
755
- * When true the SDK posts to `/tenant/stores/:ref/customers/orders`, which
912
+ * When true the SDK posts to `/storefront/stores/:ref/customers/orders`, which
756
913
  * derives BOTH `customer_id` (ResolveCustomerInterceptor) and `user_id`
757
914
  * (JWT) server-side; the payload carries neither, and `CreateOrderDto` has no
758
915
  * such fields to carry them in. The request reaches that guarded route
@@ -780,8 +937,31 @@ interface ShipmentTrackingView {
780
937
  statusLabel: string | null;
781
938
  events: OrderShipmentSummary["events"];
782
939
  }
940
+ /**
941
+ * Builds the shipment details to show for an order: carrier, tracking number,
942
+ * tracking link, status and events. Uses the order's `shipment` when the API
943
+ * sends one and falls back to the order's carrier and tracking fields for an
944
+ * older API.
945
+ *
946
+ * @param order - The order to read.
947
+ * @returns The shipment view, or `null` when there is nothing to show.
948
+ */
783
949
  declare function deriveShipmentTracking(order: Order): ShipmentTrackingView | null;
950
+ /**
951
+ * Tells whether the shopper may still cancel the order. Follows the API's
952
+ * `can_cancel` flag when present, else the order status.
953
+ *
954
+ * @param order - The order to check.
955
+ * @returns `true` when the order can be cancelled.
956
+ */
784
957
  declare function canCustomerCancel(order: Order): boolean;
958
+ /**
959
+ * Tells whether the order's shipment has been handed to a carrier and is not
960
+ * cancelled, failed or returned.
961
+ *
962
+ * @param order - The order to check.
963
+ * @returns `true` while the shipment is with a carrier.
964
+ */
785
965
  declare function isHandedToCarrier(order: Order): boolean;
786
966
  /**
787
967
  * True only for a carrier-booked shipment. The API also sends `order.shipment`
@@ -842,58 +1022,20 @@ interface PromotionDescriptionData {
842
1022
  */
843
1023
  declare function getPromotionDescription(promotion: PromotionDescriptionData, locale?: string, currency?: string): string;
844
1024
 
845
- declare const sdk: {
846
- products: _ecomweb_sdk.ProductsApi;
847
- collections: _ecomweb_sdk.CollectionsApi;
848
- categories: _ecomweb_sdk.CategoriesApi;
849
- cart: _ecomweb_sdk.CartApi;
850
- orders: _ecomweb_sdk.OrdersApi;
851
- blog: _ecomweb_sdk.BlogApi;
852
- stores: _ecomweb_sdk.StoresApi;
853
- themes: _ecomweb_sdk.ThemesApi;
854
- metaobjects: _ecomweb_sdk.MetaobjectsApi;
855
- search: _ecomweb_sdk.SearchApi;
856
- shipping: _ecomweb_sdk.ShippingApi;
857
- promotions: _ecomweb_sdk.PromotionsApi;
858
- paymentMethods: _ecomweb_sdk.PaymentMethodsApi;
859
- payments: _ecomweb_sdk.PaymentsApi;
860
- reviews: _ecomweb_sdk.ReviewsApi;
861
- customers: _ecomweb_sdk.CustomersApi;
862
- addresses: _ecomweb_sdk.AddressesApi;
863
- contentPages: _ecomweb_sdk.ContentPagesApi;
864
- menus: _ecomweb_sdk.MenusApi;
865
- redirects: _ecomweb_sdk.RedirectsApi;
866
- };
1025
+ declare const sdk: EcomwebSdk;
867
1026
  /**
868
- * SDK bound to one store, whose authenticated modules (cart, orders, blog
869
- * comments, customers, addresses) go through the same-origin proxy route so the
870
- * httpOnly session cookie can be turned into a bearer token server-side.
1027
+ * SDK bound to one store, for the browser. Public calls go straight to the
1028
+ * API with the publishable key; every private call (cart, orders, payments,
1029
+ * customers, addresses, shopper-side blog, review and metaobject calls, rate
1030
+ * calculation, promotion validation) goes to the same-origin proxy at
1031
+ * `/store/<ref>/api/backend` (`/api/backend` on a single-store site), which
1032
+ * adds the storefront secret key and turns the httpOnly session cookie into a
1033
+ * bearer token. The secret key never reaches the browser.
871
1034
  *
872
1035
  * Memoised per store so the returned object is referentially stable and safe to
873
1036
  * use in a React dependency array.
874
1037
  */
875
- declare function createStoreSdk(storeRef: string): {
876
- products: _ecomweb_sdk.ProductsApi;
877
- collections: _ecomweb_sdk.CollectionsApi;
878
- categories: _ecomweb_sdk.CategoriesApi;
879
- cart: _ecomweb_sdk.CartApi;
880
- orders: _ecomweb_sdk.OrdersApi;
881
- blog: _ecomweb_sdk.BlogApi;
882
- stores: _ecomweb_sdk.StoresApi;
883
- themes: _ecomweb_sdk.ThemesApi;
884
- metaobjects: _ecomweb_sdk.MetaobjectsApi;
885
- search: _ecomweb_sdk.SearchApi;
886
- shipping: _ecomweb_sdk.ShippingApi;
887
- promotions: _ecomweb_sdk.PromotionsApi;
888
- paymentMethods: _ecomweb_sdk.PaymentMethodsApi;
889
- payments: _ecomweb_sdk.PaymentsApi;
890
- reviews: _ecomweb_sdk.ReviewsApi;
891
- customers: _ecomweb_sdk.CustomersApi;
892
- addresses: _ecomweb_sdk.AddressesApi;
893
- contentPages: _ecomweb_sdk.ContentPagesApi;
894
- menus: _ecomweb_sdk.MenusApi;
895
- redirects: _ecomweb_sdk.RedirectsApi;
896
- };
1038
+ declare function createStoreSdk(storeRef: string): EcomwebServerSdk;
897
1039
 
898
1040
  /**
899
1041
  * Renders a shipping option's price for display: the free label when the
@@ -931,11 +1073,35 @@ type Fetcher = (storeRef: string, query: {
931
1073
  level?: number;
932
1074
  parent_code?: string;
933
1075
  }) => Promise<LocationAreasResponse>;
1076
+ /**
1077
+ * Loads the wards of a province. Results are cached per store and province,
1078
+ * and a failed request is not cached.
1079
+ *
1080
+ * @param storeRef - The store's ref.
1081
+ * @param provinceCode - The province to list wards for.
1082
+ * @param fetcher - Replaces the request that loads the areas (tests).
1083
+ * @returns The wards, or an empty list when `provinceCode` is empty.
1084
+ */
934
1085
  declare function loadWards(storeRef: string, provinceCode: string | undefined, fetcher?: Fetcher): Promise<LocationArea[]>;
1086
+ /**
1087
+ * Loads the store's provinces for an address form. Needs no provider; the
1088
+ * list is cached per store.
1089
+ *
1090
+ * @param storeRef - The store's ref.
1091
+ * @returns `provinces`, the list loaded so far, and `loading`, `true` until the first request ends.
1092
+ */
935
1093
  declare function useProvinces(storeRef: string): {
936
1094
  provinces: LocationArea[];
937
1095
  loading: boolean;
938
1096
  };
1097
+ /**
1098
+ * Loads the wards of the selected province for an address form. The list is
1099
+ * emptied while a new province loads. Needs no provider.
1100
+ *
1101
+ * @param storeRef - The store's ref.
1102
+ * @param provinceCode - The selected province; wards load only once it is set.
1103
+ * @returns `wards`, the list for that province, and `loading`.
1104
+ */
939
1105
  declare function useWards(storeRef: string, provinceCode: string | undefined): {
940
1106
  wards: LocationArea[];
941
1107
  loading: boolean;
@@ -1011,7 +1177,21 @@ interface ImageTransformOptions {
1011
1177
  * - A bare object path is resolved within `defaultBucket`.
1012
1178
  */
1013
1179
  declare function resolveTransformedImageUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions, defaultBucket?: "public-cdn"): string | null;
1180
+ /**
1181
+ * Builds the URL of a product image, optionally resized.
1182
+ *
1183
+ * @param imagePathOrUrl - The image's stored path or full URL.
1184
+ * @param opts - Size and format options.
1185
+ * @returns The image URL, or `null` when there is no image.
1186
+ */
1014
1187
  declare function resolveTransformedProductImageUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions): string | null;
1188
+ /**
1189
+ * Builds the URL of a store logo, optionally resized.
1190
+ *
1191
+ * @param imagePathOrUrl - The logo's stored path or full URL.
1192
+ * @param opts - Size and format options.
1193
+ * @returns The logo URL, or `null` when there is no logo.
1194
+ */
1015
1195
  declare function resolveTransformedStoreLogoUrl(imagePathOrUrl: string | null | undefined, opts?: ImageTransformOptions): string | null;
1016
1196
  /**
1017
1197
  * Null-safe wrapper for use directly in `src={...}`.
@@ -1021,10 +1201,34 @@ declare function resolveTransformedStoreLogoUrl(imagePathOrUrl: string | null |
1021
1201
  */
1022
1202
  declare function resolveAssetSrc(url: string | null | undefined, opts?: ImageTransformOptions): string;
1023
1203
 
1204
+ /**
1205
+ * Finds the ref of the store a request serves. In single-store mode it is
1206
+ * `ECOMWEB_STORE_REF`; in multi-store mode it comes from the route's
1207
+ * `storeRef` param.
1208
+ *
1209
+ * @param params - The page's `params` promise; only read in multi-store mode.
1210
+ * @returns The store ref.
1211
+ */
1024
1212
  declare function resolveStoreRef(params?: Promise<{
1025
1213
  storeRef?: string;
1026
1214
  }>): Promise<string>;
1215
+ /**
1216
+ * Builds a page path for a store: `/store/<ref>/…` in multi-store mode, the
1217
+ * path from the site root in single-store mode.
1218
+ *
1219
+ * @param storeRef - The store's ref.
1220
+ * @param path - Path under the store, such as `/cart`; defaults to its home.
1221
+ * @returns The path to link to.
1222
+ */
1027
1223
  declare function storePath(storeRef: string, path?: string): string;
1224
+ /**
1225
+ * Builds the path of the storefront's own API routes for a store:
1226
+ * `/store/<ref>/api/…` in multi-store mode, `/api/…` in single-store mode.
1227
+ *
1228
+ * @param storeRef - The store's ref.
1229
+ * @param subpath - Route under the API prefix, such as `auth/session`.
1230
+ * @returns The path to request.
1231
+ */
1028
1232
  declare function storeApiPath(storeRef: string, subpath: string): string;
1029
1233
 
1030
1234
  /**
@@ -1071,8 +1275,23 @@ interface BasicSettings {
1071
1275
  policyLink: string | null;
1072
1276
  };
1073
1277
  }
1074
- /** @deprecated Read `store.settings.legal_links` directly. */
1278
+ /**
1279
+ * Reads the store's terms and privacy links from its settings.
1280
+ *
1281
+ * @param store - A store with a `settings` object.
1282
+ * @returns The links, `null` where the store sets none.
1283
+ * @deprecated Read `store.settings.legal_links` directly.
1284
+ */
1075
1285
  declare function readBasicSettings(store: StoreLike): BasicSettings;
1286
+ /**
1287
+ * Turns a legal link into the URL to put in an anchor. A full URL is kept; a
1288
+ * path is made store-relative.
1289
+ *
1290
+ * @param link - The store's own link, or `null`.
1291
+ * @param fallbackPath - Path to use when the store sets no link.
1292
+ * @param toStoreUrl - Builds a store URL from a path, for example with {@link storePath}.
1293
+ * @returns The URL, or `#` when there is neither link nor fallback.
1294
+ */
1076
1295
  declare function resolveLegalHref(link: string | null, fallbackPath: string | null, toStoreUrl: (path: string) => string): string;
1077
1296
 
1078
1297
  interface ThemeSettingsContextValue {
@@ -1087,6 +1306,14 @@ declare function ThemeSettingsProvider({ themeId, themeKey, settings, children,
1087
1306
  }): react_jsx_runtime.JSX.Element;
1088
1307
  /** Pass the theme's settings type: `useThemeSettings<MyThemeSettings>()`. */
1089
1308
  declare function useThemeSettings<T = ThemeValues>(): T;
1309
+ /**
1310
+ * The id of the theme rendering the store.
1311
+ *
1312
+ * Must run under the theme settings provider the storefront's layout sets up.
1313
+ *
1314
+ * @returns The theme id.
1315
+ * @throws When used outside that provider.
1316
+ */
1090
1317
  declare function useThemeId(): string;
1091
1318
  /** The theme id, or null outside a ThemeSettingsProvider (e.g. a store 404). */
1092
1319
  declare function useOptionalThemeId(): string | null;
@@ -1147,6 +1374,13 @@ declare function RichText({ value }: RichTextProps): ReactElement | null;
1147
1374
 
1148
1375
  /** A `:root{…}` rule from a theme's custom properties; null when empty. */
1149
1376
  declare function themeStyleCss(vars: Record<string, string> | null | undefined): string | null;
1377
+ /**
1378
+ * Renders a theme's CSS custom properties as a `:root` style tag. Names that
1379
+ * are not `--custom-properties` and unsafe values are dropped.
1380
+ *
1381
+ * @param props.vars - The properties by name, for example from the theme's `styles` function.
1382
+ * @returns A `<style>` element, or `null` when no property is usable.
1383
+ */
1150
1384
  declare function ThemeStyle({ vars, }: {
1151
1385
  vars: Record<string, string> | null | undefined;
1152
1386
  }): react_jsx_runtime.JSX.Element | null;
@@ -1168,6 +1402,14 @@ declare function ThemePreviewBridge({ onRefresh }: {
1168
1402
  onRefresh: () => void;
1169
1403
  }): null;
1170
1404
 
1405
+ /**
1406
+ * Loads a store's configuration, settings and embedded scripts. Server-side;
1407
+ * calls with the same ref during one request share a single fetch.
1408
+ *
1409
+ * @param storeRef - The store's ref.
1410
+ * @param options - Accepted for compatibility and ignored; the full configuration is always fetched.
1411
+ * @returns The store, or `null` when it does not exist.
1412
+ */
1171
1413
  declare const getCachedStore: (storeRef: string, options?: {
1172
1414
  includeConfig?: boolean;
1173
1415
  includeSettings?: boolean;
@@ -1264,8 +1506,28 @@ declare const STORE_COMING_SOON_REDIRECT_PATH = "/coming-soon";
1264
1506
  * - Honors `NEXT_PUBLIC_LOG_LEVEL` (client) or `LOG_LEVEL` (server)
1265
1507
  */
1266
1508
  type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
1509
+ /**
1510
+ * Reads the configured log level: `NEXT_PUBLIC_LOG_LEVEL` in the browser or
1511
+ * `LOG_LEVEL` on the server, else `warn` in production and `debug` in
1512
+ * development.
1513
+ *
1514
+ * @returns The active log level.
1515
+ */
1267
1516
  declare function getLogLevel(): LogLevel;
1517
+ /**
1518
+ * Tells whether a message of one level is shown at the current level.
1519
+ *
1520
+ * @param currentLevel - The level the app is configured for.
1521
+ * @param messageLevel - The level of the message to print.
1522
+ * @returns `true` when the message should be printed; always `false` when the current level is `silent`.
1523
+ */
1268
1524
  declare function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel): boolean;
1525
+ /**
1526
+ * Silences the `console` methods below the log level by replacing them.
1527
+ * Calling it again with the same level does nothing.
1528
+ *
1529
+ * @param level - The level to apply; defaults to {@link getLogLevel}.
1530
+ */
1269
1531
  declare function applyConsoleFilter(level?: LogLevel): void;
1270
1532
 
1271
1533
  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":["// @ecomweb/storefront-kit: client-safe hooks, providers and helpers.\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":"AACA,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":[]}
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 type { EcomwebSdk, EcomwebServerSdk } from \"@ecomweb/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;AAEpC;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":[]}
@@ -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;AAEO,SAAS,cAAwB;AACtC,QAAM,WACJ,aAAa,EAAE,YAAY,eAAe;AAE5C,MAAI,YAAY,YAAY,WAAY,QAAO;AAE/C,SAAO,QAAQ,IAAI,aAAa,eAAe,SAAS;AAC1D;AAEO,SAAS,UAAU,cAAwB,cAAwB;AACxE,SACE,WAAW,YAAY,KAAK,WAAW,YAAY,KACnD,iBAAiB;AAErB;AAOA,IAAI,eAAgC;AAC7B,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":[]}
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":[]}