diff --git a/packages/client/src/actions/admins.ts b/packages/client/src/actions/admins.ts new file mode 100644 index 000000000..094fabfe7 --- /dev/null +++ b/packages/client/src/actions/admins.ts @@ -0,0 +1,53 @@ +import type { + AddAdminsRequest, + AddAdminsResult, + RemoveAdminsRequest, + RemoveAdminsResult, +} from '@lens-protocol/graphql'; +import { AddAdminsMutation, RemoveAdminsMutation } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { SessionClient } from '../clients'; +import type { UnauthenticatedError, UnexpectedError } from '../errors'; + +/** + * Add Admins + * + * ```ts + * const result = await addAdmins(sessionClient{ + * admins: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')], + * address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), + * }); + * ``` + * + * @param client - The session client logged as a builder. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function addAdmins( + client: SessionClient, + request: AddAdminsRequest, +): ResultAsync { + return client.mutation(AddAdminsMutation, { request }); +} + +/** + * Remove admins + * + * ```ts + * const result = await removeAdmins(sessionClient{ + * admins: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')], + * address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), + * }); + * ``` + * + * @param client - The session client for the authenticated Account. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function removeAdmins( + client: SessionClient, + request: RemoveAdminsRequest, +): ResultAsync { + return client.mutation(RemoveAdminsMutation, { request }); +} diff --git a/packages/client/src/actions/index.ts b/packages/client/src/actions/index.ts index d3c97fe25..9bafa0133 100644 --- a/packages/client/src/actions/index.ts +++ b/packages/client/src/actions/index.ts @@ -1,8 +1,9 @@ export * from './account'; +export * from './admins'; export * from './app'; export * from './authentication'; export * from './follow'; export * from './post'; export * from './posts'; -export * from './transactions'; export * from './timeline'; +export * from './transactions'; diff --git a/packages/graphql/src/admins.ts b/packages/graphql/src/admins.ts new file mode 100644 index 000000000..64edd50b2 --- /dev/null +++ b/packages/graphql/src/admins.ts @@ -0,0 +1,59 @@ +import type { FragmentOf } from 'gql.tada'; +import { + SelfFundedTransactionRequest, + SponsoredTransactionRequest, + TransactionWillFail, +} from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +const AddAdminsResult = graphql( + `fragment AddAdminsResult on AddAdminsResult { + ...on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [SponsoredTransactionRequest, SelfFundedTransactionRequest, TransactionWillFail], +); +export type AddAdminsResult = FragmentOf; + +export const AddAdminsMutation = graphql( + `mutation AddAdmins($request: AddAdminsRequest!) { + value: addAdmins(request: $request) { + ...AddAdminsResult + } + }`, + [AddAdminsResult], +); +export type AddAdminsRequest = RequestOf; + +const RemoveAdminsResult = graphql( + `fragment RemoveAdminsResult on RemoveAdminsResult { + ...on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [SponsoredTransactionRequest, SelfFundedTransactionRequest, TransactionWillFail], +); +export type RemoveAdminsResult = FragmentOf; + +export const RemoveAdminsMutation = graphql( + `mutation RemoveAdmins($request: RemoveAdminsRequest!) { + value: removeAdmins(request: $request) { + ...RemoveAdminsResult + } + }`, + [RemoveAdminsResult], +); +export type RemoveAdminsRequest = RequestOf; diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index a4190f76b..def1cea07 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -1,4 +1,5 @@ export * from './accounts'; +export * from './admins'; export * from './app'; export * from './authentication'; export * from './enums';