sockethub 5.0.0-alpha.2 → 5.0.0-alpha.4

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 (101) hide show
  1. package/bin/sockethub +2 -29
  2. package/build.js +21 -0
  3. package/package.json +15 -65
  4. package/{dist/defaults.json → sockethub.config.json} +8 -7
  5. package/tsconfig.json +6 -68
  6. package/README.md +0 -98
  7. package/config.json.example +0 -32
  8. package/dist/bootstrap/init.js +0 -74
  9. package/dist/bootstrap/init.js.map +0 -1
  10. package/dist/bootstrap/platforms.js +0 -103
  11. package/dist/common.js +0 -20
  12. package/dist/common.js.map +0 -1
  13. package/dist/config.js +0 -60
  14. package/dist/config.js.map +0 -1
  15. package/dist/crypto.js +0 -38
  16. package/dist/crypto.js.map +0 -1
  17. package/dist/janitor.js +0 -98
  18. package/dist/janitor.js.map +0 -1
  19. package/dist/middleware/create-activity-object.js +0 -19
  20. package/dist/middleware/create-activity-object.js.map +0 -1
  21. package/dist/middleware/expand-activity-stream.js +0 -33
  22. package/dist/middleware/expand-activity-stream.js.map +0 -1
  23. package/dist/middleware/expand-activity-stream.test.data.js +0 -360
  24. package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
  25. package/dist/middleware/store-credentials.js +0 -19
  26. package/dist/middleware/store-credentials.js.map +0 -1
  27. package/dist/middleware/validate.js +0 -77
  28. package/dist/middleware/validate.js.map +0 -1
  29. package/dist/middleware/validate.test.data.js +0 -321
  30. package/dist/middleware/validate.test.data.js.map +0 -1
  31. package/dist/middleware.js +0 -54
  32. package/dist/middleware.js.map +0 -1
  33. package/dist/platform-instance.js +0 -226
  34. package/dist/platform-instance.js.map +0 -1
  35. package/dist/platform.js +0 -186
  36. package/dist/platform.js.map +0 -1
  37. package/dist/process-manager.js +0 -78
  38. package/dist/process-manager.js.map +0 -1
  39. package/dist/routes.js +0 -84
  40. package/dist/routes.js.map +0 -1
  41. package/dist/serve.js +0 -102
  42. package/dist/serve.js.map +0 -1
  43. package/dist/sockethub-client.js +0 -2604
  44. package/dist/sockethub-client.js.map +0 -1
  45. package/dist/sockethub-client.min.js +0 -2
  46. package/dist/sockethub-client.min.js.LICENSE.txt +0 -24
  47. package/dist/sockethub.js +0 -130
  48. package/dist/sockethub.js.map +0 -1
  49. package/dist/store.js +0 -17
  50. package/dist/store.js.map +0 -1
  51. package/src/bootstrap/init.d.ts +0 -8
  52. package/src/bootstrap/init.ts +0 -91
  53. package/src/bootstrap/platforms.js +0 -103
  54. package/src/common.test.ts +0 -54
  55. package/src/common.ts +0 -14
  56. package/src/config.d.ts +0 -2
  57. package/src/config.test.ts +0 -28
  58. package/src/config.ts +0 -72
  59. package/src/crypto.d.ts +0 -5
  60. package/src/crypto.test.ts +0 -41
  61. package/src/crypto.ts +0 -41
  62. package/src/defaults.json +0 -32
  63. package/src/janitor.d.ts +0 -8
  64. package/src/janitor.ts +0 -89
  65. package/src/middleware/create-activity-object.test.ts +0 -10
  66. package/src/middleware/create-activity-object.ts +0 -13
  67. package/src/middleware/expand-activity-stream.test.data.ts +0 -365
  68. package/src/middleware/expand-activity-stream.test.ts +0 -78
  69. package/src/middleware/expand-activity-stream.ts +0 -27
  70. package/src/middleware/store-credentials.test.ts +0 -72
  71. package/src/middleware/store-credentials.ts +0 -16
  72. package/src/middleware/validate.d.ts +0 -1
  73. package/src/middleware/validate.test.data.ts +0 -320
  74. package/src/middleware/validate.test.ts +0 -47
  75. package/src/middleware/validate.ts +0 -49
  76. package/src/middleware.d.ts +0 -21
  77. package/src/middleware.test.ts +0 -148
  78. package/src/middleware.ts +0 -52
  79. package/src/platform-instance.test.ts +0 -237
  80. package/src/platform-instance.ts +0 -236
  81. package/src/platform.ts +0 -189
  82. package/src/process-manager.ts +0 -64
  83. package/src/routes.test.ts +0 -100
  84. package/src/routes.ts +0 -93
  85. package/src/serve.ts +0 -79
  86. package/src/sockethub-client.test.ts +0 -235
  87. package/src/sockethub-client.ts +0 -164
  88. package/src/sockethub.d.ts +0 -1
  89. package/src/sockethub.ts +0 -184
  90. package/src/store.test.ts +0 -26
  91. package/src/store.ts +0 -17
  92. package/test/init-suite.js +0 -41
  93. package/test/sockethub-suite.js +0 -25
  94. package/views/examples/dummy.ejs +0 -93
  95. package/views/examples/feeds.ejs +0 -90
  96. package/views/examples/irc.ejs +0 -239
  97. package/views/examples/shared.js +0 -72
  98. package/views/examples/xmpp.ejs +0 -191
  99. package/views/index.ejs +0 -17
  100. package/webpack.minified.config.js +0 -14
  101. package/webpack.normal.config.js +0 -14
@@ -1,27 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export default function validate(type: any): (next: any, msg: any) => void;
@@ -1,320 +0,0 @@
1
- export default [
2
- {
3
- "name": "mismatched types",
4
- "valid": false,
5
- "type": "credentials",
6
- "input":{
7
- "id":"blah",
8
- "type":"send",
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
- "user": 'foo',
23
- "pass": 'bar'
24
- }
25
- },
26
- 'error': "Error: credential activity streams must have credentials set as type"
27
- },
28
- {
29
- "name": "basic",
30
- "valid":true,
31
- "type":"credentials",
32
- "input":{
33
- "id":"blah",
34
- "type":"credentials",
35
- "context":"dummy",
36
- "actor":{
37
- "id":"dood@irc.freenode.net",
38
- "type":"person",
39
- "name":"dood"
40
- },
41
- "object":{
42
- 'type': 'credentials',
43
- "user": 'foo',
44
- "pass": 'bar'
45
- }
46
- },
47
- "output":"same"
48
- },
49
- {
50
- "name":"irc credentials",
51
- "valid":true,
52
- "type":"credentials",
53
- "input":{
54
- "context":"irc",
55
- "type":"credentials",
56
- "actor":{
57
- "id":"sh-9K3Vk@irc.freenode.net",
58
- "type":"person",
59
- "name":"sh-9K3Vk",
60
- "image":{
61
- "height":250,
62
- "mediaType":"image/jpeg",
63
- "url":"http://example.org/image.jpg",
64
- "width":250
65
- },
66
- "url":"http://sockethub.org"
67
- },
68
- "object":{
69
- "type":"credentials",
70
- "nick":"sh-9K3Vk",
71
- "port":6667,
72
- "secure":false,
73
- "server":"irc.freenode.net"
74
- }
75
- },
76
- "output":"same"
77
- },
78
- {
79
- "name":"bad irc credentials: user/nick host/server",
80
- "valid":false,
81
- "type":"credentials",
82
- "input":{
83
- "context":"irc",
84
- "type":"credentials",
85
- "actor":{
86
- "id":"sh-9K3Vk@irc.freenode.net",
87
- "type":"person",
88
- "name":"sh-9K3Vk",
89
- "image":{
90
- "height":250,
91
- "mediaType":"image/jpeg",
92
- "url":"http://example.org/image.jpg",
93
- "width":250
94
- },
95
- "url":"http://sockethub.org"
96
- },
97
- "object":{
98
- "type":"credentials",
99
- "user":"sh-9K3Vk",
100
- "port":6667,
101
- "secure":false,
102
- "host":"irc.freenode.net"
103
- }
104
- },
105
- "error":
106
- "Error: /object: must NOT have additional properties"
107
- },
108
- {
109
- "name":"no type specified",
110
- "valid":false,
111
- "type":"credentials",
112
- "input":{
113
- "actor":"hyper_rau@localhost",
114
- "context":"xmpp",
115
- "object":{
116
- "username":"hyper_rau",
117
- "password":"123",
118
- "server":"localhost",
119
- "port":5222,
120
- "resource":"laptop"
121
- }
122
- },
123
- "error": "Error: credential activity streams must have credentials set as type"
124
- },
125
- {
126
- "name":"basic person",
127
- "type":"activity-object",
128
- "valid":true,
129
- "input":{
130
- "id":"blah",
131
- "type":"person",
132
- "name":"dood"
133
- },
134
- "output":"same"
135
- },
136
- {
137
- "name":"person with extras",
138
- "valid":true,
139
- "type":"activity-object",
140
- "input":{
141
- "id":"blah",
142
- "type":"person",
143
- "name":"bob",
144
- "hello":"there",
145
- "i":[
146
- "am",
147
- "extras"
148
- ]
149
- },
150
- "output":"same"
151
- },
152
- {
153
- "name":"alone credentials (as activity-object)",
154
- "valid":false,
155
- "type":"activity-object",
156
- "input":{
157
- "type":"credentials",
158
- "nick":"sh-9K3Vk",
159
- "port":6667,
160
- "secure":false,
161
- "server":"irc.freenode.net"
162
- },
163
- "error":
164
- "Error: /object: must match exactly one schema in oneOf: " +
165
- "credentials, feed, message, me, person, room, service, website, " +
166
- "attendance, presence, relationship, topic, address"
167
- },
168
- {
169
- "name":"alone credentials (as credentials)",
170
- "valid":false,
171
- "type":"credentials",
172
- "input":{
173
- "type":"credentials",
174
- "nick":"sh-9K3Vk",
175
- "port":6667,
176
- "secure":false,
177
- "server":"irc.freenode.net"
178
- },
179
- "error": "Error: platform context undefined not registered with this sockethub instance."
180
- },
181
- {
182
- "name":"new person",
183
- "valid":true,
184
- "type":"activity-object",
185
- "input":{
186
- "id":"sh-9K3Vk@irc.freenode.net",
187
- "type":"person",
188
- "name":"sh-9K3Vk",
189
- "image":{
190
- "height":250,
191
- "mediaType":"image/jpeg",
192
- "url":"http://example.org/image.jpg",
193
- "width":250
194
- },
195
- "url":"http://sockethub.org"
196
- },
197
- "output":"same"
198
- },
199
- {
200
- "name":"new person",
201
- "valid":true,
202
- "type":"activity-object",
203
- "input":{
204
- "id":"irc://sh-9K3Vk@irc.freenode.net",
205
- "type":"person",
206
- "name":"sh-9K3Vk",
207
- "url":"http://sockethub.org"
208
- },
209
- "output":"same"
210
- },
211
- {
212
- "name":"bad parent object",
213
- "valid":false,
214
- "type":"activity-stream",
215
- "input":{
216
- "string":"this is a string",
217
- "array":[
218
- "this",
219
- "is",
220
- {
221
- "an":"array"
222
- }
223
- ],
224
- "as":{
225
- "id":"blah",
226
- "type":"send",
227
- "context":"hello",
228
- "actor":{
229
- "name":"dood"
230
- },
231
- "target":{
232
- "type":"person",
233
- "name":"bob"
234
- },
235
- "object":{
236
- "type":"credentials"
237
- }
238
- },
239
- "noId":{
240
- "name":"dood"
241
- },
242
- "noId2":{
243
- "type":"person",
244
- "name":"bob"
245
- },
246
- "noDisplayName":{
247
- "id":"larg"
248
- }
249
- },
250
- "error": "Error: platform context undefined not registered with this sockethub instance."
251
- },
252
- {
253
- "name":"unexpected AS",
254
- "valid":false,
255
- "type":"message",
256
- "input":{
257
- "actor":"irc://uuu@localhost",
258
- "type":"join",
259
- "context":"irc",
260
- "target":"irc://irc.dooder.net/a-room"
261
- },
262
- "error": "Error: /actor: must be object"
263
- },
264
- {
265
- "name":"missing type property",
266
- "valid":false,
267
- "type":"message",
268
- "input":{
269
- "actor": { "id": "irc://uuu@localhost", "type": "person" },
270
- "context":"irc",
271
- "target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
272
- },
273
- "error": "Error: activity stream: must have required property \'type\'"
274
- },
275
- {
276
- "name":"invalid context property",
277
- "valid":false,
278
- "type":"message",
279
- "input":{
280
- "actor": { "id": "irc://uuu@localhost", "type": "person" },
281
- "type":"foo",
282
- "context": "foobar",
283
- "target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
284
- },
285
- "error": "Error: platform context foobar not registered with this sockethub instance."
286
- },
287
- {
288
- "name":"missing actor property",
289
- "valid":false,
290
- "type":"message",
291
- "input":{
292
- "type": "foo",
293
- "context":"irc",
294
- "target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
295
- },
296
- "error": "Error: activity stream: must have required property \'actor\'"
297
- },
298
- {
299
- "name":"traditional message",
300
- "valid":true,
301
- "type":"message",
302
- "input":{
303
- "type": "update",
304
- "context": "irc",
305
- "actor": { "id": "irc://uuu@localhost", "type": "person" }
306
- }
307
- },
308
- {
309
- "name":"message with wrong type",
310
- "valid":false,
311
- "type":"message",
312
- "input":{
313
- "type": "foorg",
314
- "context": "irc",
315
- "actor": { "id": "irc://uuu@localhost", "type": "person" }
316
- },
317
- "error": "Error: platform type foorg not supported by irc platform. " +
318
- "(types: credentials, connect, update, join, leave, send, query, announce)"
319
- }
320
- ];
@@ -1,47 +0,0 @@
1
- import { expect } from 'chai';
2
- import proxyquire from 'proxyquire';
3
-
4
- proxyquire.noPreserveCache();
5
- proxyquire.noCallThru();
6
-
7
- // @ts-ignore
8
- import platformLoad from './../bootstrap/platforms';
9
- const packageJSON = require('./../../package.json');
10
- const platforms = platformLoad(Object.keys(packageJSON.dependencies));
11
-
12
- const validateMod = proxyquire('./validate', {
13
- '../bootstrap/init': {
14
- platforms: platforms
15
- }
16
- });
17
- const validate = validateMod.default;
18
-
19
- import asObjects from "./validate.test.data";
20
-
21
- describe('Middleware: Validate', () => {
22
- describe('AS object validations', () => {
23
- asObjects.forEach((obj) => {
24
- it(`${obj.type}: ${obj.name}, should ${obj.valid ? 'pass' : 'fail'}`, (done) => {
25
- // @ts-ignore
26
- validate(obj.type, 'tests')(obj.input, (msg) => {
27
- if (obj.output) {
28
- if (obj.output === 'same') {
29
- expect(msg).to.eql(obj.input);
30
- } else {
31
- expect(msg).to.eql(obj.output);
32
- }
33
- }
34
- if (obj.valid) {
35
- expect(msg).to.not.be.instanceof(Error);
36
- } else {
37
- expect(msg).to.be.instanceof(Error);
38
- if (obj.error) {
39
- expect(msg.toString()).to.equal(obj.error);
40
- }
41
- }
42
- done();
43
- });
44
- });
45
- });
46
- });
47
- });
@@ -1,49 +0,0 @@
1
- /**
2
- * responsible for handling the validation and expansion (when applicable) of all incoming objects
3
- */
4
- import debug from 'debug';
5
- import * as Schemas from 'sockethub-schemas';
6
- import { ActivityStream } from "../sockethub";
7
-
8
- // @ts-ignore
9
- import init from "../bootstrap/init";
10
-
11
- init.platforms.forEach((platform) => {
12
- Object.keys(platform.schemas).forEach((key) => {
13
- if (! platform.schemas[key]) { return; }
14
- Schemas.validator.addPlatformSchema(platform.schemas[key], `${platform.id}/${key}`);
15
- });
16
- });
17
-
18
- // called when registered with the middleware function, define the type of validation
19
- // that will be called when the middleware eventually does.
20
- export default function validate(type: string, sockethubId: string) {
21
- const sessionLog = debug(`sockethub:validate:${sockethubId}`);
22
- return (msg: ActivityStream, done: Function) => {
23
- sessionLog('applying schema validation for ' + type);
24
- if (type === 'activity-object') {
25
- const err = Schemas.validator.validateActivityObject(msg);
26
- err ? done(new Error(err)) : done(msg);
27
- } else if (! init.platforms.has(msg.context)) {
28
- return done(
29
- new Error(`platform context ${msg.context} not registered with this sockethub instance.`)
30
- );
31
- } else if (type === 'credentials') {
32
- const err = Schemas.validator.validateCredentials(msg);
33
- err ? done(new Error(err)) : done(msg);
34
- } else {
35
- const err = Schemas.validator.validateActivityStream(msg);
36
- if (err) {
37
- done(new Error(err));
38
- } else {
39
- const platformMeta = init.platforms.get(msg.context);
40
- if (!platformMeta.types.includes(msg.type)) {
41
- return done(new Error(`platform type ${msg.type} not supported by ${msg.context} ` +
42
- `platform. (types: ${platformMeta.types.join(', ')})`));
43
- } else {
44
- done(msg);
45
- }
46
- }
47
- }
48
- };
49
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * a very simple middleware handler
3
- *
4
- * When initialized, provide a function which will be called if there were any failures during
5
- * the execution of functions along the chain.
6
- *
7
- * Use middleware.chain, passing in a list of functions to call in order. It then returns
8
- * a function which accepts the message from the input. That function then will
9
- * call each of the originally passed in functions, in order, with a `next` callback as
10
- * the first parameter, and any number of originating parameters.
11
- *
12
- * As one middleware function is done, they call `next` with the first argument `true`
13
- * (succeeded, continue) any parameters to pass along.
14
- *
15
- * If any of the middleware function calls the `next` handler with `false` as the first param, the
16
- * execution of the function chain is halted, and the failure callback is called. Again, any
17
- * number of params passed after the `false` will be passed to the failure callback.
18
- *
19
- */
20
- declare function Middleware(errorHandler: any): void;
21
- export default Middleware;