Skip to content

Commit

Permalink
Add fetchValidateFrameList and fetchValidateFrameAnalytics and mark f…
Browse files Browse the repository at this point in the history
…etchCastLikes, fetchCastReactions and fetchRecasters as deprecated

Add fetchValidateFrameList and fetchValidateFrameAnalytics and mark fetchCastLikes, fetchCastReactions and fetchRecasters as deprecated
  • Loading branch information
Shreyaschorge authored Apr 8, 2024
2 parents 75e6e28 + 3189435 commit 5a721fd
Show file tree
Hide file tree
Showing 22 changed files with 952 additions and 121 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.15.0",
"version": "1.16.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/neynar-api/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ export enum BulkCastsSortType {
export enum BulkUserAddressTypes {
CUSTODY_ADDRESS = "custody_address",
VERIFIED_ADDRESS = "verified_address"
}

export enum ValidateFrameAggregateWindow {
TEN_SECONDS = "10s",
ONE_MINUTE = "1m",
TWO_MINUTES = "2m",
TWENTY_MINUTES = "20m",
THIRTY_MINUTES = "30m",
TWO_HOURS = "2h",
TWELVE_HOURS = "12h",
ONE_DAY = "1d",
SEVEN_DAYS = "7d",
}
4 changes: 3 additions & 1 deletion src/neynar-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export {
ReactionsType,
CastParamType,
ReactionType,
FrameButtonActionType
FrameButtonActionType,
ValidateFrameAnalyticsType,
} from "./v2";
export {
TimeWindow,
BulkCastsSortType,
BulkUserAddressTypes,
ValidateFrameAggregateWindow,
} from "./common/constants";
206 changes: 161 additions & 45 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import {
WebhookSubscriptionFilters,
WebhookListResponse,
Conversation,
ReactionsCastResponse,
FrameValidateAnalyticsResponse,
ValidateFrameAnalyticsType,
FrameValidateListResponse,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -84,6 +88,7 @@ import {
SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN,
TimeWindow,
TrendingFeedTimeWindow,
ValidateFrameAggregateWindow,
} from "./common/constants";
import { isApiErrorResponse } from "./utils";

Expand Down Expand Up @@ -314,7 +319,7 @@ export class NeynarAPIClient {
/**
* @deprecated
* Now deprecated, use `lookupCastConversation` instead.
*
*
* Retrieves all casts, including root cast and all replies for a given thread hash. No limit to the depth of replies.
* **Note :** The parent provided by the caller is included in the response.
*
Expand Down Expand Up @@ -550,6 +555,9 @@ export class NeynarAPIClient {
// ------------ Reactions ------------

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves all like reactions for a specific cast in reverse chronological order.
*
* @param {CastV1 | string} castOrCastHash - The Cast object or its hash for which likes are being retrieved.
Expand Down Expand Up @@ -584,6 +592,9 @@ export class NeynarAPIClient {
}

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves all reactions (likes and recasts) for a specific cast.
*
* @param {CastV1 | string} castOrCastHash - The Cast object or its hash for which reactions are being retrieved.
Expand Down Expand Up @@ -618,6 +629,9 @@ export class NeynarAPIClient {
}

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves the list of users who have recasted a specific cast.
*
* @param {CastV1 | string} castOrCastHash - The Cast object or its hash for which recasters are being retrieved.
Expand Down Expand Up @@ -1256,51 +1270,50 @@ export class NeynarAPIClient {
public async searchUser(
q: string,
viewerFid?: number,
options?: { limit?: number, cursor?: string}
options?: { limit?: number; cursor?: string }
): Promise<UserSearchResponse> {
return await this.clients.v2.searchUser(q, viewerFid, options);
}

/**
* Retrieves comprehensive details about a specific cast conversation, identified by either a hash or a URL. This method is instrumental in accessing the full depth of a conversation, including initial casts and subsequent replies, up to a user-defined depth. By allowing the specification of the identifier type and the depth of replies to fetch, it offers flexibility in how conversation data is retrieved, making it suitable for applications requiring detailed conversation analysis or display.
*
* @param {string} castHashOrUrl - The unique hash or URL identifying the cast conversation to retrieve. This identifier enables precise targeting of the conversation of interest.
* @param {CastParamType} type - Enumerates the identifier type, specifying whether the provided value is a hash or a URL, thus guiding the retrieval process appropriately.
* @param {Object} [options] - An optional parameter object to refine the query.
* @param {number} [options.replyDepth] - An optional parameter within the options object, specifying the desired depth of replies to fetch within the conversation. This allows for tailored retrieval of conversation data, ranging from top-level casts only to deeper, more comprehensive conversation threads.
* @param {boolean} [options.includeChronologicalParentCasts] - An optional parameter within the options object, indicating whether to include chronological parent casts in the response. This parameter is useful for applications requiring a structured view of the conversation, including parent casts that provide context for the replies.
* @returns {Promise<Conversation>} A promise resolving to a `Conversation` object. This object encapsulates detailed information about the cast conversation, including the content of the conversation itself and any replies, structured up to the specified depth.
*
* @example
* // Example usage: Retrieve detailed information about a cast conversation via URL, including replies up to two levels deep
* import { CastParamType } from "@neynar/nodejs-sdk";
*
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* { replyDepth: 2, includeChronologicalParentCasts: true}
* ).then(response => {
* console.log('Cast Conversation Information:', response); // Displays the detailed structure of the specified cast conversation
* });
*
* // Refer to the Neynar API documentation for more details and advanced options:
* // https://docs.neynar.com/reference/cast-conversation
*/
public async lookupCastConversation(
castHashOrUrl: string,
type: CastParamType,
options?: {
replyDepth?: number;
includeChronologicalParentCasts?: boolean;
}
): Promise<Conversation> {
return await this.clients.v2.lookupCastConversation(
castHashOrUrl,
type,
options
);
}

/**
* Retrieves comprehensive details about a specific cast conversation, identified by either a hash or a URL. This method is instrumental in accessing the full depth of a conversation, including initial casts and subsequent replies, up to a user-defined depth. By allowing the specification of the identifier type and the depth of replies to fetch, it offers flexibility in how conversation data is retrieved, making it suitable for applications requiring detailed conversation analysis or display.
*
* @param {string} castHashOrUrl - The unique hash or URL identifying the cast conversation to retrieve. This identifier enables precise targeting of the conversation of interest.
* @param {CastParamType} type - Enumerates the identifier type, specifying whether the provided value is a hash or a URL, thus guiding the retrieval process appropriately.
* @param {Object} [options] - An optional parameter object to refine the query.
* @param {number} [options.replyDepth] - An optional parameter within the options object, specifying the desired depth of replies to fetch within the conversation. This allows for tailored retrieval of conversation data, ranging from top-level casts only to deeper, more comprehensive conversation threads.
* @param {boolean} [options.includeChronologicalParentCasts] - An optional parameter within the options object, indicating whether to include chronological parent casts in the response. This parameter is useful for applications requiring a structured view of the conversation, including parent casts that provide context for the replies.
* @returns {Promise<Conversation>} A promise resolving to a `Conversation` object. This object encapsulates detailed information about the cast conversation, including the content of the conversation itself and any replies, structured up to the specified depth.
*
* @example
* // Example usage: Retrieve detailed information about a cast conversation via URL, including replies up to two levels deep
* import { CastParamType } from "@neynar/nodejs-sdk";
*
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* { replyDepth: 2, includeChronologicalParentCasts: true}
* ).then(response => {
* console.log('Cast Conversation Information:', response); // Displays the detailed structure of the specified cast conversation
* });
*
* // Refer to the Neynar API documentation for more details and advanced options:
* // https://docs.neynar.com/reference/cast-conversation
*/
public async lookupCastConversation(
castHashOrUrl: string,
type: CastParamType,
options?: {
replyDepth?: number;
includeChronologicalParentCasts?: boolean;
}
): Promise<Conversation> {
return await this.clients.v2.lookupCastConversation(
castHashOrUrl,
type,
options
);
}

/**
* Looks up a user by their custody address.
Expand Down Expand Up @@ -1796,6 +1809,42 @@ public async lookupCastConversation(
return await this.clients.v2.fetchUserReactions(fid, type, options);
}

/**
* Fetches reactions (likes, recasts, or all) for a given cast. This method allows retrieving
* the reactions associated with a cast, specified by the cast hash.
*
* @param {string} hash - The hash of the cast whose reactions are being fetched.
* @param {ReactionsType} types - The type of reaction to fetch (likes, recasts, or all).
* @param {Object} [options] - Optional parameters for customizing the response.
* @param {number} [options.limit] - Limits the number of results. Default is 25, with a maximum of 100.
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<ReactionsCastResponse>} A promise that resolves to a `ReactionsResponse` object,
* containing the reactions associated with the user's casts.
*
* @example
*
* import { ReactionsType } from "@neynar/nodejs-sdk";
*
* // Example: Fetch a casts reactions
* client.fetchReactionsForCast("0xfe90f9de682273e05b201629ad2338bdcd89b6be", ReactionsType.All, {
* limit: 50,
* // cursor: "nextPageCursor" // Omit this parameter for the initial request
* }).then(response => {
* console.log('Cast Reactions:', response); // Outputs the casts reactions
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/reactions-cast).
*/
public async fetchReactionsForCast(
hash: string,
types: ReactionsType,
options?: { limit?: number; cursor?: string }
): Promise<ReactionsCastResponse> {
return await this.clients.v2.fetchCastReactions(hash, types, options);
}

// ------------ Notifications ------------

/**
Expand Down Expand Up @@ -1972,14 +2021,17 @@ public async lookupCastConversation(
*
* @example
* // Example: Retrieve a list of all channels
* client.fetchAllChannels().then(response => {
* client.fetchAllChannels({limit: 5}).then(response => {
* console.log('All Channels:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/list-all-channels).
*/
public async fetchAllChannels(): Promise<ChannelListResponse> {
return await this.clients.v2.fetchAllChannels();
public async fetchAllChannels(options?: {
limit?: number;
cursor?: string;
}): Promise<ChannelListResponse> {
return await this.clients.v2.fetchAllChannels(options);
}

/**
Expand Down Expand Up @@ -2387,6 +2439,70 @@ public async lookupCastConversation(
);
}

/**
* Retrieve a list of all the frames validated by a user
*
* @returns {Promise<FrameValidateListResponse>} A promise that resolves to an array of frame urls
*
* @example
*
* // Retrieve the list of validated frames
* client.fetchValidateFrameList()
* .then(response => console.log(response))
* .catch(error => console.error(error));
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/validate-frame-list).
*/
public async fetchValidateFrameList(): Promise<FrameValidateListResponse> {
return await this.clients.v2.fetchValidateFrameList();
}

/**
* Retrieves analytics for a specific frame over a given time period.
* This method allows for detailed analysis of frame interactions, providing insights into user engagement metrics such as total interactors, interactions per cast, and input text analysis.
*
* @param {string} frameUrl - The URL of the frame for which analytics are being retrieved.
* @param {ValidateFrameAnalyticsType} analyticsType - Specifies the type of analytics to retrieve. Can include metrics like total-interactors, interactors, interactions-per-cast, and input-text, each offering a different perspective on user engagement.
* @param {string} start - The start date/time for the analytics period. This parameter sets the beginning of the timeframe for the data being requested.
* @param {string} stop - The stop date/time for the analytics period. Similarly, this defines the end of the timeframe for analytics retrieval, allowing for precise period analysis.
* @param {Object} [options]
* @param {ValidateFrameAggregateWindow} [options.aggregateWindow] - Defines the aggregation window for the analytics, particularly required for 'interactions-per-cast' type analytics to determine the granularity of data aggregation.
*
* @returns {Promise<FrameValidateAnalyticsResponse>} A promise that resolves to FrameValidateAnalyticsResponse containing the requested frame analytics data, structured according to the specified analytics type and period.
*
*
* @example
*
* import {ValidateFrameAnalyticsType, ValidateFrameAggregateWindow } from '@neynar/nodejs-sdk'
*
* client.fetchValidateFrameAnalytics(
* 'https://shorturl.at/bDRY9',
* ValidateFrameAnalyticsType.InteractionsPerCast,
* '2024-04-06T06:44:56.811Z',
* '2024-04-08T06:44:56.811Z',
* { aggregateWindow: ValidateFrameAggregateWindow.TWELVE_HOURS }
* )
* .then(response => console.log(response))
* .catch(error => console.error(error));
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/validate-frame-analytics).
*/
public async fetchValidateFrameAnalytics(
frameUrl: string,
analyticsType: ValidateFrameAnalyticsType,
start: string,
stop: string,
options?: { aggregateWindow?: ValidateFrameAggregateWindow }
): Promise<FrameValidateAnalyticsResponse> {
return await this.clients.v2.fetchValidateFrameAnalytics(
frameUrl,
analyticsType,
start,
stop,
options
);
}

// ------------ Webhook ------------

/**
Expand Down
11 changes: 10 additions & 1 deletion src/neynar-api/v1/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class NeynarV1APIClient {
/**
* @deprecated
* Now deprecated, use `lookupCastConversation` instead.
*
*
* Retrieves all casts, including root cast and all replies for a given thread hash. No limit to the depth of replies.
* **Note :** The parent provided by the caller is included in the response.
*
Expand Down Expand Up @@ -616,6 +616,9 @@ export class NeynarV1APIClient {
// ------------ Reactions ------------

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves all like reactions for a specific cast in reverse chronological order.
*
* @param {Cast | string} castOrCastHash - The Cast object or its hash for which likes are being retrieved.
Expand Down Expand Up @@ -665,6 +668,9 @@ export class NeynarV1APIClient {
}

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves all reactions (likes and recasts) for a specific cast.
*
* @param {Cast | string} castOrCastHash - The Cast object or its hash for which reactions are being retrieved.
Expand Down Expand Up @@ -714,6 +720,9 @@ export class NeynarV1APIClient {
}

/**
* @deprecated
* Now deprecated, use `fetchReactionsForCast` instead.
*
* Retrieves the list of users who have recasted a specific cast.
*
* @param {Cast | string} castOrCastHash - The Cast object or its hash for which recasters are being retrieved.
Expand Down
4 changes: 4 additions & 0 deletions src/neynar-api/v1/openapi/apis/cast-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const CastApiAxiosParamCreator = function (configuration?: Configuration)
* @param {string} threadHash The hash of the thread to retrieve casts from.
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {*} [options] Override http request option.
* @deprecated
* @throws {RequiredError}
*/
allCastsInThread: async (apiKey: string, threadHash: string, viewerFid?: number, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
Expand Down Expand Up @@ -269,6 +270,7 @@ export const CastApiFp = function(configuration?: Configuration) {
* @param {string} threadHash The hash of the thread to retrieve casts from.
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {*} [options] Override http request option.
* @deprecated
* @throws {RequiredError}
*/
async allCastsInThread(apiKey: string, threadHash: string, viewerFid?: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<AllCastsInThreadResponse>> {
Expand Down Expand Up @@ -336,6 +338,7 @@ export const CastApiFactory = function (configuration?: Configuration, basePath?
* @param {string} threadHash The hash of the thread to retrieve casts from.
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {*} [options] Override http request option.
* @deprecated
* @throws {RequiredError}
*/
allCastsInThread(apiKey: string, threadHash: string, viewerFid?: number, options?: any): AxiosPromise<AllCastsInThreadResponse> {
Expand Down Expand Up @@ -399,6 +402,7 @@ export class CastApi extends BaseAPI {
* @param {string} threadHash The hash of the thread to retrieve casts from.
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {*} [options] Override http request option.
* @deprecated
* @throws {RequiredError}
* @memberof CastApi
*/
Expand Down
Loading

0 comments on commit 5a721fd

Please sign in to comment.