@hocuspocus/extension-webhook 2.1.0 → 2.2.0
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/dist/packages/server/src/ClientConnection.d.ts +56 -0
- package/dist/packages/server/src/DirectConnection.d.ts +2 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +5 -13
- package/dist/packages/server/src/types.d.ts +4 -0
- package/dist/packages/server/src/util/getParameters.d.ts +8 -0
- package/package.json +4 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage } from 'http';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
import { Debugger } from './Debugger.js';
|
|
5
|
+
import Document from './Document.js';
|
|
6
|
+
import { Hocuspocus } from './Hocuspocus.js';
|
|
7
|
+
import { onDisconnectPayload } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* The `ClientConnection` class is responsible for handling an incoming WebSocket
|
|
10
|
+
*
|
|
11
|
+
* TODO-refactor:
|
|
12
|
+
* - use event handlers instead of calling hooks directly, hooks should probably be called from Hocuspocus.ts
|
|
13
|
+
*/
|
|
14
|
+
export declare class ClientConnection {
|
|
15
|
+
private readonly websocket;
|
|
16
|
+
private readonly request;
|
|
17
|
+
private readonly documentProvider;
|
|
18
|
+
private readonly hooks;
|
|
19
|
+
private readonly debuggerTool;
|
|
20
|
+
private readonly opts;
|
|
21
|
+
private readonly defaultContext;
|
|
22
|
+
private readonly documentConnections;
|
|
23
|
+
private readonly incomingMessageQueue;
|
|
24
|
+
private readonly documentConnectionsEstablished;
|
|
25
|
+
private readonly hookPayloads;
|
|
26
|
+
private readonly callbacks;
|
|
27
|
+
private readonly closeIdleConnectionTimeout;
|
|
28
|
+
private readonly socketId;
|
|
29
|
+
/**
|
|
30
|
+
* The `ClientConnection` class receives incoming WebSocket connections,
|
|
31
|
+
* runs all hooks:
|
|
32
|
+
*
|
|
33
|
+
* - onConnect for all connections
|
|
34
|
+
* - onAuthenticate only if required
|
|
35
|
+
*
|
|
36
|
+
* … and if nothings fails it’ll fully establish the connection and
|
|
37
|
+
* load the Document then.
|
|
38
|
+
*/
|
|
39
|
+
constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
|
|
40
|
+
createDocument: Hocuspocus['createDocument'];
|
|
41
|
+
}, hooks: Hocuspocus['hooks'], debuggerTool: Debugger, opts: {
|
|
42
|
+
requiresAuthentication: boolean;
|
|
43
|
+
timeout: number;
|
|
44
|
+
}, defaultContext?: any);
|
|
45
|
+
/**
|
|
46
|
+
* Set a callback that will be triggered when the connection is closed
|
|
47
|
+
*/
|
|
48
|
+
onClose(callback: (document: Document, payload: onDisconnectPayload) => void): ClientConnection;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new connection by the given request and document
|
|
51
|
+
*/
|
|
52
|
+
private createConnection;
|
|
53
|
+
private setUpNewConnection;
|
|
54
|
+
private handleQueueingMessage;
|
|
55
|
+
private messageHandler;
|
|
56
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Document from './Document.js';
|
|
2
2
|
import type { Hocuspocus } from './Hocuspocus.js';
|
|
3
|
-
|
|
3
|
+
import type { DirectConnection as DirectConnectionInterface } from './types';
|
|
4
|
+
export declare class DirectConnection implements DirectConnectionInterface {
|
|
4
5
|
document: Document | null;
|
|
5
6
|
instance: Hocuspocus;
|
|
6
7
|
context: any;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
3
|
+
import { Server as HTTPServer, IncomingMessage } from 'http';
|
|
4
4
|
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
5
|
-
import { Configuration, HookName, HookPayload, onListenPayload, onStoreDocumentPayload } from './types.js';
|
|
6
|
-
import Document from './Document.js';
|
|
7
5
|
import { Debugger } from './Debugger.js';
|
|
8
6
|
import { DirectConnection } from './DirectConnection.js';
|
|
7
|
+
import Document from './Document.js';
|
|
8
|
+
import { Configuration, ConnectionConfiguration, HookName, HookPayload, onListenPayload, onStoreDocumentPayload } from './types.js';
|
|
9
9
|
export declare const defaultConfiguration: {
|
|
10
10
|
name: null;
|
|
11
11
|
port: number;
|
|
@@ -69,7 +69,7 @@ export declare class Hocuspocus {
|
|
|
69
69
|
* … and if nothings fails it’ll fully establish the connection and
|
|
70
70
|
* load the Document then.
|
|
71
71
|
*/
|
|
72
|
-
handleConnection(incoming: WebSocket, request: IncomingMessage,
|
|
72
|
+
handleConnection(incoming: WebSocket, request: IncomingMessage, defaultContext?: any): void;
|
|
73
73
|
/**
|
|
74
74
|
* Handle update of the given document
|
|
75
75
|
*/
|
|
@@ -85,21 +85,13 @@ export declare class Hocuspocus {
|
|
|
85
85
|
/**
|
|
86
86
|
* Create a new document by the given request
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Create a new connection by the given request and document
|
|
91
|
-
*/
|
|
92
|
-
private createConnection;
|
|
88
|
+
createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
93
89
|
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): void;
|
|
94
90
|
/**
|
|
95
91
|
* Run the given hook on all configured extensions.
|
|
96
92
|
* Runs the given callback after each hook.
|
|
97
93
|
*/
|
|
98
94
|
hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
|
|
99
|
-
/**
|
|
100
|
-
* Get parameters by the given request
|
|
101
|
-
*/
|
|
102
|
-
private static getParameters;
|
|
103
95
|
enableDebugging(): void;
|
|
104
96
|
enableMessageLogging(): void;
|
|
105
97
|
disableLogging(): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
4
|
+
import { URLSearchParams } from 'url';
|
|
5
|
+
/**
|
|
6
|
+
* Get parameters by the given request
|
|
7
|
+
*/
|
|
8
|
+
export declare function getParameters(request?: Pick<IncomingMessage, 'url'>): URLSearchParams;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-webhook",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "hocuspocus webhook extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@hocuspocus/common": "^2.
|
|
34
|
-
"@hocuspocus/server": "^2.
|
|
35
|
-
"@hocuspocus/transformer": "^2.
|
|
33
|
+
"@hocuspocus/common": "^2.2.0",
|
|
34
|
+
"@hocuspocus/server": "^2.2.0",
|
|
35
|
+
"@hocuspocus/transformer": "^2.2.0",
|
|
36
36
|
"axios": "^1.2.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|