@lssm/lib.overlay-engine 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406
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/dist/index.js +8 -1
- package/dist/merger.js +106 -1
- package/dist/react.js +22 -1
- package/dist/registry.js +106 -1
- package/dist/runtime.js +53 -1
- package/dist/signer.js +62 -1
- package/dist/spec.js +14 -1
- package/dist/validator.js +100 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { OVERLAY_SCOPE_ORDER, defineOverlay } from "./spec.js";
|
|
2
|
+
import { assertOverlayValid, defaultOverlayValidator, validateOverlaySpec } from "./validator.js";
|
|
3
|
+
import { OverlayRegistry } from "./registry.js";
|
|
4
|
+
import { applyOverlayModifications } from "./merger.js";
|
|
5
|
+
import { OverlayEngine } from "./runtime.js";
|
|
6
|
+
import { canonicalizeOverlay, signOverlay, stripSignature, verifyOverlaySignature } from "./signer.js";
|
|
7
|
+
|
|
8
|
+
export { OVERLAY_SCOPE_ORDER, OverlayEngine, OverlayRegistry, applyOverlayModifications, assertOverlayValid, canonicalizeOverlay, defaultOverlayValidator, defineOverlay, signOverlay, stripSignature, validateOverlaySpec, verifyOverlaySignature };
|
package/dist/merger.js
CHANGED
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/merger.ts
|
|
2
|
+
function applyOverlayModifications(target, overlays, options = {}) {
|
|
3
|
+
if (!overlays.length) return target;
|
|
4
|
+
const states = target.fields.map((field) => ({
|
|
5
|
+
key: field.key,
|
|
6
|
+
field: { ...field },
|
|
7
|
+
hidden: field.visible === false
|
|
8
|
+
}));
|
|
9
|
+
const fieldMap = new Map(states.map((state) => [state.key, state]));
|
|
10
|
+
let orderSequence = target.fields.map((field) => field.key);
|
|
11
|
+
const handleMissing = (field, overlayId) => {
|
|
12
|
+
if (options.strict) throw new Error(`Overlay "${overlayId}" referenced unknown field "${field}".`);
|
|
13
|
+
};
|
|
14
|
+
overlays.forEach((overlay) => {
|
|
15
|
+
overlay.modifications.forEach((modification) => {
|
|
16
|
+
switch (modification.type) {
|
|
17
|
+
case "hideField": {
|
|
18
|
+
const state = fieldMap.get(modification.field);
|
|
19
|
+
if (!state) return handleMissing(modification.field, overlay.overlayId);
|
|
20
|
+
state.hidden = true;
|
|
21
|
+
state.field.visible = false;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case "renameLabel": {
|
|
25
|
+
const state = fieldMap.get(modification.field);
|
|
26
|
+
if (!state) return handleMissing(modification.field, overlay.overlayId);
|
|
27
|
+
state.field.label = modification.newLabel;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "setDefault": {
|
|
31
|
+
const state = fieldMap.get(modification.field);
|
|
32
|
+
if (!state) return handleMissing(modification.field, overlay.overlayId);
|
|
33
|
+
state.field.defaultValue = modification.value;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "addHelpText": {
|
|
37
|
+
const state = fieldMap.get(modification.field);
|
|
38
|
+
if (!state) return handleMissing(modification.field, overlay.overlayId);
|
|
39
|
+
state.field.helpText = modification.text;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "makeRequired": {
|
|
43
|
+
const state = fieldMap.get(modification.field);
|
|
44
|
+
if (!state) return handleMissing(modification.field, overlay.overlayId);
|
|
45
|
+
state.field.required = modification.required ?? true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "reorderFields": {
|
|
49
|
+
const { filtered, missing } = normalizeOrderList(modification.fields, fieldMap);
|
|
50
|
+
if (missing.length && options.strict) missing.forEach((field) => handleMissing(field, overlay.overlayId));
|
|
51
|
+
orderSequence = applyReorder(orderSequence, filtered);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default: break;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
const visibleFields = [];
|
|
59
|
+
const seen = /* @__PURE__ */ new Set();
|
|
60
|
+
orderSequence.forEach((key) => {
|
|
61
|
+
const state = fieldMap.get(key);
|
|
62
|
+
if (!state || state.hidden) return;
|
|
63
|
+
seen.add(key);
|
|
64
|
+
visibleFields.push(state.field);
|
|
65
|
+
});
|
|
66
|
+
states.forEach((state) => {
|
|
67
|
+
if (state.hidden || seen.has(state.key)) return;
|
|
68
|
+
visibleFields.push(state.field);
|
|
69
|
+
});
|
|
70
|
+
visibleFields.forEach((field, index) => {
|
|
71
|
+
field.order = index;
|
|
72
|
+
field.visible = true;
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
...target,
|
|
76
|
+
fields: visibleFields
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function normalizeOrderList(fields, fieldMap) {
|
|
80
|
+
const filtered = [];
|
|
81
|
+
const missing = [];
|
|
82
|
+
const seen = /* @__PURE__ */ new Set();
|
|
83
|
+
fields.forEach((field) => {
|
|
84
|
+
if (!field?.trim()) return;
|
|
85
|
+
if (!fieldMap.has(field)) {
|
|
86
|
+
missing.push(field);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (seen.has(field)) return;
|
|
90
|
+
seen.add(field);
|
|
91
|
+
filtered.push(field);
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
filtered,
|
|
95
|
+
missing
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function applyReorder(sequence, orderedFields) {
|
|
99
|
+
if (!orderedFields.length) return sequence;
|
|
100
|
+
const orderedSet = new Set(orderedFields);
|
|
101
|
+
const remainder = sequence.filter((key) => !orderedSet.has(key));
|
|
102
|
+
return [...orderedFields, ...remainder];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { applyOverlayModifications };
|
package/dist/react.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/react.ts
|
|
4
|
+
function useOverlay(engine, params, deps = []) {
|
|
5
|
+
return useMemo(() => {
|
|
6
|
+
if (!engine) return {
|
|
7
|
+
target: params.target,
|
|
8
|
+
overlaysApplied: []
|
|
9
|
+
};
|
|
10
|
+
return engine.apply(params);
|
|
11
|
+
}, [
|
|
12
|
+
engine,
|
|
13
|
+
params,
|
|
14
|
+
...deps
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
function useOverlayFields(engine, params, deps = []) {
|
|
18
|
+
return useOverlay(engine, params, deps).target.fields;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { useOverlay, useOverlayFields };
|
package/dist/registry.js
CHANGED
|
@@ -1 +1,106 @@
|
|
|
1
|
-
import{defaultOverlayValidator
|
|
1
|
+
import { defaultOverlayValidator } from "./validator.js";
|
|
2
|
+
|
|
3
|
+
//#region src/registry.ts
|
|
4
|
+
const TARGET_KEYS = [
|
|
5
|
+
"capability",
|
|
6
|
+
"workflow",
|
|
7
|
+
"dataView",
|
|
8
|
+
"presentation",
|
|
9
|
+
"operation"
|
|
10
|
+
];
|
|
11
|
+
const SCOPE_WEIGHTS = {
|
|
12
|
+
tenantId: 8,
|
|
13
|
+
role: 4,
|
|
14
|
+
userId: 16,
|
|
15
|
+
device: 2,
|
|
16
|
+
tags: 1
|
|
17
|
+
};
|
|
18
|
+
var OverlayRegistry = class {
|
|
19
|
+
overlays = /* @__PURE__ */ new Map();
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
register(overlay, options) {
|
|
24
|
+
if (!options?.skipValidation) {
|
|
25
|
+
const result = (this.options.validator ?? defaultOverlayValidator)(overlay);
|
|
26
|
+
if (!result.valid) {
|
|
27
|
+
const reason = result.issues.map((issue) => `${issue.code}: ${issue.message}`).join("; ");
|
|
28
|
+
throw new Error(`Overlay "${overlay.overlayId}" failed validation: ${reason}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const normalized = this.ensureSigned(overlay);
|
|
32
|
+
const key = this.getKey(normalized.overlayId, normalized.version);
|
|
33
|
+
const stored = {
|
|
34
|
+
overlay: normalized,
|
|
35
|
+
specificity: computeSpecificity(normalized.appliesTo),
|
|
36
|
+
registeredAt: Date.now()
|
|
37
|
+
};
|
|
38
|
+
this.overlays.set(key, stored);
|
|
39
|
+
return normalized;
|
|
40
|
+
}
|
|
41
|
+
unregister(overlayId, version) {
|
|
42
|
+
if (version) {
|
|
43
|
+
this.overlays.delete(this.getKey(overlayId, version));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const key of Array.from(this.overlays.keys())) if (key.startsWith(`${overlayId}@`)) this.overlays.delete(key);
|
|
47
|
+
}
|
|
48
|
+
list() {
|
|
49
|
+
return Array.from(this.overlays.values()).map((entry) => entry.overlay);
|
|
50
|
+
}
|
|
51
|
+
get(overlayId, version) {
|
|
52
|
+
return this.overlays.get(this.getKey(overlayId, version))?.overlay;
|
|
53
|
+
}
|
|
54
|
+
forContext(query) {
|
|
55
|
+
return Array.from(this.overlays.values()).filter((entry) => matches(entry.overlay.appliesTo, query)).sort((a, b) => {
|
|
56
|
+
if (a.specificity !== b.specificity) return a.specificity - b.specificity;
|
|
57
|
+
return a.registeredAt - b.registeredAt;
|
|
58
|
+
}).map((entry) => entry.overlay);
|
|
59
|
+
}
|
|
60
|
+
clear() {
|
|
61
|
+
this.overlays.clear();
|
|
62
|
+
}
|
|
63
|
+
size() {
|
|
64
|
+
return this.overlays.size;
|
|
65
|
+
}
|
|
66
|
+
ensureSigned(input) {
|
|
67
|
+
if (isSignedOverlay(input)) {
|
|
68
|
+
if (!input.signature?.signature && !this.options.allowUnsigned) throw new Error(`Overlay "${input.overlayId}" is missing a signature.`);
|
|
69
|
+
return input;
|
|
70
|
+
}
|
|
71
|
+
if (!this.options.allowUnsigned) throw new Error(`Overlay "${input.overlayId}" must be signed before registration.`);
|
|
72
|
+
return input;
|
|
73
|
+
}
|
|
74
|
+
getKey(overlayId, version) {
|
|
75
|
+
return `${overlayId}@${version}`;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function isSignedOverlay(spec) {
|
|
79
|
+
return Boolean(spec.signature);
|
|
80
|
+
}
|
|
81
|
+
function computeSpecificity(appliesTo) {
|
|
82
|
+
let score = 0;
|
|
83
|
+
Object.keys(SCOPE_WEIGHTS).forEach((key) => {
|
|
84
|
+
if (key === "tags" ? Array.isArray(appliesTo.tags) && appliesTo.tags.length > 0 : Boolean(appliesTo[key])) score += SCOPE_WEIGHTS[key];
|
|
85
|
+
});
|
|
86
|
+
return score;
|
|
87
|
+
}
|
|
88
|
+
function matches(appliesTo, ctx) {
|
|
89
|
+
for (const key of TARGET_KEYS) {
|
|
90
|
+
const expected = appliesTo[key];
|
|
91
|
+
if (expected && expected !== ctx[key]) return false;
|
|
92
|
+
}
|
|
93
|
+
if (appliesTo.tenantId && appliesTo.tenantId !== ctx.tenantId) return false;
|
|
94
|
+
if (appliesTo.role && appliesTo.role !== ctx.role) return false;
|
|
95
|
+
if (appliesTo.userId && appliesTo.userId !== ctx.userId) return false;
|
|
96
|
+
if (appliesTo.device && appliesTo.device !== ctx.device) return false;
|
|
97
|
+
if (appliesTo.tags?.length) {
|
|
98
|
+
if (!ctx.tags?.length) return false;
|
|
99
|
+
const ctxTags = new Set(ctx.tags);
|
|
100
|
+
if (!appliesTo.tags.every((tag) => ctxTags.has(tag))) return false;
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { OverlayRegistry };
|
package/dist/runtime.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
import{applyOverlayModifications
|
|
1
|
+
import { applyOverlayModifications } from "./merger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime.ts
|
|
4
|
+
var OverlayEngine = class {
|
|
5
|
+
registry;
|
|
6
|
+
audit;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.registry = options.registry;
|
|
9
|
+
this.audit = options.audit;
|
|
10
|
+
}
|
|
11
|
+
apply(params) {
|
|
12
|
+
const overlays = params.overlays ?? this.registry.forContext({
|
|
13
|
+
capability: params.capability,
|
|
14
|
+
workflow: params.workflow,
|
|
15
|
+
dataView: params.dataView,
|
|
16
|
+
presentation: params.presentation,
|
|
17
|
+
operation: params.operation,
|
|
18
|
+
tenantId: params.tenantId,
|
|
19
|
+
role: params.role,
|
|
20
|
+
userId: params.userId,
|
|
21
|
+
device: params.device,
|
|
22
|
+
tags: params.tags
|
|
23
|
+
});
|
|
24
|
+
const merged = applyOverlayModifications(params.target, overlays, { strict: params.strict });
|
|
25
|
+
const context = extractContext(params);
|
|
26
|
+
overlays.forEach((overlay) => {
|
|
27
|
+
this.audit?.({
|
|
28
|
+
overlay: {
|
|
29
|
+
overlayId: overlay.overlayId,
|
|
30
|
+
version: overlay.version
|
|
31
|
+
},
|
|
32
|
+
context,
|
|
33
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
target: merged,
|
|
38
|
+
overlaysApplied: overlays
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function extractContext(params) {
|
|
43
|
+
return {
|
|
44
|
+
tenantId: params.tenantId,
|
|
45
|
+
role: params.role,
|
|
46
|
+
userId: params.userId,
|
|
47
|
+
device: params.device,
|
|
48
|
+
tags: params.tags
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { OverlayEngine };
|
package/dist/signer.js
CHANGED
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringify from "fast-json-stable-stringify";
|
|
2
|
+
import { constants, createPrivateKey, createPublicKey, sign, verify } from "crypto";
|
|
3
|
+
|
|
4
|
+
//#region src/signer.ts
|
|
5
|
+
function signOverlay(spec, privateKey, options = {}) {
|
|
6
|
+
const algorithm = options.algorithm ?? "ed25519";
|
|
7
|
+
const keyObject = typeof privateKey === "string" || Buffer.isBuffer(privateKey) ? createPrivateKey(privateKey) : privateKey;
|
|
8
|
+
const payload = Buffer.from(canonicalizeOverlay(spec), "utf8");
|
|
9
|
+
let rawSignature;
|
|
10
|
+
if (algorithm === "ed25519") rawSignature = sign(null, payload, keyObject);
|
|
11
|
+
else if (algorithm === "rsa-pss-sha256") rawSignature = sign("sha256", payload, {
|
|
12
|
+
key: keyObject,
|
|
13
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
14
|
+
saltLength: 32
|
|
15
|
+
});
|
|
16
|
+
else throw new Error(`Unsupported overlay signature algorithm: ${algorithm}`);
|
|
17
|
+
const publicKey = options.publicKey ?? createPublicKey(keyObject).export({
|
|
18
|
+
format: "pem",
|
|
19
|
+
type: "spki"
|
|
20
|
+
}).toString();
|
|
21
|
+
return {
|
|
22
|
+
...spec,
|
|
23
|
+
signature: {
|
|
24
|
+
algorithm,
|
|
25
|
+
signature: rawSignature.toString("base64"),
|
|
26
|
+
publicKey,
|
|
27
|
+
keyId: options.keyId,
|
|
28
|
+
issuedAt: toIso(options.issuedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
|
+
expiresAt: toIso(options.expiresAt),
|
|
30
|
+
metadata: options.metadata
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function verifyOverlaySignature(overlay) {
|
|
35
|
+
if (!overlay.signature?.signature) throw new Error(`Overlay "${overlay.overlayId}" is missing signature metadata.`);
|
|
36
|
+
const payload = Buffer.from(canonicalizeOverlay(overlay), "utf8");
|
|
37
|
+
const signature = Buffer.from(overlay.signature.signature, "base64");
|
|
38
|
+
const publicKey = createPublicKey(overlay.signature.publicKey);
|
|
39
|
+
if (overlay.signature.algorithm === "ed25519") return verify(null, payload, publicKey, signature);
|
|
40
|
+
if (overlay.signature.algorithm === "rsa-pss-sha256") return verify("sha256", payload, {
|
|
41
|
+
key: publicKey,
|
|
42
|
+
padding: constants.RSA_PKCS1_PSS_PADDING,
|
|
43
|
+
saltLength: 32
|
|
44
|
+
}, signature);
|
|
45
|
+
throw new Error(`Unsupported overlay signature algorithm: ${overlay.signature.algorithm}`);
|
|
46
|
+
}
|
|
47
|
+
function canonicalizeOverlay(spec) {
|
|
48
|
+
const { signature, ...rest } = spec;
|
|
49
|
+
return stringify(rest);
|
|
50
|
+
}
|
|
51
|
+
function stripSignature(spec) {
|
|
52
|
+
const { signature, ...rest } = spec;
|
|
53
|
+
return { ...rest };
|
|
54
|
+
}
|
|
55
|
+
function toIso(value) {
|
|
56
|
+
if (!value) return;
|
|
57
|
+
if (typeof value === "string") return new Date(value).toISOString();
|
|
58
|
+
return value.toISOString();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { canonicalizeOverlay, signOverlay, stripSignature, verifyOverlaySignature };
|
package/dist/spec.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/spec.ts
|
|
2
|
+
const OVERLAY_SCOPE_ORDER = [
|
|
3
|
+
"tenantId",
|
|
4
|
+
"role",
|
|
5
|
+
"userId",
|
|
6
|
+
"device",
|
|
7
|
+
"tags"
|
|
8
|
+
];
|
|
9
|
+
function defineOverlay(spec) {
|
|
10
|
+
return spec;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { OVERLAY_SCOPE_ORDER, defineOverlay };
|
package/dist/validator.js
CHANGED
|
@@ -1 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/validator.ts
|
|
2
|
+
const TARGET_KEYS = [
|
|
3
|
+
"capability",
|
|
4
|
+
"workflow",
|
|
5
|
+
"dataView",
|
|
6
|
+
"presentation",
|
|
7
|
+
"operation"
|
|
8
|
+
];
|
|
9
|
+
const defaultOverlayValidator = (spec) => validateOverlaySpec(spec);
|
|
10
|
+
function validateOverlaySpec(spec) {
|
|
11
|
+
const issues = [];
|
|
12
|
+
if (!spec.overlayId?.trim()) issues.push({
|
|
13
|
+
code: "overlay.id",
|
|
14
|
+
message: "overlayId is required",
|
|
15
|
+
path: ["overlayId"]
|
|
16
|
+
});
|
|
17
|
+
if (!spec.version?.trim()) issues.push({
|
|
18
|
+
code: "overlay.version",
|
|
19
|
+
message: "version is required",
|
|
20
|
+
path: ["version"]
|
|
21
|
+
});
|
|
22
|
+
if (!TARGET_KEYS.some((key) => {
|
|
23
|
+
const value = spec.appliesTo?.[key];
|
|
24
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
25
|
+
})) issues.push({
|
|
26
|
+
code: "overlay.target",
|
|
27
|
+
message: "Overlay must specify at least one target (capability, workflow, dataView, presentation, or operation).",
|
|
28
|
+
path: ["appliesTo"]
|
|
29
|
+
});
|
|
30
|
+
if (!spec.modifications?.length) issues.push({
|
|
31
|
+
code: "overlay.modifications.empty",
|
|
32
|
+
message: "Overlay must include at least one modification.",
|
|
33
|
+
path: ["modifications"]
|
|
34
|
+
});
|
|
35
|
+
else spec.modifications.forEach((mod, idx) => {
|
|
36
|
+
validateModification(mod, ["modifications", String(idx)], issues);
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
valid: issues.length === 0,
|
|
40
|
+
issues
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function validateModification(modification, path, issues) {
|
|
44
|
+
const push = (code, message, extraPath) => {
|
|
45
|
+
issues.push({
|
|
46
|
+
code,
|
|
47
|
+
message,
|
|
48
|
+
path: extraPath ? [...path, ...extraPath] : path
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
if (isFieldModification(modification)) {
|
|
52
|
+
if (!modification.field?.trim()) push("overlay.mod.field", "field is required for this modification", ["field"]);
|
|
53
|
+
}
|
|
54
|
+
switch (modification.type) {
|
|
55
|
+
case "renameLabel":
|
|
56
|
+
if (!modification.newLabel?.trim()) push("overlay.mod.renameLabel.newLabel", "newLabel is required", ["newLabel"]);
|
|
57
|
+
break;
|
|
58
|
+
case "reorderFields": {
|
|
59
|
+
if (!modification.fields?.length) push("overlay.mod.reorderFields.fields", "fields list cannot be empty", ["fields"]);
|
|
60
|
+
const seen = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const field of modification.fields ?? []) {
|
|
62
|
+
if (!field?.trim()) {
|
|
63
|
+
push("overlay.mod.reorderFields.fields.blank", "fields entries must be non-empty");
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (seen.has(field)) {
|
|
67
|
+
push("overlay.mod.reorderFields.fields.duplicate", `field "${field}" was listed multiple times`);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
seen.add(field);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "setDefault":
|
|
75
|
+
if (modification.value === void 0) push("overlay.mod.setDefault.value", "value is required", ["value"]);
|
|
76
|
+
break;
|
|
77
|
+
case "addHelpText":
|
|
78
|
+
if (!modification.text?.trim()) push("overlay.mod.addHelpText.text", "text is required", ["text"]);
|
|
79
|
+
break;
|
|
80
|
+
case "makeRequired":
|
|
81
|
+
case "hideField": break;
|
|
82
|
+
default: {
|
|
83
|
+
const exhaustive = modification;
|
|
84
|
+
throw new Error(`Unsupported overlay modification ${exhaustive?.type ?? "unknown"}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function isFieldModification(mod) {
|
|
89
|
+
return "field" in mod;
|
|
90
|
+
}
|
|
91
|
+
function assertOverlayValid(spec, validator = defaultOverlayValidator) {
|
|
92
|
+
const result = validator(spec);
|
|
93
|
+
if (!result.valid) {
|
|
94
|
+
const message = result.issues.map((issue) => `${issue.code}: ${issue.message}`).join("; ");
|
|
95
|
+
throw new Error(`Invalid OverlaySpec "${spec.overlayId}": ${message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { assertOverlayValid, defaultOverlayValidator, validateOverlaySpec };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.overlay-engine",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251217072406",
|
|
4
4
|
"description": "Runtime overlay engine for ContractSpec personalization and adaptive UI rendering.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "bun run"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lssm/lib.contracts": "0.0.0-canary-
|
|
27
|
+
"@lssm/lib.contracts": "0.0.0-canary-20251217072406",
|
|
28
28
|
"fast-json-stable-stringify": "^2.1.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lssm/tool.tsdown": "0.0.0-canary-
|
|
40
|
-
"@lssm/tool.typescript": "0.0.0-canary-
|
|
39
|
+
"@lssm/tool.tsdown": "0.0.0-canary-20251217072406",
|
|
40
|
+
"@lssm/tool.typescript": "0.0.0-canary-20251217072406",
|
|
41
41
|
"tsdown": "^0.17.4",
|
|
42
42
|
"typescript": "^5.9.3"
|
|
43
43
|
},
|