solid-logic 3.1.1-da65b2c → 3.1.1-e3eba68
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 +2 -108
- package/eslint.config.js +29 -0
- package/jest.config.js +10 -0
- package/lib/acl/aclLogic.d.ts +5 -0
- package/{dist → lib}/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +168 -0
- package/lib/acl/aclLogic.js.map +1 -0
- package/{dist → lib}/authSession/authSession.js +1 -1
- package/{dist → lib}/authSession/authSession.js.map +1 -1
- package/{dist → lib}/authn/SolidAuthnLogic.d.ts +3 -3
- package/{dist → lib}/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +193 -0
- package/lib/authn/SolidAuthnLogic.js.map +1 -0
- package/{dist → lib}/authn/authUtil.d.ts +1 -1
- package/{dist → lib}/authn/authUtil.js +12 -12
- package/lib/authn/authUtil.js.map +1 -0
- package/{dist → lib}/chat/chatLogic.d.ts +1 -1
- package/lib/chat/chatLogic.js +272 -0
- package/lib/chat/chatLogic.js.map +1 -0
- package/{dist → lib}/inbox/inboxLogic.d.ts +1 -1
- package/{dist → lib}/inbox/inboxLogic.d.ts.map +1 -1
- package/lib/inbox/inboxLogic.js +139 -0
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/{dist → lib}/index.d.ts +1 -1
- package/{dist → lib}/index.d.ts.map +1 -1
- package/{dist → lib}/index.js +4 -4
- package/{dist → lib}/index.js.map +1 -1
- package/lib/issuer/issuerLogic.js +52 -0
- package/lib/issuer/issuerLogic.js.map +1 -0
- package/{dist → lib}/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +89 -0
- package/lib/logic/CustomError.js.map +1 -0
- package/lib/logic/solidLogic.d.ts +6 -0
- package/{dist → lib}/logic/solidLogic.d.ts.map +1 -1
- package/{dist → lib}/logic/solidLogic.js +33 -32
- package/lib/logic/solidLogic.js.map +1 -0
- package/lib/logic/solidLogicSingleton.js +94 -0
- package/lib/logic/solidLogicSingleton.js.map +1 -0
- package/{dist → lib}/profile/profileLogic.d.ts +1 -1
- package/lib/profile/profileLogic.js +259 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.js +399 -0
- package/lib/typeIndex/typeIndexLogic.js.map +1 -0
- package/{dist → lib}/types.d.ts +2 -2
- package/{dist → lib}/util/containerLogic.d.ts +1 -1
- package/{dist → lib}/util/containerLogic.d.ts.map +1 -1
- package/lib/util/containerLogic.js +102 -0
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/debug.d.ts.map +1 -0
- package/lib/util/debug.js +40 -0
- package/lib/util/debug.js.map +1 -0
- package/{dist → lib}/util/ns.js +2 -2
- package/{dist → lib}/util/ns.js.map +1 -1
- package/{dist → lib}/util/utilityLogic.d.ts +1 -1
- package/{dist → lib}/util/utilityLogic.d.ts.map +1 -1
- package/lib/util/utilityLogic.js +284 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/{dist → lib}/util/utils.d.ts +1 -1
- package/{dist → lib}/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +47 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +20 -58
- package/src/acl/aclLogic.ts +156 -0
- package/src/authSession/authSession.ts +7 -0
- package/src/authn/SolidAuthnLogic.ts +127 -0
- package/src/authn/authUtil.ts +70 -0
- package/src/chat/chatLogic.ts +226 -0
- package/src/inbox/inboxLogic.ts +59 -0
- package/src/index.ts +22 -0
- package/src/issuer/issuerLogic.ts +40 -0
- package/src/logic/CustomError.ts +29 -0
- package/src/logic/solidLogic.ts +76 -0
- package/src/logic/solidLogicSingleton.ts +20 -0
- package/src/profile/profileLogic.ts +125 -0
- package/src/typeIndex/typeIndexLogic.ts +198 -0
- package/src/types.ts +122 -0
- package/{dist/util/containerLogic.js → src/util/containerLogic.ts} +25 -20
- package/src/util/debug.ts +20 -0
- package/src/util/ns.ts +5 -0
- package/src/util/utilityLogic.ts +156 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +24 -0
- package/test/authUtil.test.ts +23 -0
- package/test/chatLogic.test.ts +316 -0
- package/test/container.test.ts +58 -0
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +17 -0
- package/test/inboxLogic.test.ts +218 -0
- package/test/logic.test.ts +29 -0
- package/test/profileLogic.test.ts +246 -0
- package/test/solidAuthLogic.test.ts +49 -0
- package/test/typeIndexLogic.test.ts +255 -0
- package/test/utilityLogic.test.ts +179 -0
- package/test/utils.test.ts +32 -0
- package/tsconfig.json +75 -0
- package/dist/789.solid-logic.js +0 -11
- package/dist/789.solid-logic.js.map +0 -1
- package/dist/789.solid-logic.min.js +0 -1
- package/dist/841.solid-logic.js +0 -12133
- package/dist/841.solid-logic.js.map +0 -1
- package/dist/841.solid-logic.min.js +0 -73
- package/dist/841.solid-logic.min.js.map +0 -1
- package/dist/acl/aclLogic.d.ts +0 -5
- package/dist/acl/aclLogic.js +0 -122
- package/dist/acl/aclLogic.js.map +0 -1
- package/dist/authn/SolidAuthnLogic.js +0 -147
- package/dist/authn/SolidAuthnLogic.js.map +0 -1
- package/dist/authn/authUtil.js.map +0 -1
- package/dist/chat/chatLogic.js +0 -160
- package/dist/chat/chatLogic.js.map +0 -1
- package/dist/inbox/inboxLogic.js +0 -55
- package/dist/inbox/inboxLogic.js.map +0 -1
- package/dist/issuer/issuerLogic.js +0 -40
- package/dist/issuer/issuerLogic.js.map +0 -1
- package/dist/logic/CustomError.js +0 -38
- package/dist/logic/CustomError.js.map +0 -1
- package/dist/logic/solidLogic.d.ts +0 -6
- package/dist/logic/solidLogic.js.map +0 -1
- package/dist/logic/solidLogicSingleton.js +0 -54
- package/dist/logic/solidLogicSingleton.js.map +0 -1
- package/dist/profile/profileLogic.js +0 -165
- package/dist/profile/profileLogic.js.map +0 -1
- package/dist/solid-logic.esm.external.js +0 -12725
- package/dist/solid-logic.esm.external.js.map +0 -1
- package/dist/solid-logic.esm.external.min.js +0 -32
- package/dist/solid-logic.esm.external.min.js.map +0 -1
- package/dist/solid-logic.external.js +0 -12802
- package/dist/solid-logic.external.js.map +0 -1
- package/dist/solid-logic.external.min.js +0 -32
- package/dist/solid-logic.external.min.js.map +0 -1
- package/dist/solid-logic.js +0 -40921
- package/dist/solid-logic.js.map +0 -1
- package/dist/solid-logic.min.js +0 -41
- package/dist/solid-logic.min.js.map +0 -1
- package/dist/typeIndex/typeIndexLogic.js +0 -222
- package/dist/typeIndex/typeIndexLogic.js.map +0 -1
- package/dist/util/containerLogic.js.map +0 -1
- package/dist/util/debug.d.ts.map +0 -1
- package/dist/util/debug.js +0 -20
- package/dist/util/debug.js.map +0 -1
- package/dist/util/utilityLogic.js +0 -180
- package/dist/util/utilityLogic.js.map +0 -1
- package/dist/util/utils.js +0 -47
- package/dist/util/utils.js.map +0 -1
- package/dist/versionInfo.js +0 -33
- package/dist/versionInfo.js.map +0 -1
- /package/{dist → lib}/authSession/authSession.d.ts +0 -0
- /package/{dist → lib}/authSession/authSession.d.ts.map +0 -0
- /package/{dist → lib}/authn/authUtil.d.ts.map +0 -0
- /package/{dist → lib}/chat/chatLogic.d.ts.map +0 -0
- /package/{dist → lib}/issuer/issuerLogic.d.ts +0 -0
- /package/{dist → lib}/issuer/issuerLogic.d.ts.map +0 -0
- /package/{dist → lib}/logic/CustomError.d.ts +0 -0
- /package/{dist → lib}/logic/solidLogicSingleton.d.ts +0 -0
- /package/{dist → lib}/logic/solidLogicSingleton.d.ts.map +0 -0
- /package/{dist → lib}/profile/profileLogic.d.ts.map +0 -0
- /package/{dist → lib}/typeIndex/typeIndexLogic.d.ts +0 -0
- /package/{dist → lib}/typeIndex/typeIndexLogic.d.ts.map +0 -0
- /package/{dist → lib}/types.d.ts.map +0 -0
- /package/{dist → lib}/types.js +0 -0
- /package/{dist → lib}/types.js.map +0 -0
- /package/{dist → lib}/util/debug.d.ts +0 -0
- /package/{dist → lib}/util/ns.d.ts +0 -0
- /package/{dist → lib}/util/ns.d.ts.map +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
}
|
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createContainerLogic = createContainerLogic;
|
|
4
|
-
const rdflib_1 = require("rdflib");
|
|
1
|
+
import { NamedNode, Statement, sym } from "rdflib";
|
|
2
|
+
|
|
5
3
|
/**
|
|
6
4
|
* Container-related class
|
|
7
5
|
*/
|
|
8
|
-
function createContainerLogic(store) {
|
|
9
|
-
|
|
6
|
+
export function createContainerLogic(store) {
|
|
7
|
+
|
|
8
|
+
function getContainerElements(containerNode: NamedNode): NamedNode[] {
|
|
10
9
|
return store
|
|
11
|
-
.statementsMatching(
|
|
12
|
-
|
|
10
|
+
.statementsMatching(
|
|
11
|
+
containerNode,
|
|
12
|
+
sym("http://www.w3.org/ns/ldp#contains"),
|
|
13
|
+
undefined
|
|
14
|
+
)
|
|
15
|
+
.map((st: Statement) => st.object as NamedNode);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
function isContainer(url: NamedNode) {
|
|
15
19
|
const nodeToString = url.value;
|
|
16
|
-
return nodeToString.charAt(nodeToString.length - 1) ===
|
|
20
|
+
return nodeToString.charAt(nodeToString.length - 1) === "/";
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
async function createContainer(url: string) {
|
|
24
|
+
const stringToNode = sym(url);
|
|
20
25
|
if (!isContainer(stringToNode)) {
|
|
21
26
|
throw new Error(`Not a container URL ${url}`);
|
|
22
27
|
}
|
|
23
28
|
// Copied from https://github.com/solidos/solid-crud-tests/blob/v3.1.0/test/surface/create-container.test.ts#L56-L64
|
|
24
29
|
const result = await store.fetcher._fetch(url, {
|
|
25
|
-
method:
|
|
30
|
+
method: "PUT",
|
|
26
31
|
headers: {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
"Content-Type": "text/turtle",
|
|
33
|
+
"If-None-Match": "*",
|
|
29
34
|
Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"', // See https://github.com/solidos/node-solid-server/issues/1465
|
|
30
35
|
},
|
|
31
|
-
body:
|
|
36
|
+
body: " ", // work around https://github.com/michielbdejong/community-server/issues/4#issuecomment-776222863
|
|
32
37
|
});
|
|
33
38
|
if (result.status.toString()[0] !== '2') {
|
|
34
39
|
throw new Error(`Not OK: got ${result.status} response while creating container at ${url}`);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
|
|
42
|
+
|
|
43
|
+
async function getContainerMembers(containerUrl: NamedNode): Promise<NamedNode[]> {
|
|
38
44
|
await store.fetcher.load(containerUrl);
|
|
39
45
|
return getContainerElements(containerUrl);
|
|
40
46
|
}
|
|
@@ -43,6 +49,5 @@ function createContainerLogic(store) {
|
|
|
43
49
|
createContainer,
|
|
44
50
|
getContainerElements,
|
|
45
51
|
getContainerMembers
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=containerLogic.js.map
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
export function log(...args: any[]): void {
|
|
3
|
+
// eslint-disable-next-line no-console
|
|
4
|
+
console.log(...args);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function warn(...args: any[]): void {
|
|
8
|
+
// eslint-disable-next-line no-console
|
|
9
|
+
console.warn(...args);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function error(...args: any[]): void {
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.error(...args);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function trace(...args: any[]): void {
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.trace(...args);
|
|
20
|
+
}
|
package/src/util/ns.ts
ADDED