solid-logic 1.3.11 → 1.3.13-057429fe
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 +39 -5
- package/.github/workflows/release.yml +0 -0
- package/LICENSE +0 -0
- package/README.md +7 -1
- 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 -5
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +167 -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 +14 -72
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +39 -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 +4 -0
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -0
- package/lib/logic/solidLogicSingleton.js +77 -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 +31 -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 +19 -17
- package/renovate.json +0 -0
- package/src/acl/aclLogic.ts +137 -0
- package/src/authSession/authSession.ts +13 -0
- package/src/authn/SolidAuthnLogic.ts +114 -9
- 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 +29 -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 +18 -0
- package/src/profile/ProfileLogic.ts +4 -5
- package/src/typeIndex/typeIndexLogic.ts +170 -0
- package/src/types.ts +43 -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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Access Control
|
|
3
|
+
*
|
|
4
|
+
* This function sets up a simple default ACL for a resource, with
|
|
5
|
+
* RWC for the owner, and a specified access (default none) for the public.
|
|
6
|
+
* In all cases owner has read write control.
|
|
7
|
+
* Parameter lists modes allowed to public
|
|
8
|
+
*
|
|
9
|
+
* @param options
|
|
10
|
+
* @param options.public eg ['Read', 'Write']
|
|
11
|
+
*
|
|
12
|
+
* @returns Resolves with aclDoc uri on successful write
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { graph, NamedNode, Namespace, serialize } from "rdflib"
|
|
16
|
+
import solidNamespace from 'solid-namespace'
|
|
17
|
+
import * as $rdf from 'rdflib'
|
|
18
|
+
import { solidLogicSingleton } from "../logic/solidLogicSingleton"
|
|
19
|
+
import { ACL_LINK } from "../util/UtilityLogic"
|
|
20
|
+
|
|
21
|
+
export const ns = solidNamespace($rdf)
|
|
22
|
+
|
|
23
|
+
export function setACLUserPublic (
|
|
24
|
+
docURI: string,
|
|
25
|
+
me: NamedNode,
|
|
26
|
+
options: {
|
|
27
|
+
defaultForNew?: boolean,
|
|
28
|
+
public?: []
|
|
29
|
+
}
|
|
30
|
+
): Promise<NamedNode> {
|
|
31
|
+
const aclDoc = solidLogicSingleton.store.any(
|
|
32
|
+
solidLogicSingleton.store.sym(docURI),
|
|
33
|
+
ACL_LINK
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return Promise.resolve()
|
|
37
|
+
.then(() => {
|
|
38
|
+
if (aclDoc) {
|
|
39
|
+
return aclDoc as NamedNode
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return fetchACLRel(docURI).catch(err => {
|
|
43
|
+
throw new Error(`Error fetching rel=ACL header for ${docURI}: ${err}`)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
.then(aclDoc => {
|
|
47
|
+
const aclText = genACLText(docURI, me, aclDoc.uri, options)
|
|
48
|
+
if (!solidLogicSingleton.store.fetcher) {
|
|
49
|
+
throw new Error('Cannot PUT this, store has no fetcher')
|
|
50
|
+
}
|
|
51
|
+
return solidLogicSingleton.store.fetcher
|
|
52
|
+
.webOperation('PUT', aclDoc.uri, {
|
|
53
|
+
data: aclText,
|
|
54
|
+
contentType: 'text/turtle'
|
|
55
|
+
})
|
|
56
|
+
.then(result => {
|
|
57
|
+
if (!result.ok) {
|
|
58
|
+
throw new Error('Error writing ACL text: ' + result.error)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return aclDoc
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param docURI
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
function fetchACLRel (docURI: string): Promise<NamedNode> {
|
|
71
|
+
const fetcher = solidLogicSingleton.store.fetcher
|
|
72
|
+
if (!fetcher) {
|
|
73
|
+
throw new Error('Cannot fetch ACL rel, store has no fetcher')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return fetcher.load(docURI).then(result => {
|
|
77
|
+
if (!result.ok) {
|
|
78
|
+
throw new Error('fetchACLRel: While loading:' + (result as any).error)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const aclDoc = solidLogicSingleton.store.any(
|
|
82
|
+
solidLogicSingleton.store.sym(docURI),
|
|
83
|
+
ACL_LINK
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if (!aclDoc) {
|
|
87
|
+
throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return aclDoc as NamedNode
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param docURI
|
|
96
|
+
* @param me
|
|
97
|
+
* @param aclURI
|
|
98
|
+
* @param options
|
|
99
|
+
*
|
|
100
|
+
* @returns Serialized ACL
|
|
101
|
+
*/
|
|
102
|
+
export function genACLText (
|
|
103
|
+
docURI: string,
|
|
104
|
+
me: NamedNode,
|
|
105
|
+
aclURI: string,
|
|
106
|
+
options: {
|
|
107
|
+
defaultForNew?: boolean,
|
|
108
|
+
public?: []
|
|
109
|
+
} = {}
|
|
110
|
+
): string | undefined {
|
|
111
|
+
const optPublic = options.public || []
|
|
112
|
+
const g = graph()
|
|
113
|
+
const auth = Namespace('http://www.w3.org/ns/auth/acl#')
|
|
114
|
+
let a = g.sym(`${aclURI}#a1`)
|
|
115
|
+
const acl = g.sym(aclURI)
|
|
116
|
+
const doc = g.sym(docURI)
|
|
117
|
+
g.add(a, ns.rdf('type'), auth('Authorization'), acl)
|
|
118
|
+
g.add(a, auth('accessTo'), doc, acl)
|
|
119
|
+
if (options.defaultForNew) {
|
|
120
|
+
g.add(a, auth('default'), doc, acl)
|
|
121
|
+
}
|
|
122
|
+
g.add(a, auth('agent'), me, acl)
|
|
123
|
+
g.add(a, auth('mode'), auth('Read'), acl)
|
|
124
|
+
g.add(a, auth('mode'), auth('Write'), acl)
|
|
125
|
+
g.add(a, auth('mode'), auth('Control'), acl)
|
|
126
|
+
|
|
127
|
+
if (optPublic.length) {
|
|
128
|
+
a = g.sym(`${aclURI}#a2`)
|
|
129
|
+
g.add(a, ns.rdf('type'), auth('Authorization'), acl)
|
|
130
|
+
g.add(a, auth('accessTo'), doc, acl)
|
|
131
|
+
g.add(a, auth('agentClass'), ns.foaf('Agent'), acl)
|
|
132
|
+
for (let p = 0; p < optPublic.length; p++) {
|
|
133
|
+
g.add(a, auth('mode'), auth(optPublic[p]), acl) // Like 'Read' etc
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return serialize(acl, g, aclURI)
|
|
137
|
+
}
|
|
@@ -1,18 +1,123 @@
|
|
|
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
|
-
* Implements AuthnLogic relying on solid-auth-client
|
|
7
|
-
*/
|
|
5
|
+
import { AuthenticationContext, AuthnLogic } from "../types";
|
|
8
6
|
export class SolidAuthnLogic implements AuthnLogic {
|
|
9
|
-
private session
|
|
7
|
+
private session: Session;
|
|
10
8
|
|
|
11
9
|
constructor(solidAuthSession: Session) {
|
|
12
10
|
this.session = solidAuthSession;
|
|
13
11
|
}
|
|
12
|
+
|
|
13
|
+
// we created authSession getter because we want to access it as authn.authSession externally
|
|
14
|
+
get authSession():Session { return this.session }
|
|
14
15
|
|
|
15
16
|
currentUser(): NamedNode | null {
|
|
16
|
-
|
|
17
|
+
const app = appContext()
|
|
18
|
+
if (app.viewingNoAuthPage) {
|
|
19
|
+
return sym(app.webId)
|
|
20
|
+
}
|
|
21
|
+
if (this.session.info.webId && this.session.info.isLoggedIn) {
|
|
22
|
+
return sym(this.session.info.webId)
|
|
23
|
+
}
|
|
24
|
+
return offlineTestID() // null unless testing
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves currently logged in webId from either
|
|
29
|
+
* defaultTestUser or SolidAuth
|
|
30
|
+
* Also activates a session after login
|
|
31
|
+
* @param [setUserCallback] Optional callback
|
|
32
|
+
* @returns Resolves with webId uri, if no callback provided
|
|
33
|
+
*/
|
|
34
|
+
async checkUser<T> (
|
|
35
|
+
setUserCallback?: (me: NamedNode | null) => T
|
|
36
|
+
): Promise<NamedNode | T | null> {
|
|
37
|
+
// Save hash for "restorePreviousSession"
|
|
38
|
+
const preLoginRedirectHash = new URL(window.location.href).hash
|
|
39
|
+
if (preLoginRedirectHash) {
|
|
40
|
+
window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash)
|
|
41
|
+
}
|
|
42
|
+
this.session.onSessionRestore((url) => {
|
|
43
|
+
if (document.location.toString() !== url) history.replaceState(null, '', url)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Handle a successful authentication redirect
|
|
48
|
+
*/
|
|
49
|
+
await this.session
|
|
50
|
+
.handleIncomingRedirect({
|
|
51
|
+
restorePreviousSession: true,
|
|
52
|
+
url: window.location.href
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Check to see if a hash was stored in local storage
|
|
56
|
+
const postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash')
|
|
57
|
+
if (postLoginRedirectHash) {
|
|
58
|
+
const curUrl = new URL(window.location.href)
|
|
59
|
+
if (curUrl.hash !== postLoginRedirectHash) {
|
|
60
|
+
if (history.pushState) {
|
|
61
|
+
// console.log('Setting window.location.has using pushState')
|
|
62
|
+
history.pushState(null, document.title, postLoginRedirectHash)
|
|
63
|
+
} else {
|
|
64
|
+
// console.warn('Setting window.location.has using location.hash')
|
|
65
|
+
location.hash = postLoginRedirectHash
|
|
66
|
+
}
|
|
67
|
+
curUrl.hash = postLoginRedirectHash
|
|
68
|
+
}
|
|
69
|
+
// See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
|
|
70
|
+
// window.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
|
|
71
|
+
window.localStorage.setItem('preLoginRedirectHash', '')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check to see if already logged in / have the WebID
|
|
75
|
+
let me = offlineTestID()
|
|
76
|
+
if (me) {
|
|
77
|
+
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const webId = this.webIdFromSession(this.session.info)
|
|
81
|
+
if (webId) {
|
|
82
|
+
me = this.saveUser(webId)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (me) {
|
|
86
|
+
debug.log(`(Logged in as ${me} by authentication)`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Saves `webId` in `context.me`
|
|
94
|
+
* @param webId
|
|
95
|
+
* @param context
|
|
96
|
+
*
|
|
97
|
+
* @returns Returns the WebID, after setting it
|
|
98
|
+
*/
|
|
99
|
+
saveUser (
|
|
100
|
+
webId: NamedNode | string | null,
|
|
101
|
+
context?: AuthenticationContext
|
|
102
|
+
): NamedNode | null {
|
|
103
|
+
let webIdUri: string
|
|
104
|
+
if (webId) {
|
|
105
|
+
webIdUri = (typeof webId === 'string') ? webId : webId.uri
|
|
106
|
+
const me = namedNode(webIdUri)
|
|
107
|
+
if (context) {
|
|
108
|
+
context.me = me
|
|
109
|
+
}
|
|
110
|
+
return me
|
|
111
|
+
}
|
|
112
|
+
return null
|
|
17
113
|
}
|
|
18
|
-
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @returns {Promise<string|null>} Resolves with WebID URI or null
|
|
117
|
+
*/
|
|
118
|
+
webIdFromSession (session?: { webId?: string, isLoggedIn: boolean }): string | null {
|
|
119
|
+
const webId = session?.webId && session.isLoggedIn ? session.webId : null
|
|
120
|
+
return webId
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
@@ -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
|
}
|