alado 3.6.4 → 3.7.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.
- package/README.md +15 -11
- package/dist/alado-server/alado-server.js +3 -1
- package/dist/alado-server/alado-server.js.map +1 -1
- package/dist/constants/reg-exp.d.ts +0 -1
- package/dist/constants/reg-exp.js +1 -2
- package/dist/constants/reg-exp.js.map +1 -1
- package/dist/decorators/access-control.js +2 -0
- package/dist/decorators/access-control.js.map +1 -1
- package/dist/decorators/define-request.js +2 -0
- package/dist/decorators/define-request.js.map +1 -1
- package/dist/decorators/define-response.js +2 -0
- package/dist/decorators/define-response.js.map +1 -1
- package/dist/decorators/http.js +2 -0
- package/dist/decorators/http.js.map +1 -1
- package/dist/decorators/registered-members.d.ts +2 -0
- package/dist/decorators/registered-members.js +18 -0
- package/dist/decorators/registered-members.js.map +1 -0
- package/dist/decorators/with-auth.js +2 -0
- package/dist/decorators/with-auth.js.map +1 -1
- package/dist/factory/open-api-doc-factory.js +14 -13
- package/dist/factory/open-api-doc-factory.js.map +1 -1
- package/dist/helpers/parser/authenticate.js +34 -0
- package/dist/helpers/parser/authenticate.js.map +1 -1
- package/dist/helpers/parser/body-parser.d.ts +25 -6
- package/dist/helpers/parser/body-parser.js +169 -77
- package/dist/helpers/parser/body-parser.js.map +1 -1
- package/dist/helpers/parser/xml-parser.js +20 -8
- package/dist/helpers/parser/xml-parser.js.map +1 -1
- package/dist/helpers/validate/alado-options/validate-alado-options.js +8 -0
- package/dist/helpers/validate/alado-options/validate-alado-options.js.map +1 -1
- package/dist/helpers/validate/built-in/validator.d.ts +1 -1
- package/dist/helpers/validate/built-in/validator.js +13 -3
- package/dist/helpers/validate/built-in/validator.js.map +1 -1
- package/dist/request-processor/request-processor.d.ts +6 -1
- package/dist/request-processor/request-processor.js +98 -31
- package/dist/request-processor/request-processor.js.map +1 -1
- package/dist/router/router.js +18 -2
- package/dist/router/router.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -497,17 +497,17 @@ validate.custom(fn); // starts with a custom rule
|
|
|
497
497
|
|
|
498
498
|
**String**
|
|
499
499
|
|
|
500
|
-
| Method
|
|
501
|
-
|
|
|
502
|
-
| `min(n)`
|
|
503
|
-
| `max(n)`
|
|
504
|
-
| `length(n)`
|
|
505
|
-
| `regex(pattern)`
|
|
506
|
-
| `email()`
|
|
507
|
-
| `uuid()`
|
|
508
|
-
| `objectId()`
|
|
509
|
-
| `url()`
|
|
510
|
-
| `trim()`
|
|
500
|
+
| Method | Description |
|
|
501
|
+
| ----------------- | ------------------------------------------------------------------------------------------------ |
|
|
502
|
+
| `min(n)` | Min length (string) or min value (number) |
|
|
503
|
+
| `max(n)` | Max length (string) or max value (number) |
|
|
504
|
+
| `length(n)` | Exact length |
|
|
505
|
+
| `regex(pattern)` | Must match RegExp |
|
|
506
|
+
| `email()` | Valid email format |
|
|
507
|
+
| `uuid()` | Valid UUID v4 |
|
|
508
|
+
| `objectId()` | Valid MongoDB ObjectId (24-char hex) |
|
|
509
|
+
| `url(protocols?)` | Valid URL (parsed by `new URL()`) whose protocol is in `protocols` (default `['http', 'https']`) |
|
|
510
|
+
| `trim()` | No leading/trailing whitespace |
|
|
511
511
|
|
|
512
512
|
**Number**
|
|
513
513
|
|
|
@@ -949,6 +949,10 @@ The `inputProperty` supports dot-notation and can point to any part of the reque
|
|
|
949
949
|
|
|
950
950
|
The resolved value from `handler` is set at `outputProperty` on the request object, making it available as `req.auth.user` in your handler.
|
|
951
951
|
|
|
952
|
+
The value at `inputProperty` is checked before `handler` runs (the rest of the request is validated only after authentication). If the route declares a validator for that field (for example `body.token` in the request DTO), that validator decides; otherwise only a string is accepted. Anything else, such as an object from a JSON body or an array from a repeated query key, gets the configured `error` and `handler` is not called.
|
|
953
|
+
|
|
954
|
+
When `inputProperty` reads a header, a query parameter or a path parameter, the request body is read only after authentication (and after access control, unless a rule reads `body.*`). A refused request never has its body parsed, and its connection is closed after the error response.
|
|
955
|
+
|
|
952
956
|
**Optional auth** — set `required: false` for soft checking (handler runs but failure doesn't block the request):
|
|
953
957
|
|
|
954
958
|
```ts
|
|
@@ -27,7 +27,9 @@ class AladoServer {
|
|
|
27
27
|
options.openApiDoc.route = `${(0, _helper_1.clearRoutePath)(options.openApiDoc.route)}`;
|
|
28
28
|
}
|
|
29
29
|
this.logger = options.logger || console;
|
|
30
|
-
|
|
30
|
+
// a deep copy: a shallow one would share `paths` and `components` with every other instance in
|
|
31
|
+
// the process, so one server's swagger.json would list the routes of all of them
|
|
32
|
+
this.openApiDocObject = { ...structuredClone(_const_1.defaultOpenApiDocObject), info: options.openApiDoc?.info || {} };
|
|
31
33
|
this.router = new _router_1.Router({
|
|
32
34
|
cors: {
|
|
33
35
|
enable: options.cors?.enable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alado-server.js","sourceRoot":"","sources":["../../src/alado-server/alado-server.ts"],"names":[],"mappings":";;;AAEA,mCAOgB;AAGhB,qCAAiC;AACjC,uCAA6C;AAC7C,qCAA+D;AAE/D,MAAa,WAAW;IACL,KAAK,CAAS;IACd,MAAM,CAAS;IACf,MAAM,CAAS;IACf,gBAAgB,CAAM;IAC/B,IAAI,CAAS;IACb,IAAI,CAAS;IACb,OAAO,CAAS;IACP,MAAM,CAAqB;IAE5C,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO,CAAC,UAAU,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACzC,CAAC;QACD,IAAA,8BAAoB,EAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,mBAAU,CAAC;QACzC,IAAI,OAAO,CAAC,UAAU,EAAE,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;IAEM,MAAM,CACX,IAAY,EACZ,OAAqB,EACrB,OAAiE;QAEjE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAU,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAEM,IAAI,CAAC,IAAY,EAAE,OAAqB,EAAE,OAAiD;QAChG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,EAA0B;QACrC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACnG,CAAC;IAEM,IAAI,CAAC,EAA2B;QACrC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAC9D,CAAC;CACF;AA1GD,kCA0GC"}
|
|
@@ -3,7 +3,6 @@ export declare const outputPropertyRegexp: RegExp;
|
|
|
3
3
|
export declare const startRouteRegexp: RegExp;
|
|
4
4
|
export declare const trimRouteRegexp: RegExp;
|
|
5
5
|
export declare const multiSlashRegExp: RegExp;
|
|
6
|
-
export declare const spaceRegExp: RegExp;
|
|
7
6
|
export declare const formDataRegExp: Record<string, RegExp>;
|
|
8
7
|
export declare const deprecatedJsonPropertiesRegExp: RegExp;
|
|
9
8
|
export declare const deprecatedJsonPropertiesHintRegExp: RegExp;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deprecatedJsonPropertiesHintRegExp = exports.deprecatedJsonPropertiesRegExp = exports.formDataRegExp = exports.
|
|
3
|
+
exports.deprecatedJsonPropertiesHintRegExp = exports.deprecatedJsonPropertiesRegExp = exports.formDataRegExp = exports.multiSlashRegExp = exports.trimRouteRegexp = exports.startRouteRegexp = exports.outputPropertyRegexp = exports.inputPropertyRegexp = void 0;
|
|
4
4
|
exports.inputPropertyRegexp = /^(headers|body|query|path)(\.[\w-]+)$/;
|
|
5
5
|
exports.outputPropertyRegexp = /^auth(\.[\w-]+)?$/;
|
|
6
6
|
exports.startRouteRegexp = /^\//;
|
|
7
7
|
exports.trimRouteRegexp = /\/$/;
|
|
8
8
|
exports.multiSlashRegExp = /\/+/g;
|
|
9
|
-
exports.spaceRegExp = /^\s+|\s+$/;
|
|
10
9
|
exports.formDataRegExp = {
|
|
11
10
|
name: /name="(.+?)"/,
|
|
12
11
|
value: /\r\n\r\n([\S\s]*)\r\n--$/,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reg-exp.js","sourceRoot":"","sources":["../../src/constants/reg-exp.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,uCAAuC,CAAC;AAC9D,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,gBAAgB,GAAW,KAAK,CAAC;AACjC,QAAA,eAAe,GAAW,KAAK,CAAC;AAChC,QAAA,gBAAgB,GAAW,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"reg-exp.js","sourceRoot":"","sources":["../../src/constants/reg-exp.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,uCAAuC,CAAC;AAC9D,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAE3C,QAAA,gBAAgB,GAAW,KAAK,CAAC;AACjC,QAAA,eAAe,GAAW,KAAK,CAAC;AAChC,QAAA,gBAAgB,GAAW,MAAM,CAAC;AAElC,QAAA,cAAc,GAA2B;IACpD,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,0BAA0B;IACjC,QAAQ,EAAE,kBAAkB;IAC5B,QAAQ,EAAE,wBAAwB;CACnC,CAAC;AAEF,8GAA8G;AAC9G,yEAAyE;AAC5D,QAAA,8BAA8B,GAAG,uEAAuE,CAAC;AACtH,gGAAgG;AAChG,sFAAsF;AACzE,QAAA,kCAAkC,GAAG,yDAAyD,CAAC"}
|
|
@@ -4,11 +4,13 @@ exports.accessControl = accessControl;
|
|
|
4
4
|
const _injector_1 = require("../injector/index.js");
|
|
5
5
|
const initialize_injector_1 = require("./initialize-injector");
|
|
6
6
|
const class_key_1 = require("./class-key");
|
|
7
|
+
const registered_members_1 = require("./registered-members");
|
|
7
8
|
function accessControl(configs) {
|
|
8
9
|
(0, initialize_injector_1.initializeInjector)();
|
|
9
10
|
return function (...args) {
|
|
10
11
|
const [controller, method,] = args;
|
|
11
12
|
const key = (0, class_key_1.memberKey)(controller, method);
|
|
13
|
+
(0, registered_members_1.assertNotRegistered)(key, 'accessControl');
|
|
12
14
|
_injector_1.injector.injected.accessControlMapping[key] = configs;
|
|
13
15
|
};
|
|
14
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-control.js","sourceRoot":"","sources":["../../src/decorators/access-control.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"access-control.js","sourceRoot":"","sources":["../../src/decorators/access-control.ts"],"names":[],"mappings":";;AAMA,sCAWC;AAhBD,yCAAqC;AACrC,+DAA2D;AAC3D,2CAAwC;AACxC,6DAA2D;AAE3D,SAAgB,aAAa,CAAC,OAAmC;IAC/D,IAAA,wCAAkB,GAAE,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC7B,MAAM,CACJ,UAAU,EACV,MAAM,EACP,GAAG,IAAI,CAAC;QACT,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAA,wCAAmB,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAC1C,oBAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.defineRequest = defineRequest;
|
|
|
4
4
|
const _injector_1 = require("../injector/index.js");
|
|
5
5
|
const initialize_injector_1 = require("./initialize-injector");
|
|
6
6
|
const class_key_1 = require("./class-key");
|
|
7
|
+
const registered_members_1 = require("./registered-members");
|
|
7
8
|
function defineRequest(request) {
|
|
8
9
|
(0, initialize_injector_1.initializeInjector)();
|
|
9
10
|
return function (...args) {
|
|
@@ -11,6 +12,7 @@ function defineRequest(request) {
|
|
|
11
12
|
_injector_1.injector.injected.requestMapping = {};
|
|
12
13
|
}
|
|
13
14
|
const key = (0, class_key_1.memberKey)(args[0], args[1]);
|
|
15
|
+
(0, registered_members_1.assertNotRegistered)(key, 'defineRequest');
|
|
14
16
|
const r = {};
|
|
15
17
|
for (const k in request) {
|
|
16
18
|
const dto = request[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-request.js","sourceRoot":"","sources":["../../src/decorators/define-request.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define-request.js","sourceRoot":"","sources":["../../src/decorators/define-request.ts"],"names":[],"mappings":";;AAOA,sCAgBC;AAtBD,yCAAqC;AAErC,+DAA2D;AAC3D,2CAAkD;AAClD,6DAA2D;AAE3D,SAAgB,aAAa,CAAC,OAAiD;IAC7E,IAAA,wCAAkB,GAAE,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC7B,IAAI,CAAC,oBAAQ,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;YACtC,oBAAQ,CAAC,QAAQ,CAAC,cAAc,GAAG,EAAE,CAAC;QACxC,CAAC;QACD,MAAM,GAAG,GAAW,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,IAAA,wCAAmB,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAgF,EAAE,CAAC;QAC1F,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAkB,CAAC,CAAC;YACxC,MAAM,SAAS,GAAuB,GAAG,CAAC,CAAC,CAAC,IAAA,oBAAQ,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACtE,CAAC,CAAC,CAAC,CAAC,GAAG,oBAAQ,CAAC,QAAQ,CAAC,0BAA0B,CAAC,SAAmB,CAAC,CAAC;YACzE,oBAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.defineResponse = defineResponse;
|
|
|
4
4
|
const _injector_1 = require("../injector/index.js");
|
|
5
5
|
const initialize_injector_1 = require("./initialize-injector");
|
|
6
6
|
const class_key_1 = require("./class-key");
|
|
7
|
+
const registered_members_1 = require("./registered-members");
|
|
7
8
|
function defineResponse(response) {
|
|
8
9
|
(0, initialize_injector_1.initializeInjector)();
|
|
9
10
|
return function (...args) {
|
|
@@ -12,6 +13,7 @@ function defineResponse(response) {
|
|
|
12
13
|
}
|
|
13
14
|
const [controller, method,] = args;
|
|
14
15
|
const key = (0, class_key_1.memberKey)(controller, method);
|
|
16
|
+
(0, registered_members_1.assertNotRegistered)(key, 'defineResponse');
|
|
15
17
|
_injector_1.injector.injected.responseMapping[key] = response;
|
|
16
18
|
};
|
|
17
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-response.js","sourceRoot":"","sources":["../../src/decorators/define-response.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define-response.js","sourceRoot":"","sources":["../../src/decorators/define-response.ts"],"names":[],"mappings":";;AAMA,wCAcC;AApBD,yCAAqC;AAErC,+DAA2D;AAC3D,2CAAwC;AACxC,6DAA2D;AAE3D,SAAgB,cAAc,CAAC,QAAuB;IACpD,IAAA,wCAAkB,GAAE,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC7B,IAAI,CAAC,oBAAQ,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;YACvC,oBAAQ,CAAC,QAAQ,CAAC,eAAe,GAAG,EAAE,CAAC;QACzC,CAAC;QACD,MAAM,CACJ,UAAU,EACV,MAAM,EACP,GAAG,IAAI,CAAC;QACT,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAA,wCAAmB,EAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;QAC3C,oBAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/decorators/http.js
CHANGED
|
@@ -12,6 +12,7 @@ const _injector_1 = require("../injector/index.js");
|
|
|
12
12
|
const initialize_injector_1 = require("./initialize-injector");
|
|
13
13
|
const class_key_1 = require("./class-key");
|
|
14
14
|
const controller_instances_1 = require("./controller-instances");
|
|
15
|
+
const registered_members_1 = require("./registered-members");
|
|
15
16
|
function callHttpMethod(httpMethod, path, options = {}) {
|
|
16
17
|
(0, initialize_injector_1.initializeInjector)();
|
|
17
18
|
const defaultDescription = `${httpMethod} ${path}`;
|
|
@@ -42,6 +43,7 @@ function callHttpMethod(httpMethod, path, options = {}) {
|
|
|
42
43
|
(request) => instance[method].call(controller_instances_1.controllerInstances.get(instance) ?? instance, request));
|
|
43
44
|
};
|
|
44
45
|
if (app) {
|
|
46
|
+
(0, registered_members_1.markRegistered)(key);
|
|
45
47
|
fn(app);
|
|
46
48
|
const shadowApp = _injector_1.injector.injected.shadowAppMapping[appId];
|
|
47
49
|
if (Array.isArray(shadowApp) && shadowApp.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/decorators/http.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/decorators/http.ts"],"names":[],"mappings":";;AA0DA,kBAEC;AAED,sBAEC;AAED,oBAEC;AAED,kBAEC;AAED,sBAEC;AAED,kBAEC;AAED,oBAEC;AApFD,mCAAgD;AAChD,yCAAqC;AAGrC,+DAA2D;AAC3D,2CAAwC;AACxC,iEAA6D;AAC7D,6DAAsD;AAEtD,SAAS,cAAc,CAAC,UAAsB,EAAE,IAAY,EAAE,UAAgC,EAAE;IAC9F,IAAA,wCAAkB,GAAE,CAAC;IACrB,MAAM,kBAAkB,GAAW,GAAG,UAAU,IAAI,IAAI,EAAE,CAAC;IAC3D,MAAM,gBAAgB,GAAW,UAAU,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,KAAK,GAAW,OAAO,EAAE,KAAK,IAAI,mBAAU,CAAC;IACnD,MAAM,GAAG,GAAgB,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO,UAAU,QAAa,EAAE,MAAc;QAC5C,MAAM,GAAG,GAAW,IAAA,qBAAS,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,EAAE,GAAG,CAAC,GAAgB,EAAQ,EAAE;YACpC,GAAG,CAAC,gBAAkF,CAAC,CACrF,IAAI,EACJ;gBACE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,kBAAkB;gBAC1C,IAAI,EAAE,oBAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,SAAS;gBACrD,aAAa,EAAE,oBAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,SAAS;gBACvE,OAAO,EAAE;oBACP,kBAAkB,EAAE,KAAK;oBACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,KAAK;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AAC;QACrD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,GAAG,CAAC,IAAY,EAAE,UAAgC,EAAE;IAClE,OAAO,cAAc,CAAC,mBAAU,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAgC,EAAE;IACpE,OAAO,cAAc,CAAC,mBAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,SAAgB,IAAI,CAAC,IAAY,EAAE,UAAgC,EAAE;IACnE,OAAO,cAAc,CAAC,mBAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,SAAgB,GAAG,CAAC,IAAY,EAAE,UAAgC,EAAE;IAClE,OAAO,cAAc,CAAC,mBAAU,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAgC,EAAE;IACpE,OAAO,cAAc,CAAC,mBAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,SAAgB,GAAG,CAAC,IAAY,EAAE,UAAgC,EAAE;IAClE,OAAO,cAAc,CAAC,mBAAU,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,IAAI,CAAC,IAAY,EAAE,UAAgC,EAAE;IACnE,OAAO,cAAc,CAAC,mBAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.markRegistered = markRegistered;
|
|
4
|
+
exports.assertNotRegistered = assertNotRegistered;
|
|
5
|
+
// Members whose route was registered the moment its HTTP decorator ran (the application already
|
|
6
|
+
// existed). Decorators apply bottom-up, so one written above @get/@post/... runs after that and
|
|
7
|
+
// its configuration would never reach the route.
|
|
8
|
+
const registeredMembers = new Set();
|
|
9
|
+
function markRegistered(key) {
|
|
10
|
+
registeredMembers.add(key);
|
|
11
|
+
}
|
|
12
|
+
function assertNotRegistered(key, decorator) {
|
|
13
|
+
if (registeredMembers.has(key)) {
|
|
14
|
+
throw new Error(`@${decorator} on ${key} is applied after its route was registered, so it would be ignored. ` +
|
|
15
|
+
`Place the HTTP method decorator (@get, @post, ...) above every other decorator of the method.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=registered-members.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-members.js","sourceRoot":"","sources":["../../src/decorators/registered-members.ts"],"names":[],"mappings":";;AAKA,wCAEC;AAED,kDAOC;AAhBD,gGAAgG;AAChG,gGAAgG;AAChG,iDAAiD;AACjD,MAAM,iBAAiB,GAAgB,IAAI,GAAG,EAAU,CAAC;AAEzD,SAAgB,cAAc,CAAC,GAAW;IACxC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAW,EAAE,SAAiB;IAChE,IAAI,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,IAAI,SAAS,OAAO,GAAG,sEAAsE;YAC3F,+FAA+F,CAClG,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -4,11 +4,13 @@ exports.withAuth = withAuth;
|
|
|
4
4
|
const _injector_1 = require("../injector/index.js");
|
|
5
5
|
const initialize_injector_1 = require("./initialize-injector");
|
|
6
6
|
const class_key_1 = require("./class-key");
|
|
7
|
+
const registered_members_1 = require("./registered-members");
|
|
7
8
|
function withAuth(requestAuthentication) {
|
|
8
9
|
(0, initialize_injector_1.initializeInjector)();
|
|
9
10
|
return function (...args) {
|
|
10
11
|
const [controller, method,] = args;
|
|
11
12
|
const key = (0, class_key_1.memberKey)(controller, method);
|
|
13
|
+
(0, registered_members_1.assertNotRegistered)(key, 'withAuth');
|
|
12
14
|
_injector_1.injector.injected.authMapping[key] = requestAuthentication;
|
|
13
15
|
};
|
|
14
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-auth.js","sourceRoot":"","sources":["../../src/decorators/with-auth.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"with-auth.js","sourceRoot":"","sources":["../../src/decorators/with-auth.ts"],"names":[],"mappings":";;AAMA,4BAWC;AAhBD,yCAAqC;AACrC,+DAA2D;AAC3D,2CAAwC;AACxC,6DAA2D;AAE3D,SAAgB,QAAQ,CAAC,qBAA4C;IACnE,IAAA,wCAAkB,GAAE,CAAC;IACrB,OAAO,UAAU,GAAG,IAAW;QAC7B,MAAM,CACJ,UAAU,EACV,MAAM,EACP,GAAG,IAAI,CAAC;QACT,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAA,wCAAmB,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACrC,oBAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -11,7 +11,8 @@ function openApiDocFactory(openApiMethod, openApiRoute, context, openApiDocObjec
|
|
|
11
11
|
openApiRoute = openApiRoute.toString().replace(/\/$/, '');
|
|
12
12
|
// Docs part
|
|
13
13
|
openApiDocObject.paths[openApiRoute] = openApiDocObject.paths[openApiRoute] || {};
|
|
14
|
-
|
|
14
|
+
// both are optional in a Context (the router fills in `request` only after this runs)
|
|
15
|
+
const openApiDoc = context.options?.openApiDoc;
|
|
15
16
|
openApiDocObject.paths[openApiRoute][openApiMethod] = { ...openApiDoc, parameters: [] };
|
|
16
17
|
const { title } = context;
|
|
17
18
|
if (context.auth) {
|
|
@@ -27,7 +28,7 @@ function openApiDocFactory(openApiMethod, openApiRoute, context, openApiDocObjec
|
|
|
27
28
|
}
|
|
28
29
|
openApiDocObject.paths[openApiRoute][openApiMethod].security = [{ [authStrategyName]: [] }];
|
|
29
30
|
}
|
|
30
|
-
const { headers, body, path, query, files } = context.request;
|
|
31
|
+
const { headers, body, path, query, files } = context.request || {};
|
|
31
32
|
if (headers) {
|
|
32
33
|
for (const header in headers) {
|
|
33
34
|
openApiDocObject.paths[openApiRoute][openApiMethod].parameters.push({
|
|
@@ -40,17 +41,17 @@ function openApiDocFactory(openApiMethod, openApiRoute, context, openApiDocObjec
|
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
44
|
+
// OpenAPI 3: every {param} of the path has to be declared, with required: true
|
|
45
|
+
for (const [, param,] of openApiRoute.matchAll(/\{([^}]+)\}/g)) {
|
|
46
|
+
const definition = path?.[param];
|
|
47
|
+
openApiDocObject.paths[openApiRoute][openApiMethod].parameters.push({
|
|
48
|
+
in: 'path',
|
|
49
|
+
name: param,
|
|
50
|
+
required: true,
|
|
51
|
+
schema: definition?.openApiDoc?.schema || { type: 'string' },
|
|
52
|
+
description: definition?.openApiDoc?.description,
|
|
53
|
+
example: definition?.openApiDoc?.example,
|
|
54
|
+
});
|
|
54
55
|
}
|
|
55
56
|
if (query) {
|
|
56
57
|
for (const param in query) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-api-doc-factory.js","sourceRoot":"","sources":["../../src/factory/open-api-doc-factory.ts"],"names":[],"mappings":";;AAQA,
|
|
1
|
+
{"version":3,"file":"open-api-doc-factory.js","sourceRoot":"","sources":["../../src/factory/open-api-doc-factory.ts"],"names":[],"mapp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,EAAE,CAAC;gBAC/B,CAAC;gBACD,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAE,MAAiB,IAAK,KAAgB,CAAC,GAAG,UAAU,CAAC;gBAC1F,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,GAAG;oBAC9D,CAAC,UAAU,CAAC,EAAE;wBACZ,WAAW;wBACX,OAAO,EAAE;4BACP,CAAC,mBAA6B,CAAC,EAAE;gCAC/B,MAAM,EAAE;oCACN,IAAI,EAAE,wBAAwB,MAAM,IAAI,KAAK,EAAE;iCAChD;6BACF;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,gBAAgB,CAAC,KAAK,CAAC,YAAsB,CAAC,CAAC,aAAuB,CAAC,CAAC,SAAS,GAAG;gBAClF,CAAC,UAAU,CAAC,EAAE;oBACZ,WAAW;oBACX,OAAO,EAAE;wBACP,CAAC,mBAA6B,CAAC,EAAE;4BAC/B,OAAO,EAAE,EAAE;yBACZ;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authenticate = authenticate;
|
|
4
4
|
const accessor_1 = require("../accessor");
|
|
5
|
+
const json_parser_1 = require("./json-parser");
|
|
6
|
+
/**
|
|
7
|
+
* The auth input is checked before the handler sees it: validation of the rest of the request runs
|
|
8
|
+
* only after authentication, so without this a JSON body or a repeated query key could hand the
|
|
9
|
+
* handler an object or an array (e.g. {"$ne": null}, a NoSQL operator) instead of a token.
|
|
10
|
+
* With a validator declared for the field (context.request.<part>.<name>) that validator decides;
|
|
11
|
+
* without one, only a string is accepted.
|
|
12
|
+
*/
|
|
13
|
+
async function isValidAuthInput(context, request, value) {
|
|
14
|
+
const [part, name,] = context.auth.inputProperty.split('.');
|
|
15
|
+
const definition = context.request?.[part]?.[name];
|
|
16
|
+
const handler = definition?.validation?.handler;
|
|
17
|
+
if (typeof handler !== 'function') {
|
|
18
|
+
return typeof value === 'string';
|
|
19
|
+
}
|
|
20
|
+
let input = value;
|
|
21
|
+
if (definition?.isJSON && typeof value === 'string') {
|
|
22
|
+
try {
|
|
23
|
+
input = (0, json_parser_1.parseJson)(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// the validator gets the raw string, as in request validation
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return Boolean(await handler.apply(request, [input]));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
5
36
|
async function authenticate(context, request) {
|
|
6
37
|
const { auth } = context;
|
|
7
38
|
const { required, handler, handlerContext, inputProperty, outputProperty, error } = auth;
|
|
@@ -9,6 +40,9 @@ async function authenticate(context, request) {
|
|
|
9
40
|
if (required && !authData) {
|
|
10
41
|
return error;
|
|
11
42
|
}
|
|
43
|
+
if (authData !== undefined && authData !== null && !(await isValidAuthInput(context, request, authData))) {
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
12
46
|
try {
|
|
13
47
|
const result = await handler.apply(handlerContext || {}, [authData]);
|
|
14
48
|
if (!result && required) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/helpers/parser/authenticate.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/helpers/parser/authenticate.ts"],"names":[],"mappings":";;AAoCA,oCAqBC;AAxDD,0CAAuD;AACvD,+CAA0C;AAE1C;;;;;;GAMG;AACH,KAAK,UAAU,gBAAgB,CAAC,OAAqB,EAAE,OAAY,EAAE,KAAc;IACjF,MAAM,CACJ,IAAI,EACJ,IAAI,EACL,GAAI,OAAO,CAAC,IAA8B,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,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AAC;QACzG,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,cAAc,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAA,sBAAW,EAAC,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,6EAA6E;QAC7E,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
2
|
+
export declare function mediaType(contentType: string | undefined): string;
|
|
2
3
|
export declare function isXmlContentType(contentType: string | undefined): boolean;
|
|
3
|
-
|
|
4
|
+
export declare function isJsonContentType(contentType: string | undefined): boolean;
|
|
5
|
+
type PartHeaders = {
|
|
4
6
|
name: string | null;
|
|
5
|
-
value: string | null;
|
|
6
7
|
filename: string | null;
|
|
7
8
|
mimetype: string | null;
|
|
8
9
|
};
|
|
10
|
+
type MultipartFile = {
|
|
11
|
+
name: string;
|
|
12
|
+
mimetype: string;
|
|
13
|
+
content: Buffer;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Header fields of one part. `headers` is the text before the blank line, read as latin1 (one
|
|
17
|
+
* char per byte); the field name is UTF-8 and is decoded back. filename="" is kept as '': it is
|
|
18
|
+
* what a browser sends for a file input left empty.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parsePartHeaders(headers: string): PartHeaders;
|
|
9
21
|
/**
|
|
10
|
-
* Splits
|
|
11
|
-
*
|
|
12
|
-
*
|
|
22
|
+
* Splits a multipart body without turning it into a string: delimiters are found with
|
|
23
|
+
* Buffer.indexOf, and a file's content is a subarray() of `raw` (same memory, no copy). Every
|
|
24
|
+
* search is bounded by the part it belongs to, so the whole body is scanned once.
|
|
25
|
+
* A part without its closing delimiter (a cut-off body) is dropped.
|
|
13
26
|
*/
|
|
14
|
-
export declare function
|
|
27
|
+
export declare function parseMultipartBody(raw: Buffer, boundary: string): {
|
|
28
|
+
fields: Array<[
|
|
29
|
+
string,
|
|
30
|
+
Buffer
|
|
31
|
+
]>;
|
|
32
|
+
files: MultipartFile[];
|
|
33
|
+
};
|
|
15
34
|
export declare function multipartBoundary(contentType: string): string | null;
|
|
16
35
|
export declare function bodyParser(req: IncomingMessage, res: OutgoingMessage, limit: number, acceptFiles?: boolean): Promise<any>;
|
|
17
36
|
export {};
|