From 99ec331cbcd6d6af672d564be0109505a488b57c Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Mon, 21 Oct 2024 19:14:32 +0530 Subject: [PATCH] Update the oas and sdk and add publishFarcasterAction --- src/neynar-api/neynar-api-client.ts | 68 +++++++-- src/neynar-api/v2/client.ts | 137 +++++++++++------ .../.openapi-generator/FILES | 3 + src/neynar-api/v2/openapi-farcaster/api.ts | 1 + .../v2/openapi-farcaster/apis/action-api.ts | 140 ++++++++++++++++++ .../farcaster-action-req-body-action.ts | 36 +++++ .../models/farcaster-action-req-body.ts | 45 ++++++ .../v2/openapi-farcaster/models/index.ts | 2 + 8 files changed, 374 insertions(+), 58 deletions(-) create mode 100644 src/neynar-api/v2/openapi-farcaster/apis/action-api.ts create mode 100644 src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body-action.ts create mode 100644 src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body.ts diff --git a/src/neynar-api/neynar-api-client.ts b/src/neynar-api/neynar-api-client.ts index ccd6f9cd..ba38fed0 100644 --- a/src/neynar-api/neynar-api-client.ts +++ b/src/neynar-api/neynar-api-client.ts @@ -82,6 +82,7 @@ import { ChannelMemberInviteListResponse, ChannelMemberListResponse, FollowersResponse, + FarcasterActionReqBodyAction, } from "./v2/openapi-farcaster"; import { @@ -265,7 +266,7 @@ export class NeynarAPIClient { /** * @deprecated * Now deprecated, use v2's `lookupUserByUsernameV2` instead. - * + * * Retrieves the specified user via their username (if found). * * @param {string} username - The username of the user whose information is being retrieved. @@ -679,6 +680,48 @@ export class NeynarAPIClient { // ============ v2 APIs ============ + // ------------ Action ------------ + + /** + * Perform actions on behalf of users across different apps. + * + * This method enables an application to securely communicate and trigger actions in another app on behalf of a mutual user. + * The actions are performed by signing messages using the user's Farcaster signer, ensuring that all actions are authenticated and authorized. + * + * @param {FarcasterActionReqBody} farcasterActionReqBody - The request body containing the action details and the necessary information to perform the action. + * + * @returns {Promise} A promise that resolves to an object containing the response data. + * The structure of the response can vary depending on the action performed, as defined by the API's response schema by the app performing the action. + * + * @example + * // Example: Perform an action on behalf of a user + * const signerUuid = '19d0c5fd-9b33-4a48-a0e2-bc7b0555baec'; + * const base_url = "https://appb.example.com", + * const action = { + * type: "sendMessage", + * payload: { + * "message": "Hello from App A!" + * } + * }; + * + * client.publishFarcasterAction(signerUuid, url, action).then(response => { + * console.log('Action Response:', response); // Outputs the response of the action + * }); + * + * For more information, refer to the [Neynar documentation](https://docs.neynar.com/docs/farcaster-actions-spec). + */ + public async publishFarcasterAction( + signerUuid: string, + base_url: string, + action: FarcasterActionReqBodyAction + ): Promise { + return await this.clients.v2.publishFarcasterAction( + signerUuid, + base_url, + action + ); + } + // ------------ Signer ------------ /** @@ -1360,14 +1403,14 @@ export class NeynarAPIClient { * console.log('Cast Conversation Information:', response); // Displays the detailed structure of the specified cast conversation * }); * - * + * * @example * // Implement above and below 'the fold', generally seen in clients as "show more replies". * // Fetch first page above the fold: * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: true, * fold: 'above', @@ -1381,7 +1424,7 @@ export class NeynarAPIClient { * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: false, * fold: 'above', @@ -1395,7 +1438,7 @@ export class NeynarAPIClient { * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: false, * fold: 'below', @@ -1405,8 +1448,8 @@ export class NeynarAPIClient { * }).then(response => { * console.log('Casts from below the fold:', response.conversation.cast.direct_replies); * }); - * - * + * + * * // Refer to the Neynar API documentation for more details and advanced options: * // https://docs.neynar.com/reference/cast-conversation */ @@ -1418,7 +1461,7 @@ export class NeynarAPIClient { includeChronologicalParentCasts?: boolean; viewerFid?: number; sortType?: CastConversationSortType; - fold?: 'above' | 'below'; + fold?: "above" | "below"; limit?: number; cursor?: string; } @@ -3009,7 +3052,8 @@ export class NeynarAPIClient { * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-channel-memberships). */ - public async fetchUserChannelMemberships(fid: number, + public async fetchUserChannelMemberships( + fid: number, options?: { limit?: number; cursor?: string; @@ -3822,7 +3866,7 @@ export class NeynarAPIClient { public async fetchBanList( options: { limit?: number; cursor?: string } = {} ): Promise { - const { limit, cursor = '' } = options; + const { limit, cursor = "" } = options; return await this.clients.v2.fetchBanList({ limit, cursor }); } @@ -3842,9 +3886,7 @@ export class NeynarAPIClient { * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/add-ban). * */ - public async publishBans( - fids: number[] - ): Promise { + public async publishBans(fids: number[]): Promise { return await this.clients.v2.publishBans(fids); } diff --git a/src/neynar-api/v2/client.ts b/src/neynar-api/v2/client.ts index cebac1e5..4a32c721 100644 --- a/src/neynar-api/v2/client.ts +++ b/src/neynar-api/v2/client.ts @@ -104,6 +104,9 @@ import { ChannelMemberListResponse, ChannelFollowReqBody, FollowersResponse, + FarcasterActionReqBody, + FarcasterActionReqBodyAction, + ActionApi, } from "./openapi-farcaster"; import axios, { AxiosError, AxiosInstance } from "axios"; import { silentLogger, Logger } from "../common/logger"; @@ -126,6 +129,7 @@ export class NeynarV2APIClient { private readonly apiKey: string; public readonly apis: { + action: ActionApi; signer: SignerApi; user: UserApi; cast: CastApi; @@ -210,6 +214,7 @@ export class NeynarV2APIClient { }); this.apis = { + action: new ActionApi(config, undefined, axiosInstance), signer: new SignerApi(config, undefined, axiosInstance), user: new UserApi(config, undefined, axiosInstance), cast: new CastApi(config, undefined, axiosInstance), @@ -246,6 +251,54 @@ export class NeynarV2APIClient { ); } + // ------------ Action ------------ + + /** + * Perform actions on behalf of users across different apps. + * + * This method enables an application to securely communicate and trigger actions in another app on behalf of a mutual user. + * The actions are performed by signing messages using the user's Farcaster signer, ensuring that all actions are authenticated and authorized. + * + * @param {FarcasterActionReqBody} farcasterActionReqBody - The request body containing the action details and the necessary information to perform the action. + * + * @returns {Promise} A promise that resolves to an object containing the response data. + * The structure of the response can vary depending on the action performed, as defined by the API's response schema by the app performing the action. + * + * @example + * // Example: Perform an action on behalf of a user + * const signerUuid = '19d0c5fd-9b33-4a48-a0e2-bc7b0555baec'; + * const base_url = "https://appb.example.com", + * const action = { + * type: "sendMessage", + * payload: { + * "message": "Hello from App A!" + * } + * }; + * + * client.publishFarcasterAction(signerUuid, url, action).then(response => { + * console.log('Action Response:', response); // Outputs the response of the action + * }); + * + * For more information, refer to the [Neynar documentation](https://docs.neynar.com/docs/farcaster-actions-spec). + */ + public async publishFarcasterAction( + signerUuid: string, + baseUrl: string, + action: FarcasterActionReqBodyAction + ) { + const farcasterActionReqBody: FarcasterActionReqBody = { + signer_uuid: signerUuid, + base_url: baseUrl, + action: action, + }; + + const response = await this.apis.action.publishFarcasterAction( + this.apiKey, + farcasterActionReqBody + ); + return response.data; + } + // ------------ Signer ------------ /** @@ -1032,19 +1085,19 @@ export class NeynarV2APIClient { * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-by-username-v2). */ - public async lookupUserByUsernameV2( - username: string, - options?: { - viewerFid?: number; - } - ): Promise { - const response = await this.apis.user.userByUsernameV2( - this.apiKey, - username, - options?.viewerFid - ); - return response.data; + public async lookupUserByUsernameV2( + username: string, + options?: { + viewerFid?: number; } + ): Promise { + const response = await this.apis.user.userByUsernameV2( + this.apiKey, + username, + options?.viewerFid + ); + return response.data; + } // ------------ Cast ------------ @@ -1171,7 +1224,7 @@ export class NeynarV2APIClient { * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: true, * fold: 'above', @@ -1185,7 +1238,7 @@ export class NeynarV2APIClient { * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: false, * fold: 'above', @@ -1199,7 +1252,7 @@ export class NeynarV2APIClient { * client.lookupCastConversation( * 'https://warpcast.com/rish/0x9288c1', * CastParamType.Url, - * { + * { * replyDepth: 2, * includeChronologicalParentCasts: false, * fold: 'below', @@ -1209,7 +1262,7 @@ export class NeynarV2APIClient { * }).then(response => { * console.log('Casts from below the fold:', response.conversation.cast.direct_replies); * }); - * + * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/cast-conversation). */ public async lookupCastConversation( @@ -1220,7 +1273,7 @@ export class NeynarV2APIClient { includeChronologicalParentCasts?: boolean; viewerFid?: number; sortType?: CastConversationSortType; - fold? : 'above' | 'below'; + fold?: "above" | "below"; limit?: number; cursor?: string; } @@ -3078,21 +3131,21 @@ export class NeynarV2APIClient { * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-channel-memberships). */ - public async fetchUserChannelMemberships( - fid: number, - options?: { - limit?: number; - cursor?: string; - } - ): Promise { - const response = await this.apis.channel.userChannelMemberships( - this.apiKey, - fid, - options?.limit, - options?.cursor - ); - return response.data; + public async fetchUserChannelMemberships( + fid: number, + options?: { + limit?: number; + cursor?: string; } + ): Promise { + const response = await this.apis.channel.userChannelMemberships( + this.apiKey, + fid, + options?.limit, + options?.cursor + ); + return response.data; + } // ------------ Storage ------------ @@ -3972,9 +4025,10 @@ export class NeynarV2APIClient { * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/ban-list). */ - public async fetchBanList( - options?: { limit?: number; cursor: string } - ): Promise { + public async fetchBanList(options?: { + limit?: number; + cursor: string; + }): Promise { const response = await this.apis.ban.banList( this.apiKey, options?.limit, @@ -3999,11 +4053,9 @@ export class NeynarV2APIClient { * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/add-ban). * */ - public async publishBans( - fids: number[] - ): Promise { + public async publishBans(fids: number[]): Promise { const addBanBody = { - fids + fids, }; const response = await this.apis.ban.addBan(this.apiKey, addBanBody); return response.data; @@ -4024,16 +4076,11 @@ export class NeynarV2APIClient { * * For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/delete-ban). */ - public async deleteBans( - fids: number[] - ): Promise { + public async deleteBans(fids: number[]): Promise { const deleteBanBody = { fids, }; - const response = await this.apis.ban.deleteBan( - this.apiKey, - deleteBanBody - ); + const response = await this.apis.ban.deleteBan(this.apiKey, deleteBanBody); return response.data; } diff --git a/src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES b/src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES index 5f68294e..d1d30470 100644 --- a/src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES +++ b/src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES @@ -2,6 +2,7 @@ .npmignore .openapi-generator-ignore api.ts +apis/action-api.ts apis/ban-api.ts apis/block-api.ts apis/cast-api.ts @@ -99,6 +100,8 @@ models/embed-url-metadata.ts models/embed-url.ts models/embedded-cast.ts models/error-res.ts +models/farcaster-action-req-body-action.ts +models/farcaster-action-req-body.ts models/feed-for-you400-response.ts models/feed-response.ts models/feed-trending-provider.ts diff --git a/src/neynar-api/v2/openapi-farcaster/api.ts b/src/neynar-api/v2/openapi-farcaster/api.ts index 51eafc11..f273b258 100644 --- a/src/neynar-api/v2/openapi-farcaster/api.ts +++ b/src/neynar-api/v2/openapi-farcaster/api.ts @@ -14,6 +14,7 @@ +export * from './apis/action-api'; export * from './apis/ban-api'; export * from './apis/block-api'; export * from './apis/cast-api'; diff --git a/src/neynar-api/v2/openapi-farcaster/apis/action-api.ts b/src/neynar-api/v2/openapi-farcaster/apis/action-api.ts new file mode 100644 index 00000000..c18f44f7 --- /dev/null +++ b/src/neynar-api/v2/openapi-farcaster/apis/action-api.ts @@ -0,0 +1,140 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Farcaster API V2 + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from '../configuration'; +import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; +// Some imports not used depending on template conditions +// @ts-ignore +import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; +// @ts-ignore +import { FarcasterActionReqBody } from '../models'; +/** + * ActionApi - axios parameter creator + * @export + */ +export const ActionApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * 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 Perform actions on behalf of users across different apps + * @param {string} apiKey API key required for authentication. + * @param {FarcasterActionReqBody} farcasterActionReqBody + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + publishFarcasterAction: async (apiKey: string, farcasterActionReqBody: FarcasterActionReqBody, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'apiKey' is not null or undefined + assertParamExists('publishFarcasterAction', 'apiKey', apiKey) + // verify required parameter 'farcasterActionReqBody' is not null or undefined + assertParamExists('publishFarcasterAction', 'farcasterActionReqBody', farcasterActionReqBody) + const localVarPath = `/farcaster/action`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (apiKey != null) { + localVarHeaderParameter['api_key'] = String(apiKey); + } + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(farcasterActionReqBody, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * ActionApi - functional programming interface + * @export + */ +export const ActionApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = ActionApiAxiosParamCreator(configuration) + return { + /** + * 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 Perform actions on behalf of users across different apps + * @param {string} apiKey API key required for authentication. + * @param {FarcasterActionReqBody} farcasterActionReqBody + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async publishFarcasterAction(apiKey: string, farcasterActionReqBody: FarcasterActionReqBody, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<{ [key: string]: any; }>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.publishFarcasterAction(apiKey, farcasterActionReqBody, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + } +}; + +/** + * ActionApi - factory interface + * @export + */ +export const ActionApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = ActionApiFp(configuration) + return { + /** + * 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 Perform actions on behalf of users across different apps + * @param {string} apiKey API key required for authentication. + * @param {FarcasterActionReqBody} farcasterActionReqBody + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + publishFarcasterAction(apiKey: string, farcasterActionReqBody: FarcasterActionReqBody, options?: any): AxiosPromise<{ [key: string]: any; }> { + return localVarFp.publishFarcasterAction(apiKey, farcasterActionReqBody, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * ActionApi - object-oriented interface + * @export + * @class ActionApi + * @extends {BaseAPI} + */ +export class ActionApi extends BaseAPI { + /** + * 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 Perform actions on behalf of users across different apps + * @param {string} apiKey API key required for authentication. + * @param {FarcasterActionReqBody} farcasterActionReqBody + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ActionApi + */ + public publishFarcasterAction(apiKey: string, farcasterActionReqBody: FarcasterActionReqBody, options?: AxiosRequestConfig) { + return ActionApiFp(this.configuration).publishFarcasterAction(apiKey, farcasterActionReqBody, options).then((request) => request(this.axios, this.basePath)); + } +} diff --git a/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body-action.ts b/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body-action.ts new file mode 100644 index 00000000..f58dcfb7 --- /dev/null +++ b/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body-action.ts @@ -0,0 +1,36 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Farcaster API V2 + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface FarcasterActionReqBodyAction + */ +export interface FarcasterActionReqBodyAction { + /** + * The type of action being performed. + * @type {string} + * @memberof FarcasterActionReqBodyAction + */ + 'type': string; + /** + * The payload of the action being performed. + * @type {object} + * @memberof FarcasterActionReqBodyAction + */ + 'payload': object; +} + diff --git a/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body.ts b/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body.ts new file mode 100644 index 00000000..611f7a40 --- /dev/null +++ b/src/neynar-api/v2/openapi-farcaster/models/farcaster-action-req-body.ts @@ -0,0 +1,45 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Farcaster API V2 + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import { FarcasterActionReqBodyAction } from './farcaster-action-req-body-action'; + +/** + * + * @export + * @interface FarcasterActionReqBody + */ +export interface FarcasterActionReqBody { + /** + * The signer_uuid of the user on behalf of whom the action is being performed. + * @type {string} + * @memberof FarcasterActionReqBody + */ + 'signer_uuid': string; + /** + * The base URL of the app on which the action is being performed. + * @type {string} + * @memberof FarcasterActionReqBody + */ + 'base_url': string; + /** + * + * @type {FarcasterActionReqBodyAction} + * @memberof FarcasterActionReqBody + */ + 'action': FarcasterActionReqBodyAction; +} + diff --git a/src/neynar-api/v2/openapi-farcaster/models/index.ts b/src/neynar-api/v2/openapi-farcaster/models/index.ts index 714df749..9de17053 100644 --- a/src/neynar-api/v2/openapi-farcaster/models/index.ts +++ b/src/neynar-api/v2/openapi-farcaster/models/index.ts @@ -74,6 +74,8 @@ export * from './embed-url-metadata-video'; export * from './embed-url-metadata-video-stream-inner'; export * from './embedded-cast'; export * from './error-res'; +export * from './farcaster-action-req-body'; +export * from './farcaster-action-req-body-action'; export * from './feed-for-you400-response'; export * from './feed-response'; export * from './feed-trending-provider';