Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add trial attention banner (#665)

ecmadaoa310fccd5654
diff --git a/enterprise/api/license.go b/enterprise/api/license.go
index dae41195b9..775c8906fc 100644
--- a/enterprise/api/license.go
+++ b/enterprise/api/license.go
@@ -15,10 +15,12 @@ var validPlans = []api.PlanType{
// License is the API message for enterprise license.
type License struct {
- Audience string `jsonapi:"attr,audience"`
- InstanceCount int `jsonapi:"attr,instanceCount"`
- ExpiresTs int64 `jsonapi:"attr,expiresTs"`
- Plan api.PlanType `jsonapi:"attr,plan"`
+ Audience string
+ InstanceCount int
+ ExpiresTs int64
+ IssuedTs int64
+ Plan api.PlanType
+ Trialing bool
}
// Valid will check if license expired or has correct plan type.
diff --git a/enterprise/api/subscription.go b/enterprise/api/subscription.go
index 79f105ce03..5b631365d9 100644
--- a/enterprise/api/subscription.go
+++ b/enterprise/api/subscription.go
@@ -11,5 +11,7 @@ type SubscriptionPatch struct {
type Subscription struct {
InstanceCount int `jsonapi:"attr,instanceCount"`
ExpiresTs int64 `jsonapi:"attr,expiresTs"`
+ StartedTs int64 `jsonapi:"attr,startedTs"`
Plan api.PlanType `jsonapi:"attr,plan"`
+ Trialing bool `jsonapi:"attr,trialing"`
}
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index 9995704522..004f740536 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -96,6 +96,11 @@ func (s *LicenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
return nil, common.Errorf(common.Invalid, fmt.Errorf("exp is not valid, found '%v'", claims["exp"]))
}
+ iat, ok := claims["iat"].(float64)
+ if !ok {
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("iat is not valid, found '%v'", claims["iat"]))
+ }
+
verifyIssuer := claims.VerifyIssuer(s.config.Issuer, true)
if !verifyIssuer {
return nil, common.Errorf(common.Invalid, fmt.Errorf("iss is not valid, expect %s but found '%v'", s.config.Issuer, claims["iss"]))
@@ -111,6 +116,11 @@ func (s *LicenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
return nil, common.Errorf(common.Invalid, fmt.Errorf("plan is not valid, found '%v'", claims["plan"]))
}
+ trialing, ok := claims["trialing"].(bool)
+ if !ok {
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("trialing is not valid, found '%v'", claims["trialing"]))
+ }
+
planType, err := convertPlanType(plan)
if err != nil {
return nil, common.Errorf(common.Invalid, fmt.Errorf("plan type %q is not valid", planType))
@@ -124,8 +134,10 @@ func (s *LicenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
license := &enterpriseAPI.License{
InstanceCount: int(instance),
ExpiresTs: int64(exp),
+ IssuedTs: int64(iat),
Plan: planType,
Audience: aud,
+ Trialing: trialing,
}
if err := license.Valid(); err != nil {
diff --git a/frontend/src/components/PricingTable.vue b/frontend/src/components/PricingTable.vue
index db15d04ce1..4cc0ff0292 100644
--- a/frontend/src/components/PricingTable.vue
+++ b/frontend/src/components/PricingTable.vue
@@ -145,7 +145,7 @@
<td v-for="plan in plans" :key="plan.type" class="pt-5 px-6">
<a
v-if="!plan.isFreePlan"
- href="https://hub.bytebase.com"
+ href="https://hub.bytebase.com/pricing"
target="_blank"
class="block w-full py-4 bg-gray-800 border border-gray-800 rounded-md py-2 text-sm font-semibold text-white text-center hover:bg-gray-900"
>
@@ -265,7 +265,7 @@ export default {
const onButtonClick = (plan: Plan) => {
if (plan.type === PlanType.TEAM) {
- window.open("https://hub.bytebase.com/", "__blank");
+ window.open("https://hub.bytebase.com/pricing", "__blank");
} else if (plan.type === PlanType.ENTERPRISE) {
window.open(
"mailto:[email protected]?subject=Request for enterprise plan"
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index e43de04c4d..a5b38b7f04 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -3,6 +3,9 @@
<template v-if="isDemo">
<BannerDemo />
</template>
+ <template v-else-if="isNearTrialExpireTime">
+ <BannerTrial />
+ </template>
<template v-else-if="isReadonly">
<div
class="h-12 w-full text-lg font-medium bg-yellow-500 text-white flex justify-center items-center"
@@ -43,12 +46,18 @@ import { useStore } from "vuex";
import ProvideDashboardContext from "../components/ProvideDashboardContext.vue";
import DashboardHeader from "../views/DashboardHeader.vue";
import BannerDemo from "../views/BannerDemo.vue";
+import BannerTrial from "../views/BannerTrial.vue";
import { ServerInfo } from "../types";
import { computed } from "vue";
export default {
name: "DashboardLayout",
- components: { ProvideDashboardContext, DashboardHeader, BannerDemo },
+ components: {
+ ProvideDashboardContext,
+ DashboardHeader,
+ BannerDemo,
+ BannerTrial,
+ },
setup() {
const store = useStore();
@@ -63,6 +72,9 @@ export default {
};
const isDemo = computed(() => store.getters["actuator/isDemo"]());
+ const isNearTrialExpireTime = computed(() =>
+ store.getters["subscription/isNearTrialExpireTime"]()
+ );
const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
@@ -70,6 +82,7 @@ export default {
ping,
isDemo,
isReadonly,
+ isNearTrialExpireTime,
};
},
};
diff --git a/frontend/src/layouts/SqlEditorLayout.vue b/frontend/src/layouts/SqlEditorLayout.vue
index cb7d790f98..aa69254665 100644
--- a/frontend/src/layouts/SqlEditorLayout.vue
+++ b/frontend/src/layouts/SqlEditorLayout.vue
@@ -3,6 +3,9 @@
<template v-if="isDemo">
<BannerDemo />
</template>
+ <template v-else-if="isNearTrialExpireTime">
+ <BannerTrial />
+ </template>
<nav class="bg-white border-b border-block-border">
<div class="max-w-full mx-auto px-4">
@@ -38,6 +41,7 @@ import { computed } from "vue";
import ProvideSqlEditorContext from "@/components/ProvideSqlEditorContext.vue";
import EditorHeader from "@/views/SqlEditor/EditorHeader.vue";
import BannerDemo from "@/views/BannerDemo.vue";
+import BannerTrial from "@/views/BannerTrial.vue";
import { ServerInfo } from "../types";
const store = useStore();
@@ -54,5 +58,9 @@ const ping = () => {
const isDemo = computed(() => store.getters["actuator/isDemo"]());
+const isNearTrialExpireTime = computed(() =>
+ store.getters["subscription/isNearTrialExpireTime"]()
+);
+
const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
</script>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index b97e559745..7815a98078 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -221,6 +221,8 @@ task:
banner:
demo-intro: This is a demo version of Bytebase.
demo-intro-readonly: This is a demo version of Bytebase in read-only mode.
+ trial-expires: Your trial for {plan} plan will expires in {days} days.
+ extend-trial: Extend trialing time
action: Deploy yours in 5 seconds
intro:
content: >-
@@ -1176,6 +1178,7 @@ subscription:
cancel: cancel your subscription
announcement: You can upgrade, downgrade, or {cancel} anytime. No
hidden charges.
+ trialing: trialing
update:
success:
title: Successfully updated license
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index 581de78292..2cd0d6d004 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -218,6 +218,8 @@ task:
banner:
demo-intro: 这是 Bytebase 的演示版本。
demo-intro-readonly: 这是 Bytebase 的只读演示版本
+ trial-expires: 您的{plan}试用仅剩 {days} 天
+ extend-trial: 申请延长试用
action: 5 秒部署您自己的服务
intro:
content: >-
@@ -1044,6 +1046,7 @@ subscription:
buy: 购买{plan}
cancel: 取消订阅
announcement: 您可以随时升级、降级或{cancel}。没有任何隐藏费用。
+ trialing: 试用期
update:
success:
title: 证书更新成功
diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.ts
index 994d4b2fa2..b8bdfcf098 100644
--- a/frontend/src/store/modules/subscription.ts
+++ b/frontend/src/store/modules/subscription.ts
@@ -1,4 +1,5 @@
import axios from "axios";
+import dayjs from "dayjs";
import {
Subscription,
FeatureType,
@@ -25,6 +26,30 @@ const getters = {
(type: FeatureType): boolean => {
return FEATURE_MATRIX.get(type)![getters["currentPlan"]()];
},
+
+ nextPaymentDays: (state: SubscriptionState) => (): number => {
+ if (!state.subscription || state.subscription.expiresTs <= 0) {
+ return -1;
+ }
+
+ const expiresTime = dayjs(state.subscription.expiresTs * 1000);
+ return expiresTime.diff(new Date(), "day");
+ },
+
+ isNearTrialExpireTime:
+ (state: SubscriptionState, getters: any) => (): boolean => {
+ if (!state.subscription || !state.subscription?.trialing) return false;
+
+ const nextPaymentDays = getters["nextPaymentDays"]();
+ if (nextPaymentDays <= 0) return false;
+
+ const trialEndTime = dayjs(state.subscription.expiresTs * 1000);
+ const total = trialEndTime.diff(
+ state.subscription.startedTs * 1000,
+ "day"
+ );
+ return nextPaymentDays / total < 0.5;
+ },
};
const actions = {
diff --git a/frontend/src/types/subscription.ts b/frontend/src/types/subscription.ts
index a7923327e5..2dd6b0961b 100644
--- a/frontend/src/types/subscription.ts
+++ b/frontend/src/types/subscription.ts
@@ -3,7 +3,9 @@ import { PlanType } from "./plan";
export interface Subscription {
instanceCount: number;
expiresTs: number;
+ startedTs: number;
plan: PlanType;
+ trialing: boolean;
}
export interface SubscriptionState {
diff --git a/frontend/src/views/BannerTrial.vue b/frontend/src/views/BannerTrial.vue
new file mode 100644
index 0000000000..debb0b2d63
--- /dev/null
+++ b/frontend/src/views/BannerTrial.vue
@@ -0,0 +1,89 @@
+<template>
+ <div v-if="show" class="bg-accent">
+ <div class="mx-auto py-3 px-3">
+ <div class="flex items-center justify-between flex-wrap">
+ <div class="w-0 flex-1 flex items-center">
+ <p class="ml-3 font-medium text-white truncate">
+ <span>
+ {{
+ $t("banner.trial-expires", {
+ plan: currentPlan,
+ days: nextPaymentDays,
+ })
+ }}
+ </span>
+ </p>
+ </div>
+ <div
+ class="order-3 mt-2 flex-shrink-0 w-full sm:order-2 sm:mt-0 sm:w-auto"
+ >
+ <a
+ :href="extendTrialingEmail"
+ target="_self"
+ class="flex items-center justify-center p-2 border border-transparent rounded-md shadow-sm text-base font-medium text-accent bg-white hover:bg-indigo-50"
+ >
+ {{ $t("banner.extend-trial") }}
+ </a>
+ </div>
+ <div class="order-2 flex-shrink-0 sm:order-3 sm:ml-3">
+ <button
+ type="button"
+ class="-mr-1 flex p-2 rounded-md hover:bg-accent-hover focus:outline-none focus:ring-2 focus:ring-white sm:-mr-2"
+ @click.prevent="show = false"
+ >
+ <span class="sr-only">{{ $t("common.dismiss") }}</span>
+ <!-- Heroicon name: outline/x -->
+ <heroicons-outline:x class="h-6 w-6 text-white" />
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, ref } from "vue";
+import { useStore } from "vuex";
+import { useI18n } from "vue-i18n";
+import { PlanType } from "../types";
+
+export default {
+ name: "BannerTrial",
+ setup() {
+ const store = useStore();
+ const { t } = useI18n();
+ const show = ref(true);
+
+ const emailBody = [
+ "Hi bytebase support,\n",
+ "I request to extend the trialing time for another 14 days.",
+ "{please implement your reason to extend here}\n",
+ "My email in the bytebase hub account: {email}",
+ "My organization key: {orgKey}",
+ ].join("\n");
+
+ const currentPlan = computed((): string => {
+ const plan = store.getters["subscription/currentPlan"]();
+ switch (plan) {
+ case PlanType.TEAM:
+ return t("subscription.plan.team.title");
+ case PlanType.ENTERPRISE:
+ return t("subscription.plan.enterprise.title");
+ default:
+ return t("subscription.plan.free.title");
+ }
+ });
+
+ return {
+ show,
+ currentPlan,
+ nextPaymentDays: computed((): number =>
+ store.getters["subscription/nextPaymentDays"]()
+ ),
+ extendTrialingEmail: `mailto:[email protected]?subject=Request to extend trial&body=${encodeURIComponent(
+ emailBody
+ )}`,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/views/SettingWorkspaceSubscription.vue b/frontend/src/views/SettingWorkspaceSubscription.vue
index 210fd1d988..80338dc67f 100644
--- a/frontend/src/views/SettingWorkspaceSubscription.vue
+++ b/frontend/src/views/SettingWorkspaceSubscription.vue
@@ -2,7 +2,11 @@
<div class="mx-auto">
<div class="textinfolabel">
{{ $t("subscription.description") }}
- <a class="text-accent" href="https://hub.bytebase.com" target="__blank">
+ <a
+ class="text-accent"
+ href="https://hub.bytebase.com/pricing"
+ target="__blank"
+ >
{{ $t("subscription.description-highlight") }}
</a>
</div>
@@ -12,7 +16,15 @@
{{ $t("subscription.current") }}
</dt>
<dd class="text-indigo-600 mt-1 text-4xl">
- {{ currentPlan }}
+ <div class="flex items-center">
+ {{ currentPlan }}
+ <span
+ v-if="subscription.trialing"
+ class="ml-2 inline-flex items-center px-3 py-0.5 rounded-full text-base font-sm bg-indigo-100 text-indigo-800 h-6"
+ >
+ {{ $t("subscription.trialing") }}
+ </span>
+ </div>
</dd>
</div>
<div class="my-3">
@@ -44,7 +56,6 @@
'btn-primary inline-flex justify-center ml-auto mt-3',
]"
target="_blank"
- href="https://hub.bytebase.com"
@click="uploadLicense"
>
{{ $t("subscription.upload-license") }}
diff --git a/server/subscription.go b/server/subscription.go
index 293b79dab1..2b8fe88fdc 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -55,7 +55,9 @@ func (s *Server) loadSubscription() *enterpriseAPI.Subscription {
subscription = &enterpriseAPI.Subscription{
Plan: license.Plan,
ExpiresTs: license.ExpiresTs,
+ StartedTs: license.IssuedTs,
InstanceCount: license.InstanceCount,
+ Trialing: license.Trialing,
}
}