solid-logic 1.3.17-8a332867 → 1.3.17-a2363122
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 +152 -119
- 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/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 +18 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +77 -34
- 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/SolidLogic.d.ts +8 -34
- package/lib/logic/SolidLogic.d.ts.map +1 -1
- package/lib/logic/SolidLogic.js +16 -250
- package/lib/logic/SolidLogic.js.map +1 -1
- package/lib/logic/solidLogicSingleton.js +1 -1
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/logic/solidLogicSingletonNew.d.ts +68 -0
- package/lib/logic/solidLogicSingletonNew.d.ts.map +1 -0
- package/lib/logic/solidLogicSingletonNew.js +221 -0
- package/lib/logic/solidLogicSingletonNew.js.map +1 -0
- 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 +18 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +304 -296
- 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/ns.d.ts +2 -0
- package/lib/util/ns.d.ts.map +1 -0
- package/lib/util/ns.js +34 -0
- package/lib/util/ns.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 +3 -1
- package/src/acl/aclLogic.ts +136 -118
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +123 -29
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/SolidLogic.ts +30 -211
- package/src/logic/solidLogicSingleton.ts +1 -1
- package/src/logic/solidLogicSingletonNew.ts +213 -0
- package/src/profile/profileLogic.ts +134 -0
- package/src/typeIndex/typeIndexLogic.ts +175 -182
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/ns.ts +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/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +1 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +10 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +487 -30
- 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/discovery/discoveryLogic.d.ts +0 -40
- package/lib/discovery/discoveryLogic.d.ts.map +0 -1
- package/lib/discovery/discoveryLogic.js +0 -494
- package/lib/discovery/discoveryLogic.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/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/discovery/discoveryLogic.ts +0 -310
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
- package/test/discoveryLogic.test.ts +0 -740
package/src/index.ts
CHANGED
|
@@ -1,51 +1,145 @@
|
|
|
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
3
|
import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
+
|
|
4
5
|
const authn = solidLogicSingleton.authn
|
|
5
6
|
const authSession = solidLogicSingleton.authn.authSession
|
|
6
7
|
const store = solidLogicSingleton.store
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const aclLogic = solidLogicSingleton.aclLogic
|
|
10
|
+
const utilityLogic = solidLogicSingleton.utilityLogic
|
|
11
|
+
const containerLogic = solidLogicSingleton.containerLogic
|
|
12
|
+
const profileLogic = solidLogicSingleton.profileLogic
|
|
13
|
+
const inboxLogic = solidLogicSingleton.inboxLogic
|
|
14
|
+
const typeIndexLogic = solidLogicSingleton.typeIndexLogic
|
|
15
|
+
const chatLogic = solidLogicSingleton.chatLogic
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
const {
|
|
18
|
+
findAclDocUrl,
|
|
12
19
|
setACLUserPublic,
|
|
13
|
-
genACLText
|
|
14
|
-
}
|
|
20
|
+
genACLText,
|
|
21
|
+
} = aclLogic
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
ensureTypeIndexes,
|
|
18
|
-
loadTypeIndexes,
|
|
23
|
+
const {
|
|
19
24
|
registerInTypeIndex,
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
getRegistrations,
|
|
26
|
+
//NEW function for discovery
|
|
27
|
+
loadTypeIndexesFor,
|
|
28
|
+
loadCommunityTypeIndexes,
|
|
29
|
+
loadAllTypeIndexes,
|
|
30
|
+
getScopedAppInstances,
|
|
31
|
+
getAppInstances,
|
|
32
|
+
suggestPublicTypeIndex,
|
|
33
|
+
suggestPrivateTypeIndex,
|
|
34
|
+
deleteTypeIndexRegistration,
|
|
35
|
+
getScopedAppsFromIndex
|
|
36
|
+
} = typeIndexLogic
|
|
22
37
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
const {
|
|
39
|
+
setAcl,
|
|
40
|
+
addToPrivateTypeIndex,
|
|
41
|
+
findChat,
|
|
42
|
+
createChatThing,
|
|
43
|
+
getChat,
|
|
44
|
+
sendInvite,
|
|
45
|
+
mintNew
|
|
46
|
+
} = chatLogic
|
|
47
|
+
|
|
48
|
+
const { createInboxFor, getNewMessages, markAsRead } = inboxLogic
|
|
49
|
+
const {
|
|
50
|
+
recursiveDelete,
|
|
51
|
+
setSinglePeerAccess,
|
|
52
|
+
createEmptyRdfDoc,
|
|
53
|
+
//NEW function for discovery
|
|
26
54
|
followOrCreateLink,
|
|
27
|
-
getAppInstances,
|
|
28
|
-
getScopedAppInstances,
|
|
29
|
-
getScopedAppsFromIndex,
|
|
30
|
-
loadAllTypeIndexes,
|
|
31
|
-
loadCommunityTypeIndexes,
|
|
32
55
|
loadOrCreateIfNotExists,
|
|
56
|
+
} = utilityLogic
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
ensureLoadedPreferences,
|
|
60
|
+
loadMe,
|
|
61
|
+
getPodRoot,
|
|
62
|
+
getMainInbox,
|
|
63
|
+
findStorage,
|
|
64
|
+
//NEW content from discovery
|
|
33
65
|
loadPreferences,
|
|
34
66
|
loadProfile,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
suggestPrivateTypeIndex,
|
|
39
|
-
suggestPublicTypeIndex,
|
|
40
|
-
uniqueNodes
|
|
41
|
-
} from './discovery/discoveryLogic'
|
|
67
|
+
//NEW function for discovery
|
|
68
|
+
silencedLoadPreferences
|
|
69
|
+
} = profileLogic
|
|
42
70
|
|
|
43
|
-
|
|
71
|
+
const {
|
|
72
|
+
isContainer,
|
|
73
|
+
createContainer,
|
|
74
|
+
getContainerElements,
|
|
75
|
+
getContainerMembers
|
|
76
|
+
} = containerLogic
|
|
77
|
+
|
|
78
|
+
export { ACL_LINK } from './acl/aclLogic'
|
|
44
79
|
export { offlineTestID, appContext } from './authn/authUtil'
|
|
45
|
-
export { ACL_LINK } from './util/UtilityLogic'
|
|
46
80
|
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
81
|
+
export { SolidLogic } from './logic/SolidLogic'
|
|
47
82
|
export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
|
|
48
83
|
// solidLogicSingleton is exported entirely because it is used in solid-panes
|
|
49
84
|
export { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
50
|
-
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
|
|
51
|
-
|
|
85
|
+
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
store,
|
|
89
|
+
authn,
|
|
90
|
+
authSession,
|
|
91
|
+
aclLogic,
|
|
92
|
+
utilityLogic,
|
|
93
|
+
containerLogic,
|
|
94
|
+
profileLogic,
|
|
95
|
+
inboxLogic,
|
|
96
|
+
typeIndexLogic,
|
|
97
|
+
chatLogic,
|
|
98
|
+
//aclLogic
|
|
99
|
+
findAclDocUrl,
|
|
100
|
+
setACLUserPublic,
|
|
101
|
+
genACLText,
|
|
102
|
+
//typeIndexLogic
|
|
103
|
+
registerInTypeIndex,
|
|
104
|
+
getRegistrations,
|
|
105
|
+
loadTypeIndexesFor,
|
|
106
|
+
loadCommunityTypeIndexes,
|
|
107
|
+
loadAllTypeIndexes,
|
|
108
|
+
getScopedAppInstances,
|
|
109
|
+
getAppInstances,
|
|
110
|
+
suggestPublicTypeIndex,
|
|
111
|
+
suggestPrivateTypeIndex,
|
|
112
|
+
deleteTypeIndexRegistration,
|
|
113
|
+
getScopedAppsFromIndex,
|
|
114
|
+
setAcl,
|
|
115
|
+
addToPrivateTypeIndex,
|
|
116
|
+
findChat,
|
|
117
|
+
createChatThing,
|
|
118
|
+
getChat,
|
|
119
|
+
sendInvite,
|
|
120
|
+
//inboxLogic
|
|
121
|
+
mintNew,
|
|
122
|
+
createInboxFor,
|
|
123
|
+
getNewMessages,
|
|
124
|
+
markAsRead,
|
|
125
|
+
//utilityLogic
|
|
126
|
+
recursiveDelete,
|
|
127
|
+
setSinglePeerAccess,
|
|
128
|
+
createEmptyRdfDoc,
|
|
129
|
+
followOrCreateLink,
|
|
130
|
+
loadOrCreateIfNotExists,
|
|
131
|
+
//profileLogic
|
|
132
|
+
ensureLoadedPreferences,
|
|
133
|
+
loadMe,
|
|
134
|
+
getPodRoot,
|
|
135
|
+
getMainInbox,
|
|
136
|
+
findStorage,
|
|
137
|
+
loadPreferences,
|
|
138
|
+
loadProfile,
|
|
139
|
+
silencedLoadPreferences,
|
|
140
|
+
//containerLogic
|
|
141
|
+
isContainer,
|
|
142
|
+
createContainer,
|
|
143
|
+
getContainerElements,
|
|
144
|
+
getContainerMembers
|
|
145
|
+
}
|
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
|
|
package/src/logic/SolidLogic.ts
CHANGED
|
@@ -1,225 +1,64 @@
|
|
|
1
1
|
import { Session } from "@inrupt/solid-client-authn-browser";
|
|
2
2
|
import * as rdf from "rdflib";
|
|
3
|
-
import { NamedNode, Statement
|
|
4
|
-
import
|
|
3
|
+
import { LiveStore, NamedNode, Statement } from "rdflib";
|
|
4
|
+
import { createAclLogic } from "../acl/aclLogic";
|
|
5
5
|
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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 } from "../types";
|
|
9
13
|
import * as debug from "../util/debug";
|
|
10
|
-
import { UtilityLogic } from "../util/UtilityLogic";
|
|
11
|
-
import { CrossOriginForbiddenError, FetchError, NotFoundError, SameOriginForbiddenError, UnauthorizedError } from "./CustomError";
|
|
12
14
|
/*
|
|
13
15
|
** It is important to distinquish `fetch`, a function provided by the browser
|
|
14
16
|
** and `Fetcher`, a helper object for the rdflib Store which turns it
|
|
15
17
|
** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
|
|
16
18
|
** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
const ns: SolidNamespace = solidNamespace(rdf);
|
|
20
|
-
|
|
21
20
|
export class SolidLogic {
|
|
22
|
-
cache: {
|
|
23
|
-
profileDocument: {
|
|
24
|
-
[WebID: string]: NamedNode;
|
|
25
|
-
};
|
|
26
|
-
preferencesFile: {
|
|
27
|
-
[WebID: string]: NamedNode;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
21
|
|
|
31
22
|
store: LiveStore;
|
|
32
23
|
me: string | undefined;
|
|
33
|
-
underlyingFetch: { fetch: (url: string, options?: any) => any };
|
|
34
|
-
|
|
35
|
-
chat: ChatLogic;
|
|
36
|
-
profile: ProfileLogic;
|
|
37
24
|
authn: AuthnLogic;
|
|
38
|
-
|
|
25
|
+
|
|
26
|
+
aclLogic
|
|
27
|
+
utilityLogic
|
|
28
|
+
containerLogic
|
|
29
|
+
profileLogic
|
|
30
|
+
inboxLogic
|
|
31
|
+
typeIndexLogic
|
|
32
|
+
chatLogic
|
|
33
|
+
|
|
39
34
|
|
|
40
35
|
constructor(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: Session) {
|
|
41
36
|
// would xpect to be able to do it this way: but get TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation status: 999
|
|
42
37
|
// this.store = new rdf.LiveStore({})
|
|
43
38
|
// this.store.fetcher._fetch = fetch
|
|
44
|
-
|
|
39
|
+
debug.log("SolidLogic: Unique instance created. There should only be one of these.")
|
|
45
40
|
this.store = rdf.graph() as LiveStore; // Make a Quad store
|
|
46
41
|
rdf.fetcher(this.store, { fetch: specialFetch.fetch}); // Attach a web I/O module, store.fetcher
|
|
47
42
|
this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
|
|
48
|
-
|
|
49
43
|
this.store.features = [] // disable automatic node merging on store load
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
preferencesFile: {},
|
|
53
|
-
};
|
|
54
|
-
this.underlyingFetch = { fetch: fetch }; // Note global one not the one passed
|
|
55
|
-
this.authn = new SolidAuthnLogic(session);
|
|
56
|
-
debug.log('SolidAuthnLogic initialized')
|
|
57
|
-
this.profile = new ProfileLogic(this.store, ns, this.authn);
|
|
58
|
-
this.chat = new ChatLogic(this.store, ns, this.profile);
|
|
59
|
-
this.util = new UtilityLogic(this.store, ns, this.underlyingFetch);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
findAclDocUrl(url: string) {
|
|
63
|
-
return this.util.findAclDocUrl(url);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async loadProfile(me: NamedNode): Promise<NamedNode> {
|
|
67
|
-
/*
|
|
68
|
-
// console.log('loadProfile cache ', this.cache)
|
|
69
|
-
if (this.cache.profileDocument[me.value]) {
|
|
70
|
-
return this.cache.profileDocument[me.value];
|
|
71
|
-
} @@ just use the cache in the store
|
|
72
|
-
*/
|
|
73
|
-
console.log('loadProfile me ', me)
|
|
74
|
-
const profileDocument = me.doc()
|
|
75
|
-
try {
|
|
76
|
-
await this.store.fetcher.load(profileDocument);
|
|
77
|
-
return profileDocument;
|
|
78
|
-
} catch (err) {
|
|
79
|
-
const message = `Cannot load profile ${profileDocument} : ${err}`;
|
|
80
|
-
throw new Error(message);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async loadPreferences(me: NamedNode): Promise<NamedNode> {
|
|
85
|
-
console.log('loadPreferences cache ', this.cache)
|
|
86
|
-
if (this.cache.preferencesFile[me.value]) {
|
|
87
|
-
return this.cache.preferencesFile[me.value];
|
|
88
|
-
}
|
|
89
|
-
await this.loadProfile(me) // Load pointer to pref file
|
|
90
|
-
const preferencesFile = this.store.any(me, ns.space('preferencesFile'), null, me.doc());
|
|
91
|
-
|
|
92
|
-
// console.log('this.store.any()', this.store.any())
|
|
93
|
-
/**
|
|
94
|
-
* Are we working cross-origin?
|
|
95
|
-
* Returns True if we are in a webapp at an origin, and the file origin is different
|
|
96
|
-
*/
|
|
97
|
-
function differentOrigin(): boolean {
|
|
98
|
-
if (!preferencesFile) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return (
|
|
102
|
-
`${window.location.origin}/` !== new URL(preferencesFile.value).origin
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!preferencesFile) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Can't find a preference file pointer in profile ${me.doc()}`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// //// Load preference file
|
|
113
|
-
try {
|
|
114
|
-
await this.store.fetcher.load(preferencesFile as NamedNode, {
|
|
115
|
-
withCredentials: true,
|
|
116
|
-
});
|
|
117
|
-
} catch (err) {
|
|
118
|
-
// Really important to look at why
|
|
119
|
-
const status = err.status;
|
|
120
|
-
debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
|
|
121
|
-
if (status === 401) {
|
|
122
|
-
throw new UnauthorizedError();
|
|
123
|
-
}
|
|
124
|
-
if (status === 403) {
|
|
125
|
-
if (differentOrigin()) {
|
|
126
|
-
throw new CrossOriginForbiddenError();
|
|
127
|
-
}
|
|
128
|
-
throw new SameOriginForbiddenError();
|
|
129
|
-
}
|
|
130
|
-
if (status === 404) {
|
|
131
|
-
throw new NotFoundError(preferencesFile.value);
|
|
132
|
-
}
|
|
133
|
-
throw new FetchError(err.status, err.message);
|
|
134
|
-
}
|
|
135
|
-
return preferencesFile as NamedNode;
|
|
136
|
-
}
|
|
44
|
+
|
|
45
|
+
this.authn = new SolidAuthnLogic(session)
|
|
137
46
|
|
|
138
|
-
|
|
139
|
-
me: NamedNode | string,
|
|
140
|
-
preferencesFile: NamedNode | string,
|
|
141
|
-
isPublic: boolean
|
|
142
|
-
): NamedNode[] {
|
|
143
|
-
// console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
|
|
144
|
-
return this.store.each(
|
|
145
|
-
me as NamedNode,
|
|
146
|
-
isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
|
|
147
|
-
undefined,
|
|
148
|
-
preferencesFile as NamedNode
|
|
149
|
-
) as NamedNode[];
|
|
150
|
-
}
|
|
47
|
+
debug.log('SolidAuthnLogic initialized')
|
|
151
48
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.
|
|
155
|
-
.
|
|
156
|
-
|
|
157
|
-
|
|
49
|
+
this.aclLogic = createAclLogic(this.store)
|
|
50
|
+
this.containerLogic = createContainerLogic(this.store)
|
|
51
|
+
this.utilityLogic = createUtilityLogic(this.store, this.aclLogic, this.containerLogic)
|
|
52
|
+
this.profileLogic = createProfileLogic(this.store, this.authn, this.utilityLogic)
|
|
53
|
+
this.chatLogic = createChatLogic(this.store, this.profileLogic)
|
|
54
|
+
this.inboxLogic = createInboxLogic(this.store, this.profileLogic, this.utilityLogic, this.containerLogic, this.aclLogic)
|
|
55
|
+
this.typeIndexLogic = createTypeIndexLogic(this.store, this.authn, this.profileLogic, this.utilityLogic)
|
|
158
56
|
}
|
|
159
57
|
|
|
160
58
|
load(doc: NamedNode | NamedNode[] | string) {
|
|
161
59
|
return this.store.fetcher.load(doc);
|
|
162
60
|
}
|
|
163
61
|
|
|
164
|
-
async loadIndexes(
|
|
165
|
-
me: NamedNode | string,
|
|
166
|
-
publicProfile: NamedNode | string | null,
|
|
167
|
-
preferencesFile: NamedNode | string | null,
|
|
168
|
-
onWarning = async (_err: Error) => {
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
|
-
): Promise<{
|
|
172
|
-
private: any;
|
|
173
|
-
public: any;
|
|
174
|
-
}> {
|
|
175
|
-
let privateIndexes: any[] = [];
|
|
176
|
-
let publicIndexes: any[] = [];
|
|
177
|
-
if (publicProfile) {
|
|
178
|
-
publicIndexes = this.getTypeIndex(me, publicProfile, true);
|
|
179
|
-
try {
|
|
180
|
-
await this.load(publicIndexes as NamedNode[]);
|
|
181
|
-
} catch (err) {
|
|
182
|
-
onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (preferencesFile) {
|
|
186
|
-
privateIndexes = this.getTypeIndex(me, preferencesFile, false);
|
|
187
|
-
// console.log({ privateIndexes })
|
|
188
|
-
if (privateIndexes.length === 0) {
|
|
189
|
-
await onWarning(
|
|
190
|
-
new Error(
|
|
191
|
-
`Your preference file ${preferencesFile} does not point to a private type index.`
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
} else {
|
|
195
|
-
try {
|
|
196
|
-
await this.load(privateIndexes);
|
|
197
|
-
} catch (err) {
|
|
198
|
-
onWarning(
|
|
199
|
-
new Error(`loadIndex: loading private type index(es) ${err}`)
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// } else {
|
|
204
|
-
// debug.log(
|
|
205
|
-
// 'We know your preference file is not available, so we are not bothering with private type indexes.'
|
|
206
|
-
// )
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
private: privateIndexes,
|
|
211
|
-
public: publicIndexes,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async createEmptyRdfDoc(doc: NamedNode, comment: string) {
|
|
216
|
-
await this.store.fetcher.webOperation("PUT", doc.uri, {
|
|
217
|
-
data: `# ${new Date()} ${comment}
|
|
218
|
-
`,
|
|
219
|
-
contentType: "text/turtle",
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
62
|
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
224
63
|
updatePromise(
|
|
225
64
|
del: Array<Statement>,
|
|
@@ -236,27 +75,7 @@ export class SolidLogic {
|
|
|
236
75
|
}); // promise
|
|
237
76
|
}
|
|
238
77
|
|
|
239
|
-
isContainer(url: string) {
|
|
240
|
-
return this.util.isContainer(url);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
getContainerElements(containerNode: NamedNode): NamedNode[] {
|
|
244
|
-
return this.util.getContainerElements(containerNode);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
getContainerMembers(containerUrl: string): Promise<string[]> {
|
|
248
|
-
return this.util.getContainerMembers(containerUrl);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async recursiveDelete(url: string) {
|
|
252
|
-
return this.util.recursiveDelete(url);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
78
|
clearStore() {
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
async fetch(url: string, options?: any) {
|
|
260
|
-
return this.underlyingFetch.fetch(url, options);
|
|
79
|
+
this.store.statements.slice().forEach(this.store.remove.bind(this.store));
|
|
261
80
|
}
|
|
262
81
|
}
|
|
@@ -5,7 +5,7 @@ import { SolidLogic } from "./SolidLogic"
|
|
|
5
5
|
const _fetch = async (url, requestInit) => {
|
|
6
6
|
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
7
7
|
if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
|
|
8
|
-
// In fact
|
|
8
|
+
// In fact fetch should respect credentials omit itself
|
|
9
9
|
return authSession.fetch(url, requestInit)
|
|
10
10
|
} else {
|
|
11
11
|
return window.fetch(url, requestInit)
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import * as rdf from "rdflib"
|
|
2
|
+
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic"
|
|
3
|
+
import { authSession } from "../authSession/authSession"
|
|
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"
|
|
12
|
+
|
|
13
|
+
export function solidLogicSingleton() {
|
|
14
|
+
|
|
15
|
+
const _fetch = async (url, requestInit) => {
|
|
16
|
+
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
17
|
+
if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
|
|
18
|
+
// In fact fetch should respect credentials omit itself
|
|
19
|
+
return authSession.fetch(url, requestInit)
|
|
20
|
+
} else {
|
|
21
|
+
return window.fetch(url, requestInit)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
debug.log("SolidLogicSingleton: Unique instance created. There should only be one of these.")
|
|
26
|
+
|
|
27
|
+
const store = rdf.graph() as rdf.LiveStore; // Make a Quad store
|
|
28
|
+
rdf.fetcher(store, { fetch: _fetch }); // Attach a web I/O module, store.fetcher
|
|
29
|
+
store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
|
|
30
|
+
store.features = [] // disable automatic node merging on store load
|
|
31
|
+
|
|
32
|
+
debug.log('SolidAuthnLogic initialized')
|
|
33
|
+
const authn = new SolidAuthnLogic(authSession)
|
|
34
|
+
|
|
35
|
+
const aclLogic = createAclLogic(store)
|
|
36
|
+
const {
|
|
37
|
+
findAclDocUrl,
|
|
38
|
+
setACLUserPublic,
|
|
39
|
+
genACLText
|
|
40
|
+
} = aclLogic
|
|
41
|
+
|
|
42
|
+
const containerLogic = createContainerLogic(store)
|
|
43
|
+
const {
|
|
44
|
+
isContainer,
|
|
45
|
+
createContainer,
|
|
46
|
+
getContainerElements,
|
|
47
|
+
getContainerMembers
|
|
48
|
+
} = containerLogic
|
|
49
|
+
|
|
50
|
+
const utilityLogic = createUtilityLogic(store, aclLogic, containerLogic)
|
|
51
|
+
const {
|
|
52
|
+
recursiveDelete,
|
|
53
|
+
setSinglePeerAccess,
|
|
54
|
+
createEmptyRdfDoc,
|
|
55
|
+
followOrCreateLink,
|
|
56
|
+
loadOrCreateIfNotExists
|
|
57
|
+
} = utilityLogic
|
|
58
|
+
|
|
59
|
+
const profileLogic = createProfileLogic(store, authn, utilityLogic)
|
|
60
|
+
const {
|
|
61
|
+
ensureLoadedPreferences,
|
|
62
|
+
loadMe,
|
|
63
|
+
getPodRoot,
|
|
64
|
+
getMainInbox,
|
|
65
|
+
findStorage,
|
|
66
|
+
loadPreferences,
|
|
67
|
+
loadProfile,
|
|
68
|
+
silencedLoadPreferences
|
|
69
|
+
} = profileLogic
|
|
70
|
+
|
|
71
|
+
const chatLogic = createChatLogic(store, profileLogic)
|
|
72
|
+
const {
|
|
73
|
+
setAcl,
|
|
74
|
+
addToPrivateTypeIndex,
|
|
75
|
+
findChat,
|
|
76
|
+
createChatThing,
|
|
77
|
+
getChat,
|
|
78
|
+
sendInvite,
|
|
79
|
+
mintNew
|
|
80
|
+
} = chatLogic
|
|
81
|
+
|
|
82
|
+
const inboxLogic = createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic)
|
|
83
|
+
const {
|
|
84
|
+
createInboxFor,
|
|
85
|
+
getNewMessages,
|
|
86
|
+
markAsRead
|
|
87
|
+
} = inboxLogic
|
|
88
|
+
|
|
89
|
+
const typeIndexLogic = createTypeIndexLogic(store, authn, profileLogic, utilityLogic)
|
|
90
|
+
const {
|
|
91
|
+
registerInTypeIndex,
|
|
92
|
+
getRegistrations,
|
|
93
|
+
loadTypeIndexesFor,
|
|
94
|
+
loadCommunityTypeIndexes,
|
|
95
|
+
loadAllTypeIndexes,
|
|
96
|
+
getScopedAppInstances,
|
|
97
|
+
getAppInstances,
|
|
98
|
+
suggestPublicTypeIndex,
|
|
99
|
+
suggestPrivateTypeIndex,
|
|
100
|
+
deleteTypeIndexRegistration,
|
|
101
|
+
getScopedAppsFromIndex
|
|
102
|
+
} = typeIndexLogic
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
store,
|
|
106
|
+
authn,
|
|
107
|
+
authSession,
|
|
108
|
+
//unilityLogic
|
|
109
|
+
recursiveDelete,
|
|
110
|
+
setSinglePeerAccess,
|
|
111
|
+
createEmptyRdfDoc,
|
|
112
|
+
followOrCreateLink,
|
|
113
|
+
loadOrCreateIfNotExists,
|
|
114
|
+
//containerLogic
|
|
115
|
+
isContainer,
|
|
116
|
+
createContainer,
|
|
117
|
+
getContainerElements,
|
|
118
|
+
getContainerMembers,
|
|
119
|
+
//typeIndexLogic
|
|
120
|
+
registerInTypeIndex,
|
|
121
|
+
getRegistrations,
|
|
122
|
+
loadTypeIndexesFor,
|
|
123
|
+
loadCommunityTypeIndexes,
|
|
124
|
+
loadAllTypeIndexes,
|
|
125
|
+
getScopedAppInstances,
|
|
126
|
+
getAppInstances,
|
|
127
|
+
suggestPublicTypeIndex,
|
|
128
|
+
suggestPrivateTypeIndex,
|
|
129
|
+
deleteTypeIndexRegistration,
|
|
130
|
+
getScopedAppsFromIndex,
|
|
131
|
+
//profileLogic
|
|
132
|
+
ensureLoadedPreferences,
|
|
133
|
+
loadMe,
|
|
134
|
+
getPodRoot,
|
|
135
|
+
getMainInbox,
|
|
136
|
+
findStorage,
|
|
137
|
+
loadPreferences,
|
|
138
|
+
loadProfile,
|
|
139
|
+
silencedLoadPreferences,
|
|
140
|
+
//inboxLogic
|
|
141
|
+
createInboxFor,
|
|
142
|
+
getNewMessages,
|
|
143
|
+
markAsRead,
|
|
144
|
+
//chatLogic
|
|
145
|
+
setAcl,
|
|
146
|
+
addToPrivateTypeIndex,
|
|
147
|
+
findChat,
|
|
148
|
+
createChatThing,
|
|
149
|
+
getChat,
|
|
150
|
+
sendInvite,
|
|
151
|
+
mintNew,
|
|
152
|
+
//aclLogic
|
|
153
|
+
findAclDocUrl,
|
|
154
|
+
setACLUserPublic,
|
|
155
|
+
genACLText
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/*export {
|
|
160
|
+
store,
|
|
161
|
+
authn,
|
|
162
|
+
authSession,
|
|
163
|
+
//unilityLogic
|
|
164
|
+
recursiveDelete,
|
|
165
|
+
setSinglePeerAccess,
|
|
166
|
+
createEmptyRdfDoc,
|
|
167
|
+
followOrCreateLink,
|
|
168
|
+
loadOrCreateIfNotExists,
|
|
169
|
+
//containerLogic
|
|
170
|
+
isContainer,
|
|
171
|
+
createContainer,
|
|
172
|
+
getContainerElements,
|
|
173
|
+
getContainerMembers,
|
|
174
|
+
//typeIndexLogic
|
|
175
|
+
ensureTypeIndexes,
|
|
176
|
+
registerInTypeIndex,
|
|
177
|
+
getRegistrations,
|
|
178
|
+
loadTypeIndexesFor,
|
|
179
|
+
loadCommunityTypeIndexes,
|
|
180
|
+
loadAllTypeIndexes,
|
|
181
|
+
getScopedAppInstances,
|
|
182
|
+
getAppInstances,
|
|
183
|
+
suggestPublicTypeIndex,
|
|
184
|
+
suggestPrivateTypeIndex,
|
|
185
|
+
deleteTypeIndexRegistration,
|
|
186
|
+
getScopedAppsFromIndex,
|
|
187
|
+
//profileLogic
|
|
188
|
+
ensureLoadedPreferences,
|
|
189
|
+
loadMe,
|
|
190
|
+
getPodRoot,
|
|
191
|
+
getMainInbox,
|
|
192
|
+
findStorage,
|
|
193
|
+
loadPreferences,
|
|
194
|
+
loadProfile,
|
|
195
|
+
silencedLoadPreferences,
|
|
196
|
+
//inboxLogic
|
|
197
|
+
createInboxFor,
|
|
198
|
+
getNewMessages,
|
|
199
|
+
markAsRead,
|
|
200
|
+
//chatLogic
|
|
201
|
+
setAcl,
|
|
202
|
+
addToPrivateTypeIndex,
|
|
203
|
+
findChat,
|
|
204
|
+
createChatThing,
|
|
205
|
+
getChat,
|
|
206
|
+
sendInvite,
|
|
207
|
+
mintNew,
|
|
208
|
+
//aclLogic
|
|
209
|
+
findAclDocUrl,
|
|
210
|
+
setACLUserPublic,
|
|
211
|
+
genACLText
|
|
212
|
+
}
|
|
213
|
+
*/
|