neynarxyz / nodejs-sdk

Typescript SDK for Neynar APIs
https://neynar.com
MIT License
50 stars 10 forks source link

fix: add cursor to cast and channel search #164

Closed valerierose closed 1 month ago

valerierose commented 1 month ago

Overview

This PR fixes the type error in searchCasts by adding a new type called CastsSearchResponse which includes the cursor.

This PR also adds the limit and cursor to the searchChannels method.

Tests:

Search Casts

# index.js
const result = await client.searchCasts("demure", {limit: 3});
console.log(JSON.stringify(result));
node index.js  | jq '{next: .result.next, casts: [.result.casts[] | {text: .text, timestamp: .timestamp, fid: .author.fid, username: .author.username, hash: .hash}]}

Returns:

{
  "next": {
    "cursor": "eyJwYWdlIjoyfQ%3D%3D"
  },
  "casts": [
    {
      "text": "So I guess we’re not hearing “very demure, very mindful” on the next episode of ok banger",
      "timestamp": "2024-08-25T04:49:30.000Z",
      "fid": 723495,
      "username": "5681352568135276",
      "hash": "0x60070abdb8aa1c4da684fef255510997c78bc523"
    },
    {
      "text": "Hey  see how  addresses the nation?\nVery demure. Very cutesy. Very sophisticated.\nShe’s not like you, she doesn’t need to spew lies & call people nasty names.\nShe’s poised, elegant.\nVery much NEXT POTUS of USA #DNCConvention2024 #DNC2024 #KamalaHarris",
      "timestamp": "2024-08-25T04:57:02.000Z",
      "fid": 766716,
      "username": "ythvd",
      "hash": "0x8990a887df8edecaa0a51816e0204a71a34d9dff"
    },
    {
      "text": "Base should pay for Jools Lebron to fight for her trademark\n\nTLDR Jools created “Very Demure, Very Mindful” \n\nShe is a light of pure joy, and some dickhead went and ripped the trademark out from under her\n\nCould be massive PR and underscore the Onchain value prop\n\n\n\nhttps://www.tiktok.com/t/ZP81nT8xU/",
      "timestamp": "2024-08-25T05:09:48.000Z",
      "fid": 1626,
      "username": "mcbain",
      "hash": "0xef7723a7a82d773d1c30dc1b149ed20ae941bf07"
    }
  ]
}

Search Channels

# index.js
const result = await client.searchChannels("memes", {limit: 3});
console.log(JSON.stringify(result));
node index.js | jq '{next: .next, channels: [.channels[] | {id: .id, description: .description, follower_count: .follower_count}]}'
{
  "next": {
    "cursor": "eyJwYWdlIjoyfQ%3D%3D"
  },
  "channels": [
    {
      "id": "memes",
      "description": "Funny memes, wholesome memes, and everything in-between. subscribe to earn (~$1/mo) https://hypersub.withfabric.xyz/collection/memes-1x0fzjq6ytfy8",
      "follower_count": 359702
    },
    {
      "id": "memesby6529",
      "description": "For those passionate about the Memes by 6529 and advancing decentralization, community, and self-sovereignty within crypto-economic and crypto-social layers.\n\nhttps://seize.io/",
      "follower_count": 1092
    },
    {
      "id": "animememes",
      "description": "Created For Cool people , feel free to cast Meme and Anything about Anime and funny things here ! 👀",
      "follower_count": 153
    }
  ]
}

Calling again with the cursor returns:

{
  "next": {
    "cursor": "eyJwYWdlIjozfQ%3D%3D"
  },
  "channels": [
    {
      "id": "spk",
      "description": "spk | customer support with crypto memes",
      "follower_count": 17
    },
    {
      "id": "memes-onchain",
      "description": "✏️💸mintable memes ONLY | 💸OC = onchain | ✏️OC = Original Content (preferred) | ✏️CC = creator credit (reply comment posts & !CC the creator if ya know 'em) | 🛠building+stimulating meme-2-earn economy | ✏️💸 mintboard: [uplink.wtf/memes/mintboard]",
      "follower_count": 608
    },
    {
      "id": "memesoutside",
      "description": "Dedicated to taking minted art, outside. Fun, safe and free. Join us!",
      "follower_count": 70
    }
  ]
}