@lucaapp/service-utils 5.29.2 → 5.30.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.
@@ -7,6 +7,12 @@ 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;
10
16
  openApiVersion?: OpenApiVersion;
11
17
  apiVersion?: string;
12
18
  apiTitle?: string;
@@ -19,6 +25,7 @@ type ApiConstructorOptions = {
19
25
  type ApiChildOptions = {
20
26
  prefixPath?: string;
21
27
  tags?: string[];
28
+ hidden?: boolean;
22
29
  };
23
30
  export declare class Api {
24
31
  router: Router;
@@ -31,6 +38,7 @@ export declare class Api {
31
38
  private rootPrefixPath;
32
39
  debug: boolean;
33
40
  tags: string[];
41
+ private hidden;
34
42
  constructor(options?: ApiConstructorOptions);
35
43
  child(options: ApiChildOptions): Api;
36
44
  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;
@@ -30,6 +30,7 @@ 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;
33
34
  this.router.use(body_parser_1.default.json({ verify: rawBodySaver, limit: '2mb' }));
34
35
  }
35
36
  child(options) {
@@ -39,29 +40,31 @@ class Api {
39
40
  tags: [...this.tags, ...(options.tags || [])],
40
41
  registry: this.registry,
41
42
  router: this.router,
43
+ // Once hidden, always hidden: a child cannot re-expose its parent's tree.
44
+ hidden: this.hidden || options.hidden || false,
42
45
  });
43
46
  child.rootPrefixPath = this.rootPrefixPath;
44
47
  return child;
45
48
  }
46
49
  get(path, summary, options, handler) {
47
50
  (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);
51
+ (0, openapi_1.registerEndpoint)(this.registry, 'get', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
49
52
  }
50
53
  post(path, summary, options, handler) {
51
54
  (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);
55
+ (0, openapi_1.registerEndpoint)(this.registry, 'post', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
53
56
  }
54
57
  patch(path, summary, options, handler) {
55
58
  (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);
59
+ (0, openapi_1.registerEndpoint)(this.registry, 'patch', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
57
60
  }
58
61
  put(path, summary, options, handler) {
59
62
  (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);
63
+ (0, openapi_1.registerEndpoint)(this.registry, 'put', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
61
64
  }
62
65
  delete(path, summary, options, handler) {
63
66
  (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);
67
+ (0, openapi_1.registerEndpoint)(this.registry, 'delete', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
65
68
  }
66
69
  generateOpenAPISpec() {
67
70
  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) => void;
29
29
  export {};
@@ -227,7 +227,13 @@ 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) => {
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
+ if (hiddenApi || options.hidden) {
235
+ return;
236
+ }
231
237
  let bodySchema = options.schemas?.body || undefined;
232
238
  let paramsSchema = options.schemas?.params || undefined;
233
239
  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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucaapp/service-utils",
3
- "version": "5.29.2",
3
+ "version": "5.30.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [