@openplanr/protocol 0.11.0 → 0.12.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/package.json +5 -1
- package/registries/commands.json +2 -2
- package/schemas/v1.19.0/company-resource-upload-prepare.schema.json +187 -0
- package/schemas/v1.19.0/company-resource-upload-receipt.schema.json +184 -0
- package/schemas/v1.19.0/company-resource-upload-status.schema.json +303 -0
- package/schemas/v1.19.0/enterprise-artifact-page.schema.json +267 -0
- package/schemas/v1.19.0/enterprise-guest-authorization.schema.json +179 -0
- package/schemas/v1.19.0/enterprise-guest-invitation.schema.json +128 -0
- package/schemas/v1.19.0/enterprise-journey-capabilities.schema.json +83 -0
- package/schemas/v1.19.0/enterprise-project-lifecycle.schema.json +169 -0
- package/schemas/v1.19.0/enterprise-project-page.schema.json +164 -0
- package/schemas/v1.19.0/enterprise-project-transition.schema.json +65 -0
- package/schemas/v1.19.0/enterprise-review-mention.schema.json +178 -0
- package/schemas/v1.19.0/enterprise-review-projection.schema.json +278 -0
- package/src/browser-contracts.d.mts +6 -0
- package/src/browser-contracts.mjs +26 -0
- package/src/contracts.mjs +38 -0
- package/src/enterprise-journey-contracts.d.mts +331 -0
- package/src/enterprise-journey-contracts.mjs +671 -0
- package/src/generated/canonical-registries.mjs +2 -2
- package/src/index.d.mts +1 -1
- package/src/index.mjs +1 -1
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** Portable company revision, delivery and lifecycle contracts. Storage adapters verify authority. */
|
|
3
|
+
import { assertLargeObjectData } from './bounded-json-data.mjs';
|
|
4
|
+
import { canonicalizeJson, deepFreeze, sha256Hex } from './canonical-json.mjs';
|
|
5
|
+
import { ENTERPRISE_ACTIONS } from './enterprise-contracts.mjs';
|
|
6
|
+
import { ENTERPRISE_REVIEW_ANCHOR_V11_SCHEMA } from './enterprise-resource-contracts.mjs';
|
|
7
|
+
import { validateJson } from './json-schema.mjs';
|
|
8
|
+
import {
|
|
9
|
+
assertLargeObjectContract,
|
|
10
|
+
COMPANY_RESOURCE_UPLOAD_PREPARE_SCHEMA,
|
|
11
|
+
COMPANY_RESOURCE_UPLOAD_RECEIPT_SCHEMA,
|
|
12
|
+
COMPANY_RESOURCE_UPLOAD_STATUS_SCHEMA,
|
|
13
|
+
} from './large-object-contracts.mjs';
|
|
14
|
+
|
|
15
|
+
export const ENTERPRISE_JOURNEY_PROTOCOL_VERSION = '1.19.0';
|
|
16
|
+
const id = { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}(?![\\s\\S])' };
|
|
17
|
+
const revisionId = { type: 'string', pattern: '^[A-Za-z0-9_-]{1,128}(?![\\s\\S])' };
|
|
18
|
+
const operationId = { type: 'string', pattern: '^[A-Za-z0-9_-]{22,64}(?![\\s\\S])' };
|
|
19
|
+
const digest = { type: 'string', pattern: '^sha256:[a-f0-9]{64}(?![\\s\\S])' };
|
|
20
|
+
const hash = { type: 'string', pattern: '^[a-f0-9]{64}(?![\\s\\S])' };
|
|
21
|
+
const timestamp = {
|
|
22
|
+
type: 'string',
|
|
23
|
+
format: 'date-time',
|
|
24
|
+
maxLength: 40,
|
|
25
|
+
pattern: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z(?![\\s\\S])',
|
|
26
|
+
};
|
|
27
|
+
const integer = { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER };
|
|
28
|
+
const positive = { ...integer, minimum: 1 };
|
|
29
|
+
const closed = (properties, required = Object.keys(properties)) => ({
|
|
30
|
+
type: 'object',
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
properties,
|
|
33
|
+
required,
|
|
34
|
+
});
|
|
35
|
+
const list = (items, maxItems = 100, minItems = 0) => ({
|
|
36
|
+
type: 'array',
|
|
37
|
+
items,
|
|
38
|
+
maxItems,
|
|
39
|
+
minItems,
|
|
40
|
+
});
|
|
41
|
+
const scope = { organizationId: id, projectId: id };
|
|
42
|
+
const artifact = { ...scope, artifactId: id };
|
|
43
|
+
const pin = closed({ revisionId, contentDigest: digest, publicationId: id });
|
|
44
|
+
const envelope = (kind) => ({
|
|
45
|
+
kind: { const: `openplanr-${kind}` },
|
|
46
|
+
schemaVersion: { const: '1.0.0' },
|
|
47
|
+
protocolVersion: { const: ENTERPRISE_JOURNEY_PROTOCOL_VERSION },
|
|
48
|
+
});
|
|
49
|
+
const schema = (name, properties, required) => ({
|
|
50
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
51
|
+
$id: `https://openplanr.dev/schemas/v1.19.0/${name}.schema.json`,
|
|
52
|
+
'x-openplanr-contract': { id: name, version: ENTERPRISE_JOURNEY_PROTOCOL_VERSION },
|
|
53
|
+
...closed(properties, required),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const ENTERPRISE_GUEST_INVITATION_SCHEMA = deepFreeze(
|
|
57
|
+
schema('enterprise-guest-invitation', {
|
|
58
|
+
...envelope('enterprise-guest-invitation'),
|
|
59
|
+
...artifact,
|
|
60
|
+
invitationId: id,
|
|
61
|
+
deliveryOperationId: operationId,
|
|
62
|
+
inviterId: id,
|
|
63
|
+
recipientId: id,
|
|
64
|
+
role: { enum: ['reviewer', 'viewer'] },
|
|
65
|
+
binding: { const: 'fixed' },
|
|
66
|
+
pin,
|
|
67
|
+
deliveryStatus: { enum: ['queued', 'failed', 'delivered', 'expired'] },
|
|
68
|
+
grantStatus: { enum: ['pending', 'active', 'denied', 'revoked'] },
|
|
69
|
+
createdAt: timestamp,
|
|
70
|
+
expiresAt: timestamp,
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
const guestAuthorization = schema(
|
|
74
|
+
'enterprise-guest-authorization',
|
|
75
|
+
{
|
|
76
|
+
...envelope('enterprise-guest-authorization'),
|
|
77
|
+
...artifact,
|
|
78
|
+
authorizationId: id,
|
|
79
|
+
operationId,
|
|
80
|
+
invitationId: id,
|
|
81
|
+
actorId: id,
|
|
82
|
+
role: { enum: ['reviewer', 'viewer'] },
|
|
83
|
+
binding: { const: 'fixed' },
|
|
84
|
+
pin,
|
|
85
|
+
status: { enum: ['pending', 'active', 'denied', 'revoked'] },
|
|
86
|
+
lifecycleEpoch: positive,
|
|
87
|
+
expiresAt: timestamp,
|
|
88
|
+
receipt: closed({
|
|
89
|
+
receiptId: id,
|
|
90
|
+
operationId,
|
|
91
|
+
authorizedAt: timestamp,
|
|
92
|
+
publicationHeadAdvanced: { const: false },
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
[
|
|
96
|
+
'kind',
|
|
97
|
+
'schemaVersion',
|
|
98
|
+
'protocolVersion',
|
|
99
|
+
...Object.keys(artifact),
|
|
100
|
+
'authorizationId',
|
|
101
|
+
'operationId',
|
|
102
|
+
'invitationId',
|
|
103
|
+
'actorId',
|
|
104
|
+
'role',
|
|
105
|
+
'binding',
|
|
106
|
+
'pin',
|
|
107
|
+
'status',
|
|
108
|
+
'lifecycleEpoch',
|
|
109
|
+
'expiresAt',
|
|
110
|
+
],
|
|
111
|
+
);
|
|
112
|
+
Object.assign(guestAuthorization, {
|
|
113
|
+
allOf: [
|
|
114
|
+
{ if: { properties: { status: { const: 'active' } } }, then: { required: ['receipt'] } },
|
|
115
|
+
{
|
|
116
|
+
if: { properties: { status: { const: 'pending' } } },
|
|
117
|
+
then: { not: { required: ['receipt'] } },
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
export const ENTERPRISE_GUEST_AUTHORIZATION_SCHEMA = deepFreeze(guestAuthorization);
|
|
122
|
+
|
|
123
|
+
const projectQuery = closed({
|
|
124
|
+
organizationId: id,
|
|
125
|
+
actorId: id,
|
|
126
|
+
scope: { const: 'projects' },
|
|
127
|
+
filter: closed({
|
|
128
|
+
status: { enum: ['all', 'active', 'archived'] },
|
|
129
|
+
search: { type: 'string', maxLength: 240 },
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
const artifactQuery = closed({
|
|
133
|
+
...scope,
|
|
134
|
+
actorId: id,
|
|
135
|
+
scope: { const: 'artifacts' },
|
|
136
|
+
filter: closed(
|
|
137
|
+
{
|
|
138
|
+
kind: { enum: ['all', 'diagram', 'design', 'artifact'] },
|
|
139
|
+
contentFormat: {
|
|
140
|
+
enum: [
|
|
141
|
+
'all',
|
|
142
|
+
'diagram-authoring',
|
|
143
|
+
'design-review',
|
|
144
|
+
'planning-document',
|
|
145
|
+
'generic-artifact',
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
status: { enum: ['all', 'active', 'archived'] },
|
|
149
|
+
search: { type: 'string', maxLength: 240 },
|
|
150
|
+
},
|
|
151
|
+
['kind', 'status', 'search'],
|
|
152
|
+
),
|
|
153
|
+
});
|
|
154
|
+
const reviewQuery = {
|
|
155
|
+
oneOf: [
|
|
156
|
+
closed({
|
|
157
|
+
organizationId: id,
|
|
158
|
+
actorId: id,
|
|
159
|
+
scope: { const: 'organization-reviews' },
|
|
160
|
+
filter: artifactQuery.properties.filter,
|
|
161
|
+
}),
|
|
162
|
+
closed({
|
|
163
|
+
...scope,
|
|
164
|
+
actorId: id,
|
|
165
|
+
scope: { const: 'project-reviews' },
|
|
166
|
+
filter: artifactQuery.properties.filter,
|
|
167
|
+
}),
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
const query = { oneOf: [projectQuery, artifactQuery, ...reviewQuery.oneOf] };
|
|
171
|
+
const cursor = closed({
|
|
172
|
+
token: { type: 'string', minLength: 1, maxLength: 2048 },
|
|
173
|
+
queryDigest: hash,
|
|
174
|
+
});
|
|
175
|
+
const capabilities = {
|
|
176
|
+
...list({ enum: ENTERPRISE_ACTIONS }, ENTERPRISE_ACTIONS.length),
|
|
177
|
+
uniqueItems: true,
|
|
178
|
+
};
|
|
179
|
+
export const ENTERPRISE_PROJECT_PAGE_SCHEMA = deepFreeze(
|
|
180
|
+
schema('enterprise-project-page', {
|
|
181
|
+
...envelope('enterprise-project-page'),
|
|
182
|
+
query: projectQuery,
|
|
183
|
+
items: list(
|
|
184
|
+
closed({
|
|
185
|
+
organizationId: id,
|
|
186
|
+
projectId: id,
|
|
187
|
+
slug: { type: 'string', pattern: '^[A-Za-z0-9_-]{1,150}(?![\\s\\S])' },
|
|
188
|
+
name: { type: 'string', minLength: 1, maxLength: 240 },
|
|
189
|
+
status: { enum: ['active', 'archiving', 'archived', 'restoring'] },
|
|
190
|
+
capabilities,
|
|
191
|
+
}),
|
|
192
|
+
),
|
|
193
|
+
nextCursor: { oneOf: [cursor, { type: 'null' }] },
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
const artifactSummary = closed({
|
|
197
|
+
...artifact,
|
|
198
|
+
kind: { enum: ['diagram', 'design', 'artifact'] },
|
|
199
|
+
contentFormat: {
|
|
200
|
+
enum: ['diagram-authoring', 'design-review', 'planning-document', 'generic-artifact'],
|
|
201
|
+
},
|
|
202
|
+
title: { type: 'string', minLength: 1, maxLength: 240 },
|
|
203
|
+
revisionId: { oneOf: [revisionId, { type: 'null' }] },
|
|
204
|
+
status: { enum: ['active', 'archived'] },
|
|
205
|
+
capabilities,
|
|
206
|
+
});
|
|
207
|
+
artifactSummary.allOf = [
|
|
208
|
+
{
|
|
209
|
+
if: { properties: { kind: { const: 'diagram' } } },
|
|
210
|
+
then: { properties: { contentFormat: { const: 'diagram-authoring' } } },
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
if: { properties: { kind: { const: 'design' } } },
|
|
214
|
+
then: { properties: { contentFormat: { const: 'design-review' } } },
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
if: { properties: { kind: { const: 'artifact' } } },
|
|
218
|
+
then: { properties: { contentFormat: { enum: ['planning-document', 'generic-artifact'] } } },
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
export const ENTERPRISE_ARTIFACT_PAGE_SCHEMA = deepFreeze(
|
|
222
|
+
schema('enterprise-artifact-page', {
|
|
223
|
+
...envelope('enterprise-artifact-page'),
|
|
224
|
+
query: artifactQuery,
|
|
225
|
+
items: list(artifactSummary),
|
|
226
|
+
nextCursor: { oneOf: [cursor, { type: 'null' }] },
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
export const ENTERPRISE_REVIEW_PROJECTION_SCHEMA = deepFreeze(
|
|
230
|
+
schema('enterprise-review-projection', {
|
|
231
|
+
...envelope('enterprise-review-projection'),
|
|
232
|
+
query: reviewQuery,
|
|
233
|
+
items: list(
|
|
234
|
+
closed({
|
|
235
|
+
...artifact,
|
|
236
|
+
threadId: id,
|
|
237
|
+
revisionId,
|
|
238
|
+
publicationId: id,
|
|
239
|
+
category: { enum: ['question', 'suggestion', 'change-request', 'blocker'] },
|
|
240
|
+
status: { enum: ['open', 'addressed', 'resolved'] },
|
|
241
|
+
updatedAt: timestamp,
|
|
242
|
+
}),
|
|
243
|
+
),
|
|
244
|
+
nextCursor: { oneOf: [cursor, { type: 'null' }] },
|
|
245
|
+
index: closed({ status: { enum: ['current', 'lagging'] }, watermark: timestamp }),
|
|
246
|
+
}),
|
|
247
|
+
);
|
|
248
|
+
export const ENTERPRISE_REVIEW_MENTION_SCHEMA = deepFreeze(
|
|
249
|
+
schema('enterprise-review-mention', {
|
|
250
|
+
...envelope('enterprise-review-mention'),
|
|
251
|
+
...artifact,
|
|
252
|
+
operationId,
|
|
253
|
+
actorId: id,
|
|
254
|
+
threadId: id,
|
|
255
|
+
anchor: ENTERPRISE_REVIEW_ANCHOR_V11_SCHEMA,
|
|
256
|
+
recipients: { ...list(id, 50, 1), uniqueItems: true },
|
|
257
|
+
authority: { const: 'notification-only' },
|
|
258
|
+
}),
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
export const ENTERPRISE_PROJECT_LIFECYCLE_SCHEMA = deepFreeze(
|
|
262
|
+
schema(
|
|
263
|
+
'enterprise-project-lifecycle',
|
|
264
|
+
{
|
|
265
|
+
...envelope('enterprise-project-lifecycle'),
|
|
266
|
+
...scope,
|
|
267
|
+
status: { enum: ['active', 'archiving', 'archived', 'restoring'] },
|
|
268
|
+
version: integer,
|
|
269
|
+
epoch: positive,
|
|
270
|
+
updatedAt: timestamp,
|
|
271
|
+
operation: closed({
|
|
272
|
+
operationId,
|
|
273
|
+
action: { enum: ['archive', 'restore'] },
|
|
274
|
+
expectedVersion: integer,
|
|
275
|
+
previousEpoch: positive,
|
|
276
|
+
inventoryDigest: digest,
|
|
277
|
+
artifactCount: integer,
|
|
278
|
+
acknowledgedCount: integer,
|
|
279
|
+
acknowledgedInventoryDigest: { oneOf: [digest, { type: 'null' }] },
|
|
280
|
+
}),
|
|
281
|
+
receipt: closed({
|
|
282
|
+
receiptId: id,
|
|
283
|
+
operationId,
|
|
284
|
+
action: { enum: ['archive', 'restore'] },
|
|
285
|
+
version: integer,
|
|
286
|
+
epoch: positive,
|
|
287
|
+
completedAt: timestamp,
|
|
288
|
+
}),
|
|
289
|
+
},
|
|
290
|
+
[
|
|
291
|
+
'kind',
|
|
292
|
+
'schemaVersion',
|
|
293
|
+
'protocolVersion',
|
|
294
|
+
'organizationId',
|
|
295
|
+
'projectId',
|
|
296
|
+
'status',
|
|
297
|
+
'version',
|
|
298
|
+
'epoch',
|
|
299
|
+
'updatedAt',
|
|
300
|
+
],
|
|
301
|
+
),
|
|
302
|
+
);
|
|
303
|
+
export const ENTERPRISE_PROJECT_TRANSITION_SCHEMA = deepFreeze(
|
|
304
|
+
schema('enterprise-project-transition', {
|
|
305
|
+
...envelope('enterprise-project-transition'),
|
|
306
|
+
...scope,
|
|
307
|
+
operationId,
|
|
308
|
+
actorId: id,
|
|
309
|
+
action: { enum: ['archive', 'restore'] },
|
|
310
|
+
expectedVersion: integer,
|
|
311
|
+
expectedEpoch: positive,
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
export const ENTERPRISE_JOURNEY_FEATURES = Object.freeze([
|
|
315
|
+
'resource-draft',
|
|
316
|
+
'resource-publication',
|
|
317
|
+
'fixed-guest',
|
|
318
|
+
'project-lifecycle',
|
|
319
|
+
'review-mentions',
|
|
320
|
+
'scoped-pages',
|
|
321
|
+
]);
|
|
322
|
+
export const ENTERPRISE_JOURNEY_READER_REQUIREMENTS = deepFreeze({
|
|
323
|
+
'resource-draft': ['resource-draft', 'project-lifecycle'],
|
|
324
|
+
'resource-publication': ['resource-publication', 'fixed-guest', 'project-lifecycle'],
|
|
325
|
+
'fixed-guest': ['fixed-guest', 'project-lifecycle'],
|
|
326
|
+
'project-lifecycle': ['project-lifecycle'],
|
|
327
|
+
'review-mentions': ['review-mentions', 'fixed-guest', 'project-lifecycle'],
|
|
328
|
+
'scoped-pages': ['scoped-pages'],
|
|
329
|
+
});
|
|
330
|
+
export const ENTERPRISE_JOURNEY_CAPABILITIES_SCHEMA = deepFreeze(
|
|
331
|
+
schema('enterprise-journey-capabilities', {
|
|
332
|
+
...envelope('enterprise-journey-capabilities'),
|
|
333
|
+
readers: { ...list({ enum: ENTERPRISE_JOURNEY_FEATURES }, 6), uniqueItems: true },
|
|
334
|
+
writers: { ...list({ enum: ENTERPRISE_JOURNEY_FEATURES }, 6), uniqueItems: true },
|
|
335
|
+
rollbackFloor: closed({
|
|
336
|
+
protocolVersion: { const: '1.19.0' },
|
|
337
|
+
serviceVersion: id,
|
|
338
|
+
candidateDigest: digest,
|
|
339
|
+
}),
|
|
340
|
+
}),
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
function resourceSuccessor(source, name) {
|
|
344
|
+
const result = structuredClone(source);
|
|
345
|
+
result.$id = `https://openplanr.dev/schemas/v1.19.0/${name}.schema.json`;
|
|
346
|
+
result['x-openplanr-contract'] = { id: name, version: '1.19.0' };
|
|
347
|
+
result.properties.schemaVersion = { const: '2.1.0' };
|
|
348
|
+
result.properties.protocolVersion = { const: '1.19.0' };
|
|
349
|
+
result.required.push('protocolVersion');
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
const intent = { enum: ['draft', 'publish'] };
|
|
353
|
+
const prepare = resourceSuccessor(
|
|
354
|
+
COMPANY_RESOURCE_UPLOAD_PREPARE_SCHEMA,
|
|
355
|
+
'company-resource-upload-prepare',
|
|
356
|
+
);
|
|
357
|
+
Object.assign(prepare.properties, { intent, expectedVersion: integer, lifecycleEpoch: positive });
|
|
358
|
+
prepare.required.push('intent', 'expectedVersion', 'lifecycleEpoch');
|
|
359
|
+
export const COMPANY_RESOURCE_UPLOAD_PREPARE_V21_SCHEMA = deepFreeze(prepare);
|
|
360
|
+
const receipt = resourceSuccessor(
|
|
361
|
+
COMPANY_RESOURCE_UPLOAD_RECEIPT_SCHEMA,
|
|
362
|
+
'company-resource-upload-receipt',
|
|
363
|
+
);
|
|
364
|
+
Object.assign(receipt.properties, {
|
|
365
|
+
intent,
|
|
366
|
+
baseRevisionId: prepare.properties.baseRevisionId,
|
|
367
|
+
version: positive,
|
|
368
|
+
lifecycleEpoch: positive,
|
|
369
|
+
effect: {
|
|
370
|
+
oneOf: [
|
|
371
|
+
closed({
|
|
372
|
+
kind: { const: 'draft' },
|
|
373
|
+
authorHeadRevisionId: revisionId,
|
|
374
|
+
publicationHeadUnchanged: { const: true },
|
|
375
|
+
}),
|
|
376
|
+
closed({
|
|
377
|
+
kind: { const: 'publication' },
|
|
378
|
+
authorHeadRevisionId: revisionId,
|
|
379
|
+
publicationId: id,
|
|
380
|
+
publicationRevisionId: revisionId,
|
|
381
|
+
}),
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
receipt.required.push('intent', 'baseRevisionId', 'version', 'lifecycleEpoch', 'effect');
|
|
386
|
+
receipt.allOf = [
|
|
387
|
+
{
|
|
388
|
+
if: { properties: { intent: { const: 'draft' } } },
|
|
389
|
+
then: { properties: { effect: { properties: { kind: { const: 'draft' } } } } },
|
|
390
|
+
else: { properties: { effect: { properties: { kind: { const: 'publication' } } } } },
|
|
391
|
+
},
|
|
392
|
+
];
|
|
393
|
+
export const COMPANY_RESOURCE_UPLOAD_RECEIPT_V21_SCHEMA = deepFreeze(receipt);
|
|
394
|
+
const status = resourceSuccessor(
|
|
395
|
+
COMPANY_RESOURCE_UPLOAD_STATUS_SCHEMA,
|
|
396
|
+
'company-resource-upload-status',
|
|
397
|
+
);
|
|
398
|
+
Object.assign(status.properties, {
|
|
399
|
+
intent,
|
|
400
|
+
revisionId: operationId,
|
|
401
|
+
manifestSha256: hash,
|
|
402
|
+
expiresAt: timestamp,
|
|
403
|
+
lifecycleEpoch: positive,
|
|
404
|
+
status: { enum: ['prepared', 'committed', 'cancelled', 'expired'] },
|
|
405
|
+
receipt: COMPANY_RESOURCE_UPLOAD_RECEIPT_V21_SCHEMA,
|
|
406
|
+
});
|
|
407
|
+
status.required.push('intent', 'revisionId', 'manifestSha256', 'expiresAt', 'lifecycleEpoch');
|
|
408
|
+
status.allOf = [
|
|
409
|
+
{
|
|
410
|
+
if: { properties: { status: { const: 'committed' } } },
|
|
411
|
+
then: { required: ['receipt'] },
|
|
412
|
+
else: { not: { required: ['receipt'] } },
|
|
413
|
+
},
|
|
414
|
+
];
|
|
415
|
+
export const COMPANY_RESOURCE_UPLOAD_STATUS_V21_SCHEMA = deepFreeze(status);
|
|
416
|
+
|
|
417
|
+
export const ENTERPRISE_JOURNEY_SCHEMAS = deepFreeze({
|
|
418
|
+
'enterprise-guest-invitation': ENTERPRISE_GUEST_INVITATION_SCHEMA,
|
|
419
|
+
'enterprise-guest-authorization': ENTERPRISE_GUEST_AUTHORIZATION_SCHEMA,
|
|
420
|
+
'enterprise-project-page': ENTERPRISE_PROJECT_PAGE_SCHEMA,
|
|
421
|
+
'enterprise-artifact-page': ENTERPRISE_ARTIFACT_PAGE_SCHEMA,
|
|
422
|
+
'enterprise-review-projection': ENTERPRISE_REVIEW_PROJECTION_SCHEMA,
|
|
423
|
+
'enterprise-review-mention': ENTERPRISE_REVIEW_MENTION_SCHEMA,
|
|
424
|
+
'enterprise-project-lifecycle': ENTERPRISE_PROJECT_LIFECYCLE_SCHEMA,
|
|
425
|
+
'enterprise-project-transition': ENTERPRISE_PROJECT_TRANSITION_SCHEMA,
|
|
426
|
+
'enterprise-journey-capabilities': ENTERPRISE_JOURNEY_CAPABILITIES_SCHEMA,
|
|
427
|
+
'company-resource-upload-prepare': COMPANY_RESOURCE_UPLOAD_PREPARE_V21_SCHEMA,
|
|
428
|
+
'company-resource-upload-receipt': COMPANY_RESOURCE_UPLOAD_RECEIPT_V21_SCHEMA,
|
|
429
|
+
'company-resource-upload-status': COMPANY_RESOURCE_UPLOAD_STATUS_V21_SCHEMA,
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
/** Structural and identity consistency only; current authenticated records come from the adapter. */
|
|
433
|
+
export function assertEnterpriseJourneyContract(value, kind) {
|
|
434
|
+
assertLargeObjectData(value);
|
|
435
|
+
const selected = Object.hasOwn(ENTERPRISE_JOURNEY_SCHEMAS, kind)
|
|
436
|
+
? ENTERPRISE_JOURNEY_SCHEMAS[kind]
|
|
437
|
+
: null;
|
|
438
|
+
if (!selected) throw new TypeError('Unknown company journey contract.');
|
|
439
|
+
const errors = validateJson(value, selected);
|
|
440
|
+
if (errors.length) throw new TypeError(`Invalid ${kind}: ${errors[0].path} ${errors[0].detail}`);
|
|
441
|
+
assertCalendarTimestamps(value);
|
|
442
|
+
const check = semanticChecks[kind];
|
|
443
|
+
if (check) check(value);
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
// JSON Schema date-time checks are lexical; reject impossible calendar dates too.
|
|
447
|
+
function assertCalendarTimestamps(value) {
|
|
448
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
449
|
+
if (key.endsWith('At') || key === 'watermark') {
|
|
450
|
+
const time = Date.parse(nested);
|
|
451
|
+
if (
|
|
452
|
+
!Number.isFinite(time) ||
|
|
453
|
+
new Date(time).toISOString().replace('.000Z', 'Z') !== nested.replace('.000Z', 'Z')
|
|
454
|
+
)
|
|
455
|
+
throw new TypeError('Expected an actual UTC calendar timestamp.');
|
|
456
|
+
} else if (nested && typeof nested === 'object') assertCalendarTimestamps(nested);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const semanticChecks = {
|
|
460
|
+
'enterprise-guest-invitation': (value) => {
|
|
461
|
+
if (Date.parse(value.expiresAt) <= Date.parse(value.createdAt))
|
|
462
|
+
throw new TypeError('Invitation expiry must follow creation.');
|
|
463
|
+
},
|
|
464
|
+
'enterprise-guest-authorization': (value) => {
|
|
465
|
+
if (value.receipt && value.receipt.operationId !== value.operationId)
|
|
466
|
+
throw new TypeError('Guest authorization needs its exact receipt.');
|
|
467
|
+
},
|
|
468
|
+
'enterprise-project-page': assertPage,
|
|
469
|
+
'enterprise-artifact-page': assertPage,
|
|
470
|
+
'enterprise-review-projection': assertPage,
|
|
471
|
+
'enterprise-project-lifecycle': assertLifecycle,
|
|
472
|
+
'enterprise-journey-capabilities': (value) => {
|
|
473
|
+
if (
|
|
474
|
+
value.writers.some((feature) =>
|
|
475
|
+
ENTERPRISE_JOURNEY_READER_REQUIREMENTS[feature].some(
|
|
476
|
+
(reader) => !value.readers.includes(reader),
|
|
477
|
+
),
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
throw new TypeError('A writer requires its compatible reader.');
|
|
481
|
+
},
|
|
482
|
+
'company-resource-upload-prepare': (value) =>
|
|
483
|
+
assertLargeObjectContract(value.manifest, 'company-resource-manifest'),
|
|
484
|
+
'company-resource-upload-receipt': assertResourceReceipt,
|
|
485
|
+
'company-resource-upload-status': assertResourceStatus,
|
|
486
|
+
};
|
|
487
|
+
function assertPage(value) {
|
|
488
|
+
if (value.nextCursor && value.nextCursor.queryDigest !== enterprisePageQueryDigest(value.query))
|
|
489
|
+
throw new TypeError('Cursor does not match the selected actor, project and filters.');
|
|
490
|
+
if (
|
|
491
|
+
value.items.some(
|
|
492
|
+
(item) =>
|
|
493
|
+
item.organizationId !== value.query.organizationId ||
|
|
494
|
+
(value.query.projectId && item.projectId !== value.query.projectId),
|
|
495
|
+
)
|
|
496
|
+
)
|
|
497
|
+
throw new TypeError('Page contains another project.');
|
|
498
|
+
}
|
|
499
|
+
function assertResourceReceipt(value) {
|
|
500
|
+
if (
|
|
501
|
+
(value.intent === 'draft') !== (value.effect.kind === 'draft') ||
|
|
502
|
+
value.effect.authorHeadRevisionId !== value.revisionId ||
|
|
503
|
+
(value.intent === 'publish' && value.effect.publicationRevisionId !== value.revisionId)
|
|
504
|
+
)
|
|
505
|
+
throw new TypeError('Commit effect does not match the exact revision and intent.');
|
|
506
|
+
}
|
|
507
|
+
function assertResourceStatus(value) {
|
|
508
|
+
if (new Set(value.receivedChunks.map((part) => part.index)).size !== value.receivedChunks.length)
|
|
509
|
+
throw new TypeError('Upload status has repeated chunks.');
|
|
510
|
+
if (!value.receipt) return;
|
|
511
|
+
assertEnterpriseJourneyContract(value.receipt, 'company-resource-upload-receipt');
|
|
512
|
+
if (
|
|
513
|
+
['operationId', 'revisionId', 'manifestSha256', 'intent', 'lifecycleEpoch'].some(
|
|
514
|
+
(key) => value[key] !== value.receipt[key],
|
|
515
|
+
)
|
|
516
|
+
)
|
|
517
|
+
throw new TypeError('Upload status identity differs from its receipt.');
|
|
518
|
+
}
|
|
519
|
+
function sameScope(left, right) {
|
|
520
|
+
return ['organizationId', 'projectId'].every((key) => left[key] === right[key]);
|
|
521
|
+
}
|
|
522
|
+
function assertLifecycle(value) {
|
|
523
|
+
const { operation, receipt: completed } = value;
|
|
524
|
+
if (['archiving', 'restoring', 'archived'].includes(value.status) && !operation)
|
|
525
|
+
throw new TypeError('A lifecycle transition needs its durable operation.');
|
|
526
|
+
if (!operation) {
|
|
527
|
+
if (completed) throw new TypeError('A lifecycle receipt needs its operation.');
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (
|
|
531
|
+
value.epoch !== operation.previousEpoch + 1 ||
|
|
532
|
+
value.version !== operation.expectedVersion + (completed ? 2 : 1)
|
|
533
|
+
)
|
|
534
|
+
throw new TypeError('Lifecycle epoch or version differs from its transition.');
|
|
535
|
+
if (
|
|
536
|
+
operation.acknowledgedCount > operation.artifactCount ||
|
|
537
|
+
(operation.acknowledgedInventoryDigest !== null &&
|
|
538
|
+
operation.acknowledgedInventoryDigest !== operation.inventoryDigest)
|
|
539
|
+
)
|
|
540
|
+
throw new TypeError('Barrier acknowledgements differ from the frozen inventory.');
|
|
541
|
+
const terminal = value.status === 'archived' || value.status === 'active';
|
|
542
|
+
if (
|
|
543
|
+
terminal !== Boolean(completed) ||
|
|
544
|
+
(operation.action === 'archive') !== ['archiving', 'archived'].includes(value.status)
|
|
545
|
+
)
|
|
546
|
+
throw new TypeError('Lifecycle status differs from its operation.');
|
|
547
|
+
if (completed) assertLifecycleReceipt(value, operation, completed);
|
|
548
|
+
}
|
|
549
|
+
function assertLifecycleReceipt(value, operation, completed) {
|
|
550
|
+
if (
|
|
551
|
+
operation.acknowledgedCount !== operation.artifactCount ||
|
|
552
|
+
operation.acknowledgedInventoryDigest !== operation.inventoryDigest ||
|
|
553
|
+
['operationId', 'action'].some((key) => completed[key] !== operation[key]) ||
|
|
554
|
+
['epoch', 'version'].some((key) => completed[key] !== value[key])
|
|
555
|
+
)
|
|
556
|
+
throw new TypeError('Lifecycle completion needs all barriers and its exact receipt.');
|
|
557
|
+
}
|
|
558
|
+
export function enterprisePageQueryDigest(value) {
|
|
559
|
+
assertLargeObjectData(value);
|
|
560
|
+
const errors = validateJson(value, query);
|
|
561
|
+
if (errors.length) throw new TypeError('Invalid scoped page query.');
|
|
562
|
+
return sha256Hex(canonicalizeJson(value));
|
|
563
|
+
}
|
|
564
|
+
/** Fail closed before any new-mode bytes are sent. Deployment readiness is verified separately. */
|
|
565
|
+
export function assertEnterpriseJourneyWrite(capabilities, feature) {
|
|
566
|
+
assertEnterpriseJourneyContract(capabilities, 'enterprise-journey-capabilities');
|
|
567
|
+
if (!capabilities.writers.includes(feature) || !capabilities.readers.includes(feature))
|
|
568
|
+
throw new TypeError('The selected company write mode is not supported.');
|
|
569
|
+
return feature;
|
|
570
|
+
}
|
|
571
|
+
/** Exact upload retries cannot change intent, basis, scope, epoch or frozen bytes. */
|
|
572
|
+
export function assertCompanyResourcePreparationRetry(previous, next) {
|
|
573
|
+
for (const value of [previous, next])
|
|
574
|
+
assertEnterpriseJourneyContract(value, 'company-resource-upload-prepare');
|
|
575
|
+
if (canonicalizeJson(previous) !== canonicalizeJson(next))
|
|
576
|
+
throw new TypeError('A prepared upload identity cannot change.');
|
|
577
|
+
return next;
|
|
578
|
+
}
|
|
579
|
+
/** Authenticated recipient eligibility is supplied by the server for this exact anchored revision. */
|
|
580
|
+
export function assertEnterpriseMentionRecipients(value, authorization) {
|
|
581
|
+
assertEnterpriseJourneyContract(value, 'enterprise-review-mention');
|
|
582
|
+
assertLargeObjectData(authorization);
|
|
583
|
+
if (
|
|
584
|
+
!sameScope(value, authorization) ||
|
|
585
|
+
value.artifactId !== authorization.artifactId ||
|
|
586
|
+
value.anchor.revisionId !== authorization.revisionId ||
|
|
587
|
+
value.actorId !== authorization.actorId ||
|
|
588
|
+
!Array.isArray(authorization.recipientIds) ||
|
|
589
|
+
value.recipients.some((entry) => !authorization.recipientIds.includes(entry))
|
|
590
|
+
)
|
|
591
|
+
throw new TypeError('Mention recipients are not authorized on the anchored revision.');
|
|
592
|
+
return value;
|
|
593
|
+
}
|
|
594
|
+
/** No following-head fallback is permitted for a fixed guest. */
|
|
595
|
+
export function assertEnterpriseFixedGuestAccess(value, requested, now) {
|
|
596
|
+
assertEnterpriseJourneyContract(value, 'enterprise-guest-authorization');
|
|
597
|
+
assertLargeObjectData(requested);
|
|
598
|
+
if (
|
|
599
|
+
!Number.isFinite(Date.parse(now)) ||
|
|
600
|
+
value.status !== 'active' ||
|
|
601
|
+
Date.parse(value.expiresAt) <= Date.parse(now) ||
|
|
602
|
+
!sameScope(value, requested) ||
|
|
603
|
+
value.artifactId !== requested.artifactId ||
|
|
604
|
+
value.actorId !== requested.actorId ||
|
|
605
|
+
value.lifecycleEpoch !== requested.lifecycleEpoch ||
|
|
606
|
+
['revisionId', 'contentDigest', 'publicationId'].some(
|
|
607
|
+
(key) => value.pin[key] !== requested[key],
|
|
608
|
+
)
|
|
609
|
+
)
|
|
610
|
+
throw new TypeError('Guest access requires the exact active authorized publication.');
|
|
611
|
+
return value.pin;
|
|
612
|
+
}
|
|
613
|
+
/** The adapter rechecks this admission before delivering newly requested content. */
|
|
614
|
+
export function enterpriseProjectAdmission(value, epoch) {
|
|
615
|
+
assertEnterpriseJourneyContract(value, 'enterprise-project-lifecycle');
|
|
616
|
+
return value.status === 'active' && value.epoch === epoch;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/** Compare the command with the loaded lifecycle; the service must serialize the transition. */
|
|
620
|
+
export function assertEnterpriseProjectTransition(value, current) {
|
|
621
|
+
assertEnterpriseJourneyContract(value, 'enterprise-project-transition');
|
|
622
|
+
assertEnterpriseJourneyContract(current, 'enterprise-project-lifecycle');
|
|
623
|
+
if (
|
|
624
|
+
!sameScope(value, current) ||
|
|
625
|
+
value.expectedVersion !== current.version ||
|
|
626
|
+
value.expectedEpoch !== current.epoch ||
|
|
627
|
+
(value.action === 'archive' ? current.status !== 'active' : current.status !== 'archived')
|
|
628
|
+
)
|
|
629
|
+
throw new TypeError('Project lifecycle changed; reload before transitioning.');
|
|
630
|
+
return value;
|
|
631
|
+
}
|
|
632
|
+
/** The commit adapter compares this receipt with its already frozen preparation. */
|
|
633
|
+
export function assertCompanyResourceCommitReceipt(value, preparation) {
|
|
634
|
+
assertEnterpriseJourneyContract(value, 'company-resource-upload-receipt');
|
|
635
|
+
assertEnterpriseJourneyContract(preparation, 'company-resource-upload-prepare');
|
|
636
|
+
if (
|
|
637
|
+
!sameScope(value, preparation.manifest) ||
|
|
638
|
+
value.artifactId !== preparation.manifest.artifactId ||
|
|
639
|
+
value.operationId !== preparation.operationId ||
|
|
640
|
+
value.baseRevisionId !== preparation.baseRevisionId ||
|
|
641
|
+
value.revisionId !== preparation.manifest.revisionId ||
|
|
642
|
+
value.contentDigest !== preparation.manifest.contentDigest ||
|
|
643
|
+
value.manifestSha256 !== sha256Hex(canonicalizeJson(preparation.manifest)) ||
|
|
644
|
+
value.intent !== preparation.intent ||
|
|
645
|
+
value.lifecycleEpoch !== preparation.lifecycleEpoch ||
|
|
646
|
+
value.version !== preparation.expectedVersion + 1
|
|
647
|
+
)
|
|
648
|
+
throw new TypeError('Commit receipt differs from its frozen preparation.');
|
|
649
|
+
return value;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/** Acceptance preserves the invitation snapshot; authorization never creates another publication. */
|
|
653
|
+
export function assertEnterpriseGuestAuthorizationReceipt(value, invitation, now) {
|
|
654
|
+
assertEnterpriseJourneyContract(value, 'enterprise-guest-authorization');
|
|
655
|
+
assertEnterpriseJourneyContract(invitation, 'enterprise-guest-invitation');
|
|
656
|
+
if (
|
|
657
|
+
!sameScope(value, invitation) ||
|
|
658
|
+
value.artifactId !== invitation.artifactId ||
|
|
659
|
+
value.invitationId !== invitation.invitationId ||
|
|
660
|
+
value.actorId !== invitation.recipientId ||
|
|
661
|
+
value.role !== invitation.role ||
|
|
662
|
+
value.expiresAt !== invitation.expiresAt ||
|
|
663
|
+
canonicalizeJson(value.pin) !== canonicalizeJson(invitation.pin) ||
|
|
664
|
+
(value.status === 'active' &&
|
|
665
|
+
(!Number.isFinite(Date.parse(now)) ||
|
|
666
|
+
Date.parse(invitation.expiresAt) <= Date.parse(now) ||
|
|
667
|
+
['denied', 'revoked'].includes(invitation.grantStatus)))
|
|
668
|
+
)
|
|
669
|
+
throw new TypeError('Guest authorization differs from its original invitation.');
|
|
670
|
+
return value;
|
|
671
|
+
}
|
|
@@ -2116,7 +2116,7 @@ export const CANONICAL_REGISTRIES = deepFreeze({
|
|
|
2116
2116
|
"ownerPackage": "openplanr",
|
|
2117
2117
|
"source": {
|
|
2118
2118
|
"path": "packages/cli/src/cli/commands/upgrade.ts",
|
|
2119
|
-
"digest": "sha256:
|
|
2119
|
+
"digest": "sha256:9ea7a2085f100e9221a1e266633369340904a669497801a63adc943a338c7868"
|
|
2120
2120
|
},
|
|
2121
2121
|
"authorityClass": "workflow",
|
|
2122
2122
|
"machineJson": false,
|
|
@@ -3099,7 +3099,7 @@ export const CANONICAL_REGISTRIES = deepFreeze({
|
|
|
3099
3099
|
]
|
|
3100
3100
|
}
|
|
3101
3101
|
],
|
|
3102
|
-
"documentDigest": "sha256:
|
|
3102
|
+
"documentDigest": "sha256:735f3c5f9f5e3b1a14ea614361083192768652bd993ea0e47cda9384f1c85da1"
|
|
3103
3103
|
},
|
|
3104
3104
|
"skills.json": {
|
|
3105
3105
|
"kind": "skill-catalog",
|