diff --git a/packages/client/src/actions/app.ts b/packages/client/src/actions/app.ts index d713d8216..abc1ba3e8 100644 --- a/packages/client/src/actions/app.ts +++ b/packages/client/src/actions/app.ts @@ -361,7 +361,7 @@ export function removeAppSigners( * * ```ts * const result = await setAppGraph(sessionClient, { - * graph: graph: { globalGraph: true }, + * graph: { globalGraph: true }, * app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), * }); * ``` diff --git a/packages/client/src/actions/index.ts b/packages/client/src/actions/index.ts index 410cd9c46..9e1382ebe 100644 --- a/packages/client/src/actions/index.ts +++ b/packages/client/src/actions/index.ts @@ -10,6 +10,7 @@ export * from './graph'; export * from './group'; export * from './health'; export * from './namespace'; +export * from './ml'; export * from './notifications'; export * from './post'; export * from './posts'; diff --git a/packages/client/src/actions/ml.ts b/packages/client/src/actions/ml.ts new file mode 100644 index 000000000..e5c7bc92f --- /dev/null +++ b/packages/client/src/actions/ml.ts @@ -0,0 +1,141 @@ +import type { + Account, + DismissRecommendedAccountsRequest, + MlAccountRecommendationsRequest, + MlPostsExploreRequest, + MlPostsForYouRequest, + Paginated, + Post, + PostForYou, + PostNotInterestedRequest, +} from '@lens-protocol/graphql'; +import { + AddPostNotInterestedMutation, + MlAccountRecommendationsQuery, + MlDismissRecommendedAccountsMutation, + MlPostsExploreQuery, + MlPostsForYouQuery, + UndoPostNotInterestedMutation, +} from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { AnyClient, SessionClient } from '../clients'; +import type { UnauthenticatedError, UnexpectedError } from '../errors'; + +/** + * Fetch account recommendations from ML. + * + * ```ts + * const result = await fetchMlAccountRecommendations(anyClient, { + * account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list accounts recommended. + */ +export function fetchMlAccountRecommendations( + client: AnyClient, + request: MlAccountRecommendationsRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(MlAccountRecommendationsQuery, { request }); +} + +/** + * Fetch posts for you from ML. + * + * ```ts + * const result = await fetchPostsForYou(anyClient, { + * account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of recommended posts. + */ +export function fetchPostsForYou( + client: AnyClient, + request: MlPostsForYouRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(MlPostsForYouQuery, { request }); +} + +/** + * Fetch posts to explore. + * + * ```ts + * const result = await fetchPostsToExplore(anyClient); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of posts to explore. + */ +export function fetchPostsToExplore( + client: AnyClient, + request: MlPostsExploreRequest, +): ResultAsync | null, UnexpectedError> { + return client.query(MlPostsExploreQuery, { request }); +} + +/** + * Dismiss recommended account. + * + * ```ts + * const result = await dismissRecommendedAccount(sessionClient, { + * accounts: [evmAddress('0xe2f2...')], + * }); + * ``` + * + * @param client - Session Lens client. + * @param request - The list of accounts to dismiss. + * @returns - void + */ +export function dismissRecommendedAccount( + client: SessionClient, + request: DismissRecommendedAccountsRequest, +): ResultAsync { + return client.mutation(MlDismissRecommendedAccountsMutation, { request }); +} + +/** + * Add post as not interested. + * + * ```ts + * const result = await addPostNotInterested(sessionClient, { + * post: postID('34fdasd...'), + * }); + * ``` + * + * @param client - Session Lens client. + * @param request - The post to add as not interested. + * @returns - void + */ +export function addPostNotInterested( + client: SessionClient, + request: PostNotInterestedRequest, +): ResultAsync { + return client.mutation(AddPostNotInterestedMutation, { request }); +} + +/** + * Remove post as not interested. + * + * ```ts + * const result = await undoPostNotInterested(sessionClient, { + * post: postID('34fdasd...'), + * }); + * ``` + * + * @param client - Session Lens client. + * @param request - The post to remove as not interested. + * @returns - void + */ +export function undoPostNotInterested( + client: SessionClient, + request: PostNotInterestedRequest, +): ResultAsync { + return client.mutation(UndoPostNotInterestedMutation, { request }); +} diff --git a/packages/client/src/actions/sponsorship.ts b/packages/client/src/actions/sponsorship.ts index 5ecee3bd3..a18384ef0 100644 --- a/packages/client/src/actions/sponsorship.ts +++ b/packages/client/src/actions/sponsorship.ts @@ -112,7 +112,7 @@ export function fetchSponsorshipSigners( * * @param client - Any Lens client. * @param request - The query request. - * @returns The paginated list of Sponsorship Signers. + * @returns The paginated list of excluded addresses. */ export function fetchSponsorshipLimitExclusions( client: AnyClient, diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index f6b97132b..7c212cb56 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -12,6 +12,7 @@ export * from './graph'; export * from './graphql'; export * from './group'; export * from './health'; +export * from './ml'; export * from './namespace'; export * from './notifications'; export * from './post'; diff --git a/packages/graphql/src/ml.ts b/packages/graphql/src/ml.ts new file mode 100644 index 000000000..816d92c51 --- /dev/null +++ b/packages/graphql/src/ml.ts @@ -0,0 +1,84 @@ +import type { FragmentOf } from 'gql.tada'; +import { AccountFragment, PaginatedResultInfoFragment, PostFragment } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +export const MlAccountRecommendationsQuery = graphql( + `query MlAccountRecommendations($request: MlaccountRecommendationsRequest!) { + value: mlAccountRecommendations(request: $request) { + __typename + items { + ...Account + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AccountFragment, PaginatedResultInfoFragment], +); +export type MlAccountRecommendationsRequest = RequestOf; + +export const PostForYouFragment = graphql( + `fragment PostForYou on PostForYou { + __typename + post { + ...Post + } + source + }`, + [PostFragment], +); +export type PostForYou = FragmentOf; + +export const MlPostsForYouQuery = graphql( + `query MlPostsForYou($request: MlpostsForYouRequest!) { + value: mlPostsForYou(request: $request) { + __typename + items { + ...PostForYou + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PostForYouFragment, PaginatedResultInfoFragment], +); +export type MlPostsForYouRequest = RequestOf; + +export const MlPostsExploreQuery = graphql( + `query MlPostsExplore($request: MlexplorePostsRequest!) { + value: mlPostsExplore(request: $request) { + __typename + items { + ...Post + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PostFragment, PaginatedResultInfoFragment], +); +export type MlPostsExploreRequest = RequestOf; + +export const MlDismissRecommendedAccountsMutation = graphql( + `mutation MlDismissRecommendedAccounts($request: DismissRecommendedAccountsRequest!) { + value: mlDismissRecommendedAccounts(request: $request) + }`, +); +export type DismissRecommendedAccountsRequest = RequestOf< + typeof MlDismissRecommendedAccountsMutation +>; + +export const AddPostNotInterestedMutation = graphql( + `mutation AddPostNotInterested($request: PostNotInterestedRequest!) { + value: addPostNotInterested(request: $request) + }`, +); +export const UndoPostNotInterestedMutation = graphql( + `mutation UndoPostNotInterested($request: PostNotInterestedRequest!) { + value: undoPostNotInterested(request: $request) + }`, +); +export type PostNotInterestedRequest = RequestOf; diff --git a/packages/graphql/src/namespace.ts b/packages/graphql/src/namespace.ts index 3644e1afd..7ac594231 100644 --- a/packages/graphql/src/namespace.ts +++ b/packages/graphql/src/namespace.ts @@ -104,19 +104,8 @@ export const NamespacesQuery = graphql( ); export type NamespacesRequest = RequestOf; -const UpdateNamespaceRulesResponseFragment = graphql( - `fragment UpdateNamespaceRulesResponse on UpdateNamespaceRulesResponse { - __typename - hash - }`, -); -export type UpdateNamespaceRulesResponse = FragmentOf; - const UpdateNamespaceRulesResultFragment = graphql( `fragment UpdateNamespaceRulesResult on UpdateNamespaceRulesResult { - ...on UpdateNamespaceRulesResponse { - ...UpdateNamespaceRulesResponse - } ...on SponsoredTransactionRequest { ...SponsoredTransactionRequest } @@ -128,7 +117,6 @@ const UpdateNamespaceRulesResultFragment = graphql( } }`, [ - UpdateNamespaceRulesResponseFragment, SelfFundedTransactionRequestFragment, SponsoredTransactionRequestFragment, TransactionWillFailFragment,