@thorprovider/create-thor-app 2.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 +470 -0
- package/dist/index.js +1054 -0
- package/package.json +46 -0
- package/templates/default/.env.example +56 -0
- package/templates/default/.eslintrc.json +43 -0
- package/templates/default/README.md +151 -0
- package/templates/default/app/api/revalidate/route.ts +64 -0
- package/templates/default/app/backend-unavailable/page.tsx +85 -0
- package/templates/default/app/error.tsx +58 -0
- package/templates/default/app/global-error.tsx +208 -0
- package/templates/default/app/globals.css +125 -0
- package/templates/default/app/layout.tsx +50 -0
- package/templates/default/app/not-found.tsx +31 -0
- package/templates/default/app/page.tsx +124 -0
- package/templates/default/components/providers/app-providers.tsx +77 -0
- package/templates/default/components/providers/navigation-provider.tsx +37 -0
- package/templates/default/config/site.config.ts +156 -0
- package/templates/default/docs/README.md +46 -0
- package/templates/default/docs/commerce-api.md +243 -0
- package/templates/default/docs/components.md +276 -0
- package/templates/default/docs/dependencies.md +53 -0
- package/templates/default/docs/patterns.md +100 -0
- package/templates/default/docs/project-structure.md +53 -0
- package/templates/default/docs/rules.md +51 -0
- package/templates/default/docs/types.md +329 -0
- package/templates/default/lib/auth-context.tsx +213 -0
- package/templates/default/lib/cart-provider.tsx +53 -0
- package/templates/default/lib/commerce-provider.tsx +48 -0
- package/templates/default/lib/commerce.ts +165 -0
- package/templates/default/lib/env.ts +147 -0
- package/templates/default/lib/region-detection.ts +80 -0
- package/templates/default/lib/region-provider.tsx +53 -0
- package/templates/default/lib/regions-config.ts +48 -0
- package/templates/default/lib/storefront-config.ts +54 -0
- package/templates/default/lib/utils.ts +10 -0
- package/templates/default/next-env.d.ts +6 -0
- package/templates/default/next.config.mjs +51 -0
- package/templates/default/package.json +42 -0
- package/templates/default/postcss.config.mjs +8 -0
- package/templates/default/proxy.ts +155 -0
- package/templates/default/scripts/generate-regions-config.ts +498 -0
- package/templates/default/tsconfig.json +43 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# Domain Types
|
|
2
|
+
|
|
3
|
+
All types come from `@thorprovider/types`. Import with:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import type { Product, Cart, Order, Customer, Address, Money } from '@thorprovider/types';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Core Primitives
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface Money {
|
|
15
|
+
amount: string; // Decimal as string: "45.00"
|
|
16
|
+
currencyCode: string; // ISO 4217: "USD", "EUR"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Image {
|
|
20
|
+
url: string;
|
|
21
|
+
altText: string;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Country {
|
|
27
|
+
code: string; // ISO 3166-1 alpha-2: "US", "ES"
|
|
28
|
+
name: string; // "United States"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Product
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
interface Product {
|
|
38
|
+
id: string;
|
|
39
|
+
handle: string; // URL slug
|
|
40
|
+
title: string;
|
|
41
|
+
description: string;
|
|
42
|
+
descriptionHtml?: string;
|
|
43
|
+
availableForSale: boolean;
|
|
44
|
+
options: ProductOption[];
|
|
45
|
+
variants: ProductVariant[];
|
|
46
|
+
featuredImage?: Image;
|
|
47
|
+
images: Image[];
|
|
48
|
+
priceRange: PriceRange;
|
|
49
|
+
collections?: Array<{ id: string; title: string; handle: string }>;
|
|
50
|
+
productType?: string;
|
|
51
|
+
tags?: string[];
|
|
52
|
+
seo?: { title: string; description: string };
|
|
53
|
+
createdAt: string;
|
|
54
|
+
updatedAt: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ProductVariant {
|
|
58
|
+
id: string;
|
|
59
|
+
title: string;
|
|
60
|
+
sku?: string;
|
|
61
|
+
availableForSale: boolean;
|
|
62
|
+
selectedOptions: Array<{ name: string; value: string }>;
|
|
63
|
+
price: Money;
|
|
64
|
+
compareAtPrice?: Money; // original price (for sale display)
|
|
65
|
+
quantityAvailable?: number;
|
|
66
|
+
image?: Image;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ProductOption {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string; // "Size", "Color"
|
|
72
|
+
values: string[]; // ["S", "M", "L"]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface PriceRange {
|
|
76
|
+
minVariantPrice: Money;
|
|
77
|
+
maxVariantPrice: Money;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Cart
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
interface Cart {
|
|
87
|
+
id: string | undefined;
|
|
88
|
+
checkoutUrl: string;
|
|
89
|
+
cost: {
|
|
90
|
+
subtotalAmount: Money;
|
|
91
|
+
totalAmount: Money;
|
|
92
|
+
totalTaxAmount?: Money;
|
|
93
|
+
};
|
|
94
|
+
lines: CartItem[];
|
|
95
|
+
totalQuantity: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface CartItem {
|
|
99
|
+
id: string | undefined;
|
|
100
|
+
quantity: number;
|
|
101
|
+
cost: { totalAmount: Money };
|
|
102
|
+
merchandise: {
|
|
103
|
+
id: string; // variant ID
|
|
104
|
+
title: string;
|
|
105
|
+
selectedOptions: Array<{ name: string; value: string }>;
|
|
106
|
+
product: {
|
|
107
|
+
id: string;
|
|
108
|
+
handle: string;
|
|
109
|
+
title: string;
|
|
110
|
+
featuredImage: Image;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// For addToCart:
|
|
116
|
+
interface CartLineInput { merchandiseId: string; quantity: number; }
|
|
117
|
+
|
|
118
|
+
// For updateCart:
|
|
119
|
+
interface CartLineUpdate { id: string; merchandiseId: string; quantity: number; }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Order
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
type OrderStatus = 'pending' | 'processing' | 'completed' | 'cancelled' | 'refunded';
|
|
128
|
+
type PaymentStatus = 'pending' | 'authorized' | 'paid' | 'partially_refunded' | 'refunded';
|
|
129
|
+
type FulfillmentStatus = 'unfulfilled' | 'partially_fulfilled' | 'fulfilled' | 'returned';
|
|
130
|
+
|
|
131
|
+
interface Order {
|
|
132
|
+
id: string;
|
|
133
|
+
orderNumber: string;
|
|
134
|
+
email: string;
|
|
135
|
+
status: OrderStatus;
|
|
136
|
+
paymentStatus: PaymentStatus;
|
|
137
|
+
fulfillmentStatus: FulfillmentStatus;
|
|
138
|
+
customerId?: string;
|
|
139
|
+
customer?: Customer;
|
|
140
|
+
items: OrderItem[];
|
|
141
|
+
subtotal: Money;
|
|
142
|
+
total: Money;
|
|
143
|
+
tax?: Money;
|
|
144
|
+
shipping?: Money;
|
|
145
|
+
discount?: Money;
|
|
146
|
+
shippingAddress?: Address;
|
|
147
|
+
billingAddress?: Address;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
updatedAt: string;
|
|
150
|
+
isDraft?: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface OrderItem {
|
|
154
|
+
id: string;
|
|
155
|
+
title: string;
|
|
156
|
+
variantTitle?: string;
|
|
157
|
+
quantity: number;
|
|
158
|
+
price: Money;
|
|
159
|
+
total: Money;
|
|
160
|
+
sku?: string;
|
|
161
|
+
image?: Image;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Customer
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
interface Customer {
|
|
171
|
+
id: string;
|
|
172
|
+
email: string;
|
|
173
|
+
firstName: string | null;
|
|
174
|
+
lastName: string | null;
|
|
175
|
+
phone?: string | null;
|
|
176
|
+
hasAccount?: boolean;
|
|
177
|
+
createdAt?: string;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Address
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
interface Address {
|
|
187
|
+
id?: string;
|
|
188
|
+
firstName: string;
|
|
189
|
+
lastName: string;
|
|
190
|
+
company?: string;
|
|
191
|
+
address1: string;
|
|
192
|
+
address2?: string;
|
|
193
|
+
city: string;
|
|
194
|
+
province?: string;
|
|
195
|
+
postalCode: string;
|
|
196
|
+
countryCode: string; // ISO 3166-1 alpha-2
|
|
197
|
+
phone?: string;
|
|
198
|
+
isDefault?: boolean;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Collection & Category
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
interface Collection {
|
|
208
|
+
id: string;
|
|
209
|
+
handle: string;
|
|
210
|
+
title: string;
|
|
211
|
+
description: string;
|
|
212
|
+
path: string;
|
|
213
|
+
seo?: { title: string; description: string };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface ProductCategory {
|
|
217
|
+
id: string;
|
|
218
|
+
name: string;
|
|
219
|
+
handle: string;
|
|
220
|
+
description?: string;
|
|
221
|
+
parentCategoryId?: string;
|
|
222
|
+
productCount?: number;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Shipping & Payment
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
interface ShippingMethod {
|
|
232
|
+
id: string;
|
|
233
|
+
name: string;
|
|
234
|
+
price: Money;
|
|
235
|
+
description?: string;
|
|
236
|
+
estimatedDays?: string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
type PaymentMethodType = 'card' | 'wallet' | 'bank_transfer' | 'buy_now_pay_later' | 'cash_on_delivery' | 'crypto' | 'other';
|
|
240
|
+
|
|
241
|
+
interface PaymentMethod {
|
|
242
|
+
id: string;
|
|
243
|
+
name: string;
|
|
244
|
+
type: PaymentMethodType;
|
|
245
|
+
isEnabled: boolean;
|
|
246
|
+
description?: string;
|
|
247
|
+
logo?: string;
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Region
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
interface Region {
|
|
257
|
+
id: string;
|
|
258
|
+
name: string;
|
|
259
|
+
countryCodes: string[];
|
|
260
|
+
currency: string; // ISO 4217
|
|
261
|
+
taxRate?: number;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Auth Types
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
interface LoginCredentials { email: string; password: string; }
|
|
271
|
+
|
|
272
|
+
interface RegisterData {
|
|
273
|
+
email: string;
|
|
274
|
+
password: string;
|
|
275
|
+
first_name: string;
|
|
276
|
+
last_name: string;
|
|
277
|
+
phone?: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface AuthResponse {
|
|
281
|
+
token?: string;
|
|
282
|
+
customer?: Customer;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface CreateAddressData {
|
|
286
|
+
firstName: string;
|
|
287
|
+
lastName: string;
|
|
288
|
+
company?: string;
|
|
289
|
+
address1: string;
|
|
290
|
+
address2?: string;
|
|
291
|
+
city: string;
|
|
292
|
+
province?: string;
|
|
293
|
+
postalCode: string;
|
|
294
|
+
countryCode: string;
|
|
295
|
+
phone?: string;
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Inventory (Admin)
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
type StockStatus = 'in_stock' | 'out_of_stock' | 'low_stock';
|
|
305
|
+
|
|
306
|
+
interface StockLocation {
|
|
307
|
+
id: string;
|
|
308
|
+
name: string;
|
|
309
|
+
address?: { address1: string; city: string; countryCode: string; postalCode: string };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
interface InventoryLevel {
|
|
313
|
+
locationId: string;
|
|
314
|
+
locationName: string;
|
|
315
|
+
availableQuantity: number;
|
|
316
|
+
reservedQuantity: number;
|
|
317
|
+
stockedQuantity: number;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
interface StockValidation {
|
|
321
|
+
allAvailable: boolean;
|
|
322
|
+
unavailableItems: Array<{
|
|
323
|
+
variantId: string;
|
|
324
|
+
productName: string;
|
|
325
|
+
requestedQuantity: number;
|
|
326
|
+
availableQuantity: number;
|
|
327
|
+
}>;
|
|
328
|
+
}
|
|
329
|
+
```
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @thorprovider/core - Authentication Context
|
|
5
|
+
*
|
|
6
|
+
* Provides authentication state and methods to the application.
|
|
7
|
+
* Uses @thorprovider/adapters for framework-agnostic auth implementation.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react'
|
|
11
|
+
import { commerce } from './commerce'
|
|
12
|
+
import type {
|
|
13
|
+
Customer,
|
|
14
|
+
LoginCredentials,
|
|
15
|
+
RegisterData,
|
|
16
|
+
UpdateCustomerData
|
|
17
|
+
} from '@thorprovider/types'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Authentication context value
|
|
21
|
+
*/
|
|
22
|
+
interface AuthContextValue {
|
|
23
|
+
customer: Customer | null
|
|
24
|
+
loading: boolean
|
|
25
|
+
isInitializing: boolean
|
|
26
|
+
login: (credentials: LoginCredentials) => Promise<void>
|
|
27
|
+
register: (data: RegisterData) => Promise<void>
|
|
28
|
+
logout: () => Promise<void>
|
|
29
|
+
requestPasswordReset: (email: string) => Promise<void>
|
|
30
|
+
resetPassword: (token: string, password: string, metadata?: Record<string, unknown>) => Promise<void>
|
|
31
|
+
updateCustomer: (data: UpdateCustomerData) => Promise<void>
|
|
32
|
+
isAuthenticated: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const AuthContext = createContext<AuthContextValue | undefined>(undefined)
|
|
36
|
+
|
|
37
|
+
export function useAuth() {
|
|
38
|
+
const context = useContext(AuthContext)
|
|
39
|
+
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error('useAuth must be used within AuthProvider')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return context
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface AuthProviderProps {
|
|
48
|
+
children: React.ReactNode
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function AuthProvider({ children }: AuthProviderProps) {
|
|
52
|
+
const [customer, setCustomer] = useState<Customer | null>(null)
|
|
53
|
+
const [loading, setLoading] = useState(false)
|
|
54
|
+
const [isInitializing, setIsInitializing] = useState(true)
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
async function checkAuth() {
|
|
58
|
+
if (!commerce.auth) {
|
|
59
|
+
console.warn('Auth not configured in commerce provider')
|
|
60
|
+
setIsInitializing(false)
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const currentCustomer = await commerce.auth.getCurrentCustomer()
|
|
66
|
+
setCustomer(currentCustomer)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Failed to check auth status:', error)
|
|
69
|
+
} finally {
|
|
70
|
+
setIsInitializing(false)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
checkAuth()
|
|
75
|
+
}, [])
|
|
76
|
+
|
|
77
|
+
const login = useCallback(async (credentials: LoginCredentials) => {
|
|
78
|
+
if (!commerce.auth) {
|
|
79
|
+
throw new Error('Auth not configured')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setLoading(true)
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const response = await commerce.auth.login(credentials)
|
|
86
|
+
|
|
87
|
+
if (response.requiresAction) {
|
|
88
|
+
if (response.redirectUrl) {
|
|
89
|
+
window.location.href = response.redirectUrl
|
|
90
|
+
}
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setCustomer(response.customer ?? null)
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('Login failed:', error)
|
|
97
|
+
throw error
|
|
98
|
+
} finally {
|
|
99
|
+
setLoading(false)
|
|
100
|
+
}
|
|
101
|
+
}, [])
|
|
102
|
+
|
|
103
|
+
const register = useCallback(async (data: RegisterData) => {
|
|
104
|
+
if (!commerce.auth) {
|
|
105
|
+
throw new Error('Auth not configured')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setLoading(true)
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const response = await commerce.auth.register(data)
|
|
112
|
+
setCustomer(response.customer ?? null)
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('Registration failed:', error)
|
|
115
|
+
throw error
|
|
116
|
+
} finally {
|
|
117
|
+
setLoading(false)
|
|
118
|
+
}
|
|
119
|
+
}, [])
|
|
120
|
+
|
|
121
|
+
const logout = useCallback(async () => {
|
|
122
|
+
if (!commerce.auth) {
|
|
123
|
+
throw new Error('Auth not configured')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
setLoading(true)
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await commerce.auth.logout()
|
|
130
|
+
setCustomer(null)
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Logout failed:', error)
|
|
133
|
+
throw error
|
|
134
|
+
} finally {
|
|
135
|
+
setLoading(false)
|
|
136
|
+
}
|
|
137
|
+
}, [])
|
|
138
|
+
|
|
139
|
+
const requestPasswordReset = useCallback(async (email: string) => {
|
|
140
|
+
if (!commerce.auth) {
|
|
141
|
+
throw new Error('Auth not configured')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setLoading(true)
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
await commerce.auth.requestPasswordReset(email)
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error('Password reset request failed:', error)
|
|
150
|
+
throw error
|
|
151
|
+
} finally {
|
|
152
|
+
setLoading(false)
|
|
153
|
+
}
|
|
154
|
+
}, [])
|
|
155
|
+
|
|
156
|
+
const resetPassword = useCallback(async (
|
|
157
|
+
token: string,
|
|
158
|
+
password: string,
|
|
159
|
+
metadata?: Record<string, unknown>
|
|
160
|
+
) => {
|
|
161
|
+
if (!commerce.auth) {
|
|
162
|
+
throw new Error('Auth not configured')
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setLoading(true)
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
await commerce.auth.resetPassword(token, password, metadata)
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error('Password reset failed:', error)
|
|
171
|
+
throw error
|
|
172
|
+
} finally {
|
|
173
|
+
setLoading(false)
|
|
174
|
+
}
|
|
175
|
+
}, [])
|
|
176
|
+
|
|
177
|
+
const updateCustomer = useCallback(async (data: UpdateCustomerData) => {
|
|
178
|
+
if (!commerce.auth) {
|
|
179
|
+
throw new Error('Auth not configured')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
setLoading(true)
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const updatedCustomer = await commerce.auth.updateCustomer(data)
|
|
186
|
+
setCustomer(updatedCustomer ?? null)
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error('Update customer failed:', error)
|
|
189
|
+
throw error
|
|
190
|
+
} finally {
|
|
191
|
+
setLoading(false)
|
|
192
|
+
}
|
|
193
|
+
}, [])
|
|
194
|
+
|
|
195
|
+
const value: AuthContextValue = {
|
|
196
|
+
customer,
|
|
197
|
+
loading,
|
|
198
|
+
isInitializing,
|
|
199
|
+
login,
|
|
200
|
+
register,
|
|
201
|
+
logout,
|
|
202
|
+
requestPasswordReset,
|
|
203
|
+
resetPassword,
|
|
204
|
+
updateCustomer,
|
|
205
|
+
isAuthenticated: customer !== null,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<AuthContext.Provider value={value}>
|
|
210
|
+
{children}
|
|
211
|
+
</AuthContext.Provider>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thorprovider/core - Cart Provider (Next.js Wrapper)
|
|
3
|
+
*
|
|
4
|
+
* Framework-specific wrapper for CartProvider from @thorprovider/providers.
|
|
5
|
+
* Injects commerce, region, and auth dependencies via Dependency Injection.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client';
|
|
9
|
+
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { CartProvider, useCart as useCartBase } from '@thorprovider/providers';
|
|
12
|
+
import { useCommerce } from './commerce-provider';
|
|
13
|
+
import { useRegion } from './region-provider';
|
|
14
|
+
import { useAuth } from './auth-context';
|
|
15
|
+
import type { ReactNode } from 'react';
|
|
16
|
+
import type { CommerceProvider as CommerceProviderType } from '@thorprovider/types';
|
|
17
|
+
import type { CartContextValue as ElementsCartContextValue } from '@thorprovider/providers';
|
|
18
|
+
|
|
19
|
+
export type CartContextValue = ElementsCartContextValue;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* ClientCartProvider (Next.js Wrapper)
|
|
23
|
+
*
|
|
24
|
+
* Wrapper for framework-agnostic CartProvider.
|
|
25
|
+
* Injects Next.js dependencies:
|
|
26
|
+
* - commerce from CommerceProvider context
|
|
27
|
+
* - region from RegionProvider context
|
|
28
|
+
* - auth from AuthProvider context
|
|
29
|
+
* - localStorage/sessionStorage for persistence
|
|
30
|
+
*/
|
|
31
|
+
export function ClientCartProvider({ children }: { children: ReactNode }) {
|
|
32
|
+
const { provider: commerce } = useCommerce();
|
|
33
|
+
const { region } = useRegion();
|
|
34
|
+
const auth = useAuth();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<CartProvider
|
|
38
|
+
commerce={commerce as unknown as CommerceProviderType}
|
|
39
|
+
region={region}
|
|
40
|
+
auth={auth}
|
|
41
|
+
storage={typeof window !== 'undefined' ? localStorage : undefined}
|
|
42
|
+
sessionStorage={typeof window !== 'undefined' ? sessionStorage : undefined}
|
|
43
|
+
debug={process.env.NODE_ENV === 'development'}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</CartProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Typed wrapper to avoid `never` inference in consuming app code.
|
|
51
|
+
export function useCart(): CartContextValue {
|
|
52
|
+
return useCartBase() as CartContextValue;
|
|
53
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thorprovider/core - Commerce Provider (Next.js Wrapper)
|
|
3
|
+
*
|
|
4
|
+
* Framework-specific wrapper for CommerceProvider from @thorprovider/providers.
|
|
5
|
+
* Injects commerce singleton via Dependency Injection pattern.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client';
|
|
9
|
+
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import {
|
|
12
|
+
CommerceProvider,
|
|
13
|
+
useCommerce as useCommerceBase,
|
|
14
|
+
useCapabilities as useCapabilitiesBase,
|
|
15
|
+
} from '@thorprovider/providers';
|
|
16
|
+
import { commerce } from './commerce';
|
|
17
|
+
import type { ReactNode } from 'react';
|
|
18
|
+
import type { BackendCapabilities, CommerceProvider as CommerceProviderType } from '@thorprovider/types';
|
|
19
|
+
|
|
20
|
+
export type CommerceContextValue = {
|
|
21
|
+
provider: CommerceProviderType;
|
|
22
|
+
capabilities: BackendCapabilities;
|
|
23
|
+
backendName: string;
|
|
24
|
+
backendVersion: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* ClientCommerceProvider (Next.js Wrapper)
|
|
29
|
+
*
|
|
30
|
+
* Wrapper for framework-agnostic CommerceProvider.
|
|
31
|
+
* Injects commerce singleton from ./commerce.ts
|
|
32
|
+
*/
|
|
33
|
+
export function ClientCommerceProvider({ children }: { children: ReactNode }) {
|
|
34
|
+
return (
|
|
35
|
+
<CommerceProvider commerce={commerce as unknown as CommerceProviderType}>
|
|
36
|
+
{children}
|
|
37
|
+
</CommerceProvider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Typed wrappers to prevent `never` inference in consuming app code.
|
|
42
|
+
export function useCommerce(): CommerceContextValue {
|
|
43
|
+
return useCommerceBase() as unknown as CommerceContextValue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useCapabilities(): BackendCapabilities {
|
|
47
|
+
return useCapabilitiesBase() as unknown as BackendCapabilities;
|
|
48
|
+
}
|