@degenerate/endpoints 0.0.10 → 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 (65) 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-endpoints.d.ts +16 -0
  8. package/dist/cors/authority/jwt/validate-jwt-endpoints.d.ts.map +1 -0
  9. package/dist/cors/authority/jwt/validate-jwt-endpoints.js +32 -0
  10. package/dist/cors/authority/jwt/validate-jwt-events.d.ts +16 -0
  11. package/dist/cors/authority/jwt/validate-jwt-events.d.ts.map +1 -0
  12. package/dist/cors/authority/jwt/validate-jwt-events.js +32 -0
  13. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts +16 -0
  14. package/dist/cors/authority/jwt/validate-jwt-functions.d.ts.map +1 -0
  15. package/dist/cors/authority/jwt/validate-jwt-functions.js +32 -0
  16. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts +16 -0
  17. package/dist/cors/authority/jwt/validate-jwt-rules.d.ts.map +1 -0
  18. package/dist/cors/authority/jwt/validate-jwt-rules.js +32 -0
  19. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts +16 -0
  20. package/dist/cors/authority/jwt/validate-jwt-share-data.d.ts.map +1 -0
  21. package/dist/cors/authority/jwt/validate-jwt-share-data.js +32 -0
  22. package/dist/cors/index.d.ts +12 -4
  23. package/dist/cors/index.d.ts.map +1 -1
  24. package/dist/cors/index.js +20 -6
  25. package/dist/cors/logging/add-unique-tracking.d.ts +11 -0
  26. package/dist/cors/logging/add-unique-tracking.d.ts.map +1 -0
  27. package/dist/cors/logging/add-unique-tracking.js +18 -0
  28. package/dist/cors/logging/request-logging.d.ts +11 -0
  29. package/dist/cors/logging/request-logging.d.ts.map +1 -0
  30. package/dist/cors/logging/request-logging.js +26 -0
  31. package/dist/cors/routes/authorities/v1.routes.d.ts +2 -0
  32. package/dist/cors/routes/authorities/v1.routes.d.ts.map +1 -0
  33. package/dist/cors/routes/authorities/v1.routes.js +87 -0
  34. package/dist/cors/routes/authorities.routes.d.ts.map +1 -1
  35. package/dist/cors/routes/authorities.routes.js +8 -61
  36. package/dist/cors/routes/rules/v1/rule-set.routes.d.ts +2 -0
  37. package/dist/cors/routes/rules/v1/rule-set.routes.d.ts.map +1 -0
  38. package/dist/cors/routes/rules/v1/rule-set.routes.js +104 -0
  39. package/dist/cors/routes/rules/v1.routes.d.ts +2 -0
  40. package/dist/cors/routes/rules/v1.routes.d.ts.map +1 -0
  41. package/dist/cors/routes/rules/v1.routes.js +44 -0
  42. package/dist/cors/routes/rules.routes.d.ts.map +1 -1
  43. package/dist/cors/routes/rules.routes.js +6 -24
  44. package/dist/schema/{authorities.schema.d.ts → authorities-transactions.schema.d.ts} +16 -53
  45. package/dist/schema/authorities-transactions.schema.d.ts.map +1 -0
  46. package/dist/schema/{authorities.schema.js → authorities-transactions.schema.js} +6 -19
  47. package/dist/schema/rules/rules-conditions.schema.d.ts +402 -0
  48. package/dist/schema/rules/rules-conditions.schema.d.ts.map +1 -0
  49. package/dist/schema/rules/rules-conditions.schema.js +99 -0
  50. package/dist/schema/rules/rules-enums.schema.d.ts +39 -0
  51. package/dist/schema/rules/rules-enums.schema.d.ts.map +1 -0
  52. package/dist/schema/rules/rules-enums.schema.js +90 -0
  53. package/dist/schema/rules/rules.schema.d.ts +2839 -0
  54. package/dist/schema/rules/rules.schema.d.ts.map +1 -0
  55. package/dist/schema/rules/rules.schema.js +76 -0
  56. package/dist/schema/rules-transactions.schema.d.ts +450 -0
  57. package/dist/schema/rules-transactions.schema.d.ts.map +1 -0
  58. package/dist/schema/rules-transactions.schema.js +63 -0
  59. package/dist/schema/transactions.schema.d.ts +45 -0
  60. package/dist/schema/transactions.schema.d.ts.map +1 -0
  61. package/dist/schema/{transaction.schema.js → transactions.schema.js} +16 -1
  62. package/package.json +3 -3
  63. package/dist/schema/authorities.schema.d.ts.map +0 -1
  64. package/dist/schema/transaction.schema.d.ts +0 -8
  65. 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,iBAclF"}
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"}
@@ -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
+ }
@@ -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"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ //#region Package Imports
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.v1 = void 0;
28
+ const express = __importStar(require("express"));
29
+ //#endregion Package Imports
30
+ // #region Middleware Protections
31
+ const validate_request_body_1 = require("../../endpoints/helpers/validate-request-body");
32
+ const validate_incoming_request_data_1 = require("../../endpoints/helpers/validate-incoming-request-data");
33
+ // #endregion Middleware Protections
34
+ //#region Incoming Shape Validations
35
+ const authorities_transactions_schema_1 = require("../../../schema/authorities-transactions.schema");
36
+ //#endregion Incoming Shape Validations
37
+ //#region Functions and Models
38
+ const add_unique_tracking_1 = require("../../logging/add-unique-tracking");
39
+ //#endregion Functions and Models
40
+ //#region Route Imports
41
+ //#endregion Route Imports
42
+ const generic_1 = require("@degenerate/generic");
43
+ // eslint-disable-next-line new-cap
44
+ const router = express.Router({ mergeParams: true });
45
+ router.use(add_unique_tracking_1.addUniqueTracking); // add the unique tracking id to the request
46
+ /**
47
+ * This creates a new authority object.
48
+ */
49
+ router.post(// https://{hostname}/authorities/v1
50
+ '/', add_unique_tracking_1.addUniqueTracking, // add a unique tracking id to the request
51
+ validate_request_body_1.validateRequestBody, // make sure this is a valid request body
52
+ (0, validate_incoming_request_data_1.validateIncomingRequestData)(authorities_transactions_schema_1.ISAFETransactionAuthorityAddSchema), async (req, res) => {
53
+ return res.status(200).send({ successful: true });
54
+ });
55
+ /**
56
+ * This gets the authorities objects and their data.
57
+ */
58
+ router.get(// https://{hostname}/authorities/v1
59
+ '/', add_unique_tracking_1.addUniqueTracking, // add a unique tracking id to the request
60
+ async (req, res) => {
61
+ res.status(200).send({ successful: true });
62
+ return;
63
+ });
64
+ router.get(// https://{hostname}/authorities/v1/{authorityid}
65
+ '/:authorityid', add_unique_tracking_1.addUniqueTracking, // add a unique tracking id to the request
66
+ async (req, res) => {
67
+ const authorityId = (0, generic_1.getAuthorityId)(req); // get the authority id.
68
+ return res.status(200).send({ successful: true, authorityId });
69
+ });
70
+ /**
71
+ * This updates the authority object.
72
+ */
73
+ router.patch(// https://{hostname}/authorities/v1
74
+ '/', add_unique_tracking_1.addUniqueTracking, // add a unique tracking id to the request
75
+ validate_request_body_1.validateRequestBody, (0, validate_incoming_request_data_1.validateIncomingRequestData)(authorities_transactions_schema_1.ISAFETransactionAuthorityUpdateSchema), async (req, res) => {
76
+ return res.status(200).send({ successful: true });
77
+ });
78
+ /**
79
+ * This deletes the authority object.
80
+ */
81
+ router.delete(// https://{hostname}/authorities/v1
82
+ '/:authorityid', add_unique_tracking_1.addUniqueTracking, // add a unique tracking id to the request
83
+ validate_request_body_1.validateRequestBody, (0, validate_incoming_request_data_1.validateIncomingRequestData)(authorities_transactions_schema_1.ISAFETransactionAuthorityRemoveSchema), async (req, res) => {
84
+ const authorityId = (0, generic_1.getAuthorityId)(req); // get the authority id.
85
+ return res.status(200).send({ successful: true, authorityId });
86
+ });
87
+ exports.v1 = router; // https://{hostname}/authorities/v1
@@ -1 +1 @@
1
- {"version":3,"file":"authorities.routes.d.ts","sourceRoot":"","sources":["../../../src/cors/routes/authorities.routes.ts"],"names":[],"mappings":"AA0DA,eAAO,MAAM,WAAW,4CAAS,CAAC"}
1
+ {"version":3,"file":"authorities.routes.d.ts","sourceRoot":"","sources":["../../../src/cors/routes/authorities.routes.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,WAAW,4CAAS,CAAC"}