mailschema 0.1.4 → 0.2.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.
package/dist/map.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- export declare function mapErrors(value: unknown): string[];
2
- export declare function assertMapDocument(value: unknown): void;
3
- export declare function contentReviewRequestErrors(value: unknown): string[];
4
- export declare function assertContentReviewRequest(value: unknown): void;
5
- export declare function contentReview01RequestErrors(value: unknown): string[];
6
- export declare function assertContentReview01Request(value: unknown): void;
1
+ /** The MAP profile whose core artifacts this package carries. */
2
+ export declare const MAP_PROFILE = "https://mailschema.org/profiles/map/0.2";
3
+ /** A fresh copy of the MAP 0.2 core schema, as the profile record binds it by SHA-256. */
7
4
  export declare function getMapSchema(): Record<string, unknown>;
8
- export declare function getContentReviewSchema(): Record<string, unknown>;
9
- export declare function getContentReviewContract(): Record<string, unknown>;
10
- export declare function getContentReview01Schema(): Record<string, unknown>;
11
- export declare function getContentReview01Contract(): Record<string, unknown>;
5
+ /** A fresh copy of the MAP 0.2 JSON-LD context. */
6
+ export declare function getMapContext(): Record<string, unknown>;
7
+ /** A fresh copy of the type contract format every MAP 0.2 contract follows. */
8
+ export declare function getContractFormatSchema(): Record<string, unknown>;
9
+ /** A fresh copy of the form fields block contracts pin. */
10
+ export declare function getFormsSchema(): Record<string, unknown>;
package/dist/map.js CHANGED
@@ -1,57 +1,20 @@
1
- import Ajv2020 from 'ajv/dist/2020.js';
2
- import addFormats from 'ajv-formats';
3
- import mapSchema from './map-0.1.schema.json' with { type: 'json' };
4
- import contentReview01Schema from './content-review-0.1.schema.json' with { type: 'json' };
5
- import contentReview01Contract from './content-review-0.1.contract.json' with { type: 'json' };
6
- import contentReview02Schema from './content-review-0.2.schema.json' with { type: 'json' };
7
- import contentReview02Contract from './content-review-0.2.contract.json' with { type: 'json' };
8
- const ajv = new Ajv2020({ allErrors: true, strict: true, strictRequired: false });
9
- addFormats(ajv);
10
- ajv.addSchema(mapSchema);
11
- const mapDocument = ajv.getSchema(mapSchema.$id);
12
- const contentReview01Request = ajv.compile(contentReview01Schema);
13
- const contentReview02Request = ajv.compile(contentReview02Schema);
14
- function errors(validate, value) {
15
- if (validate(value))
16
- return [];
17
- return (validate.errors || []).map((error) => `${error.instancePath || '/'} ${error.message}${error.keyword === 'required' ? `: ${error.params.missingProperty}` : ''}`);
18
- }
19
- export function mapErrors(value) {
20
- return errors(mapDocument, value);
21
- }
22
- export function assertMapDocument(value) {
23
- const found = mapErrors(value);
24
- if (found.length)
25
- throw new Error(`Invalid MAP 0.1 document:\n${found.join('\n')}`);
26
- }
27
- export function contentReviewRequestErrors(value) {
28
- return errors(contentReview02Request, value);
29
- }
30
- export function assertContentReviewRequest(value) {
31
- const found = contentReviewRequestErrors(value);
32
- if (found.length)
33
- throw new Error(`Invalid Content Review 0.2 request:\n${found.join('\n')}`);
34
- }
35
- export function contentReview01RequestErrors(value) {
36
- return errors(contentReview01Request, value);
37
- }
38
- export function assertContentReview01Request(value) {
39
- const found = contentReview01RequestErrors(value);
40
- if (found.length)
41
- throw new Error(`Invalid Content Review 0.1 request:\n${found.join('\n')}`);
42
- }
1
+ import { readFileSync } from 'node:fs';
2
+ /** The MAP profile whose core artifacts this package carries. */
3
+ export const MAP_PROFILE = 'https://mailschema.org/profiles/map/0.2';
4
+ const artifact = (name) => JSON.parse(readFileSync(new URL(`./${name}`, import.meta.url), 'utf8'));
5
+ /** A fresh copy of the MAP 0.2 core schema, as the profile record binds it by SHA-256. */
43
6
  export function getMapSchema() {
44
- return structuredClone(mapSchema);
45
- }
46
- export function getContentReviewSchema() {
47
- return structuredClone(contentReview02Schema);
7
+ return artifact('map-0.2.schema.json');
48
8
  }
49
- export function getContentReviewContract() {
50
- return structuredClone(contentReview02Contract);
9
+ /** A fresh copy of the MAP 0.2 JSON-LD context. */
10
+ export function getMapContext() {
11
+ return artifact('map-0.2.jsonld');
51
12
  }
52
- export function getContentReview01Schema() {
53
- return structuredClone(contentReview01Schema);
13
+ /** A fresh copy of the type contract format every MAP 0.2 contract follows. */
14
+ export function getContractFormatSchema() {
15
+ return artifact('type-contract-0.2.schema.json');
54
16
  }
55
- export function getContentReview01Contract() {
56
- return structuredClone(contentReview01Contract);
17
+ /** A fresh copy of the form fields block contracts pin. */
18
+ export function getFormsSchema() {
19
+ return artifact('forms-0.1.schema.json');
57
20
  }
@@ -0,0 +1,179 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://mailschema.org/schemas/type-contract-0.2.schema.json",
4
+ "title": "MailSchema type contract for MAP 0.2",
5
+ "description": "A versioned interaction contract: the details, inputs, results, authority, repeatability and consequences of each operation, with every schema it depends on pinned by digest.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "kind": {
10
+ "const": "MapTypeContract"
11
+ },
12
+ "id": {
13
+ "type": "string",
14
+ "pattern": "^https://mailschema\\.org/types/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
15
+ "maxLength": 2048
16
+ },
17
+ "version": {
18
+ "type": "string",
19
+ "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:-[a-zA-Z0-9.-]+)?$",
20
+ "maxLength": 80
21
+ },
22
+ "profile": {
23
+ "const": "https://mailschema.org/profiles/map/0.2"
24
+ },
25
+ "target": {
26
+ "$ref": "#/$defs/prose"
27
+ },
28
+ "dependencies": {
29
+ "type": "array",
30
+ "minItems": 1,
31
+ "maxItems": 20,
32
+ "items": {
33
+ "$ref": "#/$defs/schemaReference"
34
+ }
35
+ },
36
+ "detailsSchema": {
37
+ "type": "object"
38
+ },
39
+ "requestSchema": {
40
+ "$ref": "#/$defs/schemaReference"
41
+ },
42
+ "operations": {
43
+ "type": "array",
44
+ "minItems": 1,
45
+ "maxItems": 100,
46
+ "items": {
47
+ "type": "object",
48
+ "additionalProperties": false,
49
+ "properties": {
50
+ "id": {
51
+ "$ref": "#/$defs/token"
52
+ },
53
+ "effect": {
54
+ "$ref": "#/$defs/prose"
55
+ },
56
+ "authority": {
57
+ "type": "array",
58
+ "items": {
59
+ "enum": ["credential", "possession"]
60
+ },
61
+ "minItems": 1,
62
+ "maxItems": 2,
63
+ "uniqueItems": true
64
+ },
65
+ "consequences": {
66
+ "type": "array",
67
+ "items": {
68
+ "enum": [
69
+ "refusal",
70
+ "protection",
71
+ "record",
72
+ "disclosure",
73
+ "commitment",
74
+ "authorization",
75
+ "assertion"
76
+ ]
77
+ },
78
+ "minItems": 1,
79
+ "maxItems": 7,
80
+ "uniqueItems": true
81
+ },
82
+ "repeatable": {
83
+ "type": "boolean"
84
+ },
85
+ "fieldBindings": {
86
+ "type": "array",
87
+ "minItems": 1,
88
+ "maxItems": 10,
89
+ "items": {
90
+ "type": "object",
91
+ "additionalProperties": false,
92
+ "properties": {
93
+ "input": {
94
+ "$ref": "#/$defs/pointer"
95
+ },
96
+ "fields": {
97
+ "$ref": "#/$defs/pointer"
98
+ }
99
+ },
100
+ "required": ["input", "fields"]
101
+ }
102
+ },
103
+ "results": {
104
+ "type": "array",
105
+ "minItems": 1,
106
+ "maxItems": 5,
107
+ "items": {
108
+ "type": "object",
109
+ "additionalProperties": false,
110
+ "properties": {
111
+ "state": {
112
+ "enum": ["accepted", "completed", "failed", "pending", "approval-required"]
113
+ },
114
+ "reasons": {
115
+ "type": "array",
116
+ "items": {
117
+ "$ref": "#/$defs/token"
118
+ },
119
+ "minItems": 1,
120
+ "maxItems": 20,
121
+ "uniqueItems": true
122
+ },
123
+ "outputSchema": {
124
+ "type": "object"
125
+ }
126
+ },
127
+ "required": ["state", "outputSchema"]
128
+ }
129
+ }
130
+ },
131
+ "required": ["id", "effect", "authority", "consequences", "results"]
132
+ }
133
+ }
134
+ },
135
+ "required": [
136
+ "kind",
137
+ "id",
138
+ "version",
139
+ "profile",
140
+ "target",
141
+ "dependencies",
142
+ "requestSchema",
143
+ "operations"
144
+ ],
145
+ "$defs": {
146
+ "prose": {
147
+ "type": "string",
148
+ "minLength": 1,
149
+ "maxLength": 12000,
150
+ "pattern": "[^\\t\\n\\u000b\\f\\r \\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]"
151
+ },
152
+ "token": {
153
+ "type": "string",
154
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
155
+ "maxLength": 100
156
+ },
157
+ "pointer": {
158
+ "type": "string",
159
+ "pattern": "^(?:/(?:[^~/]|~[01])*)+$",
160
+ "maxLength": 1000
161
+ },
162
+ "schemaReference": {
163
+ "type": "object",
164
+ "additionalProperties": false,
165
+ "properties": {
166
+ "url": {
167
+ "type": "string",
168
+ "pattern": "^https://mailschema\\.org/schemas/[a-z0-9.-]+\\.json$",
169
+ "maxLength": 2048
170
+ },
171
+ "canonicalDigest": {
172
+ "type": "string",
173
+ "pattern": "^sha-256:[a-f0-9]{64}$"
174
+ }
175
+ },
176
+ "required": ["url", "canonicalDigest"]
177
+ }
178
+ }
179
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mailschema",
3
- "version": "0.1.4",
4
- "description": "Schemas and validation tools for Mail Action Protocol and the MailSchema Registry",
3
+ "version": "0.2.1",
4
+ "description": "Mail Action Protocol 0.2 core artifacts and MailSchema Registry validation",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "MailSchema contributors",
8
- "homepage": "https://mailschema.org/tools/",
8
+ "homepage": "https://mailschema.org/tools",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/mailschema/javascript.git"
@@ -22,11 +22,10 @@
22
22
  "import": "./dist/index.js"
23
23
  },
24
24
  "./contribution.schema.json": "./dist/contribution.schema.json",
25
- "./map-0.1.schema.json": "./dist/map-0.1.schema.json",
26
- "./content-review-0.1.schema.json": "./dist/content-review-0.1.schema.json",
27
- "./content-review-0.1.contract.json": "./dist/content-review-0.1.contract.json",
28
- "./content-review-0.2.schema.json": "./dist/content-review-0.2.schema.json",
29
- "./content-review-0.2.contract.json": "./dist/content-review-0.2.contract.json",
25
+ "./map-0.2.schema.json": "./dist/map-0.2.schema.json",
26
+ "./map-0.2.jsonld": "./dist/map-0.2.jsonld",
27
+ "./type-contract-0.2.schema.json": "./dist/type-contract-0.2.schema.json",
28
+ "./forms-0.1.schema.json": "./dist/forms-0.1.schema.json",
30
29
  "./package.json": "./package.json"
31
30
  },
32
31
  "types": "./dist/index.d.ts",
@@ -48,6 +47,7 @@
48
47
  "ajv-formats": "3.0.1"
49
48
  },
50
49
  "devDependencies": {
50
+ "@types/node": "24.13.6",
51
51
  "typescript": "5.9.3"
52
52
  },
53
53
  "keywords": [
@@ -1,58 +0,0 @@
1
- {
2
- "kind": "MapTypeContract",
3
- "id": "https://mailschema.org/types/content-review",
4
- "version": "0.1",
5
- "profile": "https://mailschema.org/profiles/map/0.1",
6
- "target": "Service-owned content at the exact revision and digest named in the request.",
7
- "requestSchema": {
8
- "url": "https://mailschema.org/schemas/content-review-0.1.schema.json",
9
- "canonicalDigest": "sha-256:cdad1149ab193d1bf71cb9463e3c4b7331ed56b0123e225adf68f70a2022b29d"
10
- },
11
- "operations": [
12
- {
13
- "id": "request-changes",
14
- "effect": "Record review feedback on the named revision.",
15
- "results": [
16
- {
17
- "state": "accepted",
18
- "outputSchema": {
19
- "type": "object",
20
- "additionalProperties": false,
21
- "properties": {
22
- "feedbackRecorded": { "const": true }
23
- },
24
- "required": ["feedbackRecorded"]
25
- }
26
- }
27
- ]
28
- },
29
- {
30
- "id": "approve",
31
- "effect": "Record approval of the named revision.",
32
- "results": [
33
- {
34
- "state": "approval-required",
35
- "outputSchema": {
36
- "type": "object",
37
- "additionalProperties": false,
38
- "properties": {
39
- "approvalUrl": { "type": "string", "format": "uri", "pattern": "^https://" }
40
- },
41
- "required": ["approvalUrl"]
42
- }
43
- },
44
- {
45
- "state": "completed",
46
- "outputSchema": {
47
- "type": "object",
48
- "additionalProperties": false,
49
- "properties": {
50
- "decision": { "const": "approved" }
51
- },
52
- "required": ["decision"]
53
- }
54
- }
55
- ]
56
- }
57
- ]
58
- }
@@ -1,54 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://mailschema.org/schemas/content-review-0.1.schema.json",
4
- "title": "Content Review 0.1 MAP request binding",
5
- "allOf": [
6
- { "$ref": "https://mailschema.org/schemas/map-0.1.schema.json#/$defs/request" },
7
- {
8
- "type": "object",
9
- "properties": {
10
- "type": {
11
- "type": "object",
12
- "properties": {
13
- "id": { "const": "https://mailschema.org/types/content-review" },
14
- "version": { "const": "0.1" }
15
- }
16
- }
17
- }
18
- },
19
- {
20
- "oneOf": [
21
- {
22
- "type": "object",
23
- "properties": {
24
- "operation": { "const": "request-changes" },
25
- "input": {
26
- "type": "object",
27
- "additionalProperties": false,
28
- "properties": {
29
- "feedback": {
30
- "type": "string",
31
- "minLength": 1,
32
- "maxLength": 12000,
33
- "pattern": "\\S"
34
- }
35
- },
36
- "required": ["feedback"]
37
- }
38
- }
39
- },
40
- {
41
- "type": "object",
42
- "properties": {
43
- "operation": { "const": "approve" },
44
- "input": {
45
- "type": "object",
46
- "additionalProperties": false,
47
- "maxProperties": 0
48
- }
49
- }
50
- }
51
- ]
52
- }
53
- ]
54
- }
@@ -1,91 +0,0 @@
1
- {
2
- "kind": "MapTypeContract",
3
- "id": "https://mailschema.org/types/content-review",
4
- "version": "0.2",
5
- "profile": "https://mailschema.org/profiles/map/0.1",
6
- "target": "Service-owned content at the exact revision and digest named in the request.",
7
- "requestSchema": {
8
- "url": "https://mailschema.org/schemas/content-review-0.2.schema.json",
9
- "canonicalDigest": "sha-256:43a01e620e0730e47755694bdf5d086f8d0a1d3d8328fb0c7d2a4b70c6e62e25"
10
- },
11
- "operations": [
12
- {
13
- "id": "request-changes",
14
- "effect": "Record review feedback on the named revision.",
15
- "results": [
16
- {
17
- "state": "accepted",
18
- "outputSchema": {
19
- "type": "object",
20
- "additionalProperties": false,
21
- "properties": {
22
- "feedbackRecorded": {
23
- "const": true
24
- }
25
- },
26
- "required": [
27
- "feedbackRecorded"
28
- ]
29
- }
30
- }
31
- ]
32
- },
33
- {
34
- "id": "approve",
35
- "effect": "Record approval of the named revision, or record why a proposed approval ended without approval.",
36
- "results": [
37
- {
38
- "state": "approval-required",
39
- "outputSchema": {
40
- "type": "object",
41
- "additionalProperties": false,
42
- "properties": {
43
- "approvalUrl": {
44
- "type": "string",
45
- "format": "uri",
46
- "pattern": "^https://"
47
- }
48
- },
49
- "required": [
50
- "approvalUrl"
51
- ]
52
- }
53
- },
54
- {
55
- "state": "completed",
56
- "outputSchema": {
57
- "type": "object",
58
- "additionalProperties": false,
59
- "properties": {
60
- "decision": {
61
- "const": "approved"
62
- }
63
- },
64
- "required": [
65
- "decision"
66
- ]
67
- }
68
- },
69
- {
70
- "state": "failed",
71
- "outputSchema": {
72
- "type": "object",
73
- "additionalProperties": false,
74
- "properties": {
75
- "reason": {
76
- "enum": [
77
- "declined",
78
- "stale-target",
79
- "expired"
80
- ]
81
- }
82
- },
83
- "required": [
84
- "reason"
85
- ]
86
- }
87
- }
88
- ]
89
- }
90
- ]
91
- }
@@ -1,54 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://mailschema.org/schemas/content-review-0.2.schema.json",
4
- "title": "Content Review 0.2 MAP request binding",
5
- "allOf": [
6
- { "$ref": "https://mailschema.org/schemas/map-0.1.schema.json#/$defs/request" },
7
- {
8
- "type": "object",
9
- "properties": {
10
- "type": {
11
- "type": "object",
12
- "properties": {
13
- "id": { "const": "https://mailschema.org/types/content-review" },
14
- "version": { "const": "0.2" }
15
- }
16
- }
17
- }
18
- },
19
- {
20
- "oneOf": [
21
- {
22
- "type": "object",
23
- "properties": {
24
- "operation": { "const": "request-changes" },
25
- "input": {
26
- "type": "object",
27
- "additionalProperties": false,
28
- "properties": {
29
- "feedback": {
30
- "type": "string",
31
- "minLength": 1,
32
- "maxLength": 12000,
33
- "pattern": "\\S"
34
- }
35
- },
36
- "required": ["feedback"]
37
- }
38
- }
39
- },
40
- {
41
- "type": "object",
42
- "properties": {
43
- "operation": { "const": "approve" },
44
- "input": {
45
- "type": "object",
46
- "additionalProperties": false,
47
- "maxProperties": 0
48
- }
49
- }
50
- }
51
- ]
52
- }
53
- ]
54
- }