Skip to content

Latest commit

 

History

History
977 lines (578 loc) · 25.8 KB

index.MerkleAPIClient.md

File metadata and controls

977 lines (578 loc) · 25.8 KB

@standard-crypto/farcaster-js / Modules / index / MerkleAPIClient

Class: MerkleAPIClient

index.MerkleAPIClient

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new MerkleAPIClient(walletOrAuthToken?, «destructured»?)

Instantiates a MerkleAPIClient

Note: A Wallet must be provided if the API client is to mint new AuthTokens

Parameters

Name Type
walletOrAuthToken? Wallet | { expiresAt?: number ; secret: string }
«destructured» Object
› axiosInstance? AxiosInstance
› logger? Logger

Defined in

src/merkleAPI/MerkleAPIClient.ts:74

Properties

apis

Readonly apis: Object

Type declaration

Name Type
assets AssetsApi
auth AuthApi
casts CastsApi
follows FollowsApi
miscellaneous MiscellaneousApi
notifications NotificationsApi
signerRequests SignerRequestsApi
user UserApi
users UsersApi
verifications VerificationsApi
watches WatchesApi

Defined in

src/merkleAPI/MerkleAPIClient.ts:55

Methods

checkServerAcceptsAuthToken

checkServerAcceptsAuthToken(authToken): Promise<void>

Parameters

Name Type
authToken AuthToken

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:145


createAuthToken

createAuthToken(expiryDurationMillis?, «destructured»?): Promise<AuthToken>

Creates a new auth token from the signing key of the Wallet configured with this API client.

Parameters

Name Type Default value
expiryDurationMillis number TEN_MINUTES_IN_MILLIS
«destructured» Object {}
› checkServerAcceptsToken undefined | boolean undefined

Returns

Promise<AuthToken>

Defined in

src/merkleAPI/MerkleAPIClient.ts:155


createSignerRequest

createSignerRequest(publicKey, name): Promise<V2SignerRequestsPost200ResponseResult>

Creates a SignerRequest. See Warpcast documentation for more details.

Note: Authentication credentials are not required for this API endpoint.

Parameters

Name Type
publicKey string
name string

Returns

Promise<V2SignerRequestsPost200ResponseResult>

Defined in

src/merkleAPI/MerkleAPIClient.ts:201


deleteCast

deleteCast(castOrCastHash): Promise<void>

Delete a cast

Parameters

Name Type
castOrCastHash string | Cast

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:240


deleteRecast

deleteRecast(castOrCastHash): Promise<void>

Delete a recast

Parameters

Name Type
castOrCastHash string | Cast

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:254


fetchCast

fetchCast(castOrCastHash): Promise<undefined | Cast>

Gets information about an individual cast

Parameters

Name Type
castOrCastHash string | Cast

Returns

Promise<undefined | Cast>

Defined in

src/merkleAPI/MerkleAPIClient.ts:268


fetchCastLikes

fetchCastLikes(castOrCastHash, «destructured»?): AsyncGenerator<CastReaction, void, undefined>

Lists a given cast's likes

Parameters

Name Type
castOrCastHash string | Cast
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<CastReaction, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:436


fetchCastsForUser

fetchCastsForUser(user, «destructured»?): AsyncGenerator<Cast, void, undefined>

Gets all casts (including replies and recasts) created by the specified user.

@Note: Deleted cast filtering is applied server-side while recast filtering is applied client-side.

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› includeDeletedCasts undefined | boolean
› includeRecasts undefined | boolean
› pageSize undefined | number

Returns

AsyncGenerator<Cast, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:328


fetchCastsInThread

fetchCastsInThread(threadParent, «destructured»?): AsyncGenerator<Cast, void, undefined>

Fetches casts in a given thread. Note that the parent provided by the caller is included in the response.

Parameters

Name Type
threadParent Cast | { hash: string }
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<Cast, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:295


fetchCurrentUser

fetchCurrentUser(): Promise<User>

Gets the currently authenticated user

Returns

Promise<User>

Defined in

src/merkleAPI/MerkleAPIClient.ts:364


fetchCustodyAddressForUser

fetchCustodyAddressForUser(userOrUsername): Promise<string>

Parameters

Name Type
userOrUsername string | User

Returns

Promise<string>

Defined in

src/merkleAPI/MerkleAPIClient.ts:370


fetchLatestCastForUser

fetchLatestCastForUser(user, includeRecasts?): Promise<undefined | Cast>

Fetch the latest cast for the user, if there is one

Parameters

Name Type Default value
user Object undefined
user.fid number undefined
includeRecasts boolean false

Returns

Promise<undefined | Cast>

Defined in

src/merkleAPI/MerkleAPIClient.ts:389


fetchMentionAndReplyNotifications

fetchMentionAndReplyNotifications(«destructured»?): AsyncGenerator<NotificationCastMention | NotificationCastReply, void, undefined>

Parameters

Name Type
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<NotificationCastMention | NotificationCastReply, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:403


fetchRecentCasts

fetchRecentCasts(«destructured»?): AsyncGenerator<Cast, void, undefined>

A list of the latest casts across all users in reverse chronological order based on timestamp

Parameters

Name Type
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<Cast, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:470


fetchRecentUsers

fetchRecentUsers(«destructured»?): AsyncGenerator<User, void, undefined>

A list of users in reverse chronological order based on sign up.

Parameters

Name Type
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<User, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:501


fetchSignerRequest

fetchSignerRequest(token): Promise<undefined | SignerRequest>

Fetches an existing SignerRequest. See Warpcast documentation for more details.

Note: Authentication credentials are not required for this API endpoint.

Parameters

Name Type
token string

Returns

Promise<undefined | SignerRequest>

Defined in

src/merkleAPI/MerkleAPIClient.ts:534


fetchUserAssetCollections

fetchUserAssetCollections(user, «destructured»?): AsyncGenerator<AssetCollection, void, undefined>

Fetch all asset collections owned by the specified user.

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<AssetCollection, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:557


fetchUserAssetsInCollection

fetchUserAssetsInCollection(user, collectionId, «destructured»?): AsyncGenerator<Asset, void, undefined>

Fetch all assets owned by a given user for a specific collection.

Parameters

Name Type
user Object
user.fid number
collectionId string
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<Asset, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:588


fetchUserCastLikes

fetchUserCastLikes(user, «destructured»?): AsyncGenerator<CastReaction, void, undefined>

Fetch all likes by a given user.

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<CastReaction, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:621


fetchUserFollowers

fetchUserFollowers(user, «destructured»?): AsyncGenerator<User, void, undefined>

Get all users that follow the specified user

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<User, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:651


fetchUserFollowing

fetchUserFollowing(user, «destructured»?): AsyncGenerator<User, void, undefined>

Get all users the specified user is following.

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<User, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:682


fetchUserVerifications

fetchUserVerifications(user, «destructured»?): AsyncGenerator<Verification, void, undefined>

Parameters

Name Type
user Object
user.fid number
«destructured» Object
› pageSize undefined | number

Returns

AsyncGenerator<Verification, void, undefined>

Defined in

src/merkleAPI/MerkleAPIClient.ts:710


followUser

followUser(user): Promise<void>

Follow a user

Parameters

Name Type
user Object
user.fid number

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:739


getOrCreateValidAuthToken

getOrCreateValidAuthToken(): Promise<AuthToken>

Returns an existing valid auth token if one exists, otherwise provisions a new one from the signing key of the given Wallet.

Note that provisioning a new auth token requires an API round trip.

Returns

Promise<AuthToken>

Defined in

src/merkleAPI/MerkleAPIClient.ts:218


healthcheck

healthcheck(): Promise<{ status: string }>

Check the status of the API. Expected status is "ok".

Note: authentication parameters are not required.

Returns

Promise<{ status: string }>

Defined in

src/merkleAPI/MerkleAPIClient.ts:751


lookupUserByFid

lookupUserByFid(fid): Promise<undefined | User>

Gets the specified user via their FID (if found)

Parameters

Name Type
fid number

Returns

Promise<undefined | User>

Defined in

src/merkleAPI/MerkleAPIClient.ts:759


lookupUserByUsername

lookupUserByUsername(username): Promise<undefined | User>

Gets the specified user via their username (if found)

Parameters

Name Type
username string

Returns

Promise<undefined | User>

Defined in

src/merkleAPI/MerkleAPIClient.ts:781


lookupUserByVerification

lookupUserByVerification(address): Promise<undefined | User>

Checks if a given Ethereum address has a Farcaster user associated with it. Note: if an address is associated with multiple users, the API will return the user who most recently published a verification with the address (based on when Merkle received the proof, not a self-reported timestamp).

Parameters

Name Type
address string

Returns

Promise<undefined | User>

Defined in

src/merkleAPI/MerkleAPIClient.ts:804


publishCast

publishCast(text, replyTo?, embeds?): Promise<Cast>

Publishes a cast for the currently authenticated user

Parameters

Name Type
text string
replyTo? Cast | { fid: number ; hash: string }
embeds? string[]

Returns

Promise<Cast>

Defined in

src/merkleAPI/MerkleAPIClient.ts:824


reactToCast

reactToCast(reaction, cast): Promise<CastReaction>

React to a cast

Parameters

Name Type
reaction "like"
cast Cast | { castHash: string }

Returns

Promise<CastReaction>

Defined in

src/merkleAPI/MerkleAPIClient.ts:856


recast

recast(castOrCastHash): Promise<void>

Recast a cast

Parameters

Name Type
castOrCastHash string | Cast

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:881


removeReactionToCast

removeReactionToCast(reaction, cast): Promise<void>

Remove a reaction to a cast

Parameters

Name Type
reaction "like"
cast Cast | { castHash: string }

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:897


revokeAllAuthTokens

revokeAllAuthTokens(): Promise<void>

Revokes all other auth tokens created for this user, with the exception of the one token still in use by this particular instance.

You may still use this instance after calling this method, but any other applications using Auth Tokens for your user will most likely cease working.

Credit to DavidFurlong for this approach: https://github.com/davidfurlong/farcaster-auth-tokens/blob/a114450a1d511caa044e8ace0674146e1ace2531/revoke-all.ts

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:946


revokeAuthToken

revokeAuthToken(authToken): Promise<void>

Parameters

Name Type
authToken AuthToken

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:915


unfollowUser

unfollowUser(user): Promise<void>

Unfollow a user

Parameters

Name Type
user Object
user.fid number

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:971


unwatchCast

unwatchCast(cast): Promise<void>

Unwatch a cast

Parameters

Name Type
cast Cast | { castHash: string ; casterFid: number }

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:981


watchCast

watchCast(cast): Promise<void>

Watch a cast

Parameters

Name Type
cast Cast | { castHash: string ; casterFid: number }

Returns

Promise<void>

Defined in

src/merkleAPI/MerkleAPIClient.ts:1004


isApiErrorResponse

Static isApiErrorResponse(error): error is WithRequired<AxiosError<ApiErrorResponse, any>, "response">

Utility for parsing errors returned by the Merkle API server. Returns true if the given error is caused by an error response from the server, and narrows the type of error accordingly.

Parameters

Name Type
error any

Returns

error is WithRequired<AxiosError<ApiErrorResponse, any>, "response">

Defined in

src/merkleAPI/MerkleAPIClient.ts:135