~james/core

core/web/src/lib/api/emailDid.ts -rw-r--r-- 885 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { Fetch } from "#lib/fetch.ts";

// best-effort batch lookup of verified signup emails against the internal
// `/_internal/email-did` route. returns only the emails that resolved; a
// transport or parse failure answers an empty map so hydration never throws.
export const resolveEmailToDid = async (
	fetchFn: Fetch,
	emails: string[]
): Promise<Map<string, string>> => {
	if (emails.length === 0) return new Map();
	const params = new URLSearchParams();
	for (const email of emails) params.append("emails", email);
	try {
		const res = await fetchFn(`/_internal/email-did?${params}`);
		if (!res.ok) return new Map();
		const map: Record<string, string | null> = await res.json();
		const result = new Map<string, string>();
		for (const [email, did] of Object.entries(map)) {
			if (did) result.set(email, did);
		}
		return result;
	} catch {
		return new Map();
	}
};