bc-api-client 0.2.1 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts DELETED
@@ -1,160 +0,0 @@
1
- import { Logger } from './core';
2
- import { RateLimitOptions, RequestOptions, StoreOptions, KyOptions } from './net';
3
- /**
4
- * Options for GET requests to the BigCommerce API
5
- */
6
- export type GetOptions = {
7
- /** Query parameters to include in the request */
8
- query?: Record<string, string>;
9
- /** API version to use (v2 or v3) */
10
- version?: 'v2' | 'v3';
11
- /** Options to pass directly to ky */
12
- kyOptions?: KyOptions;
13
- };
14
- /**
15
- * Options for POST/PUT requests to the BigCommerce API
16
- */
17
- export type PostOptions<T> = GetOptions & {
18
- /** Request body data */
19
- body: T;
20
- };
21
- /**
22
- * Options for controlling concurrent request behavior
23
- */
24
- export type ConcurrencyOptions = {
25
- /** Maximum number of concurrent requests (default: 10) */
26
- concurrency?: number;
27
- /** Whether to skip errors and continue processing (default: false) */
28
- skipErrors?: boolean;
29
- };
30
- /**
31
- * Options for querying multiple values against a single filter field
32
- */
33
- export type QueryOptions = Omit<GetOptions, 'version'> & ConcurrencyOptions & {
34
- /** The field name to query against */
35
- key: string;
36
- /** Array of values to query for */
37
- values: (string | number)[];
38
- } & {
39
- /** Options to pass directly to ky */
40
- kyOptions?: KyOptions;
41
- };
42
- /**
43
- * Configuration options for the BigCommerce client
44
- */
45
- export type Config = StoreOptions & RateLimitOptions & ConcurrencyOptions & {
46
- /** Logger instance */
47
- logger?: Logger;
48
- };
49
- /**
50
- * Client for interacting with the BigCommerce API
51
- *
52
- * This client provides methods for making HTTP requests to the BigCommerce API,
53
- * with support for both v2 and v3 endpoints, pagination, and concurrent requests.
54
- */
55
- export declare class BigCommerceClient {
56
- private readonly config;
57
- /**
58
- * Creates a new BigCommerce client instance
59
- * @param config - Configuration options for the client
60
- * @param config.baseUrl - The base URL to use for the client (default: https://api.bigcommerce.com)
61
- * @param config.storeHash - The store hash to use for the client
62
- * @param config.accessToken - The API access token to use for the client
63
- * @param config.maxRetries - The maximum number of retries for rate limit errors (default: 5)
64
- * @param config.maxDelay - Maximum time to wait to retry in case of rate limit errors in milliseconds (default: 60000 - 1 minute). If `X-Rate-Limit-Time-Reset-Ms` header is higher than `maxDelay`, the request will fail immediately.
65
- * @param config.concurrency - The default concurrency for concurrent methods (default: 10)
66
- * @param config.skipErrors - Whether to skip errors during concurrent requests (default: false)
67
- * @param config.logger - Optional logger instance for debugging and error tracking
68
- */
69
- constructor(config: Config);
70
- /**
71
- * Makes a GET request to the BigCommerce API
72
- * @param endpoint - The API endpoint to request
73
- * @param options.query - Query parameters to include in the request
74
- * @param options.version - API version to use (v2 or v3) (default: v3)
75
- * @returns Promise resolving to the response data of type `R`
76
- */
77
- get<R>(endpoint: string, options?: GetOptions): Promise<R>;
78
- /**
79
- * Makes a POST request to the BigCommerce API
80
- * @param endpoint - The API endpoint to request
81
- * @param options.query - Query parameters to include in the request
82
- * @param options.version - API version to use (v2 or v3) (default: v3)
83
- * @param options.body - Request body data of type `T`
84
- * @returns Promise resolving to the response data of type `R`
85
- */
86
- post<T, R>(endpoint: string, options?: PostOptions<T>): Promise<R>;
87
- /**
88
- * Makes a PUT request to the BigCommerce API
89
- * @param endpoint - The API endpoint to request
90
- * @param options.query - Query parameters to include in the request
91
- * @param options.version - API version to use (v2 or v3) (default: v3)
92
- * @param options.body - Request body data of type `T`
93
- * @returns Promise resolving to the response data of type `R`
94
- */
95
- put<T, R>(endpoint: string, options?: PostOptions<T>): Promise<R>;
96
- /**
97
- * Makes a DELETE request to the BigCommerce API
98
- * @param endpoint - The API endpoint to delete
99
- * @param options.version - API version to use (v2 or v3) (default: v3)
100
- * @returns Promise resolving to void
101
- */
102
- delete<R>(endpoint: string, options?: Pick<GetOptions, 'version' | 'query'> & {
103
- kyOptions?: KyOptions;
104
- }): Promise<void>;
105
- /**
106
- * Executes multiple requests concurrently with controlled concurrency
107
- * @param requests - Array of request options to execute
108
- * @param options.concurrency - Maximum number of concurrent requests, overrides the client's concurrency setting (default: 10)
109
- * @param options.skipErrors - Whether to skip errors and continue processing (the errors will be logged if logger is provided), overrides the client's skipErrors setting (default: false)
110
- * @returns Promise resolving to array of response data
111
- */
112
- concurrent<T, R>(requests: RequestOptions<T>[], options?: ConcurrencyOptions): Promise<R[]>;
113
- /**
114
- * Lowest level concurrent request method.
115
- * This method executes requests in chunks and returns bare PromiseSettledResult objects.
116
- * Use this method if you need to handle errors in a custom way.
117
- * @param requests - Array of request options to execute
118
- * @param options.concurrency - Maximum number of concurrent requests, overrides the client's concurrency setting (default: 10)
119
- * @returns Promise resolving to array of PromiseSettledResult containing both successful and failed requests
120
- */
121
- concurrentSettled<T, R>(requests: RequestOptions<T>[], options?: Pick<ConcurrencyOptions, 'concurrency'>): Promise<PromiseSettledResult<R>[]>;
122
- /**
123
- * Collects all pages of data from a paginated v3 API endpoint.
124
- * This method pulls the first page and uses pagination meta to collect the remaining pages concurrently.
125
- * @param endpoint - The API endpoint to request
126
- * @param options.query - Query parameters to include in the request
127
- * @param options.concurrency - Maximum number of concurrent requests, overrides the client's concurrency setting (default: 10)
128
- * @param options.skipErrors - Whether to skip errors and continue processing (the errors will be logged if logger is provided), overrides the client's skipErrors setting (default: false)
129
- * @returns Promise resolving to array of all items across all pages
130
- */
131
- collect<T>(endpoint: string, options?: Omit<GetOptions, 'version'> & ConcurrencyOptions & {
132
- kyOptions?: KyOptions;
133
- }): Promise<T[]>;
134
- /**
135
- * Collects all pages of data from a paginated v2 API endpoint.
136
- * This method simply pulls all pages concurrently until a 204 is returned in a batch.
137
- * @param endpoint - The API endpoint to request
138
- * @param options.query - Query parameters to include in the request
139
- * @param options.concurrency - Maximum number of concurrent requests, overrides the client's concurrency setting (default: 10)
140
- * @param options.skipErrors - Whether to skip errors and continue processing (the errors will be logged if logger is provided), overrides the client's skipErrors setting (default: false)
141
- * @returns Promise resolving to array of all items across all pages
142
- */
143
- collectV2<T>(endpoint: string, options?: Omit<GetOptions, 'version'> & ConcurrencyOptions & {
144
- kyOptions?: KyOptions;
145
- }): Promise<T[]>;
146
- /**
147
- * Queries multiple values against a single field using the v3 API.
148
- * If the url + query params are too long, the query will be chunked. Otherwise, this method acts like `collect`.
149
- * This method does not check for uniqueness of the `values` array.
150
- *
151
- * @param endpoint - The API endpoint to request
152
- * @param options.key - The field name to query against e.g. `sku:in`
153
- * @param options.values - Array of values to query for e.g. `['123', '456', ...]`
154
- * @param options.query - Additional query parameters
155
- * @param options.concurrency - Maximum number of concurrent requests, overrides the client's concurrency setting (default: 10)
156
- * @param options.skipErrors - Whether to skip errors and continue processing (the errors will be logged if logger is provided), overrides the client's skipErrors setting (default: false)
157
- * @returns Promise resolving to array of matching items
158
- */
159
- query<T>(endpoint: string, options: QueryOptions): Promise<T[]>;
160
- }
package/dist/core.d.ts DELETED
@@ -1,27 +0,0 @@
1
- export type Pagination = {
2
- total: number;
3
- count: number;
4
- per_page: number;
5
- current_page: number;
6
- total_pages: number;
7
- links: {
8
- previous: string | null;
9
- current: string;
10
- next: string | null;
11
- };
12
- };
13
- export type V3Resource<T> = {
14
- data: T;
15
- meta: {
16
- pagination: Pagination;
17
- };
18
- };
19
- /**
20
- * Logger interface for logging messages and data, Pino compatible by default
21
- */
22
- export interface Logger {
23
- debug: (data: unknown, message?: string) => void;
24
- info: (data: unknown, message?: string) => void;
25
- warn: (data: unknown, message?: string) => void;
26
- error: (data: unknown, message?: string) => void;
27
- }
@@ -1,471 +0,0 @@
1
- export declare const customerSegmentation: {
2
- segments: string;
3
- shopperProfileSegments: (profileId: string) => string;
4
- shopperProfiles: string;
5
- segmentShopperProfiles: (segmentId: string) => string;
6
- };
7
- export declare const geography: {
8
- v2: {
9
- countries: {
10
- path: string;
11
- byId: (id: string) => string;
12
- count: string;
13
- states: {
14
- path: (id: string) => string;
15
- byId: (countryId: string, id: string) => string;
16
- count: (countryId: string) => string;
17
- };
18
- };
19
- states: {
20
- path: string;
21
- count: string;
22
- };
23
- };
24
- };
25
- export declare const bc: {
26
- catalogSummary: string;
27
- products: {
28
- path: string;
29
- byId: (id: number) => string;
30
- batchPrices: string;
31
- metafields: {
32
- batch: string;
33
- product: {
34
- path: (productId: number) => string;
35
- byId: (productId: number, id: number) => string;
36
- };
37
- };
38
- bulkPricingRules: {
39
- path: (productId: number) => string;
40
- byId: (productId: number, id: number) => string;
41
- };
42
- categoryAssignments: string;
43
- channelAssignments: string;
44
- complexRules: {
45
- path: (productId: number) => string;
46
- byId: (productId: number, id: number) => string;
47
- };
48
- customFields: {
49
- path: (productId: number) => string;
50
- byId: (productId: number, id: number) => string;
51
- };
52
- images: {
53
- path: (productId: number) => string;
54
- byId: (productId: number, id: number) => string;
55
- };
56
- reviews: {
57
- path: (productId: number) => string;
58
- byId: (productId: number, id: number) => string;
59
- };
60
- videos: {
61
- path: (productId: number) => string;
62
- byId: (productId: number, id: number) => string;
63
- };
64
- };
65
- modifiers: {
66
- path: (productId: number) => string;
67
- byId: (productId: number, id: number) => string;
68
- values: {
69
- path: (productId: number, modifierId: number) => string;
70
- byId: (productId: number, modifierId: number, id: number) => string;
71
- createImage: (productId: number, modifierId: number, id: number) => string;
72
- };
73
- };
74
- variantOptions: {
75
- path: (productId: number) => string;
76
- byId: (productId: number, id: number) => string;
77
- values: {
78
- path: (productId: number, optionId: number) => string;
79
- byId: (productId: number, optionId: number, id: number) => string;
80
- };
81
- };
82
- variants: {
83
- batch: string;
84
- path: (productId: number) => string;
85
- byId: (productId: number, id: number) => string;
86
- createImage: (productId: number, id: number) => string;
87
- metafields: {
88
- batch: string;
89
- path: (productId: number, id: number) => string;
90
- byId: (productId: number, variantId: number, id: number) => string;
91
- };
92
- };
93
- brands: {
94
- path: string;
95
- byId: (id: number) => string;
96
- image: (id: number) => string;
97
- metafields: {
98
- batch: string;
99
- path: (id: number) => string;
100
- byId: (brandId: number, id: number) => string;
101
- };
102
- };
103
- categories: {
104
- deprecated: {
105
- path: string;
106
- byId: (id: number) => string;
107
- };
108
- image: (id: number) => string;
109
- metafields: {
110
- batch: string;
111
- path: (id: number) => string;
112
- byId: (categoryId: number, id: number) => string;
113
- };
114
- sortOrder: (id: number) => string;
115
- };
116
- trees: {
117
- path: string;
118
- byId: (id: number) => string;
119
- categories: (id: number) => string;
120
- allCategories: string;
121
- };
122
- abandonedCarts: {
123
- path: (token: string) => string;
124
- settings: {
125
- global: string;
126
- channel: (channelId: number) => string;
127
- };
128
- };
129
- carts: {
130
- path: string;
131
- byId: (uuid: string) => string;
132
- createRedirectUrl: (uuid: string) => string;
133
- items: {
134
- path: (uuid: string) => string;
135
- byId: (cartUuid: string, itemUuid: string) => string;
136
- };
137
- metafields: {
138
- batch: string;
139
- path: (uuid: string) => string;
140
- byId: (cartUuid: string, metafieldUuid: string) => string;
141
- };
142
- settings: {
143
- global: string;
144
- channel: (channelId: number) => string;
145
- };
146
- };
147
- channels: {
148
- path: string;
149
- byId: (id: number) => string;
150
- activeTheme: (id: number) => string;
151
- site: (id: number) => string;
152
- menus: (id: number) => string;
153
- checkoutUrl: (id: number) => string;
154
- currencyAssignments: {
155
- path: (id: number) => string;
156
- byId: (channelId: number, id: number) => string;
157
- };
158
- listings: {
159
- path: (id: number) => string;
160
- byId: (channelId: number, id: number) => string;
161
- };
162
- metafields: {
163
- batch: string;
164
- path: (id: number) => string;
165
- byId: (channelId: number, id: number) => string;
166
- };
167
- };
168
- checkouts: {
169
- path: (uuid: string) => string;
170
- billingAddress: (uuid: string) => string;
171
- consignments: {
172
- path: (uuid: string) => string;
173
- byId: (checkoutUuid: string, consignmentUuid: string) => string;
174
- };
175
- coupons: {
176
- add: (uuid: string) => string;
177
- delete: (uuid: string, code: string) => string;
178
- };
179
- discounts: (uuid: string) => string;
180
- fees: (uuid: string) => string;
181
- createOrder: (uuid: string) => string;
182
- settings: string;
183
- createToken: (uuid: string) => string;
184
- };
185
- currencies: {
186
- v2: {
187
- path: string;
188
- byId: (id: string) => string;
189
- };
190
- };
191
- customers: {
192
- path: string;
193
- addresses: string;
194
- attributes: string;
195
- attributesValues: string;
196
- settings: {
197
- channel: (channelId: number) => string;
198
- global: string;
199
- };
200
- consent: (id: number) => string;
201
- formFieldValues: string;
202
- storedInstruments: (id: number) => string;
203
- validateCredentials: string;
204
- metafields: {
205
- batch: string;
206
- path: (id: number) => string;
207
- byId: (customerId: number, id: number) => string;
208
- };
209
- v2: {
210
- groups: {
211
- path: string;
212
- byId: (id: number) => string;
213
- count: string;
214
- };
215
- deprecated: {
216
- path: string;
217
- byId: (id: number) => string;
218
- addresses: {
219
- path: (id: number) => string;
220
- byId: (customerId: number, id: number) => string;
221
- };
222
- validatePassword: (id: number) => string;
223
- };
224
- };
225
- subscribers: {
226
- path: string;
227
- byId: (id: number) => string;
228
- };
229
- };
230
- customerSegmentation: {
231
- segments: string;
232
- shopperProfileSegments: (profileId: string) => string;
233
- shopperProfiles: string;
234
- segmentShopperProfiles: (segmentId: string) => string;
235
- };
236
- geography: {
237
- v2: {
238
- countries: {
239
- path: string;
240
- byId: (id: string) => string;
241
- count: string;
242
- states: {
243
- path: (id: string) => string;
244
- byId: (countryId: string, id: string) => string;
245
- count: (countryId: string) => string;
246
- };
247
- };
248
- states: {
249
- path: string;
250
- count: string;
251
- };
252
- };
253
- };
254
- inventory: {
255
- adjustments: {
256
- absolute: string;
257
- relative: string;
258
- };
259
- items: {
260
- path: string;
261
- atLocation: (locationId: string) => string;
262
- updateLocationSettings: (locationId: string) => string;
263
- };
264
- };
265
- locations: {
266
- path: string;
267
- metafields: {
268
- batch: string;
269
- path: (id: string) => string;
270
- byId: (locationId: string, id: string) => string;
271
- };
272
- };
273
- orders: {
274
- v2: {
275
- path: string;
276
- byId: (id: number) => string;
277
- count: string;
278
- consignments: {
279
- path: (id: number) => string;
280
- shippingQuotes: (orderId: number, consignmentId: number) => string;
281
- };
282
- coupons: (id: number) => string;
283
- fees: (id: number) => string;
284
- messages: (id: number) => string;
285
- products: {
286
- path: (id: number) => string;
287
- byId: (orderId: number, id: number) => string;
288
- };
289
- shipments: {
290
- path: (id: number) => string;
291
- count: (id: number) => string;
292
- byId: (orderId: number, id: number) => string;
293
- };
294
- shippingAddresses: {
295
- path: (id: number) => string;
296
- byId: (orderId: number, id: number) => string;
297
- quotes: (orderId: number, id: number) => string;
298
- };
299
- statuses: {
300
- path: string;
301
- byId: (id: number) => string;
302
- };
303
- taxes: (id: number) => string;
304
- };
305
- transactions: (id: number) => string;
306
- metafields: {
307
- batch: string;
308
- path: (id: number) => string;
309
- byId: (orderId: number, id: number) => string;
310
- };
311
- settings: {
312
- global: string;
313
- channel: (channelId: number) => string;
314
- };
315
- payments: {
316
- capture: (id: number) => string;
317
- void: (id: number) => string;
318
- };
319
- refunds: {
320
- path: string;
321
- byId: (refundId: number) => string;
322
- quote: (id: number) => string;
323
- forOrder: (id: number) => string;
324
- };
325
- pickups: {
326
- path: string;
327
- methods: string;
328
- options: string;
329
- };
330
- };
331
- priceLists: {
332
- path: string;
333
- byId: (id: number) => string;
334
- assignments: {
335
- path: string;
336
- byId: (id: number) => string;
337
- };
338
- records: {
339
- path: string;
340
- forList: (id: number) => string;
341
- byVariant: (listId: number, variantId: number) => string;
342
- byCurrency: (listId: number, variantId: number, currencyCode: string) => string;
343
- };
344
- };
345
- promotions: {
346
- path: string;
347
- byId: (id: number) => string;
348
- coupons: {
349
- path: (promotionId: number) => string;
350
- byId: (promotionId: number, id: number) => string;
351
- };
352
- settings: string;
353
- };
354
- redirects: {
355
- path: string;
356
- imexJobs: string;
357
- createExportJob: string;
358
- createImportJob: string;
359
- exportEventStream: (jobUuid: string) => string;
360
- importEventStream: (jobUuid: string) => string;
361
- downloadExport: (jobUuid: string) => string;
362
- };
363
- scripts: {
364
- path: string;
365
- byId: (uuid: string) => string;
366
- };
367
- settings: {
368
- analytics: {
369
- providers: string;
370
- provider: (providerId: string) => string;
371
- };
372
- catalog: string;
373
- emailStatuses: string;
374
- createFavicon: string;
375
- inventory: {
376
- path: string;
377
- notifications: string;
378
- };
379
- logo: {
380
- path: string;
381
- image: string;
382
- };
383
- filters: {
384
- enabled: string;
385
- available: string;
386
- contextual: string;
387
- };
388
- locale: string;
389
- profile: string;
390
- storefront: {
391
- category: string;
392
- product: string;
393
- robotstxt: string;
394
- search: string;
395
- security: string;
396
- seo: string;
397
- status: string;
398
- uom: string;
399
- };
400
- };
401
- shipping: {
402
- v2: {
403
- carrierConnections: string;
404
- methods: {
405
- path: (zoneId: number) => string;
406
- byId: (zoneId: number, id: number) => string;
407
- };
408
- zones: {
409
- path: string;
410
- byId: (id: number) => string;
411
- };
412
- };
413
- customsInformation: string;
414
- settings: {
415
- global: string;
416
- channel: (channelId: number) => string;
417
- };
418
- };
419
- sites: {
420
- path: string;
421
- byId: (id: number) => string;
422
- certificates: {
423
- all: string;
424
- forSite: (id: number) => string;
425
- };
426
- routes: {
427
- path: (siteId: number) => string;
428
- byId: (siteId: number, id: number) => string;
429
- };
430
- };
431
- store: {
432
- v2: {
433
- info: string;
434
- time: string;
435
- };
436
- metafields: {
437
- batch: string;
438
- path: (id: number) => string;
439
- byId: (storeId: number, id: number) => string;
440
- };
441
- logs: string;
442
- };
443
- tax: {
444
- v2: {
445
- classes: {
446
- path: string;
447
- byId: (id: number) => string;
448
- };
449
- };
450
- customers: string;
451
- rates: string;
452
- zones: string;
453
- properties: string;
454
- productProperties: string;
455
- settings: string;
456
- };
457
- wishlists: {
458
- path: string;
459
- byId: (id: number) => string;
460
- items: {
461
- delete: (id: number, itemId: number) => string;
462
- add: (id: number) => string;
463
- };
464
- };
465
- webhooks: {
466
- path: string;
467
- byId: (id: number) => string;
468
- admin: string;
469
- upsertEmailNotifications: string;
470
- };
471
- };