UNPKG

@5minds/processcube_app_sdk

Version:
2 lines (1 loc) 2.65 kB
"use server";import{DataModels as C}from"@5minds/processcube_engine_client";import{DataModels as b}from"@5minds/processcube_engine_client";import{getToken as d}from"next-auth/jwt";import{ResponseCookies as k}from"next/dist/compiled/@edge-runtime/cookies";import{cookies as a,headers as y}from"next/headers";async function i(){let e=await d({req:{cookies:a(),headers:y()}});if(e?.expiresAt&&Date.now()>=e.expiresAt*1e3){let t=await fetch(`${process.env.NEXTAUTH_URL}/api/auth/session`,{method:"GET",headers:{"Content-Type":"application/json",cookie:a().toString()}}),o=new k(t.headers);if(o.getAll().length){let p=!1;try{for(let c of o.getAll())a().set(c.name,c.value,{...c})}catch{p=!0}if(e=await d({req:{cookies:p?o:a(),headers:y()}}),e?.error)throw e.error}}if(!e?.accessToken||!e?.sub)throw new Error("AccessToken or Sub could not be determined!");return{token:e?.accessToken,userId:e?.sub}}import{EngineClient as T}from"@5minds/processcube_engine_client";var h=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",n=new T(h);async function r(){try{return i()}catch{return}}async function u(e){let s=await r();return(await n.processInstances.query({processInstanceId:e},{identity:s})).processInstances[0]}async function I(e,s={sortSettings:{sortBy:b.FlowNodeInstances.FlowNodeInstanceSortableColumns.createdAt,sortDir:"ASC"}}){return(await n.flowNodeInstances.query({processInstanceId:e},{...s,identity:s.identity??await r()})).flowNodeInstances}async function l(e){let s=await r();return(await n.flowNodeInstances.query({triggeredByFlowNodeInstance:e},{identity:s})).flowNodeInstances}async function f(e,s,t){let o=await r();await n.processInstances.retryProcessInstance(e,{flowNodeInstanceId:s,newStartToken:t,identity:o})}async function m(e){let s=await r();await n.processInstances.terminateProcessInstance(e,s)}async function g(...e){await n.manualTasks.finishManualTask(...e)}async function w(...e){await n.userTasks.finishUserTask(...e)}async function P(...e){await n.untypedTasks.finishTask(...e)}async function E(){try{return i()}catch{return}}var X=async(e,s)=>{let t=await E();s==="bpmn:UserTask"?await w(e,{},t):s==="bpmn:ManualTask"?await g(e,t):s==="bpmn:Task"?await P(e,t):console.error(`[@5minds/processcube_app_sdk:handlePlay] Unsupported flow node type: ${s}`)},z=async e=>{await m(e)},J=async(e,s,t)=>{await f(e,s,t)},K=async e=>u(e),V=async e=>I(e,{sortSettings:{sortBy:C.FlowNodeInstances.FlowNodeInstanceSortableColumns.createdAt,sortDir:"DESC"}}),W=async e=>l(e);export{X as finishTask,V as getFlowNodeInstances,K as getProcessInstance,W as getTriggeredFlowNodeInstances,J as retryProcess,z as terminateProcess};