Files
outline/server/presenters/revision.ts
T
Tom Moor 81d9bed9ba feat: Attribute revisions to the auth type they were made with (#13312)
Adds a sourceMetadata JSON column to revisions, populated with the
authentication type of the request that produced the edit, so the
document history sidebar can show "Tom edited via MCP"
2026-08-05 20:07:03 -04:00

54 lines
1.5 KiB
TypeScript

import parseTitle from "@shared/utils/parseTitle";
import { traceFunction } from "@server/logging/tracing";
import type { Revision } from "@server/models";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import presentUser from "./user";
type PresentRevisionOptions = {
/**
* Whether to include the document content. Defaults to true.
*/
includeContent?: boolean;
};
async function presentRevision(
revision: Revision,
options: PresentRevisionOptions = {}
) {
const { includeContent = true } = options;
// TODO: Remove this fallback once all revisions have been migrated
const { emoji, strippedTitle } = parseTitle(revision.title);
const [data, text, collaborators] = await Promise.all([
includeContent ? DocumentHelper.toJSON(revision) : undefined,
includeContent ? DocumentHelper.toMarkdown(revision) : undefined,
revision.collaborators,
]);
return {
id: revision.id,
documentId: revision.documentId,
title: strippedTitle,
name: revision.name,
data,
text,
icon: revision.icon ?? emoji,
color: revision.color,
collaborators: collaborators.map((user) => presentUser(user)),
sourceMetadata: revision.sourceMetadata
? {
authType: revision.sourceMetadata.authType,
}
: undefined,
createdAt: revision.createdAt,
createdBy: presentUser(revision.user),
createdById: revision.userId,
deletedAt: revision.deletedAt,
};
}
export default traceFunction({
spanName: "presenters",
})(presentRevision);