@lssm/lib.overlay-engine 0.1.2 → 0.2.0

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.
@@ -0,0 +1,8 @@
1
+ import { AddHelpTextModification, HideFieldModification, MakeRequiredModification, OVERLAY_SCOPE_ORDER, OverlayAppliesTo, OverlayFieldModificationBase, OverlayInput, OverlayModification, OverlayScopeContext, OverlayScopeKey, OverlaySignatureAlgorithm, OverlaySignatureBlock, OverlaySpec, OverlayTargetRef, RenameLabelModification, ReorderFieldsModification, SetDefaultModification, SignedOverlaySpec, defineOverlay } from "./spec.js";
2
+ import { OverlayAuditEvent, OverlayLayoutConfig, OverlayMatchContext, OverlayRenderable, OverlayRenderableField } from "./types.js";
3
+ import { OverlayValidationIssue, OverlayValidationResult, OverlayValidator, assertOverlayValid, defaultOverlayValidator, validateOverlaySpec } from "./validator.js";
4
+ import { OverlayLookup, OverlayRegistry, OverlayRegistryOptions } from "./registry.js";
5
+ import { ApplyOverlayOptions, applyOverlayModifications } from "./merger.js";
6
+ import { OverlayApplyParams, OverlayEngine, OverlayEngineOptions, OverlayRuntimeResult } from "./runtime.js";
7
+ import { SignOverlayOptions, canonicalizeOverlay, signOverlay, stripSignature, verifyOverlaySignature } from "./signer.js";
8
+ export { AddHelpTextModification, ApplyOverlayOptions, HideFieldModification, MakeRequiredModification, OVERLAY_SCOPE_ORDER, OverlayAppliesTo, OverlayApplyParams, OverlayAuditEvent, OverlayEngine, OverlayEngineOptions, OverlayFieldModificationBase, OverlayInput, OverlayLayoutConfig, OverlayLookup, OverlayMatchContext, OverlayModification, OverlayRegistry, OverlayRegistryOptions, OverlayRenderable, OverlayRenderableField, OverlayRuntimeResult, OverlayScopeContext, OverlayScopeKey, OverlaySignatureAlgorithm, OverlaySignatureBlock, OverlaySpec, OverlayTargetRef, OverlayValidationIssue, OverlayValidationResult, OverlayValidator, RenameLabelModification, ReorderFieldsModification, SetDefaultModification, SignOverlayOptions, SignedOverlaySpec, applyOverlayModifications, assertOverlayValid, canonicalizeOverlay, defaultOverlayValidator, defineOverlay, signOverlay, stripSignature, validateOverlaySpec, verifyOverlaySignature };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{OVERLAY_SCOPE_ORDER as e,defineOverlay as t}from"./spec.js";import{assertOverlayValid as n,defaultOverlayValidator as r,validateOverlaySpec as i}from"./validator.js";import{OverlayRegistry as a}from"./registry.js";import{applyOverlayModifications as o}from"./merger.js";import{OverlayEngine as s}from"./runtime.js";import{canonicalizeOverlay as c,signOverlay as l,stripSignature as u,verifyOverlaySignature as d}from"./signer.js";export{e as OVERLAY_SCOPE_ORDER,s as OverlayEngine,a as OverlayRegistry,o as applyOverlayModifications,n as assertOverlayValid,c as canonicalizeOverlay,r as defaultOverlayValidator,t as defineOverlay,l as signOverlay,u as stripSignature,i as validateOverlaySpec,d as verifyOverlaySignature};
@@ -0,0 +1,11 @@
1
+ import { SignedOverlaySpec } from "./spec.js";
2
+ import { OverlayRenderable } from "./types.js";
3
+
4
+ //#region src/merger.d.ts
5
+ interface ApplyOverlayOptions {
6
+ strict?: boolean;
7
+ }
8
+ declare function applyOverlayModifications<T extends OverlayRenderable>(target: T, overlays: SignedOverlaySpec[], options?: ApplyOverlayOptions): T;
9
+ //#endregion
10
+ export { ApplyOverlayOptions, applyOverlayModifications };
11
+ //# sourceMappingURL=merger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merger.d.ts","names":[],"sources":["../src/merger.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,mBAAA;;AAAjB;AAUgB,iBAAA,yBAAyB,CAAA,UAAW,iBAAX,CAAA,CAAA,MAAA,EAC/B,CAD+B,EAAA,QAAA,EAE7B,iBAF6B,EAAA,EAAA,OAAA,CAAA,EAG9B,mBAH8B,CAAA,EAItC,CAJsC"}
package/dist/merger.js ADDED
@@ -0,0 +1,2 @@
1
+ function e(e,r,i={}){if(!r.length)return e;let a=e.fields.map(e=>({key:e.key,field:{...e},hidden:e.visible===!1})),o=new Map(a.map(e=>[e.key,e])),s=e.fields.map(e=>e.key),c=(e,t)=>{if(i.strict)throw Error(`Overlay "${t}" referenced unknown field "${e}".`)};r.forEach(e=>{e.modifications.forEach(r=>{switch(r.type){case`hideField`:{let t=o.get(r.field);if(!t)return c(r.field,e.overlayId);t.hidden=!0,t.field.visible=!1;break}case`renameLabel`:{let t=o.get(r.field);if(!t)return c(r.field,e.overlayId);t.field.label=r.newLabel;break}case`setDefault`:{let t=o.get(r.field);if(!t)return c(r.field,e.overlayId);t.field.defaultValue=r.value;break}case`addHelpText`:{let t=o.get(r.field);if(!t)return c(r.field,e.overlayId);t.field.helpText=r.text;break}case`makeRequired`:{let t=o.get(r.field);if(!t)return c(r.field,e.overlayId);t.field.required=r.required??!0;break}case`reorderFields`:{let{filtered:a,missing:l}=t(r.fields,o);l.length&&i.strict&&l.forEach(t=>c(t,e.overlayId)),s=n(s,a);break}default:break}})});let l=[],u=new Set;return s.forEach(e=>{let t=o.get(e);!t||t.hidden||(u.add(e),l.push(t.field))}),a.forEach(e=>{e.hidden||u.has(e.key)||l.push(e.field)}),l.forEach((e,t)=>{e.order=t,e.visible=!0}),{...e,fields:l}}function t(e,t){let n=[],r=[],i=new Set;return e.forEach(e=>{if(e?.trim()){if(!t.has(e)){r.push(e);return}i.has(e)||(i.add(e),n.push(e))}}),{filtered:n,missing:r}}function n(e,t){if(!t.length)return e;let n=new Set(t),r=e.filter(e=>!n.has(e));return[...t,...r]}export{e as applyOverlayModifications};
2
+ //# sourceMappingURL=merger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merger.js","names":["visibleFields: OverlayRenderableField[]","filtered: string[]","missing: string[]"],"sources":["../src/merger.ts"],"sourcesContent":["import type { SignedOverlaySpec } from './spec';\nimport type { OverlayRenderable, OverlayRenderableField } from './types';\n\nexport interface ApplyOverlayOptions {\n strict?: boolean;\n}\n\ninterface FieldState<TField extends OverlayRenderableField> {\n key: string;\n field: TField;\n hidden: boolean;\n}\n\nexport function applyOverlayModifications<T extends OverlayRenderable>(\n target: T,\n overlays: SignedOverlaySpec[],\n options: ApplyOverlayOptions = {}\n): T {\n if (!overlays.length) {\n return target;\n }\n\n const states = target.fields.map<FieldState<any>>((field) => ({\n key: field.key,\n field: { ...field },\n hidden: field.visible === false,\n }));\n\n const fieldMap = new Map(states.map((state) => [state.key, state]));\n let orderSequence = target.fields.map((field) => field.key);\n\n const handleMissing = (field: string, overlayId: string) => {\n if (options.strict) {\n throw new Error(\n `Overlay \"${overlayId}\" referenced unknown field \"${field}\".`\n );\n }\n };\n\n overlays.forEach((overlay) => {\n overlay.modifications.forEach((modification) => {\n switch (modification.type) {\n case 'hideField': {\n const state = fieldMap.get(modification.field);\n if (!state)\n return handleMissing(modification.field, overlay.overlayId);\n state.hidden = true;\n state.field.visible = false;\n break;\n }\n case 'renameLabel': {\n const state = fieldMap.get(modification.field);\n if (!state)\n return handleMissing(modification.field, overlay.overlayId);\n state.field.label = modification.newLabel;\n break;\n }\n case 'setDefault': {\n const state = fieldMap.get(modification.field);\n if (!state)\n return handleMissing(modification.field, overlay.overlayId);\n state.field.defaultValue = modification.value;\n break;\n }\n case 'addHelpText': {\n const state = fieldMap.get(modification.field);\n if (!state)\n return handleMissing(modification.field, overlay.overlayId);\n state.field.helpText = modification.text;\n break;\n }\n case 'makeRequired': {\n const state = fieldMap.get(modification.field);\n if (!state)\n return handleMissing(modification.field, overlay.overlayId);\n state.field.required = modification.required ?? true;\n break;\n }\n case 'reorderFields': {\n const { filtered, missing } = normalizeOrderList(\n modification.fields,\n fieldMap\n );\n if (missing.length && options.strict) {\n missing.forEach((field) => handleMissing(field, overlay.overlayId));\n }\n orderSequence = applyReorder(orderSequence, filtered);\n break;\n }\n default:\n break;\n }\n });\n });\n\n const visibleFields: OverlayRenderableField[] = [];\n const seen = new Set<string>();\n orderSequence.forEach((key) => {\n const state = fieldMap.get(key);\n if (!state || state.hidden) {\n return;\n }\n seen.add(key);\n visibleFields.push(state.field);\n });\n\n // Handle any fields introduced dynamically that were not part of the original sequence.\n states.forEach((state) => {\n if (state.hidden || seen.has(state.key)) {\n return;\n }\n visibleFields.push(state.field);\n });\n\n visibleFields.forEach((field, index) => {\n field.order = index;\n field.visible = true;\n });\n\n return {\n ...(target as T),\n fields: visibleFields as T['fields'],\n };\n}\n\nfunction normalizeOrderList(\n fields: string[],\n fieldMap: Map<string, FieldState<any>>\n): { filtered: string[]; missing: string[] } {\n const filtered: string[] = [];\n const missing: string[] = [];\n const seen = new Set<string>();\n\n fields.forEach((field) => {\n if (!field?.trim()) {\n return;\n }\n if (!fieldMap.has(field)) {\n missing.push(field);\n return;\n }\n if (seen.has(field)) {\n return;\n }\n seen.add(field);\n filtered.push(field);\n });\n\n return { filtered, missing };\n}\n\nfunction applyReorder(sequence: string[], orderedFields: string[]): string[] {\n if (!orderedFields.length) {\n return sequence;\n }\n const orderedSet = new Set(orderedFields);\n const remainder = sequence.filter((key) => !orderedSet.has(key));\n return [...orderedFields, ...remainder];\n}\n"],"mappings":"AAaA,SAAgB,EACd,EACA,EACA,EAA+B,EAAE,CAC9B,CACH,GAAI,CAAC,EAAS,OACZ,OAAO,EAGT,IAAM,EAAS,EAAO,OAAO,IAAsB,IAAW,CAC5D,IAAK,EAAM,IACX,MAAO,CAAE,GAAG,EAAO,CACnB,OAAQ,EAAM,UAAY,GAC3B,EAAE,CAEG,EAAW,IAAI,IAAI,EAAO,IAAK,GAAU,CAAC,EAAM,IAAK,EAAM,CAAC,CAAC,CAC/D,EAAgB,EAAO,OAAO,IAAK,GAAU,EAAM,IAAI,CAErD,GAAiB,EAAe,IAAsB,CAC1D,GAAI,EAAQ,OACV,MAAU,MACR,YAAY,EAAU,8BAA8B,EAAM,IAC3D,EAIL,EAAS,QAAS,GAAY,CAC5B,EAAQ,cAAc,QAAS,GAAiB,CAC9C,OAAQ,EAAa,KAArB,CACE,IAAK,YAAa,CAChB,IAAM,EAAQ,EAAS,IAAI,EAAa,MAAM,C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,EAAM,IAAI,EAGvC,EAAc,KAAK,EAAM,MAAM,EAC/B,CAEF,EAAc,SAAS,EAAO,IAAU,CACtC,EAAM,MAAQ,EACd,EAAM,QAAU,IAChB,CAEK,CACL,GAAI,EACJ,OAAQ,EACT,CAGH,SAAS,EACP,EACA,EAC2C,CAC3C,IAAMC,EAAqB,EAAE,CACvBC,EAAoB,EAAE,CACtB,EAAO,IAAI,IAiBjB,OAfA,EAAO,QAAS,GAAU,CACnB,MAAO,MAAM,CAGlB,IAAI,CAAC,EAAS,IAAI,EAAM,CAAE,CACxB,EAAQ,KAAK,EAAM,CACnB,OAEE,EAAK,IAAI,EAAM,GAGnB,EAAK,IAAI,EAAM,CACf,EAAS,KAAK,EAAM,IACpB,CAEK,CAAE,WAAU,UAAS,CAG9B,SAAS,EAAa,EAAoB,EAAmC,CAC3E,GAAI,CAAC,EAAc,OACjB,OAAO,EAET,IAAM,EAAa,IAAI,IAAI,EAAc,CACnC,EAAY,EAAS,OAAQ,GAAQ,CAAC,EAAW,IAAI,EAAI,CAAC,CAChE,MAAO,CAAC,GAAG,EAAe,GAAG,EAAU"}
@@ -0,0 +1,10 @@
1
+ import { OverlayRenderable } from "./types.js";
2
+ import { OverlayApplyParams, OverlayEngine, OverlayRuntimeResult } from "./runtime.js";
3
+ import { DependencyList } from "react";
4
+
5
+ //#region src/react.d.ts
6
+ declare function useOverlay<T extends OverlayRenderable>(engine: OverlayEngine | undefined, params: OverlayApplyParams<T>, deps?: DependencyList): OverlayRuntimeResult<T>;
7
+ declare function useOverlayFields<T extends OverlayRenderable>(engine: OverlayEngine | undefined, params: OverlayApplyParams<T>, deps?: DependencyList): T['fields'];
8
+ //#endregion
9
+ export { useOverlay, useOverlayFields };
10
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../src/react.ts"],"sourcesContent":[],"mappings":";;;;;iBAKgB,qBAAqB,2BAC3B,mCACA,mBAAmB,WACrB,iBACL,qBAAqB;AAJR,iBAgBA,gBAhBU,CAAA,UAgBiB,iBAhBjB,CAAA,CAAA,MAAA,EAiBhB,aAjBgB,GAAA,SAAA,EAAA,MAAA,EAkBhB,kBAlBgB,CAkBG,CAlBH,CAAA,EAAA,IAAA,CAAA,EAmBlB,cAnBkB,CAAA,EAoBvB,CApBuB,CAAA,QAAA,CAAA"}
package/dist/react.js ADDED
@@ -0,0 +1,2 @@
1
+ import{useMemo as e}from"react";function t(t,n,r=[]){return e(()=>t?t.apply(n):{target:n.target,overlaysApplied:[]},[t,n,...r])}function n(e,n,r=[]){return t(e,n,r).target.fields}export{t as useOverlay,n as useOverlayFields};
2
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":[],"sources":["../src/react.ts"],"sourcesContent":["import { useMemo, type DependencyList } from 'react';\nimport type { OverlayRenderable } from './types';\nimport type { OverlayApplyParams, OverlayRuntimeResult } from './runtime';\nimport { OverlayEngine } from './runtime';\n\nexport function useOverlay<T extends OverlayRenderable>(\n engine: OverlayEngine | undefined,\n params: OverlayApplyParams<T>,\n deps: DependencyList = []\n): OverlayRuntimeResult<T> {\n return useMemo(() => {\n if (!engine) {\n return {\n target: params.target,\n overlaysApplied: [],\n };\n }\n return engine.apply(params);\n }, [engine, params, ...deps]);\n}\n\nexport function useOverlayFields<T extends OverlayRenderable>(\n engine: OverlayEngine | undefined,\n params: OverlayApplyParams<T>,\n deps: DependencyList = []\n): T['fields'] {\n const result = useOverlay(engine, params, deps);\n return result.target.fields;\n}\n"],"mappings":"gCAKA,SAAgB,EACd,EACA,EACA,EAAuB,EAAE,CACA,CACzB,OAAO,MACA,EAME,EAAO,MAAM,EAAO,CALlB,CACL,OAAQ,EAAO,OACf,gBAAiB,EAAE,CACpB,CAGF,CAAC,EAAQ,EAAQ,GAAG,EAAK,CAAC,CAG/B,SAAgB,EACd,EACA,EACA,EAAuB,EAAE,CACZ,CAEb,OADe,EAAW,EAAQ,EAAQ,EAAK,CACjC,OAAO"}
@@ -0,0 +1,28 @@
1
+ import { OverlayInput, OverlayScopeContext, OverlayTargetRef, SignedOverlaySpec } from "./spec.js";
2
+ import { OverlayValidator } from "./validator.js";
3
+
4
+ //#region src/registry.d.ts
5
+ interface OverlayRegistryOptions {
6
+ validator?: OverlayValidator;
7
+ allowUnsigned?: boolean;
8
+ }
9
+ interface OverlayLookup extends OverlayScopeContext, OverlayTargetRef {}
10
+ declare class OverlayRegistry {
11
+ private readonly options;
12
+ private readonly overlays;
13
+ constructor(options?: OverlayRegistryOptions);
14
+ register(overlay: OverlayInput, options?: {
15
+ skipValidation?: boolean;
16
+ }): SignedOverlaySpec;
17
+ unregister(overlayId: string, version?: string): void;
18
+ list(): SignedOverlaySpec[];
19
+ get(overlayId: string, version: string): SignedOverlaySpec | undefined;
20
+ forContext(query: OverlayLookup): SignedOverlaySpec[];
21
+ clear(): void;
22
+ size(): number;
23
+ private ensureSigned;
24
+ private getKey;
25
+ }
26
+ //#endregion
27
+ export { OverlayLookup, OverlayRegistry, OverlayRegistryOptions };
28
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../src/registry.ts"],"sourcesContent":[],"mappings":";;;;UAUiB,sBAAA;cACH;EADG,aAAA,CAAA,EAAA,OAAA;AAKjB;AAwBa,UAxBI,aAAA,SAAsB,mBAwBX,EAxBgC,gBAwBhC,CAAA;AAMf,cANA,eAAA,CAMA;EAER,iBAAA,OAAA;EAsCK,iBAAA,QAAA;EAIiC,WAAA,CAAA,OAAA,CAAA,EA/CH,sBA+CG;EAIvB,QAAA,CAAA,OAAA,EAhDP,YAgDO,EAAA,OAAiC,CAAjC,EAAA;IAAgB,cAAA,CAAA,EAAA,OAAA;EAAiB,CAAA,CAAA,EA9ChD,iBA8CgD;;UAR3C;2CAIiC;oBAIvB,gBAAgB"}
@@ -0,0 +1,2 @@
1
+ import{defaultOverlayValidator as e}from"./validator.js";const t=[`capability`,`workflow`,`dataView`,`presentation`,`operation`],n={tenantId:8,role:4,userId:16,device:2,tags:1};var r=class{overlays=new Map;constructor(e={}){this.options=e}register(t,n){if(!n?.skipValidation){let n=(this.options.validator??e)(t);if(!n.valid){let e=n.issues.map(e=>`${e.code}: ${e.message}`).join(`; `);throw Error(`Overlay "${t.overlayId}" failed validation: ${e}`)}}let r=this.ensureSigned(t),i=this.getKey(r.overlayId,r.version),o={overlay:r,specificity:a(r.appliesTo),registeredAt:Date.now()};return this.overlays.set(i,o),r}unregister(e,t){if(t){this.overlays.delete(this.getKey(e,t));return}for(let t of Array.from(this.overlays.keys()))t.startsWith(`${e}@`)&&this.overlays.delete(t)}list(){return Array.from(this.overlays.values()).map(e=>e.overlay)}get(e,t){return this.overlays.get(this.getKey(e,t))?.overlay}forContext(e){return Array.from(this.overlays.values()).filter(t=>o(t.overlay.appliesTo,e)).sort((e,t)=>e.specificity===t.specificity?e.registeredAt-t.registeredAt:e.specificity-t.specificity).map(e=>e.overlay)}clear(){this.overlays.clear()}size(){return this.overlays.size}ensureSigned(e){if(i(e)){if(!e.signature?.signature&&!this.options.allowUnsigned)throw Error(`Overlay "${e.overlayId}" is missing a signature.`);return e}if(!this.options.allowUnsigned)throw Error(`Overlay "${e.overlayId}" must be signed before registration.`);return e}getKey(e,t){return`${e}@${t}`}};function i(e){return!!e.signature}function a(e){let t=0;return Object.keys(n).forEach(r=>{(r===`tags`?Array.isArray(e.tags)&&e.tags.length>0:e[r])&&(t+=n[r])}),t}function o(e,n){for(let r of t){let t=e[r];if(t&&t!==n[r])return!1}if(e.tenantId&&e.tenantId!==n.tenantId||e.role&&e.role!==n.role||e.userId&&e.userId!==n.userId||e.device&&e.device!==n.device)return!1;if(e.tags?.length){if(!n.tags?.length)return!1;let t=new Set(n.tags);if(!e.tags.every(e=>t.has(e)))return!1}return!0}export{r as OverlayRegistry};
2
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","names":["TARGET_KEYS: (keyof OverlayTargetRef)[]","SCOPE_WEIGHTS: Record<keyof OverlayScopeContext, number>","options: OverlayRegistryOptions","stored: StoredOverlay"],"sources":["../src/registry.ts"],"sourcesContent":["import type {\n OverlayInput,\n OverlayAppliesTo,\n OverlayScopeContext,\n OverlayTargetRef,\n SignedOverlaySpec,\n} from './spec';\nimport type { OverlayValidator } from './validator';\nimport { defaultOverlayValidator } from './validator';\n\nexport interface OverlayRegistryOptions {\n validator?: OverlayValidator;\n allowUnsigned?: boolean;\n}\n\nexport interface OverlayLookup extends OverlayScopeContext, OverlayTargetRef {}\n\ninterface StoredOverlay {\n overlay: SignedOverlaySpec;\n specificity: number;\n registeredAt: number;\n}\n\nconst TARGET_KEYS: (keyof OverlayTargetRef)[] = [\n 'capability',\n 'workflow',\n 'dataView',\n 'presentation',\n 'operation',\n];\n\nconst SCOPE_WEIGHTS: Record<keyof OverlayScopeContext, number> = {\n tenantId: 8,\n role: 4,\n userId: 16,\n device: 2,\n tags: 1,\n};\n\nexport class OverlayRegistry {\n private readonly overlays = new Map<string, StoredOverlay>();\n\n constructor(private readonly options: OverlayRegistryOptions = {}) {}\n\n register(\n overlay: OverlayInput,\n options?: { skipValidation?: boolean }\n ): SignedOverlaySpec {\n if (!options?.skipValidation) {\n const validator = this.options.validator ?? defaultOverlayValidator;\n const result = validator(overlay as SignedOverlaySpec);\n if (!result.valid) {\n const reason = result.issues\n .map((issue) => `${issue.code}: ${issue.message}`)\n .join('; ');\n throw new Error(\n `Overlay \"${overlay.overlayId}\" failed validation: ${reason}`\n );\n }\n }\n\n const normalized = this.ensureSigned(overlay);\n const key = this.getKey(normalized.overlayId, normalized.version);\n const stored: StoredOverlay = {\n overlay: normalized,\n specificity: computeSpecificity(normalized.appliesTo),\n registeredAt: Date.now(),\n };\n this.overlays.set(key, stored);\n return normalized;\n }\n\n unregister(overlayId: string, version?: string) {\n if (version) {\n this.overlays.delete(this.getKey(overlayId, version));\n return;\n }\n\n for (const key of Array.from(this.overlays.keys())) {\n if (key.startsWith(`${overlayId}@`)) {\n this.overlays.delete(key);\n }\n }\n }\n\n list(): SignedOverlaySpec[] {\n return Array.from(this.overlays.values()).map((entry) => entry.overlay);\n }\n\n get(overlayId: string, version: string): SignedOverlaySpec | undefined {\n return this.overlays.get(this.getKey(overlayId, version))?.overlay;\n }\n\n forContext(query: OverlayLookup): SignedOverlaySpec[] {\n return Array.from(this.overlays.values())\n .filter((entry) => matches(entry.overlay.appliesTo, query))\n .sort((a, b) => {\n if (a.specificity !== b.specificity) {\n return a.specificity - b.specificity;\n }\n return a.registeredAt - b.registeredAt;\n })\n .map((entry) => entry.overlay);\n }\n\n clear() {\n this.overlays.clear();\n }\n\n size(): number {\n return this.overlays.size;\n }\n\n private ensureSigned(input: OverlayInput): SignedOverlaySpec {\n if (isSignedOverlay(input)) {\n if (!input.signature?.signature && !this.options.allowUnsigned) {\n throw new Error(`Overlay \"${input.overlayId}\" is missing a signature.`);\n }\n return input;\n }\n\n if (!this.options.allowUnsigned) {\n throw new Error(\n `Overlay \"${input.overlayId}\" must be signed before registration.`\n );\n }\n\n return input as SignedOverlaySpec;\n }\n\n private getKey(overlayId: string, version: string) {\n return `${overlayId}@${version}`;\n }\n}\n\nfunction isSignedOverlay(spec: OverlayInput): spec is SignedOverlaySpec {\n return Boolean((spec as SignedOverlaySpec).signature);\n}\n\nfunction computeSpecificity(appliesTo: OverlayAppliesTo): number {\n let score = 0;\n (Object.keys(SCOPE_WEIGHTS) as (keyof OverlayScopeContext)[]).forEach(\n (key) => {\n const hasValue =\n key === 'tags'\n ? Array.isArray(appliesTo.tags) && appliesTo.tags.length > 0\n : Boolean(appliesTo[key]);\n if (hasValue) {\n score += SCOPE_WEIGHTS[key];\n }\n }\n );\n return score;\n}\n\nfunction matches(appliesTo: OverlayAppliesTo, ctx: OverlayLookup): boolean {\n for (const key of TARGET_KEYS) {\n const expected = appliesTo[key];\n if (expected && expected !== ctx[key]) {\n return false;\n }\n }\n\n if (appliesTo.tenantId && appliesTo.tenantId !== ctx.tenantId) {\n return false;\n }\n if (appliesTo.role && appliesTo.role !== ctx.role) {\n return false;\n }\n if (appliesTo.userId && appliesTo.userId !== ctx.userId) {\n return false;\n }\n if (appliesTo.device && appliesTo.device !== ctx.device) {\n return false;\n }\n if (appliesTo.tags?.length) {\n if (!ctx.tags?.length) {\n return false;\n }\n const ctxTags = new Set(ctx.tags);\n const satisfies = appliesTo.tags.every((tag) => ctxTags.has(tag));\n if (!satisfies) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":"yDAuBA,MAAMA,EAA0C,CAC9C,aACA,WACA,WACA,eACA,YACD,CAEKC,EAA2D,CAC/D,SAAU,EACV,KAAM,EACN,OAAQ,GACR,OAAQ,EACR,KAAM,EACP,CAED,IAAa,EAAb,KAA6B,CAC3B,SAA4B,IAAI,IAEhC,YAAY,EAAmD,EAAE,CAAE,CAAtC,KAAA,QAAA,EAE7B,SACE,EACA,EACmB,CACnB,GAAI,CAAC,GAAS,eAAgB,CAE5B,IAAM,GADY,KAAK,QAAQ,WAAa,GACnB,EAA6B,CACtD,GAAI,CAAC,EAAO,MAAO,CACjB,IAAM,EAAS,EAAO,OACnB,IAAK,GAAU,GAAG,EAAM,KAAK,IAAI,EAAM,UAAU,CACjD,KAAK,KAAK,CACb,MAAU,MACR,YAAY,EAAQ,UAAU,uBAAuB,IACtD,EAIL,IAAM,EAAa,KAAK,aAAa,EAAQ,CACvC,EAAM,KAAK,OAAO,EAAW,UAAW,EAAW,QAAQ,CAC3DE,EAAwB,CAC5B,QAAS,EACT,YAAa,EAAmB,EAAW,UAAU,CACrD,aAAc,KAAK,KAAK,CACzB,CAED,OADA,KAAK,SAAS,IAAI,EAAK,EAAO,CACvB,EAGT,WAAW,EAAmB,EAAkB,CAC9C,GAAI,EAAS,CACX,KAAK,SAAS,OAAO,KAAK,OAAO,EAAW,EAAQ,CAAC,CACrD,OAGF,IAAK,IAAM,KAAO,MAAM,KAAK,KAAK,SAAS,MAA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AAO,EAAa,CAC7B,IAAM,EAAW,EAAU,GAC3B,GAAI,GAAY,IAAa,EAAI,GAC/B,MAAO,GAaX,GATI,EAAU,UAAY,EAAU,WAAa,EAAI,UAGjD,EAAU,MAAQ,EAAU,OAAS,EAAI,MAGzC,EAAU,QAAU,EAAU,SAAW,EAAI,QAG7C,EAAU,QAAU,EAAU,SAAW,EAAI,OAC/C,MAAO,GAET,GAAI,EAAU,MAAM,OAAQ,CAC1B,GAAI,CAAC,EAAI,MAAM,OACb,MAAO,GAET,IAAM,EAAU,IAAI,IAAI,EAAI,KAAK,CAEjC,GAAI,CADc,EAAU,KAAK,MAAO,GAAQ,EAAQ,IAAI,EAAI,CAAC,CAE/D,MAAO,GAIX,MAAO"}
@@ -0,0 +1,28 @@
1
+ import { SignedOverlaySpec } from "./spec.js";
2
+ import { OverlayAuditEvent, OverlayRenderable } from "./types.js";
3
+ import { OverlayLookup, OverlayRegistry } from "./registry.js";
4
+ import { ApplyOverlayOptions } from "./merger.js";
5
+
6
+ //#region src/runtime.d.ts
7
+ interface OverlayEngineOptions {
8
+ registry: OverlayRegistry;
9
+ audit?: (event: OverlayAuditEvent) => void;
10
+ }
11
+ interface OverlayApplyParams<T extends OverlayRenderable> extends OverlayLookup {
12
+ target: T;
13
+ overlays?: SignedOverlaySpec[];
14
+ strict?: ApplyOverlayOptions['strict'];
15
+ }
16
+ interface OverlayRuntimeResult<T extends OverlayRenderable> {
17
+ target: T;
18
+ overlaysApplied: SignedOverlaySpec[];
19
+ }
20
+ declare class OverlayEngine {
21
+ private readonly registry;
22
+ private readonly audit?;
23
+ constructor(options: OverlayEngineOptions);
24
+ apply<T extends OverlayRenderable>(params: OverlayApplyParams<T>): OverlayRuntimeResult<T>;
25
+ }
26
+ //#endregion
27
+ export { OverlayApplyParams, OverlayEngine, OverlayEngineOptions, OverlayRuntimeResult };
28
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","names":[],"sources":["../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;UAKiB,oBAAA;YACL;EADK,KAAA,CAAA,EAAA,CAAA,KAAA,EAEC,iBAFmB,EACzB,GAAA,IAAA;AAIZ;AAA8C,UAA7B,kBAA6B,CAAA,UAAA,iBAAA,CAAA,SACpC,aADoC,CAAA;EAEpC,MAAA,EAAA,CAAA;EACG,QAAA,CAAA,EAAA,iBAAA,EAAA;EACF,MAAA,CAAA,EAAA,mBAAA,CAAA,QAAA,CAAA;;AAHY,UAMN,oBANM,CAAA,UAMyB,iBANzB,CAAA,CAAA;EAMN,MAAA,EACP,CADO;EAA+B,eAAA,EAE7B,iBAF6B,EAAA;;AAE7B,cAGN,aAAA,CAHM;EAAiB,iBAAA,QAAA;EAGvB,iBAAa,KAAA;EAIH,WAAA,CAAA,OAAA,EAAA,oBAAA;EAKL,KAAA,CAAA,UAAA,iBAAA,CAAA,CAAA,MAAA,EACN,kBADM,CACa,CADb,CAAA,CAAA,EAEb,oBAFa,CAEQ,CAFR,CAAA"}
@@ -0,0 +1,2 @@
1
+ import{applyOverlayModifications as e}from"./merger.js";var t=class{registry;audit;constructor(e){this.registry=e.registry,this.audit=e.audit}apply(t){let r=t.overlays??this.registry.forContext({capability:t.capability,workflow:t.workflow,dataView:t.dataView,presentation:t.presentation,operation:t.operation,tenantId:t.tenantId,role:t.role,userId:t.userId,device:t.device,tags:t.tags}),i=e(t.target,r,{strict:t.strict}),a=n(t);return r.forEach(e=>{this.audit?.({overlay:{overlayId:e.overlayId,version:e.version},context:a,timestamp:new Date().toISOString()})}),{target:i,overlaysApplied:r}}};function n(e){return{tenantId:e.tenantId,role:e.role,userId:e.userId,device:e.device,tags:e.tags}}export{t as OverlayEngine};
2
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import { applyOverlayModifications, type ApplyOverlayOptions } from './merger';\nimport { OverlayRegistry, type OverlayLookup } from './registry';\nimport type { SignedOverlaySpec } from './spec';\nimport type { OverlayRenderable, OverlayAuditEvent } from './types';\n\nexport interface OverlayEngineOptions {\n registry: OverlayRegistry;\n audit?: (event: OverlayAuditEvent) => void;\n}\n\nexport interface OverlayApplyParams<T extends OverlayRenderable>\n extends OverlayLookup {\n target: T;\n overlays?: SignedOverlaySpec[];\n strict?: ApplyOverlayOptions['strict'];\n}\n\nexport interface OverlayRuntimeResult<T extends OverlayRenderable> {\n target: T;\n overlaysApplied: SignedOverlaySpec[];\n}\n\nexport class OverlayEngine {\n private readonly registry: OverlayRegistry;\n private readonly audit?: (event: OverlayAuditEvent) => void;\n\n constructor(options: OverlayEngineOptions) {\n this.registry = options.registry;\n this.audit = options.audit;\n }\n\n apply<T extends OverlayRenderable>(\n params: OverlayApplyParams<T>\n ): OverlayRuntimeResult<T> {\n const overlays =\n params.overlays ??\n this.registry.forContext({\n capability: params.capability,\n workflow: params.workflow,\n dataView: params.dataView,\n presentation: params.presentation,\n operation: params.operation,\n tenantId: params.tenantId,\n role: params.role,\n userId: params.userId,\n device: params.device,\n tags: params.tags,\n });\n\n const merged = applyOverlayModifications(params.target, overlays, {\n strict: params.strict,\n });\n\n const context = extractContext(params);\n overlays.forEach((overlay) => {\n this.audit?.({\n overlay: {\n overlayId: overlay.overlayId,\n version: overlay.version,\n },\n context,\n timestamp: new Date().toISOString(),\n });\n });\n\n return {\n target: merged,\n overlaysApplied: overlays,\n };\n }\n}\n\nfunction extractContext(params: OverlayLookup): OverlayAuditEvent['context'] {\n return {\n tenantId: params.tenantId,\n role: params.role,\n userId: params.userId,\n device: params.device,\n tags: params.tags,\n };\n}\n"],"mappings":"wDAsBA,IAAa,EAAb,KAA2B,CACzB,SACA,MAEA,YAAY,EAA+B,CACzC,KAAK,SAAW,EAAQ,SACxB,KAAK,MAAQ,EAAQ,MAGvB,MACE,EACyB,CACzB,IAAM,EACJ,EAAO,UACP,KAAK,SAAS,WAAW,CACvB,WAAY,EAAO,WACnB,SAAU,EAAO,SACjB,SAAU,EAAO,SACjB,aAAc,EAAO,aACrB,UAAW,EAAO,UAClB,SAAU,EAAO,SACjB,KAAM,EAAO,KACb,OAAQ,EAAO,OACf,OAAQ,EAAO,OACf,KAAM,EAAO,KACd,CAAC,CAEE,EAAS,EAA0B,EAAO,OAAQ,EAAU,CAChE,OAAQ,EAAO,OAChB,CAAC,CAEI,EAAU,EAAe,EAAO,CAYtC,OAXA,EAAS,QAAS,GAAY,CAC5B,KAAK,QAAQ,CACX,QAAS,CACP,UAAW,EAAQ,UACnB,QAAS,EAAQ,QAClB,CACD,UACA,UAAW,IAAI,MAAM,CAAC,aAAa,CACpC,CAAC,EACF,CAEK,CACL,OAAQ,EACR,gBAAiB,EAClB,GAIL,SAAS,EAAe,EAAqD,CAC3E,MAAO,CACL,SAAU,EAAO,SACjB,KAAM,EAAO,KACb,OAAQ,EAAO,OACf,OAAQ,EAAO,OACf,KAAM,EAAO,KACd"}
@@ -0,0 +1,19 @@
1
+ import { OverlaySignatureAlgorithm, OverlaySpec, SignedOverlaySpec } from "./spec.js";
2
+ import { KeyLike } from "crypto";
3
+
4
+ //#region src/signer.d.ts
5
+ interface SignOverlayOptions {
6
+ algorithm?: OverlaySignatureAlgorithm;
7
+ keyId?: string;
8
+ issuedAt?: Date | string;
9
+ expiresAt?: Date | string;
10
+ metadata?: Record<string, unknown>;
11
+ publicKey?: string;
12
+ }
13
+ declare function signOverlay(spec: OverlaySpec, privateKey: KeyLike | string | Buffer, options?: SignOverlayOptions): SignedOverlaySpec;
14
+ declare function verifyOverlaySignature(overlay: SignedOverlaySpec): boolean;
15
+ declare function canonicalizeOverlay(spec: OverlaySpec | SignedOverlaySpec): string;
16
+ declare function stripSignature<T extends OverlaySpec | SignedOverlaySpec>(spec: T): OverlaySpec;
17
+ //#endregion
18
+ export { SignOverlayOptions, canonicalizeOverlay, signOverlay, stripSignature, verifyOverlaySignature };
19
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","names":[],"sources":["../src/signer.ts"],"sourcesContent":[],"mappings":";;;;UAeiB,kBAAA;cACH;EADG,KAAA,CAAA,EAAA,MAAA;EACH,QAAA,CAAA,EAED,IAFC,GAAA,MAAA;EAED,SAAA,CAAA,EACC,IADD,GAAA,MAAA;EACC,QAAA,CAAA,EACD,MADC,CAAA,MAAA,EAAA,OAAA,CAAA;EACD,SAAA,CAAA,EAAA,MAAA;;AAIG,iBAAA,WAAA,CAAW,IAAA,EACnB,WADmB,EAAA,UAAA,EAEb,OAFa,GAAA,MAAA,GAEM,MAFN,EAAA,OAAA,CAAA,EAGhB,kBAHgB,CAAA,EAIxB,iBAJwB;AACnB,iBA4CQ,sBAAA,CA5CR,OAAA,EA4CwC,iBA5CxC,CAAA,EAAA,OAAA;AACM,iBA2EE,mBAAA,CA3EF,IAAA,EA4EN,WA5EM,GA4EQ,iBA5ER,CAAA,EAAA,MAAA;AAAmB,iBAkFjB,cAlFiB,CAAA,UAkFQ,WAlFR,GAkFsB,iBAlFtB,CAAA,CAAA,IAAA,EAmFzB,CAnFyB,CAAA,EAoF9B,WApF8B"}
package/dist/signer.js ADDED
@@ -0,0 +1,2 @@
1
+ import e from"fast-json-stable-stringify";import{constants as t,createPrivateKey as n,createPublicKey as r,sign as i,verify as a}from"crypto";function o(e,a,o={}){let s=o.algorithm??`ed25519`,l=typeof a==`string`||Buffer.isBuffer(a)?n(a):a,d=Buffer.from(c(e),`utf8`),f;if(s===`ed25519`)f=i(null,d,l);else if(s===`rsa-pss-sha256`)f=i(`sha256`,d,{key:l,padding:t.RSA_PKCS1_PSS_PADDING,saltLength:32});else throw Error(`Unsupported overlay signature algorithm: ${s}`);let p=o.publicKey??r(l).export({format:`pem`,type:`spki`}).toString();return{...e,signature:{algorithm:s,signature:f.toString(`base64`),publicKey:p,keyId:o.keyId,issuedAt:u(o.issuedAt)??new Date().toISOString(),expiresAt:u(o.expiresAt),metadata:o.metadata}}}function s(e){if(!e.signature?.signature)throw Error(`Overlay "${e.overlayId}" is missing signature metadata.`);let n=Buffer.from(c(e),`utf8`),i=Buffer.from(e.signature.signature,`base64`),o=r(e.signature.publicKey);if(e.signature.algorithm===`ed25519`)return a(null,n,o,i);if(e.signature.algorithm===`rsa-pss-sha256`)return a(`sha256`,n,{key:o,padding:t.RSA_PKCS1_PSS_PADDING,saltLength:32},i);throw Error(`Unsupported overlay signature algorithm: ${e.signature.algorithm}`)}function c(t){let{signature:n,...r}=t;return e(r)}function l(e){let{signature:t,...n}=e;return{...n}}function u(e){if(e)return typeof e==`string`?new Date(e).toISOString():e.toISOString()}export{c as canonicalizeOverlay,o as signOverlay,l as stripSignature,s as verifyOverlaySignature};
2
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","names":["rawSignature: Buffer"],"sources":["../src/signer.ts"],"sourcesContent":["import stringify from 'fast-json-stable-stringify';\nimport {\n constants,\n createPrivateKey,\n createPublicKey,\n type KeyLike,\n sign,\n verify,\n} from 'crypto';\nimport type {\n OverlaySignatureAlgorithm,\n OverlaySpec,\n SignedOverlaySpec,\n} from './spec';\n\nexport interface SignOverlayOptions {\n algorithm?: OverlaySignatureAlgorithm;\n keyId?: string;\n issuedAt?: Date | string;\n expiresAt?: Date | string;\n metadata?: Record<string, unknown>;\n publicKey?: string;\n}\n\nexport function signOverlay(\n spec: OverlaySpec,\n privateKey: KeyLike | string | Buffer,\n options: SignOverlayOptions = {}\n): SignedOverlaySpec {\n const algorithm = options.algorithm ?? 'ed25519';\n const keyObject =\n typeof privateKey === 'string' || Buffer.isBuffer(privateKey)\n ? createPrivateKey(privateKey)\n : privateKey;\n const payload = Buffer.from(canonicalizeOverlay(spec), 'utf8');\n\n let rawSignature: Buffer;\n if (algorithm === 'ed25519') {\n rawSignature = sign(null, payload, keyObject);\n } else if (algorithm === 'rsa-pss-sha256') {\n rawSignature = sign('sha256', payload, {\n key: keyObject,\n padding: constants.RSA_PKCS1_PSS_PADDING,\n saltLength: 32,\n });\n } else {\n throw new Error(`Unsupported overlay signature algorithm: ${algorithm}`);\n }\n\n const publicKey =\n options.publicKey ??\n createPublicKey(keyObject)\n .export({ format: 'pem', type: 'spki' })\n .toString();\n\n return {\n ...spec,\n signature: {\n algorithm,\n signature: rawSignature.toString('base64'),\n publicKey,\n keyId: options.keyId,\n issuedAt: toIso(options.issuedAt) ?? new Date().toISOString(),\n expiresAt: toIso(options.expiresAt),\n metadata: options.metadata,\n },\n };\n}\n\nexport function verifyOverlaySignature(overlay: SignedOverlaySpec): boolean {\n if (!overlay.signature?.signature) {\n throw new Error(\n `Overlay \"${overlay.overlayId}\" is missing signature metadata.`\n );\n }\n const payload = Buffer.from(canonicalizeOverlay(overlay), 'utf8');\n const signature = Buffer.from(overlay.signature.signature, 'base64');\n const publicKey = createPublicKey(overlay.signature.publicKey);\n\n if (overlay.signature.algorithm === 'ed25519') {\n return verify(null, payload, publicKey, signature);\n }\n\n if (overlay.signature.algorithm === 'rsa-pss-sha256') {\n return verify(\n 'sha256',\n payload,\n {\n key: publicKey,\n padding: constants.RSA_PKCS1_PSS_PADDING,\n saltLength: 32,\n },\n signature\n );\n }\n\n throw new Error(\n `Unsupported overlay signature algorithm: ${overlay.signature.algorithm}`\n );\n}\n\nexport function canonicalizeOverlay(\n spec: OverlaySpec | SignedOverlaySpec\n): string {\n const { signature, ...rest } = spec as SignedOverlaySpec;\n return stringify(rest);\n}\n\nexport function stripSignature<T extends OverlaySpec | SignedOverlaySpec>(\n spec: T\n): OverlaySpec {\n const { signature, ...rest } = spec as SignedOverlaySpec;\n return { ...rest };\n}\n\nfunction toIso(value?: Date | string): string | undefined {\n if (!value) {\n return undefined;\n }\n if (typeof value === 'string') {\n return new Date(value).toISOString();\n }\n return value.toISOString();\n}\n"],"mappings":"8IAwBA,SAAgB,EACd,EACA,EACA,EAA8B,EAAE,CACb,CACnB,IAAM,EAAY,EAAQ,WAAa,UACjC,EACJ,OAAO,GAAe,UAAY,OAA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,EAC/B,MAAO,CAAE,GAAG,EAAM,CAGpB,SAAS,EAAM,EAA2C,CACnD,KAML,OAHI,OAAO,GAAU,SACZ,IAAI,KAAK,EAAM,CAAC,aAAa,CAE/B,EAAM,aAAa"}
package/dist/spec.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ import { AnyContractSpec } from "@lssm/lib.contracts";
2
+
3
+ //#region src/spec.d.ts
4
+ type OverlayScopeKey = 'tenantId' | 'role' | 'userId' | 'device' | 'tags';
5
+ interface OverlayScopeContext {
6
+ tenantId?: string;
7
+ role?: string;
8
+ userId?: string;
9
+ device?: string;
10
+ tags?: string[];
11
+ }
12
+ interface OverlayTargetRef {
13
+ capability?: string;
14
+ workflow?: string;
15
+ dataView?: string;
16
+ presentation?: string;
17
+ operation?: AnyContractSpec['meta']['name'];
18
+ }
19
+ interface OverlayAppliesTo extends OverlayScopeContext, OverlayTargetRef {
20
+ /**
21
+ * Optional label to describe why this overlay exists (displayed in tooling).
22
+ */
23
+ label?: string;
24
+ }
25
+ type OverlayModification = HideFieldModification | RenameLabelModification | ReorderFieldsModification | SetDefaultModification | AddHelpTextModification | MakeRequiredModification;
26
+ interface OverlayFieldModificationBase {
27
+ field: string;
28
+ description?: string;
29
+ }
30
+ interface HideFieldModification extends OverlayFieldModificationBase {
31
+ type: 'hideField';
32
+ reason?: string;
33
+ }
34
+ interface RenameLabelModification extends OverlayFieldModificationBase {
35
+ type: 'renameLabel';
36
+ newLabel: string;
37
+ }
38
+ interface ReorderFieldsModification {
39
+ type: 'reorderFields';
40
+ fields: string[];
41
+ description?: string;
42
+ }
43
+ interface SetDefaultModification extends OverlayFieldModificationBase {
44
+ type: 'setDefault';
45
+ value: unknown;
46
+ }
47
+ interface AddHelpTextModification extends OverlayFieldModificationBase {
48
+ type: 'addHelpText';
49
+ text: string;
50
+ }
51
+ interface MakeRequiredModification extends OverlayFieldModificationBase {
52
+ type: 'makeRequired';
53
+ required?: boolean;
54
+ }
55
+ interface OverlaySpec {
56
+ overlayId: string;
57
+ version: string;
58
+ description?: string;
59
+ appliesTo: OverlayAppliesTo;
60
+ modifications: OverlayModification[];
61
+ metadata?: Record<string, unknown>;
62
+ createdBy?: string;
63
+ createdAt?: string;
64
+ }
65
+ type OverlaySignatureAlgorithm = 'ed25519' | 'rsa-pss-sha256';
66
+ interface OverlaySignatureBlock {
67
+ algorithm: OverlaySignatureAlgorithm;
68
+ signature: string;
69
+ publicKey: string;
70
+ keyId?: string;
71
+ issuedAt?: string;
72
+ expiresAt?: string;
73
+ metadata?: Record<string, unknown>;
74
+ }
75
+ type SignedOverlaySpec = OverlaySpec & {
76
+ signature: OverlaySignatureBlock;
77
+ };
78
+ type OverlayInput = OverlaySpec | SignedOverlaySpec;
79
+ declare const OVERLAY_SCOPE_ORDER: OverlayScopeKey[];
80
+ declare function defineOverlay<T extends OverlaySpec>(spec: T): T;
81
+ //#endregion
82
+ export { AddHelpTextModification, HideFieldModification, MakeRequiredModification, OVERLAY_SCOPE_ORDER, OverlayAppliesTo, OverlayFieldModificationBase, OverlayInput, OverlayModification, OverlayScopeContext, OverlayScopeKey, OverlaySignatureAlgorithm, OverlaySignatureBlock, OverlaySpec, OverlayTargetRef, RenameLabelModification, ReorderFieldsModification, SetDefaultModification, SignedOverlaySpec, defineOverlay };
83
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","names":[],"sources":["../src/spec.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;UAOK,mBAAA;EAPL,QAAA,CAAA,EAAA,MAAA;EAOK,IAAA,CAAA,EAAA,MAAA;EAQA,MAAA,CAAA,EAAA,MAAA;EAQA,MAAA,CAAA,EAAA,MAAA;EASL,IAAA,CAAA,EAAA,MAAA,EAAA;;AAER,UAnBa,gBAAA,CAmBb;EACA,UAAA,CAAA,EAAA,MAAA;EACA,QAAA,CAAA,EAAA,MAAA;EACA,QAAA,CAAA,EAAA,MAAA;EACA,YAAA,CAAA,EAAA,MAAA;EAAwB,SAAA,CAAA,EAlBd,eAkBc,CAAA,MAAA,CAAA,CAAA,MAAA,CAAA;AAE5B;AAKiB,UAtBA,gBAAA,SACP,mBAqBqC,EApB3C,gBAoBuE,CAAA;EAK1D;AAKjB;AAMA;EAKiB,KAAA,CAAA,EAAA,MAAA;AAKjB;AAKiB,KA5CL,mBAAA,GACR,qBA2CwB,GA1CxB,uBA0CwB,GAzCxB,yBAyCwB,GAxCxB,sBAwCwB,GAvCxB,uBAuCwB,GAtCxB,wBAsCwB;AAIf,UAxCI,4BAAA,CAwCJ;EACI,KAAA,EAAA,MAAA;EACJ,WAAA,CAAA,EAAA,MAAA;;AAKD,UA1CK,qBAAA,SAA8B,4BA0CV,CAAA;EAEpB,IAAA,EAAA,WAAA;EAUL,MAAA,CAAA,EAAA,MAAA;AAIZ;AAEa,UAvDI,uBAAA,SAAgC,4BAuDA,CAAA;EAQjC,IAAA,EAAA,aAAa;EAAW,QAAA,EAAA,MAAA;;AAAuB,UA1D9C,yBAAA,CA0D8C;EAAC,IAAA,EAAA,eAAA;;;;UApD/C,sBAAA,SAA+B;;;;UAK/B,uBAAA,SAAgC;;;;UAKhC,wBAAA,SAAiC;;;;UAKjC,WAAA;;;;aAIJ;iBACI;aACJ;;;;KAKD,yBAAA;UAEK,qBAAA;aACJ;;;;;;aAMA;;KAGD,iBAAA,GAAoB;aACnB;;KAGD,YAAA,GAAe,cAAc;cAE5B,qBAAqB;iBAQlB,wBAAwB,mBAAmB,IAAI"}
package/dist/spec.js ADDED
@@ -0,0 +1,2 @@
1
+ const e=[`tenantId`,`role`,`userId`,`device`,`tags`];function t(e){return e}export{e as OVERLAY_SCOPE_ORDER,t as defineOverlay};
2
+ //# sourceMappingURL=spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.js","names":["OVERLAY_SCOPE_ORDER: OverlayScopeKey[]"],"sources":["../src/spec.ts"],"sourcesContent":["import type { AnyContractSpec } from '@lssm/lib.contracts';\n\nexport type OverlayScopeKey =\n | 'tenantId'\n | 'role'\n | 'userId'\n | 'device'\n | 'tags';\n\nexport interface OverlayScopeContext {\n tenantId?: string;\n role?: string;\n userId?: string;\n device?: string;\n tags?: string[];\n}\n\nexport interface OverlayTargetRef {\n capability?: string;\n workflow?: string;\n dataView?: string;\n presentation?: string;\n operation?: AnyContractSpec['meta']['name'];\n}\n\nexport interface OverlayAppliesTo\n extends OverlayScopeContext,\n OverlayTargetRef {\n /**\n * Optional label to describe why this overlay exists (displayed in tooling).\n */\n label?: string;\n}\n\nexport type OverlayModification =\n | HideFieldModification\n | RenameLabelModification\n | ReorderFieldsModification\n | SetDefaultModification\n | AddHelpTextModification\n | MakeRequiredModification;\n\nexport interface OverlayFieldModificationBase {\n field: string;\n description?: string;\n}\n\nexport interface HideFieldModification extends OverlayFieldModificationBase {\n type: 'hideField';\n reason?: string;\n}\n\nexport interface RenameLabelModification extends OverlayFieldModificationBase {\n type: 'renameLabel';\n newLabel: string;\n}\n\nexport interface ReorderFieldsModification {\n type: 'reorderFields';\n fields: string[];\n description?: string;\n}\n\nexport interface SetDefaultModification extends OverlayFieldModificationBase {\n type: 'setDefault';\n value: unknown;\n}\n\nexport interface AddHelpTextModification extends OverlayFieldModificationBase {\n type: 'addHelpText';\n text: string;\n}\n\nexport interface MakeRequiredModification extends OverlayFieldModificationBase {\n type: 'makeRequired';\n required?: boolean;\n}\n\nexport interface OverlaySpec {\n overlayId: string;\n version: string;\n description?: string;\n appliesTo: OverlayAppliesTo;\n modifications: OverlayModification[];\n metadata?: Record<string, unknown>;\n createdBy?: string;\n createdAt?: string;\n}\n\nexport type OverlaySignatureAlgorithm = 'ed25519' | 'rsa-pss-sha256';\n\nexport interface OverlaySignatureBlock {\n algorithm: OverlaySignatureAlgorithm;\n signature: string;\n publicKey: string;\n keyId?: string;\n issuedAt?: string;\n expiresAt?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport type SignedOverlaySpec = OverlaySpec & {\n signature: OverlaySignatureBlock;\n};\n\nexport type OverlayInput = OverlaySpec | SignedOverlaySpec;\n\nexport const OVERLAY_SCOPE_ORDER: OverlayScopeKey[] = [\n 'tenantId',\n 'role',\n 'userId',\n 'device',\n 'tags',\n];\n\nexport function defineOverlay<T extends OverlaySpec>(spec: T): T {\n return spec;\n}\n"],"mappings":"AA2GA,MAAaA,EAAyC,CACpD,WACA,OACA,SACA,SACA,OACD,CAED,SAAgB,EAAqC,EAAY,CAC/D,OAAO"}
@@ -0,0 +1,33 @@
1
+ import { OverlayScopeContext, OverlayTargetRef, SignedOverlaySpec } from "./spec.js";
2
+
3
+ //#region src/types.d.ts
4
+ interface OverlayRenderableField {
5
+ key: string;
6
+ label?: string;
7
+ visible?: boolean;
8
+ required?: boolean;
9
+ helpText?: string;
10
+ defaultValue?: unknown;
11
+ metadata?: Record<string, unknown>;
12
+ order?: number;
13
+ }
14
+ interface OverlayLayoutConfig {
15
+ kind?: 'form' | 'list' | 'table' | 'grid';
16
+ columns?: number;
17
+ density?: 'comfortable' | 'compact';
18
+ [key: string]: unknown;
19
+ }
20
+ interface OverlayRenderable<TField extends OverlayRenderableField = OverlayRenderableField> {
21
+ fields: TField[];
22
+ layout?: OverlayLayoutConfig;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ interface OverlayMatchContext extends OverlayScopeContext, OverlayTargetRef {}
26
+ interface OverlayAuditEvent {
27
+ overlay: Pick<SignedOverlaySpec, 'overlayId' | 'version'>;
28
+ context: OverlayScopeContext;
29
+ timestamp: string;
30
+ }
31
+ //#endregion
32
+ export { OverlayAuditEvent, OverlayLayoutConfig, OverlayMatchContext, OverlayRenderable, OverlayRenderableField };
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;UAMiB,sBAAA;;EAAA,KAAA,CAAA,EAAA,MAAA;EAWA,OAAA,CAAA,EAAA,OAAA;EAOA,QAAA,CAAA,EAAA,OAAA;EACA,QAAA,CAAA,EAAA,MAAA;EAAyB,YAAA,CAAA,EAAA,OAAA;EAEhC,QAAA,CAAA,EAdG,MAcH,CAAA,MAAA,EAAA,OAAA,CAAA;EACC,KAAA,CAAA,EAAA,MAAA;;AACQ,UAZF,mBAAA,CAYE;EAGF,IAAA,CAAA,EAAA,MAAA,GAAA,MACf,GAAA,OAAA,GAAQ,MAAA;EAGO,OAAA,CAAA,EAAA,MAAA;EACD,OAAA,CAAA,EAAA,aAAA,GAAA,SAAA;EAAL,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;AACmB,UAdb,iBAca,CAAA,eAbb,sBAaa,GAbY,sBAaZ,CAAA,CAAA;UAXpB;WACC;aACE;;UAGI,mBAAA,SACP,qBACN;UAEa,iBAAA;WACN,KAAK;WACL"}
@@ -0,0 +1,19 @@
1
+ import { OverlaySpec } from "./spec.js";
2
+
3
+ //#region src/validator.d.ts
4
+ interface OverlayValidationIssue {
5
+ code: string;
6
+ message: string;
7
+ path?: string[];
8
+ }
9
+ interface OverlayValidationResult {
10
+ valid: boolean;
11
+ issues: OverlayValidationIssue[];
12
+ }
13
+ type OverlayValidator = (spec: OverlaySpec) => OverlayValidationResult;
14
+ declare const defaultOverlayValidator: OverlayValidator;
15
+ declare function validateOverlaySpec(spec: OverlaySpec): OverlayValidationResult;
16
+ declare function assertOverlayValid(spec: OverlaySpec, validator?: OverlayValidator): void;
17
+ //#endregion
18
+ export { OverlayValidationIssue, OverlayValidationResult, OverlayValidator, assertOverlayValid, defaultOverlayValidator, validateOverlaySpec };
19
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","names":[],"sources":["../src/validator.ts"],"sourcesContent":[],"mappings":";;;UAEiB,sBAAA;;EAAA,OAAA,EAAA,MAAA;EAMA,IAAA,CAAA,EAAA,MAAA,EAAA;AAKjB;AAUa,UAfI,uBAAA,CAgBU;EAEX,KAAA,EAAA,OAAA;EA+IA,MAAA,EA/JN,sBA+JwB,EAAA;;KA5JtB,gBAAA,UAA0B,gBAAgB;cAUzC,yBAAyB;iBAGtB,mBAAA,OACR,cACL;iBA6Ia,kBAAA,OACR,yBACK"}
@@ -0,0 +1,2 @@
1
+ const e=[`capability`,`workflow`,`dataView`,`presentation`,`operation`],t=e=>n(e);function n(t){let n=[];return t.overlayId?.trim()||n.push({code:`overlay.id`,message:`overlayId is required`,path:[`overlayId`]}),t.version?.trim()||n.push({code:`overlay.version`,message:`version is required`,path:[`version`]}),e.some(e=>{let n=t.appliesTo?.[e];return typeof n==`string`&&n.trim().length>0})||n.push({code:`overlay.target`,message:`Overlay must specify at least one target (capability, workflow, dataView, presentation, or operation).`,path:[`appliesTo`]}),t.modifications?.length?t.modifications.forEach((e,t)=>{r(e,[`modifications`,String(t)],n)}):n.push({code:`overlay.modifications.empty`,message:`Overlay must include at least one modification.`,path:[`modifications`]}),{valid:n.length===0,issues:n}}function r(e,t,n){let r=(e,r,i)=>{n.push({code:e,message:r,path:i?[...t,...i]:t})};switch(i(e)&&(e.field?.trim()||r(`overlay.mod.field`,`field is required for this modification`,[`field`])),e.type){case`renameLabel`:e.newLabel?.trim()||r(`overlay.mod.renameLabel.newLabel`,`newLabel is required`,[`newLabel`]);break;case`reorderFields`:{e.fields?.length||r(`overlay.mod.reorderFields.fields`,`fields list cannot be empty`,[`fields`]);let t=new Set;for(let n of e.fields??[]){if(!n?.trim()){r(`overlay.mod.reorderFields.fields.blank`,`fields entries must be non-empty`);break}if(t.has(n)){r(`overlay.mod.reorderFields.fields.duplicate`,`field "${n}" was listed multiple times`);break}t.add(n)}break}case`setDefault`:e.value===void 0&&r(`overlay.mod.setDefault.value`,`value is required`,[`value`]);break;case`addHelpText`:e.text?.trim()||r(`overlay.mod.addHelpText.text`,`text is required`,[`text`]);break;case`makeRequired`:case`hideField`:break;default:{let t=e;throw Error(`Unsupported overlay modification ${t?.type??`unknown`}`)}}}function i(e){return`field`in e}function a(e,n=t){let r=n(e);if(!r.valid){let t=r.issues.map(e=>`${e.code}: ${e.message}`).join(`; `);throw Error(`Invalid OverlaySpec "${e.overlayId}": ${t}`)}}export{a as assertOverlayValid,t as defaultOverlayValidator,n as validateOverlaySpec};
2
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","names":["defaultOverlayValidator: OverlayValidator","issues: OverlayValidationIssue[]","exhaustive: never"],"sources":["../src/validator.ts"],"sourcesContent":["import type { OverlayModification, OverlaySpec } from './spec';\n\nexport interface OverlayValidationIssue {\n code: string;\n message: string;\n path?: string[];\n}\n\nexport interface OverlayValidationResult {\n valid: boolean;\n issues: OverlayValidationIssue[];\n}\n\nexport type OverlayValidator = (spec: OverlaySpec) => OverlayValidationResult;\n\nconst TARGET_KEYS = [\n 'capability',\n 'workflow',\n 'dataView',\n 'presentation',\n 'operation',\n] as const;\n\nexport const defaultOverlayValidator: OverlayValidator = (spec) =>\n validateOverlaySpec(spec);\n\nexport function validateOverlaySpec(\n spec: OverlaySpec\n): OverlayValidationResult {\n const issues: OverlayValidationIssue[] = [];\n\n if (!spec.overlayId?.trim()) {\n issues.push({\n code: 'overlay.id',\n message: 'overlayId is required',\n path: ['overlayId'],\n });\n }\n\n if (!spec.version?.trim()) {\n issues.push({\n code: 'overlay.version',\n message: 'version is required',\n path: ['version'],\n });\n }\n\n const hasTarget = TARGET_KEYS.some((key) => {\n const value = spec.appliesTo?.[key as keyof typeof spec.appliesTo];\n return typeof value === 'string' && value.trim().length > 0;\n });\n\n if (!hasTarget) {\n issues.push({\n code: 'overlay.target',\n message:\n 'Overlay must specify at least one target (capability, workflow, dataView, presentation, or operation).',\n path: ['appliesTo'],\n });\n }\n\n if (!spec.modifications?.length) {\n issues.push({\n code: 'overlay.modifications.empty',\n message: 'Overlay must include at least one modification.',\n path: ['modifications'],\n });\n } else {\n spec.modifications.forEach((mod, idx) => {\n const path = ['modifications', String(idx)];\n validateModification(mod, path, issues);\n });\n }\n\n return {\n valid: issues.length === 0,\n issues,\n };\n}\n\nfunction validateModification(\n modification: OverlayModification,\n path: string[],\n issues: OverlayValidationIssue[]\n) {\n const push = (code: string, message: string, extraPath?: string[]) => {\n issues.push({\n code,\n message,\n path: extraPath ? [...path, ...extraPath] : path,\n });\n };\n\n if (isFieldModification(modification)) {\n if (!modification.field?.trim()) {\n push('overlay.mod.field', 'field is required for this modification', [\n 'field',\n ]);\n }\n }\n\n switch (modification.type) {\n case 'renameLabel': {\n if (!modification.newLabel?.trim()) {\n push('overlay.mod.renameLabel.newLabel', 'newLabel is required', [\n 'newLabel',\n ]);\n }\n break;\n }\n case 'reorderFields': {\n if (!modification.fields?.length) {\n push(\n 'overlay.mod.reorderFields.fields',\n 'fields list cannot be empty',\n ['fields']\n );\n }\n const seen = new Set<string>();\n for (const field of modification.fields ?? []) {\n if (!field?.trim()) {\n push(\n 'overlay.mod.reorderFields.fields.blank',\n 'fields entries must be non-empty'\n );\n break;\n }\n if (seen.has(field)) {\n push(\n 'overlay.mod.reorderFields.fields.duplicate',\n `field \"${field}\" was listed multiple times`\n );\n break;\n }\n seen.add(field);\n }\n break;\n }\n case 'setDefault': {\n if (modification.value === undefined) {\n push('overlay.mod.setDefault.value', 'value is required', ['value']);\n }\n break;\n }\n case 'addHelpText': {\n if (!modification.text?.trim()) {\n push('overlay.mod.addHelpText.text', 'text is required', ['text']);\n }\n break;\n }\n case 'makeRequired':\n case 'hideField':\n // no extra validation\n break;\n default: {\n const exhaustive: never = modification;\n throw new Error(\n `Unsupported overlay modification ${(exhaustive as any)?.type ?? 'unknown'}`\n );\n }\n }\n}\n\nfunction isFieldModification(\n mod: OverlayModification\n): mod is Extract<OverlayModification, { field: string }> {\n return 'field' in mod;\n}\n\nexport function assertOverlayValid(\n spec: OverlaySpec,\n validator: OverlayValidator = defaultOverlayValidator\n) {\n const result = validator(spec);\n if (!result.valid) {\n const message = result.issues\n .map((issue) => `${issue.code}: ${issue.message}`)\n .join('; ');\n throw new Error(`Invalid OverlaySpec \"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B,EACE,mCACA,8BACA,CAAC,SAAS,CACX,CAEH,IAAM,EAAO,IAAI,IACjB,IAAK,IAAM,KAAS,EAAa,QAAU,EAAE,CAAE,CAC7C,GAAI,CAAC,GAAO,MAAM,CAAE,CAClB,EACE,yCACA,mCACD,CACD,MAEF,GAAI,EAAK,IAAI,EAAM,CAAE,CACnB,EACE,6CACA,UAAU,EAAM,6BACjB,CACD,MAEF,EAAK,IAAI,EAAM,CAEjB,MAEF,IAAK,aACC,EAAa,QAAU,IAAA,IACzB,EAAK,+BAAgC,oBAAqB,CAAC,QAAQ,CAAC,CAEtE,MAEF,IAAK,cACE,EAAa,MAAM,MAAM,EAC5B,EAAK,+BAAgC,mBAAoB,CAAC,OAAO,CAAC,CAEpE,MAEF,IAAK,eACL,IAAK,YAEH,MACF,QAAS,CACP,IAAMC,EAAoB,EAC1B,MAAU,MACR,oCAAqC,GAAoB,MAAQ,YAClE,GAKP,SAAS,EACP,EACwD,CACxD,MAAO,UAAW,EAGpB,SAAgB,EACd,EACA,EAA8B,EAC9B,CACA,IAAM,EAAS,EAAU,EAAK,CAC9B,GAAI,CAAC,EAAO,MAAO,CACjB,IAAM,EAAU,EAAO,OACpB,IAAK,GAAU,GAAG,EAAM,KAAK,IAAI,EAAM,UAAU,CACjD,KAAK,KAAK,CACb,MAAU,MAAM,wBAAwB,EAAK,UAAU,KAAK,IAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/lib.overlay-engine",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Runtime overlay engine for ContractSpec personalization and adaptive UI rendering.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",