@sockethub/server 5.0.0-alpha.3 → 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 -60
- 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 +20 -7
- package/src/bootstrap/init.test.ts +211 -0
- package/src/bootstrap/init.ts +152 -75
- package/src/bootstrap/load-platforms.ts +151 -0
- package/src/config.test.ts +27 -22
- package/src/config.ts +82 -78
- package/src/defaults.json +24 -16
- package/src/index.ts +67 -27
- package/src/janitor.test.ts +211 -0
- package/src/janitor.ts +145 -77
- package/src/listener.ts +151 -57
- package/src/middleware/create-activity-object.test.ts +28 -8
- package/src/middleware/create-activity-object.ts +17 -8
- package/src/middleware/expand-activity-stream.test.data.ts +332 -346
- package/src/middleware/expand-activity-stream.test.ts +65 -66
- package/src/middleware/expand-activity-stream.ts +29 -19
- package/src/middleware/store-credentials.test.ts +74 -62
- package/src/middleware/store-credentials.ts +15 -15
- package/src/middleware/validate.test.data.ts +240 -242
- package/src/middleware/validate.test.ts +39 -78
- package/src/middleware/validate.ts +63 -39
- package/src/middleware.test.ts +168 -138
- package/src/middleware.ts +62 -43
- package/src/platform-instance.test.ts +507 -213
- package/src/platform-instance.ts +337 -219
- package/src/platform.test.ts +375 -0
- package/src/platform.ts +306 -139
- package/src/process-manager.ts +75 -51
- package/src/routes.test.ts +43 -89
- package/src/routes.ts +40 -77
- package/src/sentry.test.ts +106 -0
- package/src/sentry.ts +19 -0
- package/src/sockethub.ts +186 -153
- package/src/util.ts +5 -0
- package/coverage/tmp/coverage-93126-1649152190997-0.json +0 -1
- package/dist/bootstrap/init.d.ts +0 -18
- package/dist/bootstrap/init.js +0 -63
- package/dist/bootstrap/init.js.map +0 -1
- package/dist/bootstrap/platforms.js +0 -75
- package/dist/common.d.ts +0 -3
- package/dist/common.js +0 -20
- package/dist/common.js.map +0 -1
- package/dist/config.d.ts +0 -6
- package/dist/config.js +0 -102
- package/dist/config.js.map +0 -1
- package/dist/crypto.d.ts +0 -10
- package/dist/crypto.js +0 -38
- package/dist/crypto.js.map +0 -1
- package/dist/defaults.json +0 -28
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -1
- package/dist/janitor.d.ts +0 -15
- package/dist/janitor.js +0 -89
- package/dist/janitor.js.map +0 -1
- package/dist/listener.d.ts +0 -28
- package/dist/listener.js +0 -91
- package/dist/listener.js.map +0 -1
- package/dist/middleware/create-activity-object.d.ts +0 -6
- 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 -2
- package/dist/middleware/expand-activity-stream.js +0 -33
- 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 -19
- package/dist/middleware/store-credentials.js.map +0 -1
- package/dist/middleware/validate.d.ts +0 -2
- package/dist/middleware/validate.js +0 -58
- 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 -10
- package/dist/middleware.js +0 -54
- package/dist/middleware.js.map +0 -1
- package/dist/platform-instance.d.ts +0 -77
- package/dist/platform-instance.js +0 -211
- package/dist/platform-instance.js.map +0 -1
- package/dist/platform.d.ts +0 -6
- package/dist/platform.js +0 -187
- package/dist/platform.js.map +0 -1
- package/dist/process-manager.d.ts +0 -11
- package/dist/process-manager.js +0 -78
- 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 -39
- package/dist/sockethub.js +0 -119
- package/dist/sockethub.js.map +0 -1
- package/dist/store.d.ts +0 -5
- package/dist/store.js +0 -17
- package/dist/store.js.map +0 -1
- package/src/bootstrap/platforms.js +0 -75
- package/src/common.test.ts +0 -54
- package/src/common.ts +0 -14
- package/src/config.d.ts +0 -2
- package/src/crypto.d.ts +0 -5
- package/src/crypto.test.ts +0 -41
- package/src/crypto.ts +0 -41
- package/src/janitor.d.ts +0 -8
- package/src/middleware/validate.d.ts +0 -1
- package/src/middleware.d.ts +0 -21
- package/src/sockethub.d.ts +0 -1
- package/src/store.test.ts +0 -28
- package/src/store.ts +0 -17
- package/test/init-suite.js +0 -41
- package/test/queue.functional.test.js +0 -0
- package/test/sockethub-suite.js +0 -25
- package/tsconfig.json +0 -18
- package/views/examples/dummy.ejs +0 -93
- 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 -191
- package/views/index.ejs +0 -17
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
import { expect } from
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import expandActivityStream from "./expand-activity-stream";
|
|
3
|
+
import expandActivityStream from "./expand-activity-stream.js";
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import { ASFactory } from "@sockethub/activity-streams";
|
|
6
|
+
import asObjects from "./expand-activity-stream.test.data.js";
|
|
7
|
+
import { ActivityStream } from "@sockethub/schemas";
|
|
8
|
+
|
|
9
|
+
const activity = ASFactory();
|
|
7
10
|
|
|
8
|
-
const activity = ActivityStreams();
|
|
9
11
|
// register known activity objects
|
|
10
12
|
[
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
{
|
|
14
|
+
id: "blah",
|
|
15
|
+
type: "person",
|
|
16
|
+
name: "dood",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "blah2",
|
|
20
|
+
type: "person",
|
|
21
|
+
name: "bob",
|
|
22
|
+
hello: "there",
|
|
23
|
+
i: ["am", "extras"],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "sh-9K3Vk@irc.freenode.net",
|
|
27
|
+
type: "person",
|
|
28
|
+
name: "sh-9K3Vk",
|
|
29
|
+
image: {
|
|
30
|
+
height: 250,
|
|
31
|
+
mediaType: "image/jpeg",
|
|
32
|
+
url: "https://example.org/image.jpg",
|
|
33
|
+
width: 250,
|
|
34
|
+
},
|
|
35
|
+
url: "https://sockethub.org",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "blah3",
|
|
39
|
+
type: "person",
|
|
40
|
+
name: "bob",
|
|
41
|
+
hello: "there",
|
|
42
|
+
i: ["am", "extras"],
|
|
35
43
|
},
|
|
36
|
-
"url":"http://sockethub.org"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"id":"blah3",
|
|
40
|
-
"type":"person",
|
|
41
|
-
"name":"bob",
|
|
42
|
-
"hello":"there",
|
|
43
|
-
"i":[
|
|
44
|
-
"am",
|
|
45
|
-
"extras"
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
44
|
].forEach((obj) => {
|
|
49
|
-
|
|
45
|
+
activity.Object.create(obj);
|
|
50
46
|
});
|
|
51
47
|
|
|
52
|
-
describe(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
describe("Middleware: Expand Activity Stream", () => {
|
|
49
|
+
describe("AS object expansion", () => {
|
|
50
|
+
asObjects.forEach((obj) => {
|
|
51
|
+
it(`${obj.type}: ${obj.name}, should ${
|
|
52
|
+
obj.valid ? "pass" : "fail"
|
|
53
|
+
}`, (done) => {
|
|
54
|
+
expandActivityStream(obj.input as ActivityStream, (msg) => {
|
|
55
|
+
if (obj.output) {
|
|
56
|
+
if (obj.output === "same") {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
expect(obj.input).toEqual(msg);
|
|
59
|
+
} else {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
expect(obj.output).toEqual(msg);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (obj.valid) {
|
|
65
|
+
expect(msg instanceof Error).toBeFalse();
|
|
66
|
+
} else {
|
|
67
|
+
expect(msg instanceof Error).toBeTrue();
|
|
68
|
+
if (obj.error) {
|
|
69
|
+
expect(obj.error).toEqual(msg.toString());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
done();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
74
75
|
});
|
|
75
|
-
});
|
|
76
76
|
});
|
|
77
|
-
});
|
|
78
77
|
});
|
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { ASFactory, type ASFactoryOptions } from "@sockethub/activity-streams";
|
|
2
|
+
import type { ActivityStream } from "@sockethub/schemas";
|
|
3
3
|
|
|
4
|
-
import config from "../config";
|
|
4
|
+
import config from "../config.js";
|
|
5
|
+
import type { MiddlewareChainInterface } from "../middleware.js";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const asConfig = config.get(
|
|
8
|
+
"packageConfig:@sockethub/activity-streams",
|
|
9
|
+
) as ASFactoryOptions;
|
|
10
|
+
asConfig.warnOnUnknownObjectProperties = false;
|
|
11
|
+
asConfig.failOnUnknownObjectProperties = false;
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
const activity = ASFactory(asConfig);
|
|
14
|
+
|
|
15
|
+
function ensureObject(msg: unknown) {
|
|
16
|
+
return !(typeof msg !== "object" || Array.isArray(msg));
|
|
10
17
|
}
|
|
11
18
|
|
|
12
|
-
export default function expandActivityStream(
|
|
13
|
-
|
|
14
|
-
done
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
done(new Error('activity stream must contain an actor property.'));
|
|
19
|
+
export default function expandActivityStream(
|
|
20
|
+
msg: ActivityStream,
|
|
21
|
+
done: MiddlewareChainInterface,
|
|
22
|
+
) {
|
|
23
|
+
if (!ensureObject(msg)) {
|
|
24
|
+
done(new Error("message received is not an object."));
|
|
25
|
+
} else if (typeof msg.context !== "string") {
|
|
26
|
+
done(new Error("activity stream must contain a context property"));
|
|
27
|
+
} else if (typeof msg.type !== "string") {
|
|
28
|
+
done(new Error("activity stream must contain a type property."));
|
|
23
29
|
} else {
|
|
24
|
-
|
|
30
|
+
const msgStream = activity.Stream(msg) as ActivityStream;
|
|
31
|
+
if (!msgStream.actor) {
|
|
32
|
+
done(new Error("activity stream must contain an actor property."));
|
|
33
|
+
} else {
|
|
34
|
+
done(msgStream);
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
|
-
}
|
|
27
37
|
}
|
|
@@ -1,73 +1,85 @@
|
|
|
1
|
-
import { expect } from
|
|
2
|
-
import * as sinon from
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import * as sinon from "sinon";
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import type { CredentialsObject } from "@sockethub/schemas";
|
|
5
|
+
import storeCredentials from "./store-credentials.js";
|
|
5
6
|
|
|
6
|
-
const creds = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
7
|
+
const creds: CredentialsObject = {
|
|
8
|
+
type: "credentials",
|
|
9
|
+
context: "dummy",
|
|
10
|
+
actor: {
|
|
11
|
+
id: "dood@irc.freenode.net",
|
|
12
|
+
type: "person",
|
|
13
|
+
name: "dood",
|
|
14
|
+
},
|
|
15
|
+
target: {
|
|
16
|
+
id: "irc.freenode.net/service",
|
|
17
|
+
type: "person",
|
|
18
|
+
name: "service",
|
|
19
|
+
},
|
|
20
|
+
object: {
|
|
21
|
+
type: "credentials",
|
|
22
|
+
},
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
describe(
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
describe("Middleware: storeCredentials", () => {
|
|
26
|
+
let storeSuccess: any,
|
|
27
|
+
storeError: any,
|
|
28
|
+
saveErrorFake: any,
|
|
29
|
+
saveSuccessFake: any;
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
storeSuccess = {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
save: async (id: any, creds: any) => {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
storeError = {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
+
save: (id: any, creds: any): Promise<void> => {
|
|
41
|
+
throw new Error("some error");
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
saveSuccessFake = sinon.replace(
|
|
45
|
+
storeSuccess,
|
|
46
|
+
"save",
|
|
47
|
+
sinon.fake(storeSuccess.save),
|
|
48
|
+
);
|
|
49
|
+
saveErrorFake = sinon.replace(
|
|
50
|
+
storeError,
|
|
51
|
+
"save",
|
|
52
|
+
sinon.fake(storeError.save),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
sinon.reset();
|
|
58
|
+
});
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
60
|
+
it("returns a middleware handler", () => {
|
|
61
|
+
const sc = storeCredentials(storeSuccess);
|
|
62
|
+
expect(typeof sc).toEqual("function");
|
|
63
|
+
expect(saveSuccessFake.callCount).toEqual(0);
|
|
64
|
+
});
|
|
55
65
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
it("successfully stores credentials", (done) => {
|
|
67
|
+
const sc = storeCredentials(storeSuccess);
|
|
68
|
+
sc(creds as CredentialsObject, (err: any) => {
|
|
69
|
+
expect(saveSuccessFake.callCount).toEqual(1);
|
|
70
|
+
expect(saveSuccessFake.firstArg).toEqual(creds.actor.id);
|
|
71
|
+
expect(err).toEqual(creds);
|
|
72
|
+
done();
|
|
73
|
+
});
|
|
62
74
|
});
|
|
63
|
-
});
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
it("handle error while storing credentials", (done) => {
|
|
77
|
+
const sc = storeCredentials(storeError);
|
|
78
|
+
sc(creds as CredentialsObject, (err: any) => {
|
|
79
|
+
expect(saveErrorFake.callCount).toEqual(1);
|
|
80
|
+
expect(saveErrorFake.firstArg).toEqual(creds.actor.id);
|
|
81
|
+
expect(err.toString()).toEqual("Error: some error");
|
|
82
|
+
done();
|
|
83
|
+
});
|
|
71
84
|
});
|
|
72
|
-
|
|
73
|
-
});
|
|
85
|
+
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { CredentialsStoreInterface } from "@sockethub/data-layer";
|
|
2
|
+
import type { CredentialsObject } from "@sockethub/schemas";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
4
|
+
import type { MiddlewareChainInterface } from "../middleware.js";
|
|
5
|
+
|
|
6
|
+
export default function storeCredentials(store: CredentialsStoreInterface) {
|
|
7
|
+
return (creds: CredentialsObject, done: MiddlewareChainInterface) => {
|
|
8
|
+
try {
|
|
9
|
+
store.save(creds.actor.id, creds).then(() => {
|
|
10
|
+
done(creds);
|
|
11
|
+
});
|
|
12
|
+
} catch (err) {
|
|
13
|
+
done(err);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|