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