@contractspec/example.personalization 1.44.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 (65) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +91 -0
  2. package/.turbo/turbo-build.log +93 -0
  3. package/CHANGELOG.md +228 -0
  4. package/LICENSE +21 -0
  5. package/dist/behavior-tracking.d.ts +5 -0
  6. package/dist/behavior-tracking.d.ts.map +1 -0
  7. package/dist/behavior-tracking.js +48 -0
  8. package/dist/behavior-tracking.js.map +1 -0
  9. package/dist/docs/index.d.ts +1 -0
  10. package/dist/docs/index.js +1 -0
  11. package/dist/docs/personalization.docblock.d.ts +1 -0
  12. package/dist/docs/personalization.docblock.js +30 -0
  13. package/dist/docs/personalization.docblock.js.map +1 -0
  14. package/dist/example.d.ts +34 -0
  15. package/dist/example.d.ts.map +1 -0
  16. package/dist/example.js +39 -0
  17. package/dist/example.js.map +1 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +7 -0
  20. package/dist/libs/contracts/src/capabilities/capabilities.d.ts +9 -0
  21. package/dist/libs/contracts/src/capabilities/capabilities.d.ts.map +1 -0
  22. package/dist/libs/contracts/src/docs/registry.d.ts +8 -0
  23. package/dist/libs/contracts/src/docs/registry.d.ts.map +1 -0
  24. package/dist/libs/contracts/src/events.d.ts +1 -0
  25. package/dist/libs/contracts/src/experiments/spec-resolver.d.ts +3 -0
  26. package/dist/libs/contracts/src/experiments/spec.d.ts +9 -0
  27. package/dist/libs/contracts/src/experiments/spec.d.ts.map +1 -0
  28. package/dist/libs/contracts/src/features/index.d.ts +4 -0
  29. package/dist/libs/contracts/src/features/install.d.ts +4 -0
  30. package/dist/libs/contracts/src/features/registry.d.ts +1 -0
  31. package/dist/libs/contracts/src/features/types.d.ts +13 -0
  32. package/dist/libs/contracts/src/features/types.d.ts.map +1 -0
  33. package/dist/libs/contracts/src/features/validation.d.ts +1 -0
  34. package/dist/libs/contracts/src/install.d.ts +6 -0
  35. package/dist/libs/contracts/src/operations/index.d.ts +2 -0
  36. package/dist/libs/contracts/src/operations/operation.d.ts +2 -0
  37. package/dist/libs/contracts/src/operations/registry.d.ts +4 -0
  38. package/dist/libs/contracts/src/ownership.d.ts +60 -0
  39. package/dist/libs/contracts/src/ownership.d.ts.map +1 -0
  40. package/dist/libs/contracts/src/presentations/index.d.ts +2 -0
  41. package/dist/libs/contracts/src/presentations/registry.d.ts +1 -0
  42. package/dist/libs/contracts/src/presentations/transform-engine.d.ts +1 -0
  43. package/dist/libs/contracts/src/registry.d.ts +1 -0
  44. package/dist/libs/contracts/src/resources.d.ts +1 -0
  45. package/dist/libs/contracts/src/types.d.ts +2 -0
  46. package/dist/libs/contracts/src/workflow/spec.d.ts +88 -0
  47. package/dist/libs/contracts/src/workflow/spec.d.ts.map +1 -0
  48. package/dist/overlay-customization.d.ts +5 -0
  49. package/dist/overlay-customization.d.ts.map +1 -0
  50. package/dist/overlay-customization.js +50 -0
  51. package/dist/overlay-customization.js.map +1 -0
  52. package/dist/workflow-extension.d.ts +8 -0
  53. package/dist/workflow-extension.d.ts.map +1 -0
  54. package/dist/workflow-extension.js +67 -0
  55. package/dist/workflow-extension.js.map +1 -0
  56. package/package.json +67 -0
  57. package/src/behavior-tracking.ts +47 -0
  58. package/src/docs/index.ts +1 -0
  59. package/src/docs/personalization.docblock.ts +28 -0
  60. package/src/example.ts +25 -0
  61. package/src/index.ts +5 -0
  62. package/src/overlay-customization.ts +57 -0
  63. package/src/workflow-extension.ts +63 -0
  64. package/tsconfig.json +17 -0
  65. package/tsdown.config.js +6 -0
@@ -0,0 +1,5 @@
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 };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { runBehaviorTrackingExample } from "./behavior-tracking.js";
2
+ import example_default from "./example.js";
3
+ import { runOverlayCustomizationExample } from "./overlay-customization.js";
4
+ import { composeTenantWorkflowExample, logTenantWorkflowSteps } from "./workflow-extension.js";
5
+ import "./docs/index.js";
6
+
7
+ export { composeTenantWorkflowExample, example_default as example, logTenantWorkflowSteps, runBehaviorTrackingExample, runOverlayCustomizationExample };
@@ -0,0 +1,9 @@
1
+ //#region ../../libs/contracts/src/capabilities/capabilities.d.ts
2
+
3
+ interface CapabilityRef {
4
+ key: string;
5
+ version: number;
6
+ }
7
+ //#endregion
8
+ export { CapabilityRef };
9
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","names":[],"sources":["../../../../../../../libs/contracts/src/capabilities/capabilities.ts"],"sourcesContent":[],"mappings":";;UAqCiB,aAAA"}
@@ -0,0 +1,8 @@
1
+ //#region ../../libs/contracts/src/docs/registry.d.ts
2
+
3
+ type DocId = string & {
4
+ __docId: true;
5
+ };
6
+ //#endregion
7
+ export { DocId };
8
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../../../../../libs/contracts/src/docs/registry.ts"],"sourcesContent":[],"mappings":";;KASY,KAAA"}
@@ -0,0 +1 @@
1
+ import "./registry.js";
@@ -0,0 +1,3 @@
1
+ import "../resources.js";
2
+ import "../types.js";
3
+ import "../operations/index.js";
@@ -0,0 +1,9 @@
1
+ //#region ../../libs/contracts/src/experiments/spec.d.ts
2
+
3
+ interface ExperimentRef {
4
+ key: string;
5
+ version?: number;
6
+ }
7
+ //#endregion
8
+ export { ExperimentRef };
9
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","names":[],"sources":["../../../../../../../libs/contracts/src/experiments/spec.ts"],"sourcesContent":[],"mappings":";;UAMiB,aAAA"}
@@ -0,0 +1,4 @@
1
+ import { OpRef } from "./types.js";
2
+ import "./registry.js";
3
+ import "./install.js";
4
+ import "./validation.js";
@@ -0,0 +1,4 @@
1
+ import "../operations/registry.js";
2
+ import "./types.js";
3
+ import "./registry.js";
4
+ import "../presentations/index.js";
@@ -0,0 +1 @@
1
+ import "./types.js";
@@ -0,0 +1,13 @@
1
+ import "../operations/index.js";
2
+
3
+ //#region ../../libs/contracts/src/features/types.d.ts
4
+
5
+ interface OpRef {
6
+ /** Operation key (OperationSpec.meta.key). */
7
+ key: string;
8
+ /** Operation version (OperationSpec.meta.version). */
9
+ version: number;
10
+ }
11
+ //#endregion
12
+ export { OpRef };
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../../../../../libs/contracts/src/features/types.ts"],"sourcesContent":[],"mappings":";;;;UASiB,KAAA"}
@@ -0,0 +1 @@
1
+ import "./types.js";
@@ -0,0 +1,6 @@
1
+ import "./resources.js";
2
+ import "./types.js";
3
+ import "./events.js";
4
+ import "./operations/registry.js";
5
+ import "./operations/index.js";
6
+ import "zod";
@@ -0,0 +1,2 @@
1
+ import "./operation.js";
2
+ import "./registry.js";
@@ -0,0 +1,2 @@
1
+ import "../resources.js";
2
+ import "../events.js";
@@ -0,0 +1,4 @@
1
+ import "../resources.js";
2
+ import "../types.js";
3
+ import "./operation.js";
4
+ import "../install.js";
@@ -0,0 +1,60 @@
1
+ import { DocId } from "./docs/registry.js";
2
+
3
+ //#region ../../libs/contracts/src/ownership.d.ts
4
+ declare const StabilityEnum: {
5
+ readonly Idea: "idea";
6
+ readonly InCreation: "in_creation";
7
+ readonly Experimental: "experimental";
8
+ readonly Beta: "beta";
9
+ readonly Stable: "stable";
10
+ readonly Deprecated: "deprecated";
11
+ };
12
+ type Stability = (typeof StabilityEnum)[keyof typeof StabilityEnum];
13
+ declare const OwnersEnum: {
14
+ readonly PlatformCore: "platform.core";
15
+ readonly PlatformSigil: "platform.sigil";
16
+ readonly PlatformMarketplace: "platform.marketplace";
17
+ readonly PlatformMessaging: "platform.messaging";
18
+ readonly PlatformContent: "platform.content";
19
+ readonly PlatformFeatureFlags: "platform.featureflags";
20
+ readonly PlatformFinance: "platform.finance";
21
+ };
22
+ type Owner = (typeof OwnersEnum)[keyof typeof OwnersEnum] | (string & {});
23
+ declare const TagsEnum: {
24
+ readonly Spots: "spots";
25
+ readonly Collectivity: "collectivity";
26
+ readonly Marketplace: "marketplace";
27
+ readonly Sellers: "sellers";
28
+ readonly Auth: "auth";
29
+ readonly Login: "login";
30
+ readonly Signup: "signup";
31
+ readonly Guide: "guide";
32
+ readonly Docs: "docs";
33
+ readonly I18n: "i18n";
34
+ readonly Incident: "incident";
35
+ readonly Automation: "automation";
36
+ readonly Hygiene: "hygiene";
37
+ };
38
+ type Tag = (typeof TagsEnum)[keyof typeof TagsEnum] | (string & {});
39
+ interface OwnerShipMeta {
40
+ /** Breaking changes => bump version */
41
+ version: number;
42
+ /** Fully-qualified spec key (e.g., "sigil.beginSignup") */
43
+ key: string;
44
+ /** Human-friendly spec title (e.g., "Signup begin") */
45
+ title?: string;
46
+ /** Short human-friendly summary */
47
+ description: string;
48
+ domain?: string;
49
+ /** Lifecycle marker for comms & tooling */
50
+ stability: Stability;
51
+ /** Owners for CODEOWNERS / on-call / approvals */
52
+ owners: Owner[];
53
+ /** Search tags, grouping, docs navigation */
54
+ tags: Tag[];
55
+ /** Doc block(s) for this operation. */
56
+ docId?: DocId[];
57
+ }
58
+ //#endregion
59
+ export { OwnerShipMeta };
60
+ //# sourceMappingURL=ownership.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ownership.d.ts","names":[],"sources":["../../../../../../libs/contracts/src/ownership.ts"],"sourcesContent":[],"mappings":";;;cAIa;;EAAA,SAAA,UAOH,EAAA,aAAA;EACE,SAAA,YAAS,EAAA,cAAW;EAGnB,SAAA,IAQH,EAAA,MAAA;EACE,SAAK,MAAA,EAAA,QACL;EAMC,SAAA,UAcH,EAAA,YAAA;AACV,CAAA;AAIiB,KAtCL,SAAA,GAsCkB,CAAA,OAtCE,aAsCF,CAAA,CAAA,MAAA,OAtC8B,aAsC9B,CAAA;AAWjB,cA9CA,UA8CA,EAAA;EAEH,SAAA,YAAA,EAAA,eAAA;EAEF,SAAA,aAAA,EAAA,gBAAA;EAGE,SAAA,mBAAA,EAAA,sBAAA;EAAK,SAAA,iBAAA,EAAA,oBAAA;;;;;KA5CH,KAAA,WACA,yBAAyB;cAMxB;;;;;;;;;;;;;;;KAeD,GAAA,WAAc,uBAAuB;UAIhC,aAAA;;;;;;;;;;;aAWJ;;UAEH;;QAEF;;UAGE"}
@@ -0,0 +1,2 @@
1
+ import "./transform-engine.js";
2
+ import "./registry.js";
@@ -0,0 +1 @@
1
+ import "../registry.js";
@@ -0,0 +1 @@
1
+ import "./types.js";
@@ -0,0 +1 @@
1
+ import "zod";
@@ -0,0 +1,2 @@
1
+ import "./experiments/spec-resolver.js";
2
+ import "./events.js";
@@ -0,0 +1,88 @@
1
+ import { OwnerShipMeta } from "../ownership.js";
2
+ import { CapabilityRef } from "../capabilities/capabilities.js";
3
+ import { ExperimentRef } from "../experiments/spec.js";
4
+ import { OpRef } from "../features/types.js";
5
+ import "../features/index.js";
6
+
7
+ //#region ../../libs/contracts/src/workflow/spec.d.ts
8
+ /**
9
+ * Reference to a form spec declared in {@link FormRegistry}.
10
+ */
11
+ interface FormRef {
12
+ key: string;
13
+ version: number;
14
+ }
15
+ type StepType = 'human' | 'automation' | 'decision';
16
+ type GuardConditionKind = 'policy' | 'expression';
17
+ interface GuardCondition {
18
+ type: GuardConditionKind;
19
+ /** Policy name or expression string depending on the type. */
20
+ value: string;
21
+ }
22
+ interface RetryPolicy {
23
+ maxAttempts: number;
24
+ backoff: 'linear' | 'exponential';
25
+ delayMs: number;
26
+ /** Optional max delay cap for exponential backoff. */
27
+ maxDelayMs?: number;
28
+ }
29
+ interface StepAction {
30
+ /** Operation executed for automation steps. */
31
+ operation?: OpRef;
32
+ /** Form rendered for human input steps. */
33
+ form?: FormRef;
34
+ }
35
+ interface Step {
36
+ id: string;
37
+ type: StepType;
38
+ label: string;
39
+ description?: string;
40
+ action?: StepAction;
41
+ guard?: GuardCondition;
42
+ timeoutMs?: number;
43
+ retry?: RetryPolicy;
44
+ /** Integration slot identifiers required before this step can execute. */
45
+ requiredIntegrations?: string[];
46
+ /** Capabilities that must be enabled for this step to execute. */
47
+ requiredCapabilities?: CapabilityRef[];
48
+ }
49
+ interface Transition {
50
+ from: string;
51
+ to: string;
52
+ label?: string;
53
+ /** Expression evaluated against workflow data (e.g., `data.approved === true`). */
54
+ condition?: string;
55
+ }
56
+ interface SLA {
57
+ totalDurationMs?: number;
58
+ stepDurationMs?: Record<string, number>;
59
+ }
60
+ interface CompensationStep {
61
+ stepId: string;
62
+ operation: OpRef;
63
+ description?: string;
64
+ }
65
+ interface CompensationStrategy {
66
+ trigger?: 'on_failure' | 'manual';
67
+ steps: CompensationStep[];
68
+ }
69
+ interface WorkflowDefinition {
70
+ steps: Step[];
71
+ transitions: Transition[];
72
+ /** Optional explicit entry step. Defaults to the first step when omitted. */
73
+ entryStepId?: string;
74
+ sla?: SLA;
75
+ compensation?: CompensationStrategy;
76
+ }
77
+ type WorkflowMeta = OwnerShipMeta;
78
+ interface WorkflowSpec {
79
+ meta: WorkflowMeta;
80
+ definition: WorkflowDefinition;
81
+ policy?: {
82
+ flags?: string[];
83
+ };
84
+ experiments?: ExperimentRef[];
85
+ }
86
+ //#endregion
87
+ export { WorkflowSpec };
88
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","names":[],"sources":["../../../../../../../libs/contracts/src/workflow/spec.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AASiB,UAAA,OAAA,CAAO;EAKZ,GAAA,EAAA,MAAQ;EASR,OAAA,EAAA,MAAA;AAEZ;AAMiB,KAjBL,QAAA,GAiBgB,OAAA,GAAA,YAAA,GAAA,UAAA;AAeX,KAvBL,kBAAA,GAuBS,QAAA,GAAA,YAAA;AAEb,UAvBS,cAAA,CAuBT;EAGG,IAAA,EAzBH,kBAyBG;EACD;EAEA,KAAA,EAAA,MAAA;;AAI4B,UA3BrB,WAAA,CA2BqB;EAGrB,WAAA,EAAU,MAAA;EAQV,OAAG,EAAA,QAAA,GAED,aAAM;EAGR,OAAA,EAAA,MAAA;EAMA;EAKA,UAAA,CAAA,EAAA,MAAA;;AAEF,UAhDE,UAAA,CAgDF;EAGP;EACS,SAAA,CAAA,EAlDH,KAkDG;EAAoB;EAGzB,IAAA,CAAA,EAnDH,OAmDG;AAEZ;AACQ,UAnDS,IAAA,CAmDT;EACM,EAAA,EAAA,MAAA;EAEE,IAAA,EApDR,QAoDQ;EAAa,KAAA,EAAA,MAAA;;WAjDlB;UACD;;UAEA;;;;yBAIe;;UAGR,UAAA;;;;;;;UAQA,GAAA;;mBAEE;;UAGF,gBAAA;;aAEJ;;;UAII,oBAAA;;SAER;;UAGQ,kBAAA;SACR;eACM;;;QAGP;iBACS;;KAGL,YAAA,GAAe;UAEV,YAAA;QACT;cACM;;;;gBAEE"}
@@ -0,0 +1,5 @@
1
+ //#region src/overlay-customization.d.ts
2
+ declare function runOverlayCustomizationExample(): Promise<void>;
3
+ //#endregion
4
+ export { runOverlayCustomizationExample };
5
+ //# sourceMappingURL=overlay-customization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-customization.d.ts","names":[],"sources":["../src/overlay-customization.ts"],"sourcesContent":[],"mappings":";iBAgBsB,8BAAA,CAAA,GAAkC"}
@@ -0,0 +1,50 @@
1
+ import { LogLevel, Logger } from "@contractspec/lib.logger";
2
+ import { defineOverlay } from "@contractspec/lib.overlay-engine/spec";
3
+ import { signOverlay } from "@contractspec/lib.overlay-engine/signer";
4
+ import { OverlayEngine, OverlayRegistry } from "@contractspec/lib.overlay-engine";
5
+
6
+ //#region src/overlay-customization.ts
7
+ const logger = new Logger({
8
+ level: process.env.NODE_ENV === "production" ? LogLevel.INFO : LogLevel.DEBUG,
9
+ environment: process.env.NODE_ENV || "development",
10
+ enableColors: process.env.NODE_ENV !== "production"
11
+ });
12
+ async function runOverlayCustomizationExample() {
13
+ const registry = new OverlayRegistry({ allowUnsigned: true });
14
+ const engine = new OverlayEngine({ registry });
15
+ const signed = await signOverlay(defineOverlay({
16
+ overlayId: "demo-overlay",
17
+ version: "1.0.0",
18
+ appliesTo: {
19
+ capability: "billing.createOrder",
20
+ tenantId: "demo"
21
+ },
22
+ modifications: [{
23
+ type: "hideField",
24
+ field: "internalNotes"
25
+ }, {
26
+ type: "renameLabel",
27
+ field: "customerReference",
28
+ newLabel: "PO Number"
29
+ }]
30
+ }), process.env.PRIVATE_KEY_PEM ?? "");
31
+ registry.register(signed);
32
+ const result = engine.apply({
33
+ target: { fields: [{
34
+ key: "customerReference",
35
+ label: "Customer Reference",
36
+ visible: true
37
+ }, {
38
+ key: "internalNotes",
39
+ label: "Internal Notes",
40
+ visible: true
41
+ }] },
42
+ capability: "billing.createOrder",
43
+ tenantId: "demo"
44
+ });
45
+ logger.info("Overlay applied", { fields: result.target.fields });
46
+ }
47
+
48
+ //#endregion
49
+ export { runOverlayCustomizationExample };
50
+ //# sourceMappingURL=overlay-customization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-customization.js","names":[],"sources":["../src/overlay-customization.ts"],"sourcesContent":["import { defineOverlay } from '@contractspec/lib.overlay-engine/spec';\nimport { signOverlay } from '@contractspec/lib.overlay-engine/signer';\nimport {\n OverlayEngine,\n OverlayRegistry,\n} from '@contractspec/lib.overlay-engine';\nimport { Logger, LogLevel } from '@contractspec/lib.logger';\n\nconst logger = new Logger({\n level: process.env.NODE_ENV === 'production' ? LogLevel.INFO : LogLevel.DEBUG,\n environment:\n (process.env.NODE_ENV as 'production' | 'development' | 'test') ||\n 'development',\n enableColors: process.env.NODE_ENV !== 'production',\n});\n\nexport async function runOverlayCustomizationExample(): Promise<void> {\n const registry = new OverlayRegistry({ allowUnsigned: true });\n const engine = new OverlayEngine({ registry });\n\n const overlay = defineOverlay({\n overlayId: 'demo-overlay',\n version: '1.0.0',\n appliesTo: {\n capability: 'billing.createOrder',\n tenantId: 'demo',\n },\n modifications: [\n { type: 'hideField', field: 'internalNotes' },\n {\n type: 'renameLabel',\n field: 'customerReference',\n newLabel: 'PO Number',\n },\n ],\n });\n\n const signed = await signOverlay(overlay, process.env.PRIVATE_KEY_PEM ?? '');\n registry.register(signed);\n\n const result = engine.apply({\n target: {\n fields: [\n {\n key: 'customerReference',\n label: 'Customer Reference',\n visible: true,\n },\n { key: 'internalNotes', label: 'Internal Notes', visible: true },\n ],\n },\n capability: 'billing.createOrder',\n tenantId: 'demo',\n });\n\n logger.info('Overlay applied', { fields: result.target.fields });\n}\n"],"mappings":";;;;;;AAQA,MAAM,SAAS,IAAI,OAAO;CACxB,OAAO,QAAQ,IAAI,aAAa,eAAe,SAAS,OAAO,SAAS;CACxE,aACG,QAAQ,IAAI,YACb;CACF,cAAc,QAAQ,IAAI,aAAa;CACxC,CAAC;AAEF,eAAsB,iCAAgD;CACpE,MAAM,WAAW,IAAI,gBAAgB,EAAE,eAAe,MAAM,CAAC;CAC7D,MAAM,SAAS,IAAI,cAAc,EAAE,UAAU,CAAC;CAmB9C,MAAM,SAAS,MAAM,YAjBL,cAAc;EAC5B,WAAW;EACX,SAAS;EACT,WAAW;GACT,YAAY;GACZ,UAAU;GACX;EACD,eAAe,CACb;GAAE,MAAM;GAAa,OAAO;GAAiB,EAC7C;GACE,MAAM;GACN,OAAO;GACP,UAAU;GACX,CACF;EACF,CAAC,EAEwC,QAAQ,IAAI,mBAAmB,GAAG;AAC5E,UAAS,SAAS,OAAO;CAEzB,MAAM,SAAS,OAAO,MAAM;EAC1B,QAAQ,EACN,QAAQ,CACN;GACE,KAAK;GACL,OAAO;GACP,SAAS;GACV,EACD;GAAE,KAAK;GAAiB,OAAO;GAAkB,SAAS;GAAM,CACjE,EACF;EACD,YAAY;EACZ,UAAU;EACX,CAAC;AAEF,QAAO,KAAK,mBAAmB,EAAE,QAAQ,OAAO,OAAO,QAAQ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { WorkflowSpec } from "./libs/contracts/src/workflow/spec.js";
2
+
3
+ //#region src/workflow-extension.d.ts
4
+ declare function composeTenantWorkflowExample(): WorkflowSpec;
5
+ declare function logTenantWorkflowSteps(workflow: WorkflowSpec): void;
6
+ //#endregion
7
+ export { composeTenantWorkflowExample, logTenantWorkflowSteps };
8
+ //# sourceMappingURL=workflow-extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-extension.d.ts","names":[],"sources":["../src/workflow-extension.ts"],"sourcesContent":[],"mappings":";;;iBAiCgB,4BAAA,CAAA,GAAgC;iBAwBhC,sBAAA,WAAiC"}
@@ -0,0 +1,67 @@
1
+ import { LogLevel, Logger } from "@contractspec/lib.logger";
2
+ import { StabilityEnum } from "@contractspec/lib.contracts";
3
+ import { WorkflowComposer } from "@contractspec/lib.workflow-composer";
4
+
5
+ //#region src/workflow-extension.ts
6
+ const logger = new Logger({
7
+ level: process.env.NODE_ENV === "production" ? LogLevel.INFO : LogLevel.DEBUG,
8
+ environment: process.env.NODE_ENV || "development",
9
+ enableColors: process.env.NODE_ENV !== "production"
10
+ });
11
+ const BaseWorkflow = {
12
+ meta: {
13
+ key: "billing.invoiceApproval",
14
+ version: 1,
15
+ title: "Invoice Approval",
16
+ owners: [],
17
+ tags: [],
18
+ description: "",
19
+ domain: "billing",
20
+ stability: StabilityEnum.Stable
21
+ },
22
+ definition: {
23
+ steps: [{
24
+ id: "validate-invoice",
25
+ type: "automation",
26
+ label: "Validate Invoice"
27
+ }, {
28
+ id: "final-approval",
29
+ type: "human",
30
+ label: "Final Approval"
31
+ }],
32
+ transitions: [{
33
+ from: "validate-invoice",
34
+ to: "final-approval"
35
+ }]
36
+ }
37
+ };
38
+ function composeTenantWorkflowExample() {
39
+ const composer = new WorkflowComposer();
40
+ composer.register({
41
+ workflow: "billing.invoiceApproval",
42
+ tenantId: "acme",
43
+ customSteps: [{
44
+ after: "validate-invoice",
45
+ inject: {
46
+ id: "acme-legal",
47
+ type: "human",
48
+ label: "ACME Legal Review"
49
+ },
50
+ transitionTo: "final-approval"
51
+ }]
52
+ });
53
+ return composer.compose({
54
+ base: BaseWorkflow,
55
+ tenantId: "acme"
56
+ });
57
+ }
58
+ function logTenantWorkflowSteps(workflow) {
59
+ logger.info("Tenant workflow composed", {
60
+ workflow: workflow.meta.key,
61
+ steps: workflow.definition.steps.map((step) => step.id)
62
+ });
63
+ }
64
+
65
+ //#endregion
66
+ export { composeTenantWorkflowExample, logTenantWorkflowSteps };
67
+ //# sourceMappingURL=workflow-extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-extension.js","names":["BaseWorkflow: WorkflowSpec"],"sources":["../src/workflow-extension.ts"],"sourcesContent":["import { StabilityEnum } from '@contractspec/lib.contracts';\nimport type { WorkflowSpec } from '@contractspec/lib.contracts/workflow/spec';\nimport { WorkflowComposer } from '@contractspec/lib.workflow-composer';\nimport { Logger, LogLevel } from '@contractspec/lib.logger';\n\nconst logger = new Logger({\n level: process.env.NODE_ENV === 'production' ? LogLevel.INFO : LogLevel.DEBUG,\n environment:\n (process.env.NODE_ENV as 'production' | 'development' | 'test') ||\n 'development',\n enableColors: process.env.NODE_ENV !== 'production',\n});\n\nconst BaseWorkflow: WorkflowSpec = {\n meta: {\n key: 'billing.invoiceApproval',\n version: 1,\n title: 'Invoice Approval',\n owners: [],\n tags: [],\n description: '',\n domain: 'billing',\n stability: StabilityEnum.Stable,\n },\n definition: {\n steps: [\n { id: 'validate-invoice', type: 'automation', label: 'Validate Invoice' },\n { id: 'final-approval', type: 'human', label: 'Final Approval' },\n ],\n transitions: [{ from: 'validate-invoice', to: 'final-approval' }],\n },\n};\n\nexport function composeTenantWorkflowExample(): WorkflowSpec {\n const composer = new WorkflowComposer();\n composer.register({\n workflow: 'billing.invoiceApproval',\n tenantId: 'acme',\n customSteps: [\n {\n after: 'validate-invoice',\n inject: {\n id: 'acme-legal',\n type: 'human',\n label: 'ACME Legal Review',\n },\n transitionTo: 'final-approval',\n },\n ],\n });\n\n return composer.compose({\n base: BaseWorkflow,\n tenantId: 'acme',\n });\n}\n\nexport function logTenantWorkflowSteps(workflow: WorkflowSpec): void {\n logger.info('Tenant workflow composed', {\n workflow: workflow.meta.key,\n steps: workflow.definition.steps.map((step) => step.id),\n });\n}\n"],"mappings":";;;;;AAKA,MAAM,SAAS,IAAI,OAAO;CACxB,OAAO,QAAQ,IAAI,aAAa,eAAe,SAAS,OAAO,SAAS;CACxE,aACG,QAAQ,IAAI,YACb;CACF,cAAc,QAAQ,IAAI,aAAa;CACxC,CAAC;AAEF,MAAMA,eAA6B;CACjC,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,QAAQ,EAAE;EACV,MAAM,EAAE;EACR,aAAa;EACb,QAAQ;EACR,WAAW,cAAc;EAC1B;CACD,YAAY;EACV,OAAO,CACL;GAAE,IAAI;GAAoB,MAAM;GAAc,OAAO;GAAoB,EACzE;GAAE,IAAI;GAAkB,MAAM;GAAS,OAAO;GAAkB,CACjE;EACD,aAAa,CAAC;GAAE,MAAM;GAAoB,IAAI;GAAkB,CAAC;EAClE;CACF;AAED,SAAgB,+BAA6C;CAC3D,MAAM,WAAW,IAAI,kBAAkB;AACvC,UAAS,SAAS;EAChB,UAAU;EACV,UAAU;EACV,aAAa,CACX;GACE,OAAO;GACP,QAAQ;IACN,IAAI;IACJ,MAAM;IACN,OAAO;IACR;GACD,cAAc;GACf,CACF;EACF,CAAC;AAEF,QAAO,SAAS,QAAQ;EACtB,MAAM;EACN,UAAU;EACX,CAAC;;AAGJ,SAAgB,uBAAuB,UAA8B;AACnE,QAAO,KAAK,4BAA4B;EACtC,UAAU,SAAS,KAAK;EACxB,OAAO,SAAS,WAAW,MAAM,KAAK,SAAS,KAAK,GAAG;EACxD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@contractspec/example.personalization",
3
+ "version": "1.44.0",
4
+ "description": "Personalization examples: behavior tracking, overlay customization, workflow extension.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./behavior-tracking": "./dist/behavior-tracking.js",
11
+ "./docs": "./dist/docs/index.js",
12
+ "./docs/personalization.docblock": "./dist/docs/personalization.docblock.js",
13
+ "./example": "./dist/example.js",
14
+ "./overlay-customization": "./dist/overlay-customization.js",
15
+ "./workflow-extension": "./dist/workflow-extension.js",
16
+ "./*": "./*"
17
+ },
18
+ "scripts": {
19
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
20
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
21
+ "build": "bun build:types && bun build:bundle",
22
+ "build:bundle": "tsdown",
23
+ "build:types": "tsc --noEmit",
24
+ "dev": "bun build:bundle --watch",
25
+ "clean": "rimraf dist .turbo",
26
+ "lint": "bun lint:fix",
27
+ "lint:fix": "eslint src --fix",
28
+ "lint:check": "eslint src",
29
+ "test": "bun test"
30
+ },
31
+ "dependencies": {
32
+ "@contractspec/lib.personalization": "1.44.0",
33
+ "@contractspec/lib.overlay-engine": "1.44.0",
34
+ "@contractspec/lib.workflow-composer": "1.44.0",
35
+ "@contractspec/lib.schema": "1.44.0",
36
+ "@contractspec/lib.contracts": "1.44.0",
37
+ "@contractspec/lib.logger": "1.44.0"
38
+ },
39
+ "devDependencies": {
40
+ "@contractspec/tool.tsdown": "1.44.0",
41
+ "@contractspec/tool.typescript": "1.44.0",
42
+ "tsdown": "^0.18.3",
43
+ "typescript": "^5.9.3"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "exports": {
48
+ ".": "./dist/index.js",
49
+ "./behavior-tracking": "./dist/behavior-tracking.js",
50
+ "./docs": "./dist/docs/index.js",
51
+ "./docs/personalization.docblock": "./dist/docs/personalization.docblock.js",
52
+ "./example": "./dist/example.js",
53
+ "./overlay-customization": "./dist/overlay-customization.js",
54
+ "./workflow-extension": "./dist/workflow-extension.js",
55
+ "./*": "./*"
56
+ },
57
+ "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "module": "./dist/index.js",
60
+ "license": "MIT",
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "https://github.com/lssm-tech/contractspec.git",
64
+ "directory": "packages/examples/personalization"
65
+ },
66
+ "homepage": "https://contractspec.io"
67
+ }
@@ -0,0 +1,47 @@
1
+ import { createBehaviorTracker } from '@contractspec/lib.personalization/tracker';
2
+ import { InMemoryBehaviorStore } from '@contractspec/lib.personalization/store';
3
+ import { BehaviorAnalyzer } from '@contractspec/lib.personalization/analyzer';
4
+ import { Logger, LogLevel } from '@contractspec/lib.logger';
5
+
6
+ const logger = new Logger({
7
+ level: process.env.NODE_ENV === 'production' ? LogLevel.INFO : LogLevel.DEBUG,
8
+ environment:
9
+ (process.env.NODE_ENV as 'production' | 'development' | 'test') ||
10
+ 'development',
11
+ enableColors: process.env.NODE_ENV !== 'production',
12
+ });
13
+
14
+ export async function runBehaviorTrackingExample(): Promise<void> {
15
+ const store = new InMemoryBehaviorStore();
16
+ const tracker = createBehaviorTracker({
17
+ store,
18
+ context: {
19
+ tenantId: 'acme',
20
+ userId: 'user-123',
21
+ },
22
+ });
23
+
24
+ tracker.trackFieldAccess({
25
+ operation: 'billing.createOrder',
26
+ field: 'internalNotes',
27
+ });
28
+ tracker.trackFieldAccess({
29
+ operation: 'billing.createOrder',
30
+ field: 'customerReference',
31
+ });
32
+ tracker.trackFeatureUsage({ feature: 'workflow-editor', action: 'opened' });
33
+ tracker.trackWorkflowStep({
34
+ workflow: 'invoice-approval',
35
+ step: 'review',
36
+ status: 'entered',
37
+ });
38
+ await tracker.flush();
39
+
40
+ const analyzer = new BehaviorAnalyzer(store);
41
+ const insights = await analyzer.analyze({
42
+ tenantId: 'acme',
43
+ userId: 'user-123',
44
+ });
45
+
46
+ logger.info('Behavior insights computed', { insights });
47
+ }
@@ -0,0 +1 @@
1
+ import './personalization.docblock';
@@ -0,0 +1,28 @@
1
+ import type { DocBlock } from '@contractspec/lib.contracts/docs';
2
+ import { registerDocBlocks } from '@contractspec/lib.contracts/docs';
3
+
4
+ const blocks: DocBlock[] = [
5
+ {
6
+ id: 'docs.examples.personalization',
7
+ title: 'Personalization Patterns (example)',
8
+ summary:
9
+ 'Behavior tracking, overlay-driven UI tweaks, and tenant workflow extension patterns.',
10
+ kind: 'reference',
11
+ visibility: 'public',
12
+ route: '/docs/examples/personalization',
13
+ tags: ['personalization', 'overlays', 'workflows', 'example'],
14
+ 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.`,
15
+ },
16
+ {
17
+ id: 'docs.examples.personalization.usage',
18
+ title: 'Personalization — Usage',
19
+ summary: 'How to run the small examples and swap adapters.',
20
+ kind: 'usage',
21
+ visibility: 'public',
22
+ route: '/docs/examples/personalization/usage',
23
+ tags: ['personalization', 'usage'],
24
+ 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.`,
25
+ },
26
+ ];
27
+
28
+ registerDocBlocks(blocks);
package/src/example.ts ADDED
@@ -0,0 +1,25 @@
1
+ const example = {
2
+ id: 'personalization',
3
+ title: 'Personalization Patterns',
4
+ summary:
5
+ 'Small examples for behavior tracking, overlay-based UI customization, and tenant workflow extension.',
6
+ tags: ['personalization', 'overlays', 'behavior', 'workflows'],
7
+ kind: 'library',
8
+ visibility: 'public',
9
+ docs: {
10
+ rootDocId: 'docs.examples.personalization',
11
+ usageDocId: 'docs.examples.personalization.usage',
12
+ },
13
+ entrypoints: {
14
+ packageName: '@contractspec/example.personalization',
15
+ docs: './docs',
16
+ },
17
+ surfaces: {
18
+ templates: true,
19
+ sandbox: { enabled: true, modes: ['markdown', 'specs'] },
20
+ studio: { enabled: true, installable: true },
21
+ mcp: { enabled: true },
22
+ },
23
+ } as const;
24
+
25
+ export default example;
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
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';