-
Notifications
You must be signed in to change notification settings - Fork 0
Restore app shell and add ltx-2 support #50
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,63 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { savePollinationsApiKey } from "./actions"; | ||
| import { fetchMutation } from "convex/nextjs"; | ||
| import { getConvexClerkToken } from "@/app/_server/convex/client"; | ||
| import { api } from "@/convex/_generated/api"; | ||
|
|
||
| vi.mock("convex/nextjs", () => ({ | ||
| fetchMutation: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/app/_server/convex/client", () => ({ | ||
| getConvexClerkToken: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/convex/_generated/api", () => ({ | ||
| api: { | ||
| users: { | ||
| setPollinationsApiKey: "users:setPollinationsApiKey", | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| describe("savePollinationsApiKey", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.mocked(getConvexClerkToken).mockResolvedValue("convex-token"); | ||
| vi.mocked(fetchMutation).mockResolvedValue({ success: true }); | ||
| }); | ||
|
|
||
| it("stores a valid API key with the Clerk Convex token", async () => { | ||
| const result = await savePollinationsApiKey("sk_test1234"); | ||
|
|
||
| expect(result).toEqual({ status: "success" }); | ||
| expect(fetchMutation).toHaveBeenCalledWith( | ||
| api.users.setPollinationsApiKey, | ||
| { apiKey: "sk_test1234" }, | ||
| { token: "convex-token" }, | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects a missing API key before calling Convex", async () => { | ||
| const result = await savePollinationsApiKey(null); | ||
|
|
||
| expect(result).toEqual({ status: "error_missing_key" }); | ||
| expect(fetchMutation).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects an invalid API key before calling Convex", async () => { | ||
| const result = await savePollinationsApiKey("invalid"); | ||
|
|
||
| expect(result).toEqual({ status: "error_invalid_key" }); | ||
| expect(fetchMutation).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("returns save failure when no auth token is available", async () => { | ||
| vi.mocked(getConvexClerkToken).mockResolvedValue(undefined); | ||
|
|
||
| const result = await savePollinationsApiKey("sk_test1234"); | ||
|
|
||
| expect(result).toEqual({ status: "error_save_failed" }); | ||
| expect(fetchMutation).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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,51 @@ | ||
| "use server"; | ||
|
|
||
| import { fetchMutation } from "convex/nextjs"; | ||
| import { api } from "@/convex/_generated/api"; | ||
| import { getConvexClerkToken } from "@/app/_server/convex/client"; | ||
| import { isValidApiKeyFormat } from "@/lib/pollen-auth/storage"; | ||
|
|
||
| export type SavePollinationsApiKeyResult = { | ||
| status: | ||
| | "idle" | ||
| | "success" | ||
| | "error_missing_key" | ||
| | "error_invalid_key" | ||
| | "error_save_failed"; | ||
| }; | ||
|
|
||
| /** | ||
| * Stores the Pollinations API key from the OAuth callback via an authenticated | ||
| * server boundary. The browser still has to read the URL hash because fragments | ||
| * are not sent to the server. | ||
| */ | ||
| export async function savePollinationsApiKey( | ||
| apiKey: string | null, | ||
| ): Promise<SavePollinationsApiKeyResult> { | ||
| if (!apiKey) { | ||
| return { status: "error_missing_key" }; | ||
| } | ||
|
|
||
| if (!isValidApiKeyFormat(apiKey)) { | ||
| return { status: "error_invalid_key" }; | ||
| } | ||
|
|
||
| try { | ||
| const token = await getConvexClerkToken(); | ||
|
|
||
| if (!token) { | ||
| return { status: "error_save_failed" }; | ||
| } | ||
|
|
||
| await fetchMutation( | ||
| api.users.setPollinationsApiKey, | ||
| { apiKey }, | ||
| { token }, | ||
| ); | ||
|
|
||
| return { status: "success" }; | ||
| } catch (error) { | ||
| console.error("[PollinationsCallback] Error saving API key:", error); | ||
| return { status: "error_save_failed" }; | ||
| } | ||
| } | ||
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
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.
Avoid logging the raw exception in the API-key save path.
This handler processes a secret, and dumping the full thrown object to server logs can expose the key or request metadata from downstream failures. Log a sanitized identifier instead.
Suggested fix
} catch (error) { - console.error("[PollinationsCallback] Error saving API key:", error); + console.error("[PollinationsCallback] Error saving API key", { + errorName: error instanceof Error ? error.name : "unknown", + }); return { status: "error_save_failed" }; }📝 Committable suggestion
🤖 Prompt for AI Agents