solid-logic 3.0.9-f51524a8 → 3.0.9-ff53d0a
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/README.md +103 -2
- package/dist/acl/aclLogic.js +118 -0
- package/dist/acl/aclLogic.js.map +1 -0
- package/{lib → dist}/authSession/authSession.d.ts.map +1 -1
- package/dist/authSession/authSession.js +3 -0
- package/dist/authSession/authSession.js.map +1 -0
- package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/dist/authn/SolidAuthnLogic.js +110 -0
- package/dist/authn/SolidAuthnLogic.js.map +1 -0
- package/dist/authn/authUtil.js +67 -0
- package/dist/authn/authUtil.js.map +1 -0
- package/dist/chat/chatLogic.js +157 -0
- package/dist/chat/chatLogic.js.map +1 -0
- package/dist/inbox/inboxLogic.js +52 -0
- package/dist/inbox/inboxLogic.js.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/issuer/issuerLogic.js +37 -0
- package/dist/issuer/issuerLogic.js.map +1 -0
- package/dist/logic/CustomError.js +28 -0
- package/dist/logic/CustomError.js.map +1 -0
- package/dist/logic/solidLogic.js +65 -0
- package/dist/logic/solidLogic.js.map +1 -0
- package/dist/logic/solidLogicSingleton.js +18 -0
- package/dist/logic/solidLogicSingleton.js.map +1 -0
- package/dist/profile/profileLogic.js +129 -0
- package/dist/profile/profileLogic.js.map +1 -0
- package/dist/solid-logic.esm.js +8560 -0
- package/dist/solid-logic.esm.js.map +1 -0
- package/dist/solid-logic.esm.min.js +32 -0
- package/dist/solid-logic.esm.min.js.map +1 -0
- package/dist/solid-logic.umd.js +8597 -0
- package/dist/solid-logic.umd.js.map +1 -0
- package/dist/solid-logic.umd.min.js +32 -0
- package/dist/solid-logic.umd.min.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.js +186 -0
- package/dist/typeIndex/typeIndexLogic.js.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/{src/util/containerLogic.ts → dist/util/containerLogic.js} +18 -26
- package/dist/util/containerLogic.js.map +1 -0
- package/dist/util/debug.js +14 -0
- package/dist/util/debug.js.map +1 -0
- package/dist/util/ns.js +5 -0
- package/dist/util/ns.js.map +1 -0
- package/dist/util/utilityLogic.js +144 -0
- package/dist/util/utilityLogic.js.map +1 -0
- package/dist/util/utils.js +39 -0
- package/dist/util/utils.js.map +1 -0
- package/package.json +28 -9
- package/babel.config.js +0 -6
- package/eslint.config.js +0 -28
- package/jest.config.js +0 -17
- package/lib/solid-logic.js +0 -107
- package/lib/solid-logic.js.map +0 -1
- package/rollup.config.js +0 -29
- package/src/acl/aclLogic.ts +0 -156
- package/src/authSession/authSession.ts +0 -13
- package/src/authn/SolidAuthnLogic.ts +0 -126
- package/src/authn/authUtil.ts +0 -70
- package/src/chat/chatLogic.ts +0 -226
- package/src/inbox/inboxLogic.ts +0 -59
- package/src/index.ts +0 -21
- package/src/issuer/issuerLogic.ts +0 -40
- package/src/logic/CustomError.ts +0 -29
- package/src/logic/solidLogic.ts +0 -76
- package/src/logic/solidLogicSingleton.ts +0 -20
- package/src/profile/profileLogic.ts +0 -125
- package/src/typeIndex/typeIndexLogic.ts +0 -198
- package/src/types.ts +0 -122
- package/src/util/debug.ts +0 -16
- package/src/util/ns.ts +0 -5
- package/src/util/utilityLogic.ts +0 -156
- package/src/util/utils.ts +0 -52
- package/src/versionInfo.ts +0 -32
- package/test/aclLogic.test.ts +0 -24
- package/test/authUtil.test.ts +0 -23
- package/test/chatLogic.test.ts +0 -322
- package/test/container.test.ts +0 -58
- package/test/helpers/dataSetup.ts +0 -135
- package/test/helpers/setup.ts +0 -22
- package/test/inboxLogic.test.ts +0 -209
- package/test/logic.test.ts +0 -29
- package/test/profileLogic.test.ts +0 -248
- package/test/solidAuthLogic.test.ts +0 -49
- package/test/typeIndexLogic.test.ts +0 -255
- package/test/utilityLogic.test.ts +0 -180
- package/test/utils.test.ts +0 -32
- package/timestamp.sh +0 -13
- package/tsconfig.json +0 -77
- package/tsconfig.test.json +0 -8
- /package/{lib → dist}/acl/aclLogic.d.ts +0 -0
- /package/{lib → dist}/acl/aclLogic.d.ts.map +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts +0 -0
- /package/{lib → dist}/authn/SolidAuthnLogic.d.ts +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts.map +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts.map +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts.map +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.d.ts.map +0 -0
- /package/{lib → dist}/issuer/issuerLogic.d.ts +0 -0
- /package/{lib → dist}/issuer/issuerLogic.d.ts.map +0 -0
- /package/{lib → dist}/logic/CustomError.d.ts +0 -0
- /package/{lib → dist}/logic/CustomError.d.ts.map +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts.map +0 -0
- /package/{lib → dist}/logic/solidLogicSingleton.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogicSingleton.d.ts.map +0 -0
- /package/{lib → dist}/profile/profileLogic.d.ts +0 -0
- /package/{lib → dist}/profile/profileLogic.d.ts.map +0 -0
- /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts +0 -0
- /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts.map +0 -0
- /package/{lib → dist}/types.d.ts +0 -0
- /package/{lib → dist}/types.d.ts.map +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/debug.d.ts +0 -0
- /package/{lib → dist}/util/debug.d.ts.map +0 -0
- /package/{lib → dist}/util/ns.d.ts +0 -0
- /package/{lib → dist}/util/ns.d.ts.map +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/utils.d.ts +0 -0
- /package/{lib → dist}/util/utils.d.ts.map +0 -0
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Make these variables directly accessible as it is what you need most of the time
|
|
2
|
-
// This also makes these variable globaly accesible in mashlib
|
|
3
|
-
import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
-
|
|
5
|
-
const authn = solidLogicSingleton.authn
|
|
6
|
-
const authSession = solidLogicSingleton.authn.authSession
|
|
7
|
-
const store = solidLogicSingleton.store
|
|
8
|
-
|
|
9
|
-
export { ACL_LINK } from './acl/aclLogic'
|
|
10
|
-
export { offlineTestID, appContext } from './authn/authUtil'
|
|
11
|
-
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
12
|
-
export type { AppDetails, SolidNamespace, AuthenticationContext, SolidLogic } from './types'
|
|
13
|
-
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
solidLogicSingleton, // solidLogicSingleton is exported entirely because it is used in solid-panes
|
|
17
|
-
store,
|
|
18
|
-
authn,
|
|
19
|
-
authSession
|
|
20
|
-
}
|
|
21
|
-
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const DEFAULT_ISSUERS = [
|
|
2
|
-
{
|
|
3
|
-
name: 'Solid Community',
|
|
4
|
-
uri: 'https://solidcommunity.net'
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
name: 'Solid Web',
|
|
8
|
-
uri: 'https://solidweb.org'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: 'Inrupt.net',
|
|
12
|
-
uri: 'https://inrupt.net'
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'pod.Inrupt.com',
|
|
16
|
-
uri: 'https://login.inrupt.com'
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @returns - A list of suggested OIDC issuers
|
|
22
|
-
*/
|
|
23
|
-
export function getSuggestedIssuers (): { name: string, uri: string }[] {
|
|
24
|
-
// Suggest a default list of OIDC issuers
|
|
25
|
-
const issuers = [...DEFAULT_ISSUERS]
|
|
26
|
-
|
|
27
|
-
// Suggest the current host if not already included
|
|
28
|
-
const { host, origin } = new URL(location.href)
|
|
29
|
-
const hosts = issuers.map(({ uri }) => new URL(uri).host)
|
|
30
|
-
if (!hosts.includes(host) && !hosts.some(existing => isSubdomainOf(host, existing))) {
|
|
31
|
-
issuers.unshift({ name: host, uri: origin })
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return issuers
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isSubdomainOf (subdomain: string, domain: string): boolean {
|
|
38
|
-
const dot = subdomain.length - domain.length - 1
|
|
39
|
-
return dot > 0 && subdomain[dot] === '.' && subdomain.endsWith(domain)
|
|
40
|
-
}
|
package/src/logic/CustomError.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
class CustomError extends Error {
|
|
2
|
-
constructor(message?: string) {
|
|
3
|
-
super(message)
|
|
4
|
-
// see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
5
|
-
Object.setPrototypeOf(this, new.target.prototype) // restore prototype chain
|
|
6
|
-
this.name = new.target.name // stack traces display correctly now
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class UnauthorizedError extends CustomError {}
|
|
11
|
-
|
|
12
|
-
export class CrossOriginForbiddenError extends CustomError {}
|
|
13
|
-
|
|
14
|
-
export class SameOriginForbiddenError extends CustomError {}
|
|
15
|
-
|
|
16
|
-
export class NotFoundError extends CustomError {}
|
|
17
|
-
|
|
18
|
-
export class NotEditableError extends CustomError { }
|
|
19
|
-
|
|
20
|
-
export class WebOperationError extends CustomError {}
|
|
21
|
-
|
|
22
|
-
export class FetchError extends CustomError {
|
|
23
|
-
status: number
|
|
24
|
-
|
|
25
|
-
constructor(status: number, message?: string) {
|
|
26
|
-
super(message)
|
|
27
|
-
this.status = status
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/logic/solidLogic.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Session } from '@inrupt/solid-client-authn-browser'
|
|
2
|
-
import * as rdf from 'rdflib'
|
|
3
|
-
import { LiveStore, NamedNode, Statement } from 'rdflib'
|
|
4
|
-
import { createAclLogic } from '../acl/aclLogic'
|
|
5
|
-
import { SolidAuthnLogic } from '../authn/SolidAuthnLogic'
|
|
6
|
-
import { createChatLogic } from '../chat/chatLogic'
|
|
7
|
-
import { createInboxLogic } from '../inbox/inboxLogic'
|
|
8
|
-
import { createProfileLogic } from '../profile/profileLogic'
|
|
9
|
-
import { createTypeIndexLogic } from '../typeIndex/typeIndexLogic'
|
|
10
|
-
import { createContainerLogic } from '../util/containerLogic'
|
|
11
|
-
import { createUtilityLogic } from '../util/utilityLogic'
|
|
12
|
-
import { AuthnLogic, SolidLogic } from '../types'
|
|
13
|
-
import * as debug from '../util/debug'
|
|
14
|
-
/*
|
|
15
|
-
** It is important to distinquish `fetch`, a function provided by the browser
|
|
16
|
-
** and `Fetcher`, a helper object for the rdflib Store which turns it
|
|
17
|
-
** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
|
|
18
|
-
** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
|
|
19
|
-
*/
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
export function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: Session): SolidLogic {
|
|
22
|
-
|
|
23
|
-
debug.log('SolidLogic: Unique instance created. There should only be one of these.')
|
|
24
|
-
const store: LiveStore = rdf.graph() as LiveStore
|
|
25
|
-
rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher
|
|
26
|
-
store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater
|
|
27
|
-
store.features = [] // disable automatic node merging on store load
|
|
28
|
-
|
|
29
|
-
const authn: AuthnLogic = new SolidAuthnLogic(session)
|
|
30
|
-
|
|
31
|
-
const acl = createAclLogic(store)
|
|
32
|
-
const containerLogic = createContainerLogic(store)
|
|
33
|
-
const utilityLogic = createUtilityLogic(store, acl, containerLogic)
|
|
34
|
-
const profile = createProfileLogic(store, authn, utilityLogic)
|
|
35
|
-
const chat = createChatLogic(store, profile)
|
|
36
|
-
const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)
|
|
37
|
-
const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)
|
|
38
|
-
debug.log('SolidAuthnLogic initialized')
|
|
39
|
-
|
|
40
|
-
function load(doc: NamedNode | NamedNode[] | string) {
|
|
41
|
-
return store.fetcher.load(doc)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
45
|
-
function updatePromise(
|
|
46
|
-
del: Array<Statement>,
|
|
47
|
-
ins: Array<Statement> = []
|
|
48
|
-
): Promise<void> {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
51
|
-
if (!ok) {
|
|
52
|
-
reject(new Error(errorBody))
|
|
53
|
-
} else {
|
|
54
|
-
resolve()
|
|
55
|
-
}
|
|
56
|
-
}) // callback
|
|
57
|
-
}) // promise
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function clearStore() {
|
|
61
|
-
store.statements.slice().forEach(store.remove.bind(store))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
store,
|
|
66
|
-
authn,
|
|
67
|
-
acl,
|
|
68
|
-
inbox,
|
|
69
|
-
chat,
|
|
70
|
-
profile,
|
|
71
|
-
typeIndex,
|
|
72
|
-
load,
|
|
73
|
-
updatePromise,
|
|
74
|
-
clearStore
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as debug from '../util/debug'
|
|
2
|
-
import { authSession } from '../authSession/authSession'
|
|
3
|
-
import { createSolidLogic } from './solidLogic'
|
|
4
|
-
|
|
5
|
-
const _fetch = async (url, requestInit) => {
|
|
6
|
-
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
7
|
-
if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
|
|
8
|
-
// In fact fetch should respect credentials omit itself
|
|
9
|
-
return authSession.fetch(url, requestInit)
|
|
10
|
-
} else {
|
|
11
|
-
return window.fetch(url, requestInit)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//this const makes solidLogicSingleton global accessible in mashlib
|
|
16
|
-
const solidLogicSingleton = createSolidLogic({ fetch: _fetch }, authSession)
|
|
17
|
-
|
|
18
|
-
debug.log('Unique quadstore initialized.')
|
|
19
|
-
|
|
20
|
-
export { solidLogicSingleton }
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { NamedNode } from 'rdflib'
|
|
2
|
-
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from '../logic/CustomError'
|
|
3
|
-
import * as debug from '../util/debug'
|
|
4
|
-
import { ns as namespace } from '../util/ns'
|
|
5
|
-
import { differentOrigin, suggestPreferencesFile } from '../util/utils'
|
|
6
|
-
import { ProfileLogic } from '../types'
|
|
7
|
-
|
|
8
|
-
export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
9
|
-
const ns = namespace
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* loads the preference without throwing errors - if it can create it it does so.
|
|
13
|
-
* remark: it still throws error if it cannot load profile.
|
|
14
|
-
* @param user
|
|
15
|
-
* @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it
|
|
16
|
-
*/
|
|
17
|
-
async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {
|
|
18
|
-
try {
|
|
19
|
-
return await loadPreferences(user)
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
-
} catch (err) {
|
|
22
|
-
return undefined
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* loads the preference without returning different errors if it cannot create or load it.
|
|
28
|
-
* remark: it also throws error if it cannot load profile.
|
|
29
|
-
* @param user
|
|
30
|
-
* @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it
|
|
31
|
-
*/
|
|
32
|
-
async function loadPreferences (user: NamedNode): Promise <NamedNode> {
|
|
33
|
-
await loadProfile(user)
|
|
34
|
-
|
|
35
|
-
const possiblePreferencesFile = suggestPreferencesFile(user)
|
|
36
|
-
let preferencesFile
|
|
37
|
-
try {
|
|
38
|
-
preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const message = `User ${user} has no pointer in profile to preferences file.`
|
|
41
|
-
debug.warn(message)
|
|
42
|
-
// we are listing the possible errors
|
|
43
|
-
if (err instanceof NotEditableError) { throw err }
|
|
44
|
-
if (err instanceof WebOperationError) { throw err }
|
|
45
|
-
if (err instanceof UnauthorizedError) { throw err }
|
|
46
|
-
if (err instanceof CrossOriginForbiddenError) { throw err }
|
|
47
|
-
if (err instanceof SameOriginForbiddenError) { throw err }
|
|
48
|
-
if (err instanceof FetchError) { throw err }
|
|
49
|
-
throw err
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
await store.fetcher.load(preferencesFile as NamedNode)
|
|
54
|
-
} catch (err) { // Maybe a permission problem or origin problem
|
|
55
|
-
const msg = `Unable to load preference of user ${user}: ${err}`
|
|
56
|
-
debug.warn(msg)
|
|
57
|
-
if (err.response.status === 401) {
|
|
58
|
-
throw new UnauthorizedError()
|
|
59
|
-
}
|
|
60
|
-
if (err.response.status === 403) {
|
|
61
|
-
if (differentOrigin(preferencesFile)) {
|
|
62
|
-
throw new CrossOriginForbiddenError()
|
|
63
|
-
}
|
|
64
|
-
throw new SameOriginForbiddenError()
|
|
65
|
-
}
|
|
66
|
-
/*if (err.response.status === 404) {
|
|
67
|
-
throw new NotFoundError();
|
|
68
|
-
}*/
|
|
69
|
-
throw new Error(msg)
|
|
70
|
-
}
|
|
71
|
-
return preferencesFile as NamedNode
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function loadProfile (user: NamedNode):Promise <NamedNode> {
|
|
75
|
-
if (!user) {
|
|
76
|
-
throw new Error('loadProfile: no user given.')
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
await store.fetcher.load(user.doc())
|
|
80
|
-
} catch (err) {
|
|
81
|
-
throw new Error(`Unable to load profile of user ${user}: ${err}`)
|
|
82
|
-
}
|
|
83
|
-
return user.doc()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function loadMe(): Promise<NamedNode> {
|
|
87
|
-
const me = authn.currentUser()
|
|
88
|
-
if (me === null) {
|
|
89
|
-
throw new Error('Current user not found! Not logged in?')
|
|
90
|
-
}
|
|
91
|
-
await store.fetcher.load(me.doc())
|
|
92
|
-
return me
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function getPodRoot(user: NamedNode): NamedNode {
|
|
96
|
-
const podRoot = findStorage(user)
|
|
97
|
-
if (!podRoot) {
|
|
98
|
-
throw new Error('User pod root not found!')
|
|
99
|
-
}
|
|
100
|
-
return podRoot as NamedNode
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function getMainInbox(user: NamedNode): Promise<NamedNode> {
|
|
104
|
-
await store.fetcher.load(user)
|
|
105
|
-
const mainInbox = store.any(user, ns.ldp('inbox'), undefined, user.doc())
|
|
106
|
-
if (!mainInbox) {
|
|
107
|
-
throw new Error('User main inbox not found!')
|
|
108
|
-
}
|
|
109
|
-
return mainInbox as NamedNode
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function findStorage(me: NamedNode) {
|
|
113
|
-
return store.any(me, ns.space('storage'), undefined, me.doc())
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
loadMe,
|
|
118
|
-
getPodRoot,
|
|
119
|
-
getMainInbox,
|
|
120
|
-
findStorage,
|
|
121
|
-
loadPreferences,
|
|
122
|
-
loadProfile,
|
|
123
|
-
silencedLoadPreferences
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { NamedNode, st, sym } from 'rdflib'
|
|
2
|
-
import { ScopedApp, TypeIndexLogic, TypeIndexScope } from '../types'
|
|
3
|
-
import * as debug from '../util/debug'
|
|
4
|
-
import { ns as namespace } from '../util/ns'
|
|
5
|
-
import { newThing } from '../util/utils'
|
|
6
|
-
|
|
7
|
-
export function createTypeIndexLogic(store, authn, profileLogic, utilityLogic): TypeIndexLogic {
|
|
8
|
-
const ns = namespace
|
|
9
|
-
|
|
10
|
-
function getRegistrations(instance, theClass) {
|
|
11
|
-
return store
|
|
12
|
-
.each(undefined, ns.solid('instance'), instance)
|
|
13
|
-
.filter((r) => {
|
|
14
|
-
return store.holds(r, ns.solid('forClass'), theClass)
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function loadTypeIndexesFor(user: NamedNode): Promise<Array<TypeIndexScope>> {
|
|
19
|
-
if (!user) throw new Error('loadTypeIndexesFor: No user given')
|
|
20
|
-
const profile = await profileLogic.loadProfile(user)
|
|
21
|
-
|
|
22
|
-
const suggestion = suggestPublicTypeIndex(user)
|
|
23
|
-
let publicTypeIndex
|
|
24
|
-
try {
|
|
25
|
-
publicTypeIndex = await utilityLogic.followOrCreateLink(user, ns.solid('publicTypeIndex') as NamedNode, suggestion, profile)
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
-
} catch (err) {
|
|
28
|
-
const message = `User ${user} has no pointer in profile to publicTypeIndex file.`
|
|
29
|
-
debug.warn(message)
|
|
30
|
-
}
|
|
31
|
-
const publicScopes = publicTypeIndex ? [{ label: 'public', index: publicTypeIndex as NamedNode, agent: user }] : []
|
|
32
|
-
|
|
33
|
-
let preferencesFile
|
|
34
|
-
try {
|
|
35
|
-
preferencesFile = await profileLogic.silencedLoadPreferences(user)
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
|
-
} catch (err) {
|
|
38
|
-
preferencesFile = null
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let privateScopes
|
|
42
|
-
if (preferencesFile) { // watch out - can be in either as spec was not clear. Legacy is profile.
|
|
43
|
-
// If there is a legacy one linked from the profile, use that.
|
|
44
|
-
// Otherwiae use or make one linked from Preferences
|
|
45
|
-
const suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)
|
|
46
|
-
let privateTypeIndex
|
|
47
|
-
try {
|
|
48
|
-
privateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile) ||
|
|
49
|
-
await utilityLogic.followOrCreateLink(user, ns.solid('privateTypeIndex') as NamedNode, suggestedPrivateTypeIndex, preferencesFile)
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
-
} catch (err) {
|
|
52
|
-
const message = `User ${user} has no pointer in preference file to privateTypeIndex file.`
|
|
53
|
-
debug.warn(message)
|
|
54
|
-
}
|
|
55
|
-
privateScopes = privateTypeIndex ? [{ label: 'private', index: privateTypeIndex as NamedNode, agent: user }] : []
|
|
56
|
-
} else {
|
|
57
|
-
privateScopes = []
|
|
58
|
-
}
|
|
59
|
-
const scopes = publicScopes.concat(privateScopes)
|
|
60
|
-
if (scopes.length === 0) return scopes
|
|
61
|
-
const files = scopes.map(scope => scope.index)
|
|
62
|
-
try {
|
|
63
|
-
await store.fetcher.load(files)
|
|
64
|
-
} catch (err) {
|
|
65
|
-
debug.warn('Problems loading type index: ', err)
|
|
66
|
-
}
|
|
67
|
-
return scopes
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function loadCommunityTypeIndexes(user: NamedNode): Promise<TypeIndexScope[][]> {
|
|
71
|
-
let preferencesFile
|
|
72
|
-
try {
|
|
73
|
-
preferencesFile = await profileLogic.silencedLoadPreferences(user)
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
-
} catch (err) {
|
|
76
|
-
const message = `User ${user} has no pointer in profile to preferences file.`
|
|
77
|
-
debug.warn(message)
|
|
78
|
-
}
|
|
79
|
-
if (preferencesFile) { // For now, pick up communities as simple links from the preferences file.
|
|
80
|
-
const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(
|
|
81
|
-
store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)
|
|
82
|
-
)
|
|
83
|
-
let result = []
|
|
84
|
-
for (const org of communities) {
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
result = result.concat(await loadTypeIndexesFor(org as NamedNode) as any)
|
|
87
|
-
}
|
|
88
|
-
return result
|
|
89
|
-
}
|
|
90
|
-
return [] // No communities
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function loadAllTypeIndexes(user: NamedNode) {
|
|
94
|
-
return (await loadTypeIndexesFor(user)).concat((await loadCommunityTypeIndexes(user)).flat())
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function getScopedAppInstances(klass: NamedNode, user: NamedNode): Promise<ScopedApp[]> {
|
|
98
|
-
const scopes = await loadAllTypeIndexes(user)
|
|
99
|
-
let scopedApps = []
|
|
100
|
-
for (const scope of scopes) {
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
-
const scopedApps0 = await getScopedAppsFromIndex(scope, klass) as any
|
|
103
|
-
scopedApps = scopedApps.concat(scopedApps0)
|
|
104
|
-
}
|
|
105
|
-
return scopedApps
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// This is the function signature which used to be in solid-ui/logic
|
|
109
|
-
// Recommended to use getScopedAppInstances instead as it provides more information.
|
|
110
|
-
//
|
|
111
|
-
async function getAppInstances(klass: NamedNode): Promise<NamedNode[]> {
|
|
112
|
-
const user = authn.currentUser()
|
|
113
|
-
if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')
|
|
114
|
-
const scopedAppInstances = await getScopedAppInstances(klass, user)
|
|
115
|
-
return scopedAppInstances.map(scoped => scoped.instance)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function suggestPublicTypeIndex(me: NamedNode) {
|
|
119
|
-
return sym(me.doc().dir()?.uri + 'publicTypeIndex.ttl')
|
|
120
|
-
}
|
|
121
|
-
// Note this one is based off the pref file not the profile
|
|
122
|
-
|
|
123
|
-
function suggestPrivateTypeIndex(preferencesFile: NamedNode) {
|
|
124
|
-
return sym(preferencesFile.doc().dir()?.uri + 'privateTypeIndex.ttl')
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/*
|
|
128
|
-
* Register a new app in a type index
|
|
129
|
-
* used in chat in bookmark.js (solid-ui)
|
|
130
|
-
* Returns the registration object if successful else null
|
|
131
|
-
*/
|
|
132
|
-
async function registerInTypeIndex(
|
|
133
|
-
instance: NamedNode,
|
|
134
|
-
index: NamedNode,
|
|
135
|
-
theClass: NamedNode,
|
|
136
|
-
// agent: NamedNode
|
|
137
|
-
): Promise<NamedNode | null> {
|
|
138
|
-
const registration = newThing(index)
|
|
139
|
-
const ins = [
|
|
140
|
-
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
|
|
141
|
-
st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
142
|
-
st(registration, ns.solid('forClass'), theClass, index),
|
|
143
|
-
st(registration, ns.solid('instance'), instance, index)
|
|
144
|
-
]
|
|
145
|
-
try {
|
|
146
|
-
await store.updater.update([], ins)
|
|
147
|
-
} catch (err) {
|
|
148
|
-
const msg = `Unable to register ${instance} in index ${index}: ${err}`
|
|
149
|
-
console.warn(msg)
|
|
150
|
-
return null
|
|
151
|
-
}
|
|
152
|
-
return registration
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function deleteTypeIndexRegistration(item) {
|
|
156
|
-
const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode
|
|
157
|
-
if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)
|
|
158
|
-
const statements = store.statementsMatching(reg, null, null, item.scope.index)
|
|
159
|
-
await store.updater.update(statements, [])
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async function getScopedAppsFromIndex(scope: TypeIndexScope, theClass: NamedNode | null): Promise<ScopedApp[]> {
|
|
163
|
-
const index = scope.index
|
|
164
|
-
const results: ScopedApp[] = []
|
|
165
|
-
const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
|
|
166
|
-
.concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
|
|
167
|
-
.map(st => st.subject)
|
|
168
|
-
for (const reg of registrations) {
|
|
169
|
-
const klass = store.any(reg, ns.solid('forClass'), null, index)
|
|
170
|
-
if (!theClass || klass.sameTerm(theClass)) {
|
|
171
|
-
const instances = store.each(reg, ns.solid('instance'), null, index)
|
|
172
|
-
for (const instance of instances) {
|
|
173
|
-
results.push({ instance, type: klass, scope })
|
|
174
|
-
}
|
|
175
|
-
const containers = store.each(reg, ns.solid('instanceContainer'), null, index)
|
|
176
|
-
for (const instance of containers) {
|
|
177
|
-
await store.fetcher.load(instance)
|
|
178
|
-
results.push({ instance: sym(instance.value), type: klass, scope })
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return results
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
registerInTypeIndex,
|
|
187
|
-
getRegistrations,
|
|
188
|
-
loadTypeIndexesFor,
|
|
189
|
-
loadCommunityTypeIndexes,
|
|
190
|
-
loadAllTypeIndexes,
|
|
191
|
-
getScopedAppInstances,
|
|
192
|
-
getAppInstances,
|
|
193
|
-
suggestPublicTypeIndex,
|
|
194
|
-
suggestPrivateTypeIndex,
|
|
195
|
-
deleteTypeIndexRegistration,
|
|
196
|
-
getScopedAppsFromIndex
|
|
197
|
-
}
|
|
198
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Session } from '@inrupt/solid-client-authn-browser'
|
|
2
|
-
import { LiveStore, NamedNode, Statement } from 'rdflib'
|
|
3
|
-
|
|
4
|
-
export type AppDetails = {
|
|
5
|
-
noun: string
|
|
6
|
-
appPathSegment: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type AuthenticationContext = {
|
|
10
|
-
containers?: Array<NamedNode>
|
|
11
|
-
div?: HTMLElement
|
|
12
|
-
dom?: HTMLDocument
|
|
13
|
-
index?: { [key: string]: Array<NamedNode> }
|
|
14
|
-
instances?: Array<NamedNode>
|
|
15
|
-
me?: NamedNode | null
|
|
16
|
-
noun?: string
|
|
17
|
-
preferencesFile?: NamedNode
|
|
18
|
-
preferencesFileError?: string
|
|
19
|
-
publicProfile?: NamedNode
|
|
20
|
-
statusArea?: HTMLElement
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface AuthnLogic {
|
|
24
|
-
authSession: Session //this needs to be deprecated in the future. Is only here to allow imports like panes.UI.authn.authSession prior to moving authn from ui to logic
|
|
25
|
-
currentUser: () => NamedNode | null
|
|
26
|
-
checkUser: <T>(setUserCallback?: (me: NamedNode | null) => T) => Promise<NamedNode | T | null>
|
|
27
|
-
saveUser: (webId: NamedNode | string | null,
|
|
28
|
-
context?: AuthenticationContext) => NamedNode | null
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface SolidNamespace {
|
|
32
|
-
[key: string]: (term: string) => NamedNode
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type TypeIndexScope = { label: string, index: NamedNode, agent: NamedNode }
|
|
36
|
-
export type ScopedApp = { instance: NamedNode, type: NamedNode, scope: TypeIndexScope }
|
|
37
|
-
|
|
38
|
-
export interface NewPaneOptions {
|
|
39
|
-
me?: NamedNode;
|
|
40
|
-
newInstance?: NamedNode;
|
|
41
|
-
newBase: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface CreatedPaneOptions {
|
|
45
|
-
newInstance: NamedNode;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface ChatLogic {
|
|
49
|
-
setAcl: (chatContainer: NamedNode, me: NamedNode, invitee: NamedNode) => Promise<void>,
|
|
50
|
-
addToPrivateTypeIndex: (chatThing, me) => void | Promise<void>,
|
|
51
|
-
findChat: (invitee: NamedNode) => Promise<Chat>,
|
|
52
|
-
createChatThing: (chatContainer: NamedNode, me: NamedNode) => Promise<NamedNode>,
|
|
53
|
-
mintNew: (newPaneOptions: NewPaneOptions) => Promise<CreatedPaneOptions>,
|
|
54
|
-
getChat: (invitee: NamedNode, boolean) => Promise<NamedNode | null>,
|
|
55
|
-
sendInvite: (invitee: NamedNode, chatThing: NamedNode) => void
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface Chat {
|
|
59
|
-
me: NamedNode,
|
|
60
|
-
chatContainer: NamedNode,
|
|
61
|
-
exists: boolean
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ProfileLogic {
|
|
65
|
-
silencedLoadPreferences: (user: NamedNode) => Promise<NamedNode | undefined>,
|
|
66
|
-
loadPreferences: (user: NamedNode) => Promise<NamedNode>,
|
|
67
|
-
loadProfile: (user: NamedNode) => Promise<NamedNode>,
|
|
68
|
-
loadMe: () => Promise<NamedNode>,
|
|
69
|
-
getPodRoot: (user: NamedNode) => NamedNode,
|
|
70
|
-
getMainInbox: (user: NamedNode) => Promise<NamedNode>,
|
|
71
|
-
findStorage: (me: NamedNode) => Node | null
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface AclLogic {
|
|
75
|
-
findAclDocUrl: (url: NamedNode) => Promise<string | undefined>,
|
|
76
|
-
setACLUserPublic: (docURI: string, me: NamedNode,
|
|
77
|
-
options: {
|
|
78
|
-
defaultForNew?: boolean,
|
|
79
|
-
public?: []
|
|
80
|
-
}
|
|
81
|
-
) => Promise<NamedNode>,
|
|
82
|
-
genACLText: (docURI: string, me: NamedNode, aclURI: string,
|
|
83
|
-
options: {
|
|
84
|
-
defaultForNew?: boolean,
|
|
85
|
-
public?: []
|
|
86
|
-
}
|
|
87
|
-
) => string | undefined
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface InboxLogic {
|
|
91
|
-
createInboxFor: (peerWebId: string, nick: string) => Promise<string>,
|
|
92
|
-
getNewMessages: (user?: NamedNode) => Promise<NamedNode[]>,
|
|
93
|
-
markAsRead: (url: string, date: Date) => void
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface TypeIndexLogic {
|
|
97
|
-
getRegistrations: (instance, theClass) => Node[],
|
|
98
|
-
loadTypeIndexesFor: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
|
|
99
|
-
loadCommunityTypeIndexes: (user: NamedNode) => Promise<TypeIndexScope[][]>,
|
|
100
|
-
loadAllTypeIndexes: (user: NamedNode) => Promise<Array<TypeIndexScope>>,
|
|
101
|
-
getScopedAppInstances: (klass: NamedNode, user: NamedNode) => Promise<ScopedApp[]>,
|
|
102
|
-
getAppInstances: (klass: NamedNode) => Promise<NamedNode[]>,
|
|
103
|
-
suggestPublicTypeIndex: (me: NamedNode) => NamedNode,
|
|
104
|
-
suggestPrivateTypeIndex: (preferencesFile: NamedNode) => NamedNode,
|
|
105
|
-
registerInTypeIndex: (instance: NamedNode, index: NamedNode, theClass: NamedNode) => Promise<NamedNode | null>,
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
deleteTypeIndexRegistration: (item: any) => Promise<void>
|
|
108
|
-
getScopedAppsFromIndex: (scope: TypeIndexScope, theClass: NamedNode | null) => Promise<ScopedApp[]>
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface SolidLogic {
|
|
112
|
-
store: LiveStore,
|
|
113
|
-
authn: AuthnLogic,
|
|
114
|
-
acl: AclLogic,
|
|
115
|
-
profile: ProfileLogic,
|
|
116
|
-
inbox: InboxLogic,
|
|
117
|
-
typeIndex: TypeIndexLogic,
|
|
118
|
-
chat: ChatLogic,
|
|
119
|
-
load: (doc: NamedNode | NamedNode[] | string) => void,
|
|
120
|
-
updatePromise: (del: Array<Statement>, ins: Array<Statement>) => Promise<void>,
|
|
121
|
-
clearStore: () => void
|
|
122
|
-
}
|
package/src/util/debug.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
export function log(...args: any[]): void {
|
|
3
|
-
console.log(...args)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function warn(...args: any[]): void {
|
|
7
|
-
console.warn(...args)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function error(...args: any[]): void {
|
|
11
|
-
console.error(...args)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function trace(...args: any[]): void {
|
|
15
|
-
console.trace(...args)
|
|
16
|
-
}
|
package/src/util/ns.ts
DELETED