@nocobase/server 2.4.0-alpha.2 → 2.4.0-alpha.20
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/README.md +4 -4
- package/lib/app-supervisor/index.d.ts +5 -1
- package/lib/app-supervisor/index.js +37 -18
- package/lib/app-supervisor/main-only-adapter.js +8 -2
- package/lib/app-supervisor/types.d.ts +1 -1
- package/lib/application.d.ts +8 -0
- package/lib/application.js +18 -2
- package/lib/audit-manager/index.d.ts +3 -0
- package/lib/audit-manager/index.js +12 -2
- package/lib/environment.d.ts +5 -1
- package/lib/environment.js +17 -1
- package/lib/gateway/errors.d.ts +5 -0
- package/lib/gateway/errors.js +21 -0
- package/lib/gateway/index.d.ts +1 -0
- package/lib/gateway/index.js +60 -44
- package/lib/gateway/static-file-security.js +1 -0
- package/lib/gateway/ws-server.d.ts +5 -0
- package/lib/gateway/ws-server.js +31 -5
- package/lib/helper.js +57 -2
- package/lib/main-data-source.js +11 -7
- package/lib/plugin-manager/deps.js +1 -1
- package/lib/plugin-manager/utils.js +1 -1
- package/lib/plugin.js +1 -10
- package/lib/types/vendor.d.js +9 -0
- package/package.json +18 -19
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Online Demo:
|
|
|
24
24
|
https://demo.nocobase.com/new
|
|
25
25
|
|
|
26
26
|
Documents:
|
|
27
|
-
https://docs.nocobase.com/
|
|
27
|
+
https://nocode.docs.nocobase.com/
|
|
28
28
|
|
|
29
29
|
Forum:
|
|
30
30
|
https://forum.nocobase.com/
|
|
@@ -80,15 +80,15 @@ Adding more no-code features will never cover every business case. NocoBase is b
|
|
|
80
80
|
|
|
81
81
|
NocoBase supports three installation methods:
|
|
82
82
|
|
|
83
|
-
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
|
|
83
|
+
- <a target="_blank" href="https://nocode.docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
|
|
84
84
|
|
|
85
85
|
Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
|
|
86
86
|
|
|
87
|
-
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
|
|
87
|
+
- <a target="_blank" href="https://nocode.docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
|
|
88
88
|
|
|
89
89
|
The business code of the project is completely independent and supports low-code development.
|
|
90
90
|
|
|
91
|
-
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
|
|
91
|
+
- <a target="_blank" href="https://nocode.docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
|
|
92
92
|
|
|
93
93
|
If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
|
|
94
94
|
|
|
@@ -43,6 +43,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
43
43
|
emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
|
44
44
|
private discoveryAdapter;
|
|
45
45
|
private processAdapter;
|
|
46
|
+
private readonly syncedStopAppName;
|
|
46
47
|
private commandAdapter;
|
|
47
48
|
private discoveryAdapterName;
|
|
48
49
|
private processAdapterName;
|
|
@@ -53,6 +54,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
53
54
|
private appSsoIssuer?;
|
|
54
55
|
appOptionsFactory: AppOptionsFactory;
|
|
55
56
|
private environmentHeartbeatInterval;
|
|
57
|
+
private environmentHeartbeatTimeout;
|
|
56
58
|
private environmentHeartbeatTimer;
|
|
57
59
|
private constructor();
|
|
58
60
|
private resolveDiscoveryAdapterName;
|
|
@@ -163,11 +165,13 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
163
165
|
proxyWeb(appName: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
|
|
164
166
|
proxyWs(req: IncomingMessage, socket: any, head: Buffer): Promise<boolean>;
|
|
165
167
|
registerEnvironment(mainApp: Application): Promise<void>;
|
|
168
|
+
private getEnvironmentInfo;
|
|
166
169
|
unregisterEnvironment(): Promise<void>;
|
|
167
170
|
private normalizeEnvInfo;
|
|
168
171
|
listEnvironments(): Promise<EnvironmentInfo[]>;
|
|
169
172
|
getEnvironment(environmentName: string): Promise<EnvironmentInfo>;
|
|
170
|
-
heartbeatEnvironment(): Promise<void>;
|
|
173
|
+
heartbeatEnvironment(mainApp: Application): Promise<void>;
|
|
174
|
+
private stopEnvironmentHeartbeat;
|
|
171
175
|
dispatchCommand(command: ProcessCommand): Promise<void>;
|
|
172
176
|
registerCommandHandler(mainApp: Application): void;
|
|
173
177
|
sendSyncMessage(mainApp: Application, message: {
|
|
@@ -43,6 +43,7 @@ __export(app_supervisor_exports, {
|
|
|
43
43
|
MainOnlyAdapter: () => import_main_only_adapter2.MainOnlyAdapter
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(app_supervisor_exports);
|
|
46
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
46
47
|
var import_lodash = __toESM(require("lodash"));
|
|
47
48
|
var import_utils = require("@nocobase/utils");
|
|
48
49
|
var import_events = require("events");
|
|
@@ -64,6 +65,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
64
65
|
aesEncryptor;
|
|
65
66
|
discoveryAdapter;
|
|
66
67
|
processAdapter;
|
|
68
|
+
syncedStopAppName = new import_node_async_hooks.AsyncLocalStorage();
|
|
67
69
|
commandAdapter;
|
|
68
70
|
discoveryAdapterName;
|
|
69
71
|
processAdapterName;
|
|
@@ -74,6 +76,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
74
76
|
appSsoIssuer;
|
|
75
77
|
appOptionsFactory = import_app_options_factory.appOptionsFactory;
|
|
76
78
|
environmentHeartbeatInterval = 2 * 60 * 1e3;
|
|
79
|
+
environmentHeartbeatTimeout = 5 * 60 * 1e3;
|
|
77
80
|
environmentHeartbeatTimer = null;
|
|
78
81
|
constructor() {
|
|
79
82
|
super();
|
|
@@ -282,13 +285,11 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
282
285
|
}
|
|
283
286
|
async reset() {
|
|
284
287
|
var _a, _b, _c, _d;
|
|
288
|
+
this.stopEnvironmentHeartbeat();
|
|
285
289
|
await this.processAdapter.removeAllApps();
|
|
286
290
|
await ((_b = (_a = this.discoveryAdapter).dispose) == null ? void 0 : _b.call(_a));
|
|
287
291
|
await ((_d = (_c = this.commandAdapter) == null ? void 0 : _c.dispose) == null ? void 0 : _d.call(_c));
|
|
288
292
|
this.appManifests.clear();
|
|
289
|
-
if (this.environmentHeartbeatTimer) {
|
|
290
|
-
this.environmentHeartbeatTimer = null;
|
|
291
|
-
}
|
|
292
293
|
this.removeAllListeners();
|
|
293
294
|
this.logger.close();
|
|
294
295
|
}
|
|
@@ -353,6 +354,9 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
353
354
|
});
|
|
354
355
|
});
|
|
355
356
|
app.on("afterStop", async () => {
|
|
357
|
+
if (this.syncedStopAppName.getStore() === appName) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
356
360
|
await this.sendSyncMessage(mainApp, {
|
|
357
361
|
type: "app:stopped",
|
|
358
362
|
appName
|
|
@@ -389,12 +393,17 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
389
393
|
if (!appOptions) {
|
|
390
394
|
return;
|
|
391
395
|
}
|
|
396
|
+
if (appModel.environments && !appModel.environments.includes(this.environmentName)) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
392
399
|
const newApp = this.registerApp({ appModel, mainApp: app2 });
|
|
393
400
|
newApp.runCommand("start", "--quickstart");
|
|
394
401
|
}
|
|
395
402
|
if (type === "app:stopped") {
|
|
396
403
|
const { appName } = message;
|
|
397
|
-
|
|
404
|
+
if (this.hasApp(appName)) {
|
|
405
|
+
await this.syncedStopAppName.run(appName, () => this.stopApp(appName));
|
|
406
|
+
}
|
|
398
407
|
}
|
|
399
408
|
if (type === "app:removed") {
|
|
400
409
|
const { appName } = message;
|
|
@@ -601,24 +610,25 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
601
610
|
if (!this.environmentName || typeof this.discoveryAdapter.registerEnvironment !== "function") {
|
|
602
611
|
return;
|
|
603
612
|
}
|
|
604
|
-
const registered = await this.discoveryAdapter.registerEnvironment(
|
|
613
|
+
const registered = await this.discoveryAdapter.registerEnvironment(this.getEnvironmentInfo(mainApp));
|
|
614
|
+
if (registered) {
|
|
615
|
+
this.heartbeatEnvironment(mainApp);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
getEnvironmentInfo(mainApp) {
|
|
619
|
+
return {
|
|
605
620
|
name: this.environmentName,
|
|
606
621
|
url: this.environmentUrl || "",
|
|
607
622
|
proxyUrl: this.environmentProxyUrl || this.environmentUrl || "",
|
|
608
623
|
appVersion: mainApp.getPackageVersion(),
|
|
609
624
|
lastHeartbeatAt: Date.now()
|
|
610
|
-
}
|
|
611
|
-
if (registered) {
|
|
612
|
-
this.heartbeatEnvironment();
|
|
613
|
-
}
|
|
625
|
+
};
|
|
614
626
|
}
|
|
615
627
|
async unregisterEnvironment() {
|
|
628
|
+
this.stopEnvironmentHeartbeat();
|
|
616
629
|
if (this.environmentName && typeof this.discoveryAdapter.unregisterEnvironment === "function") {
|
|
617
630
|
await this.discoveryAdapter.unregisterEnvironment();
|
|
618
631
|
}
|
|
619
|
-
if (this.environmentHeartbeatTimer) {
|
|
620
|
-
this.environmentHeartbeatTimer = null;
|
|
621
|
-
}
|
|
622
632
|
}
|
|
623
633
|
normalizeEnvInfo(environment) {
|
|
624
634
|
if (typeof environment.available === "boolean") {
|
|
@@ -631,7 +641,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
631
641
|
available: false
|
|
632
642
|
};
|
|
633
643
|
}
|
|
634
|
-
const available = Date.now() - lastHeartbeatAt <= this.
|
|
644
|
+
const available = Date.now() - lastHeartbeatAt <= this.environmentHeartbeatTimeout;
|
|
635
645
|
return {
|
|
636
646
|
...environment,
|
|
637
647
|
available
|
|
@@ -654,17 +664,26 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
654
664
|
}
|
|
655
665
|
return this.normalizeEnvInfo(environment);
|
|
656
666
|
}
|
|
657
|
-
async heartbeatEnvironment() {
|
|
667
|
+
async heartbeatEnvironment(mainApp) {
|
|
658
668
|
if (typeof this.discoveryAdapter.heartbeatEnvironment !== "function") {
|
|
659
669
|
return;
|
|
660
670
|
}
|
|
661
671
|
if (this.environmentHeartbeatTimer) {
|
|
662
672
|
return;
|
|
663
673
|
}
|
|
664
|
-
this.environmentHeartbeatTimer = setInterval(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
674
|
+
this.environmentHeartbeatTimer = setInterval(async () => {
|
|
675
|
+
try {
|
|
676
|
+
await this.discoveryAdapter.heartbeatEnvironment(this.getEnvironmentInfo(mainApp));
|
|
677
|
+
} catch (error) {
|
|
678
|
+
this.logger.error(error instanceof Error ? error.message : String(error), { method: "heartbeatEnvironment" });
|
|
679
|
+
}
|
|
680
|
+
}, this.environmentHeartbeatInterval);
|
|
681
|
+
}
|
|
682
|
+
stopEnvironmentHeartbeat() {
|
|
683
|
+
if (this.environmentHeartbeatTimer) {
|
|
684
|
+
clearInterval(this.environmentHeartbeatTimer);
|
|
685
|
+
this.environmentHeartbeatTimer = null;
|
|
686
|
+
}
|
|
668
687
|
}
|
|
669
688
|
async dispatchCommand(command) {
|
|
670
689
|
var _a;
|
|
@@ -50,7 +50,10 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
50
50
|
return this.apps[appName];
|
|
51
51
|
}
|
|
52
52
|
async bootstrapApp(appName) {
|
|
53
|
-
if (appName !== "main"
|
|
53
|
+
if (appName !== "main") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!this.apps[appName]) {
|
|
54
57
|
this.setAppStatus(appName, "not_found");
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
@@ -138,13 +141,16 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
138
141
|
return this.removeApp("main");
|
|
139
142
|
}
|
|
140
143
|
setAppStatus(appName, status, options = {}) {
|
|
141
|
-
if (this.status === status) {
|
|
144
|
+
if (appName !== "main" || this.status === status) {
|
|
142
145
|
return;
|
|
143
146
|
}
|
|
144
147
|
this.status = status;
|
|
145
148
|
this.supervisor.emit("appStatusChanged", { appName, status, options });
|
|
146
149
|
}
|
|
147
150
|
getAppStatus(appName, defaultStatus) {
|
|
151
|
+
if (appName !== "main") {
|
|
152
|
+
return "not_found";
|
|
153
|
+
}
|
|
148
154
|
return this.status ?? defaultStatus ?? null;
|
|
149
155
|
}
|
|
150
156
|
hasAppError(appName) {
|
|
@@ -132,7 +132,7 @@ export interface AppDiscoveryAdapter {
|
|
|
132
132
|
unregisterEnvironment?(): Promise<void>;
|
|
133
133
|
listEnvironments?(): Promise<EnvironmentInfo[]>;
|
|
134
134
|
getEnvironment?(environmentName: string): Promise<EnvironmentInfo | null>;
|
|
135
|
-
heartbeatEnvironment?(): Promise<void>;
|
|
135
|
+
heartbeatEnvironment?(environment: EnvironmentInfo): Promise<void>;
|
|
136
136
|
getBootstrapLock?(appName: string): Promise<BootstrapLock | null> | BootstrapLock | null;
|
|
137
137
|
proxyWeb?(appName: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
|
|
138
138
|
proxyWs?(req: IncomingMessage, socket: any, head: Buffer): Promise<boolean>;
|
package/lib/application.d.ts
CHANGED
|
@@ -201,6 +201,14 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
201
201
|
static addCommand(callback: (app: Application) => void): void;
|
|
202
202
|
private _sqlLogger;
|
|
203
203
|
get instanceId(): number;
|
|
204
|
+
/**
|
|
205
|
+
* Adopt a worker id handed out at runtime, after the allocator loses its lease and acquires a different one. Ids may
|
|
206
|
+
* only be minted under a worker id this process currently holds, so the generator is rebuilt to match.
|
|
207
|
+
*
|
|
208
|
+
* Returning early on an unchanged id is required rather than an optimisation: rebuilding restarts the sequence at 0,
|
|
209
|
+
* so doing it for the same worker id inside one second would re-issue ids this process has already handed out.
|
|
210
|
+
*/
|
|
211
|
+
setInstanceId(instanceId: number): void;
|
|
204
212
|
get sqlLogger(): Logger;
|
|
205
213
|
protected _logger: SystemLogger;
|
|
206
214
|
get logger(): SystemLogger;
|
package/lib/application.js
CHANGED
|
@@ -154,6 +154,21 @@ const _Application = class _Application extends import_koa.default {
|
|
|
154
154
|
get instanceId() {
|
|
155
155
|
return this._instanceId;
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Adopt a worker id handed out at runtime, after the allocator loses its lease and acquires a different one. Ids may
|
|
159
|
+
* only be minted under a worker id this process currently holds, so the generator is rebuilt to match.
|
|
160
|
+
*
|
|
161
|
+
* Returning early on an unchanged id is required rather than an optimisation: rebuilding restarts the sequence at 0,
|
|
162
|
+
* so doing it for the same worker id inside one second would re-issue ids this process has already handed out.
|
|
163
|
+
*/
|
|
164
|
+
setInstanceId(instanceId) {
|
|
165
|
+
if (this._instanceId === instanceId) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this._instanceId = instanceId;
|
|
169
|
+
this.snowflakeIdGenerator = new import_snowflake_id.Snowflake({ workerId: instanceId });
|
|
170
|
+
this.log.info(`adopt worker id: ${instanceId}`, { method: "setInstanceId" });
|
|
171
|
+
}
|
|
157
172
|
get sqlLogger() {
|
|
158
173
|
return this._sqlLogger;
|
|
159
174
|
}
|
|
@@ -383,6 +398,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
383
398
|
return this.cli._findCommand(name);
|
|
384
399
|
}
|
|
385
400
|
async disposeServices() {
|
|
401
|
+
await this.workerIdAllocator.release();
|
|
386
402
|
if (this.redisConnectionManager) {
|
|
387
403
|
await this.redisConnectionManager.close();
|
|
388
404
|
}
|
|
@@ -395,7 +411,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
395
411
|
if (this.telemetry.started) {
|
|
396
412
|
await this.telemetry.shutdown();
|
|
397
413
|
}
|
|
398
|
-
await this.workerIdAllocator.release();
|
|
399
414
|
}
|
|
400
415
|
/**
|
|
401
416
|
* @internal
|
|
@@ -452,7 +467,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
452
467
|
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
453
468
|
await this.emitAsync("beforeLoad", this, options);
|
|
454
469
|
}
|
|
455
|
-
if (
|
|
470
|
+
if (this._instanceId == null) {
|
|
456
471
|
this._instanceId = await this.workerIdAllocator.getWorkerId();
|
|
457
472
|
this.log.info(`allocate worker id: ${this._instanceId}`, { method: "load" });
|
|
458
473
|
}
|
|
@@ -881,6 +896,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
881
896
|
init() {
|
|
882
897
|
const options = this.options;
|
|
883
898
|
this._instanceId = options.instanceId;
|
|
899
|
+
this.snowflakeIdGenerator = void 0;
|
|
884
900
|
this.initLogger(options.logger);
|
|
885
901
|
this.reInitEvents();
|
|
886
902
|
this.middleware = new import_utils.Toposort();
|
|
@@ -43,10 +43,13 @@ type Action = string | {
|
|
|
43
43
|
getUserInfo?: (ctx: Context) => Promise<UserInfo>;
|
|
44
44
|
getSourceAndTarget?: (ctx: Context) => Promise<SourceAndTarget>;
|
|
45
45
|
};
|
|
46
|
+
type MetadataSanitizer = (metadata: NonNullable<AuditLog['metadata']>) => NonNullable<AuditLog['metadata']>;
|
|
46
47
|
export declare class AuditManager {
|
|
48
|
+
private readonly metadataSanitizers;
|
|
47
49
|
logger: AuditLogger;
|
|
48
50
|
resources: Map<string, Map<string, Action>>;
|
|
49
51
|
constructor();
|
|
52
|
+
registerMetadataSanitizer(dataSource: string, resource: string, actions: string[], sanitize: MetadataSanitizer): void;
|
|
50
53
|
setLogger(logger: AuditLogger): void;
|
|
51
54
|
/**
|
|
52
55
|
* 注册需要参与审计的资源和操作,支持几种写法
|
|
@@ -47,11 +47,17 @@ function isStream(obj) {
|
|
|
47
47
|
}
|
|
48
48
|
__name(isStream, "isStream");
|
|
49
49
|
const _AuditManager = class _AuditManager {
|
|
50
|
+
metadataSanitizers = /* @__PURE__ */ new Map();
|
|
50
51
|
logger;
|
|
51
52
|
resources;
|
|
52
53
|
constructor() {
|
|
53
54
|
this.resources = /* @__PURE__ */ new Map();
|
|
54
55
|
}
|
|
56
|
+
registerMetadataSanitizer(dataSource, resource, actions, sanitize) {
|
|
57
|
+
for (const action of actions) {
|
|
58
|
+
this.metadataSanitizers.set(`${dataSource}:${resource}:${action}`, sanitize);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
55
61
|
setLogger(logger) {
|
|
56
62
|
this.logger = logger;
|
|
57
63
|
}
|
|
@@ -253,7 +259,7 @@ const _AuditManager = class _AuditManager {
|
|
|
253
259
|
return auditLog;
|
|
254
260
|
}
|
|
255
261
|
async output(ctx, reqId, metadata) {
|
|
256
|
-
var _a;
|
|
262
|
+
var _a, _b;
|
|
257
263
|
try {
|
|
258
264
|
if (!ctx.action) {
|
|
259
265
|
return;
|
|
@@ -302,9 +308,13 @@ const _AuditManager = class _AuditManager {
|
|
|
302
308
|
}
|
|
303
309
|
}
|
|
304
310
|
}
|
|
311
|
+
const sanitize = this.metadataSanitizers.get(`${((_a = ctx.dataSource) == null ? void 0 : _a.name) || "main"}:${resourceName}:${actionName}`);
|
|
312
|
+
if (sanitize) {
|
|
313
|
+
auditLog.metadata = sanitize(auditLog.metadata);
|
|
314
|
+
}
|
|
305
315
|
this.logger.log(auditLog);
|
|
306
316
|
} catch (err) {
|
|
307
|
-
(
|
|
317
|
+
(_b = ctx.log) == null ? void 0 : _b.error(err);
|
|
308
318
|
}
|
|
309
319
|
}
|
|
310
320
|
// 中间件
|
package/lib/environment.d.ts
CHANGED
|
@@ -8,10 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class Environment {
|
|
10
10
|
private vars;
|
|
11
|
-
|
|
11
|
+
private secretKeys;
|
|
12
|
+
setVariable(key: string, value: string, options?: {
|
|
13
|
+
isSecret?: boolean;
|
|
14
|
+
}): void;
|
|
12
15
|
removeVariable(key: string): void;
|
|
13
16
|
getVariablesAndSecrets(): {};
|
|
14
17
|
getVariables(): {};
|
|
18
|
+
getNonSecretVariables(): {};
|
|
15
19
|
renderJsonTemplate(template: any, options?: {
|
|
16
20
|
omit?: string[];
|
|
17
21
|
}): any;
|
package/lib/environment.js
CHANGED
|
@@ -44,11 +44,18 @@ var import_utils = require("@nocobase/utils");
|
|
|
44
44
|
var import_lodash = __toESM(require("lodash"));
|
|
45
45
|
const _Environment = class _Environment {
|
|
46
46
|
vars = {};
|
|
47
|
-
|
|
47
|
+
secretKeys = /* @__PURE__ */ new Set();
|
|
48
|
+
setVariable(key, value, options) {
|
|
48
49
|
this.vars[key] = value;
|
|
50
|
+
if ((options == null ? void 0 : options.isSecret) === true) {
|
|
51
|
+
this.secretKeys.add(key);
|
|
52
|
+
} else if ((options == null ? void 0 : options.isSecret) === false) {
|
|
53
|
+
this.secretKeys.delete(key);
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
removeVariable(key) {
|
|
51
57
|
delete this.vars[key];
|
|
58
|
+
this.secretKeys.delete(key);
|
|
52
59
|
}
|
|
53
60
|
getVariablesAndSecrets() {
|
|
54
61
|
return this.vars;
|
|
@@ -56,6 +63,15 @@ const _Environment = class _Environment {
|
|
|
56
63
|
getVariables() {
|
|
57
64
|
return this.vars;
|
|
58
65
|
}
|
|
66
|
+
getNonSecretVariables() {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const key of Object.keys(this.vars)) {
|
|
69
|
+
if (!this.secretKeys.has(key)) {
|
|
70
|
+
result[key] = this.vars[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
59
75
|
renderJsonTemplate(template, options) {
|
|
60
76
|
if (options == null ? void 0 : options.omit) {
|
|
61
77
|
const omitTemplate = import_lodash.default.omit(template, options.omit);
|
package/lib/gateway/errors.d.ts
CHANGED
|
@@ -6,6 +6,11 @@
|
|
|
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
|
+
/** Raised when a request resolves to an app name that could never name a real application. */
|
|
10
|
+
export declare class InvalidAppNameError extends Error {
|
|
11
|
+
readonly appName: unknown;
|
|
12
|
+
constructor(appName: unknown);
|
|
13
|
+
}
|
|
9
14
|
interface AppError {
|
|
10
15
|
status: number;
|
|
11
16
|
message: any;
|
package/lib/gateway/errors.js
CHANGED
|
@@ -37,6 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var errors_exports = {};
|
|
39
39
|
__export(errors_exports, {
|
|
40
|
+
InvalidAppNameError: () => InvalidAppNameError,
|
|
40
41
|
applyErrorWithArgs: () => applyErrorWithArgs,
|
|
41
42
|
errors: () => errors,
|
|
42
43
|
getErrorWithCode: () => getErrorWithCode
|
|
@@ -44,6 +45,15 @@ __export(errors_exports, {
|
|
|
44
45
|
module.exports = __toCommonJS(errors_exports);
|
|
45
46
|
var import_app_supervisor = require("../app-supervisor");
|
|
46
47
|
var import_lodash = __toESM(require("lodash"));
|
|
48
|
+
const _InvalidAppNameError = class _InvalidAppNameError extends Error {
|
|
49
|
+
constructor(appName) {
|
|
50
|
+
super("invalid application name");
|
|
51
|
+
this.appName = appName;
|
|
52
|
+
this.name = "InvalidAppNameError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__name(_InvalidAppNameError, "InvalidAppNameError");
|
|
56
|
+
let InvalidAppNameError = _InvalidAppNameError;
|
|
47
57
|
function getMaintaining(app) {
|
|
48
58
|
var _a;
|
|
49
59
|
return (_a = app == null ? void 0 : app.getMaintaining) == null ? void 0 : _a.call(app);
|
|
@@ -54,6 +64,16 @@ function getAppName(app) {
|
|
|
54
64
|
}
|
|
55
65
|
__name(getAppName, "getAppName");
|
|
56
66
|
const errors = {
|
|
67
|
+
INVALID_APP_NAME: {
|
|
68
|
+
status: 400,
|
|
69
|
+
message: "invalid application name",
|
|
70
|
+
maintaining: false
|
|
71
|
+
},
|
|
72
|
+
APP_ENVIRONMENT_UNAVAILABLE: {
|
|
73
|
+
status: 503,
|
|
74
|
+
message: /* @__PURE__ */ __name(({ appName }) => `deployment environment for application ${appName} is unavailable`, "message"),
|
|
75
|
+
maintaining: true
|
|
76
|
+
},
|
|
57
77
|
APP_NOT_FOUND: {
|
|
58
78
|
status: 404,
|
|
59
79
|
message: /* @__PURE__ */ __name(({ appName }) => `application ${appName} not found`, "message"),
|
|
@@ -186,6 +206,7 @@ function applyErrorWithArgs(error, options) {
|
|
|
186
206
|
__name(applyErrorWithArgs, "applyErrorWithArgs");
|
|
187
207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
188
208
|
0 && (module.exports = {
|
|
209
|
+
InvalidAppNameError,
|
|
189
210
|
applyErrorWithArgs,
|
|
190
211
|
errors,
|
|
191
212
|
getErrorWithCode
|
package/lib/gateway/index.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export declare class Gateway extends EventEmitter {
|
|
|
108
108
|
requestHandler(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
109
109
|
getAppSelectorMiddlewares(): Toposort<AppSelectorMiddleware>;
|
|
110
110
|
getRequestHandleAppName(req: IncomingMessage | IncomingRequest): Promise<string>;
|
|
111
|
+
private handleUpgrade;
|
|
111
112
|
getCallback(): any;
|
|
112
113
|
watch(): Promise<void>;
|
|
113
114
|
run(options: RunOptions): Promise<void>;
|
package/lib/gateway/index.js
CHANGED
|
@@ -66,13 +66,21 @@ var import_plugin_manager = require("../plugin-manager");
|
|
|
66
66
|
var import_errors = require("./errors");
|
|
67
67
|
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
68
68
|
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
69
|
-
var import_static_file_security = require("./static-file-security");
|
|
70
69
|
var import_utils3 = require("./utils");
|
|
71
70
|
var import_ws_server = require("./ws-server");
|
|
72
71
|
var import_node_worker_threads = require("node:worker_threads");
|
|
73
72
|
var import_node_process = __toESM(require("node:process"));
|
|
74
73
|
var import_utils4 = require("./utils");
|
|
75
74
|
const compress = (0, import_node_util.promisify)((0, import_compression.default)());
|
|
75
|
+
const APP_NAME_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_-]*$/;
|
|
76
|
+
const MAX_APP_NAME_LENGTH = 255;
|
|
77
|
+
function isValidAppName(name) {
|
|
78
|
+
if (typeof name !== "string" || name.length > MAX_APP_NAME_LENGTH || !APP_NAME_PATTERN.test(name)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return !(name in Object.prototype);
|
|
82
|
+
}
|
|
83
|
+
__name(isValidAppName, "isValidAppName");
|
|
76
84
|
function normalizeBasePath(path = "") {
|
|
77
85
|
const normalized = path.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
78
86
|
return normalized || "/";
|
|
@@ -123,7 +131,17 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
123
131
|
const internalUrl = req.url;
|
|
124
132
|
req.url = this.getOriginalRequestUrl(req);
|
|
125
133
|
try {
|
|
126
|
-
|
|
134
|
+
const proxied = await supervisor.proxyWeb(appName, req, res);
|
|
135
|
+
const adapter = supervisor.getDiscoveryAdapter();
|
|
136
|
+
if (!proxied && import_node_process.default.env.APP_MODE === "supervisor" && typeof adapter.proxyWeb === "function") {
|
|
137
|
+
let code = "APP_ENVIRONMENT_UNAVAILABLE";
|
|
138
|
+
if (typeof adapter.getAppModel === "function" && !await supervisor.getAppModel(appName)) {
|
|
139
|
+
code = "APP_NOT_FOUND";
|
|
140
|
+
}
|
|
141
|
+
this.responseErrorWithCode(code, res, { appName });
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return proxied;
|
|
127
145
|
} finally {
|
|
128
146
|
req.url = internalUrl;
|
|
129
147
|
}
|
|
@@ -263,6 +281,9 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
263
281
|
this.emit("appSelectorChanged");
|
|
264
282
|
}
|
|
265
283
|
getLogger(appName, res) {
|
|
284
|
+
if (!isValidAppName(appName)) {
|
|
285
|
+
throw new Error("Invalid app name");
|
|
286
|
+
}
|
|
266
287
|
const reqId = (0, import_crypto.randomUUID)();
|
|
267
288
|
res.setHeader("X-Request-Id", reqId);
|
|
268
289
|
let logger = this.loggers.get(appName);
|
|
@@ -286,7 +307,9 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
286
307
|
res.end(JSON.stringify({ error }));
|
|
287
308
|
}
|
|
288
309
|
responseErrorWithCode(code, res, options) {
|
|
289
|
-
const
|
|
310
|
+
const appName = options == null ? void 0 : options.appName;
|
|
311
|
+
const loggerName = isValidAppName(appName) && import_app_supervisor.AppSupervisor.getInstance().hasApp(appName) ? appName : "main";
|
|
312
|
+
const log = this.getLogger(loggerName, res);
|
|
290
313
|
const error = (0, import_errors.applyErrorWithArgs)((0, import_errors.getErrorWithCode)(code), options);
|
|
291
314
|
log.error(error.message, {
|
|
292
315
|
method: "responseErrorWithCode",
|
|
@@ -604,31 +627,14 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
604
627
|
try {
|
|
605
628
|
handleApp = await this.getRequestHandleAppName(req);
|
|
606
629
|
} catch (error) {
|
|
630
|
+
if (error instanceof import_errors.InvalidAppNameError) {
|
|
631
|
+
this.responseErrorWithCode("INVALID_APP_NAME", res, {});
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
607
634
|
this.getLogger("main", res).error("Failed to get handle app name", { error });
|
|
608
635
|
this.responseErrorWithCode("APP_INITIALIZING", res, { appName: handleApp });
|
|
609
636
|
return;
|
|
610
637
|
}
|
|
611
|
-
if (pathname.startsWith(APP_PUBLIC_PATH + "storage/uploads/")) {
|
|
612
|
-
if (handleApp !== "main") {
|
|
613
|
-
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
614
|
-
if (isProxy) {
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const headers = (0, import_static_file_security.getStorageUploadSecurityHeaders)(`${pathname}${search || ""}`);
|
|
619
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
|
|
620
|
-
await compress(req, res);
|
|
621
|
-
return (0, import_serve_handler.default)(req, res, {
|
|
622
|
-
public: (0, import_utils.resolveStorageRoot)(),
|
|
623
|
-
directoryListing: false,
|
|
624
|
-
headers: [
|
|
625
|
-
{
|
|
626
|
-
source: "**/*",
|
|
627
|
-
headers: Object.entries(headers).map(([key, value]) => ({ key, value }))
|
|
628
|
-
}
|
|
629
|
-
]
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
638
|
if (pathname.startsWith(APP_PUBLIC_PATH + "dist/")) {
|
|
633
639
|
if (handleApp !== "main") {
|
|
634
640
|
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
@@ -665,7 +671,8 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
665
671
|
});
|
|
666
672
|
}
|
|
667
673
|
const isFilesRequest = Boolean(getFileAccessRestPath(pathname, APP_PUBLIC_PATH));
|
|
668
|
-
|
|
674
|
+
const isLegacyUploadRequest = pathname.startsWith(APP_PUBLIC_PATH + "storage/uploads/");
|
|
675
|
+
if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH) && !isFilesRequest && !isLegacyUploadRequest) {
|
|
669
676
|
if (this.isSettingsRequest(pathname)) {
|
|
670
677
|
if (handleApp !== "main") {
|
|
671
678
|
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
@@ -839,8 +846,32 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
839
846
|
if (!ctx.resolvedAppName) {
|
|
840
847
|
ctx.resolvedAppName = "main";
|
|
841
848
|
}
|
|
849
|
+
if (!isValidAppName(ctx.resolvedAppName)) {
|
|
850
|
+
throw new import_errors.InvalidAppNameError(ctx.resolvedAppName);
|
|
851
|
+
}
|
|
842
852
|
return ctx.resolvedAppName;
|
|
843
853
|
}
|
|
854
|
+
async handleUpgrade(request, socket, head) {
|
|
855
|
+
const isProxy = await import_app_supervisor.AppSupervisor.getInstance().proxyWs(request, socket, head);
|
|
856
|
+
if (isProxy) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const appInstance = await import_app_supervisor.AppSupervisor.getInstance().getApp("main");
|
|
860
|
+
for (const handle of _Gateway.wsServers) {
|
|
861
|
+
const result = await handle(request, socket, head, appInstance);
|
|
862
|
+
if (result !== false) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const { pathname } = (0, import_url.parse)(request.url);
|
|
867
|
+
if (pathname === import_node_process.default.env.WS_PATH) {
|
|
868
|
+
this.wsServer.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
869
|
+
this.wsServer.wss.emit("connection", ws, request);
|
|
870
|
+
});
|
|
871
|
+
} else {
|
|
872
|
+
socket.destroy();
|
|
873
|
+
}
|
|
874
|
+
}
|
|
844
875
|
getCallback() {
|
|
845
876
|
return this.requestHandler.bind(this);
|
|
846
877
|
}
|
|
@@ -957,26 +988,11 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
957
988
|
this.getCallback()(req, res);
|
|
958
989
|
});
|
|
959
990
|
this.wsServer = new import_ws_server.WSServer();
|
|
960
|
-
this.server.on("upgrade",
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
const appInstance = await import_app_supervisor.AppSupervisor.getInstance().getApp("main");
|
|
966
|
-
for (const handle of _Gateway.wsServers) {
|
|
967
|
-
const result = await handle(request, socket, head, appInstance);
|
|
968
|
-
if (result !== false) {
|
|
969
|
-
return;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
const { pathname } = (0, import_url.parse)(request.url);
|
|
973
|
-
if (pathname === import_node_process.default.env.WS_PATH) {
|
|
974
|
-
this.wsServer.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
975
|
-
this.wsServer.wss.emit("connection", ws, request);
|
|
976
|
-
});
|
|
977
|
-
} else {
|
|
991
|
+
this.server.on("upgrade", (request, socket, head) => {
|
|
992
|
+
this.handleUpgrade(request, socket, head).catch((error) => {
|
|
993
|
+
import_app_supervisor.AppSupervisor.getInstance().logger.error("Failed to handle websocket upgrade", { error });
|
|
978
994
|
socket.destroy();
|
|
979
|
-
}
|
|
995
|
+
});
|
|
980
996
|
});
|
|
981
997
|
this.server.listen(this.port, this.host, () => {
|
|
982
998
|
console.log(`Gateway HTTP Server running at http://${this.host}:${this.port}/`);
|
|
@@ -74,6 +74,7 @@ function hasActiveContentExtension(pathname = "") {
|
|
|
74
74
|
__name(hasActiveContentExtension, "hasActiveContentExtension");
|
|
75
75
|
function getStorageUploadSecurityHeaders(pathname = "") {
|
|
76
76
|
const headers = {
|
|
77
|
+
"Cache-Control": "private, no-store",
|
|
77
78
|
"Content-Security-Policy": "sandbox",
|
|
78
79
|
"X-Content-Type-Options": "nosniff"
|
|
79
80
|
};
|
|
@@ -32,6 +32,11 @@ export declare class WSServer extends EventEmitter {
|
|
|
32
32
|
addNewConnection(ws: WebSocketWithId, request: IncomingMessage): WebSocketClient;
|
|
33
33
|
setClientTag(clientId: string, tagKey: string, tagValue: string): void;
|
|
34
34
|
removeClientTag(clientId: string, tagKey: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Drop a connection whose url or headers resolve to an app name that can never exist. Closing beats tagging it with
|
|
37
|
+
* the raw value: the tag would end up as a map key and would bootstrap an app on every selector change.
|
|
38
|
+
*/
|
|
39
|
+
private rejectInvalidAppName;
|
|
35
40
|
setClientApp(client: WebSocketClient): Promise<void>;
|
|
36
41
|
removeConnection(id: string): void;
|
|
37
42
|
sendMessageToConnection(client: WebSocketClient, sendMessage: object): void;
|
package/lib/gateway/ws-server.js
CHANGED
|
@@ -80,10 +80,19 @@ const _WSServer = class _WSServer extends import_events.default {
|
|
|
80
80
|
});
|
|
81
81
|
import_gateway.Gateway.getInstance().on("appSelectorChanged", () => {
|
|
82
82
|
this.loopThroughConnections(async (client) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
let handleAppName;
|
|
84
|
+
try {
|
|
85
|
+
handleAppName = await import_gateway.Gateway.getInstance().getRequestHandleAppName({
|
|
86
|
+
url: client.url,
|
|
87
|
+
headers: client.headers
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!(error instanceof import_errors.InvalidAppNameError)) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
this.rejectInvalidAppName(client);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
87
96
|
for (const tag of client.tags) {
|
|
88
97
|
if (tag.startsWith("app#")) {
|
|
89
98
|
client.tags.delete(tag);
|
|
@@ -238,12 +247,29 @@ const _WSServer = class _WSServer extends import_events.default {
|
|
|
238
247
|
}
|
|
239
248
|
});
|
|
240
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Drop a connection whose url or headers resolve to an app name that can never exist. Closing beats tagging it with
|
|
252
|
+
* the raw value: the tag would end up as a map key and would bootstrap an app on every selector change.
|
|
253
|
+
*/
|
|
254
|
+
rejectInvalidAppName(client) {
|
|
255
|
+
client.ws.close(1008, "INVALID_APP_NAME");
|
|
256
|
+
this.removeConnection(client.id);
|
|
257
|
+
}
|
|
241
258
|
async setClientApp(client) {
|
|
242
259
|
const req = {
|
|
243
260
|
url: client.url,
|
|
244
261
|
headers: client.headers
|
|
245
262
|
};
|
|
246
|
-
|
|
263
|
+
let handleAppName;
|
|
264
|
+
try {
|
|
265
|
+
handleAppName = await import_gateway.Gateway.getInstance().getRequestHandleAppName(req);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (!(error instanceof import_errors.InvalidAppNameError)) {
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
this.rejectInvalidAppName(client);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
247
273
|
client.app = handleAppName;
|
|
248
274
|
console.log(`client tags: app#${handleAppName}`);
|
|
249
275
|
client.tags.add(`app#${handleAppName}`);
|
package/lib/helper.js
CHANGED
|
@@ -57,10 +57,24 @@ var import_crypto = require("crypto");
|
|
|
57
57
|
var import_fs = __toESM(require("fs"));
|
|
58
58
|
var import_i18next = __toESM(require("i18next"));
|
|
59
59
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
60
|
+
var import_koa_send = __toESM(require("koa-send"));
|
|
60
61
|
var import_perf_hooks = require("perf_hooks");
|
|
61
62
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
62
63
|
var import_extract_client_ip = require("./middlewares/extract-client-ip");
|
|
64
|
+
var import_static_file_security = require("./gateway/static-file-security");
|
|
63
65
|
var import_i18n = require("./middlewares/i18n");
|
|
66
|
+
function resolveAppPublicPath(value = "/") {
|
|
67
|
+
const normalized = String(value || "/").trim() || "/";
|
|
68
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
69
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
70
|
+
}
|
|
71
|
+
__name(resolveAppPublicPath, "resolveAppPublicPath");
|
|
72
|
+
function resolveApiBasePath(value = "/api") {
|
|
73
|
+
const normalized = String(value || "/api").trim() || "/api";
|
|
74
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
75
|
+
return withLeadingSlash.replace(/\/+$/g, "") || "/";
|
|
76
|
+
}
|
|
77
|
+
__name(resolveApiBasePath, "resolveApiBasePath");
|
|
64
78
|
function createI18n(options) {
|
|
65
79
|
const instance = import_i18next.default.createInstance();
|
|
66
80
|
instance.init({
|
|
@@ -138,7 +152,7 @@ function registerMiddlewares(app, options) {
|
|
|
138
152
|
}
|
|
139
153
|
app.use(/* @__PURE__ */ __name(async function getBearerToken(ctx, next) {
|
|
140
154
|
ctx.getBearerToken = () => {
|
|
141
|
-
var _a2;
|
|
155
|
+
var _a2, _b;
|
|
142
156
|
const authorization = ctx.get("Authorization");
|
|
143
157
|
if (authorization) {
|
|
144
158
|
ctx.state.pendingAuthTokenSource = "authorization";
|
|
@@ -148,7 +162,7 @@ function registerMiddlewares(app, options) {
|
|
|
148
162
|
ctx.state.pendingAuthTokenSource = "query";
|
|
149
163
|
return ctx.query.token;
|
|
150
164
|
}
|
|
151
|
-
const canUseAuthCookie = Boolean((_a2 = ctx.state) == null ? void 0 : _a2.fileAccess) && ["GET", "HEAD"].includes(ctx.method);
|
|
165
|
+
const canUseAuthCookie = Boolean(((_a2 = ctx.state) == null ? void 0 : _a2.fileAccess) || ((_b = ctx.state) == null ? void 0 : _b.legacyFileAccess)) && ["GET", "HEAD"].includes(ctx.method);
|
|
152
166
|
const cookieToken = canUseAuthCookie ? ctx.cookies.get((0, import_utils.getAuthCookieName)("authToken", app.name)) : void 0;
|
|
153
167
|
ctx.state.pendingAuthTokenSource = cookieToken ? "cookie" : void 0;
|
|
154
168
|
return cookieToken;
|
|
@@ -159,6 +173,47 @@ function registerMiddlewares(app, options) {
|
|
|
159
173
|
if (options.dataWrapping !== false) {
|
|
160
174
|
app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "cors" });
|
|
161
175
|
}
|
|
176
|
+
app.use(
|
|
177
|
+
/* @__PURE__ */ __name(async function legacyFileAccess(ctx, next) {
|
|
178
|
+
const publicPath = resolveAppPublicPath(process.env.APP_PUBLIC_PATH);
|
|
179
|
+
const uploadsPrefix = `${publicPath}storage/uploads/`;
|
|
180
|
+
const authCheckPath = `${resolveApiBasePath(process.env.API_BASE_PATH)}/auth:checkLegacyFileAccess`;
|
|
181
|
+
const isUploadRequest = ctx.path.startsWith(uploadsPrefix);
|
|
182
|
+
const isAuthCheckRequest = ctx.path === authCheckPath || ctx.path === "/auth:checkLegacyFileAccess";
|
|
183
|
+
if (!isUploadRequest && !isAuthCheckRequest) {
|
|
184
|
+
return next();
|
|
185
|
+
}
|
|
186
|
+
if (!["GET", "HEAD"].includes(ctx.method)) {
|
|
187
|
+
return ctx.throw(405);
|
|
188
|
+
}
|
|
189
|
+
ctx.state.legacyFileAccess = true;
|
|
190
|
+
ctx.state.legacyLocalStoragePublicAccess = process.env.LEGACY_LOCAL_STORAGE_PUBLIC_ACCESS === "true";
|
|
191
|
+
if (ctx.state.legacyLocalStoragePublicAccess) {
|
|
192
|
+
ctx.skipAuthCheck = true;
|
|
193
|
+
}
|
|
194
|
+
if (isAuthCheckRequest) {
|
|
195
|
+
return next();
|
|
196
|
+
}
|
|
197
|
+
const originalPath = ctx.path;
|
|
198
|
+
ctx.path = authCheckPath;
|
|
199
|
+
try {
|
|
200
|
+
await next();
|
|
201
|
+
} finally {
|
|
202
|
+
ctx.path = originalPath;
|
|
203
|
+
}
|
|
204
|
+
const relativePath = `uploads/${originalPath.slice(uploadsPrefix.length)}`;
|
|
205
|
+
const headers = (0, import_static_file_security.getStorageUploadSecurityHeaders)(`${originalPath}${ctx.search || ""}`);
|
|
206
|
+
if (!headers["Content-Disposition"]) {
|
|
207
|
+
headers["Content-Disposition"] = "inline";
|
|
208
|
+
}
|
|
209
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
210
|
+
ctx.set(name, value);
|
|
211
|
+
}
|
|
212
|
+
ctx.status = 200;
|
|
213
|
+
await (0, import_koa_send.default)(ctx, relativePath, { root: (0, import_utils.resolveStorageRoot)() });
|
|
214
|
+
}, "legacyFileAccess"),
|
|
215
|
+
{ tag: "legacyFileAccess", before: "dataSource", after: "dataWrapping" }
|
|
216
|
+
);
|
|
162
217
|
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "dataWrapping" });
|
|
163
218
|
app.use((0, import_extract_client_ip.extractClientIp)(), { tag: "extractClientIp", before: "cors" });
|
|
164
219
|
}
|
package/lib/main-data-source.js
CHANGED
|
@@ -116,12 +116,10 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
116
116
|
...filter
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
|
-
const collections = loadedCollections.filter(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
);
|
|
119
|
+
const collections = loadedCollections.filter((collection) => {
|
|
120
|
+
var _a;
|
|
121
|
+
return ((_a = collection.options) == null ? void 0 : _a.from) !== "db2cm";
|
|
122
|
+
});
|
|
125
123
|
const loadedData = {};
|
|
126
124
|
for (const collection of collections) {
|
|
127
125
|
const c = db.getCollection(collection.name);
|
|
@@ -157,7 +155,13 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
157
155
|
} catch (err) {
|
|
158
156
|
ctx.log.error(err);
|
|
159
157
|
}
|
|
160
|
-
const toLoadCollections =
|
|
158
|
+
const toLoadCollections = collections.flatMap((collection) => {
|
|
159
|
+
const loaded = loadedCollections[collection.tableName];
|
|
160
|
+
return this.mergeWithLoadedCollections(
|
|
161
|
+
[collection],
|
|
162
|
+
(loaded == null ? void 0 : loaded.from) === "dbsync" ? { [collection.name]: loaded } : loadedCollections
|
|
163
|
+
);
|
|
164
|
+
});
|
|
161
165
|
const currentSchema = process.env.COLLECTION_MANAGER_SCHEMA || db.options.schema || "public";
|
|
162
166
|
for (const values of toLoadCollections) {
|
|
163
167
|
if (values.schema === currentSchema) {
|
|
@@ -79,7 +79,7 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
79
79
|
var import_utils = require("@nocobase/utils");
|
|
80
80
|
var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
|
|
81
81
|
var import_axios = __toESM(require("axios"));
|
|
82
|
-
var import_decompress = __toESM(require("decompress"));
|
|
82
|
+
var import_decompress = __toESM(require("@xhmikosr/decompress"));
|
|
83
83
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
84
84
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
85
85
|
var import_ini = __toESM(require("ini"));
|
package/lib/plugin.js
CHANGED
|
@@ -214,15 +214,6 @@ const _Plugin = class _Plugin {
|
|
|
214
214
|
log: this.log
|
|
215
215
|
});
|
|
216
216
|
await toolsLoader.load();
|
|
217
|
-
const mcpLoader = new import_ai.MCPLoader(this.ai, {
|
|
218
|
-
pluginName: this.getName(),
|
|
219
|
-
scan: {
|
|
220
|
-
basePath,
|
|
221
|
-
pattern: ["mcp/*.ts", "mcp/*.js", "!mcp/*.d.ts"]
|
|
222
|
-
},
|
|
223
|
-
log: this.log
|
|
224
|
-
});
|
|
225
|
-
await mcpLoader.load();
|
|
226
217
|
const skillsLoader = new import_ai.SkillsLoader(this.ai, {
|
|
227
218
|
pluginName: this.getName(),
|
|
228
219
|
scan: { basePath, pattern: ["**/skills/**/SKILLS.md"] },
|
|
@@ -276,7 +267,7 @@ const _Plugin = class _Plugin {
|
|
|
276
267
|
"fr-FR": "fr/"
|
|
277
268
|
};
|
|
278
269
|
if (packageName.startsWith("@nocobase/plugin-")) {
|
|
279
|
-
packageJson.homepage = `https://docs.nocobase.com/${langMap[locale] || ""}plugins/${packageName}`;
|
|
270
|
+
packageJson.homepage = `https://nocode.docs.nocobase.com/${langMap[locale] || ""}plugins/${packageName}`;
|
|
280
271
|
}
|
|
281
272
|
const results = {
|
|
282
273
|
...this.options,
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "2.4.0-alpha.
|
|
3
|
+
"version": "2.4.0-alpha.20",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,25 +10,25 @@
|
|
|
10
10
|
"@koa/cors": "^5.0.0",
|
|
11
11
|
"@koa/multer": "^3.1.0",
|
|
12
12
|
"@koa/router": "^13.1.0",
|
|
13
|
-
"@nocobase/acl": "2.4.0-alpha.
|
|
14
|
-
"@nocobase/actions": "2.4.0-alpha.
|
|
15
|
-
"@nocobase/ai": "2.4.0-alpha.
|
|
16
|
-
"@nocobase/auth": "2.4.0-alpha.
|
|
17
|
-
"@nocobase/cache": "2.4.0-alpha.
|
|
18
|
-
"@nocobase/data-source-manager": "2.4.0-alpha.
|
|
19
|
-
"@nocobase/database": "2.4.0-alpha.
|
|
20
|
-
"@nocobase/evaluators": "2.4.0-alpha.
|
|
21
|
-
"@nocobase/lock-manager": "2.4.0-alpha.
|
|
22
|
-
"@nocobase/logger": "2.4.0-alpha.
|
|
23
|
-
"@nocobase/resourcer": "2.4.0-alpha.
|
|
24
|
-
"@nocobase/sdk": "2.4.0-alpha.
|
|
25
|
-
"@nocobase/snowflake-id": "2.4.0-alpha.
|
|
26
|
-
"@nocobase/telemetry": "2.4.0-alpha.
|
|
27
|
-
"@nocobase/utils": "2.4.0-alpha.
|
|
28
|
-
"@types/decompress": "4.2.7",
|
|
13
|
+
"@nocobase/acl": "2.4.0-alpha.20",
|
|
14
|
+
"@nocobase/actions": "2.4.0-alpha.20",
|
|
15
|
+
"@nocobase/ai": "2.4.0-alpha.20",
|
|
16
|
+
"@nocobase/auth": "2.4.0-alpha.20",
|
|
17
|
+
"@nocobase/cache": "2.4.0-alpha.20",
|
|
18
|
+
"@nocobase/data-source-manager": "2.4.0-alpha.20",
|
|
19
|
+
"@nocobase/database": "2.4.0-alpha.20",
|
|
20
|
+
"@nocobase/evaluators": "2.4.0-alpha.20",
|
|
21
|
+
"@nocobase/lock-manager": "2.4.0-alpha.20",
|
|
22
|
+
"@nocobase/logger": "2.4.0-alpha.20",
|
|
23
|
+
"@nocobase/resourcer": "2.4.0-alpha.20",
|
|
24
|
+
"@nocobase/sdk": "2.4.0-alpha.20",
|
|
25
|
+
"@nocobase/snowflake-id": "2.4.0-alpha.20",
|
|
26
|
+
"@nocobase/telemetry": "2.4.0-alpha.20",
|
|
27
|
+
"@nocobase/utils": "2.4.0-alpha.20",
|
|
29
28
|
"@types/ini": "^1.3.31",
|
|
30
29
|
"@types/koa-send": "^4.1.3",
|
|
31
30
|
"@types/multer": "^1.4.12",
|
|
31
|
+
"@xhmikosr/decompress": "^11.1.4",
|
|
32
32
|
"async-mutex": "^0.5.0",
|
|
33
33
|
"axios": "^1.7.0",
|
|
34
34
|
"chalk": "^4.1.1",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"cron": "^2.4.4",
|
|
38
38
|
"cronstrue": "^2.11.0",
|
|
39
39
|
"dayjs": "^1.11.8",
|
|
40
|
-
"decompress": "4.2.1",
|
|
41
40
|
"find-package-json": "^1.2.0",
|
|
42
41
|
"fs-extra": "^11.1.1",
|
|
43
42
|
"i18next": "^22.4.9",
|
|
@@ -61,5 +60,5 @@
|
|
|
61
60
|
"@types/serve-handler": "^6.1.1",
|
|
62
61
|
"@types/ws": "^8.5.5"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "29f7108990d7d4a7739bca6eaf674a096bfb7369"
|
|
65
64
|
}
|