@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,90 +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
- var _a;
16
- let types = [];
17
- types.push(msg === null || msg === void 0 ? void 0 : msg.type);
18
- for (const prop in msg) {
19
- if ((_a = msg[prop]) === null || _a === void 0 ? void 0 : _a.type) {
20
- types = [...types, ...getTypeList(msg[prop])];
21
- }
22
- }
23
- return types;
24
- }
25
- function getSchemaType(error) {
26
- const schemaTypeRes = error.schemaPath.match(/#\/\w+\/\w+\/([\w-]+)\//);
27
- return schemaTypeRes ? schemaTypeRes[1] : undefined;
28
- }
29
- function getErrType(error) {
30
- const errTypeRes = error.instancePath.match(/\/(\w+)/);
31
- return errTypeRes ? errTypeRes[1] : undefined;
32
- }
33
- function getPartsCount(error, types) {
34
- const schemaType = getSchemaType(error);
35
- const errType = getErrType(error);
36
- if (!errType) {
37
- return -1;
38
- }
39
- if (!types[errType]) {
40
- return -1;
41
- }
42
- if (!types[errType].includes(schemaType)) {
43
- return -1;
44
- }
45
- const parts = error.instancePath.split('/');
46
- return parts.length;
47
- }
48
- function getTypes(msg) {
49
- return {
50
- actor: getTypeList(msg.actor),
51
- target: getTypeList(msg.target),
52
- object: getTypeList(msg.context ? msg.object : msg)
53
- };
54
- }
55
- /**
56
- * Traverses the errors array from ajv, and makes a series of filtering decisions to
57
- * try to arrive at the most useful error.
58
- * @param msg
59
- * @param errors
60
- * @returns {string}
61
- */
62
- function getErrorMessage(msg, errors) {
63
- const types = getTypes(msg);
64
- let deepest_entry = 0, highest_depth = -1;
65
- for (let i = 0; i < errors.length; i++) {
66
- const partsCount = getPartsCount(errors[i], types);
67
- if (partsCount > highest_depth) {
68
- highest_depth = partsCount;
69
- deepest_entry = i;
70
- }
71
- }
72
- return highest_depth >= 0 ?
73
- parseMsg(errors[deepest_entry]) :
74
- composeFinalError(errors[errors.length - 1]);
75
- }
76
- exports.default = getErrorMessage;
77
- function composeFinalError(error) {
78
- // if we have yet to build an error message, assume this is an invalid type value (oneOf),
79
- // try to build a list of valid types
80
- let msg;
81
- if (error.keyword === 'oneOf') {
82
- msg = `${error.instancePath}: ${error.message}: ` +
83
- `${objects_1.ObjectTypesList.join(', ')}`;
84
- }
85
- else {
86
- msg = `${error.instancePath ?
87
- error.instancePath : 'activity stream'}: ${error.message}`;
88
- }
89
- return msg;
90
- }
@@ -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) {
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 * from "./types";
package/dist/index.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ObjectTypesList = exports.ActivityStreamSchema = exports.ActivityObjectSchema = exports.PlatformSchema = void 0;
21
- const validator_1 = require("./validator");
22
- const objects_1 = require("./helpers/objects");
23
- Object.defineProperty(exports, "ObjectTypesList", { enumerable: true, get: function () { return objects_1.ObjectTypesList; } });
24
- const activity_object_1 = __importDefault(require("./schemas/activity-object"));
25
- exports.ActivityObjectSchema = activity_object_1.default;
26
- const activity_stream_1 = __importDefault(require("./schemas/activity-stream"));
27
- exports.ActivityStreamSchema = activity_stream_1.default;
28
- const platform_1 = __importDefault(require("./schemas/platform"));
29
- exports.PlatformSchema = platform_1.default;
30
- exports.default = {
31
- addPlatformSchema: validator_1.addPlatformSchema,
32
- validatePlatformSchema: validator_1.validatePlatformSchema,
33
- validateCredentials: validator_1.validateCredentials,
34
- validateActivityStream: validator_1.validateActivityStream,
35
- validateActivityObject: validator_1.validateActivityObject,
36
- };
37
- __exportStar(require("./types"), exports);
@@ -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
- ];