@openplanr/protocol 0.14.0 → 0.16.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.
@@ -1,9 +1,13 @@
1
1
  // @ts-check
2
2
 
3
3
  import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
4
- import { DESIGN_DOCUMENT_SCHEMA } from './design-contracts.mjs';
4
+ import {
5
+ DESIGN_DOCUMENT_SCHEMA,
6
+ DESIGN_DOCUMENT_V120_SCHEMA,
7
+ validateDesignProps,
8
+ } from './design-contracts.mjs';
9
+ import { DESIGN_REVIEW_BUNDLE_SCHEMA } from './design-review-bundle-contracts.mjs';
5
10
  import { validateJson } from './json-schema.mjs';
6
- import { DESIGN_REVIEW_BUNDLE_SCHEMA } from './workspace-contracts.mjs';
7
11
 
8
12
  const text = { type: 'string', maxLength: 16384 };
9
13
  const id = { type: 'string', minLength: 1, maxLength: 128 };
@@ -119,15 +123,36 @@ bundleCurrent.allOf = [
119
123
  const currentDesign = /** @type {MutableSchema} */ (bundleCurrent.properties.design);
120
124
  for (const key of ['frames', 'layout'])
121
125
  currentDesign.properties[key] = /** @type {Record<string, unknown>} */ (
122
- DESIGN_DOCUMENT_SCHEMA.properties
126
+ DESIGN_DOCUMENT_V120_SCHEMA.properties
123
127
  )[key];
124
- bundleCurrent.$defs = structuredClone(DESIGN_DOCUMENT_SCHEMA.$defs);
128
+ bundleCurrent.$defs = structuredClone(DESIGN_DOCUMENT_V120_SCHEMA.$defs);
125
129
  const currentEntries = /** @type {{ items: { properties: Record<string, unknown> } }} */ (
126
130
  bundleCurrent.properties.entries
127
131
  );
128
132
  currentEntries.items.properties.height = { const: 'auto' };
133
+ /** @type {typeof import('./review-experience-contracts.d.mts').DESIGN_REVIEW_BUNDLE_V120_SCHEMA} */
134
+ export const DESIGN_REVIEW_BUNDLE_V120_SCHEMA = bundleCurrent;
135
+
136
+ const bundleProps = /** @type {MutableSchema} */ (structuredClone(bundleCurrent));
137
+ bundleProps.$id = 'https://openplanr.dev/schemas/v1.22.0/design-review-bundle.schema.json';
138
+ bundleProps['x-openplanr-contract'] = { id: 'design-review-bundle', version: '1.22.0' };
139
+ const propsDesign = /** @type {MutableSchema} */ (bundleProps.properties.design);
140
+ const authoredProperties = /** @type {Record<string, unknown>} */ (
141
+ DESIGN_DOCUMENT_SCHEMA.properties
142
+ );
143
+ propsDesign.properties.schemaVersion = authoredProperties.schemaVersion;
144
+ for (const key of ['screens', 'variants']) {
145
+ const projected = /** @type {{ items: { properties: Record<string, unknown> } }} */ (
146
+ propsDesign.properties[key]
147
+ );
148
+ const authored = /** @type {{ items: { properties: Record<string, unknown> } }} */ (
149
+ authoredProperties[key]
150
+ );
151
+ projected.items.properties.props = authored.items.properties.props;
152
+ }
153
+ propsDesign.allOf = structuredClone(DESIGN_DOCUMENT_SCHEMA.allOf);
129
154
  /** @type {typeof import('./review-experience-contracts.d.mts').DESIGN_REVIEW_BUNDLE_CURRENT_SCHEMA} */
130
- export const DESIGN_REVIEW_BUNDLE_CURRENT_SCHEMA = bundleCurrent;
155
+ export const DESIGN_REVIEW_BUNDLE_CURRENT_SCHEMA = bundleProps;
131
156
 
132
157
  const item = closed(
133
158
  {
@@ -261,9 +286,24 @@ export function assertDesignReviewMetadata(value) {
261
286
  }
262
287
  /** @returns {ReturnType<typeof import('./review-experience-contracts.d.mts').assertDesignReviewBundle>} */
263
288
  export function assertDesignReviewBundle(value) {
289
+ if (
290
+ value?.design?.schemaVersion !== '1.1.0' &&
291
+ ['screens', 'variants'].some(
292
+ (field) =>
293
+ Array.isArray(value?.design?.[field]) &&
294
+ value.design[field].some((item) => item && Object.hasOwn(item, 'props')),
295
+ )
296
+ )
297
+ throw new TypeError('Invalid design props: props require design.schemaVersion "1.1.0"');
264
298
  assertReviewExperience(
265
299
  value,
266
- value?.design?.layout !== undefined ||
300
+ value?.design?.schemaVersion !== undefined ||
301
+ ['screens', 'variants'].some(
302
+ (field) =>
303
+ Array.isArray(value?.design?.[field]) &&
304
+ value.design[field].some((item) => item && Object.hasOwn(item, 'props')),
305
+ ) ||
306
+ value?.design?.layout !== undefined ||
267
307
  (Array.isArray(value?.design?.frames) &&
268
308
  value.design.frames.some(({ height }) => height === 'auto'))
269
309
  ? DESIGN_REVIEW_BUNDLE_CURRENT_SCHEMA
@@ -273,6 +313,8 @@ export function assertDesignReviewBundle(value) {
273
313
  ? DESIGN_REVIEW_BUNDLE_V11_SCHEMA
274
314
  : DESIGN_REVIEW_BUNDLE_SCHEMA,
275
315
  );
316
+ const propErrors = validateDesignProps(value.design);
317
+ if (propErrors.length) throw new TypeError(`Invalid design props:\n${propErrors.join('\n')}`);
276
318
  if (['1.1.0', '1.2.0'].includes(value.schemaVersion)) {
277
319
  if (
278
320
  value.reviewContext.designId !== value.design.id ||
@@ -35,7 +35,6 @@ export interface DesignReviewWorkspace {
35
35
  ownerPublicKey: WorkspacePublicKey;
36
36
  keyring: WorkspaceCiphertext;
37
37
  }
38
- export declare const DESIGN_WORKSPACE_VERSION: '1.0.0';
39
38
  export declare const DESIGN_WORKSPACE_API: '/api/v1/design-workspaces';
40
39
  export declare const DESIGN_WORKSPACE_MAX_BYTES: number;
41
40
  export declare const DESIGN_WORKSPACE_MAX_EVENT_BYTES: number;
@@ -44,7 +43,6 @@ export declare const DESIGN_WORKSPACE_SCHEMA: Readonly<Record<string, unknown>>;
44
43
  export declare const DESIGN_WORKSPACE_CREATE_SCHEMA: Readonly<Record<string, unknown>>;
45
44
  export declare const DESIGN_WORKSPACE_REVISION_SCHEMA: Readonly<Record<string, unknown>>;
46
45
  export declare const DESIGN_WORKSPACE_EVENT_SCHEMA: Readonly<Record<string, unknown>>;
47
- export declare const DESIGN_REVIEW_BUNDLE_SCHEMA: Readonly<Record<string, unknown>>;
48
46
  export declare const DESIGN_WORKSPACE_SCHEMAS: Readonly<
49
47
  Record<string, Readonly<Record<string, unknown>>>
50
48
  >;
@@ -52,3 +50,7 @@ export declare function assertWorkspaceContract<T>(
52
50
  value: T,
53
51
  contract: Readonly<Record<string, unknown>>,
54
52
  ): T;
53
+ export {
54
+ DESIGN_REVIEW_BUNDLE_SCHEMA,
55
+ DESIGN_WORKSPACE_VERSION,
56
+ } from './design-review-bundle-contracts.mjs';
@@ -1,9 +1,11 @@
1
1
  // @ts-check
2
- import { DESIGN_DOCUMENT_V1_SCHEMA } from './design-contracts.mjs';
2
+ import {
3
+ DESIGN_REVIEW_BUNDLE_SCHEMA,
4
+ DESIGN_WORKSPACE_VERSION,
5
+ } from './design-review-bundle-contracts.mjs';
3
6
  import { validateJson } from './json-schema.mjs';
4
7
 
5
- /** @type {typeof import('./workspace-contracts.d.mts').DESIGN_WORKSPACE_VERSION} */
6
- export const DESIGN_WORKSPACE_VERSION = '1.0.0';
8
+ export { DESIGN_REVIEW_BUNDLE_SCHEMA, DESIGN_WORKSPACE_VERSION };
7
9
  /** @type {typeof import('./workspace-contracts.d.mts').DESIGN_WORKSPACE_API} */
8
10
  export const DESIGN_WORKSPACE_API = '/api/v1/design-workspaces';
9
11
  /** @type {typeof import('./workspace-contracts.d.mts').DESIGN_WORKSPACE_MAX_BYTES} */
@@ -94,86 +96,6 @@ export const DESIGN_WORKSPACE_SCHEMA = schema('design-review-workspace', {
94
96
  keyring: sealed,
95
97
  });
96
98
 
97
- // An explicit presentation-only model. Authored paths, source provenance, and
98
- // design-system references are deliberately not part of a published workspace.
99
- const designProperties =
100
- /** @type {Record<string, { items: { properties: Record<string, unknown>; required: string[] } }>} */ (
101
- structuredClone(DESIGN_DOCUMENT_V1_SCHEMA.properties)
102
- );
103
- for (const key of ['kind', 'schemaVersion', 'brief', 'assets', 'designSystem'])
104
- delete designProperties[key];
105
- delete designProperties.screens.items.properties.source;
106
- designProperties.screens.items.required = ['id', 'title'];
107
- delete designProperties.variants.items.properties.sources;
108
- /** @type {typeof import('./workspace-contracts.d.mts').DESIGN_REVIEW_BUNDLE_SCHEMA} */
109
- export const DESIGN_REVIEW_BUNDLE_SCHEMA = {
110
- ...schema(
111
- 'design-review-bundle',
112
- {
113
- kind: { const: 'openplanr-design-review-bundle' },
114
- schemaVersion: { const: DESIGN_WORKSPACE_VERSION },
115
- design: {
116
- type: 'object',
117
- additionalProperties: false,
118
- properties: designProperties,
119
- required: [
120
- 'id',
121
- 'title',
122
- 'frames',
123
- 'screens',
124
- 'screenOrder',
125
- 'variants',
126
- 'selectedVariant',
127
- 'defaultView',
128
- ],
129
- },
130
- envelope: { type: 'object', required: ['schemaVersion', 'artifacts', 'viewer'] },
131
- entries: {
132
- type: 'array',
133
- minItems: 1,
134
- maxItems: 256,
135
- items: {
136
- type: 'object',
137
- additionalProperties: false,
138
- required: ['artifactId', 'screenId', 'variantId', 'frameId'],
139
- properties: Object.fromEntries(
140
- ['artifactId', 'screenId', 'variantId', 'frameId'].map((key) => [
141
- key,
142
- { type: 'string', minLength: 1, maxLength: 128 },
143
- ]),
144
- ),
145
- },
146
- },
147
- state: {
148
- type: ['object', 'null'],
149
- additionalProperties: false,
150
- properties: {
151
- positions: {
152
- type: 'object',
153
- additionalProperties: {
154
- type: 'object',
155
- additionalProperties: false,
156
- required: ['x', 'y'],
157
- properties: {
158
- x: { type: 'number', minimum: -1e7, maximum: 1e7 },
159
- y: { type: 'number', minimum: -1e7, maximum: 1e7 },
160
- },
161
- },
162
- },
163
- },
164
- },
165
- revision: { type: 'string', minLength: 1, maxLength: 128 },
166
- verification: {
167
- type: ['object', 'null'],
168
- additionalProperties: false,
169
- properties: { status: { enum: ['verified', 'unverified', 'failed', 'pending'] } },
170
- },
171
- },
172
- ['kind', 'schemaVersion', 'design', 'envelope', 'entries', 'revision'],
173
- ),
174
- $defs: structuredClone(DESIGN_DOCUMENT_V1_SCHEMA.$defs),
175
- };
176
-
177
99
  /** @returns {ReturnType<typeof import('./workspace-contracts.d.mts').assertWorkspaceContract>} */
178
100
  export function assertWorkspaceContract(value, contract) {
179
101
  const errors = validateJson(value, contract);