UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

70 lines (68 loc) 2.65 kB
import { ReplaySubject, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { GatewayUrls } from '../gateway-urls'; import { SearchType } from './models/search-type'; /** * Active Directory Service implementation. */ export class ActiveDirectory { gateway; defaultDirectorySearchSizeLimit; isGatewayDomainJoined; isGatewayDomainJoinedSubject; /** * Initializes a new instance of the ActiveDirectory class. * @param gateway the gateway instance. */ constructor(gateway) { this.gateway = gateway; this.defaultDirectorySearchSizeLimit = 150; this.isGatewayDomainJoinedSubject = new ReplaySubject(1); this.isGatewayDomainJoined = this.isGatewayDomainJoinedSubject.asObservable(); this.gateway.get(GatewayUrls.adDomainRelativeUrl).subscribe({ next: (response) => { // if response is not empty, the gateway is domain joined this.isGatewayDomainJoinedSubject.next(!!response); }, error: () => { this.isGatewayDomainJoinedSubject.next(false); // TODO: LOG THIS ERROR } }); } /** * Search computer list from active directory through gateway api */ search(options) { const type = encodeURIComponent(this.getSearchType(options)); const searchString = encodeURIComponent(options.searchString) || ''; if (MsftSme.isNullOrUndefined(options.sizeLimit)) { options.sizeLimit = this.defaultDirectorySearchSizeLimit; } const requestUrl = `${GatewayUrls.adAccountsRelativeUrl}?type=${type}&filter=${searchString}&size=${options.sizeLimit}`; return this.gateway.get(requestUrl).pipe(catchError(error => { const exceptionMessage = MsftSme.getValue(error, 'response.exceptionMessage'); if (exceptionMessage) { return throwError(() => exceptionMessage); } return throwError(() => error); })); } /** * Get the appropriate search type string from the search options */ getSearchType(options) { if (Array.isArray(options.searchOn)) { options.searchOn = options.searchOn[0]; } if (MsftSme.isNullOrUndefined(options.searchOn)) { return 'any'; } options.searchOn = options.searchOn.toLowerCase(); if (MsftSme.isNullOrUndefined(SearchType[options.searchOn])) { return options.searchOn; } return SearchType[options.searchOn]; } } //# sourceMappingURL=active-directory.js.map