@lde/iiif-validator 0.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.
Files changed (2) hide show
  1. package/README.md +44 -0
  2. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # IIIF Validator
2
+
3
+ Validates that a URL dereferences to a valid [IIIF Presentation](https://iiif.io/api/presentation/) Manifest. A small, dependency-light building block for Linked Data tooling that needs to tell a _declared_ IIIF manifest apart from one that actually resolves and parses.
4
+
5
+ ```ts
6
+ import { validateManifest } from '@lde/iiif-validator';
7
+
8
+ const verdict = await validateManifest('https://example.org/manifest.json');
9
+ if (verdict.valid) {
10
+ // verdict.reason === 'valid-manifest'
11
+ }
12
+ ```
13
+
14
+ `validateManifest` never throws; every outcome is reported as a `ManifestValidation`:
15
+
16
+ ```ts
17
+ interface ManifestValidation {
18
+ valid: boolean;
19
+ reason:
20
+ | 'valid-manifest'
21
+ | 'timeout'
22
+ | 'network-error'
23
+ | 'http-error'
24
+ | 'invalid-json'
25
+ | 'not-a-manifest';
26
+ }
27
+ ```
28
+
29
+ ## Behaviour
30
+
31
+ - **Dereference over HTTP** with `Accept: application/ld+json, application/json`, following redirects, using the global `fetch` with an `AbortSignal` timeout (default 10 000 ms). Both are injectable via the options argument (`fetch`, `timeoutMs`).
32
+ - **Lightweight, version-aware structural check.** A document is valid when the response is HTTP 2xx, the body parses as JSON, its `@context` references an IIIF Presentation context, and its `type`/`@type` indicates a manifest – accepting both v3 (`Manifest`) and v2 (`sc:Manifest`). The `@context` value may be a string, an array, or an object; all forms are handled. The version segment of the context is accepted version-agnostically.
33
+ - **Strict failure semantics, no retries.** A timeout, network error, non-2xx status, unparseable body, missing IIIF `@context`, or wrong `type` all yield `valid: false` with the corresponding coarse `reason`. There is no deep JSON Schema validation and no dependency on the hosted IIIF Presentation Validator service.
34
+
35
+ ## Options
36
+
37
+ ```ts
38
+ interface ValidateManifestOptions {
39
+ /** `fetch` implementation to use. Injectable for testing; defaults to the global `fetch`. */
40
+ fetch?: typeof globalThis.fetch;
41
+ /** Per-request timeout in milliseconds. Defaults to 10 000. */
42
+ timeoutMs?: number;
43
+ }
44
+ ```
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@lde/iiif-validator",
3
+ "version": "0.1.0",
4
+ "repository": {
5
+ "url": "git+https://github.com/ldelements/lde.git",
6
+ "directory": "packages/iiif-validator"
7
+ },
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "development": "./src/index.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist",
24
+ "!**/*.tsbuildinfo"
25
+ ],
26
+ "dependencies": {
27
+ "tslib": "^2.3.0"
28
+ }
29
+ }