Skip to content

Commit b3e8a7b

Browse files
committed
Address PR comments, make version registration public
1 parent a96d3e2 commit b3e8a7b

File tree

8 files changed

+42
-19
lines changed

8 files changed

+42
-19
lines changed

packages/analytics/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function registerAnalytics(instance: _FirebaseNamespace): void {
5959
new Component('analytics-internal', internalFactory, ComponentType.PRIVATE)
6060
);
6161

62-
instance.INTERNAL.registerVersionComponent(ANALYTICS_TYPE, version);
62+
instance.registerVersion('ANALYTICS_TYPE', version);
6363

6464
function internalFactory(
6565
container: ComponentContainer

packages/app-types/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ export interface FirebaseNamespace {
9898
*/
9999
apps: FirebaseApp[];
100100

101+
/**
102+
* Registers a library's name and version for platform logging purposes.
103+
* @param library Name of 1p or 3p library (e.g. firestore, angularfire)
104+
* @param version Current version of that library.
105+
*/
106+
registerVersion(
107+
library: string,
108+
version: string
109+
): void
110+
101111
// The current SDK version.
102112
SDK_VERSION: string;
103113
}

packages/app/src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
export const DEFAULT_ENTRY_NAME = '[DEFAULT]';
1919

20-
export const platformLogString: { [key: string]: string } = {
20+
export const PLATFORM_LOG_STRING = {
2121
'firebase': 'fire-js',
2222
'app': 'fire-core',
2323
'analytics': 'fire-analytics',
@@ -29,4 +29,4 @@ export const platformLogString: { [key: string]: string } = {
2929
'remote-config': 'fire-rc',
3030
'storage': 'fire-gcs',
3131
'firestore': 'fire-fst'
32-
};
32+
} as const;

packages/app/src/firebaseNamespaceCore.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ export function createFirebaseNamespaceCore(
6060
initializeApp,
6161
// @ts-ignore
6262
app,
63+
registerVersion,
6364
// @ts-ignore
6465
apps: null,
6566
SDK_VERSION: version,
6667
INTERNAL: {
6768
registerComponent,
68-
registerVersionComponent,
6969
removeApp,
7070
components,
7171
useAsService
@@ -236,16 +236,18 @@ export function createFirebaseNamespaceCore(
236236
: null;
237237
}
238238

239-
function registerVersionComponent(
239+
function registerVersion(
240240
library: string,
241241
version: string
242-
): FirebaseServiceNamespace<FirebaseService> | null {
243-
return registerComponent(
242+
): void {
243+
if (library.match(/\s|\//)) {
244+
logger.warn(`Could not register ${library}: it contains illegal characters.`);
245+
return;
246+
}
247+
registerComponent(
244248
new Component(
245249
`${library}-version` as Name,
246-
() => {
247-
return new VersionService(library, version);
248-
},
250+
() => new VersionService(library, version),
249251
ComponentType.VERSION
250252
)
251253
);

packages/app/src/platformLoggerService.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
import { ComponentContainer, ComponentType } from '@firebase/component';
1919
import { VersionService } from './version-service';
20-
import { platformLogString } from './constants';
20+
import { PLATFORM_LOG_STRING } from './constants';
2121

2222
export class PlatformLoggerService {
23-
constructor(private container: ComponentContainer) {}
23+
constructor(private readonly container: ComponentContainer) {}
2424
// In initial implementation, this will be called by installations on
2525
// auth token refresh, and installations will send this string.
2626
getPlatformInfoString(): string {
@@ -29,18 +29,19 @@ export class PlatformLoggerService {
2929
// version components.
3030
return providers
3131
.map(provider => {
32-
const service = provider.getImmediate();
32+
const service = provider.getImmediate() as VersionService;
3333
const component = provider.getComponent();
3434
if (service && component && component.type === ComponentType.VERSION) {
3535
const platformString =
36-
platformLogString[(service as VersionService).library] ||
37-
(service as VersionService).library;
38-
return `${platformString}/${(service as VersionService).version}`;
36+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37+
(PLATFORM_LOG_STRING as any)[service.library] ||
38+
service.library;
39+
return `${platformString}/${service.version}`;
3940
} else {
4041
return null;
4142
}
4243
})
43-
.filter((logString: string | null) => logString)
44+
.filter(logString => logString)
4445
.join(' ');
4546
}
4647
}

packages/firebase/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import firebase from '@firebase/app';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
2020

21-
(firebase as _FirebaseNamespace).INTERNAL.registerVersionComponent(
21+
(firebase as _FirebaseNamespace).registerVersion(
2222
'firebase',
2323
firebase.SDK_VERSION
2424
);

packages/firebase/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ declare namespace firebase {
8383
*/
8484
var SDK_VERSION: string;
8585

86+
/**
87+
* Registers a library's name and version for platform logging purposes.
88+
* @param library Name of 1p or 3p library (e.g. firestore, angularfire)
89+
* @param version Current version of that library.
90+
*/
91+
function registerVersion(
92+
library: string,
93+
version: string
94+
): void
95+
8696
/**
8797
* @hidden
8898
*/

packages/functions/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ export function registerFunctions(instance: _FirebaseNamespace): void {
5050
.setServiceProps(namespaceExports)
5151
.setMultipleInstances(true)
5252
);
53-
instance.INTERNAL.registerVersionComponent('functions', version);
53+
instance.registerVersion('functions', version);
5454
}

0 commit comments

Comments
 (0)