From f55600ff7840dd38aa6d1edd997c6ff6c657d325 Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Thu, 29 Oct 2026 03:13:14 +0530 Subject: [PATCH] SX1: the storefront on Workers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vercel-partner-solutions/nextjs-salesforce-commerce-cloud (a474b5e, MIT in license.md) in apps/web, built by next build --webpack and @opennextjs/cloudflare 1.20.11 into one Worker with Static Assets: the R2 incremental cache (infra/terraform/cloudflare-r2), the sharded Durable Object tag cache and the Durable Object revalidation queue, as the commerce baselines have them. Cache Components are off and experimental.useCache keeps every "use cache" read with its cacheLife("days") and its collections/products tags — a Cache Components page answers 500 then hangs on workerd (opennextjs-cloudflare#1450); Next is 16.3.8, the lowest 16.x the adapter accepts. commerce-sdk-isomorphic 3.5.0 runs on workerd, and the SLAS guest login is upstream's: a public client's PKCE flow, or a private client's secret. next.config.ts env inlines SFCC_CLIENT_ID, SFCC_ORGANIZATIONID, SFCC_SHORTCODE, SFCC_SITEID, the origin and the company name at build; SFCC_SECRET and SFCC_REVALIDATION_SECRET are Worker secrets the deploy sets after the build, never inlined. With no coordinates (lib/sfcc/connection.ts) every reader answers empty, the guest login and every cart or checkout write refuse before a request, every page carries the connect note and / says "Connect your Salesforce Commerce Cloud store". getCart and getCheckoutOrder check their cookie before minting a guest token (upstream logged a guest in on every cart-less page view). /api/revalidate answers 503 with no secret, 401 to a missing or wrong ?secret= (constant time; upstream answered 200), and revalidates products or collections by x-sfcc-topic. SITE_NAME (app/site.ts) is the one store-name seam; the Open Graph images draw on workerd; /api/health. Upstream's check (prettier --check, formatted once because it failed upstream) is the app's test; ESLint added for the workspace's lint. typecheck, lint, test (upstream's check and tests/web's 23, including both guest logins against the stand-in) and build are green; the Worker is 2.53 MiB gzipped (Workers Free). Co-Authored-By: Claude Orun-Task: SX-2 --- README.md | 117 +- apps/web/.env.example | 21 + apps/web/.gitignore | 49 + apps/web/.prettierignore | 6 + apps/web/README.md | 47 + apps/web/app/[page]/layout.tsx | 12 + apps/web/app/[page]/opengraph-image.tsx | 17 + apps/web/app/[page]/page.tsx | 50 + apps/web/app/api/health/route.ts | 12 + apps/web/app/api/revalidate/route.ts | 6 + .../app/checkout/(main)/information/page.tsx | 13 + apps/web/app/checkout/(main)/layout.tsx | 47 + apps/web/app/checkout/(main)/page.tsx | 11 + apps/web/app/checkout/(main)/payment/page.tsx | 22 + .../web/app/checkout/(main)/shipping/page.tsx | 24 + apps/web/app/checkout/confirmation/page.tsx | 64 + apps/web/app/error.tsx | 19 + apps/web/app/favicon.ico | Bin 0 -> 15086 bytes apps/web/app/globals.css | 43 + apps/web/app/layout.tsx | 50 + apps/web/app/opengraph-image.tsx | 5 + apps/web/app/page.tsx | 32 + apps/web/app/product/[handle]/page.tsx | 156 + apps/web/app/robots.ts | 13 + .../search/[collection]/opengraph-image.tsx | 14 + apps/web/app/search/[collection]/page.tsx | 50 + apps/web/app/search/children-wrapper.tsx | 14 + apps/web/app/search/layout.tsx | 31 + apps/web/app/search/loading.tsx | 21 + apps/web/app/search/page.tsx | 39 + apps/web/app/site.ts | 9 + apps/web/app/sitemap.ts | 48 + apps/web/cloudflare-env.d.ts | 15 + apps/web/component.yaml | 129 + apps/web/components.json | 18 + apps/web/components/carousel.tsx | 46 + apps/web/components/cart/actions.ts | 108 + apps/web/components/cart/add-to-cart.tsx | 94 + apps/web/components/cart/cart-context.tsx | 233 + .../components/cart/delete-item-button.tsx | 38 + .../cart/edit-item-quantity-button.tsx | 61 + apps/web/components/cart/modal.tsx | 270 + apps/web/components/cart/open-cart.tsx | 27 + apps/web/components/cc-input.tsx | 88 + apps/web/components/checkout/actions.ts | 164 + apps/web/components/checkout/address-form.tsx | 274 + .../web/components/checkout/checkout-cart.tsx | 118 + .../components/checkout/checkout-context.tsx | 120 + .../components/checkout/checkout-crumbs.tsx | 55 + .../components/checkout/checkout-error.tsx | 18 + .../components/checkout/checkout-status.tsx | 214 + .../checkout/collapsible-summary.tsx | 44 + .../components/checkout/information-form.tsx | 79 + apps/web/components/checkout/loading-cart.tsx | 36 + .../checkout/loading-shipping-methods.tsx | 28 + apps/web/components/checkout/payment-form.tsx | 226 + .../web/components/checkout/shipping-form.tsx | 109 + apps/web/components/connect-store.tsx | 55 + apps/web/components/grid/index.tsx | 27 + apps/web/components/grid/three-items.tsx | 68 + apps/web/components/grid/tile.tsx | 52 + apps/web/components/icons/cc-icons.tsx | 77 + apps/web/components/icons/logo.tsx | 17 + apps/web/components/label.tsx | 43 + apps/web/components/layout/copyright-date.tsx | 7 + apps/web/components/layout/footer-menu.tsx | 46 + apps/web/components/layout/footer.tsx | 81 + apps/web/components/layout/navbar/index.tsx | 62 + .../components/layout/navbar/mobile-menu.tsx | 104 + apps/web/components/layout/navbar/search.tsx | 44 + .../components/layout/product-grid-items.tsx | 37 + .../components/layout/search/collections.tsx | 37 + .../layout/search/filter/dropdown.tsx | 69 + .../components/layout/search/filter/index.tsx | 47 + .../components/layout/search/filter/item.tsx | 76 + apps/web/components/loading-dots.tsx | 15 + apps/web/components/logo-square.tsx | 23 + apps/web/components/opengraph-image.tsx | 64 + apps/web/components/phone-input.tsx | 132 + apps/web/components/postal-code-input.tsx | 133 + apps/web/components/price.tsx | 54 + apps/web/components/product/gallery.tsx | 97 + .../components/product/product-context.tsx | 99 + .../product/product-description.tsx | 26 + apps/web/components/product/product-price.tsx | 33 + .../components/product/variant-selector.tsx | 128 + apps/web/components/prose.tsx | 15 + apps/web/components/ui/alert.tsx | 67 + apps/web/components/ui/button.tsx | 58 + apps/web/components/ui/card.tsx | 86 + apps/web/components/ui/checkbox.tsx | 32 + apps/web/components/ui/collapsible.tsx | 33 + apps/web/components/ui/input.tsx | 25 + apps/web/components/ui/label.tsx | 26 + apps/web/components/ui/radio-group.tsx | 44 + apps/web/components/ui/select.tsx | 163 + apps/web/components/ui/separator.tsx | 31 + apps/web/components/ui/skeleton.tsx | 18 + apps/web/components/welcome-toast.tsx | 37 + apps/web/docs/architecture.md | 39 + apps/web/docs/overview.md | 20 + apps/web/docs/runbook.md | 41 + apps/web/eslint.config.mjs | 20 + apps/web/lib/constants.ts | 8 + apps/web/lib/sfcc/connection.ts | 27 + apps/web/lib/sfcc/constants.ts | 85 + apps/web/lib/sfcc/content.ts | 207 + apps/web/lib/sfcc/index.ts | 820 ++ apps/web/lib/sfcc/reshape.ts | 330 + apps/web/lib/sfcc/schemas.ts | 59 + apps/web/lib/sfcc/type-guards.ts | 17 + apps/web/lib/sfcc/types.ts | 193 + apps/web/lib/sfcc/utils.ts | 249 + apps/web/lib/utils.ts | 29 + apps/web/license.md | 21 + apps/web/next.config.ts | 51 + apps/web/open-next.config.ts | 31 + apps/web/package.json | 58 + apps/web/postcss.config.mjs | 6 + apps/web/public/fonts/Inter-Bold.ttf | Bin 0 -> 316100 bytes apps/web/tailwind.config.js | 76 + apps/web/tsconfig.json | 37 + apps/web/turbo.json | 19 + apps/web/wiring.fixture.json | 11 + apps/web/wrangler.jsonc | 54 + apps/web/wrangler.template.jsonc | 62 + infra/terraform/cloudflare-r2/component.yaml | 62 + .../cloudflare-r2/docs/architecture.md | 29 + .../terraform/cloudflare-r2/docs/overview.md | 19 + infra/terraform/cloudflare-r2/docs/runbook.md | 20 + .../cloudflare-r2/terraform/adopt.tf | 38 + .../cloudflare-r2/terraform/backend.tf | 5 + .../terraform/cloudflare-r2/terraform/main.tf | 120 + .../cloudflare-r2/terraform/outputs.tf | 2 + .../cloudflare-r2/terraform/variables.tf | 2 + pnpm-lock.yaml | 6752 ++++++++++++++++- specs/epics/README.md | 2 +- .../sfcc-commerce/IMPLEMENTATION-STATUS.md | 43 +- specs/epics/sfcc-commerce/README.md | 2 +- tests/web/component.yaml | 31 + tests/web/docs/architecture.md | 11 + tests/web/docs/overview.md | 20 + tests/web/docs/runbook.md | 26 + tests/web/eslint.config.js | 2 + tests/web/fake-sfcc.mjs | 251 + tests/web/package.json | 24 + tests/web/src/connection.test.ts | 153 + tests/web/src/fake.ts | 54 + tests/web/src/health.test.ts | 42 + tests/web/src/revalidate.test.ts | 111 + tests/web/src/site.test.ts | 29 + tests/web/src/utils.test.ts | 45 + tests/web/tsconfig.json | 21 + tests/web/vitest.config.ts | 22 + tooling/catalog/gen-component-docs.py | 550 ++ 155 files changed, 16701 insertions(+), 419 deletions(-) create mode 100644 apps/web/.env.example create mode 100644 apps/web/.gitignore create mode 100644 apps/web/.prettierignore create mode 100644 apps/web/README.md create mode 100644 apps/web/app/[page]/layout.tsx create mode 100644 apps/web/app/[page]/opengraph-image.tsx create mode 100644 apps/web/app/[page]/page.tsx create mode 100644 apps/web/app/api/health/route.ts create mode 100644 apps/web/app/api/revalidate/route.ts create mode 100644 apps/web/app/checkout/(main)/information/page.tsx create mode 100644 apps/web/app/checkout/(main)/layout.tsx create mode 100644 apps/web/app/checkout/(main)/page.tsx create mode 100644 apps/web/app/checkout/(main)/payment/page.tsx create mode 100644 apps/web/app/checkout/(main)/shipping/page.tsx create mode 100644 apps/web/app/checkout/confirmation/page.tsx create mode 100644 apps/web/app/error.tsx create mode 100644 apps/web/app/favicon.ico create mode 100644 apps/web/app/globals.css create mode 100644 apps/web/app/layout.tsx create mode 100644 apps/web/app/opengraph-image.tsx create mode 100644 apps/web/app/page.tsx create mode 100644 apps/web/app/product/[handle]/page.tsx create mode 100644 apps/web/app/robots.ts create mode 100644 apps/web/app/search/[collection]/opengraph-image.tsx create mode 100644 apps/web/app/search/[collection]/page.tsx create mode 100644 apps/web/app/search/children-wrapper.tsx create mode 100644 apps/web/app/search/layout.tsx create mode 100644 apps/web/app/search/loading.tsx create mode 100644 apps/web/app/search/page.tsx create mode 100644 apps/web/app/site.ts create mode 100644 apps/web/app/sitemap.ts create mode 100644 apps/web/cloudflare-env.d.ts create mode 100644 apps/web/component.yaml create mode 100644 apps/web/components.json create mode 100644 apps/web/components/carousel.tsx create mode 100644 apps/web/components/cart/actions.ts create mode 100644 apps/web/components/cart/add-to-cart.tsx create mode 100644 apps/web/components/cart/cart-context.tsx create mode 100644 apps/web/components/cart/delete-item-button.tsx create mode 100644 apps/web/components/cart/edit-item-quantity-button.tsx create mode 100644 apps/web/components/cart/modal.tsx create mode 100644 apps/web/components/cart/open-cart.tsx create mode 100644 apps/web/components/cc-input.tsx create mode 100644 apps/web/components/checkout/actions.ts create mode 100644 apps/web/components/checkout/address-form.tsx create mode 100644 apps/web/components/checkout/checkout-cart.tsx create mode 100644 apps/web/components/checkout/checkout-context.tsx create mode 100644 apps/web/components/checkout/checkout-crumbs.tsx create mode 100644 apps/web/components/checkout/checkout-error.tsx create mode 100644 apps/web/components/checkout/checkout-status.tsx create mode 100644 apps/web/components/checkout/collapsible-summary.tsx create mode 100644 apps/web/components/checkout/information-form.tsx create mode 100644 apps/web/components/checkout/loading-cart.tsx create mode 100644 apps/web/components/checkout/loading-shipping-methods.tsx create mode 100644 apps/web/components/checkout/payment-form.tsx create mode 100644 apps/web/components/checkout/shipping-form.tsx create mode 100644 apps/web/components/connect-store.tsx create mode 100644 apps/web/components/grid/index.tsx create mode 100644 apps/web/components/grid/three-items.tsx create mode 100644 apps/web/components/grid/tile.tsx create mode 100644 apps/web/components/icons/cc-icons.tsx create mode 100644 apps/web/components/icons/logo.tsx create mode 100644 apps/web/components/label.tsx create mode 100644 apps/web/components/layout/copyright-date.tsx create mode 100644 apps/web/components/layout/footer-menu.tsx create mode 100644 apps/web/components/layout/footer.tsx create mode 100644 apps/web/components/layout/navbar/index.tsx create mode 100644 apps/web/components/layout/navbar/mobile-menu.tsx create mode 100644 apps/web/components/layout/navbar/search.tsx create mode 100644 apps/web/components/layout/product-grid-items.tsx create mode 100644 apps/web/components/layout/search/collections.tsx create mode 100644 apps/web/components/layout/search/filter/dropdown.tsx create mode 100644 apps/web/components/layout/search/filter/index.tsx create mode 100644 apps/web/components/layout/search/filter/item.tsx create mode 100644 apps/web/components/loading-dots.tsx create mode 100644 apps/web/components/logo-square.tsx create mode 100644 apps/web/components/opengraph-image.tsx create mode 100644 apps/web/components/phone-input.tsx create mode 100644 apps/web/components/postal-code-input.tsx create mode 100644 apps/web/components/price.tsx create mode 100644 apps/web/components/product/gallery.tsx create mode 100644 apps/web/components/product/product-context.tsx create mode 100644 apps/web/components/product/product-description.tsx create mode 100644 apps/web/components/product/product-price.tsx create mode 100644 apps/web/components/product/variant-selector.tsx create mode 100644 apps/web/components/prose.tsx create mode 100644 apps/web/components/ui/alert.tsx create mode 100644 apps/web/components/ui/button.tsx create mode 100644 apps/web/components/ui/card.tsx create mode 100644 apps/web/components/ui/checkbox.tsx create mode 100644 apps/web/components/ui/collapsible.tsx create mode 100644 apps/web/components/ui/input.tsx create mode 100644 apps/web/components/ui/label.tsx create mode 100644 apps/web/components/ui/radio-group.tsx create mode 100644 apps/web/components/ui/select.tsx create mode 100644 apps/web/components/ui/separator.tsx create mode 100644 apps/web/components/ui/skeleton.tsx create mode 100644 apps/web/components/welcome-toast.tsx create mode 100644 apps/web/docs/architecture.md create mode 100644 apps/web/docs/overview.md create mode 100644 apps/web/docs/runbook.md create mode 100644 apps/web/eslint.config.mjs create mode 100644 apps/web/lib/constants.ts create mode 100644 apps/web/lib/sfcc/connection.ts create mode 100644 apps/web/lib/sfcc/constants.ts create mode 100644 apps/web/lib/sfcc/content.ts create mode 100644 apps/web/lib/sfcc/index.ts create mode 100644 apps/web/lib/sfcc/reshape.ts create mode 100644 apps/web/lib/sfcc/schemas.ts create mode 100644 apps/web/lib/sfcc/type-guards.ts create mode 100644 apps/web/lib/sfcc/types.ts create mode 100644 apps/web/lib/sfcc/utils.ts create mode 100644 apps/web/lib/utils.ts create mode 100644 apps/web/license.md create mode 100644 apps/web/next.config.ts create mode 100644 apps/web/open-next.config.ts create mode 100644 apps/web/package.json create mode 100644 apps/web/postcss.config.mjs create mode 100644 apps/web/public/fonts/Inter-Bold.ttf create mode 100644 apps/web/tailwind.config.js create mode 100644 apps/web/tsconfig.json create mode 100644 apps/web/turbo.json create mode 100644 apps/web/wiring.fixture.json create mode 100644 apps/web/wrangler.jsonc create mode 100644 apps/web/wrangler.template.jsonc create mode 100644 infra/terraform/cloudflare-r2/component.yaml create mode 100644 infra/terraform/cloudflare-r2/docs/architecture.md create mode 100644 infra/terraform/cloudflare-r2/docs/overview.md create mode 100644 infra/terraform/cloudflare-r2/docs/runbook.md create mode 100644 infra/terraform/cloudflare-r2/terraform/adopt.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/backend.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/main.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/outputs.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/variables.tf create mode 100644 tests/web/component.yaml create mode 100644 tests/web/docs/architecture.md create mode 100644 tests/web/docs/overview.md create mode 100644 tests/web/docs/runbook.md create mode 100644 tests/web/eslint.config.js create mode 100644 tests/web/fake-sfcc.mjs create mode 100644 tests/web/package.json create mode 100644 tests/web/src/connection.test.ts create mode 100644 tests/web/src/fake.ts create mode 100644 tests/web/src/health.test.ts create mode 100644 tests/web/src/revalidate.test.ts create mode 100644 tests/web/src/site.test.ts create mode 100644 tests/web/src/utils.test.ts create mode 100644 tests/web/tsconfig.json create mode 100644 tests/web/vitest.config.ts create mode 100644 tooling/catalog/gen-component-docs.py diff --git a/README.md b/README.md index 5e23347..3770c6c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,111 @@ # sfcc-commerce -[Next.js Commerce for Salesforce Commerce Cloud](https://github.com/vercel-partner-solutions/nextjs-salesforce-commerce-cloud) on -**Cloudflare Workers**, deployed by [Orun](https://github.com/sourceplane/orun) to stage -and prod on every merge, and then packaged as an Orun baseline. - -This commit is the repository's frame: `intent.yaml` (with the placeholder -workspace `ws_CHANGE_ME`, so CI plans nothing until it is linked), the Orun -CI workflow, the shared TypeScript and ESLint configuration, and the spec -index. The work is tracked as an epic under [`specs/epics`](specs/epics/README.md). +Vercel's [Next.js Commerce for Salesforce Commerce Cloud](https://github.com/vercel-partner-solutions/nextjs-salesforce-commerce-cloud) +— Next.js Commerce on Salesforce B2C Commerce's Shopper APIs (SCAPI): a home +page with a featured grid and a carousel, the catalogue's categories with +sorting, search, product pages with variants and recommendations, a cart and +a guest checkout, every shopper a SLAS guest and every catalogue read a +`"use cache"` entry dropped by tag when the catalogue changes — running on +**Cloudflare Workers + Static Assets** through +[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), with the +Next.js data cache in an **R2 bucket** provisioned by Terraform through +[Orun](https://github.com/sourceplane/orun) and the tag cache and revalidation +queue in **Durable Objects** the Worker itself exports, deployed by +[Orun](https://github.com/sourceplane/orun) to stage and prod on every merge. +Packaging it as an Orun baseline is the next milestone (SX2). + +A fresh build needs no Salesforce store: until its owner connects one, `/` +says "Connect your Salesforce Commerce Cloud store" and every other page +answers with an empty catalogue and the same note — never a 500. The owner +connects a store by setting its SLAS client id, organization, short code and +site as Orun secrets (and a private client's secret) and redeploying. The +Worker is about 2.5 MiB gzipped (`next build --webpack`), inside Workers +Free's 3 MiB. See [`specs/epics/sfcc-commerce`](specs/epics/sfcc-commerce/README.md) +for the design, the milestones and the as-built status. + +## What is here (the product) + +| Surface | Where | +|---|---| +| The storefront's routes: `/`, `/search`, `/search/`, `/product/`, the content pages, `/checkout`, `/api/revalidate`, `/api/health`, the sitemap and the Open Graph images | `apps/web/app` | +| The store's name and its source link | `apps/web/app/site.ts` (`SITE_NAME`, `SOURCE_URL`) | +| Whether a Salesforce store is connected, and what the storefront says until one is | `apps/web/lib/sfcc/connection.ts`, `apps/web/components/connect-store.tsx` | +| The SCAPI client, the SLAS guest login, the cached reads and their tags, the cart and checkout, the revalidation route's logic | `apps/web/lib/sfcc` | +| Workers build, cache bindings and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ the committed `wrangler.jsonc`), `component.yaml` | +| The R2 bucket (stage, prod) | `infra/terraform/cloudflare-r2` | +| The wrangler renderer, and the step that puts `SFCC_SECRET` and the revalidation secret on the Worker | `tooling/wire` | +| Tests | `tests/web` (the port's seams: the store name, the connection and its guest logins, health, the URL helpers, revalidation) | + +## Getting started + +```bash +pnpm install +pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture +pnpm typecheck +pnpm lint +pnpm test +pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next +``` + +```bash +pnpm --filter @app/web dev # http://localhost:3000, Next's dev server +pnpm --filter @app/web preview # wrangler dev over the built Worker, a local R2 bucket and local Durable Objects +``` + +With no `SFCC_*` coordinates both serve the "connect your Salesforce Commerce +Cloud store" storefront. To run against a store, put its four coordinates in +`apps/web/.env.local` (from `apps/web/.env.example`, which lists Salesforce's +public demo instance). Offline, the e2e's stand-in SCAPI + SLAS answers the +storefront's calls from a three-product catalogue: +`node tests/web/fake-sfcc.mjs --port 4010 --client c --org o --site s`, then +`SFCC_CLIENT_ID=c SFCC_ORGANIZATIONID=o SFCC_SHORTCODE=x SFCC_SITEID=s +SFCC_API_ORIGIN=http://127.0.0.1:4010` (`SFCC_API_ORIGIN` is the test-only +override of `https://.api.commercecloud.salesforce.com`). + +## How it maps to Vercel + +| Vercel | Here | +|---|---| +| Next.js hosting (SSR, server actions, route handlers, `next/og`) | One Cloudflare Worker (`.open-next/worker.js`) + Static Assets (`ASSETS`) | +| Cache Components with `"use cache"`, `cacheLife` and `cacheTag` | `"use cache"`, its lifetimes and its tags kept through `experimental.useCache`; every route renders per request from those cached reads | +| Data Cache entries | The R2 bucket bound as `NEXT_INC_CACHE_R2_BUCKET` | +| `revalidateTag` | A sharded Durable Object tag cache (`NEXT_TAG_CACHE_DO_SHARDED`) consulted on every cache read | +| Stale-while-revalidate | A Durable Object queue (`NEXT_CACHE_DO_QUEUE`) that re-renders stale entries through the Worker's `WORKER_SELF_REFERENCE` binding | +| Image Optimization | Off (`images.unoptimized`): images come from the instance's image URLs | +| `SFCC_CLIENT_ID`, `SFCC_ORGANIZATIONID`, `SFCC_SHORTCODE`, `SFCC_SITEID` | Orun secrets (optional build env) — and, unset, the "connect your Salesforce Commerce Cloud store" storefront instead of a build that throws on every read | +| `SFCC_SECRET`, `SFCC_REVALIDATION_SECRET` | Orun secrets each deploy puts on the Worker; the build never sees them. Without the first the client is public (PKCE); without the second the route answers 503 | +| `VERCEL_PROJECT_PRODUCTION_URL` | Each environment's `SITE_URL`, else its workers.dev URL, set by the build as `NEXT_PUBLIC_SITE_URL` | +| Deploy on push | Orun applies the bucket and deploys `-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`) | +| "Deploy with Vercel" (clone the template) | `orun new --blueprint repo-blueprint.yaml` — a new repository, branded, deployed | + +Cache Components are off: `@opennextjs/cloudflare` 1.20 cannot run Next 16's +Cache Components on workerd yet (a Cache Components page answers 500 and then +hangs — opennextjs-cloudflare#1450), so the storefront keeps upstream's +`"use cache"` reads through `experimental.useCache` and renders every route at +request time. The epic's [IMPLEMENTATION-STATUS](specs/epics/sfcc-commerce/IMPLEMENTATION-STATUS.md) +has the evidence. + +## How the bucket reaches the Worker + +``` +infra/terraform/cloudflare-r2 ──apply (r2-data token)──► orun secret WIRING_CLOUDFLARE_R2 (stage, prod) + │ (each deploy resolves it as it starts; + │ a missing one fails the lane) + ▼ +apps/web dependsOn cloudflare-r2 (enforced on main) · secretEnv WIRING_CLOUDFLARE_R2_ + build: tooling/wire/live.mjs → wrangler.jsonc with the environment's bucket name + (dev, verify-only, renders the fixture) → next build → opennextjs-cloudflare + → tooling/wire/worker-secrets.mjs puts SFCC_SECRET, SFCC_REVALIDATION_SECRET on the Worker + deploy: workers-deploy token → -web-, its Durable Objects migrated on first deploy +``` + +`wrangler.jsonc` is committed as the fixture render of +`wrangler.template.jsonc`, because the deploy lane's `verify-app-structure` +step checks the config exists before it builds; `testing/e2e.test.sh` fails +if the two disagree. + +## CI + +| Workflow | What it runs | Ships to a product | +|---|---|---| +| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the R2 root planned for stage and prod, the storefront built and dry-deployed per environment; they neither lint nor run the tests, which `baseline.yml`'s e2e tier runs before every tag), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it (the landing checked its commit in the box); a merge applies the R2 bucket, then deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes | diff --git a/apps/web/.env.example b/apps/web/.env.example new file mode 100644 index 0000000..702aa3d --- /dev/null +++ b/apps/web/.env.example @@ -0,0 +1,21 @@ +# Local settings for `pnpm dev` (copy to .env.local) — a deployed storefront +# reads these from the environment's Orun secrets instead (component.yaml). +# +# The store: your SLAS client and site. Salesforce's public demo instance +# (the PWA Kit demo backend) works with these values and no secret: +# SFCC_CLIENT_ID=c9c45bfd-0ed3-4aa2-9971-40f88962b836 +# SFCC_ORGANIZATIONID=f_ecom_zzrf_001 +# SFCC_SHORTCODE=8o7m175y +# SFCC_SITEID=RefArchGlobal +# Left empty, the storefront renders and says how to connect a store. +SFCC_CLIENT_ID="" +SFCC_ORGANIZATIONID="" +SFCC_SHORTCODE="" +SFCC_SITEID="" +# A private SLAS client's secret; empty for a public client (PKCE guest login). +SFCC_SECRET="" +# The `?secret=` app/api/revalidate requires; empty turns revalidation off. +SFCC_REVALIDATION_SECRET="" +# The footer's copyright holder (defaults to the site's name). +COMPANY_NAME="" +NEXT_PUBLIC_SITE_URL="http://localhost:3000" diff --git a/apps/web/.gitignore b/apps/web/.gitignore new file mode 100644 index 0000000..74ceb62 --- /dev/null +++ b/apps/web/.gitignore @@ -0,0 +1,49 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage +.playwright + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env* +!.env.example + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts +.env*.local + +# editors +.cursor + +# Cloudflare Workers: OpenNext's build, wrangler's local state and secrets +/.open-next/ +/.wrangler/ +/.turbo/ +.dev.vars +.dev.vars.* diff --git a/apps/web/.prettierignore b/apps/web/.prettierignore new file mode 100644 index 0000000..ca73276 --- /dev/null +++ b/apps/web/.prettierignore @@ -0,0 +1,6 @@ +# Generated, with their generators' own layout: wrangler.jsonc is the +# template rendered (`pnpm run wire:fixture`), docs/ is the component's +# generated pages; both carry names a new product's rename makes longer. +wrangler.jsonc +wrangler.template.jsonc +docs/ diff --git a/apps/web/README.md b/apps/web/README.md new file mode 100644 index 0000000..b5d9685 --- /dev/null +++ b/apps/web/README.md @@ -0,0 +1,47 @@ +# apps/web — the storefront + +Vercel's Next.js Commerce for Salesforce Commerce Cloud (MIT, `license.md`) +on Cloudflare Workers + Static Assets: server components over Salesforce B2C +Commerce's Shopper APIs, every shopper a SLAS guest, a server-action cart and +checkout kept in your instance's basket, `"use cache"` reads revalidated by +tag. The upstream pages and components are kept; what this app adds is the +Workers build, the cache bindings, a storefront that says how to connect a +store while none is, a secret-checked revalidation route and `/api/health`. + +- `app/` — the routes: home, `/search`, `/search/`, + `/product/`, the content pages (`[page]`), `/checkout` (information, + shipping, payment) and `/checkout/confirmation`, the Open Graph images, + `robots.txt`, `sitemap.xml`, `/api/revalidate` and `/api/health` +- `app/site.ts` — the store's name and the repository its footer links to +- `lib/sfcc/` — the SCAPI client (`commerce-sdk-isomorphic`), the SLAS guest + login (a public client's PKCE flow, or a private client's secret), the + cached readers and their tags, the cart and checkout calls, the reshaping + to the page's types, and the revalidation route's logic; `connection.ts` + says whether a store is connected, and while none is every reader answers + empty without a call +- `components/` — cart (server actions, modal), checkout forms, navbar, + grid, carousel, product gallery and variants, the connect-store note + +```bash +pnpm dev # next dev on http://localhost:3000 +pnpm build # next build --webpack + opennextjs-cloudflare build → .open-next/ +pnpm test # upstream's check: the prettier format check +pnpm preview # wrangler dev over the built Worker: a local R2 bucket, local Durable Objects +``` + +The cache's bucket is not hand-written. `wrangler.template.jsonc` names it as +a wiring token; `wrangler.jsonc` is that template rendered from +`wiring.fixture.json` (placeholder names, for local work and verification), +and every deploy renders it again from the name the `cloudflare-r2` Terraform +root published for the environment (`component.yaml`'s `buildCommand`). + +## Store backend + +| The four `SFCC_*` coordinates | catalogue | cart and checkout | +| ----------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------ | +| unset (a fresh deploy) | empty; `/` says "Connect your Salesforce Commerce Cloud store" and every page carries the note | none | +| set (read by the build) | the Shopper APIs, cached in R2 (`"use cache"`), revalidated through `/api/revalidate` | the instance's own basket and order, per shopper | + +Connecting a store is four Orun secrets and a redeploy (five for a private +SLAS client), and revalidation one more — the repository's README, +"Connecting Salesforce Commerce Cloud". diff --git a/apps/web/app/[page]/layout.tsx b/apps/web/app/[page]/layout.tsx new file mode 100644 index 0000000..d76dedd --- /dev/null +++ b/apps/web/app/[page]/layout.tsx @@ -0,0 +1,12 @@ +import Footer from "components/layout/footer"; + +export default function Layout({ children }: { children: React.ReactNode }) { + return ( + <> +
+
{children}
+
+