import { SPHttpClient } from '@microsoft/sp-http' ; import { Environment , EnvironmentType } from '@microsoft/sp-core-library' ; import { BaseComponentContext } from '@microsoft/sp-component-base' ; import { IRoleDefinitionInformation , IPropertyFieldRoleDefinitionPickerHostProps } from '../propertyFields/roleDefinitionPicker' ; import { ISPRoleDefinitionPickerService } from './ISPRoleDefinitionPickerService' ; import { IRoleDefinitionInformationCollection } from '../propertyFields/roleDefinitionPicker' ; /**
 * Service implementation to get list & list items from current SharePoint site
 */ export class SPRoleDefinitionPickerService implements ISPRoleDefinitionPickerService { private context : BaseComponentContext ; private props : IPropertyFieldRoleDefinitionPickerHostProps ; /**
     * Service constructor
     */ constructor ( _props , pageContext ) { this . props = _props ; this . context = pageContext ; } /**
     * Gets the collection of view for a selected list
     */ public async getRoleDefinitions ( ) { const webAbsoluteUrl = this . props . webAbsoluteUrl ? this . props . webAbsoluteUrl : this . context . pageContext . web . absoluteUrl ; let queryUrl = `${ webAbsoluteUrl }/_api/web/RoleDefinitions` ; let response = await this . context . spHttpClient . get ( queryUrl , SPHttpClient . configurations . v1 , { headers : [ [ 'accept' , 'application/json;odata=nometadata' ] , [ 'odata-version' , '' ] ] } ) ; let roleDefinitions = ( await response . json ( ) ) as IRoleDefinitionInformationCollection ; if ( this . props . onRoleDefinitionsRetrieved ) { let lr = this . props . onRoleDefinitionsRetrieved ( roleDefinitions . value ) ; let output ; if ( lr instanceof Array ) { output = lr ; } else { output = await lr ; } roleDefinitions . value = output ; } return roleDefinitions ; } /**
     * Returns an empty view for when a list isn't selected
     */ private getEmptyViews ( ) { return new Promise < IRoleDefinitionInformationCollection > ( ( resolve ) => { const roleDefinitionData = { value : [ ] } ; resolve ( roleDefinitionData ) ; } ) ; } }