@ecomweb/storefront-kit 0.6.0 → 0.9.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.
Files changed (64) hide show
  1. package/dist/api/proxy.js +5 -1
  2. package/dist/api/proxy.js.map +1 -1
  3. package/dist/api/server-client.js +7 -4
  4. package/dist/api/server-client.js.map +1 -1
  5. package/dist/auth/cookies.js +51 -33
  6. package/dist/auth/cookies.js.map +1 -1
  7. package/dist/auth/error-copy.js +2 -1
  8. package/dist/auth/error-copy.js.map +1 -1
  9. package/dist/auth/route-handlers.js +2 -2
  10. package/dist/auth/route-handlers.js.map +1 -1
  11. package/dist/auth/session-refresh.js +11 -5
  12. package/dist/auth/session-refresh.js.map +1 -1
  13. package/dist/auth/session.js +8 -4
  14. package/dist/auth/session.js.map +1 -1
  15. package/dist/checkout/get-payment-state.js.map +1 -1
  16. package/dist/checkout/initiate-gateway-payment.js.map +1 -1
  17. package/dist/checkout/order-handoff.js +10 -1
  18. package/dist/checkout/order-handoff.js.map +1 -1
  19. package/dist/checkout/use-checkout.js +8 -2
  20. package/dist/checkout/use-checkout.js.map +1 -1
  21. package/dist/config/schema.js +12 -1
  22. package/dist/config/schema.js.map +1 -1
  23. package/dist/config/server.js +9 -2
  24. package/dist/config/server.js.map +1 -1
  25. package/dist/config.d.ts +3 -3
  26. package/dist/index.d.ts +84 -24
  27. package/dist/index.js +12 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/middleware/create-storefront-middleware.js +62 -26
  30. package/dist/middleware/create-storefront-middleware.js.map +1 -1
  31. package/dist/middleware.d.ts +2 -2
  32. package/dist/{mode-YNx2aOtQ.d.ts → mode-Lm9t4qzX.d.ts} +1 -1
  33. package/dist/promotions/use-promotion-validation.js +19 -16
  34. package/dist/promotions/use-promotion-validation.js.map +1 -1
  35. package/dist/{schema-Tc0qRs-Q.d.ts → schema-Dg0ZflMW.d.ts} +1 -0
  36. package/dist/server.d.ts +8 -2
  37. package/dist/server.js +2 -0
  38. package/dist/server.js.map +1 -1
  39. package/dist/shipping/shipping-calculation-reducer.js +7 -4
  40. package/dist/shipping/shipping-calculation-reducer.js.map +1 -1
  41. package/dist/stores/get-store-by-host.js +41 -6
  42. package/dist/stores/get-store-by-host.js.map +1 -1
  43. package/dist/stores/store-subdomain.js +25 -0
  44. package/dist/stores/store-subdomain.js.map +1 -0
  45. package/dist/stores/store-traffic.js +50 -0
  46. package/dist/stores/store-traffic.js.map +1 -0
  47. package/dist/stores/ttl-cache.js +34 -0
  48. package/dist/stores/ttl-cache.js.map +1 -0
  49. package/dist/theme/define.js.map +1 -1
  50. package/dist/theme/index.js.map +1 -1
  51. package/dist/theme/preview-bridge.js +33 -0
  52. package/dist/theme/preview-bridge.js.map +1 -0
  53. package/dist/theme/preview-cookie.js +13 -6
  54. package/dist/theme/preview-cookie.js.map +1 -1
  55. package/dist/theme/preview-host.js +7 -0
  56. package/dist/theme/preview-host.js.map +1 -0
  57. package/dist/theme/read-preview-host.js +10 -0
  58. package/dist/theme/read-preview-host.js.map +1 -0
  59. package/dist/theme/read-preview-token.js +5 -3
  60. package/dist/theme/read-preview-token.js.map +1 -1
  61. package/dist/theme/settings-context.js +14 -1
  62. package/dist/theme/settings-context.js.map +1 -1
  63. package/dist/theme.d.ts +65 -5
  64. package/package.json +2 -2
@@ -1,6 +1,20 @@
1
1
  import { sdk } from "../sdk.js";
2
2
  import { isStoreSuspendedError } from "./store-suspension.js";
3
3
  import { publicConfig } from "../config.js";
4
+ import { TtlCache } from "./ttl-cache.js";
5
+ const FOUND_TTL_MS = 3e4;
6
+ const NOT_FOUND_TTL_MS = 1e4;
7
+ const MAX_HOSTS = 1e4;
8
+ const byHost = new TtlCache(MAX_HOSTS);
9
+ function clearStoreByHostCache() {
10
+ byHost.clear();
11
+ }
12
+ function platformSubdomain(hostname, platformDomain) {
13
+ const suffix = `.${platformDomain}`;
14
+ if (!hostname.endsWith(suffix)) return null;
15
+ const label = hostname.slice(0, -suffix.length);
16
+ return label && !label.includes(".") ? label : null;
17
+ }
4
18
  async function getStoreByHost(host) {
5
19
  if (host.includes("localhost") || host.includes("127.0.0.1")) {
6
20
  return {
@@ -8,34 +22,55 @@ async function getStoreByHost(host) {
8
22
  domain: null,
9
23
  isSubDomain: false,
10
24
  suspended: false,
11
- externalUrl: null
25
+ externalUrl: null,
26
+ previewSlug: null
12
27
  };
13
28
  }
29
+ const key = host.toLowerCase();
30
+ const cached = byHost.get(key);
31
+ if (cached) return cached;
14
32
  let storeRef = null;
15
33
  let domain = null;
16
34
  let suspended = false;
17
35
  let externalUrl = null;
18
- const parts = host.split(".");
19
- const platformDomain = publicConfig().platformDomainSuffix ?? "ecomsite.app";
20
- const isSubDomain = host.indexOf(platformDomain) >= 0 && parts.length === 3;
36
+ let previewSlug = null;
37
+ let failed = false;
38
+ const hostname = key.split(":")[0];
39
+ const platformDomain = (publicConfig().platformDomainSuffix ?? "ecomsite.app").toLowerCase();
40
+ const subdomain = platformSubdomain(hostname, platformDomain);
41
+ const isSubDomain = subdomain !== null;
21
42
  try {
22
- const lookupValue = isSubDomain ? parts[0] : host;
43
+ const lookupValue = subdomain ?? host;
23
44
  const foundStore = await sdk.stores.getByDomain(lookupValue);
24
45
  if (foundStore?.ref) {
25
46
  storeRef = foundStore.ref;
26
47
  domain = foundStore.config?.custom_domain || null;
27
48
  externalUrl = foundStore.storefront_url || null;
49
+ previewSlug = foundStore.preview_slug || null;
28
50
  }
29
51
  } catch (error) {
30
52
  if (isStoreSuspendedError(error)) {
31
53
  suspended = true;
32
54
  } else {
55
+ failed = true;
33
56
  console.error("Store not found for host:", host);
34
57
  }
35
58
  }
36
- return { storeRef, domain, isSubDomain, suspended, externalUrl };
59
+ const result = {
60
+ storeRef,
61
+ domain,
62
+ isSubDomain,
63
+ suspended,
64
+ externalUrl,
65
+ previewSlug
66
+ };
67
+ if (!failed) {
68
+ byHost.set(key, result, storeRef ? FOUND_TTL_MS : NOT_FOUND_TTL_MS);
69
+ }
70
+ return result;
37
71
  }
38
72
  export {
73
+ clearStoreByHostCache,
39
74
  getStoreByHost
40
75
  };
41
76
  //# sourceMappingURL=get-store-by-host.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stores/get-store-by-host.ts"],"sourcesContent":["import { sdk } from \"../sdk\";\nimport { isStoreSuspendedError } from \"./store-suspension\";\nimport { publicConfig } from \"../config\";\n\n/**\n * Get store ref and domain info from host\n * Used by middleware and API routes to determine which store is being accessed\n */\nexport async function getStoreByHost(host: string): Promise<{\n storeRef: string | null;\n domain: string | null;\n isSubDomain: boolean;\n // True when the backend identified a store for this host but rejected it\n // with STORE_SUSPENDED. There is no `ref` to route on in that case — the\n // 403 response carries no store-identifying payload — so the caller must\n // handle this without a storeRef (see proxy.ts, which rewrites to a\n // platform-level suspended page rather than `/store/<ref>`).\n suspended: boolean;\n // The live theme's URL when it is external (`storefront_url`), else null.\n // Null too when the API predates external themes.\n externalUrl: string | null;\n}> {\n if (host.includes(\"localhost\") || host.includes(\"127.0.0.1\")) {\n return {\n storeRef: null,\n domain: null,\n isSubDomain: false,\n suspended: false,\n externalUrl: null,\n };\n }\n\n let storeRef: string | null = null;\n let domain: string | null = null;\n let suspended = false;\n let externalUrl: string | null = null;\n\n const parts = host.split(\".\");\n const platformDomain =\n publicConfig().platformDomainSuffix ?? \"ecomsite.app\";\n const isSubDomain = host.indexOf(platformDomain) >= 0 && parts.length === 3;\n\n try {\n const lookupValue = isSubDomain ? parts[0] : host;\n const foundStore = await sdk.stores.getByDomain(lookupValue);\n\n if (foundStore?.ref) {\n storeRef = foundStore.ref;\n domain = foundStore.config?.custom_domain || null;\n externalUrl = foundStore.storefront_url || null;\n }\n } catch (error) {\n if (isStoreSuspendedError(error)) {\n suspended = true;\n } else {\n console.error(\"Store not found for host:\", host);\n }\n }\n\n return { storeRef, domain, isSubDomain, suspended, externalUrl };\n}\n"],"mappings":"AAAA,SAAS,WAAW;AACpB,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAM7B,eAAsB,eAAe,MAalC;AACD,MAAI,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,WAAW,GAAG;AAC5D,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,WAAW;AAAA,MACX,aAAa;AAAA,IACf;AAAA,EACF;AAEA,MAAI,WAA0B;AAC9B,MAAI,SAAwB;AAC5B,MAAI,YAAY;AAChB,MAAI,cAA6B;AAEjC,QAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,QAAM,iBACJ,aAAa,EAAE,wBAAwB;AACzC,QAAM,cAAc,KAAK,QAAQ,cAAc,KAAK,KAAK,MAAM,WAAW;AAE1E,MAAI;AACF,UAAM,cAAc,cAAc,MAAM,CAAC,IAAI;AAC7C,UAAM,aAAa,MAAM,IAAI,OAAO,YAAY,WAAW;AAE3D,QAAI,YAAY,KAAK;AACnB,iBAAW,WAAW;AACtB,eAAS,WAAW,QAAQ,iBAAiB;AAC7C,oBAAc,WAAW,kBAAkB;AAAA,IAC7C;AAAA,EACF,SAAS,OAAO;AACd,QAAI,sBAAsB,KAAK,GAAG;AAChC,kBAAY;AAAA,IACd,OAAO;AACL,cAAQ,MAAM,6BAA6B,IAAI;AAAA,IACjD;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,QAAQ,aAAa,WAAW,YAAY;AACjE;","names":[]}
1
+ {"version":3,"sources":["../../src/stores/get-store-by-host.ts"],"sourcesContent":["import { sdk } from \"../sdk\";\nimport { isStoreSuspendedError } from \"./store-suspension\";\nimport { publicConfig } from \"../config\";\nimport { TtlCache } from \"./ttl-cache\";\n\ntype StoreByHost = Awaited<ReturnType<typeof getStoreByHost>>;\n\n/**\n * How long a lookup is reused in this process. A merchant's change (custom\n * domain, external theme, suspension) reaches shoppers within this window on\n * top of the API's own Redis cache. Misses and suspensions expire sooner so\n * a new or re-enabled store shows up quickly. A failed lookup (API down) is\n * never cached: it would turn a blip into a run of 404s.\n */\nconst FOUND_TTL_MS = 30_000;\nconst NOT_FOUND_TTL_MS = 10_000;\nconst MAX_HOSTS = 10_000;\n\nconst byHost = new TtlCache<StoreByHost>(MAX_HOSTS);\n\n/** Tests only: forget every cached lookup. */\nexport function clearStoreByHostCache(): void {\n byHost.clear();\n}\n\n/**\n * The store's subdomain label when `hostname` is `<label>.<platformDomain>`\n * (a single label, so `www.shop.<platform>` and `shop.evil<platform>` are\n * not subdomains), else null.\n */\nfunction platformSubdomain(\n hostname: string,\n platformDomain: string\n): string | null {\n const suffix = `.${platformDomain}`;\n if (!hostname.endsWith(suffix)) return null;\n const label = hostname.slice(0, -suffix.length);\n return label && !label.includes(\".\") ? label : null;\n}\n\n/**\n * Get store ref and domain info from host\n * Used by middleware and API routes to determine which store is being accessed\n */\nexport async function getStoreByHost(host: string): Promise<{\n storeRef: string | null;\n domain: string | null;\n isSubDomain: boolean;\n // True when the backend identified a store for this host but rejected it\n // with STORE_SUSPENDED. There is no `ref` to route on in that case — the\n // 403 response carries no store-identifying payload — so the caller must\n // handle this without a storeRef (see proxy.ts, which rewrites to a\n // platform-level suspended page rather than `/store/<ref>`).\n suspended: boolean;\n // The live theme's URL when it is external (`storefront_url`), else null.\n // Null too when the API predates external themes.\n externalUrl: string | null;\n // A theme's preview host, p-<slug> (theme preview hosts): its slug.\n previewSlug: string | null;\n}> {\n if (host.includes(\"localhost\") || host.includes(\"127.0.0.1\")) {\n return {\n storeRef: null,\n domain: null,\n isSubDomain: false,\n suspended: false,\n externalUrl: null,\n previewSlug: null,\n };\n }\n\n const key = host.toLowerCase();\n const cached = byHost.get(key);\n if (cached) return cached;\n\n let storeRef: string | null = null;\n let domain: string | null = null;\n let suspended = false;\n let externalUrl: string | null = null;\n let previewSlug: string | null = null;\n\n let failed = false;\n\n const hostname = key.split(\":\")[0]!;\n const platformDomain = (\n publicConfig().platformDomainSuffix ?? \"ecomsite.app\"\n ).toLowerCase();\n const subdomain = platformSubdomain(hostname, platformDomain);\n const isSubDomain = subdomain !== null;\n\n try {\n const lookupValue = subdomain ?? host;\n const foundStore = await sdk.stores.getByDomain(lookupValue);\n\n if (foundStore?.ref) {\n storeRef = foundStore.ref;\n domain = foundStore.config?.custom_domain || null;\n externalUrl = foundStore.storefront_url || null;\n previewSlug = foundStore.preview_slug || null;\n }\n } catch (error) {\n if (isStoreSuspendedError(error)) {\n suspended = true;\n } else {\n failed = true;\n console.error(\"Store not found for host:\", host);\n }\n }\n\n const result = {\n storeRef,\n domain,\n isSubDomain,\n suspended,\n externalUrl,\n previewSlug,\n };\n if (!failed) {\n byHost.set(key, result, storeRef ? FOUND_TTL_MS : NOT_FOUND_TTL_MS);\n }\n return result;\n}\n"],"mappings":"AAAA,SAAS,WAAW;AACpB,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AAWzB,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAElB,MAAM,SAAS,IAAI,SAAsB,SAAS;AAG3C,SAAS,wBAA8B;AAC5C,SAAO,MAAM;AACf;AAOA,SAAS,kBACP,UACA,gBACe;AACf,QAAM,SAAS,IAAI,cAAc;AACjC,MAAI,CAAC,SAAS,SAAS,MAAM,EAAG,QAAO;AACvC,QAAM,QAAQ,SAAS,MAAM,GAAG,CAAC,OAAO,MAAM;AAC9C,SAAO,SAAS,CAAC,MAAM,SAAS,GAAG,IAAI,QAAQ;AACjD;AAMA,eAAsB,eAAe,MAelC;AACD,MAAI,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,WAAW,GAAG;AAC5D,WAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,WAAW;AAAA,MACX,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,MAAM,KAAK,YAAY;AAC7B,QAAM,SAAS,OAAO,IAAI,GAAG;AAC7B,MAAI,OAAQ,QAAO;AAEnB,MAAI,WAA0B;AAC9B,MAAI,SAAwB;AAC5B,MAAI,YAAY;AAChB,MAAI,cAA6B;AACjC,MAAI,cAA6B;AAEjC,MAAI,SAAS;AAEb,QAAM,WAAW,IAAI,MAAM,GAAG,EAAE,CAAC;AACjC,QAAM,kBACJ,aAAa,EAAE,wBAAwB,gBACvC,YAAY;AACd,QAAM,YAAY,kBAAkB,UAAU,cAAc;AAC5D,QAAM,cAAc,cAAc;AAElC,MAAI;AACF,UAAM,cAAc,aAAa;AACjC,UAAM,aAAa,MAAM,IAAI,OAAO,YAAY,WAAW;AAE3D,QAAI,YAAY,KAAK;AACnB,iBAAW,WAAW;AACtB,eAAS,WAAW,QAAQ,iBAAiB;AAC7C,oBAAc,WAAW,kBAAkB;AAC3C,oBAAc,WAAW,gBAAgB;AAAA,IAC3C;AAAA,EACF,SAAS,OAAO;AACd,QAAI,sBAAsB,KAAK,GAAG;AAChC,kBAAY;AAAA,IACd,OAAO;AACL,eAAS;AACT,cAAQ,MAAM,6BAA6B,IAAI;AAAA,IACjD;AAAA,EACF;AAEA,QAAM,SAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,QAAQ;AACX,WAAO,IAAI,KAAK,QAAQ,WAAW,eAAe,gBAAgB;AAAA,EACpE;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,25 @@
1
+ import { sdk } from "../sdk.js";
2
+ import { TtlCache } from "./ttl-cache.js";
3
+ const TTL_MS = 6e4;
4
+ const MAX_REFS = 1e4;
5
+ const byRef = new TtlCache(MAX_REFS);
6
+ function clearStoreSubdomainCache() {
7
+ byRef.clear();
8
+ }
9
+ async function getStoreSubdomain(storeRef) {
10
+ const cached = byRef.get(storeRef);
11
+ if (cached !== void 0) return cached;
12
+ const store = await sdk.stores.getById(storeRef, {
13
+ includeConfig: true,
14
+ includeSettings: false,
15
+ includeEmbeddedScripts: false
16
+ });
17
+ const subdomain = store?.config?.subdomain || null;
18
+ byRef.set(storeRef, subdomain, TTL_MS);
19
+ return subdomain;
20
+ }
21
+ export {
22
+ clearStoreSubdomainCache,
23
+ getStoreSubdomain
24
+ };
25
+ //# sourceMappingURL=store-subdomain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/stores/store-subdomain.ts"],"sourcesContent":["import { sdk } from \"../sdk\";\nimport { TtlCache } from \"./ttl-cache\";\n\nconst TTL_MS = 60_000;\nconst MAX_REFS = 10_000;\n\nconst byRef = new TtlCache<string | null>(MAX_REFS);\n\n/** Tests only: forget every cached lookup. */\nexport function clearStoreSubdomainCache(): void {\n byRef.clear();\n}\n\n/**\n * The platform subdomain label of the store `storeRef`, or null when there\n * is no such store or it has none. Throws when the API cannot be reached, so\n * the caller can tell \"no store\" from \"don't know\" (only the former is\n * cached).\n */\nexport async function getStoreSubdomain(\n storeRef: string\n): Promise<string | null> {\n const cached = byRef.get(storeRef);\n if (cached !== undefined) return cached;\n\n const store = await sdk.stores.getById(storeRef, {\n includeConfig: true,\n includeSettings: false,\n includeEmbeddedScripts: false,\n });\n const subdomain = store?.config?.subdomain || null;\n byRef.set(storeRef, subdomain, TTL_MS);\n return subdomain;\n}\n"],"mappings":"AAAA,SAAS,WAAW;AACpB,SAAS,gBAAgB;AAEzB,MAAM,SAAS;AACf,MAAM,WAAW;AAEjB,MAAM,QAAQ,IAAI,SAAwB,QAAQ;AAG3C,SAAS,2BAAiC;AAC/C,QAAM,MAAM;AACd;AAQA,eAAsB,kBACpB,UACwB;AACxB,QAAM,SAAS,MAAM,IAAI,QAAQ;AACjC,MAAI,WAAW,OAAW,QAAO;AAEjC,QAAM,QAAQ,MAAM,IAAI,OAAO,QAAQ,UAAU;AAAA,IAC/C,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB,wBAAwB;AAAA,EAC1B,CAAC;AACD,QAAM,YAAY,OAAO,QAAQ,aAAa;AAC9C,QAAM,IAAI,UAAU,WAAW,MAAM;AACrC,SAAO;AACT;","names":[]}
@@ -0,0 +1,50 @@
1
+ import { serverConfig } from "../config/server.js";
2
+ const WINDOW_MS = 6e4;
3
+ class StoreTraffic {
4
+ constructor(threshold, log = console.warn) {
5
+ this.threshold = threshold;
6
+ this.log = log;
7
+ }
8
+ threshold;
9
+ log;
10
+ windowStart = null;
11
+ counts = /* @__PURE__ */ new Map();
12
+ hit(storeRef, now = Date.now()) {
13
+ if (this.threshold <= 0) return;
14
+ if (this.windowStart === null) this.windowStart = now;
15
+ if (now - this.windowStart >= WINDOW_MS) {
16
+ this.flush();
17
+ this.windowStart = now;
18
+ }
19
+ const count = (this.counts.get(storeRef) ?? 0) + 1;
20
+ this.counts.set(storeRef, count);
21
+ if (count === this.threshold) {
22
+ this.log(
23
+ `[store-traffic] over store=${storeRef} requests=${count} window=60s threshold=${this.threshold}`
24
+ );
25
+ }
26
+ }
27
+ flush() {
28
+ for (const [storeRef, count] of this.counts) {
29
+ if (count >= this.threshold) {
30
+ this.log(
31
+ `[store-traffic] peak store=${storeRef} requests=${count} window=60s threshold=${this.threshold}`
32
+ );
33
+ }
34
+ }
35
+ this.counts.clear();
36
+ }
37
+ }
38
+ let shared;
39
+ function recordStoreRequest(storeRef) {
40
+ try {
41
+ shared ??= new StoreTraffic(serverConfig().storeTrafficLogPerMinute);
42
+ shared.hit(storeRef);
43
+ } catch {
44
+ }
45
+ }
46
+ export {
47
+ StoreTraffic,
48
+ recordStoreRequest
49
+ };
50
+ //# sourceMappingURL=store-traffic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/stores/store-traffic.ts"],"sourcesContent":["import { serverConfig } from \"../config/server\";\n\nconst WINDOW_MS = 60_000;\n\n/**\n * Requests per store on this server, in fixed one-minute windows: the data\n * for sizing a per-store limit on the shared storefront. Log only; nothing\n * is refused.\n *\n * - A store reaching the threshold is logged at once (\"over\").\n * - When a window closes, every store that reached it is logged with its\n * final count (\"peak\"). Windows close on the next request, so a server\n * that goes quiet logs its last window late.\n *\n * Counts are this server's share only: multiply by the pod count for the\n * whole fleet.\n */\nexport class StoreTraffic {\n private windowStart: number | null = null;\n private counts = new Map<string, number>();\n\n constructor(\n private readonly threshold: number,\n private readonly log: (line: string) => void = console.warn\n ) {}\n\n hit(storeRef: string, now = Date.now()): void {\n if (this.threshold <= 0) return;\n if (this.windowStart === null) this.windowStart = now;\n if (now - this.windowStart >= WINDOW_MS) {\n this.flush();\n this.windowStart = now;\n }\n\n const count = (this.counts.get(storeRef) ?? 0) + 1;\n this.counts.set(storeRef, count);\n if (count === this.threshold) {\n this.log(\n `[store-traffic] over store=${storeRef} requests=${count} window=60s threshold=${this.threshold}`\n );\n }\n }\n\n private flush(): void {\n for (const [storeRef, count] of this.counts) {\n if (count >= this.threshold) {\n this.log(\n `[store-traffic] peak store=${storeRef} requests=${count} window=60s threshold=${this.threshold}`\n );\n }\n }\n this.counts.clear();\n }\n}\n\nlet shared: StoreTraffic | undefined;\n\n/**\n * Counts one request to `storeRef` (see StoreTraffic). Never throws: this is\n * measurement, and must not take a page down.\n */\nexport function recordStoreRequest(storeRef: string): void {\n try {\n shared ??= new StoreTraffic(serverConfig().storeTrafficLogPerMinute);\n shared.hit(storeRef);\n } catch {\n // Unreadable config: count nothing (the page reports it elsewhere).\n }\n}\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,MAAM,YAAY;AAeX,MAAM,aAAa;AAAA,EAIxB,YACmB,WACA,MAA8B,QAAQ,MACvD;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EALX,cAA6B;AAAA,EAC7B,SAAS,oBAAI,IAAoB;AAAA,EAOzC,IAAI,UAAkB,MAAM,KAAK,IAAI,GAAS;AAC5C,QAAI,KAAK,aAAa,EAAG;AACzB,QAAI,KAAK,gBAAgB,KAAM,MAAK,cAAc;AAClD,QAAI,MAAM,KAAK,eAAe,WAAW;AACvC,WAAK,MAAM;AACX,WAAK,cAAc;AAAA,IACrB;AAEA,UAAM,SAAS,KAAK,OAAO,IAAI,QAAQ,KAAK,KAAK;AACjD,SAAK,OAAO,IAAI,UAAU,KAAK;AAC/B,QAAI,UAAU,KAAK,WAAW;AAC5B,WAAK;AAAA,QACH,8BAA8B,QAAQ,aAAa,KAAK,yBAAyB,KAAK,SAAS;AAAA,MACjG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,QAAc;AACpB,eAAW,CAAC,UAAU,KAAK,KAAK,KAAK,QAAQ;AAC3C,UAAI,SAAS,KAAK,WAAW;AAC3B,aAAK;AAAA,UACH,8BAA8B,QAAQ,aAAa,KAAK,yBAAyB,KAAK,SAAS;AAAA,QACjG;AAAA,MACF;AAAA,IACF;AACA,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;AAEA,IAAI;AAMG,SAAS,mBAAmB,UAAwB;AACzD,MAAI;AACF,eAAW,IAAI,aAAa,aAAa,EAAE,wBAAwB;AACnE,WAAO,IAAI,QAAQ;AAAA,EACrB,QAAQ;AAAA,EAER;AACF;","names":[]}
@@ -0,0 +1,34 @@
1
+ class TtlCache {
2
+ constructor(maxEntries) {
3
+ this.maxEntries = maxEntries;
4
+ }
5
+ maxEntries;
6
+ entries = /* @__PURE__ */ new Map();
7
+ get(key, now = Date.now()) {
8
+ const entry = this.entries.get(key);
9
+ if (!entry) return void 0;
10
+ this.entries.delete(key);
11
+ if (entry.expires <= now) return void 0;
12
+ this.entries.set(key, entry);
13
+ return entry.value;
14
+ }
15
+ set(key, value, ttlMs, now = Date.now()) {
16
+ this.entries.delete(key);
17
+ this.entries.set(key, { value, expires: now + ttlMs });
18
+ while (this.entries.size > this.maxEntries) {
19
+ const oldest = this.entries.keys().next().value;
20
+ if (oldest === void 0) break;
21
+ this.entries.delete(oldest);
22
+ }
23
+ }
24
+ clear() {
25
+ this.entries.clear();
26
+ }
27
+ get size() {
28
+ return this.entries.size;
29
+ }
30
+ }
31
+ export {
32
+ TtlCache
33
+ };
34
+ //# sourceMappingURL=ttl-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/stores/ttl-cache.ts"],"sourcesContent":["/**\n * A small in-process cache with per-entry expiry and a size bound.\n *\n * The middleware resolves the store on every request; without this each one\n * is a round trip to the API (which caches in Redis, but the hop remains).\n * The bound matters because the key is the request's Host: random hosts\n * under the platform domain would otherwise grow the map without limit.\n *\n * Map keeps insertion order, so the first key is the oldest write; a hit\n * re-inserts its entry, which makes eviction least-recently-used.\n */\nexport class TtlCache<V> {\n private readonly entries = new Map<string, { value: V; expires: number }>();\n\n constructor(private readonly maxEntries: number) {}\n\n get(key: string, now = Date.now()): V | undefined {\n const entry = this.entries.get(key);\n if (!entry) return undefined;\n this.entries.delete(key);\n if (entry.expires <= now) return undefined;\n this.entries.set(key, entry);\n return entry.value;\n }\n\n set(key: string, value: V, ttlMs: number, now = Date.now()): void {\n this.entries.delete(key);\n this.entries.set(key, { value, expires: now + ttlMs });\n while (this.entries.size > this.maxEntries) {\n const oldest = this.entries.keys().next().value;\n if (oldest === undefined) break;\n this.entries.delete(oldest);\n }\n }\n\n clear(): void {\n this.entries.clear();\n }\n\n get size(): number {\n return this.entries.size;\n }\n}\n"],"mappings":"AAWO,MAAM,SAAY;AAAA,EAGvB,YAA6B,YAAoB;AAApB;AAAA,EAAqB;AAAA,EAArB;AAAA,EAFZ,UAAU,oBAAI,IAA2C;AAAA,EAI1E,IAAI,KAAa,MAAM,KAAK,IAAI,GAAkB;AAChD,UAAM,QAAQ,KAAK,QAAQ,IAAI,GAAG;AAClC,QAAI,CAAC,MAAO,QAAO;AACnB,SAAK,QAAQ,OAAO,GAAG;AACvB,QAAI,MAAM,WAAW,IAAK,QAAO;AACjC,SAAK,QAAQ,IAAI,KAAK,KAAK;AAC3B,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,IAAI,KAAa,OAAU,OAAe,MAAM,KAAK,IAAI,GAAS;AAChE,SAAK,QAAQ,OAAO,GAAG;AACvB,SAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,SAAS,MAAM,MAAM,CAAC;AACrD,WAAO,KAAK,QAAQ,OAAO,KAAK,YAAY;AAC1C,YAAM,SAAS,KAAK,QAAQ,KAAK,EAAE,KAAK,EAAE;AAC1C,UAAI,WAAW,OAAW;AAC1B,WAAK,QAAQ,OAAO,MAAM;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,SAAK,QAAQ,MAAM;AAAA,EACrB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theme/define.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type {\n Banner,\n StoreConfigurationInfo,\n ThemeSchema,\n ThemeSettingsOf,\n} from \"@ecomweb/sdk\";\n\n/**\n * The theme contract (spec: schema-driven themes §5.2). A theme declares its\n * settings with `defineSchema` and fills the slots the shared routes render.\n * Routes load data through the kit and pass it in: a theme is presentation.\n */\n\nexport function defineSchema<const S extends ThemeSchema>(schema: S): S {\n return schema;\n}\n\nexport interface ThemeInfo {\n id: string;\n name: string;\n version: string;\n author: string;\n}\n\n/** A slot may be a server component (async) or a plain one. */\nexport type ThemeSlot<P> = (props: P) => ReactNode | Promise<ReactNode>;\n\nexport interface ThemeSlotProps<V> {\n store: StoreConfigurationInfo;\n storeRef: string;\n settings: V;\n}\n\nexport interface LayoutSlotProps<V> extends ThemeSlotProps<V> {\n children: ReactNode;\n}\n\nexport interface HomePageSlotProps<V> extends ThemeSlotProps<V> {\n banners: Banner[];\n}\n\nexport interface ThemeComponents<V> {\n Layout?: ThemeSlot<LayoutSlotProps<V>>;\n HomePage?: ThemeSlot<HomePageSlotProps<V>>;\n}\n\nexport type ThemeSlotName = keyof ThemeComponents<unknown>;\n\nexport interface ThemeDefinition<S extends ThemeSchema = ThemeSchema> {\n info: ThemeInfo;\n schema: S;\n components: ThemeComponents<ThemeSettingsOf<S>>;\n /** CSS custom properties for :root, from the resolved settings. */\n styles?: (settings: ThemeSettingsOf<S>) => Record<string, string>;\n}\n\n/**\n * A theme of unknown schema, as the registry holds it. Its slots are called\n * with settings resolved against its own schema.\n */\nexport interface AnyThemeDefinition {\n info: ThemeInfo;\n schema: ThemeSchema;\n components: ThemeComponents<any>;\n styles?: (settings: any) => Record<string, string>;\n}\n\nexport function defineTheme<const S extends ThemeSchema>(\n theme: ThemeDefinition<S>\n): ThemeDefinition<S> {\n return theme;\n}\n"],"mappings":"AAcO,SAAS,aAA0C,QAAc;AACtE,SAAO;AACT;AAoDO,SAAS,YACd,OACoB;AACpB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/theme/define.ts"],"sourcesContent":["import type { ComponentType, ReactNode } from \"react\";\nimport type {\n BlogCategory,\n BlogPost,\n Collection,\n ContentPage,\n Product,\n ProductDetail,\n ProductWithVariants,\n SearchProduct,\n StoreConfigurationInfo,\n ThemeSchema,\n ThemeSettingsOf,\n} from \"@ecomweb/sdk\";\n\n/**\n * The theme contract (spec: schema-driven themes §5.2). A theme declares its\n * settings with `defineSchema` and fills the slots the shared routes render.\n * Routes load data through the kit and pass it in: a theme is presentation.\n */\n\nexport function defineSchema<const S extends ThemeSchema>(schema: S): S {\n return schema;\n}\n\nexport interface ThemeInfo {\n id: string;\n name: string;\n version: string;\n author: string;\n}\n\n/** A slot may be a server component (async) or a plain one. */\nexport type ThemeSlot<P> = (props: P) => ReactNode | Promise<ReactNode>;\n\nexport interface ThemeSlotProps<V> {\n store: StoreConfigurationInfo;\n storeRef: string;\n settings: V;\n}\n\nexport interface LayoutSlotProps<V> extends ThemeSlotProps<V> {\n children: ReactNode;\n}\n\n/** Banners and the shop introduction are theme settings (default@1.1.0). */\nexport type HomePageSlotProps<V> = ThemeSlotProps<V>;\n\nexport interface ProductPageSlotProps<V> extends ThemeSlotProps<V> {\n product: ProductDetail;\n}\n\n/** The collection route's query string, as the filters read it. */\nexport interface CollectionSearchParams {\n q?: string;\n category?: string;\n page?: string;\n sort?: string;\n min_price?: string;\n max_price?: string;\n has_promotion?: string;\n}\n\nexport interface CollectionPageSlotProps<V> extends ThemeSlotProps<V> {\n slug: string;\n /** Null for the \"all\" pseudo-collection. */\n collection: Collection | null;\n searchParams: CollectionSearchParams;\n}\n\nexport interface ContentPageSlotProps<V> extends ThemeSlotProps<V> {\n page: ContentPage;\n isPreview: boolean;\n}\n\nexport interface BlogIndexSlotProps<V> extends ThemeSlotProps<V> {\n blogTitle: string;\n posts: BlogPost[];\n categories: BlogCategory[];\n total: number;\n page: number;\n totalPages: number;\n /** Category id filter from the query string, \"\" when none. */\n category: string;\n search: string;\n}\n\nexport interface BlogPostSlotProps<V> extends ThemeSlotProps<V> {\n blogTitle: string;\n post: BlogPost;\n /** The post's linked products, in the post's order. */\n products: SearchProduct[];\n}\n\nexport interface ThemeComponents<V> {\n Layout?: ThemeSlot<LayoutSlotProps<V>>;\n HomePage?: ThemeSlot<HomePageSlotProps<V>>;\n ProductPage?: ThemeSlot<ProductPageSlotProps<V>>;\n CollectionPage?: ThemeSlot<CollectionPageSlotProps<V>>;\n ContentPage?: ThemeSlot<ContentPageSlotProps<V>>;\n BlogIndex?: ThemeSlot<BlogIndexSlotProps<V>>;\n BlogPost?: ThemeSlot<BlogPostSlotProps<V>>;\n}\n\n/**\n * Components rendered inside client components, so they cannot be resolved\n * on the server per request. The app keeps a registry keyed by theme id.\n */\nexport interface ProductCardProps {\n product: Product | ProductWithVariants | SearchProduct;\n storeRef?: string;\n}\n\nexport interface NotFoundProps {\n /** Null when the store itself was not found. */\n storeRef: string | null;\n}\n\nexport interface ThemeClientComponents {\n ProductCard?: ComponentType<ProductCardProps>;\n NotFound?: ComponentType<NotFoundProps>;\n}\n\nexport type ThemeSlotName = keyof ThemeComponents<unknown>;\n\nexport interface ThemeDefinition<S extends ThemeSchema = ThemeSchema> {\n info: ThemeInfo;\n schema: S;\n components: ThemeComponents<ThemeSettingsOf<S>>;\n /** CSS custom properties for :root, from the resolved settings. */\n styles?: (settings: ThemeSettingsOf<S>) => Record<string, string>;\n}\n\n/**\n * A theme of unknown schema, as the registry holds it. Its slots are called\n * with settings resolved against its own schema.\n */\nexport interface AnyThemeDefinition {\n info: ThemeInfo;\n schema: ThemeSchema;\n components: ThemeComponents<any>;\n styles?: (settings: any) => Record<string, string>;\n}\n\nexport function defineTheme<const S extends ThemeSchema>(\n theme: ThemeDefinition<S>\n): ThemeDefinition<S> {\n return theme;\n}\n"],"mappings":"AAqBO,SAAS,aAA0C,QAAc;AACtE,SAAO;AACT;AAyHO,SAAS,YACd,OACoB;AACpB,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theme/index.ts"],"sourcesContent":["// @ecomweb/storefront-kit/theme: authoring a theme (schema, definition, slot\n// types). No side effects, so build tools such as CI's theme export can import\n// it without a storefront configuration.\nexport { defineSchema, defineTheme } from \"./define\";\nexport type {\n AnyThemeDefinition,\n HomePageSlotProps,\n LayoutSlotProps,\n ThemeComponents,\n ThemeDefinition,\n ThemeInfo,\n ThemeSlot,\n ThemeSlotName,\n ThemeSlotProps,\n} from \"./define\";\n"],"mappings":"AAGA,SAAS,cAAc,mBAAmB;","names":[]}
1
+ {"version":3,"sources":["../../src/theme/index.ts"],"sourcesContent":["// @ecomweb/storefront-kit/theme: authoring a theme (schema, definition, slot\n// types). No side effects, so build tools such as CI's theme export can import\n// it without a storefront configuration.\nexport { defineSchema, defineTheme } from \"./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 \"./define\";\n"],"mappings":"AAGA,SAAS,cAAc,mBAAmB;","names":[]}
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { useEffect, useRef } from "react";
3
+ const THEME_PREVIEW_MESSAGE = "ecomweb:theme-preview";
4
+ const THEME_PREVIEW_FRAME_ATTR = "data-theme-preview-frame";
5
+ function ThemePreviewBridge({ onRefresh }) {
6
+ const refresh = useRef(onRefresh);
7
+ refresh.current = onRefresh;
8
+ useEffect(() => {
9
+ const parent = window.parent;
10
+ if (!parent || parent === window) return;
11
+ const root = document.documentElement;
12
+ root.setAttribute(THEME_PREVIEW_FRAME_ATTR, "");
13
+ const onMessage = (event) => {
14
+ if (event.source !== parent) return;
15
+ const data = event.data;
16
+ if (data?.type !== THEME_PREVIEW_MESSAGE) return;
17
+ if (data.action === "refresh") refresh.current();
18
+ };
19
+ window.addEventListener("message", onMessage);
20
+ parent.postMessage({ type: THEME_PREVIEW_MESSAGE, action: "ready" }, "*");
21
+ return () => {
22
+ window.removeEventListener("message", onMessage);
23
+ root.removeAttribute(THEME_PREVIEW_FRAME_ATTR);
24
+ };
25
+ }, []);
26
+ return null;
27
+ }
28
+ export {
29
+ THEME_PREVIEW_FRAME_ATTR,
30
+ THEME_PREVIEW_MESSAGE,
31
+ ThemePreviewBridge
32
+ };
33
+ //# sourceMappingURL=preview-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/theme/preview-bridge.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\n/** The messages the dashboard's theme editor and its preview frame trade. */\nexport const THEME_PREVIEW_MESSAGE = \"ecomweb:theme-preview\";\n\n/** Set on <html> while the preview is inside the theme editor's frame. */\nexport const THEME_PREVIEW_FRAME_ATTR = \"data-theme-preview-frame\";\n\n/**\n * The storefront side of the theme editor's live preview. Inside the\n * editor's frame it says it is ready, then calls onRefresh each time the\n * editor has sent its unsaved values to the API, which the preview token\n * reads them back from. The app re-renders the page in place (router.refresh:\n * server components again, scroll and client state kept); routing is the\n * app's, not the kit's. Only the frame's parent is listened to; outside a\n * frame it does nothing.\n */\nexport function ThemePreviewBridge({ onRefresh }: { onRefresh: () => void }) {\n // The latest callback, without listening again each render.\n const refresh = useRef(onRefresh);\n refresh.current = onRefresh;\n\n useEffect(() => {\n const parent = window.parent;\n if (!parent || parent === window) return;\n const root = document.documentElement;\n root.setAttribute(THEME_PREVIEW_FRAME_ATTR, \"\");\n\n const onMessage = (event: MessageEvent) => {\n if (event.source !== parent) return;\n const data = event.data as { type?: unknown; action?: unknown } | null;\n if (data?.type !== THEME_PREVIEW_MESSAGE) return;\n if (data.action === \"refresh\") refresh.current();\n };\n window.addEventListener(\"message\", onMessage);\n // The editor holds back live updates until a storefront says it can.\n parent.postMessage({ type: THEME_PREVIEW_MESSAGE, action: \"ready\" }, \"*\");\n return () => {\n window.removeEventListener(\"message\", onMessage);\n root.removeAttribute(THEME_PREVIEW_FRAME_ATTR);\n };\n }, []);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAG3B,MAAM,wBAAwB;AAG9B,MAAM,2BAA2B;AAWjC,SAAS,mBAAmB,EAAE,UAAU,GAA8B;AAE3E,QAAM,UAAU,OAAO,SAAS;AAChC,UAAQ,UAAU;AAElB,YAAU,MAAM;AACd,UAAM,SAAS,OAAO;AACtB,QAAI,CAAC,UAAU,WAAW,OAAQ;AAClC,UAAM,OAAO,SAAS;AACtB,SAAK,aAAa,0BAA0B,EAAE;AAE9C,UAAM,YAAY,CAAC,UAAwB;AACzC,UAAI,MAAM,WAAW,OAAQ;AAC7B,YAAM,OAAO,MAAM;AACnB,UAAI,MAAM,SAAS,sBAAuB;AAC1C,UAAI,KAAK,WAAW,UAAW,SAAQ,QAAQ;AAAA,IACjD;AACA,WAAO,iBAAiB,WAAW,SAAS;AAE5C,WAAO,YAAY,EAAE,MAAM,uBAAuB,QAAQ,QAAQ,GAAG,GAAG;AACxE,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,SAAS;AAC/C,WAAK,gBAAgB,wBAAwB;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
@@ -1,9 +1,13 @@
1
1
  import { NextResponse } from "next/server";
2
+ import { hostOnlyCookieName, secureCookies } from "../auth/cookies.js";
2
3
  import { publicNextUrl } from "../request/public-url.js";
3
4
  const THEME_PREVIEW_COOKIE = "ecomweb_theme_preview";
4
5
  const THEME_PREVIEW_PARAM = "preview_theme";
5
6
  const MAX_TOKEN_LENGTH = 2048;
6
7
  const MAX_AGE_SECONDS = 24 * 60 * 60;
8
+ function themePreviewCookieName(cookiePath) {
9
+ return hostOnlyCookieName(THEME_PREVIEW_COOKIE, cookiePath);
10
+ }
7
11
  function applyThemePreview(req, cookiePath) {
8
12
  const value = req.nextUrl.searchParams.get(THEME_PREVIEW_PARAM);
9
13
  if (value === null) return null;
@@ -11,22 +15,25 @@ function applyThemePreview(req, cookiePath) {
11
15
  url.searchParams.delete(THEME_PREVIEW_PARAM);
12
16
  const res = NextResponse.redirect(url, 307);
13
17
  const valid = value !== "exit" && value.length > 0 && value.length <= MAX_TOKEN_LENGTH;
14
- res.cookies.set(THEME_PREVIEW_COOKIE, valid ? value : "", {
18
+ const production = secureCookies();
19
+ res.cookies.set(themePreviewCookieName(cookiePath), valid ? value : "", {
15
20
  httpOnly: true,
16
- secure: process.env.NODE_ENV === "production",
17
- sameSite: "lax",
21
+ // Locally the dashboard and the store share a site (localhost), and
22
+ // SameSite=None needs https.
23
+ ...production ? { secure: true, sameSite: "none", partitioned: true } : { secure: false, sameSite: "lax" },
18
24
  path: cookiePath,
19
25
  maxAge: valid ? MAX_AGE_SECONDS : 0
20
26
  });
21
27
  return res;
22
28
  }
23
- function hasThemePreview(req) {
24
- return !!req.cookies.get(THEME_PREVIEW_COOKIE)?.value;
29
+ function hasThemePreview(req, cookiePath) {
30
+ return !!req.cookies.get(themePreviewCookieName(cookiePath))?.value;
25
31
  }
26
32
  export {
27
33
  THEME_PREVIEW_COOKIE,
28
34
  THEME_PREVIEW_PARAM,
29
35
  applyThemePreview,
30
- hasThemePreview
36
+ hasThemePreview,
37
+ themePreviewCookieName
31
38
  };
32
39
  //# sourceMappingURL=preview-cookie.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theme/preview-cookie.ts"],"sourcesContent":["import { NextResponse, type NextRequest } from \"next/server\";\nimport { publicNextUrl } from \"../request/public-url\";\n\nexport const THEME_PREVIEW_COOKIE = \"ecomweb_theme_preview\";\nexport const THEME_PREVIEW_PARAM = \"preview_theme\";\nconst MAX_TOKEN_LENGTH = 2048;\nconst MAX_AGE_SECONDS = 24 * 60 * 60;\n\n/**\n * A dashboard preview link (`?preview_theme=<token>`) becomes an httpOnly\n * cookie scoped to the store, then a redirect to the clean URL, so the token\n * never stays in the address bar or in shared links. `preview_theme=exit`\n * clears it. The API validates the token on every render (themes spec §6.1).\n */\nexport function applyThemePreview(\n req: NextRequest,\n cookiePath: string\n): NextResponse | null {\n const value = req.nextUrl.searchParams.get(THEME_PREVIEW_PARAM);\n if (value === null) return null;\n const url = publicNextUrl(req);\n url.searchParams.delete(THEME_PREVIEW_PARAM);\n const res = NextResponse.redirect(url, 307);\n const valid =\n value !== \"exit\" && value.length > 0 && value.length <= MAX_TOKEN_LENGTH;\n res.cookies.set(THEME_PREVIEW_COOKIE, valid ? value : \"\", {\n httpOnly: true,\n secure: process.env.NODE_ENV === \"production\",\n sameSite: \"lax\",\n path: cookiePath,\n maxAge: valid ? MAX_AGE_SECONDS : 0,\n });\n return res;\n}\n\nexport function hasThemePreview(req: NextRequest): boolean {\n return !!req.cookies.get(THEME_PREVIEW_COOKIE)?.value;\n}\n"],"mappings":"AAAA,SAAS,oBAAsC;AAC/C,SAAS,qBAAqB;AAEvB,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AACnC,MAAM,mBAAmB;AACzB,MAAM,kBAAkB,KAAK,KAAK;AAQ3B,SAAS,kBACd,KACA,YACqB;AACrB,QAAM,QAAQ,IAAI,QAAQ,aAAa,IAAI,mBAAmB;AAC9D,MAAI,UAAU,KAAM,QAAO;AAC3B,QAAM,MAAM,cAAc,GAAG;AAC7B,MAAI,aAAa,OAAO,mBAAmB;AAC3C,QAAM,MAAM,aAAa,SAAS,KAAK,GAAG;AAC1C,QAAM,QACJ,UAAU,UAAU,MAAM,SAAS,KAAK,MAAM,UAAU;AAC1D,MAAI,QAAQ,IAAI,sBAAsB,QAAQ,QAAQ,IAAI;AAAA,IACxD,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,QAAQ,QAAQ,kBAAkB;AAAA,EACpC,CAAC;AACD,SAAO;AACT;AAEO,SAAS,gBAAgB,KAA2B;AACzD,SAAO,CAAC,CAAC,IAAI,QAAQ,IAAI,oBAAoB,GAAG;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../src/theme/preview-cookie.ts"],"sourcesContent":["import { NextResponse, type NextRequest } from \"next/server\";\nimport { hostOnlyCookieName, secureCookies } from \"../auth/cookies\";\nimport { publicNextUrl } from \"../request/public-url\";\n\nexport const THEME_PREVIEW_COOKIE = \"ecomweb_theme_preview\";\nexport const THEME_PREVIEW_PARAM = \"preview_theme\";\nconst MAX_TOKEN_LENGTH = 2048;\nconst MAX_AGE_SECONDS = 24 * 60 * 60;\n\n/**\n * A dashboard preview link (`?preview_theme=<token>`) becomes an httpOnly\n * cookie scoped to the store, then a redirect to the clean URL, so the token\n * never stays in the address bar or in shared links. `preview_theme=exit`\n * clears it. The API validates the token on every render (themes spec §6.1).\n * In production the cookie also works inside the dashboard's theme editor,\n * which frames the store from another site: SameSite=None, partitioned by\n * the top-level site (CHIPS), so it never follows the store anywhere else.\n */\n/** The preview cookie's name at `cookiePath` (see hostOnlyCookieName). */\nexport function themePreviewCookieName(cookiePath: string): string {\n return hostOnlyCookieName(THEME_PREVIEW_COOKIE, cookiePath);\n}\n\nexport function applyThemePreview(\n req: NextRequest,\n cookiePath: string\n): NextResponse | null {\n const value = req.nextUrl.searchParams.get(THEME_PREVIEW_PARAM);\n if (value === null) return null;\n const url = publicNextUrl(req);\n url.searchParams.delete(THEME_PREVIEW_PARAM);\n const res = NextResponse.redirect(url, 307);\n const valid =\n value !== \"exit\" && value.length > 0 && value.length <= MAX_TOKEN_LENGTH;\n const production = secureCookies();\n res.cookies.set(themePreviewCookieName(cookiePath), valid ? value : \"\", {\n httpOnly: true,\n // Locally the dashboard and the store share a site (localhost), and\n // SameSite=None needs https.\n ...(production\n ? { secure: true, sameSite: \"none\" as const, partitioned: true }\n : { secure: false, sameSite: \"lax\" as const }),\n path: cookiePath,\n maxAge: valid ? MAX_AGE_SECONDS : 0,\n });\n return res;\n}\n\nexport function hasThemePreview(req: NextRequest, cookiePath: string): boolean {\n return !!req.cookies.get(themePreviewCookieName(cookiePath))?.value;\n}\n"],"mappings":"AAAA,SAAS,oBAAsC;AAC/C,SAAS,oBAAoB,qBAAqB;AAClD,SAAS,qBAAqB;AAEvB,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AACnC,MAAM,mBAAmB;AACzB,MAAM,kBAAkB,KAAK,KAAK;AAY3B,SAAS,uBAAuB,YAA4B;AACjE,SAAO,mBAAmB,sBAAsB,UAAU;AAC5D;AAEO,SAAS,kBACd,KACA,YACqB;AACrB,QAAM,QAAQ,IAAI,QAAQ,aAAa,IAAI,mBAAmB;AAC9D,MAAI,UAAU,KAAM,QAAO;AAC3B,QAAM,MAAM,cAAc,GAAG;AAC7B,MAAI,aAAa,OAAO,mBAAmB;AAC3C,QAAM,MAAM,aAAa,SAAS,KAAK,GAAG;AAC1C,QAAM,QACJ,UAAU,UAAU,MAAM,SAAS,KAAK,MAAM,UAAU;AAC1D,QAAM,aAAa,cAAc;AACjC,MAAI,QAAQ,IAAI,uBAAuB,UAAU,GAAG,QAAQ,QAAQ,IAAI;AAAA,IACtE,UAAU;AAAA;AAAA;AAAA,IAGV,GAAI,aACA,EAAE,QAAQ,MAAM,UAAU,QAAiB,aAAa,KAAK,IAC7D,EAAE,QAAQ,OAAO,UAAU,MAAe;AAAA,IAC9C,MAAM;AAAA,IACN,QAAQ,QAAQ,kBAAkB;AAAA,EACpC,CAAC;AACD,SAAO;AACT;AAEO,SAAS,gBAAgB,KAAkB,YAA6B;AAC7E,SAAO,CAAC,CAAC,IAAI,QAAQ,IAAI,uBAAuB,UAAU,CAAC,GAAG;AAChE;","names":[]}
@@ -0,0 +1,7 @@
1
+ const THEME_PREVIEW_HOST_HEADER = "x-ecomweb-preview-slug";
2
+ const PREVIEW_HOST_ROBOTS = "User-agent: *\nDisallow: /\n";
3
+ export {
4
+ PREVIEW_HOST_ROBOTS,
5
+ THEME_PREVIEW_HOST_HEADER
6
+ };
7
+ //# sourceMappingURL=preview-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/theme/preview-host.ts"],"sourcesContent":["/**\n * Theme preview hosts: every store theme has its own p-<slug>.<suffix>,\n * where the shared storefront renders that theme (a build's runs on its own\n * pods instead). The middleware names the slug to the page in this request\n * header; it always drops one sent by the client.\n */\nexport const THEME_PREVIEW_HOST_HEADER = \"x-ecomweb-preview-slug\";\n\n/** The robots.txt of a preview host: nothing there is for search engines. */\nexport const PREVIEW_HOST_ROBOTS = \"User-agent: *\\nDisallow: /\\n\";\n"],"mappings":"AAMO,MAAM,4BAA4B;AAGlC,MAAM,sBAAsB;","names":[]}
@@ -0,0 +1,10 @@
1
+ import "server-only";
2
+ import { headers } from "next/headers";
3
+ import { THEME_PREVIEW_HOST_HEADER } from "./preview-host.js";
4
+ async function readPreviewHostSlug() {
5
+ return (await headers()).get(THEME_PREVIEW_HOST_HEADER) || null;
6
+ }
7
+ export {
8
+ readPreviewHostSlug
9
+ };
10
+ //# sourceMappingURL=read-preview-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/theme/read-preview-host.ts"],"sourcesContent":["import \"server-only\";\nimport { headers } from \"next/headers\";\nimport { THEME_PREVIEW_HOST_HEADER } from \"./preview-host\";\n\n/**\n * The theme preview host's slug when this request came in on one (server\n * components only); the middleware sets it, never the client.\n */\nexport async function readPreviewHostSlug(): Promise<string | null> {\n return (await headers()).get(THEME_PREVIEW_HOST_HEADER) || null;\n}\n"],"mappings":"AAAA,OAAO;AACP,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAM1C,eAAsB,sBAA8C;AAClE,UAAQ,MAAM,QAAQ,GAAG,IAAI,yBAAyB,KAAK;AAC7D;","names":[]}
@@ -1,8 +1,10 @@
1
1
  import "server-only";
2
- import { cookies } from "next/headers";
3
- import { THEME_PREVIEW_COOKIE } from "./preview-cookie.js";
2
+ import { cookies, headers } from "next/headers";
3
+ import { isHostMappedRequest } from "../auth/cookies.js";
4
+ import { THEME_PREVIEW_COOKIE, themePreviewCookieName } from "./preview-cookie.js";
4
5
  async function readThemePreviewToken() {
5
- return (await cookies()).get(THEME_PREVIEW_COOKIE)?.value || null;
6
+ const name = isHostMappedRequest({ headers: await headers() }) ? themePreviewCookieName("/") : THEME_PREVIEW_COOKIE;
7
+ return (await cookies()).get(name)?.value || null;
6
8
  }
7
9
  export {
8
10
  readThemePreviewToken
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theme/read-preview-token.ts"],"sourcesContent":["import \"server-only\";\nimport { cookies } from \"next/headers\";\nimport { THEME_PREVIEW_COOKIE } from \"./preview-cookie\";\n\n/** The open theme preview's token, if any (server components only). */\nexport async function readThemePreviewToken(): Promise<string | null> {\n return (await cookies()).get(THEME_PREVIEW_COOKIE)?.value || null;\n}\n"],"mappings":"AAAA,OAAO;AACP,SAAS,eAAe;AACxB,SAAS,4BAA4B;AAGrC,eAAsB,wBAAgD;AACpE,UAAQ,MAAM,QAAQ,GAAG,IAAI,oBAAoB,GAAG,SAAS;AAC/D;","names":[]}
1
+ {"version":3,"sources":["../../src/theme/read-preview-token.ts"],"sourcesContent":["import \"server-only\";\nimport { cookies, headers } from \"next/headers\";\nimport { isHostMappedRequest } from \"../auth/cookies\";\nimport { THEME_PREVIEW_COOKIE, themePreviewCookieName } from \"./preview-cookie\";\n\n/** The open theme preview's token, if any (server components only). */\nexport async function readThemePreviewToken(): Promise<string | null> {\n // Host-mapped requests keep the cookie at `/` (authCookiePath), the one\n // path whose name differs; on the shared host it is path-scoped and bare.\n const name = isHostMappedRequest({ headers: await headers() })\n ? themePreviewCookieName(\"/\")\n : THEME_PREVIEW_COOKIE;\n return (await cookies()).get(name)?.value || null;\n}\n"],"mappings":"AAAA,OAAO;AACP,SAAS,SAAS,eAAe;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB,8BAA8B;AAG7D,eAAsB,wBAAgD;AAGpE,QAAM,OAAO,oBAAoB,EAAE,SAAS,MAAM,QAAQ,EAAE,CAAC,IACzD,uBAAuB,GAAG,IAC1B;AACJ,UAAQ,MAAM,QAAQ,GAAG,IAAI,IAAI,GAAG,SAAS;AAC/C;","names":[]}
@@ -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(() => ({ themeId, settings }), [themeId, settings]);
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 }), [themeId, settings]);\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"],"mappings":";AAsBI;AApBJ,SAAS,eAAe,YAAY,eAA+B;AAQnE,MAAM,uBAAuB;AAAA,EAC3B;AACF;AAGO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,QAAQ,QAAQ,OAAO,EAAE,SAAS,SAAS,IAAI,CAAC,SAAS,QAAQ,CAAC;AACxE,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;","names":[]}
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, Banner, ThemeSettingsOf } from '@ecomweb/sdk';
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
- interface HomePageSlotProps<V> extends ThemeSlotProps<V> {
27
- banners: Banner[];
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.6.0",
3
+ "version": "0.9.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.6.0"
50
+ "@ecomweb/sdk": "^0.9.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "next": ">=16",