@sockethub/server 5.0.0-alpha.4 → 5.0.0-alpha.6
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/README.md +54 -60
- package/bin/sockethub +4 -3
- package/package.json +42 -54
- package/res/socket.io.js +4908 -0
- package/res/sockethub-client.js +602 -0
- package/res/sockethub-client.min.js +19 -0
- package/sockethub.config.example.json +2 -3
- package/src/bootstrap/init.d.ts +16 -13
- package/src/bootstrap/init.test.ts +211 -0
- package/src/bootstrap/init.ts +152 -76
- package/src/bootstrap/load-platforms.ts +151 -0
- package/src/config.test.ts +27 -22
- package/src/config.ts +82 -86
- package/src/defaults.json +24 -16
- package/src/index.ts +61 -22
- package/src/janitor.test.ts +191 -169
- package/src/janitor.ts +141 -118
- package/src/listener.ts +148 -58
- package/src/middleware/create-activity-object.test.ts +28 -8
- package/src/middleware/create-activity-object.ts +16 -10
- package/src/middleware/expand-activity-stream.test.data.ts +331 -345
- package/src/middleware/expand-activity-stream.test.ts +65 -66
- package/src/middleware/expand-activity-stream.ts +26 -21
- package/src/middleware/store-credentials.test.ts +74 -60
- package/src/middleware/store-credentials.ts +14 -8
- package/src/middleware/validate.test.data.ts +240 -242
- package/src/middleware/validate.test.ts +39 -78
- package/src/middleware/validate.ts +62 -36
- package/src/middleware.test.ts +168 -138
- package/src/middleware.ts +57 -55
- package/src/platform-instance.test.ts +508 -214
- package/src/platform-instance.ts +324 -231
- package/src/platform.test.ts +375 -0
- package/src/platform.ts +306 -117
- package/src/process-manager.ts +75 -51
- package/src/routes.test.ts +43 -89
- package/src/routes.ts +40 -78
- package/src/sentry.test.ts +106 -0
- package/src/sentry.ts +19 -0
- package/src/sockethub.ts +190 -129
- package/src/util.ts +5 -0
- package/coverage/tmp/coverage-39338-1663949520416-0.json +0 -1
- package/dist/bootstrap/init.d.ts +0 -18
- package/dist/bootstrap/init.js +0 -64
- package/dist/bootstrap/init.js.map +0 -1
- package/dist/bootstrap/platforms.js +0 -75
- package/dist/config.d.ts +0 -12
- package/dist/config.js +0 -107
- package/dist/config.js.map +0 -1
- package/dist/defaults.json +0 -28
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/janitor.d.ts +0 -30
- package/dist/janitor.js +0 -120
- package/dist/janitor.js.map +0 -1
- package/dist/listener.d.ts +0 -31
- package/dist/listener.js +0 -94
- package/dist/listener.js.map +0 -1
- package/dist/middleware/create-activity-object.d.ts +0 -8
- package/dist/middleware/create-activity-object.js +0 -19
- package/dist/middleware/create-activity-object.js.map +0 -1
- package/dist/middleware/expand-activity-stream.d.ts +0 -3
- package/dist/middleware/expand-activity-stream.js +0 -36
- package/dist/middleware/expand-activity-stream.js.map +0 -1
- package/dist/middleware/expand-activity-stream.test.data.d.ts +0 -480
- package/dist/middleware/expand-activity-stream.test.data.js +0 -360
- package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
- package/dist/middleware/store-credentials.d.ts +0 -3
- package/dist/middleware/store-credentials.js +0 -9
- package/dist/middleware/store-credentials.js.map +0 -1
- package/dist/middleware/validate.d.ts +0 -2
- package/dist/middleware/validate.js +0 -56
- package/dist/middleware/validate.js.map +0 -1
- package/dist/middleware/validate.test.data.d.ts +0 -532
- package/dist/middleware/validate.test.data.js +0 -263
- package/dist/middleware/validate.test.data.js.map +0 -1
- package/dist/middleware.d.ts +0 -21
- package/dist/middleware.js +0 -56
- package/dist/middleware.js.map +0 -1
- package/dist/platform-instance.d.ts +0 -78
- package/dist/platform-instance.js +0 -226
- package/dist/platform-instance.js.map +0 -1
- package/dist/platform.d.ts +0 -6
- package/dist/platform.js +0 -176
- package/dist/platform.js.map +0 -1
- package/dist/process-manager.d.ts +0 -11
- package/dist/process-manager.js +0 -82
- package/dist/process-manager.js.map +0 -1
- package/dist/routes.d.ts +0 -13
- package/dist/routes.js +0 -83
- package/dist/routes.js.map +0 -1
- package/dist/sockethub.d.ts +0 -18
- package/dist/sockethub.js +0 -112
- package/dist/sockethub.js.map +0 -1
- package/src/bootstrap/platforms.js +0 -75
- package/test/init-suite.js +0 -41
- package/test/sockethub-suite.js +0 -25
- package/tsconfig.json +0 -18
- package/views/examples/dummy.ejs +0 -95
- package/views/examples/feeds.ejs +0 -90
- package/views/examples/irc.ejs +0 -239
- package/views/examples/shared.js +0 -72
- package/views/examples/xmpp.ejs +0 -217
- package/views/index.ejs +0 -17
|
@@ -1,263 +0,0 @@
|
|
|
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": "https://example.org/image.jpg",
|
|
135
|
-
"width": 250
|
|
136
|
-
},
|
|
137
|
-
"url": "https://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": "https://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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.test.data.js","sourceRoot":"/","sources":["middleware/validate.test.data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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"}
|
package/dist/middleware.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IActivityStream } from "@sockethub/schemas";
|
|
2
|
-
export default function middleware(name: string): MiddlewareChain;
|
|
3
|
-
export interface MiddlewareChainInterface {
|
|
4
|
-
(error: IActivityStream | Error, data?: IActivityStream | MiddlewareChainInterface, next?: MiddlewareChainInterface): void;
|
|
5
|
-
}
|
|
6
|
-
interface ErrorHandlerInterface {
|
|
7
|
-
(err: Error, data?: unknown, cb?: unknown): void;
|
|
8
|
-
}
|
|
9
|
-
export interface LogErrorInterface {
|
|
10
|
-
(msg: Error): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class MiddlewareChain {
|
|
13
|
-
name: string;
|
|
14
|
-
private chain;
|
|
15
|
-
private errHandler;
|
|
16
|
-
private readonly logger;
|
|
17
|
-
constructor(name: string);
|
|
18
|
-
use(func: ErrorHandlerInterface | MiddlewareChainInterface): this;
|
|
19
|
-
done(): (data: unknown, callback: MiddlewareChainInterface) => void;
|
|
20
|
-
}
|
|
21
|
-
export {};
|
package/dist/middleware.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
// ensure we have a callback function
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const next = (_data) => {
|
|
40
|
-
if (_data instanceof Error) {
|
|
41
|
-
this.logger(_data);
|
|
42
|
-
this.errHandler(_data, data, callback);
|
|
43
|
-
}
|
|
44
|
-
else if (typeof this.chain[position] === 'function') {
|
|
45
|
-
this.chain[position++](_data, next);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
callback(_data);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
next(data);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.MiddlewareChain = MiddlewareChain;
|
|
56
|
-
//# sourceMappingURL=/middleware.js.map
|
package/dist/middleware.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"/","sources":["middleware.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAG9B,SAAwB,UAAU,CAAC,IAAY;IAC7C,OAAO,IAAI,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C;qBAAM,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,UAAU,EAAE;oBACrD,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAwB,EAAE,IAAI,CAAC,CAAC;iBACxD;qBAAM;oBACL,QAAQ,CAAC,KAAwB,CAAC,CAAC;iBACpC;YACH,CAAC,CAAC;YACF,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;CACF;AA/CD,0CA+CC"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ChildProcess } from 'child_process';
|
|
3
|
-
import { Debugger } from 'debug';
|
|
4
|
-
import { IActivityStream, CompletedJobHandler } from "@sockethub/schemas";
|
|
5
|
-
import { JobQueue } from "@sockethub/data-layer";
|
|
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 | unknown> {
|
|
14
|
-
0: string;
|
|
15
|
-
1: unknown;
|
|
16
|
-
}
|
|
17
|
-
interface PlatformConfig {
|
|
18
|
-
persist?: boolean;
|
|
19
|
-
requireCredentials?: Array<string>;
|
|
20
|
-
}
|
|
21
|
-
export default class PlatformInstance {
|
|
22
|
-
id: string;
|
|
23
|
-
flaggedForTermination: boolean;
|
|
24
|
-
initialized: boolean;
|
|
25
|
-
jobQueue: JobQueue;
|
|
26
|
-
readonly global: boolean;
|
|
27
|
-
readonly completedJobHandlers: Map<string, CompletedJobHandler>;
|
|
28
|
-
readonly config: PlatformConfig;
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly process: ChildProcess;
|
|
31
|
-
readonly debug: Debugger;
|
|
32
|
-
readonly parentId: string;
|
|
33
|
-
readonly sessions: Set<string>;
|
|
34
|
-
readonly sessionCallbacks: object;
|
|
35
|
-
private readonly actor?;
|
|
36
|
-
constructor(params: PlatformInstanceParams);
|
|
37
|
-
/**
|
|
38
|
-
* Destroys all references to this platform instance, internal listeners and controlled processes
|
|
39
|
-
*/
|
|
40
|
-
shutdown(): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* When jobs are completed or failed, we prepare the results and send them to the client socket
|
|
43
|
-
*/
|
|
44
|
-
initQueue(secret: string): void;
|
|
45
|
-
/**
|
|
46
|
-
* Register listener to be called when the process emits a message.
|
|
47
|
-
* @param sessionId ID of socket connection that will receive messages from platform emits
|
|
48
|
-
*/
|
|
49
|
-
registerSession(sessionId: string): void;
|
|
50
|
-
/**
|
|
51
|
-
* Sends a message to client (user), can be registered with an event emitted from the platform
|
|
52
|
-
* process.
|
|
53
|
-
* @param sessionId ID of the socket connection to send the message to
|
|
54
|
-
* @param msg ActivityStream object to send to client
|
|
55
|
-
*/
|
|
56
|
-
sendToClient(sessionId: string, msg: IActivityStream): void;
|
|
57
|
-
private broadcastToSharedPeers;
|
|
58
|
-
private handleJobResult;
|
|
59
|
-
/**
|
|
60
|
-
* Sends error message to client and clears all references to this class.
|
|
61
|
-
* @param sessionId
|
|
62
|
-
* @param errorMessage
|
|
63
|
-
*/
|
|
64
|
-
private reportError;
|
|
65
|
-
/**
|
|
66
|
-
* Updates the instance with a new identifier, updating the platformInstances mapping as well.
|
|
67
|
-
* @param identifier
|
|
68
|
-
*/
|
|
69
|
-
private updateIdentifier;
|
|
70
|
-
/**
|
|
71
|
-
* Generates a function tied to a given client session (socket connection), the generated
|
|
72
|
-
* function will be called for each session ID registered, for every platform emit.
|
|
73
|
-
* @param listener
|
|
74
|
-
* @param sessionId
|
|
75
|
-
*/
|
|
76
|
-
private callbackFunction;
|
|
77
|
-
}
|
|
78
|
-
export {};
|
|
@@ -1,226 +0,0 @@
|
|
|
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 data_layer_1 = require("@sockethub/data-layer");
|
|
11
|
-
const config_1 = __importDefault(require("./config"));
|
|
12
|
-
const listener_1 = require("./listener");
|
|
13
|
-
const nconf_1 = __importDefault(require("nconf"));
|
|
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.initialized = false;
|
|
20
|
-
this.global = false;
|
|
21
|
-
this.completedJobHandlers = new Map();
|
|
22
|
-
this.config = {};
|
|
23
|
-
this.sessions = new Set();
|
|
24
|
-
this.sessionCallbacks = {
|
|
25
|
-
'close': (() => new Map())(),
|
|
26
|
-
'message': (() => new Map())()
|
|
27
|
-
};
|
|
28
|
-
this.id = params.identifier;
|
|
29
|
-
this.name = params.platform;
|
|
30
|
-
this.parentId = params.parentId;
|
|
31
|
-
if (params.actor) {
|
|
32
|
-
this.actor = params.actor;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.global = true;
|
|
36
|
-
}
|
|
37
|
-
this.debug = (0, debug_1.debug)(`sockethub:server:platform-instance:${this.id}`);
|
|
38
|
-
const env = {};
|
|
39
|
-
if (process.env.DEBUG) {
|
|
40
|
-
env.DEBUG = process.env.DEBUG;
|
|
41
|
-
}
|
|
42
|
-
if (config_1.default.get('redis:url')) {
|
|
43
|
-
env.REDIS_URL = config_1.default.get('redis:url');
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
env.REDIS_HOST = config_1.default.get('redis:host');
|
|
47
|
-
env.REDIS_PORT = config_1.default.get('redis:port');
|
|
48
|
-
}
|
|
49
|
-
// spin off a process
|
|
50
|
-
this.process = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'platform.js'), [this.parentId, this.name, this.id], { env: env });
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Destroys all references to this platform instance, internal listeners and controlled processes
|
|
54
|
-
*/
|
|
55
|
-
async shutdown() {
|
|
56
|
-
this.debug('shutdown');
|
|
57
|
-
this.flaggedForTermination = true;
|
|
58
|
-
try {
|
|
59
|
-
await this.process.removeAllListeners('close');
|
|
60
|
-
await this.process.unref();
|
|
61
|
-
this.process.kill();
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
// needs to happen
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
await this.jobQueue.shutdown();
|
|
68
|
-
delete this.jobQueue;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
// this needs to happen
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
exports.platformInstances.delete(this.id);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
// this needs to happen
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* When jobs are completed or failed, we prepare the results and send them to the client socket
|
|
82
|
-
*/
|
|
83
|
-
initQueue(secret) {
|
|
84
|
-
this.jobQueue = new data_layer_1.JobQueue(this.parentId, this.id, secret, nconf_1.default.get('redis'));
|
|
85
|
-
this.jobQueue.initResultEvents();
|
|
86
|
-
this.jobQueue.on('global:completed', async (job, result) => {
|
|
87
|
-
await this.handleJobResult('completed', job, result);
|
|
88
|
-
});
|
|
89
|
-
this.jobQueue.on('global:failed', async (job, result) => {
|
|
90
|
-
await this.handleJobResult('failed', job, result);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Register listener to be called when the process emits a message.
|
|
95
|
-
* @param sessionId ID of socket connection that will receive messages from platform emits
|
|
96
|
-
*/
|
|
97
|
-
registerSession(sessionId) {
|
|
98
|
-
if (!this.sessions.has(sessionId)) {
|
|
99
|
-
this.sessions.add(sessionId);
|
|
100
|
-
for (const type of Object.keys(this.sessionCallbacks)) {
|
|
101
|
-
const cb = this.callbackFunction(type, sessionId);
|
|
102
|
-
this.process.on(type, cb);
|
|
103
|
-
this.sessionCallbacks[type].set(sessionId, cb);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sends a message to client (user), can be registered with an event emitted from the platform
|
|
109
|
-
* process.
|
|
110
|
-
* @param sessionId ID of the socket connection to send the message to
|
|
111
|
-
* @param msg ActivityStream object to send to client
|
|
112
|
-
*/
|
|
113
|
-
sendToClient(sessionId, msg) {
|
|
114
|
-
(0, listener_1.getSocket)(sessionId).then((socket) => {
|
|
115
|
-
try {
|
|
116
|
-
// this property should never be exposed externally
|
|
117
|
-
delete msg.sessionSecret;
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
msg.context = this.name;
|
|
121
|
-
if ((msg.type === 'error') && (typeof msg.actor === 'undefined') && (this.actor)) {
|
|
122
|
-
// ensure an actor is present if not otherwise defined
|
|
123
|
-
msg.actor = { id: this.actor, type: 'unknown' };
|
|
124
|
-
}
|
|
125
|
-
socket.emit('message', msg);
|
|
126
|
-
}
|
|
127
|
-
}, (err) => this.debug(`sendToClient ${err}`));
|
|
128
|
-
}
|
|
129
|
-
// send message to every connected socket associated with this platform instance.
|
|
130
|
-
async broadcastToSharedPeers(sessionId, msg) {
|
|
131
|
-
for (const sid of this.sessions.values()) {
|
|
132
|
-
if (sid !== sessionId) {
|
|
133
|
-
this.debug(`broadcasting message to ${sid}`);
|
|
134
|
-
await this.sendToClient(sid, msg);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// handle job results coming in on the queue from platform instances
|
|
139
|
-
async handleJobResult(type, job, result) {
|
|
140
|
-
const msg = job.msg;
|
|
141
|
-
if (type === 'failed') {
|
|
142
|
-
msg.error = result ? result : "job failed for unknown reason";
|
|
143
|
-
this.debug(`${job.title} ${type}: ${msg.error}`);
|
|
144
|
-
}
|
|
145
|
-
// send result to client
|
|
146
|
-
const callback = this.completedJobHandlers.get(job.title);
|
|
147
|
-
if (callback) {
|
|
148
|
-
callback(msg);
|
|
149
|
-
this.completedJobHandlers.delete(job.title);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
await this.sendToClient(job.sessionId, msg);
|
|
153
|
-
}
|
|
154
|
-
// let all related peers know of result as an independent message
|
|
155
|
-
// (not as part of a job completion, or failure)
|
|
156
|
-
await this.broadcastToSharedPeers(job.sessionId, msg);
|
|
157
|
-
if ((this.config.persist) && (this.config.requireCredentials.includes(job.msg.type))) {
|
|
158
|
-
if (type === 'failed') {
|
|
159
|
-
this.debug(`critical job type ${job.msg.type} failed, flagging for termination`);
|
|
160
|
-
await this.jobQueue.pause();
|
|
161
|
-
this.initialized = false;
|
|
162
|
-
this.flaggedForTermination = true;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
await this.jobQueue.resume();
|
|
166
|
-
this.initialized = true;
|
|
167
|
-
this.flaggedForTermination = false;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Sends error message to client and clears all references to this class.
|
|
173
|
-
* @param sessionId
|
|
174
|
-
* @param errorMessage
|
|
175
|
-
*/
|
|
176
|
-
async reportError(sessionId, errorMessage) {
|
|
177
|
-
const errorObject = {
|
|
178
|
-
context: this.name,
|
|
179
|
-
type: 'error',
|
|
180
|
-
actor: { id: this.actor, type: 'unknown' },
|
|
181
|
-
error: errorMessage
|
|
182
|
-
};
|
|
183
|
-
this.sendToClient(sessionId, errorObject);
|
|
184
|
-
this.sessions.clear();
|
|
185
|
-
await this.shutdown();
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Updates the instance with a new identifier, updating the platformInstances mapping as well.
|
|
189
|
-
* @param identifier
|
|
190
|
-
*/
|
|
191
|
-
updateIdentifier(identifier) {
|
|
192
|
-
exports.platformInstances.delete(this.id);
|
|
193
|
-
this.id = identifier;
|
|
194
|
-
exports.platformInstances.set(this.id, this);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Generates a function tied to a given client session (socket connection), the generated
|
|
198
|
-
* function will be called for each session ID registered, for every platform emit.
|
|
199
|
-
* @param listener
|
|
200
|
-
* @param sessionId
|
|
201
|
-
*/
|
|
202
|
-
callbackFunction(listener, sessionId) {
|
|
203
|
-
const funcs = {
|
|
204
|
-
'close': async (e) => {
|
|
205
|
-
this.debug(`close even triggered ${this.id}: ${e}`);
|
|
206
|
-
await this.reportError(sessionId, `Error: session thread closed unexpectedly: ${e}`);
|
|
207
|
-
},
|
|
208
|
-
'message': async ([first, second, third]) => {
|
|
209
|
-
if (first === 'updateActor') {
|
|
210
|
-
// We need to update the key to the store in order to find it in the future.
|
|
211
|
-
this.updateIdentifier(third);
|
|
212
|
-
}
|
|
213
|
-
else if ((first === 'error') && (typeof second === "string")) {
|
|
214
|
-
await this.reportError(sessionId, second);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
// treat like a message to clients
|
|
218
|
-
this.sendToClient(sessionId, second);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
return funcs[listener];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.default = PlatformInstance;
|
|
226
|
-
//# sourceMappingURL=/platform-instance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platform-instance.js","sourceRoot":"/","sources":["platform-instance.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAkD;AAClD,+BAA4B;AAC5B,iCAAwC;AAExC,sDAAiE;AAEjE,sDAA8B;AAC9B,yCAAuC;AACvC,kDAA0B;AAE1B,mDAAmD;AACtC,QAAA,iBAAiB,GAAG,IAAI,GAAG,EAA4B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