Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jun 2, 2025

Summary by CodeRabbit

  • New Features
    • Added a utility to retrieve and cache user, space, and platform context information for integration with Supabase.
    • Made this context information accessible globally within the extension.
  • Bug Fixes
    • Improved error handling and response codes for user and account lookup APIs.
  • API Enhancements
    • Introduced new API endpoints to fetch user and account information by email or account ID.

@linear
Copy link

linear bot commented Jun 2, 2025

ENG-371 getContext()

@vercel
Copy link

vercel bot commented Jun 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
discourse-graph ⬜️ Skipped (Inspect) Jun 9, 2025 6:16pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

A new utility for fetching and caching Supabase context was introduced and made globally accessible in the Roam extension. Supporting API endpoints for account and person retrieval were enhanced with new GET handlers. The context utility coordinates multiple API calls to retrieve or create platform, space, person, and account records.

Changes

File(s) Change Summary
apps/roam/src/index.ts Imported getSupabaseContext and exposed it on window.roamjs.extension.queryBuilder.
apps/roam/src/utils/supabaseContext.ts Added new module exporting SupabaseContext type and getSupabaseContext async function.
apps/website/app/api/supabase/account/route.ts Added GET handler for account retrieval; adjusted uniqueness constraint in account creation logic.
apps/website/app/api/supabase/person/route.ts Added GET handler for person retrieval by email.

Sequence Diagram(s)

sequenceDiagram
    participant RoamExtension as Roam Extension
    participant SupabaseContextUtil as getSupabaseContext
    participant API as Next.js API
    participant Supabase as Supabase DB

    RoamExtension->>SupabaseContextUtil: getSupabaseContext()
    SupabaseContextUtil->>API: POST /api/supabase/platform (with Roam URL)
    API->>Supabase: Query/Create Platform
    API-->>SupabaseContextUtil: platformId

    SupabaseContextUtil->>API: POST /api/supabase/space (with platformId)
    API->>Supabase: Query/Create Space
    API-->>SupabaseContextUtil: spaceId

    SupabaseContextUtil->>API: GET /api/supabase/account?platform_id&account_local_id
    API->>Supabase: Query Account
    API-->>SupabaseContextUtil: userId or null

    alt Account not found
        SupabaseContextUtil->>API: GET /api/supabase/person?email
        API->>Supabase: Query Person
        API-->>SupabaseContextUtil: personId or null

        SupabaseContextUtil->>API: POST /api/supabase/person (if needed)
        API->>Supabase: Create Person
        API-->>SupabaseContextUtil: personId

        SupabaseContextUtil->>API: POST /api/supabase/account (create)
        API->>Supabase: Create Account
        API-->>SupabaseContextUtil: userId
    end

    SupabaseContextUtil-->>RoamExtension: { platformId, spaceId, userId }
Loading

Poem

In the warren of code, a context appears,
Supabase secrets now hop to our ears.
With GETs and POSTs, accounts take flight,
Persons found by email, all through the night.
The rabbit rejoices—connections are made,
In Roam and beyond, our queries cascade!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@maparent
Copy link
Collaborator Author

maparent commented Jun 2, 2025

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (2)
apps/roam/src/utils/supabaseContext.ts (2)

36-38: Extract URL parsing logic for reusability.

The URL parsing logic to extract the space name could be extracted into a utility function.

Consider extracting:

+const extractSpaceNameFromUrl = (url: string): string => {
+  const urlParts = url.split("/");
+  return urlParts[urlParts.length - 1];
+};

      const url = getRoamUrl();
-     const urlParts = url.split("/");
-     const name = urlParts[urlParts.length - 1];
+     const name = extractSpaceNameFromUrl(url);

61-61: Track TODO comment for future enhancement.

The comment indicates planned support for multiple emails per person.

Would you like me to create an issue to track this enhancement for supporting multiple emails per person?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63e8bff and d953c18.

📒 Files selected for processing (4)
  • apps/roam/src/index.ts (2 hunks)
  • apps/roam/src/utils/supabaseContext.ts (1 hunks)
  • apps/website/app/api/supabase/account/route.ts (3 hunks)
  • apps/website/app/api/supabase/person/route.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/website/app/api/supabase/account/route.ts (3)
apps/website/app/api/supabase/person/route.ts (1)
  • GET (87-119)
apps/website/app/utils/supabase/apiUtils.ts (2)
  • handleRouteError (54-74)
  • createApiResponse (20-48)
apps/website/app/utils/supabase/server.ts (1)
  • createClient (5-47)
🔇 Additional comments (2)
apps/roam/src/index.ts (1)

25-25: LGTM!

The integration of getSupabaseContext follows the existing pattern and properly exposes the utility function through the global namespace.

Also applies to: 127-127

apps/website/app/api/supabase/account/route.ts (1)

2-2: Verify the uniqueness constraint change is intentional.

The import change and uniqueness constraint modification from ["agent_id", "platform_id"] to ["account_local_id", "platform_id"] appears to be a significant schema change. Please ensure this aligns with the database schema and won't cause conflicts with existing data.

Also applies to: 52-52

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff. Two main blockers

  • Roam doesn't expose the email to plugins anymore
  • What is the use case of adding getSupabseContext to the window object?

@maparent
Copy link
Collaborator Author

maparent commented Jun 9, 2025

@mdroidian I'm realizing that I still need approval despite having closed al conversations. What action is needed on your side?

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reviewed supabaseContext.ts

I'm assuming this is the only file required of the 23?

@maparent maparent force-pushed the ENG-371-getContext branch from b03999d to fd78491 Compare June 9, 2025 17:08
@mdroidian mdroidian changed the title create context for subsequent supabase operations ENG-371 create context for subsequent supabase operations Jun 9, 2025
@maparent maparent force-pushed the ENG-371-getContext branch from fd78491 to 628c2ab Compare June 9, 2025 17:24
@maparent maparent force-pushed the ENG-371-getContext branch from 628c2ab to 051f93b Compare June 9, 2025 17:59
@maparent maparent force-pushed the ENG-371-getContext branch from 051f93b to f21158c Compare June 9, 2025 18:16
@maparent maparent merged commit a8ab3ef into main Jun 9, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jun 9, 2025
@maparent maparent deleted the ENG-371-getContext branch June 9, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants