@spree/next 0.1.1 → 0.2.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 +261 -0
- package/dist/actions/addresses.js +12 -12
- package/dist/actions/addresses.js.map +1 -1
- package/dist/actions/auth.d.ts +3 -3
- package/dist/actions/auth.js +13 -13
- package/dist/actions/auth.js.map +1 -1
- package/dist/actions/cart.js +13 -13
- package/dist/actions/cart.js.map +1 -1
- package/dist/actions/checkout.js +14 -14
- package/dist/actions/checkout.js.map +1 -1
- package/dist/actions/credit-cards.js +9 -9
- package/dist/actions/credit-cards.js.map +1 -1
- package/dist/actions/gift-cards.js +9 -9
- package/dist/actions/gift-cards.js.map +1 -1
- package/dist/actions/orders.js +9 -9
- package/dist/actions/orders.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +5 -5
- package/dist/config.js.map +1 -1
- package/dist/data/countries.js +7 -7
- package/dist/data/countries.js.map +1 -1
- package/dist/data/products.js +8 -8
- package/dist/data/products.js.map +1 -1
- package/dist/data/store.js +6 -6
- package/dist/data/store.js.map +1 -1
- package/dist/data/taxonomies.js +7 -7
- package/dist/data/taxonomies.js.map +1 -1
- package/dist/data/taxons.js +8 -8
- package/dist/data/taxons.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +52 -52
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/package.json +17 -16
- package/LICENSE +0 -58
package/dist/index.js
CHANGED
|
@@ -9,18 +9,18 @@ function initSpreeNext(config) {
|
|
|
9
9
|
_config = config;
|
|
10
10
|
_client = createSpreeClient({
|
|
11
11
|
baseUrl: config.baseUrl,
|
|
12
|
-
|
|
12
|
+
publishableKey: config.publishableKey
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function getClient() {
|
|
16
16
|
if (!_client) {
|
|
17
17
|
const baseUrl = process.env.SPREE_API_URL;
|
|
18
|
-
const
|
|
19
|
-
if (baseUrl &&
|
|
20
|
-
initSpreeNext({ baseUrl,
|
|
18
|
+
const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
|
|
19
|
+
if (baseUrl && publishableKey) {
|
|
20
|
+
initSpreeNext({ baseUrl, publishableKey });
|
|
21
21
|
} else {
|
|
22
22
|
throw new Error(
|
|
23
|
-
"@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and
|
|
23
|
+
"@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -35,19 +35,19 @@ function getConfig() {
|
|
|
35
35
|
|
|
36
36
|
// src/data/products.ts
|
|
37
37
|
async function listProducts(params, options) {
|
|
38
|
-
return getClient().products.list(params, {
|
|
38
|
+
return getClient().store.products.list(params, {
|
|
39
39
|
locale: options?.locale,
|
|
40
40
|
currency: options?.currency
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
async function getProduct(slugOrId, params, options) {
|
|
44
|
-
return getClient().products.get(slugOrId, params, {
|
|
44
|
+
return getClient().store.products.get(slugOrId, params, {
|
|
45
45
|
locale: options?.locale,
|
|
46
46
|
currency: options?.currency
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
async function getProductFilters(params, options) {
|
|
50
|
-
return getClient().products.filters(params, {
|
|
50
|
+
return getClient().store.products.filters(params, {
|
|
51
51
|
locale: options?.locale,
|
|
52
52
|
currency: options?.currency
|
|
53
53
|
});
|
|
@@ -55,19 +55,19 @@ async function getProductFilters(params, options) {
|
|
|
55
55
|
|
|
56
56
|
// src/data/taxons.ts
|
|
57
57
|
async function listTaxons(params, options) {
|
|
58
|
-
return getClient().taxons.list(params, {
|
|
58
|
+
return getClient().store.taxons.list(params, {
|
|
59
59
|
locale: options?.locale,
|
|
60
60
|
currency: options?.currency
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
async function getTaxon(idOrPermalink, params, options) {
|
|
64
|
-
return getClient().taxons.get(idOrPermalink, params, {
|
|
64
|
+
return getClient().store.taxons.get(idOrPermalink, params, {
|
|
65
65
|
locale: options?.locale,
|
|
66
66
|
currency: options?.currency
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
async function listTaxonProducts(taxonId, params, options) {
|
|
70
|
-
return getClient().taxons.products.list(taxonId, params, {
|
|
70
|
+
return getClient().store.taxons.products.list(taxonId, params, {
|
|
71
71
|
locale: options?.locale,
|
|
72
72
|
currency: options?.currency
|
|
73
73
|
});
|
|
@@ -75,13 +75,13 @@ async function listTaxonProducts(taxonId, params, options) {
|
|
|
75
75
|
|
|
76
76
|
// src/data/taxonomies.ts
|
|
77
77
|
async function listTaxonomies(params, options) {
|
|
78
|
-
return getClient().taxonomies.list(params, {
|
|
78
|
+
return getClient().store.taxonomies.list(params, {
|
|
79
79
|
locale: options?.locale,
|
|
80
80
|
currency: options?.currency
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
async function getTaxonomy(id, params, options) {
|
|
84
|
-
return getClient().taxonomies.get(id, params, {
|
|
84
|
+
return getClient().store.taxonomies.get(id, params, {
|
|
85
85
|
locale: options?.locale,
|
|
86
86
|
currency: options?.currency
|
|
87
87
|
});
|
|
@@ -89,7 +89,7 @@ async function getTaxonomy(id, params, options) {
|
|
|
89
89
|
|
|
90
90
|
// src/data/store.ts
|
|
91
91
|
async function getStore(options) {
|
|
92
|
-
return getClient().store.get({
|
|
92
|
+
return getClient().store.store.get({
|
|
93
93
|
locale: options?.locale,
|
|
94
94
|
currency: options?.currency
|
|
95
95
|
});
|
|
@@ -97,13 +97,13 @@ async function getStore(options) {
|
|
|
97
97
|
|
|
98
98
|
// src/data/countries.ts
|
|
99
99
|
async function listCountries(options) {
|
|
100
|
-
return getClient().countries.list({
|
|
100
|
+
return getClient().store.countries.list({
|
|
101
101
|
locale: options?.locale,
|
|
102
102
|
currency: options?.currency
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
async function getCountry(iso, options) {
|
|
106
|
-
return getClient().countries.get(iso, {
|
|
106
|
+
return getClient().store.countries.get(iso, {
|
|
107
107
|
locale: options?.locale,
|
|
108
108
|
currency: options?.currency
|
|
109
109
|
});
|
|
@@ -175,7 +175,7 @@ async function getCart() {
|
|
|
175
175
|
const token = await getAccessToken();
|
|
176
176
|
if (!orderToken && !token) return null;
|
|
177
177
|
try {
|
|
178
|
-
return await getClient().cart.get({ orderToken, token });
|
|
178
|
+
return await getClient().store.cart.get({ orderToken, token });
|
|
179
179
|
} catch {
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
@@ -184,7 +184,7 @@ async function getOrCreateCart() {
|
|
|
184
184
|
const existing = await getCart();
|
|
185
185
|
if (existing) return existing;
|
|
186
186
|
const token = await getAccessToken();
|
|
187
|
-
const cart = await getClient().cart.create(token ? { token } : void 0);
|
|
187
|
+
const cart = await getClient().store.cart.create(token ? { token } : void 0);
|
|
188
188
|
if (cart.token) {
|
|
189
189
|
await setCartToken(cart.token);
|
|
190
190
|
}
|
|
@@ -195,7 +195,7 @@ async function addItem(variantId, quantity = 1) {
|
|
|
195
195
|
const cart = await getOrCreateCart();
|
|
196
196
|
const orderToken = cart.token;
|
|
197
197
|
const token = await getAccessToken();
|
|
198
|
-
const lineItem = await getClient().orders.lineItems.create(
|
|
198
|
+
const lineItem = await getClient().store.orders.lineItems.create(
|
|
199
199
|
cart.id,
|
|
200
200
|
{ variant_id: variantId, quantity },
|
|
201
201
|
{ orderToken, token }
|
|
@@ -207,8 +207,8 @@ async function updateItem(lineItemId, quantity) {
|
|
|
207
207
|
const orderToken = await getCartToken();
|
|
208
208
|
const token = await getAccessToken();
|
|
209
209
|
if (!orderToken && !token) throw new Error("No cart found");
|
|
210
|
-
const cart = await getClient().cart.get({ orderToken, token });
|
|
211
|
-
const lineItem = await getClient().orders.lineItems.update(
|
|
210
|
+
const cart = await getClient().store.cart.get({ orderToken, token });
|
|
211
|
+
const lineItem = await getClient().store.orders.lineItems.update(
|
|
212
212
|
cart.id,
|
|
213
213
|
lineItemId,
|
|
214
214
|
{ quantity },
|
|
@@ -221,8 +221,8 @@ async function removeItem(lineItemId) {
|
|
|
221
221
|
const orderToken = await getCartToken();
|
|
222
222
|
const token = await getAccessToken();
|
|
223
223
|
if (!orderToken && !token) throw new Error("No cart found");
|
|
224
|
-
const cart = await getClient().cart.get({ orderToken, token });
|
|
225
|
-
await getClient().orders.lineItems.delete(cart.id, lineItemId, {
|
|
224
|
+
const cart = await getClient().store.cart.get({ orderToken, token });
|
|
225
|
+
await getClient().store.orders.lineItems.delete(cart.id, lineItemId, {
|
|
226
226
|
orderToken,
|
|
227
227
|
token
|
|
228
228
|
});
|
|
@@ -237,7 +237,7 @@ async function associateCart() {
|
|
|
237
237
|
const token = await getAccessToken();
|
|
238
238
|
if (!orderToken || !token) return null;
|
|
239
239
|
try {
|
|
240
|
-
const result = await getClient().cart.associate({ orderToken, token });
|
|
240
|
+
const result = await getClient().store.cart.associate({ orderToken, token });
|
|
241
241
|
revalidateTag("cart");
|
|
242
242
|
return result;
|
|
243
243
|
} catch {
|
|
@@ -253,7 +253,7 @@ async function getCheckoutOptions() {
|
|
|
253
253
|
}
|
|
254
254
|
async function getCheckout(orderId) {
|
|
255
255
|
const options = await getCheckoutOptions();
|
|
256
|
-
return getClient().orders.get(
|
|
256
|
+
return getClient().store.orders.get(
|
|
257
257
|
orderId,
|
|
258
258
|
{ includes: "line_items,shipments,ship_address,bill_address" },
|
|
259
259
|
options
|
|
@@ -261,29 +261,29 @@ async function getCheckout(orderId) {
|
|
|
261
261
|
}
|
|
262
262
|
async function updateAddresses(orderId, params) {
|
|
263
263
|
const options = await getCheckoutOptions();
|
|
264
|
-
const result = await getClient().orders.update(orderId, params, options);
|
|
264
|
+
const result = await getClient().store.orders.update(orderId, params, options);
|
|
265
265
|
revalidateTag("checkout");
|
|
266
266
|
return result;
|
|
267
267
|
}
|
|
268
268
|
async function advance(orderId) {
|
|
269
269
|
const options = await getCheckoutOptions();
|
|
270
|
-
const result = await getClient().orders.advance(orderId, options);
|
|
270
|
+
const result = await getClient().store.orders.advance(orderId, options);
|
|
271
271
|
revalidateTag("checkout");
|
|
272
272
|
return result;
|
|
273
273
|
}
|
|
274
274
|
async function next(orderId) {
|
|
275
275
|
const options = await getCheckoutOptions();
|
|
276
|
-
const result = await getClient().orders.next(orderId, options);
|
|
276
|
+
const result = await getClient().store.orders.next(orderId, options);
|
|
277
277
|
revalidateTag("checkout");
|
|
278
278
|
return result;
|
|
279
279
|
}
|
|
280
280
|
async function getShipments(orderId) {
|
|
281
281
|
const options = await getCheckoutOptions();
|
|
282
|
-
return getClient().orders.shipments.list(orderId, options);
|
|
282
|
+
return getClient().store.orders.shipments.list(orderId, options);
|
|
283
283
|
}
|
|
284
284
|
async function selectShippingRate(orderId, shipmentId, shippingRateId) {
|
|
285
285
|
const options = await getCheckoutOptions();
|
|
286
|
-
const result = await getClient().orders.shipments.update(
|
|
286
|
+
const result = await getClient().store.orders.shipments.update(
|
|
287
287
|
orderId,
|
|
288
288
|
shipmentId,
|
|
289
289
|
{ selected_shipping_rate_id: shippingRateId },
|
|
@@ -294,21 +294,21 @@ async function selectShippingRate(orderId, shipmentId, shippingRateId) {
|
|
|
294
294
|
}
|
|
295
295
|
async function applyCoupon(orderId, code) {
|
|
296
296
|
const options = await getCheckoutOptions();
|
|
297
|
-
const result = await getClient().orders.couponCodes.apply(orderId, code, options);
|
|
297
|
+
const result = await getClient().store.orders.couponCodes.apply(orderId, code, options);
|
|
298
298
|
revalidateTag("checkout");
|
|
299
299
|
revalidateTag("cart");
|
|
300
300
|
return result;
|
|
301
301
|
}
|
|
302
302
|
async function removeCoupon(orderId, promotionId) {
|
|
303
303
|
const options = await getCheckoutOptions();
|
|
304
|
-
const result = await getClient().orders.couponCodes.remove(orderId, promotionId, options);
|
|
304
|
+
const result = await getClient().store.orders.couponCodes.remove(orderId, promotionId, options);
|
|
305
305
|
revalidateTag("checkout");
|
|
306
306
|
revalidateTag("cart");
|
|
307
307
|
return result;
|
|
308
308
|
}
|
|
309
309
|
async function complete(orderId) {
|
|
310
310
|
const options = await getCheckoutOptions();
|
|
311
|
-
const result = await getClient().orders.complete(orderId, options);
|
|
311
|
+
const result = await getClient().store.orders.complete(orderId, options);
|
|
312
312
|
revalidateTag("checkout");
|
|
313
313
|
revalidateTag("cart");
|
|
314
314
|
return result;
|
|
@@ -324,7 +324,7 @@ async function getAuthOptions() {
|
|
|
324
324
|
const now = Math.floor(Date.now() / 1e3);
|
|
325
325
|
if (exp && exp - now < 3600) {
|
|
326
326
|
try {
|
|
327
|
-
const refreshed = await getClient().auth.refresh({ token });
|
|
327
|
+
const refreshed = await getClient().store.auth.refresh({ token });
|
|
328
328
|
await setAccessToken(refreshed.token);
|
|
329
329
|
return { token: refreshed.token };
|
|
330
330
|
} catch {
|
|
@@ -344,7 +344,7 @@ async function withAuthRefresh(fn) {
|
|
|
344
344
|
} catch (error) {
|
|
345
345
|
if (error instanceof SpreeError && error.status === 401) {
|
|
346
346
|
try {
|
|
347
|
-
const refreshed = await getClient().auth.refresh({ token: options.token });
|
|
347
|
+
const refreshed = await getClient().store.auth.refresh({ token: options.token });
|
|
348
348
|
await setAccessToken(refreshed.token);
|
|
349
349
|
return await fn({ token: refreshed.token });
|
|
350
350
|
} catch {
|
|
@@ -359,12 +359,12 @@ async function withAuthRefresh(fn) {
|
|
|
359
359
|
// src/actions/auth.ts
|
|
360
360
|
async function login(email, password) {
|
|
361
361
|
try {
|
|
362
|
-
const result = await getClient().auth.login({ email, password });
|
|
362
|
+
const result = await getClient().store.auth.login({ email, password });
|
|
363
363
|
await setAccessToken(result.token);
|
|
364
364
|
const cartToken = await getCartToken();
|
|
365
365
|
if (cartToken) {
|
|
366
366
|
try {
|
|
367
|
-
await getClient().cart.associate({
|
|
367
|
+
await getClient().store.cart.associate({
|
|
368
368
|
token: result.token,
|
|
369
369
|
orderToken: cartToken
|
|
370
370
|
});
|
|
@@ -383,7 +383,7 @@ async function login(email, password) {
|
|
|
383
383
|
}
|
|
384
384
|
async function register(email, password, passwordConfirmation) {
|
|
385
385
|
try {
|
|
386
|
-
const result = await getClient().auth.register({
|
|
386
|
+
const result = await getClient().store.auth.register({
|
|
387
387
|
email,
|
|
388
388
|
password,
|
|
389
389
|
password_confirmation: passwordConfirmation
|
|
@@ -392,7 +392,7 @@ async function register(email, password, passwordConfirmation) {
|
|
|
392
392
|
const cartToken = await getCartToken();
|
|
393
393
|
if (cartToken) {
|
|
394
394
|
try {
|
|
395
|
-
await getClient().cart.associate({
|
|
395
|
+
await getClient().store.cart.associate({
|
|
396
396
|
token: result.token,
|
|
397
397
|
orderToken: cartToken
|
|
398
398
|
});
|
|
@@ -421,7 +421,7 @@ async function getCustomer() {
|
|
|
421
421
|
if (!token) return null;
|
|
422
422
|
try {
|
|
423
423
|
return await withAuthRefresh(async (options) => {
|
|
424
|
-
return getClient().customer.get(options);
|
|
424
|
+
return getClient().store.customer.get(options);
|
|
425
425
|
});
|
|
426
426
|
} catch {
|
|
427
427
|
await clearAccessToken();
|
|
@@ -430,38 +430,38 @@ async function getCustomer() {
|
|
|
430
430
|
}
|
|
431
431
|
async function updateCustomer(data) {
|
|
432
432
|
const result = await withAuthRefresh(async (options) => {
|
|
433
|
-
return getClient().customer.update(data, options);
|
|
433
|
+
return getClient().store.customer.update(data, options);
|
|
434
434
|
});
|
|
435
435
|
revalidateTag("customer");
|
|
436
436
|
return result;
|
|
437
437
|
}
|
|
438
438
|
async function listAddresses() {
|
|
439
439
|
return withAuthRefresh(async (options) => {
|
|
440
|
-
return getClient().customer.addresses.list(void 0, options);
|
|
440
|
+
return getClient().store.customer.addresses.list(void 0, options);
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
443
|
async function getAddress(id) {
|
|
444
444
|
return withAuthRefresh(async (options) => {
|
|
445
|
-
return getClient().customer.addresses.get(id, options);
|
|
445
|
+
return getClient().store.customer.addresses.get(id, options);
|
|
446
446
|
});
|
|
447
447
|
}
|
|
448
448
|
async function createAddress(params) {
|
|
449
449
|
const result = await withAuthRefresh(async (options) => {
|
|
450
|
-
return getClient().customer.addresses.create(params, options);
|
|
450
|
+
return getClient().store.customer.addresses.create(params, options);
|
|
451
451
|
});
|
|
452
452
|
revalidateTag("addresses");
|
|
453
453
|
return result;
|
|
454
454
|
}
|
|
455
455
|
async function updateAddress(id, params) {
|
|
456
456
|
const result = await withAuthRefresh(async (options) => {
|
|
457
|
-
return getClient().customer.addresses.update(id, params, options);
|
|
457
|
+
return getClient().store.customer.addresses.update(id, params, options);
|
|
458
458
|
});
|
|
459
459
|
revalidateTag("addresses");
|
|
460
460
|
return result;
|
|
461
461
|
}
|
|
462
462
|
async function deleteAddress(id) {
|
|
463
463
|
await withAuthRefresh(async (options) => {
|
|
464
|
-
return getClient().customer.addresses.delete(id, options);
|
|
464
|
+
return getClient().store.customer.addresses.delete(id, options);
|
|
465
465
|
});
|
|
466
466
|
revalidateTag("addresses");
|
|
467
467
|
}
|
|
@@ -469,22 +469,22 @@ async function deleteAddress(id) {
|
|
|
469
469
|
// src/actions/orders.ts
|
|
470
470
|
async function listOrders(params) {
|
|
471
471
|
return withAuthRefresh(async (options) => {
|
|
472
|
-
return getClient().orders.list(params, options);
|
|
472
|
+
return getClient().store.orders.list(params, options);
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
475
|
async function getOrder(idOrNumber, params) {
|
|
476
476
|
return withAuthRefresh(async (options) => {
|
|
477
|
-
return getClient().orders.get(idOrNumber, params, options);
|
|
477
|
+
return getClient().store.orders.get(idOrNumber, params, options);
|
|
478
478
|
});
|
|
479
479
|
}
|
|
480
480
|
async function listCreditCards() {
|
|
481
481
|
return withAuthRefresh(async (options) => {
|
|
482
|
-
return getClient().customer.creditCards.list(void 0, options);
|
|
482
|
+
return getClient().store.customer.creditCards.list(void 0, options);
|
|
483
483
|
});
|
|
484
484
|
}
|
|
485
485
|
async function deleteCreditCard(id) {
|
|
486
486
|
await withAuthRefresh(async (options) => {
|
|
487
|
-
return getClient().customer.creditCards.delete(id, options);
|
|
487
|
+
return getClient().store.customer.creditCards.delete(id, options);
|
|
488
488
|
});
|
|
489
489
|
revalidateTag("credit-cards");
|
|
490
490
|
}
|
|
@@ -492,12 +492,12 @@ async function deleteCreditCard(id) {
|
|
|
492
492
|
// src/actions/gift-cards.ts
|
|
493
493
|
async function listGiftCards() {
|
|
494
494
|
return withAuthRefresh(async (options) => {
|
|
495
|
-
return getClient().customer.giftCards.list(void 0, options);
|
|
495
|
+
return getClient().store.customer.giftCards.list(void 0, options);
|
|
496
496
|
});
|
|
497
497
|
}
|
|
498
498
|
async function getGiftCard(id) {
|
|
499
499
|
return withAuthRefresh(async (options) => {
|
|
500
|
-
return getClient().customer.giftCards.get(id, options);
|
|
500
|
+
return getClient().store.customer.giftCards.get(id, options);
|
|
501
501
|
});
|
|
502
502
|
}
|
|
503
503
|
|
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,I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Y;AACxC,IAAA,OAAO,WAAU,CAAE,QAAA,CAAS,WAAA,CAAY,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,EACjE,CAAC,CAAA;AACH;AAKA,eAAsB,iBAAiB,EAAA,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,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA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AAA,OAAO,WAAU,CAAE,KAAA,CAAM,OAAO,GAAA,CAAI,UAAA,EAAY,QAAQ,OAAO,CAAA;AAAA,EACjE,CAAC,CAAA;AACH;ACjBA,eAAsB,eAAA,GAAwD;AAC5E,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,WAAA,CAAY,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,EACvE,CAAC,CAAA;AACH;AAKA,eAAsB,iBAAiB,EAAA,EAA2B;AAChE,EAAA,MAAM,eAAA,CAAgB,OAAO,OAAA,KAAY;AACvC,IAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,WAAA,CAAY,MAAA,CAAO,IAAI,OAAO,CAAA;AAAA,EAClE,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,KAAA,CAAM,SAAS,SAAA,CAAU,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,EACrE,CAAC,CAAA;AACH;AAKA,eAAsB,YAAY,EAAA,EAAoC;AACpE,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,SAAA,CAAU,GAAA,CAAI,IAAI,OAAO,CAAA;AAAA,EAC7D,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_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\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 publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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.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().store.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().store.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().store.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().store.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().store.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().store.cart.get({ orderToken, token });\n\n const lineItem = await getClient().store.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().store.cart.get({ orderToken, token });\n\n await getClient().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.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().store.customer.giftCards.get(id, options);\n });\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
interface SpreeNextConfig {
|
|
2
2
|
/** Base URL of the Spree API (e.g., 'https://api.mystore.com') */
|
|
3
3
|
baseUrl: string;
|
|
4
|
-
/** Publishable API key for
|
|
5
|
-
|
|
4
|
+
/** Publishable API key for Store API access */
|
|
5
|
+
publishableKey: string;
|
|
6
6
|
/** Cookie name for the cart order token (default: '_spree_cart_token') */
|
|
7
7
|
cartCookieName?: string;
|
|
8
8
|
/** Cookie name for the JWT access token (default: '_spree_jwt') */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spree/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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.
|
|
58
|
+
"@spree/sdk": ">=0.2.0",
|
|
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
|
+
}
|