@lucaapp/service-utils 5.29.2 → 5.31.0
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/lib/api/api.d.ts
CHANGED
|
@@ -7,6 +7,23 @@ import { ZodObjectSchemaOrUndefined } from './types/utils';
|
|
|
7
7
|
type OpenApiVersion = '3.0.0' | '3.0.1' | '3.0.2' | '3.0.3' | '3.1.0';
|
|
8
8
|
type ApiConstructorOptions = {
|
|
9
9
|
prefixPath?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Keep every endpoint registered on this Api out of the generated OpenAPI
|
|
12
|
+
* spec. Inherited by children and never turned off again, so a hidden branch
|
|
13
|
+
* stays hidden. Routing is unaffected; this only controls documentation.
|
|
14
|
+
*/
|
|
15
|
+
hidden?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Paths kept out of the generated OpenAPI spec, matched against the full
|
|
18
|
+
* registered path including the prefix. A string must match exactly; a
|
|
19
|
+
* RegExp is tested against it. Inherited by children.
|
|
20
|
+
*
|
|
21
|
+
* This is the central place to keep routes undocumented, so the decision
|
|
22
|
+
* lives in one list next to the Api rather than spread across the route
|
|
23
|
+
* files it applies to. `hidden` on a single endpoint does the same thing at
|
|
24
|
+
* the definition site; prefer this list when the routes share a reason.
|
|
25
|
+
*/
|
|
26
|
+
excludeFromSpec?: ReadonlyArray<string | RegExp>;
|
|
10
27
|
openApiVersion?: OpenApiVersion;
|
|
11
28
|
apiVersion?: string;
|
|
12
29
|
apiTitle?: string;
|
|
@@ -19,6 +36,7 @@ type ApiConstructorOptions = {
|
|
|
19
36
|
type ApiChildOptions = {
|
|
20
37
|
prefixPath?: string;
|
|
21
38
|
tags?: string[];
|
|
39
|
+
hidden?: boolean;
|
|
22
40
|
};
|
|
23
41
|
export declare class Api {
|
|
24
42
|
router: Router;
|
|
@@ -31,6 +49,8 @@ export declare class Api {
|
|
|
31
49
|
private rootPrefixPath;
|
|
32
50
|
debug: boolean;
|
|
33
51
|
tags: string[];
|
|
52
|
+
private hidden;
|
|
53
|
+
private excludeFromSpec;
|
|
34
54
|
constructor(options?: ApiConstructorOptions);
|
|
35
55
|
child(options: ApiChildOptions): Api;
|
|
36
56
|
get<TResponseSchemas extends ReadonlyArray<EndpointResponseSchema>, TRequestBodySchema extends ZodObjectSchemaOrUndefined = undefined, TRequestParamsSchema extends ZodObjectSchemaOrUndefined = undefined, TRequestQuerySchema extends ZodObjectSchemaOrUndefined = undefined, TRequestHeadersSchema extends ZodObjectSchemaOrUndefined = undefined, TMiddlewares extends ReadonlyArray<Middleware<any, any, any, any, any, any>> | undefined = undefined>(path: string, summary: string, options: EndpointOptions<TResponseSchemas, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares>, handler: EndpointHandler<TResponseSchemas, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares>): void;
|
package/dist/lib/api/api.js
CHANGED
|
@@ -30,6 +30,8 @@ class Api {
|
|
|
30
30
|
this.apiDescription = options.apiDescription || '';
|
|
31
31
|
this.debug = options.debug || false;
|
|
32
32
|
this.tags = options.tags || [];
|
|
33
|
+
this.hidden = options.hidden || false;
|
|
34
|
+
this.excludeFromSpec = options.excludeFromSpec || [];
|
|
33
35
|
this.router.use(body_parser_1.default.json({ verify: rawBodySaver, limit: '2mb' }));
|
|
34
36
|
}
|
|
35
37
|
child(options) {
|
|
@@ -39,29 +41,32 @@ class Api {
|
|
|
39
41
|
tags: [...this.tags, ...(options.tags || [])],
|
|
40
42
|
registry: this.registry,
|
|
41
43
|
router: this.router,
|
|
44
|
+
// Once hidden, always hidden: a child cannot re-expose its parent's tree.
|
|
45
|
+
hidden: this.hidden || options.hidden || false,
|
|
46
|
+
excludeFromSpec: this.excludeFromSpec,
|
|
42
47
|
});
|
|
43
48
|
child.rootPrefixPath = this.rootPrefixPath;
|
|
44
49
|
return child;
|
|
45
50
|
}
|
|
46
51
|
get(path, summary, options, handler) {
|
|
47
52
|
(0, endpoint_1.mountEndpoint)(this.router, 'get', path, options, handler, this.debug);
|
|
48
|
-
(0, openapi_1.registerEndpoint)(this.registry, 'get', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug);
|
|
53
|
+
(0, openapi_1.registerEndpoint)(this.registry, 'get', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
|
|
49
54
|
}
|
|
50
55
|
post(path, summary, options, handler) {
|
|
51
56
|
(0, endpoint_1.mountEndpoint)(this.router, 'post', path, options, handler, this.debug);
|
|
52
|
-
(0, openapi_1.registerEndpoint)(this.registry, 'post', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug);
|
|
57
|
+
(0, openapi_1.registerEndpoint)(this.registry, 'post', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
|
|
53
58
|
}
|
|
54
59
|
patch(path, summary, options, handler) {
|
|
55
60
|
(0, endpoint_1.mountEndpoint)(this.router, 'patch', path, options, handler, this.debug);
|
|
56
|
-
(0, openapi_1.registerEndpoint)(this.registry, 'patch', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug);
|
|
61
|
+
(0, openapi_1.registerEndpoint)(this.registry, 'patch', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
|
|
57
62
|
}
|
|
58
63
|
put(path, summary, options, handler) {
|
|
59
64
|
(0, endpoint_1.mountEndpoint)(this.router, 'put', path, options, handler, this.debug);
|
|
60
|
-
(0, openapi_1.registerEndpoint)(this.registry, 'put', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug);
|
|
65
|
+
(0, openapi_1.registerEndpoint)(this.registry, 'put', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
|
|
61
66
|
}
|
|
62
67
|
delete(path, summary, options, handler) {
|
|
63
68
|
(0, endpoint_1.mountEndpoint)(this.router, 'delete', path, options, handler, this.debug);
|
|
64
|
-
(0, openapi_1.registerEndpoint)(this.registry, 'delete', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug);
|
|
69
|
+
(0, openapi_1.registerEndpoint)(this.registry, 'delete', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
|
|
65
70
|
}
|
|
66
71
|
generateOpenAPISpec() {
|
|
67
72
|
let generator;
|
|
@@ -25,5 +25,5 @@ export declare const hoistCombinatorRequiredFields: (spec: {
|
|
|
25
25
|
schemas?: Record<string, unknown>;
|
|
26
26
|
};
|
|
27
27
|
}) => void;
|
|
28
|
-
export declare const registerEndpoint: (registry: OpenAPIRegistry, method: HttpMethod, prefixPath: string, rootPrefixPath: string, path: string, summary: string, options: EndpointOptions<any, any, any, any, any, any>, tags: string[], debug: boolean) => void;
|
|
28
|
+
export declare const registerEndpoint: (registry: OpenAPIRegistry, method: HttpMethod, prefixPath: string, rootPrefixPath: string, path: string, summary: string, options: EndpointOptions<any, any, any, any, any, any>, tags: string[], debug: boolean, hiddenApi?: boolean, excludeFromSpec?: ReadonlyArray<string | RegExp>) => void;
|
|
29
29
|
export {};
|
package/dist/lib/api/openapi.js
CHANGED
|
@@ -227,7 +227,18 @@ const hoistCombinatorRequiredFields = (spec) => {
|
|
|
227
227
|
exports.hoistCombinatorRequiredFields = hoistCombinatorRequiredFields;
|
|
228
228
|
const registerEndpoint = (registry, method, prefixPath, rootPrefixPath, path, summary,
|
|
229
229
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
-
options, tags, debug) => {
|
|
230
|
+
options, tags, debug, hiddenApi = false, excludeFromSpec = []) => {
|
|
231
|
+
// Hidden endpoints are never registered, so they leave no path, no
|
|
232
|
+
// operationId and no security behind. Checked before any schema work: there
|
|
233
|
+
// is nothing to build for an operation that will not be published.
|
|
234
|
+
//
|
|
235
|
+
// The exclusion list is matched against the same path string the spec would
|
|
236
|
+
// have used, so an entry can be copied straight out of a generated spec.
|
|
237
|
+
const specPath = mapExpressParamsToOpenAPIParams(prefixPath + path);
|
|
238
|
+
const excluded = excludeFromSpec.some(pattern => typeof pattern === 'string' ? pattern === specPath : pattern.test(specPath));
|
|
239
|
+
if (hiddenApi || options.hidden || excluded) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
231
242
|
let bodySchema = options.schemas?.body || undefined;
|
|
232
243
|
let paramsSchema = options.schemas?.params || undefined;
|
|
233
244
|
let querySchema = options.schemas?.query || undefined;
|
|
@@ -21,4 +21,11 @@ export type EndpointOptions<TResponseSchemas extends ReadonlyArray<EndpointRespo
|
|
|
21
21
|
responses: TResponseSchemas;
|
|
22
22
|
errors?: Record<string, number>;
|
|
23
23
|
operationId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Keep this endpoint out of the generated OpenAPI spec. For routes that only
|
|
26
|
+
* a known caller may use -- provider webhooks, service-to-service endpoints,
|
|
27
|
+
* job triggers -- where publishing the shape invites traffic that has no
|
|
28
|
+
* business arriving. Routing is unaffected.
|
|
29
|
+
*/
|
|
30
|
+
hidden?: boolean;
|
|
24
31
|
};
|