@sockethub/server 5.0.0-alpha.13 → 5.0.0-alpha.15
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 +26 -0
- package/dist/cors.d.ts +30 -0
- package/dist/http/actions.d.ts +29 -0
- package/dist/http/session-registry.d.ts +3 -0
- package/dist/index.js +31558 -16897
- package/dist/index.js.map +102 -121
- package/dist/listener.d.ts +3 -0
- package/dist/message-handlers.d.ts +33 -0
- package/dist/middleware/validate.d.ts +2 -2
- package/dist/platform-instance.d.ts +21 -1
- package/dist/platform.js +4343 -4570
- package/dist/platform.js.map +10 -10
- package/dist/process-manager.d.ts +10 -1
- package/package.json +16 -17
- package/res/sockethub-client.js +307 -2
- package/res/sockethub-client.min.js +11 -11
package/dist/listener.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as HTTP from "node:http";
|
|
2
|
+
import { type Express } from "express";
|
|
2
3
|
import { Server, type Socket } from "socket.io";
|
|
3
4
|
/**
|
|
4
5
|
* Handles the initialization and access of Sockethub resources.
|
|
@@ -8,6 +9,7 @@ import { Server, type Socket } from "socket.io";
|
|
|
8
9
|
* - Socket.io (bidirectional websocket communication)
|
|
9
10
|
*/
|
|
10
11
|
declare class Listener {
|
|
12
|
+
app?: Express;
|
|
11
13
|
io: Server;
|
|
12
14
|
http: HTTP.Server;
|
|
13
15
|
/**
|
|
@@ -31,6 +33,7 @@ declare class Listener {
|
|
|
31
33
|
private static corsOrigin;
|
|
32
34
|
private startHttp;
|
|
33
35
|
private static initExpress;
|
|
36
|
+
getApp(): Express;
|
|
34
37
|
}
|
|
35
38
|
declare const listener: Listener;
|
|
36
39
|
/**
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared handler pipelines for socket and HTTP request paths.
|
|
3
|
+
*
|
|
4
|
+
* Keeps validation, credentials storage, and queueing logic identical so
|
|
5
|
+
* both transports behave the same.
|
|
6
|
+
*/
|
|
7
|
+
import type { CredentialsStoreInterface } from "@sockethub/data-layer";
|
|
8
|
+
import type { ActivityStream, InternalActivityStream } from "@sockethub/schemas";
|
|
9
|
+
import type PlatformInstance from "./platform-instance.js";
|
|
10
|
+
import type ProcessManager from "./process-manager.js";
|
|
11
|
+
export type MessageHandler<T> = (data: T, callback: (data?: T | Error) => void) => void;
|
|
12
|
+
export interface MessageHandlers {
|
|
13
|
+
credentials: MessageHandler<ActivityStream>;
|
|
14
|
+
message: MessageHandler<InternalActivityStream>;
|
|
15
|
+
}
|
|
16
|
+
export interface MessageHandlersOptions {
|
|
17
|
+
processManager: ProcessManager;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
sessionSecret: string;
|
|
20
|
+
credentialsStore: CredentialsStoreInterface;
|
|
21
|
+
clientIp?: string;
|
|
22
|
+
isSessionActive?: (sessionId: string) => boolean;
|
|
23
|
+
platformSessionId?: string;
|
|
24
|
+
onPlatformInstance?: (platformInstance: PlatformInstance) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalize middleware errors into payload-safe error responses.
|
|
28
|
+
* Removes internal-only properties that must never be sent to clients.
|
|
29
|
+
*/
|
|
30
|
+
export declare function attachError<T extends ActivityStream>(err: unknown, msg?: T): Error | (T & {
|
|
31
|
+
sessionSecret?: string;
|
|
32
|
+
});
|
|
33
|
+
export declare function createMessageHandlers(options: MessageHandlersOptions): MessageHandlers;
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type ActivityStream } from "@sockethub/schemas";
|
|
5
5
|
import { type IInitObject } from "../bootstrap/init.js";
|
|
6
|
-
import type {
|
|
7
|
-
export default function validate<T extends ActivityStream>(type: "credentials" | "message", sockethubId: string, passedInitObj?: IInitObject):
|
|
6
|
+
import type { MiddlewareHandler } from "../middleware.js";
|
|
7
|
+
export default function validate<T extends ActivityStream>(type: "credentials" | "message", sockethubId: string, passedInitObj?: IInitObject): MiddlewareHandler<T>;
|
|
@@ -12,6 +12,7 @@ export interface PlatformInstanceParams {
|
|
|
12
12
|
type EnvFormat = {
|
|
13
13
|
LOG_LEVEL?: string;
|
|
14
14
|
REDIS_URL: string;
|
|
15
|
+
SOCKETHUB_CREDENTIALS_TTL_MS?: string;
|
|
15
16
|
SOCKETHUB_PLATFORM_CHILD?: string;
|
|
16
17
|
SOCKETHUB_PLATFORM_CONFIG?: string;
|
|
17
18
|
SOCKETHUB_PLATFORM_HEARTBEAT_INTERVAL_MS?: string;
|
|
@@ -45,6 +46,8 @@ export default class PlatformInstance {
|
|
|
45
46
|
private heartbeatMonitor?;
|
|
46
47
|
private heartbeatListener?;
|
|
47
48
|
private heartbeatFailureHandled;
|
|
49
|
+
private replaced;
|
|
50
|
+
private shutdownResult?;
|
|
48
51
|
private readonly actor?;
|
|
49
52
|
constructor(params: PlatformInstanceParams);
|
|
50
53
|
createQueue(): void;
|
|
@@ -55,9 +58,26 @@ export default class PlatformInstance {
|
|
|
55
58
|
*/
|
|
56
59
|
isInitialized(): boolean;
|
|
57
60
|
/**
|
|
58
|
-
*
|
|
61
|
+
* Marks this instance as superseded by a replacement that shares its
|
|
62
|
+
* identifier — and therefore its Redis queue name and platformInstances
|
|
63
|
+
* slot. shutdown() on a replaced instance must leave those shared
|
|
64
|
+
* resources alone: pausing/obliterating the queue would destroy the
|
|
65
|
+
* replacement's pending jobs, and deleting the map entry would evict
|
|
66
|
+
* the replacement, causing duplicate child processes (#1166).
|
|
67
|
+
*/
|
|
68
|
+
markReplaced(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Destroys all references to this platform instance, internal listeners and controlled processes.
|
|
71
|
+
*
|
|
72
|
+
* Single-flight: every caller shares one teardown run. A crash-close
|
|
73
|
+
* teardown pauses and obliterates the Redis queue asynchronously, so a
|
|
74
|
+
* caller about to create a replacement (ProcessManager.ensureProcess)
|
|
75
|
+
* must be able to await the teardown *already in flight* — a second,
|
|
76
|
+
* independent run would resolve while the first is still obliterating
|
|
77
|
+
* the queue name the replacement is about to reuse.
|
|
59
78
|
*/
|
|
60
79
|
shutdown(): Promise<void>;
|
|
80
|
+
private teardown;
|
|
61
81
|
/**
|
|
62
82
|
* When jobs are completed or failed, we prepare the results and send them to the client socket
|
|
63
83
|
*/
|