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:
@@ -7,7 +7,7 @@ interface DidDocument {
|
||||
service?: { id: string; serviceEndpoint: string }[];
|
||||
}
|
||||
|
||||
function decodeJwtPayload(token: string): JwtPayload {
|
||||
export function decodeJwtPayload(token: string): JwtPayload {
|
||||
const parts = token.split(".");
|
||||
if (parts.length !== 3) throw new Error("Invalid JWT format");
|
||||
const payload = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
||||
|
||||
@@ -139,7 +139,7 @@ export type SearchOptions = {
|
||||
limit: number;
|
||||
};
|
||||
|
||||
const decodeCursor = (cursor: string): [number, string] | undefined => {
|
||||
export const decodeCursor = (cursor: string): [number, string] | undefined => {
|
||||
try {
|
||||
const parsed = JSON.parse(atob(cursor));
|
||||
if (
|
||||
@@ -157,10 +157,10 @@ const decodeCursor = (cursor: string): [number, string] | undefined => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const encodeCursor = (score: number, rkey: string): string =>
|
||||
export const encodeCursor = (score: number, rkey: string): string =>
|
||||
btoa(JSON.stringify([score, rkey]));
|
||||
|
||||
const firstSnippet = (
|
||||
export const firstSnippet = (
|
||||
highlight: Record<string, string[]> | undefined,
|
||||
source: { content?: string; title?: string },
|
||||
): string => {
|
||||
|
||||
Reference in New Issue
Block a user