@hocuspocus/extension-webhook
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -78,9 +78,14 @@ import { createHmac } from 'crypto'; | ||
const save = () => { | ||
this.sendRequest(Events.onChange, { | ||
document: this.configuration.transformer.fromYdoc(data.document), | ||
documentName: data.documentName, | ||
context: data.context, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}); | ||
try { | ||
this.sendRequest(Events.onChange, { | ||
document: this.configuration.transformer.fromYdoc(data.document), | ||
documentName: data.documentName, | ||
context: data.context, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}); | ||
} | ||
catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`); | ||
} | ||
}; | ||
@@ -99,18 +104,23 @@ if (!this.configuration.debounce) { | ||
} | ||
const response = await this.sendRequest(Events.onCreate, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}); | ||
if (response.status !== 200 || !response.data) | ||
return; | ||
const document = typeof response.data === 'string' | ||
? JSON.parse(response.data) | ||
: response.data; | ||
// eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
for (const fieldName in document) { | ||
if (data.document.isEmpty(fieldName)) { | ||
data.document.merge(this.configuration.transformer.toYdoc(document[fieldName], fieldName)); | ||
try { | ||
const response = await this.sendRequest(Events.onCreate, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}); | ||
if (response.status !== 200 || !response.data) | ||
return; | ||
const document = typeof response.data === 'string' | ||
? JSON.parse(response.data) | ||
: response.data; | ||
// eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
for (const fieldName in document) { | ||
if (data.document.isEmpty(fieldName)) { | ||
data.document.merge(this.configuration.transformer.toYdoc(document[fieldName], fieldName)); | ||
} | ||
} | ||
} | ||
catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`); | ||
} | ||
} | ||
@@ -143,8 +153,13 @@ /** | ||
} | ||
await this.sendRequest(Events.onDisconnect, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
context: data.context, | ||
}); | ||
try { | ||
await this.sendRequest(Events.onDisconnect, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
context: data.context, | ||
}); | ||
} | ||
catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`); | ||
} | ||
} | ||
@@ -151,0 +166,0 @@ } |
@@ -5,3 +5,2 @@ /// <reference types="node" /> | ||
import { Transformer } from '@hocuspocus/transformer'; | ||
import { AxiosResponse } from 'axios'; | ||
export declare enum Events { | ||
@@ -45,3 +44,3 @@ onChange = "change", | ||
*/ | ||
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>; | ||
sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any>>; | ||
/** | ||
@@ -48,0 +47,0 @@ * onChange hook |
export * from './HocuspocusProvider'; | ||
export * from './HocuspocusCloudProvider'; | ||
export * from './TiptapCollabProvider'; | ||
export * from './types'; |
{ | ||
"name": "@hocuspocus/extension-webhook", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "hocuspocus webhook extension", | ||
@@ -32,5 +32,5 @@ "homepage": "https://hocuspocus.dev", | ||
"dependencies": { | ||
"@hocuspocus/common": "^1.1.1", | ||
"@hocuspocus/server": "^1.1.1", | ||
"@hocuspocus/transformer": "^1.1.1", | ||
"@hocuspocus/common": "^1.1.2", | ||
"@hocuspocus/server": "^1.1.2", | ||
"@hocuspocus/transformer": "^1.1.2", | ||
"axios": "^1.2.2" | ||
@@ -37,0 +37,0 @@ }, |
@@ -11,3 +11,3 @@ import { createHmac } from 'crypto' | ||
import { TiptapTransformer, Transformer } from '@hocuspocus/transformer' | ||
import axios, { AxiosResponse } from 'axios' | ||
import axios from 'axios' | ||
import { Forbidden } from '@hocuspocus/common' | ||
@@ -115,9 +115,13 @@ | ||
const save = () => { | ||
this.sendRequest(Events.onChange, { | ||
document: this.configuration.transformer.fromYdoc(data.document), | ||
documentName: data.documentName, | ||
context: data.context, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}) | ||
try { | ||
this.sendRequest(Events.onChange, { | ||
document: this.configuration.transformer.fromYdoc(data.document), | ||
documentName: data.documentName, | ||
context: data.context, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}) | ||
} catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`) | ||
} | ||
} | ||
@@ -140,21 +144,25 @@ | ||
const response = <AxiosResponse> await this.sendRequest(Events.onCreate, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}) | ||
try { | ||
const response = await this.sendRequest(Events.onCreate, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
}) | ||
if (response.status !== 200 || !response.data) return | ||
if (response.status !== 200 || !response.data) return | ||
const document = typeof response.data === 'string' | ||
? JSON.parse(response.data) | ||
: response.data | ||
const document = typeof response.data === 'string' | ||
? JSON.parse(response.data) | ||
: response.data | ||
// eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
for (const fieldName in document) { | ||
if (data.document.isEmpty(fieldName)) { | ||
data.document.merge( | ||
this.configuration.transformer.toYdoc(document[fieldName], fieldName), | ||
) | ||
// eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
for (const fieldName in document) { | ||
if (data.document.isEmpty(fieldName)) { | ||
data.document.merge( | ||
this.configuration.transformer.toYdoc(document[fieldName], fieldName), | ||
) | ||
} | ||
} | ||
} catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`) | ||
} | ||
@@ -172,3 +180,3 @@ } | ||
try { | ||
const response = <AxiosResponse> await this.sendRequest(Events.onConnect, { | ||
const response = await this.sendRequest(Events.onConnect, { | ||
documentName: data.documentName, | ||
@@ -193,10 +201,14 @@ requestHeaders: data.requestHeaders, | ||
await this.sendRequest(Events.onDisconnect, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
context: data.context, | ||
}) | ||
try { | ||
await this.sendRequest(Events.onDisconnect, { | ||
documentName: data.documentName, | ||
requestHeaders: data.requestHeaders, | ||
requestParameters: Object.fromEntries(data.requestParameters.entries()), | ||
context: data.context, | ||
}) | ||
} catch (e) { | ||
console.error(`Caught error in extension-webhook: ${e}`) | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95938
2144
Updated@hocuspocus/common@^1.1.2
Updated@hocuspocus/server@^1.1.2