This repository was archived by the owner on Jul 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
200 lines (182 loc) · 4.25 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
import * as OAuth from 'oauth-1.0a'
export declare type CoCartVersion =
| 'cocart/v2'
| 'cocart/v1'
export declare type CoCartEncoding = 'utf-8' | 'ascii'
export declare type CoCartMethod =
| 'get'
| 'post'
| 'put'
| 'delete'
| 'options'
export interface CoCartOptions {
/* Your Store URL, example: https://example.com/ */
url: string
/* Your API consumer key or username */
consumerKey: string
/* Your API consumer secret or password */
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 `cocart/v2` */
version?: CoCartVersion
/* Encoding, default is 'utf-8' */
encoding?: CoCartEncoding
/* 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
/* Authenticate with Oauth 1.0a */
oauth?: boolean,
/* Define the request timeout */
timeout?: number
/* Define the custom Axios config, also override this library options */
axiosConfig?: any
}
export interface CoCartQuery {
[key: string]: string
}
/**
* CoCart REST API wrapper
*
* @param {Object} opt
*/
export default class CoCart {
protected classVersion: string
protected url: string
protected consumerKey: string
protected consumerSecret: string
protected wpAPIPrefix: string
protected version: CoCartVersion
protected encoding: CoCartEncoding
protected queryStringAuth: boolean
protected port: number
protected oauth: boolean
protected timeout: number
protected axiosConfig: any
/**
* Class constructor.
*
* @param {Object} opt
*/
constructor(opt: CoCartOptions | CoCart)
/**
* Set default options
*
* @param {Object} opt
*/
private _setDefaultsOptions(opt: CoCartOptions): void
/**
* Parse params object.
*
* @param {Object} params
* @param {Object} query
*/
private _parseParamsObject(params: any, query: any): CoCartQuery
/**
* 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: CoCartMethod,
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)
}