@contractspec/lib.personalization 6.0.17 → 6.0.18

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/tracker.js CHANGED
@@ -1,95 +1,2 @@
1
1
  // @bun
2
- // src/tracker.ts
3
- import { metrics, trace } from "@opentelemetry/api";
4
- var DEFAULT_BUFFER_SIZE = 25;
5
-
6
- class BehaviorTracker {
7
- store;
8
- context;
9
- tracer = trace.getTracer("lssm.personalization", "1.0.0");
10
- counter = metrics.getMeter("lssm.personalization", "1.0.0").createCounter("lssm.personalization.events", {
11
- description: "Behavior events tracked for personalization"
12
- });
13
- buffer = [];
14
- bufferSize;
15
- flushTimer;
16
- constructor(options) {
17
- this.store = options.store;
18
- this.context = options.context;
19
- this.bufferSize = options.bufferSize ?? DEFAULT_BUFFER_SIZE;
20
- if (options.autoFlushIntervalMs) {
21
- this.flushTimer = setInterval(() => {
22
- this.flush();
23
- }, options.autoFlushIntervalMs);
24
- }
25
- }
26
- trackFieldAccess(input) {
27
- const event = {
28
- type: "field_access",
29
- operation: input.operation,
30
- field: input.field,
31
- timestamp: Date.now(),
32
- ...this.context,
33
- metadata: { ...this.context.metadata, ...input.metadata }
34
- };
35
- this.enqueue(event);
36
- }
37
- trackFeatureUsage(input) {
38
- const event = {
39
- type: "feature_usage",
40
- feature: input.feature,
41
- action: input.action,
42
- timestamp: Date.now(),
43
- ...this.context,
44
- metadata: { ...this.context.metadata, ...input.metadata }
45
- };
46
- this.enqueue(event);
47
- }
48
- trackWorkflowStep(input) {
49
- const event = {
50
- type: "workflow_step",
51
- workflow: input.workflow,
52
- step: input.step,
53
- status: input.status,
54
- timestamp: Date.now(),
55
- ...this.context,
56
- metadata: { ...this.context.metadata, ...input.metadata }
57
- };
58
- this.enqueue(event);
59
- }
60
- async flush() {
61
- if (!this.buffer.length)
62
- return;
63
- const events = this.buffer;
64
- this.buffer = [];
65
- await this.store.bulkRecord(events);
66
- }
67
- async dispose() {
68
- if (this.flushTimer) {
69
- clearInterval(this.flushTimer);
70
- }
71
- await this.flush();
72
- }
73
- enqueue(event) {
74
- this.buffer.push(event);
75
- this.counter.add(1, {
76
- tenantId: this.context.tenantId,
77
- type: event.type
78
- });
79
- this.tracer.startActiveSpan(`personalization.${event.type}`, (span) => {
80
- span.setAttribute("tenant.id", this.context.tenantId);
81
- if (this.context.userId)
82
- 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) {
87
- this.flush();
88
- }
89
- }
90
- }
91
- var createBehaviorTracker = (options) => new BehaviorTracker(options);
92
- export {
93
- createBehaviorTracker,
94
- BehaviorTracker
95
- };
2
+ import{metrics as a,trace as s}from"@opentelemetry/api";var i=25;class r{store;context;tracer=s.getTracer("lssm.personalization","1.0.0");counter=a.getMeter("lssm.personalization","1.0.0").createCounter("lssm.personalization.events",{description:"Behavior events tracked for personalization"});buffer=[];bufferSize;flushTimer;constructor(e){if(this.store=e.store,this.context=e.context,this.bufferSize=e.bufferSize??i,e.autoFlushIntervalMs)this.flushTimer=setInterval(()=>{this.flush()},e.autoFlushIntervalMs)}trackFieldAccess(e){let t={type:"field_access",operation:e.operation,field:e.field,timestamp:Date.now(),...this.context,metadata:{...this.context.metadata,...e.metadata}};this.enqueue(t)}trackFeatureUsage(e){let t={type:"feature_usage",feature:e.feature,action:e.action,timestamp:Date.now(),...this.context,metadata:{...this.context.metadata,...e.metadata}};this.enqueue(t)}trackWorkflowStep(e){let t={type:"workflow_step",workflow:e.workflow,step:e.step,status:e.status,timestamp:Date.now(),...this.context,metadata:{...this.context.metadata,...e.metadata}};this.enqueue(t)}async flush(){if(!this.buffer.length)return;let e=this.buffer;this.buffer=[],await this.store.bulkRecord(e)}async dispose(){if(this.flushTimer)clearInterval(this.flushTimer);await this.flush()}enqueue(e){if(this.buffer.push(e),this.counter.add(1,{tenantId:this.context.tenantId,type:e.type}),this.tracer.startActiveSpan(`personalization.${e.type}`,(t)=>{if(t.setAttribute("tenant.id",this.context.tenantId),this.context.userId)t.setAttribute("user.id",this.context.userId);t.setAttribute("personalization.event_type",e.type),t.end()}),this.buffer.length>=this.bufferSize)this.flush()}}var n=(e)=>new r(e);export{n as createBehaviorTracker,r as BehaviorTracker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/lib.personalization",
3
- "version": "6.0.17",
3
+ "version": "6.0.18",
4
4
  "description": "Behavior tracking, analysis, and adaptation helpers for ContractSpec personalization.",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -25,23 +25,23 @@
25
25
  "dev": "contractspec-bun-build dev",
26
26
  "clean": "rimraf dist .turbo",
27
27
  "lint": "bun lint:fix",
28
- "lint:fix": "biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .",
29
- "lint:check": "biome check .",
28
+ "lint:fix": "node ../../../scripts/biome.cjs check --write --unsafe --only=nursery/useSortedClasses . && node ../../../scripts/biome.cjs check --write .",
29
+ "lint:check": "node ../../../scripts/biome.cjs check .",
30
30
  "test": "bun test --pass-with-no-tests",
31
31
  "prebuild": "contractspec-bun-build prebuild",
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@contractspec/lib.bus": "3.7.17",
35
+ "@contractspec/lib.bus": "3.7.18",
36
36
  "@contractspec/lib.schema": "3.7.14",
37
- "@contractspec/lib.contracts-spec": "5.1.0",
38
- "@contractspec/lib.knowledge": "3.7.17",
39
- "@contractspec/lib.overlay-engine": "3.7.17",
37
+ "@contractspec/lib.contracts-spec": "5.2.0",
38
+ "@contractspec/lib.knowledge": "3.7.18",
39
+ "@contractspec/lib.overlay-engine": "3.7.18",
40
40
  "@opentelemetry/api": "^1.9.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@opentelemetry/api": "^1.9.1",
44
- "@contractspec/lib.surface-runtime": "0.5.17"
44
+ "@contractspec/lib.surface-runtime": "0.5.18"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
47
  "@contractspec/lib.surface-runtime": {
@@ -51,7 +51,7 @@
51
51
  "devDependencies": {
52
52
  "@contractspec/tool.typescript": "3.7.13",
53
53
  "typescript": "^5.9.3",
54
- "@contractspec/tool.bun": "3.7.13"
54
+ "@contractspec/tool.bun": "3.7.14"
55
55
  },
56
56
  "exports": {
57
57
  ".": {