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
package/src/authn/authUtil.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { NamedNode, sym } from "rdflib"
|
|
2
|
-
import * as debug from '../util/debug'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* find a user or app's context as set in window.SolidAppContext
|
|
6
|
-
* this is a const, not a function, because we have problems to jest mock it otherwise
|
|
7
|
-
* see: https://github.com/facebook/jest/issues/936#issuecomment-545080082 for more
|
|
8
|
-
* @return {any} - an appContext object
|
|
9
|
-
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
export const appContext = ():any => {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
let { SolidAppContext }: any = window
|
|
14
|
-
SolidAppContext ||= {}
|
|
15
|
-
SolidAppContext.viewingNoAuthPage = false
|
|
16
|
-
if (SolidAppContext.noAuth && window.document) {
|
|
17
|
-
const currentPage = window.document.location.href
|
|
18
|
-
if (currentPage.startsWith(SolidAppContext.noAuth)) {
|
|
19
|
-
SolidAppContext.viewingNoAuthPage = true
|
|
20
|
-
const params = new URLSearchParams(window.document.location.search)
|
|
21
|
-
if (params) {
|
|
22
|
-
let viewedPage = SolidAppContext.viewedPage = params.get('uri') || null
|
|
23
|
-
if (viewedPage) {
|
|
24
|
-
viewedPage = decodeURI(viewedPage)
|
|
25
|
-
if (!viewedPage.startsWith(SolidAppContext.noAuth)) {
|
|
26
|
-
const ary = viewedPage.split(/\//)
|
|
27
|
-
SolidAppContext.idp = ary[0] + '//' + ary[2]
|
|
28
|
-
SolidAppContext.viewingNoAuthPage = false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return SolidAppContext
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Returns `sym($SolidTestEnvironment.username)` if
|
|
39
|
-
* `$SolidTestEnvironment.username` is defined as a global
|
|
40
|
-
* or
|
|
41
|
-
* returns testID defined in the HTML page
|
|
42
|
-
* @returns {NamedNode|null}
|
|
43
|
-
*/
|
|
44
|
-
export function offlineTestID (): NamedNode | null {
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
const { $SolidTestEnvironment }: any = window
|
|
47
|
-
if (
|
|
48
|
-
typeof $SolidTestEnvironment !== 'undefined' &&
|
|
49
|
-
$SolidTestEnvironment.username
|
|
50
|
-
) {
|
|
51
|
-
// Test setup
|
|
52
|
-
debug.log('Assuming the user is ' + $SolidTestEnvironment.username)
|
|
53
|
-
return sym($SolidTestEnvironment.username)
|
|
54
|
-
}
|
|
55
|
-
// hack that makes SolidOS work in offline mode by adding the webId directly in html
|
|
56
|
-
// example usage: https://github.com/solidos/mashlib/blob/29b8b53c46bf02e0e219f0bacd51b0e9951001dd/test/contact/local.html#L37
|
|
57
|
-
if (
|
|
58
|
-
typeof document !== 'undefined' &&
|
|
59
|
-
document.location &&
|
|
60
|
-
('' + document.location).slice(0, 16) === 'http://localhost'
|
|
61
|
-
) {
|
|
62
|
-
const div = document.getElementById('appTarget')
|
|
63
|
-
if (!div) return null
|
|
64
|
-
const id = div.getAttribute('testID')
|
|
65
|
-
if (!id) return null
|
|
66
|
-
debug.log('Assuming user is ' + id)
|
|
67
|
-
return sym(id)
|
|
68
|
-
}
|
|
69
|
-
return null
|
|
70
|
-
}
|
package/src/chat/chatLogic.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { NamedNode, Node, st, term } from "rdflib"
|
|
2
|
-
import { ChatLogic, CreatedPaneOptions, NewPaneOptions, Chat } from "../types"
|
|
3
|
-
import { ns as namespace } from "../util/ns";
|
|
4
|
-
import { determineChatContainer, newThing } from "../util/utils"
|
|
5
|
-
|
|
6
|
-
const CHAT_LOCATION_IN_CONTAINER = "index.ttl#this"
|
|
7
|
-
|
|
8
|
-
export function createChatLogic(store, profileLogic): ChatLogic {
|
|
9
|
-
const ns = namespace
|
|
10
|
-
|
|
11
|
-
async function setAcl(
|
|
12
|
-
chatContainer: NamedNode,
|
|
13
|
-
me: NamedNode,
|
|
14
|
-
invitee: NamedNode
|
|
15
|
-
): Promise<void> {
|
|
16
|
-
// Some servers don't present a Link http response header
|
|
17
|
-
// if the container doesn't exist yet, so refetch the container
|
|
18
|
-
// now that it has been created:
|
|
19
|
-
await store.fetcher.load(chatContainer);
|
|
20
|
-
|
|
21
|
-
// FIXME: check the Why value on this quad:
|
|
22
|
-
const chatAclDoc = store.any(
|
|
23
|
-
chatContainer,
|
|
24
|
-
new NamedNode("http://www.iana.org/assignments/link-relations/acl")
|
|
25
|
-
);
|
|
26
|
-
if (!chatAclDoc) {
|
|
27
|
-
throw new Error("Chat ACL doc not found!");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const aclBody = `
|
|
31
|
-
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
|
|
32
|
-
<#owner>
|
|
33
|
-
a acl:Authorization;
|
|
34
|
-
acl:agent <${me.value}>;
|
|
35
|
-
acl:accessTo <.>;
|
|
36
|
-
acl:default <.>;
|
|
37
|
-
acl:mode
|
|
38
|
-
acl:Read, acl:Write, acl:Control.
|
|
39
|
-
<#invitee>
|
|
40
|
-
a acl:Authorization;
|
|
41
|
-
acl:agent <${invitee.value}>;
|
|
42
|
-
acl:accessTo <.>;
|
|
43
|
-
acl:default <.>;
|
|
44
|
-
acl:mode
|
|
45
|
-
acl:Read, acl:Append.
|
|
46
|
-
`;
|
|
47
|
-
await store.fetcher.webOperation("PUT", chatAclDoc.value, {
|
|
48
|
-
data: aclBody,
|
|
49
|
-
contentType: "text/turtle",
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function addToPrivateTypeIndex(chatThing, me) {
|
|
54
|
-
// Add to private type index
|
|
55
|
-
const privateTypeIndex = store.any(
|
|
56
|
-
me,
|
|
57
|
-
ns.solid("privateTypeIndex")
|
|
58
|
-
) as NamedNode | null;
|
|
59
|
-
if (!privateTypeIndex) {
|
|
60
|
-
throw new Error("Private type index not found!");
|
|
61
|
-
}
|
|
62
|
-
await store.fetcher.load(privateTypeIndex);
|
|
63
|
-
const reg = newThing(privateTypeIndex);
|
|
64
|
-
const ins = [
|
|
65
|
-
st(
|
|
66
|
-
reg,
|
|
67
|
-
ns.rdf("type"),
|
|
68
|
-
ns.solid("TypeRegistration"),
|
|
69
|
-
privateTypeIndex.doc()
|
|
70
|
-
),
|
|
71
|
-
st(
|
|
72
|
-
reg,
|
|
73
|
-
ns.solid("forClass"),
|
|
74
|
-
ns.meeting("LongChat"),
|
|
75
|
-
privateTypeIndex.doc()
|
|
76
|
-
),
|
|
77
|
-
st(reg, ns.solid("instance"), chatThing, privateTypeIndex.doc()),
|
|
78
|
-
];
|
|
79
|
-
await new Promise((resolve, reject) => {
|
|
80
|
-
store.updater.update([], ins, function (_uri, ok, errm) {
|
|
81
|
-
if (!ok) {
|
|
82
|
-
reject(new Error(errm));
|
|
83
|
-
} else {
|
|
84
|
-
resolve(null);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function findChat(invitee: NamedNode): Promise<Chat> {
|
|
91
|
-
const me = await profileLogic.loadMe();
|
|
92
|
-
const podRoot = await profileLogic.getPodRoot(me);
|
|
93
|
-
const chatContainer = determineChatContainer(invitee, podRoot);
|
|
94
|
-
let exists = true;
|
|
95
|
-
try {
|
|
96
|
-
await store.fetcher.load(
|
|
97
|
-
new NamedNode(chatContainer.value + "index.ttl#this")
|
|
98
|
-
);
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
-
} catch (e) {
|
|
101
|
-
exists = false;
|
|
102
|
-
}
|
|
103
|
-
return { me, chatContainer, exists };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function createChatThing(
|
|
107
|
-
chatContainer: NamedNode,
|
|
108
|
-
me: NamedNode
|
|
109
|
-
): Promise<NamedNode> {
|
|
110
|
-
const created = await mintNew({
|
|
111
|
-
me,
|
|
112
|
-
newBase: chatContainer.value,
|
|
113
|
-
});
|
|
114
|
-
return created.newInstance;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function mintNew(newPaneOptions: NewPaneOptions): Promise<CreatedPaneOptions> {
|
|
118
|
-
const kb = store;
|
|
119
|
-
const updater = kb.updater;
|
|
120
|
-
if (newPaneOptions.me && !newPaneOptions.me.uri) {
|
|
121
|
-
throw new Error("chat mintNew: Invalid userid " + newPaneOptions.me);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const newInstance = (newPaneOptions.newInstance =
|
|
125
|
-
newPaneOptions.newInstance ||
|
|
126
|
-
kb.sym(newPaneOptions.newBase + CHAT_LOCATION_IN_CONTAINER));
|
|
127
|
-
const newChatDoc = newInstance.doc();
|
|
128
|
-
|
|
129
|
-
kb.add(
|
|
130
|
-
newInstance,
|
|
131
|
-
ns.rdf("type"),
|
|
132
|
-
ns.meeting("LongChat"),
|
|
133
|
-
newChatDoc
|
|
134
|
-
);
|
|
135
|
-
kb.add(newInstance, ns.dc("title"), "Chat channel", newChatDoc);
|
|
136
|
-
kb.add(
|
|
137
|
-
newInstance,
|
|
138
|
-
ns.dc("created"),
|
|
139
|
-
term<Node>(new Date(Date.now())),
|
|
140
|
-
newChatDoc
|
|
141
|
-
);
|
|
142
|
-
if (newPaneOptions.me) {
|
|
143
|
-
kb.add(newInstance, ns.dc("author"), newPaneOptions.me, newChatDoc);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return new Promise(function (resolve, reject) {
|
|
147
|
-
updater?.put(
|
|
148
|
-
newChatDoc,
|
|
149
|
-
kb.statementsMatching(undefined, undefined, undefined, newChatDoc),
|
|
150
|
-
"text/turtle",
|
|
151
|
-
function (uri2, ok, message) {
|
|
152
|
-
if (ok) {
|
|
153
|
-
resolve({
|
|
154
|
-
...newPaneOptions,
|
|
155
|
-
newInstance,
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
reject(
|
|
159
|
-
new Error(
|
|
160
|
-
"FAILED to save new chat channel at: " + uri2 + " : " + message
|
|
161
|
-
)
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Find (and optionally create) an individual chat between the current user and the given invitee
|
|
171
|
-
* @param invitee - The person to chat with
|
|
172
|
-
* @param createIfMissing - Whether the chat should be created, if missing
|
|
173
|
-
* @returns null if missing, or a node referring to an already existing chat, or the newly created chat
|
|
174
|
-
*/
|
|
175
|
-
async function getChat(
|
|
176
|
-
invitee: NamedNode,
|
|
177
|
-
createIfMissing = true
|
|
178
|
-
): Promise<NamedNode | null> {
|
|
179
|
-
const { me, chatContainer, exists } = await findChat(invitee);
|
|
180
|
-
if (exists) {
|
|
181
|
-
return new NamedNode(chatContainer.value + CHAT_LOCATION_IN_CONTAINER);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (createIfMissing) {
|
|
185
|
-
const chatThing = await createChatThing(chatContainer, me);
|
|
186
|
-
await sendInvite(invitee, chatThing);
|
|
187
|
-
await setAcl(chatContainer, me, invitee);
|
|
188
|
-
await addToPrivateTypeIndex(chatThing, me);
|
|
189
|
-
return chatThing;
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function sendInvite(invitee: NamedNode, chatThing: NamedNode) {
|
|
195
|
-
await store.fetcher.load(invitee.doc());
|
|
196
|
-
const inviteeInbox = store.any(
|
|
197
|
-
invitee,
|
|
198
|
-
ns.ldp("inbox"),
|
|
199
|
-
undefined,
|
|
200
|
-
invitee.doc()
|
|
201
|
-
);
|
|
202
|
-
if (!inviteeInbox) {
|
|
203
|
-
throw new Error(`Invitee inbox not found! ${invitee.value}`);
|
|
204
|
-
}
|
|
205
|
-
const inviteBody = `
|
|
206
|
-
<> a <http://www.w3.org/ns/pim/meeting#LongChatInvite> ;
|
|
207
|
-
${ns.rdf("seeAlso")} <${chatThing.value}> .
|
|
208
|
-
`;
|
|
209
|
-
|
|
210
|
-
const inviteResponse = await store.fetcher?.webOperation(
|
|
211
|
-
"POST",
|
|
212
|
-
inviteeInbox.value,
|
|
213
|
-
{
|
|
214
|
-
data: inviteBody,
|
|
215
|
-
contentType: "text/turtle",
|
|
216
|
-
}
|
|
217
|
-
);
|
|
218
|
-
const locationStr = inviteResponse?.headers.get("location");
|
|
219
|
-
if (!locationStr) {
|
|
220
|
-
throw new Error(`Invite sending returned a ${inviteResponse?.status}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
setAcl, addToPrivateTypeIndex, findChat, createChatThing, getChat, sendInvite, mintNew
|
|
225
|
-
}
|
|
226
|
-
}
|
package/src/inbox/inboxLogic.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { NamedNode } from "rdflib";
|
|
2
|
-
import { InboxLogic } from "../types";
|
|
3
|
-
import { getArchiveUrl } from "../util/utils";
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
export function createInboxLogic(store, profileLogic, utilityLogic, containerLogic, aclLogic): InboxLogic {
|
|
7
|
-
|
|
8
|
-
async function createInboxFor(peerWebId: string, nick: string) {
|
|
9
|
-
const myWebId: NamedNode = await profileLogic.loadMe();
|
|
10
|
-
const podRoot: NamedNode = await profileLogic.getPodRoot(myWebId);
|
|
11
|
-
const ourInbox = `${podRoot.value}p2p-inboxes/${encodeURIComponent(nick)}/`;
|
|
12
|
-
await containerLogic.createContainer(ourInbox);
|
|
13
|
-
// const aclDocUrl = await aclLogic.findAclDocUrl(ourInbox);
|
|
14
|
-
await utilityLogic.setSinglePeerAccess({
|
|
15
|
-
ownerWebId: myWebId.value,
|
|
16
|
-
peerWebId,
|
|
17
|
-
accessToModes: 'acl:Append',
|
|
18
|
-
target: ourInbox
|
|
19
|
-
});
|
|
20
|
-
return ourInbox;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function getNewMessages(
|
|
24
|
-
user?: NamedNode
|
|
25
|
-
): Promise<NamedNode[]> {
|
|
26
|
-
if (!user) {
|
|
27
|
-
user = await profileLogic.loadMe();
|
|
28
|
-
}
|
|
29
|
-
const inbox = await profileLogic.getMainInbox(user);
|
|
30
|
-
const urls = await containerLogic.getContainerMembers(inbox);
|
|
31
|
-
return urls.filter(url => !containerLogic.isContainer(url));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function markAsRead(url: string, date: Date) {
|
|
35
|
-
const downloaded = await store.fetcher._fetch(url);
|
|
36
|
-
if (downloaded.status !== 200) {
|
|
37
|
-
throw new Error(`Not OK! ${url}`);
|
|
38
|
-
}
|
|
39
|
-
const archiveUrl = getArchiveUrl(url, date);
|
|
40
|
-
const options = {
|
|
41
|
-
method: 'PUT',
|
|
42
|
-
body: await downloaded.text(),
|
|
43
|
-
headers: [
|
|
44
|
-
['Content-Type', downloaded.headers.get('Content-Type') || 'application/octet-stream']
|
|
45
|
-
]
|
|
46
|
-
};
|
|
47
|
-
const uploaded = await store.fetcher._fetch(archiveUrl, options);
|
|
48
|
-
if (uploaded.status.toString()[0] === '2') {
|
|
49
|
-
await store.fetcher._fetch(url, {
|
|
50
|
-
method: 'DELETE'
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
createInboxFor,
|
|
56
|
-
getNewMessages,
|
|
57
|
-
markAsRead
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Make these variables directly accessible as it is what you need most of the time
|
|
2
|
-
// This also makes these variable globaly accesible in mashlib
|
|
3
|
-
import { solidLogicSingleton } from './logic/solidLogicSingleton'
|
|
4
|
-
|
|
5
|
-
const authn = solidLogicSingleton.authn
|
|
6
|
-
const authSession = solidLogicSingleton.authn.authSession
|
|
7
|
-
const store = solidLogicSingleton.store
|
|
8
|
-
|
|
9
|
-
export { ACL_LINK } from './acl/aclLogic'
|
|
10
|
-
export { offlineTestID, appContext } from './authn/authUtil'
|
|
11
|
-
export { getSuggestedIssuers } from './issuer/issuerLogic'
|
|
12
|
-
export { createTypeIndexLogic } from './typeIndex/typeIndexLogic'
|
|
13
|
-
export { AppDetails, SolidNamespace, AuthenticationContext, SolidLogic } from './types'
|
|
14
|
-
export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError, NotEditableError, WebOperationError } from './logic/CustomError'
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
solidLogicSingleton, // solidLogicSingleton is exported entirely because it is used in solid-panes
|
|
18
|
-
store,
|
|
19
|
-
authn,
|
|
20
|
-
authSession
|
|
21
|
-
}
|
|
22
|
-
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const DEFAULT_ISSUERS = [
|
|
2
|
-
{
|
|
3
|
-
name: 'Solid Community',
|
|
4
|
-
uri: 'https://solidcommunity.net'
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
name: 'Solid Web',
|
|
8
|
-
uri: 'https://solidweb.org'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: 'Solid Web ME',
|
|
12
|
-
uri: 'https://solidweb.me'
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'Inrupt.com',
|
|
16
|
-
uri: 'https://login.inrupt.com'
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @returns - A list of suggested OIDC issuers
|
|
22
|
-
*/
|
|
23
|
-
export function getSuggestedIssuers (): { name: string, uri: string }[] {
|
|
24
|
-
// Suggest a default list of OIDC issuers
|
|
25
|
-
const issuers = [...DEFAULT_ISSUERS]
|
|
26
|
-
|
|
27
|
-
// Suggest the current host if not already included
|
|
28
|
-
const { host, origin } = new URL(location.href)
|
|
29
|
-
const hosts = issuers.map(({ uri }) => new URL(uri).host)
|
|
30
|
-
if (!hosts.includes(host) && !hosts.some(existing => isSubdomainOf(host, existing))) {
|
|
31
|
-
issuers.unshift({ name: host, uri: origin })
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return issuers
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isSubdomainOf (subdomain: string, domain: string): boolean {
|
|
38
|
-
const dot = subdomain.length - domain.length - 1
|
|
39
|
-
return dot > 0 && subdomain[dot] === '.' && subdomain.endsWith(domain)
|
|
40
|
-
}
|
package/src/logic/CustomError.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
class CustomError extends Error {
|
|
2
|
-
constructor(message?: string) {
|
|
3
|
-
super(message);
|
|
4
|
-
// see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
5
|
-
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
|
|
6
|
-
this.name = new.target.name; // stack traces display correctly now
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class UnauthorizedError extends CustomError {}
|
|
11
|
-
|
|
12
|
-
export class CrossOriginForbiddenError extends CustomError {}
|
|
13
|
-
|
|
14
|
-
export class SameOriginForbiddenError extends CustomError {}
|
|
15
|
-
|
|
16
|
-
export class NotFoundError extends CustomError {}
|
|
17
|
-
|
|
18
|
-
export class NotEditableError extends CustomError { }
|
|
19
|
-
|
|
20
|
-
export class WebOperationError extends CustomError {}
|
|
21
|
-
|
|
22
|
-
export class FetchError extends CustomError {
|
|
23
|
-
status: number;
|
|
24
|
-
|
|
25
|
-
constructor(status: number, message?: string) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.status = status;
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/logic/solidLogic.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Session } from "@inrupt/solid-client-authn-browser";
|
|
2
|
-
import * as rdf from "rdflib";
|
|
3
|
-
import { LiveStore, NamedNode, Statement } from "rdflib";
|
|
4
|
-
import { createAclLogic } from "../acl/aclLogic";
|
|
5
|
-
import { SolidAuthnLogic } from "../authn/SolidAuthnLogic";
|
|
6
|
-
import { createChatLogic } from "../chat/chatLogic";
|
|
7
|
-
import { createInboxLogic } from "../inbox/inboxLogic";
|
|
8
|
-
import { createProfileLogic } from "../profile/profileLogic";
|
|
9
|
-
import { createTypeIndexLogic } from "../typeIndex/typeIndexLogic";
|
|
10
|
-
import { createContainerLogic } from "../util/containerLogic";
|
|
11
|
-
import { createUtilityLogic } from "../util/utilityLogic";
|
|
12
|
-
import { AuthnLogic, SolidLogic } from "../types";
|
|
13
|
-
import * as debug from "../util/debug";
|
|
14
|
-
/*
|
|
15
|
-
** It is important to distinquish `fetch`, a function provided by the browser
|
|
16
|
-
** and `Fetcher`, a helper object for the rdflib Store which turns it
|
|
17
|
-
** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is
|
|
18
|
-
** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,
|
|
19
|
-
*/
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
export function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: Session): SolidLogic {
|
|
22
|
-
|
|
23
|
-
debug.log("SolidLogic: Unique instance created. There should only be one of these.")
|
|
24
|
-
const store: LiveStore = rdf.graph() as LiveStore
|
|
25
|
-
rdf.fetcher(store, {fetch: specialFetch.fetch}); // Attach a web I/O module, store.fetcher
|
|
26
|
-
store.updater = new rdf.UpdateManager(store); // Add real-time live updates store.updater
|
|
27
|
-
store.features = [] // disable automatic node merging on store load
|
|
28
|
-
|
|
29
|
-
const authn: AuthnLogic = new SolidAuthnLogic(session)
|
|
30
|
-
|
|
31
|
-
const acl = createAclLogic(store)
|
|
32
|
-
const containerLogic = createContainerLogic(store)
|
|
33
|
-
const utilityLogic = createUtilityLogic(store, acl, containerLogic)
|
|
34
|
-
const profile = createProfileLogic(store, authn, utilityLogic)
|
|
35
|
-
const chat = createChatLogic(store, profile)
|
|
36
|
-
const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)
|
|
37
|
-
const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)
|
|
38
|
-
debug.log('SolidAuthnLogic initialized')
|
|
39
|
-
|
|
40
|
-
function load(doc: NamedNode | NamedNode[] | string) {
|
|
41
|
-
return store.fetcher.load(doc);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// @@@@ use the one in rdflib.js when it is available and delete this
|
|
45
|
-
function updatePromise(
|
|
46
|
-
del: Array<Statement>,
|
|
47
|
-
ins: Array<Statement> = []
|
|
48
|
-
): Promise<void> {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
store.updater.update(del, ins, function (_uri, ok, errorBody) {
|
|
51
|
-
if (!ok) {
|
|
52
|
-
reject(new Error(errorBody));
|
|
53
|
-
} else {
|
|
54
|
-
resolve();
|
|
55
|
-
}
|
|
56
|
-
}); // callback
|
|
57
|
-
}); // promise
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function clearStore() {
|
|
61
|
-
store.statements.slice().forEach(store.remove.bind(store));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
store,
|
|
66
|
-
authn,
|
|
67
|
-
acl,
|
|
68
|
-
inbox,
|
|
69
|
-
chat,
|
|
70
|
-
profile,
|
|
71
|
-
typeIndex,
|
|
72
|
-
load,
|
|
73
|
-
updatePromise,
|
|
74
|
-
clearStore
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as debug from "../util/debug"
|
|
2
|
-
import { authSession } from "../authSession/authSession"
|
|
3
|
-
import { createSolidLogic } from "./solidLogic"
|
|
4
|
-
|
|
5
|
-
const _fetch = async (url, requestInit) => {
|
|
6
|
-
const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'
|
|
7
|
-
if (authSession.info.webId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114
|
|
8
|
-
// In fact fetch should respect credentials omit itself
|
|
9
|
-
return authSession.fetch(url, requestInit)
|
|
10
|
-
} else {
|
|
11
|
-
return window.fetch(url, requestInit)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//this const makes solidLogicSingleton global accessible in mashlib
|
|
16
|
-
const solidLogicSingleton = createSolidLogic({ fetch: _fetch }, authSession)
|
|
17
|
-
|
|
18
|
-
debug.log('Unique quadstore initialized.')
|
|
19
|
-
|
|
20
|
-
export { solidLogicSingleton }
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { NamedNode } from "rdflib";
|
|
2
|
-
import { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from "../logic/CustomError";
|
|
3
|
-
import * as debug from "../util/debug";
|
|
4
|
-
import { ns as namespace } from '../util/ns';
|
|
5
|
-
import { differentOrigin, suggestPreferencesFile } from "../util/utils"
|
|
6
|
-
import { ProfileLogic } from "../types"
|
|
7
|
-
|
|
8
|
-
export function createProfileLogic(store, authn, utilityLogic): ProfileLogic {
|
|
9
|
-
const ns = namespace
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* loads the preference without throwing errors - if it can create it it does so.
|
|
13
|
-
* remark: it still throws error if it cannot load profile.
|
|
14
|
-
* @param user
|
|
15
|
-
* @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it
|
|
16
|
-
*/
|
|
17
|
-
async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {
|
|
18
|
-
try {
|
|
19
|
-
return await loadPreferences(user)
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
-
} catch (err) {
|
|
22
|
-
return undefined
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* loads the preference without returning different errors if it cannot create or load it.
|
|
28
|
-
* remark: it also throws error if it cannot load profile.
|
|
29
|
-
* @param user
|
|
30
|
-
* @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it
|
|
31
|
-
*/
|
|
32
|
-
async function loadPreferences (user: NamedNode): Promise <NamedNode> {
|
|
33
|
-
await loadProfile(user)
|
|
34
|
-
|
|
35
|
-
const possiblePreferencesFile = suggestPreferencesFile(user)
|
|
36
|
-
let preferencesFile
|
|
37
|
-
try {
|
|
38
|
-
preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const message = `User ${user} has no pointer in profile to preferences file.`
|
|
41
|
-
debug.warn(message)
|
|
42
|
-
// we are listing the possible errors
|
|
43
|
-
if (err instanceof NotEditableError) { throw err }
|
|
44
|
-
if (err instanceof WebOperationError) { throw err }
|
|
45
|
-
if (err instanceof UnauthorizedError) { throw err }
|
|
46
|
-
if (err instanceof CrossOriginForbiddenError) { throw err }
|
|
47
|
-
if (err instanceof SameOriginForbiddenError) { throw err }
|
|
48
|
-
if (err instanceof FetchError) { throw err }
|
|
49
|
-
throw err
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
await store.fetcher.load(preferencesFile as NamedNode)
|
|
54
|
-
} catch (err) { // Maybe a permission problem or origin problem
|
|
55
|
-
const msg = `Unable to load preference of user ${user}: ${err}`
|
|
56
|
-
debug.warn(msg)
|
|
57
|
-
if (err.response.status === 401) {
|
|
58
|
-
throw new UnauthorizedError();
|
|
59
|
-
}
|
|
60
|
-
if (err.response.status === 403) {
|
|
61
|
-
if (differentOrigin(preferencesFile)) {
|
|
62
|
-
throw new CrossOriginForbiddenError();
|
|
63
|
-
}
|
|
64
|
-
throw new SameOriginForbiddenError();
|
|
65
|
-
}
|
|
66
|
-
/*if (err.response.status === 404) {
|
|
67
|
-
throw new NotFoundError();
|
|
68
|
-
}*/
|
|
69
|
-
throw new Error(msg)
|
|
70
|
-
}
|
|
71
|
-
return preferencesFile as NamedNode
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function loadProfile (user: NamedNode):Promise <NamedNode> {
|
|
75
|
-
if (!user) {
|
|
76
|
-
throw new Error(`loadProfile: no user given.`)
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
await store.fetcher.load(user.doc())
|
|
80
|
-
} catch (err) {
|
|
81
|
-
throw new Error(`Unable to load profile of user ${user}: ${err}`)
|
|
82
|
-
}
|
|
83
|
-
return user.doc()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function loadMe(): Promise<NamedNode> {
|
|
87
|
-
const me = authn.currentUser();
|
|
88
|
-
if (me === null) {
|
|
89
|
-
throw new Error("Current user not found! Not logged in?");
|
|
90
|
-
}
|
|
91
|
-
await store.fetcher.load(me.doc());
|
|
92
|
-
return me;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function getPodRoot(user: NamedNode): NamedNode {
|
|
96
|
-
const podRoot = findStorage(user);
|
|
97
|
-
if (!podRoot) {
|
|
98
|
-
throw new Error("User pod root not found!");
|
|
99
|
-
}
|
|
100
|
-
return podRoot as NamedNode;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function getMainInbox(user: NamedNode): Promise<NamedNode> {
|
|
104
|
-
await store.fetcher.load(user);
|
|
105
|
-
const mainInbox = store.any(user, ns.ldp("inbox"), undefined, user.doc());
|
|
106
|
-
if (!mainInbox) {
|
|
107
|
-
throw new Error("User main inbox not found!");
|
|
108
|
-
}
|
|
109
|
-
return mainInbox as NamedNode;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function findStorage(me: NamedNode) {
|
|
113
|
-
return store.any(me, ns.space("storage"), undefined, me.doc());
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
loadMe,
|
|
118
|
-
getPodRoot,
|
|
119
|
-
getMainInbox,
|
|
120
|
-
findStorage,
|
|
121
|
-
loadPreferences,
|
|
122
|
-
loadProfile,
|
|
123
|
-
silencedLoadPreferences
|
|
124
|
-
}
|
|
125
|
-
}
|