solid-logic 1.3.17-1274f5aa → 1.3.17-1aa535b3
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/jest.config.js +1 -1
- package/lib/acl/aclLogic.d.ts +12 -30
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +151 -116
- package/lib/acl/aclLogic.js.map +1 -1
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +2 -2
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/chat/chatLogic.d.ts +16 -0
- package/lib/chat/chatLogic.d.ts.map +1 -0
- package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/discovery/discoveryLogic.d.ts +4 -8
- package/lib/discovery/discoveryLogic.d.ts.map +1 -1
- package/lib/discovery/discoveryLogic.js +37 -22
- package/lib/discovery/discoveryLogic.js.map +1 -1
- package/lib/inbox/inboxLogic.d.ts +7 -0
- package/lib/inbox/inboxLogic.d.ts.map +1 -0
- package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +10 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +76 -45
- package/lib/index.js.map +1 -1
- package/lib/logic/CustomError.d.ts +4 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +17 -1
- package/lib/logic/CustomError.js.map +1 -1
- package/lib/logic/solidLogicSingleton.d.ts +35 -3
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
- package/lib/logic/solidLogicSingleton.js +87 -8
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/profileLogic.d.ts +13 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +268 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +31 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +650 -295
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/util/containerLogic.d.ts +11 -0
- package/lib/util/containerLogic.d.ts.map +1 -0
- package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/utilityLogic.d.ts +15 -0
- package/lib/util/utilityLogic.d.ts.map +1 -0
- package/lib/util/utilityLogic.js +272 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +8 -0
- package/lib/util/utils.d.ts.map +1 -0
- package/lib/util/utils.js +48 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/acl/aclLogic.ts +135 -119
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/discovery/discoveryLogic.ts +19 -32
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +71 -31
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/solidLogicSingleton.ts +160 -7
- package/src/profile/profileLogic.ts +134 -0
- package/src/typeIndex/typeIndexLogic.ts +417 -153
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/ns.js +5 -0
- package/src/util/utilityLogic.ts +155 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +13 -4
- package/test/chatLogic.test.ts +70 -71
- package/test/container.test.ts +56 -0
- package/test/discoveryLogic.test.ts +502 -530
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +1 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +11 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +49 -22
- package/test/typeIndexLogicPart2.test.ts +485 -0
- package/test/utilityLogic.test.ts +172 -126
- package/test/utils.test.ts +32 -0
- package/lib/chat/ChatLogic.d.ts +0 -26
- package/lib/chat/ChatLogic.d.ts.map +0 -1
- package/lib/chat/ChatLogic.js.map +0 -1
- package/lib/chat/determineChatContainer.d.ts +0 -3
- package/lib/chat/determineChatContainer.d.ts.map +0 -1
- package/lib/chat/determineChatContainer.js +0 -12
- package/lib/chat/determineChatContainer.js.map +0 -1
- package/lib/inbox/InboxLogic.d.ts +0 -18
- package/lib/inbox/InboxLogic.d.ts.map +0 -1
- package/lib/inbox/InboxLogic.js.map +0 -1
- package/lib/logic/SolidLogic.d.ts +0 -48
- package/lib/logic/SolidLogic.d.ts.map +0 -1
- package/lib/logic/SolidLogic.js +0 -321
- package/lib/logic/SolidLogic.js.map +0 -1
- package/lib/profile/ProfileLogic.d.ts +0 -13
- package/lib/profile/ProfileLogic.d.ts.map +0 -1
- package/lib/profile/ProfileLogic.js.map +0 -1
- package/lib/util/UtilityLogic.d.ts +0 -33
- package/lib/util/UtilityLogic.d.ts.map +0 -1
- package/lib/util/UtilityLogic.js +0 -240
- package/lib/util/UtilityLogic.js.map +0 -1
- package/lib/util/uri.d.ts +0 -3
- package/lib/util/uri.d.ts.map +0 -1
- package/lib/util/uri.js +0 -9
- package/lib/util/uri.js.map +0 -1
- package/src/chat/ChatLogic.ts +0 -244
- package/src/chat/determineChatContainer.ts +0 -14
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/logic/SolidLogic.ts +0 -262
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { NamedNode } from "rdflib";
|
|
2
|
+
import { getArchiveUrl } from "../util/utils";
|
|
3
|
+
|
|
4
|
+
export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic) {
|
|
5
|
+
|
|
6
|
+
async function createInboxFor(peerWebId: string, nick: string) {
|
|
7
|
+
const myWebId: NamedNode = await profileLogic.loadMe();
|
|
8
|
+
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
|
|
9
|
+
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
|
|
10
|
+
await containerLogic.createContainer(ourInbox);
|
|
11
|
+
const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
|
|
12
|
+
await utilityLogic.setSinglePeerAccess({
|
|
13
|
+
ownerWebId: myWebId.value,
|
|
14
|
+
peerWebId,
|
|
15
|
+
accessToModes: 'acl:Append',
|
|
16
|
+
target: ourInbox
|
|
17
|
+
});
|
|
18
|
+
return ourInbox;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getNewMessages(
|
|
22
|
+
user?: NamedNode
|
|
23
|
+
): Promise<string[]> {
|
|
24
|
+
if (!user) {
|
|
25
|
+
user = await profileLogic.loadMe();
|
|
26
|
+
}
|
|
27
|
+
const inbox = await profileLogic.getMainInbox(user);
|
|
28
|
+
const urls = await containerLogic.getContainerMembers(inbox.value);
|
|
29
|
+
return urls.filter(url => !containerLogic.isContainer(url));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function markAsRead(url: string, date: Date) {
|
|
33
|
+
const downloaded = await store.fetcher._fetch(url);
|
|
34
|
+
if (downloaded.status !== 200) {
|
|
35
|
+
throw new Error(`Not OK! ${url}`);
|
|
36
|
+
}
|
|
37
|
+
const archiveUrl = getArchiveUrl(url, date);
|
|
38
|
+
const options = {
|
|
39
|
+
method: 'PUT',
|
|
40
|
+
body: await downloaded.text(),
|
|
41
|
+
headers: [
|
|
42
|
+
['Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream']
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
const uploaded = await store.fetcher._fetch(archiveUrl, options);
|
|
46
|
+
if (uploaded.status.toString()[0] === '2') {
|
|
47
|
+
await store.fetcher._fetch(url, {
|
|
48
|
+
method: 'DELETE'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
createInboxFor,
|
|
54
|
+
getNewMessages,
|
|
55
|
+
markAsRead
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,52 +1,92 @@
|
|
|
1
1
|
// Make these variables directly accessible as it is what you need most of the time
|
|
2
2
|
// This also makes these variable globaly accesible in mashlib
|
|
3
|
-
import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
-
const authn = solidLogicSingleton.authn
|
|
5
|
-
const authSession = solidLogicSingleton.authn.authSession
|
|
6
|
-
const store = solidLogicSingleton.store
|
|
3
|
+
//import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
+
//const authn = solidLogicSingleton.authn
|
|
5
|
+
//const authSession = solidLogicSingleton.authn.authSession
|
|
6
|
+
//const store = solidLogicSingleton.store
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export {
|
|
9
|
+
ACL_LINK
|
|
10
|
+
} from './acl/aclLogic'
|
|
10
11
|
|
|
11
12
|
export {
|
|
13
|
+
findAclDocUrl,
|
|
12
14
|
setACLUserPublic,
|
|
13
|
-
genACLText
|
|
14
|
-
} from './
|
|
15
|
+
genACLText,
|
|
16
|
+
} from './logic/solidLogicSingleton'
|
|
15
17
|
|
|
16
18
|
export {
|
|
17
19
|
ensureTypeIndexes,
|
|
18
20
|
loadTypeIndexes,
|
|
19
21
|
registerInTypeIndex,
|
|
20
|
-
loadIndex
|
|
21
|
-
|
|
22
|
+
loadIndex,
|
|
23
|
+
ensureOneTypeIndex,
|
|
24
|
+
putIndex,
|
|
25
|
+
makeIndexIfNecessary,
|
|
26
|
+
loadIndexes,
|
|
27
|
+
getTypeIndex,
|
|
28
|
+
getRegistrations,
|
|
29
|
+
//NEW function for discovery
|
|
30
|
+
loadTypeIndexesFor,
|
|
31
|
+
loadCommunityTypeIndexes,
|
|
32
|
+
loadAllTypeIndexes,
|
|
33
|
+
getScopedAppInstances,
|
|
34
|
+
getAppInstances,
|
|
35
|
+
suggestPublicTypeIndex,
|
|
36
|
+
suggestPrivateTypeIndex,
|
|
37
|
+
registerInstanceInTypeIndex,
|
|
38
|
+
deleteTypeIndexRegistration,
|
|
39
|
+
getScopedAppsFromIndex
|
|
40
|
+
} from './logic/solidLogicSingleton'
|
|
22
41
|
|
|
23
|
-
// Generate by
|
|
24
|
-
// grep export src/discovery/discoveryLogic.ts | sed -e 's/export //g' | sed -e 's/async //g'| sed -e 's/function //g' | sed -e 's/ .*/,/g' | sort
|
|
25
42
|
export {
|
|
26
|
-
|
|
43
|
+
setAcl,
|
|
44
|
+
addToPrivateTypeIndex,
|
|
45
|
+
findChat,
|
|
46
|
+
createChatThing,
|
|
47
|
+
getChat,
|
|
48
|
+
sendInvite,
|
|
49
|
+
mintNew
|
|
50
|
+
} from './logic/solidLogicSingleton'
|
|
51
|
+
|
|
52
|
+
export { offlineTestID, appContext } from './authn/authUtil'
|
|
53
|
+
export { createInboxFor, getNewMessages, markAsRead } from './logic/solidLogicSingleton'
|
|
54
|
+
export {
|
|
55
|
+
recursiveDelete,
|
|
56
|
+
setSinglePeerAccess,
|
|
57
|
+
createEmptyRdfDoc,
|
|
58
|
+
//NEW function for discovery
|
|
27
59
|
followOrCreateLink,
|
|
28
|
-
getAppInstances,
|
|
29
|
-
getScopedAppInstances,
|
|
30
|
-
getScopedAppsFromIndex,
|
|
31
|
-
loadAllTypeIndexes,
|
|
32
|
-
loadCommunityTypeIndexes,
|
|
33
60
|
loadOrCreateIfNotExists,
|
|
61
|
+
} from './logic/solidLogicSingleton'
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
ensureLoadedPreferences,
|
|
65
|
+
loadMe,
|
|
66
|
+
getPodRoot,
|
|
67
|
+
getMainInbox,
|
|
68
|
+
findStorage,
|
|
69
|
+
//NEW content from discovery
|
|
34
70
|
loadPreferences,
|
|
35
71
|
loadProfile,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
suggestPrivateTypeIndex,
|
|
40
|
-
suggestPublicTypeIndex,
|
|
41
|
-
uniqueNodes
|
|
42
|
-
} from './discovery/discoveryLogic'
|
|
72
|
+
//NEW function for discovery
|
|
73
|
+
silencedLoadPreferences
|
|
74
|
+
} from './logic/solidLogicSingleton'
|
|
43
75
|
|
|
44
|
-
export { SolidLogic } from './logic/SolidLogic'
|
|
45
|
-
export { offlineTestID, appContext } from './authn/authUtil'
|
|
46
|
-
export { ACL_LINK } from './util/UtilityLogic'
|
|
47
76
|
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
isContainer,
|
|
80
|
+
createContainer,
|
|
81
|
+
getContainerElements,
|
|
82
|
+
getContainerMembers
|
|
83
|
+
} from './logic/solidLogicSingleton'
|
|
84
|
+
|
|
85
|
+
export { authn, authSession, store } from './logic/solidLogicSingleton'
|
|
86
|
+
|
|
87
|
+
//export { SolidLogic } from './logic/SolidLogic'
|
|
48
88
|
export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
|
|
49
89
|
// solidLogicSingleton is exported entirely because it is used in solid-panes
|
|
50
|
-
export { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
51
|
-
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
|
|
52
|
-
|
|
90
|
+
//export { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
91
|
+
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
92
|
+
|
package/src/logic/CustomError.ts
CHANGED
|
@@ -6,7 +6,7 @@ class CustomError extends Error {
|
|
|
6
6
|
this.name = new.target.name; // stack traces display correctly now
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
export class UnauthorizedError extends CustomError {}
|
|
11
11
|
|
|
12
12
|
export class CrossOriginForbiddenError extends CustomError {}
|
|
@@ -15,6 +15,10 @@ export class SameOriginForbiddenError extends CustomError {}
|
|
|
15
15
|
|
|
16
16
|
export class NotFoundError extends CustomError {}
|
|
17
17
|
|
|
18
|
+
export class NotEditableError extends CustomError { }
|
|
19
|
+
|
|
20
|
+
export class WebOperationError extends CustomError {}
|
|
21
|
+
|
|
18
22
|
export class FetchError extends CustomError {
|
|
19
23
|
status: number;
|
|
20
24
|
|
|
@@ -1,20 +1,173 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as rdf from "rdflib"
|
|
2
|
+
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic"
|
|
2
3
|
import { authSession } from "../authSession/authSession"
|
|
3
|
-
import {
|
|
4
|
+
import { createContainerLogic } from "../util/containerLogic"
|
|
5
|
+
import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic"
|
|
6
|
+
import * as debug from "../util/debug"
|
|
7
|
+
import { createUtilityLogic } from "../util/utilityLogic"
|
|
8
|
+
import { createProfileLogic } from "../profile/profileLogic"
|
|
9
|
+
import { createInboxLogic } from "../inbox/inboxLogic"
|
|
10
|
+
import { createChatLogic } from "../chat/chatLogic"
|
|
11
|
+
import { createAclLogic } from "../acl/aclLogic"
|
|
4
12
|
|
|
5
13
|
const _fetch = async (url, requestInit) => {
|
|
6
14
|
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
7
15
|
if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
|
|
8
|
-
// In fact
|
|
16
|
+
// In fact fetch should respect credentials omit itself
|
|
9
17
|
return authSession.fetch(url, requestInit)
|
|
10
18
|
} else {
|
|
11
19
|
return window.fetch(url, requestInit)
|
|
12
20
|
}
|
|
13
21
|
}
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
debug.log("SolidLogicSingleton: Unique instance created. There should only be one of these.")
|
|
24
|
+
|
|
25
|
+
const store = rdf.graph() as rdf.LiveStore; // Make a Quad store
|
|
26
|
+
rdf.fetcher(store, { fetch: _fetch}); // Attach a web I/O module, store.fetcher
|
|
27
|
+
store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
|
|
28
|
+
store.features = [] // disable automatic node merging on store load
|
|
29
|
+
|
|
30
|
+
debug.log('SolidAuthnLogic initialized')
|
|
31
|
+
const authn = new SolidAuthnLogic(authSession)
|
|
32
|
+
|
|
33
|
+
const aclLogic = createAclLogic(store)
|
|
34
|
+
const {
|
|
35
|
+
findAclDocUrl,
|
|
36
|
+
setACLUserPublic,
|
|
37
|
+
genACLText
|
|
38
|
+
} = aclLogic
|
|
39
|
+
|
|
40
|
+
const containerLogic = createContainerLogic(store)
|
|
41
|
+
const {
|
|
42
|
+
isContainer,
|
|
43
|
+
createContainer,
|
|
44
|
+
getContainerElements,
|
|
45
|
+
getContainerMembers
|
|
46
|
+
} = containerLogic
|
|
17
47
|
|
|
18
|
-
|
|
48
|
+
const utilityLogic = createUtilityLogic(store, aclLogic, containerLogic)
|
|
49
|
+
const {
|
|
50
|
+
recursiveDelete,
|
|
51
|
+
setSinglePeerAccess,
|
|
52
|
+
createEmptyRdfDoc,
|
|
53
|
+
followOrCreateLink,
|
|
54
|
+
loadOrCreateIfNotExists
|
|
55
|
+
} = utilityLogic
|
|
56
|
+
|
|
57
|
+
const profileLogic = createProfileLogic(store, authn, utilityLogic)
|
|
58
|
+
const {
|
|
59
|
+
ensureLoadedPreferences,
|
|
60
|
+
loadMe,
|
|
61
|
+
getPodRoot,
|
|
62
|
+
getMainInbox,
|
|
63
|
+
findStorage,
|
|
64
|
+
loadPreferences,
|
|
65
|
+
loadProfile,
|
|
66
|
+
silencedLoadPreferences
|
|
67
|
+
} = profileLogic
|
|
68
|
+
|
|
69
|
+
const chatLogic = createChatLogic(store, profileLogic)
|
|
70
|
+
const {
|
|
71
|
+
setAcl,
|
|
72
|
+
addToPrivateTypeIndex,
|
|
73
|
+
findChat,
|
|
74
|
+
createChatThing,
|
|
75
|
+
getChat,
|
|
76
|
+
sendInvite,
|
|
77
|
+
mintNew
|
|
78
|
+
} = chatLogic
|
|
79
|
+
|
|
80
|
+
const inboxLogic = createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic)
|
|
81
|
+
const {
|
|
82
|
+
createInboxFor,
|
|
83
|
+
getNewMessages,
|
|
84
|
+
markAsRead
|
|
85
|
+
} = inboxLogic
|
|
86
|
+
|
|
87
|
+
const typeIndexLogic = createTypeIndexLogic(store, authn, profileLogic, utilityLogic)
|
|
88
|
+
const {
|
|
89
|
+
ensureTypeIndexes,
|
|
90
|
+
loadTypeIndexes,
|
|
91
|
+
registerInTypeIndex,
|
|
92
|
+
loadIndex,
|
|
93
|
+
ensureOneTypeIndex,
|
|
94
|
+
putIndex,
|
|
95
|
+
makeIndexIfNecessary,
|
|
96
|
+
loadIndexes,
|
|
97
|
+
getTypeIndex,
|
|
98
|
+
getRegistrations,
|
|
99
|
+
loadTypeIndexesFor,
|
|
100
|
+
loadCommunityTypeIndexes,
|
|
101
|
+
loadAllTypeIndexes,
|
|
102
|
+
getScopedAppInstances,
|
|
103
|
+
getAppInstances,
|
|
104
|
+
suggestPublicTypeIndex,
|
|
105
|
+
suggestPrivateTypeIndex,
|
|
106
|
+
registerInstanceInTypeIndex,
|
|
107
|
+
deleteTypeIndexRegistration,
|
|
108
|
+
getScopedAppsFromIndex
|
|
109
|
+
} = typeIndexLogic
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
store,
|
|
113
|
+
authn,
|
|
114
|
+
authSession,
|
|
115
|
+
//unilityLogic
|
|
116
|
+
recursiveDelete,
|
|
117
|
+
setSinglePeerAccess,
|
|
118
|
+
createEmptyRdfDoc,
|
|
119
|
+
followOrCreateLink,
|
|
120
|
+
loadOrCreateIfNotExists,
|
|
121
|
+
//containerLogic
|
|
122
|
+
isContainer,
|
|
123
|
+
createContainer,
|
|
124
|
+
getContainerElements,
|
|
125
|
+
getContainerMembers,
|
|
126
|
+
//typeIndexLogic
|
|
127
|
+
ensureTypeIndexes,
|
|
128
|
+
loadTypeIndexes,
|
|
129
|
+
registerInTypeIndex,
|
|
130
|
+
loadIndex,
|
|
131
|
+
ensureOneTypeIndex,
|
|
132
|
+
putIndex,
|
|
133
|
+
makeIndexIfNecessary,
|
|
134
|
+
loadIndexes,
|
|
135
|
+
getTypeIndex,
|
|
136
|
+
getRegistrations,
|
|
137
|
+
loadTypeIndexesFor,
|
|
138
|
+
loadCommunityTypeIndexes,
|
|
139
|
+
loadAllTypeIndexes,
|
|
140
|
+
getScopedAppInstances,
|
|
141
|
+
getAppInstances,
|
|
142
|
+
suggestPublicTypeIndex,
|
|
143
|
+
suggestPrivateTypeIndex,
|
|
144
|
+
registerInstanceInTypeIndex,
|
|
145
|
+
deleteTypeIndexRegistration,
|
|
146
|
+
getScopedAppsFromIndex,
|
|
147
|
+
//profileLogic
|
|
148
|
+
ensureLoadedPreferences,
|
|
149
|
+
loadMe,
|
|
150
|
+
getPodRoot,
|
|
151
|
+
getMainInbox,
|
|
152
|
+
findStorage,
|
|
153
|
+
loadPreferences,
|
|
154
|
+
loadProfile,
|
|
155
|
+
silencedLoadPreferences,
|
|
156
|
+
//inboxLogic
|
|
157
|
+
createInboxFor,
|
|
158
|
+
getNewMessages,
|
|
159
|
+
markAsRead,
|
|
160
|
+
//chatLogic
|
|
161
|
+
setAcl,
|
|
162
|
+
addToPrivateTypeIndex,
|
|
163
|
+
findChat,
|
|
164
|
+
createChatThing,
|
|
165
|
+
getChat,
|
|
166
|
+
sendInvite,
|
|
167
|
+
mintNew,
|
|
168
|
+
//aclLogic
|
|
169
|
+
findAclDocUrl,
|
|
170
|
+
setACLUserPublic,
|
|
171
|
+
genACLText
|
|
172
|
+
}
|
|
19
173
|
|
|
20
|
-
export { solidLogicSingleton }
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { NamedNode } from "rdflib";
|
|
2
|
+
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from "../logic/CustomError";
|
|
3
|
+
import { AuthenticationContext } from "../types";
|
|
4
|
+
import * as debug from "../util/debug";
|
|
5
|
+
import { differentOrigin, suggestPreferencesFile } from "../util/utils";
|
|
6
|
+
import { ns as namespace } from '../util/ns'
|
|
7
|
+
|
|
8
|
+
export function createProfileLogic(store, authn, utilityLogic) {
|
|
9
|
+
const ns = namespace
|
|
10
|
+
|
|
11
|
+
async function ensureLoadedPreferences (context: AuthenticationContext) {
|
|
12
|
+
if (!context.me) throw new Error('@@ ensureLoadedPreferences: no user specified')
|
|
13
|
+
context.publicProfile = await loadProfile(context.me)
|
|
14
|
+
context.preferencesFile = await silencedLoadPreferences(context.me)
|
|
15
|
+
return context
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* loads the preference without throwing errors - if it can create it it does so.
|
|
20
|
+
* remark: it still throws error if it cannot load profile.
|
|
21
|
+
* @param user
|
|
22
|
+
* @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it
|
|
23
|
+
*/
|
|
24
|
+
async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {
|
|
25
|
+
try {
|
|
26
|
+
return await loadPreferences(user)
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* loads the preference without returning different errors if it cannot create or load it.
|
|
34
|
+
* remark: it also throws error if it cannot load profile.
|
|
35
|
+
* @param user
|
|
36
|
+
* @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it
|
|
37
|
+
*/
|
|
38
|
+
async function loadPreferences (user: NamedNode): Promise <NamedNode> {
|
|
39
|
+
await loadProfile(user)
|
|
40
|
+
|
|
41
|
+
const possiblePreferencesFile = suggestPreferencesFile(user)
|
|
42
|
+
let preferencesFile
|
|
43
|
+
try {
|
|
44
|
+
preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const message = `User ${user} has no pointer in profile to preferences file.`
|
|
47
|
+
debug.warn(message)
|
|
48
|
+
// we are listing the possible errors
|
|
49
|
+
if (err instanceof NotEditableError) { throw err }
|
|
50
|
+
if (err instanceof WebOperationError) { throw err }
|
|
51
|
+
if (err instanceof UnauthorizedError) { throw err }
|
|
52
|
+
if (err instanceof CrossOriginForbiddenError) { throw err }
|
|
53
|
+
if (err instanceof SameOriginForbiddenError) { throw err }
|
|
54
|
+
if (err instanceof FetchError) { throw err }
|
|
55
|
+
throw err
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let response
|
|
59
|
+
try {
|
|
60
|
+
response = await store.fetcher.load(preferencesFile as NamedNode)
|
|
61
|
+
} catch (err) { // Maybe a permission problem or origin problem
|
|
62
|
+
const msg = `Unable to load preference of user ${user}: ${err}`
|
|
63
|
+
debug.warn(msg)
|
|
64
|
+
if (err.response.status === 401) {
|
|
65
|
+
throw new UnauthorizedError();
|
|
66
|
+
}
|
|
67
|
+
if (err.response.status === 403) {
|
|
68
|
+
if (differentOrigin(preferencesFile)) {
|
|
69
|
+
throw new CrossOriginForbiddenError();
|
|
70
|
+
}
|
|
71
|
+
throw new SameOriginForbiddenError();
|
|
72
|
+
}
|
|
73
|
+
/*if (err.response.status === 404) {
|
|
74
|
+
throw new NotFoundError();
|
|
75
|
+
}*/
|
|
76
|
+
throw new Error(msg)
|
|
77
|
+
}
|
|
78
|
+
return preferencesFile as NamedNode
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function loadProfile (user: NamedNode):Promise <NamedNode> {
|
|
82
|
+
if (!user) {
|
|
83
|
+
throw new Error(`loadProfile: no user given.`)
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await store.fetcher.load(user.doc())
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw new Error(`Unable to load profile of user ${user}: ${err}`)
|
|
89
|
+
}
|
|
90
|
+
return user.doc()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function loadMe(): Promise<NamedNode> {
|
|
94
|
+
const me = authn.currentUser();
|
|
95
|
+
if (me === null) {
|
|
96
|
+
throw new Error("Current user not found! Not logged in?");
|
|
97
|
+
}
|
|
98
|
+
await store.fetcher.load(me.doc());
|
|
99
|
+
return me;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getPodRoot(user: NamedNode): NamedNode {
|
|
103
|
+
const podRoot = findStorage(user);
|
|
104
|
+
if (!podRoot) {
|
|
105
|
+
throw new Error("User pod root not found!");
|
|
106
|
+
}
|
|
107
|
+
return podRoot as NamedNode;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function getMainInbox(user: NamedNode): Promise<NamedNode> {
|
|
111
|
+
await store.fetcher.load(user);
|
|
112
|
+
const mainInbox = store.any(user, ns.ldp("inbox"), undefined, user.doc());
|
|
113
|
+
if (!mainInbox) {
|
|
114
|
+
throw new Error("User main inbox not found!");
|
|
115
|
+
}
|
|
116
|
+
return mainInbox as NamedNode;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function findStorage(me: NamedNode) {
|
|
120
|
+
return store.any(me, ns.space("storage"), undefined, me.doc());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
ensureLoadedPreferences,
|
|
125
|
+
loadMe,
|
|
126
|
+
getPodRoot,
|
|
127
|
+
getMainInbox,
|
|
128
|
+
findStorage,
|
|
129
|
+
loadPreferences,
|
|
130
|
+
loadProfile,
|
|
131
|
+
silencedLoadPreferences
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|