mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge pull request #402 from oceanprotocol/revert-396-feature/metadata_edit_and_delete
Revert "Feature/metadata edit and delete"
This commit is contained in:
commit
d1ceabe6a2
@ -1,7 +1,6 @@
|
|||||||
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'
|
||||||
|
|
||||||
@ -261,90 +260,6 @@ export class Aquarius {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit Metadata for a DDO.
|
|
||||||
* @param {did} string DID.
|
|
||||||
* @param {newMetadata} EditableMetaData Metadata fields & new values.
|
|
||||||
* @param {String} updated Updated field of the DDO
|
|
||||||
* @param {String} signature Signature using updated field to verify that the consumer has rights
|
|
||||||
* @return {Promise<String>} 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/${did.getDid()}`
|
|
||||||
const 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 = newMetadata.links
|
|
||||||
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(
|
|
||||||
'editMetaData failed:',
|
|
||||||
response.status,
|
|
||||||
response.statusText
|
|
||||||
)
|
|
||||||
return null
|
|
||||||
})
|
|
||||||
|
|
||||||
.catch(error => {
|
|
||||||
this.logger.error('Error transfering ownership metadata: ', error)
|
|
||||||
return null
|
|
||||||
})
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retire a DDO (Delete)
|
|
||||||
* @param {DID | string} did DID of the asset to update.
|
|
||||||
* @param {String} updated Updated field of the DDO
|
|
||||||
* @param {String} signature Signature using updated field to verify that the consumer has rights
|
|
||||||
* @return {Promise<String>} 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('retire 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,21 +276,3 @@ export interface MetaData {
|
|||||||
additionalInformation?: AdditionalInformation
|
additionalInformation?: AdditionalInformation
|
||||||
curation?: Curation
|
curation?: Curation
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServicePrices {
|
|
||||||
serviceIndex: number
|
|
||||||
price: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditableMetaDataLinks {
|
|
||||||
name: string
|
|
||||||
url: string
|
|
||||||
type: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditableMetaData {
|
|
||||||
description?: string
|
|
||||||
title?: string
|
|
||||||
links?: EditableMetaDataLinks[]
|
|
||||||
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, EditableMetaData } from '../ddo/MetaData'
|
import { MetaData } 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,55 +384,6 @@ export class OceanAssets extends Instantiable {
|
|||||||
return txReceipt
|
return txReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit Metadata for a DDO.
|
|
||||||
* @param {did} string DID.
|
|
||||||
* @param {newMetadata} EditableMetaData Metadata fields & new values.
|
|
||||||
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
|
|
||||||
* @return {Promise<string>}
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retire a DDO (Delete)
|
|
||||||
* @param {did} string DID.
|
|
||||||
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
|
|
||||||
* @return {Promise<string>}
|
|
||||||
*/
|
|
||||||
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,23 +43,13 @@ export class WebServiceConnector {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public delete(url: string, payload?: BodyInit): Promise<Response> {
|
public delete(url: string): Promise<Response> {
|
||||||
if (payload != null) {
|
return this.fetch(url, {
|
||||||
return this.fetch(url, {
|
method: 'DELETE',
|
||||||
method: 'DELETE',
|
headers: {
|
||||||
body: payload,
|
'Content-type': 'application/json'
|
||||||
headers: {
|
}
|
||||||
'Content-type': 'application/json'
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return this.fetch(url, {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'Content-type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async downloadFile(
|
public async downloadFile(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
import { getMetadata } from '../utils'
|
import { getMetadata } from '../utils'
|
||||||
import { Ocean, Account, EditableMetaData } from '../../../src' // @oceanprotocol/squid
|
import { Ocean, Account } from '../../../src' // @oceanprotocol/squid
|
||||||
|
|
||||||
describe('Asset Owners', () => {
|
describe('Asset Owners', () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
@ -80,8 +80,8 @@ describe('Asset Owners', () => {
|
|||||||
const { length: finalLength1 } = await ocean.assets.consumerAssets(
|
const { length: finalLength1 } = await ocean.assets.consumerAssets(
|
||||||
account2.getId()
|
account2.getId()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.equal(finalLength1 - initialLength, 0)
|
assert.equal(finalLength1 - initialLength, 0)
|
||||||
|
|
||||||
// Granting access
|
// Granting access
|
||||||
try {
|
try {
|
||||||
await account2.requestTokens(
|
await account2.requestTokens(
|
||||||
@ -111,74 +111,4 @@ describe('Asset Owners', () => {
|
|||||||
const aquariusOwner = await ocean.assets.owner(id)
|
const aquariusOwner = await ocean.assets.owner(id)
|
||||||
assert.equal(aquariusOwner, account2.getId())
|
assert.equal(aquariusOwner, account2.getId())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should be able to update metadata', async () => {
|
|
||||||
const { id } = await ocean.assets.create(metadata as any, account1)
|
|
||||||
const links = [
|
|
||||||
{
|
|
||||||
name: 'Sample1',
|
|
||||||
url: 'http://www.example.com',
|
|
||||||
type: 'sample'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Sample2',
|
|
||||||
url: 'http://www.example.net',
|
|
||||||
type: 'sample'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const newPrices = [
|
|
||||||
{
|
|
||||||
serviceIndex: 0,
|
|
||||||
price: '31000000000000000000'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
serviceIndex: 2,
|
|
||||||
price: '31000000000000000000'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const newMetaData = {
|
|
||||||
title: 'New title',
|
|
||||||
description: 'New description',
|
|
||||||
links: links,
|
|
||||||
servicePrices: newPrices
|
|
||||||
}
|
|
||||||
await ocean.assets.editMetadata(id, newMetaData, account1)
|
|
||||||
|
|
||||||
const newDDO = await ocean.assets.resolve(id)
|
|
||||||
|
|
||||||
assert.equal(newDDO.service[0].attributes.main.name, 'New title')
|
|
||||||
assert.equal(
|
|
||||||
newDDO.service[0].attributes.additionalInformation.description,
|
|
||||||
'New description'
|
|
||||||
)
|
|
||||||
assert.equal(newDDO.service[0].attributes.main.price, '31000000000000000000')
|
|
||||||
assert.equal(newDDO.service[2].attributes.main.price, '31000000000000000000')
|
|
||||||
assert.equal(
|
|
||||||
newDDO.service[0].attributes.additionalInformation.links[0].name,
|
|
||||||
'Sample1'
|
|
||||||
)
|
|
||||||
assert.equal(
|
|
||||||
newDDO.service[0].attributes.additionalInformation.links[0].url,
|
|
||||||
'http://www.example.com'
|
|
||||||
)
|
|
||||||
assert.equal(
|
|
||||||
newDDO.service[0].attributes.additionalInformation.links[1].name,
|
|
||||||
'Sample2'
|
|
||||||
)
|
|
||||||
assert.equal(
|
|
||||||
newDDO.service[0].attributes.additionalInformation.links[1].url,
|
|
||||||
'http://www.example.net'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should be able to retire metadata', async () => {
|
|
||||||
const { id } = await ocean.assets.create(metadata as any, account1)
|
|
||||||
|
|
||||||
await ocean.assets.retire(id, account1)
|
|
||||||
|
|
||||||
const newDDO = await ocean.assets.resolve(id)
|
|
||||||
|
|
||||||
assert.equal(newDDO, null)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user