@@ -182,7 +182,7 @@ export default class TaskExecution extends EventEmitter {
182182 incident = getIncident ( getProcessInstanceIncidentResult . response ) ;
183183 }
184184
185- const isCompleted = [ 'COMPLETED' , 'TERMINATED' , 'CANCELED' ] . includes ( state ) ;
185+ const isCompleted = [ 'COMPLETED' , 'TERMINATED' , 'CANCELED' ] . includes ( state ?? '' ) ;
186186
187187 if ( isCompleted || hasIncident ) {
188188 const getProcessInstanceVariablesResult = await this . _api . getProcessInstanceVariables ( processInstanceKey ) ;
@@ -215,7 +215,7 @@ export default class TaskExecution extends EventEmitter {
215215
216216 const variables = getVariables (
217217 getProcessInstanceVariablesResult . response . items ,
218- getProcessInstanceElementInstancesResult . response . items ,
218+ getProcessInstanceElementInstancesResult . response . items ?? [ ] ,
219219 processInstance ,
220220 element . id
221221 ) ;
@@ -282,16 +282,21 @@ export default class TaskExecution extends EventEmitter {
282282/**
283283 * Get the process instance key from the response.
284284 *
285- * @param {CreateProcessInstanceResponse } response
285+ * @param {import('./types').CreateProcessInstanceResult } response
286286 *
287- * @returns {string| null } The process instance key or null if not found.
287+ * @returns {string | null } The process instance key or null if not found.
288288 */
289289function getProcessInstanceKey ( response ) {
290290 const { processInstanceKey } = response ;
291291
292292 return processInstanceKey || null ;
293293}
294294
295+ /**
296+ * @param {import('./types').ProcessInstanceSearchQueryResult } response
297+ * @param {string } processInstanceKey
298+ * @return {import('./types').ProcessInstanceResult | null }
299+ */
295300function getProcessInstance ( response , processInstanceKey ) {
296301 const { items = [ ] } = response ;
297302
@@ -302,6 +307,11 @@ function getProcessInstance(response, processInstanceKey) {
302307 return items . find ( item => item . processInstanceKey === processInstanceKey ) || null ;
303308}
304309
310+ /**
311+ * @param {import('./types').ProcessInstanceSearchQueryResult } response
312+ * @param {string } processInstanceKey
313+ * @return {import('./types').ProcessInstanceStateEnum | null }
314+ */
305315function getProcessInstanceState ( response , processInstanceKey ) {
306316 const processInstance = getProcessInstance ( response , processInstanceKey ) ;
307317
@@ -312,6 +322,11 @@ function getProcessInstanceState(response, processInstanceKey) {
312322 return processInstance . state ;
313323}
314324
325+ /**
326+ * @param {import('./types').ProcessInstanceSearchQueryResult } response
327+ * @param {string } processInstanceKey
328+ * @returns {boolean }
329+ */
315330function hasProcessInstanceIncident ( response , processInstanceKey ) {
316331 const processInstance = getProcessInstance ( response , processInstanceKey ) ;
317332
@@ -322,6 +337,14 @@ function hasProcessInstanceIncident(response, processInstanceKey) {
322337 return processInstance . hasIncident || false ;
323338}
324339
340+ /**
341+ *
342+ * @param {import('./types').VariableSearchResult[] } getVariablesResponseItems
343+ * @param {import('./types').ElementInstanceResult[] } getElementInstancesResponseItems
344+ * @param {import('./types').ProcessInstanceResult } processInstance
345+ * @param elementId
346+ * @returns {object }
347+ */
325348export function getVariables ( getVariablesResponseItems , getElementInstancesResponseItems , processInstance , elementId ) {
326349 const variables = { } ;
327350
@@ -348,6 +371,11 @@ export function getVariables(getVariablesResponseItems, getElementInstancesRespo
348371 return variables ;
349372}
350373
374+ /**
375+ *
376+ * @param {import('./types').IncidentSearchQueryResult } response
377+ * @return {import('./types').IncidentResult | null }
378+ */
351379function getIncident ( response ) {
352380 const { items = [ ] } = response ;
353381
@@ -358,11 +386,19 @@ function getIncident(response) {
358386 return items [ 0 ] ;
359387}
360388
389+ /**
390+ *
391+ * @param {import('./types').VariableSearchResult } variable
392+ * @param {import('./types').ElementInstanceResult[] } elementInstances
393+ * @param {import('./types').ProcessInstanceResult } processInstance
394+ * @param {string } elementId
395+ * @return {null | string }
396+ */
361397function getScope ( variable , elementInstances , processInstance , elementId ) {
362398 const { scopeKey } = variable ;
363399
364400 const elementInstance = elementInstances . find ( elementInstance => {
365- return elementInstance . elementInstanceKey === scopeKey && elementInstance . elementId === elementId ;
401+ return String ( elementInstance . elementInstanceKey ) === String ( scopeKey ) && elementInstance . elementId === elementId ;
366402 } ) ;
367403
368404 if ( elementInstance ) {
@@ -371,7 +407,7 @@ function getScope(variable, elementInstances, processInstance, elementId) {
371407
372408 const { processInstanceKey } = processInstance ;
373409
374- if ( scopeKey === processInstanceKey ) {
410+ if ( String ( scopeKey ) === String ( processInstanceKey ) ) {
375411 return SCOPES . PROCESS ;
376412 }
377413
@@ -381,16 +417,16 @@ function getScope(variable, elementInstances, processInstance, elementId) {
381417/**
382418 * Get the process definition key from the deployment response.
383419 *
384- * @param {import('@camunda8/sdk/dist/c8/lib/C8Dto ').DeployResourceResponse } deployResponse
420+ * @param {import('./types ').ExtendedDeploymentResult } deployResponse
385421 * @param {string } processId
386422 *
387- * @returns {string| null }
423+ * @returns {string | null }
388424 */
389425export function getProcessDefinitionKey ( deployResponse , processId ) {
390426 const { deployments = [ ] } = deployResponse ;
391427
392428 for ( const deployment of deployments ) {
393- if ( 'processDefinition' in deployment ) {
429+ if ( deployment . processDefinition ) {
394430 const { processDefinition } = deployment ;
395431
396432 if ( processDefinition . processDefinitionId === processId ) {
@@ -400,4 +436,4 @@ export function getProcessDefinitionKey(deployResponse, processId) {
400436 }
401437
402438 return null ;
403- }
439+ }
0 commit comments