@apifn/core 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,434 +1,9 @@
1
+ import { IntrospectOptions, IntrospectedRoute, SchemaDescriptor, SchemaInput, JsonSchema, OpenAPIGenerateOptions, OpenAPIDocument, ValidationError, DiffResult, DiffEntry, WatchFnClient, EndpointMetrics, AuthFnClient, SecFnRateLimiter, RateLimitInfo, LogFnClient } from './types.cjs';
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.cjs';
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
- /** Maximum accepted request body size in bytes (default: 10 MiB) */
419
- maxRequestBodyBytes?: number;
420
- /** CORS configuration */
421
- cors?: boolean | CorsOptions;
422
- }
423
- interface CorsOptions {
424
- origin?: string | string[] | ((origin: string) => boolean);
425
- methods?: HttpMethod[];
426
- allowedHeaders?: string[];
427
- exposedHeaders?: string[];
428
- credentials?: boolean;
429
- maxAge?: number;
430
- }
431
-
432
7
  declare function introspectRouter(router: Router<unknown>, options?: IntrospectOptions): IntrospectedRoute[];
433
8
 
434
9
  declare function apiSchema(descriptor: SchemaDescriptor): SchemaDescriptor;
@@ -693,4 +268,4 @@ declare class ApifnTestAdapter extends BaseAdapter {
693
268
  run(tests: TestCase[], options: RunOptions): Promise<TestResult[]>;
694
269
  }
695
270
 
696
- export { ApifnTestAdapter, type AuthConfig, type CliLoggerOptions, type ComponentsObject, type CorsOptions, type CreateWatchFnClientOptions, type DeduplicateSchemaInput, type DeduplicateSchemasResult, type DiffEntry, type DiffReportJson, type DiffResult, type EncodingObject, type EndpointMetrics, type ExampleObject, type ExternalDocsObject, type FetchEndpointMetricsOptions, type FromRouterOptions, type HeaderObject, type HttpMethod, type IntrospectOptions, type IntrospectedRoute, type JsonSchema, type LinkObject, type MediaTypeObject, type MintTestTokenOptions, type MintTestTokenResponse, type MockServerOptions, type OAuthFlowObject, type OAuthFlowsObject, type OpenAPIDocument, type OpenAPIGenerateOptions, type OpenAPIInfoObject, type OperationObject, type ParameterDescriptor, type ParameterObject, type PathItemObject, type PathsObject, type RateLimitInfo, type ReferenceObject, type RequestBodyDescriptor, type RequestBodyObject, type ResponseDescriptor, type ResponseObject, type SchemaDescriptor, type SchemaDescriptorResponse, type SchemaInput, type SchemaObject, type SchemaType, type SecurityRequirement, type SecuritySchemeObject, type ServerObject, type SnippetOptions, type SnippetTarget, type TagObject, type ValidationError, type 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 };
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 };