@openplanr/protocol 0.6.1 → 0.6.2

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.
Files changed (55) hide show
  1. package/lib/dashboard/closed-json-contract.mjs +99 -109
  2. package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
  3. package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
  4. package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
  5. package/lib/dashboard/operate-experience-display-contract.mjs +768 -831
  6. package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
  7. package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
  8. package/lib/dashboard/operate-review-contract.d.mts +7 -14
  9. package/lib/dashboard/operate-review-contract.mjs +46 -42
  10. package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
  11. package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
  12. package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
  13. package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
  14. package/lib/protocol/index.d.ts +2647 -543
  15. package/package.json +1 -1
  16. package/registries/commands.json +3 -3
  17. package/registries/skills.json +5 -5
  18. package/src/browser-contracts.d.mts +4 -1
  19. package/src/browser-contracts.mjs +16 -5
  20. package/src/canonical-json.d.mts +3 -1
  21. package/src/canonical-json.mjs +57 -20
  22. package/src/compat/live-evidence-v2.mjs +1604 -485
  23. package/src/compat/operate-experience-live-patch.mjs +67 -15
  24. package/src/compat/operating-planning-contracts.mjs +183 -51
  25. package/src/contracts.d.mts +54 -13
  26. package/src/contracts.mjs +625 -335
  27. package/src/design-contracts.mjs +58 -21
  28. package/src/design-handoff-contracts.d.mts +67 -11
  29. package/src/design-handoff-contracts.mjs +243 -98
  30. package/src/design-publication-contracts.mjs +98 -33
  31. package/src/diagram-authoring-contracts.d.mts +422 -78
  32. package/src/diagram-authoring-contracts.mjs +1697 -326
  33. package/src/diagram-contracts.d.mts +4 -1
  34. package/src/diagram-contracts.mjs +16 -4
  35. package/src/enterprise-contracts.d.mts +211 -46
  36. package/src/enterprise-contracts.mjs +727 -175
  37. package/src/errors.mjs +4 -0
  38. package/src/generated/canonical-registries.mjs +8 -8
  39. package/src/index.d.mts +8 -8
  40. package/src/index.mjs +36 -20
  41. package/src/json-schema.d.mts +21 -6
  42. package/src/json-schema.mjs +66 -18
  43. package/src/planning-contracts.d.mts +8 -2
  44. package/src/planning-contracts.mjs +33 -7
  45. package/src/registries.d.mts +11 -3
  46. package/src/registries.mjs +369 -87
  47. package/src/review-experience-contracts.d.mts +7 -2
  48. package/src/review-experience-contracts.mjs +198 -49
  49. package/src/semver.mjs +5 -1
  50. package/src/skill-source-contracts.d.mts +36 -16
  51. package/src/skill-source-contracts.mjs +25 -6
  52. package/src/task-contracts.d.mts +13 -3
  53. package/src/task-contracts.mjs +181 -40
  54. package/src/workspace-contracts.d.mts +38 -10
  55. package/src/workspace-contracts.mjs +147 -33
@@ -1,700 +1,645 @@
1
1
  import { validateJson } from '../../src/json-schema.mjs';
2
2
  import {
3
- contentHash,
4
- deepFreeze,
5
- exactEventHead,
6
- exactJson,
7
- hasOwn,
8
- safeDataClone,
9
- withoutContentHash,
10
- } from "./closed-json-contract.mjs";
3
+ contentHash,
4
+ deepFreeze,
5
+ exactEventHead,
6
+ exactJson,
7
+ hasOwn,
8
+ safeDataClone,
9
+ withoutContentHash,
10
+ } from './closed-json-contract.mjs';
11
11
  import {
12
- OPERATE_EXPERIENCE_AUDIT_DISPLAY_SURFACE_SCHEMA as auditDisplaySchema,
13
- OPERATE_REVIEW_DISPLAY_WORKSPACE_SCHEMA as reviewWorkspaceSchema,
14
- OPERATE_EXPERIENCE_VIEW_SCHEMA as experienceViewSchema,
15
- OPERATE_EXPERIENCE_SURFACE_SCHEMA as surfaceSchema,
16
- OPERATING_TRACE_MATRIX_SCHEMA as traceMatrixSchema,
17
- } from "./generated/operate-experience-surface-schema-data.mjs";
18
- import { assertOperateExperienceSurfaceV1 } from "./operate-experience-surface-contract.mjs";
19
-
20
- const AUDIT_DISPLAY_DOMAIN =
21
- "openplanr:operate-experience-audit-display-surface:1.0.0";
22
- const AUDIT_SURFACES = new Set([
23
- "evidence",
24
- "outcomes",
25
- "outcome",
26
- "history",
27
- "search",
28
- "export",
29
- ]);
12
+ OPERATE_EXPERIENCE_AUDIT_DISPLAY_SURFACE_SCHEMA as auditDisplaySchema,
13
+ OPERATE_EXPERIENCE_VIEW_SCHEMA as experienceViewSchema,
14
+ OPERATE_REVIEW_DISPLAY_WORKSPACE_SCHEMA as reviewWorkspaceSchema,
15
+ OPERATE_EXPERIENCE_SURFACE_SCHEMA as surfaceSchema,
16
+ OPERATING_TRACE_MATRIX_SCHEMA as traceMatrixSchema,
17
+ } from './generated/operate-experience-surface-schema-data.mjs';
18
+ import { assertOperateExperienceSurfaceV1 } from './operate-experience-surface-contract.mjs';
19
+
20
+ const AUDIT_DISPLAY_DOMAIN = 'openplanr:operate-experience-audit-display-surface:1.0.0';
21
+ const AUDIT_SURFACES = new Set(['evidence', 'outcomes', 'outcome', 'history', 'search', 'export']);
30
22
  const schemas = new Map([
31
- ["operate-experience-audit-display-surface.schema.json", auditDisplaySchema],
32
- ["operate-experience-surface.schema.json", surfaceSchema],
33
- ["operate-experience-view.schema.json", experienceViewSchema],
34
- ["operate-review-display-workspace.schema.json", reviewWorkspaceSchema],
35
- ["operating-trace-matrix.schema.json", traceMatrixSchema],
23
+ ['operate-experience-audit-display-surface.schema.json', auditDisplaySchema],
24
+ ['operate-experience-surface.schema.json', surfaceSchema],
25
+ ['operate-experience-view.schema.json', experienceViewSchema],
26
+ ['operate-review-display-workspace.schema.json', reviewWorkspaceSchema],
27
+ ['operating-trace-matrix.schema.json', traceMatrixSchema],
36
28
  ]);
37
29
 
38
30
  function jsonPointer(root, fragment) {
39
- if (!fragment || fragment === "#") return root;
40
- if (!fragment.startsWith("#/")) return null;
41
- return fragment
42
- .slice(2)
43
- .split("/")
44
- .map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"))
45
- .reduce((value, part) => value?.[part], root);
31
+ if (!fragment || fragment === '#') return root;
32
+ if (!fragment.startsWith('#/')) return null;
33
+ return fragment
34
+ .slice(2)
35
+ .split('/')
36
+ .map((part) => part.replaceAll('~1', '/').replaceAll('~0', '~'))
37
+ .reduce((value, part) => value?.[part], root);
46
38
  }
47
39
 
48
40
  function resolveSchemaRef(reference) {
49
- const [path, pointer = ""] = reference.split("#");
50
- const filename = path.split("/").at(-1);
51
- const rootSchema = schemas.get(filename);
52
- if (!rootSchema) return null;
53
- return {
54
- schema: jsonPointer(rootSchema, pointer ? `#${pointer}` : "#"),
55
- rootSchema,
56
- base: filename,
57
- };
41
+ const [path, pointer = ''] = reference.split('#');
42
+ const filename = path.split('/').at(-1);
43
+ const rootSchema = schemas.get(filename);
44
+ if (!rootSchema) return null;
45
+ return {
46
+ schema: jsonPointer(rootSchema, pointer ? `#${pointer}` : '#'),
47
+ rootSchema,
48
+ base: filename,
49
+ };
58
50
  }
59
51
 
60
52
  function validationFailure() {
61
- return [
62
- {
63
- path: "$",
64
- rule: "closedContract",
65
- detail: "does not satisfy the closed audit display contract",
66
- },
67
- ];
53
+ return [
54
+ {
55
+ path: '$',
56
+ rule: 'closedContract',
57
+ detail: 'does not satisfy the closed audit display contract',
58
+ },
59
+ ];
68
60
  }
69
61
 
70
62
  function validCanonicalSubjectSegment(segment) {
71
- try {
72
- const decoded = decodeURIComponent(segment);
73
- return (
74
- decoded.length > 0 &&
75
- decoded !== "." &&
76
- decoded !== ".." &&
77
- !decoded.includes("/") &&
78
- !decoded.includes("\\") &&
79
- encodeURIComponent(decoded) === segment
80
- );
81
- } catch {
82
- return false;
83
- }
63
+ try {
64
+ const decoded = decodeURIComponent(segment);
65
+ return (
66
+ decoded.length > 0 &&
67
+ decoded !== '.' &&
68
+ decoded !== '..' &&
69
+ !decoded.includes('/') &&
70
+ !decoded.includes('\\') &&
71
+ encodeURIComponent(decoded) === segment
72
+ );
73
+ } catch {
74
+ return false;
75
+ }
84
76
  }
85
77
 
86
78
  function validOwnedLink(value) {
87
- if (value === null) return true;
88
- return ownedLinkDestination(value) !== null;
79
+ if (value === null) return true;
80
+ return ownedLinkDestination(value) !== null;
89
81
  }
90
82
 
91
83
  function exactOwnedLink(value, surface, subjectId) {
92
- if (value === null) return true;
93
- if (typeof subjectId !== "string") return false;
94
- if (surface === "action") {
95
- return value === `#/operate/actions/${encodeURIComponent(subjectId)}`;
96
- }
97
- if (surface === "cycle") {
98
- return value === `#/operate/cycles/${encodeURIComponent(subjectId)}`;
99
- }
100
- const route = surface === "evidence" ? "evidence" : "outcomes";
101
- return value === `#/operate/${route}/${encodeURIComponent(subjectId)}`;
84
+ if (value === null) return true;
85
+ if (typeof subjectId !== 'string') return false;
86
+ if (surface === 'action') {
87
+ return value === `#/operate/actions/${encodeURIComponent(subjectId)}`;
88
+ }
89
+ if (surface === 'cycle') {
90
+ return value === `#/operate/cycles/${encodeURIComponent(subjectId)}`;
91
+ }
92
+ const route = surface === 'evidence' ? 'evidence' : 'outcomes';
93
+ return value === `#/operate/${route}/${encodeURIComponent(subjectId)}`;
102
94
  }
103
95
 
104
96
  function ownedLinkDestination(value) {
105
- if (typeof value !== "string") return null;
106
- const match = /^#\/operate\/(evidence|outcomes)\/([^/?#]+)$/u.exec(value);
107
- if (match !== null && validCanonicalSubjectSegment(match[2])) {
108
- return {
109
- surface: match[1] === "evidence" ? "evidence" : "outcome",
110
- subjectId: decodeURIComponent(match[2]),
111
- };
112
- }
113
- const actionMatch = /^#\/operate\/actions\/([^/?#]+)$/u.exec(value);
114
- if (actionMatch !== null && validCanonicalSubjectSegment(actionMatch[1])) {
115
- return {
116
- surface: "action",
117
- subjectId: decodeURIComponent(actionMatch[1]),
118
- };
119
- }
120
- const cycleMatch = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(value);
121
- if (cycleMatch !== null && validCanonicalSubjectSegment(cycleMatch[1])) {
122
- return {
123
- surface: "cycle",
124
- subjectId: decodeURIComponent(cycleMatch[1]),
125
- };
126
- }
127
- return null;
97
+ if (typeof value !== 'string') return null;
98
+ const match = /^#\/operate\/(evidence|outcomes)\/([^/?#]+)$/u.exec(value);
99
+ if (match !== null && validCanonicalSubjectSegment(match[2])) {
100
+ return {
101
+ surface: match[1] === 'evidence' ? 'evidence' : 'outcome',
102
+ subjectId: decodeURIComponent(match[2]),
103
+ };
104
+ }
105
+ const actionMatch = /^#\/operate\/actions\/([^/?#]+)$/u.exec(value);
106
+ if (actionMatch !== null && validCanonicalSubjectSegment(actionMatch[1])) {
107
+ return {
108
+ surface: 'action',
109
+ subjectId: decodeURIComponent(actionMatch[1]),
110
+ };
111
+ }
112
+ const cycleMatch = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(value);
113
+ if (cycleMatch !== null && validCanonicalSubjectSegment(cycleMatch[1])) {
114
+ return {
115
+ surface: 'cycle',
116
+ subjectId: decodeURIComponent(cycleMatch[1]),
117
+ };
118
+ }
119
+ return null;
128
120
  }
129
121
 
130
122
  function validLinkProjection(value, seen = new Set()) {
131
- if (value === null || typeof value !== "object") return true;
132
- if (seen.has(value)) return false;
133
- seen.add(value);
134
- try {
135
- if (Array.isArray(value))
136
- return value.every((entry) => validLinkProjection(entry, seen));
137
- for (const [key, child] of Object.entries(value)) {
138
- if (key === "deepLink") {
139
- if (!validOwnedLink(child)) return false;
140
- continue;
141
- }
142
- if (key === "deepLinks") {
143
- if (!Array.isArray(child) || !child.every(validOwnedLink)) return false;
144
- continue;
145
- }
146
- if (!validLinkProjection(child, seen)) return false;
147
- }
148
- return true;
149
- } finally {
150
- seen.delete(value);
151
- }
123
+ if (value === null || typeof value !== 'object') return true;
124
+ if (seen.has(value)) return false;
125
+ seen.add(value);
126
+ try {
127
+ if (Array.isArray(value)) return value.every((entry) => validLinkProjection(entry, seen));
128
+ for (const [key, child] of Object.entries(value)) {
129
+ if (key === 'deepLink') {
130
+ if (!validOwnedLink(child)) return false;
131
+ continue;
132
+ }
133
+ if (key === 'deepLinks') {
134
+ if (!Array.isArray(child) || !child.every(validOwnedLink)) return false;
135
+ continue;
136
+ }
137
+ if (!validLinkProjection(child, seen)) return false;
138
+ }
139
+ return true;
140
+ } finally {
141
+ seen.delete(value);
142
+ }
152
143
  }
153
144
 
154
145
  function restoreLegacyLinks(value, seen = new Set()) {
155
- if (value === null || typeof value !== "object" || seen.has(value)) return;
156
- seen.add(value);
157
- if (Array.isArray(value)) {
158
- for (const entry of value) restoreLegacyLinks(entry, seen);
159
- return;
160
- }
161
- for (const [key, child] of Object.entries(value)) {
162
- if (key === "deepLink" && child === null) {
163
- value[key] = "#/operate/history/redacted";
164
- continue;
165
- }
166
- restoreLegacyLinks(child, seen);
167
- }
146
+ if (value === null || typeof value !== 'object' || seen.has(value)) return;
147
+ seen.add(value);
148
+ if (Array.isArray(value)) {
149
+ for (const entry of value) restoreLegacyLinks(entry, seen);
150
+ return;
151
+ }
152
+ for (const [key, child] of Object.entries(value)) {
153
+ if (key === 'deepLink' && child === null) {
154
+ value[key] = '#/operate/history/redacted';
155
+ continue;
156
+ }
157
+ restoreLegacyLinks(child, seen);
158
+ }
168
159
  }
169
160
 
170
161
  function legacyCompatibleSearchData(data) {
171
- return {
172
- ...data,
173
- results: data.results.map((entry) => {
174
- if (
175
- !["evidence", "claim", "outcome"].includes(entry.kind) &&
176
- hasOwn(entry, "deepLink")
177
- ) {
178
- const { deepLink: _deepLink, ...rest } = entry;
179
- return rest;
180
- }
181
- return entry;
182
- }),
183
- };
162
+ return {
163
+ ...data,
164
+ results: data.results.map((entry) => {
165
+ if (!['evidence', 'claim', 'outcome'].includes(entry.kind) && hasOwn(entry, 'deepLink')) {
166
+ const { deepLink: _deepLink, ...rest } = entry;
167
+ return rest;
168
+ }
169
+ return entry;
170
+ }),
171
+ };
184
172
  }
185
173
 
186
174
  function validLegacyPayload(payload) {
187
- try {
188
- const legacy = safeDataClone(payload);
189
- legacy.mutationEnabled = legacy.status === "ready";
190
- if (legacy.surface === "search") {
191
- legacy.data = legacyCompatibleSearchData(legacy.data);
192
- }
193
- restoreLegacyLinks(legacy.data);
194
- assertOperateExperienceSurfaceV1(legacy);
195
- return true;
196
- } catch {
197
- return false;
198
- }
175
+ try {
176
+ const legacy = safeDataClone(payload);
177
+ legacy.mutationEnabled = legacy.status === 'ready';
178
+ if (legacy.surface === 'search') {
179
+ legacy.data = legacyCompatibleSearchData(legacy.data);
180
+ }
181
+ restoreLegacyLinks(legacy.data);
182
+ assertOperateExperienceSurfaceV1(legacy);
183
+ return true;
184
+ } catch {
185
+ return false;
186
+ }
199
187
  }
200
188
 
201
189
  function uniqueRows(records, field) {
202
- const ids = records.map((entry) => entry[field]);
203
- return (
204
- ids.every((id) => typeof id === "string") &&
205
- new Set(ids).size === ids.length
206
- );
190
+ const ids = records.map((entry) => entry[field]);
191
+ return ids.every((id) => typeof id === 'string') && new Set(ids).size === ids.length;
207
192
  }
208
193
 
209
194
  function restrictedEvidenceIsClosed(entry) {
210
- if (entry.accessState === "available") return entry.accessReason === null;
211
- return (
212
- entry.accessState === "restricted" &&
213
- entry.claimStatus === "restricted" &&
214
- entry.evidenceKind === null &&
215
- entry.resolvedAt === null &&
216
- entry.source === null &&
217
- entry.producer === null &&
218
- entry.observedAt === null &&
219
- entry.provenance === null &&
220
- entry.confidence === null &&
221
- entry.accessReason === "access-denied" &&
222
- entry.supportClaimIds.length === 0 &&
223
- entry.contradictClaimIds.length === 0 &&
224
- entry.gaps.length === 0 &&
225
- entry.errors.length === 0 &&
226
- entry.causalLinks.length === 0
227
- );
195
+ if (entry.accessState === 'available') return entry.accessReason === null;
196
+ return (
197
+ entry.accessState === 'restricted' &&
198
+ entry.claimStatus === 'restricted' &&
199
+ entry.evidenceKind === null &&
200
+ entry.resolvedAt === null &&
201
+ entry.source === null &&
202
+ entry.producer === null &&
203
+ entry.observedAt === null &&
204
+ entry.provenance === null &&
205
+ entry.confidence === null &&
206
+ entry.accessReason === 'access-denied' &&
207
+ entry.supportClaimIds.length === 0 &&
208
+ entry.contradictClaimIds.length === 0 &&
209
+ entry.gaps.length === 0 &&
210
+ entry.errors.length === 0 &&
211
+ entry.causalLinks.length === 0
212
+ );
228
213
  }
229
214
 
230
215
  function restrictedClaimIsClosed(entry) {
231
- if (entry.accessReason === null) return entry.statement !== null;
232
- return (
233
- entry.status === "restricted" &&
234
- entry.accessReason === "access-denied" &&
235
- entry.statement === null &&
236
- entry.source === null &&
237
- entry.producer === null &&
238
- entry.provenance === null &&
239
- entry.confidence === null &&
240
- entry.supportEvidenceRefIds.length === 0 &&
241
- entry.contradictEvidenceRefIds.length === 0 &&
242
- entry.gaps.length === 0 &&
243
- entry.errors.length === 0 &&
244
- entry.causalLinks.length === 0
245
- );
216
+ if (entry.accessReason === null) return entry.statement !== null;
217
+ return (
218
+ entry.status === 'restricted' &&
219
+ entry.accessReason === 'access-denied' &&
220
+ entry.statement === null &&
221
+ entry.source === null &&
222
+ entry.producer === null &&
223
+ entry.provenance === null &&
224
+ entry.confidence === null &&
225
+ entry.supportEvidenceRefIds.length === 0 &&
226
+ entry.contradictEvidenceRefIds.length === 0 &&
227
+ entry.gaps.length === 0 &&
228
+ entry.errors.length === 0 &&
229
+ entry.causalLinks.length === 0
230
+ );
246
231
  }
247
232
 
248
233
  function validCausalLink(link) {
249
- return link.kind === "outcome"
250
- ? exactOwnedLink(link.deepLink, "outcome", link.subjectId)
251
- : link.deepLink === null;
234
+ return link.kind === 'outcome'
235
+ ? exactOwnedLink(link.deepLink, 'outcome', link.subjectId)
236
+ : link.deepLink === null;
252
237
  }
253
238
 
254
239
  function validEvidenceData(data) {
255
- const evidence = new Map(
256
- data.evidence.map((entry) => [entry.evidenceRefId, entry]),
257
- );
258
- const claims = new Map(data.claims.map((entry) => [entry.claimId, entry]));
259
- if (
260
- !uniqueRows(data.evidence, "evidenceRefId") ||
261
- !uniqueRows(data.claims, "claimId") ||
262
- !data.evidence.every(
263
- (entry) =>
264
- restrictedEvidenceIsClosed(entry) &&
265
- exactOwnedLink(entry.deepLink, "evidence", entry.evidenceRefId) &&
266
- entry.causalLinks.every(validCausalLink),
267
- ) ||
268
- !data.claims.every(
269
- (entry) =>
270
- restrictedClaimIsClosed(entry) &&
271
- exactOwnedLink(entry.deepLink, "evidence", entry.claimId) &&
272
- entry.causalLinks.every(validCausalLink),
273
- )
274
- )
275
- return false;
276
- for (const entry of data.evidence) {
277
- if (
278
- !entry.supportClaimIds.every((id) =>
279
- claims.get(id)?.supportEvidenceRefIds.includes(entry.evidenceRefId),
280
- ) ||
281
- !entry.contradictClaimIds.every((id) =>
282
- claims.get(id)?.contradictEvidenceRefIds.includes(entry.evidenceRefId),
283
- )
284
- )
285
- return false;
286
- }
287
- return data.claims.every(
288
- (entry) =>
289
- entry.supportEvidenceRefIds.every((id) =>
290
- evidence.get(id)?.supportClaimIds.includes(entry.claimId),
291
- ) &&
292
- entry.contradictEvidenceRefIds.every((id) =>
293
- evidence.get(id)?.contradictClaimIds.includes(entry.claimId),
294
- ),
295
- );
240
+ const evidence = new Map(data.evidence.map((entry) => [entry.evidenceRefId, entry]));
241
+ const claims = new Map(data.claims.map((entry) => [entry.claimId, entry]));
242
+ if (
243
+ !uniqueRows(data.evidence, 'evidenceRefId') ||
244
+ !uniqueRows(data.claims, 'claimId') ||
245
+ !data.evidence.every(
246
+ (entry) =>
247
+ restrictedEvidenceIsClosed(entry) &&
248
+ exactOwnedLink(entry.deepLink, 'evidence', entry.evidenceRefId) &&
249
+ entry.causalLinks.every(validCausalLink),
250
+ ) ||
251
+ !data.claims.every(
252
+ (entry) =>
253
+ restrictedClaimIsClosed(entry) &&
254
+ exactOwnedLink(entry.deepLink, 'evidence', entry.claimId) &&
255
+ entry.causalLinks.every(validCausalLink),
256
+ )
257
+ )
258
+ return false;
259
+ for (const entry of data.evidence) {
260
+ if (
261
+ !entry.supportClaimIds.every((id) =>
262
+ claims.get(id)?.supportEvidenceRefIds.includes(entry.evidenceRefId),
263
+ ) ||
264
+ !entry.contradictClaimIds.every((id) =>
265
+ claims.get(id)?.contradictEvidenceRefIds.includes(entry.evidenceRefId),
266
+ )
267
+ )
268
+ return false;
269
+ }
270
+ return data.claims.every(
271
+ (entry) =>
272
+ entry.supportEvidenceRefIds.every((id) =>
273
+ evidence.get(id)?.supportClaimIds.includes(entry.claimId),
274
+ ) &&
275
+ entry.contradictEvidenceRefIds.every((id) =>
276
+ evidence.get(id)?.contradictClaimIds.includes(entry.claimId),
277
+ ),
278
+ );
296
279
  }
297
280
 
298
281
  function visibleAffirmativeOutcome(outcome) {
299
- return (
300
- outcome.accessReason === null &&
301
- outcome.observationIds.length > 0 &&
302
- outcome.evidenceRefIds.length > 0 &&
303
- outcome.metric.observed !== null &&
304
- outcome.metric.freshness === "current" &&
305
- outcome.verification.accessReason === null
306
- );
282
+ return (
283
+ outcome.accessReason === null &&
284
+ outcome.observationIds.length > 0 &&
285
+ outcome.evidenceRefIds.length > 0 &&
286
+ outcome.metric.observed !== null &&
287
+ outcome.metric.freshness === 'current' &&
288
+ outcome.verification.accessReason === null
289
+ );
307
290
  }
308
291
 
309
292
  function restrictedOutcome(outcome) {
310
- return (
311
- outcome.accessReason === "access-denied" &&
312
- outcome.observationIds.length === 0 &&
313
- outcome.evidenceRefIds.length === 0 &&
314
- outcome.metric.baseline === null &&
315
- outcome.metric.target === null &&
316
- outcome.metric.observed === null &&
317
- outcome.metric.unit === null &&
318
- outcome.metric.window === null &&
319
- outcome.metric.confidence === null &&
320
- outcome.verification.accessReason === "access-denied" &&
321
- outcome.verification.method === null &&
322
- outcome.verification.evaluationRules.length === 0 &&
323
- outcome.verification.observationRequest === null &&
324
- outcome.nextObservation === null &&
325
- outcome.revisit === null
326
- );
293
+ return (
294
+ outcome.accessReason === 'access-denied' &&
295
+ outcome.observationIds.length === 0 &&
296
+ outcome.evidenceRefIds.length === 0 &&
297
+ outcome.metric.baseline === null &&
298
+ outcome.metric.target === null &&
299
+ outcome.metric.observed === null &&
300
+ outcome.metric.unit === null &&
301
+ outcome.metric.window === null &&
302
+ outcome.metric.confidence === null &&
303
+ outcome.verification.accessReason === 'access-denied' &&
304
+ outcome.verification.method === null &&
305
+ outcome.verification.evaluationRules.length === 0 &&
306
+ outcome.verification.observationRequest === null &&
307
+ outcome.nextObservation === null &&
308
+ outcome.revisit === null
309
+ );
327
310
  }
328
311
 
329
312
  function restrictedAffirmativeOutcome(outcome) {
330
- return (
331
- ["succeeded", "failed"].includes(outcome.status) &&
332
- restrictedOutcome(outcome)
333
- );
313
+ return ['succeeded', 'failed'].includes(outcome.status) && restrictedOutcome(outcome);
334
314
  }
335
315
 
336
316
  function validOutcomeTuple(outcome) {
337
- const metric = outcome.metric;
338
- const verification = outcome.verification;
339
- if (
340
- metric === null ||
341
- verification === null ||
342
- outcome.verificationPlanId !== verification.verificationPlanId ||
343
- metric.metricId !== verification.metricId ||
344
- metric.metricHash !== verification.metricHash ||
345
- !exactOwnedLink(outcome.deepLink, "outcome", outcome.outcomeId) ||
346
- (outcome.decision !== null && outcome.decision.deepLink !== null) ||
347
- !outcome.execution.every((entry) => entry.deepLink === null) ||
348
- !outcome.rollback.every((entry) => entry.deepLink === null)
349
- )
350
- return false;
351
- if (
352
- (outcome.accessReason === "access-denied" ||
353
- verification.accessReason === "access-denied") &&
354
- !restrictedOutcome(outcome)
355
- )
356
- return false;
357
- if (outcome.status === "insufficient-evidence") {
358
- return (
359
- metric.observed === null &&
360
- outcome.observationIds.length === 0 &&
361
- outcome.evidenceRefIds.length === 0 &&
362
- outcome.snapshot === null &&
363
- outcome.delta === null
364
- );
365
- }
366
- return (
367
- !["succeeded", "failed"].includes(outcome.status) ||
368
- visibleAffirmativeOutcome(outcome) ||
369
- restrictedAffirmativeOutcome(outcome)
370
- );
317
+ const metric = outcome.metric;
318
+ const verification = outcome.verification;
319
+ if (
320
+ metric === null ||
321
+ verification === null ||
322
+ outcome.verificationPlanId !== verification.verificationPlanId ||
323
+ metric.metricId !== verification.metricId ||
324
+ metric.metricHash !== verification.metricHash ||
325
+ !exactOwnedLink(outcome.deepLink, 'outcome', outcome.outcomeId) ||
326
+ (outcome.decision !== null && outcome.decision.deepLink !== null) ||
327
+ !outcome.execution.every((entry) => entry.deepLink === null) ||
328
+ !outcome.rollback.every((entry) => entry.deepLink === null)
329
+ )
330
+ return false;
331
+ if (
332
+ (outcome.accessReason === 'access-denied' || verification.accessReason === 'access-denied') &&
333
+ !restrictedOutcome(outcome)
334
+ )
335
+ return false;
336
+ if (outcome.status === 'insufficient-evidence') {
337
+ return (
338
+ metric.observed === null &&
339
+ outcome.observationIds.length === 0 &&
340
+ outcome.evidenceRefIds.length === 0 &&
341
+ outcome.snapshot === null &&
342
+ outcome.delta === null
343
+ );
344
+ }
345
+ return (
346
+ !['succeeded', 'failed'].includes(outcome.status) ||
347
+ visibleAffirmativeOutcome(outcome) ||
348
+ restrictedAffirmativeOutcome(outcome)
349
+ );
371
350
  }
372
351
 
373
352
  function validOutcomesData(data, detail = false) {
374
- const outcomes = detail ? [data.outcome] : data.outcomes;
375
- if (!uniqueRows(outcomes, "outcomeId") || !outcomes.every(validOutcomeTuple))
376
- return false;
377
- if (
378
- !detail &&
379
- !data.domainMetrics.every((entry) =>
380
- entry.dueVerification.every((item) => item.deepLink === null),
381
- )
382
- )
383
- return false;
384
- const outcomeIds = new Set(outcomes.map((entry) => entry.outcomeId));
385
- return (
386
- uniqueRows(data.learnings, "learningId") &&
387
- data.learnings.every((entry) => outcomeIds.has(entry.outcomeId))
388
- );
353
+ const outcomes = detail ? [data.outcome] : data.outcomes;
354
+ if (!uniqueRows(outcomes, 'outcomeId') || !outcomes.every(validOutcomeTuple)) return false;
355
+ if (
356
+ !detail &&
357
+ !data.domainMetrics.every((entry) =>
358
+ entry.dueVerification.every((item) => item.deepLink === null),
359
+ )
360
+ )
361
+ return false;
362
+ const outcomeIds = new Set(outcomes.map((entry) => entry.outcomeId));
363
+ return (
364
+ uniqueRows(data.learnings, 'learningId') &&
365
+ data.learnings.every((entry) => outcomeIds.has(entry.outcomeId))
366
+ );
389
367
  }
390
368
 
391
369
  function validHistoryData(data, eventHead) {
392
- return (
393
- uniqueRows(data.history, "eventId") &&
394
- data.history.every((entry) =>
395
- entry.deepLinks.every((deepLink) => {
396
- const destination = ownedLinkDestination(deepLink);
397
- return destination?.surface === "evidence"
398
- ? destination.subjectId === entry.entityId ||
399
- entry.evidenceRefIds.includes(destination.subjectId)
400
- : destination?.surface === "outcome" &&
401
- destination.subjectId === entry.entityId;
402
- }),
403
- ) &&
404
- data.replay.liveAccessUsed === false &&
405
- exactEventHead(data.replay.finalHead, eventHead) &&
406
- data.replay.parityProof.finalEventHashMatches === true
407
- );
370
+ return (
371
+ uniqueRows(data.history, 'eventId') &&
372
+ data.history.every((entry) =>
373
+ entry.deepLinks.every((deepLink) => {
374
+ const destination = ownedLinkDestination(deepLink);
375
+ return destination?.surface === 'evidence'
376
+ ? destination.subjectId === entry.entityId ||
377
+ entry.evidenceRefIds.includes(destination.subjectId)
378
+ : destination?.surface === 'outcome' && destination.subjectId === entry.entityId;
379
+ }),
380
+ ) &&
381
+ data.replay.liveAccessUsed === false &&
382
+ exactEventHead(data.replay.finalHead, eventHead) &&
383
+ data.replay.parityProof.finalEventHashMatches === true
384
+ );
408
385
  }
409
386
 
410
387
  function validSearchData(data) {
411
- return data.results.every((entry) => {
412
- if (!hasOwn(entry, "deepLink")) return true;
413
- if (entry.kind === "evidence" || entry.kind === "claim")
414
- return exactOwnedLink(entry.deepLink, "evidence", entry.subjectId);
415
- if (entry.kind === "outcome")
416
- return exactOwnedLink(entry.deepLink, "outcome", entry.subjectId);
417
- if (entry.kind === "action")
418
- return exactOwnedLink(entry.deepLink, "action", entry.subjectId);
419
- if (entry.kind === "cycle")
420
- return exactOwnedLink(entry.deepLink, "cycle", entry.subjectId);
421
- if (entry.kind === "assignment") {
422
- if (entry.deepLink === null) return true;
423
- const match = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(entry.deepLink);
424
- return match !== null && validCanonicalSubjectSegment(match[1]);
425
- }
426
- return false;
427
- });
388
+ return data.results.every((entry) => {
389
+ if (!hasOwn(entry, 'deepLink')) return true;
390
+ if (entry.kind === 'evidence' || entry.kind === 'claim')
391
+ return exactOwnedLink(entry.deepLink, 'evidence', entry.subjectId);
392
+ if (entry.kind === 'outcome') return exactOwnedLink(entry.deepLink, 'outcome', entry.subjectId);
393
+ if (entry.kind === 'action') return exactOwnedLink(entry.deepLink, 'action', entry.subjectId);
394
+ if (entry.kind === 'cycle') return exactOwnedLink(entry.deepLink, 'cycle', entry.subjectId);
395
+ if (entry.kind === 'assignment') {
396
+ if (entry.deepLink === null) return true;
397
+ const match = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(entry.deepLink);
398
+ return match !== null && validCanonicalSubjectSegment(match[1]);
399
+ }
400
+ return false;
401
+ });
428
402
  }
429
403
 
430
404
  const EXPORT_ROOT_KEYS = [
431
- "kind",
432
- "schemaVersion",
433
- "protocolVersion",
434
- "scopeId",
435
- "domainId",
436
- "domainVersion",
437
- "generatedAt",
438
- "eventHead",
439
- "status",
440
- "attention",
441
- "domainMetrics",
442
- "cycles",
443
- "inbox",
444
- "actions",
445
- "evidence",
446
- "claims",
447
- "rationale",
448
- "outcomes",
449
- "learnings",
450
- "history",
451
- "replay",
452
- "omissions",
405
+ 'kind',
406
+ 'schemaVersion',
407
+ 'protocolVersion',
408
+ 'scopeId',
409
+ 'domainId',
410
+ 'domainVersion',
411
+ 'generatedAt',
412
+ 'eventHead',
413
+ 'status',
414
+ 'attention',
415
+ 'domainMetrics',
416
+ 'cycles',
417
+ 'inbox',
418
+ 'actions',
419
+ 'evidence',
420
+ 'claims',
421
+ 'rationale',
422
+ 'outcomes',
423
+ 'learnings',
424
+ 'history',
425
+ 'replay',
426
+ 'omissions',
453
427
  ].sort();
454
428
  const FORBIDDEN_EXPORT_FIELDS = new Set([
455
- "ownerActorId",
456
- "actorId",
457
- "partyId",
458
- "requiredCapability",
459
- "source",
460
- "producer",
461
- "provenance",
462
- "authority",
463
- "actionLocator",
464
- "rawHash",
465
- "canonicalHash",
429
+ 'ownerActorId',
430
+ 'actorId',
431
+ 'partyId',
432
+ 'requiredCapability',
433
+ 'source',
434
+ 'producer',
435
+ 'provenance',
436
+ 'authority',
437
+ 'actionLocator',
438
+ 'rawHash',
439
+ 'canonicalHash',
466
440
  ]);
467
441
 
468
442
  function validExportTree(value, seen = new Set()) {
469
- if (value === null || typeof value !== "object") return true;
470
- if (seen.has(value)) return false;
471
- seen.add(value);
472
- try {
473
- if (Array.isArray(value))
474
- return value.every((entry) => validExportTree(entry, seen));
475
- for (const [key, child] of Object.entries(value)) {
476
- if (FORBIDDEN_EXPORT_FIELDS.has(key)) return false;
477
- if (key === "errors" && (!Array.isArray(child) || child.length !== 0))
478
- return false;
479
- if (!validExportTree(child, seen)) return false;
480
- }
481
- return true;
482
- } finally {
483
- seen.delete(value);
484
- }
443
+ if (value === null || typeof value !== 'object') return true;
444
+ if (seen.has(value)) return false;
445
+ seen.add(value);
446
+ try {
447
+ if (Array.isArray(value)) return value.every((entry) => validExportTree(entry, seen));
448
+ for (const [key, child] of Object.entries(value)) {
449
+ if (FORBIDDEN_EXPORT_FIELDS.has(key)) return false;
450
+ if (key === 'errors' && (!Array.isArray(child) || child.length !== 0)) return false;
451
+ if (!validExportTree(child, seen)) return false;
452
+ }
453
+ return true;
454
+ } finally {
455
+ seen.delete(value);
456
+ }
485
457
  }
486
458
 
487
459
  function escapeHtml(value) {
488
- return value
489
- .replaceAll("&", "&")
490
- .replaceAll("<", "&lt;")
491
- .replaceAll(">", "&gt;");
460
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
492
461
  }
493
462
 
494
463
  function unescapeHtml(value) {
495
- return value
496
- .replaceAll("&lt;", "<")
497
- .replaceAll("&gt;", ">")
498
- .replaceAll("&amp;", "&");
464
+ return value.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&amp;', '&');
499
465
  }
500
466
 
501
467
  function validExportValue(value) {
502
- return (
503
- value !== null &&
504
- typeof value === "object" &&
505
- !Array.isArray(value) &&
506
- exactJson(Object.keys(value).sort(), EXPORT_ROOT_KEYS) &&
507
- validExportTree(value) &&
508
- validLinkProjection(value)
509
- );
468
+ return (
469
+ value !== null &&
470
+ typeof value === 'object' &&
471
+ !Array.isArray(value) &&
472
+ exactJson(Object.keys(value).sort(), EXPORT_ROOT_KEYS) &&
473
+ validExportTree(value) &&
474
+ validLinkProjection(value)
475
+ );
510
476
  }
511
477
 
512
478
  function canonicalizeExportValue(value) {
513
- if (Array.isArray(value))
514
- return value.map((entry) => canonicalizeExportValue(entry));
515
- if (value === null || typeof value !== "object") return value;
516
- return Object.fromEntries(
517
- Object.keys(value)
518
- .sort()
519
- .map((key) => [key, canonicalizeExportValue(value[key])]),
520
- );
479
+ if (Array.isArray(value)) return value.map((entry) => canonicalizeExportValue(entry));
480
+ if (value === null || typeof value !== 'object') return value;
481
+ return Object.fromEntries(
482
+ Object.keys(value)
483
+ .sort()
484
+ .map((key) => [key, canonicalizeExportValue(value[key])]),
485
+ );
521
486
  }
522
487
 
523
488
  function validExportData(data) {
524
- try {
525
- if (data.format === "json") {
526
- if (data.mediaType !== "application/json") return false;
527
- const value = JSON.parse(data.content);
528
- return (
529
- validExportValue(value) &&
530
- JSON.stringify(canonicalizeExportValue(value)) === data.content
531
- );
532
- }
533
- if (data.mediaType !== "text/html; charset=utf-8") return false;
534
- const prefix =
535
- '<!doctype html><html lang="en"><meta charset="utf-8"><title>OpenPlanr Operate audit export</title><body><main><h1>Operate audit export</h1><p>';
536
- const marker = "</p><pre>";
537
- const suffix = "</pre></main></body></html>";
538
- if (!data.content.startsWith(prefix) || !data.content.endsWith(suffix))
539
- return false;
540
- const markerIndex = data.content.indexOf(marker, prefix.length);
541
- if (markerIndex < 0) return false;
542
- const escapedJson = data.content.slice(
543
- markerIndex + marker.length,
544
- -suffix.length,
545
- );
546
- const value = JSON.parse(unescapeHtml(escapedJson));
547
- if (!validExportValue(value)) return false;
548
- const canonicalValue = canonicalizeExportValue(value);
549
- const expected = `${prefix}${escapeHtml(`${canonicalValue.domainId} / ${canonicalValue.scopeId}`)}${marker}${escapeHtml(JSON.stringify(canonicalValue, null, 2))}${suffix}`;
550
- return data.content === expected;
551
- } catch {
552
- return false;
553
- }
489
+ try {
490
+ if (data.format === 'json') {
491
+ if (data.mediaType !== 'application/json') return false;
492
+ const value = JSON.parse(data.content);
493
+ return (
494
+ validExportValue(value) && JSON.stringify(canonicalizeExportValue(value)) === data.content
495
+ );
496
+ }
497
+ if (data.mediaType !== 'text/html; charset=utf-8') return false;
498
+ const prefix =
499
+ '<!doctype html><html lang="en"><meta charset="utf-8"><title>OpenPlanr Operate audit export</title><body><main><h1>Operate audit export</h1><p>';
500
+ const marker = '</p><pre>';
501
+ const suffix = '</pre></main></body></html>';
502
+ if (!data.content.startsWith(prefix) || !data.content.endsWith(suffix)) return false;
503
+ const markerIndex = data.content.indexOf(marker, prefix.length);
504
+ if (markerIndex < 0) return false;
505
+ const escapedJson = data.content.slice(markerIndex + marker.length, -suffix.length);
506
+ const value = JSON.parse(unescapeHtml(escapedJson));
507
+ if (!validExportValue(value)) return false;
508
+ const canonicalValue = canonicalizeExportValue(value);
509
+ const expected = `${prefix}${escapeHtml(`${canonicalValue.domainId} / ${canonicalValue.scopeId}`)}${marker}${escapeHtml(JSON.stringify(canonicalValue, null, 2))}${suffix}`;
510
+ return data.content === expected;
511
+ } catch {
512
+ return false;
513
+ }
554
514
  }
555
515
 
556
516
  function validAuditPayloadSemantics(payload) {
557
- if (payload.surface === "evidence") return validEvidenceData(payload.data);
558
- if (payload.surface === "outcomes") return validOutcomesData(payload.data);
559
- if (payload.surface === "outcome")
560
- return validOutcomesData(payload.data, true);
561
- if (payload.surface === "history")
562
- return validHistoryData(payload.data, payload.eventHead);
563
- if (payload.surface === "search") return validSearchData(payload.data);
564
- if (payload.surface === "export") return validExportData(payload.data);
565
- return false;
517
+ if (payload.surface === 'evidence') return validEvidenceData(payload.data);
518
+ if (payload.surface === 'outcomes') return validOutcomesData(payload.data);
519
+ if (payload.surface === 'outcome') return validOutcomesData(payload.data, true);
520
+ if (payload.surface === 'history') return validHistoryData(payload.data, payload.eventHead);
521
+ if (payload.surface === 'search') return validSearchData(payload.data);
522
+ if (payload.surface === 'export') return validExportData(payload.data);
523
+ return false;
566
524
  }
567
525
 
568
526
  function validApplicableBinding(binding, payload) {
569
- if (
570
- binding.actorId !== payload.actorId ||
571
- binding.scopeId !== payload.scopeId ||
572
- binding.domainId !== payload.domainId ||
573
- binding.domainVersion !== payload.domainVersion ||
574
- binding.generatedAt !== payload.generatedAt ||
575
- binding.viewHash !== payload.viewHash ||
576
- binding.surface !== payload.surface ||
577
- !exactEventHead(binding.eventHead, payload.eventHead)
578
- )
579
- return false;
580
- if (binding.surface === "outcome") {
581
- return (
582
- typeof binding.subjectId === "string" &&
583
- binding.query === null &&
584
- binding.format === null &&
585
- payload.data.outcome?.outcomeId === binding.subjectId
586
- );
587
- }
588
- if (binding.surface === "evidence") {
589
- const subjectMatches =
590
- binding.subjectId === null ||
591
- payload.data.evidence?.some(
592
- (item) => item.evidenceRefId === binding.subjectId,
593
- ) ||
594
- payload.data.claims?.some((item) => item.claimId === binding.subjectId);
595
- return subjectMatches && binding.query === null && binding.format === null;
596
- }
597
- if (binding.surface === "search") {
598
- return (
599
- binding.subjectId === null &&
600
- typeof binding.query === "string" &&
601
- binding.query === payload.data.query &&
602
- binding.format === null
603
- );
604
- }
605
- if (binding.surface === "export") {
606
- return (
607
- binding.subjectId === null &&
608
- binding.query === null &&
609
- binding.format === payload.data.format
610
- );
611
- }
612
- return (
613
- binding.subjectId === null &&
614
- binding.query === null &&
615
- binding.format === null
616
- );
527
+ if (
528
+ binding.actorId !== payload.actorId ||
529
+ binding.scopeId !== payload.scopeId ||
530
+ binding.domainId !== payload.domainId ||
531
+ binding.domainVersion !== payload.domainVersion ||
532
+ binding.generatedAt !== payload.generatedAt ||
533
+ binding.viewHash !== payload.viewHash ||
534
+ binding.surface !== payload.surface ||
535
+ !exactEventHead(binding.eventHead, payload.eventHead)
536
+ )
537
+ return false;
538
+ if (binding.surface === 'outcome') {
539
+ return (
540
+ typeof binding.subjectId === 'string' &&
541
+ binding.query === null &&
542
+ binding.format === null &&
543
+ payload.data.outcome?.outcomeId === binding.subjectId
544
+ );
545
+ }
546
+ if (binding.surface === 'evidence') {
547
+ const subjectMatches =
548
+ binding.subjectId === null ||
549
+ payload.data.evidence?.some((item) => item.evidenceRefId === binding.subjectId) ||
550
+ payload.data.claims?.some((item) => item.claimId === binding.subjectId);
551
+ return subjectMatches && binding.query === null && binding.format === null;
552
+ }
553
+ if (binding.surface === 'search') {
554
+ return (
555
+ binding.subjectId === null &&
556
+ typeof binding.query === 'string' &&
557
+ binding.query === payload.data.query &&
558
+ binding.format === null
559
+ );
560
+ }
561
+ if (binding.surface === 'export') {
562
+ return (
563
+ binding.subjectId === null && binding.query === null && binding.format === payload.data.format
564
+ );
565
+ }
566
+ return binding.subjectId === null && binding.query === null && binding.format === null;
617
567
  }
618
568
 
619
569
  function validAuditSemantics(value, expected) {
620
- return (
621
- AUDIT_SURFACES.has(value.payload.surface) &&
622
- value.payload.readOnly === true &&
623
- value.payload.mutationEnabled === false &&
624
- value.integrity.sourceViewHash === value.payload.viewHash &&
625
- value.integrity.sourceViewHash === value.requestBinding.viewHash &&
626
- value.payload.truthSummary.sourceViewHash === value.payload.viewHash &&
627
- exactEventHead(value.payload.truthSummary.sourceEventHead, value.payload.eventHead) &&
628
- validApplicableBinding(value.requestBinding, value.payload) &&
629
- (expected === undefined || exactJson(value.requestBinding, expected)) &&
630
- validLinkProjection(value.payload.data) &&
631
- validAuditPayloadSemantics(value.payload) &&
632
- validLegacyPayload(value.payload)
633
- );
634
- }
635
-
636
- export function validateOperateExperienceAuditDisplaySurfaceV1(
637
- value,
638
- expected,
639
- ) {
640
- try {
641
- const clone = safeDataClone(value);
642
- const errors = validateJson(clone, auditDisplaySchema, {
643
- base: "schemas/v1.2.0/operate-experience-audit-display-surface.schema.json",
644
- resolveRef: resolveSchemaRef,
645
- });
646
- if (errors.length > 0 || !validAuditSemantics(clone, expected))
647
- return errors.length > 0 ? errors : validationFailure();
648
- return clone.integrity.contentHash ===
649
- contentHash(withoutContentHash(clone), clone.integrity.domain)
650
- ? []
651
- : validationFailure();
652
- } catch {
653
- return validationFailure();
654
- }
570
+ return (
571
+ AUDIT_SURFACES.has(value.payload.surface) &&
572
+ value.payload.readOnly === true &&
573
+ value.payload.mutationEnabled === false &&
574
+ value.integrity.sourceViewHash === value.payload.viewHash &&
575
+ value.integrity.sourceViewHash === value.requestBinding.viewHash &&
576
+ value.payload.truthSummary.sourceViewHash === value.payload.viewHash &&
577
+ exactEventHead(value.payload.truthSummary.sourceEventHead, value.payload.eventHead) &&
578
+ validApplicableBinding(value.requestBinding, value.payload) &&
579
+ (expected === undefined || exactJson(value.requestBinding, expected)) &&
580
+ validLinkProjection(value.payload.data) &&
581
+ validAuditPayloadSemantics(value.payload) &&
582
+ validLegacyPayload(value.payload)
583
+ );
584
+ }
585
+
586
+ export function validateOperateExperienceAuditDisplaySurfaceV1(value, expected) {
587
+ try {
588
+ const clone = safeDataClone(value);
589
+ const errors = validateJson(clone, auditDisplaySchema, {
590
+ base: 'schemas/v1.2.0/operate-experience-audit-display-surface.schema.json',
591
+ resolveRef: resolveSchemaRef,
592
+ });
593
+ if (errors.length > 0 || !validAuditSemantics(clone, expected))
594
+ return errors.length > 0 ? errors : validationFailure();
595
+ return clone.integrity.contentHash ===
596
+ contentHash(withoutContentHash(clone), clone.integrity.domain)
597
+ ? []
598
+ : validationFailure();
599
+ } catch {
600
+ return validationFailure();
601
+ }
655
602
  }
656
603
 
657
604
  export function assertOperateExperienceAuditDisplaySurfaceV1(value, expected) {
658
- if (
659
- validateOperateExperienceAuditDisplaySurfaceV1(value, expected).length > 0
660
- ) {
661
- const error = new TypeError(
662
- "The Operate audit display surface does not satisfy its closed integrity contract.",
663
- );
664
- error.code = "E_OPERATE_EXPERIENCE_AUDIT_DISPLAY_INVALID";
665
- throw error;
666
- }
667
- return value;
605
+ if (validateOperateExperienceAuditDisplaySurfaceV1(value, expected).length > 0) {
606
+ const error = new TypeError(
607
+ 'The Operate audit display surface does not satisfy its closed integrity contract.',
608
+ );
609
+ error.code = 'E_OPERATE_EXPERIENCE_AUDIT_DISPLAY_INVALID';
610
+ throw error;
611
+ }
612
+ return value;
668
613
  }
669
614
 
670
615
  export function issueOperateExperienceAuditDisplaySurfaceV1(payload, binding) {
671
- const selected = safeDataClone(payload);
672
- selected.readOnly = true;
673
- selected.mutationEnabled = false;
674
- const requestBinding = safeDataClone(binding);
675
- const base = {
676
- kind: "operate-experience-audit-display-surface",
677
- schemaVersion: "1.0.0",
678
- protocolVersion: "2.0.0",
679
- requestBinding,
680
- payload: selected,
681
- integrity: {
682
- algorithm: "sha-256-jcs",
683
- domain: AUDIT_DISPLAY_DOMAIN,
684
- sourceViewHash: selected.viewHash,
685
- },
686
- };
687
- const issued = {
688
- ...base,
689
- integrity: {
690
- ...base.integrity,
691
- contentHash: contentHash(base, AUDIT_DISPLAY_DOMAIN),
692
- },
693
- };
694
- assertOperateExperienceAuditDisplaySurfaceV1(issued, requestBinding);
695
- return deepFreeze(issued);
616
+ const selected = safeDataClone(payload);
617
+ selected.readOnly = true;
618
+ selected.mutationEnabled = false;
619
+ const requestBinding = safeDataClone(binding);
620
+ const base = {
621
+ kind: 'operate-experience-audit-display-surface',
622
+ schemaVersion: '1.0.0',
623
+ protocolVersion: '2.0.0',
624
+ requestBinding,
625
+ payload: selected,
626
+ integrity: {
627
+ algorithm: 'sha-256-jcs',
628
+ domain: AUDIT_DISPLAY_DOMAIN,
629
+ sourceViewHash: selected.viewHash,
630
+ },
631
+ };
632
+ const issued = {
633
+ ...base,
634
+ integrity: {
635
+ ...base.integrity,
636
+ contentHash: contentHash(base, AUDIT_DISPLAY_DOMAIN),
637
+ },
638
+ };
639
+ assertOperateExperienceAuditDisplaySurfaceV1(issued, requestBinding);
640
+ return deepFreeze(issued);
696
641
  }
697
642
 
698
643
  export const OPERATE_EXPERIENCE_AUDIT_DISPLAY_SURFACE_SCHEMA_V1 = Object.freeze(
699
- structuredClone(auditDisplaySchema),
644
+ structuredClone(auditDisplaySchema),
700
645
  );