@nocobase/server 2.1.0-alpha.4 → 2.1.0-alpha.40

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.
Files changed (61) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/lib/acl/available-action.js +1 -1
  4. package/lib/aes-encryptor.js +3 -2
  5. package/lib/app-supervisor/app-options-factory.d.ts +1 -0
  6. package/lib/app-supervisor/index.js +15 -1
  7. package/lib/app-supervisor/main-only-adapter.d.ts +1 -1
  8. package/lib/app-supervisor/main-only-adapter.js +17 -12
  9. package/lib/application.d.ts +1 -2
  10. package/lib/application.js +3 -24
  11. package/lib/audit-manager/index.d.ts +2 -0
  12. package/lib/audit-manager/index.js +5 -2
  13. package/lib/commands/ai.js +1 -6
  14. package/lib/commands/create-migration.js +1 -1
  15. package/lib/commands/install.js +0 -2
  16. package/lib/commands/pm.js +7 -0
  17. package/lib/commands/start.js +2 -5
  18. package/lib/commands/upgrade.js +0 -2
  19. package/lib/{ai/create-docs-index.d.ts → constants.d.ts} +1 -5
  20. package/lib/constants.js +36 -0
  21. package/lib/event-queue.js +1 -1
  22. package/lib/gateway/index.d.ts +15 -3
  23. package/lib/gateway/index.js +161 -20
  24. package/lib/gateway/static-file-security.d.ts +10 -0
  25. package/lib/gateway/static-file-security.js +69 -0
  26. package/lib/gateway/utils.d.ts +17 -0
  27. package/lib/gateway/utils.js +115 -0
  28. package/lib/helper.js +33 -1
  29. package/lib/index.d.ts +3 -1
  30. package/lib/index.js +5 -4
  31. package/lib/locale/locale.d.ts +24 -0
  32. package/lib/locale/locale.js +29 -5
  33. package/lib/main-data-source.js +12 -5
  34. package/lib/plugin-manager/deps.js +3 -2
  35. package/lib/plugin-manager/findPackageNames.js +4 -2
  36. package/lib/plugin-manager/options/resource.d.ts +12 -1
  37. package/lib/plugin-manager/options/resource.js +212 -53
  38. package/lib/plugin-manager/plugin-manager.d.ts +7 -2
  39. package/lib/plugin-manager/plugin-manager.js +65 -56
  40. package/lib/plugin-manager/utils.d.ts +9 -1
  41. package/lib/plugin-manager/utils.js +68 -10
  42. package/lib/plugin.js +46 -2
  43. package/lib/pub-sub-manager/handler-manager.d.ts +1 -0
  44. package/lib/pub-sub-manager/handler-manager.js +11 -0
  45. package/lib/pub-sub-manager/pub-sub-manager.js +2 -1
  46. package/lib/swagger/app.d.ts +102 -0
  47. package/lib/swagger/app.js +124 -0
  48. package/lib/swagger/base.d.ts +244 -0
  49. package/lib/swagger/base.js +292 -0
  50. package/lib/swagger/collections.d.ts +996 -0
  51. package/lib/swagger/collections.js +1264 -0
  52. package/lib/swagger/index.d.ts +1774 -0
  53. package/lib/swagger/index.js +70 -0
  54. package/lib/swagger/pm.d.ts +462 -0
  55. package/lib/swagger/pm.js +422 -0
  56. package/lib/sync-message-manager.js +8 -1
  57. package/lib/worker-mode.d.ts +19 -0
  58. package/lib/worker-mode.js +67 -0
  59. package/package.json +19 -19
  60. package/lib/ai/create-docs-index.js +0 -892
  61. package/lib/swagger/index.json +0 -1569
@@ -41,8 +41,8 @@ __export(locale_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(locale_exports);
43
43
  var import_utils = require("@nocobase/utils");
44
+ var import_constants = require("../constants");
44
45
  var import_resource = require("./resource");
45
- var import__ = require("..");
46
46
  var import_deepmerge = __toESM(require("deepmerge"));
47
47
  const _Locale = class _Locale {
48
48
  app;
@@ -52,6 +52,7 @@ const _Locale = class _Locale {
52
52
  resourceCached = /* @__PURE__ */ new Map();
53
53
  i18nInstances = /* @__PURE__ */ new Map();
54
54
  resourceStorers = new import_utils.Registry();
55
+ sources = new import_utils.Registry();
55
56
  constructor(app) {
56
57
  this.app = app;
57
58
  this.app.on("afterLoad", async () => {
@@ -92,6 +93,25 @@ const _Locale = class _Locale {
92
93
  registerResourceStorer(name, storer) {
93
94
  this.resourceStorers.register(name, storer);
94
95
  }
96
+ registerSource(name, source) {
97
+ this.sources.register(name, source);
98
+ }
99
+ async syncSources(ctx, types) {
100
+ const resources = { client: {} };
101
+ const sources = Array.from(this.sources.getKeys());
102
+ const syncSources = sources.filter((source) => types.includes(source) && this.sources.get(source).sync);
103
+ const promises = syncSources.map((source) => this.sources.get(source).sync(ctx));
104
+ const results = await Promise.all(promises);
105
+ return results.reduce((result, resource) => {
106
+ Object.entries(resource).forEach(([module2, texts]) => {
107
+ result[module2] = {
108
+ ...result[module2] || {},
109
+ ...texts
110
+ };
111
+ });
112
+ return result;
113
+ }, resources);
114
+ }
95
115
  async get(lang) {
96
116
  const defaults = {
97
117
  resources: await this.getCacheResources(lang)
@@ -124,7 +144,7 @@ const _Locale = class _Locale {
124
144
  }
125
145
  return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang));
126
146
  }
127
- async getResources(lang) {
147
+ async getBuiltInResources(lang) {
128
148
  var _a;
129
149
  const resources = {};
130
150
  const names = this.app.pm.getPlugins().keys();
@@ -141,13 +161,17 @@ const _Locale = class _Locale {
141
161
  const res = await (0, import_resource.getResource)(packageName, lang);
142
162
  if (res) {
143
163
  resources[packageName] = { ...res };
144
- if (packageName.includes(import__.OFFICIAL_PLUGIN_PREFIX)) {
145
- resources[packageName.substring(import__.OFFICIAL_PLUGIN_PREFIX.length)] = { ...res };
164
+ if (packageName.includes(import_constants.OFFICIAL_PLUGIN_PREFIX)) {
165
+ resources[packageName.substring(import_constants.OFFICIAL_PLUGIN_PREFIX.length)] = { ...res };
146
166
  }
147
167
  }
148
168
  } catch (err) {
149
169
  }
150
170
  }
171
+ return resources;
172
+ }
173
+ async getResources(lang) {
174
+ const resources = await this.getBuiltInResources(lang);
151
175
  const storers = this.resourceStorers.getValues();
152
176
  for (const storer of storers) {
153
177
  const custom = await storer.getResources(lang);
@@ -156,7 +180,7 @@ const _Locale = class _Locale {
156
180
  const resource = resources[module2];
157
181
  const customResource = custom[key];
158
182
  resources[module2] = resource ? (0, import_deepmerge.default)(resource, customResource) : customResource;
159
- const pkgName = `${import__.OFFICIAL_PLUGIN_PREFIX}${module2}`;
183
+ const pkgName = `${import_constants.OFFICIAL_PLUGIN_PREFIX}${module2}`;
160
184
  if (resources[pkgName]) {
161
185
  resources[pkgName] = { ...resources[module2] };
162
186
  }
@@ -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((collection) => {
119
- var _a;
120
- return ((_a = collection.options) == null ? void 0 : _a.from) !== "db2cm";
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);
@@ -155,7 +158,11 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
155
158
  ctx.log.error(err);
156
159
  }
157
160
  const toLoadCollections = this.mergeWithLoadedCollections(collections, loadedCollections);
161
+ const currentSchema = process.env.COLLECTION_MANAGER_SCHEMA || db.options.schema || "public";
158
162
  for (const values of toLoadCollections) {
163
+ if (values.schema === currentSchema) {
164
+ delete values.schema;
165
+ }
159
166
  const existsFields = loadedCollections[values.tableName].fields;
160
167
  const deletedFields = existsFields.filter((field) => !values.fields.find((f) => f.name === field.name));
161
168
  await db.sequelize.transaction(async (transaction) => {
@@ -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: "2.x",
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
- "./storage/plugins/*/package.json",
89
- "./storage/plugins/*/*/package.json"
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,16 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ export 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 getAppDevUrl(packageName: string, lane: PluginClientLane): string;
16
+ static hasClientEntry(packageName: string, lane: PluginClientLane): Promise<boolean>;
17
+ static fetch(packageName: string, lane?: PluginClientLane): Promise<string>;
18
+ }
9
19
  declare const _default: {
10
20
  name: string;
11
21
  actions: {
@@ -15,8 +25,9 @@ declare const _default: {
15
25
  enable(ctx: any, next: any): Promise<void>;
16
26
  disable(ctx: any, next: any): Promise<void>;
17
27
  remove(ctx: any, next: any): Promise<void>;
18
- list(ctx: any, next: any): Promise<void>;
28
+ list(ctx: any, next: any): Promise<any>;
19
29
  listEnabled(ctx: any, next: any): Promise<void>;
30
+ listEnabledV2(ctx: any, next: any): Promise<void>;
20
31
  get(ctx: any, next: any): Promise<void>;
21
32
  };
22
33
  };
@@ -39,45 +39,193 @@ 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_plugin_manager = __toESM(require("../plugin-manager"));
52
+ var import_utils2 = require("../utils");
53
+ var import_package = __toESM(require("../../../package.json"));
54
+ const PLUGIN_CLIENT_ENTRY_FILES = {
55
+ client: "dist/client/index.js",
56
+ "client-v2": "dist/client-v2/index.js"
57
+ };
58
+ const PLUGIN_CLIENT_MARKER_FILES = {
59
+ client: "client.js",
60
+ "client-v2": "client-v2.js"
61
+ };
62
+ function getAppDevPluginUrls() {
63
+ if (process.env.NOCOBASE_APP_DEV !== "true" || !process.env.NOCOBASE_APP_DEV_PLUGIN_URLS) {
64
+ return {};
65
+ }
66
+ try {
67
+ return JSON.parse(process.env.NOCOBASE_APP_DEV_PLUGIN_URLS);
68
+ } catch (error) {
69
+ return {};
70
+ }
71
+ }
72
+ __name(getAppDevPluginUrls, "getAppDevPluginUrls");
73
+ function getAppDevPluginDependencies(packageJson2, lane) {
74
+ const appDevPluginUrls = getAppDevPluginUrls();
75
+ const deps = {
76
+ ...packageJson2.dependencies,
77
+ ...packageJson2.peerDependencies,
78
+ ...packageJson2.devDependencies
79
+ };
80
+ return Object.keys(deps).filter(
81
+ (packageName) => {
82
+ var _a;
83
+ return ((_a = appDevPluginUrls[packageName]) == null ? void 0 : _a[lane]) || packageName.startsWith("@nocobase/plugin-") || packageName.startsWith("@nocobase/preset-");
84
+ }
85
+ );
86
+ }
87
+ __name(getAppDevPluginDependencies, "getAppDevPluginDependencies");
49
88
  const _PackageUrls = class _PackageUrls {
50
- static async get(packageName) {
51
- if (!this.items[packageName]) {
52
- this.items[packageName] = await this.fetch(packageName);
89
+ static clear() {
90
+ this.items = {};
91
+ }
92
+ static getCacheKey(packageName, lane) {
93
+ return `${lane}:${packageName}`;
94
+ }
95
+ static async get(packageName, lane = "client") {
96
+ const appDevUrl = this.getAppDevUrl(packageName, lane);
97
+ if (appDevUrl) {
98
+ return appDevUrl;
99
+ }
100
+ const cacheKey = this.getCacheKey(packageName, lane);
101
+ const cached = this.items[cacheKey];
102
+ if (cached) {
103
+ return cached;
104
+ }
105
+ const nextUrl = await this.fetch(packageName, lane);
106
+ if (nextUrl == null ? void 0 : nextUrl.includes("?hash=")) {
107
+ this.items[cacheKey] = nextUrl;
108
+ } else {
109
+ delete this.items[cacheKey];
53
110
  }
54
- return this.items[packageName];
111
+ return nextUrl;
55
112
  }
56
- static async fetch(packageName) {
57
- const PLUGIN_CLIENT_ENTRY_FILE = "dist/client/index.js";
113
+ static getAppDevUrl(packageName, lane) {
114
+ var _a;
115
+ return (_a = getAppDevPluginUrls()[packageName]) == null ? void 0 : _a[lane];
116
+ }
117
+ static async hasClientEntry(packageName, lane) {
118
+ if (this.getAppDevUrl(packageName, lane)) {
119
+ return true;
120
+ }
58
121
  const pkgPath = import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName);
59
- const r = await import_fs_extra.default.exists(pkgPath);
60
- if (r) {
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;
122
+ if (!await import_fs_extra.default.exists(pkgPath)) {
123
+ return false;
71
124
  }
125
+ return await import_fs_extra.default.exists(import_path.default.resolve(pkgPath, PLUGIN_CLIENT_MARKER_FILES[lane]));
126
+ }
127
+ static async fetch(packageName, lane = "client") {
128
+ const pluginClientEntryFile = PLUGIN_CLIENT_ENTRY_FILES[lane];
129
+ const pkgPath = import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName);
130
+ const pkgExists = await import_fs_extra.default.exists(pkgPath);
131
+ if (!pkgExists) {
132
+ return;
133
+ }
134
+ let t = "";
135
+ const dist = import_path.default.resolve(pkgPath, pluginClientEntryFile);
136
+ const distExists = await import_fs_extra.default.exists(dist);
137
+ if (distExists) {
138
+ const fsState = await import_fs_extra.default.stat(dist);
139
+ const appKey = process.env.APP_KEY || "";
140
+ let version = "";
141
+ try {
142
+ const pkgJson = await import_fs_extra.default.readJson(import_path.default.resolve(pkgPath, "package.json"));
143
+ if (pkgJson && typeof pkgJson.version === "string") {
144
+ version = pkgJson.version;
145
+ }
146
+ } catch (error) {
147
+ }
148
+ const appVersion = import_package.default.version;
149
+ const salt = process.env.PLUGIN_URL_HASH_SALT || "";
150
+ const hash = import_crypto.default.createHash("sha256").update(fsState.mtime.getTime() + appKey + version + appVersion + salt).digest("hex").slice(0, 8);
151
+ t = `?hash=${hash}`;
152
+ }
153
+ const cdnBaseUrl = process.env.CDN_BASE_URL.replace(/\/+$/, "");
154
+ const url = `${cdnBaseUrl}${"/static/plugins/"}${packageName}/${pluginClientEntryFile}${t}`;
155
+ return url;
72
156
  }
73
157
  };
74
158
  __name(_PackageUrls, "PackageUrls");
75
159
  __publicField(_PackageUrls, "items", {});
76
160
  let PackageUrls = _PackageUrls;
161
+ async function listEnabledPlugins(ctx, lane = "client") {
162
+ const pm = ctx.db.getRepository("applicationPlugins");
163
+ const items = await pm.find({
164
+ filter: {
165
+ enabled: true
166
+ }
167
+ });
168
+ const arr = [];
169
+ for (const item of items) {
170
+ if (lane === "client-v2" && !await PackageUrls.hasClientEntry(item.packageName, lane)) {
171
+ continue;
172
+ }
173
+ const url = await PackageUrls.get(item.packageName, lane);
174
+ const { name, packageName, options } = item.toJSON();
175
+ if (url) {
176
+ const entry = {
177
+ name,
178
+ packageName,
179
+ options,
180
+ url
181
+ };
182
+ if (PackageUrls.getAppDevUrl(packageName, lane)) {
183
+ const packageJson2 = await import_plugin_manager.default.getPackageJson(packageName);
184
+ entry.devMode = "esm";
185
+ entry.appDevDependencies = getAppDevPluginDependencies(packageJson2, lane);
186
+ }
187
+ if (lane === "client" && await PackageUrls.hasClientEntry(packageName, "client-v2")) {
188
+ const clientV2Url = await PackageUrls.get(packageName, "client-v2");
189
+ if (clientV2Url) {
190
+ entry.clientV2Url = clientV2Url;
191
+ }
192
+ }
193
+ arr.push(entry);
194
+ }
195
+ }
196
+ return arr;
197
+ }
198
+ __name(listEnabledPlugins, "listEnabledPlugins");
199
+ function normalizePmPluginKeys(filterByTk) {
200
+ if (typeof filterByTk === "string") {
201
+ return filterByTk.split(",").map((k) => k.trim()).filter(Boolean);
202
+ }
203
+ if (!Array.isArray(filterByTk) || filterByTk.some((item) => typeof item !== "string")) {
204
+ return [];
205
+ }
206
+ return filterByTk.flatMap(
207
+ (item) => item.split(",").map((k) => k.trim()).filter(Boolean)
208
+ );
209
+ }
210
+ __name(normalizePmPluginKeys, "normalizePmPluginKeys");
211
+ function coerceAwaitResponse(value) {
212
+ if (value === true || value === 1) {
213
+ return true;
214
+ }
215
+ if (typeof value === "string") {
216
+ const v = value.trim().toLowerCase();
217
+ return v === "true" || v === "1" || v === "yes";
218
+ }
219
+ return false;
220
+ }
221
+ __name(coerceAwaitResponse, "coerceAwaitResponse");
77
222
  var resource_default = {
78
223
  name: "pm",
79
224
  actions: {
80
225
  async add(ctx, next) {
226
+ if (process.env.DISABLE_PM_ADD === "true") {
227
+ ctx.throw(403, "The current environment does not allow adding plugins online");
228
+ }
81
229
  const app = ctx.app;
82
230
  const { values = {} } = ctx.action.params;
83
231
  if (values == null ? void 0 : values.packageName) {
@@ -93,12 +241,12 @@ var resource_default = {
93
241
  }
94
242
  app.runAsCLI(["pm", "add", values.packageName, ...args], { from: "user" });
95
243
  } else if (ctx.file) {
96
- const tmpDir = import_path.default.resolve(process.cwd(), "storage", "tmp");
244
+ const tmpDir = (0, import_utils.storagePathJoin)("tmp");
97
245
  try {
98
246
  await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
99
247
  } catch (error) {
100
248
  }
101
- const tempFile = import_path.default.join(process.cwd(), "storage/tmp", (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
249
+ const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
102
250
  await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
103
251
  app.runAsCLI(["pm", "add", tempFile], { from: "user" });
104
252
  } else if (values.compressedFileUrl) {
@@ -108,6 +256,9 @@ var resource_default = {
108
256
  await next();
109
257
  },
110
258
  async update(ctx, next) {
259
+ if (process.env.DISABLE_PM_ADD === "true") {
260
+ ctx.throw(403, "The current environment does not allow adding plugins online");
261
+ }
111
262
  const app = ctx.app;
112
263
  const values = ctx.action.params.values || {};
113
264
  const args = [];
@@ -122,12 +273,12 @@ var resource_default = {
122
273
  }
123
274
  if (ctx.file) {
124
275
  values.packageName = ctx.request.body.packageName;
125
- const tmpDir = import_path.default.resolve(process.cwd(), "storage", "tmp");
276
+ const tmpDir = (0, import_utils.storagePathJoin)("tmp");
126
277
  try {
127
278
  await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
128
279
  } catch (error) {
129
280
  }
130
- const tempFile = import_path.default.join(process.cwd(), "storage/tmp", (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
281
+ const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
131
282
  await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
132
283
  values.compressedFileUrl = tempFile;
133
284
  }
@@ -145,23 +296,40 @@ var resource_default = {
145
296
  await next();
146
297
  },
147
298
  async enable(ctx, next) {
148
- const { filterByTk } = ctx.action.params;
299
+ const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
149
300
  const app = ctx.app;
150
- if (!filterByTk) {
301
+ const keys = normalizePmPluginKeys(filterByTk);
302
+ if (!keys.length) {
151
303
  ctx.throw(400, "plugin name invalid");
152
304
  }
153
- const keys = Array.isArray(filterByTk) ? filterByTk : [filterByTk];
154
- app.runAsCLI(["pm", "enable", ...keys], { from: "user" });
305
+ const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
306
+ const argv = ["pm", "enable", ...keys];
307
+ if (awaitResponse) {
308
+ await app.runAsCLI(argv, { from: "user", throwError: true });
309
+ } else {
310
+ void app.runAsCLI(argv, { from: "user" }).catch((err) => {
311
+ app.log.error(err);
312
+ });
313
+ }
155
314
  ctx.body = filterByTk;
156
315
  await next();
157
316
  },
158
317
  async disable(ctx, next) {
159
- const { filterByTk } = ctx.action.params;
160
- if (!filterByTk) {
318
+ const { filterByTk, awaitResponse: awaitResponseRaw } = ctx.action.params;
319
+ const app = ctx.app;
320
+ const keys = normalizePmPluginKeys(filterByTk);
321
+ if (!keys.length) {
161
322
  ctx.throw(400, "plugin name invalid");
162
323
  }
163
- const app = ctx.app;
164
- app.runAsCLI(["pm", "disable", filterByTk], { from: "user" });
324
+ const awaitResponse = coerceAwaitResponse(awaitResponseRaw);
325
+ const argv = ["pm", "disable", ...keys];
326
+ if (awaitResponse) {
327
+ await app.runAsCLI(argv, { from: "user", throwError: true });
328
+ } else {
329
+ void app.runAsCLI(argv, { from: "user" }).catch((err) => {
330
+ app.log.error(err);
331
+ });
332
+ }
165
333
  ctx.body = filterByTk;
166
334
  await next();
167
335
  },
@@ -176,6 +344,11 @@ var resource_default = {
176
344
  await next();
177
345
  },
178
346
  async list(ctx, next) {
347
+ const { mode } = ctx.action.params;
348
+ if (mode === "summary") {
349
+ ctx.body = await (0, import_utils2.pmListSummary)(ctx.app);
350
+ return next();
351
+ }
179
352
  const locale = ctx.getCurrentLocale();
180
353
  const pm = ctx.app.pm;
181
354
  const plugin = pm.get("nocobase");
@@ -183,29 +356,11 @@ var resource_default = {
183
356
  await next();
184
357
  },
185
358
  async listEnabled(ctx, next) {
186
- const toArr = /* @__PURE__ */ __name(async () => {
187
- const pm = ctx.db.getRepository("applicationPlugins");
188
- const items = await pm.find({
189
- filter: {
190
- enabled: true
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();
359
+ ctx.body = await listEnabledPlugins(ctx, "client");
360
+ await next();
361
+ },
362
+ async listEnabledV2(ctx, next) {
363
+ ctx.body = await listEnabledPlugins(ctx, "client-v2");
209
364
  await next();
210
365
  },
211
366
  async get(ctx, next) {
@@ -221,3 +376,7 @@ var resource_default = {
221
376
  }
222
377
  }
223
378
  };
379
+ // Annotate the CommonJS export names for ESM import in node:
380
+ 0 && (module.exports = {
381
+ PackageUrls
382
+ });
@@ -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 checkAndGetCompatible: typeof checkAndGetCompatible;
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