Skip to content

Commit

Permalink
feat: createNeynar
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed May 16, 2024
1 parent b36a9e8 commit a9123a0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-jokes-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Added `createNeynar` for composing hub and middleware.
11 changes: 4 additions & 7 deletions playground/src/neynar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Button, Frog } from 'frog'
import { neynar } from 'frog/middlewares'
import { createNeynar } from 'frog/middlewares'

export const neynarMiddleware = neynar({
apiKey: 'NEYNAR_FROG_FM',
features: ['interactor', 'cast'],
})
const neynar = createNeynar({ apiKey: 'NEYNAR_FROG_FM' })

export const app = new Frog()
export const app = new Frog({ hub: neynar.hub })
.frame('/', (c) => {
return c.res({
action: '/guess',
Expand All @@ -28,7 +25,7 @@ export const app = new Frog()
intents: [<Button>Go on</Button>],
})
})
.frame('/guess', neynarMiddleware, (c) => {
.frame('/guess', neynar.middleware, (c) => {
const { displayName, followerCount } = c.var.interactor || {}
console.log('interactor: ', c.var.interactor)
console.log('cast: ', c.var.cast)
Expand Down
2 changes: 1 addition & 1 deletion src/hubs/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { neynar } from './neynar.js'
export { neynar, type NeynarHubParameters } from './neynar.js'
export { pinata } from './pinata.js'
2 changes: 2 additions & 0 deletions src/middlewares/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export {
createNeynar,
neynar,
type CreateNeynarParameters,
type NeynarVariables,
type NeynarCast,
type NeynarMiddlewareParameters,
Expand Down
26 changes: 26 additions & 0 deletions src/middlewares/neynar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { MiddlewareHandler } from 'hono'
import { hexToBytes } from 'viem'

import { Message } from '../protobufs/generated/message_pb.js'
import type { Pretty } from '../types/utils.js'
import { messageToFrameData } from '../utils/verifyFrame.js'
import {
neynar as neynarHub,
type NeynarHubParameters,
} from '../hubs/neynar.js'

export type NeynarVariables = {
/**
Expand Down Expand Up @@ -184,3 +189,24 @@ export type NeynarUser = {
followedBy: boolean
}
}

///////////////////////////////////////////////////////////////////////////
// Higher-Level API

export type CreateNeynarParameters = {
apiKey: string
hub?: NeynarHubParameters | undefined
middleware?: NeynarMiddlewareParameters | undefined
}

export function createNeynar(parameters: CreateNeynarParameters) {
const {
apiKey,
hub = { apiKey },
middleware = { apiKey, features: ['cast', 'interactor'] },
} = parameters
return {
hub: neynarHub(hub),
middleware: neynar(middleware),
}
}

0 comments on commit a9123a0

Please sign in to comment.