UNPKG

@iexec/dataprotector

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

35 lines 1.49 kB
import { WorkflowError } from '../../utils/errors.js'; import { numberBetweenSchema, throwIfMissing } from '../../utils/validators.js'; import { getCollectionOwnersQuery } from './subgraph/getCollectionOwnersQuery.js'; export async function getCollectionOwners({ iexec = throwIfMissing(), graphQLClient = throwIfMissing(), limit, }) { const vLimit = numberBetweenSchema(1, 1000) .default(100) .label('limit') .validateSync(limit); let userAddress = await iexec.wallet.getAddress(); userAddress = userAddress.toLowerCase(); try { const getCollectionOwnersQueryResponse = await getCollectionOwnersQuery({ graphQLClient, userAddress, limit: vLimit, }); const withActiveSubscriptions = getCollectionOwnersQueryResponse.accounts.map((account) => ({ ...account, hasActiveSubscription: account.collections.some((collection) => collection.subscriptions && collection.subscriptions.length > 0), collections: account.collections.map((collection) => { const { subscriptions, ...rest } = collection; return rest; }), })); return { collectionOwners: withActiveSubscriptions }; } catch (e) { console.error(e); throw new WorkflowError({ message: 'Failed to get collection owners', errorCause: e, }); } } //# sourceMappingURL=getCollectionOwners.js.map