@sockethub/schemas 3.0.0-alpha.10 → 3.0.0-alpha.12
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/context.js +101 -0
- package/dist/context.js.map +10 -0
- package/dist/contexts/platform/dummy/v1.jsonld +8 -0
- package/dist/contexts/platform/error/v1.jsonld +8 -0
- package/dist/contexts/platform/feeds/v1.jsonld +8 -0
- package/dist/contexts/platform/irc/v1.jsonld +8 -0
- package/dist/contexts/platform/metadata/v1.jsonld +8 -0
- package/dist/contexts/platform/sockethub%3Ainternal/v1.jsonld +8 -0
- package/dist/contexts/platform/xmpp/v1.jsonld +8 -0
- package/dist/contexts/v1.jsonld +7 -0
- package/dist/index.js +533 -796
- package/dist/index.js.map +10 -15
- package/dist/maps/context-map.json +35 -0
- package/dist/schemas/platform/dummy/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/dummy/v1/messages.schema.json +22 -0
- package/dist/schemas/platform/error/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/error/v1/messages.schema.json +1 -0
- package/dist/schemas/platform/feeds/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/feeds/v1/messages.schema.json +36 -0
- package/dist/schemas/platform/irc/v1/credentials.schema.json +48 -0
- package/dist/schemas/platform/irc/v1/messages.schema.json +19 -0
- package/dist/schemas/platform/metadata/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/metadata/v1/messages.schema.json +29 -0
- package/dist/schemas/platform/sockethub%3Ainternal/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/sockethub%3Ainternal/v1/messages.schema.json +1 -0
- package/dist/schemas/platform/xmpp/v1/credentials.schema.json +43 -0
- package/dist/schemas/platform/xmpp/v1/messages.schema.json +21 -0
- package/package.json +15 -8
- package/src/context.ts +125 -0
- package/src/helpers/error-parser.ts +65 -18
- package/src/helpers/objects.ts +59 -3
- package/src/index.test.data.credentials.ts +37 -5
- package/src/index.test.data.platform.ts +3 -0
- package/src/index.test.data.streams.ts +117 -25
- package/src/index.test.ts +31 -3
- package/src/index.ts +30 -1
- package/src/schemas/activity-stream.ts +30 -9
- package/src/schemas/json/activity-object.json +50 -1
- package/src/schemas/json/activity-stream.json +77 -44
- package/src/schemas/json/platform.json +22 -2
- package/src/schemas/json/sockethub-config.json +120 -28
- package/src/schemas/platform.ts +25 -1
- package/src/schemas/sockethub-config.ts +94 -14
- package/src/types/ajv-formats-draft2019.d.ts +5 -0
- package/src/types.ts +29 -12
- package/src/validator.ts +138 -25
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "3.0.0-alpha.12",
|
|
3
|
+
"generatedAt": "2026-03-29T20:04:59.384Z",
|
|
4
|
+
"contextToPlatformId": {
|
|
5
|
+
"https://sockethub.org/ns/context/platform/dummy/v1.jsonld": "dummy",
|
|
6
|
+
"https://sockethub.org/ns/context/platform/error/v1.jsonld": "error",
|
|
7
|
+
"https://sockethub.org/ns/context/platform/feeds/v1.jsonld": "feeds",
|
|
8
|
+
"https://sockethub.org/ns/context/platform/irc/v1.jsonld": "irc",
|
|
9
|
+
"https://sockethub.org/ns/context/platform/metadata/v1.jsonld": "metadata",
|
|
10
|
+
"https://sockethub.org/ns/context/platform/sockethub:internal/v1.jsonld": "sockethub:internal",
|
|
11
|
+
"https://sockethub.org/ns/context/platform/xmpp/v1.jsonld": "xmpp"
|
|
12
|
+
},
|
|
13
|
+
"contextToSchemaId": {
|
|
14
|
+
"https://sockethub.org/ns/context/platform/dummy/v1.jsonld": "https://sockethub.org/schemas/as2/platform/dummy/v1/messages.schema.json",
|
|
15
|
+
"https://sockethub.org/ns/context/platform/error/v1.jsonld": "https://sockethub.org/schemas/as2/platform/error/v1/messages.schema.json",
|
|
16
|
+
"https://sockethub.org/ns/context/platform/feeds/v1.jsonld": "https://sockethub.org/schemas/as2/platform/feeds/v1/messages.schema.json",
|
|
17
|
+
"https://sockethub.org/ns/context/platform/irc/v1.jsonld": "https://sockethub.org/schemas/as2/platform/irc/v1/messages.schema.json",
|
|
18
|
+
"https://sockethub.org/ns/context/platform/metadata/v1.jsonld": "https://sockethub.org/schemas/as2/platform/metadata/v1/messages.schema.json",
|
|
19
|
+
"https://sockethub.org/ns/context/platform/sockethub:internal/v1.jsonld": "https://sockethub.org/schemas/as2/platform/sockethub%3Ainternal/v1/messages.schema.json",
|
|
20
|
+
"https://sockethub.org/ns/context/platform/xmpp/v1.jsonld": "https://sockethub.org/schemas/as2/platform/xmpp/v1/messages.schema.json"
|
|
21
|
+
},
|
|
22
|
+
"contextToCredentialsSchemaId": {
|
|
23
|
+
"https://sockethub.org/ns/context/platform/dummy/v1.jsonld": "https://sockethub.org/schemas/as2/platform/dummy/v1/credentials.schema.json",
|
|
24
|
+
"https://sockethub.org/ns/context/platform/error/v1.jsonld": "https://sockethub.org/schemas/as2/platform/error/v1/credentials.schema.json",
|
|
25
|
+
"https://sockethub.org/ns/context/platform/feeds/v1.jsonld": "https://sockethub.org/schemas/as2/platform/feeds/v1/credentials.schema.json",
|
|
26
|
+
"https://sockethub.org/ns/context/platform/irc/v1.jsonld": "https://sockethub.org/schemas/as2/platform/irc/v1/credentials.schema.json",
|
|
27
|
+
"https://sockethub.org/ns/context/platform/metadata/v1.jsonld": "https://sockethub.org/schemas/as2/platform/metadata/v1/credentials.schema.json",
|
|
28
|
+
"https://sockethub.org/ns/context/platform/sockethub:internal/v1.jsonld": "https://sockethub.org/schemas/as2/platform/sockethub%3Ainternal/v1/credentials.schema.json",
|
|
29
|
+
"https://sockethub.org/ns/context/platform/xmpp/v1.jsonld": "https://sockethub.org/schemas/as2/platform/xmpp/v1/credentials.schema.json"
|
|
30
|
+
},
|
|
31
|
+
"constants": {
|
|
32
|
+
"as2": "https://www.w3.org/ns/activitystreams",
|
|
33
|
+
"sockethub": "https://sockethub.org/ns/context/v1.jsonld"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"type"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"type": {
|
|
7
|
+
"enum": [
|
|
8
|
+
"echo",
|
|
9
|
+
"fail",
|
|
10
|
+
"throw",
|
|
11
|
+
"greet",
|
|
12
|
+
"exit0",
|
|
13
|
+
"exit1",
|
|
14
|
+
"throwTypeError",
|
|
15
|
+
"throwReferenceError",
|
|
16
|
+
"sigterm",
|
|
17
|
+
"sigkill",
|
|
18
|
+
"hang"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"type"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"type": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"enum": [
|
|
9
|
+
"fetch"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"object": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"oneOf": [
|
|
15
|
+
{
|
|
16
|
+
"$ref": "#/definitions/objectTypes/feed-parameters-date"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"$ref": "#/definitions/objectTypes/feed-parameters-url"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"definitions": {
|
|
25
|
+
"objectTypes": {
|
|
26
|
+
"feed-parameters-date": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"additionalProperties": true
|
|
29
|
+
},
|
|
30
|
+
"feed-parameters-url": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"additionalProperties": true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"object"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"actor": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"required": [
|
|
9
|
+
"id"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"object": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"required": [
|
|
15
|
+
"type",
|
|
16
|
+
"nick",
|
|
17
|
+
"server"
|
|
18
|
+
],
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"properties": {
|
|
21
|
+
"type": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
},
|
|
24
|
+
"nick": {
|
|
25
|
+
"type": "string"
|
|
26
|
+
},
|
|
27
|
+
"username": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"password": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"server": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"port": {
|
|
37
|
+
"type": "number"
|
|
38
|
+
},
|
|
39
|
+
"secure": {
|
|
40
|
+
"type": "boolean"
|
|
41
|
+
},
|
|
42
|
+
"sasl": {
|
|
43
|
+
"type": "boolean"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"type"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"type": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"enum": [
|
|
9
|
+
"fetch"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"object": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"oneOf": [
|
|
15
|
+
{
|
|
16
|
+
"$ref": "#/definitions/objectTypes/feed-parameters-url"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"definitions": {
|
|
22
|
+
"objectTypes": {
|
|
23
|
+
"feed-parameters-url": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"additionalProperties": true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"object"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"actor": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"required": [
|
|
9
|
+
"id"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"object": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"required": [
|
|
15
|
+
"type",
|
|
16
|
+
"userAddress",
|
|
17
|
+
"password",
|
|
18
|
+
"resource"
|
|
19
|
+
],
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"properties": {
|
|
22
|
+
"type": {
|
|
23
|
+
"type": "string"
|
|
24
|
+
},
|
|
25
|
+
"userAddress": {
|
|
26
|
+
"type": "string"
|
|
27
|
+
},
|
|
28
|
+
"password": {
|
|
29
|
+
"type": "string"
|
|
30
|
+
},
|
|
31
|
+
"server": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
},
|
|
34
|
+
"port": {
|
|
35
|
+
"type": "number"
|
|
36
|
+
},
|
|
37
|
+
"resource": {
|
|
38
|
+
"type": "string"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"required": [
|
|
3
|
+
"type"
|
|
4
|
+
],
|
|
5
|
+
"properties": {
|
|
6
|
+
"type": {
|
|
7
|
+
"enum": [
|
|
8
|
+
"connect",
|
|
9
|
+
"join",
|
|
10
|
+
"leave",
|
|
11
|
+
"send",
|
|
12
|
+
"update",
|
|
13
|
+
"request-friend",
|
|
14
|
+
"remove-friend",
|
|
15
|
+
"make-friend",
|
|
16
|
+
"query",
|
|
17
|
+
"disconnect"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sockethub/schemas",
|
|
3
3
|
"description": "JSON schema files for validating Sockethub Activity Streams",
|
|
4
|
-
"version": "3.0.0-alpha.
|
|
4
|
+
"version": "3.0.0-alpha.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
"bun": "./src/index.ts",
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./context": {
|
|
20
|
+
"bun": "./src/context.ts",
|
|
21
|
+
"import": "./dist/context.js",
|
|
22
|
+
"default": "./dist/context.js"
|
|
23
|
+
},
|
|
24
|
+
"./schemas/json/sockethub-config.json": {
|
|
25
|
+
"default": "./src/schemas/json/sockethub-config.json"
|
|
18
26
|
}
|
|
19
27
|
},
|
|
20
28
|
"files": [
|
|
@@ -38,18 +46,17 @@
|
|
|
38
46
|
},
|
|
39
47
|
"homepage": "https://github.com/sockethub/sockethub/tree/master/packages/schemas",
|
|
40
48
|
"devDependencies": {
|
|
41
|
-
"@types/bun": "latest"
|
|
42
|
-
"@types/debug": "^4.1.12"
|
|
49
|
+
"@types/bun": "latest"
|
|
43
50
|
},
|
|
44
51
|
"scripts": {
|
|
45
|
-
"build": "bun ./scripts/export-json-schema.ts && bun build src/index.ts --outdir dist --target node --format esm --sourcemap=external",
|
|
46
|
-
"clean": "rm -rf dist"
|
|
52
|
+
"build": "bun ./scripts/export-json-schema.ts && bun ./scripts/export-canonical-assets.ts && bun build src/index.ts src/context.ts --outdir dist --target node --format esm --sourcemap=external",
|
|
53
|
+
"clean": "rm -rf dist",
|
|
54
|
+
"clean:deps": "rm -rf node_modules"
|
|
47
55
|
},
|
|
48
56
|
"dependencies": {
|
|
49
57
|
"ajv": "^8.17.1",
|
|
50
58
|
"ajv-formats": "^2.1.1",
|
|
51
|
-
"ajv-formats-draft2019": "^1.6.1"
|
|
52
|
-
"debug": "^4.4.3"
|
|
59
|
+
"ajv-formats-draft2019": "^1.6.1"
|
|
53
60
|
},
|
|
54
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "f039dab3c3f67cbbf204476fc397532e973f82a8"
|
|
55
62
|
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { ActivityStream, JsonLdContext } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canonical AS2 base vocabulary URL.
|
|
5
|
+
*/
|
|
6
|
+
export const AS2_BASE_CONTEXT_URL = "https://www.w3.org/ns/activitystreams";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sockethub base vocabulary URL for shared platform terms.
|
|
10
|
+
*/
|
|
11
|
+
export const SOCKETHUB_BASE_CONTEXT_URL =
|
|
12
|
+
"https://sockethub.org/ns/context/v1.jsonld";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* URL prefix for per-platform context URLs.
|
|
16
|
+
*/
|
|
17
|
+
export const PLATFORM_CONTEXT_PREFIX =
|
|
18
|
+
"https://sockethub.org/ns/context/platform/";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Built-in pseudo-platform used for server-side error payloads.
|
|
22
|
+
*/
|
|
23
|
+
export const ERROR_PLATFORM_ID = "error";
|
|
24
|
+
export const ERROR_PLATFORM_CONTEXT_URL =
|
|
25
|
+
"https://sockethub.org/ns/context/platform/error/v1.jsonld";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Built-in pseudo-platform used for internal control messages.
|
|
29
|
+
*/
|
|
30
|
+
export const INTERNAL_PLATFORM_ID = "sockethub:internal";
|
|
31
|
+
export const INTERNAL_PLATFORM_CONTEXT_URL =
|
|
32
|
+
"https://sockethub.org/ns/context/platform/sockethub:internal/v1.jsonld";
|
|
33
|
+
|
|
34
|
+
const platformContextToPlatformId = new Map<string, string>();
|
|
35
|
+
const platformContextToSchemaId = new Map<string, string>();
|
|
36
|
+
const platformContextToCredentialsSchemaId = new Map<string, string>();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build the canonical Sockethub @context array for a platform context URL.
|
|
40
|
+
*/
|
|
41
|
+
export function buildCanonicalContext(
|
|
42
|
+
platformContextUrl: string,
|
|
43
|
+
): JsonLdContext {
|
|
44
|
+
return [
|
|
45
|
+
AS2_BASE_CONTEXT_URL,
|
|
46
|
+
SOCKETHUB_BASE_CONTEXT_URL,
|
|
47
|
+
platformContextUrl,
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Normalize unknown @context input into a string-only array.
|
|
53
|
+
*/
|
|
54
|
+
function normalizeContextArray(value: unknown): Array<string> {
|
|
55
|
+
if (!Array.isArray(value)) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return value.filter((entry): entry is string => typeof entry === "string");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get a normalized @context array from an activity stream.
|
|
63
|
+
*/
|
|
64
|
+
export function getContextArray(msg: ActivityStream): Array<string> {
|
|
65
|
+
return normalizeContextArray(msg["@context"]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Register a platform context URL and its schema IDs for runtime resolution.
|
|
70
|
+
*/
|
|
71
|
+
export function registerPlatformContext(
|
|
72
|
+
platformId: string,
|
|
73
|
+
platformContextUrl: string,
|
|
74
|
+
schemaId: string,
|
|
75
|
+
credentialsSchemaId: string,
|
|
76
|
+
) {
|
|
77
|
+
platformContextToPlatformId.set(platformContextUrl, platformId);
|
|
78
|
+
platformContextToSchemaId.set(platformContextUrl, schemaId);
|
|
79
|
+
platformContextToCredentialsSchemaId.set(
|
|
80
|
+
platformContextUrl,
|
|
81
|
+
credentialsSchemaId,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the single registered platform context URL from a message.
|
|
87
|
+
* Returns null when there are zero or multiple registered platform contexts.
|
|
88
|
+
*/
|
|
89
|
+
export function resolvePlatformContextUrl(msg: ActivityStream): string | null {
|
|
90
|
+
const contexts = getContextArray(msg);
|
|
91
|
+
const matches = contexts.filter((contextUrl) =>
|
|
92
|
+
platformContextToPlatformId.has(contextUrl),
|
|
93
|
+
);
|
|
94
|
+
if (matches.length !== 1) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return matches[0];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resolve a platform ID from a platform context URL.
|
|
102
|
+
*/
|
|
103
|
+
export function getPlatformIdByContextUrl(
|
|
104
|
+
platformContextUrl: string,
|
|
105
|
+
): string | undefined {
|
|
106
|
+
return platformContextToPlatformId.get(platformContextUrl);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Resolve a message schema ID from a platform context URL.
|
|
111
|
+
*/
|
|
112
|
+
export function getSchemaIdByContextUrl(
|
|
113
|
+
platformContextUrl: string,
|
|
114
|
+
): string | undefined {
|
|
115
|
+
return platformContextToSchemaId.get(platformContextUrl);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Resolve a credentials schema ID from a platform context URL.
|
|
120
|
+
*/
|
|
121
|
+
export function getCredentialsSchemaIdByContextUrl(
|
|
122
|
+
platformContextUrl: string,
|
|
123
|
+
): string | undefined {
|
|
124
|
+
return platformContextToCredentialsSchemaId.get(platformContextUrl);
|
|
125
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ErrorObject } from "ajv";
|
|
2
2
|
import type { ActivityObject, ActivityStream } from "../types.js";
|
|
3
|
-
import { ObjectTypesList } from "./objects.js";
|
|
3
|
+
import { ActorTypesList, ObjectTypesList, TargetTypesList } from "./objects.js";
|
|
4
|
+
|
|
5
|
+
export interface ValidationErrorOptions {
|
|
6
|
+
excludeTypes?: Array<string>;
|
|
7
|
+
}
|
|
4
8
|
|
|
5
9
|
interface TypeBreakdown {
|
|
6
10
|
actor: Array<string>;
|
|
@@ -21,22 +25,28 @@ function parseMsg(error: ErrorObject): string {
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
function getTypeList(msg: ActivityStream | ActivityObject): Array<string> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const types: Array<string> = [];
|
|
29
|
+
if (msg?.type) {
|
|
30
|
+
types.push(msg.type);
|
|
31
|
+
}
|
|
32
|
+
const record = msg as Record<string, unknown>;
|
|
33
|
+
for (const prop in record) {
|
|
34
|
+
const value = record[prop];
|
|
35
|
+
if (value && typeof value === "object" && "type" in value) {
|
|
36
|
+
types.push(
|
|
37
|
+
...getTypeList(value as ActivityStream | ActivityObject),
|
|
38
|
+
);
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
return types;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
function getSchemaType(error: ErrorObject): string {
|
|
44
|
+
function getSchemaType(error: ErrorObject): string | undefined {
|
|
35
45
|
const schemaTypeRes = error.schemaPath.match(/#\/\w+\/\w+\/([\w-]+)\//);
|
|
36
46
|
return schemaTypeRes ? schemaTypeRes[1] : undefined;
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
function getErrType(error: ErrorObject): string {
|
|
49
|
+
function getErrType(error: ErrorObject): string | undefined {
|
|
40
50
|
const errTypeRes = error.instancePath.match(/\/(\w+)/);
|
|
41
51
|
return errTypeRes ? errTypeRes[1] : undefined;
|
|
42
52
|
}
|
|
@@ -47,21 +57,33 @@ function getPartsCount(error: ErrorObject, types: TypeBreakdown): number {
|
|
|
47
57
|
if (!errType) {
|
|
48
58
|
return -1;
|
|
49
59
|
}
|
|
50
|
-
|
|
60
|
+
const typeList = (types as unknown as Record<string, Array<string>>)[
|
|
61
|
+
errType
|
|
62
|
+
];
|
|
63
|
+
if (!typeList) {
|
|
51
64
|
return -1;
|
|
52
65
|
}
|
|
53
|
-
if (!
|
|
66
|
+
if (!schemaType || !typeList.includes(schemaType)) {
|
|
54
67
|
return -1;
|
|
55
68
|
}
|
|
56
69
|
const parts = error.instancePath.split("/");
|
|
57
70
|
return parts.length;
|
|
58
71
|
}
|
|
59
72
|
|
|
60
|
-
function getTypes(msg: ActivityStream): TypeBreakdown {
|
|
73
|
+
function getTypes(msg: ActivityStream | ActivityObject): TypeBreakdown {
|
|
74
|
+
if (!Array.isArray((msg as ActivityStream)["@context"])) {
|
|
75
|
+
return {
|
|
76
|
+
actor: [],
|
|
77
|
+
target: [],
|
|
78
|
+
object: getTypeList(msg),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const stream = msg as ActivityStream;
|
|
61
83
|
return {
|
|
62
|
-
actor: getTypeList(
|
|
63
|
-
target: getTypeList(
|
|
64
|
-
object:
|
|
84
|
+
actor: getTypeList(stream.actor),
|
|
85
|
+
target: getTypeList(stream.target),
|
|
86
|
+
object: stream.object ? getTypeList(stream.object) : [],
|
|
65
87
|
};
|
|
66
88
|
}
|
|
67
89
|
|
|
@@ -73,8 +95,9 @@ function getTypes(msg: ActivityStream): TypeBreakdown {
|
|
|
73
95
|
* @returns {string}
|
|
74
96
|
*/
|
|
75
97
|
export default function getErrorMessage(
|
|
76
|
-
msg,
|
|
98
|
+
msg: ActivityStream | ActivityObject,
|
|
77
99
|
errors: Array<ErrorObject>,
|
|
100
|
+
options?: ValidationErrorOptions,
|
|
78
101
|
): string {
|
|
79
102
|
const types = getTypes(msg);
|
|
80
103
|
let deepest_entry = 0;
|
|
@@ -90,17 +113,41 @@ export default function getErrorMessage(
|
|
|
90
113
|
|
|
91
114
|
return highest_depth >= 0
|
|
92
115
|
? parseMsg(errors[deepest_entry])
|
|
93
|
-
: composeFinalError(errors[errors.length - 1]);
|
|
116
|
+
: composeFinalError(errors[errors.length - 1], options);
|
|
94
117
|
}
|
|
95
118
|
|
|
96
|
-
function
|
|
119
|
+
function filterTypeList(
|
|
120
|
+
types: Array<string>,
|
|
121
|
+
options?: ValidationErrorOptions,
|
|
122
|
+
): Array<string> {
|
|
123
|
+
if (!options?.excludeTypes || options.excludeTypes.length === 0) {
|
|
124
|
+
return types;
|
|
125
|
+
}
|
|
126
|
+
const exclude = new Set(options.excludeTypes);
|
|
127
|
+
return types.filter((type) => !exclude.has(type));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function composeFinalError(
|
|
131
|
+
error: ErrorObject,
|
|
132
|
+
options?: ValidationErrorOptions,
|
|
133
|
+
): string {
|
|
97
134
|
// if we have yet to build an error message, assume this is an invalid type value (oneOf),
|
|
98
135
|
// try to build a list of valid types
|
|
99
136
|
let msg: string;
|
|
100
137
|
if (error.keyword === "oneOf") {
|
|
138
|
+
const instanceRoot = error.instancePath.split("/")[1];
|
|
139
|
+
const pathScopedTypes =
|
|
140
|
+
instanceRoot === "actor"
|
|
141
|
+
? ActorTypesList
|
|
142
|
+
: instanceRoot === "target"
|
|
143
|
+
? TargetTypesList
|
|
144
|
+
: ObjectTypesList;
|
|
145
|
+
const filteredTypes = filterTypeList(pathScopedTypes, options);
|
|
146
|
+
const typesList =
|
|
147
|
+
filteredTypes.length > 0 ? filteredTypes : pathScopedTypes;
|
|
101
148
|
msg =
|
|
102
149
|
`${error.instancePath}: ${error.message}: ` +
|
|
103
|
-
`${
|
|
150
|
+
`${typesList.join(", ")}`;
|
|
104
151
|
} else {
|
|
105
152
|
msg = `${
|
|
106
153
|
error.instancePath ? error.instancePath : "activity stream"
|