Skip to content

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

Merged
merged 5 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/extensions/extensions-api-client-internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*!
* @license
* Copyright 2021 Google Inc.
Copy link
Member

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?

*
* 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.
*/
Copy link
Member

Choose a reason for hiding this comment

The 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';
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
16 changes: 16 additions & 0 deletions src/extensions/extensions-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*!
* @license
* Copyright 2021 Google Inc.
Copy link
Member

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?

*
* 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.
*/
33 changes: 33 additions & 0 deletions src/extensions/extensions.ts
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.
}
62 changes: 62 additions & 0 deletions src/extensions/index.ts
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));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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