1- import { type FrameActionPayload , getFrame } from "frames.js" ;
1+ import { type FrameActionPayload } from "frames.js" ;
22import { type NextRequest } from "next/server" ;
33import { getAction } from "../actions/getAction" ;
44import { persistMockResponsesForDebugHubRequests } from "../utils/mock-hub-utils" ;
55import type { SupportedParsingSpecification } from "frames.js" ;
6+ import { parseFramesWithReports } from "frames.js/parseFramesWithReports" ;
67import { z } from "zod" ;
78import type { ParseActionResult } from "../actions/types" ;
8- import type { ParseResult } from "frames.js/frame-parsers" ;
9+ import type { ParseFramesWithReportsResult } from "frames.js/frame-parsers" ;
10+ import type { JsonObject } from "frames.js/types" ;
911
1012const castActionMessageParser = z . object ( {
1113 type : z . literal ( "message" ) ,
@@ -43,7 +45,7 @@ export type CastActionDefinitionResponse = ParseActionResult & {
4345 url : string ;
4446} ;
4547
46- export type FrameDefinitionResponse = ParseResult & {
48+ export type FrameDefinitionResponse = ParseFramesWithReportsResult & {
4749 type : "frame" ;
4850} ;
4951
@@ -91,17 +93,16 @@ export async function GET(request: NextRequest): Promise<Response> {
9193 } satisfies CastActionDefinitionResponse ) ;
9294 }
9395
94- const htmlString = await urlRes . text ( ) ;
96+ const html = await urlRes . text ( ) ;
9597
96- const result = getFrame ( {
97- htmlString,
98- url,
99- specification,
98+ const parseResult = parseFramesWithReports ( {
99+ html,
100+ fallbackPostUrl : url ,
100101 fromRequestMethod : "GET" ,
101102 } ) ;
102103
103104 return Response . json ( {
104- ...result ,
105+ ...parseResult ,
105106 type : "frame" ,
106107 } satisfies FrameDefinitionResponse ) ;
107108 } catch ( err ) {
@@ -138,7 +139,7 @@ export async function POST(req: NextRequest): Promise<Response> {
138139 }
139140
140141 if ( ! postUrl ) {
141- return Response . error ( ) ;
142+ return Response . json ( { message : "Invalid post URL" } , { status : 400 } ) ;
142143 }
143144
144145 try {
@@ -197,7 +198,7 @@ export async function POST(req: NextRequest): Promise<Response> {
197198 }
198199
199200 if ( isTransactionRequest ) {
200- const transaction = ( await r . json ( ) ) as JSON ;
201+ const transaction = ( await r . json ( ) ) as JsonObject ;
201202 return Response . json ( transaction ) ;
202203 }
203204
@@ -221,19 +222,26 @@ export async function POST(req: NextRequest): Promise<Response> {
221222 } ) ;
222223 }
223224
224- const htmlString = await r . text ( ) ;
225+ const html = await r . text ( ) ;
225226
226- const result = getFrame ( {
227- htmlString,
228- url : body . untrustedData . url ,
229- specification,
227+ const parseResult = parseFramesWithReports ( {
228+ html,
229+ fallbackPostUrl : body . untrustedData . url ,
230230 fromRequestMethod : "POST" ,
231231 } ) ;
232232
233- return Response . json ( result ) ;
233+ return Response . json ( {
234+ type : "frame" ,
235+ ...parseResult ,
236+ } satisfies FrameDefinitionResponse ) ;
234237 } catch ( err ) {
235238 // eslint-disable-next-line no-console -- provide feedback to the user
236239 console . error ( err ) ;
237- return Response . error ( ) ;
240+ return Response . json (
241+ {
242+ message : String ( err ) ,
243+ } ,
244+ { status : 500 }
245+ ) ;
238246 }
239247}
0 commit comments