Skip to content
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

docs: Add Orama Search #202

Merged
merged 7 commits into from
Feb 12, 2025
Merged

docs: Add Orama Search #202

merged 7 commits into from
Feb 12, 2025

Conversation

Fryuni
Copy link
Owner

@Fryuni Fryuni commented Feb 12, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced search experience featuring real-time suggestions, adaptive theming, and secure integration with external cloud services.
    • Improved environment configurations to ensure stable and reliable search functionality.
  • Chores

    • Removed outdated security tokens.
    • Optimized build routines and updated dependencies for smoother performance.

@Fryuni Fryuni self-assigned this Feb 12, 2025
Copy link

vercel bot commented Feb 12, 2025

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

Name Status Preview Updated (UTC)
inox-tools ✅ Ready (Inspect) Visit Preview Feb 12, 2025 5:32pm

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request removes a sensitive cryptographic key from the development environment file and introduces new environment variables for the Orama cloud service. It also updates the Astro configuration to validate these new variables and integrates a new search component that leverages Orama’s web components. Additionally, the build script and TypeScript configuration are modified, and the Turbo build system is updated to pass through the specified environment variables.

Changes

File(s) Change Summary
docs/.env.development Removed a cryptographic token and added three new environment variables: ORAMA_CLOUD_ENDPOINT, ORAMA_CLOUD_API_KEY, and ORAMA_CLOUD_PROXY_KEY.
docs/astro.config.ts Added an env configuration with secret validation and a schema for ORAMA_CLOUD_ENDPOINT and ORAMA_CLOUD_API_KEY; updated integrations to include a new Search component and enabled pagefind.
docs/package.json Modified the build script to remove the .astro directory and added a new dependency: @orama/wc-components version ^0.4.1.
docs/src/components/Search.astro Introduced a new search component using Orama web components; implemented a MutationObserver to update the search theme dynamically; defined custom elements, configured the search box, and applied responsive styling.
docs/tsconfig.json Added new compiler options: set jsx to "react-jsx" and introduced jsxImportSource with the value "react".
docs/turbo.json Updated the build task by adding a passThroughEnv property to pass several environment variables during the build process.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchComponent
    participant MutationObserver
    User->>SearchComponent: Load search component
    SearchComponent->>SearchComponent: Initialize component and call updateSearchTheme
    SearchComponent->>MutationObserver: Start observing document attribute changes
    Note over MutationObserver: Wait for theme attribute changes
    MutationObserver->>SearchComponent: Notify updateSearchTheme on change
    SearchComponent->>SearchComponent: Update theme accordingly
Loading

Possibly related PRs

Suggested labels

pkg/content-utils, pkg/astro-tests, pkg/custom-routing

Suggested reviewers

  • BryceRussell

Poem

I'm a hopping little bunny,
Leaping through changes light and sunny,
Keys removed and secrets set,
New search paths now firmly met,
A code hop for progress—oh so funny!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d127873 and 25041c2.

📒 Files selected for processing (1)
  • docs/src/components/Search.astro (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/src/components/Search.astro
⏰ Context from checks skipped due to timeout of 120000ms (2)
  • GitHub Check: E2E test
  • GitHub Check: Deploy "custom-routing" to Cloudflare

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

@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: 0

🧹 Nitpick comments (6)
docs/src/utils/search.ts (3)

31-31: Avoid using any type for PostHog.

The any type for posthog reduces type safety. Consider using a more specific type from PostHog's type definitions.

-    posthog: any;
+    posthog: import('posthog-js').PostHog;

39-40: Remove TODO comments and console.log statements.

These debug logs should be removed before merging to production.

-      // TODO: remove this console.log
-      console.log('Identifying user with Cookie ID:', userId);
+      client.identify(userId);
-      // TODO: remove this console.log
-      console.log('Identifying session with PostHog:', window.posthog.get_distinct_id());
+      client.alias(window.posthog.get_distinct_id());

Also applies to: 43-44


48-48: Enhance error logging.

The current error logging could be more informative. Consider using console.error and including the error stack trace.

-    console.log(`Error setting identity: ${error}`);
+    console.error('Error setting identity:', error instanceof Error ? error : new Error(String(error)));
docs/src/components/Search.astro (3)

8-8: Remove debug console.log.

Debug logging should be removed before production deployment.

-console.log('Redering custom search');

Note: There's also a typo in 'Redering' (should be 'Rendering').


50-51: Avoid type assertion with any.

Using as any bypasses TypeScript's type checking. Consider using a proper type for the color scheme.

-    if (button) button.colorScheme = theme as any;
-    if (box) box.colorScheme = theme as any;
+    type ColorScheme = 'light' | 'dark';
+    if (button) button.colorScheme = theme as ColorScheme;
+    if (box) box.colorScheme = theme as ColorScheme;

36-36: Update placeholder text.

The chat placeholder text refers to "Inox Tools" but the chat functionality is disabled (disableChat: true). Consider removing this placeholder since chat is disabled.

-    chatPlaceholder: 'What do you dream of doing with Inox Tools?',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1674a8c and 6f875aa.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • docs/.env.development (1 hunks)
  • docs/astro.config.ts (4 hunks)
  • docs/package.json (1 hunks)
  • docs/src/components/Search.astro (1 hunks)
  • docs/src/utils/search.ts (1 hunks)
  • docs/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/package.json
🔇 Additional comments (3)
docs/astro.config.ts (1)

153-162: Review security implications of exposing API key to client.

The Orama Cloud API key is marked as access: 'public' and exposed to the client. This could pose a security risk if the API key has broad permissions.

Please verify:

  1. That this API key has limited scope and is specifically intended for client-side usage
  2. That rate limiting is properly configured on the Orama Cloud side
❌ Verification inconclusive

🌐 Web query:

What are the security best practices for using Orama Cloud API keys in client-side applications?

💡 Result:

When using Orama Cloud API keys in client-side applications, implementing robust security measures is critical to prevent unauthorized access and data breaches. Here are the key best practices:

1. Avoid Direct Client-Side Exposure

  • Never embed API keys in frontend code or expose them in URLs where they can be intercepted[1][3][6]. Instead:
    • Use Orama's Secure Proxy to safely handle third-party API calls (like OpenAI embeddings) without exposing credentials[10]
    • Implement server-side authentication layers that add API keys to requests before forwarding them[1][3]

2. Implement Secure Transmission

  • Enforce HTTPS for all API communications to encrypt data in transit[1][7]
  • Use x-goog-api-key headers instead of query parameters when integrating with Google APIs[3]

3. Key Management Best Practices

  • Rotate API keys regularly (every 90 days or sooner) using automated tools[1][4]
  • Delete unused keys through Orama Cloud's developer tools dashboard[2][5]
  • Store production keys securely using encrypted environment variables[4][7]

4. Access Control & Monitoring

  • Apply least-privilege permissions in Orama Cloud:
    • Restrict indexes each key can access[2]
    • Limit operations (read-only vs write)[1][4]
  • Enable real-time usage monitoring with:
    • Rate limiting (requests/minute)[1]
    • Anomaly detection alerts[1][7]

5. Client-Side Specific Protections

// Proper browser implementation with user identification
import { OramaClient } from "@oramacloud/client";

const client = new OramaClient({
  endpoint: "<CLOUD_ENDPOINT>",
  api_key: "<PUBLIC_API_KEY>" // Use PUBLIC key type from dashboard
});

// Identify users securely
client.identify("USER_ID"); 
client.reset(); // On logout[8]
  • Use public API key type instead of private keys for frontend operations[8]
  • Implement user-level rate limiting through Orama's Secure Proxy configuration[10]

6. Architectural Security

  • Combine with multi-factor authentication for admin access[7]
  • Maintain audit logs of all API key activities[1][3]
  • Use automated vulnerability scanning for dependencies like @oramacloud/client[8]

By following these practices while leveraging Orama Cloud's built-in security features like secure proxies and granular permission controls, developers can maintain strong security without compromising application functionality. Regular audits and team training on credential handling further reduce human error risks[1][5].

Citations:


Security Verification: Public API Key Exposure and Rate Limiting

  • The configuration in docs/astro.config.ts designates the Orama Cloud API key with access: 'public' and context: 'client', which indicates it’s intended for client-side usage.
  • According to Orama Cloud best practices, a public API key should be limited to non-sensitive, client-facing operations. It’s important to confirm on your Orama Cloud dashboard that the key’s permissions are indeed restricted (e.g., read-only or limited to specific indexes).
  • Additionally, ensure that rate limiting (or any equivalent abuse-mitigation settings) is properly configured on the Orama Cloud side—typically via secure proxy settings or dedicated dashboard configurations—to protect against potential misuse.

Please verify on the Orama Cloud settings that these conditions are met.

docs/.env.development (1)

3-3: LGTM! Good security practice.

Removing the cryptographic key from the development environment file is a good security practice.

docs/tsconfig.json (1)

9-10: LGTM! Proper configuration for React JSX support.

The added compiler options correctly enable the modern JSX transform with React as the source, which is necessary for using React-based components like Orama Search.

Copy link

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f875aa and bdf446e.

📒 Files selected for processing (2)
  • docs/.env.development (1 hunks)
  • docs/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/package.json
⏰ Context from checks skipped due to timeout of 120000ms (1)
  • GitHub Check: E2E test

@Fryuni Fryuni enabled auto-merge (squash) February 12, 2025 17:33
@Fryuni Fryuni added the documentation Improvements or additions to documentation label Feb 12, 2025
@Fryuni Fryuni merged commit fc61047 into main Feb 12, 2025
20 checks passed
@Fryuni Fryuni deleted the docs/oramasearch branch February 12, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant