@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
package/dist/platform.d.ts
DELETED
package/dist/platform.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const debug_1 = __importDefault(require("debug"));
|
|
30
|
-
const crypto_1 = __importStar(require("@sockethub/crypto"));
|
|
31
|
-
const data_layer_1 = require("@sockethub/data-layer");
|
|
32
|
-
// command-line params
|
|
33
|
-
const parentId = process.argv[2];
|
|
34
|
-
const platformName = process.argv[3];
|
|
35
|
-
let identifier = process.argv[4];
|
|
36
|
-
const loggerPrefix = `sockethub:platform:${platformName}:${identifier}`;
|
|
37
|
-
let logger = (0, debug_1.default)(loggerPrefix);
|
|
38
|
-
const redisConfig = process.env.REDIS_URL ? process.env.REDIS_URL
|
|
39
|
-
: { host: process.env.REDIS_HOST, port: process.env.REDIS_PORT };
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
41
|
-
const PlatformModule = require(`@sockethub/platform-${platformName}`);
|
|
42
|
-
let jobQueue;
|
|
43
|
-
let jobQueueStarted = false;
|
|
44
|
-
let parentSecret1, parentSecret2;
|
|
45
|
-
logger(`platform handler initialized for ${platformName} ${identifier}`);
|
|
46
|
-
/**
|
|
47
|
-
* Handle any uncaught errors from the platform by alerting the worker and shutting down.
|
|
48
|
-
*/
|
|
49
|
-
process.on('uncaughtException', (err) => {
|
|
50
|
-
console.log('EXCEPTION IN PLATFORM');
|
|
51
|
-
// eslint-disable-next-line security-node/detect-crlf
|
|
52
|
-
console.log(err.stack);
|
|
53
|
-
process.send(['error', err.toString()]);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Incoming messages from the worker to this platform. Data is an array, the first property is the
|
|
58
|
-
* method to call, the rest are params.
|
|
59
|
-
*/
|
|
60
|
-
process.on('message', async (data) => {
|
|
61
|
-
if (data[0] === 'secrets') {
|
|
62
|
-
const { parentSecret2: parentSecret3, parentSecret1: parentSecret } = data[1];
|
|
63
|
-
parentSecret1 = parentSecret;
|
|
64
|
-
parentSecret2 = parentSecret3;
|
|
65
|
-
await startQueueListener();
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw new Error('received unknown command from parent thread');
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
/**
|
|
72
|
-
* Initialize platform module
|
|
73
|
-
*/
|
|
74
|
-
const platformSession = {
|
|
75
|
-
debug: (0, debug_1.default)(`sockethub:platform:${platformName}:${identifier}`),
|
|
76
|
-
sendToClient: getSendFunction('message'),
|
|
77
|
-
updateActor: updateActor
|
|
78
|
-
};
|
|
79
|
-
const platform = new PlatformModule(platformSession);
|
|
80
|
-
/**
|
|
81
|
-
* Returns a function used to handle completed jobs from the platform code (the `done` callback).
|
|
82
|
-
*/
|
|
83
|
-
function getJobHandler() {
|
|
84
|
-
return (job, done) => {
|
|
85
|
-
const jobLog = (0, debug_1.default)(`${loggerPrefix}:${job.sessionId}`);
|
|
86
|
-
jobLog(`received ${job.title} ${job.msg.type}`);
|
|
87
|
-
const credentialStore = new data_layer_1.CredentialsStore(parentId, job.sessionId, parentSecret1 + job.msg.sessionSecret, redisConfig);
|
|
88
|
-
delete job.msg.sessionSecret;
|
|
89
|
-
let jobCallbackCalled = false;
|
|
90
|
-
const doneCallback = (err, result) => {
|
|
91
|
-
if (jobCallbackCalled) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
jobCallbackCalled = true;
|
|
95
|
-
if (err) {
|
|
96
|
-
jobLog(`failed ${job.title} ${job.msg.type}`);
|
|
97
|
-
let errMsg;
|
|
98
|
-
// some error objects (eg. TimeoutError) don't interpolate correctly to human-readable
|
|
99
|
-
// so we have to do this little dance
|
|
100
|
-
try {
|
|
101
|
-
errMsg = err.toString();
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
errMsg = err;
|
|
105
|
-
}
|
|
106
|
-
done(new Error(errMsg));
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
jobLog(`completed ${job.title} ${job.msg.type}`);
|
|
110
|
-
done(null, result);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
platform.config.requireCredentials ? platform.config.requireCredentials : [];
|
|
114
|
-
if (platform.config.requireCredentials.includes(job.msg.type)) {
|
|
115
|
-
// this method requires credentials and should be called even if the platform is not
|
|
116
|
-
// yet initialized, because they need to authenticate before they are initialized.
|
|
117
|
-
credentialStore.get(job.msg.actor.id, platform.credentialsHash).then((credentials) => {
|
|
118
|
-
platform[job.msg.type](job.msg, credentials, doneCallback);
|
|
119
|
-
}).catch((err) => {
|
|
120
|
-
jobLog('error ' + err.toString());
|
|
121
|
-
return done(new Error(err.toString()));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
else if ((platform.config.persist) && (!platform.initialized)) {
|
|
125
|
-
done(new Error(`${job.msg.type} called on uninitialized platform`));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
platform[job.msg.type](job.msg, doneCallback);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get an function which sends a message to the parent thread (PlatformInstance). The platform
|
|
134
|
-
* can call that function to send messages back to the client.
|
|
135
|
-
* @param command string containing the type of command to be sent. 'message' or 'close'
|
|
136
|
-
*/
|
|
137
|
-
function getSendFunction(command) {
|
|
138
|
-
return function (msg, special) {
|
|
139
|
-
process.send([command, msg, special]);
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* When a user changes it's actor name, the channel identifier changes, we need to ensure that
|
|
144
|
-
* both the queue thread (listening on the channel for jobs) and the logging object are updated.
|
|
145
|
-
* @param credentials
|
|
146
|
-
*/
|
|
147
|
-
async function updateActor(credentials) {
|
|
148
|
-
identifier = (0, crypto_1.getPlatformId)(platformName, credentials.actor.id);
|
|
149
|
-
logger(`platform actor updated to ${credentials.actor.id} identifier ${identifier}`);
|
|
150
|
-
logger = (0, debug_1.default)(`sockethub:platform:${identifier}`);
|
|
151
|
-
platform.credentialsHash = crypto_1.default.objectHash(credentials.object);
|
|
152
|
-
platform.debug = (0, debug_1.default)(`sockethub:platform:${platformName}:${identifier}`);
|
|
153
|
-
process.send(['updateActor', undefined, identifier]);
|
|
154
|
-
await startQueueListener(true);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Starts listening on the queue for incoming jobs
|
|
158
|
-
* @param refresh boolean if the param is true, we re-init the queue.process
|
|
159
|
-
* (used when identifier changes)
|
|
160
|
-
*/
|
|
161
|
-
async function startQueueListener(refresh = false) {
|
|
162
|
-
if (jobQueueStarted) {
|
|
163
|
-
if (refresh) {
|
|
164
|
-
await jobQueue.shutdown();
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
logger('start queue called multiple times, skipping');
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
jobQueue = new data_layer_1.JobQueue(parentId, identifier, parentSecret1 + parentSecret2, redisConfig);
|
|
172
|
-
logger('listening on the queue for incoming jobs');
|
|
173
|
-
jobQueue.onJob(getJobHandler());
|
|
174
|
-
jobQueueStarted = true;
|
|
175
|
-
}
|
|
176
|
-
//# sourceMappingURL=/platform.js.map
|
package/dist/platform.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"/","sources":["platform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,4DAAwD;AACxD,sDAA8E;AAG9E,sBAAsB;AACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjC,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACrC,IAAI,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjC,MAAM,YAAY,GAAG,sBAAsB,YAAY,IAAI,UAAU,EAAE,CAAC;AACxE,IAAI,MAAM,GAAG,IAAA,eAAK,EAAC,YAAY,CAA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AAI,qBAAQ,CACrB,QAAQ,EAAE,UAAU,EAAE,aAAa,GAAG,aAAa,EAAE,WAA0B,CAChF,CAAC;IACF,MAAM,CAAC,0CAA0C,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAChC,eAAe,GAAG,IAAI,CAAC;AACzB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import PlatformInstance from "./platform-instance";
|
|
2
|
-
declare class ProcessManager {
|
|
3
|
-
private readonly parentId;
|
|
4
|
-
private readonly parentSecret1;
|
|
5
|
-
private readonly parentSecret2;
|
|
6
|
-
constructor(parentId: string, parentSecret1: string, parentSecret2: string);
|
|
7
|
-
get(platform: string, actorId: string, sessionId?: string): PlatformInstance;
|
|
8
|
-
private createPlatformInstance;
|
|
9
|
-
private ensureProcess;
|
|
10
|
-
}
|
|
11
|
-
export default ProcessManager;
|
package/dist/process-manager.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const init_1 = __importDefault(require("./bootstrap/init"));
|
|
30
|
-
const platform_instance_1 = __importStar(require("./platform-instance"));
|
|
31
|
-
const crypto_1 = require("@sockethub/crypto");
|
|
32
|
-
class ProcessManager {
|
|
33
|
-
constructor(parentId, parentSecret1, parentSecret2) {
|
|
34
|
-
this.parentId = parentId;
|
|
35
|
-
this.parentSecret1 = parentSecret1;
|
|
36
|
-
this.parentSecret2 = parentSecret2;
|
|
37
|
-
}
|
|
38
|
-
get(platform, actorId, sessionId) {
|
|
39
|
-
const platformDetails = init_1.default.platforms.get(platform);
|
|
40
|
-
let pi;
|
|
41
|
-
if (platformDetails.config.persist) {
|
|
42
|
-
// ensure process is started - one for each actor
|
|
43
|
-
pi = this.ensureProcess(platform, sessionId, actorId);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// ensure process is started - one for all jobs
|
|
47
|
-
pi = this.ensureProcess(platform);
|
|
48
|
-
}
|
|
49
|
-
pi.config = platformDetails.config;
|
|
50
|
-
return pi;
|
|
51
|
-
}
|
|
52
|
-
createPlatformInstance(identifier, platform, actor) {
|
|
53
|
-
const secrets = [
|
|
54
|
-
'secrets', {
|
|
55
|
-
parentSecret1: this.parentSecret1,
|
|
56
|
-
parentSecret2: this.parentSecret2
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
const platformInstanceConfig = {
|
|
60
|
-
identifier: identifier,
|
|
61
|
-
platform: platform,
|
|
62
|
-
parentId: this.parentId,
|
|
63
|
-
actor: actor
|
|
64
|
-
};
|
|
65
|
-
const platformInstance = new platform_instance_1.default(platformInstanceConfig);
|
|
66
|
-
platformInstance.initQueue(this.parentSecret1 + this.parentSecret2);
|
|
67
|
-
platformInstance.process.send(secrets);
|
|
68
|
-
return platformInstance;
|
|
69
|
-
}
|
|
70
|
-
ensureProcess(platform, sessionId, actor) {
|
|
71
|
-
const identifier = (0, crypto_1.getPlatformId)(platform, actor);
|
|
72
|
-
const platformInstance = platform_instance_1.platformInstances.get(identifier) ||
|
|
73
|
-
this.createPlatformInstance(identifier, platform, actor);
|
|
74
|
-
if (sessionId) {
|
|
75
|
-
platformInstance.registerSession(sessionId);
|
|
76
|
-
}
|
|
77
|
-
platform_instance_1.platformInstances.set(identifier, platformInstance);
|
|
78
|
-
return platformInstance;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.default = ProcessManager;
|
|
82
|
-
//# sourceMappingURL=/process-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-manager.js","sourceRoot":"/","sources":["process-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAoC;AACpC,yEAC4F;AAC5F,8CAAgD;AAEhD,MAAM,cAAc;IAKlB,YAAY,QAAgB,EAAE,aAAqB,EAAE,aAAqB;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,QAAgB,EAAE,OAAe,EAAE,SAAkB;QACvD,MAAM,eAAe,GAAG,cAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,EAAE,CAAC;QAEP,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE;YAClC,iDAAiD;YACjD,EA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AAU,EAAE,gBAAgB,CAAC,CAAC;QACpD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
package/dist/routes.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface IRoutePaths {
|
|
2
|
-
[key: string]: string;
|
|
3
|
-
}
|
|
4
|
-
export declare const basePaths: IRoutePaths;
|
|
5
|
-
export declare const examplePaths: IRoutePaths;
|
|
6
|
-
export declare const examplePages: IRoutePaths;
|
|
7
|
-
/**
|
|
8
|
-
* Setup
|
|
9
|
-
*/
|
|
10
|
-
declare const routes: {
|
|
11
|
-
setup: (app: unknown, examplesEnabled?: boolean) => void;
|
|
12
|
-
};
|
|
13
|
-
export default routes;
|
package/dist/routes.js
DELETED
|
@@ -1,83 +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.examplePages = exports.examplePaths = exports.basePaths = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const config_1 = __importDefault(require("./config"));
|
|
9
|
-
const debug_1 = __importDefault(require("debug"));
|
|
10
|
-
const debug_scope = process.env.DEBUG || '', logger = (0, debug_1.default)('sockethub:server:routes'), address = config_1.default.get('public:protocol') + '://' +
|
|
11
|
-
config_1.default.get('public:host') + ':' +
|
|
12
|
-
config_1.default.get('public:port') +
|
|
13
|
-
config_1.default.get('public:path');
|
|
14
|
-
exports.basePaths = {
|
|
15
|
-
'/sockethub-client.js': path_1.default.resolve(`${__dirname}/../node_modules/@sockethub/client/dist/sockethub-client.js`),
|
|
16
|
-
'/sockethub-client.min.js': path_1.default.resolve(`${__dirname}/../node_modules/@sockethub/client/dist/sockethub-client.min.js`),
|
|
17
|
-
'/sockethub-client.js.map': path_1.default.resolve(`${__dirname}/../node_modules/@sockethub/client/dist/sockethub-client.js.map`),
|
|
18
|
-
'/socket.io.js': path_1.default.resolve(`${__dirname}/../node_modules/socket.io/client-dist/socket.io.js`)
|
|
19
|
-
};
|
|
20
|
-
exports.examplePaths = {
|
|
21
|
-
'/jquery.js': path_1.default.resolve(`${__dirname}/../node_modules/jquery/dist/jquery.min.js`),
|
|
22
|
-
'/jquery.min.map': path_1.default.resolve(`${__dirname}/../node_modules/jquery/dist/jquery.min.map`),
|
|
23
|
-
'/examples/shared.js': path_1.default.resolve(`${__dirname}/../views/examples/shared.js`)
|
|
24
|
-
};
|
|
25
|
-
exports.examplePages = {
|
|
26
|
-
'/': path_1.default.resolve(`${__dirname}/../views/index.ejs`),
|
|
27
|
-
'/examples/dummy': path_1.default.resolve(`${__dirname}/../views/examples/dummy.ejs`),
|
|
28
|
-
'/examples/feeds': path_1.default.resolve(`${__dirname}/../views/examples/feeds.ejs`),
|
|
29
|
-
'/examples/irc': path_1.default.resolve(`${__dirname}/../views/examples/irc.ejs`),
|
|
30
|
-
'/examples/xmpp': path_1.default.resolve(`${__dirname}/../views/examples/xmpp.ejs`)
|
|
31
|
-
};
|
|
32
|
-
function prepFileRoutes(pathMap) {
|
|
33
|
-
const _routes = [];
|
|
34
|
-
Object.keys(pathMap).forEach((key) => {
|
|
35
|
-
_routes.push({
|
|
36
|
-
meta: {
|
|
37
|
-
method: 'GET',
|
|
38
|
-
path: key
|
|
39
|
-
},
|
|
40
|
-
route: (req, res) => {
|
|
41
|
-
logger(`serving resource ${req.url}`);
|
|
42
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
43
|
-
res.sendFile(pathMap[req.url]);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return _routes;
|
|
48
|
-
}
|
|
49
|
-
const baseRoutes = prepFileRoutes(exports.basePaths);
|
|
50
|
-
const exampleRoutes = prepFileRoutes(exports.examplePaths);
|
|
51
|
-
Object.keys(exports.examplePages).forEach((key) => {
|
|
52
|
-
exampleRoutes.push({
|
|
53
|
-
meta: {
|
|
54
|
-
method: 'GET',
|
|
55
|
-
path: key
|
|
56
|
-
},
|
|
57
|
-
route: (req, res) => {
|
|
58
|
-
logger(`serving page ${req.url}`);
|
|
59
|
-
res.render(exports.examplePages[req.url], {
|
|
60
|
-
debug_scope: debug_scope,
|
|
61
|
-
address: address,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
function addRoute(app) {
|
|
67
|
-
return (route) => {
|
|
68
|
-
app[route.meta.method.toLowerCase()](route.meta.path, route.route);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Setup
|
|
73
|
-
*/
|
|
74
|
-
const routes = {
|
|
75
|
-
setup: function (app, examplesEnabled = config_1.default.get('examples:enabled')) {
|
|
76
|
-
baseRoutes.forEach(addRoute(app));
|
|
77
|
-
if (examplesEnabled) {
|
|
78
|
-
exampleRoutes.forEach(addRoute(app));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
exports.default = routes;
|
|
83
|
-
//# sourceMappingURL=/routes.js.map
|
package/dist/routes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"/","sources":["routes.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAC9B,kDAA0B;AAE1B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,EACrC,MAAM,GAAQ,IAAA,eAAK,EAAC,yBAAyB,CAAC,EAC9C,OAAO,GAAO,gBAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,KAAK;IACrC,gBAAM,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,GAAG;IAC/B,gBAAM,CAAC,GAAG,CAAC,aAAa,CAAC;IACzB,gBAAM,CAAC,GAAG,CAAC,aAA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AK,EAAE,UAAU,GAAY,EACZ,kBAA2B,gBAAM,CAAC,GAAG,CAAC,kBAAkB,CAAY;QACnF,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,IAAI,eAAe,EAAE;YACnB,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;SACtC;IACH,CAAC;CACF,CAAC;AACF,kBAAe,MAAM,CAAC"}
|
package/dist/sockethub.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import ProcessManager from "./process-manager";
|
|
2
|
-
declare class Sockethub {
|
|
3
|
-
private readonly parentId;
|
|
4
|
-
private readonly parentSecret1;
|
|
5
|
-
private readonly parentSecret2;
|
|
6
|
-
counter: number;
|
|
7
|
-
platforms: Map<string, object>;
|
|
8
|
-
status: boolean;
|
|
9
|
-
processManager: ProcessManager;
|
|
10
|
-
constructor();
|
|
11
|
-
/**
|
|
12
|
-
* initialization of Sockethub starts here
|
|
13
|
-
*/
|
|
14
|
-
boot(): void;
|
|
15
|
-
shutdown(): Promise<void>;
|
|
16
|
-
private handleIncomingConnection;
|
|
17
|
-
}
|
|
18
|
-
export default Sockethub;
|
package/dist/sockethub.js
DELETED
|
@@ -1,112 +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
|
-
const debug_1 = __importDefault(require("debug"));
|
|
7
|
-
const crypto_1 = __importDefault(require("@sockethub/crypto"));
|
|
8
|
-
const data_layer_1 = require("@sockethub/data-layer");
|
|
9
|
-
const init_1 = __importDefault(require("./bootstrap/init"));
|
|
10
|
-
const middleware_1 = __importDefault(require("./middleware"));
|
|
11
|
-
const create_activity_object_1 = __importDefault(require("./middleware/create-activity-object"));
|
|
12
|
-
const expand_activity_stream_1 = __importDefault(require("./middleware/expand-activity-stream"));
|
|
13
|
-
const store_credentials_1 = __importDefault(require("./middleware/store-credentials"));
|
|
14
|
-
const validate_1 = __importDefault(require("./middleware/validate"));
|
|
15
|
-
const janitor_1 = __importDefault(require("./janitor"));
|
|
16
|
-
const listener_1 = __importDefault(require("./listener"));
|
|
17
|
-
const process_manager_1 = __importDefault(require("./process-manager"));
|
|
18
|
-
const nconf_1 = __importDefault(require("nconf"));
|
|
19
|
-
const log = (0, debug_1.default)('sockethub:server:core');
|
|
20
|
-
function attachError(err, msg) {
|
|
21
|
-
if (typeof msg !== 'object') {
|
|
22
|
-
msg = { context: 'error' };
|
|
23
|
-
}
|
|
24
|
-
msg.error = err.toString();
|
|
25
|
-
delete msg.sessionSecret;
|
|
26
|
-
return msg;
|
|
27
|
-
}
|
|
28
|
-
class Sockethub {
|
|
29
|
-
constructor() {
|
|
30
|
-
this.platforms = init_1.default.platforms;
|
|
31
|
-
this.status = false;
|
|
32
|
-
this.parentId = crypto_1.default.randToken(16);
|
|
33
|
-
this.parentSecret1 = crypto_1.default.randToken(16);
|
|
34
|
-
this.parentSecret2 = crypto_1.default.randToken(16);
|
|
35
|
-
this.processManager = new process_manager_1.default(this.parentId, this.parentSecret1, this.parentSecret2);
|
|
36
|
-
log('session id: ' + this.parentId);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* initialization of Sockethub starts here
|
|
40
|
-
*/
|
|
41
|
-
boot() {
|
|
42
|
-
if (this.status) {
|
|
43
|
-
return log('Sockethub.boot() called more than once');
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this.status = true;
|
|
47
|
-
}
|
|
48
|
-
log('active platforms: ', [...init_1.default.platforms.keys()]);
|
|
49
|
-
listener_1.default.start(); // start external services
|
|
50
|
-
janitor_1.default.start(); // start cleanup cycle
|
|
51
|
-
log('registering handlers');
|
|
52
|
-
listener_1.default.io.on('connection', this.handleIncomingConnection.bind(this));
|
|
53
|
-
}
|
|
54
|
-
async shutdown() {
|
|
55
|
-
await janitor_1.default.stop();
|
|
56
|
-
}
|
|
57
|
-
handleIncomingConnection(socket) {
|
|
58
|
-
// session-specific debug messages
|
|
59
|
-
const sessionLog = (0, debug_1.default)('sockethub:server:core:' + socket.id), sessionSecret = crypto_1.default.randToken(16),
|
|
60
|
-
// store instance is session-specific
|
|
61
|
-
// store = getSessionStore(this.parentId, this.parentSecret1, socket.id, sessionSecret);
|
|
62
|
-
credentialsStore = new data_layer_1.CredentialsStore(this.parentId, socket.id, this.parentSecret1 + sessionSecret, nconf_1.default.get('redis'));
|
|
63
|
-
sessionLog(`socket.io connection`);
|
|
64
|
-
socket.on('disconnect', () => {
|
|
65
|
-
sessionLog('disconnect received from client');
|
|
66
|
-
});
|
|
67
|
-
socket.on('credentials', (0, middleware_1.default)('credentials')
|
|
68
|
-
.use(expand_activity_stream_1.default)
|
|
69
|
-
.use((0, validate_1.default)('credentials', socket.id))
|
|
70
|
-
.use((0, store_credentials_1.default)(credentialsStore))
|
|
71
|
-
.use((err, data, next) => {
|
|
72
|
-
// error handler
|
|
73
|
-
next(attachError(err, data));
|
|
74
|
-
}).use((data, next) => { next(); })
|
|
75
|
-
.done());
|
|
76
|
-
// when new activity objects are created on the client side, an event is
|
|
77
|
-
// fired and we receive a copy on the server side.
|
|
78
|
-
socket.on('activity-object', (0, middleware_1.default)('activity-object')
|
|
79
|
-
.use((0, validate_1.default)('activity-object', socket.id))
|
|
80
|
-
.use(create_activity_object_1.default)
|
|
81
|
-
.use((err, data, next) => {
|
|
82
|
-
next(attachError(err, data));
|
|
83
|
-
}).use((data, next) => { next(); })
|
|
84
|
-
.done());
|
|
85
|
-
socket.on('message', (0, middleware_1.default)('message')
|
|
86
|
-
.use(expand_activity_stream_1.default)
|
|
87
|
-
.use((0, validate_1.default)('message', socket.id))
|
|
88
|
-
.use((msg, next) => {
|
|
89
|
-
// The platform thread must find the credentials on their own using the given
|
|
90
|
-
// sessionSecret, which indicates that this specific session (socket
|
|
91
|
-
// connection) has provided credentials.
|
|
92
|
-
msg.sessionSecret = sessionSecret;
|
|
93
|
-
next(msg);
|
|
94
|
-
}).use((err, data, next) => {
|
|
95
|
-
next(attachError(err, data));
|
|
96
|
-
}).use(async (msg, next) => {
|
|
97
|
-
const platformInstance = this.processManager.get(msg.context, msg.actor.id, socket.id);
|
|
98
|
-
// job validated and queued, store socket.io callback for when job is completed
|
|
99
|
-
const job = await platformInstance.jobQueue.add(socket.id, msg);
|
|
100
|
-
if (job) {
|
|
101
|
-
platformInstance.completedJobHandlers.set(job.title, next);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// failed to add job to queue, reject handler immediately
|
|
105
|
-
msg.error = 'failed to add job to queue';
|
|
106
|
-
next(msg);
|
|
107
|
-
}
|
|
108
|
-
}).done());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.default = Sockethub;
|
|
112
|
-
//# sourceMappingURL=/sockethub.js.map
|
package/dist/sockethub.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sockethub.js","sourceRoot":"/","sources":["sockethub.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,+DAAuC;AACvC,sDAAuD;AAEvD,4DAAoC;AACpC,8DAAkE;AAClE,iGAAuE;AACvE,iGAAuE;AACvE,uFAA8D;AAC9D,qEAA6C;AAC7C,wDAAgC;AAChC,0DAAkC;AAClC,wEAA+C;AAC/C,kDAA0B;AAG1B,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,uBAAuB,CAAC,CAAC;AAE3C,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG;IAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;KAC5B;IACD,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC3B,OAAO,GAAG,CAAC,aAAa,CAA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AoB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;aAC5D;iBAAM;gBACL,yDAAyD;gBACzD,GAAG,CAAC,KAAK,GAAG,4BAA4B,CAAC;gBACzC,IAAI,CAAC,GAAG,CAAC,CAAC;aACX;QACH,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,CAAC;CACF;AAED,kBAAe,SAAS,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bootstrap/platforms.js
|
|
3
|
-
*
|
|
4
|
-
* A Singleton responsible for finding and loading all valid Sockethub
|
|
5
|
-
* platforms, and whitelisting or blacklisting (or neither) based on the
|
|
6
|
-
* config.
|
|
7
|
-
*/
|
|
8
|
-
const debug = require('debug'),
|
|
9
|
-
schemas = require('@sockethub/schemas').default;
|
|
10
|
-
|
|
11
|
-
const log = debug('sockethub:server:bootstrap:platforms');
|
|
12
|
-
|
|
13
|
-
log('loading platforms');
|
|
14
|
-
|
|
15
|
-
// if the platform schema lists valid types it implements (essentially methods/verbs for
|
|
16
|
-
// Sockethub to call) then add it to the supported types list.
|
|
17
|
-
function platformListsSupportedTypes(p) {
|
|
18
|
-
return ((p.schema.messages.properties) && (p.schema.messages.properties.type) &&
|
|
19
|
-
(p.schema.messages.properties.type.enum) &&
|
|
20
|
-
(p.schema.messages.properties.type.enum.length > 0));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = function platformLoad(platformsList, requireModule) {
|
|
24
|
-
if (!requireModule) {
|
|
25
|
-
requireModule = require;
|
|
26
|
-
}
|
|
27
|
-
// load platforms from config.platforms
|
|
28
|
-
const platforms = new Map();
|
|
29
|
-
|
|
30
|
-
if (platformsList.length <= 0) {
|
|
31
|
-
throw new Error('No platforms defined. Please check your sockethub.config.json');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (let moduleName of platformsList) {
|
|
35
|
-
log(`loading ${moduleName}`);
|
|
36
|
-
// try to load platform
|
|
37
|
-
// eslint-disable-next-line security-node/detect-non-literal-require-calls
|
|
38
|
-
const P = requireModule(moduleName);
|
|
39
|
-
const p = new P();
|
|
40
|
-
let types = [];
|
|
41
|
-
|
|
42
|
-
const err = schemas.validatePlatformSchema(p.schema);
|
|
43
|
-
if (err) {
|
|
44
|
-
throw new Error(`${moduleName} ${err}`);
|
|
45
|
-
} else if (typeof p.config !== 'object') {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`${moduleName} platform must have a config property that is an object.`);
|
|
48
|
-
} else {
|
|
49
|
-
if (p.schema.credentials) {
|
|
50
|
-
// register the platforms credentials schema
|
|
51
|
-
types.push('credentials');
|
|
52
|
-
} else {
|
|
53
|
-
p.config.noCredentials = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (platformListsSupportedTypes(p)) {
|
|
58
|
-
types = [...types, ...p.schema.messages.properties.type.enum];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const platformName = p.schema.name;
|
|
62
|
-
platforms.set(platformName, {
|
|
63
|
-
id: platformName,
|
|
64
|
-
moduleName: moduleName,
|
|
65
|
-
config: p.config,
|
|
66
|
-
schemas: {
|
|
67
|
-
credentials: p.schema.credentials || {},
|
|
68
|
-
messages: p.schema.messages || {}
|
|
69
|
-
},
|
|
70
|
-
version: p.schema.version,
|
|
71
|
-
types: types
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return platforms;
|
|
75
|
-
};
|
package/test/init-suite.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
if (typeof define !== 'function') {
|
|
2
|
-
let define = require('amdefine')(module);
|
|
3
|
-
}
|
|
4
|
-
define(['require'], function (require) {
|
|
5
|
-
return [
|
|
6
|
-
{
|
|
7
|
-
desc: 'dist/bootstrap/init',
|
|
8
|
-
abortOnFail: true,
|
|
9
|
-
setup: function (env, test) {
|
|
10
|
-
env.init = require('../dist/bootstrap/init').default;
|
|
11
|
-
test.assertType(env.init, 'object');
|
|
12
|
-
},
|
|
13
|
-
tests: [
|
|
14
|
-
{
|
|
15
|
-
desc: 'platforms',
|
|
16
|
-
run: function (env, test) {
|
|
17
|
-
test.assertTypeAnd(env.init.platforms, 'object');
|
|
18
|
-
test.assert(env.init.platforms.has('irc'), true);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
desc: 'nconf should have defaults set',
|
|
25
|
-
setup: function (env, test) {
|
|
26
|
-
env.nconf = require('nconf');
|
|
27
|
-
test.assertType(env.nconf.get, 'function');
|
|
28
|
-
},
|
|
29
|
-
tests: [
|
|
30
|
-
{
|
|
31
|
-
desc: 'whitelist and blacklist',
|
|
32
|
-
run: function (env, test) {
|
|
33
|
-
console.log('whitelist: ', typeof require('nconf').get('platforms:whitelist'));
|
|
34
|
-
test.assertTypeAnd(require('nconf').get('platforms:whitelist'), 'array');
|
|
35
|
-
test.assertType(require('nconf').get('platforms:blacklist'), 'array');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
];
|
|
41
|
-
});
|