Skip to content

Commit

Permalink
update v1 sdk for stp changes and Add fetchFollowSuggestions and `f…
Browse files Browse the repository at this point in the history
…etchFrameMetaTagsFromUrl` (#238)

* remove stp as a seperate folder

* Patch update: v1.70.1

* add fetchFollowSuggestions and fetchFrameMetaTagsFromUrl

* feat: new method to fetch user's token balances (#239)

* generate code

* new model files

* add new method to client

* Bump up minor version

* add networks model

* update user api

* update clients

* base-mainnet -> base

---------

Co-authored-by: Shreyaschorge <[email protected]>

---------

Co-authored-by: Valerie Coffman <[email protected]>
  • Loading branch information
Shreyaschorge and valerierose authored Nov 13, 2024
1 parent 370529d commit 71fc030
Show file tree
Hide file tree
Showing 35 changed files with 677 additions and 716 deletions.
5 changes: 0 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Auto-generated code is located in the following directories:

- `src/neynar-api/v1/openapi`
- `src/neynar-api/v2/openapi-farcaster`
- `src/neynar-api/v2/openapi-stp`

These are generated using [openapi-generator-cli](https://github.com/OpenAPITools/openapi-generator-cli). To make changes, update the OpenAPI Specification (OAS) in the [OAS Repository](https://github.com/neynarxyz/oas). After updating the OAS, synchronize the OAS in your local clone of the SDK repository.

Expand All @@ -49,10 +48,6 @@ yarn generate:neynar-oas-v1-farcaster
```bash
yarn generate:neynar-oas-v2-farcaster
```
- For STP APIs
```bash
yarn generate:neynar-oas-v2-stp
```

### Writing Wrapper Code

Expand Down
15 changes: 15 additions & 0 deletions openapi-generator-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"withSeparateModelsAndApi": true,
"apiPackage": "apis",
"modelPackage": "models",
"templateDir": "./templates",
"modelPropertyNaming": "original",
"ensureUniqueParams": true,
"generateAliasAsModel": true,
"additionalProperties": {
"useSingleRequestParameter": true,
"withInterfaces": true,
"supportsES6": true,
"paramNaming": "snake_case"
}
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "1.70.0",
"version": "1.71.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand All @@ -10,9 +10,8 @@
"scripts": {
"clean": "del-cli ./build/*",
"build": "yarn run clean && tsc",
"generate:neynar-oas-v1-farcaster": "del-cli src/neynar-api/v1/openapi; openapi-generator-cli generate -i src/oas/src/v1/spec.yaml -g typescript-axios -o src/neynar-api/v1/openapi --config src/oas/openapi-generator-config.json --inline-schema-options 'REFACTOR_ALLOF_INLINE_SCHEMAS=true'",
"generate:neynar-oas-v2-farcaster": "del-cli src/neynar-api/v2/openapi-farcaster; openapi-generator-cli generate -i src/oas/src/v2/spec.yaml -g typescript-axios -o src/neynar-api/v2/openapi-farcaster --config src/oas/openapi-generator-config.json --inline-schema-options 'REFACTOR_ALLOF_INLINE_SCHEMAS=true'",
"generate:neynar-oas-v2-stp": "del-cli src/neynar-api/v2/openapi-stp; openapi-generator-cli generate -i src/oas/src/v2/stp/spec.yaml -g typescript-axios -o src/neynar-api/v2/openapi-stp --config src/oas/openapi-generator-config.json --inline-schema-options 'REFACTOR_ALLOF_INLINE_SCHEMAS=true'"
"generate:neynar-oas-v1-farcaster": "del-cli src/neynar-api/v1/openapi; openapi-generator-cli generate -i src/oas/src/v1/spec.yaml -g typescript-axios -o src/neynar-api/v1/openapi --config ./openapi-generator-config.json --inline-schema-options 'REFACTOR_ALLOF_INLINE_SCHEMAS=true'",
"generate:neynar-oas-v2-farcaster": "del-cli src/neynar-api/v2/openapi-farcaster; openapi-generator-cli generate -i src/oas/src/v2/spec.yaml -g typescript-axios -o src/neynar-api/v2/openapi-farcaster --config ./openapi-generator-config.json --inline-schema-options 'REFACTOR_ALLOF_INLINE_SCHEMAS=true'"
},
"author": "Neynar",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/neynar-api/common/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "1.70.0";
export const version = "1.71.0";
75 changes: 74 additions & 1 deletion src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ import {
PostCastReqBodyEmbeds,
NeynarFrameUpdateReqBody,
NeynarFrameCreationReqBody,
BalanceResponse,
Networks,
FetchFrameMetaTagsFromUrl200Response,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -1542,6 +1545,26 @@ export class NeynarAPIClient {
);
}

/**
* Fetches the token balance of a user given their FID.
*
* @param {number} fid - The FID of the user whose token balance is being fetched.
* @param {Array<Networks>} networks Comma separated list of networks to fetch balances for. Currently, only \&quot;base\&quot; is supported.
*
* @returns {Promise<BalanceResponse>} A promise that resolves to a `BalanceResponse` object
*
* @example
* // Example: Fetch the token balance of a user with FID 3
* client.fetchUserBalance(3).then(response => {
* console.log('User Balance:', response); // Outputs the token balance of the user
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/fetch-user-balance)
*/
public async fetchUserBalance(fid: number, networks: Networks[]): Promise<BalanceResponse> {
return await this.clients.v2.fetchUserBalance(fid, networks);
}

// ------------ Cast ------------

/**
Expand Down Expand Up @@ -3034,6 +3057,33 @@ export class NeynarAPIClient {
return await this.clients.v2.fetchUserChannelMemberships(fid, options);
}

/**
* Fetch a list of suggested users to follow. Used to help users discover new users to follow
*
* @param {number} fid - FID of the user whose following you want to fetch.
* @param {Object} [options] - Optional parameters for customizing the response
* @param {number} [options.limit] - Number of results to fetch (Default: 25, Maximum: 100)
* @param {number} [options.viewerFid] - Providing this will return a list of users that respects this user's mutes and blocks and includes `viewer_context`.
*
* @returns {Promise<UsersResponse>} A promise that resolves to a `UsersResponse` object
*
* @example
*
* // Example: Fetch follow suggestions for a user
* client.fetchFollowSuggestions(3, {limit: 5}).then(response => {
* console.log('Follow Suggestions:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/fetch-follow-suggestions)
*
*/
public async fetchFollowSuggestions(
fid: number,
options?: { limit?: number; viewerFid?: number }
): Promise<UsersResponse> {
return await this.clients.v2.fetchFollowSuggestions(fid, options);
}

// ------------ Storage ------------

/**
Expand Down Expand Up @@ -3244,6 +3294,29 @@ export class NeynarAPIClient {
return await this.clients.v2.deleteNeynarFrame(uuid);
}

/**
* Fetches the frame meta tags from the URL
*
* @param {string} url - The URL from which to fetch the frame meta tags
*
* @returns {Promise<FetchFrameMetaTagsFromUrl200Response>} A promise that resolves to a `FetchFrameMetaTagsFromUrl200Response` object
*
* @example
* // Example: Fetch frame meta tags from a URL
* const url = 'https://frames.neynar.com/f/862277df/ff7be6a4';
* client.fetchFrameMetaTagsFromUrl(url).then(response => {
* console.log('Frame Meta Tags:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-frame-meta-tags-from-url)
*
*/
public async fetchFrameMetaTagsFromUrl(
url: string
): Promise<FetchFrameMetaTagsFromUrl200Response> {
return await this.clients.v2.fetchFrameMetaTagsFromUrl(url);
}

/**
* Retrieves a list of frames created by the developer, identified through the provided API key.
* This method is essential for developers to review their frames submitted to the platform.
Expand Down Expand Up @@ -4000,7 +4073,7 @@ export class NeynarAPIClient {
* @example
* // Example: Fetch Subscription Check for tabletop on Base.
* client.fetchSubscriptionCheck(['0xedd3783e8c7c52b80cfbd026a63c207edc9cbee7','0x5a927ac639636e534b678e81768ca19e2c6280b7'], '0x76ad4cb9ac51c09f4d9c2cadcea75c9fa9074e5b', '8453').then(response => {
*
* console.log('Subscription Check:', response)});
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/subscription-check).
*/
Expand Down
87 changes: 84 additions & 3 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ import {
InviteChannelMemberReqBody,
RemoveChannelMemberReqBody,
RespondChannelInviteReqBody,
StpApi,
SubscriptionStatus,
BalanceResponse,
Networks,
FetchFrameMetaTagsFromUrl200Response,
} from "./openapi-farcaster";
import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
Expand All @@ -123,7 +128,6 @@ import {
ValidateFrameAggregateWindow,
} from "../common/constants";
import { version } from "../common/version";
import { STPApi, SubscriptionStatus } from "./openapi-stp";

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

Expand All @@ -148,7 +152,7 @@ export class NeynarV2APIClient {
block: BlockApi;
ban: BanApi;
subscribers: SubscribersApi;
stp: STPApi;
stp: StpApi;
};

/**
Expand Down Expand Up @@ -233,7 +237,7 @@ export class NeynarV2APIClient {
block: new BlockApi(config, undefined, axiosInstance),
ban: new BanApi(config, undefined, axiosInstance),
subscribers: new SubscribersApi(config, undefined, axiosInstance),
stp: new STPApi(config, undefined, axiosInstance),
stp: new StpApi(config, undefined, axiosInstance),
};
}

Expand Down Expand Up @@ -1092,6 +1096,27 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Fetches the token balance of a user given their FID.
*
* @param {number} fid - The FID of the user whose token balance is being fetched.
* @param {Array<Networks>} networks Comma separated list of networks to fetch balances for. Currently, only \&quot;base\&quot; is supported.
*
* @returns {Promise<BalanceResponse>} A promise that resolves to a `BalanceResponse` object
*
* @example
* // Example: Fetch the token balance of a user with FID 3
* client.fetchUserBalance(3).then(response => {
* console.log('User Balance:', response); // Outputs the token balance of the user
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/fetch-user-balance)
*/
public async fetchUserBalance(fid: number, networks: Networks[]): Promise<BalanceResponse> {
const response = await this.apis.user.fetchUserBalance({ fid , networks });
return response.data;
}

// ------------ Cast ------------

/**
Expand Down Expand Up @@ -3051,6 +3076,38 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Fetch a list of suggested users to follow. Used to help users discover new users to follow
*
* @param {number} fid - FID of the user whose following you want to fetch.
* @param {Object} [options] - Optional parameters for customizing the response
* @param {number} [options.limit] - Number of results to fetch (Default: 25, Maximum: 100)
* @param {number} [options.viewerFid] - Providing this will return a list of users that respects this user's mutes and blocks and includes `viewer_context`.
*
* @returns {Promise<UsersResponse>} A promise that resolves to a `UsersResponse` object
*
* @example
*
* // Example: Fetch follow suggestions for a user
* client.fetchFollowSuggestions(3, {limit: 5}).then(response => {
* console.log('Follow Suggestions:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/fetch-follow-suggestions)
*
*/
public async fetchFollowSuggestions(
fid: number,
options?: { limit?: number; viewerFid?: number }
): Promise<UsersResponse> {
const response = await this.apis.follows.fetchFollowSuggestions({
fid,
limit: options?.limit,
viewer_fid: options?.viewerFid,
});
return response.data;
}

// ------------ Storage ------------

/**
Expand Down Expand Up @@ -3287,6 +3344,30 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Fetches the frame meta tags from the URL
*
* @param {string} url - The URL from which to fetch the frame meta tags
*
* @returns {Promise<FetchFrameMetaTagsFromUrl200Response>} A promise that resolves to a `FetchFrameMetaTagsFromUrl200Response` object
*
* @example
* // Example: Fetch frame meta tags from a URL
* const url = 'https://frames.neynar.com/f/862277df/ff7be6a4';
* client.fetchFrameMetaTagsFromUrl(url).then(response => {
* console.log('Frame Meta Tags:', response);
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-frame-meta-tags-from-url)
*
*/
public async fetchFrameMetaTagsFromUrl(
url: string
): Promise<FetchFrameMetaTagsFromUrl200Response> {
const response = await this.apis.frame.fetchFrameMetaTagsFromUrl({ url });
return response.data;
}

/**
* Retrieves a list of frames created by the developer, identified through the provided API key.
* This method is essential for developers to review their frames submitted to the platform.
Expand Down
10 changes: 10 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apis/notifications-api.ts
apis/reaction-api.ts
apis/signer-api.ts
apis/storage-api.ts
apis/stp-api.ts
apis/subscribers-api.ts
apis/user-api.ts
apis/webhook-api.ts
Expand All @@ -25,8 +26,12 @@ configuration.ts
git_push.sh
index.ts
models/add-verification-req-body.ts
models/address-balance-verified-address.ts
models/address-balance.ts
models/authorization-url-response-type.ts
models/authorization-url-response.ts
models/balance-response-user-balance.ts
models/balance-response.ts
models/ban-list-response.ts
models/ban-record.ts
models/ban-req-body.ts
Expand Down Expand Up @@ -157,6 +162,7 @@ models/mute-list-response.ts
models/mute-record.ts
models/mute-req-body.ts
models/mute-response.ts
models/networks.ts
models/next-cursor.ts
models/neynar-frame-creation-req-body.ts
models/neynar-frame-page.ts
Expand Down Expand Up @@ -222,6 +228,7 @@ models/subscribed-to-response.ts
models/subscribed-to.ts
models/subscriber.ts
models/subscribers-response.ts
models/subscription-check-response.ts
models/subscription-metadata.ts
models/subscription-price.ts
models/subscription-provider.ts
Expand All @@ -233,6 +240,9 @@ models/subscription-token.ts
models/subscription.ts
models/subscriptions-response.ts
models/subscriptions.ts
models/token-balance-balance.ts
models/token-balance-token.ts
models/token-balance.ts
models/trending-channel-response.ts
models/update-user-req-body-location.ts
models/update-user-req-body.ts
Expand Down
1 change: 1 addition & 0 deletions src/neynar-api/v2/openapi-farcaster/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './apis/notifications-api';
export * from './apis/reaction-api';
export * from './apis/signer-api';
export * from './apis/storage-api';
export * from './apis/stp-api';
export * from './apis/subscribers-api';
export * from './apis/user-api';
export * from './apis/webhook-api';
Expand Down
Loading

0 comments on commit 71fc030

Please sign in to comment.