@igniter-js/caller 0.1.2 → 0.1.4

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,5 +1,8 @@
1
- import { StandardSchemaV1, IgniterLogger, IgniterError } from '@igniter-js/core';
1
+ import { StandardSchemaV1, IgniterError, IgniterLogger } from '@igniter-js/core';
2
+ import { IgniterTelemetryManager } from '@igniter-js/telemetry';
2
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';
3
6
 
4
7
  /**
5
8
  * Supported HTTP methods for `IgniterCaller` requests.
@@ -42,7 +45,7 @@ interface IgniterCallerRequestOptions<TBody = unknown> extends IgniterCallerBase
42
45
  url: string;
43
46
  body?: TBody;
44
47
  params?: Record<string, string | number | boolean>;
45
- responseSchema?: z.ZodSchema<any>;
48
+ responseSchema?: z.ZodSchema<any> | StandardSchemaV1;
46
49
  cache?: RequestCache;
47
50
  }
48
51
  /**
@@ -60,8 +63,8 @@ interface IgniterCallerDirectRequestOptions<TBody = unknown> extends IgniterCall
60
63
  params?: Record<string, string | number | boolean>;
61
64
  /** Cookies to send with the request */
62
65
  cookies?: Record<string, string>;
63
- /** Response validation schema (Zod) */
64
- responseSchema?: z.ZodSchema<any>;
66
+ /** Response validation schema (Zod or any StandardSchemaV1 implementation) */
67
+ responseSchema?: z.ZodSchema<any> | StandardSchemaV1;
65
68
  /** Cache strategy */
66
69
  cache?: RequestCache;
67
70
  /** Cache key for stale-while-revalidate */
@@ -78,8 +81,10 @@ interface IgniterCallerDirectRequestOptions<TBody = unknown> extends IgniterCall
78
81
  * Response object containing either successful data or an error.
79
82
  */
80
83
  interface IgniterCallerApiResponse<T> {
84
+ /** Parsed response data when the request succeeds. */
81
85
  data?: T;
82
- error?: Error;
86
+ /** Error instance when the request fails. */
87
+ error?: IgniterError;
83
88
  /** HTTP status code from the response */
84
89
  status?: number;
85
90
  /** Response headers */
@@ -90,7 +95,9 @@ interface IgniterCallerApiResponse<T> {
90
95
  * @deprecated Use execute() with responseType<File>() instead
91
96
  */
92
97
  interface IgniterCallerFileResponse {
98
+ /** File instance when download succeeds. */
93
99
  file: File | null;
100
+ /** Error instance when download fails. */
94
101
  error: Error | null;
95
102
  }
96
103
  /**
@@ -125,11 +132,17 @@ type IgniterCallerSchemaMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | '
125
132
  *
126
133
  * Maps status codes to response schemas with optional request schema.
127
134
  */
128
- type IgniterCallerEndpointSchema<TRequest extends StandardSchemaV1 = any, TResponses extends Record<number, StandardSchemaV1> = Record<number, StandardSchemaV1>> = {
135
+ type IgniterCallerEndpointSchema<TRequest extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1> = Record<number | string, StandardSchemaV1>> = {
129
136
  /** Request body schema (optional) */
130
137
  request?: TRequest;
131
138
  /** Response schemas by status code */
132
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;
133
146
  };
134
147
  /**
135
148
  * Schema map for multiple endpoints.
@@ -166,6 +179,10 @@ type IgniterCallerEndpointSchema<TRequest extends StandardSchemaV1 = any, TRespo
166
179
  * ```
167
180
  */
168
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}`>;
169
186
  /**
170
187
  * Extract path parameters from a URL pattern.
171
188
  *
@@ -187,15 +204,15 @@ type InferRequestType<T> = T extends IgniterCallerEndpointSchema<infer R, any> ?
187
204
  /**
188
205
  * Infer response type by status code from endpoint schema.
189
206
  */
190
- type InferResponseType<T, Status extends number> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? Status extends keyof Responses ? Responses[Status] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[Status]> : never : never : never;
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;
191
208
  /**
192
209
  * Infer the success response type (status 200 or 201) from endpoint schema.
193
210
  */
194
- type InferSuccessResponseType<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? 200 extends keyof Responses ? Responses[200] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[200]> : never : 201 extends keyof Responses ? Responses[201] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[201]> : never : never : never;
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;
195
212
  /**
196
213
  * Infer all possible response types (union) from endpoint schema.
197
214
  */
198
- type InferAllResponseTypes<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? Responses extends Record<number, StandardSchemaV1> ? {
215
+ type InferAllResponseTypes<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? Responses extends Record<number | string, StandardSchemaV1> ? {
199
216
  [K in keyof Responses]: Responses[K] extends StandardSchemaV1 ? {
200
217
  status: K;
201
218
  data: StandardSchemaV1.InferOutput<Responses[K]>;
@@ -209,6 +226,36 @@ type SchemaMapPaths<TSchemas extends IgniterCallerSchemaMap> = keyof TSchemas &
209
226
  * Get available methods for a specific path.
210
227
  */
211
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'>;
212
259
  /**
213
260
  * Get endpoint schema for a specific path and method.
214
261
  */
@@ -216,11 +263,28 @@ type SchemaMapEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends ke
216
263
  /**
217
264
  * Infer response type from schema map for a specific path, method, and status.
218
265
  */
219
- type SchemaMapResponseType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath], TStatus extends number = 200> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<any, infer Responses> ? TStatus extends keyof Responses ? Responses[TStatus] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Responses[TStatus]> : never : never : never;
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;
220
267
  /**
221
268
  * Infer request type from schema map for a specific path and method.
222
269
  */
223
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
+ };
224
288
  /**
225
289
  * Options for schema validation behavior.
226
290
  */
@@ -242,159 +306,6 @@ interface IgniterCallerSchemaValidationOptions {
242
306
  }) => void;
243
307
  }
244
308
 
245
- /**
246
- * Store adapter interface compatible with Igniter.js Store.
247
- *
248
- * This allows IgniterCaller to use any store implementation (Redis, in-memory, etc.)
249
- * for persistent caching across requests and deployments.
250
- */
251
- interface IgniterCallerStoreAdapter<TClient = any> {
252
- /** The underlying client instance (e.g., Redis client). */
253
- readonly client: TClient;
254
- /**
255
- * Retrieves a value from the store by its key.
256
- * @param key The key to retrieve.
257
- * @returns The value if found (auto-deserialized), otherwise null.
258
- */
259
- get<T = any>(key: string): Promise<T | null>;
260
- /**
261
- * Stores a value in the store.
262
- * @param key The key to store the value under.
263
- * @param value The value to store (will be auto-serialized).
264
- * @param options Configuration options, such as TTL.
265
- */
266
- set(key: string, value: any, options?: {
267
- ttl?: number;
268
- [key: string]: any;
269
- }): Promise<void>;
270
- /**
271
- * Deletes a key from the store.
272
- * @param key The key to delete.
273
- */
274
- delete(key: string): Promise<void>;
275
- /**
276
- * Checks if a key exists in the store.
277
- * @param key The key to check.
278
- * @returns `true` if the key exists, otherwise `false`.
279
- */
280
- has(key: string): Promise<boolean>;
281
- }
282
- /**
283
- * Configuration options for store-based caching.
284
- */
285
- interface IgniterCallerStoreOptions {
286
- /** Default TTL in seconds for cached entries (default: 3600 = 1 hour). */
287
- ttl?: number;
288
- /** Prefix for all cache keys (default: 'igniter:caller:'). */
289
- keyPrefix?: string;
290
- /** Whether to fallback to fetch cache when store is unavailable (default: true). */
291
- fallbackToFetch?: boolean;
292
- }
293
-
294
- type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = {
295
- baseURL?: string;
296
- headers?: Record<string, string>;
297
- cookies?: Record<string, string>;
298
- logger?: IgniterLogger;
299
- requestInterceptors?: IgniterCallerRequestInterceptor[];
300
- responseInterceptors?: IgniterCallerResponseInterceptor[];
301
- store?: IgniterCallerStoreAdapter;
302
- storeOptions?: IgniterCallerStoreOptions;
303
- schemas?: TSchemas;
304
- schemaValidation?: IgniterCallerSchemaValidationOptions;
305
- };
306
- type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = (state: IgniterCallerBuilderState<TSchemas>) => TCaller;
307
- /**
308
- * Utility type to replace the schema type in a caller.
309
- * Used by withSchemas to properly type the returned caller.
310
- */
311
- type ReplaceCallerSchema<TCaller, TNewSchemas extends IgniterCallerSchemaMap> = TCaller extends {
312
- schemas?: infer _;
313
- } ? Omit<TCaller, 'schemas'> & {
314
- schemas?: TNewSchemas;
315
- } : TCaller;
316
- /**
317
- * Builder used by developers to initialize the `IgniterCaller` client.
318
- *
319
- * This API is designed to remain stable when extracted to `@igniter-js/caller`.
320
- */
321
- declare class IgniterCallerBuilder<TCaller = unknown, TSchemas extends IgniterCallerSchemaMap = any> {
322
- private readonly state;
323
- private readonly factory;
324
- private constructor();
325
- /**
326
- * Creates a new builder instance.
327
- */
328
- static create<TCaller, TSchemas extends IgniterCallerSchemaMap = any>(factory: IgniterCallerBuilderFactory<TCaller, TSchemas>): IgniterCallerBuilder<TCaller, TSchemas>;
329
- /** Sets the base URL for all requests. */
330
- withBaseUrl(baseURL: string): IgniterCallerBuilder<TCaller, TSchemas>;
331
- /** Merges default headers for all requests. */
332
- withHeaders(headers: Record<string, string>): IgniterCallerBuilder<TCaller>;
333
- /** Sets default cookies (sent as the `Cookie` header). */
334
- withCookies(cookies: Record<string, string>): IgniterCallerBuilder<TCaller>;
335
- /** Attaches a logger instance. */
336
- withLogger(logger: IgniterLogger): IgniterCallerBuilder<TCaller, TSchemas>;
337
- /** Adds a request interceptor that runs before each request. */
338
- withRequestInterceptor(interceptor: IgniterCallerRequestInterceptor): IgniterCallerBuilder<TCaller, TSchemas>;
339
- /** Adds a response interceptor that runs after each request. */
340
- withResponseInterceptor(interceptor: IgniterCallerResponseInterceptor): IgniterCallerBuilder<TCaller, TSchemas>;
341
- /**
342
- * Configures a persistent store adapter for caching.
343
- *
344
- * When configured, cache operations will use the store (e.g., Redis)
345
- * instead of in-memory cache, enabling persistent cache across deployments.
346
- */
347
- withStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): IgniterCallerBuilder<TCaller, TSchemas>;
348
- /**
349
- * Configures schema-based type safety and validation.
350
- *
351
- * Enables automatic type inference for requests/responses based on
352
- * route and method, with optional runtime validation via Zod.
353
- *
354
- * @example
355
- * ```ts
356
- * const api = IgniterCaller.create()
357
- * .withSchemas({
358
- * '/users': {
359
- * GET: {
360
- * responses: {
361
- * 200: z.array(UserSchema),
362
- * 401: ErrorSchema,
363
- * },
364
- * },
365
- * POST: {
366
- * request: CreateUserSchema,
367
- * responses: {
368
- * 201: UserSchema,
369
- * 400: ValidationErrorSchema,
370
- * },
371
- * },
372
- * },
373
- * })
374
- * .build()
375
- * ```
376
- */
377
- withSchemas<TNewSchemas extends IgniterCallerSchemaMap>(schemas: TNewSchemas, validation?: IgniterCallerSchemaValidationOptions): IgniterCallerBuilder<TCaller, TNewSchemas>;
378
- /**
379
- * Builds the `IgniterCaller` instance.
380
- */
381
- build(): TCaller;
382
- }
383
-
384
- /**
385
- * Constructor params for the request builder.
386
- */
387
- interface IgniterCallerRequestBuilderParams {
388
- baseURL?: string;
389
- defaultHeaders?: Record<string, string>;
390
- defaultCookies?: Record<string, string>;
391
- logger?: IgniterLogger;
392
- requestInterceptors?: IgniterCallerRequestInterceptor[];
393
- responseInterceptors?: IgniterCallerResponseInterceptor[];
394
- eventEmitter?: (url: string, method: string, result: any) => Promise<void>;
395
- schemas?: IgniterCallerSchemaMap;
396
- schemaValidation?: IgniterCallerSchemaValidationOptions;
397
- }
398
309
  /**
399
310
  * Fluent request builder for `IgniterCaller`.
400
311
  *
@@ -404,6 +315,7 @@ interface IgniterCallerRequestBuilderParams {
404
315
  declare class IgniterCallerRequestBuilder<TResponse = unknown> {
405
316
  private options;
406
317
  private logger?;
318
+ private telemetry?;
407
319
  private retryOptions?;
408
320
  private fallbackFn?;
409
321
  private cacheKey?;
@@ -414,56 +326,87 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
414
326
  private schemas?;
415
327
  private schemaValidation?;
416
328
  private responseTypeSchema?;
329
+ /**
330
+ * Creates a new request builder instance.
331
+ *
332
+ * @param params - Builder configuration from the manager.
333
+ */
417
334
  constructor(params: IgniterCallerRequestBuilderParams);
418
335
  /**
419
336
  * Sets the HTTP method for this request.
420
337
  * @internal Used by IgniterCaller.request() for generic requests.
338
+ *
339
+ * @param method - HTTP method for the request.
421
340
  */
422
341
  _setMethod(method: IgniterCallerHttpMethod): this;
423
342
  /**
424
343
  * Sets the URL for this request.
425
344
  * @internal Used when URL is passed to HTTP method directly.
345
+ *
346
+ * @param url - Request URL or path.
426
347
  */
427
348
  _setUrl(url: string): this;
428
349
  /**
429
350
  * Overrides the logger for this request chain.
351
+ *
352
+ * @param logger - Logger implementation from `@igniter-js/core`.
430
353
  */
431
354
  withLogger(logger: IgniterLogger): this;
432
355
  /**
433
356
  * Sets the request URL.
357
+ *
358
+ * @param url - Request URL or path.
434
359
  */
435
360
  url(url: string): this;
436
361
  /**
437
362
  * Sets the request body.
438
363
  * For GET/HEAD requests, body will be automatically converted to query params.
364
+ *
365
+ * @param body - Body payload for the request.
439
366
  */
440
367
  body<TBody>(body: TBody): this;
441
368
  /**
442
369
  * Sets URL query parameters.
370
+ *
371
+ * @param params - Query string parameters.
443
372
  */
444
373
  params(params: Record<string, string | number | boolean>): this;
445
374
  /**
446
375
  * Merges additional headers into the request.
376
+ *
377
+ * @param headers - Header map merged into existing headers.
447
378
  */
448
379
  headers(headers: Record<string, string>): this;
449
380
  /**
450
381
  * Sets request timeout in milliseconds.
382
+ *
383
+ * @param timeout - Timeout in milliseconds.
451
384
  */
452
385
  timeout(timeout: number): this;
453
386
  /**
454
387
  * Sets cache strategy and optional cache key.
388
+ *
389
+ * @param cache - Cache strategy for the request.
390
+ * @param key - Optional cache key override.
455
391
  */
456
392
  cache(cache: RequestCache, key?: string): this;
457
393
  /**
458
394
  * Configures retry behavior for failed requests.
395
+ *
396
+ * @param maxAttempts - Maximum number of attempts.
397
+ * @param options - Retry options excluding `maxAttempts`.
459
398
  */
460
399
  retry(maxAttempts: number, options?: Omit<IgniterCallerRetryOptions, 'maxAttempts'>): this;
461
400
  /**
462
401
  * Provides a fallback value if the request fails.
402
+ *
403
+ * @param fn - Fallback factory called when the request fails.
463
404
  */
464
405
  fallback<T>(fn: () => T): this;
465
406
  /**
466
407
  * Sets cache stale time in milliseconds.
408
+ *
409
+ * @param milliseconds - Stale time in milliseconds.
467
410
  */
468
411
  stale(milliseconds: number): this;
469
412
  /**
@@ -474,6 +417,8 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
474
417
  *
475
418
  * The actual parsing is based on Content-Type headers, not this setting.
476
419
  *
420
+ * @param schema - Zod/StandardSchema instance for validation (optional).
421
+ *
477
422
  * @example
478
423
  * ```ts
479
424
  * // With Zod schema (validates JSON response)
@@ -487,6 +432,8 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
487
432
  /**
488
433
  * Downloads a file via GET request.
489
434
  * @deprecated Use `.responseType<File>().execute()` instead. The response type is auto-detected.
435
+ *
436
+ * @param url - URL or path to download.
490
437
  */
491
438
  getFile(url: string): {
492
439
  execute: () => Promise<IgniterCallerFileResponse>;
@@ -503,29 +450,86 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
503
450
  * - `application/octet-stream` → returned as Blob
504
451
  *
505
452
  * Schema validation (if configured) only runs for validatable content types (JSON, XML, CSV).
453
+ *
454
+ * @returns Response envelope with data or error.
506
455
  */
507
456
  execute(): Promise<IgniterCallerApiResponse<TResponse>>;
508
457
  private executeWithRetry;
509
458
  private executeSingleRequest;
459
+ private resolveUrl;
510
460
  private buildRequest;
511
461
  /**
512
462
  * Emits event for this response using injected emitter.
513
463
  */
514
464
  private emitEvent;
515
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
+ }
516
524
  /**
517
525
  * Request builder type without internal methods.
518
- * Used when creating requests via specific HTTP methods (get, post, etc.)
526
+ * Used when creating requests via specific HTTP methods (get, post, etc.).
519
527
  */
520
- type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
528
+ type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, "_setMethod" | "_setUrl">;
521
529
  /**
522
530
  * Request builder with typed response based on schema inference.
523
- * Used when creating requests via HTTP methods with URL that matches a schema.
524
- *
525
- * This type ensures that the execute() method returns the correct response type
526
- * based on the schema map configuration.
527
531
  */
528
- type IgniterCallerTypedRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
532
+ type IgniterCallerTypedRequestBuilder<TResponse = unknown> = IgniterCallerMethodRequestBuilder<TResponse>;
529
533
 
530
534
  /**
531
535
  * Callback function for event listeners.
@@ -540,6 +544,11 @@ type IgniterCallerEventCallback<T = any> = (result: IgniterCallerApiResponse<T>,
540
544
  */
541
545
  type IgniterCallerUrlPattern = string | RegExp;
542
546
 
547
+ /**
548
+ * @fileoverview Type inference helpers for @igniter-js/caller.
549
+ * @module @igniter-js/caller/types/infer
550
+ */
551
+
543
552
  /**
544
553
  * Infer success response type from endpoint schema (200 or 201).
545
554
  */
@@ -553,6 +562,86 @@ type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string,
553
562
  * Returns `unknown` if the path/method is not in the schema.
554
563
  */
555
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
+
556
645
  /**
557
646
  * HTTP client runtime for Igniter.js.
558
647
  *
@@ -561,124 +650,141 @@ type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string
561
650
  *
562
651
  * @template TSchemas - The schema map type for type-safe requests/responses.
563
652
  */
564
- declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
653
+ declare class IgniterCallerManager<TSchemas extends IgniterCallerSchemaMap> implements IIgniterCallerManager<TSchemas> {
565
654
  /** Global event emitter for observing HTTP responses */
566
655
  private static readonly events;
567
656
  private baseURL?;
568
657
  private headers?;
569
658
  private cookies?;
570
659
  private logger?;
660
+ private telemetry?;
571
661
  private requestInterceptors?;
572
662
  private responseInterceptors?;
573
663
  private schemas?;
574
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
+ */
575
671
  constructor(baseURL?: string, opts?: {
576
672
  headers?: Record<string, string>;
577
673
  cookies?: Record<string, string>;
578
674
  logger?: IgniterLogger;
675
+ telemetry?: IgniterTelemetryManager<any>;
579
676
  requestInterceptors?: IgniterCallerRequestInterceptor[];
580
677
  responseInterceptors?: IgniterCallerResponseInterceptor[];
581
678
  schemas?: TSchemas;
582
679
  schemaValidation?: IgniterCallerSchemaValidationOptions;
583
680
  });
584
- /**
585
- * Canonical initialization entrypoint.
586
- *
587
- * This is designed to remain stable when extracted to `@igniter-js/caller`.
588
- */
589
- static create<TInitSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap>(): IgniterCallerBuilder<IgniterCaller<TInitSchemas>, TInitSchemas>;
590
- /**
591
- * Returns a new client with the same config and a new logger.
592
- */
593
- withLogger(logger: IgniterLogger): IgniterCaller<TSchemas>;
594
- setBaseURL(baseURL: string): this;
595
- setHeaders(headers: Record<string, string>): this;
596
- setCookies(cookies: Record<string, string>): this;
597
681
  /**
598
682
  * Creates common request builder params.
599
683
  */
600
684
  private createBuilderParams;
601
- /**
602
- * Resolves the full URL path by prepending baseURL if needed.
603
- */
604
- private resolveSchemaPath;
605
685
  /**
606
686
  * Creates a GET request.
607
687
  *
608
- * When a URL is provided and matches a schema, the response type is automatically inferred.
688
+ * When a URL is provided and matches a schema, the response, body, and params types
689
+ * are automatically inferred from the schema definition.
609
690
  *
610
- * @param url Optional URL for the request. Can also be set via `.url()`.
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.
611
693
  *
612
694
  * @example
613
695
  * ```ts
614
- * // With typed schema - response type is inferred
615
- * const result = await api.get('/users').execute()
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()
616
700
  * // result.data is typed based on schema
617
701
  *
618
- * // Without schema or URL set later
702
+ * // Without URL (set later with .url())
619
703
  * const result = await api.get().url('/users').execute()
620
704
  * ```
621
705
  */
706
+ get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'GET'>;
622
707
  get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
623
708
  /**
624
709
  * Creates a POST request.
625
710
  *
626
- * When a URL is provided and matches a schema, the response type is automatically inferred.
711
+ * When a URL is provided and matches a schema, the response, body, and params types
712
+ * are automatically inferred from the schema definition.
627
713
  *
628
- * @param url Optional URL for the request. Can also be set via `.url()`.
714
+ * @param url Optional URL for the request.
629
715
  *
630
716
  * @example
631
717
  * ```ts
632
- * const result = await api.post('/users').body({ name: 'John' }).execute()
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()
633
722
  * ```
634
723
  */
724
+ post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'POST'>;
635
725
  post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
636
726
  /**
637
727
  * Creates a PUT request.
638
728
  *
639
- * When a URL is provided and matches a schema, the response type is automatically inferred.
729
+ * When a URL is provided and matches a schema, the response, body, and params types
730
+ * are automatically inferred from the schema definition.
640
731
  *
641
- * @param url Optional URL for the request. Can also be set via `.url()`.
732
+ * @param url Optional URL for the request.
642
733
  *
643
734
  * @example
644
735
  * ```ts
645
- * const result = await api.put('/users/1').body({ name: 'Jane' }).execute()
736
+ * const result = await api.put('/users/:id')
737
+ * .params({ id: '1' })
738
+ * .body({ name: 'Jane' })
739
+ * .execute()
646
740
  * ```
647
741
  */
742
+ put<TPath extends PutPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PUT'>;
648
743
  put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
649
744
  /**
650
745
  * Creates a PATCH request.
651
746
  *
652
- * When a URL is provided and matches a schema, the response type is automatically inferred.
747
+ * When a URL is provided and matches a schema, the response, body, and params types
748
+ * are automatically inferred from the schema definition.
653
749
  *
654
- * @param url Optional URL for the request. Can also be set via `.url()`.
750
+ * @param url Optional URL for the request.
655
751
  *
656
752
  * @example
657
753
  * ```ts
658
- * const result = await api.patch('/users/1').body({ name: 'Jane' }).execute()
754
+ * const result = await api.patch('/users/:id')
755
+ * .params({ id: '1' })
756
+ * .body({ name: 'Jane' })
757
+ * .execute()
659
758
  * ```
660
759
  */
760
+ patch<TPath extends PatchPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PATCH'>;
661
761
  patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
662
762
  /**
663
763
  * Creates a DELETE request.
664
764
  *
665
- * When a URL is provided and matches a schema, the response type is automatically inferred.
765
+ * When a URL is provided and matches a schema, the response, body, and params types
766
+ * are automatically inferred from the schema definition.
666
767
  *
667
- * @param url Optional URL for the request. Can also be set via `.url()`.
768
+ * @param url Optional URL for the request.
668
769
  *
669
770
  * @example
670
771
  * ```ts
671
- * const result = await api.delete('/users/1').execute()
772
+ * const result = await api.delete('/users/:id')
773
+ * .params({ id: '1' })
774
+ * .execute()
672
775
  * ```
673
776
  */
777
+ delete<TPath extends DeletePaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'DELETE'>;
674
778
  delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
675
779
  /**
676
780
  * Creates a HEAD request.
677
781
  *
678
- * When a URL is provided and matches a schema, the response type is automatically inferred.
782
+ * When a URL is provided and matches a schema, the response, body, and params types
783
+ * are automatically inferred from the schema definition.
679
784
  *
680
- * @param url Optional URL for the request. Can also be set via `.url()`.
785
+ * @param url Optional URL for the request.
681
786
  */
787
+ head<TPath extends HeadPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'HEAD'>;
682
788
  head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
683
789
  /**
684
790
  * Executes a request directly with all options in one object (axios-style).
@@ -686,6 +792,9 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
686
792
  * This is a convenience method for making requests without using the builder pattern.
687
793
  * Useful for dynamic requests where options are constructed programmatically.
688
794
  *
795
+ * @param options - Request configuration for method, url, and behavior.
796
+ * @returns Response envelope with data or error.
797
+ *
689
798
  * @example
690
799
  * ```ts
691
800
  * const result = await api.request({
@@ -716,6 +825,9 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
716
825
  * Executes multiple requests in parallel and returns results as an array.
717
826
  *
718
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.
719
831
  */
720
832
  static batch<T extends readonly Promise<IgniterCallerApiResponse<any>>[]>(requests: [...T]): Promise<{
721
833
  [K in keyof T]: T[K] extends Promise<infer R> ? R : never;
@@ -736,7 +848,7 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
736
848
  * @example
737
849
  * ```ts
738
850
  * // Listen to all user endpoints
739
- * const cleanup = IgniterCaller.on(/^\/users/, (result, context) => {
851
+ * const cleanup = IgniterCallerManager.on(/^\/users/, (result, context) => {
740
852
  * console.log(`${context.method} ${context.url}`, result)
741
853
  * })
742
854
  *
@@ -747,6 +859,9 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
747
859
  static on(pattern: IgniterCallerUrlPattern, callback: IgniterCallerEventCallback): () => void;
748
860
  /**
749
861
  * Removes event listeners for a pattern.
862
+ *
863
+ * @param pattern - URL string or RegExp pattern.
864
+ * @param callback - Callback to remove (optional).
750
865
  */
751
866
  static off(pattern: IgniterCallerUrlPattern, callback?: IgniterCallerEventCallback): void;
752
867
  /**
@@ -754,11 +869,13 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
754
869
  *
755
870
  * This is useful after mutations to ensure fresh data on next fetch.
756
871
  *
872
+ * @param key - Cache key to invalidate.
873
+ *
757
874
  * @example
758
875
  * ```ts
759
876
  * // After creating a user
760
877
  * await api.post('/users').body(newUser).execute()
761
- * await IgniterCaller.invalidate('/users') // Clear users list cache
878
+ * await IgniterCallerManager.invalidate('/users') // Clear users list cache
762
879
  * ```
763
880
  */
764
881
  static invalidate(key: string): Promise<void>;
@@ -766,11 +883,12 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
766
883
  * Invalidates all cache entries matching a pattern.
767
884
  *
768
885
  * @param pattern Glob pattern (e.g., '/users/*') or exact key
886
+ * @returns Promise that resolves when invalidation completes.
769
887
  *
770
888
  * @example
771
889
  * ```ts
772
890
  * // Invalidate all user-related caches
773
- * await IgniterCaller.invalidatePattern('/users/*')
891
+ * await IgniterCallerManager.invalidatePattern('/users/*')
774
892
  * ```
775
893
  */
776
894
  static invalidatePattern(pattern: string): Promise<void>;
@@ -778,6 +896,10 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
778
896
  * Emits an event to all registered listeners.
779
897
  *
780
898
  * @internal
899
+ *
900
+ * @param url - Request URL (resolved).
901
+ * @param method - HTTP method.
902
+ * @param result - Response envelope.
781
903
  */
782
904
  static emitEvent(url: string, method: string, result: IgniterCallerApiResponse<any>): Promise<void>;
783
905
  }
@@ -820,120 +942,450 @@ declare class IgniterCallerEvents {
820
942
  on(pattern: IgniterCallerUrlPattern, callback: IgniterCallerEventCallback): () => void;
821
943
  /**
822
944
  * Removes a specific listener or all listeners for a pattern.
945
+ *
946
+ * @param pattern - URL string or RegExp pattern.
947
+ * @param callback - Optional specific callback to remove.
823
948
  */
824
949
  off(pattern: IgniterCallerUrlPattern, callback?: IgniterCallerEventCallback): void;
825
950
  /**
826
951
  * Emits an event to all matching listeners.
827
952
  *
828
953
  * @internal
954
+ *
955
+ * @param url - Request URL to match listeners against.
956
+ * @param method - HTTP method.
957
+ * @param result - Response envelope.
829
958
  */
830
959
  emit(url: string, method: string, result: any): Promise<void>;
831
960
  /**
832
961
  * Removes all listeners.
962
+ *
963
+ * @returns Nothing.
833
964
  */
834
965
  clear(): void;
835
966
  }
836
967
 
837
- type IgniterCallerErrorCode = 'IGNITER_CALLER_HTTP_ERROR' | 'IGNITER_CALLER_TIMEOUT' | 'IGNITER_CALLER_REQUEST_VALIDATION_FAILED' | 'IGNITER_CALLER_RESPONSE_VALIDATION_FAILED' | 'IGNITER_CALLER_UNKNOWN_ERROR';
838
- type IgniterCallerOperation = 'execute' | 'download' | 'buildRequest' | 'parseResponse' | 'validateRequest' | 'validateResponse';
839
968
  /**
840
- * Payload used to create an {@link IgniterCallerError}.
969
+ * @fileoverview Schema builder helper types for @igniter-js/caller.
970
+ * @module @igniter-js/caller/types/schema-builder
841
971
  */
842
- type IgniterCallerErrorPayload = {
843
- /** Machine-readable error code. */
844
- code: IgniterCallerErrorCode;
845
- /** Where the error happened. */
846
- operation: IgniterCallerOperation;
847
- /** Human-readable message. */
848
- message: string;
849
- /** Optional HTTP status code when surfacing errors through HTTP boundaries. */
850
- statusCode?: number;
851
- /** Optional HTTP status text (when available). */
852
- statusText?: string;
853
- /** Extra diagnostic details (e.g. response body or schema issues). */
854
- details?: unknown;
855
- /** Arbitrary metadata for debugging. */
856
- metadata?: Record<string, unknown>;
857
- /** Optional original cause. */
858
- cause?: unknown;
859
- /** Optional logger used by IgniterError. */
860
- logger?: IgniterLogger;
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;
861
986
  };
862
987
  /**
863
- * Typed error for predictable failures in `IgniterCaller`.
864
- *
865
- * Designed to be extracted into `@igniter-js/caller`.
988
+ * Helper type for array wrappers on StandardSchemaV1.
866
989
  */
867
- declare class IgniterCallerError extends IgniterError {
868
- readonly code: IgniterCallerErrorCode;
869
- readonly operation: IgniterCallerOperation;
870
- readonly statusText?: string;
871
- readonly cause?: unknown;
872
- constructor(payload: IgniterCallerErrorPayload);
873
- static is(error: unknown): error is IgniterCallerError;
874
- }
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;
875
1057
 
876
- declare class IgniterCallerBodyUtils {
1058
+ /**
1059
+ * Builder used by developers to initialize the `IgniterCaller` client.
1060
+ *
1061
+ * This API is designed to remain stable when extracted to `@igniter-js/caller`.
1062
+ */
1063
+ declare class IgniterCallerBuilder<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
1064
+ private readonly state;
1065
+ private constructor();
877
1066
  /**
878
- * Returns true when the request body should be passed to `fetch` as-is.
1067
+ * Creates a new builder instance.
1068
+ *
1069
+ * @returns New builder instance with empty state.
879
1070
  */
880
- static isRawBody(body: unknown): boolean;
1071
+ static create(): IgniterCallerBuilder<{}>;
881
1072
  /**
882
- * Removes Content-Type for FormData so fetch can set boundaries automatically.
1073
+ * Sets the base URL for all requests.
1074
+ *
1075
+ * @param baseURL - Base URL prefix for outgoing requests.
883
1076
  */
884
- static normalizeHeadersForBody(headers: Record<string, string> | undefined, body: unknown): Record<string, string> | undefined;
885
- }
886
-
887
- /**
888
- * Cache interface for HTTP responses.
889
- *
890
- * Supports both in-memory caching and persistent store-based caching (Redis, etc).
891
- */
892
- declare class IgniterCallerCacheUtils {
893
- private static cache;
894
- private static store;
895
- private static storeOptions;
1077
+ withBaseUrl(baseURL: string): IgniterCallerBuilder<TSchemas>;
1078
+ /**
1079
+ * Merges default headers for all requests.
1080
+ *
1081
+ * @param headers - Header map merged into every request.
1082
+ */
1083
+ withHeaders(headers: Record<string, string>): IgniterCallerBuilder<TSchemas>;
1084
+ /**
1085
+ * Sets default cookies (sent as the `Cookie` header).
1086
+ *
1087
+ * @param cookies - Cookie key/value pairs.
1088
+ */
1089
+ withCookies(cookies: Record<string, string>): IgniterCallerBuilder<TSchemas>;
1090
+ /**
1091
+ * Attaches a logger instance.
1092
+ *
1093
+ * @param logger - Logger implementation from `@igniter-js/core`.
1094
+ */
1095
+ withLogger(logger: IgniterLogger): IgniterCallerBuilder<TSchemas>;
1096
+ /**
1097
+ * Adds a request interceptor that runs before each request.
1098
+ *
1099
+ * @param interceptor - Interceptor called with request options.
1100
+ */
1101
+ withRequestInterceptor(interceptor: IgniterCallerRequestInterceptor): IgniterCallerBuilder<TSchemas>;
1102
+ /**
1103
+ * Adds a response interceptor that runs after each request.
1104
+ *
1105
+ * @param interceptor - Interceptor called with the response result.
1106
+ */
1107
+ withResponseInterceptor(interceptor: IgniterCallerResponseInterceptor): IgniterCallerBuilder<TSchemas>;
896
1108
  /**
897
1109
  * Configures a persistent store adapter for caching.
898
1110
  *
899
1111
  * When configured, cache operations will use the store (e.g., Redis)
900
1112
  * instead of in-memory cache, enabling persistent cache across deployments.
1113
+ *
1114
+ * @param store - Store adapter implementation.
1115
+ * @param options - Store options (ttl, keyPrefix, fallback).
901
1116
  */
902
- static setStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): void;
1117
+ withStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): IgniterCallerBuilder<TSchemas>;
903
1118
  /**
904
- * Gets the configured store adapter.
1119
+ * Configures schema-based type safety and validation.
1120
+ *
1121
+ * Enables automatic type inference for requests/responses based on
1122
+ * route and method, with optional runtime validation via StandardSchemaV1
1123
+ * (Zod is supported).
1124
+ *
1125
+ * @param schemas - Schema map keyed by URL path and method.
1126
+ * @param validation - Validation options for request/response checks.
1127
+ *
1128
+ * @example
1129
+ * ```ts
1130
+ * const api = IgniterCaller.create()
1131
+ * .withSchemas({
1132
+ * '/users': {
1133
+ * GET: {
1134
+ * responses: {
1135
+ * 200: z.array(UserSchema),
1136
+ * 401: ErrorSchema,
1137
+ * },
1138
+ * },
1139
+ * POST: {
1140
+ * request: CreateUserSchema,
1141
+ * responses: {
1142
+ * 201: UserSchema,
1143
+ * 400: ValidationErrorSchema,
1144
+ * },
1145
+ * },
1146
+ * },
1147
+ * })
1148
+ * .build()
1149
+ * ```
905
1150
  */
906
- static getStore(): IgniterCallerStoreAdapter | null;
1151
+ withSchemas<TNewSchemas extends IgniterCallerSchemaInput>(schemas: TNewSchemas, validation?: IgniterCallerSchemaValidationOptions): IgniterCallerBuilder<IgniterCallerSchemaMapFrom<TNewSchemas>>;
907
1152
  /**
908
- * Gets cached data if it exists and is not stale.
1153
+ * Attaches telemetry for request monitoring and observability.
1154
+ *
1155
+ * Telemetry is optional and only emits events when a manager is provided.
1156
+ *
1157
+ * Telemetry events emitted by the caller package include:
1158
+ * - `request.execute.started`
1159
+ * - `request.execute.success`
1160
+ * - `request.execute.error`
1161
+ * - `request.timeout.error`
1162
+ * - `cache.read.hit`
1163
+ * - `retry.attempt.started`
1164
+ * - `validation.request.error`
1165
+ * - `validation.response.error`
1166
+ *
1167
+ * @param telemetry - Telemetry manager instance.
1168
+ *
1169
+ * @example
1170
+ * ```ts
1171
+ * import { IgniterTelemetry } from '@igniter-js/telemetry'
1172
+ * import { IgniterCallerTelemetryEvents } from '@igniter-js/caller/telemetry'
1173
+ *
1174
+ * const telemetry = IgniterTelemetry.create()
1175
+ * .withService('my-api')
1176
+ * .addEvents(IgniterCallerTelemetryEvents)
1177
+ * .build()
1178
+ *
1179
+ * const api = IgniterCaller.create()
1180
+ * .withBaseUrl('https://api.example.com')
1181
+ * .withTelemetry(telemetry)
1182
+ * .build()
1183
+ * ```
909
1184
  */
910
- static get<T>(key: string, staleTime?: number): Promise<T | undefined>;
1185
+ withTelemetry(telemetry: IgniterTelemetryManager<any>): IgniterCallerBuilder<TSchemas>;
911
1186
  /**
912
- * Stores data in cache with current timestamp.
1187
+ * Builds the `IgniterCaller` instance.
1188
+ *
1189
+ * @returns Configured manager instance.
913
1190
  */
914
- static set(key: string, data: unknown, ttl?: number): Promise<void>;
1191
+ build(): IgniterCallerManager<TSchemas>;
1192
+ }
1193
+ /**
1194
+ * Main entrypoint for the caller builder.
1195
+ *
1196
+ * @example
1197
+ * ```ts
1198
+ * const api = IgniterCaller.create().withBaseUrl('https://api.example.com').build()
1199
+ * ```
1200
+ */
1201
+ declare const IgniterCaller: {
1202
+ create: typeof IgniterCallerBuilder.create;
1203
+ };
1204
+
1205
+ /**
1206
+ * @fileoverview Path-first schema builder for @igniter-js/caller.
1207
+ * @module @igniter-js/caller/builders/schema-path
1208
+ */
1209
+
1210
+ /**
1211
+ * Builder for schema methods within a single path.
1212
+ */
1213
+ declare class IgniterCallerSchemaPathBuilder<TMethods extends Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>> = {}, TRegistry extends IgniterCallerSchemaRegistry = {}> {
1214
+ private readonly methods;
1215
+ private readonly registry;
1216
+ private constructor();
915
1217
  /**
916
- * Clears a specific cache entry.
1218
+ * Creates a new path builder for the provided registry.
917
1219
  */
918
- static clear(key: string): Promise<void>;
1220
+ static create<TRegistry extends IgniterCallerSchemaRegistry>(registry: TRegistry): IgniterCallerSchemaPathBuilder<{}, TRegistry>;
919
1221
  /**
920
- * Clears all cache entries matching a pattern.
1222
+ * Returns a registry reference helper for a given key.
1223
+ * The helper exposes optional Zod-based wrappers (array/optional/nullable/record).
1224
+ */
1225
+ ref<TKey extends keyof TRegistry>(key: TKey): {
1226
+ schema: TRegistry[TKey];
1227
+ array: () => SchemaArray<TRegistry[TKey]>;
1228
+ nullable: () => SchemaNullable<TRegistry[TKey]>;
1229
+ optional: () => SchemaOptional<TRegistry[TKey]>;
1230
+ record: (keyType?: StandardSchemaV1) => SchemaRecord<TRegistry[TKey]>;
1231
+ };
1232
+ /**
1233
+ * Defines a GET endpoint.
1234
+ */
1235
+ get<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1236
+ GET: IgniterCallerEndpointSchema<TRequest, TResponses>;
1237
+ }, TRegistry>;
1238
+ /**
1239
+ * Defines a POST endpoint.
1240
+ */
1241
+ post<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1242
+ POST: IgniterCallerEndpointSchema<TRequest, TResponses>;
1243
+ }, TRegistry>;
1244
+ /**
1245
+ * Defines a PUT endpoint.
1246
+ */
1247
+ put<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1248
+ PUT: IgniterCallerEndpointSchema<TRequest, TResponses>;
1249
+ }, TRegistry>;
1250
+ /**
1251
+ * Defines a PATCH endpoint.
1252
+ */
1253
+ patch<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1254
+ PATCH: IgniterCallerEndpointSchema<TRequest, TResponses>;
1255
+ }, TRegistry>;
1256
+ /**
1257
+ * Defines a DELETE endpoint.
1258
+ */
1259
+ delete<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1260
+ DELETE: IgniterCallerEndpointSchema<TRequest, TResponses>;
1261
+ }, TRegistry>;
1262
+ /**
1263
+ * Defines a HEAD endpoint.
1264
+ */
1265
+ head<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
1266
+ HEAD: IgniterCallerEndpointSchema<TRequest, TResponses>;
1267
+ }, TRegistry>;
1268
+ /**
1269
+ * Builds the accumulated method map for the path.
1270
+ */
1271
+ build(): TMethods;
1272
+ private addMethod;
1273
+ }
1274
+
1275
+ /**
1276
+ * @fileoverview Schema builder for @igniter-js/caller.
1277
+ * @module @igniter-js/caller/builders/schema
1278
+ */
1279
+
1280
+ /**
1281
+ * Path-first builder for caller schemas with registry support.
1282
+ */
1283
+ declare class IgniterCallerSchema<TSchemas extends IgniterCallerSchemaMap = {}, TRegistry extends IgniterCallerSchemaRegistry = {}> {
1284
+ private readonly schemas;
1285
+ private readonly registry;
1286
+ private constructor();
1287
+ /**
1288
+ * Creates a new empty schema builder.
1289
+ */
1290
+ static create(): IgniterCallerSchema<{}, {}>;
1291
+ /**
1292
+ * Registers a reusable schema in the registry.
1293
+ */
1294
+ schema<TKey extends string, TSchema extends StandardSchemaV1>(key: TKey, schema: TSchema, options?: {
1295
+ internal?: boolean;
1296
+ }): IgniterCallerSchema<TSchemas, TRegistry & {
1297
+ [K in TKey]: TSchema;
1298
+ }>;
1299
+ /**
1300
+ * Defines a path with its methods using a fluent builder.
1301
+ */
1302
+ path<TPath extends string, TMethods extends Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>>>(path: TPath, builder: (pathBuilder: IgniterCallerSchemaPathBuilder<{}, TRegistry>) => IgniterCallerSchemaPathBuilder<TMethods, TRegistry>): IgniterCallerSchema<TSchemas & {
1303
+ [K in TPath]: TMethods;
1304
+ }, TRegistry>;
1305
+ /**
1306
+ * Builds the schema map and attaches inference + runtime helpers.
1307
+ */
1308
+ build(): IgniterCallerSchemaBuildResult<TSchemas, TRegistry>;
1309
+ }
1310
+
1311
+ /**
1312
+ * Stable error codes emitted by `IgniterCaller`.
1313
+ */
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';
1315
+ /**
1316
+ * Operation identifiers used to describe where an error happened.
1317
+ */
1318
+ type IgniterCallerOperation = 'execute' | 'download' | 'buildRequest' | 'parseResponse' | 'validateRequest' | 'validateResponse' | 'buildSchema';
1319
+ /**
1320
+ * Payload used to create an {@link IgniterCallerError}.
1321
+ */
1322
+ type IgniterCallerErrorPayload = {
1323
+ /** Machine-readable error code. */
1324
+ code: IgniterCallerErrorCode;
1325
+ /** Where the error happened. */
1326
+ operation: IgniterCallerOperation;
1327
+ /** Human-readable message. */
1328
+ message: string;
1329
+ /** Optional HTTP status code when surfacing errors through HTTP boundaries. */
1330
+ statusCode?: number;
1331
+ /** Optional HTTP status text (when available). */
1332
+ statusText?: string;
1333
+ /** Extra diagnostic details (e.g. response body or schema issues). */
1334
+ details?: unknown;
1335
+ /** Arbitrary metadata for debugging. */
1336
+ metadata?: Record<string, unknown>;
1337
+ /** Optional original cause. */
1338
+ cause?: Error;
1339
+ /** Optional logger used by IgniterError. */
1340
+ logger?: IgniterLogger;
1341
+ };
1342
+ /**
1343
+ * Typed error for predictable failures in `IgniterCaller`.
1344
+ *
1345
+ * Designed to be extracted into `@igniter-js/caller`.
1346
+ */
1347
+ declare class IgniterCallerError extends IgniterError {
1348
+ /** Machine-readable error code. */
1349
+ readonly code: IgniterCallerErrorCode;
1350
+ /** Operation that produced the error. */
1351
+ readonly operation: IgniterCallerOperation;
1352
+ /** Optional HTTP status text. */
1353
+ readonly statusText?: string;
1354
+ /** Optional original error cause. */
1355
+ readonly cause?: Error;
1356
+ /**
1357
+ * Creates a new typed caller error.
921
1358
  *
922
- * @param pattern Glob pattern (e.g., '/users/*') or exact key
1359
+ * @param payload - Error payload with code, message, and metadata.
923
1360
  */
924
- static clearPattern(pattern: string): Promise<void>;
1361
+ constructor(payload: IgniterCallerErrorPayload);
925
1362
  /**
926
- * Clears all cache entries.
1363
+ * Type guard for `IgniterCallerError`.
1364
+ *
1365
+ * @param error - Value to check.
927
1366
  */
928
- static clearAll(): Promise<void>;
1367
+ static is(error: unknown): error is IgniterCallerError;
1368
+ }
1369
+
1370
+ /**
1371
+ * Body utilities for `IgniterCaller`.
1372
+ */
1373
+ declare class IgniterCallerBodyUtils {
929
1374
  /**
930
- * Adds the configured prefix to a key.
1375
+ * Returns true when the request body should be passed to `fetch` as-is.
1376
+ *
1377
+ * @param body - Request body to inspect.
1378
+ * @returns True if the body should be sent as raw data.
931
1379
  */
932
- private static getPrefixedKey;
1380
+ static isRawBody(body: unknown): boolean;
933
1381
  /**
934
- * Converts a glob pattern to a RegExp.
1382
+ * Removes Content-Type for FormData so fetch can set boundaries automatically.
1383
+ *
1384
+ * @param headers - Request headers map.
1385
+ * @param body - Request body.
1386
+ * @returns Updated headers without Content-Type when needed.
935
1387
  */
936
- private static globToRegex;
1388
+ static normalizeHeadersForBody(headers: Record<string, string> | undefined, body: unknown): Record<string, string> | undefined;
937
1389
  }
938
1390
 
939
1391
  /**
@@ -945,6 +1397,10 @@ declare class IgniterCallerSchemaUtils {
945
1397
  /**
946
1398
  * Matches a URL path against schema map paths (supports path parameters).
947
1399
  *
1400
+ * @param actualPath - Incoming request path.
1401
+ * @param schemaPath - Schema path pattern.
1402
+ * @returns Match result with params when matched.
1403
+ *
948
1404
  * @example
949
1405
  * ```ts
950
1406
  * matchPath('/users/123', '/users/:id') // { matched: true, params: { id: '123' } }
@@ -957,6 +1413,11 @@ declare class IgniterCallerSchemaUtils {
957
1413
  };
958
1414
  /**
959
1415
  * Finds the schema for a given path and method from the schema map.
1416
+ *
1417
+ * @param schemaMap - Schema map from the builder.
1418
+ * @param path - Request path to match.
1419
+ * @param method - HTTP method to match.
1420
+ * @returns Matching schema and extracted params.
960
1421
  */
961
1422
  static findSchema(schemaMap: IgniterCallerSchemaMap | undefined, path: string, method: string): {
962
1423
  schema: IgniterCallerEndpointSchema | undefined;
@@ -967,12 +1428,21 @@ declare class IgniterCallerSchemaUtils {
967
1428
  *
968
1429
  * If the schema provides `~standard.validate`, it will be used.
969
1430
  * Otherwise, returns the input as-is.
1431
+ *
1432
+ * @param schema - StandardSchema instance.
1433
+ * @param input - Input value to validate.
1434
+ * @returns Validated input value.
970
1435
  */
971
1436
  private static validateWithStandardSchema;
972
1437
  /**
973
1438
  * Validates request body against schema.
974
1439
  *
975
- * @returns Validated data or throws/logs error based on validation mode
1440
+ * @param data - Request body data.
1441
+ * @param schema - Request schema (if any).
1442
+ * @param options - Validation options.
1443
+ * @param context - Request context for error reporting.
1444
+ * @param logger - Optional logger instance.
1445
+ * @returns Validated data or throws/logs error based on validation mode.
976
1446
  */
977
1447
  static validateRequest<T>(data: unknown, schema: StandardSchemaV1 | undefined, options: IgniterCallerSchemaValidationOptions | undefined, context: {
978
1448
  url: string;
@@ -981,7 +1451,13 @@ declare class IgniterCallerSchemaUtils {
981
1451
  /**
982
1452
  * Validates response data against schema.
983
1453
  *
984
- * @returns Validated data or throws/logs error based on validation mode
1454
+ * @param data - Response payload to validate.
1455
+ * @param schema - Response schema (if any).
1456
+ * @param statusCode - HTTP status code.
1457
+ * @param options - Validation options.
1458
+ * @param context - Request context for error reporting.
1459
+ * @param logger - Optional logger instance.
1460
+ * @returns Validated data or throws/logs error based on validation mode.
985
1461
  */
986
1462
  static validateResponse<T>(data: unknown, schema: StandardSchemaV1 | undefined, statusCode: number, options: IgniterCallerSchemaValidationOptions | undefined, context: {
987
1463
  url: string;
@@ -989,6 +1465,92 @@ declare class IgniterCallerSchemaUtils {
989
1465
  }, logger?: IgniterLogger): Promise<T>;
990
1466
  }
991
1467
 
1468
+ /**
1469
+ * URL utilities for `IgniterCaller`.
1470
+ */
1471
+ declare class IgniterCallerUrlUtils {
1472
+ /**
1473
+ * Builds a full URL with optional base URL and query parameters.
1474
+ *
1475
+ * @param params - URL construction parameters.
1476
+ * @returns Full URL string.
1477
+ */
1478
+ static buildUrl(params: {
1479
+ url: string;
1480
+ baseURL?: string;
1481
+ query?: Record<string, string | number | boolean>;
1482
+ }): string;
1483
+ }
1484
+
1485
+ /**
1486
+ * Cache interface for HTTP responses.
1487
+ *
1488
+ * Supports both in-memory caching and persistent store-based caching (Redis, etc).
1489
+ */
1490
+ declare class IgniterCallerCacheUtils {
1491
+ private static cache;
1492
+ private static store;
1493
+ private static storeOptions;
1494
+ /**
1495
+ * Configures a persistent store adapter for caching.
1496
+ *
1497
+ * When configured, cache operations will use the store (e.g., Redis)
1498
+ * instead of in-memory cache, enabling persistent cache across deployments.
1499
+ *
1500
+ * @param store - Store adapter implementation.
1501
+ * @param options - Store options such as ttl and key prefix.
1502
+ */
1503
+ static setStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): void;
1504
+ /**
1505
+ * Gets the configured store adapter.
1506
+ *
1507
+ * @returns Store adapter or null when unset.
1508
+ */
1509
+ static getStore(): IgniterCallerStoreAdapter | null;
1510
+ /**
1511
+ * Gets cached data if it exists and is not stale.
1512
+ *
1513
+ * @param key - Cache key (without prefix).
1514
+ * @param staleTime - Optional stale time in milliseconds.
1515
+ * @returns Cached value or undefined when missing/stale.
1516
+ */
1517
+ static get<T>(key: string, staleTime?: number): Promise<T | undefined>;
1518
+ /**
1519
+ * Stores data in cache with current timestamp.
1520
+ *
1521
+ * @param key - Cache key (without prefix).
1522
+ * @param data - Data to cache.
1523
+ * @param ttl - Optional TTL override in seconds.
1524
+ */
1525
+ static set(key: string, data: unknown, ttl?: number): Promise<void>;
1526
+ /**
1527
+ * Clears a specific cache entry.
1528
+ *
1529
+ * @param key - Cache key (without prefix).
1530
+ */
1531
+ static clear(key: string): Promise<void>;
1532
+ /**
1533
+ * Clears all cache entries matching a pattern.
1534
+ *
1535
+ * @param pattern Glob pattern (e.g., '/users/*') or exact key
1536
+ */
1537
+ static clearPattern(pattern: string): Promise<void>;
1538
+ /**
1539
+ * Clears all cache entries.
1540
+ *
1541
+ * @returns Promise that resolves when in-memory cache is cleared.
1542
+ */
1543
+ static clearAll(): Promise<void>;
1544
+ /**
1545
+ * Adds the configured prefix to a key.
1546
+ */
1547
+ private static getPrefixedKey;
1548
+ /**
1549
+ * Converts a glob pattern to a RegExp.
1550
+ */
1551
+ private static globToRegex;
1552
+ }
1553
+
992
1554
  /**
993
1555
  * Testing utilities for `IgniterCaller`.
994
1556
  *
@@ -997,28 +1559,30 @@ declare class IgniterCallerSchemaUtils {
997
1559
  declare class IgniterCallerMock {
998
1560
  /**
999
1561
  * Creates a successful mock response.
1562
+ *
1563
+ * @param data - Mock response data.
1000
1564
  */
1001
1565
  static mockResponse<T>(data: T): IgniterCallerApiResponse<T>;
1002
1566
  /**
1003
1567
  * Creates an error mock response.
1568
+ *
1569
+ * @param code - Error code to use.
1570
+ * @param message - Optional error message.
1004
1571
  */
1005
1572
  static mockError<T = never>(code: IgniterCallerErrorCode, message?: string): IgniterCallerApiResponse<T>;
1006
1573
  /**
1007
1574
  * Creates a successful file download mock.
1575
+ *
1576
+ * @param filename - File name for the mock.
1577
+ * @param content - File contents as string or Blob.
1008
1578
  */
1009
1579
  static mockFile(filename: string, content: string | Blob): IgniterCallerFileResponse;
1010
1580
  /**
1011
1581
  * Creates a failed file download mock.
1582
+ *
1583
+ * @param message - Optional error message.
1012
1584
  */
1013
1585
  static mockFileError(message?: string): IgniterCallerFileResponse;
1014
1586
  }
1015
1587
 
1016
- declare class IgniterCallerUrlUtils {
1017
- static buildUrl(params: {
1018
- url: string;
1019
- baseURL?: string;
1020
- query?: Record<string, string | number | boolean>;
1021
- }): string;
1022
- }
1023
-
1024
- export { type ExtractPathParams, IgniterCaller, type IgniterCallerApiResponse, type IgniterCallerBaseRequestOptions, IgniterCallerBodyUtils, IgniterCallerBuilder, type IgniterCallerBuilderFactory, type IgniterCallerBuilderState, IgniterCallerCacheUtils, type IgniterCallerDirectRequestOptions, type IgniterCallerEndpointSchema, IgniterCallerError, type IgniterCallerErrorCode, type IgniterCallerErrorPayload, type IgniterCallerEventCallback, IgniterCallerEvents, type IgniterCallerFileResponse, type IgniterCallerHttpMethod, type IgniterCallerMethodRequestBuilder, IgniterCallerMock, type IgniterCallerOperation, IgniterCallerRequestBuilder, type IgniterCallerRequestBuilderParams, type IgniterCallerRequestInterceptor, type IgniterCallerRequestOptions, type IgniterCallerResponseContentType, type IgniterCallerResponseInterceptor, type IgniterCallerResponseMarker, type IgniterCallerRetryOptions, type IgniterCallerSchemaMap, type IgniterCallerSchemaMethod, IgniterCallerSchemaUtils, type IgniterCallerSchemaValidationOptions, type IgniterCallerStoreAdapter, type IgniterCallerStoreOptions, type IgniterCallerTypedRequestBuilder, type IgniterCallerUrlPattern, IgniterCallerUrlUtils, type IgniterCallerValidatableContentType, type InferAllResponseTypes, type InferRequestType, type InferResponseType, type InferSuccessResponseType, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType };
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 };