@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
|
@@ -15,11 +15,11 @@ export declare const SelectorZ: z.ZodUnion<[z.ZodObject<{
|
|
|
15
15
|
type: z.ZodLiteral<"css">;
|
|
16
16
|
value: z.ZodString;
|
|
17
17
|
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
value: string;
|
|
19
18
|
type: "css";
|
|
20
|
-
}, {
|
|
21
19
|
value: string;
|
|
20
|
+
}, {
|
|
22
21
|
type: "css";
|
|
22
|
+
value: string;
|
|
23
23
|
}>, z.ZodObject<{
|
|
24
24
|
type: z.ZodLiteral<"aria">;
|
|
25
25
|
role: z.ZodOptional<z.ZodString>;
|
|
@@ -36,11 +36,11 @@ export declare const SelectorZ: z.ZodUnion<[z.ZodObject<{
|
|
|
36
36
|
type: z.ZodLiteral<"shadow-css">;
|
|
37
37
|
value: z.ZodString;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
39
|
-
value: string;
|
|
40
39
|
type: "shadow-css";
|
|
41
|
-
}, {
|
|
42
40
|
value: string;
|
|
41
|
+
}, {
|
|
43
42
|
type: "shadow-css";
|
|
43
|
+
value: string;
|
|
44
44
|
}>, z.ZodObject<{
|
|
45
45
|
type: z.ZodLiteral<"ref">;
|
|
46
46
|
el: z.ZodAny;
|
|
@@ -70,11 +70,11 @@ export declare const TooltipStepZ: z.ZodObject<{
|
|
|
70
70
|
type: z.ZodLiteral<"css">;
|
|
71
71
|
value: z.ZodString;
|
|
72
72
|
}, "strip", z.ZodTypeAny, {
|
|
73
|
-
value: string;
|
|
74
73
|
type: "css";
|
|
75
|
-
}, {
|
|
76
74
|
value: string;
|
|
75
|
+
}, {
|
|
77
76
|
type: "css";
|
|
77
|
+
value: string;
|
|
78
78
|
}>, z.ZodObject<{
|
|
79
79
|
type: z.ZodLiteral<"aria">;
|
|
80
80
|
role: z.ZodOptional<z.ZodString>;
|
|
@@ -91,11 +91,11 @@ export declare const TooltipStepZ: z.ZodObject<{
|
|
|
91
91
|
type: z.ZodLiteral<"shadow-css">;
|
|
92
92
|
value: z.ZodString;
|
|
93
93
|
}, "strip", z.ZodTypeAny, {
|
|
94
|
-
value: string;
|
|
95
94
|
type: "shadow-css";
|
|
96
|
-
}, {
|
|
97
95
|
value: string;
|
|
96
|
+
}, {
|
|
98
97
|
type: "shadow-css";
|
|
98
|
+
value: string;
|
|
99
99
|
}>, z.ZodObject<{
|
|
100
100
|
type: z.ZodLiteral<"ref">;
|
|
101
101
|
el: z.ZodAny;
|
|
@@ -139,15 +139,15 @@ export declare const TooltipStepZ: z.ZodObject<{
|
|
|
139
139
|
key: string;
|
|
140
140
|
value?: string | undefined;
|
|
141
141
|
} | {
|
|
142
|
-
value: string;
|
|
143
142
|
type: "css";
|
|
143
|
+
value: string;
|
|
144
144
|
} | {
|
|
145
145
|
type: "aria";
|
|
146
146
|
label?: string | undefined;
|
|
147
147
|
role?: string | undefined;
|
|
148
148
|
} | {
|
|
149
|
-
value: string;
|
|
150
149
|
type: "shadow-css";
|
|
150
|
+
value: string;
|
|
151
151
|
} | {
|
|
152
152
|
type: "ref";
|
|
153
153
|
el?: any;
|
|
@@ -173,15 +173,15 @@ export declare const TooltipStepZ: z.ZodObject<{
|
|
|
173
173
|
key: string;
|
|
174
174
|
value?: string | undefined;
|
|
175
175
|
} | {
|
|
176
|
-
value: string;
|
|
177
176
|
type: "css";
|
|
177
|
+
value: string;
|
|
178
178
|
} | {
|
|
179
179
|
type: "aria";
|
|
180
180
|
label?: string | undefined;
|
|
181
181
|
role?: string | undefined;
|
|
182
182
|
} | {
|
|
183
|
-
value: string;
|
|
184
183
|
type: "shadow-css";
|
|
184
|
+
value: string;
|
|
185
185
|
} | {
|
|
186
186
|
type: "ref";
|
|
187
187
|
el?: any;
|
|
@@ -221,11 +221,11 @@ export declare const HighlightStepZ: z.ZodObject<{
|
|
|
221
221
|
type: z.ZodLiteral<"css">;
|
|
222
222
|
value: z.ZodString;
|
|
223
223
|
}, "strip", z.ZodTypeAny, {
|
|
224
|
-
value: string;
|
|
225
224
|
type: "css";
|
|
226
|
-
}, {
|
|
227
225
|
value: string;
|
|
226
|
+
}, {
|
|
228
227
|
type: "css";
|
|
228
|
+
value: string;
|
|
229
229
|
}>, z.ZodObject<{
|
|
230
230
|
type: z.ZodLiteral<"aria">;
|
|
231
231
|
role: z.ZodOptional<z.ZodString>;
|
|
@@ -242,11 +242,11 @@ export declare const HighlightStepZ: z.ZodObject<{
|
|
|
242
242
|
type: z.ZodLiteral<"shadow-css">;
|
|
243
243
|
value: z.ZodString;
|
|
244
244
|
}, "strip", z.ZodTypeAny, {
|
|
245
|
-
value: string;
|
|
246
245
|
type: "shadow-css";
|
|
247
|
-
}, {
|
|
248
246
|
value: string;
|
|
247
|
+
}, {
|
|
249
248
|
type: "shadow-css";
|
|
249
|
+
value: string;
|
|
250
250
|
}>, z.ZodObject<{
|
|
251
251
|
type: z.ZodLiteral<"ref">;
|
|
252
252
|
el: z.ZodAny;
|
|
@@ -296,15 +296,15 @@ export declare const HighlightStepZ: z.ZodObject<{
|
|
|
296
296
|
key: string;
|
|
297
297
|
value?: string | undefined;
|
|
298
298
|
} | {
|
|
299
|
-
value: string;
|
|
300
299
|
type: "css";
|
|
300
|
+
value: string;
|
|
301
301
|
} | {
|
|
302
302
|
type: "aria";
|
|
303
303
|
label?: string | undefined;
|
|
304
304
|
role?: string | undefined;
|
|
305
305
|
} | {
|
|
306
|
-
value: string;
|
|
307
306
|
type: "shadow-css";
|
|
307
|
+
value: string;
|
|
308
308
|
} | {
|
|
309
309
|
type: "ref";
|
|
310
310
|
el?: any;
|
|
@@ -332,15 +332,15 @@ export declare const HighlightStepZ: z.ZodObject<{
|
|
|
332
332
|
key: string;
|
|
333
333
|
value?: string | undefined;
|
|
334
334
|
} | {
|
|
335
|
-
value: string;
|
|
336
335
|
type: "css";
|
|
336
|
+
value: string;
|
|
337
337
|
} | {
|
|
338
338
|
type: "aria";
|
|
339
339
|
label?: string | undefined;
|
|
340
340
|
role?: string | undefined;
|
|
341
341
|
} | {
|
|
342
|
-
value: string;
|
|
343
342
|
type: "shadow-css";
|
|
343
|
+
value: string;
|
|
344
344
|
} | {
|
|
345
345
|
type: "ref";
|
|
346
346
|
el?: any;
|
|
@@ -386,11 +386,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
386
386
|
type: z.ZodLiteral<"css">;
|
|
387
387
|
value: z.ZodString;
|
|
388
388
|
}, "strip", z.ZodTypeAny, {
|
|
389
|
-
value: string;
|
|
390
389
|
type: "css";
|
|
391
|
-
}, {
|
|
392
390
|
value: string;
|
|
391
|
+
}, {
|
|
393
392
|
type: "css";
|
|
393
|
+
value: string;
|
|
394
394
|
}>, z.ZodObject<{
|
|
395
395
|
type: z.ZodLiteral<"aria">;
|
|
396
396
|
role: z.ZodOptional<z.ZodString>;
|
|
@@ -407,11 +407,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
407
407
|
type: z.ZodLiteral<"shadow-css">;
|
|
408
408
|
value: z.ZodString;
|
|
409
409
|
}, "strip", z.ZodTypeAny, {
|
|
410
|
-
value: string;
|
|
411
410
|
type: "shadow-css";
|
|
412
|
-
}, {
|
|
413
411
|
value: string;
|
|
412
|
+
}, {
|
|
414
413
|
type: "shadow-css";
|
|
414
|
+
value: string;
|
|
415
415
|
}>, z.ZodObject<{
|
|
416
416
|
type: z.ZodLiteral<"ref">;
|
|
417
417
|
el: z.ZodAny;
|
|
@@ -455,15 +455,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
455
455
|
key: string;
|
|
456
456
|
value?: string | undefined;
|
|
457
457
|
} | {
|
|
458
|
-
value: string;
|
|
459
458
|
type: "css";
|
|
459
|
+
value: string;
|
|
460
460
|
} | {
|
|
461
461
|
type: "aria";
|
|
462
462
|
label?: string | undefined;
|
|
463
463
|
role?: string | undefined;
|
|
464
464
|
} | {
|
|
465
|
-
value: string;
|
|
466
465
|
type: "shadow-css";
|
|
466
|
+
value: string;
|
|
467
467
|
} | {
|
|
468
468
|
type: "ref";
|
|
469
469
|
el?: any;
|
|
@@ -489,15 +489,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
489
489
|
key: string;
|
|
490
490
|
value?: string | undefined;
|
|
491
491
|
} | {
|
|
492
|
-
value: string;
|
|
493
492
|
type: "css";
|
|
493
|
+
value: string;
|
|
494
494
|
} | {
|
|
495
495
|
type: "aria";
|
|
496
496
|
label?: string | undefined;
|
|
497
497
|
role?: string | undefined;
|
|
498
498
|
} | {
|
|
499
|
-
value: string;
|
|
500
499
|
type: "shadow-css";
|
|
500
|
+
value: string;
|
|
501
501
|
} | {
|
|
502
502
|
type: "ref";
|
|
503
503
|
el?: any;
|
|
@@ -536,11 +536,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
536
536
|
type: z.ZodLiteral<"css">;
|
|
537
537
|
value: z.ZodString;
|
|
538
538
|
}, "strip", z.ZodTypeAny, {
|
|
539
|
-
value: string;
|
|
540
539
|
type: "css";
|
|
541
|
-
}, {
|
|
542
540
|
value: string;
|
|
541
|
+
}, {
|
|
543
542
|
type: "css";
|
|
543
|
+
value: string;
|
|
544
544
|
}>, z.ZodObject<{
|
|
545
545
|
type: z.ZodLiteral<"aria">;
|
|
546
546
|
role: z.ZodOptional<z.ZodString>;
|
|
@@ -557,11 +557,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
557
557
|
type: z.ZodLiteral<"shadow-css">;
|
|
558
558
|
value: z.ZodString;
|
|
559
559
|
}, "strip", z.ZodTypeAny, {
|
|
560
|
-
value: string;
|
|
561
560
|
type: "shadow-css";
|
|
562
|
-
}, {
|
|
563
561
|
value: string;
|
|
562
|
+
}, {
|
|
564
563
|
type: "shadow-css";
|
|
564
|
+
value: string;
|
|
565
565
|
}>, z.ZodObject<{
|
|
566
566
|
type: z.ZodLiteral<"ref">;
|
|
567
567
|
el: z.ZodAny;
|
|
@@ -611,15 +611,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
611
611
|
key: string;
|
|
612
612
|
value?: string | undefined;
|
|
613
613
|
} | {
|
|
614
|
-
value: string;
|
|
615
614
|
type: "css";
|
|
615
|
+
value: string;
|
|
616
616
|
} | {
|
|
617
617
|
type: "aria";
|
|
618
618
|
label?: string | undefined;
|
|
619
619
|
role?: string | undefined;
|
|
620
620
|
} | {
|
|
621
|
-
value: string;
|
|
622
621
|
type: "shadow-css";
|
|
622
|
+
value: string;
|
|
623
623
|
} | {
|
|
624
624
|
type: "ref";
|
|
625
625
|
el?: any;
|
|
@@ -647,15 +647,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
647
647
|
key: string;
|
|
648
648
|
value?: string | undefined;
|
|
649
649
|
} | {
|
|
650
|
-
value: string;
|
|
651
650
|
type: "css";
|
|
651
|
+
value: string;
|
|
652
652
|
} | {
|
|
653
653
|
type: "aria";
|
|
654
654
|
label?: string | undefined;
|
|
655
655
|
role?: string | undefined;
|
|
656
656
|
} | {
|
|
657
|
-
value: string;
|
|
658
657
|
type: "shadow-css";
|
|
658
|
+
value: string;
|
|
659
659
|
} | {
|
|
660
660
|
type: "ref";
|
|
661
661
|
el?: any;
|
|
@@ -685,15 +685,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
685
685
|
key: string;
|
|
686
686
|
value?: string | undefined;
|
|
687
687
|
} | {
|
|
688
|
-
value: string;
|
|
689
688
|
type: "css";
|
|
689
|
+
value: string;
|
|
690
690
|
} | {
|
|
691
691
|
type: "aria";
|
|
692
692
|
label?: string | undefined;
|
|
693
693
|
role?: string | undefined;
|
|
694
694
|
} | {
|
|
695
|
-
value: string;
|
|
696
695
|
type: "shadow-css";
|
|
696
|
+
value: string;
|
|
697
697
|
} | {
|
|
698
698
|
type: "ref";
|
|
699
699
|
el?: any;
|
|
@@ -719,15 +719,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
719
719
|
key: string;
|
|
720
720
|
value?: string | undefined;
|
|
721
721
|
} | {
|
|
722
|
-
value: string;
|
|
723
722
|
type: "css";
|
|
723
|
+
value: string;
|
|
724
724
|
} | {
|
|
725
725
|
type: "aria";
|
|
726
726
|
label?: string | undefined;
|
|
727
727
|
role?: string | undefined;
|
|
728
728
|
} | {
|
|
729
|
-
value: string;
|
|
730
729
|
type: "shadow-css";
|
|
730
|
+
value: string;
|
|
731
731
|
} | {
|
|
732
732
|
type: "ref";
|
|
733
733
|
el?: any;
|
|
@@ -760,15 +760,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
760
760
|
key: string;
|
|
761
761
|
value?: string | undefined;
|
|
762
762
|
} | {
|
|
763
|
-
value: string;
|
|
764
763
|
type: "css";
|
|
764
|
+
value: string;
|
|
765
765
|
} | {
|
|
766
766
|
type: "aria";
|
|
767
767
|
label?: string | undefined;
|
|
768
768
|
role?: string | undefined;
|
|
769
769
|
} | {
|
|
770
|
-
value: string;
|
|
771
770
|
type: "shadow-css";
|
|
771
|
+
value: string;
|
|
772
772
|
} | {
|
|
773
773
|
type: "ref";
|
|
774
774
|
el?: any;
|
|
@@ -794,15 +794,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
|
|
|
794
794
|
key: string;
|
|
795
795
|
value?: string | undefined;
|
|
796
796
|
} | {
|
|
797
|
-
value: string;
|
|
798
797
|
type: "css";
|
|
798
|
+
value: string;
|
|
799
799
|
} | {
|
|
800
800
|
type: "aria";
|
|
801
801
|
label?: string | undefined;
|
|
802
802
|
role?: string | undefined;
|
|
803
803
|
} | {
|
|
804
|
-
value: string;
|
|
805
804
|
type: "shadow-css";
|
|
805
|
+
value: string;
|
|
806
806
|
} | {
|
|
807
807
|
type: "ref";
|
|
808
808
|
el?: any;
|
|
@@ -836,15 +836,15 @@ export declare function validateRecipe(json: unknown): {
|
|
|
836
836
|
key: string;
|
|
837
837
|
value?: string | undefined;
|
|
838
838
|
} | {
|
|
839
|
-
value: string;
|
|
840
839
|
type: "css";
|
|
840
|
+
value: string;
|
|
841
841
|
} | {
|
|
842
842
|
type: "aria";
|
|
843
843
|
label?: string | undefined;
|
|
844
844
|
role?: string | undefined;
|
|
845
845
|
} | {
|
|
846
|
-
value: string;
|
|
847
846
|
type: "shadow-css";
|
|
847
|
+
value: string;
|
|
848
848
|
} | {
|
|
849
849
|
type: "ref";
|
|
850
850
|
el?: any;
|
|
@@ -870,15 +870,15 @@ export declare function validateRecipe(json: unknown): {
|
|
|
870
870
|
key: string;
|
|
871
871
|
value?: string | undefined;
|
|
872
872
|
} | {
|
|
873
|
-
value: string;
|
|
874
873
|
type: "css";
|
|
874
|
+
value: string;
|
|
875
875
|
} | {
|
|
876
876
|
type: "aria";
|
|
877
877
|
label?: string | undefined;
|
|
878
878
|
role?: string | undefined;
|
|
879
879
|
} | {
|
|
880
|
-
value: string;
|
|
881
880
|
type: "shadow-css";
|
|
881
|
+
value: string;
|
|
882
882
|
} | {
|
|
883
883
|
type: "ref";
|
|
884
884
|
el?: any;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SmartCanvasRuntime - Unified runtime for v2 adaptives.
|
|
3
|
+
*
|
|
4
|
+
* The runtime provides access to all core providers:
|
|
5
|
+
* - telemetry: Event tracking (PostHog)
|
|
6
|
+
* - context: Page/session/viewport state
|
|
7
|
+
* - events: Normalized event stream
|
|
8
|
+
* - state: Persistent state storage
|
|
9
|
+
*
|
|
10
|
+
* Note: ExperimentClient (GrowthBook) is NOT part of the runtime.
|
|
11
|
+
* GrowthBook's job is done at page load when it selects which config to deliver.
|
|
12
|
+
* The runtime receives the config and makes decisions using DecisionStrategy.
|
|
13
|
+
*/
|
|
14
|
+
import type { TelemetryClient } from "./telemetry/types";
|
|
15
|
+
import { ContextManager } from "./context/ContextManager";
|
|
16
|
+
import { EventBus } from "./events/EventBus";
|
|
17
|
+
import { StateStore } from "./state/StateStore";
|
|
18
|
+
import type { DecisionStrategy, DecisionResult } from "./decisions/types";
|
|
19
|
+
import type { SessionMetricTracker } from "./metrics/sessionMetrics";
|
|
20
|
+
import type { RoutesConfig, TileConfig } from "./types";
|
|
21
|
+
/**
|
|
22
|
+
* Runtime version.
|
|
23
|
+
*/
|
|
24
|
+
export declare const RUNTIME_VERSION = "2.0.0";
|
|
25
|
+
/**
|
|
26
|
+
* Runtime mode.
|
|
27
|
+
*/
|
|
28
|
+
export type RuntimeMode = "production" | "development" | "editor" | "audit";
|
|
29
|
+
/**
|
|
30
|
+
* SmartCanvasRuntime interface.
|
|
31
|
+
*/
|
|
32
|
+
export interface SmartCanvasRuntime {
|
|
33
|
+
/** Telemetry client for event tracking */
|
|
34
|
+
telemetry?: TelemetryClient;
|
|
35
|
+
/** Context manager for page/session/viewport state */
|
|
36
|
+
context: ContextManager;
|
|
37
|
+
/** Event bus for normalized event stream */
|
|
38
|
+
events: EventBus;
|
|
39
|
+
/** State store for persistent state */
|
|
40
|
+
state: StateStore;
|
|
41
|
+
/** Session metric tracker (optional) */
|
|
42
|
+
sessionMetrics?: SessionMetricTracker;
|
|
43
|
+
/** Runtime version */
|
|
44
|
+
version: string;
|
|
45
|
+
/** Runtime mode */
|
|
46
|
+
mode: RuntimeMode;
|
|
47
|
+
/**
|
|
48
|
+
* Evaluate a decision strategy against the current context.
|
|
49
|
+
*/
|
|
50
|
+
evaluate<T>(strategy: DecisionStrategy<T>): Promise<DecisionResult<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Synchronously evaluate a decision strategy (for simple strategies).
|
|
53
|
+
*/
|
|
54
|
+
evaluateSync<T>(strategy: DecisionStrategy<T>): DecisionResult<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Filter tiles based on their activation configs.
|
|
57
|
+
*/
|
|
58
|
+
filterTiles(tiles: TileConfig[]): Promise<TileConfig[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Update the routes config (e.g., when config is fetched).
|
|
61
|
+
*/
|
|
62
|
+
setRoutes(routes: RoutesConfig): void;
|
|
63
|
+
/**
|
|
64
|
+
* Clean up runtime resources.
|
|
65
|
+
*/
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Options for creating a SmartCanvasRuntime.
|
|
70
|
+
*/
|
|
71
|
+
export interface SmartCanvasRuntimeOptions {
|
|
72
|
+
/** Telemetry client */
|
|
73
|
+
telemetry?: TelemetryClient;
|
|
74
|
+
/** Session metric tracker */
|
|
75
|
+
sessionMetrics?: SessionMetricTracker;
|
|
76
|
+
/** Initial routes config */
|
|
77
|
+
routes?: RoutesConfig;
|
|
78
|
+
/** Runtime mode */
|
|
79
|
+
mode?: RuntimeMode;
|
|
80
|
+
/** State namespace */
|
|
81
|
+
namespace?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a SmartCanvasRuntime instance.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createSmartCanvasRuntime(options?: SmartCanvasRuntimeOptions): SmartCanvasRuntime;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createContextManager } from "./context/ContextManager";
|
|
2
|
+
import { createEventBus } from "./events/EventBus";
|
|
3
|
+
import { createStateStore } from "./state/StateStore";
|
|
4
|
+
import { createDecisionEngine } from "./decisions/engine";
|
|
5
|
+
/**
|
|
6
|
+
* Runtime version.
|
|
7
|
+
*/
|
|
8
|
+
export const RUNTIME_VERSION = "2.0.0";
|
|
9
|
+
/**
|
|
10
|
+
* Check if a URL matches a route filter.
|
|
11
|
+
*/
|
|
12
|
+
function matchesRouteFilter(url, filter) {
|
|
13
|
+
if (!filter)
|
|
14
|
+
return true;
|
|
15
|
+
// Extract pathname
|
|
16
|
+
let pathname;
|
|
17
|
+
try {
|
|
18
|
+
pathname = new URL(url).pathname;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
pathname = url;
|
|
22
|
+
}
|
|
23
|
+
// Normalize pathname
|
|
24
|
+
const normalizedPath = pathname.replace(/\/$/, "") || "/";
|
|
25
|
+
// Check exclude patterns first
|
|
26
|
+
if (filter.exclude) {
|
|
27
|
+
for (const pattern of filter.exclude) {
|
|
28
|
+
if (matchRoutePattern(normalizedPath, pattern)) {
|
|
29
|
+
return false; // Explicitly excluded
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// If include list exists, must match at least one
|
|
34
|
+
if (filter.include && filter.include.length > 0) {
|
|
35
|
+
for (const pattern of filter.include) {
|
|
36
|
+
if (matchRoutePattern(normalizedPath, pattern)) {
|
|
37
|
+
return true; // Matches include list
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false; // Didn't match any include pattern
|
|
41
|
+
}
|
|
42
|
+
// No include list, not excluded = pass
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Match a pathname against a route pattern.
|
|
47
|
+
*/
|
|
48
|
+
function matchRoutePattern(pathname, pattern) {
|
|
49
|
+
const normalizedPattern = pattern.replace(/\/$/, "") || "/";
|
|
50
|
+
// Exact match
|
|
51
|
+
if (pathname === normalizedPattern)
|
|
52
|
+
return true;
|
|
53
|
+
// Convert pattern to regex
|
|
54
|
+
const regexPattern = normalizedPattern
|
|
55
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape regex chars
|
|
56
|
+
.replace(/\*\*/g, ".*") // ** matches anything
|
|
57
|
+
.replace(/\*/g, "[^/]*") // * matches within path segment
|
|
58
|
+
.replace(/:[^/]+/g, "[^/]+"); // :param matches any segment
|
|
59
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
60
|
+
return regex.test(pathname);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a SmartCanvasRuntime instance.
|
|
64
|
+
*/
|
|
65
|
+
export function createSmartCanvasRuntime(options = {}) {
|
|
66
|
+
const { telemetry, sessionMetrics, routes, mode = "production", namespace } = options;
|
|
67
|
+
// Create core providers
|
|
68
|
+
const context = createContextManager({
|
|
69
|
+
telemetry,
|
|
70
|
+
routes,
|
|
71
|
+
});
|
|
72
|
+
const events = createEventBus();
|
|
73
|
+
const state = createStateStore({
|
|
74
|
+
namespace,
|
|
75
|
+
});
|
|
76
|
+
// Create decision engine with bound options
|
|
77
|
+
const decisionEngine = createDecisionEngine({
|
|
78
|
+
state,
|
|
79
|
+
events,
|
|
80
|
+
sessionMetrics,
|
|
81
|
+
});
|
|
82
|
+
const runtime = {
|
|
83
|
+
telemetry,
|
|
84
|
+
context,
|
|
85
|
+
events,
|
|
86
|
+
state,
|
|
87
|
+
sessionMetrics,
|
|
88
|
+
version: RUNTIME_VERSION,
|
|
89
|
+
mode,
|
|
90
|
+
async evaluate(strategy) {
|
|
91
|
+
return decisionEngine.evaluate(strategy, context.get());
|
|
92
|
+
},
|
|
93
|
+
evaluateSync(strategy) {
|
|
94
|
+
return decisionEngine.evaluateSync(strategy, context.get());
|
|
95
|
+
},
|
|
96
|
+
async filterTiles(tiles) {
|
|
97
|
+
const currentUrl = context.get().page.url;
|
|
98
|
+
const results = [];
|
|
99
|
+
for (const tile of tiles) {
|
|
100
|
+
const activation = tile.activation;
|
|
101
|
+
// If no activation config, tile always renders
|
|
102
|
+
if (!activation) {
|
|
103
|
+
results.push(tile);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Check route filter first
|
|
107
|
+
if (!matchesRouteFilter(currentUrl, activation.routes)) {
|
|
108
|
+
continue; // Doesn't match route filter
|
|
109
|
+
}
|
|
110
|
+
// If no strategy, tile renders (route filter passed)
|
|
111
|
+
if (!activation.strategy) {
|
|
112
|
+
results.push(tile);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// Evaluate strategy
|
|
116
|
+
const result = await this.evaluate(activation.strategy);
|
|
117
|
+
if (result.value) {
|
|
118
|
+
results.push(tile);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return results;
|
|
122
|
+
},
|
|
123
|
+
setRoutes(routes) {
|
|
124
|
+
context.setRoutes(routes);
|
|
125
|
+
},
|
|
126
|
+
destroy() {
|
|
127
|
+
context.destroy();
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return runtime;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAcA,OAAO,EAAkB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,EAAY,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAc,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK1D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AA8EvC;;GAEG;AACH,SAAS,kBAAkB,CAAC,GAAW,EAAE,MAAoB;IAC3D,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,mBAAmB;IACnB,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,QAAQ,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,qBAAqB;IACrB,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;IAE1D,+BAA+B;IAC/B,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,KAAK,MAAM,O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