@cloudcart/storefront-mcp 0.0.0-stage → 0.1.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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Parts of the Storefront API that only answer when the merchant runs the app
3
+ * behind them.
4
+ *
5
+ * A storefront that assumes every field is always populated ships bugs that
6
+ * only appear on some stores — an empty list read as "this shop sells nothing
7
+ * customisable", a null read as "no reviews yet". None of these fields error;
8
+ * they simply return nothing, which is the harder failure to spot.
9
+ *
10
+ * Everything listed here was confirmed against the platform, not guessed, and
11
+ * every pattern was checked to match a type or operation that exists. A group
12
+ * whose patterns match nothing is worse than no group at all: it reads as
13
+ * covered while never firing.
14
+ *
15
+ * That is why up-sell and cross-sell are not here. They are real app-gated
16
+ * behaviour, but they surface as input fields — `CartLineInput.upSellTriggerVariantId`
17
+ * and `crossSellId` — which this matcher never sees. The guide carries them
18
+ * instead.
19
+ */
20
+ export interface AppResourceGroup {
21
+ /** Stable identifier for the group. */
22
+ group: string;
23
+ /** Human-readable label. */
24
+ label: string;
25
+ /** Shown once per group in introspection results. */
26
+ notice: string;
27
+ /** Matched case-insensitively as substrings of type / field / operation names. */
28
+ patterns: string[];
29
+ }
30
+ export declare const APP_RESOURCE_GROUPS: AppResourceGroup[];
31
+ export declare function matchAppResourceGroup(name: string): AppResourceGroup | null;
32
+ export declare function formatAppNotice(group: AppResourceGroup): string;
33
+ /**
34
+ * The admin MCP flags any operation taking an app `key`. The Storefront API has
35
+ * no such parameter: a storefront never addresses an app directly, it just gets
36
+ * emptier answers. Kept so the shared introspection code has something to
37
+ * reference, and deliberately matches nothing.
38
+ */
39
+ export declare const APP_KEY_NOTICE_GROUP: AppResourceGroup;
40
+ //# sourceMappingURL=app-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-resources.d.ts","sourceRoot":"","sources":["../src/app-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,EA4EjD,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAQ3E;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAE/D;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAOlC,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Parts of the Storefront API that only answer when the merchant runs the app
3
+ * behind them.
4
+ *
5
+ * A storefront that assumes every field is always populated ships bugs that
6
+ * only appear on some stores — an empty list read as "this shop sells nothing
7
+ * customisable", a null read as "no reviews yet". None of these fields error;
8
+ * they simply return nothing, which is the harder failure to spot.
9
+ *
10
+ * Everything listed here was confirmed against the platform, not guessed, and
11
+ * every pattern was checked to match a type or operation that exists. A group
12
+ * whose patterns match nothing is worse than no group at all: it reads as
13
+ * covered while never firing.
14
+ *
15
+ * That is why up-sell and cross-sell are not here. They are real app-gated
16
+ * behaviour, but they surface as input fields — `CartLineInput.upSellTriggerVariantId`
17
+ * and `crossSellId` — which this matcher never sees. The guide carries them
18
+ * instead.
19
+ */
20
+ export const APP_RESOURCE_GROUPS = [
21
+ {
22
+ group: "product-options",
23
+ label: "Product Options",
24
+ notice: "Needs the `product_options` app. Without it `product.customizations` is an empty list and " +
25
+ "`CartLineInput.customizations` has nothing valid to send — the platform returns no fields at all " +
26
+ "rather than erroring. Treat an empty list as 'the merchant asks nothing about this product', " +
27
+ "not as a failure.",
28
+ patterns: ["customization", "productcustomization"],
29
+ },
30
+ {
31
+ group: "store-locations",
32
+ label: "Store Locations",
33
+ notice: "Collect-from-shop is the merchant's `store_locations` app: `CartDeliveryAddressInput.storeId` picks one " +
34
+ "of the shops `storeLocations` lists. `storeLocations` lists the merchant's shops whether the app is on or " +
35
+ "not, so a store locator works either way.",
36
+ patterns: ["storelocation"],
37
+ },
38
+ {
39
+ group: "delivery-hours",
40
+ label: "Delivery Time Slots",
41
+ notice: "Needs the merchant's delivery hours app (`shipping_hours`), and only for couriers that deliver in slots. " +
42
+ "For such a courier send `deliverySlotKey` with `cartSelectedDeliveryOptionUpdate`, from " +
43
+ "`cartDeliverySlots`: without it `cartCheckoutReadiness` lists `DELIVERY_SLOT` and the order is refused. " +
44
+ "For every other courier the list is empty and no slot is needed.",
45
+ patterns: ["deliveryslot"],
46
+ },
47
+ {
48
+ group: "gdpr",
49
+ label: "GDPR Consents",
50
+ notice: "When the GDPR app is active, `checkoutSettings.legal.gdprActive` is true and the consents to " +
51
+ "collect come from `gdprPolicies`; the legacy `termsPages` list is then empty. The two are " +
52
+ "mutually exclusive — render whichever is populated, never both.",
53
+ patterns: ["gdpr", "consent"],
54
+ },
55
+ {
56
+ group: "reviews",
57
+ label: "Product Reviews",
58
+ notice: "Needs the merchant's reviews app (`product_review`), installed and active. Without it `product.reviews` " +
59
+ "is empty and `product.reviewSummary` " +
60
+ "is null — which means 'reviews are not in use here', not 'this product has no reviews'. Hide the " +
61
+ "section rather than showing a zero.",
62
+ patterns: ["review"],
63
+ },
64
+ {
65
+ group: "credit",
66
+ label: "Instalments & Leasing",
67
+ notice: "Requires a credit provider the merchant set up. A payment method with `group: CREDIT` is refused " +
68
+ "without a plan — read `cartCreditPlans` and pass one of its `creditPlanId`s (and `downPayment` where " +
69
+ "the plan takes one) to `cartPaymentMethodUpdate`.",
70
+ patterns: ["creditplan"],
71
+ },
72
+ {
73
+ group: "analytics",
74
+ label: "Pixels & Server-side Events",
75
+ notice: "Which pixels answer depends on what the merchant has connected — read `analyticsSettings` first. " +
76
+ "`analyticsEventPublish` returns the `eventId` the browser pixel must reuse, otherwise the vendor counts " +
77
+ "the same conversion twice.",
78
+ patterns: ["analytics"],
79
+ },
80
+ {
81
+ group: "returns",
82
+ label: "Returns",
83
+ notice: "Needs the merchant's returns app (`aftercare`): without it `returnByReference` answers null and the " +
84
+ "flow a `NOT_AVAILABLE` error. The flow is start → verify by emailed code → create, and " +
85
+ "`returnByReference` reads one back without a customer token.",
86
+ patterns: ["return"],
87
+ },
88
+ ];
89
+ export function matchAppResourceGroup(name) {
90
+ const needle = name.toLowerCase();
91
+ return (APP_RESOURCE_GROUPS.find((group) => group.patterns.some((pattern) => needle.includes(pattern))) ?? null);
92
+ }
93
+ export function formatAppNotice(group) {
94
+ return `ℹ️ ${group.label} — ${group.notice}`;
95
+ }
96
+ /**
97
+ * The admin MCP flags any operation taking an app `key`. The Storefront API has
98
+ * no such parameter: a storefront never addresses an app directly, it just gets
99
+ * emptier answers. Kept so the shared introspection code has something to
100
+ * reference, and deliberately matches nothing.
101
+ */
102
+ export const APP_KEY_NOTICE_GROUP = {
103
+ group: "app-key",
104
+ label: "Application-Provided",
105
+ notice: "This resource comes from a marketplace app. The Storefront API never names an app directly — " +
106
+ "when one is missing the field simply answers empty.",
107
+ patterns: [],
108
+ };
109
+ //# sourceMappingURL=app-resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-resources.js","sourceRoot":"","sources":["../src/app-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAaH,MAAM,CAAC,MAAM,mBAAmB,GAAuB;IACrD;QACE,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,iBAAiB;QACxB,MAAM,EACJ,4FAA4F;YAC5F,mGAAmG;YACnG,+FAA+F;YAC/F,mBAAmB;QACrB,QAAQ,EAAE,CAAC,eAAe,EAAE,sBAAsB,CAAC;KACpD;IACD;QACE,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,iBAAiB;QACxB,MAAM,EACJ,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,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAC3D,IAAI,IAAI,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAuB;IACrD,OAAO,OAAO,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAqB;IACpD,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,sBAAsB;IAC7B,MAAM,EACJ,+FAA+F;QAC/F,qDAAqD;IACvD,QAAQ,EAAE,EAAE;CACb,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ import { z } from "zod";
6
+ import { learnStorefrontApi } from "./tools/learn-storefront-api.js";
7
+ import { introspectSchema } from "./tools/introspect-schema.js";
8
+ import { validateGraphql } from "./tools/validate-graphql.js";
9
+ // The package's own version, so a release changes it in one place.
10
+ const { version } = createRequire(import.meta.url)("../package.json");
11
+ const server = new McpServer({
12
+ name: "cloudcart-storefront-mcp",
13
+ version,
14
+ });
15
+ server.tool("learn_cloudcart_storefront", `Call this first, before anything else in this server.
16
+
17
+ It returns a conversationId that every other tool here requires, and — more
18
+ usefully — what the CloudCart Storefront API's schema does not show: how a
19
+ signed-in buyer is sent (an argument or @inContext(buyer:), never an
20
+ Authorization header), that a Nitrogen storefront's checkout is the store's own
21
+ (cart.checkoutUrl), that the server owns every price and money is shown as
22
+ \`formatted\`, and that a cart is addressed by an unguessable key.
23
+
24
+ Reading it first is the difference between a storefront that works and one that
25
+ charges the wrong total.`, {
26
+ conversationId: z
27
+ .string()
28
+ .optional()
29
+ .describe("An existing conversation id. Omit to start a new one."),
30
+ model: z
31
+ .string()
32
+ .optional()
33
+ .describe("Your model name or id (e.g. 'claude-opus-5'). Used to improve this documentation."),
34
+ }, async (input) => learnStorefrontApi(input));
35
+ server.tool("introspect_graphql_schema", `Look up types, queries and mutations in the CloudCart Storefront schema by name.
36
+
37
+ Use this when you already know what something is called. When you know what you
38
+ want to do but not what it is called, read learn_cloudcart_storefront's guide
39
+ first — it names the operation for each step.
40
+
41
+ It searches the names of types, queries and mutations, not of fields: look up
42
+ the type that holds a field.
43
+
44
+ Results flag fields that only answer when the merchant runs the app behind them,
45
+ which is the usual explanation for an empty list.`, {
46
+ query: z
47
+ .string()
48
+ .describe("Name or part of a name — 'Cart', 'cartLinesAdd', 'delivery', 'MoneyV2'."),
49
+ filter: z
50
+ .array(z.enum(["all", "types", "queries", "mutations"]))
51
+ .optional()
52
+ .default(["all"])
53
+ .describe("Restrict the search to one category."),
54
+ mode: z
55
+ .enum(["full", "compact"])
56
+ .optional()
57
+ .default("full")
58
+ .describe("`full` expands the best match with all its fields. `compact` returns the summary line only — use it when you already have the signature and just want a sanity check."),
59
+ conversationId: z.string().describe("From learn_cloudcart_storefront."),
60
+ api: z.enum(["storefront"]).optional().default("storefront").describe("Which schema to search."),
61
+ }, async (input) => introspectSchema(input));
62
+ server.tool("validate_graphql_codeblocks", `Check GraphQL against the Storefront schema before it reaches a browser.
63
+
64
+ Always run generated queries and mutations through this. The schema is large
65
+ and has many close names, and an invented field looks entirely plausible until
66
+ it fails.
67
+
68
+ Beyond schema validity it flags mistakes that validate cleanly and still fail at
69
+ runtime, such as a numeric cart id or reading delivery before the cart has an
70
+ address, and it answers names borrowed from other storefront APIs with the
71
+ CloudCart one.`, {
72
+ codeblocks: z
73
+ .array(z.object({
74
+ content: z
75
+ .string()
76
+ .describe("Raw GraphQL — no markdown fences."),
77
+ artifactId: z
78
+ .string()
79
+ .optional()
80
+ .describe("Reuse the same id when revalidating a corrected version of the same block."),
81
+ revision: z
82
+ .number()
83
+ .int()
84
+ .positive()
85
+ .optional()
86
+ .describe("Starts at 1; increment on each retry of the same artifactId."),
87
+ }))
88
+ .describe("The code blocks to check."),
89
+ api: z.enum(["storefront"]).optional().default("storefront").describe("Which schema to validate against."),
90
+ conversationId: z.string().describe("From learn_cloudcart_storefront."),
91
+ }, async (input) => validateGraphql(input));
92
+ async function main() {
93
+ const transport = new StdioServerTransport();
94
+ await server.connect(transport);
95
+ }
96
+ main().catch((error) => {
97
+ console.error("Fatal error:", error);
98
+ process.exit(1);
99
+ });
100
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,mEAAmE;AACnE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAwB,CAAC;AAE7F,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,0BAA0B;IAChC,OAAO;CACR,CAAC,CAAC;AAEH,MAAM,CAAC,IAAI,CACT,4BAA4B,EAC5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,CAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;aACP,MAAM,EAAE;aACR,QAAQ,CAAC,mCAAmC,CAAC;QAChD,UAAU,EAAE,CAAC;aACV,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,4EAA4E,CAAC;QACzF,QAAQ,EAAE,CAAC;aACR,MAAM,EAAE;aACR,GAAG,EAAE;aACL,QAAQ,EAAE;aACV,QAAQ,EAAE;aACV,QAAQ,CAAC,8DAA8D,CAAC;KAC5E,CAAC,CACH;SACA,QAAQ,CAAC,2BAA2B,CAAC;IACxC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IAC1G,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;CACxE,EACD,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CACxC,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What an assistant needs to know before writing against the Storefront API.
3
+ *
4
+ * Not a feature list — the schema carries one, and every type and field in it is
5
+ * documented. This is the set of things a competent developer gets wrong on the
6
+ * first attempt, because they follow from how the platform works rather than
7
+ * from how the schema looks.
8
+ *
9
+ * Organised by what you are building, since almost nobody builds all of it at
10
+ * once. Every claim here was checked against the deployed schema and the code
11
+ * behind it; check again when either changes.
12
+ */
13
+ export declare const STOREFRONT_GUIDE: string;
14
+ //# sourceMappingURL=storefront.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront.d.ts","sourceRoot":"","sources":["../../src/prompts/storefront.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,gBAAgB,QAoTrB,CAAC"}
@@ -0,0 +1,322 @@
1
+ /**
2
+ * What an assistant needs to know before writing against the Storefront API.
3
+ *
4
+ * Not a feature list — the schema carries one, and every type and field in it is
5
+ * documented. This is the set of things a competent developer gets wrong on the
6
+ * first attempt, because they follow from how the platform works rather than
7
+ * from how the schema looks.
8
+ *
9
+ * Organised by what you are building, since almost nobody builds all of it at
10
+ * once. Every claim here was checked against the deployed schema and the code
11
+ * behind it; check again when either changes.
12
+ */
13
+ export const STOREFRONT_GUIDE = `
14
+ # CloudCart Storefront API
15
+
16
+ \`POST /api/sf\` — one GraphQL endpoint for the whole storefront: catalog,
17
+ collections, search, content, cart, checkout, customer accounts, orders and
18
+ returns. One schema serves every client: Nitrogen storefronts, the mobile app
19
+ and others.
20
+
21
+ ## On a Nitrogen storefront
22
+
23
+ Nitrogen is CloudCart's framework for headless storefronts, and it sends the
24
+ requests: you write \`#graphql\` documents, not headers.
25
+
26
+ - The storefront's tokens and the buyer's IP go from the storefront's server.
27
+ The browser reaches the API only through the storefront's \`/api/sf\` proxy.
28
+ - The signed-in buyer's access token stays in the storefront's signed session
29
+ cookie. A document that should run for that buyer declares
30
+ \`$buyer: BuyerInput\` and \`@inContext(buyer: $buyer)\`, and the storefront
31
+ passes the buyer it read from the session.
32
+ - The checkout is the platform's: send the buyer to \`cart.checkoutUrl\`. An
33
+ order placed on the page itself — a product's one-step order — is
34
+ \`fastOrderSubmit\`. The API's own checkout steps below are for a client that
35
+ runs its own checkout, such as a mobile app.
36
+
37
+ The \`cloudcart-nitrogen\` skill shows the code for each.
38
+
39
+ ## Authentication
40
+
41
+ The storefront's access token goes in \`X-Storefront-Access-Token\`. It names the
42
+ store, so no operation takes a store argument.
43
+
44
+ A signed-in buyer is sent in one of two ways — **never in an \`Authorization\`
45
+ header**:
46
+
47
+ - \`customerAccessToken\` — the argument of \`customer\`, \`order\` and every
48
+ customer mutation; they always take it, \`@inContext\` does not replace it. An invalid or expired token gives \`null\` from a query and a
49
+ \`TOKEN_INVALID\` error from a mutation.
50
+ - \`@inContext(buyer: {customerAccessToken: …})\` on the operation — the whole
51
+ operation runs for that buyer: their customer group's prices and discounts,
52
+ and the buyer of a fast order and of the store's forms. An invalid or expired
53
+ token is ignored and the operation runs as a guest. It does not give a cart an
54
+ owner: \`buyerIdentity.customerAccessToken\` on \`cartCreate\` or
55
+ \`cartBuyerIdentityUpdate\` does. \`BuyerInput\` is \`{customerAccessToken}\`.
56
+
57
+ The token comes from \`customerLoginCodeVerify\`. On the web keep it on the server
58
+ — Nitrogen keeps it in the signed session cookie — never in a URL, browser
59
+ storage or client code.
60
+
61
+ \`@inContext(country:, language:)\` are accepted and ignored: a store serves one
62
+ country and one language.
63
+
64
+ ## Conventions that hold everywhere
65
+
66
+ **Ids are global.** \`gid://cloudcart/Product/123\`. Most single-object queries
67
+ also accept \`handle\`, which is what a URL carries — prefer it. \`node(id)\` and
68
+ \`nodes(ids)\` read a product, collection, vendor, tag, page, blog, article or
69
+ store location by its id.
70
+
71
+ **Lists are Relay connections** with \`edges\`, \`nodes\`, \`pageInfo\`. Use \`nodes\`
72
+ unless you need cursors. \`first\` and \`last\` default to 25 and a larger value is
73
+ cut to 100 on most lists (a product's \`reviews\`: 10 and 50). \`first\`/\`after\` page forward
74
+ and \`last\`/\`before\` back, except \`relatedProducts\`, which pages forward only.
75
+ Trust \`pageInfo.hasNextPage\`, not the number of nodes you got.
76
+
77
+ **Show \`formatted\`.** Every \`MoneyV2\` has \`amount\`, a decimal string for logic,
78
+ and \`formatted\`, the amount as the store writes money: its currency's symbol and
79
+ where it stands, its decimals and separators. Never format \`amount\` yourself. An
80
+ amount you add up from amounts the API gave is written with \`Shop.currencyFormat\`,
81
+ the pattern \`formatted\` is made with.
82
+
83
+ **Mutations do not throw for a business failure.** Each payload carries its
84
+ errors — \`userErrors\`, or \`customerUserErrors\` on the customer payloads — each
85
+ with a \`message\` meant for the buyer and, on most, \`field\` and \`code\`. Empty
86
+ means success. A cart payload also carries \`warnings\`: inputs that were sent and
87
+ had no effect, such as a discount code the store did not honour. A GraphQL-level
88
+ error means the request itself was malformed.
89
+
90
+ **Some fields depend on the merchant's apps.** They answer empty rather than
91
+ erroring, which is the harder failure to notice. \`introspect_graphql_schema\`
92
+ flags them.
93
+
94
+ ---
95
+
96
+ # Catalog
97
+
98
+ \`products(first, after, query, sortKey, reverse, filters, smartFacetCounts)\`
99
+ returns a \`ProductConnection\` with:
100
+
101
+ - \`nodes\` — the products
102
+ - \`totalCount\` — the real total for the query and filters, for "47 products"
103
+ - \`filters\` — the facets **for this result set**, from the store's search engine,
104
+ and \`filterCapabilities\` — whether their counts are exact and their values
105
+ complete
106
+
107
+ Build the facet sidebar from \`filters\` (on a search, \`productFilters\`); do not
108
+ hardcode facets. Each \`Filter\`
109
+ has an \`id\`, a \`label\`, a \`type\` (\`LIST\`, \`BOOLEAN\`, \`PRICE_RANGE\`, \`RANGE\`,
110
+ \`SWATCH_COLOR\`, \`SWATCH_IMAGE\`) and \`values\`, each with its \`count\` and its
111
+ \`input\`: the \`ProductFilter\` to send back when the buyer picks it. Ranges add
112
+ \`minValue\`/\`maxValue\`, \`rangeStep\` and \`decimals\`. A collection's, a vendor's
113
+ and a tag's \`products\` take the same arguments.
114
+
115
+ \`smartFacetCounts\` (default true) recounts each active facet as if its own
116
+ filter were off, so a buyer sees what another value would give. It costs one
117
+ more engine search per active filter; turn it off when you do not show those
118
+ counts.
119
+
120
+ \`ProductFilter\` accepts \`available\`, \`onSale\`, \`isNew\`, \`isFeatured\`, \`tag\`,
121
+ \`productVendor\`, \`price\`, \`variantOption\`, \`category\`, \`brandModel\` and
122
+ \`productMetafield\` (a category property's value). Send back a value's \`input\`
123
+ rather than building one.
124
+
125
+ Sort with \`ProductSortKeys\`: \`TITLE\`, \`PRICE\`, \`BEST_SELLING\`, \`CREATED_AT\`,
126
+ \`UPDATED_AT\`, \`PRODUCT_TYPE\`, \`VENDOR\`, \`RELEVANCE\`, \`ID\`. Without a \`sortKey\`
127
+ a list comes in the store's own order.
128
+
129
+ For "you may also like", \`product.relatedProducts\` pages through the merchant's
130
+ linked products, then the product's category; \`product.linkedProducts\` is the
131
+ linked ones alone. \`productRecommendations(productId | productHandle, intent)\`
132
+ gives a short list: \`RELATED\` or \`COMPLEMENTARY\`.
133
+
134
+ ## Collections
135
+
136
+ A collection is a category or a merchant's selection (a smart collection), in
137
+ one type; \`kind\` on \`collection\` and \`collections\` tells them apart. A smart
138
+ collection's id carries \`sc_\` — \`gid://cloudcart/Collection/sc_12\` — so never
139
+ parse an id as a number.
140
+
141
+ \`Collection\` gives you a whole category page: \`parent\`, \`children\`,
142
+ \`breadcrumb\`, \`productsCount\`, \`displayChildren\`, \`seo\`, \`googleTaxonomy\`,
143
+ plus \`restrictions\`, which is why a payment or shipping method may be unavailable
144
+ later in the checkout.
145
+
146
+ ## Search
147
+
148
+ \`search(query, types, productFilters, sortKey, unavailableProducts, smartFacetCounts)\`
149
+ spans products, pages and articles. Its facets are \`productFilters\`, not
150
+ \`filters\`; \`totalCount\` counts every result and \`productCount\` the products.
151
+ \`predictiveSearch(query, limit, limitScope, types)\` is the type-ahead —
152
+ products, collections, vendors, pages and articles, smaller and faster.
153
+
154
+ ---
155
+
156
+ # Cart and checkout
157
+
158
+ **The server owns every number.** Never compute a price, discount, tax or total
159
+ in the storefront. Every cart mutation returns the whole repriced cart — read the
160
+ answer, do not predict it.
161
+
162
+ **Record where the buyer came from**, early, while the landing URL still exists:
163
+ \`cartAttributionUpdate\` keeps the landing page, referrer, visitor and UTM on the
164
+ cart, and both the store's checkout (through \`checkoutUrl\`) and
165
+ \`cartSubmitForCompletion\` read it. Skip it and the order is recorded as direct
166
+ traffic. A fast order takes the same in its \`attribution\` input.
167
+
168
+ **A cart's id is \`gid://cloudcart/Cart/<key>\`**, where the key is a long random
169
+ string. It is not a row number and cannot be guessed. Keep it yourself — a
170
+ Nitrogen storefront keeps it in a cookie; there is no implicit "current cart".
171
+
172
+ ## The checkout
173
+
174
+ **\`cart.checkoutUrl\`** hands the cart to the store's own checkout, signed in as
175
+ the buyer when the request carried one. It is signed and **valid for ten
176
+ minutes**: read it right before sending the buyer, not from a page loaded long
177
+ before, or the buyer lands on a 404.
178
+
179
+ **\`fastOrderSubmit(attemptToken, input)\`** places an order from the page: one
180
+ line or bundle, the buyer's contact and consents. It answers \`COMPLETED\` with the
181
+ order, or \`FAILED\` with \`userErrors\`.
182
+
183
+ ## The API's own checkout
184
+
185
+ For a client that runs its own checkout. **There are no steps:** no mutation has
186
+ to precede another. Ask what is missing and let that drive the UI:
187
+
188
+ \`\`\`graphql
189
+ query { cartCheckoutReadiness(cartId: $id) { status missing consents { id } } }
190
+ \`\`\`
191
+
192
+ \`missing\` names what remains — \`BUYER_EMAIL\`, \`DELIVERY_ADDRESS\`,
193
+ \`DELIVERY_OPTION\`, \`DELIVERY_SLOT\`, \`PAYMENT_METHOD\`, \`CONSENTS\` and others
194
+ (\`CartCheckoutRequirement\`).
195
+
196
+ 1. \`cartCreate\` — lines, buyer identity and discount codes in one call
197
+ 2. \`cartAttributionUpdate\` — early (above)
198
+ 3. \`cartDeliveryAddressUpdate\` — a street address, a courier office or locker
199
+ (\`pickupPointId\`), a merchant shop (\`storeId\`), or a signed-in buyer's saved
200
+ address (\`addressId\`)
201
+ 4. \`cart { delivery { carriers } }\` — the couriers that can deliver there; it
202
+ **calls no courier** and is cheap
203
+ 5. \`cartDeliveryQuote(cartId, carrierHandle)\` — one courier, live. Quote the
204
+ couriers **in parallel**, so one slow courier does not hold up the rest.
205
+ 6. \`cartSelectedDeliveryOptionUpdate\` — the option's handle, plus
206
+ \`deliverySlotKey\` for a courier that delivers in slots (\`cartDeliverySlots\`)
207
+ 7. \`cart { paymentMethods }\` → \`cartPaymentMethodUpdate\`
208
+ 8. \`cartSubmitForCompletion\` with an \`attemptToken\`
209
+
210
+ \`CartSubmitStatus\` is one of three: \`COMPLETED\` — the order exists;
211
+ \`REQUIRES_REDIRECT\` with \`redirectUrl\` — send the buyer to the payment
212
+ provider; \`FAILED\` — read \`userErrors\`. The \`attemptToken\`
213
+ makes retrying safe: the same token returns the same order instead of a second
214
+ one.
215
+
216
+ ## Traps
217
+
218
+ **Delivery needs an address.** \`carriers\` is empty until the cart has one, and a
219
+ quote without one is refused.
220
+
221
+ **Payment follows delivery.** \`paymentMethods\` is empty until a shippable cart
222
+ has a delivery service chosen: the courier decides half of what is allowed. Read
223
+ it again when delivery changes.
224
+
225
+ **Line discounts are already inside the subtotal.** Only order-level discounts
226
+ appear as separate rows of \`totals\` (the \`discount.before\` group). Adding the
227
+ line ones again double-counts.
228
+
229
+ **\`totals\` and \`cost\` come from one calculation** and cannot disagree.
230
+ \`totals\` is the merchant's ordered summary, with their own labels — the right
231
+ thing to render a summary panel from. \`cost\` is the same figures as named
232
+ aggregates, for when you just need the total.
233
+
234
+ **Customizations are not variant options.** A variant option picks *which*
235
+ variant. A customization — engraving, gift wrap, a cut to size — rides along with
236
+ the line, can change its price, and is part of the line's identity: the same
237
+ variant with different answers is a **separate line**, not a larger quantity.
238
+ Read \`product.customizations\` for what a product accepts.
239
+
240
+ **Bundles are groups, not lines.** \`cartBundleAdd\` adds one line per product in
241
+ the bundle, all sharing a \`bundle.id\`. Group by it for display. A bundle is added
242
+ whole or not at all.
243
+
244
+ **A cart may have no customer.** Identity arrives at any point, in any order.
245
+ Sending only a phone or a name creates nothing — it waits on the cart until an
246
+ email or a sign-in gives it an owner.
247
+
248
+ **Record where a line came from.** If the buyer took an up-sell or cross-sell
249
+ offer, send \`upSellTriggerVariantId\` or \`crossSellId\` on the line: the line is
250
+ then priced as the offer and counted in the merchant's reporting. Without the
251
+ store's up-sell and cross-sell app they do nothing, and the line gets a warning.
252
+
253
+ ---
254
+
255
+ # Customers
256
+
257
+ Sign in with \`customerLoginCodeSend\`, then \`customerLoginCodeVerify\`, which
258
+ returns the access token. **There is deliberately no password login and no
259
+ password reset.**
260
+
261
+ \`customer(customerAccessToken)\` is the account area in one query: \`orders\`,
262
+ \`wishlist\`, \`downloads\`, \`payments\`, \`returns\`, \`addresses\`,
263
+ \`billingAddresses\`, \`defaultAddress\`, \`numberOfOrders\`, \`tags\`.
264
+
265
+ Delivery and billing addresses are separate sets with separate mutations. A
266
+ buyer can have several: a street address, one per courier office, one per
267
+ locker. Do not assume one buyer has one address.
268
+
269
+ ## Orders
270
+
271
+ \`customer.orders\` lists them, newest first, with \`totalCount\`; there is no
272
+ filter or search over them. \`order(customerAccessToken, id)\` reads one with its
273
+ lines, addresses, payments, discounts, \`totals\` and \`returnEligibility\`.
274
+
275
+ **A guest reads an order's status** with \`orderStatus(id, email)\` — the order's
276
+ \`id\` and the email it was placed with: the status, the totals, whether it is
277
+ paid, nothing that identifies the buyer. A wrong pair answers \`null\`. It is how a
278
+ client returning from a payment provider asks the store what the payment did.
279
+
280
+ ## Returns
281
+
282
+ \`returnRequestStart\` → \`returnRequestVerify\` (a code sent by email) →
283
+ \`returnRequestCreate\`. \`returnByReference(reference)\` reads one back **without
284
+ a sign-in**, by the reference from the notification email. Returns need the
285
+ merchant's returns app; without it they answer \`null\` or a \`NOT_AVAILABLE\`
286
+ error.
287
+
288
+ ---
289
+
290
+ # Content and shop
291
+
292
+ \`page\`, \`pages\`, \`blog\`, \`blogs\`, \`article\`, \`articles\`, \`policies\` and
293
+ \`menu(handle)\` are the content. \`menu\` takes a handle such as \`main\` or
294
+ \`footer\` and returns the tree.
295
+
296
+ \`shop\` gives the store's name, description, logo, primary domain, contact,
297
+ payment settings and \`currencyFormat\`. \`checkoutSettings\` says which checkout
298
+ fields exist and whether each is required, optional or hidden — build a form from
299
+ it rather than hardcoding, because it differs per merchant. \`cookieConsent\` is
300
+ the merchant's cookie banner and its consent groups; \`subscribeForms\` are their
301
+ sign-up forms.
302
+
303
+ \`storeLocations\` lists the merchant's physical shops, for a store locator and
304
+ for collect-from-shop.
305
+
306
+ ---
307
+
308
+ # Analytics
309
+
310
+ \`analyticsSettings\` says which pixels the merchant runs. \`analyticsEventPublish\`
311
+ records an event and returns its \`eventId\` — fire the browser pixel's event with
312
+ that same id, or the vendor counts the conversion twice. A Nitrogen storefront
313
+ publishes its events through Nitrogen's analytics, not by hand.
314
+
315
+ ---
316
+
317
+ # Before you ship a query
318
+
319
+ Run it through \`validate_graphql_codeblocks\`. The schema is large, and close
320
+ names are easy to invent.
321
+ `.trim();
322
+ //# sourceMappingURL=storefront.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront.js","sourceRoot":"","sources":["../../src/prompts/storefront.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoT/B,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type GraphQLSchema, type IntrospectionQuery } from "graphql";
2
+ interface SchemaCache {
3
+ raw: IntrospectionQuery;
4
+ schema: GraphQLSchema;
5
+ types: IntrospectionType[];
6
+ queries: IntrospectionField[];
7
+ mutations: IntrospectionField[];
8
+ }
9
+ export interface IntrospectionType {
10
+ name: string;
11
+ kind: string;
12
+ description?: string | null;
13
+ fields?: IntrospectionField[] | null;
14
+ inputFields?: IntrospectionInputField[] | null;
15
+ enumValues?: IntrospectionEnumValue[] | null;
16
+ interfaces?: IntrospectionTypeRef[] | null;
17
+ }
18
+ export interface IntrospectionField {
19
+ name: string;
20
+ description?: string | null;
21
+ args?: IntrospectionArg[];
22
+ type: IntrospectionTypeRef;
23
+ }
24
+ interface IntrospectionInputField {
25
+ name: string;
26
+ description?: string | null;
27
+ type: IntrospectionTypeRef;
28
+ defaultValue?: string | null;
29
+ }
30
+ interface IntrospectionEnumValue {
31
+ name: string;
32
+ description?: string | null;
33
+ }
34
+ interface IntrospectionArg {
35
+ name: string;
36
+ description?: string | null;
37
+ type: IntrospectionTypeRef;
38
+ defaultValue?: string | null;
39
+ }
40
+ interface IntrospectionTypeRef {
41
+ kind: string;
42
+ name?: string | null;
43
+ ofType?: IntrospectionTypeRef | null;
44
+ }
45
+ export declare function loadSchema(api: string): SchemaCache;
46
+ export {};
47
+ //# sourceMappingURL=loader.d.ts.map