@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 settings that survive the page-builder retirement, read from their
885
- * new `settings.*` homes with a fallback to the legacy `theme_config` paths.
886
- * The fallbacks go once the API migration (spec §6) has run everywhere.
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 are now in settings, not theme_config\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
+ {"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 settings = store.settings ?? {};
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: first(str(legal.terms), str(theme.checkout?.term_link)),
49
- policyLink: first(str(legal.privacy), str(theme.checkout?.policy_link))
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 settings that survive the page-builder retirement, read from their\n * new `settings.*` homes with a fallback to the legacy `theme_config` paths.\n * The fallbacks go once the API migration (spec §6) has run everywhere.\n */\n\ntype Loose = Record<string, any>;\n\nexport interface StoreLike {\n settings?: Loose | null;\n theme_config?: Loose | null;\n}\n\nexport interface BasicSettings {\n brandColor: string | null;\n backgroundColor: string | null;\n navigation: {\n mainMenuRef: string | null;\n topbarMessage: string | null;\n customerSupportMenuRef: string | null;\n aboutUsMenuRef: string | null;\n copyrightText: string | null;\n };\n legalLinks: { termsLink: string | null; policyLink: string | null };\n homepageCollectionSlug: string | null;\n}\n\nfunction str(v: unknown): string | null {\n return typeof v === \"string\" && v.trim() !== \"\" ? v.trim() : null;\n}\n\nconst HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\n\n/** Only hex colors: the value is interpolated into a <style> tag. */\nfunction color(v: unknown): string | null {\n const s = str(v);\n return s && HEX_COLOR.test(s) ? s : null;\n}\n\nfunction first<T>(...values: (T | null)[]): T | null {\n for (const v of values) if (v !== null) return v;\n return null;\n}\n\nexport function readBasicSettings(store: StoreLike): BasicSettings {\n const settings: Loose = store.settings ?? {};\n const theme: Loose = store.theme_config ?? settings.theme_config ?? {};\n const nav: Loose = settings.navigation ?? {};\n const legal: Loose = settings.legal_links ?? {};\n\n return {\n brandColor: first(color(settings.brand_color), color(theme.theme_color)),\n backgroundColor: color(theme.background_color),\n navigation: {\n mainMenuRef: first(\n str(nav.main_menu_ref),\n str(theme.header?.main_menu_ref),\n str(theme.menu?.main_menu)\n ),\n topbarMessage: first(\n str(nav.topbar_message),\n str(theme.header?.topbar_message),\n str(theme.topbar?.message)\n ),\n customerSupportMenuRef: first(\n str(nav.customer_support_menu_ref),\n str(theme.footer?.customer_support_menu_ref),\n str(theme.menu?.customer_support_menu)\n ),\n aboutUsMenuRef: first(\n str(nav.about_us_menu_ref),\n str(theme.footer?.about_us_menu_ref),\n str(theme.menu?.about_us_menu)\n ),\n copyrightText: first(\n str(nav.copyright_text),\n str(theme.footer?.copyright_text)\n ),\n },\n legalLinks: {\n termsLink: first(str(legal.terms), str(theme.checkout?.term_link)),\n policyLink: first(str(legal.privacy), str(theme.checkout?.policy_link)),\n },\n homepageCollectionSlug: first(\n str(settings.homepage_collection_slug),\n str(theme.homepage?.collection_slug)\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 toStoreU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M,MAAM,aAAa;AAAA,MAC/B;AAAA,MACA,eAAe;AAAA,QACb,IAAI,IAAI,cAAc;AAAA,QACtB,IAAI,MAAM,QAAQ,cAAc;AAAA,MAClC;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV,WAAW,MAAM,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,UAAU,SAAS,CAAC;AAAA,MACjE,YAAY,MAAM,IAAI,MAAM,OAAO,GAAG,IAAI,MAAM,UAAU,WAAW,CAAC;AAAA,IACxE;AAAA,IACA,wBAAwB;AAAA,MACtB,IAAI,SAAS,wBAAwB;AAAA,MACrC,IAAI,MAAM,UAAU,eAAe;AAAA,IACrC;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":[]}
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.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.3.0"
50
+ "@ecomweb/sdk": "^0.4.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "next": ">=16",