@contractspec/example.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.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +37 -39
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +16 -0
  4. package/dist/behavior-tracking.d.ts +1 -4
  5. package/dist/behavior-tracking.d.ts.map +1 -1
  6. package/dist/behavior-tracking.js +39 -42
  7. package/dist/browser/behavior-tracking.js +44 -0
  8. package/dist/browser/docs/index.js +40 -0
  9. package/dist/browser/docs/personalization.docblock.js +40 -0
  10. package/dist/browser/example.js +33 -0
  11. package/dist/browser/index.js +227 -0
  12. package/dist/browser/overlay-customization.js +53 -0
  13. package/dist/browser/workflow-extension.js +60 -0
  14. package/dist/docs/index.d.ts +2 -1
  15. package/dist/docs/index.d.ts.map +1 -0
  16. package/dist/docs/index.js +41 -1
  17. package/dist/docs/personalization.docblock.d.ts +2 -1
  18. package/dist/docs/personalization.docblock.d.ts.map +1 -0
  19. package/dist/docs/personalization.docblock.js +38 -27
  20. package/dist/example.d.ts +2 -6
  21. package/dist/example.d.ts.map +1 -1
  22. package/dist/example.js +32 -43
  23. package/dist/index.d.ts +6 -5
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +227 -6
  26. package/dist/node/behavior-tracking.js +44 -0
  27. package/dist/node/docs/index.js +40 -0
  28. package/dist/node/docs/personalization.docblock.js +40 -0
  29. package/dist/node/example.js +33 -0
  30. package/dist/node/index.js +227 -0
  31. package/dist/node/overlay-customization.js +53 -0
  32. package/dist/node/workflow-extension.js +60 -0
  33. package/dist/overlay-customization.d.ts +1 -4
  34. package/dist/overlay-customization.d.ts.map +1 -1
  35. package/dist/overlay-customization.js +49 -45
  36. package/dist/workflow-extension.d.ts +3 -7
  37. package/dist/workflow-extension.d.ts.map +1 -1
  38. package/dist/workflow-extension.js +53 -59
  39. package/package.json +80 -31
  40. package/tsdown.config.js +1 -2
  41. package/.turbo/turbo-build$colon$bundle.log +0 -38
  42. package/dist/behavior-tracking.js.map +0 -1
  43. package/dist/docs/personalization.docblock.js.map +0 -1
  44. package/dist/example.js.map +0 -1
  45. package/dist/overlay-customization.js.map +0 -1
  46. package/dist/workflow-extension.js.map +0 -1
@@ -0,0 +1,60 @@
1
+ // src/workflow-extension.ts
2
+ import { StabilityEnum } from "@contractspec/lib.contracts";
3
+ import { WorkflowComposer } from "@contractspec/lib.workflow-composer";
4
+ import { Logger, LogLevel } from "@contractspec/lib.logger";
5
+ var logger = new Logger({
6
+ level: LogLevel.DEBUG,
7
+ environment: "development",
8
+ enableColors: true
9
+ });
10
+ var BaseWorkflow = {
11
+ meta: {
12
+ key: "billing.invoiceApproval",
13
+ version: "1.0.0",
14
+ title: "Invoice Approval",
15
+ owners: [],
16
+ tags: [],
17
+ description: "",
18
+ domain: "billing",
19
+ stability: StabilityEnum.Stable
20
+ },
21
+ definition: {
22
+ steps: [
23
+ { id: "validate-invoice", type: "automation", label: "Validate Invoice" },
24
+ { id: "final-approval", type: "human", label: "Final Approval" }
25
+ ],
26
+ transitions: [{ from: "validate-invoice", to: "final-approval" }]
27
+ }
28
+ };
29
+ function composeTenantWorkflowExample() {
30
+ const composer = new WorkflowComposer;
31
+ composer.register({
32
+ workflow: "billing.invoiceApproval",
33
+ tenantId: "acme",
34
+ customSteps: [
35
+ {
36
+ after: "validate-invoice",
37
+ inject: {
38
+ id: "acme-legal",
39
+ type: "human",
40
+ label: "ACME Legal Review"
41
+ },
42
+ transitionTo: "final-approval"
43
+ }
44
+ ]
45
+ });
46
+ return composer.compose({
47
+ base: BaseWorkflow,
48
+ tenantId: "acme"
49
+ });
50
+ }
51
+ function logTenantWorkflowSteps(workflow) {
52
+ logger.info("Tenant workflow composed", {
53
+ workflow: workflow.meta.key,
54
+ steps: workflow.definition.steps.map((step) => step.id)
55
+ });
56
+ }
57
+ export {
58
+ logTenantWorkflowSteps,
59
+ composeTenantWorkflowExample
60
+ };
@@ -1 +1,2 @@
1
- export { };
1
+ import './personalization.docblock';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docs/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC"}
@@ -1 +1,41 @@
1
- import "./personalization.docblock.js";
1
+ // @bun
2
+ // src/docs/personalization.docblock.ts
3
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
4
+ var blocks = [
5
+ {
6
+ id: "docs.examples.personalization",
7
+ title: "Personalization Patterns (example)",
8
+ summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
9
+ kind: "reference",
10
+ visibility: "public",
11
+ route: "/docs/examples/personalization",
12
+ tags: ["personalization", "overlays", "workflows", "example"],
13
+ body: `## Includes
14
+ - Behavior tracking + insight analysis.
15
+ - Overlay customization (hide fields, rename labels).
16
+ - Workflow extension (inject tenant-specific steps).
17
+
18
+ ## Guardrails
19
+ - Keep tracking events structured and non-PII.
20
+ - Keep overlays signed and scoped.
21
+ - Keep workflow composition deterministic.`
22
+ },
23
+ {
24
+ id: "docs.examples.personalization.usage",
25
+ title: "Personalization \u2014 Usage",
26
+ summary: "How to run the small examples and swap adapters.",
27
+ kind: "usage",
28
+ visibility: "public",
29
+ route: "/docs/examples/personalization/usage",
30
+ tags: ["personalization", "usage"],
31
+ body: `## Usage
32
+ - Call \`runBehaviorTrackingExample()\` for insights.
33
+ - Call \`runOverlayCustomizationExample()\` to apply overlays.
34
+ - Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.
35
+
36
+ ## Notes
37
+ - Replace in-memory stores with app-layer storage.
38
+ - Keep PII out of logs and markdown outputs.`
39
+ }
40
+ ];
41
+ registerDocBlocks(blocks);
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=personalization.docblock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"personalization.docblock.d.ts","sourceRoot":"","sources":["../../src/docs/personalization.docblock.ts"],"names":[],"mappings":""}
@@ -1,30 +1,41 @@
1
+ // @bun
2
+ // src/docs/personalization.docblock.ts
1
3
  import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
4
+ var blocks = [
5
+ {
6
+ id: "docs.examples.personalization",
7
+ title: "Personalization Patterns (example)",
8
+ summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
9
+ kind: "reference",
10
+ visibility: "public",
11
+ route: "/docs/examples/personalization",
12
+ tags: ["personalization", "overlays", "workflows", "example"],
13
+ body: `## Includes
14
+ - Behavior tracking + insight analysis.
15
+ - Overlay customization (hide fields, rename labels).
16
+ - Workflow extension (inject tenant-specific steps).
2
17
 
3
- //#region src/docs/personalization.docblock.ts
4
- registerDocBlocks([{
5
- id: "docs.examples.personalization",
6
- title: "Personalization Patterns (example)",
7
- summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
8
- kind: "reference",
9
- visibility: "public",
10
- route: "/docs/examples/personalization",
11
- tags: [
12
- "personalization",
13
- "overlays",
14
- "workflows",
15
- "example"
16
- ],
17
- body: `## Includes\n- Behavior tracking + insight analysis.\n- Overlay customization (hide fields, rename labels).\n- Workflow extension (inject tenant-specific steps).\n\n## Guardrails\n- Keep tracking events structured and non-PII.\n- Keep overlays signed and scoped.\n- Keep workflow composition deterministic.`
18
- }, {
19
- id: "docs.examples.personalization.usage",
20
- title: "Personalization — Usage",
21
- summary: "How to run the small examples and swap adapters.",
22
- kind: "usage",
23
- visibility: "public",
24
- route: "/docs/examples/personalization/usage",
25
- tags: ["personalization", "usage"],
26
- body: `## Usage\n- Call \`runBehaviorTrackingExample()\` for insights.\n- Call \`runOverlayCustomizationExample()\` to apply overlays.\n- Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.\n\n## Notes\n- Replace in-memory stores with app-layer storage.\n- Keep PII out of logs and markdown outputs.`
27
- }]);
18
+ ## Guardrails
19
+ - Keep tracking events structured and non-PII.
20
+ - Keep overlays signed and scoped.
21
+ - Keep workflow composition deterministic.`
22
+ },
23
+ {
24
+ id: "docs.examples.personalization.usage",
25
+ title: "Personalization \u2014 Usage",
26
+ summary: "How to run the small examples and swap adapters.",
27
+ kind: "usage",
28
+ visibility: "public",
29
+ route: "/docs/examples/personalization/usage",
30
+ tags: ["personalization", "usage"],
31
+ body: `## Usage
32
+ - Call \`runBehaviorTrackingExample()\` for insights.
33
+ - Call \`runOverlayCustomizationExample()\` to apply overlays.
34
+ - Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.
28
35
 
29
- //#endregion
30
- //# sourceMappingURL=personalization.docblock.js.map
36
+ ## Notes
37
+ - Replace in-memory stores with app-layer storage.
38
+ - Keep PII out of logs and markdown outputs.`
39
+ }
40
+ ];
41
+ registerDocBlocks(blocks);
package/dist/example.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
2
-
3
- //#region src/example.d.ts
4
- declare const example: _contractspec_lib_contracts0.ExampleSpec;
5
- //#endregion
6
- export { example as default };
1
+ declare const example: import("@contractspec/lib.contracts").ExampleSpec;
2
+ export default example;
7
3
  //# sourceMappingURL=example.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"example.d.ts","names":[],"sources":["../src/example.ts"],"mappings":";;;cAEM,OAAA,EA2BJ,4BAAA,CA3BW,WAAA"}
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,OAAO,mDA2BX,CAAC;AAEH,eAAe,OAAO,CAAC"}
package/dist/example.js CHANGED
@@ -1,45 +1,34 @@
1
+ // @bun
2
+ // src/example.ts
1
3
  import { defineExample } from "@contractspec/lib.contracts";
2
-
3
- //#region src/example.ts
4
- const example = defineExample({
5
- meta: {
6
- key: "personalization",
7
- version: "1.0.0",
8
- title: "Personalization Patterns",
9
- description: "Small examples for behavior tracking, overlay-based UI customization, and tenant workflow extension.",
10
- kind: "library",
11
- visibility: "public",
12
- stability: "experimental",
13
- owners: ["@platform.core"],
14
- tags: [
15
- "personalization",
16
- "overlays",
17
- "behavior",
18
- "workflows"
19
- ]
20
- },
21
- docs: {
22
- rootDocId: "docs.examples.personalization",
23
- usageDocId: "docs.examples.personalization.usage"
24
- },
25
- entrypoints: {
26
- packageName: "@contractspec/example.personalization",
27
- docs: "./docs"
28
- },
29
- surfaces: {
30
- templates: true,
31
- sandbox: {
32
- enabled: true,
33
- modes: ["markdown", "specs"]
34
- },
35
- studio: {
36
- enabled: true,
37
- installable: true
38
- },
39
- mcp: { enabled: true }
40
- }
4
+ var example = defineExample({
5
+ meta: {
6
+ key: "personalization",
7
+ version: "1.0.0",
8
+ title: "Personalization Patterns",
9
+ description: "Small examples for behavior tracking, overlay-based UI customization, and tenant workflow extension.",
10
+ kind: "library",
11
+ visibility: "public",
12
+ stability: "experimental",
13
+ owners: ["@platform.core"],
14
+ tags: ["personalization", "overlays", "behavior", "workflows"]
15
+ },
16
+ docs: {
17
+ rootDocId: "docs.examples.personalization",
18
+ usageDocId: "docs.examples.personalization.usage"
19
+ },
20
+ entrypoints: {
21
+ packageName: "@contractspec/example.personalization",
22
+ docs: "./docs"
23
+ },
24
+ surfaces: {
25
+ templates: true,
26
+ sandbox: { enabled: true, modes: ["markdown", "specs"] },
27
+ studio: { enabled: true, installable: true },
28
+ mcp: { enabled: true }
29
+ }
41
30
  });
42
-
43
- //#endregion
44
- export { example as default };
45
- //# sourceMappingURL=example.js.map
31
+ var example_default = example;
32
+ export {
33
+ example_default as default
34
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { runBehaviorTrackingExample } from "./behavior-tracking.js";
2
- import example from "./example.js";
3
- import { runOverlayCustomizationExample } from "./overlay-customization.js";
4
- import { composeTenantWorkflowExample, logTenantWorkflowSteps } from "./workflow-extension.js";
5
- export { composeTenantWorkflowExample, example, logTenantWorkflowSteps, runBehaviorTrackingExample, runOverlayCustomizationExample };
1
+ export * from './behavior-tracking';
2
+ export * from './overlay-customization';
3
+ export * from './workflow-extension';
4
+ export { default as example } from './example';
5
+ import './docs';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,228 @@
1
- import { runBehaviorTrackingExample } from "./behavior-tracking.js";
2
- import example from "./example.js";
3
- import { runOverlayCustomizationExample } from "./overlay-customization.js";
4
- import { composeTenantWorkflowExample, logTenantWorkflowSteps } from "./workflow-extension.js";
5
- import "./docs/index.js";
1
+ // @bun
2
+ // src/behavior-tracking.ts
3
+ import { createBehaviorTracker } from "@contractspec/lib.personalization/tracker";
4
+ import { InMemoryBehaviorStore } from "@contractspec/lib.personalization/store";
5
+ import { BehaviorAnalyzer } from "@contractspec/lib.personalization/analyzer";
6
+ import { Logger, LogLevel } from "@contractspec/lib.logger";
7
+ var logger = new Logger({
8
+ level: LogLevel.DEBUG,
9
+ environment: "development",
10
+ enableColors: true
11
+ });
12
+ async function runBehaviorTrackingExample() {
13
+ const store = new InMemoryBehaviorStore;
14
+ const tracker = createBehaviorTracker({
15
+ store,
16
+ context: {
17
+ tenantId: "acme",
18
+ userId: "user-123"
19
+ }
20
+ });
21
+ tracker.trackFieldAccess({
22
+ operation: "billing.createOrder",
23
+ field: "internalNotes"
24
+ });
25
+ tracker.trackFieldAccess({
26
+ operation: "billing.createOrder",
27
+ field: "customerReference"
28
+ });
29
+ tracker.trackFeatureUsage({ feature: "workflow-editor", action: "opened" });
30
+ tracker.trackWorkflowStep({
31
+ workflow: "invoice-approval",
32
+ step: "review",
33
+ status: "entered"
34
+ });
35
+ await tracker.flush();
36
+ const analyzer = new BehaviorAnalyzer(store);
37
+ const insights = await analyzer.analyze({
38
+ tenantId: "acme",
39
+ userId: "user-123"
40
+ });
41
+ logger.info("Behavior insights computed", { insights });
42
+ }
6
43
 
7
- export { composeTenantWorkflowExample, example, logTenantWorkflowSteps, runBehaviorTrackingExample, runOverlayCustomizationExample };
44
+ // src/docs/personalization.docblock.ts
45
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
46
+ var blocks = [
47
+ {
48
+ id: "docs.examples.personalization",
49
+ title: "Personalization Patterns (example)",
50
+ summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
51
+ kind: "reference",
52
+ visibility: "public",
53
+ route: "/docs/examples/personalization",
54
+ tags: ["personalization", "overlays", "workflows", "example"],
55
+ body: `## Includes
56
+ - Behavior tracking + insight analysis.
57
+ - Overlay customization (hide fields, rename labels).
58
+ - Workflow extension (inject tenant-specific steps).
59
+
60
+ ## Guardrails
61
+ - Keep tracking events structured and non-PII.
62
+ - Keep overlays signed and scoped.
63
+ - Keep workflow composition deterministic.`
64
+ },
65
+ {
66
+ id: "docs.examples.personalization.usage",
67
+ title: "Personalization \u2014 Usage",
68
+ summary: "How to run the small examples and swap adapters.",
69
+ kind: "usage",
70
+ visibility: "public",
71
+ route: "/docs/examples/personalization/usage",
72
+ tags: ["personalization", "usage"],
73
+ body: `## Usage
74
+ - Call \`runBehaviorTrackingExample()\` for insights.
75
+ - Call \`runOverlayCustomizationExample()\` to apply overlays.
76
+ - Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.
77
+
78
+ ## Notes
79
+ - Replace in-memory stores with app-layer storage.
80
+ - Keep PII out of logs and markdown outputs.`
81
+ }
82
+ ];
83
+ registerDocBlocks(blocks);
84
+ // src/example.ts
85
+ import { defineExample } from "@contractspec/lib.contracts";
86
+ var example = defineExample({
87
+ meta: {
88
+ key: "personalization",
89
+ version: "1.0.0",
90
+ title: "Personalization Patterns",
91
+ description: "Small examples for behavior tracking, overlay-based UI customization, and tenant workflow extension.",
92
+ kind: "library",
93
+ visibility: "public",
94
+ stability: "experimental",
95
+ owners: ["@platform.core"],
96
+ tags: ["personalization", "overlays", "behavior", "workflows"]
97
+ },
98
+ docs: {
99
+ rootDocId: "docs.examples.personalization",
100
+ usageDocId: "docs.examples.personalization.usage"
101
+ },
102
+ entrypoints: {
103
+ packageName: "@contractspec/example.personalization",
104
+ docs: "./docs"
105
+ },
106
+ surfaces: {
107
+ templates: true,
108
+ sandbox: { enabled: true, modes: ["markdown", "specs"] },
109
+ studio: { enabled: true, installable: true },
110
+ mcp: { enabled: true }
111
+ }
112
+ });
113
+ var example_default = example;
114
+
115
+ // src/overlay-customization.ts
116
+ import { defineOverlay } from "@contractspec/lib.overlay-engine/spec";
117
+ import { signOverlay } from "@contractspec/lib.overlay-engine/signer";
118
+ import {
119
+ OverlayEngine,
120
+ OverlayRegistry
121
+ } from "@contractspec/lib.overlay-engine";
122
+ import { Logger as Logger2, LogLevel as LogLevel2 } from "@contractspec/lib.logger";
123
+ var logger2 = new Logger2({
124
+ level: LogLevel2.DEBUG,
125
+ environment: "development",
126
+ enableColors: true
127
+ });
128
+ async function runOverlayCustomizationExample() {
129
+ const registry = new OverlayRegistry({ allowUnsigned: true });
130
+ const engine = new OverlayEngine({ registry });
131
+ const overlay = defineOverlay({
132
+ overlayId: "demo-overlay",
133
+ version: "1.0.0",
134
+ appliesTo: {
135
+ capability: "billing.createOrder",
136
+ tenantId: "demo"
137
+ },
138
+ modifications: [
139
+ { type: "hideField", field: "internalNotes" },
140
+ {
141
+ type: "renameLabel",
142
+ field: "customerReference",
143
+ newLabel: "PO Number"
144
+ }
145
+ ]
146
+ });
147
+ const signed = await signOverlay(overlay, process.env.PRIVATE_KEY_PEM ?? "");
148
+ registry.register(signed);
149
+ const result = engine.apply({
150
+ target: {
151
+ fields: [
152
+ {
153
+ key: "customerReference",
154
+ label: "Customer Reference",
155
+ visible: true
156
+ },
157
+ { key: "internalNotes", label: "Internal Notes", visible: true }
158
+ ]
159
+ },
160
+ capability: "billing.createOrder",
161
+ tenantId: "demo"
162
+ });
163
+ logger2.info("Overlay applied", { fields: result.target.fields });
164
+ }
165
+
166
+ // src/workflow-extension.ts
167
+ import { StabilityEnum } from "@contractspec/lib.contracts";
168
+ import { WorkflowComposer } from "@contractspec/lib.workflow-composer";
169
+ import { Logger as Logger3, LogLevel as LogLevel3 } from "@contractspec/lib.logger";
170
+ var logger3 = new Logger3({
171
+ level: LogLevel3.DEBUG,
172
+ environment: "development",
173
+ enableColors: true
174
+ });
175
+ var BaseWorkflow = {
176
+ meta: {
177
+ key: "billing.invoiceApproval",
178
+ version: "1.0.0",
179
+ title: "Invoice Approval",
180
+ owners: [],
181
+ tags: [],
182
+ description: "",
183
+ domain: "billing",
184
+ stability: StabilityEnum.Stable
185
+ },
186
+ definition: {
187
+ steps: [
188
+ { id: "validate-invoice", type: "automation", label: "Validate Invoice" },
189
+ { id: "final-approval", type: "human", label: "Final Approval" }
190
+ ],
191
+ transitions: [{ from: "validate-invoice", to: "final-approval" }]
192
+ }
193
+ };
194
+ function composeTenantWorkflowExample() {
195
+ const composer = new WorkflowComposer;
196
+ composer.register({
197
+ workflow: "billing.invoiceApproval",
198
+ tenantId: "acme",
199
+ customSteps: [
200
+ {
201
+ after: "validate-invoice",
202
+ inject: {
203
+ id: "acme-legal",
204
+ type: "human",
205
+ label: "ACME Legal Review"
206
+ },
207
+ transitionTo: "final-approval"
208
+ }
209
+ ]
210
+ });
211
+ return composer.compose({
212
+ base: BaseWorkflow,
213
+ tenantId: "acme"
214
+ });
215
+ }
216
+ function logTenantWorkflowSteps(workflow) {
217
+ logger3.info("Tenant workflow composed", {
218
+ workflow: workflow.meta.key,
219
+ steps: workflow.definition.steps.map((step) => step.id)
220
+ });
221
+ }
222
+ export {
223
+ runOverlayCustomizationExample,
224
+ runBehaviorTrackingExample,
225
+ logTenantWorkflowSteps,
226
+ example_default as example,
227
+ composeTenantWorkflowExample
228
+ };
@@ -0,0 +1,44 @@
1
+ // src/behavior-tracking.ts
2
+ import { createBehaviorTracker } from "@contractspec/lib.personalization/tracker";
3
+ import { InMemoryBehaviorStore } from "@contractspec/lib.personalization/store";
4
+ import { BehaviorAnalyzer } from "@contractspec/lib.personalization/analyzer";
5
+ import { Logger, LogLevel } from "@contractspec/lib.logger";
6
+ var logger = new Logger({
7
+ level: LogLevel.DEBUG,
8
+ environment: "development",
9
+ enableColors: true
10
+ });
11
+ async function runBehaviorTrackingExample() {
12
+ const store = new InMemoryBehaviorStore;
13
+ const tracker = createBehaviorTracker({
14
+ store,
15
+ context: {
16
+ tenantId: "acme",
17
+ userId: "user-123"
18
+ }
19
+ });
20
+ tracker.trackFieldAccess({
21
+ operation: "billing.createOrder",
22
+ field: "internalNotes"
23
+ });
24
+ tracker.trackFieldAccess({
25
+ operation: "billing.createOrder",
26
+ field: "customerReference"
27
+ });
28
+ tracker.trackFeatureUsage({ feature: "workflow-editor", action: "opened" });
29
+ tracker.trackWorkflowStep({
30
+ workflow: "invoice-approval",
31
+ step: "review",
32
+ status: "entered"
33
+ });
34
+ await tracker.flush();
35
+ const analyzer = new BehaviorAnalyzer(store);
36
+ const insights = await analyzer.analyze({
37
+ tenantId: "acme",
38
+ userId: "user-123"
39
+ });
40
+ logger.info("Behavior insights computed", { insights });
41
+ }
42
+ export {
43
+ runBehaviorTrackingExample
44
+ };
@@ -0,0 +1,40 @@
1
+ // src/docs/personalization.docblock.ts
2
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
3
+ var blocks = [
4
+ {
5
+ id: "docs.examples.personalization",
6
+ title: "Personalization Patterns (example)",
7
+ summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/examples/personalization",
11
+ tags: ["personalization", "overlays", "workflows", "example"],
12
+ body: `## Includes
13
+ - Behavior tracking + insight analysis.
14
+ - Overlay customization (hide fields, rename labels).
15
+ - Workflow extension (inject tenant-specific steps).
16
+
17
+ ## Guardrails
18
+ - Keep tracking events structured and non-PII.
19
+ - Keep overlays signed and scoped.
20
+ - Keep workflow composition deterministic.`
21
+ },
22
+ {
23
+ id: "docs.examples.personalization.usage",
24
+ title: "Personalization — Usage",
25
+ summary: "How to run the small examples and swap adapters.",
26
+ kind: "usage",
27
+ visibility: "public",
28
+ route: "/docs/examples/personalization/usage",
29
+ tags: ["personalization", "usage"],
30
+ body: `## Usage
31
+ - Call \`runBehaviorTrackingExample()\` for insights.
32
+ - Call \`runOverlayCustomizationExample()\` to apply overlays.
33
+ - Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.
34
+
35
+ ## Notes
36
+ - Replace in-memory stores with app-layer storage.
37
+ - Keep PII out of logs and markdown outputs.`
38
+ }
39
+ ];
40
+ registerDocBlocks(blocks);
@@ -0,0 +1,40 @@
1
+ // src/docs/personalization.docblock.ts
2
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
3
+ var blocks = [
4
+ {
5
+ id: "docs.examples.personalization",
6
+ title: "Personalization Patterns (example)",
7
+ summary: "Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/examples/personalization",
11
+ tags: ["personalization", "overlays", "workflows", "example"],
12
+ body: `## Includes
13
+ - Behavior tracking + insight analysis.
14
+ - Overlay customization (hide fields, rename labels).
15
+ - Workflow extension (inject tenant-specific steps).
16
+
17
+ ## Guardrails
18
+ - Keep tracking events structured and non-PII.
19
+ - Keep overlays signed and scoped.
20
+ - Keep workflow composition deterministic.`
21
+ },
22
+ {
23
+ id: "docs.examples.personalization.usage",
24
+ title: "Personalization — Usage",
25
+ summary: "How to run the small examples and swap adapters.",
26
+ kind: "usage",
27
+ visibility: "public",
28
+ route: "/docs/examples/personalization/usage",
29
+ tags: ["personalization", "usage"],
30
+ body: `## Usage
31
+ - Call \`runBehaviorTrackingExample()\` for insights.
32
+ - Call \`runOverlayCustomizationExample()\` to apply overlays.
33
+ - Call \`composeTenantWorkflowExample()\` and \`logTenantWorkflowSteps()\` to inspect steps.
34
+
35
+ ## Notes
36
+ - Replace in-memory stores with app-layer storage.
37
+ - Keep PII out of logs and markdown outputs.`
38
+ }
39
+ ];
40
+ registerDocBlocks(blocks);