From 799b6b15d70e6af04eb2fe2ccf893dcf6ed67099 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 2 Jan 2025 16:11:15 +0000 Subject: [PATCH 1/3] Convert portal feature flags store to TS --- packages/builder/src/stores/portal/auth.ts | 6 +++--- .../builder/src/stores/portal/featureFlags.js | 16 ---------------- .../builder/src/stores/portal/featureFlags.ts | 19 +++++++++++++++++++ packages/types/src/api/web/global/self.ts | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 packages/builder/src/stores/portal/featureFlags.js create mode 100644 packages/builder/src/stores/portal/featureFlags.ts diff --git a/packages/builder/src/stores/portal/auth.ts b/packages/builder/src/stores/portal/auth.ts index afbb75646c1..171b2b43ae3 100644 --- a/packages/builder/src/stores/portal/auth.ts +++ b/packages/builder/src/stores/portal/auth.ts @@ -4,14 +4,14 @@ import { admin } from "@/stores/portal" import analytics from "@/analytics" import { BudiStore } from "@/stores/BudiStore" import { + GetGlobalSelfResponse, isSSOUser, SetInitInfoRequest, UpdateSelfRequest, - User, } from "@budibase/types" interface PortalAuthStore { - user?: User + user?: GetGlobalSelfResponse initInfo?: Record accountPortalAccess: boolean loaded: boolean @@ -33,7 +33,7 @@ class AuthStore extends BudiStore { }) } - setUser(user?: User) { + setUser(user?: GetGlobalSelfResponse) { this.set({ loaded: true, user: user, diff --git a/packages/builder/src/stores/portal/featureFlags.js b/packages/builder/src/stores/portal/featureFlags.js deleted file mode 100644 index ef1100310a6..00000000000 --- a/packages/builder/src/stores/portal/featureFlags.js +++ /dev/null @@ -1,16 +0,0 @@ -import { derived } from "svelte/store" -import { auth } from "@/stores/portal" - -export const INITIAL_FEATUREFLAG_STATE = { - SQS: false, - DEFAULT_VALUES: false, - BUDIBASE_AI: false, - AI_CUSTOM_CONFIGS: false, -} - -export const featureFlags = derived([auth], ([$auth]) => { - return { - ...INITIAL_FEATUREFLAG_STATE, - ...($auth?.user?.flags || {}), - } -}) diff --git a/packages/builder/src/stores/portal/featureFlags.ts b/packages/builder/src/stores/portal/featureFlags.ts new file mode 100644 index 00000000000..ac071f1169f --- /dev/null +++ b/packages/builder/src/stores/portal/featureFlags.ts @@ -0,0 +1,19 @@ +import { derived, Readable } from "svelte/store" +import { auth } from "@/stores/portal" + +export const INITIAL_FEATUREFLAG_STATE = { + SQS: false, + DEFAULT_VALUES: false, + BUDIBASE_AI: false, + AI_CUSTOM_CONFIGS: false, +} + +export const featureFlags: Readable> = derived( + [auth], + ([$auth]) => { + return { + ...INITIAL_FEATUREFLAG_STATE, + ...($auth?.user?.flags || {}), + } + } +) diff --git a/packages/types/src/api/web/global/self.ts b/packages/types/src/api/web/global/self.ts index 5f21a8ddc52..c478e89dd6b 100644 --- a/packages/types/src/api/web/global/self.ts +++ b/packages/types/src/api/web/global/self.ts @@ -8,5 +8,5 @@ export interface GenerateAPIKeyResponse extends DevInfo {} export interface FetchAPIKeyResponse extends DevInfo {} export interface GetGlobalSelfResponse extends User { - flags?: Record + flags?: Record } From 9f712eda71eba4c2bf6092e1cabfd38bf27e97c0 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Jan 2025 13:36:56 +0000 Subject: [PATCH 2/3] Revert pro change --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index ae786121d92..32d84f109d4 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit ae786121d923449b0ad5fcbd123d0a9fec28f65e +Subproject commit 32d84f109d4edc526145472a7446327312151442 From ab3bf05dfefe22520e8bedd601134ba6275f9710 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Jan 2025 13:37:55 +0000 Subject: [PATCH 3/3] Make store terser --- packages/builder/src/stores/portal/featureFlags.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/stores/portal/featureFlags.ts b/packages/builder/src/stores/portal/featureFlags.ts index ab0b178ab46..0e40d0c7b49 100644 --- a/packages/builder/src/stores/portal/featureFlags.ts +++ b/packages/builder/src/stores/portal/featureFlags.ts @@ -2,12 +2,7 @@ import { derived, Readable } from "svelte/store" import { auth } from "@/stores/portal" import { FeatureFlags, FeatureFlagDefaults } from "@budibase/types" -export const featureFlags: Readable = derived( - [auth], - ([$auth]) => { - return { - ...FeatureFlagDefaults, - ...($auth?.user?.flags || {}), - } - } -) +export const featureFlags: Readable = derived(auth, $auth => ({ + ...FeatureFlagDefaults, + ...($auth?.user?.flags || {}), +}))