@syntrologie/runtime-sdk 0.2.0
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/README.md +185 -0
- package/dist/SmartCanvasApp.d.ts +29 -0
- package/dist/SmartCanvasApp.js +68 -0
- package/dist/SmartCanvasApp.js.map +1 -0
- package/dist/SmartCanvasElement.d.ts +29 -0
- package/dist/SmartCanvasElement.js +133 -0
- package/dist/SmartCanvasElement.js.map +1 -0
- package/dist/SmartCanvasPortal.d.ts +7 -0
- package/dist/SmartCanvasPortal.js +17 -0
- package/dist/SmartCanvasPortal.js.map +1 -0
- package/dist/antiFlicker.d.ts +10 -0
- package/dist/antiFlicker.js +39 -0
- package/dist/antiFlicker.js.map +1 -0
- package/dist/api.d.ts +60 -0
- package/dist/api.js +159 -0
- package/dist/api.js.map +1 -0
- package/dist/bootstrap.d.ts +62 -0
- package/dist/bootstrap.js +83 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/bundle-entry.d.ts +4 -0
- package/dist/bundle-entry.js +9 -0
- package/dist/bundle-entry.js.map +1 -0
- package/dist/components/RectangleCard.d.ts +15 -0
- package/dist/components/RectangleCard.js +226 -0
- package/dist/components/RectangleCard.js.map +1 -0
- package/dist/components/RectangleWheel.d.ts +8 -0
- package/dist/components/RectangleWheel.js +30 -0
- package/dist/components/RectangleWheel.js.map +1 -0
- package/dist/components/ShadowCanvasOverlay.d.ts +26 -0
- package/dist/components/ShadowCanvasOverlay.js +163 -0
- package/dist/components/ShadowCanvasOverlay.js.map +1 -0
- package/dist/configFetcher.d.ts +15 -0
- package/dist/configFetcher.js +90 -0
- package/dist/configFetcher.js.map +1 -0
- package/dist/controller.d.ts +15 -0
- package/dist/controller.js +34 -0
- package/dist/controller.js.map +1 -0
- package/dist/earlyPatcher.d.ts +23 -0
- package/dist/earlyPatcher.js +70 -0
- package/dist/earlyPatcher.js.map +1 -0
- package/dist/editorLoader.d.ts +17 -0
- package/dist/editorLoader.js +95 -0
- package/dist/editorLoader.js.map +1 -0
- package/dist/experiments/adapters/growthbook.d.ts +45 -0
- package/dist/experiments/adapters/growthbook.js +79 -0
- package/dist/experiments/adapters/growthbook.js.map +1 -0
- package/dist/experiments/index.d.ts +3 -0
- package/dist/experiments/index.js +4 -0
- package/dist/experiments/index.js.map +1 -0
- package/dist/experiments/registry.d.ts +13 -0
- package/dist/experiments/registry.js +30 -0
- package/dist/experiments/registry.js.map +1 -0
- package/dist/experiments/types.d.ts +25 -0
- package/dist/experiments/types.js +2 -0
- package/dist/experiments/types.js.map +1 -0
- package/dist/fetchers/cdnFetcher.d.ts +35 -0
- package/dist/fetchers/cdnFetcher.js +100 -0
- package/dist/fetchers/cdnFetcher.js.map +1 -0
- package/dist/fetchers/experimentsFetcher.d.ts +33 -0
- package/dist/fetchers/experimentsFetcher.js +42 -0
- package/dist/fetchers/experimentsFetcher.js.map +1 -0
- package/dist/fetchers/index.d.ts +3 -0
- package/dist/fetchers/index.js +5 -0
- package/dist/fetchers/index.js.map +1 -0
- package/dist/fetchers/registry.d.ts +14 -0
- package/dist/fetchers/registry.js +58 -0
- package/dist/fetchers/registry.js.map +1 -0
- package/dist/fetchers/types.d.ts +26 -0
- package/dist/fetchers/types.js +2 -0
- package/dist/fetchers/types.js.map +1 -0
- package/dist/hooks/useCanvasOverlays.d.ts +13 -0
- package/dist/hooks/useCanvasOverlays.js +59 -0
- package/dist/hooks/useCanvasOverlays.js.map +1 -0
- package/dist/hooks/useHostPatches.d.ts +9 -0
- package/dist/hooks/useHostPatches.js +40 -0
- package/dist/hooks/useHostPatches.js.map +1 -0
- package/dist/hooks/useShadowCanvasConfig.d.ts +20 -0
- package/dist/hooks/useShadowCanvasConfig.js +46 -0
- package/dist/hooks/useShadowCanvasConfig.js.map +1 -0
- package/dist/hostPatcher/core/patcher.d.ts +3 -0
- package/dist/hostPatcher/core/patcher.js +173 -0
- package/dist/hostPatcher/core/patcher.js.map +1 -0
- package/dist/hostPatcher/core/sanitizer.d.ts +1 -0
- package/dist/hostPatcher/core/sanitizer.js +45 -0
- package/dist/hostPatcher/core/sanitizer.js.map +1 -0
- package/dist/hostPatcher/core/types.d.ts +94 -0
- package/dist/hostPatcher/core/types.js +2 -0
- package/dist/hostPatcher/core/types.js.map +1 -0
- package/dist/hostPatcher/index.d.ts +6 -0
- package/dist/hostPatcher/index.js +7 -0
- package/dist/hostPatcher/index.js.map +1 -0
- package/dist/hostPatcher/policy/defaultPolicy.d.ts +2 -0
- package/dist/hostPatcher/policy/defaultPolicy.js +41 -0
- package/dist/hostPatcher/policy/defaultPolicy.js.map +1 -0
- package/dist/hostPatcher/utils/anchors.d.ts +13 -0
- package/dist/hostPatcher/utils/anchors.js +107 -0
- package/dist/hostPatcher/utils/anchors.js.map +1 -0
- package/dist/hostPatcher/utils/observer.d.ts +3 -0
- package/dist/hostPatcher/utils/observer.js +11 -0
- package/dist/hostPatcher/utils/observer.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/overlays/fetcher.d.ts +4 -0
- package/dist/overlays/fetcher.js +17 -0
- package/dist/overlays/fetcher.js.map +1 -0
- package/dist/overlays/runtime/anchor/resolve.d.ts +4 -0
- package/dist/overlays/runtime/anchor/resolve.js +87 -0
- package/dist/overlays/runtime/anchor/resolve.js.map +1 -0
- package/dist/overlays/runtime/index.d.ts +6 -0
- package/dist/overlays/runtime/index.js +7 -0
- package/dist/overlays/runtime/index.js.map +1 -0
- package/dist/overlays/runtime/overlay/highlight.d.ts +10 -0
- package/dist/overlays/runtime/overlay/highlight.js +152 -0
- package/dist/overlays/runtime/overlay/highlight.js.map +1 -0
- package/dist/overlays/runtime/overlay/root.d.ts +4 -0
- package/dist/overlays/runtime/overlay/root.js +165 -0
- package/dist/overlays/runtime/overlay/root.js.map +1 -0
- package/dist/overlays/runtime/overlay/runner.d.ts +2 -0
- package/dist/overlays/runtime/overlay/runner.js +101 -0
- package/dist/overlays/runtime/overlay/runner.js.map +1 -0
- package/dist/overlays/runtime/overlay/tooltip.d.ts +14 -0
- package/dist/overlays/runtime/overlay/tooltip.js +174 -0
- package/dist/overlays/runtime/overlay/tooltip.js.map +1 -0
- package/dist/overlays/runtime/utils/dom.d.ts +2 -0
- package/dist/overlays/runtime/utils/dom.js +9 -0
- package/dist/overlays/runtime/utils/dom.js.map +1 -0
- package/dist/overlays/schema.d.ts +907 -0
- package/dist/overlays/schema.js +48 -0
- package/dist/overlays/schema.js.map +1 -0
- package/dist/overlays/types.d.ts +68 -0
- package/dist/overlays/types.js +2 -0
- package/dist/overlays/types.js.map +1 -0
- package/dist/react.d.ts +99 -0
- package/dist/react.js +119 -0
- package/dist/react.js.map +1 -0
- package/dist/smart-canvas.esm.js +202 -0
- package/dist/smart-canvas.esm.js.map +7 -0
- package/dist/smart-canvas.js +40406 -0
- package/dist/smart-canvas.js.map +7 -0
- package/dist/smart-canvas.min.js +202 -0
- package/dist/smart-canvas.min.js.map +7 -0
- package/dist/telemetry/adapters/posthog.d.ts +67 -0
- package/dist/telemetry/adapters/posthog.js +61 -0
- package/dist/telemetry/adapters/posthog.js.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/registry.d.ts +13 -0
- package/dist/telemetry/registry.js +27 -0
- package/dist/telemetry/registry.js.map +1 -0
- package/dist/telemetry/types.d.ts +28 -0
- package/dist/telemetry/types.js +2 -0
- package/dist/telemetry/types.js.map +1 -0
- package/dist/token.d.ts +36 -0
- package/dist/token.js +47 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +147 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +64 -0
- package/schema/canvas-config.schema.json +329 -0
- package/scripts/validate-config.mjs +80 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://syntropyforge.com/schemas/smart-canvas-config.json",
|
|
4
|
+
"title": "Smart Canvas Configuration",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["fetchedAt", "rectangles"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"fetchedAt": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"format": "date-time"
|
|
11
|
+
},
|
|
12
|
+
"configVersion": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"canvasTitle": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"overlayRecipeUri": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "Optional URI pointing to tooltip/highlight recipe"
|
|
21
|
+
},
|
|
22
|
+
"overlayRecipe": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"description": "Inline overlay recipe (for testing)",
|
|
25
|
+
"properties": {
|
|
26
|
+
"id": { "type": "string" },
|
|
27
|
+
"version": { "type": "number" },
|
|
28
|
+
"routes": { "type": "array", "items": { "type": "string" } },
|
|
29
|
+
"steps": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"items": { "oneOf": [
|
|
32
|
+
{ "$ref": "#/$defs/tooltipStep" },
|
|
33
|
+
{ "$ref": "#/$defs/highlightStep" }
|
|
34
|
+
] }
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"required": ["id", "version", "steps"],
|
|
38
|
+
"additionalProperties": false
|
|
39
|
+
},
|
|
40
|
+
"patches": {
|
|
41
|
+
"type": "array",
|
|
42
|
+
"description": "Optional host DOM patches to apply when the canvas renders",
|
|
43
|
+
"items": {
|
|
44
|
+
"$ref": "#/$defs/patch"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"rectangles": {
|
|
48
|
+
"type": "array",
|
|
49
|
+
"items": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"required": ["id", "title", "content"],
|
|
52
|
+
"properties": {
|
|
53
|
+
"id": { "type": "string" },
|
|
54
|
+
"title": { "type": "string" },
|
|
55
|
+
"subtitle": { "type": "string" },
|
|
56
|
+
"icon": { "type": "string" },
|
|
57
|
+
"size": { "type": "string", "enum": ["half", "quarter"] },
|
|
58
|
+
"order": { "type": "number" },
|
|
59
|
+
"style": {
|
|
60
|
+
"type": "object",
|
|
61
|
+
"properties": {
|
|
62
|
+
"background": { "type": "string" },
|
|
63
|
+
"borderColor": { "type": "string" },
|
|
64
|
+
"textColor": { "type": "string" },
|
|
65
|
+
"accentColor": { "type": "string" }
|
|
66
|
+
},
|
|
67
|
+
"additionalProperties": false
|
|
68
|
+
},
|
|
69
|
+
"content": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"required": ["type"],
|
|
72
|
+
"properties": {
|
|
73
|
+
"type": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"enum": ["text", "metric", "chatbot", "embed", "custom"]
|
|
76
|
+
},
|
|
77
|
+
"headline": { "type": "string" },
|
|
78
|
+
"body": { "type": "string" },
|
|
79
|
+
"metricValue": { "type": "string" },
|
|
80
|
+
"metricUnit": { "type": "string" },
|
|
81
|
+
"embedUrl": { "type": "string" },
|
|
82
|
+
"customRendererKey": { "type": "string" },
|
|
83
|
+
"actions": {
|
|
84
|
+
"type": "array",
|
|
85
|
+
"items": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"required": ["label"],
|
|
88
|
+
"properties": {
|
|
89
|
+
"label": { "type": "string" },
|
|
90
|
+
"href": { "type": "string" },
|
|
91
|
+
"onClickId": { "type": "string" }
|
|
92
|
+
},
|
|
93
|
+
"additionalProperties": false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"additionalProperties": false
|
|
98
|
+
},
|
|
99
|
+
"experiment": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"properties": {
|
|
102
|
+
"featureKey": { "type": "string" },
|
|
103
|
+
"variationId": { "type": "number" },
|
|
104
|
+
"variationValue": {},
|
|
105
|
+
"predicate": {}
|
|
106
|
+
},
|
|
107
|
+
"additionalProperties": true
|
|
108
|
+
},
|
|
109
|
+
"analyticsKey": { "type": "string" }
|
|
110
|
+
},
|
|
111
|
+
"additionalProperties": false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"additionalProperties": false,
|
|
116
|
+
"$defs": {
|
|
117
|
+
"anchorSelector": {
|
|
118
|
+
"type": "object",
|
|
119
|
+
"oneOf": [
|
|
120
|
+
{
|
|
121
|
+
"required": ["by", "value"],
|
|
122
|
+
"properties": {
|
|
123
|
+
"by": { "const": "css" },
|
|
124
|
+
"value": { "type": "string" },
|
|
125
|
+
"within": { "enum": ["document", "shadow"] }
|
|
126
|
+
},
|
|
127
|
+
"additionalProperties": false
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"required": ["by", "key"],
|
|
131
|
+
"properties": {
|
|
132
|
+
"by": { "const": "data" },
|
|
133
|
+
"key": { "type": "string" },
|
|
134
|
+
"value": { "type": "string" },
|
|
135
|
+
"within": { "enum": ["document", "shadow"] }
|
|
136
|
+
},
|
|
137
|
+
"additionalProperties": false
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"required": ["by"],
|
|
141
|
+
"properties": {
|
|
142
|
+
"by": { "const": "aria" },
|
|
143
|
+
"role": { "type": "string" },
|
|
144
|
+
"label": { "type": "string" },
|
|
145
|
+
"within": { "enum": ["document", "shadow"] }
|
|
146
|
+
},
|
|
147
|
+
"additionalProperties": false
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"required": ["by", "el"],
|
|
151
|
+
"properties": {
|
|
152
|
+
"by": { "const": "ref" },
|
|
153
|
+
"el": {}
|
|
154
|
+
},
|
|
155
|
+
"additionalProperties": false
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"operation": {
|
|
160
|
+
"oneOf": [
|
|
161
|
+
{
|
|
162
|
+
"type": "object",
|
|
163
|
+
"required": ["kind"],
|
|
164
|
+
"properties": {
|
|
165
|
+
"kind": { "const": "append" },
|
|
166
|
+
"html": { "type": "string" },
|
|
167
|
+
"position": { "type": "string" }
|
|
168
|
+
},
|
|
169
|
+
"additionalProperties": false
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"type": "object",
|
|
173
|
+
"required": ["kind"],
|
|
174
|
+
"properties": {
|
|
175
|
+
"kind": { "const": "prepend" },
|
|
176
|
+
"html": { "type": "string" }
|
|
177
|
+
},
|
|
178
|
+
"additionalProperties": false
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"type": "object",
|
|
182
|
+
"required": ["kind", "where"],
|
|
183
|
+
"properties": {
|
|
184
|
+
"kind": { "const": "insertAdjacent" },
|
|
185
|
+
"where": {
|
|
186
|
+
"enum": ["beforebegin", "afterbegin", "beforeend", "afterend"]
|
|
187
|
+
},
|
|
188
|
+
"html": { "type": "string" }
|
|
189
|
+
},
|
|
190
|
+
"additionalProperties": false
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"type": "object",
|
|
194
|
+
"required": ["kind", "className"],
|
|
195
|
+
"properties": {
|
|
196
|
+
"kind": { "enum": ["addClass", "removeClass"] },
|
|
197
|
+
"className": { "type": "string" }
|
|
198
|
+
},
|
|
199
|
+
"additionalProperties": false
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"type": "object",
|
|
203
|
+
"required": ["kind", "name"],
|
|
204
|
+
"properties": {
|
|
205
|
+
"kind": { "const": "setAttr" },
|
|
206
|
+
"name": { "type": "string" },
|
|
207
|
+
"value": { "type": ["string", "null"] }
|
|
208
|
+
},
|
|
209
|
+
"additionalProperties": false
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"type": "object",
|
|
213
|
+
"required": ["kind", "prop"],
|
|
214
|
+
"properties": {
|
|
215
|
+
"kind": { "const": "setStyle" },
|
|
216
|
+
"prop": { "type": "string" },
|
|
217
|
+
"value": { "type": ["string", "null"] },
|
|
218
|
+
"important": { "type": "boolean" }
|
|
219
|
+
},
|
|
220
|
+
"additionalProperties": false
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"type": "object",
|
|
224
|
+
"required": ["kind", "text"],
|
|
225
|
+
"properties": {
|
|
226
|
+
"kind": { "const": "setText" },
|
|
227
|
+
"text": { "type": "string" }
|
|
228
|
+
},
|
|
229
|
+
"additionalProperties": false
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"patch": {
|
|
234
|
+
"type": "object",
|
|
235
|
+
"required": ["id", "anchor", "operations"],
|
|
236
|
+
"properties": {
|
|
237
|
+
"id": { "type": "string" },
|
|
238
|
+
"anchor": { "$ref": "#/$defs/anchorSelector" },
|
|
239
|
+
"tier": { "enum": ["additive", "moderate", "surgical"] },
|
|
240
|
+
"operations": {
|
|
241
|
+
"type": "array",
|
|
242
|
+
"items": { "$ref": "#/$defs/operation" }
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
"additionalProperties": false
|
|
246
|
+
},
|
|
247
|
+
"tooltipStep": {
|
|
248
|
+
"type": "object",
|
|
249
|
+
"required": ["kind", "id", "anchor", "content"],
|
|
250
|
+
"properties": {
|
|
251
|
+
"kind": { "const": "tooltip" },
|
|
252
|
+
"id": { "type": "string" },
|
|
253
|
+
"anchor": { "$ref": "#/$defs/anchorSelector" },
|
|
254
|
+
"content": {
|
|
255
|
+
"type": "object",
|
|
256
|
+
"properties": {
|
|
257
|
+
"title": { "type": "string" },
|
|
258
|
+
"body": { "type": "string" }
|
|
259
|
+
},
|
|
260
|
+
"required": ["body"],
|
|
261
|
+
"additionalProperties": false
|
|
262
|
+
},
|
|
263
|
+
"placement": { "enum": ["top","bottom","left","right","auto"] },
|
|
264
|
+
"offsetPx": { "type": "number" },
|
|
265
|
+
"blocking": { "type": "boolean" },
|
|
266
|
+
"trigger": { "enum": ["immediate","hover","click"] },
|
|
267
|
+
"ctaButtons": {
|
|
268
|
+
"type": "array",
|
|
269
|
+
"items": {
|
|
270
|
+
"type": "object",
|
|
271
|
+
"properties": {
|
|
272
|
+
"label": { "type": "string" },
|
|
273
|
+
"actionId": { "type": "string" }
|
|
274
|
+
},
|
|
275
|
+
"required": ["label","actionId"],
|
|
276
|
+
"additionalProperties": false
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
"dismiss": {
|
|
280
|
+
"type": "object",
|
|
281
|
+
"properties": {
|
|
282
|
+
"onEsc": { "type": "boolean" },
|
|
283
|
+
"closeButton": { "type": "boolean" },
|
|
284
|
+
"timeoutMs": { "type": "number" }
|
|
285
|
+
},
|
|
286
|
+
"additionalProperties": false
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
"additionalProperties": false
|
|
290
|
+
},
|
|
291
|
+
"highlightStep": {
|
|
292
|
+
"type": "object",
|
|
293
|
+
"required": ["kind", "id", "anchor"],
|
|
294
|
+
"properties": {
|
|
295
|
+
"kind": { "const": "highlight" },
|
|
296
|
+
"id": { "type": "string" },
|
|
297
|
+
"anchor": { "$ref": "#/$defs/anchorSelector" },
|
|
298
|
+
"copy": { "type": "string" },
|
|
299
|
+
"ring": {
|
|
300
|
+
"type": "object",
|
|
301
|
+
"properties": {
|
|
302
|
+
"paddingPx": { "type": "number" },
|
|
303
|
+
"radiusPx": { "type": "number" }
|
|
304
|
+
},
|
|
305
|
+
"additionalProperties": false
|
|
306
|
+
},
|
|
307
|
+
"scrim": {
|
|
308
|
+
"type": "object",
|
|
309
|
+
"properties": {
|
|
310
|
+
"opacity": { "type": "number" }
|
|
311
|
+
},
|
|
312
|
+
"additionalProperties": false
|
|
313
|
+
},
|
|
314
|
+
"ringColor": { "type": "string" },
|
|
315
|
+
"blocking": { "type": "boolean" },
|
|
316
|
+
"dismiss": {
|
|
317
|
+
"type": "object",
|
|
318
|
+
"properties": {
|
|
319
|
+
"onClickOutside": { "type": "boolean" },
|
|
320
|
+
"onEsc": { "type": "boolean" },
|
|
321
|
+
"timeoutMs": { "type": "number" }
|
|
322
|
+
},
|
|
323
|
+
"additionalProperties": false
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
"additionalProperties": false
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import url from "url";
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
7
|
+
const schemaPath = path.resolve(__dirname, "../schema/canvas-config.schema.json");
|
|
8
|
+
|
|
9
|
+
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf-8"));
|
|
10
|
+
|
|
11
|
+
const usage = () => {
|
|
12
|
+
console.error("Usage: npm run validate-config -- <path/to/config.json>");
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const targetPath = process.argv[2];
|
|
16
|
+
if (!targetPath) {
|
|
17
|
+
usage();
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const configPath = path.resolve(process.cwd(), targetPath);
|
|
22
|
+
|
|
23
|
+
const loadJson = (file) => JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
24
|
+
|
|
25
|
+
const errors = [];
|
|
26
|
+
|
|
27
|
+
const validateSchema = (schemaNode, value, pointer = "$") => {
|
|
28
|
+
if (schemaNode.type) {
|
|
29
|
+
const types = Array.isArray(schemaNode.type) ? schemaNode.type : [schemaNode.type];
|
|
30
|
+
const matches = types.some((t) => typeof value === t || (t === "array" && Array.isArray(value)) || (t === "object" && value && typeof value === "object" && !Array.isArray(value)));
|
|
31
|
+
if (!matches) {
|
|
32
|
+
errors.push(`${pointer}: expected ${schemaNode.type}, received ${Array.isArray(value) ? "array" : typeof value}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (schemaNode.enum && !schemaNode.enum.includes(value)) {
|
|
38
|
+
errors.push(`${pointer}: value must be one of ${schemaNode.enum.join(", ")}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (schemaNode.required && typeof value === "object" && !Array.isArray(value)) {
|
|
42
|
+
for (const key of schemaNode.required) {
|
|
43
|
+
if (!(key in value)) {
|
|
44
|
+
errors.push(`${pointer}: missing required property "${key}"`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (schemaNode.properties && typeof value === "object" && value) {
|
|
50
|
+
for (const [key, subSchema] of Object.entries(schemaNode.properties)) {
|
|
51
|
+
if (key in value) {
|
|
52
|
+
validateSchema(subSchema, value[key], `${pointer}.${key}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (schemaNode.items && Array.isArray(value)) {
|
|
58
|
+
value.forEach((item, idx) => validateSchema(schemaNode.items, item, `${pointer}[${idx}]`));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
let data;
|
|
63
|
+
try {
|
|
64
|
+
data = loadJson(configPath);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(`Failed to read ${configPath}:`, err.message);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
validateSchema(schema, data);
|
|
71
|
+
|
|
72
|
+
if (errors.length) {
|
|
73
|
+
console.error(`❌ Config invalid (${errors.length} issues):`);
|
|
74
|
+
for (const err of errors) {
|
|
75
|
+
console.error(` - ${err}`);
|
|
76
|
+
}
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`✅ ${path.relative(process.cwd(), configPath)} is valid.`);
|