@sockethub/schemas 3.0.0-alpha.3 → 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 -31
  2. package/src/index.ts +23 -22
  3. package/src/schemas/activity-object.ts +15 -15
  4. package/src/schemas/activity-stream.ts +41 -38
  5. package/{dist → src}/schemas/json/activity-object.json +1 -1
  6. package/{dist → src}/schemas/json/activity-stream.json +5 -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 -91
  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 -22
  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 -256
  24. package/dist/index.test.data.streams.js +0 -449
  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 -235
  28. package/dist/schemas/activity-stream.js +0 -49
  29. package/dist/schemas/platform.d.ts +0 -41
  30. package/dist/schemas/platform.js +0 -44
  31. package/dist/types.d.ts +0 -20
  32. package/dist/types.js +0 -2
  33. package/dist/validator.d.ts +0 -8
  34. package/dist/validator.js +0 -78
  35. package/src/helpers/error-parser.ts +0 -99
  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 -470
  41. package/src/index.test.ts +0 -84
  42. package/src/types.ts +0 -23
  43. package/src/validator.ts +0 -79
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const objects_1 = require("./objects");
4
- function parseMsg(error) {
5
- let err = `${error.instancePath ? error.instancePath : 'activity stream'}: ${error.message}`;
6
- if (error.keyword === 'additionalProperties') {
7
- err += `: ${error.params.additionalProperty}`;
8
- }
9
- else if (error.keyword === 'enum') {
10
- err += `: ${error.params.allowedValues.join(', ')}`;
11
- }
12
- return err;
13
- }
14
- function getTypeList(msg) {
15
- let types = [];
16
- if ((typeof msg === 'object') && (msg.type)) {
17
- types.push(msg.type);
18
- }
19
- else {
20
- types.push(undefined);
21
- }
22
- for (let prop in msg) {
23
- if ((typeof msg[prop] === 'object') && (msg[prop].type)) {
24
- types = [...types, ...getTypeList(msg[prop])];
25
- }
26
- }
27
- return types;
28
- }
29
- function getSchemaType(error) {
30
- const schemaTypeRes = error.schemaPath.match(/#\/\w+\/\w+\/([\w-]+)\//);
31
- return schemaTypeRes ? schemaTypeRes[1] : undefined;
32
- }
33
- function getErrType(error) {
34
- const errTypeRes = error.instancePath.match(/\/([\w]+)/);
35
- return errTypeRes ? errTypeRes[1] : undefined;
36
- }
37
- function getPartsCount(error, types) {
38
- const schemaType = getSchemaType(error);
39
- const errType = getErrType(error);
40
- if (!errType) {
41
- return -1;
42
- }
43
- if (!types[errType].includes(schemaType)) {
44
- return -1;
45
- }
46
- const parts = error.instancePath.split('/');
47
- return parts.length;
48
- }
49
- function getTypes(msg) {
50
- return {
51
- actor: getTypeList(msg.actor),
52
- target: getTypeList(msg.target),
53
- object: getTypeList(msg.context ? msg.object : msg)
54
- };
55
- }
56
- /**
57
- * Traverses the errors array from ajv, and makes a series of filtering decisions to
58
- * try to arrive at the most useful error.
59
- * @param msg
60
- * @param errors
61
- * @returns {string}
62
- */
63
- function getErrorMessage(msg, errors) {
64
- const types = getTypes(msg);
65
- let deepest_entry = 0, highest_depth = -1;
66
- for (let i = 0; i < errors.length; i++) {
67
- const partsCount = getPartsCount(errors[i], types);
68
- if (partsCount > highest_depth) {
69
- highest_depth = partsCount;
70
- deepest_entry = i;
71
- }
72
- }
73
- return highest_depth >= 0 ?
74
- parseMsg(errors[deepest_entry]) :
75
- composeFinalError(errors[errors.length - 1]);
76
- }
77
- exports.default = getErrorMessage;
78
- function composeFinalError(error) {
79
- // if we have yet to build an error message, assume this is an invalid type value (oneOf),
80
- // try to build a list of valid types
81
- let msg = "";
82
- if (error.keyword === 'oneOf') {
83
- msg = `${error.instancePath}: ${error.message}: ` +
84
- `${objects_1.ObjectTypesList.join(', ')}`;
85
- }
86
- else {
87
- msg = `${error.instancePath ?
88
- error.instancePath : 'activity stream'}: ${error.message}`;
89
- }
90
- return msg;
91
- }
@@ -1,206 +0,0 @@
1
- export declare const validObjectRefs: any[];
2
- export declare const validObjectDefs: {};
3
- export declare const ObjectTypesSchema: {
4
- credentials: {
5
- required: string[];
6
- additionalProperties: boolean;
7
- properties: {
8
- type: {
9
- enum: string[];
10
- };
11
- };
12
- };
13
- feed: {
14
- required: string[];
15
- additionalProperties: boolean;
16
- properties: {
17
- type: {
18
- enum: string[];
19
- };
20
- id: {
21
- type: string;
22
- format: string;
23
- };
24
- name: {
25
- type: string;
26
- };
27
- description: {
28
- type: string;
29
- };
30
- author: {
31
- type: string;
32
- };
33
- favicon: {
34
- type: string;
35
- };
36
- };
37
- };
38
- message: {
39
- required: string[];
40
- additionalProperties: boolean;
41
- properties: {
42
- type: {
43
- enum: string[];
44
- };
45
- id: {
46
- type: string;
47
- };
48
- name: {
49
- type: string;
50
- };
51
- content: {
52
- type: string;
53
- };
54
- };
55
- };
56
- me: {
57
- required: string[];
58
- additionalProperties: boolean;
59
- properties: {
60
- type: {
61
- enum: string[];
62
- };
63
- content: {
64
- type: string;
65
- };
66
- };
67
- };
68
- person: {
69
- required: string[];
70
- additionalProperties: boolean;
71
- properties: {
72
- id: {
73
- type: string;
74
- };
75
- type: {
76
- enum: string[];
77
- };
78
- name: {
79
- type: string;
80
- };
81
- };
82
- };
83
- room: {
84
- required: string[];
85
- additionalProperties: boolean;
86
- properties: {
87
- id: {
88
- type: string;
89
- };
90
- type: {
91
- enum: string[];
92
- };
93
- name: {
94
- type: string;
95
- };
96
- };
97
- };
98
- service: {
99
- required: string[];
100
- additionalProperties: boolean;
101
- properties: {
102
- id: {
103
- type: string;
104
- };
105
- type: {
106
- enum: string[];
107
- };
108
- name: {
109
- type: string;
110
- };
111
- };
112
- };
113
- website: {
114
- required: string[];
115
- additionalProperties: boolean;
116
- properties: {
117
- id: {
118
- type: string;
119
- format: string;
120
- };
121
- type: {
122
- enum: string[];
123
- };
124
- name: {
125
- type: string;
126
- };
127
- };
128
- };
129
- attendance: {
130
- required: string[];
131
- additionalProperties: boolean;
132
- properties: {
133
- type: {
134
- enum: string[];
135
- };
136
- members: {
137
- type: string;
138
- items: {
139
- type: string;
140
- };
141
- };
142
- };
143
- };
144
- presence: {
145
- required: string[];
146
- additionalProperties: boolean;
147
- properties: {
148
- type: {
149
- enum: string[];
150
- };
151
- presence: {
152
- enum: string[];
153
- };
154
- role: {
155
- enum: string[];
156
- };
157
- content: {
158
- type: string;
159
- };
160
- };
161
- };
162
- relationship: {
163
- required: string[];
164
- additionalProperties: boolean;
165
- properties: {
166
- type: {
167
- enum: string[];
168
- };
169
- relationship: {
170
- enum: string[];
171
- };
172
- subject: {
173
- type: string;
174
- oneOf: {
175
- $ref: string;
176
- }[];
177
- };
178
- object: {
179
- type: string;
180
- oneOf: any[];
181
- };
182
- };
183
- };
184
- topic: {
185
- required: string[];
186
- additionalProperties: boolean;
187
- properties: {
188
- type: {
189
- enum: string[];
190
- };
191
- content: {
192
- type: string;
193
- };
194
- };
195
- };
196
- address: {
197
- required: string[];
198
- additionalProperties: boolean;
199
- properties: {
200
- type: {
201
- enum: string[];
202
- };
203
- };
204
- };
205
- };
206
- export declare const ObjectTypesList: string[];
@@ -1,217 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObjectTypesList = exports.ObjectTypesSchema = exports.validObjectDefs = exports.validObjectRefs = void 0;
4
- exports.validObjectRefs = [];
5
- exports.validObjectDefs = {};
6
- exports.ObjectTypesSchema = {
7
- "credentials": {
8
- "required": ["type"],
9
- "additionalProperties": true,
10
- "properties": {
11
- "type": {
12
- "enum": ["credentials"]
13
- }
14
- }
15
- },
16
- "feed": {
17
- "required": ["id", "type"],
18
- "additionalProperties": true,
19
- "properties": {
20
- "type": {
21
- "enum": ["feed"]
22
- },
23
- "id": {
24
- "type": "string",
25
- "format": "iri"
26
- },
27
- "name": {
28
- "type": "string"
29
- },
30
- "description": {
31
- "type": "string"
32
- },
33
- "author": {
34
- "type": "string"
35
- },
36
- "favicon": {
37
- "type": "string"
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
- "me": {
60
- "required": ["type", "content"],
61
- "additionalProperties": true,
62
- "properties": {
63
- "type": {
64
- "enum": ["me"]
65
- },
66
- "content": {
67
- "type": "string"
68
- }
69
- }
70
- },
71
- "person": {
72
- "required": ["id", "type"],
73
- "additionalProperties": true,
74
- "properties": {
75
- "id": {
76
- "type": "string"
77
- },
78
- "type": {
79
- "enum": ["person"]
80
- },
81
- "name": {
82
- "type": "string"
83
- }
84
- }
85
- },
86
- "room": {
87
- "required": ["id", "type"],
88
- "additionalProperties": true,
89
- "properties": {
90
- "id": {
91
- "type": "string"
92
- },
93
- "type": {
94
- "enum": ["room"]
95
- },
96
- "name": {
97
- "type": "string"
98
- }
99
- }
100
- },
101
- "service": {
102
- "required": ["id", "type"],
103
- "additionalProperties": true,
104
- "properties": {
105
- "id": {
106
- "type": "string"
107
- },
108
- "type": {
109
- "enum": ["service"]
110
- },
111
- "name": {
112
- "type": "string"
113
- }
114
- }
115
- },
116
- "website": {
117
- "required": ["id", "type"],
118
- "additionalProperties": true,
119
- "properties": {
120
- "id": {
121
- "type": "string",
122
- "format": "iri"
123
- },
124
- "type": {
125
- "enum": ["website"]
126
- },
127
- "name": {
128
- "type": "string"
129
- }
130
- }
131
- },
132
- "attendance": {
133
- "required": ["type"],
134
- "additionalProperties": false,
135
- "properties": {
136
- "type": {
137
- "enum": ["attendance"]
138
- },
139
- "members": {
140
- "type": "array",
141
- "items": {
142
- "type": "string"
143
- }
144
- }
145
- }
146
- },
147
- "presence": {
148
- "required": ["type"],
149
- "additionalProperties": false,
150
- "properties": {
151
- "type": {
152
- "enum": ["presence"]
153
- },
154
- "presence": {
155
- "enum": ["away", "chat", "dnd", "xa", "offline", "online"]
156
- },
157
- "role": {
158
- "enum": ["owner", "member", "participant", "admin"]
159
- },
160
- "content": {
161
- "type": "string"
162
- }
163
- }
164
- },
165
- // inspired by https://www.w3.org/ns/activitystreams#Relationship
166
- "relationship": {
167
- "required": ["type", "relationship"],
168
- "additionalProperties": false,
169
- "properties": {
170
- "type": {
171
- "enum": ["relationship"]
172
- },
173
- "relationship": {
174
- "enum": ["role"]
175
- },
176
- "subject": {
177
- "type": "object",
178
- "oneOf": [
179
- { "$ref": "#/definitions/type/presence" }
180
- ]
181
- },
182
- "object": {
183
- "type": "object",
184
- "oneOf": exports.validObjectRefs,
185
- }
186
- }
187
- },
188
- "topic": {
189
- "required": ["type"],
190
- "additionalProperties": false,
191
- "properties": {
192
- "type": {
193
- "enum": ["topic"]
194
- },
195
- "content": {
196
- "type": "string"
197
- }
198
- }
199
- },
200
- "address": {
201
- "required": ["type"],
202
- "additionalProperties": false,
203
- "properties": {
204
- "type": {
205
- "enum": ["address"]
206
- }
207
- }
208
- }
209
- };
210
- exports.ObjectTypesList = Object.keys(exports.ObjectTypesSchema);
211
- exports.ObjectTypesList.forEach(function (type, i) {
212
- if (type === 'credentials') {
213
- return;
214
- }
215
- exports.validObjectRefs.push({ "$ref": "#/definitions/type/" + type });
216
- exports.validObjectDefs[type] = exports.ObjectTypesSchema[type];
217
- });
package/dist/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { addPlatformSchema, validateActivityObject, validateActivityStream, validateCredentials, validatePlatformSchema } from "./validator";
2
- import { ObjectTypesList } from "./helpers/objects";
3
- import ActivityObjectSchema from "./schemas/activity-object";
4
- import ActivityStreamSchema from "./schemas/activity-stream";
5
- import PlatformSchema from "./schemas/platform";
6
- declare const _default: {
7
- addPlatformSchema: typeof addPlatformSchema;
8
- validatePlatformSchema: typeof validatePlatformSchema;
9
- validateCredentials: typeof validateCredentials;
10
- validateActivityStream: typeof validateActivityStream;
11
- validateActivityObject: typeof validateActivityObject;
12
- };
13
- export default _default;
14
- export { PlatformSchema, ActivityObjectSchema, ActivityStreamSchema, ObjectTypesList };
15
- export { IActivityStream, IActivityObject } from "./types";
package/dist/index.js DELETED
@@ -1,22 +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.ObjectTypesList = exports.ActivityStreamSchema = exports.ActivityObjectSchema = exports.PlatformSchema = void 0;
7
- const validator_1 = require("./validator");
8
- const objects_1 = require("./helpers/objects");
9
- Object.defineProperty(exports, "ObjectTypesList", { enumerable: true, get: function () { return objects_1.ObjectTypesList; } });
10
- const activity_object_1 = __importDefault(require("./schemas/activity-object"));
11
- exports.ActivityObjectSchema = activity_object_1.default;
12
- const activity_stream_1 = __importDefault(require("./schemas/activity-stream"));
13
- exports.ActivityStreamSchema = activity_stream_1.default;
14
- const platform_1 = __importDefault(require("./schemas/platform"));
15
- exports.PlatformSchema = platform_1.default;
16
- exports.default = {
17
- addPlatformSchema: validator_1.addPlatformSchema,
18
- validatePlatformSchema: validator_1.validatePlatformSchema,
19
- validateCredentials: validator_1.validateCredentials,
20
- validateActivityStream: validator_1.validateActivityStream,
21
- validateActivityObject: validator_1.validateActivityObject,
22
- };
@@ -1,37 +0,0 @@
1
- declare const _default: ((string | boolean | {
2
- type: string;
3
- object: {
4
- type: string;
5
- };
6
- })[] | (string | boolean | {
7
- context: string;
8
- object: {
9
- type: string;
10
- };
11
- })[] | (string | boolean | {
12
- context: string;
13
- type: string;
14
- object: {
15
- type: string;
16
- user: string;
17
- pass: string;
18
- };
19
- })[] | (string | boolean | {
20
- context: string;
21
- type: string;
22
- object: {
23
- type: string;
24
- username: string;
25
- password: string;
26
- };
27
- })[] | (string | boolean | {
28
- context: string;
29
- type: string;
30
- object: {
31
- type: string;
32
- username: string;
33
- password: string;
34
- host: string;
35
- };
36
- })[])[];
37
- export default _default;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [
4
- [
5
- 'credentials with no context',
6
- {
7
- type: 'credentials',
8
- object: {
9
- type: 'credentials'
10
- }
11
- },
12
- false,
13
- `credential activity streams must have a context set`
14
- ],
15
- [
16
- 'credentials with no type',
17
- {
18
- context: 'test-platform',
19
- object: {
20
- type: 'credentials'
21
- }
22
- },
23
- false,
24
- `credential activity streams must have credentials set as type`
25
- ],
26
- [
27
- 'credentials with props',
28
- {
29
- context: 'test-platform',
30
- type: 'credentials',
31
- object: {
32
- type: 'credentials',
33
- user: "foo",
34
- pass: "bar"
35
- }
36
- },
37
- false,
38
- `/object: must NOT have additional properties`
39
- ],
40
- [
41
- 'credentials with props',
42
- {
43
- context: 'test-platform',
44
- type: 'credentials',
45
- object: {
46
- type: 'credentials',
47
- username: "foo",
48
- password: "bar"
49
- }
50
- },
51
- false,
52
- `/object: must have required property 'host'`
53
- ],
54
- [
55
- 'credentials with props',
56
- {
57
- context: 'test-platform',
58
- type: 'credentials',
59
- object: {
60
- type: 'credentials',
61
- username: "foo",
62
- password: "bar",
63
- host: 'yarg'
64
- }
65
- },
66
- true,
67
- ""
68
- ],
69
- ];
@@ -1,50 +0,0 @@
1
- declare const _default: ((string | boolean | {
2
- id: string;
3
- type: string;
4
- name: string;
5
- })[] | (string | boolean | {
6
- type: string;
7
- })[] | (string | boolean | {
8
- type: string;
9
- user: string;
10
- pass: string;
11
- })[] | (string | boolean | {
12
- type: string;
13
- name: string;
14
- })[] | (string | boolean | {
15
- id: string;
16
- type: string;
17
- })[] | (string | boolean | {
18
- id: string;
19
- type: string;
20
- content: string;
21
- })[] | (string | boolean | {
22
- type: string;
23
- members: string[];
24
- })[] | (string | boolean | {
25
- type: string;
26
- status: string;
27
- })[] | (string | boolean | {
28
- type: string;
29
- presence: string;
30
- content: string;
31
- })[] | (string | boolean | {
32
- type: string;
33
- content: string;
34
- })[] | (string | boolean | {
35
- type: string;
36
- topic: string;
37
- })[] | (string | boolean | {
38
- type: string;
39
- relationship: string;
40
- subject: {
41
- type: string;
42
- role: string;
43
- };
44
- object: {
45
- type: string;
46
- id: string;
47
- name: string;
48
- };
49
- })[])[];
50
- export default _default;