Skip to content

Commit 89e718a

Browse files
committed
Implemented schema in SSI API
1 parent c4c9743 commit 89e718a

File tree

9 files changed

+542
-136
lines changed

9 files changed

+542
-136
lines changed

src/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ export default {
546546
icon: "fa fa-id-badge",
547547
})
548548
549+
menu.push({
550+
href: "/studio/ssi/schema/" + this.getSelectedService.appId,
551+
title: "Schemas",
552+
icon: "fa fa-puzzle-piece",
553+
})
554+
549555
menu.push({
550556
href: "/studio/ssi/credit/" + this.getSelectedService.appId,
551557
title: "Credits",

src/assets/css/gblStyle.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ a {
126126
.greyFont {
127127
color: grey
128128
}
129+
130+
.sticky-header {
131+
position: sticky;
132+
top: 0;
133+
}
134+

src/components/element/HfButtons.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
2-
<v-btn class="btn btn-outline-secondary" :class="customClass ? `${customClass}` : 'btn button-theme'"
2+
<v-btn :class="customClass ? `${customClass}` : 'btn button-theme'"
33
:title="title"
4+
depressed
45
@click="emitExecuteAction()"
56
>
67
<span v-if="iconClass"><i :class="iconClass"></i></span>
@@ -21,7 +22,8 @@ export default {
2122
},
2223
customClass:{
2324
type:String,
24-
require:false
25+
require:false,
26+
default: 'btn btn-outline-secondary'
2527
},
2628
title:{
2729
type:String,

src/components/element/hfPopup.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<template>
2-
<b-modal v-model="show" :id="id" hide-footer ref="modal-1" :title="Header" centered>
2+
<b-modal
3+
:size="size"
4+
scrollable
5+
v-model="show"
6+
:id="id"
7+
hide-footer
8+
ref="modal-1"
9+
:title="Header"
10+
centered
11+
header-bg-variant="dark"
12+
header-text-variant='light'
13+
>
314
<slot />
415
</b-modal>
516
</template>
@@ -18,6 +29,10 @@ export default {
1829
},
1930
id: {
2031
type: String,
32+
},
33+
size: {
34+
type: String,
35+
default: ''
2136
}
2237
},
2338
created() {

src/router.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Router from 'vue-router'
33
import fetch from 'node-fetch'
44
import config from './config'
55
import store from './store'
6+
import Schema from './views/playground/Schema.vue'
67
const Home = () => import('./views/Home.vue');
78
const PKIIdLogin = () => import('./views/PKIIdLogin.vue')
89
const MainDashboard = () => import('./views/Dashboard.vue')
@@ -96,6 +97,15 @@ const router = new Router({
9697
title: `${config.app.name} - DIDs`
9798
}
9899
},
100+
{
101+
path: '/studio/ssi/schema/:appId',
102+
name: 'Schemas',
103+
component: Schema,
104+
meta: {
105+
requiresAuth: true,
106+
title: `${config.app.name} - Schema`
107+
}
108+
},
99109
{
100110
path: '/studio/ssi/credit/:appId',
101111
name: 'Credit',

src/store/mainStore.js

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,15 @@ const mainStore = {
208208
setDIDList(state, payload) {
209209
state.didList = payload;
210210
},
211+
setSchemaList(state, payload) {
212+
state.schemaList = payload;
213+
},
211214
insertDIDList(state, payload) {
212215
state.didList.push(payload);
213216
},
217+
insertSchemaList(state, payload) {
218+
state.schemaList.push(payload);
219+
},
214220
updateADID(state, payload) {
215221
let index = state.didList.findIndex(x => x.did === payload.did);
216222
if (index >= 0) {
@@ -219,6 +225,14 @@ const mainStore = {
219225
state.didList.push(payload);
220226
}
221227
},
228+
updateASchema(state, payload) {
229+
let index = state.schemaList.findIndex(x => x.id === payload.id);
230+
if (index >= 0) {
231+
Object.assign(state.schemaList[index], { ...payload });
232+
} else {
233+
state.schemaList.push(payload);
234+
}
235+
},
222236
setAdminMembers: (state, payload) => {
223237
state.adminMembers = payload
224238
},
@@ -1847,6 +1861,180 @@ const mainStore = {
18471861
}
18481862
})
18491863
},
1864+
1865+
1866+
1867+
// schema
1868+
1869+
fetchSchemaList({ commit, getters, dispatch }, payload = {}) {
1870+
return new Promise(function (resolve, reject) {
1871+
{
1872+
let tenantUrl = ''
1873+
let accessToken = ""
1874+
if (payload && payload.tenantUrl && payload.accessToken) {
1875+
tenantUrl = payload.tenantUrl
1876+
accessToken = payload.accessToken
1877+
1878+
} else if (getters.getSelectedService && getters.getSelectedService.tenantUrl && getters.getSelectedService.access_token) {
1879+
tenantUrl = getters.getSelectedService.tenantUrl;
1880+
accessToken = getters.getSelectedService.access_token
1881+
} else {
1882+
return reject(new Error('Tenant url is null or empty, service is not selected'))
1883+
}
1884+
1885+
const url = `${sanitizeUrl(tenantUrl)}/api/v1/schema?page=1&limit=100`;
1886+
const options = {
1887+
method: "GET",
1888+
headers: {
1889+
"Content-Type": "application/json",
1890+
"Authorization": `Bearer ${accessToken}`,
1891+
"Origin": '*'
1892+
}
1893+
}
1894+
fetch(url, {
1895+
headers: options.headers
1896+
})
1897+
.then(response => response.json())
1898+
.then(json => {
1899+
if (json) {
1900+
if (json.data.length > 0) {
1901+
const payload = json.data.map(x => {
1902+
return {
1903+
id: x,
1904+
schemaDocument: {},
1905+
status: ""
1906+
}
1907+
})
1908+
1909+
if (getters.getSelectedService) {
1910+
json.data.map(x => {
1911+
console.log({ x })
1912+
dispatch('resolveSchema', x)
1913+
})
1914+
commit('setSchemaList', payload)
1915+
}
1916+
1917+
resolve(json.data)
1918+
} else {
1919+
resolve([])
1920+
commit('setSchemaList', [])
1921+
}
1922+
} else {
1923+
reject(new Error('Could not fetch DID for this service'))
1924+
}
1925+
1926+
}).catch(e => {
1927+
reject(e)
1928+
})
1929+
}
1930+
})
1931+
1932+
},
1933+
1934+
1935+
async resolveSchema({ commit, getters, }, payload) {
1936+
try {
1937+
let selectedService = {};
1938+
if (getters.getSelectedService.services[0].id === 'SSI_API') {
1939+
selectedService = getters.getSelectedService
1940+
} else if (getters.getSelectedService.services[0].id === 'CAVACH_API') {
1941+
const ssiSserviceId = getters.getSelectedService.dependentServices[0];
1942+
const associatedSSIService = getters.getAppsWithSSIServices.find(
1943+
(x) => x.appId === ssiSserviceId
1944+
);
1945+
selectedService = associatedSSIService
1946+
}
1947+
1948+
if (!selectedService || !selectedService.tenantUrl) {
1949+
throw new Error('Tenant url is null or empty, service is not selected')
1950+
}
1951+
1952+
const url = `${sanitizeUrl(selectedService.tenantUrl)}/api/v1/schema/${payload}`;
1953+
// const url = `http://ent-8ee83cc.localhost:3003/api/v1/schema/${payload}`;
1954+
1955+
const options = {
1956+
method: "GET",
1957+
headers: {
1958+
"Content-Type": "application/json",
1959+
"Authorization": `Bearer ${selectedService.access_token}`,
1960+
"Origin": '*'
1961+
}
1962+
}
1963+
const response = await fetch(url, {
1964+
headers: options.headers
1965+
})
1966+
const json = await response.json()
1967+
1968+
if (json && json.id) {
1969+
const data = {
1970+
id: payload,
1971+
schemaDocument: json,
1972+
status: json.proof && Object.keys(json.proof).length > 0 ? 'Registered' : 'Created',
1973+
}
1974+
commit('updateASchema', data);
1975+
} else {
1976+
const data = {
1977+
id: payload,
1978+
schemaDocument: {},
1979+
status: 'Error',
1980+
error: json?.message[0].data
1981+
}
1982+
commit('updateASchema', data);
1983+
// console.error('Could not fetch Schema for this service id = ' + payload)
1984+
}
1985+
} catch (e) {
1986+
const data = {
1987+
id: payload,
1988+
schemaDocument: {},
1989+
status: 'Error',
1990+
error: e.message
1991+
}
1992+
commit('updateASchema', data);
1993+
console.error(e)
1994+
}
1995+
},
1996+
1997+
1998+
createSchemaForAService({ commit, getters }, payload) {
1999+
return new Promise(function (resolve, reject) {
2000+
{
2001+
// const payload = data.requestBody
2002+
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {
2003+
return reject(new Error('Tenant url is null or empty, service is not selected'))
2004+
}
2005+
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/schema`;
2006+
const options = {
2007+
method: "POST",
2008+
body: JSON.stringify(payload),
2009+
headers: {
2010+
"Content-Type": "application/json",
2011+
"Authorization": `Bearer ${getters.getSelectedService.access_token}`,
2012+
"Origin": '*'
2013+
}
2014+
}
2015+
fetch(url, {
2016+
...options
2017+
})
2018+
.then(response => response.json())
2019+
.then(async json => {
2020+
if (json && json.schemaId) {
2021+
commit('insertSchemaList', {
2022+
id: json.schemaId,
2023+
schemaDocument: {},
2024+
status: 'Please wait...'
2025+
})
2026+
//dispatch('resolveSchema', json.schemaId)
2027+
resolve(json)
2028+
} else {
2029+
reject(new Error('Could not create DID for this service'))
2030+
}
2031+
}).catch(e => {
2032+
reject(e)
2033+
})
2034+
}
2035+
})
2036+
2037+
},
18502038
}
18512039
}
18522040

src/views/Apps.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@
357357
{{ did }}
358358
</option>
359359
</select>
360-
<!-- <input type="text" class="form-control" id="orgDid" v-else v-model="appModel.issuerDid" disabled
361-
aria-describedby="orgNameHelp" /> -->
362360
</div>
363361

364362
<div class="form-group" v-if="
@@ -377,8 +375,7 @@
377375
{{ truncate(vm.id, 40) + ' (' +vm.type+')' }}
378376
</option>
379377
</select>
380-
<!-- <input type="text" class="form-control" id="orgDid" v-else v-model="appModel.issuerDid" disabled
381-
aria-describedby="orgNameHelp" /> -->
378+
382379
</div>
383380

384381
</div>

src/views/playground/DID.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<style scoped>
2-
.sticky-header {
3-
position: sticky;
4-
top: 0;
5-
}
6-
72
.container {
83
width: 80vw;
94
}
@@ -651,7 +646,7 @@ export default {
651646
})
652647
clearInterval(statusCheckInterval)
653648
} else {
654-
this.notifyError('Sorry we could not register your DID, txHash: '+ response.data[0].txnHash)
649+
this.notifyErr('Sorry we could not register your DID, txHash: '+ response.data[0].txnHash)
655650
}
656651
}
657652
if(i == maxrtries){

0 commit comments

Comments
 (0)