@degenerate/endpoints 0.0.9 → 0.0.11

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 (73) hide show
  1. package/README.md +27 -2
  2. package/dist/__tests__/jest.setup.d.ts +10 -0
  3. package/dist/__tests__/jest.setup.d.ts.map +1 -0
  4. package/dist/__tests__/jest.setup.js +2 -0
  5. package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts +2 -2
  6. package/dist/cors/authority/jwt/validate-jwt-authorities.d.ts.map +1 -1
  7. package/dist/cors/authority/jwt/validate-jwt-authorities.js +0 -1
  8. package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts +16 -0
  9. package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts.map +1 -0
  10. package/dist/cors/authority/jwt/validate-jwt-endpoints.js +32 -0
  11. package/dist/cors/authority/jwt/validate-jwt-events.d.ts +16 -0
  12. package/dist/cors/authority/jwt/validate-jwt-events.d.ts.map +1 -0
  13. package/dist/cors/authority/jwt/validate-jwt-events.js +32 -0
  14. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts +16 -0
  15. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts.map +1 -0
  16. package/dist/cors/authority/jwt/validate-jwt-functions.js +32 -0
  17. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts +16 -0
  18. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts.map +1 -0
  19. package/dist/cors/authority/jwt/validate-jwt-rules.js +32 -0
  20. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts +16 -0
  21. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts.map +1 -0
  22. package/dist/cors/authority/jwt/validate-jwt-share-data.js +32 -0
  23. package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts +10 -0
  24. package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts.map +1 -0
  25. package/dist/cors/endpoints/helpers/validate-incoming-request-data.js +37 -0
  26. package/dist/cors/errors/bad-request-handler.d.ts.map +1 -1
  27. package/dist/cors/errors/bad-request-handler.js +1 -2
  28. package/dist/cors/index.d.ts +12 -4
  29. package/dist/cors/index.d.ts.map +1 -1
  30. package/dist/cors/index.js +20 -6
  31. package/dist/cors/logging/add-unique-tracking.d.ts +11 -0
  32. package/dist/cors/logging/add-unique-tracking.d.ts.map +1 -0
  33. package/dist/cors/logging/add-unique-tracking.js +18 -0
  34. package/dist/cors/logging/request-logging.d.ts +11 -0
  35. package/dist/cors/logging/request-logging.d.ts.map +1 -0
  36. package/dist/cors/logging/request-logging.js +26 -0
  37. package/dist/cors/routes/authorities/v1.routes.d.ts +2 -0
  38. package/dist/cors/routes/authorities/v1.routes.d.ts.map +1 -0
  39. package/dist/cors/routes/authorities/v1.routes.js +87 -0
  40. package/dist/cors/routes/authorities.routes.d.ts.map +1 -1
  41. package/dist/cors/routes/authorities.routes.js +8 -59
  42. package/dist/cors/routes/rules/v1/rule-set.routes.d.ts +2 -0
  43. package/dist/cors/routes/rules/v1/rule-set.routes.d.ts.map +1 -0
  44. package/dist/cors/routes/rules/v1/rule-set.routes.js +104 -0
  45. package/dist/cors/routes/rules/v1.routes.d.ts +2 -0
  46. package/dist/cors/routes/rules/v1.routes.d.ts.map +1 -0
  47. package/dist/cors/routes/rules/v1.routes.js +44 -0
  48. package/dist/cors/routes/rules.routes.d.ts.map +1 -1
  49. package/dist/cors/routes/rules.routes.js +6 -24
  50. package/dist/examples/express-server/app.d.ts.map +1 -1
  51. package/dist/examples/express-server/app.js +4 -0
  52. package/dist/schema/{authorities.schema.d.ts → authorities-transactions.schema.d.ts} +47 -154
  53. package/dist/schema/authorities-transactions.schema.d.ts.map +1 -0
  54. package/dist/schema/{authorities.schema.js → authorities-transactions.schema.js} +12 -29
  55. package/dist/schema/rules/rules-conditions.schema.d.ts +402 -0
  56. package/dist/schema/rules/rules-conditions.schema.d.ts.map +1 -0
  57. package/dist/schema/rules/rules-conditions.schema.js +99 -0
  58. package/dist/schema/rules/rules-enums.schema.d.ts +39 -0
  59. package/dist/schema/rules/rules-enums.schema.d.ts.map +1 -0
  60. package/dist/schema/rules/rules-enums.schema.js +90 -0
  61. package/dist/schema/rules/rules.schema.d.ts +2839 -0
  62. package/dist/schema/rules/rules.schema.d.ts.map +1 -0
  63. package/dist/schema/rules/rules.schema.js +76 -0
  64. package/dist/schema/rules-transactions.schema.d.ts +450 -0
  65. package/dist/schema/rules-transactions.schema.d.ts.map +1 -0
  66. package/dist/schema/rules-transactions.schema.js +63 -0
  67. package/dist/schema/transactions.schema.d.ts +45 -0
  68. package/dist/schema/transactions.schema.d.ts.map +1 -0
  69. package/dist/schema/{transaction.schema.js → transactions.schema.js} +16 -1
  70. package/package.json +3 -3
  71. package/dist/schema/authorities.schema.d.ts.map +0 -1
  72. package/dist/schema/transaction.schema.d.ts +0 -8
  73. package/dist/schema/transaction.schema.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # @Degenerate/<new-package-name> Package
1
+ # @degenerate/endpoints
2
+
3
+ The `@degenerate/endpoints` package is a core component of the SAFE system, responsible for handling various API endpoints within the system. This package provides a set of routes and middleware to manage and process incoming requests, ensuring that the system operates within the defined constraints and policies.
4
+
5
+ ## Features
6
+
7
+ **Route Management**: Provides a structured way to define and manage API routes.
8
+ **Middleware Integration**: Supports the integration of various middleware for request processing, validation, and error handling.
9
+
10
+ **Error Handling**: Includes built-in error handlers to manage unauthorized access, bad requests, and other errors.
11
+
12
+ **Extensibility**: Allows the addition of custom routes and middleware to cater to specific requirements.
13
+
14
+ ## Installation
15
+
16
+ To install the `@degenerate/endpoints` package, use the following command:
17
+
18
+ ```sh
19
+ npm install @degenerate/endpoints
20
+ ```
21
+
22
+
23
+ ## Example Server
24
+
25
+ ```sh
26
+ ts-node ./packages/endpoints/src/examples/express-server/server.ts
27
+ ```
2
28
 
3
- This package contains the functions for <new-package-name>. The package <what-the-purpose-of-the-package-is> in the SAFE environment.
@@ -0,0 +1,10 @@
1
+ import { AuthorizedAuthorities } from '@degenerate/generic';
2
+ declare global {
3
+ namespace Express {
4
+ interface Request {
5
+ authorizedAuthorities: AuthorizedAuthorities;
6
+ uniqueTrackingId: string;
7
+ }
8
+ }
9
+ }
10
+ //# sourceMappingURL=jest.setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/jest.setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,qBAAqB,EAAE,qBAAqB,CAAC;YAC7C,gBAAgB,EAAE,MAAM,CAAC;SAC5B;KACJ;CACJ"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { NextFunction } from 'express';
1
+ import { Request, Response, NextFunction } from 'express';
2
2
  /**
3
3
  * This function validates that the incoming request has a valid JWT token and it is authorized
4
4
  * for the expected function.
@@ -12,5 +12,5 @@ import { NextFunction } from 'express';
12
12
  *
13
13
  * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
14
14
  */
15
- export declare function validateJWTAuthorities(req: any, res: any, next: NextFunction): Promise<void>;
15
+ export declare function validateJWTAuthorities(req: Request, res: Response, next: NextFunction): Promise<void>;
16
16
  //# 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,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,iBAelF"}
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"}
@@ -18,7 +18,6 @@ const get_set_audiences_1 = require("../audience/get-set-audiences");
18
18
  * @returns the next step if the validation succeeds or a unauthorized or disallowed response.
19
19
  */
20
20
  async function validateJWTAuthorities(req, res, next) {
21
- console.log('validateJWTAuthorities called');
22
21
  // get audience from the request
23
22
  const audience = (0, get_set_audiences_1.getAudienceAuthority)(req);
24
23
  if (!audience) {
@@ -0,0 +1,16 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
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.
14
+ */
15
+ export declare function validateJWTEndpoints(req: Request, res: Response, next: NextFunction): Promise<void>;
16
+ //# sourceMappingURL=validate-jwt-endpoints.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateJWTEndpoints = validateJWTEndpoints;
5
+ const generic_1 = require("@degenerate/generic");
6
+ const get_set_audiences_1 = require("../audience/get-set-audiences");
7
+ /**
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.
19
+ */
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
+ }
@@ -0,0 +1,16 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
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.
14
+ */
15
+ export declare function validateJWTEvents(req: Request, res: Response, next: NextFunction): Promise<void>;
16
+ //# sourceMappingURL=validate-jwt-events.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateJWTEvents = validateJWTEvents;
5
+ const generic_1 = require("@degenerate/generic");
6
+ const get_set_audiences_1 = require("../audience/get-set-audiences");
7
+ /**
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.
19
+ */
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
+ }
@@ -0,0 +1,16 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
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.
14
+ */
15
+ export declare function validateJWTFunctions(req: Request, res: Response, next: NextFunction): Promise<void>;
16
+ //# sourceMappingURL=validate-jwt-functions.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateJWTFunctions = validateJWTFunctions;
5
+ const generic_1 = require("@degenerate/generic");
6
+ const get_set_audiences_1 = require("../audience/get-set-audiences");
7
+ /**
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.
19
+ */
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
+ }
@@ -0,0 +1,16 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
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.
14
+ */
15
+ export declare function validateJWTRules(req: Request, res: Response, next: NextFunction): Promise<void>;
16
+ //# sourceMappingURL=validate-jwt-rules.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateJWTRules = validateJWTRules;
5
+ const generic_1 = require("@degenerate/generic");
6
+ const get_set_audiences_1 = require("../audience/get-set-audiences");
7
+ /**
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.
19
+ */
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
+ }
@@ -0,0 +1,16 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
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.
14
+ */
15
+ export declare function validateJWTShareData(req: Request, res: Response, next: NextFunction): Promise<void>;
16
+ //# sourceMappingURL=validate-jwt-share-data.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateJWTShareData = validateJWTShareData;
5
+ const generic_1 = require("@degenerate/generic");
6
+ const get_set_audiences_1 = require("../audience/get-set-audiences");
7
+ /**
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.
19
+ */
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
+ }
@@ -0,0 +1,10 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { Request, Response, NextFunction } from 'express';
3
+ /**
4
+ * This function validates the incoming request data against a schema.
5
+ *
6
+ * @param schema the schema to validate against
7
+ * @returns a middleware function that will validate the incoming request data
8
+ */
9
+ export declare function validateIncomingRequestData<T extends ZodSchema<any>>(schema: T): (req: Request, res: Response, next: NextFunction) => void;
10
+ //# sourceMappingURL=validate-incoming-request-data.d.ts.map
@@ -0,0 +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,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,SAC9D,OAAO,OAAO,QAAQ,QAAQ,YAAY,UAa1D"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateIncomingRequestData = validateIncomingRequestData;
4
+ const zod_1 = require("zod");
5
+ const generic_1 = require("@degenerate/generic");
6
+ /**
7
+ * This function validates the incoming request data against a schema.
8
+ *
9
+ * @param schema the schema to validate against
10
+ * @returns a middleware function that will validate the incoming request data
11
+ */
12
+ function validateIncomingRequestData(schema) {
13
+ return (req, res, next) => {
14
+ try {
15
+ schema.parse(req.body);
16
+ next();
17
+ }
18
+ catch (error) {
19
+ if (error instanceof zod_1.ZodError) {
20
+ const messages = formatZodErrors(error);
21
+ throw new generic_1.RequestValidationFailedError(req, messages);
22
+ }
23
+ else {
24
+ next(error); // Pass other errors to the next middleware
25
+ }
26
+ }
27
+ };
28
+ }
29
+ /**
30
+ * This function formats Zod error messages.
31
+ *
32
+ * @param error the ZodError object
33
+ * @returns an array of formatted error messages
34
+ */
35
+ function formatZodErrors(error) {
36
+ return error.errors.map(issue => `${issue.path.join('.')} is ${issue.message}`);
37
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"bad-request-handler.d.ts","sourceRoot":"","sources":["../../../src/cors/errors/bad-request-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC7B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,kDAYrB"}
1
+ {"version":3,"file":"bad-request-handler.d.ts","sourceRoot":"","sources":["../../../src/cors/errors/bad-request-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC7B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,kDAWrB"}
@@ -13,10 +13,9 @@ const generic_1 = require("@degenerate/generic");
13
13
  */
14
14
  function badRequestHandler(err, req, res, next) {
15
15
  if (err instanceof generic_1.BaseError && err.errorCode === 400) {
16
- console.error(err.toJSON());
17
16
  const response = {
18
17
  successful: false,
19
- error: 'Bad Request',
18
+ error: err.message,
20
19
  };
21
20
  return res.status(400).send(response);
22
21
  }
@@ -1,13 +1,21 @@
1
+ export * from './authority/audience/get-set-audiences';
2
+ export * from './authority/jwt/validate-jwt-authorities';
3
+ export * from './authority/jwt/validate-jwt-endpoints';
4
+ export * from './authority/jwt/validate-jwt-events';
5
+ export * from './authority/jwt/validate-jwt-functions';
6
+ export * from './authority/jwt/validate-jwt-rules';
7
+ export * from './authority/jwt/validate-jwt-share-data';
8
+ export * from './endpoints/authorities/validate-authorities-transaction';
9
+ export * from './endpoints/helpers/validate-request-body';
10
+ export * from './endpoints/helpers/validate-incoming-request-data';
1
11
  export * from './errors/all-error-handler';
2
12
  export * from './errors/bad-request-handler';
3
13
  export * from './errors/unauthorized-handler';
14
+ export * from './logging/add-unique-tracking';
15
+ export * from './logging/request-logging';
4
16
  export * from './routes/authorities.routes';
5
17
  export * from './routes/events.routes';
6
18
  export * from './routes/functions.routes';
7
19
  export * from './routes/rules.routes';
8
20
  export * from './routes/share-data.routes';
9
- export * from './authority/audience/get-set-audiences';
10
- export * from './authority/jwt/validate-jwt-authorities';
11
- export * from './endpoints/authorities/validate-authorities-transaction';
12
- export * from './endpoints/helpers/validate-request-body';
13
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cors/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAM9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAI3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AAEzD,cAAc,0DAA0D,CAAC;AACzE,cAAc,2CAA2C,CAAC"}
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;AAExD,cAAc,0DAA0D,CAAC;AAEzE,cAAc,2CAA2C,CAAC;AAE1D,cAAc,oDAAoD,CAAC;AAInE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAI9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAI1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC"}
@@ -14,11 +14,29 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- //#region cors functions
17
+ __exportStar(require("./authority/audience/get-set-audiences"), exports);
18
+ __exportStar(require("./authority/jwt/validate-jwt-authorities"), exports);
19
+ __exportStar(require("./authority/jwt/validate-jwt-endpoints"), exports);
20
+ __exportStar(require("./authority/jwt/validate-jwt-events"), exports);
21
+ __exportStar(require("./authority/jwt/validate-jwt-functions"), exports);
22
+ __exportStar(require("./authority/jwt/validate-jwt-rules"), exports);
23
+ __exportStar(require("./authority/jwt/validate-jwt-share-data"), exports);
24
+ //#region Endpoints
25
+ __exportStar(require("./endpoints/authorities/validate-authorities-transaction"), exports);
26
+ // zod checks
27
+ __exportStar(require("./endpoints/helpers/validate-request-body"), exports);
28
+ // object javascript checks
29
+ __exportStar(require("./endpoints/helpers/validate-incoming-request-data"), exports);
30
+ //#endregion Endpoints
31
+ //#region errors functions
18
32
  __exportStar(require("./errors/all-error-handler"), exports);
19
33
  __exportStar(require("./errors/bad-request-handler"), exports);
20
34
  __exportStar(require("./errors/unauthorized-handler"), exports);
21
- //#endregion cors functions
35
+ //#endregion errors functions
36
+ //#region logging
37
+ __exportStar(require("./logging/add-unique-tracking"), exports);
38
+ __exportStar(require("./logging/request-logging"), exports);
39
+ //#endregion logging
22
40
  //#region routes
23
41
  __exportStar(require("./routes/authorities.routes"), exports);
24
42
  __exportStar(require("./routes/events.routes"), exports);
@@ -26,7 +44,3 @@ __exportStar(require("./routes/functions.routes"), exports);
26
44
  __exportStar(require("./routes/rules.routes"), exports);
27
45
  __exportStar(require("./routes/share-data.routes"), exports);
28
46
  //#endregion routes
29
- __exportStar(require("./authority/audience/get-set-audiences"), exports);
30
- __exportStar(require("./authority/jwt/validate-jwt-authorities"), exports);
31
- __exportStar(require("./endpoints/authorities/validate-authorities-transaction"), exports);
32
- __exportStar(require("./endpoints/helpers/validate-request-body"), exports);
@@ -0,0 +1,11 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
3
+ * This function adds a unique tracking id to the request object.
4
+ *
5
+ * @param req the incoming request
6
+ * @param res the response object
7
+ * @param next the next function
8
+ * @returns
9
+ */
10
+ export declare function addUniqueTracking(req: Request, res: Response, next: NextFunction): void;
11
+ //# sourceMappingURL=add-unique-tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-unique-tracking.d.ts","sourceRoot":"","sources":["../../../src/cors/logging/add-unique-tracking.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,QAIhF"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addUniqueTracking = addUniqueTracking;
4
+ const generic_1 = require("@degenerate/generic");
5
+ const request_object_helpers_1 = require("@degenerate/generic/src/helpers/request/request-object-helpers");
6
+ /**
7
+ * This function adds a unique tracking id to the request object.
8
+ *
9
+ * @param req the incoming request
10
+ * @param res the response object
11
+ * @param next the next function
12
+ * @returns
13
+ */
14
+ function addUniqueTracking(req, res, next) {
15
+ (0, request_object_helpers_1.setUniqueTrackingId)(req, `${(0, generic_1.createId)(30)}-${Date.now()}`);
16
+ next();
17
+ return;
18
+ }
@@ -0,0 +1,11 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
3
+ * This function logs the incoming request.
4
+ *
5
+ * @param req the incoming request
6
+ * @param res the response object
7
+ * @param next the next function
8
+ * @returns
9
+ */
10
+ export declare function requestLogging(req: Request, res: Response, next: NextFunction): void;
11
+ //# sourceMappingURL=request-logging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-logging.d.ts","sourceRoot":"","sources":["../../../src/cors/logging/request-logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,QAa7E"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestLogging = requestLogging;
4
+ /**
5
+ * This function logs the incoming request.
6
+ *
7
+ * @param req the incoming request
8
+ * @param res the response object
9
+ * @param next the next function
10
+ * @returns
11
+ */
12
+ function requestLogging(req, res, next) {
13
+ console.log(`Request Url: ${req.originalUrl}`);
14
+ console.log(`Request Method: ${req.method}`);
15
+ console.log(`Request IP: ${req.ip}`);
16
+ console.log(`Request Ips: ${req.ips.join(' ,')}`);
17
+ console.log(`Request Headers: ${JSON.stringify(req.headers, null, 2)}`);
18
+ if (req.body) {
19
+ console.log(`Request Body: ${JSON.stringify(req.body, null, 2)}`);
20
+ }
21
+ console.log(`Request Http Version: ${req.httpVersion}`);
22
+ console.log(`Request Params: ${JSON.stringify(req.params, null, 2)}`);
23
+ next();
24
+ return;
25
+ }
26
+ ;
@@ -0,0 +1,2 @@
1
+ export declare const v1: import("express-serve-static-core").Router;
2
+ //# sourceMappingURL=v1.routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.routes.d.ts","sourceRoot":"","sources":["../../../../src/cors/routes/authorities/v1.routes.ts"],"names":[],"mappings":"AAgGA,eAAO,MAAM,EAAE,4CAAS,CAAC"}