solid-logic 3.1.1-f0ed025 → 3.1.1-f480b7d
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 +105 -2
- package/dist/acl/aclLogic.d.ts +5 -0
- package/{lib → dist}/acl/aclLogic.d.ts.map +1 -1
- package/dist/acl/aclLogic.js +122 -0
- package/dist/acl/aclLogic.js.map +1 -0
- package/{lib → dist}/authSession/authSession.js +1 -1
- package/{lib → dist}/authSession/authSession.js.map +1 -1
- package/{lib → dist}/authn/SolidAuthnLogic.d.ts +3 -3
- package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/dist/authn/SolidAuthnLogic.js +147 -0
- package/dist/authn/SolidAuthnLogic.js.map +1 -0
- package/{lib → dist}/authn/authUtil.d.ts +1 -1
- package/{lib → dist}/authn/authUtil.js +12 -12
- package/dist/authn/authUtil.js.map +1 -0
- package/{lib → dist}/chat/chatLogic.d.ts +1 -1
- package/dist/chat/chatLogic.js +160 -0
- package/dist/chat/chatLogic.js.map +1 -0
- package/{lib → dist}/inbox/inboxLogic.d.ts +1 -1
- package/{lib → dist}/inbox/inboxLogic.d.ts.map +1 -1
- package/dist/inbox/inboxLogic.js +55 -0
- package/dist/inbox/inboxLogic.js.map +1 -0
- package/{lib → dist}/index.d.ts +1 -1
- package/{lib → dist}/index.d.ts.map +1 -1
- package/{lib → dist}/index.js +4 -4
- package/{lib → dist}/index.js.map +1 -1
- package/dist/issuer/issuerLogic.js +40 -0
- package/dist/issuer/issuerLogic.js.map +1 -0
- package/{lib → dist}/logic/CustomError.d.ts.map +1 -1
- package/dist/logic/CustomError.js +38 -0
- package/dist/logic/CustomError.js.map +1 -0
- package/dist/logic/solidLogic.d.ts +6 -0
- package/{lib → dist}/logic/solidLogic.d.ts.map +1 -1
- package/{lib → dist}/logic/solidLogic.js +32 -33
- package/dist/logic/solidLogic.js.map +1 -0
- package/dist/logic/solidLogicSingleton.js +54 -0
- package/dist/logic/solidLogicSingleton.js.map +1 -0
- package/{lib → dist}/profile/profileLogic.d.ts +1 -1
- package/dist/profile/profileLogic.js +165 -0
- package/dist/profile/profileLogic.js.map +1 -0
- package/dist/solid-logic.esm.external.js +12725 -0
- package/dist/solid-logic.esm.external.js.map +1 -0
- package/dist/solid-logic.esm.external.min.js +32 -0
- package/dist/solid-logic.esm.external.min.js.map +1 -0
- package/dist/solid-logic.js +12802 -0
- package/dist/solid-logic.js.map +1 -0
- package/dist/solid-logic.min.js +32 -0
- package/dist/solid-logic.min.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.js +222 -0
- package/dist/typeIndex/typeIndexLogic.js.map +1 -0
- package/{lib → dist}/types.d.ts +2 -2
- package/{lib → dist}/util/containerLogic.d.ts +1 -1
- package/{lib → dist}/util/containerLogic.d.ts.map +1 -1
- package/{src/util/containerLogic.ts → dist/util/containerLogic.js} +20 -25
- package/dist/util/containerLogic.js.map +1 -0
- package/dist/util/debug.d.ts.map +1 -0
- package/dist/util/debug.js +20 -0
- package/dist/util/debug.js.map +1 -0
- package/{lib → dist}/util/ns.js +2 -2
- package/{lib → dist}/util/ns.js.map +1 -1
- package/{lib → dist}/util/utilityLogic.d.ts +1 -1
- package/{lib → dist}/util/utilityLogic.d.ts.map +1 -1
- package/dist/util/utilityLogic.js +180 -0
- package/dist/util/utilityLogic.js.map +1 -0
- package/{lib → dist}/util/utils.d.ts +1 -1
- package/{lib → dist}/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +47 -0
- package/dist/util/utils.js.map +1 -0
- package/dist/versionInfo.js +33 -0
- package/dist/versionInfo.js.map +1 -0
- package/package.json +50 -22
- package/eslint.config.js +0 -29
- package/jest.config.js +0 -10
- package/lib/acl/aclLogic.d.ts +0 -5
- package/lib/acl/aclLogic.js +0 -168
- package/lib/acl/aclLogic.js.map +0 -1
- package/lib/authn/SolidAuthnLogic.js +0 -193
- package/lib/authn/SolidAuthnLogic.js.map +0 -1
- package/lib/authn/authUtil.js.map +0 -1
- package/lib/chat/chatLogic.js +0 -272
- package/lib/chat/chatLogic.js.map +0 -1
- package/lib/inbox/inboxLogic.js +0 -139
- package/lib/inbox/inboxLogic.js.map +0 -1
- package/lib/issuer/issuerLogic.js +0 -52
- package/lib/issuer/issuerLogic.js.map +0 -1
- package/lib/logic/CustomError.js +0 -89
- package/lib/logic/CustomError.js.map +0 -1
- package/lib/logic/solidLogic.d.ts +0 -6
- package/lib/logic/solidLogic.js.map +0 -1
- package/lib/logic/solidLogicSingleton.js +0 -94
- package/lib/logic/solidLogicSingleton.js.map +0 -1
- package/lib/profile/profileLogic.js +0 -259
- package/lib/profile/profileLogic.js.map +0 -1
- package/lib/typeIndex/typeIndexLogic.js +0 -399
- package/lib/typeIndex/typeIndexLogic.js.map +0 -1
- package/lib/util/containerLogic.js +0 -102
- package/lib/util/containerLogic.js.map +0 -1
- package/lib/util/debug.d.ts.map +0 -1
- package/lib/util/debug.js +0 -40
- package/lib/util/debug.js.map +0 -1
- package/lib/util/utilityLogic.js +0 -284
- package/lib/util/utilityLogic.js.map +0 -1
- package/lib/util/utils.js +0 -47
- package/lib/util/utils.js.map +0 -1
- package/src/acl/aclLogic.ts +0 -156
- package/src/authSession/authSession.ts +0 -7
- package/src/authn/SolidAuthnLogic.ts +0 -127
- 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 -22
- 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 -20
- package/src/util/ns.ts +0 -5
- package/src/util/utilityLogic.ts +0 -156
- package/src/util/utils.ts +0 -52
- package/test/aclLogic.test.ts +0 -24
- package/test/authUtil.test.ts +0 -23
- package/test/chatLogic.test.ts +0 -316
- package/test/container.test.ts +0 -58
- package/test/helpers/dataSetup.ts +0 -134
- package/test/helpers/setup.ts +0 -17
- package/test/inboxLogic.test.ts +0 -218
- package/test/logic.test.ts +0 -29
- package/test/profileLogic.test.ts +0 -246
- package/test/solidAuthLogic.test.ts +0 -49
- package/test/typeIndexLogic.test.ts +0 -255
- package/test/utilityLogic.test.ts +0 -179
- package/test/utils.test.ts +0 -32
- package/tsconfig.json +0 -75
- /package/{lib → dist}/authSession/authSession.d.ts +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts.map +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts.map +0 -0
- /package/{lib → dist}/chat/chatLogic.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/solidLogicSingleton.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogicSingleton.d.ts.map +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.map +0 -0
- /package/{lib → dist}/types.js +0 -0
- /package/{lib → dist}/types.js.map +0 -0
- /package/{lib → dist}/util/debug.d.ts +0 -0
- /package/{lib → dist}/util/ns.d.ts +0 -0
- /package/{lib → dist}/util/ns.d.ts.map +0 -0
|
@@ -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,20 +0,0 @@
|
|
|
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
DELETED
package/src/util/utilityLogic.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { NamedNode, st, sym } from "rdflib";
|
|
2
|
-
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from "../logic/CustomError";
|
|
3
|
-
import * as debug from '../util/debug';
|
|
4
|
-
import { differentOrigin } from "./utils";
|
|
5
|
-
|
|
6
|
-
export function createUtilityLogic(store, aclLogic, containerLogic) {
|
|
7
|
-
|
|
8
|
-
async function recursiveDelete(containerNode: NamedNode) {
|
|
9
|
-
try {
|
|
10
|
-
if (containerLogic.isContainer(containerNode)) {
|
|
11
|
-
const aclDocUrl = await aclLogic.findAclDocUrl(containerNode)
|
|
12
|
-
await store.fetcher._fetch(aclDocUrl, { method: "DELETE" });
|
|
13
|
-
const containerMembers = await containerLogic.getContainerMembers(containerNode);
|
|
14
|
-
await Promise.all(
|
|
15
|
-
containerMembers.map((url) => recursiveDelete(url))
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
const nodeToStringHere = containerNode.value;
|
|
19
|
-
return store.fetcher._fetch(nodeToStringHere, { method: "DELETE" })
|
|
20
|
-
} catch (e) {
|
|
21
|
-
debug.log(`Please manually remove ${containerNode.value} from your system.`, e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Create a resource if it really does not exist
|
|
27
|
-
* Be absolutely sure something does not exist before creating a new empty file
|
|
28
|
-
* as otherwise existing could be deleted.
|
|
29
|
-
* @param doc {NamedNode} - The resource
|
|
30
|
-
*/
|
|
31
|
-
async function loadOrCreateIfNotExists(doc: NamedNode) {
|
|
32
|
-
let response
|
|
33
|
-
try {
|
|
34
|
-
response = await store.fetcher.load(doc)
|
|
35
|
-
} catch (err) {
|
|
36
|
-
if (err.response.status === 404) {
|
|
37
|
-
try {
|
|
38
|
-
await store.fetcher.webOperation('PUT', doc, { data: '', contentType: 'text/turtle' })
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err
|
|
41
|
-
throw new WebOperationError(msg)
|
|
42
|
-
}
|
|
43
|
-
await store.fetcher.load(doc)
|
|
44
|
-
} else {
|
|
45
|
-
if (err.response.status === 401) {
|
|
46
|
-
throw new UnauthorizedError();
|
|
47
|
-
}
|
|
48
|
-
if (err.response.status === 403) {
|
|
49
|
-
if (differentOrigin(doc)) {
|
|
50
|
-
throw new CrossOriginForbiddenError();
|
|
51
|
-
}
|
|
52
|
-
throw new SameOriginForbiddenError();
|
|
53
|
-
}
|
|
54
|
-
const msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err
|
|
55
|
-
throw new FetchError(err.status, err.message + msg)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return response
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/* Follow link from this doc to another thing, or else make a new link
|
|
62
|
-
**
|
|
63
|
-
** @returns existing object, or creates it if non existent
|
|
64
|
-
*/
|
|
65
|
-
async function followOrCreateLink(subject: NamedNode, predicate: NamedNode,
|
|
66
|
-
object: NamedNode, doc: NamedNode
|
|
67
|
-
): Promise<NamedNode | null> {
|
|
68
|
-
await store.fetcher.load(doc)
|
|
69
|
-
const result = store.any(subject, predicate, null, doc)
|
|
70
|
-
|
|
71
|
-
if (result) return result as NamedNode
|
|
72
|
-
if (!store.updater.editable(doc)) {
|
|
73
|
-
const msg = `followOrCreateLink: cannot edit ${doc.value}`
|
|
74
|
-
debug.warn(msg)
|
|
75
|
-
throw new NotEditableError(msg)
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
await store.updater.update([], [st(subject, predicate, object, doc)])
|
|
79
|
-
} catch (err) {
|
|
80
|
-
const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`
|
|
81
|
-
debug.warn(msg)
|
|
82
|
-
throw new WebOperationError(err)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await loadOrCreateIfNotExists(object)
|
|
87
|
-
// store.fetcher.webOperation('PUT', object, { data: '', contentType: 'text/turtle'})
|
|
88
|
-
} catch (err) {
|
|
89
|
-
debug.warn(`followOrCreateLink: Error loading or saving new linked document: ${object}: ${err}`)
|
|
90
|
-
throw err;
|
|
91
|
-
}
|
|
92
|
-
return object
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Copied from https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5
|
|
96
|
-
async function setSinglePeerAccess(options: {
|
|
97
|
-
ownerWebId: string,
|
|
98
|
-
peerWebId: string,
|
|
99
|
-
accessToModes?: string,
|
|
100
|
-
defaultModes?: string,
|
|
101
|
-
target: string
|
|
102
|
-
}) {
|
|
103
|
-
let str = [
|
|
104
|
-
'@prefix acl: <http://www.w3.org/ns/auth/acl#>.',
|
|
105
|
-
'',
|
|
106
|
-
`<#alice> a acl:Authorization;\n acl:agent <${options.ownerWebId}>;`,
|
|
107
|
-
` acl:accessTo <${options.target}>;`,
|
|
108
|
-
` acl:default <${options.target}>;`,
|
|
109
|
-
' acl:mode acl:Read, acl:Write, acl:Control.',
|
|
110
|
-
''
|
|
111
|
-
].join('\n')
|
|
112
|
-
if (options.accessToModes) {
|
|
113
|
-
str += [
|
|
114
|
-
'<#bobAccessTo> a acl:Authorization;',
|
|
115
|
-
` acl:agent <${options.peerWebId}>;`,
|
|
116
|
-
` acl:accessTo <${options.target}>;`,
|
|
117
|
-
` acl:mode ${options.accessToModes}.`,
|
|
118
|
-
''
|
|
119
|
-
].join('\n')
|
|
120
|
-
}
|
|
121
|
-
if (options.defaultModes) {
|
|
122
|
-
str += [
|
|
123
|
-
'<#bobDefault> a acl:Authorization;',
|
|
124
|
-
` acl:agent <${options.peerWebId}>;`,
|
|
125
|
-
` acl:default <${options.target}>;`,
|
|
126
|
-
` acl:mode ${options.defaultModes}.`,
|
|
127
|
-
''
|
|
128
|
-
].join('\n')
|
|
129
|
-
}
|
|
130
|
-
const aclDocUrl = await aclLogic.findAclDocUrl(sym(options.target))
|
|
131
|
-
return store.fetcher._fetch(aclDocUrl, {
|
|
132
|
-
method: 'PUT',
|
|
133
|
-
body: str,
|
|
134
|
-
headers: [
|
|
135
|
-
['Content-Type', 'text/turtle']
|
|
136
|
-
]
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function createEmptyRdfDoc(doc: NamedNode, comment: string) {
|
|
141
|
-
await store.fetcher.webOperation("PUT", doc.uri, {
|
|
142
|
-
data: `# ${new Date()} ${comment}
|
|
143
|
-
`,
|
|
144
|
-
contentType: "text/turtle",
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
recursiveDelete,
|
|
150
|
-
setSinglePeerAccess,
|
|
151
|
-
createEmptyRdfDoc,
|
|
152
|
-
followOrCreateLink,
|
|
153
|
-
loadOrCreateIfNotExists
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
package/src/util/utils.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { NamedNode, sym } from "rdflib";
|
|
2
|
-
|
|
3
|
-
export function newThing(doc: NamedNode): NamedNode {
|
|
4
|
-
return sym(doc.uri + "#" + "id" + ("" + Date.now()));
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function uniqueNodes (arr: NamedNode[]): NamedNode[] {
|
|
8
|
-
const uris = arr.map(x => x.uri)
|
|
9
|
-
const set = new Set(uris)
|
|
10
|
-
const uris2 = Array.from(set)
|
|
11
|
-
const arr2 = uris2.map(u => new NamedNode(u))
|
|
12
|
-
return arr2 // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getArchiveUrl(baseUrl: string, date: Date) {
|
|
16
|
-
const year = date.getUTCFullYear();
|
|
17
|
-
const month = ('0' + (date.getUTCMonth()+1)).slice(-2);
|
|
18
|
-
const day = ('0' + (date.getUTCDate())).slice(-2);
|
|
19
|
-
const parts = baseUrl.split('/');
|
|
20
|
-
const filename = parts[parts.length -1 ];
|
|
21
|
-
return new URL(`./archive/${year}/${month}/${day}/${filename}`, baseUrl).toString();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function differentOrigin(doc): boolean {
|
|
25
|
-
if (!doc) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return (
|
|
29
|
-
`${window.location.origin}/` !== new URL(doc.value).origin
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function suggestPreferencesFile (me:NamedNode) {
|
|
34
|
-
const stripped = me.uri.replace('/profile/', '/').replace('/public/', '/')
|
|
35
|
-
// const stripped = me.uri.replace(\/[p|P]rofile/\g, '/').replace(\/[p|P]ublic/\g, '/')
|
|
36
|
-
const folderURI = stripped.split('/').slice(0,-1).join('/') + '/Settings/'
|
|
37
|
-
const fileURI = folderURI + 'Preferences.ttl'
|
|
38
|
-
return sym(fileURI)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function determineChatContainer(
|
|
42
|
-
invitee: NamedNode,
|
|
43
|
-
podRoot: NamedNode
|
|
44
|
-
): NamedNode {
|
|
45
|
-
// Create chat
|
|
46
|
-
// See https://gitter.im/solid/chat-app?at=5f3c800f855be416a23ae74a
|
|
47
|
-
const chatContainerStr = new URL(
|
|
48
|
-
`IndividualChats/${new URL(invitee.value).host}/`,
|
|
49
|
-
podRoot.value
|
|
50
|
-
).toString();
|
|
51
|
-
return new NamedNode(chatContainerStr);
|
|
52
|
-
}
|
package/test/aclLogic.test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Fetcher, Store, sym, UpdateManager } from 'rdflib';
|
|
2
|
-
import { createAclLogic } from '../src/acl/aclLogic';
|
|
3
|
-
|
|
4
|
-
describe('setACLUserPublic', () => {
|
|
5
|
-
let aclLogic
|
|
6
|
-
let store
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
const options = { fetch: fetch };
|
|
9
|
-
store = new Store()
|
|
10
|
-
store.fetcher = new Fetcher(store, options);
|
|
11
|
-
store.updater = new UpdateManager(store);
|
|
12
|
-
aclLogic = createAclLogic(store)
|
|
13
|
-
})
|
|
14
|
-
it('exists', () => {
|
|
15
|
-
expect(aclLogic.setACLUserPublic).toBeInstanceOf(Function)
|
|
16
|
-
})
|
|
17
|
-
it.skip('runs', async () => {
|
|
18
|
-
expect(await aclLogic.setACLUserPublic(
|
|
19
|
-
'https://test.test#',
|
|
20
|
-
sym('https://test.test#'),
|
|
21
|
-
{}
|
|
22
|
-
)).toEqual({})
|
|
23
|
-
})
|
|
24
|
-
})
|
package/test/authUtil.test.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
import * as authUtil from '../src/authn/authUtil'
|
|
6
|
-
|
|
7
|
-
describe('offlineTestID', () => {
|
|
8
|
-
it('exists', () => {
|
|
9
|
-
expect(authUtil.offlineTestID).toBeInstanceOf(Function)
|
|
10
|
-
})
|
|
11
|
-
it('runs', () => {
|
|
12
|
-
expect(authUtil.offlineTestID()).toEqual(null)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe('appContext', () => {
|
|
17
|
-
it('exists', () => {
|
|
18
|
-
expect(authUtil.appContext).toBeInstanceOf(Function)
|
|
19
|
-
})
|
|
20
|
-
it('runs', () => {
|
|
21
|
-
expect(authUtil.appContext()).toEqual({"viewingNoAuthPage": false,})
|
|
22
|
-
})
|
|
23
|
-
})
|