UNPKG

@cisco-meraki/dashboard-api-tools

Version:

Typescript library for interacting with Meraki's public API

41 lines (40 loc) 1.52 kB
declare const httpMethods: readonly ["get", "post", "put", "delete", "options", "GET", "POST", "PUT", "DELETE", "OPTIONS"]; export declare type HTTPMethod = typeof httpMethods[number]; export declare type ApiError = { errors: string[]; ok: false; statusCode: number; statusText: string; }; export declare type Options = { fetchOptions?: RequestInit | undefined; auth?: { apiKey?: string; csrfToken?: string; }; }; export declare type ApiResponse<ResponseData> = ApiMetadata & { data: ResponseData; }; declare type ApiMetadata = { firstPageUrl: string | null; lastPageUrl: string | null; nextPageUrl: string | null; prevPageUrl: string | null; linkHeader: string | null; retryAfter: number | null; errors: null; ok: true; statusCode: number; statusText: string; }; export declare type ApiRequestParams = { method: HTTPMethod; url: string; data?: Record<string, unknown> | undefined; options?: Options; }; declare const apiRequest: <ResponseData>(method: HTTPMethod, url: string, data?: Record<string, unknown> | undefined, options?: Options) => Promise<ApiResponse<ResponseData>>; declare const isApiError: (response: unknown) => response is ApiError; declare const paginatedApiRequest: <ResponseData>(dataHandler: (data: ResponseData) => void, errorHandler: (errors: string[]) => void, apiRequestParams: ApiRequestParams, maxRequests?: number) => Promise<void>; export { apiRequest, isApiError, paginatedApiRequest };