@hocuspocus/extension-throttle 1.0.0-alpha.53 → 1.0.0-alpha.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +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,QAA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AAE,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;;;;;"}
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 +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,\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;;;;IAcnB,YAAY,aAA8C;QAZ1D,kBAAa,GAA0B;YACrC,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,CAAC;SACX,CAAA;QAED,oBAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;QAEvD,cAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAMxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;;;;;IAMO,QAAQ,CAAC,EA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eAC5B,EAAE,CAAA;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;KACzE;;;;;"}
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,Q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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;;;;"}
@@ -3,7 +3,6 @@ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPay
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;
@@ -56,7 +55,6 @@ export declare class Collector {
56
55
  platform: NodeJS.Platform;
57
56
  started: string;
58
57
  version: string;
59
- yjsVersion: string;
60
58
  }>;
61
59
  private static readableYDoc;
62
60
  }
@@ -3,14 +3,8 @@ import { Awareness } from 'y-protocols/awareness';
3
3
  import * as mutex from 'lib0/mutex';
4
4
  import type { Event, CloseEvent, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
- import { OutgoingMessage } from './OutgoingMessage';
7
- import { ConstructableOutgoingMessage } from './types';
6
+ import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
8
7
  import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
9
- export declare enum WebSocketStatus {
10
- Connecting = "connecting",
11
- Connected = "connected",
12
- Disconnected = "disconnected"
13
- }
14
8
  export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
15
9
  export interface CompleteHocuspocusProviderConfiguration {
16
10
  /**
@@ -92,22 +86,18 @@ export interface CompleteHocuspocusProviderConfiguration {
92
86
  */
93
87
  timeout: number;
94
88
  onAuthenticated: () => void;
95
- onAuthenticationFailed: ({ reason }: {
96
- reason: string;
97
- }) => void;
98
- onOpen: (event: Event) => void;
89
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
+ onOpen: (data: onOpenParameters) => void;
99
91
  onConnect: () => void;
100
- onMessage: (event: MessageEvent) => void;
101
- onOutgoingMessage: (message: OutgoingMessage) => void;
102
- onStatus: (status: any) => void;
103
- onSynced: ({ state }: {
104
- state: boolean;
105
- }) => void;
106
- onDisconnect: (event: CloseEvent) => void;
107
- onClose: (event: CloseEvent) => void;
92
+ onMessage: (data: onMessageParameters) => void;
93
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
94
+ onStatus: (data: onStatusParameters) => void;
95
+ onSynced: (data: onSyncedParameters) => void;
96
+ onDisconnect: (data: onDisconnectParameters) => void;
97
+ onClose: (data: onCloseParameters) => void;
108
98
  onDestroy: () => void;
109
- onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void;
110
- onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void;
99
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
100
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
111
101
  /**
112
102
  * Don’t output any warnings.
113
103
  */
@@ -1,18 +1,26 @@
1
1
  import { Awareness } from 'y-protocols/awareness';
2
2
  import * as Y from 'yjs';
3
3
  import { Encoder } from 'lib0/encoding';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
4
5
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
5
6
  import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
6
7
  import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
7
8
  import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
8
9
  import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
9
10
  import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
11
+ import { IncomingMessage } from './IncomingMessage';
12
+ import { OutgoingMessage } from './OutgoingMessage';
10
13
  export declare enum MessageType {
11
14
  Sync = 0,
12
15
  Awareness = 1,
13
16
  Auth = 2,
14
17
  QueryAwareness = 3
15
18
  }
19
+ export declare enum WebSocketStatus {
20
+ Connecting = "connecting",
21
+ Connected = "connected",
22
+ Disconnected = "disconnected"
23
+ }
16
24
  export interface OutgoingMessageInterface {
17
25
  encoder: Encoder;
18
26
  type?: MessageType;
@@ -32,6 +40,31 @@ export interface Constructable<T> {
32
40
  new (...args: any): T;
33
41
  }
34
42
  export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
43
+ export declare type onAuthenticationFailedParameters = {
44
+ reason: string;
45
+ };
46
+ export declare type onOpenParameters = {
47
+ event: Event;
48
+ };
49
+ export declare type onMessageParameters = {
50
+ event: MessageEvent;
51
+ message: IncomingMessage;
52
+ };
53
+ export declare type onOutgoingMessageParameters = {
54
+ message: OutgoingMessage;
55
+ };
56
+ export declare type onStatusParameters = {
57
+ status: WebSocketStatus;
58
+ };
59
+ export declare type onSyncedParameters = {
60
+ state: boolean;
61
+ };
62
+ export declare type onDisconnectParameters = {
63
+ event: CloseEvent;
64
+ };
65
+ export declare type onCloseParameters = {
66
+ event: CloseEvent;
67
+ };
35
68
  export declare type onAwarenessUpdateParameters = {
36
69
  states: StatesArray;
37
70
  };
@@ -212,6 +212,5 @@ export interface onDestroyPayload {
212
212
  export interface onConfigurePayload {
213
213
  configuration: Configuration;
214
214
  version: string;
215
- yjsVersion: string;
216
215
  instance: Hocuspocus;
217
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-throttle",
3
- "version": "1.0.0-alpha.53",
3
+ "version": "1.0.0-alpha.54",
4
4
  "description": "hocuspocus throttle extension",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^1.0.0-alpha.97"
30
+ "@hocuspocus/server": "^1.0.0-alpha.98"
31
31
  },
32
- "gitHead": "673dd4b2c723e71bf9b33b8f7804ab35c8417417"
32
+ "gitHead": "1fc2a6cff1b5fd626b8dd7c486755111965da20d"
33
33
  }