@nocobase/server 2.1.0-alpha.3 → 2.1.0-alpha.31
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/acl/available-action.js +1 -1
- package/lib/aes-encryptor.js +3 -2
- package/lib/app-supervisor/app-options-factory.d.ts +1 -0
- package/lib/app-supervisor/index.js +15 -1
- package/lib/app-supervisor/main-only-adapter.d.ts +1 -1
- package/lib/app-supervisor/main-only-adapter.js +17 -12
- package/lib/application.d.ts +1 -2
- package/lib/application.js +3 -24
- package/lib/audit-manager/index.d.ts +2 -0
- package/lib/audit-manager/index.js +5 -2
- package/lib/commands/ai.js +1 -6
- package/lib/commands/create-migration.js +1 -1
- package/lib/commands/install.js +0 -2
- package/lib/commands/pm.js +7 -0
- package/lib/commands/start.js +2 -5
- package/lib/commands/upgrade.js +0 -2
- package/lib/event-queue.js +1 -1
- package/lib/gateway/index.d.ts +15 -3
- package/lib/gateway/index.js +153 -19
- package/lib/gateway/utils.d.ts +17 -0
- package/lib/gateway/utils.js +115 -0
- package/lib/helper.js +33 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/main-data-source.js +8 -5
- package/lib/plugin-manager/deps.js +3 -2
- package/lib/plugin-manager/findPackageNames.js +4 -2
- package/lib/plugin-manager/options/resource.d.ts +11 -1
- package/lib/plugin-manager/options/resource.js +162 -53
- package/lib/plugin-manager/plugin-manager.d.ts +7 -2
- package/lib/plugin-manager/plugin-manager.js +57 -44
- package/lib/plugin-manager/utils.d.ts +9 -1
- package/lib/plugin-manager/utils.js +68 -10
- package/lib/plugin.js +46 -2
- package/lib/pub-sub-manager/handler-manager.d.ts +1 -0
- package/lib/pub-sub-manager/handler-manager.js +11 -0
- package/lib/pub-sub-manager/pub-sub-manager.js +2 -1
- package/lib/swagger/app.d.ts +102 -0
- package/lib/swagger/app.js +124 -0
- package/lib/swagger/base.d.ts +244 -0
- package/lib/swagger/base.js +292 -0
- package/lib/swagger/collections.d.ts +996 -0
- package/lib/swagger/collections.js +1264 -0
- package/lib/swagger/index.d.ts +1774 -0
- package/lib/swagger/index.js +70 -0
- package/lib/swagger/pm.d.ts +462 -0
- package/lib/swagger/pm.js +422 -0
- package/lib/sync-message-manager.js +8 -1
- package/lib/worker-mode.d.ts +19 -0
- package/lib/worker-mode.js +67 -0
- package/package.json +19 -19
- package/lib/ai/create-docs-index.d.ts +0 -13
- package/lib/ai/create-docs-index.js +0 -892
- package/lib/swagger/index.json +0 -1569
package/lib/gateway/index.js
CHANGED
|
@@ -39,7 +39,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
39
39
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
40
|
var gateway_exports = {};
|
|
41
41
|
__export(gateway_exports, {
|
|
42
|
-
Gateway: () => Gateway
|
|
42
|
+
Gateway: () => Gateway,
|
|
43
|
+
getHost: () => import_utils4.getHost,
|
|
44
|
+
getHostname: () => import_utils4.getHostname
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(gateway_exports);
|
|
45
47
|
var import_logger = require("@nocobase/logger");
|
|
@@ -54,6 +56,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
54
56
|
var import_http = __toESM(require("http"));
|
|
55
57
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
56
58
|
var import_node_util = require("node:util");
|
|
59
|
+
var import_node_os = require("node:os");
|
|
57
60
|
var import_path = require("path");
|
|
58
61
|
var import_qs = __toESM(require("qs"));
|
|
59
62
|
var import_serve_handler = __toESM(require("serve-handler"));
|
|
@@ -63,16 +66,26 @@ var import_plugin_manager = require("../plugin-manager");
|
|
|
63
66
|
var import_errors = require("./errors");
|
|
64
67
|
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
65
68
|
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
69
|
+
var import_utils3 = require("./utils");
|
|
66
70
|
var import_ws_server = require("./ws-server");
|
|
67
71
|
var import_node_worker_threads = require("node:worker_threads");
|
|
68
72
|
var import_node_process = __toESM(require("node:process"));
|
|
73
|
+
var import_utils4 = require("./utils");
|
|
69
74
|
const compress = (0, import_node_util.promisify)((0, import_compression.default)());
|
|
75
|
+
function normalizeBasePath(path = "") {
|
|
76
|
+
const normalized = path.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
77
|
+
return normalized || "/";
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeBasePath, "normalizeBasePath");
|
|
70
80
|
function getSocketPath() {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
81
|
+
const socketPath = import_node_process.default.env.SOCKET_PATH;
|
|
82
|
+
if (socketPath) {
|
|
83
|
+
return (0, import_path.isAbsolute)(socketPath) ? socketPath : (0, import_path.resolve)(import_node_process.default.cwd(), socketPath);
|
|
84
|
+
}
|
|
85
|
+
if (import_node_process.default.env.NOCOBASE_RUNNING_IN_DOCKER === "true") {
|
|
86
|
+
return (0, import_path.resolve)((0, import_node_os.homedir)(), ".nocobase", "gateway.sock");
|
|
74
87
|
}
|
|
75
|
-
return (0,
|
|
88
|
+
return (0, import_utils.storagePathJoin)("gateway.sock");
|
|
76
89
|
}
|
|
77
90
|
__name(getSocketPath, "getSocketPath");
|
|
78
91
|
const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
@@ -87,8 +100,21 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
87
100
|
loggers = new import_utils.Registry();
|
|
88
101
|
port = import_node_process.default.env.APP_PORT ? parseInt(import_node_process.default.env.APP_PORT) : null;
|
|
89
102
|
host = "0.0.0.0";
|
|
90
|
-
socketPath = (
|
|
103
|
+
socketPath = getSocketPath();
|
|
104
|
+
v2IndexTemplateCache = null;
|
|
91
105
|
terminating = false;
|
|
106
|
+
getOriginalRequestUrl(req) {
|
|
107
|
+
return req.originalUrl || req.url;
|
|
108
|
+
}
|
|
109
|
+
async proxyRequestToSubApp(supervisor, appName, req, res) {
|
|
110
|
+
const internalUrl = req.url;
|
|
111
|
+
req.url = this.getOriginalRequestUrl(req);
|
|
112
|
+
try {
|
|
113
|
+
return await supervisor.proxyWeb(appName, req, res);
|
|
114
|
+
} finally {
|
|
115
|
+
req.url = internalUrl;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
92
118
|
onTerminate = /* @__PURE__ */ __name(async (signal) => {
|
|
93
119
|
var _a;
|
|
94
120
|
if (this.terminating) {
|
|
@@ -119,7 +145,6 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
119
145
|
constructor() {
|
|
120
146
|
super();
|
|
121
147
|
this.reset();
|
|
122
|
-
this.socketPath = getSocketPath();
|
|
123
148
|
import_node_process.default.once("SIGTERM", this.onTerminate);
|
|
124
149
|
import_node_process.default.once("SIGINT", this.onTerminate);
|
|
125
150
|
}
|
|
@@ -151,14 +176,30 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
151
176
|
this.selectorMiddlewares = new import_utils.Toposort();
|
|
152
177
|
this.addAppSelectorMiddleware(
|
|
153
178
|
async (ctx, next) => {
|
|
154
|
-
var _a;
|
|
179
|
+
var _a, _b;
|
|
155
180
|
const { req } = ctx;
|
|
156
|
-
const
|
|
181
|
+
const parsedUrl = (0, import_url.parse)(req.url);
|
|
182
|
+
const appName = (_a = import_qs.default.parse(parsedUrl.query)) == null ? void 0 : _a.__appName;
|
|
183
|
+
const apiBasePath = normalizeBasePath(import_node_process.default.env.API_BASE_PATH || "/api");
|
|
184
|
+
const appPathPrefix = `${apiBasePath}/__app/`;
|
|
185
|
+
if (req.headers["x-app"]) {
|
|
186
|
+
ctx.resolvedAppName = req.headers["x-app"];
|
|
187
|
+
}
|
|
157
188
|
if (appName) {
|
|
158
189
|
ctx.resolvedAppName = appName;
|
|
159
190
|
}
|
|
160
|
-
if (
|
|
161
|
-
|
|
191
|
+
if ((_b = parsedUrl.pathname) == null ? void 0 : _b.startsWith(appPathPrefix)) {
|
|
192
|
+
const restPath = parsedUrl.pathname.slice(appPathPrefix.length);
|
|
193
|
+
const [pathAppName, ...segments] = restPath.split("/");
|
|
194
|
+
if (pathAppName) {
|
|
195
|
+
ctx.resolvedAppName = pathAppName;
|
|
196
|
+
const rewrittenPath = `${apiBasePath}${segments.length ? `/${segments.join("/")}` : ""}`;
|
|
197
|
+
const rewrittenUrl = `${rewrittenPath}${parsedUrl.search || ""}`;
|
|
198
|
+
if (!req.originalUrl) {
|
|
199
|
+
req.originalUrl = req.url;
|
|
200
|
+
}
|
|
201
|
+
req.url = rewrittenUrl;
|
|
202
|
+
}
|
|
162
203
|
}
|
|
163
204
|
await next();
|
|
164
205
|
},
|
|
@@ -222,9 +263,79 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
222
263
|
});
|
|
223
264
|
this.responseError(res, error);
|
|
224
265
|
}
|
|
266
|
+
getV2PublicPath() {
|
|
267
|
+
return (0, import_utils3.resolveV2PublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
268
|
+
}
|
|
269
|
+
getAppPublicPath() {
|
|
270
|
+
return (0, import_utils3.resolvePublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
271
|
+
}
|
|
272
|
+
isV2Request(pathname) {
|
|
273
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
274
|
+
return pathname === v2PublicPath.slice(0, -1) || pathname.startsWith(v2PublicPath);
|
|
275
|
+
}
|
|
276
|
+
isV2IndexRequest(pathname) {
|
|
277
|
+
if (!this.isV2Request(pathname)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
281
|
+
if (pathname === v2PublicPath || pathname === v2PublicPath.slice(0, -1) || pathname === `${v2PublicPath}index.html`) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
return !(0, import_path.extname)(pathname);
|
|
285
|
+
}
|
|
286
|
+
getV2RuntimeConfig() {
|
|
287
|
+
return {
|
|
288
|
+
__nocobase_public_path__: this.getV2PublicPath(),
|
|
289
|
+
__nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
|
|
290
|
+
__nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
|
|
291
|
+
__nocobase_api_client_storage_type__: import_node_process.default.env.API_CLIENT_STORAGE_TYPE,
|
|
292
|
+
__nocobase_api_client_share_token__: import_node_process.default.env.API_CLIENT_SHARE_TOKEN === "true",
|
|
293
|
+
__nocobase_ws_url__: import_node_process.default.env.WEBSOCKET_URL || "",
|
|
294
|
+
__nocobase_ws_path__: import_node_process.default.env.WS_PATH,
|
|
295
|
+
__esm_cdn_base_url__: import_node_process.default.env.ESM_CDN_BASE_URL || "https://esm.sh",
|
|
296
|
+
__esm_cdn_suffix__: import_node_process.default.env.ESM_CDN_SUFFIX || ""
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
getV2RuntimeConfigScript() {
|
|
300
|
+
const runtimeConfig = this.getV2RuntimeConfig();
|
|
301
|
+
const scriptContent = Object.entries(runtimeConfig).map(([key, value]) => `window['${key}'] = ${JSON.stringify(value)};`).join("\n");
|
|
302
|
+
return `<script>${scriptContent}</script>`;
|
|
303
|
+
}
|
|
304
|
+
getV2AssetPublicPath() {
|
|
305
|
+
if (import_node_process.default.env.CDN_BASE_URL) {
|
|
306
|
+
return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/v2/`;
|
|
307
|
+
}
|
|
308
|
+
return this.getV2PublicPath();
|
|
309
|
+
}
|
|
310
|
+
getV2IndexTemplate() {
|
|
311
|
+
const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/v2/index.html`;
|
|
312
|
+
if (!import_fs.default.existsSync(file)) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
const stat = import_fs.default.statSync(file);
|
|
316
|
+
if (this.v2IndexTemplateCache && this.v2IndexTemplateCache.file === file && this.v2IndexTemplateCache.mtimeMs === stat.mtimeMs) {
|
|
317
|
+
return this.v2IndexTemplateCache.html;
|
|
318
|
+
}
|
|
319
|
+
const html = import_fs.default.readFileSync(file, "utf-8");
|
|
320
|
+
this.v2IndexTemplateCache = {
|
|
321
|
+
file,
|
|
322
|
+
mtimeMs: stat.mtimeMs,
|
|
323
|
+
html
|
|
324
|
+
};
|
|
325
|
+
return html;
|
|
326
|
+
}
|
|
327
|
+
renderV2IndexHtml() {
|
|
328
|
+
const template = this.getV2IndexTemplate();
|
|
329
|
+
if (!template) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
const html = (0, import_utils3.rewriteV2AssetPublicPath)(template, this.getV2AssetPublicPath());
|
|
333
|
+
return (0, import_utils3.injectRuntimeScript)(html, this.getV2RuntimeConfigScript());
|
|
334
|
+
}
|
|
225
335
|
async requestHandler(req, res) {
|
|
226
336
|
const { pathname } = (0, import_url.parse)(req.url);
|
|
227
|
-
const { PLUGIN_STATICS_PATH
|
|
337
|
+
const { PLUGIN_STATICS_PATH } = import_node_process.default.env;
|
|
338
|
+
const APP_PUBLIC_PATH = this.getAppPublicPath();
|
|
228
339
|
if (pathname.endsWith("/__umi/api/bundle-status")) {
|
|
229
340
|
res.statusCode = 200;
|
|
230
341
|
res.end("ok");
|
|
@@ -241,21 +352,21 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
241
352
|
}
|
|
242
353
|
if (pathname.startsWith(APP_PUBLIC_PATH + "storage/uploads/")) {
|
|
243
354
|
if (handleApp !== "main") {
|
|
244
|
-
const isProxy = await
|
|
355
|
+
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
245
356
|
if (isProxy) {
|
|
246
357
|
return;
|
|
247
358
|
}
|
|
248
359
|
}
|
|
249
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length
|
|
360
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
|
|
250
361
|
await compress(req, res);
|
|
251
362
|
return (0, import_serve_handler.default)(req, res, {
|
|
252
|
-
public: (0,
|
|
363
|
+
public: (0, import_utils.resolveStorageRoot)(),
|
|
253
364
|
directoryListing: false
|
|
254
365
|
});
|
|
255
366
|
}
|
|
256
367
|
if (pathname.startsWith(PLUGIN_STATICS_PATH) && !pathname.includes("/server/")) {
|
|
257
368
|
if (handleApp !== "main") {
|
|
258
|
-
const isProxy = await
|
|
369
|
+
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
259
370
|
if (isProxy) {
|
|
260
371
|
return;
|
|
261
372
|
}
|
|
@@ -275,8 +386,29 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
275
386
|
});
|
|
276
387
|
}
|
|
277
388
|
if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH)) {
|
|
389
|
+
if (this.isV2Request(pathname)) {
|
|
390
|
+
if (handleApp !== "main") {
|
|
391
|
+
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
392
|
+
if (isProxy) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (this.isV2IndexRequest(pathname)) {
|
|
397
|
+
const v2Html = this.renderV2IndexHtml();
|
|
398
|
+
if (v2Html) {
|
|
399
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
400
|
+
res.end(v2Html);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
|
|
405
|
+
await compress(req, res);
|
|
406
|
+
return (0, import_serve_handler.default)(req, res, {
|
|
407
|
+
public: `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client`
|
|
408
|
+
});
|
|
409
|
+
}
|
|
278
410
|
if (handleApp !== "main") {
|
|
279
|
-
const isProxy = await
|
|
411
|
+
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
280
412
|
if (isProxy) {
|
|
281
413
|
return;
|
|
282
414
|
}
|
|
@@ -289,7 +421,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
289
421
|
});
|
|
290
422
|
}
|
|
291
423
|
if (handleApp !== "main") {
|
|
292
|
-
const isProxy = await
|
|
424
|
+
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
293
425
|
if (isProxy) {
|
|
294
426
|
return;
|
|
295
427
|
}
|
|
@@ -541,5 +673,7 @@ __publicField(_Gateway, "wsServers", []);
|
|
|
541
673
|
let Gateway = _Gateway;
|
|
542
674
|
// Annotate the CommonJS export names for ESM import in node:
|
|
543
675
|
0 && (module.exports = {
|
|
544
|
-
Gateway
|
|
676
|
+
Gateway,
|
|
677
|
+
getHost,
|
|
678
|
+
getHostname
|
|
545
679
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
10
|
+
import { IncomingMessage } from 'http';
|
|
11
|
+
import { IncomingRequest } from '.';
|
|
12
|
+
export declare function resolvePublicPath(appPublicPath?: string): string;
|
|
13
|
+
export declare function resolveV2PublicPath(appPublicPath?: string): string;
|
|
14
|
+
export declare function rewriteV2AssetPublicPath(html: string, assetPublicPath: string): string;
|
|
15
|
+
export declare function injectRuntimeScript(html: string, runtimeScript: string): string;
|
|
16
|
+
export declare function getHost(req: IncomingMessage | IncomingRequest): any;
|
|
17
|
+
export declare function getHostname(req: IncomingMessage | IncomingRequest): any;
|
|
@@ -0,0 +1,115 @@
|
|
|
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 utils_exports = {};
|
|
29
|
+
__export(utils_exports, {
|
|
30
|
+
getHost: () => getHost,
|
|
31
|
+
getHostname: () => getHostname,
|
|
32
|
+
injectRuntimeScript: () => injectRuntimeScript,
|
|
33
|
+
resolvePublicPath: () => resolvePublicPath,
|
|
34
|
+
resolveV2PublicPath: () => resolveV2PublicPath,
|
|
35
|
+
rewriteV2AssetPublicPath: () => rewriteV2AssetPublicPath
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
function resolvePublicPath(appPublicPath = "/") {
|
|
39
|
+
const normalized = String(appPublicPath || "/").trim() || "/";
|
|
40
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
41
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
42
|
+
}
|
|
43
|
+
__name(resolvePublicPath, "resolvePublicPath");
|
|
44
|
+
function resolveV2PublicPath(appPublicPath = "/") {
|
|
45
|
+
const publicPath = resolvePublicPath(appPublicPath);
|
|
46
|
+
return `${publicPath.replace(/\/$/, "")}/v2/`;
|
|
47
|
+
}
|
|
48
|
+
__name(resolveV2PublicPath, "resolveV2PublicPath");
|
|
49
|
+
function ensureTrailingSlash(value) {
|
|
50
|
+
return value.endsWith("/") ? value : `${value}/`;
|
|
51
|
+
}
|
|
52
|
+
__name(ensureTrailingSlash, "ensureTrailingSlash");
|
|
53
|
+
function rewriteV2AssetPublicPath(html, assetPublicPath) {
|
|
54
|
+
const normalizedAssetPublicPath = ensureTrailingSlash(assetPublicPath);
|
|
55
|
+
if (normalizedAssetPublicPath === "/v2/") {
|
|
56
|
+
return html;
|
|
57
|
+
}
|
|
58
|
+
return html.replace(/((?:src|href)=["'])\/v2\//g, `$1${normalizedAssetPublicPath}`);
|
|
59
|
+
}
|
|
60
|
+
__name(rewriteV2AssetPublicPath, "rewriteV2AssetPublicPath");
|
|
61
|
+
function injectRuntimeScript(html, runtimeScript) {
|
|
62
|
+
const browserCheckerScriptMatch = html.match(/<script\b[^>]*browser-checker\.js[^>]*><\/script>/i);
|
|
63
|
+
if (browserCheckerScriptMatch == null ? void 0 : browserCheckerScriptMatch[0]) {
|
|
64
|
+
return html.replace(browserCheckerScriptMatch[0], `${runtimeScript}
|
|
65
|
+
${browserCheckerScriptMatch[0]}`);
|
|
66
|
+
}
|
|
67
|
+
const moduleScriptMatch = html.match(/<script\b[^>]*type=["']module["'][^>]*>/i);
|
|
68
|
+
if (moduleScriptMatch == null ? void 0 : moduleScriptMatch[0]) {
|
|
69
|
+
return html.replace(moduleScriptMatch[0], `${runtimeScript}
|
|
70
|
+
${moduleScriptMatch[0]}`);
|
|
71
|
+
}
|
|
72
|
+
if (html.includes("</head>")) {
|
|
73
|
+
return html.replace("</head>", `${runtimeScript}
|
|
74
|
+
</head>`);
|
|
75
|
+
}
|
|
76
|
+
return `${runtimeScript}
|
|
77
|
+
${html}`;
|
|
78
|
+
}
|
|
79
|
+
__name(injectRuntimeScript, "injectRuntimeScript");
|
|
80
|
+
function splitCommaSeparatedValues(value, limit) {
|
|
81
|
+
return value.split(",", limit).map((v) => v.trim());
|
|
82
|
+
}
|
|
83
|
+
__name(splitCommaSeparatedValues, "splitCommaSeparatedValues");
|
|
84
|
+
function getHost(req) {
|
|
85
|
+
let host = req.headers["x-forwarded-host"];
|
|
86
|
+
if (!host) {
|
|
87
|
+
host = req.headers[":authority"] || req.headers["host"];
|
|
88
|
+
}
|
|
89
|
+
if (!host) return "";
|
|
90
|
+
host = splitCommaSeparatedValues(host, 1)[0];
|
|
91
|
+
if (host.includes("@")) {
|
|
92
|
+
try {
|
|
93
|
+
host = new URL(`http://${host}`).host;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return host;
|
|
99
|
+
}
|
|
100
|
+
__name(getHost, "getHost");
|
|
101
|
+
function getHostname(req) {
|
|
102
|
+
const host = getHost(req);
|
|
103
|
+
if (!host) return "";
|
|
104
|
+
return host.split(":", 1)[0];
|
|
105
|
+
}
|
|
106
|
+
__name(getHostname, "getHostname");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
getHost,
|
|
110
|
+
getHostname,
|
|
111
|
+
injectRuntimeScript,
|
|
112
|
+
resolvePublicPath,
|
|
113
|
+
resolveV2PublicPath,
|
|
114
|
+
rewriteV2AssetPublicPath
|
|
115
|
+
});
|
package/lib/helper.js
CHANGED
|
@@ -239,14 +239,46 @@ function isNumeric(str) {
|
|
|
239
239
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
240
240
|
}
|
|
241
241
|
__name(isNumeric, "isNumeric");
|
|
242
|
+
function getFieldFromCollectionManager(ctx, resourceName, fieldPath) {
|
|
243
|
+
var _a;
|
|
244
|
+
const collectionManager = (_a = ctx.dataSource) == null ? void 0 : _a.collectionManager;
|
|
245
|
+
if (!(collectionManager == null ? void 0 : collectionManager.getCollection)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const collection = collectionManager.getCollection(resourceName);
|
|
249
|
+
if (!(collection == null ? void 0 : collection.getField)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const [firstName, ...others] = fieldPath.split(".");
|
|
253
|
+
let field = collection.getField(firstName);
|
|
254
|
+
if (!field || !others.length) {
|
|
255
|
+
return field;
|
|
256
|
+
}
|
|
257
|
+
let currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
|
|
258
|
+
for (const name of others) {
|
|
259
|
+
if (!(currentCollection == null ? void 0 : currentCollection.getField)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
field = currentCollection.getField(name);
|
|
263
|
+
if (!field) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
|
|
267
|
+
}
|
|
268
|
+
return field;
|
|
269
|
+
}
|
|
270
|
+
__name(getFieldFromCollectionManager, "getFieldFromCollectionManager");
|
|
242
271
|
function createContextVariablesScope(ctx) {
|
|
243
272
|
const state = JSON.parse(JSON.stringify(ctx.state));
|
|
244
273
|
return {
|
|
245
274
|
timezone: ctx.get("x-timezone"),
|
|
246
275
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
247
276
|
getField: /* @__PURE__ */ __name((path) => {
|
|
248
|
-
const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
|
|
249
277
|
const { resourceName } = ctx.action;
|
|
278
|
+
const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
|
|
279
|
+
if (!ctx.database) {
|
|
280
|
+
return getFieldFromCollectionManager(ctx, resourceName, fieldPath);
|
|
281
|
+
}
|
|
250
282
|
return ctx.database.getFieldByPath(`${resourceName}.${fieldPath}`);
|
|
251
283
|
}, "getField"),
|
|
252
284
|
vars: {
|
package/lib/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './plugin-manager';
|
|
|
20
20
|
export * from './pub-sub-manager';
|
|
21
21
|
export * from './event-queue';
|
|
22
22
|
export * from './worker-id-allocator';
|
|
23
|
+
export * from './worker-mode';
|
|
23
24
|
export * from './redis-connection-manager';
|
|
24
25
|
export * from './main-data-source';
|
|
25
26
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
package/lib/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
|
63
63
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
64
64
|
__reExport(src_exports, require("./event-queue"), module.exports);
|
|
65
65
|
__reExport(src_exports, require("./worker-id-allocator"), module.exports);
|
|
66
|
+
__reExport(src_exports, require("./worker-mode"), module.exports);
|
|
66
67
|
__reExport(src_exports, require("./redis-connection-manager"), module.exports);
|
|
67
68
|
__reExport(src_exports, require("./main-data-source"), module.exports);
|
|
68
69
|
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
@@ -92,6 +93,7 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
92
93
|
...require("./pub-sub-manager"),
|
|
93
94
|
...require("./event-queue"),
|
|
94
95
|
...require("./worker-id-allocator"),
|
|
96
|
+
...require("./worker-mode"),
|
|
95
97
|
...require("./redis-connection-manager"),
|
|
96
98
|
...require("./main-data-source")
|
|
97
99
|
});
|
package/lib/main-data-source.js
CHANGED
|
@@ -96,6 +96,7 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
96
96
|
const results = await this.tables2Collections(toAddTables);
|
|
97
97
|
const values = results.map((result) => ({
|
|
98
98
|
...result,
|
|
99
|
+
from: "dbsync",
|
|
99
100
|
underscored: false
|
|
100
101
|
}));
|
|
101
102
|
await repo.create({ values, context: ctx });
|
|
@@ -115,14 +116,16 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
115
116
|
...filter
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
|
-
const collections = loadedCollections.filter(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
const collections = loadedCollections.filter(
|
|
120
|
+
(collection) => {
|
|
121
|
+
var _a;
|
|
122
|
+
return !["db2cm", "dbsync"].includes((_a = collection.options) == null ? void 0 : _a.from);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
122
125
|
const loadedData = {};
|
|
123
126
|
for (const collection of collections) {
|
|
124
127
|
const c = db.getCollection(collection.name);
|
|
125
|
-
loadedData[c.tableName
|
|
128
|
+
loadedData[c.model.tableName] = {
|
|
126
129
|
...collection.toJSON(),
|
|
127
130
|
fields: collection.fields.map((field) => {
|
|
128
131
|
const f = c.getField(field.name);
|
|
@@ -44,7 +44,7 @@ const deps = {
|
|
|
44
44
|
mathjs: "15.x",
|
|
45
45
|
winston: "3.x",
|
|
46
46
|
"winston-daily-rotate-file": "4.x",
|
|
47
|
-
koa: "
|
|
47
|
+
koa: "3.x",
|
|
48
48
|
"@koa/cors": "5.x",
|
|
49
49
|
"@koa/router": "13.x",
|
|
50
50
|
multer: "1.x",
|
|
@@ -76,6 +76,7 @@ const deps = {
|
|
|
76
76
|
lodash: "4.x",
|
|
77
77
|
"china-division": "2.x",
|
|
78
78
|
cronstrue: "2.x",
|
|
79
|
-
"@nocobase/license-kit": "0.3.x"
|
|
79
|
+
"@nocobase/license-kit": "0.3.x",
|
|
80
|
+
joi: "17.x"
|
|
80
81
|
};
|
|
81
82
|
var deps_default = deps;
|
|
@@ -46,6 +46,7 @@ __export(findPackageNames_exports, {
|
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(findPackageNames_exports);
|
|
48
48
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
49
|
+
var import_utils = require("@nocobase/utils");
|
|
49
50
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
50
51
|
var import_lodash = __toESM(require("lodash"));
|
|
51
52
|
var import_path = __toESM(require("path"));
|
|
@@ -81,12 +82,13 @@ const excludes = [
|
|
|
81
82
|
"@nocobase/plugin-workflow-test"
|
|
82
83
|
];
|
|
83
84
|
async function findPackageNames() {
|
|
85
|
+
const pluginStoragePath = (0, import_utils.resolvePluginStoragePath)();
|
|
84
86
|
const patterns = [
|
|
85
87
|
"./packages/plugins/*/package.json",
|
|
86
88
|
"./packages/plugins/*/*/package.json",
|
|
87
89
|
"./packages/pro-plugins/*/*/package.json",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
+
import_path.default.join(pluginStoragePath, "*/package.json"),
|
|
91
|
+
import_path.default.join(pluginStoragePath, "*/*/package.json")
|
|
90
92
|
];
|
|
91
93
|
try {
|
|
92
94
|
const packageJsonPaths = await (0, import_fast_glob.default)(patterns, {
|
|
@@ -6,6 +6,15 @@
|
|
|
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 type PluginClientLane = 'client' | 'client-v2';
|
|
10
|
+
export declare class PackageUrls {
|
|
11
|
+
static items: Record<string, string | undefined>;
|
|
12
|
+
static clear(): void;
|
|
13
|
+
static getCacheKey(packageName: string, lane: PluginClientLane): string;
|
|
14
|
+
static get(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
15
|
+
static hasClientEntry(packageName: string, lane: PluginClientLane): Promise<boolean>;
|
|
16
|
+
static fetch(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
17
|
+
}
|
|
9
18
|
declare const _default: {
|
|
10
19
|
name: string;
|
|
11
20
|
actions: {
|
|
@@ -15,8 +24,9 @@ declare const _default: {
|
|
|
15
24
|
enable(ctx: any, next: any): Promise<void>;
|
|
16
25
|
disable(ctx: any, next: any): Promise<void>;
|
|
17
26
|
remove(ctx: any, next: any): Promise<void>;
|
|
18
|
-
list(ctx: any, next: any): Promise<
|
|
27
|
+
list(ctx: any, next: any): Promise<any>;
|
|
19
28
|
listEnabled(ctx: any, next: any): Promise<void>;
|
|
29
|
+
listEnabledV2(ctx: any, next: any): Promise<void>;
|
|
20
30
|
get(ctx: any, next: any): Promise<void>;
|
|
21
31
|
};
|
|
22
32
|
};
|