import { distributionPlan, hasPlan, type Plan, proPlan } from '../plans.js'; import type { AppEntitlementContext } from './context.js'; export type FeatureId = | 'analytics' | 'application_groups' | 'artifact_configurations' | 'custom_domain' | 'nsis_web_installer'; export interface EntitlementFeatureDefinition { description: string; hasAccess: (context: AppEntitlementContext) => boolean; id: FeatureId; label: string; plan: Plan; } export interface EntitlementFeatureAccess { description: string; hasAccess: boolean; id: FeatureId; label: string; plan: Plan; } export const entitlementFeatures: Record< FeatureId, EntitlementFeatureDefinition > = { analytics: { description: 'Track monthly customer downloads and application releases.', hasAccess: ({ effectiveSubscription }) => hasPlan(proPlan, effectiveSubscription), id: 'analytics', label: 'Analytics', plan: proPlan, }, application_groups: { description: 'Create staging and testing apps that inherit subscription-backed access from a parent app.', hasAccess: ({ childAppLimit }) => childAppLimit > 0, id: 'application_groups', label: 'Application groups', plan: proPlan, }, artifact_configurations: { description: 'Distribute your application via Mac ZIP, Windows MSI, Linux Debian and more.', hasAccess: ({ effectiveSubscription }) => hasPlan(distributionPlan, effectiveSubscription), id: 'artifact_configurations', label: 'Build artifacts', plan: distributionPlan, }, custom_domain: { description: 'Serve your application downloads from a custom domain of your choice.', hasAccess: ({ effectiveSubscription }) => hasPlan(distributionPlan, effectiveSubscription), id: 'custom_domain', label: 'Custom domain', plan: distributionPlan, }, nsis_web_installer: { description: 'Create a lightweight Windows NSIS Web installer for your application.', hasAccess: ({ effectiveSubscription }) => hasPlan(proPlan, effectiveSubscription), id: 'nsis_web_installer', label: 'NSIS Web installer', plan: proPlan, }, }; export function getAllFeatureAccess( context: AppEntitlementContext, ): EntitlementFeatureAccess[] { return Object.values(entitlementFeatures).map((definition) => ({ description: definition.description, hasAccess: definition.hasAccess(context), id: definition.id, label: definition.label, plan: definition.plan, })); }