@syntrologie/runtime-sdk 0.2.20 → 0.2.21
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/CAPABILITIES.md +211 -0
- package/dist/api.js +7 -6
- package/dist/api.js.map +1 -1
- package/dist/bootstrap.d.ts +16 -2
- package/dist/bootstrap.js +63 -14
- package/dist/bootstrap.js.map +1 -1
- package/dist/context/ContextManager.d.ts +66 -0
- package/dist/context/ContextManager.js +268 -0
- package/dist/context/ContextManager.js.map +1 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.js +7 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/schema.d.ts +360 -0
- package/dist/context/schema.js +50 -0
- package/dist/context/schema.js.map +1 -0
- package/dist/context/types.d.ts +101 -0
- package/dist/context/types.js +8 -0
- package/dist/context/types.js.map +1 -0
- package/dist/decisions/engine.d.ts +43 -0
- package/dist/decisions/engine.js +112 -0
- package/dist/decisions/engine.js.map +1 -0
- package/dist/decisions/index.d.ts +9 -0
- package/dist/decisions/index.js +10 -0
- package/dist/decisions/index.js.map +1 -0
- package/dist/decisions/schema.d.ts +2166 -0
- package/dist/decisions/schema.js +143 -0
- package/dist/decisions/schema.js.map +1 -0
- package/dist/decisions/strategies/rules.d.ts +24 -0
- package/dist/decisions/strategies/rules.js +152 -0
- package/dist/decisions/strategies/rules.js.map +1 -0
- package/dist/decisions/strategies/score.d.ts +10 -0
- package/dist/decisions/strategies/score.js +29 -0
- package/dist/decisions/strategies/score.js.map +1 -0
- package/dist/decisions/types.d.ts +242 -0
- package/dist/decisions/types.js +2 -0
- package/dist/decisions/types.js.map +1 -0
- package/dist/editorLoader.d.ts +10 -0
- package/dist/editorLoader.js +38 -0
- package/dist/editorLoader.js.map +1 -1
- package/dist/events/EventBus.d.ts +59 -0
- package/dist/events/EventBus.js +154 -0
- package/dist/events/EventBus.js.map +1 -0
- package/dist/events/index.d.ts +9 -0
- package/dist/events/index.js +10 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/normalizers/canvas.d.ts +67 -0
- package/dist/events/normalizers/canvas.js +116 -0
- package/dist/events/normalizers/canvas.js.map +1 -0
- package/dist/events/normalizers/posthog.d.ts +29 -0
- package/dist/events/normalizers/posthog.js +155 -0
- package/dist/events/normalizers/posthog.js.map +1 -0
- package/dist/events/schema.d.ts +70 -0
- package/dist/events/schema.js +30 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/types.d.ts +73 -0
- package/dist/events/types.js +41 -0
- package/dist/events/types.js.map +1 -0
- package/dist/hooks/useShadowCanvasConfig.d.ts +5 -1
- package/dist/hooks/useShadowCanvasConfig.js +17 -3
- package/dist/hooks/useShadowCanvasConfig.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/overlays/schema.d.ts +48 -48
- package/dist/runtime.d.ts +86 -0
- package/dist/runtime.js +132 -0
- package/dist/runtime.js.map +1 -0
- package/dist/smart-canvas.esm.js +11 -11
- package/dist/smart-canvas.esm.js.map +4 -4
- package/dist/smart-canvas.js +1504 -17
- package/dist/smart-canvas.js.map +4 -4
- package/dist/smart-canvas.min.js +11 -11
- package/dist/smart-canvas.min.js.map +4 -4
- package/dist/state/StateStore.d.ts +41 -0
- package/dist/state/StateStore.js +170 -0
- package/dist/state/StateStore.js.map +1 -0
- package/dist/state/helpers/cooldowns.d.ts +7 -0
- package/dist/state/helpers/cooldowns.js +31 -0
- package/dist/state/helpers/cooldowns.js.map +1 -0
- package/dist/state/helpers/dismissals.d.ts +7 -0
- package/dist/state/helpers/dismissals.js +34 -0
- package/dist/state/helpers/dismissals.js.map +1 -0
- package/dist/state/helpers/frequency.d.ts +8 -0
- package/dist/state/helpers/frequency.js +43 -0
- package/dist/state/helpers/frequency.js.map +1 -0
- package/dist/state/index.d.ts +7 -0
- package/dist/state/index.js +7 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/schema.d.ts +49 -0
- package/dist/state/schema.js +25 -0
- package/dist/state/schema.js.map +1 -0
- package/dist/state/types.d.ts +137 -0
- package/dist/state/types.js +9 -0
- package/dist/state/types.js.map +1 -0
- package/dist/telemetry/adapters/posthog.d.ts +1 -1
- package/dist/telemetry/adapters/posthog.js +1 -1
- package/dist/telemetry/adapters/posthog.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
- package/schema/canvas-config.schema.json +205 -0
- package/schema/runtime-context.schema.json +131 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateStore - Unified state management for the runtime.
|
|
3
|
+
*
|
|
4
|
+
* Provides scoped storage (session and user) with built-in helpers
|
|
5
|
+
* for common patterns like dismissals, cooldowns, and frequency caps.
|
|
6
|
+
*/
|
|
7
|
+
import type { ScopedStorage, DismissalStore, CooldownStore, FrequencyStore } from "./types";
|
|
8
|
+
export interface StateStoreOptions {
|
|
9
|
+
/** Namespace prefix for storage keys */
|
|
10
|
+
namespace?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* StateStore class for unified state management.
|
|
14
|
+
*/
|
|
15
|
+
export declare class StateStore {
|
|
16
|
+
/** Session-scoped storage (cleared on browser close) */
|
|
17
|
+
readonly session: ScopedStorage;
|
|
18
|
+
/** User-scoped storage (persists across sessions) */
|
|
19
|
+
readonly user: ScopedStorage;
|
|
20
|
+
/** Dismissal tracking */
|
|
21
|
+
readonly dismissals: DismissalStore;
|
|
22
|
+
/** Cooldown tracking */
|
|
23
|
+
readonly cooldowns: CooldownStore;
|
|
24
|
+
/** Frequency tracking */
|
|
25
|
+
readonly frequency: FrequencyStore;
|
|
26
|
+
private readonly namespace;
|
|
27
|
+
private readonly namespacedStorages;
|
|
28
|
+
constructor(options?: StateStoreOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Create a namespaced storage scope.
|
|
31
|
+
* Useful for isolating state by adaptive/tile.
|
|
32
|
+
*
|
|
33
|
+
* @param namespace - Additional namespace segment
|
|
34
|
+
* @returns A ScopedStorage with the nested namespace
|
|
35
|
+
*/
|
|
36
|
+
ns(namespace: string): ScopedStorage;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a StateStore instance.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createStateStore(options?: StateStoreOptions): StateStore;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { createDismissalStore } from "./helpers/dismissals";
|
|
2
|
+
import { createCooldownStore } from "./helpers/cooldowns";
|
|
3
|
+
import { createFrequencyStore } from "./helpers/frequency";
|
|
4
|
+
const DEFAULT_NAMESPACE = "syntro";
|
|
5
|
+
/**
|
|
6
|
+
* Create a ScopedStorage backed by browser storage.
|
|
7
|
+
*/
|
|
8
|
+
function createBrowserStorage(storage, namespace) {
|
|
9
|
+
const prefix = `${namespace}:`;
|
|
10
|
+
return {
|
|
11
|
+
get(key) {
|
|
12
|
+
if (!storage)
|
|
13
|
+
return undefined;
|
|
14
|
+
try {
|
|
15
|
+
const raw = storage.getItem(prefix + key);
|
|
16
|
+
if (!raw)
|
|
17
|
+
return undefined;
|
|
18
|
+
const stored = JSON.parse(raw);
|
|
19
|
+
// Check TTL
|
|
20
|
+
if (stored.expiresAt && Date.now() >= stored.expiresAt) {
|
|
21
|
+
storage.removeItem(prefix + key);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return stored.value;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
set(key, value, ttlMs) {
|
|
31
|
+
if (!storage)
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
const stored = {
|
|
35
|
+
value,
|
|
36
|
+
expiresAt: ttlMs ? Date.now() + ttlMs : undefined,
|
|
37
|
+
};
|
|
38
|
+
storage.setItem(prefix + key, JSON.stringify(stored));
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.warn("[StateStore] Failed to save:", err);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
remove(key) {
|
|
45
|
+
if (!storage)
|
|
46
|
+
return;
|
|
47
|
+
storage.removeItem(prefix + key);
|
|
48
|
+
},
|
|
49
|
+
has(key) {
|
|
50
|
+
if (!storage)
|
|
51
|
+
return false;
|
|
52
|
+
return this.get(key) !== undefined;
|
|
53
|
+
},
|
|
54
|
+
keys() {
|
|
55
|
+
if (!storage)
|
|
56
|
+
return [];
|
|
57
|
+
const keys = [];
|
|
58
|
+
for (let i = 0; i < storage.length; i++) {
|
|
59
|
+
const key = storage.key(i);
|
|
60
|
+
if (key === null || key === void 0 ? void 0 : key.startsWith(prefix)) {
|
|
61
|
+
keys.push(key.slice(prefix.length));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return keys;
|
|
65
|
+
},
|
|
66
|
+
clear() {
|
|
67
|
+
if (!storage)
|
|
68
|
+
return;
|
|
69
|
+
const keysToRemove = this.keys();
|
|
70
|
+
for (const key of keysToRemove) {
|
|
71
|
+
storage.removeItem(prefix + key);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create an in-memory ScopedStorage (for SSR/testing).
|
|
78
|
+
*/
|
|
79
|
+
function createMemoryStorage(namespace) {
|
|
80
|
+
const store = new Map();
|
|
81
|
+
const prefix = `${namespace}:`;
|
|
82
|
+
return {
|
|
83
|
+
get(key) {
|
|
84
|
+
const stored = store.get(prefix + key);
|
|
85
|
+
if (!stored)
|
|
86
|
+
return undefined;
|
|
87
|
+
if (stored.expiresAt && Date.now() >= stored.expiresAt) {
|
|
88
|
+
store.delete(prefix + key);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return stored.value;
|
|
92
|
+
},
|
|
93
|
+
set(key, value, ttlMs) {
|
|
94
|
+
store.set(prefix + key, {
|
|
95
|
+
value,
|
|
96
|
+
expiresAt: ttlMs ? Date.now() + ttlMs : undefined,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
remove(key) {
|
|
100
|
+
store.delete(prefix + key);
|
|
101
|
+
},
|
|
102
|
+
has(key) {
|
|
103
|
+
return this.get(key) !== undefined;
|
|
104
|
+
},
|
|
105
|
+
keys() {
|
|
106
|
+
const keys = [];
|
|
107
|
+
for (const key of store.keys()) {
|
|
108
|
+
if (key.startsWith(prefix)) {
|
|
109
|
+
keys.push(key.slice(prefix.length));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return keys;
|
|
113
|
+
},
|
|
114
|
+
clear() {
|
|
115
|
+
for (const key of store.keys()) {
|
|
116
|
+
if (key.startsWith(prefix)) {
|
|
117
|
+
store.delete(key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* StateStore class for unified state management.
|
|
125
|
+
*/
|
|
126
|
+
export class StateStore {
|
|
127
|
+
constructor(options = {}) {
|
|
128
|
+
var _a;
|
|
129
|
+
this.namespacedStorages = new Map();
|
|
130
|
+
this.namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : DEFAULT_NAMESPACE;
|
|
131
|
+
// Create scoped storages
|
|
132
|
+
if (typeof window !== "undefined") {
|
|
133
|
+
this.session = createBrowserStorage(typeof sessionStorage !== "undefined" ? sessionStorage : undefined, this.namespace);
|
|
134
|
+
this.user = createBrowserStorage(typeof localStorage !== "undefined" ? localStorage : undefined, this.namespace);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// SSR fallback to in-memory storage
|
|
138
|
+
this.session = createMemoryStorage(this.namespace);
|
|
139
|
+
this.user = createMemoryStorage(this.namespace);
|
|
140
|
+
}
|
|
141
|
+
// Create helpers
|
|
142
|
+
this.dismissals = createDismissalStore(this.session, this.user);
|
|
143
|
+
this.cooldowns = createCooldownStore(this.user); // Cooldowns persist
|
|
144
|
+
this.frequency = createFrequencyStore(this.session); // Frequency is session-based
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a namespaced storage scope.
|
|
148
|
+
* Useful for isolating state by adaptive/tile.
|
|
149
|
+
*
|
|
150
|
+
* @param namespace - Additional namespace segment
|
|
151
|
+
* @returns A ScopedStorage with the nested namespace
|
|
152
|
+
*/
|
|
153
|
+
ns(namespace) {
|
|
154
|
+
const fullNamespace = `${this.namespace}:${namespace}`;
|
|
155
|
+
if (!this.namespacedStorages.has(fullNamespace)) {
|
|
156
|
+
const storage = typeof window !== "undefined" && typeof sessionStorage !== "undefined"
|
|
157
|
+
? createBrowserStorage(sessionStorage, fullNamespace)
|
|
158
|
+
: createMemoryStorage(fullNamespace);
|
|
159
|
+
this.namespacedStorages.set(fullNamespace, storage);
|
|
160
|
+
}
|
|
161
|
+
return this.namespacedStorages.get(fullNamespace);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create a StateStore instance.
|
|
166
|
+
*/
|
|
167
|
+
export function createStateStore(options = {}) {
|
|
168
|
+
return new StateStore(options);
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=StateStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateStore.js","sourceRoot":"","sources":["../../src/state/StateStore.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAO3D,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC;;GAEG;AACH,SAAS,oBAAoB,CAC3B,OAA4B,EAC5B,SAAiB;IAEjB,MAAM,MAAM,GAAG,GAAG,SAAS,GAAG,CAAC;IAE/B,OAAO;QACL,GAAG,CAAI,GAAW;YAChB,IAAI,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAC;YAE/B,IAAI,CAAC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AAI,OAAO,cAAc,KAAK,WAAW;gBACpE,CAAC,CAAC,oBAAoB,CAAC,cAAc,EAAE,aAAa,CAAC;gBACrD,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;YACzC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAE,CAAC;IACrD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IAC9D,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cooldown Store Implementation
|
|
3
|
+
*
|
|
4
|
+
* Tracks time-based cooldowns to prevent items from showing too frequently.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScopedStorage, CooldownStore } from "../types";
|
|
7
|
+
export declare function createCooldownStore(storage: ScopedStorage): CooldownStore;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const COOLDOWN_PREFIX = "cooldown:";
|
|
2
|
+
export function createCooldownStore(storage) {
|
|
3
|
+
return {
|
|
4
|
+
set(key, durationMs) {
|
|
5
|
+
const storageKey = COOLDOWN_PREFIX + key;
|
|
6
|
+
const expiresAt = Date.now() + durationMs;
|
|
7
|
+
storage.set(storageKey, expiresAt);
|
|
8
|
+
},
|
|
9
|
+
isActive(key) {
|
|
10
|
+
return this.remaining(key) > 0;
|
|
11
|
+
},
|
|
12
|
+
remaining(key) {
|
|
13
|
+
const storageKey = COOLDOWN_PREFIX + key;
|
|
14
|
+
const expiresAt = storage.get(storageKey);
|
|
15
|
+
if (expiresAt === undefined)
|
|
16
|
+
return 0;
|
|
17
|
+
const remaining = expiresAt - Date.now();
|
|
18
|
+
if (remaining <= 0) {
|
|
19
|
+
// Clean up expired cooldown
|
|
20
|
+
storage.remove(storageKey);
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return remaining;
|
|
24
|
+
},
|
|
25
|
+
clear(key) {
|
|
26
|
+
const storageKey = COOLDOWN_PREFIX + key;
|
|
27
|
+
storage.remove(storageKey);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cooldowns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cooldowns.js","sourceRoot":"","sources":["../../../src/state/helpers/cooldowns.ts"],"names":[],"mappings":"AAOA,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO;QACL,GAAG,CAAC,GAAW,EAAE,UAAkB;YACjC,MAAM,UAAU,GAAG,eAAe,GAAG,GAAG,CAAC;YACzC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC;YAC1C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACrC,CAAC;QAED,QAAQ,CAAC,GAAW;YAClB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;QAED,SAAS,CAAC,GAAW;YACnB,MAAM,UAAU,GAAG,eAAe,GAAG,GAAG,CAAC;YACzC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAS,UAAU,CAAC,CAAC;YAClD,IAAI,SAAS,KAAK,SAAS;gBAAE,OAAO,CAAC,CAAC;YAEtC,MAAM,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;gBACnB,4BAA4B;gBAC5B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC3B,OAAO,CAAC,CAAC;YACX,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,KAAK,CAAC,GAAW;YACf,MAAM,UAAU,GAAG,eAAe,GAAG,GAAG,CAAC;YACzC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dismissal Store Implementation
|
|
3
|
+
*
|
|
4
|
+
* Tracks dismissed items in session or user storage.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScopedStorage, DismissalStore } from "../types";
|
|
7
|
+
export declare function createDismissalStore(sessionStorage: ScopedStorage, userStorage: ScopedStorage): DismissalStore;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const DISMISSAL_PREFIX = "dismissed:";
|
|
2
|
+
export function createDismissalStore(sessionStorage, userStorage) {
|
|
3
|
+
return {
|
|
4
|
+
mark(key, permanent = false) {
|
|
5
|
+
const storageKey = DISMISSAL_PREFIX + key;
|
|
6
|
+
const storage = permanent ? userStorage : sessionStorage;
|
|
7
|
+
storage.set(storageKey, true);
|
|
8
|
+
},
|
|
9
|
+
isDismissed(key) {
|
|
10
|
+
const storageKey = DISMISSAL_PREFIX + key;
|
|
11
|
+
// Check both session and user storage
|
|
12
|
+
return sessionStorage.has(storageKey) || userStorage.has(storageKey);
|
|
13
|
+
},
|
|
14
|
+
clear(key) {
|
|
15
|
+
const storageKey = DISMISSAL_PREFIX + key;
|
|
16
|
+
sessionStorage.remove(storageKey);
|
|
17
|
+
userStorage.remove(storageKey);
|
|
18
|
+
},
|
|
19
|
+
clearAll() {
|
|
20
|
+
// Clear all dismissal keys from both storages
|
|
21
|
+
for (const key of sessionStorage.keys()) {
|
|
22
|
+
if (key.startsWith(DISMISSAL_PREFIX)) {
|
|
23
|
+
sessionStorage.remove(key);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const key of userStorage.keys()) {
|
|
27
|
+
if (key.startsWith(DISMISSAL_PREFIX)) {
|
|
28
|
+
userStorage.remove(key);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=dismissals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dismissals.js","sourceRoot":"","sources":["../../../src/state/helpers/dismissals.ts"],"names":[],"mappings":"AAOA,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAM,UAAU,oBAAoB,CAClC,cAA6B,EAC7B,WAA0B;IAE1B,OAAO;QACL,IAAI,CAAC,GAAW,EAAE,SAAS,GAAG,KAAK;YACjC,MAAM,UAAU,GAAG,gBAAgB,GAAG,GAAG,CAAC;YAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,WAAW,CAAC,GAAW;YACrB,MAAM,UAAU,GAAG,gBAAgB,GAAG,GAAG,CAAC;YAC1C,sCAAsC;YACtC,OAAO,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvE,CAAC;QAED,KAAK,CAAC,GAAW;YACf,MAAM,UAAU,GAAG,gBAAgB,GAAG,GAAG,CAAC;YAC1C,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAClC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;QAED,QAAQ;YACN,8CAA8C;YAC9C,KAAK,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC;gBACxC,IAAI,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;oBACrC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;YACD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;oBACrC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frequency Store Implementation
|
|
3
|
+
*
|
|
4
|
+
* Tracks how many times items have been shown or actions taken,
|
|
5
|
+
* optionally resetting after a time window.
|
|
6
|
+
*/
|
|
7
|
+
import type { ScopedStorage, FrequencyStore } from "../types";
|
|
8
|
+
export declare function createFrequencyStore(storage: ScopedStorage): FrequencyStore;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const FREQUENCY_PREFIX = "freq:";
|
|
2
|
+
export function createFrequencyStore(storage) {
|
|
3
|
+
function getEntry(key) {
|
|
4
|
+
const storageKey = FREQUENCY_PREFIX + key;
|
|
5
|
+
const entry = storage.get(storageKey);
|
|
6
|
+
if (!entry)
|
|
7
|
+
return undefined;
|
|
8
|
+
// Check if reset time has passed
|
|
9
|
+
if (entry.resetAt && Date.now() >= entry.resetAt) {
|
|
10
|
+
storage.remove(storageKey);
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return entry;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
increment(key, resetAfterMs) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const storageKey = FREQUENCY_PREFIX + key;
|
|
19
|
+
const existing = getEntry(key);
|
|
20
|
+
const newCount = ((_a = existing === null || existing === void 0 ? void 0 : existing.count) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
21
|
+
const entry = {
|
|
22
|
+
count: newCount,
|
|
23
|
+
// Keep existing resetAt or set new one
|
|
24
|
+
resetAt: (_b = existing === null || existing === void 0 ? void 0 : existing.resetAt) !== null && _b !== void 0 ? _b : (resetAfterMs ? Date.now() + resetAfterMs : undefined),
|
|
25
|
+
};
|
|
26
|
+
storage.set(storageKey, entry);
|
|
27
|
+
return newCount;
|
|
28
|
+
},
|
|
29
|
+
count(key) {
|
|
30
|
+
var _a;
|
|
31
|
+
const entry = getEntry(key);
|
|
32
|
+
return (_a = entry === null || entry === void 0 ? void 0 : entry.count) !== null && _a !== void 0 ? _a : 0;
|
|
33
|
+
},
|
|
34
|
+
reset(key) {
|
|
35
|
+
const storageKey = FREQUENCY_PREFIX + key;
|
|
36
|
+
storage.remove(storageKey);
|
|
37
|
+
},
|
|
38
|
+
hasReachedLimit(key, limit) {
|
|
39
|
+
return this.count(key) >= limit;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=frequency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frequency.js","sourceRoot":"","sources":["../../../src/state/helpers/frequency.ts"],"names":[],"mappings":"AAQA,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEjC,MAAM,UAAU,oBAAoB,CAAC,OAAsB;IACzD,SAAS,QAAQ,CAAC,GAAW;QAC3B,MAAM,UAAU,GAAG,gBAAgB,GAAG,GAAG,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAiB,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAE7B,iCAAiC;QACjC,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YACjD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,SAAS,CAAC,GAAW,EAAE,YAAqB;;YAC1C,MAAM,UAAU,GAAG,gBAAgB,GAAG,GAAG,CAAC;YAC1C,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CA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/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export declare const StoredValueZ: z.ZodObject<{
|
|
6
|
+
value: z.ZodUnknown;
|
|
7
|
+
expiresAt: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
value?: unknown;
|
|
10
|
+
expiresAt?: number | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
value?: unknown;
|
|
13
|
+
expiresAt?: number | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const FrequencyEntryZ: z.ZodObject<{
|
|
16
|
+
count: z.ZodNumber;
|
|
17
|
+
resetAt: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
count: number;
|
|
20
|
+
resetAt?: number | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
count: number;
|
|
23
|
+
resetAt?: number | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate a StoredValue object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateStoredValue(data: unknown): z.SafeParseReturnType<{
|
|
29
|
+
value?: unknown;
|
|
30
|
+
expiresAt?: number | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
value?: unknown;
|
|
33
|
+
expiresAt?: number | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Validate a FrequencyEntry object.
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateFrequencyEntry(data: unknown): z.SafeParseReturnType<{
|
|
39
|
+
count: number;
|
|
40
|
+
resetAt?: number | undefined;
|
|
41
|
+
}, {
|
|
42
|
+
count: number;
|
|
43
|
+
resetAt?: number | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Type inference from Zod schema.
|
|
47
|
+
*/
|
|
48
|
+
export type StoredValueSchema = z.infer<typeof StoredValueZ>;
|
|
49
|
+
export type FrequencyEntrySchema = z.infer<typeof FrequencyEntryZ>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for state validation.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const StoredValueZ = z.object({
|
|
6
|
+
value: z.unknown(),
|
|
7
|
+
expiresAt: z.number().optional(),
|
|
8
|
+
});
|
|
9
|
+
export const FrequencyEntryZ = z.object({
|
|
10
|
+
count: z.number(),
|
|
11
|
+
resetAt: z.number().optional(),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Validate a StoredValue object.
|
|
15
|
+
*/
|
|
16
|
+
export function validateStoredValue(data) {
|
|
17
|
+
return StoredValueZ.safeParse(data);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate a FrequencyEntry object.
|
|
21
|
+
*/
|
|
22
|
+
export function validateFrequencyEntry(data) {
|
|
23
|
+
return FrequencyEntryZ.safeParse(data);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/state/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;IAClB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAa;IAC/C,OAAO,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAa;IAClD,OAAO,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Store Types
|
|
3
|
+
*
|
|
4
|
+
* The StateStore provides scoped storage for session and user data,
|
|
5
|
+
* with built-in helpers for common patterns like dismissals, cooldowns,
|
|
6
|
+
* and frequency caps.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Scoped storage interface for reading/writing state.
|
|
10
|
+
*/
|
|
11
|
+
export interface ScopedStorage {
|
|
12
|
+
/**
|
|
13
|
+
* Get a value from storage.
|
|
14
|
+
* @param key - Storage key
|
|
15
|
+
* @returns The stored value or undefined
|
|
16
|
+
*/
|
|
17
|
+
get<T>(key: string): T | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Set a value in storage.
|
|
20
|
+
* @param key - Storage key
|
|
21
|
+
* @param value - Value to store
|
|
22
|
+
* @param ttlMs - Optional time-to-live in milliseconds
|
|
23
|
+
*/
|
|
24
|
+
set<T>(key: string, value: T, ttlMs?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Remove a value from storage.
|
|
27
|
+
* @param key - Storage key
|
|
28
|
+
*/
|
|
29
|
+
remove(key: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a key exists in storage.
|
|
32
|
+
* @param key - Storage key
|
|
33
|
+
*/
|
|
34
|
+
has(key: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Get all keys in this storage scope.
|
|
37
|
+
*/
|
|
38
|
+
keys(): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Clear all values in this storage scope.
|
|
41
|
+
*/
|
|
42
|
+
clear(): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Dismissal store for tracking dismissed items.
|
|
46
|
+
*/
|
|
47
|
+
export interface DismissalStore {
|
|
48
|
+
/**
|
|
49
|
+
* Mark an item as dismissed.
|
|
50
|
+
* @param key - Item identifier
|
|
51
|
+
* @param permanent - If true, store in user storage (persistent). Default: session storage.
|
|
52
|
+
*/
|
|
53
|
+
mark(key: string, permanent?: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Check if an item has been dismissed.
|
|
56
|
+
* @param key - Item identifier
|
|
57
|
+
*/
|
|
58
|
+
isDismissed(key: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Clear a dismissal.
|
|
61
|
+
* @param key - Item identifier
|
|
62
|
+
*/
|
|
63
|
+
clear(key: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Clear all dismissals.
|
|
66
|
+
*/
|
|
67
|
+
clearAll(): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Cooldown store for time-based restrictions.
|
|
71
|
+
*/
|
|
72
|
+
export interface CooldownStore {
|
|
73
|
+
/**
|
|
74
|
+
* Set a cooldown for an item.
|
|
75
|
+
* @param key - Item identifier
|
|
76
|
+
* @param durationMs - Cooldown duration in milliseconds
|
|
77
|
+
*/
|
|
78
|
+
set(key: string, durationMs: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a cooldown is active.
|
|
81
|
+
* @param key - Item identifier
|
|
82
|
+
*/
|
|
83
|
+
isActive(key: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Get remaining cooldown time in milliseconds.
|
|
86
|
+
* @param key - Item identifier
|
|
87
|
+
* @returns Remaining time, or 0 if not active
|
|
88
|
+
*/
|
|
89
|
+
remaining(key: string): number;
|
|
90
|
+
/**
|
|
91
|
+
* Clear a cooldown.
|
|
92
|
+
* @param key - Item identifier
|
|
93
|
+
*/
|
|
94
|
+
clear(key: string): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Frequency store for counting occurrences.
|
|
98
|
+
*/
|
|
99
|
+
export interface FrequencyStore {
|
|
100
|
+
/**
|
|
101
|
+
* Increment the count for an item.
|
|
102
|
+
* @param key - Item identifier
|
|
103
|
+
* @param resetAfterMs - Optional reset window in milliseconds
|
|
104
|
+
* @returns The new count
|
|
105
|
+
*/
|
|
106
|
+
increment(key: string, resetAfterMs?: number): number;
|
|
107
|
+
/**
|
|
108
|
+
* Get the current count for an item.
|
|
109
|
+
* @param key - Item identifier
|
|
110
|
+
*/
|
|
111
|
+
count(key: string): number;
|
|
112
|
+
/**
|
|
113
|
+
* Reset the count for an item.
|
|
114
|
+
* @param key - Item identifier
|
|
115
|
+
*/
|
|
116
|
+
reset(key: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* Check if an item has reached a limit.
|
|
119
|
+
* @param key - Item identifier
|
|
120
|
+
* @param limit - Maximum count
|
|
121
|
+
*/
|
|
122
|
+
hasReachedLimit(key: string, limit: number): boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Stored value with optional TTL metadata.
|
|
126
|
+
*/
|
|
127
|
+
export interface StoredValue<T = unknown> {
|
|
128
|
+
value: T;
|
|
129
|
+
expiresAt?: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Frequency entry with count and reset metadata.
|
|
133
|
+
*/
|
|
134
|
+
export interface FrequencyEntry {
|
|
135
|
+
count: number;
|
|
136
|
+
resetAt?: number;
|
|
137
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -15,7 +15,7 @@ export class PostHogAdapter {
|
|
|
15
15
|
const enableFeatureFlags = (_a = options.enableFeatureFlags) !== null && _a !== void 0 ? _a : true;
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
17
|
this.client.init(options.apiKey, {
|
|
18
|
-
api_host: (_b = options.apiHost) !== null && _b !== void 0 ? _b : "https://
|
|
18
|
+
api_host: (_b = options.apiHost) !== null && _b !== void 0 ? _b : "https://telemetry.syntrologie.com",
|
|
19
19
|
// Feature flags for segment membership (in_segment_* flags)
|
|
20
20
|
// When enabled, /decide is called to get segment flags
|
|
21
21
|
advanced_disable_feature_flags: !enableFeatureFlags,
|