import { OS_LIST } from '../Lib/platform/osList' ; import { BROWSER_LIST } from '../Lib/platform/browserList' ; /**
 * Class responsible for tracking which Virgil SDK is being used to make requests, its version,
 * browser and platform.
 */ export class VirgilAgent { value : string ; private userAgent : string ; return { string } private getUserAgent ( ) { if ( typeof navigator !== "undefined" && typeof navigator . userAgent === "string" ) { return navigator . userAgent ; } else { return "" ; } } param { string } product param { string } version param { string } userAgent constructor ( product , version , userAgent ? ) { this . userAgent = userAgent || this . getUserAgent ( ) ; this . value = `${ product };js;${ this . getHeaderValue ( ) };${ version }` ; } ; returns { string } getOsName ( ) { const os = OS_LIST . find ( ( os ) => os . test . some ( condition => condition . test ( this . userAgent ) ) ) ; return os ? os . name : 'other' ; } returns { string } getBrowser ( ) { const browser = BROWSER_LIST . find ( ( browser ) => browser . test . some ( condition => condition . test ( this . userAgent ) ) ) ; return browser ? browser . name : 'other' ; } return { boolean } private isReactNative ( ) { return typeof navigator === "object" && navigator . product === "ReactNative" ; } return { boolean } private isIonic = ( ) : boolean => typeof window !== "undefined" && ! ! ( "cordova" in window || "phonegap" in window || "PhoneGap" in window ) && /android|ios|iphone|ipod|ipad|iemobile/i . test ( this . userAgent ) ; return { string } private getHeaderValue ( ) { try { if ( this . isReactNative ( ) ) return "ReactNative" ; if ( this . isIonic ( ) ) return `Ionic/${ this . getOsName ( ) }` ; if ( ! process . browser && typeof global !== 'undefined' ) { const majorVersion = process . version . replace ( /\.\d+\.\d+$/ , '' ) . replace ( 'v' , '' ) ; return `Node${ majorVersion }/${ process . platform }` ; } return `${ this . getBrowser ( ) }/${ this . getOsName ( ) }` ; } catch ( e ) { return `Unknown` ; } } }