@spree/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +649 -0
- package/dist/index.cjs +534 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +389 -0
- package/dist/index.d.ts +389 -0
- package/dist/index.js +530 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +786 -0
- package/dist/types/index.d.ts +786 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +91 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { LoginCredentials, AuthTokens, RegisterParams, StoreStore, ProductListParams, PaginatedResponse, StoreProduct, ProductFiltersParams, ProductFiltersResponse, ListParams, StoreTaxonomy, TaxonListParams, StoreTaxon, StoreCountry, StoreOrder, OrderListParams, UpdateOrderParams, AddLineItemParams, StoreLineItem, UpdateLineItemParams, StorePayment, StorePaymentMethod, StoreShipment, StoreUser, StoreAddress, AddressParams, StoreCreditCard, StoreGiftCard, StoreWishlist, StoreWishedItem, ErrorResponse } from './types/index.js';
|
|
2
|
+
export { AdminMetafield, AdminOrder, AdminPrice, AdminProduct, AdminTaxon, AdminTaxonomy, AdminUser, AdminVariant, AvailabilityFilter, FilterOption, OptionFilter, OptionFilterOption, PaginationMeta, PriceRangeFilter, ProductFilter, SortOption, StoreBase, StoreDigitalLink, StoreImage, StoreMetafield, StoreOptionType, StoreOptionValue, StoreOrderPromotion, StorePrice, StoreShippingMethod, StoreShippingRate, StoreState, StoreStockLocation, StoreVariant, TaxonFilter, TaxonFilterOption } from './types/index.js';
|
|
3
|
+
|
|
4
|
+
interface SpreeClientConfig {
|
|
5
|
+
/** Base URL of the Spree API (e.g., 'https://api.mystore.com') */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/** Publishable API key for store access */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/** Custom fetch implementation (optional, defaults to global fetch) */
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
interface RequestOptions {
|
|
13
|
+
/** Bearer token for authenticated requests */
|
|
14
|
+
token?: string;
|
|
15
|
+
/** Order token for guest checkout */
|
|
16
|
+
orderToken?: string;
|
|
17
|
+
/** Locale for translated content (e.g., 'en', 'fr') */
|
|
18
|
+
locale?: string;
|
|
19
|
+
/** Currency for prices (e.g., 'USD', 'EUR') */
|
|
20
|
+
currency?: string;
|
|
21
|
+
/** Custom headers */
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
declare class SpreeError extends Error {
|
|
25
|
+
readonly code: string;
|
|
26
|
+
readonly status: number;
|
|
27
|
+
readonly details?: Record<string, string[]>;
|
|
28
|
+
constructor(response: ErrorResponse, status: number);
|
|
29
|
+
}
|
|
30
|
+
declare class SpreeClient {
|
|
31
|
+
private readonly baseUrl;
|
|
32
|
+
private readonly apiKey;
|
|
33
|
+
private readonly fetchFn;
|
|
34
|
+
constructor(config: SpreeClientConfig);
|
|
35
|
+
private request;
|
|
36
|
+
readonly auth: {
|
|
37
|
+
/**
|
|
38
|
+
* Login with email and password
|
|
39
|
+
*/
|
|
40
|
+
login: (credentials: LoginCredentials) => Promise<AuthTokens>;
|
|
41
|
+
/**
|
|
42
|
+
* Register a new customer account
|
|
43
|
+
*/
|
|
44
|
+
register: (params: RegisterParams) => Promise<AuthTokens>;
|
|
45
|
+
/**
|
|
46
|
+
* Refresh access token (requires valid Bearer token)
|
|
47
|
+
*/
|
|
48
|
+
refresh: (options: RequestOptions) => Promise<AuthTokens>;
|
|
49
|
+
};
|
|
50
|
+
readonly store: {
|
|
51
|
+
/**
|
|
52
|
+
* Get current store information
|
|
53
|
+
*/
|
|
54
|
+
get: (options?: RequestOptions) => Promise<StoreStore>;
|
|
55
|
+
};
|
|
56
|
+
readonly products: {
|
|
57
|
+
/**
|
|
58
|
+
* List products
|
|
59
|
+
*/
|
|
60
|
+
list: (params?: ProductListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreProduct>>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a product by ID or slug
|
|
63
|
+
*/
|
|
64
|
+
get: (idOrSlug: string, params?: {
|
|
65
|
+
includes?: string;
|
|
66
|
+
}, options?: RequestOptions) => Promise<StoreProduct>;
|
|
67
|
+
/**
|
|
68
|
+
* Get available filters for products
|
|
69
|
+
* Returns filter options (price range, availability, option types, taxons) with counts
|
|
70
|
+
*/
|
|
71
|
+
filters: (params?: ProductFiltersParams, options?: RequestOptions) => Promise<ProductFiltersResponse>;
|
|
72
|
+
};
|
|
73
|
+
readonly taxonomies: {
|
|
74
|
+
/**
|
|
75
|
+
* List taxonomies
|
|
76
|
+
*/
|
|
77
|
+
list: (params?: ListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreTaxonomy>>;
|
|
78
|
+
/**
|
|
79
|
+
* Get a taxonomy by ID
|
|
80
|
+
*/
|
|
81
|
+
get: (id: string, params?: {
|
|
82
|
+
includes?: string;
|
|
83
|
+
}, options?: RequestOptions) => Promise<StoreTaxonomy>;
|
|
84
|
+
};
|
|
85
|
+
readonly taxons: {
|
|
86
|
+
/**
|
|
87
|
+
* List taxons
|
|
88
|
+
*/
|
|
89
|
+
list: (params?: TaxonListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreTaxon>>;
|
|
90
|
+
/**
|
|
91
|
+
* Get a taxon by ID or permalink
|
|
92
|
+
*/
|
|
93
|
+
get: (idOrPermalink: string, params?: {
|
|
94
|
+
includes?: string;
|
|
95
|
+
}, options?: RequestOptions) => Promise<StoreTaxon>;
|
|
96
|
+
/**
|
|
97
|
+
* Nested resource: Products in a taxon
|
|
98
|
+
*/
|
|
99
|
+
products: {
|
|
100
|
+
/**
|
|
101
|
+
* List products in a taxon
|
|
102
|
+
* @param taxonId - Taxon ID (prefix_id) or permalink
|
|
103
|
+
*/
|
|
104
|
+
list: (taxonId: string, params?: ProductListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreProduct>>;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
readonly countries: {
|
|
108
|
+
/**
|
|
109
|
+
* List countries available for checkout
|
|
110
|
+
* Returns countries from the store's checkout zone without states
|
|
111
|
+
*/
|
|
112
|
+
list: (options?: RequestOptions) => Promise<{
|
|
113
|
+
data: StoreCountry[];
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Get a country by ISO code with states
|
|
117
|
+
* @param iso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")
|
|
118
|
+
*/
|
|
119
|
+
get: (iso: string, options?: RequestOptions) => Promise<StoreCountry>;
|
|
120
|
+
};
|
|
121
|
+
readonly cart: {
|
|
122
|
+
/**
|
|
123
|
+
* Get current cart (returns null if none exists)
|
|
124
|
+
* Pass orderToken for guest checkout, or use JWT for authenticated users
|
|
125
|
+
*/
|
|
126
|
+
get: (options?: RequestOptions) => Promise<StoreOrder & {
|
|
127
|
+
token: string;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Create a new cart (alias for orders.create)
|
|
131
|
+
*/
|
|
132
|
+
create: (options?: RequestOptions) => Promise<StoreOrder & {
|
|
133
|
+
token: string;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Associate a guest cart with the currently authenticated user
|
|
137
|
+
* Requires both JWT token (for authentication) and orderToken (to identify the cart)
|
|
138
|
+
* @param options - Must include both `token` (JWT) and `orderToken` (guest cart token)
|
|
139
|
+
*/
|
|
140
|
+
associate: (options: RequestOptions) => Promise<StoreOrder & {
|
|
141
|
+
token: string;
|
|
142
|
+
}>;
|
|
143
|
+
};
|
|
144
|
+
readonly orders: {
|
|
145
|
+
/**
|
|
146
|
+
* List orders for the authenticated customer
|
|
147
|
+
*/
|
|
148
|
+
list: (params?: OrderListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreOrder>>;
|
|
149
|
+
/**
|
|
150
|
+
* Create a new order (cart)
|
|
151
|
+
*/
|
|
152
|
+
create: (options?: RequestOptions) => Promise<StoreOrder & {
|
|
153
|
+
order_token: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Get an order by ID or number
|
|
157
|
+
*/
|
|
158
|
+
get: (idOrNumber: string, params?: {
|
|
159
|
+
includes?: string;
|
|
160
|
+
}, options?: RequestOptions) => Promise<StoreOrder>;
|
|
161
|
+
/**
|
|
162
|
+
* Update an order
|
|
163
|
+
*/
|
|
164
|
+
update: (idOrNumber: string, params: UpdateOrderParams, options?: RequestOptions) => Promise<StoreOrder>;
|
|
165
|
+
/**
|
|
166
|
+
* Advance order to next checkout step
|
|
167
|
+
*/
|
|
168
|
+
next: (idOrNumber: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
169
|
+
/**
|
|
170
|
+
* Advance through all checkout steps
|
|
171
|
+
*/
|
|
172
|
+
advance: (idOrNumber: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
173
|
+
/**
|
|
174
|
+
* Complete the order
|
|
175
|
+
*/
|
|
176
|
+
complete: (idOrNumber: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
177
|
+
/**
|
|
178
|
+
* Add store credit to order
|
|
179
|
+
*/
|
|
180
|
+
addStoreCredit: (idOrNumber: string, amount?: number, options?: RequestOptions) => Promise<StoreOrder>;
|
|
181
|
+
/**
|
|
182
|
+
* Remove store credit from order
|
|
183
|
+
*/
|
|
184
|
+
removeStoreCredit: (idOrNumber: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
185
|
+
/**
|
|
186
|
+
* Nested resource: Line items
|
|
187
|
+
*/
|
|
188
|
+
lineItems: {
|
|
189
|
+
/**
|
|
190
|
+
* Add a line item to an order
|
|
191
|
+
*/
|
|
192
|
+
create: (orderId: string, params: AddLineItemParams, options?: RequestOptions) => Promise<StoreLineItem>;
|
|
193
|
+
/**
|
|
194
|
+
* Update a line item
|
|
195
|
+
*/
|
|
196
|
+
update: (orderId: string, lineItemId: string, params: UpdateLineItemParams, options?: RequestOptions) => Promise<StoreLineItem>;
|
|
197
|
+
/**
|
|
198
|
+
* Remove a line item from an order
|
|
199
|
+
*/
|
|
200
|
+
delete: (orderId: string, lineItemId: string, options?: RequestOptions) => Promise<void>;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Nested resource: Payments
|
|
204
|
+
*/
|
|
205
|
+
payments: {
|
|
206
|
+
/**
|
|
207
|
+
* List payments for an order
|
|
208
|
+
*/
|
|
209
|
+
list: (orderId: string, options?: RequestOptions) => Promise<{
|
|
210
|
+
data: StorePayment[];
|
|
211
|
+
meta: object;
|
|
212
|
+
}>;
|
|
213
|
+
/**
|
|
214
|
+
* Get a payment by ID
|
|
215
|
+
*/
|
|
216
|
+
get: (orderId: string, paymentId: string, options?: RequestOptions) => Promise<StorePayment>;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Nested resource: Payment methods
|
|
220
|
+
*/
|
|
221
|
+
paymentMethods: {
|
|
222
|
+
/**
|
|
223
|
+
* List available payment methods for an order
|
|
224
|
+
*/
|
|
225
|
+
list: (orderId: string, options?: RequestOptions) => Promise<PaginatedResponse<StorePaymentMethod>>;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Nested resource: Coupon codes
|
|
229
|
+
*/
|
|
230
|
+
couponCodes: {
|
|
231
|
+
/**
|
|
232
|
+
* Apply a coupon code to an order
|
|
233
|
+
*/
|
|
234
|
+
apply: (orderId: string, code: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
235
|
+
/**
|
|
236
|
+
* Remove a coupon code from an order
|
|
237
|
+
* @param promotionId - The promotion prefix_id (e.g., 'promo_xxx')
|
|
238
|
+
*/
|
|
239
|
+
remove: (orderId: string, promotionId: string, options?: RequestOptions) => Promise<StoreOrder>;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Nested resource: Shipments
|
|
243
|
+
*/
|
|
244
|
+
shipments: {
|
|
245
|
+
/**
|
|
246
|
+
* List shipments for an order
|
|
247
|
+
*/
|
|
248
|
+
list: (orderId: string, options?: RequestOptions) => Promise<{
|
|
249
|
+
data: StoreShipment[];
|
|
250
|
+
}>;
|
|
251
|
+
/**
|
|
252
|
+
* Update a shipment (e.g., select shipping rate)
|
|
253
|
+
*/
|
|
254
|
+
update: (orderId: string, shipmentId: string, params: {
|
|
255
|
+
selected_shipping_rate_id: string;
|
|
256
|
+
}, options?: RequestOptions) => Promise<StoreShipment>;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
readonly customer: {
|
|
260
|
+
/**
|
|
261
|
+
* Get current customer profile
|
|
262
|
+
*/
|
|
263
|
+
get: (options?: RequestOptions) => Promise<StoreUser>;
|
|
264
|
+
/**
|
|
265
|
+
* Update current customer profile
|
|
266
|
+
*/
|
|
267
|
+
update: (params: {
|
|
268
|
+
first_name?: string;
|
|
269
|
+
last_name?: string;
|
|
270
|
+
email?: string;
|
|
271
|
+
}, options?: RequestOptions) => Promise<StoreUser>;
|
|
272
|
+
/**
|
|
273
|
+
* Nested resource: Addresses
|
|
274
|
+
*/
|
|
275
|
+
addresses: {
|
|
276
|
+
/**
|
|
277
|
+
* List customer addresses
|
|
278
|
+
*/
|
|
279
|
+
list: (params?: ListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreAddress>>;
|
|
280
|
+
/**
|
|
281
|
+
* Get an address by ID
|
|
282
|
+
*/
|
|
283
|
+
get: (id: string, options?: RequestOptions) => Promise<StoreAddress>;
|
|
284
|
+
/**
|
|
285
|
+
* Create an address
|
|
286
|
+
*/
|
|
287
|
+
create: (params: AddressParams, options?: RequestOptions) => Promise<StoreAddress>;
|
|
288
|
+
/**
|
|
289
|
+
* Update an address
|
|
290
|
+
*/
|
|
291
|
+
update: (id: string, params: Partial<AddressParams>, options?: RequestOptions) => Promise<StoreAddress>;
|
|
292
|
+
/**
|
|
293
|
+
* Delete an address
|
|
294
|
+
*/
|
|
295
|
+
delete: (id: string, options?: RequestOptions) => Promise<void>;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Nested resource: Credit Cards
|
|
299
|
+
*/
|
|
300
|
+
creditCards: {
|
|
301
|
+
/**
|
|
302
|
+
* List customer credit cards
|
|
303
|
+
*/
|
|
304
|
+
list: (params?: ListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreCreditCard>>;
|
|
305
|
+
/**
|
|
306
|
+
* Get a credit card by ID
|
|
307
|
+
*/
|
|
308
|
+
get: (id: string, options?: RequestOptions) => Promise<StoreCreditCard>;
|
|
309
|
+
/**
|
|
310
|
+
* Delete a credit card
|
|
311
|
+
*/
|
|
312
|
+
delete: (id: string, options?: RequestOptions) => Promise<void>;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Nested resource: Gift Cards
|
|
316
|
+
*/
|
|
317
|
+
giftCards: {
|
|
318
|
+
/**
|
|
319
|
+
* List customer gift cards
|
|
320
|
+
* Returns gift cards associated with the current user, ordered by newest first
|
|
321
|
+
*/
|
|
322
|
+
list: (params?: ListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreGiftCard>>;
|
|
323
|
+
/**
|
|
324
|
+
* Get a gift card by ID
|
|
325
|
+
*/
|
|
326
|
+
get: (id: string, options?: RequestOptions) => Promise<StoreGiftCard>;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
readonly wishlists: {
|
|
330
|
+
/**
|
|
331
|
+
* List wishlists
|
|
332
|
+
*/
|
|
333
|
+
list: (params?: ListParams, options?: RequestOptions) => Promise<PaginatedResponse<StoreWishlist>>;
|
|
334
|
+
/**
|
|
335
|
+
* Get a wishlist by ID
|
|
336
|
+
*/
|
|
337
|
+
get: (id: string, params?: {
|
|
338
|
+
includes?: string;
|
|
339
|
+
}, options?: RequestOptions) => Promise<StoreWishlist>;
|
|
340
|
+
/**
|
|
341
|
+
* Create a wishlist
|
|
342
|
+
*/
|
|
343
|
+
create: (params: {
|
|
344
|
+
name: string;
|
|
345
|
+
is_private?: boolean;
|
|
346
|
+
is_default?: boolean;
|
|
347
|
+
}, options?: RequestOptions) => Promise<StoreWishlist>;
|
|
348
|
+
/**
|
|
349
|
+
* Update a wishlist
|
|
350
|
+
*/
|
|
351
|
+
update: (id: string, params: {
|
|
352
|
+
name?: string;
|
|
353
|
+
is_private?: boolean;
|
|
354
|
+
is_default?: boolean;
|
|
355
|
+
}, options?: RequestOptions) => Promise<StoreWishlist>;
|
|
356
|
+
/**
|
|
357
|
+
* Delete a wishlist
|
|
358
|
+
*/
|
|
359
|
+
delete: (id: string, options?: RequestOptions) => Promise<void>;
|
|
360
|
+
/**
|
|
361
|
+
* Nested resource: Wishlist items
|
|
362
|
+
*/
|
|
363
|
+
items: {
|
|
364
|
+
/**
|
|
365
|
+
* Add an item to a wishlist
|
|
366
|
+
*/
|
|
367
|
+
create: (wishlistId: string, params: {
|
|
368
|
+
variant_id: string;
|
|
369
|
+
quantity?: number;
|
|
370
|
+
}, options?: RequestOptions) => Promise<StoreWishedItem>;
|
|
371
|
+
/**
|
|
372
|
+
* Update a wishlist item
|
|
373
|
+
*/
|
|
374
|
+
update: (wishlistId: string, itemId: string, params: {
|
|
375
|
+
quantity: number;
|
|
376
|
+
}, options?: RequestOptions) => Promise<StoreWishedItem>;
|
|
377
|
+
/**
|
|
378
|
+
* Remove an item from a wishlist
|
|
379
|
+
*/
|
|
380
|
+
delete: (wishlistId: string, itemId: string, options?: RequestOptions) => Promise<void>;
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Create a new Spree SDK client
|
|
386
|
+
*/
|
|
387
|
+
declare function createSpreeClient(config: SpreeClientConfig): SpreeClient;
|
|
388
|
+
|
|
389
|
+
export { AddLineItemParams, AddressParams, AuthTokens, ErrorResponse, ListParams, LoginCredentials, OrderListParams, PaginatedResponse, ProductFiltersParams, ProductFiltersResponse, ProductListParams, RegisterParams, type RequestOptions, SpreeClient, type SpreeClientConfig, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreGiftCard, StoreLineItem, StoreOrder, StorePayment, StorePaymentMethod, StoreProduct, StoreShipment, StoreStore, StoreTaxon, StoreTaxonomy, StoreUser, StoreWishedItem, StoreWishlist, TaxonListParams, UpdateLineItemParams, UpdateOrderParams, createSpreeClient };
|