@spree/sdk 0.6.8 → 0.7.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 +118 -120
- package/dist/index.cjs +51 -242
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -124
- package/dist/index.d.ts +87 -124
- package/dist/index.js +39 -230
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.cts +129 -418
- package/dist/types/index.d.ts +129 -418
- package/dist/zod/index.cjs +311 -550
- package/dist/zod/index.cjs.map +1 -1
- package/dist/zod/index.d.cts +120 -713
- package/dist/zod/index.d.ts +120 -713
- package/dist/zod/index.js +257 -489
- package/dist/zod/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -15,53 +15,52 @@ pnpm add @spree/sdk
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import {
|
|
18
|
+
import { createClient } from '@spree/sdk';
|
|
19
19
|
|
|
20
20
|
// Initialize the client
|
|
21
|
-
const client =
|
|
21
|
+
const client = createClient({
|
|
22
22
|
baseUrl: 'https://api.mystore.com',
|
|
23
|
-
publishableKey: 'spree_pk_xxx',
|
|
24
|
-
secretKey: 'spree_sk_xxx', // Admin API (optional)
|
|
23
|
+
publishableKey: 'spree_pk_xxx',
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
// Browse products (Store API)
|
|
28
|
-
const products = await client.
|
|
27
|
+
const products = await client.products.list({
|
|
29
28
|
limit: 10,
|
|
30
29
|
expand: ['variants', 'images'],
|
|
31
30
|
});
|
|
32
31
|
|
|
33
32
|
// Get a single product
|
|
34
|
-
const product = await client.
|
|
33
|
+
const product = await client.products.get('spree-tote');
|
|
35
34
|
|
|
36
35
|
// Authentication
|
|
37
|
-
const { token, user } = await client.
|
|
36
|
+
const { token, user } = await client.auth.login({
|
|
38
37
|
email: 'customer@example.com',
|
|
39
38
|
password: 'password123',
|
|
40
39
|
});
|
|
41
40
|
|
|
42
41
|
// Create a cart and add items
|
|
43
|
-
const cart = await client.
|
|
44
|
-
await client.
|
|
42
|
+
const cart = await client.cart.create();
|
|
43
|
+
await client.orders.lineItems.create(cart.id, {
|
|
45
44
|
variant_id: 'var_abc123',
|
|
46
45
|
quantity: 2,
|
|
47
46
|
}, { orderToken: cart.token });
|
|
48
47
|
|
|
49
48
|
// Checkout flow
|
|
50
|
-
await client.
|
|
51
|
-
await client.
|
|
49
|
+
await client.orders.next(cart.id, { orderToken: cart.token });
|
|
50
|
+
await client.orders.complete(cart.id, { orderToken: cart.token });
|
|
52
51
|
```
|
|
53
52
|
|
|
54
53
|
## Client Architecture
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
All Store API resources are available directly on the client:
|
|
57
56
|
|
|
58
57
|
```typescript
|
|
59
|
-
client.
|
|
60
|
-
client.
|
|
58
|
+
client.products.list() // Products
|
|
59
|
+
client.cart.create() // Cart
|
|
60
|
+
client.orders.complete(id, opt) // Checkout
|
|
61
|
+
client.customer.get(opt) // Account
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
All Store API endpoints live under `client.store.*`. The Admin API namespace is ready for future endpoints.
|
|
64
|
-
|
|
65
64
|
## Authentication
|
|
66
65
|
|
|
67
66
|
The SDK supports multiple authentication modes:
|
|
@@ -69,35 +68,35 @@ The SDK supports multiple authentication modes:
|
|
|
69
68
|
### 1. Publishable Key Only (Guest/Public Access)
|
|
70
69
|
|
|
71
70
|
```typescript
|
|
72
|
-
const client =
|
|
71
|
+
const client = createClient({
|
|
73
72
|
baseUrl: 'https://api.mystore.com',
|
|
74
73
|
publishableKey: 'spree_pk_xxx',
|
|
75
74
|
});
|
|
76
75
|
|
|
77
76
|
// Public endpoints work without user authentication
|
|
78
|
-
const products = await client.
|
|
77
|
+
const products = await client.products.list();
|
|
79
78
|
```
|
|
80
79
|
|
|
81
80
|
### 2. Publishable Key + JWT (Authenticated Customer)
|
|
82
81
|
|
|
83
82
|
```typescript
|
|
84
83
|
// Login to get tokens
|
|
85
|
-
const { token, user } = await client.
|
|
84
|
+
const { token, user } = await client.auth.login({
|
|
86
85
|
email: 'customer@example.com',
|
|
87
86
|
password: 'password123',
|
|
88
87
|
});
|
|
89
88
|
|
|
90
89
|
// Use token for authenticated requests
|
|
91
|
-
const orders = await client.
|
|
90
|
+
const orders = await client.orders.list({}, { token });
|
|
92
91
|
|
|
93
92
|
// Refresh token when needed
|
|
94
|
-
const newTokens = await client.
|
|
93
|
+
const newTokens = await client.auth.refresh({ token });
|
|
95
94
|
```
|
|
96
95
|
|
|
97
96
|
### 3. Register New Customer
|
|
98
97
|
|
|
99
98
|
```typescript
|
|
100
|
-
const { token, user } = await client.
|
|
99
|
+
const { token, user } = await client.auth.register({
|
|
101
100
|
email: 'new@example.com',
|
|
102
101
|
password: 'password123',
|
|
103
102
|
password_confirmation: 'password123',
|
|
@@ -112,24 +111,24 @@ For guest checkout, use the `token` (or `order_token`) returned when creating a
|
|
|
112
111
|
|
|
113
112
|
```typescript
|
|
114
113
|
// Create a cart (guest)
|
|
115
|
-
const cart = await client.
|
|
114
|
+
const cart = await client.cart.create();
|
|
116
115
|
|
|
117
116
|
// Use orderToken for all cart operations
|
|
118
117
|
const options = { orderToken: cart.token };
|
|
119
118
|
|
|
120
119
|
// Add items
|
|
121
|
-
await client.
|
|
120
|
+
await client.orders.lineItems.create(cart.id, {
|
|
122
121
|
variant_id: 'var_abc123',
|
|
123
122
|
quantity: 1,
|
|
124
123
|
}, options);
|
|
125
124
|
|
|
126
125
|
// Update order with email
|
|
127
|
-
await client.
|
|
126
|
+
await client.orders.update(cart.id, {
|
|
128
127
|
email: 'guest@example.com',
|
|
129
128
|
}, options);
|
|
130
129
|
|
|
131
130
|
// Complete checkout
|
|
132
|
-
await client.
|
|
131
|
+
await client.orders.complete(cart.id, options);
|
|
133
132
|
```
|
|
134
133
|
|
|
135
134
|
## API Reference
|
|
@@ -138,14 +137,14 @@ await client.store.orders.complete(cart.id, options);
|
|
|
138
137
|
|
|
139
138
|
```typescript
|
|
140
139
|
// Get current store information
|
|
141
|
-
const store = await client.store.
|
|
140
|
+
const store = await client.store.get();
|
|
142
141
|
```
|
|
143
142
|
|
|
144
143
|
### Products
|
|
145
144
|
|
|
146
145
|
```typescript
|
|
147
146
|
// List products with filtering
|
|
148
|
-
const products = await client.
|
|
147
|
+
const products = await client.products.list({
|
|
149
148
|
page: 1,
|
|
150
149
|
limit: 25,
|
|
151
150
|
name_cont: 'shirt',
|
|
@@ -154,12 +153,12 @@ const products = await client.store.products.list({
|
|
|
154
153
|
});
|
|
155
154
|
|
|
156
155
|
// Get single product by ID or slug
|
|
157
|
-
const product = await client.
|
|
156
|
+
const product = await client.products.get('spree-tote', {
|
|
158
157
|
expand: ['variants', 'images'],
|
|
159
158
|
});
|
|
160
159
|
|
|
161
160
|
// Get available filters (price range, availability, options, taxons)
|
|
162
|
-
const filters = await client.
|
|
161
|
+
const filters = await client.products.filters({
|
|
163
162
|
taxon_id: 'txn_abc123', // Optional: scope filters to a taxon
|
|
164
163
|
});
|
|
165
164
|
```
|
|
@@ -168,28 +167,28 @@ const filters = await client.store.products.filters({
|
|
|
168
167
|
|
|
169
168
|
```typescript
|
|
170
169
|
// List taxonomies
|
|
171
|
-
const taxonomies = await client.
|
|
170
|
+
const taxonomies = await client.taxonomies.list({
|
|
172
171
|
expand: ['taxons'],
|
|
173
172
|
});
|
|
174
173
|
|
|
175
174
|
// Get taxonomy with taxons
|
|
176
|
-
const categories = await client.
|
|
175
|
+
const categories = await client.taxonomies.get('tax_123', {
|
|
177
176
|
expand: ['root', 'taxons'],
|
|
178
177
|
});
|
|
179
178
|
|
|
180
179
|
// List taxons with filtering
|
|
181
|
-
const taxons = await client.
|
|
180
|
+
const taxons = await client.taxons.list({
|
|
182
181
|
depth_eq: 1, // Top-level categories only
|
|
183
182
|
taxonomy_id_eq: '123', // Filter by taxonomy
|
|
184
183
|
});
|
|
185
184
|
|
|
186
185
|
// Get single taxon by ID or permalink
|
|
187
|
-
const taxon = await client.
|
|
186
|
+
const taxon = await client.taxons.get('categories/clothing', {
|
|
188
187
|
expand: ['ancestors', 'children'], // For breadcrumbs and subcategories
|
|
189
188
|
});
|
|
190
189
|
|
|
191
190
|
// List products in a category
|
|
192
|
-
const categoryProducts = await client.
|
|
191
|
+
const categoryProducts = await client.taxons.products.list('categories/clothing', {
|
|
193
192
|
page: 1,
|
|
194
193
|
limit: 12,
|
|
195
194
|
expand: ['images', 'default_variant'],
|
|
@@ -200,14 +199,14 @@ const categoryProducts = await client.store.taxons.products.list('categories/clo
|
|
|
200
199
|
|
|
201
200
|
```typescript
|
|
202
201
|
// Get current cart
|
|
203
|
-
const cart = await client.
|
|
202
|
+
const cart = await client.cart.get({ orderToken: 'xxx' });
|
|
204
203
|
|
|
205
204
|
// Create a new cart
|
|
206
|
-
const newCart = await client.
|
|
205
|
+
const newCart = await client.cart.create();
|
|
207
206
|
|
|
208
207
|
// Associate guest cart with authenticated user
|
|
209
208
|
// (after user logs in, merge their guest cart with their account)
|
|
210
|
-
await client.
|
|
209
|
+
await client.cart.associate({
|
|
211
210
|
token: jwtToken, // User's JWT token
|
|
212
211
|
orderToken: cart.token, // Guest cart token
|
|
213
212
|
});
|
|
@@ -217,19 +216,19 @@ await client.store.cart.associate({
|
|
|
217
216
|
|
|
218
217
|
```typescript
|
|
219
218
|
// List orders for authenticated customer
|
|
220
|
-
const orders = await client.
|
|
219
|
+
const orders = await client.orders.list({}, { token });
|
|
221
220
|
|
|
222
221
|
// Create a new order (cart)
|
|
223
|
-
const cart = await client.
|
|
222
|
+
const cart = await client.orders.create();
|
|
224
223
|
const options = { orderToken: cart.order_token };
|
|
225
224
|
|
|
226
225
|
// Get order by ID or number
|
|
227
|
-
const order = await client.
|
|
226
|
+
const order = await client.orders.get('R123456789', {
|
|
228
227
|
expand: ['line_items', 'shipments'],
|
|
229
228
|
}, options);
|
|
230
229
|
|
|
231
230
|
// Update order (email, addresses)
|
|
232
|
-
await client.
|
|
231
|
+
await client.orders.update(cart.id, {
|
|
233
232
|
email: 'customer@example.com',
|
|
234
233
|
ship_address: {
|
|
235
234
|
firstname: 'John',
|
|
@@ -245,9 +244,9 @@ await client.store.orders.update(cart.id, {
|
|
|
245
244
|
}, options);
|
|
246
245
|
|
|
247
246
|
// Checkout flow
|
|
248
|
-
await client.
|
|
249
|
-
await client.
|
|
250
|
-
await client.
|
|
247
|
+
await client.orders.next(cart.id, options); // Move to next step
|
|
248
|
+
await client.orders.advance(cart.id, options); // Advance through all steps
|
|
249
|
+
await client.orders.complete(cart.id, options); // Complete the order
|
|
251
250
|
```
|
|
252
251
|
|
|
253
252
|
### Line Items
|
|
@@ -256,18 +255,18 @@ await client.store.orders.complete(cart.id, options); // Complete the order
|
|
|
256
255
|
const options = { orderToken: cart.token };
|
|
257
256
|
|
|
258
257
|
// Add item
|
|
259
|
-
await client.
|
|
258
|
+
await client.orders.lineItems.create(cart.id, {
|
|
260
259
|
variant_id: 'var_123',
|
|
261
260
|
quantity: 2,
|
|
262
261
|
}, options);
|
|
263
262
|
|
|
264
263
|
// Update item quantity
|
|
265
|
-
await client.
|
|
264
|
+
await client.orders.lineItems.update(cart.id, lineItemId, {
|
|
266
265
|
quantity: 3,
|
|
267
266
|
}, options);
|
|
268
267
|
|
|
269
268
|
// Remove item
|
|
270
|
-
await client.
|
|
269
|
+
await client.orders.lineItems.delete(cart.id, lineItemId, options);
|
|
271
270
|
```
|
|
272
271
|
|
|
273
272
|
### Coupon Codes
|
|
@@ -276,10 +275,10 @@ await client.store.orders.lineItems.delete(cart.id, lineItemId, options);
|
|
|
276
275
|
const options = { orderToken: cart.token };
|
|
277
276
|
|
|
278
277
|
// Apply a coupon code
|
|
279
|
-
await client.
|
|
278
|
+
await client.orders.couponCodes.apply(cart.id, 'SAVE20', options);
|
|
280
279
|
|
|
281
280
|
// Remove a coupon code
|
|
282
|
-
await client.
|
|
281
|
+
await client.orders.couponCodes.remove(cart.id, 'promo_xxx', options);
|
|
283
282
|
```
|
|
284
283
|
|
|
285
284
|
### Store Credits
|
|
@@ -288,13 +287,13 @@ await client.store.orders.couponCodes.remove(cart.id, 'promo_xxx', options);
|
|
|
288
287
|
const options = { orderToken: cart.token };
|
|
289
288
|
|
|
290
289
|
// Apply store credit to order (applies maximum available by default)
|
|
291
|
-
await client.
|
|
290
|
+
await client.orders.addStoreCredit(cart.id, undefined, options);
|
|
292
291
|
|
|
293
292
|
// Apply specific amount of store credit
|
|
294
|
-
await client.
|
|
293
|
+
await client.orders.addStoreCredit(cart.id, 25.00, options);
|
|
295
294
|
|
|
296
295
|
// Remove store credit from order
|
|
297
|
-
await client.
|
|
296
|
+
await client.orders.removeStoreCredit(cart.id, options);
|
|
298
297
|
```
|
|
299
298
|
|
|
300
299
|
### Shipments
|
|
@@ -303,10 +302,10 @@ await client.store.orders.removeStoreCredit(cart.id, options);
|
|
|
303
302
|
const options = { orderToken: cart.token };
|
|
304
303
|
|
|
305
304
|
// List shipments for an order
|
|
306
|
-
const shipments = await client.
|
|
305
|
+
const shipments = await client.orders.shipments.list(cart.id, options);
|
|
307
306
|
|
|
308
307
|
// Select a shipping rate
|
|
309
|
-
await client.
|
|
308
|
+
await client.orders.shipments.update(cart.id, shipmentId, {
|
|
310
309
|
selected_shipping_rate_id: 'rate_xxx',
|
|
311
310
|
}, options);
|
|
312
311
|
```
|
|
@@ -317,13 +316,13 @@ await client.store.orders.shipments.update(cart.id, shipmentId, {
|
|
|
317
316
|
const options = { orderToken: cart.token };
|
|
318
317
|
|
|
319
318
|
// Get available payment methods for an order
|
|
320
|
-
const methods = await client.
|
|
319
|
+
const methods = await client.orders.paymentMethods.list(cart.id, options);
|
|
321
320
|
|
|
322
321
|
// List payments on an order
|
|
323
|
-
const payments = await client.
|
|
322
|
+
const payments = await client.orders.payments.list(cart.id, options);
|
|
324
323
|
|
|
325
324
|
// Get a specific payment
|
|
326
|
-
const payment = await client.
|
|
325
|
+
const payment = await client.orders.payments.get(cart.id, paymentId, options);
|
|
327
326
|
```
|
|
328
327
|
|
|
329
328
|
### Payment Sessions
|
|
@@ -334,7 +333,7 @@ Payment sessions provide a unified, provider-agnostic interface for payment proc
|
|
|
334
333
|
const options = { orderToken: cart.token };
|
|
335
334
|
|
|
336
335
|
// Create a payment session (initializes a session with the payment gateway)
|
|
337
|
-
const session = await client.
|
|
336
|
+
const session = await client.orders.paymentSessions.create(cart.id, {
|
|
338
337
|
payment_method_id: 'pm_xxx',
|
|
339
338
|
amount: '99.99', // Optional, defaults to order total
|
|
340
339
|
external_data: { // Optional, provider-specific data
|
|
@@ -346,17 +345,17 @@ const session = await client.store.orders.paymentSessions.create(cart.id, {
|
|
|
346
345
|
console.log(session.external_data.client_secret);
|
|
347
346
|
|
|
348
347
|
// Get a payment session
|
|
349
|
-
const existing = await client.
|
|
348
|
+
const existing = await client.orders.paymentSessions.get(
|
|
350
349
|
cart.id, session.id, options
|
|
351
350
|
);
|
|
352
351
|
|
|
353
352
|
// Update a payment session (e.g., after order total changes)
|
|
354
|
-
await client.
|
|
353
|
+
await client.orders.paymentSessions.update(cart.id, session.id, {
|
|
355
354
|
amount: '149.99',
|
|
356
355
|
}, options);
|
|
357
356
|
|
|
358
357
|
// Complete the payment session (after customer confirms payment on the frontend)
|
|
359
|
-
const completed = await client.
|
|
358
|
+
const completed = await client.orders.paymentSessions.complete(
|
|
360
359
|
cart.id, session.id,
|
|
361
360
|
{ session_result: 'success' },
|
|
362
361
|
options
|
|
@@ -368,21 +367,21 @@ console.log(completed.status); // 'completed'
|
|
|
368
367
|
|
|
369
368
|
```typescript
|
|
370
369
|
// List all markets
|
|
371
|
-
const { data: markets } = await client.
|
|
370
|
+
const { data: markets } = await client.markets.list();
|
|
372
371
|
// [{ id: "mkt_xxx", name: "North America", currency: "USD", default_locale: "en", ... }]
|
|
373
372
|
|
|
374
373
|
// Get a single market
|
|
375
|
-
const market = await client.
|
|
374
|
+
const market = await client.markets.get('mkt_xxx');
|
|
376
375
|
|
|
377
376
|
// Resolve which market applies for a country
|
|
378
|
-
const market = await client.
|
|
377
|
+
const market = await client.markets.resolve('DE');
|
|
379
378
|
// => { id: "mkt_xxx", name: "Europe", currency: "EUR", default_locale: "de", ... }
|
|
380
379
|
|
|
381
380
|
// List countries in a market
|
|
382
|
-
const { data: countries } = await client.
|
|
381
|
+
const { data: countries } = await client.markets.countries.list('mkt_xxx');
|
|
383
382
|
|
|
384
383
|
// Get a country in a market (with states for address forms)
|
|
385
|
-
const country = await client.
|
|
384
|
+
const country = await client.markets.countries.get('mkt_xxx', 'DE', {
|
|
386
385
|
expand: ['states'],
|
|
387
386
|
});
|
|
388
387
|
```
|
|
@@ -391,10 +390,10 @@ const country = await client.store.markets.countries.get('mkt_xxx', 'DE', {
|
|
|
391
390
|
|
|
392
391
|
```typescript
|
|
393
392
|
// List countries available for checkout
|
|
394
|
-
const { data: countries } = await client.
|
|
393
|
+
const { data: countries } = await client.countries.list();
|
|
395
394
|
|
|
396
395
|
// Get country by ISO code (with states)
|
|
397
|
-
const usa = await client.
|
|
396
|
+
const usa = await client.countries.get('US', { expand: ['states'] });
|
|
398
397
|
console.log(usa.states); // Array of states
|
|
399
398
|
```
|
|
400
399
|
|
|
@@ -404,10 +403,10 @@ console.log(usa.states); // Array of states
|
|
|
404
403
|
const options = { token: jwtToken };
|
|
405
404
|
|
|
406
405
|
// Get profile
|
|
407
|
-
const profile = await client.
|
|
406
|
+
const profile = await client.customer.get(options);
|
|
408
407
|
|
|
409
408
|
// Update profile
|
|
410
|
-
await client.
|
|
409
|
+
await client.customer.update({
|
|
411
410
|
first_name: 'John',
|
|
412
411
|
last_name: 'Doe',
|
|
413
412
|
}, options);
|
|
@@ -419,13 +418,13 @@ await client.store.customer.update({
|
|
|
419
418
|
const options = { token: jwtToken };
|
|
420
419
|
|
|
421
420
|
// List addresses
|
|
422
|
-
const { data: addresses } = await client.
|
|
421
|
+
const { data: addresses } = await client.customer.addresses.list({}, options);
|
|
423
422
|
|
|
424
423
|
// Get address by ID
|
|
425
|
-
const address = await client.
|
|
424
|
+
const address = await client.customer.addresses.get('addr_xxx', options);
|
|
426
425
|
|
|
427
426
|
// Create address
|
|
428
|
-
await client.
|
|
427
|
+
await client.customer.addresses.create({
|
|
429
428
|
firstname: 'John',
|
|
430
429
|
lastname: 'Doe',
|
|
431
430
|
address1: '123 Main St',
|
|
@@ -436,14 +435,14 @@ await client.store.customer.addresses.create({
|
|
|
436
435
|
}, options);
|
|
437
436
|
|
|
438
437
|
// Update address
|
|
439
|
-
await client.
|
|
438
|
+
await client.customer.addresses.update('addr_xxx', { city: 'Brooklyn' }, options);
|
|
440
439
|
|
|
441
440
|
// Delete address
|
|
442
|
-
await client.
|
|
441
|
+
await client.customer.addresses.delete('addr_xxx', options);
|
|
443
442
|
|
|
444
443
|
// Mark as default billing or shipping address
|
|
445
|
-
await client.
|
|
446
|
-
await client.
|
|
444
|
+
await client.customer.addresses.markAsDefault('addr_xxx', 'billing', options);
|
|
445
|
+
await client.customer.addresses.markAsDefault('addr_xxx', 'shipping', options);
|
|
447
446
|
```
|
|
448
447
|
|
|
449
448
|
### Customer Credit Cards
|
|
@@ -452,13 +451,13 @@ await client.store.customer.addresses.markAsDefault('addr_xxx', 'shipping', opti
|
|
|
452
451
|
const options = { token: jwtToken };
|
|
453
452
|
|
|
454
453
|
// List saved credit cards
|
|
455
|
-
const { data: cards } = await client.
|
|
454
|
+
const { data: cards } = await client.customer.creditCards.list({}, options);
|
|
456
455
|
|
|
457
456
|
// Get credit card by ID
|
|
458
|
-
const card = await client.
|
|
457
|
+
const card = await client.customer.creditCards.get('cc_xxx', options);
|
|
459
458
|
|
|
460
459
|
// Delete credit card
|
|
461
|
-
await client.
|
|
460
|
+
await client.customer.creditCards.delete('cc_xxx', options);
|
|
462
461
|
```
|
|
463
462
|
|
|
464
463
|
### Wishlists
|
|
@@ -467,26 +466,26 @@ await client.store.customer.creditCards.delete('cc_xxx', options);
|
|
|
467
466
|
const options = { token: jwtToken };
|
|
468
467
|
|
|
469
468
|
// List wishlists
|
|
470
|
-
const { data: wishlists } = await client.
|
|
469
|
+
const { data: wishlists } = await client.wishlists.list({}, options);
|
|
471
470
|
|
|
472
471
|
// Get wishlist by ID
|
|
473
|
-
const wishlist = await client.
|
|
472
|
+
const wishlist = await client.wishlists.get('wl_xxx', {
|
|
474
473
|
expand: ['wished_items'],
|
|
475
474
|
}, options);
|
|
476
475
|
|
|
477
476
|
// Create wishlist
|
|
478
|
-
const newWishlist = await client.
|
|
477
|
+
const newWishlist = await client.wishlists.create({
|
|
479
478
|
name: 'Birthday Ideas',
|
|
480
479
|
is_private: true,
|
|
481
480
|
}, options);
|
|
482
481
|
|
|
483
482
|
// Update wishlist
|
|
484
|
-
await client.
|
|
483
|
+
await client.wishlists.update('wl_xxx', {
|
|
485
484
|
name: 'Updated Name',
|
|
486
485
|
}, options);
|
|
487
486
|
|
|
488
487
|
// Delete wishlist
|
|
489
|
-
await client.
|
|
488
|
+
await client.wishlists.delete('wl_xxx', options);
|
|
490
489
|
```
|
|
491
490
|
|
|
492
491
|
### Wishlist Items
|
|
@@ -495,18 +494,18 @@ await client.store.wishlists.delete('wl_xxx', options);
|
|
|
495
494
|
const options = { token: jwtToken };
|
|
496
495
|
|
|
497
496
|
// Add item to wishlist
|
|
498
|
-
await client.
|
|
497
|
+
await client.wishlists.items.create('wl_xxx', {
|
|
499
498
|
variant_id: 'var_123',
|
|
500
499
|
quantity: 1,
|
|
501
500
|
}, options);
|
|
502
501
|
|
|
503
502
|
// Update item quantity
|
|
504
|
-
await client.
|
|
503
|
+
await client.wishlists.items.update('wl_xxx', 'wi_xxx', {
|
|
505
504
|
quantity: 2,
|
|
506
505
|
}, options);
|
|
507
506
|
|
|
508
507
|
// Remove item from wishlist
|
|
509
|
-
await client.
|
|
508
|
+
await client.wishlists.items.delete('wl_xxx', 'wi_xxx', options);
|
|
510
509
|
```
|
|
511
510
|
|
|
512
511
|
## Nested Resources
|
|
@@ -515,29 +514,29 @@ The SDK uses a resource builder pattern for nested resources:
|
|
|
515
514
|
|
|
516
515
|
| Parent Resource | Nested Resource | Available Methods |
|
|
517
516
|
|-----------------|-----------------|-------------------|
|
|
518
|
-
| `
|
|
519
|
-
| `
|
|
520
|
-
| `
|
|
521
|
-
| `
|
|
522
|
-
| `
|
|
523
|
-
| `
|
|
524
|
-
| `
|
|
525
|
-
| `
|
|
526
|
-
| `
|
|
527
|
-
| `
|
|
528
|
-
| `
|
|
529
|
-
| `
|
|
517
|
+
| `orders` | `lineItems` | `create`, `update`, `delete` |
|
|
518
|
+
| `orders` | `payments` | `list`, `get` |
|
|
519
|
+
| `orders` | `paymentMethods` | `list` |
|
|
520
|
+
| `orders` | `paymentSessions` | `create`, `get`, `update`, `complete` |
|
|
521
|
+
| `orders` | `shipments` | `list`, `update` |
|
|
522
|
+
| `orders` | `couponCodes` | `apply`, `remove` |
|
|
523
|
+
| `customer` | `addresses` | `list`, `get`, `create`, `update`, `delete`, `markAsDefault` |
|
|
524
|
+
| `customer` | `creditCards` | `list`, `get`, `delete` |
|
|
525
|
+
| `customer` | `giftCards` | `list`, `get` |
|
|
526
|
+
| `markets` | `countries` | `list`, `get` |
|
|
527
|
+
| `taxons` | `products` | `list` |
|
|
528
|
+
| `wishlists` | `items` | `create`, `update`, `delete` |
|
|
530
529
|
|
|
531
530
|
Example:
|
|
532
531
|
```typescript
|
|
533
|
-
// Nested resources follow the pattern: client.
|
|
534
|
-
await client.
|
|
535
|
-
await client.
|
|
536
|
-
await client.
|
|
537
|
-
await client.
|
|
538
|
-
await client.
|
|
539
|
-
await client.
|
|
540
|
-
await client.
|
|
532
|
+
// Nested resources follow the pattern: client.parent.nested.method(parentId, ...)
|
|
533
|
+
await client.orders.lineItems.create(orderId, params, options);
|
|
534
|
+
await client.orders.payments.list(orderId, options);
|
|
535
|
+
await client.orders.shipments.update(orderId, shipmentId, params, options);
|
|
536
|
+
await client.customer.addresses.list({}, options);
|
|
537
|
+
await client.markets.countries.list(marketId);
|
|
538
|
+
await client.taxons.products.list(taxonId, params, options);
|
|
539
|
+
await client.wishlists.items.create(wishlistId, params, options);
|
|
541
540
|
```
|
|
542
541
|
|
|
543
542
|
## Localization & Currency
|
|
@@ -547,7 +546,7 @@ await client.store.wishlists.items.create(wishlistId, params, options);
|
|
|
547
546
|
Set locale, currency, and country when creating the client:
|
|
548
547
|
|
|
549
548
|
```typescript
|
|
550
|
-
const client =
|
|
549
|
+
const client = createClient({
|
|
551
550
|
baseUrl: 'https://api.mystore.com',
|
|
552
551
|
publishableKey: 'spree_pk_xxx',
|
|
553
552
|
locale: 'fr',
|
|
@@ -556,7 +555,7 @@ const client = createSpreeClient({
|
|
|
556
555
|
});
|
|
557
556
|
|
|
558
557
|
// All requests use fr/EUR/FR automatically
|
|
559
|
-
const products = await client.
|
|
558
|
+
const products = await client.products.list();
|
|
560
559
|
```
|
|
561
560
|
|
|
562
561
|
Update defaults at any time:
|
|
@@ -572,7 +571,7 @@ client.setCountry('DE');
|
|
|
572
571
|
Pass locale and currency headers with any request to override defaults:
|
|
573
572
|
|
|
574
573
|
```typescript
|
|
575
|
-
const products = await client.
|
|
574
|
+
const products = await client.products.list({}, {
|
|
576
575
|
locale: 'fr',
|
|
577
576
|
currency: 'EUR',
|
|
578
577
|
country: 'FR',
|
|
@@ -585,7 +584,7 @@ const products = await client.store.products.list({}, {
|
|
|
585
584
|
import { SpreeError } from '@spree/sdk';
|
|
586
585
|
|
|
587
586
|
try {
|
|
588
|
-
await client.
|
|
587
|
+
await client.products.get('non-existent');
|
|
589
588
|
} catch (error) {
|
|
590
589
|
if (error instanceof SpreeError) {
|
|
591
590
|
console.log(error.code); // 'record_not_found'
|
|
@@ -614,8 +613,8 @@ import type {
|
|
|
614
613
|
} from '@spree/sdk';
|
|
615
614
|
|
|
616
615
|
// All responses are fully typed
|
|
617
|
-
const products: PaginatedResponse<StoreProduct> = await client.
|
|
618
|
-
const taxon: StoreTaxon = await client.
|
|
616
|
+
const products: PaginatedResponse<StoreProduct> = await client.products.list();
|
|
617
|
+
const taxon: StoreTaxon = await client.taxons.get('clothing');
|
|
619
618
|
```
|
|
620
619
|
|
|
621
620
|
## Available Types
|
|
@@ -658,10 +657,9 @@ The SDK exports all Store API types:
|
|
|
658
657
|
- `StoreWishedItem` - Wishlist item
|
|
659
658
|
|
|
660
659
|
### Client Types
|
|
661
|
-
- `
|
|
660
|
+
- `Client` - Main client interface
|
|
662
661
|
- `StoreClient` - Store API client
|
|
663
|
-
- `
|
|
664
|
-
- `SpreeClientConfig` - Client configuration
|
|
662
|
+
- `ClientConfig` - Client configuration
|
|
665
663
|
- `RequestOptions` - Per-request options
|
|
666
664
|
- `RetryConfig` - Retry behavior configuration
|
|
667
665
|
|
|
@@ -679,9 +677,9 @@ The SDK exports all Store API types:
|
|
|
679
677
|
You can provide a custom fetch implementation:
|
|
680
678
|
|
|
681
679
|
```typescript
|
|
682
|
-
import {
|
|
680
|
+
import { createClient } from '@spree/sdk';
|
|
683
681
|
|
|
684
|
-
const client =
|
|
682
|
+
const client = createClient({
|
|
685
683
|
baseUrl: 'https://api.mystore.com',
|
|
686
684
|
publishableKey: 'spree_pk_xxx',
|
|
687
685
|
fetch: customFetchImplementation,
|