@flink-app/management-api-plugin 0.12.1-alpha.4 → 0.12.1-alpha.44
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 +2 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/start.d.ts +2 -0
- package/dist/.flink/start.js +2 -1
- package/package.json +4 -4
- package/readme.md +177 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
|
|
3
3
|
import * as GetManagement_0 from "../src/handlers/Management/GetManagement";
|
|
4
4
|
import * as DeleteByUserid_0 from "../src/handlers/User/DeleteByUserid";
|
package/.flink/generatedJobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredJobs } from "@flink-app/flink";
|
|
3
3
|
export const jobs = [];
|
|
4
4
|
autoRegisteredJobs.push(...jobs);
|
package/.flink/generatedRepos.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
import ManagementUserRepo from "../src/repos/ManagementUserRepo";
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ import { PostUserLoginRes } from "../../src/schemas/User/PostLoginRes";
|
|
|
15
15
|
import { PutUserByUseridReq } from "../../src/schemas/User/PutByUseridReq";
|
|
16
16
|
import { PutUserByUseridRes } from "../../src/schemas/User/PutByUseridRes";
|
|
17
17
|
|
|
18
|
-
// Generated
|
|
18
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
19
19
|
export interface GetManagement_6_ReqSchema extends GetManagementReq {}
|
|
20
20
|
|
|
21
21
|
export interface GetManagement_6_ResSchema extends GetManagementRes {}
|
package/.flink/start.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import "./generatedHandlers";
|
|
3
3
|
import "./generatedRepos";
|
|
4
4
|
import "./generatedJobs";
|
|
5
5
|
import "../src/index";
|
|
6
|
+
export default {}; // Export an empty object to make it a module
|
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.handlers = void 0;
|
|
27
|
-
// Generated
|
|
27
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
28
28
|
var flink_1 = require("@flink-app/flink");
|
|
29
29
|
var DeleteByUserid_0 = __importStar(require("../src/handlers/User/DeleteByUserid"));
|
|
30
30
|
var GetByUserid_1 = __importStar(require("../src/handlers/User/GetByUserid"));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jobs = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.jobs = [];
|
|
7
7
|
flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.repos = void 0;
|
|
7
|
-
// Generated
|
|
7
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
8
8
|
var flink_1 = require("@flink-app/flink");
|
|
9
9
|
var ManagementUserRepo_1 = __importDefault(require("../src/repos/ManagementUserRepo"));
|
|
10
10
|
exports.repos = [{ collectionName: "managementuser", repoInstanceName: "managementUserRepo", Repo: ManagementUserRepo_1.default }];
|
package/dist/.flink/start.d.ts
CHANGED
package/dist/.flink/start.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated Sun Nov 23 2025 14:20:53 GMT+0100 (Central European Standard Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
7
7
|
require("../src/index");
|
|
8
|
+
exports.default = {}; // Export an empty object to make it a module
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/management-api-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.44",
|
|
4
4
|
"description": "Flink plugin that makes it possible to expose management api:s for other plugins",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
7
7
|
"build": "flink build",
|
|
8
|
-
"
|
|
8
|
+
"prepare": "npm run build",
|
|
9
9
|
"watch": "nodemon --exec \"flink build\""
|
|
10
10
|
},
|
|
11
11
|
"author": "johan@frost.se",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"jsonwebtoken": "^8.5.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@flink-app/flink": "^0.12.1-alpha.
|
|
24
|
+
"@flink-app/flink": "^0.12.1-alpha.44",
|
|
25
25
|
"@types/bcrypt": "^5.0.0",
|
|
26
26
|
"@types/express": "4.17.11",
|
|
27
27
|
"@types/express-fileupload": "^1.1.7",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-node": "^9.1.1",
|
|
31
31
|
"typescript": "5.4.5"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "4243e3b3cd6d4e1ca001a61baa8436bf2bbe4113"
|
|
34
34
|
}
|
package/readme.md
CHANGED
|
@@ -1,51 +1,202 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flink-app/management-api-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Flink plugin that provides a secure management API system with built-in user authentication and module registration. This plugin enables other plugins to expose their own management endpoints through a centralized API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Built-in user management system with authentication
|
|
8
|
+
- JWT-based token authentication
|
|
9
|
+
- Module-based architecture for extensibility
|
|
10
|
+
- Token or JWT authentication for all endpoints
|
|
11
|
+
- Automatic endpoint registration for modules
|
|
12
|
+
- MongoDB-backed user storage
|
|
13
|
+
- Password hashing with bcrypt
|
|
8
14
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
Install plugin to your flink app project:
|
|
15
|
+
## Installation
|
|
12
16
|
|
|
13
|
-
```
|
|
14
|
-
npm
|
|
17
|
+
```bash
|
|
18
|
+
npm install @flink-app/management-api-plugin
|
|
15
19
|
```
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
## Usage
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
import { managementApiPlugin } from "@flink-app/management-api-plugin";
|
|
23
|
+
### Basic Setup
|
|
21
24
|
|
|
25
|
+
```typescript
|
|
26
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
27
|
+
import { managementApiPlugin } from "@flink-app/management-api-plugin";
|
|
22
28
|
|
|
23
29
|
function start() {
|
|
24
30
|
new FlinkApp<AppContext>({
|
|
25
31
|
name: "My app",
|
|
26
32
|
plugins: [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
managementApiPlugin({
|
|
34
|
+
token: "SECRET_TOKEN_USED_TO_COMMUNICATE_WITH_THE_API",
|
|
35
|
+
jwtSecret: "JWT_SECRET_USED_TO_GENERATE_LOGGED_IN_TOKENS",
|
|
36
|
+
modules: [],
|
|
37
|
+
baseUrl: "/managementapi", // optional, defaults to /managementapi
|
|
38
|
+
}),
|
|
33
39
|
],
|
|
34
40
|
}).start();
|
|
35
41
|
}
|
|
36
42
|
```
|
|
37
43
|
|
|
38
|
-
##
|
|
44
|
+
## Configuration Options
|
|
45
|
+
|
|
46
|
+
- `token` (required): Master token for initial authentication and user creation
|
|
47
|
+
- `jwtSecret` (required): Secret key for JWT token generation and verification
|
|
48
|
+
- `modules` (required): Array of management API modules to register
|
|
49
|
+
- `baseUrl` (optional): Base URL for all management API endpoints (defaults to `/managementapi`)
|
|
50
|
+
|
|
51
|
+
## Authentication
|
|
52
|
+
|
|
53
|
+
The management API supports two authentication methods:
|
|
54
|
+
|
|
55
|
+
1. **Master Token**: Use the `token` specified during plugin initialization
|
|
56
|
+
2. **JWT Token**: Login with a management user to receive a JWT token
|
|
57
|
+
|
|
58
|
+
All requests (except login) must include one of these tokens in the `management-token` header.
|
|
59
|
+
|
|
60
|
+
## Built-in User Management
|
|
39
61
|
|
|
40
|
-
|
|
62
|
+
The plugin includes a complete user management system:
|
|
41
63
|
|
|
42
|
-
|
|
64
|
+
### Endpoints
|
|
43
65
|
|
|
44
|
-
|
|
66
|
+
- `POST /managementapi/managementapiuser` - Create new user
|
|
67
|
+
- `POST /managementapi/managementapiuser/login` - Login and receive JWT token
|
|
68
|
+
- `GET /managementapi/managementapiuser` - List all users
|
|
69
|
+
- `GET /managementapi/managementapiuser/me` - Get current user info
|
|
70
|
+
- `GET /managementapi/managementapiuser/:userid` - Get user by ID
|
|
71
|
+
- `PUT /managementapi/managementapiuser/:userid` - Update user
|
|
72
|
+
- `DELETE /managementapi/managementapiuser/:userid` - Delete user
|
|
45
73
|
|
|
74
|
+
### Creating Your First User
|
|
75
|
+
|
|
76
|
+
To create the initial management user, make a POST request with the master token:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
curl 'https://YOUR-API-URL/managementapi/managementapiuser' \
|
|
80
|
+
-H 'management-token: SECRET_TOKEN_USED_TO_COMMUNICATE_WITH_THE_API' \
|
|
81
|
+
-H 'Content-Type: application/json' \
|
|
82
|
+
--data-raw '{"username":"admin","password":"secure_password"}'
|
|
46
83
|
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
84
|
+
|
|
85
|
+
### Logging In
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
curl 'https://YOUR-API-URL/managementapi/managementapiuser/login' \
|
|
89
|
+
-H 'Content-Type: application/json' \
|
|
90
|
+
--data-raw '{"username":"admin","password":"secure_password"}'
|
|
51
91
|
```
|
|
92
|
+
|
|
93
|
+
This returns a JWT token that can be used in the `management-token` header for subsequent requests.
|
|
94
|
+
|
|
95
|
+
## Creating Management Modules
|
|
96
|
+
|
|
97
|
+
Other plugins can create management modules that get registered with this plugin:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { ManagementApiModule, ManagementApiType } from "@flink-app/management-api-plugin";
|
|
101
|
+
import { HttpMethod } from "@flink-app/flink";
|
|
102
|
+
|
|
103
|
+
const myModule: ManagementApiModule = {
|
|
104
|
+
id: "my-module",
|
|
105
|
+
type: ManagementApiType.custom, // or other types
|
|
106
|
+
ui: true,
|
|
107
|
+
uiSettings: {
|
|
108
|
+
title: "My Module",
|
|
109
|
+
icon: "",
|
|
110
|
+
features: [],
|
|
111
|
+
},
|
|
112
|
+
endpoints: [
|
|
113
|
+
{
|
|
114
|
+
handler: myHandler,
|
|
115
|
+
routeProps: {
|
|
116
|
+
method: HttpMethod.get,
|
|
117
|
+
path: "/list",
|
|
118
|
+
docs: "List all items",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
data: {},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Register with management API plugin
|
|
126
|
+
managementApiPlugin({
|
|
127
|
+
token: "...",
|
|
128
|
+
jwtSecret: "...",
|
|
129
|
+
modules: [myModule],
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Module Types
|
|
134
|
+
|
|
135
|
+
The plugin supports different module types via `ManagementApiType`:
|
|
136
|
+
|
|
137
|
+
- `managementUser` - User management (built-in)
|
|
138
|
+
- `action` - Action modules (used by management-actions-plugin)
|
|
139
|
+
- Custom types can be defined
|
|
140
|
+
|
|
141
|
+
## API Endpoints
|
|
142
|
+
|
|
143
|
+
### Get Management API Info
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
GET /managementapi
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Returns information about all registered modules and their configuration.
|
|
150
|
+
|
|
151
|
+
## TypeScript Support
|
|
152
|
+
|
|
153
|
+
The plugin includes full TypeScript definitions. To use the plugin context in your application:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { managementApiPluginContext } from "@flink-app/management-api-plugin";
|
|
157
|
+
|
|
158
|
+
interface MyContext extends FlinkContext<managementApiPluginContext> {
|
|
159
|
+
// your context
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Database Requirements
|
|
164
|
+
|
|
165
|
+
This plugin requires MongoDB to be configured in your Flink app for user management. The plugin automatically creates a `ManagementUserRepo` repository.
|
|
166
|
+
|
|
167
|
+
## Security Notes
|
|
168
|
+
|
|
169
|
+
- Always use strong, unique values for `token` and `jwtSecret`
|
|
170
|
+
- Store secrets in environment variables, never commit them to source control
|
|
171
|
+
- The master token provides full access - protect it carefully
|
|
172
|
+
- User passwords are automatically hashed using bcrypt
|
|
173
|
+
- The login endpoint is the only endpoint that doesn't require authentication
|
|
174
|
+
|
|
175
|
+
## Example Integration with Management Actions Plugin
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { managementApiPlugin } from "@flink-app/management-api-plugin";
|
|
179
|
+
import { GetManagementModule } from "@flink-app/management-actions-plugin";
|
|
180
|
+
|
|
181
|
+
const actionsModule = GetManagementModule({
|
|
182
|
+
ui: true,
|
|
183
|
+
uiSettings: { title: "Actions" },
|
|
184
|
+
actions: [
|
|
185
|
+
// your actions
|
|
186
|
+
],
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
new FlinkApp<AppContext>({
|
|
190
|
+
plugins: [
|
|
191
|
+
managementApiPlugin({
|
|
192
|
+
token: process.env.MANAGEMENT_TOKEN!,
|
|
193
|
+
jwtSecret: process.env.JWT_SECRET!,
|
|
194
|
+
modules: [actionsModule],
|
|
195
|
+
}),
|
|
196
|
+
],
|
|
197
|
+
}).start();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|