@firebase/app 0.10.18 → 0.11.0-20250205220033

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.
@@ -439,9 +439,11 @@ interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'name'> {
439
439
  * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
440
440
  * needs to have been recently minted for this operation to succeed.
441
441
  *
442
- * If the token fails local verification, or if the Auth service has failed to validate it when
443
- * the Auth SDK is initialized, then a warning is logged to the console and the Auth SDK will not
444
- * sign in a user on initialization.
442
+ * If the token fails local verification due to expiration or parsing errors, then a console error
443
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
444
+ *
445
+ * If the Auth service has failed to validate the token when the Auth SDK is initialized, then an
446
+ * warning is logged to the console and the Auth SDK will not sign in a user on initialization.
445
447
  *
446
448
  * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
447
449
  * is invoked with the `User` object as per standard Auth flows. However, `User` objects
@@ -449,6 +451,14 @@ interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'name'> {
449
451
  * operations fail.
450
452
  */
451
453
  authIdToken?: string;
454
+ /**
455
+ * An optional App Check token. If provided, the Firebase SDKs that use App Check will utilize
456
+ * this App Check token in place of requiring an instance of App Check to be initialized.
457
+ *
458
+ * If the token fails local verification due to expiration or parsing errors, then a console error
459
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
460
+ */
461
+ appCheckToken?: string;
452
462
  /**
453
463
  * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
454
464
  * object to monitor the garbage collection status of the provided object. The
@@ -881,7 +891,7 @@ declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj is Fire
881
891
  *
882
892
  * @internal
883
893
  */
884
- declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
894
+ declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp | null | undefined): obj is FirebaseServerApp;
885
895
  /**
886
896
  * Test only
887
897
  *
@@ -17,6 +17,7 @@
17
17
  import { ComponentContainer } from '@firebase/component';
18
18
  import { FirebaseApp } from './public-types';
19
19
  import { HeartbeatsByUserAgent, HeartbeatService, HeartbeatsInIndexedDB, HeartbeatStorage, SingleDateHeartbeat } from './types';
20
+ export declare const MAX_NUM_STORED_HEARTBEATS = 30;
20
21
  export declare class HeartbeatServiceImpl implements HeartbeatService {
21
22
  private readonly container;
22
23
  /**
@@ -81,3 +82,8 @@ export declare class HeartbeatStorageImpl implements HeartbeatStorage {
81
82
  * to base 64.
82
83
  */
83
84
  export declare function countBytes(heartbeatsCache: HeartbeatsByUserAgent[]): number;
85
+ /**
86
+ * Returns the index of the heartbeat with the earliest date.
87
+ * If the heartbeats array is empty, -1 is returned.
88
+ */
89
+ export declare function getEarliestHeartbeatIdx(heartbeats: SingleDateHeartbeat[]): number;
@@ -86,7 +86,7 @@ export declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj
86
86
  *
87
87
  * @internal
88
88
  */
89
- export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
89
+ export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp | null | undefined): obj is FirebaseServerApp;
90
90
  /**
91
91
  * Test only
92
92
  *
@@ -171,9 +171,11 @@ export interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'na
171
171
  * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
172
172
  * needs to have been recently minted for this operation to succeed.
173
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 initialization.
174
+ * If the token fails local verification due to expiration or parsing errors, then a console error
175
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
176
+ *
177
+ * If the Auth service has failed to validate the token when the Auth SDK is initialized, then an
178
+ * warning is logged to the console and the Auth SDK will not sign in a user on initialization.
177
179
  *
178
180
  * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
179
181
  * is invoked with the `User` object as per standard Auth flows. However, `User` objects
@@ -181,6 +183,14 @@ export interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'na
181
183
  * operations fail.
182
184
  */
183
185
  authIdToken?: string;
186
+ /**
187
+ * An optional App Check token. If provided, the Firebase SDKs that use App Check will utilize
188
+ * this App Check token in place of requiring an instance of App Check to be initialized.
189
+ *
190
+ * If the token fails local verification due to expiration or parsing errors, then a console error
191
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
192
+ */
193
+ appCheckToken?: string;
184
194
  /**
185
195
  * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
186
196
  * object to monitor the garbage collection status of the provided object. The
@@ -207,9 +207,11 @@ export declare interface FirebaseServerAppSettings extends Omit<FirebaseAppSetti
207
207
  * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
208
208
  * needs to have been recently minted for this operation to succeed.
209
209
  *
210
- * If the token fails local verification, or if the Auth service has failed to validate it when
211
- * the Auth SDK is initialized, then a warning is logged to the console and the Auth SDK will not
212
- * sign in a user on initialization.
210
+ * If the token fails local verification due to expiration or parsing errors, then a console error
211
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
212
+ *
213
+ * If the Auth service has failed to validate the token when the Auth SDK is initialized, then an
214
+ * warning is logged to the console and the Auth SDK will not sign in a user on initialization.
213
215
  *
214
216
  * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
215
217
  * is invoked with the `User` object as per standard Auth flows. However, `User` objects
@@ -217,6 +219,14 @@ export declare interface FirebaseServerAppSettings extends Omit<FirebaseAppSetti
217
219
  * operations fail.
218
220
  */
219
221
  authIdToken?: string;
222
+ /**
223
+ * An optional App Check token. If provided, the Firebase SDKs that use App Check will utilize
224
+ * this App Check token in place of requiring an instance of App Check to be initialized.
225
+ *
226
+ * If the token fails local verification due to expiration or parsing errors, then a console error
227
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
228
+ */
229
+ appCheckToken?: string;
220
230
  /**
221
231
  * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
222
232
  * object to monitor the garbage collection status of the provided object. The
package/dist/app.d.ts CHANGED
@@ -241,9 +241,11 @@ export declare interface FirebaseServerAppSettings extends Omit<FirebaseAppSetti
241
241
  * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
242
242
  * needs to have been recently minted for this operation to succeed.
243
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 initialization.
244
+ * If the token fails local verification due to expiration or parsing errors, then a console error
245
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
246
+ *
247
+ * If the Auth service has failed to validate the token when the Auth SDK is initialized, then an
248
+ * warning is logged to the console and the Auth SDK will not sign in a user on initialization.
247
249
  *
248
250
  * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
249
251
  * is invoked with the `User` object as per standard Auth flows. However, `User` objects
@@ -251,6 +253,14 @@ export declare interface FirebaseServerAppSettings extends Omit<FirebaseAppSetti
251
253
  * operations fail.
252
254
  */
253
255
  authIdToken?: string;
256
+ /**
257
+ * An optional App Check token. If provided, the Firebase SDKs that use App Check will utilize
258
+ * this App Check token in place of requiring an instance of App Check to be initialized.
259
+ *
260
+ * If the token fails local verification due to expiration or parsing errors, then a console error
261
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
262
+ */
263
+ appCheckToken?: string;
254
264
  /**
255
265
  * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
256
266
  * object to monitor the garbage collection status of the provided object. The
@@ -457,7 +467,7 @@ export declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj
457
467
  *
458
468
  * @internal
459
469
  */
460
- export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
470
+ export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp | null | undefined): obj is FirebaseServerApp;
461
471
 
462
472
  /**
463
473
  * Sets log handler for all Firebase SDKs.
@@ -17,6 +17,7 @@
17
17
  import { ComponentContainer } from '@firebase/component';
18
18
  import { FirebaseApp } from './public-types';
19
19
  import { HeartbeatsByUserAgent, HeartbeatService, HeartbeatsInIndexedDB, HeartbeatStorage, SingleDateHeartbeat } from './types';
20
+ export declare const MAX_NUM_STORED_HEARTBEATS = 30;
20
21
  export declare class HeartbeatServiceImpl implements HeartbeatService {
21
22
  private readonly container;
22
23
  /**
@@ -81,3 +82,8 @@ export declare class HeartbeatStorageImpl implements HeartbeatStorage {
81
82
  * to base 64.
82
83
  */
83
84
  export declare function countBytes(heartbeatsCache: HeartbeatsByUserAgent[]): number;
85
+ /**
86
+ * Returns the index of the heartbeat with the earliest date.
87
+ * If the heartbeats array is empty, -1 is returned.
88
+ */
89
+ export declare function getEarliestHeartbeatIdx(heartbeats: SingleDateHeartbeat[]): number;
@@ -86,7 +86,7 @@ export declare function _isFirebaseApp(obj: FirebaseApp | FirebaseOptions): obj
86
86
  *
87
87
  * @internal
88
88
  */
89
- export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp): obj is FirebaseServerApp;
89
+ export declare function _isFirebaseServerApp(obj: FirebaseApp | FirebaseServerApp | null | undefined): obj is FirebaseServerApp;
90
90
  /**
91
91
  * Test only
92
92
  *
@@ -171,9 +171,11 @@ export interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'na
171
171
  * causes an automatic attempt to sign in the user that the `authIdToken` represents. The token
172
172
  * needs to have been recently minted for this operation to succeed.
173
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 initialization.
174
+ * If the token fails local verification due to expiration or parsing errors, then a console error
175
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
176
+ *
177
+ * If the Auth service has failed to validate the token when the Auth SDK is initialized, then an
178
+ * warning is logged to the console and the Auth SDK will not sign in a user on initialization.
177
179
  *
178
180
  * If a user is successfully signed in, then the Auth instance's `onAuthStateChanged` callback
179
181
  * is invoked with the `User` object as per standard Auth flows. However, `User` objects
@@ -181,6 +183,14 @@ export interface FirebaseServerAppSettings extends Omit<FirebaseAppSettings, 'na
181
183
  * operations fail.
182
184
  */
183
185
  authIdToken?: string;
186
+ /**
187
+ * An optional App Check token. If provided, the Firebase SDKs that use App Check will utilize
188
+ * this App Check token in place of requiring an instance of App Check to be initialized.
189
+ *
190
+ * If the token fails local verification due to expiration or parsing errors, then a console error
191
+ * is logged at the time of initialization of the `FirebaseServerApp` instance.
192
+ */
193
+ appCheckToken?: string;
184
194
  /**
185
195
  * An optional object. If provided, the Firebase SDK uses a `FinalizationRegistry`
186
196
  * object to monitor the garbage collection status of the provided object. The
@@ -1,6 +1,6 @@
1
1
  import { Component, ComponentContainer } from '@firebase/component';
2
2
  import { Logger, setUserLogHandler, setLogLevel as setLogLevel$1 } from '@firebase/logger';
3
- import { ErrorFactory, getDefaultAppConfig, deepEqual, isBrowser, isWebWorker, FirebaseError, base64urlEncodeWithoutPadding, isIndexedDBAvailable, validateIndexedDBOpenable } from '@firebase/util';
3
+ import { ErrorFactory, base64Decode, getDefaultAppConfig, deepEqual, isBrowser, isWebWorker, FirebaseError, base64urlEncodeWithoutPadding, isIndexedDBAvailable, validateIndexedDBOpenable } from '@firebase/util';
4
4
  export { FirebaseError } from '@firebase/util';
5
5
  import { openDB } from 'idb';
6
6
 
@@ -58,7 +58,7 @@ function isVersionServiceProvider(provider) {
58
58
  }
59
59
 
60
60
  const name$q = "@firebase/app";
61
- const version$1 = "0.10.18";
61
+ const version$1 = "0.11.0-20250205220033";
62
62
 
63
63
  /**
64
64
  * @license
@@ -129,7 +129,7 @@ const name$2 = "@firebase/vertexai";
129
129
  const name$1 = "@firebase/firestore-compat";
130
130
 
131
131
  const name = "firebase";
132
- const version = "11.2.0";
132
+ const version = "11.3.0-20250205220033";
133
133
 
134
134
  /**
135
135
  * @license
@@ -307,6 +307,9 @@ function _isFirebaseApp(obj) {
307
307
  * @internal
308
308
  */
309
309
  function _isFirebaseServerApp(obj) {
310
+ if (obj === null || obj === undefined) {
311
+ return false;
312
+ }
310
313
  return obj.settings !== undefined;
311
314
  }
312
315
  /**
@@ -437,6 +440,27 @@ class FirebaseAppImpl {
437
440
  * See the License for the specific language governing permissions and
438
441
  * limitations under the License.
439
442
  */
443
+ // Parse the token and check to see if the `exp` claim is in the future.
444
+ // Reports an error to the console if the token or claim could not be parsed, or if `exp` is in
445
+ // the past.
446
+ function validateTokenTTL(base64Token, tokenName) {
447
+ const secondPart = base64Decode(base64Token.split('.')[1]);
448
+ if (secondPart === null) {
449
+ console.error(`FirebaseServerApp ${tokenName} is invalid: second part could not be parsed.`);
450
+ return;
451
+ }
452
+ const expClaim = JSON.parse(secondPart).exp;
453
+ if (expClaim === undefined) {
454
+ console.error(`FirebaseServerApp ${tokenName} is invalid: expiration claim could not be parsed`);
455
+ return;
456
+ }
457
+ const exp = JSON.parse(secondPart).exp * 1000;
458
+ const now = new Date().getTime();
459
+ const diff = exp - now;
460
+ if (diff <= 0) {
461
+ console.error(`FirebaseServerApp ${tokenName} is invalid: the token has expired.`);
462
+ }
463
+ }
440
464
  class FirebaseServerAppImpl extends FirebaseAppImpl {
441
465
  constructor(options, serverConfig, name, container) {
442
466
  // Build configuration parameters for the FirebaseAppImpl base class.
@@ -458,6 +482,14 @@ class FirebaseServerAppImpl extends FirebaseAppImpl {
458
482
  }
459
483
  // Now construct the data for the FirebaseServerAppImpl.
460
484
  this._serverConfig = Object.assign({ automaticDataCollectionEnabled }, serverConfig);
485
+ // Ensure that the current time is within the `authIdtoken` window of validity.
486
+ if (this._serverConfig.authIdToken) {
487
+ validateTokenTTL(this._serverConfig.authIdToken, 'authIdToken');
488
+ }
489
+ // Ensure that the current time is within the `appCheckToken` window of validity.
490
+ if (this._serverConfig.appCheckToken) {
491
+ validateTokenTTL(this._serverConfig.appCheckToken, 'appCheckToken');
492
+ }
461
493
  this._finalizationRegistry = null;
462
494
  if (typeof FinalizationRegistry !== 'undefined') {
463
495
  this._finalizationRegistry = new FinalizationRegistry(() => {
@@ -878,8 +910,7 @@ function computeKey(app) {
878
910
  * limitations under the License.
879
911
  */
880
912
  const MAX_HEADER_BYTES = 1024;
881
- // 30 days
882
- const STORED_HEARTBEAT_RETENTION_MAX_MILLIS = 30 * 24 * 60 * 60 * 1000;
913
+ const MAX_NUM_STORED_HEARTBEATS = 30;
883
914
  class HeartbeatServiceImpl {
884
915
  constructor(container) {
885
916
  this.container = container;
@@ -933,14 +964,13 @@ class HeartbeatServiceImpl {
933
964
  else {
934
965
  // There is no entry for this date. Create one.
935
966
  this._heartbeatsCache.heartbeats.push({ date, agent });
967
+ // If the number of stored heartbeats exceeds the maximum number of stored heartbeats, remove the heartbeat with the earliest date.
968
+ // Since this is executed each time a heartbeat is pushed, the limit can only be exceeded by one, so only one needs to be removed.
969
+ if (this._heartbeatsCache.heartbeats.length > MAX_NUM_STORED_HEARTBEATS) {
970
+ const earliestHeartbeatIdx = getEarliestHeartbeatIdx(this._heartbeatsCache.heartbeats);
971
+ this._heartbeatsCache.heartbeats.splice(earliestHeartbeatIdx, 1);
972
+ }
936
973
  }
937
- // Remove entries older than 30 days.
938
- this._heartbeatsCache.heartbeats =
939
- this._heartbeatsCache.heartbeats.filter(singleDateHeartbeat => {
940
- const hbTimestamp = new Date(singleDateHeartbeat.date).valueOf();
941
- const now = Date.now();
942
- return now - hbTimestamp <= STORED_HEARTBEAT_RETENTION_MAX_MILLIS;
943
- });
944
974
  return this._storage.overwrite(this._heartbeatsCache);
945
975
  }
946
976
  catch (e) {
@@ -1115,6 +1145,24 @@ function countBytes(heartbeatsCache) {
1115
1145
  // heartbeatsCache wrapper properties
1116
1146
  JSON.stringify({ version: 2, heartbeats: heartbeatsCache })).length;
1117
1147
  }
1148
+ /**
1149
+ * Returns the index of the heartbeat with the earliest date.
1150
+ * If the heartbeats array is empty, -1 is returned.
1151
+ */
1152
+ function getEarliestHeartbeatIdx(heartbeats) {
1153
+ if (heartbeats.length === 0) {
1154
+ return -1;
1155
+ }
1156
+ let earliestHeartbeatIdx = 0;
1157
+ let earliestHeartbeatDate = heartbeats[0].date;
1158
+ for (let i = 1; i < heartbeats.length; i++) {
1159
+ if (heartbeats[i].date < earliestHeartbeatDate) {
1160
+ earliestHeartbeatDate = heartbeats[i].date;
1161
+ earliestHeartbeatIdx = i;
1162
+ }
1163
+ }
1164
+ return earliestHeartbeatIdx;
1165
+ }
1118
1166
 
1119
1167
  /**
1120
1168
  * @license