solid-logic 1.3.16 → 1.3.17-1aa535b3
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 +0 -0
- package/.github/workflows/release.yml +0 -0
- package/.nvmrc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/jest.config.js +0 -0
- package/lib/acl/aclLogic.d.ts +12 -30
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +151 -116
- package/lib/acl/aclLogic.js.map +1 -1
- package/lib/authSession/authSession.d.ts +0 -0
- package/lib/authSession/authSession.d.ts.map +0 -0
- package/lib/authSession/authSession.js +0 -0
- package/lib/authSession/authSession.js.map +0 -0
- package/lib/authn/SolidAuthnLogic.d.ts +0 -0
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +3 -3
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/authn/authUtil.d.ts +0 -0
- package/lib/authn/authUtil.d.ts.map +0 -0
- package/lib/authn/authUtil.js +1 -1
- package/lib/authn/authUtil.js.map +1 -1
- package/lib/chat/chatLogic.d.ts +16 -0
- package/lib/chat/chatLogic.d.ts.map +1 -0
- package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -87
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/discovery/discoveryLogic.d.ts +31 -7
- package/lib/discovery/discoveryLogic.d.ts.map +1 -1
- package/lib/discovery/discoveryLogic.js +378 -81
- package/lib/discovery/discoveryLogic.js.map +1 -1
- package/lib/inbox/inboxLogic.d.ts +7 -0
- package/lib/inbox/inboxLogic.d.ts.map +1 -0
- package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +10 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +76 -32
- package/lib/index.js.map +1 -1
- package/lib/issuer/issuerLogic.d.ts +0 -0
- package/lib/issuer/issuerLogic.d.ts.map +0 -0
- package/lib/issuer/issuerLogic.js +0 -0
- package/lib/issuer/issuerLogic.js.map +0 -0
- package/lib/logic/CustomError.d.ts +4 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +17 -1
- package/lib/logic/CustomError.js.map +1 -1
- package/lib/logic/solidLogicSingleton.d.ts +35 -3
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
- package/lib/logic/solidLogicSingleton.js +88 -9
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/profileLogic.d.ts +13 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +268 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +31 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +650 -295
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +0 -0
- package/lib/types.js.map +0 -0
- package/lib/util/containerLogic.d.ts +11 -0
- package/lib/util/containerLogic.d.ts.map +1 -0
- package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/debug.d.ts +0 -0
- package/lib/util/debug.d.ts.map +0 -0
- package/lib/util/debug.js +0 -0
- package/lib/util/debug.js.map +0 -0
- package/lib/util/utilityLogic.d.ts +15 -0
- package/lib/util/utilityLogic.d.ts.map +1 -0
- package/lib/util/utilityLogic.js +272 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +8 -0
- package/lib/util/utils.d.ts.map +1 -0
- package/lib/util/utils.js +48 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +10 -8
- package/src/acl/aclLogic.ts +135 -119
- package/src/authSession/authSession.ts +0 -0
- package/src/authn/SolidAuthnLogic.ts +8 -7
- package/src/authn/authUtil.ts +1 -1
- package/src/chat/chatLogic.ts +225 -0
- package/src/discovery/discoveryLogic.ts +225 -48
- package/src/inbox/inboxLogic.ts +57 -0
- package/src/index.ts +74 -21
- package/src/issuer/issuerLogic.ts +0 -0
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/solidLogicSingleton.ts +161 -8
- package/src/profile/profileLogic.ts +134 -0
- package/src/typeIndex/typeIndexLogic.ts +417 -153
- package/src/types.ts +7 -3
- package/src/util/containerLogic.ts +54 -0
- package/src/util/debug.ts +0 -0
- package/src/util/ns.js +5 -0
- package/src/util/utilityLogic.ts +155 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +13 -4
- package/test/authUtil.test.ts +0 -0
- package/test/chatLogic.test.ts +70 -71
- package/test/container.test.ts +56 -0
- package/test/discoveryLogic.test.ts +712 -0
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +4 -0
- package/test/inboxLogic.test.ts +39 -38
- package/test/logic.test.ts +11 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/solidAuthLogic.test.ts +0 -0
- package/test/typeIndexLogic.test.ts +48 -20
- package/test/typeIndexLogicPart2.test.ts +485 -0
- package/test/utilityLogic.test.ts +172 -126
- package/test/utils.test.ts +32 -0
- package/tsconfig.json +0 -0
- package/lib/chat/ChatLogic.d.ts +0 -26
- package/lib/chat/ChatLogic.d.ts.map +0 -1
- package/lib/chat/ChatLogic.js.map +0 -1
- package/lib/chat/determineChatContainer.d.ts +0 -3
- package/lib/chat/determineChatContainer.d.ts.map +0 -1
- package/lib/chat/determineChatContainer.js +0 -12
- package/lib/chat/determineChatContainer.js.map +0 -1
- package/lib/inbox/InboxLogic.d.ts +0 -18
- package/lib/inbox/InboxLogic.d.ts.map +0 -1
- package/lib/inbox/InboxLogic.js.map +0 -1
- package/lib/logic/SolidLogic.d.ts +0 -48
- package/lib/logic/SolidLogic.d.ts.map +0 -1
- package/lib/logic/SolidLogic.js +0 -321
- package/lib/logic/SolidLogic.js.map +0 -1
- package/lib/profile/ProfileLogic.d.ts +0 -13
- package/lib/profile/ProfileLogic.d.ts.map +0 -1
- package/lib/profile/ProfileLogic.js.map +0 -1
- package/lib/util/UtilityLogic.d.ts +0 -33
- package/lib/util/UtilityLogic.d.ts.map +0 -1
- package/lib/util/UtilityLogic.js +0 -240
- package/lib/util/UtilityLogic.js.map +0 -1
- package/lib/util/uri.d.ts +0 -3
- package/lib/util/uri.d.ts.map +0 -1
- package/lib/util/uri.js +0 -9
- package/lib/util/uri.js.map +0 -1
- package/src/chat/ChatLogic.ts +0 -244
- package/src/chat/determineChatContainer.ts +0 -14
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/logic/SolidLogic.ts +0 -262
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
|
@@ -1,90 +1,267 @@
|
|
|
1
|
-
import { NamedNode,
|
|
1
|
+
import { NamedNode, LiveStore, sym, st } from 'rdflib'
|
|
2
|
+
import * as $rdf from 'rdflib'
|
|
3
|
+
import { newThing } from "../util/utils"
|
|
4
|
+
import solidNamespace from 'solid-namespace'
|
|
5
|
+
import { authn } from '../logic/solidLogicSingleton'
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
const ns = solidNamespace($rdf)
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
type TypeIndexScope = { label: string, index: NamedNode, agent: NamedNode }
|
|
10
|
+
type ScopedApp = { instance: NamedNode, scope: TypeIndexScope }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a resource if it really does not exist
|
|
14
|
+
* Be absolutely sure something does not exist before creating a new empty file
|
|
15
|
+
* as otherwise existing could be deleted.
|
|
16
|
+
* @param doc {NamedNode} - The resource
|
|
17
|
+
*/
|
|
18
|
+
export async function loadOrCreateIfNotExists (store: LiveStore, doc: NamedNode) {
|
|
19
|
+
let response
|
|
20
|
+
try {
|
|
21
|
+
response = await store.fetcher.load(doc)
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (err.response.status === 404) {
|
|
24
|
+
try {
|
|
25
|
+
store.fetcher.webOperation('PUT', doc, {data: '', contentType: 'text/turtle'})
|
|
26
|
+
} catch (err) {
|
|
27
|
+
const msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err
|
|
28
|
+
throw new Error(msg)
|
|
29
|
+
}
|
|
30
|
+
delete store.fetcher.requested[doc.uri] // delete cached 404 error
|
|
31
|
+
} else {
|
|
32
|
+
const msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err
|
|
33
|
+
throw new Error(msg) // @@ add nested errors
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return response
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function suggestPreferencesFile (me:NamedNode) {
|
|
40
|
+
const stripped = me.uri.replace('/profile/', '/').replace('/public/', '/')
|
|
41
|
+
// const stripped = me.uri.replace(\/[p|P]rofile/\g, '/').replace(\/[p|P]ublic/\g, '/')
|
|
42
|
+
const folderURI = stripped.split('/').slice(0,-1).join('/') + '/Settings/'
|
|
43
|
+
const fileURI = folderURI + 'Preferences.ttl'
|
|
44
|
+
return sym(fileURI)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function suggestPublicTypeIndex (me:NamedNode) {
|
|
48
|
+
return sym(me.doc().dir()?.uri + 'publicTypeIndex.ttl')
|
|
49
|
+
}
|
|
50
|
+
// Note this one is based off the pref file not the profile
|
|
51
|
+
|
|
52
|
+
export function suggestPrivateTypeIndex (preferencesFile:NamedNode) {
|
|
53
|
+
return sym(preferencesFile.doc().dir()?.uri + 'privateTypeIndex.ttl')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Follow link from this doc to another thing, or else make a new link
|
|
57
|
+
**
|
|
58
|
+
** return: null no ld one and failed to make a new one
|
|
59
|
+
*/
|
|
60
|
+
export async function followOrCreateLink (store: LiveStore, subject: NamedNode, predicate: NamedNode,
|
|
61
|
+
object: NamedNode, doc:NamedNode):Promise<NamedNode | null> {
|
|
62
|
+
await store.fetcher.load(doc)
|
|
63
|
+
const result = store.any(subject, predicate, null, doc)
|
|
64
|
+
|
|
65
|
+
if (result) return result as NamedNode
|
|
66
|
+
if (!store.updater.editable(doc)) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
await store.updater.update([], [ st(subject, predicate, object, doc)])
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.warn(`followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`)
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await loadOrCreateIfNotExists(store, object)
|
|
78
|
+
// store.fetcher.webOperation('PUT', object, { data: '', contentType: 'text/turtle'})
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)
|
|
81
|
+
}
|
|
82
|
+
return object
|
|
8
83
|
}
|
|
9
84
|
|
|
10
|
-
export async function loadProfile(store: LiveStore, user) {
|
|
85
|
+
export async function loadProfile (store: LiveStore, user: NamedNode) {
|
|
11
86
|
if (!user) {
|
|
12
87
|
throw new Error(`loadProfile: no user given.`)
|
|
13
88
|
}
|
|
14
89
|
try {
|
|
15
90
|
await store.fetcher.load(user.doc())
|
|
16
91
|
} catch (err) {
|
|
17
|
-
throw new Error(`Unable to load profile of user
|
|
92
|
+
throw new Error(`Unable to load profile of user ${user}: ${err}`)
|
|
18
93
|
}
|
|
19
94
|
return user.doc()
|
|
20
95
|
}
|
|
21
96
|
|
|
22
|
-
export async function loadPreferences(store: LiveStore, user): Promise <NamedNode | undefined > {
|
|
23
|
-
|
|
24
|
-
|
|
97
|
+
export async function loadPreferences (store: LiveStore, user: NamedNode): Promise <NamedNode | undefined > {
|
|
98
|
+
await loadProfile(store as LiveStore, user)
|
|
99
|
+
|
|
100
|
+
const possiblePreferencesFile = suggestPreferencesFile(user)
|
|
101
|
+
|
|
102
|
+
const preferencesFile = await followOrCreateLink(store, user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())
|
|
103
|
+
|
|
25
104
|
if (!preferencesFile) {
|
|
26
|
-
|
|
105
|
+
const message = `User ${user} has no pointer in profile to preferences file.`
|
|
106
|
+
console.warn(message)
|
|
27
107
|
return undefined
|
|
28
108
|
}
|
|
29
109
|
try {
|
|
30
|
-
store.fetcher.load(preferencesFile as NamedNode)
|
|
31
|
-
} catch (err) { //
|
|
110
|
+
await store.fetcher.load(preferencesFile as NamedNode)
|
|
111
|
+
} catch (err) { // Maybe a permission propblem or origin problem
|
|
32
112
|
return undefined
|
|
33
|
-
// throw new Error(`Unable to load preferences file ${preferencesFile} of user <${user}>: ${err}`)
|
|
34
113
|
}
|
|
35
114
|
return preferencesFile as NamedNode
|
|
36
115
|
}
|
|
37
116
|
|
|
38
|
-
export async function loadTypeIndexesFor(store: LiveStore, user:NamedNode): Promise<Array<
|
|
117
|
+
export async function loadTypeIndexesFor (store: LiveStore, user:NamedNode): Promise<Array<TypeIndexScope>> {
|
|
39
118
|
if (!user) throw new Error(`loadTypeIndexesFor: No user given`)
|
|
40
119
|
const profile = await loadProfile(store, user)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
120
|
+
|
|
121
|
+
const suggestion = suggestPublicTypeIndex(user)
|
|
122
|
+
|
|
123
|
+
const publicTypeIndex = await followOrCreateLink(store, user, ns.solid('publicTypeIndex') as NamedNode, suggestion, profile)
|
|
124
|
+
|
|
125
|
+
const publicScopes = publicTypeIndex ? [ { label: 'public', index: publicTypeIndex as NamedNode, agent: user } ] : []
|
|
126
|
+
|
|
127
|
+
let preferencesFile
|
|
128
|
+
try {
|
|
129
|
+
preferencesFile = await loadPreferences(store, user)
|
|
130
|
+
} catch (err) {
|
|
131
|
+
preferencesFile = null
|
|
48
132
|
}
|
|
49
|
-
const pub = publicTypeIndex ? [ { label: 'public', index: publicTypeIndex as NamedNode, agent: user } ] : []
|
|
50
133
|
|
|
51
|
-
|
|
52
|
-
if (preferencesFile) { // watch out - can be in either as spec was not clear
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
134
|
+
let privateScopes
|
|
135
|
+
if (preferencesFile) { // watch out - can be in either as spec was not clear. Legacy is profile.
|
|
136
|
+
// If there is a legacy one linked from the profile, use that.
|
|
137
|
+
// Otherwiae use or make one linked from Preferences
|
|
138
|
+
const suggestedPrivateTypeIndex = suggestPrivateTypeIndex(preferencesFile)
|
|
139
|
+
|
|
140
|
+
const privateTypeIndex = store.any(user, ns.solid('privateTypeIndex'), undefined, profile) ||
|
|
141
|
+
|
|
142
|
+
await followOrCreateLink(store, user, ns.solid('privateTypeIndex') as NamedNode, suggestedPrivateTypeIndex, preferencesFile);
|
|
143
|
+
|
|
144
|
+
privateScopes = privateTypeIndex ? [ { label: 'private', index: privateTypeIndex as NamedNode, agent: user } ] : []
|
|
145
|
+
} else {
|
|
146
|
+
privateScopes = []
|
|
147
|
+
}
|
|
148
|
+
const scopes = publicScopes.concat(privateScopes)
|
|
149
|
+
if (scopes.length === 0) return scopes
|
|
150
|
+
const files = scopes.map(scope => scope.index)
|
|
151
|
+
try {
|
|
152
|
+
await store.fetcher.load(files)
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.warn('Problems loading type index: ', err)
|
|
57
155
|
}
|
|
58
|
-
return
|
|
156
|
+
return scopes
|
|
59
157
|
}
|
|
60
158
|
|
|
61
|
-
export async function loadCommunityTypeIndexes (store:LiveStore, user:NamedNode): Promise<
|
|
159
|
+
export async function loadCommunityTypeIndexes (store:LiveStore, user:NamedNode): Promise<TypeIndexScope[][]> {
|
|
62
160
|
const preferencesFile = await loadPreferences(store, user)
|
|
63
|
-
if (preferencesFile) {
|
|
64
|
-
const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// const communityTypeIndexes = await Promise.all(communityTypeIndexesPromise)
|
|
71
|
-
/*
|
|
72
|
-
let result = [] as TypeIndex[]
|
|
73
|
-
for(const community of communities) {
|
|
74
|
-
result = result.concat(await loadTypeIndexesFor(store, community as NamedNode)) as TypeIndex[] // @@ how oto make functional with async?
|
|
161
|
+
if (preferencesFile) { // For now, pick up communities as simple links from the preferences file.
|
|
162
|
+
const communities = store.each(user, ns.solid('community'), undefined, preferencesFile as NamedNode).concat(
|
|
163
|
+
store.each(user, ns.solid('community'), undefined, user.doc() as NamedNode)
|
|
164
|
+
)
|
|
165
|
+
let result = []
|
|
166
|
+
for (const org of communities) {
|
|
167
|
+
result = result.concat(await loadTypeIndexesFor(store, org as NamedNode) as any)
|
|
75
168
|
}
|
|
76
|
-
|
|
77
|
-
// return communityTypeIndexesPromise.resolve()
|
|
169
|
+
return result
|
|
78
170
|
}
|
|
79
|
-
return []
|
|
171
|
+
return [] // No communities
|
|
80
172
|
}
|
|
81
173
|
|
|
82
174
|
export async function loadAllTypeIndexes (store:LiveStore, user:NamedNode) {
|
|
83
175
|
return (await loadTypeIndexesFor(store, user)).concat((await loadCommunityTypeIndexes(store, user)).flat())
|
|
84
176
|
}
|
|
85
177
|
|
|
178
|
+
// Utility: remove duplicates from Array of NamedNodes
|
|
179
|
+
export function uniqueNodes (arr: NamedNode[]): NamedNode[] {
|
|
180
|
+
const uris = arr.map(x => x.uri)
|
|
181
|
+
const set = new Set(uris)
|
|
182
|
+
const uris2 = Array.from(set)
|
|
183
|
+
const arr2 = uris2.map(u => new NamedNode(u))
|
|
184
|
+
return arr2 // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function getScopedAppsFromIndex (store, scope, theClass: NamedNode | null) {
|
|
188
|
+
const index = scope.index
|
|
189
|
+
const registrations = store.statementsMatching(null, ns.solid('instance'), null, index)
|
|
190
|
+
.concat(store.statementsMatching(null, ns.solid('instanceContainer'), null, index))
|
|
191
|
+
.map(st => st.subject)
|
|
192
|
+
const relevant = theClass ? registrations.filter(reg => store.any(reg, ns.solid('forClass'), null, index).sameTerm(theClass))
|
|
193
|
+
: registrations
|
|
194
|
+
const directInstances = relevant.map(reg => store.each(reg as NamedNode, ns.solid('instance'), null, index)).flat()
|
|
195
|
+
let instances = uniqueNodes(directInstances)
|
|
196
|
+
|
|
197
|
+
const instanceContainers = relevant.map(
|
|
198
|
+
reg => store.each(reg as NamedNode, ns.solid('instanceContainer'), null, index)).flat()
|
|
199
|
+
|
|
200
|
+
// instanceContainers may be deprocatable if no one has used them
|
|
201
|
+
const containers = uniqueNodes(instanceContainers)
|
|
202
|
+
if (containers.length > 0) { console.log('@@ getScopedAppsFromIndex containers ', containers)}
|
|
203
|
+
for (let i = 0; i < containers.length; i++) {
|
|
204
|
+
const cont = containers[i]
|
|
205
|
+
await store.fetcher.load(cont)
|
|
206
|
+
const contents = store.each(cont, ns.ldp('contains'), null, cont)
|
|
207
|
+
instances = instances.concat(contents)
|
|
208
|
+
}
|
|
209
|
+
return instances.map(instance => { return {instance, scope}})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export async function getScopedAppInstances (store:LiveStore, klass: NamedNode, user: NamedNode):Promise<ScopedApp[]> {
|
|
213
|
+
const scopes = await loadAllTypeIndexes(store, user)
|
|
214
|
+
let scopedApps = []
|
|
215
|
+
for (const scope of scopes) {
|
|
216
|
+
const scopedApps0 = await getScopedAppsFromIndex(store, scope, klass) as any
|
|
217
|
+
scopedApps = scopedApps.concat(scopedApps0)
|
|
218
|
+
}
|
|
219
|
+
return scopedApps
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// This is the function signature which used to be in solid-ui/logic
|
|
223
|
+
// Recommended to use getScopedAppInstances instead as it provides more information.
|
|
224
|
+
//
|
|
225
|
+
export async function getAppInstances (store:LiveStore, klass: NamedNode): Promise<NamedNode[]> {
|
|
226
|
+
const user = authn.currentUser()
|
|
227
|
+
if (!user) throw new Error('getAppInstances: Must be logged in to find apps.')
|
|
228
|
+
const scopedAppInstances = await getScopedAppInstances(store, klass, user)
|
|
229
|
+
return scopedAppInstances.map(scoped => scoped.instance)
|
|
230
|
+
}
|
|
231
|
+
|
|
86
232
|
/*
|
|
87
|
-
|
|
233
|
+
* Register a new app in a type index
|
|
234
|
+
* used in chat in bookmark.js (solid-ui)
|
|
235
|
+
* Returns the registration object if successful else null
|
|
236
|
+
*/
|
|
237
|
+
export async function registerInstanceInTypeIndex (
|
|
238
|
+
store:LiveStore,
|
|
239
|
+
instance: NamedNode,
|
|
240
|
+
index: NamedNode,
|
|
241
|
+
theClass: NamedNode,
|
|
242
|
+
// agent: NamedNode
|
|
243
|
+
): Promise<NamedNode | null> {
|
|
244
|
+
const registration = newThing(index)
|
|
245
|
+
const ins = [
|
|
246
|
+
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
|
|
247
|
+
st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
248
|
+
st(registration, ns.solid('forClass'), theClass, index),
|
|
249
|
+
st(registration, ns.solid('instance'), instance, index)
|
|
250
|
+
]
|
|
251
|
+
try {
|
|
252
|
+
await store.updater.update([], ins)
|
|
253
|
+
} catch (err) {
|
|
254
|
+
const msg = `Unable to register ${instance} in index ${index}: ${err}`
|
|
255
|
+
console.warn(msg)
|
|
256
|
+
return null
|
|
257
|
+
}
|
|
258
|
+
return registration
|
|
259
|
+
}
|
|
88
260
|
|
|
261
|
+
export async function deleteTypeIndexRegistration (store: LiveStore, item) {
|
|
262
|
+
const reg = store.the(null, ns.solid('instance'), item.instance, item.scope.index) as NamedNode
|
|
263
|
+
if (!reg) throw new Error(`deleteTypeIndexRegistration: No registration found for ${item.instance}`)
|
|
264
|
+
const statements = store.statementsMatching(reg, null, null, item.scope.index)
|
|
265
|
+
await store.updater.update(statements, [])
|
|
89
266
|
}
|
|
90
|
-
|
|
267
|
+
// ENDS
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { NamedNode } from "rdflib";
|
|
2
|
+
import { getArchiveUrl } from "../util/utils";
|
|
3
|
+
|
|
4
|
+
export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic) {
|
|
5
|
+
|
|
6
|
+
async function createInboxFor(peerWebId: string, nick: string) {
|
|
7
|
+
const myWebId: NamedNode = await profileLogic.loadMe();
|
|
8
|
+
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
|
|
9
|
+
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
|
|
10
|
+
await containerLogic.createContainer(ourInbox);
|
|
11
|
+
const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
|
|
12
|
+
await utilityLogic.setSinglePeerAccess({
|
|
13
|
+
ownerWebId: myWebId.value,
|
|
14
|
+
peerWebId,
|
|
15
|
+
accessToModes: 'acl:Append',
|
|
16
|
+
target: ourInbox
|
|
17
|
+
});
|
|
18
|
+
return ourInbox;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getNewMessages(
|
|
22
|
+
user?: NamedNode
|
|
23
|
+
): Promise<string[]> {
|
|
24
|
+
if (!user) {
|
|
25
|
+
user = await profileLogic.loadMe();
|
|
26
|
+
}
|
|
27
|
+
const inbox = await profileLogic.getMainInbox(user);
|
|
28
|
+
const urls = await containerLogic.getContainerMembers(inbox.value);
|
|
29
|
+
return urls.filter(url => !containerLogic.isContainer(url));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function markAsRead(url: string, date: Date) {
|
|
33
|
+
const downloaded = await store.fetcher._fetch(url);
|
|
34
|
+
if (downloaded.status !== 200) {
|
|
35
|
+
throw new Error(`Not OK! ${url}`);
|
|
36
|
+
}
|
|
37
|
+
const archiveUrl = getArchiveUrl(url, date);
|
|
38
|
+
const options = {
|
|
39
|
+
method: 'PUT',
|
|
40
|
+
body: await downloaded.text(),
|
|
41
|
+
headers: [
|
|
42
|
+
['Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream']
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
const uploaded = await store.fetcher._fetch(archiveUrl, options);
|
|
46
|
+
if (uploaded.status.toString()[0] === '2') {
|
|
47
|
+
await store.fetcher._fetch(url, {
|
|
48
|
+
method: 'DELETE'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
createInboxFor,
|
|
54
|
+
getNewMessages,
|
|
55
|
+
markAsRead
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,39 +1,92 @@
|
|
|
1
1
|
// Make these variables directly accessible as it is what you need most of the time
|
|
2
2
|
// This also makes these variable globaly accesible in mashlib
|
|
3
|
-
import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
-
const authn = solidLogicSingleton.authn
|
|
5
|
-
const authSession = solidLogicSingleton.authn.authSession
|
|
6
|
-
const store = solidLogicSingleton.store
|
|
3
|
+
//import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
+
//const authn = solidLogicSingleton.authn
|
|
5
|
+
//const authSession = solidLogicSingleton.authn.authSession
|
|
6
|
+
//const store = solidLogicSingleton.store
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export {
|
|
9
|
+
ACL_LINK
|
|
10
|
+
} from './acl/aclLogic'
|
|
10
11
|
|
|
11
12
|
export {
|
|
13
|
+
findAclDocUrl,
|
|
12
14
|
setACLUserPublic,
|
|
13
|
-
genACLText
|
|
14
|
-
} from './
|
|
15
|
+
genACLText,
|
|
16
|
+
} from './logic/solidLogicSingleton'
|
|
15
17
|
|
|
16
18
|
export {
|
|
17
19
|
ensureTypeIndexes,
|
|
18
20
|
loadTypeIndexes,
|
|
19
21
|
registerInTypeIndex,
|
|
20
|
-
loadIndex
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
loadIndex,
|
|
23
|
+
ensureOneTypeIndex,
|
|
24
|
+
putIndex,
|
|
25
|
+
makeIndexIfNecessary,
|
|
26
|
+
loadIndexes,
|
|
27
|
+
getTypeIndex,
|
|
28
|
+
getRegistrations,
|
|
29
|
+
//NEW function for discovery
|
|
26
30
|
loadTypeIndexesFor,
|
|
27
31
|
loadCommunityTypeIndexes,
|
|
28
|
-
loadAllTypeIndexes
|
|
29
|
-
|
|
32
|
+
loadAllTypeIndexes,
|
|
33
|
+
getScopedAppInstances,
|
|
34
|
+
getAppInstances,
|
|
35
|
+
suggestPublicTypeIndex,
|
|
36
|
+
suggestPrivateTypeIndex,
|
|
37
|
+
registerInstanceInTypeIndex,
|
|
38
|
+
deleteTypeIndexRegistration,
|
|
39
|
+
getScopedAppsFromIndex
|
|
40
|
+
} from './logic/solidLogicSingleton'
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
setAcl,
|
|
44
|
+
addToPrivateTypeIndex,
|
|
45
|
+
findChat,
|
|
46
|
+
createChatThing,
|
|
47
|
+
getChat,
|
|
48
|
+
sendInvite,
|
|
49
|
+
mintNew
|
|
50
|
+
} from './logic/solidLogicSingleton'
|
|
30
51
|
|
|
31
|
-
export { SolidLogic } from './logic/SolidLogic'
|
|
32
52
|
export { offlineTestID, appContext } from './authn/authUtil'
|
|
33
|
-
export {
|
|
53
|
+
export { createInboxFor, getNewMessages, markAsRead } from './logic/solidLogicSingleton'
|
|
54
|
+
export {
|
|
55
|
+
recursiveDelete,
|
|
56
|
+
setSinglePeerAccess,
|
|
57
|
+
createEmptyRdfDoc,
|
|
58
|
+
//NEW function for discovery
|
|
59
|
+
followOrCreateLink,
|
|
60
|
+
loadOrCreateIfNotExists,
|
|
61
|
+
} from './logic/solidLogicSingleton'
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
ensureLoadedPreferences,
|
|
65
|
+
loadMe,
|
|
66
|
+
getPodRoot,
|
|
67
|
+
getMainInbox,
|
|
68
|
+
findStorage,
|
|
69
|
+
//NEW content from discovery
|
|
70
|
+
loadPreferences,
|
|
71
|
+
loadProfile,
|
|
72
|
+
//NEW function for discovery
|
|
73
|
+
silencedLoadPreferences
|
|
74
|
+
} from './logic/solidLogicSingleton'
|
|
75
|
+
|
|
34
76
|
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
isContainer,
|
|
80
|
+
createContainer,
|
|
81
|
+
getContainerElements,
|
|
82
|
+
getContainerMembers
|
|
83
|
+
} from './logic/solidLogicSingleton'
|
|
84
|
+
|
|
85
|
+
export { authn, authSession, store } from './logic/solidLogicSingleton'
|
|
86
|
+
|
|
87
|
+
//export { SolidLogic } from './logic/SolidLogic'
|
|
35
88
|
export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
|
|
36
89
|
// solidLogicSingleton is exported entirely because it is used in solid-panes
|
|
37
|
-
export { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
38
|
-
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
|
|
39
|
-
|
|
90
|
+
//export { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
91
|
+
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
92
|
+
|
|
File without changes
|
package/src/logic/CustomError.ts
CHANGED
|
@@ -6,7 +6,7 @@ class CustomError extends Error {
|
|
|
6
6
|
this.name = new.target.name; // stack traces display correctly now
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
export class UnauthorizedError extends CustomError {}
|
|
11
11
|
|
|
12
12
|
export class CrossOriginForbiddenError extends CustomError {}
|
|
@@ -15,6 +15,10 @@ export class SameOriginForbiddenError extends CustomError {}
|
|
|
15
15
|
|
|
16
16
|
export class NotFoundError extends CustomError {}
|
|
17
17
|
|
|
18
|
+
export class NotEditableError extends CustomError { }
|
|
19
|
+
|
|
20
|
+
export class WebOperationError extends CustomError {}
|
|
21
|
+
|
|
18
22
|
export class FetchError extends CustomError {
|
|
19
23
|
status: number;
|
|
20
24
|
|