@trojanbox-vcp-test/contracts 0.1.0 → 0.2.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,49 +0,0 @@
1
- import { z } from "zod";
2
- export const SiteEditBoundaryKindSchema = z.enum([
3
- "component-boundary",
4
- "repeat-region",
5
- "conditional-region",
6
- "fragment-region",
7
- "opaque-region",
8
- ]);
9
- export const SiteEditCapabilityModeSchema = z.enum([
10
- "direct",
11
- "proxy",
12
- "upstream",
13
- "readonly",
14
- "unsupported",
15
- ]);
16
- export const SiteEditConstraintKindSchema = z.enum([
17
- "component-boundary",
18
- "repeat-region",
19
- "conditional-region",
20
- "opaque-region",
21
- "void-element",
22
- "read-only",
23
- "cross-file-required",
24
- "import-required",
25
- ]);
26
- export const SiteEditCapabilityModeViewSchema = z.object({
27
- mode: SiteEditCapabilityModeSchema,
28
- reasonCode: z.string().min(1).optional(),
29
- });
30
- export const SiteEditCapabilityConstraintSchema = z.object({
31
- kind: SiteEditConstraintKindSchema,
32
- message: z.string().min(1),
33
- });
34
- export const SiteEditNodeCapabilitySnapshotSchema = z.object({
35
- key: z.string().min(1),
36
- canUpdateText: z.boolean(),
37
- canInsertChild: z.boolean(),
38
- canMove: z.boolean(),
39
- canRemove: z.boolean(),
40
- editModes: z
41
- .object({
42
- updateText: SiteEditCapabilityModeViewSchema.optional(),
43
- insertChild: SiteEditCapabilityModeViewSchema.optional(),
44
- move: SiteEditCapabilityModeViewSchema.optional(),
45
- remove: SiteEditCapabilityModeViewSchema.optional(),
46
- })
47
- .optional(),
48
- constraints: z.array(SiteEditCapabilityConstraintSchema),
49
- });
@@ -1,118 +0,0 @@
1
- import { z } from "zod";
2
- export const SiteEditClassNameSourceRangeSchema = z
3
- .object({
4
- start: z.number().int().nonnegative(),
5
- end: z.number().int().nonnegative(),
6
- startLine: z.number().int().positive().optional(),
7
- startColumn: z.number().int().nonnegative().optional(),
8
- endLine: z.number().int().positive().optional(),
9
- endColumn: z.number().int().nonnegative().optional(),
10
- })
11
- .superRefine((value, ctx) => {
12
- if (value.end < value.start) {
13
- ctx.addIssue({
14
- code: "custom",
15
- path: ["end"],
16
- message: "end must be greater than or equal to start",
17
- });
18
- }
19
- });
20
- export const SiteEditClassNameSourceDiagnosticSchema = z.object({
21
- code: z.enum([
22
- "missing-class-name",
23
- "unsupported-attribute-name",
24
- "source-locator-warning",
25
- "invalid-new-attr",
26
- "version-conflict",
27
- "write-failed",
28
- ]),
29
- message: z.string().min(1),
30
- });
31
- export const SiteEditClassNameSourceSchema = z
32
- .object({
33
- key: z.string().min(1),
34
- routeId: z.string().min(1),
35
- filePath: z.string().min(1),
36
- componentName: z.string().min(1),
37
- sourceKind: z.enum(["missing", "stringLiteral", "expression"]),
38
- attrRaw: z.string().min(1).nullable(),
39
- valueRaw: z.string().min(1).nullable(),
40
- attrRange: SiteEditClassNameSourceRangeSchema.nullable(),
41
- valueRange: SiteEditClassNameSourceRangeSchema.nullable(),
42
- openingElementRange: SiteEditClassNameSourceRangeSchema,
43
- version: z.object({
44
- documentVersion: z.number().int().nonnegative(),
45
- contentHash: z.string().min(1),
46
- parserVersion: z.string().min(1),
47
- }),
48
- diagnostics: z.array(SiteEditClassNameSourceDiagnosticSchema),
49
- })
50
- .superRefine((value, ctx) => {
51
- if (value.sourceKind === "missing") {
52
- if (value.attrRaw !== null ||
53
- value.valueRaw !== null ||
54
- value.attrRange !== null ||
55
- value.valueRange !== null) {
56
- ctx.addIssue({
57
- code: "custom",
58
- message: "missing className source must not include attr raw or range",
59
- });
60
- }
61
- return;
62
- }
63
- if (value.attrRaw === null ||
64
- value.valueRaw === null ||
65
- value.attrRange === null ||
66
- value.valueRange === null) {
67
- ctx.addIssue({
68
- code: "custom",
69
- message: "present className source must include attr raw and ranges",
70
- });
71
- }
72
- });
73
- export const SiteEditGetClassNameSourceResultSchema = SiteEditClassNameSourceSchema;
74
- export const SiteEditSetClassNameSourceIntentSchema = z.object({
75
- source: z.enum(["style-panel", "class-source-editor"]),
76
- operation: z.enum([
77
- "replace-static-classname",
78
- "replace-expression",
79
- "create-attribute",
80
- "remove-attribute",
81
- ]),
82
- });
83
- export const SiteEditSetClassNameSourceRequestSchema = z.object({
84
- key: z.string().min(1),
85
- routeId: z.string().min(1).optional(),
86
- filePath: z.string().min(1),
87
- expectedVersion: z.object({
88
- documentVersion: z.number().int().nonnegative(),
89
- contentHash: z.string().min(1),
90
- }),
91
- oldAttrRaw: z.string().min(1).nullable(),
92
- oldAttrRange: SiteEditClassNameSourceRangeSchema.nullable(),
93
- openingElementRange: SiteEditClassNameSourceRangeSchema,
94
- newAttrRaw: z.string().min(1).nullable(),
95
- intent: SiteEditSetClassNameSourceIntentSchema,
96
- });
97
- export const SiteEditSetClassNameSourceFailureReasonSchema = z.enum([
98
- "node_not_found",
99
- "document_version_stale",
100
- "file_hash_mismatch",
101
- "range_mismatch",
102
- "old_attr_mismatch",
103
- "invalid_new_attr",
104
- "unsupported_target",
105
- "write_failed",
106
- ]);
107
- export const SiteEditSetClassNameSourceResultSchema = z.discriminatedUnion("ok", [
108
- z.object({
109
- ok: z.literal(true),
110
- source: SiteEditClassNameSourceSchema,
111
- }),
112
- z.object({
113
- ok: z.literal(false),
114
- reason: SiteEditSetClassNameSourceFailureReasonSchema,
115
- current: SiteEditClassNameSourceSchema.optional(),
116
- diagnostics: z.array(SiteEditClassNameSourceDiagnosticSchema),
117
- }),
118
- ]);
@@ -1,41 +0,0 @@
1
- import { z } from "zod";
2
- import { SiteEditOperationErrorSchema } from "./site-edit-operation.js";
3
- import { SiteEditOperationResultSchema } from "./site-edit-operation.js";
4
- export const SiteEditEventSchema = z.discriminatedUnion("type", [
5
- z.object({
6
- type: z.literal("site-edit.document.changed"),
7
- siteId: z.string().min(1),
8
- snapshotId: z.string().min(1),
9
- routeId: z.string().min(1),
10
- version: z.number().int().nonnegative(),
11
- at: z.string().min(1),
12
- }),
13
- z.object({
14
- type: z.literal("site-edit.operation.planned"),
15
- siteId: z.string().min(1),
16
- operationId: z.string().min(1),
17
- baseSnapshotId: z.string().min(1),
18
- changedFiles: z.array(z.string().min(1)),
19
- at: z.string().min(1),
20
- }),
21
- z.object({
22
- type: z.literal("site-edit.operation.completed"),
23
- siteId: z.string().min(1),
24
- result: SiteEditOperationResultSchema,
25
- at: z.string().min(1),
26
- }),
27
- z.object({
28
- type: z.literal("site-edit.operation.failed"),
29
- siteId: z.string().min(1),
30
- requestId: z.string().min(1),
31
- error: SiteEditOperationErrorSchema,
32
- at: z.string().min(1),
33
- }),
34
- z.object({
35
- type: z.literal("site-edit.capability.changed"),
36
- siteId: z.string().min(1),
37
- routeId: z.string().min(1),
38
- keys: z.array(z.string().min(1)),
39
- at: z.string().min(1),
40
- }),
41
- ]);
@@ -1,33 +0,0 @@
1
- import { z } from "zod";
2
- const SITE_EDIT_IDENTITY_SEPARATOR = "::";
3
- export const SiteEditSourceIdentitySchema = z
4
- .object({
5
- file: z.string().min(1),
6
- component: z.string().min(1),
7
- structuralPath: z.string().min(1),
8
- key: z.string().min(1),
9
- })
10
- .superRefine((value, ctx) => {
11
- const expected = computeSiteEditSourceIdentityKey(value.file, value.component, value.structuralPath);
12
- if (value.key !== expected) {
13
- ctx.addIssue({
14
- code: "custom",
15
- path: ["key"],
16
- message: "key must match file::component::structuralPath",
17
- });
18
- }
19
- });
20
- export function computeSiteEditSourceIdentityKey(file, component, structuralPath) {
21
- return `${file}${SITE_EDIT_IDENTITY_SEPARATOR}${component}${SITE_EDIT_IDENTITY_SEPARATOR}${structuralPath}`;
22
- }
23
- export function parseSiteEditSourceIdentityKey(key) {
24
- const [file, component, ...pathParts] = key.split(SITE_EDIT_IDENTITY_SEPARATOR);
25
- if (!file || !component || pathParts.length === 0) {
26
- return null;
27
- }
28
- return {
29
- file,
30
- component,
31
- structuralPath: pathParts.join(SITE_EDIT_IDENTITY_SEPARATOR),
32
- };
33
- }
@@ -1,379 +0,0 @@
1
- import { z } from "zod";
2
- export const SiteEditOperationTypeSchema = z.enum([
3
- "update-text",
4
- "remove-node",
5
- "insert-child",
6
- "move-node",
7
- "replace-rich-text-content",
8
- "insert-rich-text-block",
9
- "remove-rich-text-block",
10
- "set-media-field",
11
- "set-component-slot-content",
12
- "set-object-field",
13
- "insert-object-field",
14
- "remove-object-field",
15
- "update-array-item",
16
- "insert-array-item",
17
- "remove-array-item",
18
- "move-array-item",
19
- "replace-conditional-expression",
20
- "set-conditional-branch-content",
21
- "set-jsx-prop",
22
- "remove-jsx-prop",
23
- "set-class-name",
24
- "add-class-token",
25
- "remove-class-token",
26
- "set-style-property",
27
- "set-style-properties",
28
- "set-css-module-class",
29
- "set-directive",
30
- "remove-directive",
31
- "set-route-export",
32
- "set-metadata-field",
33
- "set-generate-metadata",
34
- ]);
35
- export const SiteEditOperationValueSchema = z.lazy(() => z.union([
36
- z.string(),
37
- z.number(),
38
- z.boolean(),
39
- z.null(),
40
- z.array(SiteEditOperationValueSchema),
41
- z.record(z.string(), SiteEditOperationValueSchema),
42
- ]));
43
- export const SiteEditOperationTargetSchema = z.discriminatedUnion("kind", [
44
- z.object({
45
- kind: z.literal("node"),
46
- key: z.string().min(1),
47
- }),
48
- z.object({
49
- kind: z.literal("route"),
50
- routeId: z.string().min(1),
51
- }),
52
- ]);
53
- export const SiteEditStylePropertySchema = z.enum([
54
- "display",
55
- "position",
56
- "top",
57
- "right",
58
- "bottom",
59
- "left",
60
- "zIndex",
61
- "flexDirection",
62
- "flexWrap",
63
- "flexGrow",
64
- "flexShrink",
65
- "flexBasis",
66
- "order",
67
- "gridTemplateColumns",
68
- "gridTemplateRows",
69
- "columns",
70
- "gridColumn",
71
- "gridRow",
72
- "gap",
73
- "gapX",
74
- "gapY",
75
- "spaceX",
76
- "spaceY",
77
- "alignItems",
78
- "justifyContent",
79
- "marginTop",
80
- "marginRight",
81
- "marginBottom",
82
- "marginLeft",
83
- "paddingTop",
84
- "paddingRight",
85
- "paddingBottom",
86
- "paddingLeft",
87
- "width",
88
- "height",
89
- "minWidth",
90
- "minHeight",
91
- "maxWidth",
92
- "maxHeight",
93
- "overflow",
94
- "fontFamily",
95
- "fontSize",
96
- "fontWeight",
97
- "lineHeight",
98
- "letterSpacing",
99
- "textAlign",
100
- "textTransform",
101
- "textDecoration",
102
- "textOverflow",
103
- "textIndent",
104
- "writingMode",
105
- "whiteSpace",
106
- "wordBreak",
107
- "lineClamp",
108
- "fontVariantNumeric",
109
- "screenReaderOnly",
110
- "color",
111
- "backgroundColor",
112
- "backgroundImage",
113
- "borderStyle",
114
- "borderWidth",
115
- "borderRadius",
116
- "borderColor",
117
- "objectFit",
118
- "objectPosition",
119
- "aspectRatio",
120
- "opacity",
121
- "boxShadow",
122
- "transform",
123
- "transformOrigin",
124
- "transitionProperty",
125
- "transitionDuration",
126
- "transitionTimingFunction",
127
- "animation",
128
- "pointerEvents",
129
- "cursor",
130
- "userSelect",
131
- "fontStyle",
132
- "textUnderlineOffset",
133
- "scrollMarginTop",
134
- "alignSelf",
135
- "flex",
136
- "outlineStyle",
137
- "resize",
138
- "ringWidth",
139
- "ringColor",
140
- "backdropFilter",
141
- "overscrollBehavior",
142
- "divideWidth",
143
- "divideColor",
144
- ]);
145
- export const SiteEditStyleStateModeSchema = z.enum([
146
- "hover",
147
- "active",
148
- "focus",
149
- "disabled",
150
- ]);
151
- export const SiteEditStyleBreakpointSchema = z.enum([
152
- "sm",
153
- "md",
154
- "lg",
155
- "xl",
156
- "2xl",
157
- ]);
158
- export const SiteEditMoveTargetSchema = z.union([
159
- z.object({
160
- relation: z.enum(["before", "after"]),
161
- anchorKey: z.string().min(1),
162
- }),
163
- z.object({
164
- relation: z.enum(["prepend", "append"]),
165
- parentKey: z.string().min(1),
166
- }),
167
- ]);
168
- export const SiteEditInsertNodeSpecSchema = z.discriminatedUnion("kind", [
169
- z.object({
170
- kind: z.literal("native-tag"),
171
- tag: z.string().min(1),
172
- text: z.string().optional(),
173
- }),
174
- z.object({
175
- kind: z.literal("component-call"),
176
- component: z.object({
177
- source: z.string().min(1),
178
- exportName: z.string().min(1),
179
- }),
180
- props: z.record(z.string(), z.unknown()).optional(),
181
- }),
182
- ]);
183
- export const SiteEditOperationParamsSchema = z.discriminatedUnion("kind", [
184
- z.object({
185
- kind: z.literal("update-text"),
186
- segmentIndex: z.number().int().min(0),
187
- value: z.string(),
188
- }),
189
- z.object({ kind: z.literal("remove-node") }),
190
- z.object({
191
- kind: z.literal("insert-child"),
192
- node: SiteEditInsertNodeSpecSchema,
193
- position: SiteEditMoveTargetSchema,
194
- }),
195
- z.object({
196
- kind: z.literal("move-node"),
197
- target: SiteEditMoveTargetSchema,
198
- preserveBindings: z.boolean().optional(),
199
- }),
200
- z.object({
201
- kind: z.literal("replace-rich-text-content"),
202
- field: z.string().min(1),
203
- value: SiteEditOperationValueSchema,
204
- }),
205
- z.object({
206
- kind: z.literal("insert-rich-text-block"),
207
- field: z.string().min(1),
208
- index: z.number().int().min(0),
209
- block: SiteEditOperationValueSchema,
210
- }),
211
- z.object({
212
- kind: z.literal("remove-rich-text-block"),
213
- field: z.string().min(1),
214
- index: z.number().int().min(0),
215
- }),
216
- z.object({
217
- kind: z.literal("set-media-field"),
218
- field: z.enum(["src", "alt", "poster", "caption", "width", "height"]),
219
- value: SiteEditOperationValueSchema,
220
- }),
221
- z.object({
222
- kind: z.literal("set-component-slot-content"),
223
- slotName: z.string().min(1),
224
- value: SiteEditOperationValueSchema,
225
- }),
226
- z.object({
227
- kind: z.literal("set-object-field"),
228
- segmentIndex: z.number().int().min(0),
229
- value: SiteEditOperationValueSchema,
230
- }),
231
- z.object({
232
- kind: z.literal("insert-object-field"),
233
- segmentIndex: z.number().int().min(0),
234
- field: z.string().min(1),
235
- value: SiteEditOperationValueSchema,
236
- }),
237
- z.object({
238
- kind: z.literal("remove-object-field"),
239
- segmentIndex: z.number().int().min(0),
240
- field: z.string().min(1).optional(),
241
- }),
242
- z.object({
243
- kind: z.literal("update-array-item"),
244
- segmentIndex: z.number().int().min(0),
245
- value: SiteEditOperationValueSchema,
246
- index: z.number().int().min(0).optional(),
247
- }),
248
- z.object({
249
- kind: z.literal("insert-array-item"),
250
- segmentIndex: z.number().int().min(0),
251
- index: z.number().int().min(0),
252
- value: SiteEditOperationValueSchema,
253
- }),
254
- z.object({
255
- kind: z.literal("remove-array-item"),
256
- segmentIndex: z.number().int().min(0),
257
- index: z.number().int().min(0).optional(),
258
- }),
259
- z.object({
260
- kind: z.literal("move-array-item"),
261
- segmentIndex: z.number().int().min(0),
262
- toIndex: z.number().int().min(0),
263
- fromIndex: z.number().int().min(0).optional(),
264
- }),
265
- z.object({
266
- kind: z.literal("replace-conditional-expression"),
267
- nextExpression: z.string().min(1),
268
- }),
269
- z.object({
270
- kind: z.literal("set-conditional-branch-content"),
271
- branch: z.enum(["then", "else"]),
272
- content: z.object({ jsx: z.string().min(1) }),
273
- }),
274
- z.object({
275
- kind: z.literal("set-jsx-prop"),
276
- name: z.string().min(1),
277
- value: SiteEditOperationValueSchema.nullable(),
278
- }),
279
- z.object({
280
- kind: z.literal("remove-jsx-prop"),
281
- name: z.string().min(1),
282
- }),
283
- z.object({ kind: z.literal("set-class-name"), value: z.string() }),
284
- z.object({
285
- kind: z.literal("add-class-token"),
286
- token: z.string().min(1),
287
- }),
288
- z.object({
289
- kind: z.literal("remove-class-token"),
290
- token: z.string().min(1),
291
- }),
292
- z.object({
293
- kind: z.literal("set-style-property"),
294
- property: z.string().min(1),
295
- value: SiteEditOperationValueSchema.nullable(),
296
- }),
297
- z.object({
298
- kind: z.literal("set-style-properties"),
299
- properties: z.record(z.string(), SiteEditOperationValueSchema.nullable()),
300
- }),
301
- z.object({
302
- kind: z.literal("set-css-module-class"),
303
- from: z.string().min(1),
304
- to: z.string().min(1),
305
- }),
306
- z.object({
307
- kind: z.literal("set-directive"),
308
- value: z.enum(["use client", "use server"]),
309
- }),
310
- z.object({
311
- kind: z.literal("remove-directive"),
312
- value: z.enum(["use client", "use server"]),
313
- }),
314
- z.object({
315
- kind: z.literal("set-route-export"),
316
- name: z.string().min(1),
317
- value: SiteEditOperationValueSchema,
318
- }),
319
- z.object({
320
- kind: z.literal("set-metadata-field"),
321
- field: z.string().min(1),
322
- value: SiteEditOperationValueSchema.nullable(),
323
- }),
324
- z.object({
325
- kind: z.literal("set-generate-metadata"),
326
- field: z.string().min(1),
327
- value: SiteEditOperationValueSchema.nullable(),
328
- }),
329
- ]);
330
- export const SiteEditOperationErrorCodeSchema = z.enum([
331
- "NODE_NOT_FOUND",
332
- "ROUTE_NOT_FOUND",
333
- "CAPABILITY_REJECTED",
334
- "CONSTRAINT_VIOLATED",
335
- "INVALID_PARAMS",
336
- "PLAN_FAILED",
337
- "VERSION_STALE",
338
- "AST_PARSE_ERROR",
339
- "UNSUPPORTED_OPERATION",
340
- "LOCATOR_FAILED",
341
- "INVALID_TARGET",
342
- "WRITE_IO_ERROR",
343
- "CONCURRENT_MODIFIED",
344
- "ROLLBACK_FAILED",
345
- "INTERNAL_ERROR",
346
- ]);
347
- export const SiteEditOperationErrorSchema = z.object({
348
- code: SiteEditOperationErrorCodeSchema,
349
- message: z.string().min(1),
350
- details: z.record(z.string(), z.unknown()).optional(),
351
- });
352
- export const SiteEditOperationRequestSchema = z
353
- .object({
354
- id: z.string().min(1),
355
- siteId: z.string().min(1),
356
- baseSnapshotId: z.string().min(1),
357
- routeId: z.string().min(1).optional(),
358
- kind: SiteEditOperationTypeSchema,
359
- target: SiteEditOperationTargetSchema,
360
- documentVersion: z.number().int().nonnegative(),
361
- params: SiteEditOperationParamsSchema,
362
- })
363
- .superRefine((value, ctx) => {
364
- if (value.kind !== value.params.kind) {
365
- ctx.addIssue({
366
- code: "custom",
367
- path: ["params", "kind"],
368
- message: "params.kind must match operation kind",
369
- });
370
- }
371
- });
372
- export const SiteEditOperationResultSchema = z.object({
373
- requestId: z.string().min(1),
374
- kind: SiteEditOperationTypeSchema,
375
- target: SiteEditOperationTargetSchema,
376
- ok: z.boolean(),
377
- resultVersion: z.number().int().nonnegative(),
378
- error: SiteEditOperationErrorSchema.optional(),
379
- });
@@ -1,62 +0,0 @@
1
- import { z } from "zod";
2
- const SiteEditSnapshotFilePathSchema = z
3
- .string()
4
- .min(1)
5
- .refine((path) => !path.startsWith("/") && !path.includes(".."), {
6
- message: "Patch paths must be safe relative POSIX paths.",
7
- });
8
- const SiteEditSnapshotContentHashSchema = z
9
- .string()
10
- .regex(/^sha256:[a-f0-9]{64}$/);
11
- export const SiteEditPatchPlanPatchSchema = z
12
- .object({
13
- path: SiteEditSnapshotFilePathSchema,
14
- operation: z.enum(["create", "update", "delete"]),
15
- expectedHash: SiteEditSnapshotContentHashSchema.optional(),
16
- fullContent: z.string().optional(),
17
- })
18
- .superRefine((value, ctx) => {
19
- if (value.operation === "delete" && value.fullContent !== undefined) {
20
- ctx.addIssue({
21
- code: "custom",
22
- path: ["fullContent"],
23
- message: "delete patches must not include fullContent",
24
- });
25
- }
26
- if (value.operation !== "delete" && value.fullContent === undefined) {
27
- ctx.addIssue({
28
- code: "custom",
29
- path: ["fullContent"],
30
- message: "create/update patches must include fullContent",
31
- });
32
- }
33
- });
34
- export const SiteEditPatchPlanSchema = z
35
- .object({
36
- siteId: z.string().min(1),
37
- baseSnapshotId: z.string().min(1),
38
- operationId: z.string().min(1),
39
- reason: z.string().min(1),
40
- patches: z.array(SiteEditPatchPlanPatchSchema).min(1),
41
- changedRouteIds: z.array(z.string().min(1)),
42
- diagnostics: z
43
- .array(z.object({
44
- code: z.string().min(1),
45
- message: z.string().min(1),
46
- path: z.string().min(1).optional(),
47
- }))
48
- .default([]),
49
- })
50
- .superRefine((value, ctx) => {
51
- const seenPaths = new Set();
52
- for (const [index, patch] of value.patches.entries()) {
53
- if (seenPaths.has(patch.path)) {
54
- ctx.addIssue({
55
- code: "custom",
56
- path: ["patches", index, "path"],
57
- message: `Duplicate patch path: ${patch.path}`,
58
- });
59
- }
60
- seenPaths.add(patch.path);
61
- }
62
- });