UNPKG

magento2-api-wrapper

Version:

Minimal Magento 2 API library. Both node and browser compatible

39 lines (38 loc) 1.76 kB
/// <reference types="node" /> import { OAuth } from "./OAuth.js"; export declare class Magento2Api { oauth: undefined | OAuth; options: MagentoApiOptions; requestMiddleware: ((request: Request) => any)[]; responseMiddleware: ((response: Response | null, error?: Error) => any)[]; constructor(options: MagentoApiOptions); request(method: string, path: string, data?: any, options?: Magento2ApiRequestOptions & any): Promise<Response>; /** * Internal method that could be overriden to decorate more response / reqest / add exception etc. */ fetch(request: Request, options: any): Promise<Response>; buildRequest(method: string, path: string, data?: any, options?: Magento2ApiRequestOptions): Promise<Request>; $<T>(method: string, path: string, data: any, options?: Magento2ApiRequestOptions): Promise<T>; $get<T>(path: string, options?: Magento2ApiRequestOptions): Promise<T>; $post<T>(path: string, data: any, options?: Magento2ApiRequestOptions): Promise<T>; $patch<T>(path: string, data: any, options?: Magento2ApiRequestOptions): Promise<T>; $put<T>(path: string, data: any, options?: Magento2ApiRequestOptions): Promise<T>; $delete<T>(path: string, options?: Magento2ApiRequestOptions): Promise<T>; } export type MagentoApiOptions = { url: string; storeCode?: string; apiVersion?: number; consumerKey?: string; consumerSecret?: string; accessToken?: string; tokenSecret?: string; }; export type Magento2ApiRequestOptions<FetchOptions = any> = RequestInit & { params?: any; storeCode?: string; fetchOptions?: FetchOptions; }; export declare class MagentoOAuth extends OAuth { constructRequestUrl(request: Pick<Request, "url">): string; }