|
| 1 | + |
| 2 | +declare module '@foxcomm/api-js' { |
| 3 | + declare type StringDict = {[name: string]: string}; |
| 4 | + |
| 5 | + declare type AbortablePromise = Promise & { |
| 6 | + abort(): void; |
| 7 | + }; |
| 8 | + |
| 9 | + declare type AgentLike = AbortablePromise & { |
| 10 | + get(url: string): AgentLike; |
| 11 | + post(url: string): AgentLike; |
| 12 | + patch(url: string): AgentLike; |
| 13 | + delete(url: string): AgentLike; |
| 14 | + |
| 15 | + set(headers: StringDict): AgentLike; |
| 16 | + withCredentials(): AgentLike; |
| 17 | + }; |
| 18 | + |
| 19 | + declare type RequestOptions = { |
| 20 | + headers?: StringDict, |
| 21 | + credentials?: string, |
| 22 | + agent?: AgentLike; |
| 23 | + }; |
| 24 | + |
| 25 | + // @TODO: add subclasses |
| 26 | + declare class ApiClass { |
| 27 | + addresses: mixed; |
| 28 | + auth: mixed; |
| 29 | + creditCards: mixed; |
| 30 | + storeCredits: mixed; |
| 31 | + cart: mixed; |
| 32 | + account: mixed; |
| 33 | + orders: mixed; |
| 34 | + reviews: mixed; |
| 35 | + analytics: mixed; |
| 36 | + crossSell: mixed; |
| 37 | + |
| 38 | + addAuth(jwt: string): ApiClass; |
| 39 | + removeAuth(): ApiClass; |
| 40 | + |
| 41 | + // Returns customer id from parsed jwt string |
| 42 | + // You can define jwt string via `addAuth` method, if there is no jwt strings method returns null. |
| 43 | + getCustomerId(): ?number; |
| 44 | + |
| 45 | + setHeaders(headers: StringDict): ApiClass; |
| 46 | + addHeaders(headers: StringDict): ApiClass; |
| 47 | + uri(path: string): string; |
| 48 | + queryStringToObject(qs: string): StringDict; |
| 49 | + |
| 50 | + request(method: string, uri: string, data: ?Object, options: ?RequestOptions): AbortablePromise; |
| 51 | + get(uri: string, data: ?Object, options: ?Object): AbortablePromise; |
| 52 | + post(uri: string, data: ?Object, options: ?Object): AbortablePromise; |
| 53 | + patch(uri: string, data: ?Object, options: ?Object): AbortablePromise; |
| 54 | + delete(uri: string, data: ?Object, options: ?Object): AbortablePromise; |
| 55 | + } |
| 56 | + |
| 57 | + declare function parseError(err: mixed): Array<string>; |
| 58 | + |
| 59 | + declare module.exports: typeof ApiClass; |
| 60 | +} |
0 commit comments