Skip to content

Commit

Permalink
Update the oas and sdk and add publishFarcasterAction
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyaschorge committed Oct 21, 2024
1 parent 281496b commit 99ec331
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 58 deletions.
68 changes: 55 additions & 13 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
ChannelMemberInviteListResponse,
ChannelMemberListResponse,
FollowersResponse,
FarcasterActionReqBodyAction,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -265,7 +266,7 @@ export class NeynarAPIClient {
/**
* @deprecated
* Now deprecated, use v2's `lookupUserByUsernameV2` instead.
*
*
* Retrieves the specified user via their username (if found).
*
* @param {string} username - The username of the user whose information is being retrieved.
Expand Down Expand Up @@ -679,6 +680,48 @@ export class NeynarAPIClient {

// ============ v2 APIs ============

// ------------ Action ------------

/**
* Perform actions on behalf of users across different apps.
*
* This method enables an application to securely communicate and trigger actions in another app on behalf of a mutual user.
* The actions are performed by signing messages using the user's Farcaster signer, ensuring that all actions are authenticated and authorized.
*
* @param {FarcasterActionReqBody} farcasterActionReqBody - The request body containing the action details and the necessary information to perform the action.
*
* @returns {Promise<Object>} A promise that resolves to an object containing the response data.
* The structure of the response can vary depending on the action performed, as defined by the API's response schema by the app performing the action.
*
* @example
* // Example: Perform an action on behalf of a user
* const signerUuid = '19d0c5fd-9b33-4a48-a0e2-bc7b0555baec';
* const base_url = "https://appb.example.com",
* const action = {
* type: "sendMessage",
* payload: {
* "message": "Hello from App A!"
* }
* };
*
* client.publishFarcasterAction(signerUuid, url, action).then(response => {
* console.log('Action Response:', response); // Outputs the response of the action
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/docs/farcaster-actions-spec).
*/
public async publishFarcasterAction(
signerUuid: string,
base_url: string,
action: FarcasterActionReqBodyAction
): Promise<Object> {
return await this.clients.v2.publishFarcasterAction(
signerUuid,
base_url,
action
);
}

// ------------ Signer ------------

/**
Expand Down Expand Up @@ -1360,14 +1403,14 @@ export class NeynarAPIClient {
* console.log('Cast Conversation Information:', response); // Displays the detailed structure of the specified cast conversation
* });
*
*
*
* @example
* // Implement above and below 'the fold', generally seen in clients as "show more replies".
* // Fetch first page above the fold:
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: true,
* fold: 'above',
Expand All @@ -1381,7 +1424,7 @@ export class NeynarAPIClient {
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: false,
* fold: 'above',
Expand All @@ -1395,7 +1438,7 @@ export class NeynarAPIClient {
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: false,
* fold: 'below',
Expand All @@ -1405,8 +1448,8 @@ export class NeynarAPIClient {
* }).then(response => {
* console.log('Casts from below the fold:', response.conversation.cast.direct_replies);
* });
*
*
*
*
* // Refer to the Neynar API documentation for more details and advanced options:
* // https://docs.neynar.com/reference/cast-conversation
*/
Expand All @@ -1418,7 +1461,7 @@ export class NeynarAPIClient {
includeChronologicalParentCasts?: boolean;
viewerFid?: number;
sortType?: CastConversationSortType;
fold?: 'above' | 'below';
fold?: "above" | "below";
limit?: number;
cursor?: string;
}
Expand Down Expand Up @@ -3009,7 +3052,8 @@ export class NeynarAPIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-channel-memberships).
*/
public async fetchUserChannelMemberships(fid: number,
public async fetchUserChannelMemberships(
fid: number,
options?: {
limit?: number;
cursor?: string;
Expand Down Expand Up @@ -3822,7 +3866,7 @@ export class NeynarAPIClient {
public async fetchBanList(
options: { limit?: number; cursor?: string } = {}
): Promise<BanListResponse> {
const { limit, cursor = '' } = options;
const { limit, cursor = "" } = options;
return await this.clients.v2.fetchBanList({ limit, cursor });
}

Expand All @@ -3842,9 +3886,7 @@ export class NeynarAPIClient {
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/add-ban).
*
*/
public async publishBans(
fids: number[]
): Promise<BanResponse> {
public async publishBans(fids: number[]): Promise<BanResponse> {
return await this.clients.v2.publishBans(fids);
}

Expand Down
137 changes: 92 additions & 45 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ import {
ChannelMemberListResponse,
ChannelFollowReqBody,
FollowersResponse,
FarcasterActionReqBody,
FarcasterActionReqBodyAction,
ActionApi,
} from "./openapi-farcaster";
import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
Expand All @@ -126,6 +129,7 @@ export class NeynarV2APIClient {
private readonly apiKey: string;

public readonly apis: {
action: ActionApi;
signer: SignerApi;
user: UserApi;
cast: CastApi;
Expand Down Expand Up @@ -210,6 +214,7 @@ export class NeynarV2APIClient {
});

this.apis = {
action: new ActionApi(config, undefined, axiosInstance),
signer: new SignerApi(config, undefined, axiosInstance),
user: new UserApi(config, undefined, axiosInstance),
cast: new CastApi(config, undefined, axiosInstance),
Expand Down Expand Up @@ -246,6 +251,54 @@ export class NeynarV2APIClient {
);
}

// ------------ Action ------------

/**
* Perform actions on behalf of users across different apps.
*
* This method enables an application to securely communicate and trigger actions in another app on behalf of a mutual user.
* The actions are performed by signing messages using the user's Farcaster signer, ensuring that all actions are authenticated and authorized.
*
* @param {FarcasterActionReqBody} farcasterActionReqBody - The request body containing the action details and the necessary information to perform the action.
*
* @returns {Promise<Object>} A promise that resolves to an object containing the response data.
* The structure of the response can vary depending on the action performed, as defined by the API's response schema by the app performing the action.
*
* @example
* // Example: Perform an action on behalf of a user
* const signerUuid = '19d0c5fd-9b33-4a48-a0e2-bc7b0555baec';
* const base_url = "https://appb.example.com",
* const action = {
* type: "sendMessage",
* payload: {
* "message": "Hello from App A!"
* }
* };
*
* client.publishFarcasterAction(signerUuid, url, action).then(response => {
* console.log('Action Response:', response); // Outputs the response of the action
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/docs/farcaster-actions-spec).
*/
public async publishFarcasterAction(
signerUuid: string,
baseUrl: string,
action: FarcasterActionReqBodyAction
) {
const farcasterActionReqBody: FarcasterActionReqBody = {
signer_uuid: signerUuid,
base_url: baseUrl,
action: action,
};

const response = await this.apis.action.publishFarcasterAction(
this.apiKey,
farcasterActionReqBody
);
return response.data;
}

// ------------ Signer ------------

/**
Expand Down Expand Up @@ -1032,19 +1085,19 @@ export class NeynarV2APIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-by-username-v2).
*/
public async lookupUserByUsernameV2(
username: string,
options?: {
viewerFid?: number;
}
): Promise<UserResponse> {
const response = await this.apis.user.userByUsernameV2(
this.apiKey,
username,
options?.viewerFid
);
return response.data;
public async lookupUserByUsernameV2(
username: string,
options?: {
viewerFid?: number;
}
): Promise<UserResponse> {
const response = await this.apis.user.userByUsernameV2(
this.apiKey,
username,
options?.viewerFid
);
return response.data;
}

// ------------ Cast ------------

Expand Down Expand Up @@ -1171,7 +1224,7 @@ export class NeynarV2APIClient {
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: true,
* fold: 'above',
Expand All @@ -1185,7 +1238,7 @@ export class NeynarV2APIClient {
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: false,
* fold: 'above',
Expand All @@ -1199,7 +1252,7 @@ export class NeynarV2APIClient {
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* {
* {
* replyDepth: 2,
* includeChronologicalParentCasts: false,
* fold: 'below',
Expand All @@ -1209,7 +1262,7 @@ export class NeynarV2APIClient {
* }).then(response => {
* console.log('Casts from below the fold:', response.conversation.cast.direct_replies);
* });
*
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/cast-conversation).
*/
public async lookupCastConversation(
Expand All @@ -1220,7 +1273,7 @@ export class NeynarV2APIClient {
includeChronologicalParentCasts?: boolean;
viewerFid?: number;
sortType?: CastConversationSortType;
fold? : 'above' | 'below';
fold?: "above" | "below";
limit?: number;
cursor?: string;
}
Expand Down Expand Up @@ -3078,21 +3131,21 @@ export class NeynarV2APIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-channel-memberships).
*/
public async fetchUserChannelMemberships(
fid: number,
options?: {
limit?: number;
cursor?: string;
}
): Promise<ChannelMemberListResponse> {
const response = await this.apis.channel.userChannelMemberships(
this.apiKey,
fid,
options?.limit,
options?.cursor
);
return response.data;
public async fetchUserChannelMemberships(
fid: number,
options?: {
limit?: number;
cursor?: string;
}
): Promise<ChannelMemberListResponse> {
const response = await this.apis.channel.userChannelMemberships(
this.apiKey,
fid,
options?.limit,
options?.cursor
);
return response.data;
}

// ------------ Storage ------------

Expand Down Expand Up @@ -3972,9 +4025,10 @@ export class NeynarV2APIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/ban-list).
*/
public async fetchBanList(
options?: { limit?: number; cursor: string }
): Promise<BanListResponse> {
public async fetchBanList(options?: {
limit?: number;
cursor: string;
}): Promise<BanListResponse> {
const response = await this.apis.ban.banList(
this.apiKey,
options?.limit,
Expand All @@ -3999,11 +4053,9 @@ export class NeynarV2APIClient {
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/add-ban).
*
*/
public async publishBans(
fids: number[]
): Promise<BanResponse> {
public async publishBans(fids: number[]): Promise<BanResponse> {
const addBanBody = {
fids
fids,
};
const response = await this.apis.ban.addBan(this.apiKey, addBanBody);
return response.data;
Expand All @@ -4024,16 +4076,11 @@ export class NeynarV2APIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/delete-ban).
*/
public async deleteBans(
fids: number[]
): Promise<BanResponse> {
public async deleteBans(fids: number[]): Promise<BanResponse> {
const deleteBanBody = {
fids,
};
const response = await this.apis.ban.deleteBan(
this.apiKey,
deleteBanBody
);
const response = await this.apis.ban.deleteBan(this.apiKey, deleteBanBody);
return response.data;
}

Expand Down
Loading

0 comments on commit 99ec331

Please sign in to comment.