mailschema 0.1.3 → 0.1.5

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,6 +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;
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. */
5
4
  export declare function getMapSchema(): Record<string, unknown>;
6
- export declare function getContentReviewSchema(): 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,35 +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 contentReviewSchema from './content-review-0.1.schema.json' with { type: 'json' };
5
- const ajv = new Ajv2020({ allErrors: true, strict: true, strictRequired: false });
6
- addFormats(ajv);
7
- const mapDocument = ajv.compile(mapSchema);
8
- const contentReviewRequest = ajv.compile(contentReviewSchema);
9
- function errors(validate, value) {
10
- if (validate(value))
11
- return [];
12
- return (validate.errors || []).map((error) => `${error.instancePath || '/'} ${error.message}${error.keyword === 'required' ? `: ${error.params.missingProperty}` : ''}`);
13
- }
14
- export function mapErrors(value) {
15
- return errors(mapDocument, value);
16
- }
17
- export function assertMapDocument(value) {
18
- const found = mapErrors(value);
19
- if (found.length)
20
- throw new Error(`Invalid MAP 0.1 document:\n${found.join('\n')}`);
21
- }
22
- export function contentReviewRequestErrors(value) {
23
- return errors(contentReviewRequest, value);
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. */
6
+ export function getMapSchema() {
7
+ return artifact('map-0.2.schema.json');
24
8
  }
25
- export function assertContentReviewRequest(value) {
26
- const found = contentReviewRequestErrors(value);
27
- if (found.length)
28
- throw new Error(`Invalid Content Review 0.1 request:\n${found.join('\n')}`);
9
+ /** A fresh copy of the MAP 0.2 JSON-LD context. */
10
+ export function getMapContext() {
11
+ return artifact('map-0.2.jsonld');
29
12
  }
30
- export function getMapSchema() {
31
- return structuredClone(mapSchema);
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');
32
16
  }
33
- export function getContentReviewSchema() {
34
- return structuredClone(contentReviewSchema);
17
+ /** A fresh copy of the form fields block contracts pin. */
18
+ export function getFormsSchema() {
19
+ return artifact('forms-0.1.schema.json');
35
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.3",
4
- "description": "Schemas and validation tools for Mail Action Protocol and the MailSchema Registry",
3
+ "version": "0.1.5",
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,8 +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",
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",
27
29
  "./package.json": "./package.json"
28
30
  },
29
31
  "types": "./dist/index.d.ts",
@@ -45,6 +47,7 @@
45
47
  "ajv-formats": "3.0.1"
46
48
  },
47
49
  "devDependencies": {
50
+ "@types/node": "24.13.6",
48
51
  "typescript": "5.9.3"
49
52
  },
50
53
  "keywords": [
@@ -1,52 +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",
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
- "recordDigest": {
16
- "const": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
17
- }
18
- }
19
- }
20
- }
21
- },
22
- {
23
- "oneOf": [
24
- {
25
- "type": "object",
26
- "properties": {
27
- "operation": { "const": "request-changes" },
28
- "input": {
29
- "type": "object",
30
- "additionalProperties": false,
31
- "properties": {
32
- "feedback": { "type": "string", "minLength": 1, "maxLength": 12000 }
33
- },
34
- "required": ["feedback"]
35
- }
36
- }
37
- },
38
- {
39
- "type": "object",
40
- "properties": {
41
- "operation": { "const": "approve" },
42
- "input": {
43
- "type": "object",
44
- "additionalProperties": false,
45
- "maxProperties": 0
46
- }
47
- }
48
- }
49
- ]
50
- }
51
- ]
52
- }
@@ -1,275 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://mailschema.org/schemas/map-0.1.schema.json",
4
- "title": "Mail Action Protocol 0.1",
5
- "description": "Description, request, result and problem documents for the MAP 0.1 authenticated HTTPS profile.",
6
- "oneOf": [
7
- { "$ref": "#/$defs/description" },
8
- { "$ref": "#/$defs/request" },
9
- { "$ref": "#/$defs/result" },
10
- { "$ref": "#/$defs/problem" }
11
- ],
12
- "$defs": {
13
- "profile": {
14
- "const": "https://mailschema.org/profiles/map/0.1"
15
- },
16
- "identifier": {
17
- "type": "string",
18
- "format": "uri",
19
- "maxLength": 2048
20
- },
21
- "uuidUrn": {
22
- "type": "string",
23
- "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
24
- },
25
- "digest": {
26
- "type": "string",
27
- "pattern": "^sha-256:[a-f0-9]{64}$"
28
- },
29
- "recordDigest": {
30
- "type": "string",
31
- "pattern": "^sha-256:[a-f0-9]{64}$"
32
- },
33
- "typeReference": {
34
- "type": "object",
35
- "additionalProperties": false,
36
- "properties": {
37
- "id": { "$ref": "#/$defs/identifier" },
38
- "version": {
39
- "type": "string",
40
- "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:-[a-zA-Z0-9.-]+)?$",
41
- "maxLength": 80
42
- },
43
- "recordDigest": { "$ref": "#/$defs/recordDigest" }
44
- },
45
- "required": ["id", "version", "recordDigest"]
46
- },
47
- "target": {
48
- "type": "object",
49
- "additionalProperties": false,
50
- "properties": {
51
- "id": { "$ref": "#/$defs/identifier" },
52
- "revision": { "type": "string", "minLength": 1, "maxLength": 240 },
53
- "title": { "type": "string", "minLength": 1, "maxLength": 500 },
54
- "digest": { "$ref": "#/$defs/digest" }
55
- },
56
- "required": ["id", "revision", "digest"]
57
- },
58
- "operation": {
59
- "type": "object",
60
- "additionalProperties": false,
61
- "properties": {
62
- "id": {
63
- "type": "string",
64
- "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
65
- "maxLength": 100
66
- },
67
- "name": { "type": "string", "minLength": 1, "maxLength": 240 },
68
- "description": { "type": "string", "minLength": 1, "maxLength": 2000 },
69
- "inputSchema": { "$ref": "#/$defs/identifier" }
70
- },
71
- "required": ["id", "name", "description", "inputSchema"]
72
- },
73
- "description": {
74
- "type": "object",
75
- "additionalProperties": false,
76
- "properties": {
77
- "@context": {
78
- "const": "https://mailschema.org/contexts/map-0.1.jsonld"
79
- },
80
- "@type": { "const": "MailAction" },
81
- "@id": { "$ref": "#/$defs/uuidUrn" },
82
- "profile": { "$ref": "#/$defs/profile" },
83
- "type": { "$ref": "#/$defs/typeReference" },
84
- "describedAt": { "type": "string", "format": "date-time" },
85
- "expiresAt": { "type": "string", "format": "date-time" },
86
- "service": {
87
- "type": "object",
88
- "additionalProperties": false,
89
- "properties": {
90
- "id": { "$ref": "#/$defs/identifier" },
91
- "name": { "type": "string", "minLength": 1, "maxLength": 240 },
92
- "execution": {
93
- "type": "object",
94
- "additionalProperties": false,
95
- "properties": {
96
- "url": { "$ref": "#/$defs/identifier" },
97
- "method": { "const": "POST" },
98
- "requestMediaType": { "const": "application/json" },
99
- "resultMediaType": { "const": "application/json" },
100
- "resultUrlTemplate": {
101
- "type": "string",
102
- "format": "uri-template",
103
- "pattern": "^https://.*\\{requestId\\}.*$",
104
- "maxLength": 2048
105
- },
106
- "resultRetentionSeconds": {
107
- "type": "integer",
108
- "minimum": 300,
109
- "maximum": 31536000
110
- }
111
- },
112
- "required": [
113
- "url",
114
- "method",
115
- "requestMediaType",
116
- "resultMediaType",
117
- "resultUrlTemplate",
118
- "resultRetentionSeconds"
119
- ]
120
- },
121
- "humanUrl": { "$ref": "#/$defs/identifier" },
122
- "authorization": {
123
- "type": "object",
124
- "additionalProperties": false,
125
- "properties": {
126
- "kind": { "const": "service-configured" },
127
- "schemes": {
128
- "type": "array",
129
- "items": { "enum": ["oauth2", "bearer", "session"] },
130
- "minItems": 1,
131
- "uniqueItems": true
132
- },
133
- "audience": { "type": "string", "minLength": 1, "maxLength": 500 }
134
- },
135
- "required": ["kind", "schemes"]
136
- }
137
- },
138
- "required": ["id", "name", "execution", "humanUrl", "authorization"]
139
- },
140
- "target": { "$ref": "#/$defs/target" },
141
- "operations": {
142
- "type": "array",
143
- "items": { "$ref": "#/$defs/operation" },
144
- "minItems": 1,
145
- "maxItems": 100
146
- }
147
- },
148
- "required": [
149
- "@context",
150
- "@type",
151
- "@id",
152
- "profile",
153
- "type",
154
- "describedAt",
155
- "expiresAt",
156
- "service",
157
- "target",
158
- "operations"
159
- ]
160
- },
161
- "request": {
162
- "type": "object",
163
- "additionalProperties": false,
164
- "properties": {
165
- "kind": { "const": "MapRequest" },
166
- "profile": { "$ref": "#/$defs/profile" },
167
- "requestId": { "$ref": "#/$defs/uuidUrn" },
168
- "interactionId": { "$ref": "#/$defs/uuidUrn" },
169
- "requestedAt": { "type": "string", "format": "date-time" },
170
- "type": { "$ref": "#/$defs/typeReference" },
171
- "operation": {
172
- "type": "string",
173
- "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
174
- "maxLength": 100
175
- },
176
- "target": { "$ref": "#/$defs/target" },
177
- "input": { "type": "object", "maxProperties": 100 }
178
- },
179
- "required": [
180
- "kind",
181
- "profile",
182
- "requestId",
183
- "interactionId",
184
- "requestedAt",
185
- "type",
186
- "operation",
187
- "target",
188
- "input"
189
- ]
190
- },
191
- "result": {
192
- "type": "object",
193
- "additionalProperties": false,
194
- "properties": {
195
- "kind": { "const": "MapResult" },
196
- "profile": { "$ref": "#/$defs/profile" },
197
- "requestId": { "$ref": "#/$defs/uuidUrn" },
198
- "interactionId": { "$ref": "#/$defs/uuidUrn" },
199
- "operation": {
200
- "type": "string",
201
- "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
202
- "maxLength": 100
203
- },
204
- "state": { "enum": ["accepted", "completed", "pending", "approval-required"] },
205
- "target": { "$ref": "#/$defs/target" },
206
- "recordedAt": { "type": "string", "format": "date-time" },
207
- "resultUrl": { "$ref": "#/$defs/identifier" },
208
- "output": { "type": "object", "maxProperties": 100 }
209
- },
210
- "required": [
211
- "kind",
212
- "profile",
213
- "requestId",
214
- "interactionId",
215
- "operation",
216
- "state",
217
- "target",
218
- "recordedAt",
219
- "resultUrl",
220
- "output"
221
- ]
222
- },
223
- "problem": {
224
- "type": "object",
225
- "additionalProperties": false,
226
- "properties": {
227
- "type": {
228
- "enum": [
229
- "https://mailschema.org/problems/refused",
230
- "https://mailschema.org/problems/stale-target",
231
- "https://mailschema.org/problems/expired-interaction",
232
- "https://mailschema.org/problems/invalid-request",
233
- "https://mailschema.org/problems/unsupported-profile",
234
- "https://mailschema.org/problems/unsupported-type",
235
- "https://mailschema.org/problems/unsupported-operation",
236
- "https://mailschema.org/problems/idempotency-conflict",
237
- "https://mailschema.org/problems/request-in-progress"
238
- ]
239
- },
240
- "title": { "type": "string", "minLength": 1, "maxLength": 240 },
241
- "status": { "type": "integer", "minimum": 400, "maximum": 599 },
242
- "detail": { "type": "string", "minLength": 1, "maxLength": 4000 },
243
- "instance": { "$ref": "#/$defs/identifier" },
244
- "profile": { "$ref": "#/$defs/profile" },
245
- "requestId": { "$ref": "#/$defs/uuidUrn" },
246
- "interactionId": { "$ref": "#/$defs/uuidUrn" },
247
- "code": {
248
- "enum": [
249
- "refused",
250
- "stale-target",
251
- "expired-interaction",
252
- "invalid-request",
253
- "unsupported-profile",
254
- "unsupported-type",
255
- "unsupported-operation",
256
- "idempotency-conflict",
257
- "request-in-progress"
258
- ]
259
- },
260
- "target": { "$ref": "#/$defs/target" }
261
- },
262
- "required": [
263
- "type",
264
- "title",
265
- "status",
266
- "detail",
267
- "instance",
268
- "profile",
269
- "requestId",
270
- "interactionId",
271
- "code"
272
- ]
273
- }
274
- }
275
- }