@hocuspocus/extension-throttle 2.13.5-rc.0 → 3.0.0-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.
Files changed (48) hide show
  1. package/dist/hocuspocus-throttle.cjs +0 -2
  2. package/dist/hocuspocus-throttle.cjs.map +1 -1
  3. package/dist/hocuspocus-throttle.esm.js.map +1 -1
  4. package/dist/packages/common/src/auth.d.ts +1 -1
  5. package/dist/packages/extension-database/src/Database.d.ts +1 -1
  6. package/dist/packages/extension-logger/src/Logger.d.ts +1 -1
  7. package/dist/packages/extension-redis/src/Redis.d.ts +4 -3
  8. package/dist/packages/extension-sqlite/src/SQLite.d.ts +2 -1
  9. package/dist/packages/extension-throttle/src/index.d.ts +2 -3
  10. package/dist/packages/extension-webhook/src/index.d.ts +3 -4
  11. package/dist/packages/provider/src/HocuspocusProvider.d.ts +4 -13
  12. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +5 -5
  13. package/dist/packages/provider/src/IncomingMessage.d.ts +3 -3
  14. package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
  15. package/dist/packages/provider/src/MessageSender.d.ts +2 -2
  16. package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
  17. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +2 -1
  18. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +2 -1
  19. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +2 -1
  20. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +2 -1
  21. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +2 -1
  22. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +2 -1
  23. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +2 -1
  24. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +2 -1
  25. package/dist/packages/provider/src/TiptapCollabProvider.d.ts +2 -1
  26. package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +2 -1
  27. package/dist/packages/provider/src/types.d.ts +12 -12
  28. package/dist/packages/server/src/ClientConnection.d.ts +6 -7
  29. package/dist/packages/server/src/Connection.d.ts +7 -9
  30. package/dist/packages/server/src/DirectConnection.d.ts +1 -1
  31. package/dist/packages/server/src/Document.d.ts +5 -5
  32. package/dist/packages/server/src/Hocuspocus.d.ts +6 -27
  33. package/dist/packages/server/src/IncomingMessage.d.ts +3 -3
  34. package/dist/packages/server/src/MessageReceiver.d.ts +5 -5
  35. package/dist/packages/server/src/OutgoingMessage.d.ts +3 -3
  36. package/dist/packages/server/src/Server.d.ts +22 -3
  37. package/dist/packages/server/src/index.d.ts +1 -0
  38. package/dist/packages/server/src/types.d.ts +7 -24
  39. package/dist/packages/server/src/util/getParameters.d.ts +1 -3
  40. package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
  41. package/dist/packages/transformer/src/Tiptap.d.ts +3 -3
  42. package/dist/packages/transformer/src/types.d.ts +1 -1
  43. package/dist/tests/utils/newHocuspocus.d.ts +2 -2
  44. package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
  45. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +4 -3
  46. package/dist/tests/utils/retryableAssertion.d.ts +1 -1
  47. package/package.json +2 -2
  48. package/src/index.ts +3 -3
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  class Throttle {
6
4
  /**
7
5
  * Constructor
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-throttle.cjs","sources":["../src/index.ts"],"sourcesContent":["import {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: 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 consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: 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\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timer\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): Boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":";;;;MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;QAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;KACzG;IAED,SAAS,GAAA;QACP,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;AACpC,SAAA;AAED,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;KACzB;IAEM,SAAS,GAAA;QACd,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;YAC1C,MAAM,aAAa,GAAG,KAAK;iBACxB,MAAM,CAAC,SAAS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G,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;;QAGpC,MAAM,0CAA0C,GAAG,mBAAmB;aACnE,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE9F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAA;QAExE,IAAI,0CAA0C,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AACnF,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAClC,YAAA,OAAO,IAAI,CAAA;AACZ,SAAA;AAED,QAAA,OAAO,KAAK,CAAA;KACb;AAED;;;AAGG;AACH,IAAA,SAAS,CAAC,IAAsB,EAAA;AAC9B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;;AAGxB,QAAA,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;AAClC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;eAClC,OAAO,CAAC,MAAM,CAAC,aAAa;AAC5B,eAAA,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;AAEF;;;;"}
1
+ {"version":3,"file":"hocuspocus-throttle.cjs","sources":["../src/index.ts"],"sourcesContent":["import type {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: 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 consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: 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\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timeout\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":";;MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;QAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;KACzG;IAED,SAAS,GAAA;AACP,QAAA,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SACpC;AAED,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;KACzB;IAEM,SAAS,GAAA;QACd,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;YAC1C,MAAM,aAAa,GAAG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AG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;;QAGpC,MAAM,0CAA0C,GAAG,mBAAmB;aACnE,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE9F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAA;QAExE,IAAI,0CAA0C,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AACnF,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAClC,YAAA,OAAO,IAAI,CAAA;SACZ;AAED,QAAA,OAAO,KAAK,CAAA;KACb;AAED;;;AAGG;AACH,IAAA,SAAS,CAAC,IAAsB,EAAA;AAC9B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;;AAGxB,QAAA,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;AAClC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;eAClC,OAAO,CAAC,MAAM,CAAC,aAAa;AAC5B,eAAA,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;AAEF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-throttle.esm.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: 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 consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: 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\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timer\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): Boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":"MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;QAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;KACzG;IAED,SAAS,GAAA;QACP,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;AACpC,SAAA;AAED,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;KACzB;IAEM,SAAS,GAAA;QACd,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;YAC1C,MAAM,aAA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AmB,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;;QAGpC,MAAM,0CAA0C,GAAG,mBAAmB;aACnE,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE9F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAA;QAExE,IAAI,0CAA0C,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AACnF,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAClC,YAAA,OAAO,IAAI,CAAA;AACZ,SAAA;AAED,QAAA,OAAO,KAAK,CAAA;KACb;AAED;;;AAGG;AACH,IAAA,SAAS,CAAC,IAAsB,EAAA;AAC9B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;;AAGxB,QAAA,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;AAClC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;eAClC,OAAO,CAAC,MAAM,CAAC,aAAa;AAC5B,eAAA,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;AAEF;;;;"}
1
+ {"version":3,"file":"hocuspocus-throttle.esm.js","sources":["../src/index.ts"],"sourcesContent":["import type {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: 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 consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: 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\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timeout\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":"MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;QAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;KACzG;IAED,SAAS,GAAA;AACP,QAAA,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SACpC;AAED,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;KACzB;IAEM,SAAS,GAAA;QACd,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAA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AAmB,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC9D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;;QAGpC,MAAM,0CAA0C,GAAG,mBAAmB;aACnE,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE9F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAA;QAExE,IAAI,0CAA0C,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AACnF,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAClC,YAAA,OAAO,IAAI,CAAA;SACZ;AAED,QAAA,OAAO,KAAK,CAAA;KACb;AAED;;;AAGG;AACH,IAAA,SAAS,CAAC,IAAsB,EAAA;AAC9B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;;AAGxB,QAAA,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;AAClC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;eAClC,OAAO,CAAC,MAAM,CAAC,aAAa;AAC5B,eAAA,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;AAEF;;;;"}
@@ -2,5 +2,5 @@ import * as encoding from 'lib0/encoding';
2
2
  import * as decoding from 'lib0/decoding';
3
3
  export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
4
  export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
- export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: 'readonly' | 'read-write') => void;
5
+ export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: "readonly" | "read-write") => void;
6
6
  export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
@@ -1,4 +1,4 @@
1
- import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
1
+ import type { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
2
2
  export interface DatabaseConfiguration {
3
3
  /**
4
4
  * Pass a Promise to retrieve updates from your database. The Promise should resolve to
@@ -1,4 +1,4 @@
1
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
1
+ import type { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
2
  export interface LoggerConfiguration {
3
3
  /**
4
4
  * Prepend all logging message with a string.
@@ -1,7 +1,8 @@
1
- /// <reference types="node" />
2
- import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
1
+ import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
2
+ import RedisClient from 'ioredis';
3
3
  import Redlock from 'redlock';
4
- import { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
4
+ import type { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
5
+ import { Debugger } from '@hocuspocus/server';
5
6
  export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
6
7
  export interface Configuration {
7
8
  /**
@@ -1,4 +1,5 @@
1
- import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
1
+ import type { DatabaseConfiguration } from '@hocuspocus/extension-database';
2
+ import { Database } from '@hocuspocus/extension-database';
2
3
  import sqlite3 from 'sqlite3';
3
4
  export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
4
5
  export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { Extension, onConnectPayload } from '@hocuspocus/server';
1
+ import type { Extension, onConnectPayload } from '@hocuspocus/server';
3
2
  export interface ThrottleConfiguration {
4
3
  throttle: number | null | false;
5
4
  consideredSeconds: number;
@@ -10,7 +9,7 @@ export declare class Throttle implements Extension {
10
9
  configuration: ThrottleConfiguration;
11
10
  connectionsByIp: Map<string, Array<number>>;
12
11
  bannedIps: Map<string, number>;
13
- cleanupInterval?: NodeJS.Timer;
12
+ cleanupInterval?: NodeJS.Timeout;
14
13
  /**
15
14
  * Constructor
16
15
  */
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
- import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
3
- import { Doc } from 'yjs';
4
- import { Transformer } from '@hocuspocus/transformer';
1
+ import type { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
2
+ import type { Doc } from 'yjs';
3
+ import type { Transformer } from '@hocuspocus/transformer';
5
4
  export declare enum Events {
6
5
  onChange = "change",
7
6
  onConnect = "connect",
@@ -3,8 +3,9 @@ import type { CloseEvent, Event, MessageEvent } from 'ws';
3
3
  import { Awareness } from 'y-protocols/awareness';
4
4
  import * as Y from 'yjs';
5
5
  import EventEmitter from './EventEmitter.js';
6
- import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
7
- import { ConstructableOutgoingMessage, WebSocketStatus, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters } from './types.js';
6
+ import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
7
+ import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
8
+ import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters } from './types.js';
8
9
  export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
9
10
  export interface CompleteHocuspocusProviderConfiguration {
10
11
  /**
@@ -81,24 +82,19 @@ export declare class HocuspocusProvider extends EventEmitter {
81
82
  subscribedToBroadcastChannel: boolean;
82
83
  isSynced: boolean;
83
84
  unsyncedChanges: number;
84
- status: WebSocketStatus;
85
85
  isAuthenticated: boolean;
86
86
  authorizedScope: string | undefined;
87
87
  mux: mutex.mutex;
88
88
  intervals: any;
89
- isConnected: boolean;
90
89
  constructor(configuration: HocuspocusProviderConfiguration);
91
- boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
92
90
  boundPageHide: () => void;
93
91
  boundOnOpen: (event: Event) => Promise<void>;
94
92
  boundOnClose: (event: CloseEvent) => void;
95
- boundOnStatus: ({ status }: onStatusParameters) => void;
96
93
  forwardConnect: (e: any) => this;
97
94
  forwardOpen: (e: any) => this;
98
95
  forwardClose: (e: any) => this;
99
96
  forwardDisconnect: (e: any) => this;
100
97
  forwardDestroy: (e: any) => this;
101
- onStatus({ status }: onStatusParameters): void;
102
98
  setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
103
99
  get document(): Y.Doc;
104
100
  get awareness(): Awareness | null;
@@ -122,7 +118,7 @@ export declare class HocuspocusProvider extends EventEmitter {
122
118
  set synced(state: boolean);
123
119
  receiveStateless(payload: string): void;
124
120
  get isAuthenticationRequired(): boolean;
125
- connect(): Promise<any>;
121
+ connect(): Promise<void>;
126
122
  disconnect(): void;
127
123
  onOpen(event: Event): Promise<void>;
128
124
  getToken(): Promise<string | null>;
@@ -133,10 +129,5 @@ export declare class HocuspocusProvider extends EventEmitter {
133
129
  destroy(): void;
134
130
  permissionDeniedHandler(reason: string): void;
135
131
  authenticatedHandler(scope: string): void;
136
- get broadcastChannel(): string;
137
- broadcastChannelSubscriber(data: ArrayBuffer): void;
138
- subscribeToBroadcastChannel(): void;
139
- disconnectBroadcastChannel(): void;
140
- broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
141
132
  setAwarenessField(key: string, value: any): void;
142
133
  }
@@ -1,8 +1,8 @@
1
- import type { MessageEvent } from 'ws';
2
- import { Event } from 'ws';
1
+ import type { MessageEvent, Event } from 'ws';
3
2
  import EventEmitter from './EventEmitter.js';
4
- import { HocuspocusProvider } from './HocuspocusProvider.js';
5
- import { WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
3
+ import type { HocuspocusProvider } from './HocuspocusProvider.js';
4
+ import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
5
+ import { WebSocketStatus } from './types.js';
6
6
  export type HocusPocusWebSocket = WebSocket & {
7
7
  identifier: string;
8
8
  };
@@ -102,7 +102,7 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
102
102
  receivedOnStatusPayload?: onStatusParameters | undefined;
103
103
  onOpen(event: Event): Promise<void>;
104
104
  onStatus(data: onStatusParameters): Promise<void>;
105
- attach(provider: HocuspocusProvider): Promise<any> | undefined;
105
+ attach(provider: HocuspocusProvider): void;
106
106
  detach(provider: HocuspocusProvider): void;
107
107
  setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
108
108
  cancelWebsocketRetry?: () => void;
@@ -1,6 +1,6 @@
1
- import { Decoder } from 'lib0/decoding';
2
- import { Encoder } from 'lib0/encoding';
3
- import { MessageType } from './types.js';
1
+ import type { Decoder } from 'lib0/decoding';
2
+ import type { Encoder } from 'lib0/encoding';
3
+ import type { MessageType } from './types.js';
4
4
  export declare class IncomingMessage {
5
5
  data: any;
6
6
  encoder: Encoder;
@@ -1,5 +1,5 @@
1
- import { HocuspocusProvider } from './HocuspocusProvider.js';
2
- import { IncomingMessage } from './IncomingMessage.js';
1
+ import type { HocuspocusProvider } from './HocuspocusProvider.js';
2
+ import type { IncomingMessage } from './IncomingMessage.js';
3
3
  export declare class MessageReceiver {
4
4
  message: IncomingMessage;
5
5
  broadcasted: boolean;
@@ -1,5 +1,5 @@
1
- import { Encoder } from 'lib0/encoding';
2
- import { ConstructableOutgoingMessage } from './types.js';
1
+ import type { Encoder } from 'lib0/encoding';
2
+ import type { ConstructableOutgoingMessage } from './types.js';
3
3
  export declare class MessageSender {
4
4
  encoder: Encoder;
5
5
  message: any;
@@ -1,5 +1,5 @@
1
- import { Encoder } from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.js';
1
+ import type { Encoder } from 'lib0/encoding';
2
+ import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.js';
3
3
  export declare class OutgoingMessage implements OutgoingMessageInterface {
4
4
  encoder: Encoder;
5
5
  type?: MessageType;
@@ -1,4 +1,5 @@
1
- import { MessageType, OutgoingMessageArguments } from '../types.js';
1
+ import type { OutgoingMessageArguments } from '../types.js';
2
+ import { MessageType } from '../types.js';
2
3
  import { OutgoingMessage } from '../OutgoingMessage.js';
3
4
  export declare class AuthenticationMessage extends OutgoingMessage {
4
5
  type: MessageType;
@@ -1,5 +1,6 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments } from '../types.js';
2
+ import type { OutgoingMessageArguments } from '../types.js';
3
+ import { MessageType } from '../types.js';
3
4
  import { OutgoingMessage } from '../OutgoingMessage.js';
4
5
  export declare class AwarenessMessage extends OutgoingMessage {
5
6
  type: MessageType;
@@ -1,5 +1,6 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments } from '../types.js';
2
+ import type { OutgoingMessageArguments } from '../types.js';
3
+ import { MessageType } from '../types.js';
3
4
  import { OutgoingMessage } from '../OutgoingMessage.js';
4
5
  export declare class CloseMessage extends OutgoingMessage {
5
6
  type: MessageType;
@@ -1,5 +1,6 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments } from '../types.js';
2
+ import type { OutgoingMessageArguments } from '../types.js';
3
+ import { MessageType } from '../types.js';
3
4
  import { OutgoingMessage } from '../OutgoingMessage.js';
4
5
  export declare class QueryAwarenessMessage extends OutgoingMessage {
5
6
  type: MessageType;
@@ -1,4 +1,5 @@
1
- import { MessageType, OutgoingMessageArguments } from '../types.js';
1
+ import type { OutgoingMessageArguments } from '../types.js';
2
+ import { MessageType } from '../types.js';
2
3
  import { OutgoingMessage } from '../OutgoingMessage.js';
3
4
  export declare class StatelessMessage extends OutgoingMessage {
4
5
  type: MessageType;
@@ -1,5 +1,6 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments } from '../types.js';
2
+ import type { OutgoingMessageArguments } from '../types.js';
3
+ import { MessageType } from '../types.js';
3
4
  import { OutgoingMessage } from '../OutgoingMessage.js';
4
5
  export declare class SyncStepOneMessage extends OutgoingMessage {
5
6
  type: MessageType;
@@ -1,5 +1,6 @@
1
1
  import * as encoding from 'lib0/encoding';
2
- import { MessageType, OutgoingMessageArguments } from '../types.js';
2
+ import type { OutgoingMessageArguments } from '../types.js';
3
+ import { MessageType } from '../types.js';
3
4
  import { OutgoingMessage } from '../OutgoingMessage.js';
4
5
  export declare class SyncStepTwoMessage extends OutgoingMessage {
5
6
  type: MessageType;
@@ -1,4 +1,5 @@
1
- import { MessageType, OutgoingMessageArguments } from '../types.js';
1
+ import type { OutgoingMessageArguments } from '../types.js';
2
+ import { MessageType } from '../types.js';
2
3
  import { OutgoingMessage } from '../OutgoingMessage.js';
3
4
  export declare class UpdateMessage extends OutgoingMessage {
4
5
  type: MessageType;
@@ -1,6 +1,7 @@
1
1
  import type { AbstractType, YArrayEvent } from 'yjs';
2
2
  import * as Y from 'yjs';
3
- import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
3
+ import type { HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
4
+ import { HocuspocusProvider } from './HocuspocusProvider.js';
4
5
  import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
5
6
  import type { TCollabComment, TCollabThread, THistoryVersion } from './types.js';
6
7
  export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>) & Pick<AdditionalTiptapCollabProviderConfiguration, 'user'>;
@@ -1,4 +1,5 @@
1
- import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
1
+ import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
2
+ import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
2
3
  export type TiptapCollabProviderWebsocketConfiguration = Partial<CompleteHocuspocusProviderWebsocketConfiguration> & AdditionalTiptapCollabProviderWebsocketConfiguration;
3
4
  export interface AdditionalTiptapCollabProviderWebsocketConfiguration {
4
5
  /**
@@ -1,16 +1,16 @@
1
- import { Encoder } from 'lib0/encoding';
1
+ import type { Encoder } from 'lib0/encoding';
2
2
  import type { Event, MessageEvent } from 'ws';
3
- import { Awareness } from 'y-protocols/awareness';
4
- import * as Y from 'yjs';
5
- import { CloseEvent } from '@hocuspocus/common';
6
- import { IncomingMessage } from './IncomingMessage.js';
7
- import { OutgoingMessage } from './OutgoingMessage.js';
8
- import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
9
- import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js';
10
- import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js';
11
- import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js';
12
- import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js';
13
- import { UpdateMessage } from './OutgoingMessages/UpdateMessage.js';
3
+ import type { Awareness } from 'y-protocols/awareness';
4
+ import type * as Y from 'yjs';
5
+ import type { CloseEvent } from '@hocuspocus/common';
6
+ import type { IncomingMessage } from './IncomingMessage.js';
7
+ import type { OutgoingMessage } from './OutgoingMessage.js';
8
+ import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
9
+ import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js';
10
+ import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js';
11
+ import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js';
12
+ import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js';
13
+ import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.js';
14
14
  export declare enum MessageType {
15
15
  Sync = 0,
16
16
  Awareness = 1,
@@ -1,10 +1,9 @@
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';
1
+ import type { IncomingMessage } from 'http';
2
+ import type WebSocket from 'ws';
3
+ import type { Debugger } from './Debugger.js';
4
+ import type Document from './Document.js';
5
+ import type { Hocuspocus } from './Hocuspocus.js';
6
+ import type { onDisconnectPayload } from './types.js';
8
7
  /**
9
8
  * The `ClientConnection` class is responsible for handling an incoming WebSocket
10
9
  *
@@ -1,12 +1,10 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { IncomingMessage as HTTPIncomingMessage } from 'http';
1
+ import type { IncomingMessage as HTTPIncomingMessage } from 'http';
4
2
  import AsyncLock from 'async-lock';
5
- import WebSocket from 'ws';
6
- import { CloseEvent } from '@hocuspocus/common';
7
- import Document from './Document.js';
8
- import { Debugger } from './Debugger.js';
9
- import { onStatelessPayload } from './types.js';
3
+ import type WebSocket from 'ws';
4
+ import type { CloseEvent } from '@hocuspocus/common';
5
+ import type Document from './Document.js';
6
+ import type { Debugger } from './Debugger.js';
7
+ import type { onStatelessPayload } from './types.js';
10
8
  export declare class Connection {
11
9
  webSocket: WebSocket;
12
10
  context: any;
@@ -18,7 +16,7 @@ export declare class Connection {
18
16
  callbacks: any;
19
17
  socketId: string;
20
18
  lock: AsyncLock;
21
- readOnly: Boolean;
19
+ readOnly: boolean;
22
20
  logger: Debugger;
23
21
  /**
24
22
  * Constructor.
@@ -1,4 +1,4 @@
1
- import Document from './Document.js';
1
+ import type Document from './Document.js';
2
2
  import type { Hocuspocus } from './Hocuspocus.js';
3
3
  import type { DirectConnection as DirectConnectionInterface } from './types.js';
4
4
  export declare class DirectConnection implements DirectConnectionInterface {
@@ -1,9 +1,9 @@
1
- import WebSocket from 'ws';
1
+ import type WebSocket from 'ws';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
- import { mutex } from 'lib0/mutex.js';
5
- import Connection from './Connection.js';
6
- import { Debugger } from './Debugger.js';
4
+ import type { mutex } from 'lib0/mutex.js';
5
+ import type Connection from './Connection.js';
6
+ import type { Debugger } from './Debugger.js';
7
7
  export declare class Document extends Doc {
8
8
  awareness: Awareness;
9
9
  callbacks: {
@@ -23,7 +23,7 @@ export declare class Document extends Doc {
23
23
  /**
24
24
  * Constructor.
25
25
  */
26
- constructor(name: string, logger?: Debugger, yDocOptions?: {});
26
+ constructor(name: string, logger?: Debugger, yDocOptions?: object);
27
27
  /**
28
28
  * Check if the Document (XMLFragment or Map) is empty
29
29
  */
@@ -1,15 +1,12 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- import WebSocket, { AddressInfo } from 'ws';
4
- import { Server as HocuspocusServer } from './Server.js';
1
+ import type { IncomingMessage } from 'http';
2
+ import type WebSocket from 'ws';
3
+ import type { Server } from './Server.js';
5
4
  import { Debugger } from './Debugger.js';
6
5
  import { DirectConnection } from './DirectConnection.js';
7
6
  import Document from './Document.js';
8
- import { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onListenPayload, onStoreDocumentPayload } from './types.js';
7
+ import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.js';
9
8
  export declare const defaultConfiguration: {
10
9
  name: null;
11
- port: number;
12
- address: string;
13
10
  timeout: number;
14
11
  debounce: number;
15
12
  maxDebounce: number;
@@ -19,16 +16,12 @@ export declare const defaultConfiguration: {
19
16
  gcFilter: () => boolean;
20
17
  };
21
18
  unloadImmediately: boolean;
22
- stopOnSignals: boolean;
23
19
  };
24
- /**
25
- * Hocuspocus Server
26
- */
27
20
  export declare class Hocuspocus {
28
21
  configuration: Configuration;
29
22
  loadingDocuments: Map<string, Promise<Document>>;
30
23
  documents: Map<string, Document>;
31
- server?: HocuspocusServer;
24
+ server?: Server;
32
25
  debugger: Debugger;
33
26
  debouncer: {
34
27
  debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any;
@@ -37,19 +30,10 @@ export declare class Hocuspocus {
37
30
  };
38
31
  constructor(configuration?: Partial<Configuration>);
39
32
  /**
40
- * Configure the server
33
+ * Configure Hocuspocus
41
34
  */
42
35
  configure(configuration: Partial<Configuration>): Hocuspocus;
43
36
  get requiresAuthentication(): boolean;
44
- /**
45
- * Start the server
46
- */
47
- listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
48
- get address(): AddressInfo;
49
- get URL(): string;
50
- get webSocketURL(): string;
51
- get httpURL(): string;
52
- private showStartScreen;
53
37
  /**
54
38
  * Get the total number of active documents
55
39
  */
@@ -62,10 +46,6 @@ export declare class Hocuspocus {
62
46
  * Force close one or more connections
63
47
  */
64
48
  closeConnections(documentName?: string): void;
65
- /**
66
- * Destroy the server
67
- */
68
- destroy(): Promise<any>;
69
49
  /**
70
50
  * The `handleConnection` method receives incoming WebSocket connections,
71
51
  * runs all hooks:
@@ -104,4 +84,3 @@ export declare class Hocuspocus {
104
84
  getMessageLogs(): any[];
105
85
  openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>;
106
86
  }
107
- export declare const Server: Hocuspocus;
@@ -1,6 +1,6 @@
1
- import { Decoder } from 'lib0/decoding';
2
- import { Encoder } from 'lib0/encoding';
3
- import { MessageType } from './types.js';
1
+ import type { Decoder } from 'lib0/decoding';
2
+ import type { Encoder } from 'lib0/encoding';
3
+ import type { MessageType } from './types.js';
4
4
  export declare class IncomingMessage {
5
5
  /**
6
6
  * Access to the received message.
@@ -1,13 +1,13 @@
1
- import Connection from './Connection.js';
2
- import { Debugger } from './Debugger.js';
3
- import Document from './Document.js';
4
- import { IncomingMessage } from './IncomingMessage.js';
1
+ import type Connection from './Connection.js';
2
+ import type { Debugger } from './Debugger.js';
3
+ import type Document from './Document.js';
4
+ import type { IncomingMessage } from './IncomingMessage.js';
5
5
  export declare class MessageReceiver {
6
6
  message: IncomingMessage;
7
7
  logger: Debugger;
8
8
  defaultTransactionOrigin?: string;
9
9
  constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string);
10
10
  apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
11
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
12
12
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
13
13
  }
@@ -1,6 +1,6 @@
1
- import { Encoder } from 'lib0/encoding';
2
- import { Awareness } from 'y-protocols/awareness';
3
- import Document from './Document.js';
1
+ import type { Encoder } from 'lib0/encoding';
2
+ import type { Awareness } from 'y-protocols/awareness';
3
+ import type Document from './Document.js';
4
4
  export declare class OutgoingMessage {
5
5
  encoder: Encoder;
6
6
  type?: number;
@@ -1,13 +1,32 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage, Server as HTTPServer, ServerResponse } from 'http';
1
+ import type { IncomingMessage, Server as HTTPServer, ServerResponse } from 'http';
2
+ import type { AddressInfo } from 'ws';
3
3
  import { WebSocketServer } from 'ws';
4
4
  import { Hocuspocus } from './Hocuspocus.js';
5
+ import type { Configuration } from './types';
6
+ export interface ServerConfiguration extends Configuration {
7
+ port?: number;
8
+ address?: string;
9
+ stopOnSignals?: boolean;
10
+ }
11
+ export declare const defaultServerConfiguration: {
12
+ port: number;
13
+ address: string;
14
+ stopOnSignals: boolean;
15
+ };
5
16
  export declare class Server {
6
17
  httpServer: HTTPServer;
7
18
  webSocketServer: WebSocketServer;
8
19
  hocuspocus: Hocuspocus;
9
- constructor(hocuspocus: Hocuspocus);
20
+ configuration: ServerConfiguration;
21
+ constructor(configuration?: Partial<ServerConfiguration>);
10
22
  setupWebsocketConnection: () => void;
11
23
  setupHttpUpgrade: () => void;
12
24
  requestHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
25
+ listen(port?: number, callback?: any): Promise<Hocuspocus>;
26
+ get address(): AddressInfo;
27
+ destroy(): Promise<any>;
28
+ get URL(): string;
29
+ get webSocketURL(): string;
30
+ get httpURL(): string;
31
+ private showStartScreen;
13
32
  }
@@ -5,5 +5,6 @@ export * from './Hocuspocus.js';
5
5
  export * from './IncomingMessage.js';
6
6
  export * from './MessageReceiver.js';
7
7
  export * from './OutgoingMessage.js';
8
+ export * from './Server.js';
8
9
  export * from './types.js';
9
10
  export * from './util/debounce.js';
@@ -1,19 +1,16 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
5
- import { URLSearchParams } from 'url';
6
- import { Awareness } from 'y-protocols/awareness';
7
- import Connection from './Connection.js';
8
- import Document from './Document.js';
9
- import { Hocuspocus } from './Hocuspocus.js';
1
+ import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
2
+ import type { URLSearchParams } from 'url';
3
+ import type { Awareness } from 'y-protocols/awareness';
4
+ import type Connection from './Connection.js';
5
+ import type Document from './Document.js';
6
+ import type { Hocuspocus } from './Hocuspocus.js';
10
7
  export declare enum MessageType {
11
8
  Unknown = -1,
12
9
  Sync = 0,
13
10
  Awareness = 1,
14
11
  Auth = 2,
15
12
  QueryAwareness = 3,
16
- SyncReply = 4,
13
+ SyncReply = 4,// same as Sync, but won't trigger another 'SyncStep1'
17
14
  Stateless = 5,
18
15
  BroadcastStateless = 6,
19
16
  CLOSE = 7,
@@ -85,14 +82,6 @@ export interface Configuration extends Extension {
85
82
  * A list of hocuspocus extensions.
86
83
  */
87
84
  extensions: Array<Extension>;
88
- /**
89
- * The port which the server listens on.
90
- */
91
- port?: number;
92
- /**
93
- * The address which the server listens on.
94
- */
95
- address?: string;
96
85
  /**
97
86
  * Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
98
87
  */
@@ -118,12 +107,6 @@ export interface Configuration extends Extension {
118
107
  * your onStoreDocument is rate-limited.
119
108
  */
120
109
  unloadImmediately: boolean;
121
- /**
122
- * the server will gracefully stop if SIGINT, SIGQUIT or SIGTERM is received.
123
- *
124
- * Set this to false if you don't want that.
125
- */
126
- stopOnSignals: boolean;
127
110
  /**
128
111
  * options to pass to the ydoc document
129
112
  */
@@ -1,6 +1,4 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { IncomingMessage } from 'http';
1
+ import type { IncomingMessage } from 'http';
4
2
  import { URLSearchParams } from 'url';
5
3
  /**
6
4
  * Get parameters by the given request
@@ -1,6 +1,6 @@
1
1
  import { Doc } from 'yjs';
2
2
  import { Schema } from '@tiptap/pm/model';
3
- import { Transformer } from './types.js';
3
+ import type { Transformer } from './types.js';
4
4
  declare class Prosemirror implements Transformer {
5
5
  defaultSchema: Schema;
6
6
  schema(schema: Schema): Prosemirror;
@@ -1,6 +1,6 @@
1
- import { Doc } from 'yjs';
2
- import { Extensions } from '@tiptap/core';
3
- import { Transformer } from './types.js';
1
+ import type { Doc } from 'yjs';
2
+ import type { Extensions } from '@tiptap/core';
3
+ import type { Transformer } from './types.js';
4
4
  export declare class Tiptap implements Transformer {
5
5
  defaultExtensions: Extensions;
6
6
  extensions(extensions: Extensions): Tiptap;
@@ -1,4 +1,4 @@
1
- import { Doc } from 'yjs';
1
+ import type { Doc } from 'yjs';
2
2
  export interface Transformer {
3
3
  fromYdoc: (document: Doc, fieldName?: string | Array<string>) => any;
4
4
  toYdoc: (document: any, fieldName: string) => Doc;
@@ -1,2 +1,2 @@
1
- import { Hocuspocus, Configuration } from '@hocuspocus/server';
2
- export declare const newHocuspocus: (options?: Partial<Configuration>) => Promise<Hocuspocus>;
1
+ import type { ServerConfiguration } from '@hocuspocus/server';
2
+ export declare const newHocuspocus: (options?: Partial<ServerConfiguration>) => Promise<import("@hocuspocus/server").Hocuspocus>;
@@ -1,3 +1,3 @@
1
- import { HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
- import { Hocuspocus } from '@hocuspocus/server';
1
+ import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
+ import type { Hocuspocus } from '@hocuspocus/server';
3
3
  export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
@@ -1,3 +1,4 @@
1
- import { HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
- import { Hocuspocus } from '@hocuspocus/server';
3
- export declare const newHocuspocusProviderWebsocket: (server: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, 'url'>>) => HocuspocusProviderWebsocket;
1
+ import type { HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
+ import { HocuspocusProviderWebsocket } from '@hocuspocus/provider';
3
+ import type { Hocuspocus } from '@hocuspocus/server';
4
+ export declare const newHocuspocusProviderWebsocket: (hocuspocus: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, "url">>) => HocuspocusProviderWebsocket;
@@ -1,2 +1,2 @@
1
- import { ExecutionContext } from 'ava';
1
+ import type { ExecutionContext } from 'ava';
2
2
  export declare const retryableAssertion: (t: ExecutionContext, recoverableTry: (tt: ExecutionContext) => void) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-throttle",
3
- "version": "2.13.5-rc.0",
3
+ "version": "3.0.0-rc.0",
4
4
  "description": "hocuspocus throttle extension",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@hocuspocus/server": "^2.13.5-rc.0"
31
+ "@hocuspocus/server": "^3.0.0-rc.0"
32
32
  },
33
33
  "gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d"
34
34
  }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  Extension,
3
3
  onConnectPayload,
4
4
  } from '@hocuspocus/server'
@@ -23,7 +23,7 @@ export class Throttle implements Extension {
23
23
 
24
24
  bannedIps: Map<string, number> = new Map()
25
25
 
26
- cleanupInterval?: NodeJS.Timer
26
+ cleanupInterval?: NodeJS.Timeout
27
27
 
28
28
  /**
29
29
  * Constructor
@@ -73,7 +73,7 @@ export class Throttle implements Extension {
73
73
  * Throttle requests
74
74
  * @private
75
75
  */
76
- private throttle(ip: string): Boolean {
76
+ private throttle(ip: string): boolean {
77
77
  if (!this.configuration.throttle) {
78
78
  return false
79
79
  }