@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
|
@@ -39,45 +39,143 @@ 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 resource_exports = {};
|
|
41
41
|
__export(resource_exports, {
|
|
42
|
+
PackageUrls: () => PackageUrls,
|
|
42
43
|
default: () => resource_default
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(resource_exports);
|
|
45
46
|
var import_utils = require("@nocobase/utils");
|
|
47
|
+
var import_crypto = __toESM(require("crypto"));
|
|
46
48
|
var import_fs = __toESM(require("fs"));
|
|
47
49
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
48
50
|
var import_path = __toESM(require("path"));
|
|
51
|
+
var import_utils2 = require("../utils");
|
|
52
|
+
var import_package = __toESM(require("../../../package.json"));
|
|
53
|
+
const PLUGIN_CLIENT_ENTRY_FILES = {
|
|
54
|
+
client: "dist/client/index.js",
|
|
55
|
+
"client-v2": "dist/client-v2/index.js"
|
|
56
|
+
};
|
|
57
|
+
const PLUGIN_CLIENT_MARKER_FILES = {
|
|
58
|
+
client: "client.js",
|
|
59
|
+
"client-v2": "client-v2.js"
|
|
60
|
+
};
|
|
49
61
|
const _PackageUrls = class _PackageUrls {
|
|
50
|
-
static
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
static clear() {
|
|
63
|
+
this.items = {};
|
|
64
|
+
}
|
|
65
|
+
static getCacheKey(packageName, lane) {
|
|
66
|
+
return `${lane}:${packageName}`;
|
|
67
|
+
}
|
|
68
|
+
static async get(packageName, lane = "client") {
|
|
69
|
+
const cacheKey = this.getCacheKey(packageName, lane);
|
|
70
|
+
const cached = this.items[cacheKey];
|
|
71
|
+
if (cached) {
|
|
72
|
+
return cached;
|
|
73
|
+
}
|
|
74
|
+
const nextUrl = await this.fetch(packageName, lane);
|
|
75
|
+
if (nextUrl == null ? void 0 : nextUrl.includes("?hash=")) {
|
|
76
|
+
this.items[cacheKey] = nextUrl;
|
|
77
|
+
} else {
|
|
78
|
+
delete this.items[cacheKey];
|
|
53
79
|
}
|
|
54
|
-
return
|
|
80
|
+
return nextUrl;
|
|
55
81
|
}
|
|
56
|
-
static async
|
|
57
|
-
const PLUGIN_CLIENT_ENTRY_FILE = "dist/client/index.js";
|
|
82
|
+
static async hasClientEntry(packageName, lane) {
|
|
58
83
|
const pkgPath = import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
let t = "";
|
|
62
|
-
const dist = import_path.default.resolve(pkgPath, PLUGIN_CLIENT_ENTRY_FILE);
|
|
63
|
-
const distExists = await import_fs_extra.default.exists(dist);
|
|
64
|
-
if (distExists) {
|
|
65
|
-
const fsState = await import_fs_extra.default.stat(distExists ? dist : pkgPath);
|
|
66
|
-
t = `?t=${fsState.mtime.getTime()}`;
|
|
67
|
-
}
|
|
68
|
-
const cdnBaseUrl = process.env.CDN_BASE_URL.replace(/\/+$/, "");
|
|
69
|
-
const url = `${cdnBaseUrl}${"/static/plugins/"}${packageName}/${PLUGIN_CLIENT_ENTRY_FILE}${t}`;
|
|
70
|
-
return url;
|
|
84
|
+
if (!await import_fs_extra.default.exists(pkgPath)) {
|
|
85
|
+
return false;
|
|
71
86
|
}
|
|
87
|
+
return await import_fs_extra.default.exists(import_path.default.resolve(pkgPath, PLUGIN_CLIENT_MARKER_FILES[lane]));
|
|
88
|
+
}
|
|
89
|
+
static async fetch(packageName, lane = "client") {
|
|
90
|
+
const pluginClientEntryFile = PLUGIN_CLIENT_ENTRY_FILES[lane];
|
|
91
|
+
const pkgPath = import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName);
|
|
92
|
+
const pkgExists = await import_fs_extra.default.exists(pkgPath);
|
|
93
|
+
if (!pkgExists) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let t = "";
|
|
97
|
+
const dist = import_path.default.resolve(pkgPath, pluginClientEntryFile);
|
|
98
|
+
const distExists = await import_fs_extra.default.exists(dist);
|
|
99
|
+
if (distExists) {
|
|
100
|
+
const fsState = await import_fs_extra.default.stat(dist);
|
|
101
|
+
const appKey = process.env.APP_KEY || "";
|
|
102
|
+
let version = "";
|
|
103
|
+
try {
|
|
104
|
+
const pkgJson = await import_fs_extra.default.readJson(import_path.default.resolve(pkgPath, "package.json"));
|
|
105
|
+
if (pkgJson && typeof pkgJson.version === "string") {
|
|
106
|
+
version = pkgJson.version;
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
}
|
|
110
|
+
const appVersion = import_package.default.version;
|
|
111
|
+
const salt = process.env.PLUGIN_URL_HASH_SALT || "";
|
|
112
|
+
const hash = import_crypto.default.createHash("sha256").update(fsState.mtime.getTime() + appKey + version + appVersion + salt).digest("hex").slice(0, 8);
|
|
113
|
+
t = `?hash=${hash}`;
|
|
114
|
+
}
|
|
115
|
+
const cdnBaseUrl = process.env.CDN_BASE_URL.replace(/\/+$/, "");
|
|
116
|
+
const url = `${cdnBaseUrl}${"/static/plugins/"}${packageName}/${pluginClientEntryFile}${t}`;
|
|
117
|
+
return url;
|
|
72
118
|
}
|
|
73
119
|
};
|
|
74
120
|
__name(_PackageUrls, "PackageUrls");
|
|
75
121
|
__publicField(_PackageUrls, "items", {});
|
|
76
122
|
let PackageUrls = _PackageUrls;
|
|
123
|
+
async function listEnabledPlugins(ctx, lane = "client") {
|
|
124
|
+
const pm = ctx.db.getRepository("applicationPlugins");
|
|
125
|
+
const items = await pm.find({
|
|
126
|
+
filter: {
|
|
127
|
+
enabled: true
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const arr = [];
|
|
131
|
+
for (const item of items) {
|
|
132
|
+
if (lane === "client-v2" && !await PackageUrls.hasClientEntry(item.packageName, lane)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const url = await PackageUrls.get(item.packageName, lane);
|
|
136
|
+
const { name, packageName, options } = item.toJSON();
|
|
137
|
+
if (url) {
|
|
138
|
+
arr.push({
|
|
139
|
+
name,
|
|
140
|
+
packageName,
|
|
141
|
+
options,
|
|
142
|
+
url
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return arr;
|
|
147
|
+
}
|
|
148
|
+
__name(listEnabledPlugins, "listEnabledPlugins");
|
|
149
|
+
function normalizePmPluginKeys(filterByTk) {
|
|
150
|
+
if (typeof filterByTk === "string") {
|
|
151
|
+
return filterByTk.split(",").map((k) => k.trim()).filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
if (!Array.isArray(filterByTk) || filterByTk.some((item) => typeof item !== "string")) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
return filterByTk.flatMap(
|
|
157
|
+
(item) => item.split(",").map((k) => k.trim()).filter(Boolean)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
__name(normalizePmPluginKeys, "normalizePmPluginKeys");
|
|
161
|
+
function coerceAwaitResponse(value) {
|
|
162
|
+
if (value === true || value === 1) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (typeof value === "string") {
|
|
166
|
+
const v = value.trim().toLowerCase();
|
|
167
|
+
return v === "true" || v === "1" || v === "yes";
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
__name(coerceAwaitResponse, "coerceAwaitResponse");
|
|
77
172
|
var resource_default = {
|
|
78
173
|
name: "pm",
|
|
79
174
|
actions: {
|
|
80
175
|
async add(ctx, next) {
|
|
176
|
+
if (process.env.DISABLE_PM_ADD === "true") {
|
|
177
|
+
ctx.throw(403, "The current environment does not allow adding plugins online");
|
|
178
|
+
}
|
|
81
179
|
const app = ctx.app;
|
|
82
180
|
const { values = {} } = ctx.action.params;
|
|
83
181
|
if (values == null ? void 0 : values.packageName) {
|
|
@@ -93,12 +191,12 @@ var resource_default = {
|
|
|
93
191
|
}
|
|
94
192
|
app.runAsCLI(["pm", "add", values.packageName, ...args], { from: "user" });
|
|
95
193
|
} else if (ctx.file) {
|
|
96
|
-
const tmpDir =
|
|
194
|
+
const tmpDir = (0, import_utils.storagePathJoin)("tmp");
|
|
97
195
|
try {
|
|
98
196
|
await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
|
|
99
197
|
} catch (error) {
|
|
100
198
|
}
|
|
101
|
-
const tempFile = import_path.default.join(
|
|
199
|
+
const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
|
|
102
200
|
await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
|
|
103
201
|
app.runAsCLI(["pm", "add", tempFile], { from: "user" });
|
|
104
202
|
} else if (values.compressedFileUrl) {
|
|
@@ -108,6 +206,9 @@ var resource_default = {
|
|
|
108
206
|
await next();
|
|
109
207
|
},
|
|
110
208
|
async update(ctx, next) {
|
|
209
|
+
if (process.env.DISABLE_PM_ADD === "true") {
|
|
210
|
+
ctx.throw(403, "The current environment does not allow adding plugins online");
|
|
211
|
+
}
|
|
111
212
|
const app = ctx.app;
|
|
112
213
|
const values = ctx.action.params.values || {};
|
|
113
214
|
const args = [];
|
|
@@ -122,12 +223,12 @@ var resource_default = {
|
|
|
122
223
|
}
|
|
123
224
|
if (ctx.file) {
|
|
124
225
|
values.packageName = ctx.request.body.packageName;
|
|
125
|
-
const tmpDir =
|
|
226
|
+
const tmpDir = (0, import_utils.storagePathJoin)("tmp");
|
|
126
227
|
try {
|
|
127
228
|
await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
|
|
128
229
|
} catch (error) {
|
|
129
230
|
}
|
|
130
|
-
const tempFile = import_path.default.join(
|
|
231
|
+
const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
|
|
131
232
|
await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
|
|
132
233
|
values.compressedFileUrl = tempFile;
|
|
133
234
|
}
|
|
@@ -145,23 +246,40 @@ var resource_default = {
|
|
|
145
246
|
await next();
|
|
146
247
|
},
|
|
147
248
|
async enable(ctx, next) {
|
|
148
|
-
const { filterByTk } = ctx.action.params;
|
|
249
|
+
const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
|
|
149
250
|
const app = ctx.app;
|
|
150
|
-
|
|
251
|
+
const keys = normalizePmPluginKeys(filterByTk);
|
|
252
|
+
if (!keys.length) {
|
|
151
253
|
ctx.throw(400, "plugin name invalid");
|
|
152
254
|
}
|
|
153
|
-
const
|
|
154
|
-
|
|
255
|
+
const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
|
|
256
|
+
const argv = ["pm", "enable", ...keys];
|
|
257
|
+
if (awaitResponse) {
|
|
258
|
+
await app.runAsCLI(argv, { from: "user", throwError: true });
|
|
259
|
+
} else {
|
|
260
|
+
void app.runAsCLI(argv, { from: "user" }).catch((err) => {
|
|
261
|
+
app.log.error(err);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
155
264
|
ctx.body = filterByTk;
|
|
156
265
|
await next();
|
|
157
266
|
},
|
|
158
267
|
async disable(ctx, next) {
|
|
159
|
-
const { filterByTk } = ctx.action.params;
|
|
160
|
-
|
|
268
|
+
const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
|
|
269
|
+
const app = ctx.app;
|
|
270
|
+
const keys = normalizePmPluginKeys(filterByTk);
|
|
271
|
+
if (!keys.length) {
|
|
161
272
|
ctx.throw(400, "plugin name invalid");
|
|
162
273
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
274
|
+
const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
|
|
275
|
+
const argv = ["pm", "disable", ...keys];
|
|
276
|
+
if (awaitResponse) {
|
|
277
|
+
await app.runAsCLI(argv, { from: "user", throwError: true });
|
|
278
|
+
} else {
|
|
279
|
+
void app.runAsCLI(argv, { from: "user" }).catch((err) => {
|
|
280
|
+
app.log.error(err);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
165
283
|
ctx.body = filterByTk;
|
|
166
284
|
await next();
|
|
167
285
|
},
|
|
@@ -176,6 +294,11 @@ var resource_default = {
|
|
|
176
294
|
await next();
|
|
177
295
|
},
|
|
178
296
|
async list(ctx, next) {
|
|
297
|
+
const { mode } = ctx.action.params;
|
|
298
|
+
if (mode === "summary") {
|
|
299
|
+
ctx.body = await (0, import_utils2.pmListSummary)(ctx.app);
|
|
300
|
+
return next();
|
|
301
|
+
}
|
|
179
302
|
const locale = ctx.getCurrentLocale();
|
|
180
303
|
const pm = ctx.app.pm;
|
|
181
304
|
const plugin = pm.get("nocobase");
|
|
@@ -183,29 +306,11 @@ var resource_default = {
|
|
|
183
306
|
await next();
|
|
184
307
|
},
|
|
185
308
|
async listEnabled(ctx, next) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
const arr = [];
|
|
194
|
-
for (const item of items) {
|
|
195
|
-
const url = await PackageUrls.get(item.packageName);
|
|
196
|
-
const { name, packageName, options } = item.toJSON();
|
|
197
|
-
if (url) {
|
|
198
|
-
arr.push({
|
|
199
|
-
name,
|
|
200
|
-
packageName,
|
|
201
|
-
options,
|
|
202
|
-
url
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return arr;
|
|
207
|
-
}, "toArr");
|
|
208
|
-
ctx.body = await toArr();
|
|
309
|
+
ctx.body = await listEnabledPlugins(ctx, "client");
|
|
310
|
+
await next();
|
|
311
|
+
},
|
|
312
|
+
async listEnabledV2(ctx, next) {
|
|
313
|
+
ctx.body = await listEnabledPlugins(ctx, "client-v2");
|
|
209
314
|
await next();
|
|
210
315
|
},
|
|
211
316
|
async get(ctx, next) {
|
|
@@ -221,3 +326,7 @@ var resource_default = {
|
|
|
221
326
|
}
|
|
222
327
|
}
|
|
223
328
|
};
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
PackageUrls
|
|
332
|
+
});
|
|
@@ -13,7 +13,6 @@ import Application from '../application';
|
|
|
13
13
|
import { Plugin } from '../plugin';
|
|
14
14
|
import { PluginManagerRepository } from './plugin-manager-repository';
|
|
15
15
|
import { PluginData } from './types';
|
|
16
|
-
import { checkAndGetCompatible } from './utils';
|
|
17
16
|
export declare const sleep: (timeout?: number) => Promise<unknown>;
|
|
18
17
|
export interface PluginManagerOptions {
|
|
19
18
|
app: Application;
|
|
@@ -29,7 +28,12 @@ export declare class AddPresetError extends Error {
|
|
|
29
28
|
}
|
|
30
29
|
export declare class PluginManager {
|
|
31
30
|
options: PluginManagerOptions;
|
|
32
|
-
static
|
|
31
|
+
private static compatibleCache;
|
|
32
|
+
private static compatiblePending;
|
|
33
|
+
static checkAndGetCompatible(packageName: string): Promise<{
|
|
34
|
+
isCompatible: boolean;
|
|
35
|
+
depsCompatible: import("./utils").DepCompatible[];
|
|
36
|
+
}>;
|
|
33
37
|
/**
|
|
34
38
|
* @internal
|
|
35
39
|
*/
|
|
@@ -95,6 +99,7 @@ export declare class PluginManager {
|
|
|
95
99
|
create(pluginName: string, options?: {
|
|
96
100
|
forceRecreate?: boolean;
|
|
97
101
|
}): Promise<void>;
|
|
102
|
+
addOrThrow(plugin?: string | typeof Plugin, options?: any, insert?: boolean, isUpgrade?: boolean): Promise<void>;
|
|
98
103
|
add(plugin?: string | typeof Plugin, options?: any, insert?: boolean, isUpgrade?: boolean): Promise<void>;
|
|
99
104
|
/**
|
|
100
105
|
* @internal
|
|
@@ -58,6 +58,14 @@ var import_collection = __toESM(require("./options/collection"));
|
|
|
58
58
|
var import_resource = __toESM(require("./options/resource"));
|
|
59
59
|
var import_plugin_manager_repository = require("./plugin-manager-repository");
|
|
60
60
|
var import_utils2 = require("./utils");
|
|
61
|
+
const _PluginLoadError = class _PluginLoadError extends Error {
|
|
62
|
+
constructor(pluginName) {
|
|
63
|
+
super(`${pluginName} plugin load error`);
|
|
64
|
+
this.name = "PluginLoadError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__name(_PluginLoadError, "PluginLoadError");
|
|
68
|
+
let PluginLoadError = _PluginLoadError;
|
|
61
69
|
const sleep = /* @__PURE__ */ __name(async (timeout = 0) => {
|
|
62
70
|
return new Promise((resolve2) => {
|
|
63
71
|
setTimeout(resolve2, timeout);
|
|
@@ -82,6 +90,7 @@ const _PluginManager = class _PluginManager {
|
|
|
82
90
|
this._repository.setPluginManager(this);
|
|
83
91
|
this.app.resourcer.define(import_resource.default);
|
|
84
92
|
this.app.acl.allow("pm", "listEnabled", "public");
|
|
93
|
+
this.app.acl.allow("pm", "listEnabledV2", "public");
|
|
85
94
|
this.app.acl.registerSnippet({
|
|
86
95
|
name: "pm",
|
|
87
96
|
actions: ["pm:*"]
|
|
@@ -92,6 +101,23 @@ const _PluginManager = class _PluginManager {
|
|
|
92
101
|
});
|
|
93
102
|
this.app.resourceManager.use(import_middleware.uploadMiddleware, { tag: "upload", after: "acl" });
|
|
94
103
|
}
|
|
104
|
+
static async checkAndGetCompatible(packageName) {
|
|
105
|
+
if (this.compatibleCache.has(packageName)) {
|
|
106
|
+
return this.compatibleCache.get(packageName);
|
|
107
|
+
}
|
|
108
|
+
const pending = this.compatiblePending.get(packageName);
|
|
109
|
+
if (pending) {
|
|
110
|
+
return pending;
|
|
111
|
+
}
|
|
112
|
+
const task = (0, import_utils2.checkAndGetCompatible)(packageName).then((compatible) => {
|
|
113
|
+
this.compatibleCache.set(packageName, compatible);
|
|
114
|
+
return compatible;
|
|
115
|
+
}).finally(() => {
|
|
116
|
+
this.compatiblePending.delete(packageName);
|
|
117
|
+
});
|
|
118
|
+
this.compatiblePending.set(packageName, task);
|
|
119
|
+
return task;
|
|
120
|
+
}
|
|
95
121
|
/**
|
|
96
122
|
* @internal
|
|
97
123
|
*/
|
|
@@ -276,7 +302,7 @@ const _PluginManager = class _PluginManager {
|
|
|
276
302
|
if (options == null ? void 0 : options.forceRecreate) {
|
|
277
303
|
await import_fs_extra.default.rm(pluginDir, { recursive: true, force: true });
|
|
278
304
|
}
|
|
279
|
-
const { PluginGenerator } = require("@nocobase/cli/src/plugin-generator");
|
|
305
|
+
const { PluginGenerator } = require("@nocobase/cli-v1/src/plugin-generator");
|
|
280
306
|
const generator = new PluginGenerator({
|
|
281
307
|
cwd: process.cwd(),
|
|
282
308
|
args: {},
|
|
@@ -297,43 +323,28 @@ const _PluginManager = class _PluginManager {
|
|
|
297
323
|
});
|
|
298
324
|
await (0, import_helper.tsxRerunning)();
|
|
299
325
|
}
|
|
300
|
-
async
|
|
326
|
+
async addOrThrow(plugin, options = {}, insert = false, isUpgrade = false) {
|
|
301
327
|
if (!isUpgrade && this.has(plugin)) {
|
|
302
328
|
const name = typeof plugin === "string" ? plugin : plugin.name;
|
|
303
|
-
|
|
304
|
-
return;
|
|
329
|
+
throw new Error(`plugin [${name}] already added`);
|
|
305
330
|
}
|
|
306
331
|
if (!options.name && typeof plugin === "string") {
|
|
307
332
|
options.name = plugin;
|
|
308
333
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
options["packageName"] = packageName;
|
|
314
|
-
}
|
|
334
|
+
if (typeof plugin === "string" && options.name && !options.packageName) {
|
|
335
|
+
const packageName = await _PluginManager.getPackageName(options.name);
|
|
336
|
+
if (packageName) {
|
|
337
|
+
options["packageName"] = packageName;
|
|
315
338
|
}
|
|
316
|
-
if (options.packageName) {
|
|
317
|
-
const packageJson = await _PluginManager.getPackageJson(options.packageName);
|
|
318
|
-
options["packageJson"] = packageJson;
|
|
319
|
-
options["version"] = packageJson.version;
|
|
320
|
-
}
|
|
321
|
-
} catch (error) {
|
|
322
|
-
this.app.log.error(error);
|
|
323
|
-
console.error(error);
|
|
324
339
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
P = await _PluginManager.resolvePlugin(options.packageName || plugin, isUpgrade, !!options.packageName);
|
|
334
|
-
} catch (error) {
|
|
335
|
-
this.app.log.warn("plugin not found", error);
|
|
336
|
-
return;
|
|
340
|
+
if (options.packageName) {
|
|
341
|
+
const packageJson = await _PluginManager.getPackageJson(options.packageName);
|
|
342
|
+
options["packageJson"] = packageJson;
|
|
343
|
+
options["version"] = packageJson.version;
|
|
344
|
+
}
|
|
345
|
+
const P = await _PluginManager.resolvePlugin(options.packageName || plugin, isUpgrade, !!options.packageName);
|
|
346
|
+
if (!P) {
|
|
347
|
+
throw new Error(`plugin [${(options == null ? void 0 : options.name) || "unknown"}] load error`);
|
|
337
348
|
}
|
|
338
349
|
const instance = new P((0, import_helper.createAppProxy)(this.app), options);
|
|
339
350
|
this.pluginInstances.set(P, instance);
|
|
@@ -344,12 +355,13 @@ const _PluginManager = class _PluginManager {
|
|
|
344
355
|
this.pluginAliases.set(options.packageName, instance);
|
|
345
356
|
}
|
|
346
357
|
await instance.afterAdd();
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
}
|
|
359
|
+
async add(plugin, options = {}, insert = false, isUpgrade = false) {
|
|
360
|
+
try {
|
|
361
|
+
await this.addOrThrow(plugin, options, insert, isUpgrade);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
this.app.log.error(error);
|
|
364
|
+
}
|
|
353
365
|
}
|
|
354
366
|
/**
|
|
355
367
|
* @internal
|
|
@@ -520,13 +532,13 @@ const _PluginManager = class _PluginManager {
|
|
|
520
532
|
added[pluginName] = true;
|
|
521
533
|
continue;
|
|
522
534
|
}
|
|
523
|
-
await this.
|
|
535
|
+
await this.addOrThrow(pluginName);
|
|
524
536
|
}
|
|
525
537
|
for (const name of pluginNames) {
|
|
526
538
|
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
527
539
|
const plugin = this.get(pluginName);
|
|
528
540
|
if (!plugin) {
|
|
529
|
-
throw new
|
|
541
|
+
throw new PluginLoadError(pluginName);
|
|
530
542
|
}
|
|
531
543
|
if (added[pluginName]) {
|
|
532
544
|
continue;
|
|
@@ -549,7 +561,7 @@ const _PluginManager = class _PluginManager {
|
|
|
549
561
|
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
550
562
|
const plugin = this.get(pluginName);
|
|
551
563
|
if (!plugin) {
|
|
552
|
-
throw new
|
|
564
|
+
throw new PluginLoadError(pluginName);
|
|
553
565
|
}
|
|
554
566
|
if (added[pluginName]) {
|
|
555
567
|
continue;
|
|
@@ -574,7 +586,7 @@ const _PluginManager = class _PluginManager {
|
|
|
574
586
|
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
575
587
|
const plugin = this.get(pluginName);
|
|
576
588
|
if (!plugin) {
|
|
577
|
-
throw new
|
|
589
|
+
throw new PluginLoadError(pluginName);
|
|
578
590
|
}
|
|
579
591
|
if (plugin.enabled) {
|
|
580
592
|
continue;
|
|
@@ -647,7 +659,7 @@ const _PluginManager = class _PluginManager {
|
|
|
647
659
|
const { name: pluginName } = await _PluginManager.parseName(name2);
|
|
648
660
|
const plugin = this.get(pluginName);
|
|
649
661
|
if (!plugin) {
|
|
650
|
-
throw new
|
|
662
|
+
throw new PluginLoadError(pluginName);
|
|
651
663
|
}
|
|
652
664
|
if (!plugin.enabled) {
|
|
653
665
|
continue;
|
|
@@ -763,7 +775,7 @@ const _PluginManager = class _PluginManager {
|
|
|
763
775
|
if (process.env.VITEST) {
|
|
764
776
|
return;
|
|
765
777
|
}
|
|
766
|
-
const file = (0,
|
|
778
|
+
const file = (0, import_utils.storagePathJoin)(".upgrading");
|
|
767
779
|
this.app.log.debug("pending upgrade");
|
|
768
780
|
await import_fs_extra.default.writeFile(file, "upgrading");
|
|
769
781
|
}, "writeFile");
|
|
@@ -848,7 +860,7 @@ const _PluginManager = class _PluginManager {
|
|
|
848
860
|
});
|
|
849
861
|
return;
|
|
850
862
|
}
|
|
851
|
-
const file = (0,
|
|
863
|
+
const file = (0, import_utils.storagePathJoin)("app-upgrading");
|
|
852
864
|
await import_fs_extra.default.writeFile(file, "", "utf-8");
|
|
853
865
|
await (0, import_helper.tsxRerunning)();
|
|
854
866
|
await (0, import_execa.default)("yarn", ["nocobase", "pm2-restart"], {
|
|
@@ -1113,7 +1125,8 @@ const _PluginManager = class _PluginManager {
|
|
|
1113
1125
|
}
|
|
1114
1126
|
};
|
|
1115
1127
|
__name(_PluginManager, "PluginManager");
|
|
1116
|
-
__publicField(_PluginManager, "
|
|
1128
|
+
__publicField(_PluginManager, "compatibleCache", /* @__PURE__ */ new Map());
|
|
1129
|
+
__publicField(_PluginManager, "compatiblePending", /* @__PURE__ */ new Map());
|
|
1117
1130
|
__publicField(_PluginManager, "parsedNames", {});
|
|
1118
1131
|
let PluginManager = _PluginManager;
|
|
1119
1132
|
var plugin_manager_default = PluginManager;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { AxiosRequestConfig } from 'axios';
|
|
10
10
|
import { PluginManagerRepository } from './plugin-manager-repository';
|
|
11
11
|
import { PluginData } from './types';
|
|
12
|
+
import Application from '../application';
|
|
12
13
|
/**
|
|
13
14
|
* get temp dir
|
|
14
15
|
*
|
|
@@ -16,7 +17,8 @@ import { PluginData } from './types';
|
|
|
16
17
|
* getTempDir() => '/tmp/nocobase'
|
|
17
18
|
*/
|
|
18
19
|
export declare function getTempDir(): Promise<string>;
|
|
19
|
-
export declare function
|
|
20
|
+
export declare function assertSafePluginPackageName(packageName: string): void;
|
|
21
|
+
export declare function resolveSafeChildPath(baseDir: string, child: string): string;
|
|
20
22
|
export declare function getLocalPluginPackagesPathArr(): string[];
|
|
21
23
|
export declare function getStoragePluginDir(packageName: string): string;
|
|
22
24
|
export declare function getLocalPluginDir(packageDirBasename: string): string;
|
|
@@ -112,4 +114,10 @@ export declare function checkAndGetCompatible(packageName: string): Promise<{
|
|
|
112
114
|
depsCompatible: DepCompatible[];
|
|
113
115
|
}>;
|
|
114
116
|
export declare function getPluginBasePath(packageName: string): Promise<string>;
|
|
117
|
+
export declare function pmListSummary(app: Application): Promise<{
|
|
118
|
+
displayName: any;
|
|
119
|
+
packageName: any;
|
|
120
|
+
enabled: boolean;
|
|
121
|
+
description: any;
|
|
122
|
+
}[]>;
|
|
115
123
|
export {};
|