@sockethub/schemas 3.0.0-alpha.9 → 3.0.0-beta.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/activity-stream-helper.d.ts +5 -0
- package/dist/activity-stream-helper.js +36 -0
- package/dist/activity-stream-helper.js.map +10 -0
- package/dist/context.d.ts +56 -0
- package/dist/context.js +80 -0
- package/dist/context.js.map +10 -0
- package/dist/contexts/platform/caldav/v1.jsonld +8 -0
- package/dist/contexts/platform/carddav/v1.jsonld +8 -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/helpers/codegen.d.ts +23 -0
- package/dist/helpers/error-parser.d.ts +13 -0
- package/dist/helpers/objects.d.ts +157 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1375 -1147
- package/dist/index.js.map +16 -17
- package/dist/maps/context-map.json +41 -0
- package/dist/object-types.d.ts +2 -0
- package/dist/object-types.js +299 -0
- package/dist/object-types.js.map +12 -0
- package/dist/schema-id.d.ts +11 -0
- package/dist/schemas/activity-stream.d.ts +196 -0
- package/{src/schemas/json/activity-object.json → dist/schemas/json/activity-stream.json} +99 -158
- package/dist/schemas/json/platform.json +52 -0
- package/dist/schemas/json/service-descriptor.json +58 -0
- package/dist/schemas/json/sockethub-config.json +515 -0
- package/dist/schemas/platform/caldav/v1/credentials.schema.json +71 -0
- package/dist/schemas/platform/caldav/v1/messages.schema.json +769 -0
- package/dist/schemas/platform/carddav/v1/credentials.schema.json +67 -0
- package/dist/schemas/platform/carddav/v1/messages.schema.json +375 -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 +27 -0
- package/dist/schemas/platform/irc/v1/credentials.schema.json +118 -0
- package/dist/schemas/platform/irc/v1/messages.schema.json +149 -0
- package/dist/schemas/platform/metadata/v1/credentials.schema.json +1 -0
- package/dist/schemas/platform/metadata/v1/messages.schema.json +14 -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 +45 -0
- package/dist/schemas/platform/xmpp/v1/messages.schema.json +129 -0
- package/dist/schemas/platform.d.ts +62 -0
- package/dist/schemas/service-descriptor.d.ts +84 -0
- package/dist/schemas/sockethub-config.d.ts +481 -0
- package/dist/service-descriptor.d.ts +9 -0
- package/dist/service-descriptor.js +6355 -0
- package/dist/service-descriptor.js.map +78 -0
- package/{src/types.ts → dist/types.d.ts} +52 -53
- package/dist/validator.d.ts +50 -0
- package/package.json +32 -11
- package/src/helpers/error-parser.ts +0 -113
- package/src/helpers/objects.ts +0 -227
- package/src/index.test.data.credentials.ts +0 -71
- package/src/index.test.data.objects.ts +0 -241
- package/src/index.test.data.platform.ts +0 -45
- package/src/index.test.data.streams.ts +0 -498
- package/src/index.test.ts +0 -99
- package/src/index.ts +0 -27
- package/src/schemas/activity-object.ts +0 -19
- package/src/schemas/activity-stream.ts +0 -54
- package/src/schemas/json/activity-stream.json +0 -469
- package/src/schemas/json/platform.json +0 -28
- package/src/schemas/json/sockethub-config.json +0 -144
- package/src/schemas/platform.ts +0 -47
- package/src/schemas/sockethub-config.ts +0 -140
- package/src/validator.ts +0 -94
|
@@ -1,77 +1,66 @@
|
|
|
1
1
|
export interface ASCollection {
|
|
2
|
-
context:
|
|
2
|
+
"@context": JsonLdContext;
|
|
3
3
|
id?: string;
|
|
4
4
|
summary: string;
|
|
5
5
|
type: "collection";
|
|
6
6
|
totalItems: number;
|
|
7
7
|
items: Array<ActivityStream>;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
export type JsonLdContext = Array<string>;
|
|
10
10
|
export interface ActivityStream {
|
|
11
|
+
"@context": JsonLdContext;
|
|
11
12
|
id?: string;
|
|
12
13
|
type: string;
|
|
13
|
-
context: string;
|
|
14
14
|
actor: ActivityActor;
|
|
15
15
|
object?: ActivityObject;
|
|
16
16
|
target?: ActivityActor;
|
|
17
17
|
error?: string;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
export interface InternalActivityStream extends ActivityStream {
|
|
21
20
|
sessionSecret?: string;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
export interface BaseActivityObject {
|
|
25
23
|
id?: string;
|
|
26
24
|
type: string;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
export interface ActivityActor extends BaseActivityObject {
|
|
30
27
|
id: string;
|
|
31
28
|
type: string;
|
|
32
29
|
name?: string;
|
|
33
30
|
[key: string]: unknown;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
export interface ActivityObject extends BaseActivityObject {
|
|
37
33
|
content?: string;
|
|
38
34
|
[key: string]: unknown;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
type ErrorMsg = string | Error;
|
|
42
|
-
|
|
43
|
-
export type PlatformCallback = (
|
|
44
|
-
err?: ErrorMsg,
|
|
45
|
-
data?: ActivityStream | ASCollection,
|
|
46
|
-
) => void;
|
|
47
|
-
|
|
37
|
+
export type PlatformCallback = (err?: ErrorMsg, data?: ActivityStream | ASCollection) => void;
|
|
48
38
|
export type CallbackInterface = (err?: ErrorMsg, data?: unknown) => void;
|
|
49
|
-
|
|
50
39
|
export type MiddlewareCallback = (data: ActivityStream | Error) => void;
|
|
51
|
-
|
|
52
40
|
export type CompletedJobHandler = (data: ActivityStream | undefined) => void;
|
|
53
|
-
|
|
54
|
-
export type PlatformSendToClient = (
|
|
55
|
-
msg: ActivityStream,
|
|
56
|
-
special?: string,
|
|
57
|
-
) => void;
|
|
58
|
-
|
|
41
|
+
export type PlatformSendToClient = (msg: ActivityStream, special?: string) => void;
|
|
59
42
|
export type PlatformUpdateActor = (credentials: object) => Promise<void>;
|
|
60
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Read-only check that a proposed actor rename will not overwrite a different
|
|
45
|
+
* account. IRC calls this before sending NICK: the refusal has to happen
|
|
46
|
+
* before the server applies the nick, or a collision still changes the nick
|
|
47
|
+
* the connection is using while the client is told the rename failed.
|
|
48
|
+
*/
|
|
49
|
+
export type PlatformPrepareActorUpdate = (credentials: object) => Promise<void>;
|
|
61
50
|
export interface Logger {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(
|
|
51
|
+
error(message: string, meta?: object): void;
|
|
52
|
+
warn(message: string, meta?: object): void;
|
|
53
|
+
info(message: string, meta?: object): void;
|
|
54
|
+
debug(message: string, meta?: object): void;
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
export interface PlatformSession {
|
|
68
|
-
|
|
57
|
+
log: Logger;
|
|
69
58
|
sendToClient: PlatformSendToClient;
|
|
70
59
|
updateActor: PlatformUpdateActor;
|
|
60
|
+
prepareActorUpdate?: PlatformPrepareActorUpdate;
|
|
71
61
|
}
|
|
72
|
-
|
|
73
62
|
export interface CredentialsObject {
|
|
74
|
-
context:
|
|
63
|
+
"@context": JsonLdContext;
|
|
75
64
|
type: "credentials";
|
|
76
65
|
actor: ActivityActor;
|
|
77
66
|
object: {
|
|
@@ -80,7 +69,6 @@ export interface CredentialsObject {
|
|
|
80
69
|
};
|
|
81
70
|
target?: ActivityActor;
|
|
82
71
|
}
|
|
83
|
-
|
|
84
72
|
/**
|
|
85
73
|
* Platform configuration discriminated union.
|
|
86
74
|
*
|
|
@@ -99,17 +87,25 @@ export interface CredentialsObject {
|
|
|
99
87
|
* - Example: IRC, XMPP
|
|
100
88
|
*/
|
|
101
89
|
export type PlatformConfig = StatelessPlatformConfig | PersistentPlatformConfig;
|
|
102
|
-
|
|
103
90
|
interface BasePlatformConfig {
|
|
104
91
|
connectTimeoutMs?: number;
|
|
92
|
+
allowPrivateAddresses?: boolean;
|
|
93
|
+
/** CalDAV-only escape hatch for explicitly configured HTTP services. */
|
|
94
|
+
allowInsecureHttp?: boolean;
|
|
105
95
|
}
|
|
106
|
-
|
|
107
96
|
/** Configuration for stateless platforms that start/stop per-request */
|
|
108
97
|
export interface StatelessPlatformConfig extends BasePlatformConfig {
|
|
109
98
|
persist: false;
|
|
110
99
|
requireCredentials?: string[];
|
|
100
|
+
/**
|
|
101
|
+
* Number of jobs the platform's worker processes in parallel. Stateless
|
|
102
|
+
* platforms are shared by every session on the server, so serial
|
|
103
|
+
* processing lets one slow job (e.g. a hanging feed fetch) stall all
|
|
104
|
+
* other clients. Defaults to 10; override per-platform via
|
|
105
|
+
* `packageConfig`.
|
|
106
|
+
*/
|
|
107
|
+
concurrency?: number;
|
|
111
108
|
}
|
|
112
|
-
|
|
113
109
|
/**
|
|
114
110
|
* Configuration for persistent platforms with long-running connections.
|
|
115
111
|
* These always require credentials because persistent state is actor-specific.
|
|
@@ -118,13 +114,14 @@ export interface PersistentPlatformConfig extends BasePlatformConfig {
|
|
|
118
114
|
persist: true;
|
|
119
115
|
/** Message types requiring credentials (must be non-empty for persistent platforms) */
|
|
120
116
|
requireCredentials: string[];
|
|
121
|
-
/** Whether the platform has completed initialization */
|
|
122
|
-
initialized: boolean;
|
|
123
117
|
}
|
|
124
|
-
|
|
125
118
|
export interface PlatformSchemaStruct {
|
|
126
119
|
name: string;
|
|
127
120
|
version: string;
|
|
121
|
+
contextUrl: string;
|
|
122
|
+
contextVersion: string;
|
|
123
|
+
schemaVersion: string;
|
|
124
|
+
messageConstraints?: object;
|
|
128
125
|
credentials?: object;
|
|
129
126
|
messages?: {
|
|
130
127
|
required?: string[];
|
|
@@ -134,23 +131,34 @@ export interface PlatformSchemaStruct {
|
|
|
134
131
|
};
|
|
135
132
|
};
|
|
136
133
|
};
|
|
134
|
+
responses?: object;
|
|
137
135
|
}
|
|
138
|
-
|
|
139
136
|
export interface PlatformConstructor {
|
|
140
|
-
new (session: PlatformSession): {
|
|
137
|
+
new (session: PlatformSession): {
|
|
138
|
+
log: Logger;
|
|
139
|
+
};
|
|
141
140
|
}
|
|
142
|
-
|
|
143
141
|
/**
|
|
144
142
|
* Base interface for all Sockethub platforms.
|
|
145
143
|
* Platforms implement protocol-specific logic for ActivityStreams messages.
|
|
146
144
|
*/
|
|
147
145
|
export interface PlatformInterface {
|
|
148
|
-
debug: Logger;
|
|
149
146
|
get config(): PlatformConfig;
|
|
150
147
|
get schema(): PlatformSchemaStruct;
|
|
148
|
+
/**
|
|
149
|
+
* Returns whether the platform is ready to handle jobs.
|
|
150
|
+
*
|
|
151
|
+
* For persistent platforms: Returns true once the initial connection succeeds.
|
|
152
|
+
* During temporary network interruptions with automatic reconnection, should
|
|
153
|
+
* remain true to allow queued jobs to retry rather than fail.
|
|
154
|
+
*
|
|
155
|
+
* For stateless platforms: Can always return true since they have no connection state.
|
|
156
|
+
*
|
|
157
|
+
* @returns true if the platform can process jobs, false otherwise
|
|
158
|
+
*/
|
|
159
|
+
isInitialized(): boolean;
|
|
151
160
|
cleanup(cb: PlatformCallback): void;
|
|
152
161
|
}
|
|
153
|
-
|
|
154
162
|
/**
|
|
155
163
|
* Interface for persistent platforms with long-running connections.
|
|
156
164
|
*
|
|
@@ -168,15 +176,6 @@ export interface PersistentPlatformInterface extends PlatformInterface {
|
|
|
168
176
|
*/
|
|
169
177
|
credentialsHash: string | undefined;
|
|
170
178
|
get config(): PersistentPlatformConfig;
|
|
171
|
-
connect(
|
|
172
|
-
job: ActivityStream,
|
|
173
|
-
credentials: CredentialsObject,
|
|
174
|
-
done: PlatformCallback,
|
|
175
|
-
): void;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export interface PlatformSession {
|
|
179
|
-
debug: Logger;
|
|
180
|
-
sendToClient: PlatformSendToClient;
|
|
181
|
-
updateActor: PlatformUpdateActor;
|
|
179
|
+
connect(job: ActivityStream, credentials: CredentialsObject, done: PlatformCallback): void;
|
|
182
180
|
}
|
|
181
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Schema } from "ajv";
|
|
2
|
+
import { type ValidationErrorOptions } from "./helpers/error-parser.js";
|
|
3
|
+
import type { ActivityStream } from "./types.js";
|
|
4
|
+
export declare function registerSystemPlatformContexts(): void;
|
|
5
|
+
export declare function setValidationErrorOptions(options: ValidationErrorOptions): void;
|
|
6
|
+
/**
|
|
7
|
+
* Validate a (fully-materialized) Sockethub server config object against the
|
|
8
|
+
* canonical config schema. Returns "" when valid, otherwise a human-readable
|
|
9
|
+
* error string. Used by the server at startup so a mis-typed or unknown config
|
|
10
|
+
* value — including inside a platform's `packageConfig` entry — fails loudly
|
|
11
|
+
* rather than reaching a platform wrong-typed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateSockethubConfig(config: unknown): string;
|
|
14
|
+
/**
|
|
15
|
+
* Validate an inbound activity stream against the shared envelope and its
|
|
16
|
+
* registered platform message schema. Returns "" when valid; skipped (also "")
|
|
17
|
+
* when code generation is unavailable.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateActivityStream(msg: ActivityStream): string;
|
|
20
|
+
/**
|
|
21
|
+
* Validate an outbound platform response against that platform's `responses`
|
|
22
|
+
* schema. Returns "" when the platform has no responses schema registered (yet),
|
|
23
|
+
* so outbound validation can be adopted platform-by-platform.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateActivityStreamResponse(msg: ActivityStream): string;
|
|
26
|
+
/**
|
|
27
|
+
* Validate a credentials activity stream against the shared envelope and its
|
|
28
|
+
* registered platform credentials schema. Returns "" when valid; skipped (also
|
|
29
|
+
* "") when code generation is unavailable.
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateCredentials(msg: ActivityStream): string;
|
|
32
|
+
/**
|
|
33
|
+
* Validate a platform schema: its structural shape via Ajv (when available)
|
|
34
|
+
* and that its actor/target types are registered in the shared ActivityStreams
|
|
35
|
+
* envelope. Returns "" when valid, otherwise an error string.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validatePlatformSchema(schema: Schema): string;
|
|
38
|
+
/**
|
|
39
|
+
* Register a platform's message or credentials schema with the validators, so
|
|
40
|
+
* local validation uses the same canonical sources as the server. No-op when
|
|
41
|
+
* code generation is unavailable.
|
|
42
|
+
*/
|
|
43
|
+
export declare function addPlatformSchema(schema: Schema, platform_type: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Look up a registered platform schema validator, or `undefined` when no such
|
|
46
|
+
* schema is registered or code generation is unavailable.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getPlatformSchema(platform_type: string): import("ajv/dist/core.js").AnyValidateFunction<unknown>;
|
|
49
|
+
export declare function addPlatformContext(platformId: string, platformContextUrl: string): void;
|
|
50
|
+
export declare function resolvePlatformId(msg: ActivityStream): string | null;
|
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-
|
|
4
|
+
"version": "3.0.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
@@ -12,17 +12,38 @@
|
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./context": {
|
|
20
|
+
"types": "./dist/context.d.ts",
|
|
21
|
+
"import": "./dist/context.js",
|
|
22
|
+
"default": "./dist/context.js"
|
|
23
|
+
},
|
|
24
|
+
"./object-types": {
|
|
25
|
+
"types": "./dist/object-types.d.ts",
|
|
26
|
+
"import": "./dist/object-types.js",
|
|
27
|
+
"default": "./dist/object-types.js"
|
|
28
|
+
},
|
|
29
|
+
"./service-descriptor": {
|
|
30
|
+
"types": "./dist/service-descriptor.d.ts",
|
|
31
|
+
"bun": "./src/service-descriptor.ts",
|
|
32
|
+
"import": "./dist/service-descriptor.js",
|
|
33
|
+
"default": "./dist/service-descriptor.js"
|
|
34
|
+
},
|
|
35
|
+
"./schemas/json/sockethub-config.json": {
|
|
36
|
+
"default": "./dist/schemas/json/sockethub-config.json"
|
|
37
|
+
},
|
|
38
|
+
"./schemas/json/service-descriptor.json": {
|
|
39
|
+
"default": "./dist/schemas/json/service-descriptor.json"
|
|
18
40
|
}
|
|
19
41
|
},
|
|
20
42
|
"files": [
|
|
21
|
-
"src/",
|
|
22
43
|
"dist/"
|
|
23
44
|
],
|
|
24
45
|
"engines": {
|
|
25
|
-
"
|
|
46
|
+
"node": ">=20"
|
|
26
47
|
},
|
|
27
48
|
"keywords": [
|
|
28
49
|
"sockethub",
|
|
@@ -38,18 +59,18 @@
|
|
|
38
59
|
},
|
|
39
60
|
"homepage": "https://github.com/sockethub/sockethub/tree/master/packages/schemas",
|
|
40
61
|
"devDependencies": {
|
|
41
|
-
"@types/bun": "latest"
|
|
42
|
-
"@types/debug": "^4.1.12"
|
|
62
|
+
"@types/bun": "latest"
|
|
43
63
|
},
|
|
44
64
|
"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"
|
|
65
|
+
"build": "bun ./scripts/export-json-schema.ts && bun ./scripts/export-canonical-assets.ts && bun build src/index.ts src/object-types.ts --outdir dist --target node --format esm --sourcemap=external && bun build src/context.ts src/activity-stream-helper.ts src/service-descriptor.ts --outdir dist --target browser --format esm --sourcemap=external",
|
|
66
|
+
"clean": "rm -rf dist",
|
|
67
|
+
"clean:deps": "rm -rf node_modules"
|
|
47
68
|
},
|
|
48
69
|
"dependencies": {
|
|
49
70
|
"ajv": "^8.17.1",
|
|
50
71
|
"ajv-formats": "^2.1.1",
|
|
51
|
-
"ajv-formats-draft2019": "^1.6.1"
|
|
52
|
-
"debug": "^4.4.3"
|
|
72
|
+
"ajv-formats-draft2019": "^1.6.1"
|
|
53
73
|
},
|
|
54
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "928f0c480e4828f492fb29a97712474a8f1bcaef",
|
|
75
|
+
"types": "./dist/index.d.ts"
|
|
55
76
|
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { ErrorObject } from "ajv";
|
|
2
|
-
import type { ActivityObject, ActivityStream } from "../types.js";
|
|
3
|
-
import { ObjectTypesList } from "./objects.js";
|
|
4
|
-
|
|
5
|
-
interface TypeBreakdown {
|
|
6
|
-
actor: Array<string>;
|
|
7
|
-
object: Array<string>;
|
|
8
|
-
target: Array<string>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function parseMsg(error: ErrorObject): string {
|
|
12
|
-
let err = `${
|
|
13
|
-
error.instancePath ? error.instancePath : "activity stream"
|
|
14
|
-
}: ${error.message}`;
|
|
15
|
-
if (error.keyword === "additionalProperties") {
|
|
16
|
-
err += `: ${error.params.additionalProperty}`;
|
|
17
|
-
} else if (error.keyword === "enum") {
|
|
18
|
-
err += `: ${error.params.allowedValues.join(", ")}`;
|
|
19
|
-
}
|
|
20
|
-
return err;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getTypeList(msg: ActivityStream | ActivityObject): Array<string> {
|
|
24
|
-
let types = [];
|
|
25
|
-
types.push(msg?.type);
|
|
26
|
-
for (const prop in msg) {
|
|
27
|
-
if (msg[prop]?.type) {
|
|
28
|
-
types = [...types, ...getTypeList(msg[prop])];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return types;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getSchemaType(error: ErrorObject): string {
|
|
35
|
-
const schemaTypeRes = error.schemaPath.match(/#\/\w+\/\w+\/([\w-]+)\//);
|
|
36
|
-
return schemaTypeRes ? schemaTypeRes[1] : undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getErrType(error: ErrorObject): string {
|
|
40
|
-
const errTypeRes = error.instancePath.match(/\/(\w+)/);
|
|
41
|
-
return errTypeRes ? errTypeRes[1] : undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getPartsCount(error: ErrorObject, types: TypeBreakdown): number {
|
|
45
|
-
const schemaType = getSchemaType(error);
|
|
46
|
-
const errType = getErrType(error);
|
|
47
|
-
if (!errType) {
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
if (!types[errType]) {
|
|
51
|
-
return -1;
|
|
52
|
-
}
|
|
53
|
-
if (!types[errType].includes(schemaType)) {
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
const parts = error.instancePath.split("/");
|
|
57
|
-
return parts.length;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getTypes(msg: ActivityStream): TypeBreakdown {
|
|
61
|
-
return {
|
|
62
|
-
actor: getTypeList(msg.actor),
|
|
63
|
-
target: getTypeList(msg.target),
|
|
64
|
-
object: getTypeList(msg.context ? msg.object : msg),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Traverses the errors array from ajv, and makes a series of filtering decisions to
|
|
70
|
-
* try to arrive at the most useful error.
|
|
71
|
-
* @param msg
|
|
72
|
-
* @param errors
|
|
73
|
-
* @returns {string}
|
|
74
|
-
*/
|
|
75
|
-
export default function getErrorMessage(
|
|
76
|
-
msg,
|
|
77
|
-
errors: Array<ErrorObject>,
|
|
78
|
-
): string {
|
|
79
|
-
const types = getTypes(msg);
|
|
80
|
-
let deepest_entry = 0;
|
|
81
|
-
let highest_depth = -1;
|
|
82
|
-
|
|
83
|
-
for (let i = 0; i < errors.length; i++) {
|
|
84
|
-
const partsCount = getPartsCount(errors[i], types);
|
|
85
|
-
if (partsCount > highest_depth) {
|
|
86
|
-
highest_depth = partsCount;
|
|
87
|
-
deepest_entry = i;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return highest_depth >= 0
|
|
92
|
-
? parseMsg(errors[deepest_entry])
|
|
93
|
-
: composeFinalError(errors[errors.length - 1]);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function composeFinalError(error) {
|
|
97
|
-
// if we have yet to build an error message, assume this is an invalid type value (oneOf),
|
|
98
|
-
// try to build a list of valid types
|
|
99
|
-
let msg: string;
|
|
100
|
-
if (error.keyword === "oneOf") {
|
|
101
|
-
msg =
|
|
102
|
-
`${error.instancePath}: ${error.message}: ` +
|
|
103
|
-
`${ObjectTypesList.join(", ")}`;
|
|
104
|
-
} else {
|
|
105
|
-
msg = `${
|
|
106
|
-
error.instancePath ? error.instancePath : "activity stream"
|
|
107
|
-
}: ${error.message}`;
|
|
108
|
-
}
|
|
109
|
-
if ("additionalProperty" in error.params) {
|
|
110
|
-
msg += `: ${error.params.additionalProperty}`;
|
|
111
|
-
}
|
|
112
|
-
return msg;
|
|
113
|
-
}
|
package/src/helpers/objects.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
export const validObjectRefs = [];
|
|
2
|
-
export const validObjectDefs = {};
|
|
3
|
-
|
|
4
|
-
export const ObjectTypesSchema = {
|
|
5
|
-
credentials: {
|
|
6
|
-
required: ["type"],
|
|
7
|
-
additionalProperties: true,
|
|
8
|
-
properties: {
|
|
9
|
-
type: {
|
|
10
|
-
enum: ["credentials"],
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
feed: {
|
|
16
|
-
required: ["id", "type"],
|
|
17
|
-
additionalProperties: true,
|
|
18
|
-
properties: {
|
|
19
|
-
type: {
|
|
20
|
-
enum: ["feed"],
|
|
21
|
-
},
|
|
22
|
-
id: {
|
|
23
|
-
type: "string",
|
|
24
|
-
format: "iri",
|
|
25
|
-
},
|
|
26
|
-
name: {
|
|
27
|
-
type: "string",
|
|
28
|
-
},
|
|
29
|
-
description: {
|
|
30
|
-
type: "string",
|
|
31
|
-
},
|
|
32
|
-
author: {
|
|
33
|
-
type: "string",
|
|
34
|
-
},
|
|
35
|
-
favicon: {
|
|
36
|
-
type: "string",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
message: {
|
|
42
|
-
required: ["type", "content"],
|
|
43
|
-
additionalProperties: true,
|
|
44
|
-
properties: {
|
|
45
|
-
type: {
|
|
46
|
-
enum: ["message"],
|
|
47
|
-
},
|
|
48
|
-
id: {
|
|
49
|
-
type: "string",
|
|
50
|
-
},
|
|
51
|
-
name: {
|
|
52
|
-
type: "string",
|
|
53
|
-
},
|
|
54
|
-
content: {
|
|
55
|
-
type: "string",
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
me: {
|
|
61
|
-
required: ["type", "content"],
|
|
62
|
-
additionalProperties: true,
|
|
63
|
-
properties: {
|
|
64
|
-
type: {
|
|
65
|
-
enum: ["me"],
|
|
66
|
-
},
|
|
67
|
-
content: {
|
|
68
|
-
type: "string",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
person: {
|
|
74
|
-
required: ["id", "type"],
|
|
75
|
-
additionalProperties: true,
|
|
76
|
-
properties: {
|
|
77
|
-
id: {
|
|
78
|
-
type: "string",
|
|
79
|
-
},
|
|
80
|
-
type: {
|
|
81
|
-
enum: ["person"],
|
|
82
|
-
},
|
|
83
|
-
name: {
|
|
84
|
-
type: "string",
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
room: {
|
|
90
|
-
required: ["id", "type"],
|
|
91
|
-
additionalProperties: true,
|
|
92
|
-
properties: {
|
|
93
|
-
id: {
|
|
94
|
-
type: "string",
|
|
95
|
-
},
|
|
96
|
-
type: {
|
|
97
|
-
enum: ["room"],
|
|
98
|
-
},
|
|
99
|
-
name: {
|
|
100
|
-
type: "string",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
service: {
|
|
106
|
-
required: ["id", "type"],
|
|
107
|
-
additionalProperties: true,
|
|
108
|
-
properties: {
|
|
109
|
-
id: {
|
|
110
|
-
type: "string",
|
|
111
|
-
},
|
|
112
|
-
type: {
|
|
113
|
-
enum: ["service"],
|
|
114
|
-
},
|
|
115
|
-
name: {
|
|
116
|
-
type: "string",
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
website: {
|
|
122
|
-
required: ["id", "type"],
|
|
123
|
-
additionalProperties: true,
|
|
124
|
-
properties: {
|
|
125
|
-
id: {
|
|
126
|
-
type: "string",
|
|
127
|
-
format: "iri",
|
|
128
|
-
},
|
|
129
|
-
type: {
|
|
130
|
-
enum: ["website"],
|
|
131
|
-
},
|
|
132
|
-
name: {
|
|
133
|
-
type: "string",
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
attendance: {
|
|
139
|
-
required: ["type"],
|
|
140
|
-
additionalProperties: false,
|
|
141
|
-
properties: {
|
|
142
|
-
type: {
|
|
143
|
-
enum: ["attendance"],
|
|
144
|
-
},
|
|
145
|
-
members: {
|
|
146
|
-
type: "array",
|
|
147
|
-
items: {
|
|
148
|
-
type: "string",
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
presence: {
|
|
155
|
-
required: ["type"],
|
|
156
|
-
additionalProperties: false,
|
|
157
|
-
properties: {
|
|
158
|
-
type: {
|
|
159
|
-
enum: ["presence"],
|
|
160
|
-
},
|
|
161
|
-
presence: {
|
|
162
|
-
enum: ["away", "chat", "dnd", "xa", "offline", "online"],
|
|
163
|
-
},
|
|
164
|
-
role: {
|
|
165
|
-
enum: ["owner", "member", "participant", "admin"],
|
|
166
|
-
},
|
|
167
|
-
content: {
|
|
168
|
-
type: "string",
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
// inspired by https://www.w3.org/ns/activitystreams#Relationship
|
|
174
|
-
relationship: {
|
|
175
|
-
required: ["type", "relationship"],
|
|
176
|
-
additionalProperties: false,
|
|
177
|
-
properties: {
|
|
178
|
-
type: {
|
|
179
|
-
enum: ["relationship"],
|
|
180
|
-
},
|
|
181
|
-
relationship: {
|
|
182
|
-
enum: ["role"],
|
|
183
|
-
},
|
|
184
|
-
subject: {
|
|
185
|
-
type: "object",
|
|
186
|
-
oneOf: [{ $ref: "#/definitions/type/presence" }],
|
|
187
|
-
},
|
|
188
|
-
object: {
|
|
189
|
-
type: "object",
|
|
190
|
-
oneOf: validObjectRefs,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
topic: {
|
|
196
|
-
required: ["type"],
|
|
197
|
-
additionalProperties: false,
|
|
198
|
-
properties: {
|
|
199
|
-
type: {
|
|
200
|
-
enum: ["topic"],
|
|
201
|
-
},
|
|
202
|
-
content: {
|
|
203
|
-
type: "string",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
address: {
|
|
209
|
-
required: ["type"],
|
|
210
|
-
additionalProperties: false,
|
|
211
|
-
properties: {
|
|
212
|
-
type: {
|
|
213
|
-
enum: ["address"],
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
export const ObjectTypesList = Object.keys(ObjectTypesSchema);
|
|
220
|
-
|
|
221
|
-
for (const type of ObjectTypesList) {
|
|
222
|
-
if (type === "credentials") {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
|
|
226
|
-
validObjectDefs[type] = ObjectTypesSchema[type];
|
|
227
|
-
}
|