Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: subscription store (#491)
ecmadao6fca3e0f2f43
diff --git a/frontend/src/components/PricingTable.vue b/frontend/src/components/PricingTable.vueindex f9f872e70c..840d1437f9 100644--- a/frontend/src/components/PricingTable.vue+++ b/frontend/src/components/PricingTable.vue@@ -102,7 +102,7 @@<script lang="ts">import { reactive, computed, PropType } from "vue";-import { Plan, License, PlanType } from "../types";+import { Plan, Subscription, PlanType } from "../types";import {FEATURE_SECTIONS,FREE_PLAN,@@ -125,10 +125,10 @@ interface LocalPlan extends Plan {export default {name: "PricingTable",props: {- license: {+ subscription: {required: false,default: undefined,- type: Object as PropType<License>,+ type: Object as PropType<Subscription>,},},setup(props) {@@ -160,7 +160,7 @@ export default {const getButtonText = (plan: Plan): string => {if (plan.type === PlanType.FREE) return "Deploy";if (plan.type === PlanType.ENTERPRISE) return "Contact us";- if (plan.type === props.license?.plan) return "Current plan";+ if (plan.type === props.subscription?.plan) return "Current plan";if (plan.trialDays && plan.trialPrice) {return `Start trial with $${plan.trialPrice} for ${plan.trialDays} days`;}diff --git a/frontend/src/store/modules/plan.ts b/frontend/src/store/modules/plan.tsindex 368d874fde..dc45e2d4b2 100644--- a/frontend/src/store/modules/plan.ts+++ b/frontend/src/store/modules/plan.ts@@ -5,8 +5,8 @@ import { Plan, FeatureType, PlanPatch, PlanState, PlanType } from "../../types";// Make sure this is consistent with the matrix in plan.go//// TODO: fetch the matrix from the backend instead of duplicating it here or use a JSON/YAML file-// so that it can be shared between frontend/backend.-const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([+// so that it can be shared between frontend/backend.+export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([// Change Workflow["bb.feature.backward-compatibility", [false, true, true]],["bb.feature.schema-drift", [false, true, true]],@@ -164,9 +164,9 @@ const getters = {feature:(state: PlanState, getters: any) =>- (type: FeatureType): boolean => {- return FEATURE_MATRIX.get(type)![getters["currentPlan"]()];- },+ (type: FeatureType): boolean => {+ return FEATURE_MATRIX.get(type)![getters["currentPlan"]()];+ },};const actions = {diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.tsnew file mode 100644index 0000000000..4c763c7275--- /dev/null+++ b/frontend/src/store/modules/subscription.ts@@ -0,0 +1,86 @@+import axios from "axios";+import {+ Subscription,+ FeatureType,+ PlanType,+ SubscriptionState,+} from "../../types";+import { FEATURE_MATRIX } from "./plan";++const state: () => SubscriptionState = () => ({+ subscription: undefined,+});++const getters = {+ subscription: (state: SubscriptionState) => (): Subscription | undefined => {+ return state.subscription;+ },++ currentPlan: (state: SubscriptionState) => (): PlanType => {+ // TODO: this is used for align with current logic - TEAM plan is default plan+ return state.subscription?.plan ?? PlanType.TEAM;+ },++ feature:+ (state: SubscriptionState, getters: any) =>+ (type: FeatureType): boolean => {+ return FEATURE_MATRIX.get(type)![getters["currentPlan"]()];+ },+};++const actions = {+ async fetchSubscription({ commit }: any): Promise<Subscription | undefined> {+ try {+ const data = (await axios.get(`/api/subscription`)).data.data;+ const subscription = data.attributes;+ commit("setSubscription", subscription);+ return subscription;+ } catch (e) {+ console.error(e);+ }+ },++ async patchSubscription(+ { commit }: any,+ license: string+ ): Promise<Subscription | undefined> {+ const data = (+ await axios.patch(`/api/subscription`, {+ data: {+ type: "SubscriptionPatch",+ attributes: {+ license,+ },+ },+ })+ ).data.data;+ const subscription = data.attributes;+ commit("setSubscription", subscription);+ return subscription;+ },++ // TODO: this is a mock function, should remove this before GA+ async changePlan({ commit }: any, newPlan: PlanType) {+ const subscription: Subscription = {+ instanceCount: 5,+ plan: newPlan,+ expiresTs: new Date().getTime() / 1000 + 24 * 60 * 60,+ };+ console.debug(`set subscription: ${JSON.stringify(subscription)}`);+ commit("setSubscription", subscription);+ },+};++const mutations = {+ setSubscription(state: SubscriptionState, subscription: Subscription) {+ state.subscription = subscription;+ },+};++export default {+ namespaced: true,+ state,+ getters,+ actions,+ mutations,+};diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 02e8a0e0be..0655ff301c 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -37,4 +37,4 @@ export * from "./label";export * from "./deployment";export * from "./sqlEditor";export * from "./editorSelector";-export * from "./license";+export * from "./subscription";diff --git a/frontend/src/types/license.ts b/frontend/src/types/license.tsdeleted file mode 100644index e3e6b6f158..0000000000--- a/frontend/src/types/license.ts+++ /dev/null@@ -1,8 +0,0 @@-import { PlanType } from "./plan";--export interface License {- audience: string;- instanceCount: number;- expiresTs: number;- plan: PlanType;-}diff --git a/frontend/src/types/subscription.ts b/frontend/src/types/subscription.tsnew file mode 100644index 0000000000..a7923327e5--- /dev/null+++ b/frontend/src/types/subscription.ts@@ -0,0 +1,11 @@+import { PlanType } from "./plan";++export interface Subscription {+ instanceCount: number;+ expiresTs: number;+ plan: PlanType;+}++export interface SubscriptionState {+ subscription: Subscription | undefined;+}