@ecomweb/storefront-kit 0.6.0 → 0.10.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.
- package/README.md +28 -1
- package/dist/api/proxy.js +5 -1
- package/dist/api/proxy.js.map +1 -1
- package/dist/api/server-client.js +7 -4
- package/dist/api/server-client.js.map +1 -1
- package/dist/auth/cookies.js +51 -33
- package/dist/auth/cookies.js.map +1 -1
- package/dist/auth/error-copy.js +5 -1
- package/dist/auth/error-copy.js.map +1 -1
- package/dist/auth/route-handlers.js +2 -2
- package/dist/auth/route-handlers.js.map +1 -1
- package/dist/auth/session-refresh.js +11 -5
- package/dist/auth/session-refresh.js.map +1 -1
- package/dist/auth/session.js +8 -4
- package/dist/auth/session.js.map +1 -1
- package/dist/checkout/get-payment-state.js.map +1 -1
- package/dist/checkout/initiate-gateway-payment.js.map +1 -1
- package/dist/checkout/order-handoff.js +10 -1
- package/dist/checkout/order-handoff.js.map +1 -1
- package/dist/checkout/quote-changed.js +16 -0
- package/dist/checkout/quote-changed.js.map +1 -0
- package/dist/checkout/use-checkout.js +44 -7
- package/dist/checkout/use-checkout.js.map +1 -1
- package/dist/config/schema.js +12 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/server.js +9 -2
- package/dist/config/server.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/index.d.ts +167 -26
- package/dist/index.js +37 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/create-storefront-middleware.js +62 -26
- package/dist/middleware/create-storefront-middleware.js.map +1 -1
- package/dist/middleware.d.ts +2 -2
- package/dist/{mode-YNx2aOtQ.d.ts → mode-Lm9t4qzX.d.ts} +1 -1
- package/dist/orders/index.js +17 -1
- package/dist/orders/index.js.map +1 -1
- package/dist/orders/shipment-tracking.js +80 -0
- package/dist/orders/shipment-tracking.js.map +1 -0
- package/dist/promotions/use-promotion-validation.js +19 -16
- package/dist/promotions/use-promotion-validation.js.map +1 -1
- package/dist/{schema-Tc0qRs-Q.d.ts → schema-Dg0ZflMW.d.ts} +1 -0
- package/dist/server.d.ts +8 -2
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/dist/shipping/format-shipping-option.js +28 -0
- package/dist/shipping/format-shipping-option.js.map +1 -1
- package/dist/shipping/messages.js +2 -0
- package/dist/shipping/messages.js.map +1 -1
- package/dist/shipping/option-id.js +7 -0
- package/dist/shipping/option-id.js.map +1 -0
- package/dist/shipping/shipping-calculation-reducer.js +61 -10
- package/dist/shipping/shipping-calculation-reducer.js.map +1 -1
- package/dist/shipping/use-shipping-calculation.js +38 -5
- package/dist/shipping/use-shipping-calculation.js.map +1 -1
- package/dist/stores/get-store-by-host.js +41 -6
- package/dist/stores/get-store-by-host.js.map +1 -1
- package/dist/stores/store-subdomain.js +25 -0
- package/dist/stores/store-subdomain.js.map +1 -0
- package/dist/stores/store-traffic.js +50 -0
- package/dist/stores/store-traffic.js.map +1 -0
- package/dist/stores/ttl-cache.js +34 -0
- package/dist/stores/ttl-cache.js.map +1 -0
- package/dist/theme/define.js.map +1 -1
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/preview-bridge.js +33 -0
- package/dist/theme/preview-bridge.js.map +1 -0
- package/dist/theme/preview-cookie.js +13 -6
- package/dist/theme/preview-cookie.js.map +1 -1
- package/dist/theme/preview-host.js +7 -0
- package/dist/theme/preview-host.js.map +1 -0
- package/dist/theme/read-preview-host.js +10 -0
- package/dist/theme/read-preview-host.js.map +1 -0
- package/dist/theme/read-preview-token.js +5 -3
- package/dist/theme/read-preview-token.js.map +1 -1
- package/dist/theme/settings-context.js +14 -1
- package/dist/theme/settings-context.js.map +1 -1
- package/dist/theme.d.ts +65 -5
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ 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, OrderStatus, Order, CreateOrderRequest, 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, LocationAreasResponse, LocationArea, StoreConfig, ThemeValues, WithMetafields, StorefrontMetafields, ResolvedMetaobjectRef, ResolvedMetaobjectStub, StorefrontMetaobjectEntry, MetaobjectListParams, MetaobjectListResult, RichTextRoot } from '@ecomweb/sdk';
|
|
6
6
|
import currencyJs from 'currency.js';
|
|
7
7
|
import { AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
8
|
-
export { AnyThemeDefinition, HomePageSlotProps, LayoutSlotProps, ThemeComponents, ThemeDefinition, ThemeInfo, ThemeSlot, ThemeSlotName, ThemeSlotProps, defineSchema, defineTheme } from './theme.js';
|
|
8
|
+
export { AnyThemeDefinition, BlogIndexSlotProps, BlogPostSlotProps, CollectionPageSlotProps, CollectionSearchParams, ContentPageSlotProps, HomePageSlotProps, LayoutSlotProps, NotFoundProps, ProductCardProps, ProductPageSlotProps, ThemeClientComponents, ThemeComponents, ThemeDefinition, ThemeInfo, ThemeSlot, ThemeSlotName, ThemeSlotProps, defineSchema, defineTheme } from './theme.js';
|
|
9
9
|
import { Metadata } from 'next';
|
|
10
10
|
|
|
11
11
|
type NoticeKind = "success" | "error" | "info";
|
|
@@ -73,6 +73,50 @@ interface CartItem {
|
|
|
73
73
|
bestPromotion?: any;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* What the thank-you page shows of the order (contact, address, methods,
|
|
78
|
+
* lines, money), built by the storefront when it places the order. Like the
|
|
79
|
+
* rest of the handoff it stays in the shopper's own browser.
|
|
80
|
+
*/
|
|
81
|
+
interface OrderHandoffSummary {
|
|
82
|
+
customer_name: string;
|
|
83
|
+
phone: string;
|
|
84
|
+
email: string | null;
|
|
85
|
+
/** The delivery address as one display line. */
|
|
86
|
+
address: string;
|
|
87
|
+
shipping_method: string | null;
|
|
88
|
+
shipping_fee: number | null;
|
|
89
|
+
payment_label: string;
|
|
90
|
+
items: {
|
|
91
|
+
name: string;
|
|
92
|
+
variant: string | null;
|
|
93
|
+
quantity: number;
|
|
94
|
+
/** Unit price. */
|
|
95
|
+
price: number;
|
|
96
|
+
image: string | null;
|
|
97
|
+
}[];
|
|
98
|
+
subtotal: number;
|
|
99
|
+
discount: number;
|
|
100
|
+
}
|
|
101
|
+
interface OrderHandoff {
|
|
102
|
+
order_code: string;
|
|
103
|
+
/** `cod`, `bank_transfer`, or a gateway code. */
|
|
104
|
+
payment_method: string;
|
|
105
|
+
/** Non-null only for gateway-backed methods. */
|
|
106
|
+
provider_code: string | null;
|
|
107
|
+
total: number;
|
|
108
|
+
currency_code: string;
|
|
109
|
+
/** Absent for gateway returns and older handoffs. */
|
|
110
|
+
summary?: OrderHandoffSummary | null;
|
|
111
|
+
written_at: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the handoff only if it is present, well-formed, fresh, and for the
|
|
115
|
+
* order being shown. Any mismatch yields null: showing one order's amount on
|
|
116
|
+
* another order's screen would be worse than showing no amount at all.
|
|
117
|
+
*/
|
|
118
|
+
declare function readOrderHandoff(order_code: string | null): OrderHandoff | null;
|
|
119
|
+
|
|
76
120
|
/** What the shopper entered; the app owns the form and its validation. */
|
|
77
121
|
interface PlaceOrderInput {
|
|
78
122
|
fullName: string;
|
|
@@ -86,6 +130,11 @@ interface PlaceOrderInput {
|
|
|
86
130
|
notes?: string;
|
|
87
131
|
/** A `payment_method` code from `paymentMethods`. */
|
|
88
132
|
paymentMethod: string;
|
|
133
|
+
/**
|
|
134
|
+
* What the thank-you page shows of the order; stored with the handoff in
|
|
135
|
+
* this browser only, never sent to the API.
|
|
136
|
+
*/
|
|
137
|
+
summary?: OrderHandoffSummary;
|
|
89
138
|
}
|
|
90
139
|
interface PlacedOrder {
|
|
91
140
|
order_code: string;
|
|
@@ -98,7 +147,13 @@ interface PlacedOrder {
|
|
|
98
147
|
* this again instead of creating a second order.
|
|
99
148
|
* - success: an offline-payment order; show its confirmation.
|
|
100
149
|
* - stock_issues: nothing was placed; `issues` is copy keyed by cart line id.
|
|
101
|
-
* - error: nothing was placed.
|
|
150
|
+
* - error: nothing was placed. `code` is the API's error code when it sent
|
|
151
|
+
* one; pass it to `errorCopy`. On ORDER_PROMOTION_NOT_APPLICABLE the applied
|
|
152
|
+
* code has already been removed, so the shopper sees the real total before
|
|
153
|
+
* placing again.
|
|
154
|
+
* - quote_changed: nothing was placed; the shipping options were replaced with
|
|
155
|
+
* the API's new prices and the selection kept where possible; show
|
|
156
|
+
* `SHIPPING_MESSAGES.quoteChanged` and let the shopper place again.
|
|
102
157
|
* - busy: an earlier placeOrder is still running; this call did nothing.
|
|
103
158
|
*/
|
|
104
159
|
type PlaceOrderResult = {
|
|
@@ -115,6 +170,9 @@ type PlaceOrderResult = {
|
|
|
115
170
|
} | {
|
|
116
171
|
kind: "error";
|
|
117
172
|
message: string;
|
|
173
|
+
code?: string;
|
|
174
|
+
} | {
|
|
175
|
+
kind: "quote_changed";
|
|
118
176
|
} | {
|
|
119
177
|
kind: "busy";
|
|
120
178
|
};
|
|
@@ -122,6 +180,11 @@ interface UseCheckoutOptions {
|
|
|
122
180
|
/** The address fields shipping is quoted against (codes, may be empty). */
|
|
123
181
|
province: string;
|
|
124
182
|
ward: string;
|
|
183
|
+
/**
|
|
184
|
+
* Ask the API for carrier-quoted shipping options too. Off by default;
|
|
185
|
+
* passed to `useShippingCalculation`.
|
|
186
|
+
*/
|
|
187
|
+
includeCarrierOptions?: boolean;
|
|
125
188
|
/** Leaves for the payment provider; defaults to a full-page navigation. */
|
|
126
189
|
navigateToGateway?: (url: string) => void;
|
|
127
190
|
}
|
|
@@ -130,7 +193,7 @@ interface UseCheckoutOptions {
|
|
|
130
193
|
* totals, placing the order and the payment-provider hand-off. The app
|
|
131
194
|
* renders the form and decides what to show for each PlaceOrderResult.
|
|
132
195
|
*/
|
|
133
|
-
declare function useCheckout({ province, ward, navigateToGateway, }: UseCheckoutOptions): {
|
|
196
|
+
declare function useCheckout({ province, ward, includeCarrierOptions, navigateToGateway, }: UseCheckoutOptions): {
|
|
134
197
|
items: CartItem[];
|
|
135
198
|
isCartLoading: boolean;
|
|
136
199
|
paymentMethods: StorePaymentMethod[];
|
|
@@ -142,7 +205,11 @@ declare function useCheckout({ province, ward, navigateToGateway, }: UseCheckout
|
|
|
142
205
|
isCalculating: boolean;
|
|
143
206
|
hasCalculated: boolean;
|
|
144
207
|
calculationFailed: boolean;
|
|
208
|
+
/** @deprecated Use selectOption. */
|
|
145
209
|
selectRate: (rateId: number) => void;
|
|
210
|
+
selectedOptionId: string | null;
|
|
211
|
+
selectedOption: _ecomweb_sdk.ShippingOption | null;
|
|
212
|
+
selectOption: (optionId: string) => void;
|
|
146
213
|
retry: () => Promise<void>;
|
|
147
214
|
};
|
|
148
215
|
promotion: {
|
|
@@ -178,23 +245,6 @@ declare function useCheckout({ province, ward, navigateToGateway, }: UseCheckout
|
|
|
178
245
|
retryPaymentRedirect: () => Promise<PlaceOrderResult>;
|
|
179
246
|
};
|
|
180
247
|
|
|
181
|
-
interface OrderHandoff {
|
|
182
|
-
order_code: string;
|
|
183
|
-
/** `cod`, `bank_transfer`, or a gateway code. */
|
|
184
|
-
payment_method: string;
|
|
185
|
-
/** Non-null only for gateway-backed methods. */
|
|
186
|
-
provider_code: string | null;
|
|
187
|
-
total: number;
|
|
188
|
-
currency_code: string;
|
|
189
|
-
written_at: number;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Returns the handoff only if it is present, well-formed, fresh, and for the
|
|
193
|
-
* order being shown. Any mismatch yields null: showing one order's amount on
|
|
194
|
-
* another order's screen would be worse than showing no amount at all.
|
|
195
|
-
*/
|
|
196
|
-
declare function readOrderHandoff(order_code: string | null): OrderHandoff | null;
|
|
197
|
-
|
|
198
248
|
/**
|
|
199
249
|
* Which success screen an order gets.
|
|
200
250
|
*
|
|
@@ -584,7 +634,7 @@ declare function pollPaymentState(options: PollPaymentStateOptions): Promise<Pol
|
|
|
584
634
|
* TEMPORARY adapter standing in for `sdk.payments.getPaymentState`.
|
|
585
635
|
*
|
|
586
636
|
* `sdk.payments` was added by this plan's Task 2
|
|
587
|
-
* (`ecomweb-
|
|
637
|
+
* (`ecomweb-contracts` branch `feat/payment-client-methods`, commit `58c2c76`),
|
|
588
638
|
* but that SDK PR is not yet merged to `main`, and this repo's lockfile
|
|
589
639
|
* pins an older `@ecomweb/sdk` commit that has no `payments` module at all
|
|
590
640
|
* — see `lib/checkout/initiate-gateway-payment.ts` for the full story
|
|
@@ -604,6 +654,21 @@ declare function pollPaymentState(options: PollPaymentStateOptions): Promise<Pol
|
|
|
604
654
|
*/
|
|
605
655
|
declare function getPaymentState(storeRef: string, order_code: string): Promise<PaymentStateResult>;
|
|
606
656
|
|
|
657
|
+
/**
|
|
658
|
+
* The options the API now offers, read off a 409 SHIPPING_QUOTE_CHANGED.
|
|
659
|
+
* Null for any other error, or when `details.options` is missing, empty or
|
|
660
|
+
* has an entry without a numeric `rate_id` and `amount`; the caller then
|
|
661
|
+
* treats it as a plain error. Duck-typed like `insufficientItemsFrom`.
|
|
662
|
+
*/
|
|
663
|
+
declare function quoteChangedOptionsFrom(error: unknown): ShippingOption[] | null;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* The stable identity of a shipping option. Carrier-backed rates can offer
|
|
667
|
+
* several options under one `rate_id`, so the API sends `option_id`; older
|
|
668
|
+
* APIs don't, and `rate_id` alone is unique there.
|
|
669
|
+
*/
|
|
670
|
+
declare function optionIdOf(option: ShippingOption): string;
|
|
671
|
+
|
|
607
672
|
/**
|
|
608
673
|
* Turns the API's 409 INSUFFICIENT_INVENTORY into per-line shopper copy.
|
|
609
674
|
*
|
|
@@ -637,6 +702,44 @@ declare const publicOrdersApi: {
|
|
|
637
702
|
createStoreOrder(storeRef: string, data: Omit<CreateOrderRequest, "store_id">, isAuth: boolean): Promise<OrderWithItems>;
|
|
638
703
|
};
|
|
639
704
|
|
|
705
|
+
/** The API's SHIPMENT_STATUS_LABEL_VI, copied exactly so badge and events agree. */
|
|
706
|
+
declare const SHIPMENT_STATUS_LABELS: Record<ShipmentStatus, string>;
|
|
707
|
+
declare const TRACKING_MESSAGES: {
|
|
708
|
+
readonly title: "Vận chuyển";
|
|
709
|
+
readonly trackingNumber: "Mã vận đơn";
|
|
710
|
+
readonly trackLink: "Theo dõi đơn hàng";
|
|
711
|
+
readonly handedToCarrier: "Đơn đã được giao cho hãng vận chuyển";
|
|
712
|
+
readonly noEvents: "Chưa có cập nhật từ hãng vận chuyển";
|
|
713
|
+
readonly eventFallback: "Cập nhật vận chuyển";
|
|
714
|
+
};
|
|
715
|
+
interface ShipmentTrackingView {
|
|
716
|
+
carrierName: string | null;
|
|
717
|
+
carrierLogoUrl: string | null;
|
|
718
|
+
serviceName: string | null;
|
|
719
|
+
trackingNumber: string | null;
|
|
720
|
+
trackLink: string | null;
|
|
721
|
+
statusLabel: string | null;
|
|
722
|
+
events: OrderShipmentSummary["events"];
|
|
723
|
+
}
|
|
724
|
+
declare function deriveShipmentTracking(order: Order): ShipmentTrackingView | null;
|
|
725
|
+
declare function canCustomerCancel(order: Order): boolean;
|
|
726
|
+
declare function isHandedToCarrier(order: Order): boolean;
|
|
727
|
+
/**
|
|
728
|
+
* True only for a carrier-booked shipment. The API also sends `order.shipment`
|
|
729
|
+
* for a manual shipment (carrier and tracking number typed by the merchant),
|
|
730
|
+
* with `status: null` and no events; that one has no carrier timeline to show.
|
|
731
|
+
*/
|
|
732
|
+
declare function isCarrierShipment(order: Order): boolean;
|
|
733
|
+
/**
|
|
734
|
+
* The text of one tracking event. A blank label falls back to the event's own
|
|
735
|
+
* status label when it carries a known one, else to neutral copy -- never the
|
|
736
|
+
* shipment's current status, which is not what that event reported.
|
|
737
|
+
*/
|
|
738
|
+
declare function shipmentEventLabel(event: {
|
|
739
|
+
label?: string | null;
|
|
740
|
+
status?: string | null;
|
|
741
|
+
}): string;
|
|
742
|
+
|
|
640
743
|
type CreatedOrder = Awaited<ReturnType<typeof publicOrdersApi.createStoreOrder>>;
|
|
641
744
|
interface OrderSuccessInfo {
|
|
642
745
|
order: CreatedOrder;
|
|
@@ -691,7 +794,6 @@ declare const sdk: {
|
|
|
691
794
|
themes: _ecomweb_sdk.ThemesApi;
|
|
692
795
|
metaobjects: _ecomweb_sdk.MetaobjectsApi;
|
|
693
796
|
search: _ecomweb_sdk.SearchApi;
|
|
694
|
-
banners: _ecomweb_sdk.BannersApi;
|
|
695
797
|
shipping: _ecomweb_sdk.ShippingApi;
|
|
696
798
|
promotions: _ecomweb_sdk.PromotionsApi;
|
|
697
799
|
paymentMethods: _ecomweb_sdk.PaymentMethodsApi;
|
|
@@ -722,7 +824,6 @@ declare function createStoreSdk(storeRef: string): {
|
|
|
722
824
|
themes: _ecomweb_sdk.ThemesApi;
|
|
723
825
|
metaobjects: _ecomweb_sdk.MetaobjectsApi;
|
|
724
826
|
search: _ecomweb_sdk.SearchApi;
|
|
725
|
-
banners: _ecomweb_sdk.BannersApi;
|
|
726
827
|
shipping: _ecomweb_sdk.ShippingApi;
|
|
727
828
|
promotions: _ecomweb_sdk.PromotionsApi;
|
|
728
829
|
paymentMethods: _ecomweb_sdk.PaymentMethodsApi;
|
|
@@ -744,6 +845,18 @@ declare function createStoreSdk(storeRef: string): {
|
|
|
744
845
|
* plain vitest spec.
|
|
745
846
|
*/
|
|
746
847
|
declare function formatShippingAmount(amount: number, freeLabel: string, locale: string, currency: SupportedCurrency | string): string;
|
|
848
|
+
interface ShippingOptionDisplay {
|
|
849
|
+
title: string;
|
|
850
|
+
carrierName: string | null;
|
|
851
|
+
carrierLogoUrl: string | null;
|
|
852
|
+
eta: string | null;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* What an option row shows: title, carrier (when carrier-quoted) and an ETA.
|
|
856
|
+
* The carrier's own label wins over the fixed-rate day range. The carrier
|
|
857
|
+
* line names the service too: one carrier can offer several at one price.
|
|
858
|
+
*/
|
|
859
|
+
declare function describeShippingOption(option: ShippingOption): ShippingOptionDisplay;
|
|
747
860
|
|
|
748
861
|
/**
|
|
749
862
|
* Location data is fetched in two steps rather than all at once: the 34
|
|
@@ -796,6 +909,8 @@ declare const SHIPPING_MESSAGES: Readonly<{
|
|
|
796
909
|
failedHint: "Kết nối có thể đang gián đoạn. Vui lòng thử lại.";
|
|
797
910
|
retry: "Thử lại";
|
|
798
911
|
free: "Miễn phí";
|
|
912
|
+
quoteChanged: "Phí vận chuyển đã thay đổi";
|
|
913
|
+
quoteChangedHint: "Vui lòng kiểm tra lại phí vận chuyển mới rồi đặt hàng.";
|
|
799
914
|
estimate: "Dự kiến giao: {min} đến {max} ngày";
|
|
800
915
|
}>;
|
|
801
916
|
/** Fills in the `{min}`/`{max}` placeholders in `SHIPPING_MESSAGES.estimate`. */
|
|
@@ -903,15 +1018,24 @@ declare function resolveLegalHref(link: string | null, fallbackPath: string | nu
|
|
|
903
1018
|
|
|
904
1019
|
interface ThemeSettingsContextValue {
|
|
905
1020
|
themeId: string;
|
|
1021
|
+
/** The registry key of the code rendering, e.g. "meridian@1" (theme majors). */
|
|
1022
|
+
themeKey?: string;
|
|
906
1023
|
settings: ThemeValues;
|
|
907
1024
|
}
|
|
908
1025
|
/** The published (or previewed) theme's resolved settings, for client components. */
|
|
909
|
-
declare function ThemeSettingsProvider({ themeId, settings, children, }: ThemeSettingsContextValue & {
|
|
1026
|
+
declare function ThemeSettingsProvider({ themeId, themeKey, settings, children, }: ThemeSettingsContextValue & {
|
|
910
1027
|
children: ReactNode;
|
|
911
1028
|
}): react_jsx_runtime.JSX.Element;
|
|
912
1029
|
/** Pass the theme's settings type: `useThemeSettings<MyThemeSettings>()`. */
|
|
913
1030
|
declare function useThemeSettings<T = ThemeValues>(): T;
|
|
914
1031
|
declare function useThemeId(): string;
|
|
1032
|
+
/** The theme id, or null outside a ThemeSettingsProvider (e.g. a store 404). */
|
|
1033
|
+
declare function useOptionalThemeId(): string | null;
|
|
1034
|
+
/**
|
|
1035
|
+
* The registry key of the theme code rendering ("meridian@1"), else its id;
|
|
1036
|
+
* null outside a ThemeSettingsProvider. Client registries look up by it.
|
|
1037
|
+
*/
|
|
1038
|
+
declare function useOptionalThemeKey(): string | null;
|
|
915
1039
|
|
|
916
1040
|
/**
|
|
917
1041
|
* A metafield's resolved value by identifier, e.g.
|
|
@@ -968,6 +1092,23 @@ declare function ThemeStyle({ vars, }: {
|
|
|
968
1092
|
vars: Record<string, string> | null | undefined;
|
|
969
1093
|
}): react_jsx_runtime.JSX.Element | null;
|
|
970
1094
|
|
|
1095
|
+
/** The messages the dashboard's theme editor and its preview frame trade. */
|
|
1096
|
+
declare const THEME_PREVIEW_MESSAGE = "ecomweb:theme-preview";
|
|
1097
|
+
/** Set on <html> while the preview is inside the theme editor's frame. */
|
|
1098
|
+
declare const THEME_PREVIEW_FRAME_ATTR = "data-theme-preview-frame";
|
|
1099
|
+
/**
|
|
1100
|
+
* The storefront side of the theme editor's live preview. Inside the
|
|
1101
|
+
* editor's frame it says it is ready, then calls onRefresh each time the
|
|
1102
|
+
* editor has sent its unsaved values to the API, which the preview token
|
|
1103
|
+
* reads them back from. The app re-renders the page in place (router.refresh:
|
|
1104
|
+
* server components again, scroll and client state kept); routing is the
|
|
1105
|
+
* app's, not the kit's. Only the frame's parent is listened to; outside a
|
|
1106
|
+
* frame it does nothing.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function ThemePreviewBridge({ onRefresh }: {
|
|
1109
|
+
onRefresh: () => void;
|
|
1110
|
+
}): null;
|
|
1111
|
+
|
|
971
1112
|
declare const getCachedStore: (storeRef: string, options?: {
|
|
972
1113
|
includeConfig?: boolean;
|
|
973
1114
|
includeSettings?: boolean;
|
|
@@ -1027,4 +1168,4 @@ declare function getLogLevel(): LogLevel;
|
|
|
1027
1168
|
declare function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel): boolean;
|
|
1028
1169
|
declare function applyConsoleFilter(level?: LogLevel): void;
|
|
1029
1170
|
|
|
1030
|
-
export { type BankAccountView, DEFAULT_REDIRECT, type Notice, type NoticeHandler, type NoticeKind, ORDER_PROGRESS_STEPS, type OrderHandoff, type OrderSuccessInfo, type PaymentConfirmationState, type PlaceOrderInput, type PlaceOrderResult, type PlacedOrder, RichText, type RichTextProps, SHIPPING_MESSAGES, STATUS_OPTIONS, STOCK_ISSUE_TOAST_DESCRIPTION, SUSPENDED_STORE_METADATA, StorefrontKitProvider, type StorefrontKitProviderProps, type SupportedCurrency, ThemeSettingsProvider, ThemeStyle, type UseCheckoutOptions, applyConsoleFilter, buildStoreUrl, createStoreSdk, deriveOrderProgress, errorCopy, errorCopyFor, findProvinceByCodeOrName, findWardByCodeOrName, formatNumber, formatPrice, formatPriceRange, formatPriceWithoutSymbol, formatShippingAmount, formatShippingEstimate, getCachedStore, getDefaultLocale, getLogLevel, getMetaobject, getMetaobjects, getPasswordPolicyHints, getPaymentState, getPromotionDescription, isStoreSuspendedError, loadWards, metafield, metaobjectField, money, pollPaymentState, publicApiClient, readBasicSettings, readOrderHandoff, refFromPathname, resolveAssetSrc, resolveInitialState, resolveLegalHref, resolveStoreRef, resolveTransformedImageUrl, resolveTransformedProductImageUrl, resolveTransformedStoreLogoUrl, safeRedirectPath, sdk, searchTextFor, shouldLog, shouldPollForConfirmation, storeApiPath, storePath, themeStyleCss, unwrap, unwrapOrNull, useAuth, useCart, useCheckout, useNotify, useOptionalStoreId, useOrderLookup, useOrderStatus, useProvinces, usePublicAuthConfig, useStore, useStoreCurrency, useStoreData, useStoreId, useStoreLocale, useThemeId, useThemeSettings, useWards, validatePasswordAgainstPolicy, withSuspendedStoreMetadataFallback };
|
|
1171
|
+
export { type BankAccountView, 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, 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, createStoreSdk, deriveOrderProgress, deriveShipmentTracking, describeShippingOption, errorCopy, errorCopyFor, findProvinceByCodeOrName, findWardByCodeOrName, formatNumber, formatPrice, formatPriceRange, formatPriceWithoutSymbol, formatShippingAmount, formatShippingEstimate, getCachedStore, getDefaultLocale, getLogLevel, getMetaobject, getMetaobjects, getPasswordPolicyHints, getPaymentState, getPromotionDescription, isCarrierShipment, isHandedToCarrier, isStoreSuspendedError, loadWards, metafield, metaobjectField, money, optionIdOf, pollPaymentState, publicApiClient, quoteChangedOptionsFrom, readBasicSettings, readOrderHandoff, refFromPathname, resolveAssetSrc, resolveInitialState, resolveLegalHref, resolveStoreRef, resolveTransformedImageUrl, resolveTransformedProductImageUrl, resolveTransformedStoreLogoUrl, safeRedirectPath, sdk, searchTextFor, shipmentEventLabel, shouldLog, shouldPollForConfirmation, storeApiPath, storePath, themeStyleCss, unwrap, unwrapOrNull, useAuth, useCart, useCheckout, useNotify, useOptionalStoreId, useOptionalThemeId, useOptionalThemeKey, useOrderLookup, useOrderStatus, useProvinces, usePublicAuthConfig, useStore, useStoreCurrency, useStoreData, useStoreId, useStoreLocale, useThemeId, useThemeSettings, useWards, validatePasswordAgainstPolicy, withSuspendedStoreMetadataFallback };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,8 @@ import { useCart } from "./cart/server-context.js";
|
|
|
24
24
|
import { getPaymentState } from "./checkout/get-payment-state.js";
|
|
25
25
|
import { readOrderHandoff } from "./checkout/order-handoff.js";
|
|
26
26
|
import { pollPaymentState } from "./checkout/payment-state-poll.js";
|
|
27
|
+
import { quoteChangedOptionsFrom } from "./checkout/quote-changed.js";
|
|
28
|
+
import { optionIdOf } from "./shipping/option-id.js";
|
|
27
29
|
import { STOCK_ISSUE_TOAST_DESCRIPTION } from "./checkout/stock-issues.js";
|
|
28
30
|
import {
|
|
29
31
|
resolveInitialState,
|
|
@@ -42,9 +44,21 @@ import {
|
|
|
42
44
|
deriveOrderProgress
|
|
43
45
|
} from "./orders/derive-progress.js";
|
|
44
46
|
import { STATUS_OPTIONS } from "./orders/types.js";
|
|
47
|
+
import {
|
|
48
|
+
SHIPMENT_STATUS_LABELS,
|
|
49
|
+
TRACKING_MESSAGES,
|
|
50
|
+
canCustomerCancel,
|
|
51
|
+
deriveShipmentTracking,
|
|
52
|
+
isCarrierShipment,
|
|
53
|
+
isHandedToCarrier,
|
|
54
|
+
shipmentEventLabel
|
|
55
|
+
} from "./orders/shipment-tracking.js";
|
|
45
56
|
import { getPromotionDescription } from "./promotions/utils.js";
|
|
46
57
|
import { createStoreSdk, sdk } from "./sdk.js";
|
|
47
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
formatShippingAmount,
|
|
60
|
+
describeShippingOption
|
|
61
|
+
} from "./shipping/format-shipping-option.js";
|
|
48
62
|
import {
|
|
49
63
|
loadWards,
|
|
50
64
|
searchTextFor,
|
|
@@ -68,6 +82,8 @@ import { readBasicSettings, resolveLegalHref } from "./stores/basic-settings.js"
|
|
|
68
82
|
import { defineSchema, defineTheme } from "./theme/define.js";
|
|
69
83
|
import {
|
|
70
84
|
ThemeSettingsProvider,
|
|
85
|
+
useOptionalThemeId,
|
|
86
|
+
useOptionalThemeKey,
|
|
71
87
|
useThemeId,
|
|
72
88
|
useThemeSettings
|
|
73
89
|
} from "./theme/settings-context.js";
|
|
@@ -75,6 +91,11 @@ import { metafield, metaobjectField } from "./metafields/readers.js";
|
|
|
75
91
|
import { getMetaobject, getMetaobjects } from "./metafields/metaobjects.js";
|
|
76
92
|
import { RichText } from "./metafields/rich-text.js";
|
|
77
93
|
import { ThemeStyle, themeStyleCss } from "./theme/style.js";
|
|
94
|
+
import {
|
|
95
|
+
THEME_PREVIEW_FRAME_ATTR,
|
|
96
|
+
THEME_PREVIEW_MESSAGE,
|
|
97
|
+
ThemePreviewBridge
|
|
98
|
+
} from "./theme/preview-bridge.js";
|
|
78
99
|
import { getCachedStore } from "./stores/cached.js";
|
|
79
100
|
import {
|
|
80
101
|
SUSPENDED_STORE_METADATA,
|
|
@@ -87,19 +108,27 @@ export {
|
|
|
87
108
|
DEFAULT_REDIRECT,
|
|
88
109
|
ORDER_PROGRESS_STEPS,
|
|
89
110
|
RichText,
|
|
111
|
+
SHIPMENT_STATUS_LABELS,
|
|
90
112
|
SHIPPING_MESSAGES,
|
|
91
113
|
STATUS_OPTIONS,
|
|
92
114
|
STOCK_ISSUE_TOAST_DESCRIPTION,
|
|
93
115
|
SUSPENDED_STORE_METADATA,
|
|
94
116
|
StorefrontKitProvider,
|
|
117
|
+
THEME_PREVIEW_FRAME_ATTR,
|
|
118
|
+
THEME_PREVIEW_MESSAGE,
|
|
119
|
+
TRACKING_MESSAGES,
|
|
120
|
+
ThemePreviewBridge,
|
|
95
121
|
ThemeSettingsProvider,
|
|
96
122
|
ThemeStyle,
|
|
97
123
|
applyConsoleFilter,
|
|
98
124
|
buildStoreUrl,
|
|
125
|
+
canCustomerCancel,
|
|
99
126
|
createStoreSdk,
|
|
100
127
|
defineSchema,
|
|
101
128
|
defineTheme,
|
|
102
129
|
deriveOrderProgress,
|
|
130
|
+
deriveShipmentTracking,
|
|
131
|
+
describeShippingOption,
|
|
103
132
|
errorCopy,
|
|
104
133
|
errorCopyFor,
|
|
105
134
|
findProvinceByCodeOrName,
|
|
@@ -118,13 +147,17 @@ export {
|
|
|
118
147
|
getPasswordPolicyHints,
|
|
119
148
|
getPaymentState,
|
|
120
149
|
getPromotionDescription,
|
|
150
|
+
isCarrierShipment,
|
|
151
|
+
isHandedToCarrier,
|
|
121
152
|
isStoreSuspendedError,
|
|
122
153
|
loadWards,
|
|
123
154
|
metafield,
|
|
124
155
|
metaobjectField,
|
|
125
156
|
money,
|
|
157
|
+
optionIdOf,
|
|
126
158
|
pollPaymentState,
|
|
127
159
|
publicApiClient,
|
|
160
|
+
quoteChangedOptionsFrom,
|
|
128
161
|
readBasicSettings,
|
|
129
162
|
readOrderHandoff,
|
|
130
163
|
refFromPathname,
|
|
@@ -138,6 +171,7 @@ export {
|
|
|
138
171
|
safeRedirectPath,
|
|
139
172
|
sdk,
|
|
140
173
|
searchTextFor,
|
|
174
|
+
shipmentEventLabel,
|
|
141
175
|
shouldLog,
|
|
142
176
|
shouldPollForConfirmation,
|
|
143
177
|
storeApiPath,
|
|
@@ -150,6 +184,8 @@ export {
|
|
|
150
184
|
useCheckout,
|
|
151
185
|
useNotify,
|
|
152
186
|
useOptionalStoreId,
|
|
187
|
+
useOptionalThemeId,
|
|
188
|
+
useOptionalThemeKey,
|
|
153
189
|
useOrderLookup,
|
|
154
190
|
useOrderStatus,
|
|
155
191
|
useProvinces,
|
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 type { BankAccountView } from \"./orders/use-order-status\";\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 {
|
|
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 type { BankAccountView } from \"./orders/use-order-status\";\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 SUSPENDED_STORE_METADATA,\n withSuspendedStoreMetadataFallback,\n} from \"./stores/metadata\";\nexport { refFromPathname } from \"./stores/store-path\";\nexport { isStoreSuspendedError } from \"./stores/store-suspension\";\nexport { applyConsoleFilter, getLogLevel, shouldLog } from \"./logging\";\n"],"mappings":"AACA,SAAS,6BAA6B;AAEtC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,sBAAsB;AAS/C;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,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,oBAAoB,aAAa,iBAAiB;","names":[]}
|
|
@@ -19,6 +19,12 @@ import { publicConfig } from "../config/public.js";
|
|
|
19
19
|
import { lookupRedirect } from "../redirects/lookup-redirect.js";
|
|
20
20
|
import { multiTenantStorePath } from "../store-scope/index.js";
|
|
21
21
|
import { getStoreByHost } from "../stores/get-store-by-host.js";
|
|
22
|
+
import { getStoreSubdomain } from "../stores/store-subdomain.js";
|
|
23
|
+
import { recordStoreRequest } from "../stores/store-traffic.js";
|
|
24
|
+
import {
|
|
25
|
+
PREVIEW_HOST_ROBOTS,
|
|
26
|
+
THEME_PREVIEW_HOST_HEADER
|
|
27
|
+
} from "../theme/preview-host.js";
|
|
22
28
|
const METADATA_FILES = [
|
|
23
29
|
"/robots.txt",
|
|
24
30
|
"/sitemap.xml",
|
|
@@ -32,7 +38,7 @@ const EXTERNAL_METADATA_FILES = ["/robots.txt", "/sitemap.xml"];
|
|
|
32
38
|
const DOMAIN_NOT_CONNECTED_PATH = "/domain-not-connected";
|
|
33
39
|
function externalThemeResponse(req, host, storeRef, externalUrl) {
|
|
34
40
|
if (!externalUrl) return null;
|
|
35
|
-
if (req.nextUrl.searchParams.has(THEME_PREVIEW_PARAM) || hasThemePreview(req))
|
|
41
|
+
if (req.nextUrl.searchParams.has(THEME_PREVIEW_PARAM) || hasThemePreview(req, authCookiePath(storeRef, true)))
|
|
36
42
|
return null;
|
|
37
43
|
const pathname = req.nextUrl.pathname;
|
|
38
44
|
const prefix = multiTenantStorePath(storeRef);
|
|
@@ -69,6 +75,28 @@ function buildRedirectResponse(req, redirect, pathPrefix = "") {
|
|
|
69
75
|
redirectUrl.pathname = `${pathPrefix}${redirect.destination_path}`;
|
|
70
76
|
return NextResponse.redirect(redirectUrl, { status: redirect.redirect_type });
|
|
71
77
|
}
|
|
78
|
+
async function apexStoreResponse(req, storeRef, platformDomain) {
|
|
79
|
+
let subdomain = null;
|
|
80
|
+
try {
|
|
81
|
+
subdomain = await getStoreSubdomain(storeRef);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error("Store lookup failed for apex path:", storeRef, error);
|
|
84
|
+
}
|
|
85
|
+
if (!subdomain) {
|
|
86
|
+
const url = req.nextUrl.clone();
|
|
87
|
+
url.pathname = "/404";
|
|
88
|
+
url.search = "";
|
|
89
|
+
return NextResponse.rewrite(url);
|
|
90
|
+
}
|
|
91
|
+
const prefix = multiTenantStorePath(storeRef);
|
|
92
|
+
const pathname = req.nextUrl.pathname;
|
|
93
|
+
const target = publicNextUrl(req);
|
|
94
|
+
target.hostname = `${subdomain}.${platformDomain}`;
|
|
95
|
+
target.port = "";
|
|
96
|
+
target.pathname = pathname.startsWith(`${prefix}/`) ? pathname.slice(prefix.length) : "/";
|
|
97
|
+
const safe = req.method === "GET" || req.method === "HEAD";
|
|
98
|
+
return NextResponse.redirect(target, { status: safe ? 302 : 307 });
|
|
99
|
+
}
|
|
72
100
|
async function multiTenant(req) {
|
|
73
101
|
const host = req.headers.get("host") || "";
|
|
74
102
|
const pathname = req.nextUrl.pathname;
|
|
@@ -78,16 +106,30 @@ async function multiTenant(req) {
|
|
|
78
106
|
}
|
|
79
107
|
const platformDomain = publicConfig().platformDomainSuffix ?? "ecomsite.app";
|
|
80
108
|
const hostIdentifiesStore = !host.includes("localhost") && !host.includes("127.0.0.1") && host !== platformDomain && host !== `www.${platformDomain}`;
|
|
109
|
+
const isPlatformApex = host === platformDomain || host === `www.${platformDomain}`;
|
|
110
|
+
if (isPlatformApex) {
|
|
111
|
+
const apexStoreRef = storeRefFromPath(pathname);
|
|
112
|
+
if (apexStoreRef)
|
|
113
|
+
return apexStoreResponse(req, apexStoreRef, platformDomain);
|
|
114
|
+
}
|
|
81
115
|
let hostStoreRef = null;
|
|
82
116
|
let hostResolved = false;
|
|
83
117
|
let hostStoreSuspended = false;
|
|
118
|
+
let previewSlug = null;
|
|
84
119
|
if (isMetadataFile && !hostIdentifiesStore) return NextResponse.next();
|
|
85
120
|
if (hostIdentifiesStore) {
|
|
86
121
|
try {
|
|
87
|
-
const
|
|
122
|
+
const lookup = await getStoreByHost(host);
|
|
123
|
+
const { storeRef: storeRef2, domain, isSubDomain, suspended, externalUrl } = lookup;
|
|
88
124
|
hostResolved = true;
|
|
89
125
|
hostStoreRef = storeRef2 || null;
|
|
90
126
|
hostStoreSuspended = suspended;
|
|
127
|
+
previewSlug = storeRef2 ? lookup.previewSlug : null;
|
|
128
|
+
if (previewSlug && isMetadataFile) {
|
|
129
|
+
return pathname === "/robots.txt" ? new NextResponse(PREVIEW_HOST_ROBOTS, {
|
|
130
|
+
headers: { "content-type": "text/plain" }
|
|
131
|
+
}) : new NextResponse(null, { status: 404 });
|
|
132
|
+
}
|
|
91
133
|
if (storeRef2) {
|
|
92
134
|
const external = externalThemeResponse(
|
|
93
135
|
req,
|
|
@@ -99,7 +141,7 @@ async function multiTenant(req) {
|
|
|
99
141
|
}
|
|
100
142
|
if (isMetadataFile) return NextResponse.next();
|
|
101
143
|
if (storeRef2) {
|
|
102
|
-
if (isSubDomain && domain && domain !== host) {
|
|
144
|
+
if (isSubDomain && domain && domain !== host && !previewSlug) {
|
|
103
145
|
const url = publicNextUrl(req);
|
|
104
146
|
url.hostname = domain;
|
|
105
147
|
url.protocol = "https:";
|
|
@@ -121,11 +163,10 @@ async function multiTenant(req) {
|
|
|
121
163
|
}
|
|
122
164
|
}
|
|
123
165
|
const storeRef = hostStoreRef ?? storeRefFromPath(pathname);
|
|
124
|
-
if (storeRef)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
);
|
|
166
|
+
if (storeRef) recordStoreRequest(storeRef);
|
|
167
|
+
const cookiePath = storeRef ? authCookiePath(storeRef, !!hostStoreRef) : null;
|
|
168
|
+
if (storeRef && cookiePath) {
|
|
169
|
+
const preview = applyThemePreview(req, cookiePath);
|
|
129
170
|
if (preview) return preview;
|
|
130
171
|
}
|
|
131
172
|
if (!hostStoreRef && storeRef) {
|
|
@@ -142,7 +183,7 @@ async function multiTenant(req) {
|
|
|
142
183
|
}
|
|
143
184
|
}
|
|
144
185
|
}
|
|
145
|
-
const rotated = storeRef ? await refreshIfNearExpiry(req, storeRef) : null;
|
|
186
|
+
const rotated = storeRef && cookiePath ? await refreshIfNearExpiry(req, storeRef, cookiePath) : null;
|
|
146
187
|
const downstream = downstreamRequestHeaders(
|
|
147
188
|
req,
|
|
148
189
|
!!hostStoreRef,
|
|
@@ -153,6 +194,7 @@ async function multiTenant(req) {
|
|
|
153
194
|
REQUEST_PATH_HEADER,
|
|
154
195
|
`${req.nextUrl.pathname}${req.nextUrl.search}`
|
|
155
196
|
);
|
|
197
|
+
if (previewSlug) downstream.set(THEME_PREVIEW_HOST_HEADER, previewSlug);
|
|
156
198
|
const init = { request: { headers: downstream } };
|
|
157
199
|
let response;
|
|
158
200
|
if (hostStoreRef) {
|
|
@@ -175,14 +217,11 @@ async function multiTenant(req) {
|
|
|
175
217
|
} else {
|
|
176
218
|
response = NextResponse.next(init);
|
|
177
219
|
}
|
|
178
|
-
if (hasThemePreview(req))
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
rotated,
|
|
184
|
-
authCookiePath(storeRef, !!hostStoreRef)
|
|
185
|
-
);
|
|
220
|
+
if (previewSlug || cookiePath && hasThemePreview(req, cookiePath)) {
|
|
221
|
+
response.headers.set("x-robots-tag", "noindex");
|
|
222
|
+
}
|
|
223
|
+
if (rotated && storeRef && cookiePath) {
|
|
224
|
+
writeAuthCookies(response, storeRef, rotated, cookiePath);
|
|
186
225
|
}
|
|
187
226
|
return response;
|
|
188
227
|
}
|
|
@@ -190,7 +229,8 @@ async function singleStore(req) {
|
|
|
190
229
|
const pathname = req.nextUrl.pathname;
|
|
191
230
|
if (METADATA_FILES.includes(pathname)) return NextResponse.next();
|
|
192
231
|
const storeRef = publicConfig().storeRef;
|
|
193
|
-
const
|
|
232
|
+
const cookiePath = authCookiePath(storeRef, true);
|
|
233
|
+
const preview = applyThemePreview(req, cookiePath);
|
|
194
234
|
if (preview) return preview;
|
|
195
235
|
try {
|
|
196
236
|
const redirect = await lookupRedirect(storeRef, pathname);
|
|
@@ -202,20 +242,16 @@ async function singleStore(req) {
|
|
|
202
242
|
} catch (error) {
|
|
203
243
|
console.debug("Redirect lookup error:", error);
|
|
204
244
|
}
|
|
205
|
-
const rotated = await refreshIfNearExpiry(req, storeRef);
|
|
245
|
+
const rotated = await refreshIfNearExpiry(req, storeRef, cookiePath);
|
|
206
246
|
const response = NextResponse.next({
|
|
207
247
|
request: {
|
|
208
248
|
headers: downstreamRequestHeaders(req, true, storeRef, rotated)
|
|
209
249
|
}
|
|
210
250
|
});
|
|
211
|
-
if (hasThemePreview(req
|
|
251
|
+
if (hasThemePreview(req, cookiePath))
|
|
252
|
+
response.headers.set("x-robots-tag", "noindex");
|
|
212
253
|
if (rotated) {
|
|
213
|
-
writeAuthCookies(
|
|
214
|
-
response,
|
|
215
|
-
storeRef,
|
|
216
|
-
rotated,
|
|
217
|
-
authCookiePath(storeRef, true)
|
|
218
|
-
);
|
|
254
|
+
writeAuthCookies(response, storeRef, rotated, cookiePath);
|
|
219
255
|
}
|
|
220
256
|
return response;
|
|
221
257
|
}
|