@flink-app/management-api-plugin 0.12.1-alpha.23 → 0.12.1-alpha.33

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.
@@ -1,4 +1,4 @@
1
- // Generated Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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";
@@ -1,4 +1,4 @@
1
- // Generated Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredJobs } from "@flink-app/flink";
3
3
  export const jobs = [];
4
4
  autoRegisteredJobs.push(...jobs);
@@ -1,4 +1,4 @@
1
- // Generated Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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 Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
18
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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,4 +1,4 @@
1
- // Generated Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer Time)
2
2
  import "./generatedHandlers";
3
3
  import "./generatedRepos";
4
4
  import "./generatedJobs";
@@ -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 Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
27
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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 Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
4
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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 Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
7
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer 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 }];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Generated Mon Aug 25 2025 11:28:38 GMT+0200 (Central European Summer Time)
3
+ // Generated Fri Oct 24 2025 08:13:55 GMT+0200 (Central European Summer Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/management-api-plugin",
3
- "version": "0.12.1-alpha.23",
3
+ "version": "0.12.1-alpha.33",
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\"",
@@ -30,5 +30,5 @@
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "5.4.5"
32
32
  },
33
- "gitHead": "ab25ba2532fd79e5452390591c1899fbe3eae230"
33
+ "gitHead": "eec3a22c21db0e7fec84190bf7a74c1e430e5ec4"
34
34
  }
package/readme.md CHANGED
@@ -1,51 +1,202 @@
1
- # Flink API Docs
1
+ # @flink-app/management-api-plugin
2
2
 
3
- **WORK IN PROGRESS 👷‍♀️👷🏻‍♂️**
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
- A FLINK plugin that lets you expose management api:s for other plugins.
5
+ ## Features
6
6
 
7
- Other plugins must be able to generate a ManagementApiModule that can be registered with this plugin to expose management apis.
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
- ## Usage
10
-
11
- Install plugin to your flink app project:
15
+ ## Installation
12
16
 
13
- ```
14
- npm i -S @flink-app/management-api-plugin
17
+ ```bash
18
+ npm install @flink-app/management-api-plugin
15
19
  ```
16
20
 
17
- Add and configure plugin in your app startup (probable the `index.ts` in root project):
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
- // Register plugin
28
- managementApiPlugin({
29
- token : "SECRET_TOKEN_USED_TO_COMMUNICATE_WITH_THE_API",
30
- jwtSecret : "JWT_SECRET_USED_TO_GENERATE_LOGGED_IN_TOKENS",
31
- modules : []
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
- ## Communicating with the management api
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
- To work with the management api you must in the http header `management-token` send either the `token` specified when register the plugin or a user login token.
62
+ The plugin includes a complete user management system:
41
63
 
42
- The management API have it's own users system, where you might add, edit or remove management users.
64
+ ### Endpoints
43
65
 
44
- To create a first user to your management api make a POST request to /managementapi/managementapiuser with http-header management-token set to the specified token.
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
- curl 'https://URL-TO-YOUR-API/managementapi/managementapiuser' \
48
- -H 'management-token: SECRET_TOKEN_USED_TO_COMMUNICATE_WITH_THE_API' \
49
- -H 'Content-Type: application/json;charset=UTF-8' \
50
- --data-raw '{"username":"test","password":"test"}'
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