@sockethub/schemas 3.0.0-alpha.12 → 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.
Files changed (46) hide show
  1. package/dist/activity-stream-helper.d.ts +5 -0
  2. package/dist/activity-stream-helper.js +36 -0
  3. package/dist/activity-stream-helper.js.map +10 -0
  4. package/dist/context.d.ts +56 -0
  5. package/dist/context.js +20 -41
  6. package/dist/context.js.map +3 -3
  7. package/dist/helpers/error-parser.d.ts +13 -0
  8. package/dist/helpers/objects.d.ts +122 -0
  9. package/dist/index.d.ts +9 -0
  10. package/dist/index.js +180 -218
  11. package/dist/index.js.map +12 -12
  12. package/dist/maps/context-map.json +2 -2
  13. package/dist/object-types.d.ts +2 -0
  14. package/dist/object-types.js +296 -0
  15. package/dist/object-types.js.map +12 -0
  16. package/dist/schemas/activity-stream.d.ts +161 -0
  17. package/dist/schemas/platform/feeds/v1/messages.schema.json +8 -17
  18. package/dist/schemas/platform/irc/v1/credentials.schema.json +71 -1
  19. package/dist/schemas/platform/irc/v1/messages.schema.json +84 -0
  20. package/dist/schemas/platform/metadata/v1/messages.schema.json +1 -16
  21. package/dist/schemas/platform/xmpp/v1/credentials.schema.json +2 -2
  22. package/dist/schemas/platform/xmpp/v1/messages.schema.json +108 -0
  23. package/dist/schemas/platform.d.ts +62 -0
  24. package/dist/schemas/sockethub-config.d.ts +261 -0
  25. package/{src/types.ts → dist/types.d.ts} +17 -45
  26. package/dist/validator.d.ts +26 -0
  27. package/package.json +13 -8
  28. package/src/context.ts +0 -125
  29. package/src/helpers/error-parser.ts +0 -160
  30. package/src/helpers/objects.ts +0 -283
  31. package/src/index.test.data.credentials.ts +0 -103
  32. package/src/index.test.data.objects.ts +0 -241
  33. package/src/index.test.data.platform.ts +0 -48
  34. package/src/index.test.data.streams.ts +0 -590
  35. package/src/index.test.ts +0 -127
  36. package/src/index.ts +0 -56
  37. package/src/schemas/activity-object.ts +0 -19
  38. package/src/schemas/activity-stream.ts +0 -75
  39. package/src/schemas/json/activity-object.json +0 -405
  40. package/src/schemas/json/activity-stream.json +0 -502
  41. package/src/schemas/json/platform.json +0 -48
  42. package/src/schemas/json/sockethub-config.json +0 -236
  43. package/src/schemas/platform.ts +0 -71
  44. package/src/schemas/sockethub-config.ts +0 -220
  45. package/src/types/ajv-formats-draft2019.d.ts +0 -5
  46. package/src/validator.ts +0 -207
package/src/index.test.ts DELETED
@@ -1,127 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import type { ActivityObject, ActivityStream } from "./types";
3
-
4
- import testCredentialsData from "./index.test.data.credentials";
5
- import testActivityObjectsData from "./index.test.data.objects";
6
- import testPlatformSchemaData from "./index.test.data.platform";
7
- import testActivityStreamsData from "./index.test.data.streams";
8
- import { ActivityObjectSchema } from "./schemas/activity-object";
9
- import { ActivityStreamSchema } from "./schemas/activity-stream";
10
- import {
11
- addPlatformContext,
12
- addPlatformSchema,
13
- getPlatformSchema,
14
- validateActivityObject,
15
- validateActivityStream,
16
- validateCredentials,
17
- validatePlatformSchema,
18
- } from "./validator";
19
-
20
- const permissiveMessageSchema = {
21
- required: ["type"],
22
- properties: {
23
- type: {
24
- type: "string",
25
- },
26
- },
27
- };
28
-
29
- addPlatformSchema(permissiveMessageSchema, "irc/messages");
30
- addPlatformSchema(permissiveMessageSchema, "dood/messages");
31
- addPlatformSchema(
32
- testPlatformSchemaData.credentials,
33
- "test-platform/credentials",
34
- );
35
- addPlatformContext(
36
- "irc",
37
- "https://sockethub.org/ns/context/platform/irc/v1.jsonld",
38
- );
39
- addPlatformContext(
40
- "dood",
41
- "https://sockethub.org/ns/context/platform/dood/v1.jsonld",
42
- );
43
- addPlatformContext(
44
- "test-platform",
45
- "https://sockethub.org/ns/context/platform/test-platform/v1.jsonld",
46
- );
47
-
48
- describe("schemas/src/index.ts", () => {
49
- describe("Platform schema validation", () => {
50
- it("returns an empty error for a valid schema", () => {
51
- const err = validatePlatformSchema(testPlatformSchemaData);
52
- expect(err).toEqual("");
53
- });
54
- it("returns an error for an invalid schema", () => {
55
- const err = validatePlatformSchema({ foo: "bar" });
56
- expect(err).toEqual(
57
- "platform schema failed to validate: must have required property 'name'",
58
- );
59
- });
60
- });
61
-
62
- describe("Adding a PlatformSchema", () => {
63
- it("returns the same schema when fetched", () => {
64
- const platform_type = "test-platform/credentials";
65
- const compiledSchema = getPlatformSchema(platform_type);
66
- expect(compiledSchema.schema).toEqual(
67
- testPlatformSchemaData.credentials,
68
- );
69
- });
70
- });
71
-
72
- describe("Credentials", () => {
73
- testCredentialsData.forEach(
74
- ([name, creds, expectedResult, expectedFailureMessage]) => {
75
- describe("validateCredential " + name, () => {
76
- it(`returns expected result`, () => {
77
- const err = validateCredentials(creds as ActivityStream);
78
- expect(err).toEqual(expectedFailureMessage);
79
- expect(!err).toEqual(expectedResult);
80
- });
81
- });
82
- },
83
- );
84
- });
85
-
86
- describe("ActivityObject", () => {
87
- it("has expected properties", () => {
88
- expect(typeof ActivityObjectSchema).toEqual("object");
89
- expect(ActivityObjectSchema["$id"]).toEqual(
90
- "https://sockethub.org/schemas/v/activity-object.json",
91
- );
92
- });
93
-
94
- testActivityObjectsData.forEach(
95
- ([name, ao, expectedResult, expectedFailureMessage]) => {
96
- describe("validateActivityObject " + name, () => {
97
- it(`returns expected result`, () => {
98
- const err = validateActivityObject(ao as ActivityObject);
99
- expect(err).toEqual(expectedFailureMessage);
100
- expect(!err).toEqual(expectedResult);
101
- });
102
- });
103
- },
104
- );
105
- });
106
-
107
- describe("ActivityStream", () => {
108
- it("has expected properties", () => {
109
- expect(typeof ActivityStreamSchema).toEqual("object");
110
- expect(ActivityStreamSchema["$id"]).toEqual(
111
- "https://sockethub.org/schemas/v/activity-stream.json",
112
- );
113
- });
114
-
115
- testActivityStreamsData.forEach(
116
- ([name, as, expectedResult, expectedFailureMessage]) => {
117
- describe("validateActivityStream " + name, () => {
118
- it(`returns expected result`, () => {
119
- const err = validateActivityStream(as as ActivityStream);
120
- expect(err).toEqual(expectedFailureMessage);
121
- expect(!err).toEqual(expectedResult);
122
- });
123
- });
124
- },
125
- );
126
- });
127
- });
package/src/index.ts DELETED
@@ -1,56 +0,0 @@
1
- import {
2
- AS2_BASE_CONTEXT_URL,
3
- buildCanonicalContext,
4
- ERROR_PLATFORM_CONTEXT_URL,
5
- ERROR_PLATFORM_ID,
6
- INTERNAL_PLATFORM_CONTEXT_URL,
7
- INTERNAL_PLATFORM_ID,
8
- PLATFORM_CONTEXT_PREFIX,
9
- SOCKETHUB_BASE_CONTEXT_URL,
10
- } from "./context.js";
11
- import { InternalObjectTypesList, ObjectTypesList } from "./helpers/objects.js";
12
- import { ActivityObjectSchema } from "./schemas/activity-object.js";
13
- import { ActivityStreamSchema } from "./schemas/activity-stream.js";
14
- import { PlatformSchema } from "./schemas/platform.js";
15
- import { SockethubConfigSchema } from "./schemas/sockethub-config.js";
16
- import {
17
- addPlatformContext,
18
- addPlatformSchema,
19
- getPlatformSchema,
20
- registerSystemPlatformContexts,
21
- resolvePlatformId,
22
- setValidationErrorOptions,
23
- validateActivityObject,
24
- validateActivityStream,
25
- validateCredentials,
26
- validatePlatformSchema,
27
- } from "./validator.js";
28
-
29
- export {
30
- AS2_BASE_CONTEXT_URL,
31
- SOCKETHUB_BASE_CONTEXT_URL,
32
- PLATFORM_CONTEXT_PREFIX,
33
- ERROR_PLATFORM_ID,
34
- ERROR_PLATFORM_CONTEXT_URL,
35
- INTERNAL_PLATFORM_ID,
36
- INTERNAL_PLATFORM_CONTEXT_URL,
37
- buildCanonicalContext,
38
- addPlatformContext,
39
- addPlatformSchema,
40
- getPlatformSchema,
41
- resolvePlatformId,
42
- registerSystemPlatformContexts,
43
- validatePlatformSchema,
44
- validateCredentials,
45
- validateActivityStream,
46
- validateActivityObject,
47
- setValidationErrorOptions,
48
- PlatformSchema,
49
- ActivityObjectSchema,
50
- ActivityStreamSchema,
51
- SockethubConfigSchema,
52
- ObjectTypesList,
53
- InternalObjectTypesList,
54
- };
55
-
56
- export * from "./types.js";
@@ -1,19 +0,0 @@
1
- import { validObjectDefs, validObjectRefs } from "../helpers/objects.js";
2
-
3
- export const ActivityObjectSchema = {
4
- $id: "https://sockethub.org/schemas/v/activity-object.json",
5
- description: "Schema for Sockethub Activity Objects",
6
-
7
- type: "object",
8
- required: ["object"],
9
- properties: {
10
- object: {
11
- type: "object",
12
- oneOf: validObjectRefs,
13
- },
14
- },
15
-
16
- definitions: {
17
- type: validObjectDefs,
18
- },
19
- };
@@ -1,75 +0,0 @@
1
- import {
2
- AS2_BASE_CONTEXT_URL,
3
- SOCKETHUB_BASE_CONTEXT_URL,
4
- } from "../context.js";
5
- import {
6
- ObjectTypesList,
7
- ObjectTypesSchema,
8
- validActorRefs,
9
- validTargetRefs,
10
- } from "../helpers/objects.js";
11
-
12
- const validObjectRefs = [];
13
-
14
- for (const type of ObjectTypesList) {
15
- validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
16
- }
17
-
18
- const contextSchema = {
19
- type: "array",
20
- minItems: 3,
21
- maxItems: 3,
22
- items: {
23
- type: "string",
24
- },
25
- allOf: [
26
- {
27
- contains: {
28
- const: AS2_BASE_CONTEXT_URL,
29
- },
30
- },
31
- {
32
- contains: {
33
- const: SOCKETHUB_BASE_CONTEXT_URL,
34
- },
35
- },
36
- ],
37
- };
38
- const typeSchema = {
39
- type: "string",
40
- };
41
-
42
- export const ActivityStreamSchema = {
43
- $id: "https://sockethub.org/schemas/v/activity-stream.json",
44
- description: "Schema for Sockethub Activity Streams",
45
-
46
- type: "object",
47
- required: ["@context", "type", "actor"],
48
- properties: {
49
- "@context": contextSchema,
50
- id: {
51
- type: "string",
52
- },
53
- type: typeSchema,
54
- actor: {
55
- type: "object",
56
- oneOf: validActorRefs,
57
- },
58
- target: {
59
- type: "object",
60
- oneOf: validTargetRefs,
61
- },
62
- object: {
63
- type: "object",
64
- oneOf: validObjectRefs,
65
- },
66
- published: {
67
- type: "string",
68
- format: "date-time",
69
- },
70
- },
71
-
72
- definitions: {
73
- type: ObjectTypesSchema,
74
- },
75
- };
@@ -1,405 +0,0 @@
1
- {
2
- "$id": "https://sockethub.org/schemas/3.0.0-alpha.12/activity-object.json",
3
- "description": "Schema for Sockethub Activity Objects",
4
- "type": "object",
5
- "required": [
6
- "object"
7
- ],
8
- "properties": {
9
- "object": {
10
- "type": "object",
11
- "oneOf": [
12
- {
13
- "$ref": "#/definitions/type/feed"
14
- },
15
- {
16
- "$ref": "#/definitions/type/message"
17
- },
18
- {
19
- "$ref": "#/definitions/type/me"
20
- },
21
- {
22
- "$ref": "#/definitions/type/person"
23
- },
24
- {
25
- "$ref": "#/definitions/type/room"
26
- },
27
- {
28
- "$ref": "#/definitions/type/service"
29
- },
30
- {
31
- "$ref": "#/definitions/type/platform"
32
- },
33
- {
34
- "$ref": "#/definitions/type/website"
35
- },
36
- {
37
- "$ref": "#/definitions/type/attendance"
38
- },
39
- {
40
- "$ref": "#/definitions/type/presence"
41
- },
42
- {
43
- "$ref": "#/definitions/type/relationship"
44
- },
45
- {
46
- "$ref": "#/definitions/type/topic"
47
- },
48
- {
49
- "$ref": "#/definitions/type/address"
50
- },
51
- {
52
- "$ref": "#/definitions/type/heartbeat"
53
- }
54
- ]
55
- }
56
- },
57
- "definitions": {
58
- "type": {
59
- "feed": {
60
- "required": [
61
- "id",
62
- "type"
63
- ],
64
- "additionalProperties": true,
65
- "properties": {
66
- "type": {
67
- "enum": [
68
- "feed"
69
- ]
70
- },
71
- "id": {
72
- "type": "string",
73
- "format": "iri"
74
- },
75
- "name": {
76
- "type": "string"
77
- },
78
- "description": {
79
- "type": "string"
80
- },
81
- "author": {
82
- "type": "string"
83
- },
84
- "favicon": {
85
- "type": "string"
86
- }
87
- }
88
- },
89
- "message": {
90
- "required": [
91
- "type",
92
- "content"
93
- ],
94
- "additionalProperties": true,
95
- "properties": {
96
- "type": {
97
- "enum": [
98
- "message"
99
- ]
100
- },
101
- "id": {
102
- "type": "string"
103
- },
104
- "name": {
105
- "type": "string"
106
- },
107
- "content": {
108
- "type": "string"
109
- }
110
- }
111
- },
112
- "me": {
113
- "required": [
114
- "type",
115
- "content"
116
- ],
117
- "additionalProperties": true,
118
- "properties": {
119
- "type": {
120
- "enum": [
121
- "me"
122
- ]
123
- },
124
- "content": {
125
- "type": "string"
126
- }
127
- }
128
- },
129
- "person": {
130
- "required": [
131
- "id",
132
- "type"
133
- ],
134
- "additionalProperties": true,
135
- "properties": {
136
- "id": {
137
- "type": "string"
138
- },
139
- "type": {
140
- "enum": [
141
- "person"
142
- ]
143
- },
144
- "name": {
145
- "type": "string"
146
- }
147
- }
148
- },
149
- "room": {
150
- "required": [
151
- "id",
152
- "type"
153
- ],
154
- "additionalProperties": true,
155
- "properties": {
156
- "id": {
157
- "type": "string"
158
- },
159
- "type": {
160
- "enum": [
161
- "room"
162
- ]
163
- },
164
- "name": {
165
- "type": "string"
166
- }
167
- }
168
- },
169
- "service": {
170
- "required": [
171
- "id",
172
- "type"
173
- ],
174
- "additionalProperties": true,
175
- "properties": {
176
- "id": {
177
- "type": "string"
178
- },
179
- "type": {
180
- "enum": [
181
- "service"
182
- ]
183
- },
184
- "name": {
185
- "type": "string"
186
- }
187
- }
188
- },
189
- "platform": {
190
- "required": [
191
- "id",
192
- "type"
193
- ],
194
- "additionalProperties": true,
195
- "properties": {
196
- "id": {
197
- "type": "string"
198
- },
199
- "type": {
200
- "enum": [
201
- "platform"
202
- ]
203
- },
204
- "name": {
205
- "type": "string"
206
- }
207
- }
208
- },
209
- "website": {
210
- "required": [
211
- "id",
212
- "type"
213
- ],
214
- "additionalProperties": true,
215
- "properties": {
216
- "id": {
217
- "type": "string",
218
- "format": "iri"
219
- },
220
- "type": {
221
- "enum": [
222
- "website"
223
- ]
224
- },
225
- "name": {
226
- "type": "string"
227
- }
228
- }
229
- },
230
- "attendance": {
231
- "required": [
232
- "type"
233
- ],
234
- "additionalProperties": false,
235
- "properties": {
236
- "type": {
237
- "enum": [
238
- "attendance"
239
- ]
240
- },
241
- "members": {
242
- "type": "array",
243
- "items": {
244
- "type": "string"
245
- }
246
- }
247
- }
248
- },
249
- "presence": {
250
- "required": [
251
- "type"
252
- ],
253
- "additionalProperties": false,
254
- "properties": {
255
- "type": {
256
- "enum": [
257
- "presence"
258
- ]
259
- },
260
- "presence": {
261
- "enum": [
262
- "away",
263
- "chat",
264
- "dnd",
265
- "xa",
266
- "offline",
267
- "online"
268
- ]
269
- },
270
- "role": {
271
- "enum": [
272
- "owner",
273
- "member",
274
- "participant",
275
- "admin"
276
- ]
277
- },
278
- "content": {
279
- "type": "string"
280
- }
281
- }
282
- },
283
- "relationship": {
284
- "required": [
285
- "type",
286
- "relationship"
287
- ],
288
- "additionalProperties": false,
289
- "properties": {
290
- "type": {
291
- "enum": [
292
- "relationship"
293
- ]
294
- },
295
- "relationship": {
296
- "enum": [
297
- "role"
298
- ]
299
- },
300
- "subject": {
301
- "type": "object",
302
- "oneOf": [
303
- {
304
- "$ref": "#/definitions/type/presence"
305
- }
306
- ]
307
- },
308
- "object": {
309
- "type": "object",
310
- "oneOf": [
311
- {
312
- "$ref": "#/definitions/type/feed"
313
- },
314
- {
315
- "$ref": "#/definitions/type/message"
316
- },
317
- {
318
- "$ref": "#/definitions/type/me"
319
- },
320
- {
321
- "$ref": "#/definitions/type/person"
322
- },
323
- {
324
- "$ref": "#/definitions/type/room"
325
- },
326
- {
327
- "$ref": "#/definitions/type/service"
328
- },
329
- {
330
- "$ref": "#/definitions/type/platform"
331
- },
332
- {
333
- "$ref": "#/definitions/type/website"
334
- },
335
- {
336
- "$ref": "#/definitions/type/attendance"
337
- },
338
- {
339
- "$ref": "#/definitions/type/presence"
340
- },
341
- {
342
- "$ref": "#/definitions/type/relationship"
343
- },
344
- {
345
- "$ref": "#/definitions/type/topic"
346
- },
347
- {
348
- "$ref": "#/definitions/type/address"
349
- },
350
- {
351
- "$ref": "#/definitions/type/heartbeat"
352
- }
353
- ]
354
- }
355
- }
356
- },
357
- "topic": {
358
- "required": [
359
- "type"
360
- ],
361
- "additionalProperties": false,
362
- "properties": {
363
- "type": {
364
- "enum": [
365
- "topic"
366
- ]
367
- },
368
- "content": {
369
- "type": "string"
370
- }
371
- }
372
- },
373
- "address": {
374
- "required": [
375
- "type"
376
- ],
377
- "additionalProperties": false,
378
- "properties": {
379
- "type": {
380
- "enum": [
381
- "address"
382
- ]
383
- }
384
- }
385
- },
386
- "heartbeat": {
387
- "required": [
388
- "type",
389
- "timestamp"
390
- ],
391
- "additionalProperties": false,
392
- "properties": {
393
- "type": {
394
- "enum": [
395
- "heartbeat"
396
- ]
397
- },
398
- "timestamp": {
399
- "type": "number"
400
- }
401
- }
402
- }
403
- }
404
- }
405
- }