@sockethub/schemas 3.0.0-alpha.11 → 3.0.0-alpha.13
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/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/error-parser.d.ts +13 -0
- package/dist/helpers/objects.d.ts +122 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +459 -216
- package/dist/index.js.map +12 -11
- package/dist/maps/context-map.json +35 -0
- package/dist/object-types.d.ts +2 -0
- package/dist/object-types.js +296 -0
- package/dist/object-types.js.map +12 -0
- package/dist/schemas/activity-stream.d.ts +161 -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 +103 -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 +43 -0
- package/dist/schemas/platform/xmpp/v1/messages.schema.json +129 -0
- package/dist/schemas/platform.d.ts +62 -0
- package/dist/schemas/sockethub-config.d.ts +261 -0
- package/{src/types.ts → dist/types.d.ts} +25 -46
- package/dist/validator.d.ts +26 -0
- package/package.json +17 -7
- 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 -29
- package/src/schemas/activity-object.ts +0 -19
- package/src/schemas/activity-stream.ts +0 -54
- package/src/schemas/json/activity-object.json +0 -356
- 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 -222
- package/src/schemas/platform.ts +0 -47
- package/src/schemas/sockethub-config.ts +0 -206
- package/src/validator.ts +0 -87
package/src/schemas/platform.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of Sockethub.
|
|
3
|
-
*
|
|
4
|
-
* Developed by Nick Jennings (https://github.com/silverbucket)
|
|
5
|
-
*
|
|
6
|
-
* server is licensed under the LGPL.
|
|
7
|
-
* See the LICENSE file for details.
|
|
8
|
-
*
|
|
9
|
-
* The latest version of server can be found here:
|
|
10
|
-
* git://github.com/sockethub/sockethub.git
|
|
11
|
-
*
|
|
12
|
-
* For more information about Sockethub visit https://sockethub.org/.
|
|
13
|
-
*
|
|
14
|
-
* This program is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
// this schema defines the general structure of the schema object which should
|
|
20
|
-
// be returned from platforms.
|
|
21
|
-
export const PlatformSchema = {
|
|
22
|
-
$id: "https://sockethub.org/schemas/v/platform.json",
|
|
23
|
-
type: "object",
|
|
24
|
-
required: ["name", "version", "messages"],
|
|
25
|
-
additionalProperties: false,
|
|
26
|
-
properties: {
|
|
27
|
-
credentials: {
|
|
28
|
-
title: "credentials",
|
|
29
|
-
type: "object",
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
messages: {
|
|
33
|
-
title: "messages",
|
|
34
|
-
type: "object",
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
name: {
|
|
38
|
-
title: "name",
|
|
39
|
-
type: "string",
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
version: {
|
|
43
|
-
title: "version",
|
|
44
|
-
type: "string",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
const connectConfigPlatforms = {
|
|
2
|
-
connectTimeoutMs: {
|
|
3
|
-
type: "number",
|
|
4
|
-
},
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const SockethubConfigSchema = {
|
|
8
|
-
$id: "https://sockethub.org/schemas/v/sockethub-config.json",
|
|
9
|
-
description: "Sockethub Config Schema",
|
|
10
|
-
type: "object",
|
|
11
|
-
required: ["platforms"],
|
|
12
|
-
additionalProperties: false,
|
|
13
|
-
properties: {
|
|
14
|
-
$schema: {
|
|
15
|
-
type: "string",
|
|
16
|
-
},
|
|
17
|
-
examples: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
default: true,
|
|
20
|
-
},
|
|
21
|
-
logging: {
|
|
22
|
-
type: "object",
|
|
23
|
-
additionalProperties: false,
|
|
24
|
-
properties: {
|
|
25
|
-
level: {
|
|
26
|
-
type: "string",
|
|
27
|
-
enum: ["error", "warn", "info", "debug"],
|
|
28
|
-
default: "info",
|
|
29
|
-
},
|
|
30
|
-
fileLevel: {
|
|
31
|
-
type: "string",
|
|
32
|
-
enum: ["error", "warn", "info", "debug"],
|
|
33
|
-
default: "debug",
|
|
34
|
-
},
|
|
35
|
-
file: {
|
|
36
|
-
type: "string",
|
|
37
|
-
default: "sockethub.log",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
packageConfig: {
|
|
42
|
-
type: "object",
|
|
43
|
-
properties: {
|
|
44
|
-
"@sockethub/activity-streams": {
|
|
45
|
-
type: "object",
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
properties: {
|
|
48
|
-
specialObjs: {
|
|
49
|
-
type: "array",
|
|
50
|
-
items: {
|
|
51
|
-
type: "string",
|
|
52
|
-
},
|
|
53
|
-
default: ["credentials"],
|
|
54
|
-
},
|
|
55
|
-
failOnUnknownObjectProperties: {
|
|
56
|
-
type: "boolean",
|
|
57
|
-
default: true,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
"@sockethub/platform-dummy": {
|
|
62
|
-
type: "object",
|
|
63
|
-
additionalProperties: false,
|
|
64
|
-
properties: {
|
|
65
|
-
greeting: {
|
|
66
|
-
type: "string",
|
|
67
|
-
default: "Hello",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
"@sockethub/platform-feeds": {
|
|
72
|
-
type: "object",
|
|
73
|
-
additionalProperties: false,
|
|
74
|
-
properties: {
|
|
75
|
-
...connectConfigPlatforms,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
"@sockethub/platform-irc": {
|
|
79
|
-
type: "object",
|
|
80
|
-
additionalProperties: false,
|
|
81
|
-
properties: {
|
|
82
|
-
...connectConfigPlatforms,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
"@sockethub/platform-xmpp": {
|
|
86
|
-
type: "object",
|
|
87
|
-
additionalProperties: false,
|
|
88
|
-
properties: {
|
|
89
|
-
...connectConfigPlatforms,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
platforms: {
|
|
95
|
-
type: "array",
|
|
96
|
-
items: {
|
|
97
|
-
type: "string",
|
|
98
|
-
},
|
|
99
|
-
default: [
|
|
100
|
-
"@sockethub/platform-dummy",
|
|
101
|
-
"@sockethub/platform-feeds",
|
|
102
|
-
"@sockethub/platform-irc",
|
|
103
|
-
"@sockethub/platform-metadata",
|
|
104
|
-
"@sockethub/platform-xmpp",
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
public: {
|
|
108
|
-
type: "object",
|
|
109
|
-
additionalProperties: false,
|
|
110
|
-
properties: {
|
|
111
|
-
protocol: {
|
|
112
|
-
type: "string",
|
|
113
|
-
default: "http",
|
|
114
|
-
},
|
|
115
|
-
host: {
|
|
116
|
-
type: "string",
|
|
117
|
-
default: "localhost",
|
|
118
|
-
},
|
|
119
|
-
port: {
|
|
120
|
-
type: "number",
|
|
121
|
-
default: 10550,
|
|
122
|
-
},
|
|
123
|
-
path: {
|
|
124
|
-
type: "string",
|
|
125
|
-
default: "/",
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
rateLimiter: {
|
|
130
|
-
type: "object",
|
|
131
|
-
additionalProperties: false,
|
|
132
|
-
properties: {
|
|
133
|
-
windowMs: {
|
|
134
|
-
type: "number",
|
|
135
|
-
default: 1000,
|
|
136
|
-
},
|
|
137
|
-
maxRequests: {
|
|
138
|
-
type: "number",
|
|
139
|
-
default: 100,
|
|
140
|
-
},
|
|
141
|
-
blockDurationMs: {
|
|
142
|
-
type: "number",
|
|
143
|
-
default: 5000,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
redis: {
|
|
148
|
-
type: "object",
|
|
149
|
-
additionalProperties: false,
|
|
150
|
-
properties: {
|
|
151
|
-
url: {
|
|
152
|
-
type: "string",
|
|
153
|
-
default: "redis://127.0.0.1:6379",
|
|
154
|
-
},
|
|
155
|
-
connectTimeout: {
|
|
156
|
-
type: "number",
|
|
157
|
-
default: 10000,
|
|
158
|
-
description: "Connection timeout in milliseconds",
|
|
159
|
-
},
|
|
160
|
-
disconnectTimeout: {
|
|
161
|
-
type: "number",
|
|
162
|
-
default: 5000,
|
|
163
|
-
description: "Disconnect timeout in milliseconds",
|
|
164
|
-
},
|
|
165
|
-
maxRetriesPerRequest: {
|
|
166
|
-
type: ["number", "null"],
|
|
167
|
-
default: null,
|
|
168
|
-
description:
|
|
169
|
-
"Maximum number of retries per request (null for BullMQ default)",
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
sentry: {
|
|
174
|
-
type: "object",
|
|
175
|
-
additionalProperties: false,
|
|
176
|
-
properties: {
|
|
177
|
-
dsn: {
|
|
178
|
-
type: "string",
|
|
179
|
-
default: "",
|
|
180
|
-
},
|
|
181
|
-
traceSampleRate: {
|
|
182
|
-
type: "number",
|
|
183
|
-
default: 1.0,
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
sockethub: {
|
|
188
|
-
type: "object",
|
|
189
|
-
additionalProperties: false,
|
|
190
|
-
properties: {
|
|
191
|
-
port: {
|
|
192
|
-
type: "number",
|
|
193
|
-
default: 10550,
|
|
194
|
-
},
|
|
195
|
-
host: {
|
|
196
|
-
type: "string",
|
|
197
|
-
default: "localhost",
|
|
198
|
-
},
|
|
199
|
-
path: {
|
|
200
|
-
type: "string",
|
|
201
|
-
default: "/sockethub",
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
};
|
package/src/validator.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import Ajv, { type Schema } from "ajv";
|
|
2
|
-
import addFormats from "ajv-formats";
|
|
3
|
-
import additionsFormats2019 from "ajv-formats-draft2019";
|
|
4
|
-
import getErrorMessage from "./helpers/error-parser.js";
|
|
5
|
-
import { ActivityObjectSchema } from "./schemas/activity-object.js";
|
|
6
|
-
import { ActivityStreamSchema } from "./schemas/activity-stream.js";
|
|
7
|
-
import { PlatformSchema } from "./schemas/platform.js";
|
|
8
|
-
import type { ActivityStream } from "./types.js";
|
|
9
|
-
|
|
10
|
-
const ajv = new Ajv({ strictTypes: false, allErrors: true });
|
|
11
|
-
addFormats(ajv);
|
|
12
|
-
additionsFormats2019(ajv);
|
|
13
|
-
|
|
14
|
-
interface SchemasDict {
|
|
15
|
-
string?: Schema;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const schemaURL = "https://sockethub.org/schemas/v0";
|
|
19
|
-
const schemas: SchemasDict = {};
|
|
20
|
-
|
|
21
|
-
schemas[`${schemaURL}/activity-stream`] = ActivityStreamSchema;
|
|
22
|
-
schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
|
|
23
|
-
|
|
24
|
-
for (const uri in schemas) {
|
|
25
|
-
ajv.addSchema(schemas[uri], uri);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function handleValidation(
|
|
29
|
-
schemaRef: string,
|
|
30
|
-
msg: ActivityStream,
|
|
31
|
-
isObject = false,
|
|
32
|
-
): string {
|
|
33
|
-
const validator = ajv.getSchema(schemaRef);
|
|
34
|
-
let result: boolean | Promise<unknown>;
|
|
35
|
-
if (isObject) {
|
|
36
|
-
result = validator({ object: msg });
|
|
37
|
-
} else {
|
|
38
|
-
result = validator(msg);
|
|
39
|
-
}
|
|
40
|
-
if (!result) {
|
|
41
|
-
let errorMessage = getErrorMessage(msg, validator.errors);
|
|
42
|
-
if (msg.context) {
|
|
43
|
-
errorMessage = `[${msg.context}] ${errorMessage}`;
|
|
44
|
-
}
|
|
45
|
-
return errorMessage;
|
|
46
|
-
}
|
|
47
|
-
return "";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function validateActivityObject(msg: ActivityStream): string {
|
|
51
|
-
return handleValidation(`${schemaURL}/activity-object`, msg, true);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function validateActivityStream(msg: ActivityStream): string {
|
|
55
|
-
return handleValidation(`${schemaURL}/activity-stream`, msg);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function validateCredentials(msg: ActivityStream): string {
|
|
59
|
-
if (!msg.context) {
|
|
60
|
-
return "credential activity streams must have a context set";
|
|
61
|
-
}
|
|
62
|
-
if (msg.type !== "credentials") {
|
|
63
|
-
return "credential activity streams must have credentials set as type";
|
|
64
|
-
}
|
|
65
|
-
return handleValidation(
|
|
66
|
-
`${schemaURL}/context/${msg.context}/credentials`,
|
|
67
|
-
msg,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function validatePlatformSchema(schema: Schema): string {
|
|
72
|
-
const validate = ajv.compile(PlatformSchema);
|
|
73
|
-
// validate schema property
|
|
74
|
-
const err = validate(schema);
|
|
75
|
-
if (!err) {
|
|
76
|
-
return `platform schema failed to validate: ${validate.errors[0].instancePath} ${validate.errors[0].message}`;
|
|
77
|
-
}
|
|
78
|
-
return "";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function addPlatformSchema(schema: Schema, platform_type: string) {
|
|
82
|
-
ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function getPlatformSchema(platform_type: string) {
|
|
86
|
-
return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
|
|
87
|
-
}
|