@nocobase/server 1.6.0-alpha.3 → 1.6.0-alpha.30
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/lib/aes-encryptor.d.ts +20 -0
- package/lib/aes-encryptor.js +126 -0
- package/lib/application.d.ts +9 -1
- package/lib/application.js +28 -2
- package/lib/audit-manager/index.js +11 -7
- package/lib/environment.d.ts +18 -0
- package/lib/environment.js +80 -0
- package/lib/gateway/index.js +44 -24
- package/lib/gateway/ws-server.d.ts +18 -2
- package/lib/gateway/ws-server.js +105 -27
- package/lib/helper.js +5 -0
- package/lib/helpers/application-version.js +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -2
- package/lib/middlewares/data-template.js +5 -5
- package/lib/middlewares/extract-client-ip.d.ts +10 -0
- package/lib/middlewares/extract-client-ip.js +46 -0
- package/lib/middlewares/index.d.ts +1 -0
- package/lib/middlewares/index.js +3 -1
- package/lib/plugin-manager/deps.js +1 -1
- package/lib/plugin-manager/options/collection.js +1 -0
- package/lib/plugin-manager/plugin-manager.d.ts +4 -4
- package/lib/plugin-manager/plugin-manager.js +27 -15
- package/lib/service-container.d.ts +5 -0
- package/lib/service-container.js +50 -0
- package/package.json +58 -58
package/lib/gateway/ws-server.js
CHANGED
|
@@ -46,16 +46,18 @@ var import_nanoid = require("nanoid");
|
|
|
46
46
|
var import_app_supervisor = require("../app-supervisor");
|
|
47
47
|
var import_errors = require("./errors");
|
|
48
48
|
var import_lodash = __toESM(require("lodash"));
|
|
49
|
+
var import_events = __toESM(require("events"));
|
|
49
50
|
function getPayloadByErrorCode(code, options) {
|
|
50
51
|
const error = (0, import_errors.getErrorWithCode)(code);
|
|
51
52
|
return import_lodash.default.omit((0, import_errors.applyErrorWithArgs)(error, options), ["status", "maintaining"]);
|
|
52
53
|
}
|
|
53
54
|
__name(getPayloadByErrorCode, "getPayloadByErrorCode");
|
|
54
|
-
const _WSServer = class _WSServer {
|
|
55
|
+
const _WSServer = class _WSServer extends import_events.default {
|
|
55
56
|
wss;
|
|
56
57
|
webSocketClients = /* @__PURE__ */ new Map();
|
|
57
58
|
logger;
|
|
58
59
|
constructor() {
|
|
60
|
+
super();
|
|
59
61
|
this.wss = new import_ws.WebSocketServer({ noServer: true });
|
|
60
62
|
this.wss.on("connection", (ws, request) => {
|
|
61
63
|
const client = this.addNewConnection(ws, request);
|
|
@@ -66,6 +68,15 @@ const _WSServer = class _WSServer {
|
|
|
66
68
|
ws.on("close", () => {
|
|
67
69
|
this.removeConnection(ws.id);
|
|
68
70
|
});
|
|
71
|
+
ws.on("message", (message) => {
|
|
72
|
+
if (message.toString() === "ping") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.emit("message", {
|
|
76
|
+
client,
|
|
77
|
+
message
|
|
78
|
+
});
|
|
79
|
+
});
|
|
69
80
|
});
|
|
70
81
|
import_gateway.Gateway.getInstance().on("appSelectorChanged", () => {
|
|
71
82
|
this.loopThroughConnections(async (client) => {
|
|
@@ -73,8 +84,12 @@ const _WSServer = class _WSServer {
|
|
|
73
84
|
url: client.url,
|
|
74
85
|
headers: client.headers
|
|
75
86
|
});
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
for (const tag of client.tags) {
|
|
88
|
+
if (tag.startsWith("app#")) {
|
|
89
|
+
client.tags.delete(tag);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
client.tags.add(`app#${handleAppName}`);
|
|
78
93
|
import_app_supervisor.AppSupervisor.getInstance().bootStrapApp(handleAppName);
|
|
79
94
|
});
|
|
80
95
|
});
|
|
@@ -118,19 +133,87 @@ const _WSServer = class _WSServer {
|
|
|
118
133
|
}
|
|
119
134
|
});
|
|
120
135
|
});
|
|
136
|
+
import_app_supervisor.AppSupervisor.getInstance().on("afterAppAdded", (app) => {
|
|
137
|
+
this.bindAppWSEvents(app);
|
|
138
|
+
});
|
|
139
|
+
this.on("message", async ({ client, message }) => {
|
|
140
|
+
const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(client.app);
|
|
141
|
+
if (!app) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const parsedMessage = JSON.parse(message.toString());
|
|
145
|
+
if (!parsedMessage.type) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const eventName = `ws:message:${parsedMessage.type}`;
|
|
149
|
+
app.emit(eventName, {
|
|
150
|
+
clientId: client.id,
|
|
151
|
+
tags: [...client.tags],
|
|
152
|
+
payload: parsedMessage.payload
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
bindAppWSEvents(app) {
|
|
157
|
+
if (app.listenerCount("ws:setTag") > 0) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
app.on("ws:setTag", ({ clientId, tagKey, tagValue }) => {
|
|
161
|
+
this.setClientTag(clientId, tagKey, tagValue);
|
|
162
|
+
});
|
|
163
|
+
app.on("ws:removeTag", ({ clientId, tagKey }) => {
|
|
164
|
+
this.removeClientTag(clientId, tagKey);
|
|
165
|
+
});
|
|
166
|
+
app.on("ws:sendToTag", ({ tagKey, tagValue, message }) => {
|
|
167
|
+
this.sendToConnectionsByTags(
|
|
168
|
+
[
|
|
169
|
+
{ tagName: tagKey, tagValue },
|
|
170
|
+
{ tagName: "app", tagValue: app.name }
|
|
171
|
+
],
|
|
172
|
+
message
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
app.on("ws:sendToClient", ({ clientId, message }) => {
|
|
176
|
+
this.sendToClient(clientId, message);
|
|
177
|
+
});
|
|
178
|
+
app.on("ws:sendToCurrentApp", ({ message }) => {
|
|
179
|
+
this.sendToConnectionsByTag("app", app.name, message);
|
|
180
|
+
});
|
|
181
|
+
app.on("ws:sendToTags", ({ tags, message }) => {
|
|
182
|
+
this.sendToConnectionsByTags(tags, message);
|
|
183
|
+
});
|
|
184
|
+
app.on("ws:authorized", ({ clientId, userId }) => {
|
|
185
|
+
this.sendToClient(clientId, { type: "authorized" });
|
|
186
|
+
});
|
|
121
187
|
}
|
|
122
188
|
addNewConnection(ws, request) {
|
|
123
189
|
const id = (0, import_nanoid.nanoid)();
|
|
124
190
|
ws.id = id;
|
|
125
191
|
this.webSocketClients.set(id, {
|
|
126
192
|
ws,
|
|
127
|
-
tags:
|
|
193
|
+
tags: /* @__PURE__ */ new Set(),
|
|
128
194
|
url: request.url,
|
|
129
|
-
headers: request.headers
|
|
195
|
+
headers: request.headers,
|
|
196
|
+
id
|
|
130
197
|
});
|
|
131
198
|
this.setClientApp(this.webSocketClients.get(id));
|
|
132
199
|
return this.webSocketClients.get(id);
|
|
133
200
|
}
|
|
201
|
+
setClientTag(clientId, tagKey, tagValue) {
|
|
202
|
+
const client = this.webSocketClients.get(clientId);
|
|
203
|
+
if (!client) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
client.tags.add(`${tagKey}#${tagValue}`);
|
|
207
|
+
console.log(`client tags: ${Array.from(client.tags)}`);
|
|
208
|
+
}
|
|
209
|
+
removeClientTag(clientId, tagKey) {
|
|
210
|
+
const client = this.webSocketClients.get(clientId);
|
|
211
|
+
client.tags.forEach((tag) => {
|
|
212
|
+
if (tag.startsWith(tagKey)) {
|
|
213
|
+
client.tags.delete(tag);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
134
217
|
async setClientApp(client) {
|
|
135
218
|
const req = {
|
|
136
219
|
url: client.url,
|
|
@@ -139,31 +222,11 @@ const _WSServer = class _WSServer {
|
|
|
139
222
|
const handleAppName = await import_gateway.Gateway.getInstance().getRequestHandleAppName(req);
|
|
140
223
|
client.app = handleAppName;
|
|
141
224
|
console.log(`client tags: app#${handleAppName}`);
|
|
142
|
-
client.tags.
|
|
225
|
+
client.tags.add(`app#${handleAppName}`);
|
|
143
226
|
const hasApp = import_app_supervisor.AppSupervisor.getInstance().hasApp(handleAppName);
|
|
144
227
|
if (!hasApp) {
|
|
145
228
|
import_app_supervisor.AppSupervisor.getInstance().bootStrapApp(handleAppName);
|
|
146
229
|
}
|
|
147
|
-
const appStatus = import_app_supervisor.AppSupervisor.getInstance().getAppStatus(handleAppName, "initializing");
|
|
148
|
-
if (appStatus === "not_found") {
|
|
149
|
-
this.sendMessageToConnection(client, {
|
|
150
|
-
type: "maintaining",
|
|
151
|
-
payload: getPayloadByErrorCode("APP_NOT_FOUND", { appName: handleAppName })
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (appStatus === "initializing") {
|
|
156
|
-
this.sendMessageToConnection(client, {
|
|
157
|
-
type: "maintaining",
|
|
158
|
-
payload: getPayloadByErrorCode("APP_INITIALIZING", { appName: handleAppName })
|
|
159
|
-
});
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(handleAppName);
|
|
163
|
-
this.sendMessageToConnection(client, {
|
|
164
|
-
type: "maintaining",
|
|
165
|
-
payload: getPayloadByErrorCode(appStatus, { app })
|
|
166
|
-
});
|
|
167
230
|
}
|
|
168
231
|
removeConnection(id) {
|
|
169
232
|
console.log(`client disconnected ${id}`);
|
|
@@ -173,12 +236,27 @@ const _WSServer = class _WSServer {
|
|
|
173
236
|
client.ws.send(JSON.stringify(sendMessage));
|
|
174
237
|
}
|
|
175
238
|
sendToConnectionsByTag(tagName, tagValue, sendMessage) {
|
|
239
|
+
this.sendToConnectionsByTags([{ tagName, tagValue }], sendMessage);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Send message to clients that match all the given tag conditions
|
|
243
|
+
* @param tags Array of tag conditions, each condition is an object with tagName and tagValue
|
|
244
|
+
* @param sendMessage Message to be sent
|
|
245
|
+
*/
|
|
246
|
+
sendToConnectionsByTags(tags, sendMessage) {
|
|
176
247
|
this.loopThroughConnections((client) => {
|
|
177
|
-
|
|
248
|
+
const allTagsMatch = tags.every(({ tagName, tagValue }) => client.tags.has(`${tagName}#${tagValue}`));
|
|
249
|
+
if (allTagsMatch) {
|
|
178
250
|
this.sendMessageToConnection(client, sendMessage);
|
|
179
251
|
}
|
|
180
252
|
});
|
|
181
253
|
}
|
|
254
|
+
sendToClient(clientId, sendMessage) {
|
|
255
|
+
const client = this.webSocketClients.get(clientId);
|
|
256
|
+
if (client) {
|
|
257
|
+
this.sendMessageToConnection(client, sendMessage);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
182
260
|
loopThroughConnections(callback) {
|
|
183
261
|
this.webSocketClients.forEach((client) => {
|
|
184
262
|
callback(client);
|
package/lib/helper.js
CHANGED
|
@@ -56,6 +56,7 @@ var import_i18next = __toESM(require("i18next"));
|
|
|
56
56
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
57
57
|
var import_perf_hooks = require("perf_hooks");
|
|
58
58
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
59
|
+
var import_extract_client_ip = require("./middlewares/extract-client-ip");
|
|
59
60
|
var import_i18n = require("./middlewares/i18n");
|
|
60
61
|
function createI18n(options) {
|
|
61
62
|
const instance = import_i18next.default.createInstance();
|
|
@@ -87,6 +88,9 @@ function registerMiddlewares(app, options) {
|
|
|
87
88
|
app.use(
|
|
88
89
|
(0, import_cors.default)({
|
|
89
90
|
exposeHeaders: ["content-disposition"],
|
|
91
|
+
origin(ctx) {
|
|
92
|
+
return ctx.get("origin");
|
|
93
|
+
},
|
|
90
94
|
...options.cors
|
|
91
95
|
}),
|
|
92
96
|
{
|
|
@@ -121,6 +125,7 @@ function registerMiddlewares(app, options) {
|
|
|
121
125
|
app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "cors" });
|
|
122
126
|
}
|
|
123
127
|
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "dataWrapping" });
|
|
128
|
+
app.use((0, import_extract_client_ip.extractClientIp)(), { tag: "extractClientIp", before: "cors" });
|
|
124
129
|
}
|
|
125
130
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
126
131
|
const createAppProxy = /* @__PURE__ */ __name((app) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
export * from './aes-encryptor';
|
|
9
10
|
export * from './app-supervisor';
|
|
10
11
|
export * from './application';
|
|
11
12
|
export { Application as default } from './application';
|
|
13
|
+
export * from './audit-manager';
|
|
12
14
|
export * from './gateway';
|
|
13
15
|
export * as middlewares from './middlewares';
|
|
14
16
|
export * from './migration';
|
|
15
17
|
export * from './plugin';
|
|
16
18
|
export * from './plugin-manager';
|
|
17
|
-
export * from './audit-manager';
|
|
18
19
|
export * from './pub-sub-manager';
|
|
19
20
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
20
21
|
export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
|
package/lib/index.js
CHANGED
|
@@ -48,15 +48,16 @@ __export(src_exports, {
|
|
|
48
48
|
runPluginStaticImports: () => import_run_plugin_static_imports.runPluginStaticImports
|
|
49
49
|
});
|
|
50
50
|
module.exports = __toCommonJS(src_exports);
|
|
51
|
+
__reExport(src_exports, require("./aes-encryptor"), module.exports);
|
|
51
52
|
__reExport(src_exports, require("./app-supervisor"), module.exports);
|
|
52
53
|
__reExport(src_exports, require("./application"), module.exports);
|
|
53
54
|
var import_application = require("./application");
|
|
55
|
+
__reExport(src_exports, require("./audit-manager"), module.exports);
|
|
54
56
|
__reExport(src_exports, require("./gateway"), module.exports);
|
|
55
57
|
var middlewares = __toESM(require("./middlewares"));
|
|
56
58
|
__reExport(src_exports, require("./migration"), module.exports);
|
|
57
59
|
__reExport(src_exports, require("./plugin"), module.exports);
|
|
58
60
|
__reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
59
|
-
__reExport(src_exports, require("./audit-manager"), module.exports);
|
|
60
61
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
61
62
|
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
62
63
|
var import_run_plugin_static_imports = require("./run-plugin-static-imports");
|
|
@@ -71,12 +72,13 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
71
72
|
middlewares,
|
|
72
73
|
packageNameTrim,
|
|
73
74
|
runPluginStaticImports,
|
|
75
|
+
...require("./aes-encryptor"),
|
|
74
76
|
...require("./app-supervisor"),
|
|
75
77
|
...require("./application"),
|
|
78
|
+
...require("./audit-manager"),
|
|
76
79
|
...require("./gateway"),
|
|
77
80
|
...require("./migration"),
|
|
78
81
|
...require("./plugin"),
|
|
79
82
|
...require("./plugin-manager"),
|
|
80
|
-
...require("./audit-manager"),
|
|
81
83
|
...require("./pub-sub-manager")
|
|
82
84
|
});
|
|
@@ -32,12 +32,12 @@ __export(data_template_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(data_template_exports);
|
|
33
33
|
async function dataTemplate(ctx, next) {
|
|
34
34
|
const { resourceName, actionName } = ctx.action;
|
|
35
|
-
const { isTemplate, fields } = ctx.action.params;
|
|
35
|
+
const { isTemplate, fields, appends } = ctx.action.params;
|
|
36
36
|
await next();
|
|
37
|
-
if (isTemplate && actionName === "get"
|
|
37
|
+
if (isTemplate && actionName === "get") {
|
|
38
38
|
ctx.body = traverseJSON(JSON.parse(JSON.stringify(ctx.body)), {
|
|
39
|
-
collection: ctx.
|
|
40
|
-
include: fields
|
|
39
|
+
collection: ctx.getCurrentRepository().collection,
|
|
40
|
+
include: [...fields || [], ...appends || []]
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -101,7 +101,7 @@ const traverseJSON = /* @__PURE__ */ __name((data, options) => {
|
|
|
101
101
|
result[key] = data[key];
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
|
-
if (field.options.primaryKey && excludePk) {
|
|
104
|
+
if (field.options.primaryKey && excludePk && !collection.isMultiFilterTargetKey()) {
|
|
105
105
|
continue;
|
|
106
106
|
}
|
|
107
107
|
if (field.options.isForeignKey) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Context, Next } from '@nocobase/actions';
|
|
10
|
+
export declare function extractClientIp(): (ctx: Context, next: Next) => Promise<void>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var extract_client_ip_exports = {};
|
|
29
|
+
__export(extract_client_ip_exports, {
|
|
30
|
+
extractClientIp: () => extractClientIp
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(extract_client_ip_exports);
|
|
33
|
+
function extractClientIp() {
|
|
34
|
+
return /* @__PURE__ */ __name(async function extractClientIp2(ctx, next) {
|
|
35
|
+
const forwardedFor = ctx.get("X-Forwarded-For");
|
|
36
|
+
const ipArray = forwardedFor ? forwardedFor.split(",") : [];
|
|
37
|
+
const clientIp = ipArray.length > 0 ? ipArray[0].trim() : ctx.request.ip;
|
|
38
|
+
ctx.state.clientIp = clientIp;
|
|
39
|
+
await next();
|
|
40
|
+
}, "extractClientIp");
|
|
41
|
+
}
|
|
42
|
+
__name(extractClientIp, "extractClientIp");
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
extractClientIp
|
|
46
|
+
});
|
package/lib/middlewares/index.js
CHANGED
|
@@ -31,9 +31,11 @@ __export(middlewares_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(middlewares_exports);
|
|
33
33
|
__reExport(middlewares_exports, require("./data-wrapping"), module.exports);
|
|
34
|
+
__reExport(middlewares_exports, require("./extract-client-ip"), module.exports);
|
|
34
35
|
var import_parse_variables = require("./parse-variables");
|
|
35
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
37
|
0 && (module.exports = {
|
|
37
38
|
parseVariables,
|
|
38
|
-
...require("./data-wrapping")
|
|
39
|
+
...require("./data-wrapping"),
|
|
40
|
+
...require("./extract-client-ip")
|
|
39
41
|
});
|
|
@@ -33,6 +33,7 @@ var import_database = require("@nocobase/database");
|
|
|
33
33
|
var collection_default = (0, import_database.defineCollection)({
|
|
34
34
|
name: "applicationPlugins",
|
|
35
35
|
dumpRules: "required",
|
|
36
|
+
migrationRules: ["overwrite", "schema-only"],
|
|
36
37
|
repository: "PluginManagerRepository",
|
|
37
38
|
origin: "@nocobase/server",
|
|
38
39
|
fields: [
|
|
@@ -67,7 +67,7 @@ export declare class PluginManager {
|
|
|
67
67
|
/**
|
|
68
68
|
* @internal
|
|
69
69
|
*/
|
|
70
|
-
static getPackageName(name: string): Promise<
|
|
70
|
+
static getPackageName(name: string): Promise<any>;
|
|
71
71
|
/**
|
|
72
72
|
* @internal
|
|
73
73
|
*/
|
|
@@ -75,7 +75,7 @@ export declare class PluginManager {
|
|
|
75
75
|
/**
|
|
76
76
|
* @internal
|
|
77
77
|
*/
|
|
78
|
-
static findPackage(name: string): Promise<
|
|
78
|
+
static findPackage(name: string): Promise<any>;
|
|
79
79
|
/**
|
|
80
80
|
* @internal
|
|
81
81
|
*/
|
|
@@ -89,9 +89,9 @@ export declare class PluginManager {
|
|
|
89
89
|
addPreset(plugin: string | typeof Plugin, options?: any): void;
|
|
90
90
|
getPlugins(): Map<typeof Plugin, Plugin<any>>;
|
|
91
91
|
getAliases(): IterableIterator<string>;
|
|
92
|
-
get(name: string | typeof Plugin):
|
|
92
|
+
get<T extends Plugin>(name: string | typeof Plugin | (new () => T)): T;
|
|
93
93
|
has(name: string | typeof Plugin): boolean;
|
|
94
|
-
del(name:
|
|
94
|
+
del(name: any): void;
|
|
95
95
|
create(pluginName: string, options?: {
|
|
96
96
|
forceRecreate?: boolean;
|
|
97
97
|
}): Promise<void>;
|
|
@@ -139,15 +139,12 @@ const _PluginManager = class _PluginManager {
|
|
|
139
139
|
* @internal
|
|
140
140
|
*/
|
|
141
141
|
static async getPackageName(name) {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (exists) {
|
|
147
|
-
return `${prefix}${name}`;
|
|
148
|
-
}
|
|
142
|
+
const { packageName } = await this.parseName(name);
|
|
143
|
+
const packageFile = (0, import_path.resolve)(process.env.NODE_MODULES_PATH, packageName, "package.json");
|
|
144
|
+
if (!await import_fs_extra.default.exists(packageFile)) {
|
|
145
|
+
return null;
|
|
149
146
|
}
|
|
150
|
-
|
|
147
|
+
return packageName;
|
|
151
148
|
}
|
|
152
149
|
/**
|
|
153
150
|
* @internal
|
|
@@ -312,7 +309,9 @@ const _PluginManager = class _PluginManager {
|
|
|
312
309
|
try {
|
|
313
310
|
if (typeof plugin === "string" && options.name && !options.packageName) {
|
|
314
311
|
const packageName = await _PluginManager.getPackageName(options.name);
|
|
315
|
-
|
|
312
|
+
if (packageName) {
|
|
313
|
+
options["packageName"] = packageName;
|
|
314
|
+
}
|
|
316
315
|
}
|
|
317
316
|
if (options.packageName) {
|
|
318
317
|
const packageJson = await _PluginManager.getPackageJson(options.packageName);
|
|
@@ -320,12 +319,14 @@ const _PluginManager = class _PluginManager {
|
|
|
320
319
|
options["version"] = packageJson.version;
|
|
321
320
|
}
|
|
322
321
|
} catch (error) {
|
|
322
|
+
this.app.log.error(error);
|
|
323
323
|
console.error(error);
|
|
324
324
|
}
|
|
325
|
-
this.app.log.trace(`
|
|
325
|
+
this.app.log.trace(`adding plugin [${options.name}]`, {
|
|
326
326
|
method: "add",
|
|
327
327
|
submodule: "plugin-manager",
|
|
328
|
-
name: options.name
|
|
328
|
+
name: options.name,
|
|
329
|
+
options
|
|
329
330
|
});
|
|
330
331
|
let P;
|
|
331
332
|
try {
|
|
@@ -343,6 +344,12 @@ const _PluginManager = class _PluginManager {
|
|
|
343
344
|
this.pluginAliases.set(options.packageName, instance);
|
|
344
345
|
}
|
|
345
346
|
await instance.afterAdd();
|
|
347
|
+
this.app.log.trace(`added plugin [${options.name}]`, {
|
|
348
|
+
method: "add",
|
|
349
|
+
submodule: "plugin-manager",
|
|
350
|
+
name: instance.name,
|
|
351
|
+
options: instance.options
|
|
352
|
+
});
|
|
346
353
|
}
|
|
347
354
|
/**
|
|
348
355
|
* @internal
|
|
@@ -364,15 +371,20 @@ const _PluginManager = class _PluginManager {
|
|
|
364
371
|
const packageNames = items.map((item) => item.packageName);
|
|
365
372
|
const source = [];
|
|
366
373
|
for (const packageName of packageNames) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
374
|
+
try {
|
|
375
|
+
const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
|
|
376
|
+
const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "{ts,js}" : "js"));
|
|
377
|
+
source.push(directory.replaceAll(import_path.sep, "/"));
|
|
378
|
+
} catch (error) {
|
|
379
|
+
this.app.log.error(error);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
370
382
|
}
|
|
371
383
|
for (const plugin of this.options.plugins || []) {
|
|
372
384
|
if (typeof plugin === "string") {
|
|
373
385
|
const { packageName } = await _PluginManager.parseName(plugin);
|
|
374
386
|
const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
|
|
375
|
-
const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "ts" : "js"));
|
|
387
|
+
const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "{ts,js}" : "js"));
|
|
376
388
|
source.push(directory.replaceAll(import_path.sep, "/"));
|
|
377
389
|
}
|
|
378
390
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var service_container_exports = {};
|
|
29
|
+
__export(service_container_exports, {
|
|
30
|
+
ServiceContainer: () => ServiceContainer
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(service_container_exports);
|
|
33
|
+
const _ServiceContainer = class _ServiceContainer {
|
|
34
|
+
services = /* @__PURE__ */ new Map();
|
|
35
|
+
register(name, service) {
|
|
36
|
+
if (typeof service === "function") {
|
|
37
|
+
service = service();
|
|
38
|
+
}
|
|
39
|
+
this.services.set(name, service);
|
|
40
|
+
}
|
|
41
|
+
get(name) {
|
|
42
|
+
return this.services.get(name);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__name(_ServiceContainer, "ServiceContainer");
|
|
46
|
+
let ServiceContainer = _ServiceContainer;
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
ServiceContainer
|
|
50
|
+
});
|