@igniter-js/caller 0.1.3 → 0.1.5

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.
@@ -0,0 +1,1121 @@
1
+ import { StandardSchemaV1, IgniterError, IgniterLogger } from '@igniter-js/common';
2
+ import { IgniterTelemetryManager } from '@igniter-js/telemetry';
3
+ import { z } from 'zod';
4
+ import { I as IgniterCallerStoreAdapter, a as IgniterCallerStoreOptions } from './store-D2p2dqGN.js';
5
+
6
+ /**
7
+ * Supported HTTP methods for `IgniterCaller` requests.
8
+ *
9
+ * This type is designed to remain stable when extracted to `@igniter-js/caller`.
10
+ */
11
+ type IgniterCallerHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
12
+
13
+ /**
14
+ * Retry configuration for failed requests.
15
+ */
16
+ interface IgniterCallerRetryOptions {
17
+ /** Maximum number of retry attempts. */
18
+ maxAttempts: number;
19
+ /** Backoff strategy between retries. */
20
+ backoff?: 'linear' | 'exponential';
21
+ /** Base delay in milliseconds (default: 1000). */
22
+ baseDelay?: number;
23
+ /** HTTP status codes that should trigger a retry (default: [408, 429, 500, 502, 503, 504]). */
24
+ retryOnStatus?: number[];
25
+ }
26
+
27
+ /**
28
+ * Base configuration options for HTTP requests.
29
+ */
30
+ interface IgniterCallerBaseRequestOptions {
31
+ /** Base URL for all requests (e.g. `https://api.example.com`). */
32
+ baseURL?: string;
33
+ /** Default headers merged into each request. */
34
+ headers?: Record<string, string>;
35
+ /** Request timeout in milliseconds (default: 30000). */
36
+ timeout?: number;
37
+ }
38
+ /**
39
+ * Complete request configuration extending base options.
40
+ */
41
+ interface IgniterCallerRequestOptions<TBody = unknown> extends IgniterCallerBaseRequestOptions {
42
+ method: IgniterCallerHttpMethod;
43
+ /** Endpoint URL path. If absolute, `baseURL` is ignored. */
44
+ url: string;
45
+ body?: TBody;
46
+ params?: Record<string, string | number | boolean>;
47
+ responseSchema?: z.ZodSchema<any> | StandardSchemaV1;
48
+ cache?: RequestCache;
49
+ }
50
+ /**
51
+ * Options for the direct request() method (axios-style).
52
+ * All options in one object, executes immediately.
53
+ */
54
+ interface IgniterCallerDirectRequestOptions<TBody = unknown> extends IgniterCallerBaseRequestOptions {
55
+ /** HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD) */
56
+ method: IgniterCallerHttpMethod;
57
+ /** Endpoint URL path. If absolute, `baseURL` is ignored. */
58
+ url: string;
59
+ /** Request body (for POST, PUT, PATCH) */
60
+ body?: TBody;
61
+ /** URL query parameters */
62
+ params?: Record<string, string | number | boolean>;
63
+ /** Cookies to send with the request */
64
+ cookies?: Record<string, string>;
65
+ /** Response validation schema (Zod or any StandardSchemaV1 implementation) */
66
+ responseSchema?: z.ZodSchema<any> | StandardSchemaV1;
67
+ /** Cache strategy */
68
+ cache?: RequestCache;
69
+ /** Cache key for stale-while-revalidate */
70
+ cacheKey?: string;
71
+ /** Stale time in milliseconds for caching */
72
+ staleTime?: number;
73
+ /** Retry configuration */
74
+ retry?: IgniterCallerRetryOptions;
75
+ /** Fallback value if request fails */
76
+ fallback?: () => any;
77
+ }
78
+
79
+ /**
80
+ * Response object containing either successful data or an error.
81
+ */
82
+ interface IgniterCallerApiResponse<T> {
83
+ /** Parsed response data when the request succeeds. */
84
+ data?: T;
85
+ /** Error instance when the request fails. */
86
+ error?: IgniterError;
87
+ /** HTTP status code from the response */
88
+ status?: number;
89
+ /** Response headers */
90
+ headers?: Headers;
91
+ }
92
+ /**
93
+ * Response object for file downloads.
94
+ * @deprecated Use execute() with responseType<File>() instead
95
+ */
96
+ interface IgniterCallerFileResponse {
97
+ /** File instance when download succeeds. */
98
+ file: File | null;
99
+ /** Error instance when download fails. */
100
+ error: Error | null;
101
+ }
102
+ /**
103
+ * Supported response content types that can be auto-detected.
104
+ */
105
+ type IgniterCallerResponseContentType = 'json' | 'xml' | 'csv' | 'text' | 'html' | 'blob' | 'stream' | 'arraybuffer' | 'formdata';
106
+ /**
107
+ * Content types that support schema validation.
108
+ */
109
+ type IgniterCallerValidatableContentType = 'json' | 'xml' | 'csv';
110
+ /**
111
+ * Marker types for responseType() to indicate expected response format.
112
+ * These are used for typing only and don't affect runtime behavior.
113
+ */
114
+ type IgniterCallerResponseMarker = File | Blob | ReadableStream | ArrayBuffer | FormData;
115
+
116
+ /**
117
+ * Function that can modify request configuration before execution.
118
+ */
119
+ type IgniterCallerRequestInterceptor = (config: IgniterCallerRequestOptions) => Promise<IgniterCallerRequestOptions> | IgniterCallerRequestOptions;
120
+ /**
121
+ * Function that can transform responses after execution.
122
+ */
123
+ type IgniterCallerResponseInterceptor = <T>(response: IgniterCallerApiResponse<T>) => Promise<IgniterCallerApiResponse<T>> | IgniterCallerApiResponse<T>;
124
+
125
+ /**
126
+ * HTTP methods supported for schema mapping.
127
+ */
128
+ type IgniterCallerSchemaMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
129
+ /**
130
+ * Schema definition for a single endpoint.
131
+ *
132
+ * Maps status codes to response schemas with optional request schema.
133
+ */
134
+ type IgniterCallerEndpointSchema<TRequest extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1> = Record<number | string, StandardSchemaV1>> = {
135
+ /** Request body schema (optional) */
136
+ request?: TRequest;
137
+ /** Response schemas by status code */
138
+ responses: TResponses;
139
+ /** Optional summary or description for docs */
140
+ doc?: string;
141
+ /** Optional tags for grouping */
142
+ tags?: string[];
143
+ /** Optional operation identifier */
144
+ operationId?: string;
145
+ };
146
+ /**
147
+ * Schema map for multiple endpoints.
148
+ *
149
+ * Structure: { [path]: { [method]: EndpointSchema } }
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const schemas = {
154
+ * '/users': {
155
+ * GET: {
156
+ * responses: {
157
+ * 200: z.array(UserSchema),
158
+ * 401: z.object({ error: z.string() }),
159
+ * },
160
+ * },
161
+ * POST: {
162
+ * request: CreateUserSchema,
163
+ * responses: {
164
+ * 201: UserSchema,
165
+ * 400: z.object({ errors: z.array(z.string()) }),
166
+ * },
167
+ * },
168
+ * },
169
+ * '/users/:id': {
170
+ * GET: {
171
+ * responses: {
172
+ * 200: UserSchema,
173
+ * 404: z.object({ error: z.string() }),
174
+ * },
175
+ * },
176
+ * },
177
+ * }
178
+ * ```
179
+ */
180
+ type IgniterCallerSchemaMap = Record<string, Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>>>;
181
+ /**
182
+ * Resolves a status key against a response map.
183
+ */
184
+ type ResolveStatusKey<TResponses extends Record<number | string, StandardSchemaV1>, TStatus extends number | string> = Extract<keyof TResponses, TStatus | `${TStatus}`>;
185
+ /**
186
+ * Extract path parameters from a URL pattern.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * type Params = ExtractPathParams<'/users/:id/posts/:postId'>
191
+ * // { id: string; postId: string }
192
+ * ```
193
+ */
194
+ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
195
+ [K in Param | keyof ExtractPathParams<`/${Rest}`>]: string;
196
+ } : T extends `${infer _Start}:${infer Param}` ? {
197
+ [K in Param]: string;
198
+ } : Record<never, never>;
199
+ /**
200
+ * Infer request type from endpoint schema.
201
+ */
202
+ type InferRequestType<T> = T extends IgniterCallerEndpointSchema<infer R, any> ? R extends StandardSchemaV1 ? StandardSchemaV1.InferInput<R> : never : never;
203
+ /**
204
+ * Infer response type by status code from endpoint schema.
205
+ */
206
+ type InferResponseType<T, Status extends number | string> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? ResolveStatusKey<Responses, Status> extends keyof Responses ? Responses[ResolveStatusKey<Responses, Status>] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[ResolveStatusKey<Responses, Status>]> : never : never : never;
207
+ /**
208
+ * Infer the success response type (status 200 or 201) from endpoint schema.
209
+ */
210
+ type InferSuccessResponseType<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? ResolveStatusKey<Responses, 200> extends keyof Responses ? Responses[ResolveStatusKey<Responses, 200>] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[ResolveStatusKey<Responses, 200>]> : never : ResolveStatusKey<Responses, 201> extends keyof Responses ? Responses[ResolveStatusKey<Responses, 201>] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[ResolveStatusKey<Responses, 201>]> : never : never : never;
211
+ /**
212
+ * Infer all possible response types (union) from endpoint schema.
213
+ */
214
+ type InferAllResponseTypes<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? Responses extends Record<number | string, StandardSchemaV1> ? {
215
+ [K in keyof Responses]: Responses[K] extends StandardSchemaV1 ? {
216
+ status: K;
217
+ data: StandardSchemaV1.InferOutput<Responses[K]>;
218
+ } : never;
219
+ }[keyof Responses] : never : never;
220
+ /**
221
+ * Get all available paths from a schema map.
222
+ */
223
+ type SchemaMapPaths<TSchemas extends IgniterCallerSchemaMap> = keyof TSchemas & string;
224
+ /**
225
+ * Get available methods for a specific path.
226
+ */
227
+ type SchemaMapMethods<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas> = keyof TSchemas[TPath] & IgniterCallerSchemaMethod;
228
+ /**
229
+ * Get all paths that have a specific method defined.
230
+ */
231
+ type PathsForMethod<TSchemas extends IgniterCallerSchemaMap, TMethod extends IgniterCallerSchemaMethod> = {
232
+ [K in keyof TSchemas]: TMethod extends keyof TSchemas[K] ? K : never;
233
+ }[keyof TSchemas] & string;
234
+ /**
235
+ * Get paths available for GET method.
236
+ */
237
+ type GetPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'GET'>;
238
+ /**
239
+ * Get paths available for POST method.
240
+ */
241
+ type PostPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'POST'>;
242
+ /**
243
+ * Get paths available for PUT method.
244
+ */
245
+ type PutPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PUT'>;
246
+ /**
247
+ * Get paths available for PATCH method.
248
+ */
249
+ type PatchPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PATCH'>;
250
+ /**
251
+ * Get paths available for DELETE method.
252
+ */
253
+ type DeletePaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'DELETE'>;
254
+ /**
255
+ * Get paths available for HEAD method.
256
+ */
257
+ type HeadPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'HEAD'>;
258
+ /**
259
+ * Get endpoint schema for a specific path and method.
260
+ */
261
+ type SchemaMapEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod];
262
+ /**
263
+ * Infer response type from schema map for a specific path, method, and status.
264
+ */
265
+ type SchemaMapResponseType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath], TStatus extends number | string = 200> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<any, infer Responses> ? ResolveStatusKey<Responses, TStatus> extends keyof Responses ? Responses[ResolveStatusKey<Responses, TStatus>] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[ResolveStatusKey<Responses, TStatus>]> : never : never : never;
266
+ /**
267
+ * Infer request type from schema map for a specific path and method.
268
+ */
269
+ type SchemaMapRequestType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Request, any> ? Request extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Request> : never : never;
270
+ /**
271
+ * Infer endpoint info for a specific path and method.
272
+ * Returns an object with response, request, and params types.
273
+ */
274
+ type EndpointInfo<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? {
275
+ response: TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<any, infer R> ? 200 extends keyof R ? R[200] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[200]> : unknown : 201 extends keyof R ? R[201] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[201]> : unknown : unknown : unknown;
276
+ request: TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Req, any> ? Req extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Req> : never : never;
277
+ params: ExtractPathParams<TPath & string>;
278
+ } : {
279
+ response: unknown;
280
+ request: never;
281
+ params: Record<never, never>;
282
+ } : {
283
+ response: unknown;
284
+ request: never;
285
+ params: Record<never, never>;
286
+ };
287
+ /**
288
+ * Options for schema validation behavior.
289
+ */
290
+ interface IgniterCallerSchemaValidationOptions {
291
+ /**
292
+ * Validation mode:
293
+ * - 'strict': Throw error on validation failure (default)
294
+ * - 'soft': Log error but return raw data
295
+ * - 'off': Skip validation entirely
296
+ */
297
+ mode?: 'strict' | 'soft' | 'off';
298
+ /**
299
+ * Custom error handler for validation failures.
300
+ */
301
+ onValidationError?: (error: any, context: {
302
+ url: string;
303
+ method: string;
304
+ statusCode: number;
305
+ }) => void;
306
+ }
307
+
308
+ /**
309
+ * @fileoverview Schema builder helper types for @igniter-js/caller.
310
+ * @module @igniter-js/caller/types/schema-builder
311
+ */
312
+
313
+ /**
314
+ * Registry of reusable schemas keyed by name.
315
+ */
316
+ type IgniterCallerSchemaRegistry = Record<string, StandardSchemaV1>;
317
+ /**
318
+ * Configuration payload for a single endpoint method in the schema builder.
319
+ */
320
+ type IgniterCallerSchemaEndpointConfig<TRequest extends StandardSchemaV1 | undefined = undefined, TResponses extends Record<number | string, StandardSchemaV1> = Record<number | string, StandardSchemaV1>> = {
321
+ request?: TRequest;
322
+ responses: TResponses;
323
+ doc?: string;
324
+ tags?: string[];
325
+ operationId?: string;
326
+ };
327
+ /**
328
+ * Helper type for array wrappers on StandardSchemaV1.
329
+ */
330
+ type SchemaArray<TSchema extends StandardSchemaV1> = StandardSchemaV1<Array<StandardSchemaV1.InferInput<TSchema>>, Array<StandardSchemaV1.InferOutput<TSchema>>>;
331
+ /**
332
+ * Helper type for nullable wrappers on StandardSchemaV1.
333
+ */
334
+ type SchemaNullable<TSchema extends StandardSchemaV1> = StandardSchemaV1<StandardSchemaV1.InferInput<TSchema> | null, StandardSchemaV1.InferOutput<TSchema> | null>;
335
+ /**
336
+ * Helper type for optional wrappers on StandardSchemaV1.
337
+ */
338
+ type SchemaOptional<TSchema extends StandardSchemaV1> = StandardSchemaV1<StandardSchemaV1.InferInput<TSchema> | undefined, StandardSchemaV1.InferOutput<TSchema> | undefined>;
339
+ /**
340
+ * Helper type for record wrappers on StandardSchemaV1.
341
+ */
342
+ type SchemaRecord<TSchema extends StandardSchemaV1> = StandardSchemaV1<Record<string, StandardSchemaV1.InferInput<TSchema>>, Record<string, StandardSchemaV1.InferOutput<TSchema>>>;
343
+ /**
344
+ * Extracts the raw responses map (schemas) from a schema map.
345
+ */
346
+ type SchemaMapResponses<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<any, infer Responses> ? Responses : never;
347
+ /**
348
+ * Infers the response output types for every status in a responses map.
349
+ */
350
+ type SchemaMapResponsesType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = SchemaMapResponses<TSchemas, TPath, TMethod> extends Record<number | string, StandardSchemaV1> ? {
351
+ [K in keyof SchemaMapResponses<TSchemas, TPath, TMethod>]: SchemaMapResponses<TSchemas, TPath, TMethod>[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<SchemaMapResponses<TSchemas, TPath, TMethod>[K]> : never;
352
+ } : never;
353
+ /**
354
+ * Extracts the request schema for a path + method.
355
+ */
356
+ type SchemaMapRequestSchema<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Request, any> ? Request : never;
357
+ /**
358
+ * Extracts the response schema for a path + method + status code.
359
+ */
360
+ type SchemaMapResponseSchema<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath], TStatus extends number | string> = SchemaMapResponses<TSchemas, TPath, TMethod> extends Record<number | string, StandardSchemaV1> ? ResolveStatusKey<SchemaMapResponses<TSchemas, TPath, TMethod>, TStatus> extends keyof SchemaMapResponses<TSchemas, TPath, TMethod> ? SchemaMapResponses<TSchemas, TPath, TMethod>[ResolveStatusKey<SchemaMapResponses<TSchemas, TPath, TMethod>, TStatus>] : never : never;
361
+ /**
362
+ * Type-level helpers attached to schema build outputs.
363
+ */
364
+ type IgniterCallerSchemaInfer<TSchemas extends IgniterCallerSchemaMap, TRegistry extends IgniterCallerSchemaRegistry> = {
365
+ Path: SchemaMapPaths<TSchemas>;
366
+ Endpoint: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>>() => EndpointInfo<TSchemas, TPath, TMethod>;
367
+ Request: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>>() => SchemaMapRequestType<TSchemas, TPath, TMethod>;
368
+ Response: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>, TStatus extends number | string>() => SchemaMapResponseType<TSchemas, TPath, TMethod, TStatus>;
369
+ Responses: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>>() => SchemaMapResponsesType<TSchemas, TPath, TMethod>;
370
+ Schema: <TKey extends keyof TRegistry>() => StandardSchemaV1.InferOutput<TRegistry[TKey]>;
371
+ };
372
+ /**
373
+ * Runtime helpers attached to schema build outputs.
374
+ */
375
+ type IgniterCallerSchemaGetters<TSchemas extends IgniterCallerSchemaMap, TRegistry extends IgniterCallerSchemaRegistry> = {
376
+ path: <TPath extends SchemaMapPaths<TSchemas>>(path: TPath) => TSchemas[TPath];
377
+ endpoint: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>>(path: TPath, method: TMethod) => SchemaMapEndpoint<TSchemas, TPath, TMethod>;
378
+ request: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>>(path: TPath, method: TMethod) => SchemaMapRequestSchema<TSchemas, TPath, TMethod>;
379
+ response: <TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>, TStatus extends number | string>(path: TPath, method: TMethod, status: TStatus) => SchemaMapResponseSchema<TSchemas, TPath, TMethod, TStatus>;
380
+ schema: <TKey extends keyof TRegistry>(key: TKey) => TRegistry[TKey];
381
+ };
382
+ /**
383
+ * Output type for IgniterCallerSchema.build().
384
+ */
385
+ type IgniterCallerSchemaBuildResult<TSchemas extends IgniterCallerSchemaMap, TRegistry extends IgniterCallerSchemaRegistry> = TSchemas & {
386
+ $Infer: IgniterCallerSchemaInfer<TSchemas, TRegistry>;
387
+ get: IgniterCallerSchemaGetters<TSchemas, TRegistry>;
388
+ };
389
+ /**
390
+ * Accepted input types for `withSchemas`.
391
+ */
392
+ type IgniterCallerSchemaInput<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap, TRegistry extends IgniterCallerSchemaRegistry = IgniterCallerSchemaRegistry> = TSchemas | IgniterCallerSchemaBuildResult<TSchemas, TRegistry>;
393
+ /**
394
+ * Extracts the schema map from a build result or raw map.
395
+ */
396
+ type IgniterCallerSchemaMapFrom<T> = T extends IgniterCallerSchemaBuildResult<infer TMap, any> ? TMap : T extends IgniterCallerSchemaMap ? T : never;
397
+
398
+ /**
399
+ * @fileoverview Mock types for @igniter-js/caller.
400
+ * @module @igniter-js/caller/types/mock
401
+ */
402
+
403
+ /**
404
+ * Resolves valid status codes for a mocked path+method based on the schema map.
405
+ */
406
+ type IgniterCallerMockStatus<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = keyof SchemaMapResponses<TSchemas, TPath, TMethod> & (number | string);
407
+ /**
408
+ * Picks the default success status for a mocked path+method.
409
+ * Prefers 200, then 201, then the first available status.
410
+ */
411
+ type IgniterCallerMockDefaultStatus<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = 200 extends IgniterCallerMockStatus<TSchemas, TPath, TMethod> ? 200 : 201 extends IgniterCallerMockStatus<TSchemas, TPath, TMethod> ? 201 : IgniterCallerMockStatus<TSchemas, TPath, TMethod>;
412
+ /**
413
+ * Full request context passed to mock handlers.
414
+ */
415
+ interface IgniterCallerMockRequest<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> {
416
+ method: TMethod;
417
+ path: TPath;
418
+ url: string;
419
+ safeUrl: string;
420
+ baseURL?: string;
421
+ headers: Record<string, string>;
422
+ query: Record<string, string | number | boolean>;
423
+ params: EndpointInfo<TSchemas, TPath, TMethod>['params'];
424
+ body?: SchemaMapRequestType<TSchemas, TPath, TMethod>;
425
+ timeoutMs?: number;
426
+ cache?: RequestCache;
427
+ cacheKey?: string;
428
+ staleTime?: number;
429
+ responseTypeSchema?: StandardSchemaV1 | z.ZodSchema<any>;
430
+ }
431
+ /**
432
+ * Resolved mock handler for a given request path+method.
433
+ */
434
+ interface IgniterCallerMockResolvedHandler<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas> = SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath> = SchemaMapMethods<TSchemas, TPath>> {
435
+ handler: IgniterCallerMockHandlerDefinition<TSchemas, TPath, TMethod>;
436
+ params: Record<string, string>;
437
+ path: TPath;
438
+ method: TMethod;
439
+ }
440
+ /**
441
+ * Contract for the mock manager used by the request builder.
442
+ */
443
+ interface IIgniterCallerMockManager<TSchemas extends IgniterCallerSchemaMap> {
444
+ resolve(path: string, method: IgniterCallerSchemaMethod): IgniterCallerMockResolvedHandler<TSchemas> | null;
445
+ }
446
+ /**
447
+ * Mock response payload for a specific status code.
448
+ */
449
+ type IgniterCallerMockResponseForStatus<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>, TStatus extends IgniterCallerMockStatus<TSchemas, TPath, TMethod>> = {
450
+ status: TStatus;
451
+ response: SchemaMapResponseType<TSchemas, TPath, TMethod, TStatus>;
452
+ headers?: Record<string, string>;
453
+ delayMs?: number;
454
+ errorMessage?: string;
455
+ };
456
+ /**
457
+ * Mock response payload when status is omitted (uses default success status).
458
+ */
459
+ type IgniterCallerMockResponseDefault<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = {
460
+ response: SchemaMapResponseType<TSchemas, TPath, TMethod, IgniterCallerMockDefaultStatus<TSchemas, TPath, TMethod>>;
461
+ status?: undefined;
462
+ headers?: Record<string, string>;
463
+ delayMs?: number;
464
+ errorMessage?: string;
465
+ };
466
+ /**
467
+ * Union of all supported mock response payloads for a path+method.
468
+ */
469
+ type IgniterCallerMockResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = IgniterCallerMockResponseDefault<TSchemas, TPath, TMethod> | {
470
+ [TStatus in IgniterCallerMockStatus<TSchemas, TPath, TMethod>]: IgniterCallerMockResponseForStatus<TSchemas, TPath, TMethod, TStatus>;
471
+ }[IgniterCallerMockStatus<TSchemas, TPath, TMethod>];
472
+ /**
473
+ * Mock handler signature (receives full request context).
474
+ */
475
+ type IgniterCallerMockHandler<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = (request: IgniterCallerMockRequest<TSchemas, TPath, TMethod>) => IgniterCallerMockResponse<TSchemas, TPath, TMethod> | Promise<IgniterCallerMockResponse<TSchemas, TPath, TMethod>>;
476
+ /**
477
+ * Either a static mock response or a handler callback.
478
+ */
479
+ type IgniterCallerMockHandlerDefinition<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>, TMethod extends SchemaMapMethods<TSchemas, TPath>> = IgniterCallerMockResponse<TSchemas, TPath, TMethod> | IgniterCallerMockHandler<TSchemas, TPath, TMethod>;
480
+ /**
481
+ * Mock definitions for a single path (method -> handler/response).
482
+ */
483
+ type IgniterCallerMockPathDefinition<TSchemas extends IgniterCallerSchemaMap, TPath extends SchemaMapPaths<TSchemas>> = Partial<{
484
+ [TMethod in SchemaMapMethods<TSchemas, TPath>]: IgniterCallerMockHandlerDefinition<TSchemas, TPath, TMethod>;
485
+ }>;
486
+ /**
487
+ * Registry of mocked paths for a schema map.
488
+ */
489
+ type IgniterCallerMockRegistry<TSchemas extends IgniterCallerSchemaMap> = Partial<{
490
+ [TPath in SchemaMapPaths<TSchemas>]: IgniterCallerMockPathDefinition<TSchemas, TPath>;
491
+ }>;
492
+ /**
493
+ * Mock configuration passed to the caller builder.
494
+ */
495
+ interface IgniterCallerMockConfig<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
496
+ enabled: boolean;
497
+ mock: IIgniterCallerMockManager<TSchemas>;
498
+ }
499
+
500
+ /**
501
+ * Fluent request builder for `IgniterCaller`.
502
+ *
503
+ * When created via specific HTTP methods (get, post, put, patch, delete),
504
+ * the method is already set and cannot be changed.
505
+ */
506
+ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
507
+ private options;
508
+ private logger?;
509
+ private telemetry?;
510
+ private retryOptions?;
511
+ private fallbackFn?;
512
+ private cacheKey?;
513
+ private staleTime?;
514
+ private requestInterceptors?;
515
+ private responseInterceptors?;
516
+ private eventEmitter?;
517
+ private schemas?;
518
+ private schemaValidation?;
519
+ private responseTypeSchema?;
520
+ private mock?;
521
+ /**
522
+ * Creates a new request builder instance.
523
+ *
524
+ * @param params - Builder configuration from the manager.
525
+ */
526
+ constructor(params: IgniterCallerRequestBuilderParams);
527
+ /**
528
+ * Sets the HTTP method for this request.
529
+ * @internal Used by IgniterCaller.request() for generic requests.
530
+ *
531
+ * @param method - HTTP method for the request.
532
+ */
533
+ _setMethod(method: IgniterCallerHttpMethod): this;
534
+ /**
535
+ * Sets the URL for this request.
536
+ * @internal Used when URL is passed to HTTP method directly.
537
+ *
538
+ * @param url - Request URL or path.
539
+ */
540
+ _setUrl(url: string): this;
541
+ /**
542
+ * Overrides the logger for this request chain.
543
+ *
544
+ * @param logger - Logger implementation from `@igniter-js/common`.
545
+ */
546
+ withLogger(logger: IgniterLogger): this;
547
+ /**
548
+ * Sets the request URL.
549
+ *
550
+ * @param url - Request URL or path.
551
+ */
552
+ url(url: string): this;
553
+ /**
554
+ * Sets the request body.
555
+ * For GET/HEAD requests, body will be automatically converted to query params.
556
+ *
557
+ * @param body - Body payload for the request.
558
+ */
559
+ body<TBody>(body: TBody): this;
560
+ /**
561
+ * Sets URL query parameters.
562
+ *
563
+ * @param params - Query string parameters.
564
+ */
565
+ params(params: Record<string, string | number | boolean>): this;
566
+ /**
567
+ * Merges additional headers into the request.
568
+ *
569
+ * @param headers - Header map merged into existing headers.
570
+ */
571
+ headers(headers: Record<string, string>): this;
572
+ /**
573
+ * Sets request timeout in milliseconds.
574
+ *
575
+ * @param timeout - Timeout in milliseconds.
576
+ */
577
+ timeout(timeout: number): this;
578
+ /**
579
+ * Sets cache strategy and optional cache key.
580
+ *
581
+ * @param cache - Cache strategy for the request.
582
+ * @param key - Optional cache key override.
583
+ */
584
+ cache(cache: RequestCache, key?: string): this;
585
+ /**
586
+ * Configures retry behavior for failed requests.
587
+ *
588
+ * @param maxAttempts - Maximum number of attempts.
589
+ * @param options - Retry options excluding `maxAttempts`.
590
+ */
591
+ retry(maxAttempts: number, options?: Omit<IgniterCallerRetryOptions, 'maxAttempts'>): this;
592
+ /**
593
+ * Provides a fallback value if the request fails.
594
+ *
595
+ * @param fn - Fallback factory called when the request fails.
596
+ */
597
+ fallback<T>(fn: () => T): this;
598
+ /**
599
+ * Sets cache stale time in milliseconds.
600
+ *
601
+ * @param milliseconds - Stale time in milliseconds.
602
+ */
603
+ stale(milliseconds: number): this;
604
+ /**
605
+ * Sets the expected response type for TypeScript inference.
606
+ *
607
+ * - If a Zod/StandardSchema is passed, it will validate the response (only for JSON/XML/CSV)
608
+ * - If a type parameter is passed (e.g., `responseType<File>()`), it's for typing only
609
+ *
610
+ * The actual parsing is based on Content-Type headers, not this setting.
611
+ *
612
+ * @param schema - Zod/StandardSchema instance for validation (optional).
613
+ *
614
+ * @example
615
+ * ```ts
616
+ * // With Zod schema (validates JSON response)
617
+ * const result = await api.get('/users').responseType(UserSchema).execute()
618
+ *
619
+ * // With type marker (typing only, no validation)
620
+ * const result = await api.get('/file').responseType<Blob>().execute()
621
+ * ```
622
+ */
623
+ responseType<T>(schema?: z.ZodSchema<T> | StandardSchemaV1): IgniterCallerRequestBuilder<T>;
624
+ /**
625
+ * Downloads a file via GET request.
626
+ * @deprecated Use `.responseType<File>().execute()` instead. The response type is auto-detected.
627
+ *
628
+ * @param url - URL or path to download.
629
+ */
630
+ getFile(url: string): {
631
+ execute: () => Promise<IgniterCallerFileResponse>;
632
+ };
633
+ /**
634
+ * Executes the HTTP request.
635
+ *
636
+ * Response parsing is automatic based on Content-Type headers:
637
+ * - `application/json` → parsed as JSON
638
+ * - `text/xml`, `application/xml` → returned as text (parse with your XML library)
639
+ * - `text/csv` → returned as text
640
+ * - `text/html`, `text/plain` → returned as text
641
+ * - `image/*`, `audio/*`, `video/*`, `application/pdf`, etc. → returned as Blob
642
+ * - `application/octet-stream` → returned as Blob
643
+ *
644
+ * Schema validation (if configured) only runs for validatable content types (JSON, XML, CSV).
645
+ *
646
+ * @returns Response envelope with data or error.
647
+ */
648
+ execute(): Promise<IgniterCallerApiResponse<TResponse>>;
649
+ private executeWithRetry;
650
+ private executeSingleRequest;
651
+ private resolveUrl;
652
+ private buildRequest;
653
+ /**
654
+ * Normalizes a URL into a path for mock matching.
655
+ */
656
+ private normalizeMockPath;
657
+ /**
658
+ * Resolves the final query object (merges GET/HEAD body into params).
659
+ */
660
+ private getFinalQuery;
661
+ /**
662
+ * Executes a mock handler when enabled and matched.
663
+ */
664
+ private executeMockRequest;
665
+ /**
666
+ * Normalizes a mock handler result into a response payload with status.
667
+ */
668
+ private resolveMockResponse;
669
+ /**
670
+ * Emits event for this response using injected emitter.
671
+ */
672
+ private emitEvent;
673
+ }
674
+
675
+ /**
676
+ * @fileoverview Builder and request builder types for @igniter-js/caller.
677
+ * @module @igniter-js/caller/types/builder
678
+ */
679
+
680
+ /**
681
+ * Builder state for {@link IgniterCallerBuilder}.
682
+ */
683
+ type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = {
684
+ /** Base URL prefix for outgoing requests. */
685
+ baseURL?: string;
686
+ /** Default headers merged into each request. */
687
+ headers?: Record<string, string>;
688
+ /** Default cookies (sent as the Cookie header). */
689
+ cookies?: Record<string, string>;
690
+ /** Logger instance for request lifecycle logs. */
691
+ logger?: IgniterLogger;
692
+ /** Telemetry manager for emitting events. */
693
+ telemetry?: IgniterTelemetryManager<any>;
694
+ /** Request interceptors executed before the request. */
695
+ requestInterceptors?: IgniterCallerRequestInterceptor[];
696
+ /** Response interceptors executed after the request. */
697
+ responseInterceptors?: IgniterCallerResponseInterceptor[];
698
+ /** Store adapter for persistent cache. */
699
+ store?: IgniterCallerStoreAdapter;
700
+ /** Store adapter options (ttl, keyPrefix, fallback). */
701
+ storeOptions?: IgniterCallerStoreOptions;
702
+ /** Schema map for request/response inference. */
703
+ schemas?: TSchemas;
704
+ /** Validation options for schema enforcement. */
705
+ schemaValidation?: IgniterCallerSchemaValidationOptions;
706
+ /** Optional mock configuration (routes requests to mock handlers). */
707
+ mock?: IgniterCallerMockConfig<TSchemas>;
708
+ };
709
+ /**
710
+ * Constructor params for the request builder.
711
+ */
712
+ interface IgniterCallerRequestBuilderParams {
713
+ /** Base URL prefix for outgoing requests. */
714
+ baseURL?: string;
715
+ /** Default headers merged into each request. */
716
+ defaultHeaders?: Record<string, string>;
717
+ /** Default cookies (sent as the Cookie header). */
718
+ defaultCookies?: Record<string, string>;
719
+ /** Logger instance for request lifecycle logs. */
720
+ logger?: IgniterLogger;
721
+ /** Telemetry manager for emitting events. */
722
+ telemetry?: IgniterTelemetryManager<any>;
723
+ /** Request interceptors executed before the request. */
724
+ requestInterceptors?: IgniterCallerRequestInterceptor[];
725
+ /** Response interceptors executed after the request. */
726
+ responseInterceptors?: IgniterCallerResponseInterceptor[];
727
+ /** Callback invoked after request completion. */
728
+ eventEmitter?: (url: string, method: string, result: IgniterCallerApiResponse<unknown>) => Promise<void>;
729
+ /** Schema map for request/response inference. */
730
+ schemas?: IgniterCallerSchemaMap;
731
+ /** Validation options for schema enforcement. */
732
+ schemaValidation?: IgniterCallerSchemaValidationOptions;
733
+ /** Optional mock configuration. */
734
+ mock?: IgniterCallerMockConfig<any>;
735
+ }
736
+ /**
737
+ * Request builder type without internal methods.
738
+ * Used when creating requests via specific HTTP methods (get, post, etc.).
739
+ */
740
+ type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, "_setMethod" | "_setUrl">;
741
+ /**
742
+ * Request builder with typed response based on schema inference.
743
+ */
744
+ type IgniterCallerTypedRequestBuilder<TResponse = unknown> = IgniterCallerMethodRequestBuilder<TResponse>;
745
+
746
+ /**
747
+ * Callback function for event listeners.
748
+ */
749
+ type IgniterCallerEventCallback<T = any> = (result: IgniterCallerApiResponse<T>, context: {
750
+ url: string;
751
+ method: string;
752
+ timestamp: number;
753
+ }) => void | Promise<void>;
754
+ /**
755
+ * Pattern for matching URLs (string or RegExp).
756
+ */
757
+ type IgniterCallerUrlPattern = string | RegExp;
758
+
759
+ /**
760
+ * @fileoverview Type inference helpers for @igniter-js/caller.
761
+ * @module @igniter-js/caller/types/infer
762
+ */
763
+
764
+ /**
765
+ * Infer success response type from endpoint schema (200 or 201).
766
+ */
767
+ type InferSuccessResponse<T> = T extends IgniterCallerEndpointSchema<any, infer R> ? 200 extends keyof R ? R[200] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[200]> : unknown : 201 extends keyof R ? R[201] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[201]> : unknown : unknown : unknown;
768
+ /**
769
+ * Get the endpoint schema for a path and method from a schema map.
770
+ */
771
+ type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? TSchemas[TPath][TMethod] : undefined : undefined;
772
+ /**
773
+ * Infer the response type for a given path and method.
774
+ * Returns `unknown` if the path/method is not in the schema.
775
+ */
776
+ type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = InferSuccessResponse<GetEndpoint<TSchemas, TPath, TMethod>>;
777
+ /**
778
+ * Typed request builder with inferred body and params types.
779
+ */
780
+ type TypedRequestBuilder<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = Omit<IgniterCallerMethodRequestBuilder<EndpointInfo<TSchemas, TPath, TMethod>["response"]>, "body" | "params"> & {
781
+ /**
782
+ * Sets the request body with type inference from schema.
783
+ */
784
+ body: EndpointInfo<TSchemas, TPath, TMethod>["request"] extends never ? <TBody>(body: TBody) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (body: EndpointInfo<TSchemas, TPath, TMethod>["request"]) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
785
+ /**
786
+ * Sets URL path parameters with type inference from URL pattern.
787
+ */
788
+ params: keyof EndpointInfo<TSchemas, TPath, TMethod>["params"] extends never ? (params: Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (params: EndpointInfo<TSchemas, TPath, TMethod>["params"] & Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
789
+ };
790
+
791
+ /**
792
+ * @fileoverview Manager contracts for @igniter-js/caller.
793
+ * @module @igniter-js/caller/types/manager
794
+ */
795
+
796
+ /**
797
+ * Public contract for the IgniterCaller manager runtime.
798
+ */
799
+ interface IIgniterCallerManager<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
800
+ /**
801
+ * Creates a GET request.
802
+ *
803
+ * @param url - Optional URL for the request.
804
+ * @returns Typed request builder.
805
+ */
806
+ get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "GET">;
807
+ get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "GET">>;
808
+ /**
809
+ * Creates a POST request.
810
+ *
811
+ * @param url - Optional URL for the request.
812
+ * @returns Typed request builder.
813
+ */
814
+ post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "POST">;
815
+ post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "POST">>;
816
+ /**
817
+ * Creates a PUT request.
818
+ *
819
+ * @param url - Optional URL for the request.
820
+ * @returns Typed request builder.
821
+ */
822
+ put<TPath extends PutPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "PUT">;
823
+ put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "PUT">>;
824
+ /**
825
+ * Creates a PATCH request.
826
+ *
827
+ * @param url - Optional URL for the request.
828
+ * @returns Typed request builder.
829
+ */
830
+ patch<TPath extends PatchPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "PATCH">;
831
+ patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "PATCH">>;
832
+ /**
833
+ * Creates a DELETE request.
834
+ *
835
+ * @param url - Optional URL for the request.
836
+ * @returns Typed request builder.
837
+ */
838
+ delete<TPath extends DeletePaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "DELETE">;
839
+ delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "DELETE">>;
840
+ /**
841
+ * Creates a HEAD request.
842
+ *
843
+ * @param url - Optional URL for the request.
844
+ * @returns Typed request builder.
845
+ */
846
+ head<TPath extends HeadPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, "HEAD">;
847
+ head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, "HEAD">>;
848
+ /**
849
+ * Executes a request directly with all options in one object.
850
+ *
851
+ * @param options - Request configuration.
852
+ * @returns Response envelope with data or error.
853
+ */
854
+ request<T = unknown>(options: IgniterCallerDirectRequestOptions): Promise<IgniterCallerApiResponse<T>>;
855
+ }
856
+
857
+ /**
858
+ * HTTP client runtime for Igniter.js.
859
+ *
860
+ * This module is intentionally structured to be extracted into a standalone package
861
+ * in the Igniter.js ecosystem as `@igniter-js/caller`.
862
+ *
863
+ * @template TSchemas - The schema map type for type-safe requests/responses.
864
+ */
865
+ declare class IgniterCallerManager<TSchemas extends IgniterCallerSchemaMap> implements IIgniterCallerManager<TSchemas> {
866
+ /** Global event emitter for observing HTTP responses */
867
+ private static readonly events;
868
+ private baseURL?;
869
+ private headers?;
870
+ private cookies?;
871
+ private logger?;
872
+ private telemetry?;
873
+ private requestInterceptors?;
874
+ private responseInterceptors?;
875
+ private schemas?;
876
+ private schemaValidation?;
877
+ private mock?;
878
+ /**
879
+ * Creates a new manager instance.
880
+ *
881
+ * @param baseURL - Base URL prefix for requests.
882
+ * @param opts - Optional configuration (headers, cookies, telemetry, schemas).
883
+ */
884
+ constructor(baseURL?: string, opts?: {
885
+ headers?: Record<string, string>;
886
+ cookies?: Record<string, string>;
887
+ logger?: IgniterLogger;
888
+ telemetry?: IgniterTelemetryManager<any>;
889
+ requestInterceptors?: IgniterCallerRequestInterceptor[];
890
+ responseInterceptors?: IgniterCallerResponseInterceptor[];
891
+ schemas?: TSchemas;
892
+ schemaValidation?: IgniterCallerSchemaValidationOptions;
893
+ mock?: IgniterCallerMockConfig<TSchemas>;
894
+ });
895
+ /**
896
+ * Creates common request builder params.
897
+ */
898
+ private createBuilderParams;
899
+ /**
900
+ * Creates a GET request.
901
+ *
902
+ * When a URL is provided and matches a schema, the response, body, and params types
903
+ * are automatically inferred from the schema definition.
904
+ *
905
+ * @param url Optional URL for the request. When provided and matching a schema path,
906
+ * enables full type inference for response, body, and path params.
907
+ *
908
+ * @example
909
+ * ```ts
910
+ * // With typed schema - full type inference
911
+ * const result = await api.get('/users/:id')
912
+ * .params({ id: '123' }) // params are typed based on URL pattern
913
+ * .execute()
914
+ * // result.data is typed based on schema
915
+ *
916
+ * // Without URL (set later with .url())
917
+ * const result = await api.get().url('/users').execute()
918
+ * ```
919
+ */
920
+ get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'GET'>;
921
+ get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
922
+ /**
923
+ * Creates a POST request.
924
+ *
925
+ * When a URL is provided and matches a schema, the response, body, and params types
926
+ * are automatically inferred from the schema definition.
927
+ *
928
+ * @param url Optional URL for the request.
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * // With typed schema - body type is inferred from schema
933
+ * const result = await api.post('/users')
934
+ * .body({ name: 'John', email: 'john@example.com' }) // body is typed
935
+ * .execute()
936
+ * ```
937
+ */
938
+ post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'POST'>;
939
+ post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
940
+ /**
941
+ * Creates a PUT request.
942
+ *
943
+ * When a URL is provided and matches a schema, the response, body, and params types
944
+ * are automatically inferred from the schema definition.
945
+ *
946
+ * @param url Optional URL for the request.
947
+ *
948
+ * @example
949
+ * ```ts
950
+ * const result = await api.put('/users/:id')
951
+ * .params({ id: '1' })
952
+ * .body({ name: 'Jane' })
953
+ * .execute()
954
+ * ```
955
+ */
956
+ put<TPath extends PutPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PUT'>;
957
+ put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
958
+ /**
959
+ * Creates a PATCH request.
960
+ *
961
+ * When a URL is provided and matches a schema, the response, body, and params types
962
+ * are automatically inferred from the schema definition.
963
+ *
964
+ * @param url Optional URL for the request.
965
+ *
966
+ * @example
967
+ * ```ts
968
+ * const result = await api.patch('/users/:id')
969
+ * .params({ id: '1' })
970
+ * .body({ name: 'Jane' })
971
+ * .execute()
972
+ * ```
973
+ */
974
+ patch<TPath extends PatchPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PATCH'>;
975
+ patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
976
+ /**
977
+ * Creates a DELETE request.
978
+ *
979
+ * When a URL is provided and matches a schema, the response, body, and params types
980
+ * are automatically inferred from the schema definition.
981
+ *
982
+ * @param url Optional URL for the request.
983
+ *
984
+ * @example
985
+ * ```ts
986
+ * const result = await api.delete('/users/:id')
987
+ * .params({ id: '1' })
988
+ * .execute()
989
+ * ```
990
+ */
991
+ delete<TPath extends DeletePaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'DELETE'>;
992
+ delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
993
+ /**
994
+ * Creates a HEAD request.
995
+ *
996
+ * When a URL is provided and matches a schema, the response, body, and params types
997
+ * are automatically inferred from the schema definition.
998
+ *
999
+ * @param url Optional URL for the request.
1000
+ */
1001
+ head<TPath extends HeadPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'HEAD'>;
1002
+ head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
1003
+ /**
1004
+ * Executes a request directly with all options in one object (axios-style).
1005
+ *
1006
+ * This is a convenience method for making requests without using the builder pattern.
1007
+ * Useful for dynamic requests where options are constructed programmatically.
1008
+ *
1009
+ * @param options - Request configuration for method, url, and behavior.
1010
+ * @returns Response envelope with data or error.
1011
+ *
1012
+ * @example
1013
+ * ```ts
1014
+ * const result = await api.request({
1015
+ * method: 'POST',
1016
+ * url: '/users',
1017
+ * body: { name: 'John' },
1018
+ * headers: { 'X-Custom': 'value' },
1019
+ * timeout: 5000,
1020
+ * })
1021
+ *
1022
+ * // With caching
1023
+ * const result = await api.request({
1024
+ * method: 'GET',
1025
+ * url: '/users',
1026
+ * staleTime: 30000,
1027
+ * })
1028
+ *
1029
+ * // With retry
1030
+ * const result = await api.request({
1031
+ * method: 'GET',
1032
+ * url: '/health',
1033
+ * retry: { maxAttempts: 3, backoff: 'exponential' },
1034
+ * })
1035
+ * ```
1036
+ */
1037
+ request<T = unknown>(options: IgniterCallerDirectRequestOptions): Promise<IgniterCallerApiResponse<T>>;
1038
+ /**
1039
+ * Executes multiple requests in parallel and returns results as an array.
1040
+ *
1041
+ * This is useful for batching independent API calls.
1042
+ *
1043
+ * @param requests - Array of request promises.
1044
+ * @returns Array of resolved results in the same order.
1045
+ */
1046
+ static batch<T extends readonly Promise<IgniterCallerApiResponse<any>>[]>(requests: [...T]): Promise<{
1047
+ [K in keyof T]: T[K] extends Promise<infer R> ? R : never;
1048
+ }>;
1049
+ /**
1050
+ * Registers a global event listener for HTTP responses.
1051
+ *
1052
+ * This allows observing API responses across the application for:
1053
+ * - Debugging and logging
1054
+ * - Real-time monitoring
1055
+ * - Cache invalidation triggers
1056
+ * - Analytics and telemetry
1057
+ *
1058
+ * @param pattern URL string (exact match) or RegExp pattern
1059
+ * @param callback Function to execute when a response matches
1060
+ * @returns Cleanup function to remove the listener
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * // Listen to all user endpoints
1065
+ * const cleanup = IgniterCallerManager.on(/^\/users/, (result, context) => {
1066
+ * console.log(`${context.method} ${context.url}`, result)
1067
+ * })
1068
+ *
1069
+ * // Cleanup when done
1070
+ * cleanup()
1071
+ * ```
1072
+ */
1073
+ static on(pattern: IgniterCallerUrlPattern, callback: IgniterCallerEventCallback): () => void;
1074
+ /**
1075
+ * Removes event listeners for a pattern.
1076
+ *
1077
+ * @param pattern - URL string or RegExp pattern.
1078
+ * @param callback - Callback to remove (optional).
1079
+ */
1080
+ static off(pattern: IgniterCallerUrlPattern, callback?: IgniterCallerEventCallback): void;
1081
+ /**
1082
+ * Invalidates a specific cache entry.
1083
+ *
1084
+ * This is useful after mutations to ensure fresh data on next fetch.
1085
+ *
1086
+ * @param key - Cache key to invalidate.
1087
+ *
1088
+ * @example
1089
+ * ```ts
1090
+ * // After creating a user
1091
+ * await api.post('/users').body(newUser).execute()
1092
+ * await IgniterCallerManager.invalidate('/users') // Clear users list cache
1093
+ * ```
1094
+ */
1095
+ static invalidate(key: string): Promise<void>;
1096
+ /**
1097
+ * Invalidates all cache entries matching a pattern.
1098
+ *
1099
+ * @param pattern Glob pattern (e.g., '/users/*') or exact key
1100
+ * @returns Promise that resolves when invalidation completes.
1101
+ *
1102
+ * @example
1103
+ * ```ts
1104
+ * // Invalidate all user-related caches
1105
+ * await IgniterCallerManager.invalidatePattern('/users/*')
1106
+ * ```
1107
+ */
1108
+ static invalidatePattern(pattern: string): Promise<void>;
1109
+ /**
1110
+ * Emits an event to all registered listeners.
1111
+ *
1112
+ * @internal
1113
+ *
1114
+ * @param url - Request URL (resolved).
1115
+ * @param method - HTTP method.
1116
+ * @param result - Response envelope.
1117
+ */
1118
+ static emitEvent(url: string, method: string, result: IgniterCallerApiResponse<any>): Promise<void>;
1119
+ }
1120
+
1121
+ export { type SchemaMapEndpoint as $, type IgniterCallerMockPathDefinition as A, type IgniterCallerFileResponse as B, IgniterCallerRequestBuilder as C, type DeletePaths as D, type EndpointInfo as E, type IgniterCallerHttpMethod as F, type GetPaths as G, type HeadPaths as H, IgniterCallerManager as I, type IgniterCallerBaseRequestOptions as J, type IgniterCallerRequestOptions as K, type IgniterCallerDirectRequestOptions as L, type IgniterCallerResponseContentType as M, type IgniterCallerValidatableContentType as N, type IgniterCallerResponseMarker as O, type PostPaths as P, type IgniterCallerRetryOptions as Q, type ResolveStatusKey as R, type SchemaArray as S, type TypedRequestBuilder as T, type ExtractPathParams as U, type InferRequestType as V, type InferResponseType as W, type InferSuccessResponseType as X, type InferAllResponseTypes as Y, type SchemaMapMethods as Z, type PathsForMethod as _, type IgniterCallerApiResponse as a, type SchemaMapResponseType as a0, type SchemaMapRequestType as a1, type SchemaMapResponses as a2, type SchemaMapResponsesType as a3, type SchemaMapRequestSchema as a4, type SchemaMapResponseSchema as a5, type IgniterCallerSchemaInfer as a6, type IgniterCallerSchemaGetters as a7, type IgniterCallerMockStatus as a8, type IgniterCallerMockDefaultStatus as a9, type IgniterCallerMockRequest as aa, type IgniterCallerMockResponseForStatus as ab, type IgniterCallerMockResponseDefault as ac, type IgniterCallerMockResponse as ad, type IgniterCallerMockHandler as ae, type IgniterCallerMockHandlerDefinition as af, type IgniterCallerBuilderState as ag, type IgniterCallerRequestBuilderParams as ah, type IgniterCallerMethodRequestBuilder as ai, type InferSuccessResponse as aj, type GetEndpoint as ak, type IIgniterCallerManager as al, type IgniterCallerSchemaMap as b, type IgniterCallerSchemaMethod as c, type InferResponse as d, type IgniterCallerTypedRequestBuilder as e, type PutPaths as f, type PatchPaths as g, type IgniterCallerUrlPattern as h, type IgniterCallerEventCallback as i, type IIgniterCallerMockManager as j, type IgniterCallerMockRegistry as k, type IgniterCallerMockResolvedHandler as l, type IgniterCallerRequestInterceptor as m, type IgniterCallerResponseInterceptor as n, type IgniterCallerSchemaInput as o, type IgniterCallerSchemaValidationOptions as p, type IgniterCallerSchemaMapFrom as q, type IgniterCallerMockConfig as r, type IgniterCallerEndpointSchema as s, type IgniterCallerSchemaRegistry as t, type SchemaNullable as u, type SchemaOptional as v, type SchemaRecord as w, type IgniterCallerSchemaEndpointConfig as x, type IgniterCallerSchemaBuildResult as y, type SchemaMapPaths as z };