@spree/sdk 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/dist/index.cjs +32 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -33
- package/dist/index.d.ts +14 -33
- package/dist/index.js +32 -30
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.cts +18 -31
- package/dist/types/index.d.ts +18 -31
- package/dist/zod/index.cjs +19 -39
- package/dist/zod/index.cjs.map +1 -1
- package/dist/zod/index.d.cts +19 -77
- package/dist/zod/index.d.ts +19 -77
- package/dist/zod/index.js +20 -39
- package/dist/zod/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorResponse, LoginCredentials, AuthTokens, RegisterParams,
|
|
1
|
+
import { ErrorResponse, LoginCredentials, AuthTokens, RegisterParams, ProductListParams, PaginatedResponse, StoreProduct, ProductFiltersParams, ProductFiltersResponse, ListParams, StoreTaxonomy, TaxonListParams, StoreTaxon, ListResponse, StoreCountry, StoreCurrency, StoreLocale, StoreMarket, StoreOrder, CreateCartParams, UpdateOrderParams, AddLineItemParams, UpdateLineItemParams, StorePayment, StorePaymentMethod, CreatePaymentSessionParams, StorePaymentSession, UpdatePaymentSessionParams, CompletePaymentSessionParams, StoreShipment, StoreCustomer, StoreAddress, AddressParams, StoreCreditCard, StoreGiftCard, OrderListParams, CreatePaymentSetupSessionParams, StorePaymentSetupSession, CompletePaymentSetupSessionParams, StoreWishlist, StoreWishedItem } from './types/index.cjs';
|
|
2
2
|
export { AdminCustomer, AdminLineItem, AdminMetafield, AdminOrder, AdminPrice, AdminProduct, AdminTaxon, AdminTaxonomy, AdminVariant, AvailabilityFilter, FilterOption, LocaleDefaults, OptionFilter, OptionFilterOption, PaginationMeta, PriceRangeFilter, ProductFilter, SortOption, StoreAsset, StoreBase, StoreCustomerReturn, StoreDigital, StoreDigitalLink, StoreExport, StoreGiftCardBatch, StoreImage, StoreImport, StoreImportRow, StoreInvitation, StoreLineItem, StoreMetafield, StoreNewsletterSubscriber, StoreOptionType, StoreOptionValue, StoreOrderPromotion, StorePaymentSource, StorePrice, StorePromotion, StoreRefund, StoreReimbursement, StoreReport, StoreReturnAuthorization, StoreReturnItem, StoreShippingMethod, StoreShippingRate, StoreState, StoreStockItem, StoreStockLocation, StoreStockMovement, StoreStockTransfer, StoreStoreCredit, StoreVariant, TaxonFilter, TaxonFilterOption } from './types/index.cjs';
|
|
3
3
|
|
|
4
4
|
interface RetryConfig {
|
|
@@ -24,6 +24,8 @@ interface RequestOptions {
|
|
|
24
24
|
currency?: string;
|
|
25
25
|
/** Country ISO code for market resolution (e.g., 'US', 'DE') */
|
|
26
26
|
country?: string;
|
|
27
|
+
/** Idempotency key for safe retries of mutating requests (max 255 characters) */
|
|
28
|
+
idempotencyKey?: string;
|
|
27
29
|
/** Custom headers */
|
|
28
30
|
headers?: Record<string, string>;
|
|
29
31
|
}
|
|
@@ -56,12 +58,6 @@ declare class StoreClient {
|
|
|
56
58
|
*/
|
|
57
59
|
refresh: (options: RequestOptions) => Promise<AuthTokens>;
|
|
58
60
|
};
|
|
59
|
-
readonly store: {
|
|
60
|
-
/**
|
|
61
|
-
* Get current store information
|
|
62
|
-
*/
|
|
63
|
-
get: (options?: RequestOptions) => Promise<StoreStore>;
|
|
64
|
-
};
|
|
65
61
|
readonly products: {
|
|
66
62
|
/**
|
|
67
63
|
* List products
|
|
@@ -118,9 +114,7 @@ declare class StoreClient {
|
|
|
118
114
|
* List countries available in the store
|
|
119
115
|
* Each country includes currency and default_locale derived from its market
|
|
120
116
|
*/
|
|
121
|
-
list: (options?: RequestOptions) => Promise<
|
|
122
|
-
data: StoreCountry[];
|
|
123
|
-
}>;
|
|
117
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreCountry>>;
|
|
124
118
|
/**
|
|
125
119
|
* Get a country by ISO code
|
|
126
120
|
* Use `?expand=states` to expand states for address forms
|
|
@@ -134,25 +128,19 @@ declare class StoreClient {
|
|
|
134
128
|
/**
|
|
135
129
|
* List currencies supported by the store (derived from markets)
|
|
136
130
|
*/
|
|
137
|
-
list: (options?: RequestOptions) => Promise<
|
|
138
|
-
data: StoreCurrency[];
|
|
139
|
-
}>;
|
|
131
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreCurrency>>;
|
|
140
132
|
};
|
|
141
133
|
readonly locales: {
|
|
142
134
|
/**
|
|
143
135
|
* List locales supported by the store (derived from markets)
|
|
144
136
|
*/
|
|
145
|
-
list: (options?: RequestOptions) => Promise<
|
|
146
|
-
data: StoreLocale[];
|
|
147
|
-
}>;
|
|
137
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreLocale>>;
|
|
148
138
|
};
|
|
149
139
|
readonly markets: {
|
|
150
140
|
/**
|
|
151
141
|
* List all markets for the current store
|
|
152
142
|
*/
|
|
153
|
-
list: (options?: RequestOptions) => Promise<
|
|
154
|
-
data: StoreMarket[];
|
|
155
|
-
}>;
|
|
143
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreMarket>>;
|
|
156
144
|
/**
|
|
157
145
|
* Get a market by prefixed ID
|
|
158
146
|
* @param id - Market prefixed ID (e.g., "mkt_k5nR8xLq")
|
|
@@ -171,9 +159,7 @@ declare class StoreClient {
|
|
|
171
159
|
* List countries belonging to a market
|
|
172
160
|
* @param marketId - Market prefixed ID
|
|
173
161
|
*/
|
|
174
|
-
list: (marketId: string, options?: RequestOptions) => Promise<
|
|
175
|
-
data: StoreCountry[];
|
|
176
|
-
}>;
|
|
162
|
+
list: (marketId: string, options?: RequestOptions) => Promise<ListResponse<StoreCountry>>;
|
|
177
163
|
/**
|
|
178
164
|
* Get a country by ISO code within a market
|
|
179
165
|
* @param marketId - Market prefixed ID
|
|
@@ -266,10 +252,7 @@ declare class StoreClient {
|
|
|
266
252
|
/**
|
|
267
253
|
* List payments for an order
|
|
268
254
|
*/
|
|
269
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
270
|
-
data: StorePayment[];
|
|
271
|
-
meta: object;
|
|
272
|
-
}>;
|
|
255
|
+
list: (orderId: string, options?: RequestOptions) => Promise<PaginatedResponse<StorePayment>>;
|
|
273
256
|
/**
|
|
274
257
|
* Get a payment by ID
|
|
275
258
|
*/
|
|
@@ -282,7 +265,7 @@ declare class StoreClient {
|
|
|
282
265
|
/**
|
|
283
266
|
* List available payment methods for an order
|
|
284
267
|
*/
|
|
285
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
268
|
+
list: (orderId: string, options?: RequestOptions) => Promise<ListResponse<StorePaymentMethod>>;
|
|
286
269
|
};
|
|
287
270
|
/**
|
|
288
271
|
* Nested resource: Payment sessions
|
|
@@ -329,9 +312,7 @@ declare class StoreClient {
|
|
|
329
312
|
/**
|
|
330
313
|
* List shipments for an order
|
|
331
314
|
*/
|
|
332
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
333
|
-
data: StoreShipment[];
|
|
334
|
-
}>;
|
|
315
|
+
list: (orderId: string, options?: RequestOptions) => Promise<ListResponse<StoreShipment>>;
|
|
335
316
|
/**
|
|
336
317
|
* Select a shipping rate for a shipment.
|
|
337
318
|
* Returns the updated order with recalculated totals.
|
|
@@ -512,8 +493,8 @@ declare class AdminClient {
|
|
|
512
493
|
interface SpreeClientConfig {
|
|
513
494
|
/** Base URL of the Spree API (e.g., 'https://api.mystore.com') */
|
|
514
495
|
baseUrl: string;
|
|
515
|
-
/** Publishable API key for Store API access */
|
|
516
|
-
publishableKey
|
|
496
|
+
/** Publishable API key for Store API access (required for Store API) */
|
|
497
|
+
publishableKey?: string;
|
|
517
498
|
/** Secret API key for Admin API access (optional) */
|
|
518
499
|
secretKey?: string;
|
|
519
500
|
/** Custom fetch implementation (optional, defaults to global fetch) */
|
|
@@ -546,4 +527,4 @@ declare class SpreeClient {
|
|
|
546
527
|
*/
|
|
547
528
|
declare function createSpreeClient(config: SpreeClientConfig): SpreeClient;
|
|
548
529
|
|
|
549
|
-
export { AddLineItemParams, AddressParams, AdminClient, AuthTokens, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, ErrorResponse, ListParams, LoginCredentials, OrderListParams, PaginatedResponse, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, type RequestOptions, type RetryConfig, SpreeClient, type SpreeClientConfig, SpreeError, StoreAddress, StoreClient, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreGiftCard, StoreLocale, StoreMarket, StoreOrder, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StoreProduct, StoreShipment,
|
|
530
|
+
export { AddLineItemParams, AddressParams, AdminClient, AuthTokens, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, ErrorResponse, ListParams, ListResponse, LoginCredentials, OrderListParams, PaginatedResponse, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, type RequestOptions, type RetryConfig, SpreeClient, type SpreeClientConfig, SpreeError, StoreAddress, StoreClient, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreGiftCard, StoreLocale, StoreMarket, StoreOrder, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StoreProduct, StoreShipment, StoreTaxon, StoreTaxonomy, StoreWishedItem, StoreWishlist, TaxonListParams, UpdateLineItemParams, UpdateOrderParams, UpdatePaymentSessionParams, createSpreeClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorResponse, LoginCredentials, AuthTokens, RegisterParams,
|
|
1
|
+
import { ErrorResponse, LoginCredentials, AuthTokens, RegisterParams, ProductListParams, PaginatedResponse, StoreProduct, ProductFiltersParams, ProductFiltersResponse, ListParams, StoreTaxonomy, TaxonListParams, StoreTaxon, ListResponse, StoreCountry, StoreCurrency, StoreLocale, StoreMarket, StoreOrder, CreateCartParams, UpdateOrderParams, AddLineItemParams, UpdateLineItemParams, StorePayment, StorePaymentMethod, CreatePaymentSessionParams, StorePaymentSession, UpdatePaymentSessionParams, CompletePaymentSessionParams, StoreShipment, StoreCustomer, StoreAddress, AddressParams, StoreCreditCard, StoreGiftCard, OrderListParams, CreatePaymentSetupSessionParams, StorePaymentSetupSession, CompletePaymentSetupSessionParams, StoreWishlist, StoreWishedItem } from './types/index.js';
|
|
2
2
|
export { AdminCustomer, AdminLineItem, AdminMetafield, AdminOrder, AdminPrice, AdminProduct, AdminTaxon, AdminTaxonomy, AdminVariant, AvailabilityFilter, FilterOption, LocaleDefaults, OptionFilter, OptionFilterOption, PaginationMeta, PriceRangeFilter, ProductFilter, SortOption, StoreAsset, StoreBase, StoreCustomerReturn, StoreDigital, StoreDigitalLink, StoreExport, StoreGiftCardBatch, StoreImage, StoreImport, StoreImportRow, StoreInvitation, StoreLineItem, StoreMetafield, StoreNewsletterSubscriber, StoreOptionType, StoreOptionValue, StoreOrderPromotion, StorePaymentSource, StorePrice, StorePromotion, StoreRefund, StoreReimbursement, StoreReport, StoreReturnAuthorization, StoreReturnItem, StoreShippingMethod, StoreShippingRate, StoreState, StoreStockItem, StoreStockLocation, StoreStockMovement, StoreStockTransfer, StoreStoreCredit, StoreVariant, TaxonFilter, TaxonFilterOption } from './types/index.js';
|
|
3
3
|
|
|
4
4
|
interface RetryConfig {
|
|
@@ -24,6 +24,8 @@ interface RequestOptions {
|
|
|
24
24
|
currency?: string;
|
|
25
25
|
/** Country ISO code for market resolution (e.g., 'US', 'DE') */
|
|
26
26
|
country?: string;
|
|
27
|
+
/** Idempotency key for safe retries of mutating requests (max 255 characters) */
|
|
28
|
+
idempotencyKey?: string;
|
|
27
29
|
/** Custom headers */
|
|
28
30
|
headers?: Record<string, string>;
|
|
29
31
|
}
|
|
@@ -56,12 +58,6 @@ declare class StoreClient {
|
|
|
56
58
|
*/
|
|
57
59
|
refresh: (options: RequestOptions) => Promise<AuthTokens>;
|
|
58
60
|
};
|
|
59
|
-
readonly store: {
|
|
60
|
-
/**
|
|
61
|
-
* Get current store information
|
|
62
|
-
*/
|
|
63
|
-
get: (options?: RequestOptions) => Promise<StoreStore>;
|
|
64
|
-
};
|
|
65
61
|
readonly products: {
|
|
66
62
|
/**
|
|
67
63
|
* List products
|
|
@@ -118,9 +114,7 @@ declare class StoreClient {
|
|
|
118
114
|
* List countries available in the store
|
|
119
115
|
* Each country includes currency and default_locale derived from its market
|
|
120
116
|
*/
|
|
121
|
-
list: (options?: RequestOptions) => Promise<
|
|
122
|
-
data: StoreCountry[];
|
|
123
|
-
}>;
|
|
117
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreCountry>>;
|
|
124
118
|
/**
|
|
125
119
|
* Get a country by ISO code
|
|
126
120
|
* Use `?expand=states` to expand states for address forms
|
|
@@ -134,25 +128,19 @@ declare class StoreClient {
|
|
|
134
128
|
/**
|
|
135
129
|
* List currencies supported by the store (derived from markets)
|
|
136
130
|
*/
|
|
137
|
-
list: (options?: RequestOptions) => Promise<
|
|
138
|
-
data: StoreCurrency[];
|
|
139
|
-
}>;
|
|
131
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreCurrency>>;
|
|
140
132
|
};
|
|
141
133
|
readonly locales: {
|
|
142
134
|
/**
|
|
143
135
|
* List locales supported by the store (derived from markets)
|
|
144
136
|
*/
|
|
145
|
-
list: (options?: RequestOptions) => Promise<
|
|
146
|
-
data: StoreLocale[];
|
|
147
|
-
}>;
|
|
137
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreLocale>>;
|
|
148
138
|
};
|
|
149
139
|
readonly markets: {
|
|
150
140
|
/**
|
|
151
141
|
* List all markets for the current store
|
|
152
142
|
*/
|
|
153
|
-
list: (options?: RequestOptions) => Promise<
|
|
154
|
-
data: StoreMarket[];
|
|
155
|
-
}>;
|
|
143
|
+
list: (options?: RequestOptions) => Promise<ListResponse<StoreMarket>>;
|
|
156
144
|
/**
|
|
157
145
|
* Get a market by prefixed ID
|
|
158
146
|
* @param id - Market prefixed ID (e.g., "mkt_k5nR8xLq")
|
|
@@ -171,9 +159,7 @@ declare class StoreClient {
|
|
|
171
159
|
* List countries belonging to a market
|
|
172
160
|
* @param marketId - Market prefixed ID
|
|
173
161
|
*/
|
|
174
|
-
list: (marketId: string, options?: RequestOptions) => Promise<
|
|
175
|
-
data: StoreCountry[];
|
|
176
|
-
}>;
|
|
162
|
+
list: (marketId: string, options?: RequestOptions) => Promise<ListResponse<StoreCountry>>;
|
|
177
163
|
/**
|
|
178
164
|
* Get a country by ISO code within a market
|
|
179
165
|
* @param marketId - Market prefixed ID
|
|
@@ -266,10 +252,7 @@ declare class StoreClient {
|
|
|
266
252
|
/**
|
|
267
253
|
* List payments for an order
|
|
268
254
|
*/
|
|
269
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
270
|
-
data: StorePayment[];
|
|
271
|
-
meta: object;
|
|
272
|
-
}>;
|
|
255
|
+
list: (orderId: string, options?: RequestOptions) => Promise<PaginatedResponse<StorePayment>>;
|
|
273
256
|
/**
|
|
274
257
|
* Get a payment by ID
|
|
275
258
|
*/
|
|
@@ -282,7 +265,7 @@ declare class StoreClient {
|
|
|
282
265
|
/**
|
|
283
266
|
* List available payment methods for an order
|
|
284
267
|
*/
|
|
285
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
268
|
+
list: (orderId: string, options?: RequestOptions) => Promise<ListResponse<StorePaymentMethod>>;
|
|
286
269
|
};
|
|
287
270
|
/**
|
|
288
271
|
* Nested resource: Payment sessions
|
|
@@ -329,9 +312,7 @@ declare class StoreClient {
|
|
|
329
312
|
/**
|
|
330
313
|
* List shipments for an order
|
|
331
314
|
*/
|
|
332
|
-
list: (orderId: string, options?: RequestOptions) => Promise<
|
|
333
|
-
data: StoreShipment[];
|
|
334
|
-
}>;
|
|
315
|
+
list: (orderId: string, options?: RequestOptions) => Promise<ListResponse<StoreShipment>>;
|
|
335
316
|
/**
|
|
336
317
|
* Select a shipping rate for a shipment.
|
|
337
318
|
* Returns the updated order with recalculated totals.
|
|
@@ -512,8 +493,8 @@ declare class AdminClient {
|
|
|
512
493
|
interface SpreeClientConfig {
|
|
513
494
|
/** Base URL of the Spree API (e.g., 'https://api.mystore.com') */
|
|
514
495
|
baseUrl: string;
|
|
515
|
-
/** Publishable API key for Store API access */
|
|
516
|
-
publishableKey
|
|
496
|
+
/** Publishable API key for Store API access (required for Store API) */
|
|
497
|
+
publishableKey?: string;
|
|
517
498
|
/** Secret API key for Admin API access (optional) */
|
|
518
499
|
secretKey?: string;
|
|
519
500
|
/** Custom fetch implementation (optional, defaults to global fetch) */
|
|
@@ -546,4 +527,4 @@ declare class SpreeClient {
|
|
|
546
527
|
*/
|
|
547
528
|
declare function createSpreeClient(config: SpreeClientConfig): SpreeClient;
|
|
548
529
|
|
|
549
|
-
export { AddLineItemParams, AddressParams, AdminClient, AuthTokens, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, ErrorResponse, ListParams, LoginCredentials, OrderListParams, PaginatedResponse, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, type RequestOptions, type RetryConfig, SpreeClient, type SpreeClientConfig, SpreeError, StoreAddress, StoreClient, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreGiftCard, StoreLocale, StoreMarket, StoreOrder, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StoreProduct, StoreShipment,
|
|
530
|
+
export { AddLineItemParams, AddressParams, AdminClient, AuthTokens, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, ErrorResponse, ListParams, ListResponse, LoginCredentials, OrderListParams, PaginatedResponse, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, type RequestOptions, type RetryConfig, SpreeClient, type SpreeClientConfig, SpreeError, StoreAddress, StoreClient, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreGiftCard, StoreLocale, StoreMarket, StoreOrder, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StoreProduct, StoreShipment, StoreTaxon, StoreTaxonomy, StoreWishedItem, StoreWishlist, TaxonListParams, UpdateLineItemParams, UpdateOrderParams, UpdatePaymentSessionParams, createSpreeClient };
|
package/dist/index.js
CHANGED
|
@@ -19,20 +19,23 @@ function calculateDelay(attempt, config) {
|
|
|
19
19
|
function sleep(ms) {
|
|
20
20
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
22
|
+
function generateIdempotencyKey() {
|
|
23
|
+
return `spree-sdk-retry-${crypto.randomUUID()}`;
|
|
24
|
+
}
|
|
25
|
+
function shouldRetryOnStatus(method, status, config, hasIdempotencyKey) {
|
|
26
|
+
const isIdempotent = method === "GET" || method === "HEAD" || hasIdempotencyKey;
|
|
24
27
|
if (isIdempotent) {
|
|
25
28
|
return config.retryOnStatus.includes(status);
|
|
26
29
|
}
|
|
27
30
|
return status === 429;
|
|
28
31
|
}
|
|
29
|
-
function shouldRetryOnNetworkError(method, config) {
|
|
32
|
+
function shouldRetryOnNetworkError(method, config, hasIdempotencyKey) {
|
|
30
33
|
if (!config.retryOnNetworkError) return false;
|
|
31
|
-
return method === "GET" || method === "HEAD";
|
|
34
|
+
return method === "GET" || method === "HEAD" || hasIdempotencyKey;
|
|
32
35
|
}
|
|
33
36
|
function createRequestFn(config, basePath, auth, defaults) {
|
|
34
37
|
return async function request(method, path, options = {}) {
|
|
35
|
-
const { token, orderToken, headers = {}, body, params } = options;
|
|
38
|
+
const { token, orderToken, idempotencyKey, headers = {}, body, params } = options;
|
|
36
39
|
const locale = options.locale ?? defaults?.locale;
|
|
37
40
|
const currency = options.currency ?? defaults?.currency;
|
|
38
41
|
const country = options.country ?? defaults?.country;
|
|
@@ -48,14 +51,13 @@ function createRequestFn(config, basePath, auth, defaults) {
|
|
|
48
51
|
}
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
|
-
if (orderToken) {
|
|
52
|
-
url.searchParams.set("order_token", orderToken);
|
|
53
|
-
}
|
|
54
54
|
const requestHeaders = {
|
|
55
55
|
"Content-Type": "application/json",
|
|
56
|
-
[auth.headerName]: auth.headerValue,
|
|
57
56
|
...headers
|
|
58
57
|
};
|
|
58
|
+
if (auth.headerName && auth.headerValue) {
|
|
59
|
+
requestHeaders[auth.headerName] = auth.headerValue;
|
|
60
|
+
}
|
|
59
61
|
if (token) {
|
|
60
62
|
requestHeaders["Authorization"] = `Bearer ${token}`;
|
|
61
63
|
}
|
|
@@ -71,6 +73,12 @@ function createRequestFn(config, basePath, auth, defaults) {
|
|
|
71
73
|
if (country) {
|
|
72
74
|
requestHeaders["x-spree-country"] = country;
|
|
73
75
|
}
|
|
76
|
+
const isMutating = method !== "GET" && method !== "HEAD";
|
|
77
|
+
const effectiveIdempotencyKey = idempotencyKey ?? (isMutating && config.retryConfig ? generateIdempotencyKey() : void 0);
|
|
78
|
+
if (effectiveIdempotencyKey) {
|
|
79
|
+
requestHeaders["Idempotency-Key"] = effectiveIdempotencyKey;
|
|
80
|
+
}
|
|
81
|
+
const hasIdempotencyKey = !!effectiveIdempotencyKey;
|
|
74
82
|
const maxAttempts = config.retryConfig ? config.retryConfig.maxRetries + 1 : 1;
|
|
75
83
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
76
84
|
try {
|
|
@@ -81,7 +89,7 @@ function createRequestFn(config, basePath, auth, defaults) {
|
|
|
81
89
|
});
|
|
82
90
|
if (!response.ok) {
|
|
83
91
|
const isLastAttempt = attempt >= maxAttempts - 1;
|
|
84
|
-
if (!isLastAttempt && config.retryConfig && shouldRetryOnStatus(method, response.status, config.retryConfig)) {
|
|
92
|
+
if (!isLastAttempt && config.retryConfig && shouldRetryOnStatus(method, response.status, config.retryConfig, hasIdempotencyKey)) {
|
|
85
93
|
const retryAfter = response.headers.get("Retry-After");
|
|
86
94
|
const delay = retryAfter ? Math.min(parseInt(retryAfter, 10) * 1e3, config.retryConfig.maxDelay) : calculateDelay(attempt, config.retryConfig);
|
|
87
95
|
await sleep(delay);
|
|
@@ -99,7 +107,7 @@ function createRequestFn(config, basePath, auth, defaults) {
|
|
|
99
107
|
throw error;
|
|
100
108
|
}
|
|
101
109
|
const isLastAttempt = attempt >= maxAttempts - 1;
|
|
102
|
-
if (!isLastAttempt && config.retryConfig && shouldRetryOnNetworkError(method, config.retryConfig)) {
|
|
110
|
+
if (!isLastAttempt && config.retryConfig && shouldRetryOnNetworkError(method, config.retryConfig, hasIdempotencyKey)) {
|
|
103
111
|
const delay = calculateDelay(attempt, config.retryConfig);
|
|
104
112
|
await sleep(delay);
|
|
105
113
|
continue;
|
|
@@ -163,15 +171,6 @@ var StoreClient = class {
|
|
|
163
171
|
refresh: (options) => this.request("POST", "/auth/refresh", options)
|
|
164
172
|
};
|
|
165
173
|
// ============================================
|
|
166
|
-
// Store
|
|
167
|
-
// ============================================
|
|
168
|
-
store = {
|
|
169
|
-
/**
|
|
170
|
-
* Get current store information
|
|
171
|
-
*/
|
|
172
|
-
get: (options) => this.request("GET", "/store", options)
|
|
173
|
-
};
|
|
174
|
-
// ============================================
|
|
175
174
|
// Products
|
|
176
175
|
// ============================================
|
|
177
176
|
products = {
|
|
@@ -180,7 +179,7 @@ var StoreClient = class {
|
|
|
180
179
|
*/
|
|
181
180
|
list: (params, options) => this.request("GET", "/products", {
|
|
182
181
|
...options,
|
|
183
|
-
params:
|
|
182
|
+
params: transformListParams({ ...params })
|
|
184
183
|
}),
|
|
185
184
|
/**
|
|
186
185
|
* Get a product by ID or slug
|
|
@@ -207,7 +206,7 @@ var StoreClient = class {
|
|
|
207
206
|
*/
|
|
208
207
|
list: (params, options) => this.request("GET", "/taxonomies", {
|
|
209
208
|
...options,
|
|
210
|
-
params
|
|
209
|
+
params: transformListParams({ ...params })
|
|
211
210
|
}),
|
|
212
211
|
/**
|
|
213
212
|
* Get a taxonomy by ID
|
|
@@ -223,7 +222,7 @@ var StoreClient = class {
|
|
|
223
222
|
*/
|
|
224
223
|
list: (params, options) => this.request("GET", "/taxons", {
|
|
225
224
|
...options,
|
|
226
|
-
params:
|
|
225
|
+
params: transformListParams({ ...params })
|
|
227
226
|
}),
|
|
228
227
|
/**
|
|
229
228
|
* Get a taxon by ID or permalink
|
|
@@ -245,7 +244,7 @@ var StoreClient = class {
|
|
|
245
244
|
`/taxons/${taxonId}/products`,
|
|
246
245
|
{
|
|
247
246
|
...options,
|
|
248
|
-
params:
|
|
247
|
+
params: transformListParams({ ...params })
|
|
249
248
|
}
|
|
250
249
|
)
|
|
251
250
|
}
|
|
@@ -578,7 +577,7 @@ var StoreClient = class {
|
|
|
578
577
|
list: (params, options) => this.request(
|
|
579
578
|
"GET",
|
|
580
579
|
"/customer/addresses",
|
|
581
|
-
{ ...options, params }
|
|
580
|
+
{ ...options, params: transformListParams({ ...params }) }
|
|
582
581
|
),
|
|
583
582
|
/**
|
|
584
583
|
* Get an address by ID
|
|
@@ -620,7 +619,7 @@ var StoreClient = class {
|
|
|
620
619
|
list: (params, options) => this.request(
|
|
621
620
|
"GET",
|
|
622
621
|
"/customer/credit_cards",
|
|
623
|
-
{ ...options, params }
|
|
622
|
+
{ ...options, params: transformListParams({ ...params }) }
|
|
624
623
|
),
|
|
625
624
|
/**
|
|
626
625
|
* Get a credit card by ID
|
|
@@ -642,7 +641,7 @@ var StoreClient = class {
|
|
|
642
641
|
list: (params, options) => this.request(
|
|
643
642
|
"GET",
|
|
644
643
|
"/customer/gift_cards",
|
|
645
|
-
{ ...options, params }
|
|
644
|
+
{ ...options, params: transformListParams({ ...params }) }
|
|
646
645
|
),
|
|
647
646
|
/**
|
|
648
647
|
* Get a gift card by ID
|
|
@@ -658,7 +657,7 @@ var StoreClient = class {
|
|
|
658
657
|
*/
|
|
659
658
|
list: (params, options) => this.request("GET", "/customer/orders", {
|
|
660
659
|
...options,
|
|
661
|
-
params:
|
|
660
|
+
params: transformListParams({ ...params })
|
|
662
661
|
})
|
|
663
662
|
},
|
|
664
663
|
/**
|
|
@@ -698,7 +697,7 @@ var StoreClient = class {
|
|
|
698
697
|
*/
|
|
699
698
|
list: (params, options) => this.request("GET", "/wishlists", {
|
|
700
699
|
...options,
|
|
701
|
-
params
|
|
700
|
+
params: transformListParams({ ...params })
|
|
702
701
|
}),
|
|
703
702
|
/**
|
|
704
703
|
* Get a wishlist by ID
|
|
@@ -774,6 +773,9 @@ var SpreeClient = class {
|
|
|
774
773
|
admin;
|
|
775
774
|
_defaults;
|
|
776
775
|
constructor(config) {
|
|
776
|
+
if (!config.publishableKey && !config.secretKey) {
|
|
777
|
+
throw new Error("SpreeClient requires at least one of publishableKey or secretKey");
|
|
778
|
+
}
|
|
777
779
|
const baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
778
780
|
const fetchFn = config.fetch || fetch.bind(globalThis);
|
|
779
781
|
this._defaults = {
|
|
@@ -797,7 +799,7 @@ var SpreeClient = class {
|
|
|
797
799
|
const storeRequestFn = createRequestFn(
|
|
798
800
|
requestConfig,
|
|
799
801
|
"/api/v3/store",
|
|
800
|
-
{ headerName: "x-spree-api-key", headerValue: config.publishableKey },
|
|
802
|
+
config.publishableKey ? { headerName: "x-spree-api-key", headerValue: config.publishableKey } : { headerName: "", headerValue: "" },
|
|
801
803
|
this._defaults
|
|
802
804
|
);
|
|
803
805
|
const adminRequestFn = createRequestFn(
|