@ecomweb/storefront-kit 0.3.0 → 0.4.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/dist/index.d.ts
CHANGED
|
@@ -881,31 +881,21 @@ declare function buildStoreUrl(store: {
|
|
|
881
881
|
} | StoreConfig | StoreConfigurationInfo, path?: string): string;
|
|
882
882
|
|
|
883
883
|
/**
|
|
884
|
-
* The store
|
|
885
|
-
*
|
|
886
|
-
*
|
|
884
|
+
* The store's checkout and register legal links, from `settings.legal_links`.
|
|
885
|
+
* Everything else the page builder's theme_config held is a theme setting
|
|
886
|
+
* now (`useThemeSettings`).
|
|
887
887
|
*/
|
|
888
888
|
type Loose = Record<string, any>;
|
|
889
889
|
interface StoreLike {
|
|
890
890
|
settings?: Loose | null;
|
|
891
|
-
theme_config?: Loose | null;
|
|
892
891
|
}
|
|
893
892
|
interface BasicSettings {
|
|
894
|
-
brandColor: string | null;
|
|
895
|
-
backgroundColor: string | null;
|
|
896
|
-
navigation: {
|
|
897
|
-
mainMenuRef: string | null;
|
|
898
|
-
topbarMessage: string | null;
|
|
899
|
-
customerSupportMenuRef: string | null;
|
|
900
|
-
aboutUsMenuRef: string | null;
|
|
901
|
-
copyrightText: string | null;
|
|
902
|
-
};
|
|
903
893
|
legalLinks: {
|
|
904
894
|
termsLink: string | null;
|
|
905
895
|
policyLink: string | null;
|
|
906
896
|
};
|
|
907
|
-
homepageCollectionSlug: string | null;
|
|
908
897
|
}
|
|
898
|
+
/** @deprecated Read `store.settings.legal_links` directly. */
|
|
909
899
|
declare function readBasicSettings(store: StoreLike): BasicSettings;
|
|
910
900
|
declare function resolveLegalHref(link: string | null, fallbackPath: string | null, toStoreUrl: (path: string) => string): string;
|
|
911
901
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/store/store-context.tsx"],"sourcesContent":["\"use client\";\n\nimport type { StoreConfigurationInfo } from \"@ecomweb/sdk\";\nimport { createContext, useContext, ReactNode } from \"react\";\n\nimport {\n SupportedCurrency,\n getDefaultLocale,\n isSupportedCurrency,\n} from \"../currency\";\n\ninterface StoreContextData {\n store: StoreConfigurationInfo;\n}\n\ninterface StoreProviderProps {\n children: ReactNode;\n store: StoreConfigurationInfo;\n}\n\nconst StoreContext = createContext<StoreContextData | undefined>(undefined);\n\nexport function StoreProvider({ children, store }: StoreProviderProps) {\n const value: StoreContextData = {\n store,\n };\n\n return (\n <StoreContext.Provider value={value}>{children}</StoreContext.Provider>\n );\n}\n\nexport function useStore() {\n const context = useContext(StoreContext);\n if (!context) {\n throw new Error(\"useStore must be used within a StoreProvider\");\n }\n return context;\n}\n\n// Export specific hooks for convenience\nexport function useStoreData() {\n const { store } = useStore();\n return store;\n}\n\n/** The store ref, or null outside a StoreProvider (e.g. a store-level 404). */\nexport function useOptionalStoreId(): string | null {\n return useContext(StoreContext)?.store.ref ?? null;\n}\n\nexport function useStoreId() {\n const { store } = useStore();\n return store.ref;\n}\n\nexport function useStoreSettings() {\n const { store } = useStore();\n return store.settings;\n}\n\nexport function useStoreConfig() {\n const { store } = useStore();\n return store.config;\n}\n\nexport function useBlogSettings() {\n const { store } = useStore();\n\n // Blog settings
|
|
1
|
+
{"version":3,"sources":["../../src/store/store-context.tsx"],"sourcesContent":["\"use client\";\n\nimport type { StoreConfigurationInfo } from \"@ecomweb/sdk\";\nimport { createContext, useContext, ReactNode } from \"react\";\n\nimport {\n SupportedCurrency,\n getDefaultLocale,\n isSupportedCurrency,\n} from \"../currency\";\n\ninterface StoreContextData {\n store: StoreConfigurationInfo;\n}\n\ninterface StoreProviderProps {\n children: ReactNode;\n store: StoreConfigurationInfo;\n}\n\nconst StoreContext = createContext<StoreContextData | undefined>(undefined);\n\nexport function StoreProvider({ children, store }: StoreProviderProps) {\n const value: StoreContextData = {\n store,\n };\n\n return (\n <StoreContext.Provider value={value}>{children}</StoreContext.Provider>\n );\n}\n\nexport function useStore() {\n const context = useContext(StoreContext);\n if (!context) {\n throw new Error(\"useStore must be used within a StoreProvider\");\n }\n return context;\n}\n\n// Export specific hooks for convenience\nexport function useStoreData() {\n const { store } = useStore();\n return store;\n}\n\n/** The store ref, or null outside a StoreProvider (e.g. a store-level 404). */\nexport function useOptionalStoreId(): string | null {\n return useContext(StoreContext)?.store.ref ?? null;\n}\n\nexport function useStoreId() {\n const { store } = useStore();\n return store.ref;\n}\n\nexport function useStoreSettings() {\n const { store } = useStore();\n return store.settings;\n}\n\nexport function useStoreConfig() {\n const { store } = useStore();\n return store.config;\n}\n\nexport function useBlogSettings() {\n const { store } = useStore();\n\n // Blog settings live in store settings.\n return {\n blogEnabled: store.settings?.is_blog_enabled ?? false,\n blogTitle: store.settings?.blog_title ?? \"Blog\",\n };\n}\n\nexport function useStoreCurrency(): SupportedCurrency {\n const { store } = useStore();\n const currencyCode = store.settings?.currency_code;\n\n // Default to VND for anything we cannot price in.\n if (!currencyCode || !isSupportedCurrency(currencyCode)) {\n return \"VND\";\n }\n\n return currencyCode;\n}\n\nexport function useStoreLocale(): string {\n const currency = useStoreCurrency();\n return getDefaultLocale(currency);\n}\n"],"mappings":";AA4BI;AAzBJ,SAAS,eAAe,kBAA6B;AAErD;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAWP,MAAM,eAAe,cAA4C,MAAS;AAEnE,SAAS,cAAc,EAAE,UAAU,MAAM,GAAuB;AACrE,QAAM,QAA0B;AAAA,IAC9B;AAAA,EACF;AAEA,SACE,oBAAC,aAAa,UAAb,EAAsB,OAAe,UAAS;AAEnD;AAEO,SAAS,WAAW;AACzB,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAGO,SAAS,eAAe;AAC7B,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,SAAO;AACT;AAGO,SAAS,qBAAoC;AAClD,SAAO,WAAW,YAAY,GAAG,MAAM,OAAO;AAChD;AAEO,SAAS,aAAa;AAC3B,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,SAAO,MAAM;AACf;AAEO,SAAS,mBAAmB;AACjC,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,SAAO,MAAM;AACf;AAEO,SAAS,iBAAiB;AAC/B,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,SAAO,MAAM;AACf;AAEO,SAAS,kBAAkB;AAChC,QAAM,EAAE,MAAM,IAAI,SAAS;AAG3B,SAAO;AAAA,IACL,aAAa,MAAM,UAAU,mBAAmB;AAAA,IAChD,WAAW,MAAM,UAAU,cAAc;AAAA,EAC3C;AACF;AAEO,SAAS,mBAAsC;AACpD,QAAM,EAAE,MAAM,IAAI,SAAS;AAC3B,QAAM,eAAe,MAAM,UAAU;AAGrC,MAAI,CAAC,gBAAgB,CAAC,oBAAoB,YAAY,GAAG;AACvD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,iBAAyB;AACvC,QAAM,WAAW,iBAAiB;AAClC,SAAO,iBAAiB,QAAQ;AAClC;","names":[]}
|
|
@@ -1,57 +1,13 @@
|
|
|
1
1
|
function str(v) {
|
|
2
2
|
return typeof v === "string" && v.trim() !== "" ? v.trim() : null;
|
|
3
3
|
}
|
|
4
|
-
const HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
5
|
-
function color(v) {
|
|
6
|
-
const s = str(v);
|
|
7
|
-
return s && HEX_COLOR.test(s) ? s : null;
|
|
8
|
-
}
|
|
9
|
-
function first(...values) {
|
|
10
|
-
for (const v of values) if (v !== null) return v;
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
4
|
function readBasicSettings(store) {
|
|
14
|
-
const
|
|
15
|
-
const theme = store.theme_config ?? settings.theme_config ?? {};
|
|
16
|
-
const nav = settings.navigation ?? {};
|
|
17
|
-
const legal = settings.legal_links ?? {};
|
|
5
|
+
const legal = store.settings?.legal_links ?? {};
|
|
18
6
|
return {
|
|
19
|
-
brandColor: first(color(settings.brand_color), color(theme.theme_color)),
|
|
20
|
-
backgroundColor: color(theme.background_color),
|
|
21
|
-
navigation: {
|
|
22
|
-
mainMenuRef: first(
|
|
23
|
-
str(nav.main_menu_ref),
|
|
24
|
-
str(theme.header?.main_menu_ref),
|
|
25
|
-
str(theme.menu?.main_menu)
|
|
26
|
-
),
|
|
27
|
-
topbarMessage: first(
|
|
28
|
-
str(nav.topbar_message),
|
|
29
|
-
str(theme.header?.topbar_message),
|
|
30
|
-
str(theme.topbar?.message)
|
|
31
|
-
),
|
|
32
|
-
customerSupportMenuRef: first(
|
|
33
|
-
str(nav.customer_support_menu_ref),
|
|
34
|
-
str(theme.footer?.customer_support_menu_ref),
|
|
35
|
-
str(theme.menu?.customer_support_menu)
|
|
36
|
-
),
|
|
37
|
-
aboutUsMenuRef: first(
|
|
38
|
-
str(nav.about_us_menu_ref),
|
|
39
|
-
str(theme.footer?.about_us_menu_ref),
|
|
40
|
-
str(theme.menu?.about_us_menu)
|
|
41
|
-
),
|
|
42
|
-
copyrightText: first(
|
|
43
|
-
str(nav.copyright_text),
|
|
44
|
-
str(theme.footer?.copyright_text)
|
|
45
|
-
)
|
|
46
|
-
},
|
|
47
7
|
legalLinks: {
|
|
48
|
-
termsLink:
|
|
49
|
-
policyLink:
|
|
50
|
-
}
|
|
51
|
-
homepageCollectionSlug: first(
|
|
52
|
-
str(settings.homepage_collection_slug),
|
|
53
|
-
str(theme.homepage?.collection_slug)
|
|
54
|
-
)
|
|
8
|
+
termsLink: str(legal.terms),
|
|
9
|
+
policyLink: str(legal.privacy)
|
|
10
|
+
}
|
|
55
11
|
};
|
|
56
12
|
}
|
|
57
13
|
function resolveLegalHref(link, fallbackPath, toStoreUrl) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stores/basic-settings.ts"],"sourcesContent":["/**\n * The store
|
|
1
|
+
{"version":3,"sources":["../../src/stores/basic-settings.ts"],"sourcesContent":["/**\n * The store's checkout and register legal links, from `settings.legal_links`.\n * Everything else the page builder's theme_config held is a theme setting\n * now (`useThemeSettings`).\n */\n\ntype Loose = Record<string, any>;\n\nexport interface StoreLike {\n settings?: Loose | null;\n}\n\nexport interface BasicSettings {\n legalLinks: { termsLink: string | null; policyLink: string | null };\n}\n\nfunction str(v: unknown): string | null {\n return typeof v === \"string\" && v.trim() !== \"\" ? v.trim() : null;\n}\n\n/** @deprecated Read `store.settings.legal_links` directly. */\nexport function readBasicSettings(store: StoreLike): BasicSettings {\n const legal: Loose = store.settings?.legal_links ?? {};\n return {\n legalLinks: {\n termsLink: str(legal.terms),\n policyLink: str(legal.privacy),\n },\n };\n}\n\nexport function resolveLegalHref(\n link: string | null,\n fallbackPath: string | null,\n toStoreUrl: (path: string) => string\n): string {\n const target = link ?? fallbackPath;\n if (!target) return \"#\";\n if (/^https?:\\/\\//i.test(target)) return target;\n return toStoreUrl(target.startsWith(\"/\") ? target : `/${target}`);\n}\n"],"mappings":"AAgBA,SAAS,IAAI,GAA2B;AACtC,SAAO,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,IAAI;AAC/D;AAGO,SAAS,kBAAkB,OAAiC;AACjE,QAAM,QAAe,MAAM,UAAU,eAAe,CAAC;AACrD,SAAO;AAAA,IACL,YAAY;AAAA,MACV,WAAW,IAAI,MAAM,KAAK;AAAA,MAC1B,YAAY,IAAI,MAAM,OAAO;AAAA,IAC/B;AAAA,EACF;AACF;AAEO,SAAS,iBACd,MACA,cACA,YACQ;AACR,QAAM,SAAS,QAAQ;AACvB,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,gBAAgB,KAAK,MAAM,EAAG,QAAO;AACzC,SAAO,WAAW,OAAO,WAAW,GAAG,IAAI,SAAS,IAAI,MAAM,EAAE;AAClE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomweb/storefront-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.4.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"next": ">=16",
|