@ixo/editor 6.15.0 → 6.16.0

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.
@@ -984,18 +984,51 @@ function buildServicesFromHandlers(handlers) {
984
984
 
985
985
  // src/core/lib/xeroWorkItems.ts
986
986
  var XERO_WORK_ITEMS_MAP_NAME = "xeroWorkItems";
987
+ var XERO_WORK_TERMINAL_MAP_NAME = "xeroWorkItemsTerminal";
987
988
  function getXeroWorkItemsMap(doc) {
988
989
  return doc.getMap(XERO_WORK_ITEMS_MAP_NAME);
989
990
  }
991
+ function getXeroWorkTerminalMap(doc) {
992
+ return doc.getMap(XERO_WORK_TERMINAL_MAP_NAME);
993
+ }
994
+ function terminalMapFor(map) {
995
+ return map?.doc ? getXeroWorkTerminalMap(map.doc) : null;
996
+ }
997
+ function resolveItem(terminal, item) {
998
+ const record = terminal?.get(item.id);
999
+ if (!record || item.status === "completed") return item;
1000
+ return {
1001
+ ...item,
1002
+ status: "completed",
1003
+ error: void 0,
1004
+ ...record.reviewPayload !== void 0 ? { reviewPayload: record.reviewPayload } : {},
1005
+ ...record.submittedPayload !== void 0 ? { submittedPayload: record.submittedPayload } : {},
1006
+ ...record.result !== void 0 ? { result: record.result } : {},
1007
+ completedAt: record.completedAt,
1008
+ ...record.completedByDid !== void 0 ? { completedByDid: record.completedByDid } : {}
1009
+ };
1010
+ }
1011
+ function ensureTerminalRecord(terminal, item) {
1012
+ if (!terminal || terminal.get(item.id)) return;
1013
+ terminal.set(item.id, {
1014
+ itemId: item.id,
1015
+ ...item.reviewPayload !== void 0 ? { reviewPayload: item.reviewPayload } : {},
1016
+ ...item.submittedPayload !== void 0 ? { submittedPayload: item.submittedPayload } : {},
1017
+ ...item.result !== void 0 ? { result: item.result } : {},
1018
+ completedAt: item.completedAt ?? Date.now(),
1019
+ ...item.completedByDid !== void 0 ? { completedByDid: item.completedByDid } : {}
1020
+ });
1021
+ }
990
1022
  function getEditorXeroWorkItemsMap(editor) {
991
1023
  return editor?._yXeroWorkItems || null;
992
1024
  }
993
1025
  function readMapItems(map) {
994
1026
  if (!map) return [];
1027
+ const terminal = terminalMapFor(map);
995
1028
  const items = [];
996
1029
  map.forEach((value) => {
997
1030
  if (value && typeof value === "object" && "id" in value) {
998
- items.push({ ...value });
1031
+ items.push(resolveItem(terminal, { ...value }));
999
1032
  }
1000
1033
  });
1001
1034
  return items;
@@ -1039,18 +1072,25 @@ function upsertXeroWorkItem(map, next) {
1039
1072
  if (!map) {
1040
1073
  return next;
1041
1074
  }
1075
+ const terminal = terminalMapFor(map);
1042
1076
  let existing;
1043
1077
  map.forEach((item) => {
1044
1078
  if (item?.idempotencyKey === next.idempotencyKey) existing = item;
1045
1079
  });
1046
- const stored = existing ? mergeItem(existing, next) : next;
1047
- map.set(stored.id, stored);
1080
+ const stored = existing ? mergeItem(resolveItem(terminal, existing), next) : next;
1081
+ const write = () => {
1082
+ map.set(stored.id, stored);
1083
+ if (stored.status === "completed") ensureTerminalRecord(terminal, stored);
1084
+ };
1085
+ if (map.doc) map.doc.transact(write);
1086
+ else write();
1048
1087
  return stored;
1049
1088
  }
1050
1089
  function updateXeroWorkReviewPayload(map, itemId, reviewPayload) {
1051
1090
  if (!map) return null;
1052
- const item = map.get(itemId);
1053
- if (!item) return null;
1091
+ const raw = map.get(itemId);
1092
+ if (!raw) return null;
1093
+ const item = resolveItem(terminalMapFor(map), raw);
1054
1094
  if (item.status === "completed") return item;
1055
1095
  const updatedItem = { ...item, reviewPayload };
1056
1096
  map.set(itemId, updatedItem);
@@ -1058,8 +1098,9 @@ function updateXeroWorkReviewPayload(map, itemId, reviewPayload) {
1058
1098
  }
1059
1099
  function markXeroWorkFailed(map, itemId, params) {
1060
1100
  if (!map) return null;
1061
- const item = map.get(itemId);
1062
- if (!item) return null;
1101
+ const raw = map.get(itemId);
1102
+ if (!raw) return null;
1103
+ const item = resolveItem(terminalMapFor(map), raw);
1063
1104
  if (item.status === "completed") return item;
1064
1105
  const at = params.at ?? Date.now();
1065
1106
  const updatedItem = {
@@ -1074,8 +1115,9 @@ function markXeroWorkFailed(map, itemId, params) {
1074
1115
  }
1075
1116
  function markXeroWorkApproved(map, itemId, params) {
1076
1117
  if (!map) return null;
1077
- const item = map.get(itemId);
1078
- if (!item) return null;
1118
+ const raw = map.get(itemId);
1119
+ if (!raw) return null;
1120
+ const item = resolveItem(terminalMapFor(map), raw);
1079
1121
  if (item.status === "approved" || item.status === "completed" || item.status === "cancelled") return item;
1080
1122
  const at = params.at ?? Date.now();
1081
1123
  const updatedItem = {
@@ -1090,8 +1132,10 @@ function markXeroWorkApproved(map, itemId, params) {
1090
1132
  }
1091
1133
  function markXeroWorkCompleted(map, itemId, params) {
1092
1134
  if (!map) return null;
1093
- const item = map.get(itemId);
1094
- if (!item) return null;
1135
+ const raw = map.get(itemId);
1136
+ if (!raw) return null;
1137
+ const terminal = terminalMapFor(map);
1138
+ const item = resolveItem(terminal, raw);
1095
1139
  if (item.status === "completed") return item;
1096
1140
  const at = params.at ?? Date.now();
1097
1141
  const updatedItem = {
@@ -1105,7 +1149,12 @@ function markXeroWorkCompleted(map, itemId, params) {
1105
1149
  completedByDid: params.byDid,
1106
1150
  attempts: [...item.attempts ?? [], { at, byDid: params.byDid, payload: params.payload, result: params.result }]
1107
1151
  };
1108
- map.set(itemId, updatedItem);
1152
+ const write = () => {
1153
+ map.set(itemId, updatedItem);
1154
+ ensureTerminalRecord(terminal, updatedItem);
1155
+ };
1156
+ if (map.doc) map.doc.transact(write);
1157
+ else write();
1109
1158
  return updatedItem;
1110
1159
  }
1111
1160
  function findXeroWorkItemsForEditor(editor, filter) {
@@ -11126,6 +11175,7 @@ var buildFlowNodeFromBlock = (block) => {
11126
11175
 
11127
11176
  // src/core/lib/flowEngine/runtime.ts
11128
11177
  var XERO_WORK_ITEMS_MAP_NAME2 = "xeroWorkItems";
11178
+ var XERO_WORK_TERMINAL_MAP_NAME2 = "xeroWorkItemsTerminal";
11129
11179
  var XERO_CONNECTION_MAP_NAME = "xeroConnection";
11130
11180
  var ensureStateObject = (value) => {
11131
11181
  if (!value || typeof value !== "object") {
@@ -11172,6 +11222,7 @@ function clearRuntimeForTemplateClone(yDoc) {
11172
11222
  const agentLeases = yDoc.getMap("agentLeases");
11173
11223
  const auditTrail = yDoc.getMap("auditTrail");
11174
11224
  const xeroWorkItems = yDoc.getMap(XERO_WORK_ITEMS_MAP_NAME2);
11225
+ const xeroWorkTerminal = yDoc.getMap(XERO_WORK_TERMINAL_MAP_NAME2);
11175
11226
  const xeroConnection = yDoc.getMap(XERO_CONNECTION_MAP_NAME);
11176
11227
  yDoc.transact(() => {
11177
11228
  runtime.forEach((_, key) => runtime.delete(key));
@@ -11181,6 +11232,7 @@ function clearRuntimeForTemplateClone(yDoc) {
11181
11232
  agentLeases.forEach((_, key) => agentLeases.delete(key));
11182
11233
  auditTrail.forEach((_, key) => auditTrail.delete(key));
11183
11234
  xeroWorkItems.forEach((_, key) => xeroWorkItems.delete(key));
11235
+ xeroWorkTerminal.forEach((_, key) => xeroWorkTerminal.delete(key));
11184
11236
  xeroConnection.forEach((_, key) => xeroConnection.delete(key));
11185
11237
  });
11186
11238
  }
@@ -15008,7 +15060,9 @@ export {
15008
15060
  extractDid,
15009
15061
  extractSurveyAnswerSchema,
15010
15062
  XERO_WORK_ITEMS_MAP_NAME,
15063
+ XERO_WORK_TERMINAL_MAP_NAME,
15011
15064
  getXeroWorkItemsMap,
15065
+ getXeroWorkTerminalMap,
15012
15066
  buildXeroInvoiceWorkKey,
15013
15067
  buildXeroPaymentWorkKey,
15014
15068
  findXeroWorkItems,
@@ -15150,4 +15204,4 @@ export {
15150
15204
  executeQueuedFlowAgentCoreCommands,
15151
15205
  FlowAgentService
15152
15206
  };
15153
- //# sourceMappingURL=chunk-WSRVRHND.js.map
15207
+ //# sourceMappingURL=chunk-TFY73KIE.js.map