@firebase/app 0.9.29 → 0.10.0-canary.42fcdfe4c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.d.ts CHANGED
@@ -197,6 +197,88 @@ export declare interface FirebaseOptions {
197
197
  measurementId?: string;
198
198
  }
199
199
 
200
+ /**
201
+ * A {@link @firebase/app#FirebaseServerApp} holds the initialization information
202
+ * for a collection of services running in server environments.
203
+ *
204
+ * Do not call this constructor directly. Instead, use
205
+ * {@link (initializeServerApp:1) | initializeServerApp()} to create
206
+ * an app.
207
+ *
208
+ * @public
209
+ */
210
+ export declare interface FirebaseServerApp extends FirebaseApp {
211
+ /**
212
+ * There is no `getApp()` operation for `FirebaseServerApp`, so the name is not relevant for
213
+ * applications. However, it may be used internally, and is declared here so that
214
+ * `FirebaseServerApp` conforms to the `FirebaseApp` interface.
215
+ */
216
+ name: string;
217
+ /**
218
+ * The (read-only) configuration settings for this server app. These are the original
219
+ * parameters given in {@link (initializeServerApp:1) | initializeServerApp()}.
220
+ *
221
+ * @example
222
+ * ```javascript
223
+ * const app = initializeServerApp(settings);
224
+ * console.log(app.settings.authIdToken === options.authIdToken); // true
225
+ * ```
226
+ */
227
+ readonly settings: FirebaseServerAppSettings;
228
+ }
229
+
230
+ /**
231
+ * @public
232
+ *
233
+ * Configuration options given to {@link (initializeServerApp:1) | initializeServerApp()}
234
+ */
235
+ export declare interface FirebaseServerAppSettings extends FirebaseAppSettings {
236
+ /**
237
+ * An optional Auth ID token used to resume a signed in user session from a client
238
+ * runtime environment.
239
+ *
240
+ * Invoking `getAuth` with a `FirebaseServerApp` configured with a validated `authIdToken`
241
+ * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
242
+ * needs to have been recently minted for this operation to succeed.
243
+ *
244
+ * If the token fails local verification, or if the Auth service has failed to validate it when
245
+ * the Auth SDK is initialized, then a warning is logged to the console and the Auth SDK will not
246
+ * sign in a user on initalization.
247
+ *
248
+ * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
249
+ * is invoked with the `User` object as per standard Auth flows. However, `User` objects
250
+ * created via an `authIdToken` do not have a refresh token. Attempted `refreshToken`
251
+ * operations fail.
252
+ */
253
+ authIdToken?: string;
254
+ /**
255
+ * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
256
+ * object to monitor the garbage collection status of the provided object. The
257
+ * Firebase SDK releases its reference on the `FirebaseServerApp` instance when the
258
+ * provided `releaseOnDeref` object is garbage collected.
259
+ *
260
+ * You can use this field to reduce memory management overhead for your application.
261
+ * If provided, an app running in a SSR pass does not need to perform
262
+ * `FirebaseServerApp` cleanup, so long as the reference object is deleted (by falling out of
263
+ * SSR scope, for instance.)
264
+ *
265
+ * If an object is not provided then the application must clean up the `FirebaseServerApp`
266
+ * instance by invoking `deleteApp`.
267
+ *
268
+ * If the application provides an object in this parameter, but the application is
269
+ * executed in a JavaScript engine that predates the support of `FinalizationRegistry`
270
+ * (introduced in node v14.6.0, for instance), then an error is thrown at `FirebaseServerApp`
271
+ * initialization.
272
+ */
273
+ releaseOnDeref?: object;
274
+ /**
275
+ * There is no `getApp()` operation for `FirebaseServerApp`, so the name is not relevant for
276
+ * applications. However, it may be used internally, and is declared here so that
277
+ * `FirebaseServerApp` conforms to the `FirebaseApp` interface.
278
+ */
279
+ name?: undefined;
280
+ }
281
+
200
282
  /**
201
283
  * @internal
202
284
  */
@@ -320,6 +402,69 @@ export declare function initializeApp(options: FirebaseOptions, config?: Firebas
320
402
  */
321
403
  export declare function initializeApp(): FirebaseApp;
322
404
 
405
+ /**
406
+ * Creates and initializes a {@link @firebase/app#FirebaseServerApp} instance.
407
+ *
408
+ * The `FirebaseServerApp` is similar to `FirebaseApp`, but is intended for execution in
409
+ * server side rendering environments only. Initialization will fail if invoked from a
410
+ * browser environment.
411
+ *
412
+ * See
413
+ * {@link
414
+ * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app
415
+ * | Add Firebase to your app} and
416
+ * {@link
417
+ * https://firebase.google.com/docs/web/setup#multiple-projects
418
+ * | Initialize multiple projects} for detailed documentation.
419
+ *
420
+ * @example
421
+ * ```javascript
422
+ *
423
+ * // Initialize an instance of `FirebaseServerApp`.
424
+ * // Retrieve your own options values by adding a web app on
425
+ * // https://console.firebase.google.com
426
+ * initializeServerApp({
427
+ * apiKey: "AIza....", // Auth / General Use
428
+ * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
429
+ * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
430
+ * storageBucket: "YOUR_APP.appspot.com", // Storage
431
+ * messagingSenderId: "123456789" // Cloud Messaging
432
+ * },
433
+ * {
434
+ * authIdToken: "Your Auth ID Token"
435
+ * });
436
+ * ```
437
+ *
438
+ * @param options - `Firebase.AppOptions` to configure the app's services, or a
439
+ * a `FirebaseApp` instance which contains the `AppOptions` within.
440
+ * @param config - `FirebaseServerApp` configuration.
441
+ *
442
+ * @returns The initialized `FirebaseServerApp`.
443
+ *
444
+ * @public
445
+ */
446
+ export declare function initializeServerApp(options: FirebaseOptions | FirebaseApp, config: FirebaseServerAppSettings): FirebaseServerApp;
447
+
448
+ /**
449
+ *
450
+ * @param obj - an object of type FirebaseApp or FirebaseOptions.
451
+ *
452
+ * @returns true if the provide object is of type FirebaseApp.
453
+ *
454
+ * @internal
455
+ */
456
+ export declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj is FirebaseApp;
457
+
458
+ /**
459
+ *
460
+ * @param obj - an object of type FirebaseApp.
461
+ *
462
+ * @returns true if the provided object is of type FirebaseServerAppImpl.
463
+ *
464
+ * @internal
465
+ */
466
+ export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
467
+
323
468
  /**
324
469
  * Sets log handler for all Firebase SDKs.
325
470
  * @param logCallback - An optional custom log handler that executes user code whenever
@@ -365,6 +510,11 @@ export declare function _removeServiceInstance<T extends Name>(app: FirebaseApp,
365
510
  */
366
511
  export declare const SDK_VERSION: string;
367
512
 
513
+ /**
514
+ * @internal
515
+ */
516
+ export declare const _serverApps: Map<string, FirebaseServerApp>;
517
+
368
518
  /**
369
519
  * Sets log level for all Firebase SDKs.
370
520
  *
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { FirebaseApp, FirebaseOptions, FirebaseAppSettings } from './public-types';
17
+ import { FirebaseApp, FirebaseServerApp, FirebaseOptions, FirebaseAppSettings, FirebaseServerAppSettings } from './public-types';
18
18
  import { LogLevelString, LogCallback, LogOptions } from '@firebase/logger';
19
19
  export { FirebaseError } from '@firebase/util';
20
20
  /**
@@ -83,6 +83,48 @@ export declare function initializeApp(options: FirebaseOptions, config?: Firebas
83
83
  * @public
84
84
  */
85
85
  export declare function initializeApp(): FirebaseApp;
86
+ /**
87
+ * Creates and initializes a {@link @firebase/app#FirebaseServerApp} instance.
88
+ *
89
+ * The `FirebaseServerApp` is similar to `FirebaseApp`, but is intended for execution in
90
+ * server side rendering environments only. Initialization will fail if invoked from a
91
+ * browser environment.
92
+ *
93
+ * See
94
+ * {@link
95
+ * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app
96
+ * | Add Firebase to your app} and
97
+ * {@link
98
+ * https://firebase.google.com/docs/web/setup#multiple-projects
99
+ * | Initialize multiple projects} for detailed documentation.
100
+ *
101
+ * @example
102
+ * ```javascript
103
+ *
104
+ * // Initialize an instance of `FirebaseServerApp`.
105
+ * // Retrieve your own options values by adding a web app on
106
+ * // https://console.firebase.google.com
107
+ * initializeServerApp({
108
+ * apiKey: "AIza....", // Auth / General Use
109
+ * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
110
+ * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
111
+ * storageBucket: "YOUR_APP.appspot.com", // Storage
112
+ * messagingSenderId: "123456789" // Cloud Messaging
113
+ * },
114
+ * {
115
+ * authIdToken: "Your Auth ID Token"
116
+ * });
117
+ * ```
118
+ *
119
+ * @param options - `Firebase.AppOptions` to configure the app's services, or a
120
+ * a `FirebaseApp` instance which contains the `AppOptions` within.
121
+ * @param config - `FirebaseServerApp` configuration.
122
+ *
123
+ * @returns The initialized `FirebaseServerApp`.
124
+ *
125
+ * @public
126
+ */
127
+ export declare function initializeServerApp(options: FirebaseOptions | FirebaseApp, config: FirebaseServerAppSettings): FirebaseServerApp;
86
128
  /**
87
129
  * Retrieves a {@link @firebase/app#FirebaseApp} instance.
88
130
  *
@@ -20,13 +20,16 @@ export declare const enum AppError {
20
20
  BAD_APP_NAME = "bad-app-name",
21
21
  DUPLICATE_APP = "duplicate-app",
22
22
  APP_DELETED = "app-deleted",
23
+ SERVER_APP_DELETED = "server-app-deleted",
23
24
  NO_OPTIONS = "no-options",
24
25
  INVALID_APP_ARGUMENT = "invalid-app-argument",
25
26
  INVALID_LOG_ARGUMENT = "invalid-log-argument",
26
27
  IDB_OPEN = "idb-open",
27
28
  IDB_GET = "idb-get",
28
29
  IDB_WRITE = "idb-set",
29
- IDB_DELETE = "idb-delete"
30
+ IDB_DELETE = "idb-delete",
31
+ FINALIZATION_REGISTRY_NOT_SUPPORTED = "finalization-registry-not-supported",
32
+ INVALID_SERVER_APP_ENVIRONMENT = "invalid-server-app-environment"
30
33
  }
31
34
  interface ErrorParams {
32
35
  [AppError.NO_APP]: {
@@ -56,6 +59,9 @@ interface ErrorParams {
56
59
  [AppError.IDB_DELETE]: {
57
60
  originalErrorMessage?: string;
58
61
  };
62
+ [AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED]: {
63
+ appName?: string;
64
+ };
59
65
  }
60
66
  export declare const ERROR_FACTORY: ErrorFactory<AppError, ErrorParams>;
61
67
  export {};
@@ -17,8 +17,8 @@
17
17
  import { FirebaseApp, FirebaseOptions, FirebaseAppSettings } from './public-types';
18
18
  import { ComponentContainer } from '@firebase/component';
19
19
  export declare class FirebaseAppImpl implements FirebaseApp {
20
- private readonly _options;
21
- private readonly _name;
20
+ protected readonly _options: FirebaseOptions;
21
+ protected readonly _name: string;
22
22
  /**
23
23
  * Original config values passed in as a constructor parameter.
24
24
  * It is only used to compare with another config object to support idempotent initializeApp().
@@ -27,7 +27,7 @@ export declare class FirebaseAppImpl implements FirebaseApp {
27
27
  */
28
28
  private readonly _config;
29
29
  private _automaticDataCollectionEnabled;
30
- private _isDeleted;
30
+ protected _isDeleted: boolean;
31
31
  private readonly _container;
32
32
  constructor(options: FirebaseOptions, config: Required<FirebaseAppSettings>, container: ComponentContainer);
33
33
  get automaticDataCollectionEnabled(): boolean;
@@ -42,5 +42,5 @@ export declare class FirebaseAppImpl implements FirebaseApp {
42
42
  * This function will throw an Error if the App has already been deleted -
43
43
  * use before performing API actions on the App.
44
44
  */
45
- private checkDestroyed;
45
+ protected checkDestroyed(): void;
46
46
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseServerApp, FirebaseServerAppSettings, FirebaseOptions } from './public-types';
18
+ import { ComponentContainer } from '@firebase/component';
19
+ import { FirebaseAppImpl } from './firebaseApp';
20
+ export declare class FirebaseServerAppImpl extends FirebaseAppImpl implements FirebaseServerApp {
21
+ private readonly _serverConfig;
22
+ private _finalizationRegistry;
23
+ private _refCount;
24
+ constructor(options: FirebaseOptions | FirebaseAppImpl, serverConfig: FirebaseServerAppSettings, name: string, container: ComponentContainer);
25
+ get refCount(): number;
26
+ incRefCount(obj: object | undefined): void;
27
+ decRefCount(): number;
28
+ private automaticCleanup;
29
+ get settings(): FirebaseServerAppSettings;
30
+ /**
31
+ * This function will throw an Error if the App has already been deleted -
32
+ * use before performing API actions on the App.
33
+ */
34
+ protected checkDestroyed(): void;
35
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';
@@ -14,13 +14,17 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { FirebaseApp } from './public-types';
17
+ import { FirebaseApp, FirebaseOptions, FirebaseServerApp } from './public-types';
18
18
  import { Component, Provider, Name } from '@firebase/component';
19
19
  import { DEFAULT_ENTRY_NAME } from './constants';
20
20
  /**
21
21
  * @internal
22
22
  */
23
23
  export declare const _apps: Map<string, FirebaseApp>;
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare const _serverApps: Map<string, FirebaseServerApp>;
24
28
  /**
25
29
  * Registered components.
26
30
  *
@@ -65,6 +69,24 @@ export declare function _getProvider<T extends Name>(app: FirebaseApp, name: T):
65
69
  * @internal
66
70
  */
67
71
  export declare function _removeServiceInstance<T extends Name>(app: FirebaseApp, name: T, instanceIdentifier?: string): void;
72
+ /**
73
+ *
74
+ * @param obj - an object of type FirebaseApp or FirebaseOptions.
75
+ *
76
+ * @returns true if the provide object is of type FirebaseApp.
77
+ *
78
+ * @internal
79
+ */
80
+ export declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj is FirebaseApp;
81
+ /**
82
+ *
83
+ * @param obj - an object of type FirebaseApp.
84
+ *
85
+ * @returns true if the provided object is of type FirebaseServerAppImpl.
86
+ *
87
+ * @internal
88
+ */
89
+ export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
68
90
  /**
69
91
  * Test only
70
92
  *
@@ -62,6 +62,35 @@ export interface FirebaseApp {
62
62
  */
63
63
  automaticDataCollectionEnabled: boolean;
64
64
  }
65
+ /**
66
+ * A {@link @firebase/app#FirebaseServerApp} holds the initialization information
67
+ * for a collection of services running in server environments.
68
+ *
69
+ * Do not call this constructor directly. Instead, use
70
+ * {@link (initializeServerApp:1) | initializeServerApp()} to create
71
+ * an app.
72
+ *
73
+ * @public
74
+ */
75
+ export interface FirebaseServerApp extends FirebaseApp {
76
+ /**
77
+ * There is no `getApp()` operation for `FirebaseServerApp`, so the name is not relevant for
78
+ * applications. However, it may be used internally, and is declared here so that
79
+ * `FirebaseServerApp` conforms to the `FirebaseApp` interface.
80
+ */
81
+ name: string;
82
+ /**
83
+ * The (read-only) configuration settings for this server app. These are the original
84
+ * parameters given in {@link (initializeServerApp:1) | initializeServerApp()}.
85
+ *
86
+ * @example
87
+ * ```javascript
88
+ * const app = initializeServerApp(settings);
89
+ * console.log(app.settings.authIdToken === options.authIdToken); // true
90
+ * ```
91
+ */
92
+ readonly settings: FirebaseServerAppSettings;
93
+ }
65
94
  /**
66
95
  * @public
67
96
  *
@@ -128,6 +157,57 @@ export interface FirebaseAppSettings {
128
157
  */
129
158
  automaticDataCollectionEnabled?: boolean;
130
159
  }
160
+ /**
161
+ * @public
162
+ *
163
+ * Configuration options given to {@link (initializeServerApp:1) | initializeServerApp()}
164
+ */
165
+ export interface FirebaseServerAppSettings extends FirebaseAppSettings {
166
+ /**
167
+ * An optional Auth ID token used to resume a signed in user session from a client
168
+ * runtime environment.
169
+ *
170
+ * Invoking `getAuth` with a `FirebaseServerApp` configured with a validated `authIdToken`
171
+ * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
172
+ * needs to have been recently minted for this operation to succeed.
173
+ *
174
+ * If the token fails local verification, or if the Auth service has failed to validate it when
175
+ * the Auth SDK is initialized, then a warning is logged to the console and the Auth SDK will not
176
+ * sign in a user on initalization.
177
+ *
178
+ * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
179
+ * is invoked with the `User` object as per standard Auth flows. However, `User` objects
180
+ * created via an `authIdToken` do not have a refresh token. Attempted `refreshToken`
181
+ * operations fail.
182
+ */
183
+ authIdToken?: string;
184
+ /**
185
+ * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
186
+ * object to monitor the garbage collection status of the provided object. The
187
+ * Firebase SDK releases its reference on the `FirebaseServerApp` instance when the
188
+ * provided `releaseOnDeref` object is garbage collected.
189
+ *
190
+ * You can use this field to reduce memory management overhead for your application.
191
+ * If provided, an app running in a SSR pass does not need to perform
192
+ * `FirebaseServerApp` cleanup, so long as the reference object is deleted (by falling out of
193
+ * SSR scope, for instance.)
194
+ *
195
+ * If an object is not provided then the application must clean up the `FirebaseServerApp`
196
+ * instance by invoking `deleteApp`.
197
+ *
198
+ * If the application provides an object in this parameter, but the application is
199
+ * executed in a JavaScript engine that predates the support of `FinalizationRegistry`
200
+ * (introduced in node v14.6.0, for instance), then an error is thrown at `FirebaseServerApp`
201
+ * initialization.
202
+ */
203
+ releaseOnDeref?: object;
204
+ /**
205
+ * There is no `getApp()` operation for `FirebaseServerApp`, so the name is not relevant for
206
+ * applications. However, it may be used internally, and is declared here so that
207
+ * `FirebaseServerApp` conforms to the `FirebaseApp` interface.
208
+ */
209
+ name?: undefined;
210
+ }
131
211
  /**
132
212
  * @internal
133
213
  */