@flink-app/management-api-plugin 0.11.0 → 0.11.4-next.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/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.ts +1 -1
- package/.flink/start.ts +1 -1
- package/dist/.flink/generated-schemas.json +270 -0
- package/dist/.flink/generatedHandlers.js +6 -2
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas.json +722 -0
- package/dist/.flink/start.js +1 -1
- package/dist/src/handlers/Management/Get.d.ts +7 -0
- package/dist/src/handlers/Management/Get.js +53 -0
- package/dist/src/handlers/Management/GetManagement.js +11 -13
- package/dist/src/handlers/User/DeleteByUserid.js +20 -22
- package/dist/src/handlers/User/GetByUserid.js +20 -22
- package/dist/src/handlers/User/GetList.d.ts +1 -1
- package/dist/src/handlers/User/GetList.js +21 -23
- package/dist/src/handlers/User/GetMe.js +23 -25
- package/dist/src/handlers/User/Post.d.ts +1 -1
- package/dist/src/handlers/User/Post.js +38 -40
- package/dist/src/handlers/User/PostLogin.d.ts +1 -1
- package/dist/src/handlers/User/PostLogin.js +33 -35
- package/dist/src/handlers/User/PutByUserid.js +44 -46
- package/dist/src/index.js +6 -2
- package/dist/src/models/ManagementApi.js +1 -1
- package/dist/src/schemas/ManagementApi.d.ts +25 -0
- package/dist/src/schemas/ManagementApi.js +8 -0
- package/dist/src/utils/bcrypt.js +2 -3
- package/package.json +34 -34
- package/tsconfig.json +21 -21
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -47,51 +47,49 @@ exports.Route = {
|
|
|
47
47
|
// type Params = {
|
|
48
48
|
// userid: string;
|
|
49
49
|
// };
|
|
50
|
-
var PutUserByUserid = function (_a) {
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (existingUser !=
|
|
65
|
-
|
|
66
|
-
return [2 /*return*/, flink_1.conflict("Username already taken")];
|
|
67
|
-
}
|
|
50
|
+
var PutUserByUserid = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
51
|
+
var model, existingUser, salt, hash, updated;
|
|
52
|
+
var ctx = _b.ctx, req = _b.req;
|
|
53
|
+
return __generator(this, function (_c) {
|
|
54
|
+
switch (_c.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
model = req.body;
|
|
57
|
+
if (!(model.username != null)) return [3 /*break*/, 2];
|
|
58
|
+
return [4 /*yield*/, ctx.repos.managementuserRepo.getOne({
|
|
59
|
+
username: model.username,
|
|
60
|
+
})];
|
|
61
|
+
case 1:
|
|
62
|
+
existingUser = _c.sent();
|
|
63
|
+
if (existingUser != null) {
|
|
64
|
+
if (existingUser._id != req.params.userid) {
|
|
65
|
+
return [2 /*return*/, (0, flink_1.conflict)("Username already taken")];
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
67
|
+
}
|
|
68
|
+
_c.label = 2;
|
|
69
|
+
case 2:
|
|
70
|
+
if (!(model.password != null)) return [3 /*break*/, 5];
|
|
71
|
+
return [4 /*yield*/, (0, bcrypt_1.genSalt)(10)];
|
|
72
|
+
case 3:
|
|
73
|
+
salt = _c.sent();
|
|
74
|
+
return [4 /*yield*/, (0, bcrypt_1.encrypt)(model.password, salt)];
|
|
75
|
+
case 4:
|
|
76
|
+
hash = _c.sent();
|
|
77
|
+
model.password = hash;
|
|
78
|
+
model.salt = salt;
|
|
79
|
+
_c.label = 5;
|
|
80
|
+
case 5: return [4 /*yield*/, ctx.repos.managementuserRepo.updateOne(req.params.userid, model)];
|
|
81
|
+
case 6:
|
|
82
|
+
updated = _c.sent();
|
|
83
|
+
if (updated == null) {
|
|
84
|
+
return [2 /*return*/, (0, flink_1.notFound)()];
|
|
85
|
+
}
|
|
86
|
+
return [2 /*return*/, {
|
|
87
|
+
data: (0, ManagementUserViewModel_1.GetManagementUserViewModel)(updated),
|
|
88
|
+
status: 200,
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
93
91
|
});
|
|
94
|
-
};
|
|
92
|
+
}); };
|
|
95
93
|
exports.default = PutUserByUserid;
|
|
96
94
|
exports.__assumedHttpMethod = "put", exports.__file = "PutByUserid.ts", exports.__query = [], exports.__params = [];
|
|
97
95
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" } }, "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "_id": { "type": "string" }, "username": { "type": "string" } }, "required": ["_id", "username"], "definitions": {} } };
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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];
|
|
@@ -166,7 +170,7 @@ function init(app, options) {
|
|
|
166
170
|
next();
|
|
167
171
|
}
|
|
168
172
|
catch (ex) {
|
|
169
|
-
res.status(401).json(flink_1.unauthorized());
|
|
173
|
+
res.status(401).json((0, flink_1.unauthorized)());
|
|
170
174
|
}
|
|
171
175
|
}
|
|
172
176
|
});
|
|
@@ -8,4 +8,4 @@ var ManagementApiType;
|
|
|
8
8
|
ManagementApiType["action"] = "ACTION";
|
|
9
9
|
ManagementApiType["debug"] = "DEBUG";
|
|
10
10
|
ManagementApiType["notification"] = "NOTIFICATION";
|
|
11
|
-
})(ManagementApiType
|
|
11
|
+
})(ManagementApiType || (exports.ManagementApiType = ManagementApiType = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Handler, HandlerConfigWithMethod } from "@flink-app/flink";
|
|
2
|
+
export interface ManagementApiEndpoint {
|
|
3
|
+
config: HandlerConfigWithMethod;
|
|
4
|
+
handlerFn: Handler<any>;
|
|
5
|
+
}
|
|
6
|
+
export declare enum ManagementApiType {
|
|
7
|
+
user = "USER",
|
|
8
|
+
managementUser = "MANAGEMENT_USER"
|
|
9
|
+
}
|
|
10
|
+
export interface ManagementApiModule {
|
|
11
|
+
id: string;
|
|
12
|
+
type: ManagementApiType;
|
|
13
|
+
endpoints: ManagementApiEndpoint[];
|
|
14
|
+
ui: Boolean;
|
|
15
|
+
uiSettings?: {
|
|
16
|
+
title: string;
|
|
17
|
+
icon: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ManagementApiOptions {
|
|
21
|
+
token: string;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
jwtSecret: string;
|
|
24
|
+
modules: ManagementApiModule[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManagementApiType = void 0;
|
|
4
|
+
var ManagementApiType;
|
|
5
|
+
(function (ManagementApiType) {
|
|
6
|
+
ManagementApiType["user"] = "USER";
|
|
7
|
+
ManagementApiType["managementUser"] = "MANAGEMENT_USER";
|
|
8
|
+
})(ManagementApiType = exports.ManagementApiType || (exports.ManagementApiType = {}));
|
package/dist/src/utils/bcrypt.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.encrypt = encrypt;
|
|
7
|
+
exports.genSalt = genSalt;
|
|
7
8
|
var bcrypt_1 = __importDefault(require("bcrypt"));
|
|
8
9
|
function encrypt(password, salt) {
|
|
9
10
|
return new Promise(function (resolve, reject) {
|
|
@@ -14,7 +15,6 @@ function encrypt(password, salt) {
|
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
exports.encrypt = encrypt;
|
|
18
18
|
function genSalt(rounds) {
|
|
19
19
|
if (rounds === void 0) { rounds = 10; }
|
|
20
20
|
return new Promise(function (resolve, reject) {
|
|
@@ -25,4 +25,3 @@ function genSalt(rounds) {
|
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
exports.genSalt = genSalt;
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
"name": "@flink-app/management-api-plugin",
|
|
3
|
+
"version": "0.11.4-next.0",
|
|
4
|
+
"description": "Flink plugin that makes it possible to expose management api:s for other plugins",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\"",
|
|
7
|
+
"build": "flink build",
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"watch": "nodemon --exec \"flink build\"",
|
|
10
|
+
"postinstall": "flink generate-schemas"
|
|
11
|
+
},
|
|
12
|
+
"author": "johan@frost.se",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"types": "dist/src/index.d.ts",
|
|
18
|
+
"main": "dist/src/index.js",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"bcrypt": "^5.0.1",
|
|
21
|
+
"express": "^4.17.1",
|
|
22
|
+
"jsonwebtoken": "^8.5.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@flink-app/flink": "^0.11.4-next.0",
|
|
26
|
+
"@types/bcrypt": "^5.0.0",
|
|
27
|
+
"@types/express": "4.17.11",
|
|
28
|
+
"@types/express-fileupload": "^1.1.7",
|
|
29
|
+
"@types/jsonwebtoken": "^8.5.4",
|
|
30
|
+
"@types/mongodb": "3.6.12",
|
|
31
|
+
"@types/node": "^22.10.1",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "5.6.2"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "6a44df1b6601c86ea3402750b939784d003202c3"
|
|
36
36
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": ["esnext", "es2016"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": false,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"checkJs": true,
|
|
19
|
+
"outDir": "dist"
|
|
20
|
+
},
|
|
21
|
+
"include": ["./src/*"],
|
|
22
|
+
"exclude": ["./node_modules/**"]
|
|
23
23
|
}
|