@@ -208,9 +208,15 @@ const mainStore = {
208
208
setDIDList ( state , payload ) {
209
209
state . didList = payload ;
210
210
} ,
211
+ setSchemaList ( state , payload ) {
212
+ state . schemaList = payload ;
213
+ } ,
211
214
insertDIDList ( state , payload ) {
212
215
state . didList . push ( payload ) ;
213
216
} ,
217
+ insertSchemaList ( state , payload ) {
218
+ state . schemaList . push ( payload ) ;
219
+ } ,
214
220
updateADID ( state , payload ) {
215
221
let index = state . didList . findIndex ( x => x . did === payload . did ) ;
216
222
if ( index >= 0 ) {
@@ -219,6 +225,14 @@ const mainStore = {
219
225
state . didList . push ( payload ) ;
220
226
}
221
227
} ,
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
+ } ,
222
236
setAdminMembers : ( state , payload ) => {
223
237
state . adminMembers = payload
224
238
} ,
@@ -1847,6 +1861,180 @@ const mainStore = {
1847
1861
}
1848
1862
} )
1849
1863
} ,
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
+ } ,
1850
2038
}
1851
2039
}
1852
2040
0 commit comments