UNPKG

nylas

Version:

A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.

83 lines (82 loc) 2.71 kB
import { Request, Response } from 'node-fetch'; import { NylasConfig, OverridableNylasConfig } from './config.js'; import { FormData } from 'formdata-node'; /** * The header key for the debugging flow ID */ export declare const FLOW_ID_HEADER = "x-fastly-id"; /** * The header key for the request ID */ export declare const REQUEST_ID_HEADER = "x-request-id"; /** * Options for a request to the Nylas API * @property path The path to the API endpoint * @property method The HTTP method to use * @property headers Additional headers to send with the request * @property queryParams Query parameters to send with the request * @property body The body of the request * @property overrides Overrides to the default Nylas API client configuration * @ignore Not for public use */ export interface RequestOptionsParams { path: string; method: string; headers?: Record<string, string>; queryParams?: Record<string, any>; body?: any; form?: FormData; overrides?: OverridableNylasConfig; } /** * Options for building a request for fetch to understand * @property path The path to the API endpoint * @property method The HTTP method to use * @property headers Additional headers to send with the request * @property url The URL of the request * @property body The body of the request * @property overrides Overrides to the default Nylas API client configuration * @ignore Not for public use */ interface RequestOptions { path: string; method: string; headers: Record<string, string>; url: URL; body?: any; overrides?: Partial<NylasConfig>; } /** * The API client for communicating with the Nylas API * @ignore Not for public use */ export default class APIClient { /** * The API key to use for authentication */ apiKey: string; /** * The URL to use for communicating with the Nylas API */ serverUrl: string; /** * The timeout for requests to the Nylas API, in seconds */ timeout: number; /** * Additional headers to send with outgoing requests */ headers: Record<string, string>; constructor({ apiKey, apiUri, timeout, headers }: Required<NylasConfig>); private setRequestUrl; private setQueryStrings; private setRequestHeaders; private sendRequest; requestOptions(optionParams: RequestOptionsParams): RequestOptions; newRequest(options: RequestOptionsParams): Request; requestWithResponse<T>(response: Response): Promise<T>; request<T>(options: RequestOptionsParams): Promise<T>; requestRaw(options: RequestOptionsParams): Promise<Buffer>; requestStream(options: RequestOptionsParams): Promise<NodeJS.ReadableStream>; } export {};