@sockethub/schemas 3.0.0-alpha.4 → 3.0.0-alpha.5

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/package.json +16 -32
  2. package/src/index.ts +23 -19
  3. package/src/schemas/activity-object.ts +15 -15
  4. package/src/schemas/activity-stream.ts +40 -41
  5. package/{dist → src}/schemas/json/activity-object.json +1 -1
  6. package/{dist → src}/schemas/json/activity-stream.json +1 -1
  7. package/{dist → src}/schemas/json/platform.json +1 -0
  8. package/src/schemas/json/sockethub-config.json +144 -0
  9. package/src/schemas/platform.ts +22 -22
  10. package/src/schemas/sockethub-config.ts +140 -0
  11. package/dist/helpers/error-parser.d.ts +0 -9
  12. package/dist/helpers/error-parser.js +0 -90
  13. package/dist/helpers/objects.d.ts +0 -206
  14. package/dist/helpers/objects.js +0 -217
  15. package/dist/index.d.ts +0 -15
  16. package/dist/index.js +0 -37
  17. package/dist/index.test.data.credentials.d.ts +0 -37
  18. package/dist/index.test.data.credentials.js +0 -69
  19. package/dist/index.test.data.objects.d.ts +0 -50
  20. package/dist/index.test.data.objects.js +0 -214
  21. package/dist/index.test.data.platform.d.ts +0 -44
  22. package/dist/index.test.data.platform.js +0 -47
  23. package/dist/index.test.data.streams.d.ts +0 -274
  24. package/dist/index.test.data.streams.js +0 -473
  25. package/dist/schemas/activity-object.d.ts +0 -16
  26. package/dist/schemas/activity-object.js +0 -18
  27. package/dist/schemas/activity-stream.d.ts +0 -239
  28. package/dist/schemas/activity-stream.js +0 -53
  29. package/dist/schemas/platform.d.ts +0 -41
  30. package/dist/schemas/platform.js +0 -44
  31. package/dist/types.d.ts +0 -34
  32. package/dist/types.js +0 -2
  33. package/dist/validator.d.ts +0 -8
  34. package/dist/validator.js +0 -80
  35. package/src/helpers/error-parser.ts +0 -96
  36. package/src/helpers/objects.ts +0 -230
  37. package/src/index.test.data.credentials.ts +0 -71
  38. package/src/index.test.data.objects.ts +0 -235
  39. package/src/index.test.data.platform.ts +0 -45
  40. package/src/index.test.data.streams.ts +0 -495
  41. package/src/index.test.ts +0 -85
  42. package/src/types.ts +0 -42
  43. package/src/validator.ts +0 -81
@@ -1,239 +0,0 @@
1
- declare const _default: {
2
- $id: string;
3
- description: string;
4
- type: string;
5
- required: string[];
6
- properties: {
7
- id: {
8
- type: string;
9
- };
10
- type: {
11
- type: string;
12
- };
13
- context: {
14
- type: string;
15
- };
16
- actor: {
17
- type: string;
18
- oneOf: any[];
19
- };
20
- target: {
21
- type: string;
22
- oneOf: any[];
23
- };
24
- object: {
25
- type: string;
26
- oneOf: any[];
27
- };
28
- published: {
29
- type: string;
30
- format: string;
31
- };
32
- };
33
- definitions: {
34
- type: {
35
- credentials: {
36
- required: string[];
37
- additionalProperties: boolean;
38
- properties: {
39
- type: {
40
- enum: string[];
41
- };
42
- };
43
- };
44
- feed: {
45
- required: string[];
46
- additionalProperties: boolean;
47
- properties: {
48
- type: {
49
- enum: string[];
50
- };
51
- id: {
52
- type: string;
53
- format: string;
54
- };
55
- name: {
56
- type: string;
57
- };
58
- description: {
59
- type: string;
60
- };
61
- author: {
62
- type: string;
63
- };
64
- favicon: {
65
- type: string;
66
- };
67
- };
68
- };
69
- message: {
70
- required: string[];
71
- additionalProperties: boolean;
72
- properties: {
73
- type: {
74
- enum: string[];
75
- };
76
- id: {
77
- type: string;
78
- };
79
- name: {
80
- type: string;
81
- };
82
- content: {
83
- type: string;
84
- };
85
- };
86
- };
87
- me: {
88
- required: string[];
89
- additionalProperties: boolean;
90
- properties: {
91
- type: {
92
- enum: string[];
93
- };
94
- content: {
95
- type: string;
96
- };
97
- };
98
- };
99
- person: {
100
- required: string[];
101
- additionalProperties: boolean;
102
- properties: {
103
- id: {
104
- type: string;
105
- };
106
- type: {
107
- enum: string[];
108
- };
109
- name: {
110
- type: string;
111
- };
112
- };
113
- };
114
- room: {
115
- required: string[];
116
- additionalProperties: boolean;
117
- properties: {
118
- id: {
119
- type: string;
120
- };
121
- type: {
122
- enum: string[];
123
- };
124
- name: {
125
- type: string;
126
- };
127
- };
128
- };
129
- service: {
130
- required: string[];
131
- additionalProperties: boolean;
132
- properties: {
133
- id: {
134
- type: string;
135
- };
136
- type: {
137
- enum: string[];
138
- };
139
- name: {
140
- type: string;
141
- };
142
- };
143
- };
144
- website: {
145
- required: string[];
146
- additionalProperties: boolean;
147
- properties: {
148
- id: {
149
- type: string;
150
- format: string;
151
- };
152
- type: {
153
- enum: string[];
154
- };
155
- name: {
156
- type: string;
157
- };
158
- };
159
- };
160
- attendance: {
161
- required: string[];
162
- additionalProperties: boolean;
163
- properties: {
164
- type: {
165
- enum: string[];
166
- };
167
- members: {
168
- type: string;
169
- items: {
170
- type: string;
171
- };
172
- };
173
- };
174
- };
175
- presence: {
176
- required: string[];
177
- additionalProperties: boolean;
178
- properties: {
179
- type: {
180
- enum: string[];
181
- };
182
- presence: {
183
- enum: string[];
184
- };
185
- role: {
186
- enum: string[];
187
- };
188
- content: {
189
- type: string;
190
- };
191
- };
192
- };
193
- relationship: {
194
- required: string[];
195
- additionalProperties: boolean;
196
- properties: {
197
- type: {
198
- enum: string[];
199
- };
200
- relationship: {
201
- enum: string[];
202
- };
203
- subject: {
204
- type: string;
205
- oneOf: {
206
- $ref: string;
207
- }[];
208
- };
209
- object: {
210
- type: string;
211
- oneOf: any[];
212
- };
213
- };
214
- };
215
- topic: {
216
- required: string[];
217
- additionalProperties: boolean;
218
- properties: {
219
- type: {
220
- enum: string[];
221
- };
222
- content: {
223
- type: string;
224
- };
225
- };
226
- };
227
- address: {
228
- required: string[];
229
- additionalProperties: boolean;
230
- properties: {
231
- type: {
232
- enum: string[];
233
- };
234
- };
235
- };
236
- };
237
- };
238
- };
239
- export default _default;
@@ -1,53 +0,0 @@
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
- const activity_object_1 = __importDefault(require("./activity-object"));
7
- const objects_1 = require("../helpers/objects");
8
- const validActorRefs = activity_object_1.default.properties.object.oneOf;
9
- const validTargetRefs = activity_object_1.default.properties.object.oneOf;
10
- // eslint-disable-next-line security-node/detect-crlf
11
- console.log(validActorRefs);
12
- const validObjectRefs = [];
13
- objects_1.ObjectTypesList.forEach(function (type) {
14
- validObjectRefs.push({ "$ref": "#/definitions/type/" + type });
15
- });
16
- const contextSchema = {
17
- "type": "string"
18
- };
19
- const typeSchema = {
20
- "type": "string"
21
- };
22
- exports.default = {
23
- "$id": "https://sockethub.org/schemas/v0/activity-stream#",
24
- "description": "Schema for Sockethub Activity Streams",
25
- "type": "object",
26
- "required": ["context", "type", "actor"],
27
- "properties": {
28
- "id": {
29
- "type": "string"
30
- },
31
- "type": typeSchema,
32
- "context": contextSchema,
33
- "actor": {
34
- "type": "object",
35
- "oneOf": validActorRefs
36
- },
37
- "target": {
38
- "type": "object",
39
- "oneOf": validTargetRefs
40
- },
41
- "object": {
42
- "type": "object",
43
- "oneOf": validObjectRefs
44
- },
45
- "published": {
46
- "type": "string",
47
- "format": "date-time"
48
- }
49
- },
50
- "definitions": {
51
- "type": objects_1.ObjectTypesSchema
52
- }
53
- };
@@ -1,41 +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
- 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;
@@ -1,44 +0,0 @@
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
- };
package/dist/types.d.ts DELETED
@@ -1,34 +0,0 @@
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?: never;
20
- }
21
- declare type ErrorMsg = string | Error;
22
- export interface CallbackInterface {
23
- (err?: ErrorMsg, data?: unknown): void;
24
- }
25
- export interface CallbackActivityStreamInterface {
26
- (data: IActivityStream | Error): void;
27
- }
28
- export interface CompletedJobHandler {
29
- (data: IActivityStream): void;
30
- }
31
- export interface LogInterface {
32
- (msg: string): void;
33
- }
34
- export {};
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
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>;
package/dist/validator.js DELETED
@@ -1,80 +0,0 @@
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_1 = __importDefault(require("ajv-formats"));
10
- const ajv_formats_draft2019_1 = __importDefault(require("ajv-formats-draft2019"));
11
- const error_parser_1 = __importDefault(require("./helpers/error-parser"));
12
- const platform_1 = __importDefault(require("./schemas/platform"));
13
- const activity_stream_1 = __importDefault(require("./schemas/activity-stream"));
14
- const activity_object_1 = __importDefault(require("./schemas/activity-object"));
15
- const log = (0, debug_1.default)('sockethub:schemas');
16
- const ajv = new ajv_1.default({ strictTypes: false, allErrors: true });
17
- (0, ajv_formats_1.default)(ajv);
18
- (0, ajv_formats_draft2019_1.default)(ajv);
19
- const schemaURL = 'https://sockethub.org/schemas/v0';
20
- const schemas = {};
21
- schemas[`${schemaURL}/activity-stream`] = activity_stream_1.default;
22
- schemas[`${schemaURL}/activity-object`] = activity_object_1.default;
23
- for (const uri in schemas) {
24
- log(`registering schema ${uri}`);
25
- ajv.addSchema(schemas[uri], uri);
26
- }
27
- function handleValidation(schemaRef, msg, isObject = false) {
28
- const validator = ajv.getSchema(schemaRef);
29
- let result;
30
- if (isObject) {
31
- result = validator({ object: msg });
32
- }
33
- else {
34
- result = validator(msg);
35
- }
36
- if (!result) {
37
- return (0, error_parser_1.default)(msg, validator.errors);
38
- }
39
- return "";
40
- }
41
- function validateActivityObject(msg) {
42
- return handleValidation(`${schemaURL}/activity-object`, msg, true);
43
- }
44
- exports.validateActivityObject = validateActivityObject;
45
- function validateActivityStream(msg) {
46
- return handleValidation(`${schemaURL}/activity-stream`, msg);
47
- }
48
- exports.validateActivityStream = validateActivityStream;
49
- function validateCredentials(msg) {
50
- if (!msg.context) {
51
- return 'credential activity streams must have a context set';
52
- }
53
- if (msg.type !== 'credentials') {
54
- return 'credential activity streams must have credentials set as type';
55
- }
56
- return handleValidation(`${schemaURL}/context/${msg.context}/credentials`, msg);
57
- }
58
- exports.validateCredentials = validateCredentials;
59
- function validatePlatformSchema(schema) {
60
- const validate = ajv.compile(platform_1.default);
61
- // validate schema property
62
- const err = validate(schema);
63
- if (!err) {
64
- return `platform schema failed to validate: ` +
65
- `${validate.errors[0].instancePath} ${validate.errors[0].message}`;
66
- }
67
- else {
68
- return "";
69
- }
70
- }
71
- exports.validatePlatformSchema = validatePlatformSchema;
72
- function addPlatformSchema(schema, platform_type) {
73
- log(`registering schema ${schemaURL}/context/${platform_type}`);
74
- ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
75
- }
76
- exports.addPlatformSchema = addPlatformSchema;
77
- function getPlatformSchema(platform_type) {
78
- return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
79
- }
80
- exports.getPlatformSchema = getPlatformSchema;
@@ -1,96 +0,0 @@
1
- import {ErrorObject} from "ajv";
2
- import {ObjectTypesList} from "./objects";
3
- import {IActivityStream, IActivityObject} from "../types";
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 = `${error.instancePath ? error.instancePath : 'activity stream'}: ${error.message}`;
13
- if (error.keyword === 'additionalProperties') {
14
- err += `: ${error.params.additionalProperty}`;
15
- } else if (error.keyword === 'enum') {
16
- err += `: ${error.params.allowedValues.join(', ')}`;
17
- }
18
- return err;
19
- }
20
-
21
- function getTypeList(msg: IActivityStream | IActivityObject): Array<string> {
22
- let types = [];
23
- types.push(msg?.type);
24
- for (const prop in msg) {
25
- if (msg[prop]?.type) {
26
- types = [...types, ...getTypeList(msg[prop])];
27
- }
28
- }
29
- return types;
30
- }
31
-
32
- function getSchemaType(error: ErrorObject): string {
33
- const schemaTypeRes = error.schemaPath.match(/#\/\w+\/\w+\/([\w-]+)\//);
34
- return schemaTypeRes ? schemaTypeRes[1] : undefined;
35
- }
36
-
37
- function getErrType(error: ErrorObject): string {
38
- const errTypeRes = error.instancePath.match(/\/(\w+)/);
39
- return errTypeRes ? errTypeRes[1] : undefined;
40
- }
41
-
42
- function getPartsCount(error: ErrorObject, types: TypeBreakdown): number {
43
- const schemaType = getSchemaType(error);
44
- const errType = getErrType(error);
45
- if (!errType) { return -1; }
46
- if (!types[errType]) { return -1; }
47
- if (!types[errType].includes(schemaType)) { return -1; }
48
- const parts = error.instancePath.split('/');
49
- return parts.length;
50
- }
51
-
52
- function getTypes(msg: IActivityStream): TypeBreakdown {
53
- return {
54
- actor: getTypeList(msg.actor),
55
- target: getTypeList(msg.target),
56
- object: getTypeList(msg.context ? msg.object : msg)
57
- };
58
- }
59
-
60
- /**
61
- * Traverses the errors array from ajv, and makes a series of filtering decisions to
62
- * try to arrive at the most useful error.
63
- * @param msg
64
- * @param errors
65
- * @returns {string}
66
- */
67
- export default function getErrorMessage(msg, errors: Array<ErrorObject>): string {
68
- const types = getTypes(msg);
69
- let deepest_entry = 0, highest_depth = -1;
70
-
71
- for (let i = 0; i < errors.length; i++) {
72
- const partsCount = getPartsCount(errors[i], types);
73
- if (partsCount > highest_depth) {
74
- highest_depth = partsCount;
75
- deepest_entry = i;
76
- }
77
- }
78
-
79
- return highest_depth >= 0 ?
80
- parseMsg(errors[deepest_entry]) :
81
- composeFinalError(errors[errors.length - 1]);
82
- }
83
-
84
- function composeFinalError(error) {
85
- // if we have yet to build an error message, assume this is an invalid type value (oneOf),
86
- // try to build a list of valid types
87
- let msg: string;
88
- if (error.keyword === 'oneOf') {
89
- msg = `${error.instancePath}: ${error.message}: ` +
90
- `${ObjectTypesList.join(', ')}`;
91
- } else {
92
- msg = `${error.instancePath ?
93
- error.instancePath : 'activity stream'}: ${error.message}`;
94
- }
95
- return msg;
96
- }