import { getSolidDataset, getStringNoLocale, getThingAll, getUrl, } from "@inrupt/solid-client"; import { fetch, getDefaultSession } from "@inrupt/solid-client-authn-browser"; import { FOAF, VCARD } from "@inrupt/vocab-common-rdf"; import { thingToTask } from "./models/task"; export const getPodTasks = async (podUrl: string) => { const tasksDataset = await getSolidDataset(`${podUrl}/tasks/default`, { fetch: fetch, }); const things = getThingAll(tasksDataset); return things.map(thingToTask); }; export const getProfile = async () => { const session = getDefaultSession(); const webId = session.info.webId; if (!webId) return null; const profileDataset = await getSolidDataset(webId, { fetch: fetch }); const subjects = getThingAll(profileDataset); 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), webId, }; };