refactor(search,auth): export pure helpers for direct testing

encodeCursor/decodeCursor/firstSnippet (opensearch) and
decodeJwtPayload (verify) become public exports so tests can
hit them without round-tripping through fetch.
This commit is contained in:
Julien Calixte
2026-06-07 22:06:49 +02:00
parent 01048c753e
commit 49608cff20
2 changed files with 4 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ interface DidDocument {
service?: { id: string; serviceEndpoint: string }[]; service?: { id: string; serviceEndpoint: string }[];
} }
function decodeJwtPayload(token: string): JwtPayload { export function decodeJwtPayload(token: string): JwtPayload {
const parts = token.split("."); const parts = token.split(".");
if (parts.length !== 3) throw new Error("Invalid JWT format"); if (parts.length !== 3) throw new Error("Invalid JWT format");
const payload = parts[1].replace(/-/g, "+").replace(/_/g, "/"); const payload = parts[1].replace(/-/g, "+").replace(/_/g, "/");

View File

@@ -139,7 +139,7 @@ export type SearchOptions = {
limit: number; limit: number;
}; };
const decodeCursor = (cursor: string): [number, string] | undefined => { export const decodeCursor = (cursor: string): [number, string] | undefined => {
try { try {
const parsed = JSON.parse(atob(cursor)); const parsed = JSON.parse(atob(cursor));
if ( if (
@@ -157,10 +157,10 @@ const decodeCursor = (cursor: string): [number, string] | undefined => {
return undefined; return undefined;
}; };
const encodeCursor = (score: number, rkey: string): string => export const encodeCursor = (score: number, rkey: string): string =>
btoa(JSON.stringify([score, rkey])); btoa(JSON.stringify([score, rkey]));
const firstSnippet = ( export const firstSnippet = (
highlight: Record<string, string[]> | undefined, highlight: Record<string, string[]> | undefined,
source: { content?: string; title?: string }, source: { content?: string; title?: string },
): string => { ): string => {