@hocuspocus/provider 3.4.3 → 3.4.4
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/hocuspocus-provider.cjs +11 -9
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +11 -9
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/auth.d.ts +2 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +3 -3
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +5 -0
- package/dist/packages/provider/src/types.d.ts +2 -1
- package/dist/packages/server/src/Connection.d.ts +7 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +16 -9
- package/src/HocuspocusProviderWebsocket.ts +16 -4
- package/src/MessageReceiver.ts +2 -2
- package/src/types.ts +3 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as encoding from "lib0/encoding";
|
|
2
2
|
import * as decoding from "lib0/decoding";
|
|
3
|
+
import type { AuthorizedScope } from "../../provider/src";
|
|
3
4
|
export declare enum AuthMessageType {
|
|
4
5
|
Token = 0,
|
|
5
6
|
PermissionDenied = 1,
|
|
@@ -7,6 +8,6 @@ export declare enum AuthMessageType {
|
|
|
7
8
|
}
|
|
8
9
|
export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
|
|
9
10
|
export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
|
|
10
|
-
export declare const writeAuthenticated: (encoder: encoding.Encoder, scope:
|
|
11
|
+
export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: AuthorizedScope) => void;
|
|
11
12
|
export declare const writeTokenSyncRequest: (encoder: encoding.Encoder) => void;
|
|
12
13
|
export declare const readAuthMessage: (decoder: decoding.Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
|
|
@@ -4,8 +4,8 @@ import * as Y from "yjs";
|
|
|
4
4
|
import EventEmitter from "./EventEmitter.ts";
|
|
5
5
|
import type { CompleteHocuspocusProviderWebsocketConfiguration } from "./HocuspocusProviderWebsocket.ts";
|
|
6
6
|
import { HocuspocusProviderWebsocket } from "./HocuspocusProviderWebsocket.ts";
|
|
7
|
-
import type { ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters } from "./types.ts";
|
|
8
|
-
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>);
|
|
7
|
+
import type { AuthorizedScope, ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters } from "./types.ts";
|
|
8
|
+
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & ((Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "preserveTrailingSlash">>) | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>);
|
|
9
9
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
10
|
/**
|
|
11
11
|
* The identifier/name of your document
|
|
@@ -60,7 +60,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
60
60
|
isSynced: boolean;
|
|
61
61
|
unsyncedChanges: number;
|
|
62
62
|
isAuthenticated: boolean;
|
|
63
|
-
authorizedScope:
|
|
63
|
+
authorizedScope: AuthorizedScope | undefined;
|
|
64
64
|
manageSocket: boolean;
|
|
65
65
|
private _isAttached;
|
|
66
66
|
intervals: any;
|
|
@@ -16,6 +16,11 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
16
16
|
* URL of your @hocuspocus/server instance
|
|
17
17
|
*/
|
|
18
18
|
url: string;
|
|
19
|
+
/**
|
|
20
|
+
* By default, trailing slashes are removed from the URL. Set this to true
|
|
21
|
+
* to preserve trailing slashes if your server configuration requires them.
|
|
22
|
+
*/
|
|
23
|
+
preserveTrailingSlash: boolean;
|
|
19
24
|
/**
|
|
20
25
|
* An optional WebSocket polyfill, for example for Node.js
|
|
21
26
|
*/
|
|
@@ -25,6 +25,7 @@ export declare enum WebSocketStatus {
|
|
|
25
25
|
Connected = "connected",
|
|
26
26
|
Disconnected = "disconnected"
|
|
27
27
|
}
|
|
28
|
+
export type AuthorizedScope = "read-write" | "readonly";
|
|
28
29
|
export interface OutgoingMessageInterface {
|
|
29
30
|
encoder: Encoder;
|
|
30
31
|
type?: MessageType;
|
|
@@ -50,7 +51,7 @@ export type onAuthenticationFailedParameters = {
|
|
|
50
51
|
reason: string;
|
|
51
52
|
};
|
|
52
53
|
export type onAuthenticatedParameters = {
|
|
53
|
-
scope:
|
|
54
|
+
scope: AuthorizedScope;
|
|
54
55
|
};
|
|
55
56
|
export type onOpenParameters = {
|
|
56
57
|
event: Event;
|
|
@@ -2,7 +2,7 @@ import type { IncomingMessage as HTTPIncomingMessage } from "node:http";
|
|
|
2
2
|
import { type CloseEvent } from "@hocuspocus/common";
|
|
3
3
|
import type WebSocket from "ws";
|
|
4
4
|
import type Document from "./Document.ts";
|
|
5
|
-
import type { beforeSyncPayload, onStatelessPayload
|
|
5
|
+
import type { beforeSyncPayload, onStatelessPayload } from "./types.ts";
|
|
6
6
|
export declare class Connection {
|
|
7
7
|
webSocket: WebSocket;
|
|
8
8
|
context: any;
|
|
@@ -13,7 +13,9 @@ export declare class Connection {
|
|
|
13
13
|
beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>;
|
|
14
14
|
beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>;
|
|
15
15
|
statelessCallback: (payload: onStatelessPayload) => Promise<void>;
|
|
16
|
-
onTokenSyncCallback: (payload:
|
|
16
|
+
onTokenSyncCallback: (payload: {
|
|
17
|
+
token: string;
|
|
18
|
+
}) => Promise<void>;
|
|
17
19
|
};
|
|
18
20
|
socketId: string;
|
|
19
21
|
readOnly: boolean;
|
|
@@ -40,7 +42,9 @@ export declare class Connection {
|
|
|
40
42
|
/**
|
|
41
43
|
* Set a callback that will be triggered when on token sync message is received
|
|
42
44
|
*/
|
|
43
|
-
onTokenSyncCallback(callback: (payload:
|
|
45
|
+
onTokenSyncCallback(callback: (payload: {
|
|
46
|
+
token: string;
|
|
47
|
+
}) => Promise<void>): Connection;
|
|
44
48
|
/**
|
|
45
49
|
* Send the given message
|
|
46
50
|
*/
|
|
@@ -6,6 +6,6 @@ export declare class MessageReceiver {
|
|
|
6
6
|
defaultTransactionOrigin?: string;
|
|
7
7
|
constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
|
|
8
8
|
apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
|
|
9
|
-
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 |
|
|
9
|
+
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
|
|
10
10
|
applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"description": "hocuspocus provider",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@hocuspocus/common": "^3.4.
|
|
32
|
+
"@hocuspocus/common": "^3.4.4",
|
|
33
33
|
"@lifeomic/attempt": "^3.0.2",
|
|
34
34
|
"lib0": "^0.2.87",
|
|
35
35
|
"ws": "^8.17.1"
|
|
@@ -14,6 +14,7 @@ import { StatelessMessage } from "./OutgoingMessages/StatelessMessage.ts";
|
|
|
14
14
|
import { SyncStepOneMessage } from "./OutgoingMessages/SyncStepOneMessage.ts";
|
|
15
15
|
import { UpdateMessage } from "./OutgoingMessages/UpdateMessage.ts";
|
|
16
16
|
import type {
|
|
17
|
+
AuthorizedScope,
|
|
17
18
|
ConstructableOutgoingMessage,
|
|
18
19
|
onAuthenticatedParameters,
|
|
19
20
|
onAuthenticationFailedParameters,
|
|
@@ -35,7 +36,13 @@ export type HocuspocusProviderConfiguration = Required<
|
|
|
35
36
|
> &
|
|
36
37
|
Partial<CompleteHocuspocusProviderConfiguration> &
|
|
37
38
|
(
|
|
38
|
-
| Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">>
|
|
39
|
+
| (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> &
|
|
40
|
+
Partial<
|
|
41
|
+
Pick<
|
|
42
|
+
CompleteHocuspocusProviderWebsocketConfiguration,
|
|
43
|
+
"preserveTrailingSlash"
|
|
44
|
+
>
|
|
45
|
+
>)
|
|
39
46
|
| Required<
|
|
40
47
|
Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">
|
|
41
48
|
>
|
|
@@ -129,7 +136,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
129
136
|
|
|
130
137
|
isAuthenticated = false;
|
|
131
138
|
|
|
132
|
-
authorizedScope:
|
|
139
|
+
authorizedScope: AuthorizedScope | undefined = undefined;
|
|
133
140
|
|
|
134
141
|
// @internal
|
|
135
142
|
manageSocket = false;
|
|
@@ -221,12 +228,10 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
221
228
|
configuration: Partial<HocuspocusProviderConfiguration> = {},
|
|
222
229
|
): void {
|
|
223
230
|
if (!configuration.websocketProvider) {
|
|
224
|
-
const websocketProviderConfig =
|
|
225
|
-
configuration as CompleteHocuspocusProviderWebsocketConfiguration;
|
|
226
231
|
this.manageSocket = true;
|
|
227
|
-
this.configuration.websocketProvider = new HocuspocusProviderWebsocket(
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
this.configuration.websocketProvider = new HocuspocusProviderWebsocket(
|
|
233
|
+
configuration as CompleteHocuspocusProviderWebsocketConfiguration,
|
|
234
|
+
);
|
|
230
235
|
}
|
|
231
236
|
|
|
232
237
|
this.configuration = { ...this.configuration, ...configuration };
|
|
@@ -309,7 +314,9 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
309
314
|
try {
|
|
310
315
|
token = await this.getToken();
|
|
311
316
|
} catch (error) {
|
|
312
|
-
this.permissionDeniedHandler(
|
|
317
|
+
this.permissionDeniedHandler(
|
|
318
|
+
`Failed to get token during sendToken(): ${error}`,
|
|
319
|
+
);
|
|
313
320
|
return;
|
|
314
321
|
}
|
|
315
322
|
|
|
@@ -580,7 +587,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
580
587
|
|
|
581
588
|
authenticatedHandler(scope: string) {
|
|
582
589
|
this.isAuthenticated = true;
|
|
583
|
-
this.authorizedScope = scope;
|
|
590
|
+
this.authorizedScope = scope as AuthorizedScope;
|
|
584
591
|
|
|
585
592
|
this.emit("authenticated", { scope });
|
|
586
593
|
}
|
|
@@ -37,6 +37,12 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
37
37
|
*/
|
|
38
38
|
url: string;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* By default, trailing slashes are removed from the URL. Set this to true
|
|
42
|
+
* to preserve trailing slashes if your server configuration requires them.
|
|
43
|
+
*/
|
|
44
|
+
preserveTrailingSlash: boolean;
|
|
45
|
+
|
|
40
46
|
/**
|
|
41
47
|
* An optional WebSocket polyfill, for example for Node.js
|
|
42
48
|
*/
|
|
@@ -102,6 +108,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
102
108
|
public configuration: CompleteHocuspocusProviderWebsocketConfiguration = {
|
|
103
109
|
url: "",
|
|
104
110
|
autoConnect: true,
|
|
111
|
+
preserveTrailingSlash: false,
|
|
105
112
|
// @ts-ignore
|
|
106
113
|
document: undefined,
|
|
107
114
|
WebSocketPolyfill: undefined,
|
|
@@ -434,13 +441,18 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
434
441
|
}
|
|
435
442
|
}
|
|
436
443
|
|
|
437
|
-
// Ensure that the URL never ends with /
|
|
438
444
|
get serverUrl() {
|
|
439
|
-
|
|
440
|
-
return this.configuration.url
|
|
445
|
+
if (this.configuration.preserveTrailingSlash) {
|
|
446
|
+
return this.configuration.url;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// By default, ensure that the URL never ends with /
|
|
450
|
+
let url = this.configuration.url;
|
|
451
|
+
while (url[url.length - 1] === "/") {
|
|
452
|
+
url = url.slice(0, url.length - 1);
|
|
441
453
|
}
|
|
442
454
|
|
|
443
|
-
return
|
|
455
|
+
return url;
|
|
444
456
|
}
|
|
445
457
|
|
|
446
458
|
get url() {
|
package/src/MessageReceiver.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readAuthMessage } from "@hocuspocus/common";
|
|
2
2
|
import { readVarInt, readVarString } from "lib0/decoding";
|
|
3
|
+
import type { CloseEvent } from "ws";
|
|
3
4
|
import * as awarenessProtocol from "y-protocols/awareness";
|
|
4
5
|
import { messageYjsSyncStep2, readSyncMessage } from "y-protocols/sync";
|
|
5
|
-
import type { CloseEvent } from "ws";
|
|
6
6
|
import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
|
|
7
7
|
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
8
8
|
import { OutgoingMessage } from "./OutgoingMessage.ts";
|
|
@@ -60,7 +60,7 @@ export class MessageReceiver {
|
|
|
60
60
|
};
|
|
61
61
|
provider.onClose();
|
|
62
62
|
provider.configuration.onClose({ event });
|
|
63
|
-
provider.forwardClose(event);
|
|
63
|
+
provider.forwardClose({ event });
|
|
64
64
|
break;
|
|
65
65
|
|
|
66
66
|
default:
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,8 @@ export enum WebSocketStatus {
|
|
|
28
28
|
Disconnected = "disconnected",
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export type AuthorizedScope = "read-write" | "readonly";
|
|
32
|
+
|
|
31
33
|
export interface OutgoingMessageInterface {
|
|
32
34
|
encoder: Encoder;
|
|
33
35
|
type?: MessageType;
|
|
@@ -62,7 +64,7 @@ export type onAuthenticationFailedParameters = {
|
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export type onAuthenticatedParameters = {
|
|
65
|
-
scope:
|
|
67
|
+
scope: AuthorizedScope;
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
export type onOpenParameters = {
|