jpegxl 8.4.0 → 8.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +294 -229
  2. package/dist/animation.browser.mjs +2 -2
  3. package/dist/animation.mjs +2 -2
  4. package/dist/capture-complete.browser.mjs +2 -2
  5. package/dist/capture-complete.mjs +2 -2
  6. package/dist/capture-groups.mjs +2 -2
  7. package/dist/capture.browser.mjs +2 -2
  8. package/dist/capture.mjs +2 -2
  9. package/dist/cli-add.mjs +2 -2
  10. package/dist/cli-astro.mjs +2 -2
  11. package/dist/cli-cloudflare.mjs +2 -2
  12. package/dist/cli-emdash.mjs +2 -2
  13. package/dist/cli-places.mjs +2 -2
  14. package/dist/cli-selftest.mjs +2 -2
  15. package/dist/cli-workers.mjs +2 -2
  16. package/dist/cli.mjs +2 -2
  17. package/dist/decode.browser.mjs +2 -2
  18. package/dist/decode.mjs +2 -2
  19. package/dist/decode.node.mjs +2 -2
  20. package/dist/format.browser.mjs +2 -2
  21. package/dist/format.mjs +2 -2
  22. package/dist/hdr.mjs +2 -2
  23. package/dist/helpers.mjs +2 -2
  24. package/dist/index.browser.mjs +2 -2
  25. package/dist/index.mjs +2 -2
  26. package/dist/jpeg.browser.mjs +2 -2
  27. package/dist/jpeg.mjs +2 -2
  28. package/dist/jpeg.node.mjs +2 -2
  29. package/dist/metadata.mjs +2 -2
  30. package/dist/polyfill.mjs +2 -2
  31. package/dist/resumable.mjs +2 -2
  32. package/dist/resumable.node.mjs +2 -2
  33. package/dist/serve.mjs +2 -2
  34. package/dist/serve.node.mjs +2 -2
  35. package/dist/upload.browser.mjs +2 -2
  36. package/dist/upload.mjs +2 -2
  37. package/dist/verify.mjs +2 -2
  38. package/dist/verify.node.mjs +2 -2
  39. package/dist/wasm-modules.mjs +2 -2
  40. package/examples/agents/jxl-tools.mjs +8 -8
  41. package/examples/android/prepare-assets.mjs +2 -2
  42. package/examples/capacitor/prepare-assets.mjs +2 -2
  43. package/examples/emdash/admin-work.mjs +1 -1
  44. package/examples/emdash/backfill.mjs +4 -4
  45. package/examples/emdash/background.mjs +5 -5
  46. package/examples/emdash/browser-candidate.mjs +1 -1
  47. package/examples/emdash/deliver.mjs +2 -2
  48. package/examples/emdash/host-policy.mjs +6 -6
  49. package/examples/emdash/index.mjs +3 -3
  50. package/examples/emdash/job-runner.mjs +31 -31
  51. package/examples/emdash/job-store.mjs +21 -21
  52. package/examples/emdash/jpeg-source.mjs +2 -2
  53. package/examples/emdash/library-jobs.mjs +21 -21
  54. package/examples/emdash/local-store.mjs +16 -16
  55. package/examples/emdash/media-admin.mjs +9 -9
  56. package/examples/emdash/media-plugin.mjs +62 -62
  57. package/examples/emdash/media-storage.mjs +55 -55
  58. package/examples/emdash/media-words.mjs +89 -89
  59. package/examples/emdash/media-worker.mjs +1 -1
  60. package/examples/emdash/original-envelope.mjs +2 -2
  61. package/examples/emdash/originals.mjs +77 -77
  62. package/examples/emdash/r2-store.mjs +3 -3
  63. package/examples/emdash/read-all.mjs +14 -14
  64. package/examples/emdash/server-only.mjs +1 -1
  65. package/examples/emdash/storage.mjs +1 -1
  66. package/examples/emdash/structural-delivery.mjs +42 -42
  67. package/examples/emdash/thread-driver.mjs +15 -15
  68. package/examples/emdash/thread-worker.mjs +3 -3
  69. package/examples/emdash/work-queue.mjs +11 -11
  70. package/examples/flutter/prepare-assets.mjs +3 -3
  71. package/examples/ios/prepare-assets.mjs +3 -3
  72. package/examples/page-rects.js +14 -14
  73. package/examples/react-native/src/JXLProvider.tsx +19 -9
  74. package/examples/snapdom/jxl.js +3 -2
  75. package/examples/svg-jxl.js +10 -10
  76. package/package.json +1 -1
  77. package/types/animation.d.mts +2 -2
  78. package/types/capture-complete.d.mts +5 -5
  79. package/types/capture.d.mts +1 -1
  80. package/types/format.d.mts +2 -2
  81. package/types/index.d.mts +6 -6
  82. package/types/jpeg.d.mts +1 -1
  83. package/types/result.d.mts +5 -4
  84. package/types/resumable.d.mts +7 -7
  85. package/types/serve.d.mts +1 -1
  86. package/types/types.d.mts +19 -18
  87. package/types/upload.d.mts +1 -1
  88. package/types/verify.d.mts +4 -4
@@ -8,7 +8,7 @@ import {COLOR_HEADER_BYTES, colorOf, isColor, sameColor, checkable} from './colo
8
8
 
9
9
  const ACTIVE = Symbol.for('rapier-jxl.emdash.storage');
10
10
  export function registerStorage(storage, scope) {
11
- if (typeof scope !== 'string' || !scope.length) throw new TypeError('Native storage requires its configured backend scope.');
11
+ if (typeof scope !== 'string' || !scope.length) throw new TypeError('storage: backend scope');
12
12
  globalThis[ACTIVE] = {storage, scope};
13
13
  return storage;
14
14
  }
@@ -30,7 +30,7 @@ const failure = (code, message, cause) => Object.assign(new Error(message, cause
30
30
  function publicKey(key) {
31
31
  if (typeof key !== 'string' || !key || key.includes('\\') || key.includes('\0') ||
32
32
  key.split('/').some(part => !part || part === '.' || part === '..') || key.startsWith(ROOT))
33
- throw failure('JXL_INPUT', "Invalid media key; use a key within public storage.");
33
+ throw failure('JXL_INPUT', "media key: public storage");
34
34
  return key;
35
35
  }
36
36
 
@@ -47,10 +47,10 @@ function meetsFloor(fidelity, floor) {
47
47
  export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1024, create, compareAndSet, originalBackend,
48
48
  cpuLimitMs, memoryLimitBytes} = {}) {
49
49
  if (maxPixels !== undefined && (!Number.isSafeInteger(maxPixels) || maxPixels < 1))
50
- throw failure('JXL_OPTIONS', "Invalid maxPixels; use a positive safe integer.");
51
- if (create !== undefined && typeof create !== 'function') throw failure('JXL_OPTIONS', "Invalid create; supply an atomic create-only function.");
50
+ throw failure('JXL_OPTIONS', "maxPixels: positive safe integer");
51
+ if (create !== undefined && typeof create !== 'function') throw failure('JXL_OPTIONS', "create: atomic create-only function");
52
52
  if (compareAndSet !== undefined && typeof compareAndSet !== 'function')
53
- throw failure('JXL_OPTIONS', "Invalid compareAndSet; supply a conditional write function.");
53
+ throw failure('JXL_OPTIONS', "compareAndSet: conditional write function");
54
54
  let originals;
55
55
  const physicalStore = inner;
56
56
  const host = hostLimits(originalBackend?.platform ?? 'node', {cpuLimitMs, memoryLimitBytes});
@@ -72,7 +72,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
72
72
  catch (error) {
73
73
  signal?.throwIfAborted();
74
74
  if (error?.code === 'NOT_FOUND' || error?.code?.startsWith('JXL_')) throw error;
75
- throw failure('JXL_INTERNAL', "Invalid image result; report the input and options.", error);
75
+ throw failure('JXL_INTERNAL', "media-storage:handler", error);
76
76
  }
77
77
  }
78
78
  async function files(prefix, signal, call = direct) {
@@ -81,7 +81,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
81
81
  const page = await io(() => call(() => inner.list({prefix, limit: 100, signal, ...(cursor ? {cursor} : {})})), signal);
82
82
  all.push(...page.files.filter(file => file.key.startsWith(prefix)));
83
83
  if (!page.nextCursor) return all;
84
- if (seen.has(page.nextCursor)) throw failure('JXL_INTERNAL', "Invalid image result; report the input and options.");
84
+ if (seen.has(page.nextCursor)) throw failure('JXL_INTERNAL', "media-storage:page-cursor");
85
85
  seen.add(page.nextCursor); cursor = page.nextCursor;
86
86
  }
87
87
  }
@@ -91,7 +91,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
91
91
  catch (error) { if (error?.code === 'NOT_FOUND') return null; throw error; }
92
92
  const bytes = await io(() => readAll(file.body, {maxBytes, signal}), signal);
93
93
  if (Number.isSafeInteger(file.size) && file.size !== bytes.length)
94
- throw failure('JXL_INPUT', "Wrong copy length; reload its record and retry.");
94
+ throw failure('JXL_INPUT', "copy length: reload record");
95
95
  return {...file, bytes, size: bytes.length};
96
96
  }
97
97
  const base = async key => ROOT + await digest(utf8(key)) + '.';
@@ -129,9 +129,9 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
129
129
  if (!file) return null;
130
130
  signal?.throwIfAborted();
131
131
  if (range && !headed && (file?.range?.offset !== range.offset || file.range.length !== range.length))
132
- throw failure('JXL_UNSUPPORTED', "Wrong source range; use a backend with range reads.");
132
+ throw failure('JXL_UNSUPPORTED', "source range: backend range reads");
133
133
  const version = await versionOf(file);
134
- if (range && !version) throw failure('JXL_UNSUPPORTED', "Missing generation; pass the captured source generation.");
134
+ if (range && !version) throw failure('JXL_UNSUPPORTED', "generation: captured source generation");
135
135
  return {generation: version, size: file.size};
136
136
  } catch (error) {
137
137
  failed = true;
@@ -149,7 +149,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
149
149
  // an existing archive on a host whose allowance changed must not trigger a cold restore inside a 10 ms request.
150
150
  async function physicalHead(key, {signal, call = direct} = {}) {
151
151
  if (!deliveryOnly(host) || typeof originalBackend?.head !== 'function')
152
- throw failure('JXL_UNSUPPORTED', "Missing host or source reader; configure a Free Worker with a storage head() function.");
152
+ throw failure('JXL_UNSUPPORTED', "reader: Free Worker storage head()");
153
153
  const file = await io(() => call(() => originalBackend.head(key, {signal})), signal);
154
154
  return file ? {generation: await versionOf(file), size: file.size} : null;
155
155
  }
@@ -159,17 +159,17 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
159
159
  const file = await io(() => call(() => physicalStore.download(key, {range: {offset: 0, length}, signal})), signal);
160
160
  try {
161
161
  if (file?.range?.offset !== 0 || file.range.length !== length)
162
- throw failure('JXL_UNSUPPORTED', "Wrong header range; use a backend with range reads.");
162
+ throw failure('JXL_UNSUPPORTED', "header range: backend range reads");
163
163
  if (file.size !== before.size || await versionOf(file) !== before.generation)
164
- throw failure('JXL_INPUT', "Original changed; reload its record and retry.");
164
+ throw failure('JXL_INPUT', "original: changed; reload record");
165
165
  const bytes = await io(() => readAll(file.body, {maxBytes: length, signal}), signal);
166
- if (bytes.length !== length) throw failure('JXL_INPUT', "Wrong header length; reread the requested range.");
166
+ if (bytes.length !== length) throw failure('JXL_INPUT', "header length: reread range");
167
167
  return bytes;
168
168
  } finally { try { await file?.body?.cancel?.(); } catch {} }
169
169
  }
170
170
  async function originalHeader(key, before, {signal, call = direct} = {}) {
171
171
  if (!Number.isSafeInteger(before?.size) || before.size < 8 || before.size > maxInputBytes || !before.generation)
172
- throw failure('JXL_LIMIT', "Missing source size or generation; read both first.");
172
+ throw failure('JXL_LIMIT', "source: size and generation");
173
173
  const mimeType = sourceMimeType(key);
174
174
  let bytes = await readPhysicalHeader(key, before, SOURCE_HEADER_BYTES, {signal, call});
175
175
  try { return {geometry: originalGeometry(bytes, {mimeType, maxPixels}), bytes}; }
@@ -205,7 +205,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
205
205
  }
206
206
  async function snapshot(key, {signal, call = direct} = {}) {
207
207
  publicKey(key);
208
- if (typeof call !== 'function') throw failure('JXL_OPTIONS', "Invalid storage dispatcher; pass a function.");
208
+ if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
209
209
  const file = await read(key, maxInputBytes, signal, call);
210
210
  if (!file) return null;
211
211
  const sha256 = await digest(file.bytes);
@@ -223,13 +223,13 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
223
223
  async function selectDelivery(key, mode, {expectedGeneration, expectedRevision, signal, call = direct} = {}) {
224
224
  publicKey(key);
225
225
  if (!HASH.test(expectedGeneration ?? '') || !COPY_ID.test(expectedRevision ?? '') || typeof call !== 'function')
226
- throw failure('JXL_OPTIONS', "Invalid revision; refresh the library.");
227
- if (!compareAndSet) throw failure('JXL_UNSUPPORTED', "Conditional writes unavailable; configure compare-and-set writes.");
226
+ throw failure('JXL_OPTIONS', "revision: refresh library");
227
+ if (!compareAndSet) throw failure('JXL_UNSUPPORTED', "writes: compare-and-set required");
228
228
  if (await generation(key, {signal, call}) !== expectedGeneration)
229
- throw failure('JXL_INPUT', "Picture changed; refresh the library.");
229
+ throw failure('JXL_INPUT', "picture: changed; refresh library");
230
230
  const prior = await delivery(key, expectedGeneration, signal, call);
231
231
  if (prior.revision !== expectedRevision || prior.etag === undefined)
232
- throw failure('JXL_INPUT', "Delivery setting changed; refresh the library.");
232
+ throw failure('JXL_INPUT', "delivery: changed; refresh library");
233
233
  const revision = crypto.randomUUID().replaceAll('-', ''), policyKey = await deliveryKey(key, expectedGeneration);
234
234
  const value = {owner: OWNER, kind: 'delivery', source: key, generation: expectedGeneration, revision, mode};
235
235
  let written, uncertain;
@@ -240,41 +240,41 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
240
240
  if (uncertain) {
241
241
  const observed = await delivery(key, expectedGeneration, signal, call);
242
242
  if (observed.revision !== revision || observed.mode !== mode) throw uncertain;
243
- } else if (written !== true) throw failure('JXL_INPUT', "Delivery setting changed; refresh the library.");
243
+ } else if (written !== true) throw failure('JXL_INPUT', "delivery: changed; refresh library");
244
244
  if (await generation(key, {signal, call}) !== expectedGeneration)
245
- throw failure('JXL_INPUT', "Picture changed; refresh the library.");
245
+ throw failure('JXL_INPUT', "picture: changed; refresh library");
246
246
  return {generation: expectedGeneration, revision, mode};
247
247
  }
248
248
  async function readSource(key, offset, length, {generation: expectedGeneration, signal, call = direct} = {}) {
249
249
  publicKey(key); signal?.throwIfAborted();
250
- if (typeof call !== 'function') throw failure('JXL_OPTIONS', "Invalid storage dispatcher; pass a function.");
250
+ if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
251
251
  if (typeof expectedGeneration !== 'string' || !HASH.test(expectedGeneration))
252
- throw failure('JXL_OPTIONS', "Missing generation; pass the captured source generation.");
252
+ throw failure('JXL_OPTIONS', "generation: captured source generation");
253
253
  if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || length < 1 || offset > maxInputBytes - length)
254
- throw failure('JXL_LIMIT', "Range exceeds maxInputBytes; raise it or request fewer bytes.");
254
+ throw failure('JXL_LIMIT', "range: maxInputBytes limit");
255
255
  let file;
256
256
  try {
257
257
  // Keep the returned body reachable if cancellation arrives during the download.
258
258
  file = await io(() => call(() => inner.download(key, {range: {offset, length}, signal})));
259
259
  signal?.throwIfAborted();
260
260
  if (!Number.isSafeInteger(file?.size) || file.size < 1)
261
- throw failure('JXL_INPUT', "Missing source size; supply its byte length.");
261
+ throw failure('JXL_INPUT', "source size: byte length");
262
262
  if (file.size > maxInputBytes || offset > file.size - length)
263
- throw failure('JXL_LIMIT', "Range exceeds source or maxInputBytes; request fewer bytes.");
263
+ throw failure('JXL_LIMIT', "range: within source and maxInputBytes");
264
264
  if (file.range?.offset !== offset || file.range.length !== length)
265
- throw failure('JXL_UNSUPPORTED', "Wrong source range; use a backend with range reads.");
265
+ throw failure('JXL_UNSUPPORTED', "source range: backend range reads");
266
266
  const version = await versionOf(file);
267
- if (!version) throw failure('JXL_UNSUPPORTED', "Missing generation; pass the captured source generation.");
268
- if (version !== expectedGeneration) throw failure('JXL_INPUT', "Source changed; reload its record and retry.");
267
+ if (!version) throw failure('JXL_UNSUPPORTED', "generation: captured source generation");
268
+ if (version !== expectedGeneration) throw failure('JXL_INPUT', "source: changed; reload record");
269
269
  const bytes = await io(() => readAll(file.body, {maxBytes: length, signal}), signal);
270
- if (bytes.length !== length) throw failure('JXL_INPUT', "Wrong source length; reread the requested range.");
270
+ if (bytes.length !== length) throw failure('JXL_INPUT', "source length: reread range");
271
271
  // A one-byte check also stays bounded for adapters that buffer downloads.
272
272
  if (await generation(key, {signal, range: {offset: 0, length: 1}, call}) !== expectedGeneration)
273
- throw failure('JXL_INPUT', "Source changed; reload its record and retry.");
273
+ throw failure('JXL_INPUT', "source: changed; reload record");
274
274
  return bytes;
275
275
  } catch (error) {
276
276
  signal?.throwIfAborted();
277
- if (error?.code === 'NOT_FOUND') throw failure('JXL_INPUT', "Source changed; reload its record and retry.");
277
+ if (error?.code === 'NOT_FOUND') throw failure('JXL_INPUT', "source: changed; reload record");
278
278
  throw error;
279
279
  } finally {
280
280
  try { Promise.resolve(file?.body?.cancel?.(signal?.aborted ? signal.reason : undefined)).catch(() => {}); } catch {}
@@ -446,21 +446,21 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
446
446
  const {width, height} = result ?? {};
447
447
  const refused = reason => ({key, ...(variant ? {width} : {}), stored: null, reason});
448
448
  signal?.throwIfAborted();
449
- if (typeof call !== 'function') throw failure('JXL_OPTIONS', "Invalid storage dispatcher; pass a function.");
450
- if (fence !== undefined && typeof fence !== 'function') throw failure('JXL_OPTIONS', "Invalid publication guard; pass its server function.");
449
+ if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
450
+ if (fence !== undefined && typeof fence !== 'function') throw failure('JXL_OPTIONS', "publication guard: server function");
451
451
  if (structural && (!deliveryOnly(host) || !HASH.test(expectedGeneration ?? '') || verified !== undefined || jobIdentity !== undefined))
452
- throw failure('JXL_UNSUPPORTED', "Delivery unsupported here; use a Free Worker or server verification.");
452
+ throw failure('JXL_UNSUPPORTED', "delivery: Free Worker or server verify");
453
453
  if (structural && replace)
454
- throw failure('JXL_UNSUPPORTED', "Delivery would replace copy history; clear it before selecting a new delivery.");
454
+ throw failure('JXL_UNSUPPORTED', "delivery: clear copy history");
455
455
  if (!IMAGE.test(key) || (!variant && !hasSidecar(key))) return refused('not_image_key');
456
456
  if (!structural && !HASH.test(source ?? '')) return refused('source_required');
457
457
  if (expectedGeneration !== undefined && !HASH.test(expectedGeneration))
458
- throw failure('JXL_OPTIONS', "Invalid generation; pass the source version digest.");
458
+ throw failure('JXL_OPTIONS', "generation: source version digest");
459
459
  if (!COPY_ID.test(expectedDeliveryRevision ?? ''))
460
- throw failure('JXL_OPTIONS', "Invalid revision; pass the revision captured before conversion.");
460
+ throw failure('JXL_OPTIONS', "revision: pre-conversion revision");
461
461
  if (jobIdentity !== undefined && (typeof jobIdentity !== 'string' || !COPY_ID.test(jobIdentity) || expectedGeneration === undefined))
462
- throw failure('JXL_OPTIONS', "Invalid rendition; pass its server ID and source generation.");
463
- if (typeof replace !== 'boolean') throw failure('JXL_OPTIONS', "Invalid replace; pass true or false.");
462
+ throw failure('JXL_OPTIONS', "rendition: server ID and generation");
463
+ if (typeof replace !== 'boolean') throw failure('JXL_OPTIONS', "replace: boolean");
464
464
  if (result?.meetsTarget !== true) return refused(result?.reason?.code ?? 'JXL_TARGET');
465
465
  if (result.format !== 'jxl' || !['jpeg-bytes', 'pixels', 'lossy'].includes(result.kept)) return refused('JXL_INPUT');
466
466
  const value = result.bytes;
@@ -478,7 +478,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
478
478
  : verified.source?.kind === 'bytes' && verified.source.digest === 'sha256:' + source) || !/^sha256:[a-f0-9]{64}$/.test(verified.outputDigest ?? '') ||
479
479
  verified.width !== width || verified.height !== height || verified.format !== savedResult.format ||
480
480
  verified.kept !== savedResult.kept || JSON.stringify(verified.fidelity) !== JSON.stringify(savedResult.fidelity))
481
- throw failure('JXL_INPUT', "Receipt mismatch; verify its original and candidate.");
481
+ throw failure('JXL_INPUT', "receipt: verify original/candidate");
482
482
  } else if (!structural) {
483
483
  let info;
484
484
  try { info = await inspect(bytes, {details: ['layout'], maxInputBytes: maxCopyBytes, maxPixels, maxBoxes: 4096}); }
@@ -517,7 +517,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
517
517
  catch (error) { signal?.throwIfAborted(); if (replace || !error?.verification) throw error; receipt = error.verification; }
518
518
  }
519
519
  if (!structural && receipt?.verified !== true) {
520
- if (replace) throw failure('JXL_INPUT', "Unverified replacement; verify it against its original.");
520
+ if (replace) throw failure('JXL_INPUT', "replacement: verify original");
521
521
  return refused('not_verified');
522
522
  }
523
523
  // Ruling 91: the copy's color and its source's, both read from headers, ride in its ownership record.
@@ -526,7 +526,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
526
526
  const slot = variant ? `w${width}` : 'main', previous = replace ? await records(key, before.generation, signal, slot, false, call) : [];
527
527
  // A persisted job reuses its identity; ordinary admissions are independent.
528
528
  const identity = jobIdentity ?? crypto.randomUUID().replaceAll('-', '');
529
- if (!COPY_ID.test(identity)) throw failure('JXL_INTERNAL', "Invalid image result; report the input and options.");
529
+ if (!COPY_ID.test(identity)) throw failure('JXL_INTERNAL', "media-storage:copy-id");
530
530
  const sha256 = verified ? verified.outputDigest.slice(7) : await digest(bytes), prefix = await base(key), stem =
531
531
  `${prefix}${before.generation}.${slot}.${identity}.${sha256}`;
532
532
  const copyKey = stem + '.jxl', recordKey = stem + '.json';
@@ -535,7 +535,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
535
535
  ...(preservedFor && {preservedFor}), ...(color && {color, sourceColor}), state: 'active'};
536
536
  const recordBytes = utf8(JSON.stringify(valueRecord));
537
537
  // The terminal state "retired" adds one byte to the serialized active record.
538
- if (recordBytes.length + 1 > MAX_RECORD_BYTES) throw failure('JXL_LIMIT', "Ownership record too large; reduce its contents.");
538
+ if (recordBytes.length + 1 > MAX_RECORD_BYTES) throw failure('JXL_LIMIT', "ownership record: too large");
539
539
  const owned = {...valueRecord, width, height, key: copyKey, recordKey, recordBytes, recordSize: recordBytes.length, size: bytes.length};
540
540
  const changed = fence && await fence();
541
541
  if (changed) return refused(changed);
@@ -589,7 +589,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
589
589
  // then the create-only record. A run stopped before the record leaves the copy unchecked; no key is overwritten.
590
590
  async function checkColor(key, {signal, call = direct} = {}) {
591
591
  publicKey(key);
592
- if (typeof call !== 'function') throw failure('JXL_OPTIONS', "Invalid storage dispatcher; pass a function.");
592
+ if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
593
593
  if (!create) return {checked: 0, differs: 0, reason: 'conditional_write_required'};
594
594
  if (!checkable(key)) return {checked: 0, differs: 0, reason: 'color_unread'};
595
595
  const head = await sourceHead(key, {signal, call});
@@ -621,7 +621,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
621
621
  ({source, generation, identity, sha256, bytes, result, kind, deliveryRevision, ...(color && {color, sourceColor}), key, recordKey});
622
622
  // Retire a refused copy and remove its payload (attach's `collect`); only its own bytes are deleted.
623
623
  async function collect(copy, {signal, call = direct} = {}) {
624
- if (typeof call !== 'function') throw failure('JXL_OPTIONS', "Invalid storage dispatcher; pass a function.");
624
+ if (typeof call !== 'function') throw failure('JXL_OPTIONS', "dispatcher: function");
625
625
  const prefix = typeof copy?.source === 'string' && IMAGE.test(copy.source) ? await base(copy.source) : null;
626
626
  if (!prefix || !HASH.test(copy.generation ?? '') || !COPY_ID.test(copy.identity ?? '') || !HASH.test(copy.sha256 ?? '') ||
627
627
  !COPY_ID.test(copy.deliveryRevision ?? '') ||
@@ -629,7 +629,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
629
629
  !copy.key.startsWith(prefix + copy.generation + '.') || !copy.key.endsWith(`.${copy.identity}.${copy.sha256}.jxl`) ||
630
630
  copy.recordKey !== copy.key.slice(0, -4) + '.json' ||
631
631
  ((copy.color !== undefined || copy.sourceColor !== undefined) && !(isColor(copy.color) && isColor(copy.sourceColor))))
632
- throw failure('JXL_INPUT', "Invalid retired copy; pass one returned by attach.");
632
+ throw failure('JXL_INPUT', "retired copy: attach result");
633
633
  return remove({...copy, owner: OWNER}, signal, call);
634
634
  }
635
635
 
@@ -639,20 +639,20 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
639
639
  async function preserveArchiveDelivery(key, result, options = {}) {
640
640
  const {signal, call = direct, source, expectedGeneration, expectedDeliveryRevision, receipt, jobIdentity, preservationId} = options;
641
641
  if (!COPY_ID.test(preservationId ?? ''))
642
- throw failure('JXL_INPUT', "Missing restore record; reload it.");
642
+ throw failure('JXL_INPUT', "restore record: reload");
643
643
  const eligible = async () => {
644
644
  const current = await deliveryState(key, {signal, call});
645
645
  return current?.generation === expectedGeneration && current.mode === 'copies' && current.revision === expectedDeliveryRevision;
646
646
  };
647
647
  if (!await eligible()) return {preserved: true, reason: 'no_longer_selected'};
648
648
  if (!(result?.bytes instanceof Uint8Array) || result.bytes.length < 2 || result.bytes.length > maxCopyBytes)
649
- throw failure('JXL_LIMIT', "Archive copy too large; keep its current delivery.");
649
+ throw failure('JXL_LIMIT', "archive copy: too large; retain delivery");
650
650
  if (result.kept !== 'jpeg-bytes' || result.fidelity !== 'exact' || receipt?.verified !== true ||
651
651
  receipt.kind !== 'jpeg-restore' || receipt.format !== 'jxl' || receipt.kept !== 'jpeg-bytes' || receipt.fidelity !== 'exact' ||
652
652
  receipt.source?.kind !== 'bytes' || receipt.source.digest !== 'sha256:' + source ||
653
653
  receipt.referenceDigest !== 'sha256:' + source || receipt.restoredDigest !== 'sha256:' + source ||
654
654
  receipt.outputDigest !== 'sha256:' + await digest(result.bytes))
655
- throw failure('JXL_INPUT', "Archive receipt mismatch; verify its original and candidate.");
655
+ throw failure('JXL_INPUT', "archive receipt: verify original/candidate");
656
656
  const published = await attach(key, result, {source, expectedGeneration, expectedDeliveryRevision, receipt,
657
657
  jobIdentity, signal, call}, false, undefined, preservationId);
658
658
  if (published?.stored === 'sidecar') return {preserved: true, publication: published};
@@ -662,7 +662,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
662
662
  if (published.collect) await collect(published.collect, {signal, call});
663
663
  return {preserved: true, reason: 'no_longer_selected'};
664
664
  }
665
- throw failure('JXL_IO', "Archive delivery unconfirmed; reconcile its publication before retrying.");
665
+ throw failure('JXL_IO', "archive delivery: reconcile publication");
666
666
  }
667
667
 
668
668
  const extra = {
@@ -680,7 +680,7 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
680
680
  async sourceSnapshot(key, options) {
681
681
  const file = await snapshot(key, options);
682
682
  if (!file) return null;
683
- if (!file.generation) throw failure('JXL_INPUT', "Missing generation; pass the source generation.");
683
+ if (!file.generation) throw failure('JXL_INPUT', "generation: source generation");
684
684
  const selected = await delivery(key, file.generation, options?.signal, options?.call);
685
685
  // Bind verification admission to the actual original, never a browser's smaller output or a plugin default.
686
686
  // The public reader supplies geometry without decoding pixels. An unreadable header supplies no bound.
@@ -791,11 +791,11 @@ export function withMediaCopies(inner, {maxPixels, maxInputBytes = 32 * 1024 * 1
791
791
  // removes the copy of each whose source is gone (remove() above). A source that is there, a record that is not
792
792
  // ours and every other object are left as they are. Returns the cursor for the next step, null after the last page.
793
793
  async sweepCopies({cursor, limit = 25, signal, call = direct} = {}) {
794
- if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw failure('JXL_OPTIONS', "Invalid limit; use 1 to 100.");
794
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw failure('JXL_OPTIONS', "limit: integer 1-100");
795
795
  // One listing per first hex digit of a record's name: EmDash's local storage lists only the names that start with
796
796
  // the prefix's last segment, so the whole folder cannot be listed at once. The cursor is "<digit>:<listing cursor>".
797
797
  const at = /^([0-9a-f]):(.*)$/.exec(cursor ?? '0:');
798
- if (!at) throw failure('JXL_OPTIONS', "Invalid cursor; pass the preceding step's cursor.");
798
+ if (!at) throw failure('JXL_OPTIONS', "cursor: preceding step");
799
799
  const page = await io(() => call(() => inner.list({prefix: ROOT + at[1], limit, signal, ...(at[2] ? {cursor: at[2]} : {})})), signal);
800
800
  const next = page.nextCursor ? at[1] + ':' + page.nextCursor : at[1] === 'f' ? null : (parseInt(at[1], 16) + 1).toString(16) + ':';
801
801
  const result = {examined: 0, removed: 0, cursor: next};
@@ -112,7 +112,7 @@ export const WORDS = {
112
112
  setupAgentTab: 'Coding agent',
113
113
  setupManualTab: 'By hand',
114
114
  setupCommand: 'npx jpegxl add emdash',
115
- setupAgent: 'Add rapier-jxl to my EmDash site with npx jpegxl add emdash.',
115
+ setupAgent: 'Add jpegxl to my EmDash site with npx jpegxl add emdash.',
116
116
  setupInstall: 'npm install jpegxl \\\n @cloudflare/kumo@2.6.0',
117
117
  setupManual: "import {jxl}\n from 'jpegxl/emdash';\n\njxl(emdash, {\n // Your existing EmDash options.\n})",
118
118
  setupOpen: 'open the optimizer',
@@ -211,90 +211,90 @@ Options:
211
211
 
212
212
  Uses EMDASH_TOKEN or the matching EmDash login.
213
213
  `,
214
- manual: "import {jxl} from 'jpegxl/emdash' and replace emdash({...}) with jxl(emdash, {...}), keeping the site's storage and other options",
215
- removeFix: `keep the integration enabled until every JPEG is restored, then run npx ${CLI} remove emdash again`,
216
- addOption: 'Unknown add emdash option: {option}',
217
- addHelpFix: `run npx ${CLI} add emdash --help`,
214
+ manual: "import {jxl} from 'jpegxl/emdash'; use jxl(emdash, {...})",
215
+ removeFix: `restore JPEGs before disable; run npx ${CLI} remove emdash`,
216
+ addOption: 'unknown option: {option}',
217
+ addHelpFix: `run: npx ${CLI} add emdash --help`,
218
218
  workersQuestion: 'Workers Paid?',
219
- workersChoice: 'Choose the Workers allowance for this Cloudflare site',
220
- workersChoiceFix: `run npx ${CLI} add emdash with --workers-paid or --workers-free; Node needs neither flag`,
221
- workersAnswer: 'Answer yes or no',
222
- workersDowngrade: 'Restore archived JPEG originals before changing this integration to Workers Free',
223
- workersDowngradeFix: `run npx ${CLI} remove emdash under the existing allowance, then run npx ${CLI} add emdash --workers-free`,
224
- workersHost: 'The native Workers allowance is not an unambiguous numeric option',
225
- workersHostFix: 'use an explicit cpuLimitMs number in the third jxl(emdash, config, options) argument, then run setup again',
226
- workersSource: 'Expected one regular source wrangler.json or wrangler.jsonc in the site folder',
227
- workersSourceFix: 'configure the intended source Worker manually; use cpuLimitMs: 30000 and limits.cpu_ms: 30000 for Paid, or cpuLimitMs: 10 with no custom CPU limit for Free',
228
- workersEnvironment: 'This Worker has an environment or config selection that setup cannot safely choose',
229
- workersEnvironmentFix: 'configure the intended Worker environment and its matching native CPU allowance explicitly before running setup',
230
- workersJson: 'The source Wrangler config must be one unambiguous JSON or JSONC object',
231
- workersChanged: 'The source Wrangler config changed during setup',
232
- workersChangedFix: 'keep your latest config, finish that edit, then run setup again',
219
+ workersChoice: 'workers: --workers-paid or --workers-free',
220
+ workersChoiceFix: `flags: --workers-paid or --workers-free; Node: omit flags`,
221
+ workersAnswer: 'workers: yes or no',
222
+ workersDowngrade: 'workers-free: restore JPEGs first',
223
+ workersDowngradeFix: `run: npx ${CLI} remove emdash; then npx ${CLI} add emdash --workers-free`,
224
+ workersHost: 'cpuLimitMs: explicit number',
225
+ workersHostFix: 'cpuLimitMs: set third jxl() argument',
226
+ workersSource: 'wrangler: one source json/jsonc',
227
+ workersSourceFix: 'Paid: cpuLimitMs 30000, limits.cpu_ms 30000; Free: cpuLimitMs 10, no limits.cpu_ms',
228
+ workersEnvironment: 'worker environment: explicit selection',
229
+ workersEnvironmentFix: 'worker: configure matching environment and CPU allowance',
230
+ workersJson: 'wrangler: single JSON/JSONC object',
231
+ workersChanged: 'wrangler: changed during setup',
232
+ workersChangedFix: 'finish config edit; rerun setup',
233
233
  updatedWrangler: 'Updated {file}.',
234
- removeOption: 'Unknown remove emdash option: {option}',
235
- removeHelpFix: `run npx ${CLI} remove emdash --help`,
236
- explicitObject: 'Cannot edit astro.config.mjs safely: {property} needs an explicit object',
237
- explicitProperty: 'Cannot edit astro.config.mjs safely: expected one explicit {property} property',
238
- laterProperty: 'Cannot edit astro.config.mjs safely: a later spread or computed key may replace {property}',
239
- configSyntax: 'Cannot read astro.config.mjs',
240
- configSyntaxFix: 'fix its JavaScript syntax, then run this command again',
241
- emdashImport: 'Cannot edit astro.config.mjs safely: expected one EmDash import from emdash/astro',
242
- configDynamic: 'Cannot edit astro.config.mjs safely: export a config object or defineConfig({...}); this config is dynamic',
243
- explicitIntegrations: 'Cannot edit astro.config.mjs safely: integrations must be an explicit array without spreads',
244
- reactMissing: 'The EmDash admin needs react() in integrations',
245
- reactFix: `add the @astrojs/react integration to this site, then run npx ${CLI} add emdash again`,
246
- oneIntegration: 'Cannot edit astro.config.mjs safely: expected one EmDash integration in integrations',
247
- explicitOptions: 'Cannot edit astro.config.mjs safely: the EmDash options must be one explicit object',
248
- explicitStorage: "Cannot edit astro.config.mjs safely: use the site's local() or r2() storage directly in its EmDash options",
249
- directWrapper: 'Cannot edit astro.config.mjs safely: the wrapper call is not direct',
250
- explicitWrapperImport: 'Cannot edit astro.config.mjs safely: the wrapper import is not explicit',
251
- directEmdash: 'Cannot edit astro.config.mjs safely: the EmDash call is not direct',
252
- manifest: 'Cannot read {file}',
253
- manifestFix: 'fix that file, then run this command again',
254
- ambiguousPackage: 'More than one npx package was requested, so the local jpegxl source is ambiguous',
255
- ambiguousPackageFix: `run ${CLI} add emdash --package <jpegxl.tgz> to name the local build explicitly`,
256
- localPackage: '--package must name a local .tgz file',
257
- localPackageFix: 'pass the tarball made by npm pack',
258
- packageRead: 'Cannot read the package tarball',
259
- packageReadFix: 'pass an intact local tarball made by npm pack',
260
- packageMissing: 'That tarball does not contain jpegxl/emdash',
261
- packageMissingFix: 'pack the jpegxl build that includes the EmDash integration',
262
- managerType: 'packageManager in package.json must be a string',
263
- managerTypeFix: 'set it to the package manager this site uses, then run this command again',
264
- managerUnsupported: "Cannot install with the site's package manager: {manager}",
265
- managerUnsupportedFix: 'install jpegxl and @cloudflare/kumo with that manager, then run this command again',
266
- managerAmbiguous: 'More than one package manager lockfile is present',
267
- managerAmbiguousFix: 'set packageManager in package.json to the manager this site uses, then run this command again',
268
- managerRun: 'Could not run {manager}',
269
- managerRunFix: 'install jpegxl and @cloudflare/kumo with {manager}, then run this command again',
270
- managerExit: '{manager} install did not finish ({reason})',
271
- managerExitCode: 'exit {code}',
272
- managerExitFix: `resolve the install error, then run npx ${CLI} add emdash again`,
273
- configFile: 'Cannot edit astro.config.mjs safely: this folder needs a regular, unlinked config file',
274
- configFileFix: 'run this in the EmDash site folder; for a shared or differently named config, add jxl(emdash, {...}) manually',
275
- siteMissing: 'This folder does not declare an EmDash and Astro site in package.json',
276
- siteMissingFix: 'run this command in the existing EmDash site folder',
277
- adminMissing: 'The installed EmDash admin needs @cloudflare/kumo 2.6.0 or later',
278
- adminMissingFix: `install the site's EmDash dependencies with its package manager, then run npx ${CLI} add emdash again`,
279
- kumoMismatch: 'The site uses @cloudflare/kumo {siteVersion}, but its EmDash admin uses {hostVersion}',
280
- kumoMismatchFix: `align the site's @cloudflare/kumo dependency with EmDash ({hostVersion}), then run npx ${CLI} add emdash again`,
281
- dependencyOld: '{dependency} {minimum} or later is needed (installed: {version})',
282
- dependencyOldFix: `update {dependency} with the site's package manager, then run npx ${CLI} add emdash again`,
234
+ removeOption: 'unknown option: {option}',
235
+ removeHelpFix: `run: npx ${CLI} remove emdash --help`,
236
+ explicitObject: '{property}: explicit object',
237
+ explicitProperty: '{property}: one explicit property',
238
+ laterProperty: '{property}: later spread/computed key',
239
+ configSyntax: 'astro.config.mjs: unreadable',
240
+ configSyntaxFix: 'fix JavaScript syntax; rerun',
241
+ emdashImport: 'import: one emdash/astro',
242
+ configDynamic: 'config: static object or defineConfig({...})',
243
+ explicitIntegrations: 'integrations: array without spreads',
244
+ reactMissing: 'integrations: react() needed',
245
+ reactFix: `add @astrojs/react; run npx ${CLI} add emdash`,
246
+ oneIntegration: 'integrations: one EmDash',
247
+ explicitOptions: 'EmDash options: explicit object',
248
+ explicitStorage: "storage: local() or r2()",
249
+ directWrapper: 'wrapper: direct call',
250
+ explicitWrapperImport: 'wrapper: explicit import',
251
+ directEmdash: 'EmDash: direct call',
252
+ manifest: '{file}: unreadable',
253
+ manifestFix: 'fix {file}; rerun',
254
+ ambiguousPackage: 'package: ambiguous npx source',
255
+ ambiguousPackageFix: `run: ${CLI} add emdash --package <jpegxl.tgz>`,
256
+ localPackage: '--package: local .tgz',
257
+ localPackageFix: 'use npm pack tarball',
258
+ packageRead: 'tarball: unreadable',
259
+ packageReadFix: 'use intact npm pack tarball',
260
+ packageMissing: 'tarball: missing jpegxl/emdash',
261
+ packageMissingFix: 'pack build with jpegxl/emdash',
262
+ managerType: 'packageManager: string',
263
+ managerTypeFix: 'set packageManager in package.json',
264
+ managerUnsupported: "package manager: {manager} unsupported",
265
+ managerUnsupportedFix: 'install jpegxl and @cloudflare/kumo with {manager}',
266
+ managerAmbiguous: 'lockfiles: multiple package managers',
267
+ managerAmbiguousFix: 'set packageManager in package.json',
268
+ managerRun: '{manager}: run failed',
269
+ managerRunFix: 'install jpegxl and @cloudflare/kumo with {manager}',
270
+ managerExit: '{manager}: install failed ({reason})',
271
+ managerExitCode: 'exit: {code}',
272
+ managerExitFix: `fix install; run npx ${CLI} add emdash`,
273
+ configFile: 'astro.config.mjs: regular unlinked file',
274
+ configFileFix: 'run in EmDash site; otherwise configure jxl() manually',
275
+ siteMissing: 'site: EmDash and Astro dependencies',
276
+ siteMissingFix: 'run in EmDash site folder',
277
+ adminMissing: '@cloudflare/kumo: >=2.6.0',
278
+ adminMissingFix: `install EmDash dependencies; run npx ${CLI} add emdash`,
279
+ kumoMismatch: '@cloudflare/kumo: {siteVersion} vs {hostVersion}',
280
+ kumoMismatchFix: `install @cloudflare/kumo@{hostVersion}; run npx ${CLI} add emdash`,
281
+ dependencyOld: '{dependency}: >= {minimum}, got {version}',
282
+ dependencyOldFix: `update {dependency}; run npx ${CLI} add emdash`,
283
283
  installing: 'Installing {packages} with {manager}…',
284
284
  dryRun: 'Dry run, nothing changed. Would install: {packages}. Would update: {files}.',
285
285
  dryRunNone: 'nothing',
286
286
  tarball: 'the jpegxl tarball',
287
287
  packageSeparator: ' and ',
288
- installedMissing: 'The installed jpegxl does not include jpegxl/emdash',
289
- installedMissingFix: 'reinstall jpegxl, then run this command again',
290
- packageChanged: 'The local package changed during setup or its installed version differs',
291
- packageChangedFix: 'finish packing the package, then run this command again',
292
- dependencyMissing: '{dependency} {minimum} or later is not installed',
293
- dependencyMissingFix: "install {dependency} with the site's package manager, then run this command again",
294
- kumoInstalledMismatch: 'The installed @cloudflare/kumo does not match the EmDash admin',
295
- kumoInstalledFix: "install @cloudflare/kumo@{hostVersion} with the site's package manager, then run this command again",
296
- configChanged: 'astro.config.mjs changed during {action}; it was not overwritten',
297
- configChangedFix: 'review the change, then run this command again',
288
+ installedMissing: 'package: missing jpegxl/emdash',
289
+ installedMissingFix: 'reinstall jpegxl; rerun',
290
+ packageChanged: 'package: changed during setup',
291
+ packageChangedFix: 'finish packing; rerun setup',
292
+ dependencyMissing: '{dependency}: >= {minimum} required',
293
+ dependencyMissingFix: "install {dependency}; rerun",
294
+ kumoInstalledMismatch: '@cloudflare/kumo: admin mismatch',
295
+ kumoInstalledFix: "install @cloudflare/kumo@{hostVersion}; rerun",
296
+ configChanged: 'astro.config.mjs: changed during {action}',
297
+ configChangedFix: 'review config; rerun',
298
298
  setup: 'setup',
299
299
  removal: 'removal',
300
300
  updated: 'Updated astro.config.mjs. The site keeps its existing storage and plugins.',
@@ -304,16 +304,16 @@ Uses EMDASH_TOKEN or the matching EmDash login.
304
304
  alreadyRemoved: '{name} is not enabled in astro.config.mjs.',
305
305
  removed: CLI_REMOVAL + ' Removed {name} from astro.config.mjs.',
306
306
  restartRemoved: 'Rebuild and redeploy the site to finish removal.',
307
- removalUrl: 'Expected an EmDash site origin with HTTPS, or HTTP on localhost',
308
- removalUrlFix: 'pass --url with the site origin; URL credentials, paths, queries and fragments are not accepted',
309
- removalClient: 'The installed EmDash client transport is unavailable',
310
- removalClientFix: "install this site's EmDash dependencies, then run this command again",
311
- credentials: 'The matching EmDash login could not be read or has expired',
312
- loginFix: 'run npx emdash login --url {url}, or set EMDASH_TOKEN for that site, then run this command again',
313
- credentialHeader: 'The matching EmDash login has invalid custom headers',
314
- requestFailed: 'The EmDash restoration request failed ({status})',
315
- responseInvalid: 'EmDash returned an invalid restoration response',
316
- restorationMismatch: 'The restoration response belongs to another site, backend or operation',
317
- restorationFailed: 'JPEG restoration has not completed',
307
+ removalUrl: 'url: HTTPS or localhost HTTP',
308
+ removalUrlFix: '--url: origin only; no credentials/path/query/fragment',
309
+ removalClient: 'EmDash transport: unavailable',
310
+ removalClientFix: "install EmDash dependencies; rerun",
311
+ credentials: 'login: expired or missing',
312
+ loginFix: 'run: npx emdash login --url {url}; or EMDASH_TOKEN',
313
+ credentialHeader: 'login: invalid custom headers',
314
+ requestFailed: 'restoration request: {status}',
315
+ responseInvalid: 'restoration response: invalid',
316
+ restorationMismatch: 'restoration response: wrong site/backend/operation',
317
+ restorationFailed: 'JPEG restoration: incomplete',
318
318
  restoring: 'Restoring JPEGs: {count}',
319
319
  };
@@ -25,7 +25,7 @@ async function browserVerified(file, result, progress) {
25
25
  configureDecoder(decode, restore);
26
26
  const browserVerification = await verify(file, result, {onProgress: progress});
27
27
  if (browserVerification?.verified !== true)
28
- throw Object.assign(new Error("Delivery unverified; verify its original and candidate."), {code: 'JXL_INPUT'});
28
+ throw Object.assign(new Error("delivery: verify original/candidate"), {code: 'JXL_INPUT'});
29
29
  // Informational browser assurance is deliberately separate from the private server receipt.
30
30
  const {verification: ignored, ...candidate} = result;
31
31
  return {...candidate, browserVerification};
@@ -6,7 +6,7 @@ const UUID = Uint8Array.of(0x65, 0x6d, 0x64, 0x61, 0x73, 0x68, 0x4a, 0x58, 0x8c,
6
6
  export const ENVELOPE_BYTES = 40;
7
7
  export const ENVELOPE_PREFIX_BYTES = 4096;
8
8
  const equal = (a, b) => a.length === b.length && a.every((value, i) => value === b[i]);
9
- const fail = () => Object.assign(new Error("Invalid archive input; use an unwrapped JPEG XL container and a 32-digit hex ID."), {code: 'JXL_INPUT'});
9
+ const fail = () => Object.assign(new Error("archive: unwrapped JXL; ID: 32 hex"), {code: 'JXL_INPUT'});
10
10
  function insertion(bytes) {
11
11
  if (!(bytes instanceof Uint8Array) || bytes.length < 20 || !equal(bytes.subarray(0, 12), SIGNATURE) ||
12
12
  String.fromCharCode(...bytes.subarray(16, 20)) !== 'ftyp') throw fail();
@@ -36,7 +36,7 @@ export function wrapOriginal(payload, id) {
36
36
  export function unwrapOriginal(bytes, id, payloadBytes) {
37
37
  const marker = envelopeIdentity(bytes);
38
38
  if (!marker || marker.id !== id || bytes.length !== payloadBytes + ENVELOPE_BYTES)
39
- throw Object.assign(new Error("Archive owner mismatch; restore the matching original."), {code: 'JXL_INPUT'});
39
+ throw Object.assign(new Error("archive owner: restore matching original"), {code: 'JXL_INPUT'});
40
40
  const payload = new Uint8Array(payloadBytes);
41
41
  payload.set(bytes.subarray(0, marker.offset));
42
42
  payload.set(bytes.subarray(marker.offset + ENVELOPE_BYTES), marker.offset);