solid-logic 1.3.12 → 1.3.13-33f4d6e3
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/.babelrc +0 -0
- package/.eslintrc.js +0 -0
- package/.github/workflows/ci.yml +40 -5
- package/.github/workflows/release.yml +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/jest.config.js +4 -1
- package/lib/acl/aclLogic.d.ts +32 -0
- package/lib/acl/aclLogic.d.ts.map +1 -0
- package/lib/acl/aclLogic.js +132 -0
- package/lib/acl/aclLogic.js.map +1 -0
- package/lib/authSession/authSession.d.ts +3 -0
- package/lib/authSession/authSession.d.ts.map +1 -0
- package/lib/authSession/authSession.js +8 -0
- package/lib/authSession/authSession.js.map +1 -0
- package/lib/authn/SolidAuthnLogic.d.ts +26 -6
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +161 -5
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/authn/authUtil.d.ts +17 -0
- package/lib/authn/authUtil.d.ts.map +1 -0
- package/lib/authn/authUtil.js +88 -0
- package/lib/authn/authUtil.js.map +1 -0
- package/lib/chat/ChatLogic.d.ts +2 -2
- package/lib/chat/ChatLogic.d.ts.map +1 -1
- package/lib/chat/ChatLogic.js +38 -33
- package/lib/chat/ChatLogic.js.map +1 -1
- package/lib/chat/determineChatContainer.d.ts +0 -0
- package/lib/chat/determineChatContainer.d.ts.map +0 -0
- package/lib/chat/determineChatContainer.js +0 -0
- package/lib/chat/determineChatContainer.js.map +0 -0
- package/lib/inbox/InboxLogic.d.ts +2 -2
- package/lib/inbox/InboxLogic.d.ts.map +1 -1
- package/lib/inbox/InboxLogic.js +14 -13
- package/lib/inbox/InboxLogic.js.map +1 -1
- package/lib/index.d.ts +9 -72
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -387
- package/lib/index.js.map +1 -1
- package/lib/issuer/issuerLogic.d.ts +8 -0
- package/lib/issuer/issuerLogic.d.ts.map +1 -0
- package/lib/issuer/issuerLogic.js +53 -0
- package/lib/issuer/issuerLogic.js.map +1 -0
- package/lib/logic/CustomError.d.ts +17 -0
- package/lib/logic/CustomError.d.ts.map +1 -0
- package/lib/logic/CustomError.js +73 -0
- package/lib/logic/CustomError.js.map +1 -0
- package/lib/{index-alain.d.ts → logic/SolidLogic.d.ts} +7 -33
- package/lib/logic/SolidLogic.d.ts.map +1 -0
- package/lib/{index-alain.js → logic/SolidLogic.js} +17 -99
- package/lib/logic/SolidLogic.js.map +1 -0
- package/lib/logic/solidLogicSingleton.d.ts +8 -0
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -0
- package/lib/logic/solidLogicSingleton.js +85 -0
- package/lib/logic/solidLogicSingleton.js.map +1 -0
- package/lib/profile/ProfileLogic.d.ts +2 -3
- package/lib/profile/ProfileLogic.d.ts.map +1 -1
- package/lib/profile/ProfileLogic.js +10 -8
- package/lib/profile/ProfileLogic.js.map +1 -1
- package/lib/typeIndex/typeIndexLogic.d.ts +22 -0
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -0
- package/lib/typeIndex/typeIndexLogic.js +302 -0
- package/lib/typeIndex/typeIndexLogic.js.map +1 -0
- package/lib/types.d.ts +29 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/{authn/index.js → types.js} +1 -1
- package/lib/types.js.map +1 -0
- package/lib/util/UtilityLogic.d.ts +2 -2
- package/lib/util/UtilityLogic.d.ts.map +1 -1
- package/lib/util/UtilityLogic.js +10 -8
- package/lib/util/UtilityLogic.js.map +1 -1
- package/lib/{debug.d.ts → util/debug.d.ts} +0 -0
- package/lib/util/debug.d.ts.map +1 -0
- package/lib/{debug.js → util/debug.js} +0 -0
- package/lib/util/debug.js.map +1 -0
- package/lib/{uri.d.ts → util/uri.d.ts} +0 -0
- package/lib/util/uri.d.ts.map +1 -0
- package/lib/{uri.js → util/uri.js} +0 -0
- package/lib/util/uri.js.map +1 -0
- package/package.json +7 -5
- package/renovate.json +0 -0
- package/src/acl/aclLogic.ts +137 -0
- package/src/authSession/authSession.ts +12 -0
- package/src/authn/SolidAuthnLogic.ts +112 -10
- package/src/authn/authUtil.ts +67 -0
- package/src/chat/ChatLogic.ts +13 -13
- package/src/chat/determineChatContainer.ts +0 -0
- package/src/inbox/InboxLogic.ts +3 -15
- package/src/index.ts +18 -307
- package/src/issuer/issuerLogic.ts +40 -0
- package/src/logic/CustomError.ts +25 -0
- package/src/logic/SolidLogic.ts +264 -0
- package/src/logic/solidLogicSingleton.ts +24 -0
- package/src/profile/ProfileLogic.ts +4 -5
- package/src/typeIndex/typeIndexLogic.ts +170 -0
- package/src/types.ts +41 -0
- package/src/util/UtilityLogic.ts +4 -16
- package/src/{debug.ts → util/debug.ts} +0 -0
- package/src/{uri.ts → util/uri.ts} +0 -0
- package/test/aclLogic.test.ts +15 -0
- package/test/authUtil.test.ts +23 -0
- package/{src/chat/integration.test.ts → test/chatLogic.test.ts} +4 -5
- package/test/helpers/setup.ts +13 -0
- package/{src/inbox/unit.test.ts → test/inboxLogic.test.ts} +5 -6
- package/test/logic.test.ts +28 -0
- package/test/solidAuthLogic.test.ts +49 -0
- package/test/typeIndexLogic.test.ts +26 -0
- package/{src/util/unit.test.ts → test/utilityLogic.test.ts} +3 -4
- package/tsconfig.json +0 -0
- package/jest.setup.ts +0 -2
- package/lib/authn/NoAuthnLogic.d.ts +0 -9
- package/lib/authn/NoAuthnLogic.d.ts.map +0 -1
- package/lib/authn/NoAuthnLogic.js +0 -17
- package/lib/authn/NoAuthnLogic.js.map +0 -1
- package/lib/authn/index.d.ts +0 -5
- package/lib/authn/index.d.ts.map +0 -1
- package/lib/authn/index.js.map +0 -1
- package/lib/chat/integration.test.d.ts +0 -2
- package/lib/chat/integration.test.d.ts.map +0 -1
- package/lib/chat/integration.test.js +0 -318
- package/lib/chat/integration.test.js.map +0 -1
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js.map +0 -1
- package/lib/inbox/unit.test.d.ts +0 -2
- package/lib/inbox/unit.test.d.ts.map +0 -1
- package/lib/inbox/unit.test.js +0 -264
- package/lib/inbox/unit.test.js.map +0 -1
- package/lib/index-alain.d.ts.map +0 -1
- package/lib/index-alain.js.map +0 -1
- package/lib/uri.d.ts.map +0 -1
- package/lib/uri.js.map +0 -1
- package/lib/util/UtilityLogic-alain.d.ts +0 -32
- package/lib/util/UtilityLogic-alain.d.ts.map +0 -1
- package/lib/util/UtilityLogic-alain.js +0 -248
- package/lib/util/UtilityLogic-alain.js.map +0 -1
- package/lib/util/unit.test.d.ts +0 -2
- package/lib/util/unit.test.d.ts.map +0 -1
- package/lib/util/unit.test.js +0 -200
- package/lib/util/unit.test.js.map +0 -1
- package/src/authn/NoAuthnLogic.ts +0 -16
- package/src/authn/index.ts +0 -5
- package/src/index-alain.txt +0 -316
- package/src/util/UtilityLogic-alain.txt +0 -181
|
@@ -1,18 +1,120 @@
|
|
|
1
|
-
import { NamedNode, sym } from "rdflib";
|
|
2
|
-
import {
|
|
1
|
+
import { namedNode, NamedNode, sym } from "rdflib";
|
|
2
|
+
import { appContext, offlineTestID } from "./authUtil";
|
|
3
|
+
import * as debug from '../util/debug'
|
|
3
4
|
import { Session } from "@inrupt/solid-client-authn-browser";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export class SolidAuthnLogic implements AuthnLogic {
|
|
9
|
-
private session?: Session;
|
|
5
|
+
import { AuthenticationContext } from "../types";
|
|
6
|
+
export class SolidAuthnLogic {
|
|
7
|
+
private session: Session;
|
|
10
8
|
|
|
11
9
|
constructor(solidAuthSession: Session) {
|
|
12
10
|
this.session = solidAuthSession;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
currentUser(): NamedNode | null {
|
|
16
|
-
|
|
14
|
+
const app = appContext()
|
|
15
|
+
if (app.viewingNoAuthPage) {
|
|
16
|
+
return sym(app.webId)
|
|
17
|
+
}
|
|
18
|
+
if (this.session.info.webId && this.session.info.isLoggedIn) {
|
|
19
|
+
return sym(this.session.info.webId)
|
|
20
|
+
}
|
|
21
|
+
return offlineTestID() // null unless testing
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves currently logged in webId from either
|
|
26
|
+
* defaultTestUser or SolidAuth
|
|
27
|
+
* Also activates a session after login
|
|
28
|
+
* @param [setUserCallback] Optional callback
|
|
29
|
+
* @returns Resolves with webId uri, if no callback provided
|
|
30
|
+
*/
|
|
31
|
+
async checkUser<T> (
|
|
32
|
+
setUserCallback?: (me: NamedNode | null) => T
|
|
33
|
+
): Promise<NamedNode | T | null> {
|
|
34
|
+
// Save hash for "restorePreviousSession"
|
|
35
|
+
const preLoginRedirectHash = new URL(window.location.href).hash
|
|
36
|
+
if (preLoginRedirectHash) {
|
|
37
|
+
window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash)
|
|
38
|
+
}
|
|
39
|
+
this.session.onSessionRestore((url) => {
|
|
40
|
+
if (document.location.toString() !== url) history.replaceState(null, '', url)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Handle a successful authentication redirect
|
|
45
|
+
*/
|
|
46
|
+
await this.session
|
|
47
|
+
.handleIncomingRedirect({
|
|
48
|
+
restorePreviousSession: true,
|
|
49
|
+
url: window.location.href
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// Check to see if a hash was stored in local storage
|
|
53
|
+
const postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash')
|
|
54
|
+
if (postLoginRedirectHash) {
|
|
55
|
+
const curUrl = new URL(window.location.href)
|
|
56
|
+
if (curUrl.hash !== postLoginRedirectHash) {
|
|
57
|
+
if (history.pushState) {
|
|
58
|
+
// console.log('Setting window.location.has using pushState')
|
|
59
|
+
history.pushState(null, document.title, postLoginRedirectHash)
|
|
60
|
+
} else {
|
|
61
|
+
// console.warn('Setting window.location.has using location.hash')
|
|
62
|
+
location.hash = postLoginRedirectHash
|
|
63
|
+
}
|
|
64
|
+
curUrl.hash = postLoginRedirectHash
|
|
65
|
+
}
|
|
66
|
+
// See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
|
|
67
|
+
// window.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
|
|
68
|
+
window.localStorage.setItem('preLoginRedirectHash', '')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check to see if already logged in / have the WebID
|
|
72
|
+
let me = offlineTestID()
|
|
73
|
+
if (me) {
|
|
74
|
+
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const webId = this.webIdFromSession(this.session.info)
|
|
78
|
+
if (webId) {
|
|
79
|
+
me = this.saveUser(webId)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (me) {
|
|
83
|
+
debug.log(`(Logged in as ${me} by authentication)`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Saves `webId` in `context.me`
|
|
91
|
+
* @param webId
|
|
92
|
+
* @param context
|
|
93
|
+
*
|
|
94
|
+
* @returns Returns the WebID, after setting it
|
|
95
|
+
*/
|
|
96
|
+
saveUser (
|
|
97
|
+
webId: NamedNode | string | null,
|
|
98
|
+
context?: AuthenticationContext
|
|
99
|
+
): NamedNode | null {
|
|
100
|
+
let webIdUri: string
|
|
101
|
+
if (webId) {
|
|
102
|
+
webIdUri = (typeof webId === 'string') ? webId : webId.uri
|
|
103
|
+
const me = namedNode(webIdUri)
|
|
104
|
+
if (context) {
|
|
105
|
+
context.me = me
|
|
106
|
+
}
|
|
107
|
+
return me
|
|
108
|
+
}
|
|
109
|
+
return null
|
|
17
110
|
}
|
|
18
|
-
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @returns {Promise<string|null>} Resolves with WebID URI or null
|
|
114
|
+
*/
|
|
115
|
+
webIdFromSession (session?: { webId?: string, isLoggedIn: boolean }): string | null {
|
|
116
|
+
const webId = session?.webId && session.isLoggedIn ? session.webId : null
|
|
117
|
+
return webId
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NamedNode, sym } from "rdflib"
|
|
2
|
+
import * as debug from '../util/debug'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* find a user or app's context as set in window.SolidAppContext
|
|
6
|
+
* this is a const, not a function, because we have problems to jest mock it otherwise
|
|
7
|
+
* see: https://github.com/facebook/jest/issues/936#issuecomment-545080082 for more
|
|
8
|
+
* @return {any} - an appContext object
|
|
9
|
+
*/
|
|
10
|
+
export const appContext = ():any => {
|
|
11
|
+
let { SolidAppContext }: any = window
|
|
12
|
+
SolidAppContext ||= {}
|
|
13
|
+
SolidAppContext.viewingNoAuthPage = false
|
|
14
|
+
if (SolidAppContext.noAuth && window.document) {
|
|
15
|
+
const currentPage = window.document.location.href
|
|
16
|
+
if (currentPage.startsWith(SolidAppContext.noAuth)) {
|
|
17
|
+
SolidAppContext.viewingNoAuthPage = true
|
|
18
|
+
const params = new URLSearchParams(window.document.location.search)
|
|
19
|
+
if (params) {
|
|
20
|
+
let viewedPage = SolidAppContext.viewedPage = params.get('uri') || null
|
|
21
|
+
if (viewedPage) {
|
|
22
|
+
viewedPage = decodeURI(viewedPage)
|
|
23
|
+
if (!viewedPage.startsWith(SolidAppContext.noAuth)) {
|
|
24
|
+
const ary = viewedPage.split(/\//)
|
|
25
|
+
SolidAppContext.idp = ary[0] + '//' + ary[2]
|
|
26
|
+
SolidAppContext.viewingNoAuthPage = false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return SolidAppContext
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns `sym($SolidTestEnvironment.username)` if
|
|
37
|
+
* `$SolidTestEnvironment.username` is defined as a global
|
|
38
|
+
* or
|
|
39
|
+
* returns testID defined in the HTML page
|
|
40
|
+
* @returns {NamedNode|null}
|
|
41
|
+
*/
|
|
42
|
+
export function offlineTestID (): NamedNode | null {
|
|
43
|
+
const { $SolidTestEnvironment }: any = window
|
|
44
|
+
if (
|
|
45
|
+
typeof $SolidTestEnvironment !== 'undefined' &&
|
|
46
|
+
$SolidTestEnvironment.username
|
|
47
|
+
) {
|
|
48
|
+
// Test setup
|
|
49
|
+
debug.log('Assuming the user is ' + $SolidTestEnvironment.username)
|
|
50
|
+
return sym($SolidTestEnvironment.username)
|
|
51
|
+
}
|
|
52
|
+
// hack that makes SolidOS work in offline mode by adding the webId directly in html
|
|
53
|
+
// example usage: https://github.com/solid/mashlib/blob/29b8b53c46bf02e0e219f0bacd51b0e9951001dd/test/contact/local.html#L37
|
|
54
|
+
if (
|
|
55
|
+
typeof document !== 'undefined' &&
|
|
56
|
+
document.location &&
|
|
57
|
+
('' + document.location).slice(0, 16) === 'http://localhost'
|
|
58
|
+
) {
|
|
59
|
+
const div = document.getElementById('appTarget')
|
|
60
|
+
if (!div) return null
|
|
61
|
+
const id = div.getAttribute('testID')
|
|
62
|
+
if (!id) return null
|
|
63
|
+
debug.log('Assuming user is ' + id)
|
|
64
|
+
return sym(id)
|
|
65
|
+
}
|
|
66
|
+
return null
|
|
67
|
+
}
|
package/src/chat/ChatLogic.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NamedNode, Node, st, term } from "rdflib";
|
|
2
|
-
import { LiveStore, SolidNamespace } from "../index";
|
|
1
|
+
import { NamedNode, Node, st, term, LiveStore } from "rdflib";
|
|
3
2
|
import { ProfileLogic } from "../profile/ProfileLogic";
|
|
4
|
-
import {
|
|
3
|
+
import { SolidNamespace } from "../types";
|
|
4
|
+
import { newThing } from "../util/uri";
|
|
5
5
|
import { determineChatContainer } from "./determineChatContainer";
|
|
6
6
|
|
|
7
7
|
const CHAT_LOCATION_IN_CONTAINER = "index.ttl#this";
|
|
@@ -38,7 +38,7 @@ export class ChatLogic {
|
|
|
38
38
|
// Some servers don't present a Link http response header
|
|
39
39
|
// if the container doesn't exist yet, so refetch the container
|
|
40
40
|
// now that it has been created:
|
|
41
|
-
await this.store.fetcher
|
|
41
|
+
await this.store.fetcher?.load(chatContainer);
|
|
42
42
|
|
|
43
43
|
// FIXME: check the Why value on this quad:
|
|
44
44
|
const chatAclDoc = this.store.any(
|
|
@@ -66,7 +66,7 @@ export class ChatLogic {
|
|
|
66
66
|
acl:mode
|
|
67
67
|
acl:Read, acl:Append.
|
|
68
68
|
`;
|
|
69
|
-
await this.store.fetcher
|
|
69
|
+
await this.store.fetcher?.webOperation("PUT", chatAclDoc.value, {
|
|
70
70
|
data: aclBody,
|
|
71
71
|
contentType: "text/turtle",
|
|
72
72
|
});
|
|
@@ -81,7 +81,7 @@ export class ChatLogic {
|
|
|
81
81
|
if (!privateTypeIndex) {
|
|
82
82
|
throw new Error("Private type index not found!");
|
|
83
83
|
}
|
|
84
|
-
await this.store.fetcher
|
|
84
|
+
await this.store.fetcher?.load(privateTypeIndex);
|
|
85
85
|
const reg = newThing(privateTypeIndex);
|
|
86
86
|
const ins = [
|
|
87
87
|
st(
|
|
@@ -99,7 +99,7 @@ export class ChatLogic {
|
|
|
99
99
|
st(reg, this.ns.solid("instance"), chatThing, privateTypeIndex.doc()),
|
|
100
100
|
];
|
|
101
101
|
await new Promise((resolve, reject) => {
|
|
102
|
-
this.store.updater
|
|
102
|
+
this.store.updater?.update([], ins, function (_uri, ok, errm) {
|
|
103
103
|
if (!ok) {
|
|
104
104
|
reject(new Error(errm));
|
|
105
105
|
} else {
|
|
@@ -115,7 +115,7 @@ export class ChatLogic {
|
|
|
115
115
|
const chatContainer = determineChatContainer(invitee, podRoot);
|
|
116
116
|
let exists = true;
|
|
117
117
|
try {
|
|
118
|
-
await this.store.fetcher
|
|
118
|
+
await this.store.fetcher?.load(
|
|
119
119
|
new NamedNode(chatContainer.value + "index.ttl#this")
|
|
120
120
|
);
|
|
121
121
|
} catch (e) {
|
|
@@ -165,7 +165,7 @@ export class ChatLogic {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
return new Promise(function (resolve, reject) {
|
|
168
|
-
updater
|
|
168
|
+
updater?.put(
|
|
169
169
|
newChatDoc,
|
|
170
170
|
kb.statementsMatching(undefined, undefined, undefined, newChatDoc),
|
|
171
171
|
"text/turtle",
|
|
@@ -213,7 +213,7 @@ export class ChatLogic {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
private async sendInvite(invitee: NamedNode, chatThing: NamedNode) {
|
|
216
|
-
await this.store.fetcher
|
|
216
|
+
await this.store.fetcher?.load(invitee.doc());
|
|
217
217
|
const inviteeInbox = this.store.any(
|
|
218
218
|
invitee,
|
|
219
219
|
this.ns.ldp("inbox"),
|
|
@@ -228,7 +228,7 @@ export class ChatLogic {
|
|
|
228
228
|
${this.ns.rdf("seeAlso")} <${chatThing.value}> .
|
|
229
229
|
`;
|
|
230
230
|
|
|
231
|
-
const inviteResponse = await this.store.fetcher
|
|
231
|
+
const inviteResponse = await this.store.fetcher?.webOperation(
|
|
232
232
|
"POST",
|
|
233
233
|
inviteeInbox.value,
|
|
234
234
|
{
|
|
@@ -236,9 +236,9 @@ ${this.ns.rdf("seeAlso")} <${chatThing.value}> .
|
|
|
236
236
|
contentType: "text/turtle",
|
|
237
237
|
}
|
|
238
238
|
);
|
|
239
|
-
const locationStr = inviteResponse
|
|
239
|
+
const locationStr = inviteResponse?.headers.get("location");
|
|
240
240
|
if (!locationStr) {
|
|
241
|
-
throw new Error(`Invite sending returned a ${inviteResponse
|
|
241
|
+
throw new Error(`Invite sending returned a ${inviteResponse?.status}`);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
}
|
|
File without changes
|
package/src/inbox/InboxLogic.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { NamedNode, Node, st, term } from "rdflib";
|
|
3
|
-
import { LiveStore, SolidNamespace } from "../index";
|
|
1
|
+
import { NamedNode, LiveStore } from "rdflib";
|
|
4
2
|
import { ProfileLogic } from "../profile/ProfileLogic";
|
|
3
|
+
import { SolidNamespace } from "../types";
|
|
5
4
|
import { UtilityLogic } from "../util/UtilityLogic";
|
|
6
|
-
// import { newThing } from "../uri";
|
|
7
|
-
|
|
8
|
-
interface NewPaneOptions {
|
|
9
|
-
me?: NamedNode;
|
|
10
|
-
newInstance?: NamedNode;
|
|
11
|
-
newBase: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface CreatedPaneOptions {
|
|
15
|
-
newInstance: NamedNode;
|
|
16
|
-
}
|
|
17
5
|
|
|
18
6
|
/**
|
|
19
7
|
* Inbox-related logic
|
|
@@ -70,7 +58,7 @@ export class InboxLogic {
|
|
|
70
58
|
};
|
|
71
59
|
const uploaded = await this.util.fetcher.fetch(archiveUrl, options);
|
|
72
60
|
if (uploaded.status.toString()[0] === '2') {
|
|
73
|
-
await this.store.fetcher
|
|
61
|
+
await this.store.fetcher?._fetch(url, {
|
|
74
62
|
method: 'DELETE'
|
|
75
63
|
});
|
|
76
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,307 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export { ACL_LINK } from './util/UtilityLogic'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
fetcher: Fetcher;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface LiveStore extends ConnectedStore {
|
|
23
|
-
updater: UpdateManager;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface SolidNamespace {
|
|
27
|
-
[key: string]: (term: string) => NamedNode;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class SolidLogic {
|
|
31
|
-
cache: {
|
|
32
|
-
profileDocument: {
|
|
33
|
-
[WebID: string]: NamedNode;
|
|
34
|
-
};
|
|
35
|
-
preferencesFile: {
|
|
36
|
-
[WebID: string]: NamedNode;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
store: LiveStore;
|
|
41
|
-
me: string | undefined;
|
|
42
|
-
fetcher: { fetch: (url: string, options?: any) => any };
|
|
43
|
-
|
|
44
|
-
chat: ChatLogic;
|
|
45
|
-
profile: ProfileLogic;
|
|
46
|
-
authn: AuthnLogic;
|
|
47
|
-
util: UtilityLogic;
|
|
48
|
-
|
|
49
|
-
constructor(fetcher: { fetch: (url: any, requestInit: any) => any }, solidAuthSession: Session) {
|
|
50
|
-
this.store = rdf.graph() as LiveStore; // Make a Quad store
|
|
51
|
-
rdf.fetcher(this.store, fetcher); // Attach a web I/O module, store.fetcher
|
|
52
|
-
this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
|
|
53
|
-
this.cache = {
|
|
54
|
-
profileDocument: {},
|
|
55
|
-
preferencesFile: {},
|
|
56
|
-
};
|
|
57
|
-
this.fetcher = fetcher;
|
|
58
|
-
if (solidAuthSession) {
|
|
59
|
-
this.authn = new SolidAuthnLogic(solidAuthSession);
|
|
60
|
-
} else {
|
|
61
|
-
this.authn = new NoAuthnLogic();
|
|
62
|
-
}
|
|
63
|
-
this.profile = new ProfileLogic(this.store, ns, this.authn);
|
|
64
|
-
this.chat = new ChatLogic(this.store, ns, this.profile);
|
|
65
|
-
this.util = new UtilityLogic(this.store, ns, this.fetcher);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
findAclDocUrl(url: string) {
|
|
69
|
-
return this.util.findAclDocUrl(url);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
loadDoc(doc: NamedNode): Promise<void> {
|
|
73
|
-
return this.util.loadDoc(doc);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async loadProfile(me: NamedNode): Promise<NamedNode> {
|
|
77
|
-
// console.log('loadProfile', me)
|
|
78
|
-
if (this.cache.profileDocument[me.value]) {
|
|
79
|
-
return this.cache.profileDocument[me.value];
|
|
80
|
-
}
|
|
81
|
-
let profileDocument;
|
|
82
|
-
try {
|
|
83
|
-
profileDocument = me.doc();
|
|
84
|
-
await this.loadDoc(profileDocument);
|
|
85
|
-
return profileDocument;
|
|
86
|
-
} catch (err) {
|
|
87
|
-
const message = `Logged in but cannot load profile ${profileDocument} : ${err}`;
|
|
88
|
-
throw new Error(message);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async loadPreferences(me: NamedNode): Promise<NamedNode> {
|
|
93
|
-
// console.log('loadPreferences', me)
|
|
94
|
-
if (this.cache.preferencesFile[me.value]) {
|
|
95
|
-
return this.cache.preferencesFile[me.value];
|
|
96
|
-
}
|
|
97
|
-
const preferencesFile = this.store.any(me, ns.space("preferencesFile"));
|
|
98
|
-
|
|
99
|
-
// console.log('this.store.any()', this.store.any())
|
|
100
|
-
/**
|
|
101
|
-
* Are we working cross-origin?
|
|
102
|
-
* Returns True if we are in a webapp at an origin, and the file origin is different
|
|
103
|
-
*/
|
|
104
|
-
function differentOrigin(): boolean {
|
|
105
|
-
if (!preferencesFile) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
return (
|
|
109
|
-
`${window.location.origin}/` !== new URL(preferencesFile.value).origin
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!preferencesFile) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Can't find a preference file pointer in profile ${me.doc()}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!this.store.fetcher) {
|
|
120
|
-
throw new Error("Cannot load doc, have no fetcher");
|
|
121
|
-
}
|
|
122
|
-
// //// Load preference file
|
|
123
|
-
try {
|
|
124
|
-
await this.store.fetcher.load(preferencesFile as NamedNode, {
|
|
125
|
-
withCredentials: true,
|
|
126
|
-
});
|
|
127
|
-
} catch (err) {
|
|
128
|
-
// Really important to look at why
|
|
129
|
-
const status = err.status;
|
|
130
|
-
debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
|
|
131
|
-
if (status === 401) {
|
|
132
|
-
throw new UnauthorizedError();
|
|
133
|
-
}
|
|
134
|
-
if (status === 403) {
|
|
135
|
-
if (differentOrigin()) {
|
|
136
|
-
throw new CrossOriginForbiddenError();
|
|
137
|
-
}
|
|
138
|
-
throw new SameOriginForbiddenError();
|
|
139
|
-
}
|
|
140
|
-
if (status === 404) {
|
|
141
|
-
throw new NotFoundError(preferencesFile.value);
|
|
142
|
-
}
|
|
143
|
-
throw new FetchError(err.status, err.message);
|
|
144
|
-
}
|
|
145
|
-
return preferencesFile as NamedNode;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getTypeIndex(
|
|
149
|
-
me: NamedNode | string,
|
|
150
|
-
preferencesFile: NamedNode | string,
|
|
151
|
-
isPublic: boolean
|
|
152
|
-
): NamedNode[] {
|
|
153
|
-
// console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
|
|
154
|
-
return this.store.each(
|
|
155
|
-
me as NamedNode,
|
|
156
|
-
isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
|
|
157
|
-
undefined,
|
|
158
|
-
preferencesFile as NamedNode
|
|
159
|
-
) as NamedNode[];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
getRegistrations(instance, theClass) {
|
|
163
|
-
return this.store
|
|
164
|
-
.each(undefined, ns.solid("instance"), instance)
|
|
165
|
-
.filter((r) => {
|
|
166
|
-
return this.store.holds(r, ns.solid("forClass"), theClass);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
load(doc: NamedNode | NamedNode[] | string) {
|
|
171
|
-
if (!this.store.fetcher) {
|
|
172
|
-
throw new Error("Cannot load doc(s), have no fetcher");
|
|
173
|
-
}
|
|
174
|
-
return this.store.fetcher.load(doc);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async loadIndexes(
|
|
178
|
-
me: NamedNode | string,
|
|
179
|
-
publicProfile: NamedNode | string | null,
|
|
180
|
-
preferencesFile: NamedNode | string | null,
|
|
181
|
-
onWarning = async (_err: Error) => {
|
|
182
|
-
return undefined;
|
|
183
|
-
}
|
|
184
|
-
): Promise<{
|
|
185
|
-
private: any;
|
|
186
|
-
public: any;
|
|
187
|
-
}> {
|
|
188
|
-
let privateIndexes: any[] = [];
|
|
189
|
-
let publicIndexes: any[] = [];
|
|
190
|
-
if (publicProfile) {
|
|
191
|
-
publicIndexes = this.getTypeIndex(me, publicProfile, true);
|
|
192
|
-
try {
|
|
193
|
-
await this.load(publicIndexes as NamedNode[]);
|
|
194
|
-
} catch (err) {
|
|
195
|
-
onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (preferencesFile) {
|
|
199
|
-
privateIndexes = this.getTypeIndex(me, preferencesFile, false);
|
|
200
|
-
// console.log({ privateIndexes })
|
|
201
|
-
if (privateIndexes.length === 0) {
|
|
202
|
-
await onWarning(
|
|
203
|
-
new Error(
|
|
204
|
-
`Your preference file ${preferencesFile} does not point to a private type index.`
|
|
205
|
-
)
|
|
206
|
-
);
|
|
207
|
-
} else {
|
|
208
|
-
try {
|
|
209
|
-
await this.load(privateIndexes);
|
|
210
|
-
} catch (err) {
|
|
211
|
-
onWarning(
|
|
212
|
-
new Error(`loadIndex: loading private type index(es) ${err}`)
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
// } else {
|
|
217
|
-
// debug.log(
|
|
218
|
-
// 'We know your preference file is not available, so we are not bothering with private type indexes.'
|
|
219
|
-
// )
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
private: privateIndexes,
|
|
224
|
-
public: publicIndexes,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async createEmptyRdfDoc(doc: NamedNode, comment: string) {
|
|
229
|
-
if (!this.store.fetcher) {
|
|
230
|
-
throw new Error("Cannot create empty rdf doc, have no fetcher");
|
|
231
|
-
}
|
|
232
|
-
await this.store.fetcher.webOperation("PUT", doc.uri, {
|
|
233
|
-
data: `# ${new Date()} ${comment}
|
|
234
|
-
`,
|
|
235
|
-
contentType: "text/turtle",
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
240
|
-
updatePromise(
|
|
241
|
-
del: Array<Statement>,
|
|
242
|
-
ins: Array<Statement> = []
|
|
243
|
-
): Promise<void> {
|
|
244
|
-
return new Promise((resolve, reject) => {
|
|
245
|
-
if (!this.store.updater) {
|
|
246
|
-
throw new Error("Cannot updatePromise, have no updater");
|
|
247
|
-
}
|
|
248
|
-
this.store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
249
|
-
if (!ok) {
|
|
250
|
-
reject(new Error(errorBody));
|
|
251
|
-
} else {
|
|
252
|
-
resolve();
|
|
253
|
-
}
|
|
254
|
-
}); // callback
|
|
255
|
-
}); // promise
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
isContainer(url: string) {
|
|
259
|
-
return this.util.isContainer(url);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
getContainerElements(containerNode: NamedNode): NamedNode[] {
|
|
263
|
-
return this.util.getContainerElements(containerNode);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
getContainerMembers(containerUrl: string): Promise<string[]> {
|
|
267
|
-
return this.util.getContainerMembers(containerUrl);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async recursiveDelete(url: string) {
|
|
271
|
-
return this.util.recursiveDelete(url);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
clearStore() {
|
|
275
|
-
return this.util.clearStore();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async fetch(url: string, options?: any) {
|
|
279
|
-
return this.fetcher.fetch(url, options);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
class CustomError extends Error {
|
|
284
|
-
constructor(message?: string) {
|
|
285
|
-
super(message);
|
|
286
|
-
// see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
287
|
-
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
|
|
288
|
-
this.name = new.target.name; // stack traces display correctly now
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class UnauthorizedError extends CustomError {}
|
|
293
|
-
|
|
294
|
-
export class CrossOriginForbiddenError extends CustomError {}
|
|
295
|
-
|
|
296
|
-
export class SameOriginForbiddenError extends CustomError {}
|
|
297
|
-
|
|
298
|
-
export class NotFoundError extends CustomError {}
|
|
299
|
-
|
|
300
|
-
export class FetchError extends CustomError {
|
|
301
|
-
status: number;
|
|
302
|
-
|
|
303
|
-
constructor(status: number, message?: string) {
|
|
304
|
-
super(message);
|
|
305
|
-
this.status = status;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
setACLUserPublic,
|
|
3
|
+
genACLText
|
|
4
|
+
} from './acl/aclLogic'
|
|
5
|
+
export {
|
|
6
|
+
ensureTypeIndexes,
|
|
7
|
+
loadTypeIndexes,
|
|
8
|
+
registerInTypeIndex,
|
|
9
|
+
loadIndex
|
|
10
|
+
} from './typeIndex/typeIndexLogic'
|
|
11
|
+
export { authSession } from './authSession/authSession'
|
|
12
|
+
export { SolidLogic } from './logic/SolidLogic'
|
|
13
|
+
export { offlineTestID, appContext } from './authn/authUtil'
|
|
14
|
+
export { ACL_LINK } from './util/UtilityLogic'
|
|
15
|
+
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
16
|
+
export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
|
|
17
|
+
export { solidLogicSingleton, authn, store, chat, profile } from './logic/solidLogicSingleton'
|
|
18
|
+
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
|