{"version":3,"sources":["../../../packages/core/data/active-directory/active-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6B,MAAM,MAAM,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,0CAA0C,CAAC;AAGxF;;GAEG;AACH,qBAAa,eAAe;IAUZ,OAAO,CAAC,OAAO;IARpB,+BAA+B,EAAE,MAAM,CAAC;IAC/C,SAAgB,qBAAqB,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3D,OAAO,CAAC,4BAA4B,CAAyB;IAE7D;;;OAGG;gBACiB,OAAO,EAAE,iBAAiB;IAiB9C;;OAEG;IACI,MAAM,CAAC,OAAO,EAAE,4BAA4B,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAkB/E;;OAEG;IACH,OAAO,CAAC,aAAa;CAiBxB","file":"active-directory.d.ts","sourcesContent":["import { Observable, ReplaySubject, throwError } from 'rxjs';\r\nimport { catchError } from 'rxjs/operators';\r\nimport { GatewayConnection } from '../gateway-connection';\r\nimport { GatewayUrls } from '../gateway-urls';\r\nimport { AccountInfo } from './models/account-info';\r\nimport { ActiveDirectorySearchOptions } from './models/active-directory-search-options';\r\nimport { SearchType } from './models/search-type';\r\n\r\n/**\r\n * Active Directory Service implementation.\r\n */\r\nexport class ActiveDirectory {\r\n\r\n    public defaultDirectorySearchSizeLimit: number;\r\n    public readonly isGatewayDomainJoined: Observable<boolean>;\r\n    private isGatewayDomainJoinedSubject: ReplaySubject<boolean>;\r\n\r\n    /**\r\n     * Initializes a new instance of the ActiveDirectory class.\r\n     * @param gateway the gateway instance.\r\n     */\r\n    constructor(private gateway: GatewayConnection) {\r\n        this.defaultDirectorySearchSizeLimit = 150;\r\n        this.isGatewayDomainJoinedSubject = new ReplaySubject(1);\r\n        this.isGatewayDomainJoined = this.isGatewayDomainJoinedSubject.asObservable();\r\n\r\n        this.gateway.get(GatewayUrls.adDomainRelativeUrl).subscribe({\r\n            next: (response: any) => {\r\n                // if response is not empty, the gateway is domain joined\r\n                this.isGatewayDomainJoinedSubject.next(!!response);\r\n            },\r\n            error: () => {\r\n                this.isGatewayDomainJoinedSubject.next(false);\r\n                // TODO: LOG THIS ERROR\r\n            }\r\n        });\r\n    }\r\n\r\n    /**\r\n     * Search computer list from active directory through gateway api\r\n     */\r\n    public search(options: ActiveDirectorySearchOptions): Observable<AccountInfo[]> {\r\n        const type = encodeURIComponent(this.getSearchType(options));\r\n        const searchString = encodeURIComponent(options.searchString) || '';\r\n        if (MsftSme.isNullOrUndefined(options.sizeLimit)) {\r\n            options.sizeLimit = this.defaultDirectorySearchSizeLimit;\r\n        }\r\n        const requestUrl = `${GatewayUrls.adAccountsRelativeUrl}?type=${type}&filter=${searchString}&size=${options.sizeLimit}`;\r\n        return this.gateway.get(requestUrl).pipe(\r\n            catchError(error => {\r\n                const exceptionMessage = MsftSme.getValue(error, 'response.exceptionMessage');\r\n                if (exceptionMessage) {\r\n                    return throwError(() => exceptionMessage);\r\n                }\r\n                return throwError(() => error);\r\n            })\r\n        );\r\n    }\r\n\r\n    /**\r\n     * Get the appropriate search type string from the search options\r\n     */\r\n    private getSearchType(options: ActiveDirectorySearchOptions): string {\r\n        if (Array.isArray(options.searchOn)) {\r\n            options.searchOn = options.searchOn[0];\r\n        }\r\n\r\n        if (MsftSme.isNullOrUndefined(options.searchOn)) {\r\n            return 'any';\r\n        }\r\n\r\n        options.searchOn = options.searchOn.toLowerCase();\r\n\r\n        if (MsftSme.isNullOrUndefined(SearchType[options.searchOn])) {\r\n            return options.searchOn;\r\n        }\r\n\r\n        return SearchType[options.searchOn];\r\n    }\r\n}\r\n"]}