forked from hunterashaw/bigcommerce-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
91 lines (82 loc) · 4.96 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/// <reference types="node" />
export default class BigCommerceClient {
base: string;
headers: {
'X-Auth-Token': string;
'Accept': 'application/json';
'Content-Type': 'application/json';
};
meta: object;
debug: boolean;
status?: number;
maxAttempts: number;
timeout: number;
/**
* Construct BigCommerceClient Instance.
* @param {string} hash Store Hash (ex: gha3w9n1at)
* @param {string} token API Token (ex: j3aovsvag3vg88hhyl4qt89q6ag2b6b)
* @param {boolean} debug Enable console output for every request
* @param {number} timeout Max time in millis for timeout (default: 15000)
* @param {number} maxAttempts Number of retry attempts on timeout (default: 3)
*/
constructor(hash: string, token: string, debug?: boolean, timeout?: number, maxAttempts?: number)
/**
* Performs a GET request to the BigCommerce Management API at the specified endpoint. Throws error w/ http status information if non-200 response is returned.
* @returns {object} JSON data returned from a 2-- request
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} queries Object w/ keys & string values of each url query parameter (example: {sku:'10205'})
*/
get(endpoint: string, queries?: object): any
/**
* Function to perform on each page returned by endpoint. Should accept an array of objects from page.
* @callback eachPage
* @param {object[]} pageContents
*/
/**
* Performs sequential GET requests to the BigCommerce Management API at the specified endpoint. For each page in query it will perform the provided callback, passing an array of objects in page.
* @async
* @returns {Promise}
* @param {string} endoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {eachPage} eachPage Callback for each page provided by endpoint
* @param {object} queries Object w/ keys & string values of each url query parameter (example: {sku:'10205'}). Page & limit can be passed to control start & page size.
* @param {number} concurrency Amount of concurrent requests to make. Isn't a
*/
paginate(endpoint: string, eachPage: (page: object[]) => void, queries?: object, concurrency?: number): Promise<void>
/**
* Performs sequential GET request to the BigCommerce Management API at the specified endpoint. Concatenates results from all pages.
* @async
* @returns {object[]} Concatenated JSON data returned from a 2-- request
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} queries Object w/ keys & string values of each url query parameter (example: {sku:'10205'})
*/
getAll(endpoint: string, queries?: ParsedUrlQueryInput): Promise<object[]>
/**
* Performs a POST request to the BigCommerce Management API at the specified endpoint. Throws error w/ http status information if non-200 response is returned.
* @returns {object} JSON data returned from a 2-- request
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} body Request body to be serialized and sent to endpoint
*/
post(endpoint: string, body?: object): Promise<object>
/**
* Performs a PUT request to the BigCommerce Management API at the specified endpoint. Throws error w/ http status information if non-200 response is returned.
* @returns {object} JSON data returned from a 2-- request
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} body Request body to be serialized and sent to endpoint
*/
put(endpoint: string, body: object): Promise<object>
/**
* Performs a DELETE request to the BigCommerce Management API at the specified endpoint. Throws error w/ http status information if non-200 response is returned.
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} queries Object w/ keys & string values of each url query parameter (example: {sku:'10205'})
*/
delete(endpoint: string, queries?: object): Promise<void>
/**
* Performs sequential DELETE requests to the BigCommerce Management API at the specified endpoint. Will perform a getAll request, then for each ID returned, it will perform a DELETE.
* @async
* @param {string} endpoint Url endpoint from version onward (example: 'v3/catalog/products')
* @param {object} queries Object w/ keys & string values of each url query parameter (example: {sku:'10205'}).
* @param {number} limit Amount of concurrent delete requests that will be performed. If the default setting of 3 errors out, set it to 1.
*/
deleteAll(endpoint: string, queries?: object, limit?: number): Promise<void>
readResponse(url: string, method?: string, body?: any, attempts?: number): Promise<object>
}