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

feat: add next-runtime-env #869

Merged
merged 10 commits into from
Feb 15, 2024
Merged

feat: add next-runtime-env #869

merged 10 commits into from
Feb 15, 2024

Conversation

catalinpit
Copy link
Contributor

@catalinpit catalinpit commented Jan 25, 2024

This PR adds the package next-runtime-env to populate the public environment variables at runtime.

Copy link

vercel bot commented Jan 25, 2024

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

Name Status Preview Comments Updated (UTC)
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2024 2:05am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2024 2:05am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Feb 12, 2024 2:05am
prd-marketing ⬜️ Ignored (Inspect) Feb 12, 2024 2:05am

Copy link
Contributor

coderabbitai bot commented Jan 25, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: coderabbit. Please add one of these labels to enable auto reviews.

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.

Walkthrough

The overarching change across the application involves the adoption of the next-runtime-env package to manage environment variables more efficiently. This shift enhances the reliability and flexibility in accessing these variables, notably NEXT_PUBLIC_WEBAPP_URL and NEXT_PUBLIC_DISABLE_SIGNUP, across various components and modules. The adjustments include typo corrections, import modifications, and the systematic replacement of direct process.env accesses with the next-runtime-env approach, streamlining the management of environment variables within the application.

Changes

Files Change Summary
.../edit-document.tsx Corrected a typo in the declaration of the documentFlow variable.
.../create-billing-portal.action.ts, .../route.tsx, .../page.tsx, .../signin/page.tsx, .../signup/page.tsx, layout.tsx, .../avatar-with-recipient.tsx, .../get-asset-buffer.ts, .../template-document-self-signed.tsx, .../template-reset-password.tsx, .../delete-document.ts, .../resend-document.tsx, .../send-completed-email.ts, .../send-document.tsx, .../send-pending-email.ts, .../get-base-url.ts, .../put-file.ts, .../server-actions.ts, .../document-share-button.tsx Introduced next-runtime-env for environment variable management, replacing direct process.env access with env function calls.
.../constants/app.ts, .../constants/feature-flags.ts, .../next-auth/auth-options.ts, .../server-only/auth/send-confirmation-email.ts, .../server-only/auth/send-forgot-password.ts, .../server-only/auth/send-reset-password.ts, .../server-only/feature-flags/all.ts, .../server-only/feature-flags/get.ts, .../auth-router/router.ts, .../singleplayer-router/router.ts Modified to use next-runtime-env for retrieving environment variables, enhancing the initialization and usage of variables like NEXT_PUBLIC_WEBAPP_URL, NEXT_PUBLIC_DISABLE_SIGNUP, NEXT_PUBLIC_FEATURE_BILLING_ENABLED, and NEXT_PUBLIC_POSTHOG_KEY.
packages/ee/server-only/limits/client.ts Updated import statements and the URL construction logic to handle potentially undefined APP_BASE_URL.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@catalinpit
Copy link
Contributor Author

@coderabbitai review

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9d6ee94 and c0bb520.
Files ignored due to path filters (2)
  • package-lock.json is excluded by: !**/*.json
  • package.json is excluded by: !**/*.json
Files selected for processing (32)
  • apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/settings/billing/create-billing-portal.action.ts (1 hunks)
  • apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts (3 hunks)
  • apps/web/src/app/(share)/share/[slug]/opengraph/route.tsx (3 hunks)
  • apps/web/src/app/(share)/share/[slug]/page.tsx (2 hunks)
  • apps/web/src/app/(unauthenticated)/signin/page.tsx (3 hunks)
  • apps/web/src/app/(unauthenticated)/signup/page.tsx (2 hunks)
  • apps/web/src/app/layout.tsx (4 hunks)
  • apps/web/src/components/(dashboard)/avatar/avatar-with-recipient.tsx (3 hunks)
  • apps/web/src/helpers/get-asset-buffer.ts (2 hunks)
  • packages/ee/server-only/limits/client.ts (2 hunks)
  • packages/email/template-components/template-document-self-signed.tsx (2 hunks)
  • packages/email/template-components/template-reset-password.tsx (3 hunks)
  • packages/lib/constants/app.ts (1 hunks)
  • packages/lib/constants/feature-flags.ts (2 hunks)
  • packages/lib/next-auth/auth-options.ts (3 hunks)
  • packages/lib/server-only/auth/send-confirmation-email.ts (3 hunks)
  • packages/lib/server-only/auth/send-forgot-password.ts (3 hunks)
  • packages/lib/server-only/auth/send-reset-password.ts (2 hunks)
  • packages/lib/server-only/document/delete-document.ts (3 hunks)
  • packages/lib/server-only/document/resend-document.tsx (3 hunks)
  • packages/lib/server-only/document/send-completed-email.ts (3 hunks)
  • packages/lib/server-only/document/send-document.tsx (3 hunks)
  • packages/lib/server-only/document/send-pending-email.ts (3 hunks)
  • packages/lib/server-only/feature-flags/all.ts (3 hunks)
  • packages/lib/server-only/feature-flags/get.ts (3 hunks)
  • packages/lib/universal/get-base-url.ts (2 hunks)
  • packages/lib/universal/upload/put-file.ts (2 hunks)
  • packages/lib/universal/upload/server-actions.ts (2 hunks)
  • packages/trpc/server/auth-router/router.ts (2 hunks)
  • packages/trpc/server/singleplayer-router/router.ts (3 hunks)
  • packages/ui/components/document/document-share-button.tsx (6 hunks)
Files skipped from review due to trivial changes (1)
  • packages/lib/server-only/auth/send-reset-password.ts
Additional comments: 53
packages/lib/universal/get-base-url.ts (1)
  • 2-4: The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL is a positive change, enhancing modularity and maintainability by centralizing the retrieval of environment variables.
packages/lib/constants/app.ts (1)
  • 1-12: The use of env from 'next-runtime-env' to retrieve environment variables instead of direct process.env access is a good practice, improving security and flexibility in environment variable management.
apps/web/src/helpers/get-asset-buffer.ts (1)
  • 10-18: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-15]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for asset base URL retrieval is a good improvement, providing a more flexible and reliable way to access environment variables.

apps/web/src/app/(dashboard)/settings/billing/create-billing-portal.action.ts (1)
  • 3-18: The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the returnUrl parameter in createBillingPortal function is a good practice, enhancing flexibility in environment variable handling.
packages/ee/server-only/limits/client.ts (2)
  • 4-5: The modification of import statements for TLimitsResponseSchema and ZLimitsResponseSchema is a good practice, ensuring that only necessary types are imported.
  • 14-14: Updating the url construction in the getLimits function to handle potentially undefined APP_BASE_URL is a good improvement, making the code more robust.
apps/web/src/app/(unauthenticated)/signup/page.tsx (1)
  • 13-21: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [5-18]

The addition of env from 'next-runtime-env' to retrieve NEXT_PUBLIC_DISABLE_SIGNUP and its conditional usage to redirect users is a good practice, improving the handling and security of environment variables.

apps/web/src/app/(unauthenticated)/signin/page.tsx (1)
  • 12-19: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-27]

The addition of env from 'next-runtime-env' to retrieve NEXT_PUBLIC_DISABLE_SIGNUP and its conditional usage within the SignInPage component is a good practice, improving the handling and security of environment variables.

packages/email/template-components/template-reset-password.tsx (1)
  • 10-17: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-31]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the TemplateResetPassword component is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/lib/constants/feature-flags.ts (1)
  • 21-35: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-32]

The use of env from 'next-runtime-env' to retrieve environment variables instead of direct process.env access is a good practice, improving security and flexibility in environment variable management.

apps/web/src/app/(share)/share/[slug]/page.tsx (1)
  • 30-43: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-42]

The modifications, including the use of type keyword for importing Metadata, adding env from 'next-runtime-env', and replacing direct process.env access with env function calls, are good practices that improve modularity and environment variable handling.

apps/web/src/app/(dashboard)/settings/billing/create-checkout.action.ts (1)
  • 31-43: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-41]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the returnUrl parameter in createCheckout function is a good practice, enhancing flexibility in environment variable handling.

packages/lib/server-only/auth/send-forgot-password.ts (1)
  • 12-19: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-37]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the sendForgotPassword function is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/lib/universal/upload/put-file.ts (1)
  • 12-21: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [2-18]

The addition of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_UPLOAD_TRANSPORT for the putFile function is a good practice, improving the handling and security of environment variables.

packages/lib/server-only/document/send-pending-email.ts (1)
  • 13-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-48]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the sendPendingEmail function is a good improvement, replacing direct references to process.env with a more flexible approach.

apps/web/src/components/(dashboard)/avatar/avatar-with-recipient.tsx (1)
  • 18-25: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [5-31]

The addition of env from 'next-runtime-env' to retrieve NEXT_PUBLIC_WEBAPP_URL and its usage in the AvatarWithRecipient function is a good practice, improving the handling and security of environment variables.

packages/lib/server-only/auth/send-confirmation-email.ts (1)
  • 12-21: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-42]

The import of env from 'next-runtime-env' and its usage to retrieve environment variables for the sendConfirmationEmail function is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/lib/server-only/feature-flags/all.ts (1)
  • 12-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-49]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL and NEXT_PUBLIC_MARKETING_URL for the handlerFeatureFlagAll function is a good practice, improving the handling and security of environment variables.

packages/lib/server-only/document/send-completed-email.ts (1)
  • 40-51: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-48]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the sendCompletedEmail function is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/trpc/server/auth-router/router.ts (1)
  • 9-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [2-17]

The addition of env from 'next-runtime-env' to retrieve NEXT_PUBLIC_DISABLE_SIGNUP and its usage in the authRouter module is a good practice, improving the handling and security of environment variables.

packages/lib/server-only/document/delete-document.ts (1)
  • 2-9: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [5-21]

The addition of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the deleteDocument function is a good practice, improving the handling and security of environment variables.

packages/email/template-components/template-document-self-signed.tsx (1)
  • 12-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-17]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the TemplateDocumentSelfSigned component is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/lib/server-only/document/resend-document.tsx (1)
  • 16-23: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-75]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the resendDocument function is a good practice, improving the handling and security of environment variables.

packages/lib/server-only/document/send-document.tsx (1)
  • 16-23: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-67]

The import of env from 'next-runtime-env' and its usage to retrieve NEXT_PUBLIC_WEBAPP_URL for the sendDocument function is a good improvement, replacing direct references to process.env with a more flexible approach.

packages/lib/universal/upload/server-actions.ts (3)
  • 14-14: The import of env from next-runtime-env is correctly implemented to facilitate environment variable access in a more secure and flexible manner.
  • 21-21: The declaration of NEXT_PUBLIC_UPLOAD_TRANSPORT using env('NEXT_PUBLIC_UPLOAD_TRANSPORT') is a good practice, ensuring that environment variables are accessed securely and consistently across the application.
  • 123-123: The conditional check if (NEXT_PUBLIC_UPLOAD_TRANSPORT !== 's3') correctly uses the NEXT_PUBLIC_UPLOAD_TRANSPORT variable to determine the upload transport mechanism. This enhances the flexibility and configurability of the upload functionality.
packages/lib/server-only/feature-flags/get.ts (4)
  • 4-6: The adjustment in imports for JWT and getToken from next-auth/jwt, and the introduction of env from next-runtime-env, are correctly implemented to align with the updated approach for handling authentication and environment variables.
  • 18-19: Correctly declaring NEXT_PUBLIC_WEBAPP_URL and NEXT_PUBLIC_MARKETING_URL using env ensures secure and consistent access to these environment variables across the application.
  • 65-65: The conditional check using NEXT_PUBLIC_WEBAPP_URL to determine the origin for CORS headers is a good practice, enhancing security by dynamically setting allowed origins based on environment configuration.
  • 69-69: Similarly, using NEXT_PUBLIC_MARKETING_URL for CORS header configuration further exemplifies the application's flexible and secure approach to handling cross-origin requests.
apps/web/src/app/layout.tsx (5)
  • 5-5: The import of PublicEnvScript and env from next-runtime-env is correctly implemented, indicating a shift towards using environment variables for configuration within the application's layout.
  • 24-24: Correctly declaring NEXT_PUBLIC_WEBAPP_URL using env ensures that the application can dynamically use the base URL for various purposes, such as constructing image URLs for social media sharing.
  • 42-42: Using NEXT_PUBLIC_WEBAPP_URL to dynamically set the image URL in the Open Graph metadata is a good practice, ensuring that the metadata reflects the correct base URL based on the deployment environment.
  • 47-47: Similarly, using NEXT_PUBLIC_WEBAPP_URL for Twitter card images ensures consistency and correctness in social media sharing functionality.
  • 69-69: The inclusion of PublicEnvScript in the document head is a necessary step for ensuring that environment variables are correctly exposed to the client-side of the application.
apps/web/src/app/(share)/share/[slug]/opengraph/route.tsx (3)
  • 4-4: The import of env from next-runtime-env is correctly implemented, aligning with the application's strategy for securely accessing environment variables.
  • 26-26: Correctly declaring NEXT_PUBLIC_WEBAPP_URL using env ensures that the application can dynamically use the base URL for generating Open Graph images, enhancing flexibility and configurability.
  • 43-43: Using NEXT_PUBLIC_WEBAPP_URL to construct the base URL for API calls related to sharing functionality is a good practice, ensuring that the application adapts to different deployment environments.
packages/ui/components/document/document-share-button.tsx (7)
  • 7-7: The import of env from next-runtime-env is correctly implemented, facilitating secure and consistent access to environment variables within the component.
  • 42-42: Correctly declaring NEXT_PUBLIC_WEBAPP_URL using env ensures that the component can dynamically construct share links and Open Graph image URLs based on the deployment environment.
  • 73-73: Using NEXT_PUBLIC_WEBAPP_URL to construct the share link URL is a good practice, ensuring that the links are correctly formed based on the current deployment environment.
  • 97-97: Pre-warming the Open Graph image by fetching it before sharing on Twitter, using NEXT_PUBLIC_WEBAPP_URL, is an effective way to ensure that the image is available when the tweet is viewed.
  • 105-105: Opening the Twitter share intent with a URL constructed using NEXT_PUBLIC_WEBAPP_URL ensures that the shared content is correctly linked back to the application.
  • 153-153: Displaying the share link in the UI using NEXT_PUBLIC_WEBAPP_URL ensures that users see the correct URL based on the deployment environment.
  • 165-165: Using NEXT_PUBLIC_WEBAPP_URL to construct the Open Graph image URL for display within the share dialog is a good practice, ensuring that the image is correctly sourced from the current deployment environment.
packages/trpc/server/singleplayer-router/router.ts (3)
  • 3-3: The import of env from next-runtime-env is correctly implemented, aligning with the application's strategy for securely accessing environment variables in server-side logic.
  • 28-28: Correctly declaring NEXT_PUBLIC_WEBAPP_URL using env ensures that server-side logic can dynamically use the base URL for constructing email templates and other URLs, enhancing flexibility and configurability.
  • 154-154: Using NEXT_PUBLIC_WEBAPP_URL to set the assetBaseUrl in the email template is a good practice, ensuring that the email content correctly references assets based on the deployment environment.
packages/lib/next-auth/auth-options.ts (3)
  • 10-10: The import of env from next-runtime-env is correctly implemented, facilitating secure and consistent access to environment variables within the authentication options configuration.
  • 20-20: Correctly declaring NEXT_PUBLIC_DISABLE_SIGNUP using env ensures that the authentication logic can dynamically enable or disable signups based on the deployment environment.
  • 189-189: Using NEXT_PUBLIC_DISABLE_SIGNUP to conditionally allow sign-ins based on the environment configuration is a good practice, ensuring that the application can dynamically adapt its authentication behavior.
apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx (1)
  • 64-64: The correction of the typo in the variable declaration from "DcumentFlowStep" to "DocumentFlowStep" ensures the correctness and readability of the code.

Mythie
Mythie previously approved these changes Feb 8, 2024
Copy link
Collaborator

@Mythie Mythie left a comment

Choose a reason for hiding this comment

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

If it builds we ride 🏇🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: marketing Issues related to website or marketing app apps: web Issues related to the webapp pkg: ee changes version bump 👀
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants