@nocobase/plugin-environment-variables 1.6.0-alpha.18 → 1.6.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.
@@ -9,12 +9,12 @@
9
9
 
10
10
  module.exports = {
11
11
  "@formily/react": "2.3.0",
12
- "@nocobase/client": "1.6.0-alpha.18",
12
+ "@nocobase/client": "1.6.0-alpha.20",
13
13
  "react": "18.2.0",
14
- "@nocobase/server": "1.6.0-alpha.18",
14
+ "@nocobase/server": "1.6.0-alpha.20",
15
15
  "@ant-design/icons": "5.2.6",
16
16
  "@formily/antd-v5": "1.1.9",
17
17
  "@formily/core": "2.3.0",
18
18
  "antd": "5.12.8",
19
- "@nocobase/database": "1.6.0-alpha.18"
19
+ "@nocobase/database": "1.6.0-alpha.20"
20
20
  };
@@ -14,6 +14,10 @@ export declare class PluginEnvironmentVariablesServer extends Plugin {
14
14
  load(): Promise<void>;
15
15
  registerACL(): void;
16
16
  listEnvironmentVariables(): Promise<any>;
17
+ validateTexts(texts: Array<{
18
+ text: string;
19
+ secret: boolean;
20
+ }>): void;
17
21
  setEnvironmentVariablesByText(texts: Array<{
18
22
  text: string;
19
23
  secret: boolean;
@@ -66,7 +66,39 @@ class PluginEnvironmentVariablesServer extends import_server.Plugin {
66
66
  });
67
67
  return items.map(({ name, type }) => ({ name, type }));
68
68
  }
69
+ validateTexts(texts) {
70
+ if (!Array.isArray(texts)) {
71
+ throw new Error("texts parameter must be an array");
72
+ }
73
+ for (const item of texts) {
74
+ if (!item || typeof item !== "object") {
75
+ throw new Error("Each item in texts must be an object");
76
+ }
77
+ if (typeof item.text !== "string" || !item.text.trim()) {
78
+ throw new Error("text property must be a non-empty string");
79
+ }
80
+ if (typeof item.secret !== "boolean") {
81
+ throw new Error("secret property must be a boolean");
82
+ }
83
+ const lines = item.text.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
84
+ for (const line of lines) {
85
+ const equalIndex = line.indexOf("=");
86
+ if (equalIndex === -1) {
87
+ throw new Error(`Invalid environment variable format: ${line}`);
88
+ }
89
+ const key = line.slice(0, equalIndex).trim();
90
+ const value = line.slice(equalIndex + 1).trim();
91
+ if (!key) {
92
+ throw new Error(`Environment variable name cannot be empty`);
93
+ }
94
+ if (!value) {
95
+ throw new Error(`Environment variable "${key}" must have a value`);
96
+ }
97
+ }
98
+ }
99
+ }
69
100
  async setEnvironmentVariablesByText(texts) {
101
+ this.validateTexts(texts);
70
102
  const repository = this.db.getRepository("environmentVariables");
71
103
  for (const { text, secret } of texts) {
72
104
  const lines = text.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
@@ -78,10 +110,13 @@ class PluginEnvironmentVariablesServer extends import_server.Plugin {
78
110
  }
79
111
  const key = line.slice(0, equalIndex).trim();
80
112
  const value = line.slice(equalIndex + 1).trim();
81
- if (!key || !value) {
82
- this.app.log.warn(`Empty key or value found: ${line}`);
113
+ if (!key) {
114
+ this.app.log.warn(`Empty key found: ${line}`);
83
115
  continue;
84
116
  }
117
+ if (!value) {
118
+ throw new Error(`Empty value is not allowed for key: ${key}`);
119
+ }
85
120
  await repository.create({
86
121
  values: {
87
122
  name: key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-environment-variables",
3
- "version": "1.6.0-alpha.18",
3
+ "version": "1.6.0-alpha.20",
4
4
  "main": "dist/server/index.js",
5
5
  "peerDependencies": {
6
6
  "@nocobase/client": "1.x",
@@ -14,5 +14,5 @@
14
14
  "keywords": [
15
15
  "System management"
16
16
  ],
17
- "gitHead": "db361bebe9ed4a5ca19fc14183fe4576443568ef"
17
+ "gitHead": "c127664eb2b900edd5c18c9344046cd663a06c3b"
18
18
  }