Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SNS endpoints to the sdk #1057

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './namespace';
export * from './notifications';
export * from './post';
export * from './posts';
export * from './sns';
export * from './timeline';
export * from './transactions';
export * from './username';
20 changes: 10 additions & 10 deletions packages/client/src/actions/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function post(
*
* ```ts
* const result = await repost(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -78,7 +78,7 @@ export function repost(
*
* ```ts
* const result = await editPost(sessionClient, {
* post: post.id,
* post: postId('42'),
* contentUri: uri('https://example.com'),
* });
* ```
Expand All @@ -99,7 +99,7 @@ export function editPost(
*
* ```ts
* const result = await deletePost(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -119,7 +119,7 @@ export function deletePost(
*
* ```ts
* const result = await addReaction(sessionClient, {
* post: post.id,
* post: postId('42'),
* reaction: "UPVOTE" | "DOWNVOTE",
* });
* ```
Expand All @@ -140,7 +140,7 @@ export function addReaction(
*
* ```ts
* const result = await undoReaction(sessionClient, {
* post: post.id,
* post: postId('42'),
* reaction: "UPVOTE" | "DOWNVOTE",
* });
* ```
Expand All @@ -161,7 +161,7 @@ export function undoReaction(
*
* ```ts
* const result = await bookmarkPost(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -181,7 +181,7 @@ export function bookmarkPost(
*
* ```ts
* const result = await undoBookmarkPost(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -201,7 +201,7 @@ export function undoBookmarkPost(
*
* ```ts
* const result = await hideReply(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -221,7 +221,7 @@ export function hideReply(
*
* ```ts
* const result = await unhideReply(sessionClient, {
* post: post.id,
* post: postId('42'),
* });
* ```
*
Expand All @@ -242,7 +242,7 @@ export function unhideReply(
* ```ts
* const result = await reportPost(sessionClient, {
* reason: "SCAM",
* post: post.id,
* post: postId('1234...'),
* });
* ```
*
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/actions/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function fetchPostReactions(
* Fetch bookmarked posts.
*
* ```ts
* const result = await fetchPostReactions(anyClient);
* const result = await fetchPostBookmarks(anyClient);
* ```
*
* @param client - Session Lens client.
Expand Down
79 changes: 79 additions & 0 deletions packages/client/src/actions/sns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type {
CreateSnsSubscriptionRequest,
DeleteSnsSubscriptionRequest,
GetSnsSubscriptionsRequest,
SnsSubscription,
} from '@lens-protocol/graphql';
import {
CreateSnsSubscriptionsMutation,
DeleteSnsSubscriptionMutation,
GetSnsSubscriptionsQuery,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
* Fetch a SNS subscription.
*
* ```ts
* const result = await fetchSnsSubscription(anyClient, {
* account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The details of the SNS subscription.
*/
export function fetchSnsSubscription(
client: AnyClient,
request: GetSnsSubscriptionsRequest,
): ResultAsync<Array<SnsSubscription> | [], UnexpectedError> {
return client.query(GetSnsSubscriptionsQuery, { request });
}

/**
* Create SNS subscriptions.
*
* ```ts
* const result = await createSnsSubscription(sessionClient, {
* topics: [
* { accountMentioned: evmAddress('0x1234...') },
* { accountFollowed: evmAddress('0x90ab...') },
* ],
* webhook: uri('https://example.com'),
* });
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns List of SNS subscriptions created.
*/
export function createSnsSubscriptions(
client: SessionClient,
request: CreateSnsSubscriptionRequest,
): ResultAsync<Array<SnsSubscription>, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateSnsSubscriptionsMutation, { request });
}

/**
* Delete a SNS subscription.
*
* ```ts
* const result = await deleteSnsSubscription(sessionClient, {
* id: "1234-dasdf-...",
* });
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Void
*/
export function deleteSnsSubscription(
client: SessionClient,
request: DeleteSnsSubscriptionRequest,
): ResultAsync<void, UnexpectedError | UnauthenticatedError> {
return client.mutation(DeleteSnsSubscriptionMutation, { request });
}
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './health';
export * from './namespace';
export * from './notifications';
export * from './post';
export * from './sns';
export * from './timeline';
export * from './transactions';
export * from './username';
43 changes: 43 additions & 0 deletions packages/graphql/src/sns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { FragmentOf } from 'gql.tada';
import { type RequestOf, graphql } from './graphql';

const SnsSubscriptionFragment = graphql(
`fragment SnsSubscription on SnsSubscription {
__typename
id
account
webhook
app
topic
topicArn
filter
}`,
);
export type SnsSubscription = FragmentOf<typeof SnsSubscriptionFragment>;

export const GetSnsSubscriptionsQuery = graphql(
`query GetSnsSubscriptions($request: GetSnsSubscriptionsRequest!) {
value: getSnsSubscriptions(request: $request) {
...SnsSubscription
}
}`,
[SnsSubscriptionFragment],
);
export type GetSnsSubscriptionsRequest = RequestOf<typeof GetSnsSubscriptionsQuery>;

export const CreateSnsSubscriptionsMutation = graphql(
`mutation CreateSnsSubscriptions($request: CreateSnsSubscriptionRequest!) {
value: createSnsSubscriptions(request: $request) {
...SnsSubscription
}
}`,
[SnsSubscriptionFragment],
);
export type CreateSnsSubscriptionRequest = RequestOf<typeof CreateSnsSubscriptionsMutation>;

export const DeleteSnsSubscriptionMutation = graphql(
`mutation DeleteSnsSubscription($request: DeleteSnsSubscriptionRequest!) {
value: deleteSnsSubscription(request: $request)
}`,
);
export type DeleteSnsSubscriptionRequest = RequestOf<typeof DeleteSnsSubscriptionMutation>;
Loading