Skip to content

Commit

Permalink
Bugfix/Add FrameAction in CastWithInteractions and other improvements
Browse files Browse the repository at this point in the history
Bugfix/Add FrameAction in CastWithInteractions and other improvements
  • Loading branch information
Shreyaschorge authored Feb 1, 2024
2 parents 6524f4f + 44de2ff commit 159f163
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "1.9.0",
"version": "1.9.1",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/neynar-api/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ export enum TimeWindow {
SEVEN_DAYS = "7d",
THIRTY_DAYS = "30d",
}

export enum BulkCastsSortType {
TRENDING = "trending",
LIKES = "likes",
RECASTS = "recasts",
REPLIES = "replies",
RECENT = "recent",
}
2 changes: 1 addition & 1 deletion src/neynar-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export {
CastParamType,
ReactionType,
} from "./v2";
export { TimeWindow } from "./common/constants";
export { TimeWindow, BulkCastsSortType } from "./common/constants";
56 changes: 42 additions & 14 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { viemPublicClient } from "./common/viemClient";
import { SignedKeyRequestMetadataABI } from "./abi/signed-key-request-metadata";
import { keyGatewayAbi } from "./abi/key-gateway";
import {
BulkCastsSortType,
SIGNED_KEY_REQUEST_TYPE,
SIGNED_KEY_REQUEST_TYPE_FOR_ADD_FOR,
SIGNED_KEY_REQUEST_VALIDATOR,
Expand Down Expand Up @@ -1066,24 +1067,41 @@ export class NeynarAPIClient {

/**
* Retrieves information about multiple casts using an array of their hashes. This method is useful
* for fetching details of several casts at once, identified by their unique hashes.
* for fetching details of several casts at once, identified by their unique hashes. Optional parameters
* allow for adding viewer context to the cast objects to show whether the viewer has liked or recasted
* the cast and sorting the casts based on different criteria.
*
* @param {Array<string>} castsHashes - An array of strings representing the hashes of the casts
* to be retrieved.
* @param {Object} [options] - Optional parameters for the request.
* @param {number} [options.viewerFid] - Adds viewer context to cast objects to indicate whether the viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [options.sortType] - Optional parameter to sort the casts based on different criteria such as trending, likes, recasts, replies, or recent.
*
* @returns {Promise<CastsResponse>} A promise that resolves to a `CastsResponse` object,
* containing information about the requested casts.
*
* @example
* // Example: Fetch information about multiple casts using their hashes
* client.fetchBulkCasts(['0xa896906a5e397b4fec247c3ee0e9e4d4990b8004','0x27ff810f7f718afd8c40be236411f017982e0994']).then(response => {
* // Example: Fetch information about multiple casts using their hashes with viewer context and sorting by likes
*
* import { BulkCastsSortType } from "@neynar/nodejs-sdk";
*
* client.fetchBulkCasts(['0xa896906a5e397b4fec247c3ee0e9e4d4990b8004','0x27ff810f7f718afd8c40be236411f017982e0994'], {
* viewerFid: 3,
* sortType: BulkCastsSortType.LIKES
* }).then(response => {
* console.log('Bulk Casts Information:', response); // Outputs information about the specified casts
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/casts).
*/
public async fetchBulkCasts(castsHashes: string[]): Promise<CastsResponse> {
return await this.clients.v2.fetchBulkCasts(castsHashes);
public async fetchBulkCasts(
castsHashes: string[],
options?: {
viewerFid?: number;
sortType?: BulkCastsSortType;
}
): Promise<CastsResponse> {
return await this.clients.v2.fetchBulkCasts(castsHashes, options);
}

/**
Expand Down Expand Up @@ -1867,28 +1885,38 @@ export class NeynarAPIClient {
}

/**
* Validates a frame action against the Farcaster Hub. This method is essential for verifying
* the authenticity and integrity of a frame action by providing the message bytes from the
* frame action in hexadecimal format.
* Validates a frame action against the Farcaster Hub. This method is crucial for verifying
* the authenticity and integrity of a frame action, provided in hexadecimal format. It supports
* optional contexts for cast reactions and follow actions to enrich validation responses.
*
* @param {string} messageBytesInHex - The message bytes from the Frame Action provided in hexadecimal format.
* @param {string} messageBytesInHex - The message bytes from the Frame Action in hexadecimal format.
* @param {Object} [options] - Optional parameters for the validation request.
* @param {boolean} [options.castReactionContext] - Include context about cast reactions in the validation response.
* @param {boolean} [options.followContext] - Include context about follow actions in the validation response.
*
* @returns {Promise<ValidateFrameActionResponse>} A promise that resolves to a `ValidateFrameActionResponse` object,
* indicating the validation result of the frame action.
* indicating the outcome of the frame action validation, potentially enriched with specified contexts.
*
* @example
* // Example: Validate a frame action
* // Example: Validate a frame action with additional context for cast reactions and follow actions
* const messageBytesInHex = '0a49080d1085940118f6a6a32e20018201390a1a86db69b3ffdf6ab8acb6872b69ccbe7eb6a67af7ab71e95aa69f10021a1908ef011214237025b322fd03a9ddc7ec6c078fb9c56d1a72111214e3d88aeb2d0af356024e0c693f31c11b42c76b721801224043cb2f3fcbfb5dafce110e934b9369267cf3d1aef06f51ce653dc01700fc7b778522eb7873fd60dda4611376200076caf26d40a736d3919ce14e78a684e4d30b280132203a66717c82d728beb3511b05975c6603275c7f6a0600370bf637b9ecd2bd231e';
* client.validateFrameAction(messageBytesInHex).then(response => {
* client.validateFrameAction(messageBytesInHex, { castReactionContext: false, followContext: true }).then(response => {
* console.log('Frame Action Validation:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/validate-frame).
*/
public async validateFrameAction(
messageBytesInHex: string
messageBytesInHex: string,
options?: {
castReactionContext?: boolean;
followContext?: boolean;
}
): Promise<ValidateFrameActionResponse> {
return await this.clients.v2.validateFrameAction(messageBytesInHex);
return await this.clients.v2.validateFrameAction(
messageBytesInHex,
options
);
}

// ------------ Recommendation ------------
Expand Down
63 changes: 49 additions & 14 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
import type { SetRequired } from "type-fest";
import { NFTApi, RelevantMints } from "./openapi-recommendation";
import { TimeWindow } from "../common/constants";
import { BulkCastsSortType, TimeWindow } from "../common/constants";

const BASE_PATH = "https://api.neynar.com/v2";

Expand Down Expand Up @@ -604,25 +604,47 @@ export class NeynarV2APIClient {

/**
* Retrieves information about multiple casts using an array of their hashes. This method is useful
* for fetching details of several casts at once, identified by their unique hashes.
* for fetching details of several casts at once, identified by their unique hashes. Optional parameters
* allow for adding viewer context to the cast objects to show whether the viewer has liked or recasted
* the cast and sorting the casts based on different criteria.
*
* @param {Array<string>} castsHashes - An array of strings representing the hashes of the casts
* to be retrieved.
* @param {Object} [options] - Optional parameters for the request.
* @param {number} [options.viewerFid] - Adds viewer context to cast objects to indicate whether the viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [options.sortType] - Optional parameter to sort the casts based on different criteria such as trending, likes, recasts, replies, or recent.
*
* @returns {Promise<CastsResponse>} A promise that resolves to a `CastsResponse` object,
* containing information about the requested casts.
*
* @example
* // Example: Fetch information about multiple casts using their hashes
* client.fetchBulkCasts(['0xa896906a5e397b4fec247c3ee0e9e4d4990b8004','0x27ff810f7f718afd8c40be236411f017982e0994']).then(response => {
* // Example: Fetch information about multiple casts using their hashes with viewer context and sorting by likes
*
* import { BulkCastsSortType } from "@neynar/nodejs-sdk";
*
* client.fetchBulkCasts(['0xa896906a5e397b4fec247c3ee0e9e4d4990b8004','0x27ff810f7f718afd8c40be236411f017982e0994'], {
* viewerFid: 3,
* sortType: BulkCastsSortType.LIKES
* }).then(response => {
* console.log('Bulk Casts Information:', response); // Outputs information about the specified casts
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/casts).
*/
public async fetchBulkCasts(castsHashes: string[]): Promise<CastsResponse> {
public async fetchBulkCasts(
castsHashes: string[],
options?: {
viewerFid?: number;
sortType?: BulkCastsSortType;
}
): Promise<CastsResponse> {
const _castsHashes = castsHashes.join(",");
const response = await this.apis.cast.casts(this.apiKey, _castsHashes);
const response = await this.apis.cast.casts(
this.apiKey,
_castsHashes,
options?.viewerFid,
options?.sortType
);
return response.data;
}

Expand Down Expand Up @@ -1558,29 +1580,42 @@ export class NeynarV2APIClient {
}

/**
* Validates a frame action against the Farcaster Hub. This method is essential for verifying
* the authenticity and integrity of a frame action by providing the message bytes from the
* frame action in hexadecimal format.
* Validates a frame action against the Farcaster Hub. This method is crucial for verifying
* the authenticity and integrity of a frame action, provided in hexadecimal format. It supports
* optional contexts for cast reactions and follow actions to enrich validation responses.
*
* @param {string} messageBytesInHex - The message bytes from the Frame Action provided in hexadecimal format.
* @param {string} messageBytesInHex - The message bytes from the Frame Action in hexadecimal format.
* @param {Object} [options] - Optional parameters for the validation request.
* @param {boolean} [options.castReactionContext] - Include context about cast reactions in the validation response.
* @param {boolean} [options.followContext] - Include context about follow actions in the validation response.
*
* @returns {Promise<ValidateFrameActionResponse>} A promise that resolves to a `ValidateFrameActionResponse` object,
* indicating the validation result of the frame action.
* indicating the outcome of the frame action validation, potentially enriched with specified contexts.
*
* @example
* // Example: Validate a frame action
* // Example: Validate a frame action with additional context for cast reactions and follow actions
* const messageBytesInHex = '0a49080d1085940118f6a6a32e20018201390a1a86db69b3ffdf6ab8acb6872b69ccbe7eb6a67af7ab71e95aa69f10021a1908ef011214237025b322fd03a9ddc7ec6c078fb9c56d1a72111214e3d88aeb2d0af356024e0c693f31c11b42c76b721801224043cb2f3fcbfb5dafce110e934b9369267cf3d1aef06f51ce653dc01700fc7b778522eb7873fd60dda4611376200076caf26d40a736d3919ce14e78a684e4d30b280132203a66717c82d728beb3511b05975c6603275c7f6a0600370bf637b9ecd2bd231e';
* client.validateFrameAction(messageBytesInHex).then(response => {
* client.validateFrameAction(messageBytesInHex, { castReactionContext: false, followContext: true }).then(response => {
* console.log('Frame Action Validation:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/validate-frame).
*/
public async validateFrameAction(
messageBytesInHex: string
messageBytesInHex: string,
options?: {
castReactionContext?: boolean;
followContext?: boolean;
}
): Promise<ValidateFrameActionResponse> {
const reqBody: ValidateFrameRequest = {
message_bytes_in_hex: messageBytesInHex,
...(typeof options?.castReactionContext !== "undefined" && {
cast_reaction_context: options?.castReactionContext,
}),
...(typeof options?.followContext !== "undefined" && {
follow_context: options?.followContext,
}),
};

const response = await this.apis.frame.validateFrame(this.apiKey, reqBody);
Expand Down
22 changes: 15 additions & 7 deletions src/neynar-api/v2/openapi-farcaster/apis/cast-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ export const CastApiAxiosParamCreator = function (configuration?: Configuration)
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {number} [viewerFid] adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
casts: async (apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
casts: async (apiKey: string, casts: string, viewerFid?: number, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('casts', 'apiKey', apiKey)
// verify required parameter 'casts' is not null or undefined
Expand All @@ -124,6 +125,10 @@ export const CastApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['casts'] = casts;
}

if (viewerFid !== undefined) {
localVarQueryParameter['viewer_fid'] = viewerFid;
}

if (sortType !== undefined) {
localVarQueryParameter['sort_type'] = sortType;
}
Expand Down Expand Up @@ -257,12 +262,13 @@ export const CastApiFp = function(configuration?: Configuration) {
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {number} [viewerFid] adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CastsResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.casts(apiKey, casts, sortType, options);
async casts(apiKey: string, casts: string, viewerFid?: number, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CastsResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.casts(apiKey, casts, viewerFid, sortType, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
Expand Down Expand Up @@ -316,12 +322,13 @@ export const CastApiFactory = function (configuration?: Configuration, basePath?
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {number} [viewerFid] adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: any): AxiosPromise<CastsResponse> {
return localVarFp.casts(apiKey, casts, sortType, options).then((request) => request(axios, basePath));
casts(apiKey: string, casts: string, viewerFid?: number, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: any): AxiosPromise<CastsResponse> {
return localVarFp.casts(apiKey, casts, viewerFid, sortType, options).then((request) => request(axios, basePath));
},
/**
* Delete an existing cast. \\ (In order to delete a cast `signer_uuid` must be approved)
Expand Down Expand Up @@ -374,13 +381,14 @@ export class CastApi extends BaseAPI {
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {number} [viewerFid] adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof CastApi
*/
public casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig) {
return CastApiFp(this.configuration).casts(apiKey, casts, sortType, options).then((request) => request(this.axios, this.basePath));
public casts(apiKey: string, casts: string, viewerFid?: number, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig) {
return CastApiFp(this.configuration).casts(apiKey, casts, viewerFid, sortType, options).then((request) => request(this.axios, this.basePath));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { CastWithInteractionsReactions } from './cast-with-interactions-reaction
import { CastWithInteractionsReplies } from './cast-with-interactions-replies';
// May contain unused imports in some cases
// @ts-ignore
import { FrameAction } from './frame-action';
// May contain unused imports in some cases
// @ts-ignore
import { User } from './user';

/**
Expand All @@ -29,6 +32,12 @@ import { User } from './user';
* @interface CastWithInteractionsAllOf
*/
export interface CastWithInteractionsAllOf {
/**
*
* @type {Array<FrameAction>}
* @memberof CastWithInteractionsAllOf
*/
'frames'?: Array<FrameAction>;
/**
*
* @type {CastWithInteractionsReactions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import { CastWithInteractionsReplies } from './cast-with-interactions-replies';
import { EmbeddedCast } from './embedded-cast';
// May contain unused imports in some cases
// @ts-ignore
import { FrameAction } from './frame-action';
// May contain unused imports in some cases
// @ts-ignore
import { User } from './user';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ export interface FrameActionButton {
* @memberof FrameActionButton
*/
'index': number;
/**
*
* @type {string}
* @memberof FrameActionButton
*/
'action_type'?: string;
}

Loading

0 comments on commit 159f163

Please sign in to comment.