@haiiro/docuflow 0.0.19 → 0.0.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.
@@ -119749,7 +119749,7 @@ var getCrmUrl = () => {
119749
119749
  // package.json
119750
119750
  var package_default = {
119751
119751
  name: "@haiiro/docuflow",
119752
- version: "0.0.19",
119752
+ version: "0.0.21",
119753
119753
  description: "NorDiv \u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u043E\u0431\u043E\u0440\u043E\u0442: \u0437\u0430\u0434\u0430\u043D\u0438\u044F \u0441 \u043F\u043E\u043B\u044F\u043C\u0438, \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u044B \u0441 \u0437\u0430\u043F\u0443\u0441\u043A\u043E\u043C \u043F\u043E \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C, \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u044B \u0441\u043E \u0432\u0441\u0435\u0445 \u0437\u0430\u043F\u0438\u0441\u0435\u0439, \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u0411\u0438\u0442\u0440\u0438\u043A\u044124",
119754
119754
  license: "AGPL-3.0-only",
119755
119755
  publishConfig: {
@@ -59961,7 +59961,7 @@ var AL = class {
59961
59961
  // package.json
59962
59962
  var package_default = {
59963
59963
  name: "@haiiro/docuflow",
59964
- version: "0.0.19",
59964
+ version: "0.0.21",
59965
59965
  description: "NorDiv \u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u043E\u0431\u043E\u0440\u043E\u0442: \u0437\u0430\u0434\u0430\u043D\u0438\u044F \u0441 \u043F\u043E\u043B\u044F\u043C\u0438, \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u044B \u0441 \u0437\u0430\u043F\u0443\u0441\u043A\u043E\u043C \u043F\u043E \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C, \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u044B \u0441\u043E \u0432\u0441\u0435\u0445 \u0437\u0430\u043F\u0438\u0441\u0435\u0439, \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u0411\u0438\u0442\u0440\u0438\u043A\u044124",
59966
59966
  license: "AGPL-3.0-only",
59967
59967
  publishConfig: {
@@ -119630,6 +119630,7 @@ var restClient = (runAs) => clients[runAs];
119630
119630
 
119631
119631
  // src/server/process-catalog.ts
119632
119632
  var MEMBERSHIP_KEY = "docflow-processes";
119633
+ var LAUNCH_SETTINGS_KEY = "docflow-launch-settings";
119633
119634
  var PAGE_SIZE = 200;
119634
119635
  var VERSIONS_BATCH_SIZE = 50;
119635
119636
  var readStringList = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
@@ -119637,6 +119638,10 @@ var readMembership = async () => {
119637
119638
  const stored = await kL.get(MEMBERSHIP_KEY);
119638
119639
  return { included: readStringList(stored?.included), excluded: readStringList(stored?.excluded) };
119639
119640
  };
119641
+ var readLaunchSettings = async () => {
119642
+ const stored = await kL.get(LAUNCH_SETTINGS_KEY);
119643
+ return typeof stored === "object" && stored !== null ? stored : {};
119644
+ };
119640
119645
  var readLegacyWorkflows = async (runAs) => {
119641
119646
  try {
119642
119647
  const { records } = readRestList(
@@ -119687,8 +119692,9 @@ var readVersions = async (workflowIds, runAs) => {
119687
119692
  }
119688
119693
  return result;
119689
119694
  };
119690
- var toProcess = (node, versions, legacy) => {
119691
- const savedFields = parseLaunchFields(legacy?.smbLaunchFields);
119695
+ var toProcess = (node, versions, legacy, launchSettings) => {
119696
+ const savedFields = parseLaunchFields(launchSettings?.fields ?? legacy?.smbLaunchFields);
119697
+ const savedObject = launchSettings !== void 0 ? launchSettings.launchObject : legacy?.smbLaunchObject;
119692
119698
  const active = versions?.active;
119693
119699
  return {
119694
119700
  workflowId: node.id,
@@ -119699,14 +119705,18 @@ var toProcess = (node, versions, legacy) => {
119699
119705
  // Fields saved by docflow, or for a webhook set up in the Twenty editor
119700
119706
  // the values its body expects
119701
119707
  launchFields: savedFields.length > 0 ? savedFields : parseExpectedBodyFields(active?.trigger),
119702
- launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(legacy?.smbLaunchObject) : void 0
119708
+ launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(savedObject) : void 0,
119709
+ // The draft is launched on this object once published: the settings page
119710
+ // shows what was saved, not what is published
119711
+ savedLaunchObject: parseLaunchObject(savedObject)
119703
119712
  };
119704
119713
  };
119705
119714
  var listDocflowProcesses = async (runAs = "person") => {
119706
- const [nodes, membership, legacy] = await Promise.all([
119715
+ const [nodes, membership, legacy, launchSettings] = await Promise.all([
119707
119716
  listCoreWorkflows(runAs),
119708
119717
  readMembership(),
119709
- readLegacyWorkflows(runAs)
119718
+ readLegacyWorkflows(runAs),
119719
+ readLaunchSettings()
119710
119720
  ]);
119711
119721
  const docflowNodes = nodes.filter((node) => isDocflowNode(node, membership, legacy));
119712
119722
  const versions = await readVersions(
@@ -119714,7 +119724,12 @@ var listDocflowProcesses = async (runAs = "person") => {
119714
119724
  runAs
119715
119725
  );
119716
119726
  return docflowNodes.map(
119717
- (node) => toProcess(node, versions.get(node.id), node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0)
119727
+ (node) => toProcess(
119728
+ node,
119729
+ versions.get(node.id),
119730
+ node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0,
119731
+ launchSettings[node.id]
119732
+ )
119718
119733
  );
119719
119734
  };
119720
119735
  var findDocflowProcess = async (workflowId, runAs = "person") => (await listDocflowProcesses(runAs)).find(
@@ -1691,6 +1691,7 @@ var readUserMessage = (value) => {
1691
1691
  }
1692
1692
  return void 0;
1693
1693
  };
1694
+ var isMissingGraphqlField = (error) => error instanceof CoreGraphqlError && /Cannot query field|Unknown type/i.test(error.message);
1694
1695
  var callCoreGraphql = async ({
1695
1696
  query,
1696
1697
  variables,
@@ -119538,6 +119539,7 @@ var restClient = (runAs) => clients[runAs];
119538
119539
 
119539
119540
  // src/server/process-catalog.ts
119540
119541
  var MEMBERSHIP_KEY = "docflow-processes";
119542
+ var LAUNCH_SETTINGS_KEY = "docflow-launch-settings";
119541
119543
  var PAGE_SIZE = 200;
119542
119544
  var VERSIONS_BATCH_SIZE = 50;
119543
119545
  var readStringList = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
@@ -119545,6 +119547,26 @@ var readMembership = async () => {
119545
119547
  const stored = await kL.get(MEMBERSHIP_KEY);
119546
119548
  return { included: readStringList(stored?.included), excluded: readStringList(stored?.excluded) };
119547
119549
  };
119550
+ var readLaunchSettings = async () => {
119551
+ const stored = await kL.get(LAUNCH_SETTINGS_KEY);
119552
+ return typeof stored === "object" && stored !== null ? stored : {};
119553
+ };
119554
+ var NIL_ID = "00000000-0000-0000-0000-000000000000";
119555
+ var canAppEditCache;
119556
+ var canAppEditProcesses = async () => {
119557
+ if (canAppEditCache === void 0) {
119558
+ try {
119559
+ await callCoreGraphql({
119560
+ query: "mutation($id: UUID!) { activateWorkflowVersion(workflowVersionId: $id) }",
119561
+ variables: { id: NIL_ID }
119562
+ });
119563
+ canAppEditCache = true;
119564
+ } catch (error) {
119565
+ canAppEditCache = !isMissingGraphqlField(error);
119566
+ }
119567
+ }
119568
+ return canAppEditCache;
119569
+ };
119548
119570
  var readLegacyWorkflows = async (runAs) => {
119549
119571
  try {
119550
119572
  const { records } = readRestList(
@@ -119595,8 +119617,9 @@ var readVersions = async (workflowIds, runAs) => {
119595
119617
  }
119596
119618
  return result;
119597
119619
  };
119598
- var toProcess = (node, versions, legacy) => {
119599
- const savedFields = parseLaunchFields(legacy?.smbLaunchFields);
119620
+ var toProcess = (node, versions, legacy, launchSettings) => {
119621
+ const savedFields = parseLaunchFields(launchSettings?.fields ?? legacy?.smbLaunchFields);
119622
+ const savedObject = launchSettings !== void 0 ? launchSettings.launchObject : legacy?.smbLaunchObject;
119600
119623
  const active = versions?.active;
119601
119624
  return {
119602
119625
  workflowId: node.id,
@@ -119607,14 +119630,18 @@ var toProcess = (node, versions, legacy) => {
119607
119630
  // Fields saved by docflow, or for a webhook set up in the Twenty editor
119608
119631
  // the values its body expects
119609
119632
  launchFields: savedFields.length > 0 ? savedFields : parseExpectedBodyFields(active?.trigger),
119610
- launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(legacy?.smbLaunchObject) : void 0
119633
+ launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(savedObject) : void 0,
119634
+ // The draft is launched on this object once published: the settings page
119635
+ // shows what was saved, not what is published
119636
+ savedLaunchObject: parseLaunchObject(savedObject)
119611
119637
  };
119612
119638
  };
119613
119639
  var listDocflowProcesses = async (runAs = "person") => {
119614
- const [nodes, membership, legacy] = await Promise.all([
119640
+ const [nodes, membership, legacy, launchSettings] = await Promise.all([
119615
119641
  listCoreWorkflows(runAs),
119616
119642
  readMembership(),
119617
- readLegacyWorkflows(runAs)
119643
+ readLegacyWorkflows(runAs),
119644
+ readLaunchSettings()
119618
119645
  ]);
119619
119646
  const docflowNodes = nodes.filter((node) => isDocflowNode(node, membership, legacy));
119620
119647
  const versions = await readVersions(
@@ -119622,7 +119649,12 @@ var listDocflowProcesses = async (runAs = "person") => {
119622
119649
  runAs
119623
119650
  );
119624
119651
  return docflowNodes.map(
119625
- (node) => toProcess(node, versions.get(node.id), node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0)
119652
+ (node) => toProcess(
119653
+ node,
119654
+ versions.get(node.id),
119655
+ node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0,
119656
+ launchSettings[node.id]
119657
+ )
119626
119658
  );
119627
119659
  };
119628
119660
  var listOtherProcesses = async () => {
@@ -119655,8 +119687,10 @@ var handler = async (event, context) => {
119655
119687
  const body = readJsonBody(event.body);
119656
119688
  try {
119657
119689
  switch (body.action) {
119658
- case "list":
119659
- return { processes: await listDocflowProcesses("person") };
119690
+ case "list": {
119691
+ const [processes, canAppEdit] = await Promise.all([listDocflowProcesses("person"), canAppEditProcesses()]);
119692
+ return { processes, canAppEdit };
119693
+ }
119660
119694
  case "others":
119661
119695
  return { processes: await listOtherProcesses() };
119662
119696
  case "add":
@@ -7,6 +7,7 @@ import {
7
7
  import { CoreGraphqlError } from 'src/shared/api/core-graphql.util';
8
8
  import { jsonResponse, readJsonBody, withRouteErrors } from 'src/server/http-response';
9
9
  import {
10
+ canAppEditProcesses,
10
11
  listDocflowProcesses,
11
12
  listOtherProcesses,
12
13
  setDocflowMembership,
@@ -22,7 +23,8 @@ const readIds = (value: unknown): string[] =>
22
23
  // The processes pages read docflow processes here, not from the process
23
24
  // records: Twenty 2.50 keeps processes only in its engine. Read as the
24
25
  // person, so the "Workflows" permission decides who sees them.
25
- // { action: 'list' } docflow processes with their versions
26
+ // { action: 'list' } docflow processes with their versions, and
27
+ // whether the app may change them (canAppEdit)
26
28
  // { action: 'others' } the workspace's other processes
27
29
  // { action: 'add' | 'remove', workflowIds }
28
30
  const handler = async (event: RoutePayload, context: LogicFunctionExecutionContext) => {
@@ -34,8 +36,11 @@ const handler = async (event: RoutePayload, context: LogicFunctionExecutionConte
34
36
 
35
37
  try {
36
38
  switch (body.action) {
37
- case 'list':
38
- return { processes: await listDocflowProcesses('person') };
39
+ case 'list': {
40
+ const [processes, canAppEdit] = await Promise.all([listDocflowProcesses('person'), canAppEditProcesses()]);
41
+
42
+ return { processes, canAppEdit };
43
+ }
39
44
  case 'others':
40
45
  return { processes: await listOtherProcesses() };
41
46
  case 'add':
@@ -119553,6 +119553,7 @@ var listWorkflowVersions = async (runAs, workflowId) => readRestList(
119553
119553
 
119554
119554
  // src/server/process-catalog.ts
119555
119555
  var MEMBERSHIP_KEY = "docflow-processes";
119556
+ var LAUNCH_SETTINGS_KEY = "docflow-launch-settings";
119556
119557
  var PAGE_SIZE = 200;
119557
119558
  var VERSIONS_BATCH_SIZE = 50;
119558
119559
  var readStringList = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
@@ -119560,6 +119561,10 @@ var readMembership = async () => {
119560
119561
  const stored = await kL.get(MEMBERSHIP_KEY);
119561
119562
  return { included: readStringList(stored?.included), excluded: readStringList(stored?.excluded) };
119562
119563
  };
119564
+ var readLaunchSettings = async () => {
119565
+ const stored = await kL.get(LAUNCH_SETTINGS_KEY);
119566
+ return typeof stored === "object" && stored !== null ? stored : {};
119567
+ };
119563
119568
  var readLegacyWorkflows = async (runAs) => {
119564
119569
  try {
119565
119570
  const { records } = readRestList(
@@ -119610,8 +119615,9 @@ var readVersions = async (workflowIds, runAs) => {
119610
119615
  }
119611
119616
  return result;
119612
119617
  };
119613
- var toProcess = (node, versions, legacy) => {
119614
- const savedFields = parseLaunchFields(legacy?.smbLaunchFields);
119618
+ var toProcess = (node, versions, legacy, launchSettings) => {
119619
+ const savedFields = parseLaunchFields(launchSettings?.fields ?? legacy?.smbLaunchFields);
119620
+ const savedObject = launchSettings !== void 0 ? launchSettings.launchObject : legacy?.smbLaunchObject;
119615
119621
  const active = versions?.active;
119616
119622
  return {
119617
119623
  workflowId: node.id,
@@ -119622,14 +119628,18 @@ var toProcess = (node, versions, legacy) => {
119622
119628
  // Fields saved by docflow, or for a webhook set up in the Twenty editor
119623
119629
  // the values its body expects
119624
119630
  launchFields: savedFields.length > 0 ? savedFields : parseExpectedBodyFields(active?.trigger),
119625
- launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(legacy?.smbLaunchObject) : void 0
119631
+ launchObject: isLaunchTrigger(active?.trigger) ? parseLaunchObject(savedObject) : void 0,
119632
+ // The draft is launched on this object once published: the settings page
119633
+ // shows what was saved, not what is published
119634
+ savedLaunchObject: parseLaunchObject(savedObject)
119626
119635
  };
119627
119636
  };
119628
119637
  var listDocflowProcesses = async (runAs = "person") => {
119629
- const [nodes, membership, legacy] = await Promise.all([
119638
+ const [nodes, membership, legacy, launchSettings] = await Promise.all([
119630
119639
  listCoreWorkflows(runAs),
119631
119640
  readMembership(),
119632
- readLegacyWorkflows(runAs)
119641
+ readLegacyWorkflows(runAs),
119642
+ readLaunchSettings()
119633
119643
  ]);
119634
119644
  const docflowNodes = nodes.filter((node) => isDocflowNode(node, membership, legacy));
119635
119645
  const versions = await readVersions(
@@ -119637,7 +119647,12 @@ var listDocflowProcesses = async (runAs = "person") => {
119637
119647
  runAs
119638
119648
  );
119639
119649
  return docflowNodes.map(
119640
- (node) => toProcess(node, versions.get(node.id), node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0)
119650
+ (node) => toProcess(
119651
+ node,
119652
+ versions.get(node.id),
119653
+ node.workspaceWorkflowId ? legacy.get(node.workspaceWorkflowId) : void 0,
119654
+ launchSettings[node.id]
119655
+ )
119641
119656
  );
119642
119657
  };
119643
119658
  var findDocflowProcess = async (workflowId, runAs = "person") => (await listDocflowProcesses(runAs)).find(