offline license structure

This commit is contained in:
Rory Powell 2023-07-13 21:53:05 +01:00
parent 7c4fe15781
commit 052a74f1d7
1 changed files with 25 additions and 8 deletions

View File

@ -2,7 +2,7 @@ import {
Billing, Billing,
Customer, Customer,
Feature, Feature,
License, License, OfflineLicense,
PlanModel, PlanModel,
PlanType, PlanType,
PriceDuration, PriceDuration,
@ -11,6 +11,7 @@ import {
Quotas, Quotas,
Subscription, Subscription,
} from "@budibase/types" } from "@budibase/types"
import { generator } from "./generator"
export function price(): PurchasedPrice { export function price(): PurchasedPrice {
return { return {
@ -127,14 +128,16 @@ export function subscription(): Subscription {
} }
} }
interface GenerateLicenseOpts {
quotas?: Quotas
plan?: PurchasedPlan
planType?: PlanType
features?: Feature[]
billing?: Billing
}
export const license = ( export const license = (
opts: { opts: GenerateLicenseOpts = {}
quotas?: Quotas
plan?: PurchasedPlan
planType?: PlanType
features?: Feature[]
billing?: Billing
} = {}
): License => { ): License => {
return { return {
features: opts.features || [], features: opts.features || [],
@ -143,3 +146,17 @@ export const license = (
billing: opts.billing || billing(), billing: opts.billing || billing(),
} }
} }
export function offlineLicense (
opts: GenerateLicenseOpts = {}
): OfflineLicense {
const base = license(opts)
return {
...base,
expireAt: new Date().toISOString(),
identifier: {
installId: generator.guid(),
tenantId: generator.guid()
}
}
}