@nocobase/server 2.1.0-beta.8 → 2.2.0-alpha.1

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 (64) hide show
  1. package/lib/acl/available-action.js +1 -1
  2. package/lib/aes-encryptor.js +3 -2
  3. package/lib/app-supervisor/app-options-factory.d.ts +1 -0
  4. package/lib/app-supervisor/index.d.ts +13 -5
  5. package/lib/app-supervisor/index.js +48 -13
  6. package/lib/app-supervisor/main-only-adapter.d.ts +3 -0
  7. package/lib/app-supervisor/main-only-adapter.js +7 -0
  8. package/lib/app-supervisor/types.d.ts +18 -3
  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 -4
  16. package/lib/commands/pm.js +7 -0
  17. package/lib/commands/start.js +2 -5
  18. package/lib/commands/upgrade.js +0 -4
  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 +180 -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 +19 -0
  27. package/lib/gateway/utils.js +128 -0
  28. package/lib/helpers/application-version.js +1 -0
  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/constants.js +1 -1
  35. package/lib/plugin-manager/deps.js +3 -2
  36. package/lib/plugin-manager/findPackageNames.d.ts +5 -5
  37. package/lib/plugin-manager/findPackageNames.js +35 -58
  38. package/lib/plugin-manager/options/collection.js +1 -0
  39. package/lib/plugin-manager/options/resource.d.ts +12 -1
  40. package/lib/plugin-manager/options/resource.js +210 -65
  41. package/lib/plugin-manager/plugin-manager.d.ts +7 -2
  42. package/lib/plugin-manager/plugin-manager.js +59 -81
  43. package/lib/plugin-manager/utils.d.ts +9 -1
  44. package/lib/plugin-manager/utils.js +67 -9
  45. package/lib/plugin.js +33 -2
  46. package/lib/pub-sub-manager/handler-manager.d.ts +1 -0
  47. package/lib/pub-sub-manager/handler-manager.js +11 -0
  48. package/lib/pub-sub-manager/pub-sub-manager.js +2 -1
  49. package/lib/swagger/app.d.ts +102 -0
  50. package/lib/swagger/app.js +124 -0
  51. package/lib/swagger/base.d.ts +244 -0
  52. package/lib/swagger/base.js +292 -0
  53. package/lib/swagger/collections.d.ts +996 -0
  54. package/lib/swagger/collections.js +1264 -0
  55. package/lib/swagger/index.d.ts +1774 -0
  56. package/lib/swagger/index.js +70 -0
  57. package/lib/swagger/pm.d.ts +462 -0
  58. package/lib/swagger/pm.js +422 -0
  59. package/lib/sync-message-manager.js +8 -1
  60. package/lib/worker-mode.d.ts +19 -0
  61. package/lib/worker-mode.js +67 -0
  62. package/package.json +18 -18
  63. package/lib/ai/create-docs-index.js +0 -892
  64. 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) => {
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(constants_exports);
38
38
  const APP_NAME = "nocobase";
39
39
  const DEFAULT_PLUGIN_STORAGE_PATH = "storage/plugins";
40
40
  const DEFAULT_PLUGIN_PATH = "packages/plugins/";
41
- const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
41
+ const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-").split(",");
42
42
  const requireRegex = /require\s*\(['"`](.*?)['"`]\)/g;
43
43
  const importRegex = /^import(?:['"\s]*([\w*${}\s,]+)from\s*)?['"\s]['"\s](.*[@\w_-]+)['"\s].*/gm;
44
44
  const EXTERNAL = [
@@ -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;
@@ -6,11 +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
- declare function trim(packageNames: string[]): Promise<any[]>;
10
- export declare function findPackageNames(): Promise<any[]>;
11
- export declare function findBuiltInPlugins(): Promise<any[]>;
12
- export declare function findLocalPlugins(): Promise<any[]>;
13
- export declare function findAllPlugins(): Promise<any[]>;
9
+ declare function trim(packageNames: string[]): Promise<string[]>;
10
+ export declare function findPackageNames(): Promise<string[]>;
11
+ export declare function findBuiltInPlugins(): Promise<string[]>;
12
+ export declare function findLocalPlugins(): Promise<string[]>;
13
+ export declare function findAllPlugins(): Promise<string[]>;
14
14
  export declare const packageNameTrim: typeof trim;
15
15
  export declare function appendToBuiltInPlugins(nameOrPkg: string): Promise<void>;
16
16
  export {};
@@ -45,24 +45,17 @@ __export(findPackageNames_exports, {
45
45
  packageNameTrim: () => packageNameTrim
46
46
  });
47
47
  module.exports = __toCommonJS(findPackageNames_exports);
48
- var import_fast_glob = __toESM(require("fast-glob"));
49
- var import_fs_extra = __toESM(require("fs-extra"));
48
+ var import_plugin_package = require("../../../utils/plugin-package");
50
49
  var import_lodash = __toESM(require("lodash"));
51
- var import_path = __toESM(require("path"));
52
- var import__ = require("./");
53
- function splitNames(name) {
54
- return (name || "").split(",").filter(Boolean);
55
- }
56
- __name(splitNames, "splitNames");
57
50
  async function trim(packageNames) {
58
51
  const nameOrPkgs = import_lodash.default.uniq(packageNames).filter(Boolean);
59
52
  const names = [];
60
53
  for (const nameOrPkg of nameOrPkgs) {
61
- const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
62
- try {
63
- await import__.PluginManager.getPackageJson(packageName);
54
+ const { name, packageName } = await (0, import_plugin_package.parsePluginName)(nameOrPkg, {
55
+ nodeModulesPath: process.env.NODE_MODULES_PATH
56
+ });
57
+ if (await (0, import_plugin_package.resolvePluginPackagePath)(packageName)) {
64
58
  names.push(name);
65
- } catch (error) {
66
59
  }
67
60
  }
68
61
  return names;
@@ -81,75 +74,57 @@ const excludes = [
81
74
  "@nocobase/plugin-workflow-test"
82
75
  ];
83
76
  async function findPackageNames() {
84
- const patterns = [
85
- "./packages/plugins/*/package.json",
86
- "./packages/plugins/*/*/package.json",
87
- "./packages/pro-plugins/*/*/package.json",
88
- "./storage/plugins/*/package.json",
89
- "./storage/plugins/*/*/package.json"
90
- ];
91
77
  try {
92
- const packageJsonPaths = await (0, import_fast_glob.default)(patterns, {
93
- cwd: process.cwd(),
94
- absolute: true,
95
- ignore: ["**/external-db-data-source/**"]
78
+ const packages = await (0, import_plugin_package.discoverPluginPackages)({
79
+ nodeModulesPath: process.env.NODE_MODULES_PATH
96
80
  });
97
- const packageNames = await Promise.all(
98
- packageJsonPaths.map(async (packageJsonPath) => {
99
- const packageJson = await import_fs_extra.default.readJson(packageJsonPath);
100
- return packageJson.name;
101
- })
102
- );
103
- const nocobasePlugins = await findNocobasePlugins();
104
- const { APPEND_PRESET_BUILT_IN_PLUGINS = "", APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
105
- return trim(
106
- packageNames.filter((pkg) => pkg && !excludes.includes(pkg)).concat(nocobasePlugins).concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS))
107
- );
81
+ return trim(packages.filter((pkg) => !excludes.includes(pkg.packageName)).map((pkg) => pkg.packageName));
108
82
  } catch (error) {
109
83
  return [];
110
84
  }
111
85
  }
112
86
  __name(findPackageNames, "findPackageNames");
113
87
  async function getPackageJson() {
114
- const packageJson = await import_fs_extra.default.readJson(
115
- import_path.default.resolve(process.env.NODE_MODULES_PATH, "@nocobase/preset-nocobase/package.json")
116
- );
88
+ const packageJson = await (0, import_plugin_package.getPresetNocoBasePackageJson)({
89
+ nodeModulesPath: process.env.NODE_MODULES_PATH
90
+ });
91
+ if (!packageJson) {
92
+ throw new Error("Cannot find @nocobase/preset-nocobase package.json");
93
+ }
117
94
  return packageJson;
118
95
  }
119
96
  __name(getPackageJson, "getPackageJson");
120
- async function findNocobasePlugins() {
121
- try {
122
- const packageJson = await getPackageJson();
123
- const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith("@nocobase/plugin-"));
124
- return trim(pluginNames.filter((pkg) => pkg && !excludes.includes(pkg)));
125
- } catch (error) {
126
- return [];
127
- }
128
- }
129
- __name(findNocobasePlugins, "findNocobasePlugins");
130
97
  async function findBuiltInPlugins() {
131
98
  const { APPEND_PRESET_BUILT_IN_PLUGINS = "" } = process.env;
132
99
  try {
133
100
  const packageJson = await getPackageJson();
134
- return trim(packageJson.builtIn.concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)));
101
+ return trim((packageJson.builtIn || []).concat((0, import_plugin_package.splitPluginNames)(APPEND_PRESET_BUILT_IN_PLUGINS)));
135
102
  } catch (error) {
136
103
  return [];
137
104
  }
138
105
  }
139
106
  __name(findBuiltInPlugins, "findBuiltInPlugins");
140
107
  async function findLocalPlugins() {
141
- const { APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
142
- const plugins1 = await findNocobasePlugins();
143
- const plugins2 = await findPackageNames();
144
- const builtInPlugins = await findBuiltInPlugins();
145
108
  const packageJson = await getPackageJson();
146
- const items = await trim(
109
+ const packages = await (0, import_plugin_package.discoverPluginPackages)({
110
+ nodeModulesPath: process.env.NODE_MODULES_PATH
111
+ });
112
+ const builtInPackageNames = await Promise.all(
113
+ (packageJson.builtIn || []).concat((0, import_plugin_package.splitPluginNames)(process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "")).map(
114
+ async (nameOrPkg) => (await (0, import_plugin_package.parsePluginName)(nameOrPkg, { nodeModulesPath: process.env.NODE_MODULES_PATH })).packageName
115
+ )
116
+ );
117
+ const deprecatedPackageNames = await Promise.all(
118
+ (packageJson.deprecated || []).map(
119
+ async (nameOrPkg) => (await (0, import_plugin_package.parsePluginName)(nameOrPkg, { nodeModulesPath: process.env.NODE_MODULES_PATH })).packageName
120
+ )
121
+ );
122
+ return trim(
147
123
  import_lodash.default.difference(
148
- plugins1.concat(plugins2).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS)),
149
- builtInPlugins.concat(await trim(packageJson.deprecated))
124
+ packages.filter((pkg) => !excludes.includes(pkg.packageName)).map((pkg) => pkg.packageName),
125
+ import_lodash.default.uniq(builtInPackageNames.concat(deprecatedPackageNames))
150
126
  )
151
127
  );
152
- return items;
153
128
  }
154
129
  __name(findLocalPlugins, "findLocalPlugins");
155
130
  async function findAllPlugins() {
@@ -161,8 +136,10 @@ __name(findAllPlugins, "findAllPlugins");
161
136
  const packageNameTrim = trim;
162
137
  async function appendToBuiltInPlugins(nameOrPkg) {
163
138
  const APPEND_PRESET_BUILT_IN_PLUGINS = process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "";
164
- const keys = APPEND_PRESET_BUILT_IN_PLUGINS.split(",");
165
- const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
139
+ const keys = (0, import_plugin_package.splitPluginNames)(APPEND_PRESET_BUILT_IN_PLUGINS);
140
+ const { name, packageName } = await (0, import_plugin_package.parsePluginName)(nameOrPkg, {
141
+ nodeModulesPath: process.env.NODE_MODULES_PATH
142
+ });
166
143
  if (keys.includes(packageName)) {
167
144
  return;
168
145
  }
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(collection_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var collection_default = (0, import_database.defineCollection)({
34
34
  name: "applicationPlugins",
35
+ dataCategory: "system",
35
36
  dumpRules: "required",
36
37
  migrationRules: ["overwrite", "schema-only"],
37
38
  repository: "PluginManagerRepository",
@@ -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
  };