@anvil-di/bellows 0.0.3 → 0.0.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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2026 typescript-di contributors
189
+ Copyright 2026 Mike Sulak
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -0,0 +1,28 @@
1
+ import type { Request } from "express";
2
+ export interface AuthnResult<U = unknown> {
3
+ identified: boolean;
4
+ user?: U;
5
+ }
6
+ /**
7
+ * `Scheme` is never evaluated at runtime — it's read directly off the
8
+ * `implements AuthnService<User, "bearerAuth">` clause by anvil-bellows'
9
+ * codegen to populate the OpenAPI `security` requirement for routes that
10
+ * declare this service via `@Authn(...)`.
11
+ */
12
+ export interface AuthnService<U = unknown, Scheme extends string = never> {
13
+ identify(req: Request): AuthnResult<U> | Promise<AuthnResult<U>>;
14
+ }
15
+ export type AuthzDecision = "allow" | "deny" | "next";
16
+ export interface AuthzService {
17
+ authorize(req: Request, user: unknown): AuthzDecision | Promise<AuthzDecision>;
18
+ }
19
+ /**
20
+ * Marks a handler parameter for injection of the identified user
21
+ * (`res.locals.user`, set by the route's `@Authn` cascade). `T` is a pure
22
+ * type-level marker — anvil-bellows' codegen statically verifies `T`
23
+ * identity-matches the `U` declared by every `@Authn` service on the route
24
+ * (`implements AuthnService<U, Scheme>`), rejecting the route at build time
25
+ * if they disagree or can't be resolved. At runtime this is just `T`.
26
+ */
27
+ export type AuthnUser<T> = T;
28
+ //# sourceMappingURL=authz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authz.d.ts","sourceRoot":"","sources":["../src/authz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,SAAS,MAAM,GAAG,KAAK;IACtE,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAClE;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAChF;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC"}
package/dist/authz.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authz.js","sourceRoot":"","sources":["../src/authz.ts"],"names":[],"mappings":""}
@@ -1,16 +1,31 @@
1
1
  import type { RequestHandler } from "express";
2
+ import type { AuthnService, AuthzService } from "./authz.js";
2
3
  export type ExpressMiddleware = RequestHandler;
4
+ type AuthnServiceClass = new (...args: never[]) => AuthnService<any, any>;
5
+ type AuthzServiceClass = new (...args: never[]) => AuthzService;
3
6
  export declare function Controller(_path: string): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
4
7
  export declare function Get(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
5
8
  export declare function Post(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
6
9
  export declare function Put(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
7
10
  export declare function Delete(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
8
11
  export declare function Patch(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
12
+ /**
13
+ * Marks a route as a Server-Sent Events stream (`text/event-stream`) rather
14
+ * than a buffered JSON response. Registered as a `GET` route. The handler
15
+ * must return `void`/`Promise<void>` and manages the connection itself via
16
+ * an injected `SseStream` param — see `@anvil-di/bellows`'s `SseStream`.
17
+ */
18
+ export declare function Sse(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
9
19
  export declare function Middleware(...fns: ExpressMiddleware[]): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
10
20
  export declare function Middleware(...fns: ExpressMiddleware[]): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
11
21
  export declare function Tag(_name: string): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
12
22
  export declare function Returns(_status: number, _schema?: unknown): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
13
23
  export declare function Security(scheme: string): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
14
24
  export declare function Security(scheme: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
25
+ export declare function Authn(...services: AuthnServiceClass[]): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
26
+ export declare function Authn(...services: AuthnServiceClass[]): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
27
+ export declare function Authz(...services: AuthzServiceClass[]): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
28
+ export declare function Authz(...services: AuthzServiceClass[]): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
15
29
  export declare function Deprecated(_reason?: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
30
+ export {};
16
31
  //# sourceMappingURL=decorators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAE/C,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GACZ,CAAC,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACtD,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAC1B,CAAC,CAEL;A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AS,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACtD,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAC1B,CAAC,CAAC;AAEP,wBAAgB,KAAK,CACnB,GAAG,QAAQ,EAAE,iBAAiB,EAAE,GAC/B,CAAC,IAAI,EAAE,IAAI,SAAS,SAAS,OAAO,EAAE,EAAE,MAAM,EAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAC7C,GAAG,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,KAC1E,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;AAM3C,wBAAgB,UAAU,CACxB,OAAO,CAAC,EAAE,MAAM,GACf,CAAC,IAAI,EAAE,IAAI,SAAS,SAAS,OAAO,EAAE,EAAE,MAAM,EAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAC7C,GAAG,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,KAC1E,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAEzC"}
@@ -16,6 +16,15 @@ export function Delete(_path) {
16
16
  export function Patch(_path) {
17
17
  return (target, _ctx) => target;
18
18
  }
19
+ /**
20
+ * Marks a route as a Server-Sent Events stream (`text/event-stream`) rather
21
+ * than a buffered JSON response. Registered as a `GET` route. The handler
22
+ * must return `void`/`Promise<void>` and manages the connection itself via
23
+ * an injected `SseStream` param — see `@anvil-di/bellows`'s `SseStream`.
24
+ */
25
+ export function Sse(_path) {
26
+ return (target, _ctx) => target;
27
+ }
19
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
29
  export function Middleware(..._fns) {
21
30
  return (target) => target;
@@ -30,6 +39,14 @@ export function Returns(_status, _schema) {
30
39
  export function Security(_scheme) {
31
40
  return (target) => target;
32
41
  }
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ export function Authn(..._services) {
44
+ return (target) => target;
45
+ }
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ export function Authz(..._services) {
48
+ return (target) => target;
49
+ }
33
50
  export function Deprecated(_reason) {
34
51
  return (target, _ctx) => target;
35
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,UAAU,CACxB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,MAAM,CACpB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAgBD,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,GAAG,IAAyB;IACrD,OAAO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AI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CACjB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAgBD,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,GAAG,IAAyB;IACrD,OAAO,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,OAAe,EACf,OAAiB;IAKjB,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAgBD,8DAA8D;AAC9D,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC;AACrC,CAAC;AAgBD,8DAA8D;AAC9D,MAAM,UAAU,KAAK,CAAC,GAAG,SAA8B;IACrD,OAAO,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC;AACrC,CAAC;AAgBD,8DAA8D;AAC9D,MAAM,UAAU,KAAK,CAAC,GAAG,SAA8B;IACrD,OAAO,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,OAAgB;IAKhB,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC"}
@@ -0,0 +1,95 @@
1
+ import type { NextFunction, Request, Response } from "express";
2
+ /**
3
+ * HTTP error hierarchy for bellows controllers.
4
+ *
5
+ * bellows-generated route handlers do not catch exceptions, and Express 5
6
+ * forwards rejected promises from async handlers to the error middleware.
7
+ * So controller methods signal non-2xx outcomes by throwing one of these,
8
+ * and `errorHandler` (registered last on the app) maps them to a response.
9
+ */
10
+ export declare class HttpError extends Error {
11
+ readonly status: number;
12
+ readonly error: string;
13
+ constructor(status: number, error: string, message?: string);
14
+ body(): Record<string, unknown>;
15
+ }
16
+ export declare class BadRequestError extends HttpError {
17
+ constructor(message?: string);
18
+ }
19
+ export declare class UnauthorizedError extends HttpError {
20
+ constructor(message?: string);
21
+ }
22
+ export declare class ForbiddenError extends HttpError {
23
+ constructor(message?: string);
24
+ }
25
+ export declare class NotFoundError extends HttpError {
26
+ constructor(message?: string);
27
+ }
28
+ export declare class MethodNotAllowedError extends HttpError {
29
+ constructor(message?: string);
30
+ }
31
+ export declare class NotAcceptableError extends HttpError {
32
+ constructor(message?: string);
33
+ }
34
+ export declare class RequestTimeoutError extends HttpError {
35
+ constructor(message?: string);
36
+ }
37
+ export declare class ConflictError extends HttpError {
38
+ constructor(message?: string);
39
+ }
40
+ export declare class GoneError extends HttpError {
41
+ constructor(message?: string);
42
+ }
43
+ export declare class PreconditionFailedError extends HttpError {
44
+ constructor(message?: string);
45
+ }
46
+ export declare class PayloadTooLargeError extends HttpError {
47
+ constructor(message?: string);
48
+ }
49
+ export declare class UnsupportedMediaTypeError extends HttpError {
50
+ constructor(message?: string);
51
+ }
52
+ export declare class UnprocessableEntityError extends HttpError {
53
+ constructor(message?: string);
54
+ }
55
+ export declare class TooManyRequestsError extends HttpError {
56
+ constructor(message?: string);
57
+ }
58
+ export declare class InternalServerError extends HttpError {
59
+ constructor(message?: string);
60
+ }
61
+ export declare class NotImplementedError extends HttpError {
62
+ constructor(message?: string);
63
+ }
64
+ export declare class BadGatewayError extends HttpError {
65
+ constructor(message?: string);
66
+ }
67
+ export declare class ServiceUnavailableError extends HttpError {
68
+ constructor(message?: string);
69
+ }
70
+ export declare class GatewayTimeoutError extends HttpError {
71
+ constructor(message?: string);
72
+ }
73
+ /**
74
+ * Minimal structural type for a pino-style logger. `errorHandler` looks for
75
+ * `req.log` (as attached by e.g. `pino-http`) but does not depend on pino —
76
+ * anything satisfying this shape works, and unhandled errors are still
77
+ * caught if `req.log` is absent.
78
+ */
79
+ export interface RequestLogger {
80
+ error(obj: Record<string, unknown>, msg?: string): void;
81
+ }
82
+ export interface RequestWithLogger extends Request {
83
+ log?: RequestLogger;
84
+ }
85
+ /**
86
+ * Express error-handling middleware. Maps `HttpError` subclasses to their
87
+ * status and body. Falls back to 500 for anything unexpected, logging the
88
+ * full error via `req.log` (if present) while returning only a generic
89
+ * message to the caller — internal error text should never be echoed back,
90
+ * since it may embed request data the caller isn't entitled to see.
91
+ *
92
+ * Must be registered after all routes.
93
+ */
94
+ export declare function errorHandler(err: unknown, req: Request, res: Response, _next: NextFunction): void;
95
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAEhC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM;gBADb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,MAAM;IAMlB,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAKhC;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,qBAAa,qBAAsB,SAAQ,SAAS;gBACtC,OAAO,CAAC,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GAAG,CAAC,EAAE,aAAa,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,YAAY,GAClB,IAAI,CAgBN"}
package/dist/errors.js ADDED
@@ -0,0 +1,143 @@
1
+ /**
2
+ * HTTP error hierarchy for bellows controllers.
3
+ *
4
+ * bellows-generated route handlers do not catch exceptions, and Express 5
5
+ * forwards rejected promises from async handlers to the error middleware.
6
+ * So controller methods signal non-2xx outcomes by throwing one of these,
7
+ * and `errorHandler` (registered last on the app) maps them to a response.
8
+ */
9
+ export class HttpError extends Error {
10
+ status;
11
+ error;
12
+ constructor(status, error, message) {
13
+ super(message ?? error);
14
+ this.status = status;
15
+ this.error = error;
16
+ this.name = new.target.name;
17
+ }
18
+ body() {
19
+ return this.message && this.message !== this.error
20
+ ? { error: this.error, message: this.message }
21
+ : { error: this.error };
22
+ }
23
+ }
24
+ export class BadRequestError extends HttpError {
25
+ constructor(message) {
26
+ super(400, "Bad Request", message);
27
+ }
28
+ }
29
+ export class UnauthorizedError extends HttpError {
30
+ constructor(message) {
31
+ super(401, "Unauthorized", message);
32
+ }
33
+ }
34
+ export class ForbiddenError extends HttpError {
35
+ constructor(message) {
36
+ super(403, "Forbidden", message);
37
+ }
38
+ }
39
+ export class NotFoundError extends HttpError {
40
+ constructor(message) {
41
+ super(404, "Not Found", message);
42
+ }
43
+ }
44
+ export class MethodNotAllowedError extends HttpError {
45
+ constructor(message) {
46
+ super(405, "Method Not Allowed", message);
47
+ }
48
+ }
49
+ export class NotAcceptableError extends HttpError {
50
+ constructor(message) {
51
+ super(406, "Not Acceptable", message);
52
+ }
53
+ }
54
+ export class RequestTimeoutError extends HttpError {
55
+ constructor(message) {
56
+ super(408, "Request Timeout", message);
57
+ }
58
+ }
59
+ export class ConflictError extends HttpError {
60
+ constructor(message) {
61
+ super(409, "Conflict", message);
62
+ }
63
+ }
64
+ export class GoneError extends HttpError {
65
+ constructor(message) {
66
+ super(410, "Gone", message);
67
+ }
68
+ }
69
+ export class PreconditionFailedError extends HttpError {
70
+ constructor(message) {
71
+ super(412, "Precondition Failed", message);
72
+ }
73
+ }
74
+ export class PayloadTooLargeError extends HttpError {
75
+ constructor(message) {
76
+ super(413, "Payload Too Large", message);
77
+ }
78
+ }
79
+ export class UnsupportedMediaTypeError extends HttpError {
80
+ constructor(message) {
81
+ super(415, "Unsupported Media Type", message);
82
+ }
83
+ }
84
+ export class UnprocessableEntityError extends HttpError {
85
+ constructor(message) {
86
+ super(422, "Unprocessable Entity", message);
87
+ }
88
+ }
89
+ export class TooManyRequestsError extends HttpError {
90
+ constructor(message) {
91
+ super(429, "Too Many Requests", message);
92
+ }
93
+ }
94
+ export class InternalServerError extends HttpError {
95
+ constructor(message) {
96
+ super(500, "Internal Server Error", message);
97
+ }
98
+ }
99
+ export class NotImplementedError extends HttpError {
100
+ constructor(message) {
101
+ super(501, "Not Implemented", message);
102
+ }
103
+ }
104
+ export class BadGatewayError extends HttpError {
105
+ constructor(message) {
106
+ super(502, "Bad Gateway", message);
107
+ }
108
+ }
109
+ export class ServiceUnavailableError extends HttpError {
110
+ constructor(message) {
111
+ super(503, "Service Unavailable", message);
112
+ }
113
+ }
114
+ export class GatewayTimeoutError extends HttpError {
115
+ constructor(message) {
116
+ super(504, "Gateway Timeout", message);
117
+ }
118
+ }
119
+ /**
120
+ * Express error-handling middleware. Maps `HttpError` subclasses to their
121
+ * status and body. Falls back to 500 for anything unexpected, logging the
122
+ * full error via `req.log` (if present) while returning only a generic
123
+ * message to the caller — internal error text should never be echoed back,
124
+ * since it may embed request data the caller isn't entitled to see.
125
+ *
126
+ * Must be registered after all routes.
127
+ */
128
+ export function errorHandler(err, req, res, _next) {
129
+ // `_next` is required so Express recognizes this as error-handling middleware.
130
+ void _next;
131
+ if (res.headersSent) {
132
+ // Response already streaming (e.g. SSE) — let Express close the socket.
133
+ res.end();
134
+ return;
135
+ }
136
+ if (err instanceof HttpError) {
137
+ res.status(err.status).json(err.body());
138
+ return;
139
+ }
140
+ req.log?.error({ err }, "Unhandled error");
141
+ res.status(500).json({ error: "Internal Server Error", message: "Internal server error" });
142
+ }
143
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEvB;IACA;IAFX,YACW,MAAc,EACd,KAAa,EACtB,OAAgB;QAEhB,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;QAJf,WAAM,GAAN,MAAM,CAAQ;QACd,UAAK,GAAL,KAAK,CAAQ;QAItB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK;YAChD,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;YAC9C,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,OAAgB;QAC1B,KAAK,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,OAAgB;QAC1B,KAAK,CAAC,GAAG,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC3C,YAAY,OAAgB;QAC1B,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACnC,CA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C;IAED,IAAI,GAAG,YAAY,SAAS,EAAE,CAAC;QAC7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACxC,OAAO;IACT,CAAC;IAEA,GAAyB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAC;IAClE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAC7F,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,4 +2,7 @@ export * from "./decorators.js";
2
2
  export * from "./schema.js";
3
3
  export * from "./routes.js";
4
4
  export * from "./hook.js";
5
+ export * from "./authz.js";
6
+ export * from "./errors.js";
7
+ export * from "./sse.js";
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -2,4 +2,7 @@ export * from "./decorators.js";
2
2
  export * from "./schema.js";
3
3
  export * from "./routes.js";
4
4
  export * from "./hook.js";
5
+ export * from "./authz.js";
6
+ export * from "./errors.js";
7
+ export * from "./sse.js";
5
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/dist/routes.d.ts CHANGED
@@ -1,9 +1,75 @@
1
- import { Router, type Request, type Response } from "express";
1
+ import { Router, type ErrorRequestHandler, type Request, type RequestHandler, type Response } from "express";
2
+ import type { AuthnService, AuthzService } from "./authz.js";
3
+ declare global {
4
+ namespace Express {
5
+ interface Request {
6
+ /** Raw request body bytes, captured by the body parser `bellowsRoutes`
7
+ * mounts for any route declaring a `RawBody` param. */
8
+ rawBody?: Buffer;
9
+ }
10
+ }
11
+ }
2
12
  export interface RouteDefinition {
3
13
  method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
4
14
  path: string;
15
+ /**
16
+ * Which body parser to mount for this route, derived by codegen from its
17
+ * `Body<S>`/`FormBody<S>`/`RawBody`/two-arg `Body<S, C>` params: `"json"`
18
+ * or `"urlencoded"` populate `req.body` via Express's built-in parsers,
19
+ * `"raw"` leaves `req.body` as the raw `Buffer` (no parsed param declared
20
+ * alongside `RawBody`), and the `{ kind: "codec", ... }` form — from
21
+ * `Body<S, C>` — mounts `express.raw()` scoped to `contentType` and
22
+ * replaces `req.body` with `decode()`'s result before the handler's
23
+ * `S.safeParse(req.body)` runs. All variants also capture the exact wire
24
+ * bytes into `req.rawBody`. Absent when the route declares none of those
25
+ * params — unaffected, as before.
26
+ */
27
+ bodyParser?: "json" | "urlencoded" | "raw" | {
28
+ kind: "codec";
29
+ contentType: string;
30
+ decode: (raw: Buffer) => unknown;
31
+ };
32
+ /**
33
+ * Ordered authentication cascade from `@Authn(...)` decorators (class-level
34
+ * first, then method-level). The first service whose `identify()` returns
35
+ * `identified: true` wins and its `user` becomes `res.locals.user`. When
36
+ * this is non-empty and none identify the requester, the route fails
37
+ * closed with 401 — undeclared (empty/absent) means no authn check runs.
38
+ */
39
+ authn?: AuthnService[];
40
+ /**
41
+ * Ordered authorization cascade from `@Authz(...)` decorators (class-level
42
+ * first, then method-level), run only after authn succeeds (or when no
43
+ * `authn` is declared). The first non-`"next"` decision wins. When this is
44
+ * non-empty and every service returns `"next"` (or one returns `"deny"`),
45
+ * the route fails closed with 403 — undeclared means no authz check runs.
46
+ */
47
+ authz?: AuthzService[];
48
+ /**
49
+ * Ordered middleware run after authn/authz and before `handler`, from
50
+ * `@Middleware(...)` decorators (class-level first, then method-level). A
51
+ * middleware that doesn't call `next()` short-circuits the request —
52
+ * standard Express semantics.
53
+ */
54
+ middleware?: RequestHandler[];
5
55
  handler: (req: Request, res: Response) => void | Promise<void>;
6
56
  }
57
+ /** Request-lifecycle hooks that apply to every route registered via `bellowsRoutes`. */
58
+ export interface BellowsHooks {
59
+ /** Runs before any route's middleware/handler, for every request. */
60
+ onRequest?: RequestHandler;
61
+ /** Runs after the response has been sent, for every request. */
62
+ onResponse?: (req: Request, res: Response) => void;
63
+ /**
64
+ * Error-handling middleware registered after all routes, so an `HttpError`
65
+ * thrown (or passed to `next`) by any route's auth handler, middleware, or
66
+ * handler is converted to a response — Express 5 forwards rejected
67
+ * promises from async handlers automatically. Defaults to `errorHandler`
68
+ * from `./errors.js`. Pass `false` to opt out, e.g. when a shared instance
69
+ * is mounted once on the parent app instead of per-router.
70
+ */
71
+ errorHandler?: ErrorRequestHandler | false;
72
+ }
7
73
  /** Returns an Express Router with all routes from `routes` registered on it. */
8
- export declare function bellowsRoutes(routes: Iterable<RouteDefinition>): Router;
74
+ export declare function bellowsRoutes(routes: Iterable<RouteDefinition>, hooks?: BellowsHooks): Router;
9
75
  //# sourceMappingURL=routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChE;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,MAAM,CAYvE"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAgB,EACd,MAAM,EACN,KAAK,mBAAmB,EACxB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,QAAQ,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG7D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf;oEACwD;YACxD,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB;KACF;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EACP,MAAM,GACN,YAAY,GACZ,KAAK,GACL;QACE,IAAI,EAAE,OAA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