@syntrologie/adapt-gamification 2.4.1 → 2.5.1

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.
@@ -1,142 +0,0 @@
1
- /**
2
- * Shared Zod schemas for decision strategies, conditions, and event scoping.
3
- *
4
- * These are the canonical definitions — runtime-sdk and all adaptive packages
5
- * should import from here instead of duplicating.
6
- */
7
- import { z } from 'zod';
8
- // =============================================================================
9
- // CONDITION SCHEMAS
10
- // =============================================================================
11
- export const PageUrlConditionZ = z.object({
12
- type: z.literal('page_url'),
13
- url: z.string(),
14
- });
15
- export const RouteConditionZ = z.object({
16
- type: z.literal('route'),
17
- routeId: z.string(),
18
- });
19
- export const AnchorVisibleConditionZ = z.object({
20
- type: z.literal('anchor_visible'),
21
- anchorId: z.string(),
22
- state: z.enum(['visible', 'present', 'absent']),
23
- });
24
- export const EventOccurredConditionZ = z.object({
25
- type: z.literal('event_occurred'),
26
- eventName: z.string(),
27
- withinMs: z.number().optional(),
28
- });
29
- export const StateEqualsConditionZ = z.object({
30
- type: z.literal('state_equals'),
31
- key: z.string(),
32
- value: z.unknown(),
33
- });
34
- export const ViewportConditionZ = z.object({
35
- type: z.literal('viewport'),
36
- minWidth: z.number().optional(),
37
- maxWidth: z.number().optional(),
38
- minHeight: z.number().optional(),
39
- maxHeight: z.number().optional(),
40
- });
41
- export const SessionMetricConditionZ = z.object({
42
- type: z.literal('session_metric'),
43
- key: z.string(),
44
- operator: z.enum(['gte', 'lte', 'eq', 'gt', 'lt']),
45
- threshold: z.number(),
46
- });
47
- export const DismissedConditionZ = z.object({
48
- type: z.literal('dismissed'),
49
- key: z.string(),
50
- inverted: z.boolean().optional(),
51
- });
52
- export const CooldownActiveConditionZ = z.object({
53
- type: z.literal('cooldown_active'),
54
- key: z.string(),
55
- inverted: z.boolean().optional(),
56
- });
57
- export const FrequencyLimitConditionZ = z.object({
58
- type: z.literal('frequency_limit'),
59
- key: z.string(),
60
- limit: z.number(),
61
- inverted: z.boolean().optional(),
62
- });
63
- export const EventCountConditionZ = z.object({
64
- type: z.literal('event_count'),
65
- key: z.string(),
66
- operator: z.enum(['gte', 'lte', 'eq', 'gt', 'lt']),
67
- count: z.number().int().min(0),
68
- withinMs: z.number().positive().optional(),
69
- });
70
- export const ConditionZ = z.discriminatedUnion('type', [
71
- PageUrlConditionZ,
72
- RouteConditionZ,
73
- AnchorVisibleConditionZ,
74
- EventOccurredConditionZ,
75
- StateEqualsConditionZ,
76
- ViewportConditionZ,
77
- SessionMetricConditionZ,
78
- DismissedConditionZ,
79
- CooldownActiveConditionZ,
80
- FrequencyLimitConditionZ,
81
- EventCountConditionZ,
82
- ]);
83
- // =============================================================================
84
- // STRATEGY SCHEMAS
85
- // =============================================================================
86
- export const RuleZ = z.object({
87
- conditions: z.array(ConditionZ),
88
- value: z.unknown(),
89
- });
90
- export const RuleStrategyZ = z.object({
91
- type: z.literal('rules'),
92
- rules: z.array(RuleZ),
93
- default: z.unknown(),
94
- });
95
- export const ScoreStrategyZ = z.object({
96
- type: z.literal('score'),
97
- field: z.string(),
98
- threshold: z.number(),
99
- above: z.unknown(),
100
- below: z.unknown(),
101
- });
102
- export const ModelStrategyZ = z.object({
103
- type: z.literal('model'),
104
- modelId: z.string(),
105
- inputs: z.array(z.string()),
106
- outputMapping: z.record(z.string(), z.unknown()),
107
- default: z.unknown(),
108
- });
109
- export const ExternalStrategyZ = z.object({
110
- type: z.literal('external'),
111
- endpoint: z.string(),
112
- method: z.enum(['GET', 'POST']).optional(),
113
- default: z.unknown(),
114
- timeoutMs: z.number().optional(),
115
- });
116
- export const DecisionStrategyZ = z.discriminatedUnion('type', [
117
- RuleStrategyZ,
118
- ScoreStrategyZ,
119
- ModelStrategyZ,
120
- ExternalStrategyZ,
121
- ]);
122
- // =============================================================================
123
- // EVENT SCOPE SCHEMA
124
- // =============================================================================
125
- /** Scopes a widget to specific events/URLs. */
126
- export const EventScopeZ = z.object({
127
- events: z.array(z.string()),
128
- urlContains: z.string().optional(),
129
- props: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
130
- });
131
- // =============================================================================
132
- // NOTIFY SCHEMA
133
- // =============================================================================
134
- /** Toast notification config for showWhen transitions. */
135
- export const NotifyZ = z
136
- .object({
137
- title: z.string().optional(),
138
- body: z.string().optional(),
139
- icon: z.string().optional(),
140
- })
141
- .nullable()
142
- .optional();
@@ -1,33 +0,0 @@
1
- {
2
- "name": "@syntrologie/sdk-contracts",
3
- "version": "0.0.0-semantically-released",
4
- "description": "Shared TypeScript contracts between runtime-sdk and adaptive packages",
5
- "license": "Proprietary",
6
- "private": true,
7
- "type": "module",
8
- "main": "dist/index.js",
9
- "types": "dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js"
14
- },
15
- "./schemas": {
16
- "types": "./dist/schemas.d.ts",
17
- "import": "./dist/schemas.js"
18
- }
19
- },
20
- "files": [
21
- "dist"
22
- ],
23
- "scripts": {
24
- "build": "tsc",
25
- "typecheck": "tsc --noEmit"
26
- },
27
- "dependencies": {
28
- "zod": "^3.25.76"
29
- },
30
- "devDependencies": {
31
- "typescript": "^5.9.3"
32
- }
33
- }