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 2 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, {
juangm marked this conversation as resolved.
Show resolved Hide resolved
* topics: [
* { accountMentioned: evmAddress('0x1234...') },
* { accountFollowed: evmAddress('0x90ab...') },
* ],
* webhook: '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, {
juangm marked this conversation as resolved.
Show resolved Hide resolved
* 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 });
}
107 changes: 106 additions & 1 deletion packages/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,7 @@ The reason for the failure is provided.
type FailedTransactionStatus {
reason: String!
blockTimestamp: DateTime!
summary: [SubOperationStatus!]!
}

input FeeFollowRuleInput {
Expand Down Expand Up @@ -2010,6 +2011,7 @@ If the transaction involves any metadata, the metadata has been snapshotted and
"""
type FinishedTransactionStatus {
blockTimestamp: DateTime!
summary: [SubOperationStatus!]!
}

type FollowNotification {
Expand Down Expand Up @@ -2438,6 +2440,12 @@ type ImageMetadata {
content: String!
}

enum IndexingStatus {
FINISHED
PENDING
FAILED
}

type InvalidUsername {
reason: String!
}
Expand Down Expand Up @@ -3939,6 +3947,7 @@ The transaction could be:
"""
type PendingTransactionStatus {
blockTimestamp: DateTime!
summary: [SubOperationStatus!]!
}

"""PhysicalAddress"""
Expand Down Expand Up @@ -4858,7 +4867,7 @@ type SnsSubscription {
app: EvmAddress
topic: SnsNotificationType!
topicArn: String!
attributes: JSON!
filter: JSON!
}

input SnsTopicInput @oneOf {
Expand Down Expand Up @@ -4989,6 +4998,11 @@ type StoryMetadata {
content: String!
}

type SubOperationStatus {
operation: TransactionOperation!
status: IndexingStatus!
}

input SwitchAccountRequest {
account: EvmAddress!
}
Expand Down Expand Up @@ -5208,6 +5222,97 @@ type TransactionMetadata {
content: String!
}

enum TransactionOperation {
juangm marked this conversation as resolved.
Show resolved Hide resolved
ACCESS_CONTROL_ROLE_GRANTED
ACCESS_CONTROL_ROLE_REVOKED
ACCESS_CONTROL_FACTORY_OWNER_ADMIN_DEPLOYMENT
ACCOUNT_FACTORY_DEPLOYMENT
ACCOUNT_MANAGER_ADDED
ACCOUNT_MANAGER_REMOVED
ACCOUNT_MANAGER_UPDATED
ACCOUNT_OWNER_TRANSFERRED
ACCOUNT_METADATA_URI_SET
APP_FACTORY_DEPLOYMENT
APP_ACCESS_CONTROL_ADDED
APP_ACCESS_CONTROL_UPDATED
APP_DEFAULT_FEED_SET
APP_EXTRA_DATA_ADDED
APP_EXTRA_DATA_REMOVED
APP_EXTRA_DATA_UPDATED
APP_FEED_ADDED
APP_FEED_REMOVED
APP_GRAPH_ADDED
APP_GRAPH_REMOVED
APP_GROUP_ADDED
APP_GROUP_REMOVED
APP_METADATA_URI_SET
APP_SIGNER_ADDED
APP_SIGNER_REMOVED
APP_SOURCE_STAMP_VERIFICATION_SET
APP_PAYMASTER_ADDED
APP_PAYMASTER_REMOVED
APP_TREASURY_SET
APP_USERNAME_ADDED
APP_USERNAME_REMOVED
FEED_ACCESS_CONTROL_ADDED
FEED_ACCESS_CONTROL_UPDATED
FEED_EXTRA_DATA_ADDED
FEED_EXTRA_DATA_REMOVED
FEED_EXTRA_DATA_UPDATED
FEED_METADATA_URI_SET
FEED_POST_CREATED
FEED_POST_DELETED
FEED_POST_EDITED
GRAPH_FACTORY_DEPLOYMENT
GRAPH_ACCESS_CONTROL_ADDED
GRAPH_ACCESS_CONTROL_UPDATED
GRAPH_EXTRA_DATA_ADDED
GRAPH_EXTRA_DATA_REMOVED
GRAPH_EXTRA_DATA_UPDATED
GRAPH_FOLLOWED
GRAPH_METADATA_URI_SET
GRAPH_UNFOLLOWED
GROUP_FACTORY_DEPLOYMENT
GROUP_MEMBER_JOINED
GROUP_MEMBER_LEFT
GROUP_MEMBER_REMOVED
GROUP_ACCESS_CONTROL_ADDED
GROUP_ACCESS_CONTROL_UPDATED
GROUP_EXTRA_DATA_ADDED
GROUP_EXTRA_DATA_REMOVED
GROUP_EXTRA_DATA_UPDATED
GROUP_METADATA_URI_SET
SPONSOR_FREE_PAYMASTER_CREATED
SPONSOR_ADDED_TO_APPROVED_SIGNERS
SPONSOR_METADATA_URI_CHANGED
USERNAME_ASSIGNED
USERNAME_CREATED
USERNAME_FACTORY_DEPLOYMENT
USERNAME_REMOVED
USERNAME_UNASSIGNED
USERNAME_ACCESS_CONTROL_ADDED
USERNAME_ACCESS_CONTROL_UPDATED
USERNAME_EXTRA_DATA_ADDED
USERNAME_EXTRA_DATA_REMOVED
USERNAME_EXTRA_DATA_UPDATED
USERNAME_METADATA_URI_SET
SPONSORSHIP_ACCESS_CONTROL_ADDED
SPONSORSHIP_ACCESS_CONTROL_UPDATED
SPONSORSHIP_ADDED_TO_EXCLUSION_LIST
SPONSORSHIP_REMOVED_FROM_EXCLUSION_LIST
SPONSORSHIP_FACTORY_DEPLOYMENT
SPONSORSHIP_FUNDS_SPENT
SPONSORSHIP_GRANT_REVOKED
SPONSORSHIP_GRANTED_FUNDS
SPONSORSHIP_METADATA_URI_SET
SPONSORSHIP_PAUSED
SPONSORSHIP_RATE_LIMITS_CHANGED
SPONSORSHIP_UNPAUSED
SPONSORSHIP_SIGNER_ADDED
SPONSORSHIP_SIGNER_REMOVED
FEED_FACTORY_DEPLOYMENT
}

input TransactionStatusRequest {
txHash: TxHash!
}
Expand Down
Loading
Loading