solid-logic 3.0.9-f51524a8 → 3.0.9-fa4d7e8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint.config.js +24 -23
- package/jest.config.js +8 -15
- package/lib/acl/aclLogic.d.ts +2 -2
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +168 -0
- package/lib/acl/aclLogic.js.map +1 -0
- package/lib/authSession/authSession.js +8 -0
- package/lib/authSession/authSession.js.map +1 -0
- package/lib/authn/SolidAuthnLogic.d.ts +3 -3
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +191 -0
- package/lib/authn/SolidAuthnLogic.js.map +1 -0
- package/lib/authn/authUtil.d.ts +1 -1
- package/lib/authn/authUtil.js +105 -0
- package/lib/authn/authUtil.js.map +1 -0
- package/lib/chat/chatLogic.d.ts +1 -1
- package/lib/chat/chatLogic.js +272 -0
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/inbox/inboxLogic.d.ts +1 -1
- package/lib/inbox/inboxLogic.d.ts.map +1 -1
- package/lib/inbox/inboxLogic.js +139 -0
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -0
- package/lib/index.js.map +1 -0
- package/lib/issuer/issuerLogic.js +52 -0
- package/lib/issuer/issuerLogic.js.map +1 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +89 -0
- package/lib/logic/CustomError.js.map +1 -0
- package/lib/logic/solidLogic.d.ts +2 -2
- package/lib/logic/solidLogic.d.ts.map +1 -1
- package/lib/logic/solidLogic.js +102 -0
- package/lib/logic/solidLogic.js.map +1 -0
- package/lib/logic/solidLogicSingleton.js +94 -0
- package/lib/logic/solidLogicSingleton.js.map +1 -0
- package/lib/profile/profileLogic.d.ts +1 -1
- package/lib/profile/profileLogic.js +259 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.js +399 -0
- package/lib/typeIndex/typeIndexLogic.js.map +1 -0
- package/lib/types.d.ts +2 -2
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/util/containerLogic.d.ts +1 -1
- package/lib/util/containerLogic.d.ts.map +1 -1
- package/lib/util/containerLogic.js +102 -0
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/debug.d.ts.map +1 -1
- package/lib/util/debug.js +40 -0
- package/lib/util/debug.js.map +1 -0
- package/lib/util/ns.js +44 -0
- package/lib/util/ns.js.map +1 -0
- package/lib/util/utilityLogic.d.ts +1 -1
- package/lib/util/utilityLogic.d.ts.map +1 -1
- package/lib/util/utilityLogic.js +284 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +1 -1
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +47 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +15 -38
- package/src/acl/aclLogic.ts +8 -8
- package/src/authn/SolidAuthnLogic.ts +6 -6
- package/src/authn/authUtil.ts +1 -1
- package/src/chat/chatLogic.ts +75 -75
- package/src/inbox/inboxLogic.ts +19 -19
- package/src/index.ts +2 -1
- package/src/logic/CustomError.ts +6 -6
- package/src/logic/solidLogic.ts +22 -22
- package/src/logic/solidLogicSingleton.ts +3 -3
- package/src/profile/profileLogic.ts +22 -22
- package/src/typeIndex/typeIndexLogic.ts +7 -7
- package/src/types.ts +2 -2
- package/src/util/containerLogic.ts +15 -15
- package/src/util/debug.ts +8 -4
- package/src/util/utilityLogic.ts +18 -18
- package/src/util/utils.ts +12 -12
- package/test/aclLogic.test.ts +5 -5
- package/test/authUtil.test.ts +1 -1
- package/test/chatLogic.test.ts +154 -160
- package/test/container.test.ts +23 -23
- package/test/helpers/dataSetup.ts +1 -2
- package/test/helpers/setup.ts +3 -8
- package/test/inboxLogic.test.ts +110 -101
- package/test/logic.test.ts +2 -2
- package/test/profileLogic.test.ts +33 -35
- package/test/solidAuthLogic.test.ts +1 -1
- package/test/typeIndexLogic.test.ts +71 -71
- package/test/utilityLogic.test.ts +45 -46
- package/test/utils.test.ts +11 -11
- package/tsconfig.json +3 -5
- package/babel.config.js +0 -6
- package/lib/solid-logic.js +0 -107
- package/lib/solid-logic.js.map +0 -1
- package/rollup.config.js +0 -29
- package/src/versionInfo.ts +0 -32
- package/timestamp.sh +0 -13
- package/tsconfig.test.json +0 -8
package/src/chat/chatLogic.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NamedNode, Node, st, term } from
|
|
2
|
-
import { ChatLogic, CreatedPaneOptions, NewPaneOptions, Chat } from
|
|
3
|
-
import { ns as namespace } from
|
|
4
|
-
import { determineChatContainer, newThing } from
|
|
1
|
+
import { NamedNode, Node, st, term } from "rdflib"
|
|
2
|
+
import { ChatLogic, CreatedPaneOptions, NewPaneOptions, Chat } from "../types"
|
|
3
|
+
import { ns as namespace } from "../util/ns";
|
|
4
|
+
import { determineChatContainer, newThing } from "../util/utils"
|
|
5
5
|
|
|
6
|
-
const CHAT_LOCATION_IN_CONTAINER =
|
|
6
|
+
const CHAT_LOCATION_IN_CONTAINER = "index.ttl#this"
|
|
7
7
|
|
|
8
8
|
export function createChatLogic(store, profileLogic): ChatLogic {
|
|
9
9
|
const ns = namespace
|
|
@@ -16,15 +16,15 @@ export function createChatLogic(store, profileLogic): ChatLogic {
|
|
|
16
16
|
// Some servers don't present a Link http response header
|
|
17
17
|
// if the container doesn't exist yet, so refetch the container
|
|
18
18
|
// now that it has been created:
|
|
19
|
-
await store.fetcher.load(chatContainer)
|
|
19
|
+
await store.fetcher.load(chatContainer);
|
|
20
20
|
|
|
21
21
|
// FIXME: check the Why value on this quad:
|
|
22
22
|
const chatAclDoc = store.any(
|
|
23
23
|
chatContainer,
|
|
24
|
-
new NamedNode(
|
|
25
|
-
)
|
|
24
|
+
new NamedNode("http://www.iana.org/assignments/link-relations/acl")
|
|
25
|
+
);
|
|
26
26
|
if (!chatAclDoc) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error("Chat ACL doc not found!");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const aclBody = `
|
|
@@ -43,64 +43,64 @@ export function createChatLogic(store, profileLogic): ChatLogic {
|
|
|
43
43
|
acl:default <.>;
|
|
44
44
|
acl:mode
|
|
45
45
|
acl:Read, acl:Append.
|
|
46
|
-
|
|
47
|
-
await store.fetcher.webOperation(
|
|
46
|
+
`;
|
|
47
|
+
await store.fetcher.webOperation("PUT", chatAclDoc.value, {
|
|
48
48
|
data: aclBody,
|
|
49
|
-
contentType:
|
|
50
|
-
})
|
|
49
|
+
contentType: "text/turtle",
|
|
50
|
+
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async function addToPrivateTypeIndex(chatThing, me) {
|
|
54
54
|
// Add to private type index
|
|
55
55
|
const privateTypeIndex = store.any(
|
|
56
56
|
me,
|
|
57
|
-
ns.solid(
|
|
58
|
-
) as NamedNode | null
|
|
57
|
+
ns.solid("privateTypeIndex")
|
|
58
|
+
) as NamedNode | null;
|
|
59
59
|
if (!privateTypeIndex) {
|
|
60
|
-
throw new Error(
|
|
60
|
+
throw new Error("Private type index not found!");
|
|
61
61
|
}
|
|
62
|
-
await store.fetcher.load(privateTypeIndex)
|
|
63
|
-
const reg = newThing(privateTypeIndex)
|
|
62
|
+
await store.fetcher.load(privateTypeIndex);
|
|
63
|
+
const reg = newThing(privateTypeIndex);
|
|
64
64
|
const ins = [
|
|
65
65
|
st(
|
|
66
66
|
reg,
|
|
67
|
-
ns.rdf(
|
|
68
|
-
ns.solid(
|
|
67
|
+
ns.rdf("type"),
|
|
68
|
+
ns.solid("TypeRegistration"),
|
|
69
69
|
privateTypeIndex.doc()
|
|
70
70
|
),
|
|
71
71
|
st(
|
|
72
72
|
reg,
|
|
73
|
-
ns.solid(
|
|
74
|
-
ns.meeting(
|
|
73
|
+
ns.solid("forClass"),
|
|
74
|
+
ns.meeting("LongChat"),
|
|
75
75
|
privateTypeIndex.doc()
|
|
76
76
|
),
|
|
77
|
-
st(reg, ns.solid(
|
|
78
|
-
]
|
|
77
|
+
st(reg, ns.solid("instance"), chatThing, privateTypeIndex.doc()),
|
|
78
|
+
];
|
|
79
79
|
await new Promise((resolve, reject) => {
|
|
80
80
|
store.updater.update([], ins, function (_uri, ok, errm) {
|
|
81
81
|
if (!ok) {
|
|
82
|
-
reject(new Error(errm))
|
|
82
|
+
reject(new Error(errm));
|
|
83
83
|
} else {
|
|
84
|
-
resolve(null)
|
|
84
|
+
resolve(null);
|
|
85
85
|
}
|
|
86
|
-
})
|
|
87
|
-
})
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
async function findChat(invitee: NamedNode): Promise<Chat> {
|
|
91
|
-
const me = await profileLogic.loadMe()
|
|
92
|
-
const podRoot = await profileLogic.getPodRoot(me)
|
|
93
|
-
const chatContainer = determineChatContainer(invitee, podRoot)
|
|
94
|
-
let exists = true
|
|
91
|
+
const me = await profileLogic.loadMe();
|
|
92
|
+
const podRoot = await profileLogic.getPodRoot(me);
|
|
93
|
+
const chatContainer = determineChatContainer(invitee, podRoot);
|
|
94
|
+
let exists = true;
|
|
95
95
|
try {
|
|
96
96
|
await store.fetcher.load(
|
|
97
|
-
new NamedNode(chatContainer.value +
|
|
98
|
-
)
|
|
97
|
+
new NamedNode(chatContainer.value + "index.ttl#this")
|
|
98
|
+
);
|
|
99
99
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
100
|
} catch (e) {
|
|
101
|
-
exists = false
|
|
101
|
+
exists = false;
|
|
102
102
|
}
|
|
103
|
-
return { me, chatContainer, exists }
|
|
103
|
+
return { me, chatContainer, exists };
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async function createChatThing(
|
|
@@ -110,60 +110,60 @@ export function createChatLogic(store, profileLogic): ChatLogic {
|
|
|
110
110
|
const created = await mintNew({
|
|
111
111
|
me,
|
|
112
112
|
newBase: chatContainer.value,
|
|
113
|
-
})
|
|
114
|
-
return created.newInstance
|
|
113
|
+
});
|
|
114
|
+
return created.newInstance;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function mintNew(newPaneOptions: NewPaneOptions): Promise<CreatedPaneOptions> {
|
|
118
|
-
const kb = store
|
|
119
|
-
const updater = kb.updater
|
|
118
|
+
const kb = store;
|
|
119
|
+
const updater = kb.updater;
|
|
120
120
|
if (newPaneOptions.me && !newPaneOptions.me.uri) {
|
|
121
|
-
throw new Error(
|
|
121
|
+
throw new Error("chat mintNew: Invalid userid " + newPaneOptions.me);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
const newInstance = (newPaneOptions.newInstance =
|
|
125
125
|
newPaneOptions.newInstance ||
|
|
126
|
-
kb.sym(newPaneOptions.newBase + CHAT_LOCATION_IN_CONTAINER))
|
|
127
|
-
const newChatDoc = newInstance.doc()
|
|
126
|
+
kb.sym(newPaneOptions.newBase + CHAT_LOCATION_IN_CONTAINER));
|
|
127
|
+
const newChatDoc = newInstance.doc();
|
|
128
128
|
|
|
129
129
|
kb.add(
|
|
130
130
|
newInstance,
|
|
131
|
-
ns.rdf(
|
|
132
|
-
ns.meeting(
|
|
131
|
+
ns.rdf("type"),
|
|
132
|
+
ns.meeting("LongChat"),
|
|
133
133
|
newChatDoc
|
|
134
|
-
)
|
|
135
|
-
kb.add(newInstance, ns.dc(
|
|
134
|
+
);
|
|
135
|
+
kb.add(newInstance, ns.dc("title"), "Chat channel", newChatDoc);
|
|
136
136
|
kb.add(
|
|
137
137
|
newInstance,
|
|
138
|
-
ns.dc(
|
|
138
|
+
ns.dc("created"),
|
|
139
139
|
term<Node>(new Date(Date.now())),
|
|
140
140
|
newChatDoc
|
|
141
|
-
)
|
|
141
|
+
);
|
|
142
142
|
if (newPaneOptions.me) {
|
|
143
|
-
kb.add(newInstance, ns.dc(
|
|
143
|
+
kb.add(newInstance, ns.dc("author"), newPaneOptions.me, newChatDoc);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
return new Promise(function (resolve, reject) {
|
|
147
147
|
updater?.put(
|
|
148
148
|
newChatDoc,
|
|
149
149
|
kb.statementsMatching(undefined, undefined, undefined, newChatDoc),
|
|
150
|
-
|
|
150
|
+
"text/turtle",
|
|
151
151
|
function (uri2, ok, message) {
|
|
152
152
|
if (ok) {
|
|
153
153
|
resolve({
|
|
154
154
|
...newPaneOptions,
|
|
155
155
|
newInstance,
|
|
156
|
-
})
|
|
156
|
+
});
|
|
157
157
|
} else {
|
|
158
158
|
reject(
|
|
159
159
|
new Error(
|
|
160
|
-
|
|
160
|
+
"FAILED to save new chat channel at: " + uri2 + " : " + message
|
|
161
161
|
)
|
|
162
|
-
)
|
|
162
|
+
);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
)
|
|
166
|
-
})
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/**
|
|
@@ -176,48 +176,48 @@ export function createChatLogic(store, profileLogic): ChatLogic {
|
|
|
176
176
|
invitee: NamedNode,
|
|
177
177
|
createIfMissing = true
|
|
178
178
|
): Promise<NamedNode | null> {
|
|
179
|
-
const { me, chatContainer, exists } = await findChat(invitee)
|
|
179
|
+
const { me, chatContainer, exists } = await findChat(invitee);
|
|
180
180
|
if (exists) {
|
|
181
|
-
return new NamedNode(chatContainer.value + CHAT_LOCATION_IN_CONTAINER)
|
|
181
|
+
return new NamedNode(chatContainer.value + CHAT_LOCATION_IN_CONTAINER);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
if (createIfMissing) {
|
|
185
|
-
const chatThing = await createChatThing(chatContainer, me)
|
|
186
|
-
await sendInvite(invitee, chatThing)
|
|
187
|
-
await setAcl(chatContainer, me, invitee)
|
|
188
|
-
await addToPrivateTypeIndex(chatThing, me)
|
|
189
|
-
return chatThing
|
|
185
|
+
const chatThing = await createChatThing(chatContainer, me);
|
|
186
|
+
await sendInvite(invitee, chatThing);
|
|
187
|
+
await setAcl(chatContainer, me, invitee);
|
|
188
|
+
await addToPrivateTypeIndex(chatThing, me);
|
|
189
|
+
return chatThing;
|
|
190
190
|
}
|
|
191
|
-
return null
|
|
191
|
+
return null;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
async function sendInvite(invitee: NamedNode, chatThing: NamedNode) {
|
|
195
|
-
await store.fetcher.load(invitee.doc())
|
|
195
|
+
await store.fetcher.load(invitee.doc());
|
|
196
196
|
const inviteeInbox = store.any(
|
|
197
197
|
invitee,
|
|
198
|
-
ns.ldp(
|
|
198
|
+
ns.ldp("inbox"),
|
|
199
199
|
undefined,
|
|
200
200
|
invitee.doc()
|
|
201
|
-
)
|
|
201
|
+
);
|
|
202
202
|
if (!inviteeInbox) {
|
|
203
|
-
throw new Error(`Invitee inbox not found! ${invitee.value}`)
|
|
203
|
+
throw new Error(`Invitee inbox not found! ${invitee.value}`);
|
|
204
204
|
}
|
|
205
205
|
const inviteBody = `
|
|
206
206
|
<> a <http://www.w3.org/ns/pim/meeting#LongChatInvite> ;
|
|
207
|
-
${ns.rdf(
|
|
208
|
-
|
|
207
|
+
${ns.rdf("seeAlso")} <${chatThing.value}> .
|
|
208
|
+
`;
|
|
209
209
|
|
|
210
210
|
const inviteResponse = await store.fetcher?.webOperation(
|
|
211
|
-
|
|
211
|
+
"POST",
|
|
212
212
|
inviteeInbox.value,
|
|
213
213
|
{
|
|
214
214
|
data: inviteBody,
|
|
215
|
-
contentType:
|
|
215
|
+
contentType: "text/turtle",
|
|
216
216
|
}
|
|
217
|
-
)
|
|
218
|
-
const locationStr = inviteResponse?.headers.get(
|
|
217
|
+
);
|
|
218
|
+
const locationStr = inviteResponse?.headers.get("location");
|
|
219
219
|
if (!locationStr) {
|
|
220
|
-
throw new Error(`Invite sending returned a ${inviteResponse?.status}`)
|
|
220
|
+
throw new Error(`Invite sending returned a ${inviteResponse?.status}`);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
return {
|
package/src/inbox/inboxLogic.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { NamedNode } from
|
|
2
|
-
import { InboxLogic } from
|
|
3
|
-
import { getArchiveUrl } from
|
|
1
|
+
import { NamedNode } from "rdflib";
|
|
2
|
+
import { InboxLogic } from "../types";
|
|
3
|
+
import { getArchiveUrl } from "../util/utils";
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
6
|
export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic): InboxLogic {
|
|
7
7
|
|
|
8
8
|
async function createInboxFor(peerWebId: string, nick: string) {
|
|
9
|
-
const myWebId: NamedNode = await profileLogic.loadMe()
|
|
10
|
-
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId)
|
|
11
|
-
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}
|
|
12
|
-
await containerLogic.createContainer(ourInbox)
|
|
9
|
+
const myWebId: NamedNode = await profileLogic.loadMe();
|
|
10
|
+
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
|
|
11
|
+
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
|
|
12
|
+
await containerLogic.createContainer(ourInbox);
|
|
13
13
|
// const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
|
|
14
14
|
await utilityLogic.setSinglePeerAccess({
|
|
15
15
|
ownerWebId: myWebId.value,
|
|
16
16
|
peerWebId,
|
|
17
17
|
accessToModes: 'acl:Append',
|
|
18
18
|
target: ourInbox
|
|
19
|
-
})
|
|
20
|
-
return ourInbox
|
|
19
|
+
});
|
|
20
|
+
return ourInbox;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async function getNewMessages(
|
|
24
24
|
user?: NamedNode
|
|
25
25
|
): Promise<NamedNode[]> {
|
|
26
26
|
if (!user) {
|
|
27
|
-
user = await profileLogic.loadMe()
|
|
27
|
+
user = await profileLogic.loadMe();
|
|
28
28
|
}
|
|
29
|
-
const inbox = await profileLogic.getMainInbox(user)
|
|
30
|
-
const urls = await containerLogic.getContainerMembers(inbox)
|
|
31
|
-
return urls.filter(url => !containerLogic.isContainer(url))
|
|
29
|
+
const inbox = await profileLogic.getMainInbox(user);
|
|
30
|
+
const urls = await containerLogic.getContainerMembers(inbox);
|
|
31
|
+
return urls.filter(url => !containerLogic.isContainer(url));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async function markAsRead(url: string, date: Date) {
|
|
35
|
-
const downloaded = await store.fetcher._fetch(url)
|
|
35
|
+
const downloaded = await store.fetcher._fetch(url);
|
|
36
36
|
if (downloaded.status !== 200) {
|
|
37
|
-
throw new Error(`Not OK! ${url}`)
|
|
37
|
+
throw new Error(`Not OK! ${url}`);
|
|
38
38
|
}
|
|
39
|
-
const archiveUrl = getArchiveUrl(url, date)
|
|
39
|
+
const archiveUrl = getArchiveUrl(url, date);
|
|
40
40
|
const options = {
|
|
41
41
|
method: 'PUT',
|
|
42
42
|
body: await downloaded.text(),
|
|
43
43
|
headers: [
|
|
44
44
|
['Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream']
|
|
45
45
|
]
|
|
46
|
-
}
|
|
47
|
-
const uploaded = await store.fetcher._fetch(archiveUrl, options)
|
|
46
|
+
};
|
|
47
|
+
const uploaded = await store.fetcher._fetch(archiveUrl, options);
|
|
48
48
|
if (uploaded.status.toString()[0] === '2') {
|
|
49
49
|
await store.fetcher._fetch(url, {
|
|
50
50
|
method: 'DELETE'
|
|
51
|
-
})
|
|
51
|
+
});
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
return {
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,8 @@ const store = solidLogicSingleton.store
|
|
|
9
9
|
export { ACL_LINK } from './acl/aclLogic'
|
|
10
10
|
export { offlineTestID, appContext } from './authn/authUtil'
|
|
11
11
|
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
12
|
-
export
|
|
12
|
+
export { createTypeIndexLogic } from './typeIndex/typeIndexLogic'
|
|
13
|
+
export { AppDetails, SolidNamespace, AuthenticationContext, SolidLogic } from './types'
|
|
13
14
|
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
14
15
|
|
|
15
16
|
export {
|
package/src/logic/CustomError.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
class CustomError extends Error {
|
|
2
2
|
constructor(message?: string) {
|
|
3
|
-
super(message)
|
|
3
|
+
super(message);
|
|
4
4
|
// see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
5
|
-
Object.setPrototypeOf(this, new.target.prototype) // restore prototype chain
|
|
6
|
-
this.name = new.target.name // stack traces display correctly now
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
|
|
6
|
+
this.name = new.target.name; // stack traces display correctly now
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -20,10 +20,10 @@ export class NotEditableError extends CustomError { }
|
|
|
20
20
|
export class WebOperationError extends CustomError {}
|
|
21
21
|
|
|
22
22
|
export class FetchError extends CustomError {
|
|
23
|
-
status: number
|
|
23
|
+
status: number;
|
|
24
24
|
|
|
25
25
|
constructor(status: number, message?: string) {
|
|
26
|
-
super(message)
|
|
27
|
-
this.status = status
|
|
26
|
+
super(message);
|
|
27
|
+
this.status = status;
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/logic/solidLogic.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Session } from
|
|
2
|
-
import * as rdf from
|
|
3
|
-
import { LiveStore, NamedNode, Statement } from
|
|
4
|
-
import { createAclLogic } from
|
|
5
|
-
import { SolidAuthnLogic } from
|
|
6
|
-
import { createChatLogic } from
|
|
7
|
-
import { createInboxLogic } from
|
|
8
|
-
import { createProfileLogic } from
|
|
9
|
-
import { createTypeIndexLogic } from
|
|
10
|
-
import { createContainerLogic } from
|
|
11
|
-
import { createUtilityLogic } from
|
|
12
|
-
import { AuthnLogic, SolidLogic } from
|
|
13
|
-
import * as debug from
|
|
1
|
+
import { Session } from "@inrupt/solid-client-authn-browser";
|
|
2
|
+
import * as rdf from "rdflib";
|
|
3
|
+
import { LiveStore, NamedNode, Statement } from "rdflib";
|
|
4
|
+
import { createAclLogic } from "../acl/aclLogic";
|
|
5
|
+
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic";
|
|
6
|
+
import { createChatLogic } from "../chat/chatLogic";
|
|
7
|
+
import { createInboxLogic } from "../inbox/inboxLogic";
|
|
8
|
+
import { createProfileLogic } from "../profile/profileLogic";
|
|
9
|
+
import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic";
|
|
10
|
+
import { createContainerLogic } from "../util/containerLogic";
|
|
11
|
+
import { createUtilityLogic } from "../util/utilityLogic";
|
|
12
|
+
import { AuthnLogic, SolidLogic } from "../types";
|
|
13
|
+
import * as debug from "../util/debug";
|
|
14
14
|
/*
|
|
15
15
|
** It is important to distinquish `fetch`, a function provided by the browser
|
|
16
16
|
** and `Fetcher`, a helper object for the rdflib Store which turns it
|
|
@@ -20,10 +20,10 @@ import * as debug from '../util/debug'
|
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
21
|
export function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: Session): SolidLogic {
|
|
22
22
|
|
|
23
|
-
debug.log(
|
|
23
|
+
debug.log("SolidLogic: Unique instance created. There should only be one of these.")
|
|
24
24
|
const store: LiveStore = rdf.graph() as LiveStore
|
|
25
|
-
rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher
|
|
26
|
-
store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater
|
|
25
|
+
rdf.fetcher(store, {fetch: specialFetch.fetch}); // Attach a web I/O module, store.fetcher
|
|
26
|
+
store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
|
|
27
27
|
store.features = [] // disable automatic node merging on store load
|
|
28
28
|
|
|
29
29
|
const authn: AuthnLogic = new SolidAuthnLogic(session)
|
|
@@ -38,7 +38,7 @@ export function createSolidLogic(specialFetch: { fetch: (url: any, requestInit:
|
|
|
38
38
|
debug.log('SolidAuthnLogic initialized')
|
|
39
39
|
|
|
40
40
|
function load(doc: NamedNode | NamedNode[] | string) {
|
|
41
|
-
return store.fetcher.load(doc)
|
|
41
|
+
return store.fetcher.load(doc);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
@@ -49,16 +49,16 @@ export function createSolidLogic(specialFetch: { fetch: (url: any, requestInit:
|
|
|
49
49
|
return new Promise((resolve, reject) => {
|
|
50
50
|
store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
51
51
|
if (!ok) {
|
|
52
|
-
reject(new Error(errorBody))
|
|
52
|
+
reject(new Error(errorBody));
|
|
53
53
|
} else {
|
|
54
|
-
resolve()
|
|
54
|
+
resolve();
|
|
55
55
|
}
|
|
56
|
-
}) // callback
|
|
57
|
-
}) // promise
|
|
56
|
+
}); // callback
|
|
57
|
+
}); // promise
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function clearStore() {
|
|
61
|
-
store.statements.slice().forEach(store.remove.bind(store))
|
|
61
|
+
store.statements.slice().forEach(store.remove.bind(store));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as debug from
|
|
2
|
-
import { authSession } from
|
|
3
|
-
import { createSolidLogic } from
|
|
1
|
+
import * as debug from "../util/debug"
|
|
2
|
+
import { authSession } from "../authSession/authSession"
|
|
3
|
+
import { createSolidLogic } from "./solidLogic"
|
|
4
4
|
|
|
5
5
|
const _fetch = async (url, requestInit) => {
|
|
6
6
|
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NamedNode } from
|
|
2
|
-
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from
|
|
3
|
-
import * as debug from
|
|
4
|
-
import { ns as namespace } from '../util/ns'
|
|
5
|
-
import { differentOrigin, suggestPreferencesFile } from
|
|
6
|
-
import { ProfileLogic } from
|
|
1
|
+
import { NamedNode } from "rdflib";
|
|
2
|
+
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from "../logic/CustomError";
|
|
3
|
+
import * as debug from "../util/debug";
|
|
4
|
+
import { ns as namespace } from '../util/ns';
|
|
5
|
+
import { differentOrigin, suggestPreferencesFile } from "../util/utils"
|
|
6
|
+
import { ProfileLogic } from "../types"
|
|
7
7
|
|
|
8
8
|
export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
9
9
|
const ns = namespace
|
|
@@ -55,13 +55,13 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
|
55
55
|
const msg = `Unable to load preference of user ${user}: ${err}`
|
|
56
56
|
debug.warn(msg)
|
|
57
57
|
if (err.response.status === 401) {
|
|
58
|
-
throw new UnauthorizedError()
|
|
58
|
+
throw new UnauthorizedError();
|
|
59
59
|
}
|
|
60
60
|
if (err.response.status === 403) {
|
|
61
61
|
if (differentOrigin(preferencesFile)) {
|
|
62
|
-
throw new CrossOriginForbiddenError()
|
|
62
|
+
throw new CrossOriginForbiddenError();
|
|
63
63
|
}
|
|
64
|
-
throw new SameOriginForbiddenError()
|
|
64
|
+
throw new SameOriginForbiddenError();
|
|
65
65
|
}
|
|
66
66
|
/*if (err.response.status === 404) {
|
|
67
67
|
throw new NotFoundError();
|
|
@@ -73,7 +73,7 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
|
73
73
|
|
|
74
74
|
async function loadProfile (user: NamedNode):Promise <NamedNode> {
|
|
75
75
|
if (!user) {
|
|
76
|
-
throw new Error(
|
|
76
|
+
throw new Error(`loadProfile: no user given.`)
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
79
|
await store.fetcher.load(user.doc())
|
|
@@ -84,33 +84,33 @@ export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
async function loadMe(): Promise<NamedNode> {
|
|
87
|
-
const me = authn.currentUser()
|
|
87
|
+
const me = authn.currentUser();
|
|
88
88
|
if (me === null) {
|
|
89
|
-
throw new Error(
|
|
89
|
+
throw new Error("Current user not found! Not logged in?");
|
|
90
90
|
}
|
|
91
|
-
await store.fetcher.load(me.doc())
|
|
92
|
-
return me
|
|
91
|
+
await store.fetcher.load(me.doc());
|
|
92
|
+
return me;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function getPodRoot(user: NamedNode): NamedNode {
|
|
96
|
-
const podRoot = findStorage(user)
|
|
96
|
+
const podRoot = findStorage(user);
|
|
97
97
|
if (!podRoot) {
|
|
98
|
-
throw new Error(
|
|
98
|
+
throw new Error("User pod root not found!");
|
|
99
99
|
}
|
|
100
|
-
return podRoot as NamedNode
|
|
100
|
+
return podRoot as NamedNode;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
async function getMainInbox(user: NamedNode): Promise<NamedNode> {
|
|
104
|
-
await store.fetcher.load(user)
|
|
105
|
-
const mainInbox = store.any(user, ns.ldp(
|
|
104
|
+
await store.fetcher.load(user);
|
|
105
|
+
const mainInbox = store.any(user, ns.ldp("inbox"), undefined, user.doc());
|
|
106
106
|
if (!mainInbox) {
|
|
107
|
-
throw new Error(
|
|
107
|
+
throw new Error("User main inbox not found!");
|
|
108
108
|
}
|
|
109
|
-
return mainInbox as NamedNode
|
|
109
|
+
return mainInbox as NamedNode;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function findStorage(me: NamedNode) {
|
|
113
|
-
return store.any(me, ns.space(
|
|
113
|
+
return store.any(me, ns.space("storage"), undefined, me.doc());
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
return {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { NamedNode, st, sym } from 'rdflib'
|
|
2
2
|
import { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'
|
|
3
|
-
import * as debug from
|
|
3
|
+
import * as debug from "../util/debug"
|
|
4
4
|
import { ns as namespace } from '../util/ns'
|
|
5
|
-
import { newThing } from
|
|
5
|
+
import { newThing } from "../util/utils"
|
|
6
6
|
|
|
7
7
|
export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {
|
|
8
8
|
const ns = namespace
|
|
9
9
|
|
|
10
10
|
function getRegistrations(instance, theClass) {
|
|
11
11
|
return store
|
|
12
|
-
.each(undefined, ns.solid(
|
|
12
|
+
.each(undefined, ns.solid("instance"), instance)
|
|
13
13
|
.filter((r) => {
|
|
14
|
-
return store.holds(r, ns.solid(
|
|
15
|
-
})
|
|
14
|
+
return store.holds(r, ns.solid("forClass"), theClass);
|
|
15
|
+
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {
|
|
19
|
-
if (!user) throw new Error(
|
|
19
|
+
if (!user) throw new Error(`loadTypeIndexesFor: No user given`)
|
|
20
20
|
const profile = await profileLogic.loadProfile(user)
|
|
21
21
|
|
|
22
22
|
const suggestion = suggestPublicTypeIndex(user)
|
|
@@ -46,7 +46,7 @@ export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic):
|
|
|
46
46
|
let privateTypeIndex
|
|
47
47
|
try {
|
|
48
48
|
privateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile) ||
|
|
49
|
-
await utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex') as NamedNode, suggestedPrivateTypeIndex, preferencesFile)
|
|
49
|
+
await utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex') as NamedNode, suggestedPrivateTypeIndex, preferencesFile);
|
|
50
50
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
51
|
} catch (err) {
|
|
52
52
|
const message = `User ${user} has no pointer in preference file to privateTypeIndex file.`
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Session } from
|
|
2
|
-
import { LiveStore, NamedNode, Statement } from
|
|
1
|
+
import { Session } from "@inrupt/solid-client-authn-browser"
|
|
2
|
+
import { LiveStore, NamedNode, Statement } from "rdflib"
|
|
3
3
|
|
|
4
4
|
export type AppDetails = {
|
|
5
5
|
noun: string
|