1
0
Fork 0
mirror of synced 2024-09-19 02:39:37 +12:00
budibase/packages/backend-core/tests/core/utilities/mocks/licenses.ts

108 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Feature, License, Quotas } from "@budibase/types"
2023-07-25 22:45:19 +12:00
import cloneDeep from "lodash/cloneDeep"
let CLOUD_FREE_LICENSE: License
2022-12-15 10:48:48 +13:00
let UNLIMITED_LICENSE: License
let getCachedLicense: any
// init for the packages other than pro
export function init(proPkg: any) {
initInternal({
CLOUD_FREE_LICENSE: proPkg.constants.licenses.CLOUD_FREE_LICENSE,
2022-12-15 10:48:48 +13:00
UNLIMITED_LICENSE: proPkg.constants.licenses.UNLIMITED_LICENSE,
getCachedLicense: proPkg.licensing.cache.getCachedLicense,
})
}
// init for the pro package
export function initInternal(opts: {
CLOUD_FREE_LICENSE: License
2022-12-15 10:48:48 +13:00
UNLIMITED_LICENSE: License
getCachedLicense: any
}) {
CLOUD_FREE_LICENSE = opts.CLOUD_FREE_LICENSE
2022-12-15 10:48:48 +13:00
UNLIMITED_LICENSE = opts.UNLIMITED_LICENSE
getCachedLicense = opts.getCachedLicense
}
export interface UseLicenseOpts {
features?: Feature[]
quotas?: Quotas
}
// LICENSES
export const useLicense = (license: License, opts?: UseLicenseOpts) => {
if (opts) {
if (opts.features) {
license.features.push(...opts.features)
}
if (opts.quotas) {
license.quotas = opts.quotas
}
}
getCachedLicense.mockReturnValue(license)
return license
}
export const useUnlimited = (opts?: UseLicenseOpts) => {
2022-12-15 10:48:48 +13:00
return useLicense(UNLIMITED_LICENSE, opts)
}
export const useCloudFree = () => {
return useLicense(CLOUD_FREE_LICENSE)
}
// FEATURES
const useFeature = (feature: Feature) => {
2023-07-25 22:45:19 +12:00
const license = cloneDeep(UNLIMITED_LICENSE)
const opts: UseLicenseOpts = {
features: [feature],
}
return useLicense(license, opts)
}
export const useBackups = () => {
return useFeature(Feature.APP_BACKUPS)
}
export const useEnforceableSSO = () => {
return useFeature(Feature.ENFORCEABLE_SSO)
}
export const useGroups = () => {
return useFeature(Feature.USER_GROUPS)
}
2023-02-01 04:27:16 +13:00
export const useEnvironmentVariables = () => {
return useFeature(Feature.ENVIRONMENT_VARIABLES)
}
export const useAuditLogs = () => {
return useFeature(Feature.AUDIT_LOGS)
}
2023-03-14 04:34:08 +13:00
export const useScimIntegration = () => {
2023-03-21 05:12:55 +13:00
return useFeature(Feature.SCIM)
2023-03-14 04:34:08 +13:00
}
2023-05-19 21:07:02 +12:00
export const useSyncAutomations = () => {
return useFeature(Feature.SYNC_AUTOMATIONS)
2023-05-13 02:57:34 +12:00
}
export const useAppBuilders = () => {
return useFeature(Feature.APP_BUILDERS)
}
// QUOTAS
export const setAutomationLogsQuota = (value: number) => {
2023-07-25 22:45:19 +12:00
const license = cloneDeep(UNLIMITED_LICENSE)
license.quotas.constant.automationLogRetentionDays.value = value
return useLicense(license)
}