@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
|
@@ -6,10 +6,14 @@ const ThemeSettingsContext = createContext(
|
|
|
6
6
|
);
|
|
7
7
|
function ThemeSettingsProvider({
|
|
8
8
|
themeId,
|
|
9
|
+
themeKey,
|
|
9
10
|
settings,
|
|
10
11
|
children
|
|
11
12
|
}) {
|
|
12
|
-
const value = useMemo(
|
|
13
|
+
const value = useMemo(
|
|
14
|
+
() => ({ themeId, themeKey, settings }),
|
|
15
|
+
[themeId, themeKey, settings]
|
|
16
|
+
);
|
|
13
17
|
return /* @__PURE__ */ jsx(ThemeSettingsContext.Provider, { value, children });
|
|
14
18
|
}
|
|
15
19
|
function useThemeSettingsContext(hook) {
|
|
@@ -25,8 +29,17 @@ function useThemeSettings() {
|
|
|
25
29
|
function useThemeId() {
|
|
26
30
|
return useThemeSettingsContext("useThemeId").themeId;
|
|
27
31
|
}
|
|
32
|
+
function useOptionalThemeId() {
|
|
33
|
+
return useContext(ThemeSettingsContext)?.themeId ?? null;
|
|
34
|
+
}
|
|
35
|
+
function useOptionalThemeKey() {
|
|
36
|
+
const ctx = useContext(ThemeSettingsContext);
|
|
37
|
+
return ctx ? ctx.themeKey ?? ctx.themeId : null;
|
|
38
|
+
}
|
|
28
39
|
export {
|
|
29
40
|
ThemeSettingsProvider,
|
|
41
|
+
useOptionalThemeId,
|
|
42
|
+
useOptionalThemeKey,
|
|
30
43
|
useThemeId,
|
|
31
44
|
useThemeSettings
|
|
32
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/settings-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ThemeValues } from \"@ecomweb/sdk\";\n\ninterface ThemeSettingsContextValue {\n themeId: string;\n settings: ThemeValues;\n}\n\nconst ThemeSettingsContext = createContext<ThemeSettingsContextValue | null>(\n null\n);\n\n/** The published (or previewed) theme's resolved settings, for client components. */\nexport function ThemeSettingsProvider({\n themeId,\n settings,\n children,\n}: ThemeSettingsContextValue & { children: ReactNode }) {\n const value = useMemo(() => ({ themeId, settings })
|
|
1
|
+
{"version":3,"sources":["../../src/theme/settings-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ThemeValues } from \"@ecomweb/sdk\";\n\ninterface ThemeSettingsContextValue {\n themeId: string;\n /** The registry key of the code rendering, e.g. \"meridian@1\" (theme majors). */\n themeKey?: string;\n settings: ThemeValues;\n}\n\nconst ThemeSettingsContext = createContext<ThemeSettingsContextValue | null>(\n null\n);\n\n/** The published (or previewed) theme's resolved settings, for client components. */\nexport function ThemeSettingsProvider({\n themeId,\n themeKey,\n settings,\n children,\n}: ThemeSettingsContextValue & { children: ReactNode }) {\n const value = useMemo(\n () => ({ themeId, themeKey, settings }),\n [themeId, themeKey, settings]\n );\n return (\n <ThemeSettingsContext.Provider value={value}>\n {children}\n </ThemeSettingsContext.Provider>\n );\n}\n\nfunction useThemeSettingsContext(hook: string): ThemeSettingsContextValue {\n const ctx = useContext(ThemeSettingsContext);\n if (!ctx) {\n throw new Error(`${hook} must be used inside a ThemeSettingsProvider`);\n }\n return ctx;\n}\n\n/** Pass the theme's settings type: `useThemeSettings<MyThemeSettings>()`. */\nexport function useThemeSettings<T = ThemeValues>(): T {\n return useThemeSettingsContext(\"useThemeSettings\").settings as T;\n}\n\nexport function useThemeId(): string {\n return useThemeSettingsContext(\"useThemeId\").themeId;\n}\n\n/** The theme id, or null outside a ThemeSettingsProvider (e.g. a store 404). */\nexport function useOptionalThemeId(): string | null {\n return useContext(ThemeSettingsContext)?.themeId ?? null;\n}\n\n/**\n * The registry key of the theme code rendering (\"meridian@1\"), else its id;\n * null outside a ThemeSettingsProvider. Client registries look up by it.\n */\nexport function useOptionalThemeKey(): string | null {\n const ctx = useContext(ThemeSettingsContext);\n return ctx ? (ctx.themeKey ?? ctx.themeId) : null;\n}\n"],"mappings":";AA4BI;AA1BJ,SAAS,eAAe,YAAY,eAA+B;AAUnE,MAAM,uBAAuB;AAAA,EAC3B;AACF;AAGO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,QAAQ;AAAA,IACZ,OAAO,EAAE,SAAS,UAAU,SAAS;AAAA,IACrC,CAAC,SAAS,UAAU,QAAQ;AAAA,EAC9B;AACA,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAC5B,UACH;AAEJ;AAEA,SAAS,wBAAwB,MAAyC;AACxE,QAAM,MAAM,WAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,GAAG,IAAI,8CAA8C;AAAA,EACvE;AACA,SAAO;AACT;AAGO,SAAS,mBAAuC;AACrD,SAAO,wBAAwB,kBAAkB,EAAE;AACrD;AAEO,SAAS,aAAqB;AACnC,SAAO,wBAAwB,YAAY,EAAE;AAC/C;AAGO,SAAS,qBAAoC;AAClD,SAAO,WAAW,oBAAoB,GAAG,WAAW;AACtD;AAMO,SAAS,sBAAqC;AACnD,QAAM,MAAM,WAAW,oBAAoB;AAC3C,SAAO,MAAO,IAAI,YAAY,IAAI,UAAW;AAC/C;","names":[]}
|
package/dist/theme.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ThemeSchema, StoreConfigurationInfo,
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
import { ThemeSchema, StoreConfigurationInfo, ProductDetail, Collection, ContentPage, BlogPost, BlogCategory, SearchProduct, Product, ProductWithVariants, ThemeSettingsOf } from '@ecomweb/sdk';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The theme contract (spec: schema-driven themes §5.2). A theme declares its
|
|
@@ -23,12 +23,72 @@ interface ThemeSlotProps<V> {
|
|
|
23
23
|
interface LayoutSlotProps<V> extends ThemeSlotProps<V> {
|
|
24
24
|
children: ReactNode;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/** Banners and the shop introduction are theme settings (default@1.1.0). */
|
|
27
|
+
type HomePageSlotProps<V> = ThemeSlotProps<V>;
|
|
28
|
+
interface ProductPageSlotProps<V> extends ThemeSlotProps<V> {
|
|
29
|
+
product: ProductDetail;
|
|
30
|
+
}
|
|
31
|
+
/** The collection route's query string, as the filters read it. */
|
|
32
|
+
interface CollectionSearchParams {
|
|
33
|
+
q?: string;
|
|
34
|
+
category?: string;
|
|
35
|
+
page?: string;
|
|
36
|
+
sort?: string;
|
|
37
|
+
min_price?: string;
|
|
38
|
+
max_price?: string;
|
|
39
|
+
has_promotion?: string;
|
|
40
|
+
}
|
|
41
|
+
interface CollectionPageSlotProps<V> extends ThemeSlotProps<V> {
|
|
42
|
+
slug: string;
|
|
43
|
+
/** Null for the "all" pseudo-collection. */
|
|
44
|
+
collection: Collection | null;
|
|
45
|
+
searchParams: CollectionSearchParams;
|
|
46
|
+
}
|
|
47
|
+
interface ContentPageSlotProps<V> extends ThemeSlotProps<V> {
|
|
48
|
+
page: ContentPage;
|
|
49
|
+
isPreview: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface BlogIndexSlotProps<V> extends ThemeSlotProps<V> {
|
|
52
|
+
blogTitle: string;
|
|
53
|
+
posts: BlogPost[];
|
|
54
|
+
categories: BlogCategory[];
|
|
55
|
+
total: number;
|
|
56
|
+
page: number;
|
|
57
|
+
totalPages: number;
|
|
58
|
+
/** Category id filter from the query string, "" when none. */
|
|
59
|
+
category: string;
|
|
60
|
+
search: string;
|
|
61
|
+
}
|
|
62
|
+
interface BlogPostSlotProps<V> extends ThemeSlotProps<V> {
|
|
63
|
+
blogTitle: string;
|
|
64
|
+
post: BlogPost;
|
|
65
|
+
/** The post's linked products, in the post's order. */
|
|
66
|
+
products: SearchProduct[];
|
|
28
67
|
}
|
|
29
68
|
interface ThemeComponents<V> {
|
|
30
69
|
Layout?: ThemeSlot<LayoutSlotProps<V>>;
|
|
31
70
|
HomePage?: ThemeSlot<HomePageSlotProps<V>>;
|
|
71
|
+
ProductPage?: ThemeSlot<ProductPageSlotProps<V>>;
|
|
72
|
+
CollectionPage?: ThemeSlot<CollectionPageSlotProps<V>>;
|
|
73
|
+
ContentPage?: ThemeSlot<ContentPageSlotProps<V>>;
|
|
74
|
+
BlogIndex?: ThemeSlot<BlogIndexSlotProps<V>>;
|
|
75
|
+
BlogPost?: ThemeSlot<BlogPostSlotProps<V>>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Components rendered inside client components, so they cannot be resolved
|
|
79
|
+
* on the server per request. The app keeps a registry keyed by theme id.
|
|
80
|
+
*/
|
|
81
|
+
interface ProductCardProps {
|
|
82
|
+
product: Product | ProductWithVariants | SearchProduct;
|
|
83
|
+
storeRef?: string;
|
|
84
|
+
}
|
|
85
|
+
interface NotFoundProps {
|
|
86
|
+
/** Null when the store itself was not found. */
|
|
87
|
+
storeRef: string | null;
|
|
88
|
+
}
|
|
89
|
+
interface ThemeClientComponents {
|
|
90
|
+
ProductCard?: ComponentType<ProductCardProps>;
|
|
91
|
+
NotFound?: ComponentType<NotFoundProps>;
|
|
32
92
|
}
|
|
33
93
|
type ThemeSlotName = keyof ThemeComponents<unknown>;
|
|
34
94
|
interface ThemeDefinition<S extends ThemeSchema = ThemeSchema> {
|
|
@@ -50,4 +110,4 @@ interface AnyThemeDefinition {
|
|
|
50
110
|
}
|
|
51
111
|
declare function defineTheme<const S extends ThemeSchema>(theme: ThemeDefinition<S>): ThemeDefinition<S>;
|
|
52
112
|
|
|
53
|
-
export { type AnyThemeDefinition, type HomePageSlotProps, type LayoutSlotProps, type ThemeComponents, type ThemeDefinition, type ThemeInfo, type ThemeSlot, type ThemeSlotName, type ThemeSlotProps, defineSchema, defineTheme };
|
|
113
|
+
export { type AnyThemeDefinition, type BlogIndexSlotProps, type BlogPostSlotProps, type CollectionPageSlotProps, type CollectionSearchParams, type ContentPageSlotProps, type HomePageSlotProps, type LayoutSlotProps, type NotFoundProps, type ProductCardProps, type ProductPageSlotProps, type ThemeClientComponents, type ThemeComponents, type ThemeDefinition, type ThemeInfo, type ThemeSlot, type ThemeSlotName, type ThemeSlotProps, defineSchema, defineTheme };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomweb/storefront-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Headless storefront logic for ecomweb: auth, cart, checkout, API proxy",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"currency.js": "^2.0.4",
|
|
48
48
|
"server-only": "^0.0.1",
|
|
49
49
|
"zod": "^4.1.12",
|
|
50
|
-
"@ecomweb/sdk": "^0.
|
|
50
|
+
"@ecomweb/sdk": "^0.10.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"next": ">=16",
|