alado 3.6.1 → 3.6.18
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 +11 -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/body-parser.d.ts +2 -0
- package/dist/helpers/parser/body-parser.js +40 -19
- package/dist/helpers/parser/body-parser.js.map +1 -1
- package/dist/helpers/parser/index.d.ts +1 -0
- package/dist/helpers/parser/index.js +1 -0
- package/dist/helpers/parser/index.js.map +1 -1
- package/dist/helpers/parser/json-parser.d.ts +23 -0
- package/dist/helpers/parser/json-parser.js +105 -0
- package/dist/helpers/parser/json-parser.js.map +1 -0
- 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/helpers/validate/context/validate-request-part.js +4 -1
- package/dist/helpers/validate/context/validate-request-part.js.map +1 -1
- package/dist/request-processor/request-processor.d.ts +6 -1
- package/dist/request-processor/request-processor.js +35 -13
- 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
|
|
|
@@ -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,KAAK,EAAE,CAAC;YAC9B,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,GAAG,IAAA,wBAAc,EAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAK,OAA6B,CAAC;QAC/D,IAAI,CAAC,gBAAgB,GAAG,EAAE,GAAG,gCAAuB,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,EA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AC;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,6D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,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":[],"mappings":";;AAQA,8CA+KC;AAtLD,qCAA0C;AAE1C,MAAM,eAAe,GAAG;IACtB,kBAAkB;IAClB,iBAAiB;CAClB,CAAC;AAEF,SAAgB,iBAAiB,CAC/B,aAAqB,EACrB,YAAoB,EACpB,OAAqB,EACrB,gBAAqB;IAErB,kBAAkB;IAClB,YAAY,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1D,YAAY;IACZ,gBAAgB,CAAC,KAAK,CAAC,Y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AE,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"}
|
|
@@ -1,5 +1,7 @@
|
|
|
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;
|
|
4
|
+
export declare function isJsonContentType(contentType: string | undefined): boolean;
|
|
3
5
|
type MultipartPart = {
|
|
4
6
|
name: string | null;
|
|
5
7
|
value: string | null;
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mediaType = mediaType;
|
|
3
4
|
exports.isXmlContentType = isXmlContentType;
|
|
5
|
+
exports.isJsonContentType = isJsonContentType;
|
|
4
6
|
exports.parseMultipartPart = parseMultipartPart;
|
|
5
7
|
exports.multipartBoundary = multipartBoundary;
|
|
6
8
|
exports.bodyParser = bodyParser;
|
|
7
9
|
const _const_1 = require("../../constants/index.js");
|
|
8
10
|
const stream_1 = require("stream");
|
|
9
11
|
const xml_parser_1 = require("./xml-parser");
|
|
12
|
+
const json_parser_1 = require("./json-parser");
|
|
10
13
|
const file_signature_1 = require("../validate/context/file-signature");
|
|
11
14
|
// "application/xml; charset=utf-8" is still XML, and so are +xml types such as SOAP 1.2's application/soap+xml
|
|
15
|
+
// media type without parameters, lower-cased: "Application/JSON; charset=utf-8" -> "application/json"
|
|
16
|
+
function mediaType(contentType) {
|
|
17
|
+
return (contentType || '').split(';')[0].trim().toLowerCase();
|
|
18
|
+
}
|
|
12
19
|
function isXmlContentType(contentType) {
|
|
13
|
-
const mime = (contentType
|
|
20
|
+
const mime = mediaType(contentType);
|
|
14
21
|
return mime === _const_1.ContentType.XML || mime === _const_1.ContentType.TEXT_XML || /^application\/[\w.+-]+\+xml$/.test(mime);
|
|
15
22
|
}
|
|
23
|
+
// application/json, and +json types such as application/merge-patch+json or application/problem+json
|
|
24
|
+
function isJsonContentType(contentType) {
|
|
25
|
+
const mime = mediaType(contentType);
|
|
26
|
+
return mime === _const_1.ContentType.JSON || /^application\/[\w.+-]+\+json$/.test(mime);
|
|
27
|
+
}
|
|
16
28
|
const partNameRegExp = /(?:^|[;\s])name="([^"]*)"/i;
|
|
17
29
|
const partFilenameRegExp = /(?:^|[;\s])filename="([^"]*)"/i;
|
|
18
30
|
const partContentTypeRegExp = /^content-type:([^\r\n]*)$/im;
|
|
@@ -34,10 +46,13 @@ function parseMultipartPart(item) {
|
|
|
34
46
|
const match = regExp.exec(headers);
|
|
35
47
|
return match && match[1] ? match[1] : null;
|
|
36
48
|
};
|
|
49
|
+
// filename="" is kept as '': it is what a browser sends for a file input left empty
|
|
50
|
+
const filenameMatch = partFilenameRegExp.exec(headers);
|
|
37
51
|
return {
|
|
38
52
|
name: pick(partNameRegExp),
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
// '' is a field or file sent empty, null a part without a well-formed value
|
|
54
|
+
value,
|
|
55
|
+
filename: filenameMatch ? filenameMatch[1] : null,
|
|
41
56
|
mimetype: pick(partContentTypeRegExp),
|
|
42
57
|
};
|
|
43
58
|
}
|
|
@@ -95,7 +110,8 @@ async function bodyParser(req, res, limit, acceptFiles = true) {
|
|
|
95
110
|
abortOversizedBody(req, res);
|
|
96
111
|
throw contentTooLarge;
|
|
97
112
|
}
|
|
98
|
-
|
|
113
|
+
const mime = mediaType(contentType);
|
|
114
|
+
if (mime === _const_1.ContentType.FORM_DATA) {
|
|
99
115
|
const boundary = multipartBoundary(req.headers['content-type']);
|
|
100
116
|
await new Promise((resolve, reject) => {
|
|
101
117
|
req.on('data', collectChunks(req, res, limit, received, reject));
|
|
@@ -118,10 +134,14 @@ async function bodyParser(req, res, limit, acceptFiles = true) {
|
|
|
118
134
|
// the body is parsed as a binary string (one char per byte) to keep file bytes intact;
|
|
119
135
|
// text (field names and values) is UTF-8 and has to be decoded back
|
|
120
136
|
const name = element.name && Buffer.from(element.name, 'binary').toString('utf8');
|
|
121
|
-
if (!name ||
|
|
137
|
+
if (!name || value === null) {
|
|
122
138
|
continue;
|
|
123
139
|
}
|
|
124
|
-
if (filename) {
|
|
140
|
+
if (filename !== null) {
|
|
141
|
+
// a file input left empty: no file was chosen
|
|
142
|
+
if (filename === '' && value === '') {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
125
145
|
if (!mimetype || !acceptFiles) {
|
|
126
146
|
continue;
|
|
127
147
|
}
|
|
@@ -144,7 +164,7 @@ async function bodyParser(req, res, limit, acceptFiles = true) {
|
|
|
144
164
|
}
|
|
145
165
|
formData.files.forEach((file) => {
|
|
146
166
|
const { name, stream, mimetype, size } = file;
|
|
147
|
-
const key = name.
|
|
167
|
+
const key = name.trim();
|
|
148
168
|
// a file named __proto__ would otherwise replace the prototype of request.files
|
|
149
169
|
if (_const_1.deprecatedJsonPropertiesRegExp.test(key)) {
|
|
150
170
|
return;
|
|
@@ -153,7 +173,7 @@ async function bodyParser(req, res, limit, acceptFiles = true) {
|
|
|
153
173
|
stream: stream,
|
|
154
174
|
// byte length of the content, not a private field of the stream
|
|
155
175
|
size,
|
|
156
|
-
mimetype: mimetype.
|
|
176
|
+
mimetype: mimetype.trim(),
|
|
157
177
|
};
|
|
158
178
|
file_signature_1.uploadedFileHeads.set(result.files[key], file.head);
|
|
159
179
|
});
|
|
@@ -168,23 +188,24 @@ async function bodyParser(req, res, limit, acceptFiles = true) {
|
|
|
168
188
|
req.on('end', () => {
|
|
169
189
|
body = concatChunks(received, 'utf8');
|
|
170
190
|
result.rawBody = body;
|
|
171
|
-
if (contentType
|
|
191
|
+
if (isJsonContentType(contentType) && !body) {
|
|
192
|
+
// no body at all (clients often send the header on every request): same as the other types
|
|
193
|
+
resolve();
|
|
194
|
+
}
|
|
195
|
+
else if (isJsonContentType(contentType)) {
|
|
172
196
|
try {
|
|
173
|
-
|
|
174
|
-
result.body = _const_1.deprecatedJsonPropertiesHintRegExp.test(body)
|
|
175
|
-
? JSON.parse(body, function (key, value) {
|
|
176
|
-
if (!_const_1.deprecatedJsonPropertiesRegExp.test(key)) {
|
|
177
|
-
return value;
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
: JSON.parse(body);
|
|
197
|
+
result.body = (0, json_parser_1.parseJson)(body);
|
|
181
198
|
resolve();
|
|
182
199
|
}
|
|
183
200
|
catch (e) {
|
|
184
|
-
|
|
201
|
+
// the depth message is ours; a SyntaxError's text is not passed on
|
|
202
|
+
reject({
|
|
203
|
+
statusCode: 400,
|
|
204
|
+
message: e instanceof json_parser_1.JsonDepthError ? `Invalid JSON body: ${e.message}` : `Invalid JSON body`,
|
|
205
|
+
});
|
|
185
206
|
}
|
|
186
207
|
}
|
|
187
|
-
else if (
|
|
208
|
+
else if (mime === _const_1.ContentType.X_WWW_FORM_URLENCODED) {
|
|
188
209
|
// URLSearchParams decodes %XX and '+', keeps '=' inside values and never throws
|
|
189
210
|
for (const [key, value,] of new URLSearchParams(body)) {
|
|
190
211
|
if (key && !_const_1.deprecatedJsonPropertiesRegExp.test(key)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;AAUA,8BAEC;AAED,4CAGC;AAGD,8CAGC;AAaD,gDAuBC;AAG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BAAqB,EAAE,CAAC;oBACtD,gFAAgF;oBAChF,KAAK,MAAM,CACT,GAAG,EACH,KAAK,EACN,IAAI,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC/B,IAAI,GAAG,IAAI,CAAC,uCAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;4BACrD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;wBAC3B,CAAC;oBACH,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;qBAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;oBACzC,IAAI,CAAC;wBACH,MAAM,CAAC,IAAI,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,CAAC;wBAC9B,OAAO,EAAE,CAAC;oBACZ,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACzE,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;oBACnB,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./access-control-checker"), exports);
|
|
18
18
|
__exportStar(require("./authenticate"), exports);
|
|
19
19
|
__exportStar(require("./body-parser"), exports);
|
|
20
|
+
__exportStar(require("./json-parser"), exports);
|
|
20
21
|
__exportStar(require("./query-parser"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/parser/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,iDAA+B;AAC/B,gDAA8B;AAC9B,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/parser/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B;AAC9B,iDAA+B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const MAX_JSON_DEPTH: number;
|
|
2
|
+
export declare class JsonDepthError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Whether arrays and objects nest deeper than `limit` (the outermost one is level 1). Reads the
|
|
7
|
+
* text, not the parsed value, so a deep document is refused before JSON.parse spends time building
|
|
8
|
+
* it, and stops at the first level past the limit. Brackets inside strings do not count.
|
|
9
|
+
*/
|
|
10
|
+
export declare function jsonDepthExceeds(text: string, limit?: number): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Deletes forbidden keys (__proto__, constructor, ...) from a JSON.parse result, at any depth.
|
|
13
|
+
* Iterative, so no nesting depth can overflow the stack. JSON.parse defines "__proto__" as an own
|
|
14
|
+
* data property, so `delete` removes it without touching the prototype.
|
|
15
|
+
*/
|
|
16
|
+
export declare function removeForbiddenKeys(root: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* JSON.parse without forbidden keys and without nesting deeper than MAX_JSON_DEPTH (JsonDepthError).
|
|
19
|
+
* A reviver would take V8 off its fast JSON path and run for every value (about 7x slower on a
|
|
20
|
+
* 1 MB body); parsing plainly and walking the result afterwards, only when the text can contain
|
|
21
|
+
* such a key, gives the same result.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseJson(text: string): unknown;
|