Skip to content

Commit

Permalink
fix profile and publication stats
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Sep 20, 2023
1 parent 028461f commit d015573
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 231 deletions.
62 changes: 0 additions & 62 deletions examples/node/scripts/profile/profileStats.ts

This file was deleted.

52 changes: 52 additions & 0 deletions examples/node/scripts/profile/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
CustomFiltersType,
LensClient,
OpenActionCategoryType,
OpenActionModuleType,
development,
} from '@lens-protocol/client';

async function main() {
const client = new LensClient({
environment: development,
});

// stats across the whole protocol
const protocolWideStats = await client.profile.stats({ request: { forProfileId: '0x01' } });

console.log('Result: ', protocolWideStats);

// stats for a specified apps
const statsForSpecifiedApps = await client.profile.stats({
request: { forProfileId: '0x01' },
profileStatsArg: { forApps: ['APP_ID', 'ANOTHER_APP_ID'] },
});

console.log('Result: ', statsForSpecifiedApps);

// filter open actions
const filteredOpenActions = await client.profile.stats({
request: { forProfileId: '0x01' },
profileStatsCountOpenActionArgs: {
anyOf: [
{
address: '0x00',
type: OpenActionModuleType.SimpleCollectOpenActionModule,
category: OpenActionCategoryType.Collect,
},
],
},
});

console.log('Result: ', filteredOpenActions);

// stats for a specified app and with custom filters
const customFilteredStats = await client.profile.stats({
request: { forProfileId: '0x01' },
profileStatsArg: { forApps: ['APP_ID'], customFilters: [CustomFiltersType.Gardeners] },
});

console.log('Result: ', customFilteredStats);
}

main();
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function main() {

const result = await client.publication.stats({
request: {
forId: '0x123',
forId: '0x04-0x0b',
},
});

Expand Down
18 changes: 6 additions & 12 deletions examples/node/scripts/revenue/fromPublication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@ async function main() {
environment: development,
});

try {
const publications = await client.publication.fetchAll();
const publications = await client.publication.fetchAll();

const firstPublication = publications.items[0];
const firstPublication = publications.items[0];

const publicationRevenue = await client.revenue.fromPublication({
for: firstPublication.id,
});
const publicationRevenue = await client.revenue.fromPublication({
for: firstPublication.id,
});

console.log(`Revenue for publication with id: ${firstPublication.id}`, publicationRevenue);
} catch (e) {
if (e instanceof Error) {
console.log(e.message);
}
}
console.log(`Revenue for publication with id: ${firstPublication.id}`, publicationRevenue);
}

main();
3 changes: 3 additions & 0 deletions packages/client/src/graphql/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,11 @@ export type RevenueFromPublicationRequest = {

export type RevenueFromPublicationsRequest = {
cursor?: InputMaybe<Scalars['Cursor']['input']>;
/** The profile to get revenue for */
for: Scalars['ProfileId']['input'];
limit?: InputMaybe<LimitType>;
/** Will return revenue for publications made on any of the provided app ids. Will include all apps if omitted */
publishedOn?: InputMaybe<Array<Scalars['AppId']['input']>>;
};

export type SensitiveReasonInput = {
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './buildPaginatedQueryResult';
export * from './poll';
export * from './requireAuthHeaders';
export * from './sdkAuthHeaderWrapper';
export * from './profileStatistics';
20 changes: 0 additions & 20 deletions packages/client/src/helpers/profileStatistics.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
MirrorFragment,
CommentFragment,
Eip712TypedDataDomainFragment,
Eip712TypedDataFieldFragment,
RelaySuccessFragment,
LensProfileManagerRelayErrorFragment,
Eip712TypedDataFieldFragment,
CreateMomokaPublicationResultFragment,
} from '../../../graphql/fragments.generated';
import { GraphQLClient } from 'graphql-request';
Expand All @@ -26,9 +26,9 @@ import {
MirrorFragmentDoc,
CommentFragmentDoc,
Eip712TypedDataDomainFragmentDoc,
Eip712TypedDataFieldFragmentDoc,
RelaySuccessFragmentDoc,
LensProfileManagerRelayErrorFragmentDoc,
Eip712TypedDataFieldFragmentDoc,
CreateMomokaPublicationResultFragmentDoc,
} from '../../../graphql/fragments.generated';
export type ExplorePublicationsQueryVariables = Types.Exact<{
Expand Down
54 changes: 36 additions & 18 deletions packages/client/src/submodules/profile/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ import type {
} from '../../graphql/types.generated';
import {
PaginatedResult,
ProfileQueryOptions,
buildImageTransformsFromConfig,
buildPaginatedQueryResult,
buildProfileQueryOptions,
requireAuthHeaders,
sdkAuthHeaderWrapper,
} from '../../helpers';
Expand All @@ -54,17 +52,19 @@ import {
CreateUnfollowBroadcastItemResultFragment,
ProfileManagerFragment,
ProfileStatsFragment,
ProfileStatsQueryVariables,
Sdk,
getSdk,
} from './graphql/profile.generated';

/**
* Profiles are the accounts that create publications and are owned by wallets
*
* @group LensClient Modules
*/
export class Profile {
private readonly authentication: Authentication | undefined;
private readonly sdk: Sdk;
private readonly defaultOptions: ProfileQueryOptions;

constructor(
private readonly config: LensConfig,
Expand All @@ -74,9 +74,6 @@ export class Profile {

this.sdk = getSdk(client, sdkAuthHeaderWrapper(authentication));
this.authentication = authentication;
this.defaultOptions = buildProfileQueryOptions({
config,
});
}

async fetch(request: ProfileRequest): Promise<ProfileFragment | null> {
Expand All @@ -99,6 +96,39 @@ export class Profile {
}, request);
}

/**
* Fetches a profile's stats
*
* @param variables - Object defining all variables for the query
* @returns {@link ProfileStatsFragment} or undefined if not found
*
* @example
* ```ts
* const result = await client.profile.stats({
* request: {
* forProfileId: '0x01',
* },
* });
* ```
*/
async stats(variables: ProfileStatsQueryVariables): Promise<ProfileStatsFragment | undefined> {
const {
request,
profileStatsArg = {
forApps: this.config.forApps,
},
profileStatsCountOpenActionArgs = { anyOf: [] },
} = variables;

const result = await this.sdk.ProfileStats({
request,
profileStatsArg,
profileStatsCountOpenActionArgs,
});

return result.data.result?.stats;
}

async managers(
request: ProfileManagersRequest,
): Promise<PaginatedResult<ProfileManagerFragment>> {
Expand Down Expand Up @@ -286,18 +316,6 @@ export class Profile {
});
}

async stats(
request: ProfileRequest,
options: ProfileQueryOptions = this.defaultOptions,
): Promise<ProfileStatsFragment | undefined> {
const result = await this.sdk.ProfileStats({
request,
...options,
});

return result.data.result?.stats;
}

async createOnchainSetProfileMetadataTypedData(
request: OnchainSetProfileMetadataRequest,
options?: TypedDataOptions,
Expand Down
Loading

0 comments on commit d015573

Please sign in to comment.