@shop-on/create-theme 0.9.0 → 0.11.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 (48) hide show
  1. package/dist/cli.mjs +1 -2
  2. package/dist/index.d.mts +1 -3
  3. package/dist/index.mjs +1 -2
  4. package/package.json +3 -3
  5. package/template/.claude/skills/theme-dev/SKILL.md +4 -4
  6. package/template/.claude/skills/theme-dev/recipes/concepts.md +2 -2
  7. package/template/.claude/skills/theme-dev/recipes/custom-sections.md +28 -226
  8. package/template/.claude/skills/theme-dev/recipes/customer-auth.md +2 -1
  9. package/template/.claude/skills/theme-dev/recipes/data-fetching.md +2 -2
  10. package/template/.claude/skills/theme-dev/recipes/input-settings.md +5 -6
  11. package/template/.claude/skills/theme-dev/recipes/locales.md +1 -1
  12. package/template/.claude/skills/theme-dev/recipes/picker-data.md +2 -2
  13. package/template/.env.example +2 -3
  14. package/template/.oxfmtrc.json +0 -1
  15. package/template/package.json +21 -22
  16. package/template/src/ai/guide.md +25 -0
  17. package/template/src/blocks/custom-block.json +4 -0
  18. package/template/src/blocks/custom-block.test.ts +16 -0
  19. package/template/src/blocks/custom-block.tsx +26 -0
  20. package/template/src/lib/i18n.server.ts +2 -2
  21. package/template/src/lib/i18n.ts +9 -0
  22. package/template/src/lib/listing-search.ts +7 -12
  23. package/template/src/lib/use-analytics.ts +11 -11
  24. package/template/src/locales/en.default.json +4 -0
  25. package/template/src/locales/en.default.schema.json +16 -2
  26. package/template/src/locales/mn.default.json +4 -0
  27. package/template/src/locales/mn.default.schema.json +16 -2
  28. package/template/src/route-adapter.tsx +0 -2
  29. package/template/src/routeTree.gen.ts +22 -0
  30. package/template/src/routes/__root.tsx +2 -2
  31. package/template/src/routes/robots[.]txt.tsx +5 -5
  32. package/template/src/routes/sitemap[.]xml.tsx +5 -4
  33. package/template/src/routes/{-$locale}/checkout.tsx +13 -8
  34. package/template/src/routes/{-$locale}/collections/index.tsx +1 -1
  35. package/template/src/routes/{-$locale}/orders/find.tsx +13 -0
  36. package/template/src/sections/custom-section.json +39 -0
  37. package/template/src/sections/custom-section.test.ts +14 -0
  38. package/template/src/sections/custom-section.tsx +73 -0
  39. package/template/src/sections/hero.json +6 -1
  40. package/template/src/sections/main-collection.test.tsx +21 -7
  41. package/template/src/sections/main-product.json +1 -0
  42. package/template/src/sections/main-product.tsx +15 -0
  43. package/template/src/server/i18n.server.test.ts +2 -2
  44. package/template/src/server/i18n.server.ts +7 -19
  45. package/template/src/server/settings.ts +26 -7
  46. package/template/src/server/template-loader.ts +2 -2
  47. package/template/tsconfig.json +0 -7
  48. package/template/src/server/checkout-redirect.ts +0 -21
@@ -11,11 +11,11 @@ const trackProductClicked = vi.fn();
11
11
  const trackProductListViewed = vi.fn();
12
12
  vi.mock("@shop-on/theme-react/analytics", () => ({
13
13
  ensureVisit,
14
- toInt: (value: unknown) => Number.parseInt(String(value), 10),
15
14
  track,
16
15
  trackProductClicked,
17
16
  trackProductListViewed,
18
17
  trackSearchSubmitted: vi.fn(),
18
+ wireIdOf: (value: string | null | undefined) => value ?? null,
19
19
  }));
20
20
  // The real `Link` needs a router; a plain anchor is what it renders anyway.
21
21
  vi.mock("@/src/snippets/link", () => ({
@@ -25,13 +25,25 @@ vi.mock("@/src/snippets/link", () => ({
25
25
  const { default: MainCollection } = await import("./main-collection");
26
26
 
27
27
  const collectionData = {
28
- id: "7",
28
+ id: "collection_01h455vb4pex5vsknk084sn02q",
29
29
  handle: "all",
30
30
  title: "All",
31
31
  total_count: 2,
32
32
  products: [
33
- { id: "11", handle: "a", title: "A", price: { amount: 1000, currencyCode: "MNT" }, media: [] },
34
- { id: "12", handle: "b", title: "B", price: { amount: 2000, currencyCode: "MNT" }, media: [] },
33
+ {
34
+ id: "prod_01h455vb4pex5vsknk084sn0aa",
35
+ handle: "a",
36
+ title: "A",
37
+ price: { amount: 1000, currencyCode: "MNT" },
38
+ media: [],
39
+ },
40
+ {
41
+ id: "prod_01h455vb4pex5vsknk084sn0bb",
42
+ handle: "b",
43
+ title: "B",
44
+ price: { amount: 2000, currencyCode: "MNT" },
45
+ media: [],
46
+ },
35
47
  ],
36
48
  } as unknown as CollectionPageData;
37
49
 
@@ -63,16 +75,18 @@ afterEach(() => {
63
75
 
64
76
  it("reports a click-through from a product card", async () => {
65
77
  await render(<MainCollection collectionData={collectionData} />);
66
- const link = container.querySelector<HTMLAnchorElement>('[data-product-id="12"] a');
78
+ const link = container.querySelector<HTMLAnchorElement>(
79
+ '[data-product-id="prod_01h455vb4pex5vsknk084sn0bb"] a',
80
+ );
67
81
  expect(link?.getAttribute("href")).toBe("/products/b");
68
82
 
69
83
  link?.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
70
84
 
71
85
  expect(trackProductClicked).toHaveBeenCalledWith({
72
- productId: "12",
86
+ productId: "prod_01h455vb4pex5vsknk084sn0bb",
73
87
  productHandle: "b",
74
88
  listType: "collection",
75
- listId: "7",
89
+ listId: "collection_01h455vb4pex5vsknk084sn02q",
76
90
  position: 1,
77
91
  });
78
92
  });
@@ -3,5 +3,6 @@
3
3
  "tag": "section",
4
4
  "enabled_on": { "templates": ["product", "product.*"] },
5
5
  "settings": [],
6
+ "blocks": [{ "type": "custom-block" }],
6
7
  "presets": [{ "name": "t:sections.main_product" }]
7
8
  }
@@ -7,16 +7,24 @@
7
7
  // settings as `productData`. Then add a variant picker + add-to-cart (cart
8
8
  // mutations live in `@shop-on/theme-server/cart-mutations`).
9
9
  import { formatMoney } from "@shop-on/theme-runtime/money";
10
+ import { hasCustomOutput } from "@shop-on/theme-react/custom-section-html";
10
11
  import type { ProductData } from "@shop-on/theme-server/product";
12
+ import { BlockRenderer, type BlockInstance } from "@/src/components/template-renderer";
11
13
  import { useProductViewed } from "@/src/lib/use-analytics";
12
14
 
13
15
  export default function MainProduct({
14
16
  sectionId,
15
17
  productData,
18
+ blocks = [],
16
19
  }: {
17
20
  sectionId?: string;
18
21
  productData?: ProductData | null;
22
+ blocks?: BlockInstance[];
19
23
  }) {
24
+ // An AI-built block the custom-section pass rendered nothing for would still
25
+ // get a wrapper of its own, and the wrapper's margin would open a gap.
26
+ const shown = blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings));
27
+
20
28
  // `product_viewed` — no-ops until the route patches in `productData`.
21
29
  useProductViewed(productData?.id, productData?.handle);
22
30
 
@@ -47,6 +55,13 @@ export default function MainProduct({
47
55
  <div className="h-4 w-5/6 rounded-sm bg-border" />
48
56
  </div>
49
57
  )}
58
+ {/* One wrapper per block, not one BlockRenderer over the list: its own
59
+ wrapper is `display: contents`, so it can't carry the spacing. */}
60
+ {shown.map((block, i) => (
61
+ <div key={block.id ?? i} className="mt-8">
62
+ <BlockRenderer blocks={[block]} />
63
+ </div>
64
+ ))}
50
65
  </div>
51
66
  </div>
52
67
  </section>
@@ -9,8 +9,8 @@ import config from "../../theme.config.json";
9
9
  // default-language copy. `check:locales` compares keys file by file and cannot
10
10
  // see it.
11
11
  //
12
- // `INSTALL_ID` is read at import, and with one set the merchant's overrides
13
- // would be fetched over the shipped copy — pin it empty before importing.
12
+ // With an `INSTALL_ID` set, the merchant's overrides would be read over the
13
+ // shipped copy — pin it empty.
14
14
  vi.stubEnv("INSTALL_ID", "");
15
15
  const { getMessagesForLocale } = await import("./i18n.server");
16
16
 
@@ -1,5 +1,5 @@
1
1
  import type { AbstractIntlMessages } from "@shop-on/i18n";
2
- import { applyCatalogOverrides, fetchThemeContent } from "@shop-on/theme-server/translations";
2
+ import { themeStrings } from "@shop-on/theme-server/translations";
3
3
  import type { Locale } from "@/src/lib/i18n";
4
4
 
5
5
  // The theme's own strings — every word a buyer reads that the merchant did not
@@ -19,23 +19,11 @@ const SHIPPED: Partial<Record<Locale, AbstractIntlMessages>> = Object.fromEntrie
19
19
 
20
20
  const DEFAULT_MESSAGES = SHIPPED.en!;
21
21
 
22
- const INSTALL_ID = process.env.INSTALL_ID || "";
23
-
22
+ // The merchant's `strings` rows for the locale, from admin → Translations, laid
23
+ // over the shipped catalog. The primary locale's are included: those reword the
24
+ // theme's own copy ("Add to cart" → "Add to bag"), which is why this is a read
25
+ // and not just a bundled import. With no install (local `pnpm dev`) or a failed
26
+ // read, the shipped catalog as it is: default-language copy beats a 500.
24
27
  export async function getMessagesForLocale(locale: Locale): Promise<AbstractIntlMessages> {
25
- const base = SHIPPED[locale] ?? DEFAULT_MESSAGES;
26
- // Local `pnpm dev` has no install identity and often no backend — serve the
27
- // shipped catalog rather than failing the root loader over it.
28
- if (!INSTALL_ID) return base;
29
-
30
- try {
31
- // The merchant's `locale_content` rows for the active locale, from admin →
32
- // Translations. Primary-locale rows are included: those are overrides of the
33
- // theme's own default copy ("Add to cart" → "Add to bag"), which is why this
34
- // is a fetch and not just a bundled import.
35
- const rows = await fetchThemeContent(INSTALL_ID, locale, { type: "LOCALE_CONTENT" });
36
- return applyCatalogOverrides(base, rows) as AbstractIntlMessages;
37
- } catch {
38
- // Transient API failure: a page in default-language copy beats a 500.
39
- return base;
40
- }
28
+ return themeStrings(SHIPPED[locale] ?? DEFAULT_MESSAGES, locale);
41
29
  }
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { createServerFn } from "@tanstack/react-start";
23
23
  import type { LoadedTemplate } from "@shop-on/theme-loader/types";
24
+ import { isValidLocale, localizedPath } from "@/src/lib/i18n";
24
25
 
25
26
  /** Everything the loader needs about the request behind a template load. */
26
27
  interface TemplateRequest {
@@ -37,16 +38,35 @@ async function loadTemplate(
37
38
  templateId: string,
38
39
  req: TemplateRequest = {},
39
40
  ): Promise<LoadedTemplate | null> {
40
- const [{ loadTemplateForRequest, runEnrichment }, { loaderConfig }, { enrichAdapter }] =
41
- await Promise.all([
42
- import("@shop-on/theme-loader"),
43
- import("./template-loader"),
44
- import("./enrich-adapter"),
45
- ]);
41
+ const [
42
+ { loadTemplateForRequest, runEnrichment },
43
+ { loaderConfig },
44
+ { enrichAdapter },
45
+ { renderCustomSections },
46
+ ] = await Promise.all([
47
+ import("@shop-on/theme-loader"),
48
+ import("./template-loader"),
49
+ import("./enrich-adapter"),
50
+ import("@shop-on/theme-loader/custom-sections"),
51
+ ]);
46
52
 
47
53
  const template = await loadTemplateForRequest(loaderConfig, templateId, req.sid, req.locale);
48
54
  if (!template) return null;
49
55
  await runEnrichment(loaderConfig, template, enrichAdapter, req);
56
+ // AI-built sections and blocks (`custom-section`, `custom-block`). AFTER the
57
+ // enrichment, deliberately: its last phase re-scans every string setting, so
58
+ // rendered HTML must land after it. `link_url` hands `localizePath` a
59
+ // locale-free site path. Only a locale the shop serves may prefix it:
60
+ // `req.locale` is server-fn input, and a crafted one would otherwise turn a
61
+ // site path into another host's (`//evil.example/…`). Once a route loads its
62
+ // product or collection here, pass `product` / `getCollection` as well, and
63
+ // the template's `product` / `collection` drops fill in on that page.
64
+ const pathLocale = isValidLocale(req.locale) ? req.locale : undefined;
65
+ await renderCustomSections(loaderConfig, template, {
66
+ sid: req.sid,
67
+ locale: req.locale,
68
+ localizePath: (path) => localizedPath(path, pathLocale),
69
+ });
50
70
  return template;
51
71
  }
52
72
 
@@ -129,7 +149,6 @@ interface TemplateRequestInput {
129
149
  collectionHandle?: string;
130
150
  variantId?: string;
131
151
  previewTemplate?: string;
132
- after?: string;
133
152
  tag?: string;
134
153
  q?: string;
135
154
  page?: number;
@@ -25,8 +25,8 @@ export const CONFIG_DIR = process.env.CONFIG_DIR || DEV_CONFIG_DIR;
25
25
  export const loaderConfig: ThemeLoaderConfig = {
26
26
  orchestratorUrl: process.env.ORCHESTRATOR_URL || "http://localhost:4100",
27
27
  // Both empty on a plain `vite dev`, which is what disables the preview path
28
- // (and, for INSTALL_ID, the merchant translation overlays) rather than
29
- // pointing them at a store that isn't there.
28
+ // rather than pointing it at a store that isn't there. (An empty INSTALL_ID
29
+ // also leaves the merchant's translations unread: theme-server's own read.)
30
30
  storeSlug: process.env.STORE_SLUG || "",
31
31
  installId: process.env.INSTALL_ID || "",
32
32
  configDir: CONFIG_DIR,
@@ -15,13 +15,6 @@
15
15
  "isolatedModules": true,
16
16
  "jsx": "react-jsx",
17
17
  "incremental": true,
18
- "plugins": [
19
- {
20
- "name": "gql.tada/ts-plugin",
21
- "schema": "./node_modules/@shop-on/theme-server/dist/schema.storefront.graphql",
22
- "tadaOutputLocation": "src/server/graphql-env.d.ts"
23
- }
24
- ],
25
18
  "paths": {
26
19
  "@/*": ["./*"]
27
20
  }
@@ -1,21 +0,0 @@
1
- // Server-side cart→checkout bounce. The cart-cookie read + `cartCheckout` call
2
- // + result mapping live in the shared `@shop-on/theme-server/checkout` helper;
3
- // this forwards the buyer token so a signed-in checkout arrives prefilled
4
- // (anonymous buyers forward nothing). The node-only helpers are dynamic-
5
- // imported inside the handler so this module stays safe to import from the
6
- // client-side `/checkout` route.
7
- import { createServerFn } from "@tanstack/react-start";
8
- import type { CheckoutHandoffResult } from "@shop-on/theme-server/checkout";
9
-
10
- export type { CheckoutHandoffResult };
11
-
12
- // `state` is the `checkout_state` checkout's `/begin` sent back; without one the
13
- // result is the `/begin` URL itself (what a browser-side caller gets).
14
- export const startCheckoutFn = createServerFn({ method: "POST" })
15
- .validator((data: { state?: string } | undefined) => ({ state: data?.state }))
16
- .handler(async ({ data }): Promise<CheckoutHandoffResult> => {
17
- const { readCustomerSession } = await import("@shop-on/theme-server/customer-session");
18
- const { startCheckoutHandoff } = await import("@shop-on/theme-server/checkout");
19
- const session = await readCustomerSession();
20
- return startCheckoutHandoff({ state: data.state, customerToken: session?.token });
21
- });