@syntrologie/runtime-sdk 0.2.19 → 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,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for decision strategy validation.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// CONDITION SCHEMAS
|
|
7
|
+
// =============================================================================
|
|
8
|
+
export const PageUrlConditionZ = z.object({
|
|
9
|
+
type: z.literal("page_url"),
|
|
10
|
+
url: z.string(),
|
|
11
|
+
});
|
|
12
|
+
export const RouteConditionZ = z.object({
|
|
13
|
+
type: z.literal("route"),
|
|
14
|
+
routeId: z.string(),
|
|
15
|
+
});
|
|
16
|
+
export const AnchorVisibleConditionZ = z.object({
|
|
17
|
+
type: z.literal("anchor_visible"),
|
|
18
|
+
anchorId: z.string(),
|
|
19
|
+
state: z.enum(["visible", "present", "absent"]),
|
|
20
|
+
});
|
|
21
|
+
export const EventOccurredConditionZ = z.object({
|
|
22
|
+
type: z.literal("event_occurred"),
|
|
23
|
+
eventName: z.string(),
|
|
24
|
+
withinMs: z.number().optional(),
|
|
25
|
+
});
|
|
26
|
+
export const StateEqualsConditionZ = z.object({
|
|
27
|
+
type: z.literal("state_equals"),
|
|
28
|
+
key: z.string(),
|
|
29
|
+
value: z.unknown(),
|
|
30
|
+
});
|
|
31
|
+
export const ViewportConditionZ = z.object({
|
|
32
|
+
type: z.literal("viewport"),
|
|
33
|
+
minWidth: z.number().optional(),
|
|
34
|
+
maxWidth: z.number().optional(),
|
|
35
|
+
minHeight: z.number().optional(),
|
|
36
|
+
maxHeight: z.number().optional(),
|
|
37
|
+
});
|
|
38
|
+
export const SessionMetricConditionZ = z.object({
|
|
39
|
+
type: z.literal("session_metric"),
|
|
40
|
+
key: z.string(),
|
|
41
|
+
operator: z.enum(["gte", "lte", "eq", "gt", "lt"]),
|
|
42
|
+
threshold: z.number(),
|
|
43
|
+
});
|
|
44
|
+
export const DismissedConditionZ = z.object({
|
|
45
|
+
type: z.literal("dismissed"),
|
|
46
|
+
key: z.string(),
|
|
47
|
+
inverted: z.boolean().optional(),
|
|
48
|
+
});
|
|
49
|
+
export const CooldownActiveConditionZ = z.object({
|
|
50
|
+
type: z.literal("cooldown_active"),
|
|
51
|
+
key: z.string(),
|
|
52
|
+
inverted: z.boolean().optional(),
|
|
53
|
+
});
|
|
54
|
+
export const FrequencyLimitConditionZ = z.object({
|
|
55
|
+
type: z.literal("frequency_limit"),
|
|
56
|
+
key: z.string(),
|
|
57
|
+
limit: z.number(),
|
|
58
|
+
inverted: z.boolean().optional(),
|
|
59
|
+
});
|
|
60
|
+
export const ConditionZ = z.discriminatedUnion("type", [
|
|
61
|
+
PageUrlConditionZ,
|
|
62
|
+
RouteConditionZ,
|
|
63
|
+
AnchorVisibleConditionZ,
|
|
64
|
+
EventOccurredConditionZ,
|
|
65
|
+
StateEqualsConditionZ,
|
|
66
|
+
ViewportConditionZ,
|
|
67
|
+
SessionMetricConditionZ,
|
|
68
|
+
DismissedConditionZ,
|
|
69
|
+
CooldownActiveConditionZ,
|
|
70
|
+
FrequencyLimitConditionZ,
|
|
71
|
+
]);
|
|
72
|
+
// =============================================================================
|
|
73
|
+
// STRATEGY SCHEMAS
|
|
74
|
+
// =============================================================================
|
|
75
|
+
export const RuleZ = z.object({
|
|
76
|
+
conditions: z.array(ConditionZ),
|
|
77
|
+
value: z.unknown(),
|
|
78
|
+
});
|
|
79
|
+
export const RuleStrategyZ = z.object({
|
|
80
|
+
type: z.literal("rules"),
|
|
81
|
+
rules: z.array(RuleZ),
|
|
82
|
+
default: z.unknown(),
|
|
83
|
+
});
|
|
84
|
+
export const ScoreStrategyZ = z.object({
|
|
85
|
+
type: z.literal("score"),
|
|
86
|
+
field: z.string(),
|
|
87
|
+
threshold: z.number(),
|
|
88
|
+
above: z.unknown(),
|
|
89
|
+
below: z.unknown(),
|
|
90
|
+
});
|
|
91
|
+
export const ModelStrategyZ = z.object({
|
|
92
|
+
type: z.literal("model"),
|
|
93
|
+
modelId: z.string(),
|
|
94
|
+
inputs: z.array(z.string()),
|
|
95
|
+
outputMapping: z.record(z.unknown()),
|
|
96
|
+
default: z.unknown(),
|
|
97
|
+
});
|
|
98
|
+
export const ExternalStrategyZ = z.object({
|
|
99
|
+
type: z.literal("external"),
|
|
100
|
+
endpoint: z.string(),
|
|
101
|
+
method: z.enum(["GET", "POST"]).optional(),
|
|
102
|
+
default: z.unknown(),
|
|
103
|
+
timeoutMs: z.number().optional(),
|
|
104
|
+
});
|
|
105
|
+
export const DecisionStrategyZ = z.discriminatedUnion("type", [
|
|
106
|
+
RuleStrategyZ,
|
|
107
|
+
ScoreStrategyZ,
|
|
108
|
+
ModelStrategyZ,
|
|
109
|
+
ExternalStrategyZ,
|
|
110
|
+
]);
|
|
111
|
+
// =============================================================================
|
|
112
|
+
// ACTIVATION CONFIG SCHEMA
|
|
113
|
+
// =============================================================================
|
|
114
|
+
export const RouteFilterZ = z.object({
|
|
115
|
+
include: z.array(z.string()).optional(),
|
|
116
|
+
exclude: z.array(z.string()).optional(),
|
|
117
|
+
});
|
|
118
|
+
export const ActivationConfigZ = z.object({
|
|
119
|
+
routes: RouteFilterZ.optional(),
|
|
120
|
+
strategy: DecisionStrategyZ.optional(),
|
|
121
|
+
});
|
|
122
|
+
// =============================================================================
|
|
123
|
+
// VALIDATION FUNCTIONS
|
|
124
|
+
// =============================================================================
|
|
125
|
+
/**
|
|
126
|
+
* Validate a Condition object.
|
|
127
|
+
*/
|
|
128
|
+
export function validateCondition(data) {
|
|
129
|
+
return ConditionZ.safeParse(data);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Validate a DecisionStrategy object.
|
|
133
|
+
*/
|
|
134
|
+
export function validateStrategy(data) {
|
|
135
|
+
return DecisionStrategyZ.safeParse(data);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Validate an ActivationConfig object.
|
|
139
|
+
*/
|
|
140
|
+
export function validateActivationConfig(data) {
|
|
141
|
+
return ActivationConfigZ.safeParse(data);
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/decisions/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;CAChD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,CA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;IACd,cAAc;IACd,iBAAiB;CAClB,CAAC,CAAC;AAEH,gFAAgF;AAChF,2BAA2B;AAC3B,gFAAgF;AAEhF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAC;AAEH,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAa;IACpD,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule Strategy Evaluator
|
|
3
|
+
*
|
|
4
|
+
* Evaluates rules in order and returns the value of the first matching rule.
|
|
5
|
+
*/
|
|
6
|
+
import type { RuleStrategy, Rule, Condition, DecisionResult, EvaluationContext } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Evaluate a single condition against the evaluation context.
|
|
9
|
+
*/
|
|
10
|
+
export declare function evaluateCondition(condition: Condition, evalContext: EvaluationContext): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Evaluate a single rule (all conditions must be true).
|
|
13
|
+
*/
|
|
14
|
+
export declare function evaluateRule(rule: Rule, evalContext: EvaluationContext): {
|
|
15
|
+
matched: boolean;
|
|
16
|
+
conditionResults: Array<{
|
|
17
|
+
condition: Condition;
|
|
18
|
+
result: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Evaluate a RuleStrategy and return the result.
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateRuleStrategy<T>(strategy: RuleStrategy<T>, evalContext: EvaluationContext): DecisionResult<T>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate a single condition against the evaluation context.
|
|
3
|
+
*/
|
|
4
|
+
export function evaluateCondition(condition, evalContext) {
|
|
5
|
+
var _a, _b, _c, _d, _e;
|
|
6
|
+
const { context, state, events } = evalContext;
|
|
7
|
+
switch (condition.type) {
|
|
8
|
+
case "page_url": {
|
|
9
|
+
const { url } = condition;
|
|
10
|
+
const currentUrl = context.page.url;
|
|
11
|
+
// Simple pattern matching with wildcards
|
|
12
|
+
const pattern = url
|
|
13
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape regex chars except * and ?
|
|
14
|
+
.replace(/\*\*/g, ".*") // ** matches anything
|
|
15
|
+
.replace(/\*/g, "[^/]*"); // * matches within path segment
|
|
16
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
17
|
+
return regex.test(currentUrl);
|
|
18
|
+
}
|
|
19
|
+
case "route": {
|
|
20
|
+
return context.page.routeId === condition.routeId;
|
|
21
|
+
}
|
|
22
|
+
case "anchor_visible": {
|
|
23
|
+
const anchor = (_a = context.anchors) === null || _a === void 0 ? void 0 : _a.find((a) => a.anchorId === condition.anchorId);
|
|
24
|
+
switch (condition.state) {
|
|
25
|
+
case "visible":
|
|
26
|
+
return (anchor === null || anchor === void 0 ? void 0 : anchor.visible) === true;
|
|
27
|
+
case "present":
|
|
28
|
+
return (anchor === null || anchor === void 0 ? void 0 : anchor.present) === true;
|
|
29
|
+
case "absent":
|
|
30
|
+
return !(anchor === null || anchor === void 0 ? void 0 : anchor.present);
|
|
31
|
+
default:
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
case "event_occurred": {
|
|
36
|
+
if (!events)
|
|
37
|
+
return false;
|
|
38
|
+
const withinMs = (_b = condition.withinMs) !== null && _b !== void 0 ? _b : 60000; // Default 1 minute
|
|
39
|
+
return events.hasRecentEvent(condition.eventName, withinMs);
|
|
40
|
+
}
|
|
41
|
+
case "state_equals": {
|
|
42
|
+
// This checks arbitrary state values - implementation depends on
|
|
43
|
+
// how the state store exposes values. For now, check session storage.
|
|
44
|
+
if (!state)
|
|
45
|
+
return false;
|
|
46
|
+
// The state key format could be "dismissals:xyz" or just "xyz"
|
|
47
|
+
// For simplicity, we'll do a basic comparison
|
|
48
|
+
return false; // TODO: Implement when state interface is clearer
|
|
49
|
+
}
|
|
50
|
+
case "viewport": {
|
|
51
|
+
const { width, height } = context.viewport;
|
|
52
|
+
if (condition.minWidth !== undefined && width < condition.minWidth)
|
|
53
|
+
return false;
|
|
54
|
+
if (condition.maxWidth !== undefined && width > condition.maxWidth)
|
|
55
|
+
return false;
|
|
56
|
+
if (condition.minHeight !== undefined && height < condition.minHeight)
|
|
57
|
+
return false;
|
|
58
|
+
if (condition.maxHeight !== undefined && height > condition.maxHeight)
|
|
59
|
+
return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
case "session_metric": {
|
|
63
|
+
if (!state)
|
|
64
|
+
return false;
|
|
65
|
+
const metricValue = state.getSessionMetric(condition.key);
|
|
66
|
+
const { operator, threshold } = condition;
|
|
67
|
+
switch (operator) {
|
|
68
|
+
case "gte":
|
|
69
|
+
return metricValue >= threshold;
|
|
70
|
+
case "lte":
|
|
71
|
+
return metricValue <= threshold;
|
|
72
|
+
case "eq":
|
|
73
|
+
return metricValue === threshold;
|
|
74
|
+
case "gt":
|
|
75
|
+
return metricValue > threshold;
|
|
76
|
+
case "lt":
|
|
77
|
+
return metricValue < threshold;
|
|
78
|
+
default:
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
case "dismissed": {
|
|
83
|
+
if (!state)
|
|
84
|
+
return (_c = condition.inverted) !== null && _c !== void 0 ? _c : false;
|
|
85
|
+
const isDismissed = state.isDismissed(condition.key);
|
|
86
|
+
return condition.inverted ? !isDismissed : isDismissed;
|
|
87
|
+
}
|
|
88
|
+
case "cooldown_active": {
|
|
89
|
+
if (!state)
|
|
90
|
+
return (_d = condition.inverted) !== null && _d !== void 0 ? _d : false;
|
|
91
|
+
const isActive = state.isCooldownActive(condition.key);
|
|
92
|
+
return condition.inverted ? !isActive : isActive;
|
|
93
|
+
}
|
|
94
|
+
case "frequency_limit": {
|
|
95
|
+
if (!state)
|
|
96
|
+
return (_e = condition.inverted) !== null && _e !== void 0 ? _e : false;
|
|
97
|
+
const count = state.getFrequencyCount(condition.key);
|
|
98
|
+
const limitReached = count >= condition.limit;
|
|
99
|
+
return condition.inverted ? !limitReached : limitReached;
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
// Unknown condition type - fail closed (return false)
|
|
103
|
+
console.warn("[RuleStrategy] Unknown condition type:", condition.type);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Evaluate a single rule (all conditions must be true).
|
|
109
|
+
*/
|
|
110
|
+
export function evaluateRule(rule, evalContext) {
|
|
111
|
+
const conditionResults = [];
|
|
112
|
+
for (const condition of rule.conditions) {
|
|
113
|
+
const result = evaluateCondition(condition, evalContext);
|
|
114
|
+
conditionResults.push({ condition, result });
|
|
115
|
+
// Short-circuit: if any condition fails, rule doesn't match
|
|
116
|
+
if (!result) {
|
|
117
|
+
return { matched: false, conditionResults };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// All conditions passed
|
|
121
|
+
return { matched: true, conditionResults };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Evaluate a RuleStrategy and return the result.
|
|
125
|
+
*/
|
|
126
|
+
export function evaluateRuleStrategy(strategy, evalContext) {
|
|
127
|
+
// Evaluate rules in order
|
|
128
|
+
for (let i = 0; i < strategy.rules.length; i++) {
|
|
129
|
+
const rule = strategy.rules[i];
|
|
130
|
+
const { matched, conditionResults } = evaluateRule(rule, evalContext);
|
|
131
|
+
if (matched) {
|
|
132
|
+
return {
|
|
133
|
+
value: rule.value,
|
|
134
|
+
isFallback: false,
|
|
135
|
+
matchInfo: {
|
|
136
|
+
strategyType: "rules",
|
|
137
|
+
matchedRuleIndex: i,
|
|
138
|
+
evaluatedConditions: conditionResults,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// No rules matched, return default
|
|
144
|
+
return {
|
|
145
|
+
value: strategy.default,
|
|
146
|
+
isFallback: true,
|
|
147
|
+
matchInfo: {
|
|
148
|
+
strategyType: "rules",
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../src/decisions/strategies/rules.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAAoB,EACpB,WAA8B;;IAE9B,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;IAE/C,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;YAC1B,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YAEpC,yCAAyC;YACz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mCAAmC;IACnC,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,OAAY;QAC5B,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE;YACT,YAAY,EAAE,OAAO;SACtB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Score Strategy Evaluator
|
|
3
|
+
*
|
|
4
|
+
* Compares an augmented field value against a threshold.
|
|
5
|
+
*/
|
|
6
|
+
import type { ScoreStrategy, DecisionResult, EvaluationContext } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Evaluate a ScoreStrategy and return the result.
|
|
9
|
+
*/
|
|
10
|
+
export declare function evaluateScoreStrategy<T>(strategy: ScoreStrategy<T>, evalContext: EvaluationContext): DecisionResult<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate a ScoreStrategy and return the result.
|
|
3
|
+
*/
|
|
4
|
+
export function evaluateScoreStrategy(strategy, evalContext) {
|
|
5
|
+
var _a;
|
|
6
|
+
const { context } = evalContext;
|
|
7
|
+
// Get the score from augmented context
|
|
8
|
+
const score = (_a = context.augmented) === null || _a === void 0 ? void 0 : _a[strategy.field];
|
|
9
|
+
// If no score available, return below value as fallback
|
|
10
|
+
if (score === undefined || typeof score !== "number") {
|
|
11
|
+
return {
|
|
12
|
+
value: strategy.below,
|
|
13
|
+
isFallback: true,
|
|
14
|
+
matchInfo: {
|
|
15
|
+
strategyType: "score",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Compare against threshold
|
|
20
|
+
const isAbove = score >= strategy.threshold;
|
|
21
|
+
return {
|
|
22
|
+
value: isAbove ? strategy.above : strategy.below,
|
|
23
|
+
isFallback: false,
|
|
24
|
+
matchInfo: {
|
|
25
|
+
strategyType: "score",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../../src/decisions/strategies/score.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA0B,EAC1B,WAA8B;;IAE9B,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;IAEhC,uCAAuC;IACvC,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,SAAS,0CAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElD,wDAAwD;IACxD,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrD,OAAO;YACL,KAAK,EAAE,QAAQ,CAAC,KAAU;YAC1B,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE;gBACT,YAAY,EAAE,OAAO;aACtB;SACF,CAAC;IACJ,CAAC;IAED,4BAA4B;IAC5B,MAAM,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,SAAS,CAAC;IAE5C,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,CAAC,CAAE,QAAQ,CAAC,KAAW,CAAC,CAAC,CAAE,QAAQ,CAAC,KAAW;QAC9D,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE;YACT,YAAY,EAAE,OAAO;SACtB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision Strategy Types
|
|
3
|
+
*
|
|
4
|
+
* DecisionStrategy is the core abstraction for conditional rendering
|
|
5
|
+
* and adaptive behavior in the v2 runtime. It replaces the experiment-based
|
|
6
|
+
* filtering with a more flexible, context-aware system.
|
|
7
|
+
*/
|
|
8
|
+
import type { RuntimeContext } from "../context/types";
|
|
9
|
+
/**
|
|
10
|
+
* Condition that checks if the current page URL matches a pattern.
|
|
11
|
+
*/
|
|
12
|
+
export interface PageUrlCondition {
|
|
13
|
+
type: "page_url";
|
|
14
|
+
/** URL pattern (supports wildcards: * and **) */
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Condition that checks if the current route matches.
|
|
19
|
+
*/
|
|
20
|
+
export interface RouteCondition {
|
|
21
|
+
type: "route";
|
|
22
|
+
/** Route ID from RoutesConfig */
|
|
23
|
+
routeId: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Condition that checks anchor element visibility.
|
|
27
|
+
*/
|
|
28
|
+
export interface AnchorVisibleCondition {
|
|
29
|
+
type: "anchor_visible";
|
|
30
|
+
/** Anchor element ID */
|
|
31
|
+
anchorId: string;
|
|
32
|
+
/** Required state */
|
|
33
|
+
state: "visible" | "present" | "absent";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Condition that checks if an event occurred recently.
|
|
37
|
+
*/
|
|
38
|
+
export interface EventOccurredCondition {
|
|
39
|
+
type: "event_occurred";
|
|
40
|
+
/** Event name to check */
|
|
41
|
+
eventName: string;
|
|
42
|
+
/** Time window in milliseconds (optional) */
|
|
43
|
+
withinMs?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Condition that checks a state value.
|
|
47
|
+
*/
|
|
48
|
+
export interface StateEqualsCondition {
|
|
49
|
+
type: "state_equals";
|
|
50
|
+
/** State key to check */
|
|
51
|
+
key: string;
|
|
52
|
+
/** Expected value */
|
|
53
|
+
value: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Condition that checks viewport size.
|
|
57
|
+
*/
|
|
58
|
+
export interface ViewportCondition {
|
|
59
|
+
type: "viewport";
|
|
60
|
+
/** Minimum viewport width */
|
|
61
|
+
minWidth?: number;
|
|
62
|
+
/** Maximum viewport width */
|
|
63
|
+
maxWidth?: number;
|
|
64
|
+
/** Minimum viewport height */
|
|
65
|
+
minHeight?: number;
|
|
66
|
+
/** Maximum viewport height */
|
|
67
|
+
maxHeight?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Condition that checks a session metric threshold.
|
|
71
|
+
*/
|
|
72
|
+
export interface SessionMetricCondition {
|
|
73
|
+
type: "session_metric";
|
|
74
|
+
/** Metric key */
|
|
75
|
+
key: string;
|
|
76
|
+
/** Comparison operator */
|
|
77
|
+
operator: "gte" | "lte" | "eq" | "gt" | "lt";
|
|
78
|
+
/** Threshold value */
|
|
79
|
+
threshold: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Condition that checks if an item has been dismissed.
|
|
83
|
+
*/
|
|
84
|
+
export interface DismissedCondition {
|
|
85
|
+
type: "dismissed";
|
|
86
|
+
/** Item key to check */
|
|
87
|
+
key: string;
|
|
88
|
+
/** Invert the condition (true if NOT dismissed) */
|
|
89
|
+
inverted?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Condition that checks if a cooldown is active.
|
|
93
|
+
*/
|
|
94
|
+
export interface CooldownActiveCondition {
|
|
95
|
+
type: "cooldown_active";
|
|
96
|
+
/** Cooldown key to check */
|
|
97
|
+
key: string;
|
|
98
|
+
/** Invert the condition (true if NOT active) */
|
|
99
|
+
inverted?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Condition that checks frequency limits.
|
|
103
|
+
*/
|
|
104
|
+
export interface FrequencyLimitCondition {
|
|
105
|
+
type: "frequency_limit";
|
|
106
|
+
/** Frequency key to check */
|
|
107
|
+
key: string;
|
|
108
|
+
/** Maximum allowed count */
|
|
109
|
+
limit: number;
|
|
110
|
+
/** Invert the condition (true if limit NOT reached) */
|
|
111
|
+
inverted?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Union of all condition types.
|
|
115
|
+
*/
|
|
116
|
+
export type Condition = PageUrlCondition | RouteCondition | AnchorVisibleCondition | EventOccurredCondition | StateEqualsCondition | ViewportCondition | SessionMetricCondition | DismissedCondition | CooldownActiveCondition | FrequencyLimitCondition;
|
|
117
|
+
/**
|
|
118
|
+
* Rule with conditions and output value.
|
|
119
|
+
*/
|
|
120
|
+
export interface Rule<T = unknown> {
|
|
121
|
+
/** Conditions that must all be met (AND logic) */
|
|
122
|
+
conditions: Condition[];
|
|
123
|
+
/** Value to return if all conditions are met */
|
|
124
|
+
value: T;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Rule-based strategy: evaluates rules in order, returns first match.
|
|
128
|
+
*/
|
|
129
|
+
export interface RuleStrategy<T = unknown> {
|
|
130
|
+
type: "rules";
|
|
131
|
+
/** Rules to evaluate in order */
|
|
132
|
+
rules: Rule<T>[];
|
|
133
|
+
/** Default value if no rules match */
|
|
134
|
+
default: T;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Score-based strategy: compares an augmented field against a threshold.
|
|
138
|
+
*/
|
|
139
|
+
export interface ScoreStrategy<T = unknown> {
|
|
140
|
+
type: "score";
|
|
141
|
+
/** Field name in augmented context */
|
|
142
|
+
field: string;
|
|
143
|
+
/** Threshold value */
|
|
144
|
+
threshold: number;
|
|
145
|
+
/** Value if score >= threshold */
|
|
146
|
+
above: T;
|
|
147
|
+
/** Value if score < threshold */
|
|
148
|
+
below: T;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Model-based strategy: invokes an ML model for prediction.
|
|
152
|
+
* (Phase 3 - placeholder)
|
|
153
|
+
*/
|
|
154
|
+
export interface ModelStrategy<T = unknown> {
|
|
155
|
+
type: "model";
|
|
156
|
+
/** Model endpoint or ID */
|
|
157
|
+
modelId: string;
|
|
158
|
+
/** Input fields from context */
|
|
159
|
+
inputs: string[];
|
|
160
|
+
/** Mapping of model outputs to values */
|
|
161
|
+
outputMapping: Record<string, T>;
|
|
162
|
+
/** Default value if model call fails */
|
|
163
|
+
default: T;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* External strategy: calls a remote endpoint for decision.
|
|
167
|
+
* (Phase 3 - placeholder)
|
|
168
|
+
*/
|
|
169
|
+
export interface ExternalStrategy<T = unknown> {
|
|
170
|
+
type: "external";
|
|
171
|
+
/** Endpoint URL */
|
|
172
|
+
endpoint: string;
|
|
173
|
+
/** HTTP method */
|
|
174
|
+
method?: "GET" | "POST";
|
|
175
|
+
/** Default value if endpoint fails */
|
|
176
|
+
default: T;
|
|
177
|
+
/** Timeout in milliseconds */
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Union of all strategy types.
|
|
182
|
+
*/
|
|
183
|
+
export type DecisionStrategy<T = unknown> = RuleStrategy<T> | ScoreStrategy<T> | ModelStrategy<T> | ExternalStrategy<T>;
|
|
184
|
+
/**
|
|
185
|
+
* Result of evaluating a DecisionStrategy.
|
|
186
|
+
*/
|
|
187
|
+
export interface DecisionResult<T = unknown> {
|
|
188
|
+
/** The decided value */
|
|
189
|
+
value: T;
|
|
190
|
+
/** Whether the result came from a fallback/default */
|
|
191
|
+
isFallback: boolean;
|
|
192
|
+
/** Debug info about which rule/condition matched */
|
|
193
|
+
matchInfo?: {
|
|
194
|
+
/** Strategy type that produced the result */
|
|
195
|
+
strategyType: DecisionStrategy<T>["type"];
|
|
196
|
+
/** Index of matched rule (for rule strategy) */
|
|
197
|
+
matchedRuleIndex?: number;
|
|
198
|
+
/** Conditions that were evaluated */
|
|
199
|
+
evaluatedConditions?: Array<{
|
|
200
|
+
condition: Condition;
|
|
201
|
+
result: boolean;
|
|
202
|
+
}>;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Route filter for tile activation.
|
|
207
|
+
*/
|
|
208
|
+
export interface RouteFilter {
|
|
209
|
+
/** Routes where the tile should appear */
|
|
210
|
+
include?: string[];
|
|
211
|
+
/** Routes where the tile should NOT appear */
|
|
212
|
+
exclude?: string[];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Activation configuration for tiles.
|
|
216
|
+
* Replaces the old TileExperiment type.
|
|
217
|
+
*/
|
|
218
|
+
export interface ActivationConfig {
|
|
219
|
+
/** Route-based filtering */
|
|
220
|
+
routes?: RouteFilter;
|
|
221
|
+
/** Decision strategy for conditional rendering */
|
|
222
|
+
strategy?: DecisionStrategy<boolean>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Extended context for strategy evaluation.
|
|
226
|
+
* Includes runtime references for state/event checks.
|
|
227
|
+
*/
|
|
228
|
+
export interface EvaluationContext {
|
|
229
|
+
/** Runtime context snapshot */
|
|
230
|
+
context: RuntimeContext;
|
|
231
|
+
/** Access to state store (for dismissals, cooldowns, frequency) */
|
|
232
|
+
state?: {
|
|
233
|
+
isDismissed(key: string): boolean;
|
|
234
|
+
isCooldownActive(key: string): boolean;
|
|
235
|
+
getFrequencyCount(key: string): number;
|
|
236
|
+
getSessionMetric(key: string): number;
|
|
237
|
+
};
|
|
238
|
+
/** Access to event bus (for event_occurred checks) */
|
|
239
|
+
events?: {
|
|
240
|
+
hasRecentEvent(eventName: string, withinMs: number): boolean;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/decisions/types.ts"],"names":[],"mappings":""}
|
package/dist/editorLoader.d.ts
CHANGED
|
@@ -4,6 +4,16 @@ export declare const DEFAULT_EDITOR_URL = "https://cdn.syntrologie.com/editor-sd
|
|
|
4
4
|
* Requires editor_token parameter for security (not just syntro_editor flag).
|
|
5
5
|
*/
|
|
6
6
|
export declare const shouldLoadEditor: () => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if audit mode should be activated based on URL query parameters.
|
|
9
|
+
* Audit mode enables element marking for product touring.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isAuditMode: () => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if any SDK mode (editor or audit) should be loaded.
|
|
14
|
+
* Returns the mode type if active, or null if neither.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getActiveSdkMode: () => "editor" | "audit" | null;
|
|
7
17
|
export interface EditorLoadOptions {
|
|
8
18
|
/** URL to load editor SDK from */
|
|
9
19
|
editorUrl?: string;
|