diff --git a/packages/client/src/actions/app.ts b/packages/client/src/actions/app.ts index d173ecad7..411d90192 100644 --- a/packages/client/src/actions/app.ts +++ b/packages/client/src/actions/app.ts @@ -6,9 +6,19 @@ import type { AddAppSignersRequest, AddAppSignersResult, App, + AppFeed, + AppFeedsRequest, + AppGroupsRequest, AppRequest, + AppSigner, + AppSignersRequest, + AppUser, + AppUsersRequest, + AppsRequest, CreateAppRequest, CreateAppResult, + Group, + Paginated, RemoveAppFeedsRequest, RemoveAppFeedsResult, RemoveAppGroupsRequest, @@ -34,7 +44,12 @@ import { AddAppFeedsMutation, AddAppGroupsMutation, AddAppSignersMutation, + AppFeedsQuery, + AppGroupsQuery, AppQuery, + AppSignersQuery, + AppUsersQuery, + AppsQuery, CreateAppMutation, RemoveAppFeedsMutation, RemoveAppGroupsMutation, @@ -49,6 +64,7 @@ import { } from '@lens-protocol/graphql'; import type { ResultAsync } from '@lens-protocol/types'; +import type {} from '@lens-protocol/graphql'; import type { AnyClient, SessionClient } from '../clients'; import type { UnauthenticatedError, UnexpectedError } from '../errors'; @@ -74,6 +90,110 @@ export function fetchApp( return client.query(AppQuery, { request }); } +/** + * Fetch Apps. + * + * ```ts + * const result = await fetchApps(anyClient, { + * filter: { + * managedBy: { + * address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5') + * } + * }, + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of Apps or empty if it does not exist. + */ +export function fetchApps( + client: AnyClient, + request: AppsRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(AppsQuery, { request }); +} + +/** + * Fetch Groups linked to an App. + * + * ```ts + * const result = await fetchAppGroups(anyClient, { + * app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5') + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of groups for an App or empty if it does not exist. + */ +export function fetchAppGroups( + client: AnyClient, + request: AppGroupsRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(AppGroupsQuery, { request }); +} + +/** + * Fetch Feeds linked to an App. + * + * ```ts + * const result = await fetchAppFeeds(anyClient, { + * app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5') + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of feeds for an App or empty if it does not exist. + */ +export function fetchAppFeeds( + client: AnyClient, + request: AppFeedsRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(AppFeedsQuery, { request }); +} + +/** + * Fetch Signers linked to an App. + * + * ```ts + * const result = await fetchAppSigners(anyClient, { + * app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5') + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of signers for an App or empty if it does not exist. + */ +export function fetchAppSigners( + client: AnyClient, + request: AppSignersRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(AppSignersQuery, { request }); +} + +/** + * Fetch users using an App. + * + * ```ts + * const result = await fetchAppUsers(anyClient, { + * app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5') + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of users for an App or empty if it does not exist. + */ +export function fetchAppUsers( + client: AnyClient, + request: AppUsersRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(AppUsersQuery, { request }); +} + /** * Create an App * diff --git a/packages/graphql/src/app.ts b/packages/graphql/src/app.ts index 3754d676e..6b97701c6 100644 --- a/packages/graphql/src/app.ts +++ b/packages/graphql/src/app.ts @@ -1,6 +1,9 @@ import type { FragmentOf } from 'gql.tada'; import { + AccountFragment, AppFragment, + GroupFragment, + PaginatedResultInfoFragment, SelfFundedTransactionRequestFragment, SponsoredTransactionRequestFragment, TransactionWillFailFragment, @@ -17,6 +20,125 @@ export const AppQuery = graphql( ); export type AppRequest = RequestOf; +export const AppsQuery = graphql( + `query Apps($request: AppsRequest!) { + value: apps(request: $request) { + __typename + items { + ...App + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AppFragment, PaginatedResultInfoFragment], +); +export type AppsRequest = RequestOf; + +export const AppGroupsQuery = graphql( + `query AppGroups($request: AppGroupsRequest!) { + value: appGroups(request: $request) { + __typename + items { + ...Group + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [GroupFragment, PaginatedResultInfoFragment], +); +export type AppGroupsRequest = RequestOf; + +export const AppSignerFragment = graphql( + `fragment AppSigner on AppSigner { + __typename + signer + timestamp + }`, +); +export type AppSigner = FragmentOf; + +export const AppSignersQuery = graphql( + `query AppSigners($request: AppSignersRequest!) { + value: appSigners(request: $request) { + __typename + items { + ...AppSigner + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AppSignerFragment, PaginatedResultInfoFragment], +); +export type AppSignersRequest = RequestOf; + +export const AppFeedFragment = graphql( + `fragment AppFeed on AppFeed { + __typename + feed + timestamp + }`, +); +export type AppFeed = FragmentOf; + +export const AppFeedsQuery = graphql( + `query AppFeeds($request: AppFeedsRequest!) { + value: appFeeds(request: $request) { + __typename + items { + ...AppFeed + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AppFeedFragment, PaginatedResultInfoFragment], +); +export type AppFeedsRequest = RequestOf; + +export const AppUserFragment = graphql( + `fragment AppUser on AppUser { + __typename + account { + ...Account + } + lastActiveOn + firstLoginOn + }`, + [AccountFragment], +); +export type AppUser = FragmentOf; + +export const AppUsersQuery = graphql( + `query AppUsers($request: AppUsersRequest!) { + value: appUsers(request: $request) { + __typename + items { + ...AppUser + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AppUserFragment, PaginatedResultInfoFragment], +); +export type AppUsersRequest = RequestOf; + +export const AppServerApiKeyQuery = graphql( + `query AppServerApiKey($request: AppServerApiKeyRequest!) { + value: appServerApiKey(request: $request) + }`, + [AppFragment], +); +export type AppServerApiKeyRequest = RequestOf; + const CreateAppResponseFragment = graphql( `fragment CreateAppResponse on CreateAppResponse { __typename