@apifn/core 0.0.1 → 0.0.3
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/README.md +255 -0
- package/dist/index.cjs +69 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -426
- package/dist/index.d.ts +5 -426
- package/dist/index.js +68 -21
- package/dist/index.js.map +1 -1
- package/dist/{out-ZUKS5QZF.js → out-X7U3YPXW.js} +3 -2
- package/dist/{out-ZUKS5QZF.js.map → out-X7U3YPXW.js.map} +1 -1
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +430 -0
- package/dist/types.d.ts +430 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +7 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,432 +1,9 @@
|
|
|
1
|
+
import { IntrospectOptions, IntrospectedRoute, SchemaDescriptor, SchemaInput, JsonSchema, OpenAPIGenerateOptions, OpenAPIDocument, ValidationError, DiffResult, DiffEntry, WatchFnClient, EndpointMetrics, AuthFnClient, SecFnRateLimiter, RateLimitInfo, LogFnClient } from './types.js';
|
|
2
|
+
export { AuthConfig, ComponentsObject, CorsOptions, EncodingObject, ExampleObject, ExternalDocsObject, HeaderObject, HttpMethod, LinkObject, MediaTypeObject, MockServerOptions, OAuthFlowObject, OAuthFlowsObject, OpenAPIInfoObject, OperationObject, ParameterDescriptor, ParameterObject, PathItemObject, PathsObject, ReferenceObject, RequestBodyDescriptor, RequestBodyObject, ResponseDescriptor, ResponseObject, SchemaDescriptorResponse, SchemaObject, SecurityRequirement, SecuritySchemeObject, ServerObject, SnippetOptions, SnippetTarget, TagObject } from './types.js';
|
|
1
3
|
import { Router } from '@superfunctions/http';
|
|
2
4
|
export { Middleware, Route, Router } from '@superfunctions/http';
|
|
3
5
|
import { BaseAdapter, TestCase, RunOptions, TestResult } from '@testfn/core';
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
* @apifn/core — Core types and interfaces
|
|
7
|
-
*
|
|
8
|
-
* All shared types for route introspection, schema descriptors,
|
|
9
|
-
* OpenAPI generation, diff detection, and ecosystem integrations.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD";
|
|
13
|
-
/** Represents any schema type: zod, TypeBox, or plain JSON Schema */
|
|
14
|
-
type SchemaInput = any;
|
|
15
|
-
/** JSON Schema object */
|
|
16
|
-
type JsonSchema = Record<string, unknown>;
|
|
17
|
-
interface IntrospectOptions {
|
|
18
|
-
/** Include routes matching these path prefixes only */
|
|
19
|
-
include?: string[];
|
|
20
|
-
/** Exclude routes matching these path prefixes */
|
|
21
|
-
exclude?: string[];
|
|
22
|
-
/** Base path to prepend to all route paths */
|
|
23
|
-
basePath?: string;
|
|
24
|
-
}
|
|
25
|
-
interface ParameterDescriptor {
|
|
26
|
-
name: string;
|
|
27
|
-
in: "path" | "query" | "header" | "cookie";
|
|
28
|
-
required: boolean;
|
|
29
|
-
description?: string;
|
|
30
|
-
deprecated?: boolean;
|
|
31
|
-
schema: JsonSchema;
|
|
32
|
-
}
|
|
33
|
-
interface RequestBodyDescriptor {
|
|
34
|
-
required?: boolean;
|
|
35
|
-
description?: string;
|
|
36
|
-
content: Record<string, {
|
|
37
|
-
schema: JsonSchema;
|
|
38
|
-
examples?: Record<string, unknown>;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
|
41
|
-
interface ResponseDescriptor {
|
|
42
|
-
description: string;
|
|
43
|
-
content?: Record<string, {
|
|
44
|
-
schema: JsonSchema;
|
|
45
|
-
examples?: Record<string, unknown>;
|
|
46
|
-
}>;
|
|
47
|
-
headers?: Record<string, {
|
|
48
|
-
schema: JsonSchema;
|
|
49
|
-
description?: string;
|
|
50
|
-
}>;
|
|
51
|
-
}
|
|
52
|
-
type SecurityRequirement = Record<string, string[]>;
|
|
53
|
-
interface IntrospectedRoute {
|
|
54
|
-
method: HttpMethod;
|
|
55
|
-
path: string;
|
|
56
|
-
operationId?: string;
|
|
57
|
-
summary?: string;
|
|
58
|
-
description?: string;
|
|
59
|
-
tags?: string[];
|
|
60
|
-
deprecated?: boolean;
|
|
61
|
-
parameters: ParameterDescriptor[];
|
|
62
|
-
requestBody?: RequestBodyDescriptor;
|
|
63
|
-
responses: Record<string, ResponseDescriptor>;
|
|
64
|
-
security?: SecurityRequirement[];
|
|
65
|
-
meta: Record<string, unknown>;
|
|
66
|
-
}
|
|
67
|
-
interface SchemaDescriptorResponse {
|
|
68
|
-
description: string;
|
|
69
|
-
schema?: SchemaInput;
|
|
70
|
-
headers?: Record<string, SchemaInput>;
|
|
71
|
-
}
|
|
72
|
-
interface SchemaDescriptor {
|
|
73
|
-
/** Human-readable summary */
|
|
74
|
-
summary?: string;
|
|
75
|
-
/** Detailed description */
|
|
76
|
-
description?: string;
|
|
77
|
-
/** Unique operation identifier */
|
|
78
|
-
operationId?: string;
|
|
79
|
-
/** Tags for grouping */
|
|
80
|
-
tags?: string[];
|
|
81
|
-
/** Whether this endpoint is deprecated */
|
|
82
|
-
deprecated?: boolean;
|
|
83
|
-
/** Request body schema (zod, TypeBox, or JSON Schema) */
|
|
84
|
-
body?: SchemaInput;
|
|
85
|
-
/** Query parameter schemas */
|
|
86
|
-
query?: Record<string, SchemaInput>;
|
|
87
|
-
/** Path parameter schemas */
|
|
88
|
-
params?: Record<string, SchemaInput>;
|
|
89
|
-
/** Header parameter schemas */
|
|
90
|
-
headers?: Record<string, SchemaInput>;
|
|
91
|
-
/** Response schemas keyed by status code */
|
|
92
|
-
responses?: Record<string | number, SchemaDescriptorResponse>;
|
|
93
|
-
/** Security requirements */
|
|
94
|
-
security?: SecurityRequirement[];
|
|
95
|
-
}
|
|
96
|
-
interface OpenAPIInfoObject {
|
|
97
|
-
title: string;
|
|
98
|
-
version: string;
|
|
99
|
-
description?: string;
|
|
100
|
-
termsOfService?: string;
|
|
101
|
-
contact?: {
|
|
102
|
-
name?: string;
|
|
103
|
-
url?: string;
|
|
104
|
-
email?: string;
|
|
105
|
-
};
|
|
106
|
-
license?: {
|
|
107
|
-
name: string;
|
|
108
|
-
url?: string;
|
|
109
|
-
identifier?: string;
|
|
110
|
-
};
|
|
111
|
-
summary?: string;
|
|
112
|
-
}
|
|
113
|
-
interface ServerObject {
|
|
114
|
-
url: string;
|
|
115
|
-
description?: string;
|
|
116
|
-
variables?: Record<string, {
|
|
117
|
-
default: string;
|
|
118
|
-
enum?: string[];
|
|
119
|
-
description?: string;
|
|
120
|
-
}>;
|
|
121
|
-
}
|
|
122
|
-
interface ExternalDocsObject {
|
|
123
|
-
url: string;
|
|
124
|
-
description?: string;
|
|
125
|
-
}
|
|
126
|
-
interface TagObject {
|
|
127
|
-
name: string;
|
|
128
|
-
description?: string;
|
|
129
|
-
externalDocs?: ExternalDocsObject;
|
|
130
|
-
}
|
|
131
|
-
interface SchemaObject extends JsonSchema {
|
|
132
|
-
[key: string]: unknown;
|
|
133
|
-
}
|
|
134
|
-
interface MediaTypeObject {
|
|
135
|
-
schema?: SchemaObject;
|
|
136
|
-
example?: unknown;
|
|
137
|
-
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
138
|
-
encoding?: Record<string, EncodingObject>;
|
|
139
|
-
}
|
|
140
|
-
interface ExampleObject {
|
|
141
|
-
summary?: string;
|
|
142
|
-
description?: string;
|
|
143
|
-
value?: unknown;
|
|
144
|
-
externalValue?: string;
|
|
145
|
-
}
|
|
146
|
-
interface ReferenceObject {
|
|
147
|
-
$ref: string;
|
|
148
|
-
summary?: string;
|
|
149
|
-
description?: string;
|
|
150
|
-
}
|
|
151
|
-
interface EncodingObject {
|
|
152
|
-
contentType?: string;
|
|
153
|
-
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
154
|
-
style?: string;
|
|
155
|
-
explode?: boolean;
|
|
156
|
-
allowReserved?: boolean;
|
|
157
|
-
}
|
|
158
|
-
interface HeaderObject {
|
|
159
|
-
description?: string;
|
|
160
|
-
required?: boolean;
|
|
161
|
-
deprecated?: boolean;
|
|
162
|
-
schema?: SchemaObject;
|
|
163
|
-
}
|
|
164
|
-
interface ParameterObject {
|
|
165
|
-
name: string;
|
|
166
|
-
in: "path" | "query" | "header" | "cookie";
|
|
167
|
-
description?: string;
|
|
168
|
-
required?: boolean;
|
|
169
|
-
deprecated?: boolean;
|
|
170
|
-
allowEmptyValue?: boolean;
|
|
171
|
-
style?: string;
|
|
172
|
-
explode?: boolean;
|
|
173
|
-
allowReserved?: boolean;
|
|
174
|
-
schema?: SchemaObject;
|
|
175
|
-
example?: unknown;
|
|
176
|
-
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
177
|
-
content?: Record<string, MediaTypeObject>;
|
|
178
|
-
}
|
|
179
|
-
interface RequestBodyObject {
|
|
180
|
-
description?: string;
|
|
181
|
-
content: Record<string, MediaTypeObject>;
|
|
182
|
-
required?: boolean;
|
|
183
|
-
}
|
|
184
|
-
interface ResponseObject {
|
|
185
|
-
description: string;
|
|
186
|
-
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
187
|
-
content?: Record<string, MediaTypeObject>;
|
|
188
|
-
links?: Record<string, LinkObject | ReferenceObject>;
|
|
189
|
-
}
|
|
190
|
-
interface LinkObject {
|
|
191
|
-
operationRef?: string;
|
|
192
|
-
operationId?: string;
|
|
193
|
-
parameters?: Record<string, unknown>;
|
|
194
|
-
requestBody?: unknown;
|
|
195
|
-
description?: string;
|
|
196
|
-
server?: ServerObject;
|
|
197
|
-
}
|
|
198
|
-
interface OperationObject {
|
|
199
|
-
tags?: string[];
|
|
200
|
-
summary?: string;
|
|
201
|
-
description?: string;
|
|
202
|
-
externalDocs?: ExternalDocsObject;
|
|
203
|
-
operationId?: string;
|
|
204
|
-
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
205
|
-
requestBody?: RequestBodyObject | ReferenceObject;
|
|
206
|
-
responses?: Record<string, ResponseObject | ReferenceObject>;
|
|
207
|
-
callbacks?: Record<string, Record<string, PathItemObject> | ReferenceObject>;
|
|
208
|
-
deprecated?: boolean;
|
|
209
|
-
security?: SecurityRequirement[];
|
|
210
|
-
servers?: ServerObject[];
|
|
211
|
-
}
|
|
212
|
-
interface PathItemObject {
|
|
213
|
-
summary?: string;
|
|
214
|
-
description?: string;
|
|
215
|
-
get?: OperationObject;
|
|
216
|
-
put?: OperationObject;
|
|
217
|
-
post?: OperationObject;
|
|
218
|
-
delete?: OperationObject;
|
|
219
|
-
options?: OperationObject;
|
|
220
|
-
head?: OperationObject;
|
|
221
|
-
patch?: OperationObject;
|
|
222
|
-
trace?: OperationObject;
|
|
223
|
-
servers?: ServerObject[];
|
|
224
|
-
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
225
|
-
}
|
|
226
|
-
type PathsObject = Record<string, PathItemObject>;
|
|
227
|
-
interface SecuritySchemeObject {
|
|
228
|
-
type: "apiKey" | "http" | "mutualTLS" | "oauth2" | "openIdConnect";
|
|
229
|
-
description?: string;
|
|
230
|
-
name?: string;
|
|
231
|
-
in?: "query" | "header" | "cookie";
|
|
232
|
-
scheme?: string;
|
|
233
|
-
bearerFormat?: string;
|
|
234
|
-
flows?: OAuthFlowsObject;
|
|
235
|
-
openIdConnectUrl?: string;
|
|
236
|
-
}
|
|
237
|
-
interface OAuthFlowsObject {
|
|
238
|
-
implicit?: OAuthFlowObject;
|
|
239
|
-
password?: OAuthFlowObject;
|
|
240
|
-
clientCredentials?: OAuthFlowObject;
|
|
241
|
-
authorizationCode?: OAuthFlowObject;
|
|
242
|
-
}
|
|
243
|
-
interface OAuthFlowObject {
|
|
244
|
-
authorizationUrl?: string;
|
|
245
|
-
tokenUrl?: string;
|
|
246
|
-
refreshUrl?: string;
|
|
247
|
-
scopes: Record<string, string>;
|
|
248
|
-
}
|
|
249
|
-
interface ComponentsObject {
|
|
250
|
-
schemas?: Record<string, SchemaObject | ReferenceObject>;
|
|
251
|
-
responses?: Record<string, ResponseObject | ReferenceObject>;
|
|
252
|
-
parameters?: Record<string, ParameterObject | ReferenceObject>;
|
|
253
|
-
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
254
|
-
requestBodies?: Record<string, RequestBodyObject | ReferenceObject>;
|
|
255
|
-
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
256
|
-
securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;
|
|
257
|
-
links?: Record<string, LinkObject | ReferenceObject>;
|
|
258
|
-
callbacks?: Record<string, Record<string, PathItemObject> | ReferenceObject>;
|
|
259
|
-
pathItems?: Record<string, PathItemObject | ReferenceObject>;
|
|
260
|
-
}
|
|
261
|
-
interface OpenAPIDocument {
|
|
262
|
-
openapi: "3.1.0";
|
|
263
|
-
info: OpenAPIInfoObject;
|
|
264
|
-
servers?: ServerObject[];
|
|
265
|
-
paths: PathsObject;
|
|
266
|
-
components?: ComponentsObject;
|
|
267
|
-
security?: SecurityRequirement[];
|
|
268
|
-
tags?: TagObject[];
|
|
269
|
-
externalDocs?: ExternalDocsObject;
|
|
270
|
-
jsonSchemaDialect?: string;
|
|
271
|
-
webhooks?: Record<string, PathItemObject | ReferenceObject>;
|
|
272
|
-
[key: `x-${string}`]: unknown;
|
|
273
|
-
}
|
|
274
|
-
interface OpenAPIGenerateOptions {
|
|
275
|
-
/** OpenAPI info object */
|
|
276
|
-
info: {
|
|
277
|
-
title: string;
|
|
278
|
-
version: string;
|
|
279
|
-
description?: string;
|
|
280
|
-
termsOfService?: string;
|
|
281
|
-
contact?: {
|
|
282
|
-
name?: string;
|
|
283
|
-
url?: string;
|
|
284
|
-
email?: string;
|
|
285
|
-
};
|
|
286
|
-
license?: {
|
|
287
|
-
name: string;
|
|
288
|
-
url?: string;
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
/** Server URLs */
|
|
292
|
-
servers?: Array<{
|
|
293
|
-
url: string;
|
|
294
|
-
description?: string;
|
|
295
|
-
}>;
|
|
296
|
-
/** Global security schemes */
|
|
297
|
-
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
298
|
-
/** Global security requirements */
|
|
299
|
-
security?: SecurityRequirement[];
|
|
300
|
-
/** External docs */
|
|
301
|
-
externalDocs?: {
|
|
302
|
-
url: string;
|
|
303
|
-
description?: string;
|
|
304
|
-
};
|
|
305
|
-
/** Custom x- extensions on the root document */
|
|
306
|
-
extensions?: Record<string, unknown>;
|
|
307
|
-
}
|
|
308
|
-
interface DiffEntry {
|
|
309
|
-
type: "added" | "removed" | "modified";
|
|
310
|
-
breaking: boolean;
|
|
311
|
-
path: string;
|
|
312
|
-
description: string;
|
|
313
|
-
before?: unknown;
|
|
314
|
-
after?: unknown;
|
|
315
|
-
}
|
|
316
|
-
interface DiffResult {
|
|
317
|
-
breaking: DiffEntry[];
|
|
318
|
-
nonBreaking: DiffEntry[];
|
|
319
|
-
/** Overall: true if any breaking changes exist */
|
|
320
|
-
hasBreakingChanges: boolean;
|
|
321
|
-
summary: {
|
|
322
|
-
added: number;
|
|
323
|
-
removed: number;
|
|
324
|
-
modified: number;
|
|
325
|
-
breaking: number;
|
|
326
|
-
nonBreaking: number;
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
interface ValidationError {
|
|
330
|
-
path: string;
|
|
331
|
-
message: string;
|
|
332
|
-
severity: "error" | "warning";
|
|
333
|
-
}
|
|
334
|
-
interface AuthConfig {
|
|
335
|
-
type: "bearer" | "basic" | "apikey" | "oauth2";
|
|
336
|
-
token?: string;
|
|
337
|
-
username?: string;
|
|
338
|
-
password?: string;
|
|
339
|
-
key?: string;
|
|
340
|
-
keyName?: string;
|
|
341
|
-
keyIn?: "header" | "query";
|
|
342
|
-
}
|
|
343
|
-
interface EndpointMetrics {
|
|
344
|
-
method: string;
|
|
345
|
-
path: string;
|
|
346
|
-
latency: {
|
|
347
|
-
p50: number;
|
|
348
|
-
p95: number;
|
|
349
|
-
p99: number;
|
|
350
|
-
avg: number;
|
|
351
|
-
};
|
|
352
|
-
throughput: {
|
|
353
|
-
rpm: number;
|
|
354
|
-
total: number;
|
|
355
|
-
};
|
|
356
|
-
errors: {
|
|
357
|
-
rate: number;
|
|
358
|
-
count: number;
|
|
359
|
-
lastError?: string;
|
|
360
|
-
};
|
|
361
|
-
availability: number;
|
|
362
|
-
lastUpdated: string;
|
|
363
|
-
}
|
|
364
|
-
interface WatchFnClient {
|
|
365
|
-
fetchMetrics(options?: {
|
|
366
|
-
timeRange?: string;
|
|
367
|
-
endpoints?: string[];
|
|
368
|
-
}): Promise<EndpointMetrics[]>;
|
|
369
|
-
}
|
|
370
|
-
interface RateLimitInfo {
|
|
371
|
-
endpoint: string;
|
|
372
|
-
method: string;
|
|
373
|
-
remaining: number;
|
|
374
|
-
limit: number;
|
|
375
|
-
resetAt: number;
|
|
376
|
-
blocked: boolean;
|
|
377
|
-
}
|
|
378
|
-
interface SecFnRateLimiter {
|
|
379
|
-
peek(endpoint: string, context?: Record<string, string>): Promise<RateLimitInfo | null>;
|
|
380
|
-
}
|
|
381
|
-
interface AuthFnClient {
|
|
382
|
-
baseUrl: string;
|
|
383
|
-
adminKey?: string;
|
|
384
|
-
}
|
|
385
|
-
interface LogFnClient {
|
|
386
|
-
info(eventType: string, payload?: unknown): void;
|
|
387
|
-
error(eventType: string, error: Error | string, payload?: unknown): void;
|
|
388
|
-
warn(eventType: string, payload?: unknown): void;
|
|
389
|
-
debug(eventType: string, payload?: unknown): void;
|
|
390
|
-
child(context: Record<string, unknown>): LogFnClient;
|
|
391
|
-
}
|
|
392
|
-
type SnippetTarget = "curl" | "fetch" | "axios" | "node-fetch" | "python-requests" | "python-httpx" | "go-http" | "ruby-net-http" | "php-curl" | "csharp-httpclient" | "java-okhttp";
|
|
393
|
-
interface SnippetOptions {
|
|
394
|
-
/** Target language/library */
|
|
395
|
-
target: SnippetTarget;
|
|
396
|
-
/** Include auth headers */
|
|
397
|
-
auth?: {
|
|
398
|
-
type: string;
|
|
399
|
-
token?: string;
|
|
400
|
-
key?: string;
|
|
401
|
-
};
|
|
402
|
-
/** Base URL */
|
|
403
|
-
baseUrl: string;
|
|
404
|
-
/** Indentation (default: 2 spaces) */
|
|
405
|
-
indent?: number;
|
|
406
|
-
}
|
|
407
|
-
interface MockServerOptions {
|
|
408
|
-
/** OpenAPI document */
|
|
409
|
-
spec: OpenAPIDocument;
|
|
410
|
-
/** Port (default: 4010) */
|
|
411
|
-
port?: number;
|
|
412
|
-
/** Generate responses from examples or schema (default: "schema") */
|
|
413
|
-
responseMode?: "examples" | "schema" | "random";
|
|
414
|
-
/** Validate incoming requests against schemas */
|
|
415
|
-
validateRequests?: boolean;
|
|
416
|
-
/** Delay responses by ms (simulates latency) */
|
|
417
|
-
delay?: number;
|
|
418
|
-
/** CORS configuration */
|
|
419
|
-
cors?: boolean | CorsOptions;
|
|
420
|
-
}
|
|
421
|
-
interface CorsOptions {
|
|
422
|
-
origin?: string | string[] | ((origin: string) => boolean);
|
|
423
|
-
methods?: HttpMethod[];
|
|
424
|
-
allowedHeaders?: string[];
|
|
425
|
-
exposedHeaders?: string[];
|
|
426
|
-
credentials?: boolean;
|
|
427
|
-
maxAge?: number;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
7
|
declare function introspectRouter(router: Router<unknown>, options?: IntrospectOptions): IntrospectedRoute[];
|
|
431
8
|
|
|
432
9
|
declare function apiSchema(descriptor: SchemaDescriptor): SchemaDescriptor;
|
|
@@ -539,6 +116,8 @@ interface WatchFnMiddlewareOptions {
|
|
|
539
116
|
fireAndForget?: boolean;
|
|
540
117
|
/** Suppress console warnings on errors (default: false) */
|
|
541
118
|
silent?: boolean;
|
|
119
|
+
/** Event POST timeout in ms (default: 2000) */
|
|
120
|
+
timeoutMs?: number;
|
|
542
121
|
}
|
|
543
122
|
/**
|
|
544
123
|
* Fetch endpoint metrics from a watchfn query API endpoint.
|
|
@@ -689,4 +268,4 @@ declare class ApifnTestAdapter extends BaseAdapter {
|
|
|
689
268
|
run(tests: TestCase[], options: RunOptions): Promise<TestResult[]>;
|
|
690
269
|
}
|
|
691
270
|
|
|
692
|
-
export { ApifnTestAdapter, type
|
|
271
|
+
export { ApifnTestAdapter, type CliLoggerOptions, type CreateWatchFnClientOptions, type DeduplicateSchemaInput, type DeduplicateSchemasResult, DiffEntry, type DiffReportJson, DiffResult, EndpointMetrics, type FetchEndpointMetricsOptions, type FromRouterOptions, IntrospectOptions, IntrospectedRoute, JsonSchema, type MintTestTokenOptions, type MintTestTokenResponse, OpenAPIDocument, OpenAPIGenerateOptions, RateLimitInfo, SchemaDescriptor, SchemaInput, type SchemaType, ValidationError, WatchFnClient, type WatchFnMiddlewareOptions, apiSchema, apifnWatchMiddleware, convertSchema, convertTypeBoxSchema, convertZodSchema, createAuthfnCollectionMiddleware, createCliLogger, createWatchFnClient, deduplicateSchemas, detectSchemaType, diffOpenAPI, fetchEndpointMetrics, fetchRateLimits, formatDiffAsJson, formatDiffAsText, fromRouter, generateOpenAPI, introspectRouter, logfnReporter, mintTestToken, parseOpenAPI, upconvertFrom3_0, validateOpenAPI };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var KNOWN_DESCRIPTOR_KEYS = [
|
|
|
14
14
|
"headers",
|
|
15
15
|
"security"
|
|
16
16
|
];
|
|
17
|
-
var PATH_PARAM_PATTERN = /:([A-Za-z0-9_]+)/g;
|
|
18
17
|
function isObject(value) {
|
|
19
18
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
19
|
}
|
|
@@ -47,10 +46,29 @@ function withBasePath(path2, basePath) {
|
|
|
47
46
|
}
|
|
48
47
|
function toOpenApiPath(path2) {
|
|
49
48
|
const params = [];
|
|
50
|
-
|
|
49
|
+
let openApiPath = "";
|
|
50
|
+
let index = 0;
|
|
51
|
+
while (index < path2.length) {
|
|
52
|
+
const char = path2[index];
|
|
53
|
+
if (char !== ":") {
|
|
54
|
+
openApiPath += char;
|
|
55
|
+
index += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
let end = index + 1;
|
|
59
|
+
while (end < path2.length && /[A-Za-z0-9_]/.test(path2[end])) {
|
|
60
|
+
end += 1;
|
|
61
|
+
}
|
|
62
|
+
if (end === index + 1) {
|
|
63
|
+
openApiPath += char;
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const param = path2.slice(index + 1, end);
|
|
51
68
|
params.push(param);
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
openApiPath += `{${param}}`;
|
|
70
|
+
index = end;
|
|
71
|
+
}
|
|
54
72
|
return { path: openApiPath, pathParams: params };
|
|
55
73
|
}
|
|
56
74
|
function pathParamsToDescriptors(pathParams) {
|
|
@@ -597,8 +615,6 @@ function upconvertNode(value) {
|
|
|
597
615
|
const merged = new Set(currentType);
|
|
598
616
|
merged.add("null");
|
|
599
617
|
output.type = Array.from(merged);
|
|
600
|
-
} else {
|
|
601
|
-
output.type = ["null"];
|
|
602
618
|
}
|
|
603
619
|
}
|
|
604
620
|
return output;
|
|
@@ -690,8 +706,19 @@ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch",
|
|
|
690
706
|
function isRef(obj) {
|
|
691
707
|
return typeof obj === "object" && obj !== null && "$ref" in obj;
|
|
692
708
|
}
|
|
693
|
-
function
|
|
694
|
-
|
|
709
|
+
function emitUnresolvedRef(opPath, location, ref, emit) {
|
|
710
|
+
emit({
|
|
711
|
+
type: "modified",
|
|
712
|
+
breaking: true,
|
|
713
|
+
path: `${opPath}.${location}`,
|
|
714
|
+
description: `Parameter reference '${ref}' in ${opPath} could not be resolved; diff coverage is incomplete`
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function resolveParam(p, opPath, location, emit) {
|
|
718
|
+
if (isRef(p)) {
|
|
719
|
+
emitUnresolvedRef(opPath, location, p.$ref, emit);
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
695
722
|
if (typeof p === "object" && p !== null && "name" in p && "in" in p) {
|
|
696
723
|
return p;
|
|
697
724
|
}
|
|
@@ -715,8 +742,8 @@ function isTypeNarrowing(before, after) {
|
|
|
715
742
|
return false;
|
|
716
743
|
}
|
|
717
744
|
function diffParameters(opPath, before, after, emit) {
|
|
718
|
-
const beforeParams = (before.parameters ?? []).map(resolveParam).filter((p) => p !== null);
|
|
719
|
-
const afterParams = (after.parameters ?? []).map(resolveParam).filter((p) => p !== null);
|
|
745
|
+
const beforeParams = (before.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
|
|
746
|
+
const afterParams = (after.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
|
|
720
747
|
const beforeMap = /* @__PURE__ */ new Map();
|
|
721
748
|
for (const p of beforeParams) {
|
|
722
749
|
beforeMap.set(`${p.in}:${p.name}`, p);
|
|
@@ -796,6 +823,16 @@ function diffRequestBody(opPath, before, after, emit) {
|
|
|
796
823
|
return;
|
|
797
824
|
}
|
|
798
825
|
if (!beforeBody || !afterBody) return;
|
|
826
|
+
if (!beforeBody.required && afterBody.required) {
|
|
827
|
+
emit({
|
|
828
|
+
type: "modified",
|
|
829
|
+
breaking: true,
|
|
830
|
+
path: `${opPath}.requestBody.required`,
|
|
831
|
+
description: `Request body became required in ${opPath}`,
|
|
832
|
+
before: false,
|
|
833
|
+
after: true
|
|
834
|
+
});
|
|
835
|
+
}
|
|
799
836
|
const beforeSchema = beforeBody.content?.["application/json"]?.schema ?? null;
|
|
800
837
|
const afterSchema = afterBody.content?.["application/json"]?.schema ?? null;
|
|
801
838
|
if (!beforeSchema || !afterSchema) return;
|
|
@@ -817,12 +854,12 @@ function diffObjectSchemaRequiredFields(opPath, schemaPath, before, after, emit)
|
|
|
817
854
|
const afterProps = after.properties ?? {};
|
|
818
855
|
const beforeProps = before.properties ?? {};
|
|
819
856
|
for (const field of afterRequired) {
|
|
820
|
-
if (!beforeRequired.has(field)
|
|
857
|
+
if (!beforeRequired.has(field)) {
|
|
821
858
|
emit({
|
|
822
859
|
type: "modified",
|
|
823
860
|
breaking: true,
|
|
824
861
|
path: `${opPath}.${schemaPath}.required`,
|
|
825
|
-
description: `New required field '${field}' added to request body in ${opPath}`
|
|
862
|
+
description: beforeProps[field] ? `Existing request body field '${field}' became required in ${opPath}` : `New required field '${field}' added to request body in ${opPath}`
|
|
826
863
|
});
|
|
827
864
|
}
|
|
828
865
|
}
|
|
@@ -920,11 +957,12 @@ function diffSecurity(opPath, before, after, emit) {
|
|
|
920
957
|
}
|
|
921
958
|
for (const key of beforeKeys) {
|
|
922
959
|
if (!afterKeys.has(key)) {
|
|
960
|
+
const removedAlternative = afterSec.length > 0;
|
|
923
961
|
emit({
|
|
924
962
|
type: "removed",
|
|
925
|
-
breaking:
|
|
963
|
+
breaking: removedAlternative,
|
|
926
964
|
path: `${opPath}.security`,
|
|
927
|
-
description: `Security requirement removed from ${opPath}`,
|
|
965
|
+
description: removedAlternative ? `Security requirement alternative removed from ${opPath} \u2014 breaking` : `Security requirement removed from ${opPath}`,
|
|
928
966
|
before: beforeSec,
|
|
929
967
|
after: afterSec
|
|
930
968
|
});
|
|
@@ -1200,7 +1238,8 @@ function apifnWatchMiddleware(options) {
|
|
|
1200
1238
|
baseUrl,
|
|
1201
1239
|
apiKey,
|
|
1202
1240
|
fireAndForget = true,
|
|
1203
|
-
silent = false
|
|
1241
|
+
silent = false,
|
|
1242
|
+
timeoutMs = 2e3
|
|
1204
1243
|
} = options;
|
|
1205
1244
|
const eventUrl = `${baseUrl.replace(/\/$/, "")}/api/events`;
|
|
1206
1245
|
const headers = {
|
|
@@ -1210,11 +1249,19 @@ function apifnWatchMiddleware(options) {
|
|
|
1210
1249
|
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
1211
1250
|
async function sendEvent(event) {
|
|
1212
1251
|
try {
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1252
|
+
const controller = new AbortController();
|
|
1253
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1254
|
+
let res;
|
|
1255
|
+
try {
|
|
1256
|
+
res = await fetch(eventUrl, {
|
|
1257
|
+
method: "POST",
|
|
1258
|
+
headers,
|
|
1259
|
+
body: JSON.stringify(event),
|
|
1260
|
+
signal: controller.signal
|
|
1261
|
+
});
|
|
1262
|
+
} finally {
|
|
1263
|
+
clearTimeout(timer);
|
|
1264
|
+
}
|
|
1218
1265
|
if (!res.ok && !silent) {
|
|
1219
1266
|
console.warn(`[apifn/watchfn] Event POST returned HTTP ${res.status}`);
|
|
1220
1267
|
}
|
|
@@ -1402,7 +1449,7 @@ var ApifnTestAdapter = class extends BaseAdapter {
|
|
|
1402
1449
|
async discover(patterns) {
|
|
1403
1450
|
let glob;
|
|
1404
1451
|
try {
|
|
1405
|
-
const fg = await import("./out-
|
|
1452
|
+
const fg = await import("./out-X7U3YPXW.js");
|
|
1406
1453
|
glob = fg.default ?? fg;
|
|
1407
1454
|
} catch {
|
|
1408
1455
|
console.warn("[apifn/testfn] fast-glob not found, using basic fs discovery");
|