@haiiro/docuflow 0.0.7 → 0.0.9
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/README.md +25 -11
- package/manifest.json +37 -33
- package/package.json +1 -1
- package/src/front-components/docflow-documents.front-component.mjs +26 -26
- package/src/front-components/docflow-documents.front-component.tsx +24 -8
- package/src/front-components/docflow-processes.front-component.mjs +23 -23
- package/src/front-components/docflow-processes.front-component.tsx +27 -3
- package/src/front-components/docflow-tasks.front-component.mjs +32 -32
- package/src/front-components/docflow-tasks.front-component.tsx +16 -4
- package/src/front-components/process-steps.front-component.mjs +21 -21
- package/src/front-components/process-steps.front-component.tsx +36 -13
- package/src/logic-functions/hand-out-form-step.logic-function.mjs +6 -1
- package/src/logic-functions/launch-parameters-step.logic-function.mjs +1 -15
- package/src/logic-functions/launch-parameters-step.logic-function.ts +4 -18
- package/src/logic-functions/on-workflow-run-updated.logic-function.mjs +6 -1
- package/src/logic-functions/save-launch-fields.logic-function.mjs +72 -106
- package/src/logic-functions/save-launch-fields.logic-function.ts +9 -9
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { defineFrontComponent } from 'twenty-sdk/define';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AppPath,
|
|
5
|
+
closeSidePanel,
|
|
6
|
+
enqueueSnackbar,
|
|
7
|
+
navigate,
|
|
8
|
+
useSelectedRecordIds,
|
|
9
|
+
} from 'twenty-sdk/front-component';
|
|
4
10
|
import { Button } from 'twenty-ui/primitives/input';
|
|
5
11
|
import { useTheme } from 'twenty-ui/theme';
|
|
6
12
|
|
|
@@ -19,11 +25,11 @@ import {
|
|
|
19
25
|
} from 'src/front/ui/components';
|
|
20
26
|
import { FormFieldsBuilder } from 'src/front/ui/form-fields-builder';
|
|
21
27
|
import { restAnd, restEq } from 'src/shared/api/rest-filter.util';
|
|
22
|
-
import {
|
|
28
|
+
import { LAUNCH_TRIGGER_NAME, TRIGGER_STEP_ID } from 'src/shared/docflow.constants';
|
|
23
29
|
import { type FormField } from 'src/shared/form/form-field.type';
|
|
24
30
|
import { getFillableFormFields, getFormFieldsError, parseFormFields } from 'src/shared/form/form-fields.util';
|
|
25
31
|
import { readStepSettings, type StepSettings } from 'src/shared/form/step-settings.util';
|
|
26
|
-
import {
|
|
32
|
+
import { parseLaunchFields } from 'src/shared/workflow/launch-step.util';
|
|
27
33
|
import { type WorkflowStep } from 'src/shared/workflow/workflow-run.type';
|
|
28
34
|
import { getFormStepFields, isFormStep } from 'src/shared/workflow/workflow-run.util';
|
|
29
35
|
import { logDocflow, logDocflowError } from 'src/shared/log.util';
|
|
@@ -36,15 +42,32 @@ type ProcessRecord = { id: string; smbLaunchFields?: unknown };
|
|
|
36
42
|
|
|
37
43
|
const sectionStyle = { display: 'flex', flexDirection: 'column' as const };
|
|
38
44
|
|
|
45
|
+
// The workflow editor reads a version once when it opens and keeps it: it is
|
|
46
|
+
// not told that the server changed the trigger, so the new parameters would
|
|
47
|
+
// show up as variables only after a reload. Opening the process again (out
|
|
48
|
+
// and back, without history entries) makes the editor read the draft afresh.
|
|
49
|
+
const reopenWorkflowEditor = async (workflowId: string) => {
|
|
50
|
+
try {
|
|
51
|
+
await closeSidePanel();
|
|
52
|
+
await navigate(AppPath.RecordIndexPage, { objectNamePlural: 'workflows' }, undefined, { replace: true });
|
|
53
|
+
await navigate(
|
|
54
|
+
AppPath.RecordShowPage,
|
|
55
|
+
{ objectNameSingular: 'workflow', objectRecordId: workflowId },
|
|
56
|
+
undefined,
|
|
57
|
+
{ replace: true },
|
|
58
|
+
);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logDocflowError('process: editor not reopened', error, { workflowId });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
39
64
|
const LaunchParametersEditor = ({
|
|
40
65
|
workflowId,
|
|
41
66
|
initialFields,
|
|
42
|
-
launchStepId,
|
|
43
67
|
onSaved,
|
|
44
68
|
}: {
|
|
45
69
|
workflowId: string;
|
|
46
70
|
initialFields: FormField[];
|
|
47
|
-
launchStepId: string | undefined;
|
|
48
71
|
onSaved: () => void;
|
|
49
72
|
}) => {
|
|
50
73
|
const theme = useTheme();
|
|
@@ -72,11 +95,12 @@ const LaunchParametersEditor = ({
|
|
|
72
95
|
await enqueueSnackbar({
|
|
73
96
|
message:
|
|
74
97
|
fields.length > 0
|
|
75
|
-
? `Параметры сохранены:
|
|
98
|
+
? `Параметры сохранены: процесс начинается с «${LAUNCH_TRIGGER_NAME}», опубликуйте его`
|
|
76
99
|
: 'Параметры убраны',
|
|
77
100
|
variant: 'success',
|
|
78
101
|
});
|
|
79
102
|
onSaved();
|
|
103
|
+
await reopenWorkflowEditor(workflowId);
|
|
80
104
|
} catch (error) {
|
|
81
105
|
logDocflowError('process: save launch fields failed', error, { workflowId });
|
|
82
106
|
setErrorMessage(getErrorMessage(error, 'Не удалось сохранить параметры'));
|
|
@@ -86,17 +110,17 @@ const LaunchParametersEditor = ({
|
|
|
86
110
|
};
|
|
87
111
|
|
|
88
112
|
return (
|
|
89
|
-
<section style={{ ...sectionStyle, gap: theme.spacing[2] }} aria-label=
|
|
90
|
-
<SectionTitle
|
|
113
|
+
<section style={{ ...sectionStyle, gap: theme.spacing[2] }} aria-label="Параметры запуска">
|
|
114
|
+
<SectionTitle>Параметры запуска</SectionTitle>
|
|
91
115
|
<Message tone="hint">
|
|
92
|
-
Что человек заполняет перед запуском.
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
Что человек заполняет перед запуском. Первым блоком процесса становится «{LAUNCH_TRIGGER_NAME}»:
|
|
117
|
+
в следующих шагах значения выбираются как его переменные, например сотрудник — в поле
|
|
118
|
+
«Исполнитель». Без параметров процесс начинается с обычного «Запуск вручную».
|
|
95
119
|
</Message>
|
|
96
120
|
<FormFieldsBuilder
|
|
97
121
|
fields={fields}
|
|
98
122
|
onChange={setFields}
|
|
99
|
-
variablePrefix={
|
|
123
|
+
variablePrefix={TRIGGER_STEP_ID}
|
|
100
124
|
disabled={isSaving}
|
|
101
125
|
/>
|
|
102
126
|
{errorMessage !== undefined && <Message tone="danger">{errorMessage}</Message>}
|
|
@@ -261,7 +285,6 @@ const ProcessSteps = () => {
|
|
|
261
285
|
key={`${workflowId}:${launchEditorKey}`}
|
|
262
286
|
workflowId={workflowId}
|
|
263
287
|
initialFields={parseLaunchFields(data.process.smbLaunchFields)}
|
|
264
|
-
launchStepId={findLaunchParametersStep(draft?.steps)?.id}
|
|
265
288
|
onSaved={() => {
|
|
266
289
|
void reload().then(() => setLaunchEditorKey((current) => current + 1));
|
|
267
290
|
}}
|
|
@@ -26,6 +26,7 @@ var DOCFLOW_SECTION = "DOCFLOW";
|
|
|
26
26
|
var CRM_SECTION = "CRM";
|
|
27
27
|
var DOCFLOW_LAUNCH_PARAMETERS_KEY = "smbDocflowParameters";
|
|
28
28
|
var LAUNCH_PARAMETERS_STEP_INPUT = `{{trigger.${DOCFLOW_LAUNCH_PARAMETERS_KEY}}}`;
|
|
29
|
+
var LAUNCH_TRIGGER_NAME = "\u0417\u0430\u043F\u0443\u0441\u043A \u0441 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C\u0438";
|
|
29
30
|
var TASK_TODO_STATUS = "TODO";
|
|
30
31
|
var FORM_FIELD_ROLE_SETTING = "smbRole";
|
|
31
32
|
var FORM_FIELD_DUE_IN_DAYS_SETTING = "smbDueInDays";
|
|
@@ -73,6 +74,10 @@ var getRunTargetRecord = (state) => {
|
|
|
73
74
|
return targetFieldName !== void 0 && recordId !== void 0 ? { targetFieldName, recordId } : void 0;
|
|
74
75
|
};
|
|
75
76
|
|
|
77
|
+
// src/shared/workflow/launch-step.util.ts
|
|
78
|
+
var isLaunchTrigger = (trigger) => trigger?.type === "WEBHOOK" && trigger.name === LAUNCH_TRIGGER_NAME;
|
|
79
|
+
var isLaunchableTrigger = (trigger) => trigger?.type === "MANUAL" || isLaunchTrigger(trigger);
|
|
80
|
+
|
|
76
81
|
// src/shared/workflow/workflow-run.util.ts
|
|
77
82
|
var DAY_IN_MS = 24 * 60 * 60 * 1e3;
|
|
78
83
|
var UUID_PATTERN2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -135,7 +140,7 @@ var getFormStepTaskRequests = ({
|
|
|
135
140
|
}) => {
|
|
136
141
|
const steps = state?.flow?.steps ?? [];
|
|
137
142
|
const stepInfos = state?.stepInfos ?? {};
|
|
138
|
-
const isStartedByHand = state?.flow?.trigger
|
|
143
|
+
const isStartedByHand = isLaunchableTrigger(state?.flow?.trigger);
|
|
139
144
|
return steps.flatMap((step) => {
|
|
140
145
|
const stepInfo = stepInfos[step.id];
|
|
141
146
|
if (!isFormStep(step) || stepInfo?.status !== "PENDING" || stepInfo.error !== void 0 && stepInfo.error !== null || typeof stepInfo.threadId !== "string" || stepInfo.threadId.length === 0) {
|
|
@@ -24,7 +24,6 @@ var defineLogicFunction = __defineFactoryStub;
|
|
|
24
24
|
// src/shared/docflow.constants.ts
|
|
25
25
|
var DOCFLOW_LAUNCH_PARAMETERS_KEY = "smbDocflowParameters";
|
|
26
26
|
var LAUNCH_PARAMETERS_STEP_INPUT = `{{trigger.${DOCFLOW_LAUNCH_PARAMETERS_KEY}}}`;
|
|
27
|
-
var LAUNCH_PARAMETERS_STEP_NAME = "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0443\u0441\u043A\u0430";
|
|
28
27
|
|
|
29
28
|
// src/shared/workflow/launch-step.util.ts
|
|
30
29
|
var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -40,20 +39,7 @@ var launch_parameters_step_logic_function_default = defineLogicFunction({
|
|
|
40
39
|
name: "docflow-launch-parameters",
|
|
41
40
|
description: "\u041E\u0442\u0434\u0430\u0451\u0442 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u043C \u0448\u0430\u0433\u0430\u043C \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B, \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u043D\u044B\u0435 \u043F\u0435\u0440\u0435\u0434 \u0437\u0430\u043F\u0443\u0441\u043A\u043E\u043C \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430",
|
|
42
41
|
timeoutSeconds: 10,
|
|
43
|
-
handler
|
|
44
|
-
workflowActionTriggerSettings: {
|
|
45
|
-
label: LAUNCH_PARAMETERS_STEP_NAME,
|
|
46
|
-
icon: "IconPlayerPlay",
|
|
47
|
-
inputSchema: [
|
|
48
|
-
{
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
parameters: { type: "string", label: "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0443\u0441\u043A\u0430 (\u043F\u043E\u0434\u0441\u0442\u0430\u0432\u043B\u044F\u044E\u0442\u0441\u044F \u0441\u0430\u043C\u0438)" }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
outputSchema: [{ type: "object", properties: {} }]
|
|
56
|
-
}
|
|
42
|
+
handler
|
|
57
43
|
});
|
|
58
44
|
export {
|
|
59
45
|
launch_parameters_step_logic_function_default as default
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { defineLogicFunction } from 'twenty-sdk/define';
|
|
2
2
|
|
|
3
|
-
import { LAUNCH_PARAMETERS_STEP_NAME } from 'src/shared/docflow.constants';
|
|
4
3
|
import { readLaunchParameters } from 'src/shared/workflow/launch-step.util';
|
|
5
4
|
import { LAUNCH_PARAMETERS_STEP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/universal-identifiers';
|
|
6
5
|
|
|
7
|
-
// The
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
6
|
+
// The step that returned the launch parameters in processes from 0.0.6 and
|
|
7
|
+
// earlier. Parameters now come with the "Запуск с параметрами" trigger, so the
|
|
8
|
+
// editor no longer offers this step; the function stays for the runs of
|
|
9
|
+
// published versions that still contain it.
|
|
11
10
|
const handler = (payload: { parameters?: unknown }) =>
|
|
12
11
|
readLaunchParameters(payload.parameters);
|
|
13
12
|
|
|
@@ -17,17 +16,4 @@ export default defineLogicFunction({
|
|
|
17
16
|
description: 'Отдаёт следующим шагам параметры, заполненные перед запуском процесса',
|
|
18
17
|
timeoutSeconds: 10,
|
|
19
18
|
handler,
|
|
20
|
-
workflowActionTriggerSettings: {
|
|
21
|
-
label: LAUNCH_PARAMETERS_STEP_NAME,
|
|
22
|
-
icon: 'IconPlayerPlay',
|
|
23
|
-
inputSchema: [
|
|
24
|
-
{
|
|
25
|
-
type: 'object',
|
|
26
|
-
properties: {
|
|
27
|
-
parameters: { type: 'string', label: 'Параметры запуска (подставляются сами)' },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
outputSchema: [{ type: 'object', properties: {} }],
|
|
32
|
-
},
|
|
33
19
|
});
|
|
@@ -119324,6 +119324,7 @@ var isAppEngine = (value) => getDocflowEngine(value) === "APP";
|
|
|
119324
119324
|
// src/shared/docflow.constants.ts
|
|
119325
119325
|
var DOCFLOW_LAUNCH_PARAMETERS_KEY = "smbDocflowParameters";
|
|
119326
119326
|
var LAUNCH_PARAMETERS_STEP_INPUT = `{{trigger.${DOCFLOW_LAUNCH_PARAMETERS_KEY}}}`;
|
|
119327
|
+
var LAUNCH_TRIGGER_NAME = "\u0417\u0430\u043F\u0443\u0441\u043A \u0441 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C\u0438";
|
|
119327
119328
|
var TASK_DONE_STATUS = "DONE";
|
|
119328
119329
|
var FORM_FIELD_ROLE_SETTING = "smbRole";
|
|
119329
119330
|
var FORM_FIELD_DUE_IN_DAYS_SETTING = "smbDueInDays";
|
|
@@ -119338,6 +119339,10 @@ var parseFormFields = (value) => Array.isArray(value) ? value.filter(
|
|
|
119338
119339
|
(field) => typeof field === "object" && field !== null && typeof field.name === "string" && typeof field.label === "string" && typeof field.type === "string"
|
|
119339
119340
|
) : [];
|
|
119340
119341
|
|
|
119342
|
+
// src/shared/workflow/launch-step.util.ts
|
|
119343
|
+
var isLaunchTrigger = (trigger) => trigger?.type === "WEBHOOK" && trigger.name === LAUNCH_TRIGGER_NAME;
|
|
119344
|
+
var isLaunchableTrigger = (trigger) => trigger?.type === "MANUAL" || isLaunchTrigger(trigger);
|
|
119345
|
+
|
|
119341
119346
|
// src/shared/workflow/workflow-run.util.ts
|
|
119342
119347
|
var DAY_IN_MS = 24 * 60 * 60 * 1e3;
|
|
119343
119348
|
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -119400,7 +119405,7 @@ var getFormStepTaskRequests = ({
|
|
|
119400
119405
|
}) => {
|
|
119401
119406
|
const steps = state?.flow?.steps ?? [];
|
|
119402
119407
|
const stepInfos = state?.stepInfos ?? {};
|
|
119403
|
-
const isStartedByHand = state?.flow?.trigger
|
|
119408
|
+
const isStartedByHand = isLaunchableTrigger(state?.flow?.trigger);
|
|
119404
119409
|
return steps.flatMap((step) => {
|
|
119405
119410
|
const stepInfo = stepInfos[step.id];
|
|
119406
119411
|
if (!isFormStep(step) || stepInfo?.status !== "PENDING" || stepInfo.error !== void 0 && stepInfo.error !== null || typeof stepInfo.threadId !== "string" || stepInfo.threadId.length === 0) {
|
|
@@ -1724,9 +1724,6 @@ var callCoreGraphql = async ({
|
|
|
1724
1724
|
var UPDATE_WORKFLOW_VERSION_STEP_MUTATION = `mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {
|
|
1725
1725
|
updateWorkflowVersionStep(input: $input) { id }
|
|
1726
1726
|
}`;
|
|
1727
|
-
var CREATE_WORKFLOW_VERSION_STEP_MUTATION = `mutation CreateWorkflowVersionStep($input: CreateWorkflowVersionStepInput!) {
|
|
1728
|
-
createWorkflowVersionStep(input: $input) { __typename }
|
|
1729
|
-
}`;
|
|
1730
1727
|
var DELETE_WORKFLOW_VERSION_STEP_MUTATION = `mutation DeleteWorkflowVersionStep($input: DeleteWorkflowVersionStepInput!) {
|
|
1731
1728
|
deleteWorkflowVersionStep(input: $input) { __typename }
|
|
1732
1729
|
}`;
|
|
@@ -1760,7 +1757,7 @@ var readRestRecord = (response) => {
|
|
|
1760
1757
|
// src/shared/docflow.constants.ts
|
|
1761
1758
|
var DOCFLOW_LAUNCH_PARAMETERS_KEY = "smbDocflowParameters";
|
|
1762
1759
|
var LAUNCH_PARAMETERS_STEP_INPUT = `{{trigger.${DOCFLOW_LAUNCH_PARAMETERS_KEY}}}`;
|
|
1763
|
-
var
|
|
1760
|
+
var LAUNCH_TRIGGER_NAME = "\u0417\u0430\u043F\u0443\u0441\u043A \u0441 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C\u0438";
|
|
1764
1761
|
var FORM_FIELD_ROLE_SETTING = "smbRole";
|
|
1765
1762
|
var TRIGGER_STEP_ID = "trigger";
|
|
1766
1763
|
|
|
@@ -1800,12 +1797,10 @@ var isLaunchParametersStep = (step) => {
|
|
|
1800
1797
|
}
|
|
1801
1798
|
return isPlainRecord(input.logicFunctionInput) && input.logicFunctionInput.parameters === LAUNCH_PARAMETERS_STEP_INPUT;
|
|
1802
1799
|
};
|
|
1800
|
+
var isLaunchTrigger = (trigger) => trigger?.type === "WEBHOOK" && trigger.name === LAUNCH_TRIGGER_NAME;
|
|
1803
1801
|
var findLaunchParametersStep = (steps) => (steps ?? []).find(isLaunchParametersStep);
|
|
1804
1802
|
var parseLaunchFields = (value) => getFillableFormFields(parseFormFields(value));
|
|
1805
1803
|
|
|
1806
|
-
// src/server/launch-step.ts
|
|
1807
|
-
import { MetadataApiClient } from "twenty-client-sdk/metadata";
|
|
1808
|
-
|
|
1809
1804
|
// src/shared/form/form-field-builder.util.ts
|
|
1810
1805
|
var OUTPUT_LEAF_TYPES = {
|
|
1811
1806
|
NUMBER: "number",
|
|
@@ -1828,6 +1823,12 @@ var buildFieldsOutputSchema = (fields) => Object.fromEntries(
|
|
|
1828
1823
|
}
|
|
1829
1824
|
])
|
|
1830
1825
|
);
|
|
1826
|
+
var buildFieldsExpectedBody = (fields) => Object.fromEntries(
|
|
1827
|
+
getFillableFormFields(fields).map((field) => [
|
|
1828
|
+
field.name,
|
|
1829
|
+
field.type === "RECORD" ? { id: "" } : field.type === "NUMBER" ? 0 : ""
|
|
1830
|
+
])
|
|
1831
|
+
);
|
|
1831
1832
|
|
|
1832
1833
|
// node_modules/twenty-client-sdk/dist/chunk-Dqa2HsxW.mjs
|
|
1833
1834
|
var e = Object.create;
|
|
@@ -61215,10 +61216,6 @@ var listWorkflowVersions = async (runAs, workflowId) => readRestList(
|
|
|
61215
61216
|
})
|
|
61216
61217
|
).records;
|
|
61217
61218
|
|
|
61218
|
-
// src/universal-identifiers.ts
|
|
61219
|
-
var LAUNCH_PARAMETERS_STEP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER = "f7559a62-213e-4b1f-a142-603b463a585a";
|
|
61220
|
-
var SAVE_LAUNCH_FIELDS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER = "d2cce9f2-6ba4-415c-aa3d-5d9aba6ae89c";
|
|
61221
|
-
|
|
61222
61219
|
// src/server/launch-step.ts
|
|
61223
61220
|
var MANUAL_TRIGGER = {
|
|
61224
61221
|
name: "\u0417\u0430\u043F\u0443\u0441\u043A \u0432\u0440\u0443\u0447\u043D\u0443\u044E",
|
|
@@ -61232,18 +61229,23 @@ var MANUAL_TRIGGER = {
|
|
|
61232
61229
|
},
|
|
61233
61230
|
nextStepIds: []
|
|
61234
61231
|
};
|
|
61235
|
-
var
|
|
61236
|
-
|
|
61237
|
-
|
|
61238
|
-
}
|
|
61239
|
-
|
|
61240
|
-
|
|
61241
|
-
|
|
61242
|
-
|
|
61243
|
-
|
|
61232
|
+
var buildLaunchTrigger = (base, fields) => ({
|
|
61233
|
+
name: LAUNCH_TRIGGER_NAME,
|
|
61234
|
+
type: "WEBHOOK",
|
|
61235
|
+
position: base.position ?? { x: 0, y: 0 },
|
|
61236
|
+
nextStepIds: base.nextStepIds ?? [],
|
|
61237
|
+
settings: {
|
|
61238
|
+
httpMethod: "POST",
|
|
61239
|
+
authentication: "API_KEY",
|
|
61240
|
+
expectedBody: buildFieldsExpectedBody(fields),
|
|
61241
|
+
outputSchema: buildFieldsOutputSchema(fields)
|
|
61244
61242
|
}
|
|
61245
|
-
|
|
61246
|
-
|
|
61243
|
+
});
|
|
61244
|
+
var buildManualTrigger = (base) => ({
|
|
61245
|
+
...MANUAL_TRIGGER,
|
|
61246
|
+
position: base.position ?? MANUAL_TRIGGER.position,
|
|
61247
|
+
nextStepIds: base.nextStepIds ?? []
|
|
61248
|
+
});
|
|
61247
61249
|
var findOrCreateDraft = async (workflowId) => {
|
|
61248
61250
|
const versions = await listWorkflowVersions("person", workflowId);
|
|
61249
61251
|
const draft = versions.find(({ status }) => status === "DRAFT");
|
|
@@ -61257,105 +61259,66 @@ var findOrCreateDraft = async (workflowId) => {
|
|
|
61257
61259
|
return (await listWorkflowVersions("person", workflowId)).find(({ status }) => status === "DRAFT");
|
|
61258
61260
|
};
|
|
61259
61261
|
var STEP_ROW_HEIGHT = 150;
|
|
61260
|
-
var
|
|
61261
|
-
const
|
|
61262
|
-
|
|
61262
|
+
var retargetStepVariables = (step, launchStepId) => {
|
|
61263
|
+
const settings = JSON.stringify(step.settings ?? {});
|
|
61264
|
+
const retargeted = settings.split(`{{${launchStepId}.`).join(`{{${TRIGGER_STEP_ID}.`);
|
|
61265
|
+
return retargeted === settings ? void 0 : { ...step, settings: JSON.parse(retargeted) };
|
|
61263
61266
|
};
|
|
61264
|
-
var
|
|
61265
|
-
const
|
|
61266
|
-
|
|
61267
|
+
var removeLegacyLaunchStep = async (draft) => {
|
|
61268
|
+
const launchStep = findLaunchParametersStep(draft.steps);
|
|
61269
|
+
if (launchStep === void 0) {
|
|
61270
|
+
return;
|
|
61271
|
+
}
|
|
61272
|
+
await callCoreGraphql({
|
|
61273
|
+
query: DELETE_WORKFLOW_VERSION_STEP_MUTATION,
|
|
61274
|
+
variables: { input: { workflowVersionId: draft.id, stepId: launchStep.id } }
|
|
61275
|
+
});
|
|
61276
|
+
const removedY = launchStep.position?.y;
|
|
61267
61277
|
for (const step of draft.steps ?? []) {
|
|
61268
|
-
|
|
61269
|
-
|
|
61270
|
-
await callCoreGraphql({
|
|
61271
|
-
query: UPDATE_WORKFLOW_VERSION_STEP_MUTATION,
|
|
61272
|
-
variables: {
|
|
61273
|
-
input: {
|
|
61274
|
-
workflowVersionId: draft.id,
|
|
61275
|
-
step: { ...step, position: { ...stepPosition, y: stepPosition.y + STEP_ROW_HEIGHT } }
|
|
61276
|
-
}
|
|
61277
|
-
}
|
|
61278
|
-
});
|
|
61278
|
+
if (step.id === launchStep.id) {
|
|
61279
|
+
continue;
|
|
61279
61280
|
}
|
|
61281
|
+
const retargeted = retargetStepVariables(step, launchStep.id);
|
|
61282
|
+
const movesUp = typeof removedY === "number" && typeof step.position?.y === "number" && step.position.y > removedY;
|
|
61283
|
+
if (retargeted === void 0 && !movesUp) {
|
|
61284
|
+
continue;
|
|
61285
|
+
}
|
|
61286
|
+
const updated = retargeted ?? step;
|
|
61287
|
+
await callCoreGraphql({
|
|
61288
|
+
query: UPDATE_WORKFLOW_VERSION_STEP_MUTATION,
|
|
61289
|
+
variables: {
|
|
61290
|
+
input: {
|
|
61291
|
+
workflowVersionId: draft.id,
|
|
61292
|
+
step: movesUp && step.position ? { ...updated, position: { ...step.position, y: step.position.y - STEP_ROW_HEIGHT } } : updated
|
|
61293
|
+
}
|
|
61294
|
+
}
|
|
61295
|
+
});
|
|
61280
61296
|
}
|
|
61281
|
-
return position;
|
|
61282
61297
|
};
|
|
61283
|
-
var
|
|
61298
|
+
var syncLaunchTrigger = async ({
|
|
61284
61299
|
workflowId,
|
|
61285
61300
|
fields
|
|
61286
61301
|
}) => {
|
|
61287
|
-
|
|
61302
|
+
const draft = await findOrCreateDraft(workflowId);
|
|
61288
61303
|
if (draft === void 0) {
|
|
61289
61304
|
return void 0;
|
|
61290
61305
|
}
|
|
61291
|
-
|
|
61292
|
-
|
|
61293
|
-
query: UPDATE_WORKFLOW_VERSION_TRIGGER_MUTATION,
|
|
61294
|
-
variables: { input: { workflowVersionId: draft.id, trigger: MANUAL_TRIGGER } }
|
|
61295
|
-
});
|
|
61296
|
-
draft = { ...draft, trigger: MANUAL_TRIGGER };
|
|
61297
|
-
}
|
|
61298
|
-
if (draft.trigger?.type !== "MANUAL") {
|
|
61306
|
+
const current = draft.trigger ?? MANUAL_TRIGGER;
|
|
61307
|
+
if (current.type !== "MANUAL" && !isLaunchTrigger(current)) {
|
|
61299
61308
|
return { status: "NOT_MANUAL" };
|
|
61300
61309
|
}
|
|
61301
|
-
|
|
61302
|
-
|
|
61303
|
-
if (existingStep !== void 0) {
|
|
61304
|
-
await callCoreGraphql({
|
|
61305
|
-
query: DELETE_WORKFLOW_VERSION_STEP_MUTATION,
|
|
61306
|
-
variables: { input: { workflowVersionId: draft.id, stepId: existingStep.id } }
|
|
61307
|
-
});
|
|
61308
|
-
}
|
|
61309
|
-
return { status: "SAVED", workflowVersionId: draft.id, stepId: null };
|
|
61310
|
-
}
|
|
61311
|
-
let step = existingStep;
|
|
61312
|
-
if (step === void 0) {
|
|
61313
|
-
const stepId = crypto.randomUUID();
|
|
61314
|
-
const position = await makeRoomUnderTrigger(draft);
|
|
61315
|
-
await callCoreGraphql({
|
|
61316
|
-
query: CREATE_WORKFLOW_VERSION_STEP_MUTATION,
|
|
61317
|
-
variables: {
|
|
61318
|
-
input: {
|
|
61319
|
-
workflowVersionId: draft.id,
|
|
61320
|
-
id: stepId,
|
|
61321
|
-
stepType: "LOGIC_FUNCTION",
|
|
61322
|
-
parentStepId: TRIGGER_STEP_ID,
|
|
61323
|
-
nextStepId: draft.trigger.nextStepIds?.[0],
|
|
61324
|
-
position,
|
|
61325
|
-
defaultSettings: {
|
|
61326
|
-
input: {
|
|
61327
|
-
logicFunctionId: await findLaunchStepLogicFunctionId(),
|
|
61328
|
-
logicFunctionInput: { parameters: LAUNCH_PARAMETERS_STEP_INPUT }
|
|
61329
|
-
}
|
|
61330
|
-
}
|
|
61331
|
-
}
|
|
61332
|
-
}
|
|
61333
|
-
});
|
|
61334
|
-
const versions = await listWorkflowVersions("person", workflowId);
|
|
61335
|
-
step = versions.find(({ id: id3 }) => id3 === draft?.id)?.steps?.find(({ id: id3 }) => id3 === stepId);
|
|
61336
|
-
if (step === void 0) {
|
|
61337
|
-
throw new Error(`The launch step ${stepId} was not created`);
|
|
61338
|
-
}
|
|
61339
|
-
}
|
|
61310
|
+
await removeLegacyLaunchStep(draft);
|
|
61311
|
+
const trigger = (await listWorkflowVersions("person", workflowId)).find(({ id: id3 }) => id3 === draft.id)?.trigger ?? current;
|
|
61340
61312
|
await callCoreGraphql({
|
|
61341
|
-
query:
|
|
61313
|
+
query: UPDATE_WORKFLOW_VERSION_TRIGGER_MUTATION,
|
|
61342
61314
|
variables: {
|
|
61343
61315
|
input: {
|
|
61344
61316
|
workflowVersionId: draft.id,
|
|
61345
|
-
|
|
61346
|
-
...step,
|
|
61347
|
-
name: LAUNCH_PARAMETERS_STEP_NAME,
|
|
61348
|
-
// A step put in by an earlier version has no place on the canvas
|
|
61349
|
-
position: readPosition(step.position) ?? await makeRoomUnderTrigger({
|
|
61350
|
-
...draft,
|
|
61351
|
-
steps: (draft.steps ?? []).filter(({ id: id3 }) => id3 !== step?.id)
|
|
61352
|
-
}),
|
|
61353
|
-
settings: { ...step.settings, outputSchema: buildFieldsOutputSchema(fields) }
|
|
61354
|
-
}
|
|
61317
|
+
trigger: fields.length > 0 ? buildLaunchTrigger(trigger, fields) : buildManualTrigger(trigger)
|
|
61355
61318
|
}
|
|
61356
61319
|
}
|
|
61357
61320
|
});
|
|
61358
|
-
return { status: "SAVED", workflowVersionId: draft.id
|
|
61321
|
+
return { status: "SAVED", workflowVersionId: draft.id };
|
|
61359
61322
|
};
|
|
61360
61323
|
|
|
61361
61324
|
// node_modules/twenty-sdk/dist/logic-function/isDefined-Dtu5EYqP-CMNeFg4z.mjs
|
|
@@ -119650,6 +119613,9 @@ var describeError = (error) => {
|
|
|
119650
119613
|
var logDocflow = (event, details) => console.info(PREFIX, event, details ?? "");
|
|
119651
119614
|
var logDocflowError = (event, error, details) => console.error(PREFIX, event, describeError(error), details ?? "");
|
|
119652
119615
|
|
|
119616
|
+
// src/universal-identifiers.ts
|
|
119617
|
+
var SAVE_LAUNCH_FIELDS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER = "d2cce9f2-6ba4-415c-aa3d-5d9aba6ae89c";
|
|
119618
|
+
|
|
119653
119619
|
// src/logic-functions/save-launch-fields.logic-function.ts
|
|
119654
119620
|
var handler = async (event) => {
|
|
119655
119621
|
const body = readJsonBody(event.body);
|
|
@@ -119671,25 +119637,25 @@ var handler = async (event) => {
|
|
|
119671
119637
|
return jsonResponse(404, { message: "\u041F\u0440\u043E\u0446\u0435\u0441\u0441 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D" });
|
|
119672
119638
|
}
|
|
119673
119639
|
try {
|
|
119674
|
-
const result = await
|
|
119640
|
+
const result = await syncLaunchTrigger({ workflowId, fields });
|
|
119675
119641
|
logDocflow("launch fields: draft synced", { workflowId, result });
|
|
119676
119642
|
if (result?.status === "NOT_MANUAL") {
|
|
119677
119643
|
return jsonResponse(409, {
|
|
119678
|
-
message: "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u043D\u043E \
|
|
119644
|
+
message: "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u043D\u043E \u0437\u0430\u043F\u0443\u0441\u043A \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430 \u043D\u0435 \u0438\u0437\u043C\u0435\u043D\u0451\u043D: \u043E\u043D \u0437\u0430\u043F\u0443\u0441\u043A\u0430\u0435\u0442\u0441\u044F \u043D\u0435 \u0432\u0440\u0443\u0447\u043D\u0443\u044E"
|
|
119679
119645
|
});
|
|
119680
119646
|
}
|
|
119681
|
-
return { status: "SAVED"
|
|
119647
|
+
return { status: "SAVED" };
|
|
119682
119648
|
} catch (error) {
|
|
119683
119649
|
logDocflowError("launch fields: draft not synced", error, { workflowId });
|
|
119684
119650
|
return jsonResponse(502, {
|
|
119685
|
-
message: error instanceof CoreGraphqlError && error.userMessage !== void 0 ? `\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \
|
|
119651
|
+
message: error instanceof CoreGraphqlError && error.userMessage !== void 0 ? `\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u0437\u0430\u043F\u0443\u0441\u043A \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430 \u043D\u0435 \u043E\u0431\u043D\u043E\u0432\u043B\u0451\u043D: ${error.userMessage}` : `\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u0437\u0430\u043F\u0443\u0441\u043A \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430 \u043D\u0435 \u043E\u0431\u043D\u043E\u0432\u043B\u0451\u043D: ${error instanceof Error ? error.message : "\u043E\u0448\u0438\u0431\u043A\u0430 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440\u0430 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u0432"}`
|
|
119686
119652
|
});
|
|
119687
119653
|
}
|
|
119688
119654
|
};
|
|
119689
119655
|
var save_launch_fields_logic_function_default = defineLogicFunction({
|
|
119690
119656
|
universalIdentifier: SAVE_LAUNCH_FIELDS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
|
|
119691
119657
|
name: "docflow-save-launch-fields",
|
|
119692
|
-
description: "\u0421\u043E\u0445\u0440\u0430\u043D\u044F\u0435\u0442 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430 \
|
|
119658
|
+
description: "\u0421\u043E\u0445\u0440\u0430\u043D\u044F\u0435\u0442 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u0438 \u0434\u0435\u043B\u0430\u0435\u0442 \u043F\u0435\u0440\u0432\u044B\u043C \u0431\u043B\u043E\u043A\u043E\u043C \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430 \xAB\u0417\u0430\u043F\u0443\u0441\u043A \u0441 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C\u0438\xBB",
|
|
119693
119659
|
timeoutSeconds: 30,
|
|
119694
119660
|
handler,
|
|
119695
119661
|
httpRouteTriggerSettings: {
|
|
@@ -5,14 +5,14 @@ import { CoreGraphqlError } from 'src/shared/api/core-graphql.util';
|
|
|
5
5
|
import { readRestRecord } from 'src/shared/api/rest-response.util';
|
|
6
6
|
import { getFormFieldsError } from 'src/shared/form/form-fields.util';
|
|
7
7
|
import { parseLaunchFields } from 'src/shared/workflow/launch-step.util';
|
|
8
|
-
import {
|
|
8
|
+
import { syncLaunchTrigger } from 'src/server/launch-step';
|
|
9
9
|
import { jsonResponse, readJsonBody } from 'src/server/http-response';
|
|
10
10
|
import { restClient } from 'src/server/records';
|
|
11
11
|
import { logDocflow, logDocflowError } from 'src/shared/log.util';
|
|
12
12
|
import { SAVE_LAUNCH_FIELDS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/universal-identifiers';
|
|
13
13
|
|
|
14
|
-
// Saves the parameters of a process and
|
|
15
|
-
// "
|
|
14
|
+
// Saves the parameters of a process and puts them into its draft as the
|
|
15
|
+
// "Запуск с параметрами" trigger, whose fields later steps read as variables.
|
|
16
16
|
const handler = async (event: RoutePayload) => {
|
|
17
17
|
const body = readJsonBody(event.body);
|
|
18
18
|
const workflowId = body.workflowId;
|
|
@@ -41,25 +41,25 @@ const handler = async (event: RoutePayload) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
try {
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await syncLaunchTrigger({ workflowId, fields });
|
|
45
45
|
|
|
46
46
|
logDocflow('launch fields: draft synced', { workflowId, result });
|
|
47
47
|
|
|
48
48
|
if (result?.status === 'NOT_MANUAL') {
|
|
49
49
|
return jsonResponse(409, {
|
|
50
|
-
message: 'Параметры сохранены, но
|
|
50
|
+
message: 'Параметры сохранены, но запуск процесса не изменён: он запускается не вручную',
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
return { status: 'SAVED'
|
|
54
|
+
return { status: 'SAVED' };
|
|
55
55
|
} catch (error) {
|
|
56
56
|
logDocflowError('launch fields: draft not synced', error, { workflowId });
|
|
57
57
|
|
|
58
58
|
return jsonResponse(502, {
|
|
59
59
|
message:
|
|
60
60
|
error instanceof CoreGraphqlError && error.userMessage !== undefined
|
|
61
|
-
? `Параметры сохранены,
|
|
62
|
-
: `Параметры сохранены,
|
|
61
|
+
? `Параметры сохранены, запуск процесса не обновлён: ${error.userMessage}`
|
|
62
|
+
: `Параметры сохранены, запуск процесса не обновлён: ${error instanceof Error ? error.message : 'ошибка редактора процессов'}`,
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
};
|
|
@@ -67,7 +67,7 @@ const handler = async (event: RoutePayload) => {
|
|
|
67
67
|
export default defineLogicFunction({
|
|
68
68
|
universalIdentifier: SAVE_LAUNCH_FIELDS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
|
|
69
69
|
name: 'docflow-save-launch-fields',
|
|
70
|
-
description: 'Сохраняет параметры запуска
|
|
70
|
+
description: 'Сохраняет параметры запуска и делает первым блоком процесса «Запуск с параметрами»',
|
|
71
71
|
timeoutSeconds: 30,
|
|
72
72
|
handler,
|
|
73
73
|
httpRouteTriggerSettings: {
|