Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit 738645e

Browse files
committed
add search options to get published and purchased subscriptions
1 parent acc61aa commit 738645e

File tree

6 files changed

+95
-46
lines changed

6 files changed

+95
-46
lines changed

catalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nevermined-io/catalog",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"dependencies": {

catalog/src/catalog.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
BigNumber,
2424
SubscriptionsAndServicesDDOs,
2525
OrderProgressStep,
26-
SubscriptionsAndDatasetsDDOs
26+
SubscriptionsAndDatasetsDDOs,
27+
SearchOptions
2728
} from './types'
2829
import {
2930
conductOrder,
@@ -210,85 +211,87 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
210211
}
211212
},
212213

213-
getPublishedSubscriptions: async (): Promise<DDO[]> => {
214+
getPublishedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
214215
try {
215216
const account = await getCurrentAccount(sdk)
216-
const query = await sdk.search.subscriptionsCreated(account)
217+
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
217218
return query.results
218219
} catch {
219220
verbose && Logger.error(error)
220221
return []
221222
}
222223
},
223224

224-
getPublishedSubscriptionsAndServices: async (): Promise<SubscriptionsAndServicesDDOs[]> => {
225+
getPublishedSubscriptionsAndServices: async (searchOptions?: SearchOptions
226+
): Promise<SubscriptionsAndServicesDDOs[]> => {
225227
try {
226228
const account = await getCurrentAccount(sdk)
227-
const query = await sdk.search.subscriptionsCreated(account)
228-
return getSubscriptionsAndServices(query.results, sdk)
229+
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
230+
return getSubscriptionsAndServices(query.results, sdk, searchOptions)
229231
} catch (error) {
230232
verbose && Logger.error(error)
231233
return []
232234
}
233235
},
234236

235-
getPublishedSubscriptionsAndDatasets: async (): Promise<SubscriptionsAndDatasetsDDOs[]> => {
237+
getPublishedSubscriptionsAndDatasets: async (searchOptions?: SearchOptions): Promise<SubscriptionsAndDatasetsDDOs[]> => {
236238
try {
237239
const account = await getCurrentAccount(sdk)
238-
const query = await sdk.search.subscriptionsCreated(account)
239-
return getSubscriptionsAndDatasets(query.results, sdk)
240+
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
241+
return getSubscriptionsAndDatasets(query.results, sdk, searchOptions)
240242
} catch (error) {
241243
verbose && Logger.error(error)
242244
return []
243245
}
244246
},
245247

246-
getPurchasedSubscriptions: async (): Promise<DDO[]> => {
248+
getPurchasedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
247249
try {
248250
const account = await getCurrentAccount(sdk)
249-
const query = await sdk.search.subscriptionsPurchased(account)
251+
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
250252
return query.results
251253
} catch (error) {
252254
verbose && Logger.error(error)
253255
return []
254256
}
255257
},
256258

257-
getPurchasedSubscriptionsAndServices: async (): Promise<SubscriptionsAndServicesDDOs[]> => {
259+
getPurchasedSubscriptionsAndServices: async (searchOptions?: SearchOptions
260+
): Promise<SubscriptionsAndServicesDDOs[]> => {
258261
try {
259262
const account = await getCurrentAccount(sdk)
260-
const query = await sdk.search.subscriptionsPurchased(account)
261-
return getSubscriptionsAndServices(query.results, sdk)
263+
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
264+
return getSubscriptionsAndServices(query.results, sdk, searchOptions)
262265
} catch (error) {
263266
verbose && Logger.error(error)
264267
return []
265268
}
266269
},
267270

268-
getPurchasedSubscriptionsAndDatasets: async (): Promise<SubscriptionsAndDatasetsDDOs[]> => {
271+
getPurchasedSubscriptionsAndDatasets: async (searchOptions?: SearchOptions): Promise<SubscriptionsAndDatasetsDDOs[]> => {
269272
try {
270273
const account = await getCurrentAccount(sdk)
271-
const query = await sdk.search.subscriptionsPurchased(account)
272-
return getSubscriptionsAndDatasets(query.results, sdk)
274+
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
275+
return getSubscriptionsAndDatasets(query.results, sdk, searchOptions)
273276
} catch (error) {
274277
verbose && Logger.error(error)
275278
return []
276279
}
277280
},
278281

279-
getAssociatedServices: async (did: string): Promise<DDO[]> => {
282+
getAssociatedServices: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
280283
try {
281-
const query = await sdk.search.servicesBySubscription(did)
284+
const query = await sdk.search.servicesBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
282285
return query.results
283286
} catch (error) {
284287
verbose && Logger.error(error)
285288
return []
286289
}
287290
},
288291

289-
getAssociatedDatasets: async (did: string): Promise<DDO[]> => {
292+
getAssociatedDatasets: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
290293
try {
291-
const query = await sdk.search.datasetsBySubscription(did)
294+
const query = await sdk.search.datasetsBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
292295
return query.results
293296
} catch (error) {
294297
verbose && Logger.error(error)

catalog/src/types/index.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,20 @@ export interface GenericOutput<T, E> {
299299
success: boolean
300300
}
301301

302+
/**
303+
* Query search options
304+
*/
305+
export interface SearchOptions {
306+
/** Number of results per page */
307+
offset?: number
308+
/** Number of page */
309+
page?: number
310+
/** result order */
311+
sort?: 'asc' | 'desc'
312+
/** If app to search have an id */
313+
appId?: string
314+
}
315+
302316
/** Id of the asset */
303317
export type DID = string
304318

@@ -405,51 +419,62 @@ export interface AccountModule {
405419
/**
406420
* Get only published Subscriptions
407421
* @param address the address which published the subscription returned
422+
* @param searchOptions options for customize result
408423
* @returns published subscriptions
409424
*/
410-
getPublishedSubscriptions: (address: string) => Promise<DDO[]>
425+
getPublishedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
411426
/**
412427
* Get all the services associated a subscription
413428
* @param address the subscription address
429+
* @param searchOptions options for customize result
414430
* @returns associated services to subscriptions
415431
*/
416-
getAssociatedServices: (did: string) => Promise<DDO[]>
432+
getAssociatedServices: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
417433
/**
418434
* Get all the datasets associated to a subscription
419435
* @param address the subscription address
436+
* @param searchOptions options for customize result
420437
* @returns associated datasets to subscriptions
421438
*/
422-
getAssociatedDatasets: (did: string) => Promise<DDO[]>
439+
getAssociatedDatasets: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
423440
/**
424441
* Get all the published subscriptions and services associated from the wallet address passed
425-
* @param did the did of the subscription
442+
* @param searchOptions options for customize result
426443
* @returns published subscriptions and service
427444
*/
428-
getPublishedSubscriptionsAndServices: (address: string) => Promise<SubscriptionsAndServicesDDOs[]>
445+
getPublishedSubscriptionsAndServices: (
446+
searchOptions?: SearchOptions,
447+
) => Promise<SubscriptionsAndServicesDDOs[]>
429448
/**
430449
* Get all the published subscriptions and datasets associated from the wallet address passed
431-
* @param did the did of the subscription
450+
* @param searchOptions options for customize result
432451
* @returns published subscriptions and its datasets
433452
*/
434-
getPublishedSubscriptionsAndDatasets: (address: string) => Promise<SubscriptionsAndDatasetsDDOs[]>
453+
getPublishedSubscriptionsAndDatasets: (
454+
searchOptions?: SearchOptions,
455+
) => Promise<SubscriptionsAndDatasetsDDOs[]>
435456
/**
436457
* Get only purchased Subscriptions
437-
* @param address the address which purchased the subscription returned
458+
* @param searchOptions options for customize result
438459
* @returns purchased subscriptions
439460
*/
440-
getPurchasedSubscriptions: (address: string) => Promise<DDO[]>
461+
getPurchasedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
441462
/**
442463
* Get all the purchased subscriptions and services associated from the wallet address passed
443-
* @param address the address which published the subscription returned
464+
* @param searchOptions options for customize result
444465
* @returns purchased subscriptions and services
445466
*/
446-
getPurchasedSubscriptionsAndServices: (address: string) => Promise<SubscriptionsAndServicesDDOs[]>
467+
getPurchasedSubscriptionsAndServices: (
468+
searchOptions?: SearchOptions,
469+
) => Promise<SubscriptionsAndServicesDDOs[]>
447470
/**
448471
* Get all the purchased subscriptions and datasets associated from the wallet address passed
449-
* @param did the did of the subscription
472+
* @param searchOptions options for customize result
450473
* @returns purchased subscriptions and its datasets
451474
*/
452-
getPurchasedSubscriptionsAndDatasets: (address: string) => Promise<SubscriptionsAndDatasetsDDOs[]>
475+
getPurchasedSubscriptionsAndDatasets: (
476+
searchOptions?: SearchOptions,
477+
) => Promise<SubscriptionsAndDatasetsDDOs[]>
453478
/**
454479
* Generate a token for authentication in the Marketplace API
455480
* @returns The new generated token

catalog/src/utils/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ERCType,
55
MarketplaceAPIToken,
66
NeverminedOptions,
7+
SearchOptions,
78
SubscribablePromise,
89
} from '../types'
910
import axios from 'axios'
@@ -173,10 +174,20 @@ export const handlePostRequest = async (url: string, formData: FormData, retries
173174
}
174175
}
175176

176-
export const getSubscriptionsAndServices = async (subscriptionsDDOs: DDO[], sdk: Nevermined) => {
177+
export const getSubscriptionsAndServices = async (
178+
subscriptionsDDOs: DDO[],
179+
sdk: Nevermined,
180+
searchOptions?: SearchOptions,
181+
) => {
177182
return Promise.all(
178183
subscriptionsDDOs.map(async (ddo) => {
179-
const query = await sdk.search.servicesBySubscription(ddo.id)
184+
const query = await sdk.search.servicesBySubscription(
185+
ddo.id,
186+
searchOptions?.offset,
187+
searchOptions?.page,
188+
searchOptions?.sort,
189+
searchOptions?.appId,
190+
)
180191

181192
return {
182193
subscription: ddo,
@@ -186,10 +197,20 @@ export const getSubscriptionsAndServices = async (subscriptionsDDOs: DDO[], sdk:
186197
)
187198
}
188199

189-
export const getSubscriptionsAndDatasets = async (subscriptionsDDOs: DDO[], sdk: Nevermined) => {
200+
export const getSubscriptionsAndDatasets = async (
201+
subscriptionsDDOs: DDO[],
202+
sdk: Nevermined,
203+
searchOptions?: SearchOptions,
204+
) => {
190205
return Promise.all(
191206
subscriptionsDDOs.map(async (ddo) => {
192-
const query = await sdk.search.datasetsBySubscription(ddo.id)
207+
const query = await sdk.search.datasetsBySubscription(
208+
ddo.id,
209+
searchOptions?.offset,
210+
searchOptions?.page,
211+
searchOptions?.sort,
212+
searchOptions?.appId,
213+
)
193214

194215
return {
195216
subscription: ddo,

catalog/unit-tests/catalog/catalog.account.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ describe('Nevermined account', () => {
546546

547547
(async () => {
548548
try {
549-
const result = await account.getPublishedSubscriptions(walletAddress)
549+
const result = await account.getPublishedSubscriptions()
550550

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

583583
(async () => {
584584
try {
585-
const result = await account.getPublishedSubscriptionsAndServices(walletAddress)
585+
const result = await account.getPublishedSubscriptionsAndServices()
586586

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

622622
(async () => {
623623
try {
624-
const result = await account.getPurchasedSubscriptions(walletAddress)
624+
const result = await account.getPurchasedSubscriptions()
625625

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

658658
(async () => {
659659
try {
660-
const result = await account.getPurchasedSubscriptionsAndServices(walletAddress)
660+
const result = await account.getPurchasedSubscriptionsAndServices()
661661

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

733733
(async () => {
734734
try {
735-
const result = await account.getPublishedSubscriptionsAndDatasets(walletAddress)
735+
const result = await account.getPublishedSubscriptionsAndDatasets()
736736

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

772772
(async () => {
773773
try {
774-
const result = await account.getPublishedSubscriptionsAndDatasets(walletAddress)
774+
const result = await account.getPublishedSubscriptionsAndDatasets()
775775

776776
setSubscriptions([...result])
777777
} catch (error: any) {

providers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nevermined-io/providers",
33
"private": false,
4-
"version": "1.3.3",
4+
"version": "1.3.4",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
77
"dependencies": {

0 commit comments

Comments
 (0)