@lssm/lib.workflow-composer 0.0.0-canary-20251206160926
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/README.md +32 -0
- package/dist/composer.d.ts +12 -0
- package/dist/composer.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/injector.d.ts +7 -0
- package/dist/injector.js +1 -0
- package/dist/merger.d.ts +6 -0
- package/dist/merger.js +1 -0
- package/dist/templates.d.ts +14 -0
- package/dist/templates.js +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/validator.d.ts +11 -0
- package/dist/validator.js +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @lssm/lib.workflow-composer
|
|
2
|
+
|
|
3
|
+
Compose base WorkflowSpecs with tenant-, role-, or device-specific extensions. The composer lets teams inject steps, hide portions of a workflow, and attach tenant-scoped metadata without duplicating base definitions.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
|
|
7
|
+
- Type-safe `extendWorkflow` helper.
|
|
8
|
+
- Registry for extension templates (tenant, role, device scopes).
|
|
9
|
+
- Validation to ensure injected steps reference valid anchors.
|
|
10
|
+
- Merge utilities to combine overlays coming from tenant + user.
|
|
11
|
+
|
|
12
|
+
Refer to `docs/tech/personalization/workflow-composition.md` for more.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComposeParams, WorkflowExtension } from "./types.js";
|
|
2
|
+
import { WorkflowSpec } from "@lssm/lib.contracts/workflow/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/composer.d.ts
|
|
5
|
+
declare class WorkflowComposer {
|
|
6
|
+
private readonly extensions;
|
|
7
|
+
register(extension: WorkflowExtension): this;
|
|
8
|
+
registerMany(extensions: WorkflowExtension[]): this;
|
|
9
|
+
compose(params: ComposeParams): WorkflowSpec;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { WorkflowComposer };
|
package/dist/composer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{applyWorkflowExtension as e}from"./injector.js";var t=class{extensions=[];register(e){return this.extensions.push(e),this}registerMany(e){return e.forEach(e=>this.register(e)),this}compose(t){return this.extensions.filter(e=>n(t,e)).sort((e,t)=>(e.priority??0)-(t.priority??0)).reduce((t,n)=>e(t,n),t.base)}};function n(e,t){return!(t.workflow!==e.base.meta.name||t.baseVersion&&t.baseVersion!==e.base.meta.version||t.tenantId&&t.tenantId!==e.tenantId||t.role&&t.role!==e.role||t.device&&t.device!==e.device)}export{t as WorkflowComposer};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComposeParams, StepInjection, WorkflowExtension, WorkflowExtensionScope } from "./types.js";
|
|
2
|
+
import { StepTemplateOptions, approvalStepTemplate } from "./templates.js";
|
|
3
|
+
import { applyWorkflowExtension } from "./injector.js";
|
|
4
|
+
import { WorkflowComposer } from "./composer.js";
|
|
5
|
+
import { WorkflowExtensionValidationIssue, validateExtension } from "./validator.js";
|
|
6
|
+
import { mergeExtensions } from "./merger.js";
|
|
7
|
+
export { ComposeParams, StepInjection, StepTemplateOptions, WorkflowComposer, WorkflowExtension, WorkflowExtensionScope, WorkflowExtensionValidationIssue, applyWorkflowExtension, approvalStepTemplate, mergeExtensions, validateExtension };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{approvalStepTemplate as e}from"./templates.js";import{validateExtension as t}from"./validator.js";import{applyWorkflowExtension as n}from"./injector.js";import{WorkflowComposer as r}from"./composer.js";import{mergeExtensions as i}from"./merger.js";export{r as WorkflowComposer,n as applyWorkflowExtension,e as approvalStepTemplate,i as mergeExtensions,t as validateExtension};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WorkflowExtension } from "./types.js";
|
|
2
|
+
import { WorkflowSpec } from "@lssm/lib.contracts/workflow/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/injector.d.ts
|
|
5
|
+
declare function applyWorkflowExtension(base: WorkflowSpec, extension: WorkflowExtension): WorkflowSpec;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { applyWorkflowExtension };
|
package/dist/injector.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{validateExtension as e}from"./validator.js";function t(t,r){e(r,t);let s=o(t),c=[...s.definition.steps],l=[...s.definition.transitions],u=new Set(r.hiddenSteps??[]);return u.forEach(e=>{let t=c.findIndex(t=>t.id===e);t!==-1&&c.splice(t,1)}),u.size&&(l=l.filter(e=>!u.has(e.from)&&!u.has(e.to))),r.customSteps?.forEach(e=>{n(c,e),i(l,e)}),s.definition.steps=c,s.definition.transitions=a(l),s.meta={...s.meta,version:s.meta.version},s}function n(e,t){let n=r(e,t);if(n===-1)throw Error(`Unable to place injected step "${t.inject.id}"`);e.splice(n,0,{...t.inject})}function r(e,t){if(t.after){let n=e.findIndex(e=>e.id===t.after);return n===-1?-1:n+1}if(t.before){let n=e.findIndex(e=>e.id===t.before);return n===-1?-1:n}return e.length}function i(e,t){t.inject.id&&(t.transitionFrom&&e.push({from:t.transitionFrom,to:t.inject.id,condition:t.when}),t.transitionTo&&e.push({from:t.inject.id,to:t.transitionTo,condition:t.when}))}function a(e){let t=new Set,n=[];return e.forEach(e=>{let r=`${e.from}->${e.to}:${e.condition??``}`;t.has(r)||(t.add(r),n.push(e))}),n}function o(e){return JSON.parse(JSON.stringify(e))}export{t as applyWorkflowExtension};
|
package/dist/merger.d.ts
ADDED
package/dist/merger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e.sort((e,t)=>(e.priority??0)-(t.priority??0))}export{e as mergeExtensions};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Step, StepAction, StepType } from "@lssm/lib.contracts/workflow/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/templates.d.ts
|
|
4
|
+
interface StepTemplateOptions {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
type?: StepType;
|
|
8
|
+
description?: string;
|
|
9
|
+
action?: StepAction;
|
|
10
|
+
guardExpression?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function approvalStepTemplate(options: StepTemplateOptions): Step;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { StepTemplateOptions, approvalStepTemplate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return{id:e.id,label:e.label,type:e.type??`human`,description:e.description??`Tenant-specific approval`,action:e.action,guard:e.guardExpression?{type:`expression`,value:e.guardExpression}:void 0}}export{e as approvalStepTemplate};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Step, WorkflowSpec } from "@lssm/lib.contracts/workflow/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
interface WorkflowExtensionScope {
|
|
5
|
+
tenantId?: string;
|
|
6
|
+
role?: string;
|
|
7
|
+
device?: string;
|
|
8
|
+
}
|
|
9
|
+
interface StepInjection {
|
|
10
|
+
id?: string;
|
|
11
|
+
after?: string;
|
|
12
|
+
before?: string;
|
|
13
|
+
inject: Step;
|
|
14
|
+
when?: string;
|
|
15
|
+
transitionTo?: string;
|
|
16
|
+
transitionFrom?: string;
|
|
17
|
+
}
|
|
18
|
+
interface WorkflowExtension extends WorkflowExtensionScope {
|
|
19
|
+
workflow: string;
|
|
20
|
+
baseVersion?: number;
|
|
21
|
+
priority?: number;
|
|
22
|
+
customSteps?: StepInjection[];
|
|
23
|
+
hiddenSteps?: string[];
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
annotations?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface ComposeParams extends WorkflowExtensionScope {
|
|
28
|
+
base: WorkflowSpec;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ComposeParams, StepInjection, WorkflowExtension, WorkflowExtensionScope };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkflowExtension } from "./types.js";
|
|
2
|
+
import { WorkflowSpec } from "@lssm/lib.contracts/workflow/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/validator.d.ts
|
|
5
|
+
interface WorkflowExtensionValidationIssue {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
declare function validateExtension(extension: WorkflowExtension, base: WorkflowSpec): void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { WorkflowExtensionValidationIssue, validateExtension };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){let n=[],r=new Set(t.definition.steps.map(e=>e.id));if(e.customSteps?.forEach((e,t)=>{e.inject.id||n.push({code:`workflow.extension.step.id`,message:`customSteps[${t}] is missing an id`}),!e.after&&!e.before&&n.push({code:`workflow.extension.step.anchor`,message:`customSteps[${t}] must set after or before`}),e.after&&!r.has(e.after)&&n.push({code:`workflow.extension.step.after`,message:`customSteps[${t}] references unknown step "${e.after}"`}),e.before&&!r.has(e.before)&&n.push({code:`workflow.extension.step.before`,message:`customSteps[${t}] references unknown step "${e.before}"`})}),e.hiddenSteps?.forEach(e=>{r.has(e)||n.push({code:`workflow.extension.hidden-step`,message:`hidden step "${e}" does not exist`})}),n.length){let t=n.map(e=>`${e.code}: ${e.message}`).join(`; `);throw Error(`Invalid workflow extension for ${e.workflow}: ${t}`)}}export{e as validateExtension};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lssm/lib.workflow-composer",
|
|
3
|
+
"version": "0.0.0-canary-20251206160926",
|
|
4
|
+
"description": "Tenant-aware workflow composition helpers for ContractSpec.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
15
|
+
"build": "bun build:bundle && bun build:types",
|
|
16
|
+
"build:bundle": "tsdown",
|
|
17
|
+
"build:types": "tsc --noEmit",
|
|
18
|
+
"dev": "bun build:bundle --watch",
|
|
19
|
+
"clean": "rimraf dist .turbo",
|
|
20
|
+
"lint": "bun lint:fix",
|
|
21
|
+
"lint:fix": "eslint src --fix",
|
|
22
|
+
"lint:check": "eslint src",
|
|
23
|
+
"test": "bun run"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@lssm/lib.contracts": "workspace:*"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@lssm/tool.tsdown": "workspace:*",
|
|
30
|
+
"@lssm/tool.typescript": "workspace:*",
|
|
31
|
+
"tsdown": "^0.17.0",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js",
|
|
36
|
+
"./*": "./*"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|