From f984a169428058788b0b76c0e513e8c62e75ca61 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 20 Sep 2022 08:02:14 +0100 Subject: [PATCH] Add enterprise types and change from @budibase/pro to @budibase/types for licensing types --- .../migrations/functions/usageQuotas/syncApps.ts | 3 ++- .../migrations/functions/usageQuotas/syncRows.ts | 3 ++- .../functions/usageQuotas/tests/syncApps.spec.ts | 3 ++- .../functions/usageQuotas/tests/syncRows.spec.ts | 3 ++- packages/types/src/documents/account/account.ts | 9 ++++++++- packages/types/src/documents/global/index.ts | 1 + packages/types/src/documents/global/quotas.ts | 15 +++++++++++++++ packages/types/src/sdk/licensing/billing.ts | 3 +++ packages/types/src/sdk/licensing/plan.ts | 1 + packages/types/src/sdk/licensing/quota.ts | 5 +++-- 10 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 packages/types/src/documents/global/quotas.ts diff --git a/packages/server/src/migrations/functions/usageQuotas/syncApps.ts b/packages/server/src/migrations/functions/usageQuotas/syncApps.ts index 24e4c21969..4770844a99 100644 --- a/packages/server/src/migrations/functions/usageQuotas/syncApps.ts +++ b/packages/server/src/migrations/functions/usageQuotas/syncApps.ts @@ -1,6 +1,7 @@ import { getTenantId } from "@budibase/backend-core/tenancy" import { getAllApps } from "@budibase/backend-core/db" -import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro" +import { quotas } from "@budibase/pro" +import { QuotaUsageType, StaticQuotaName } from "@budibase/types" export const run = async () => { // get app count diff --git a/packages/server/src/migrations/functions/usageQuotas/syncRows.ts b/packages/server/src/migrations/functions/usageQuotas/syncRows.ts index b92d880f7a..540ea6e819 100644 --- a/packages/server/src/migrations/functions/usageQuotas/syncRows.ts +++ b/packages/server/src/migrations/functions/usageQuotas/syncRows.ts @@ -1,7 +1,8 @@ import { getTenantId } from "@budibase/backend-core/tenancy" import { getAllApps } from "@budibase/backend-core/db" import { getUniqueRows } from "../../../utilities/usageQuota/rows" -import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro" +import { quotas } from "@budibase/pro" +import { QuotaUsageType, StaticQuotaName } from "@budibase/types" export const run = async () => { // get all rows in all apps diff --git a/packages/server/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts b/packages/server/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts index dbc978b9bd..d0d50395b2 100644 --- a/packages/server/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +++ b/packages/server/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts @@ -1,6 +1,7 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration" import * as syncApps from "../syncApps" -import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro" +import { quotas } from "@budibase/pro" +import { QuotaUsageType, StaticQuotaName } from "@budibase/types" describe("syncApps", () => { let config = new TestConfig(false) diff --git a/packages/server/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts b/packages/server/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts index 851deb5417..b403179958 100644 --- a/packages/server/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +++ b/packages/server/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts @@ -1,6 +1,7 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration" import * as syncRows from "../syncRows" -import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro" +import { quotas } from "@budibase/pro" +import { QuotaUsageType, StaticQuotaName } from "@budibase/types" describe("syncRows", () => { let config = new TestConfig(false) diff --git a/packages/types/src/documents/account/account.ts b/packages/types/src/documents/account/account.ts index 33c96033a0..2f7767ca36 100644 --- a/packages/types/src/documents/account/account.ts +++ b/packages/types/src/documents/account/account.ts @@ -1,4 +1,4 @@ -import { Hosting } from "../../sdk" +import { Feature, Hosting, PlanType, Quotas } from "../../sdk" export interface CreateAccount { email: string @@ -22,6 +22,11 @@ export const isCreatePasswordAccount = ( account: CreateAccount ): account is CreatePassswordAccount => account.authType === AuthType.PASSWORD +export interface LicenseOverrides { + features?: Feature[] + quotas?: Quotas +} + export interface Account extends CreateAccount { // generated accountId: string @@ -31,9 +36,11 @@ export interface Account extends CreateAccount { verificationSent: boolean // licensing tier: string // deprecated + planType?: PlanType stripeCustomerId?: string licenseKey?: string licenseKeyActivatedAt?: number + licenseOverrides?: LicenseOverrides } export interface PasswordAccount extends Account { diff --git a/packages/types/src/documents/global/index.ts b/packages/types/src/documents/global/index.ts index 1f8bb4a84f..84684df369 100644 --- a/packages/types/src/documents/global/index.ts +++ b/packages/types/src/documents/global/index.ts @@ -2,3 +2,4 @@ export * from "./config" export * from "./user" export * from "./userGroup" export * from "./plugin" +export * from "./quotas" diff --git a/packages/types/src/documents/global/quotas.ts b/packages/types/src/documents/global/quotas.ts new file mode 100644 index 0000000000..b90c7e0ddb --- /dev/null +++ b/packages/types/src/documents/global/quotas.ts @@ -0,0 +1,15 @@ +import { MonthlyQuotaName, StaticQuotaName } from "../../sdk" + +export interface QuotaUsage { + _id: string + _rev?: string + quotaReset: string + usageQuota: { + [key in StaticQuotaName]: number + } + monthly: { + [key: string]: { + [key in MonthlyQuotaName]: number + } + } +} diff --git a/packages/types/src/sdk/licensing/billing.ts b/packages/types/src/sdk/licensing/billing.ts index da2aca1615..d4365525db 100644 --- a/packages/types/src/sdk/licensing/billing.ts +++ b/packages/types/src/sdk/licensing/billing.ts @@ -12,6 +12,9 @@ export interface Subscription { cancelAt: number | null | undefined currentPeriodStart: number currentPeriodEnd: number + status: string + pastDueAt?: number | null + downgradeAt?: number } export interface Billing { diff --git a/packages/types/src/sdk/licensing/plan.ts b/packages/types/src/sdk/licensing/plan.ts index 6b226887b4..b370397534 100644 --- a/packages/types/src/sdk/licensing/plan.ts +++ b/packages/types/src/sdk/licensing/plan.ts @@ -6,6 +6,7 @@ export interface AccountPlan { export enum PlanType { FREE = "free", PRO = "pro", + TEAM = "team", BUSINESS = "business", ENTERPRISE = "enterprise", } diff --git a/packages/types/src/sdk/licensing/quota.ts b/packages/types/src/sdk/licensing/quota.ts index 578a5d98d0..fcf2685e88 100644 --- a/packages/types/src/sdk/licensing/quota.ts +++ b/packages/types/src/sdk/licensing/quota.ts @@ -13,6 +13,7 @@ export enum QuotaType { export enum StaticQuotaName { ROWS = "rows", APPS = "apps", + USER_GROUPS = "userGroups", } export enum MonthlyQuotaName { @@ -22,7 +23,6 @@ export enum MonthlyQuotaName { } export enum ConstantQuotaName { - QUERY_TIMEOUT_SECONDS = "queryTimeoutSeconds", AUTOMATION_LOG_RETENTION_DAYS = "automationLogRetentionDays", } @@ -54,6 +54,7 @@ export const isConstantQuota = ( export type PlanQuotas = { [PlanType.FREE]: Quotas [PlanType.PRO]: Quotas + [PlanType.TEAM]: Quotas [PlanType.BUSINESS]: Quotas [PlanType.ENTERPRISE]: Quotas } @@ -68,10 +69,10 @@ export type Quotas = { [QuotaUsageType.STATIC]: { [StaticQuotaName.ROWS]: Quota [StaticQuotaName.APPS]: Quota + [StaticQuotaName.USER_GROUPS]: Quota } } [QuotaType.CONSTANT]: { - [ConstantQuotaName.QUERY_TIMEOUT_SECONDS]: Quota [ConstantQuotaName.AUTOMATION_LOG_RETENTION_DAYS]: Quota } }