Skip to content

[FirebaseServerApp] Add ServerApp to feature branch #7894

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 30 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1216622
initial pass of additions
DellaBitta Sep 19, 2023
2efe043
another pass, optional callback failures
DellaBitta Sep 20, 2023
fda3060
compilation fixes
DellaBitta Sep 21, 2023
5fa9c21
FirebaseServerAppImpl now extends FirebaseAppImpl
DellaBitta Sep 21, 2023
0ef3bb2
removed Headers object, added three callbacks instead
DellaBitta Oct 2, 2023
8cd1072
added deleteOnDeref support
DellaBitta Oct 2, 2023
d42f676
lint fixes
DellaBitta Oct 2, 2023
612f990
deleteOnDeref type converted from WeakRef to object.
DellaBitta Oct 3, 2023
76f2fe1
update cookie func signatures. Check for existence of FinalizationReg…
DellaBitta Oct 4, 2023
d68f986
added baseline firebaseServerApp.test.ts
DellaBitta Oct 5, 2023
09e3157
update callback method siganatures with shorter names and alt undef p…
DellaBitta Oct 5, 2023
3750aa4
added some firebaseServerApp tests
DellaBitta Oct 10, 2023
316309c
Merge branch 'master' into ddb-server-app
DellaBitta Dec 4, 2023
6cc428b
format
DellaBitta Dec 4, 2023
53c15e2
Merge branch 'master' into ddb-server-app
DellaBitta Dec 6, 2023
22b9bd9
rework builds, tests need updating
DellaBitta Dec 7, 2023
3c39866
another API update and doc generation
DellaBitta Dec 14, 2023
d5e461e
Merge branch 'master' into ddb-server-app
DellaBitta Dec 15, 2023
a7d111a
reflect new API proposal in source
DellaBitta Dec 15, 2023
0427934
FirbaseServerAppSettings name?: undefined
DellaBitta Dec 18, 2023
db9b941
merge master
DellaBitta Dec 18, 2023
e146815
remove firebaseServerApp name
DellaBitta Dec 20, 2023
e9f28ed
remove engines from package.json
DellaBitta Dec 20, 2023
a13f418
FirebaseApp / Options typeguard. More tests.
DellaBitta Dec 21, 2023
8a745d1
Update FirebaseServerAppConfig name to be undefined.
DellaBitta Dec 21, 2023
7b02583
throw if firebaseServerApp constructed in browser. Remove lib ESNext …
DellaBitta Dec 31, 2023
d86eeb7
throw in initializeServerApp if invoked in a browser env.
DellaBitta Dec 31, 2023
b34b878
Update index.d.ts
DellaBitta Dec 31, 2023
4aeb9a6
Update index.d.ts
DellaBitta Dec 31, 2023
04af931
Remove the new FirebaseServerApp from the app-types.
DellaBitta Jan 3, 2024
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
23 changes: 23 additions & 0 deletions common/api-review/app.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ export interface FirebaseOptions {
storageBucket?: string;
}

// @public
export interface FirebaseServerApp extends FirebaseApp {
appCheckTokenVerified: () => Promise<void>;
authIdTokenVerified: () => Promise<void>;
installationTokenVerified: () => Promise<void>;
name: string;
}

// @public
export interface FirebaseServerAppSettings extends FirebaseAppSettings {
appCheckToken?: string;
authIdToken?: string;
installationsAuthToken?: string;
name?: undefined;
releaseOnDeref?: object;
}

// @internal (undocumented)
export interface _FirebaseService {
// (undocumented)
Expand All @@ -96,6 +113,9 @@ export function initializeApp(options: FirebaseOptions, config?: FirebaseAppSett
// @public
export function initializeApp(): FirebaseApp;

// @public
export function initializeServerApp(options: FirebaseOptions | FirebaseApp, config: FirebaseServerAppSettings): FirebaseServerApp;

// @public
export function onLog(logCallback: LogCallback | null, options?: LogOptions): void;

Expand All @@ -111,6 +131,9 @@ export function _removeServiceInstance<T extends Name>(app: FirebaseApp, name: T
// @public
export const SDK_VERSION: string;

// @public (undocumented)
export const _serverApps: Map<string, FirebaseServerApp>;

// @public
export function setLogLevel(logLevel: LogLevelString): void;

Expand Down
1 change: 1 addition & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"es2015.core",
"es2017.object",
"es2017.string",
"ESNext.WeakRef",
],
"module": "ES2015",
"moduleResolution": "node",
Expand Down
83 changes: 83 additions & 0 deletions docs-devsite/app.firebaseserverapp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# FirebaseServerApp interface
A [FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface) holds the initialization information for a collection of services running in server enviornments.

Do not call this constructor directly. Instead, use to create an app.

<b>Signature:</b>

```typescript
export interface FirebaseServerApp extends FirebaseApp
```
<b>Extends:</b> [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [appCheckTokenVerified](./app.firebaseserverapp.md#firebaseserverappappchecktokenverified) | () =&gt; Promise&lt;void&gt; | Checks to see if the verification of the appCheckToken provided to has completed. If the optional appCheckToken parameter was omitted then the returned Promise is completed immediately.<!-- -->It is recommend that your application awaits this promise before initializing any Firebase products that use AppCheck. The Firebase SDKs will not use App Check tokens that are determined to be invalid or those that have not yet completed validation.<!-- -->The returned Promise is completed immediately if the optional appCheckToken parameter was omitted from FirebaseServerApp initialization. |
| [authIdTokenVerified](./app.firebaseserverapp.md#firebaseserverappauthidtokenverified) | () =&gt; Promise&lt;void&gt; | Checks to see if the verification of the authIdToken provided to has completed.<!-- -->It is recommend that your application awaits this promise if an authIdToken was provided during FirebaseServerApp initialization before invoking getAuth(). If an instance of Auth is created before the Auth ID Token is validated, then the token will not be used by that instance of the Auth SDK.<!-- -->The returned Promise is completed immediately if the optional authIdToken parameter was omitted from FirebaseServerApp initialization. |
| [installationTokenVerified](./app.firebaseserverapp.md#firebaseserverappinstallationtokenverified) | () =&gt; Promise&lt;void&gt; | Checks to see if the verification of the installationToken provided to has completed.<!-- -->It is recommend that your application awaits this promise before initializing any Firebase products that use Firebase Installations. The Firebase SDKs will not use Installation Auth tokens that are determined to be invalid or those that have not yet completed validation.<!-- -->The returned Promise is completed immediately if the optional appCheckToken parameter was omitted from FirebaseServerApp initialization. |
| [name](./app.firebaseserverapp.md#firebaseserverappname) | string | There is no get for FirebaseServerApp, so the name is not relevant. However, it's declared here so that FirebaseServerApp conforms to the FirebaseApp interface declaration. Internally this string will always be empty for FirebaseServerApp instances. |

## FirebaseServerApp.appCheckTokenVerified

Checks to see if the verification of the appCheckToken provided to has completed. If the optional appCheckToken parameter was omitted then the returned Promise is completed immediately.

It is recommend that your application awaits this promise before initializing any Firebase products that use AppCheck. The Firebase SDKs will not use App Check tokens that are determined to be invalid or those that have not yet completed validation.

The returned Promise is completed immediately if the optional appCheckToken parameter was omitted from FirebaseServerApp initialization.

<b>Signature:</b>

```typescript
appCheckTokenVerified: () => Promise<void>;
```

## FirebaseServerApp.authIdTokenVerified

Checks to see if the verification of the authIdToken provided to has completed.

It is recommend that your application awaits this promise if an authIdToken was provided during FirebaseServerApp initialization before invoking getAuth(). If an instance of Auth is created before the Auth ID Token is validated, then the token will not be used by that instance of the Auth SDK.

The returned Promise is completed immediately if the optional authIdToken parameter was omitted from FirebaseServerApp initialization.

<b>Signature:</b>

```typescript
authIdTokenVerified: () => Promise<void>;
```

## FirebaseServerApp.installationTokenVerified

Checks to see if the verification of the installationToken provided to has completed.

It is recommend that your application awaits this promise before initializing any Firebase products that use Firebase Installations. The Firebase SDKs will not use Installation Auth tokens that are determined to be invalid or those that have not yet completed validation.

The returned Promise is completed immediately if the optional appCheckToken parameter was omitted from FirebaseServerApp initialization.

<b>Signature:</b>

```typescript
installationTokenVerified: () => Promise<void>;
```

## FirebaseServerApp.name

There is no get for FirebaseServerApp, so the name is not relevant. However, it's declared here so that FirebaseServerApp conforms to the FirebaseApp interface declaration. Internally this string will always be empty for FirebaseServerApp instances.

<b>Signature:</b>

```typescript
name: string;
```
104 changes: 104 additions & 0 deletions docs-devsite/app.firebaseserverappsettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# FirebaseServerAppSettings interface
Configuration options given to [initializeServerApp()](./app.md#initializeserverapp)

<b>Signature:</b>

```typescript
export interface FirebaseServerAppSettings extends FirebaseAppSettings
```
<b>Extends:</b> [FirebaseAppSettings](./app.firebaseappsettings.md#firebaseappsettings_interface)

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [appCheckToken](./app.firebaseserverappsettings.md#firebaseserverappsettingsappchecktoken) | string | An optional AppCheck token.<!-- -->If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be monitored by invoking the FirebaseServerApp.appCheckTokenVerified(). Awaiting the Promise returned by appCheckTokenVerified is highly recommended if an AppCheck token is provided.<!-- -->If the token has been properly verified then the AppCheck token will be automatically used by Firebase SDKs that support App Check.<!-- -->If the token fails verification then a warning is logged and the token will not be used. |
| [authIdToken](./app.firebaseserverappsettings.md#firebaseserverappsettingsauthidtoken) | string | An optional Auth ID token used to resume a signed in user session from a client runtime environment.<!-- -->If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be queried via by the application by invoking the FirebaseServerApp.authIdTokenVerified(). Awaiting the Promise returned by authIdTokenVerified is highly recommended if an Auth ID token is provided.<!-- -->Once the token has been properly verified then invoking getAuth() will attempt to automatically sign in a user with the provided Auth ID Token.<!-- -->If the token fails verification then a warning is logged and Auth SDK will not attempt to sign in a user upon its initalization. |
| [installationsAuthToken](./app.firebaseserverappsettings.md#firebaseserverappsettingsinstallationsauthtoken) | string | An optional Installation Auth token.<!-- -->If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be monitored by invoking the FirebaseServerApp.installationTokenVerified(). Awaiting the Promise returned by appCheckTokenVerified is highly recommended before initalization any other Firebase SDKs.<!-- -->If the token has been properly verified then the Installation Auth token will be automatically used by Firebase SDKs that support Firebase Installations.<!-- -->If the token fails verification then a warning is logged and the token will not be used. |
| [name](./app.firebaseserverappsettings.md#firebaseserverappsettingsname) | "" | There is no get for FirebaseServerApps, so the name is not relevant. however it's always a blank string so that FirebaseServerApp conforms to the FirebaseApp interface declaration. |
| [releaseOnDeref](./app.firebaseserverappsettings.md#firebaseserverappsettingsreleaseonderef) | object | An optional object. If provided, the Firebase SDK will use a FinalizationRegistry object to monitor the Garbage Collection status of the provided object, and the Firebase SDK will release its refrence on the FirebaseServerApp instance when the provided object is collected. or.<!-- -->The intent of this field is to help reduce memory overhead for long-running cloud functions executing SSR fulfillment without the customer's app needing to orchestrate FirebaseServerApp cleanup. Additionally, prexisting FirebaseServerApp instances may reused if they're identical to a previously generated one that has yet to be deleted.<!-- -->If the object is not provided then the application must clean up the FirebaseServerApp instance through the applicationss own standard mechanisms by invoking deleteApp.<!-- -->If the app provides an object in this parameter, but the application is executed in a JavaScript engine that predates the support of FinalizationRegistry (introduced in node v14.6.0, for instance), then the Firebase SDK will not be able to automatically clean up the FirebaseServerApp instance and an error will be thrown. |

## FirebaseServerAppSettings.appCheckToken

An optional AppCheck token.

If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be monitored by invoking the FirebaseServerApp.appCheckTokenVerified(). Awaiting the Promise returned by appCheckTokenVerified is highly recommended if an AppCheck token is provided.

If the token has been properly verified then the AppCheck token will be automatically used by Firebase SDKs that support App Check.

If the token fails verification then a warning is logged and the token will not be used.

<b>Signature:</b>

```typescript
appCheckToken?: string;
```

## FirebaseServerAppSettings.authIdToken

An optional Auth ID token used to resume a signed in user session from a client runtime environment.

If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be queried via by the application by invoking the FirebaseServerApp.authIdTokenVerified(). Awaiting the Promise returned by authIdTokenVerified is highly recommended if an Auth ID token is provided.

Once the token has been properly verified then invoking getAuth() will attempt to automatically sign in a user with the provided Auth ID Token.

If the token fails verification then a warning is logged and Auth SDK will not attempt to sign in a user upon its initalization.

<b>Signature:</b>

```typescript
authIdToken?: string;
```

## FirebaseServerAppSettings.installationsAuthToken

An optional Installation Auth token.

If provided, the FirebaseServerApp instance will work to validate the token. The result of the validation can be monitored by invoking the FirebaseServerApp.installationTokenVerified(). Awaiting the Promise returned by appCheckTokenVerified is highly recommended before initalization any other Firebase SDKs.

If the token has been properly verified then the Installation Auth token will be automatically used by Firebase SDKs that support Firebase Installations.

If the token fails verification then a warning is logged and the token will not be used.

<b>Signature:</b>

```typescript
installationsAuthToken?: string;
```

## FirebaseServerAppSettings.name

There is no get for FirebaseServerApps, so the name is not relevant. however it's always a blank string so that FirebaseServerApp conforms to the FirebaseApp interface declaration.

<b>Signature:</b>

```typescript
name?: "";
```

## FirebaseServerAppSettings.releaseOnDeref

An optional object. If provided, the Firebase SDK will use a FinalizationRegistry object to monitor the Garbage Collection status of the provided object, and the Firebase SDK will release its refrence on the FirebaseServerApp instance when the provided object is collected. or.

The intent of this field is to help reduce memory overhead for long-running cloud functions executing SSR fulfillment without the customer's app needing to orchestrate FirebaseServerApp cleanup. Additionally, prexisting FirebaseServerApp instances may reused if they're identical to a previously generated one that has yet to be deleted.

If the object is not provided then the application must clean up the FirebaseServerApp instance through the applicationss own standard mechanisms by invoking deleteApp.

If the app provides an object in this parameter, but the application is executed in a JavaScript engine that predates the support of FinalizationRegistry (introduced in node v14.6.0, for instance), then the Firebase SDK will not be able to automatically clean up the FirebaseServerApp instance and an error will be thrown.

<b>Signature:</b>

```typescript
releaseOnDeref?: object;
```
59 changes: 59 additions & 0 deletions docs-devsite/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ This package coordinates the communication between the different Firebase compon
| [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | A [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) holds the initialization information for a collection of services.<!-- -->Do not call this constructor directly. Instead, use [initializeApp()](./app.md#initializeapp_cb2f5e1) to create an app. |
| [FirebaseAppSettings](./app.firebaseappsettings.md#firebaseappsettings_interface) | Configuration options given to [initializeApp()](./app.md#initializeapp_cb2f5e1) |
| [FirebaseOptions](./app.firebaseoptions.md#firebaseoptions_interface) | Firebase configuration object. Contains a set of parameters required by services in order to successfully communicate with Firebase server APIs and to associate client data with your Firebase project and Firebase application. Typically this object is populated by the Firebase console at project setup. See also: [Learn about the Firebase config object](https://firebase.google.com/docs/web/setup#config-object)<!-- -->. |
| [FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface) | A [FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface) holds the initialization information for a collection of services running in server enviornments.<!-- -->Do not call this constructor directly. Instead, use to create an app. |
| [FirebaseServerAppSettings](./app.firebaseserverappsettings.md#firebaseserverappsettings_interface) | Configuration options given to [initializeServerApp()](./app.md#initializeserverapp) |

## Variables

| Variable | Description |
| --- | --- |
| [\_serverApps](./app.md#_serverapps) | |
| [SDK\_VERSION](./app.md#sdk_version) | The current SDK version. |

## function(app, ...)
Expand Down Expand Up @@ -309,6 +312,62 @@ export declare function initializeApp(options: FirebaseOptions, config?: Firebas

[FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)

## initializeServerApp()

Creates and initializes a [FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface) instance.

The FirebaseServerApp is similar to FirebaseApp, but is intended for execution in server side rendering environments only.

See [Add Firebase to your app](https://firebase.google.com/docs/web/setup#add_firebase_to_your_app) and [Initialize multiple projects](https://firebase.google.com/docs/web/setup#multiple-projects) for detailed documentation.

<b>Signature:</b>

```typescript
export declare function initializeServerApp(options: FirebaseOptions | FirebaseApp, config: FirebaseServerAppSettings): FirebaseServerApp;
```

### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | [FirebaseOptions](./app.firebaseoptions.md#firebaseoptions_interface) \| [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | Firebase.AppOptions to configure the app's services, or a a FirebaseApp instance which contains the AppOptions within. |
| config | [FirebaseServerAppSettings](./app.firebaseserverappsettings.md#firebaseserverappsettings_interface) | FirebaseServerApp configuration. |

<b>Returns:</b>

[FirebaseServerApp](./app.firebaseserverapp.md#firebaseserverapp_interface)

The initialized FirebaseServerApp.

### Example


```javascript

// Initialize a FirebaseServerApp.
// Retrieve your own options values by adding a web app on
// https://console.firebase.google.com
initializeServerApp({
apiKey: "AIza....", // Auth / General Use
authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
storageBucket: "YOUR_APP.appspot.com", // Storage
messagingSenderId: "123456789" // Cloud Messaging
},
{
authIdToken: "Your Auth ID Token"
});

```

## \_serverApps

<b>Signature:</b>

```typescript
_serverApps: Map<string, FirebaseServerApp>
```

## SDK\_VERSION

The current SDK version.
Expand Down
Loading