create-skybridge 0.0.0-dev.0f97936 → 0.0.0-dev.0fa5252

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 (83) hide show
  1. package/dist/index.js +52 -26
  2. package/package.json +3 -3
  3. package/templates/blank/Dockerfile +2 -2
  4. package/templates/blank/node_modules/.bin/alpic +2 -2
  5. package/templates/blank/node_modules/.bin/tsx +2 -2
  6. package/templates/blank/node_modules/.bin/vite +2 -2
  7. package/templates/blank/package.json +8 -7
  8. package/templates/blank/vite.config.ts +7 -1
  9. package/templates/demo/Dockerfile +2 -2
  10. package/templates/demo/node_modules/.bin/alpic +2 -2
  11. package/templates/demo/node_modules/.bin/tsx +2 -2
  12. package/templates/demo/node_modules/.bin/vite +2 -2
  13. package/templates/demo/package.json +13 -12
  14. package/templates/demo/vite.config.ts +7 -1
  15. package/templates/ecom/.dockerignore +4 -0
  16. package/templates/ecom/.env.template +7 -0
  17. package/templates/ecom/.ladle/components.tsx +26 -0
  18. package/templates/ecom/.ladle/config.mjs +11 -0
  19. package/templates/ecom/.ladle/vite.config.ts +11 -0
  20. package/templates/ecom/AGENTS.md +2 -0
  21. package/templates/ecom/Dockerfile +53 -0
  22. package/templates/ecom/README.md +92 -0
  23. package/templates/ecom/_gitignore +9 -0
  24. package/templates/ecom/alpic.json +3 -0
  25. package/templates/ecom/node_modules/.bin/alpic +21 -0
  26. package/templates/ecom/node_modules/.bin/ladle +21 -0
  27. package/templates/ecom/node_modules/.bin/sb +21 -0
  28. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  29. package/templates/ecom/node_modules/.bin/tsc +21 -0
  30. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  31. package/templates/ecom/node_modules/.bin/tsx +21 -0
  32. package/templates/ecom/node_modules/.bin/vite +21 -0
  33. package/templates/ecom/package.json +42 -0
  34. package/templates/ecom/src/catalog/index.ts +19 -0
  35. package/templates/ecom/src/catalog/mock.ts +134 -0
  36. package/templates/ecom/src/catalog/shopify.ts +264 -0
  37. package/templates/ecom/src/components/chip.css.ts +63 -0
  38. package/templates/ecom/src/components/chip.stories.tsx +27 -0
  39. package/templates/ecom/src/components/chip.tsx +49 -0
  40. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  41. package/templates/ecom/src/components/empty-state.tsx +12 -0
  42. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  43. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  44. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  45. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  46. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  47. package/templates/ecom/src/components/image-gallery.tsx +163 -0
  48. package/templates/ecom/src/components/product-card.css.ts +159 -0
  49. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  50. package/templates/ecom/src/components/product-card.tsx +102 -0
  51. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  52. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  53. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  54. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  55. package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
  56. package/templates/ecom/src/components/variant-picker.tsx +70 -0
  57. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  58. package/templates/ecom/src/components/view-frame.tsx +27 -0
  59. package/templates/ecom/src/config.ts +12 -0
  60. package/templates/ecom/src/design/contract.css.ts +39 -0
  61. package/templates/ecom/src/design/fonts.css +15 -0
  62. package/templates/ecom/src/design/primitives.css.ts +101 -0
  63. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  64. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  65. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  66. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  67. package/templates/ecom/src/design/tokens.ts +8 -0
  68. package/templates/ecom/src/helpers.ts +4 -0
  69. package/templates/ecom/src/i18n.ts +35 -0
  70. package/templates/ecom/src/index.css +9 -0
  71. package/templates/ecom/src/lib/cx.ts +9 -0
  72. package/templates/ecom/src/lib/format.ts +9 -0
  73. package/templates/ecom/src/lib/variants.ts +150 -0
  74. package/templates/ecom/src/server.ts +43 -0
  75. package/templates/ecom/src/tools/render-carousel.ts +161 -0
  76. package/templates/ecom/src/tools/search-products.ts +196 -0
  77. package/templates/ecom/src/types.ts +87 -0
  78. package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
  79. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
  80. package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
  81. package/templates/ecom/src/views/carousel/index.tsx +233 -0
  82. package/templates/ecom/tsconfig.json +11 -0
  83. package/templates/ecom/vite.config.ts +8 -0
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@types+node@24.13.3_@types+react@19.2.17_jiti@2.7.0_lightningcss@1.3_8c0d7eb4f29a667fc68ef4c081ca0a73/node_modules/@ladle/react/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@types+node@24.13.3_@types+react@19.2.17_jiti@2.7.0_lightningcss@1.3_8c0d7eb4f29a667fc68ef4c081ca0a73/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@types+node@24.13.3_@types+react@19.2.17_jiti@2.7.0_lightningcss@1.3_8c0d7eb4f29a667fc68ef4c081ca0a73/node_modules/@ladle/react/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@types+node@24.13.3_@types+react@19.2.17_jiti@2.7.0_lightningcss@1.3_8c0d7eb4f29a667fc68ef4c081ca0a73/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../@ladle/react/lib/cli/cli.js" "$@"
19
+ else
20
+ exec node "$basedir/../@ladle/react/lib/cli/cli.js" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../skybridge/bin/run.js" "$@"
19
+ else
20
+ exec node "$basedir/../skybridge/bin/run.js" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../skybridge/bin/run.js" "$@"
19
+ else
20
+ exec node "$basedir/../skybridge/bin/run.js" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
19
+ else
20
+ exec node "$basedir/../typescript/bin/tsc" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/typescript@6.0.3/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
19
+ else
20
+ exec node "$basedir/../typescript/bin/tsserver" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/tsx@4.23.0/node_modules/tsx/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/tsx@4.23.0/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/tsx@4.23.0/node_modules/tsx/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/tsx@4.23.0/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../tsx/dist/cli.mjs" "$@"
19
+ else
20
+ exec node "$basedir/../tsx/dist/cli.mjs" "$@"
21
+ fi
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/vite@8.1.5_@types+node@24.13.3_esbuild@0.28.1_jiti@2.7.0_terser@5.44.1_tsx@4.23.0_yaml@2.9.0/node_modules/vite/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/vite@8.1.5_@types+node@24.13.3_esbuild@0.28.1_jiti@2.7.0_terser@5.44.1_tsx@4.23.0_yaml@2.9.0/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/vite@8.1.5_@types+node@24.13.3_esbuild@0.28.1_jiti@2.7.0_terser@5.44.1_tsx@4.23.0_yaml@2.9.0/node_modules/vite/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/vite@8.1.5_@types+node@24.13.3_esbuild@0.28.1_jiti@2.7.0_terser@5.44.1_tsx@4.23.0_yaml@2.9.0/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../vite/bin/vite.js" "$@"
19
+ else
20
+ exec node "$basedir/../vite/bin/vite.js" "$@"
21
+ fi
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "skybridge-ecom",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "description": "Skybridge MCP ecommerce template",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "skybridge dev",
9
+ "dev:tunnel": "skybridge dev --tunnel",
10
+ "build": "skybridge build",
11
+ "start": "skybridge start",
12
+ "deploy": "alpic deploy",
13
+ "ladle": "ladle serve",
14
+ "ladle:build": "ladle build"
15
+ },
16
+ "dependencies": {
17
+ "react": "^19.2.4",
18
+ "react-dom": "^19.2.4",
19
+ "skybridge": "^0.0.0-dev.0fa5252",
20
+ "vite": "^8.1.3",
21
+ "zod": "^4.4.3"
22
+ },
23
+ "devDependencies": {
24
+ "@ladle/react": "^5.1.1",
25
+ "@skybridge/devtools": "^1.2.4",
26
+ "@skybridge/vite-plugin": "^0.0.0-dev.0fa5252",
27
+ "@types/node": "^24.13.2",
28
+ "@types/react": "^19.2.14",
29
+ "@types/react-dom": "^19.2.3",
30
+ "@vanilla-extract/css": "^1.20.1",
31
+ "@vanilla-extract/recipes": "^0.5.7",
32
+ "@vanilla-extract/sprinkles": "^1.6.5",
33
+ "@vanilla-extract/vite-plugin": "^5.2.2",
34
+ "@vitejs/plugin-react": "^6.0.1",
35
+ "alpic": "^1.147.1",
36
+ "tsx": "^4.23.0",
37
+ "typescript": "^6.0.3"
38
+ },
39
+ "engines": {
40
+ "node": ">=24.18.0"
41
+ }
42
+ }
@@ -0,0 +1,19 @@
1
+ // The catalog: the app's single data seam. Both tools read products through
2
+ // these two functions, and nothing else in the app touches a backend.
3
+ //
4
+ // @todo: pick your provider. Ship one of the modules next to this file, or add
5
+ // your own (same two exports, same types) and re-export it here:
6
+ // ./mock.js placeholder catalog, no backend needed (default)
7
+ // ./shopify.js Shopify Storefront API, set the SHOPIFY_* vars in .env
8
+ //
9
+ // Writing your own: `search(input)` returns a `SearchResult`, `getProducts(ids)`
10
+ // resolves ids in the requested order (that is the display order, so resolve by
11
+ // id, never by catalog order). Both map your backend's rows into `Product`s, and
12
+ // how you group them depends on your catalog:
13
+ // - simple products: one `Product` with a single variant, `options: []`
14
+ // - grouped: one `Product` per product, `card` = union of its variants
15
+ // - one card per variant: `card` = that variant
16
+ // Either way `variants` holds ALL variants the source returns for the product;
17
+ // the detail view reads them so the client can switch variant. Order `options`
18
+ // with the imagery-driving axis first (see `Product`: order is semantic).
19
+ export { getProducts, search } from "./mock.js";
@@ -0,0 +1,134 @@
1
+ import type { SearchInput } from "../tools/search-products.js";
2
+ import type { Product, SearchResult, Spec } from "../types.js";
3
+
4
+ // Placeholder catalog provider, so both tools answer before a backend exists.
5
+ // Images are inline SVG placeholders, so no CSP domain is needed.
6
+ // @todo: delete this module once you point `./index.js` at a real provider.
7
+
8
+ function shot(fill: string): string {
9
+ return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Crect width='400' height='400' fill='%23${fill}'/%3E%3C/svg%3E`;
10
+ }
11
+
12
+ const JACKET_SPECS: Spec[] = [
13
+ { label: "Material", value: "Water-repellent cotton" },
14
+ { label: "Fit", value: "Relaxed" },
15
+ ];
16
+
17
+ // Deliberately long, to exercise the detail page's scroll and "read more".
18
+ const JACKET_DESCRIPTION = "Relaxed-fit jacket in water-repellent cotton.";
19
+
20
+ const MOCK_PRODUCTS: Product[] = [
21
+ {
22
+ id: "field-jacket",
23
+ options: [
24
+ {
25
+ id: "color",
26
+ label: "Color",
27
+ values: [
28
+ { id: "black", label: "Black", media: shot("2b2b2b") },
29
+ { id: "sand", label: "Sand", media: shot("d8c7a8") },
30
+ ],
31
+ },
32
+ ],
33
+ variants: [
34
+ {
35
+ id: "fj-black",
36
+ selection: { color: "black" },
37
+ title: "Field jacket — Black",
38
+ description: JACKET_DESCRIPTION,
39
+ price: { amount: 229, currency: "EUR" },
40
+ media: [shot("2b2b2b")],
41
+ url: "https://example.com/field-jacket-black",
42
+ specs: JACKET_SPECS,
43
+ },
44
+ {
45
+ id: "fj-sand",
46
+ selection: { color: "sand" },
47
+ title: "Field jacket — Sand",
48
+ description: JACKET_DESCRIPTION,
49
+ price: { amount: 249, currency: "EUR" },
50
+ media: [shot("d8c7a8")],
51
+ url: "https://example.com/field-jacket-sand",
52
+ specs: JACKET_SPECS,
53
+ },
54
+ ],
55
+ card: {
56
+ title: "Field jacket",
57
+ description: "Relaxed-fit jacket in water-repellent cotton.",
58
+ price: { amount: 229, currency: "EUR" },
59
+ media: [shot("2b2b2b")],
60
+ specs: JACKET_SPECS,
61
+ },
62
+ },
63
+ {
64
+ id: "canvas-tote",
65
+ options: [],
66
+ variants: [
67
+ {
68
+ id: "canvas-tote",
69
+ selection: {},
70
+ title: "Canvas tote",
71
+ description: "Sturdy everyday tote with an inner pocket.",
72
+ price: { amount: 39, currency: "EUR" },
73
+ media: [shot("e1e1e1")],
74
+ url: "https://example.com/canvas-tote",
75
+ specs: [{ label: "Material", value: "Cotton canvas" }],
76
+ },
77
+ ],
78
+ card: {
79
+ title: "Canvas tote",
80
+ description: "Sturdy everyday tote with an inner pocket.",
81
+ price: { amount: 39, currency: "EUR" },
82
+ media: [shot("e1e1e1")],
83
+ specs: [{ label: "Material", value: "Cotton canvas" }],
84
+ },
85
+ },
86
+ {
87
+ id: "wool-beanie",
88
+ options: [],
89
+ variants: [
90
+ {
91
+ id: "wool-beanie",
92
+ selection: {},
93
+ title: "Wool beanie",
94
+ description: "Ribbed merino beanie with a folded brim.",
95
+ price: { amount: 45, currency: "EUR" },
96
+ media: [shot("6b7f9e")],
97
+ url: "https://example.com/wool-beanie",
98
+ outOfStock: true,
99
+ specs: [{ label: "Material", value: "Merino wool" }],
100
+ },
101
+ ],
102
+ card: {
103
+ title: "Wool beanie",
104
+ description: "Ribbed merino beanie with a folded brim.",
105
+ price: { amount: 45, currency: "EUR" },
106
+ media: [shot("6b7f9e")],
107
+ outOfStock: true,
108
+ specs: [{ label: "Material", value: "Merino wool" }],
109
+ },
110
+ },
111
+ ];
112
+
113
+ // Ignores the input: every mock product matches every query.
114
+ export async function search(_input: SearchInput): Promise<SearchResult> {
115
+ return {
116
+ products: MOCK_PRODUCTS,
117
+ pages: { current: 1, total: 1 },
118
+ totalHits: MOCK_PRODUCTS.length,
119
+ };
120
+ }
121
+
122
+ // Requested order is the display order, so resolve by id, not catalog order.
123
+ export async function getProducts(ids: string[]): Promise<Product[]> {
124
+ const products: Product[] = [];
125
+ for (const id of ids) {
126
+ for (const product of MOCK_PRODUCTS) {
127
+ if (product.id === id) {
128
+ products.push(product);
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ return products;
134
+ }
@@ -0,0 +1,264 @@
1
+ import type { SearchInput } from "../tools/search-products.js";
2
+ import type {
3
+ Option,
4
+ Price,
5
+ Product,
6
+ SearchResult,
7
+ Spec,
8
+ Variant,
9
+ } from "../types.js";
10
+
11
+ // Shopify Storefront API provider. To use it:
12
+ // 1. re-export this module from `./index.js` instead of `./mock.js`
13
+ // 2. set SHOPIFY_STORE_DOMAIN and SHOPIFY_STOREFRONT_TOKEN in .env
14
+ // 3. uncomment the `csp` block in `src/tools/render-carousel.ts` with
15
+ // `https://cdn.shopify.com` and your store domain
16
+ //
17
+ // Product ids are Shopify handles, not GIDs: stable, readable, and far cheaper
18
+ // in model context than `gid://shopify/Product/8123456789`.
19
+
20
+ const API_VERSION = "2026-07";
21
+ const PAGE_SIZE = 20;
22
+
23
+ // Only the fields this app renders. Options are derived from the variants'
24
+ // `selectedOptions`, so the product-level `options` field is not queried.
25
+ const PRODUCT_FIELDS = `
26
+ fragment ProductFields on Product {
27
+ handle
28
+ title
29
+ description
30
+ vendor
31
+ productType
32
+ onlineStoreUrl
33
+ availableForSale
34
+ priceRange { minVariantPrice { amount currencyCode } }
35
+ images(first: 10) { nodes { url } }
36
+ variants(first: 100) {
37
+ nodes {
38
+ id
39
+ title
40
+ availableForSale
41
+ price { amount currencyCode }
42
+ image { url }
43
+ selectedOptions { name value }
44
+ }
45
+ }
46
+ }`;
47
+
48
+ type ShopifyMoney = { amount: string; currencyCode: string };
49
+
50
+ type ShopifyProduct = {
51
+ handle: string;
52
+ title: string;
53
+ description: string;
54
+ vendor: string;
55
+ productType: string;
56
+ onlineStoreUrl: string | null;
57
+ availableForSale: boolean;
58
+ priceRange: { minVariantPrice: ShopifyMoney };
59
+ images: { nodes: { url: string }[] };
60
+ variants: {
61
+ nodes: {
62
+ id: string;
63
+ title: string;
64
+ availableForSale: boolean;
65
+ price: ShopifyMoney;
66
+ image: { url: string } | null;
67
+ selectedOptions: { name: string; value: string }[];
68
+ }[];
69
+ };
70
+ };
71
+
72
+ async function storefront(query: string, variables: Record<string, unknown>) {
73
+ const domain = process.env.SHOPIFY_STORE_DOMAIN;
74
+ const token = process.env.SHOPIFY_STOREFRONT_TOKEN;
75
+ if (!domain || !token) {
76
+ throw new Error(
77
+ "Missing SHOPIFY_STORE_DOMAIN or SHOPIFY_STOREFRONT_TOKEN in the environment.",
78
+ );
79
+ }
80
+
81
+ const response = await fetch(
82
+ `https://${domain}/api/${API_VERSION}/graphql.json`,
83
+ {
84
+ method: "POST",
85
+ headers: {
86
+ "Content-Type": "application/json",
87
+ "X-Shopify-Storefront-Access-Token": token,
88
+ },
89
+ body: JSON.stringify({ query, variables }),
90
+ },
91
+ );
92
+ if (!response.ok) {
93
+ throw new Error(`Shopify ${response.status}: ${await response.text()}`);
94
+ }
95
+
96
+ const { data, errors } = await response.json();
97
+ if (errors) {
98
+ throw new Error(`Shopify: ${JSON.stringify(errors)}`);
99
+ }
100
+ return data;
101
+ }
102
+
103
+ function toPrice(money: ShopifyMoney): Price {
104
+ return { amount: Number(money.amount), currency: money.currencyCode };
105
+ }
106
+
107
+ // @todo: Shopify has no generic "specs" field. Vendor and product type are a
108
+ // starting point; swap in your own metafields once you know their namespace.
109
+ function toSpecs(node: ShopifyProduct): Spec[] {
110
+ const specs: Spec[] = [];
111
+ if (node.vendor) {
112
+ specs.push({ label: "Brand", value: node.vendor });
113
+ }
114
+ if (node.productType) {
115
+ specs.push({ label: "Type", value: node.productType });
116
+ }
117
+ return specs;
118
+ }
119
+
120
+ function toProduct(node: ShopifyProduct): Product {
121
+ const specs = toSpecs(node);
122
+ const images: string[] = [];
123
+ for (const image of node.images.nodes) {
124
+ images.push(image.url);
125
+ }
126
+
127
+ // Walk the variants once, building both the variants and the axes they vary
128
+ // on. Shopify option names are used as-is for ids, so a variant's
129
+ // `selectedOptions` maps straight onto `selection`.
130
+ const options: Option[] = [];
131
+ const variants: Variant[] = [];
132
+ for (const variant of node.variants.nodes) {
133
+ const selection: Record<string, string> = {};
134
+ for (const selected of variant.selectedOptions) {
135
+ selection[selected.name] = selected.value;
136
+
137
+ let option: Option | undefined;
138
+ for (const candidate of options) {
139
+ if (candidate.id === selected.name) {
140
+ option = candidate;
141
+ break;
142
+ }
143
+ }
144
+ if (!option) {
145
+ option = { id: selected.name, label: selected.name, values: [] };
146
+ options.push(option);
147
+ }
148
+
149
+ let known = false;
150
+ for (const value of option.values) {
151
+ if (value.id === selected.value) {
152
+ known = true;
153
+ break;
154
+ }
155
+ }
156
+ if (!known) {
157
+ option.values.push({
158
+ id: selected.value,
159
+ label: selected.value,
160
+ media: variant.image?.url,
161
+ });
162
+ }
163
+ }
164
+
165
+ variants.push({
166
+ id: variant.id,
167
+ selection,
168
+ title: variant.title === "Default Title" ? node.title : variant.title,
169
+ description: node.description,
170
+ price: toPrice(variant.price),
171
+ media: variant.image ? [variant.image.url] : images,
172
+ url: node.onlineStoreUrl ?? undefined,
173
+ outOfStock: !variant.availableForSale,
174
+ specs,
175
+ });
176
+ }
177
+
178
+ // A single-variant product has no axes to pick from.
179
+ if (variants.length < 2) {
180
+ options.length = 0;
181
+ }
182
+
183
+ return {
184
+ id: node.handle,
185
+ options,
186
+ variants,
187
+ card: {
188
+ title: node.title,
189
+ description: node.description,
190
+ price: toPrice(node.priceRange.minVariantPrice),
191
+ media: images,
192
+ url: node.onlineStoreUrl ?? undefined,
193
+ outOfStock: !node.availableForSale,
194
+ specs,
195
+ },
196
+ };
197
+ }
198
+
199
+ export async function search({
200
+ keyword,
201
+ sort,
202
+ priceRange,
203
+ }: SearchInput): Promise<SearchResult> {
204
+ // Shopify's search DSL: a bare term matches title, vendor, type and tags;
205
+ // extra clauses narrow it. @todo: add your own (`tag:`, `product_type:`…).
206
+ let query = keyword;
207
+ if (priceRange) {
208
+ const [min, max] = priceRange.split("-");
209
+ query += ` variants.price:>=${min} variants.price:<=${max}`;
210
+ }
211
+
212
+ const data = await storefront(
213
+ `${PRODUCT_FIELDS}
214
+ query Search($query: String!, $sortKey: ProductSortKeys!, $reverse: Boolean!, $first: Int!) {
215
+ products(query: $query, sortKey: $sortKey, reverse: $reverse, first: $first) {
216
+ nodes { ...ProductFields }
217
+ }
218
+ }`,
219
+ {
220
+ query,
221
+ sortKey: sort ? "PRICE" : "RELEVANCE",
222
+ reverse: sort === "price-desc",
223
+ first: PAGE_SIZE,
224
+ },
225
+ );
226
+
227
+ const products: Product[] = [];
228
+ for (const node of data.products.nodes) {
229
+ products.push(toProduct(node));
230
+ }
231
+ // Storefront paginates by cursor and reports no total, so both counts are
232
+ // left out rather than faked.
233
+ return { products };
234
+ }
235
+
236
+ export async function getProducts(ids: string[]): Promise<Product[]> {
237
+ // One aliased lookup per handle, so the response comes back in the order the
238
+ // model asked for.
239
+ const declarations: string[] = [];
240
+ const fields: string[] = [];
241
+ const variables: Record<string, string> = {};
242
+ for (let index = 0; index < ids.length; index++) {
243
+ declarations.push(`$h${index}: String!`);
244
+ fields.push(`p${index}: product(handle: $h${index}) { ...ProductFields }`);
245
+ variables[`h${index}`] = ids[index];
246
+ }
247
+
248
+ const data = await storefront(
249
+ `${PRODUCT_FIELDS}
250
+ query Products(${declarations.join(", ")}) {
251
+ ${fields.join("\n ")}
252
+ }`,
253
+ variables,
254
+ );
255
+
256
+ const products: Product[] = [];
257
+ for (let index = 0; index < ids.length; index++) {
258
+ const node = data[`p${index}`];
259
+ if (node) {
260
+ products.push(toProduct(node));
261
+ }
262
+ }
263
+ return products;
264
+ }
@@ -0,0 +1,63 @@
1
+ import { style } from "@vanilla-extract/css";
2
+ import { recipe } from "@vanilla-extract/recipes";
3
+ import { colors, primitives } from "../design/tokens";
4
+
5
+ // A selectable pill used for option values (sizes, colors…). `selected`,
6
+ // `outOfStock` and `nonExistent` are driven by the variant picker from the
7
+ // sparse variant list.
8
+ // @todo: tune the chip to your brand (radius, borders, selected treatment).
9
+ export const chip = recipe({
10
+ base: {
11
+ display: "inline-flex",
12
+ alignItems: "center",
13
+ gap: primitives.space["4xs"],
14
+ minHeight: "44px", // touch target
15
+ padding: `${primitives.space["4xs"]} ${primitives.space["3xs"]}`,
16
+ borderRadius: primitives.radius.m,
17
+ border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
18
+ backgroundColor: colors.surface.extraLight,
19
+ color: colors.content.intense,
20
+ fontFamily: primitives.font.family.primary,
21
+ fontSize: primitives.font.size.s,
22
+ cursor: "pointer",
23
+ transition: "border-color 150ms ease",
24
+ "@media": {
25
+ "(prefers-reduced-motion: reduce)": { transition: "none" },
26
+ },
27
+ },
28
+ variants: {
29
+ selected: {
30
+ true: {
31
+ borderColor: colors.common.accent,
32
+ borderWidth: primitives.stroke.medium,
33
+ },
34
+ false: {},
35
+ },
36
+ outOfStock: {
37
+ // Struck but still clickable; the buy CTA carries the state.
38
+ true: {
39
+ color: colors.content.subtle,
40
+ textDecoration: "line-through",
41
+ },
42
+ false: {},
43
+ },
44
+ nonExistent: {
45
+ // Faded and non-interactive, distinct from sold out above.
46
+ true: {
47
+ opacity: 0.35,
48
+ cursor: "default",
49
+ },
50
+ false: {},
51
+ },
52
+ },
53
+ defaultVariants: { selected: false, outOfStock: false, nonExistent: false },
54
+ });
55
+
56
+ // Small color/material swatch shown before the label on image chips.
57
+ export const swatch = style({
58
+ width: "20px",
59
+ height: "20px",
60
+ borderRadius: primitives.radius.full,
61
+ objectFit: "cover",
62
+ display: "block",
63
+ });