@neynar/nodejs-sdk
Version:
SDK to interact with Neynar APIs (https://docs.neynar.com/reference/quickstart)
1,077 lines (1,072 loc) • 222 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NeynarAPIClient = void 0;
const accounts_1 = require("viem/accounts");
const logger_1 = require("../common/logger");
const axios_1 = __importStar(require("axios"));
const configuration_1 = require("../api/configuration");
const constants_1 = require("../common/constants");
const utils_1 = require("../utils");
const action_api_1 = require("../api/apis/action-api");
const agents_api_1 = require("../api/apis/agents-api");
const app_host_api_1 = require("../api/apis/app-host-api");
const auth_address_api_1 = require("../api/apis/auth-address-api");
const ban_api_1 = require("../api/apis/ban-api");
const block_api_1 = require("../api/apis/block-api");
const cast_api_1 = require("../api/apis/cast-api");
const channel_api_1 = require("../api/apis/channel-api");
const feed_api_1 = require("../api/apis/feed-api");
const fname_api_1 = require("../api/apis/fname-api");
const follows_api_1 = require("../api/apis/follows-api");
const frame_api_1 = require("../api/apis/frame-api");
const login_api_1 = require("../api/apis/login-api");
const metrics_api_1 = require("../api/apis/metrics-api");
const mute_api_1 = require("../api/apis/mute-api");
const notifications_api_1 = require("../api/apis/notifications-api");
const onchain_api_1 = require("../api/apis/onchain-api");
const reaction_api_1 = require("../api/apis/reaction-api");
const signer_api_1 = require("../api/apis/signer-api");
const storage_api_1 = require("../api/apis/storage-api");
const studio_api_1 = require("../api/apis/studio-api");
const subscribers_api_1 = require("../api/apis/subscribers-api");
const topic_api_1 = require("../api/apis/topic-api");
const user_api_1 = require("../api/apis/user-api");
const webhook_api_1 = require("../api/apis/webhook-api");
const { version: sdkVersion } = require("../../package.json");
/**
* Converts a camelCase string to snake_case.
* If the input string is not in camelCase format, it returns the original string.
*
* @param {string} str - The string to convert.
* @returns {string} The converted string in snake_case, or the original string if not camelCase.
*/
function camelToSnakeCase(str) {
// Check if the string is camelCase
if (/^[a-z]+([A-Z][a-z]*)+$/.test(str)) {
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
}
return str; // Return the original string if it's not camelCase
}
/**
* Converts the top-level keys of an object from camelCase to snake_case.
* If a key is not in camelCase, it retains its original format.
* Nested objects or arrays are left unchanged.
* This is done to revert the conversion of top-level keys since we accept snake_case keys in the API but convert them to camelCase in the wrapper.
*
* @param {object} obj - The object whose top-level keys are to be converted.
* @returns {object} A new object with top-level keys converted to snake_case.
*/
function camelCaseToSnakeCaseKeys(obj) {
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
// Convert only the top-level keys
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
camelToSnakeCase(key), // Convert only camelCase keys
value, // Leave the value untouched
]));
}
return obj; // If not an object, return as is
}
class NeynarAPIClient {
constructor(config, options = {}) {
if (typeof config === 'string') {
console.error('Error: config must be of type Configuration');
console.log(`
Seems, like you are using sdk v2 but the syntax on client instantiation is for sdk v1.
SDK v1 -> v2 migration guide: https://docs.neynar.com/reference/neynar-nodejs-sdk-v1-to-v2-migration-guide
Correct usage way to instantiate the client:
import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";
const config = new Configuration({
apiKey: "API_KEY",
baseOptions: {
headers: {
"x-neynar-experimental": true,
},
},
});
const client = new NeynarAPIClient(config);\n`);
throw new Error('Invalid configuration type. Expected Configuration object but received string.');
}
const { logger = logger_1.silentLogger, axiosInstance: customAxiosInstance } = options;
this.logger = logger;
this.config = new configuration_1.Configuration({
apiKey: config.apiKey,
basePath: config.basePath,
baseOptions: config.baseOptions,
});
const axiosInstance = customAxiosInstance || axios_1.default.create({
headers: {
"x-sdk-version": sdkVersion,
"x-sdk": "node"
},
});
axiosInstance.defaults.decompress = true;
axiosInstance.interceptors.response.use((response) => response, (error) => {
if (error.response && [302].includes(error.response.status)) {
return {
data: {
location: error.response.headers.location,
},
};
}
if (NeynarAPIClient.isApiErrorResponse(error)) {
const apiErrors = error.response.data;
this.logger.warn(`API errors: ${JSON.stringify(apiErrors)}`);
}
throw error;
});
this.apis = {
actionApi: new action_api_1.ActionApi(this.config, undefined, axiosInstance),
agentsApi: new agents_api_1.AgentsApi(this.config, undefined, axiosInstance),
appHostApi: new app_host_api_1.AppHostApi(this.config, undefined, axiosInstance),
authAddressApi: new auth_address_api_1.AuthAddressApi(this.config, undefined, axiosInstance),
banApi: new ban_api_1.BanApi(this.config, undefined, axiosInstance),
blockApi: new block_api_1.BlockApi(this.config, undefined, axiosInstance),
castApi: new cast_api_1.CastApi(this.config, undefined, axiosInstance),
channelApi: new channel_api_1.ChannelApi(this.config, undefined, axiosInstance),
feedApi: new feed_api_1.FeedApi(this.config, undefined, axiosInstance),
fnameApi: new fname_api_1.FnameApi(this.config, undefined, axiosInstance),
followsApi: new follows_api_1.FollowsApi(this.config, undefined, axiosInstance),
frameApi: new frame_api_1.FrameApi(this.config, undefined, axiosInstance),
loginApi: new login_api_1.LoginApi(this.config, undefined, axiosInstance),
metricsApi: new metrics_api_1.MetricsApi(this.config, undefined, axiosInstance),
muteApi: new mute_api_1.MuteApi(this.config, undefined, axiosInstance),
notificationsApi: new notifications_api_1.NotificationsApi(this.config, undefined, axiosInstance),
onchainApi: new onchain_api_1.OnchainApi(this.config, undefined, axiosInstance),
reactionApi: new reaction_api_1.ReactionApi(this.config, undefined, axiosInstance),
signerApi: new signer_api_1.SignerApi(this.config, undefined, axiosInstance),
storageApi: new storage_api_1.StorageApi(this.config, undefined, axiosInstance),
studioApi: new studio_api_1.StudioApi(this.config, undefined, axiosInstance),
subscribersApi: new subscribers_api_1.SubscribersApi(this.config, undefined, axiosInstance),
topicApi: new topic_api_1.TopicApi(this.config, undefined, axiosInstance),
userApi: new user_api_1.UserApi(this.config, undefined, axiosInstance),
webhookApi: new webhook_api_1.WebhookApi(this.config, undefined, axiosInstance),
};
}
static isApiErrorResponse(error) {
var _a;
if (!(error instanceof axios_1.AxiosError))
return false;
return (((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) !== undefined && "message" in error.response.data);
}
/**
* Securely communicate and perform actions on behalf of users across different apps. It enables an app to send data or trigger actions in another app on behalf of a mutual user by signing messages using the user\'s Farcaster signer.
*
* @summary User actions across apps
*
* @param {object} params
* @param {string} params.signerUuid - The signer_uuid of the user on behalf of whom the action is being performed.
* @param {string} params.baseUrl - The base URL of the app on which the action is being performed.
* @param {FarcasterActionReqBodyAction} params.action
*
* @returns {Promise<{ [key: string]: any; }>} A promise that resolves to a `{ [key: string]: any; }` object.
*
* @example
*
* // Fill in the appropriate values
* const signerUuid =
* const baseUrl =
* const action =
*
* client.publishFarcasterAction({signerUuid, baseUrl, action}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/publish-farcaster-action)
*
*/
async publishFarcasterAction(params) {
const adjustedParams = {};
const _params = { farcasterActionReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.actionApi.publishFarcasterAction(adjustedParams);
return response.data;
}
/**
* Creates a new transaction pay mini app that can be used to collect payments through a mini app
*
* @summary Create transaction pay mini app
*
* @param {object} params
* @param {FramePayTransactionReqBodyTransaction} params.transaction
* @param {TransactionFrameConfig} params.config
* @param {string} params.idem [optional] - An Idempotency key is a unique identifier for the request. **Note:** 1) This is used to prevent duplicate requests. Use the same idem key on retry attempts. 2) This should be a unique identifier for each request. 3) Recommended format is a 16-character string generated by the developer at the time of making this request.
*
* @returns {Promise<TransactionFrameResponse>} A promise that resolves to a `TransactionFrameResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const transaction =
* const config =
* const idem =
*
* client.createTransactionPayFrame({transaction, config, idem}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/create-transaction-pay-frame)
*
*/
async createTransactionPayFrame(params) {
const adjustedParams = {};
const _params = { framePayTransactionReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.agentsApi.createTransactionPayFrame(adjustedParams);
return response.data;
}
/**
* Returns a list of interactions between two users
*
* @summary User interactions
*
* @param {object} params
* @param {number[]} params.fids - Comma separated list of two FIDs
* @param {Array<FetchUserInteractionsTypeEnum>} params.type [optional] - Comma seperated list of Interaction type to fetch
*
* @returns {Promise<FetchUserInteractions200Response>} A promise that resolves to a `FetchUserInteractions200Response` object.
*
* @example
*
* // Fill in the appropriate values
* const fids =
* const type =
*
* client.fetchUserInteractions({ fids, type }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-user-interactions)
*
*/
async fetchUserInteractions(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
if (adjustedParams.fids && Array.isArray(adjustedParams.fids)) {
adjustedParams.fids = adjustedParams.fids.map(value => (String(value)));
}
if (adjustedParams.fids && Array.isArray(adjustedParams.fids)) {
adjustedParams.fids = adjustedParams.fids.join(",");
}
const response = await this.apis.agentsApi.fetchUserInteractions(adjustedParams);
return response.data;
}
/**
* Generates a summary of all casts related to a conversation surrounding a cast by passing in a cast hash or Farcaster URL. Summary is generated by an LLM and is intended to be passed as a context to AI agents.
*
* @summary Cast conversation summary
*
* @param {object} params
* @param {string} params.identifier - Cast identifier (It's either a URL or a hash))
* @param {number} params.limit [optional] - Number of casts to consider in a summary up to a point of target cast (Default: 20, Maximum: 50)
* @param {string} params.prompt [optional] - Additional prompt used to generate a summary
*
* @returns {Promise<ConversationSummary>} A promise that resolves to a `ConversationSummary` object.
*
* @example
*
* // Fill in the appropriate values
* const identifier =
* const limit =
* const prompt =
*
* client.lookupCastConversationSummary({ identifier, limit, prompt }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/lookup-cast-conversation-summary)
*
*/
async lookupCastConversationSummary(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.agentsApi.lookupCastConversationSummary(adjustedParams);
return response.data;
}
/**
* Returns event object for app host events. Used if the app host intends to sign the event message instead of using Neynar-hosted signers.
*
* @summary Generate event
*
* @param {object} params
* @param {string} params.appDomain - The domain of the mini app
* @param {number} params.fid - The FID of the user who initiated the event
* @param {AppHostGetEventEventEnum} params.event - The type of event
*
* @returns {Promise<AppHostGetEventResponse>} A promise that resolves to a `AppHostGetEventResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const appDomain =
* const fid =
* const event =
*
* client.appHostGetEvent({ appDomain, fid, event }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/app-host-get-event)
*
*/
async appHostGetEvent(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.appHostApi.appHostGetEvent(adjustedParams);
return response.data;
}
/**
* Returns the current notification state for a specific user across all mini app domains in this app host. Shows which domains have notifications enabled.
*
* @summary Enabled notifications
*
* @param {object} params
* @param {number} params.fid - The FID of the user
*
* @returns {Promise<AppHostUserStateResponse>} A promise that resolves to a `AppHostUserStateResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const fid =
*
* client.appHostGetUserState({ fid }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/app-host-get-user-state)
*
*/
async appHostGetUserState(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.appHostApi.appHostGetUserState(adjustedParams);
return response.data;
}
/**
* Post an app_host event to the domain\'s webhook. Events such as enabling or disabling notifications for a user. Provide either a signed message or the signer UUID of an authorized neynar-hosted signers.
*
* @summary Send event
*
* @param {object} params
* @param {any} params.appHostPostEventReqBody
*
* @returns {Promise<AppHostPostEventResponse>} A promise that resolves to a `AppHostPostEventResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const appHostPostEventReqBody =
*
* client.appHostPostEvent({appHostPostEventReqBody}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/app-host-post-event)
*
*/
async appHostPostEvent(params) {
const adjustedParams = {};
const _params = { appHostPostEventReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.appHostApi.appHostPostEvent(adjustedParams);
return response.data;
}
/**
* Fetches the status of a developer managed auth address by auth address
*
* @summary Status by auth address
*
* @param {object} params
* @param {string} params.address - Ethereum address
*
* @returns {Promise<RegisterSignedKeyForDeveloperManagedAuthAddress200Response>} A promise that resolves to a `RegisterSignedKeyForDeveloperManagedAuthAddress200Response` object.
*
* @example
*
* // Fill in the appropriate values
* const address =
*
* client.lookupDeveloperManagedAuthAddress({ address }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/lookup-developer-managed-auth-address)
*
*/
async lookupDeveloperManagedAuthAddress(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.authAddressApi.lookupDeveloperManagedAuthAddress(adjustedParams);
return response.data;
}
/**
* Allow apps to register an Ethereum addresses as authorized \"auth addresses\" for a user\'s Farcaster account, enabling seamless Sign-In With Farcaster (SIWF) across applications without repeated custody wallet authorizations.
*
* @summary Register Signed Key
*
* @param {object} params
* @param {string} params.address - Ethereum address
* @param {number} params.appFid - The unique identifier of a farcaster user or app (unsigned integer)
* @param {number} params.deadline - unix timestamp in seconds that controls how long the signed key request is valid for. (24 hours from now is recommended)
* @param {string} params.signature - Signature generated by the custody address of the app. Signed data includes app_fid, deadline, 32 bytes padded auth address. [Refer guide for more details.](https://docs.neynar.com/docs/auth-address-signature-generation)
* @param {string} params.redirectUrl [optional] - Url to redirect to after the signer is approved. **Note** : This should only be used when requesting a signer from a native mobile application.
* @param {SignedKeyRequestSponsor} params.sponsor [optional]
*
* @returns {Promise<RegisterSignedKeyForDeveloperManagedAuthAddress200Response>} A promise that resolves to a `RegisterSignedKeyForDeveloperManagedAuthAddress200Response` object.
*
* @example
*
* // Fill in the appropriate values
* const address =
* const appFid =
* const deadline =
* const signature =
* const redirectUrl =
* const sponsor =
*
* client.registerSignedKeyForDeveloperManagedAuthAddress({address, appFid, deadline, signature, redirectUrl, sponsor}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/register-signed-key-for-developer-managed-auth-address)
*
*/
async registerSignedKeyForDeveloperManagedAuthAddress(params) {
const adjustedParams = {};
const _params = { registerAuthAddressDeveloperManagedSignedKeyReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.authAddressApi.registerSignedKeyForDeveloperManagedAuthAddress(adjustedParams);
return response.data;
}
/**
* Deletes a list of FIDs from the app associated with your API key.
*
* @summary Unban FIDs from app
*
* @param {object} params
* @param {Array<number>} params.fids
*
* @returns {Promise<BanResponse>} A promise that resolves to a `BanResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const fids =
*
* client.deleteBans({fids}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/delete-bans)
*
*/
async deleteBans(params) {
const adjustedParams = {};
const _params = { banReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.banApi.deleteBans(adjustedParams);
return response.data;
}
/**
* Fetches all FIDs that your app has banned.
*
* @summary Banned FIDs of app
*
* @param {object} params
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<BanListResponse>} A promise that resolves to a `BanListResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const limit =
*
* client.fetchBanList({ limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-ban-list)
*
*/
async fetchBanList(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.banApi.fetchBanList(adjustedParams);
return response.data;
}
/**
* Bans a list of FIDs from the app associated with your API key. Banned users, their casts and reactions will not appear in feeds.
*
* @summary Ban FIDs from app
*
* @param {object} params
* @param {Array<number>} params.fids
*
* @returns {Promise<BanResponse>} A promise that resolves to a `BanResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const fids =
*
* client.publishBans({fids}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/publish-bans)
*
*/
async publishBans(params) {
const adjustedParams = {};
const _params = { banReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.banApi.publishBans(adjustedParams);
return response.data;
}
/**
* Deletes a block for a given FID.
*
* @summary Unblock FID
*
* @param {object} params
* @param {string} params.signerUuid - UUID of the signer. `signer_uuid` is paired with API key, can't use a `uuid` made with a different API key.
* @param {number} params.blockedFid - The unique identifier of a farcaster user or app (unsigned integer)
*
* @returns {Promise<OperationResponse>} A promise that resolves to a `OperationResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const signerUuid =
* const blockedFid =
*
* client.deleteBlock({signerUuid, blockedFid}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/delete-block)
*
*/
async deleteBlock(params) {
const adjustedParams = {};
const _params = { blockReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.blockApi.deleteBlock(adjustedParams);
return response.data;
}
/**
* Fetches all FIDs that a user has blocked or has been blocked by
*
* @summary Blocked / Blocked by FIDs
*
* @param {object} params
* @param {number} params.blockerFid [optional] - Providing this will return the users that this user has blocked
* @param {number} params.blockedFid [optional] - Providing this will return the users that have blocked this user
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<BlockListResponse>} A promise that resolves to a `BlockListResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const blockerFid =
* const blockedFid =
* const limit =
*
* client.fetchBlockList({ blockerFid, blockedFid, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-block-list)
*
*/
async fetchBlockList(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.blockApi.fetchBlockList(adjustedParams);
return response.data;
}
/**
* Adds a block for a given FID.
*
* @summary Block FID
*
* @param {object} params
* @param {string} params.signerUuid - UUID of the signer. `signer_uuid` is paired with API key, can't use a `uuid` made with a different API key.
* @param {number} params.blockedFid - The unique identifier of a farcaster user or app (unsigned integer)
*
* @returns {Promise<OperationResponse>} A promise that resolves to a `OperationResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const signerUuid =
* const blockedFid =
*
* client.publishBlock({signerUuid, blockedFid}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/publish-block)
*
*/
async publishBlock(params) {
const adjustedParams = {};
const _params = { blockReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.blockApi.publishBlock(adjustedParams);
return response.data;
}
/**
* Delete an existing cast. (In order to delete a cast `signer_uuid` must be approved)
*
* @summary Delete a cast
*
* @param {object} params
* @param {string} params.signerUuid - UUID of the signer. `signer_uuid` is paired with API key, can't use a `uuid` made with a different API key.
* @param {string} params.targetHash
*
* @returns {Promise<OperationResponse>} A promise that resolves to a `OperationResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const signerUuid =
* const targetHash =
*
* client.deleteCast({signerUuid, targetHash}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/delete-cast)
*
*/
async deleteCast(params) {
const adjustedParams = {};
const _params = { deleteCastReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.castApi.deleteCast(adjustedParams);
return response.data;
}
/**
* Fetch multiple casts using their respective hashes.
*
* @summary Bulk fetch casts
*
* @param {object} params
* @param {string[]} params.casts - Hashes of the cast to be retrived (Comma separated, no spaces)
* @param {number} params.viewerFid [optional] - adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
* @param {FetchBulkCastsSortTypeEnum} params.sortType [optional] - Optional parameter to sort the casts based on different criteria
*
* @returns {Promise<CastsResponse>} A promise that resolves to a `CastsResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const casts =
* const viewerFid =
* const sortType =
*
* client.fetchBulkCasts({ casts, viewerFid, sortType }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-bulk-casts)
*
*/
async fetchBulkCasts(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
if (adjustedParams.casts && Array.isArray(adjustedParams.casts)) {
adjustedParams.casts = adjustedParams.casts.join(",");
}
const response = await this.apis.castApi.fetchBulkCasts(adjustedParams);
return response.data;
}
/**
* Fetch casts that quote a given cast
*
* @summary Cast Quotes
*
* @param {object} params
* @param {string} params.identifier - Cast identifier (It's either a URL or a hash)
* @param {FetchCastQuotesTypeEnum} params.type - The query param accepted by the API. Sent along with identifier param. url - Cast identifier is a url hash - Cast identifier is a hash
* @param {number} params.viewerFid [optional]
* @param {number} params.limit [optional] - Number of results to fetch (Default: 25, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<FetchCastQuotes200Response>} A promise that resolves to a `FetchCastQuotes200Response` object.
*
* @example
*
* // Fill in the appropriate values
* const identifier =
* const type =
* const viewerFid =
* const limit =
*
* client.fetchCastQuotes({ identifier, type, viewerFid, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-cast-quotes)
*
*/
async fetchCastQuotes(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.castApi.fetchCastQuotes(adjustedParams);
return response.data;
}
/**
* Crawls the given URL and returns metadata useful when embedding the URL in a cast.
*
* @summary Embedded URL metadata
*
* @param {object} params
* @param {string} params.url - URL to crawl metadata of
*
* @returns {Promise<CastEmbedCrawlResponse>} A promise that resolves to a `CastEmbedCrawlResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const url =
*
* client.fetchEmbeddedUrlMetadata({ url }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-embedded-url-metadata)
*
*/
async fetchEmbeddedUrlMetadata(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.castApi.fetchEmbeddedUrlMetadata(adjustedParams);
return response.data;
}
/**
* Gets information about an individual cast by passing in a Farcaster web URL or cast hash
*
* @summary By hash or URL
*
* @param {object} params
* @param {string} params.identifier - Cast identifier (It's either a URL or a hash)
* @param {LookupCastByHashOrUrlTypeEnum} params.type - The query param accepted by the API. Sent along with identifier param. url - Cast identifier is a url hash - Cast identifier is a hash
* @param {number} params.viewerFid [optional] - adds viewer_context to cast object to show whether viewer has liked or recasted the cast.
*
* @returns {Promise<CastResponse>} A promise that resolves to a `CastResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const identifier =
* const type =
* const viewerFid =
*
* client.lookupCastByHashOrUrl({ identifier, type, viewerFid }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/lookup-cast-by-hash-or-url)
*
*/
async lookupCastByHashOrUrl(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.castApi.lookupCastByHashOrUrl(adjustedParams);
return response.data;
}
/**
* Gets all casts related to a conversation surrounding a cast by passing in a cast hash or Farcaster URL. Includes all the ancestors of a cast up to the root parent in a chronological order. Includes all direct_replies to the cast up to the reply_depth specified in the query parameter.
*
* @summary Conversation for a cast
*
* @param {object} params
* @param {string} params.identifier - Cast identifier (It's either a URL or a hash)
* @param {LookupCastConversationTypeEnum} params.type - The query param accepted by the API. Sent along with identifier param. url - Cast identifier is a url hash - Cast identifier is a hash
* @param {number | null} params.replyDepth [optional] - The depth of replies in the conversation that will be returned (default 2)
* @param {boolean | null} params.includeChronologicalParentCasts [optional] - Include all parent casts in chronological order
* @param {number} params.viewerFid [optional] - Providing this will return a conversation that respects this user's mutes and blocks and includes `viewer_context`.
* @param {LookupCastConversationSortTypeEnum} params.sortType [optional] - Sort type for the ordering of descendants. Default is `chron`
* @param {LookupCastConversationFoldEnum} params.fold [optional] - Show conversation above or below the fold. Lower quality responses are hidden below the fold. Not passing in a value shows the full conversation without any folding.
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 50)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<Conversation>} A promise that resolves to a `Conversation` object.
*
* @example
*
* // Fill in the appropriate values
* const identifier =
* const type =
* const replyDepth =
* const includeChronologicalParentCasts =
* const viewerFid =
* const sortType =
* const fold =
* const limit =
*
* client.lookupCastConversation({ identifier, type, replyDepth, includeChronologicalParentCasts, viewerFid, sortType, fold, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/lookup-cast-conversation)
*
*/
async lookupCastConversation(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.castApi.lookupCastConversation(adjustedParams);
return response.data;
}
/**
* Posts a cast or cast reply. Works with mentions and embeds. (In order to post a cast `signer_uuid` must be approved)
*
* @summary Post a cast
*
* @param {object} params
* @param {string} params.signerUuid - UUID of the signer. `signer_uuid` is paired with API key, can't use a `uuid` made with a different API key.
* @param {string} params.text [optional]
* @param {Array<PostCastReqBodyEmbeds>} params.embeds [optional]
* @param {string} params.parent [optional] - parent_url of the channel the cast is in, or hash of the cast
* @param {string} params.channelId [optional] - Channel ID of the channel where the cast is to be posted. e.g. neynar, farcaster, warpcast
* @param {string} params.idem [optional] - An Idempotency key is a unique identifier for the request. **Note:** 1) This is used to prevent duplicate requests. Use the same idem key on retry attempts. 2) This should be a unique identifier for each request. 3) Recommended format is a 16-character string generated by the developer at the time of making this request.
* @param {number} params.parentAuthorFid [optional] - The unique identifier of a farcaster user or app (unsigned integer)
*
* @returns {Promise<PostCastResponse>} A promise that resolves to a `PostCastResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const signerUuid =
* const text =
* const embeds =
* const parent =
* const channelId =
* const idem =
* const parentAuthorFid =
*
* client.publishCast({signerUuid, text, embeds, parent, channelId, idem, parentAuthorFid}).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/publish-cast)
*
*/
async publishCast(params) {
const adjustedParams = {};
const _params = { postCastReqBody: camelCaseToSnakeCaseKeys(params) };
Object.assign(adjustedParams, _params);
const response = await this.apis.castApi.publishCast(adjustedParams);
return response.data;
}
/**
* Search for casts based on a query string, with optional AND filters
*
* @summary Search for casts
*
* @param {object} params
* @param {string} params.q - Query string to search for casts. Supported operators: | Operator | Description | | --------- | -------------------------------------------------------------------------------------------------------- | | `+` | Acts as the AND operator. This is the default operator between terms and can usually be omitted. | | `|` | Acts as the OR operator. | | `*` | When used at the end of a term, signifies a prefix query. | | `"` | Wraps several terms into a phrase (for example, `"star wars"`). | | `(`, `)` | Wrap a clause for precedence (for example, `star + (wars | trek)`). | | `~n` | When used after a term (for example, `satr~3`), sets `fuzziness`. When used after a phrase, sets `slop`. | | `-` | Negates the term. | | `before:` | Search for casts before a specific date. (e.g. `before:2025-04-20` or `before:2025-04-20T23:59:59`) | | `after:` | Search for casts after a specific date. (e.g. `after:2025-04-20` or `after:2025-04-20T00:00:00`) |
* @param {SearchCastsModeEnum} params.mode [optional] - Choices are: - `literal` - Searches for the words in the query string (default) - `semantic` - Searches for the meaning of the query string - `hybrid` - Combines both literal and semantic results
* @param {SearchCastsSortTypeEnum} params.sortType [optional] - Choices are: - `desc_chron` - All casts sorted by time in a descending order (default) - `chron` - All casts sorted by time in ascending order - `algorithmic` - Casts sorted by engagement and time
* @param {number} params.authorFid [optional] - Fid of the user whose casts you want to search
* @param {number} params.viewerFid [optional] - Providing this will return search results that respects this user's mutes and blocks and includes `viewer_context`.
* @param {string} params.parentUrl [optional] - Parent URL of the casts you want to search
* @param {string} params.channelId [optional] - Channel ID of the casts you want to search
* @param {number} params.limit [optional] - Number of results to fetch (Default: 25, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor
*
* @returns {Promise<CastsSearchResponse>} A promise that resolves to a `CastsSearchResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const q =
* const mode =
* const sortType =
* const authorFid =
* const viewerFid =
* const parentUrl =
* const channelId =
* const limit =
*
* client.searchCasts({ q, mode, sortType, authorFid, viewerFid, parentUrl, channelId, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/search-casts)
*
*/
async searchCasts(params) {
var _a, _b;
const adjustedParams = {};
Object.assign(adjustedParams, params);
adjustedParams['xNeynarExperimental'] = (_b = (_a = this.config.baseOptions) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-neynar-experimental'];
const response = await this.apis.castApi.searchCasts(adjustedParams);
return response.data;
}
/**
* Returns a list of all channels with their details
*
* @summary Fetch all channels with their details
*
* @param {object} params
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 200)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to a `ChannelListResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const limit =
*
* client.fetchAllChannels({ limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-all-channels)
*
*/
async fetchAllChannels(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.channelApi.fetchAllChannels(adjustedParams);
return response.data;
}
/**
* Returns details of multiple channels
*
* @summary Bulk fetch
*
* @param {object} params
* @param {string[]} params.ids - Comma separated list of channel IDs or parent_urls, up to 100 at a time
* @param {FetchBulkChannelsTypeEnum} params.type [optional] - Type of identifier being used to query the channels. Defaults to ID.
* @param {number} params.viewerFid [optional] - FID of the user viewing the channels.
*
* @returns {Promise<ChannelResponseBulk>} A promise that resolves to a `ChannelResponseBulk` object.
*
* @example
*
* // Fill in the appropriate values
* const ids =
* const type =
* const viewerFid =
*
* client.fetchBulkChannels({ ids, type, viewerFid }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-bulk-channels)
*
*/
async fetchBulkChannels(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
if (adjustedParams.ids && Array.isArray(adjustedParams.ids)) {
adjustedParams.ids = adjustedParams.ids.join(",");
}
const response = await this.apis.channelApi.fetchBulkChannels(adjustedParams);
return response.data;
}
/**
* Fetch a list of invites, either in a channel or for a user. If both are provided, open channel invite for that user is returned.
*
* @summary Open invites
*
* @param {object} params
* @param {string} params.channelId [optional] - Channel ID for the channel being queried
* @param {number} params.invitedFid [optional] - FID of the user being invited
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<ChannelMemberInviteListResponse>} A promise that resolves to a `ChannelMemberInviteListResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const channelId =
* const invitedFid =
* const limit =
*
* client.fetchChannelInvites({ channelId, invitedFid, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-channel-invites)
*
*/
async fetchChannelInvites(params) {
const adjustedParams = {};
Object.assign(adjustedParams, params);
const response = await this.apis.channelApi.fetchChannelInvites(adjustedParams);
return response.data;
}
/**
* Fetch a list of members in a channel
*
* @summary Fetch members
*
* @param {object} params
* @param {string} params.channelId - Channel ID for the channel being queried
* @param {number} params.fid [optional] - FID of the user being queried. Specify this to check if a user is a member of the channel without paginating through all members.
* @param {number} params.limit [optional] - Number of results to fetch (Default: 20, Maximum: 100)
* @param {string} params.cursor [optional] - Pagination cursor.
*
* @returns {Promise<ChannelMemberListResponse>} A promise that resolves to a `ChannelMemberListResponse` object.
*
* @example
*
* // Fill in the appropriate values
* const channelId =
* const fid =
* const limit =
*
* client.fetchChannelMembers({ channelId, fid, limit }).then(response => {
* console.log('response:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-channel-members)
*
*/
async fetchChannelMembers(params) {