-
Notifications
You must be signed in to change notification settings - Fork 946
Add internal API to collect platform version info #2368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f085e2a
Add platform version logging functionality.
hsubox76 8564b4b
Address PR comments
hsubox76 611f370
[AUTOMATED]: Prettier Code Styling
hsubox76 6dc72df
Validate version string
hsubox76 b912b38
Fix import
hsubox76 69c199b
Address PR comments
hsubox76 3058b9b
[AUTOMATED]: Prettier Code Styling
hsubox76 e2583e9
Get package names from package.json and add tests
hsubox76 68808af
[AUTOMATED]: Prettier Code Styling
hsubox76 d13746d
Address PR comments
hsubox76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 Google Inc. | ||
* | ||
* 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 { | ||
ComponentContainer, | ||
ComponentType, | ||
Provider, | ||
Name | ||
} from '@firebase/component'; | ||
|
||
export class PlatformLoggerService { | ||
constructor(private readonly container: ComponentContainer) {} | ||
// In initial implementation, this will be called by installations on | ||
// auth token refresh, and installations will send this string. | ||
getPlatformInfoString(): string { | ||
const providers = this.container.getProviders(); | ||
// Loop through providers and get library/version pairs from any that are | ||
// version components. | ||
return providers | ||
.map(provider => { | ||
if (isVersionServiceProvider(provider)) { | ||
const service = provider.getImmediate(); | ||
return `${service.library}/${service.version}`; | ||
} else { | ||
return null; | ||
} | ||
}) | ||
.filter(logString => logString) | ||
.join(' '); | ||
} | ||
} | ||
/** | ||
* | ||
* @param provider check if this provider provides a VersionService | ||
* | ||
* NOTE: Using Provider<'app-version'> is a hack to indicate that the provider | ||
* provides VersionService. The provider is not necessarily a 'app-version' | ||
* provider. | ||
*/ | ||
function isVersionServiceProvider( | ||
provider: Provider<Name> | ||
): provider is Provider<'app-version'> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
const component = provider.getComponent(); | ||
return component?.type === ComponentType.VERSION; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 Google Inc. | ||
* | ||
* 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 { FirebaseNamespace } from '@firebase/app-types'; | ||
import { _FirebaseNamespace } from '@firebase/app-types/private'; | ||
import { Component, ComponentType } from '@firebase/component'; | ||
import { PlatformLoggerService } from './platformLoggerService'; | ||
import { name, version } from '../package.json'; | ||
|
||
export function registerCoreComponents(firebase: FirebaseNamespace): void { | ||
(firebase as _FirebaseNamespace).INTERNAL.registerComponent( | ||
new Component( | ||
'platform-logger', | ||
container => new PlatformLoggerService(container), | ||
ComponentType.PRIVATE | ||
) | ||
); | ||
// Register `app` package. | ||
firebase.registerVersion(name, version); | ||
// Register platform SDK identifier (no version). | ||
firebase.registerVersion('fire-js', ''); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this cast TBH, since it defeats the purpose of the
Name
type. Maybe we shouldn't consider versions actualComponent
s and instead create a different type for them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it might be a good idea in the long term to have separate Map in
ComponentContainer
in addition to theProviders
Map, and this new Map just stores key/value pairs. Can be used for versions now, and other possible key/value pair data going forward. But that requires a bit of modification to ComponentContainer that might not be a good idea right now as we're planning to do our first release with the migration to the component model next week right before a holiday. Since the actualregisterVersion
API wouldn't change we can change the implementation later when the component model is in use and stable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sounds good.