configurapi 2.0.1 → 2.1.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/dist/configurapi.js +6 -2
- package/dist/entities/config.js +6 -6
- package/dist/entities/event.js +16 -18
- package/dist/entities/identity.js +9 -9
- package/dist/entities/policy.d.ts +0 -1
- package/dist/entities/policyHandlerLoader.js +3 -3
- package/dist/entities/request.d.ts +0 -1
- package/dist/entities/route.d.ts +0 -1
- package/dist/entities/service.d.ts +0 -1
- package/dist/entities/service.js +13 -2
- package/dist/interfaces/iPolicy.d.ts +0 -1
- package/dist/interfaces/iPolicyHandlerLoader.d.ts +1 -1
- package/dist/interfaces/iRequest.d.ts +0 -1
- package/dist/interfaces/iRoute.d.ts +0 -1
- package/dist/interfaces/logLevel.js +2 -2
- package/dist/interfaces/result.js +1 -1
- package/package.json +4 -4
package/dist/configurapi.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./entities/config"), exports);
|
package/dist/entities/config.js
CHANGED
|
@@ -14,15 +14,15 @@ class Config {
|
|
|
14
14
|
this.events = events;
|
|
15
15
|
}
|
|
16
16
|
static getPathParentDir(path) {
|
|
17
|
-
if (!path_1.isAbsolute(path)) {
|
|
18
|
-
path = path_1.resolve(process.cwd(), path);
|
|
17
|
+
if (!(0, path_1.isAbsolute)(path)) {
|
|
18
|
+
path = (0, path_1.resolve)(process.cwd(), path);
|
|
19
19
|
}
|
|
20
|
-
return path_1.parse(path).dir;
|
|
20
|
+
return (0, path_1.parse)(path).dir;
|
|
21
21
|
}
|
|
22
22
|
static load(path) {
|
|
23
23
|
let content = "";
|
|
24
24
|
try {
|
|
25
|
-
content = fs_1.readFileSync(path, 'utf8');
|
|
25
|
+
content = (0, fs_1.readFileSync)(path, 'utf8');
|
|
26
26
|
}
|
|
27
27
|
catch (error) {
|
|
28
28
|
throw new NestedError(`Failed to load '${path}'`, error);
|
|
@@ -30,7 +30,7 @@ class Config {
|
|
|
30
30
|
return this.parse(content, this.getPathParentDir(path));
|
|
31
31
|
}
|
|
32
32
|
static parse(content, parentDirectory) {
|
|
33
|
-
let document = js_yaml_1.load(content);
|
|
33
|
+
let document = (0, js_yaml_1.load)(content);
|
|
34
34
|
if (document instanceof Object) {
|
|
35
35
|
return new Config(this.parseImport(document, parentDirectory), this.parseApi(document));
|
|
36
36
|
}
|
|
@@ -47,7 +47,7 @@ class Config {
|
|
|
47
47
|
}
|
|
48
48
|
for (let module of document['import']) {
|
|
49
49
|
if (module.startsWith('.')) {
|
|
50
|
-
module = path_1.resolve(parentDirectory, module);
|
|
50
|
+
module = (0, path_1.resolve)(parentDirectory, module);
|
|
51
51
|
}
|
|
52
52
|
result.push(module);
|
|
53
53
|
}
|
package/dist/entities/event.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver,
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return value;
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8
7
|
};
|
|
9
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver,
|
|
10
|
-
if (!
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return privateMap.get(receiver);
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
12
|
};
|
|
15
|
-
var
|
|
13
|
+
var _Event_versionRegExp;
|
|
16
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
15
|
exports.Event = void 0;
|
|
18
16
|
const inflection_1 = require("inflection");
|
|
@@ -20,8 +18,8 @@ const uuid_1 = require("uuid");
|
|
|
20
18
|
const response_1 = require("./response");
|
|
21
19
|
class Event {
|
|
22
20
|
constructor(request) {
|
|
23
|
-
|
|
24
|
-
this.id = uuid_1.v4();
|
|
21
|
+
_Event_versionRegExp.set(this, void 0);
|
|
22
|
+
this.id = (0, uuid_1.v4)();
|
|
25
23
|
if ('query' in request && 'correlationid' in request.query) {
|
|
26
24
|
this.correlationId = request.query['correlationid'].toString();
|
|
27
25
|
}
|
|
@@ -31,7 +29,7 @@ class Event {
|
|
|
31
29
|
else {
|
|
32
30
|
this.correlationId = this.id;
|
|
33
31
|
}
|
|
34
|
-
__classPrivateFieldSet(this,
|
|
32
|
+
__classPrivateFieldSet(this, _Event_versionRegExp, new RegExp("^v\\d+(\\.\\d+)*$"), "f");
|
|
35
33
|
this.params = {};
|
|
36
34
|
this.name = request.name || "";
|
|
37
35
|
this.request = request;
|
|
@@ -43,7 +41,7 @@ class Event {
|
|
|
43
41
|
if (segments.length === 0)
|
|
44
42
|
return;
|
|
45
43
|
//Extract version, if any.
|
|
46
|
-
if (__classPrivateFieldGet(this,
|
|
44
|
+
if (__classPrivateFieldGet(this, _Event_versionRegExp, "f").test(segments[0])) {
|
|
47
45
|
this.version = segments[0];
|
|
48
46
|
segments = segments.slice(1);
|
|
49
47
|
}
|
|
@@ -59,7 +57,7 @@ class Event {
|
|
|
59
57
|
}
|
|
60
58
|
if (resource.length === 0)
|
|
61
59
|
break;
|
|
62
|
-
let singularizedResource = inflection_1.singularize(resource);
|
|
60
|
+
let singularizedResource = (0, inflection_1.singularize)(resource);
|
|
63
61
|
//Change 'get' to 'list'
|
|
64
62
|
if (!resourceId && this.method == 'get') {
|
|
65
63
|
this.method = 'list';
|
|
@@ -151,4 +149,4 @@ class Event {
|
|
|
151
149
|
}
|
|
152
150
|
}
|
|
153
151
|
exports.Event = Event;
|
|
154
|
-
|
|
152
|
+
_Event_versionRegExp = new WeakMap();
|
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Identity = void 0;
|
|
4
4
|
class Identity {
|
|
5
|
-
constructor(identity) {
|
|
6
|
-
this._claims = [];
|
|
7
|
-
this._claimsTable = new Map();
|
|
8
|
-
this.id = identity?.id;
|
|
9
|
-
this.claims = identity?.claims || [];
|
|
10
|
-
this.issuer = identity?.issuer;
|
|
11
|
-
this.name = identity?.name;
|
|
12
|
-
this.email = identity?.email;
|
|
13
|
-
}
|
|
14
5
|
get claims() {
|
|
15
6
|
return this._claims;
|
|
16
7
|
}
|
|
@@ -27,6 +18,15 @@ class Identity {
|
|
|
27
18
|
getClaimId(type, value, scope) {
|
|
28
19
|
return `${scope || ''}::${type || ''}::${value || ''}`;
|
|
29
20
|
}
|
|
21
|
+
constructor(identity) {
|
|
22
|
+
this._claims = [];
|
|
23
|
+
this._claimsTable = new Map();
|
|
24
|
+
this.id = identity?.id;
|
|
25
|
+
this.claims = identity?.claims || [];
|
|
26
|
+
this.issuer = identity?.issuer;
|
|
27
|
+
this.name = identity?.name;
|
|
28
|
+
this.email = identity?.email;
|
|
29
|
+
}
|
|
30
30
|
hasClaim(type, valueOrValues, scopeOrScopes) {
|
|
31
31
|
if (!this.claims)
|
|
32
32
|
return false;
|
|
@@ -24,12 +24,12 @@ class PolicyHandlerLoader {
|
|
|
24
24
|
this.loadHandler(exports);
|
|
25
25
|
}
|
|
26
26
|
loadCustomHandlers(directory) {
|
|
27
|
-
const absoultePath = path_1.resolve(process.cwd(), directory);
|
|
27
|
+
const absoultePath = (0, path_1.resolve)(process.cwd(), directory);
|
|
28
28
|
try {
|
|
29
|
-
let paths = fs_1.readdirSync(absoultePath);
|
|
29
|
+
let paths = (0, fs_1.readdirSync)(absoultePath);
|
|
30
30
|
for (const path of paths) {
|
|
31
31
|
let filePath = `${absoultePath}/${path}`;
|
|
32
|
-
let stat = fs_1.lstatSync(filePath);
|
|
32
|
+
let stat = (0, fs_1.lstatSync)(filePath);
|
|
33
33
|
if (stat.isFile() && path.match(/\.[jt]s$/i) !== null) {
|
|
34
34
|
this.load(absoultePath + "/" + path.replace(/\.[jt]s$/i, ''));
|
|
35
35
|
}
|
package/dist/entities/route.d.ts
CHANGED
package/dist/entities/service.js
CHANGED
|
@@ -18,7 +18,7 @@ class Service extends events_1.EventEmitter {
|
|
|
18
18
|
this.loader.load(module);
|
|
19
19
|
}
|
|
20
20
|
let customHandlerPath = 'handlers';
|
|
21
|
-
if (fs_1.existsSync(customHandlerPath)) {
|
|
21
|
+
if ((0, fs_1.existsSync)(customHandlerPath)) {
|
|
22
22
|
this.loader.loadCustomHandlers(customHandlerPath);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
@@ -43,7 +43,18 @@ class Service extends events_1.EventEmitter {
|
|
|
43
43
|
}
|
|
44
44
|
async process(event) {
|
|
45
45
|
if (!this.isReady) {
|
|
46
|
-
|
|
46
|
+
try {
|
|
47
|
+
await this.onStartPromise;
|
|
48
|
+
await this._handleEvent('on_first_request', event);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
try {
|
|
52
|
+
await this._handleError(event, error);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
47
58
|
this.isReady = true;
|
|
48
59
|
}
|
|
49
60
|
let startTime = perf_hooks_1.performance.now();
|
|
@@ -9,7 +9,7 @@ var LogLevel;
|
|
|
9
9
|
LogLevel["Warn"] = "warn";
|
|
10
10
|
LogLevel["Error"] = "error";
|
|
11
11
|
LogLevel["None"] = "none";
|
|
12
|
-
})(LogLevel
|
|
12
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
13
13
|
(function (LogLevel) {
|
|
14
14
|
const LogLevelRank = {
|
|
15
15
|
[LogLevel.Debug]: 100,
|
|
@@ -23,4 +23,4 @@ var LogLevel;
|
|
|
23
23
|
return (LogLevelRank[l1?.toString()] || 0) >= (LogLevelRank[l2?.toString()] || 0);
|
|
24
24
|
}
|
|
25
25
|
LogLevel.gte = gte;
|
|
26
|
-
})(LogLevel
|
|
26
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configurapi",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A configurable API framework",
|
|
5
5
|
"main": "dist/configurapi.js",
|
|
6
6
|
"typings": "dist/configurapi.d.ts",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"@types/js-yaml": "^4.0.5",
|
|
29
29
|
"@types/mocha": "^5.2.6",
|
|
30
30
|
"@types/nested-error-stacks": "^2.1.0",
|
|
31
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^20.11.24",
|
|
32
32
|
"@types/uuid": "^8.3.4",
|
|
33
33
|
"chai": "4.x.x",
|
|
34
34
|
"deep-equal": "^1.0.1",
|
|
35
35
|
"mocha": "6.1.x",
|
|
36
|
-
"ts-node": "^
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
37
37
|
"typemoq": "^2.1.0",
|
|
38
|
-
"typescript": "^3.
|
|
38
|
+
"typescript": "^5.3.3"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|