@@ -30,11 +30,11 @@ To use the BigCommerce Management API you first need to [obtain the store hash a
3030You can use es6 imports with the Management API:
3131
3232``` js
33- import { Management } from " @aligent/bigcommerce-api" ;
33+ import { Management } from ' @aligent/bigcommerce-api' ;
3434
3535const bigCommerce = new Management.Client ({
36- storeHash: " your store hash here" ,
37- accessToken: " your access token here" ,
36+ storeHash: ' your store hash here' ,
37+ accessToken: ' your access token here' ,
3838});
3939```
4040
@@ -43,26 +43,26 @@ const bigCommerce = new Management.Client({
4343The following code snippet will fetch store information from the V2 API and dump it to the console:
4444
4545``` js
46- import { Management } from " @aligent/bigcommerce-api" ;
46+ import { Management } from ' @aligent/bigcommerce-api' ;
4747
4848const bigCommerce = new Management.Client ({
49- storeHash: " your store hash here" ,
50- accessToken: " your access token here" ,
49+ storeHash: ' your store hash here' ,
50+ accessToken: ' your access token here' ,
5151});
5252
53- bigCommerce .v2 .get (" /store" ).then (console .dir );
53+ bigCommerce .v2 .get (' /store' ).then (console .dir );
5454```
5555
5656## How-to guides
5757
5858Start by instantiating a client instance:
5959
6060``` js
61- import { Management } from " @aligent/bigcommerce-api" ;
61+ import { Management } from ' @aligent/bigcommerce-api' ;
6262
6363const bigCommerce = new Management.Client ({
64- storeHash: " your store hash here" ,
65- accessToken: " your access token here" ,
64+ storeHash: ' your store hash here' ,
65+ accessToken: ' your access token here' ,
6666});
6767```
6868
@@ -104,7 +104,7 @@ bigCommerce.v3.get('/catalog/products/{product_id}', {
104104``` js
105105async function printAllProducts () {
106106 // list() sends one HTTP request at a time and only sends requests as the iterator is consumed
107- const products = bigCommerce .v3 .list (" /catalog/products" , { query: { include: [" images" ] } });
107+ const products = bigCommerce .v3 .list (' /catalog/products' , { query: { include: [' images' ] } });
108108 for await (const product of products ) {
109109 console .dir (product);
110110 }
@@ -191,6 +191,41 @@ Your BigCommerce Management API access token.
191191
192192Provide a node HTTP agent to override things like keepalive and connection pool size.
193193
194+ ### Overriding the internal client
195+
196+ You can provide your own fetch implementation to the clients.
197+
198+ For light modifications like custom headers or baseUrl, re-use the ` fetchTransport ` function
199+
200+ ``` typescript
201+ const v2 = new Management .V2 .Client (
202+ import { Management , fetchTransport } from " @aligent/bigcommerce-api" ;
203+ import { Agent } from " node:http" ;
204+
205+ fetchTransport ({
206+ baseUrl: ' http://custom.url/v2' ,
207+ headers: {
208+ " customer-header" : " ..."
209+ }
210+ })
211+ );
212+
213+ const v3 = new Management .V3 .Client (
214+ fetchTransport ({
215+ baseUrl: ' http://custom.url/v3' ,
216+ headers: {
217+ " customer-header" : " ..."
218+ }
219+ })
220+ );
221+ ```
222+
223+ For more control, provide a custom implementation matching the Transport interface to the clients
224+
225+ ``` typescript
226+ type Transport = (requestLine : string , params ? : Parameters ) => Promise <Response >;
227+ ```
228+
194229### V2 API client
195230
196231See the [ V2 readme] ( v2/README.md ) for more detail on the Management V2 client methods.
0 commit comments