@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.
@@ -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 ToQueryStringFn = {
67
- (params: CallApiConfig["query"]): string | null;
68
- (params: Required<CallApiConfig>["query"]): string;
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 ErrorOptions = {
87
- cause?: unknown;
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 class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
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 PluginInitContext<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
141
- initURL: string;
142
- options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
143
- request: CallApiRequestOptionsForHooks;
148
+ type ToQueryStringFn = {
149
+ (params: CallApiConfig["query"]): string | null;
150
+ (params: Required<CallApiConfig>["query"]): string;
144
151
  };
145
- type CreateExtraOptions<TMoreOptions> = (...params: never[]) => TMoreOptions;
146
- type CallApiPlugin<TMoreOptions extends AnyObject = DefaultMoreOptions> = {
147
- /**
148
- * @description Defines additional options that can be passed to callApi
149
- */
150
- createExtraOptions?: CreateExtraOptions<TMoreOptions>;
151
- /**
152
- * @description A description for the plugin
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
- declare const definePlugin: <TMoreOptions extends AnyObject = {}, TPlugin extends AnyFunction<CallApiPlugin<TMoreOptions>> | CallApiPlugin<TMoreOptions> = CallApiPlugin<TMoreOptions>>(plugin: TPlugin) => TPlugin;
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 CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = InterceptorsOrInterceptorArray<TData, TErrorData> & Partial<TMoreOptions> & RetryOptions<TErrorData> & {
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 CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = ExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & {
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 CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = Omit<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TMoreOptions>, (typeof optionsEnumToOmitFromBase)[number]>;
385
- type CombinedCallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = BaseCallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & CallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions>;
386
- type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = CallApiExtraOptions<TData, TErrorData, TResultMode, TMoreOptions> & CallApiRequestOptions;
387
- type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends CallApiResultModeUnion = CallApiResultModeUnion, TBaseMoreOptions extends AnyObject = DefaultMoreOptions> = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseMoreOptions> & CallApiRequestOptions;
388
- type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends CallApiResultModeUnion = CallApiResultModeUnion, TMoreOptions extends AnyObject = DefaultMoreOptions> = [initURL: string, config?: CallApiConfig<TData, TErrorData, TResultMode, TMoreOptions>];
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 CallApiResultModeUnion = {
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<CallApiResultModeUnion> ? ResultModeMap<TData, TErrorData>[TResultMode] : never;
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 CallApiResultModeUnion 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 Register as R, type SuccessContext as S, type CallApiConfig as a, type CallApiPlugin as b, type BaseCallApiExtraOptions as c, definePlugin as d, type CallApiExtraOptions as e, type PossibleJavaScriptError as f, type PossibleHTTPError as g, type CallApiParameters as h, type CallApiRequestOptions as i, type CallApiRequestOptionsForHooks as j, type CallApiResultErrorVariant as k, type CallApiResultSuccessVariant as l, type CombinedCallApiExtraOptions as m, type InterceptorsOrInterceptorArray as n, type PossibleJavascriptErrorNames 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 };
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 };