@openplanr/protocol 0.6.1 → 0.7.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 +10 -0
- package/lib/dashboard/closed-json-contract.mjs +99 -109
- package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
- package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
- package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
- package/lib/dashboard/operate-experience-display-contract.mjs +777 -831
- package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
- package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
- package/lib/dashboard/operate-review-contract.d.mts +7 -14
- package/lib/dashboard/operate-review-contract.mjs +46 -42
- package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
- package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
- package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
- package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
- package/lib/protocol/index.d.ts +2647 -543
- package/package.json +1 -1
- package/registries/artifact-theme.json +64 -0
- package/registries/commands.json +40 -40
- package/registries/skills.json +5 -5
- package/schemas/v1.14.0/artifact-theme.schema.json +316 -0
- package/src/browser-contracts.d.mts +4 -1
- package/src/browser-contracts.mjs +16 -5
- package/src/canonical-json.d.mts +6 -1
- package/src/canonical-json.mjs +100 -22
- package/src/compat/live-evidence-v2.mjs +1611 -485
- package/src/compat/operate-experience-live-patch.mjs +67 -15
- package/src/compat/operating-planning-contracts.mjs +183 -51
- package/src/contracts.d.mts +54 -13
- package/src/contracts.mjs +635 -343
- package/src/design-contracts.mjs +58 -21
- package/src/design-handoff-contracts.d.mts +67 -11
- package/src/design-handoff-contracts.mjs +236 -119
- package/src/design-publication-contracts.mjs +98 -33
- package/src/diagram-authoring-contracts.d.mts +422 -78
- package/src/diagram-authoring-contracts.mjs +1715 -335
- package/src/diagram-contracts.d.mts +4 -1
- package/src/diagram-contracts.mjs +16 -4
- package/src/enterprise-contracts.d.mts +211 -46
- package/src/enterprise-contracts.mjs +738 -184
- package/src/errors.mjs +4 -0
- package/src/generated/canonical-registries.mjs +45 -45
- package/src/index.d.mts +8 -8
- package/src/index.mjs +36 -20
- package/src/json-schema.d.mts +21 -6
- package/src/json-schema.mjs +66 -18
- package/src/planning-contracts.d.mts +8 -2
- package/src/planning-contracts.mjs +33 -7
- package/src/registries.d.mts +11 -3
- package/src/registries.mjs +369 -87
- package/src/review-experience-contracts.d.mts +7 -2
- package/src/review-experience-contracts.mjs +198 -49
- package/src/semver.mjs +5 -1
- package/src/skill-source-contracts.d.mts +36 -16
- package/src/skill-source-contracts.mjs +25 -6
- package/src/task-contracts.d.mts +13 -3
- package/src/task-contracts.mjs +181 -40
- package/src/workspace-contracts.d.mts +38 -10
- package/src/workspace-contracts.mjs +147 -33
|
@@ -1,700 +1,645 @@
|
|
|
1
1
|
import { validateJson } from '../../src/json-schema.mjs';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from
|
|
3
|
+
contentHash,
|
|
4
|
+
deepFreeze,
|
|
5
|
+
exactEventHead,
|
|
6
|
+
exactJson,
|
|
7
|
+
hasOwn,
|
|
8
|
+
safeDataClone,
|
|
9
|
+
withoutContentHash,
|
|
10
|
+
} from './closed-json-contract.mjs';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from
|
|
18
|
-
import { assertOperateExperienceSurfaceV1 } from
|
|
19
|
-
|
|
20
|
-
const AUDIT_DISPLAY_DOMAIN =
|
|
21
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
88
|
-
|
|
79
|
+
if (value === null) return true;
|
|
80
|
+
return ownedLinkDestination(value) !== null;
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
function exactOwnedLink(value, surface, subjectId) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
203
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
489
|
-
.replaceAll("&", "&")
|
|
490
|
-
.replaceAll("<", "<")
|
|
491
|
-
.replaceAll(">", ">");
|
|
460
|
+
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
492
461
|
}
|
|
493
462
|
|
|
494
463
|
function unescapeHtml(value) {
|
|
495
|
-
|
|
496
|
-
.replaceAll("<", "<")
|
|
497
|
-
.replaceAll(">", ">")
|
|
498
|
-
.replaceAll("&", "&");
|
|
464
|
+
return value.replaceAll('<', '<').replaceAll('>', '>').replaceAll('&', '&');
|
|
499
465
|
}
|
|
500
466
|
|
|
501
467
|
function validExportValue(value) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
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
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
export function validateOperateExperienceAuditDisplaySurfaceV1(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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
|
-
|
|
644
|
+
structuredClone(auditDisplaySchema),
|
|
700
645
|
);
|