@nocobase/server 2.1.0-alpha.17 → 2.1.0-alpha.19

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.
@@ -44,6 +44,7 @@ module.exports = __toCommonJS(aes_encryptor_exports);
44
44
  var import_crypto = __toESM(require("crypto"));
45
45
  var import_fs_extra = __toESM(require("fs-extra"));
46
46
  var import_path = __toESM(require("path"));
47
+ var import_utils = require("@nocobase/utils");
47
48
  const _AesEncryptor = class _AesEncryptor {
48
49
  key;
49
50
  constructor(key) {
@@ -99,12 +100,12 @@ const _AesEncryptor = class _AesEncryptor {
99
100
  }
100
101
  }
101
102
  static async getKeyPath(appName) {
102
- const appKeyPath = import_path.default.resolve(process.cwd(), "storage", "apps", appName, "aes_key.dat");
103
+ const appKeyPath = (0, import_utils.storagePathJoin)("apps", appName, "aes_key.dat");
103
104
  const appKeyExists = await import_fs_extra.default.exists(appKeyPath);
104
105
  if (appKeyExists) {
105
106
  return appKeyPath;
106
107
  }
107
- const envKeyPath = import_path.default.resolve(process.cwd(), "storage", "environment-variables", appName, "aes_key.dat");
108
+ const envKeyPath = (0, import_utils.storagePathJoin)("environment-variables", appName, "aes_key.dat");
108
109
  const envKeyExists = await import_fs_extra.default.exists(envKeyPath);
109
110
  if (envKeyExists) {
110
111
  return envKeyPath;
@@ -43,10 +43,11 @@ module.exports = __toCommonJS(create_docs_index_exports);
43
43
  var import_fast_glob = __toESM(require("fast-glob"));
44
44
  var import_fs_extra = __toESM(require("fs-extra"));
45
45
  var import_path = __toESM(require("path"));
46
+ var import_utils = require("@nocobase/utils");
46
47
  var import_ai = require("@nocobase/ai");
47
48
  var import_findPackageNames = require("../plugin-manager/findPackageNames");
48
49
  var import_plugin_manager = require("../plugin-manager");
49
- const DOCS_STORAGE_DIR = import_path.default.resolve(process.cwd(), "storage/ai/docs");
50
+ const DOCS_STORAGE_DIR = (0, import_utils.storagePathJoin)("ai", "docs");
50
51
  const REFERENCE_START = "<!-- docs:references:start -->";
51
52
  const REFERENCE_END = "<!-- docs:references:end -->";
52
53
  const SPLIT_REFERENCE_START = "<!-- docs:splits:start -->";
@@ -76,6 +76,6 @@ export default class extends Migration {
76
76
  `;
77
77
  await import_fs.default.promises.mkdir((0, import_path.dirname)(filename), { recursive: true });
78
78
  await import_fs.default.promises.writeFile(filename, data, "utf8");
79
- app.log.info(`migration file in ${filename}`);
79
+ console.log(`migration file in ${filename}`);
80
80
  });
81
81
  }, "default");
@@ -41,14 +41,14 @@ __export(start_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(start_exports);
43
43
  var import_fs_extra = __toESM(require("fs-extra"));
44
- var import_path = require("path");
44
+ var import_utils = require("@nocobase/utils");
45
45
  var import_create_docs_index = require("../ai/create-docs-index");
46
46
  var import_application_not_install = require("../errors/application-not-install");
47
47
  /* istanbul ignore file -- @preserve */
48
48
  var start_default = /* @__PURE__ */ __name((app) => {
49
49
  app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
50
50
  const [options] = cliArgs;
51
- const file = (0, import_path.resolve)(process.cwd(), "storage/.upgrading");
51
+ const file = (0, import_utils.storagePathJoin)(".upgrading");
52
52
  const upgrading = await import_fs_extra.default.exists(file);
53
53
  if (upgrading) {
54
54
  if (!process.env.VITEST) {
@@ -71,7 +71,7 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
71
71
  return null;
72
72
  }
73
73
  get storagePath() {
74
- return import_path.default.resolve(process.cwd(), "storage", "apps", this.options.appName, "event-queue.json");
74
+ return (0, import_utils.storagePathJoin)("apps", this.options.appName, "event-queue.json");
75
75
  }
76
76
  listen = /* @__PURE__ */ __name((channel) => {
77
77
  if (!this.connected) {
@@ -56,6 +56,7 @@ var import_fs = __toESM(require("fs"));
56
56
  var import_http = __toESM(require("http"));
57
57
  var import_koa_compose = __toESM(require("koa-compose"));
58
58
  var import_node_util = require("node:util");
59
+ var import_node_os = require("node:os");
59
60
  var import_path = require("path");
60
61
  var import_qs = __toESM(require("qs"));
61
62
  var import_serve_handler = __toESM(require("serve-handler"));
@@ -77,11 +78,14 @@ function normalizeBasePath(path = "") {
77
78
  }
78
79
  __name(normalizeBasePath, "normalizeBasePath");
79
80
  function getSocketPath() {
80
- const { SOCKET_PATH } = import_node_process.default.env;
81
- if ((0, import_path.isAbsolute)(SOCKET_PATH)) {
82
- return SOCKET_PATH;
81
+ const socketPath = import_node_process.default.env.SOCKET_PATH;
82
+ if (socketPath) {
83
+ return (0, import_path.isAbsolute)(socketPath) ? socketPath : (0, import_path.resolve)(import_node_process.default.cwd(), socketPath);
83
84
  }
84
- return (0, import_path.resolve)(import_node_process.default.cwd(), SOCKET_PATH);
85
+ if (import_node_process.default.env.NOCOBASE_RUNNING_IN_DOCKER === "true") {
86
+ return (0, import_path.resolve)((0, import_node_os.homedir)(), ".nocobase", "gateway.sock");
87
+ }
88
+ return (0, import_utils.storagePathJoin)("gateway.sock");
85
89
  }
86
90
  __name(getSocketPath, "getSocketPath");
87
91
  const _Gateway = class _Gateway extends import_events.EventEmitter {
@@ -96,7 +100,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
96
100
  loggers = new import_utils.Registry();
97
101
  port = import_node_process.default.env.APP_PORT ? parseInt(import_node_process.default.env.APP_PORT) : null;
98
102
  host = "0.0.0.0";
99
- socketPath = (0, import_path.resolve)(import_node_process.default.cwd(), "storage", "gateway.sock");
103
+ socketPath = getSocketPath();
100
104
  v2IndexTemplateCache = null;
101
105
  terminating = false;
102
106
  onTerminate = /* @__PURE__ */ __name(async (signal) => {
@@ -129,7 +133,6 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
129
133
  constructor() {
130
134
  super();
131
135
  this.reset();
132
- this.socketPath = getSocketPath();
133
136
  import_node_process.default.once("SIGTERM", this.onTerminate);
134
137
  import_node_process.default.once("SIGINT", this.onTerminate);
135
138
  }
@@ -143,6 +143,9 @@ var resource_default = {
143
143
  name: "pm",
144
144
  actions: {
145
145
  async add(ctx, next) {
146
+ if (process.env.DISABLE_PM_ADD === "true") {
147
+ ctx.throw(403, "The current environment does not allow adding plugins online");
148
+ }
146
149
  const app = ctx.app;
147
150
  const { values = {} } = ctx.action.params;
148
151
  if (values == null ? void 0 : values.packageName) {
@@ -158,12 +161,12 @@ var resource_default = {
158
161
  }
159
162
  app.runAsCLI(["pm", "add", values.packageName, ...args], { from: "user" });
160
163
  } else if (ctx.file) {
161
- const tmpDir = import_path.default.resolve(process.cwd(), "storage", "tmp");
164
+ const tmpDir = (0, import_utils.storagePathJoin)("tmp");
162
165
  try {
163
166
  await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
164
167
  } catch (error) {
165
168
  }
166
- const tempFile = import_path.default.join(process.cwd(), "storage/tmp", (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
169
+ const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
167
170
  await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
168
171
  app.runAsCLI(["pm", "add", tempFile], { from: "user" });
169
172
  } else if (values.compressedFileUrl) {
@@ -173,6 +176,9 @@ var resource_default = {
173
176
  await next();
174
177
  },
175
178
  async update(ctx, next) {
179
+ if (process.env.DISABLE_PM_ADD === "true") {
180
+ ctx.throw(403, "The current environment does not allow adding plugins online");
181
+ }
176
182
  const app = ctx.app;
177
183
  const values = ctx.action.params.values || {};
178
184
  const args = [];
@@ -187,12 +193,12 @@ var resource_default = {
187
193
  }
188
194
  if (ctx.file) {
189
195
  values.packageName = ctx.request.body.packageName;
190
- const tmpDir = import_path.default.resolve(process.cwd(), "storage", "tmp");
196
+ const tmpDir = (0, import_utils.storagePathJoin)("tmp");
191
197
  try {
192
198
  await import_fs.default.promises.mkdir(tmpDir, { recursive: true });
193
199
  } catch (error) {
194
200
  }
195
- const tempFile = import_path.default.join(process.cwd(), "storage/tmp", (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
201
+ const tempFile = import_path.default.join(tmpDir, (0, import_utils.uid)() + import_path.default.extname(ctx.file.originalname));
196
202
  await import_fs.default.promises.writeFile(tempFile, ctx.file.buffer, "binary");
197
203
  values.compressedFileUrl = tempFile;
198
204
  }
@@ -775,7 +775,7 @@ const _PluginManager = class _PluginManager {
775
775
  if (process.env.VITEST) {
776
776
  return;
777
777
  }
778
- const file = (0, import_path.resolve)(process.cwd(), "storage/.upgrading");
778
+ const file = (0, import_utils.storagePathJoin)(".upgrading");
779
779
  this.app.log.debug("pending upgrade");
780
780
  await import_fs_extra.default.writeFile(file, "upgrading");
781
781
  }, "writeFile");
@@ -860,7 +860,7 @@ const _PluginManager = class _PluginManager {
860
860
  });
861
861
  return;
862
862
  }
863
- const file = (0, import_path.resolve)(process.cwd(), "storage/app-upgrading");
863
+ const file = (0, import_utils.storagePathJoin)("app-upgrading");
864
864
  await import_fs_extra.default.writeFile(file, "", "utf-8");
865
865
  await (0, import_helper.tsxRerunning)();
866
866
  await (0, import_execa.default)("yarn", ["nocobase", "pm2-restart"], {
@@ -17,7 +17,6 @@ import Application from '../application';
17
17
  * getTempDir() => '/tmp/nocobase'
18
18
  */
19
19
  export declare function getTempDir(): Promise<string>;
20
- export declare function getPluginStoragePath(): string;
21
20
  export declare function getLocalPluginPackagesPathArr(): string[];
22
21
  export declare function getStoragePluginDir(packageName: string): string;
23
22
  export declare function getLocalPluginDir(packageDirBasename: string): string;
@@ -59,7 +59,6 @@ __export(utils_exports, {
59
59
  getPackagesFromFiles: () => getPackagesFromFiles,
60
60
  getPluginBasePath: () => getPluginBasePath,
61
61
  getPluginInfoByNpm: () => getPluginInfoByNpm,
62
- getPluginStoragePath: () => getPluginStoragePath,
63
62
  getServerPackages: () => getServerPackages,
64
63
  getStoragePluginDir: () => getStoragePluginDir,
65
64
  getTempDir: () => getTempDir,
@@ -97,11 +96,6 @@ async function getTempDir() {
97
96
  return import_path.default.join(temporaryDirectory, import_constants.APP_NAME);
98
97
  }
99
98
  __name(getTempDir, "getTempDir");
100
- function getPluginStoragePath() {
101
- const pluginStoragePath = process.env.PLUGIN_STORAGE_PATH || import_constants.DEFAULT_PLUGIN_STORAGE_PATH;
102
- return import_path.default.isAbsolute(pluginStoragePath) ? pluginStoragePath : import_path.default.join(process.cwd(), pluginStoragePath);
103
- }
104
- __name(getPluginStoragePath, "getPluginStoragePath");
105
99
  function getLocalPluginPackagesPathArr() {
106
100
  const pluginPackagesPathArr = process.env.PLUGIN_PATH || import_constants.DEFAULT_PLUGIN_PATH;
107
101
  return pluginPackagesPathArr.split(",").map((pluginPackagesPath) => {
@@ -111,7 +105,7 @@ function getLocalPluginPackagesPathArr() {
111
105
  }
112
106
  __name(getLocalPluginPackagesPathArr, "getLocalPluginPackagesPathArr");
113
107
  function getStoragePluginDir(packageName) {
114
- const pluginStoragePath = getPluginStoragePath();
108
+ const pluginStoragePath = (0, import_utils.resolvePluginStoragePath)();
115
109
  return import_path.default.join(pluginStoragePath, packageName);
116
110
  }
117
111
  __name(getStoragePluginDir, "getStoragePluginDir");
@@ -579,7 +573,6 @@ __name(pmListSummary, "pmListSummary");
579
573
  getPackagesFromFiles,
580
574
  getPluginBasePath,
581
575
  getPluginInfoByNpm,
582
- getPluginStoragePath,
583
576
  getServerPackages,
584
577
  getStoragePluginDir,
585
578
  getTempDir,
package/lib/plugin.js CHANGED
@@ -293,7 +293,7 @@ const _Plugin = class _Plugin {
293
293
  ...await (0, import_utils2.checkAndGetCompatible)(packageName),
294
294
  lastUpdated: (await import_fs.default.promises.stat(file)).ctime,
295
295
  file,
296
- updatable: file.startsWith(process.env.PLUGIN_STORAGE_PATH)
296
+ updatable: file.startsWith((0, import_utils.resolvePluginStoragePath)())
297
297
  };
298
298
  }
299
299
  return results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.1.0-alpha.17",
3
+ "version": "2.1.0-alpha.19",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
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.1.0-alpha.17",
14
- "@nocobase/actions": "2.1.0-alpha.17",
15
- "@nocobase/ai": "2.1.0-alpha.17",
16
- "@nocobase/auth": "2.1.0-alpha.17",
17
- "@nocobase/cache": "2.1.0-alpha.17",
18
- "@nocobase/data-source-manager": "2.1.0-alpha.17",
19
- "@nocobase/database": "2.1.0-alpha.17",
20
- "@nocobase/evaluators": "2.1.0-alpha.17",
21
- "@nocobase/lock-manager": "2.1.0-alpha.17",
22
- "@nocobase/logger": "2.1.0-alpha.17",
23
- "@nocobase/resourcer": "2.1.0-alpha.17",
24
- "@nocobase/sdk": "2.1.0-alpha.17",
25
- "@nocobase/snowflake-id": "2.1.0-alpha.17",
26
- "@nocobase/telemetry": "2.1.0-alpha.17",
27
- "@nocobase/utils": "2.1.0-alpha.17",
13
+ "@nocobase/acl": "2.1.0-alpha.19",
14
+ "@nocobase/actions": "2.1.0-alpha.19",
15
+ "@nocobase/ai": "2.1.0-alpha.19",
16
+ "@nocobase/auth": "2.1.0-alpha.19",
17
+ "@nocobase/cache": "2.1.0-alpha.19",
18
+ "@nocobase/data-source-manager": "2.1.0-alpha.19",
19
+ "@nocobase/database": "2.1.0-alpha.19",
20
+ "@nocobase/evaluators": "2.1.0-alpha.19",
21
+ "@nocobase/lock-manager": "2.1.0-alpha.19",
22
+ "@nocobase/logger": "2.1.0-alpha.19",
23
+ "@nocobase/resourcer": "2.1.0-alpha.19",
24
+ "@nocobase/sdk": "2.1.0-alpha.19",
25
+ "@nocobase/snowflake-id": "2.1.0-alpha.19",
26
+ "@nocobase/telemetry": "2.1.0-alpha.19",
27
+ "@nocobase/utils": "2.1.0-alpha.19",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "586cb00f56557e66168b9720d0e0193a1b752067"
64
+ "gitHead": "3d13700360eac1c0f9dbf6a5f167ed396a294a3c"
65
65
  }