@spree/sdk 0.7.0 → 0.7.1

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 CHANGED
@@ -1,8 +1,166 @@
1
1
  'use strict';
2
2
 
3
- var sdkCore = require('@spree/sdk-core');
3
+ // ../sdk-core/dist/index.js
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
+ function calculateDelay(attempt, config) {
17
+ const exponentialDelay = config.baseDelay * Math.pow(2, attempt);
18
+ const jitter = Math.random() * config.baseDelay;
19
+ return Math.min(exponentialDelay + jitter, config.maxDelay);
20
+ }
21
+ function sleep(ms) {
22
+ return new Promise((resolve) => setTimeout(resolve, ms));
23
+ }
24
+ function generateIdempotencyKey() {
25
+ return `spree-sdk-retry-${crypto.randomUUID()}`;
26
+ }
27
+ function shouldRetryOnStatus(method, status, config, hasIdempotencyKey) {
28
+ const isIdempotent = method === "GET" || method === "HEAD" || hasIdempotencyKey;
29
+ if (isIdempotent) {
30
+ return config.retryOnStatus.includes(status);
31
+ }
32
+ return status === 429;
33
+ }
34
+ function shouldRetryOnNetworkError(method, config, hasIdempotencyKey) {
35
+ if (!config.retryOnNetworkError) return false;
36
+ return method === "GET" || method === "HEAD" || hasIdempotencyKey;
37
+ }
38
+ function createRequestFn(config, basePath, auth, defaults) {
39
+ return async function request(method, path, options = {}) {
40
+ const { token, orderToken, idempotencyKey, headers = {}, body, params } = options;
41
+ const locale = options.locale ?? defaults?.locale;
42
+ const currency = options.currency ?? defaults?.currency;
43
+ const country = options.country ?? defaults?.country;
44
+ const url = new URL(`${config.baseUrl}${basePath}${path}`);
45
+ if (params) {
46
+ Object.entries(params).forEach(([key, value]) => {
47
+ if (value !== void 0) {
48
+ if (Array.isArray(value)) {
49
+ value.forEach((v) => url.searchParams.append(key, String(v)));
50
+ } else {
51
+ url.searchParams.set(key, String(value));
52
+ }
53
+ }
54
+ });
55
+ }
56
+ const requestHeaders = {
57
+ "Content-Type": "application/json",
58
+ ...headers
59
+ };
60
+ if (auth.headerValue) {
61
+ requestHeaders[auth.headerName] = auth.headerValue;
62
+ }
63
+ if (token) {
64
+ requestHeaders["Authorization"] = `Bearer ${token}`;
65
+ }
66
+ if (orderToken) {
67
+ requestHeaders["x-spree-order-token"] = orderToken;
68
+ }
69
+ if (locale) {
70
+ requestHeaders["x-spree-locale"] = locale;
71
+ }
72
+ if (currency) {
73
+ requestHeaders["x-spree-currency"] = currency;
74
+ }
75
+ if (country) {
76
+ requestHeaders["x-spree-country"] = country;
77
+ }
78
+ const isMutating = method !== "GET" && method !== "HEAD";
79
+ const effectiveIdempotencyKey = idempotencyKey ?? (isMutating && config.retryConfig ? generateIdempotencyKey() : void 0);
80
+ if (effectiveIdempotencyKey) {
81
+ requestHeaders["Idempotency-Key"] = effectiveIdempotencyKey;
82
+ }
83
+ const hasIdempotencyKey = !!effectiveIdempotencyKey;
84
+ const maxAttempts = config.retryConfig ? config.retryConfig.maxRetries + 1 : 1;
85
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
86
+ try {
87
+ const response = await config.fetchFn(url.toString(), {
88
+ method,
89
+ headers: requestHeaders,
90
+ body: body ? JSON.stringify(body) : void 0
91
+ });
92
+ if (!response.ok) {
93
+ const isLastAttempt = attempt >= maxAttempts - 1;
94
+ if (!isLastAttempt && config.retryConfig && shouldRetryOnStatus(method, response.status, config.retryConfig, hasIdempotencyKey)) {
95
+ const retryAfter = response.headers.get("Retry-After");
96
+ const delay = retryAfter ? Math.min(parseInt(retryAfter, 10) * 1e3, config.retryConfig.maxDelay) : calculateDelay(attempt, config.retryConfig);
97
+ await sleep(delay);
98
+ continue;
99
+ }
100
+ const errorBody = await response.json();
101
+ throw new SpreeError(errorBody, response.status);
102
+ }
103
+ if (response.status === 204) {
104
+ return void 0;
105
+ }
106
+ return response.json();
107
+ } catch (error) {
108
+ if (error instanceof SpreeError) {
109
+ throw error;
110
+ }
111
+ const isLastAttempt = attempt >= maxAttempts - 1;
112
+ if (!isLastAttempt && config.retryConfig && shouldRetryOnNetworkError(method, config.retryConfig, hasIdempotencyKey)) {
113
+ const delay = calculateDelay(attempt, config.retryConfig);
114
+ await sleep(delay);
115
+ continue;
116
+ }
117
+ throw error;
118
+ }
119
+ }
120
+ throw new Error("Unexpected end of retry loop");
121
+ };
122
+ }
123
+ var PASSTHROUGH_KEYS = /* @__PURE__ */ new Set(["page", "limit", "expand", "sort", "fields"]);
124
+ function transformListParams(params) {
125
+ const result = {};
126
+ for (const [key, value] of Object.entries(params)) {
127
+ if (value === void 0) continue;
128
+ if (PASSTHROUGH_KEYS.has(key)) {
129
+ result[key] = Array.isArray(value) ? value.join(",") : value;
130
+ continue;
131
+ }
132
+ if (key.startsWith("q[")) {
133
+ result[key] = value;
134
+ continue;
135
+ }
136
+ if (Array.isArray(value)) {
137
+ const base = key.endsWith("[]") ? key.slice(0, -2) : key;
138
+ result[`q[${base}][]`] = value;
139
+ } else {
140
+ result[`q[${key}]`] = value;
141
+ }
142
+ }
143
+ return result;
144
+ }
145
+ function getParams(params) {
146
+ if (!params) return void 0;
147
+ const result = {};
148
+ if (params.expand?.length) result.expand = params.expand.join(",");
149
+ if (params.fields?.length) result.fields = params.fields.join(",");
150
+ return Object.keys(result).length > 0 ? result : void 0;
151
+ }
152
+ function resolveRetryConfig(retry) {
153
+ if (retry === false) return false;
154
+ return {
155
+ maxRetries: retry?.maxRetries ?? 2,
156
+ retryOnStatus: retry?.retryOnStatus ?? [429, 500, 502, 503, 504],
157
+ baseDelay: retry?.baseDelay ?? 300,
158
+ maxDelay: retry?.maxDelay ?? 1e4,
159
+ retryOnNetworkError: retry?.retryOnNetworkError ?? true
160
+ };
161
+ }
4
162
 
5
- // src/client.ts
163
+ // src/store-client.ts
6
164
  var StoreClient = class {
7
165
  request;
8
166
  constructor(request) {
@@ -34,14 +192,14 @@ var StoreClient = class {
34
192
  */
35
193
  list: (params, options) => this.request("GET", "/products", {
36
194
  ...options,
37
- params: sdkCore.transformListParams({ ...params })
195
+ params: transformListParams({ ...params })
38
196
  }),
39
197
  /**
40
198
  * Get a product by ID or slug
41
199
  */
42
200
  get: (idOrSlug, params, options) => this.request("GET", `/products/${idOrSlug}`, {
43
201
  ...options,
44
- params: sdkCore.getParams(params)
202
+ params: getParams(params)
45
203
  }),
46
204
  /**
47
205
  * Get available filters for products
@@ -61,14 +219,14 @@ var StoreClient = class {
61
219
  */
62
220
  list: (params, options) => this.request("GET", "/taxonomies", {
63
221
  ...options,
64
- params: sdkCore.transformListParams({ ...params })
222
+ params: transformListParams({ ...params })
65
223
  }),
66
224
  /**
67
225
  * Get a taxonomy by ID
68
226
  */
69
227
  get: (id, params, options) => this.request("GET", `/taxonomies/${id}`, {
70
228
  ...options,
71
- params: sdkCore.getParams(params)
229
+ params: getParams(params)
72
230
  })
73
231
  };
74
232
  taxons = {
@@ -77,14 +235,14 @@ var StoreClient = class {
77
235
  */
78
236
  list: (params, options) => this.request("GET", "/taxons", {
79
237
  ...options,
80
- params: sdkCore.transformListParams({ ...params })
238
+ params: transformListParams({ ...params })
81
239
  }),
82
240
  /**
83
241
  * Get a taxon by ID or permalink
84
242
  */
85
243
  get: (idOrPermalink, params, options) => this.request("GET", `/taxons/${idOrPermalink}`, {
86
244
  ...options,
87
- params: sdkCore.getParams(params)
245
+ params: getParams(params)
88
246
  }),
89
247
  /**
90
248
  * Nested resource: Products in a taxon
@@ -99,7 +257,7 @@ var StoreClient = class {
99
257
  `/taxons/${taxonId}/products`,
100
258
  {
101
259
  ...options,
102
- params: sdkCore.transformListParams({ ...params })
260
+ params: transformListParams({ ...params })
103
261
  }
104
262
  )
105
263
  }
@@ -120,7 +278,7 @@ var StoreClient = class {
120
278
  */
121
279
  get: (iso, params, options) => this.request("GET", `/countries/${iso}`, {
122
280
  ...options,
123
- params: sdkCore.getParams(params)
281
+ params: getParams(params)
124
282
  })
125
283
  };
126
284
  currencies = {
@@ -177,7 +335,7 @@ var StoreClient = class {
177
335
  get: (marketId, iso, params, options) => this.request(
178
336
  "GET",
179
337
  `/markets/${marketId}/countries/${iso}`,
180
- { ...options, params: sdkCore.getParams(params) }
338
+ { ...options, params: getParams(params) }
181
339
  )
182
340
  }
183
341
  };
@@ -214,7 +372,7 @@ var StoreClient = class {
214
372
  */
215
373
  get: (idOrNumber, params, options) => this.request("GET", `/orders/${idOrNumber}`, {
216
374
  ...options,
217
- params: sdkCore.getParams(params)
375
+ params: getParams(params)
218
376
  }),
219
377
  /**
220
378
  * Update an order
@@ -432,7 +590,7 @@ var StoreClient = class {
432
590
  list: (params, options) => this.request(
433
591
  "GET",
434
592
  "/customer/addresses",
435
- { ...options, params: sdkCore.transformListParams({ ...params }) }
593
+ { ...options, params: transformListParams({ ...params }) }
436
594
  ),
437
595
  /**
438
596
  * Get an address by ID
@@ -474,7 +632,7 @@ var StoreClient = class {
474
632
  list: (params, options) => this.request(
475
633
  "GET",
476
634
  "/customer/credit_cards",
477
- { ...options, params: sdkCore.transformListParams({ ...params }) }
635
+ { ...options, params: transformListParams({ ...params }) }
478
636
  ),
479
637
  /**
480
638
  * Get a credit card by ID
@@ -496,7 +654,7 @@ var StoreClient = class {
496
654
  list: (params, options) => this.request(
497
655
  "GET",
498
656
  "/customer/gift_cards",
499
- { ...options, params: sdkCore.transformListParams({ ...params }) }
657
+ { ...options, params: transformListParams({ ...params }) }
500
658
  ),
501
659
  /**
502
660
  * Get a gift card by ID
@@ -512,7 +670,7 @@ var StoreClient = class {
512
670
  */
513
671
  list: (params, options) => this.request("GET", "/customer/orders", {
514
672
  ...options,
515
- params: sdkCore.transformListParams({ ...params })
673
+ params: transformListParams({ ...params })
516
674
  })
517
675
  },
518
676
  /**
@@ -552,14 +710,14 @@ var StoreClient = class {
552
710
  */
553
711
  list: (params, options) => this.request("GET", "/wishlists", {
554
712
  ...options,
555
- params: sdkCore.transformListParams({ ...params })
713
+ params: transformListParams({ ...params })
556
714
  }),
557
715
  /**
558
716
  * Get a wishlist by ID
559
717
  */
560
718
  get: (id, params, options) => this.request("GET", `/wishlists/${id}`, {
561
719
  ...options,
562
- params: sdkCore.getParams(params)
720
+ params: getParams(params)
563
721
  }),
564
722
  /**
565
723
  * Create a wishlist
@@ -619,9 +777,9 @@ function createClient(config) {
619
777
  currency: config.currency,
620
778
  country: config.country
621
779
  };
622
- const retryConfig = sdkCore.resolveRetryConfig(config.retry);
780
+ const retryConfig = resolveRetryConfig(config.retry);
623
781
  const requestConfig = { baseUrl, fetchFn, retryConfig };
624
- const requestFn = sdkCore.createRequestFn(
782
+ const requestFn = createRequestFn(
625
783
  requestConfig,
626
784
  "/api/v3/store",
627
785
  { headerName: "x-spree-api-key", headerValue: config.publishableKey },
@@ -641,10 +799,7 @@ function createClient(config) {
641
799
  return client;
642
800
  }
643
801
 
644
- Object.defineProperty(exports, "SpreeError", {
645
- enumerable: true,
646
- get: function () { return sdkCore.SpreeError; }
647
- });
802
+ exports.SpreeError = SpreeError;
648
803
  exports.StoreClient = StoreClient;
649
804
  exports.createClient = createClient;
650
805
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store-client.ts","../src/client.ts"],"names":["transformListParams","getParams","resolveRetryConfig","createRequestFn"],"mappings":";;;;;AA+CO,IAAM,cAAN,MAAkB;AAAA,EACN,OAAA;AAAA,EAEjB,YAAY,OAAA,EAAoB;AAC9B,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAMS,IAAA,GAAO;AAAA;AAAA;AAAA;AAAA,IAId,KAAA,EAAO,CAAC,WAAA,KACN,IAAA,CAAK,OAAA,CAAoB,QAAQ,aAAA,EAAe,EAAE,IAAA,EAAM,WAAA,EAAa,CAAA;AAAA;AAAA;AAAA;AAAA,IAKvE,QAAA,EAAU,CAAC,M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,OAAA,EAAS,OAAA,EAAS,WAAA,EAAY;AAErE,EAAA,MAAM,SAAA,GAAYC,uBAAA;AAAA,IAChB,aAAA;AAAA,IACA,eAAA;AAAA,IACA,EAAE,UAAA,EAAY,iBAAA,EAAmB,WAAA,EAAa,OAAO,cAAA,EAAe;AAAA,IACpE;AAAA,GACF;AAEA,EAAA,MAAM,WAAA,GAAc,IAAI,WAAA,CAAY,SAAS,CAAA;AAI7C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,WAAW,CAAA;AAExC,EAAA,MAAA,CAAO,SAAA,GAAY,CAAC,MAAA,KAAmB;AACrC,IAAA,QAAA,CAAS,MAAA,GAAS,MAAA;AAAA,EACpB,CAAA;AACA,EAAA,MAAA,CAAO,WAAA,GAAc,CAAC,QAAA,KAAqB;AACzC,IAAA,QAAA,CAAS,QAAA,GAAW,QAAA;AAAA,EACtB,CAAA;AACA,EAAA,MAAA,CAAO,UAAA,GAAa,CAAC,OAAA,KAAoB;AACvC,IAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AAAA,EACrB,CAAA;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["import type { RequestFn, RequestOptions } from '@spree/sdk-core';\nimport { transformListParams, getParams } from '@spree/sdk-core';\nimport type {\n ListResponse,\n PaginatedResponse,\n ListParams,\n AuthTokens,\n LoginCredentials,\n RegisterParams,\n AddressParams,\n} from '@spree/sdk-core';\nimport type {\n ProductListParams,\n ProductFiltersParams,\n ProductFiltersResponse,\n TaxonListParams,\n OrderListParams,\n CreateCartParams,\n AddLineItemParams,\n UpdateLineItemParams,\n UpdateOrderParams,\n CreatePaymentSessionParams,\n UpdatePaymentSessionParams,\n CompletePaymentSessionParams,\n CreatePaymentSetupSessionParams,\n CompletePaymentSetupSessionParams,\n CreditCard,\n GiftCard,\n Product,\n Order,\n Country,\n Currency,\n Locale,\n Market,\n Taxonomy,\n Taxon,\n Payment,\n PaymentMethod,\n PaymentSession,\n PaymentSetupSession,\n Shipment,\n Wishlist,\n WishedItem,\n Address,\n Customer,\n} from './types';\n\nexport class StoreClient {\n private readonly request: RequestFn;\n\n constructor(request: RequestFn) {\n this.request = request;\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 // Products\n // ============================================\n\n readonly products = {\n /**\n * List products\n */\n list: (\n params?: ProductListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Product>> =>\n this.request<PaginatedResponse<Product>>('GET', '/products', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a product by ID or slug\n */\n get: (\n idOrSlug: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Product> =>\n this.request<Product>('GET', `/products/${idOrSlug}`, {\n ...options,\n params: getParams(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<Taxonomy>> =>\n this.request<PaginatedResponse<Taxonomy>>('GET', '/taxonomies', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a taxonomy by ID\n */\n get: (\n id: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Taxonomy> =>\n this.request<Taxonomy>('GET', `/taxonomies/${id}`, {\n ...options,\n params: getParams(params),\n }),\n };\n\n readonly taxons = {\n /**\n * List taxons\n */\n list: (\n params?: TaxonListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Taxon>> =>\n this.request<PaginatedResponse<Taxon>>('GET', '/taxons', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a taxon by ID or permalink\n */\n get: (\n idOrPermalink: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Taxon> =>\n this.request<Taxon>('GET', `/taxons/${idOrPermalink}`, {\n ...options,\n params: getParams(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<Product>> =>\n this.request<PaginatedResponse<Product>>(\n 'GET',\n `/taxons/${taxonId}/products`,\n {\n ...options,\n params: transformListParams({ ...params }),\n }\n ),\n },\n };\n\n // ============================================\n // Countries, Currencies & Locales\n // ============================================\n\n readonly countries = {\n /**\n * List countries available in the store\n * Each country includes currency and default_locale derived from its market\n */\n list: (options?: RequestOptions): Promise<ListResponse<Country>> =>\n this.request<ListResponse<Country>>('GET', '/countries', options),\n\n /**\n * Get a country by ISO code\n * Use `?expand=states` to expand states for address forms\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n */\n get: (\n iso: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Country> =>\n this.request<Country>('GET', `/countries/${iso}`, {\n ...options,\n params: getParams(params),\n }),\n };\n\n readonly currencies = {\n /**\n * List currencies supported by the store (derived from markets)\n */\n list: (options?: RequestOptions): Promise<ListResponse<Currency>> =>\n this.request<ListResponse<Currency>>('GET', '/currencies', options),\n };\n\n readonly locales = {\n /**\n * List locales supported by the store (derived from markets)\n */\n list: (options?: RequestOptions): Promise<ListResponse<Locale>> =>\n this.request<ListResponse<Locale>>('GET', '/locales', options),\n };\n\n // ============================================\n // Markets\n // ============================================\n\n readonly markets = {\n /**\n * List all markets for the current store\n */\n list: (options?: RequestOptions): Promise<ListResponse<Market>> =>\n this.request<ListResponse<Market>>('GET', '/markets', options),\n\n /**\n * Get a market by prefixed ID\n * @param id - Market prefixed ID (e.g., \"mkt_k5nR8xLq\")\n */\n get: (id: string, options?: RequestOptions): Promise<Market> =>\n this.request<Market>('GET', `/markets/${id}`, options),\n\n /**\n * Resolve which market applies for a given country\n * @param country - ISO 3166-1 alpha-2 code (e.g., \"DE\", \"US\")\n */\n resolve: (country: string, options?: RequestOptions): Promise<Market> =>\n this.request<Market>('GET', '/markets/resolve', {\n ...options,\n params: { country },\n }),\n\n /**\n * Nested resource: Countries in a market\n */\n countries: {\n /**\n * List countries belonging to a market\n * @param marketId - Market prefixed ID\n */\n list: (\n marketId: string,\n options?: RequestOptions\n ): Promise<ListResponse<Country>> =>\n this.request<ListResponse<Country>>(\n 'GET',\n `/markets/${marketId}/countries`,\n options\n ),\n\n /**\n * Get a country by ISO code within a market\n * @param marketId - Market prefixed ID\n * @param iso - Country ISO code (e.g., \"DE\")\n */\n get: (\n marketId: string,\n iso: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Country> =>\n this.request<Country>(\n 'GET',\n `/markets/${marketId}/countries/${iso}`,\n { ...options, params: getParams(params) }\n ),\n },\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<Order & { token: string }> =>\n this.request<Order & { token: string }>('GET', '/cart', options),\n\n /**\n * Create a new cart\n * @param params - Optional cart parameters (e.g., metadata)\n */\n create: (params?: CreateCartParams, options?: RequestOptions): Promise<Order & { token: string }> =>\n this.request<Order & { token: string }>('POST', '/cart', {\n ...options,\n body: params,\n }),\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<Order & { token: string }> =>\n this.request<Order & { token: string }>('PATCH', '/cart/associate', options),\n };\n\n // ============================================\n // Orders (individual order management & checkout)\n // ============================================\n\n readonly orders = {\n /**\n * Get an order by ID or number\n */\n get: (\n idOrNumber: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('GET', `/orders/${idOrNumber}`, {\n ...options,\n params: getParams(params),\n }),\n\n /**\n * Update an order\n */\n update: (\n idOrNumber: string,\n params: UpdateOrderParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('PATCH', `/orders/${idOrNumber}`, {\n ...options,\n body: params,\n }),\n\n /**\n * Advance order to next checkout step\n */\n next: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('PATCH', `/orders/${idOrNumber}/next`, options),\n\n /**\n * Advance through all checkout steps\n */\n advance: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${idOrNumber}/advance`,\n options\n ),\n\n /**\n * Complete the order\n */\n complete: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${idOrNumber}/complete`,\n options\n ),\n\n /**\n * Add store credit to order\n */\n addStoreCredit: (\n idOrNumber: string,\n amount?: number,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('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<Order> =>\n this.request<Order>(\n 'DELETE',\n `/orders/${idOrNumber}/store_credits`,\n options\n ),\n\n /**\n * Nested resource: Line items\n */\n lineItems: {\n /**\n * Add a line item to an order.\n * Returns the updated order with recalculated totals.\n */\n create: (\n orderId: string,\n params: AddLineItemParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('POST', `/orders/${orderId}/line_items`, {\n ...options,\n body: params,\n }),\n\n /**\n * Update a line item quantity.\n * Returns the updated order with recalculated totals.\n */\n update: (\n orderId: string,\n lineItemId: string,\n params: UpdateLineItemParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${orderId}/line_items/${lineItemId}`,\n { ...options, body: params }\n ),\n\n /**\n * Remove a line item from an order.\n * Returns the updated order with recalculated totals.\n */\n delete: (\n orderId: string,\n lineItemId: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\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<PaginatedResponse<Payment>> =>\n this.request<PaginatedResponse<Payment>>(\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<Payment> =>\n this.request<Payment>(\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<ListResponse<PaymentMethod>> =>\n this.request<ListResponse<PaymentMethod>>(\n 'GET',\n `/orders/${orderId}/payment_methods`,\n options\n ),\n },\n\n /**\n * Nested resource: Payment sessions\n */\n paymentSessions: {\n /**\n * Create a payment session for an order\n * Delegates to the payment gateway to initialize a provider-specific session\n */\n create: (\n orderId: string,\n params: CreatePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'POST',\n `/orders/${orderId}/payment_sessions`,\n { ...options, body: params }\n ),\n\n /**\n * Get a payment session by ID\n */\n get: (\n orderId: string,\n sessionId: string,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'GET',\n `/orders/${orderId}/payment_sessions/${sessionId}`,\n options\n ),\n\n /**\n * Update a payment session\n * Delegates to the payment gateway to sync changes with the provider\n */\n update: (\n orderId: string,\n sessionId: string,\n params: UpdatePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'PATCH',\n `/orders/${orderId}/payment_sessions/${sessionId}`,\n { ...options, body: params }\n ),\n\n /**\n * Complete a payment session\n * Confirms the payment with the provider, triggering capture/authorization\n */\n complete: (\n orderId: string,\n sessionId: string,\n params?: CompletePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'PATCH',\n `/orders/${orderId}/payment_sessions/${sessionId}/complete`,\n { ...options, body: params }\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<Order> =>\n this.request<Order>('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<Order> =>\n this.request<Order>(\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<ListResponse<Shipment>> =>\n this.request<ListResponse<Shipment>>(\n 'GET',\n `/orders/${orderId}/shipments`,\n options\n ),\n\n /**\n * Select a shipping rate for a shipment.\n * Returns the updated order with recalculated totals.\n */\n update: (\n orderId: string,\n shipmentId: string,\n params: { selected_shipping_rate_id: string },\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\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<Customer> =>\n this.request<Customer>('GET', '/customer', options),\n\n /**\n * Update current customer profile\n */\n update: (\n params: {\n first_name?: string\n last_name?: string\n email?: string\n password?: string\n password_confirmation?: string\n accepts_email_marketing?: boolean\n phone?: string\n },\n options?: RequestOptions\n ): Promise<Customer> =>\n this.request<Customer>('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<Address>> =>\n this.request<PaginatedResponse<Address>>(\n 'GET',\n '/customer/addresses',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get an address by ID\n */\n get: (id: string, options?: RequestOptions): Promise<Address> =>\n this.request<Address>('GET', `/customer/addresses/${id}`, options),\n\n /**\n * Create an address\n */\n create: (\n params: AddressParams,\n options?: RequestOptions\n ): Promise<Address> =>\n this.request<Address>('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<Address> =>\n this.request<Address>('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 * Mark an address as default billing or shipping\n */\n markAsDefault: (\n id: string,\n kind: 'billing' | 'shipping',\n options?: RequestOptions\n ): Promise<Address> =>\n this.request<Address>('PATCH', `/customer/addresses/${id}/mark_as_default`, {\n ...options,\n body: { kind },\n }),\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<CreditCard>> =>\n this.request<PaginatedResponse<CreditCard>>(\n 'GET',\n '/customer/credit_cards',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get a credit card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<CreditCard> =>\n this.request<CreditCard>('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<GiftCard>> =>\n this.request<PaginatedResponse<GiftCard>>(\n 'GET',\n '/customer/gift_cards',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get a gift card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<GiftCard> =>\n this.request<GiftCard>('GET', `/customer/gift_cards/${id}`, options),\n },\n\n /**\n * Nested resource: Orders (customer order history)\n */\n orders: {\n /**\n * List orders for the authenticated customer\n */\n list: (\n params?: OrderListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Order>> =>\n this.request<PaginatedResponse<Order>>('GET', '/customer/orders', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n },\n\n /**\n * Nested resource: Payment Setup Sessions (save payment methods for future use)\n */\n paymentSetupSessions: {\n /**\n * Create a payment setup session\n * Delegates to the payment gateway to initialize a setup flow for saving a payment method\n */\n create: (\n params: CreatePaymentSetupSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>(\n 'POST',\n '/customer/payment_setup_sessions',\n { ...options, body: params }\n ),\n\n /**\n * Get a payment setup session by ID\n */\n get: (id: string, options?: RequestOptions): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>('GET', `/customer/payment_setup_sessions/${id}`, options),\n\n /**\n * Complete a payment setup session\n * Confirms the setup with the provider, resulting in a saved payment method\n */\n complete: (\n id: string,\n params?: CompletePaymentSetupSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>(\n 'PATCH',\n `/customer/payment_setup_sessions/${id}/complete`,\n { ...options, body: params }\n ),\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<Wishlist>> =>\n this.request<PaginatedResponse<Wishlist>>('GET', '/wishlists', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a wishlist by ID\n */\n get: (\n id: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Wishlist> =>\n this.request<Wishlist>('GET', `/wishlists/${id}`, {\n ...options,\n params: getParams(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<Wishlist> =>\n this.request<Wishlist>('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<Wishlist> =>\n this.request<Wishlist>('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<WishedItem> =>\n this.request<WishedItem>('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<WishedItem> =>\n this.request<WishedItem>(\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","import { createRequestFn, resolveRetryConfig } from '@spree/sdk-core';\nimport type { RetryConfig, RequestConfig, LocaleDefaults } from '@spree/sdk-core';\nimport { StoreClient } from './store-client';\n\nexport interface ClientConfig {\n /** Base URL of the Spree API (e.g., 'https://api.mystore.com') */\n baseUrl: string;\n /** Publishable API key for Store API access */\n publishableKey: string;\n /** Custom fetch implementation (optional, defaults to global fetch) */\n fetch?: typeof fetch;\n /** Retry configuration. Enabled by default. Pass false to disable. */\n retry?: RetryConfig | false;\n /** Default locale for API requests (e.g., 'fr') */\n locale?: string;\n /** Default currency for API requests (e.g., 'EUR') */\n currency?: string;\n /** Default country ISO code for market resolution (e.g., 'FR') */\n country?: string;\n}\n\nexport interface Client extends StoreClient {\n /** Set default locale for all subsequent requests */\n setLocale(locale: string): void;\n /** Set default currency for all subsequent requests */\n setCurrency(currency: string): void;\n /** Set default country for all subsequent requests */\n setCountry(country: string): void;\n}\n\n/**\n * Create a new Spree Store SDK client.\n *\n * Returns a flat client with all store resources directly accessible:\n * ```ts\n * const client = createClient({ baseUrl: '...', publishableKey: '...' })\n * client.products.list()\n * client.cart.create()\n * client.orders.get('order_1')\n * ```\n */\nexport function createClient(config: ClientConfig): Client {\n const baseUrl = config.baseUrl.replace(/\\/$/, '');\n const fetchFn = config.fetch || fetch.bind(globalThis);\n\n const defaults: LocaleDefaults = {\n locale: config.locale,\n currency: config.currency,\n country: config.country,\n };\n\n const retryConfig = resolveRetryConfig(config.retry);\n\n const requestConfig: RequestConfig = { baseUrl, fetchFn, retryConfig };\n\n const requestFn = createRequestFn(\n requestConfig,\n '/api/v3/store',\n { headerName: 'x-spree-api-key', headerValue: config.publishableKey },\n defaults\n );\n\n const storeClient = new StoreClient(requestFn);\n\n // Build the flat client by spreading StoreClient's prototype methods/properties\n // and adding locale/currency/country setters\n const client = Object.create(storeClient) as Client;\n\n client.setLocale = (locale: string) => {\n defaults.locale = locale;\n };\n client.setCurrency = (currency: string) => {\n defaults.currency = currency;\n };\n client.setCountry = (country: string) => {\n defaults.country = country;\n };\n\n return client;\n}\n"]}
1
+ {"version":3,"sources":["../../sdk-core/src/request.ts","../../sdk-core/src/params.ts","../../sdk-core/src/helpers.ts","../src/store-client.ts","../src/client.ts"],"names":[],"mappings":";;;AAqCO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AACpB,EAAA,IAAA;AACA,EAAA,MAAA;AACA,EAAA,OAAA;AAEhB,EAAA,WAAA,CAAY,UAAyB,MAAA,EAAgB;AACnD,IAAA,KAAA,CAAM,QAAA,CAAS,MAAM,OAAO,CAAA;AAC5B,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,SAAS,KAAA,CAAM,IAAA;AAC3B,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAA,CAAM,OAAA;AAChC,EAAA;AACF;AAQA,SAAS,cAAA,CAAe,SAAiB,MAAA,EAAuC;AAC9E,EAAA,MAAM,mBAAmB,MAAA,CAAO,SAAA,GAAY,IAAA,CAAK,GAAA,CAAI,GAAG,OAAO,CAAA;AAC/D,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,EAAA,GAAW,MAAA,CA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AS,CAAA;AAI7C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,WAAW,CAAA;AAExC,EAAA,MAAA,CAAO,SAAA,GAAY,CAAC,MAAA,KAAmB;AACrC,IAAA,QAAA,CAAS,MAAA,GAAS,MAAA;AAAA,EACpB,CAAA;AACA,EAAA,MAAA,CAAO,WAAA,GAAc,CAAC,QAAA,KAAqB;AACzC,IAAA,QAAA,CAAS,QAAA,GAAW,QAAA;AAAA,EACtB,CAAA;AACA,EAAA,MAAA,CAAO,UAAA,GAAa,CAAC,OAAA,KAAoB;AACvC,IAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AAAA,EACrB,CAAA;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["import type { ErrorResponse, LocaleDefaults } from './types';\n\nexport interface RetryConfig {\n /** Maximum number of retries (default: 2) */\n maxRetries?: number;\n /** HTTP status codes to retry on (default: [429, 500, 502, 503, 504]) */\n retryOnStatus?: number[];\n /** Base delay in ms for exponential backoff (default: 300) */\n baseDelay?: number;\n /** Maximum delay in ms (default: 10000) */\n maxDelay?: number;\n /** Whether to retry on network errors (default: true) */\n retryOnNetworkError?: boolean;\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 /** Country ISO code for market resolution (e.g., 'US', 'DE') */\n country?: string;\n /** Idempotency key for safe retries of mutating requests (max 255 characters) */\n idempotencyKey?: string;\n /** Custom headers */\n headers?: Record<string, string>;\n}\n\nexport interface InternalRequestOptions extends RequestOptions {\n body?: unknown;\n params?: Record<string, string | number | boolean | (string | number)[] | undefined>;\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 type RequestFn = <T>(\n method: string,\n path: string,\n options?: InternalRequestOptions\n) => Promise<T>;\n\nfunction calculateDelay(attempt: number, config: Required<RetryConfig>): number {\n const exponentialDelay = config.baseDelay * Math.pow(2, attempt);\n const jitter = Math.random() * config.baseDelay;\n return Math.min(exponentialDelay + jitter, config.maxDelay);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction generateIdempotencyKey(): string {\n return `spree-sdk-retry-${crypto.randomUUID()}`;\n}\n\nfunction shouldRetryOnStatus(method: string, status: number, config: Required<RetryConfig>, hasIdempotencyKey: boolean): boolean {\n const isIdempotent = method === 'GET' || method === 'HEAD' || hasIdempotencyKey;\n if (isIdempotent) {\n return config.retryOnStatus.includes(status);\n }\n return status === 429;\n}\n\nfunction shouldRetryOnNetworkError(method: string, config: Required<RetryConfig>, hasIdempotencyKey: boolean): boolean {\n if (!config.retryOnNetworkError) return false;\n return method === 'GET' || method === 'HEAD' || hasIdempotencyKey;\n}\n\nexport interface RequestConfig {\n baseUrl: string;\n fetchFn: typeof fetch;\n retryConfig: Required<RetryConfig> | false;\n}\n\nexport interface AuthConfig {\n headerName: string;\n headerValue: string;\n}\n\n/**\n * Creates a bound request function for a specific API scope (store or admin).\n */\nexport function createRequestFn(\n config: RequestConfig,\n basePath: string,\n auth: AuthConfig,\n defaults?: LocaleDefaults\n): RequestFn {\n return async function request<T>(\n method: string,\n path: string,\n options: InternalRequestOptions = {}\n ): Promise<T> {\n const { token, orderToken, idempotencyKey, headers = {}, body, params } = options;\n\n // Per-request options override client-level defaults\n const locale = options.locale ?? defaults?.locale;\n const currency = options.currency ?? defaults?.currency;\n const country = options.country ?? defaults?.country;\n\n // Build URL with query params\n const url = new URL(`${config.baseUrl}${basePath}${path}`);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\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 // Build headers\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n if (auth.headerName && auth.headerValue) {\n requestHeaders[auth.headerName] = auth.headerValue;\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 if (country) {\n requestHeaders['x-spree-country'] = country;\n }\n\n // Auto-generate idempotency key for mutating requests when retries are enabled (Stripe-style).\n // User-supplied keys take precedence over auto-generated ones.\n const isMutating = method !== 'GET' && method !== 'HEAD';\n const effectiveIdempotencyKey = idempotencyKey ?? (isMutating && config.retryConfig ? generateIdempotencyKey() : undefined);\n\n if (effectiveIdempotencyKey) {\n requestHeaders['Idempotency-Key'] = effectiveIdempotencyKey;\n }\n\n const hasIdempotencyKey = !!effectiveIdempotencyKey;\n const maxAttempts = config.retryConfig ? config.retryConfig.maxRetries + 1 : 1;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n try {\n const response = await config.fetchFn(url.toString(), {\n method,\n headers: requestHeaders,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n const isLastAttempt = attempt >= maxAttempts - 1;\n\n if (!isLastAttempt && config.retryConfig && shouldRetryOnStatus(method, response.status, config.retryConfig, hasIdempotencyKey)) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter\n ? Math.min(parseInt(retryAfter, 10) * 1000, config.retryConfig.maxDelay)\n : calculateDelay(attempt, config.retryConfig);\n await sleep(delay);\n continue;\n }\n\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 } catch (error) {\n if (error instanceof SpreeError) {\n throw error;\n }\n\n const isLastAttempt = attempt >= maxAttempts - 1;\n\n if (!isLastAttempt && config.retryConfig && shouldRetryOnNetworkError(method, config.retryConfig, hasIdempotencyKey)) {\n const delay = calculateDelay(attempt, config.retryConfig);\n await sleep(delay);\n continue;\n }\n\n throw error;\n }\n }\n\n // This should never be reached, but TypeScript needs it\n throw new Error('Unexpected end of retry loop');\n };\n}\n","/**\n * Keys that are passed through to the API without wrapping in q[...].\n */\nconst PASSTHROUGH_KEYS = new Set(['page', 'limit', 'expand', 'sort', 'fields']);\n\ntype ParamValue = string | number | boolean | (string | number)[] | undefined;\n\n/**\n * Transforms flat SDK params into Ransack-compatible query params.\n *\n * - `page`, `limit`, `expand`, `sort` pass through unchanged\n * - Keys already in `q[...]` format pass through (backward compat)\n * - All other keys are wrapped: `name_cont` → `q[name_cont]`\n */\nexport function transformListParams(\n params: Record<string, unknown>\n): Record<string, ParamValue> {\n const result: Record<string, ParamValue> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n\n if (PASSTHROUGH_KEYS.has(key)) {\n // Join arrays for passthrough keys (e.g., expand: ['variants', 'images'] → 'variants,images')\n result[key] = Array.isArray(value) ? (value as (string | number)[]).join(',') : value as ParamValue;\n continue;\n }\n\n // Backward compat: already-wrapped q[...] keys pass through\n if (key.startsWith('q[')) {\n result[key] = value as ParamValue;\n continue;\n }\n\n // Array values get [] suffix automatically: `foo: [1,2]` → `q[foo][]`\n if (Array.isArray(value)) {\n const base = key.endsWith('[]') ? key.slice(0, -2) : key;\n result[`q[${base}][]`] = value as ParamValue;\n } else {\n result[`q[${key}]`] = value as ParamValue;\n }\n }\n\n return result;\n}\n","/** Serialize expand/fields arrays into comma-separated query params */\nexport function getParams(params?: { expand?: string[]; fields?: string[] }): Record<string, string> | undefined {\n if (!params) return undefined;\n const result: Record<string, string> = {};\n if (params.expand?.length) result.expand = params.expand.join(',');\n if (params.fields?.length) result.fields = params.fields.join(',');\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\n/** Resolve retry config with defaults */\nexport interface ResolvedRetryConfig {\n maxRetries: number;\n retryOnStatus: number[];\n baseDelay: number;\n maxDelay: number;\n retryOnNetworkError: boolean;\n}\n\nexport function resolveRetryConfig(retry?: import('./request').RetryConfig | false): ResolvedRetryConfig | false {\n if (retry === false) return false;\n return {\n maxRetries: retry?.maxRetries ?? 2,\n retryOnStatus: retry?.retryOnStatus ?? [429, 500, 502, 503, 504],\n baseDelay: retry?.baseDelay ?? 300,\n maxDelay: retry?.maxDelay ?? 10000,\n retryOnNetworkError: retry?.retryOnNetworkError ?? true,\n };\n}\n","import type { RequestFn, RequestOptions } from '@spree/sdk-core';\nimport { transformListParams, getParams } from '@spree/sdk-core';\nimport type {\n ListResponse,\n PaginatedResponse,\n ListParams,\n AuthTokens,\n LoginCredentials,\n RegisterParams,\n AddressParams,\n} from '@spree/sdk-core';\nimport type {\n ProductListParams,\n ProductFiltersParams,\n ProductFiltersResponse,\n TaxonListParams,\n OrderListParams,\n CreateCartParams,\n AddLineItemParams,\n UpdateLineItemParams,\n UpdateOrderParams,\n CreatePaymentSessionParams,\n UpdatePaymentSessionParams,\n CompletePaymentSessionParams,\n CreatePaymentSetupSessionParams,\n CompletePaymentSetupSessionParams,\n CreditCard,\n GiftCard,\n Product,\n Order,\n Country,\n Currency,\n Locale,\n Market,\n Taxonomy,\n Taxon,\n Payment,\n PaymentMethod,\n PaymentSession,\n PaymentSetupSession,\n Shipment,\n Wishlist,\n WishedItem,\n Address,\n Customer,\n} from './types';\n\nexport class StoreClient {\n private readonly request: RequestFn;\n\n constructor(request: RequestFn) {\n this.request = request;\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 // Products\n // ============================================\n\n readonly products = {\n /**\n * List products\n */\n list: (\n params?: ProductListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Product>> =>\n this.request<PaginatedResponse<Product>>('GET', '/products', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a product by ID or slug\n */\n get: (\n idOrSlug: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Product> =>\n this.request<Product>('GET', `/products/${idOrSlug}`, {\n ...options,\n params: getParams(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<Taxonomy>> =>\n this.request<PaginatedResponse<Taxonomy>>('GET', '/taxonomies', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a taxonomy by ID\n */\n get: (\n id: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Taxonomy> =>\n this.request<Taxonomy>('GET', `/taxonomies/${id}`, {\n ...options,\n params: getParams(params),\n }),\n };\n\n readonly taxons = {\n /**\n * List taxons\n */\n list: (\n params?: TaxonListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Taxon>> =>\n this.request<PaginatedResponse<Taxon>>('GET', '/taxons', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a taxon by ID or permalink\n */\n get: (\n idOrPermalink: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Taxon> =>\n this.request<Taxon>('GET', `/taxons/${idOrPermalink}`, {\n ...options,\n params: getParams(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<Product>> =>\n this.request<PaginatedResponse<Product>>(\n 'GET',\n `/taxons/${taxonId}/products`,\n {\n ...options,\n params: transformListParams({ ...params }),\n }\n ),\n },\n };\n\n // ============================================\n // Countries, Currencies & Locales\n // ============================================\n\n readonly countries = {\n /**\n * List countries available in the store\n * Each country includes currency and default_locale derived from its market\n */\n list: (options?: RequestOptions): Promise<ListResponse<Country>> =>\n this.request<ListResponse<Country>>('GET', '/countries', options),\n\n /**\n * Get a country by ISO code\n * Use `?expand=states` to expand states for address forms\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n */\n get: (\n iso: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Country> =>\n this.request<Country>('GET', `/countries/${iso}`, {\n ...options,\n params: getParams(params),\n }),\n };\n\n readonly currencies = {\n /**\n * List currencies supported by the store (derived from markets)\n */\n list: (options?: RequestOptions): Promise<ListResponse<Currency>> =>\n this.request<ListResponse<Currency>>('GET', '/currencies', options),\n };\n\n readonly locales = {\n /**\n * List locales supported by the store (derived from markets)\n */\n list: (options?: RequestOptions): Promise<ListResponse<Locale>> =>\n this.request<ListResponse<Locale>>('GET', '/locales', options),\n };\n\n // ============================================\n // Markets\n // ============================================\n\n readonly markets = {\n /**\n * List all markets for the current store\n */\n list: (options?: RequestOptions): Promise<ListResponse<Market>> =>\n this.request<ListResponse<Market>>('GET', '/markets', options),\n\n /**\n * Get a market by prefixed ID\n * @param id - Market prefixed ID (e.g., \"mkt_k5nR8xLq\")\n */\n get: (id: string, options?: RequestOptions): Promise<Market> =>\n this.request<Market>('GET', `/markets/${id}`, options),\n\n /**\n * Resolve which market applies for a given country\n * @param country - ISO 3166-1 alpha-2 code (e.g., \"DE\", \"US\")\n */\n resolve: (country: string, options?: RequestOptions): Promise<Market> =>\n this.request<Market>('GET', '/markets/resolve', {\n ...options,\n params: { country },\n }),\n\n /**\n * Nested resource: Countries in a market\n */\n countries: {\n /**\n * List countries belonging to a market\n * @param marketId - Market prefixed ID\n */\n list: (\n marketId: string,\n options?: RequestOptions\n ): Promise<ListResponse<Country>> =>\n this.request<ListResponse<Country>>(\n 'GET',\n `/markets/${marketId}/countries`,\n options\n ),\n\n /**\n * Get a country by ISO code within a market\n * @param marketId - Market prefixed ID\n * @param iso - Country ISO code (e.g., \"DE\")\n */\n get: (\n marketId: string,\n iso: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Country> =>\n this.request<Country>(\n 'GET',\n `/markets/${marketId}/countries/${iso}`,\n { ...options, params: getParams(params) }\n ),\n },\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<Order & { token: string }> =>\n this.request<Order & { token: string }>('GET', '/cart', options),\n\n /**\n * Create a new cart\n * @param params - Optional cart parameters (e.g., metadata)\n */\n create: (params?: CreateCartParams, options?: RequestOptions): Promise<Order & { token: string }> =>\n this.request<Order & { token: string }>('POST', '/cart', {\n ...options,\n body: params,\n }),\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<Order & { token: string }> =>\n this.request<Order & { token: string }>('PATCH', '/cart/associate', options),\n };\n\n // ============================================\n // Orders (individual order management & checkout)\n // ============================================\n\n readonly orders = {\n /**\n * Get an order by ID or number\n */\n get: (\n idOrNumber: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('GET', `/orders/${idOrNumber}`, {\n ...options,\n params: getParams(params),\n }),\n\n /**\n * Update an order\n */\n update: (\n idOrNumber: string,\n params: UpdateOrderParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('PATCH', `/orders/${idOrNumber}`, {\n ...options,\n body: params,\n }),\n\n /**\n * Advance order to next checkout step\n */\n next: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('PATCH', `/orders/${idOrNumber}/next`, options),\n\n /**\n * Advance through all checkout steps\n */\n advance: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${idOrNumber}/advance`,\n options\n ),\n\n /**\n * Complete the order\n */\n complete: (\n idOrNumber: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${idOrNumber}/complete`,\n options\n ),\n\n /**\n * Add store credit to order\n */\n addStoreCredit: (\n idOrNumber: string,\n amount?: number,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('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<Order> =>\n this.request<Order>(\n 'DELETE',\n `/orders/${idOrNumber}/store_credits`,\n options\n ),\n\n /**\n * Nested resource: Line items\n */\n lineItems: {\n /**\n * Add a line item to an order.\n * Returns the updated order with recalculated totals.\n */\n create: (\n orderId: string,\n params: AddLineItemParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>('POST', `/orders/${orderId}/line_items`, {\n ...options,\n body: params,\n }),\n\n /**\n * Update a line item quantity.\n * Returns the updated order with recalculated totals.\n */\n update: (\n orderId: string,\n lineItemId: string,\n params: UpdateLineItemParams,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\n 'PATCH',\n `/orders/${orderId}/line_items/${lineItemId}`,\n { ...options, body: params }\n ),\n\n /**\n * Remove a line item from an order.\n * Returns the updated order with recalculated totals.\n */\n delete: (\n orderId: string,\n lineItemId: string,\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\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<PaginatedResponse<Payment>> =>\n this.request<PaginatedResponse<Payment>>(\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<Payment> =>\n this.request<Payment>(\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<ListResponse<PaymentMethod>> =>\n this.request<ListResponse<PaymentMethod>>(\n 'GET',\n `/orders/${orderId}/payment_methods`,\n options\n ),\n },\n\n /**\n * Nested resource: Payment sessions\n */\n paymentSessions: {\n /**\n * Create a payment session for an order\n * Delegates to the payment gateway to initialize a provider-specific session\n */\n create: (\n orderId: string,\n params: CreatePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'POST',\n `/orders/${orderId}/payment_sessions`,\n { ...options, body: params }\n ),\n\n /**\n * Get a payment session by ID\n */\n get: (\n orderId: string,\n sessionId: string,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'GET',\n `/orders/${orderId}/payment_sessions/${sessionId}`,\n options\n ),\n\n /**\n * Update a payment session\n * Delegates to the payment gateway to sync changes with the provider\n */\n update: (\n orderId: string,\n sessionId: string,\n params: UpdatePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'PATCH',\n `/orders/${orderId}/payment_sessions/${sessionId}`,\n { ...options, body: params }\n ),\n\n /**\n * Complete a payment session\n * Confirms the payment with the provider, triggering capture/authorization\n */\n complete: (\n orderId: string,\n sessionId: string,\n params?: CompletePaymentSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSession> =>\n this.request<PaymentSession>(\n 'PATCH',\n `/orders/${orderId}/payment_sessions/${sessionId}/complete`,\n { ...options, body: params }\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<Order> =>\n this.request<Order>('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<Order> =>\n this.request<Order>(\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<ListResponse<Shipment>> =>\n this.request<ListResponse<Shipment>>(\n 'GET',\n `/orders/${orderId}/shipments`,\n options\n ),\n\n /**\n * Select a shipping rate for a shipment.\n * Returns the updated order with recalculated totals.\n */\n update: (\n orderId: string,\n shipmentId: string,\n params: { selected_shipping_rate_id: string },\n options?: RequestOptions\n ): Promise<Order> =>\n this.request<Order>(\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<Customer> =>\n this.request<Customer>('GET', '/customer', options),\n\n /**\n * Update current customer profile\n */\n update: (\n params: {\n first_name?: string\n last_name?: string\n email?: string\n password?: string\n password_confirmation?: string\n accepts_email_marketing?: boolean\n phone?: string\n },\n options?: RequestOptions\n ): Promise<Customer> =>\n this.request<Customer>('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<Address>> =>\n this.request<PaginatedResponse<Address>>(\n 'GET',\n '/customer/addresses',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get an address by ID\n */\n get: (id: string, options?: RequestOptions): Promise<Address> =>\n this.request<Address>('GET', `/customer/addresses/${id}`, options),\n\n /**\n * Create an address\n */\n create: (\n params: AddressParams,\n options?: RequestOptions\n ): Promise<Address> =>\n this.request<Address>('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<Address> =>\n this.request<Address>('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 * Mark an address as default billing or shipping\n */\n markAsDefault: (\n id: string,\n kind: 'billing' | 'shipping',\n options?: RequestOptions\n ): Promise<Address> =>\n this.request<Address>('PATCH', `/customer/addresses/${id}/mark_as_default`, {\n ...options,\n body: { kind },\n }),\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<CreditCard>> =>\n this.request<PaginatedResponse<CreditCard>>(\n 'GET',\n '/customer/credit_cards',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get a credit card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<CreditCard> =>\n this.request<CreditCard>('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<GiftCard>> =>\n this.request<PaginatedResponse<GiftCard>>(\n 'GET',\n '/customer/gift_cards',\n { ...options, params: transformListParams({ ...params }) }\n ),\n\n /**\n * Get a gift card by ID\n */\n get: (id: string, options?: RequestOptions): Promise<GiftCard> =>\n this.request<GiftCard>('GET', `/customer/gift_cards/${id}`, options),\n },\n\n /**\n * Nested resource: Orders (customer order history)\n */\n orders: {\n /**\n * List orders for the authenticated customer\n */\n list: (\n params?: OrderListParams,\n options?: RequestOptions\n ): Promise<PaginatedResponse<Order>> =>\n this.request<PaginatedResponse<Order>>('GET', '/customer/orders', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n },\n\n /**\n * Nested resource: Payment Setup Sessions (save payment methods for future use)\n */\n paymentSetupSessions: {\n /**\n * Create a payment setup session\n * Delegates to the payment gateway to initialize a setup flow for saving a payment method\n */\n create: (\n params: CreatePaymentSetupSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>(\n 'POST',\n '/customer/payment_setup_sessions',\n { ...options, body: params }\n ),\n\n /**\n * Get a payment setup session by ID\n */\n get: (id: string, options?: RequestOptions): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>('GET', `/customer/payment_setup_sessions/${id}`, options),\n\n /**\n * Complete a payment setup session\n * Confirms the setup with the provider, resulting in a saved payment method\n */\n complete: (\n id: string,\n params?: CompletePaymentSetupSessionParams,\n options?: RequestOptions\n ): Promise<PaymentSetupSession> =>\n this.request<PaymentSetupSession>(\n 'PATCH',\n `/customer/payment_setup_sessions/${id}/complete`,\n { ...options, body: params }\n ),\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<Wishlist>> =>\n this.request<PaginatedResponse<Wishlist>>('GET', '/wishlists', {\n ...options,\n params: transformListParams({ ...params }),\n }),\n\n /**\n * Get a wishlist by ID\n */\n get: (\n id: string,\n params?: { expand?: string[]; fields?: string[] },\n options?: RequestOptions\n ): Promise<Wishlist> =>\n this.request<Wishlist>('GET', `/wishlists/${id}`, {\n ...options,\n params: getParams(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<Wishlist> =>\n this.request<Wishlist>('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<Wishlist> =>\n this.request<Wishlist>('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<WishedItem> =>\n this.request<WishedItem>('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<WishedItem> =>\n this.request<WishedItem>(\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","import { createRequestFn, resolveRetryConfig } from '@spree/sdk-core';\nimport type { RetryConfig, RequestConfig, LocaleDefaults } from '@spree/sdk-core';\nimport { StoreClient } from './store-client';\n\nexport interface ClientConfig {\n /** Base URL of the Spree API (e.g., 'https://api.mystore.com') */\n baseUrl: string;\n /** Publishable API key for Store API access */\n publishableKey: string;\n /** Custom fetch implementation (optional, defaults to global fetch) */\n fetch?: typeof fetch;\n /** Retry configuration. Enabled by default. Pass false to disable. */\n retry?: RetryConfig | false;\n /** Default locale for API requests (e.g., 'fr') */\n locale?: string;\n /** Default currency for API requests (e.g., 'EUR') */\n currency?: string;\n /** Default country ISO code for market resolution (e.g., 'FR') */\n country?: string;\n}\n\nexport interface Client extends StoreClient {\n /** Set default locale for all subsequent requests */\n setLocale(locale: string): void;\n /** Set default currency for all subsequent requests */\n setCurrency(currency: string): void;\n /** Set default country for all subsequent requests */\n setCountry(country: string): void;\n}\n\n/**\n * Create a new Spree Store SDK client.\n *\n * Returns a flat client with all store resources directly accessible:\n * ```ts\n * const client = createClient({ baseUrl: '...', publishableKey: '...' })\n * client.products.list()\n * client.cart.create()\n * client.orders.get('order_1')\n * ```\n */\nexport function createClient(config: ClientConfig): Client {\n const baseUrl = config.baseUrl.replace(/\\/$/, '');\n const fetchFn = config.fetch || fetch.bind(globalThis);\n\n const defaults: LocaleDefaults = {\n locale: config.locale,\n currency: config.currency,\n country: config.country,\n };\n\n const retryConfig = resolveRetryConfig(config.retry);\n\n const requestConfig: RequestConfig = { baseUrl, fetchFn, retryConfig };\n\n const requestFn = createRequestFn(\n requestConfig,\n '/api/v3/store',\n { headerName: 'x-spree-api-key', headerValue: config.publishableKey },\n defaults\n );\n\n const storeClient = new StoreClient(requestFn);\n\n // Build the flat client by spreading StoreClient's prototype methods/properties\n // and adding locale/currency/country setters\n const client = Object.create(storeClient) as Client;\n\n client.setLocale = (locale: string) => {\n defaults.locale = locale;\n };\n client.setCurrency = (currency: string) => {\n defaults.currency = currency;\n };\n client.setCountry = (country: string) => {\n defaults.country = country;\n };\n\n return client;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,5 @@
1
- import { RequestFn, LoginCredentials, AuthTokens, RegisterParams, RequestOptions, PaginatedResponse, ListParams, ListResponse, AddressParams, RetryConfig } from '@spree/sdk-core';
2
- export { AddressParams, AuthTokens, ErrorResponse, ListParams, ListResponse, LocaleDefaults, LoginCredentials, PaginatedResponse, PaginationMeta, RegisterParams, RequestOptions, RetryConfig, SpreeError } from '@spree/sdk-core';
3
- import { ProductListParams, Product, ProductFiltersParams, ProductFiltersResponse, StoreTaxonomy as Taxonomy, TaxonListParams, StoreTaxon as Taxon, Country, Currency, Locale, Market, Order, CreateCartParams, UpdateOrderParams, AddLineItemParams, UpdateLineItemParams, Payment, PaymentMethod, CreatePaymentSessionParams, PaymentSession, UpdatePaymentSessionParams, CompletePaymentSessionParams, Shipment, Customer, Address, CreditCard, GiftCard, OrderListParams, CreatePaymentSetupSessionParams, PaymentSetupSession, CompletePaymentSetupSessionParams, StoreWishlist as Wishlist, StoreWishedItem as WishedItem } from './types/index.cjs';
4
- export { Asset, AvailabilityFilter, Base, CustomerReturn, Digital, DigitalLink, Export, FilterOption, GiftCardBatch, Image, Import, ImportRow, Invitation, LineItem, LineItemInput, Metafield, NewsletterSubscriber, OptionFilter, OptionFilterOption, OptionType, OptionValue, OrderPromotion, PaymentSource, Price, PriceRangeFilter, ProductFilter, Promotion, Refund, Reimbursement, Report, ReturnAuthorization, ReturnItem, ShippingCategory, ShippingMethod, ShippingRate, SortOption, State, StockItem, StockLocation, StockMovement, StockTransfer, Asset as StoreAsset, StoreCredit, CustomerReturn as StoreCustomerReturn, Digital as StoreDigital, DigitalLink as StoreDigitalLink, GiftCardBatch as StoreGiftCardBatch, Image as StoreImage, LineItem as StoreLineItem, Metafield as StoreMetafield, OptionType as StoreOptionType, OptionValue as StoreOptionValue, OrderPromotion as StoreOrderPromotion, PaymentSource as StorePaymentSource, Price as StorePrice, Promotion as StorePromotion, Refund as StoreRefund, Reimbursement as StoreReimbursement, ReturnAuthorization as StoreReturnAuthorization, ReturnItem as StoreReturnItem, ShippingCategory as StoreShippingCategory, ShippingMethod as StoreShippingMethod, ShippingRate as StoreShippingRate, State as StoreState, StockItem as StoreStockItem, StockLocation as StoreStockLocation, StoreCredit as StoreStoreCredit, StoreTaxCategory, StoreVariant, StoreTaxCategory as TaxCategory, TaxonFilter, TaxonFilterOption, StoreVariant as Variant } from './types/index.cjs';
1
+ import { R as RequestFn, L as LoginCredentials, A as AuthTokens, a as RegisterParams, b as RequestOptions, P as ProductListParams, c as PaginatedResponse, d as Product, e as ProductFiltersParams, f as ProductFiltersResponse, g as ListParams, T as Taxonomy, h as TaxonListParams, i as Taxon, j as ListResponse, C as Country, k as Currency, l as Locale, M as Market, O as Order, m as CreateCartParams, U as UpdateOrderParams, n as AddLineItemParams, o as UpdateLineItemParams, p as Payment, q as PaymentMethod, r as CreatePaymentSessionParams, s as PaymentSession, t as UpdatePaymentSessionParams, u as CompletePaymentSessionParams, S as Shipment, v as Customer, w as Address, x as AddressParams, y as CreditCard, G as GiftCard, z as OrderListParams, B as CreatePaymentSetupSessionParams, D as PaymentSetupSession, E as CompletePaymentSetupSessionParams, W as Wishlist, F as WishedItem, H as RetryConfig } from './index-CgJG4R8P.cjs';
2
+ export { I as Asset, J as AvailabilityFilter, K as Base, N as CustomerReturn, Q as Digital, V as DigitalLink, X as ErrorResponse, Y as Export, Z as FilterOption, _ as GiftCardBatch, $ as Image, a0 as Import, a1 as ImportRow, a2 as Invitation, a3 as LineItem, a4 as LineItemInput, a5 as LocaleDefaults, a6 as Metafield, a7 as NewsletterSubscriber, a8 as OptionFilter, a9 as OptionFilterOption, aa as OptionType, ab as OptionValue, ac as OrderPromotion, ad as PaginationMeta, ae as PaymentSource, af as Price, ag as PriceRangeFilter, ah as ProductFilter, ai as Promotion, aj as Refund, ak as Reimbursement, al as Report, am as ReturnAuthorization, an as ReturnItem, ao as ShippingCategory, ap as ShippingMethod, aq as ShippingRate, ar as SortOption, as as SpreeError, at as State, au as StockItem, av as StockLocation, aw as StockMovement, ax as StockTransfer, I as StoreAsset, ay as StoreCredit, N as StoreCustomerReturn, Q as StoreDigital, V as StoreDigitalLink, _ as StoreGiftCardBatch, $ as StoreImage, a3 as StoreLineItem, a6 as StoreMetafield, aa as StoreOptionType, ab as StoreOptionValue, ac as StoreOrderPromotion, ae as StorePaymentSource, af as StorePrice, ai as StorePromotion, aj as StoreRefund, ak as StoreReimbursement, am as StoreReturnAuthorization, an as StoreReturnItem, ao as StoreShippingCategory, ap as StoreShippingMethod, aq as StoreShippingRate, at as StoreState, au as StoreStockItem, av as StoreStockLocation, ay as StoreStoreCredit, az as StoreTaxCategory, aA as StoreVariant, az as TaxCategory, aB as TaxonFilter, aC as TaxonFilterOption, aA as Variant } from './index-CgJG4R8P.cjs';
5
3
 
6
4
  declare class StoreClient {
7
5
  private readonly request;
@@ -490,4 +488,4 @@ interface Client extends StoreClient {
490
488
  */
491
489
  declare function createClient(config: ClientConfig): Client;
492
490
 
493
- export { AddLineItemParams, Address, type Client, type ClientConfig, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, Country, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, CreditCard, Currency, Customer, GiftCard, Locale, Market, Order, OrderListParams, Payment, PaymentMethod, PaymentSession, PaymentSetupSession, Product, ProductFiltersParams, ProductFiltersResponse, ProductListParams, Shipment, Address as StoreAddress, StoreClient, Country as StoreCountry, CreditCard as StoreCreditCard, Currency as StoreCurrency, Customer as StoreCustomer, GiftCard as StoreGiftCard, Locale as StoreLocale, Market as StoreMarket, Order as StoreOrder, Payment as StorePayment, PaymentMethod as StorePaymentMethod, PaymentSession as StorePaymentSession, PaymentSetupSession as StorePaymentSetupSession, Product as StoreProduct, Shipment as StoreShipment, Taxon as StoreTaxon, Taxonomy as StoreTaxonomy, WishedItem as StoreWishedItem, Wishlist as StoreWishlist, Taxon, TaxonListParams, Taxonomy, UpdateLineItemParams, UpdateOrderParams, UpdatePaymentSessionParams, WishedItem, Wishlist, createClient };
491
+ export { AddLineItemParams, Address, AddressParams, AuthTokens, type Client, type ClientConfig, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, Country, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, CreditCard, Currency, Customer, GiftCard, ListParams, ListResponse, Locale, LoginCredentials, Market, Order, OrderListParams, PaginatedResponse, Payment, PaymentMethod, PaymentSession, PaymentSetupSession, Product, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, RequestOptions, RetryConfig, Shipment, Address as StoreAddress, StoreClient, Country as StoreCountry, CreditCard as StoreCreditCard, Currency as StoreCurrency, Customer as StoreCustomer, GiftCard as StoreGiftCard, Locale as StoreLocale, Market as StoreMarket, Order as StoreOrder, Payment as StorePayment, PaymentMethod as StorePaymentMethod, PaymentSession as StorePaymentSession, PaymentSetupSession as StorePaymentSetupSession, Product as StoreProduct, Shipment as StoreShipment, Taxon as StoreTaxon, Taxonomy as StoreTaxonomy, WishedItem as StoreWishedItem, Wishlist as StoreWishlist, Taxon, TaxonListParams, Taxonomy, UpdateLineItemParams, UpdateOrderParams, UpdatePaymentSessionParams, WishedItem, Wishlist, createClient };