solid-logic 1.3.12 → 1.3.13-057429fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +0 -0
- package/.eslintrc.js +0 -0
- package/.github/workflows/ci.yml +39 -5
- package/.github/workflows/release.yml +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/jest.config.js +4 -1
- package/lib/acl/aclLogic.d.ts +32 -0
- package/lib/acl/aclLogic.d.ts.map +1 -0
- package/lib/acl/aclLogic.js +132 -0
- package/lib/acl/aclLogic.js.map +1 -0
- package/lib/authSession/authSession.d.ts +3 -0
- package/lib/authSession/authSession.d.ts.map +1 -0
- package/lib/authSession/authSession.js +8 -0
- package/lib/authSession/authSession.js.map +1 -0
- package/lib/authn/SolidAuthnLogic.d.ts +26 -5
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +167 -5
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/authn/authUtil.d.ts +17 -0
- package/lib/authn/authUtil.d.ts.map +1 -0
- package/lib/authn/authUtil.js +88 -0
- package/lib/authn/authUtil.js.map +1 -0
- package/lib/chat/ChatLogic.d.ts +2 -2
- package/lib/chat/ChatLogic.d.ts.map +1 -1
- package/lib/chat/ChatLogic.js +38 -33
- package/lib/chat/ChatLogic.js.map +1 -1
- package/lib/chat/determineChatContainer.d.ts +0 -0
- package/lib/chat/determineChatContainer.d.ts.map +0 -0
- package/lib/chat/determineChatContainer.js +0 -0
- package/lib/chat/determineChatContainer.js.map +0 -0
- package/lib/inbox/InboxLogic.d.ts +2 -2
- package/lib/inbox/InboxLogic.d.ts.map +1 -1
- package/lib/inbox/InboxLogic.js +14 -13
- package/lib/inbox/InboxLogic.js.map +1 -1
- package/lib/index.d.ts +14 -72
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +39 -387
- package/lib/index.js.map +1 -1
- package/lib/issuer/issuerLogic.d.ts +8 -0
- package/lib/issuer/issuerLogic.d.ts.map +1 -0
- package/lib/issuer/issuerLogic.js +53 -0
- package/lib/issuer/issuerLogic.js.map +1 -0
- package/lib/logic/CustomError.d.ts +17 -0
- package/lib/logic/CustomError.d.ts.map +1 -0
- package/lib/logic/CustomError.js +73 -0
- package/lib/logic/CustomError.js.map +1 -0
- package/lib/{index-alain.d.ts → logic/SolidLogic.d.ts} +7 -33
- package/lib/logic/SolidLogic.d.ts.map +1 -0
- package/lib/{index-alain.js → logic/SolidLogic.js} +17 -99
- package/lib/logic/SolidLogic.js.map +1 -0
- package/lib/logic/solidLogicSingleton.d.ts +4 -0
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -0
- package/lib/logic/solidLogicSingleton.js +77 -0
- package/lib/logic/solidLogicSingleton.js.map +1 -0
- package/lib/profile/ProfileLogic.d.ts +2 -3
- package/lib/profile/ProfileLogic.d.ts.map +1 -1
- package/lib/profile/ProfileLogic.js +10 -8
- package/lib/profile/ProfileLogic.js.map +1 -1
- package/lib/typeIndex/typeIndexLogic.d.ts +22 -0
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -0
- package/lib/typeIndex/typeIndexLogic.js +302 -0
- package/lib/typeIndex/typeIndexLogic.js.map +1 -0
- package/lib/types.d.ts +31 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/{authn/index.js → types.js} +1 -1
- package/lib/types.js.map +1 -0
- package/lib/util/UtilityLogic.d.ts +2 -2
- package/lib/util/UtilityLogic.d.ts.map +1 -1
- package/lib/util/UtilityLogic.js +10 -8
- package/lib/util/UtilityLogic.js.map +1 -1
- package/lib/{debug.d.ts → util/debug.d.ts} +0 -0
- package/lib/util/debug.d.ts.map +1 -0
- package/lib/{debug.js → util/debug.js} +0 -0
- package/lib/util/debug.js.map +1 -0
- package/lib/{uri.d.ts → util/uri.d.ts} +0 -0
- package/lib/util/uri.d.ts.map +1 -0
- package/lib/{uri.js → util/uri.js} +0 -0
- package/lib/util/uri.js.map +1 -0
- package/package.json +7 -5
- package/renovate.json +0 -0
- package/src/acl/aclLogic.ts +137 -0
- package/src/authSession/authSession.ts +13 -0
- package/src/authn/SolidAuthnLogic.ts +114 -9
- package/src/authn/authUtil.ts +67 -0
- package/src/chat/ChatLogic.ts +13 -13
- package/src/chat/determineChatContainer.ts +0 -0
- package/src/inbox/InboxLogic.ts +3 -15
- package/src/index.ts +29 -307
- package/src/issuer/issuerLogic.ts +40 -0
- package/src/logic/CustomError.ts +25 -0
- package/src/logic/SolidLogic.ts +264 -0
- package/src/logic/solidLogicSingleton.ts +18 -0
- package/src/profile/ProfileLogic.ts +4 -5
- package/src/typeIndex/typeIndexLogic.ts +170 -0
- package/src/types.ts +43 -0
- package/src/util/UtilityLogic.ts +4 -16
- package/src/{debug.ts → util/debug.ts} +0 -0
- package/src/{uri.ts → util/uri.ts} +0 -0
- package/test/aclLogic.test.ts +15 -0
- package/test/authUtil.test.ts +23 -0
- package/{src/chat/integration.test.ts → test/chatLogic.test.ts} +4 -5
- package/test/helpers/setup.ts +13 -0
- package/{src/inbox/unit.test.ts → test/inboxLogic.test.ts} +5 -6
- package/test/logic.test.ts +28 -0
- package/test/solidAuthLogic.test.ts +49 -0
- package/test/typeIndexLogic.test.ts +26 -0
- package/{src/util/unit.test.ts → test/utilityLogic.test.ts} +3 -4
- package/tsconfig.json +0 -0
- package/jest.setup.ts +0 -2
- package/lib/authn/NoAuthnLogic.d.ts +0 -9
- package/lib/authn/NoAuthnLogic.d.ts.map +0 -1
- package/lib/authn/NoAuthnLogic.js +0 -17
- package/lib/authn/NoAuthnLogic.js.map +0 -1
- package/lib/authn/index.d.ts +0 -5
- package/lib/authn/index.d.ts.map +0 -1
- package/lib/authn/index.js.map +0 -1
- package/lib/chat/integration.test.d.ts +0 -2
- package/lib/chat/integration.test.d.ts.map +0 -1
- package/lib/chat/integration.test.js +0 -318
- package/lib/chat/integration.test.js.map +0 -1
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js.map +0 -1
- package/lib/inbox/unit.test.d.ts +0 -2
- package/lib/inbox/unit.test.d.ts.map +0 -1
- package/lib/inbox/unit.test.js +0 -264
- package/lib/inbox/unit.test.js.map +0 -1
- package/lib/index-alain.d.ts.map +0 -1
- package/lib/index-alain.js.map +0 -1
- package/lib/uri.d.ts.map +0 -1
- package/lib/uri.js.map +0 -1
- package/lib/util/UtilityLogic-alain.d.ts +0 -32
- package/lib/util/UtilityLogic-alain.d.ts.map +0 -1
- package/lib/util/UtilityLogic-alain.js +0 -248
- package/lib/util/UtilityLogic-alain.js.map +0 -1
- package/lib/util/unit.test.d.ts +0 -2
- package/lib/util/unit.test.d.ts.map +0 -1
- package/lib/util/unit.test.js +0 -200
- package/lib/util/unit.test.js.map +0 -1
- package/src/authn/NoAuthnLogic.ts +0 -16
- package/src/authn/index.ts +0 -5
- package/src/index-alain.txt +0 -316
- package/src/util/UtilityLogic-alain.txt +0 -181
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const DEFAULT_ISSUERS = [
|
|
2
|
+
{
|
|
3
|
+
name: 'Solid Community',
|
|
4
|
+
uri: 'https://solidcommunity.net'
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
name: 'Solid Web',
|
|
8
|
+
uri: 'https://solidweb.org'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'Inrupt.net',
|
|
12
|
+
uri: 'https://inrupt.net'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'pod.Inrupt.com',
|
|
16
|
+
uri: 'https://broker.pod.inrupt.com'
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns - A list of suggested OIDC issuers
|
|
22
|
+
*/
|
|
23
|
+
export function getSuggestedIssuers (): { name: string, uri: string }[] {
|
|
24
|
+
// Suggest a default list of OIDC issuers
|
|
25
|
+
const issuers = [...DEFAULT_ISSUERS]
|
|
26
|
+
|
|
27
|
+
// Suggest the current host if not already included
|
|
28
|
+
const { host, origin } = new URL(location.href)
|
|
29
|
+
const hosts = issuers.map(({ uri }) => new URL(uri).host)
|
|
30
|
+
if (!hosts.includes(host) && !hosts.some(existing => isSubdomainOf(host, existing))) {
|
|
31
|
+
issuers.unshift({ name: host, uri: origin })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return issuers
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isSubdomainOf (subdomain: string, domain: string): boolean {
|
|
38
|
+
const dot = subdomain.length - domain.length - 1
|
|
39
|
+
return dot > 0 && subdomain[dot] === '.' && subdomain.endsWith(domain)
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class CustomError extends Error {
|
|
2
|
+
constructor(message?: string) {
|
|
3
|
+
super(message);
|
|
4
|
+
// see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
|
|
6
|
+
this.name = new.target.name; // stack traces display correctly now
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class UnauthorizedError extends CustomError {}
|
|
11
|
+
|
|
12
|
+
export class CrossOriginForbiddenError extends CustomError {}
|
|
13
|
+
|
|
14
|
+
export class SameOriginForbiddenError extends CustomError {}
|
|
15
|
+
|
|
16
|
+
export class NotFoundError extends CustomError {}
|
|
17
|
+
|
|
18
|
+
export class FetchError extends CustomError {
|
|
19
|
+
status: number;
|
|
20
|
+
|
|
21
|
+
constructor(status: number, message?: string) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.status = status;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Session } from "@inrupt/solid-client-authn-browser";
|
|
2
|
+
import * as rdf from "rdflib";
|
|
3
|
+
import { NamedNode, Statement, LiveStore } from "rdflib";
|
|
4
|
+
import solidNamespace from "solid-namespace";
|
|
5
|
+
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic";
|
|
6
|
+
import { ChatLogic } from "../chat/ChatLogic";
|
|
7
|
+
import { ProfileLogic } from "../profile/ProfileLogic";
|
|
8
|
+
import { AuthnLogic, SolidNamespace } from "../types";
|
|
9
|
+
import * as debug from "../util/debug";
|
|
10
|
+
import { UtilityLogic } from "../util/UtilityLogic";
|
|
11
|
+
import { CrossOriginForbiddenError, FetchError, NotFoundError, SameOriginForbiddenError, UnauthorizedError } from "./CustomError";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const ns: SolidNamespace = solidNamespace(rdf);
|
|
15
|
+
|
|
16
|
+
export class SolidLogic {
|
|
17
|
+
cache: {
|
|
18
|
+
profileDocument: {
|
|
19
|
+
[WebID: string]: NamedNode;
|
|
20
|
+
};
|
|
21
|
+
preferencesFile: {
|
|
22
|
+
[WebID: string]: NamedNode;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
store: LiveStore;
|
|
27
|
+
me: string | undefined;
|
|
28
|
+
fetcher: { fetch: (url: string, options?: any) => any };
|
|
29
|
+
|
|
30
|
+
chat: ChatLogic;
|
|
31
|
+
profile: ProfileLogic;
|
|
32
|
+
authn: AuthnLogic;
|
|
33
|
+
util: UtilityLogic;
|
|
34
|
+
|
|
35
|
+
constructor(fetcher: { fetch: (url: any, requestInit: any) => any }, session: Session) {
|
|
36
|
+
this.store = rdf.graph() as LiveStore; // Make a Quad store
|
|
37
|
+
rdf.fetcher(this.store, fetcher); // Attach a web I/O module, store.fetcher
|
|
38
|
+
this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
|
|
39
|
+
this.cache = {
|
|
40
|
+
profileDocument: {},
|
|
41
|
+
preferencesFile: {},
|
|
42
|
+
};
|
|
43
|
+
this.fetcher = fetcher;
|
|
44
|
+
this.authn = new SolidAuthnLogic(session);
|
|
45
|
+
debug.log('SolidAuthnLogic initialized')
|
|
46
|
+
this.profile = new ProfileLogic(this.store, ns, this.authn);
|
|
47
|
+
this.chat = new ChatLogic(this.store, ns, this.profile);
|
|
48
|
+
this.util = new UtilityLogic(this.store, ns, this.fetcher);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
findAclDocUrl(url: string) {
|
|
52
|
+
return this.util.findAclDocUrl(url);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
loadDoc(doc: NamedNode): Promise<void> {
|
|
56
|
+
return this.util.loadDoc(doc);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async loadProfile(me: NamedNode): Promise<NamedNode> {
|
|
60
|
+
// console.log('loadProfile', me)
|
|
61
|
+
if (this.cache.profileDocument[me.value]) {
|
|
62
|
+
return this.cache.profileDocument[me.value];
|
|
63
|
+
}
|
|
64
|
+
let profileDocument;
|
|
65
|
+
try {
|
|
66
|
+
profileDocument = me.doc();
|
|
67
|
+
await this.loadDoc(profileDocument);
|
|
68
|
+
return profileDocument;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
const message = `Logged in but cannot load profile ${profileDocument} : ${err}`;
|
|
71
|
+
throw new Error(message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async loadPreferences(me: NamedNode): Promise<NamedNode> {
|
|
76
|
+
// console.log('loadPreferences', me)
|
|
77
|
+
if (this.cache.preferencesFile[me.value]) {
|
|
78
|
+
return this.cache.preferencesFile[me.value];
|
|
79
|
+
}
|
|
80
|
+
const preferencesFile = this.store.any(me, ns.space("preferencesFile"));
|
|
81
|
+
|
|
82
|
+
// console.log('this.store.any()', this.store.any())
|
|
83
|
+
/**
|
|
84
|
+
* Are we working cross-origin?
|
|
85
|
+
* Returns True if we are in a webapp at an origin, and the file origin is different
|
|
86
|
+
*/
|
|
87
|
+
function differentOrigin(): boolean {
|
|
88
|
+
if (!preferencesFile) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return (
|
|
92
|
+
`${window.location.origin}/` !== new URL(preferencesFile.value).origin
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!preferencesFile) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Can't find a preference file pointer in profile ${me.doc()}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!this.store.fetcher) {
|
|
103
|
+
throw new Error("Cannot load doc, have no fetcher");
|
|
104
|
+
}
|
|
105
|
+
// //// Load preference file
|
|
106
|
+
try {
|
|
107
|
+
await this.store.fetcher.load(preferencesFile as NamedNode, {
|
|
108
|
+
withCredentials: true,
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
// Really important to look at why
|
|
112
|
+
const status = err.status;
|
|
113
|
+
debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
|
|
114
|
+
if (status === 401) {
|
|
115
|
+
throw new UnauthorizedError();
|
|
116
|
+
}
|
|
117
|
+
if (status === 403) {
|
|
118
|
+
if (differentOrigin()) {
|
|
119
|
+
throw new CrossOriginForbiddenError();
|
|
120
|
+
}
|
|
121
|
+
throw new SameOriginForbiddenError();
|
|
122
|
+
}
|
|
123
|
+
if (status === 404) {
|
|
124
|
+
throw new NotFoundError(preferencesFile.value);
|
|
125
|
+
}
|
|
126
|
+
throw new FetchError(err.status, err.message);
|
|
127
|
+
}
|
|
128
|
+
return preferencesFile as NamedNode;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getTypeIndex(
|
|
132
|
+
me: NamedNode | string,
|
|
133
|
+
preferencesFile: NamedNode | string,
|
|
134
|
+
isPublic: boolean
|
|
135
|
+
): NamedNode[] {
|
|
136
|
+
// console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
|
|
137
|
+
return this.store.each(
|
|
138
|
+
me as NamedNode,
|
|
139
|
+
isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
|
|
140
|
+
undefined,
|
|
141
|
+
preferencesFile as NamedNode
|
|
142
|
+
) as NamedNode[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getRegistrations(instance, theClass) {
|
|
146
|
+
return this.store
|
|
147
|
+
.each(undefined, ns.solid("instance"), instance)
|
|
148
|
+
.filter((r) => {
|
|
149
|
+
return this.store.holds(r, ns.solid("forClass"), theClass);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
load(doc: NamedNode | NamedNode[] | string) {
|
|
154
|
+
if (!this.store.fetcher) {
|
|
155
|
+
throw new Error("Cannot load doc(s), have no fetcher");
|
|
156
|
+
}
|
|
157
|
+
return this.store.fetcher.load(doc);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async loadIndexes(
|
|
161
|
+
me: NamedNode | string,
|
|
162
|
+
publicProfile: NamedNode | string | null,
|
|
163
|
+
preferencesFile: NamedNode | string | null,
|
|
164
|
+
onWarning = async (_err: Error) => {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
): Promise<{
|
|
168
|
+
private: any;
|
|
169
|
+
public: any;
|
|
170
|
+
}> {
|
|
171
|
+
let privateIndexes: any[] = [];
|
|
172
|
+
let publicIndexes: any[] = [];
|
|
173
|
+
if (publicProfile) {
|
|
174
|
+
publicIndexes = this.getTypeIndex(me, publicProfile, true);
|
|
175
|
+
try {
|
|
176
|
+
await this.load(publicIndexes as NamedNode[]);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (preferencesFile) {
|
|
182
|
+
privateIndexes = this.getTypeIndex(me, preferencesFile, false);
|
|
183
|
+
// console.log({ privateIndexes })
|
|
184
|
+
if (privateIndexes.length === 0) {
|
|
185
|
+
await onWarning(
|
|
186
|
+
new Error(
|
|
187
|
+
`Your preference file ${preferencesFile} does not point to a private type index.`
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
} else {
|
|
191
|
+
try {
|
|
192
|
+
await this.load(privateIndexes);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
onWarning(
|
|
195
|
+
new Error(`loadIndex: loading private type index(es) ${err}`)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// } else {
|
|
200
|
+
// debug.log(
|
|
201
|
+
// 'We know your preference file is not available, so we are not bothering with private type indexes.'
|
|
202
|
+
// )
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
private: privateIndexes,
|
|
207
|
+
public: publicIndexes,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async createEmptyRdfDoc(doc: NamedNode, comment: string) {
|
|
212
|
+
if (!this.store.fetcher) {
|
|
213
|
+
throw new Error("Cannot create empty rdf doc, have no fetcher");
|
|
214
|
+
}
|
|
215
|
+
await this.store.fetcher.webOperation("PUT", doc.uri, {
|
|
216
|
+
data: `# ${new Date()} ${comment}
|
|
217
|
+
`,
|
|
218
|
+
contentType: "text/turtle",
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
223
|
+
updatePromise(
|
|
224
|
+
del: Array<Statement>,
|
|
225
|
+
ins: Array<Statement> = []
|
|
226
|
+
): Promise<void> {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
if (!this.store.updater) {
|
|
229
|
+
throw new Error("Cannot updatePromise, have no updater");
|
|
230
|
+
}
|
|
231
|
+
this.store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
232
|
+
if (!ok) {
|
|
233
|
+
reject(new Error(errorBody));
|
|
234
|
+
} else {
|
|
235
|
+
resolve();
|
|
236
|
+
}
|
|
237
|
+
}); // callback
|
|
238
|
+
}); // promise
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
isContainer(url: string) {
|
|
242
|
+
return this.util.isContainer(url);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getContainerElements(containerNode: NamedNode): NamedNode[] {
|
|
246
|
+
return this.util.getContainerElements(containerNode);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
getContainerMembers(containerUrl: string): Promise<string[]> {
|
|
250
|
+
return this.util.getContainerMembers(containerUrl);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async recursiveDelete(url: string) {
|
|
254
|
+
return this.util.recursiveDelete(url);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
clearStore() {
|
|
258
|
+
return this.util.clearStore();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async fetch(url: string, options?: any) {
|
|
262
|
+
return this.fetcher.fetch(url, options);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as debug from "../util/debug"
|
|
2
|
+
import { authSession } from "../authSession/authSession"
|
|
3
|
+
import { SolidLogic } from "./SolidLogic"
|
|
4
|
+
|
|
5
|
+
const fetcher = async (url, requestInit) => {
|
|
6
|
+
if (authSession.info.webId) {
|
|
7
|
+
return authSession.fetch(url, requestInit)
|
|
8
|
+
} else {
|
|
9
|
+
return window.fetch(url, requestInit)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//this const makes solidLogicSingleton global accessible in mashlib
|
|
14
|
+
const solidLogicSingleton = new SolidLogic({ fetch: fetcher }, authSession)
|
|
15
|
+
|
|
16
|
+
debug.log('Unique quadstore initialized.')
|
|
17
|
+
|
|
18
|
+
export { solidLogicSingleton }
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NamedNode } from "rdflib";
|
|
2
|
-
import { AuthnLogic } from "../
|
|
3
|
-
import { LiveStore, SolidNamespace } from "../index";
|
|
1
|
+
import { NamedNode, LiveStore } from "rdflib";
|
|
2
|
+
import { AuthnLogic, SolidNamespace } from "../types";
|
|
4
3
|
|
|
5
4
|
export class ProfileLogic {
|
|
6
5
|
store: LiveStore;
|
|
@@ -18,7 +17,7 @@ export class ProfileLogic {
|
|
|
18
17
|
if (me === null) {
|
|
19
18
|
throw new Error("Current user not found! Not logged in?");
|
|
20
19
|
}
|
|
21
|
-
await this.store.fetcher
|
|
20
|
+
await this.store.fetcher?.load(me.doc());
|
|
22
21
|
return me;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -31,7 +30,7 @@ export class ProfileLogic {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async getMainInbox(user: NamedNode): Promise<NamedNode> {
|
|
34
|
-
await this.store.fetcher
|
|
33
|
+
await this.store.fetcher?.load(user);
|
|
35
34
|
const mainInbox = this.store.any(user, this.ns.ldp("inbox"), undefined, user.doc());
|
|
36
35
|
if (!mainInbox) {
|
|
37
36
|
throw new Error("User main inbox not found!");
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { NamedNode, st, sym } from "rdflib"
|
|
2
|
+
import * as debug from '../util/debug'
|
|
3
|
+
import solidNamespace from 'solid-namespace'
|
|
4
|
+
import * as $rdf from 'rdflib'
|
|
5
|
+
import { newThing } from "../util/uri"
|
|
6
|
+
import { AuthenticationContext } from "../types"
|
|
7
|
+
import { solidLogicSingleton } from "../logic/solidLogicSingleton"
|
|
8
|
+
|
|
9
|
+
export const ns = solidNamespace($rdf)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves with the same context, outputting
|
|
13
|
+
* output: index.public, index.private
|
|
14
|
+
*
|
|
15
|
+
* @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
16
|
+
*/
|
|
17
|
+
export async function loadIndex (
|
|
18
|
+
context: AuthenticationContext,
|
|
19
|
+
isPublic: boolean
|
|
20
|
+
): Promise<AuthenticationContext> {
|
|
21
|
+
const indexes = await solidLogicSingleton.loadIndexes(
|
|
22
|
+
context.me as NamedNode,
|
|
23
|
+
(isPublic ? context.publicProfile || null : null),
|
|
24
|
+
(isPublic ? null : context.preferencesFile || null),
|
|
25
|
+
// async (err: Error) => widgets.complain(context, err.message)
|
|
26
|
+
async (err: Error) => debug.error(err.message) as undefined
|
|
27
|
+
)
|
|
28
|
+
context.index = context.index || {}
|
|
29
|
+
context.index.private = indexes.private || context.index.private
|
|
30
|
+
context.index.public = indexes.public || context.index.public
|
|
31
|
+
return context
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function loadTypeIndexes (context: AuthenticationContext) {
|
|
35
|
+
const indexes = await solidLogicSingleton.loadIndexes(
|
|
36
|
+
context.me as NamedNode,
|
|
37
|
+
context.publicProfile || null,
|
|
38
|
+
context.preferencesFile || null,
|
|
39
|
+
// async (err: Error) => widgets.complain(context, err.message)
|
|
40
|
+
async (err: Error) => debug.warn(err.message) as undefined
|
|
41
|
+
)
|
|
42
|
+
context.index = context.index || {}
|
|
43
|
+
context.index.private = indexes.private || context.index.private
|
|
44
|
+
context.index.public = indexes.public || context.index.public
|
|
45
|
+
return context
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolves with the same context, outputting
|
|
50
|
+
* @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
51
|
+
*/
|
|
52
|
+
export async function ensureTypeIndexes (context: AuthenticationContext): Promise<AuthenticationContext> {
|
|
53
|
+
await ensureOneTypeIndex(context, true)
|
|
54
|
+
await ensureOneTypeIndex(context, false)
|
|
55
|
+
return context
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Load or create ONE type index
|
|
60
|
+
* Find one or make one or fail
|
|
61
|
+
* Many reasons for failing including script not having permission etc
|
|
62
|
+
*
|
|
63
|
+
* Adds its output to the context
|
|
64
|
+
* @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
|
|
65
|
+
*/
|
|
66
|
+
async function ensureOneTypeIndex (context: AuthenticationContext, isPublic: boolean): Promise<AuthenticationContext | void> {
|
|
67
|
+
async function makeIndexIfNecessary (context, isPublic) {
|
|
68
|
+
const relevant = isPublic ? context.publicProfile : context.preferencesFile
|
|
69
|
+
const visibility = isPublic ? 'public' : 'private'
|
|
70
|
+
|
|
71
|
+
async function putIndex (newIndex) {
|
|
72
|
+
try {
|
|
73
|
+
await solidLogicSingleton.createEmptyRdfDoc(newIndex, 'Blank initial Type index')
|
|
74
|
+
return context
|
|
75
|
+
} catch (e) {
|
|
76
|
+
const msg = `Error creating new index ${e}`
|
|
77
|
+
// widgets.complain(context, msg)
|
|
78
|
+
debug.warn(msg)
|
|
79
|
+
}
|
|
80
|
+
} // putIndex
|
|
81
|
+
|
|
82
|
+
context.index = context.index || {}
|
|
83
|
+
context.index[visibility] = context.index[visibility] || []
|
|
84
|
+
let newIndex
|
|
85
|
+
if (context.index[visibility].length === 0) {
|
|
86
|
+
newIndex = sym(`${relevant.dir().uri + visibility}TypeIndex.ttl`)
|
|
87
|
+
debug.log(`Linking to new fresh type index ${newIndex}`)
|
|
88
|
+
if (!confirm(`OK to create a new empty index file at ${newIndex}, overwriting anything that is now there?`)) {
|
|
89
|
+
throw new Error('cancelled by user')
|
|
90
|
+
}
|
|
91
|
+
debug.log(`Linking to new fresh type index ${newIndex}`)
|
|
92
|
+
const addMe = [
|
|
93
|
+
st(context.me, ns.solid(`${visibility}TypeIndex`), newIndex, relevant)
|
|
94
|
+
]
|
|
95
|
+
try {
|
|
96
|
+
await solidLogicSingleton.updatePromise([], addMe)
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const msg = `Error saving type index link saving back ${newIndex}: ${err}`
|
|
99
|
+
//widgets.complain(context, msg)
|
|
100
|
+
debug.warn(msg)
|
|
101
|
+
return context
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
debug.log(`Creating new fresh type index file${newIndex}`)
|
|
105
|
+
await putIndex(newIndex)
|
|
106
|
+
context.index[visibility].push(newIndex) // @@ wait
|
|
107
|
+
} else {
|
|
108
|
+
// officially exists
|
|
109
|
+
const ixs = context.index[visibility]
|
|
110
|
+
try {
|
|
111
|
+
await solidLogicSingleton.load(ixs)
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const msg = `ensureOneTypeIndex: loading indexes ${err}`
|
|
114
|
+
debug.warn(msg)
|
|
115
|
+
// widgets.complain(context, `ensureOneTypeIndex: loading indexes ${err}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} // makeIndexIfNecessary
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await loadIndex(context, isPublic)
|
|
122
|
+
if (context.index) {
|
|
123
|
+
debug.log(
|
|
124
|
+
`ensureOneTypeIndex: Type index exists already ${isPublic
|
|
125
|
+
? context.index.public[0]
|
|
126
|
+
: context.index.private[0]
|
|
127
|
+
}`
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
return context
|
|
131
|
+
} catch (error) {
|
|
132
|
+
await makeIndexIfNecessary(context, isPublic)
|
|
133
|
+
// widgets.complain(context, 'calling loadIndex:' + error)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Register a new app in a type index
|
|
139
|
+
* used in chat in bookmark.js (solid-ui)
|
|
140
|
+
*/
|
|
141
|
+
export async function registerInTypeIndex (
|
|
142
|
+
context: AuthenticationContext,
|
|
143
|
+
instance: NamedNode,
|
|
144
|
+
theClass: NamedNode,
|
|
145
|
+
isPublic: boolean
|
|
146
|
+
): Promise<AuthenticationContext> {
|
|
147
|
+
await ensureOneTypeIndex(context, isPublic)
|
|
148
|
+
if (!context.index) {
|
|
149
|
+
throw new Error('registerInTypeIndex: No type index found')
|
|
150
|
+
}
|
|
151
|
+
const indexes = isPublic ? context.index.public : context.index.private
|
|
152
|
+
if (!indexes.length) {
|
|
153
|
+
throw new Error('registerInTypeIndex: What no type index?')
|
|
154
|
+
}
|
|
155
|
+
const index = indexes[0]
|
|
156
|
+
const registration = newThing(index)
|
|
157
|
+
const ins = [
|
|
158
|
+
// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
|
|
159
|
+
st(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
|
|
160
|
+
st(registration, ns.solid('forClass'), theClass, index),
|
|
161
|
+
st(registration, ns.solid('instance'), instance, index)
|
|
162
|
+
]
|
|
163
|
+
try {
|
|
164
|
+
await solidLogicSingleton.updatePromise([], ins)
|
|
165
|
+
} catch (e) {
|
|
166
|
+
debug.log(e)
|
|
167
|
+
alert(e)
|
|
168
|
+
}
|
|
169
|
+
return context
|
|
170
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Session } from "@inrupt/solid-client-authn-browser"
|
|
2
|
+
import { NamedNode } 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
|
+
interface NewPaneOptions {
|
|
36
|
+
me?: NamedNode;
|
|
37
|
+
newInstance?: NamedNode;
|
|
38
|
+
newBase: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface CreatedPaneOptions {
|
|
42
|
+
newInstance: NamedNode;
|
|
43
|
+
}
|
package/src/util/UtilityLogic.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
import { NamedNode,
|
|
2
|
-
import {
|
|
3
|
-
import { ProfileLogic } from "../profile/ProfileLogic";
|
|
4
|
-
import { newThing } from "../uri";
|
|
1
|
+
import { NamedNode, Statement, sym, LiveStore } from "rdflib";
|
|
2
|
+
import { SolidNamespace } from "../types";
|
|
5
3
|
|
|
6
4
|
export const ACL_LINK = sym(
|
|
7
5
|
"http://www.iana.org/assignments/link-relations/acl"
|
|
8
6
|
);
|
|
9
7
|
|
|
10
|
-
interface NewPaneOptions {
|
|
11
|
-
me?: NamedNode;
|
|
12
|
-
newInstance?: NamedNode;
|
|
13
|
-
newBase: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface CreatedPaneOptions {
|
|
17
|
-
newInstance: NamedNode;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
/**
|
|
21
9
|
* Utility-related logic
|
|
22
10
|
*/
|
|
@@ -33,7 +21,7 @@ export class UtilityLogic {
|
|
|
33
21
|
|
|
34
22
|
async findAclDocUrl(url: string) {
|
|
35
23
|
const doc = this.store.sym(url);
|
|
36
|
-
await this.store.fetcher
|
|
24
|
+
await this.store.fetcher?.load(doc);
|
|
37
25
|
const docNode = this.store.any(doc, ACL_LINK);
|
|
38
26
|
if (!docNode) {
|
|
39
27
|
throw new Error(`No ACL link discovered for ${url}`);
|
|
@@ -137,7 +125,7 @@ export class UtilityLogic {
|
|
|
137
125
|
|
|
138
126
|
async getContainerMembers(containerUrl: string): Promise<string[]> {
|
|
139
127
|
const containerNode = this.store.sym(containerUrl);
|
|
140
|
-
await this.store.fetcher
|
|
128
|
+
await this.store.fetcher?.load(containerNode);
|
|
141
129
|
const nodes = this.getContainerElements(containerNode);
|
|
142
130
|
return nodes.map(node => node.value);
|
|
143
131
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sym } from 'rdflib'
|
|
2
|
+
import { setACLUserPublic } from '../src/acl/aclLogic'
|
|
3
|
+
|
|
4
|
+
describe('setACLUserPublic', () => {
|
|
5
|
+
it('exists', () => {
|
|
6
|
+
expect(setACLUserPublic).toBeInstanceOf(Function)
|
|
7
|
+
})
|
|
8
|
+
it.skip('runs', async () => {
|
|
9
|
+
expect(await setACLUserPublic(
|
|
10
|
+
'https://test.test#',
|
|
11
|
+
sym('https://test.test#'),
|
|
12
|
+
{}
|
|
13
|
+
)).toEqual({})
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
})
|