mailschema 0.3.0 → 0.3.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/README.md +6 -4
- package/bin/mailschema.js +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[Mail Action Protocol](https://mailschema.org) 0.3 for JavaScript. It parses and checks MAP descriptions, type contracts and Registry implementation records, and computes the RFC 8785 digests that identify contracts. The same code runs the MailSchema specification's own checks. It has no Node.js-only dependencies, so it also runs in browsers and workers.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npm install mailschema@0.3.
|
|
6
|
+
npm install mailschema@0.3.1
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## Check a description against its contract
|
|
@@ -34,11 +34,13 @@ The profile record, context and schemas are exported byte for byte: `mailschema/
|
|
|
34
34
|
## Command line
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
|
-
npx mailschema@0.3.
|
|
38
|
-
npx mailschema@0.3.
|
|
39
|
-
npx mailschema@0.3.
|
|
37
|
+
npx mailschema@0.3.1 contract campaign-send-approval-0.1.json
|
|
38
|
+
npx mailschema@0.3.1 description description.json --contract campaign-send-approval-0.1.json
|
|
39
|
+
npx mailschema@0.3.1 implementation record.json
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
Each command first prints a line naming what it checked. `contract` prints `Valid type contract <id> <version>` and, on the second line, the contract's digest. `description` prints `Valid MAP 0.3 description <@id>` and, on the second line, the description's digest; with `--contract`, it first checks that the description uses that contract as it allows. `implementation` prints `Valid implementation record for <service>`. A digest is `sha-256:` and the SHA-256 of the document's RFC 8785 canonical JSON, the value `digest()` returns; the description's digest is not the contract digest it names. An invalid file prints every reason on standard error and exits with status 1. Nothing is uploaded or changed.
|
|
43
|
+
|
|
42
44
|
Checking does not authenticate a message, establish a service's authority or perform an action. Those belong to the implementation, under the [specification](https://mailschema.org/specification/core).
|
|
43
45
|
|
|
44
46
|
Source: [mailschema/javascript](https://github.com/mailschema/javascript). License: MIT.
|
package/bin/mailschema.js
CHANGED
|
@@ -4,6 +4,7 @@ import { parseArgs } from 'node:util';
|
|
|
4
4
|
import {
|
|
5
5
|
Contract,
|
|
6
6
|
CONTRACT_MAX_BYTES,
|
|
7
|
+
digest,
|
|
7
8
|
InvalidDocument,
|
|
8
9
|
parseDescription,
|
|
9
10
|
parseImplementation,
|
|
@@ -16,9 +17,10 @@ const help = `Mail Action Protocol 0.3 checks
|
|
|
16
17
|
mailschema implementation <record.json>
|
|
17
18
|
|
|
18
19
|
contract checks a type contract and prints its digest. description checks a
|
|
19
|
-
description and, with --contract, that it uses that contract as it allows
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
description and, with --contract, that it uses that contract as it allows,
|
|
21
|
+
then prints the description's digest. implementation checks a Registry
|
|
22
|
+
implementation record. A digest is the SHA-256 of the document's RFC 8785
|
|
23
|
+
canonical JSON. Nothing is uploaded or changed.`;
|
|
22
24
|
|
|
23
25
|
async function read(path) {
|
|
24
26
|
const info = await stat(path);
|
|
@@ -48,7 +50,7 @@ try {
|
|
|
48
50
|
const description = parseDescription(await read(path));
|
|
49
51
|
if (values.contract)
|
|
50
52
|
report(Contract.parse(await read(values.contract)).descriptionErrors(description));
|
|
51
|
-
console.log(`Valid MAP 0.3 description ${description['@id']}`);
|
|
53
|
+
console.log(`Valid MAP 0.3 description ${description['@id']}\n${digest(description)}`);
|
|
52
54
|
} else if (command === 'implementation') {
|
|
53
55
|
const record = parseImplementation(await read(path));
|
|
54
56
|
console.log(`Valid implementation record for ${record.service}`);
|