diff --git a/examples/node/scripts/revenue/fromFollow.ts b/examples/node/scripts/revenue/fromFollow.ts index f252e2e59a..111e860817 100644 --- a/examples/node/scripts/revenue/fromFollow.ts +++ b/examples/node/scripts/revenue/fromFollow.ts @@ -1,19 +1,17 @@ import { LensClient, development } from '@lens-protocol/client'; async function main() { - const lensClient = new LensClient({ + const client = new LensClient({ environment: development, }); - const profileId = 'PROFILE_ID'; + const profileId = '0x01'; - const followRevenue = await lensClient.revenue.fromFollow({ - for: 'PROFILE_ID', + const result = await client.revenue.fromFollow({ + for: profileId, }); - console.log( - `Follow revenue for profile with id: ${profileId} - ${JSON.stringify(followRevenue)}`, - ); + console.log(`Follow revenue for profile with id: ${profileId}`, result); } main(); diff --git a/examples/node/scripts/revenue/fromPublication.ts b/examples/node/scripts/revenue/fromPublication.ts index eaefadb146..a1b7b19a6d 100644 --- a/examples/node/scripts/revenue/fromPublication.ts +++ b/examples/node/scripts/revenue/fromPublication.ts @@ -1,19 +1,25 @@ import { LensClient, development } from '@lens-protocol/client'; async function main() { - const lensClient = new LensClient({ + const client = new LensClient({ environment: development, }); - const publicationRevenue = await lensClient.revenue.fromPublication({ - for: 'PUBLICATION_ID', - }); + try { + const publications = await client.publication.fetchAll(); + + const firstPublication = publications.items[0]; + + const publicationRevenue = await client.revenue.fromPublication({ + for: firstPublication.id, + }); - console.log( - `Publication revenue for publication with id: ${ - publicationRevenue.publication.id - } - ${JSON.stringify(publicationRevenue.revenue)}`, - ); + console.log(`Revenue for publication with id: ${firstPublication.id}`, publicationRevenue); + } catch (e) { + if (e instanceof Error) { + console.log(e.message); + } + } } main(); diff --git a/examples/node/scripts/revenue/fromPublications.ts b/examples/node/scripts/revenue/fromPublications.ts index eb8c2ed123..8fa9b31251 100644 --- a/examples/node/scripts/revenue/fromPublications.ts +++ b/examples/node/scripts/revenue/fromPublications.ts @@ -1,61 +1,17 @@ import { LensClient, development } from '@lens-protocol/client'; async function main() { - const lensClient = new LensClient({ + const client = new LensClient({ environment: development, }); - const collectRevenue = await lensClient.revenue.fromPublications({ - for: 'PROFILE_ID', - // where: { - // fromCollects: true, - // }, - }); - - collectRevenue.items.map((item) => { - console.log( - `Collect revenue for publication with id: ${item.publication.id} - ${JSON.stringify( - item.revenue, - )}`, - ); - }); - - const revenueFromQuoteCollects = await lensClient.revenue.fromPublications({ - for: 'PROFILE_ID', - // where: { - // fromCollects: true, - // publicationTypes: [PublicationType.Quote], - // }, - }); - - revenueFromQuoteCollects.items.map((item) => { - console.log( - `Collect revenue for quote publication with id: ${item.publication.id} - ${JSON.stringify( - item.revenue, - )}`, - ); - }); + const profileId = '0x01'; - const revenueFromOpenAction = await lensClient.revenue.fromPublications({ - for: 'PROFILE_ID', - // where: { - // fromCollects: false, - // anyOf: [ - // { - // address: '0x000', - // category: OpenActionCategoryType.Collect, - // }, - // ], - // }, + const result = await client.revenue.fromPublications({ + for: profileId, }); - revenueFromOpenAction.items.map((item) => { - console.log( - `Open action revenue for publication with id: ${item.publication.id} - ${JSON.stringify( - item.revenue, - )}`, - ); - }); + console.log(`Follow revenue for profile with id: ${profileId}`, result); } main(); diff --git a/packages/client/src/submodules/publication/Publication.ts b/packages/client/src/submodules/publication/Publication.ts index af6ab2710a..a6fd9a40b4 100644 --- a/packages/client/src/submodules/publication/Publication.ts +++ b/packages/client/src/submodules/publication/Publication.ts @@ -142,7 +142,7 @@ export class Publication { * ``` */ async fetchAll( - request: PublicationsRequest, + request: PublicationsRequest = {}, ): Promise> { return buildPaginatedQueryResult(async (currRequest) => { const result = await this.sdk.Publications({ diff --git a/packages/client/src/submodules/revenue/Revenue.ts b/packages/client/src/submodules/revenue/Revenue.ts index 7b5073be93..f11d8d7246 100644 --- a/packages/client/src/submodules/revenue/Revenue.ts +++ b/packages/client/src/submodules/revenue/Revenue.ts @@ -20,7 +20,7 @@ import { } from './graphql/revenue.generated'; /** - * With built-in ways to earn on Lens Protocol, see the breakdown of what you have earned. + * Fetch a profile's or publication's revenue. * * @group LensClient Modules */ @@ -35,19 +35,19 @@ export class Revenue { this.sdk = getSdk(client, sdkAuthHeaderWrapper(authentication)); } - async fromPublications( - request: RevenueFromPublicationsRequest, - ): Promise> { - return buildPaginatedQueryResult(async (currRequest) => { - const result = await this.sdk.RevenueFromPublications({ - request: currRequest, - ...buildImageTransformsFromConfig(this.config.mediaTransforms), - }); - - return result.data.result; - }, request); - } - + /** + * Fetch a revenue from all follow actions. + * + * @param request - Request object for the query + * @returns Aggregated revenue + * + * @example + * ```ts + * const result = await client.revenue.fromFollow({ + * for: '0x123', + * }); + * ``` + */ async fromFollow(request: FollowRevenueRequest): Promise { const result = await this.sdk.FollowRevenues({ request, @@ -56,6 +56,18 @@ export class Revenue { return result.data.result.revenues; } + /** + * Fetch a profile's revenue from a single publication. + * @param request - Request object for the query + * @returns Publication revenue + * + * @example + * ```ts + * const result = await client.revenue.fromPublication({ + * for: '0x123-0x456', + * }); + * ``` + */ async fromPublication( request: RevenueFromPublicationRequest, ): Promise { @@ -66,4 +78,30 @@ export class Revenue { return result.data.result; } + + /** + * Fetch a profile's revenue from all publications. + * + * @param request - Request object for the query + * @returns {@link PublicationRevenueFragment} wrapped in {@link PaginatedResult} + * + * @example + * ```ts + * const result = await client.revenue.fromPublications({ + * for: '0x123', + * }); + * ``` + */ + async fromPublications( + request: RevenueFromPublicationsRequest, + ): Promise> { + return buildPaginatedQueryResult(async (currRequest) => { + const result = await this.sdk.RevenueFromPublications({ + request: currRequest, + ...buildImageTransformsFromConfig(this.config.mediaTransforms), + }); + + return result.data.result; + }, request); + } }