@nocobase/plugin-workflow-request 0.19.0-alpha.3 → 0.19.0-alpha.5

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.
@@ -1,8 +1,8 @@
1
1
  module.exports = {
2
2
  "@formily/antd-v5": "1.1.9",
3
- "@nocobase/plugin-workflow": "0.19.0-alpha.3",
4
- "@nocobase/client": "0.19.0-alpha.3",
3
+ "@nocobase/plugin-workflow": "0.19.0-alpha.5",
4
+ "@nocobase/client": "0.19.0-alpha.5",
5
5
  "react-i18next": "11.18.6",
6
- "@nocobase/server": "0.19.0-alpha.3",
6
+ "@nocobase/server": "0.19.0-alpha.5",
7
7
  "axios": "0.26.1"
8
8
  };
@@ -0,0 +1,22 @@
1
+ {
2
+ "HTTP request": "HTTP 요청",
3
+ "Send HTTP request to a URL. You can use the variables in the upstream nodes as request headers, parameters and request body.":
4
+ "URL에 HTTP 요청을 보냅니다. 상류 노드의 변수를 요청 헤더, 매개변수 및 요청 본문으로 사용할 수 있습니다.",
5
+ "HTTP method": "HTTP 메서드",
6
+ "URL": "주소",
7
+ "Headers": "헤더",
8
+ "Add request header": "요청 헤더 추가",
9
+ "Parameters": "매개변수",
10
+ "Add parameter": "매개변수 추가",
11
+ "Body": "본문",
12
+ "Use variable": "변수 사용",
13
+ "Format": "형식",
14
+ "Insert": "삽입",
15
+ "Timeout config": "시간 초과 설정",
16
+ "ms": "밀리초",
17
+ "Input request data": "요청 데이터 입력",
18
+ "Only support standard JSON data": "표준 JSON 데이터만 지원합니다",
19
+ "\"Content-Type\" only support \"application/json\", and no need to specify":
20
+ "\"Content-Type\" 헤더는 \"application/json\"만 지원하며 지정할 필요가 없습니다",
21
+ "Ignore failed request and continue workflow": "실패한 요청을 무시하고 워크플로를 계속합니다"
22
+ }
@@ -56,12 +56,29 @@ async function request(config) {
56
56
  }
57
57
  class RequestInstruction_default extends import_plugin_workflow.Instruction {
58
58
  async run(node, prevJob, processor) {
59
+ const config = processor.getParsedValue(node.config, node.id);
60
+ const { workflow } = processor.execution;
61
+ const sync = this.workflow.isWorkflowSync(workflow);
62
+ if (sync) {
63
+ try {
64
+ const response = await request(config);
65
+ return {
66
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED,
67
+ result: response.data
68
+ };
69
+ } catch (error) {
70
+ return {
71
+ status: import_plugin_workflow.JOB_STATUS.FAILED,
72
+ result: error.isAxiosError ? error.toJSON() : error.message
73
+ };
74
+ }
75
+ }
59
76
  const job = await processor.saveJob({
60
77
  status: import_plugin_workflow.JOB_STATUS.PENDING,
61
78
  nodeId: node.id,
79
+ nodeKey: node.key,
62
80
  upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
63
81
  });
64
- const config = processor.getParsedValue(node.config, node.id);
65
82
  request(config).then((response) => {
66
83
  job.set({
67
84
  status: import_plugin_workflow.JOB_STATUS.RESOLVED,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:HTTP 请求节点",
5
5
  "description": "Send HTTP requests to any HTTP service for data interaction in workflow.",
6
6
  "description.zh-CN": "可用于在工作流中向任意 HTTP 服务发送请求,进行数据交互。",
7
- "version": "0.19.0-alpha.3",
7
+ "version": "0.19.0-alpha.5",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -19,5 +19,5 @@
19
19
  "@nocobase/server": "0.x",
20
20
  "@nocobase/test": "0.x"
21
21
  },
22
- "gitHead": "3cee597df101a3f8f0f1e2a6f75fc2dddd02ac74"
22
+ "gitHead": "580eca25451ec731d17ddef285d0b8c52c48d501"
23
23
  }
@@ -0,0 +1,22 @@
1
+ {
2
+ "HTTP request": "HTTP 요청",
3
+ "Send HTTP request to a URL. You can use the variables in the upstream nodes as request headers, parameters and request body.":
4
+ "URL에 HTTP 요청을 보냅니다. 상류 노드의 변수를 요청 헤더, 매개변수 및 요청 본문으로 사용할 수 있습니다.",
5
+ "HTTP method": "HTTP 메서드",
6
+ "URL": "주소",
7
+ "Headers": "헤더",
8
+ "Add request header": "요청 헤더 추가",
9
+ "Parameters": "매개변수",
10
+ "Add parameter": "매개변수 추가",
11
+ "Body": "본문",
12
+ "Use variable": "변수 사용",
13
+ "Format": "형식",
14
+ "Insert": "삽입",
15
+ "Timeout config": "시간 초과 설정",
16
+ "ms": "밀리초",
17
+ "Input request data": "요청 데이터 입력",
18
+ "Only support standard JSON data": "표준 JSON 데이터만 지원합니다",
19
+ "\"Content-Type\" only support \"application/json\", and no need to specify":
20
+ "\"Content-Type\" 헤더는 \"application/json\"만 지원하며 지정할 필요가 없습니다",
21
+ "Ignore failed request and continue workflow": "실패한 요청을 무시하고 워크플로를 계속합니다"
22
+ }
@@ -41,14 +41,33 @@ async function request(config) {
41
41
 
42
42
  export default class extends Instruction {
43
43
  async run(node: FlowNodeModel, prevJob, processor: Processor) {
44
+ const config = processor.getParsedValue(node.config, node.id) as RequestConfig;
45
+
46
+ const { workflow } = processor.execution;
47
+ const sync = this.workflow.isWorkflowSync(workflow);
48
+
49
+ if (sync) {
50
+ try {
51
+ const response = await request(config);
52
+ return {
53
+ status: JOB_STATUS.RESOLVED,
54
+ result: response.data,
55
+ };
56
+ } catch (error) {
57
+ return {
58
+ status: JOB_STATUS.FAILED,
59
+ result: error.isAxiosError ? error.toJSON() : error.message,
60
+ };
61
+ }
62
+ }
63
+
44
64
  const job = await processor.saveJob({
45
65
  status: JOB_STATUS.PENDING,
46
66
  nodeId: node.id,
67
+ nodeKey: node.key,
47
68
  upstreamId: prevJob?.id ?? null,
48
69
  });
49
70
 
50
- const config = processor.getParsedValue(node.config, node.id) as RequestConfig;
51
-
52
71
  // eslint-disable-next-line promise/catch-or-return
53
72
  request(config)
54
73
  .then((response) => {
@@ -6,7 +6,7 @@ import bodyParser from 'koa-bodyparser';
6
6
  import Database from '@nocobase/database';
7
7
  import { MockServer } from '@nocobase/test';
8
8
 
9
- import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
9
+ import PluginWorkflow, { Processor, EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
10
10
  import { getApp, sleep } from '@nocobase/plugin-workflow-test';
11
11
 
12
12
  import { RequestConfig } from '../RequestInstruction';
@@ -349,4 +349,31 @@ describe('workflow > instructions > request', () => {
349
349
  server.close();
350
350
  });
351
351
  });
352
+
353
+ describe('sync request', () => {
354
+ it('sync trigger', async () => {
355
+ const syncFlow = await WorkflowModel.create({
356
+ type: 'syncTrigger',
357
+ enabled: true,
358
+ });
359
+ await syncFlow.createNode({
360
+ type: 'request',
361
+ config: {
362
+ url: api.URL_DATA,
363
+ method: 'GET',
364
+ } as RequestConfig,
365
+ });
366
+
367
+ const workflowPlugin = app.pm.get(PluginWorkflow) as PluginWorkflow;
368
+ const processor = (await workflowPlugin.trigger(syncFlow, { data: { title: 't1' } })) as Processor;
369
+
370
+ const [execution] = await syncFlow.getExecutions();
371
+ expect(processor.execution.id).toEqual(execution.id);
372
+ expect(processor.execution.status).toEqual(execution.status);
373
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
374
+ const [job] = await execution.getJobs();
375
+ expect(job.status).toEqual(JOB_STATUS.RESOLVED);
376
+ expect(job.result).toEqual({ meta: {}, data: {} });
377
+ });
378
+ });
352
379
  });