Skip to content

Commit 55928eb

Browse files
committed
Add TypeScript Decorator
1 parent b0e0162 commit 55928eb

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed

index.d.ts

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import axios from 'axios'
2+
import createHmac from 'create-hmac'
3+
import OAuth from 'oauth-1.0a'
4+
import Url from 'url-parse'
5+
6+
export type WooCommerceRestApiVersion =
7+
| 'wc/v3'
8+
| 'wc/v2'
9+
| 'wc/v1'
10+
| 'wc-api/v3'
11+
| 'wc-api/v2'
12+
| 'wc-api/v1'
13+
export type WooCommerceRestApiEncoding = 'utf-8' | 'ascii'
14+
export type WooCommerceRestApiMethod =
15+
| 'get'
16+
| 'post'
17+
| 'put'
18+
| 'delete'
19+
| 'options'
20+
21+
export interface IWooCommerceRestApiOptions {
22+
/* Your Store URL, example: http://woo.dev/ */
23+
url: string
24+
/* Your API consumer key */
25+
consumerKey: string
26+
/* Your API consumer secret */
27+
consumerSecret: string
28+
/* Custom WP REST API URL prefix, used to support custom prefixes created with the `rest_url_prefix filter` */
29+
wpAPIPrefix?: string
30+
/* API version, default is `v3` */
31+
version?: WooCommerceRestApiVersion
32+
/* Encoding, default is 'utf-8' */
33+
encoding?: WooCommerceRestApiEncoding
34+
/* When `true` and using under HTTPS force Basic Authentication as query string, default is `false` */
35+
queryStringAuth?: boolean
36+
/* Provide support for URLs with ports, eg: `8080` */
37+
port?: number
38+
/* Define the request timeout */
39+
timeout?: number
40+
/* Define the custom Axios config, also override this library options */
41+
axiosConfig?: any
42+
}
43+
44+
export interface IWooCommerceRestApiQuery {
45+
[key: string]: string
46+
}
47+
48+
/**
49+
* WooCommerce REST API wrapper
50+
*
51+
* @param {Object} opt
52+
*/
53+
export class WooCommerceRestApi {
54+
protected classVersion: string
55+
protected url: string
56+
protected consumerKey: string
57+
protected consumerSecret: string
58+
protected wpAPIPrefix: string
59+
protected version: WooCommerceRestApiVersion
60+
protected encoding: WooCommerceRestApiEncoding
61+
protected queryStringAuth: boolean
62+
protected port: number
63+
protected timeout: number
64+
protected axiosConfig: any
65+
66+
/**
67+
* Class constructor.
68+
*
69+
* @param {Object} opt
70+
*/
71+
constructor(opt: IWooCommerceRestApiOptions | WooCommerceRestApi)
72+
73+
/**
74+
* Set default options
75+
*
76+
* @param {Object} opt
77+
*/
78+
private _setDefaultsOptions(opt: IWooCommerceRestApiOptions): void
79+
80+
/**
81+
* Parse params object.
82+
*
83+
* @param {Object} params
84+
* @param {Object} query
85+
*/
86+
private _parseParamsObject(params: any, query: any): IWooCommerceRestApiQuery
87+
88+
/**
89+
* Normalize query string for oAuth
90+
*
91+
* @param {String} url
92+
* @param {Object} params
93+
*
94+
* @return {String}
95+
*/
96+
private _normalizeQueryString(url: string, params: any): string
97+
98+
/**
99+
* Get URL
100+
*
101+
* @param {String} endpoint
102+
* @param {Object} params
103+
*
104+
* @return {String}
105+
*/
106+
private _getUrl(endpoint: string, params: any): string
107+
108+
/**
109+
* Get OAuth
110+
*
111+
* @return {Object}
112+
*/
113+
private _getOAuth(): OAuth
114+
115+
/**
116+
* Do requests
117+
*
118+
* @param {String} method
119+
* @param {String} endpoint
120+
* @param {Object} data
121+
* @param {Object} params
122+
*
123+
* @return {Object}
124+
*/
125+
private _request(
126+
method: WooCommerceRestApiMethod,
127+
endpoint: string,
128+
data: any,
129+
params: any
130+
): any
131+
132+
/**
133+
* GET requests
134+
*
135+
* @param {String} endpoint
136+
* @param {Object} params
137+
*
138+
* @return {Object}
139+
*/
140+
public get(endpoint: string): any
141+
public get(endpoint: string, params: any): any
142+
143+
/**
144+
* POST requests
145+
*
146+
* @param {String} endpoint
147+
* @param {Object} data
148+
* @param {Object} params
149+
*
150+
* @return {Object}
151+
*/
152+
public post(endpoint: string, data: any): any
153+
public post(endpoint: string, data: any, params: any): any
154+
155+
/**
156+
* PUT requests
157+
*
158+
* @param {String} endpoint
159+
* @param {Object} data
160+
* @param {Object} params
161+
*
162+
* @return {Object}
163+
*/
164+
public put(endpoint: string, data: any): any
165+
public put(endpoint: string, data: any, params: any): any
166+
167+
/**
168+
* DELETE requests
169+
*
170+
* @param {String} endpoint
171+
* @param {Object} params
172+
* @param {Object} params
173+
*
174+
* @return {Object}
175+
*/
176+
public delete(endpoint: string): any
177+
public delete(endpoint: string, params: any): any
178+
179+
/**
180+
* OPTIONS requests
181+
*
182+
* @param {String} endpoint
183+
* @param {Object} params
184+
*
185+
* @return {Object}
186+
*/
187+
public options(endpoint: string): any
188+
public options(endpoint: string, params: any): any
189+
}
190+
191+
/**
192+
* Options Exception.
193+
*/
194+
export class OptionsException {
195+
public name: 'Options Error'
196+
public message: string
197+
198+
/**
199+
* Constructor.
200+
*
201+
* @param {String} message
202+
*/
203+
constructor(message: string)
204+
}
205+
206+
export default WooCommerceRestApi

0 commit comments

Comments
 (0)