@nocobase/plugin-workflow-request 2.1.0-beta.2 → 2.1.0-beta.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 +201 -661
- package/README.md +79 -10
- package/dist/client/RequestInstruction.d.ts +8 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +6 -5
- package/dist/locale/en-US.json +2 -1
- package/dist/locale/zh-CN.json +3 -1
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/RequestInstruction.d.ts +10 -2
- package/dist/server/RequestInstruction.js +81 -20
- package/package.json +4 -3
|
@@ -39,10 +39,11 @@ __export(RequestInstruction_exports, {
|
|
|
39
39
|
default: () => RequestInstruction_default
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(RequestInstruction_exports);
|
|
42
|
-
var
|
|
42
|
+
var import_joi = __toESM(require("joi"));
|
|
43
43
|
var import_lodash = require("lodash");
|
|
44
44
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
45
45
|
var import_plugin_file_manager = __toESM(require("@nocobase/plugin-file-manager"));
|
|
46
|
+
var import_utils = require("@nocobase/utils");
|
|
46
47
|
function getContentTypeTransformer(mimeType, app) {
|
|
47
48
|
switch (mimeType) {
|
|
48
49
|
case "text/plain":
|
|
@@ -85,8 +86,27 @@ function getContentTypeTransformer(mimeType, app) {
|
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
}
|
|
89
|
+
function createInvalidUrlError(cause) {
|
|
90
|
+
if (cause instanceof TypeError && typeof cause.code !== "undefined") {
|
|
91
|
+
return cause;
|
|
92
|
+
}
|
|
93
|
+
const error = new TypeError("Invalid URL");
|
|
94
|
+
error.code = "ERR_INVALID_URL";
|
|
95
|
+
return error;
|
|
96
|
+
}
|
|
97
|
+
function validateUrl(url) {
|
|
98
|
+
try {
|
|
99
|
+
const parsed = new URL(url);
|
|
100
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
101
|
+
throw createInvalidUrlError();
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw createInvalidUrlError(error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
88
107
|
async function request(config, app) {
|
|
89
108
|
const { url, method = "POST", contentType = "application/json", data, timeout = 5e3 } = config;
|
|
109
|
+
validateUrl(url);
|
|
90
110
|
const headers = (config.headers ?? []).reduce((result, header) => {
|
|
91
111
|
const name = (0, import_lodash.trim)(header.name);
|
|
92
112
|
if (name.toLowerCase() === "content-type") {
|
|
@@ -102,7 +122,7 @@ async function request(config, app) {
|
|
|
102
122
|
headers["Content-Type"] = contentType;
|
|
103
123
|
}
|
|
104
124
|
const transformer = getContentTypeTransformer(contentType, app);
|
|
105
|
-
return
|
|
125
|
+
return (0, import_utils.serverRequest)({
|
|
106
126
|
url: (0, import_lodash.trim)(url),
|
|
107
127
|
method,
|
|
108
128
|
headers,
|
|
@@ -118,31 +138,69 @@ function responseSuccess(response, onlyData = false) {
|
|
|
118
138
|
status: response.status,
|
|
119
139
|
statusText: response.statusText,
|
|
120
140
|
headers: response.headers,
|
|
121
|
-
config: response.config,
|
|
122
141
|
data: response.data
|
|
123
142
|
};
|
|
124
143
|
}
|
|
125
144
|
function responseFailure(error) {
|
|
126
|
-
|
|
127
|
-
message: error.message
|
|
128
|
-
stack: error.stack
|
|
145
|
+
const result = {
|
|
146
|
+
message: error instanceof Error ? error.message : String(error)
|
|
129
147
|
};
|
|
130
|
-
if (error.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} else if (error.request) {
|
|
140
|
-
result = error.toJSON();
|
|
141
|
-
}
|
|
148
|
+
if (typeof (error == null ? void 0 : error.code) !== "undefined") {
|
|
149
|
+
result["code"] = error.code;
|
|
150
|
+
}
|
|
151
|
+
if ((error == null ? void 0 : error.isAxiosError) && error.response) {
|
|
152
|
+
Object.assign(result, {
|
|
153
|
+
status: error.response.status,
|
|
154
|
+
statusText: error.response.statusText,
|
|
155
|
+
data: error.response.data
|
|
156
|
+
});
|
|
142
157
|
}
|
|
143
158
|
return result;
|
|
144
159
|
}
|
|
160
|
+
const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
161
|
+
const CONTENT_TYPES = [
|
|
162
|
+
"application/json",
|
|
163
|
+
"application/x-www-form-urlencoded",
|
|
164
|
+
"multipart/form-data",
|
|
165
|
+
"application/xml",
|
|
166
|
+
"text/plain"
|
|
167
|
+
];
|
|
168
|
+
function logFailureDebug(logger, error) {
|
|
169
|
+
if (!(error == null ? void 0 : error.isAxiosError)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (error.response) {
|
|
173
|
+
logger.debug("request failed response details", {
|
|
174
|
+
status: error.response.status,
|
|
175
|
+
statusText: error.response.statusText,
|
|
176
|
+
data: error.response.data
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
logger.debug("request failed error details", responseFailure(error));
|
|
181
|
+
}
|
|
145
182
|
class RequestInstruction_default extends import_plugin_workflow.Instruction {
|
|
183
|
+
configSchema = import_joi.default.object({
|
|
184
|
+
url: import_joi.default.string(),
|
|
185
|
+
method: import_joi.default.string().valid(...METHODS),
|
|
186
|
+
contentType: import_joi.default.string().valid(...CONTENT_TYPES),
|
|
187
|
+
headers: import_joi.default.array().items(
|
|
188
|
+
import_joi.default.object({
|
|
189
|
+
name: import_joi.default.string(),
|
|
190
|
+
value: import_joi.default.string()
|
|
191
|
+
})
|
|
192
|
+
),
|
|
193
|
+
params: import_joi.default.array().items(
|
|
194
|
+
import_joi.default.object({
|
|
195
|
+
name: import_joi.default.string(),
|
|
196
|
+
value: import_joi.default.string()
|
|
197
|
+
})
|
|
198
|
+
),
|
|
199
|
+
data: import_joi.default.alternatives().try(import_joi.default.object(), import_joi.default.array(), import_joi.default.string()),
|
|
200
|
+
timeout: import_joi.default.number().integer().positive().default(5e3),
|
|
201
|
+
ignoreFail: import_joi.default.boolean().default(false),
|
|
202
|
+
onlyData: import_joi.default.boolean().default(false)
|
|
203
|
+
});
|
|
146
204
|
async run(node, prevJob, processor) {
|
|
147
205
|
const config = processor.getParsedValue(node.config, node.id);
|
|
148
206
|
const { workflow } = processor.execution;
|
|
@@ -155,9 +213,10 @@ class RequestInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
155
213
|
result: responseSuccess(response, config.onlyData)
|
|
156
214
|
};
|
|
157
215
|
} catch (error) {
|
|
216
|
+
logFailureDebug(this.workflow.app.logger, error);
|
|
158
217
|
return {
|
|
159
218
|
status: config.ignoreFail ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.FAILED,
|
|
160
|
-
result: error
|
|
219
|
+
result: responseFailure(error)
|
|
161
220
|
};
|
|
162
221
|
}
|
|
163
222
|
}
|
|
@@ -187,6 +246,7 @@ class RequestInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
187
246
|
} else {
|
|
188
247
|
processor.logger.error(`request (#${node.id}) failed unexpectedly: ${error.message}`);
|
|
189
248
|
}
|
|
249
|
+
logFailureDebug(processor.logger, error);
|
|
190
250
|
jobDone.status = config.ignoreFail ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.FAILED;
|
|
191
251
|
jobDone.result = responseFailure(error);
|
|
192
252
|
} finally {
|
|
@@ -212,9 +272,10 @@ class RequestInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
212
272
|
result: responseSuccess(response, config.onlyData)
|
|
213
273
|
};
|
|
214
274
|
} catch (error) {
|
|
275
|
+
logFailureDebug(this.workflow.app.logger, error);
|
|
215
276
|
return {
|
|
216
277
|
status: config.ignoreFail ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.FAILED,
|
|
217
|
-
result: error
|
|
278
|
+
result: responseFailure(error)
|
|
218
279
|
};
|
|
219
280
|
}
|
|
220
281
|
}
|
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"description": "Send HTTP requests to any HTTP service for data interaction in workflow.",
|
|
7
7
|
"description.ru-RU": "Отправляет HTTP-запросы к любому HTTP-сервису для взаимодействия с данными в рабочем процессе.",
|
|
8
8
|
"description.zh-CN": "可用于在工作流中向任意 HTTP 服务发送请求,进行数据交互。",
|
|
9
|
-
"version": "2.1.0-beta.
|
|
10
|
-
"license": "
|
|
9
|
+
"version": "2.1.0-beta.21",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/handbook/workflow-request",
|
|
13
13
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/workflow-request",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"antd": "5.x",
|
|
17
17
|
"axios": "^1.7.0",
|
|
18
|
+
"joi": "^17.13.3",
|
|
18
19
|
"react": "18.x",
|
|
19
20
|
"react-i18next": "^11.15.1"
|
|
20
21
|
},
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"@nocobase/server": "2.x",
|
|
27
28
|
"@nocobase/test": "2.x"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "324bd82f33fca58e98711688a17ceb65c186b65e",
|
|
30
31
|
"keywords": [
|
|
31
32
|
"Workflow"
|
|
32
33
|
]
|