From bf3f8acbc0b67e78148b365a23e6ecce24cdb9f8 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:36:25 +0100 Subject: [PATCH] feat: Enable new booker globally for 3.0 (#9541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update migration to be on by default - remove cookie check * Use env variable to control enabling NEW_BOOKER for all * Update packages/prisma/migrations/20230524105015_added_newbooker_feature_flag/migration.sql * Update turbo.json --------- Co-authored-by: Hariom Balhara Co-authored-by: Omar López --- .env.example | 6 ++++++ apps/web/middleware.ts | 15 +++++++++++++++ apps/web/next.config.js | 32 ++++++++++++++++++++++++++++++++ turbo.json | 2 ++ 4 files changed, 55 insertions(+) diff --git a/.env.example b/.env.example index 4bfb15c3f9..798c774414 100644 --- a/.env.example +++ b/.env.example @@ -203,3 +203,9 @@ PROJECT_ID_VERCEL= TEAM_ID_VERCEL= # Get it from: https://vercel.com/account/tokens AUTH_BEARER_TOKEN_VERCEL= + +#Enables New booker for Embed only +NEW_BOOKER_ENABLED_FOR_EMBED=0 + +#Enables New booker for All but Embed requests +NEW_BOOKER_ENABLED_FOR_NON_EMBED=0 \ No newline at end of file diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts index 283c15a531..0570b43643 100644 --- a/apps/web/middleware.ts +++ b/apps/web/middleware.ts @@ -12,6 +12,21 @@ const middleware: NextMiddleware = async (req) => { const url = req.nextUrl; const requestHeaders = new Headers(req.headers); const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(req.headers.get("host") ?? ""); + const isEmbedRequest = typeof url.searchParams.get("embed") === "string"; + + /** + * We are using env variable to toggle new-booker because using flags would be an unnecessary delay for booking pages + * Also, we can't easily identify the booker page requests here(to just fetch the flags for those requests) + */ + // Enable New Booker for All but embed Requests + if (process.env.NEW_BOOKER_ENABLED_FOR_NON_EMBED === "1" && !isEmbedRequest) { + requestHeaders.set("new-booker-enabled", "1"); + } + + // Enable New Booker for Embed Requests + if (process.env.NEW_BOOKER_ENABLED_FOR_EMBED === "1" && isEmbedRequest) { + requestHeaders.set("new-booker-enabled", "1"); + } // Make sure we are in the presence of an organization if (isValidOrgDomain && url.pathname === "/") { diff --git a/apps/web/next.config.js b/apps/web/next.config.js index ba1d14190f..3ccc300bf3 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -223,6 +223,38 @@ const nextConfig = { source: "/embed/embed.js", destination: process.env.NEXT_PUBLIC_EMBED_LIB_URL?, }, */ + /** + * Header allows us to enable new-booker using middleware which uses env variables to enable/disable new booker + */ + { + source: `/:user((?!${pages.join("|")}).*)/:type`, + destination: "/new-booker/:user/:type", + has: [{ type: "header", key: "new-booker-enabled" }], + }, + { + source: `/:user((?!${pages.join("|")}).*)/:type/embed`, + destination: "/new-booker/:user/:type/embed", + has: [{ type: "header", key: "new-booker-enabled" }], + }, + { + source: "/team/:slug/:type", + destination: "/new-booker/team/:slug/:type", + has: [{ type: "header", key: "new-booker-enabled" }], + }, + { + source: "/team/:slug/:type/embed", + destination: "/new-booker/team/:slug/:type/embed", + has: [{ type: "header", key: "new-booker-enabled" }], + }, + { + source: "/d/:link/:slug", + destination: "/new-booker/d/:link/:slug", + has: [{ type: "header", key: "new-booker-enabled" }], + }, + + /** + * Enables new booker using cookie. It works even if NEW_BOOKER_ENABLED_FOR_NON_EMBED, NEW_BOOKER_ENABLED_FOR_EMBED are disabled + */ { source: `/:user((?!${pages.join("|")}).*)/:type`, destination: "/new-booker/:user/:type", diff --git a/turbo.json b/turbo.json index 3230ff6534..e8696b66c2 100644 --- a/turbo.json +++ b/turbo.json @@ -210,6 +210,8 @@ "LARK_OPEN_VERIFICATION_TOKEN", "MS_GRAPH_CLIENT_ID", "MS_GRAPH_CLIENT_SECRET", + "NEW_BOOKER_ENABLED_FOR_EMBED", + "NEW_BOOKER_ENABLED_FOR_NON_EMBED", "NEXT_PUBLIC_API_URL", "NEXT_PUBLIC_APP_NAME", "NEXT_PUBLIC_COMPANY_NAME",