@nocobase/plugin-action-custom-request 2.1.0-alpha.1 → 2.1.0-alpha.10

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.
@@ -5,22 +5,30 @@
5
5
  "Add request header": "Add request header",
6
6
  "Body": "Body",
7
7
  "Custom Request": "Custom Request",
8
+ "Custom request": "Custom request",
8
9
  "Enter description info": "Enter description info",
9
10
  "Format": "Format",
10
11
  "HTTP method": "HTTP method",
11
12
  "Headers": "Headers",
12
13
  "If not set, all roles can see this action": "If not set, all roles can see this action",
14
+ "If not set, all roles can access this request": "If not set, all roles can access this request",
13
15
  "Input request data": "Input request data",
14
16
  "Insert": "Insert",
17
+ "Key": "Key",
18
+ "Name": "Name",
15
19
  "Only support standard JSON data": "Only support standard JSON data",
16
20
  "Parameters": "Parameters",
17
21
  "Please configure the request settings first": "Please configure the request settings first",
18
22
  "Request settings": "Request settings",
23
+ "Response type": "Response type",
19
24
  "Roles": "Roles",
25
+ "Stream": "Stream",
20
26
  "Timeout config": "Timeout config",
21
27
  "Title": "Title",
22
28
  "URL": "URL",
23
29
  "Use variable": "Use variable",
30
+ "You do not have permission to access this custom request": "You do not have permission to access this custom request",
31
+ "Value": "Value",
24
32
  "When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data": "When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data",
25
33
  "ms": "ms"
26
- }
34
+ }
@@ -5,22 +5,30 @@
5
5
  "Add request header": "添加请求头",
6
6
  "Body": "请求体",
7
7
  "Custom Request": "自定义请求",
8
+ "Custom request": "自定义请求",
8
9
  "Enter description info": "输入描述信息",
9
10
  "Format": "格式化",
10
11
  "HTTP method": "HTTP 方法",
11
12
  "Headers": "请求头",
12
13
  "If not set, all roles can see this action": "如果不设置,所有角色都可以看到这个自定义请求",
14
+ "If not set, all roles can access this request": "如果不设置,所有角色都可以访问此请求",
13
15
  "Input request data": "输入请求数据",
14
16
  "Insert": "插入",
17
+ "Key": "标识",
18
+ "Name": "名称",
15
19
  "Only support standard JSON data": "仅支持标准 JSON 数据",
16
20
  "Parameters": "参数",
17
21
  "Please configure the request settings first": "请先配置请求设置",
18
22
  "Request settings": "请求设置",
23
+ "Response type": "响应类型",
19
24
  "Roles": "角色",
25
+ "Stream": "流",
20
26
  "Timeout config": "超时设置",
21
27
  "Title": "标题",
22
28
  "URL": "URL",
23
29
  "Use variable": "使用变量",
30
+ "You do not have permission to access this custom request": "你没有权限访问此自定义请求",
31
+ "Value": "值",
24
32
  "When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data": "当请求方法为 Post、Put 或 Patch 时,且此自定义请求在表单内,请求体将自动填充表单数据",
25
33
  "ms": "毫秒"
26
- }
34
+ }
@@ -43,6 +43,22 @@ module.exports = __toCommonJS(send_exports);
43
43
  var import_utils = require("@nocobase/utils");
44
44
  var import_evaluators = require("@nocobase/evaluators");
45
45
  var import_axios = __toESM(require("axios"));
46
+ var import_set = __toESM(require("lodash/set"));
47
+ const UnsafePathSegments = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
48
+ const hasUnsafePathSegment = (path) => {
49
+ return path.split(/[.[\]]+/).filter(Boolean).some((segment) => UnsafePathSegments.has(segment));
50
+ };
51
+ const applyVarsToVariables = (variables, vars) => {
52
+ if (!vars || typeof vars !== "object" || Array.isArray(vars)) {
53
+ return;
54
+ }
55
+ for (const [key, value] of Object.entries(vars)) {
56
+ if (!key || typeof key !== "string" || hasUnsafePathSegment(key)) {
57
+ continue;
58
+ }
59
+ (0, import_set.default)(variables, key, value);
60
+ }
61
+ };
46
62
  function toJSON(value) {
47
63
  if (typeof value === "string") {
48
64
  try {
@@ -75,7 +91,7 @@ const omitNullAndUndefined = (obj) => {
75
91
  return acc;
76
92
  }, {});
77
93
  };
78
- const CurrentUserVariableRegExp = /{{\s*(currentUser[^}]+)\s*}}/g;
94
+ const CurrentUserVariableRegExp = /{{\s*(?:ctx\.)?(currentUser[^}]+)\s*}}/g;
79
95
  const getCurrentUserAppends = (str, user) => {
80
96
  const matched = str.matchAll(CurrentUserVariableRegExp);
81
97
  return Array.from(matched).map((item) => {
@@ -104,18 +120,30 @@ async function send(ctx, next) {
104
120
  data: {}
105
121
  },
106
122
  $nForm,
107
- $nSelectedRecord
123
+ $nSelectedRecord,
124
+ vars,
125
+ options: runtimeOptions
108
126
  } = values;
109
127
  if (ctx.state.currentRole !== "root") {
110
- const crRepo = ctx.db.getRepository("uiButtonSchemasRoles");
111
- const hasRoles = await crRepo.find({
128
+ const schemaRoleRepo = ctx.db.getRepository("uiButtonSchemasRoles");
129
+ const customRequestRoleRepo = ctx.db.getRepository("customRequestsRoles");
130
+ const schemaRoles = await schemaRoleRepo.find({
112
131
  filter: {
113
132
  uid: filterByTk
114
133
  }
115
134
  });
116
- if (hasRoles.length) {
117
- if (!hasRoles.some((item) => ctx.state.currentRoles.includes(item.roleName))) {
118
- return ctx.throw(403, "custom request no permission");
135
+ const customRequestRoles = await customRequestRoleRepo.find({
136
+ filter: {
137
+ customRequestKey: filterByTk
138
+ }
139
+ });
140
+ const roleRows = [...schemaRoles, ...customRequestRoles];
141
+ if (roleRows.length) {
142
+ if (!roleRows.some((item) => ctx.state.currentRoles.includes(item.roleName))) {
143
+ return ctx.throw(
144
+ 403,
145
+ ctx.t("You do not have permission to access this custom request", { ns: "action-custom-request" })
146
+ );
119
147
  }
120
148
  }
121
149
  }
@@ -129,15 +157,11 @@ async function send(ctx, next) {
129
157
  ctx.throw(404, "request config not found");
130
158
  }
131
159
  ctx.withoutDataWrapping = true;
132
- const {
133
- dataSourceKey,
134
- collectionName,
135
- url,
136
- headers = [],
137
- params = [],
138
- data = {},
139
- ...options
140
- } = requestConfig.options || {};
160
+ const mergedOptions = {
161
+ ...requestConfig.options || {},
162
+ ...omitNullAndUndefined(runtimeOptions || {})
163
+ };
164
+ const { dataSourceKey, collectionName, url, headers = [], params = [], data = {}, ...options } = mergedOptions;
141
165
  if (!url) {
142
166
  return ctx.throw(400, ctx.t("Please configure the request settings first", { ns: "action-custom-request" }));
143
167
  }
@@ -174,6 +198,7 @@ async function send(ctx, next) {
174
198
  $env: ctx.app.environment.getVariables(),
175
199
  $nSelectedRecord
176
200
  };
201
+ applyVarsToVariables(variables, vars);
177
202
  const axiosRequestConfig = {
178
203
  baseURL: ctx.origin,
179
204
  ...options,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-action-custom-request",
3
- "version": "2.1.0-alpha.1",
3
+ "version": "2.1.0-alpha.10",
4
4
  "main": "dist/server/index.js",
5
5
  "homepage": "https://docs.nocobase.com/handbook/action-custom-request",
6
6
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/action-custom-request",
@@ -11,7 +11,7 @@
11
11
  "description": "Sending a request to any HTTP service supports sending context data to the target service.",
12
12
  "description.ru-RU": "Отправка запроса к любому HTTP-сервису, поддерживается отправка контекстных данных в целевой сервис.",
13
13
  "description.zh-CN": "向任意 HTTP 服务发送请求,支持将上下文数据发送给目标服务。",
14
- "license": "AGPL-3.0",
14
+ "license": "Apache-2.0",
15
15
  "devDependencies": {
16
16
  "@formily/react": "2.x",
17
17
  "@formily/shared": "2.x",
@@ -20,12 +20,18 @@
20
20
  "react-i18next": "^11.15.1",
21
21
  "react-router-dom": "6.x"
22
22
  },
23
+ "nocobase": {
24
+ "supportedVersions": [
25
+ "1.x"
26
+ ],
27
+ "editionLevel": 0
28
+ },
23
29
  "peerDependencies": {
24
30
  "@nocobase/client": "2.x",
25
31
  "@nocobase/server": "2.x",
26
32
  "@nocobase/test": "2.x"
27
33
  },
28
- "gitHead": "d27baf21569643d6fa83f882233f4e90eb5b89f1",
34
+ "gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8",
29
35
  "keywords": [
30
36
  "Actions"
31
37
  ]