2023-04-24 20:31:48 +12:00
|
|
|
import {
|
|
|
|
Billing,
|
|
|
|
Customer,
|
|
|
|
Feature,
|
|
|
|
License,
|
|
|
|
PlanModel,
|
|
|
|
PlanType,
|
|
|
|
PriceDuration,
|
|
|
|
PurchasedPlan,
|
2023-04-28 22:12:04 +12:00
|
|
|
PurchasedPrice,
|
2023-04-24 20:31:48 +12:00
|
|
|
Quotas,
|
|
|
|
Subscription,
|
|
|
|
} from "@budibase/types"
|
2022-10-07 04:03:47 +13:00
|
|
|
|
2023-04-28 22:12:04 +12:00
|
|
|
export function price(): PurchasedPrice {
|
|
|
|
return {
|
|
|
|
amount: 10000,
|
|
|
|
amountMonthly: 10000,
|
|
|
|
currency: "usd",
|
|
|
|
duration: PriceDuration.MONTHLY,
|
|
|
|
priceId: "price_123",
|
|
|
|
dayPasses: undefined,
|
|
|
|
isPerUser: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-24 20:31:48 +12:00
|
|
|
export const plan = (type: PlanType = PlanType.FREE): PurchasedPlan => {
|
2022-10-07 04:03:47 +13:00
|
|
|
return {
|
|
|
|
type,
|
2023-04-24 20:31:48 +12:00
|
|
|
usesInvoicing: false,
|
|
|
|
model: PlanModel.PER_USER,
|
2023-05-03 07:08:51 +12:00
|
|
|
price: type !== PlanType.FREE ? price() : undefined,
|
2022-10-07 04:03:47 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-24 20:31:48 +12:00
|
|
|
export function quotas(): Quotas {
|
2022-10-07 04:03:47 +13:00
|
|
|
return {
|
2023-04-24 20:31:48 +12:00
|
|
|
usage: {
|
|
|
|
monthly: {
|
|
|
|
queries: {
|
|
|
|
name: "Queries",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
automations: {
|
|
|
|
name: "Queries",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
dayPasses: {
|
|
|
|
name: "Queries",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
static: {
|
|
|
|
rows: {
|
|
|
|
name: "Rows",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
apps: {
|
|
|
|
name: "Apps",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
users: {
|
|
|
|
name: "Users",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
userGroups: {
|
|
|
|
name: "User Groups",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
name: "Plugins",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
constant: {
|
|
|
|
automationLogRetentionDays: {
|
|
|
|
name: "Automation Logs",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
appBackupRetentionDays: {
|
|
|
|
name: "Backups",
|
|
|
|
value: 1,
|
|
|
|
triggers: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function billing(
|
|
|
|
opts: { customer?: Customer; subscription?: Subscription } = {}
|
|
|
|
): Billing {
|
|
|
|
return {
|
|
|
|
customer: opts.customer || customer(),
|
|
|
|
subscription: opts.subscription || subscription(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function customer(): Customer {
|
|
|
|
return {
|
|
|
|
balance: 0,
|
|
|
|
currency: "usd",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function subscription(): Subscription {
|
|
|
|
return {
|
|
|
|
amount: 10000,
|
|
|
|
cancelAt: undefined,
|
|
|
|
currency: "usd",
|
|
|
|
currentPeriodEnd: 0,
|
|
|
|
currentPeriodStart: 0,
|
|
|
|
downgradeAt: 0,
|
|
|
|
duration: PriceDuration.MONTHLY,
|
|
|
|
pastDueAt: undefined,
|
|
|
|
quantity: 0,
|
|
|
|
status: "active",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const license = (
|
|
|
|
opts: {
|
|
|
|
quotas?: Quotas
|
|
|
|
plan?: PurchasedPlan
|
|
|
|
planType?: PlanType
|
|
|
|
features?: Feature[]
|
|
|
|
billing?: Billing
|
|
|
|
} = {}
|
|
|
|
): License => {
|
|
|
|
return {
|
|
|
|
features: opts.features || [],
|
|
|
|
quotas: opts.quotas || quotas(),
|
|
|
|
plan: opts.plan || plan(opts.planType),
|
|
|
|
billing: opts.billing || billing(),
|
2022-10-07 04:03:47 +13:00
|
|
|
}
|
|
|
|
}
|