-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Elysia YouTube channel-info POC with typed client and OpenAPI #1626
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
Open
arpitgupta1214
wants to merge
1
commit into
test
Choose a base branch
from
codex/elysia-youtube-poc
base: test
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { NextRequest } from "next/server"; | ||
| import { elysiaApi } from "@/lib/api/elysia/app"; | ||
|
|
||
| async function handle(request: NextRequest): Promise<Response> { | ||
| return elysiaApi.handle(request); | ||
| } | ||
|
|
||
| export const GET = handle; | ||
| export const POST = handle; | ||
| export const PUT = handle; | ||
| export const PATCH = handle; | ||
| export const DELETE = handle; | ||
| export const HEAD = handle; | ||
| export const OPTIONS = handle; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
| export const fetchCache = "force-no-store"; | ||
| export const revalidate = 0; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { openapi } from "@elysiajs/openapi"; | ||
| import { authPlugin } from "@/lib/api/elysia/plugins/auth"; | ||
| import { elysiaRoutes } from "@/lib/api/elysia/routes"; | ||
|
|
||
| export const elysiaApi = new Elysia({ prefix: "/api" }) | ||
| .use( | ||
| openapi({ | ||
| path: "/openapi", | ||
| specPath: "/openapi/json", | ||
| provider: "scalar", | ||
| documentation: { | ||
| info: { | ||
| title: "Recoupable Chat API (Elysia POC)", | ||
| version: "0.1.0", | ||
| }, | ||
| components: { | ||
| securitySchemes: { | ||
| apiKeyAuth: { | ||
| type: "apiKey", | ||
| in: "header", | ||
| name: "x-api-key", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ) | ||
| .use(authPlugin) | ||
| .use(elysiaRoutes); | ||
|
|
||
| export type ElysiaApi = typeof elysiaApi; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { treaty } from "@elysiajs/eden"; | ||
| import type { ElysiaApi } from "@/lib/api/elysia/app"; | ||
|
|
||
| const client = treaty<ElysiaApi>("", { | ||
| fetch: { | ||
| credentials: "include", | ||
| }, | ||
| }); | ||
|
|
||
| export const api = client.api; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { getAccountIdFromPrivyToken } from "@/lib/auth/getAccountIdFromPrivyToken"; | ||
| import { getAccountIdFromApiKey } from "@/lib/supabase/account_api_keys/getAccountIdFromApiKey"; | ||
|
|
||
| export const authPlugin = new Elysia({ name: "auth-plugin" }) | ||
| .derive({as: "global"}, async ({ cookie, request }) => { | ||
| const apiKey = request.headers.get("x-api-key"); | ||
| const privyToken = cookie["privy-token"].value as string; | ||
|
|
||
| let user: { userId: string; identifier: string } | null = null; | ||
|
|
||
| if (apiKey) { | ||
| try { | ||
| user = { | ||
| userId: await getAccountIdFromApiKey(apiKey), | ||
| identifier: apiKey, | ||
| }; | ||
| } catch (error) { | ||
| console.error("Elysia auth apiKey validation failed:", error); | ||
| } | ||
| } else if (privyToken) { | ||
| try { | ||
| const accountId = await getAccountIdFromPrivyToken(privyToken); | ||
| if (accountId) { | ||
| user = { | ||
| userId: accountId, | ||
| identifier: privyToken, | ||
| }; | ||
| } | ||
| } catch (error) { | ||
| console.error("Elysia auth privyToken validation failed:", error); | ||
| } | ||
| } | ||
|
|
||
| return { user }; | ||
| }) | ||
| .macro({ | ||
| auth: { | ||
| beforeHandle({ user, status }) { | ||
| if (!user) { | ||
| return status(401, "Authentication required"); | ||
| } | ||
| }, | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Elysia, t } from "elysia"; | ||
| import { addAgentTemplateFavorite } from "@/lib/supabase/agent_templates/addAgentTemplateFavorite"; | ||
| import { removeAgentTemplateFavorite } from "@/lib/supabase/agent_templates/removeAgentTemplateFavorite"; | ||
|
|
||
| const errorResponseSchema = t.String(); | ||
|
|
||
| export const agentTemplateFavoritesRoute = new Elysia().post( | ||
| "/favorites", | ||
| async ({body, status, user}) => { | ||
| try { | ||
| if (body.isFavourite) { | ||
| await addAgentTemplateFavorite(body.templateId, user.userId); | ||
| } else { | ||
| await removeAgentTemplateFavorite(body.templateId, user.userId); | ||
| } | ||
|
|
||
| return { success: true as const }; | ||
| } catch (error) { | ||
| console.error("Error toggling favourite:", error); | ||
| return status(500, "Failed to toggle favourite"); | ||
| } | ||
| }, | ||
| { | ||
| auth: true, | ||
| body: t.Object({ | ||
| templateId: t.String(), | ||
| isFavourite: t.Boolean(), | ||
| }), | ||
| response: { | ||
| 200: t.Object({ | ||
| success: t.Literal(true), | ||
| }), | ||
| 401: errorResponseSchema, | ||
| 500: errorResponseSchema, | ||
| }, | ||
| detail: { | ||
| summary: "Toggle agent template favorite", | ||
| description: | ||
| "Adds or removes a template favorite for the authenticated user.", | ||
| tags: ["agent-templates"], | ||
| security: [{ apiKeyAuth: [] }], | ||
| }, | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { agentTemplateFavoritesRoute } from "@/lib/api/elysia/routes/agentTemplates/favorites"; | ||
|
|
||
| export const agentTemplateRoutes = new Elysia({ prefix: "/agent-templates" }) | ||
| .use(agentTemplateFavoritesRoute); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { agentTemplateRoutes } from "@/lib/api/elysia/routes/agentTemplates"; | ||
| import { youtubeRoutes } from "@/lib/api/elysia/routes/youtube"; | ||
|
|
||
| export const elysiaRoutes = new Elysia().use(youtubeRoutes).use(agentTemplateRoutes); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do not store raw API keys/tokens in request context.
identifiercurrently contains the raw API key or Privy token. Keep only non-secret identity fields (e.g.,userId,authMethod) to reduce credential exposure risk.🔧 Suggested fix
As per coding guidelines, "Implement built-in security practices for authentication and data handling."
Also applies to: 25-28
🤖 Prompt for AI Agents