Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions extensions/op-blocknote-hocuspocus/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions extensions/op-blocknote-hocuspocus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"dependencies": {
"@blocknote/server-util": "^0.51.3",
"@hocuspocus/extension-logger": "^3.4.4",
"@hocuspocus/server": "^3.4.0",
"@hocuspocus/extension-logger": "^4.2.0",
"@hocuspocus/server": "^4.2.0",
"op-blocknote-extensions": "https://github.com/opf/op-blocknote-extensions/releases/download/v0.1.4/op-blocknote-extensions-0.1.4.tgz",
"tsx": "^4.21.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class OpenProjectApi implements Extension {
throw new Error('Unauthorized: Missing auth params');
}

const requestOrigin = data.request?.headers?.origin;
const requestOrigin = data.requestHeaders?.get("origin") ?? undefined;
const result = await decryptAndValidateToken(token, resourceUrl, requestOrigin);

const tokenExpiresAtDate = new Date(result.tokenExpiresAt);
Expand Down Expand Up @@ -103,7 +103,7 @@ export class OpenProjectApi implements Extension {
* Store data to the API. The data is a YDoc update
*/
async onStoreDocument(data: onStoreDocumentPayload): Promise<void> {
const { resourceUrl, readonly } = data.context;
const { resourceUrl, readonly } = data.lastContext;

if (!resourceUrl) {
console.warn("Missing parameters in context. Skipping store.");
Expand All @@ -124,7 +124,7 @@ export class OpenProjectApi implements Extension {
const editorData = editor.yXmlFragmentToBlocks(tempFragment);
const markdownData = await editor.blocksToMarkdownLossy(editorData);

const response = await fetchResource(resourceUrl, data.context.token, {
const response = await fetchResource(resourceUrl, data.lastContext.token, {
method: "PATCH",
body: JSON.stringify({
content_binary: base64Data,
Expand All @@ -137,7 +137,7 @@ export class OpenProjectApi implements Extension {
return;
}

data.document.connections.forEach(({ connection }) => connection.sendStateless("storeEvent"));
data.document.broadcastStateless("storeEvent");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ❤️

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ describe("OpenProjectApi", () => {
new OpenProjectApi().onAuthenticate({
token: "Yjo1x80JGIjrK8J6IDOuRn5kIOGvaAUw8C1so+dJJq7cgkllf3dQnw6d8bgiKbHXw8ZaMYE4IyOI1KQgX2ZRmx1mKBkxtb/fc7eCpGyTKGTA2Y1r/q7VJYiJZlpX7gx3nu569joEl/k=--mUkLaPiK0E82vGT9--gj1ZnTNlydL9j+Xw8+YFAA==",
documentName: "https://test.api/api/v3/documents/1",
request: {
headers: {
origin: "https://different.origin",
},
},
requestHeaders: new Headers({
origin: "https://different.origin",
}),
} as unknown as onAuthenticatePayload)
).rejects.toThrowError("Unauthorized: Token origin does not match request origin.");
});
Expand Down Expand Up @@ -269,20 +267,22 @@ describe("OpenProjectApi", () => {
// @ts-expect-error BlockNote types are complicated
editor.blocksToYXmlFragment(blocks, fragment);

const broadcastStateless = vi.fn();
const data = {
context: {
lastContext: {
token: "superValidToken",
resourceUrl: "https://test.api/api/v3/documents/121",
readonly: false,
tokenExpiresAt: new Date(Date.now() + 5 * 60 * 1000), // 5 min from now
},
document: { ...document, connections: [] } as unknown as Document,
} as onStoreDocumentPayload;
document: { ...document, broadcastStateless } as unknown as Document,
} as unknown as onStoreDocumentPayload;
Comment thread
akabiru marked this conversation as resolved.

const api = new OpenProjectApi();
await api.onStoreDocument(data);

await expect(body).resolves.toContain("content_binary");
expect(broadcastStateless).toHaveBeenCalledWith("storeEvent");
});
});

Expand Down
10 changes: 5 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@fullcalendar/resource-timeline": "^6.1.20",
"@fullcalendar/timegrid": "^6.1.20",
"@github/webauthn-json": "^2.1.1",
"@hocuspocus/provider": "^4.1.0",
"@hocuspocus/provider": "^4.2.0",
"@hotwired/stimulus": "^3.2.2",
"@hotwired/turbo": "^8.0.23",
"@hotwired/turbo-rails": "^8.0.23",
Expand Down
Loading