@spree/next 0.1.1 → 0.1.2
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 +261 -0
- package/dist/actions/auth.d.ts +3 -3
- package/dist/actions/auth.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +17 -16
- package/LICENSE +0 -58
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# @spree/next
|
|
2
|
+
|
|
3
|
+
Next.js integration for Spree Commerce — server actions, caching, and cookie-based auth.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @spree/next @spree/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @spree/next @spree/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @spree/next @spree/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Set environment variables
|
|
18
|
+
|
|
19
|
+
```env
|
|
20
|
+
SPREE_API_URL=https://api.mystore.com
|
|
21
|
+
SPREE_API_KEY=your-publishable-api-key
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The client auto-initializes from these env vars. Alternatively, initialize explicitly:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// lib/storefront.ts
|
|
28
|
+
import { initSpreeNext } from '@spree/next';
|
|
29
|
+
|
|
30
|
+
initSpreeNext({
|
|
31
|
+
baseUrl: process.env.SPREE_API_URL!,
|
|
32
|
+
apiKey: process.env.SPREE_API_KEY!,
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Fetch data in Server Components
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { listProducts, getProduct, listTaxons } from '@spree/next';
|
|
40
|
+
|
|
41
|
+
export default async function ProductsPage() {
|
|
42
|
+
const products = await listProducts({ per_page: 12 });
|
|
43
|
+
const categories = await listTaxons({ 'q[depth_eq]': 1 });
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div>
|
|
47
|
+
{products.data.map((product) => (
|
|
48
|
+
<div key={product.id}>{product.name}</div>
|
|
49
|
+
))}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 3. Use server actions for mutations
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { addItem, removeItem, getCart } from '@spree/next';
|
|
59
|
+
|
|
60
|
+
export default async function CartPage() {
|
|
61
|
+
const cart = await getCart();
|
|
62
|
+
|
|
63
|
+
async function handleAddItem(formData: FormData) {
|
|
64
|
+
'use server';
|
|
65
|
+
await addItem(formData.get('variantId') as string, 1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return <form action={handleAddItem}>...</form>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { initSpreeNext } from '@spree/next';
|
|
76
|
+
|
|
77
|
+
initSpreeNext({
|
|
78
|
+
baseUrl: 'https://api.mystore.com',
|
|
79
|
+
apiKey: 'your-publishable-api-key',
|
|
80
|
+
cartCookieName: '_spree_cart_token', // default
|
|
81
|
+
accessTokenCookieName: '_spree_jwt', // default
|
|
82
|
+
defaultLocale: 'en',
|
|
83
|
+
defaultCurrency: 'USD',
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Data Functions
|
|
88
|
+
|
|
89
|
+
Plain async functions for reading data in Server Components. Wrap with `"use cache"` in your app for caching.
|
|
90
|
+
|
|
91
|
+
### Products
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { listProducts, getProduct, getProductFilters } from '@spree/next';
|
|
95
|
+
|
|
96
|
+
const products = await listProducts({ per_page: 25, includes: 'variants,images' });
|
|
97
|
+
const product = await getProduct('ruby-on-rails-tote');
|
|
98
|
+
const filters = await getProductFilters({ taxon_id: 'txn_123' });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Categories
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { listTaxons, getTaxon, listTaxonProducts } from '@spree/next';
|
|
105
|
+
import { listTaxonomies, getTaxonomy } from '@spree/next';
|
|
106
|
+
|
|
107
|
+
const taxons = await listTaxons({ 'q[depth_eq]': 1 });
|
|
108
|
+
const taxon = await getTaxon('categories/clothing');
|
|
109
|
+
const products = await listTaxonProducts('categories/clothing', { per_page: 12 });
|
|
110
|
+
|
|
111
|
+
const taxonomies = await listTaxonomies({ includes: 'taxons' });
|
|
112
|
+
const taxonomy = await getTaxonomy('tax_123');
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Store & Geography
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { getStore, listCountries, getCountry } from '@spree/next';
|
|
119
|
+
|
|
120
|
+
const store = await getStore();
|
|
121
|
+
const countries = await listCountries();
|
|
122
|
+
const usa = await getCountry('US');
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Server Actions
|
|
126
|
+
|
|
127
|
+
Server actions handle mutations and auth-dependent reads. They automatically manage cookies for cart tokens and JWT authentication.
|
|
128
|
+
|
|
129
|
+
### Cart
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { getCart, getOrCreateCart, addItem, updateItem, removeItem, clearCart } from '@spree/next';
|
|
133
|
+
|
|
134
|
+
const cart = await getCart();
|
|
135
|
+
const cart = await getOrCreateCart();
|
|
136
|
+
await addItem(variantId, quantity);
|
|
137
|
+
await updateItem(lineItemId, quantity);
|
|
138
|
+
await removeItem(lineItemId);
|
|
139
|
+
await clearCart();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Checkout
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import {
|
|
146
|
+
getCheckout,
|
|
147
|
+
updateAddresses,
|
|
148
|
+
advance,
|
|
149
|
+
next,
|
|
150
|
+
getShipments,
|
|
151
|
+
selectShippingRate,
|
|
152
|
+
applyCoupon,
|
|
153
|
+
removeCoupon,
|
|
154
|
+
complete,
|
|
155
|
+
} from '@spree/next';
|
|
156
|
+
|
|
157
|
+
const checkout = await getCheckout();
|
|
158
|
+
await updateAddresses({ ship_address: { ... }, bill_address: { ... } });
|
|
159
|
+
await advance();
|
|
160
|
+
await next();
|
|
161
|
+
const shipments = await getShipments();
|
|
162
|
+
await selectShippingRate(shipmentId, rateId);
|
|
163
|
+
await applyCoupon('SAVE20');
|
|
164
|
+
await removeCoupon(promoId);
|
|
165
|
+
await complete();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Authentication
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { login, register, logout, getCustomer, updateCustomer } from '@spree/next';
|
|
172
|
+
|
|
173
|
+
await login(email, password);
|
|
174
|
+
await register({ email, password, password_confirmation, first_name, last_name });
|
|
175
|
+
await logout();
|
|
176
|
+
const customer = await getCustomer();
|
|
177
|
+
await updateCustomer({ first_name: 'John' });
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Addresses
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { listAddresses, getAddress, createAddress, updateAddress, deleteAddress } from '@spree/next';
|
|
184
|
+
|
|
185
|
+
const addresses = await listAddresses();
|
|
186
|
+
const address = await getAddress(addressId);
|
|
187
|
+
await createAddress({ firstname: 'John', address1: '123 Main St', ... });
|
|
188
|
+
await updateAddress(addressId, { city: 'Brooklyn' });
|
|
189
|
+
await deleteAddress(addressId);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Orders
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { listOrders, getOrder } from '@spree/next';
|
|
196
|
+
|
|
197
|
+
const orders = await listOrders();
|
|
198
|
+
const order = await getOrder(orderId);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Credit Cards & Gift Cards
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { listCreditCards, deleteCreditCard } from '@spree/next';
|
|
205
|
+
import { listGiftCards, getGiftCard } from '@spree/next';
|
|
206
|
+
|
|
207
|
+
const cards = await listCreditCards();
|
|
208
|
+
await deleteCreditCard(cardId);
|
|
209
|
+
|
|
210
|
+
const giftCards = await listGiftCards();
|
|
211
|
+
const giftCard = await getGiftCard(giftCardId);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Localization
|
|
215
|
+
|
|
216
|
+
Pass locale and currency options to data functions:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const products = await listProducts({ per_page: 10 }, { locale: 'fr', currency: 'EUR' });
|
|
220
|
+
const taxon = await getTaxon('categories/clothing', {}, { locale: 'de', currency: 'EUR' });
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## TypeScript
|
|
224
|
+
|
|
225
|
+
All types are re-exported from `@spree/sdk` for convenience:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import type {
|
|
229
|
+
StoreProduct,
|
|
230
|
+
StoreOrder,
|
|
231
|
+
StoreLineItem,
|
|
232
|
+
StoreTaxon,
|
|
233
|
+
PaginatedResponse,
|
|
234
|
+
SpreeError,
|
|
235
|
+
} from '@spree/next';
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Development
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
cd packages/next
|
|
242
|
+
pnpm install
|
|
243
|
+
pnpm dev # Build in watch mode
|
|
244
|
+
pnpm typecheck # Type-check
|
|
245
|
+
pnpm test # Run tests
|
|
246
|
+
pnpm build # Production build
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Releasing
|
|
250
|
+
|
|
251
|
+
This package uses [Changesets](https://github.com/changesets/changesets) for version management.
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
npx changeset # Add a changeset after making changes
|
|
255
|
+
npx changeset version # Bump version and update CHANGELOG
|
|
256
|
+
pnpm release # Build and publish to npm
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
package/dist/actions/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StoreCustomer } from '@spree/sdk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Login with email and password.
|
|
@@ -35,7 +35,7 @@ declare function logout(): Promise<void>;
|
|
|
35
35
|
/**
|
|
36
36
|
* Get the currently authenticated customer. Returns null if not logged in.
|
|
37
37
|
*/
|
|
38
|
-
declare function getCustomer(): Promise<
|
|
38
|
+
declare function getCustomer(): Promise<StoreCustomer | null>;
|
|
39
39
|
/**
|
|
40
40
|
* Update the current customer's profile.
|
|
41
41
|
*/
|
|
@@ -43,6 +43,6 @@ declare function updateCustomer(data: {
|
|
|
43
43
|
first_name?: string;
|
|
44
44
|
last_name?: string;
|
|
45
45
|
email?: string;
|
|
46
|
-
}): Promise<
|
|
46
|
+
}): Promise<StoreCustomer>;
|
|
47
47
|
|
|
48
48
|
export { getCustomer, login, logout, register, updateCustomer };
|
package/dist/actions/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/auth.ts","../../src/config.ts","../../src/cookies.ts","../../src/auth-helpers.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreUser } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreUser | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreUser> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n"],"mappings":";;;AAEA,SAAS,qBAAqB;;;ACF9B,SAAS,yBAA2C;AAGpD,IAAI,UAA8B;AAClC,IAAI,UAAkC;AAO/B,SAAS,cAAc,QAA+B;AAC3D,YAAU;AACV,YAAU,kBAAkB;AAAA,IAC1B,SAAS,OAAO;AAAA,IAChB,QAAQ,OAAO;AAAA,EACjB,CAAC;AACH;AAMO,SAAS,YAAyB;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,UAAU,QAAQ,IAAI;AAC5B,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,WAAW,QAAQ;AACrB,oBAAc,EAAE,SAAS,OAAO,CAAC;AAAA,IACnC,OAAO;AACL,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,YAA6B;AAC3C,MAAI,CAAC,SAAS;AACZ,cAAU;AAAA,EACZ;AACA,SAAO;AACT;;;AC/CA,SAAS,eAAe;AAGxB,IAAM,sBAAsB;AAC5B,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAE5C,SAAS,oBAA4B;AACnC,MAAI;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AC4I;AAC5I,MAAI;AACF,UAAM,SAAS,MAAM,UAAU,EAAE,KAAK,SAAS;AAAA,MAC7C;AAAA,MACA;AAAA,MACA,uBAAuB;AAAA,IACzB,CAAC;AACD,UAAM,eAAe,OAAO,KAAK;AAGjC,UAAM,YAAY,MAAM,aAAa;AACrC,QAAI,WAAW;AACb,UAAI;AACF,cAAM,UAAU,EAAE,KAAK,UAAU;AAAA,UAC/B,OAAO,OAAO;AAAA,UACd,YAAY;AAAA,QACd,CAAC;AAAA,MACH,QAAQ;AAAA,MAER;AAAA,IACF;AAEA,kBAAc,UAAU;AACxB,kBAAc,MAAM;AACpB,WAAO,EAAE,SAAS,MAAM,MAAM,OAAO,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,IAClD;AAAA,EACF;AACF;AAKA,eAAsB,SAAwB;AAC5C,QAAM,iBAAiB;AACvB,gBAAc,UAAU;AACxB,gBAAc,MAAM;AACpB,gBAAc,WAAW;AACzB,gBAAc,cAAc;AAC9B;AAKA,eAAsB,cAAyC;AAC7D,QAAM,QAAQ,MAAM,eAAe;AACnC,MAAI,CAAC,MAAO,QAAO;AAEnB,MAAI;AACF,WAAO,MAAM,gBAAgB,OAAO,YAAY;AAC9C,aAAO,UAAU,EAAE,SAAS,IAAI,OAAO;AAAA,IACzC,CAAC;AAAA,EACH,QAAQ;AACN,UAAM,iBAAiB;AACvB,WAAO;AAAA,EACT;AACF;AAKA,eAAsB,eACpB,MACoB;AACpB,QAAM,SAAS,MAAM,gBAAgB,OAAO,YAAY;AACtD,WAAO,UAAU,EAAE,SAAS,OAAO,MAAM,OAAO;AAAA,EAClD,CAAC;AACD,gBAAc,UAAU;AACxB,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/actions/auth.ts","../../src/config.ts","../../src/cookies.ts","../../src/auth-helpers.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCustomer } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreCustomer | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreCustomer> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n"],"mappings":";;;AAEA,SAAS,qBAAqB;;;ACF9B,SAAS,yBAA2C;AAGpD,IAAI,UAA8B;AAClC,IAAI,UAAkC;AAO/B,SAAS,cAAc,QAA+B;AAC3D,YAAU;AACV,YAAU,kBAAkB;AAAA,IAC1B,SAAS,OAAO;AAAA,IAChB,QAAQ,OAAO;AAAA,EACjB,CAAC;AACH;AAMO,SAAS,YAAyB;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,UAAU,QAAQ,IAAI;AAC5B,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,WAAW,QAAQ;AACrB,oBAAc,EAAE,SAAS,OAAO,CAAC;AAAA,IACnC,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ACH,QAAQ;AACN,UAAM,iBAAiB;AACvB,WAAO;AAAA,EACT;AACF;AAKA,eAAsB,eACpB,MACwB;AACxB,QAAM,SAAS,MAAM,gBAAgB,OAAO,YAAY;AACtD,WAAO,UAAU,EAAE,SAAS,OAAO,MAAM,OAAO;AAAA,EAClD,CAAC;AACD,gBAAc,UAAU;AACxB,SAAO;AACT;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export { getTaxon, listTaxonProducts, listTaxons } from './data/taxons.js';
|
|
|
5
5
|
export { getTaxonomy, listTaxonomies } from './data/taxonomies.js';
|
|
6
6
|
export { getStore } from './data/store.js';
|
|
7
7
|
export { getCountry, listCountries } from './data/countries.js';
|
|
8
|
-
import { StoreLineItem, StoreOrder, StoreShipment, AddressParams,
|
|
9
|
-
export { AddressParams, PaginatedResponse, ProductFiltersResponse, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreGiftCard, StoreImage, StoreLineItem, StoreOptionType, StoreOptionValue, StoreOrder, StoreOrderPromotion, StorePayment, StorePaymentMethod, StorePrice, StoreProduct, StoreShipment, StoreShippingRate, StoreStore, StoreTaxon, StoreTaxonomy,
|
|
8
|
+
import { StoreLineItem, StoreOrder, StoreShipment, AddressParams, StoreCustomer, StoreAddress, PaginatedResponse, StoreCreditCard, StoreGiftCard } from '@spree/sdk';
|
|
9
|
+
export { AddressParams, PaginatedResponse, ProductFiltersResponse, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreCustomer, StoreGiftCard, StoreImage, StoreLineItem, StoreOptionType, StoreOptionValue, StoreOrder, StoreOrderPromotion, StorePayment, StorePaymentMethod, StorePrice, StoreProduct, StoreShipment, StoreShippingRate, StoreStore, StoreTaxon, StoreTaxonomy, StoreVariant } from '@spree/sdk';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Get the current cart. Returns null if no cart exists.
|
|
@@ -125,7 +125,7 @@ declare function logout(): Promise<void>;
|
|
|
125
125
|
/**
|
|
126
126
|
* Get the currently authenticated customer. Returns null if not logged in.
|
|
127
127
|
*/
|
|
128
|
-
declare function getCustomer(): Promise<
|
|
128
|
+
declare function getCustomer(): Promise<StoreCustomer | null>;
|
|
129
129
|
/**
|
|
130
130
|
* Update the current customer's profile.
|
|
131
131
|
*/
|
|
@@ -133,7 +133,7 @@ declare function updateCustomer(data: {
|
|
|
133
133
|
first_name?: string;
|
|
134
134
|
last_name?: string;
|
|
135
135
|
email?: string;
|
|
136
|
-
}): Promise<
|
|
136
|
+
}): Promise<StoreCustomer>;
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
139
|
* List the authenticated customer's addresses.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/data/products.ts","../src/data/taxons.ts","../src/data/taxonomies.ts","../src/data/store.ts","../src/data/countries.ts","../src/cookies.ts","../src/actions/cart.ts","../src/actions/checkout.ts","../src/auth-helpers.ts","../src/actions/auth.ts","../src/actions/addresses.ts","../src/actions/orders.ts","../src/actions/credit-cards.ts","../src/actions/gift-cards.ts"],"names":["revalidateTag"],"mappings":";;;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ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A,EAA2B;AAChE,EAAA,MAAM,eAAA,CAAgB,OAAO,OAAA,KAAY;AACvC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,WAAA,CAAY,MAAA,CAAO,IAAI,OAAO,CAAA;AAAA,EAC5D,CAAC,CAAA;AACD,EAAAA,cAAc,cAAc,CAAA;AAC9B;;;ACfA,eAAsB,aAAA,GAAoD;AACxE,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,SAAA,CAAU,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;AAKA,eAAsB,YAAY,EAAA,EAAoC;AACpE,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,SAAA,CAAU,GAAA,CAAI,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"index.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n */\nexport async function listTaxons(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n return getClient().taxons.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxon by ID or permalink.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n return getClient().taxons.get(idOrPermalink, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List products within a taxon.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().taxons.products.list(taxonId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all available countries.\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().countries.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single country by ISO code.\n */\nexport async function getCountry(\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().countries.get(iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreLineItem } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, setCartToken, clearCartToken, getAccessToken } from '../cookies';\n\n/**\n * Get the current cart. Returns null if no cart exists.\n */\nexport async function getCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) return null;\n\n try {\n return await getClient().cart.get({ orderToken, token });\n } catch {\n return null;\n }\n}\n\n/**\n * Get existing cart or create a new one.\n */\nexport async function getOrCreateCart(): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cart = await getClient().cart.create(token ? { token } : undefined);\n\n if (cart.token) {\n await setCartToken(cart.token);\n }\n\n revalidateTag('cart');\n return cart;\n}\n\n/**\n * Add an item to the cart. Creates a cart if none exists.\n */\nexport async function addItem(\n variantId: string,\n quantity: number = 1\n): Promise<StoreLineItem> {\n const cart = await getOrCreateCart();\n const orderToken = cart.token;\n const token = await getAccessToken();\n\n const lineItem = await getClient().orders.lineItems.create(\n cart.id,\n { variant_id: variantId, quantity },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return lineItem;\n}\n\n/**\n * Update a line item quantity in the cart.\n */\nexport async function updateItem(\n lineItemId: string,\n quantity: number\n): Promise<StoreLineItem> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().cart.get({ orderToken, token });\n\n const lineItem = await getClient().orders.lineItems.update(\n cart.id,\n lineItemId,\n { quantity },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return lineItem;\n}\n\n/**\n * Remove a line item from the cart.\n */\nexport async function removeItem(lineItemId: string): Promise<void> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().cart.get({ orderToken, token });\n\n await getClient().orders.lineItems.delete(cart.id, lineItemId, {\n orderToken,\n token,\n });\n\n revalidateTag('cart');\n}\n\n/**\n * Clear the cart (abandons the current cart).\n */\nexport async function clearCart(): Promise<void> {\n await clearCartToken();\n revalidateTag('cart');\n}\n\n/**\n * Associate a guest cart with the currently authenticated user.\n * Call this after login/register when the user has an existing guest cart.\n */\nexport async function associateCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken || !token) return null;\n\n try {\n const result = await getClient().cart.associate({ orderToken, token });\n revalidateTag('cart');\n return result;\n } catch {\n // Cart might already belong to another user — clear it\n await clearCartToken();\n revalidateTag('cart');\n return null;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreShipment, AddressParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Get the current checkout order state.\n * Includes line_items, shipments, and addresses by default.\n */\nexport async function getCheckout(\n orderId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n return getClient().orders.get(\n orderId,\n { includes: 'line_items,shipments,ship_address,bill_address' },\n options\n );\n}\n\n/**\n * Update shipping and/or billing addresses on the order.\n */\nexport async function updateAddresses(\n orderId: string,\n params: {\n email?: string;\n ship_address?: AddressParams;\n bill_address?: AddressParams;\n ship_address_id?: string;\n bill_address_id?: string;\n }\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.update(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Advance the checkout to the next step.\n */\nexport async function advance(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.advance(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Move the checkout to the next step (alias for advance).\n */\nexport async function next(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.next(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get shipments for the order (includes available shipping rates).\n */\nexport async function getShipments(\n orderId: string\n): Promise<{ data: StoreShipment[] }> {\n const options = await getCheckoutOptions();\n return getClient().orders.shipments.list(orderId, options);\n}\n\n/**\n * Select a shipping rate for a shipment.\n */\nexport async function selectShippingRate(\n orderId: string,\n shipmentId: string,\n shippingRateId: string\n): Promise<StoreShipment> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.shipments.update(\n orderId,\n shipmentId,\n { selected_shipping_rate_id: shippingRateId },\n options\n );\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Apply a coupon code to the order.\n */\nexport async function applyCoupon(\n orderId: string,\n code: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.couponCodes.apply(orderId, code, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Remove a coupon/promotion from the order.\n */\nexport async function removeCoupon(\n orderId: string,\n promotionId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.couponCodes.remove(orderId, promotionId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Complete the checkout and place the order.\n */\nexport async function complete(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.complete(orderId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreUser } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreUser | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreUser> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreAddress, AddressParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's addresses.\n */\nexport async function listAddresses(): Promise<{ data: StoreAddress[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.addresses.list(undefined, options);\n });\n}\n\n/**\n * Get a single address by ID.\n */\nexport async function getAddress(id: string): Promise<StoreAddress> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.addresses.get(id, options);\n });\n}\n\n/**\n * Create a new address for the customer.\n */\nexport async function createAddress(params: AddressParams): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.create(params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Update an existing address.\n */\nexport async function updateAddress(\n id: string,\n params: Partial<AddressParams>\n): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.update(id, params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Delete an address.\n */\nexport async function deleteAddress(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.delete(id, options);\n });\n revalidateTag('addresses');\n}\n","'use server';\n\nimport type { StoreOrder, PaginatedResponse } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's orders.\n */\nexport async function listOrders(\n params?: Record<string, unknown>\n): Promise<PaginatedResponse<StoreOrder>> {\n return withAuthRefresh(async (options) => {\n return getClient().orders.list(params, options);\n });\n}\n\n/**\n * Get a single order by ID or number.\n */\nexport async function getOrder(\n idOrNumber: string,\n params?: Record<string, unknown>\n): Promise<StoreOrder> {\n return withAuthRefresh(async (options) => {\n return getClient().orders.get(idOrNumber, params, options);\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCreditCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's credit cards.\n */\nexport async function listCreditCards(): Promise<{ data: StoreCreditCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.creditCards.list(undefined, options);\n });\n}\n\n/**\n * Delete a credit card.\n */\nexport async function deleteCreditCard(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().customer.creditCards.delete(id, options);\n });\n revalidateTag('credit-cards');\n}\n","'use server';\n\nimport type { StoreGiftCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's gift cards.\n */\nexport async function listGiftCards(): Promise<{ data: StoreGiftCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.giftCards.list(undefined, options);\n });\n}\n\n/**\n * Get a single gift card by ID.\n */\nexport async function getGiftCard(id: string): Promise<StoreGiftCard> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.giftCards.get(id, options);\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/data/products.ts","../src/data/taxons.ts","../src/data/taxonomies.ts","../src/data/store.ts","../src/data/countries.ts","../src/cookies.ts","../src/actions/cart.ts","../src/actions/checkout.ts","../src/auth-helpers.ts","../src/actions/auth.ts","../src/actions/addresses.ts","../src/actions/orders.ts","../src/actions/credit-cards.ts","../src/actions/gift-cards.ts"],"names":["revalidateTag"],"mappings":";;;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;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AAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,SAAA,CAAU,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;AAKA,eAAsB,YAAY,EAAA,EAAoC;AACpE,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,SAAA,CAAU,GAAA,CAAI,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"index.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n */\nexport async function listTaxons(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n return getClient().taxons.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxon by ID or permalink.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n return getClient().taxons.get(idOrPermalink, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List products within a taxon.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().taxons.products.list(taxonId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all available countries.\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().countries.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single country by ISO code.\n */\nexport async function getCountry(\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().countries.get(iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreLineItem } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, setCartToken, clearCartToken, getAccessToken } from '../cookies';\n\n/**\n * Get the current cart. Returns null if no cart exists.\n */\nexport async function getCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) return null;\n\n try {\n return await getClient().cart.get({ orderToken, token });\n } catch {\n return null;\n }\n}\n\n/**\n * Get existing cart or create a new one.\n */\nexport async function getOrCreateCart(): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cart = await getClient().cart.create(token ? { token } : undefined);\n\n if (cart.token) {\n await setCartToken(cart.token);\n }\n\n revalidateTag('cart');\n return cart;\n}\n\n/**\n * Add an item to the cart. Creates a cart if none exists.\n */\nexport async function addItem(\n variantId: string,\n quantity: number = 1\n): Promise<StoreLineItem> {\n const cart = await getOrCreateCart();\n const orderToken = cart.token;\n const token = await getAccessToken();\n\n const lineItem = await getClient().orders.lineItems.create(\n cart.id,\n { variant_id: variantId, quantity },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return lineItem;\n}\n\n/**\n * Update a line item quantity in the cart.\n */\nexport async function updateItem(\n lineItemId: string,\n quantity: number\n): Promise<StoreLineItem> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().cart.get({ orderToken, token });\n\n const lineItem = await getClient().orders.lineItems.update(\n cart.id,\n lineItemId,\n { quantity },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return lineItem;\n}\n\n/**\n * Remove a line item from the cart.\n */\nexport async function removeItem(lineItemId: string): Promise<void> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().cart.get({ orderToken, token });\n\n await getClient().orders.lineItems.delete(cart.id, lineItemId, {\n orderToken,\n token,\n });\n\n revalidateTag('cart');\n}\n\n/**\n * Clear the cart (abandons the current cart).\n */\nexport async function clearCart(): Promise<void> {\n await clearCartToken();\n revalidateTag('cart');\n}\n\n/**\n * Associate a guest cart with the currently authenticated user.\n * Call this after login/register when the user has an existing guest cart.\n */\nexport async function associateCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken || !token) return null;\n\n try {\n const result = await getClient().cart.associate({ orderToken, token });\n revalidateTag('cart');\n return result;\n } catch {\n // Cart might already belong to another user — clear it\n await clearCartToken();\n revalidateTag('cart');\n return null;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreShipment, AddressParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Get the current checkout order state.\n * Includes line_items, shipments, and addresses by default.\n */\nexport async function getCheckout(\n orderId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n return getClient().orders.get(\n orderId,\n { includes: 'line_items,shipments,ship_address,bill_address' },\n options\n );\n}\n\n/**\n * Update shipping and/or billing addresses on the order.\n */\nexport async function updateAddresses(\n orderId: string,\n params: {\n email?: string;\n ship_address?: AddressParams;\n bill_address?: AddressParams;\n ship_address_id?: string;\n bill_address_id?: string;\n }\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.update(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Advance the checkout to the next step.\n */\nexport async function advance(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.advance(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Move the checkout to the next step (alias for advance).\n */\nexport async function next(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.next(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get shipments for the order (includes available shipping rates).\n */\nexport async function getShipments(\n orderId: string\n): Promise<{ data: StoreShipment[] }> {\n const options = await getCheckoutOptions();\n return getClient().orders.shipments.list(orderId, options);\n}\n\n/**\n * Select a shipping rate for a shipment.\n */\nexport async function selectShippingRate(\n orderId: string,\n shipmentId: string,\n shippingRateId: string\n): Promise<StoreShipment> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.shipments.update(\n orderId,\n shipmentId,\n { selected_shipping_rate_id: shippingRateId },\n options\n );\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Apply a coupon code to the order.\n */\nexport async function applyCoupon(\n orderId: string,\n code: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.couponCodes.apply(orderId, code, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Remove a coupon/promotion from the order.\n */\nexport async function removeCoupon(\n orderId: string,\n promotionId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.couponCodes.remove(orderId, promotionId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Complete the checkout and place the order.\n */\nexport async function complete(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().orders.complete(orderId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCustomer } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreCustomer | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreCustomer> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreAddress, AddressParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's addresses.\n */\nexport async function listAddresses(): Promise<{ data: StoreAddress[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.addresses.list(undefined, options);\n });\n}\n\n/**\n * Get a single address by ID.\n */\nexport async function getAddress(id: string): Promise<StoreAddress> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.addresses.get(id, options);\n });\n}\n\n/**\n * Create a new address for the customer.\n */\nexport async function createAddress(params: AddressParams): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.create(params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Update an existing address.\n */\nexport async function updateAddress(\n id: string,\n params: Partial<AddressParams>\n): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.update(id, params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Delete an address.\n */\nexport async function deleteAddress(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().customer.addresses.delete(id, options);\n });\n revalidateTag('addresses');\n}\n","'use server';\n\nimport type { StoreOrder, PaginatedResponse } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's orders.\n */\nexport async function listOrders(\n params?: Record<string, unknown>\n): Promise<PaginatedResponse<StoreOrder>> {\n return withAuthRefresh(async (options) => {\n return getClient().orders.list(params, options);\n });\n}\n\n/**\n * Get a single order by ID or number.\n */\nexport async function getOrder(\n idOrNumber: string,\n params?: Record<string, unknown>\n): Promise<StoreOrder> {\n return withAuthRefresh(async (options) => {\n return getClient().orders.get(idOrNumber, params, options);\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCreditCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's credit cards.\n */\nexport async function listCreditCards(): Promise<{ data: StoreCreditCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.creditCards.list(undefined, options);\n });\n}\n\n/**\n * Delete a credit card.\n */\nexport async function deleteCreditCard(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().customer.creditCards.delete(id, options);\n });\n revalidateTag('credit-cards');\n}\n","'use server';\n\nimport type { StoreGiftCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's gift cards.\n */\nexport async function listGiftCards(): Promise<{ data: StoreGiftCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.giftCards.list(undefined, options);\n });\n}\n\n/**\n * Get a single gift card by ID.\n */\nexport async function getGiftCard(id: string): Promise<StoreGiftCard> {\n return withAuthRefresh(async (options) => {\n return getClient().customer.giftCards.get(id, options);\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spree/next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Next.js integration for Spree Commerce — server actions, caching, and cookie-based auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,18 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"clean": "rm -rf dist",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"changeset": "changeset",
|
|
34
|
+
"version": "changeset version",
|
|
35
|
+
"release": "npm run build && changeset publish"
|
|
36
|
+
},
|
|
25
37
|
"keywords": [
|
|
26
38
|
"spree",
|
|
27
39
|
"commerce",
|
|
@@ -43,31 +55,20 @@
|
|
|
43
55
|
"url": "https://github.com/spree/spree/issues"
|
|
44
56
|
},
|
|
45
57
|
"peerDependencies": {
|
|
46
|
-
"@spree/sdk": ">=0.1.
|
|
58
|
+
"@spree/sdk": ">=0.1.5",
|
|
47
59
|
"next": ">=15.0.0",
|
|
48
60
|
"react": ">=19.0.0"
|
|
49
61
|
},
|
|
50
62
|
"devDependencies": {
|
|
51
63
|
"@changesets/changelog-github": "^0.5.2",
|
|
52
64
|
"@changesets/cli": "^2.29.8",
|
|
65
|
+
"@spree/sdk": "workspace:*",
|
|
53
66
|
"@types/node": "^20.0.0",
|
|
54
67
|
"@types/react": "^19.0.0",
|
|
55
68
|
"next": "^15.3.3",
|
|
56
69
|
"react": "^19.0.0",
|
|
57
70
|
"tsup": "^8.0.0",
|
|
58
71
|
"typescript": "^5.3.0",
|
|
59
|
-
"vitest": "^4.0.18"
|
|
60
|
-
"@spree/sdk": "0.1.4"
|
|
61
|
-
},
|
|
62
|
-
"scripts": {
|
|
63
|
-
"build": "tsup",
|
|
64
|
-
"dev": "tsup --watch",
|
|
65
|
-
"typecheck": "tsc --noEmit",
|
|
66
|
-
"test": "vitest run",
|
|
67
|
-
"test:watch": "vitest",
|
|
68
|
-
"clean": "rm -rf dist",
|
|
69
|
-
"changeset": "changeset",
|
|
70
|
-
"version": "changeset version",
|
|
71
|
-
"release": "npm run build && changeset publish"
|
|
72
|
+
"vitest": "^4.0.18"
|
|
72
73
|
}
|
|
73
|
-
}
|
|
74
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# License
|
|
2
|
-
|
|
3
|
-
Copyright © 2024-present, Vendo Connect Inc.
|
|
4
|
-
|
|
5
|
-
Copyright © 2015-2024, Spark Solutions Sp. z o.o.
|
|
6
|
-
|
|
7
|
-
Copyright © 2007-2015, Spree Commerce Inc.
|
|
8
|
-
|
|
9
|
-
Spree Commerce is a free, open-source eCommerce framework giving you full control and customizability.
|
|
10
|
-
|
|
11
|
-
For **Spree Commerce versions 4.10** and later in the [spree/spree](https://github.com/spree/spree) repository two licenses apply simultaneously and users are required to comply with the terms of these two licenses at the same time:
|
|
12
|
-
|
|
13
|
-
* [AGPL-3.0](https://opensource.org/license/agpl-v3) - for all contributions from version 4.10 onwards
|
|
14
|
-
|
|
15
|
-
* [BSD-3-Clause](https://opensource.org/license/bsd-3-clause) - for all other contributions predating version 4.10
|
|
16
|
-
|
|
17
|
-
Effectively, for versions 4.10 and upwards **AGPL-3.0** license applies.
|
|
18
|
-
|
|
19
|
-
**Spree Commerce versions 4.9** and earlier in the [spree/spree](https://github.com/spree/spree) repository are available under the **BSD-3-Clause** license and users are required to comply with its terms.
|
|
20
|
-
|
|
21
|
-
If you’d like to use Spree Commerce without the AGPL-3.0 restrictions e.g. for a **SaaS** business, please talk to us about obtaining a [Commercial License](#commercial-license).
|
|
22
|
-
|
|
23
|
-
All third party components incorporated into this software are licensed under the original license provided by the owner of the applicable component.
|
|
24
|
-
|
|
25
|
-
Please refer to our [Licensing FAQ](https://spreecommerce.org/why-spree-is-changing-its-open-source-license-to-agpl-3-0-and-introducing-a-commercial-license/) in case of questions.
|
|
26
|
-
|
|
27
|
-
## AGPL-3.0 License - Spree 4.10 upwards
|
|
28
|
-
|
|
29
|
-
If you decide to accept the AGPL-3.0 license by using Spree Commerce version 4.10 or later, you must comply with the following terms:
|
|
30
|
-
|
|
31
|
-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
32
|
-
|
|
33
|
-
This program is distributed in the hope that it will be useful,
|
|
34
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
35
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
36
|
-
GNU Affero General Public License for more details.
|
|
37
|
-
|
|
38
|
-
You should have received a copy of the GNU Affero General Public License
|
|
39
|
-
along with this program. If not, see [https://www.gnu.org/licenses/](https://www.gnu.org/licenses/).
|
|
40
|
-
|
|
41
|
-
## BSD 3-Clause License
|
|
42
|
-
|
|
43
|
-
If you decide to accept the BSD-3-Clause license by using Spree Commerce, you must comply with the following terms:
|
|
44
|
-
|
|
45
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
46
|
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
47
|
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
48
|
-
Neither the name of Spree Commerce Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
49
|
-
|
|
50
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
51
|
-
|
|
52
|
-
## Commercial License
|
|
53
|
-
|
|
54
|
-
Should you decide to use Spree Commerce version 4.10 or later for commercial redistribution (eg. SaaS) - also known as Commercial Distribution - you must do so in accordance with the terms and conditions contained in a separate written agreement between you and [Vendo Connect Inc.](https://www.getvendo.com/).
|
|
55
|
-
|
|
56
|
-
For more information about the Commercial License (CL) please contact [sales@getvendo.com](mailto:sales@getvendo.com).
|
|
57
|
-
|
|
58
|
-
Please refer to our [Licensing FAQ](https://spreecommerce.org/why-spree-is-changing-its-open-source-license-to-agpl-3-0-and-introducing-a-commercial-license/) in case of questions.
|