@spree/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,534 @@
1
+ 'use strict';
2
+
3
+ // src/client.ts
4
+ var SpreeError = class extends Error {
5
+ code;
6
+ status;
7
+ details;
8
+ constructor(response, status) {
9
+ super(response.error.message);
10
+ this.name = "SpreeError";
11
+ this.code = response.error.code;
12
+ this.status = status;
13
+ this.details = response.error.details;
14
+ }
15
+ };
16
+ var SpreeClient = class {
17
+ baseUrl;
18
+ apiKey;
19
+ fetchFn;
20
+ constructor(config) {
21
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
22
+ this.apiKey = config.apiKey;
23
+ this.fetchFn = config.fetch || fetch.bind(globalThis);
24
+ }
25
+ async request(method, path, options = {}) {
26
+ const { token, orderToken, locale, currency, headers = {}, body, params } = options;
27
+ const url = new URL(`${this.baseUrl}/api/v3/store${path}`);
28
+ if (params) {
29
+ Object.entries(params).forEach(([key, value]) => {
30
+ if (value !== void 0) {
31
+ if (Array.isArray(value)) {
32
+ value.forEach((v) => url.searchParams.append(key, String(v)));
33
+ } else {
34
+ url.searchParams.set(key, String(value));
35
+ }
36
+ }
37
+ });
38
+ }
39
+ if (orderToken) {
40
+ url.searchParams.set("order_token", orderToken);
41
+ }
42
+ const requestHeaders = {
43
+ "Content-Type": "application/json",
44
+ "x-spree-api-key": this.apiKey,
45
+ ...headers
46
+ };
47
+ if (token) {
48
+ requestHeaders["Authorization"] = `Bearer ${token}`;
49
+ }
50
+ if (orderToken) {
51
+ requestHeaders["x-spree-order-token"] = orderToken;
52
+ }
53
+ if (locale) {
54
+ requestHeaders["x-spree-locale"] = locale;
55
+ }
56
+ if (currency) {
57
+ requestHeaders["x-spree-currency"] = currency;
58
+ }
59
+ const response = await this.fetchFn(url.toString(), {
60
+ method,
61
+ headers: requestHeaders,
62
+ body: body ? JSON.stringify(body) : void 0
63
+ });
64
+ if (!response.ok) {
65
+ const errorBody = await response.json();
66
+ throw new SpreeError(errorBody, response.status);
67
+ }
68
+ if (response.status === 204) {
69
+ return void 0;
70
+ }
71
+ return response.json();
72
+ }
73
+ // ============================================
74
+ // Authentication
75
+ // ============================================
76
+ auth = {
77
+ /**
78
+ * Login with email and password
79
+ */
80
+ login: (credentials) => this.request("POST", "/auth/login", { body: credentials }),
81
+ /**
82
+ * Register a new customer account
83
+ */
84
+ register: (params) => this.request("POST", "/auth/register", { body: params }),
85
+ /**
86
+ * Refresh access token (requires valid Bearer token)
87
+ */
88
+ refresh: (options) => this.request("POST", "/auth/refresh", options)
89
+ };
90
+ // ============================================
91
+ // Store
92
+ // ============================================
93
+ store = {
94
+ /**
95
+ * Get current store information
96
+ */
97
+ get: (options) => this.request("GET", "/store", options)
98
+ };
99
+ // ============================================
100
+ // Products
101
+ // ============================================
102
+ products = {
103
+ /**
104
+ * List products
105
+ */
106
+ list: (params, options) => this.request("GET", "/products", {
107
+ ...options,
108
+ params
109
+ }),
110
+ /**
111
+ * Get a product by ID or slug
112
+ */
113
+ get: (idOrSlug, params, options) => this.request("GET", `/products/${idOrSlug}`, {
114
+ ...options,
115
+ params
116
+ }),
117
+ /**
118
+ * Get available filters for products
119
+ * Returns filter options (price range, availability, option types, taxons) with counts
120
+ */
121
+ filters: (params, options) => this.request("GET", "/products/filters", {
122
+ ...options,
123
+ params
124
+ })
125
+ };
126
+ // ============================================
127
+ // Taxonomies & Taxons
128
+ // ============================================
129
+ taxonomies = {
130
+ /**
131
+ * List taxonomies
132
+ */
133
+ list: (params, options) => this.request("GET", "/taxonomies", {
134
+ ...options,
135
+ params
136
+ }),
137
+ /**
138
+ * Get a taxonomy by ID
139
+ */
140
+ get: (id, params, options) => this.request("GET", `/taxonomies/${id}`, {
141
+ ...options,
142
+ params
143
+ })
144
+ };
145
+ taxons = {
146
+ /**
147
+ * List taxons
148
+ */
149
+ list: (params, options) => this.request("GET", "/taxons", {
150
+ ...options,
151
+ params
152
+ }),
153
+ /**
154
+ * Get a taxon by ID or permalink
155
+ */
156
+ get: (idOrPermalink, params, options) => this.request("GET", `/taxons/${idOrPermalink}`, {
157
+ ...options,
158
+ params
159
+ }),
160
+ /**
161
+ * Nested resource: Products in a taxon
162
+ */
163
+ products: {
164
+ /**
165
+ * List products in a taxon
166
+ * @param taxonId - Taxon ID (prefix_id) or permalink
167
+ */
168
+ list: (taxonId, params, options) => this.request(
169
+ "GET",
170
+ `/taxons/${taxonId}/products`,
171
+ {
172
+ ...options,
173
+ params
174
+ }
175
+ )
176
+ }
177
+ };
178
+ // ============================================
179
+ // Geography
180
+ // ============================================
181
+ countries = {
182
+ /**
183
+ * List countries available for checkout
184
+ * Returns countries from the store's checkout zone without states
185
+ */
186
+ list: (options) => this.request("GET", "/countries", options),
187
+ /**
188
+ * Get a country by ISO code with states
189
+ * @param iso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")
190
+ */
191
+ get: (iso, options) => this.request("GET", `/countries/${iso}`, options)
192
+ };
193
+ // ============================================
194
+ // Cart (convenience wrapper for current incomplete order)
195
+ // ============================================
196
+ cart = {
197
+ /**
198
+ * Get current cart (returns null if none exists)
199
+ * Pass orderToken for guest checkout, or use JWT for authenticated users
200
+ */
201
+ get: (options) => this.request("GET", "/cart", options),
202
+ /**
203
+ * Create a new cart (alias for orders.create)
204
+ */
205
+ create: (options) => this.request("POST", "/orders", options),
206
+ /**
207
+ * Associate a guest cart with the currently authenticated user
208
+ * Requires both JWT token (for authentication) and orderToken (to identify the cart)
209
+ * @param options - Must include both `token` (JWT) and `orderToken` (guest cart token)
210
+ */
211
+ associate: (options) => this.request("PATCH", "/cart/associate", options)
212
+ };
213
+ // ============================================
214
+ // Orders (all orders - complete and incomplete)
215
+ // ============================================
216
+ orders = {
217
+ /**
218
+ * List orders for the authenticated customer
219
+ */
220
+ list: (params, options) => this.request("GET", "/orders", {
221
+ ...options,
222
+ params
223
+ }),
224
+ /**
225
+ * Create a new order (cart)
226
+ */
227
+ create: (options) => this.request("POST", "/orders", options),
228
+ /**
229
+ * Get an order by ID or number
230
+ */
231
+ get: (idOrNumber, params, options) => this.request("GET", `/orders/${idOrNumber}`, {
232
+ ...options,
233
+ params
234
+ }),
235
+ /**
236
+ * Update an order
237
+ */
238
+ update: (idOrNumber, params, options) => this.request("PATCH", `/orders/${idOrNumber}`, {
239
+ ...options,
240
+ body: params
241
+ }),
242
+ /**
243
+ * Advance order to next checkout step
244
+ */
245
+ next: (idOrNumber, options) => this.request("PATCH", `/orders/${idOrNumber}/next`, options),
246
+ /**
247
+ * Advance through all checkout steps
248
+ */
249
+ advance: (idOrNumber, options) => this.request("PATCH", `/orders/${idOrNumber}/advance`, options),
250
+ /**
251
+ * Complete the order
252
+ */
253
+ complete: (idOrNumber, options) => this.request("PATCH", `/orders/${idOrNumber}/complete`, options),
254
+ /**
255
+ * Add store credit to order
256
+ */
257
+ addStoreCredit: (idOrNumber, amount, options) => this.request("POST", `/orders/${idOrNumber}/store_credits`, {
258
+ ...options,
259
+ body: amount ? { amount } : void 0
260
+ }),
261
+ /**
262
+ * Remove store credit from order
263
+ */
264
+ removeStoreCredit: (idOrNumber, options) => this.request("DELETE", `/orders/${idOrNumber}/store_credits`, options),
265
+ /**
266
+ * Nested resource: Line items
267
+ */
268
+ lineItems: {
269
+ /**
270
+ * Add a line item to an order
271
+ */
272
+ create: (orderId, params, options) => this.request("POST", `/orders/${orderId}/line_items`, {
273
+ ...options,
274
+ body: params
275
+ }),
276
+ /**
277
+ * Update a line item
278
+ */
279
+ update: (orderId, lineItemId, params, options) => this.request(
280
+ "PATCH",
281
+ `/orders/${orderId}/line_items/${lineItemId}`,
282
+ { ...options, body: params }
283
+ ),
284
+ /**
285
+ * Remove a line item from an order
286
+ */
287
+ delete: (orderId, lineItemId, options) => this.request(
288
+ "DELETE",
289
+ `/orders/${orderId}/line_items/${lineItemId}`,
290
+ options
291
+ )
292
+ },
293
+ /**
294
+ * Nested resource: Payments
295
+ */
296
+ payments: {
297
+ /**
298
+ * List payments for an order
299
+ */
300
+ list: (orderId, options) => this.request(
301
+ "GET",
302
+ `/orders/${orderId}/payments`,
303
+ options
304
+ ),
305
+ /**
306
+ * Get a payment by ID
307
+ */
308
+ get: (orderId, paymentId, options) => this.request(
309
+ "GET",
310
+ `/orders/${orderId}/payments/${paymentId}`,
311
+ options
312
+ )
313
+ },
314
+ /**
315
+ * Nested resource: Payment methods
316
+ */
317
+ paymentMethods: {
318
+ /**
319
+ * List available payment methods for an order
320
+ */
321
+ list: (orderId, options) => this.request(
322
+ "GET",
323
+ `/orders/${orderId}/payment_methods`,
324
+ options
325
+ )
326
+ },
327
+ /**
328
+ * Nested resource: Coupon codes
329
+ */
330
+ couponCodes: {
331
+ /**
332
+ * Apply a coupon code to an order
333
+ */
334
+ apply: (orderId, code, options) => this.request("POST", `/orders/${orderId}/coupon_codes`, {
335
+ ...options,
336
+ body: { code }
337
+ }),
338
+ /**
339
+ * Remove a coupon code from an order
340
+ * @param promotionId - The promotion prefix_id (e.g., 'promo_xxx')
341
+ */
342
+ remove: (orderId, promotionId, options) => this.request(
343
+ "DELETE",
344
+ `/orders/${orderId}/coupon_codes/${promotionId}`,
345
+ options
346
+ )
347
+ },
348
+ /**
349
+ * Nested resource: Shipments
350
+ */
351
+ shipments: {
352
+ /**
353
+ * List shipments for an order
354
+ */
355
+ list: (orderId, options) => this.request(
356
+ "GET",
357
+ `/orders/${orderId}/shipments`,
358
+ options
359
+ ),
360
+ /**
361
+ * Update a shipment (e.g., select shipping rate)
362
+ */
363
+ update: (orderId, shipmentId, params, options) => this.request(
364
+ "PATCH",
365
+ `/orders/${orderId}/shipments/${shipmentId}`,
366
+ { ...options, body: params }
367
+ )
368
+ }
369
+ };
370
+ // ============================================
371
+ // Customer
372
+ // ============================================
373
+ customer = {
374
+ /**
375
+ * Get current customer profile
376
+ */
377
+ get: (options) => this.request("GET", "/customer", options),
378
+ /**
379
+ * Update current customer profile
380
+ */
381
+ update: (params, options) => this.request("PATCH", "/customer", {
382
+ ...options,
383
+ body: params
384
+ }),
385
+ /**
386
+ * Nested resource: Addresses
387
+ */
388
+ addresses: {
389
+ /**
390
+ * List customer addresses
391
+ */
392
+ list: (params, options) => this.request(
393
+ "GET",
394
+ "/customer/addresses",
395
+ { ...options, params }
396
+ ),
397
+ /**
398
+ * Get an address by ID
399
+ */
400
+ get: (id, options) => this.request("GET", `/customer/addresses/${id}`, options),
401
+ /**
402
+ * Create an address
403
+ */
404
+ create: (params, options) => this.request("POST", "/customer/addresses", {
405
+ ...options,
406
+ body: params
407
+ }),
408
+ /**
409
+ * Update an address
410
+ */
411
+ update: (id, params, options) => this.request("PATCH", `/customer/addresses/${id}`, {
412
+ ...options,
413
+ body: params
414
+ }),
415
+ /**
416
+ * Delete an address
417
+ */
418
+ delete: (id, options) => this.request("DELETE", `/customer/addresses/${id}`, options)
419
+ },
420
+ /**
421
+ * Nested resource: Credit Cards
422
+ */
423
+ creditCards: {
424
+ /**
425
+ * List customer credit cards
426
+ */
427
+ list: (params, options) => this.request(
428
+ "GET",
429
+ "/customer/credit_cards",
430
+ { ...options, params }
431
+ ),
432
+ /**
433
+ * Get a credit card by ID
434
+ */
435
+ get: (id, options) => this.request("GET", `/customer/credit_cards/${id}`, options),
436
+ /**
437
+ * Delete a credit card
438
+ */
439
+ delete: (id, options) => this.request("DELETE", `/customer/credit_cards/${id}`, options)
440
+ },
441
+ /**
442
+ * Nested resource: Gift Cards
443
+ */
444
+ giftCards: {
445
+ /**
446
+ * List customer gift cards
447
+ * Returns gift cards associated with the current user, ordered by newest first
448
+ */
449
+ list: (params, options) => this.request(
450
+ "GET",
451
+ "/customer/gift_cards",
452
+ { ...options, params }
453
+ ),
454
+ /**
455
+ * Get a gift card by ID
456
+ */
457
+ get: (id, options) => this.request("GET", `/customer/gift_cards/${id}`, options)
458
+ }
459
+ };
460
+ // ============================================
461
+ // Wishlists
462
+ // ============================================
463
+ wishlists = {
464
+ /**
465
+ * List wishlists
466
+ */
467
+ list: (params, options) => this.request("GET", "/wishlists", {
468
+ ...options,
469
+ params
470
+ }),
471
+ /**
472
+ * Get a wishlist by ID
473
+ */
474
+ get: (id, params, options) => this.request("GET", `/wishlists/${id}`, {
475
+ ...options,
476
+ params
477
+ }),
478
+ /**
479
+ * Create a wishlist
480
+ */
481
+ create: (params, options) => this.request("POST", "/wishlists", {
482
+ ...options,
483
+ body: params
484
+ }),
485
+ /**
486
+ * Update a wishlist
487
+ */
488
+ update: (id, params, options) => this.request("PATCH", `/wishlists/${id}`, {
489
+ ...options,
490
+ body: params
491
+ }),
492
+ /**
493
+ * Delete a wishlist
494
+ */
495
+ delete: (id, options) => this.request("DELETE", `/wishlists/${id}`, options),
496
+ /**
497
+ * Nested resource: Wishlist items
498
+ */
499
+ items: {
500
+ /**
501
+ * Add an item to a wishlist
502
+ */
503
+ create: (wishlistId, params, options) => this.request("POST", `/wishlists/${wishlistId}/items`, {
504
+ ...options,
505
+ body: params
506
+ }),
507
+ /**
508
+ * Update a wishlist item
509
+ */
510
+ update: (wishlistId, itemId, params, options) => this.request(
511
+ "PATCH",
512
+ `/wishlists/${wishlistId}/items/${itemId}`,
513
+ { ...options, body: params }
514
+ ),
515
+ /**
516
+ * Remove an item from a wishlist
517
+ */
518
+ delete: (wishlistId, itemId, options) => this.request(
519
+ "DELETE",
520
+ `/wishlists/${wishlistId}/items/${itemId}`,
521
+ options
522
+ )
523
+ }
524
+ };
525
+ };
526
+ function createSpreeClient(config) {
527
+ return new SpreeClient(config);
528
+ }
529
+
530
+ exports.SpreeClient = SpreeClient;
531
+ exports.SpreeError = SpreeError;
532
+ exports.createSpreeClient = createSpreeClient;
533
+ //# sourceMappingURL=index.cjs.map
534
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;AA2DO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpB,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA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ACF;AAKO,SAAS,kBAAkB,MAAA,EAAwC;AACxE,EAAA,OAAO,IAAI,YAAY,MAAM,CAAA;AAC/B","file":"index.cjs","sourcesContent":["import type {\n AuthTokens,\n LoginCredentials,\n RegisterParams,\n ErrorResponse,\n PaginatedResponse,\n ListParams,\n ProductListParams,\n ProductFiltersParams,\n ProductFiltersResponse,\n TaxonListParams,\n OrderListParams,\n AddLineItemParams,\n UpdateLineItemParams,\n UpdateOrderParams,\n AddressParams,\n StoreCreditCard,\n StoreGiftCard,\n StoreProduct,\n StoreOrder,\n StoreLineItem,\n StoreCountry,\n StoreTaxonomy,\n StoreTaxon,\n StorePayment,\n StorePaymentMethod,\n StoreShipment,\n StoreStore,\n StoreWishlist,\n StoreWishedItem,\n StoreAddress,\n StoreUser,\n} from './types';\n\n// Re-export types for convenience\nexport type { AddressParams, StoreCreditCard };\n\nexport interface SpreeClientConfig {\n /** Base URL of the Spree API (e.g., 'https://api.mystore.com') */\n baseUrl: string;\n /** Publishable API key for store access */\n apiKey: string;\n /** Custom fetch implementation (optional, defaults to global fetch) */\n fetch?: typeof fetch;\n}\n\nexport interface RequestOptions {\n /** Bearer token for authenticated requests */\n token?: string;\n /** Order token for guest checkout */\n orderToken?: string;\n /** Locale for translated content (e.g., 'en', 'fr') */\n locale?: string;\n /** Currency for prices (e.g., 'USD', 'EUR') */\n currency?: string;\n /** Custom headers */\n headers?: Record<string, string>;\n}\n\nexport class SpreeError extends Error {\n public readonly code: string;\n public readonly status: number;\n public readonly details?: Record<string, string[]>;\n\n constructor(response: ErrorResponse, status: number) {\n super(response.error.message);\n this.name = 'SpreeError';\n this.code = response.error.code;\n this.status = status;\n this.details = response.error.details;\n }\n}\n\nexport class SpreeClient {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly fetchFn: typeof fetch;\n\n constructor(config: SpreeClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.apiKey = config.apiKey;\n // Bind fetch to globalThis to avoid \"Illegal invocation\" errors in browsers\n this.fetchFn = config.fetch || fetch.bind(globalThis);\n }\n\n private async request<T>(\n method: string,\n path: string,\n options: RequestOptions & {\n body?: unknown;\n params?: Record<string, string | number | undefined>;\n } = {}\n ): Promise<T> {\n const { token, orderToken, locale, currency, headers = {}, body, params } = options;\n\n // Build URL with query params\n const url = new URL(`${this.baseUrl}/api/v3/store${path}`);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n // Handle arrays by appending each value with the same key (Rails-style)\n if (Array.isArray(value)) {\n value.forEach((v) => url.searchParams.append(key, String(v)));\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n });\n }\n if (orderToken) {\n url.searchParams.set('order_token', orderToken);\n }\n\n // Build headers\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'x-spree-api-key': this.apiKey,\n ...headers,\n };\n\n if (token) {\n requestHeaders['Authorization'] = `Bearer ${token}`;\n }\n\n if (orderToken) {\n requestHeaders['x-spree-order-token'] = orderToken;\n }\n\n if (locale) {\n requestHeaders['x-spree-locale'] = locale;\n }\n\n if (currency) {\n requestHeaders['x-spree-currency'] = currency;\n }\n\n const response = await this.fetchFn(url.toString(), {\n method,\n headers: requestHeaders,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n const errorBody = await response.json() as ErrorResponse;\n throw new SpreeError(errorBody, response.status);\n }\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n return response.json() as Promise<T>;\n }\n\n // ============================================\n // Authentication\n // ============================================\n\n readonly auth = {\n /**\n * Login with email and password\n */\n login: (credentials: LoginCredentials): Promise<AuthTokens> =>\n this.request<AuthTokens>('POST', '/auth/login', { body: credentials }),\n\n /**\n * Register a new customer account\n */\n register: (params: RegisterParams): Promise<AuthTokens> =>\n this.request<AuthTokens>('POST', '/auth/register', { body: params }),\n\n /**\n * Refresh access token (requires valid Bearer token)\n */\n refresh: (options: RequestOptions): Promise<AuthTokens> =>\n this.request<AuthTokens>('POST', '/auth/refresh', options),\n };\n\n // ============================================\n // Store\n // ============================================\n\n readonly store = {\n /**\n * Get current store information\n */\n get: (options?: RequestOptions): Promise<StoreStore> =>\n this.request<StoreStore>('GET', '/store', options),\n };\n\n // ============================================\n // Products\n // ============================================\n\n readonly products = {\n /**\n * List products\n */\n list: (\n params?: ProductListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreProduct>> =>\n this.request<PaginatedResponse<StoreProduct>>('GET', '/products', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n\n /**\n * Get a product by ID or slug\n */\n get: (\n idOrSlug: string,\n params?: { includes?: string },\n options?: RequestOptions\n ): Promise<StoreProduct> =>\n this.request<StoreProduct>('GET', `/products/${idOrSlug}`, {\n ...options,\n params,\n }),\n\n /**\n * Get available filters for products\n * Returns filter options (price range, availability, option types, taxons) with counts\n */\n filters: (\n params?: ProductFiltersParams,\n options?: RequestOptions\n ): Promise<ProductFiltersResponse> =>\n this.request<ProductFiltersResponse>('GET', '/products/filters', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n };\n\n // ============================================\n // Taxonomies & Taxons\n // ============================================\n\n readonly taxonomies = {\n /**\n * List taxonomies\n */\n list: (\n params?: ListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreTaxonomy>> =>\n this.request<PaginatedResponse<StoreTaxonomy>>('GET', '/taxonomies', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n\n /**\n * Get a taxonomy by ID\n */\n get: (\n id: string,\n params?: { includes?: string },\n options?: RequestOptions\n ): Promise<StoreTaxonomy> =>\n this.request<StoreTaxonomy>('GET', `/taxonomies/${id}`, {\n ...options,\n params,\n }),\n };\n\n readonly taxons = {\n /**\n * List taxons\n */\n list: (\n params?: TaxonListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreTaxon>> =>\n this.request<PaginatedResponse<StoreTaxon>>('GET', '/taxons', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n\n /**\n * Get a taxon by ID or permalink\n */\n get: (\n idOrPermalink: string,\n params?: { includes?: string },\n options?: RequestOptions\n ): Promise<StoreTaxon> =>\n this.request<StoreTaxon>('GET', `/taxons/${idOrPermalink}`, {\n ...options,\n params,\n }),\n\n /**\n * Nested resource: Products in a taxon\n */\n products: {\n /**\n * List products in a taxon\n * @param taxonId - Taxon ID (prefix_id) or permalink\n */\n list: (\n taxonId: string,\n params?: ProductListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreProduct>> =>\n this.request<PaginatedResponse<StoreProduct>>(\n 'GET',\n `/taxons/${taxonId}/products`,\n {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }\n ),\n },\n };\n\n // ============================================\n // Geography\n // ============================================\n\n readonly countries = {\n /**\n * List countries available for checkout\n * Returns countries from the store's checkout zone without states\n */\n list: (options?: RequestOptions): Promise<{ data: StoreCountry[] }> =>\n this.request<{ data: StoreCountry[] }>('GET', '/countries', options),\n\n /**\n * Get a country by ISO code with states\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n */\n get: (iso: string, options?: RequestOptions): Promise<StoreCountry> =>\n this.request<StoreCountry>('GET', `/countries/${iso}`, options),\n };\n\n // ============================================\n // Cart (convenience wrapper for current incomplete order)\n // ============================================\n\n readonly cart = {\n /**\n * Get current cart (returns null if none exists)\n * Pass orderToken for guest checkout, or use JWT for authenticated users\n */\n get: (options?: RequestOptions): Promise<StoreOrder & { token: string }> =>\n this.request<StoreOrder & { token: string }>('GET', '/cart', options),\n\n /**\n * Create a new cart (alias for orders.create)\n */\n create: (options?: RequestOptions): Promise<StoreOrder & { token: string }> =>\n this.request<StoreOrder & { token: string }>('POST', '/orders', options),\n\n /**\n * Associate a guest cart with the currently authenticated user\n * Requires both JWT token (for authentication) and orderToken (to identify the cart)\n * @param options - Must include both `token` (JWT) and `orderToken` (guest cart token)\n */\n associate: (options: RequestOptions): Promise<StoreOrder & { token: string }> =>\n this.request<StoreOrder & { token: string }>('PATCH', '/cart/associate', options),\n };\n\n // ============================================\n // Orders (all orders - complete and incomplete)\n // ============================================\n\n readonly orders = {\n /**\n * List orders for the authenticated customer\n */\n list: (\n params?: OrderListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreOrder>> =>\n this.request<PaginatedResponse<StoreOrder>>('GET', '/orders', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n\n /**\n * Create a new order (cart)\n */\n create: (options?: RequestOptions): Promise<StoreOrder & { order_token: string }> =>\n this.request<StoreOrder & { order_token: string }>('POST', '/orders', options),\n\n /**\n * Get an order by ID or number\n */\n get: (\n idOrNumber: string,\n params?: { includes?: string },\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>('GET', `/orders/${idOrNumber}`, {\n ...options,\n params,\n }),\n\n /**\n * Update an order\n */\n update: (\n idOrNumber: string,\n params: UpdateOrderParams,\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>('PATCH', `/orders/${idOrNumber}`, {\n ...options,\n body: params,\n }),\n\n /**\n * Advance order to next checkout step\n */\n next: (idOrNumber: string, options?: RequestOptions): Promise<StoreOrder> =>\n this.request<StoreOrder>('PATCH', `/orders/${idOrNumber}/next`, options),\n\n /**\n * Advance through all checkout steps\n */\n advance: (idOrNumber: string, options?: RequestOptions): Promise<StoreOrder> =>\n this.request<StoreOrder>('PATCH', `/orders/${idOrNumber}/advance`, options),\n\n /**\n * Complete the order\n */\n complete: (idOrNumber: string, options?: RequestOptions): Promise<StoreOrder> =>\n this.request<StoreOrder>('PATCH', `/orders/${idOrNumber}/complete`, options),\n\n /**\n * Add store credit to order\n */\n addStoreCredit: (\n idOrNumber: string,\n amount?: number,\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>('POST', `/orders/${idOrNumber}/store_credits`, {\n ...options,\n body: amount ? { amount } : undefined,\n }),\n\n /**\n * Remove store credit from order\n */\n removeStoreCredit: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>('DELETE', `/orders/${idOrNumber}/store_credits`, options),\n\n /**\n * Nested resource: Line items\n */\n lineItems: {\n /**\n * Add a line item to an order\n */\n create: (\n orderId: string,\n params: AddLineItemParams,\n options?: RequestOptions\n ): Promise<StoreLineItem> =>\n this.request<StoreLineItem>('POST', `/orders/${orderId}/line_items`, {\n ...options,\n body: params,\n }),\n\n /**\n * Update a line item\n */\n update: (\n orderId: string,\n lineItemId: string,\n params: UpdateLineItemParams,\n options?: RequestOptions\n ): Promise<StoreLineItem> =>\n this.request<StoreLineItem>(\n 'PATCH',\n `/orders/${orderId}/line_items/${lineItemId}`,\n { ...options, body: params }\n ),\n\n /**\n * Remove a line item from an order\n */\n delete: (\n orderId: string,\n lineItemId: string,\n options?: RequestOptions\n ): Promise<void> =>\n this.request<void>(\n 'DELETE',\n `/orders/${orderId}/line_items/${lineItemId}`,\n options\n ),\n },\n\n /**\n * Nested resource: Payments\n */\n payments: {\n /**\n * List payments for an order\n */\n list: (\n orderId: string,\n options?: RequestOptions\n ): Promise<{ data: StorePayment[]; meta: object }> =>\n this.request<{ data: StorePayment[]; meta: object }>(\n 'GET',\n `/orders/${orderId}/payments`,\n options\n ),\n\n /**\n * Get a payment by ID\n */\n get: (\n orderId: string,\n paymentId: string,\n options?: RequestOptions\n ): Promise<StorePayment> =>\n this.request<StorePayment>(\n 'GET',\n `/orders/${orderId}/payments/${paymentId}`,\n options\n ),\n },\n\n /**\n * Nested resource: Payment methods\n */\n paymentMethods: {\n /**\n * List available payment methods for an order\n */\n list: (\n orderId: string,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StorePaymentMethod>> =>\n this.request<PaginatedResponse<StorePaymentMethod>>(\n 'GET',\n `/orders/${orderId}/payment_methods`,\n options\n ),\n },\n\n /**\n * Nested resource: Coupon codes\n */\n couponCodes: {\n /**\n * Apply a coupon code to an order\n */\n apply: (\n orderId: string,\n code: string,\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>('POST', `/orders/${orderId}/coupon_codes`, {\n ...options,\n body: { code },\n }),\n\n /**\n * Remove a coupon code from an order\n * @param promotionId - The promotion prefix_id (e.g., 'promo_xxx')\n */\n remove: (\n orderId: string,\n promotionId: string,\n options?: RequestOptions\n ): Promise<StoreOrder> =>\n this.request<StoreOrder>(\n 'DELETE',\n `/orders/${orderId}/coupon_codes/${promotionId}`,\n options\n ),\n },\n\n /**\n * Nested resource: Shipments\n */\n shipments: {\n /**\n * List shipments for an order\n */\n list: (\n orderId: string,\n options?: RequestOptions\n ): Promise<{ data: StoreShipment[] }> =>\n this.request<{ data: StoreShipment[] }>(\n 'GET',\n `/orders/${orderId}/shipments`,\n options\n ),\n\n /**\n * Update a shipment (e.g., select shipping rate)\n */\n update: (\n orderId: string,\n shipmentId: string,\n params: { selected_shipping_rate_id: string },\n options?: RequestOptions\n ): Promise<StoreShipment> =>\n this.request<StoreShipment>(\n 'PATCH',\n `/orders/${orderId}/shipments/${shipmentId}`,\n { ...options, body: params }\n ),\n },\n };\n\n // ============================================\n // Customer\n // ============================================\n\n readonly customer = {\n /**\n * Get current customer profile\n */\n get: (options?: RequestOptions): Promise<StoreUser> =>\n this.request<StoreUser>('GET', '/customer', options),\n\n /**\n * Update current customer profile\n */\n update: (\n params: { first_name?: string; last_name?: string; email?: string },\n options?: RequestOptions\n ): Promise<StoreUser> =>\n this.request<StoreUser>('PATCH', '/customer', {\n ...options,\n body: params,\n }),\n\n /**\n * Nested resource: Addresses\n */\n addresses: {\n /**\n * List customer addresses\n */\n list: (\n params?: ListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreAddress>> =>\n this.request<PaginatedResponse<StoreAddress>>(\n 'GET',\n '/customer/addresses',\n { ...options, params: params as Record<string, string | number | undefined> }\n ),\n\n /**\n * Get an address by ID\n */\n get: (id: string, options?: RequestOptions): Promise<StoreAddress> =>\n this.request<StoreAddress>('GET', `/customer/addresses/${id}`, options),\n\n /**\n * Create an address\n */\n create: (\n params: AddressParams,\n options?: RequestOptions\n ): Promise<StoreAddress> =>\n this.request<StoreAddress>('POST', '/customer/addresses', {\n ...options,\n body: params,\n }),\n\n /**\n * Update an address\n */\n update: (\n id: string,\n params: Partial<AddressParams>,\n options?: RequestOptions\n ): Promise<StoreAddress> =>\n this.request<StoreAddress>('PATCH', `/customer/addresses/${id}`, {\n ...options,\n body: params,\n }),\n\n /**\n * Delete an address\n */\n delete: (id: string, options?: RequestOptions): Promise<void> =>\n this.request<void>('DELETE', `/customer/addresses/${id}`, options),\n },\n\n /**\n * Nested resource: Credit Cards\n */\n creditCards: {\n /**\n * List customer credit cards\n */\n list: (\n params?: ListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreCreditCard>> =>\n this.request<PaginatedResponse<StoreCreditCard>>(\n 'GET',\n '/customer/credit_cards',\n { ...options, params: params as Record<string, string | number | undefined> }\n ),\n\n /**\n * Get a credit card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<StoreCreditCard> =>\n this.request<StoreCreditCard>('GET', `/customer/credit_cards/${id}`, options),\n\n /**\n * Delete a credit card\n */\n delete: (id: string, options?: RequestOptions): Promise<void> =>\n this.request<void>('DELETE', `/customer/credit_cards/${id}`, options),\n },\n\n /**\n * Nested resource: Gift Cards\n */\n giftCards: {\n /**\n * List customer gift cards\n * Returns gift cards associated with the current user, ordered by newest first\n */\n list: (\n params?: ListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreGiftCard>> =>\n this.request<PaginatedResponse<StoreGiftCard>>(\n 'GET',\n '/customer/gift_cards',\n { ...options, params: params as Record<string, string | number | undefined> }\n ),\n\n /**\n * Get a gift card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<StoreGiftCard> =>\n this.request<StoreGiftCard>('GET', `/customer/gift_cards/${id}`, options),\n },\n };\n\n // ============================================\n // Wishlists\n // ============================================\n\n readonly wishlists = {\n /**\n * List wishlists\n */\n list: (\n params?: ListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<StoreWishlist>> =>\n this.request<PaginatedResponse<StoreWishlist>>('GET', '/wishlists', {\n ...options,\n params: params as Record<string, string | number | undefined>,\n }),\n\n /**\n * Get a wishlist by ID\n */\n get: (\n id: string,\n params?: { includes?: string },\n options?: RequestOptions\n ): Promise<StoreWishlist> =>\n this.request<StoreWishlist>('GET', `/wishlists/${id}`, {\n ...options,\n params,\n }),\n\n /**\n * Create a wishlist\n */\n create: (\n params: { name: string; is_private?: boolean; is_default?: boolean },\n options?: RequestOptions\n ): Promise<StoreWishlist> =>\n this.request<StoreWishlist>('POST', '/wishlists', {\n ...options,\n body: params,\n }),\n\n /**\n * Update a wishlist\n */\n update: (\n id: string,\n params: { name?: string; is_private?: boolean; is_default?: boolean },\n options?: RequestOptions\n ): Promise<StoreWishlist> =>\n this.request<StoreWishlist>('PATCH', `/wishlists/${id}`, {\n ...options,\n body: params,\n }),\n\n /**\n * Delete a wishlist\n */\n delete: (id: string, options?: RequestOptions): Promise<void> =>\n this.request<void>('DELETE', `/wishlists/${id}`, options),\n\n /**\n * Nested resource: Wishlist items\n */\n items: {\n /**\n * Add an item to a wishlist\n */\n create: (\n wishlistId: string,\n params: { variant_id: string; quantity?: number },\n options?: RequestOptions\n ): Promise<StoreWishedItem> =>\n this.request<StoreWishedItem>('POST', `/wishlists/${wishlistId}/items`, {\n ...options,\n body: params,\n }),\n\n /**\n * Update a wishlist item\n */\n update: (\n wishlistId: string,\n itemId: string,\n params: { quantity: number },\n options?: RequestOptions\n ): Promise<StoreWishedItem> =>\n this.request<StoreWishedItem>(\n 'PATCH',\n `/wishlists/${wishlistId}/items/${itemId}`,\n { ...options, body: params }\n ),\n\n /**\n * Remove an item from a wishlist\n */\n delete: (\n wishlistId: string,\n itemId: string,\n options?: RequestOptions\n ): Promise<void> =>\n this.request<void>(\n 'DELETE',\n `/wishlists/${wishlistId}/items/${itemId}`,\n options\n ),\n },\n };\n}\n\n/**\n * Create a new Spree SDK client\n */\nexport function createSpreeClient(config: SpreeClientConfig): SpreeClient {\n return new SpreeClient(config);\n}\n"]}