@sockethub/server 5.0.0-alpha.10
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 +130 -0
- package/bin/sockethub +4 -0
- package/dist/defaults.json +36 -0
- package/dist/index.js +166465 -0
- package/dist/index.js.map +1877 -0
- package/dist/platform.js +103625 -0
- package/dist/platform.js.map +1435 -0
- package/package.json +100 -0
- package/res/socket.io.js +4908 -0
- package/res/sockethub-client.js +631 -0
- package/res/sockethub-client.min.js +19 -0
- package/src/bootstrap/init.d.ts +21 -0
- package/src/bootstrap/init.test.ts +211 -0
- package/src/bootstrap/init.ts +160 -0
- package/src/bootstrap/load-platforms.ts +151 -0
- package/src/config.test.ts +33 -0
- package/src/config.ts +98 -0
- package/src/defaults.json +36 -0
- package/src/index.ts +68 -0
- package/src/janitor.test.ts +211 -0
- package/src/janitor.ts +157 -0
- package/src/listener.ts +173 -0
- package/src/middleware/create-activity-object.test.ts +30 -0
- package/src/middleware/create-activity-object.ts +22 -0
- package/src/middleware/expand-activity-stream.test.data.ts +351 -0
- package/src/middleware/expand-activity-stream.test.ts +77 -0
- package/src/middleware/expand-activity-stream.ts +37 -0
- package/src/middleware/store-credentials.test.ts +85 -0
- package/src/middleware/store-credentials.ts +16 -0
- package/src/middleware/validate.test.data.ts +259 -0
- package/src/middleware/validate.test.ts +44 -0
- package/src/middleware/validate.ts +73 -0
- package/src/middleware.test.ts +184 -0
- package/src/middleware.ts +71 -0
- package/src/platform-instance.test.ts +531 -0
- package/src/platform-instance.ts +360 -0
- package/src/platform.test.ts +375 -0
- package/src/platform.ts +358 -0
- package/src/process-manager.ts +88 -0
- package/src/routes.test.ts +54 -0
- package/src/routes.ts +61 -0
- package/src/sentry.test.ts +106 -0
- package/src/sentry.ts +19 -0
- package/src/sockethub.ts +198 -0
- package/src/util.ts +5 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{
|
|
3
|
+
name: "not an object",
|
|
4
|
+
valid: false,
|
|
5
|
+
type: "message",
|
|
6
|
+
input: "hello world",
|
|
7
|
+
error: "Error: message received is not an object.",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: "basic invalid type",
|
|
11
|
+
valid: true,
|
|
12
|
+
type: "credentials",
|
|
13
|
+
input: {
|
|
14
|
+
id: "foo",
|
|
15
|
+
type: "send",
|
|
16
|
+
context: "dummy",
|
|
17
|
+
actor: {
|
|
18
|
+
id: "dood@irc.freenode.net",
|
|
19
|
+
type: "person",
|
|
20
|
+
name: "dood",
|
|
21
|
+
},
|
|
22
|
+
target: {
|
|
23
|
+
id: "irc.freenode.net/service",
|
|
24
|
+
type: "person",
|
|
25
|
+
name: "service",
|
|
26
|
+
},
|
|
27
|
+
object: {
|
|
28
|
+
type: "credentials",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
output: "same",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "basic valid type",
|
|
35
|
+
valid: true,
|
|
36
|
+
type: "credentials",
|
|
37
|
+
input: {
|
|
38
|
+
id: "foo",
|
|
39
|
+
type: "credentials",
|
|
40
|
+
context: "dummy",
|
|
41
|
+
actor: {
|
|
42
|
+
id: "dood@irc.freenode.net",
|
|
43
|
+
type: "person",
|
|
44
|
+
name: "dood",
|
|
45
|
+
},
|
|
46
|
+
target: {
|
|
47
|
+
id: "irc.freenode.net/service",
|
|
48
|
+
type: "person",
|
|
49
|
+
name: "service",
|
|
50
|
+
},
|
|
51
|
+
object: {
|
|
52
|
+
type: "credentials",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
output: "same",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "new format",
|
|
59
|
+
valid: true,
|
|
60
|
+
type: "credentials",
|
|
61
|
+
input: {
|
|
62
|
+
type: "credentials",
|
|
63
|
+
context: "irc",
|
|
64
|
+
actor: {
|
|
65
|
+
id: "sh-9K3Vk@irc.freenode.net",
|
|
66
|
+
type: "person",
|
|
67
|
+
name: "sh-9K3Vk",
|
|
68
|
+
image: {
|
|
69
|
+
height: 250,
|
|
70
|
+
mediaType: "image/jpeg",
|
|
71
|
+
url: "https://example.org/image.jpg",
|
|
72
|
+
width: 250,
|
|
73
|
+
},
|
|
74
|
+
url: "https://sockethub.org",
|
|
75
|
+
},
|
|
76
|
+
object: {
|
|
77
|
+
type: "credentials",
|
|
78
|
+
nick: "sh-9K3Vk",
|
|
79
|
+
port: 6667,
|
|
80
|
+
secure: false,
|
|
81
|
+
server: "irc.freenode.net",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
output: "same",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "no type specified",
|
|
88
|
+
valid: false,
|
|
89
|
+
type: "credentials",
|
|
90
|
+
input: {
|
|
91
|
+
actor: "hyper_rau@localhost",
|
|
92
|
+
context: "xmpp",
|
|
93
|
+
object: {
|
|
94
|
+
username: "hyper_rau",
|
|
95
|
+
password: "123",
|
|
96
|
+
server: "localhost",
|
|
97
|
+
port: 5222,
|
|
98
|
+
resource: "laptop",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
error: "Error: activity stream must contain a type property.",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "expand unknown actor",
|
|
105
|
+
type: "message",
|
|
106
|
+
valid: "true",
|
|
107
|
+
input: {
|
|
108
|
+
context: "foo",
|
|
109
|
+
type: "bar",
|
|
110
|
+
actor: "foo@bar",
|
|
111
|
+
object: {
|
|
112
|
+
content: "bar",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
output: {
|
|
116
|
+
context: "foo",
|
|
117
|
+
type: "bar",
|
|
118
|
+
actor: {
|
|
119
|
+
id: "foo@bar",
|
|
120
|
+
},
|
|
121
|
+
object: {
|
|
122
|
+
content: "bar",
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "expand unknown actor 2",
|
|
128
|
+
type: "message",
|
|
129
|
+
valid: "true",
|
|
130
|
+
input: {
|
|
131
|
+
context: "foo",
|
|
132
|
+
type: "bar",
|
|
133
|
+
actor: "someone@example.org/resource",
|
|
134
|
+
object: {
|
|
135
|
+
content: "bar",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
output: {
|
|
139
|
+
context: "foo",
|
|
140
|
+
type: "bar",
|
|
141
|
+
actor: {
|
|
142
|
+
id: "someone@example.org/resource",
|
|
143
|
+
},
|
|
144
|
+
object: {
|
|
145
|
+
content: "bar",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "expand unknown actor 2",
|
|
151
|
+
type: "message",
|
|
152
|
+
valid: "true",
|
|
153
|
+
input: {
|
|
154
|
+
context: "foo",
|
|
155
|
+
type: "bar",
|
|
156
|
+
actor: "xmpp:someone@example.org/resource",
|
|
157
|
+
object: {
|
|
158
|
+
content: "bar",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
output: {
|
|
162
|
+
context: "foo",
|
|
163
|
+
type: "bar",
|
|
164
|
+
actor: {
|
|
165
|
+
id: "xmpp:someone@example.org/resource",
|
|
166
|
+
},
|
|
167
|
+
object: {
|
|
168
|
+
content: "bar",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "person",
|
|
174
|
+
type: "message",
|
|
175
|
+
valid: true,
|
|
176
|
+
input: {
|
|
177
|
+
context: "some context",
|
|
178
|
+
type: "some type",
|
|
179
|
+
actor: "blah",
|
|
180
|
+
object: {},
|
|
181
|
+
},
|
|
182
|
+
output: {
|
|
183
|
+
context: "some context",
|
|
184
|
+
type: "some type",
|
|
185
|
+
actor: {
|
|
186
|
+
id: "blah",
|
|
187
|
+
type: "person",
|
|
188
|
+
name: "dood",
|
|
189
|
+
},
|
|
190
|
+
object: {},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "person with extras",
|
|
195
|
+
valid: true,
|
|
196
|
+
type: "message",
|
|
197
|
+
input: {
|
|
198
|
+
context: "some context",
|
|
199
|
+
type: "some type",
|
|
200
|
+
actor: "blah2",
|
|
201
|
+
object: {},
|
|
202
|
+
},
|
|
203
|
+
output: {
|
|
204
|
+
context: "some context",
|
|
205
|
+
type: "some type",
|
|
206
|
+
actor: {
|
|
207
|
+
id: "blah2",
|
|
208
|
+
type: "person",
|
|
209
|
+
name: "bob",
|
|
210
|
+
hello: "there",
|
|
211
|
+
i: ["am", "extras"],
|
|
212
|
+
},
|
|
213
|
+
object: {},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: "bad parent object",
|
|
218
|
+
valid: false,
|
|
219
|
+
type: "message",
|
|
220
|
+
input: {
|
|
221
|
+
string: "this is a string",
|
|
222
|
+
array: [
|
|
223
|
+
"this",
|
|
224
|
+
"is",
|
|
225
|
+
{
|
|
226
|
+
an: "array",
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
as: {
|
|
230
|
+
id: "blah",
|
|
231
|
+
type: "send",
|
|
232
|
+
context: "hello",
|
|
233
|
+
actor: {
|
|
234
|
+
name: "dood",
|
|
235
|
+
},
|
|
236
|
+
target: {
|
|
237
|
+
type: "person",
|
|
238
|
+
name: "bob",
|
|
239
|
+
},
|
|
240
|
+
object: {
|
|
241
|
+
type: "credentials",
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
noId: {
|
|
245
|
+
name: "dood",
|
|
246
|
+
},
|
|
247
|
+
noId2: {
|
|
248
|
+
type: "person",
|
|
249
|
+
name: "bob",
|
|
250
|
+
},
|
|
251
|
+
noDisplayName: {
|
|
252
|
+
id: "larg",
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
error: "Error: activity stream must contain a context property",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "no actor specified",
|
|
259
|
+
valid: false,
|
|
260
|
+
type: "message",
|
|
261
|
+
input: {
|
|
262
|
+
type: "some type",
|
|
263
|
+
context: "xmpp",
|
|
264
|
+
object: {
|
|
265
|
+
type: "error",
|
|
266
|
+
content: "error message",
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
error: "Error: activity stream must contain an actor property.",
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "expand actor and target of unknowns",
|
|
273
|
+
valid: true,
|
|
274
|
+
type: "message",
|
|
275
|
+
input: {
|
|
276
|
+
actor: "irc://uuu@localhost",
|
|
277
|
+
type: "join",
|
|
278
|
+
context: "irc",
|
|
279
|
+
target: "irc://irc.dooder.net/a-room",
|
|
280
|
+
},
|
|
281
|
+
output: {
|
|
282
|
+
actor: {
|
|
283
|
+
id: "irc://uuu@localhost",
|
|
284
|
+
},
|
|
285
|
+
type: "join",
|
|
286
|
+
context: "irc",
|
|
287
|
+
target: {
|
|
288
|
+
id: "irc://irc.dooder.net/a-room",
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "expand actor and target of unknowns",
|
|
294
|
+
valid: true,
|
|
295
|
+
type: "message",
|
|
296
|
+
input: {
|
|
297
|
+
actor: "hyper_rau@localhost",
|
|
298
|
+
type: "join",
|
|
299
|
+
context: "xmpp",
|
|
300
|
+
object: {},
|
|
301
|
+
target: "dooder",
|
|
302
|
+
},
|
|
303
|
+
output: {
|
|
304
|
+
actor: {
|
|
305
|
+
id: "hyper_rau@localhost",
|
|
306
|
+
},
|
|
307
|
+
type: "join",
|
|
308
|
+
context: "xmpp",
|
|
309
|
+
object: {},
|
|
310
|
+
target: {
|
|
311
|
+
id: "dooder",
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: "expand known person",
|
|
317
|
+
valid: true,
|
|
318
|
+
type: "message",
|
|
319
|
+
input: {
|
|
320
|
+
actor: "sh-9K3Vk@irc.freenode.net",
|
|
321
|
+
target: "blah3",
|
|
322
|
+
type: "send",
|
|
323
|
+
context: "irc",
|
|
324
|
+
object: {},
|
|
325
|
+
},
|
|
326
|
+
output: {
|
|
327
|
+
actor: {
|
|
328
|
+
id: "sh-9K3Vk@irc.freenode.net",
|
|
329
|
+
type: "person",
|
|
330
|
+
name: "sh-9K3Vk",
|
|
331
|
+
image: {
|
|
332
|
+
height: 250,
|
|
333
|
+
mediaType: "image/jpeg",
|
|
334
|
+
url: "https://example.org/image.jpg",
|
|
335
|
+
width: 250,
|
|
336
|
+
},
|
|
337
|
+
url: "https://sockethub.org",
|
|
338
|
+
},
|
|
339
|
+
target: {
|
|
340
|
+
id: "blah3",
|
|
341
|
+
type: "person",
|
|
342
|
+
name: "bob",
|
|
343
|
+
hello: "there",
|
|
344
|
+
i: ["am", "extras"],
|
|
345
|
+
},
|
|
346
|
+
type: "send",
|
|
347
|
+
context: "irc",
|
|
348
|
+
object: {},
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import expandActivityStream from "./expand-activity-stream.js";
|
|
4
|
+
|
|
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();
|
|
10
|
+
|
|
11
|
+
// register known activity objects
|
|
12
|
+
[
|
|
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"],
|
|
43
|
+
},
|
|
44
|
+
].forEach((obj) => {
|
|
45
|
+
activity.Object.create(obj);
|
|
46
|
+
});
|
|
47
|
+
|
|
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
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ASFactory, type ASFactoryOptions } from "@sockethub/activity-streams";
|
|
2
|
+
import type { ActivityStream } from "@sockethub/schemas";
|
|
3
|
+
|
|
4
|
+
import config from "../config.js";
|
|
5
|
+
import type { MiddlewareChainInterface } from "../middleware.js";
|
|
6
|
+
|
|
7
|
+
const asConfig = config.get(
|
|
8
|
+
"packageConfig:@sockethub/activity-streams",
|
|
9
|
+
) as ASFactoryOptions;
|
|
10
|
+
asConfig.warnOnUnknownObjectProperties = false;
|
|
11
|
+
asConfig.failOnUnknownObjectProperties = false;
|
|
12
|
+
|
|
13
|
+
const activity = ASFactory(asConfig);
|
|
14
|
+
|
|
15
|
+
function ensureObject(msg: unknown) {
|
|
16
|
+
return !(typeof msg !== "object" || Array.isArray(msg));
|
|
17
|
+
}
|
|
18
|
+
|
|
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."));
|
|
29
|
+
} else {
|
|
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
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import * as sinon from "sinon";
|
|
3
|
+
|
|
4
|
+
import type { CredentialsObject } from "@sockethub/schemas";
|
|
5
|
+
import storeCredentials from "./store-credentials.js";
|
|
6
|
+
|
|
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
|
+
};
|
|
24
|
+
|
|
25
|
+
describe("Middleware: storeCredentials", () => {
|
|
26
|
+
let storeSuccess: any,
|
|
27
|
+
storeError: any,
|
|
28
|
+
saveErrorFake: any,
|
|
29
|
+
saveSuccessFake: any;
|
|
30
|
+
|
|
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
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
sinon.reset();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns a middleware handler", () => {
|
|
61
|
+
const sc = storeCredentials(storeSuccess);
|
|
62
|
+
expect(typeof sc).toEqual("function");
|
|
63
|
+
expect(saveSuccessFake.callCount).toEqual(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
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
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
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
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CredentialsStoreInterface } from "@sockethub/data-layer";
|
|
2
|
+
import type { CredentialsObject } from "@sockethub/schemas";
|
|
3
|
+
|
|
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
|
+
}
|