-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: debugging #148
wip: debugging #148
Changes from 4 commits
fd723fa
7733041
43416d1
765f762
960af72
a660a7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NextRequest } from 'next/server'; | ||
import { getDebugFrameRequest } from '@coinbase/onchainkit'; | ||
|
||
export async function POST(req: NextRequest) { | ||
const data = await req.json(); | ||
const { frameData, options } = data; | ||
const postUrl = frameData.url; | ||
const debugPayload = getDebugFrameRequest({ untrustedData: frameData }, options); | ||
|
||
const res = await fetch(postUrl, { | ||
method: 'POST', | ||
body: JSON.stringify(debugPayload), | ||
}); | ||
|
||
const text = await res.text(); | ||
|
||
return Response.json({ text }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { FrameRequest, DebugFrameRequestOptions } from '@coinbase/onchainkit'; | ||
|
||
type FrameData = FrameRequest['untrustedData']; | ||
|
||
export async function postFrame(frameData: FrameData, options?: DebugFrameRequestOptions) { | ||
const res = await fetch('/api/postFrame', { | ||
body: JSON.stringify({ | ||
frameData, | ||
options, | ||
}), | ||
method: 'POST', | ||
headers: { | ||
contentType: 'application/json', | ||
}, | ||
}); | ||
const json = await res.json(); | ||
console.log(json.text); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { FrameRequest, FrameValidationData } from './types'; | ||
|
||
export type DebugFrameRequestOptions = { | ||
following?: boolean; // Indicates if the viewer clicking the frame follows the cast author | ||
interactor?: { | ||
fid?: number; // Viewer Farcaster ID | ||
custody_address?: string; // Viewer custody address | ||
verified_accounts?: string[]; // Viewer account addresses | ||
}; | ||
liked?: boolean; // Indicates if the viewer clicking the frame liked the cast | ||
recasted?: boolean; // Indicates if the viewer clicking the frame recasted the cast | ||
}; | ||
|
||
type DebugFrameRequest = FrameRequest & { onchainkitDebug: Required<FrameValidationData> }; | ||
|
||
/** | ||
* Modify a standard frame request to include simulated values (e.g., indicate the viewer | ||
* follows the cast author) for development/debugging purposes. | ||
* @param request A standard frame request. | ||
* @param options An object containing values we will pretend are real for the purposes of debugging. | ||
* @returns | ||
*/ | ||
function getDebugFrameRequest( | ||
cnasc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
request: FrameRequest, | ||
options?: DebugFrameRequestOptions, | ||
): DebugFrameRequest { | ||
return { | ||
...request, | ||
onchainkitDebug: { | ||
button: request.untrustedData.buttonIndex, | ||
input: request.untrustedData.inputText, | ||
following: !!options?.following, | ||
interactor: { | ||
fid: options?.interactor?.fid || 0, | ||
custody_address: options?.interactor?.custody_address || '0xnotarealaddress', | ||
verified_accounts: options?.interactor?.verified_accounts || [], | ||
}, | ||
liked: !!options?.liked, | ||
recasted: !!options?.recasted, | ||
valid: true, | ||
raw: { | ||
valid: true, | ||
// TODO: unjank | ||
action: {} as any, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export { getDebugFrameRequest, type DebugFrameRequest }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ import { | |
NEYNAR_DEFAULT_API_KEY, | ||
neynarFrameValidation, | ||
} from '../utils/neynar/frame/neynarFrameFunctions'; | ||
import { DebugFrameRequest } from './getDebugFrameRequest'; | ||
|
||
type FrameMessageOptions = | ||
| { | ||
neynarApiKey?: string; | ||
castReactionContext?: boolean; | ||
followContext?: boolean; | ||
allowDebug?: boolean; | ||
} | ||
| undefined; | ||
|
||
|
@@ -20,9 +22,19 @@ type FrameMessageOptions = | |
* @param body The JSON received by server on frame callback | ||
*/ | ||
async function getFrameMessage( | ||
body: FrameRequest, | ||
body: FrameRequest | DebugFrameRequest, | ||
messageOptions?: FrameMessageOptions, | ||
): Promise<FrameValidationResponse> { | ||
// Skip validation only when allowed and when receiving a debug request | ||
if (messageOptions?.allowDebug) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is a boolean, we should either use so maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, not every request is necessarily a mock request. I think it's most clear as is: if set, it will allow mock requests to pass through, otherwise it will reject them. |
||
if ((body as DebugFrameRequest).onchainkitDebug) { | ||
return { | ||
isValid: true, | ||
message: (body as DebugFrameRequest).onchainkitDebug, | ||
}; | ||
} | ||
} | ||
|
||
// Validate the message | ||
const response = await neynarFrameValidation( | ||
body?.trustedData?.messageBytes, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inteeeeerestinggggggggg
What the heck which magic is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://yarnpkg.com/protocol/portal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we finalize probably want to specify the exact version, but this is great for dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Portal Protocol 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you're thinking with portals