@igniter-js/caller 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2382 -172
- package/CHANGELOG.md +13 -0
- package/README.md +226 -14
- package/dist/adapters/index.d.mts +70 -0
- package/dist/adapters/index.d.ts +70 -0
- package/dist/adapters/index.js +91 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +89 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/client/index.d.mts +212 -0
- package/dist/client/index.d.ts +212 -0
- package/dist/client/index.js +688 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +679 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.d.mts +415 -870
- package/dist/index.d.ts +415 -870
- package/dist/index.js +1447 -297
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1439 -296
- package/dist/index.mjs.map +1 -1
- package/dist/manager-CVi9utzy.d.ts +1121 -0
- package/dist/manager-DWvX2zsz.d.mts +1121 -0
- package/dist/store-D2p2dqGN.d.mts +54 -0
- package/dist/store-D2p2dqGN.d.ts +54 -0
- package/dist/telemetry/index.d.mts +100 -0
- package/dist/telemetry/index.d.ts +100 -0
- package/dist/telemetry/index.js +54 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +52 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/package.json +35 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,402 +1,157 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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-DWvX2zsz.mjs';
|
|
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-DWvX2zsz.mjs';
|
|
3
|
+
import { IgniterLogger, StandardSchemaV1, IgniterError } from '@igniter-js/common';
|
|
4
|
+
import { IgniterTelemetryManager } from '@igniter-js/telemetry';
|
|
5
|
+
import { I as IgniterCallerStoreAdapter, a as IgniterCallerStoreOptions } from './store-D2p2dqGN.mjs';
|
|
6
|
+
export { MockCallerStoreAdapter } from './adapters/index.mjs';
|
|
7
|
+
import 'zod';
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This type is designed to remain stable when extracted to `@igniter-js/caller`.
|
|
8
|
-
*/
|
|
9
|
-
type IgniterCallerHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Retry configuration for failed requests.
|
|
13
|
-
*/
|
|
14
|
-
interface IgniterCallerRetryOptions {
|
|
15
|
-
/** Maximum number of retry attempts. */
|
|
16
|
-
maxAttempts: number;
|
|
17
|
-
/** Backoff strategy between retries. */
|
|
18
|
-
backoff?: 'linear' | 'exponential';
|
|
19
|
-
/** Base delay in milliseconds (default: 1000). */
|
|
20
|
-
baseDelay?: number;
|
|
21
|
-
/** HTTP status codes that should trigger a retry (default: [408, 429, 500, 502, 503, 504]). */
|
|
22
|
-
retryOnStatus?: number[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Base configuration options for HTTP requests.
|
|
27
|
-
*/
|
|
28
|
-
interface IgniterCallerBaseRequestOptions {
|
|
29
|
-
/** Base URL for all requests (e.g. `https://api.example.com`). */
|
|
30
|
-
baseURL?: string;
|
|
31
|
-
/** Default headers merged into each request. */
|
|
32
|
-
headers?: Record<string, string>;
|
|
33
|
-
/** Request timeout in milliseconds (default: 30000). */
|
|
34
|
-
timeout?: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Complete request configuration extending base options.
|
|
38
|
-
*/
|
|
39
|
-
interface IgniterCallerRequestOptions<TBody = unknown> extends IgniterCallerBaseRequestOptions {
|
|
40
|
-
method: IgniterCallerHttpMethod;
|
|
41
|
-
/** Endpoint URL path. If absolute, `baseURL` is ignored. */
|
|
42
|
-
url: string;
|
|
43
|
-
body?: TBody;
|
|
44
|
-
params?: Record<string, string | number | boolean>;
|
|
45
|
-
responseSchema?: z.ZodSchema<any>;
|
|
46
|
-
cache?: RequestCache;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Options for the direct request() method (axios-style).
|
|
50
|
-
* All options in one object, executes immediately.
|
|
51
|
-
*/
|
|
52
|
-
interface IgniterCallerDirectRequestOptions<TBody = unknown> extends IgniterCallerBaseRequestOptions {
|
|
53
|
-
/** HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD) */
|
|
54
|
-
method: IgniterCallerHttpMethod;
|
|
55
|
-
/** Endpoint URL path. If absolute, `baseURL` is ignored. */
|
|
56
|
-
url: string;
|
|
57
|
-
/** Request body (for POST, PUT, PATCH) */
|
|
58
|
-
body?: TBody;
|
|
59
|
-
/** URL query parameters */
|
|
60
|
-
params?: Record<string, string | number | boolean>;
|
|
61
|
-
/** Cookies to send with the request */
|
|
62
|
-
cookies?: Record<string, string>;
|
|
63
|
-
/** Response validation schema (Zod) */
|
|
64
|
-
responseSchema?: z.ZodSchema<any>;
|
|
65
|
-
/** Cache strategy */
|
|
66
|
-
cache?: RequestCache;
|
|
67
|
-
/** Cache key for stale-while-revalidate */
|
|
68
|
-
cacheKey?: string;
|
|
69
|
-
/** Stale time in milliseconds for caching */
|
|
70
|
-
staleTime?: number;
|
|
71
|
-
/** Retry configuration */
|
|
72
|
-
retry?: IgniterCallerRetryOptions;
|
|
73
|
-
/** Fallback value if request fails */
|
|
74
|
-
fallback?: () => any;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Response object containing either successful data or an error.
|
|
79
|
-
*/
|
|
80
|
-
interface IgniterCallerApiResponse<T> {
|
|
81
|
-
data?: T;
|
|
82
|
-
error?: Error;
|
|
83
|
-
/** HTTP status code from the response */
|
|
84
|
-
status?: number;
|
|
85
|
-
/** Response headers */
|
|
86
|
-
headers?: Headers;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Response object for file downloads.
|
|
90
|
-
* @deprecated Use execute() with responseType<File>() instead
|
|
91
|
-
*/
|
|
92
|
-
interface IgniterCallerFileResponse {
|
|
93
|
-
file: File | null;
|
|
94
|
-
error: Error | null;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Supported response content types that can be auto-detected.
|
|
98
|
-
*/
|
|
99
|
-
type IgniterCallerResponseContentType = 'json' | 'xml' | 'csv' | 'text' | 'html' | 'blob' | 'stream' | 'arraybuffer' | 'formdata';
|
|
100
|
-
/**
|
|
101
|
-
* Content types that support schema validation.
|
|
102
|
-
*/
|
|
103
|
-
type IgniterCallerValidatableContentType = 'json' | 'xml' | 'csv';
|
|
104
|
-
/**
|
|
105
|
-
* Marker types for responseType() to indicate expected response format.
|
|
106
|
-
* These are used for typing only and don't affect runtime behavior.
|
|
107
|
-
*/
|
|
108
|
-
type IgniterCallerResponseMarker = File | Blob | ReadableStream | ArrayBuffer | FormData;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Function that can modify request configuration before execution.
|
|
112
|
-
*/
|
|
113
|
-
type IgniterCallerRequestInterceptor = (config: IgniterCallerRequestOptions) => Promise<IgniterCallerRequestOptions> | IgniterCallerRequestOptions;
|
|
114
|
-
/**
|
|
115
|
-
* Function that can transform responses after execution.
|
|
116
|
-
*/
|
|
117
|
-
type IgniterCallerResponseInterceptor = <T>(response: IgniterCallerApiResponse<T>) => Promise<IgniterCallerApiResponse<T>> | IgniterCallerApiResponse<T>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* HTTP methods supported for schema mapping.
|
|
121
|
-
*/
|
|
122
|
-
type IgniterCallerSchemaMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
123
|
-
/**
|
|
124
|
-
* Schema definition for a single endpoint.
|
|
125
|
-
*
|
|
126
|
-
* Maps status codes to response schemas with optional request schema.
|
|
127
|
-
*/
|
|
128
|
-
type IgniterCallerEndpointSchema<TRequest extends StandardSchemaV1 = any, TResponses extends Record<number, StandardSchemaV1> = Record<number, StandardSchemaV1>> = {
|
|
129
|
-
/** Request body schema (optional) */
|
|
130
|
-
request?: TRequest;
|
|
131
|
-
/** Response schemas by status code */
|
|
132
|
-
responses: TResponses;
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Schema map for multiple endpoints.
|
|
136
|
-
*
|
|
137
|
-
* Structure: { [path]: { [method]: EndpointSchema } }
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* const schemas = {
|
|
142
|
-
* '/users': {
|
|
143
|
-
* GET: {
|
|
144
|
-
* responses: {
|
|
145
|
-
* 200: z.array(UserSchema),
|
|
146
|
-
* 401: z.object({ error: z.string() }),
|
|
147
|
-
* },
|
|
148
|
-
* },
|
|
149
|
-
* POST: {
|
|
150
|
-
* request: CreateUserSchema,
|
|
151
|
-
* responses: {
|
|
152
|
-
* 201: UserSchema,
|
|
153
|
-
* 400: z.object({ errors: z.array(z.string()) }),
|
|
154
|
-
* },
|
|
155
|
-
* },
|
|
156
|
-
* },
|
|
157
|
-
* '/users/:id': {
|
|
158
|
-
* GET: {
|
|
159
|
-
* responses: {
|
|
160
|
-
* 200: UserSchema,
|
|
161
|
-
* 404: z.object({ error: z.string() }),
|
|
162
|
-
* },
|
|
163
|
-
* },
|
|
164
|
-
* },
|
|
165
|
-
* }
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
type IgniterCallerSchemaMap = Record<string, Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>>>;
|
|
169
|
-
/**
|
|
170
|
-
* Extract path parameters from a URL pattern.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* type Params = ExtractPathParams<'/users/:id/posts/:postId'>
|
|
175
|
-
* // { id: string; postId: string }
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
179
|
-
[K in Param | keyof ExtractPathParams<`/${Rest}`>]: string;
|
|
180
|
-
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
181
|
-
[K in Param]: string;
|
|
182
|
-
} : Record<never, never>;
|
|
183
|
-
/**
|
|
184
|
-
* Infer request type from endpoint schema.
|
|
185
|
-
*/
|
|
186
|
-
type InferRequestType<T> = T extends IgniterCallerEndpointSchema<infer R, any> ? R extends StandardSchemaV1 ? StandardSchemaV1.InferInput<R> : never : never;
|
|
187
|
-
/**
|
|
188
|
-
* Infer response type by status code from endpoint schema.
|
|
189
|
-
*/
|
|
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;
|
|
191
|
-
/**
|
|
192
|
-
* Infer the success response type (status 200 or 201) from endpoint schema.
|
|
193
|
-
*/
|
|
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;
|
|
195
|
-
/**
|
|
196
|
-
* Infer all possible response types (union) from endpoint schema.
|
|
197
|
-
*/
|
|
198
|
-
type InferAllResponseTypes<T> = T extends IgniterCallerEndpointSchema<any, infer Responses> ? Responses extends Record<number, StandardSchemaV1> ? {
|
|
199
|
-
[K in keyof Responses]: Responses[K] extends StandardSchemaV1 ? {
|
|
200
|
-
status: K;
|
|
201
|
-
data: StandardSchemaV1.InferOutput<Responses[K]>;
|
|
202
|
-
} : never;
|
|
203
|
-
}[keyof Responses] : never : never;
|
|
204
|
-
/**
|
|
205
|
-
* Get all available paths from a schema map.
|
|
206
|
-
*/
|
|
207
|
-
type SchemaMapPaths<TSchemas extends IgniterCallerSchemaMap> = keyof TSchemas & string;
|
|
208
|
-
/**
|
|
209
|
-
* Get available methods for a specific path.
|
|
210
|
-
*/
|
|
211
|
-
type SchemaMapMethods<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas> = keyof TSchemas[TPath] & IgniterCallerSchemaMethod;
|
|
212
|
-
/**
|
|
213
|
-
* Get all paths that have a specific method defined.
|
|
214
|
-
*/
|
|
215
|
-
type PathsForMethod<TSchemas extends IgniterCallerSchemaMap, TMethod extends IgniterCallerSchemaMethod> = {
|
|
216
|
-
[K in keyof TSchemas]: TMethod extends keyof TSchemas[K] ? K : never;
|
|
217
|
-
}[keyof TSchemas] & string;
|
|
218
|
-
/**
|
|
219
|
-
* Get paths available for GET method.
|
|
220
|
-
*/
|
|
221
|
-
type GetPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'GET'>;
|
|
222
|
-
/**
|
|
223
|
-
* Get paths available for POST method.
|
|
224
|
-
*/
|
|
225
|
-
type PostPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'POST'>;
|
|
226
|
-
/**
|
|
227
|
-
* Get paths available for PUT method.
|
|
228
|
-
*/
|
|
229
|
-
type PutPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PUT'>;
|
|
230
|
-
/**
|
|
231
|
-
* Get paths available for PATCH method.
|
|
232
|
-
*/
|
|
233
|
-
type PatchPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PATCH'>;
|
|
234
|
-
/**
|
|
235
|
-
* Get paths available for DELETE method.
|
|
236
|
-
*/
|
|
237
|
-
type DeletePaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'DELETE'>;
|
|
238
|
-
/**
|
|
239
|
-
* Get paths available for HEAD method.
|
|
240
|
-
*/
|
|
241
|
-
type HeadPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'HEAD'>;
|
|
242
|
-
/**
|
|
243
|
-
* Get endpoint schema for a specific path and method.
|
|
244
|
-
*/
|
|
245
|
-
type SchemaMapEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod];
|
|
246
|
-
/**
|
|
247
|
-
* Infer response type from schema map for a specific path, method, and status.
|
|
248
|
-
*/
|
|
249
|
-
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;
|
|
250
|
-
/**
|
|
251
|
-
* Infer request type from schema map for a specific path and method.
|
|
252
|
-
*/
|
|
253
|
-
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;
|
|
254
|
-
/**
|
|
255
|
-
* Infer endpoint info for a specific path and method.
|
|
256
|
-
* Returns an object with response, request, and params types.
|
|
257
|
-
*/
|
|
258
|
-
type EndpointInfo<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? {
|
|
259
|
-
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;
|
|
260
|
-
request: TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Req, any> ? Req extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Req> : never : never;
|
|
261
|
-
params: ExtractPathParams<TPath & string>;
|
|
262
|
-
} : {
|
|
263
|
-
response: unknown;
|
|
264
|
-
request: never;
|
|
265
|
-
params: Record<never, never>;
|
|
266
|
-
} : {
|
|
267
|
-
response: unknown;
|
|
268
|
-
request: never;
|
|
269
|
-
params: Record<never, never>;
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* Options for schema validation behavior.
|
|
273
|
-
*/
|
|
274
|
-
interface IgniterCallerSchemaValidationOptions {
|
|
275
|
-
/**
|
|
276
|
-
* Validation mode:
|
|
277
|
-
* - 'strict': Throw error on validation failure (default)
|
|
278
|
-
* - 'soft': Log error but return raw data
|
|
279
|
-
* - 'off': Skip validation entirely
|
|
280
|
-
*/
|
|
281
|
-
mode?: 'strict' | 'soft' | 'off';
|
|
282
|
-
/**
|
|
283
|
-
* Custom error handler for validation failures.
|
|
284
|
-
*/
|
|
285
|
-
onValidationError?: (error: any, context: {
|
|
286
|
-
url: string;
|
|
287
|
-
method: string;
|
|
288
|
-
statusCode: number;
|
|
289
|
-
}) => void;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Store adapter interface compatible with Igniter.js Store.
|
|
10
|
+
* Event emitter for observing HTTP responses across the application.
|
|
294
11
|
*
|
|
295
|
-
* This allows
|
|
296
|
-
*
|
|
12
|
+
* This allows developers to listen to API responses globally for:
|
|
13
|
+
* - Debugging and logging
|
|
14
|
+
* - Real-time monitoring
|
|
15
|
+
* - Cache invalidation triggers
|
|
16
|
+
* - Analytics and telemetry
|
|
297
17
|
*/
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
18
|
+
declare class IgniterCallerEvents {
|
|
19
|
+
private listeners;
|
|
20
|
+
private patternListeners;
|
|
301
21
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* @
|
|
22
|
+
* Registers a listener for a specific URL or pattern.
|
|
23
|
+
*
|
|
24
|
+
* @param pattern URL string (exact match) or RegExp pattern
|
|
25
|
+
* @param callback Function to execute when a response matches
|
|
26
|
+
* @returns Cleanup function to remove the listener
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Listen to specific endpoint
|
|
31
|
+
* const cleanup = api.on('/users', (result) => {
|
|
32
|
+
* console.log('Users fetched:', result.data)
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* // Listen to pattern
|
|
36
|
+
* api.on(/^\/users\/\d+$/, (result) => {
|
|
37
|
+
* console.log('User detail fetched')
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Cleanup when done
|
|
41
|
+
* cleanup()
|
|
42
|
+
* ```
|
|
305
43
|
*/
|
|
306
|
-
|
|
44
|
+
on(pattern: IgniterCallerUrlPattern, callback: IgniterCallerEventCallback): () => void;
|
|
307
45
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
46
|
+
* Removes a specific listener or all listeners for a pattern.
|
|
47
|
+
*
|
|
48
|
+
* @param pattern - URL string or RegExp pattern.
|
|
49
|
+
* @param callback - Optional specific callback to remove.
|
|
312
50
|
*/
|
|
313
|
-
|
|
314
|
-
ttl?: number;
|
|
315
|
-
[key: string]: any;
|
|
316
|
-
}): Promise<void>;
|
|
51
|
+
off(pattern: IgniterCallerUrlPattern, callback?: IgniterCallerEventCallback): void;
|
|
317
52
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
53
|
+
* Emits an event to all matching listeners.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*
|
|
57
|
+
* @param url - Request URL to match listeners against.
|
|
58
|
+
* @param method - HTTP method.
|
|
59
|
+
* @param result - Response envelope.
|
|
320
60
|
*/
|
|
321
|
-
|
|
61
|
+
emit(url: string, method: string, result: any): Promise<void>;
|
|
322
62
|
/**
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @returns
|
|
63
|
+
* Removes all listeners.
|
|
64
|
+
*
|
|
65
|
+
* @returns Nothing.
|
|
326
66
|
*/
|
|
327
|
-
|
|
67
|
+
clear(): void;
|
|
328
68
|
}
|
|
69
|
+
|
|
329
70
|
/**
|
|
330
|
-
*
|
|
71
|
+
* Runtime mock registry resolver for caller requests.
|
|
331
72
|
*/
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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;
|
|
339
84
|
}
|
|
340
85
|
|
|
341
|
-
type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = {
|
|
342
|
-
baseURL?: string;
|
|
343
|
-
headers?: Record<string, string>;
|
|
344
|
-
cookies?: Record<string, string>;
|
|
345
|
-
logger?: IgniterLogger;
|
|
346
|
-
requestInterceptors?: IgniterCallerRequestInterceptor[];
|
|
347
|
-
responseInterceptors?: IgniterCallerResponseInterceptor[];
|
|
348
|
-
store?: IgniterCallerStoreAdapter;
|
|
349
|
-
storeOptions?: IgniterCallerStoreOptions;
|
|
350
|
-
schemas?: TSchemas;
|
|
351
|
-
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
352
|
-
};
|
|
353
|
-
type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = (state: IgniterCallerBuilderState<TSchemas>) => TCaller;
|
|
354
|
-
/**
|
|
355
|
-
* Utility type to replace the schema type in a caller.
|
|
356
|
-
* Used by withSchemas to properly type the returned caller.
|
|
357
|
-
*/
|
|
358
|
-
type ReplaceCallerSchema<TCaller, TNewSchemas extends IgniterCallerSchemaMap> = TCaller extends {
|
|
359
|
-
schemas?: infer _;
|
|
360
|
-
} ? Omit<TCaller, 'schemas'> & {
|
|
361
|
-
schemas?: TNewSchemas;
|
|
362
|
-
} : TCaller;
|
|
363
86
|
/**
|
|
364
87
|
* Builder used by developers to initialize the `IgniterCaller` client.
|
|
365
88
|
*
|
|
366
89
|
* This API is designed to remain stable when extracted to `@igniter-js/caller`.
|
|
367
90
|
*/
|
|
368
|
-
declare class IgniterCallerBuilder<
|
|
91
|
+
declare class IgniterCallerBuilder<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
|
|
369
92
|
private readonly state;
|
|
370
|
-
private readonly factory;
|
|
371
93
|
private constructor();
|
|
372
94
|
/**
|
|
373
95
|
* Creates a new builder instance.
|
|
96
|
+
*
|
|
97
|
+
* @returns New builder instance with empty state.
|
|
374
98
|
*/
|
|
375
|
-
static create
|
|
376
|
-
/**
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
99
|
+
static create(): IgniterCallerBuilder<{}>;
|
|
100
|
+
/**
|
|
101
|
+
* Sets the base URL for all requests.
|
|
102
|
+
*
|
|
103
|
+
* @param baseURL - Base URL prefix for outgoing requests.
|
|
104
|
+
*/
|
|
105
|
+
withBaseUrl(baseURL: string): IgniterCallerBuilder<TSchemas>;
|
|
106
|
+
/**
|
|
107
|
+
* Merges default headers for all requests.
|
|
108
|
+
*
|
|
109
|
+
* @param headers - Header map merged into every request.
|
|
110
|
+
*/
|
|
111
|
+
withHeaders(headers: Record<string, string>): IgniterCallerBuilder<TSchemas>;
|
|
112
|
+
/**
|
|
113
|
+
* Sets default cookies (sent as the `Cookie` header).
|
|
114
|
+
*
|
|
115
|
+
* @param cookies - Cookie key/value pairs.
|
|
116
|
+
*/
|
|
117
|
+
withCookies(cookies: Record<string, string>): IgniterCallerBuilder<TSchemas>;
|
|
118
|
+
/**
|
|
119
|
+
* Attaches a logger instance.
|
|
120
|
+
*
|
|
121
|
+
* @param logger - Logger implementation from `@igniter-js/common`.
|
|
122
|
+
*/
|
|
123
|
+
withLogger(logger: IgniterLogger): IgniterCallerBuilder<TSchemas>;
|
|
124
|
+
/**
|
|
125
|
+
* Adds a request interceptor that runs before each request.
|
|
126
|
+
*
|
|
127
|
+
* @param interceptor - Interceptor called with request options.
|
|
128
|
+
*/
|
|
129
|
+
withRequestInterceptor(interceptor: IgniterCallerRequestInterceptor): IgniterCallerBuilder<TSchemas>;
|
|
130
|
+
/**
|
|
131
|
+
* Adds a response interceptor that runs after each request.
|
|
132
|
+
*
|
|
133
|
+
* @param interceptor - Interceptor called with the response result.
|
|
134
|
+
*/
|
|
135
|
+
withResponseInterceptor(interceptor: IgniterCallerResponseInterceptor): IgniterCallerBuilder<TSchemas>;
|
|
388
136
|
/**
|
|
389
137
|
* Configures a persistent store adapter for caching.
|
|
390
138
|
*
|
|
391
139
|
* When configured, cache operations will use the store (e.g., Redis)
|
|
392
140
|
* instead of in-memory cache, enabling persistent cache across deployments.
|
|
141
|
+
*
|
|
142
|
+
* @param store - Store adapter implementation.
|
|
143
|
+
* @param options - Store options (ttl, keyPrefix, fallback).
|
|
393
144
|
*/
|
|
394
|
-
withStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): IgniterCallerBuilder<
|
|
145
|
+
withStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): IgniterCallerBuilder<TSchemas>;
|
|
395
146
|
/**
|
|
396
147
|
* Configures schema-based type safety and validation.
|
|
397
148
|
*
|
|
398
149
|
* Enables automatic type inference for requests/responses based on
|
|
399
|
-
* route and method, with optional runtime validation via
|
|
150
|
+
* route and method, with optional runtime validation via StandardSchemaV1
|
|
151
|
+
* (Zod is supported).
|
|
152
|
+
*
|
|
153
|
+
* @param schemas - Schema map keyed by URL path and method.
|
|
154
|
+
* @param validation - Validation options for request/response checks.
|
|
400
155
|
*
|
|
401
156
|
* @example
|
|
402
157
|
* ```ts
|
|
@@ -421,511 +176,217 @@ declare class IgniterCallerBuilder<TCaller = unknown, TSchemas extends IgniterCa
|
|
|
421
176
|
* .build()
|
|
422
177
|
* ```
|
|
423
178
|
*/
|
|
424
|
-
withSchemas<TNewSchemas extends
|
|
425
|
-
/**
|
|
426
|
-
* Builds the `IgniterCaller` instance.
|
|
427
|
-
*/
|
|
428
|
-
build(): TCaller;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Constructor params for the request builder.
|
|
433
|
-
*/
|
|
434
|
-
interface IgniterCallerRequestBuilderParams {
|
|
435
|
-
baseURL?: string;
|
|
436
|
-
defaultHeaders?: Record<string, string>;
|
|
437
|
-
defaultCookies?: Record<string, string>;
|
|
438
|
-
logger?: IgniterLogger;
|
|
439
|
-
requestInterceptors?: IgniterCallerRequestInterceptor[];
|
|
440
|
-
responseInterceptors?: IgniterCallerResponseInterceptor[];
|
|
441
|
-
eventEmitter?: (url: string, method: string, result: any) => Promise<void>;
|
|
442
|
-
schemas?: IgniterCallerSchemaMap;
|
|
443
|
-
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Fluent request builder for `IgniterCaller`.
|
|
447
|
-
*
|
|
448
|
-
* When created via specific HTTP methods (get, post, put, patch, delete),
|
|
449
|
-
* the method is already set and cannot be changed.
|
|
450
|
-
*/
|
|
451
|
-
declare class IgniterCallerRequestBuilder<TResponse = unknown> {
|
|
452
|
-
private options;
|
|
453
|
-
private logger?;
|
|
454
|
-
private retryOptions?;
|
|
455
|
-
private fallbackFn?;
|
|
456
|
-
private cacheKey?;
|
|
457
|
-
private staleTime?;
|
|
458
|
-
private requestInterceptors?;
|
|
459
|
-
private responseInterceptors?;
|
|
460
|
-
private eventEmitter?;
|
|
461
|
-
private schemas?;
|
|
462
|
-
private schemaValidation?;
|
|
463
|
-
private responseTypeSchema?;
|
|
464
|
-
constructor(params: IgniterCallerRequestBuilderParams);
|
|
465
|
-
/**
|
|
466
|
-
* Sets the HTTP method for this request.
|
|
467
|
-
* @internal Used by IgniterCaller.request() for generic requests.
|
|
468
|
-
*/
|
|
469
|
-
_setMethod(method: IgniterCallerHttpMethod): this;
|
|
179
|
+
withSchemas<TNewSchemas extends IgniterCallerSchemaInput>(schemas: TNewSchemas, validation?: IgniterCallerSchemaValidationOptions): IgniterCallerBuilder<IgniterCallerSchemaMapFrom<TNewSchemas>>;
|
|
470
180
|
/**
|
|
471
|
-
*
|
|
472
|
-
* @internal Used when URL is passed to HTTP method directly.
|
|
473
|
-
*/
|
|
474
|
-
_setUrl(url: string): this;
|
|
475
|
-
/**
|
|
476
|
-
* Overrides the logger for this request chain.
|
|
477
|
-
*/
|
|
478
|
-
withLogger(logger: IgniterLogger): this;
|
|
479
|
-
/**
|
|
480
|
-
* Sets the request URL.
|
|
481
|
-
*/
|
|
482
|
-
url(url: string): this;
|
|
483
|
-
/**
|
|
484
|
-
* Sets the request body.
|
|
485
|
-
* For GET/HEAD requests, body will be automatically converted to query params.
|
|
486
|
-
*/
|
|
487
|
-
body<TBody>(body: TBody): this;
|
|
488
|
-
/**
|
|
489
|
-
* Sets URL query parameters.
|
|
490
|
-
*/
|
|
491
|
-
params(params: Record<string, string | number | boolean>): this;
|
|
492
|
-
/**
|
|
493
|
-
* Merges additional headers into the request.
|
|
494
|
-
*/
|
|
495
|
-
headers(headers: Record<string, string>): this;
|
|
496
|
-
/**
|
|
497
|
-
* Sets request timeout in milliseconds.
|
|
498
|
-
*/
|
|
499
|
-
timeout(timeout: number): this;
|
|
500
|
-
/**
|
|
501
|
-
* Sets cache strategy and optional cache key.
|
|
502
|
-
*/
|
|
503
|
-
cache(cache: RequestCache, key?: string): this;
|
|
504
|
-
/**
|
|
505
|
-
* Configures retry behavior for failed requests.
|
|
506
|
-
*/
|
|
507
|
-
retry(maxAttempts: number, options?: Omit<IgniterCallerRetryOptions, 'maxAttempts'>): this;
|
|
508
|
-
/**
|
|
509
|
-
* Provides a fallback value if the request fails.
|
|
510
|
-
*/
|
|
511
|
-
fallback<T>(fn: () => T): this;
|
|
512
|
-
/**
|
|
513
|
-
* Sets cache stale time in milliseconds.
|
|
514
|
-
*/
|
|
515
|
-
stale(milliseconds: number): this;
|
|
516
|
-
/**
|
|
517
|
-
* Sets the expected response type for TypeScript inference.
|
|
181
|
+
* Attaches telemetry for request monitoring and observability.
|
|
518
182
|
*
|
|
519
|
-
*
|
|
520
|
-
* - If a type parameter is passed (e.g., `responseType<File>()`), it's for typing only
|
|
183
|
+
* Telemetry is optional and only emits events when a manager is provided.
|
|
521
184
|
*
|
|
522
|
-
*
|
|
185
|
+
* Telemetry events emitted by the caller package include:
|
|
186
|
+
* - `request.execute.started`
|
|
187
|
+
* - `request.execute.success`
|
|
188
|
+
* - `request.execute.error`
|
|
189
|
+
* - `request.timeout.error`
|
|
190
|
+
* - `cache.read.hit`
|
|
191
|
+
* - `retry.attempt.started`
|
|
192
|
+
* - `validation.request.error`
|
|
193
|
+
* - `validation.response.error`
|
|
194
|
+
*
|
|
195
|
+
* @param telemetry - Telemetry manager instance.
|
|
523
196
|
*
|
|
524
197
|
* @example
|
|
525
198
|
* ```ts
|
|
526
|
-
*
|
|
527
|
-
*
|
|
199
|
+
* import { IgniterTelemetry } from '@igniter-js/telemetry'
|
|
200
|
+
* import { IgniterCallerTelemetryEvents } from '@igniter-js/caller/telemetry'
|
|
201
|
+
*
|
|
202
|
+
* const telemetry = IgniterTelemetry.create()
|
|
203
|
+
* .withService('my-api')
|
|
204
|
+
* .addEvents(IgniterCallerTelemetryEvents)
|
|
205
|
+
* .build()
|
|
528
206
|
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
207
|
+
* const api = IgniterCaller.create()
|
|
208
|
+
* .withBaseUrl('https://api.example.com')
|
|
209
|
+
* .withTelemetry(telemetry)
|
|
210
|
+
* .build()
|
|
531
211
|
* ```
|
|
532
212
|
*/
|
|
533
|
-
|
|
213
|
+
withTelemetry(telemetry: IgniterTelemetryManager<any>): IgniterCallerBuilder<TSchemas>;
|
|
534
214
|
/**
|
|
535
|
-
*
|
|
536
|
-
* @deprecated Use `.responseType<File>().execute()` instead. The response type is auto-detected.
|
|
537
|
-
*/
|
|
538
|
-
getFile(url: string): {
|
|
539
|
-
execute: () => Promise<IgniterCallerFileResponse>;
|
|
540
|
-
};
|
|
541
|
-
/**
|
|
542
|
-
* Executes the HTTP request.
|
|
215
|
+
* Enables request mocking using a mock registry.
|
|
543
216
|
*
|
|
544
|
-
*
|
|
545
|
-
* - `application/json` → parsed as JSON
|
|
546
|
-
* - `text/xml`, `application/xml` → returned as text (parse with your XML library)
|
|
547
|
-
* - `text/csv` → returned as text
|
|
548
|
-
* - `text/html`, `text/plain` → returned as text
|
|
549
|
-
* - `image/*`, `audio/*`, `video/*`, `application/pdf`, etc. → returned as Blob
|
|
550
|
-
* - `application/octet-stream` → returned as Blob
|
|
217
|
+
* When enabled, matching requests are routed to the mock handlers instead of fetch.
|
|
551
218
|
*
|
|
552
|
-
*
|
|
219
|
+
* @param config - Mock configuration with registry and enable flag.
|
|
553
220
|
*/
|
|
554
|
-
|
|
555
|
-
private executeWithRetry;
|
|
556
|
-
private executeSingleRequest;
|
|
557
|
-
private buildRequest;
|
|
221
|
+
withMock(config: IgniterCallerMockConfig<TSchemas>): IgniterCallerBuilder<TSchemas>;
|
|
558
222
|
/**
|
|
559
|
-
*
|
|
223
|
+
* Builds the `IgniterCaller` instance.
|
|
224
|
+
*
|
|
225
|
+
* @returns Configured manager instance.
|
|
560
226
|
*/
|
|
561
|
-
|
|
227
|
+
build(): IgniterCallerManager<TSchemas>;
|
|
562
228
|
}
|
|
563
229
|
/**
|
|
564
|
-
*
|
|
565
|
-
* Used when creating requests via specific HTTP methods (get, post, etc.)
|
|
566
|
-
*/
|
|
567
|
-
type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
|
|
568
|
-
/**
|
|
569
|
-
* Request builder with typed response based on schema inference.
|
|
570
|
-
* Used when creating requests via HTTP methods with URL that matches a schema.
|
|
230
|
+
* Main entrypoint for the caller builder.
|
|
571
231
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const api = IgniterCaller.create().withBaseUrl('https://api.example.com').build()
|
|
235
|
+
* ```
|
|
574
236
|
*/
|
|
575
|
-
|
|
237
|
+
declare const IgniterCaller: {
|
|
238
|
+
create: typeof IgniterCallerBuilder.create;
|
|
239
|
+
};
|
|
576
240
|
|
|
577
241
|
/**
|
|
578
|
-
*
|
|
579
|
-
|
|
580
|
-
type IgniterCallerEventCallback<T = any> = (result: IgniterCallerApiResponse<T>, context: {
|
|
581
|
-
url: string;
|
|
582
|
-
method: string;
|
|
583
|
-
timestamp: number;
|
|
584
|
-
}) => void | Promise<void>;
|
|
585
|
-
/**
|
|
586
|
-
* Pattern for matching URLs (string or RegExp).
|
|
242
|
+
* @fileoverview Path-first schema builder for @igniter-js/caller.
|
|
243
|
+
* @module @igniter-js/caller/builders/schema-path
|
|
587
244
|
*/
|
|
588
|
-
type IgniterCallerUrlPattern = string | RegExp;
|
|
589
245
|
|
|
590
246
|
/**
|
|
591
|
-
*
|
|
592
|
-
*/
|
|
593
|
-
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;
|
|
594
|
-
/**
|
|
595
|
-
* Get the endpoint schema for a path and method from a schema map.
|
|
596
|
-
*/
|
|
597
|
-
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;
|
|
598
|
-
/**
|
|
599
|
-
* Infer the response type for a given path and method.
|
|
600
|
-
* Returns `unknown` if the path/method is not in the schema.
|
|
247
|
+
* Builder for schema methods within a single path.
|
|
601
248
|
*/
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
type TypedRequestBuilder<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = Omit<IgniterCallerMethodRequestBuilder<EndpointInfo<TSchemas, TPath, TMethod>['response']>, 'body' | 'params'> & {
|
|
607
|
-
/**
|
|
608
|
-
* Sets the request body with type inference from schema.
|
|
609
|
-
*/
|
|
610
|
-
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>;
|
|
611
|
-
/**
|
|
612
|
-
* Sets URL path parameters with type inference from URL pattern.
|
|
613
|
-
*/
|
|
614
|
-
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>;
|
|
615
|
-
};
|
|
616
|
-
/**
|
|
617
|
-
* HTTP client runtime for Igniter.js.
|
|
618
|
-
*
|
|
619
|
-
* This module is intentionally structured to be extracted into a standalone package
|
|
620
|
-
* in the Igniter.js ecosystem as `@igniter-js/caller`.
|
|
621
|
-
*
|
|
622
|
-
* @template TSchemas - The schema map type for type-safe requests/responses.
|
|
623
|
-
*/
|
|
624
|
-
declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
|
|
625
|
-
/** Global event emitter for observing HTTP responses */
|
|
626
|
-
private static readonly events;
|
|
627
|
-
private baseURL?;
|
|
628
|
-
private headers?;
|
|
629
|
-
private cookies?;
|
|
630
|
-
private logger?;
|
|
631
|
-
private requestInterceptors?;
|
|
632
|
-
private responseInterceptors?;
|
|
633
|
-
private schemas?;
|
|
634
|
-
private schemaValidation?;
|
|
635
|
-
constructor(baseURL?: string, opts?: {
|
|
636
|
-
headers?: Record<string, string>;
|
|
637
|
-
cookies?: Record<string, string>;
|
|
638
|
-
logger?: IgniterLogger;
|
|
639
|
-
requestInterceptors?: IgniterCallerRequestInterceptor[];
|
|
640
|
-
responseInterceptors?: IgniterCallerResponseInterceptor[];
|
|
641
|
-
schemas?: TSchemas;
|
|
642
|
-
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
643
|
-
});
|
|
644
|
-
/**
|
|
645
|
-
* Canonical initialization entrypoint.
|
|
646
|
-
*
|
|
647
|
-
* This is designed to remain stable when extracted to `@igniter-js/caller`.
|
|
648
|
-
*/
|
|
649
|
-
static create<TInitSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap>(): IgniterCallerBuilder<IgniterCaller<TInitSchemas>, TInitSchemas>;
|
|
650
|
-
/**
|
|
651
|
-
* Returns a new client with the same config and a new logger.
|
|
652
|
-
*/
|
|
653
|
-
withLogger(logger: IgniterLogger): IgniterCaller<TSchemas>;
|
|
654
|
-
setBaseURL(baseURL: string): this;
|
|
655
|
-
setHeaders(headers: Record<string, string>): this;
|
|
656
|
-
setCookies(cookies: Record<string, string>): this;
|
|
657
|
-
/**
|
|
658
|
-
* Creates common request builder params.
|
|
659
|
-
*/
|
|
660
|
-
private createBuilderParams;
|
|
661
|
-
/**
|
|
662
|
-
* Resolves the full URL path by prepending baseURL if needed.
|
|
663
|
-
*/
|
|
664
|
-
private resolveSchemaPath;
|
|
665
|
-
/**
|
|
666
|
-
* Creates a GET request.
|
|
667
|
-
*
|
|
668
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
669
|
-
* are automatically inferred from the schema definition.
|
|
670
|
-
*
|
|
671
|
-
* @param url Optional URL for the request. When provided and matching a schema path,
|
|
672
|
-
* enables full type inference for response, body, and path params.
|
|
673
|
-
*
|
|
674
|
-
* @example
|
|
675
|
-
* ```ts
|
|
676
|
-
* // With typed schema - full type inference
|
|
677
|
-
* const result = await api.get('/users/:id')
|
|
678
|
-
* .params({ id: '123' }) // params are typed based on URL pattern
|
|
679
|
-
* .execute()
|
|
680
|
-
* // result.data is typed based on schema
|
|
681
|
-
*
|
|
682
|
-
* // Without URL (set later with .url())
|
|
683
|
-
* const result = await api.get().url('/users').execute()
|
|
684
|
-
* ```
|
|
685
|
-
*/
|
|
686
|
-
get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'GET'>;
|
|
687
|
-
get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
|
|
688
|
-
/**
|
|
689
|
-
* Creates a POST request.
|
|
690
|
-
*
|
|
691
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
692
|
-
/**
|
|
693
|
-
* Creates a POST request.
|
|
694
|
-
*
|
|
695
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
696
|
-
* are automatically inferred from the schema definition.
|
|
697
|
-
*
|
|
698
|
-
* @param url Optional URL for the request.
|
|
699
|
-
*
|
|
700
|
-
* @example
|
|
701
|
-
* ```ts
|
|
702
|
-
* // With typed schema - body type is inferred from schema
|
|
703
|
-
* const result = await api.post('/users')
|
|
704
|
-
* .body({ name: 'John', email: 'john@example.com' }) // body is typed
|
|
705
|
-
* .execute()
|
|
706
|
-
* ```
|
|
707
|
-
*/
|
|
708
|
-
post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'POST'>;
|
|
709
|
-
post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
|
|
249
|
+
declare class IgniterCallerSchemaPathBuilder<TMethods extends Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>> = {}, TRegistry extends IgniterCallerSchemaRegistry = {}> {
|
|
250
|
+
private readonly methods;
|
|
251
|
+
private readonly registry;
|
|
252
|
+
private constructor();
|
|
710
253
|
/**
|
|
711
|
-
* Creates a
|
|
712
|
-
*
|
|
713
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
714
|
-
* are automatically inferred from the schema definition.
|
|
715
|
-
*
|
|
716
|
-
* @param url Optional URL for the request.
|
|
717
|
-
*
|
|
718
|
-
* @example
|
|
719
|
-
* ```ts
|
|
720
|
-
* const result = await api.put('/users/:id')
|
|
721
|
-
* .params({ id: '1' })
|
|
722
|
-
* .body({ name: 'Jane' })
|
|
723
|
-
* .execute()
|
|
724
|
-
* ```
|
|
254
|
+
* Creates a new path builder for the provided registry.
|
|
725
255
|
*/
|
|
726
|
-
|
|
727
|
-
put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
|
|
256
|
+
static create<TRegistry extends IgniterCallerSchemaRegistry>(registry: TRegistry): IgniterCallerSchemaPathBuilder<{}, TRegistry>;
|
|
728
257
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
732
|
-
* are automatically inferred from the schema definition.
|
|
733
|
-
*
|
|
734
|
-
* @param url Optional URL for the request.
|
|
735
|
-
*
|
|
736
|
-
* @example
|
|
737
|
-
* ```ts
|
|
738
|
-
* const result = await api.patch('/users/:id')
|
|
739
|
-
* .params({ id: '1' })
|
|
740
|
-
* .body({ name: 'Jane' })
|
|
741
|
-
* .execute()
|
|
742
|
-
* ```
|
|
258
|
+
* Returns a registry reference helper for a given key.
|
|
259
|
+
* The helper exposes optional Zod-based wrappers (array/optional/nullable/record).
|
|
743
260
|
*/
|
|
744
|
-
|
|
745
|
-
|
|
261
|
+
ref<TKey extends keyof TRegistry>(key: TKey): {
|
|
262
|
+
schema: TRegistry[TKey];
|
|
263
|
+
array: () => SchemaArray<TRegistry[TKey]>;
|
|
264
|
+
nullable: () => SchemaNullable<TRegistry[TKey]>;
|
|
265
|
+
optional: () => SchemaOptional<TRegistry[TKey]>;
|
|
266
|
+
record: (keyType?: StandardSchemaV1) => SchemaRecord<TRegistry[TKey]>;
|
|
267
|
+
};
|
|
746
268
|
/**
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
750
|
-
* are automatically inferred from the schema definition.
|
|
751
|
-
*
|
|
752
|
-
* @param url Optional URL for the request.
|
|
753
|
-
*
|
|
754
|
-
* @example
|
|
755
|
-
* ```ts
|
|
756
|
-
* const result = await api.delete('/users/:id')
|
|
757
|
-
* .params({ id: '1' })
|
|
758
|
-
* .execute()
|
|
759
|
-
* ```
|
|
269
|
+
* Defines a GET endpoint.
|
|
760
270
|
*/
|
|
761
|
-
|
|
762
|
-
|
|
271
|
+
get<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
272
|
+
GET: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
273
|
+
}, TRegistry>;
|
|
763
274
|
/**
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
* When a URL is provided and matches a schema, the response, body, and params types
|
|
767
|
-
* are automatically inferred from the schema definition.
|
|
768
|
-
*
|
|
769
|
-
* @param url Optional URL for the request.
|
|
275
|
+
* Defines a POST endpoint.
|
|
770
276
|
*/
|
|
771
|
-
|
|
772
|
-
|
|
277
|
+
post<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
278
|
+
POST: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
279
|
+
}, TRegistry>;
|
|
773
280
|
/**
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
* This is a convenience method for making requests without using the builder pattern.
|
|
777
|
-
* Useful for dynamic requests where options are constructed programmatically.
|
|
778
|
-
*
|
|
779
|
-
* @example
|
|
780
|
-
* ```ts
|
|
781
|
-
* const result = await api.request({
|
|
782
|
-
* method: 'POST',
|
|
783
|
-
* url: '/users',
|
|
784
|
-
* body: { name: 'John' },
|
|
785
|
-
* headers: { 'X-Custom': 'value' },
|
|
786
|
-
* timeout: 5000,
|
|
787
|
-
* })
|
|
788
|
-
*
|
|
789
|
-
* // With caching
|
|
790
|
-
* const result = await api.request({
|
|
791
|
-
* method: 'GET',
|
|
792
|
-
* url: '/users',
|
|
793
|
-
* staleTime: 30000,
|
|
794
|
-
* })
|
|
795
|
-
*
|
|
796
|
-
* // With retry
|
|
797
|
-
* const result = await api.request({
|
|
798
|
-
* method: 'GET',
|
|
799
|
-
* url: '/health',
|
|
800
|
-
* retry: { maxAttempts: 3, backoff: 'exponential' },
|
|
801
|
-
* })
|
|
802
|
-
* ```
|
|
281
|
+
* Defines a PUT endpoint.
|
|
803
282
|
*/
|
|
804
|
-
|
|
283
|
+
put<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
284
|
+
PUT: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
285
|
+
}, TRegistry>;
|
|
805
286
|
/**
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
* This is useful for batching independent API calls.
|
|
287
|
+
* Defines a PATCH endpoint.
|
|
809
288
|
*/
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
}>;
|
|
289
|
+
patch<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
290
|
+
PATCH: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
291
|
+
}, TRegistry>;
|
|
813
292
|
/**
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
* This allows observing API responses across the application for:
|
|
817
|
-
* - Debugging and logging
|
|
818
|
-
* - Real-time monitoring
|
|
819
|
-
* - Cache invalidation triggers
|
|
820
|
-
* - Analytics and telemetry
|
|
821
|
-
*
|
|
822
|
-
* @param pattern URL string (exact match) or RegExp pattern
|
|
823
|
-
* @param callback Function to execute when a response matches
|
|
824
|
-
* @returns Cleanup function to remove the listener
|
|
825
|
-
*
|
|
826
|
-
* @example
|
|
827
|
-
* ```ts
|
|
828
|
-
* // Listen to all user endpoints
|
|
829
|
-
* const cleanup = IgniterCaller.on(/^\/users/, (result, context) => {
|
|
830
|
-
* console.log(`${context.method} ${context.url}`, result)
|
|
831
|
-
* })
|
|
832
|
-
*
|
|
833
|
-
* // Cleanup when done
|
|
834
|
-
* cleanup()
|
|
835
|
-
* ```
|
|
293
|
+
* Defines a DELETE endpoint.
|
|
836
294
|
*/
|
|
837
|
-
|
|
295
|
+
delete<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
296
|
+
DELETE: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
297
|
+
}, TRegistry>;
|
|
838
298
|
/**
|
|
839
|
-
*
|
|
299
|
+
* Defines a HEAD endpoint.
|
|
840
300
|
*/
|
|
841
|
-
|
|
301
|
+
head<TRequest extends StandardSchemaV1 | undefined, TResponses extends Record<number | string, StandardSchemaV1>>(config: IgniterCallerSchemaEndpointConfig<TRequest, TResponses>): IgniterCallerSchemaPathBuilder<TMethods & {
|
|
302
|
+
HEAD: IgniterCallerEndpointSchema<TRequest, TResponses>;
|
|
303
|
+
}, TRegistry>;
|
|
842
304
|
/**
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* This is useful after mutations to ensure fresh data on next fetch.
|
|
846
|
-
*
|
|
847
|
-
* @example
|
|
848
|
-
* ```ts
|
|
849
|
-
* // After creating a user
|
|
850
|
-
* await api.post('/users').body(newUser).execute()
|
|
851
|
-
* await IgniterCaller.invalidate('/users') // Clear users list cache
|
|
852
|
-
* ```
|
|
305
|
+
* Builds the accumulated method map for the path.
|
|
853
306
|
*/
|
|
854
|
-
|
|
307
|
+
build(): TMethods;
|
|
308
|
+
private addMethod;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @fileoverview Schema builder for @igniter-js/caller.
|
|
313
|
+
* @module @igniter-js/caller/builders/schema
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Path-first builder for caller schemas with registry support.
|
|
318
|
+
*/
|
|
319
|
+
declare class IgniterCallerSchema<TSchemas extends IgniterCallerSchemaMap = {}, TRegistry extends IgniterCallerSchemaRegistry = {}> {
|
|
320
|
+
private readonly schemas;
|
|
321
|
+
private readonly registry;
|
|
322
|
+
private constructor();
|
|
855
323
|
/**
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
* @param pattern Glob pattern (e.g., '/users/*') or exact key
|
|
859
|
-
*
|
|
860
|
-
* @example
|
|
861
|
-
* ```ts
|
|
862
|
-
* // Invalidate all user-related caches
|
|
863
|
-
* await IgniterCaller.invalidatePattern('/users/*')
|
|
864
|
-
* ```
|
|
324
|
+
* Creates a new empty schema builder.
|
|
865
325
|
*/
|
|
866
|
-
static
|
|
326
|
+
static create(): IgniterCallerSchema<{}, {}>;
|
|
867
327
|
/**
|
|
868
|
-
*
|
|
869
|
-
|
|
870
|
-
|
|
328
|
+
* Registers a reusable schema in the registry.
|
|
329
|
+
*/
|
|
330
|
+
schema<TKey extends string, TSchema extends StandardSchemaV1>(key: TKey, schema: TSchema, options?: {
|
|
331
|
+
internal?: boolean;
|
|
332
|
+
}): IgniterCallerSchema<TSchemas, TRegistry & {
|
|
333
|
+
[K in TKey]: TSchema;
|
|
334
|
+
}>;
|
|
335
|
+
/**
|
|
336
|
+
* Defines a path with its methods using a fluent builder.
|
|
337
|
+
*/
|
|
338
|
+
path<TPath extends string, TMethods extends Partial<Record<IgniterCallerSchemaMethod, IgniterCallerEndpointSchema<any, any>>>>(path: TPath, builder: (pathBuilder: IgniterCallerSchemaPathBuilder<{}, TRegistry>) => IgniterCallerSchemaPathBuilder<TMethods, TRegistry>): IgniterCallerSchema<TSchemas & {
|
|
339
|
+
[K in TPath]: TMethods;
|
|
340
|
+
}, TRegistry>;
|
|
341
|
+
/**
|
|
342
|
+
* Builds the schema map and attaches inference + runtime helpers.
|
|
871
343
|
*/
|
|
872
|
-
|
|
344
|
+
build(): IgniterCallerSchemaBuildResult<TSchemas, TRegistry>;
|
|
873
345
|
}
|
|
874
346
|
|
|
875
347
|
/**
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
* This allows developers to listen to API responses globally for:
|
|
879
|
-
* - Debugging and logging
|
|
880
|
-
* - Real-time monitoring
|
|
881
|
-
* - Cache invalidation triggers
|
|
882
|
-
* - Analytics and telemetry
|
|
348
|
+
* Builder for typed caller mock registries.
|
|
883
349
|
*/
|
|
884
|
-
declare class
|
|
885
|
-
private
|
|
886
|
-
private
|
|
350
|
+
declare class IgniterCallerMockBuilder<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
|
|
351
|
+
private readonly state;
|
|
352
|
+
private constructor();
|
|
887
353
|
/**
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
* @param pattern URL string (exact match) or RegExp pattern
|
|
891
|
-
* @param callback Function to execute when a response matches
|
|
892
|
-
* @returns Cleanup function to remove the listener
|
|
893
|
-
*
|
|
894
|
-
* @example
|
|
895
|
-
* ```ts
|
|
896
|
-
* // Listen to specific endpoint
|
|
897
|
-
* const cleanup = api.on('/users', (result) => {
|
|
898
|
-
* console.log('Users fetched:', result.data)
|
|
899
|
-
* })
|
|
900
|
-
*
|
|
901
|
-
* // Listen to pattern
|
|
902
|
-
* api.on(/^\/users\/\d+$/, (result) => {
|
|
903
|
-
* console.log('User detail fetched')
|
|
904
|
-
* })
|
|
905
|
-
*
|
|
906
|
-
* // Cleanup when done
|
|
907
|
-
* cleanup()
|
|
908
|
-
* ```
|
|
354
|
+
* Creates a new mock builder.
|
|
909
355
|
*/
|
|
910
|
-
|
|
356
|
+
static create(): IgniterCallerMockBuilder<{}>;
|
|
911
357
|
/**
|
|
912
|
-
*
|
|
358
|
+
* Sets schemas to enable typed mock definitions.
|
|
359
|
+
*
|
|
360
|
+
* @param _schemas - Schema map or build result.
|
|
913
361
|
*/
|
|
914
|
-
|
|
362
|
+
withSchemas<TNewSchemas extends IgniterCallerSchemaInput>(_schemas: TNewSchemas): IgniterCallerMockBuilder<IgniterCallerSchemaMapFrom<TNewSchemas>>;
|
|
915
363
|
/**
|
|
916
|
-
*
|
|
364
|
+
* Registers mock handlers for a path.
|
|
917
365
|
*
|
|
918
|
-
* @
|
|
366
|
+
* @param path - Schema path.
|
|
367
|
+
* @param handlers - Method handlers or static responses.
|
|
919
368
|
*/
|
|
920
|
-
|
|
369
|
+
mock<TPath extends SchemaMapPaths<TSchemas>>(path: TPath, handlers: IgniterCallerMockPathDefinition<TSchemas, TPath>): IgniterCallerMockBuilder<TSchemas>;
|
|
921
370
|
/**
|
|
922
|
-
*
|
|
371
|
+
* Builds a mock manager instance.
|
|
923
372
|
*/
|
|
924
|
-
|
|
373
|
+
build(): IgniterCallerMockManager<TSchemas>;
|
|
925
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Public entrypoint for the mock builder.
|
|
377
|
+
*/
|
|
378
|
+
declare const IgniterCallerMock: {
|
|
379
|
+
create: typeof IgniterCallerMockBuilder.create;
|
|
380
|
+
};
|
|
926
381
|
|
|
927
|
-
|
|
928
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Stable error codes emitted by `IgniterCaller`.
|
|
384
|
+
*/
|
|
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';
|
|
386
|
+
/**
|
|
387
|
+
* Operation identifiers used to describe where an error happened.
|
|
388
|
+
*/
|
|
389
|
+
type IgniterCallerOperation = 'execute' | 'download' | 'buildRequest' | 'parseResponse' | 'validateRequest' | 'validateResponse' | 'buildSchema';
|
|
929
390
|
/**
|
|
930
391
|
* Payload used to create an {@link IgniterCallerError}.
|
|
931
392
|
*/
|
|
@@ -945,7 +406,7 @@ type IgniterCallerErrorPayload = {
|
|
|
945
406
|
/** Arbitrary metadata for debugging. */
|
|
946
407
|
metadata?: Record<string, unknown>;
|
|
947
408
|
/** Optional original cause. */
|
|
948
|
-
cause?:
|
|
409
|
+
cause?: Error;
|
|
949
410
|
/** Optional logger used by IgniterError. */
|
|
950
411
|
logger?: IgniterLogger;
|
|
951
412
|
};
|
|
@@ -955,75 +416,47 @@ type IgniterCallerErrorPayload = {
|
|
|
955
416
|
* Designed to be extracted into `@igniter-js/caller`.
|
|
956
417
|
*/
|
|
957
418
|
declare class IgniterCallerError extends IgniterError {
|
|
419
|
+
/** Machine-readable error code. */
|
|
958
420
|
readonly code: IgniterCallerErrorCode;
|
|
421
|
+
/** Operation that produced the error. */
|
|
959
422
|
readonly operation: IgniterCallerOperation;
|
|
423
|
+
/** Optional HTTP status text. */
|
|
960
424
|
readonly statusText?: string;
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
static is(error: unknown): error is IgniterCallerError;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
declare class IgniterCallerBodyUtils {
|
|
425
|
+
/** Optional original error cause. */
|
|
426
|
+
readonly cause?: Error;
|
|
967
427
|
/**
|
|
968
|
-
*
|
|
428
|
+
* Creates a new typed caller error.
|
|
429
|
+
*
|
|
430
|
+
* @param payload - Error payload with code, message, and metadata.
|
|
969
431
|
*/
|
|
970
|
-
|
|
432
|
+
constructor(payload: IgniterCallerErrorPayload);
|
|
971
433
|
/**
|
|
972
|
-
*
|
|
434
|
+
* Type guard for `IgniterCallerError`.
|
|
435
|
+
*
|
|
436
|
+
* @param error - Value to check.
|
|
973
437
|
*/
|
|
974
|
-
static
|
|
438
|
+
static is(error: unknown): error is IgniterCallerError;
|
|
975
439
|
}
|
|
976
440
|
|
|
977
441
|
/**
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
* Supports both in-memory caching and persistent store-based caching (Redis, etc).
|
|
442
|
+
* Body utilities for `IgniterCaller`.
|
|
981
443
|
*/
|
|
982
|
-
declare class
|
|
983
|
-
private static cache;
|
|
984
|
-
private static store;
|
|
985
|
-
private static storeOptions;
|
|
444
|
+
declare class IgniterCallerBodyUtils {
|
|
986
445
|
/**
|
|
987
|
-
*
|
|
446
|
+
* Returns true when the request body should be passed to `fetch` as-is.
|
|
988
447
|
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
991
|
-
*/
|
|
992
|
-
static setStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): void;
|
|
993
|
-
/**
|
|
994
|
-
* Gets the configured store adapter.
|
|
995
|
-
*/
|
|
996
|
-
static getStore(): IgniterCallerStoreAdapter | null;
|
|
997
|
-
/**
|
|
998
|
-
* Gets cached data if it exists and is not stale.
|
|
999
|
-
*/
|
|
1000
|
-
static get<T>(key: string, staleTime?: number): Promise<T | undefined>;
|
|
1001
|
-
/**
|
|
1002
|
-
* Stores data in cache with current timestamp.
|
|
1003
|
-
*/
|
|
1004
|
-
static set(key: string, data: unknown, ttl?: number): Promise<void>;
|
|
1005
|
-
/**
|
|
1006
|
-
* Clears a specific cache entry.
|
|
448
|
+
* @param body - Request body to inspect.
|
|
449
|
+
* @returns True if the body should be sent as raw data.
|
|
1007
450
|
*/
|
|
1008
|
-
static
|
|
451
|
+
static isRawBody(body: unknown): boolean;
|
|
1009
452
|
/**
|
|
1010
|
-
*
|
|
453
|
+
* Removes Content-Type for FormData so fetch can set boundaries automatically.
|
|
1011
454
|
*
|
|
1012
|
-
* @param
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* Clears all cache entries.
|
|
455
|
+
* @param headers - Request headers map.
|
|
456
|
+
* @param body - Request body.
|
|
457
|
+
* @returns Updated headers without Content-Type when needed.
|
|
1017
458
|
*/
|
|
1018
|
-
static
|
|
1019
|
-
/**
|
|
1020
|
-
* Adds the configured prefix to a key.
|
|
1021
|
-
*/
|
|
1022
|
-
private static getPrefixedKey;
|
|
1023
|
-
/**
|
|
1024
|
-
* Converts a glob pattern to a RegExp.
|
|
1025
|
-
*/
|
|
1026
|
-
private static globToRegex;
|
|
459
|
+
static normalizeHeadersForBody(headers: Record<string, string> | undefined, body: unknown): Record<string, string> | undefined;
|
|
1027
460
|
}
|
|
1028
461
|
|
|
1029
462
|
/**
|
|
@@ -1035,6 +468,10 @@ declare class IgniterCallerSchemaUtils {
|
|
|
1035
468
|
/**
|
|
1036
469
|
* Matches a URL path against schema map paths (supports path parameters).
|
|
1037
470
|
*
|
|
471
|
+
* @param actualPath - Incoming request path.
|
|
472
|
+
* @param schemaPath - Schema path pattern.
|
|
473
|
+
* @returns Match result with params when matched.
|
|
474
|
+
*
|
|
1038
475
|
* @example
|
|
1039
476
|
* ```ts
|
|
1040
477
|
* matchPath('/users/123', '/users/:id') // { matched: true, params: { id: '123' } }
|
|
@@ -1047,6 +484,11 @@ declare class IgniterCallerSchemaUtils {
|
|
|
1047
484
|
};
|
|
1048
485
|
/**
|
|
1049
486
|
* Finds the schema for a given path and method from the schema map.
|
|
487
|
+
*
|
|
488
|
+
* @param schemaMap - Schema map from the builder.
|
|
489
|
+
* @param path - Request path to match.
|
|
490
|
+
* @param method - HTTP method to match.
|
|
491
|
+
* @returns Matching schema and extracted params.
|
|
1050
492
|
*/
|
|
1051
493
|
static findSchema(schemaMap: IgniterCallerSchemaMap | undefined, path: string, method: string): {
|
|
1052
494
|
schema: IgniterCallerEndpointSchema | undefined;
|
|
@@ -1057,12 +499,21 @@ declare class IgniterCallerSchemaUtils {
|
|
|
1057
499
|
*
|
|
1058
500
|
* If the schema provides `~standard.validate`, it will be used.
|
|
1059
501
|
* Otherwise, returns the input as-is.
|
|
502
|
+
*
|
|
503
|
+
* @param schema - StandardSchema instance.
|
|
504
|
+
* @param input - Input value to validate.
|
|
505
|
+
* @returns Validated input value.
|
|
1060
506
|
*/
|
|
1061
507
|
private static validateWithStandardSchema;
|
|
1062
508
|
/**
|
|
1063
509
|
* Validates request body against schema.
|
|
1064
510
|
*
|
|
1065
|
-
* @
|
|
511
|
+
* @param data - Request body data.
|
|
512
|
+
* @param schema - Request schema (if any).
|
|
513
|
+
* @param options - Validation options.
|
|
514
|
+
* @param context - Request context for error reporting.
|
|
515
|
+
* @param logger - Optional logger instance.
|
|
516
|
+
* @returns Validated data or throws/logs error based on validation mode.
|
|
1066
517
|
*/
|
|
1067
518
|
static validateRequest<T>(data: unknown, schema: StandardSchemaV1 | undefined, options: IgniterCallerSchemaValidationOptions | undefined, context: {
|
|
1068
519
|
url: string;
|
|
@@ -1071,7 +522,13 @@ declare class IgniterCallerSchemaUtils {
|
|
|
1071
522
|
/**
|
|
1072
523
|
* Validates response data against schema.
|
|
1073
524
|
*
|
|
1074
|
-
* @
|
|
525
|
+
* @param data - Response payload to validate.
|
|
526
|
+
* @param schema - Response schema (if any).
|
|
527
|
+
* @param statusCode - HTTP status code.
|
|
528
|
+
* @param options - Validation options.
|
|
529
|
+
* @param context - Request context for error reporting.
|
|
530
|
+
* @param logger - Optional logger instance.
|
|
531
|
+
* @returns Validated data or throws/logs error based on validation mode.
|
|
1075
532
|
*/
|
|
1076
533
|
static validateResponse<T>(data: unknown, schema: StandardSchemaV1 | undefined, statusCode: number, options: IgniterCallerSchemaValidationOptions | undefined, context: {
|
|
1077
534
|
url: string;
|
|
@@ -1079,36 +536,124 @@ declare class IgniterCallerSchemaUtils {
|
|
|
1079
536
|
}, logger?: IgniterLogger): Promise<T>;
|
|
1080
537
|
}
|
|
1081
538
|
|
|
539
|
+
/**
|
|
540
|
+
* URL utilities for `IgniterCaller`.
|
|
541
|
+
*/
|
|
542
|
+
declare class IgniterCallerUrlUtils {
|
|
543
|
+
/**
|
|
544
|
+
* Builds a full URL with optional base URL and query parameters.
|
|
545
|
+
*
|
|
546
|
+
* @param params - URL construction parameters.
|
|
547
|
+
* @returns Full URL string.
|
|
548
|
+
*/
|
|
549
|
+
static buildUrl(params: {
|
|
550
|
+
url: string;
|
|
551
|
+
baseURL?: string;
|
|
552
|
+
query?: Record<string, string | number | boolean>;
|
|
553
|
+
}): string;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Cache interface for HTTP responses.
|
|
558
|
+
*
|
|
559
|
+
* Supports both in-memory caching and persistent store-based caching (Redis, etc).
|
|
560
|
+
*/
|
|
561
|
+
declare class IgniterCallerCacheUtils {
|
|
562
|
+
private static cache;
|
|
563
|
+
private static store;
|
|
564
|
+
private static storeOptions;
|
|
565
|
+
/**
|
|
566
|
+
* Configures a persistent store adapter for caching.
|
|
567
|
+
*
|
|
568
|
+
* When configured, cache operations will use the store (e.g., Redis)
|
|
569
|
+
* instead of in-memory cache, enabling persistent cache across deployments.
|
|
570
|
+
*
|
|
571
|
+
* @param store - Store adapter implementation.
|
|
572
|
+
* @param options - Store options such as ttl and key prefix.
|
|
573
|
+
*/
|
|
574
|
+
static setStore(store: IgniterCallerStoreAdapter, options?: IgniterCallerStoreOptions): void;
|
|
575
|
+
/**
|
|
576
|
+
* Gets the configured store adapter.
|
|
577
|
+
*
|
|
578
|
+
* @returns Store adapter or null when unset.
|
|
579
|
+
*/
|
|
580
|
+
static getStore(): IgniterCallerStoreAdapter | null;
|
|
581
|
+
/**
|
|
582
|
+
* Gets cached data if it exists and is not stale.
|
|
583
|
+
*
|
|
584
|
+
* @param key - Cache key (without prefix).
|
|
585
|
+
* @param staleTime - Optional stale time in milliseconds.
|
|
586
|
+
* @returns Cached value or undefined when missing/stale.
|
|
587
|
+
*/
|
|
588
|
+
static get<T>(key: string, staleTime?: number): Promise<T | undefined>;
|
|
589
|
+
/**
|
|
590
|
+
* Stores data in cache with current timestamp.
|
|
591
|
+
*
|
|
592
|
+
* @param key - Cache key (without prefix).
|
|
593
|
+
* @param data - Data to cache.
|
|
594
|
+
* @param ttl - Optional TTL override in seconds.
|
|
595
|
+
*/
|
|
596
|
+
static set(key: string, data: unknown, ttl?: number): Promise<void>;
|
|
597
|
+
/**
|
|
598
|
+
* Clears a specific cache entry.
|
|
599
|
+
*
|
|
600
|
+
* @param key - Cache key (without prefix).
|
|
601
|
+
*/
|
|
602
|
+
static clear(key: string): Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* Clears all cache entries matching a pattern.
|
|
605
|
+
*
|
|
606
|
+
* @param pattern Glob pattern (e.g., '/users/*') or exact key
|
|
607
|
+
*/
|
|
608
|
+
static clearPattern(pattern: string): Promise<void>;
|
|
609
|
+
/**
|
|
610
|
+
* Clears all cache entries.
|
|
611
|
+
*
|
|
612
|
+
* @returns Promise that resolves when in-memory cache is cleared.
|
|
613
|
+
*/
|
|
614
|
+
static clearAll(): Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* Adds the configured prefix to a key.
|
|
617
|
+
*/
|
|
618
|
+
private static getPrefixedKey;
|
|
619
|
+
/**
|
|
620
|
+
* Converts a glob pattern to a RegExp.
|
|
621
|
+
*/
|
|
622
|
+
private static globToRegex;
|
|
623
|
+
}
|
|
624
|
+
|
|
1082
625
|
/**
|
|
1083
626
|
* Testing utilities for `IgniterCaller`.
|
|
1084
627
|
*
|
|
1085
628
|
* Designed to simplify mocking HTTP responses in unit tests.
|
|
1086
629
|
*/
|
|
1087
|
-
declare class
|
|
630
|
+
declare class IgniterCallerHttpMock {
|
|
1088
631
|
/**
|
|
1089
632
|
* Creates a successful mock response.
|
|
633
|
+
*
|
|
634
|
+
* @param data - Mock response data.
|
|
1090
635
|
*/
|
|
1091
636
|
static mockResponse<T>(data: T): IgniterCallerApiResponse<T>;
|
|
1092
637
|
/**
|
|
1093
638
|
* Creates an error mock response.
|
|
639
|
+
*
|
|
640
|
+
* @param code - Error code to use.
|
|
641
|
+
* @param message - Optional error message.
|
|
1094
642
|
*/
|
|
1095
643
|
static mockError<T = never>(code: IgniterCallerErrorCode, message?: string): IgniterCallerApiResponse<T>;
|
|
1096
644
|
/**
|
|
1097
645
|
* Creates a successful file download mock.
|
|
646
|
+
*
|
|
647
|
+
* @param filename - File name for the mock.
|
|
648
|
+
* @param content - File contents as string or Blob.
|
|
1098
649
|
*/
|
|
1099
650
|
static mockFile(filename: string, content: string | Blob): IgniterCallerFileResponse;
|
|
1100
651
|
/**
|
|
1101
652
|
* Creates a failed file download mock.
|
|
653
|
+
*
|
|
654
|
+
* @param message - Optional error message.
|
|
1102
655
|
*/
|
|
1103
656
|
static mockFileError(message?: string): IgniterCallerFileResponse;
|
|
1104
657
|
}
|
|
1105
658
|
|
|
1106
|
-
|
|
1107
|
-
static buildUrl(params: {
|
|
1108
|
-
url: string;
|
|
1109
|
-
baseURL?: string;
|
|
1110
|
-
query?: Record<string, string | number | boolean>;
|
|
1111
|
-
}): string;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
export { type DeletePaths, type EndpointInfo, type ExtractPathParams, type GetPaths, type HeadPaths, 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 PatchPaths, type PathsForMethod, type PostPaths, type PutPaths, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType, 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 };
|