import { getSolidDataset, getStringNoLocale, getThingAll, getUrl, toRdfJsDataset } from '@inrupt/solid-client'; import { FOAF, VCARD } from '@inrupt/vocab-common-rdf'; import jsonld from 'jsonld'; import { JsonLdSerializer } from 'jsonld-streaming-serializer'; import d from 'stream-to-string'; 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 getAllSubjects = async (iri: string) => { const dataset = await getSolidDataset(iri, { fetch: fetchPod }); const subjects = getThingAll(dataset); return subjects; }; export const getProfile = async (webId: string) => { const subjects = getAllSubjects(webId); 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) }; };