create-skybridge 0.0.0-dev.994f77c → 0.0.0-dev.995023d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +107 -17
- package/package.json +1 -1
- package/templates/blank/README.md +2 -1
- package/templates/blank/node_modules/.bin/alpic +2 -2
- package/templates/blank/package.json +5 -4
- package/templates/blank/src/index.ts +3 -0
- package/templates/blank/src/server.ts +7 -11
- package/templates/blank/vite.config.ts +1 -1
- package/templates/demo/README.md +3 -1
- package/templates/demo/evals/start.eval.ts +11 -0
- package/templates/demo/node_modules/.bin/alpic +2 -2
- package/templates/demo/node_modules/.bin/vitest +21 -0
- package/templates/demo/package.json +11 -5
- package/templates/demo/src/index.ts +3 -0
- package/templates/demo/src/server.ts +86 -88
- package/templates/demo/src/views/onboarding.tsx +3 -3
- package/templates/demo/tsconfig.evals.json +11 -0
- package/templates/demo/vite.config.ts +3 -3
- package/templates/ecom/.env.template +5 -0
- package/templates/ecom/README.md +2 -1
- package/templates/ecom/node_modules/.bin/alpic +2 -2
- package/templates/ecom/node_modules/.bin/ladle +2 -2
- package/templates/ecom/node_modules/.bin/vite +2 -2
- package/templates/ecom/package.json +3 -2
- package/templates/ecom/src/catalog/index.ts +19 -0
- package/templates/ecom/src/catalog/mock.ts +134 -0
- package/templates/ecom/src/catalog/shopify.ts +264 -0
- package/templates/ecom/src/components/product-card.tsx +2 -2
- package/templates/ecom/src/components/variant-picker.stories.tsx +1 -1
- package/templates/ecom/src/components/variant-picker.tsx +1 -1
- package/templates/ecom/src/components/view-frame.tsx +4 -4
- package/templates/ecom/src/index.ts +3 -0
- package/templates/ecom/src/lib/variants.ts +1 -1
- package/templates/ecom/src/server.ts +17 -21
- package/templates/ecom/src/tools/render-carousel.ts +5 -89
- package/templates/ecom/src/tools/search-products.ts +32 -21
- package/templates/ecom/src/types.ts +72 -0
- package/templates/ecom/src/views/carousel/detail/detail.css.ts +2 -0
- package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +8 -1
- package/templates/ecom/src/views/carousel/detail/index.tsx +1 -1
- package/templates/ecom/src/views/carousel/index.tsx +1 -2
- package/templates/ecom/vite.config.ts +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { skybridge } from "@skybridge/vite-plugin";
|
|
2
3
|
import tailwindcss from "@tailwindcss/vite";
|
|
3
4
|
import react from "@vitejs/plugin-react";
|
|
4
|
-
import { skybridge } from "skybridge/vite";
|
|
5
5
|
import { defineConfig } from "vite";
|
|
6
6
|
|
|
7
7
|
export default defineConfig({
|
|
8
|
-
plugins: [skybridge(), react(), tailwindcss()],
|
|
8
|
+
plugins: [skybridge({ evals: {} }), react(), tailwindcss()],
|
|
9
9
|
server: {
|
|
10
10
|
forwardConsole: {
|
|
11
11
|
unhandledErrors: true,
|
|
@@ -14,7 +14,7 @@ export default defineConfig({
|
|
|
14
14
|
},
|
|
15
15
|
resolve: {
|
|
16
16
|
alias: {
|
|
17
|
-
"@": path.resolve(
|
|
17
|
+
"@": path.resolve(import.meta.dirname, "./src"),
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
});
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
# Copy to .env and fill in. Sourced by the server at startup.
|
|
2
2
|
API_KEY=
|
|
3
|
+
|
|
4
|
+
# Only for the Shopify catalog provider (src/catalog/shopify.ts).
|
|
5
|
+
# The token is the public Storefront API access token, not an Admin key.
|
|
6
|
+
SHOPIFY_STORE_DOMAIN=
|
|
7
|
+
SHOPIFY_STOREFRONT_TOKEN=
|
package/templates/ecom/README.md
CHANGED
|
@@ -48,7 +48,8 @@ This command starts:
|
|
|
48
48
|
|
|
49
49
|
```
|
|
50
50
|
├── src/
|
|
51
|
-
│ ├──
|
|
51
|
+
│ ├── index.ts # Entry point (starts the app)
|
|
52
|
+
│ ├── server.ts # App definition (tools, views)
|
|
52
53
|
│ └── helpers.ts # Shared utilities
|
|
53
54
|
├── vite.config.ts
|
|
54
55
|
├── alpic.json # Deployment config
|
|
@@ -10,9 +10,9 @@ case `uname` in
|
|
|
10
10
|
esac
|
|
11
11
|
|
|
12
12
|
if [ -z "$NODE_PATH" ]; then
|
|
13
|
-
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.
|
|
13
|
+
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.157.0_@opentelemetry+api@1.9.1_@opentelemetry+core@2.9.0_@opentelemetry+api@1.9_8f13b9696a5fc8688953a3b2ccd28385/node_modules/alpic/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.157.0_@opentelemetry+api@1.9.1_@opentelemetry+core@2.9.0_@opentelemetry+api@1.9_8f13b9696a5fc8688953a3b2ccd28385/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
|
|
14
14
|
else
|
|
15
|
-
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.
|
|
15
|
+
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.157.0_@opentelemetry+api@1.9.1_@opentelemetry+core@2.9.0_@opentelemetry+api@1.9_8f13b9696a5fc8688953a3b2ccd28385/node_modules/alpic/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/alpic@1.157.0_@opentelemetry+api@1.9.1_@opentelemetry+core@2.9.0_@opentelemetry+api@1.9_8f13b9696a5fc8688953a3b2ccd28385/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
16
16
|
fi
|
|
17
17
|
if [ -x "$basedir/node" ]; then
|
|
18
18
|
exec "$basedir/node" "$basedir/../alpic/bin/run.js" "$@"
|
|
@@ -10,9 +10,9 @@ case `uname` in
|
|
|
10
10
|
esac
|
|
11
11
|
|
|
12
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.
|
|
13
|
+
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@swc+helpers@0.5.23_@types+node@24.13.3_@types+react@19.2.17_jiti@2._9105ecfa2ac4b29fe87a036530c3844f/node_modules/@ladle/react/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@swc+helpers@0.5.23_@types+node@24.13.3_@types+react@19.2.17_jiti@2._9105ecfa2ac4b29fe87a036530c3844f/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules"
|
|
14
14
|
else
|
|
15
|
-
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@types+node@24.13.
|
|
15
|
+
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@swc+helpers@0.5.23_@types+node@24.13.3_@types+react@19.2.17_jiti@2._9105ecfa2ac4b29fe87a036530c3844f/node_modules/@ladle/react/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/@ladle+react@5.1.1_@swc+helpers@0.5.23_@types+node@24.13.3_@types+react@19.2.17_jiti@2._9105ecfa2ac4b29fe87a036530c3844f/node_modules:/home/runner/work/skybridge/skybridge/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
16
16
|
fi
|
|
17
17
|
if [ -x "$basedir/node" ]; then
|
|
18
18
|
exec "$basedir/node" "$basedir/../@ladle/react/lib/cli/cli.js" "$@"
|
|
@@ -10,9 +10,9 @@ case `uname` in
|
|
|
10
10
|
esac
|
|
11
11
|
|
|
12
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.
|
|
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
14
|
else
|
|
15
|
-
export NODE_PATH="/home/runner/work/skybridge/skybridge/node_modules/.pnpm/vite@8.1.5_@types+node@24.13.
|
|
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
16
|
fi
|
|
17
17
|
if [ -x "$basedir/node" ]; then
|
|
18
18
|
exec "$basedir/node" "$basedir/../vite/bin/vite.js" "$@"
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"react": "^19.2.4",
|
|
18
18
|
"react-dom": "^19.2.4",
|
|
19
|
-
"skybridge": "^0.0.0-dev.
|
|
19
|
+
"skybridge": "^0.0.0-dev.995023d",
|
|
20
20
|
"vite": "^8.1.3",
|
|
21
21
|
"zod": "^4.4.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@ladle/react": "^5.1.1",
|
|
25
|
-
"@skybridge/devtools": "^
|
|
25
|
+
"@skybridge/devtools": "^0.0.0-dev.995023d",
|
|
26
|
+
"@skybridge/vite-plugin": "^0.0.0-dev.995023d",
|
|
26
27
|
"@types/node": "^24.13.2",
|
|
27
28
|
"@types/react": "^19.2.14",
|
|
28
29
|
"@types/react-dom": "^19.2.3",
|
|
@@ -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
|
+
}
|
|
@@ -30,8 +30,8 @@ export function ProductCard({
|
|
|
30
30
|
}: ProductCardProps) {
|
|
31
31
|
const { locale } = useUser();
|
|
32
32
|
const labels = useLabels();
|
|
33
|
-
// Show the first image. @todo: the rest of `media` is available here, e.g.
|
|
34
|
-
//
|
|
33
|
+
// Show the first image. @todo: the rest of `media` is available here, e.g. to
|
|
34
|
+
// swap in media[1] on hover (do not cross-fade, breaks with transparency)
|
|
35
35
|
const cover = media?.[0];
|
|
36
36
|
return (
|
|
37
37
|
<article className={styles.card({ framed: FRAMED })}>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { initialSelection, type Selection } from "../lib/variants.js";
|
|
3
|
-
import type { Product } from "../
|
|
3
|
+
import type { Product } from "../types.js";
|
|
4
4
|
import { VariantPicker } from "./variant-picker";
|
|
5
5
|
|
|
6
6
|
// A sparse catalog: {white,42} does not exist, so "42" is hard-disabled under
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { text } from "../design/tokens";
|
|
2
2
|
import { cx } from "../lib/cx";
|
|
3
3
|
import { applyChoice, axisStates, type Selection } from "../lib/variants.js";
|
|
4
|
-
import type { Product } from "../
|
|
4
|
+
import type { Product } from "../types.js";
|
|
5
5
|
import { Chip } from "./chip";
|
|
6
6
|
import * as styles from "./variant-picker.css";
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HTMLAttributes } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useUser } from "skybridge/web";
|
|
3
3
|
import { darkTheme, lightTheme } from "../design/tokens";
|
|
4
4
|
import { cx } from "../lib/cx";
|
|
5
5
|
import { viewFrame } from "./view-frame.css";
|
|
@@ -10,8 +10,8 @@ import { viewFrame } from "./view-frame.css";
|
|
|
10
10
|
* variables the color contract declares) and paints the base surface + font +
|
|
11
11
|
* content color so descendants inherit from the DS instead of the host page.
|
|
12
12
|
*
|
|
13
|
-
* It follows the host theme via
|
|
14
|
-
* (e.g. always light), drop
|
|
13
|
+
* It follows the host theme via useUser(). To lock the widget to one palette
|
|
14
|
+
* (e.g. always light), drop useUser and hardcode the theme class.
|
|
15
15
|
*
|
|
16
16
|
* Keep view entry files thin: render <ViewFrame> at the root and let this carry
|
|
17
17
|
* the theme + base-style boilerplate.
|
|
@@ -19,7 +19,7 @@ import { viewFrame } from "./view-frame.css";
|
|
|
19
19
|
type ViewFrameProps = HTMLAttributes<HTMLDivElement>;
|
|
20
20
|
|
|
21
21
|
export function ViewFrame({ className, ...rest }: ViewFrameProps) {
|
|
22
|
-
const { theme } =
|
|
22
|
+
const { theme } = useUser();
|
|
23
23
|
const themeClass = theme === "dark" ? darkTheme : lightTheme;
|
|
24
24
|
|
|
25
25
|
return <div {...rest} className={cx(themeClass, viewFrame, className)} />;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Product, Variant } from "../
|
|
1
|
+
import type { Product, Variant } from "../types.js";
|
|
2
2
|
|
|
3
3
|
// Pure helpers that turn the client's option choices into a concrete variant.
|
|
4
4
|
// The `variants` list is SPARSE: only combinations that exist are present, and
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { Skybridge } from "skybridge/server";
|
|
3
3
|
import { CAROUSEL_RANGE, MIN_SEARCH_ITERATIONS } from "./config.js";
|
|
4
4
|
import {
|
|
5
5
|
renderCarouselDefinition,
|
|
@@ -15,29 +15,25 @@ if (existsSync(".env")) {
|
|
|
15
15
|
process.loadEnvFile();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
// @todo: adapt this server-wide prompt to your catalog.
|
|
26
|
-
instructions: `\
|
|
18
|
+
export const app = new Skybridge({
|
|
19
|
+
// @todo: name and version your app.
|
|
20
|
+
name: "skybridge-ecom",
|
|
21
|
+
version: "0.0.1",
|
|
22
|
+
// @todo: adapt this server-wide prompt to your catalog.
|
|
23
|
+
instructions: `\
|
|
27
24
|
Two phases:
|
|
28
25
|
|
|
29
|
-
SEARCH: Call search-products ${MIN_SEARCH_ITERATIONS}+ times before presenting
|
|
30
|
-
Vary the
|
|
26
|
+
SEARCH: Call search-products ${MIN_SEARCH_ITERATIONS}+ times before presenting, never off one call. \
|
|
27
|
+
Vary the keywords or page deeper. \
|
|
31
28
|
Stay silent while searching: emit NO text between calls. Speak only \
|
|
32
|
-
once the carousel renders.
|
|
29
|
+
once the carousel renders.
|
|
33
30
|
|
|
34
31
|
RENDER: After curating, call render-carousel with the chosen product IDs (aim for ${CAROUSEL_RANGE}). \
|
|
35
|
-
Speak
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
Speak once it renders, then recommend products in carousel order.`,
|
|
33
|
+
handler: (server) =>
|
|
34
|
+
server
|
|
35
|
+
.registerTool(searchProductsDefinition, searchProductsHandler)
|
|
36
|
+
.registerTool(renderCarouselDefinition, renderCarouselHandler),
|
|
37
|
+
});
|
|
40
38
|
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
export type AppType = typeof server;
|
|
39
|
+
export type AppType = typeof app;
|