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/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..2e4b28e6df4 100644 --- a/packages/app-check/src/client.ts +++ b/packages/app-check/src/client.ts @@ -42,17 +42,20 @@ 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({ + // If heartbeat service exists, add heartbeat header string to the header. + const heartbeatService = heartbeatServiceProvider.getImmediate({ optional: true }); - if (platformLogger) { - headers['X-Firebase-Client'] = platformLogger.getPlatformInfoString(); + if (heartbeatService) { + const heartbeatsHeader = await heartbeatService.getHeartbeatsHeader(); + if (heartbeatsHeader) { + 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..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'; @@ -55,7 +56,7 @@ export function getFakeApp(overrides: Record = {}): FirebaseApp { export function getFakeAppCheck(app: FirebaseApp): AppCheck { return { app, - platformLoggerProvider: getFakePlatformLoggingProvider() + heartbeatServiceProvider: getFakeHeartbeatServiceProvider() } as AppCheck; } @@ -63,7 +64,7 @@ export function getFullApp(): FirebaseApp { const app = initializeApp(fakeConfig); _registerComponent( new Component( - 'platform-logger', + 'heartbeat', () => { return {} as any; }, @@ -92,19 +93,22 @@ 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', - () => ({ getPlatformInfoString: () => fakeLogString }), + 'heartbeat', + () => + ({ + getHeartbeatsHeader: () => Promise.resolve(fakeLogString) + } as HeartbeatService), ComponentType.PRIVATE ) ); - return container.getProvider('platform-logger'); + return container.getProvider('heartbeat'); } export function getFakeGreCAPTCHA(