import type { Observable , Subscription } from 'rxjs' ; import type { ILicense } from '../../../licensing/common/types' ; export interface SpacesLicense { isEnabled ( ) : boolean ; } interface SetupDeps { license$ : Observable < ILicense > ; } export class SpacesLicenseService { private licenseSubscription ? : Subscription ; public setup ( { license$ } ) { let rawLicense ; this . licenseSubscription = license$ . subscribe ( ( nextRawLicense ) => { rawLicense = nextRawLicense ; } ) ; return { license : Object . freeze ( { isEnabled : ( ) => this . isSpacesEnabledFromRawLicense ( rawLicense ) , } ) , } ; } public stop ( ) { if ( this . licenseSubscription ) { this . licenseSubscription . unsubscribe ( ) ; this . licenseSubscription = undefined ; } } private isSpacesEnabledFromRawLicense ( rawLicense ) { if ( ! rawLicense || ! rawLicense . isAvailable ) { return false ; } const licenseCheck = rawLicense . check ( 'spaces' , 'basic' ) ; return licenseCheck . state !== 'unavailable' && licenseCheck . state !== 'invalid' ; } }