@sockethub/schemas 3.0.0-alpha.3

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.
Files changed (43) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +11 -0
  3. package/dist/helpers/error-parser.d.ts +9 -0
  4. package/dist/helpers/error-parser.js +91 -0
  5. package/dist/helpers/objects.d.ts +206 -0
  6. package/dist/helpers/objects.js +217 -0
  7. package/dist/index.d.ts +15 -0
  8. package/dist/index.js +22 -0
  9. package/dist/index.test.data.credentials.d.ts +37 -0
  10. package/dist/index.test.data.credentials.js +69 -0
  11. package/dist/index.test.data.objects.d.ts +50 -0
  12. package/dist/index.test.data.objects.js +214 -0
  13. package/dist/index.test.data.platform.d.ts +44 -0
  14. package/dist/index.test.data.platform.js +47 -0
  15. package/dist/index.test.data.streams.d.ts +256 -0
  16. package/dist/index.test.data.streams.js +449 -0
  17. package/dist/schemas/activity-object.d.ts +16 -0
  18. package/dist/schemas/activity-object.js +18 -0
  19. package/dist/schemas/activity-stream.d.ts +235 -0
  20. package/dist/schemas/activity-stream.js +49 -0
  21. package/dist/schemas/json/activity-object.json +356 -0
  22. package/dist/schemas/json/activity-stream.json +465 -0
  23. package/dist/schemas/json/platform.json +27 -0
  24. package/dist/schemas/platform.d.ts +41 -0
  25. package/dist/schemas/platform.js +44 -0
  26. package/dist/types.d.ts +20 -0
  27. package/dist/types.js +2 -0
  28. package/dist/validator.d.ts +8 -0
  29. package/dist/validator.js +78 -0
  30. package/package.json +58 -0
  31. package/src/helpers/error-parser.ts +99 -0
  32. package/src/helpers/objects.ts +230 -0
  33. package/src/index.test.data.credentials.ts +71 -0
  34. package/src/index.test.data.objects.ts +235 -0
  35. package/src/index.test.data.platform.ts +45 -0
  36. package/src/index.test.data.streams.ts +470 -0
  37. package/src/index.test.ts +84 -0
  38. package/src/index.ts +26 -0
  39. package/src/schemas/activity-object.ts +19 -0
  40. package/src/schemas/activity-stream.ts +51 -0
  41. package/src/schemas/platform.ts +47 -0
  42. package/src/types.ts +23 -0
  43. package/src/validator.ts +79 -0
@@ -0,0 +1,465 @@
1
+ {
2
+ "$id": "https://sockethub.org/schemas/v0/activity-stream#",
3
+ "description": "Schema for Sockethub Activity Streams",
4
+ "type": "object",
5
+ "required": [
6
+ "context",
7
+ "type",
8
+ "actor"
9
+ ],
10
+ "properties": {
11
+ "id": {
12
+ "type": "string"
13
+ },
14
+ "type": {
15
+ "type": "string"
16
+ },
17
+ "context": {
18
+ "type": "string"
19
+ },
20
+ "actor": {
21
+ "type": "object",
22
+ "oneOf": [
23
+ {
24
+ "$ref": "#/definitions/type/feed"
25
+ },
26
+ {
27
+ "$ref": "#/definitions/type/message"
28
+ },
29
+ {
30
+ "$ref": "#/definitions/type/me"
31
+ },
32
+ {
33
+ "$ref": "#/definitions/type/person"
34
+ },
35
+ {
36
+ "$ref": "#/definitions/type/room"
37
+ },
38
+ {
39
+ "$ref": "#/definitions/type/service"
40
+ },
41
+ {
42
+ "$ref": "#/definitions/type/website"
43
+ },
44
+ {
45
+ "$ref": "#/definitions/type/attendance"
46
+ },
47
+ {
48
+ "$ref": "#/definitions/type/presence"
49
+ },
50
+ {
51
+ "$ref": "#/definitions/type/relationship"
52
+ },
53
+ {
54
+ "$ref": "#/definitions/type/topic"
55
+ },
56
+ {
57
+ "$ref": "#/definitions/type/address"
58
+ }
59
+ ]
60
+ },
61
+ "target": {
62
+ "type": "object",
63
+ "oneOf": [
64
+ {
65
+ "$ref": "#/definitions/type/feed"
66
+ },
67
+ {
68
+ "$ref": "#/definitions/type/message"
69
+ },
70
+ {
71
+ "$ref": "#/definitions/type/me"
72
+ },
73
+ {
74
+ "$ref": "#/definitions/type/person"
75
+ },
76
+ {
77
+ "$ref": "#/definitions/type/room"
78
+ },
79
+ {
80
+ "$ref": "#/definitions/type/service"
81
+ },
82
+ {
83
+ "$ref": "#/definitions/type/website"
84
+ },
85
+ {
86
+ "$ref": "#/definitions/type/attendance"
87
+ },
88
+ {
89
+ "$ref": "#/definitions/type/presence"
90
+ },
91
+ {
92
+ "$ref": "#/definitions/type/relationship"
93
+ },
94
+ {
95
+ "$ref": "#/definitions/type/topic"
96
+ },
97
+ {
98
+ "$ref": "#/definitions/type/address"
99
+ }
100
+ ]
101
+ },
102
+ "object": {
103
+ "type": "object",
104
+ "oneOf": [
105
+ {
106
+ "$ref": "#/definitions/type/credentials"
107
+ },
108
+ {
109
+ "$ref": "#/definitions/type/feed"
110
+ },
111
+ {
112
+ "$ref": "#/definitions/type/message"
113
+ },
114
+ {
115
+ "$ref": "#/definitions/type/me"
116
+ },
117
+ {
118
+ "$ref": "#/definitions/type/person"
119
+ },
120
+ {
121
+ "$ref": "#/definitions/type/room"
122
+ },
123
+ {
124
+ "$ref": "#/definitions/type/service"
125
+ },
126
+ {
127
+ "$ref": "#/definitions/type/website"
128
+ },
129
+ {
130
+ "$ref": "#/definitions/type/attendance"
131
+ },
132
+ {
133
+ "$ref": "#/definitions/type/presence"
134
+ },
135
+ {
136
+ "$ref": "#/definitions/type/relationship"
137
+ },
138
+ {
139
+ "$ref": "#/definitions/type/topic"
140
+ },
141
+ {
142
+ "$ref": "#/definitions/type/address"
143
+ }
144
+ ]
145
+ }
146
+ },
147
+ "definitions": {
148
+ "type": {
149
+ "credentials": {
150
+ "required": [
151
+ "type"
152
+ ],
153
+ "additionalProperties": true,
154
+ "properties": {
155
+ "type": {
156
+ "enum": [
157
+ "credentials"
158
+ ]
159
+ }
160
+ }
161
+ },
162
+ "feed": {
163
+ "required": [
164
+ "id",
165
+ "type"
166
+ ],
167
+ "additionalProperties": true,
168
+ "properties": {
169
+ "type": {
170
+ "enum": [
171
+ "feed"
172
+ ]
173
+ },
174
+ "id": {
175
+ "type": "string",
176
+ "format": "iri"
177
+ },
178
+ "name": {
179
+ "type": "string"
180
+ },
181
+ "description": {
182
+ "type": "string"
183
+ },
184
+ "author": {
185
+ "type": "string"
186
+ },
187
+ "favicon": {
188
+ "type": "string"
189
+ }
190
+ }
191
+ },
192
+ "message": {
193
+ "required": [
194
+ "type",
195
+ "content"
196
+ ],
197
+ "additionalProperties": true,
198
+ "properties": {
199
+ "type": {
200
+ "enum": [
201
+ "message"
202
+ ]
203
+ },
204
+ "id": {
205
+ "type": "string"
206
+ },
207
+ "name": {
208
+ "type": "string"
209
+ },
210
+ "content": {
211
+ "type": "string"
212
+ }
213
+ }
214
+ },
215
+ "me": {
216
+ "required": [
217
+ "type",
218
+ "content"
219
+ ],
220
+ "additionalProperties": true,
221
+ "properties": {
222
+ "type": {
223
+ "enum": [
224
+ "me"
225
+ ]
226
+ },
227
+ "content": {
228
+ "type": "string"
229
+ }
230
+ }
231
+ },
232
+ "person": {
233
+ "required": [
234
+ "id",
235
+ "type"
236
+ ],
237
+ "additionalProperties": true,
238
+ "properties": {
239
+ "id": {
240
+ "type": "string"
241
+ },
242
+ "type": {
243
+ "enum": [
244
+ "person"
245
+ ]
246
+ },
247
+ "name": {
248
+ "type": "string"
249
+ }
250
+ }
251
+ },
252
+ "room": {
253
+ "required": [
254
+ "id",
255
+ "type"
256
+ ],
257
+ "additionalProperties": true,
258
+ "properties": {
259
+ "id": {
260
+ "type": "string"
261
+ },
262
+ "type": {
263
+ "enum": [
264
+ "room"
265
+ ]
266
+ },
267
+ "name": {
268
+ "type": "string"
269
+ }
270
+ }
271
+ },
272
+ "service": {
273
+ "required": [
274
+ "id",
275
+ "type"
276
+ ],
277
+ "additionalProperties": true,
278
+ "properties": {
279
+ "id": {
280
+ "type": "string"
281
+ },
282
+ "type": {
283
+ "enum": [
284
+ "service"
285
+ ]
286
+ },
287
+ "name": {
288
+ "type": "string"
289
+ }
290
+ }
291
+ },
292
+ "website": {
293
+ "required": [
294
+ "id",
295
+ "type"
296
+ ],
297
+ "additionalProperties": true,
298
+ "properties": {
299
+ "id": {
300
+ "type": "string",
301
+ "format": "iri"
302
+ },
303
+ "type": {
304
+ "enum": [
305
+ "website"
306
+ ]
307
+ },
308
+ "name": {
309
+ "type": "string"
310
+ }
311
+ }
312
+ },
313
+ "attendance": {
314
+ "required": [
315
+ "type"
316
+ ],
317
+ "additionalProperties": false,
318
+ "properties": {
319
+ "type": {
320
+ "enum": [
321
+ "attendance"
322
+ ]
323
+ },
324
+ "members": {
325
+ "type": "array",
326
+ "items": {
327
+ "type": "string"
328
+ }
329
+ }
330
+ }
331
+ },
332
+ "presence": {
333
+ "required": [
334
+ "type"
335
+ ],
336
+ "additionalProperties": false,
337
+ "properties": {
338
+ "type": {
339
+ "enum": [
340
+ "presence"
341
+ ]
342
+ },
343
+ "presence": {
344
+ "enum": [
345
+ "away",
346
+ "chat",
347
+ "dnd",
348
+ "xa",
349
+ "offline",
350
+ "online"
351
+ ]
352
+ },
353
+ "role": {
354
+ "enum": [
355
+ "owner",
356
+ "member",
357
+ "participant",
358
+ "admin"
359
+ ]
360
+ },
361
+ "content": {
362
+ "type": "string"
363
+ }
364
+ }
365
+ },
366
+ "relationship": {
367
+ "required": [
368
+ "type",
369
+ "relationship"
370
+ ],
371
+ "additionalProperties": false,
372
+ "properties": {
373
+ "type": {
374
+ "enum": [
375
+ "relationship"
376
+ ]
377
+ },
378
+ "relationship": {
379
+ "enum": [
380
+ "role"
381
+ ]
382
+ },
383
+ "subject": {
384
+ "type": "object",
385
+ "oneOf": [
386
+ {
387
+ "$ref": "#/definitions/type/presence"
388
+ }
389
+ ]
390
+ },
391
+ "object": {
392
+ "type": "object",
393
+ "oneOf": [
394
+ {
395
+ "$ref": "#/definitions/type/feed"
396
+ },
397
+ {
398
+ "$ref": "#/definitions/type/message"
399
+ },
400
+ {
401
+ "$ref": "#/definitions/type/me"
402
+ },
403
+ {
404
+ "$ref": "#/definitions/type/person"
405
+ },
406
+ {
407
+ "$ref": "#/definitions/type/room"
408
+ },
409
+ {
410
+ "$ref": "#/definitions/type/service"
411
+ },
412
+ {
413
+ "$ref": "#/definitions/type/website"
414
+ },
415
+ {
416
+ "$ref": "#/definitions/type/attendance"
417
+ },
418
+ {
419
+ "$ref": "#/definitions/type/presence"
420
+ },
421
+ {
422
+ "$ref": "#/definitions/type/relationship"
423
+ },
424
+ {
425
+ "$ref": "#/definitions/type/topic"
426
+ },
427
+ {
428
+ "$ref": "#/definitions/type/address"
429
+ }
430
+ ]
431
+ }
432
+ }
433
+ },
434
+ "topic": {
435
+ "required": [
436
+ "type"
437
+ ],
438
+ "additionalProperties": false,
439
+ "properties": {
440
+ "type": {
441
+ "enum": [
442
+ "topic"
443
+ ]
444
+ },
445
+ "content": {
446
+ "type": "string"
447
+ }
448
+ }
449
+ },
450
+ "address": {
451
+ "required": [
452
+ "type"
453
+ ],
454
+ "additionalProperties": false,
455
+ "properties": {
456
+ "type": {
457
+ "enum": [
458
+ "address"
459
+ ]
460
+ }
461
+ }
462
+ }
463
+ }
464
+ }
465
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "type": "object",
3
+ "required": [
4
+ "name",
5
+ "version",
6
+ "messages"
7
+ ],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "credentials": {
11
+ "title": "credentials",
12
+ "type": "object"
13
+ },
14
+ "messages": {
15
+ "title": "messages",
16
+ "type": "object"
17
+ },
18
+ "name": {
19
+ "title": "name",
20
+ "type": "string"
21
+ },
22
+ "version": {
23
+ "title": "version",
24
+ "type": "string"
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,41 @@
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
+ declare const _default: {
19
+ type: string;
20
+ required: string[];
21
+ additionalProperties: boolean;
22
+ properties: {
23
+ credentials: {
24
+ title: string;
25
+ type: string;
26
+ };
27
+ messages: {
28
+ title: string;
29
+ type: string;
30
+ };
31
+ name: {
32
+ title: string;
33
+ type: string;
34
+ };
35
+ version: {
36
+ title: string;
37
+ type: string;
38
+ };
39
+ };
40
+ };
41
+ export default _default;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * This file is part of Sockethub.
4
+ *
5
+ * Developed by Nick Jennings (https://github.com/silverbucket)
6
+ *
7
+ * server is licensed under the LGPL.
8
+ * See the LICENSE file for details.
9
+ *
10
+ * The latest version of server can be found here:
11
+ * git://github.com/sockethub/sockethub.git
12
+ *
13
+ * For more information about Sockethub visit https://sockethub.org/.
14
+ *
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ // this schema defines the general structure of the schema object which should
21
+ // be returned from platforms.
22
+ exports.default = {
23
+ 'type': 'object',
24
+ 'required': ['name', 'version', 'messages'],
25
+ 'additionalProperties': false,
26
+ 'properties': {
27
+ 'credentials': {
28
+ 'title': 'credentials',
29
+ 'type': 'object'
30
+ },
31
+ 'messages': {
32
+ 'title': 'messages',
33
+ 'type': 'object',
34
+ },
35
+ 'name': {
36
+ 'title': 'name',
37
+ 'type': 'string',
38
+ },
39
+ 'version': {
40
+ 'title': 'version',
41
+ 'type': 'string',
42
+ }
43
+ }
44
+ };
@@ -0,0 +1,20 @@
1
+ export interface IActivityStream {
2
+ type: string;
3
+ context: string;
4
+ actor: IActivityObjectActor;
5
+ object?: IActivityObjectObject;
6
+ target?: IActivityObjectActor;
7
+ error?: string;
8
+ sessionSecret?: string;
9
+ }
10
+ export interface IActivityObject {
11
+ id?: string;
12
+ type: string;
13
+ }
14
+ export interface IActivityObjectActor extends IActivityObject {
15
+ id: string;
16
+ name?: string;
17
+ }
18
+ export interface IActivityObjectObject extends IActivityObject {
19
+ content?: any;
20
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { Schema } from 'ajv';
2
+ import { IActivityStream } from "./types";
3
+ export declare function validateActivityObject(msg: IActivityStream): string;
4
+ export declare function validateActivityStream(msg: IActivityStream): string;
5
+ export declare function validateCredentials(msg: IActivityStream): string;
6
+ export declare function validatePlatformSchema(schema: Schema): string;
7
+ export declare function addPlatformSchema(schema: Schema, platform_type: string): void;
8
+ export declare function getPlatformSchema(platform_type: string): import("ajv/dist/types").AnyValidateFunction<unknown>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPlatformSchema = exports.addPlatformSchema = exports.validatePlatformSchema = exports.validateCredentials = exports.validateActivityStream = exports.validateActivityObject = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const ajv_1 = __importDefault(require("ajv"));
9
+ const ajv_formats_draft2019_1 = __importDefault(require("ajv-formats-draft2019"));
10
+ const error_parser_1 = __importDefault(require("./helpers/error-parser"));
11
+ const platform_1 = __importDefault(require("./schemas/platform"));
12
+ const activity_stream_1 = __importDefault(require("./schemas/activity-stream"));
13
+ const activity_object_1 = __importDefault(require("./schemas/activity-object"));
14
+ const log = (0, debug_1.default)('sockethub:schemas');
15
+ const ajv = new ajv_1.default({ strictTypes: false, allErrors: true });
16
+ (0, ajv_formats_draft2019_1.default)(ajv);
17
+ const schemaURL = 'https://sockethub.org/schemas/v0';
18
+ const schemas = {};
19
+ schemas[`${schemaURL}/activity-stream`] = activity_stream_1.default;
20
+ schemas[`${schemaURL}/activity-object`] = activity_object_1.default;
21
+ for (let uri in schemas) {
22
+ log(`registering schema ${uri}`);
23
+ ajv.addSchema(schemas[uri], uri);
24
+ }
25
+ function handleValidation(schemaRef, msg, isObject = false) {
26
+ const validator = ajv.getSchema(schemaRef);
27
+ let result;
28
+ if (isObject) {
29
+ result = validator({ object: msg });
30
+ }
31
+ else {
32
+ result = validator(msg);
33
+ }
34
+ if (!result) {
35
+ return (0, error_parser_1.default)(msg, validator.errors);
36
+ }
37
+ return "";
38
+ }
39
+ function validateActivityObject(msg) {
40
+ return handleValidation(`${schemaURL}/activity-object`, msg, true);
41
+ }
42
+ exports.validateActivityObject = validateActivityObject;
43
+ function validateActivityStream(msg) {
44
+ return handleValidation(`${schemaURL}/activity-stream`, msg);
45
+ }
46
+ exports.validateActivityStream = validateActivityStream;
47
+ function validateCredentials(msg) {
48
+ if (!msg.context) {
49
+ return 'credential activity streams must have a context set';
50
+ }
51
+ if (msg.type !== 'credentials') {
52
+ return 'credential activity streams must have credentials set as type';
53
+ }
54
+ return handleValidation(`${schemaURL}/context/${msg.context}/credentials`, msg);
55
+ }
56
+ exports.validateCredentials = validateCredentials;
57
+ function validatePlatformSchema(schema) {
58
+ const validate = ajv.compile(platform_1.default);
59
+ // validate schema property
60
+ const err = validate(schema);
61
+ if (!err) {
62
+ return `platform schema failed to validate: ` +
63
+ `${validate.errors[0].instancePath} ${validate.errors[0].message}`;
64
+ }
65
+ else {
66
+ return "";
67
+ }
68
+ }
69
+ exports.validatePlatformSchema = validatePlatformSchema;
70
+ function addPlatformSchema(schema, platform_type) {
71
+ log(`registering schema ${schemaURL}/context/${platform_type}`);
72
+ ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
73
+ }
74
+ exports.addPlatformSchema = addPlatformSchema;
75
+ function getPlatformSchema(platform_type) {
76
+ return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
77
+ }
78
+ exports.getPlatformSchema = getPlatformSchema;