@hocuspocus/extension-s3 3.2.6 → 3.3.1

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.
@@ -1,6 +1,12 @@
1
1
  import * as encoding from "lib0/encoding";
2
2
  import * as decoding from "lib0/decoding";
3
+ export declare enum AuthMessageType {
4
+ Token = 0,
5
+ PermissionDenied = 1,
6
+ Authenticated = 2
7
+ }
3
8
  export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
9
  export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
10
  export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: "readonly" | "read-write") => void;
6
- export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
11
+ export declare const writeTokenSyncRequest: (encoder: encoding.Encoder) => void;
12
+ export declare const readAuthMessage: (decoder: decoding.Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
@@ -87,6 +87,7 @@ export declare class HocuspocusProvider extends EventEmitter {
87
87
  pageHide(): void;
88
88
  registerEventListeners(): void;
89
89
  sendStateless(payload: string): void;
90
+ sendToken(): Promise<void>;
90
91
  documentUpdateHandler(update: Uint8Array, origin: any): void;
91
92
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
92
93
  /**
@@ -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 } from "./types.ts";
5
+ import type { beforeSyncPayload, onStatelessPayload, onTokenSyncPayload } from "./types.ts";
6
6
  export declare class Connection {
7
7
  webSocket: WebSocket;
8
8
  context: any;
@@ -13,6 +13,7 @@ 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: Partial<onTokenSyncPayload>) => Promise<void>;
16
17
  };
17
18
  socketId: string;
18
19
  readOnly: boolean;
@@ -36,6 +37,10 @@ export declare class Connection {
36
37
  * Set a callback that will be triggered before a sync message is handled
37
38
  */
38
39
  beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<any>): Connection;
40
+ /**
41
+ * Set a callback that will be triggered when on token sync message is received
42
+ */
43
+ onTokenSyncCallback(callback: (payload: onTokenSyncPayload) => Promise<void>): Connection;
39
44
  /**
40
45
  * Send the given message
41
46
  */
@@ -44,6 +49,10 @@ export declare class Connection {
44
49
  * Send a stateless message with payload
45
50
  */
46
51
  sendStateless(payload: string): void;
52
+ /**
53
+ * Request current token from the client
54
+ */
55
+ requestToken(): void;
47
56
  /**
48
57
  * Graceful wrapper around the WebSocket close method.
49
58
  */
@@ -19,6 +19,7 @@ export declare const defaultConfiguration: {
19
19
  export declare class Hocuspocus {
20
20
  configuration: Configuration;
21
21
  loadingDocuments: Map<string, Promise<Document>>;
22
+ unloadingDocuments: Map<string, Promise<void>>;
22
23
  documents: Map<string, Document>;
23
24
  server?: Server;
24
25
  debouncer: {
@@ -5,7 +5,7 @@ export declare class MessageReceiver {
5
5
  message: IncomingMessage;
6
6
  defaultTransactionOrigin?: string;
7
7
  constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
8
- apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): Promise<void>;
9
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): Promise<0 | 1 | 2>;
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 | 1 | 2;
10
10
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
11
11
  }
@@ -10,6 +10,7 @@ export declare class OutgoingMessage {
10
10
  createSyncReplyMessage(): OutgoingMessage;
11
11
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
12
12
  writeQueryAwareness(): OutgoingMessage;
13
+ writeTokenSyncRequest(): OutgoingMessage;
13
14
  writeAuthenticated(readonly: boolean): OutgoingMessage;
14
15
  writePermissionDenied(reason: string): OutgoingMessage;
15
16
  writeFirstSyncStepFor(document: Document): OutgoingMessage;
@@ -34,6 +34,7 @@ export interface Extension {
34
34
  onConnect?(data: onConnectPayload): Promise<any>;
35
35
  connected?(data: connectedPayload): Promise<any>;
36
36
  onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
37
+ onTokenSync?(data: onTokenSyncPayload): Promise<any>;
37
38
  onCreateDocument?(data: onCreateDocumentPayload): Promise<any>;
38
39
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
39
40
  afterLoadDocument?(data: afterLoadDocumentPayload): Promise<any>;
@@ -51,7 +52,7 @@ export interface Extension {
51
52
  afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
52
53
  onDestroy?(data: onDestroyPayload): Promise<any>;
53
54
  }
54
- export type HookName = "onConfigure" | "onListen" | "onUpgrade" | "onConnect" | "connected" | "onAuthenticate" | "onCreateDocument" | "onLoadDocument" | "afterLoadDocument" | "beforeHandleMessage" | "beforeBroadcastStateless" | "beforeSync" | "onStateless" | "onChange" | "onStoreDocument" | "afterStoreDocument" | "onAwarenessUpdate" | "onRequest" | "onDisconnect" | "beforeUnloadDocument" | "afterUnloadDocument" | "onDestroy";
55
+ export type HookName = "onConfigure" | "onListen" | "onUpgrade" | "onConnect" | "connected" | "onAuthenticate" | "onTokenSync" | "onCreateDocument" | "onLoadDocument" | "afterLoadDocument" | "beforeHandleMessage" | "beforeBroadcastStateless" | "beforeSync" | "onStateless" | "onChange" | "onStoreDocument" | "afterStoreDocument" | "onAwarenessUpdate" | "onRequest" | "onDisconnect" | "beforeUnloadDocument" | "afterUnloadDocument" | "onDestroy";
55
56
  export type HookPayloadByName = {
56
57
  onConfigure: onConfigurePayload;
57
58
  onListen: onListenPayload;
@@ -59,6 +60,7 @@ export type HookPayloadByName = {
59
60
  onConnect: onConnectPayload;
60
61
  connected: connectedPayload;
61
62
  onAuthenticate: onAuthenticatePayload;
63
+ onTokenSync: onTokenSyncPayload;
62
64
  onCreateDocument: onCreateDocumentPayload;
63
65
  onLoadDocument: onLoadDocumentPayload;
64
66
  afterLoadDocument: afterLoadDocumentPayload;
@@ -135,6 +137,18 @@ export interface onAuthenticatePayload {
135
137
  token: string;
136
138
  connectionConfig: ConnectionConfiguration;
137
139
  }
140
+ export interface onTokenSyncPayload {
141
+ context: any;
142
+ document: Document;
143
+ documentName: string;
144
+ instance: Hocuspocus;
145
+ requestHeaders: IncomingHttpHeaders;
146
+ requestParameters: URLSearchParams;
147
+ socketId: string;
148
+ token: string;
149
+ connectionConfig: ConnectionConfiguration;
150
+ connection: Connection;
151
+ }
138
152
  export interface onCreateDocumentPayload {
139
153
  context: any;
140
154
  documentName: string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-s3",
3
3
  "description": "a S3-compatible persistence driver for Hocuspocus",
4
- "version": "3.2.6",
4
+ "version": "3.3.1",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@aws-sdk/client-s3": "^3.0.0",
33
- "@hocuspocus/extension-database": "^3.2.6",
33
+ "@hocuspocus/extension-database": "^3.3.1",
34
34
  "kleur": "^4.1.4"
35
35
  },
36
36
  "publishConfig": {