@hocuspocus/extension-throttle 1.0.0-alpha.9 → 1.0.0-beta.2

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 (121) hide show
  1. package/dist/{hocuspocus-throttle.js → hocuspocus-throttle.cjs} +9 -18
  2. package/dist/hocuspocus-throttle.cjs.map +1 -0
  3. package/dist/hocuspocus-throttle.esm.js +8 -17
  4. package/dist/hocuspocus-throttle.esm.js.map +1 -1
  5. package/dist/packages/common/src/CloseEvents.d.ts +23 -0
  6. package/dist/packages/common/src/auth.d.ts +6 -0
  7. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
  8. package/dist/packages/common/src/index.d.ts +4 -0
  9. package/dist/packages/common/src/types.d.ts +10 -0
  10. package/dist/packages/extension-database/src/Database.d.ts +30 -0
  11. package/dist/packages/extension-database/src/index.d.ts +1 -0
  12. package/dist/packages/extension-logger/src/Logger.d.ts +67 -0
  13. package/dist/packages/extension-logger/src/index.d.ts +1 -0
  14. package/dist/packages/{monitor → extension-monitor}/src/Collector.d.ts +4 -5
  15. package/dist/packages/{monitor → extension-monitor}/src/Dashboard.d.ts +2 -2
  16. package/dist/packages/{monitor → extension-monitor}/src/Storage.d.ts +0 -0
  17. package/dist/packages/{monitor → extension-monitor}/src/index.d.ts +3 -5
  18. package/dist/packages/extension-redis/src/Redis.d.ts +98 -0
  19. package/dist/packages/extension-redis/src/index.d.ts +1 -0
  20. package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
  21. package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
  22. package/dist/packages/extension-throttle/src/index.d.ts +24 -0
  23. package/dist/packages/{webhook → extension-webhook}/src/index.d.ts +5 -11
  24. package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
  25. package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +11 -0
  26. package/dist/packages/provider/src/HocuspocusProvider.d.ts +163 -0
  27. package/dist/packages/provider/src/IncomingMessage.d.ts +14 -0
  28. package/dist/packages/provider/src/MessageReceiver.d.ts +13 -0
  29. package/dist/packages/provider/src/MessageSender.d.ts +10 -0
  30. package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
  31. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -0
  32. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -0
  33. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -0
  34. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -0
  35. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -0
  36. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -0
  37. package/dist/packages/provider/src/index.d.ts +3 -0
  38. package/dist/packages/provider/src/types.d.ts +77 -0
  39. package/dist/packages/server/src/Connection.d.ts +27 -7
  40. package/dist/packages/server/src/Debugger.d.ts +14 -0
  41. package/dist/packages/server/src/Document.d.ts +11 -5
  42. package/dist/packages/server/src/Hocuspocus.d.ts +63 -17
  43. package/dist/packages/server/src/IncomingMessage.d.ts +11 -7
  44. package/dist/packages/server/src/MessageReceiver.d.ts +13 -0
  45. package/dist/packages/server/src/OutgoingMessage.d.ts +6 -0
  46. package/dist/packages/server/src/index.d.ts +6 -0
  47. package/dist/packages/server/src/types.d.ts +181 -23
  48. package/dist/{demos/server/src/create-document.d.ts → playground/backend/src/default.d.ts} +0 -0
  49. package/dist/{demos/server → playground/backend}/src/express.d.ts +0 -0
  50. package/dist/{demos/server/src/minimal.d.ts → playground/backend/src/koa.d.ts} +0 -0
  51. package/dist/{demos/server/src/monitor.d.ts → playground/backend/src/load-document.d.ts} +0 -0
  52. package/dist/{demos/server/src/webhook.d.ts → playground/backend/src/monitor.d.ts} +0 -0
  53. package/dist/playground/backend/src/redis.d.ts +1 -0
  54. package/dist/playground/backend/src/slow.d.ts +1 -0
  55. package/dist/playground/backend/src/webhook.d.ts +1 -0
  56. package/dist/tests/extension-database/fetch.d.ts +1 -0
  57. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  58. package/dist/tests/extension-redis/closeConnections.d.ts +1 -0
  59. package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -0
  60. package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -0
  61. package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
  62. package/dist/tests/extension-redis/onChange.d.ts +1 -0
  63. package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -0
  64. package/dist/tests/extension-throttle/configuration.d.ts +1 -0
  65. package/dist/tests/provider/configuration.d.ts +1 -0
  66. package/dist/tests/provider/observe.d.ts +1 -0
  67. package/dist/tests/provider/observeDeep.d.ts +1 -0
  68. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  69. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  70. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  71. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  72. package/dist/tests/provider/onClose.d.ts +1 -0
  73. package/dist/tests/provider/onConnect.d.ts +1 -0
  74. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  75. package/dist/tests/provider/onMessage.d.ts +1 -0
  76. package/dist/tests/provider/onOpen.d.ts +1 -0
  77. package/dist/tests/provider/onSynced.d.ts +1 -0
  78. package/dist/tests/server/address.d.ts +1 -0
  79. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  80. package/dist/tests/server/beforeHandleMessage.d.ts +1 -0
  81. package/dist/tests/server/closeConnections.d.ts +1 -0
  82. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  83. package/dist/tests/server/getDocumentName.d.ts +1 -0
  84. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  85. package/dist/tests/server/getMessageLogs.d.ts +1 -0
  86. package/dist/tests/server/listen.d.ts +1 -0
  87. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  88. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  89. package/dist/tests/server/onChange.d.ts +1 -0
  90. package/dist/tests/server/onConfigure.d.ts +1 -0
  91. package/dist/tests/server/onConnect.d.ts +1 -0
  92. package/dist/tests/server/onDestroy.d.ts +1 -0
  93. package/dist/tests/server/onDisconnect.d.ts +1 -0
  94. package/dist/tests/server/onListen.d.ts +1 -0
  95. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  96. package/dist/tests/server/onRequest.d.ts +1 -0
  97. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  98. package/dist/tests/server/onUpgrade.d.ts +1 -0
  99. package/dist/tests/server/requiresAuthentication.d.ts +1 -0
  100. package/dist/tests/server/websocketError.d.ts +1 -0
  101. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
  102. package/dist/tests/utils/createDirectory.d.ts +1 -0
  103. package/dist/tests/utils/flushRedis.d.ts +1 -0
  104. package/dist/tests/utils/index.d.ts +8 -0
  105. package/dist/tests/utils/newHocuspocus.d.ts +2 -0
  106. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
  107. package/dist/tests/utils/randomInteger.d.ts +1 -0
  108. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
  109. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  110. package/dist/tests/utils/retryableAssertion.d.ts +2 -0
  111. package/dist/tests/utils/sleep.d.ts +1 -0
  112. package/package.json +13 -8
  113. package/src/index.ts +12 -33
  114. package/CHANGELOG.md +0 -67
  115. package/dist/hocuspocus-throttle.js.map +0 -1
  116. package/dist/packages/logger/src/index.d.ts +0 -13
  117. package/dist/packages/redis/src/Redis.d.ts +0 -22
  118. package/dist/packages/redis/src/RedisCluster.d.ts +0 -4
  119. package/dist/packages/redis/src/index.d.ts +0 -2
  120. package/dist/packages/rocksdb/src/index.d.ts +0 -30
  121. package/dist/packages/throttle/src/index.d.ts +0 -28
@@ -3,13 +3,20 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  class Throttle {
6
- constructor() {
6
+ /**
7
+ * Constructor
8
+ */
9
+ constructor(configuration) {
7
10
  this.configuration = {
8
11
  throttle: 15,
9
12
  banTime: 5,
10
13
  };
11
14
  this.connectionsByIp = new Map();
12
15
  this.bannedIps = new Map();
16
+ this.configuration = {
17
+ ...this.configuration,
18
+ ...configuration,
19
+ };
13
20
  }
14
21
  /**
15
22
  * Throttle requests
@@ -51,23 +58,7 @@ class Throttle {
51
58
  // throttle the connection
52
59
  return this.throttle(ip) ? Promise.reject() : Promise.resolve();
53
60
  }
54
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
55
- async onCreateDocument(data) { }
56
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
57
- async onChange(data) { }
58
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
59
- async onDisconnect(data) { }
60
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
61
- async onUpgrade(data) { }
62
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
63
- async onRequest(data) { }
64
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
65
- async onListen(data) { }
66
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
67
- async onDestroy(data) { }
68
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
69
- async onConfigure(data) { }
70
61
  }
71
62
 
72
63
  exports.Throttle = Throttle;
73
- //# sourceMappingURL=hocuspocus-throttle.js.map
64
+ //# sourceMappingURL=hocuspocus-throttle.cjs.map
@@ -0,0 +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,\n banTime: number,\n}\n\nexport class Throttle implements Extension {\n\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\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 const bannedAt = this.bannedIps.get(ip) || 0\n\n if (Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))) {\n return true\n }\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 minute\n const previousConnectionsInTheLastMinute = previousConnections\n .filter(timestamp => timestamp + (60 * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheLastMinute)\n\n if (previousConnectionsInTheLastMinute.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":";;;;MAUa,QAAQ,CAAA;AAWnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAZ1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;SACX,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAMxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;;AAGG;AACK,IAAA,QAAQ,CAAC,EAAU,EAAA;AACzB,QAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAA,OAAO,KAAK,CAAA;AACb,SAAA;AAED,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QAE5C,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE;AACtE,YAAA,OAAO,IAAI,CAAA;AACZ,SAAA;AAED,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;;AAGzB,QAAA,MAAM,mBAAmB,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,kCAAkC,GAAG,mBAAmB;AAC3D,aAAA,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE5D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,kCAAkC,CAAC,CAAA;QAEhE,IAAI,kCAAkC,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AAC3E,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,11 +1,18 @@
1
1
  class Throttle {
2
- constructor() {
2
+ /**
3
+ * Constructor
4
+ */
5
+ constructor(configuration) {
3
6
  this.configuration = {
4
7
  throttle: 15,
5
8
  banTime: 5,
6
9
  };
7
10
  this.connectionsByIp = new Map();
8
11
  this.bannedIps = new Map();
12
+ this.configuration = {
13
+ ...this.configuration,
14
+ ...configuration,
15
+ };
9
16
  }
10
17
  /**
11
18
  * Throttle requests
@@ -47,22 +54,6 @@ class Throttle {
47
54
  // throttle the connection
48
55
  return this.throttle(ip) ? Promise.reject() : Promise.resolve();
49
56
  }
50
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
51
- async onCreateDocument(data) { }
52
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
53
- async onChange(data) { }
54
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
55
- async onDisconnect(data) { }
56
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
57
- async onUpgrade(data) { }
58
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
59
- async onRequest(data) { }
60
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
61
- async onListen(data) { }
62
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
63
- async onDestroy(data) { }
64
- // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function
65
- async onConfigure(data) { }
66
57
  }
67
58
 
68
59
  export { Throttle };
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-throttle.esm.js","sources":["../src/index.ts"],"sourcesContent":["import {\n Extension,\n onChangePayload,\n onConfigurePayload,\n onConnectPayload,\n onCreateDocumentPayload,\n onDestroyPayload,\n onDisconnectPayload,\n onListenPayload,\n onRequestPayload,\n onUpgradePayload,\n} from '@hocuspocus/server'\n\nexport interface Configuration {\n throttle: number | null | false,\n banTime: number,\n}\n\nexport class Throttle implements Extension {\n\n configuration: Configuration = {\n throttle: 15,\n banTime: 5,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\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 const bannedAt = this.bannedIps.get(ip) || 0\n\n if (Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))) {\n return true\n }\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 minute\n const previousConnectionsInTheLastMinute = previousConnections\n .filter(timestamp => timestamp + (60 * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheLastMinute)\n\n if (previousConnectionsInTheLastMinute.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 // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onCreateDocument(data: onCreateDocumentPayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onChange(data: onChangePayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onDisconnect(data: onDisconnectPayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onUpgrade(data: onUpgradePayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onRequest(data: onRequestPayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onListen(data: onListenPayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onDestroy(data: onDestroyPayload) {}\n\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n async onConfigure(data: onConfigurePayload) {}\n}\n"],"names":[],"mappings":"MAkBa,QAAQ;IAArB;QAEE,kBAAa,GAAkB;YAC7B,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,CAAC;SACX,CAAA;QAED,oBAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;QAEvD,cAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;KA6E3C;;;;;IAvES,QAAQ,CAAC,EAAU;QACzB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAChC,OAAO,KAAK,CAAA;SACb;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QAE5C,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE;YACtE,OAAO,IAAI,CAAA;SACZ;QAED,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;;QAGzB,MAAM,mBAAmB,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,kCAAkC,GAAG,mBAAmB;aAC3D,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE5D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,kCAAkC,CAAC,CAAA;QAEhE,IAAI,kCAAkC,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC3E,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;YAClC,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,KAAK,CAAA;KACb;;;;;IAMD,SAAS,CAAC,IAAsB;QAC9B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;;QAGxB,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;eAClC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;eAClC,OAAO,CAAC,MAAM,CAAC,aAAa;eAC5B,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;;IAGD,MAAM,gBAAgB,CAAC,IAA6B,KAAI;;IAGxD,MAAM,QAAQ,CAAC,IAAqB,KAAI;;IAGxC,MAAM,YAAY,CAAC,IAAyB,KAAI;;IAGhD,MAAM,SAAS,CAAC,IAAsB,KAAI;;IAG1C,MAAM,SAAS,CAAC,IAAsB,KAAI;;IAG1C,MAAM,QAAQ,CAAC,IAAqB,KAAI;;IAGxC,MAAM,SAAS,CAAC,IAAsB,KAAI;;IAG1C,MAAM,WAAW,CAAC,IAAwB,KAAI;;;;;"}
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,\n banTime: number,\n}\n\nexport class Throttle implements Extension {\n\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\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 const bannedAt = this.bannedIps.get(ip) || 0\n\n if (Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))) {\n return true\n }\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 minute\n const previousConnectionsInTheLastMinute = previousConnections\n .filter(timestamp => timestamp + (60 * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheLastMinute)\n\n if (previousConnectionsInTheLastMinute.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":"MAUa,QAAQ,CAAA;AAWnB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAZ1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;SACX,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAMxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;KACF;AAED;;;AAGG;AACK,IAAA,QAAQ,CAAC,EAAU,EAAA;AACzB,QAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AAChC,YAAA,OAAO,KAAK,CAAA;AACb,SAAA;AAED,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QAE5C,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE;AACtE,YAAA,OAAO,IAAI,CAAA;AACZ,SAAA;AAED,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;;AAGzB,QAAA,MAAM,mBAAmB,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,kCAAkC,GAAG,mBAAmB;AAC3D,aAAA,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE5D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,kCAAkC,CAAC,CAAA;QAEhE,IAAI,kCAAkC,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AAC3E,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;;;;"}
@@ -0,0 +1,23 @@
1
+ export interface CloseEvent {
2
+ code: number;
3
+ reason: string;
4
+ }
5
+ /**
6
+ * The server successfully processed the request, asks that the requester reset
7
+ * its document view, and is not returning any content.
8
+ */
9
+ export declare const ResetConnection: CloseEvent;
10
+ /**
11
+ * Similar to Forbidden, but specifically for use when authentication is required and has
12
+ * failed or has not yet been provided.
13
+ */
14
+ export declare const Unauthorized: CloseEvent;
15
+ /**
16
+ * The request contained valid data and was understood by the server, but the server
17
+ * is refusing action.
18
+ */
19
+ export declare const Forbidden: CloseEvent;
20
+ /**
21
+ * The server timed out waiting for the request.
22
+ */
23
+ export declare const ConnectionTimeout: CloseEvent;
@@ -0,0 +1,6 @@
1
+ import * as encoding from 'lib0/encoding';
2
+ import * as decoding from 'lib0/decoding';
3
+ export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
+ export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
+ export declare const writeAuthenticated: (encoder: encoding.Encoder) => void;
6
+ export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: () => void) => void;
@@ -0,0 +1,3 @@
1
+ export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
+ clientId: number;
3
+ }[];
@@ -0,0 +1,4 @@
1
+ export * from './auth';
2
+ export * from './CloseEvents';
3
+ export * from './awarenessStatesToArray';
4
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * State of the WebSocket connection.
3
+ * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
4
+ */
5
+ export declare enum WsReadyStates {
6
+ Connecting = 0,
7
+ Open = 1,
8
+ Closing = 2,
9
+ Closed = 3
10
+ }
@@ -0,0 +1,30 @@
1
+ import { 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) => 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
+ }
@@ -0,0 +1 @@
1
+ export * from './Database';
@@ -0,0 +1,67 @@
1
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ export interface LoggerConfiguration {
3
+ /**
4
+ * Prepend all logging message with a string.
5
+ *
6
+ * @deprecated
7
+ */
8
+ prefix: null | string;
9
+ /**
10
+ * Whether to log something for the `onLoadDocument` hook.
11
+ */
12
+ onLoadDocument: boolean;
13
+ /**
14
+ * Whether to log something for the `onChange` hook.
15
+ */
16
+ onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onStoreDocument` hook.
19
+ */
20
+ onStoreDocument: boolean;
21
+ /**
22
+ * Whether to log something for the `onConnect` hook.
23
+ */
24
+ onConnect: boolean;
25
+ /**
26
+ * Whether to log something for the `onDisconnect` hook.
27
+ */
28
+ onDisconnect: boolean;
29
+ /**
30
+ * Whether to log something for the `onUpgrade` hook.
31
+ */
32
+ onUpgrade: boolean;
33
+ /**
34
+ * Whether to log something for the `onRequest` hook.
35
+ */
36
+ onRequest: boolean;
37
+ /**
38
+ * Whether to log something for the `onDestroy` hook.
39
+ */
40
+ onDestroy: boolean;
41
+ /**
42
+ * Whether to log something for the `onConfigure` hook.
43
+ */
44
+ onConfigure: boolean;
45
+ /**
46
+ * A log function, if none is provided output will go to console
47
+ */
48
+ log: (...args: any[]) => void;
49
+ }
50
+ export declare class Logger implements Extension {
51
+ name: string | null;
52
+ configuration: LoggerConfiguration;
53
+ /**
54
+ * Constructor
55
+ */
56
+ constructor(configuration?: Partial<LoggerConfiguration>);
57
+ onConfigure(data: onConfigurePayload): Promise<void>;
58
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
59
+ onChange(data: onChangePayload): Promise<void>;
60
+ onStoreDocument(data: onDisconnectPayload): Promise<void>;
61
+ onConnect(data: onConnectPayload): Promise<void>;
62
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
63
+ onUpgrade(data: onUpgradePayload): Promise<void>;
64
+ onRequest(data: onRequestPayload): Promise<void>;
65
+ onDestroy(data: onDestroyPayload): Promise<void>;
66
+ private log;
67
+ }
@@ -0,0 +1 @@
1
+ export * from './Logger';
@@ -1,9 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { Configuration, onConnectPayload, onDisconnectPayload, onCreateDocumentPayload, onChangePayload } from '@hocuspocus/server';
2
+ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPayload, onChangePayload } from '@hocuspocus/server';
3
3
  export declare class Collector {
4
4
  serverConfiguration: Partial<Configuration>;
5
5
  version: string;
6
- yjsVersion: string;
7
6
  connections: {};
8
7
  messages: {};
9
8
  messageCounter: number;
@@ -30,7 +29,7 @@ export declare class Collector {
30
29
  connectionCount(): {
31
30
  count: string | number;
32
31
  };
33
- createDocument(data: onCreateDocumentPayload): {
32
+ createDocument(data: onLoadDocumentPayload): {
34
33
  action: string;
35
34
  document: any;
36
35
  documentName: string;
@@ -51,12 +50,12 @@ export declare class Collector {
51
50
  documents(): {};
52
51
  info(): Promise<{
53
52
  configuration: Partial<Configuration>;
54
- ipAddress: string;
53
+ ipAddress: string | null;
55
54
  nodeVersion: string;
56
55
  platform: NodeJS.Platform;
57
56
  started: string;
58
57
  version: string;
59
- yjsVersion: string;
60
58
  }>;
59
+ private getIpAddress;
61
60
  private static readableYDoc;
62
61
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
- import WebSocket from 'ws';
3
+ import WebSocket, { WebSocketServer } from 'ws';
4
4
  import { Socket } from 'net';
5
5
  import { Storage } from './Storage';
6
6
  export interface Configuration {
@@ -12,7 +12,7 @@ export interface Configuration {
12
12
  }
13
13
  export declare class Dashboard {
14
14
  configuration: Configuration;
15
- websocketServer: WebSocket.Server;
15
+ websocketServer: WebSocketServer;
16
16
  connections: Map<WebSocket, any>;
17
17
  /**
18
18
  * Constructor
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
4
  import WebSocket from 'ws';
5
5
  import { Storage } from './Storage';
@@ -30,11 +30,9 @@ export declare class Monitor implements Extension {
30
30
  handleConnection(websocket: WebSocket, request: IncomingMessage): void | undefined;
31
31
  onRequest({ request, response }: onRequestPayload): Promise<void>;
32
32
  onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
33
- onConnect(data: onConnectPayload): Promise<void>;
33
+ connected(data: connectedPayload): Promise<void>;
34
34
  onDisconnect(data: onDisconnectPayload): Promise<void>;
35
- onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
35
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
36
36
  onChange(data: onChangePayload): Promise<void>;
37
- onListen(data: onListenPayload): Promise<void>;
38
- onDestroy(data: onDestroyPayload): Promise<void>;
39
37
  onConfigure(data: onConfigurePayload): Promise<void>;
40
38
  }
@@ -0,0 +1,98 @@
1
+ import RedisClient from 'ioredis';
2
+ import Redlock from 'redlock';
3
+ import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
4
+ export interface Configuration {
5
+ /**
6
+ * Redis port
7
+ */
8
+ port: number;
9
+ /**
10
+ * Redis host
11
+ */
12
+ host: string;
13
+ /**
14
+ * Options passed directly to Redis constructor
15
+ *
16
+ * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
17
+ */
18
+ options?: RedisClient.RedisOptions;
19
+ /**
20
+ * An unique instance name, required to filter messages in Redis.
21
+ * If none is provided an unique id is generated.
22
+ */
23
+ identifier: string;
24
+ /**
25
+ * Namespace for Redis keys, if none is provided 'hocuspocus' is used
26
+ */
27
+ prefix: string;
28
+ /**
29
+ * The maximum time for the Redis lock in ms (in case it can’t be released).
30
+ */
31
+ lockTimeout: number;
32
+ }
33
+ export declare class Redis implements Extension {
34
+ /**
35
+ * Make sure to give that extension a higher priority, so
36
+ * the `onStoreDocument` hook is able to intercept the chain,
37
+ * before documents are stored to the database.
38
+ */
39
+ priority: number;
40
+ configuration: Configuration;
41
+ pub: RedisClient.Redis;
42
+ sub: RedisClient.Redis;
43
+ documents: Map<string, Document>;
44
+ redlock: Redlock;
45
+ locks: Map<string, Redlock.Lock>;
46
+ logger: Debugger;
47
+ constructor(configuration: Partial<Configuration>);
48
+ onConfigure({ instance }: onConfigurePayload): Promise<void>;
49
+ onListen({ configuration }: onListenPayload): Promise<void>;
50
+ private getKey;
51
+ private pubKey;
52
+ private subKey;
53
+ private lockKey;
54
+ /**
55
+ * Once a document is laoded, subscribe to the channel in Redis.
56
+ */
57
+ afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
58
+ /**
59
+ * Publish the first sync step through Redis.
60
+ */
61
+ private publishFirstSyncStep;
62
+ /**
63
+ * Let’s ask Redis who is connected already.
64
+ */
65
+ private requestAwarenessFromOtherInstances;
66
+ /**
67
+ * Before the document is stored, make sure to set a lock in Redis.
68
+ * That’s meant to avoid conflicts with other instances trying to store the document.
69
+ */
70
+ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<unknown>;
71
+ /**
72
+ * Release the Redis lock, so other instances can store documents.
73
+ */
74
+ afterStoreDocument({ documentName }: afterStoreDocumentPayload): Promise<void>;
75
+ /**
76
+ * Handle awareness update messages received directly by this Hocuspocus instance.
77
+ */
78
+ onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<number>;
79
+ /**
80
+ * Handle incoming messages published on all subscribed document channels.
81
+ * Note that this will also include messages from ourselves as it is not possible
82
+ * in Redis to filter these.
83
+ */
84
+ private handleIncomingMessage;
85
+ /**
86
+ * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
87
+ */
88
+ onChange(data: onChangePayload): Promise<any>;
89
+ /**
90
+ * Make sure to *not* listen for further changes, when there’s
91
+ * noone connected anymore.
92
+ */
93
+ onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
94
+ /**
95
+ * Kill the Redlock connection immediately.
96
+ */
97
+ onDestroy(): Promise<void>;
98
+ }
@@ -0,0 +1 @@
1
+ export * from './Redis';
@@ -0,0 +1,26 @@
1
+ import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
+ import sqlite3 from 'sqlite3';
3
+ 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
+ export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
5
+ export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
6
+ export interface SQLiteConfiguration extends DatabaseConfiguration {
7
+ /**
8
+ * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
9
+ * string for an anonymous disk-based database. Anonymous databases are not persisted and
10
+ * when closing the database handle, their contents are lost.
11
+ *
12
+ * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
13
+ */
14
+ database: string;
15
+ /**
16
+ * The database schema to create.
17
+ */
18
+ schema: string;
19
+ }
20
+ export declare class SQLite extends Database {
21
+ db?: sqlite3.Database;
22
+ configuration: SQLiteConfiguration;
23
+ constructor(configuration?: Partial<SQLiteConfiguration>);
24
+ onConfigure(): Promise<void>;
25
+ onListen(): Promise<void>;
26
+ }
@@ -0,0 +1 @@
1
+ export * from './SQLite';
@@ -0,0 +1,24 @@
1
+ import { Extension, onConnectPayload } from '@hocuspocus/server';
2
+ export interface ThrottleConfiguration {
3
+ throttle: number | null | false;
4
+ banTime: number;
5
+ }
6
+ export declare class Throttle implements Extension {
7
+ configuration: ThrottleConfiguration;
8
+ connectionsByIp: Map<string, Array<number>>;
9
+ bannedIps: Map<string, number>;
10
+ /**
11
+ * Constructor
12
+ */
13
+ constructor(configuration?: Partial<ThrottleConfiguration>);
14
+ /**
15
+ * Throttle requests
16
+ * @private
17
+ */
18
+ private throttle;
19
+ /**
20
+ * onConnect hook
21
+ * @param data
22
+ */
23
+ onConnect(data: onConnectPayload): Promise<any>;
24
+ }
@@ -1,9 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
3
3
  import { Doc } from 'yjs';
4
4
  import { Transformer } from '@hocuspocus/transformer';
5
5
  import { AxiosResponse } from 'axios';
6
- import Timeout = NodeJS.Timeout;
7
6
  export declare enum Events {
8
7
  onChange = "change",
9
8
  onConnect = "connect",
@@ -24,7 +23,7 @@ export interface Configuration {
24
23
  export declare class Webhook implements Extension {
25
24
  configuration: Configuration;
26
25
  debounced: Map<string, {
27
- timeout: Timeout;
26
+ timeout: NodeJS.Timeout;
28
27
  start: number;
29
28
  }>;
30
29
  /**
@@ -42,23 +41,18 @@ export declare class Webhook implements Extension {
42
41
  /**
43
42
  * Send a request to the given url containing the given data
44
43
  */
45
- sendRequest(event: Events, payload: any): Promise<AxiosResponse<any>>;
44
+ sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
46
45
  /**
47
46
  * onChange hook
48
47
  */
49
48
  onChange(data: onChangePayload): Promise<void>;
50
49
  /**
51
- * onCreateDocument hook
50
+ * onLoadDocument hook
52
51
  */
53
- onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
52
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
54
53
  /**
55
54
  * onConnect hook
56
55
  */
57
56
  onConnect(data: onConnectPayload): Promise<any>;
58
57
  onDisconnect(data: onDisconnectPayload): Promise<void>;
59
- onUpgrade(data: onUpgradePayload): Promise<void>;
60
- onRequest(data: onRequestPayload): Promise<void>;
61
- onListen(data: onListenPayload): Promise<void>;
62
- onDestroy(data: onDestroyPayload): Promise<void>;
63
- onConfigure(data: onConfigurePayload): Promise<void>;
64
58
  }
@@ -0,0 +1,9 @@
1
+ export default class EventEmitter {
2
+ callbacks: {
3
+ [key: string]: Function[];
4
+ };
5
+ on(event: string, fn: Function): this;
6
+ protected emit(event: string, ...args: any): this;
7
+ off(event: string, fn?: Function): this;
8
+ removeAllListeners(): void;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
2
+ export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
3
+ export interface AdditionalHocuspocusCloudProviderConfiguration {
4
+ /**
5
+ * A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
6
+ */
7
+ key: string;
8
+ }
9
+ export declare class HocuspocusCloudProvider extends HocuspocusProvider {
10
+ constructor(configuration: HocuspocusCloudProviderConfiguration);
11
+ }