Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v1.3.3](https://github.com/nevermined-io/components-catalog/compare/v1.3.2...v1.3.3)

> 21 April 2023

- Update sdk 1.3.5 [`#281`](https://github.com/nevermined-io/components-catalog/pull/281)
- Adding v1.3.2 Changelog updates [`9686495`](https://github.com/nevermined-io/components-catalog/commit/9686495f8e2d3b8cfd116b170151043c7a57c239)
- update sdk to the version 1.3.5 [`173b139`](https://github.com/nevermined-io/components-catalog/commit/173b139792db37e85c273cacf9ef9b209c323bb3)
- update sdk-dtp in the correct version [`cb32eb0`](https://github.com/nevermined-io/components-catalog/commit/cb32eb00280cc7121dceddf5103050c4007e2fb3)

#### [v1.3.2](https://github.com/nevermined-io/components-catalog/compare/v1.3.1...v1.3.2)

> 11 April 2023
Expand Down
2 changes: 1 addition & 1 deletion catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/catalog",
"version": "1.3.3",
"version": "1.3.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
Expand Down
45 changes: 24 additions & 21 deletions catalog/src/catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
BigNumber,
SubscriptionsAndServicesDDOs,
OrderProgressStep,
SubscriptionsAndDatasetsDDOs
SubscriptionsAndDatasetsDDOs,
SearchOptions
} from './types'
import {
conductOrder,
Expand Down Expand Up @@ -210,85 +211,87 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
}
},

getPublishedSubscriptions: async (): Promise<DDO[]> => {
getPublishedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsCreated(account)
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return query.results
} catch {
verbose && Logger.error(error)
return []
}
},

getPublishedSubscriptionsAndServices: async (): Promise<SubscriptionsAndServicesDDOs[]> => {
getPublishedSubscriptionsAndServices: async (searchOptions?: SearchOptions
): Promise<SubscriptionsAndServicesDDOs[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsCreated(account)
return getSubscriptionsAndServices(query.results, sdk)
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return getSubscriptionsAndServices(query.results, sdk, searchOptions)
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getPublishedSubscriptionsAndDatasets: async (): Promise<SubscriptionsAndDatasetsDDOs[]> => {
getPublishedSubscriptionsAndDatasets: async (searchOptions?: SearchOptions): Promise<SubscriptionsAndDatasetsDDOs[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsCreated(account)
return getSubscriptionsAndDatasets(query.results, sdk)
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return getSubscriptionsAndDatasets(query.results, sdk, searchOptions)
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getPurchasedSubscriptions: async (): Promise<DDO[]> => {
getPurchasedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsPurchased(account)
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return query.results
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getPurchasedSubscriptionsAndServices: async (): Promise<SubscriptionsAndServicesDDOs[]> => {
getPurchasedSubscriptionsAndServices: async (searchOptions?: SearchOptions
): Promise<SubscriptionsAndServicesDDOs[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsPurchased(account)
return getSubscriptionsAndServices(query.results, sdk)
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return getSubscriptionsAndServices(query.results, sdk, searchOptions)
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getPurchasedSubscriptionsAndDatasets: async (): Promise<SubscriptionsAndDatasetsDDOs[]> => {
getPurchasedSubscriptionsAndDatasets: async (searchOptions?: SearchOptions): Promise<SubscriptionsAndDatasetsDDOs[]> => {
try {
const account = await getCurrentAccount(sdk)
const query = await sdk.search.subscriptionsPurchased(account)
return getSubscriptionsAndDatasets(query.results, sdk)
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return getSubscriptionsAndDatasets(query.results, sdk, searchOptions)
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getAssociatedServices: async (did: string): Promise<DDO[]> => {
getAssociatedServices: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
try {
const query = await sdk.search.servicesBySubscription(did)
const query = await sdk.search.servicesBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return query.results
} catch (error) {
verbose && Logger.error(error)
return []
}
},

getAssociatedDatasets: async (did: string): Promise<DDO[]> => {
getAssociatedDatasets: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
try {
const query = await sdk.search.datasetsBySubscription(did)
const query = await sdk.search.datasetsBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
return query.results
} catch (error) {
verbose && Logger.error(error)
Expand Down
51 changes: 38 additions & 13 deletions catalog/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ export interface GenericOutput<T, E> {
success: boolean
}

/**
* Query search options
*/
export interface SearchOptions {
/** Number of results per page */
offset?: number
/** Number of page */
page?: number
/** result order */
sort?: 'asc' | 'desc'
/** If app to search have an id */
appId?: string
}

/** Id of the asset */
export type DID = string

Expand Down Expand Up @@ -405,51 +419,62 @@ export interface AccountModule {
/**
* Get only published Subscriptions
* @param address the address which published the subscription returned
* @param searchOptions options for customize result
* @returns published subscriptions
*/
getPublishedSubscriptions: (address: string) => Promise<DDO[]>
getPublishedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
/**
* Get all the services associated a subscription
* @param address the subscription address
* @param searchOptions options for customize result
* @returns associated services to subscriptions
*/
getAssociatedServices: (did: string) => Promise<DDO[]>
getAssociatedServices: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
/**
* Get all the datasets associated to a subscription
* @param address the subscription address
* @param searchOptions options for customize result
* @returns associated datasets to subscriptions
*/
getAssociatedDatasets: (did: string) => Promise<DDO[]>
getAssociatedDatasets: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
/**
* Get all the published subscriptions and services associated from the wallet address passed
* @param did the did of the subscription
* @param searchOptions options for customize result
* @returns published subscriptions and service
*/
getPublishedSubscriptionsAndServices: (address: string) => Promise<SubscriptionsAndServicesDDOs[]>
getPublishedSubscriptionsAndServices: (
searchOptions?: SearchOptions,
) => Promise<SubscriptionsAndServicesDDOs[]>
/**
* Get all the published subscriptions and datasets associated from the wallet address passed
* @param did the did of the subscription
* @param searchOptions options for customize result
* @returns published subscriptions and its datasets
*/
getPublishedSubscriptionsAndDatasets: (address: string) => Promise<SubscriptionsAndDatasetsDDOs[]>
getPublishedSubscriptionsAndDatasets: (
searchOptions?: SearchOptions,
) => Promise<SubscriptionsAndDatasetsDDOs[]>
/**
* Get only purchased Subscriptions
* @param address the address which purchased the subscription returned
* @param searchOptions options for customize result
* @returns purchased subscriptions
*/
getPurchasedSubscriptions: (address: string) => Promise<DDO[]>
getPurchasedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
/**
* Get all the purchased subscriptions and services associated from the wallet address passed
* @param address the address which published the subscription returned
* @param searchOptions options for customize result
* @returns purchased subscriptions and services
*/
getPurchasedSubscriptionsAndServices: (address: string) => Promise<SubscriptionsAndServicesDDOs[]>
getPurchasedSubscriptionsAndServices: (
searchOptions?: SearchOptions,
) => Promise<SubscriptionsAndServicesDDOs[]>
/**
* Get all the purchased subscriptions and datasets associated from the wallet address passed
* @param did the did of the subscription
* @param searchOptions options for customize result
* @returns purchased subscriptions and its datasets
*/
getPurchasedSubscriptionsAndDatasets: (address: string) => Promise<SubscriptionsAndDatasetsDDOs[]>
getPurchasedSubscriptionsAndDatasets: (
searchOptions?: SearchOptions,
) => Promise<SubscriptionsAndDatasetsDDOs[]>
/**
* Generate a token for authentication in the Marketplace API
* @returns The new generated token
Expand Down
29 changes: 25 additions & 4 deletions catalog/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ERCType,
MarketplaceAPIToken,
NeverminedOptions,
SearchOptions,
SubscribablePromise,
} from '../types'
import axios from 'axios'
Expand Down Expand Up @@ -173,10 +174,20 @@ export const handlePostRequest = async (url: string, formData: FormData, retries
}
}

export const getSubscriptionsAndServices = async (subscriptionsDDOs: DDO[], sdk: Nevermined) => {
export const getSubscriptionsAndServices = async (
subscriptionsDDOs: DDO[],
sdk: Nevermined,
searchOptions?: SearchOptions,
) => {
return Promise.all(
subscriptionsDDOs.map(async (ddo) => {
const query = await sdk.search.servicesBySubscription(ddo.id)
const query = await sdk.search.servicesBySubscription(
ddo.id,
searchOptions?.offset,
searchOptions?.page,
searchOptions?.sort,
searchOptions?.appId,
)

return {
subscription: ddo,
Expand All @@ -186,10 +197,20 @@ export const getSubscriptionsAndServices = async (subscriptionsDDOs: DDO[], sdk:
)
}

export const getSubscriptionsAndDatasets = async (subscriptionsDDOs: DDO[], sdk: Nevermined) => {
export const getSubscriptionsAndDatasets = async (
subscriptionsDDOs: DDO[],
sdk: Nevermined,
searchOptions?: SearchOptions,
) => {
return Promise.all(
subscriptionsDDOs.map(async (ddo) => {
const query = await sdk.search.datasetsBySubscription(ddo.id)
const query = await sdk.search.datasetsBySubscription(
ddo.id,
searchOptions?.offset,
searchOptions?.page,
searchOptions?.sort,
searchOptions?.appId,
)

return {
subscription: ddo,
Expand Down
12 changes: 6 additions & 6 deletions catalog/unit-tests/catalog/catalog.account.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPublishedSubscriptions(walletAddress)
const result = await account.getPublishedSubscriptions()

setSubscriptions([...result])
} catch (error: any) {
Expand Down Expand Up @@ -582,7 +582,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPublishedSubscriptionsAndServices(walletAddress)
const result = await account.getPublishedSubscriptionsAndServices()

setSubscriptions([...result])
} catch (error: any) {
Expand Down Expand Up @@ -621,7 +621,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPurchasedSubscriptions(walletAddress)
const result = await account.getPurchasedSubscriptions()

setSubscriptions([...result])
} catch (error: any) {
Expand Down Expand Up @@ -657,7 +657,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPurchasedSubscriptionsAndServices(walletAddress)
const result = await account.getPurchasedSubscriptionsAndServices()

setSubscriptions([...result])
} catch (error: any) {
Expand Down Expand Up @@ -732,7 +732,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPublishedSubscriptionsAndDatasets(walletAddress)
const result = await account.getPublishedSubscriptionsAndDatasets()

setSubscriptions([...result])
} catch (error: any) {
Expand Down Expand Up @@ -771,7 +771,7 @@ describe('Nevermined account', () => {

(async () => {
try {
const result = await account.getPublishedSubscriptionsAndDatasets(walletAddress)
const result = await account.getPublishedSubscriptionsAndDatasets()

setSubscriptions([...result])
} catch (error: any) {
Expand Down
2 changes: 1 addition & 1 deletion providers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nevermined-io/providers",
"private": false,
"version": "1.3.3",
"version": "1.3.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
Expand Down