import { ILicense , LicenseType } from '../../licensing/common/types' ; import { LicensingPluginSetup , LicensingPluginStart } from '../../licensing/public' ; import { APP_ID } from '../common/constants' ; export enum LICENSED_FEATURES { GEO_LINE_AGG = 'GEO_LINE_AGG' , GEO_SHAPE_AGGS_GEO_TILE = 'GEO_SHAPE_AGGS_GEO_TILE' , ON_PREM_EMS = 'ON_PREM_EMS' } export interface LicensedFeatureDetail { name : string ; license : LicenseType ; } export const LICENCED_FEATURES_DETAILS = { [ LICENSED_FEATURES . GEO_LINE_AGG ] : { name : 'geo_line aggregation' , license : 'gold' , } , [ LICENSED_FEATURES . GEO_SHAPE_AGGS_GEO_TILE ] : { name : 'geo_tile aggregation on geo_shape field-type' , license : 'gold' , } , [ LICENSED_FEATURES . ON_PREM_EMS ] : { name : 'layer from local Elastic Maps Server' , license : 'enterprise' , } , } ; let licenseId ; let isGoldPlus = false ; export const getLicenseId = ( ) => licenseId ; export const getIsGoldPlus = ( ) => isGoldPlus ; let licensingPluginStart ; let initializeLicense ; const licenseInitialized = new Promise ( ( resolve ) => { initializeLicense = resolve ; } ) ; export const whenLicenseInitialized = async ( ) : Promise < void > => { await licenseInitialized ; } ; export async function setLicensingPluginStart ( licensingPlugin ) { const license = await licensingPlugin . refresh ( ) ; updateLicenseState ( license ) ; licensingPluginStart = licensingPlugin ; licensingPluginStart . license$ . subscribe ( updateLicenseState ) ; initializeLicense ( undefined ) ; } function updateLicenseState ( license ) { const gold = license . check ( APP_ID , 'gold' ) ; isGoldPlus = gold . state === 'valid' ; licenseId = license . uid ; } export function registerLicensedFeatures ( licensingPlugin ) { for ( const licensedFeature of Object . values ( LICENSED_FEATURES ) ) { licensingPlugin . featureUsage . register ( LICENCED_FEATURES_DETAILS [ licensedFeature ] . name , LICENCED_FEATURES_DETAILS [ licensedFeature ] . license ) ; } } export function notifyLicensedFeatureUsage ( licensedFeature ) { if ( ! licensingPluginStart ) { console . error ( 'May not call notifyLicensedFeatureUsage before plugin start' ) ; return ; } licensingPluginStart . featureUsage . notifyUsage ( LICENCED_FEATURES_DETAILS [ LICENSED_FEATURES [ licensedFeature ] ] . name ) ; }