@zayne-labs/callapi-plugins 4.0.31 → 4.0.33

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.
@@ -9,7 +9,7 @@ declare const fallBackRouteSchemaKey = "@default";
9
9
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
10
10
  //#endregion
11
11
  //#endregion
12
- //#region ../callapi/dist/index-DP2YeNBA.d.ts
12
+ //#region ../callapi/dist/index-YnlEWnbR.d.ts
13
13
  //#region src/types/type-helpers.d.ts
14
14
  type AnyString = string & NonNullable<unknown>;
15
15
  type AnyNumber = number & NonNullable<unknown>;
@@ -46,14 +46,13 @@ type CommonContentTypes = "application/epub+zip" | "application/gzip" | "applica
46
46
  //#region src/auth.d.ts
47
47
  type PossibleAuthValue = Awaitable<string | null | undefined>;
48
48
  type PossibleAuthValueOrGetter = PossibleAuthValue | (() => PossibleAuthValue);
49
- type BearerOrTokenAuth = {
50
- type?: "Bearer";
51
- bearer?: PossibleAuthValueOrGetter;
52
- token?: never;
53
- } | {
54
- type?: "Token";
55
- bearer?: never;
56
- token?: PossibleAuthValueOrGetter;
49
+ type BearerAuth = {
50
+ type: "Bearer";
51
+ value: PossibleAuthValueOrGetter;
52
+ };
53
+ type TokenAuth = {
54
+ type: "Token";
55
+ value: PossibleAuthValueOrGetter;
57
56
  };
58
57
  type BasicAuth = {
59
58
  type: "Basic";
@@ -80,7 +79,7 @@ type CustomAuth = {
80
79
  prefix: PossibleAuthValueOrGetter;
81
80
  value: PossibleAuthValueOrGetter;
82
81
  };
83
- type Auth = PossibleAuthValueOrGetter | BearerOrTokenAuth | BasicAuth | CustomAuth;
82
+ type AuthOption = PossibleAuthValueOrGetter | BearerAuth | TokenAuth | BasicAuth | CustomAuth;
84
83
  //#endregion
85
84
  //#region src/stream.d.ts
86
85
  type StreamProgressEvent = {
@@ -102,254 +101,85 @@ type StreamProgressEvent = {
102
101
  transferredBytes: number;
103
102
  };
104
103
  //#endregion
105
- //#region src/middlewares.d.ts
106
- type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
107
- interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {
108
- /**
109
- * Wraps the fetch implementation to intercept requests at the network layer.
110
- *
111
- * Takes a context object containing the current fetch function and returns a new fetch function.
112
- * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
113
- * Multiple middleware compose in order: plugins → base config → per-request.
114
- *
115
- * Unlike `customFetchImpl`, middleware can call through to the original fetch.
116
- *
117
- * @example
118
- * ```ts
119
- * // Cache responses
120
- * const cache = new Map();
121
- *
122
- * fetchMiddleware: (ctx) => async (input, init) => {
123
- * const key = input.toString();
124
- * if (cache.has(key)) return cache.get(key).clone();
125
- *
126
- * const response = await ctx.fetchImpl(input, init);
127
- * cache.set(key, response.clone());
128
- * return response;
129
- * }
130
- *
131
- * // Handle offline
132
- * fetchMiddleware: (ctx) => async (input, init) => {
133
- * if (!navigator.onLine) {
134
- * return new Response('{"error": "offline"}', { status: 503 });
135
- * }
136
- * return ctx.fetchImpl(input, init);
137
- * }
138
- * ```
139
- */
140
- fetchMiddleware?: (context: RequestContext<TCallApiContext> & {
141
- fetchImpl: FetchImpl;
142
- }) => FetchImpl;
143
- }
144
- //#endregion
145
- //#region src/types/conditional-types.d.ts
146
- /**
147
- * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
148
- */
149
- type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
150
- type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
151
- type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys :
152
- // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
153
- TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
154
- type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
155
- type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
156
- type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
157
- type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
158
- type JsonPrimitive = boolean | number | string | null | undefined;
159
- type SerializableObject = Record<PropertyKey, unknown>;
160
- type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
161
- type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
162
- type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
163
- /**
164
- * Body of the request, can be a object or any other supported body type.
165
- */
166
- body?: InferSchemaOutput<TSchema["body"], Body>;
167
- }>;
168
- type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
169
- type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
170
- type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
171
- /**
172
- * HTTP method for the request.
173
- * @default "GET"
174
- */
175
- method?: InferSchemaOutput<TSchema["method"], InferMethodFromURL<TInitURL>>;
176
- }>;
177
- type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
178
- type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
179
- /**
180
- * Headers to be used in the request.
181
- */
182
- headers?: InferSchemaOutput<TSchema["headers"], HeadersOption> | ((context: {
183
- baseHeaders: NonNullable<HeadersOption>;
184
- }) => InferSchemaOutput<TSchema["headers"], HeadersOption>);
185
- }>;
186
- type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
187
- type InferMetaOption<TSchema extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
188
- /**
189
- * - An optional field you can fill with additional information,
190
- * to associate with the request, typically used for logging or tracing.
191
- *
192
- * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
193
- *
194
- * @example
195
- * ```ts
196
- * const callMainApi = callApi.create({
197
- * baseURL: "https://main-api.com",
198
- * onResponseError: ({ response, options }) => {
199
- * if (options.meta?.userId) {
200
- * console.error(`User ${options.meta.userId} made an error`);
201
- * }
202
- * },
203
- * });
204
- *
205
- * const response = await callMainApi({
206
- * url: "https://example.com/api/data",
207
- * meta: { userId: "123" },
208
- * });
209
- * ```
210
- */
211
- meta?: InferSchemaOutput<TSchema["meta"], TCallApiContext["Meta"]>;
212
- }>;
213
- type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
214
- /**
215
- * Parameters to be appended to the URL (i.e: /:id)
216
- */
217
- query?: InferSchemaOutput<TSchema["query"], Query>;
218
- }>;
219
- type EmptyString = "";
220
- type EmptyTuple = readonly [];
221
- type StringTuple = readonly string[];
222
- type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
223
- type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
224
- type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
225
- type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
226
- type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
227
- type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
228
- type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
229
- /**
230
- * Parameters to be appended to the URL (i.e: /:id)
231
- */
232
- params?: InferSchemaOutput<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
233
- }>;
234
- type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferMetaOption<TSchema, TCallApiContext> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
235
- type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
236
- type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorData extends false ? {
237
- resultMode: "onlyData";
238
- } : TErrorData extends false | undefined ? {
239
- resultMode?: "onlyData";
240
- } : {
241
- resultMode?: TResultMode;
242
- };
243
- type ThrowOnErrorUnion = boolean;
244
- type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<{
245
- ErrorData: TErrorData;
246
- }>) => TThrowOnError);
247
- type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
248
- throwOnError: true;
249
- } : TErrorData extends false | undefined ? {
250
- throwOnError?: true;
251
- } : {
252
- throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
253
- };
254
- //#endregion
255
104
  //#region src/types/standard-schema.d.ts
256
105
  /**
257
106
  * The Standard Schema interface.
258
107
  * @see https://github.com/standard-schema/standard-schema
259
108
  */
260
- interface StandardSchemaV1<Input = unknown, Output = Input> {
261
- /**
262
- * The Standard Schema properties.
263
- */
264
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
109
+ /** The Standard Typed interface. This is a base type extended by other specs. */
110
+ interface StandardTypedV1<Input = unknown, Output = Input> {
111
+ /** The Standard properties. */
112
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
265
113
  }
266
- declare namespace StandardSchemaV1 {
267
- /**
268
- * The Standard Schema properties interface.
269
- */
114
+ declare namespace StandardTypedV1 {
115
+ /** The Standard Typed properties interface. */
270
116
  interface Props<Input = unknown, Output = Input> {
271
- /**
272
- * Inferred types associated with the schema.
273
- */
117
+ /** Inferred types associated with the schema. */
274
118
  readonly types?: Types<Input, Output> | undefined;
275
- /**
276
- * Validates unknown input values.
277
- */
278
- readonly validate: (value: unknown) => Promise<Result<Output>> | Result<Output>;
279
- /**
280
- * The vendor name of the schema library.
281
- */
119
+ /** The vendor name of the schema library. */
282
120
  readonly vendor: string;
283
- /**
284
- * The version number of the standard.
285
- */
121
+ /** The version number of the standard. */
286
122
  readonly version: 1;
287
123
  }
288
- /**
289
- * The result interface of the validate function.
290
- */
124
+ /** The Standard Typed types interface. */
125
+ interface Types<Input = unknown, Output = Input> {
126
+ /** The input type of the schema. */
127
+ readonly input: Input;
128
+ /** The output type of the schema. */
129
+ readonly output: Output;
130
+ }
131
+ /** Infers the input type of a Standard Typed. */
132
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
133
+ /** Infers the output type of a Standard Typed. */
134
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
135
+ }
136
+ /** The Standard Schema interface. */
137
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
138
+ /** The Standard Schema properties. */
139
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
140
+ }
141
+ declare namespace StandardSchemaV1 {
142
+ /** The Standard Schema properties interface. */
143
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
144
+ /** Validates unknown input values. */
145
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options) => Promise<Result<Output>> | Result<Output>;
146
+ }
147
+ /** The result interface of the validate function. */
291
148
  type Result<Output> = FailureResult | SuccessResult<Output>;
292
- /**
293
- * The result interface if validation succeeds.
294
- */
149
+ /** The result interface if validation succeeds. */
295
150
  interface SuccessResult<Output> {
296
- /**
297
- * The non-existent issues.
298
- */
151
+ /** A falsy value for `issues` indicates success. */
299
152
  readonly issues?: undefined;
300
- /**
301
- * The typed output value.
302
- */
153
+ /** The typed output value. */
303
154
  readonly value: Output;
304
155
  }
305
- /**
306
- * The result interface if validation fails.
307
- */
156
+ interface Options {
157
+ /** Explicit support for additional vendor-specific parameters, if needed. */
158
+ readonly libraryOptions?: Record<string, unknown> | undefined;
159
+ }
160
+ /** The result interface if validation fails. */
308
161
  interface FailureResult {
309
- /**
310
- * The issues of failed validation.
311
- */
162
+ /** The issues of failed validation. */
312
163
  readonly issues: readonly Issue[];
313
164
  }
314
- /**
315
- * The issue interface of the failure output.
316
- */
165
+ /** The issue interface of the failure output. */
317
166
  interface Issue {
318
- /**
319
- * The error message of the issue.
320
- */
167
+ /** The error message of the issue. */
321
168
  readonly message: string;
322
- /**
323
- * The path of the issue, if any.
324
- */
169
+ /** The path of the issue, if any. */
325
170
  readonly path?: ReadonlyArray<PathSegment | PropertyKey> | undefined;
326
171
  }
327
- /**
328
- * The path segment interface of the issue.
329
- */
172
+ /** The path segment interface of the issue. */
330
173
  interface PathSegment {
331
- /**
332
- * The key representing a path segment.
333
- */
174
+ /** The key representing a path segment. */
334
175
  readonly key: PropertyKey;
335
176
  }
336
- /**
337
- * The Standard Schema types interface.
338
- */
339
- interface Types<Input = unknown, Output = Input> {
340
- /** The input type of the schema. */
341
- readonly input: Input;
342
- /** The output type of the schema. */
343
- readonly output: Output;
344
- }
345
- /**
346
- * Infers the input type of a Standard Schema.
347
- */
348
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
349
- /**
350
- * Infers the output type of a Standard Schema.
351
- */
352
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
177
+ /** The Standard types interface. */
178
+ type Types<Input = unknown, Output = Input> = StandardTypedV1.Types<Input, Output>;
179
+ /** Infers the input type of a Standard. */
180
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
181
+ /** Infers the output type of a Standard. */
182
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
353
183
  }
354
184
  //#endregion
355
185
  //#region src/validation.d.ts
@@ -394,6 +224,7 @@ interface CallApiSchemaConfig {
394
224
  strict?: boolean;
395
225
  }
396
226
  interface CallApiSchema {
227
+ auth?: StandardSchemaV1<AuthOption | undefined> | ((auth: AuthOption) => Awaitable<AuthOption | undefined>);
397
228
  /**
398
229
  * The schema to use for validating the request body.
399
230
  */
@@ -557,6 +388,183 @@ interface URLOptions {
557
388
  query?: Query;
558
389
  }
559
390
  //#endregion
391
+ //#region src/types/conditional-types.d.ts
392
+ /**
393
+ * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
394
+ */
395
+ type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
396
+ type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
397
+ type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys :
398
+ // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
399
+ TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
400
+ type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
401
+ type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
402
+ type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
403
+ type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
404
+ type JsonPrimitive = boolean | number | string | null | undefined;
405
+ type SerializableObject = Record<PropertyKey, unknown>;
406
+ type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
407
+ type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
408
+ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
409
+ /**
410
+ * Body of the request, can be a object or any other supported body type.
411
+ */
412
+ body?: InferSchemaOutput<TSchema["body"], Body>;
413
+ }>;
414
+ type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
415
+ type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
416
+ type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
417
+ /**
418
+ * HTTP method for the request.
419
+ * @default "GET"
420
+ */
421
+ method?: InferSchemaOutput<TSchema["method"], InferMethodFromURL<TInitURL>>;
422
+ }>;
423
+ type HeadersOption = UnmaskType<Headers | Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
424
+ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
425
+ /**
426
+ * Headers to be used in the request.
427
+ */
428
+ headers?: InferSchemaOutput<TSchema["headers"], HeadersOption> | ((context: {
429
+ baseHeaders: Extract<HeadersOption, Record<string, unknown>>;
430
+ }) => InferSchemaOutput<TSchema["headers"], HeadersOption>);
431
+ }>;
432
+ type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
433
+ type InferMetaOption<TSchema extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
434
+ /**
435
+ * - An optional field you can fill with additional information,
436
+ * to associate with the request, typically used for logging or tracing.
437
+ *
438
+ * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
439
+ *
440
+ * @example
441
+ * ```ts
442
+ * const callMainApi = callApi.create({
443
+ * baseURL: "https://main-api.com",
444
+ * onResponseError: ({ response, options }) => {
445
+ * if (options.meta?.userId) {
446
+ * console.error(`User ${options.meta.userId} made an error`);
447
+ * }
448
+ * },
449
+ * });
450
+ *
451
+ * const response = await callMainApi({
452
+ * url: "https://example.com/api/data",
453
+ * meta: { userId: "123" },
454
+ * });
455
+ * ```
456
+ */
457
+ meta?: InferSchemaOutput<TSchema["meta"], TCallApiContext["Meta"]>;
458
+ }>;
459
+ type InferAuthOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["auth"], {
460
+ /**
461
+ * Automatically add an Authorization header value.
462
+ *
463
+ * Supports multiple authentication patterns:
464
+ * - String: Direct authorization header value
465
+ * - Auth object: Structured authentication configuration
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * const callMainApi = callApi.create({
470
+ * baseURL: "https://main-api.com",
471
+ * onRequest: ({ options }) => {
472
+ * if (options.auth) {
473
+ * options.headers.Authorization = options.auth;
474
+ * }
475
+ * },
476
+ * });
477
+ *
478
+ * const response = await callMainApi({
479
+ * url: "https://example.com/api/data",
480
+ * auth: "Bearer 123456",
481
+ * });
482
+ * ```
483
+ */
484
+ auth?: InferSchemaOutput<TSchema["auth"], AuthOption>;
485
+ }>;
486
+ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
487
+ /**
488
+ * Parameters to be appended to the URL (i.e: /:id)
489
+ */
490
+ query?: InferSchemaOutput<TSchema["query"], Query>;
491
+ }>;
492
+ type EmptyString = "";
493
+ type EmptyTuple = readonly [];
494
+ type StringTuple = readonly string[];
495
+ type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
496
+ type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute extends PossibleParamNamePatterns ? TCurrentRoute extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
497
+ type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
498
+ type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
499
+ type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
500
+ type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
501
+ type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
502
+ /**
503
+ * Parameters to be appended to the URL (i.e: /:id)
504
+ */
505
+ params?: InferSchemaOutput<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
506
+ }>;
507
+ type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferAuthOption<TSchema> & InferMetaOption<TSchema, TCallApiContext> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
508
+ type InferPluginExtraOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
509
+ type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorData extends false ? {
510
+ resultMode: "onlyData";
511
+ } : TErrorData extends false | undefined ? {
512
+ resultMode?: "onlyData";
513
+ } : {
514
+ resultMode?: TResultMode;
515
+ };
516
+ type ThrowOnErrorUnion = boolean;
517
+ type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<{
518
+ ErrorData: TErrorData;
519
+ }>) => TThrowOnError);
520
+ type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
521
+ throwOnError: true;
522
+ } : TErrorData extends false | undefined ? {
523
+ throwOnError?: true;
524
+ } : {
525
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
526
+ };
527
+ //#endregion
528
+ //#region src/middlewares.d.ts
529
+ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
530
+ interface Middlewares<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> {
531
+ /**
532
+ * Wraps the fetch implementation to intercept requests at the network layer.
533
+ *
534
+ * Takes a context object containing the current fetch function and returns a new fetch function.
535
+ * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
536
+ * Multiple middleware compose in order: plugins → base config → per-request.
537
+ *
538
+ * Unlike `customFetchImpl`, middleware can call through to the original fetch.
539
+ *
540
+ * @example
541
+ * ```ts
542
+ * // Cache responses
543
+ * const cache = new Map();
544
+ *
545
+ * fetchMiddleware: (ctx) => async (input, init) => {
546
+ * const key = input.toString();
547
+ * if (cache.has(key)) return cache.get(key).clone();
548
+ *
549
+ * const response = await ctx.fetchImpl(input, init);
550
+ * cache.set(key, response.clone());
551
+ * return response;
552
+ * }
553
+ *
554
+ * // Handle offline
555
+ * fetchMiddleware: (ctx) => async (input, init) => {
556
+ * if (!navigator.onLine) {
557
+ * return new Response('{"error": "offline"}', { status: 503 });
558
+ * }
559
+ * return ctx.fetchImpl(input, init);
560
+ * }
561
+ * ```
562
+ */
563
+ fetchMiddleware?: (context: RequestContext<TCallApiContext> & {
564
+ fetchImpl: FetchImpl;
565
+ }) => FetchImpl;
566
+ }
567
+ //#endregion
560
568
  //#region src/plugins.d.ts
561
569
  type PluginSetupContext<TCallApiContext extends CallApiContext = DefaultCallApiContext> = RequestContext<TCallApiContext> & {
562
570
  initURL: string;
@@ -1204,7 +1212,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1204
1212
  *
1205
1213
  * ```
1206
1214
  */
1207
- auth?: Auth;
1215
+ auth?: AuthOption;
1208
1216
  /**
1209
1217
  * Custom function to serialize request body objects into strings.
1210
1218
  *
@@ -1848,4 +1856,4 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1848
1856
  };
1849
1857
  //#endregion
1850
1858
  export { defaultConsoleObject as n, loggerPlugin as r, LoggerOptions as t };
1851
- //# sourceMappingURL=index-DtZjKewM.d.ts.map
1859
+ //# sourceMappingURL=index-BuFffnAC.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-DtZjKewM.js";
1
+ import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "./index-BuFffnAC.js";
2
2
  export { LoggerOptions, defaultConsoleObject, loggerPlugin };
@@ -1,2 +1,2 @@
1
- import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-DtZjKewM.js";
1
+ import { n as defaultConsoleObject, r as loggerPlugin, t as LoggerOptions } from "../../index-BuFffnAC.js";
2
2
  export { LoggerOptions, defaultConsoleObject, loggerPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/callapi-plugins",
3
3
  "type": "module",
4
- "version": "4.0.31",
4
+ "version": "4.0.33",
5
5
  "description": "A collection of plugins for callapi",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -24,24 +24,24 @@
24
24
  "peerDependencies": {
25
25
  "@zayne-labs/toolkit-type-helpers": ">=0.11.17",
26
26
  "consola": "3.x.x",
27
- "@zayne-labs/callapi": "1.11.31"
27
+ "@zayne-labs/callapi": "1.11.33"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@arethetypeswrong/cli": "0.18.2",
31
31
  "@size-limit/esbuild-why": "12.0.0",
32
32
  "@size-limit/preset-small-lib": "12.0.0",
33
33
  "@total-typescript/ts-reset": "0.6.1",
34
- "@zayne-labs/toolkit-type-helpers": "^0.12.15",
34
+ "@zayne-labs/toolkit-type-helpers": "^0.12.16",
35
35
  "@zayne-labs/tsconfig": "0.11.5",
36
36
  "concurrently": "^9.2.1",
37
37
  "consola": "3.4.2",
38
38
  "cross-env": "^10.1.0",
39
- "publint": "^0.3.15",
39
+ "publint": "^0.3.16",
40
40
  "size-limit": "12.0.0",
41
- "tsdown": "0.17.0-beta.5",
41
+ "tsdown": "0.18.0",
42
42
  "typescript": "5.9.3",
43
43
  "vitest": "^4.0.15",
44
- "@zayne-labs/callapi": "1.11.31"
44
+ "@zayne-labs/callapi": "1.11.33"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",