src/lib/solid.ts (view raw)
1import {
2 getSolidDataset,
3 getStringNoLocale,
4 getThingAll,
5 getUrl,
6} from "@inrupt/solid-client";
7import { fetch, getDefaultSession } from "@inrupt/solid-client-authn-browser";
8import { FOAF, VCARD } from "@inrupt/vocab-common-rdf";
9import { thingToTask } from "./models/task";
10
11export const getPodTasks = async (podUrl: string) => {
12 const tasksDataset = await getSolidDataset(`${podUrl}/tasks/default`, {
13 fetch: fetch,
14 });
15 const things = getThingAll(tasksDataset);
16 return things.map(thingToTask);
17};
18
19export const getProfile = async () => {
20 const session = getDefaultSession();
21 const webId = session.info.webId;
22 if (!webId) return null;
23 const profileDataset = await getSolidDataset(webId, { fetch: fetch });
24 const subjects = getThingAll(profileDataset);
25
26 const findValue = (predicate: string) =>
27 subjects
28 .map(
29 subject =>
30 getStringNoLocale(subject, predicate) || getUrl(subject, predicate)
31 )
32 ?.filter(i => !!i)[0];
33
34 return {
35 name: findValue(FOAF.name),
36 organization: findValue(VCARD.organization_name),
37 image: findValue(VCARD.hasPhoto),
38 webId,
39 };
40};