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

Commit 0a1c805

Browse files
authored
Merge pull request #297 from nevermined-io/feat/full-pagination-support
Feat/full pagination support
2 parents aeff03c + ff45cd9 commit 0a1c805

File tree

8 files changed

+61
-42
lines changed

8 files changed

+61
-42
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
44

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

7+
#### [v1.4.6](https://github.com/nevermined-io/components-catalog/compare/v1.4.5...v1.4.6)
8+
9+
> 17 May 2023
10+
11+
- Fix/fix price type [`#296`](https://github.com/nevermined-io/components-catalog/pull/296)
12+
- fix price type [`4fa17ef`](https://github.com/nevermined-io/components-catalog/commit/4fa17ef4c4386fd67d63a7dfc6f4cd175d29d297)
13+
- Adding v1.4.5 Changelog updates [`6bc7b49`](https://github.com/nevermined-io/components-catalog/commit/6bc7b492fb50363cb7bdd0627bff6dbd6fca6562)
14+
715
#### [v1.4.5](https://github.com/nevermined-io/components-catalog/compare/v1.4.4...v1.4.5)
816

917
> 17 May 2023

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.4.6",
3+
"version": "1.5.0",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"dependencies": {

catalog/src/catalog.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getSubscriptionsAndServices,
3737
getSubscriptionsAndDatasets,
3838
executeWithProgressEvent,
39+
emptyQueryResult,
3940
} from './utils'
4041
import { _getCryptoConfig, _getDTPInstance, _grantAccess } from './utils/dtp'
4142
import { getAddressTokenSigner, isTokenValid, newMarketplaceApiToken } from './utils/marketplace_token'
@@ -125,7 +126,7 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
125126
const [{ sdk }, dispatch] = useReducer(neverminedReducer, initialState)
126127
const [isLoading, setIsLoading] = useState<boolean>(true)
127128
// eslint-disable-next-line
128-
const [error, setError] = useState<any>(undefined)
129+
const [sdkError, setSdkError] = useState<any>(undefined)
129130

130131
useEffect(() => {
131132
const loadNevermined = async (): Promise<void> => {
@@ -138,7 +139,7 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
138139
if (success) {
139140
dispatch({ type: 'SET_SDK', payload: { sdk: data } })
140141
}
141-
setError(error)
142+
setSdkError(error)
142143
setIsLoading(false)
143144
}
144145
loadNevermined()
@@ -216,14 +217,14 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
216217
}
217218
},
218219

219-
getPublishedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
220+
getPublishedSubscriptions: async (searchOptions?: SearchOptions): Promise<QueryResult> => {
220221
try {
221222
const account = await getCurrentAccount(sdk)
222223
const query = await sdk.search.subscriptionsCreated(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
223-
return query.results
224-
} catch {
224+
return query
225+
} catch (error) {
225226
verbose && Logger.error(error)
226-
return []
227+
return emptyQueryResult
227228
}
228229
},
229230

@@ -250,14 +251,14 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
250251
}
251252
},
252253

253-
getPurchasedSubscriptions: async (searchOptions?: SearchOptions): Promise<DDO[]> => {
254+
getPurchasedSubscriptions: async (searchOptions?: SearchOptions): Promise<QueryResult> => {
254255
try {
255256
const account = await getCurrentAccount(sdk)
256257
const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
257-
return query.results
258+
return query
258259
} catch (error) {
259260
verbose && Logger.error(error)
260-
return []
261+
return emptyQueryResult
261262
}
262263
},
263264

@@ -284,23 +285,23 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
284285
}
285286
},
286287

287-
getAssociatedServices: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
288+
getAssociatedServices: async (did: string, searchOptions?: SearchOptions): Promise<QueryResult> => {
288289
try {
289290
const query = await sdk.search.servicesBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
290-
return query.results
291+
return query
291292
} catch (error) {
292293
verbose && Logger.error(error)
293-
return []
294+
return emptyQueryResult
294295
}
295296
},
296297

297-
getAssociatedDatasets: async (did: string, searchOptions?: SearchOptions): Promise<DDO[]> => {
298+
getAssociatedDatasets: async (did: string, searchOptions?: SearchOptions): Promise<QueryResult> => {
298299
try {
299300
const query = await sdk.search.datasetsBySubscription(did, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId)
300-
return query.results
301+
return query
301302
} catch (error) {
302303
verbose && Logger.error(error)
303-
return []
304+
return emptyQueryResult
304305
}
305306
},
306307

@@ -695,19 +696,16 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
695696
)
696697

697698
transferResult = ercType === 721
698-
? await sdk.nfts721.transferForDelegate(
699+
? await sdk.nfts721.claim(
699700
agreementId,
700701
nftHolder,
701702
buyer.getId(),
702-
nftAmount,
703-
ercType
704703
)
705-
: await sdk.nfts1155.transferForDelegate(
704+
: await sdk.nfts1155.claim(
706705
agreementId,
707706
nftHolder,
708707
buyer.getId(),
709708
nftAmount,
710-
ercType
711709
)
712710
}
713711
} catch (error) {
@@ -727,7 +725,7 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
727725
const IState = {
728726
sdk,
729727
isLoadingSDK: isLoading,
730-
sdkError: error,
728+
sdkError,
731729
subscribe,
732730
assets,
733731
account,

catalog/src/types/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CreateProgressStep,
1919
RoyaltyKind,
2020
OrderProgressStep,
21+
MetaDataExternalResource,
2122
} from '@nevermined-io/sdk'
2223
import { CryptoConfig } from '@nevermined-io/sdk-dtp'
2324

@@ -422,21 +423,21 @@ export interface AccountModule {
422423
* @param searchOptions options for customize result
423424
* @returns published subscriptions
424425
*/
425-
getPublishedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
426+
getPublishedSubscriptions: (searchOptions?: SearchOptions) => Promise<QueryResult>
426427
/**
427428
* Get all the services associated a subscription
428429
* @param address the subscription address
429430
* @param searchOptions options for customize result
430431
* @returns associated services to subscriptions
431432
*/
432-
getAssociatedServices: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
433+
getAssociatedServices: (did: string, searchOptions?: SearchOptions) => Promise<QueryResult>
433434
/**
434435
* Get all the datasets associated to a subscription
435436
* @param address the subscription address
436437
* @param searchOptions options for customize result
437438
* @returns associated datasets to subscriptions
438439
*/
439-
getAssociatedDatasets: (did: string, searchOptions?: SearchOptions) => Promise<DDO[]>
440+
getAssociatedDatasets: (did: string, searchOptions?: SearchOptions) => Promise<QueryResult>
440441
/**
441442
* Get all the published subscriptions and services associated from the wallet address passed
442443
* @param searchOptions options for customize result
@@ -458,7 +459,7 @@ export interface AccountModule {
458459
* @param searchOptions options for customize result
459460
* @returns purchased subscriptions
460461
*/
461-
getPurchasedSubscriptions: (searchOptions?: SearchOptions) => Promise<DDO[]>
462+
getPurchasedSubscriptions: (searchOptions?: SearchOptions) => Promise<QueryResult>
462463
/**
463464
* Get all the purchased subscriptions and services associated from the wallet address passed
464465
* @param searchOptions options for customize result
@@ -770,7 +771,7 @@ export interface AssetPublishParams {
770771
/** Price of the asset */
771772
price: string
772773
/** Files to download after buy the asset */
773-
assetFiles: AssetFile[]
774+
assetFiles: MetaDataExternalResource[]
774775
}
775776

776777
/** Metadata of the file */
@@ -988,10 +989,10 @@ export interface Credentials {
988989

989990
export interface SubscriptionsAndServicesDDOs {
990991
subscription: DDO
991-
services: DDO[]
992+
services: QueryResult
992993
}
993994

994995
export interface SubscriptionsAndDatasetsDDOs {
995996
subscription: DDO
996-
datasets: DDO[]
997+
datasets: QueryResult
997998
}

catalog/src/utils/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ERCType,
55
MarketplaceAPIToken,
66
NeverminedOptions,
7+
QueryResult,
78
SearchOptions,
89
SubscribablePromise,
910
} from '../types'
@@ -191,7 +192,7 @@ export const getSubscriptionsAndServices = async (
191192

192193
return {
193194
subscription: ddo,
194-
services: query.results,
195+
services: query,
195196
}
196197
}),
197198
)
@@ -214,7 +215,7 @@ export const getSubscriptionsAndDatasets = async (
214215

215216
return {
216217
subscription: ddo,
217-
datasets: query.results,
218+
datasets: query,
218219
}
219220
}),
220221
)
@@ -241,3 +242,10 @@ export const getNewSdkInstance = async (
241242
): Promise<Nevermined> => {
242243
return Nevermined.getInstance({ ...config, marketplaceAuthToken: tokenData.token })
243244
}
245+
246+
export const emptyQueryResult: QueryResult = {
247+
results: [],
248+
totalResults: {},
249+
page: 0,
250+
totalPages: 0,
251+
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ describe('Nevermined account', () => {
548548
try {
549549
const result = await account.getPublishedSubscriptions()
550550

551-
setSubscriptions([...result])
551+
setSubscriptions([...result.results])
552552
} catch (error: any) {
553553
console.error(error.message)
554554
}
@@ -601,7 +601,7 @@ describe('Nevermined account', () => {
601601
await waitFor(() => {
602602
expect(result.current).toStrictEqual([{
603603
subscription: ddo,
604-
services: [ddo2, ddo3]
604+
services: { results: [ddo2, ddo3] }
605605
}])
606606
})
607607
})
@@ -623,7 +623,7 @@ describe('Nevermined account', () => {
623623
try {
624624
const result = await account.getPurchasedSubscriptions()
625625

626-
setSubscriptions([...result])
626+
setSubscriptions([...result.results])
627627
} catch (error: any) {
628628
console.error(error.message)
629629
}
@@ -676,7 +676,7 @@ describe('Nevermined account', () => {
676676
await waitFor(() => {
677677
expect(result.current).toStrictEqual([{
678678
subscription: ddo,
679-
services: [ddo2, ddo3]
679+
services: {results: [ddo2, ddo3]}
680680
}])
681681
})
682682
})
@@ -698,7 +698,7 @@ describe('Nevermined account', () => {
698698
try {
699699
const result = await account.getAssociatedServices(ddo.id)
700700

701-
setServices([...result])
701+
setServices([...result.results])
702702
} catch (error: any) {
703703
console.error(error.message)
704704
}
@@ -751,7 +751,9 @@ describe('Nevermined account', () => {
751751
await waitFor(() => {
752752
expect(result.current).toStrictEqual([{
753753
subscription: ddo,
754-
datasets: [ddo4, ddo5]
754+
datasets: {
755+
results: [ddo4, ddo5]
756+
}
755757
}])
756758
})
757759
})
@@ -790,7 +792,9 @@ describe('Nevermined account', () => {
790792
await waitFor(() => {
791793
expect(result.current).toStrictEqual([{
792794
subscription: ddo,
793-
datasets: [ddo4, ddo5]
795+
datasets: {
796+
results: [ddo4, ddo5]
797+
}
794798
}])
795799
})
796800
})
@@ -812,7 +816,7 @@ describe('Nevermined account', () => {
812816
try {
813817
const result = await account.getAssociatedDatasets(ddo.id)
814818

815-
setDatasets([...result])
819+
setDatasets([...result.results])
816820
} catch (error: any) {
817821
console.error(error.message)
818822
}

catalog/unit-tests/mockups.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ export const nevermined = {
10271027
}),
10281028
create: async () => ddo,
10291029
createWithRoyalties: async () => ddo,
1030-
transferForDelegate: async () => true,
1030+
claim: async () => true,
10311031
},
10321032
nfts721: {
10331033
ownerOf: async () => walletAddress,
@@ -1066,7 +1066,7 @@ export const nevermined = {
10661066
}),
10671067
create: async () => ddo,
10681068
createWithRoyalties: async () => ddo,
1069-
transferForDelegate: async () => true,
1069+
claim: async () => true,
10701070
},
10711071
search: {
10721072
subscriptionsCreated: () => ({ results: [ddo] }),

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.4.6",
4+
"version": "1.5.0",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
77
"dependencies": {

0 commit comments

Comments
 (0)