@nocobase/plugin-collection-sql 1.6.0-alpha.2 → 1.6.0-alpha.21

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.txt CHANGED
@@ -1,4 +1,4 @@
1
- Updated Date: October 15, 2024
1
+ Updated Date: February 6, 2025
2
2
 
3
3
  NocoBase License Agreement
4
4
 
@@ -78,7 +78,7 @@ Except for Third-Party Open Source Software, the Company owns all copyrights, tr
78
78
 
79
79
  6.1 Obtain a permanent commercial license of the Software.
80
80
 
81
- 6.2 Get 12 months of upgrade and exclusive technical support.
81
+ 6.2 Get software upgrades and exclusive technical support during the upgrade validity period.
82
82
 
83
83
  6.3 The licensed Software can be used for commercial purposes with no restrictions on the number of applications and users.
84
84
 
@@ -108,11 +108,13 @@ Except for Third-Party Open Source Software, the Company owns all copyrights, tr
108
108
 
109
109
  7.5 It is not allowed for the User with a Standard Edition license to sell Upper Layer Application to clients without a Commercial license.
110
110
 
111
- 7.6 It is not allowed to publicly sell plugins developed for Software outside of the Marketplace.
111
+ 7.6 It is not allowed for the User with a Professional or Enterprise Edition license to sell Upper Layer Application to clients without a Commercial license with access to further development and configuration.
112
112
 
113
- 7.7 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
113
+ 7.7 It is not allowed to publicly sell plugins developed for Software outside of the Marketplace.
114
114
 
115
- 7.8 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
115
+ 7.8 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
116
+
117
+ 7.9 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
116
118
 
117
119
  ======================================
118
120
  8. Rights of Commercial Plugin License
@@ -120,7 +122,7 @@ Except for Third-Party Open Source Software, the Company owns all copyrights, tr
120
122
 
121
123
  8.1 Obtain a permanent Commercial Plugin License for the Commercial Plugin.
122
124
 
123
- 8.2 Receive 12 months of upgrades and exclusive technical support.
125
+ 8.2 Get plugins upgrades and exclusive technical support during the upgrade validity period.
124
126
 
125
127
  8.3 Can be used for commercial purposes without restrictions on the number of applications or users.
126
128
 
@@ -8,10 +8,10 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.6.0-alpha.2",
12
- "@nocobase/server": "1.6.0-alpha.2",
13
- "@nocobase/database": "1.6.0-alpha.2",
14
- "@nocobase/actions": "1.6.0-alpha.2",
11
+ "@nocobase/client": "1.6.0-alpha.21",
12
+ "@nocobase/server": "1.6.0-alpha.21",
13
+ "@nocobase/database": "1.6.0-alpha.21",
14
+ "@nocobase/actions": "1.6.0-alpha.21",
15
15
  "sequelize": "6.35.2",
16
- "@nocobase/utils": "1.6.0-alpha.2"
16
+ "@nocobase/utils": "1.6.0-alpha.21"
17
17
  };
@@ -43,6 +43,7 @@ module.exports = __toCommonJS(plugin_exports);
43
43
  var import_server = require("@nocobase/server");
44
44
  var import_sql_collection = require("./sql-collection");
45
45
  var import_sql = __toESM(require("./resources/sql"));
46
+ var import_utils = require("./utils");
46
47
  class PluginCollectionSQLServer extends import_server.Plugin {
47
48
  async beforeLoad() {
48
49
  this.app.db.collectionFactory.registerCollectionType(import_sql_collection.SQLCollection, {
@@ -61,6 +62,20 @@ class PluginCollectionSQLServer extends import_server.Plugin {
61
62
  name: `pm.data-source-manager.collection-sql `,
62
63
  actions: ["sqlCollection:*"]
63
64
  });
65
+ this.app.resourceManager.use(async (ctx, next) => {
66
+ const { resourceName, actionName } = ctx.action;
67
+ if (resourceName === "collections" && actionName === "create") {
68
+ const { sql } = ctx.action.params.values || {};
69
+ if (sql) {
70
+ try {
71
+ (0, import_utils.checkSQL)(sql);
72
+ } catch (e) {
73
+ ctx.throw(400, ctx.t(e.message));
74
+ }
75
+ }
76
+ }
77
+ return next();
78
+ });
64
79
  }
65
80
  }
66
81
  var plugin_default = PluginCollectionSQLServer;
@@ -30,7 +30,9 @@ __export(sql_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(sql_exports);
32
32
  var import_sql_collection = require("../sql-collection");
33
+ var import_utils = require("../utils");
33
34
  const updateCollection = async (ctx, transaction) => {
35
+ var _a;
34
36
  const { filterByTk, values } = ctx.action.params;
35
37
  const repo = ctx.db.getRepository("collections");
36
38
  const collection = await repo.findOne({
@@ -41,15 +43,21 @@ const updateCollection = async (ctx, transaction) => {
41
43
  });
42
44
  const existFields = await collection.getFields({ transaction });
43
45
  const deletedFields = existFields.filter((field) => {
44
- var _a;
45
- return !((_a = values.fields) == null ? void 0 : _a.find((f) => f.name === field.name));
46
+ var _a2;
47
+ return !((_a2 = values.fields) == null ? void 0 : _a2.find((f) => f.name === field.name));
46
48
  });
47
49
  for (const field of deletedFields) {
48
50
  await field.destroy({ transaction });
49
51
  }
50
52
  const upRes = await repo.update({
51
53
  filterByTk,
52
- values,
54
+ values: {
55
+ ...values,
56
+ fields: (_a = values.fields) == null ? void 0 : _a.map((f) => {
57
+ delete f.key;
58
+ return f;
59
+ })
60
+ },
53
61
  updateAssociationValues: ["fields"],
54
62
  transaction
55
63
  });
@@ -59,13 +67,14 @@ var sql_default = {
59
67
  name: "sqlCollection",
60
68
  actions: {
61
69
  execute: async (ctx, next) => {
62
- let { sql } = ctx.action.params.values || {};
70
+ const { sql } = ctx.action.params.values || {};
63
71
  if (!sql) {
64
72
  ctx.throw(400, ctx.t("Please enter a SQL statement"));
65
73
  }
66
- sql = sql.trim().split(";").shift();
67
- if (!/^select/i.test(sql) && !/^with([\s\S]+)select([\s\S]+)/i.test(sql)) {
68
- ctx.throw(400, ctx.t("Only supports SELECT statements or WITH clauses"));
74
+ try {
75
+ (0, import_utils.checkSQL)(sql);
76
+ } catch (e) {
77
+ ctx.throw(400, ctx.t(e.message));
69
78
  }
70
79
  const tmpCollection = new import_sql_collection.SQLCollection({ name: "tmp", sql }, { database: ctx.db });
71
80
  const model = tmpCollection.model;
@@ -45,13 +45,13 @@ function selectQuery(tableName, options, model) {
45
45
  attributes = this.escapeAttributes(attributes, { model });
46
46
  attributes = attributes || ["*"];
47
47
  if (Object.prototype.hasOwnProperty.call(options, "where")) {
48
- options.where = this.getWhereConditions(options.where, tableName, model, options);
48
+ options.where = this.getWhereConditions(options.where, model.name, model, options);
49
49
  if (options.where) {
50
50
  queryItems.push(` WHERE ${options.where}`);
51
51
  }
52
52
  }
53
53
  if (options.group) {
54
- options.group = Array.isArray(options.group) ? options.group.map((t) => this.aliasGrouping(t, model, tableName, options)).join(", ") : this.aliasGrouping(options.group, model, tableName, options);
54
+ options.group = Array.isArray(options.group) ? options.group.map((t) => this.aliasGrouping(t, model, model.name, options)).join(", ") : this.aliasGrouping(options.group, model, model.name, options);
55
55
  if (options.group) {
56
56
  queryItems.push(` GROUP BY ${options.group}`);
57
57
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare const checkSQL: (sql: string) => void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var utils_exports = {};
28
+ __export(utils_exports, {
29
+ checkSQL: () => checkSQL
30
+ });
31
+ module.exports = __toCommonJS(utils_exports);
32
+ const checkSQL = (sql) => {
33
+ const dangerKeywords = [
34
+ // PostgreSQL
35
+ "pg_read_file",
36
+ "pg_read_binary_file",
37
+ "pg_stat_file",
38
+ "pg_ls_dir",
39
+ "pg_logdir_ls",
40
+ "pg_terminate_backend",
41
+ "pg_cancel_backend",
42
+ "current_setting",
43
+ "set_config",
44
+ "pg_reload_conf",
45
+ "pg_sleep",
46
+ "generate_series",
47
+ // MySQL
48
+ "LOAD_FILE",
49
+ "BENCHMARK",
50
+ "@@global.",
51
+ "@@session.",
52
+ // SQLite
53
+ "sqlite3_load_extension",
54
+ "load_extension"
55
+ ];
56
+ sql = sql.trim().split(";").shift();
57
+ if (!/^select/i.test(sql) && !/^with([\s\S]+)select([\s\S]+)/i.test(sql)) {
58
+ throw new Error("Only supports SELECT statements or WITH clauses");
59
+ }
60
+ if (dangerKeywords.some((keyword) => sql.toLowerCase().includes(keyword.toLowerCase()))) {
61
+ throw new Error("SQL statements contain dangerous keywords");
62
+ }
63
+ };
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ checkSQL
67
+ });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据表: SQL",
5
5
  "description": "Provides SQL collection template",
6
6
  "description.zh-CN": "提供 SQL 数据表模板",
7
- "version": "1.6.0-alpha.2",
7
+ "version": "1.6.0-alpha.21",
8
8
  "homepage": "https://docs-cn.nocobase.com/handbook/collection-sql",
9
9
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/collection-sql",
10
10
  "main": "dist/server/index.js",
@@ -17,5 +17,5 @@
17
17
  "keywords": [
18
18
  "Collections"
19
19
  ],
20
- "gitHead": "08bbc34c21727fc0ad0880f397a42bf7741091ee"
20
+ "gitHead": "873cbaec9554e684781b8dc6cfd4386bb5cfa5b0"
21
21
  }