@zalify/storefront-kit 0.1.7 → 0.1.8

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/LICENSE.md CHANGED
@@ -11,7 +11,7 @@ and applications that you build and operate for yourself or for your
11
11
  clients.
12
12
 
13
13
  Code scaffolded into your project by Zalify tooling (for example by
14
- `create-zalify-theme`) may be modified without restriction and remains
14
+ `@zalify/theme-templates`) may be modified without restriction and remains
15
15
  governed by this license as part of your project.
16
16
 
17
17
  ## Limitations
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Zalify storefront SDK: everything shared between Zalify storefronts,
4
4
  shipped as one versioned package. Scaffold a storefront with
5
- [`create-zalify-theme`](https://www.npmjs.com/package/create-zalify-theme)
5
+ [`npx zalify theme create`](https://www.npmjs.com/package/@zalify/cli)
6
6
  and upgrade this package to pull in new engine features, sections, and
7
7
  blocks — your customizations live in your project, not in a fork
8
8
  (the same model as the Shopify Hydrogen SDK).
@@ -22,7 +22,7 @@ export function parseFontHandle(handle) {
22
22
  const match = /^(.*)_([nib])(\d)$/.exec(handle);
23
23
  if (!match)
24
24
  return fallback;
25
- const family = match[1]
25
+ const family = (match[1] ?? '')
26
26
  .split('_')
27
27
  .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
28
28
  .join(' ');
@@ -53,7 +53,7 @@ export function googleFontsHrefsFromSettings(settings) {
53
53
  const monoGoogle = str('type_mono_google');
54
54
  hrefs.push(googleFontsHref(bodyGoogle || parseFontHandle(str('type_body_font') || undefined).family));
55
55
  const heading = headingGoogle || parseFontHandle(str('type_heading_font') || undefined).family;
56
- if (!hrefs[0].includes(heading.replace(/ /g, '+'))) {
56
+ if (!hrefs[0]?.includes(heading.replace(/ /g, '+'))) {
57
57
  hrefs.push(googleFontsHref(heading, 'wght@400;500;600;700'));
58
58
  }
59
59
  if (monoGoogle)
@@ -106,8 +106,10 @@ async function fetchGoogleCss(href) {
106
106
  const latinUrls = [];
107
107
  const facePattern = /\/\*\s*latin\s*\*\/\s*@font-face\s*\{[^}]*?url\((https:[^)\s]+\.woff2)\)/g;
108
108
  let match;
109
- while ((match = facePattern.exec(css)))
110
- latinUrls.push(match[1]);
109
+ while ((match = facePattern.exec(css))) {
110
+ if (match[1])
111
+ latinUrls.push(match[1]);
112
+ }
111
113
  return { css, latinUrls };
112
114
  }
113
115
  catch {
@@ -4,11 +4,13 @@
4
4
  * preset (or flat values) in config/settings_data.json — both provided
5
5
  * at installTheme() time.
6
6
  */
7
- import { getThemeStore } from './store';
7
+ import { getThemeStore, getThemeStoreVersion } from './store';
8
+ // Keyed to the install counter: multi-tenant apps call installTheme()
9
+ // again with another store's schema, which must recompute this.
8
10
  let cache = null;
9
11
  function resolve() {
10
- if (cache)
11
- return cache;
12
+ if (cache && cache.version === getThemeStoreVersion())
13
+ return cache.resolved;
12
14
  const store = getThemeStore();
13
15
  const { settingsSchema, settingsData } = store.schema;
14
16
  const defaults = {};
@@ -46,8 +48,9 @@ function resolve() {
46
48
  const schemeSettings = Object.fromEntries(definition.map((d) => [d.id, d.default ?? '#000000']));
47
49
  schemes = [{ id: 'scheme-1', settings: schemeSettings }];
48
50
  }
49
- cache = { settings, schemes };
50
- return cache;
51
+ const resolved = { settings, schemes };
52
+ cache = { version: getThemeStoreVersion(), resolved };
53
+ return resolved;
51
54
  }
52
55
  /**
53
56
  * Global theme settings. A lazy proxy so call sites can keep reading
@@ -50,6 +50,8 @@ export interface InstallThemeOptions {
50
50
  interface ThemeStore extends InstallThemeOptions {
51
51
  }
52
52
  export declare function installTheme(options: InstallThemeOptions): void;
53
+ /** Monotonic install counter — lets derived caches detect re-installs. */
54
+ export declare function getThemeStoreVersion(): number;
53
55
  export declare function getThemeStore(): ThemeStore;
54
56
  /** Look up a page template ("index", "product", "customers/login"…). */
55
57
  export declare function getTemplate(name: string): TemplateData;
@@ -1,6 +1,14 @@
1
1
  let store = null;
2
+ let version = 0;
2
3
  export function installTheme(options) {
3
4
  store = options;
5
+ // Bump so derived caches (resolved settings) recompute — multi-tenant
6
+ // apps re-install per store from one module graph.
7
+ version++;
8
+ }
9
+ /** Monotonic install counter — lets derived caches detect re-installs. */
10
+ export function getThemeStoreVersion() {
11
+ return version;
4
12
  }
5
13
  export function getThemeStore() {
6
14
  if (!store) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalify/storefront-kit",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "The Zalify storefront SDK: framework-agnostic commerce logic (/commerce), the theme contract types and validators (/schemas), the canvas-editor bridge (/editor), and the React theme engine + shared components (/ui, /react/server). Consumed as TypeScript source inside the zalify-storefronts monorepo; published as compiled ESM + d.ts.",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -27,7 +27,7 @@ export function parseFontHandle(handle: string | undefined): ResolvedFont {
27
27
  if (!handle) return fallback;
28
28
  const match = /^(.*)_([nib])(\d)$/.exec(handle);
29
29
  if (!match) return fallback;
30
- const family = match[1]
30
+ const family = (match[1] ?? '')
31
31
  .split('_')
32
32
  .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
33
33
  .join(' ');
@@ -71,7 +71,7 @@ export function googleFontsHrefsFromSettings(
71
71
  );
72
72
  const heading =
73
73
  headingGoogle || parseFontHandle(str('type_heading_font') || undefined).family;
74
- if (!hrefs[0].includes(heading.replace(/ /g, '+'))) {
74
+ if (!hrefs[0]?.includes(heading.replace(/ /g, '+'))) {
75
75
  hrefs.push(googleFontsHref(heading, 'wght@400;500;600;700'));
76
76
  }
77
77
  if (monoGoogle) hrefs.push(googleFontsHref(monoGoogle, 'wght@400;500'));
@@ -149,7 +149,9 @@ async function fetchGoogleCss(href: string): Promise<FetchedCss | null> {
149
149
  const facePattern =
150
150
  /\/\*\s*latin\s*\*\/\s*@font-face\s*\{[^}]*?url\((https:[^)\s]+\.woff2)\)/g;
151
151
  let match: RegExpExecArray | null;
152
- while ((match = facePattern.exec(css))) latinUrls.push(match[1]);
152
+ while ((match = facePattern.exec(css))) {
153
+ if (match[1]) latinUrls.push(match[1]);
154
+ }
153
155
  return {css, latinUrls};
154
156
  } catch {
155
157
  return null;
@@ -4,7 +4,7 @@
4
4
  * preset (or flat values) in config/settings_data.json — both provided
5
5
  * at installTheme() time.
6
6
  */
7
- import {getThemeStore} from './store';
7
+ import {getThemeStore, getThemeStoreVersion} from './store';
8
8
  import type {ColorScheme, ThemeSettings} from './types';
9
9
 
10
10
  interface Resolved {
@@ -12,10 +12,12 @@ interface Resolved {
12
12
  schemes: ColorScheme[];
13
13
  }
14
14
 
15
- let cache: Resolved | null = null;
15
+ // Keyed to the install counter: multi-tenant apps call installTheme()
16
+ // again with another store's schema, which must recompute this.
17
+ let cache: {version: number; resolved: Resolved} | null = null;
16
18
 
17
19
  function resolve(): Resolved {
18
- if (cache) return cache;
20
+ if (cache && cache.version === getThemeStoreVersion()) return cache.resolved;
19
21
  const store = getThemeStore();
20
22
  const {settingsSchema, settingsData} = store.schema;
21
23
 
@@ -63,8 +65,9 @@ function resolve(): Resolved {
63
65
  schemes = [{id: 'scheme-1', settings: schemeSettings}];
64
66
  }
65
67
 
66
- cache = {settings, schemes};
67
- return cache;
68
+ const resolved = {settings, schemes};
69
+ cache = {version: getThemeStoreVersion(), resolved};
70
+ return resolved;
68
71
  }
69
72
 
70
73
  /**
@@ -56,9 +56,18 @@ export interface InstallThemeOptions {
56
56
  interface ThemeStore extends InstallThemeOptions {}
57
57
 
58
58
  let store: ThemeStore | null = null;
59
+ let version = 0;
59
60
 
60
61
  export function installTheme(options: InstallThemeOptions): void {
61
62
  store = options;
63
+ // Bump so derived caches (resolved settings) recompute — multi-tenant
64
+ // apps re-install per store from one module graph.
65
+ version++;
66
+ }
67
+
68
+ /** Monotonic install counter — lets derived caches detect re-installs. */
69
+ export function getThemeStoreVersion(): number {
70
+ return version;
62
71
  }
63
72
 
64
73
  export function getThemeStore(): ThemeStore {