@hocuspocus/extension-throttle 3.4.3 → 3.4.5-rc.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/hocuspocus-throttle.cjs +69 -86
- package/dist/hocuspocus-throttle.cjs.map +1 -1
- package/dist/hocuspocus-throttle.esm.js +68 -85
- package/dist/hocuspocus-throttle.esm.js.map +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.js +69 -0
- package/package.json +4 -4
- package/dist/node_modules/@tiptap/pm/model/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/state/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/transform/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/view/index.d.ts +0 -1
- package/dist/packages/common/src/CloseEvents.d.ts +0 -29
- package/dist/packages/common/src/auth.d.ts +0 -12
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +0 -3
- package/dist/packages/common/src/index.d.ts +0 -4
- package/dist/packages/common/src/types.d.ts +0 -10
- package/dist/packages/extension-database/src/Database.d.ts +0 -30
- package/dist/packages/extension-database/src/index.d.ts +0 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +0 -67
- package/dist/packages/extension-logger/src/index.d.ts +0 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +0 -124
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/extension-s3/src/S3.d.ts +0 -44
- package/dist/packages/extension-s3/src/index.d.ts +0 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +0 -27
- package/dist/packages/extension-sqlite/src/index.d.ts +0 -1
- package/dist/packages/extension-throttle/src/index.d.ts +0 -30
- package/dist/packages/extension-webhook/src/index.d.ts +0 -56
- package/dist/packages/provider/src/EventEmitter.d.ts +0 -9
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -116
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -114
- package/dist/packages/provider/src/IncomingMessage.d.ts +0 -17
- package/dist/packages/provider/src/MessageReceiver.d.ts +0 -12
- package/dist/packages/provider/src/MessageSender.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +0 -8
- package/dist/packages/provider/src/index.d.ts +0 -3
- package/dist/packages/provider/src/types.d.ts +0 -92
- package/dist/packages/server/src/ClientConnection.d.ts +0 -63
- package/dist/packages/server/src/Connection.d.ts +0 -71
- package/dist/packages/server/src/DirectConnection.d.ts +0 -14
- package/dist/packages/server/src/Document.d.ts +0 -92
- package/dist/packages/server/src/Hocuspocus.d.ts +0 -80
- package/dist/packages/server/src/IncomingMessage.d.ts +0 -25
- package/dist/packages/server/src/MessageReceiver.d.ts +0 -11
- package/dist/packages/server/src/OutgoingMessage.d.ts +0 -23
- package/dist/packages/server/src/Server.d.ts +0 -32
- package/dist/packages/server/src/index.d.ts +0 -9
- package/dist/packages/server/src/types.d.ts +0 -342
- package/dist/packages/server/src/util/debounce.d.ts +0 -6
- package/dist/packages/server/src/util/getParameters.d.ts +0 -6
- package/dist/packages/transformer/src/Prosemirror.d.ts +0 -11
- package/dist/packages/transformer/src/Tiptap.d.ts +0 -10
- package/dist/packages/transformer/src/index.d.ts +0 -3
- package/dist/packages/transformer/src/types.d.ts +0 -5
- package/dist/playground/backend/src/default.d.ts +0 -1
- package/dist/playground/backend/src/deno.d.ts +0 -1
- package/dist/playground/backend/src/express.d.ts +0 -1
- package/dist/playground/backend/src/hono.d.ts +0 -1
- package/dist/playground/backend/src/koa.d.ts +0 -1
- package/dist/playground/backend/src/load-document.d.ts +0 -1
- package/dist/playground/backend/src/redis.d.ts +0 -1
- package/dist/playground/backend/src/s3-redis.d.ts +0 -1
- package/dist/playground/backend/src/s3.d.ts +0 -1
- package/dist/playground/backend/src/slow.d.ts +0 -1
- package/dist/playground/backend/src/tiptapcollab.d.ts +0 -1
- package/dist/playground/backend/src/webhook.d.ts +0 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +0 -2
- package/dist/playground/frontend/app/SocketContext2.d.ts +0 -2
- package/dist/playground/frontend/next.config.d.ts +0 -3
- package/dist/tests/extension-database/fetch.d.ts +0 -1
- package/dist/tests/extension-logger/onListen.d.ts +0 -1
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +0 -1
- package/dist/tests/extension-redis/onChange.d.ts +0 -1
- package/dist/tests/extension-redis/onStateless.d.ts +0 -1
- package/dist/tests/extension-redis/onStoreDocument.d.ts +0 -1
- package/dist/tests/extension-s3/fetch.d.ts +0 -1
- package/dist/tests/extension-throttle/banning.d.ts +0 -1
- package/dist/tests/extension-throttle/configuration.d.ts +0 -1
- package/dist/tests/provider/hasUnsyncedChanges.d.ts +0 -1
- package/dist/tests/provider/observe.d.ts +0 -1
- package/dist/tests/provider/observeDeep.d.ts +0 -1
- package/dist/tests/provider/onAuthenticated.d.ts +0 -1
- package/dist/tests/provider/onAuthenticationFailed.d.ts +0 -1
- package/dist/tests/provider/onAwarenessChange.d.ts +0 -1
- package/dist/tests/provider/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/provider/onClose.d.ts +0 -1
- package/dist/tests/provider/onConnect.d.ts +0 -1
- package/dist/tests/provider/onDisconnect.d.ts +0 -1
- package/dist/tests/provider/onMessage.d.ts +0 -1
- package/dist/tests/provider/onOpen.d.ts +0 -1
- package/dist/tests/provider/onStateless.d.ts +0 -1
- package/dist/tests/provider/onSynced.d.ts +0 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +0 -1
- package/dist/tests/server/address.d.ts +0 -1
- package/dist/tests/server/afterLoadDocument.d.ts +0 -1
- package/dist/tests/server/afterStoreDocument.d.ts +0 -1
- package/dist/tests/server/afterUnloadDocument.d.ts +0 -1
- package/dist/tests/server/beforeBroadcastStateless.d.ts +0 -1
- package/dist/tests/server/beforeHandleMessage.d.ts +0 -1
- package/dist/tests/server/beforeSync.d.ts +0 -1
- package/dist/tests/server/beforeUnloadDocument.d.ts +0 -1
- package/dist/tests/server/closeConnections.d.ts +0 -1
- package/dist/tests/server/getConnectionsCount.d.ts +0 -1
- package/dist/tests/server/getDocumentsCount.d.ts +0 -1
- package/dist/tests/server/listen.d.ts +0 -1
- package/dist/tests/server/onAuthenticate.d.ts +0 -1
- package/dist/tests/server/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/server/onChange.d.ts +0 -1
- package/dist/tests/server/onClose.d.ts +0 -1
- package/dist/tests/server/onConfigure.d.ts +0 -1
- package/dist/tests/server/onConnect.d.ts +0 -1
- package/dist/tests/server/onDestroy.d.ts +0 -1
- package/dist/tests/server/onDisconnect.d.ts +0 -1
- package/dist/tests/server/onListen.d.ts +0 -1
- package/dist/tests/server/onLoadDocument.d.ts +0 -1
- package/dist/tests/server/onRequest.d.ts +0 -1
- package/dist/tests/server/onStateless.d.ts +0 -1
- package/dist/tests/server/onStoreDocument.d.ts +0 -1
- package/dist/tests/server/onTokenSync.d.ts +0 -1
- package/dist/tests/server/onUpgrade.d.ts +0 -1
- package/dist/tests/server/openDirectConnection.d.ts +0 -1
- package/dist/tests/server/websocketError.d.ts +0 -1
- package/dist/tests/transformer/TiptapTransformer.d.ts +0 -1
- package/dist/tests/utils/createDirectory.d.ts +0 -1
- package/dist/tests/utils/flushRedis.d.ts +0 -1
- package/dist/tests/utils/index.d.ts +0 -9
- package/dist/tests/utils/newHocuspocus.d.ts +0 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +0 -3
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +0 -4
- package/dist/tests/utils/randomInteger.d.ts +0 -1
- package/dist/tests/utils/redisConnectionSettings.d.ts +0 -4
- package/dist/tests/utils/removeDirectory.d.ts +0 -1
- package/dist/tests/utils/retryableAssertion.d.ts +0 -2
- package/dist/tests/utils/sleep.d.ts +0 -1
|
@@ -1,89 +1,72 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* onConnect hook
|
|
74
|
-
* @param data
|
|
75
|
-
*/
|
|
76
|
-
onConnect(data) {
|
|
77
|
-
const { request } = data;
|
|
78
|
-
// get the remote ip address
|
|
79
|
-
const ip = request.headers["x-real-ip"] ||
|
|
80
|
-
request.headers["x-forwarded-for"] ||
|
|
81
|
-
request.socket.remoteAddress ||
|
|
82
|
-
"";
|
|
83
|
-
// throttle the connection
|
|
84
|
-
return this.throttle(ip) ? Promise.reject() : Promise.resolve();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
3
|
+
//#region packages/extension-throttle/src/index.ts
|
|
4
|
+
var Throttle = class {
|
|
5
|
+
/**
|
|
6
|
+
* Constructor
|
|
7
|
+
*/
|
|
8
|
+
constructor(configuration) {
|
|
9
|
+
this.configuration = {
|
|
10
|
+
throttle: 15,
|
|
11
|
+
banTime: 5,
|
|
12
|
+
consideredSeconds: 60,
|
|
13
|
+
cleanupInterval: 90
|
|
14
|
+
};
|
|
15
|
+
this.connectionsByIp = /* @__PURE__ */ new Map();
|
|
16
|
+
this.bannedIps = /* @__PURE__ */ new Map();
|
|
17
|
+
this.configuration = {
|
|
18
|
+
...this.configuration,
|
|
19
|
+
...configuration
|
|
20
|
+
};
|
|
21
|
+
this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1e3);
|
|
22
|
+
}
|
|
23
|
+
onDestroy() {
|
|
24
|
+
if (this.cleanupInterval) clearInterval(this.cleanupInterval);
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
clearMaps() {
|
|
28
|
+
this.connectionsByIp.forEach((value, key) => {
|
|
29
|
+
const filteredValue = value.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
30
|
+
if (filteredValue.length) this.connectionsByIp.set(key, filteredValue);
|
|
31
|
+
else this.connectionsByIp.delete(key);
|
|
32
|
+
});
|
|
33
|
+
this.bannedIps.forEach((value, key) => {
|
|
34
|
+
if (!this.isBanned(key)) this.bannedIps.delete(key);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
isBanned(ip) {
|
|
38
|
+
const bannedAt = this.bannedIps.get(ip) || 0;
|
|
39
|
+
return Date.now() < bannedAt + this.configuration.banTime * 60 * 1e3;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Throttle requests
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
throttle(ip) {
|
|
46
|
+
if (!this.configuration.throttle) return false;
|
|
47
|
+
if (this.isBanned(ip)) return true;
|
|
48
|
+
this.bannedIps.delete(ip);
|
|
49
|
+
const previousConnections = this.connectionsByIp.get(ip) || [];
|
|
50
|
+
previousConnections.push(Date.now());
|
|
51
|
+
const previousConnectionsInTheConsideredInterval = previousConnections.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
52
|
+
this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval);
|
|
53
|
+
if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {
|
|
54
|
+
this.bannedIps.set(ip, Date.now());
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* onConnect hook
|
|
61
|
+
* @param data
|
|
62
|
+
*/
|
|
63
|
+
onConnect(data) {
|
|
64
|
+
const { request } = data;
|
|
65
|
+
const ip = request.headers["x-real-ip"] || request.headers["x-forwarded-for"] || request.socket.remoteAddress || "";
|
|
66
|
+
return this.throttle(ip) ? Promise.reject() : Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
87
69
|
|
|
70
|
+
//#endregion
|
|
88
71
|
exports.Throttle = Throttle;
|
|
89
|
-
//# sourceMappingURL=hocuspocus-throttle.cjs.map
|
|
72
|
+
//# sourceMappingURL=hocuspocus-throttle.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-throttle.cjs","sources":["../src/index.ts"],"sourcesContent":[null],"
|
|
1
|
+
{"version":3,"file":"hocuspocus-throttle.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Extension, onConnectPayload } from \"@hocuspocus/server\";\n\nexport interface ThrottleConfiguration {\n\tthrottle: number | null | false; // how many requests within `consideredSeconds` until we're rejecting requests (setting this to 15 means the 16th request will be rejected)\n\tconsideredSeconds: number; // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n\tbanTime: number; // for how long to ban after receiving too many requests (in minutes!)\n\tcleanupInterval: number; // how often to clean up the records of IPs (this won't delete ips that are still blocked or recent enough by `consideredSeconds`)\n}\n\nexport class Throttle implements Extension {\n\tconfiguration: ThrottleConfiguration = {\n\t\tthrottle: 15,\n\t\tbanTime: 5,\n\t\tconsideredSeconds: 60,\n\t\tcleanupInterval: 90,\n\t};\n\n\tconnectionsByIp: Map<string, Array<number>> = new Map();\n\n\tbannedIps: Map<string, number> = new Map();\n\n\tcleanupInterval?: NodeJS.Timeout;\n\n\t/**\n\t * Constructor\n\t */\n\tconstructor(configuration?: Partial<ThrottleConfiguration>) {\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\n\t\tthis.cleanupInterval = setInterval(\n\t\t\tthis.clearMaps.bind(this),\n\t\t\tthis.configuration.cleanupInterval * 1000,\n\t\t);\n\t}\n\n\tonDestroy() {\n\t\tif (this.cleanupInterval) {\n\t\t\tclearInterval(this.cleanupInterval);\n\t\t}\n\n\t\treturn Promise.resolve();\n\t}\n\n\tpublic clearMaps() {\n\t\tthis.connectionsByIp.forEach((value, key) => {\n\t\t\tconst filteredValue = value.filter(\n\t\t\t\t(timestamp) =>\n\t\t\t\t\ttimestamp + this.configuration.consideredSeconds * 1000 > Date.now(),\n\t\t\t);\n\n\t\t\tif (filteredValue.length) {\n\t\t\t\tthis.connectionsByIp.set(key, filteredValue);\n\t\t\t} else {\n\t\t\t\tthis.connectionsByIp.delete(key);\n\t\t\t}\n\t\t});\n\n\t\tthis.bannedIps.forEach((value, key) => {\n\t\t\tif (!this.isBanned(key)) {\n\t\t\t\tthis.bannedIps.delete(key);\n\t\t\t}\n\t\t});\n\t}\n\n\tisBanned(ip: string) {\n\t\tconst bannedAt = this.bannedIps.get(ip) || 0;\n\t\treturn Date.now() < bannedAt + this.configuration.banTime * 60 * 1000;\n\t}\n\n\t/**\n\t * Throttle requests\n\t * @private\n\t */\n\tprivate throttle(ip: string): boolean {\n\t\tif (!this.configuration.throttle) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.isBanned(ip)) return true;\n\n\t\tthis.bannedIps.delete(ip);\n\n\t\t// add this connection try to the list of previous connections\n\t\tconst previousConnections = this.connectionsByIp.get(ip) || [];\n\t\tpreviousConnections.push(Date.now());\n\n\t\t// calculate the previous connections in the last considered time interval\n\t\tconst previousConnectionsInTheConsideredInterval =\n\t\t\tpreviousConnections.filter(\n\t\t\t\t(timestamp) =>\n\t\t\t\t\ttimestamp + this.configuration.consideredSeconds * 1000 > Date.now(),\n\t\t\t);\n\n\t\tthis.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval);\n\n\t\tif (\n\t\t\tpreviousConnectionsInTheConsideredInterval.length >\n\t\t\tthis.configuration.throttle\n\t\t) {\n\t\t\tthis.bannedIps.set(ip, Date.now());\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * onConnect hook\n\t * @param data\n\t */\n\tonConnect(data: onConnectPayload): Promise<any> {\n\t\tconst { request } = data;\n\n\t\t// get the remote ip address\n\t\tconst ip =\n\t\t\trequest.headers[\"x-real-ip\"] ||\n\t\t\trequest.headers[\"x-forwarded-for\"] ||\n\t\t\trequest.socket.remoteAddress ||\n\t\t\t\"\";\n\n\t\t// throttle the connection\n\t\treturn this.throttle(<string>ip) ? Promise.reject() : Promise.resolve();\n\t}\n}\n"],"mappings":";;;AASA,IAAa,WAAb,MAA2C;;;;CAiB1C,YAAY,eAAgD;uBAhBrB;GACtC,UAAU;GACV,SAAS;GACT,mBAAmB;GACnB,iBAAiB;GACjB;yCAE6C,IAAI,KAAK;mCAEtB,IAAI,KAAK;AAQzC,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;AAED,OAAK,kBAAkB,YACtB,KAAK,UAAU,KAAK,KAAK,EACzB,KAAK,cAAc,kBAAkB,IACrC;;CAGF,YAAY;AACX,MAAI,KAAK,gBACR,eAAc,KAAK,gBAAgB;AAGpC,SAAO,QAAQ,SAAS;;CAGzB,AAAO,YAAY;AAClB,OAAK,gBAAgB,SAAS,OAAO,QAAQ;GAC5C,MAAM,gBAAgB,MAAM,QAC1B,cACA,YAAY,KAAK,cAAc,oBAAoB,MAAO,KAAK,KAAK,CACrE;AAED,OAAI,cAAc,OACjB,MAAK,gBAAgB,IAAI,KAAK,cAAc;OAE5C,MAAK,gBAAgB,OAAO,IAAI;IAEhC;AAEF,OAAK,UAAU,SAAS,OAAO,QAAQ;AACtC,OAAI,CAAC,KAAK,SAAS,IAAI,CACtB,MAAK,UAAU,OAAO,IAAI;IAE1B;;CAGH,SAAS,IAAY;EACpB,MAAM,WAAW,KAAK,UAAU,IAAI,GAAG,IAAI;AAC3C,SAAO,KAAK,KAAK,GAAG,WAAW,KAAK,cAAc,UAAU,KAAK;;;;;;CAOlE,AAAQ,SAAS,IAAqB;AACrC,MAAI,CAAC,KAAK,cAAc,SACvB,QAAO;AAGR,MAAI,KAAK,SAAS,GAAG,CAAE,QAAO;AAE9B,OAAK,UAAU,OAAO,GAAG;EAGzB,MAAM,sBAAsB,KAAK,gBAAgB,IAAI,GAAG,IAAI,EAAE;AAC9D,sBAAoB,KAAK,KAAK,KAAK,CAAC;EAGpC,MAAM,6CACL,oBAAoB,QAClB,cACA,YAAY,KAAK,cAAc,oBAAoB,MAAO,KAAK,KAAK,CACrE;AAEF,OAAK,gBAAgB,IAAI,IAAI,2CAA2C;AAExE,MACC,2CAA2C,SAC3C,KAAK,cAAc,UAClB;AACD,QAAK,UAAU,IAAI,IAAI,KAAK,KAAK,CAAC;AAClC,UAAO;;AAGR,SAAO;;;;;;CAOR,UAAU,MAAsC;EAC/C,MAAM,EAAE,YAAY;EAGpB,MAAM,KACL,QAAQ,QAAQ,gBAChB,QAAQ,QAAQ,sBAChB,QAAQ,OAAO,iBACf;AAGD,SAAO,KAAK,SAAiB,GAAG,GAAG,QAAQ,QAAQ,GAAG,QAAQ,SAAS"}
|
|
@@ -1,87 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* onConnect hook
|
|
72
|
-
* @param data
|
|
73
|
-
*/
|
|
74
|
-
onConnect(data) {
|
|
75
|
-
const { request } = data;
|
|
76
|
-
// get the remote ip address
|
|
77
|
-
const ip = request.headers["x-real-ip"] ||
|
|
78
|
-
request.headers["x-forwarded-for"] ||
|
|
79
|
-
request.socket.remoteAddress ||
|
|
80
|
-
"";
|
|
81
|
-
// throttle the connection
|
|
82
|
-
return this.throttle(ip) ? Promise.reject() : Promise.resolve();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
1
|
+
//#region packages/extension-throttle/src/index.ts
|
|
2
|
+
var Throttle = class {
|
|
3
|
+
/**
|
|
4
|
+
* Constructor
|
|
5
|
+
*/
|
|
6
|
+
constructor(configuration) {
|
|
7
|
+
this.configuration = {
|
|
8
|
+
throttle: 15,
|
|
9
|
+
banTime: 5,
|
|
10
|
+
consideredSeconds: 60,
|
|
11
|
+
cleanupInterval: 90
|
|
12
|
+
};
|
|
13
|
+
this.connectionsByIp = /* @__PURE__ */ new Map();
|
|
14
|
+
this.bannedIps = /* @__PURE__ */ new Map();
|
|
15
|
+
this.configuration = {
|
|
16
|
+
...this.configuration,
|
|
17
|
+
...configuration
|
|
18
|
+
};
|
|
19
|
+
this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1e3);
|
|
20
|
+
}
|
|
21
|
+
onDestroy() {
|
|
22
|
+
if (this.cleanupInterval) clearInterval(this.cleanupInterval);
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
clearMaps() {
|
|
26
|
+
this.connectionsByIp.forEach((value, key) => {
|
|
27
|
+
const filteredValue = value.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
28
|
+
if (filteredValue.length) this.connectionsByIp.set(key, filteredValue);
|
|
29
|
+
else this.connectionsByIp.delete(key);
|
|
30
|
+
});
|
|
31
|
+
this.bannedIps.forEach((value, key) => {
|
|
32
|
+
if (!this.isBanned(key)) this.bannedIps.delete(key);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
isBanned(ip) {
|
|
36
|
+
const bannedAt = this.bannedIps.get(ip) || 0;
|
|
37
|
+
return Date.now() < bannedAt + this.configuration.banTime * 60 * 1e3;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Throttle requests
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
throttle(ip) {
|
|
44
|
+
if (!this.configuration.throttle) return false;
|
|
45
|
+
if (this.isBanned(ip)) return true;
|
|
46
|
+
this.bannedIps.delete(ip);
|
|
47
|
+
const previousConnections = this.connectionsByIp.get(ip) || [];
|
|
48
|
+
previousConnections.push(Date.now());
|
|
49
|
+
const previousConnectionsInTheConsideredInterval = previousConnections.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
50
|
+
this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval);
|
|
51
|
+
if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {
|
|
52
|
+
this.bannedIps.set(ip, Date.now());
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* onConnect hook
|
|
59
|
+
* @param data
|
|
60
|
+
*/
|
|
61
|
+
onConnect(data) {
|
|
62
|
+
const { request } = data;
|
|
63
|
+
const ip = request.headers["x-real-ip"] || request.headers["x-forwarded-for"] || request.socket.remoteAddress || "";
|
|
64
|
+
return this.throttle(ip) ? Promise.reject() : Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
85
67
|
|
|
68
|
+
//#endregion
|
|
86
69
|
export { Throttle };
|
|
87
|
-
//# sourceMappingURL=hocuspocus-throttle.esm.js.map
|
|
70
|
+
//# sourceMappingURL=hocuspocus-throttle.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-throttle.esm.js","sources":["../src/index.ts"],"sourcesContent":[null],"
|
|
1
|
+
{"version":3,"file":"hocuspocus-throttle.esm.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Extension, onConnectPayload } from \"@hocuspocus/server\";\n\nexport interface ThrottleConfiguration {\n\tthrottle: number | null | false; // how many requests within `consideredSeconds` until we're rejecting requests (setting this to 15 means the 16th request will be rejected)\n\tconsideredSeconds: number; // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n\tbanTime: number; // for how long to ban after receiving too many requests (in minutes!)\n\tcleanupInterval: number; // how often to clean up the records of IPs (this won't delete ips that are still blocked or recent enough by `consideredSeconds`)\n}\n\nexport class Throttle implements Extension {\n\tconfiguration: ThrottleConfiguration = {\n\t\tthrottle: 15,\n\t\tbanTime: 5,\n\t\tconsideredSeconds: 60,\n\t\tcleanupInterval: 90,\n\t};\n\n\tconnectionsByIp: Map<string, Array<number>> = new Map();\n\n\tbannedIps: Map<string, number> = new Map();\n\n\tcleanupInterval?: NodeJS.Timeout;\n\n\t/**\n\t * Constructor\n\t */\n\tconstructor(configuration?: Partial<ThrottleConfiguration>) {\n\t\tthis.configuration = {\n\t\t\t...this.configuration,\n\t\t\t...configuration,\n\t\t};\n\n\t\tthis.cleanupInterval = setInterval(\n\t\t\tthis.clearMaps.bind(this),\n\t\t\tthis.configuration.cleanupInterval * 1000,\n\t\t);\n\t}\n\n\tonDestroy() {\n\t\tif (this.cleanupInterval) {\n\t\t\tclearInterval(this.cleanupInterval);\n\t\t}\n\n\t\treturn Promise.resolve();\n\t}\n\n\tpublic clearMaps() {\n\t\tthis.connectionsByIp.forEach((value, key) => {\n\t\t\tconst filteredValue = value.filter(\n\t\t\t\t(timestamp) =>\n\t\t\t\t\ttimestamp + this.configuration.consideredSeconds * 1000 > Date.now(),\n\t\t\t);\n\n\t\t\tif (filteredValue.length) {\n\t\t\t\tthis.connectionsByIp.set(key, filteredValue);\n\t\t\t} else {\n\t\t\t\tthis.connectionsByIp.delete(key);\n\t\t\t}\n\t\t});\n\n\t\tthis.bannedIps.forEach((value, key) => {\n\t\t\tif (!this.isBanned(key)) {\n\t\t\t\tthis.bannedIps.delete(key);\n\t\t\t}\n\t\t});\n\t}\n\n\tisBanned(ip: string) {\n\t\tconst bannedAt = this.bannedIps.get(ip) || 0;\n\t\treturn Date.now() < bannedAt + this.configuration.banTime * 60 * 1000;\n\t}\n\n\t/**\n\t * Throttle requests\n\t * @private\n\t */\n\tprivate throttle(ip: string): boolean {\n\t\tif (!this.configuration.throttle) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.isBanned(ip)) return true;\n\n\t\tthis.bannedIps.delete(ip);\n\n\t\t// add this connection try to the list of previous connections\n\t\tconst previousConnections = this.connectionsByIp.get(ip) || [];\n\t\tpreviousConnections.push(Date.now());\n\n\t\t// calculate the previous connections in the last considered time interval\n\t\tconst previousConnectionsInTheConsideredInterval =\n\t\t\tpreviousConnections.filter(\n\t\t\t\t(timestamp) =>\n\t\t\t\t\ttimestamp + this.configuration.consideredSeconds * 1000 > Date.now(),\n\t\t\t);\n\n\t\tthis.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval);\n\n\t\tif (\n\t\t\tpreviousConnectionsInTheConsideredInterval.length >\n\t\t\tthis.configuration.throttle\n\t\t) {\n\t\t\tthis.bannedIps.set(ip, Date.now());\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * onConnect hook\n\t * @param data\n\t */\n\tonConnect(data: onConnectPayload): Promise<any> {\n\t\tconst { request } = data;\n\n\t\t// get the remote ip address\n\t\tconst ip =\n\t\t\trequest.headers[\"x-real-ip\"] ||\n\t\t\trequest.headers[\"x-forwarded-for\"] ||\n\t\t\trequest.socket.remoteAddress ||\n\t\t\t\"\";\n\n\t\t// throttle the connection\n\t\treturn this.throttle(<string>ip) ? Promise.reject() : Promise.resolve();\n\t}\n}\n"],"mappings":";AASA,IAAa,WAAb,MAA2C;;;;CAiB1C,YAAY,eAAgD;uBAhBrB;GACtC,UAAU;GACV,SAAS;GACT,mBAAmB;GACnB,iBAAiB;GACjB;yCAE6C,IAAI,KAAK;mCAEtB,IAAI,KAAK;AAQzC,OAAK,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAG;GACH;AAED,OAAK,kBAAkB,YACtB,KAAK,UAAU,KAAK,KAAK,EACzB,KAAK,cAAc,kBAAkB,IACrC;;CAGF,YAAY;AACX,MAAI,KAAK,gBACR,eAAc,KAAK,gBAAgB;AAGpC,SAAO,QAAQ,SAAS;;CAGzB,AAAO,YAAY;AAClB,OAAK,gBAAgB,SAAS,OAAO,QAAQ;GAC5C,MAAM,gBAAgB,MAAM,QAC1B,cACA,YAAY,KAAK,cAAc,oBAAoB,MAAO,KAAK,KAAK,CACrE;AAED,OAAI,cAAc,OACjB,MAAK,gBAAgB,IAAI,KAAK,cAAc;OAE5C,MAAK,gBAAgB,OAAO,IAAI;IAEhC;AAEF,OAAK,UAAU,SAAS,OAAO,QAAQ;AACtC,OAAI,CAAC,KAAK,SAAS,IAAI,CACtB,MAAK,UAAU,OAAO,IAAI;IAE1B;;CAGH,SAAS,IAAY;EACpB,MAAM,WAAW,KAAK,UAAU,IAAI,GAAG,IAAI;AAC3C,SAAO,KAAK,KAAK,GAAG,WAAW,KAAK,cAAc,UAAU,KAAK;;;;;;CAOlE,AAAQ,SAAS,IAAqB;AACrC,MAAI,CAAC,KAAK,cAAc,SACvB,QAAO;AAGR,MAAI,KAAK,SAAS,GAAG,CAAE,QAAO;AAE9B,OAAK,UAAU,OAAO,GAAG;EAGzB,MAAM,sBAAsB,KAAK,gBAAgB,IAAI,GAAG,IAAI,EAAE;AAC9D,sBAAoB,KAAK,KAAK,KAAK,CAAC;EAGpC,MAAM,6CACL,oBAAoB,QAClB,cACA,YAAY,KAAK,cAAc,oBAAoB,MAAO,KAAK,KAAK,CACrE;AAEF,OAAK,gBAAgB,IAAI,IAAI,2CAA2C;AAExE,MACC,2CAA2C,SAC3C,KAAK,cAAc,UAClB;AACD,QAAK,UAAU,IAAI,IAAI,KAAK,KAAK,CAAC;AAClC,UAAO;;AAGR,SAAO;;;;;;CAOR,UAAU,MAAsC;EAC/C,MAAM,EAAE,YAAY;EAGpB,MAAM,KACL,QAAQ,QAAQ,gBAChB,QAAQ,QAAQ,sBAChB,QAAQ,OAAO,iBACf;AAGD,SAAO,KAAK,SAAiB,GAAG,GAAG,QAAQ,QAAQ,GAAG,QAAQ,SAAS"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Extension, onConnectPayload } from "@hocuspocus/server";
|
|
2
|
+
|
|
3
|
+
//#region packages/extension-throttle/src/index.d.ts
|
|
4
|
+
interface ThrottleConfiguration {
|
|
5
|
+
throttle: number | null | false;
|
|
6
|
+
consideredSeconds: number;
|
|
7
|
+
banTime: number;
|
|
8
|
+
cleanupInterval: number;
|
|
9
|
+
}
|
|
10
|
+
declare class Throttle implements Extension {
|
|
11
|
+
configuration: ThrottleConfiguration;
|
|
12
|
+
connectionsByIp: Map<string, Array<number>>;
|
|
13
|
+
bannedIps: Map<string, number>;
|
|
14
|
+
cleanupInterval?: NodeJS.Timeout;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor
|
|
17
|
+
*/
|
|
18
|
+
constructor(configuration?: Partial<ThrottleConfiguration>);
|
|
19
|
+
onDestroy(): Promise<void>;
|
|
20
|
+
clearMaps(): void;
|
|
21
|
+
isBanned(ip: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Throttle requests
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private throttle;
|
|
27
|
+
/**
|
|
28
|
+
* onConnect hook
|
|
29
|
+
* @param data
|
|
30
|
+
*/
|
|
31
|
+
onConnect(data: onConnectPayload): Promise<any>;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { Throttle, ThrottleConfiguration };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region packages/extension-throttle/src/index.ts
|
|
2
|
+
var Throttle = class {
|
|
3
|
+
/**
|
|
4
|
+
* Constructor
|
|
5
|
+
*/
|
|
6
|
+
constructor(configuration) {
|
|
7
|
+
this.configuration = {
|
|
8
|
+
throttle: 15,
|
|
9
|
+
banTime: 5,
|
|
10
|
+
consideredSeconds: 60,
|
|
11
|
+
cleanupInterval: 90
|
|
12
|
+
};
|
|
13
|
+
this.connectionsByIp = /* @__PURE__ */ new Map();
|
|
14
|
+
this.bannedIps = /* @__PURE__ */ new Map();
|
|
15
|
+
this.configuration = {
|
|
16
|
+
...this.configuration,
|
|
17
|
+
...configuration
|
|
18
|
+
};
|
|
19
|
+
this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1e3);
|
|
20
|
+
}
|
|
21
|
+
onDestroy() {
|
|
22
|
+
if (this.cleanupInterval) clearInterval(this.cleanupInterval);
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
clearMaps() {
|
|
26
|
+
this.connectionsByIp.forEach((value, key) => {
|
|
27
|
+
const filteredValue = value.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
28
|
+
if (filteredValue.length) this.connectionsByIp.set(key, filteredValue);
|
|
29
|
+
else this.connectionsByIp.delete(key);
|
|
30
|
+
});
|
|
31
|
+
this.bannedIps.forEach((value, key) => {
|
|
32
|
+
if (!this.isBanned(key)) this.bannedIps.delete(key);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
isBanned(ip) {
|
|
36
|
+
const bannedAt = this.bannedIps.get(ip) || 0;
|
|
37
|
+
return Date.now() < bannedAt + this.configuration.banTime * 60 * 1e3;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Throttle requests
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
throttle(ip) {
|
|
44
|
+
if (!this.configuration.throttle) return false;
|
|
45
|
+
if (this.isBanned(ip)) return true;
|
|
46
|
+
this.bannedIps.delete(ip);
|
|
47
|
+
const previousConnections = this.connectionsByIp.get(ip) || [];
|
|
48
|
+
previousConnections.push(Date.now());
|
|
49
|
+
const previousConnectionsInTheConsideredInterval = previousConnections.filter((timestamp) => timestamp + this.configuration.consideredSeconds * 1e3 > Date.now());
|
|
50
|
+
this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval);
|
|
51
|
+
if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {
|
|
52
|
+
this.bannedIps.set(ip, Date.now());
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* onConnect hook
|
|
59
|
+
* @param data
|
|
60
|
+
*/
|
|
61
|
+
onConnect(data) {
|
|
62
|
+
const { request } = data;
|
|
63
|
+
const ip = request.headers["x-real-ip"] || request.headers["x-forwarded-for"] || request.socket.remoteAddress || "";
|
|
64
|
+
return this.throttle(ip) ? Promise.reject() : Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Throttle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-throttle",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5-rc.0",
|
|
4
4
|
"description": "hocuspocus throttle extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "dist/hocuspocus-throttle.cjs",
|
|
14
14
|
"module": "dist/hocuspocus-throttle.esm.js",
|
|
15
|
-
"types": "dist/
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
"source": {
|
|
18
18
|
"import": "./src/index.ts"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"default": {
|
|
21
21
|
"import": "./dist/hocuspocus-throttle.esm.js",
|
|
22
22
|
"require": "./dist/hocuspocus-throttle.cjs",
|
|
23
|
-
"types": "./dist/
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@hocuspocus/server": "^3.4.
|
|
31
|
+
"@hocuspocus/server": "^3.4.5-rc.0"
|
|
32
32
|
},
|
|
33
33
|
"gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d",
|
|
34
34
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from 'prosemirror-model';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from 'prosemirror-state';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from 'prosemirror-transform';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from 'prosemirror-view';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export interface CloseEvent {
|
|
2
|
-
code: number;
|
|
3
|
-
reason: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* The server is terminating the connection because a data frame was received
|
|
7
|
-
* that is too large.
|
|
8
|
-
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
|
9
|
-
*/
|
|
10
|
-
export declare const MessageTooBig: CloseEvent;
|
|
11
|
-
/**
|
|
12
|
-
* The server successfully processed the request, asks that the requester reset
|
|
13
|
-
* its document view, and is not returning any content.
|
|
14
|
-
*/
|
|
15
|
-
export declare const ResetConnection: CloseEvent;
|
|
16
|
-
/**
|
|
17
|
-
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
18
|
-
* failed or has not yet been provided.
|
|
19
|
-
*/
|
|
20
|
-
export declare const Unauthorized: CloseEvent;
|
|
21
|
-
/**
|
|
22
|
-
* The request contained valid data and was understood by the server, but the server
|
|
23
|
-
* is refusing action.
|
|
24
|
-
*/
|
|
25
|
-
export declare const Forbidden: CloseEvent;
|
|
26
|
-
/**
|
|
27
|
-
* The server timed out waiting for the request.
|
|
28
|
-
*/
|
|
29
|
-
export declare const ConnectionTimeout: CloseEvent;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import * as decoding from "lib0/decoding";
|
|
3
|
-
export declare enum AuthMessageType {
|
|
4
|
-
Token = 0,
|
|
5
|
-
PermissionDenied = 1,
|
|
6
|
-
Authenticated = 2
|
|
7
|
-
}
|
|
8
|
-
export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
|
|
9
|
-
export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
|
|
10
|
-
export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: "readonly" | "read-write") => 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;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from "@hocuspocus/server";
|
|
2
|
-
export interface DatabaseConfiguration {
|
|
3
|
-
/**
|
|
4
|
-
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
5
|
-
* an array of items with Y.js-compatible binary data.
|
|
6
|
-
*/
|
|
7
|
-
fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
|
|
8
|
-
/**
|
|
9
|
-
* Pass a function to store updates in your database.
|
|
10
|
-
*/
|
|
11
|
-
store: (data: storePayload) => Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export declare class Database implements Extension {
|
|
14
|
-
/**
|
|
15
|
-
* Default configuration
|
|
16
|
-
*/
|
|
17
|
-
configuration: DatabaseConfiguration;
|
|
18
|
-
/**
|
|
19
|
-
* Constructor
|
|
20
|
-
*/
|
|
21
|
-
constructor(configuration: Partial<DatabaseConfiguration>);
|
|
22
|
-
/**
|
|
23
|
-
* Get stored data from the database.
|
|
24
|
-
*/
|
|
25
|
-
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
26
|
-
/**
|
|
27
|
-
* Store new updates in the database.
|
|
28
|
-
*/
|
|
29
|
-
onStoreDocument(data: onChangePayload): Promise<void>;
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Database.ts";
|