import { getSolidDataset, getStringNoLocale, getThingAll, getUrl } from '@inrupt/solid-client'; import { FOAF, VCARD } from '@inrupt/vocab-common-rdf'; export const fetchPod: typeof fetch = async (resource: URL | RequestInfo) => { const response = await fetch(`/solid/fetch?resource=${encodeURIComponent(resource.toString())}`); Object.defineProperty(response, 'url', { value: decodeURIComponent(resource.toString()) }); return response; }; export const getProfile = async (webId: string) => { const dataset = await getSolidDataset(webId, { fetch: fetchPod }); const subjects = getThingAll(dataset); const findValue = (predicate: string) => subjects .map((subject) => getStringNoLocale(subject, predicate) || getUrl(subject, predicate)) ?.filter((i) => !!i)[0]; return { name: findValue(FOAF.name), organization: findValue(VCARD.organization_name), image: findValue(VCARD.hasPhoto) }; };