sockethub 4.0.0 → 5.0.0-alpha.0

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 (140) hide show
  1. package/README.md +3 -3
  2. package/bin/sockethub +23 -19
  3. package/coverage/tmp/coverage-15699-1646422276150-0.json +1 -0
  4. package/dist/bootstrap/init.js +14 -4
  5. package/dist/bootstrap/init.js.map +1 -1
  6. package/dist/bootstrap/platforms.js +81 -69
  7. package/dist/common.js +10 -12
  8. package/dist/common.js.map +1 -1
  9. package/dist/config.js +4 -22
  10. package/dist/config.js.map +1 -1
  11. package/dist/crypto.js +7 -8
  12. package/dist/crypto.js.map +1 -1
  13. package/dist/janitor.js +14 -9
  14. package/dist/janitor.js.map +1 -1
  15. package/dist/middleware/create-activity-object.js +19 -0
  16. package/dist/middleware/create-activity-object.js.map +1 -0
  17. package/dist/middleware/expand-activity-stream.js +33 -0
  18. package/dist/middleware/expand-activity-stream.js.map +1 -0
  19. package/dist/middleware/expand-activity-stream.test.data.js +360 -0
  20. package/dist/middleware/expand-activity-stream.test.data.js.map +1 -0
  21. package/dist/middleware/store-credentials.js +19 -0
  22. package/dist/middleware/store-credentials.js.map +1 -0
  23. package/dist/middleware/validate.js +77 -0
  24. package/dist/middleware/validate.js.map +1 -0
  25. package/dist/middleware/validate.test.data.js +321 -0
  26. package/dist/middleware/validate.test.data.js.map +1 -0
  27. package/dist/middleware.js +47 -49
  28. package/dist/middleware.js.map +1 -1
  29. package/dist/platform-instance.js +84 -66
  30. package/dist/platform-instance.js.map +1 -1
  31. package/dist/platform.js +50 -25
  32. package/dist/platform.js.map +1 -1
  33. package/dist/process-manager.js +7 -4
  34. package/dist/process-manager.js.map +1 -1
  35. package/dist/routes.js +9 -7
  36. package/dist/routes.js.map +1 -1
  37. package/dist/serve.js +3 -3
  38. package/dist/serve.js.map +1 -1
  39. package/dist/sockethub-client.js +2604 -0
  40. package/dist/sockethub-client.js.map +1 -0
  41. package/dist/sockethub-client.min.js +2 -0
  42. package/dist/sockethub-client.min.js.LICENSE.txt +24 -0
  43. package/dist/sockethub.js +75 -58
  44. package/dist/sockethub.js.map +1 -1
  45. package/dist/store.js +17 -0
  46. package/dist/store.js.map +1 -0
  47. package/package.json +48 -44
  48. package/src/bootstrap/init.ts +16 -2
  49. package/src/bootstrap/platforms.js +14 -18
  50. package/src/common.test.ts +44 -33
  51. package/src/common.ts +9 -17
  52. package/src/config.test.ts +16 -38
  53. package/src/config.ts +1 -23
  54. package/src/crypto.test.ts +15 -17
  55. package/src/crypto.ts +4 -5
  56. package/src/janitor.ts +19 -12
  57. package/src/middleware/create-activity-object.test.ts +10 -0
  58. package/src/middleware/create-activity-object.ts +13 -0
  59. package/src/middleware/expand-activity-stream.test.data.ts +365 -0
  60. package/src/middleware/expand-activity-stream.test.ts +78 -0
  61. package/src/middleware/expand-activity-stream.ts +27 -0
  62. package/src/middleware/store-credentials.test.ts +72 -0
  63. package/src/middleware/store-credentials.ts +16 -0
  64. package/src/{validate.d.ts → middleware/validate.d.ts} +0 -0
  65. package/src/middleware/validate.test.data.ts +320 -0
  66. package/src/middleware/validate.test.ts +47 -0
  67. package/src/middleware/validate.ts +49 -0
  68. package/src/middleware.test.ts +148 -0
  69. package/src/middleware.ts +46 -51
  70. package/src/platform-instance.test.ts +224 -196
  71. package/src/platform-instance.ts +74 -58
  72. package/src/platform.ts +44 -24
  73. package/src/process-manager.ts +7 -4
  74. package/src/routes.test.ts +32 -17
  75. package/src/routes.ts +8 -6
  76. package/src/serve.ts +1 -1
  77. package/src/sockethub-client.test.ts +235 -0
  78. package/src/sockethub-client.ts +164 -0
  79. package/src/sockethub.ts +96 -93
  80. package/src/store.test.ts +26 -0
  81. package/src/store.ts +17 -0
  82. package/tsconfig.json +8 -8
  83. package/views/examples/dummy.ejs +7 -7
  84. package/views/examples/feeds.ejs +10 -10
  85. package/views/examples/irc.ejs +65 -59
  86. package/views/examples/shared.js +31 -29
  87. package/views/examples/xmpp.ejs +49 -58
  88. package/webpack.minified.config.js +14 -0
  89. package/webpack.normal.config.js +14 -0
  90. package/coverage/clover.xml +0 -190
  91. package/coverage/coverage-final.json +0 -6
  92. package/coverage/lcov-report/base.css +0 -224
  93. package/coverage/lcov-report/block-navigation.js +0 -79
  94. package/coverage/lcov-report/common.ts.html +0 -143
  95. package/coverage/lcov-report/config.ts.html +0 -359
  96. package/coverage/lcov-report/crypto.ts.html +0 -203
  97. package/coverage/lcov-report/favicon.png +0 -0
  98. package/coverage/lcov-report/index.html +0 -171
  99. package/coverage/lcov-report/platform-instance.ts.html +0 -740
  100. package/coverage/lcov-report/prettify.css +0 -1
  101. package/coverage/lcov-report/prettify.js +0 -2
  102. package/coverage/lcov-report/routes.ts.html +0 -353
  103. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  104. package/coverage/lcov-report/sorter.js +0 -170
  105. package/coverage/lcov-report/src/common.ts.html +0 -143
  106. package/coverage/lcov-report/src/config.ts.html +0 -359
  107. package/coverage/lcov-report/src/crypto.ts.html +0 -182
  108. package/coverage/lcov-report/src/index.html +0 -156
  109. package/coverage/lcov-report/src/platform-instance.ts.html +0 -740
  110. package/coverage/lcov-report/src/routes/base.ts.html +0 -359
  111. package/coverage/lcov-report/src/routes/examples.ts.html +0 -311
  112. package/coverage/lcov-report/src/routes/index.html +0 -111
  113. package/coverage/lcov-report/src/services/http.ts.html +0 -239
  114. package/coverage/lcov-report/src/services/index.html +0 -111
  115. package/coverage/lcov-report/src/services/redis.ts.html +0 -140
  116. package/coverage/lcov-report/src/shared-resources.ts.html +0 -104
  117. package/coverage/lcov.info +0 -336
  118. package/coverage/tmp/coverage-70996-1620314182345-0.json +0 -1
  119. package/dist/bootstrap/platforms.js.map +0 -1
  120. package/dist/js/client.js +0 -177
  121. package/dist/js/client.js.map +0 -1
  122. package/dist/resource-manager.js +0 -66
  123. package/dist/resource-manager.js.map +0 -1
  124. package/dist/routes/base.js +0 -92
  125. package/dist/routes/base.js.map +0 -1
  126. package/dist/routes/examples.js +0 -93
  127. package/dist/routes/examples.js.map +0 -1
  128. package/dist/services/http.js +0 -68
  129. package/dist/services/http.js.map +0 -1
  130. package/dist/services/redis.js +0 -1
  131. package/dist/services/redis.js.map +0 -1
  132. package/dist/shared-resources.js +0 -11
  133. package/dist/shared-resources.js.map +0 -1
  134. package/dist/validate.js +0 -157
  135. package/dist/validate.js.map +0 -1
  136. package/jest.config.js +0 -18
  137. package/src/js/client.js +0 -190
  138. package/src/validate.ts +0 -147
  139. package/test/middleware-suite.js +0 -101
  140. package/test/validate-suite.js +0 -338
@@ -0,0 +1,365 @@
1
+ export default [
2
+ {
3
+ "name": "not an object",
4
+ "valid": false,
5
+ "type": "message",
6
+ "input": "hello world",
7
+ "error": "Error: message received is not an object."
8
+ },
9
+ {
10
+ "name": "basic invalid type",
11
+ "valid":true,
12
+ "type":"credentials",
13
+ "input":{
14
+ "id":"foo",
15
+ "type":"send",
16
+ "context":"dummy",
17
+ "actor":{
18
+ "id":"dood@irc.freenode.net",
19
+ "type":"person",
20
+ "name":"dood"
21
+ },
22
+ "target":{
23
+ "id":"irc.freenode.net/sockethub",
24
+ "type":"person",
25
+ "name":"sockethub"
26
+ },
27
+ "object":{
28
+ "type":"credentials"
29
+ }
30
+ },
31
+ "output": "same"
32
+ },
33
+ {
34
+ "name": "basic valid type",
35
+ "valid":true,
36
+ "type":"credentials",
37
+ "input":{
38
+ "id":"foo",
39
+ "type":"credentials",
40
+ "context":"dummy",
41
+ "actor":{
42
+ "id":"dood@irc.freenode.net",
43
+ "type":"person",
44
+ "name":"dood"
45
+ },
46
+ "target":{
47
+ "id":"irc.freenode.net/sockethub",
48
+ "type":"person",
49
+ "name":"sockethub"
50
+ },
51
+ "object":{
52
+ "type":"credentials"
53
+ }
54
+ },
55
+ "output":"same"
56
+ },
57
+ {
58
+ "name":"new format",
59
+ "valid":true,
60
+ "type":"credentials",
61
+ "input":{
62
+ "type":"credentials",
63
+ "context":"irc",
64
+ "actor":{
65
+ "id":"sh-9K3Vk@irc.freenode.net",
66
+ "type":"person",
67
+ "name":"sh-9K3Vk",
68
+ "image":{
69
+ "height":250,
70
+ "mediaType":"image/jpeg",
71
+ "url":"http://example.org/image.jpg",
72
+ "width":250
73
+ },
74
+ "url":"http://sockethub.org"
75
+ },
76
+ "object":{
77
+ "type":"credentials",
78
+ "nick":"sh-9K3Vk",
79
+ "port":6667,
80
+ "secure":false,
81
+ "server":"irc.freenode.net"
82
+ }
83
+ },
84
+ "output":"same"
85
+ },
86
+ {
87
+ "name":"no type specified",
88
+ "valid":false,
89
+ "type":"credentials",
90
+ "input":{
91
+ "actor":"hyper_rau@localhost",
92
+ "context":"xmpp",
93
+ "object":{
94
+ "username":"hyper_rau",
95
+ "password":"123",
96
+ "server":"localhost",
97
+ "port":5222,
98
+ "resource":"laptop"
99
+ }
100
+ },
101
+ "error": "Error: activity stream must contain a type property."
102
+ },
103
+ {
104
+ "name": "expand unknown actor",
105
+ "type": "message",
106
+ "valid": "true",
107
+ "input": {
108
+ "context": "foo",
109
+ "type": "bar",
110
+ "actor": "foo@bar",
111
+ "object": {
112
+ "content": "bar"
113
+ }
114
+ },
115
+ "output": {
116
+ "context": "foo",
117
+ "type": "bar",
118
+ "actor": {
119
+ "id": "foo@bar"
120
+ },
121
+ "object": {
122
+ "content": "bar"
123
+ }
124
+ }
125
+ },
126
+ {
127
+ "name": "expand unknown actor 2",
128
+ "type": "message",
129
+ "valid": "true",
130
+ "input": {
131
+ "context": "foo",
132
+ "type": "bar",
133
+ "actor": "someone@example.org/resource",
134
+ "object": {
135
+ "content": "bar"
136
+ }
137
+ },
138
+ "output": {
139
+ "context": "foo",
140
+ "type": "bar",
141
+ "actor": {
142
+ "id": "someone@example.org/resource"
143
+ },
144
+ "object": {
145
+ "content": "bar"
146
+ }
147
+ }
148
+ },
149
+ {
150
+ "name": "expand unknown actor 2",
151
+ "type": "message",
152
+ "valid": "true",
153
+ "input": {
154
+ "context": "foo",
155
+ "type": "bar",
156
+ "actor": "xmpp:someone@example.org/resource",
157
+ "object": {
158
+ "content": "bar"
159
+ }
160
+ },
161
+ "output": {
162
+ "context": "foo",
163
+ "type": "bar",
164
+ "actor": {
165
+ "id": "xmpp:someone@example.org/resource"
166
+ },
167
+ "object": {
168
+ "content": "bar"
169
+ }
170
+ }
171
+ },
172
+ {
173
+ "name":"person",
174
+ "type":"message",
175
+ "valid":true,
176
+ "input":{
177
+ "context": "some context",
178
+ "type": "some type",
179
+ "actor": "blah",
180
+ "object": {}
181
+ },
182
+ "output": {
183
+ "context": "some context",
184
+ "type": "some type",
185
+ "actor": {
186
+ "id":"blah",
187
+ "type":"person",
188
+ "name":"dood"
189
+ },
190
+ "object": {}
191
+ }
192
+ },
193
+ {
194
+ "name":"person with extras",
195
+ "valid":true,
196
+ "type":"message",
197
+ "input": {
198
+ "context": "some context",
199
+ "type": "some type",
200
+ "actor": "blah2",
201
+ "object": {}
202
+ },
203
+ "output": {
204
+ "context": "some context",
205
+ "type": "some type",
206
+ "actor": {
207
+ "id":"blah2",
208
+ "type":"person",
209
+ "name":"bob",
210
+ "hello":"there",
211
+ "i":[
212
+ "am",
213
+ "extras"
214
+ ]
215
+ },
216
+ "object": {}
217
+ }
218
+ },
219
+ {
220
+ "name":"bad parent object",
221
+ "valid":false,
222
+ "type":"message",
223
+ "input":{
224
+ "string":"this is a string",
225
+ "array":[
226
+ "this",
227
+ "is",
228
+ {
229
+ "an":"array"
230
+ }
231
+ ],
232
+ "as":{
233
+ "id":"blah",
234
+ "type":"send",
235
+ "context":"hello",
236
+ "actor":{
237
+ "name":"dood"
238
+ },
239
+ "target":{
240
+ "type":"person",
241
+ "name":"bob"
242
+ },
243
+ "object":{
244
+ "type":"credentials"
245
+ }
246
+ },
247
+ "noId":{
248
+ "name":"dood"
249
+ },
250
+ "noId2":{
251
+ "type":"person",
252
+ "name":"bob"
253
+ },
254
+ "noDisplayName":{
255
+ "id":"larg"
256
+ }
257
+ },
258
+ "error": "Error: activity stream must contain a context property"
259
+ },
260
+ {
261
+ "name":"no actor specified",
262
+ "valid":false,
263
+ "type":"message",
264
+ "input":{
265
+ "type": "some type",
266
+ "context":"xmpp",
267
+ "object":{
268
+ "type": "error",
269
+ "content": "error message"
270
+ }
271
+ },
272
+ "error": "Error: activity stream must contain an actor property."
273
+ },
274
+ {
275
+ "name":"expand actor and target of unknowns",
276
+ "valid":true,
277
+ "type":"message",
278
+ "input":{
279
+ "actor":"irc://uuu@localhost",
280
+ "type":"join",
281
+ "context":"irc",
282
+ "target":"irc://irc.dooder.net/a-room"
283
+ },
284
+ "output":{
285
+ "actor":{
286
+ "id":"irc://uuu@localhost"
287
+ },
288
+ "type":"join",
289
+ "context":"irc",
290
+ "target":{
291
+ "id":"irc://irc.dooder.net/a-room"
292
+ }
293
+ }
294
+ },
295
+ {
296
+ "name":"expand actor and target of unknowns",
297
+ "valid":true,
298
+ "type":"message",
299
+ "input":{
300
+ "actor":"hyper_rau@localhost",
301
+ "type":"join",
302
+ "context":"xmpp",
303
+ "object":{
304
+
305
+ },
306
+ "target":"dooder"
307
+ },
308
+ "output":{
309
+ "actor":{
310
+ "id":"hyper_rau@localhost"
311
+ },
312
+ "type":"join",
313
+ "context":"xmpp",
314
+ "object":{
315
+
316
+ },
317
+ "target":{
318
+ "id":"dooder"
319
+ }
320
+ }
321
+ },
322
+ {
323
+ "name":"expand known person",
324
+ "valid":true,
325
+ "type":"message",
326
+ "input":{
327
+ "actor":"sh-9K3Vk@irc.freenode.net",
328
+ "target":"blah3",
329
+ "type":"send",
330
+ "context":"irc",
331
+ "object":{
332
+
333
+ }
334
+ },
335
+ "output":{
336
+ "actor":{
337
+ "id":"sh-9K3Vk@irc.freenode.net",
338
+ "type":"person",
339
+ "name":"sh-9K3Vk",
340
+ "image":{
341
+ "height":250,
342
+ "mediaType":"image/jpeg",
343
+ "url":"http://example.org/image.jpg",
344
+ "width":250
345
+ },
346
+ "url":"http://sockethub.org"
347
+ },
348
+ "target":{
349
+ "id":"blah3",
350
+ "type":"person",
351
+ "name":"bob",
352
+ "hello":"there",
353
+ "i":[
354
+ "am",
355
+ "extras"
356
+ ]
357
+ },
358
+ "type":"send",
359
+ "context":"irc",
360
+ "object":{
361
+
362
+ }
363
+ }
364
+ }
365
+ ];
@@ -0,0 +1,78 @@
1
+ import { expect } from 'chai';
2
+
3
+ import expandActivityStream from "./expand-activity-stream";
4
+
5
+ import asObjects from "./expand-activity-stream.test.data";
6
+ import ActivityStreams from 'activity-streams';
7
+
8
+ const activity = ActivityStreams();
9
+ // register known activity objects
10
+ [
11
+ {
12
+ "id":"blah",
13
+ "type":"person",
14
+ "name":"dood"
15
+ },
16
+ {
17
+ "id":"blah2",
18
+ "type":"person",
19
+ "name":"bob",
20
+ "hello":"there",
21
+ "i":[
22
+ "am",
23
+ "extras"
24
+ ]
25
+ },
26
+ {
27
+ "id":"sh-9K3Vk@irc.freenode.net",
28
+ "type":"person",
29
+ "name":"sh-9K3Vk",
30
+ "image":{
31
+ "height":250,
32
+ "mediaType":"image/jpeg",
33
+ "url":"http://example.org/image.jpg",
34
+ "width":250
35
+ },
36
+ "url":"http://sockethub.org"
37
+ },
38
+ {
39
+ "id":"blah3",
40
+ "type":"person",
41
+ "name":"bob",
42
+ "hello":"there",
43
+ "i":[
44
+ "am",
45
+ "extras"
46
+ ]
47
+ }
48
+ ].forEach((obj) => {
49
+ activity.Object.create(obj);
50
+ });
51
+
52
+ describe('Middleware: Expand Activity Stream', () => {
53
+ describe('AS object expansion', () => {
54
+ asObjects.forEach((obj) => {
55
+ it(`${obj.type}: ${obj.name}, should ${obj.valid ? 'pass' : 'fail'}`, (done) => {
56
+ // @ts-ignore
57
+ expandActivityStream(obj.input, (msg) => {
58
+ if (obj.output) {
59
+ if (obj.output === 'same') {
60
+ expect(obj.input).to.eql(msg);
61
+ } else {
62
+ expect(obj.output).to.eql(msg);
63
+ }
64
+ }
65
+ if (obj.valid) {
66
+ expect(msg instanceof Error).to.be.false;
67
+ } else {
68
+ expect(msg instanceof Error).to.be.true;
69
+ if (obj.error) {
70
+ expect(obj.error).to.equal(msg.toString());
71
+ }
72
+ }
73
+ done();
74
+ });
75
+ });
76
+ });
77
+ });
78
+ });
@@ -0,0 +1,27 @@
1
+ import ActivityStreams from 'activity-streams';
2
+
3
+ import config from "../config";
4
+ import { ActivityStream } from "../sockethub";
5
+
6
+ const activity = ActivityStreams(config.get('activity-streams:opts'));
7
+
8
+ function ensureObject(msg: any) {
9
+ return !((typeof msg !== 'object') || (Array.isArray(msg)));
10
+ }
11
+
12
+ export default function expandActivityStream(msg: ActivityStream, done: Function) {
13
+ if (! ensureObject(msg)) {
14
+ done(new Error(`message received is not an object.`));
15
+ } else if (typeof msg.context !== 'string') {
16
+ done(new Error('activity stream must contain a context property'));
17
+ } else if (typeof msg.type !== 'string') {
18
+ done(new Error('activity stream must contain a type property.'));
19
+ } else {
20
+ msg = activity.Stream(msg);
21
+ if (! msg.actor) {
22
+ done(new Error('activity stream must contain an actor property.'));
23
+ } else {
24
+ done(msg);
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,72 @@
1
+ import { expect } from 'chai';
2
+ import * as sinon from 'sinon';
3
+
4
+ import storeCredentials from "./store-credentials";
5
+
6
+ const creds = {
7
+ "id":"blah",
8
+ "type":"credentials",
9
+ "context":"dummy",
10
+ "actor":{
11
+ "id":"dood@irc.freenode.net",
12
+ "type":"person",
13
+ "name":"dood"
14
+ },
15
+ "target":{
16
+ "id":"irc.freenode.net/sockethub",
17
+ "type":"person",
18
+ "name":"sockethub"
19
+ },
20
+ "object":{
21
+ "type":"credentials"
22
+ }
23
+ };
24
+
25
+ describe('Middleware: storeCredentials', () => {
26
+ let storeSuccess, storeError, saveErrorFake, saveSuccessFake, sessionLogStub;
27
+
28
+ beforeEach(() => {
29
+ storeSuccess = {
30
+ save: (id, creds, cb) => {
31
+ cb();
32
+ }
33
+ };
34
+ storeError = {
35
+ save: (id, creds, cb) => {
36
+ cb('some error');
37
+ }
38
+ };
39
+ saveSuccessFake = sinon.replace(storeSuccess, 'save', sinon.fake(storeSuccess.save));
40
+ saveErrorFake = sinon.replace(storeError, 'save', sinon.fake(storeError.save));
41
+ sessionLogStub = sinon.stub();
42
+ });
43
+
44
+ afterEach(() => {
45
+ sinon.reset();
46
+ });
47
+
48
+ it('returns a middleware handler', () => {
49
+ const sc = storeCredentials(storeSuccess, sessionLogStub);
50
+ expect(typeof sc).to.equal('function');
51
+ expect(saveSuccessFake.callCount).to.equal(0);
52
+ expect(sessionLogStub.callCount).to.equal(0);
53
+ });
54
+
55
+ it('successfully store credentials', () => {
56
+ const sc = storeCredentials(storeSuccess, sessionLogStub);
57
+ sc(creds, (err) => {
58
+ expect(saveSuccessFake.callCount).to.equal(1);
59
+ expect(saveSuccessFake.firstArg).to.equal(creds.actor.id);
60
+ expect(err).to.be.undefined;
61
+ });
62
+ });
63
+
64
+ it('handle error while storing credentials', () => {
65
+ const sc = storeCredentials(storeError, sessionLogStub);
66
+ sc(creds, (err) => {
67
+ expect(saveErrorFake.callCount).to.equal(1);
68
+ expect(saveErrorFake.firstArg).to.equal(creds.actor.id);
69
+ expect(err).to.eql('some error');
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,16 @@
1
+ import { ISecureStoreInstance } from "../store";
2
+ import { ActivityStream } from "../sockethub";
3
+
4
+ export default function storeCredentials(store: ISecureStoreInstance, sessionLog: Function) {
5
+ return (creds: ActivityStream, done: Function) => {
6
+ store.save(creds.actor.id, creds, (err) => {
7
+ if (err) {
8
+ sessionLog('error saving credentials to store ' + err);
9
+ done(err);
10
+ } else {
11
+ sessionLog('credentials encrypted and saved');
12
+ done();
13
+ }
14
+ });
15
+ };
16
+ };
File without changes