@zayne-labs/callapi 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-ERam9OPy.d.cts → index-BpNetCiS.d.cts} +78 -78
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +8 -8
- package/dist/cjs/options/index.cjs.map +1 -1
- package/dist/cjs/options/index.d.cts +10 -10
- package/dist/cjs/utils/index.d.cts +1 -1
- package/dist/esm/{chunk-L7XLLBDP.js → chunk-QDTFT5II.js} +1 -1
- package/dist/esm/chunk-QDTFT5II.js.map +1 -0
- package/dist/esm/{chunk-YMYY7IIH.js → chunk-SMQCV7OH.js} +1 -1
- package/dist/esm/chunk-SMQCV7OH.js.map +1 -0
- package/dist/esm/{index-ERam9OPy.d.ts → index-BpNetCiS.d.ts} +78 -78
- package/dist/esm/index.d.ts +8 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/options/index.d.ts +10 -10
- package/dist/esm/options/index.js +1 -1
- package/dist/esm/options/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-L7XLLBDP.js.map +0 -1
- package/dist/esm/chunk-YMYY7IIH.js.map +0 -1
|
@@ -60,40 +60,48 @@ type UnmaskType<TValue> = {
|
|
|
60
60
|
}["_"];
|
|
61
61
|
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
62
62
|
type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy-Report-Only" | "Content-Security-Policy" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Platform" | "Sec-CH-UA-WoW64" | "Sec-CH-UA" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server-Timing" | "Server" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "Warning" | "WWW-Authenticate" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection";
|
|
63
|
-
type CommonAuthorizationHeaders = "Basic" | "Bearer" | "Token"
|
|
63
|
+
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
64
64
|
type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo";
|
|
65
65
|
|
|
66
|
-
type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
declare const toQueryString: ToQueryStringFn;
|
|
71
|
-
declare const getResponseType: <TResponse>(response: Response, parser?: Required<CallApiExtraOptions>["responseParser"]) => {
|
|
72
|
-
arrayBuffer: () => Promise<TResponse>;
|
|
73
|
-
blob: () => Promise<TResponse>;
|
|
74
|
-
formData: () => Promise<TResponse>;
|
|
75
|
-
json: () => Promise<Record<string, unknown> | TResponse>;
|
|
76
|
-
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
77
|
-
text: () => Promise<TResponse>;
|
|
78
|
-
};
|
|
79
|
-
type ErrorObjectUnion<TErrorData = unknown> = PossibleHTTPError<TErrorData> | PossibleJavaScriptError;
|
|
80
|
-
declare const isHTTPError: <TErrorData>(error: ErrorObjectUnion<TErrorData> | null) => error is PossibleHTTPError<TErrorData>;
|
|
81
|
-
type ErrorDetails<TErrorResponse> = {
|
|
82
|
-
defaultErrorMessage: string;
|
|
83
|
-
errorData: TErrorResponse;
|
|
84
|
-
response: Response;
|
|
66
|
+
type PluginInitContext<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
|
|
67
|
+
initURL: string;
|
|
68
|
+
options: CombinedCallApiExtraOptions<DefaultDataType, DefaultDataType, ResultModeUnion, TMoreOptions>;
|
|
69
|
+
request: CallApiRequestOptionsForHooks;
|
|
85
70
|
};
|
|
86
|
-
type
|
|
87
|
-
|
|
71
|
+
type CreateExtraOptions<TMoreOptions> = (...params: never[]) => TMoreOptions;
|
|
72
|
+
type CallApiPlugin<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
|
|
73
|
+
/**
|
|
74
|
+
* @description Defines additional options that can be passed to callApi
|
|
75
|
+
*/
|
|
76
|
+
createExtraOptions?: CreateExtraOptions<TMoreOptions>;
|
|
77
|
+
/**
|
|
78
|
+
* @description A description for the plugin
|
|
79
|
+
*/
|
|
80
|
+
description?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Hooks / Interceptors for the plugin
|
|
83
|
+
*/
|
|
84
|
+
hooks?: InterceptorsOrInterceptorArray;
|
|
85
|
+
/**
|
|
86
|
+
* @description A unique id for the plugin
|
|
87
|
+
*/
|
|
88
|
+
id: string;
|
|
89
|
+
/**
|
|
90
|
+
* @description A function that will be called when the plugin is
|
|
91
|
+
* initialized. This will be called before the any
|
|
92
|
+
* of the other internal functions.
|
|
93
|
+
*/
|
|
94
|
+
init?: (context: PluginInitContext) => Awaitable<Partial<PluginInitContext>> | Awaitable<void>;
|
|
95
|
+
/**
|
|
96
|
+
* @description A name for the plugin
|
|
97
|
+
*/
|
|
98
|
+
name: string;
|
|
99
|
+
/**
|
|
100
|
+
* @description A version for the plugin
|
|
101
|
+
*/
|
|
102
|
+
version?: string;
|
|
88
103
|
};
|
|
89
|
-
declare
|
|
90
|
-
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
|
91
|
-
isHTTPError: boolean;
|
|
92
|
-
name: "HTTPError";
|
|
93
|
-
response: ErrorDetails<TErrorResponse>["response"];
|
|
94
|
-
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
|
95
|
-
}
|
|
96
|
-
declare const isHTTPErrorInstance: <TErrorResponse>(error: unknown) => error is HTTPError<TErrorResponse>;
|
|
104
|
+
declare const definePlugin: <TMoreOptions extends AnyObject = {}, TPlugin extends AnyFunction<CallApiPlugin<TMoreOptions>> | CallApiPlugin<TMoreOptions> = CallApiPlugin<TMoreOptions>>(plugin: TPlugin) => TPlugin;
|
|
97
105
|
|
|
98
106
|
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => boolean | Promise<boolean>;
|
|
99
107
|
interface RetryOptions<TErrorData> {
|
|
@@ -137,45 +145,37 @@ interface RetryOptions<TErrorData> {
|
|
|
137
145
|
retryStrategy?: "exponential" | "linear";
|
|
138
146
|
}
|
|
139
147
|
|
|
140
|
-
type
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
request: CallApiRequestOptionsForHooks;
|
|
148
|
+
type ToQueryStringFn = {
|
|
149
|
+
(params: CallApiConfig["query"]): string | null;
|
|
150
|
+
(params: Required<CallApiConfig>["query"]): string;
|
|
144
151
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*/
|
|
154
|
-
description?: string;
|
|
155
|
-
/**
|
|
156
|
-
* Hooks / Interceptors for the plugin
|
|
157
|
-
*/
|
|
158
|
-
hooks?: InterceptorsOrInterceptorArray;
|
|
159
|
-
/**
|
|
160
|
-
* @description A unique id for the plugin
|
|
161
|
-
*/
|
|
162
|
-
id: string;
|
|
163
|
-
/**
|
|
164
|
-
* @description A function that will be called when the plugin is
|
|
165
|
-
* initialized. This will be called before the any
|
|
166
|
-
* of the other internal functions.
|
|
167
|
-
*/
|
|
168
|
-
init?: (context: PluginInitContext) => Awaitable<Partial<PluginInitContext>> | Awaitable<void>;
|
|
169
|
-
/**
|
|
170
|
-
* @description A name for the plugin
|
|
171
|
-
*/
|
|
172
|
-
name: string;
|
|
173
|
-
/**
|
|
174
|
-
* @description A version for the plugin
|
|
175
|
-
*/
|
|
176
|
-
version?: string;
|
|
152
|
+
declare const toQueryString: ToQueryStringFn;
|
|
153
|
+
declare const getResponseType: <TResponse>(response: Response, parser?: Required<CallApiExtraOptions>["responseParser"]) => {
|
|
154
|
+
arrayBuffer: () => Promise<TResponse>;
|
|
155
|
+
blob: () => Promise<TResponse>;
|
|
156
|
+
formData: () => Promise<TResponse>;
|
|
157
|
+
json: () => Promise<Record<string, unknown> | TResponse>;
|
|
158
|
+
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
|
|
159
|
+
text: () => Promise<TResponse>;
|
|
177
160
|
};
|
|
178
|
-
|
|
161
|
+
type ErrorObjectUnion<TErrorData = unknown> = PossibleHTTPError<TErrorData> | PossibleJavaScriptError;
|
|
162
|
+
declare const isHTTPError: <TErrorData>(error: ErrorObjectUnion<TErrorData> | null) => error is PossibleHTTPError<TErrorData>;
|
|
163
|
+
type ErrorDetails<TErrorResponse> = {
|
|
164
|
+
defaultErrorMessage: string;
|
|
165
|
+
errorData: TErrorResponse;
|
|
166
|
+
response: Response;
|
|
167
|
+
};
|
|
168
|
+
type ErrorOptions = {
|
|
169
|
+
cause?: unknown;
|
|
170
|
+
};
|
|
171
|
+
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
|
172
|
+
errorData: ErrorDetails<TErrorResponse>["errorData"];
|
|
173
|
+
isHTTPError: boolean;
|
|
174
|
+
name: "HTTPError";
|
|
175
|
+
response: ErrorDetails<TErrorResponse>["response"];
|
|
176
|
+
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
|
177
|
+
}
|
|
178
|
+
declare const isHTTPErrorInstance: <TErrorResponse>(error: unknown) => error is HTTPError<TErrorResponse>;
|
|
179
179
|
|
|
180
180
|
declare const fetchSpecificKeys: ("body" | "cache" | "credentials" | "headers" | "integrity" | "keepalive" | "method" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
|
|
181
181
|
|
|
@@ -196,7 +196,7 @@ interface CallApiRequestOptions extends Pick<RequestInit, FetchSpecificKeysUnion
|
|
|
196
196
|
method?: "DELETE" | "GET" | "PATCH" | "POST" | "PUT" | AnyString;
|
|
197
197
|
}
|
|
198
198
|
interface CallApiRequestOptionsForHooks extends CallApiRequestOptions {
|
|
199
|
-
headers?: Record<CommonRequestHeaders | AnyString, string>;
|
|
199
|
+
headers?: Record<CommonRequestHeaders | AnyString, string> | Record<string, string>;
|
|
200
200
|
}
|
|
201
201
|
interface Register {
|
|
202
202
|
}
|
|
@@ -241,7 +241,7 @@ type DefaultMoreOptions = NonNullable<unknown>;
|
|
|
241
241
|
type Meta = Register extends {
|
|
242
242
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
243
243
|
} ? TMeta : never;
|
|
244
|
-
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends
|
|
244
|
+
type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = InterceptorsOrInterceptorArray<TData, TErrorData> & Partial<TMoreOptions> & RetryOptions<TErrorData> & {
|
|
245
245
|
/**
|
|
246
246
|
* @description Authorization header value.
|
|
247
247
|
*/
|
|
@@ -374,18 +374,18 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
|
|
|
374
374
|
timeout?: number;
|
|
375
375
|
};
|
|
376
376
|
declare const optionsEnumToExtendFromBase: "plugins"[];
|
|
377
|
-
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends
|
|
377
|
+
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = ExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & {
|
|
378
378
|
/**
|
|
379
379
|
* @description Options that should extend the base options.
|
|
380
380
|
*/
|
|
381
381
|
extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TMoreOptions>, (typeof optionsEnumToExtendFromBase)[number]>;
|
|
382
382
|
};
|
|
383
383
|
declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
|
|
384
|
-
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends
|
|
385
|
-
type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends
|
|
386
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends
|
|
387
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends
|
|
388
|
-
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends
|
|
384
|
+
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = Omit<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TMoreOptions>, (typeof optionsEnumToOmitFromBase)[number]>;
|
|
385
|
+
type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = BaseCallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & CallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions>;
|
|
386
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = CallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & CallApiRequestOptions;
|
|
387
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseMoreOptions extends AnyObject = DefaultMoreOptions> = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseMoreOptions> & CallApiRequestOptions;
|
|
388
|
+
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = [initURL: string, config?: CallApiConfig<TData, TErrorData, TResultMode, TMoreOptions>];
|
|
389
389
|
type RequestContext = UnmaskType<{
|
|
390
390
|
options: CombinedCallApiExtraOptions;
|
|
391
391
|
request: CallApiRequestOptionsForHooks;
|
|
@@ -463,9 +463,9 @@ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType> = {
|
|
|
463
463
|
onlySuccess: CallApiResultErrorVariant<TErrorData>["data"] | CallApiResultSuccessVariant<TData>["data"];
|
|
464
464
|
onlySuccessWithException: CallApiResultSuccessVariant<TData>["data"];
|
|
465
465
|
};
|
|
466
|
-
type
|
|
466
|
+
type ResultModeUnion = {
|
|
467
467
|
[Key in keyof ResultModeMap]: Key;
|
|
468
468
|
}[keyof ResultModeMap] | undefined;
|
|
469
|
-
type GetCallApiResult<TData, TErrorData, TResultMode> = TErrorData extends false ? ResultModeMap<TData, TErrorData>["onlySuccessWithException"] : undefined extends TResultMode ? ResultModeMap<TData, TErrorData>["all"] : TResultMode extends NonNullable<
|
|
469
|
+
type GetCallApiResult<TData, TErrorData, TResultMode> = TErrorData extends false ? ResultModeMap<TData, TErrorData>["onlySuccessWithException"] : undefined extends TResultMode ? ResultModeMap<TData, TErrorData>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData>[TResultMode] : never;
|
|
470
470
|
|
|
471
|
-
export { type AnyObject as A, type BaseCallApiConfig as B, type
|
|
471
|
+
export { type AnyObject as A, type BaseCallApiConfig as B, type CallApiConfig as C, type DefaultDataType as D, type ErrorContext as E, type GetCallApiResult as G, HTTPError as H, type Interceptors as I, type PluginInitContext as P, type ResultModeUnion as R, type SuccessContext as S, type CallApiPlugin as a, type BaseCallApiExtraOptions as b, type CallApiExtraOptions as c, definePlugin as d, type PossibleJavaScriptError as e, type PossibleHTTPError as f, type CallApiParameters as g, type CallApiRequestOptions as h, type CallApiRequestOptionsForHooks as i, type CallApiResultErrorVariant as j, type CallApiResultSuccessVariant as k, type CombinedCallApiExtraOptions as l, type InterceptorsOrInterceptorArray as m, type PossibleJavascriptErrorNames as n, type Register as o, type RequestContext as p, type RequestErrorContext as q, type ResponseContext as r, type ResponseErrorContext as s, type DefaultMoreOptions as t, isHTTPError as u, isHTTPErrorInstance as v, toQueryString as w };
|