diff --git a/packages/components/src/api/session/GetSessionInfo.ts b/packages/components/src/api/session/GetSessionInfo.ts index 1b9d8ea1a8..f9bade4f3c 100644 --- a/packages/components/src/api/session/GetSessionInfo.ts +++ b/packages/components/src/api/session/GetSessionInfo.ts @@ -18,6 +18,9 @@ export interface UserInfo { display_name: string, email_gravatar_hash: string, + // Rollout feature flags + can_access_studio: boolean, + // Usage can_use_tts: boolean, can_use_w2l: boolean, diff --git a/packages/components/src/session/SessionWrapper.ts b/packages/components/src/session/SessionWrapper.ts index 0e9cc9c14e..33b8c5d2e6 100644 --- a/packages/components/src/session/SessionWrapper.ts +++ b/packages/components/src/session/SessionWrapper.ts @@ -1,4 +1,5 @@ import { GetSessionInfo, GetSessionInfoIsOk, SessionInfoSuccessResponse } from '../api/session/GetSessionInfo' +import { StudioRolloutHostnameAllowed } from '../utils/StudioRolloutHostnameAllowed'; // A lot of the APIs return null or leave values absent. // I need to pick a single strategy and stick with it. @@ -44,6 +45,14 @@ export class SessionWrapper { return this.sessionStateResponse?.logged_in || false; } + // Feature flag rollout for Storyteller Studio + // This depends on the domain name and the backend. + public canAccessStudio() : boolean { + const hostnameAllowed = StudioRolloutHostnameAllowed(); + const userAllowed = this.sessionStateResponse?.user?.can_access_studio || false; + return hostnameAllowed && userAllowed; + } + // Username is all lowercase public getUsername() : string | undefined { return this.sessionStateResponse?.user?.username; diff --git a/packages/components/src/utils/StudioRolloutHostnameAllowed.ts b/packages/components/src/utils/StudioRolloutHostnameAllowed.ts new file mode 100644 index 0000000000..e98bfd83b9 --- /dev/null +++ b/packages/components/src/utils/StudioRolloutHostnameAllowed.ts @@ -0,0 +1,19 @@ + +// Check if hostname is allowed to display studio features. +// This should allow more frequently landing against production. +export function StudioRolloutHostnameAllowed() : boolean { + const allowed = StudioRolloutHostnameCheck(); + return allowed; +} + +function StudioRolloutHostnameCheck() : boolean { + // Do not allow "production" or "staging" domains to use studio yet. + // Other domains (local development and feature branches) are allowed. + switch (window.location.hostname) { + case 'fakeyou.com': + case 'storyteller.ai': + return false; + default: + return true; + } +}