@lssm/example.personalization 0.0.0-canary-20251217060834 → 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/.turbo/turbo-build$colon$bundle.log +88 -17
- package/.turbo/turbo-build.log +87 -16
- package/CHANGELOG.md +7 -6
- package/dist/behavior-tracking.js +49 -1
- package/dist/docs/index.js +1 -1
- package/dist/docs/personalization.docblock.js +29 -8
- package/dist/example.js +38 -1
- package/dist/index.js +7 -1
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/index.js +29 -0
- package/dist/libs/contracts/dist/docs/presentations.js +71 -0
- package/dist/libs/contracts/dist/docs/registry.js +44 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +80 -0
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +357 -0
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -0
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +79 -0
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +84 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +45 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -0
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +40 -0
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +69 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +62 -0
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +155 -0
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +101 -0
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -0
- package/dist/libs/logger/dist/context.node.js +78 -0
- package/dist/libs/logger/dist/elysia-plugin.js +3 -0
- package/dist/libs/logger/dist/formatters.js +163 -0
- package/dist/libs/logger/dist/index.js +7 -0
- package/dist/libs/logger/dist/logger.node.js +189 -0
- package/dist/libs/logger/dist/timer.js +126 -0
- package/dist/libs/logger/dist/tracer.node.js +115 -0
- package/dist/libs/logger/dist/types.js +13 -0
- package/dist/libs/overlay-engine/dist/index.js +6 -0
- package/dist/libs/overlay-engine/dist/merger.js +106 -0
- package/dist/libs/overlay-engine/dist/registry.js +106 -0
- package/dist/libs/overlay-engine/dist/runtime.js +53 -0
- package/dist/libs/overlay-engine/dist/signer.js +45 -0
- package/dist/libs/overlay-engine/dist/spec.js +7 -0
- package/dist/libs/overlay-engine/dist/validator.js +93 -0
- package/dist/libs/personalization/dist/analyzer.js +54 -0
- package/dist/libs/personalization/dist/store.js +58 -0
- package/dist/libs/personalization/dist/tracker.js +92 -0
- package/dist/libs/workflow-composer/dist/composer.js +28 -0
- package/dist/libs/workflow-composer/dist/injector.js +72 -0
- package/dist/libs/workflow-composer/dist/validator.js +36 -0
- package/dist/overlay-customization.js +53 -1
- package/dist/workflow-extension.js +67 -1
- package/package.json +9 -8
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region ../../libs/overlay-engine/dist/merger.js
|
|
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 };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { defaultOverlayValidator } from "./validator.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/overlay-engine/dist/registry.js
|
|
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 };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { applyOverlayModifications } from "./merger.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/overlay-engine/dist/runtime.js
|
|
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 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import stringify from "fast-json-stable-stringify";
|
|
2
|
+
import { constants, createPrivateKey, createPublicKey, sign } from "crypto";
|
|
3
|
+
|
|
4
|
+
//#region ../../libs/overlay-engine/dist/signer.js
|
|
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 canonicalizeOverlay(spec) {
|
|
35
|
+
const { signature, ...rest } = spec;
|
|
36
|
+
return stringify(rest);
|
|
37
|
+
}
|
|
38
|
+
function toIso(value) {
|
|
39
|
+
if (!value) return;
|
|
40
|
+
if (typeof value === "string") return new Date(value).toISOString();
|
|
41
|
+
return value.toISOString();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { canonicalizeOverlay, signOverlay };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region ../../libs/overlay-engine/dist/validator.js
|
|
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
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { defaultOverlayValidator, validateOverlaySpec };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region ../../libs/personalization/dist/analyzer.js
|
|
2
|
+
const DEFAULT_THRESHOLD = 3;
|
|
3
|
+
var BehaviorAnalyzer = class {
|
|
4
|
+
constructor(store, options = {}) {
|
|
5
|
+
this.store = store;
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
async analyze(params) {
|
|
9
|
+
const query = {
|
|
10
|
+
tenantId: params.tenantId,
|
|
11
|
+
userId: params.userId,
|
|
12
|
+
role: params.role
|
|
13
|
+
};
|
|
14
|
+
if (params.windowMs) query.since = Date.now() - params.windowMs;
|
|
15
|
+
return buildInsights(await this.store.summarize(query), this.options);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function buildInsights(summary, options) {
|
|
19
|
+
const threshold = options.fieldInactivityThreshold ?? DEFAULT_THRESHOLD;
|
|
20
|
+
const minSamples = options.minSamples ?? 10;
|
|
21
|
+
const ignoredFields = [];
|
|
22
|
+
const frequentlyUsedFields = [];
|
|
23
|
+
for (const [field, count] of Object.entries(summary.fieldCounts)) {
|
|
24
|
+
if (count <= threshold) ignoredFields.push(field);
|
|
25
|
+
if (count >= threshold * 4) frequentlyUsedFields.push(field);
|
|
26
|
+
}
|
|
27
|
+
const workflowBottlenecks = Object.entries(summary.workflowStepCounts).flatMap(([workflow, steps]) => {
|
|
28
|
+
const total = Object.values(steps).reduce((acc, value) => acc + value, 0);
|
|
29
|
+
if (!total || total < minSamples) return [];
|
|
30
|
+
return Object.entries(steps).filter(([, count]) => count / total < .4).map(([step, count]) => ({
|
|
31
|
+
workflow,
|
|
32
|
+
step,
|
|
33
|
+
dropRate: 1 - count / total
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
const layoutPreference = detectLayout(summary);
|
|
37
|
+
return {
|
|
38
|
+
unusedFields: ignoredFields,
|
|
39
|
+
suggestedHiddenFields: ignoredFields.slice(0, 5),
|
|
40
|
+
frequentlyUsedFields: frequentlyUsedFields.slice(0, 10),
|
|
41
|
+
workflowBottlenecks,
|
|
42
|
+
layoutPreference
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function detectLayout(summary) {
|
|
46
|
+
const fieldCount = Object.keys(summary.fieldCounts).length;
|
|
47
|
+
if (!fieldCount) return;
|
|
48
|
+
if (fieldCount >= 15) return "table";
|
|
49
|
+
if (fieldCount >= 8) return "grid";
|
|
50
|
+
return "form";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { BehaviorAnalyzer };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region ../../libs/personalization/dist/store.js
|
|
2
|
+
var InMemoryBehaviorStore = class {
|
|
3
|
+
events = [];
|
|
4
|
+
async record(event) {
|
|
5
|
+
this.events.push(event);
|
|
6
|
+
}
|
|
7
|
+
async bulkRecord(events) {
|
|
8
|
+
this.events.push(...events);
|
|
9
|
+
}
|
|
10
|
+
async query(query) {
|
|
11
|
+
return filterEvents(this.events, query);
|
|
12
|
+
}
|
|
13
|
+
async summarize(query) {
|
|
14
|
+
const events = await this.query(query);
|
|
15
|
+
const summary = {
|
|
16
|
+
fieldCounts: {},
|
|
17
|
+
featureCounts: {},
|
|
18
|
+
workflowStepCounts: {},
|
|
19
|
+
totalEvents: events.length
|
|
20
|
+
};
|
|
21
|
+
events.forEach((event) => {
|
|
22
|
+
switch (event.type) {
|
|
23
|
+
case "field_access":
|
|
24
|
+
summary.fieldCounts[event.field] = (summary.fieldCounts[event.field] ?? 0) + 1;
|
|
25
|
+
break;
|
|
26
|
+
case "feature_usage":
|
|
27
|
+
summary.featureCounts[event.feature] = (summary.featureCounts[event.feature] ?? 0) + 1;
|
|
28
|
+
break;
|
|
29
|
+
case "workflow_step": {
|
|
30
|
+
const workflow = summary.workflowStepCounts[event.workflow] ??= {};
|
|
31
|
+
workflow[event.step] = (workflow[event.step] ?? 0) + 1;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
default: break;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return summary;
|
|
38
|
+
}
|
|
39
|
+
async clear() {
|
|
40
|
+
this.events = [];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function filterEvents(events, query) {
|
|
44
|
+
return events.filter((event) => {
|
|
45
|
+
if (query.tenantId && event.tenantId !== query.tenantId) return false;
|
|
46
|
+
if (query.userId && event.userId !== query.userId) return false;
|
|
47
|
+
if (query.role && event.role !== query.role) return false;
|
|
48
|
+
if (query.since && event.timestamp < query.since) return false;
|
|
49
|
+
if (query.until && event.timestamp > query.until) return false;
|
|
50
|
+
if (query.operation && event.type === "field_access" && event.operation !== query.operation) return false;
|
|
51
|
+
if (query.feature && event.type === "feature_usage" && event.feature !== query.feature) return false;
|
|
52
|
+
if (query.workflow && event.type === "workflow_step" && event.workflow !== query.workflow) return false;
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { InMemoryBehaviorStore };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { metrics, trace } from "@opentelemetry/api";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/personalization/dist/tracker.js
|
|
4
|
+
const DEFAULT_BUFFER_SIZE = 25;
|
|
5
|
+
var BehaviorTracker = class {
|
|
6
|
+
store;
|
|
7
|
+
context;
|
|
8
|
+
tracer = trace.getTracer("lssm.personalization", "1.0.0");
|
|
9
|
+
counter = metrics.getMeter("lssm.personalization", "1.0.0").createCounter("lssm.personalization.events", { description: "Behavior events tracked for personalization" });
|
|
10
|
+
buffer = [];
|
|
11
|
+
bufferSize;
|
|
12
|
+
flushTimer;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.store = options.store;
|
|
15
|
+
this.context = options.context;
|
|
16
|
+
this.bufferSize = options.bufferSize ?? DEFAULT_BUFFER_SIZE;
|
|
17
|
+
if (options.autoFlushIntervalMs) this.flushTimer = setInterval(() => {
|
|
18
|
+
this.flush();
|
|
19
|
+
}, options.autoFlushIntervalMs);
|
|
20
|
+
}
|
|
21
|
+
trackFieldAccess(input) {
|
|
22
|
+
const event = {
|
|
23
|
+
type: "field_access",
|
|
24
|
+
operation: input.operation,
|
|
25
|
+
field: input.field,
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
...this.context,
|
|
28
|
+
metadata: {
|
|
29
|
+
...this.context.metadata,
|
|
30
|
+
...input.metadata
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.enqueue(event);
|
|
34
|
+
}
|
|
35
|
+
trackFeatureUsage(input) {
|
|
36
|
+
const event = {
|
|
37
|
+
type: "feature_usage",
|
|
38
|
+
feature: input.feature,
|
|
39
|
+
action: input.action,
|
|
40
|
+
timestamp: Date.now(),
|
|
41
|
+
...this.context,
|
|
42
|
+
metadata: {
|
|
43
|
+
...this.context.metadata,
|
|
44
|
+
...input.metadata
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this.enqueue(event);
|
|
48
|
+
}
|
|
49
|
+
trackWorkflowStep(input) {
|
|
50
|
+
const event = {
|
|
51
|
+
type: "workflow_step",
|
|
52
|
+
workflow: input.workflow,
|
|
53
|
+
step: input.step,
|
|
54
|
+
status: input.status,
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
...this.context,
|
|
57
|
+
metadata: {
|
|
58
|
+
...this.context.metadata,
|
|
59
|
+
...input.metadata
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
this.enqueue(event);
|
|
63
|
+
}
|
|
64
|
+
async flush() {
|
|
65
|
+
if (!this.buffer.length) return;
|
|
66
|
+
const events = this.buffer;
|
|
67
|
+
this.buffer = [];
|
|
68
|
+
await this.store.bulkRecord(events);
|
|
69
|
+
}
|
|
70
|
+
async dispose() {
|
|
71
|
+
if (this.flushTimer) clearInterval(this.flushTimer);
|
|
72
|
+
await this.flush();
|
|
73
|
+
}
|
|
74
|
+
enqueue(event) {
|
|
75
|
+
this.buffer.push(event);
|
|
76
|
+
this.counter.add(1, {
|
|
77
|
+
tenantId: this.context.tenantId,
|
|
78
|
+
type: event.type
|
|
79
|
+
});
|
|
80
|
+
this.tracer.startActiveSpan(`personalization.${event.type}`, (span) => {
|
|
81
|
+
span.setAttribute("tenant.id", this.context.tenantId);
|
|
82
|
+
if (this.context.userId) span.setAttribute("user.id", this.context.userId);
|
|
83
|
+
span.setAttribute("personalization.event_type", event.type);
|
|
84
|
+
span.end();
|
|
85
|
+
});
|
|
86
|
+
if (this.buffer.length >= this.bufferSize) this.flush();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const createBehaviorTracker = (options) => new BehaviorTracker(options);
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { createBehaviorTracker };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { applyWorkflowExtension } from "./injector.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/workflow-composer/dist/composer.js
|
|
4
|
+
var WorkflowComposer = class {
|
|
5
|
+
extensions = [];
|
|
6
|
+
register(extension) {
|
|
7
|
+
this.extensions.push(extension);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
registerMany(extensions) {
|
|
11
|
+
extensions.forEach((extension) => this.register(extension));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
compose(params) {
|
|
15
|
+
return this.extensions.filter((extension) => matches(params, extension)).sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0)).reduce((acc, extension) => applyWorkflowExtension(acc, extension), params.base);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function matches(params, extension) {
|
|
19
|
+
if (extension.workflow !== params.base.meta.name) return false;
|
|
20
|
+
if (extension.baseVersion && extension.baseVersion !== params.base.meta.version) return false;
|
|
21
|
+
if (extension.tenantId && extension.tenantId !== params.tenantId) return false;
|
|
22
|
+
if (extension.role && extension.role !== params.role) return false;
|
|
23
|
+
if (extension.device && extension.device !== params.device) return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { WorkflowComposer };
|