@contractspec/lib.personalization 1.57.0 → 1.58.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.
- package/dist/adapter.d.ts +15 -19
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +43 -38
- package/dist/analyzer.d.ts +15 -19
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +69 -51
- package/dist/browser/adapter.js +46 -0
- package/dist/browser/analyzer.js +72 -0
- package/dist/browser/docs/behavior-tracking.docblock.js +97 -0
- package/dist/browser/docs/index.js +271 -0
- package/dist/browser/docs/overlay-engine.docblock.js +98 -0
- package/dist/browser/docs/workflow-composition.docblock.js +83 -0
- package/dist/browser/index.js +555 -0
- package/dist/browser/store.js +75 -0
- package/dist/browser/tracker.js +94 -0
- package/dist/browser/types.js +0 -0
- package/dist/docs/behavior-tracking.docblock.d.ts +2 -6
- package/dist/docs/behavior-tracking.docblock.d.ts.map +1 -1
- package/dist/docs/behavior-tracking.docblock.js +95 -15
- package/dist/docs/index.d.ts +4 -3
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +272 -3
- package/dist/docs/overlay-engine.docblock.d.ts +2 -6
- package/dist/docs/overlay-engine.docblock.d.ts.map +1 -1
- package/dist/docs/overlay-engine.docblock.js +96 -15
- package/dist/docs/workflow-composition.docblock.d.ts +2 -6
- package/dist/docs/workflow-composition.docblock.d.ts.map +1 -1
- package/dist/docs/workflow-composition.docblock.js +81 -15
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +555 -6
- package/dist/node/adapter.js +46 -0
- package/dist/node/analyzer.js +72 -0
- package/dist/node/docs/behavior-tracking.docblock.js +97 -0
- package/dist/node/docs/index.js +271 -0
- package/dist/node/docs/overlay-engine.docblock.js +98 -0
- package/dist/node/docs/workflow-composition.docblock.js +83 -0
- package/dist/node/index.js +555 -0
- package/dist/node/store.js +75 -0
- package/dist/node/tracker.js +94 -0
- package/dist/node/types.js +0 -0
- package/dist/store.d.ts +14 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +74 -57
- package/dist/tracker.d.ts +42 -46
- package/dist/tracker.d.ts.map +1 -1
- package/dist/tracker.js +93 -91
- package/dist/types.d.ts +48 -51
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +104 -37
- package/dist/adapter.js.map +0 -1
- package/dist/analyzer.js.map +0 -1
- package/dist/docs/behavior-tracking.docblock.js.map +0 -1
- package/dist/docs/overlay-engine.docblock.js.map +0 -1
- package/dist/docs/workflow-composition.docblock.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/tracker.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/docs/behavior-tracking.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var personalization_behavior_tracking_DocBlocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.personalization.behavior-tracking",
|
|
6
|
+
title: "Behavior Tracking",
|
|
7
|
+
summary: "`@contractspec/lib.personalization` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/personalization/behavior-tracking",
|
|
11
|
+
tags: ["personalization", "behavior-tracking"],
|
|
12
|
+
body: `# Behavior Tracking
|
|
13
|
+
|
|
14
|
+
\`@contractspec/lib.personalization\` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.
|
|
15
|
+
|
|
16
|
+
## Tracker
|
|
17
|
+
|
|
18
|
+
\`\`\`ts
|
|
19
|
+
import { createBehaviorTracker } from '@contractspec/lib.personalization';
|
|
20
|
+
import { InMemoryBehaviorStore } from '@contractspec/lib.personalization/store';
|
|
21
|
+
|
|
22
|
+
const tracker = createBehaviorTracker({
|
|
23
|
+
store: new InMemoryBehaviorStore(),
|
|
24
|
+
context: { tenantId: ctx.tenant.id, userId: ctx.identity.userId },
|
|
25
|
+
autoFlushIntervalMs: 5000,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
tracker.trackFieldAccess({ operation: 'billing.createOrder', field: 'internalNotes' });
|
|
29
|
+
tracker.trackFeatureUsage({ feature: 'workflow-editor', action: 'opened' });
|
|
30
|
+
tracker.trackWorkflowStep({ workflow: 'invoice-approval', step: 'review', status: 'entered' });
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
All events are buffered and flushed either when the buffer hits 25 entries or when \`autoFlushIntervalMs\` elapses. Tracked metrics flow to OpenTelemetry via the meter/counter built into the tracker.
|
|
34
|
+
|
|
35
|
+
## Analyzer
|
|
36
|
+
|
|
37
|
+
\`\`\`ts
|
|
38
|
+
import { BehaviorAnalyzer } from '@contractspec/lib.personalization/analyzer';
|
|
39
|
+
|
|
40
|
+
const analyzer = new BehaviorAnalyzer(store, { fieldInactivityThreshold: 2 });
|
|
41
|
+
const insights = await analyzer.analyze({ tenantId: 'acme', userId: 'manager-42', windowMs: 7 * 24 * 60 * 60 * 1000 });
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
{
|
|
45
|
+
unusedFields: ['internalNotes'],
|
|
46
|
+
suggestedHiddenFields: ['internalNotes'],
|
|
47
|
+
frequentlyUsedFields: ['customerReference', 'items'],
|
|
48
|
+
workflowBottlenecks: [{ workflow: 'invoice-approval', step: 'finance-review', dropRate: 0.6 }],
|
|
49
|
+
layoutPreference: 'table'
|
|
50
|
+
}
|
|
51
|
+
*/
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
Use the analyzer output with the overlay adapter to generate suggestions automatically.
|
|
55
|
+
|
|
56
|
+
## Adapter
|
|
57
|
+
|
|
58
|
+
\`\`\`ts
|
|
59
|
+
import { insightsToOverlaySuggestion } from '@contractspec/lib.personalization/adapter';
|
|
60
|
+
|
|
61
|
+
const overlay = insightsToOverlaySuggestion(insights, {
|
|
62
|
+
overlayId: 'acme-order-form',
|
|
63
|
+
tenantId: 'acme',
|
|
64
|
+
capability: 'billing.createOrder',
|
|
65
|
+
});
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
When the adapter returns an overlay spec, pass it to the overlay engine to register or sign it.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
`
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
registerDocBlocks(personalization_behavior_tracking_DocBlocks);
|
|
95
|
+
export {
|
|
96
|
+
personalization_behavior_tracking_DocBlocks
|
|
97
|
+
};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// src/docs/behavior-tracking.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var personalization_behavior_tracking_DocBlocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.personalization.behavior-tracking",
|
|
6
|
+
title: "Behavior Tracking",
|
|
7
|
+
summary: "`@contractspec/lib.personalization` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/personalization/behavior-tracking",
|
|
11
|
+
tags: ["personalization", "behavior-tracking"],
|
|
12
|
+
body: `# Behavior Tracking
|
|
13
|
+
|
|
14
|
+
\`@contractspec/lib.personalization\` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.
|
|
15
|
+
|
|
16
|
+
## Tracker
|
|
17
|
+
|
|
18
|
+
\`\`\`ts
|
|
19
|
+
import { createBehaviorTracker } from '@contractspec/lib.personalization';
|
|
20
|
+
import { InMemoryBehaviorStore } from '@contractspec/lib.personalization/store';
|
|
21
|
+
|
|
22
|
+
const tracker = createBehaviorTracker({
|
|
23
|
+
store: new InMemoryBehaviorStore(),
|
|
24
|
+
context: { tenantId: ctx.tenant.id, userId: ctx.identity.userId },
|
|
25
|
+
autoFlushIntervalMs: 5000,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
tracker.trackFieldAccess({ operation: 'billing.createOrder', field: 'internalNotes' });
|
|
29
|
+
tracker.trackFeatureUsage({ feature: 'workflow-editor', action: 'opened' });
|
|
30
|
+
tracker.trackWorkflowStep({ workflow: 'invoice-approval', step: 'review', status: 'entered' });
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
All events are buffered and flushed either when the buffer hits 25 entries or when \`autoFlushIntervalMs\` elapses. Tracked metrics flow to OpenTelemetry via the meter/counter built into the tracker.
|
|
34
|
+
|
|
35
|
+
## Analyzer
|
|
36
|
+
|
|
37
|
+
\`\`\`ts
|
|
38
|
+
import { BehaviorAnalyzer } from '@contractspec/lib.personalization/analyzer';
|
|
39
|
+
|
|
40
|
+
const analyzer = new BehaviorAnalyzer(store, { fieldInactivityThreshold: 2 });
|
|
41
|
+
const insights = await analyzer.analyze({ tenantId: 'acme', userId: 'manager-42', windowMs: 7 * 24 * 60 * 60 * 1000 });
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
{
|
|
45
|
+
unusedFields: ['internalNotes'],
|
|
46
|
+
suggestedHiddenFields: ['internalNotes'],
|
|
47
|
+
frequentlyUsedFields: ['customerReference', 'items'],
|
|
48
|
+
workflowBottlenecks: [{ workflow: 'invoice-approval', step: 'finance-review', dropRate: 0.6 }],
|
|
49
|
+
layoutPreference: 'table'
|
|
50
|
+
}
|
|
51
|
+
*/
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
Use the analyzer output with the overlay adapter to generate suggestions automatically.
|
|
55
|
+
|
|
56
|
+
## Adapter
|
|
57
|
+
|
|
58
|
+
\`\`\`ts
|
|
59
|
+
import { insightsToOverlaySuggestion } from '@contractspec/lib.personalization/adapter';
|
|
60
|
+
|
|
61
|
+
const overlay = insightsToOverlaySuggestion(insights, {
|
|
62
|
+
overlayId: 'acme-order-form',
|
|
63
|
+
tenantId: 'acme',
|
|
64
|
+
capability: 'billing.createOrder',
|
|
65
|
+
});
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
When the adapter returns an overlay spec, pass it to the overlay engine to register or sign it.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
`
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
registerDocBlocks(personalization_behavior_tracking_DocBlocks);
|
|
95
|
+
|
|
96
|
+
// src/docs/overlay-engine.docblock.ts
|
|
97
|
+
import { registerDocBlocks as registerDocBlocks2 } from "@contractspec/lib.contracts/docs";
|
|
98
|
+
var personalization_overlay_engine_DocBlocks = [
|
|
99
|
+
{
|
|
100
|
+
id: "docs.personalization.overlay-engine",
|
|
101
|
+
title: "Overlay Engine",
|
|
102
|
+
summary: "`@contractspec/lib.overlay-engine` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.",
|
|
103
|
+
kind: "reference",
|
|
104
|
+
visibility: "public",
|
|
105
|
+
route: "/docs/personalization/overlay-engine",
|
|
106
|
+
tags: ["personalization", "overlay-engine"],
|
|
107
|
+
body: `# Overlay Engine
|
|
108
|
+
|
|
109
|
+
\`@contractspec/lib.overlay-engine\` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.
|
|
110
|
+
|
|
111
|
+
## Key APIs
|
|
112
|
+
|
|
113
|
+
- \`defineOverlay(spec)\` – helper to keep specs typed.
|
|
114
|
+
- \`OverlayRegistry\` – register signed overlays and retrieve them per context.
|
|
115
|
+
- \`OverlayEngine\` – apply overlays to renderable targets, emit audit events, and merge modifications deterministically.
|
|
116
|
+
- \`signOverlay(spec, privateKey)\` – Ed25519/RSA-PSS signer.
|
|
117
|
+
- \`verifyOverlaySignature(overlay)\` – verify public key signatures.
|
|
118
|
+
- \`useOverlay(engine, params)\` – client hook that returns \`{ target, overlaysApplied }\`.
|
|
119
|
+
|
|
120
|
+
## Scope Precedence
|
|
121
|
+
|
|
122
|
+
Registrations are sorted by specificity:
|
|
123
|
+
|
|
124
|
+
1. Tenant overlays
|
|
125
|
+
2. Role overlays
|
|
126
|
+
3. User overlays
|
|
127
|
+
4. Device overlays
|
|
128
|
+
|
|
129
|
+
Less specific overlays run first; more specific overlays override later.
|
|
130
|
+
|
|
131
|
+
## Example
|
|
132
|
+
|
|
133
|
+
\`\`\`ts
|
|
134
|
+
const registry = new OverlayRegistry();
|
|
135
|
+
const engine = new OverlayEngine({
|
|
136
|
+
registry,
|
|
137
|
+
audit: (event) => auditLogService.record(event),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const overlay = defineOverlay({
|
|
141
|
+
overlayId: 'acme-order-form',
|
|
142
|
+
version: '1.0.0',
|
|
143
|
+
appliesTo: {
|
|
144
|
+
capability: 'billing.createOrder',
|
|
145
|
+
tenantId: 'acme',
|
|
146
|
+
},
|
|
147
|
+
modifications: [
|
|
148
|
+
{ type: 'hideField', field: 'internalNotes' },
|
|
149
|
+
{ type: 'renameLabel', field: 'customerReference', newLabel: 'PO Number' },
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const signedOverlay = await signOverlay(overlay, privateKeyPem);
|
|
154
|
+
registry.register(signedOverlay);
|
|
155
|
+
|
|
156
|
+
const result = engine.apply({
|
|
157
|
+
target: { fields: baseFields },
|
|
158
|
+
capability: 'billing.createOrder',
|
|
159
|
+
tenantId: 'acme',
|
|
160
|
+
userId: 'manager-7',
|
|
161
|
+
});
|
|
162
|
+
\`\`\`
|
|
163
|
+
|
|
164
|
+
\`result.target.fields\` now carries the hidden and renamed outputs ready for rendering.
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
`
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
registerDocBlocks2(personalization_overlay_engine_DocBlocks);
|
|
191
|
+
|
|
192
|
+
// src/docs/workflow-composition.docblock.ts
|
|
193
|
+
import { registerDocBlocks as registerDocBlocks3 } from "@contractspec/lib.contracts/docs";
|
|
194
|
+
var personalization_workflow_composition_DocBlocks = [
|
|
195
|
+
{
|
|
196
|
+
id: "docs.personalization.workflow-composition",
|
|
197
|
+
title: "Workflow Composition",
|
|
198
|
+
summary: "`@contractspec/lib.workflow-composer` composes base WorkflowSpecs with tenant/role/device-specific extensions.",
|
|
199
|
+
kind: "reference",
|
|
200
|
+
visibility: "public",
|
|
201
|
+
route: "/docs/personalization/workflow-composition",
|
|
202
|
+
tags: ["personalization", "workflow-composition"],
|
|
203
|
+
body: `# Workflow Composition
|
|
204
|
+
|
|
205
|
+
\`@contractspec/lib.workflow-composer\` composes base WorkflowSpecs with tenant/role/device-specific extensions.
|
|
206
|
+
|
|
207
|
+
## Extensions
|
|
208
|
+
|
|
209
|
+
\`\`\`ts
|
|
210
|
+
import { WorkflowComposer } from '@contractspec/lib.workflow-composer';
|
|
211
|
+
import { approvalStepTemplate } from '@contractspec/lib.workflow-composer/templates';
|
|
212
|
+
|
|
213
|
+
const composer = new WorkflowComposer();
|
|
214
|
+
|
|
215
|
+
composer.register({
|
|
216
|
+
workflow: 'billing.invoiceApproval',
|
|
217
|
+
tenantId: 'acme',
|
|
218
|
+
priority: 10,
|
|
219
|
+
customSteps: [
|
|
220
|
+
{
|
|
221
|
+
after: 'validate-invoice',
|
|
222
|
+
inject: approvalStepTemplate({
|
|
223
|
+
id: 'acme-legal-review',
|
|
224
|
+
label: 'Legal Review (ACME)',
|
|
225
|
+
description: 'Tenant-specific compliance step.',
|
|
226
|
+
}),
|
|
227
|
+
transitionTo: 'final-approval',
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
hiddenSteps: ['internal-audit'],
|
|
231
|
+
});
|
|
232
|
+
\`\`\`
|
|
233
|
+
|
|
234
|
+
## Compose
|
|
235
|
+
|
|
236
|
+
\`\`\`ts
|
|
237
|
+
const runtimeSpec = composer.compose({
|
|
238
|
+
base: BaseInvoiceWorkflow,
|
|
239
|
+
tenantId: 'acme',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
workflowRunner.execute(runtimeSpec, ctx);
|
|
243
|
+
\`\`\`
|
|
244
|
+
|
|
245
|
+
The composer uses anchor references (\`after\`/\`before\`) to place injected steps and cleans up transitions when steps are hidden.
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
`
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
registerDocBlocks3(personalization_workflow_composition_DocBlocks);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// src/docs/overlay-engine.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var personalization_overlay_engine_DocBlocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.personalization.overlay-engine",
|
|
6
|
+
title: "Overlay Engine",
|
|
7
|
+
summary: "`@contractspec/lib.overlay-engine` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/personalization/overlay-engine",
|
|
11
|
+
tags: ["personalization", "overlay-engine"],
|
|
12
|
+
body: `# Overlay Engine
|
|
13
|
+
|
|
14
|
+
\`@contractspec/lib.overlay-engine\` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.
|
|
15
|
+
|
|
16
|
+
## Key APIs
|
|
17
|
+
|
|
18
|
+
- \`defineOverlay(spec)\` – helper to keep specs typed.
|
|
19
|
+
- \`OverlayRegistry\` – register signed overlays and retrieve them per context.
|
|
20
|
+
- \`OverlayEngine\` – apply overlays to renderable targets, emit audit events, and merge modifications deterministically.
|
|
21
|
+
- \`signOverlay(spec, privateKey)\` – Ed25519/RSA-PSS signer.
|
|
22
|
+
- \`verifyOverlaySignature(overlay)\` – verify public key signatures.
|
|
23
|
+
- \`useOverlay(engine, params)\` – client hook that returns \`{ target, overlaysApplied }\`.
|
|
24
|
+
|
|
25
|
+
## Scope Precedence
|
|
26
|
+
|
|
27
|
+
Registrations are sorted by specificity:
|
|
28
|
+
|
|
29
|
+
1. Tenant overlays
|
|
30
|
+
2. Role overlays
|
|
31
|
+
3. User overlays
|
|
32
|
+
4. Device overlays
|
|
33
|
+
|
|
34
|
+
Less specific overlays run first; more specific overlays override later.
|
|
35
|
+
|
|
36
|
+
## Example
|
|
37
|
+
|
|
38
|
+
\`\`\`ts
|
|
39
|
+
const registry = new OverlayRegistry();
|
|
40
|
+
const engine = new OverlayEngine({
|
|
41
|
+
registry,
|
|
42
|
+
audit: (event) => auditLogService.record(event),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const overlay = defineOverlay({
|
|
46
|
+
overlayId: 'acme-order-form',
|
|
47
|
+
version: '1.0.0',
|
|
48
|
+
appliesTo: {
|
|
49
|
+
capability: 'billing.createOrder',
|
|
50
|
+
tenantId: 'acme',
|
|
51
|
+
},
|
|
52
|
+
modifications: [
|
|
53
|
+
{ type: 'hideField', field: 'internalNotes' },
|
|
54
|
+
{ type: 'renameLabel', field: 'customerReference', newLabel: 'PO Number' },
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const signedOverlay = await signOverlay(overlay, privateKeyPem);
|
|
59
|
+
registry.register(signedOverlay);
|
|
60
|
+
|
|
61
|
+
const result = engine.apply({
|
|
62
|
+
target: { fields: baseFields },
|
|
63
|
+
capability: 'billing.createOrder',
|
|
64
|
+
tenantId: 'acme',
|
|
65
|
+
userId: 'manager-7',
|
|
66
|
+
});
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
\`result.target.fields\` now carries the hidden and renamed outputs ready for rendering.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
`
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
registerDocBlocks(personalization_overlay_engine_DocBlocks);
|
|
96
|
+
export {
|
|
97
|
+
personalization_overlay_engine_DocBlocks
|
|
98
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/docs/workflow-composition.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var personalization_workflow_composition_DocBlocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.personalization.workflow-composition",
|
|
6
|
+
title: "Workflow Composition",
|
|
7
|
+
summary: "`@contractspec/lib.workflow-composer` composes base WorkflowSpecs with tenant/role/device-specific extensions.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/personalization/workflow-composition",
|
|
11
|
+
tags: ["personalization", "workflow-composition"],
|
|
12
|
+
body: `# Workflow Composition
|
|
13
|
+
|
|
14
|
+
\`@contractspec/lib.workflow-composer\` composes base WorkflowSpecs with tenant/role/device-specific extensions.
|
|
15
|
+
|
|
16
|
+
## Extensions
|
|
17
|
+
|
|
18
|
+
\`\`\`ts
|
|
19
|
+
import { WorkflowComposer } from '@contractspec/lib.workflow-composer';
|
|
20
|
+
import { approvalStepTemplate } from '@contractspec/lib.workflow-composer/templates';
|
|
21
|
+
|
|
22
|
+
const composer = new WorkflowComposer();
|
|
23
|
+
|
|
24
|
+
composer.register({
|
|
25
|
+
workflow: 'billing.invoiceApproval',
|
|
26
|
+
tenantId: 'acme',
|
|
27
|
+
priority: 10,
|
|
28
|
+
customSteps: [
|
|
29
|
+
{
|
|
30
|
+
after: 'validate-invoice',
|
|
31
|
+
inject: approvalStepTemplate({
|
|
32
|
+
id: 'acme-legal-review',
|
|
33
|
+
label: 'Legal Review (ACME)',
|
|
34
|
+
description: 'Tenant-specific compliance step.',
|
|
35
|
+
}),
|
|
36
|
+
transitionTo: 'final-approval',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
hiddenSteps: ['internal-audit'],
|
|
40
|
+
});
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Compose
|
|
44
|
+
|
|
45
|
+
\`\`\`ts
|
|
46
|
+
const runtimeSpec = composer.compose({
|
|
47
|
+
base: BaseInvoiceWorkflow,
|
|
48
|
+
tenantId: 'acme',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
workflowRunner.execute(runtimeSpec, ctx);
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
The composer uses anchor references (\`after\`/\`before\`) to place injected steps and cleans up transitions when steps are hidden.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
`
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
registerDocBlocks(personalization_workflow_composition_DocBlocks);
|
|
81
|
+
export {
|
|
82
|
+
personalization_workflow_composition_DocBlocks
|
|
83
|
+
};
|