@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.
- package/package.json +16 -32
- package/src/index.ts +23 -19
- package/src/schemas/activity-object.ts +15 -15
- package/src/schemas/activity-stream.ts +40 -41
- package/{dist → src}/schemas/json/activity-object.json +1 -1
- package/{dist → src}/schemas/json/activity-stream.json +1 -1
- package/{dist → src}/schemas/json/platform.json +1 -0
- package/src/schemas/json/sockethub-config.json +144 -0
- package/src/schemas/platform.ts +22 -22
- package/src/schemas/sockethub-config.ts +140 -0
- package/dist/helpers/error-parser.d.ts +0 -9
- package/dist/helpers/error-parser.js +0 -90
- package/dist/helpers/objects.d.ts +0 -206
- package/dist/helpers/objects.js +0 -217
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -37
- package/dist/index.test.data.credentials.d.ts +0 -37
- package/dist/index.test.data.credentials.js +0 -69
- package/dist/index.test.data.objects.d.ts +0 -50
- package/dist/index.test.data.objects.js +0 -214
- package/dist/index.test.data.platform.d.ts +0 -44
- package/dist/index.test.data.platform.js +0 -47
- package/dist/index.test.data.streams.d.ts +0 -274
- package/dist/index.test.data.streams.js +0 -473
- package/dist/schemas/activity-object.d.ts +0 -16
- package/dist/schemas/activity-object.js +0 -18
- package/dist/schemas/activity-stream.d.ts +0 -239
- package/dist/schemas/activity-stream.js +0 -53
- package/dist/schemas/platform.d.ts +0 -41
- package/dist/schemas/platform.js +0 -44
- package/dist/types.d.ts +0 -34
- package/dist/types.js +0 -2
- package/dist/validator.d.ts +0 -8
- package/dist/validator.js +0 -80
- package/src/helpers/error-parser.ts +0 -96
- package/src/helpers/objects.ts +0 -230
- package/src/index.test.data.credentials.ts +0 -71
- package/src/index.test.data.objects.ts +0 -235
- package/src/index.test.data.platform.ts +0 -45
- package/src/index.test.data.streams.ts +0 -495
- package/src/index.test.ts +0 -85
- package/src/types.ts +0 -42
- package/src/validator.ts +0 -81
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import {ObjectTypesList} from './helpers/objects';
|
|
2
|
-
|
|
3
|
-
export default [
|
|
4
|
-
[
|
|
5
|
-
'type:send, object:message',
|
|
6
|
-
{
|
|
7
|
-
type: 'send',
|
|
8
|
-
context: 'irc',
|
|
9
|
-
actor: {
|
|
10
|
-
id: 'dood@irc.freenode.net',
|
|
11
|
-
type: 'person',
|
|
12
|
-
name: 'dood'
|
|
13
|
-
},
|
|
14
|
-
target: {
|
|
15
|
-
id: 'irc.freenode.net/server',
|
|
16
|
-
type: 'room',
|
|
17
|
-
name: 'sockethub'
|
|
18
|
-
},
|
|
19
|
-
object: {
|
|
20
|
-
type: 'message',
|
|
21
|
-
content: 'some kind of message'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
true,
|
|
25
|
-
''
|
|
26
|
-
],
|
|
27
|
-
|
|
28
|
-
[
|
|
29
|
-
'type:send, object:message bad published value',
|
|
30
|
-
{
|
|
31
|
-
type: 'send',
|
|
32
|
-
context: 'irc',
|
|
33
|
-
published: "foo",
|
|
34
|
-
actor: {
|
|
35
|
-
id: 'dood@irc.freenode.net',
|
|
36
|
-
type: 'person',
|
|
37
|
-
name: 'dood'
|
|
38
|
-
},
|
|
39
|
-
target: {
|
|
40
|
-
id: 'irc.freenode.net/server',
|
|
41
|
-
type: 'room',
|
|
42
|
-
name: 'sockethub'
|
|
43
|
-
},
|
|
44
|
-
object: {
|
|
45
|
-
type: 'message',
|
|
46
|
-
content: 'some kind of message'
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
false,
|
|
50
|
-
'/published: must match format "date-time"'
|
|
51
|
-
],
|
|
52
|
-
|
|
53
|
-
[
|
|
54
|
-
'type:credentials, object:credentials',
|
|
55
|
-
{
|
|
56
|
-
type: 'credentials',
|
|
57
|
-
context: 'irc',
|
|
58
|
-
actor: {
|
|
59
|
-
id: 'dood@irc.freenode.net',
|
|
60
|
-
type: 'person',
|
|
61
|
-
name: 'dood'
|
|
62
|
-
},
|
|
63
|
-
target: {
|
|
64
|
-
id: 'irc.freenode.net/server',
|
|
65
|
-
type: 'room',
|
|
66
|
-
name: 'sockethub'
|
|
67
|
-
},
|
|
68
|
-
object: {
|
|
69
|
-
type: 'credentials'
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
true,
|
|
73
|
-
''
|
|
74
|
-
],
|
|
75
|
-
|
|
76
|
-
[
|
|
77
|
-
'type:credentials',
|
|
78
|
-
{
|
|
79
|
-
context: 'irc',
|
|
80
|
-
type: 'credentials',
|
|
81
|
-
actor: {
|
|
82
|
-
id: 'dood@irc.freenode.net',
|
|
83
|
-
type: 'person',
|
|
84
|
-
name: 'dood'
|
|
85
|
-
},
|
|
86
|
-
object: {
|
|
87
|
-
type: 'credentials',
|
|
88
|
-
user: "foo",
|
|
89
|
-
pass: "bar"
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
true,
|
|
93
|
-
''
|
|
94
|
-
],
|
|
95
|
-
|
|
96
|
-
[
|
|
97
|
-
'bad target',
|
|
98
|
-
{
|
|
99
|
-
id: 'blah',
|
|
100
|
-
type: 'send',
|
|
101
|
-
context: 'dood',
|
|
102
|
-
actor: {
|
|
103
|
-
id: 'dood@irc.freenode.net',
|
|
104
|
-
type: 'person',
|
|
105
|
-
name: 'dood'
|
|
106
|
-
},
|
|
107
|
-
target: {
|
|
108
|
-
type: 'person',
|
|
109
|
-
name: 'bob'
|
|
110
|
-
},
|
|
111
|
-
object: {
|
|
112
|
-
type: 'credentials'
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
false,
|
|
116
|
-
'/target: must have required property \'id\''
|
|
117
|
-
],
|
|
118
|
-
|
|
119
|
-
[
|
|
120
|
-
'bad iri in object id',
|
|
121
|
-
{
|
|
122
|
-
type: 'feed',
|
|
123
|
-
context: 'dood',
|
|
124
|
-
actor: {
|
|
125
|
-
id: 'dood@irc.freenode.net',
|
|
126
|
-
type: 'person'
|
|
127
|
-
},
|
|
128
|
-
object: {
|
|
129
|
-
id: 'example.org/some/path.html',
|
|
130
|
-
type: 'website'
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
false,
|
|
134
|
-
'/object/id: must match format "iri"'
|
|
135
|
-
],
|
|
136
|
-
|
|
137
|
-
[
|
|
138
|
-
'valid iri in object id',
|
|
139
|
-
{
|
|
140
|
-
type: 'feed',
|
|
141
|
-
context: 'dood',
|
|
142
|
-
actor: {
|
|
143
|
-
id: 'dood@irc.freenode.net',
|
|
144
|
-
type: 'person'
|
|
145
|
-
},
|
|
146
|
-
object: {
|
|
147
|
-
id: 'https://example.org/some/path.html',
|
|
148
|
-
type: 'website'
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
true,
|
|
152
|
-
''
|
|
153
|
-
],
|
|
154
|
-
|
|
155
|
-
[
|
|
156
|
-
'wrong actor type',
|
|
157
|
-
{
|
|
158
|
-
type: 'send',
|
|
159
|
-
context: 'dood',
|
|
160
|
-
actor: {
|
|
161
|
-
id: 'doobar@freenode.net/channel',
|
|
162
|
-
type: 'foo',
|
|
163
|
-
content: 'hi there'
|
|
164
|
-
},
|
|
165
|
-
object: {
|
|
166
|
-
type: 'feed',
|
|
167
|
-
id: 'http://rss.example.org/feed.rss'
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
false,
|
|
171
|
-
`/actor: must match exactly one schema in oneOf: ${ObjectTypesList.join(', ')}`
|
|
172
|
-
],
|
|
173
|
-
|
|
174
|
-
[
|
|
175
|
-
'missing actor id',
|
|
176
|
-
{
|
|
177
|
-
id: 'blah',
|
|
178
|
-
type: 'send',
|
|
179
|
-
context: 'dood',
|
|
180
|
-
actor: {
|
|
181
|
-
type: 'person',
|
|
182
|
-
name: 'dood'
|
|
183
|
-
},
|
|
184
|
-
target: {
|
|
185
|
-
id: 'bob@crusty.net/Home',
|
|
186
|
-
type: 'person',
|
|
187
|
-
name: 'bob'
|
|
188
|
-
},
|
|
189
|
-
object: {
|
|
190
|
-
type: 'feed',
|
|
191
|
-
id: 'http://rss.example.org/feed.rss'
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
false,
|
|
195
|
-
'/actor: must have required property \'id\''
|
|
196
|
-
],
|
|
197
|
-
|
|
198
|
-
[
|
|
199
|
-
'attendance request',
|
|
200
|
-
{
|
|
201
|
-
id: 'blah',
|
|
202
|
-
type: 'observe',
|
|
203
|
-
context: 'dood',
|
|
204
|
-
actor: {
|
|
205
|
-
id: 'dood',
|
|
206
|
-
type: 'person'
|
|
207
|
-
},
|
|
208
|
-
target: {
|
|
209
|
-
id: 'chatroom@crusty.net',
|
|
210
|
-
type: 'room'
|
|
211
|
-
},
|
|
212
|
-
object: {
|
|
213
|
-
type: 'attendance',
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
true,
|
|
217
|
-
''
|
|
218
|
-
],
|
|
219
|
-
|
|
220
|
-
[
|
|
221
|
-
'attendance response',
|
|
222
|
-
{
|
|
223
|
-
id: 'blah',
|
|
224
|
-
type: 'observe',
|
|
225
|
-
context: 'dood',
|
|
226
|
-
actor: {
|
|
227
|
-
id: 'chatroom@crusty.net',
|
|
228
|
-
type: 'room',
|
|
229
|
-
name: 'chatroom'
|
|
230
|
-
},
|
|
231
|
-
object: {
|
|
232
|
-
type: 'attendance',
|
|
233
|
-
members: ['bill', 'bob', 'hank']
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
true,
|
|
237
|
-
''
|
|
238
|
-
],
|
|
239
|
-
|
|
240
|
-
[
|
|
241
|
-
'invalid attendance request',
|
|
242
|
-
{
|
|
243
|
-
id: 'blah',
|
|
244
|
-
type: 'observe',
|
|
245
|
-
context: 'dood',
|
|
246
|
-
actor: {
|
|
247
|
-
id: 'dood',
|
|
248
|
-
type: 'person'
|
|
249
|
-
},
|
|
250
|
-
target: {
|
|
251
|
-
id: 'chatroom@crusty.net',
|
|
252
|
-
type: 'room'
|
|
253
|
-
},
|
|
254
|
-
object: {
|
|
255
|
-
type: 'attendance',
|
|
256
|
-
status: 'foobar'
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
false,
|
|
260
|
-
'/object: must NOT have additional properties: status'
|
|
261
|
-
],
|
|
262
|
-
|
|
263
|
-
[
|
|
264
|
-
'setting presence',
|
|
265
|
-
{
|
|
266
|
-
id: 'blah',
|
|
267
|
-
type: 'observe',
|
|
268
|
-
context: 'dood',
|
|
269
|
-
actor: {
|
|
270
|
-
id: 'dood',
|
|
271
|
-
type: 'person'
|
|
272
|
-
},
|
|
273
|
-
object: {
|
|
274
|
-
type: 'presence',
|
|
275
|
-
presence: 'away',
|
|
276
|
-
content: 'forgot the milk'
|
|
277
|
-
},
|
|
278
|
-
target: {
|
|
279
|
-
id: 'chatroom@crusty.net',
|
|
280
|
-
type: 'room'
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
true,
|
|
284
|
-
''
|
|
285
|
-
],
|
|
286
|
-
|
|
287
|
-
[
|
|
288
|
-
'setting invalid presence',
|
|
289
|
-
{
|
|
290
|
-
id: 'blah',
|
|
291
|
-
type: 'observe',
|
|
292
|
-
context: 'dood',
|
|
293
|
-
actor: {
|
|
294
|
-
id: 'dood',
|
|
295
|
-
type: 'person'
|
|
296
|
-
},
|
|
297
|
-
object: {
|
|
298
|
-
type: 'presence',
|
|
299
|
-
presence: 'afk',
|
|
300
|
-
content: 'forgot the milk'
|
|
301
|
-
},
|
|
302
|
-
target: {
|
|
303
|
-
id: 'chatroom@crusty.net',
|
|
304
|
-
type: 'room'
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
false,
|
|
308
|
-
'/object/presence: must be equal to one of the allowed values: ' +
|
|
309
|
-
'away, chat, dnd, xa, offline, online'
|
|
310
|
-
],
|
|
311
|
-
|
|
312
|
-
[
|
|
313
|
-
'setting topic',
|
|
314
|
-
{
|
|
315
|
-
id: 'blah',
|
|
316
|
-
type: 'observe',
|
|
317
|
-
context: 'dood',
|
|
318
|
-
actor: {
|
|
319
|
-
id: 'dood',
|
|
320
|
-
type: 'person'
|
|
321
|
-
},
|
|
322
|
-
object: {
|
|
323
|
-
type: 'topic',
|
|
324
|
-
content: 'the topic is goats'
|
|
325
|
-
},
|
|
326
|
-
target: {
|
|
327
|
-
id: 'chatroom@crusty.net',
|
|
328
|
-
type: 'room'
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
true,
|
|
332
|
-
''
|
|
333
|
-
],
|
|
334
|
-
|
|
335
|
-
[
|
|
336
|
-
'setting topic incorrectly',
|
|
337
|
-
{
|
|
338
|
-
id: 'blah',
|
|
339
|
-
type: 'observe',
|
|
340
|
-
context: 'dood',
|
|
341
|
-
actor: {
|
|
342
|
-
id: 'dood',
|
|
343
|
-
type: 'person'
|
|
344
|
-
},
|
|
345
|
-
object: {
|
|
346
|
-
type: 'topic',
|
|
347
|
-
topic: 'the topic is goats'
|
|
348
|
-
},
|
|
349
|
-
target: {
|
|
350
|
-
id: 'chatroom@crusty.net',
|
|
351
|
-
type: 'room'
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
false,
|
|
355
|
-
'/object: must NOT have additional properties: topic'
|
|
356
|
-
],
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
[
|
|
360
|
-
'receive topic',
|
|
361
|
-
{
|
|
362
|
-
id: 'blah',
|
|
363
|
-
type: 'observe',
|
|
364
|
-
context: 'dood',
|
|
365
|
-
actor: {
|
|
366
|
-
id: 'chatroom@crusty.net',
|
|
367
|
-
type: 'room'
|
|
368
|
-
},
|
|
369
|
-
object: {
|
|
370
|
-
type: 'topic',
|
|
371
|
-
content: 'the topic is goats'
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
true,
|
|
375
|
-
''
|
|
376
|
-
],
|
|
377
|
-
|
|
378
|
-
[
|
|
379
|
-
'change user address',
|
|
380
|
-
{
|
|
381
|
-
id: 'blah',
|
|
382
|
-
type: 'update',
|
|
383
|
-
context: 'dood',
|
|
384
|
-
actor: {
|
|
385
|
-
id: 'foobar@example.com',
|
|
386
|
-
type: 'person'
|
|
387
|
-
},
|
|
388
|
-
object: {
|
|
389
|
-
type: 'address'
|
|
390
|
-
},
|
|
391
|
-
target: {
|
|
392
|
-
id: 'futurebar@example.com',
|
|
393
|
-
type: 'person'
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
true,
|
|
397
|
-
''
|
|
398
|
-
],
|
|
399
|
-
|
|
400
|
-
[
|
|
401
|
-
'change user address incorrectly',
|
|
402
|
-
{
|
|
403
|
-
type: 'update',
|
|
404
|
-
context: 'dood',
|
|
405
|
-
actor: {
|
|
406
|
-
id: 'foobar@example.com',
|
|
407
|
-
type: 'person'
|
|
408
|
-
},
|
|
409
|
-
object: {
|
|
410
|
-
type: 'address',
|
|
411
|
-
id: 'futurebar@example.com',
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
false,
|
|
415
|
-
'/object: must NOT have additional properties: id'
|
|
416
|
-
],
|
|
417
|
-
|
|
418
|
-
[
|
|
419
|
-
'invalid activity stream',
|
|
420
|
-
{
|
|
421
|
-
"actor": { "id": "irc://uuu@localhost", "type": "person" },
|
|
422
|
-
"context":"irc",
|
|
423
|
-
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
424
|
-
},
|
|
425
|
-
false,
|
|
426
|
-
'activity stream: must have required property \'type\''
|
|
427
|
-
],
|
|
428
|
-
|
|
429
|
-
[
|
|
430
|
-
'invalid room',
|
|
431
|
-
{
|
|
432
|
-
"context":"irc",
|
|
433
|
-
"type":"credentials",
|
|
434
|
-
"actor":{
|
|
435
|
-
"id":"sh-9K3Vk@irc.freenode.net",
|
|
436
|
-
"type":"person",
|
|
437
|
-
},
|
|
438
|
-
"target": {
|
|
439
|
-
"type":"room",
|
|
440
|
-
"name":"sh-9K3Vk"
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
false,
|
|
444
|
-
'/target: must have required property \'id\''
|
|
445
|
-
],
|
|
446
|
-
|
|
447
|
-
[
|
|
448
|
-
'relationship',
|
|
449
|
-
{
|
|
450
|
-
"context":"irc",
|
|
451
|
-
"type":"add",
|
|
452
|
-
"actor":{"type":"person", "id":"alice@localhost", "name":"alice"},
|
|
453
|
-
"target":{"type":"person", "id":"Kilroy@localhost", "name":"Kilroy"},
|
|
454
|
-
"object":{
|
|
455
|
-
"type":"relationship",
|
|
456
|
-
"relationship":"role",
|
|
457
|
-
"subject": {
|
|
458
|
-
"type":"presence",
|
|
459
|
-
"role":"owner"
|
|
460
|
-
},
|
|
461
|
-
"object":{
|
|
462
|
-
"type":"room",
|
|
463
|
-
"id":"localhost/#Finnish",
|
|
464
|
-
"name":"#Finnish"
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
},
|
|
468
|
-
true, ""
|
|
469
|
-
],
|
|
470
|
-
|
|
471
|
-
[
|
|
472
|
-
'invalid role in relationship',
|
|
473
|
-
{
|
|
474
|
-
"context":"irc",
|
|
475
|
-
"type":"add",
|
|
476
|
-
"actor":{"type":"person", "id":"alice@localhost", "name":"alice"},
|
|
477
|
-
"target":{"type":"person", "id":"Kilroy@localhost", "name":"Kilroy"},
|
|
478
|
-
"object":{
|
|
479
|
-
"type":"relationship",
|
|
480
|
-
"relationship":"role",
|
|
481
|
-
"subject": {
|
|
482
|
-
"type":"presence",
|
|
483
|
-
"role":"manager"
|
|
484
|
-
},
|
|
485
|
-
"object":{
|
|
486
|
-
"type":"room",
|
|
487
|
-
"id":"localhost/#Finnish",
|
|
488
|
-
"name":"#Finnish"
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
false, "/object/subject/role: must be equal to one of the allowed values: " +
|
|
493
|
-
"owner, member, participant, admin"
|
|
494
|
-
]
|
|
495
|
-
];
|
package/src/index.test.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import {IActivityStream} from "./types";
|
|
2
|
-
|
|
3
|
-
const chai = require('chai');
|
|
4
|
-
const expect = chai.expect;
|
|
5
|
-
|
|
6
|
-
import ActivityStreamSchema from './schemas/activity-stream';
|
|
7
|
-
import ActivityObjectSchema from './schemas/activity-object';
|
|
8
|
-
import {
|
|
9
|
-
validatePlatformSchema, addPlatformSchema, validateActivityObject,
|
|
10
|
-
validateActivityStream, validateCredentials, getPlatformSchema
|
|
11
|
-
} from './validator';
|
|
12
|
-
import testCredentialsData from './index.test.data.credentials';
|
|
13
|
-
import testActivityObjectsData from './index.test.data.objects';
|
|
14
|
-
import testActivityStreamsData from './index.test.data.streams';
|
|
15
|
-
import testPlatformSchemaData from './index.test.data.platform';
|
|
16
|
-
|
|
17
|
-
describe('Platform schema validation', () => {
|
|
18
|
-
it('returns an empty error for a valid schema', () => {
|
|
19
|
-
let err = validatePlatformSchema(testPlatformSchemaData);
|
|
20
|
-
expect(err).to.equal("");
|
|
21
|
-
});
|
|
22
|
-
it('returns an error for an invalid schema', () => {
|
|
23
|
-
let err = validatePlatformSchema({foo: 'bar'});
|
|
24
|
-
expect(err).to.eql('platform schema failed to validate: must have required property \'name\'');
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
describe("Adding a PlatformSchema", () => {
|
|
30
|
-
it('returns the same schema when fetched', () => {
|
|
31
|
-
const platform_type = 'test-platform/credentials';
|
|
32
|
-
addPlatformSchema(testPlatformSchemaData.credentials, platform_type);
|
|
33
|
-
const compiledSchema = getPlatformSchema(platform_type);
|
|
34
|
-
expect(compiledSchema.schema).to.eql(testPlatformSchemaData.credentials);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
describe('Credentials', () => {
|
|
40
|
-
testCredentialsData.forEach(([name, creds, expectedResult, expectedFailureMessage]) => {
|
|
41
|
-
describe("validateCredential " + name, () => {
|
|
42
|
-
it(`returns expected result`, () => {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
const err = validateCredentials(creds);
|
|
45
|
-
expect(err).to.equal(expectedFailureMessage);
|
|
46
|
-
expect(!err).to.equal(expectedResult);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('ActivityObject', () => {
|
|
53
|
-
it('has expected properties', () => {
|
|
54
|
-
expect(typeof ActivityObjectSchema).to.equal('object');
|
|
55
|
-
expect(ActivityObjectSchema['$id']).to.equal('https://sockethub.org/schemas/v0/activity-object#');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
testActivityObjectsData.forEach(([name, ao, expectedResult, expectedFailureMessage]) => {
|
|
59
|
-
describe("validateActivityObject " + name, () => {
|
|
60
|
-
it(`returns expected result`, () => {
|
|
61
|
-
const err = validateActivityObject(ao as IActivityStream);
|
|
62
|
-
expect(err).to.equal(expectedFailureMessage);
|
|
63
|
-
expect(!err).to.equal(expectedResult);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('ActivityStream', () => {
|
|
70
|
-
it('has expected properties', () => {
|
|
71
|
-
expect(typeof ActivityStreamSchema).to.equal('object');
|
|
72
|
-
expect(ActivityStreamSchema['$id']).to.equal('https://sockethub.org/schemas/v0/activity-stream#');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
testActivityStreamsData.forEach(([name, as, expectedResult, expectedFailureMessage]) => {
|
|
76
|
-
describe("validateActivityStream " + name, () => {
|
|
77
|
-
it(`returns expected result`, () => {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
const err = validateActivityStream(as);
|
|
80
|
-
expect(err).to.equal(expectedFailureMessage);
|
|
81
|
-
expect(!err).to.equal(expectedResult);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
package/src/types.ts
DELETED
|
@@ -1,42 +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
|
-
|
|
11
|
-
export interface IActivityObject {
|
|
12
|
-
id?: string;
|
|
13
|
-
type: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IActivityObjectActor extends IActivityObject {
|
|
17
|
-
id: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface IActivityObjectObject extends IActivityObject {
|
|
22
|
-
content?: never;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type ErrorMsg = string | Error;
|
|
26
|
-
|
|
27
|
-
export interface CallbackInterface {
|
|
28
|
-
(err?: ErrorMsg, data?: unknown): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface CallbackActivityStreamInterface {
|
|
32
|
-
(data: IActivityStream | Error): void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface CompletedJobHandler {
|
|
36
|
-
(data: IActivityStream): void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface LogInterface {
|
|
40
|
-
(msg: string): void;
|
|
41
|
-
}
|
|
42
|
-
|
package/src/validator.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
|
-
import Ajv, {Schema} from 'ajv';
|
|
3
|
-
import addFormats from 'ajv-formats';
|
|
4
|
-
import additionsFormats2019 from 'ajv-formats-draft2019';
|
|
5
|
-
import getErrorMessage from "./helpers/error-parser";
|
|
6
|
-
import {IActivityStream} from "./types";
|
|
7
|
-
import PlatformSchema from './schemas/platform';
|
|
8
|
-
import ActivityStreamsSchema from './schemas/activity-stream';
|
|
9
|
-
import ActivityObjectSchema from './schemas/activity-object';
|
|
10
|
-
const log = debug('sockethub:schemas');
|
|
11
|
-
const ajv = new Ajv({strictTypes: false, allErrors: true});
|
|
12
|
-
addFormats(ajv);
|
|
13
|
-
additionsFormats2019(ajv);
|
|
14
|
-
|
|
15
|
-
interface SchemasDict {
|
|
16
|
-
string?: Schema
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const schemaURL = 'https://sockethub.org/schemas/v0';
|
|
20
|
-
const schemas: SchemasDict = {};
|
|
21
|
-
|
|
22
|
-
schemas[`${schemaURL}/activity-stream`] = ActivityStreamsSchema;
|
|
23
|
-
schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
|
|
24
|
-
|
|
25
|
-
for (const uri in schemas) {
|
|
26
|
-
log(`registering schema ${uri}`);
|
|
27
|
-
ajv.addSchema(schemas[uri], uri);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function handleValidation(schemaRef: string, msg: IActivityStream, isObject=false): string {
|
|
31
|
-
const validator = ajv.getSchema(schemaRef);
|
|
32
|
-
let result: boolean | Promise<unknown>;
|
|
33
|
-
if (isObject) {
|
|
34
|
-
result = validator({ object: msg });
|
|
35
|
-
} else {
|
|
36
|
-
result = validator(msg);
|
|
37
|
-
}
|
|
38
|
-
if (! result) {
|
|
39
|
-
return getErrorMessage(msg, validator.errors);
|
|
40
|
-
}
|
|
41
|
-
return "";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function validateActivityObject(msg: IActivityStream): string {
|
|
45
|
-
return handleValidation(`${schemaURL}/activity-object`, msg, true);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function validateActivityStream(msg: IActivityStream): string {
|
|
49
|
-
return handleValidation(`${schemaURL}/activity-stream`, msg);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function validateCredentials(msg: IActivityStream): string {
|
|
53
|
-
if (!msg.context) {
|
|
54
|
-
return 'credential activity streams must have a context set';
|
|
55
|
-
}
|
|
56
|
-
if (msg.type !== 'credentials') {
|
|
57
|
-
return 'credential activity streams must have credentials set as type';
|
|
58
|
-
}
|
|
59
|
-
return handleValidation(`${schemaURL}/context/${msg.context}/credentials`, msg);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function validatePlatformSchema(schema: Schema): string {
|
|
63
|
-
const validate = ajv.compile(PlatformSchema);
|
|
64
|
-
// validate schema property
|
|
65
|
-
const err = validate(schema);
|
|
66
|
-
if (! err) {
|
|
67
|
-
return `platform schema failed to validate: ` +
|
|
68
|
-
`${validate.errors[0].instancePath} ${validate.errors[0].message}`;
|
|
69
|
-
} else {
|
|
70
|
-
return "";
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function addPlatformSchema(schema: Schema, platform_type: string) {
|
|
75
|
-
log(`registering schema ${schemaURL}/context/${platform_type}`);
|
|
76
|
-
ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getPlatformSchema(platform_type: string) {
|
|
80
|
-
return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
|
|
81
|
-
}
|