diff --git a/apps/web/config/base.json b/apps/web/config/base.json index b6a41c203e0..cab6fbe950f 100644 --- a/apps/web/config/base.json +++ b/apps/web/config/base.json @@ -9,5 +9,6 @@ "dev": { "port": 8080, "allowedHosts": "auto" - } + }, + "flags": {} } diff --git a/apps/web/config/cloud.json b/apps/web/config/cloud.json index 51f29a05f9d..ae1a7c2675a 100644 --- a/apps/web/config/cloud.json +++ b/apps/web/config/cloud.json @@ -13,5 +13,8 @@ "proxyApi": "https://api.bitwarden.com", "proxyIdentity": "https://identity.bitwarden.com", "proxyEvents": "https://events.bitwarden.com" + }, + "flags": { + "showTrial": false } } diff --git a/apps/web/config/development.json b/apps/web/config/development.json index 7554af381d9..7f89752955f 100644 --- a/apps/web/config/development.json +++ b/apps/web/config/development.json @@ -7,5 +7,8 @@ "proxyIdentity": "http://localhost:33656", "proxyEvents": "http://localhost:46273", "proxyNotifications": "http://localhost:61840" + }, + "flags": { + "showTrial": true } } diff --git a/apps/web/config/qa.json b/apps/web/config/qa.json index 189b94d2a35..badd53cbb0a 100644 --- a/apps/web/config/qa.json +++ b/apps/web/config/qa.json @@ -7,5 +7,8 @@ "proxyApi": "https://api.qa.bitwarden.pw", "proxyIdentity": "https://identity.qa.bitwarden.pw", "proxyEvents": "https://events.qa.bitwarden.pw" + }, + "flags": { + "showTrial": true } } diff --git a/apps/web/config/selfhosted.json b/apps/web/config/selfhosted.json index 208a355a85e..3ba61fda596 100644 --- a/apps/web/config/selfhosted.json +++ b/apps/web/config/selfhosted.json @@ -5,5 +5,8 @@ "proxyEvents": "http://localhost:46274", "proxyNotifications": "http://localhost:61841", "port": 8081 + }, + "flags": { + "showTrial": false } } diff --git a/apps/web/src/app/oss-routing.module.ts b/apps/web/src/app/oss-routing.module.ts index a98cbad1d2b..76501a16f49 100644 --- a/apps/web/src/app/oss-routing.module.ts +++ b/apps/web/src/app/oss-routing.module.ts @@ -1,10 +1,12 @@ import { NgModule } from "@angular/core"; -import { RouterModule, Routes } from "@angular/router"; +import { Route, RouterModule, Routes } from "@angular/router"; import { AuthGuard } from "@bitwarden/angular/guards/auth.guard"; import { LockGuard } from "@bitwarden/angular/guards/lock.guard"; import { UnauthGuard } from "@bitwarden/angular/guards/unauth.guard"; +import { flagEnabled, FlagName } from "../utils/flags"; + import { AcceptEmergencyComponent } from "./accounts/accept-emergency.component"; import { AcceptOrganizationComponent } from "./accounts/accept-organization.component"; import { HintComponent } from "./accounts/hint.component"; @@ -65,12 +67,12 @@ const routes: Routes = [ canActivate: [UnauthGuard], data: { titleId: "createAccount" }, }, - { + buildFlaggedRoute("showTrial", { path: "trial", component: TrialInitiationComponent, canActivate: [UnauthGuard], data: { titleId: "startTrial" }, - }, + }), { path: "sso", component: SsoComponent, @@ -258,3 +260,12 @@ const routes: Routes = [ exports: [RouterModule], }) export class OssRoutingModule {} + +export function buildFlaggedRoute(flagName: FlagName, route: Route): Route { + return flagEnabled(flagName) + ? route + : { + path: route.path, + redirectTo: "/", + }; +} diff --git a/apps/web/src/utils/flags.ts b/apps/web/src/utils/flags.ts new file mode 100644 index 00000000000..d6d9d0fe0be --- /dev/null +++ b/apps/web/src/utils/flags.ts @@ -0,0 +1,19 @@ +export type Flags = { + showTrial?: boolean; +}; + +export type FlagName = keyof Flags; + +export function flagEnabled(flag: FlagName): boolean { + return flags()[flag] == null || flags()[flag]; +} + +function flags(): Flags { + const envFlags = process.env.FLAGS as string | Flags; + + if (typeof envFlags === "string") { + return JSON.parse(envFlags) as Flags; + } else { + return envFlags as Flags; + } +} diff --git a/apps/web/webpack.config.js b/apps/web/webpack.config.js index 4aae92a2ebd..65caccc1cb4 100644 --- a/apps/web/webpack.config.js +++ b/apps/web/webpack.config.js @@ -151,6 +151,7 @@ const plugins = [ STRIPE_KEY: envConfig["stripeKey"] ?? "", BRAINTREE_KEY: envConfig["braintreeKey"] ?? "", PAYPAL_CONFIG: envConfig["paypal"] ?? {}, + FLAGS: envConfig["flags"] ?? {}, }), new webpack.ProvidePlugin({ process: "process/browser",