From 85eed92bcb3cac8cc58ae3805a4d58a694cc4bd3 Mon Sep 17 00:00:00 2001 From: Kai Wu Date: Thu, 24 Feb 2022 11:49:57 -0800 Subject: [PATCH 1/6] parent 1588990b7fb06b6fa545c0d478663e137ec0ea07 author Kai Wu 1645732197 -0800 committer Christina Holland 1645750725 -0800 Add Changeset for pull/5762 (#6030) * Create pretty-mayflies-worry.md * Update pretty-mayflies-worry.md Move based indexedDB operations to util add tests Fix year use idb clean up Add comments to HeartbeatService interface methods Cache heartbeats one per date (#5945) --- .changeset/pretty-mayflies-worry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/pretty-mayflies-worry.md diff --git a/.changeset/pretty-mayflies-worry.md b/.changeset/pretty-mayflies-worry.md new file mode 100644 index 00000000000..014bba4939d --- /dev/null +++ b/.changeset/pretty-mayflies-worry.md @@ -0,0 +1,5 @@ +--- +'@firebase/messaging': patch +--- + +Await on `onBackgroundMessage` to fix silent warning issue. From 71075a5086186b9dafbe81a9e07e62a5de08d1fa Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 2 Feb 2022 13:30:08 -0800 Subject: [PATCH 2/6] App Check heartbeat implementation --- packages/app-check/src/client.test.ts | 12 ++++++------ packages/app-check/src/client.ts | 9 +++++---- packages/app-check/src/factory.ts | 6 +++--- packages/app-check/src/index.ts | 4 ++-- packages/app-check/src/internal-api.ts | 2 +- packages/app-check/src/providers.ts | 16 ++++++++-------- packages/app-check/test/util.ts | 12 ++++++------ 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/app-check/src/client.test.ts b/packages/app-check/src/client.test.ts index afa8399b916..2cf6ef2795a 100644 --- a/packages/app-check/src/client.test.ts +++ b/packages/app-check/src/client.test.ts @@ -19,7 +19,7 @@ import '../test/setup'; import { expect } from 'chai'; import { stub, SinonStub, useFakeTimers } from 'sinon'; import { FirebaseApp } from '@firebase/app'; -import { getFakeApp, getFakePlatformLoggingProvider } from '../test/util'; +import { getFakeApp, getFakeHeartbeatServiceProvider } from '../test/util'; import { getExchangeRecaptchaV3TokenRequest, exchangeToken, @@ -86,7 +86,7 @@ describe('client', () => { const response = await exchangeToken( getExchangeRecaptchaV3TokenRequest(app, 'fake-custom-token'), - getFakePlatformLoggingProvider('a/1.2.3 fire-app-check/2.3.4') + getFakeHeartbeatServiceProvider('a/1.2.3 fire-app-check/2.3.4') ); expect( @@ -114,7 +114,7 @@ describe('client', () => { try { await exchangeToken( getExchangeRecaptchaV3TokenRequest(app, 'fake-custom-token'), - getFakePlatformLoggingProvider() + getFakeHeartbeatServiceProvider() ); } catch (e) { expect(e).instanceOf(FirebaseError); @@ -143,7 +143,7 @@ describe('client', () => { try { await exchangeToken( getExchangeRecaptchaV3TokenRequest(app, 'fake-custom-token'), - getFakePlatformLoggingProvider() + getFakeHeartbeatServiceProvider() ); } catch (e) { expect(e).instanceOf(FirebaseError); @@ -171,7 +171,7 @@ describe('client', () => { try { await exchangeToken( getExchangeRecaptchaV3TokenRequest(app, 'fake-custom-token'), - getFakePlatformLoggingProvider() + getFakeHeartbeatServiceProvider() ); } catch (e) { expect(e).instanceOf(FirebaseError); @@ -205,7 +205,7 @@ describe('client', () => { try { await exchangeToken( getExchangeRecaptchaV3TokenRequest(app, 'fake-custom-token'), - getFakePlatformLoggingProvider() + getFakeHeartbeatServiceProvider() ); } catch (e) { expect(e).instanceOf(FirebaseError); diff --git a/packages/app-check/src/client.ts b/packages/app-check/src/client.ts index 94564191f64..d6fec5ccfb5 100644 --- a/packages/app-check/src/client.ts +++ b/packages/app-check/src/client.ts @@ -42,17 +42,18 @@ interface AppCheckRequest { export async function exchangeToken( { url, body }: AppCheckRequest, - platformLoggerProvider: Provider<'platform-logger'> + heartbeatServiceProvider: Provider<'heartbeat'> ): Promise { const headers: HeadersInit = { 'Content-Type': 'application/json' }; // If platform logger exists, add the platform info string to the header. - const platformLogger = platformLoggerProvider.getImmediate({ + const heartbeatService = heartbeatServiceProvider.getImmediate({ optional: true }); - if (platformLogger) { - headers['X-Firebase-Client'] = platformLogger.getPlatformInfoString(); + if (heartbeatService) { + const heartbeatsHeader = await heartbeatService.getHeartbeatsHeader(); + headers['X-Firebase-Client'] = heartbeatsHeader; } const options: RequestInit = { method: 'POST', diff --git a/packages/app-check/src/factory.ts b/packages/app-check/src/factory.ts index 8ec0cf528f1..1870772cdd1 100644 --- a/packages/app-check/src/factory.ts +++ b/packages/app-check/src/factory.ts @@ -32,7 +32,7 @@ import { getState } from './state'; export class AppCheckService implements AppCheck, _FirebaseService { constructor( public app: FirebaseApp, - public platformLoggerProvider: Provider<'platform-logger'> + public heartbeatServiceProvider: Provider<'heartbeat'> ) {} _delete(): Promise { const { tokenObservers } = getState(this.app); @@ -45,9 +45,9 @@ export class AppCheckService implements AppCheck, _FirebaseService { export function factory( app: FirebaseApp, - platformLoggerProvider: Provider<'platform-logger'> + heartbeatServiceProvider: Provider<'heartbeat'> ): AppCheckService { - return new AppCheckService(app, platformLoggerProvider); + return new AppCheckService(app, heartbeatServiceProvider); } export function internalFactory( diff --git a/packages/app-check/src/index.ts b/packages/app-check/src/index.ts index 96e7e82eb01..b01b62eec88 100644 --- a/packages/app-check/src/index.ts +++ b/packages/app-check/src/index.ts @@ -48,8 +48,8 @@ function registerAppCheck(): void { container => { // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); - const platformLoggerProvider = container.getProvider('platform-logger'); - return factory(app, platformLoggerProvider); + const heartbeatServiceProvider = container.getProvider('heartbeat'); + return factory(app, heartbeatServiceProvider); }, ComponentType.PUBLIC ) diff --git a/packages/app-check/src/internal-api.ts b/packages/app-check/src/internal-api.ts index b7885b1b524..6b086c675cd 100644 --- a/packages/app-check/src/internal-api.ts +++ b/packages/app-check/src/internal-api.ts @@ -106,7 +106,7 @@ export async function getToken( if (!state.exchangeTokenPromise) { state.exchangeTokenPromise = exchangeToken( getExchangeDebugTokenRequest(app, await getDebugToken()), - appCheck.platformLoggerProvider + appCheck.heartbeatServiceProvider ).then(token => { state.exchangeTokenPromise = undefined; return token; diff --git a/packages/app-check/src/providers.ts b/packages/app-check/src/providers.ts index b47b00a02e3..cb07375dcf2 100644 --- a/packages/app-check/src/providers.ts +++ b/packages/app-check/src/providers.ts @@ -46,7 +46,7 @@ import { getDurationString } from './util'; */ export class ReCaptchaV3Provider implements AppCheckProvider { private _app?: FirebaseApp; - private _platformLoggerProvider?: Provider<'platform-logger'>; + private _heartbeatServiceProvider?: Provider<'heartbeat'>; /** * Throttle requests on certain error codes to prevent too many retries * in a short time. @@ -66,7 +66,7 @@ export class ReCaptchaV3Provider implements AppCheckProvider { throwIfThrottled(this._throttleData); // Top-level `getToken()` has already checked that App Check is initialized - // and therefore this._app and this._platformLoggerProvider are available. + // and therefore this._app and this._heartbeatServiceProvider are available. const attestedClaimsToken = await getReCAPTCHAToken(this._app!).catch( _e => { // reCaptcha.execute() throws null which is not very descriptive. @@ -77,7 +77,7 @@ export class ReCaptchaV3Provider implements AppCheckProvider { try { result = await exchangeToken( getExchangeRecaptchaV3TokenRequest(this._app!, attestedClaimsToken), - this._platformLoggerProvider! + this._heartbeatServiceProvider! ); } catch (e) { if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { @@ -105,7 +105,7 @@ export class ReCaptchaV3Provider implements AppCheckProvider { */ initialize(app: FirebaseApp): void { this._app = app; - this._platformLoggerProvider = _getProvider(app, 'platform-logger'); + this._heartbeatServiceProvider = _getProvider(app, 'heartbeat'); initializeRecaptchaV3(app, this._siteKey).catch(() => { /* we don't care about the initialization result */ }); @@ -131,7 +131,7 @@ export class ReCaptchaV3Provider implements AppCheckProvider { */ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { private _app?: FirebaseApp; - private _platformLoggerProvider?: Provider<'platform-logger'>; + private _heartbeatServiceProvider?: Provider<'heartbeat'>; /** * Throttle requests on certain error codes to prevent too many retries * in a short time. @@ -150,7 +150,7 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { async getToken(): Promise { throwIfThrottled(this._throttleData); // Top-level `getToken()` has already checked that App Check is initialized - // and therefore this._app and this._platformLoggerProvider are available. + // and therefore this._app and this._heartbeatServiceProvider are available. const attestedClaimsToken = await getReCAPTCHAToken(this._app!).catch( _e => { // reCaptcha.execute() throws null which is not very descriptive. @@ -164,7 +164,7 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { this._app!, attestedClaimsToken ), - this._platformLoggerProvider! + this._heartbeatServiceProvider! ); } catch (e) { if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { @@ -192,7 +192,7 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { */ initialize(app: FirebaseApp): void { this._app = app; - this._platformLoggerProvider = _getProvider(app, 'platform-logger'); + this._heartbeatServiceProvider = _getProvider(app, 'heartbeat'); initializeRecaptchaEnterprise(app, this._siteKey).catch(() => { /* we don't care about the initialization result */ }); diff --git a/packages/app-check/test/util.ts b/packages/app-check/test/util.ts index fa9f1afb41a..101307ec01c 100644 --- a/packages/app-check/test/util.ts +++ b/packages/app-check/test/util.ts @@ -55,7 +55,7 @@ export function getFakeApp(overrides: Record = {}): FirebaseApp { export function getFakeAppCheck(app: FirebaseApp): AppCheck { return { app, - platformLoggerProvider: getFakePlatformLoggingProvider() + heartbeatServiceProvider: getFakeHeartbeatServiceProvider() } as AppCheck; } @@ -63,7 +63,7 @@ export function getFullApp(): FirebaseApp { const app = initializeApp(fakeConfig); _registerComponent( new Component( - 'platform-logger', + 'heartbeat', () => { return {} as any; }, @@ -92,19 +92,19 @@ export function getFakeCustomTokenProvider(): CustomProvider { }); } -export function getFakePlatformLoggingProvider( +export function getFakeHeartbeatServiceProvider( fakeLogString: string = 'a/1.2.3 b/2.3.4' -): Provider<'platform-logger'> { +): Provider<'heartbeat'> { const container = new ComponentContainer('test'); container.addComponent( new Component( - 'platform-logger', + 'heartbeat', () => ({ getPlatformInfoString: () => fakeLogString }), ComponentType.PRIVATE ) ); - return container.getProvider('platform-logger'); + return container.getProvider('heartbeat'); } export function getFakeGreCAPTCHA( From 8f4b9cf93f8e18881a8f56aa8957dfc6bb95905e Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 24 Feb 2022 17:08:17 -0800 Subject: [PATCH 3/6] add changeset, fix test --- .changeset/polite-donkeys-divide.md | 5 +++++ packages/app-check/test/util.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/polite-donkeys-divide.md diff --git a/.changeset/polite-donkeys-divide.md b/.changeset/polite-donkeys-divide.md new file mode 100644 index 00000000000..ef6527ce025 --- /dev/null +++ b/.changeset/polite-donkeys-divide.md @@ -0,0 +1,5 @@ +--- +'@firebase/app-check': patch +--- + +Update platform logging to use new endpoint. diff --git a/packages/app-check/test/util.ts b/packages/app-check/test/util.ts index 101307ec01c..4a4f8671adb 100644 --- a/packages/app-check/test/util.ts +++ b/packages/app-check/test/util.ts @@ -30,6 +30,7 @@ import { } from '@firebase/component'; import { AppCheckService } from '../src/factory'; import { AppCheck, CustomProvider } from '../src'; +import { HeartbeatService } from '@firebase/app/dist/app/src/types'; export const FAKE_SITE_KEY = 'fake-site-key'; @@ -99,7 +100,10 @@ export function getFakeHeartbeatServiceProvider( container.addComponent( new Component( 'heartbeat', - () => ({ getPlatformInfoString: () => fakeLogString }), + () => + ({ + getHeartbeatsHeader: () => Promise.resolve(fakeLogString) + } as HeartbeatService), ComponentType.PRIVATE ) ); From ec4ebfe892e3f47bb54e5f40fbb84f27152fba28 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 25 Feb 2022 10:46:42 -0800 Subject: [PATCH 4/6] remove extra changeset --- .changeset/pretty-mayflies-worry.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/pretty-mayflies-worry.md diff --git a/.changeset/pretty-mayflies-worry.md b/.changeset/pretty-mayflies-worry.md deleted file mode 100644 index 014bba4939d..00000000000 --- a/.changeset/pretty-mayflies-worry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@firebase/messaging': patch ---- - -Await on `onBackgroundMessage` to fix silent warning issue. From 1a8de702cdfc6d18eb4856de681c32c1c3adbf66 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 28 Feb 2022 16:28:47 -0800 Subject: [PATCH 5/6] Update comment --- packages/app-check/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-check/src/client.ts b/packages/app-check/src/client.ts index d6fec5ccfb5..e94020090d4 100644 --- a/packages/app-check/src/client.ts +++ b/packages/app-check/src/client.ts @@ -47,7 +47,7 @@ export async function exchangeToken( const headers: HeadersInit = { 'Content-Type': 'application/json' }; - // If platform logger exists, add the platform info string to the header. + // If heartbeat service exists, add heartbeat header string to the header. const heartbeatService = heartbeatServiceProvider.getImmediate({ optional: true }); From 46636677a3a70767dd39518122fe0df3b6d5b648 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 4 Mar 2022 13:03:33 -0800 Subject: [PATCH 6/6] Do not send empty string as header --- packages/app-check/src/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/app-check/src/client.ts b/packages/app-check/src/client.ts index e94020090d4..2e4b28e6df4 100644 --- a/packages/app-check/src/client.ts +++ b/packages/app-check/src/client.ts @@ -53,7 +53,9 @@ export async function exchangeToken( }); if (heartbeatService) { const heartbeatsHeader = await heartbeatService.getHeartbeatsHeader(); - headers['X-Firebase-Client'] = heartbeatsHeader; + if (heartbeatsHeader) { + headers['X-Firebase-Client'] = heartbeatsHeader; + } } const options: RequestInit = { method: 'POST',