Skip to content

Commit 4c8234f

Browse files
committed
WIP
1 parent 3a536a3 commit 4c8234f

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

demo/api.mjs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,40 @@ export function createApi(client) {
107107
}
108108

109109
// ---------------------------------------------------------------------------
110-
// Response-shape helpers — canonical implementations live in lib/TaskExecution.js
110+
// Response-shape helpers (duplicated from lib/TaskExecution.js — kept in sync
111+
// manually to avoid .js/.mjs cross-extension imports)
111112
// ---------------------------------------------------------------------------
112113

113-
export {
114-
getProcessDefinitionKey,
115-
getProcessInstanceKey,
116-
getProcessInstanceState,
117-
hasProcessInstanceIncident
118-
} from '../lib/TaskExecution.js';
114+
export function getProcessDefinitionKey(deployResponse, processId) {
115+
const { deployments = [] } = deployResponse;
116+
for (const deployment of deployments) {
117+
if ('processDefinition' in deployment) {
118+
const { processDefinition } = deployment;
119+
if (processDefinition.processDefinitionId === processId) {
120+
return processDefinition.processDefinitionKey;
121+
}
122+
}
123+
}
124+
return null;
125+
}
126+
127+
export function getProcessInstanceKey(response) {
128+
const { processInstanceKey } = response;
129+
return processInstanceKey || null;
130+
}
131+
132+
function getProcessInstance(response, processInstanceKey) {
133+
const { items = [] } = response;
134+
if (!items.length) return null;
135+
return items.find(item => item.processInstanceKey === processInstanceKey) || null;
136+
}
137+
138+
export function getProcessInstanceState(response, processInstanceKey) {
139+
const processInstance = getProcessInstance(response, processInstanceKey);
140+
return processInstance ? processInstance.state : null;
141+
}
142+
143+
export function hasProcessInstanceIncident(response, processInstanceKey) {
144+
const processInstance = getProcessInstance(response, processInstanceKey);
145+
return processInstance ? (processInstance.hasIncident || false) : false;
146+
}

lib/TaskExecution.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export default class TaskExecution extends EventEmitter {
324324
*
325325
* @returns {string|null} The process instance key or null if not found.
326326
*/
327-
export function getProcessInstanceKey(response) {
327+
function getProcessInstanceKey(response) {
328328
const { processInstanceKey } = response;
329329

330330
return processInstanceKey || null;
@@ -340,7 +340,7 @@ function getProcessInstance(response, processInstanceKey) {
340340
return items.find(item => item.processInstanceKey === processInstanceKey) || null;
341341
}
342342

343-
export function getProcessInstanceState(response, processInstanceKey) {
343+
function getProcessInstanceState(response, processInstanceKey) {
344344
const processInstance = getProcessInstance(response, processInstanceKey);
345345

346346
if (!processInstance) {
@@ -350,7 +350,7 @@ export function getProcessInstanceState(response, processInstanceKey) {
350350
return processInstance.state;
351351
}
352352

353-
export function hasProcessInstanceIncident(response, processInstanceKey) {
353+
function hasProcessInstanceIncident(response, processInstanceKey) {
354354
const processInstance = getProcessInstance(response, processInstanceKey);
355355

356356
if (!processInstance) {

0 commit comments

Comments
 (0)