@5minds/processcube_app_sdk 0.0.1-develop-73b219-lmfx64it → 0.0.1-develop-af64d7-lmho8chl

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/processcube_app_sdk",
3
- "version": "0.0.1-develop-73b219-lmfx64it",
3
+ "version": "0.0.1-develop-af64d7-lmho8chl",
4
4
  "description": "The SDK for ProcessCube Apps",
5
5
  "type": "module",
6
6
  "main": "common/index.cjs",
package/server/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var X=Object.create;var k=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var s in t)k(e,s,{get:t[s],enumerable:!0})},P=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!J.call(e,r)&&r!==s&&k(e,r,{get:()=>t[r],enumerable:!(n=Y(t,r))||n.enumerable});return e};var Q=(e,t,s)=>(s=e!=null?X(V(e)):{},P(t||!e||!e.__esModule?k(s,"default",{value:e,enumerable:!0}):s,e)),z=e=>P(k({},"__esModule",{value:!0}),e);var xe={};Z(xe,{finishUserTask:()=>ye,finishUserTaskAndGetNext:()=>te,getActiveProcessInstances:()=>de,getAssignedUserTasksByIdentity:()=>ie,getIdentity:()=>ce,getReservedUserTasksByIdentity:()=>ae,getUserTasks:()=>_,getWaitingUserTaskByFlowNodeInstanceId:()=>U,getWaitingUserTasks:()=>se,getWaitingUserTasksByCorrelationId:()=>oe,getWaitingUserTasksByFlowNodeId:()=>re,getWaitingUserTasksByProcessInstanceId:()=>ne,hardNavigate:()=>we,navigateToUrl:()=>Ee,startProcess:()=>ge,waitForUserTask:()=>ee,withApplicationSdk:()=>ke});module.exports=z(xe);var et=require("only-server");var c=require("@5minds/processcube_engine_client");var h=require("@5minds/processcube_engine_client"),N=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new h.EngineClient(N);async function ee(e={}){let{processInstanceId:t,flowNodeId:s}=e;return new Promise(async(n,r)=>{let a=await o.userTasks.onUserTaskWaiting(async i=>{let E=i.flowNodeInstanceId===void 0,x=t!==void 0&&i.processInstanceId!==t,T=s!==void 0&&i.flowNodeId!==s,l=t!==void 0&&s!==void 0&&i.processInstanceId!==t&&i.flowNodeId!==s;if(E||x||T||l)return;let m=await U(i.flowNodeInstanceId);return o.notification.removeSubscription(a),m===null?r(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):n(m)}),p=(await _({processInstanceId:t,flowNodeId:s,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended})).userTasks[0];p&&(o.notification.removeSubscription(a),n(p))})}async function te(e,t,s){await o.userTasks.finishUserTask(e,t);let n=await o.userTasks.query({flowNodeId:s,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended});return n.userTasks.length===0?null:n.userTasks[0]}async function _(...e){return await o.userTasks.query(...e)}async function se(e){return await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},e)}async function ne(e,t){return await o.userTasks.query({processInstanceId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function re(e,t){return await o.userTasks.query({flowNodeId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function U(e,t){let s=await o.userTasks.query({flowNodeInstanceId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{...t,limit:1});return s.userTasks.length===0?null:s.userTasks[0]}async function oe(e,t){return await o.userTasks.query({correlationId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function ae(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.actualOwnerId===e.userId);return s.userTasks=n,s}async function ie(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.assignedUserIds?.includes(e.userId));return s.userTasks=n,s}var w=require("next/headers"),F=require("next-auth/jwt");async function ce(){let e=await(0,F.getToken)({req:{cookies:(0,w.cookies)(),headers:(0,w.headers)()}});if(!e?.accessToken||!e?.sub)throw new Error("AccessToken or Sub could not be determined!");return{token:e?.accessToken,userId:e?.sub}}var R=require("@5minds/processcube_engine_client");async function de(e){return await o.processInstances.query({...e?.query,state:R.DataModels.ProcessInstances.ProcessInstanceState.running},e?.options)}var D=require("@5minds/processcube_engine_sdk"),b=require("@5minds/processcube_engine_client");var d=require("node:path"),M=require("esbuild"),I=require("node:fs"),A=require("openid-client"),L=Q(require("jwt-decode"),1),le={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},ue=.85,fe="external_task.ts",u=new D.Logger("processcube_app_sdk:external_task_adapter"),g=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;async function O(e){let t,s=[e,(0,d.join)(process.cwd(),"app"),(0,d.join)(process.cwd(),"src","app")];for(let r of s)if(r&&(0,I.existsSync)(r)){t=r;break}if(!t)throw new Error("Could not find external tasks directory");let n=await v(t);for(let r of n){let a=await pe(r);if(!a)continue;let f=(0,d.join)(r,a),p=await me(f),i=g?await q():null,E={identity:await W(i),...p?.config},x=p.default,T=(0,d.relative)(t,r).replace(/^\.\/+/,""),l=new b.ExternalTaskWorker(N,T,x,E);await S(i,l),l.onWorkerError((m,C,H)=>{u.error(`Intercepted "${m}"-type error: ${C.message}`,{err:C,type:m,externalTask:H})}),l.start(),u.info(`Started external task worker ${l.workerId} for topic '${T}'`)}}async function pe(e){let s=(await I.promises.readdir(e)).filter(n=>n===fe);if(s.length===0)return null;if(s.length>1)throw new Error(`Found more than one external task file in directory '${e}'`);return s[0]}async function q(){if(!g)throw new Error("No authority is configured");let e=await A.Issuer.discover(process.env.PROCESSCUBE_AUTHORITY_URL);return await new e.Client({client_id:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID,client_secret:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET}).grant({grant_type:"client_credentials",scope:"engine_etw"})}async function W(e){if(!g||e===null)return le;let t=e.access_token,s=(0,L.default)(t);return{token:e.access_token,userId:s.sub}}async function S(e,t,s=5){try{if(!g||e===null)return;let r=await Ie(e)*ue*1e3;setTimeout(async()=>{let a=await q(),f=await W(a);t.identity=f,await S(a,t)},r)}catch(n){if(s===0)throw n;u.error(`Could not refresh identity for external task worker ${t.workerId}`,{err:n,workerId:t.workerId});let r=2*1e3;setTimeout(async()=>await S(e,t,s-1),r)}}async function me(e){let t=await(0,M.build)({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"}),s=t.outputFiles[0].text,n=Te(s,e);if(t.errors.length>0)throw u.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&u.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),n}async function v(e){let t=await I.promises.readdir(e,{withFileTypes:!0}),s=await Promise.all(t.map(async n=>{let r=(0,d.join)(e.toString(),n.name);return n.isDirectory()?[r,...await v(r)]:[]}));return Array.prototype.concat(...s)}async function Ie(e){let t=e.expires_in;if(!t&&e.expires_at&&(t=Math.floor(e.expires_at-Date.now()/1e3)),t===void 0)throw new Error("Could not determine the time until the access token for external task workers expires");return t}function Te(e,t){try{var s=module.constructor,n=new s;return n._compile(e,t),n.exports}catch(r){throw u.error("Could not require module from string",{err:r}),r}}var y=require("next/dist/shared/lib/constants");function ke(e={}){let{applicationSdk:t,...s}=e;return async(n,r)=>{let a=n===y.PHASE_DEVELOPMENT_SERVER||n===y.PHASE_PRODUCTION_SERVER;return t?.useExternalTasks&&a&&await O(t?.customExternalTasksDirPath),s}}var B=require("next/cache"),$=require("next/navigation");async function we(e,t){(0,B.revalidatePath)(e),(0,$.redirect)(e,t)}async function ge(...e){return await o.processModels.startProcessInstance(...e)}async function ye(...e){await o.userTasks.finishUserTask(...e)}var K=require("next/cache"),G=require("next/navigation");function Ee(e){(0,K.revalidatePath)(e),(0,G.redirect)(e)}0&&(module.exports={finishUserTask,finishUserTaskAndGetNext,getActiveProcessInstances,getAssignedUserTasksByIdentity,getIdentity,getReservedUserTasksByIdentity,getUserTasks,getWaitingUserTaskByFlowNodeInstanceId,getWaitingUserTasks,getWaitingUserTasksByCorrelationId,getWaitingUserTasksByFlowNodeId,getWaitingUserTasksByProcessInstanceId,hardNavigate,navigateToUrl,startProcess,waitForUserTask,withApplicationSdk});
1
+ "use strict";var X=Object.create;var k=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var Z=(e,t)=>{for(var s in t)k(e,s,{get:t[s],enumerable:!0})},P=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!J.call(e,r)&&r!==s&&k(e,r,{get:()=>t[r],enumerable:!(n=Y(t,r))||n.enumerable});return e};var Q=(e,t,s)=>(s=e!=null?X(V(e)):{},P(t||!e||!e.__esModule?k(s,"default",{value:e,enumerable:!0}):s,e)),z=e=>P(k({},"__esModule",{value:!0}),e);var Ne={};Z(Ne,{finishUserTask:()=>Ee,finishUserTaskAndGetNext:()=>ue,getActiveProcessInstances:()=>de,getAssignedUserTasksByIdentity:()=>ke,getEngineClient:()=>ie,getIdentity:()=>ce,getReservedUserTasksByIdentity:()=>Te,getUserTasks:()=>W,getWaitingUserTaskByFlowNodeInstanceId:()=>v,getWaitingUserTasks:()=>fe,getWaitingUserTasksByCorrelationId:()=>Ie,getWaitingUserTasksByFlowNodeId:()=>me,getWaitingUserTasksByProcessInstanceId:()=>pe,hardNavigate:()=>ge,navigateToUrl:()=>xe,startProcess:()=>ye,waitForUserTask:()=>le,withApplicationSdk:()=>we});module.exports=z(Ne);var rt=require("only-server");var _=require("@5minds/processcube_engine_sdk"),U=require("@5minds/processcube_engine_client");var h=require("@5minds/processcube_engine_client"),N=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new h.EngineClient(N);var d=require("node:path"),F=require("esbuild"),I=require("node:fs"),R=require("openid-client"),D=Q(require("jwt-decode"),1),ee={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},te=.85,se="external_task.ts",u=new _.Logger("processcube_app_sdk:external_task_adapter"),w=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;async function b(e){let t,s=[e,(0,d.join)(process.cwd(),"app"),(0,d.join)(process.cwd(),"src","app")];for(let r of s)if(r&&(0,I.existsSync)(r)){t=r;break}if(!t)throw new Error("Could not find external tasks directory");let n=await L(t);for(let r of n){let a=await ne(r);if(!a)continue;let f=(0,d.join)(r,a),p=await re(f),i=w?await M():null,E={identity:await A(i),...p?.config},x=p.default,T=(0,d.relative)(t,r).replace(/^\.\/+/,""),l=new U.ExternalTaskWorker(N,T,x,E);await C(i,l),l.onWorkerError((m,S,H)=>{u.error(`Intercepted "${m}"-type error: ${S.message}`,{err:S,type:m,externalTask:H})}),l.start(),u.info(`Started external task worker ${l.workerId} for topic '${T}'`)}}async function ne(e){let s=(await I.promises.readdir(e)).filter(n=>n===se);if(s.length===0)return null;if(s.length>1)throw new Error(`Found more than one external task file in directory '${e}'`);return s[0]}async function M(){if(!w)throw new Error("No authority is configured");let e=await R.Issuer.discover(process.env.PROCESSCUBE_AUTHORITY_URL);return await new e.Client({client_id:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID,client_secret:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET}).grant({grant_type:"client_credentials",scope:"engine_etw"})}async function A(e){if(!w||e===null)return ee;let t=e.access_token,s=(0,D.default)(t);return{token:e.access_token,userId:s.sub}}async function C(e,t,s=5){try{if(!w||e===null)return;let r=await oe(e)*te*1e3;setTimeout(async()=>{let a=await M(),f=await A(a);t.identity=f,await C(a,t)},r)}catch(n){if(s===0)throw n;u.error(`Could not refresh identity for external task worker ${t.workerId}`,{err:n,workerId:t.workerId});let r=2*1e3;setTimeout(async()=>await C(e,t,s-1),r)}}async function re(e){let t=await(0,F.build)({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"}),s=t.outputFiles[0].text,n=ae(s,e);if(t.errors.length>0)throw u.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&u.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),n}async function L(e){let t=await I.promises.readdir(e,{withFileTypes:!0}),s=await Promise.all(t.map(async n=>{let r=(0,d.join)(e.toString(),n.name);return n.isDirectory()?[r,...await L(r)]:[]}));return Array.prototype.concat(...s)}async function oe(e){let t=e.expires_in;if(!t&&e.expires_at&&(t=Math.floor(e.expires_at-Date.now()/1e3)),t===void 0)throw new Error("Could not determine the time until the access token for external task workers expires");return t}function ae(e,t){try{var s=module.constructor,n=new s;return n._compile(e,t),n.exports}catch(r){throw u.error("Could not require module from string",{err:r}),r}}function ie(){return o}var g=require("next/headers"),O=require("next-auth/jwt");async function ce(){let e=await(0,O.getToken)({req:{cookies:(0,g.cookies)(),headers:(0,g.headers)()}});if(!e?.accessToken||!e?.sub)throw new Error("AccessToken or Sub could not be determined!");return{token:e?.accessToken,userId:e?.sub}}var q=require("@5minds/processcube_engine_client");async function de(e){return await o.processInstances.query({...e?.query,state:q.DataModels.ProcessInstances.ProcessInstanceState.running},e?.options)}var c=require("@5minds/processcube_engine_client");async function le(e={}){let{processInstanceId:t,flowNodeId:s}=e;return new Promise(async(n,r)=>{let a=await o.userTasks.onUserTaskWaiting(async i=>{let E=i.flowNodeInstanceId===void 0,x=t!==void 0&&i.processInstanceId!==t,T=s!==void 0&&i.flowNodeId!==s,l=t!==void 0&&s!==void 0&&i.processInstanceId!==t&&i.flowNodeId!==s;if(E||x||T||l)return;let m=await v(i.flowNodeInstanceId);return o.notification.removeSubscription(a),m===null?r(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):n(m)}),p=(await W({processInstanceId:t,flowNodeId:s,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended})).userTasks[0];p&&(o.notification.removeSubscription(a),n(p))})}async function ue(e,t,s){await o.userTasks.finishUserTask(e,t);let n=await o.userTasks.query({flowNodeId:s,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended});return n.userTasks.length===0?null:n.userTasks[0]}async function W(...e){return await o.userTasks.query(...e)}async function fe(e){return await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},e)}async function pe(e,t){return await o.userTasks.query({processInstanceId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function me(e,t){return await o.userTasks.query({flowNodeId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function v(e,t){let s=await o.userTasks.query({flowNodeInstanceId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{...t,limit:1});return s.userTasks.length===0?null:s.userTasks[0]}async function Ie(e,t){return await o.userTasks.query({correlationId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function Te(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.actualOwnerId===e.userId);return s.userTasks=n,s}async function ke(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.assignedUserIds?.includes(e.userId));return s.userTasks=n,s}var y=require("next/dist/shared/lib/constants");function we(e={}){let{applicationSdk:t,...s}=e;return async(n,r)=>{let a=n===y.PHASE_DEVELOPMENT_SERVER||n===y.PHASE_PRODUCTION_SERVER;return t?.useExternalTasks&&a&&await b(t?.customExternalTasksDirPath),s}}var B=require("next/cache"),$=require("next/navigation");async function ge(e,t){(0,B.revalidatePath)(e),(0,$.redirect)(e,t)}async function ye(...e){return await o.processModels.startProcessInstance(...e)}async function Ee(...e){await o.userTasks.finishUserTask(...e)}var K=require("next/cache"),G=require("next/navigation");function xe(e){(0,K.revalidatePath)(e),(0,G.redirect)(e)}0&&(module.exports={finishUserTask,finishUserTaskAndGetNext,getActiveProcessInstances,getAssignedUserTasksByIdentity,getEngineClient,getIdentity,getReservedUserTasksByIdentity,getUserTasks,getWaitingUserTaskByFlowNodeInstanceId,getWaitingUserTasks,getWaitingUserTasksByCorrelationId,getWaitingUserTasksByFlowNodeId,getWaitingUserTasksByProcessInstanceId,hardNavigate,navigateToUrl,startProcess,waitForUserTask,withApplicationSdk});
package/server/index.mjs CHANGED
@@ -1 +1 @@
1
- import"only-server";import{DataModels as c}from"@5minds/processcube_engine_client";import{EngineClient as _}from"@5minds/processcube_engine_client";var g=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new _(g);async function oe(e={}){let{processInstanceId:t,flowNodeId:s}=e;return new Promise(async(n,r)=>{let a=await o.userTasks.onUserTaskWaiting(async i=>{let k=i.flowNodeInstanceId===void 0,w=t!==void 0&&i.processInstanceId!==t,m=s!==void 0&&i.flowNodeId!==s,d=t!==void 0&&s!==void 0&&i.processInstanceId!==t&&i.flowNodeId!==s;if(k||w||m||d)return;let p=await F(i.flowNodeInstanceId);return o.notification.removeSubscription(a),p===null?r(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):n(p)}),f=(await U({processInstanceId:t,flowNodeId:s,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended})).userTasks[0];f&&(o.notification.removeSubscription(a),n(f))})}async function ae(e,t,s){await o.userTasks.finishUserTask(e,t);let n=await o.userTasks.query({flowNodeId:s,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended});return n.userTasks.length===0?null:n.userTasks[0]}async function U(...e){return await o.userTasks.query(...e)}async function ie(e){return await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},e)}async function ce(e,t){return await o.userTasks.query({processInstanceId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function de(e,t){return await o.userTasks.query({flowNodeId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function F(e,t){let s=await o.userTasks.query({flowNodeInstanceId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{...t,limit:1});return s.userTasks.length===0?null:s.userTasks[0]}async function le(e,t){return await o.userTasks.query({correlationId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function ue(e,t){let s=await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.actualOwnerId===e.userId);return s.userTasks=n,s}async function fe(e,t){let s=await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.assignedUserIds?.includes(e.userId));return s.userTasks=n,s}import{cookies as R,headers as D}from"next/headers";import{getToken as b}from"next-auth/jwt";async function Te(){let e=await b({req:{cookies:R(),headers:D()}});if(!e?.accessToken||!e?.sub)throw new Error("AccessToken or Sub could not be determined!");return{token:e?.accessToken,userId:e?.sub}}import{DataModels as M}from"@5minds/processcube_engine_client";async function ye(e){return await o.processInstances.query({...e?.query,state:M.ProcessInstances.ProcessInstanceState.running},e?.options)}import{Logger as A}from"@5minds/processcube_engine_sdk";import{ExternalTaskWorker as L}from"@5minds/processcube_engine_client";import{join as I,relative as O}from"node:path";import{build as q}from"esbuild";import{promises as x,existsSync as W}from"node:fs";import{Issuer as v}from"openid-client";import B from"jwt-decode";var $={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},K=.85,G="external_task.ts",l=new A("processcube_app_sdk:external_task_adapter"),T=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;async function N(e){let t,s=[e,I(process.cwd(),"app"),I(process.cwd(),"src","app")];for(let r of s)if(r&&W(r)){t=r;break}if(!t)throw new Error("Could not find external tasks directory");let n=await P(t);for(let r of n){let a=await H(r);if(!a)continue;let u=I(r,a),f=await X(u),i=T?await S():null,k={identity:await C(i),...f?.config},w=f.default,m=O(t,r).replace(/^\.\/+/,""),d=new L(g,m,w,k);await y(i,d),d.onWorkerError((p,E,h)=>{l.error(`Intercepted "${p}"-type error: ${E.message}`,{err:E,type:p,externalTask:h})}),d.start(),l.info(`Started external task worker ${d.workerId} for topic '${m}'`)}}async function H(e){let s=(await x.readdir(e)).filter(n=>n===G);if(s.length===0)return null;if(s.length>1)throw new Error(`Found more than one external task file in directory '${e}'`);return s[0]}async function S(){if(!T)throw new Error("No authority is configured");let e=await v.discover(process.env.PROCESSCUBE_AUTHORITY_URL);return await new e.Client({client_id:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID,client_secret:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET}).grant({grant_type:"client_credentials",scope:"engine_etw"})}async function C(e){if(!T||e===null)return $;let t=e.access_token,s=B(t);return{token:e.access_token,userId:s.sub}}async function y(e,t,s=5){try{if(!T||e===null)return;let r=await Y(e)*K*1e3;setTimeout(async()=>{let a=await S(),u=await C(a);t.identity=u,await y(a,t)},r)}catch(n){if(s===0)throw n;l.error(`Could not refresh identity for external task worker ${t.workerId}`,{err:n,workerId:t.workerId});let r=2*1e3;setTimeout(async()=>await y(e,t,s-1),r)}}async function X(e){let t=await q({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"}),s=t.outputFiles[0].text,n=j(s,e);if(t.errors.length>0)throw l.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&l.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),n}async function P(e){let t=await x.readdir(e,{withFileTypes:!0}),s=await Promise.all(t.map(async n=>{let r=I(e.toString(),n.name);return n.isDirectory()?[r,...await P(r)]:[]}));return Array.prototype.concat(...s)}async function Y(e){let t=e.expires_in;if(!t&&e.expires_at&&(t=Math.floor(e.expires_at-Date.now()/1e3)),t===void 0)throw new Error("Could not determine the time until the access token for external task workers expires");return t}function j(e,t){try{var s=module.constructor,n=new s;return n._compile(e,t),n.exports}catch(r){throw l.error("Could not require module from string",{err:r}),r}}import{PHASE_DEVELOPMENT_SERVER as V,PHASE_PRODUCTION_SERVER as J}from"next/dist/shared/lib/constants";function Ke(e={}){let{applicationSdk:t,...s}=e;return async(n,r)=>{let a=n===V||n===J;return t?.useExternalTasks&&a&&await N(t?.customExternalTasksDirPath),s}}import{revalidatePath as Z}from"next/cache";import{redirect as Q}from"next/navigation";async function Ve(e,t){Z(e),Q(e,t)}async function Qe(...e){return await o.processModels.startProcessInstance(...e)}async function ze(...e){await o.userTasks.finishUserTask(...e)}import{revalidatePath as z}from"next/cache";import{redirect as ee}from"next/navigation";function nt(e){z(e),ee(e)}export{ze as finishUserTask,ae as finishUserTaskAndGetNext,ye as getActiveProcessInstances,fe as getAssignedUserTasksByIdentity,Te as getIdentity,ue as getReservedUserTasksByIdentity,U as getUserTasks,F as getWaitingUserTaskByFlowNodeInstanceId,ie as getWaitingUserTasks,le as getWaitingUserTasksByCorrelationId,de as getWaitingUserTasksByFlowNodeId,ce as getWaitingUserTasksByProcessInstanceId,Ve as hardNavigate,nt as navigateToUrl,Qe as startProcess,oe as waitForUserTask,Ke as withApplicationSdk};
1
+ import"only-server";import{Logger as U}from"@5minds/processcube_engine_sdk";import{ExternalTaskWorker as F}from"@5minds/processcube_engine_client";import{EngineClient as _}from"@5minds/processcube_engine_client";var g=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new _(g);import{join as I,relative as R}from"node:path";import{build as D}from"esbuild";import{promises as x,existsSync as b}from"node:fs";import{Issuer as M}from"openid-client";import A from"jwt-decode";var L={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},O=.85,q="external_task.ts",l=new U("processcube_app_sdk:external_task_adapter"),T=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;async function N(e){let t,s=[e,I(process.cwd(),"app"),I(process.cwd(),"src","app")];for(let r of s)if(r&&b(r)){t=r;break}if(!t)throw new Error("Could not find external tasks directory");let n=await P(t);for(let r of n){let a=await W(r);if(!a)continue;let u=I(r,a),f=await v(u),i=T?await C():null,k={identity:await S(i),...f?.config},w=f.default,m=R(t,r).replace(/^\.\/+/,""),d=new F(g,m,w,k);await y(i,d),d.onWorkerError((p,E,h)=>{l.error(`Intercepted "${p}"-type error: ${E.message}`,{err:E,type:p,externalTask:h})}),d.start(),l.info(`Started external task worker ${d.workerId} for topic '${m}'`)}}async function W(e){let s=(await x.readdir(e)).filter(n=>n===q);if(s.length===0)return null;if(s.length>1)throw new Error(`Found more than one external task file in directory '${e}'`);return s[0]}async function C(){if(!T)throw new Error("No authority is configured");let e=await M.discover(process.env.PROCESSCUBE_AUTHORITY_URL);return await new e.Client({client_id:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID,client_secret:process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET}).grant({grant_type:"client_credentials",scope:"engine_etw"})}async function S(e){if(!T||e===null)return L;let t=e.access_token,s=A(t);return{token:e.access_token,userId:s.sub}}async function y(e,t,s=5){try{if(!T||e===null)return;let r=await B(e)*O*1e3;setTimeout(async()=>{let a=await C(),u=await S(a);t.identity=u,await y(a,t)},r)}catch(n){if(s===0)throw n;l.error(`Could not refresh identity for external task worker ${t.workerId}`,{err:n,workerId:t.workerId});let r=2*1e3;setTimeout(async()=>await y(e,t,s-1),r)}}async function v(e){let t=await D({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"}),s=t.outputFiles[0].text,n=$(s,e);if(t.errors.length>0)throw l.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&l.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),n}async function P(e){let t=await x.readdir(e,{withFileTypes:!0}),s=await Promise.all(t.map(async n=>{let r=I(e.toString(),n.name);return n.isDirectory()?[r,...await P(r)]:[]}));return Array.prototype.concat(...s)}async function B(e){let t=e.expires_in;if(!t&&e.expires_at&&(t=Math.floor(e.expires_at-Date.now()/1e3)),t===void 0)throw new Error("Could not determine the time until the access token for external task workers expires");return t}function $(e,t){try{var s=module.constructor,n=new s;return n._compile(e,t),n.exports}catch(r){throw l.error("Could not require module from string",{err:r}),r}}function ke(){return o}import{cookies as K,headers as G}from"next/headers";import{getToken as H}from"next-auth/jwt";async function Ee(){let e=await H({req:{cookies:K(),headers:G()}});if(!e?.accessToken||!e?.sub)throw new Error("AccessToken or Sub could not be determined!");return{token:e?.accessToken,userId:e?.sub}}import{DataModels as X}from"@5minds/processcube_engine_client";async function Se(e){return await o.processInstances.query({...e?.query,state:X.ProcessInstances.ProcessInstanceState.running},e?.options)}import{DataModels as c}from"@5minds/processcube_engine_client";async function Ue(e={}){let{processInstanceId:t,flowNodeId:s}=e;return new Promise(async(n,r)=>{let a=await o.userTasks.onUserTaskWaiting(async i=>{let k=i.flowNodeInstanceId===void 0,w=t!==void 0&&i.processInstanceId!==t,m=s!==void 0&&i.flowNodeId!==s,d=t!==void 0&&s!==void 0&&i.processInstanceId!==t&&i.flowNodeId!==s;if(k||w||m||d)return;let p=await j(i.flowNodeInstanceId);return o.notification.removeSubscription(a),p===null?r(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):n(p)}),f=(await Y({processInstanceId:t,flowNodeId:s,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended})).userTasks[0];f&&(o.notification.removeSubscription(a),n(f))})}async function Fe(e,t,s){await o.userTasks.finishUserTask(e,t);let n=await o.userTasks.query({flowNodeId:s,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended});return n.userTasks.length===0?null:n.userTasks[0]}async function Y(...e){return await o.userTasks.query(...e)}async function Re(e){return await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},e)}async function De(e,t){return await o.userTasks.query({processInstanceId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function be(e,t){return await o.userTasks.query({flowNodeId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function j(e,t){let s=await o.userTasks.query({flowNodeInstanceId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{...t,limit:1});return s.userTasks.length===0?null:s.userTasks[0]}async function Me(e,t){return await o.userTasks.query({correlationId:e,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function Ae(e,t){let s=await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.actualOwnerId===e.userId);return s.userTasks=n,s}async function Le(e,t){let s=await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),n=s.userTasks.filter(r=>r.assignedUserIds?.includes(e.userId));return s.userTasks=n,s}import{PHASE_DEVELOPMENT_SERVER as V,PHASE_PRODUCTION_SERVER as J}from"next/dist/shared/lib/constants";function Ye(e={}){let{applicationSdk:t,...s}=e;return async(n,r)=>{let a=n===V||n===J;return t?.useExternalTasks&&a&&await N(t?.customExternalTasksDirPath),s}}import{revalidatePath as Z}from"next/cache";import{redirect as Q}from"next/navigation";async function ze(e,t){Z(e),Q(e,t)}async function st(...e){return await o.processModels.startProcessInstance(...e)}async function nt(...e){await o.userTasks.finishUserTask(...e)}import{revalidatePath as z}from"next/cache";import{redirect as ee}from"next/navigation";function it(e){z(e),ee(e)}export{nt as finishUserTask,Fe as finishUserTaskAndGetNext,Se as getActiveProcessInstances,Le as getAssignedUserTasksByIdentity,ke as getEngineClient,Ee as getIdentity,Ae as getReservedUserTasksByIdentity,Y as getUserTasks,j as getWaitingUserTaskByFlowNodeInstanceId,Re as getWaitingUserTasks,Me as getWaitingUserTasksByCorrelationId,be as getWaitingUserTasksByFlowNodeId,De as getWaitingUserTasksByProcessInstanceId,ze as hardNavigate,it as navigateToUrl,st as startProcess,Ue as waitForUserTask,Ye as withApplicationSdk};
@@ -0,0 +1,2 @@
1
+ import { type EngineClient } from '@5minds/processcube_engine_client';
2
+ export declare function getEngineClient(): EngineClient;
@@ -1,4 +1,5 @@
1
- export * from './UserTaskFunctions';
1
+ export { ExternalTaskConfig } from './ExternalTaskAdapter';
2
+ export * from './getEngineClient';
2
3
  export * from './getIdentity';
3
4
  export * from './ProcessInstanceFunctions';
4
- export { ExternalTaskConfig } from './ExternalTaskAdapter';
5
+ export * from './UserTaskFunctions';