@pwfabric/pack 1.0.0-rc.2 → 1.1.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/dist/validate.d.ts +9 -2
- package/dist/validate.js +117 -2
- package/dist/validate.js.map +1 -1
- package/package.json +2 -2
package/dist/validate.d.ts
CHANGED
|
@@ -46,13 +46,20 @@ export interface PackValidation {
|
|
|
46
46
|
* `media/provenance.json` or one naming a file the pack does not carry;
|
|
47
47
|
* a file under `app/assets/` (`LEGACY_ASSETS_FOLDER`); a media declaration
|
|
48
48
|
* that breaks its schema, names a `file` missing from `media/`, or whose file
|
|
49
|
-
* has no provenance entry (see `mediaDeclarations`)
|
|
49
|
+
* has no provenance entry (see `mediaDeclarations`); an `app/content/<typeId>.json`
|
|
50
|
+
* for an undeclared entity, not shaped
|
|
51
|
+
* `{ data: [...] }`, or with a record whose `id` is missing, not a UUID or
|
|
52
|
+
* repeated.
|
|
50
53
|
*
|
|
51
54
|
* Warnings: two paths that collide on a case-insensitive file system;
|
|
52
55
|
* unknown top-level entries; unknown families under `atoms/`; the
|
|
53
56
|
* rootless or mixed layout; `pwpack.json` declaring a newer format; an app
|
|
54
57
|
* entry not in its surface order or a key listed twice; files under
|
|
55
|
-
* `app/surfaces/` that are not receipts;
|
|
58
|
+
* `app/surfaces/` that are not receipts; a receipt whose key is not in
|
|
59
|
+
* `app.surfaceOrder` (the app never serves it); an `access.rules` entry naming
|
|
60
|
+
* an undeclared entity, an unknown subject or a word that is not a verb
|
|
61
|
+
* (`APP_ACCESS_RULE`); content for a collection only `own` readers reach
|
|
62
|
+
* (`APP_CONTENT_UNREADABLE`); media files without provenance, or
|
|
56
63
|
* whose hash disagrees with it (not reported when the provenance record is
|
|
57
64
|
* itself invalid); other JSON files that do not parse; a file under
|
|
58
65
|
* `app/media/` that is not a `<key>.json` declaration.
|
package/dist/validate.js
CHANGED
|
@@ -34,10 +34,19 @@ export const ATOM_FAMILIES = new Set([
|
|
|
34
34
|
const NEUTRAL_ROOT_DIRS = new Set(['lib', 'test']);
|
|
35
35
|
const APP_SURFACES = 'app/surfaces/';
|
|
36
36
|
const RECEIPT_SUFFIX = '.receipt.json';
|
|
37
|
+
const APP_CONTENT = 'app/content/';
|
|
38
|
+
const ENTITIES_FILE = 'app/definitions/entities.json';
|
|
39
|
+
const AUTH_FILE = 'app/definitions/auth.json';
|
|
40
|
+
const ACCESS_VERBS = new Set(['create', 'list', 'view', 'update', 'delete', 'count', 'read', 'write']);
|
|
41
|
+
const normName = (s) => s.toLowerCase().replace(/[\s_-]/g, '');
|
|
42
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
37
43
|
/** A Markdown file at depth `depth` (segments), e.g. `atoms/README.md` at 2. */
|
|
38
44
|
function isDocFile(parts, depth) {
|
|
39
45
|
return parts.length === depth && parts[depth - 1].toLowerCase().endsWith('.md');
|
|
40
46
|
}
|
|
47
|
+
function isRecord(v) {
|
|
48
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
49
|
+
}
|
|
41
50
|
function parseJson(bytes) {
|
|
42
51
|
try {
|
|
43
52
|
return { ok: true, value: JSON.parse(stripBom(new TextDecoder().decode(bytes))) };
|
|
@@ -58,13 +67,20 @@ function parseJson(bytes) {
|
|
|
58
67
|
* `media/provenance.json` or one naming a file the pack does not carry;
|
|
59
68
|
* a file under `app/assets/` (`LEGACY_ASSETS_FOLDER`); a media declaration
|
|
60
69
|
* that breaks its schema, names a `file` missing from `media/`, or whose file
|
|
61
|
-
* has no provenance entry (see `mediaDeclarations`)
|
|
70
|
+
* has no provenance entry (see `mediaDeclarations`); an `app/content/<typeId>.json`
|
|
71
|
+
* for an undeclared entity, not shaped
|
|
72
|
+
* `{ data: [...] }`, or with a record whose `id` is missing, not a UUID or
|
|
73
|
+
* repeated.
|
|
62
74
|
*
|
|
63
75
|
* Warnings: two paths that collide on a case-insensitive file system;
|
|
64
76
|
* unknown top-level entries; unknown families under `atoms/`; the
|
|
65
77
|
* rootless or mixed layout; `pwpack.json` declaring a newer format; an app
|
|
66
78
|
* entry not in its surface order or a key listed twice; files under
|
|
67
|
-
* `app/surfaces/` that are not receipts;
|
|
79
|
+
* `app/surfaces/` that are not receipts; a receipt whose key is not in
|
|
80
|
+
* `app.surfaceOrder` (the app never serves it); an `access.rules` entry naming
|
|
81
|
+
* an undeclared entity, an unknown subject or a word that is not a verb
|
|
82
|
+
* (`APP_ACCESS_RULE`); content for a collection only `own` readers reach
|
|
83
|
+
* (`APP_CONTENT_UNREADABLE`); media files without provenance, or
|
|
68
84
|
* whose hash disagrees with it (not reported when the provenance record is
|
|
69
85
|
* itself invalid); other JSON files that do not parse; a file under
|
|
70
86
|
* `app/media/` that is not a `<key>.json` declaration.
|
|
@@ -205,6 +221,105 @@ export function validatePack(pack) {
|
|
|
205
221
|
const rest = path.slice(APP_SURFACES.length);
|
|
206
222
|
if (rest.includes('/') || !rest.endsWith(RECEIPT_SUFFIX)) {
|
|
207
223
|
add('warning', 'APP_UNEXPECTED_FILE', `${path} is not an app/surfaces/<key>.receipt.json`, path);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
// The pages an app serves are app.surfaceOrder. A receipt written without
|
|
227
|
+
// its key there is a page nobody can reach — every link to it lands on
|
|
228
|
+
// not-found — and the pack still validated clean.
|
|
229
|
+
const key = rest.slice(0, -RECEIPT_SUFFIX.length);
|
|
230
|
+
if (identity?.app && !identity.app.surfaceOrder.includes(key) && identity.app.entry !== key) {
|
|
231
|
+
add('warning', 'APP_SURFACE_NOT_SERVED', `${path} is not in pwpack.json app.surfaceOrder, so the app does not serve it — add "${key}" there`, path);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// ---- app access: who may do what with the app's records (definitions, `access`) ----
|
|
235
|
+
// Each rule names an entity, a subject (`public`, `member`, or a declared
|
|
236
|
+
// role) and verbs. A server ignores what it does not know, so a misspelt
|
|
237
|
+
// rule silently grants nothing: report it.
|
|
238
|
+
const entityNames = new Map(); // normalised typeId/displayName -> typeId
|
|
239
|
+
const entitiesFile = pack.files.get(ENTITIES_FILE);
|
|
240
|
+
const entitiesDoc = entitiesFile ? parseJson(entitiesFile) : undefined;
|
|
241
|
+
if (entitiesDoc?.ok && isRecord(entitiesDoc.value) && Array.isArray(entitiesDoc.value['entities'])) {
|
|
242
|
+
for (const e of entitiesDoc.value['entities']) {
|
|
243
|
+
if (!isRecord(e) || typeof e['typeId'] !== 'string')
|
|
244
|
+
continue;
|
|
245
|
+
entityNames.set(normName(e['typeId']), e['typeId']);
|
|
246
|
+
if (typeof e['displayName'] === 'string')
|
|
247
|
+
entityNames.set(normName(e['displayName']), e['typeId']);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** typeId -> whether some rule lets a subject list it whole (not only `own`). */
|
|
251
|
+
const ruled = new Map();
|
|
252
|
+
const authFile = pack.files.get(AUTH_FILE);
|
|
253
|
+
const authDoc = authFile ? parseJson(authFile) : undefined;
|
|
254
|
+
const access = authDoc?.ok && isRecord(authDoc.value) && isRecord(authDoc.value['access']) ? authDoc.value['access'] : undefined;
|
|
255
|
+
if (access && Array.isArray(access['rules'])) {
|
|
256
|
+
const roles = new Set(Array.isArray(access['roles']) ? access['roles'].filter((r) => typeof r === 'string') : []);
|
|
257
|
+
access['rules'].forEach((r, i) => {
|
|
258
|
+
if (!isRecord(r))
|
|
259
|
+
return;
|
|
260
|
+
const at = `${AUTH_FILE} access.rules[${i}]`;
|
|
261
|
+
const model = typeof r['model'] === 'string' ? r['model'] : '';
|
|
262
|
+
const subject = typeof r['subject'] === 'string' ? r['subject'].trim() : '';
|
|
263
|
+
const words = (typeof r['rule'] === 'string' ? r['rule'] : '').toLowerCase().split(/[\s,]+/).filter(Boolean);
|
|
264
|
+
const typeId = entityNames.get(normName(model));
|
|
265
|
+
if (!typeId)
|
|
266
|
+
add('warning', 'APP_ACCESS_RULE', `${at} names "${model}", which ${ENTITIES_FILE} does not declare`, AUTH_FILE);
|
|
267
|
+
if (subject !== 'public' && subject !== 'member' && !roles.has(subject)) {
|
|
268
|
+
add('warning', 'APP_ACCESS_RULE', `${at} is for "${subject}": write public, member, or a role listed in access.roles`, AUTH_FILE);
|
|
269
|
+
}
|
|
270
|
+
const unknown = words.filter((w) => w !== 'own' && !ACCESS_VERBS.has(w));
|
|
271
|
+
if (unknown.length > 0)
|
|
272
|
+
add('warning', 'APP_ACCESS_RULE', `${at} has words that are not verbs (${unknown.join(', ')}); a server ignores them. Verbs: ${[...ACCESS_VERBS].join(', ')}, and own`, AUTH_FILE);
|
|
273
|
+
if (!words.some((w) => ACCESS_VERBS.has(w)))
|
|
274
|
+
add('warning', 'APP_ACCESS_RULE', `${at} has no verb, so it grants nothing`, AUTH_FILE);
|
|
275
|
+
if (typeId) {
|
|
276
|
+
const listsWhole = !words.includes('own') && words.some((w) => w === 'list' || w === 'read');
|
|
277
|
+
ruled.set(typeId, (ruled.get(typeId) ?? false) || listsWhole);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
// ---- app content: the records an app ships for every visitor ----
|
|
282
|
+
// app/content/<typeId>.json is published into the record store once per
|
|
283
|
+
// record (insert when the id is absent, never overwrite). Its ids must be
|
|
284
|
+
// stable and server-grade. A content record has no creator, so a collection
|
|
285
|
+
// the rules let visitors read only `own` records of shows it to nobody.
|
|
286
|
+
const contentPaths = paths.filter((p) => p.startsWith(APP_CONTENT));
|
|
287
|
+
if (contentPaths.length > 0) {
|
|
288
|
+
const declared = new Set(entityNames.values());
|
|
289
|
+
for (const path of contentPaths) {
|
|
290
|
+
const rest = path.slice(APP_CONTENT.length);
|
|
291
|
+
if (rest.includes('/') || !rest.endsWith('.json')) {
|
|
292
|
+
add('warning', 'APP_UNEXPECTED_FILE', `${path} is not an app/content/<typeId>.json`, path);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const typeId = rest.slice(0, -'.json'.length);
|
|
296
|
+
const parsed = parseJson(pack.files.get(path));
|
|
297
|
+
if (!parsed.ok)
|
|
298
|
+
continue; // JSON_INVALID below
|
|
299
|
+
if (!declared.has(typeId)) {
|
|
300
|
+
add('error', 'APP_CONTENT_UNDECLARED', `${path} fills "${typeId}", which ${ENTITIES_FILE} does not declare`, path);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (ruled.get(typeId) === false) {
|
|
304
|
+
add('warning', 'APP_CONTENT_UNREADABLE', `${path} fills "${typeId}", but the access rules let nobody read it except their own records; no visitor sees this content`, path);
|
|
305
|
+
}
|
|
306
|
+
const doc = parsed.value;
|
|
307
|
+
if (!isRecord(doc) || !Array.isArray(doc['data'])) {
|
|
308
|
+
add('error', 'APP_CONTENT_INVALID', `${path} must be { "data": [ ...records ] }`, path);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const seen = new Set();
|
|
312
|
+
doc['data'].forEach((row, i) => {
|
|
313
|
+
const id = isRecord(row) ? row['id'] : undefined;
|
|
314
|
+
if (typeof id !== 'string' || !UUID.test(id)) {
|
|
315
|
+
add('error', 'APP_CONTENT_ID', `${path} data[${i}] needs an "id" that is a UUID: it stays the record's id once published, and relations point at it`, path);
|
|
316
|
+
}
|
|
317
|
+
else if (seen.has(id.toLowerCase())) {
|
|
318
|
+
add('error', 'APP_CONTENT_ID', `${path} data[${i}] repeats id ${id}`, path);
|
|
319
|
+
}
|
|
320
|
+
else
|
|
321
|
+
seen.add(id.toLowerCase());
|
|
322
|
+
});
|
|
208
323
|
}
|
|
209
324
|
}
|
|
210
325
|
// ---- JSON well-formedness ----
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GAGxB,MAAM,qBAAqB,CAAA;AAE5B,OAAO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IAAI,CAAC;KACzB,CAAA;AACH,CAAC","sourcesContent":["/**\n * Validation of a pack folder held in memory. Reports, never throws, for\n * content problems.\n *\n * @module @pwfabric/pack/validate\n */\nimport {\n classifyPackPath,\n safeParsePwpackIdentity,\n type AtomRef,\n type PwpackIdentity,\n} from '@pwfabric/contracts'\nimport type { PackFolder, PackIssue } from './types.js'\nimport { findCaseConflicts, findPathConflict, sortedPaths, unsafePathReason } from './paths.js'\nimport { PACK_DOC_FILES } from './content.js'\nimport { atomOccurrences, deriveAtoms, IDENTITY_FILE, stripBom } from './manifest.js'\nimport { sha256Hex } from './hash.js'\nimport { MEDIA_PROVENANCE_FILE as MEDIA_PROVENANCE, mediaDeclarations, readMediaProvenance } from './media.js'\n\n/** The `formatVersion` major this reader understands. A newer one gets a warning. */\nexport const SUPPORTED_FORMAT_MAJOR = 1\n\n/**\n * Atom families as directory names: under `atoms/` in the canonical folder,\n * at the root in the legacy rootless layout. `lib` holds shared code and\n * `test` the pack's own tests; neither is an atom, both are expected.\n */\nexport const ATOM_FAMILIES: ReadonlySet<string> = new Set([\n 'blocks',\n 'capabilities',\n 'connectors',\n 'providers',\n 'appearance',\n 'patterns',\n 'icons',\n 'surfaces',\n 'auth',\n 'lib',\n 'test',\n])\n\n/** Family directories that may sit at the root of either layout. */\nconst NEUTRAL_ROOT_DIRS: ReadonlySet<string> = new Set(['lib', 'test'])\n\n/** Which layout the folder's paths use. */\nexport type PackLayout =\n /** `atoms/`, `app/` (and `pwpack.json`, `media/`) only. */\n | 'canonical'\n /** Atom families at the root, the pre-`atoms/` layout. */\n | 'rootless'\n /** Both at once. */\n | 'mixed'\n /** Neither: no atom or app path at all. */\n | 'empty'\n\nexport interface PackValidation {\n /** No issue has severity `error`. */\n readonly ok: boolean\n readonly issues: readonly PackIssue[]\n /** The parsed `pwpack.json`, when it is present and valid. */\n readonly identity: PwpackIdentity | null\n readonly layout: PackLayout\n /** The derived atoms (see `deriveAtoms`). */\n readonly atoms: readonly AtomRef[]\n}\n\nconst APP_SURFACES = 'app/surfaces/'\nconst RECEIPT_SUFFIX = '.receipt.json'\n\n/** A Markdown file at depth `depth` (segments), e.g. `atoms/README.md` at 2. */\nfunction isDocFile(parts: readonly string[], depth: number): boolean {\n return parts.length === depth && (parts[depth - 1] as string).toLowerCase().endsWith('.md')\n}\n\nfunction parseJson(bytes: Uint8Array): { ok: true; value: unknown } | { ok: false; error: string } {\n try {\n return { ok: true, value: JSON.parse(stripBom(new TextDecoder().decode(bytes))) }\n } catch (e) {\n return { ok: false, error: (e as Error).message }\n }\n}\n\n/**\n * Validate a pack folder.\n *\n * Errors (the pack is not valid): an unsafe path; a path that is a file and\n * also another path's directory; `pwpack.json` missing,\n * not JSON, or not matching the contract schema; `app.entry` or an\n * `app.surfaceOrder` key without its `app/surfaces/<key>.receipt.json`; two\n * different atom directories yielding the same `kind:id`; a JSON file under\n * `app/` or `media/provenance.json` that does not parse; an invalid\n * `media/provenance.json` or one naming a file the pack does not carry;\n * a file under `app/assets/` (`LEGACY_ASSETS_FOLDER`); a media declaration\n * that breaks its schema, names a `file` missing from `media/`, or whose file\n * has no provenance entry (see `mediaDeclarations`).\n *\n * Warnings: two paths that collide on a case-insensitive file system;\n * unknown top-level entries; unknown families under `atoms/`; the\n * rootless or mixed layout; `pwpack.json` declaring a newer format; an app\n * entry not in its surface order or a key listed twice; files under\n * `app/surfaces/` that are not receipts; media files without provenance, or\n * whose hash disagrees with it (not reported when the provenance record is\n * itself invalid); other JSON files that do not parse; a file under\n * `app/media/` that is not a `<key>.json` declaration.\n *\n * Info: a legacy `package.json` at the root; a Markdown file directly in\n * `atoms/` or in an atom-family directory (documentation, not an atom).\n */\nexport function validatePack(pack: PackFolder): PackValidation {\n const issues: PackIssue[] = []\n const add = (severity: PackIssue['severity'], code: string, message: string, path?: string): void => {\n issues.push(path === undefined ? { severity, code, message } : { severity, code, message, path })\n }\n const paths = sortedPaths(pack.files.keys())\n\n // ---- collisions ----\n const conflict = findPathConflict(paths)\n if (conflict) {\n add('error', 'PATH_CONFLICT', `${conflict.file} is a file and also the directory of ${conflict.inside}`, conflict.file)\n }\n for (const group of findCaseConflicts(paths)) {\n add(\n 'warning',\n 'CASE_CONFLICT',\n `${group.join(', ')} differ only in case or Unicode normalisation; extracting them on a case-insensitive file system keeps one`,\n group[0]\n )\n }\n\n // ---- paths, top level and layout ----\n const unknownTop = new Set<string>()\n const unknownFamily = new Set<string>()\n let canonical = false\n let rootless = false\n for (const path of paths) {\n const reason = unsafePathReason(path)\n if (reason) {\n add('error', 'UNSAFE_PATH', `${path}: ${reason}`, path)\n continue\n }\n const parts = path.split('/')\n const top = parts[0] as string\n const cls = classifyPackPath(path)\n if (cls?.kind === 'identity') continue\n if (cls?.kind === 'app') {\n canonical = true\n continue\n }\n if (path === 'package.json') {\n add('info', 'LEGACY_PACKAGE_JSON', 'package.json at the root is legacy identity; pwpack.json is read instead', path)\n continue\n }\n if (PACK_DOC_FILES.has(path)) continue\n if (top === 'media' && parts.length > 1) continue\n if (top === 'atoms' && parts.length > 1) {\n canonical = true\n const family = parts[1] as string\n if (isDocFile(parts, 2) || (parts.length === 3 && ATOM_FAMILIES.has(family) && isDocFile(parts, 3))) {\n add('info', 'DOC_FILE', `${path} is documentation, not an atom`, path)\n continue\n }\n if (parts.length === 2 || !ATOM_FAMILIES.has(family)) unknownFamily.add(family)\n continue\n }\n if (parts.length > 1 && ATOM_FAMILIES.has(top)) {\n if (isDocFile(parts, 2)) add('info', 'DOC_FILE', `${path} is documentation, not an atom`, path)\n // Atom families at the root are the rootless layout. Root `lib/` and\n // `test/` are expected in both layouts (shared code on the legacy wire,\n // a source folder's own tests), so they do not decide the layout.\n if (!NEUTRAL_ROOT_DIRS.has(top)) rootless = true\n continue\n }\n unknownTop.add(parts.length > 1 ? `${top}/` : top)\n }\n for (const name of unknownTop) {\n add('warning', 'UNKNOWN_TOP_LEVEL', `${name} is not part of the pwpack folder (pwpack.json, app/, atoms/, media/)`, name)\n }\n for (const family of unknownFamily) {\n add('warning', 'UNKNOWN_ATOM_FAMILY', `atoms/${family} is not a known atom family`, `atoms/${family}`)\n }\n const layout: PackLayout = canonical && rootless ? 'mixed' : canonical ? 'canonical' : rootless ? 'rootless' : 'empty'\n if (layout === 'mixed') {\n add('warning', 'LAYOUT_MIXED', 'the folder mixes atoms/ with atom families at the root')\n } else if (layout === 'rootless') {\n add('warning', 'LAYOUT_ROOTLESS', 'atom families sit at the root; the canonical folder keeps them under atoms/')\n }\n\n // ---- identity ----\n let identity: PwpackIdentity | null = null\n const identityBytes = pack.files.get(IDENTITY_FILE)\n if (!identityBytes) {\n add('error', 'IDENTITY_MISSING', 'the folder has no pwpack.json', IDENTITY_FILE)\n } else {\n const parsed = parseJson(identityBytes)\n if (!parsed.ok) {\n add('error', 'IDENTITY_INVALID', `pwpack.json is not JSON: ${parsed.error}`, IDENTITY_FILE)\n } else {\n const result = safeParsePwpackIdentity(parsed.value)\n if (result.ok) {\n identity = result.value\n } else {\n for (const issue of result.issues) add('error', 'IDENTITY_INVALID', `pwpack.json ${issue}`, IDENTITY_FILE)\n }\n }\n }\n if (identity?.formatVersion !== undefined) {\n const major = Number(identity.formatVersion.split('.')[0])\n if (major > SUPPORTED_FORMAT_MAJOR) {\n add(\n 'warning',\n 'FORMAT_VERSION_NEWER',\n `pwpack.json formatVersion ${identity.formatVersion} is newer than this reader (${SUPPORTED_FORMAT_MAJOR}.x); parts of it may be ignored`,\n IDENTITY_FILE\n )\n }\n }\n\n // ---- app ----\n if (identity?.app) {\n const { entry, surfaceOrder } = identity.app\n const receipt = (key: string): string => `${APP_SURFACES}${key}${RECEIPT_SUFFIX}`\n const missing = new Set<string>()\n for (const key of [entry, ...surfaceOrder]) {\n if (!pack.files.has(receipt(key)) && !missing.has(key)) {\n missing.add(key)\n add('error', 'APP_SURFACE_MISSING', `pwpack.json app names surface \"${key}\" but ${receipt(key)} is absent`, receipt(key))\n }\n }\n if (!surfaceOrder.includes(entry)) {\n add('warning', 'APP_ENTRY_NOT_IN_ORDER', `app.entry \"${entry}\" is not listed in app.surfaceOrder`, IDENTITY_FILE)\n }\n const seen = new Set<string>()\n for (const key of surfaceOrder) {\n if (seen.has(key)) add('warning', 'APP_SURFACE_DUPLICATE', `app.surfaceOrder lists \"${key}\" more than once`, IDENTITY_FILE)\n seen.add(key)\n }\n }\n for (const path of paths) {\n if (!path.startsWith(APP_SURFACES)) continue\n const rest = path.slice(APP_SURFACES.length)\n if (rest.includes('/') || !rest.endsWith(RECEIPT_SUFFIX)) {\n add('warning', 'APP_UNEXPECTED_FILE', `${path} is not an app/surfaces/<key>.receipt.json`, path)\n }\n }\n\n // ---- JSON well-formedness ----\n for (const path of paths) {\n if (!path.endsWith('.json') || path === IDENTITY_FILE || path === MEDIA_PROVENANCE) continue\n const parsed = parseJson(pack.files.get(path) as Uint8Array)\n if (parsed.ok) continue\n const severity = path.startsWith('app/') ? 'error' : 'warning'\n add(severity, 'JSON_INVALID', `${path} is not JSON: ${parsed.error}`, path)\n }\n\n // ---- atoms ----\n const firstDir = new Map<string, string>()\n for (const { ref, dir } of atomOccurrences(pack)) {\n const key = `${ref.kind}:${ref.id}`\n const seenDir = firstDir.get(key)\n if (seenDir === undefined) firstDir.set(key, dir)\n else if (seenDir !== dir) {\n add('error', 'DUPLICATE_ATOM', `${key} comes from both ${seenDir} and ${dir}`, ref.relPath)\n }\n }\n\n // ---- media ----\n const mediaFiles = paths.filter((p) => p.startsWith('media/') && p !== MEDIA_PROVENANCE)\n const declared = new Set<string>()\n // Undeclared media is only computed against a provenance record that is\n // valid; an invalid one is reported once, not once per media file.\n const provenance = readMediaProvenance(pack)\n if (provenance.state === 'invalid') {\n for (const issue of provenance.issues) add('error', 'MEDIA_PROVENANCE_INVALID', `media/provenance.json ${issue}`, MEDIA_PROVENANCE)\n } else if (provenance.state === 'valid') {\n for (const item of provenance.value.items) {\n declared.add(item.path)\n const bytes = pack.files.get(item.path)\n if (!bytes) {\n add('error', 'MEDIA_PROVENANCE_PATH_MISSING', `media/provenance.json lists ${item.path}, which the pack does not carry`, item.path)\n } else if (item.hash.startsWith('sha256:') && item.hash !== `sha256:${sha256Hex(bytes)}`) {\n add('warning', 'MEDIA_HASH_MISMATCH', `${item.path} does not match the hash media/provenance.json records`, item.path)\n }\n }\n }\n for (const path of provenance.state === 'invalid' ? [] : mediaFiles) {\n if (!declared.has(path)) add('warning', 'MEDIA_UNDECLARED', `${path} has no entry in media/provenance.json`, path)\n }\n // Declarations: which layout, and whether the bytes they name are there.\n issues.push(...mediaDeclarations(pack).issues)\n\n return {\n ok: !issues.some((i) => i.severity === 'error'),\n issues,\n identity,\n layout,\n atoms: deriveAtoms(pack),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GAGxB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC/F,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,qBAAqB,IAAI,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAE9G,qFAAqF;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC;IACxD,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,KAAK;IACL,MAAM;CACP,CAAC,CAAA;AAEF,oE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AAE,IAAI,CAAC,IAAI,CAAC,CAAA;YACxH,CAAC;QACH,CAAC;IACH,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QACpE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,wCAAwC,EAAE,IAAI,CAAC,CAAA;IACpH,CAAC;IACD,yEAAyE;IACzE,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IAE9C,OAAO;QACL,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC;QAC/C,MAAM;QACN,QAAQ;QACR,MAAM;QACN,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC;KACzB,CAAA;AACH,CAAC","sourcesContent":["/**\n * Validation of a pack folder held in memory. Reports, never throws, for\n * content problems.\n *\n * @module @pwfabric/pack/validate\n */\nimport {\n classifyPackPath,\n safeParsePwpackIdentity,\n type AtomRef,\n type PwpackIdentity,\n} from '@pwfabric/contracts'\nimport type { PackFolder, PackIssue } from './types.js'\nimport { findCaseConflicts, findPathConflict, sortedPaths, unsafePathReason } from './paths.js'\nimport { PACK_DOC_FILES } from './content.js'\nimport { atomOccurrences, deriveAtoms, IDENTITY_FILE, stripBom } from './manifest.js'\nimport { sha256Hex } from './hash.js'\nimport { MEDIA_PROVENANCE_FILE as MEDIA_PROVENANCE, mediaDeclarations, readMediaProvenance } from './media.js'\n\n/** The `formatVersion` major this reader understands. A newer one gets a warning. */\nexport const SUPPORTED_FORMAT_MAJOR = 1\n\n/**\n * Atom families as directory names: under `atoms/` in the canonical folder,\n * at the root in the legacy rootless layout. `lib` holds shared code and\n * `test` the pack's own tests; neither is an atom, both are expected.\n */\nexport const ATOM_FAMILIES: ReadonlySet<string> = new Set([\n 'blocks',\n 'capabilities',\n 'connectors',\n 'providers',\n 'appearance',\n 'patterns',\n 'icons',\n 'surfaces',\n 'auth',\n 'lib',\n 'test',\n])\n\n/** Family directories that may sit at the root of either layout. */\nconst NEUTRAL_ROOT_DIRS: ReadonlySet<string> = new Set(['lib', 'test'])\n\n/** Which layout the folder's paths use. */\nexport type PackLayout =\n /** `atoms/`, `app/` (and `pwpack.json`, `media/`) only. */\n | 'canonical'\n /** Atom families at the root, the pre-`atoms/` layout. */\n | 'rootless'\n /** Both at once. */\n | 'mixed'\n /** Neither: no atom or app path at all. */\n | 'empty'\n\nexport interface PackValidation {\n /** No issue has severity `error`. */\n readonly ok: boolean\n readonly issues: readonly PackIssue[]\n /** The parsed `pwpack.json`, when it is present and valid. */\n readonly identity: PwpackIdentity | null\n readonly layout: PackLayout\n /** The derived atoms (see `deriveAtoms`). */\n readonly atoms: readonly AtomRef[]\n}\n\nconst APP_SURFACES = 'app/surfaces/'\nconst RECEIPT_SUFFIX = '.receipt.json'\nconst APP_CONTENT = 'app/content/'\nconst ENTITIES_FILE = 'app/definitions/entities.json'\nconst AUTH_FILE = 'app/definitions/auth.json'\nconst ACCESS_VERBS = new Set(['create', 'list', 'view', 'update', 'delete', 'count', 'read', 'write'])\nconst normName = (s: string): string => s.toLowerCase().replace(/[\\s_-]/g, '')\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/** A Markdown file at depth `depth` (segments), e.g. `atoms/README.md` at 2. */\nfunction isDocFile(parts: readonly string[], depth: number): boolean {\n return parts.length === depth && (parts[depth - 1] as string).toLowerCase().endsWith('.md')\n}\n\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n}\n\nfunction parseJson(bytes: Uint8Array): { ok: true; value: unknown } | { ok: false; error: string } {\n try {\n return { ok: true, value: JSON.parse(stripBom(new TextDecoder().decode(bytes))) }\n } catch (e) {\n return { ok: false, error: (e as Error).message }\n }\n}\n\n/**\n * Validate a pack folder.\n *\n * Errors (the pack is not valid): an unsafe path; a path that is a file and\n * also another path's directory; `pwpack.json` missing,\n * not JSON, or not matching the contract schema; `app.entry` or an\n * `app.surfaceOrder` key without its `app/surfaces/<key>.receipt.json`; two\n * different atom directories yielding the same `kind:id`; a JSON file under\n * `app/` or `media/provenance.json` that does not parse; an invalid\n * `media/provenance.json` or one naming a file the pack does not carry;\n * a file under `app/assets/` (`LEGACY_ASSETS_FOLDER`); a media declaration\n * that breaks its schema, names a `file` missing from `media/`, or whose file\n * has no provenance entry (see `mediaDeclarations`); an `app/content/<typeId>.json`\n * for an undeclared entity, not shaped\n * `{ data: [...] }`, or with a record whose `id` is missing, not a UUID or\n * repeated.\n *\n * Warnings: two paths that collide on a case-insensitive file system;\n * unknown top-level entries; unknown families under `atoms/`; the\n * rootless or mixed layout; `pwpack.json` declaring a newer format; an app\n * entry not in its surface order or a key listed twice; files under\n * `app/surfaces/` that are not receipts; a receipt whose key is not in\n * `app.surfaceOrder` (the app never serves it); an `access.rules` entry naming\n * an undeclared entity, an unknown subject or a word that is not a verb\n * (`APP_ACCESS_RULE`); content for a collection only `own` readers reach\n * (`APP_CONTENT_UNREADABLE`); media files without provenance, or\n * whose hash disagrees with it (not reported when the provenance record is\n * itself invalid); other JSON files that do not parse; a file under\n * `app/media/` that is not a `<key>.json` declaration.\n *\n * Info: a legacy `package.json` at the root; a Markdown file directly in\n * `atoms/` or in an atom-family directory (documentation, not an atom).\n */\nexport function validatePack(pack: PackFolder): PackValidation {\n const issues: PackIssue[] = []\n const add = (severity: PackIssue['severity'], code: string, message: string, path?: string): void => {\n issues.push(path === undefined ? { severity, code, message } : { severity, code, message, path })\n }\n const paths = sortedPaths(pack.files.keys())\n\n // ---- collisions ----\n const conflict = findPathConflict(paths)\n if (conflict) {\n add('error', 'PATH_CONFLICT', `${conflict.file} is a file and also the directory of ${conflict.inside}`, conflict.file)\n }\n for (const group of findCaseConflicts(paths)) {\n add(\n 'warning',\n 'CASE_CONFLICT',\n `${group.join(', ')} differ only in case or Unicode normalisation; extracting them on a case-insensitive file system keeps one`,\n group[0]\n )\n }\n\n // ---- paths, top level and layout ----\n const unknownTop = new Set<string>()\n const unknownFamily = new Set<string>()\n let canonical = false\n let rootless = false\n for (const path of paths) {\n const reason = unsafePathReason(path)\n if (reason) {\n add('error', 'UNSAFE_PATH', `${path}: ${reason}`, path)\n continue\n }\n const parts = path.split('/')\n const top = parts[0] as string\n const cls = classifyPackPath(path)\n if (cls?.kind === 'identity') continue\n if (cls?.kind === 'app') {\n canonical = true\n continue\n }\n if (path === 'package.json') {\n add('info', 'LEGACY_PACKAGE_JSON', 'package.json at the root is legacy identity; pwpack.json is read instead', path)\n continue\n }\n if (PACK_DOC_FILES.has(path)) continue\n if (top === 'media' && parts.length > 1) continue\n if (top === 'atoms' && parts.length > 1) {\n canonical = true\n const family = parts[1] as string\n if (isDocFile(parts, 2) || (parts.length === 3 && ATOM_FAMILIES.has(family) && isDocFile(parts, 3))) {\n add('info', 'DOC_FILE', `${path} is documentation, not an atom`, path)\n continue\n }\n if (parts.length === 2 || !ATOM_FAMILIES.has(family)) unknownFamily.add(family)\n continue\n }\n if (parts.length > 1 && ATOM_FAMILIES.has(top)) {\n if (isDocFile(parts, 2)) add('info', 'DOC_FILE', `${path} is documentation, not an atom`, path)\n // Atom families at the root are the rootless layout. Root `lib/` and\n // `test/` are expected in both layouts (shared code on the legacy wire,\n // a source folder's own tests), so they do not decide the layout.\n if (!NEUTRAL_ROOT_DIRS.has(top)) rootless = true\n continue\n }\n unknownTop.add(parts.length > 1 ? `${top}/` : top)\n }\n for (const name of unknownTop) {\n add('warning', 'UNKNOWN_TOP_LEVEL', `${name} is not part of the pwpack folder (pwpack.json, app/, atoms/, media/)`, name)\n }\n for (const family of unknownFamily) {\n add('warning', 'UNKNOWN_ATOM_FAMILY', `atoms/${family} is not a known atom family`, `atoms/${family}`)\n }\n const layout: PackLayout = canonical && rootless ? 'mixed' : canonical ? 'canonical' : rootless ? 'rootless' : 'empty'\n if (layout === 'mixed') {\n add('warning', 'LAYOUT_MIXED', 'the folder mixes atoms/ with atom families at the root')\n } else if (layout === 'rootless') {\n add('warning', 'LAYOUT_ROOTLESS', 'atom families sit at the root; the canonical folder keeps them under atoms/')\n }\n\n // ---- identity ----\n let identity: PwpackIdentity | null = null\n const identityBytes = pack.files.get(IDENTITY_FILE)\n if (!identityBytes) {\n add('error', 'IDENTITY_MISSING', 'the folder has no pwpack.json', IDENTITY_FILE)\n } else {\n const parsed = parseJson(identityBytes)\n if (!parsed.ok) {\n add('error', 'IDENTITY_INVALID', `pwpack.json is not JSON: ${parsed.error}`, IDENTITY_FILE)\n } else {\n const result = safeParsePwpackIdentity(parsed.value)\n if (result.ok) {\n identity = result.value\n } else {\n for (const issue of result.issues) add('error', 'IDENTITY_INVALID', `pwpack.json ${issue}`, IDENTITY_FILE)\n }\n }\n }\n if (identity?.formatVersion !== undefined) {\n const major = Number(identity.formatVersion.split('.')[0])\n if (major > SUPPORTED_FORMAT_MAJOR) {\n add(\n 'warning',\n 'FORMAT_VERSION_NEWER',\n `pwpack.json formatVersion ${identity.formatVersion} is newer than this reader (${SUPPORTED_FORMAT_MAJOR}.x); parts of it may be ignored`,\n IDENTITY_FILE\n )\n }\n }\n\n // ---- app ----\n if (identity?.app) {\n const { entry, surfaceOrder } = identity.app\n const receipt = (key: string): string => `${APP_SURFACES}${key}${RECEIPT_SUFFIX}`\n const missing = new Set<string>()\n for (const key of [entry, ...surfaceOrder]) {\n if (!pack.files.has(receipt(key)) && !missing.has(key)) {\n missing.add(key)\n add('error', 'APP_SURFACE_MISSING', `pwpack.json app names surface \"${key}\" but ${receipt(key)} is absent`, receipt(key))\n }\n }\n if (!surfaceOrder.includes(entry)) {\n add('warning', 'APP_ENTRY_NOT_IN_ORDER', `app.entry \"${entry}\" is not listed in app.surfaceOrder`, IDENTITY_FILE)\n }\n const seen = new Set<string>()\n for (const key of surfaceOrder) {\n if (seen.has(key)) add('warning', 'APP_SURFACE_DUPLICATE', `app.surfaceOrder lists \"${key}\" more than once`, IDENTITY_FILE)\n seen.add(key)\n }\n }\n for (const path of paths) {\n if (!path.startsWith(APP_SURFACES)) continue\n const rest = path.slice(APP_SURFACES.length)\n if (rest.includes('/') || !rest.endsWith(RECEIPT_SUFFIX)) {\n add('warning', 'APP_UNEXPECTED_FILE', `${path} is not an app/surfaces/<key>.receipt.json`, path)\n continue\n }\n // The pages an app serves are app.surfaceOrder. A receipt written without\n // its key there is a page nobody can reach — every link to it lands on\n // not-found — and the pack still validated clean.\n const key = rest.slice(0, -RECEIPT_SUFFIX.length)\n if (identity?.app && !identity.app.surfaceOrder.includes(key) && identity.app.entry !== key) {\n add('warning', 'APP_SURFACE_NOT_SERVED', `${path} is not in pwpack.json app.surfaceOrder, so the app does not serve it — add \"${key}\" there`, path)\n }\n }\n\n // ---- app access: who may do what with the app's records (definitions, `access`) ----\n // Each rule names an entity, a subject (`public`, `member`, or a declared\n // role) and verbs. A server ignores what it does not know, so a misspelt\n // rule silently grants nothing: report it.\n const entityNames = new Map<string, string>() // normalised typeId/displayName -> typeId\n const entitiesFile = pack.files.get(ENTITIES_FILE)\n const entitiesDoc = entitiesFile ? parseJson(entitiesFile) : undefined\n if (entitiesDoc?.ok && isRecord(entitiesDoc.value) && Array.isArray(entitiesDoc.value['entities'])) {\n for (const e of entitiesDoc.value['entities']) {\n if (!isRecord(e) || typeof e['typeId'] !== 'string') continue\n entityNames.set(normName(e['typeId']), e['typeId'])\n if (typeof e['displayName'] === 'string') entityNames.set(normName(e['displayName']), e['typeId'])\n }\n }\n /** typeId -> whether some rule lets a subject list it whole (not only `own`). */\n const ruled = new Map<string, boolean>()\n const authFile = pack.files.get(AUTH_FILE)\n const authDoc = authFile ? parseJson(authFile) : undefined\n const access = authDoc?.ok && isRecord(authDoc.value) && isRecord(authDoc.value['access']) ? authDoc.value['access'] : undefined\n if (access && Array.isArray(access['rules'])) {\n const roles = new Set(Array.isArray(access['roles']) ? access['roles'].filter((r): r is string => typeof r === 'string') : [])\n access['rules'].forEach((r: unknown, i: number) => {\n if (!isRecord(r)) return\n const at = `${AUTH_FILE} access.rules[${i}]`\n const model = typeof r['model'] === 'string' ? r['model'] : ''\n const subject = typeof r['subject'] === 'string' ? r['subject'].trim() : ''\n const words = (typeof r['rule'] === 'string' ? r['rule'] : '').toLowerCase().split(/[\\s,]+/).filter(Boolean)\n const typeId = entityNames.get(normName(model))\n if (!typeId) add('warning', 'APP_ACCESS_RULE', `${at} names \"${model}\", which ${ENTITIES_FILE} does not declare`, AUTH_FILE)\n if (subject !== 'public' && subject !== 'member' && !roles.has(subject)) {\n add('warning', 'APP_ACCESS_RULE', `${at} is for \"${subject}\": write public, member, or a role listed in access.roles`, AUTH_FILE)\n }\n const unknown = words.filter((w) => w !== 'own' && !ACCESS_VERBS.has(w))\n if (unknown.length > 0) add('warning', 'APP_ACCESS_RULE', `${at} has words that are not verbs (${unknown.join(', ')}); a server ignores them. Verbs: ${[...ACCESS_VERBS].join(', ')}, and own`, AUTH_FILE)\n if (!words.some((w) => ACCESS_VERBS.has(w))) add('warning', 'APP_ACCESS_RULE', `${at} has no verb, so it grants nothing`, AUTH_FILE)\n if (typeId) {\n const listsWhole = !words.includes('own') && words.some((w) => w === 'list' || w === 'read')\n ruled.set(typeId, (ruled.get(typeId) ?? false) || listsWhole)\n }\n })\n }\n\n // ---- app content: the records an app ships for every visitor ----\n // app/content/<typeId>.json is published into the record store once per\n // record (insert when the id is absent, never overwrite). Its ids must be\n // stable and server-grade. A content record has no creator, so a collection\n // the rules let visitors read only `own` records of shows it to nobody.\n const contentPaths = paths.filter((p) => p.startsWith(APP_CONTENT))\n if (contentPaths.length > 0) {\n const declared = new Set(entityNames.values())\n for (const path of contentPaths) {\n const rest = path.slice(APP_CONTENT.length)\n if (rest.includes('/') || !rest.endsWith('.json')) {\n add('warning', 'APP_UNEXPECTED_FILE', `${path} is not an app/content/<typeId>.json`, path)\n continue\n }\n const typeId = rest.slice(0, -'.json'.length)\n const parsed = parseJson(pack.files.get(path) as Uint8Array)\n if (!parsed.ok) continue // JSON_INVALID below\n if (!declared.has(typeId)) {\n add('error', 'APP_CONTENT_UNDECLARED', `${path} fills \"${typeId}\", which ${ENTITIES_FILE} does not declare`, path)\n continue\n }\n if (ruled.get(typeId) === false) {\n add('warning', 'APP_CONTENT_UNREADABLE', `${path} fills \"${typeId}\", but the access rules let nobody read it except their own records; no visitor sees this content`, path)\n }\n const doc = parsed.value\n if (!isRecord(doc) || !Array.isArray(doc['data'])) {\n add('error', 'APP_CONTENT_INVALID', `${path} must be { \"data\": [ ...records ] }`, path)\n continue\n }\n const seen = new Set<string>()\n doc['data'].forEach((row: unknown, i: number) => {\n const id = isRecord(row) ? row['id'] : undefined\n if (typeof id !== 'string' || !UUID.test(id)) {\n add('error', 'APP_CONTENT_ID', `${path} data[${i}] needs an \"id\" that is a UUID: it stays the record's id once published, and relations point at it`, path)\n } else if (seen.has(id.toLowerCase())) {\n add('error', 'APP_CONTENT_ID', `${path} data[${i}] repeats id ${id}`, path)\n } else seen.add(id.toLowerCase())\n })\n }\n }\n\n // ---- JSON well-formedness ----\n for (const path of paths) {\n if (!path.endsWith('.json') || path === IDENTITY_FILE || path === MEDIA_PROVENANCE) continue\n const parsed = parseJson(pack.files.get(path) as Uint8Array)\n if (parsed.ok) continue\n const severity = path.startsWith('app/') ? 'error' : 'warning'\n add(severity, 'JSON_INVALID', `${path} is not JSON: ${parsed.error}`, path)\n }\n\n // ---- atoms ----\n const firstDir = new Map<string, string>()\n for (const { ref, dir } of atomOccurrences(pack)) {\n const key = `${ref.kind}:${ref.id}`\n const seenDir = firstDir.get(key)\n if (seenDir === undefined) firstDir.set(key, dir)\n else if (seenDir !== dir) {\n add('error', 'DUPLICATE_ATOM', `${key} comes from both ${seenDir} and ${dir}`, ref.relPath)\n }\n }\n\n // ---- media ----\n const mediaFiles = paths.filter((p) => p.startsWith('media/') && p !== MEDIA_PROVENANCE)\n const declared = new Set<string>()\n // Undeclared media is only computed against a provenance record that is\n // valid; an invalid one is reported once, not once per media file.\n const provenance = readMediaProvenance(pack)\n if (provenance.state === 'invalid') {\n for (const issue of provenance.issues) add('error', 'MEDIA_PROVENANCE_INVALID', `media/provenance.json ${issue}`, MEDIA_PROVENANCE)\n } else if (provenance.state === 'valid') {\n for (const item of provenance.value.items) {\n declared.add(item.path)\n const bytes = pack.files.get(item.path)\n if (!bytes) {\n add('error', 'MEDIA_PROVENANCE_PATH_MISSING', `media/provenance.json lists ${item.path}, which the pack does not carry`, item.path)\n } else if (item.hash.startsWith('sha256:') && item.hash !== `sha256:${sha256Hex(bytes)}`) {\n add('warning', 'MEDIA_HASH_MISMATCH', `${item.path} does not match the hash media/provenance.json records`, item.path)\n }\n }\n }\n for (const path of provenance.state === 'invalid' ? [] : mediaFiles) {\n if (!declared.has(path)) add('warning', 'MEDIA_UNDECLARED', `${path} has no entry in media/provenance.json`, path)\n }\n // Declarations: which layout, and whether the bytes they name are there.\n issues.push(...mediaDeclarations(pack).issues)\n\n return {\n ok: !issues.some((i) => i.severity === 'error'),\n issues,\n identity,\n layout,\n atoms: deriveAtoms(pack),\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pwfabric/pack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Read, validate, hash and write the pwpack folder and its deterministic .pwpack archive",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=22"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@pwfabric/contracts": "1.
|
|
36
|
+
"@pwfabric/contracts": "1.1.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.0.0",
|