src/lib/solid.ts (view raw)
1import { getSolidDataset, getStringNoLocale, getThingAll, getUrl } from '@inrupt/solid-client';
2import { FOAF, VCARD } from '@inrupt/vocab-common-rdf';
3
4export const fetchPod: typeof fetch = async (resource: URL | RequestInfo) =>
5 fetch(`/solid/fetch?resource=${encodeURIComponent(resource.toString())}`);
6
7export const getProfile = async (webId: string) => {
8 const dataset = await getSolidDataset(webId, { fetch: fetchPod });
9 const subjects = getThingAll(dataset);
10
11 console.log({ webId, subjects });
12
13 const findValue = (predicate: string) =>
14 subjects
15 .map((subject) => getStringNoLocale(subject, predicate) || getUrl(subject, predicate))
16 ?.filter((i) => !!i)[0];
17
18 return {
19 name: findValue(FOAF.name),
20 organization: findValue(VCARD.organization_name),
21 image: findValue(VCARD.hasPhoto)
22 };
23};