@nocobase/plugin-workflow 0.9.0-alpha.2 → 0.9.1-alpha.1

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.
Files changed (135) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +9 -0
  3. package/lib/client/AddButton.d.ts +1 -1
  4. package/lib/client/AddButton.js +7 -2
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +11 -40
  8. package/lib/client/WorkflowProvider.js +10 -1
  9. package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
  10. package/lib/client/components/CollectionBlockInitializer.js +81 -0
  11. package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
  12. package/lib/client/components/CollectionFieldInitializers.js +89 -0
  13. package/lib/client/components/CollectionFieldset.js +21 -25
  14. package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
  15. package/lib/client/components/FilterDynamicComponent.js +43 -0
  16. package/lib/client/components/NullRender.d.ts +1 -0
  17. package/lib/client/components/NullRender.js +10 -0
  18. package/lib/client/components/RadioWithTooltip.d.ts +7 -0
  19. package/lib/client/components/RadioWithTooltip.js +94 -0
  20. package/lib/client/constants.d.ts +10 -8
  21. package/lib/client/constants.js +52 -14
  22. package/lib/client/index.d.ts +0 -1
  23. package/lib/client/index.js +1 -10
  24. package/lib/client/locale/en-US.d.ts +18 -18
  25. package/lib/client/locale/en-US.js +19 -19
  26. package/lib/client/locale/zh-CN.d.ts +47 -20
  27. package/lib/client/locale/zh-CN.js +48 -21
  28. package/lib/client/nodes/calculation.d.ts +40 -6
  29. package/lib/client/nodes/calculation.js +171 -19
  30. package/lib/client/nodes/condition.d.ts +67 -0
  31. package/lib/client/nodes/condition.js +287 -27
  32. package/lib/client/nodes/create.d.ts +8 -6
  33. package/lib/client/nodes/create.js +27 -33
  34. package/lib/client/nodes/delay.d.ts +2 -0
  35. package/lib/client/nodes/delay.js +8 -4
  36. package/lib/client/nodes/destroy.d.ts +2 -2
  37. package/lib/client/nodes/destroy.js +2 -2
  38. package/lib/client/nodes/index.d.ts +10 -2
  39. package/lib/client/nodes/index.js +73 -27
  40. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  41. package/lib/client/nodes/manual/AssigneesSelect.js +64 -0
  42. package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
  43. package/lib/client/nodes/manual/ModeConfig.js +160 -0
  44. package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
  45. package/lib/client/nodes/manual/SchemaConfig.js +715 -0
  46. package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
  47. package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
  48. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
  49. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
  50. package/lib/client/nodes/manual/index.d.ts +64 -0
  51. package/lib/client/nodes/manual/index.js +146 -0
  52. package/lib/client/nodes/parallel.d.ts +11 -5
  53. package/lib/client/nodes/parallel.js +22 -34
  54. package/lib/client/nodes/query.d.ts +9 -14
  55. package/lib/client/nodes/query.js +38 -44
  56. package/lib/client/nodes/request.d.ts +75 -33
  57. package/lib/client/nodes/request.js +124 -63
  58. package/lib/client/nodes/update.d.ts +2 -2
  59. package/lib/client/nodes/update.js +2 -2
  60. package/lib/client/schemas/collection.js +1 -1
  61. package/lib/client/schemas/executions.js +1 -1
  62. package/lib/client/schemas/workflows.js +1 -1
  63. package/lib/client/style.js +0 -4
  64. package/lib/client/triggers/collection.d.ts +7 -3
  65. package/lib/client/triggers/collection.js +39 -48
  66. package/lib/client/triggers/index.d.ts +5 -2
  67. package/lib/client/triggers/index.js +34 -12
  68. package/lib/client/triggers/schedule/index.d.ts +7 -5
  69. package/lib/client/triggers/schedule/index.js +38 -79
  70. package/lib/client/utils.d.ts +1 -0
  71. package/lib/client/utils.js +38 -0
  72. package/lib/client/variable.d.ts +21 -0
  73. package/lib/client/variable.js +147 -0
  74. package/lib/server/Plugin.d.ts +3 -3
  75. package/lib/server/Plugin.js +12 -21
  76. package/lib/server/Processor.d.ts +9 -2
  77. package/lib/server/Processor.js +33 -33
  78. package/lib/server/actions/index.js +2 -4
  79. package/lib/server/actions/workflows.d.ts +1 -0
  80. package/lib/server/actions/workflows.js +80 -23
  81. package/lib/server/collections/executions.js +5 -7
  82. package/lib/server/collections/flow_nodes.js +6 -18
  83. package/lib/server/collections/jobs.js +3 -1
  84. package/lib/server/collections/workflows.js +8 -4
  85. package/lib/server/constants.d.ts +9 -3
  86. package/lib/server/constants.js +11 -5
  87. package/lib/server/functions/index.d.ts +4 -0
  88. package/lib/server/functions/index.js +38 -0
  89. package/lib/server/index.d.ts +0 -1
  90. package/lib/server/index.js +0 -14
  91. package/lib/server/instructions/calculation.d.ts +2 -7
  92. package/lib/server/instructions/calculation.js +32 -37
  93. package/lib/server/instructions/condition.d.ts +4 -4
  94. package/lib/server/instructions/condition.js +126 -54
  95. package/lib/server/instructions/index.js +1 -1
  96. package/lib/server/instructions/manual/actions.js +101 -0
  97. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  98. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  99. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  100. package/lib/server/instructions/manual/index.d.ts +25 -0
  101. package/lib/server/instructions/manual/index.js +200 -0
  102. package/lib/server/instructions/parallel.js +11 -7
  103. package/lib/server/instructions/request.d.ts +5 -4
  104. package/lib/server/instructions/request.js +60 -79
  105. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  106. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  107. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  108. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  109. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  110. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  111. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  112. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  113. package/lib/server/triggers/schedule.js +11 -3
  114. package/package.json +10 -10
  115. package/lib/client/calculators.d.ts +0 -89
  116. package/lib/client/calculators.js +0 -668
  117. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  118. package/lib/client/components/CollectionFieldSelect.js +0 -106
  119. package/lib/client/components/EjsTextArea.d.ts +0 -2
  120. package/lib/client/components/EjsTextArea.js +0 -232
  121. package/lib/server/actions/jobs.d.ts +0 -2
  122. package/lib/server/actions/jobs.js +0 -39
  123. package/lib/server/calculators/index.d.ts +0 -40
  124. package/lib/server/calculators/index.js +0 -187
  125. package/lib/server/extensions/assignees/actions.js +0 -75
  126. package/lib/server/extensions/assignees/index.d.ts +0 -2
  127. package/lib/server/extensions/assignees/index.js +0 -273
  128. package/lib/server/extensions/index.d.ts +0 -3
  129. package/lib/server/extensions/index.js +0 -13
  130. package/lib/server/instructions/prompt.d.ts +0 -19
  131. package/lib/server/instructions/prompt.js +0 -131
  132. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  133. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  134. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  135. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _actions() {
9
+ const data = _interopRequireDefault(require("@nocobase/actions"));
10
+
11
+ _actions = function _actions() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _constants = require("../../constants");
19
+
20
+ var _jobs = _interopRequireDefault(require("./collecions/jobs"));
21
+
22
+ var _users = _interopRequireDefault(require("./collecions/users"));
23
+
24
+ var _users_jobs = _interopRequireDefault(require("./collecions/users_jobs"));
25
+
26
+ var _actions2 = require("./actions");
27
+
28
+ const _excluded = ["mode"];
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+
34
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
+
36
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
37
+
38
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
39
+
40
+ const MULTIPLE_ASSIGNED_MODE = {
41
+ SINGLE: Symbol('single'),
42
+ ALL: Symbol('all'),
43
+ ANY: Symbol('any'),
44
+ ALL_PERCENTAGE: Symbol('all percentage'),
45
+ ANY_PERCENTAGE: Symbol('any percentage')
46
+ };
47
+ const Modes = {
48
+ [MULTIPLE_ASSIGNED_MODE.SINGLE]: {
49
+ getStatus(distribution, assignees) {
50
+ const done = distribution.find(item => item.status !== _constants.JOB_STATUS.PENDING && item.count > 0);
51
+ return done ? done.status : null;
52
+ }
53
+
54
+ },
55
+ [MULTIPLE_ASSIGNED_MODE.ALL]: {
56
+ getStatus(distribution, assignees) {
57
+ const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
58
+
59
+ if (resolved && resolved.count === assignees.length) {
60
+ return _constants.JOB_STATUS.RESOLVED;
61
+ }
62
+
63
+ const rejected = distribution.find(item => item.status < _constants.JOB_STATUS.PENDING);
64
+
65
+ if (rejected && rejected.count) {
66
+ return rejected.status;
67
+ }
68
+
69
+ return null;
70
+ }
71
+
72
+ },
73
+ [MULTIPLE_ASSIGNED_MODE.ANY]: {
74
+ getStatus(distribution, assignees) {
75
+ const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
76
+
77
+ if (resolved && resolved.count) {
78
+ return _constants.JOB_STATUS.RESOLVED;
79
+ }
80
+
81
+ const rejectedCount = distribution.reduce((count, item) => item.status < _constants.JOB_STATUS.PENDING ? count + item.count : count, 0); // NOTE: all failures are considered as rejected for now
82
+
83
+ if (rejectedCount === assignees.length) {
84
+ return _constants.JOB_STATUS.REJECTED;
85
+ }
86
+
87
+ return null;
88
+ }
89
+
90
+ }
91
+ };
92
+
93
+ function getMode(mode) {
94
+ switch (true) {
95
+ case mode === 1:
96
+ return Modes[MULTIPLE_ASSIGNED_MODE.ALL];
97
+
98
+ case mode === -1:
99
+ return Modes[MULTIPLE_ASSIGNED_MODE.ANY];
100
+
101
+ case mode > 0:
102
+ return Modes[MULTIPLE_ASSIGNED_MODE.ALL_PERCENTAGE];
103
+
104
+ case mode < 0:
105
+ return Modes[MULTIPLE_ASSIGNED_MODE.ANY_PERCENTAGE];
106
+
107
+ default:
108
+ return Modes[MULTIPLE_ASSIGNED_MODE.SINGLE];
109
+ }
110
+ }
111
+
112
+ class _default {
113
+ constructor(plugin) {
114
+ this.plugin = void 0;
115
+ this.plugin = plugin;
116
+ plugin.db.collection(_users_jobs.default);
117
+ plugin.db.extendCollection(_users.default);
118
+ plugin.db.extendCollection(_jobs.default);
119
+ plugin.app.resource({
120
+ name: 'users_jobs',
121
+ actions: {
122
+ list: {
123
+ filter: {
124
+ $or: [{
125
+ 'workflow.enabled': true
126
+ }, {
127
+ 'workflow.enabled': false,
128
+ status: {
129
+ $ne: _constants.JOB_STATUS.PENDING
130
+ }
131
+ }]
132
+ },
133
+ handler: _actions().default.list
134
+ },
135
+ submit: _actions2.submit
136
+ }
137
+ });
138
+ }
139
+
140
+ run(node, prevJob, processor) {
141
+ return _asyncToGenerator(function* () {
142
+ var _prevJob$id;
143
+
144
+ const _node$config = node.config,
145
+ mode = _node$config.mode,
146
+ config = _objectWithoutProperties(_node$config, _excluded);
147
+
148
+ const assignees = [...new Set(processor.getParsedValue(config.assignees) || [])];
149
+ const job = yield processor.saveJob({
150
+ status: _constants.JOB_STATUS.PENDING,
151
+ result: mode ? [] : null,
152
+ nodeId: node.id,
153
+ upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
154
+ }); // NOTE: batch create users jobs
155
+
156
+ const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
157
+ yield UserJobModel.bulkCreate(assignees.map(userId => ({
158
+ userId,
159
+ jobId: job.id,
160
+ nodeId: node.id,
161
+ executionId: job.executionId,
162
+ workflowId: node.workflowId,
163
+ status: _constants.JOB_STATUS.PENDING
164
+ })), {
165
+ transaction: processor.transaction
166
+ });
167
+ return job;
168
+ })();
169
+ }
170
+
171
+ resume(node, job, processor) {
172
+ return _asyncToGenerator(function* () {
173
+ var _job$latestUserJob$re, _job$latestUserJob, _getMode$getStatus;
174
+
175
+ // NOTE: check all users jobs related if all done then continue as parallel
176
+ const _node$config2 = node.config,
177
+ _node$config2$assigne = _node$config2.assignees,
178
+ assignees = _node$config2$assigne === void 0 ? [] : _node$config2$assigne,
179
+ mode = _node$config2.mode;
180
+ const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
181
+ const distribution = yield UserJobModel.count({
182
+ where: {
183
+ jobId: job.id
184
+ },
185
+ group: ['status']
186
+ });
187
+ const submitted = distribution.reduce((count, item) => item.status !== _constants.JOB_STATUS.PENDING ? count + item.count : count, 0);
188
+ const result = mode ? (submitted || 0) / assignees.length : (_job$latestUserJob$re = (_job$latestUserJob = job.latestUserJob) === null || _job$latestUserJob === void 0 ? void 0 : _job$latestUserJob.result) !== null && _job$latestUserJob$re !== void 0 ? _job$latestUserJob$re : job.result;
189
+ job.set({
190
+ status: job.status || ((_getMode$getStatus = getMode(mode).getStatus(distribution, assignees)) !== null && _getMode$getStatus !== void 0 ? _getMode$getStatus : _constants.JOB_STATUS.PENDING),
191
+ result
192
+ });
193
+ return job;
194
+ })();
195
+ }
196
+
197
+ }
198
+
199
+ exports.default = _default;
200
+ ;
@@ -20,12 +20,14 @@ exports.PARALLEL_MODE = PARALLEL_MODE;
20
20
  const Modes = {
21
21
  [PARALLEL_MODE.ALL]: {
22
22
  next(previous) {
23
- return previous.status !== _constants.JOB_STATUS.REJECTED;
23
+ return previous.status >= _constants.JOB_STATUS.PENDING;
24
24
  },
25
25
 
26
26
  getStatus(result) {
27
- if (result.some(status => status != null && status === _constants.JOB_STATUS.REJECTED)) {
28
- return _constants.JOB_STATUS.REJECTED;
27
+ const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
28
+
29
+ if (typeof failedStatus !== 'undefined') {
30
+ return failedStatus;
29
31
  }
30
32
 
31
33
  if (result.every(status => status != null && status === _constants.JOB_STATUS.RESOLVED)) {
@@ -38,7 +40,7 @@ const Modes = {
38
40
  },
39
41
  [PARALLEL_MODE.ANY]: {
40
42
  next(previous) {
41
- return previous.status !== _constants.JOB_STATUS.RESOLVED;
43
+ return previous.status <= _constants.JOB_STATUS.PENDING;
42
44
  },
43
45
 
44
46
  getStatus(result) {
@@ -50,7 +52,7 @@ const Modes = {
50
52
  return _constants.JOB_STATUS.PENDING;
51
53
  }
52
54
 
53
- return _constants.JOB_STATUS.REJECTED;
55
+ return _constants.JOB_STATUS.FAILED;
54
56
  }
55
57
 
56
58
  },
@@ -64,8 +66,10 @@ const Modes = {
64
66
  return _constants.JOB_STATUS.RESOLVED;
65
67
  }
66
68
 
67
- if (result.some(status => status != null && status === _constants.JOB_STATUS.REJECTED)) {
68
- return _constants.JOB_STATUS.REJECTED;
69
+ const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
70
+
71
+ if (typeof failedStatus !== 'undefined') {
72
+ return failedStatus;
69
73
  }
70
74
 
71
75
  return _constants.JOB_STATUS.PENDING;
@@ -1,17 +1,18 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { Instruction } from './index';
3
+ import Processor from '../Processor';
4
+ import FlowNodeModel from '../models/FlowNode';
3
5
  export interface Header {
4
6
  name: string;
5
7
  value: string;
6
8
  }
7
- export declare type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'data' | 'timeout'> & {
9
+ export declare type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'params' | 'data' | 'timeout'> & {
8
10
  headers: Array<Header>;
9
11
  ignoreFail: boolean;
10
12
  };
11
13
  export default class implements Instruction {
12
14
  plugin: any;
13
15
  constructor(plugin: any);
14
- request: (node: any, job: any, processor: any) => Promise<any>;
15
- run(node: any, input: any, processor: any): Promise<any>;
16
- resume(node: any, job: any, processor: any): Promise<any>;
16
+ run(node: FlowNodeModel, input: any, processor: Processor): Promise<any>;
17
+ resume(node: FlowNodeModel, job: any, processor: Processor): Promise<any>;
17
18
  }
@@ -5,16 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- function _ejs() {
9
- const data = require("ejs");
10
-
11
- _ejs = function _ejs() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
8
  function _axios() {
19
9
  const data = _interopRequireDefault(require("axios"));
20
10
 
@@ -33,91 +23,82 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
33
23
 
34
24
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
35
25
 
36
- class _default {
37
- constructor(plugin) {
38
- var _this = this;
26
+ function request(_x) {
27
+ return _request.apply(this, arguments);
28
+ }
39
29
 
40
- this.plugin = void 0;
30
+ function _request() {
31
+ _request = _asyncToGenerator(function* (config) {
32
+ var _config$headers, _config$params;
33
+
34
+ // default headers
35
+ const url = config.url,
36
+ _config$method = config.method,
37
+ method = _config$method === void 0 ? 'POST' : _config$method,
38
+ data = config.data,
39
+ _config$timeout = config.timeout,
40
+ timeout = _config$timeout === void 0 ? 5000 : _config$timeout;
41
+ const headers = ((_config$headers = config.headers) !== null && _config$headers !== void 0 ? _config$headers : []).reduce((result, header) => {
42
+ if (header.name.toLowerCase() === 'content-type') {
43
+ return result;
44
+ }
41
45
 
42
- this.request = /*#__PURE__*/function () {
43
- var _ref = _asyncToGenerator(function* (node, job, processor) {
44
- const templateVars = {
45
- node: processor.jobsMapByNodeId,
46
- ctx: processor.execution.context,
47
- $jobsMapByNodeId: processor.jobsMapByNodeId,
48
- $context: processor.execution.context
49
- };
50
- const requestConfig = node.config; // default headers
51
-
52
- const headers = {
53
- 'Content-Type': 'application/json'
54
- };
55
- const _requestConfig$header = requestConfig.headers,
56
- headerArr = _requestConfig$header === void 0 ? [] : _requestConfig$header,
57
- _requestConfig$method = requestConfig.method,
58
- method = _requestConfig$method === void 0 ? 'POST' : _requestConfig$method,
59
- _requestConfig$timeou = requestConfig.timeout,
60
- timeout = _requestConfig$timeou === void 0 ? 5000 : _requestConfig$timeou;
61
- headerArr.forEach(header => headers[header.name] = header.value);
62
- let url, data;
63
-
64
- try {
65
- url = yield (0, _ejs().render)(requestConfig.url.trim(), templateVars, {
66
- async: true
67
- });
68
- data = requestConfig.data ? yield (0, _ejs().render)(requestConfig.data.trim(), templateVars, {
69
- async: true
70
- }) : undefined;
71
- } catch (error2) {
72
- // console.error(error2);
73
- job.set({
74
- status: _constants.JOB_STATUS.REJECTED,
75
- result: error2.message
76
- });
77
- }
78
-
79
- try {
80
- const response = yield _axios().default.request({
81
- url,
82
- method,
83
- headers,
84
- data,
85
- timeout
86
- });
87
- job.set({
88
- status: _constants.JOB_STATUS.RESOLVED,
89
- result: response.data
90
- });
91
- } catch (error1) {
92
- // console.error('axios error?', error1);
93
- job.set({
94
- status: _constants.JOB_STATUS.REJECTED,
95
- result: error1.isAxiosError ? error1.toJSON() : error1.message
96
- });
97
- }
98
-
99
- return _this.plugin.resume(job);
46
+ return Object.assign(result, {
47
+ [header.name]: header.value
100
48
  });
49
+ }, {});
50
+ const params = ((_config$params = config.params) !== null && _config$params !== void 0 ? _config$params : []).reduce((result, param) => Object.assign(result, {
51
+ [param.name]: param.value
52
+ }), {}); // TODO(feat): only support JSON type for now, should support others in future
53
+
54
+ headers['Content-Type'] = 'application/json';
55
+ return _axios().default.request({
56
+ url,
57
+ method,
58
+ headers,
59
+ params,
60
+ data,
61
+ timeout
62
+ });
63
+ });
64
+ return _request.apply(this, arguments);
65
+ }
101
66
 
102
- return function (_x, _x2, _x3) {
103
- return _ref.apply(this, arguments);
104
- };
105
- }();
67
+ ;
106
68
 
69
+ class _default {
70
+ constructor(plugin) {
71
+ this.plugin = void 0;
107
72
  this.plugin = plugin;
108
73
  }
109
74
 
110
75
  run(node, input, processor) {
111
- var _this2 = this;
76
+ var _this = this;
112
77
 
113
78
  return _asyncToGenerator(function* () {
114
79
  const job = yield processor.saveJob({
115
80
  status: _constants.JOB_STATUS.PENDING,
116
81
  nodeId: node.id
117
82
  });
118
- setTimeout(() => {
119
- _this2.request(node, job, processor);
83
+ const config = processor.getParsedValue(node.config);
84
+ request(config).then(response => {
85
+ job.set({
86
+ status: _constants.JOB_STATUS.RESOLVED,
87
+ result: response.data
88
+ });
89
+ }).catch(error => {
90
+ job.set({
91
+ status: _constants.JOB_STATUS.FAILED,
92
+ result: error.isAxiosError ? error.toJSON() : error.message
93
+ });
94
+ }).finally(() => {
95
+ _this.plugin.app.logger.info(`[Workflow] request (#${node.id}) response received, status: ${job.get('status')}`);
96
+
97
+ _this.plugin.resume(job);
120
98
  });
99
+
100
+ _this.plugin.app.logger.info(`[Workflow] request (#${node.id}) sent to "${config.url}", waiting for response...`);
101
+
121
102
  return job;
122
103
  })();
123
104
  }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _server() {
9
+ const data = require("@nocobase/server");
10
+
11
+ _server = function _server() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+
22
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
+
24
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
+
26
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
+
28
+ const EJS_RE = /"?<%=\s*(ctx|node)([\w\.\[\]-]+)\s*.*%>"?/;
29
+
30
+ function migrateData(input) {
31
+ if (typeof input !== 'string') {
32
+ return input;
33
+ }
34
+
35
+ if (!input) {
36
+ return null;
37
+ }
38
+
39
+ const typeMap = {
40
+ ctx: '$context',
41
+ node: '$jobsMapByNodeId'
42
+ };
43
+ return input.replace(EJS_RE, (_, type, path) => {
44
+ if (type === 'ctx') {
45
+ return `"{{$context${path}}}"`;
46
+ }
47
+
48
+ if (type === 'node') {
49
+ return `"{{$jobsMapByNodeId${path.replace('[', '.').replace(']', '.').replace(/\.$/, '')}}}"`;
50
+ }
51
+
52
+ return _;
53
+ });
54
+ }
55
+
56
+ class _default extends _server().Migration {
57
+ up() {
58
+ var _this = this;
59
+
60
+ return _asyncToGenerator(function* () {
61
+ const match = yield _this.app.version.satisfies('<0.9.0-alpha.3');
62
+
63
+ if (!match) {
64
+ return;
65
+ }
66
+
67
+ const NodeRepo = _this.context.db.getRepository('flow_nodes');
68
+
69
+ yield _this.context.db.sequelize.transaction( /*#__PURE__*/function () {
70
+ var _ref = _asyncToGenerator(function* (transaction) {
71
+ const nodes = yield NodeRepo.find({
72
+ filter: {
73
+ type: 'request'
74
+ },
75
+ transaction
76
+ });
77
+ console.log('%d nodes need to be migrated.', nodes.length);
78
+ yield nodes.reduce((promise, node) => promise.then( /*#__PURE__*/_asyncToGenerator(function* () {
79
+ if (typeof node.config.data !== 'string') {
80
+ return;
81
+ }
82
+
83
+ let data = migrateData(node.config.data);
84
+
85
+ try {
86
+ data = JSON.parse(node.config.data);
87
+ return node.update({
88
+ config: _objectSpread(_objectSpread({}, node.config), {}, {
89
+ data
90
+ })
91
+ }, {
92
+ transaction
93
+ });
94
+ } catch (error) {
95
+ console.error(`flow_node #${node.id} config migrating failed! you should migrate its format from ejs to json-templates manually in your db.`);
96
+ }
97
+ })), Promise.resolve());
98
+ });
99
+
100
+ return function (_x) {
101
+ return _ref.apply(this, arguments);
102
+ };
103
+ }());
104
+ })();
105
+ }
106
+
107
+ down() {
108
+ return _asyncToGenerator(function* () {})();
109
+ }
110
+
111
+ }
112
+
113
+ exports.default = _default;
@@ -0,0 +1,4 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class extends Migration {
3
+ up(): Promise<void>;
4
+ }