Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ Node.js 22 or newer is required. The package is ESM and includes TypeScript decl
## Validate MAP documents

```js
import { assertMapDocument, assertContentReviewRequest, getMapSchema } from 'mailschema';
import {
assertMapDocument,
assertContentReviewRequest,
getContentReviewContract,
getMapSchema,
} from 'mailschema';

assertMapDocument(description);
assertContentReviewRequest(request);
const mapSchema = getMapSchema();
const contentReviewContract = getContentReviewContract();
```

The CLI performs the same checks against local JSON files:
Expand Down Expand Up @@ -56,6 +62,7 @@ Raw Draft 2020-12 schemas are exported as:

- `mailschema/map-0.1.schema.json`
- `mailschema/content-review-0.1.schema.json`
- `mailschema/content-review-0.1.contract.json`
- `mailschema/contribution.schema.json`

## Trust boundary
Expand Down
2 changes: 1 addition & 1 deletion UPSTREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Version `0.1.3` was prepared from [`mailschema/mailschema@eddc745`](https://gith

The included contribution schema has SHA-256 digest `a8a241b4837971a6251bcc135c704283536f4fb825fbbaedaf1598c6e688d564`. The canonical schemas live in the main MailSchema repository; this repository owns the JavaScript and TypeScript package surface and its release history.

The unreleased MAP contract projection is derived from [`mailschema/mailschema@ab91b37`](https://github.com/mailschema/mailschema/commit/ab91b37d29dbf95a2e208a34a144bf5f7c26d0a6). Its MAP schema digest is `d908a960f53fade9ab47876bf69b1b3d037adeb7096091e22ca71fbc3909429c`; its Content Review schema digest is `dba2a2f1e57f843f43080f5a40ced2d9c84e7c7036ec306c371a82d39f6d6c9f`. These files are projections of that source commit and do not independently define MAP.
The unreleased MAP contract projection is derived from [`mailschema/mailschema@e2f2cc6`](https://github.com/mailschema/mailschema/commit/e2f2cc6983173e5aba1da27f1f8bff37336efd77). Its MAP schema digest is `c39befeecf8643e8beda1f53a8d1411482b68ddf14974f3806cfa95776103f85`; its Content Review schema digest is `10e2263c820ba3a6ef0381c377078e2c1f324c3b142a6f8caf92b298cc66c692`; and its Content Review contract byte digest is `754ab7245ddb09ff4da000fccc60d746724379d4146ea227973e5d87f105f800`. These files are exact projections of that source commit and do not independently define MAP.
1 change: 1 addition & 0 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ for (const name of [
'contribution.schema.json',
'map-0.1.schema.json',
'content-review-0.1.schema.json',
'content-review-0.1.contract.json',
]) {
await copyFile(resolve(root, 'src', name), resolve(root, 'dist', name));
}
58 changes: 58 additions & 0 deletions dist/content-review-0.1.contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"kind": "MapTypeContract",
"id": "https://mailschema.org/types/content-review",
"version": "0.1",
"profile": "https://mailschema.org/profiles/map/0.1",
"target": "Service-owned content at the exact revision and digest named in the request.",
"requestSchema": {
"url": "https://mailschema.org/schemas/content-review-0.1.schema.json",
"canonicalDigest": "sha-256:cdad1149ab193d1bf71cb9463e3c4b7331ed56b0123e225adf68f70a2022b29d"
},
"operations": [
{
"id": "request-changes",
"effect": "Record review feedback on the named revision.",
"results": [
{
"state": "accepted",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"feedbackRecorded": { "const": true }
},
"required": ["feedbackRecorded"]
}
}
]
},
{
"id": "approve",
"effect": "Record approval of the named revision.",
"results": [
{
"state": "approval-required",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"approvalUrl": { "type": "string", "format": "uri", "pattern": "^https://" }
},
"required": ["approvalUrl"]
}
},
{
"state": "completed",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"decision": { "const": "approved" }
},
"required": ["decision"]
}
}
]
}
]
}
7 changes: 2 additions & 5 deletions dist/content-review-0.1.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://mailschema.org/schemas/content-review-0.1.schema.json",
"title": "Content Review 0.1 MAP request",
"title": "Content Review 0.1 MAP request binding",
"allOf": [
{ "$ref": "https://mailschema.org/schemas/map-0.1.schema.json#/$defs/request" },
{
Expand All @@ -11,10 +11,7 @@
"type": "object",
"properties": {
"id": { "const": "https://mailschema.org/types/content-review" },
"version": { "const": "0.1" },
"recordDigest": {
"const": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
}
"version": { "const": "0.1" }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { contributionErrors, assertContribution, assertTypeRecord, referenceErro
export type { CatalogView } from './validation.js';
export { typeStages } from './model.js';
export type { Party, TypeDefinition, TypeRecord, Contribution, Implementation } from './model.js';
export { mapErrors, assertMapDocument, contentReviewRequestErrors, assertContentReviewRequest, getMapSchema, getContentReviewSchema, } from './map.js';
export { mapErrors, assertMapDocument, contentReviewRequestErrors, assertContentReviewRequest, getMapSchema, getContentReviewSchema, getContentReviewContract, } from './map.js';
/** Return an independent copy of the contribution JSON Schema (Draft 2020-12). */
export declare function getContributionSchema(): Record<string, unknown>;
/** Return the schema for an expanded Registry record, including attribution and history. */
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import schema from './contribution.schema.json' with { type: 'json' };
export { contributionErrors, assertContribution, assertTypeRecord, referenceErrors, } from './validation.js';
export { typeStages } from './model.js';
export { mapErrors, assertMapDocument, contentReviewRequestErrors, assertContentReviewRequest, getMapSchema, getContentReviewSchema, } from './map.js';
export { mapErrors, assertMapDocument, contentReviewRequestErrors, assertContentReviewRequest, getMapSchema, getContentReviewSchema, getContentReviewContract, } from './map.js';
/** Return an independent copy of the contribution JSON Schema (Draft 2020-12). */
export function getContributionSchema() {
return structuredClone(schema);
Expand Down
142 changes: 109 additions & 33 deletions dist/map-0.1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"type": "string",
"pattern": "^sha-256:[a-f0-9]{64}$"
},
"recordDigest": {
"contractDigest": {
"type": "string",
"pattern": "^sha-256:[a-f0-9]{64}$"
},
Expand All @@ -46,9 +46,9 @@
"pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:-[a-zA-Z0-9.-]+)?$",
"maxLength": 80
},
"recordDigest": { "$ref": "#/$defs/recordDigest" }
"contractDigest": { "$ref": "#/$defs/contractDigest" }
},
"required": ["id", "version", "recordDigest"]
"required": ["id", "version", "contractDigest"]
},
"target": {
"type": "object",
Expand Down Expand Up @@ -172,7 +172,6 @@
"profile": { "$ref": "#/$defs/profile" },
"requestId": { "$ref": "#/$defs/uuidUrn" },
"interactionId": { "$ref": "#/$defs/uuidUrn" },
"requestedAt": { "type": "string", "format": "date-time" },
"type": { "$ref": "#/$defs/typeReference" },
"operation": {
"type": "string",
Expand All @@ -187,7 +186,6 @@
"profile",
"requestId",
"interactionId",
"requestedAt",
"type",
"operation",
"target",
Expand Down Expand Up @@ -273,61 +271,139 @@
},
"target": { "$ref": "#/$defs/target" }
},
"required": [
"type",
"title",
"status",
"detail",
"instance",
"profile",
"requestId",
"interactionId",
"code"
],
"required": ["type", "title", "status", "detail"],
"dependentRequired": {
"instance": ["profile", "requestId", "code"],
"profile": ["instance", "requestId", "code"],
"requestId": ["instance", "profile", "code"],
"interactionId": ["instance", "profile", "requestId", "code"],
"code": ["instance", "profile", "requestId"]
},
"allOf": [
{
"if": {
"properties": { "code": { "not": { "const": "result-not-found" } } },
"required": ["code"]
},
"then": { "required": ["interactionId"] }
},
{
"if": { "properties": { "code": { "const": "invalid-request" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/invalid-request" }, "status": { "const": 400 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/invalid-request" },
"status": { "const": 400 }
}
}
},
{
"if": { "properties": { "code": { "const": "authentication-required" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/authentication-required" }, "status": { "const": 401 } } }
"if": {
"properties": { "code": { "const": "authentication-required" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/authentication-required" },
"status": { "const": 401 }
}
}
},
{
"if": { "properties": { "code": { "const": "refused" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/refused" }, "status": { "const": 403 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/refused" },
"status": { "const": 403 }
}
}
},
{
"if": { "properties": { "code": { "const": "result-not-found" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/result-not-found" }, "status": { "const": 404 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/result-not-found" },
"status": { "const": 404 }
}
}
},
{
"if": { "properties": { "code": { "const": "stale-target" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/stale-target" }, "status": { "const": 409 } }, "required": ["target"] }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/stale-target" },
"status": { "const": 409 }
},
"required": ["target"]
}
},
{
"if": { "properties": { "code": { "const": "idempotency-conflict" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/idempotency-conflict" }, "status": { "const": 409 } } }
"if": {
"properties": { "code": { "const": "idempotency-conflict" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/idempotency-conflict" },
"status": { "const": 409 }
}
}
},
{
"if": { "properties": { "code": { "const": "request-in-progress" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/request-in-progress" }, "status": { "const": 409 } } }
"if": {
"properties": { "code": { "const": "request-in-progress" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/request-in-progress" },
"status": { "const": 409 }
}
}
},
{
"if": { "properties": { "code": { "const": "expired-interaction" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/expired-interaction" }, "status": { "const": 410 } } }
"if": {
"properties": { "code": { "const": "expired-interaction" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/expired-interaction" },
"status": { "const": 410 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-profile" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-profile" }, "status": { "const": 422 } } }
"if": {
"properties": { "code": { "const": "unsupported-profile" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-profile" },
"status": { "const": 422 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-type" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-type" }, "status": { "const": 422 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-type" },
"status": { "const": 422 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-operation" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-operation" }, "status": { "const": 422 } } }
"if": {
"properties": { "code": { "const": "unsupported-operation" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-operation" },
"status": { "const": 422 }
}
}
}
]
}
Expand Down
1 change: 1 addition & 0 deletions dist/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export declare function contentReviewRequestErrors(value: unknown): string[];
export declare function assertContentReviewRequest(value: unknown): void;
export declare function getMapSchema(): Record<string, unknown>;
export declare function getContentReviewSchema(): Record<string, unknown>;
export declare function getContentReviewContract(): Record<string, unknown>;
4 changes: 4 additions & 0 deletions dist/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ajv2020 from 'ajv/dist/2020.js';
import addFormats from 'ajv-formats';
import mapSchema from './map-0.1.schema.json' with { type: 'json' };
import contentReviewSchema from './content-review-0.1.schema.json' with { type: 'json' };
import contentReviewContract from './content-review-0.1.contract.json' with { type: 'json' };
const ajv = new Ajv2020({ allErrors: true, strict: true, strictRequired: false });
addFormats(ajv);
const mapDocument = ajv.compile(mapSchema);
Expand Down Expand Up @@ -33,3 +34,6 @@ export function getMapSchema() {
export function getContentReviewSchema() {
return structuredClone(contentReviewSchema);
}
export function getContentReviewContract() {
return structuredClone(contentReviewContract);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"./contribution.schema.json": "./dist/contribution.schema.json",
"./map-0.1.schema.json": "./dist/map-0.1.schema.json",
"./content-review-0.1.schema.json": "./dist/content-review-0.1.schema.json",
"./content-review-0.1.contract.json": "./dist/content-review-0.1.contract.json",
"./package.json": "./package.json"
},
"types": "./dist/index.d.ts",
Expand Down
Loading
Loading