From ec58a9dd70804aa5ab9a45a6c7bc91d0e0d67963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Fri, 25 Mar 2022 17:39:38 -0700 Subject: [PATCH] The Dotenv Refactor (#2275) * dotenv refactoring * dotenv fixes * Env variables cleanup * Updates e2e variables * Moves environment file to types * Removes conflicting configs * Readds missing variables * Fixes * More fixes * Update .env.example * Update yarn.lock * Update turbo.json * Fixes e2e * Temp fix * disables cache for lint * Please work * I'm getting desperate here. * Matches node versions * Take 2 * Revert "Take 2" This reverts commit a735f47f2325c2040168e0cd99dea0fc357a791f. * Update .env.example --- .env.example | 153 ++++++++++++++- .github/workflows/check-types.yml | 1 - .github/workflows/e2e.yml | 36 ++-- .github/workflows/lint.yml | 17 +- apps/web/.env.example | 109 ----------- apps/web/components/Shell.tsx | 11 +- .../booking/pages/AvailabilityPage.tsx | 4 +- .../components/eventtype/CreateEventType.tsx | 2 +- apps/web/components/seo/head-seo.tsx | 2 +- apps/web/components/team/TeamListItem.tsx | 6 +- apps/web/components/team/TeamSettings.tsx | 2 +- .../team/TeamSettingsRightSidebar.tsx | 2 +- apps/web/ee/pages/api/teams/[team]/upgrade.ts | 2 +- .../templates/organizer-request-email.ts | 4 +- .../organizer-request-reminder-email.ts | 4 +- apps/web/next.config.js | 33 ++-- apps/web/pages/404.tsx | 4 +- apps/web/pages/api/auth/forgot-password.ts | 6 +- apps/web/pages/apps/installed.tsx | 2 +- apps/web/pages/auth/forgot-password/index.tsx | 4 +- apps/web/pages/auth/login.tsx | 8 +- apps/web/pages/auth/signup.tsx | 2 +- apps/web/pages/auth/sso/[provider].tsx | 4 +- apps/web/pages/event-types/[type].tsx | 8 +- apps/web/pages/event-types/index.tsx | 17 +- apps/web/pages/getting-started.tsx | 2 +- apps/web/pages/settings/profile.tsx | 4 +- .../playwright/auth/forgot-password.test.ts | 2 +- apps/web/server/routers/viewer.tsx | 6 +- apps/web/tsconfig.json | 4 +- package.json | 11 +- .../app-store/office365video/.env.example | 4 - .../app-store/stripepayment/api/portal.ts | 2 +- packages/app-store/zoomvideo/.env.example | 4 - packages/lib/constants.ts | 9 +- packages/prisma/seed.ts | 12 +- packages/stripe/client.ts | 2 +- packages/stripe/team-billing.ts | 4 +- {apps/web => packages/types}/environment.d.ts | 31 ++- tests/config/globalSetup.ts | 2 + turbo.json | 17 +- yarn.lock | 182 +++++++++++++++++- 42 files changed, 498 insertions(+), 243 deletions(-) delete mode 100644 apps/web/.env.example delete mode 100644 packages/app-store/office365video/.env.example delete mode 100644 packages/app-store/zoomvideo/.env.example rename {apps/web => packages/types}/environment.d.ts (51%) diff --git a/.env.example b/.env.example index e97496b152..f6e1ef23b9 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,151 @@ -# It now lives at `apps/web/.env.example` -# DATABASE_URL got moved to `packages/prisma/.env.example` +# ********** INDEX ********** +# +# - LICENSE +# - DATABASE +# - SHARED +# - NEXTAUTH +# - E-MAIL SETTINGS +# - APP STORE +# - DAILY.CO VIDEO +# - GOOGLE CALENDAR/MEET/LOGIN +# - OFFICE 365 +# - STRIPE +# - TANDEM +# - ZOOM + +# - LICENSE ************************************************************************************************* +# Set this value to 'agree' to accept our license: +# LICENSE: https://github.com/calendso/calendso/blob/main/LICENSE +# +# Summary of terms: +# - The codebase has to stay open source, whether it was modified or not +# - You can not repackage or sell the codebase +# - Acquire a commercial license to remove these terms by visiting: cal.com/sales +NEXT_PUBLIC_LICENSE_CONSENT='' +# *********************************************************************************************************** + +# - DATABASE ************************************************************************************************ +# ⚠️ ⚠️ ⚠️ DATABASE_URL got moved to `packages/prisma/.env.example` ⚠️ ⚠️ ⚠️ +# *********************************************************************************************************** + +# - SHARED ************************************************************************************************** +NEXT_PUBLIC_WEBAPP_URL='http://localhost:3000' +# Change to 'http://localhost:3001' if running the website simultaneously +NEXT_PUBLIC_WEBSITE_URL='http://localhost:3000' + +# To enable SAML login, set both these variables +# @see https://github.com/calcom/cal.com/tree/main/packages/ee#setting-up-saml-login +# SAML_DATABASE_URL="postgresql://postgres:@localhost:5450/cal-saml" +SAML_DATABASE_URL= +# SAML_ADMINS='pro@example.com' +SAML_ADMINS= +# If you use Heroku to deploy Postgres (or use self-signed certs for Postgres) then uncomment the follow line. +# @see https://devcenter.heroku.com/articles/connecting-heroku-postgres#connecting-in-node-js +# PGSSLMODE='no-verify' +PGSSLMODE= + +# - NEXTAUTH +# @see: https://github.com/calendso/calendso/issues/263 +# Required for Vercel hosting - set NEXTAUTH_URL to equal your BASE_URL +# NEXTAUTH_URL='http://localhost:3000' +NEXTAUTH_URL= +JWT_SECRET='secret' +# Used for cross-domain cookie authentication +NEXTAUTH_COOKIE_DOMAIN=.example.com + +# Remove this var if you don't want Cal to collect anonymous usage +NEXT_PUBLIC_TELEMETRY_KEY=js.2pvs2bbpqq1zxna97wcml.oi2jzirnbj1ev4tc57c5r + +# ApiKey for cronjobs +CRON_API_KEY='0cc0e6c35519bba620c9360cfe3e68d0' + +# Application Key for symmetric encryption and decryption +# must be 32 bytes for AES256 encryption algorithm +# You can use: `openssl rand -base64 24` to generate one +CALENDSO_ENCRYPTION_KEY= + +# Intercom Config +NEXT_PUBLIC_INTERCOM_APP_ID= + +# Zendesk Config +NEXT_PUBLIC_ZENDESK_KEY= + +# Help Scout Config +NEXT_PUBLIC_HELPSCOUT_KEY= + +# This is used so we can bypass emails in auth flows for E2E testing +# Set it to "1" if you need to run E2E tests locally +NEXT_PUBLIC_IS_E2E= + +# Used for internal billing system +NEXT_PUBLIC_STRIPE_PRO_PLAN_PRODUCT= +NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE= +NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE= +NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE= +# *********************************************************************************************************** + +# - E-MAIL SETTINGS ***************************************************************************************** +# Cal uses nodemailer (@see https://nodemailer.com/about/) to provide email sending. As such we are trying to +# allow access to the nodemailer transports from the .env file. E-mail templates are accessible within lib/emails/ +# Configures the global From: header whilst sending emails. +EMAIL_FROM='notifications@yourselfhostedcal.com' + +# Configure SMTP settings (@see https://nodemailer.com/smtp/). +# Note: The below configuration for Office 365 has been verified to work. +EMAIL_SERVER_HOST='smtp.office365.com' +EMAIL_SERVER_PORT=587 +EMAIL_SERVER_USER='' +# Keep in mind that if you have 2FA enabled, you will need to provision an App Password. +EMAIL_SERVER_PASSWORD='' + +# The following configuration for Gmail has been verified to work. +# EMAIL_SERVER_HOST='smtp.gmail.com' +# EMAIL_SERVER_PORT=465 +# EMAIL_SERVER_USER='' +## You will need to provision an App Password. +## @see https://support.google.com/accounts/answer/185833 +# EMAIL_SERVER_PASSWORD='' +# ********************************************************************************************************** + +# - APP STORE ********************************************************************************************** +# - DAILY.CO VIDEO +DAILY_API_KEY= +DAILY_SCALE_PLAN='' + +# - GOOGLE CALENDAR/MEET/LOGIN +# Needed to enable Google Calendar integration and Login with Google +# @see https://github.com/calendso/calendso#obtaining-the-google-api-credentials +GOOGLE_API_CREDENTIALS='{}' +# To enable Login with Google you need to: +# 1. Set `GOOGLE_API_CREDENTIALS` above +# 2. Set `GOOGLE_LOGIN_ENABLED` to `true` +# When self-hosting please ensure you configure the Google integration as an Internal app so no one else can login to your instance +# @see https://support.google.com/cloud/answer/6158849#public-and-internal&zippy=%2Cpublic-and-internal-applications +GOOGLE_LOGIN_ENABLED=false + +# - OFFICE 365 +# Used for the Office 365 / Outlook.com Calendar / MS Teams integration +# @see https://github.com/calcom/cal.com/#Obtaining-Microsoft-Graph-Client-ID-and-Secret +MS_GRAPH_CLIENT_ID= +MS_GRAPH_CLIENT_SECRET= + +# - STRIPE +NEXT_PUBLIC_STRIPE_PUBLIC_KEY= # pk_test_... +STRIPE_PRIVATE_KEY= # sk_test_... +STRIPE_WEBHOOK_SECRET= # whsec_... +STRIPE_CLIENT_ID= # ca_... +PAYMENT_FEE_FIXED=10 # Take 10 additional cents commission +PAYMENT_FEE_PERCENTAGE=0.005 # Take 0.5% commission + +# - TANDEM +# Used for the Tandem integration -- contact support@tandem.chat to for API access. +TANDEM_CLIENT_ID="" +TANDEM_CLIENT_SECRET="" +TANDEM_BASE_URL="https://tandem.chat" + +# - ZOOM +# Used for the Zoom integration +# @see https://github.com/calcom/cal.com/#obtaining-zoom-client-id-and-secret +ZOOM_CLIENT_ID= +ZOOM_CLIENT_SECRET= +# ********************************************************************************************************* diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index c170321c77..a8c933d87e 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -6,7 +6,6 @@ on: jobs: types: name: Check types - strategy: matrix: node: ["14.x"] diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 0430294af9..36e9acfc2b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,6 +1,6 @@ name: E2E test on: - pull_request_target: + pull_request: branches: - main paths-ignore: @@ -9,9 +9,16 @@ jobs: test: timeout-minutes: 10 name: Testing ${{ matrix.node }} and ${{ matrix.os }} + strategy: + matrix: + node: ["14.x"] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + env: DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - BASE_URL: http://localhost:3000 + NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000 + NEXT_PUBLIC_WEBSITE_URL: http://localhost:3000 JWT_SECRET: secret GOOGLE_API_CREDENTIALS: ${{ secrets.CI_GOOGLE_API_CREDENTIALS }} GOOGLE_LOGIN_ENABLED: true @@ -25,12 +32,13 @@ jobs: PAYMENT_FEE_FIXED: 10 SAML_DATABASE_URL: postgresql://postgres:@localhost:5432/calendso SAML_ADMINS: pro@example.com - # NEXTAUTH_URL: xxx - EMAIL_FROM: e2e@cal.com - EMAIL_SERVER_HOST: ${{ secrets.CI_EMAIL_SERVER_HOST }} - EMAIL_SERVER_PORT: ${{ secrets.CI_EMAIL_SERVER_PORT }} - EMAIL_SERVER_USER: ${{ secrets.CI_EMAIL_SERVER_USER }} - EMAIL_SERVER_PASSWORD: ${{ secrets.CI_EMAIL_SERVER_PASSWORD }} + NEXTAUTH_URL: http://localhost:3000/api/auth + NEXT_PUBLIC_IS_E2E: 1 + # EMAIL_FROM: e2e@cal.com + # EMAIL_SERVER_HOST: ${{ secrets.CI_EMAIL_SERVER_HOST }} + # EMAIL_SERVER_PORT: ${{ secrets.CI_EMAIL_SERVER_PORT }} + # EMAIL_SERVER_USER: ${{ secrets.CI_EMAIL_SERVER_USER }} + # EMAIL_SERVER_PASSWORD: ${{ secrets.CI_EMAIL_SERVER_PASSWORD }} # MS_GRAPH_CLIENT_ID: xxx # MS_GRAPH_CLIENT_SECRET: xxx # ZOOM_CLIENT_ID: xxx @@ -43,25 +51,19 @@ jobs: POSTGRES_DB: calendso ports: - 5432:5432 - runs-on: ${{ matrix.os }} - strategy: - matrix: - node: ["14.x"] - os: [ubuntu-latest] steps: - name: Checkout repo uses: actions/checkout@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 2 + fetch-depth: 0 - name: Use Node ${{ matrix.node }} uses: actions/setup-node@v2 with: - cache: "yarn" - cache-dependency-path: yarn.lock node-version: ${{ matrix.node }} + # cache: "yarn" + # cache-dependency-path: yarn.lock - name: Turbo Cache id: turbo-cache diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b190c39fcf..056c9d63e2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,25 +1,28 @@ name: Lint on: - pull_request_target: + pull_request: branches: - main jobs: lint: - runs-on: ubuntu-latest + strategy: + matrix: + node: ["14.x"] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - name: Checkout repo uses: actions/checkout@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 2 + fetch-depth: 0 - name: Use Node.js 14.x uses: actions/setup-node@v2 with: - node-version: 14.x - cache: "yarn" - cache-dependency-path: yarn.lock + node-version: ${{ matrix.node }} + # cache: "yarn" + # cache-dependency-path: yarn.lock - name: Install deps if: steps.yarn-cache.outputs.cache-hit != 'true' diff --git a/apps/web/.env.example b/apps/web/.env.example deleted file mode 100644 index dd87b26d0d..0000000000 --- a/apps/web/.env.example +++ /dev/null @@ -1,109 +0,0 @@ -# Set this value to 'agree' to accept our license: -# LICENSE: https://github.com/calendso/calendso/blob/main/LICENSE -# -# Summary of terms: -# - The codebase has to stay open source, whether it was modified or not -# - You can not repackage or sell the codebase -# - Acquire a commercial license to remove these terms by visiting: cal.com/sales -NEXT_PUBLIC_LICENSE_CONSENT='' - -# ⚠️ ⚠️ ⚠️ DATABASE_URL got moved to `packages/prisma/.env.example` ⚠️ ⚠️ ⚠️ - -# Needed to enable Google Calendar integration and Login with Google -# @see https://github.com/calendso/calendso#obtaining-the-google-api-credentials -GOOGLE_API_CREDENTIALS='{}' - -# To enable Login with Google you need to: -# 1. Set `GOOGLE_API_CREDENTIALS` above -# 2. Set `GOOGLE_LOGIN_ENABLED` to `true` -# When self-hosting please ensure you configure the Google integration as an Internal app so no one else can login to your instance -# @see https://support.google.com/cloud/answer/6158849#public-and-internal&zippy=%2Cpublic-and-internal-applications -GOOGLE_LOGIN_ENABLED=false - -BASE_URL='http://localhost:3000' -NEXT_PUBLIC_APP_URL='http://localhost:3000' - -JWT_SECRET='secret' -# This is used so we can bypass emails in auth flows for E2E testing - -# To enable SAML login, set both these variables -# @see https://github.com/calcom/cal.com/tree/main/packages/ee#setting-up-saml-login -# SAML_DATABASE_URL="postgresql://postgres:@localhost:5450/cal-saml" -# SAML_ADMINS='pro@example.com' -# If you use Heroku to deploy Postgres (or use self-signed certs for Postgres) then uncomment the follow line. -# @see https://devcenter.heroku.com/articles/connecting-heroku-postgres#connecting-in-node-js -##PGSSLMODE='no-verify' - -# @see: https://github.com/calendso/calendso/issues/263 -# Required for Vercel hosting - set NEXTAUTH_URL to equal your BASE_URL -# NEXTAUTH_URL='http://localhost:3000' - -# Remove this var if you don't want Cal to collect anonymous usage -NEXT_PUBLIC_TELEMETRY_KEY=js.2pvs2bbpqq1zxna97wcml.oi2jzirnbj1ev4tc57c5r - -# Used for the Office 365 / Outlook.com Calendar integration -MS_GRAPH_CLIENT_ID= -MS_GRAPH_CLIENT_SECRET= - -# Used for the Zoom integration -ZOOM_CLIENT_ID= -ZOOM_CLIENT_SECRET= - -#Used for the Daily integration -DAILY_API_KEY= -DAILY_SCALE_PLAN='' - -# Used for the Tandem integration -- contact support@tandem.chat to for API access. -TANDEM_CLIENT_ID="" -TANDEM_CLIENT_SECRET="" -TANDEM_BASE_URL="https://tandem.chat" - -# E-mail settings - -# Cal uses nodemailer (@see https://nodemailer.com/about/) to provide email sending. As such we are trying to -# allow access to the nodemailer transports from the .env file. E-mail templates are accessible within lib/emails/ - -# Configures the global From: header whilst sending emails. -EMAIL_FROM='notifications@yourselfhostedcal.com' - -# Configure SMTP settings (@see https://nodemailer.com/smtp/). -# Note: The below configuration for Office 365 has been verified to work. -EMAIL_SERVER_HOST='smtp.office365.com' -EMAIL_SERVER_PORT=587 -EMAIL_SERVER_USER='' -# Keep in mind that if you have 2FA enabled, you will need to provision an App Password. -EMAIL_SERVER_PASSWORD='' -# The following configuration for Gmail has been verified to work. -# EMAIL_SERVER_HOST='smtp.gmail.com' -# EMAIL_SERVER_PORT=465 -# EMAIL_SERVER_USER='' -## You will need to provision an App Password. -## @see https://support.google.com/accounts/answer/185833 -# EMAIL_SERVER_PASSWORD='' - -# ApiKey for cronjobs -CRON_API_KEY='0cc0e6c35519bba620c9360cfe3e68d0' - -# Stripe Config -NEXT_PUBLIC_STRIPE_PUBLIC_KEY= # pk_test_... -STRIPE_PRIVATE_KEY= # sk_test_... -STRIPE_CLIENT_ID= # ca_... -STRIPE_WEBHOOK_SECRET= # whsec_... -PAYMENT_FEE_PERCENTAGE=0.005 # Take 0.5% commission -PAYMENT_FEE_FIXED=10 # Take 10 additional cents commission - -# Application Key for symmetric encryption and decryption -# must be 32 bytes for AES256 encryption algorithm -CALENDSO_ENCRYPTION_KEY= - -# Intercom Config -NEXT_PUBLIC_INTERCOM_APP_ID= - -# Zendesk Config -NEXT_PUBLIC_ZENDESK_KEY= - -# Help Scout Config -NEXT_PUBLIC_HELPSCOUT_KEY= - -# Set it to "1" if you need to run E2E tests locally -NEXT_PUBLIC_IS_E2E= diff --git a/apps/web/components/Shell.tsx b/apps/web/components/Shell.tsx index 5844ab1191..b42610bf93 100644 --- a/apps/web/components/Shell.tsx +++ b/apps/web/components/Shell.tsx @@ -298,7 +298,7 @@ export default function Shell(props: { © {new Date().getFullYear()} Cal.com, Inc. v.{pkg.version + "-"} - {process.env.NEXT_PUBLIC_APP_URL === "https://cal.com" ? "h" : "sh"} + {process.env.NEXT_PUBLIC_WEBSITE_URL === "https://cal.com" ? "h" : "sh"} -{user && user.plan} @@ -437,12 +437,7 @@ function UserDropdown({ small }: { small?: boolean }) { )}> {user?.username {!user?.away && ( @@ -496,7 +491,7 @@ function UserDropdown({ small }: { small?: boolean }) { {t("view_public_page")} diff --git a/apps/web/components/booking/pages/AvailabilityPage.tsx b/apps/web/components/booking/pages/AvailabilityPage.tsx index 0bbff943ef..100f669961 100644 --- a/apps/web/components/booking/pages/AvailabilityPage.tsx +++ b/apps/web/components/booking/pages/AvailabilityPage.tsx @@ -139,7 +139,7 @@ const AvailabilityPage = ({ profile, eventType, workingHours, previousPage }: Pr .filter((user) => user.name !== profile.name) .map((user) => ({ title: user.name, - image: `${process.env.NEXT_PUBLIC_APP_URL}/${user.username}/avatar.png`, + image: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user.username}/avatar.png`, alt: user.name || undefined, })), ].filter((item) => !!item.image) as { image: string; alt?: string; title?: string }[] @@ -189,7 +189,7 @@ const AvailabilityPage = ({ profile, eventType, workingHours, previousPage }: Pr .map((user) => ({ title: user.name, alt: user.name, - image: `${process.env.NEXT_PUBLIC_APP_URL}/${user.username}/avatar.png`, + image: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/${user.username}/avatar.png`, })), ].filter((item) => !!item.image) as { image: string; alt?: string; title?: string }[] } diff --git a/apps/web/components/eventtype/CreateEventType.tsx b/apps/web/components/eventtype/CreateEventType.tsx index 8811cec13b..9bf299eb92 100644 --- a/apps/web/components/eventtype/CreateEventType.tsx +++ b/apps/web/components/eventtype/CreateEventType.tsx @@ -191,7 +191,7 @@ export default function CreateEventTypeButton(props: Props) { required addOnLeading={ - {process.env.NEXT_PUBLIC_APP_URL}/{pageSlug}/ + {process.env.NEXT_PUBLIC_WEBSITE_URL}/{pageSlug}/ } {...register("slug")} diff --git a/apps/web/components/seo/head-seo.tsx b/apps/web/components/seo/head-seo.tsx index d2e4c39639..ad71e84d3f 100644 --- a/apps/web/components/seo/head-seo.tsx +++ b/apps/web/components/seo/head-seo.tsx @@ -67,7 +67,7 @@ const constructImage = (name: string, description: string, username: string): st return ( encodeURIComponent("Meet **" + name + "**
" + description).replace(/'/g, "%27") + ".png?md=1&images=https%3A%2F%2Fcal.com%2Flogo-white.svg&images=" + - (process.env.NEXT_PUBLIC_APP_URL || process.env.BASE_URL) + + (process.env.NEXT_PUBLIC_WEBSITE_URL || process.env.NEXT_PUBLIC_WEBAPP_URL) + "/" + username + "/avatar.png" diff --git a/apps/web/components/team/TeamListItem.tsx b/apps/web/components/team/TeamListItem.tsx index c506e39db4..6c3d12fb0c 100644 --- a/apps/web/components/team/TeamListItem.tsx +++ b/apps/web/components/team/TeamListItem.tsx @@ -72,7 +72,7 @@ export default function TeamListItem(props: Props) {
{team.name} - {process.env.NEXT_PUBLIC_APP_URL}/team/{team.slug} + {process.env.NEXT_PUBLIC_WEBSITE_URL}/team/{team.slug}
@@ -112,7 +112,7 @@ export default function TeamListItem(props: Props) {