Files
outline/app/utils/routeHelpers.ts
T
Tom MoorandClaude Opus 4.7 c6aacfeeeb chore: Clear minimatch ReDoS advisories from audit ignore list (#12177)
* chore: Resolve minimatch ReDoS advisories via dep bumps and resolutions

Bump glob (8→11), rimraf (2→6), babel-jest, jest-environment-jsdom (29→30),
and lint-staged (13→16) to drop several vulnerable transitive chains. Pin
remaining minimatch and brace-expansion descriptors via resolutions so all
in-tree copies are on their latest patched release. Removes 9 ignored
advisory IDs from .yarnrc.yml.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: Make routeHelpers.urlify origin testable for jsdom 26

jsdom 26 (jest-environment-jsdom@30) makes window.location and
location.origin non-configurable, breaking the previous test that
redefined them via Object.defineProperty.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* chore: Align jest-cli to ^30.3.0 with other jest packages

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-27 09:13:52 -04:00

207 lines
4.8 KiB
TypeScript

import queryString from "query-string";
import type Collection from "~/models/Collection";
import type Comment from "~/models/Comment";
import type Document from "~/models/Document";
import env from "~/env";
export function homePath(): string {
return env.ROOT_SHARE_ID ? "/" : "/home";
}
export function logoutPath() {
return {
pathname: "/",
search: "logout=true",
};
}
export function draftsPath(): string {
return "/drafts";
}
export function archivePath(): string {
return "/archive";
}
export function trashPath(): string {
return "/trash";
}
export function debugPath(): string {
return "/debug";
}
export function debugChangesetsPath(): string {
return "/debug/changesets";
}
export function settingsPath(...args: string[]): string {
return "/settings" + (args.length > 0 ? `/${args.join("/")}` : "");
}
export function commentPath(document: Document, comment: Comment): string {
return `${documentPath(document)}?commentId=${comment.id}${
comment.isResolved ? "&resolved=1" : ""
}`;
}
export function collectionPath(
collection: Collection,
section?: string
): string {
if (section) {
return `${collection.path}/${section}`;
}
return collection.path;
}
export function collectionEditPath(collection: Collection): string {
return collectionPath(collection, "overview/edit");
}
export function updateCollectionPath(
oldUrl: string,
collection: Collection
): string {
// Update url to match the current one
return oldUrl.replace(
new RegExp("/collection/[0-9a-zA-Z-_~]*"),
collection.path
);
}
export function documentPath(doc: Document): string {
return doc.path;
}
export function documentEditPath(doc: Document): string {
return `${documentPath(doc)}/edit`;
}
export function documentHistoryPath(
doc: Document,
revisionId?: string
): string {
let base = `${documentPath(doc)}/history`;
if (revisionId) {
base += `/${revisionId}`;
}
return base;
}
/**
* Replace full url's document part with the new one in case
* the document slug has been updated
*/
export function updateDocumentPath(oldUrl: string, document: Document): string {
// Update url to match the current one
return oldUrl.replace(
new RegExp("/doc/([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})"),
document.url
);
}
export function newTemplatePath(collectionId?: string) {
return collectionId
? settingsPath("templates") + `/new?collectionId=${collectionId}`
: `${settingsPath("templates")}/new`;
}
export function newDocumentPath(
collectionId?: string | null,
params: {
templateId?: string;
} = {}
): string {
const search = queryString.stringify(params);
return collectionId
? `/collection/${collectionId}/new${search ? `?${search}` : ""}`
: `/doc/new${search ? `?${search}` : ""}`;
}
export function newNestedDocumentPath(parentDocumentId?: string): string {
const search = parentDocumentId
? `?${queryString.stringify({ parentDocumentId })}`
: "";
return `/doc/new${search}`;
}
export function newSiblingDocumentPath(params: {
collectionId?: string | null;
parentDocumentId?: string;
index: number;
}): string {
const query: Record<string, string> = {
index: String(params.index),
};
if (params.parentDocumentId) {
query.parentDocumentId = params.parentDocumentId;
}
if (params.collectionId) {
query.collectionId = params.collectionId;
}
return `/doc/new?${queryString.stringify(query)}`;
}
export function searchPath({
query,
collectionId,
documentId,
ref,
}: {
query?: string;
collectionId?: string;
documentId?: string;
ref?: string;
} = {}): string {
const search = queryString.stringify({
q: query,
collectionId,
documentId,
ref,
});
return `/search${search ? `?${search}` : ""}`;
}
export function sharedModelPath(shareId: string, modelPath?: string) {
if (shareId === env.ROOT_SHARE_ID) {
return modelPath ? modelPath : "/";
}
return modelPath ? `/s/${shareId}${modelPath}` : `/s/${shareId}`;
}
export function urlify(
path: string,
origin: string = window.location.origin
): string {
return `${origin}${path}`;
}
/**
* Converts a path to a desktop app URL using the outline:// protocol.
*
* @param path The path to convert.
* @param origin Optional origin to use instead of `window.location.origin`.
* @returns The desktop app URL.
*/
export function desktopify(path: string, origin?: string): string {
return urlify(path, origin).replace(/^https?:\/\//, "outline://");
}
export const matchCollectionSlug =
":collectionSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
export const matchCollectionEdit = `/collection/${matchCollectionSlug}/overview/edit`;
export const matchDocumentSlug =
":documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
export const matchDocumentHistory = `/doc/${matchDocumentSlug}/history/:revisionId?`;