@igniter-js/caller 0.1.4 → 0.1.51

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