@spree/docs 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.
- package/README.md +54 -0
- package/dist/api-reference/platform/authentication.md +38 -0
- package/dist/api-reference/store-api/authentication.md +188 -0
- package/dist/api-reference/store-api/errors.md +277 -0
- package/dist/api-reference/store-api/idempotency.md +129 -0
- package/dist/api-reference/store-api/introduction.md +34 -0
- package/dist/api-reference/store-api/localization.md +279 -0
- package/dist/api-reference/store-api/metadata.md +160 -0
- package/dist/api-reference/store-api/monetary-amounts.md +65 -0
- package/dist/api-reference/store-api/querying.md +399 -0
- package/dist/api-reference/store-api/rate-limitting.md +103 -0
- package/dist/api-reference/store-api/relations.md +185 -0
- package/dist/api-reference/storefront/authentication.md +88 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +165 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +194 -0
- package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +248 -0
- package/dist/api-reference/v2/fetching-multiple-resources.md +26 -0
- package/dist/api-reference/v2/filtering-and-sorting.md +53 -0
- package/dist/api-reference/v2/introduction.md +22 -0
- package/dist/api-reference/v2/pagination.md +37 -0
- package/dist/api-reference/webhooks-events.md +883 -0
- package/dist/developer/admin/admin.md +205 -0
- package/dist/developer/admin/authentication.md +59 -0
- package/dist/developer/admin/components.md +711 -0
- package/dist/developer/admin/custom-css.md +243 -0
- package/dist/developer/admin/custom-javascript.md +116 -0
- package/dist/developer/admin/extending-ui.md +1964 -0
- package/dist/developer/admin/form-builder.md +444 -0
- package/dist/developer/admin/helper-methods.md +531 -0
- package/dist/developer/admin/navigation.md +805 -0
- package/dist/developer/admin/tables.md +491 -0
- package/dist/developer/advanced/adding_spree_to_rails_app.md +106 -0
- package/dist/developer/cli/quickstart.md +137 -0
- package/dist/developer/contributing/creating-an-extension.md +258 -0
- package/dist/developer/contributing/developing-spree.md +339 -0
- package/dist/developer/contributing/quickstart.md +32 -0
- package/dist/developer/contributing/updating-extensions.md +67 -0
- package/dist/developer/core-concepts/addresses.md +265 -0
- package/dist/developer/core-concepts/adjustments.md +107 -0
- package/dist/developer/core-concepts/architecture.md +177 -0
- package/dist/developer/core-concepts/calculators.md +323 -0
- package/dist/developer/core-concepts/customers.md +230 -0
- package/dist/developer/core-concepts/events.md +624 -0
- package/dist/developer/core-concepts/imports-exports.md +698 -0
- package/dist/developer/core-concepts/inventory.md +191 -0
- package/dist/developer/core-concepts/markets.md +250 -0
- package/dist/developer/core-concepts/media.md +167 -0
- package/dist/developer/core-concepts/metafields.md +187 -0
- package/dist/developer/core-concepts/orders.md +328 -0
- package/dist/developer/core-concepts/payments.md +710 -0
- package/dist/developer/core-concepts/pricing.md +163 -0
- package/dist/developer/core-concepts/products.md +360 -0
- package/dist/developer/core-concepts/promotions.md +322 -0
- package/dist/developer/core-concepts/reports.md +206 -0
- package/dist/developer/core-concepts/search-filtering.md +237 -0
- package/dist/developer/core-concepts/shipments.md +212 -0
- package/dist/developer/core-concepts/slugs.md +111 -0
- package/dist/developer/core-concepts/staff-roles.md +123 -0
- package/dist/developer/core-concepts/store-credits-gift-cards.md +317 -0
- package/dist/developer/core-concepts/stores.md +117 -0
- package/dist/developer/core-concepts/taxes.md +135 -0
- package/dist/developer/core-concepts/translations.md +120 -0
- package/dist/developer/core-concepts/users.md +299 -0
- package/dist/developer/core-concepts/webhooks.md +378 -0
- package/dist/developer/create-spree-app/quickstart.md +158 -0
- package/dist/developer/customization/api.md +93 -0
- package/dist/developer/customization/authentication.md +88 -0
- package/dist/developer/customization/checkout.md +204 -0
- package/dist/developer/customization/configuration.md +55 -0
- package/dist/developer/customization/decorators.md +523 -0
- package/dist/developer/customization/dependencies.md +232 -0
- package/dist/developer/customization/emails.md +21 -0
- package/dist/developer/customization/extensions.md +92 -0
- package/dist/developer/customization/metadata.md +236 -0
- package/dist/developer/customization/model-preferences.md +130 -0
- package/dist/developer/customization/permissions.md +265 -0
- package/dist/developer/customization/quickstart.md +229 -0
- package/dist/developer/customization/routes.md +24 -0
- package/dist/developer/customization/v4/admin-panel.md +78 -0
- package/dist/developer/customization/v4/authentication.md +210 -0
- package/dist/developer/customization/v4/checkout.md +212 -0
- package/dist/developer/customization/v4/deface.md +251 -0
- package/dist/developer/customization/v4/images.md +86 -0
- package/dist/developer/customization/v4/storefront.md +450 -0
- package/dist/developer/deployment/assets.md +87 -0
- package/dist/developer/deployment/aws.md +335 -0
- package/dist/developer/deployment/caching.md +27 -0
- package/dist/developer/deployment/cdn.md +39 -0
- package/dist/developer/deployment/database.md +155 -0
- package/dist/developer/deployment/docker.md +128 -0
- package/dist/developer/deployment/emails.md +77 -0
- package/dist/developer/deployment/environment_variables.md +111 -0
- package/dist/developer/deployment/heroku.md +51 -0
- package/dist/developer/deployment/render.md +95 -0
- package/dist/developer/getting-started/quickstart.md +82 -0
- package/dist/developer/how-to/custom-payment-method.md +374 -0
- package/dist/developer/how-to/custom-promotion.md +373 -0
- package/dist/developer/how-to/custom-report.md +387 -0
- package/dist/developer/how-to/custom-search-provider.md +230 -0
- package/dist/developer/multi-store/quickstart.md +71 -0
- package/dist/developer/multi-store/setup.md +38 -0
- package/dist/developer/multi-tenant/configuration.md +41 -0
- package/dist/developer/multi-tenant/core-concepts.md +75 -0
- package/dist/developer/multi-tenant/installation.md +96 -0
- package/dist/developer/multi-tenant/quickstart.md +20 -0
- package/dist/developer/multi-vendor/installation.md +45 -0
- package/dist/developer/multi-vendor/quickstart.md +17 -0
- package/dist/developer/sdk/admin/quickstart.md +22 -0
- package/dist/developer/sdk/authentication.md +89 -0
- package/dist/developer/sdk/configuration.md +225 -0
- package/dist/developer/sdk/quickstart.md +82 -0
- package/dist/developer/sdk/store/account.md +67 -0
- package/dist/developer/sdk/store/cart-checkout.md +140 -0
- package/dist/developer/sdk/store/markets.md +151 -0
- package/dist/developer/sdk/store/payments.md +96 -0
- package/dist/developer/sdk/store/products.md +149 -0
- package/dist/developer/sdk/store/wishlists.md +52 -0
- package/dist/developer/security/pci_compliance.md +15 -0
- package/dist/developer/security/security_policy.md +68 -0
- package/dist/developer/storefront/blocks.md +285 -0
- package/dist/developer/storefront/custom-css.md +260 -0
- package/dist/developer/storefront/custom-javascript.md +166 -0
- package/dist/developer/storefront/helper-methods.md +1288 -0
- package/dist/developer/storefront/links.md +298 -0
- package/dist/developer/storefront/nextjs/architecture.md +150 -0
- package/dist/developer/storefront/nextjs/customization.md +141 -0
- package/dist/developer/storefront/nextjs/deployment.md +180 -0
- package/dist/developer/storefront/nextjs/quickstart.md +92 -0
- package/dist/developer/storefront/nextjs/spree-next-package.md +314 -0
- package/dist/developer/storefront/pages.md +163 -0
- package/dist/developer/storefront/sections.md +569 -0
- package/dist/developer/storefront/storefront.md +56 -0
- package/dist/developer/storefront/themes.md +161 -0
- package/dist/developer/tutorial/admin.md +134 -0
- package/dist/developer/tutorial/extending-models.md +380 -0
- package/dist/developer/tutorial/file-uploads.md +121 -0
- package/dist/developer/tutorial/introduction.md +33 -0
- package/dist/developer/tutorial/model.md +41 -0
- package/dist/developer/tutorial/page-builder.md +487 -0
- package/dist/developer/tutorial/rich-text.md +73 -0
- package/dist/developer/tutorial/seo.md +332 -0
- package/dist/developer/tutorial/storefront.md +352 -0
- package/dist/developer/tutorial/testing.md +558 -0
- package/dist/developer/upgrades/2.0-to-2.1.md +46 -0
- package/dist/developer/upgrades/2.1-to-2.2.md +59 -0
- package/dist/developer/upgrades/2.2-to-2.3.md +44 -0
- package/dist/developer/upgrades/2.3-to-2.4.md +42 -0
- package/dist/developer/upgrades/3.0-to-3.1.md +47 -0
- package/dist/developer/upgrades/3.1-to-3.2.md +34 -0
- package/dist/developer/upgrades/3.2-to-3.3.md +70 -0
- package/dist/developer/upgrades/3.3-to-3.4.md +36 -0
- package/dist/developer/upgrades/3.4-to-3.5.md +44 -0
- package/dist/developer/upgrades/3.5-to-3.6.md +40 -0
- package/dist/developer/upgrades/3.6-to-3.7.md +62 -0
- package/dist/developer/upgrades/3.7-to-4.0.md +152 -0
- package/dist/developer/upgrades/4.0-to-4.1.md +92 -0
- package/dist/developer/upgrades/4.1-to-4.2.md +109 -0
- package/dist/developer/upgrades/4.10-to-5.0.md +129 -0
- package/dist/developer/upgrades/4.2-to-4.3.md +100 -0
- package/dist/developer/upgrades/4.3-to-4.4.md +125 -0
- package/dist/developer/upgrades/4.4-to-4.5.md +94 -0
- package/dist/developer/upgrades/4.5-to-4.6.md +119 -0
- package/dist/developer/upgrades/4.6-to-4.7.md +39 -0
- package/dist/developer/upgrades/4.8-to-4.9.md +24 -0
- package/dist/developer/upgrades/4.9-to-4.10.md +24 -0
- package/dist/developer/upgrades/4.x-to-4.8.md +52 -0
- package/dist/developer/upgrades/5.0-to-5.1.md +28 -0
- package/dist/developer/upgrades/5.1-to-5.2.md +127 -0
- package/dist/developer/upgrades/5.2-to-5.3.md +338 -0
- package/dist/developer/upgrades/5.3-to-5.4.md +248 -0
- package/dist/developer/upgrades/quickstart.md +36 -0
- package/dist/integrations/analytics/google-analytics.md +64 -0
- package/dist/integrations/analytics/google-tag-manager.md +78 -0
- package/dist/integrations/integrations.md +39 -0
- package/dist/integrations/marketing/klaviyo.md +99 -0
- package/dist/integrations/payments/adyen.md +90 -0
- package/dist/integrations/payments/paypal.md +41 -0
- package/dist/integrations/payments/razorpay.md +45 -0
- package/dist/integrations/payments/stripe.md +109 -0
- package/dist/integrations/search/meilisearch.md +236 -0
- package/dist/integrations/sso-mfa-social-login/admin-dashboard.md +57 -0
- package/dist/integrations/sso-mfa-social-login/storefront.md +56 -0
- package/package.json +27 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Deployment
|
|
3
|
+
description: Deploy the Spree Next.js Storefront to Vercel, Docker, or any Node.js host
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Environment Variables
|
|
7
|
+
|
|
8
|
+
Set these variables in your hosting platform's dashboard or `.env` file.
|
|
9
|
+
|
|
10
|
+
### Required
|
|
11
|
+
|
|
12
|
+
| Variable | Description |
|
|
13
|
+
|----------|-------------|
|
|
14
|
+
| `SPREE_API_URL` | Your Spree API endpoint (e.g., `https://api.mystore.com`) |
|
|
15
|
+
| `SPREE_PUBLISHABLE_KEY` | Publishable API key from your Spree admin |
|
|
16
|
+
|
|
17
|
+
> **NOTE:** These are server-side only variables — no `NEXT_PUBLIC_` prefix needed since all API calls happen in Server Actions.
|
|
18
|
+
|
|
19
|
+
### Optional
|
|
20
|
+
|
|
21
|
+
| Variable | Description | Default |
|
|
22
|
+
|----------|-------------|---------|
|
|
23
|
+
| `GTM_ID` | Google Tag Manager container ID | _(disabled)_ |
|
|
24
|
+
| `SENTRY_DSN` | Sentry DSN for error tracking | _(disabled)_ |
|
|
25
|
+
| `SENTRY_ORG` | Sentry organization slug | _(none)_ |
|
|
26
|
+
| `SENTRY_PROJECT` | Sentry project slug | _(none)_ |
|
|
27
|
+
| `SENTRY_AUTH_TOKEN` | Sentry auth token (for source maps in CI) | _(none)_ |
|
|
28
|
+
|
|
29
|
+
## Production Build
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run build
|
|
33
|
+
npm start
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The build output is a standalone Next.js application. The `npm start` command starts the production server.
|
|
37
|
+
|
|
38
|
+
## Vercel
|
|
39
|
+
|
|
40
|
+
Vercel is the recommended deployment platform for Next.js applications.
|
|
41
|
+
|
|
42
|
+
### One-Click Deploy
|
|
43
|
+
|
|
44
|
+
1. Push your code to GitHub
|
|
45
|
+
2. Go to [vercel.com/new](https://vercel.com/new) and import your repository
|
|
46
|
+
3. Add environment variables (`SPREE_API_URL`, `SPREE_PUBLISHABLE_KEY`)
|
|
47
|
+
4. Click **Deploy**
|
|
48
|
+
|
|
49
|
+
Vercel automatically detects the Next.js framework and configures the build settings.
|
|
50
|
+
|
|
51
|
+
### Vercel CLI
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm i -g vercel
|
|
55
|
+
vercel
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Preview Deployments
|
|
59
|
+
|
|
60
|
+
Every pull request gets a unique preview URL, making it easy to test storefront changes before merging. Add your Spree API environment variables to the Vercel project settings so previews connect to your staging API.
|
|
61
|
+
|
|
62
|
+
## Docker
|
|
63
|
+
|
|
64
|
+
Create a `Dockerfile` in your project root:
|
|
65
|
+
|
|
66
|
+
```dockerfile
|
|
67
|
+
FROM node:20-alpine AS base
|
|
68
|
+
|
|
69
|
+
FROM base AS deps
|
|
70
|
+
WORKDIR /app
|
|
71
|
+
COPY package.json package-lock.json ./
|
|
72
|
+
RUN npm ci --production=false
|
|
73
|
+
|
|
74
|
+
FROM base AS builder
|
|
75
|
+
WORKDIR /app
|
|
76
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
77
|
+
COPY . .
|
|
78
|
+
RUN npm run build
|
|
79
|
+
|
|
80
|
+
FROM base AS runner
|
|
81
|
+
WORKDIR /app
|
|
82
|
+
ENV NODE_ENV=production
|
|
83
|
+
|
|
84
|
+
RUN addgroup --system --gid 1001 nodejs
|
|
85
|
+
RUN adduser --system --uid 1001 nextjs
|
|
86
|
+
|
|
87
|
+
COPY --from=builder /app/public ./public
|
|
88
|
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
89
|
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
90
|
+
|
|
91
|
+
USER nextjs
|
|
92
|
+
EXPOSE 3000
|
|
93
|
+
ENV PORT=3000
|
|
94
|
+
ENV HOSTNAME="0.0.0.0"
|
|
95
|
+
|
|
96
|
+
CMD ["node", "server.js"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> **NOTE:** Enable standalone output in your `next.config.ts` for Docker deployments:
|
|
100
|
+
>
|
|
101
|
+
> ```typescript
|
|
102
|
+
const nextConfig = {
|
|
103
|
+
output: 'standalone',
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Build and run:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
docker build -t spree-storefront .
|
|
111
|
+
docker run -p 3000:3000 \
|
|
112
|
+
-e SPREE_API_URL=https://api.mystore.com \
|
|
113
|
+
-e SPREE_PUBLISHABLE_KEY=your_key \
|
|
114
|
+
spree-storefront
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Self-Hosted Node.js
|
|
118
|
+
|
|
119
|
+
For any platform that supports Node.js (Render, Railway, Fly.io, AWS, etc.):
|
|
120
|
+
|
|
121
|
+
1. Install dependencies and build:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm ci
|
|
125
|
+
npm run build
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
2. Start the production server:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm start
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The server listens on port `3000` by default. Set the `PORT` environment variable to change it.
|
|
135
|
+
|
|
136
|
+
## CI/CD
|
|
137
|
+
|
|
138
|
+
### GitHub Actions
|
|
139
|
+
|
|
140
|
+
```yaml
|
|
141
|
+
name: Deploy Storefront
|
|
142
|
+
on:
|
|
143
|
+
push:
|
|
144
|
+
branches: [main]
|
|
145
|
+
|
|
146
|
+
jobs:
|
|
147
|
+
deploy:
|
|
148
|
+
runs-on: ubuntu-latest
|
|
149
|
+
steps:
|
|
150
|
+
- uses: actions/checkout@v4
|
|
151
|
+
|
|
152
|
+
- uses: actions/setup-node@v4
|
|
153
|
+
with:
|
|
154
|
+
node-version: 20
|
|
155
|
+
cache: npm
|
|
156
|
+
|
|
157
|
+
- run: npm ci
|
|
158
|
+
- run: npm run build
|
|
159
|
+
|
|
160
|
+
# Add your deployment step here
|
|
161
|
+
# Example for Vercel:
|
|
162
|
+
# - uses: amondnet/vercel-action@v25
|
|
163
|
+
# with:
|
|
164
|
+
# vercel-token: ${{ secrets.VERCEL_TOKEN }}
|
|
165
|
+
# vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
|
|
166
|
+
# vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
167
|
+
# vercel-args: --prod
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Performance Checklist
|
|
171
|
+
|
|
172
|
+
Before going to production, verify:
|
|
173
|
+
|
|
174
|
+
- **API URL** points to your production Spree instance (not `localhost`)
|
|
175
|
+
- **HTTPS** is enabled on both the storefront and the Spree API
|
|
176
|
+
- **CORS** is configured on your Spree API to allow requests from your storefront domain
|
|
177
|
+
- **Sentry** is configured for error monitoring (`SENTRY_DSN`)
|
|
178
|
+
- **GTM/GA4** is set up for analytics (`GTM_ID`)
|
|
179
|
+
- **Cookie security** — the storefront uses `secure: true` for cookies in production (`NODE_ENV=production`)
|
|
180
|
+
- **Caching** — Next.js cache tags are used for efficient revalidation; review your caching strategy for high-traffic stores
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Quickstart
|
|
3
|
+
description: Get started with the Spree Next.js Storefront
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The [Spree Storefront](https://github.com/spree/storefront) is a production-ready, headless e-commerce storefront built with Next.js 16, React 19, and the Spree Commerce API v3.
|
|
7
|
+
|
|
8
|
+
## Tech Stack
|
|
9
|
+
|
|
10
|
+
- **Next.js 16** - App Router, Server Actions, Turbopack
|
|
11
|
+
- **React 19** - Server Components
|
|
12
|
+
- **Tailwind CSS 4** - Utility-first styling
|
|
13
|
+
- **TypeScript 5** - Full type safety
|
|
14
|
+
- **[@spree/sdk](https://github.com/spree/spree/tree/main/packages/sdk)** - Official Spree Commerce SDK
|
|
15
|
+
- **[@spree/next](https://github.com/spree/spree/tree/main/packages/next)** - Server actions, caching, and cookie-based auth
|
|
16
|
+
- **Sentry** - Error tracking and performance monitoring
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Server-First Architecture** - All API calls happen server-side, API keys never exposed to the browser
|
|
21
|
+
- **Secure Authentication** - JWT tokens stored in httpOnly cookies
|
|
22
|
+
- **Product Catalog** - Browse, search, and filter with faceted navigation
|
|
23
|
+
- **Shopping Cart** - Server-side state management
|
|
24
|
+
- **Multi-Step Checkout** - Guest and signed-in users, multi-fulfillment, coupon codes, gift cards, store credit
|
|
25
|
+
- **Stripe Payments** - Credit Cards, Apple Pay, Google Pay, Klarna, Affirm, SEPA and more via [Spree Stripe](https://github.com/spree/spree_stripe)
|
|
26
|
+
- **Google Tag Manager** and **GA4 Ecommerce** event tracking
|
|
27
|
+
- **Customer Account** - Profile, order history, address book, gift cards, saved payment methods
|
|
28
|
+
- **Multi-Region** - Country and currency switching via URL segments
|
|
29
|
+
- **Responsive Design** - Mobile-first Tailwind CSS
|
|
30
|
+
|
|
31
|
+
## Prerequisites
|
|
32
|
+
|
|
33
|
+
- Node.js 20+
|
|
34
|
+
- A running Spree Commerce 5.4+ instance
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
### Option 1: Fork the Repository (Recommended)
|
|
39
|
+
|
|
40
|
+
Fork the repository on GitHub, then clone your fork:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/YOUR_USERNAME/storefront.git
|
|
44
|
+
cd storefront
|
|
45
|
+
npm install
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This gives you a full copy you can customize freely while still being able to pull upstream updates.
|
|
49
|
+
|
|
50
|
+
### Option 2: Clone Directly
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/spree/storefront.git
|
|
54
|
+
cd storefront
|
|
55
|
+
npm install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
Copy the environment file:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
cp .env.local.example .env.local
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Update `.env.local` with your Spree API credentials:
|
|
67
|
+
|
|
68
|
+
```env
|
|
69
|
+
SPREE_API_URL=http://localhost:3000
|
|
70
|
+
SPREE_PUBLISHABLE_KEY=your_publishable_api_key_here
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> **NOTE:** These are server-side only variables — no `NEXT_PUBLIC_` prefix needed since all API calls happen in Server Actions.
|
|
74
|
+
|
|
75
|
+
See [Deployment](/developer/storefront/nextjs/deployment) for all optional environment variables (Sentry, GTM, etc.).
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm run dev
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Open [http://localhost:3001](http://localhost:3001) in your browser.
|
|
84
|
+
|
|
85
|
+
## Production Build
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run build
|
|
89
|
+
npm start
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See the [Deployment](/developer/storefront/nextjs/deployment) guide for Vercel, Docker, and other hosting options.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "@spree/next Package"
|
|
3
|
+
description: Next.js integration library — server actions, caching, and cookie-based auth
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The `@spree/next` package provides a complete Next.js integration for Spree Commerce with server actions, automatic cookie management, and full TypeScript support.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @spree/next @spree/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
### Auto-initialization
|
|
17
|
+
|
|
18
|
+
Set environment variables and the client initializes automatically:
|
|
19
|
+
|
|
20
|
+
```env
|
|
21
|
+
SPREE_API_URL=https://api.mystore.com
|
|
22
|
+
SPREE_PUBLISHABLE_KEY=spree_pk_xxx
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Explicit initialization
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// lib/storefront.ts
|
|
29
|
+
import { initSpreeNext } from '@spree/next';
|
|
30
|
+
|
|
31
|
+
initSpreeNext({
|
|
32
|
+
baseUrl: process.env.SPREE_API_URL!,
|
|
33
|
+
publishableKey: process.env.SPREE_PUBLISHABLE_KEY!,
|
|
34
|
+
cartCookieName: '_spree_cart_token', // default
|
|
35
|
+
accessTokenCookieName: '_spree_jwt', // default
|
|
36
|
+
defaultLocale: 'en',
|
|
37
|
+
defaultCurrency: 'USD',
|
|
38
|
+
defaultCountry: 'US',
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Data Functions
|
|
43
|
+
|
|
44
|
+
Plain async functions for reading data in Server Components. Wrap with `"use cache"` in your app for caching.
|
|
45
|
+
|
|
46
|
+
### Products
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { listProducts, getProduct, getProductFilters } from '@spree/next';
|
|
50
|
+
|
|
51
|
+
const products = await listProducts({ limit: 25 });
|
|
52
|
+
const product = await getProduct('spree-tote', { expand: ['variants', 'media'] });
|
|
53
|
+
const filters = await getProductFilters({ category_id: 'ctg_123' });
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Categories
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { listCategories, getCategory, listCategoryProducts } from '@spree/next';
|
|
60
|
+
|
|
61
|
+
const categories = await listCategories({ depth_eq: 1 });
|
|
62
|
+
const category = await getCategory('clothing/shirts');
|
|
63
|
+
const products = await listCategoryProducts('clothing/shirts', { limit: 12 });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Store & Geography
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { getStore, listCountries, getCountry, listCurrencies, listLocales } from '@spree/next';
|
|
70
|
+
|
|
71
|
+
const store = await getStore();
|
|
72
|
+
const countries = await listCountries();
|
|
73
|
+
const usa = await getCountry('US');
|
|
74
|
+
const currencies = await listCurrencies();
|
|
75
|
+
const locales = await listLocales();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Using in Server Components
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { listProducts, listCategories } from '@spree/next';
|
|
82
|
+
|
|
83
|
+
export default async function ProductsPage() {
|
|
84
|
+
const products = await listProducts({ limit: 12 });
|
|
85
|
+
const categories = await listCategories({ depth_eq: 1 });
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
{products.data.map((product) => (
|
|
90
|
+
<div key={product.id}>{product.name}</div>
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Server Actions
|
|
98
|
+
|
|
99
|
+
Server actions handle mutations and auth-dependent reads. They automatically manage cookies for cart tokens and JWT authentication.
|
|
100
|
+
|
|
101
|
+
### Cart
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { getCart, getOrCreateCart, addItem, updateItem, removeItem, clearCart, associateCart } from '@spree/next';
|
|
105
|
+
|
|
106
|
+
const cart = await getCart(); // null if no cart
|
|
107
|
+
const cart = await getOrCreateCart(); // creates if needed
|
|
108
|
+
await addItem(variantId, quantity);
|
|
109
|
+
await updateItem(lineItemId, { quantity: 2 });
|
|
110
|
+
await removeItem(lineItemId);
|
|
111
|
+
await clearCart();
|
|
112
|
+
await associateCart(); // link guest cart to logged-in user
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Checkout
|
|
116
|
+
|
|
117
|
+
Checkout functions use the implicit cart resolved from cookies. No `orderId` is needed.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import {
|
|
121
|
+
getCheckout,
|
|
122
|
+
updateCheckout,
|
|
123
|
+
getFulfillments,
|
|
124
|
+
selectDeliveryRate,
|
|
125
|
+
applyCoupon,
|
|
126
|
+
removeCoupon,
|
|
127
|
+
complete,
|
|
128
|
+
} from '@spree/next';
|
|
129
|
+
|
|
130
|
+
const checkout = await getCheckout();
|
|
131
|
+
await updateCheckout({ shipping_address: { ... }, billing_address: { ... } });
|
|
132
|
+
const fulfillments = await getFulfillments();
|
|
133
|
+
await selectDeliveryRate(fulfillmentId, deliveryRateId);
|
|
134
|
+
await applyCoupon('SAVE20');
|
|
135
|
+
await removeCoupon(promotionId);
|
|
136
|
+
await complete();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Authentication
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { login, register, logout, getCustomer, updateCustomer } from '@spree/next';
|
|
143
|
+
|
|
144
|
+
await login(email, password);
|
|
145
|
+
await register(email, password, passwordConfirmation);
|
|
146
|
+
await logout();
|
|
147
|
+
const customer = await getCustomer(); // null if not logged in
|
|
148
|
+
await updateCustomer({ first_name: 'John' });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Addresses
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { listAddresses, getAddress, createAddress, updateAddress, deleteAddress } from '@spree/next';
|
|
155
|
+
|
|
156
|
+
const addresses = await listAddresses();
|
|
157
|
+
const address = await getAddress(addressId);
|
|
158
|
+
await createAddress({ first_name: 'John', address1: '123 Main St', ... });
|
|
159
|
+
await updateAddress(addressId, { city: 'Brooklyn' });
|
|
160
|
+
await deleteAddress(addressId);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Orders
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { listOrders, getOrder } from '@spree/next';
|
|
167
|
+
|
|
168
|
+
const orders = await listOrders();
|
|
169
|
+
const order = await getOrder(orderId);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Payment Sessions
|
|
173
|
+
|
|
174
|
+
Payment session functions use the implicit cart. No `orderId` is needed.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import {
|
|
178
|
+
createPaymentSession,
|
|
179
|
+
getPaymentSession,
|
|
180
|
+
updatePaymentSession,
|
|
181
|
+
completePaymentSession,
|
|
182
|
+
} from '@spree/next';
|
|
183
|
+
|
|
184
|
+
const session = await createPaymentSession({ payment_method_id: 'pm_123' });
|
|
185
|
+
|
|
186
|
+
// Access provider data (e.g., Stripe client secret)
|
|
187
|
+
const clientSecret = session.external_data.client_secret;
|
|
188
|
+
|
|
189
|
+
const current = await getPaymentSession(sessionId);
|
|
190
|
+
await updatePaymentSession(sessionId, { amount: '50.00' });
|
|
191
|
+
await completePaymentSession(sessionId, { session_result: 'success' });
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Payment Setup Sessions
|
|
195
|
+
|
|
196
|
+
For saving payment methods outside of checkout (e.g., "Add a credit card" in account settings):
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {
|
|
200
|
+
createPaymentSetupSession,
|
|
201
|
+
getPaymentSetupSession,
|
|
202
|
+
completePaymentSetupSession,
|
|
203
|
+
} from '@spree/next';
|
|
204
|
+
|
|
205
|
+
const session = await createPaymentSetupSession({ payment_method_id: 'pm_123' });
|
|
206
|
+
const current = await getPaymentSetupSession(sessionId);
|
|
207
|
+
await completePaymentSetupSession(sessionId, { session_result: 'success' });
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Credit Cards & Gift Cards
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { listCreditCards, deleteCreditCard } from '@spree/next';
|
|
214
|
+
import { listGiftCards, getGiftCard } from '@spree/next';
|
|
215
|
+
|
|
216
|
+
const cards = await listCreditCards();
|
|
217
|
+
await deleteCreditCard(cardId);
|
|
218
|
+
|
|
219
|
+
const giftCards = await listGiftCards();
|
|
220
|
+
const giftCard = await getGiftCard(giftCardId);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Using Server Actions in Forms
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { addItem, getCart } from '@spree/next';
|
|
227
|
+
|
|
228
|
+
export default async function CartPage() {
|
|
229
|
+
const cart = await getCart();
|
|
230
|
+
|
|
231
|
+
async function handleAddItem(formData: FormData) {
|
|
232
|
+
'use server';
|
|
233
|
+
await addItem(formData.get('variantId') as string, 1);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return <form action={handleAddItem}>...</form>;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Localization
|
|
241
|
+
|
|
242
|
+
### Automatic (recommended)
|
|
243
|
+
|
|
244
|
+
Data functions automatically read locale and country from cookies. Use the included middleware to set cookies based on the URL:
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// middleware.ts
|
|
248
|
+
import { createSpreeMiddleware } from '@spree/next/middleware';
|
|
249
|
+
|
|
250
|
+
export default createSpreeMiddleware({
|
|
251
|
+
defaultCountry: 'us',
|
|
252
|
+
defaultLocale: 'en',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export const config = {
|
|
256
|
+
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\..*$).*)'],
|
|
257
|
+
};
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Then data functions work without any locale arguments:
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
// Locale/country auto-read from cookies — no options needed
|
|
264
|
+
const products = await listProducts({ limit: 10 });
|
|
265
|
+
const category = await getCategory('clothing/shirts');
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Use the `setLocale` server action in country/language switchers:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { setLocale } from '@spree/next';
|
|
272
|
+
|
|
273
|
+
await setLocale({ country: 'de', locale: 'de' });
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Manual override
|
|
277
|
+
|
|
278
|
+
You can still pass locale options explicitly — they override the auto-detected values:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const products = await listProducts({ limit: 10 }, { locale: 'fr', country: 'FR' });
|
|
282
|
+
const category = await getCategory('clothing/shirts', {}, { locale: 'de', country: 'DE' });
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## TypeScript
|
|
286
|
+
|
|
287
|
+
All types are re-exported from `@spree/sdk`:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import type {
|
|
291
|
+
Product,
|
|
292
|
+
Order,
|
|
293
|
+
LineItem,
|
|
294
|
+
Variant,
|
|
295
|
+
Category,
|
|
296
|
+
Country,
|
|
297
|
+
Currency,
|
|
298
|
+
Locale,
|
|
299
|
+
Address,
|
|
300
|
+
Customer,
|
|
301
|
+
CreditCard,
|
|
302
|
+
GiftCard,
|
|
303
|
+
Fulfillment,
|
|
304
|
+
DeliveryRate,
|
|
305
|
+
Payment,
|
|
306
|
+
PaymentMethod,
|
|
307
|
+
PaymentSession,
|
|
308
|
+
PaymentSetupSession,
|
|
309
|
+
PaginatedResponse,
|
|
310
|
+
ProductFiltersResponse,
|
|
311
|
+
AddressParams,
|
|
312
|
+
SpreeError,
|
|
313
|
+
} from '@spree/next';
|
|
314
|
+
```
|