omnisend-node-sdk
Version:
🔹 Typesafe Omnisend API SDK for Node.js
53 lines (52 loc) • 2.29 kB
TypeScript
import type { AxiosInstance, AxiosRequestConfig, ResponseType } from "axios";
import FormData from "form-data";
export type QueryParamsType = Record<string | number, any>;
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
/** set parameter to `true` for call `securityWorker` for this request */
secure?: boolean;
/** request path */
path: string;
/** content type of request body */
type?: ContentType;
/** query params */
query?: QueryParamsType;
/** format of response (i.e. response.json() -> format: "json") */
format?: ResponseType;
/** request body */
body?: unknown;
}
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
export interface ApiConfig<SecurityDataType = unknown, SafeMode extends true | false = false> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
secure?: boolean;
format?: ResponseType;
safeMode?: SafeMode;
}
export declare enum ContentType {
Json = "application/json",
FormData = "multipart/form-data",
UrlEncoded = "application/x-www-form-urlencoded",
Text = "text/plain"
}
type WithSafeMode<S, T> = S extends true ? {
success: true;
data: T;
} | {
success: false;
error?: string;
} : T;
export declare class HttpClient<SecurityDataType = unknown, SafeMode extends true | false = any> {
instance: AxiosInstance;
private securityData;
private securityWorker?;
private secure?;
private format?;
private safeMode?;
constructor({ securityWorker, secure, format, safeMode, ...axiosConfig }?: ApiConfig<SecurityDataType, SafeMode>);
setSecurityData: (data: SecurityDataType | null) => void;
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
protected stringifyFormItem(formItem: unknown): string;
protected createFormData(input: Record<string, unknown>): FormData;
request: <T = any, ignore = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<WithSafeMode<SafeMode, T>>;
}
export {};