Skip to content

Commit

Permalink
Merge pull request #85 from MrKevinOConnell/main
Browse files Browse the repository at this point in the history
adds lookupCastConversation, updates searchUser params, and depreciates fetchAllCastsInThread
  • Loading branch information
Shreyaschorge authored Apr 5, 2024
2 parents c0c82d7 + 0a556c2 commit 15d6459
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 29 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.14.0",
"version": "1.15.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
54 changes: 50 additions & 4 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
WebhookResponse,
WebhookSubscriptionFilters,
WebhookListResponse,
Conversation,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -311,6 +312,9 @@ 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 @@ -1243,18 +1247,60 @@ export class NeynarAPIClient {
*
* @example
* // Example: Search for users with a specific query
* client.searchUser('ris', 19960).then(response => {
* client.searchUser('ris', 19960, { limit: 10 }).then(response => {
* console.log('User Search Results:', response); // Outputs the results of the user search
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-search).
*/
public async searchUser(
q: string,
viewerFid: number
viewerFid?: number,
options?: { limit?: number, cursor?: string}
): Promise<UserSearchResponse> {
return await this.clients.v2.searchUser(q, viewerFid);
}
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
);
}


/**
* Looks up a user by their custody address.
Expand Down
3 changes: 3 additions & 0 deletions src/neynar-api/v1/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ 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
16 changes: 8 additions & 8 deletions src/neynar-api/v1/openapi/apis/cast-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import { RecentCastsResponse } from '../models';
export const CastApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
* Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary Retrieve all casts in a given thread hash
* Now deprecated, use [v2/cast/conversation](https://docs.neynar.com/reference/cast-conversation). Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary DEPRECATED - Retrieve all casts in a given thread hash
* @param {string} apiKey API key required for authentication.
* @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.
Expand Down Expand Up @@ -263,8 +263,8 @@ export const CastApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = CastApiAxiosParamCreator(configuration)
return {
/**
* Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary Retrieve all casts in a given thread hash
* Now deprecated, use [v2/cast/conversation](https://docs.neynar.com/reference/cast-conversation). Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary DEPRECATED - Retrieve all casts in a given thread hash
* @param {string} apiKey API key required for authentication.
* @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.
Expand Down Expand Up @@ -330,8 +330,8 @@ export const CastApiFactory = function (configuration?: Configuration, basePath?
const localVarFp = CastApiFp(configuration)
return {
/**
* Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary Retrieve all casts in a given thread hash
* Now deprecated, use [v2/cast/conversation](https://docs.neynar.com/reference/cast-conversation). Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary DEPRECATED - Retrieve all casts in a given thread hash
* @param {string} apiKey API key required for authentication.
* @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.
Expand Down Expand Up @@ -393,8 +393,8 @@ export const CastApiFactory = function (configuration?: Configuration, basePath?
*/
export class CastApi extends BaseAPI {
/**
* Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary Retrieve all casts in a given thread hash
* Now deprecated, use [v2/cast/conversation](https://docs.neynar.com/reference/cast-conversation). Gets all casts, including root cast and all replies for a given thread hash. No limit the depth of replies.
* @summary DEPRECATED - Retrieve all casts in a given thread hash
* @param {string} apiKey API key required for authentication.
* @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.
Expand Down
52 changes: 50 additions & 2 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
WebhookListResponse,
WebhookPatchReqBody,
WebhookPatchReqBodyActiveEnum,
Conversation,
} from "./openapi-farcaster";
import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
Expand Down Expand Up @@ -811,9 +812,13 @@ export class NeynarV2APIClient {
*/
public async searchUser(
q: string,
viewerFid: number
viewerFid?: number,
options?: {
limit?: number;
cursor?: string;
}
): Promise<UserSearchResponse> {
const response = await this.apis.user.userSearch(this.apiKey, q, viewerFid);
const response = await this.apis.user.userSearch(this.apiKey, q, viewerFid, options?.limit, options?.cursor);
return response.data;
}

Expand Down Expand Up @@ -927,6 +932,49 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves detailed information about a cast conversation based on a specified hash or URL. Useful
* for fetching in-depth details of a single cast conversation, including replies up to a specified depth. The method
* allows for specifying the type of the provided identifier (e.g., a hash or URL) and how deep the reply chain should
* be fetched.
*
* @param {string} castHashOrUrl - The hash or URL of the cast conversation to be retrieved.
* @param {CastParamType} type - Specifies the type of the provided identifier, indicating whether it's a hash or URL.
* @param {number} [replyDepth] - Optional parameter to specify how deep the reply chain should be fetched.
* @param {boolean} [includeChronologicalParentCasts] - Optional parameter to include chronological parent casts in the response.
* @returns {Promise<Conversation>} A promise that resolves to a `Conversation` object,
* containing detailed information about the requested cast conversation, including replies up to the specified depth.
*
* @example
* // Fetch detailed information about a cast conversation using a given hash or URL, with a reply depth of 2
* client.lookupCastConversation(
* 'https://warpcast.com/rish/0x9288c1',
* CastParamType.Url,
* { replyDepth: 2, includeChronologicalParentCasts: true }
* ).then(response => {
* console.log('Cast Conversation Information:', response); // Outputs detailed information about the specified cast conversation
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/cast-conversation).
*/
public async lookupCastConversation(
castHashOrUrl: string,
type: CastParamType,
options?: {
replyDepth?: number;
includeChronologicalParentCasts?: boolean;
}
): Promise<Conversation> {
const response = await this.apis.cast.castConversation(
this.apiKey,
castHashOrUrl,
type,
options?.replyDepth,
options?.includeChronologicalParentCasts
);
return response.data;
}

/**
* Publishes a cast for the currently authenticated user. This method allows users to post
* content, including text and embeds, and can also be used to reply to existing casts.
Expand Down
3 changes: 3 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ models/cast-parent-author-all-of.ts
models/cast-parent-author.ts
models/cast-response.ts
models/cast-with-interactions-all-of.ts
models/cast-with-interactions-and-conversations.ts
models/cast-with-interactions-reactions.ts
models/cast-with-interactions-replies.ts
models/cast-with-interactions.ts
Expand All @@ -43,6 +44,8 @@ models/casts-response.ts
models/channel-list-response.ts
models/channel-response.ts
models/channel.ts
models/conversation-response.ts
models/conversation.ts
models/dehydrated-follower.ts
models/delete-cast-req-body.ts
models/delete-frame-response.ts
Expand Down
Loading

0 comments on commit 15d6459

Please sign in to comment.