Skip to content

Commit

Permalink
Merge branch 'next' into T-23255/js-actions-add-username-mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm authored Dec 11, 2024
2 parents 5eac561 + ab16f96 commit 3cec1a5
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/client/src/actions/admins.ts
Original file line number Diff line number Diff line change
@@ -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<AddAdminsResult, UnexpectedError | UnauthenticatedError> {
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<RemoveAdminsResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(RemoveAdminsMutation, { request });
}
24 changes: 24 additions & 0 deletions packages/client/src/actions/feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CreateFeedRequest, CreateFeedResult } from '@lens-protocol/graphql';
import { CreateFeedMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
* Create a Feed
*
* ```ts
* const result = await createFeed(sessionClient);
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function createFeed(
client: SessionClient,
request: CreateFeedRequest,
): ResultAsync<CreateFeedResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateFeedMutation, { request });
}
24 changes: 24 additions & 0 deletions packages/client/src/actions/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CreateGraphRequest, CreateGraphResult } from '@lens-protocol/graphql';
import { CreateGraphMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
* Create a Graph
*
* ```ts
* const result = await createGraph(sessionClient);
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function createGraph(
client: SessionClient,
request: CreateGraphRequest,
): ResultAsync<CreateGraphResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGraphMutation, { request });
}
71 changes: 71 additions & 0 deletions packages/client/src/actions/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type {
CreateGroupRequest,
CreateGroupResult,
JoinGroupRequest,
JoinGroupResult,
LeaveGroupRequest,
LeaveGroupResult,
} from '@lens-protocol/graphql';
import { CreateGroupMutation, JoinGroupMutation, LeaveGroupMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
* Create a Group
*
* ```ts
* const result = await createGroup(sessionClient);
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function createGroup(
client: SessionClient,
request: CreateGroupRequest,
): ResultAsync<CreateGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGroupMutation, { request });
}

/**
* Join a Group
*
* ```ts
* const result = await joinGroup(sessionClient, {
* group: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function joinGroup(
client: SessionClient,
request: JoinGroupRequest,
): ResultAsync<JoinGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(JoinGroupMutation, { request });
}

/**
* Leave a Group
*
* ```ts
* const result = await leaveGroup(sessionClient, {
* group: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function leaveGroup(
client: SessionClient,
request: LeaveGroupRequest,
): ResultAsync<LeaveGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(LeaveGroupMutation, { request });
}
5 changes: 5 additions & 0 deletions packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
export * from './account';
export * from './admins';
export * from './app';
export * from './authentication';
export * from './feed';
export * from './follow';
export * from './health';
export * from './graph';
export * from './namespace';
export * from './group';
export * from './post';
export * from './posts';
export * from './timeline';
Expand Down
30 changes: 30 additions & 0 deletions packages/client/src/actions/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {
CreateUsernameNamespaceRequest,
CreateUsernameNamespaceResult,
} from '@lens-protocol/graphql';
import { CreateUsernameNamespaceMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
* Create a Namespace
*
* ```ts
* const result = await createUsernameNamespace(sessionClient, {
* symbol: 'NAME',
* namespace: 'custom-namespace',
* });
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function createUsernameNamespace(
client: SessionClient,
request: CreateUsernameNamespaceRequest,
): ResultAsync<CreateUsernameNamespaceResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateUsernameNamespaceMutation, { request });
}
67 changes: 67 additions & 0 deletions packages/client/src/actions/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ import type {
DeletePostRequest,
DeletePostResult,
EditPostRequest,
HideReplyRequest,
PostResult,
UndoBookmarkPostRequest,
UndoReactionRequest,
UndoReactionResult,
UnhideReplyRequest,
} from '@lens-protocol/graphql';
import {
AddReactionMutation,
BookmarkPostMutation,
DeletePostMutation,
EditPostMutation,
HideReplyMutation,
PostMutation,
ReportPostMutation,
RepostMutation,
UndoBookmarkPostMutation,
UndoReactionMutation,
UnhideReplyMutation,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { ReportPostRequest } from '@lens-protocol/graphql';
import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

Expand Down Expand Up @@ -189,3 +195,64 @@ export function undoBookmarkPost(
): ResultAsync<void, UnauthenticatedError | UnexpectedError> {
return client.mutation(UndoBookmarkPostMutation, { request });
}

/**
* Hide a reply.
*
* ```ts
* const result = await hideReply(sessionClient, {
* post: post.id,
* });
* ```
*
* @param client - The session client.
* @param request - The mutation request.
* @returns void
*/
export function hideReply(
client: SessionClient,
request: HideReplyRequest,
): ResultAsync<void, UnauthenticatedError | UnexpectedError> {
return client.mutation(HideReplyMutation, { request });
}

/**
* Unhide a reply.
*
* ```ts
* const result = await unhideReply(sessionClient, {
* post: post.id,
* });
* ```
*
* @param client - The session client.
* @param request - The mutation request.
* @returns void
*/
export function unhideReply(
client: SessionClient,
request: UnhideReplyRequest,
): ResultAsync<void, UnauthenticatedError | UnexpectedError> {
return client.mutation(UnhideReplyMutation, { request });
}

/**
* Report a post
*
* ```ts
* const result = await reportPost(sessionClient, {
* reason: "SCAM",
* post: post.id,
* });
* ```
*
* @param client - The session client.
* @param request - The mutation request.
* @returns void
*/
export function reportPost(
client: SessionClient,
request: ReportPostRequest,
): ResultAsync<void, UnauthenticatedError | UnexpectedError> {
return client.mutation(ReportPostMutation, { request });
}
59 changes: 59 additions & 0 deletions packages/graphql/src/admins.ts
Original file line number Diff line number Diff line change
@@ -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<typeof AddAdminsResult>;

export const AddAdminsMutation = graphql(
`mutation AddAdmins($request: AddAdminsRequest!) {
value: addAdmins(request: $request) {
...AddAdminsResult
}
}`,
[AddAdminsResult],
);
export type AddAdminsRequest = RequestOf<typeof AddAdminsMutation>;

const RemoveAdminsResult = graphql(
`fragment RemoveAdminsResult on RemoveAdminsResult {
...on SponsoredTransactionRequest {
...SponsoredTransactionRequest
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[SponsoredTransactionRequest, SelfFundedTransactionRequest, TransactionWillFail],
);
export type RemoveAdminsResult = FragmentOf<typeof RemoveAdminsResult>;

export const RemoveAdminsMutation = graphql(
`mutation RemoveAdmins($request: RemoveAdminsRequest!) {
value: removeAdmins(request: $request) {
...RemoveAdminsResult
}
}`,
[RemoveAdminsResult],
);
export type RemoveAdminsRequest = RequestOf<typeof RemoveAdminsMutation>;
Loading

0 comments on commit 3cec1a5

Please sign in to comment.