forked from woocommerce/woocommerce-rest-api-js-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
201 lines (183 loc) · 4.37 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import * as OAuth from 'oauth-1.0a'
export declare type WooCommerceRestApiVersion =
| 'wc/v3'
| 'wc/v2'
| 'wc/v1'
| 'wc-api/v3'
| 'wc-api/v2'
| 'wc-api/v1'
export declare type WooCommerceRestApiEncoding = 'utf-8' | 'ascii'
export declare type WooCommerceRestApiMethod =
| 'get'
| 'post'
| 'put'
| 'delete'
| 'options'
export interface IWooCommerceRestApiOptions {
/* Your Store URL, example: http://woo.dev/ */
url: string
/* Your API consumer key */
consumerKey: string
/* Your API consumer secret */
consumerSecret: string
/* Custom WP REST API URL prefix, used to support custom prefixes created with the `rest_url_prefix filter` */
wpAPIPrefix?: string
/* API version, default is `v3` */
version?: WooCommerceRestApiVersion
/* Encoding, default is 'utf-8' */
encoding?: WooCommerceRestApiEncoding
/* When `true` and using under HTTPS force Basic Authentication as query string, default is `false` */
queryStringAuth?: boolean
/* Provide support for URLs with ports, eg: `8080` */
port?: number
/* Define the request timeout */
timeout?: number
/* Define the custom Axios config, also override this library options */
axiosConfig?: any
}
export interface IWooCommerceRestApiQuery {
[key: string]: string
}
/**
* WooCommerce REST API wrapper
*
* @param {Object} opt
*/
export default class WooCommerceRestApi {
protected classVersion: string
protected url: string
protected consumerKey: string
protected consumerSecret: string
protected wpAPIPrefix: string
protected version: WooCommerceRestApiVersion
protected encoding: WooCommerceRestApiEncoding
protected queryStringAuth: boolean
protected port: number
protected timeout: number
protected axiosConfig: any
/**
* Class constructor.
*
* @param {Object} opt
*/
constructor(opt: IWooCommerceRestApiOptions | WooCommerceRestApi)
/**
* Set default options
*
* @param {Object} opt
*/
private _setDefaultsOptions(opt: IWooCommerceRestApiOptions): void
/**
* Parse params object.
*
* @param {Object} params
* @param {Object} query
*/
private _parseParamsObject(params: any, query: any): IWooCommerceRestApiQuery
/**
* Normalize query string for oAuth
*
* @param {String} url
* @param {Object} params
*
* @return {String}
*/
private _normalizeQueryString(url: string, params: any): string
/**
* Get URL
*
* @param {String} endpoint
* @param {Object} params
*
* @return {String}
*/
private _getUrl(endpoint: string, params: any): string
/**
* Get OAuth
*
* @return {Object}
*/
private _getOAuth(): OAuth
/**
* Do requests
*
* @param {String} method
* @param {String} endpoint
* @param {Object} data
* @param {Object} params
*
* @return {Object}
*/
private _request(
method: WooCommerceRestApiMethod,
endpoint: string,
data: any,
params: any
): Promise<any>
/**
* GET requests
*
* @param {String} endpoint
* @param {Object} params
*
* @return {Object}
*/
public get(endpoint: string): Promise<any>
public get(endpoint: string, params: any): Promise<any>
/**
* POST requests
*
* @param {String} endpoint
* @param {Object} data
* @param {Object} params
*
* @return {Object}
*/
public post(endpoint: string, data: any): Promise<any>
public post(endpoint: string, data: any, params: any): Promise<any>
/**
* PUT requests
*
* @param {String} endpoint
* @param {Object} data
* @param {Object} params
*
* @return {Object}
*/
public put(endpoint: string, data: any): Promise<any>
public put(endpoint: string, data: any, params: any): Promise<any>
/**
* DELETE requests
*
* @param {String} endpoint
* @param {Object} params
* @param {Object} params
*
* @return {Object}
*/
public delete(endpoint: string): Promise<any>
public delete(endpoint: string, params: any): Promise<any>
/**
* OPTIONS requests
*
* @param {String} endpoint
* @param {Object} params
*
* @return {Object}
*/
public options(endpoint: string): Promise<any>
public options(endpoint: string, params: any): Promise<any>
}
/**
* Options Exception.
*/
export class OptionsException {
public name: 'Options Error'
public message: string
/**
* Constructor.
*
* @param {String} message
*/
constructor(message: string)
}