@hocuspocus/extension-webhook 1.0.0-alpha.34

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 (58) hide show
  1. package/CHANGELOG.md +272 -0
  2. package/LICENSE.md +21 -0
  3. package/dist/demos/backend/src/create-document.d.ts +1 -0
  4. package/dist/demos/backend/src/express.d.ts +1 -0
  5. package/dist/demos/backend/src/koa.d.ts +1 -0
  6. package/dist/demos/backend/src/minimal.d.ts +1 -0
  7. package/dist/demos/backend/src/monitor.d.ts +1 -0
  8. package/dist/demos/backend/src/redis.d.ts +1 -0
  9. package/dist/demos/backend/src/slow.d.ts +1 -0
  10. package/dist/demos/backend/src/webhook.d.ts +1 -0
  11. package/dist/hocuspocus-webhook.cjs +158 -0
  12. package/dist/hocuspocus-webhook.cjs.map +1 -0
  13. package/dist/hocuspocus-webhook.esm.js +150 -0
  14. package/dist/hocuspocus-webhook.esm.js.map +1 -0
  15. package/dist/packages/logger/src/index.d.ts +13 -0
  16. package/dist/packages/monitor/src/Collector.d.ts +62 -0
  17. package/dist/packages/monitor/src/Dashboard.d.ts +29 -0
  18. package/dist/packages/monitor/src/Storage.d.ts +35 -0
  19. package/dist/packages/monitor/src/index.d.ts +38 -0
  20. package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
  21. package/dist/packages/provider/src/HocuspocusProvider.d.ts +158 -0
  22. package/dist/packages/provider/src/IncomingMessage.d.ts +14 -0
  23. package/dist/packages/provider/src/MessageReceiver.d.ts +13 -0
  24. package/dist/packages/provider/src/MessageSender.d.ts +10 -0
  25. package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
  26. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -0
  27. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -0
  28. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -0
  29. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -0
  30. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -0
  31. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -0
  32. package/dist/packages/provider/src/index.d.ts +3 -0
  33. package/dist/packages/provider/src/types.d.ts +34 -0
  34. package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +4 -0
  35. package/dist/packages/provider/src/utils/index.d.ts +1 -0
  36. package/dist/packages/redis/src/Redis.d.ts +16 -0
  37. package/dist/packages/redis/src/RedisCluster.d.ts +4 -0
  38. package/dist/packages/redis/src/index.d.ts +2 -0
  39. package/dist/packages/rocksdb/src/index.d.ts +22 -0
  40. package/dist/packages/server/src/CloseEvents.d.ts +4 -0
  41. package/dist/packages/server/src/Connection.d.ts +62 -0
  42. package/dist/packages/server/src/Debugger.d.ts +15 -0
  43. package/dist/packages/server/src/Document.d.ts +75 -0
  44. package/dist/packages/server/src/Hocuspocus.d.ts +86 -0
  45. package/dist/packages/server/src/IncomingMessage.d.ts +19 -0
  46. package/dist/packages/server/src/MessageReceiver.d.ts +10 -0
  47. package/dist/packages/server/src/OutgoingMessage.d.ts +16 -0
  48. package/dist/packages/server/src/index.d.ts +2 -0
  49. package/dist/packages/server/src/types.d.ts +133 -0
  50. package/dist/packages/throttle/src/index.d.ts +20 -0
  51. package/dist/packages/transformer/src/Prosemirror.d.ts +11 -0
  52. package/dist/packages/transformer/src/Tiptap.d.ts +10 -0
  53. package/dist/packages/transformer/src/index.d.ts +3 -0
  54. package/dist/packages/transformer/src/types.d.ts +5 -0
  55. package/dist/packages/webhook/src/index.d.ts +59 -0
  56. package/dist/shared/protocols/auth.d.ts +6 -0
  57. package/package.json +32 -0
  58. package/src/index.ts +197 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hocuspocus-webhook.cjs","sources":["../src/index.ts"],"sourcesContent":["import { createHmac } from 'crypto'\nimport {\n Extension,\n onChangePayload,\n onConnectPayload,\n onCreateDocumentPayload,\n onDisconnectPayload,\n} from '@hocuspocus/server'\nimport { Doc } from 'yjs'\nimport { TiptapTransformer, Transformer } from '@hocuspocus/transformer'\nimport axios, { AxiosResponse } from 'axios'\nimport Timeout = NodeJS.Timeout\n\nexport enum Events {\n onChange = 'change',\n onConnect = 'connect',\n onCreate = 'create',\n onDisconnect = 'disconnect',\n}\n\nexport interface Configuration {\n debounce: number | false | null,\n debounceMaxWait: number,\n secret: string,\n transformer: Transformer | {\n toYdoc: (document: any) => Doc,\n fromYdoc: (document: Doc) => any,\n },\n url: string,\n events: Array<Events>,\n}\n\nexport class Webhook implements Extension {\n\n configuration: Configuration = {\n debounce: 2000,\n debounceMaxWait: 10000,\n secret: '',\n transformer: TiptapTransformer,\n url: '',\n events: [\n Events.onChange,\n ],\n }\n\n debounced: Map<string, { timeout: Timeout, start: number }> = new Map()\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n if (!this.configuration.url) {\n throw new Error('url is required!')\n }\n }\n\n /**\n * Create a signature for the response body\n */\n createSignature(body: string): string {\n const hmac = createHmac('sha256', this.configuration.secret)\n\n return `sha256=${hmac.update(body).digest('hex')}`\n }\n\n /**\n * debounce the given function, using the given identifier\n */\n debounce(id: string, func: Function) {\n const old = this.debounced.get(id)\n const start = old?.start || Date.now()\n\n const run = () => {\n this.debounced.delete(id)\n func()\n }\n\n if (old?.timeout) clearTimeout(old.timeout)\n if (Date.now() - start >= this.configuration.debounceMaxWait) return run()\n\n this.debounced.set(id, {\n start,\n timeout: setTimeout(run, <number> this.configuration.debounce),\n })\n }\n\n /**\n * Send a request to the given url containing the given data\n */\n async sendRequest(event: Events, payload: any) {\n const json = JSON.stringify({ event, payload })\n\n return axios.post(\n this.configuration.url,\n json,\n { headers: { 'X-Hocuspocus-Signature-256': this.createSignature(json) } },\n )\n }\n\n /**\n * onChange hook\n */\n async onChange(data: onChangePayload) {\n if (!this.configuration.events.includes(Events.onChange)) {\n return\n }\n\n const save = () => {\n this.sendRequest(Events.onChange, {\n document: this.configuration.transformer.fromYdoc(data.document),\n documentName: data.documentName,\n context: data.context,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n }\n\n if (!this.configuration.debounce) {\n return save()\n }\n\n this.debounce(data.documentName, save)\n }\n\n /**\n * onCreateDocument hook\n */\n async onCreateDocument(data: onCreateDocumentPayload) {\n if (!this.configuration.events.includes(Events.onCreate)) {\n return\n }\n\n const response = <AxiosResponse> await this.sendRequest(Events.onCreate, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n\n if (response.status !== 200 || !response.data) return\n\n const document = typeof response.data === 'string'\n ? JSON.parse(response.data)\n : response.data\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const fieldName in document) {\n if (data.document.isEmpty(fieldName)) {\n data.document.merge(\n this.configuration.transformer.toYdoc(document[fieldName], fieldName),\n )\n }\n }\n }\n\n /**\n * onConnect hook\n */\n async onConnect(data: onConnectPayload) {\n if (!this.configuration.events.includes(Events.onConnect)) {\n return\n }\n\n try {\n const response = <AxiosResponse> await this.sendRequest(Events.onConnect, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n\n return typeof response.data === 'string'\n ? JSON.parse(response.data)\n : response.data\n } catch (e) {\n // eslint-disable-next-line no-throw-literal\n throw null\n }\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n if (!this.configuration.events.includes(Events.onConnect)) {\n return\n }\n\n await this.sendRequest(Events.onDisconnect, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n context: data.context,\n })\n }\n\n}\n"],"names":["Events","TiptapTransformer","createHmac","axios"],"mappings":";;;;;;;;;;;;AAaYA;AAAZ,WAAY,MAAM;IAChB,6BAAmB,CAAA;IACnB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ACF,MAAM,QAAQ,GAAmB,MAAM,IAAI,CAAC,WAAW,CAACA,cAAM,CAAC,SAAS,EAAE;gBACxE,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;aACxE,CAAC,CAAA;YAEF,OAAO,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ;kBACpC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;kBACzB,QAAQ,CAAC,IAAI,CAAA;SAClB;QAAC,OAAO,CAAC,EAAE;;YAEV,MAAM,IAAI,CAAA;SACX;KACF;IAED,MAAM,YAAY,CAAC,IAAyB;QAC1C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAACA,cAAM,CAAC,SAAS,CAAC,EAAE;YACzD,OAAM;SACP;QAED,MAAM,IAAI,CAAC,WAAW,CAACA,cAAM,CAAC,YAAY,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;YACvE,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;KACH;;;;;"}
@@ -0,0 +1,150 @@
1
+ import { createHmac } from 'crypto';
2
+ import { TiptapTransformer } from '@hocuspocus/transformer';
3
+ import axios from 'axios';
4
+
5
+ var Events;
6
+ (function (Events) {
7
+ Events["onChange"] = "change";
8
+ Events["onConnect"] = "connect";
9
+ Events["onCreate"] = "create";
10
+ Events["onDisconnect"] = "disconnect";
11
+ })(Events || (Events = {}));
12
+ class Webhook {
13
+ /**
14
+ * Constructor
15
+ */
16
+ constructor(configuration) {
17
+ this.configuration = {
18
+ debounce: 2000,
19
+ debounceMaxWait: 10000,
20
+ secret: '',
21
+ transformer: TiptapTransformer,
22
+ url: '',
23
+ events: [
24
+ Events.onChange,
25
+ ],
26
+ };
27
+ this.debounced = new Map();
28
+ this.configuration = {
29
+ ...this.configuration,
30
+ ...configuration,
31
+ };
32
+ if (!this.configuration.url) {
33
+ throw new Error('url is required!');
34
+ }
35
+ }
36
+ /**
37
+ * Create a signature for the response body
38
+ */
39
+ createSignature(body) {
40
+ const hmac = createHmac('sha256', this.configuration.secret);
41
+ return `sha256=${hmac.update(body).digest('hex')}`;
42
+ }
43
+ /**
44
+ * debounce the given function, using the given identifier
45
+ */
46
+ debounce(id, func) {
47
+ const old = this.debounced.get(id);
48
+ const start = (old === null || old === void 0 ? void 0 : old.start) || Date.now();
49
+ const run = () => {
50
+ this.debounced.delete(id);
51
+ func();
52
+ };
53
+ if (old === null || old === void 0 ? void 0 : old.timeout)
54
+ clearTimeout(old.timeout);
55
+ if (Date.now() - start >= this.configuration.debounceMaxWait)
56
+ return run();
57
+ this.debounced.set(id, {
58
+ start,
59
+ timeout: setTimeout(run, this.configuration.debounce),
60
+ });
61
+ }
62
+ /**
63
+ * Send a request to the given url containing the given data
64
+ */
65
+ async sendRequest(event, payload) {
66
+ const json = JSON.stringify({ event, payload });
67
+ return axios.post(this.configuration.url, json, { headers: { 'X-Hocuspocus-Signature-256': this.createSignature(json) } });
68
+ }
69
+ /**
70
+ * onChange hook
71
+ */
72
+ async onChange(data) {
73
+ if (!this.configuration.events.includes(Events.onChange)) {
74
+ return;
75
+ }
76
+ const save = () => {
77
+ this.sendRequest(Events.onChange, {
78
+ document: this.configuration.transformer.fromYdoc(data.document),
79
+ documentName: data.documentName,
80
+ context: data.context,
81
+ requestHeaders: data.requestHeaders,
82
+ requestParameters: Object.fromEntries(data.requestParameters.entries()),
83
+ });
84
+ };
85
+ if (!this.configuration.debounce) {
86
+ return save();
87
+ }
88
+ this.debounce(data.documentName, save);
89
+ }
90
+ /**
91
+ * onCreateDocument hook
92
+ */
93
+ async onCreateDocument(data) {
94
+ if (!this.configuration.events.includes(Events.onCreate)) {
95
+ return;
96
+ }
97
+ const response = await this.sendRequest(Events.onCreate, {
98
+ documentName: data.documentName,
99
+ requestHeaders: data.requestHeaders,
100
+ requestParameters: Object.fromEntries(data.requestParameters.entries()),
101
+ });
102
+ if (response.status !== 200 || !response.data)
103
+ return;
104
+ const document = typeof response.data === 'string'
105
+ ? JSON.parse(response.data)
106
+ : response.data;
107
+ // eslint-disable-next-line guard-for-in,no-restricted-syntax
108
+ for (const fieldName in document) {
109
+ if (data.document.isEmpty(fieldName)) {
110
+ data.document.merge(this.configuration.transformer.toYdoc(document[fieldName], fieldName));
111
+ }
112
+ }
113
+ }
114
+ /**
115
+ * onConnect hook
116
+ */
117
+ async onConnect(data) {
118
+ if (!this.configuration.events.includes(Events.onConnect)) {
119
+ return;
120
+ }
121
+ try {
122
+ const response = await this.sendRequest(Events.onConnect, {
123
+ documentName: data.documentName,
124
+ requestHeaders: data.requestHeaders,
125
+ requestParameters: Object.fromEntries(data.requestParameters.entries()),
126
+ });
127
+ return typeof response.data === 'string'
128
+ ? JSON.parse(response.data)
129
+ : response.data;
130
+ }
131
+ catch (e) {
132
+ // eslint-disable-next-line no-throw-literal
133
+ throw null;
134
+ }
135
+ }
136
+ async onDisconnect(data) {
137
+ if (!this.configuration.events.includes(Events.onConnect)) {
138
+ return;
139
+ }
140
+ await this.sendRequest(Events.onDisconnect, {
141
+ documentName: data.documentName,
142
+ requestHeaders: data.requestHeaders,
143
+ requestParameters: Object.fromEntries(data.requestParameters.entries()),
144
+ context: data.context,
145
+ });
146
+ }
147
+ }
148
+
149
+ export { Events, Webhook };
150
+ //# sourceMappingURL=hocuspocus-webhook.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hocuspocus-webhook.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { createHmac } from 'crypto'\nimport {\n Extension,\n onChangePayload,\n onConnectPayload,\n onCreateDocumentPayload,\n onDisconnectPayload,\n} from '@hocuspocus/server'\nimport { Doc } from 'yjs'\nimport { TiptapTransformer, Transformer } from '@hocuspocus/transformer'\nimport axios, { AxiosResponse } from 'axios'\nimport Timeout = NodeJS.Timeout\n\nexport enum Events {\n onChange = 'change',\n onConnect = 'connect',\n onCreate = 'create',\n onDisconnect = 'disconnect',\n}\n\nexport interface Configuration {\n debounce: number | false | null,\n debounceMaxWait: number,\n secret: string,\n transformer: Transformer | {\n toYdoc: (document: any) => Doc,\n fromYdoc: (document: Doc) => any,\n },\n url: string,\n events: Array<Events>,\n}\n\nexport class Webhook implements Extension {\n\n configuration: Configuration = {\n debounce: 2000,\n debounceMaxWait: 10000,\n secret: '',\n transformer: TiptapTransformer,\n url: '',\n events: [\n Events.onChange,\n ],\n }\n\n debounced: Map<string, { timeout: Timeout, start: number }> = new Map()\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n if (!this.configuration.url) {\n throw new Error('url is required!')\n }\n }\n\n /**\n * Create a signature for the response body\n */\n createSignature(body: string): string {\n const hmac = createHmac('sha256', this.configuration.secret)\n\n return `sha256=${hmac.update(body).digest('hex')}`\n }\n\n /**\n * debounce the given function, using the given identifier\n */\n debounce(id: string, func: Function) {\n const old = this.debounced.get(id)\n const start = old?.start || Date.now()\n\n const run = () => {\n this.debounced.delete(id)\n func()\n }\n\n if (old?.timeout) clearTimeout(old.timeout)\n if (Date.now() - start >= this.configuration.debounceMaxWait) return run()\n\n this.debounced.set(id, {\n start,\n timeout: setTimeout(run, <number> this.configuration.debounce),\n })\n }\n\n /**\n * Send a request to the given url containing the given data\n */\n async sendRequest(event: Events, payload: any) {\n const json = JSON.stringify({ event, payload })\n\n return axios.post(\n this.configuration.url,\n json,\n { headers: { 'X-Hocuspocus-Signature-256': this.createSignature(json) } },\n )\n }\n\n /**\n * onChange hook\n */\n async onChange(data: onChangePayload) {\n if (!this.configuration.events.includes(Events.onChange)) {\n return\n }\n\n const save = () => {\n this.sendRequest(Events.onChange, {\n document: this.configuration.transformer.fromYdoc(data.document),\n documentName: data.documentName,\n context: data.context,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n }\n\n if (!this.configuration.debounce) {\n return save()\n }\n\n this.debounce(data.documentName, save)\n }\n\n /**\n * onCreateDocument hook\n */\n async onCreateDocument(data: onCreateDocumentPayload) {\n if (!this.configuration.events.includes(Events.onCreate)) {\n return\n }\n\n const response = <AxiosResponse> await this.sendRequest(Events.onCreate, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n\n if (response.status !== 200 || !response.data) return\n\n const document = typeof response.data === 'string'\n ? JSON.parse(response.data)\n : response.data\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const fieldName in document) {\n if (data.document.isEmpty(fieldName)) {\n data.document.merge(\n this.configuration.transformer.toYdoc(document[fieldName], fieldName),\n )\n }\n }\n }\n\n /**\n * onConnect hook\n */\n async onConnect(data: onConnectPayload) {\n if (!this.configuration.events.includes(Events.onConnect)) {\n return\n }\n\n try {\n const response = <AxiosResponse> await this.sendRequest(Events.onConnect, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n })\n\n return typeof response.data === 'string'\n ? JSON.parse(response.data)\n : response.data\n } catch (e) {\n // eslint-disable-next-line no-throw-literal\n throw null\n }\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n if (!this.configuration.events.includes(Events.onConnect)) {\n return\n }\n\n await this.sendRequest(Events.onDisconnect, {\n documentName: data.documentName,\n requestHeaders: data.requestHeaders,\n requestParameters: Object.fromEntries(data.requestParameters.entries()),\n context: data.context,\n })\n }\n\n}\n"],"names":[],"mappings":";;;;IAaY;AAAZ,WAAY,MAAM;IAChB,6BAAmB,CAAA;IACnB,+BAAqB,CAAA;IACrB,6BAAmB,CAAA;IACn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,CAAC,MAAM,CAAC,SAAS,EAAE;gBACxE,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;aACxE,CAAC,CAAA;YAEF,OAAO,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ;kBACpC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;kBACzB,QAAQ,CAAC,IAAI,CAAA;SAClB;QAAC,OAAO,CAAC,EAAE;;YAEV,MAAM,IAAI,CAAA;SACX;KACF;IAED,MAAM,YAAY,CAAC,IAAyB;QAC1C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YACzD,OAAM;SACP;QAED,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;YACvE,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;KACH;;;;;"}
@@ -0,0 +1,13 @@
1
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ export declare class Logger implements Extension {
3
+ onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
4
+ onChange(data: onChangePayload): Promise<void>;
5
+ onConnect(data: onConnectPayload): Promise<void>;
6
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
7
+ onUpgrade(data: onUpgradePayload): Promise<void>;
8
+ onRequest(data: onRequestPayload): Promise<void>;
9
+ onListen(data: onListenPayload): Promise<void>;
10
+ onDestroy(data: onDestroyPayload): Promise<void>;
11
+ onConfigure(data: onConfigurePayload): Promise<void>;
12
+ private static log;
13
+ }
@@ -0,0 +1,62 @@
1
+ /// <reference types="node" />
2
+ import { Configuration, onConnectPayload, onDisconnectPayload, onCreateDocumentPayload, onChangePayload } from '@hocuspocus/server';
3
+ export declare class Collector {
4
+ serverConfiguration: Partial<Configuration>;
5
+ version: string;
6
+ yjsVersion: string;
7
+ connections: {};
8
+ messages: {};
9
+ messageCounter: number;
10
+ memory(): Promise<{
11
+ free: number;
12
+ total: number;
13
+ usage: number;
14
+ }>;
15
+ cpu(): Promise<{
16
+ count: number;
17
+ model: string;
18
+ usage: number;
19
+ }>;
20
+ connect(data: onConnectPayload): {
21
+ action: string;
22
+ documentName: string;
23
+ socketId: string;
24
+ };
25
+ disconnect(data: onDisconnectPayload): {
26
+ action: string;
27
+ documentName: string;
28
+ socketId: string;
29
+ };
30
+ connectionCount(): {
31
+ count: string | number;
32
+ };
33
+ createDocument(data: onCreateDocumentPayload): {
34
+ action: string;
35
+ document: any;
36
+ documentName: string;
37
+ socketId: string;
38
+ };
39
+ changeDocument(data: onChangePayload): {
40
+ action: string;
41
+ document: any;
42
+ documentName: string;
43
+ socketId: string;
44
+ };
45
+ messageCount(): {
46
+ count: number;
47
+ };
48
+ documentCount(): {
49
+ count: number;
50
+ };
51
+ documents(): {};
52
+ info(): Promise<{
53
+ configuration: Partial<Configuration>;
54
+ ipAddress: string;
55
+ nodeVersion: string;
56
+ platform: NodeJS.Platform;
57
+ started: string;
58
+ version: string;
59
+ yjsVersion: string;
60
+ }>;
61
+ private static readableYDoc;
62
+ }
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage, ServerResponse } from 'http';
3
+ import WebSocket from 'ws';
4
+ import { Socket } from 'net';
5
+ import { Storage } from './Storage';
6
+ export interface Configuration {
7
+ password: string | undefined;
8
+ path: string;
9
+ port: number | undefined;
10
+ storage: Storage | undefined;
11
+ user: string | undefined;
12
+ }
13
+ export declare class Dashboard {
14
+ configuration: Configuration;
15
+ websocketServer: WebSocket.Server;
16
+ connections: Map<WebSocket, any>;
17
+ /**
18
+ * Constructor
19
+ */
20
+ constructor(configuration?: Partial<Configuration>);
21
+ createServer(): void;
22
+ handleRequest(request: IncomingMessage, response: ServerResponse): boolean;
23
+ handleUpgrade(request: IncomingMessage, socket: Socket, head: any): boolean;
24
+ handleConnection(connection: WebSocket, request: IncomingMessage): void;
25
+ close(connection: WebSocket): void;
26
+ send(message: string): void;
27
+ private sendInitialDataToClient;
28
+ private basicAuth;
29
+ }
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
3
+ export declare class Storage extends EventEmitter {
4
+ timed: Map<string, any>;
5
+ constant: Map<string, any>;
6
+ /**
7
+ * Get all constant values.
8
+ */
9
+ all(): Promise<any>;
10
+ /**
11
+ * Get a constant value by the given key.
12
+ */
13
+ get(key: string, defaultValue?: any): Promise<any>;
14
+ /**
15
+ * Set a constant value by the given key.
16
+ */
17
+ set(key: string, value: any): Promise<any>;
18
+ /**
19
+ * Delete a constant value by the given key.
20
+ * @param key
21
+ */
22
+ delete(key: string): Promise<any>;
23
+ /**
24
+ * Get all timed values.
25
+ */
26
+ allTimed(): Promise<any>;
27
+ /**
28
+ * Add a timed value by the given key.
29
+ */
30
+ add(key: string, value: any): Promise<any>;
31
+ /**
32
+ * Remove a timed value by the given timestamp and key.
33
+ */
34
+ remove(key: string, timestamp: string): Promise<any>;
35
+ }
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
3
+ import { IncomingMessage, ServerResponse } from 'http';
4
+ import WebSocket from 'ws';
5
+ import { Storage } from './Storage';
6
+ import { Dashboard } from './Dashboard';
7
+ import { Collector } from './Collector';
8
+ export interface Configuration {
9
+ dashboardPath: string;
10
+ enableDashboard: boolean;
11
+ metricsInterval: number;
12
+ osMetricsInterval: number;
13
+ password: string | undefined;
14
+ port: number | undefined;
15
+ user: string | undefined;
16
+ }
17
+ export declare class Monitor implements Extension {
18
+ configuration: Configuration;
19
+ storage: Storage;
20
+ collector: Collector;
21
+ dashboard?: Dashboard;
22
+ /**
23
+ * Constructor
24
+ */
25
+ constructor(configuration?: Partial<Configuration>);
26
+ private collectOsMetrics;
27
+ private collectConnectionMetrics;
28
+ private cleanMetrics;
29
+ handleRequest(request: IncomingMessage, response: ServerResponse): boolean | undefined;
30
+ handleConnection(websocket: WebSocket, request: IncomingMessage): void | undefined;
31
+ onRequest({ request, response }: onRequestPayload): Promise<void>;
32
+ onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
33
+ onConnect(data: onConnectPayload): Promise<void>;
34
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
35
+ onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
36
+ onChange(data: onChangePayload): Promise<void>;
37
+ onConfigure(data: onConfigurePayload): Promise<void>;
38
+ }
@@ -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
+ protected removeAllListeners(): void;
9
+ }
@@ -0,0 +1,158 @@
1
+ import * as Y from 'yjs';
2
+ import { Awareness } from 'y-protocols/awareness';
3
+ import * as mutex from 'lib0/mutex';
4
+ import { CloseEvent, MessageEvent, OpenEvent } from 'ws';
5
+ import EventEmitter from './EventEmitter';
6
+ import { OutgoingMessage } from './OutgoingMessage';
7
+ import { ConstructableOutgoingMessage } from './types';
8
+ export declare enum WebSocketStatus {
9
+ Connecting = "connecting",
10
+ Connected = "connected",
11
+ Disconnected = "disconnected"
12
+ }
13
+ export interface HocuspocusProviderOptions {
14
+ /**
15
+ * URL of your @hocuspocus/server instance
16
+ */
17
+ url: string;
18
+ /**
19
+ * The identifier/name of your document
20
+ */
21
+ name: string;
22
+ /**
23
+ * The actual Y.js document
24
+ */
25
+ document: Y.Doc;
26
+ /**
27
+ * Pass `false` to start the connection manually.
28
+ */
29
+ connect: boolean;
30
+ /**
31
+ * Pass false to disable broadcasting between browser tabs.
32
+ */
33
+ broadcast: boolean;
34
+ /**
35
+ * An Awareness instance to keep the presence state of all clients.
36
+ */
37
+ awareness: Awareness;
38
+ /**
39
+ * A token that’s sent to the backend for authentication purposes.
40
+ */
41
+ token: string | (() => string) | (() => Promise<string>) | null;
42
+ /**
43
+ * URL parameters that should be added.
44
+ */
45
+ parameters: {
46
+ [key: string]: any;
47
+ };
48
+ /**
49
+ * An optional WebSocket polyfill, for example for Node.js
50
+ */
51
+ WebSocketPolyfill: any;
52
+ /**
53
+ * Force syncing the document in the defined interval.
54
+ */
55
+ forceSyncInterval: false | number;
56
+ /**
57
+ * Disconnect when no message is received for the defined amount of milliseconds.
58
+ */
59
+ messageReconnectTimeout: number;
60
+ /**
61
+ * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
62
+ */
63
+ delay: number;
64
+ /**
65
+ * The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
66
+ */
67
+ initialDelay: number;
68
+ /**
69
+ * The factor option is used to grow the delay exponentially.
70
+ */
71
+ factor: number;
72
+ /**
73
+ * The maximum number of attempts or 0 if there is no limit on number of attempts.
74
+ */
75
+ maxAttempts: number;
76
+ /**
77
+ * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
78
+ */
79
+ minDelay: number;
80
+ /**
81
+ * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
82
+ */
83
+ maxDelay: number;
84
+ /**
85
+ * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
86
+ */
87
+ jitter: boolean;
88
+ /**
89
+ * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
90
+ */
91
+ timeout: number;
92
+ onAuthenticated: () => void;
93
+ onAuthenticationFailed: ({ reason }: {
94
+ reason: string;
95
+ }) => void;
96
+ onOpen: (event: OpenEvent) => void;
97
+ onConnect: () => void;
98
+ onMessage: (event: MessageEvent) => void;
99
+ onOutgoingMessage: (message: OutgoingMessage) => void;
100
+ onStatus: (status: any) => void;
101
+ onSynced: () => void;
102
+ onDisconnect: (event: CloseEvent) => void;
103
+ onClose: (event: CloseEvent) => void;
104
+ onDestroy: () => void;
105
+ onAwarenessUpdate: (states: any) => void;
106
+ onAwarenessChange: (states: any) => void;
107
+ }
108
+ export declare class HocuspocusProvider extends EventEmitter {
109
+ options: HocuspocusProviderOptions;
110
+ subscribedToBroadcastChannel: boolean;
111
+ webSocket: any;
112
+ shouldConnect: boolean;
113
+ status: WebSocketStatus;
114
+ isSynced: boolean;
115
+ isAuthenticated: boolean;
116
+ lastMessageReceived: number;
117
+ mux: mutex.mutex;
118
+ intervals: any;
119
+ connectionAttempt: {
120
+ resolve: (value?: any) => void;
121
+ reject: (reason?: any) => void;
122
+ } | null;
123
+ constructor(options?: Partial<HocuspocusProviderOptions>);
124
+ setOptions(options?: Partial<HocuspocusProviderOptions>): void;
125
+ connect(): void;
126
+ createWebSocketConnection(): Promise<unknown>;
127
+ resolveConnectionAttempt(): void;
128
+ rejectConnectionAttempt(): void;
129
+ get document(): Y.Doc;
130
+ get awareness(): Awareness;
131
+ checkConnection(): void;
132
+ forceSync(): void;
133
+ registerBeforeUnloadEventListener(): void;
134
+ documentUpdateHandler(update: Uint8Array, origin: any): void;
135
+ awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
136
+ permissionDeniedHandler(reason: string): void;
137
+ authenticatedHandler(): void;
138
+ get serverUrl(): string;
139
+ get url(): string;
140
+ get synced(): boolean;
141
+ set synced(state: boolean);
142
+ get isAuthenticationRequired(): boolean;
143
+ disconnect(): void;
144
+ onOpen(event: OpenEvent): void;
145
+ getToken(): Promise<string | null>;
146
+ webSocketConnectionEstablished(): Promise<void>;
147
+ startSync(): void;
148
+ send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
149
+ onMessage(event: MessageEvent): void;
150
+ onClose(event: CloseEvent): void;
151
+ destroy(): void;
152
+ get broadcastChannel(): string;
153
+ broadcastChannelSubscriber(data: ArrayBuffer): void;
154
+ subscribeToBroadcastChannel(): void;
155
+ disconnectBroadcastChannel(): void;
156
+ broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
157
+ setAwarenessField(key: string, value: any): void;
158
+ }