@@ -116,26 +116,60 @@ export function getInheritorRoles(targetRole: string): string[] {
116116 * Supabase-compatible tier configuration
117117 */
118118export interface TierConfig {
119- maxRequests : number
119+ // Backwards-compatible: maxRequests remains for legacy callers
120+ maxRequests ?: number
121+ // Explicit quotas used throughout services
122+ maxDocuments : number
123+ maxApiRequestsPerDay : number
124+ maxUsersPerTenant : number
120125 features : string [ ]
121126 rlsPolicy : string
127+ supportLevel ?: 'community' | 'email' | 'priority' | 'phone_24x7'
128+ customIntegrations ?: boolean
129+ advancedAnalytics ?: boolean
130+ whiteLabel ?: boolean
131+ onPremise ?: boolean
122132}
123133
124134export const TIER_CONFIGS : Record < SubscriptionTier , TierConfig > = {
125135 free : {
126136 maxRequests : 100 ,
137+ maxDocuments : 250 ,
138+ maxApiRequestsPerDay : 100 ,
139+ maxUsersPerTenant : 1 ,
127140 features : [ 'basic-chat' , 'public-docs' ] ,
128141 rlsPolicy : RLS_POLICIES . publicRead ,
142+ supportLevel : 'community' ,
143+ customIntegrations : false ,
144+ advancedAnalytics : false ,
145+ whiteLabel : false ,
146+ onPremise : false ,
129147 } ,
130148 pro : {
131149 maxRequests : 10000 ,
150+ maxDocuments : 10000 ,
151+ maxApiRequestsPerDay : 10000 ,
152+ maxUsersPerTenant : 100 ,
132153 features : [ 'advanced-chat' , 'private-docs' , 'api-access' ] ,
133154 rlsPolicy : RLS_POLICIES . proFeatures ,
155+ supportLevel : 'email' ,
156+ customIntegrations : true ,
157+ advancedAnalytics : true ,
158+ whiteLabel : false ,
159+ onPremise : false ,
134160 } ,
135161 enterprise : {
136162 maxRequests : - 1 , // unlimited
163+ maxDocuments : - 1 ,
164+ maxApiRequestsPerDay : - 1 ,
165+ maxUsersPerTenant : - 1 ,
137166 features : [ 'unlimited-chat' , 'all-docs' , 'custom-models' , 'admin-panel' ] ,
138167 rlsPolicy : RLS_POLICIES . enterpriseFeatures ,
168+ supportLevel : 'priority' ,
169+ customIntegrations : true ,
170+ advancedAnalytics : true ,
171+ whiteLabel : true ,
172+ onPremise : true ,
139173 } ,
140174}
141175
@@ -146,13 +180,40 @@ export function getTierConfig(tier: SubscriptionTier): TierConfig {
146180 return TIER_CONFIGS [ tier ]
147181}
148182
183+ /**
184+ * Backwards-compatible tier quota accessor used by services
185+ */
186+ export function getTierQuota ( tier : SubscriptionTier ) : {
187+ maxDocuments : number
188+ maxApiRequestsPerDay : number
189+ maxUsersPerTenant : number
190+ features : string [ ]
191+ rlsPolicy : string
192+ } {
193+ const cfg = getTierConfig ( tier )
194+ return {
195+ maxDocuments : cfg . maxDocuments ,
196+ maxApiRequestsPerDay : cfg . maxApiRequestsPerDay ,
197+ maxUsersPerTenant : cfg . maxUsersPerTenant ,
198+ features : cfg . features ,
199+ rlsPolicy : cfg . rlsPolicy ,
200+ }
201+ }
202+
149203/**
150204 * Check if a feature is available in a tier
151205 */
152206export function hasFeature ( tier : SubscriptionTier , feature : string ) : boolean {
153207 return TIER_CONFIGS [ tier ] . features . includes ( feature )
154208}
155209
210+ /**
211+ * Backwards-compatible feature check
212+ */
213+ export function isTierFeatureEnabled ( tier : SubscriptionTier , feature : string ) {
214+ return hasFeature ( tier , feature )
215+ }
216+
156217/**
157218 * Get the minimum tier required for a role
158219 */
@@ -169,6 +230,24 @@ export function getTierForRole(role: string): SubscriptionTier {
169230 return 'free'
170231}
171232
233+ /**
234+ * Minimum tier required for a given classification level
235+ */
236+ export function getMinimumTierForClassification (
237+ classification : 'public' | 'internal' | 'confidential'
238+ ) : SubscriptionTier {
239+ switch ( classification ) {
240+ case 'public' :
241+ return 'free'
242+ case 'internal' :
243+ return 'pro'
244+ case 'confidential' :
245+ return 'enterprise'
246+ default :
247+ return 'free'
248+ }
249+ }
250+
172251/**
173252 * Supabase RLS Policy Generator
174253 * Returns the appropriate policy for a given role
0 commit comments