@sockethub/server 5.0.0-alpha.3
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/LICENSE +165 -0
- package/README.md +136 -0
- package/bin/sockethub +3 -0
- package/coverage/tmp/coverage-93126-1649152190997-0.json +1 -0
- package/dist/bootstrap/init.d.ts +18 -0
- package/dist/bootstrap/init.js +63 -0
- package/dist/bootstrap/init.js.map +1 -0
- package/dist/bootstrap/platforms.js +75 -0
- package/dist/common.d.ts +3 -0
- package/dist/common.js +20 -0
- package/dist/common.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +102 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto.d.ts +10 -0
- package/dist/crypto.js +38 -0
- package/dist/crypto.js.map +1 -0
- package/dist/defaults.json +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/janitor.d.ts +15 -0
- package/dist/janitor.js +89 -0
- package/dist/janitor.js.map +1 -0
- package/dist/listener.d.ts +28 -0
- package/dist/listener.js +91 -0
- package/dist/listener.js.map +1 -0
- package/dist/middleware/create-activity-object.d.ts +6 -0
- package/dist/middleware/create-activity-object.js +19 -0
- package/dist/middleware/create-activity-object.js.map +1 -0
- package/dist/middleware/expand-activity-stream.d.ts +2 -0
- package/dist/middleware/expand-activity-stream.js +33 -0
- package/dist/middleware/expand-activity-stream.js.map +1 -0
- package/dist/middleware/expand-activity-stream.test.data.d.ts +480 -0
- package/dist/middleware/expand-activity-stream.test.data.js +360 -0
- package/dist/middleware/expand-activity-stream.test.data.js.map +1 -0
- package/dist/middleware/store-credentials.d.ts +3 -0
- package/dist/middleware/store-credentials.js +19 -0
- package/dist/middleware/store-credentials.js.map +1 -0
- package/dist/middleware/validate.d.ts +2 -0
- package/dist/middleware/validate.js +58 -0
- package/dist/middleware/validate.js.map +1 -0
- package/dist/middleware/validate.test.data.d.ts +532 -0
- package/dist/middleware/validate.test.data.js +263 -0
- package/dist/middleware/validate.test.data.js.map +1 -0
- package/dist/middleware.d.ts +10 -0
- package/dist/middleware.js +54 -0
- package/dist/middleware.js.map +1 -0
- package/dist/platform-instance.d.ts +77 -0
- package/dist/platform-instance.js +211 -0
- package/dist/platform-instance.js.map +1 -0
- package/dist/platform.d.ts +6 -0
- package/dist/platform.js +187 -0
- package/dist/platform.js.map +1 -0
- package/dist/process-manager.d.ts +11 -0
- package/dist/process-manager.js +78 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/routes.d.ts +13 -0
- package/dist/routes.js +83 -0
- package/dist/routes.js.map +1 -0
- package/dist/sockethub.d.ts +39 -0
- package/dist/sockethub.js +119 -0
- package/dist/sockethub.js.map +1 -0
- package/dist/store.d.ts +5 -0
- package/dist/store.js +17 -0
- package/dist/store.js.map +1 -0
- package/package.json +103 -0
- package/sockethub.config.example.json +33 -0
- package/src/bootstrap/init.d.ts +8 -0
- package/src/bootstrap/init.ts +83 -0
- package/src/bootstrap/platforms.js +75 -0
- package/src/common.test.ts +54 -0
- package/src/common.ts +14 -0
- package/src/config.d.ts +2 -0
- package/src/config.test.ts +28 -0
- package/src/config.ts +94 -0
- package/src/crypto.d.ts +5 -0
- package/src/crypto.test.ts +41 -0
- package/src/crypto.ts +41 -0
- package/src/defaults.json +28 -0
- package/src/index.ts +28 -0
- package/src/janitor.d.ts +8 -0
- package/src/janitor.ts +89 -0
- package/src/listener.ts +79 -0
- package/src/middleware/create-activity-object.test.ts +10 -0
- package/src/middleware/create-activity-object.ts +13 -0
- package/src/middleware/expand-activity-stream.test.data.ts +365 -0
- package/src/middleware/expand-activity-stream.test.ts +78 -0
- package/src/middleware/expand-activity-stream.ts +27 -0
- package/src/middleware/store-credentials.test.ts +73 -0
- package/src/middleware/store-credentials.ts +16 -0
- package/src/middleware/validate.d.ts +1 -0
- package/src/middleware/validate.test.data.ts +261 -0
- package/src/middleware/validate.test.ts +83 -0
- package/src/middleware/validate.ts +49 -0
- package/src/middleware.d.ts +21 -0
- package/src/middleware.test.ts +154 -0
- package/src/middleware.ts +52 -0
- package/src/platform-instance.test.ts +237 -0
- package/src/platform-instance.ts +242 -0
- package/src/platform.ts +191 -0
- package/src/process-manager.ts +64 -0
- package/src/routes.test.ts +100 -0
- package/src/routes.ts +98 -0
- package/src/sockethub.d.ts +1 -0
- package/src/sockethub.ts +165 -0
- package/src/store.test.ts +28 -0
- package/src/store.ts +17 -0
- package/test/init-suite.js +41 -0
- package/test/queue.functional.test.js +0 -0
- package/test/sockethub-suite.js +25 -0
- package/tsconfig.json +18 -0
- package/views/examples/dummy.ejs +93 -0
- package/views/examples/feeds.ejs +90 -0
- package/views/examples/irc.ejs +239 -0
- package/views/examples/shared.js +72 -0
- package/views/examples/xmpp.ejs +191 -0
- package/views/index.ejs +17 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = [
|
|
4
|
+
{
|
|
5
|
+
"name": "mismatched types",
|
|
6
|
+
"valid": false,
|
|
7
|
+
"type": "credentials",
|
|
8
|
+
"input": {
|
|
9
|
+
"id": "blah",
|
|
10
|
+
"type": "send",
|
|
11
|
+
"context": "fake",
|
|
12
|
+
"actor": {
|
|
13
|
+
"id": "dood@irc.freenode.net",
|
|
14
|
+
"type": "person",
|
|
15
|
+
"name": "dood"
|
|
16
|
+
},
|
|
17
|
+
"target": {
|
|
18
|
+
"id": "irc.freenode.net/service",
|
|
19
|
+
"type": "person",
|
|
20
|
+
"name": "service"
|
|
21
|
+
},
|
|
22
|
+
"object": {
|
|
23
|
+
"type": "credentials",
|
|
24
|
+
"user": 'foo',
|
|
25
|
+
"pass": 'bar'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
'error': "Error: credential activity streams must have credentials set as type"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "basic",
|
|
32
|
+
"valid": true,
|
|
33
|
+
"type": "credentials",
|
|
34
|
+
"input": {
|
|
35
|
+
"id": "blah",
|
|
36
|
+
"type": "credentials",
|
|
37
|
+
"context": "fake",
|
|
38
|
+
"actor": {
|
|
39
|
+
"id": "dood@irc.freenode.net",
|
|
40
|
+
"type": "person",
|
|
41
|
+
"name": "dood"
|
|
42
|
+
},
|
|
43
|
+
"object": {
|
|
44
|
+
'type': 'credentials',
|
|
45
|
+
"user": 'foo',
|
|
46
|
+
"pass": 'bar'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"output": "same"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "no type specified",
|
|
53
|
+
"valid": false,
|
|
54
|
+
"type": "credentials",
|
|
55
|
+
"input": {
|
|
56
|
+
"actor": "hyper_rau@localhost",
|
|
57
|
+
"context": "fake",
|
|
58
|
+
"object": {
|
|
59
|
+
"username": "hyper_rau",
|
|
60
|
+
"password": "123",
|
|
61
|
+
"server": "localhost",
|
|
62
|
+
"port": 5222,
|
|
63
|
+
"resource": "laptop"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"error": "Error: credential activity streams must have credentials set as type"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "basic person",
|
|
70
|
+
"type": "activity-object",
|
|
71
|
+
"valid": true,
|
|
72
|
+
"input": {
|
|
73
|
+
"id": "blah",
|
|
74
|
+
"type": "person",
|
|
75
|
+
"name": "dood"
|
|
76
|
+
},
|
|
77
|
+
"output": "same"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "person with extras",
|
|
81
|
+
"valid": true,
|
|
82
|
+
"type": "activity-object",
|
|
83
|
+
"input": {
|
|
84
|
+
"id": "blah",
|
|
85
|
+
"type": "person",
|
|
86
|
+
"name": "bob",
|
|
87
|
+
"hello": "there",
|
|
88
|
+
"i": [
|
|
89
|
+
"am",
|
|
90
|
+
"extras"
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
"output": "same"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "alone credentials (as activity-object)",
|
|
97
|
+
"valid": false,
|
|
98
|
+
"type": "activity-object",
|
|
99
|
+
"input": {
|
|
100
|
+
"type": "credentials",
|
|
101
|
+
"nick": "sh-9K3Vk",
|
|
102
|
+
"port": 6667,
|
|
103
|
+
"secure": false,
|
|
104
|
+
"server": "irc.freenode.net"
|
|
105
|
+
},
|
|
106
|
+
"error": "Error: /object: must match exactly one schema in oneOf: " +
|
|
107
|
+
"credentials, feed, message, me, person, room, service, website, " +
|
|
108
|
+
"attendance, presence, relationship, topic, address"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "alone credentials (as credentials)",
|
|
112
|
+
"valid": false,
|
|
113
|
+
"type": "credentials",
|
|
114
|
+
"input": {
|
|
115
|
+
"type": "credentials",
|
|
116
|
+
"nick": "sh-9K3Vk",
|
|
117
|
+
"port": 6667,
|
|
118
|
+
"secure": false,
|
|
119
|
+
"server": "irc.freenode.net"
|
|
120
|
+
},
|
|
121
|
+
"error": "Error: platform context undefined not registered with this Sockethub instance."
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "new person",
|
|
125
|
+
"valid": true,
|
|
126
|
+
"type": "activity-object",
|
|
127
|
+
"input": {
|
|
128
|
+
"id": "sh-9K3Vk@irc.freenode.net",
|
|
129
|
+
"type": "person",
|
|
130
|
+
"name": "sh-9K3Vk",
|
|
131
|
+
"image": {
|
|
132
|
+
"height": 250,
|
|
133
|
+
"mediaType": "image/jpeg",
|
|
134
|
+
"url": "http://example.org/image.jpg",
|
|
135
|
+
"width": 250
|
|
136
|
+
},
|
|
137
|
+
"url": "http://sockethub.org"
|
|
138
|
+
},
|
|
139
|
+
"output": "same"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "new person",
|
|
143
|
+
"valid": true,
|
|
144
|
+
"type": "activity-object",
|
|
145
|
+
"input": {
|
|
146
|
+
"id": "irc://sh-9K3Vk@irc.freenode.net",
|
|
147
|
+
"type": "person",
|
|
148
|
+
"name": "sh-9K3Vk",
|
|
149
|
+
"url": "http://sockethub.org"
|
|
150
|
+
},
|
|
151
|
+
"output": "same"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"name": "bad parent object",
|
|
155
|
+
"valid": false,
|
|
156
|
+
"type": "activity-stream",
|
|
157
|
+
"input": {
|
|
158
|
+
"string": "this is a string",
|
|
159
|
+
"array": [
|
|
160
|
+
"this",
|
|
161
|
+
"is",
|
|
162
|
+
{
|
|
163
|
+
"an": "array"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"as": {
|
|
167
|
+
"id": "blah",
|
|
168
|
+
"type": "send",
|
|
169
|
+
"context": "hello",
|
|
170
|
+
"actor": {
|
|
171
|
+
"name": "dood"
|
|
172
|
+
},
|
|
173
|
+
"target": {
|
|
174
|
+
"type": "person",
|
|
175
|
+
"name": "bob"
|
|
176
|
+
},
|
|
177
|
+
"object": {
|
|
178
|
+
"type": "credentials"
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"noId": {
|
|
182
|
+
"name": "dood"
|
|
183
|
+
},
|
|
184
|
+
"noId2": {
|
|
185
|
+
"type": "person",
|
|
186
|
+
"name": "bob"
|
|
187
|
+
},
|
|
188
|
+
"noDisplayName": {
|
|
189
|
+
"id": "larg"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"error": "Error: platform context undefined not registered with this Sockethub instance."
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "unexpected AS",
|
|
196
|
+
"valid": false,
|
|
197
|
+
"type": "message",
|
|
198
|
+
"input": {
|
|
199
|
+
"actor": "irc://uuu@localhost",
|
|
200
|
+
"type": "join",
|
|
201
|
+
"context": "fake",
|
|
202
|
+
"target": "irc://irc.dooder.net/a-room"
|
|
203
|
+
},
|
|
204
|
+
"error": "Error: /actor: must be object"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"name": "missing type property",
|
|
208
|
+
"valid": false,
|
|
209
|
+
"type": "message",
|
|
210
|
+
"input": {
|
|
211
|
+
"actor": { "id": "irc://uuu@localhost", "type": "person" },
|
|
212
|
+
"context": "fake",
|
|
213
|
+
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
214
|
+
},
|
|
215
|
+
"error": "Error: activity stream: must have required property \'type\'"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"name": "invalid context property",
|
|
219
|
+
"valid": false,
|
|
220
|
+
"type": "message",
|
|
221
|
+
"input": {
|
|
222
|
+
"actor": { "id": "irc://uuu@localhost", "type": "person" },
|
|
223
|
+
"type": "foo",
|
|
224
|
+
"context": "foobar",
|
|
225
|
+
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
226
|
+
},
|
|
227
|
+
"error": "Error: platform context foobar not registered with this Sockethub instance."
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"name": "missing actor property",
|
|
231
|
+
"valid": false,
|
|
232
|
+
"type": "message",
|
|
233
|
+
"input": {
|
|
234
|
+
"type": "foo",
|
|
235
|
+
"context": "fake",
|
|
236
|
+
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
237
|
+
},
|
|
238
|
+
"error": "Error: activity stream: must have required property \'actor\'"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"name": "traditional message",
|
|
242
|
+
"valid": true,
|
|
243
|
+
"type": "message",
|
|
244
|
+
"input": {
|
|
245
|
+
"type": "echo",
|
|
246
|
+
"context": "fake",
|
|
247
|
+
"actor": { "id": "irc://uuu@localhost", "type": "person" }
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "message with wrong type",
|
|
252
|
+
"valid": false,
|
|
253
|
+
"type": "message",
|
|
254
|
+
"input": {
|
|
255
|
+
"type": "foorg",
|
|
256
|
+
"context": "fake",
|
|
257
|
+
"actor": { "id": "irc://uuu@localhost", "type": "person" }
|
|
258
|
+
},
|
|
259
|
+
"error": "Error: platform type foorg not supported by fake platform. " +
|
|
260
|
+
"(types: credentials, echo, fail)"
|
|
261
|
+
}
|
|
262
|
+
];
|
|
263
|
+
//# sourceMappingURL=/middleware/validate.test.data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.test.data.js","sourceRoot":"/","sources":["middleware/validate.test.data.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb;QACE,MAAM,EAAE,kBAAkB;QAC1B,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,aAAa;QACrB,OAAO,EAAC;YACN,IAAI,EAAC,MAAM;YACX,MAAM,EAAC,MAAM;YACb,SAAS,EAAC,MAAM;YAChB,OAAO,EAAC;gBACN,IAAI,EAAC,uBAAuB;gBAC5B,MAAM,EAAC,QAAQ;gBACf,MAAM,EAAC,MAAM;aACd;YACD,QAAQ,EAAC;gBACP,IAAI,EAAC,0BAA0B;gBAC/B,MAAM,EAAC,QAAQ;gBACf,MAAM,EAAC,SAAS;aACjB;YACD,QAAQ,EAAC;gBACP,MAAM,EAAC,aAAa;gBACpB,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,KAAK;aACd;SACF;QACD,OAAO,EAAE,sEAAsE;KAChF;IACD;QACE,MAAM,EAAE,OAAO;QACf,OAAO,EAAC,IAAI;QACZ,MAAM,EAAC,aAAa;QACpB,OAAO,EAAC;YACN,IAAI,EAAC,MAAM;YACX,MAAM,EAAC,aAAa;YACpB,SAAS,EAAC,MAAM;YAChB,OAAO,EAAC;gBACN,IAAI,EAAC,uBAAuB;gBAC5B,MAAM,EAAC,QAAQ;gBACf,MAAM,EAAC,MAAM;aACd;YACD,QAAQ,EAAC;gBACP,MAAM,EAAE,aAAa;gBACrB,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,KAAK;aACd;SACF;QACD,QAAQ,EAAC,MAAM;KAChB;IACD;QACE,MAAM,EAAC,mBAAmB;QAC1B,OAAO,EAAC,KAAK;QACb,MA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IACD;QACE,MAAM,EAAC,qBAAqB;QAC5B,OAAO,EAAC,IAAI;QACZ,MAAM,EAAC,SAAS;QAChB,OAAO,EAAC;YACN,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,MAAM;YACjB,OAAO,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,QAAQ,EAAE;SAC3D;KACF;IACD;QACE,MAAM,EAAC,yBAAyB;QAChC,OAAO,EAAC,KAAK;QACb,MAAM,EAAC,SAAS;QAChB,OAAO,EAAC;YACN,MAAM,EAAE,OAAO;YACf,SAAS,EAAE,MAAM;YACjB,OAAO,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,QAAQ,EAAE;SAC3D;QACD,OAAO,EAAE,6DAA6D;YACpE,kCAAkC;KACrC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default function middleware(name: string): MiddlewareChain;
|
|
2
|
+
export declare class MiddlewareChain {
|
|
3
|
+
name: string;
|
|
4
|
+
private chain;
|
|
5
|
+
private errHandler;
|
|
6
|
+
private logger;
|
|
7
|
+
constructor(name: string);
|
|
8
|
+
use(func: Function): this;
|
|
9
|
+
done(): (data: any, callback: Function) => void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MiddlewareChain = void 0;
|
|
4
|
+
const debug_1 = require("debug");
|
|
5
|
+
function middleware(name) {
|
|
6
|
+
return new MiddlewareChain(name);
|
|
7
|
+
}
|
|
8
|
+
exports.default = middleware;
|
|
9
|
+
class MiddlewareChain {
|
|
10
|
+
constructor(name) {
|
|
11
|
+
this.chain = [];
|
|
12
|
+
this.errHandler = (err) => { throw err; };
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.logger = (0, debug_1.debug)(`sockethub:middleware:${name}`);
|
|
15
|
+
}
|
|
16
|
+
use(func) {
|
|
17
|
+
if (typeof func !== 'function') {
|
|
18
|
+
throw new Error('middleware use() can only take a function as an argument');
|
|
19
|
+
}
|
|
20
|
+
if (func.length === 3) {
|
|
21
|
+
this.errHandler = func;
|
|
22
|
+
}
|
|
23
|
+
else if (func.length === 2) {
|
|
24
|
+
this.chain.push(func);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error('middleware function provided with incorrect number of params: ' + func.length);
|
|
28
|
+
}
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
done() {
|
|
32
|
+
return (data, callback) => {
|
|
33
|
+
let position = 0;
|
|
34
|
+
if (typeof callback !== 'function') {
|
|
35
|
+
callback = () => { };
|
|
36
|
+
}
|
|
37
|
+
const next = (_data) => {
|
|
38
|
+
if (_data instanceof Error) {
|
|
39
|
+
this.logger(_data);
|
|
40
|
+
this.errHandler(_data, data, callback);
|
|
41
|
+
}
|
|
42
|
+
else if (typeof this.chain[position] === 'function') {
|
|
43
|
+
this.chain[position++](_data, next);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
callback(_data);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
next(data);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MiddlewareChain = MiddlewareChain;
|
|
54
|
+
//# sourceMappingURL=/middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"/","sources":["middleware.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,SAAwB,UAAU,CAAC,IAAY;IAC7C,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAFD,6BAEC;AAED,MAAa,eAAe;IAM1B,YAAY,IAAY;QAJhB,UAAK,GAAoB,EAAE,CAAC;QAC5B,eAAU,GAAa,CAAC,GAAU,EAAE,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAI5D,IAAI,CAAC,IAA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,IAAI,CAAC,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;CACF;AA7CD,0CA6CC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ChildProcess } from 'child_process';
|
|
3
|
+
import { Debugger } from 'debug';
|
|
4
|
+
import Queue from 'bull';
|
|
5
|
+
import { IActivityStream } from '@sockethub/schemas';
|
|
6
|
+
export declare const platformInstances: Map<string, PlatformInstance>;
|
|
7
|
+
export interface PlatformInstanceParams {
|
|
8
|
+
identifier: string;
|
|
9
|
+
platform: string;
|
|
10
|
+
parentId?: string;
|
|
11
|
+
actor?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface MessageFromParent extends Array<string | any> {
|
|
14
|
+
0: string;
|
|
15
|
+
1: any;
|
|
16
|
+
}
|
|
17
|
+
interface PlatformConfig {
|
|
18
|
+
persist?: boolean;
|
|
19
|
+
requireCredentials?: Array<string>;
|
|
20
|
+
}
|
|
21
|
+
export default class PlatformInstance {
|
|
22
|
+
flaggedForTermination: boolean;
|
|
23
|
+
id: string;
|
|
24
|
+
queue: Queue;
|
|
25
|
+
completedJobHandlers: Map<string, Function>;
|
|
26
|
+
config: PlatformConfig;
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly process: ChildProcess;
|
|
29
|
+
readonly debug: Debugger;
|
|
30
|
+
readonly parentId: string;
|
|
31
|
+
readonly sessions: Set<string>;
|
|
32
|
+
readonly sessionCallbacks: object;
|
|
33
|
+
readonly global?: boolean;
|
|
34
|
+
private readonly actor?;
|
|
35
|
+
constructor(params: PlatformInstanceParams);
|
|
36
|
+
/**
|
|
37
|
+
* Destroys all references to this platform instance, internal listeners and controlled processes
|
|
38
|
+
*/
|
|
39
|
+
destroy(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* When jobs are completed or failed, we prepare the results and send them to the client socket
|
|
42
|
+
*/
|
|
43
|
+
initQueue(secret: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Register listener to be called when the process emits a message.
|
|
46
|
+
* @param sessionId ID of socket connection that will receive messages from platform emits
|
|
47
|
+
*/
|
|
48
|
+
registerSession(sessionId: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Sends a message to client (user), can be registered with an event emitted from the platform
|
|
51
|
+
* process.
|
|
52
|
+
* @param sessionId ID of the socket connection to send the message to
|
|
53
|
+
* @param msg ActivityStream object to send to client
|
|
54
|
+
*/
|
|
55
|
+
sendToClient(sessionId: string, msg: IActivityStream): void;
|
|
56
|
+
private broadcastToSharedPeers;
|
|
57
|
+
private handleJobResult;
|
|
58
|
+
/**
|
|
59
|
+
* Sends error message to client and clears all references to this class.
|
|
60
|
+
* @param sessionId
|
|
61
|
+
* @param errorMessage
|
|
62
|
+
*/
|
|
63
|
+
private reportError;
|
|
64
|
+
/**
|
|
65
|
+
* Updates the instance with a new identifier, updating the platformInstances mapping as well.
|
|
66
|
+
* @param identifier
|
|
67
|
+
*/
|
|
68
|
+
private updateIdentifier;
|
|
69
|
+
/**
|
|
70
|
+
* Generates a function tied to a given client session (socket connection), the generated
|
|
71
|
+
* function will be called for each session ID registered, for every platform emit.
|
|
72
|
+
* @param listener
|
|
73
|
+
* @param sessionId
|
|
74
|
+
*/
|
|
75
|
+
private callbackFunction;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.platformInstances = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const debug_1 = require("debug");
|
|
10
|
+
const bull_1 = __importDefault(require("bull"));
|
|
11
|
+
const config_1 = __importDefault(require("./config"));
|
|
12
|
+
const listener_1 = require("./listener");
|
|
13
|
+
const common_1 = require("./common");
|
|
14
|
+
// collection of platform instances, stored by `id`
|
|
15
|
+
exports.platformInstances = new Map();
|
|
16
|
+
class PlatformInstance {
|
|
17
|
+
constructor(params) {
|
|
18
|
+
this.flaggedForTermination = false;
|
|
19
|
+
this.completedJobHandlers = new Map();
|
|
20
|
+
this.config = {};
|
|
21
|
+
this.sessions = new Set();
|
|
22
|
+
this.sessionCallbacks = {
|
|
23
|
+
'close': (() => new Map())(),
|
|
24
|
+
'message': (() => new Map())()
|
|
25
|
+
};
|
|
26
|
+
this.global = false;
|
|
27
|
+
this.id = params.identifier;
|
|
28
|
+
this.name = params.platform;
|
|
29
|
+
this.parentId = params.parentId;
|
|
30
|
+
if (params.actor) {
|
|
31
|
+
this.actor = params.actor;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.global = true;
|
|
35
|
+
}
|
|
36
|
+
this.debug = (0, debug_1.debug)(`sockethub:platform-instance:${this.id}`);
|
|
37
|
+
// spin off a process
|
|
38
|
+
const env = config_1.default.get('redis:url') ? { REDIS_URL: config_1.default.get('redis:url') }
|
|
39
|
+
: { REDIS_HOST: config_1.default.get('redis:host'), REDIS_PORT: config_1.default.get('redis:port') };
|
|
40
|
+
this.process = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'platform.js'), [this.parentId, this.name, this.id], { env: env });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Destroys all references to this platform instance, internal listeners and controlled processes
|
|
44
|
+
*/
|
|
45
|
+
async destroy() {
|
|
46
|
+
this.debug(`cleaning up`);
|
|
47
|
+
this.flaggedForTermination = true;
|
|
48
|
+
try {
|
|
49
|
+
await this.queue.removeAllListeners();
|
|
50
|
+
}
|
|
51
|
+
catch (e) { }
|
|
52
|
+
try {
|
|
53
|
+
await this.queue.obliterate({ force: true });
|
|
54
|
+
}
|
|
55
|
+
catch (e) { }
|
|
56
|
+
try {
|
|
57
|
+
delete this.queue;
|
|
58
|
+
await this.process.removeAllListeners('close');
|
|
59
|
+
await this.process.unref();
|
|
60
|
+
await this.process.kill();
|
|
61
|
+
}
|
|
62
|
+
catch (e) { }
|
|
63
|
+
exports.platformInstances.delete(this.id);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* When jobs are completed or failed, we prepare the results and send them to the client socket
|
|
67
|
+
*/
|
|
68
|
+
initQueue(secret) {
|
|
69
|
+
this.queue = new bull_1.default(this.parentId + this.id, { redis: config_1.default.get('redis') });
|
|
70
|
+
this.queue.on('global:completed', (jobId, resultString) => {
|
|
71
|
+
const result = resultString ? JSON.parse(resultString) : "";
|
|
72
|
+
this.queue.getJob(jobId).then(async (job) => {
|
|
73
|
+
await this.handleJobResult('completed', (0, common_1.decryptJobData)(job, secret), result);
|
|
74
|
+
await job.remove();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
this.queue.on('global:error', (jobId, result) => {
|
|
78
|
+
this.debug("unknown queue error", jobId, result);
|
|
79
|
+
});
|
|
80
|
+
this.queue.on('global:failed', (jobId, result) => {
|
|
81
|
+
this.queue.getJob(jobId).then(async (job) => {
|
|
82
|
+
await this.handleJobResult('failed', (0, common_1.decryptJobData)(job, secret), result);
|
|
83
|
+
await job.remove();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Register listener to be called when the process emits a message.
|
|
89
|
+
* @param sessionId ID of socket connection that will receive messages from platform emits
|
|
90
|
+
*/
|
|
91
|
+
registerSession(sessionId) {
|
|
92
|
+
if (!this.sessions.has(sessionId)) {
|
|
93
|
+
this.sessions.add(sessionId);
|
|
94
|
+
for (let type of Object.keys(this.sessionCallbacks)) {
|
|
95
|
+
const cb = this.callbackFunction(type, sessionId);
|
|
96
|
+
this.process.on(type, cb);
|
|
97
|
+
this.sessionCallbacks[type].set(sessionId, cb);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sends a message to client (user), can be registered with an event emitted from the platform
|
|
103
|
+
* process.
|
|
104
|
+
* @param sessionId ID of the socket connection to send the message to
|
|
105
|
+
* @param msg ActivityStream object to send to client
|
|
106
|
+
*/
|
|
107
|
+
sendToClient(sessionId, msg) {
|
|
108
|
+
(0, listener_1.getSocket)(sessionId).then((socket) => {
|
|
109
|
+
try {
|
|
110
|
+
// this property should never be exposed externally
|
|
111
|
+
delete msg.sessionSecret;
|
|
112
|
+
}
|
|
113
|
+
catch (e) { }
|
|
114
|
+
msg.context = this.name;
|
|
115
|
+
if ((msg.type === 'error') && (typeof msg.actor === 'undefined') && (this.actor)) {
|
|
116
|
+
// ensure an actor is present if not otherwise defined
|
|
117
|
+
msg.actor = { id: this.actor, type: 'unknown' };
|
|
118
|
+
}
|
|
119
|
+
socket.emit('message', msg);
|
|
120
|
+
}, (err) => this.debug(`sendToClient ${err}`));
|
|
121
|
+
}
|
|
122
|
+
// send message to every connected socket associated with this platform instance.
|
|
123
|
+
async broadcastToSharedPeers(sessionId, msg) {
|
|
124
|
+
for (let sid of this.sessions.values()) {
|
|
125
|
+
if (sid !== sessionId) {
|
|
126
|
+
this.debug(`broadcasting message to ${sid}`);
|
|
127
|
+
await this.sendToClient(sid, msg);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// handle job results coming in on the queue from platform instances
|
|
132
|
+
async handleJobResult(type, jobData, result) {
|
|
133
|
+
this.debug(`${type} job ${jobData.title}`);
|
|
134
|
+
delete jobData.msg.sessionSecret;
|
|
135
|
+
let msg = jobData.msg;
|
|
136
|
+
if (type === 'failed') {
|
|
137
|
+
msg.error = result ? result : "job failed for unknown reason";
|
|
138
|
+
if ((this.config.persist) && (this.config.requireCredentials.includes(jobData.msg.type))) {
|
|
139
|
+
this.debug(`critical job type ${jobData.msg.type} failed, terminating platform instance`);
|
|
140
|
+
await this.destroy();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// send result to client
|
|
144
|
+
const callback = this.completedJobHandlers.get(jobData.title);
|
|
145
|
+
if (callback) {
|
|
146
|
+
callback(msg);
|
|
147
|
+
this.completedJobHandlers.delete(jobData.title);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
await this.sendToClient(jobData.sessionId, msg);
|
|
151
|
+
}
|
|
152
|
+
// let all related peers know of result as an independent message
|
|
153
|
+
// (not as part of a job completion, or failure)
|
|
154
|
+
await this.broadcastToSharedPeers(jobData.sessionId, msg);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sends error message to client and clears all references to this class.
|
|
158
|
+
* @param sessionId
|
|
159
|
+
* @param errorMessage
|
|
160
|
+
*/
|
|
161
|
+
async reportError(sessionId, errorMessage) {
|
|
162
|
+
const errorObject = {
|
|
163
|
+
context: this.name,
|
|
164
|
+
type: 'error',
|
|
165
|
+
actor: { id: this.actor, type: 'unknown' },
|
|
166
|
+
error: errorMessage
|
|
167
|
+
};
|
|
168
|
+
this.sendToClient(sessionId, errorObject);
|
|
169
|
+
this.sessions.clear();
|
|
170
|
+
await this.destroy();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Updates the instance with a new identifier, updating the platformInstances mapping as well.
|
|
174
|
+
* @param identifier
|
|
175
|
+
*/
|
|
176
|
+
updateIdentifier(identifier) {
|
|
177
|
+
exports.platformInstances.delete(this.id);
|
|
178
|
+
this.id = identifier;
|
|
179
|
+
exports.platformInstances.set(this.id, this);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Generates a function tied to a given client session (socket connection), the generated
|
|
183
|
+
* function will be called for each session ID registered, for every platform emit.
|
|
184
|
+
* @param listener
|
|
185
|
+
* @param sessionId
|
|
186
|
+
*/
|
|
187
|
+
callbackFunction(listener, sessionId) {
|
|
188
|
+
const funcs = {
|
|
189
|
+
'close': (e) => {
|
|
190
|
+
this.debug(`close even triggered ${this.id}: ${e}`);
|
|
191
|
+
this.reportError(sessionId, `Error: session thread closed unexpectedly: ${e}`);
|
|
192
|
+
},
|
|
193
|
+
'message': (data) => {
|
|
194
|
+
if (data[0] === 'updateActor') {
|
|
195
|
+
// We need to update the key to the store in order to find it in the future.
|
|
196
|
+
this.updateIdentifier(data[2]);
|
|
197
|
+
}
|
|
198
|
+
else if (data[0] === 'error') {
|
|
199
|
+
this.reportError(sessionId, data[1]);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// treat like a message to clients
|
|
203
|
+
this.sendToClient(sessionId, data[1]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
return funcs[listener];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.default = PlatformInstance;
|
|
211
|
+
//# sourceMappingURL=/platform-instance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-instance.js","sourceRoot":"/","sources":["platform-instance.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAmD;AACnD,+BAA4B;AAC5B,iCAAwC;AACxC,gDAAyB;AAGzB,sDAA8B;AAE9B,yCAAuC;AACvC,qCAA0C;AAE1C,mDAAmD;AACtC,QAAA,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAC;AAkBrE,MAAqB,gBAAgB;IAkBnC,YAAY,MAA8B;QAjB1C,0BAAqB,GAAY,KAAK,CAAC;QAGvC,yBAAoB,GAA0B,IAAI,GAAG,EAAE,CAAC;QACxD,WAAM,GAAmB,EAAE,CAAC;QAKnB,aAAQ,GAAgB,IAAI,GAAG,EAAE,CAAC;QAClC,qBAAgB,GAAW;YAClC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE;YAC5B,SAAS,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE;SAC/B,CAAC;QACc,WAAM,GAAa,KAAK,CAAC;QAIvC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,Q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