@5minds/processcube_app_sdk 5.1.0-develop-20a49f-lqw1kevu → 5.1.0-develop-b9e133-lralk3eq
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
package/server/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var V=(e,t)=>{for(var s in t)C(e,s,{get:t[s],enumerable:!0})},J=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!Y.call(e,n)&&n!==s&&C(e,n,{get:()=>t[n],enumerable:!(r=H(t,n))||r.enumerable});return e};var Z=e=>J(C({},"__esModule",{value:!0}),e);var ye={};V(ye,{finishUserTask:()=>ge,finishUserTaskAndGetNext:()=>de,getActiveProcessInstances:()=>ce,getAssignedUserTasksByIdentity:()=>me,getEngineClient:()=>oe,getIdentity:()=>ie,getReservedUserTasksByIdentity:()=>Ie,getUserTasks:()=>K,getWaitingUserTaskByFlowNodeInstanceId:()=>q,getWaitingUserTasks:()=>ue,getWaitingUserTasksByCorrelationId:()=>Te,getWaitingUserTasksByFlowNodeId:()=>fe,getWaitingUserTasksByProcessInstanceId:()=>pe,navigateToUrl:()=>Ee,startProcess:()=>we,waitForUserTask:()=>le,withApplicationSdk:()=>ke});module.exports=Z(ye);var nt=require("only-server");var P=require("@5minds/processcube_engine_sdk"),U=require("@5minds/processcube_engine_client"),u=require("node:path"),F=require("esbuild"),T=require("node:fs"),A=require("openid-client"),L=require("jwt-decode");var h=require("@5minds/processcube_engine_client"),_=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new h.EngineClient(_);var Q={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},z=.85,ee=["external_task.ts","external_task.js"],p=new P.Logger("processcube_app_sdk:external_task_adapter"),E=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;if(E&&(!process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID||!process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET)){let e=new Error("Required environment variables PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID and PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET are missing. For help, please refer to our documentation on environment variables at: https://processcube.io/docs/app-sdk/samples/external-task-adapter#authority");throw p.error("Required environment variables PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID and PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET are missing",{err:e}),e}async function O(e){let t,s=[e,(0,u.join)(process.cwd(),"app"),(0,u.join)(process.cwd(),"src","app")];for(let n of s)if(n&&(0,T.existsSync)(n)){t=n;break}if(e&&!(0,T.existsSync)(e))throw new Error(`Invalid customExternalTasksDirPath. The given path '${e}' does not exist`);if(!t)throw new Error("Could not find external tasks directory");let r=await M(t);for(let n of r){let a=await te(n);if(!a)continue;let l=(0,u.join)(n,a),N=await se(l),I=await ne(N,l),i=await b(),g={identity:D(i),...I?.config},y=I.default,k=(0,u.relative)(t,n).replace(/^\.\/+|\([^)]+\)|^\/*|\/*$/g,"").replace(/[\/]{2,}/g,"/"),f=new U.ExternalTaskWorker(_,k,y,g);await S(i,f),f.onWorkerError((m,R,G)=>{p.error(`Intercepted "${m}"-type error: ${R.message}`,{err:R,type:m,externalTask:G})}),f.start(),p.info(`Started external task worker ${f.workerId} for topic '${k}'`)}}async function te(e){let s=(await T.promises.readdir(e)).filter(r=>ee.includes(r));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 b(){if(!E)return null;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"})}function D(e){if(!E||e===null)return Q;let t=e.access_token,s=(0,L.jwtDecode)(t);return{token:e.access_token,userId:s.sub}}async function S(e,t,s=5){try{if(!E||e===null)return;let n=await re(e)*z*1e3;setTimeout(async()=>{let a=await b(),l=D(a);t.identity=l,await S(a,t)},n)}catch(r){if(s===0)throw r;p.error(`Could not refresh identity for external task worker ${t.workerId}`,{err:r,workerId:t.workerId});let n=2*1e3;setTimeout(async()=>await S(e,t,s-1),n)}}async function se(e){let t=await(0,F.build)({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"});if(t.errors.length>0)throw p.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&p.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),t.outputFiles[0].text}async function ne(e,t){try{var s=module.constructor,r=new s;return r._compile(e,t),r.exports}catch(n){throw p.error("Could not require module from string",{err:n}),n}}async function M(e){let t=await T.promises.readdir(e,{withFileTypes:!0}),s=await Promise.all(t.map(async r=>{let n=(0,u.join)(e.toString(),r.name);return r.isDirectory()?[n,...await M(n)]:[]}));return Array.prototype.concat(...s)}async function re(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 oe(){return o}var d=require("next/headers"),W=require("next/dist/compiled/@edge-runtime/cookies"),x=require("next-auth/jwt"),ae=process.env.NEXTAUTH_URL?.startsWith("https://"),v=`${ae?"__Secure-":""}next-auth.session-token`;async function ie(){let e=await(0,x.getToken)({req:{cookies:(0,d.cookies)(),headers:(0,d.headers)()}});if(e?.expiresAt&&Date.now()>=e.expiresAt*1e3){let s=await fetch(`${process.env.NEXTAUTH_URL}/api/auth/session`,{method:"GET",headers:{"Content-Type":"application/json",cookie:(0,d.cookies)().toString()}}),r=new W.ResponseCookies(s.headers),n=r.get(v);if(n){let a=!1;try{(0,d.cookies)().set(v,n.value,{...n})}catch{a=!0}if(e=await(0,x.getToken)({req:{cookies:a?r:(0,d.cookies)(),headers:(0,d.headers)()}}),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}}var B=require("@5minds/processcube_engine_client");async function ce(e){return await o.processInstances.query({...e?.query,state:B.DataModels.ProcessInstances.ProcessInstanceState.running},e?.options)}var c=require("@5minds/processcube_engine_client");async function le(e={},t){let{processInstanceId:s,flowNodeId:r}=e;return new Promise(async(n,a)=>{let l=await o.userTasks.onUserTaskWaiting(async i=>{let g=i.flowNodeInstanceId===void 0,y=s!==void 0&&i.processInstanceId!==s,k=r!==void 0&&i.flowNodeId!==r,f=s!==void 0&&r!==void 0&&i.processInstanceId!==s&&i.flowNodeId!==r;if(g||y||k||f)return;let m=await q(i.flowNodeInstanceId,{identity:t});return o.notification.removeSubscription(l,t),m===null?a(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):n(m)},{identity:t}),I=(await K({processInstanceId:s,flowNodeId:r,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:t})).userTasks[0];I&&(o.notification.removeSubscription(l,t),n(I))})}async function de(e,t,s,r){await o.userTasks.finishUserTask(e,t,r);let n=await o.userTasks.query({flowNodeId:s,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:r});return n.userTasks.length===0?null:n.userTasks[0]}async function K(...e){return await o.userTasks.query(...e)}async function ue(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 fe(e,t){return await o.userTasks.query({flowNodeId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function q(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 Te(e,t){return await o.userTasks.query({correlationId:e,state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},t)}async function Ie(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),r=s.userTasks.filter(n=>n.actualOwnerId===e.userId);return s.userTasks=r,s}async function me(e,t){let s=await o.userTasks.query({state:c.DataModels.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:e,...t}),r=s.userTasks.filter(n=>n.assignedUserIds?.includes(e.userId));return s.userTasks=r,s}var w=require("next/dist/shared/lib/constants");function ke(e={}){let{applicationSdk:t,...s}=e;return async(r,n)=>{let a=r===w.PHASE_DEVELOPMENT_SERVER||r===w.PHASE_PRODUCTION_SERVER;return t?.useExternalTasks&&a&&await O(t?.customExternalTasksDirPath),s}}var X=require("next/cache"),$=require("next/navigation");function Ee(e){(0,X.revalidatePath)(e),(0,$.redirect)(e)}async function we(...e){return await o.processModels.startProcessInstance(...e)}async function ge(...e){await o.userTasks.finishUserTask(...e)}0&&(module.exports={finishUserTask,finishUserTaskAndGetNext,getActiveProcessInstances,getAssignedUserTasksByIdentity,getEngineClient,getIdentity,getReservedUserTasksByIdentity,getUserTasks,getWaitingUserTaskByFlowNodeInstanceId,getWaitingUserTasks,getWaitingUserTasksByCorrelationId,getWaitingUserTasksByFlowNodeId,getWaitingUserTasksByProcessInstanceId,navigateToUrl,startProcess,waitForUserTask,withApplicationSdk});
|
package/server/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"only-server";import{Logger as
|
|
1
|
+
import"only-server";import{Logger as b}from"@5minds/processcube_engine_sdk";import{ExternalTaskWorker as D}from"@5minds/processcube_engine_client";import{join as I,relative as M}from"node:path";import{build as v}from"esbuild";import{promises as x,existsSync as S}from"node:fs";import{Issuer as W}from"openid-client";import{jwtDecode as B}from"jwt-decode";import{EngineClient as O}from"@5minds/processcube_engine_client";var g=process.env.PROCESSCUBE_ENGINE_URL??"http://localhost:10560",o=new O(g);var K={token:"ZHVtbXlfdG9rZW4=",userId:"dummy_token"},q=.85,X=["external_task.ts","external_task.js"],d=new b("processcube_app_sdk:external_task_adapter"),m=process.env.PROCESSCUBE_AUTHORITY_URL!==void 0;if(m&&(!process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID||!process.env.PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET)){let e=new Error("Required environment variables PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID and PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET are missing. For help, please refer to our documentation on environment variables at: https://processcube.io/docs/app-sdk/samples/external-task-adapter#authority");throw d.error("Required environment variables PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_ID and PROCESSCUBE_EXTERNAL_TASK_WORKER_CLIENT_SECRET are missing",{err:e}),e}async function N(e){let t,s=[e,I(process.cwd(),"app"),I(process.cwd(),"src","app")];for(let r of s)if(r&&S(r)){t=r;break}if(e&&!S(e))throw new Error(`Invalid customExternalTasksDirPath. The given path '${e}' does not exist`);if(!t)throw new Error("Could not find external tasks directory");let n=await P(t);for(let r of n){let a=await $(r);if(!a)continue;let l=I(r,a),C=await G(l),p=await H(C,l),i=await R(),E={identity:h(i),...p?.config},w=p.default,T=M(t,r).replace(/^\.\/+|\([^)]+\)|^\/*|\/*$/g,"").replace(/[\/]{2,}/g,"/"),u=new D(g,T,w,E);await y(i,u),u.onWorkerError((f,_,L)=>{d.error(`Intercepted "${f}"-type error: ${_.message}`,{err:_,type:f,externalTask:L})}),u.start(),d.info(`Started external task worker ${u.workerId} for topic '${T}'`)}}async function $(e){let s=(await x.readdir(e)).filter(n=>X.includes(n));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 R(){if(!m)return null;let e=await W.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"})}function h(e){if(!m||e===null)return K;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(!m||e===null)return;let r=await j(e)*q*1e3;setTimeout(async()=>{let a=await R(),l=h(a);t.identity=l,await y(a,t)},r)}catch(n){if(s===0)throw n;d.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 G(e){let t=await v({entryPoints:[e],write:!1,bundle:!0,platform:"node",target:"node18",format:"cjs"});if(t.errors.length>0)throw d.error(`Could not transpile file at '${e}'`,{errors:t.errors}),new Error(`Could not transpile file at '${e}'`);return t.warnings.length>0&&d.warn(`Transpiled file at '${e}' with warnings`,{warnings:t.warnings}),t.outputFiles[0].text}async function H(e,t){try{var s=module.constructor,n=new s;return n._compile(e,t),n.exports}catch(r){throw d.error("Could not require module from string",{err:r}),r}}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 j(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 we(){return o}import{cookies as k,headers as U}from"next/headers";import{ResponseCookies as Y}from"next/dist/compiled/@edge-runtime/cookies";import{getToken as F}from"next-auth/jwt";var V=process.env.NEXTAUTH_URL?.startsWith("https://"),A=`${V?"__Secure-":""}next-auth.session-token`;async function Se(){let e=await F({req:{cookies:k(),headers:U()}});if(e?.expiresAt&&Date.now()>=e.expiresAt*1e3){let s=await fetch(`${process.env.NEXTAUTH_URL}/api/auth/session`,{method:"GET",headers:{"Content-Type":"application/json",cookie:k().toString()}}),n=new Y(s.headers),r=n.get(A);if(r){let a=!1;try{k().set(A,r.value,{...r})}catch{a=!0}if(e=await F({req:{cookies:a?n:k(),headers:U()}}),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{DataModels as J}from"@5minds/processcube_engine_client";async function he(e){return await o.processInstances.query({...e?.query,state:J.ProcessInstances.ProcessInstanceState.running},e?.options)}import{DataModels as c}from"@5minds/processcube_engine_client";async function Ae(e={},t){let{processInstanceId:s,flowNodeId:n}=e;return new Promise(async(r,a)=>{let l=await o.userTasks.onUserTaskWaiting(async i=>{let E=i.flowNodeInstanceId===void 0,w=s!==void 0&&i.processInstanceId!==s,T=n!==void 0&&i.flowNodeId!==n,u=s!==void 0&&n!==void 0&&i.processInstanceId!==s&&i.flowNodeId!==n;if(E||w||T||u)return;let f=await Q(i.flowNodeInstanceId,{identity:t});return o.notification.removeSubscription(l,t),f===null?a(new Error(`UserTask with instance ID "${i.flowNodeInstanceId}" does not exist.`)):r(f)},{identity:t}),p=(await Z({processInstanceId:s,flowNodeId:n,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:t})).userTasks[0];p&&(o.notification.removeSubscription(l,t),r(p))})}async function Le(e,t,s,n){await o.userTasks.finishUserTask(e,t,n);let r=await o.userTasks.query({flowNodeId:s,state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},{identity:n});return r.userTasks.length===0?null:r.userTasks[0]}async function Z(...e){return await o.userTasks.query(...e)}async function Oe(e){return await o.userTasks.query({state:c.FlowNodeInstances.FlowNodeInstanceState.suspended},e)}async function be(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 Q(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 ve(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 We(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 z,PHASE_PRODUCTION_SERVER as ee}from"next/dist/shared/lib/constants";function Je(e={}){let{applicationSdk:t,...s}=e;return async(n,r)=>{let a=n===z||n===ee;return t?.useExternalTasks&&a&&await N(t?.customExternalTasksDirPath),s}}import{revalidatePath as te}from"next/cache";import{redirect as se}from"next/navigation";function st(e){te(e),se(e)}async function ot(...e){return await o.processModels.startProcessInstance(...e)}async function ct(...e){await o.userTasks.finishUserTask(...e)}export{ct as finishUserTask,Le as finishUserTaskAndGetNext,he as getActiveProcessInstances,We as getAssignedUserTasksByIdentity,we as getEngineClient,Se as getIdentity,ve as getReservedUserTasksByIdentity,Z as getUserTasks,Q as getWaitingUserTaskByFlowNodeInstanceId,Oe as getWaitingUserTasks,Me as getWaitingUserTasksByCorrelationId,De as getWaitingUserTasksByFlowNodeId,be as getWaitingUserTasksByProcessInstanceId,st as navigateToUrl,ot as startProcess,Ae as waitForUserTask,Je as withApplicationSdk};
|
|
@@ -6,9 +6,3 @@ export type ExternalTaskConfig = Omit<IExternalTaskWorkerConfig, 'identity' | 'w
|
|
|
6
6
|
* @returns {Promise<void>} A promise that resolves when the external tasks are subscribed
|
|
7
7
|
* */
|
|
8
8
|
export declare function subscribeToExternalTasks(customExternalTasksDirPath?: string): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Require a module from a string.
|
|
11
|
-
* @param {string} src The source code of the module
|
|
12
|
-
* @param {string} filename The filename of the module
|
|
13
|
-
* @returns The module exports of the module
|
|
14
|
-
* */
|