Skip to content

Commit c8e73ab

Browse files
committed
Feat: added search bar functionality to store and better error messaging
1 parent 13ab2eb commit c8e73ab

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

demo/data/demo/public/storesite/src/App.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function App() {
2222
const [items, setItems] = useState([] as Item[])
2323
const [verified, setVerified] = useState(false)
2424
const [modalError, setModalError] = useState('')
25+
const [searchTerm, setSearchTerm] = useState('')
2526

2627
useEffect(() => {
2728

@@ -92,7 +93,7 @@ function App() {
9293
<img id='logo' src='store.jpg' alt='Store logo' />
9394
</div>
9495
<div id='searchBarContainer'>
95-
<input id='searchBar' placeholder='What are you looking for?'></input>
96+
<input id='searchBar' placeholder='What are you looking for?' value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)}></input>
9697
</div>
9798
</div>
9899
</nav>
@@ -102,7 +103,12 @@ function App() {
102103
<h2>Dranken</h2>
103104
<Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }} >
104105
{
105-
items.filter(item => { return verified ? true : !item.alcoholic}).map(item => displayItem(item))
106+
items.filter(item => {
107+
if (item.alcoholic && !verified) return false;
108+
if (searchTerm && (!item.name || !item.name.toLowerCase().includes(searchTerm.toLowerCase()))) return false
109+
return true
110+
//return verified ? true : !item.alcoholic
111+
}).map(item => displayItem(item))
106112
}
107113
</Grid>
108114
</div>

demo/data/demo/public/storesite/src/flow.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,32 @@ export const terms = {
3131
}
3232

3333
export async function retrieveData(webId: string): Promise<string> {
34+
35+
let profileText, viewIndex, views;
36+
let webIdData: Store;
37+
38+
try {
39+
profileText = await (await fetch(webId)).text()
40+
41+
webIdData = new Store(parser.parse(profileText));
42+
viewIndex = webIdData.getObjects(webId, terms.solid.viewIndex, null)[0]?.value;
43+
views = Object.fromEntries(webIdData.getObjects(viewIndex, terms.solid.entry, null).map(entry => {
44+
const filter = webIdData.getObjects(entry, terms.solid.filter, null)[0]?.value;
45+
const location = webIdData.getObjects(entry, terms.solid.location, null)[0]?.value;
46+
return [filter, location];
47+
}));
48+
} catch (e: any) {
49+
log(e)
50+
throw new Error('Could not read WebID information')
51+
}
3452

35-
log(`Alright, so, for the demo ...`);
36-
37-
log(`Ruben V., a.k.a. <${terms.agents.ruben}>, has some private data in <http://localhost:3000/ruben/private/data>.`);
53+
if (webIdData && webIdData.getQuads(null, "http://xmlns.com/foaf/0.1/age", null, null).length) {
54+
// Valid age found, we can return the profile document
55+
return profileText
3856

39-
log(`Of course, he does not want everyone to be able to see all of his private data when they need just one aspect of it. Therefore, Ruben has installed two Views on his data, based on SPARQL filters from a public Catalog. (When and how this is done is out-of-scope for now.)`);
57+
}
4058

41-
const webIdData = new Store(parser.parse(await (await fetch(terms.agents.ruben)).text()));
42-
const viewIndex = webIdData.getObjects(terms.agents.ruben, terms.solid.viewIndex, null)[0].value;
43-
const views = Object.fromEntries(webIdData.getObjects(viewIndex, terms.solid.entry, null).map(entry => {
44-
const filter = webIdData.getObjects(entry, terms.solid.filter, null)[0].value;
45-
const location = webIdData.getObjects(entry, terms.solid.location, null)[0].value;
46-
return [filter, location];
47-
}));
59+
if (!views) throw new Error('Could not request access to required data for verification');
4860

4961
log(`Discovery of views is currently a very crude mechanism based on a public index in the WebID document. (A cleaner mechanism using the UMA server as central hub is being devised.) Using the discovery mechanism, we find the following views on Ruben's private data.`)
5062

@@ -55,7 +67,10 @@ export async function retrieveData(webId: string): Promise<string> {
5567

5668
log(`Access to Ruben's data is based on policies he manages through his Authz Companion app, and which are stored in <${policyContainer}>. (This is, of course, not publicly known.)`);
5769

58-
const umaServer = webIdData.getObjects(terms.agents.ruben, terms.solid.umaServer, null)[0].value;
70+
const umaServer = webIdData.getObjects(webId, terms.solid.umaServer, null)[0]?.value;
71+
72+
if (!umaServer) throw new Error('Could not request access to required data for verification');
73+
5974
const configUrl = new URL('.well-known/uma2-configuration', umaServer);
6075
const umaConfig = await (await fetch(configUrl)).json();
6176
const tokenEndpoint = umaConfig.token_endpoint;
@@ -87,7 +102,7 @@ export async function retrieveData(webId: string): Promise<string> {
87102
try {
88103
const { ticket, required_claims } = await tokenEndpointResponse.json();
89104
if (!ticket || !required_claims) { // There is no negotiation
90-
throw new Error('Could not negotiate data retrieval for verification.')
105+
throw new Error('Notification sent. Check your companion app.')
91106
}
92107

93108
log(`Based on the policy, the UMA server requests the following claims from the agent:`);

0 commit comments

Comments
 (0)