-
Notifications
You must be signed in to change notification settings - Fork 392
Scaffolding out extensions namespace #1829
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
Changes from all commits
f21e263
03e6f8d
09161c2
6e9286c
c2eefd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*! | ||
* @license | ||
* Copyright 2021 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. | ||
*/ | ||
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. nit: new line |
||
import { App } from '../app'; | ||
import { FirebaseApp } from '../app/firebase-app'; | ||
import { HttpClient, AuthorizedHttpClient } from '../utils/api-request'; | ||
import { FirebaseAppError } from '../utils/error'; | ||
import * as validator from '../utils/validator'; | ||
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. nit: new line |
||
/** | ||
* Class that facilitates sending requests to the Firebase Extensions backend API. | ||
* | ||
* @internal | ||
*/ | ||
export class ExtensionsApiClient { | ||
/* eslint-disable-next-line no-unused-vars */ | ||
private readonly httpClient: HttpClient; | ||
|
||
constructor(private readonly app: App) { | ||
if (!validator.isNonNullObject(app) || !('options' in app)) { | ||
throw new FirebaseAppError( | ||
'invalid-argument', | ||
'First argument passed to getExtensions() must be a valid Firebase app instance.'); | ||
} | ||
this.httpClient = new AuthorizedHttpClient(app as FirebaseApp); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*! | ||
* @license | ||
* Copyright 2021 Google Inc. | ||
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. nit: Should this be 2022? |
||
* | ||
* 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. | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! | ||
* @license | ||
* Copyright 2021 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 { App } from '../app'; | ||
import { ExtensionsApiClient } from './extensions-api-client-internal'; | ||
|
||
export class Extensions { | ||
|
||
/* eslint-disable-next-line no-unused-vars */ | ||
private readonly client: ExtensionsApiClient; | ||
/** | ||
* @param app - The app for this `Extensions` service. | ||
* @constructor | ||
* @internal | ||
*/ | ||
constructor(readonly app: App) { | ||
this.client = new ExtensionsApiClient(app); | ||
} | ||
// TODO: Implement this. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*! | ||
* @license | ||
* Copyright 2021 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. | ||
*/ | ||
|
||
/** | ||
* Firebase Extensions service. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
import { App, getApp } from '../app'; | ||
import { FirebaseApp } from '../app/firebase-app'; | ||
import { Extensions } from './extensions'; | ||
|
||
/** | ||
* Gets the {@link Extensions} service for the default app | ||
* or a given app. | ||
* | ||
* `getExtensions()` can be called with no arguments to access the default | ||
* app's `Extensions` service or as `getExtensions(app)` to access the | ||
* `Extensions` service associated with a specific app. | ||
* | ||
* @example | ||
* ```javascript | ||
* // Get the `Extensions` service for the default app | ||
* const defaultExtensions = getExtensions(); | ||
* ``` | ||
* | ||
* @example | ||
* ```javascript | ||
* // Get the `Extensions` service for a given app | ||
* const otherExtensions = getExtensions(otherApp); | ||
* ``` | ||
* | ||
* @param app - Optional app for which to return the `Extensions` service. | ||
* If not provided, the default `Extensions` service is returned. | ||
* | ||
* @returns The default `Extensions` service if no app is provided, or the `Extensions` | ||
* service associated with the provided app. | ||
*/ | ||
export function getExtensions(app?: App): Extensions { | ||
if (typeof app === 'undefined') { | ||
app = getApp(); | ||
} | ||
|
||
const firebaseApp: FirebaseApp = app as FirebaseApp; | ||
return firebaseApp.getOrInitService('extensions', (app) => new Extensions(app)); | ||
} | ||
|
||
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. nit: new line 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. Thanks for catching these - gonna fix them in #1838 since they're all small style things |
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.
nit: should this be 2022?