From 8270def014fb65f4ef3d4a2e1304d2a9ad2a35fb Mon Sep 17 00:00:00 2001 From: Alex Volkovitsky Date: Tue, 14 Apr 2020 16:01:46 -0700 Subject: [PATCH 1/3] Add version helper to auth-next --- packages-exp/auth-exp/package.json | 1 + .../auth-exp/src/core/util/browser.test.ts | 86 +++++++++++++++++++ .../auth-exp/src/core/util/browser.ts | 84 ++++++++++++++++++ .../auth-exp/src/core/util/version.test.ts | 40 +++++++++ .../auth-exp/src/core/util/version.ts | 61 +++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 packages-exp/auth-exp/src/core/util/browser.test.ts create mode 100644 packages-exp/auth-exp/src/core/util/browser.ts create mode 100644 packages-exp/auth-exp/src/core/util/version.test.ts create mode 100644 packages-exp/auth-exp/src/core/util/version.ts diff --git a/packages-exp/auth-exp/package.json b/packages-exp/auth-exp/package.json index fc134da9648..bb353a23e44 100644 --- a/packages-exp/auth-exp/package.json +++ b/packages-exp/auth-exp/package.json @@ -29,6 +29,7 @@ "@firebase/app-types-exp": "0.x" }, "dependencies": { + "@firebase/app": "^0.6.1", "@firebase/util": "^0.2.44", "tslib": "1.11.1" }, diff --git a/packages-exp/auth-exp/src/core/util/browser.test.ts b/packages-exp/auth-exp/src/core/util/browser.test.ts new file mode 100644 index 00000000000..ed0b92c691d --- /dev/null +++ b/packages-exp/auth-exp/src/core/util/browser.test.ts @@ -0,0 +1,86 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import { getBrowserName, BrowserName} from "./browser"; + +describe('getBrowserName', () => { + it('should recognize Opera', () => { + const userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 OPR/36.0.2130.74'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.OPERA); + }); + + it('should recognize IE', () => { + const userAgent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.IE); + }); + + it('should recognize Edge', () => { + const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.EDGE); + }); + + it('should recognize Firefox', () => { + const userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.FIREFOX); + }); + + it('should recognize Silk', () => { + const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Silk/44.1.54 like Chrome/44.0.2403.63 Safari/537.36'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.SILK); + }); + + it('should recognize Safari', () => { + const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11-4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.SAFARI); + }); + + it('should recognize Chrome', () => { + const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.CHROME); + }); + + it('should recognize Android', () => { + const userAgent = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.ANDROID); + }); + + it('should recognize Blackberry', () => { + const userAgent = 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.BLACKBERRY); + }); + + it('should recognize IE Mobile', () => { + const userAgent = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.IEMOBILE); + }); + + it('should recognize WebOS', () => { + const userAgent = 'Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.WEBOS); + }); + + it('should recognize an unlisted browser', () => { + const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Awesome/2.0.012'; + expect(getBrowserName(userAgent)).to.eq('Awesome'); + }); + + it('should default to Other', () => { + const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]'; + expect(getBrowserName(userAgent)).to.eq(BrowserName.OTHER); + }); +}); \ No newline at end of file diff --git a/packages-exp/auth-exp/src/core/util/browser.ts b/packages-exp/auth-exp/src/core/util/browser.ts new file mode 100644 index 00000000000..42863526d88 --- /dev/null +++ b/packages-exp/auth-exp/src/core/util/browser.ts @@ -0,0 +1,84 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Enums for Browser name. + */ +export enum BrowserName { + ANDROID ='Android', + BLACKBERRY = 'Blackberry', + EDGE = 'Edge', + FIREFOX ='Firefox', + IE = 'IE', + IEMOBILE ='IEMobile', + OPERA = 'Opera', + OTHER = 'Other', + CHROME = 'Chrome', + SAFARI = 'Safari', + SILK = 'Silk', + WEBOS = 'Webos' +}; + +/** + * Determine the browser for the purposes of reporting usage to the API + */ +export function getBrowserName(userAgent: string): BrowserName | string { + const ua = userAgent.toLowerCase(); + if (ua.includes('opera/') || + ua.includes('opr/') || + ua.includes('opios/')) { + return BrowserName.OPERA; + } else if (ua.includes('iemobile')) { + // Windows phone IEMobile browser. + return BrowserName.IEMOBILE; + } else if (ua.includes('msie') || + ua.includes('trident/')) { + return BrowserName.IE; + } else if (ua.includes('edge/')) { + return BrowserName.EDGE; + } else if (ua.includes('firefox/')) { + return BrowserName.FIREFOX; + } else if (ua.includes('silk/')) { + return BrowserName.SILK; + } else if (ua.includes('blackberry')) { + // Blackberry browser. + return BrowserName.BLACKBERRY; + } else if (ua.includes('webos')) { + // WebOS default browser. + return BrowserName.WEBOS; + } else if (ua.includes('safari/') && + !ua.includes('chrome/') && + !ua.includes('crios/') && + !ua.includes('android')) { + return BrowserName.SAFARI; + } else if ((ua.includes('chrome/') || + ua.includes('crios/')) && + !ua.includes('edge/')) { + return BrowserName.CHROME; + } else if (ua.includes('android')) { + // Android stock browser. + return BrowserName.ANDROID; + } else { + // Most modern browsers have name/version at end of user agent string. + const re = new RegExp('([a-zA-Z\\d\\.]+)\/[a-zA-Z\\d\\.]*$'); + const matches = userAgent.match(re); + if (matches && matches.length === 2) { + return matches[1]; + } + } + return BrowserName.OTHER; +}; diff --git a/packages-exp/auth-exp/src/core/util/version.test.ts b/packages-exp/auth-exp/src/core/util/version.test.ts new file mode 100644 index 00000000000..783d8db8665 --- /dev/null +++ b/packages-exp/auth-exp/src/core/util/version.test.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import firebase from '@firebase/app'; +import { expect } from 'chai'; +import { ClientPlatform, getClientVersion } from './version'; + +describe('getClientVersion', () => { + context('browser', () => { + it('should set the correct version', () => { + expect(getClientVersion(ClientPlatform.BROWSER)).to.eq(`Chrome/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + }); + }); + + context('worker', () => { + it('should set the correct version', () => { + expect(getClientVersion(ClientPlatform.WORKER)).to.eq(`Chrome-Worker/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + }); + }); + + context('React Native', () => { + it('should set the correct version', () => { + expect(getClientVersion(ClientPlatform.REACT_NATIVE)).to.eq(`ReactNative/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + }); + }); +}); \ No newline at end of file diff --git a/packages-exp/auth-exp/src/core/util/version.ts b/packages-exp/auth-exp/src/core/util/version.ts new file mode 100644 index 00000000000..41dea7a0320 --- /dev/null +++ b/packages-exp/auth-exp/src/core/util/version.ts @@ -0,0 +1,61 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import firebase from '@firebase/app'; +import { getBrowserName } from './browser'; +import { getUA } from '@firebase/util'; + +const CLIENT_IMPLEMENTATION = 'JsCore'; + +export enum ClientPlatform { + BROWSER = 'Browser', + NODE = 'Node', + REACT_NATIVE = 'ReactNative', + WORKER = 'Worker' +} + +enum ClientFramework { + // No other framework used. + DEFAULT = 'FirebaseCore-web', + // Firebase Auth used with FirebaseUI-web. + // TODO: Pass this in when used in conjunction with FirebaseUI + FIREBASEUI = 'FirebaseUI-web' +}; + +/* + * Determine the SDK version string + * + * TODO: This should be set on the Auth object during initialization + */ +export function getClientVersion(clientPlatform: ClientPlatform): string { + let reportedPlatform: string; + switch(clientPlatform) { + case ClientPlatform.BROWSER: + // In a browser environment, report the browser name. + reportedPlatform = getBrowserName(getUA()); + break; + case ClientPlatform.WORKER: + // Technically a worker runs from a browser but we need to differentiate a + // worker from a browser. + // For example: Chrome-Worker/JsCore/4.9.1/FirebaseCore-web. + reportedPlatform = `${getBrowserName(getUA())}-${clientPlatform}`; + break; + default: + reportedPlatform = clientPlatform; + } + return `${reportedPlatform}/${CLIENT_IMPLEMENTATION}/${firebase.SDK_VERSION}/${ClientFramework.DEFAULT}`; +} \ No newline at end of file From 52652d2c2ff5c893f45bba7517b75563e4346bac Mon Sep 17 00:00:00 2001 From: Alex Volkovitsky Date: Tue, 14 Apr 2020 16:03:08 -0700 Subject: [PATCH 2/3] [AUTOMATED]: Prettier Code Styling --- .../auth-exp/src/core/util/browser.test.ts | 45 ++++++++++++------- .../auth-exp/src/core/util/browser.ts | 32 ++++++------- .../auth-exp/src/core/util/version.test.ts | 20 ++++++--- .../auth-exp/src/core/util/version.ts | 6 +-- 4 files changed, 61 insertions(+), 42 deletions(-) diff --git a/packages-exp/auth-exp/src/core/util/browser.test.ts b/packages-exp/auth-exp/src/core/util/browser.test.ts index ed0b92c691d..8a99a13a49a 100644 --- a/packages-exp/auth-exp/src/core/util/browser.test.ts +++ b/packages-exp/auth-exp/src/core/util/browser.test.ts @@ -16,71 +16,84 @@ */ import { expect } from 'chai'; -import { getBrowserName, BrowserName} from "./browser"; +import { getBrowserName, BrowserName } from './browser'; describe('getBrowserName', () => { it('should recognize Opera', () => { - const userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 OPR/36.0.2130.74'; + const userAgent = + 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 OPR/36.0.2130.74'; expect(getBrowserName(userAgent)).to.eq(BrowserName.OPERA); }); - + it('should recognize IE', () => { - const userAgent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'; + const userAgent = + 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'; expect(getBrowserName(userAgent)).to.eq(BrowserName.IE); }); it('should recognize Edge', () => { - const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240'; + const userAgent = + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240'; expect(getBrowserName(userAgent)).to.eq(BrowserName.EDGE); }); it('should recognize Firefox', () => { - const userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0'; + const userAgent = + 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0'; expect(getBrowserName(userAgent)).to.eq(BrowserName.FIREFOX); }); it('should recognize Silk', () => { - const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Silk/44.1.54 like Chrome/44.0.2403.63 Safari/537.36'; + const userAgent = + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Silk/44.1.54 like Chrome/44.0.2403.63 Safari/537.36'; expect(getBrowserName(userAgent)).to.eq(BrowserName.SILK); }); it('should recognize Safari', () => { - const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11-4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'; + const userAgent = + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11-4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'; expect(getBrowserName(userAgent)).to.eq(BrowserName.SAFARI); }); it('should recognize Chrome', () => { - const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'; + const userAgent = + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'; expect(getBrowserName(userAgent)).to.eq(BrowserName.CHROME); }); it('should recognize Android', () => { - const userAgent = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'; + const userAgent = + 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'; expect(getBrowserName(userAgent)).to.eq(BrowserName.ANDROID); }); it('should recognize Blackberry', () => { - const userAgent = 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+'; + const userAgent = + 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+'; expect(getBrowserName(userAgent)).to.eq(BrowserName.BLACKBERRY); }); it('should recognize IE Mobile', () => { - const userAgent = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'; + const userAgent = + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'; expect(getBrowserName(userAgent)).to.eq(BrowserName.IEMOBILE); }); it('should recognize WebOS', () => { - const userAgent = 'Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'; + const userAgent = + 'Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'; expect(getBrowserName(userAgent)).to.eq(BrowserName.WEBOS); }); it('should recognize an unlisted browser', () => { - const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Awesome/2.0.012'; + const userAgent = + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Awesome/2.0.012'; expect(getBrowserName(userAgent)).to.eq('Awesome'); }); it('should default to Other', () => { - const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]'; + const userAgent = + 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]'; expect(getBrowserName(userAgent)).to.eq(BrowserName.OTHER); }); -}); \ No newline at end of file +}); diff --git a/packages-exp/auth-exp/src/core/util/browser.ts b/packages-exp/auth-exp/src/core/util/browser.ts index 42863526d88..35ec605058d 100644 --- a/packages-exp/auth-exp/src/core/util/browser.ts +++ b/packages-exp/auth-exp/src/core/util/browser.ts @@ -19,34 +19,31 @@ * Enums for Browser name. */ export enum BrowserName { - ANDROID ='Android', + ANDROID = 'Android', BLACKBERRY = 'Blackberry', EDGE = 'Edge', - FIREFOX ='Firefox', + FIREFOX = 'Firefox', IE = 'IE', - IEMOBILE ='IEMobile', + IEMOBILE = 'IEMobile', OPERA = 'Opera', OTHER = 'Other', CHROME = 'Chrome', SAFARI = 'Safari', SILK = 'Silk', WEBOS = 'Webos' -}; +} /** * Determine the browser for the purposes of reporting usage to the API */ export function getBrowserName(userAgent: string): BrowserName | string { const ua = userAgent.toLowerCase(); - if (ua.includes('opera/') || - ua.includes('opr/') || - ua.includes('opios/')) { + if (ua.includes('opera/') || ua.includes('opr/') || ua.includes('opios/')) { return BrowserName.OPERA; } else if (ua.includes('iemobile')) { // Windows phone IEMobile browser. return BrowserName.IEMOBILE; - } else if (ua.includes('msie') || - ua.includes('trident/')) { + } else if (ua.includes('msie') || ua.includes('trident/')) { return BrowserName.IE; } else if (ua.includes('edge/')) { return BrowserName.EDGE; @@ -60,25 +57,28 @@ export function getBrowserName(userAgent: string): BrowserName | string { } else if (ua.includes('webos')) { // WebOS default browser. return BrowserName.WEBOS; - } else if (ua.includes('safari/') && + } else if ( + ua.includes('safari/') && !ua.includes('chrome/') && !ua.includes('crios/') && - !ua.includes('android')) { + !ua.includes('android') + ) { return BrowserName.SAFARI; - } else if ((ua.includes('chrome/') || - ua.includes('crios/')) && - !ua.includes('edge/')) { + } else if ( + (ua.includes('chrome/') || ua.includes('crios/')) && + !ua.includes('edge/') + ) { return BrowserName.CHROME; } else if (ua.includes('android')) { // Android stock browser. return BrowserName.ANDROID; } else { // Most modern browsers have name/version at end of user agent string. - const re = new RegExp('([a-zA-Z\\d\\.]+)\/[a-zA-Z\\d\\.]*$'); + const re = new RegExp('([a-zA-Z\\d\\.]+)/[a-zA-Z\\d\\.]*$'); const matches = userAgent.match(re); if (matches && matches.length === 2) { return matches[1]; } } return BrowserName.OTHER; -}; +} diff --git a/packages-exp/auth-exp/src/core/util/version.test.ts b/packages-exp/auth-exp/src/core/util/version.test.ts index 783d8db8665..c9ddeab350e 100644 --- a/packages-exp/auth-exp/src/core/util/version.test.ts +++ b/packages-exp/auth-exp/src/core/util/version.test.ts @@ -22,19 +22,25 @@ import { ClientPlatform, getClientVersion } from './version'; describe('getClientVersion', () => { context('browser', () => { it('should set the correct version', () => { - expect(getClientVersion(ClientPlatform.BROWSER)).to.eq(`Chrome/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + expect(getClientVersion(ClientPlatform.BROWSER)).to.eq( + `Chrome/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + ); }); - }); + }); context('worker', () => { it('should set the correct version', () => { - expect(getClientVersion(ClientPlatform.WORKER)).to.eq(`Chrome-Worker/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + expect(getClientVersion(ClientPlatform.WORKER)).to.eq( + `Chrome-Worker/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + ); }); - }); + }); context('React Native', () => { it('should set the correct version', () => { - expect(getClientVersion(ClientPlatform.REACT_NATIVE)).to.eq(`ReactNative/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web`); + expect(getClientVersion(ClientPlatform.REACT_NATIVE)).to.eq( + `ReactNative/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + ); }); - }); -}); \ No newline at end of file + }); +}); diff --git a/packages-exp/auth-exp/src/core/util/version.ts b/packages-exp/auth-exp/src/core/util/version.ts index 41dea7a0320..d01954cc93a 100644 --- a/packages-exp/auth-exp/src/core/util/version.ts +++ b/packages-exp/auth-exp/src/core/util/version.ts @@ -34,7 +34,7 @@ enum ClientFramework { // Firebase Auth used with FirebaseUI-web. // TODO: Pass this in when used in conjunction with FirebaseUI FIREBASEUI = 'FirebaseUI-web' -}; +} /* * Determine the SDK version string @@ -43,7 +43,7 @@ enum ClientFramework { */ export function getClientVersion(clientPlatform: ClientPlatform): string { let reportedPlatform: string; - switch(clientPlatform) { + switch (clientPlatform) { case ClientPlatform.BROWSER: // In a browser environment, report the browser name. reportedPlatform = getBrowserName(getUA()); @@ -58,4 +58,4 @@ export function getClientVersion(clientPlatform: ClientPlatform): string { reportedPlatform = clientPlatform; } return `${reportedPlatform}/${CLIENT_IMPLEMENTATION}/${firebase.SDK_VERSION}/${ClientFramework.DEFAULT}`; -} \ No newline at end of file +} From e4323bd349e25ddba0cc4c0048aa4d4652fec3ef Mon Sep 17 00:00:00 2001 From: Alex Volkovitsky Date: Wed, 15 Apr 2020 15:18:16 -0700 Subject: [PATCH 3/3] PR feedback --- packages-exp/auth-exp/package.json | 1 - packages-exp/auth-exp/src/core/util/browser.ts | 4 ++-- packages-exp/auth-exp/src/core/util/version.test.ts | 8 ++++---- packages-exp/auth-exp/src/core/util/version.ts | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages-exp/auth-exp/package.json b/packages-exp/auth-exp/package.json index bb353a23e44..fc134da9648 100644 --- a/packages-exp/auth-exp/package.json +++ b/packages-exp/auth-exp/package.json @@ -29,7 +29,6 @@ "@firebase/app-types-exp": "0.x" }, "dependencies": { - "@firebase/app": "^0.6.1", "@firebase/util": "^0.2.44", "tslib": "1.11.1" }, diff --git a/packages-exp/auth-exp/src/core/util/browser.ts b/packages-exp/auth-exp/src/core/util/browser.ts index 35ec605058d..5020f00a447 100644 --- a/packages-exp/auth-exp/src/core/util/browser.ts +++ b/packages-exp/auth-exp/src/core/util/browser.ts @@ -74,9 +74,9 @@ export function getBrowserName(userAgent: string): BrowserName | string { return BrowserName.ANDROID; } else { // Most modern browsers have name/version at end of user agent string. - const re = new RegExp('([a-zA-Z\\d\\.]+)/[a-zA-Z\\d\\.]*$'); + const re = /([a-zA-Z\d\.]+)\/[a-zA-Z\d\.]*$/; const matches = userAgent.match(re); - if (matches && matches.length === 2) { + if (matches?.length === 2) { return matches[1]; } } diff --git a/packages-exp/auth-exp/src/core/util/version.test.ts b/packages-exp/auth-exp/src/core/util/version.test.ts index c9ddeab350e..eea1c2ffe55 100644 --- a/packages-exp/auth-exp/src/core/util/version.test.ts +++ b/packages-exp/auth-exp/src/core/util/version.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import firebase from '@firebase/app'; +import { SDK_VERSION } from '@firebase/app-exp'; import { expect } from 'chai'; import { ClientPlatform, getClientVersion } from './version'; @@ -23,7 +23,7 @@ describe('getClientVersion', () => { context('browser', () => { it('should set the correct version', () => { expect(getClientVersion(ClientPlatform.BROWSER)).to.eq( - `Chrome/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + `Chrome/JsCore/${SDK_VERSION}/FirebaseCore-web` ); }); }); @@ -31,7 +31,7 @@ describe('getClientVersion', () => { context('worker', () => { it('should set the correct version', () => { expect(getClientVersion(ClientPlatform.WORKER)).to.eq( - `Chrome-Worker/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + `Chrome-Worker/JsCore/${SDK_VERSION}/FirebaseCore-web` ); }); }); @@ -39,7 +39,7 @@ describe('getClientVersion', () => { context('React Native', () => { it('should set the correct version', () => { expect(getClientVersion(ClientPlatform.REACT_NATIVE)).to.eq( - `ReactNative/JsCore/${firebase.SDK_VERSION}/FirebaseCore-web` + `ReactNative/JsCore/${SDK_VERSION}/FirebaseCore-web` ); }); }); diff --git a/packages-exp/auth-exp/src/core/util/version.ts b/packages-exp/auth-exp/src/core/util/version.ts index d01954cc93a..470213e764f 100644 --- a/packages-exp/auth-exp/src/core/util/version.ts +++ b/packages-exp/auth-exp/src/core/util/version.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import firebase from '@firebase/app'; +import { SDK_VERSION } from '@firebase/app-exp'; import { getBrowserName } from './browser'; import { getUA } from '@firebase/util'; @@ -57,5 +57,5 @@ export function getClientVersion(clientPlatform: ClientPlatform): string { default: reportedPlatform = clientPlatform; } - return `${reportedPlatform}/${CLIENT_IMPLEMENTATION}/${firebase.SDK_VERSION}/${ClientFramework.DEFAULT}`; + return `${reportedPlatform}/${CLIENT_IMPLEMENTATION}/${SDK_VERSION}/${ClientFramework.DEFAULT}`; }