|
| 1 | +importaxiosfrom'axios' |
| 2 | +importcreateHmacfrom'create-hmac' |
| 3 | +importOAuthfrom'oauth-1.0a' |
| 4 | +importUrlfrom'url-parse' |
| 5 | + |
| 6 | +exporttypeWooCommerceRestApiVersion= |
| 7 | +|'wc/v3' |
| 8 | +|'wc/v2' |
| 9 | +|'wc/v1' |
| 10 | +|'wc-api/v3' |
| 11 | +|'wc-api/v2' |
| 12 | +|'wc-api/v1' |
| 13 | +exporttypeWooCommerceRestApiEncoding='utf-8'|'ascii' |
| 14 | +exporttypeWooCommerceRestApiMethod= |
| 15 | +|'get' |
| 16 | +|'post' |
| 17 | +|'put' |
| 18 | +|'delete' |
| 19 | +|'options' |
| 20 | + |
| 21 | +exportinterfaceIWooCommerceRestApiOptions{ |
| 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 | +exportinterfaceIWooCommerceRestApiQuery{ |
| 45 | +[key: string]: string |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * WooCommerce REST API wrapper |
| 50 | + * |
| 51 | + * @param{Object} opt |
| 52 | + */ |
| 53 | +exportclassWooCommerceRestApi{ |
| 54 | +protectedclassVersion: string |
| 55 | +protectedurl: string |
| 56 | +protectedconsumerKey: string |
| 57 | +protectedconsumerSecret: string |
| 58 | +protectedwpAPIPrefix: string |
| 59 | +protectedversion: WooCommerceRestApiVersion |
| 60 | +protectedencoding: WooCommerceRestApiEncoding |
| 61 | +protectedqueryStringAuth: boolean |
| 62 | +protectedport: number |
| 63 | +protectedtimeout: number |
| 64 | +protectedaxiosConfig: 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 | +publicget(endpoint: string): any |
| 141 | +publicget(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 | +publicpost(endpoint: string,data: any): any |
| 153 | +publicpost(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 | +publicput(endpoint: string,data: any): any |
| 165 | +publicput(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 | +publicdelete(endpoint: string): any |
| 177 | +publicdelete(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 | +publicoptions(endpoint: string): any |
| 188 | +publicoptions(endpoint: string,params: any): any |
| 189 | +} |
| 190 | + |
| 191 | +/** |
| 192 | + * Options Exception. |
| 193 | + */ |
| 194 | +exportclassOptionsException{ |
| 195 | +publicname: 'Options Error' |
| 196 | +publicmessage: string |
| 197 | + |
| 198 | +/** |
| 199 | + * Constructor. |
| 200 | + * |
| 201 | + * @param{String} message |
| 202 | + */ |
| 203 | +constructor(message: string) |
| 204 | +} |
| 205 | + |
| 206 | +exportdefaultWooCommerceRestApi |
0 commit comments