solid-logic 3.0.9-ea192f01 → 3.0.9-ed64096
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/package.json +9 -3
- package/babel.config.js +0 -6
- package/eslint.config.js +0 -28
- package/jest.config.js +0 -17
- package/rollup.config.js +0 -29
- package/src/acl/aclLogic.ts +0 -156
- package/src/authSession/authSession.ts +0 -13
- package/src/authn/SolidAuthnLogic.ts +0 -126
- 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 -21
- 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/containerLogic.ts +0 -53
- package/src/util/debug.ts +0 -16
- package/src/util/ns.ts +0 -5
- package/src/util/utilityLogic.ts +0 -156
- package/src/util/utils.ts +0 -52
- package/src/versionInfo.ts +0 -32
- package/test/aclLogic.test.ts +0 -24
- package/test/authUtil.test.ts +0 -23
- package/test/chatLogic.test.ts +0 -322
- package/test/container.test.ts +0 -58
- package/test/helpers/dataSetup.ts +0 -135
- package/test/helpers/setup.ts +0 -22
- package/test/inboxLogic.test.ts +0 -209
- package/test/logic.test.ts +0 -29
- package/test/profileLogic.test.ts +0 -248
- package/test/solidAuthLogic.test.ts +0 -49
- package/test/typeIndexLogic.test.ts +0 -255
- package/test/utilityLogic.test.ts +0 -180
- package/test/utils.test.ts +0 -32
- package/timestamp.sh +0 -13
- package/tsconfig.json +0 -77
- package/tsconfig.test.json +0 -8
- /package/{lib → dist}/acl/aclLogic.d.ts +0 -0
- /package/{lib → dist}/acl/aclLogic.d.ts.map +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts.map +0 -0
- /package/{lib → dist}/authn/SolidAuthnLogic.d.ts +0 -0
- /package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts.map +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts.map +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts.map +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.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/CustomError.d.ts.map +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts.map +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 +0 -0
- /package/{lib → dist}/profile/profileLogic.d.ts.map +0 -0
- /package/{lib → dist}/solid-logic.js +0 -0
- /package/{lib → dist}/solid-logic.js.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 +0 -0
- /package/{lib → dist}/types.d.ts.map +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/debug.d.ts +0 -0
- /package/{lib → dist}/util/debug.d.ts.map +0 -0
- /package/{lib → dist}/util/ns.d.ts +0 -0
- /package/{lib → dist}/util/ns.d.ts.map +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/utils.d.ts +0 -0
- /package/{lib → dist}/util/utils.d.ts.map +0 -0
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-logic",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.9-
|
|
4
|
+
"version": "3.0.9-ed64096",
|
|
5
5
|
"description": "Core business logic of SolidOS",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "dist/solid-logic.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
7
13
|
"scripts": {
|
|
8
|
-
"clean": "rm -rf
|
|
14
|
+
"clean": "rm -rf dist src/versionInfo.ts",
|
|
9
15
|
"build": "npm run clean && npm run build-types && npm run build-version && rollup -c",
|
|
10
16
|
"build-version": "./timestamp.sh > src/versionInfo.ts && eslint 'src/versionInfo.ts' --fix",
|
|
11
17
|
"build-types": "tsc --emitDeclarationOnly",
|
package/babel.config.js
DELETED
package/eslint.config.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import tsParser from '@typescript-eslint/parser';
|
|
2
|
-
import tseslint from '@typescript-eslint/eslint-plugin';
|
|
3
|
-
import importPlugin from 'eslint-plugin-import';
|
|
4
|
-
|
|
5
|
-
export default [
|
|
6
|
-
{
|
|
7
|
-
files: ['src/**/*.ts', 'test/**/*.test.ts'],
|
|
8
|
-
ignores: ['lib/**', 'node_modules/**'],
|
|
9
|
-
languageOptions: {
|
|
10
|
-
parser: tsParser,
|
|
11
|
-
parserOptions: {
|
|
12
|
-
project: ['./tsconfig.json', './tsconfig.test.json'],
|
|
13
|
-
sourceType: 'module',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
plugins: {
|
|
17
|
-
'@typescript-eslint': tseslint,
|
|
18
|
-
import: importPlugin,
|
|
19
|
-
},
|
|
20
|
-
rules: {
|
|
21
|
-
'semi': ['error', 'never'],
|
|
22
|
-
'quotes': ['error', 'single'],
|
|
23
|
-
'no-unused-vars': 'off', // handled by TS
|
|
24
|
-
'@typescript-eslint/no-unused-vars': ['warn'],
|
|
25
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
];
|
package/jest.config.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @type {import("jest").Config} */
|
|
2
|
-
export default {
|
|
3
|
-
// verbose: true, // Uncomment for detailed test output
|
|
4
|
-
collectCoverage: true,
|
|
5
|
-
coverageDirectory: "coverage",
|
|
6
|
-
testEnvironment: "jsdom",
|
|
7
|
-
testEnvironmentOptions: {
|
|
8
|
-
customExportConditions: ["node"],
|
|
9
|
-
},
|
|
10
|
-
testPathIgnorePatterns: ["/node_modules/", "/lib/"],
|
|
11
|
-
transform: {
|
|
12
|
-
"^.+\\.[tj]sx?$": ["babel-jest", { configFile: "./babel.config.js" }],
|
|
13
|
-
},
|
|
14
|
-
setupFilesAfterEnv: ["./test/helpers/setup.ts"],
|
|
15
|
-
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
|
|
16
|
-
roots: ["<rootDir>/src", "<rootDir>/test"],
|
|
17
|
-
};
|
package/rollup.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
-
import typescript from '@rollup/plugin-typescript'
|
|
4
|
-
import { terser } from 'rollup-plugin-terser'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
import json from '@rollup/plugin-json'
|
|
7
|
-
|
|
8
|
-
const license = fs.readFileSync('./LICENSE', 'utf8')
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
input: 'src/index.ts',
|
|
12
|
-
output: {
|
|
13
|
-
file: 'lib/solid-logic.js',
|
|
14
|
-
format: 'esm',
|
|
15
|
-
banner: `/*!\n${license}\n*/`,
|
|
16
|
-
sourcemap: true
|
|
17
|
-
},
|
|
18
|
-
plugins: [
|
|
19
|
-
resolve({ preferBuiltins: true }), // best practice to be true, chooses node.js buildins
|
|
20
|
-
commonjs(),
|
|
21
|
-
typescript({
|
|
22
|
-
declaration: false, // this is false so it does not generate types for the versionInfo file
|
|
23
|
-
declarationMap: false
|
|
24
|
-
}),
|
|
25
|
-
json(),
|
|
26
|
-
terser()
|
|
27
|
-
],
|
|
28
|
-
inlineDynamicImports: true // dissables multiple chunk creation, why we use rollup in the first place
|
|
29
|
-
}
|
package/src/acl/aclLogic.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { graph, NamedNode, Namespace, serialize, sym } from 'rdflib'
|
|
2
|
-
import { AclLogic } from '../types'
|
|
3
|
-
import { ns as namespace } from '../util/ns'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const ACL_LINK = sym(
|
|
7
|
-
'http://www.iana.org/assignments/link-relations/acl'
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
export function createAclLogic(store): AclLogic {
|
|
11
|
-
|
|
12
|
-
const ns = namespace
|
|
13
|
-
|
|
14
|
-
async function findAclDocUrl(url: NamedNode) {
|
|
15
|
-
await store.fetcher.load(url)
|
|
16
|
-
const docNode = store.any(url, ACL_LINK)
|
|
17
|
-
if (!docNode) {
|
|
18
|
-
throw new Error(`No ACL link discovered for ${url}`)
|
|
19
|
-
}
|
|
20
|
-
return docNode.value
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Simple Access Control
|
|
24
|
-
*
|
|
25
|
-
* This function sets up a simple default ACL for a resource, with
|
|
26
|
-
* RWC for the owner, and a specified access (default none) for the public.
|
|
27
|
-
* In all cases owner has read write control.
|
|
28
|
-
* Parameter lists modes allowed to public
|
|
29
|
-
*
|
|
30
|
-
* @param options
|
|
31
|
-
* @param options.public eg ['Read', 'Write']
|
|
32
|
-
*
|
|
33
|
-
* @returns Resolves with aclDoc uri on successful write
|
|
34
|
-
*/
|
|
35
|
-
function setACLUserPublic (
|
|
36
|
-
docURI: string,
|
|
37
|
-
me: NamedNode,
|
|
38
|
-
options: {
|
|
39
|
-
defaultForNew?: boolean,
|
|
40
|
-
public?: []
|
|
41
|
-
}
|
|
42
|
-
): Promise<NamedNode> {
|
|
43
|
-
const aclDoc = store.any(
|
|
44
|
-
store.sym(docURI),
|
|
45
|
-
ACL_LINK
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
return Promise.resolve()
|
|
49
|
-
.then(() => {
|
|
50
|
-
if (aclDoc) {
|
|
51
|
-
return aclDoc as NamedNode
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return fetchACLRel(docURI).catch(err => {
|
|
55
|
-
throw new Error(`Error fetching rel=ACL header for ${docURI}: ${err}`)
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
.then(aclDoc => {
|
|
59
|
-
const aclText = genACLText(docURI, me, aclDoc.uri, options)
|
|
60
|
-
if (!store.fetcher) {
|
|
61
|
-
throw new Error('Cannot PUT this, store has no fetcher')
|
|
62
|
-
}
|
|
63
|
-
return store.fetcher
|
|
64
|
-
.webOperation('PUT', aclDoc.uri, {
|
|
65
|
-
data: aclText,
|
|
66
|
-
contentType: 'text/turtle'
|
|
67
|
-
})
|
|
68
|
-
.then(result => {
|
|
69
|
-
if (!result.ok) {
|
|
70
|
-
throw new Error('Error writing ACL text: ' + result.error)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return aclDoc
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @param docURI
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
function fetchACLRel (docURI: string): Promise<NamedNode> {
|
|
83
|
-
const fetcher = store.fetcher
|
|
84
|
-
if (!fetcher) {
|
|
85
|
-
throw new Error('Cannot fetch ACL rel, store has no fetcher')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return fetcher.load(docURI).then(result => {
|
|
89
|
-
if (!result.ok) {
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
-
throw new Error('fetchACLRel: While loading:' + (result as any).error)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const aclDoc = store.any(
|
|
95
|
-
store.sym(docURI),
|
|
96
|
-
ACL_LINK
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
if (!aclDoc) {
|
|
100
|
-
throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return aclDoc as NamedNode
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @param docURI
|
|
109
|
-
* @param me
|
|
110
|
-
* @param aclURI
|
|
111
|
-
* @param options
|
|
112
|
-
*
|
|
113
|
-
* @returns Serialized ACL
|
|
114
|
-
*/
|
|
115
|
-
function genACLText (
|
|
116
|
-
docURI: string,
|
|
117
|
-
me: NamedNode,
|
|
118
|
-
aclURI: string,
|
|
119
|
-
options: {
|
|
120
|
-
defaultForNew?: boolean,
|
|
121
|
-
public?: []
|
|
122
|
-
} = {}
|
|
123
|
-
): string | undefined {
|
|
124
|
-
const optPublic = options.public || []
|
|
125
|
-
const g = graph()
|
|
126
|
-
const auth = Namespace('http://www.w3.org/ns/auth/acl#')
|
|
127
|
-
let a = g.sym(`${aclURI}#a1`)
|
|
128
|
-
const acl = g.sym(aclURI)
|
|
129
|
-
const doc = g.sym(docURI)
|
|
130
|
-
g.add(a, ns.rdf('type'), auth('Authorization'), acl)
|
|
131
|
-
g.add(a, auth('accessTo'), doc, acl)
|
|
132
|
-
if (options.defaultForNew) {
|
|
133
|
-
g.add(a, auth('default'), doc, acl)
|
|
134
|
-
}
|
|
135
|
-
g.add(a, auth('agent'), me, acl)
|
|
136
|
-
g.add(a, auth('mode'), auth('Read'), acl)
|
|
137
|
-
g.add(a, auth('mode'), auth('Write'), acl)
|
|
138
|
-
g.add(a, auth('mode'), auth('Control'), acl)
|
|
139
|
-
|
|
140
|
-
if (optPublic.length) {
|
|
141
|
-
a = g.sym(`${aclURI}#a2`)
|
|
142
|
-
g.add(a, ns.rdf('type'), auth('Authorization'), acl)
|
|
143
|
-
g.add(a, auth('accessTo'), doc, acl)
|
|
144
|
-
g.add(a, auth('agentClass'), ns.foaf('Agent'), acl)
|
|
145
|
-
for (let p = 0; p < optPublic.length; p++) {
|
|
146
|
-
g.add(a, auth('mode'), auth(optPublic[p]), acl) // Like 'Read' etc
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return serialize(acl, g, aclURI)
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
findAclDocUrl,
|
|
153
|
-
setACLUserPublic,
|
|
154
|
-
genACLText
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { namedNode, NamedNode, sym } from 'rdflib'
|
|
2
|
-
import { appContext, offlineTestID } from './authUtil'
|
|
3
|
-
import * as debug from '../util/debug'
|
|
4
|
-
import { Session } from '@inrupt/solid-client-authn-browser'
|
|
5
|
-
import { AuthenticationContext, AuthnLogic } from '../types'
|
|
6
|
-
|
|
7
|
-
export class SolidAuthnLogic implements AuthnLogic {
|
|
8
|
-
private session: Session
|
|
9
|
-
|
|
10
|
-
constructor(solidAuthSession: Session) {
|
|
11
|
-
this.session = solidAuthSession
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// we created authSession getter because we want to access it as authn.authSession externally
|
|
15
|
-
get authSession():Session { return this.session }
|
|
16
|
-
|
|
17
|
-
currentUser(): NamedNode | null {
|
|
18
|
-
const app = appContext()
|
|
19
|
-
if (app.viewingNoAuthPage) {
|
|
20
|
-
return sym(app.webId)
|
|
21
|
-
}
|
|
22
|
-
if (this && this.session && this.session.info && this.session.info.webId && this.session.info.isLoggedIn) {
|
|
23
|
-
return sym(this.session.info.webId)
|
|
24
|
-
}
|
|
25
|
-
return offlineTestID() // null unless testing
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves currently logged in webId from either
|
|
30
|
-
* defaultTestUser or SolidAuth
|
|
31
|
-
* Also activates a session after login
|
|
32
|
-
* @param [setUserCallback] Optional callback
|
|
33
|
-
* @returns Resolves with webId uri, if no callback provided
|
|
34
|
-
*/
|
|
35
|
-
async checkUser<T> (
|
|
36
|
-
setUserCallback?: (me: NamedNode | null) => T
|
|
37
|
-
): Promise<NamedNode | T | null> {
|
|
38
|
-
// Save hash for "restorePreviousSession"
|
|
39
|
-
const preLoginRedirectHash = new URL(window.location.href).hash
|
|
40
|
-
if (preLoginRedirectHash) {
|
|
41
|
-
window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash)
|
|
42
|
-
}
|
|
43
|
-
this.session.onSessionRestore((url) => {
|
|
44
|
-
if (document.location.toString() !== url) history.replaceState(null, '', url)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Handle a successful authentication redirect
|
|
49
|
-
*/
|
|
50
|
-
const redirectUrl = new URL(window.location.href)
|
|
51
|
-
redirectUrl.hash = ''
|
|
52
|
-
await this.session
|
|
53
|
-
.handleIncomingRedirect({
|
|
54
|
-
restorePreviousSession: true,
|
|
55
|
-
url: redirectUrl.href
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// Check to see if a hash was stored in local storage
|
|
59
|
-
const postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash')
|
|
60
|
-
if (postLoginRedirectHash) {
|
|
61
|
-
const curUrl = new URL(window.location.href)
|
|
62
|
-
if (curUrl.hash !== postLoginRedirectHash) {
|
|
63
|
-
if (history.pushState) {
|
|
64
|
-
// debug.log('Setting window.location.has using pushState')
|
|
65
|
-
history.pushState(null, document.title, postLoginRedirectHash)
|
|
66
|
-
} else {
|
|
67
|
-
// debug.warn('Setting window.location.has using location.hash')
|
|
68
|
-
location.hash = postLoginRedirectHash
|
|
69
|
-
}
|
|
70
|
-
curUrl.hash = postLoginRedirectHash
|
|
71
|
-
}
|
|
72
|
-
// See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
|
|
73
|
-
// window.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
|
|
74
|
-
window.localStorage.setItem('preLoginRedirectHash', '')
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Check to see if already logged in / have the WebID
|
|
78
|
-
let me = offlineTestID()
|
|
79
|
-
if (me) {
|
|
80
|
-
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const webId = this.webIdFromSession(this.session.info)
|
|
84
|
-
if (webId) {
|
|
85
|
-
me = this.saveUser(webId)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (me) {
|
|
89
|
-
debug.log(`(Logged in as ${me} by authentication)`)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Saves `webId` in `context.me`
|
|
97
|
-
* @param webId
|
|
98
|
-
* @param context
|
|
99
|
-
*
|
|
100
|
-
* @returns Returns the WebID, after setting it
|
|
101
|
-
*/
|
|
102
|
-
saveUser (
|
|
103
|
-
webId: NamedNode | string | null,
|
|
104
|
-
context?: AuthenticationContext
|
|
105
|
-
): NamedNode | null {
|
|
106
|
-
let webIdUri: string
|
|
107
|
-
if (webId) {
|
|
108
|
-
webIdUri = (typeof webId === 'string') ? webId : webId.uri
|
|
109
|
-
const me = namedNode(webIdUri)
|
|
110
|
-
if (context) {
|
|
111
|
-
context.me = me
|
|
112
|
-
}
|
|
113
|
-
return me
|
|
114
|
-
}
|
|
115
|
-
return null
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @returns {Promise<string|null>} Resolves with WebID URI or null
|
|
120
|
-
*/
|
|
121
|
-
webIdFromSession (session?: { webId?: string, isLoggedIn: boolean }): string | null {
|
|
122
|
-
const webId = session?.webId && session.isLoggedIn ? session.webId : null
|
|
123
|
-
return webId
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
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
|
-
}
|