diff --git a/CHANGELOG.md b/CHANGELOG.md index f6fa804a0..5d2f20a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2231,7 +2231,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 2 May 2022 -- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248) +- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248) - Adding v0.19.21 Changelog updates [`c93cdc5`](https://github.com/nevermined-io/sdk-js/commit/c93cdc55f139a43db4130ccb0f80924d2645a931) #### [v0.19.21](https://github.com/nevermined-io/sdk-js/compare/v0.19.20...v0.19.21) @@ -2494,7 +2494,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 18 January 2022 -- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186) +- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186) - [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183) - Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177) - Adding v0.17.2 Changelog updates [`5eddda4`](https://github.com/nevermined-io/sdk-js/commit/5eddda43954e013e6e6f7344c9a877d801aacb5c) @@ -3000,7 +3000,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Feature/sync develop [`#268`](https://github.com/nevermined-io/sdk-js/pull/268) - Quick fix for non-eip1559 networks [`#266`](https://github.com/nevermined-io/sdk-js/pull/266) - integrate Permissions and refactor search query [`#264`](https://github.com/nevermined-io/sdk-js/pull/264) -- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248) +- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248) - Get the keeper version from the artifacts instead of package version [`#244`](https://github.com/nevermined-io/sdk-js/pull/244) - replace `metadata-api` url by `marketplace-api` and sort type [`#243`](https://github.com/nevermined-io/sdk-js/pull/243) - fixing issues with BigNumbers [`#246`](https://github.com/nevermined-io/sdk-js/pull/246) @@ -3039,7 +3039,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Feature/190 add did to sec markets [`#191`](https://github.com/nevermined-io/sdk-js/pull/191) - Adding utility methods for getting nft token uri [`#189`](https://github.com/nevermined-io/sdk-js/pull/189) - Lint ... [`#187`](https://github.com/nevermined-io/sdk-js/pull/187) -- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186) +- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186) - [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183) - Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177) - Correct typo in route [`#184`](https://github.com/nevermined-io/sdk-js/pull/184) diff --git a/integration/external/Zerodev.test.ts b/integration/external/Zerodev.test.ts index a5b8eff23..f980fc8bf 100644 --- a/integration/external/Zerodev.test.ts +++ b/integration/external/Zerodev.test.ts @@ -288,6 +288,8 @@ describe('Nevermined sdk with zerodev', () => { contractAddress, // DIDRegistry address '0x1c52ed414EDd1bCC20Ea670d42289e8bFC03C095', // Sales Template address '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d', // ERC20 address + '0x1bcA156f746C6Eb8b18d61654293e2Fc5b653fF5', // NFT1155 address + '0x1bcA156f746C6Eb8b18d61654293e2Fc5b653fF5', ) const sessionKey = await createSessionKey(owner, publicClient, permissions) assert.isDefined(sessionKey) diff --git a/integration/nevermined/SearchAsset.test.ts b/integration/nevermined/SearchAsset.test.ts index 929b394a9..d99c5d01d 100644 --- a/integration/nevermined/SearchAsset.test.ts +++ b/integration/nevermined/SearchAsset.test.ts @@ -105,4 +105,21 @@ describe('Search Asset', () => { nevermined.search.byDID(ddo.id).then((ddo) => assert.instanceOf(ddo, DDO)) }) }) + + it('should be able to get assets by type', async () => { + const { results: ddos } = await neverminedOffline.search.byType('dataset') + assert.equal(ddos.length, 5) + + const { results: ddosWithTextFilter } = await neverminedOffline.search.byType( + 'dataset', + 'TestAsset', + ) + assert.equal(ddosWithTextFilter.length, 4) + + const { results: ddosServices } = await neverminedOffline.search.byType('service') + assert.equal(ddosServices.length, 2) + + const { results: agent } = await neverminedOffline.search.byType('agent') + assert.equal(agent.length, 0) + }) }) diff --git a/package.json b/package.json index 066fa95a1..43964d291 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/sdk", - "version": "3.0.27", + "version": "3.0.28", "description": "Javascript SDK for connecting with Nevermined Data Platform ", "main": "./dist/node/sdk.js", "typings": "./dist/node/sdk.d.ts", diff --git a/scripts/download-artifacts.sh b/scripts/download-artifacts.sh index dd5022225..ddab8de80 100755 --- a/scripts/download-artifacts.sh +++ b/scripts/download-artifacts.sh @@ -20,7 +20,7 @@ fi REPO_URL=https://artifacts.nevermined.network declare -A NETWORKS_MAP -NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["optimism"]="10" ["kovan"]="42" ["gnosis"]="100" ["matic"]="137" ["base"]="8453" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" ["arbitrum-one"]="42161" ["arbitrum-goerli"]="421613" ["arbitrum-sepolia"]="421614" ) +NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["optimism"]="10" ["kovan"]="42" ["gnosis"]="100" ["matic"]="137" ["peaq"]="3338" ["base"]="8453" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" ["arbitrum-one"]="42161" ["arbitrum-goerli"]="421613" ["arbitrum-sepolia"]="421614" ) SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) UNPACK_DIR="$SCRIPT_DIR/../artifacts" diff --git a/src/nevermined/api/RegistryBaseApi.ts b/src/nevermined/api/RegistryBaseApi.ts index ee78dd0e1..479035009 100644 --- a/src/nevermined/api/RegistryBaseApi.ts +++ b/src/nevermined/api/RegistryBaseApi.ts @@ -155,7 +155,8 @@ export abstract class RegistryBaseApi extends Instantiable { if ( assetAttributes.metadata.main.type === 'service' || - assetAttributes.metadata.main.type === 'assistant' + assetAttributes.metadata.main.type === 'assistant' || + assetAttributes.metadata.main.type === 'agent' ) { const encryptedServiceAttributesResponse = await this.nevermined.services.node.encrypt( ddo.id, diff --git a/src/nevermined/api/SearchApi.ts b/src/nevermined/api/SearchApi.ts index e375920e9..8aa7fbe89 100644 --- a/src/nevermined/api/SearchApi.ts +++ b/src/nevermined/api/SearchApi.ts @@ -2,7 +2,7 @@ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract' import { DDO } from '../../ddo/DDO' import { NvmAccount } from '../../models/NvmAccount' import { QueryResult } from '../../services/metadata/MetadataService' -import { ServiceType, Service } from '../../types/DDOTypes' +import { MetaDataMain, Service, ServiceType } from '../../types/DDOTypes' import { EventOptions } from '../../types/EventTypes' import { NeverminedNFT1155Type, NeverminedNFT721Type } from '../../types/GeneralTypes' import { SearchQuery } from '../../types/MetadataTypes' @@ -787,4 +787,70 @@ export class SearchApi extends Instantiable { appId, ) } + + public async byType( + assetType: MetaDataMain['type'] = 'agent', + text?: string, + offset = 100, + page = 1, + appId?: string, + ) { + const mustArray: unknown[] = [] + mustArray.push(assetTypeFilter(assetType)) + if (text) { + mustArray.push(textFilter(text)) + } + + return this.query({ + query: { + bool: { + must: mustArray, + }, + }, + sort: { + created: 'desc', + }, + page: page, + offset: offset, + appId, + }) + } +} + +export const assetTypeFilter = (assetType: MetaDataMain['type']) => { + const filter: { [field: string]: unknown }[] = [ + { + match: { 'service.type': 'metadata' }, + }, + { + match: { + 'service.attributes.main.nftType': 'nft1155-credit', + }, + }, + ] + filter.push({ + match: { + 'service.attributes.main.type': assetType, + }, + }) + + return { + nested: { + path: ['service'], + query: { + bool: { + filter, + }, + }, + }, + } } + +export const textFilter = (searchInputText = '') => ({ + nested: { + path: ['service'], + query: { + query_string: { query: `*${searchInputText}*`, fields: ['service.attributes.main.name'] }, + }, + }, +}) diff --git a/src/types/DDOTypes.ts b/src/types/DDOTypes.ts index 70af27a50..111b90704 100644 --- a/src/types/DDOTypes.ts +++ b/src/types/DDOTypes.ts @@ -250,7 +250,7 @@ export interface MetaDataMain { /** * Type of the Asset. Helps to filter by the type of asset, - * initially ("dataset", "algorithm", "compute", "workflow", "model", "file", "subscription", "other"). + * initially ("dataset", "algorithm", "compute", "workflow", "model", "file", "subscription", "other", "agent"). * @example "dataset" */ type: @@ -264,6 +264,7 @@ export interface MetaDataMain { | 'file' | 'other' | 'assistant' + | 'agent' /** * Sub type asssociated to the main type of the asset. This subtype is open so final users are not restricted to use anything they need. diff --git a/src/utils/Network.ts b/src/utils/Network.ts index c89ff5f40..2595d43b7 100644 --- a/src/utils/Network.ts +++ b/src/utils/Network.ts @@ -44,6 +44,8 @@ export async function getNetworkName(networkId: number): Promise { return 'geth-localnet' case 3141: return 'hyperspace' + case 3338: + return 'peaq' case 8453: return 'base' case 10200: @@ -108,6 +110,8 @@ export function isTestnet(networkId: number): boolean { return true case 3141: return true + case 3338: + return false case 8453: return false case 10200: @@ -155,6 +159,21 @@ export function getChain(networkId: number | undefined): Chain { return gnosis case 137: return polygon + case 3338: + return defineChain({ + id: networkId, + name: 'peaq-network', + nativeCurrency: { + name: 'Peaq', + symbol: 'PEAQ', + decimals: 18, + }, + rpcUrls: { + default: { + http: ['https://evm.peaq.network'], + }, + }, + }) case 8453: return base as Chain case 42161: