mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Add MetaData Edit & Retire (delete)
This commit is contained in:
parent
d0d7ee71cc
commit
9b04e9e413
@ -1,8 +1,10 @@
|
|||||||
import { URL } from 'whatwg-url'
|
import { URL } from 'whatwg-url'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import DID from '../ocean/DID'
|
import DID from '../ocean/DID'
|
||||||
|
import { EditableMetaData } from '../ddo/MetaData'
|
||||||
import { Logger } from '../utils'
|
import { Logger } from '../utils'
|
||||||
import { WebServiceConnector } from '../ocean/utils/WebServiceConnector'
|
import { WebServiceConnector } from '../ocean/utils/WebServiceConnector'
|
||||||
|
import { escrowAccessServiceAgreementTemplate } from '../keeper/contracts/templates/EscrowAccess.serviceAgreementTemplate'
|
||||||
|
|
||||||
const apiPath = '/api/v1/aquarius/assets/ddo'
|
const apiPath = '/api/v1/aquarius/assets/ddo'
|
||||||
|
|
||||||
@ -260,6 +262,95 @@ export class Aquarius {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async editMetadata(
|
||||||
|
did: DID | string,
|
||||||
|
newMetadata: EditableMetaData,
|
||||||
|
updated: string,
|
||||||
|
signature: string
|
||||||
|
): Promise<string> {
|
||||||
|
did = did && DID.parse(did)
|
||||||
|
const fullUrl = `${this.url}${apiPath}/metadata/update/${did.getDid()}`
|
||||||
|
let data = Object()
|
||||||
|
if (newMetadata.description != null)
|
||||||
|
data.description = newMetadata.description
|
||||||
|
if (newMetadata.title != null)
|
||||||
|
data.title = newMetadata.title
|
||||||
|
if (newMetadata.servicePrices != null)
|
||||||
|
data.servicePrices = newMetadata.servicePrices
|
||||||
|
if (newMetadata.links != null) {
|
||||||
|
data.links = []
|
||||||
|
for (const [name, url] of Object.entries(newMetadata.links)) {
|
||||||
|
let asample = Object()
|
||||||
|
asample.name = name
|
||||||
|
asample.url = url
|
||||||
|
asample.type = 'sample'
|
||||||
|
data.links.push(asample)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.updated = updated
|
||||||
|
data.signature = signature
|
||||||
|
const result = await this.fetch
|
||||||
|
.put(
|
||||||
|
fullUrl,
|
||||||
|
JSON.stringify(data)
|
||||||
|
)
|
||||||
|
.then((response: any) => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.text
|
||||||
|
}
|
||||||
|
this.logger.log(
|
||||||
|
'transferownership failed:',
|
||||||
|
response.status,
|
||||||
|
response.statusText
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
.catch(error => {
|
||||||
|
this.logger.error('Error transfering ownership metadata: ', error)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retire(
|
||||||
|
did: DID | string,
|
||||||
|
updated: string,
|
||||||
|
signature: string
|
||||||
|
): Promise<string> {
|
||||||
|
did = did && DID.parse(did)
|
||||||
|
const fullUrl = `${this.url}${apiPath}/${did.getDid()}`
|
||||||
|
const result = await this.fetch
|
||||||
|
.delete(
|
||||||
|
fullUrl,
|
||||||
|
JSON.stringify({
|
||||||
|
signature: signature,
|
||||||
|
updated: updated
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then((response: any) => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.text
|
||||||
|
}
|
||||||
|
this.logger.log(
|
||||||
|
'transferownership failed:',
|
||||||
|
response.status,
|
||||||
|
response.statusText
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
.catch(error => {
|
||||||
|
this.logger.error('Error transfering ownership metadata: ', error)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public getServiceEndpoint(did: DID) {
|
public getServiceEndpoint(did: DID) {
|
||||||
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
|
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
|
||||||
}
|
}
|
||||||
|
@ -276,3 +276,15 @@ export interface MetaData {
|
|||||||
additionalInformation?: AdditionalInformation
|
additionalInformation?: AdditionalInformation
|
||||||
curation?: Curation
|
curation?: Curation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServicePrices{
|
||||||
|
serviceIndex: number,
|
||||||
|
price: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EditableMetaData{
|
||||||
|
description?: string,
|
||||||
|
title?: string,
|
||||||
|
links?: { [name: string]: string }[],
|
||||||
|
servicePrices?: ServicePrices[]
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { SearchQuery } from '../aquarius/Aquarius'
|
import { SearchQuery } from '../aquarius/Aquarius'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import { MetaData } from '../ddo/MetaData'
|
import { MetaData, EditableMetaData } from '../ddo/MetaData'
|
||||||
import { Service, ServiceAccess } from '../ddo/Service'
|
import { Service, ServiceAccess } from '../ddo/Service'
|
||||||
import Account from './Account'
|
import Account from './Account'
|
||||||
import DID from './DID'
|
import DID from './DID'
|
||||||
@ -384,6 +384,45 @@ export class OceanAssets extends Instantiable {
|
|||||||
return txReceipt
|
return txReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async editMetadata(
|
||||||
|
did: string,
|
||||||
|
newMetadata: EditableMetaData,
|
||||||
|
account: Account
|
||||||
|
): Promise<string> {
|
||||||
|
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||||
|
// get a signature
|
||||||
|
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||||
|
oldDdo.updated,
|
||||||
|
account
|
||||||
|
)
|
||||||
|
let result=null
|
||||||
|
if (signature != null)
|
||||||
|
result=await this.ocean.aquarius.editMetadata(
|
||||||
|
did,
|
||||||
|
newMetadata,
|
||||||
|
oldDdo.updated,
|
||||||
|
signature
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retire(
|
||||||
|
did: string,
|
||||||
|
account: Account
|
||||||
|
): Promise<string> {
|
||||||
|
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||||
|
// get a signature
|
||||||
|
const signature = await this.ocean.utils.signature.signForAquarius(
|
||||||
|
oldDdo.updated,
|
||||||
|
account
|
||||||
|
)
|
||||||
|
let result=null
|
||||||
|
if (signature != null)
|
||||||
|
result = await this.ocean.aquarius.retire(did, oldDdo.updated, signature)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the assets of a consumer.
|
* Returns the assets of a consumer.
|
||||||
* @param {string} consumer Consumer address.
|
* @param {string} consumer Consumer address.
|
||||||
|
@ -43,13 +43,25 @@ export class WebServiceConnector {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public delete(url: string): Promise<Response> {
|
public delete(url: string, payload?: BodyInit): Promise<Response> {
|
||||||
return this.fetch(url, {
|
if (payload != null) {
|
||||||
method: 'DELETE',
|
return this.fetch(url, {
|
||||||
headers: {
|
method: 'DELETE',
|
||||||
'Content-type': 'application/json'
|
body: payload,
|
||||||
}
|
headers: {
|
||||||
})
|
'Content-type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.fetch(url, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async downloadFile(
|
public async downloadFile(
|
||||||
|
Loading…
Reference in New Issue
Block a user