@degenerate/endpoints 0.1.7 → 0.4.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.
Files changed (87) hide show
  1. package/README.md +18 -0
  2. package/dist/cors/authority/jwt/build-validate-jwt-for-audience.d.ts +41 -0
  3. package/dist/cors/authority/jwt/build-validate-jwt-for-audience.d.ts.map +1 -0
  4. package/dist/cors/authority/jwt/build-validate-jwt-for-audience.js +75 -0
  5. package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts +5 -13
  6. package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts.map +1 -1
  7. package/dist/cors/authority/jwt/validate-jwt-authorities.js +7 -27
  8. package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts +5 -13
  9. package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts.map +1 -1
  10. package/dist/cors/authority/jwt/validate-jwt-endpoints.js +7 -27
  11. package/dist/cors/authority/jwt/validate-jwt-events.d.ts +5 -13
  12. package/dist/cors/authority/jwt/validate-jwt-events.d.ts.map +1 -1
  13. package/dist/cors/authority/jwt/validate-jwt-events.js +7 -27
  14. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts +5 -13
  15. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts.map +1 -1
  16. package/dist/cors/authority/jwt/validate-jwt-functions.js +7 -27
  17. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts +5 -13
  18. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts.map +1 -1
  19. package/dist/cors/authority/jwt/validate-jwt-rules.js +7 -27
  20. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts +5 -13
  21. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts.map +1 -1
  22. package/dist/cors/authority/jwt/validate-jwt-share-data.js +7 -27
  23. package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts.map +1 -1
  24. package/dist/cors/endpoints/helpers/validate-incoming-request-data.js +1 -1
  25. package/dist/cors/index.d.ts +1 -0
  26. package/dist/cors/index.d.ts.map +1 -1
  27. package/dist/cors/index.js +1 -0
  28. package/dist/examples/express-server/app.d.ts +20 -2
  29. package/dist/examples/express-server/app.d.ts.map +1 -1
  30. package/dist/examples/express-server/app.js +42 -21
  31. package/dist/examples/express-server/authenticate-realtime.d.ts +27 -0
  32. package/dist/examples/express-server/authenticate-realtime.d.ts.map +1 -0
  33. package/dist/examples/express-server/authenticate-realtime.js +23 -0
  34. package/dist/examples/express-server/server.d.ts +32 -1
  35. package/dist/examples/express-server/server.d.ts.map +1 -1
  36. package/dist/examples/express-server/server.js +61 -7
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/openapi/build-openapi-document.d.ts +27 -0
  41. package/dist/openapi/build-openapi-document.d.ts.map +1 -0
  42. package/dist/openapi/build-openapi-document.js +223 -0
  43. package/dist/openapi/domain-schemas.d.ts +16 -0
  44. package/dist/openapi/domain-schemas.d.ts.map +1 -0
  45. package/dist/openapi/domain-schemas.js +39 -0
  46. package/dist/openapi/index.d.ts +6 -0
  47. package/dist/openapi/index.d.ts.map +1 -0
  48. package/dist/openapi/index.js +21 -0
  49. package/dist/openapi/operations.d.ts +8 -0
  50. package/dist/openapi/operations.d.ts.map +1 -0
  51. package/dist/openapi/operations.js +22 -0
  52. package/dist/openapi/response-schemas.d.ts +32 -0
  53. package/dist/openapi/response-schemas.d.ts.map +1 -0
  54. package/dist/openapi/response-schemas.js +30 -0
  55. package/dist/openapi/types.d.ts +29 -0
  56. package/dist/openapi/types.d.ts.map +1 -0
  57. package/dist/openapi/types.js +2 -0
  58. package/dist/routes/authorities/v1.openapi.d.ts +4 -0
  59. package/dist/routes/authorities/v1.openapi.d.ts.map +1 -0
  60. package/dist/routes/authorities/v1.openapi.js +68 -0
  61. package/dist/routes/events/v1.openapi.d.ts +4 -0
  62. package/dist/routes/events/v1.openapi.d.ts.map +1 -0
  63. package/dist/routes/events/v1.openapi.js +54 -0
  64. package/dist/routes/events/v1.routes.d.ts.map +1 -1
  65. package/dist/routes/events/v1.routes.js +5 -3
  66. package/dist/routes/events.routes.d.ts.map +1 -1
  67. package/dist/routes/events.routes.js +10 -60
  68. package/dist/routes/functions/v1.openapi.d.ts +4 -0
  69. package/dist/routes/functions/v1.openapi.d.ts.map +1 -0
  70. package/dist/routes/functions/v1.openapi.js +68 -0
  71. package/dist/routes/functions.routes.d.ts.map +1 -1
  72. package/dist/routes/functions.routes.js +10 -60
  73. package/dist/routes/rules/v1/rule-set.openapi.d.ts +4 -0
  74. package/dist/routes/rules/v1/rule-set.openapi.d.ts.map +1 -0
  75. package/dist/routes/rules/v1/rule-set.openapi.js +72 -0
  76. package/dist/routes/rules/v1/rule-set.routes.js +3 -3
  77. package/dist/routes/share-data.routes.d.ts.map +1 -1
  78. package/dist/routes/share-data.routes.js +17 -59
  79. package/dist/routes/sharedata/v1.openapi.d.ts +8 -0
  80. package/dist/routes/sharedata/v1.openapi.d.ts.map +1 -0
  81. package/dist/routes/sharedata/v1.openapi.js +60 -0
  82. package/dist/routes/sharedata/v1.routes.d.ts.map +1 -1
  83. package/dist/routes/sharedata/v1.routes.js +195 -9
  84. package/dist/routes/validation/rules/validate-rules.openapi.d.ts +8 -0
  85. package/dist/routes/validation/rules/validate-rules.openapi.d.ts.map +1 -0
  86. package/dist/routes/validation/rules/validate-rules.openapi.js +76 -0
  87. package/package.json +28 -15
package/README.md CHANGED
@@ -29,3 +29,21 @@ npm install @degenerate/endpoints
29
29
  ts-node ./packages/endpoints/src/examples/express-server/server.ts
30
30
  ```
31
31
 
32
+ ## OpenAPI
33
+
34
+ The example server exposes a machine-readable description of its HTTP surface at:
35
+
36
+ ```
37
+ GET /openapi.json
38
+ ```
39
+
40
+ This route is public (no JWT) so codegen, Swagger UI, and contract-testing tools can fetch it freely. The document is an OpenAPI 3.0 spec generated by `buildOpenApiDocument()` from the same Zod schemas the routes validate against — request and response shapes never drift from what the handlers actually accept. To build the document outside the server (e.g. to write it to a file):
41
+
42
+ ```ts
43
+ import { buildOpenApiDocument } from '@degenerate/endpoints';
44
+
45
+ const spec = buildOpenApiDocument();
46
+ ```
47
+
48
+ The operation surface is described by the `OperationDescriptor` arrays under `src/routes/**/**.openapi.ts`; a coverage test asserts the descriptors and the mounted Express routes stay in lockstep.
49
+
@@ -0,0 +1,41 @@
1
+ import { RequestHandler } from 'express';
2
+ import { AuthorizationAudience } from '@degenerate/generic';
3
+ /**
4
+ * Returns an Express middleware that cryptographically verifies the request's
5
+ * Bearer JWT against the registered authority for the supplied audience.
6
+ *
7
+ * Verification flow mirrors `createShareDataAuthenticate` in
8
+ * `@degenerate/realtime/server/authorities-bridge.ts` — the HTTP and WS auth
9
+ * paths use the same primitives, so a token issued for one audience verifies
10
+ * consistently across both transports.
11
+ *
12
+ * Steps:
13
+ * 1. Read `req.app.get('authorizedAuthorities')` — host application must
14
+ * have registered an {@link AuthorizedAuthorities} instance at app
15
+ * construction time (see `createApp` in the example express server).
16
+ * 2. Extract the Bearer token from the `Authorization` header. Missing
17
+ * header or wrong scheme → `RequestNotAuthorizedError`.
18
+ * 3. Peek the token's `iss` claim via `determineIssuerFromBearerToken`
19
+ * (no signature check yet — just enough to know which key to look up).
20
+ * 4. Look up the issuer's verification key for the supplied audience. No
21
+ * registered key → `RequestNotAuthorizedError` (issuer is unknown to
22
+ * this server, regardless of whether the signature would otherwise be
23
+ * valid).
24
+ * 5. Run `decodeBearerToken` — verifies signature, issuer match, and
25
+ * payload schema (`verifyTokenPayload` enforces audience/sub/iat/nbf/exp
26
+ * formatting). Failure → `RequestNotAuthorizedError`.
27
+ * 6. Defense-in-depth: re-check `payload.aud === audience`. `decodeBearerToken`
28
+ * validates the payload schema but does not assert audience matches the
29
+ * route's expectation — without this, a token issued for the EVENTS
30
+ * audience could be used on a SHAREDATA route.
31
+ * 7. Attach the decoded payload to `req.auth` and call `next()`.
32
+ *
33
+ * Failure mode is uniform: every reject throws `RequestNotAuthorizedError`.
34
+ * Pre-verification rejects (missing/empty/wrong-scheme Authorization header,
35
+ * unregistered authorities) carry a specific message; token-verification
36
+ * failures are deliberately normalized to "Bearer token verification failed"
37
+ * so callers can't probe which check failed. The existing
38
+ * `unauthorizedHandler` error middleware turns these into 403 responses.
39
+ */
40
+ export declare const buildValidateJWTForAudience: (audience: AuthorizationAudience) => RequestHandler;
41
+ //# sourceMappingURL=build-validate-jwt-for-audience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-validate-jwt-for-audience.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/build-validate-jwt-for-audience.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EACH,qBAAqB,EAKxB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,2BAA2B,GACpC,UAAU,qBAAqB,KAChC,cA0CF,CAAC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildValidateJWTForAudience = void 0;
4
+ const generic_1 = require("@degenerate/generic");
5
+ /**
6
+ * Returns an Express middleware that cryptographically verifies the request's
7
+ * Bearer JWT against the registered authority for the supplied audience.
8
+ *
9
+ * Verification flow mirrors `createShareDataAuthenticate` in
10
+ * `@degenerate/realtime/server/authorities-bridge.ts` — the HTTP and WS auth
11
+ * paths use the same primitives, so a token issued for one audience verifies
12
+ * consistently across both transports.
13
+ *
14
+ * Steps:
15
+ * 1. Read `req.app.get('authorizedAuthorities')` — host application must
16
+ * have registered an {@link AuthorizedAuthorities} instance at app
17
+ * construction time (see `createApp` in the example express server).
18
+ * 2. Extract the Bearer token from the `Authorization` header. Missing
19
+ * header or wrong scheme → `RequestNotAuthorizedError`.
20
+ * 3. Peek the token's `iss` claim via `determineIssuerFromBearerToken`
21
+ * (no signature check yet — just enough to know which key to look up).
22
+ * 4. Look up the issuer's verification key for the supplied audience. No
23
+ * registered key → `RequestNotAuthorizedError` (issuer is unknown to
24
+ * this server, regardless of whether the signature would otherwise be
25
+ * valid).
26
+ * 5. Run `decodeBearerToken` — verifies signature, issuer match, and
27
+ * payload schema (`verifyTokenPayload` enforces audience/sub/iat/nbf/exp
28
+ * formatting). Failure → `RequestNotAuthorizedError`.
29
+ * 6. Defense-in-depth: re-check `payload.aud === audience`. `decodeBearerToken`
30
+ * validates the payload schema but does not assert audience matches the
31
+ * route's expectation — without this, a token issued for the EVENTS
32
+ * audience could be used on a SHAREDATA route.
33
+ * 7. Attach the decoded payload to `req.auth` and call `next()`.
34
+ *
35
+ * Failure mode is uniform: every reject throws `RequestNotAuthorizedError`.
36
+ * Pre-verification rejects (missing/empty/wrong-scheme Authorization header,
37
+ * unregistered authorities) carry a specific message; token-verification
38
+ * failures are deliberately normalized to "Bearer token verification failed"
39
+ * so callers can't probe which check failed. The existing
40
+ * `unauthorizedHandler` error middleware turns these into 403 responses.
41
+ */
42
+ const buildValidateJWTForAudience = (audience) => {
43
+ return (req, _res, next) => {
44
+ const authorities = req.app.get('authorizedAuthorities');
45
+ if (!authorities) {
46
+ throw new generic_1.RequestNotAuthorizedError('authorizedAuthorities is not registered on the app — see createApp()');
47
+ }
48
+ const authHeader = req.headers.authorization;
49
+ if (typeof authHeader !== 'string' || !authHeader.startsWith('Bearer ')) {
50
+ throw new generic_1.RequestNotAuthorizedError('Missing or malformed Authorization header (expected "Bearer <token>")');
51
+ }
52
+ const token = authHeader.slice('Bearer '.length).trim();
53
+ if (!token) {
54
+ throw new generic_1.RequestNotAuthorizedError('Bearer token is empty');
55
+ }
56
+ let payload;
57
+ try {
58
+ // All four verification steps (issuer peek → key lookup →
59
+ // signature/payload verify → audience defense-in-depth) are
60
+ // centralized in @degenerate/generic so the HTTP and WS
61
+ // transports can't drift on which checks they run.
62
+ payload = (0, generic_1.verifyJwtBearerTokenForAudience)(token, authorities, audience);
63
+ }
64
+ catch {
65
+ // Normalize every failure mode to one Express-friendly error.
66
+ // The underlying helper throws specific error classes; we
67
+ // collapse them so the existing unauthorized-handler chain
68
+ // turns them all into a 403.
69
+ throw new generic_1.RequestNotAuthorizedError('Bearer token verification failed');
70
+ }
71
+ req.auth = payload;
72
+ next();
73
+ };
74
+ };
75
+ exports.buildValidateJWTForAudience = buildValidateJWTForAudience;
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the AUTHORITIES audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTAuthorities(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTAuthorities: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-authorities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-authorities.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-authorities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBAc3F"}
1
+ {"version":3,"file":"validate-jwt-authorities.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-authorities.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8IAElC,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTAuthorities = validateJWTAuthorities;
3
+ exports.validateJWTAuthorities = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the AUTHORITIES audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTAuthorities(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.AUTHORITIES) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for authorities');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTAuthorities = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.AUTHORITIES);
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the ENDPOINTS audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTEndpoints(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTEndpoints: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-endpoints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-endpoints.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-endpoints.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBAczF"}
1
+ {"version":3,"file":"validate-jwt-endpoints.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-endpoints.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTEndpoints = validateJWTEndpoints;
3
+ exports.validateJWTEndpoints = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the ENDPOINTS audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTEndpoints(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.ENDPOINTS) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for endpoints');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTEndpoints = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.ENDPOINTS);
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the EVENTS audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTEvents(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTEvents: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-events.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBActF"}
1
+ {"version":3,"file":"validate-jwt-events.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-events.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,8IAE7B,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTEvents = validateJWTEvents;
3
+ exports.validateJWTEvents = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the EVENTS audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTEvents(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.EVENTS) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for events');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTEvents = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.EVENTS);
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the FUNCTIONS audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTFunctions(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTFunctions: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-functions.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBAczF"}
1
+ {"version":3,"file":"validate-jwt-functions.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-functions.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTFunctions = validateJWTFunctions;
3
+ exports.validateJWTFunctions = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the FUNCTIONS audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTFunctions(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.FUNCTIONS) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for functions');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTFunctions = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.FUNCTIONS);
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the RULES audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTRules(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTRules: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-rules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-rules.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-rules.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBAcrF"}
1
+ {"version":3,"file":"validate-jwt-rules.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-rules.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,8IAE5B,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTRules = validateJWTRules;
3
+ exports.validateJWTRules = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the RULES audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTRules(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.RULES) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for rules');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTRules = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.RULES);
@@ -1,16 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
1
  /**
3
- * This function validates that the incoming request has a valid JWT token and it is authorized
4
- * for the expected function.
5
- *
6
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
7
- * if this is successful.
8
- *
9
- * @param req the incoming request
10
- * @param res the response object
11
- * @param next CORS next function
12
- *
13
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
2
+ * Express middleware that cryptographically verifies the request's Bearer
3
+ * JWT for the SHAREDATA audience. Thin wrapper around
4
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
5
+ * `req.auth` attachment are documented on that helper.
14
6
  */
15
- export declare function validateJWTShareData(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ export declare const validateJWTShareData: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
16
8
  //# sourceMappingURL=validate-jwt-share-data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-jwt-share-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-share-data.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,iBAczF"}
1
+ {"version":3,"file":"validate-jwt-share-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/authority/jwt/validate-jwt-share-data.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,8IAEhC,CAAC"}
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateJWTShareData = validateJWTShareData;
3
+ exports.validateJWTShareData = void 0;
5
4
  const generic_1 = require("@degenerate/generic");
6
- const get_set_audiences_1 = require("../audience/get-set-audiences");
5
+ const build_validate_jwt_for_audience_1 = require("./build-validate-jwt-for-audience");
7
6
  /**
8
- * This function validates that the incoming request has a valid JWT token and it is authorized
9
- * for the expected function.
10
- *
11
- * Is is used as part of the CORS protection and adds a user object to the request 'req.user'
12
- * if this is successful.
13
- *
14
- * @param req the incoming request
15
- * @param res the response object
16
- * @param next CORS next function
17
- *
18
- * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
7
+ * Express middleware that cryptographically verifies the request's Bearer
8
+ * JWT for the SHAREDATA audience. Thin wrapper around
9
+ * {@link buildValidateJWTForAudience}; behavior, failure modes, and the
10
+ * `req.auth` attachment are documented on that helper.
19
11
  */
20
- async function validateJWTShareData(req, res, next) {
21
- // get audience from the request
22
- const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
23
- if (!audience) {
24
- throw new generic_1.RequestNotAuthorizedError('No audience found in the request');
25
- }
26
- if (audience !== generic_1.AuthorizationAudience.SHAREDATA) {
27
- throw new generic_1.RequestNotAuthorizedError('the audience included is not for share data');
28
- }
29
- // check if an Authority is present.
30
- next();
31
- return;
32
- }
12
+ exports.validateJWTShareData = (0, build_validate_jwt_for_audience_1.buildValidateJWTForAudience)(generic_1.AuthorizationAudience.SHAREDATA);
@@ -1 +1 @@
1
- {"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,SAClE,OAAO,OAAO,QAAQ,QAAQ,YAAY,UAa1D"}
1
+ {"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,IACvE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAa1D"}
@@ -33,5 +33,5 @@ function validateIncomingRequestData(schema) {
33
33
  * @returns an array of formatted error messages
34
34
  */
35
35
  function formatZodErrors(error) {
36
- return error.errors.map((issue) => `${issue.path.join('.')} is ${issue.message}`);
36
+ return error.issues.map((issue) => `${issue.path.join('.')} is ${issue.message}`);
37
37
  }
@@ -1,4 +1,5 @@
1
1
  export * from './authority/audience/get-set-audiences';
2
+ export * from './authority/jwt/build-validate-jwt-for-audience';
2
3
  export * from './authority/jwt/validate-jwt-authorities';
3
4
  export * from './authority/jwt/validate-jwt-endpoints';
4
5
  export * from './authority/jwt/validate-jwt-events';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AAGxD,cAAc,oDAAoD,CAAC;AAEnE,cAAc,2CAA2C,CAAC;AAI1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAI9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AAGxD,cAAc,oDAAoD,CAAC;AAEnE,cAAc,2CAA2C,CAAC;AAI1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAI9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC"}
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./authority/audience/get-set-audiences"), exports);
18
+ __exportStar(require("./authority/jwt/build-validate-jwt-for-audience"), exports);
18
19
  __exportStar(require("./authority/jwt/validate-jwt-authorities"), exports);
19
20
  __exportStar(require("./authority/jwt/validate-jwt-endpoints"), exports);
20
21
  __exportStar(require("./authority/jwt/validate-jwt-events"), exports);