firebase-admin 13.4.0 → 13.5.0

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.
Files changed (215) hide show
  1. package/lib/app/core.d.ts +1 -1
  2. package/lib/app/core.js +1 -1
  3. package/lib/app/credential-factory.d.ts +1 -1
  4. package/lib/app/credential-factory.js +1 -1
  5. package/lib/app/credential-internal.d.ts +1 -1
  6. package/lib/app/credential-internal.js +1 -1
  7. package/lib/app/credential.d.ts +1 -1
  8. package/lib/app/credential.js +1 -1
  9. package/lib/app/firebase-app.d.ts +1 -1
  10. package/lib/app/firebase-app.js +23 -2
  11. package/lib/app/firebase-namespace.d.ts +1 -1
  12. package/lib/app/firebase-namespace.js +1 -1
  13. package/lib/app/index.d.ts +1 -1
  14. package/lib/app/index.js +1 -1
  15. package/lib/app/lifecycle.d.ts +57 -1
  16. package/lib/app/lifecycle.js +141 -23
  17. package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
  18. package/lib/app-check/app-check-api-client-internal.js +1 -1
  19. package/lib/app-check/app-check-api.d.ts +1 -1
  20. package/lib/app-check/app-check-api.js +1 -1
  21. package/lib/app-check/app-check-namespace.d.ts +1 -1
  22. package/lib/app-check/app-check-namespace.js +1 -1
  23. package/lib/app-check/app-check.d.ts +1 -1
  24. package/lib/app-check/app-check.js +1 -1
  25. package/lib/app-check/index.d.ts +1 -1
  26. package/lib/app-check/index.js +1 -1
  27. package/lib/app-check/token-generator.d.ts +1 -1
  28. package/lib/app-check/token-generator.js +1 -1
  29. package/lib/app-check/token-verifier.d.ts +1 -1
  30. package/lib/app-check/token-verifier.js +1 -1
  31. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  32. package/lib/auth/action-code-settings-builder.js +1 -1
  33. package/lib/auth/auth-api-request.d.ts +1 -1
  34. package/lib/auth/auth-api-request.js +1 -1
  35. package/lib/auth/auth-config.d.ts +1 -1
  36. package/lib/auth/auth-config.js +1 -1
  37. package/lib/auth/auth-namespace.d.ts +1 -1
  38. package/lib/auth/auth-namespace.js +1 -1
  39. package/lib/auth/auth.d.ts +1 -1
  40. package/lib/auth/auth.js +1 -1
  41. package/lib/auth/base-auth.d.ts +1 -1
  42. package/lib/auth/base-auth.js +1 -1
  43. package/lib/auth/identifier.d.ts +1 -1
  44. package/lib/auth/identifier.js +1 -1
  45. package/lib/auth/index.d.ts +1 -1
  46. package/lib/auth/index.js +1 -1
  47. package/lib/auth/project-config-manager.d.ts +1 -1
  48. package/lib/auth/project-config-manager.js +1 -1
  49. package/lib/auth/project-config.d.ts +1 -1
  50. package/lib/auth/project-config.js +1 -1
  51. package/lib/auth/tenant-manager.d.ts +1 -1
  52. package/lib/auth/tenant-manager.js +1 -1
  53. package/lib/auth/tenant.d.ts +1 -1
  54. package/lib/auth/tenant.js +1 -1
  55. package/lib/auth/token-generator.d.ts +1 -1
  56. package/lib/auth/token-generator.js +1 -1
  57. package/lib/auth/token-verifier.d.ts +1 -1
  58. package/lib/auth/token-verifier.js +1 -1
  59. package/lib/auth/user-import-builder.d.ts +1 -1
  60. package/lib/auth/user-import-builder.js +1 -1
  61. package/lib/auth/user-record.d.ts +1 -1
  62. package/lib/auth/user-record.js +1 -1
  63. package/lib/credential/index.d.ts +1 -1
  64. package/lib/credential/index.js +1 -1
  65. package/lib/data-connect/data-connect-api-client-internal.d.ts +1 -1
  66. package/lib/data-connect/data-connect-api-client-internal.js +1 -1
  67. package/lib/data-connect/data-connect-api.d.ts +1 -1
  68. package/lib/data-connect/data-connect-api.js +1 -1
  69. package/lib/data-connect/data-connect.d.ts +1 -1
  70. package/lib/data-connect/data-connect.js +1 -1
  71. package/lib/data-connect/index.d.ts +1 -1
  72. package/lib/data-connect/index.js +1 -1
  73. package/lib/database/database-namespace.d.ts +1 -1
  74. package/lib/database/database-namespace.js +1 -1
  75. package/lib/database/database.d.ts +1 -1
  76. package/lib/database/database.js +1 -1
  77. package/lib/database/index.d.ts +1 -1
  78. package/lib/database/index.js +1 -1
  79. package/lib/default-namespace.d.ts +1 -1
  80. package/lib/default-namespace.js +1 -1
  81. package/lib/eventarc/cloudevent.d.ts +1 -1
  82. package/lib/eventarc/cloudevent.js +1 -1
  83. package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
  84. package/lib/eventarc/eventarc-client-internal.js +1 -1
  85. package/lib/eventarc/eventarc-utils.d.ts +1 -1
  86. package/lib/eventarc/eventarc-utils.js +1 -1
  87. package/lib/eventarc/eventarc.d.ts +1 -1
  88. package/lib/eventarc/eventarc.js +1 -1
  89. package/lib/eventarc/index.d.ts +1 -1
  90. package/lib/eventarc/index.js +1 -1
  91. package/lib/extensions/extensions-api-client-internal.d.ts +1 -1
  92. package/lib/extensions/extensions-api-client-internal.js +1 -1
  93. package/lib/extensions/extensions-api.d.ts +1 -1
  94. package/lib/extensions/extensions-api.js +1 -1
  95. package/lib/extensions/extensions.d.ts +1 -1
  96. package/lib/extensions/extensions.js +1 -1
  97. package/lib/extensions/index.d.ts +1 -1
  98. package/lib/extensions/index.js +1 -1
  99. package/lib/firebase-namespace-api.d.ts +1 -1
  100. package/lib/firebase-namespace-api.js +1 -1
  101. package/lib/firestore/firestore-internal.d.ts +1 -1
  102. package/lib/firestore/firestore-internal.js +1 -1
  103. package/lib/firestore/firestore-namespace.d.ts +1 -1
  104. package/lib/firestore/firestore-namespace.js +1 -1
  105. package/lib/firestore/index.d.ts +1 -1
  106. package/lib/firestore/index.js +1 -1
  107. package/lib/functions/functions-api-client-internal.d.ts +1 -1
  108. package/lib/functions/functions-api-client-internal.js +1 -1
  109. package/lib/functions/functions-api.d.ts +1 -1
  110. package/lib/functions/functions-api.js +1 -1
  111. package/lib/functions/functions.d.ts +1 -1
  112. package/lib/functions/functions.js +1 -1
  113. package/lib/functions/index.d.ts +1 -1
  114. package/lib/functions/index.js +1 -1
  115. package/lib/index.d.ts +1 -1
  116. package/lib/index.js +1 -1
  117. package/lib/installations/index.d.ts +1 -1
  118. package/lib/installations/index.js +1 -1
  119. package/lib/installations/installations-namespace.d.ts +1 -1
  120. package/lib/installations/installations-namespace.js +1 -1
  121. package/lib/installations/installations-request-handler.d.ts +1 -1
  122. package/lib/installations/installations-request-handler.js +1 -1
  123. package/lib/installations/installations.d.ts +1 -1
  124. package/lib/installations/installations.js +1 -1
  125. package/lib/instance-id/index.d.ts +1 -1
  126. package/lib/instance-id/index.js +1 -1
  127. package/lib/instance-id/instance-id-namespace.d.ts +1 -1
  128. package/lib/instance-id/instance-id-namespace.js +1 -1
  129. package/lib/instance-id/instance-id.d.ts +1 -1
  130. package/lib/instance-id/instance-id.js +1 -1
  131. package/lib/machine-learning/index.d.ts +1 -1
  132. package/lib/machine-learning/index.js +1 -1
  133. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  134. package/lib/machine-learning/machine-learning-api-client.js +1 -1
  135. package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
  136. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  137. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  138. package/lib/machine-learning/machine-learning-utils.js +1 -1
  139. package/lib/machine-learning/machine-learning.d.ts +1 -1
  140. package/lib/machine-learning/machine-learning.js +1 -1
  141. package/lib/messaging/index.d.ts +1 -1
  142. package/lib/messaging/index.js +1 -1
  143. package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
  144. package/lib/messaging/messaging-api-request-internal.js +1 -1
  145. package/lib/messaging/messaging-api.d.ts +5 -1
  146. package/lib/messaging/messaging-api.js +1 -1
  147. package/lib/messaging/messaging-errors-internal.d.ts +1 -1
  148. package/lib/messaging/messaging-errors-internal.js +1 -1
  149. package/lib/messaging/messaging-internal.d.ts +1 -1
  150. package/lib/messaging/messaging-internal.js +17 -1
  151. package/lib/messaging/messaging-namespace.d.ts +1 -1
  152. package/lib/messaging/messaging-namespace.js +1 -1
  153. package/lib/messaging/messaging.d.ts +1 -1
  154. package/lib/messaging/messaging.js +1 -1
  155. package/lib/project-management/android-app.d.ts +1 -1
  156. package/lib/project-management/android-app.js +1 -1
  157. package/lib/project-management/app-metadata.d.ts +1 -1
  158. package/lib/project-management/app-metadata.js +1 -1
  159. package/lib/project-management/index.d.ts +1 -1
  160. package/lib/project-management/index.js +1 -1
  161. package/lib/project-management/ios-app.d.ts +1 -1
  162. package/lib/project-management/ios-app.js +1 -1
  163. package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
  164. package/lib/project-management/project-management-api-request-internal.js +1 -1
  165. package/lib/project-management/project-management-namespace.d.ts +1 -1
  166. package/lib/project-management/project-management-namespace.js +1 -1
  167. package/lib/project-management/project-management.d.ts +1 -1
  168. package/lib/project-management/project-management.js +1 -1
  169. package/lib/remote-config/condition-evaluator-internal.d.ts +1 -1
  170. package/lib/remote-config/condition-evaluator-internal.js +1 -1
  171. package/lib/remote-config/index.d.ts +1 -1
  172. package/lib/remote-config/index.js +1 -1
  173. package/lib/remote-config/internal/value-impl.d.ts +1 -1
  174. package/lib/remote-config/internal/value-impl.js +1 -1
  175. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  176. package/lib/remote-config/remote-config-api-client-internal.js +1 -1
  177. package/lib/remote-config/remote-config-api.d.ts +1 -1
  178. package/lib/remote-config/remote-config-api.js +1 -1
  179. package/lib/remote-config/remote-config-namespace.d.ts +1 -1
  180. package/lib/remote-config/remote-config-namespace.js +1 -1
  181. package/lib/remote-config/remote-config.d.ts +1 -1
  182. package/lib/remote-config/remote-config.js +1 -1
  183. package/lib/security-rules/index.d.ts +1 -1
  184. package/lib/security-rules/index.js +1 -1
  185. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  186. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  187. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  188. package/lib/security-rules/security-rules-internal.js +1 -1
  189. package/lib/security-rules/security-rules-namespace.d.ts +1 -1
  190. package/lib/security-rules/security-rules-namespace.js +1 -1
  191. package/lib/security-rules/security-rules.d.ts +1 -1
  192. package/lib/security-rules/security-rules.js +1 -1
  193. package/lib/storage/index.d.ts +1 -1
  194. package/lib/storage/index.js +1 -1
  195. package/lib/storage/storage-namespace.d.ts +1 -1
  196. package/lib/storage/storage-namespace.js +1 -1
  197. package/lib/storage/storage.d.ts +1 -1
  198. package/lib/storage/storage.js +1 -1
  199. package/lib/storage/utils.d.ts +1 -1
  200. package/lib/storage/utils.js +1 -1
  201. package/lib/utils/api-request.d.ts +1 -1
  202. package/lib/utils/api-request.js +1 -1
  203. package/lib/utils/crypto-signer.d.ts +1 -1
  204. package/lib/utils/crypto-signer.js +1 -1
  205. package/lib/utils/deep-copy.d.ts +1 -1
  206. package/lib/utils/deep-copy.js +1 -1
  207. package/lib/utils/error.d.ts +1 -1
  208. package/lib/utils/error.js +1 -1
  209. package/lib/utils/index.d.ts +1 -1
  210. package/lib/utils/index.js +1 -1
  211. package/lib/utils/jwt.d.ts +1 -1
  212. package/lib/utils/jwt.js +1 -1
  213. package/lib/utils/validator.d.ts +1 -1
  214. package/lib/utils/validator.js +1 -1
  215. package/package.json +5 -4
package/lib/app/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
package/lib/app/core.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2020 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -121,18 +121,22 @@ exports.FirebaseAppInternals = FirebaseAppInternals;
121
121
  * @internal
122
122
  */
123
123
  class FirebaseApp {
124
- constructor(options, name, appStore) {
124
+ constructor(options, name, autoInit = false, appStore) {
125
125
  this.appStore = appStore;
126
126
  this.services_ = {};
127
127
  this.isDeleted_ = false;
128
+ this.autoInit_ = false;
129
+ this.customCredential_ = true;
128
130
  this.name_ = name;
129
131
  this.options_ = (0, deep_copy_1.deepCopy)(options);
132
+ this.autoInit_ = autoInit;
130
133
  if (!validator.isNonNullObject(this.options_)) {
131
134
  throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, 'Invalid Firebase app options passed as the first argument to initializeApp() for the ' +
132
135
  `app named "${this.name_}". Options must be a non-null object.`);
133
136
  }
134
137
  const hasCredential = ('credential' in this.options_);
135
138
  if (!hasCredential) {
139
+ this.customCredential_ = false;
136
140
  this.options_.credential = (0, credential_internal_1.getApplicationDefault)(this.options_.httpAgent);
137
141
  }
138
142
  const credential = this.options_.credential;
@@ -167,6 +171,23 @@ class FirebaseApp {
167
171
  getOrInitService(name, init) {
168
172
  return this.ensureService_(name, () => init(this));
169
173
  }
174
+ /**
175
+ * Returns `true` if this app was initialized with auto-initialization.
176
+ *
177
+ * @internal
178
+ */
179
+ autoInit() {
180
+ return this.autoInit_;
181
+ }
182
+ /**
183
+ * Returns `true` if the `FirebaseApp` instance was initialized with a custom
184
+ * `Credential`.
185
+ *
186
+ * @internal
187
+ */
188
+ customCredential() {
189
+ return this.customCredential_;
190
+ }
170
191
  /**
171
192
  * Deletes the FirebaseApp instance.
172
193
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
package/lib/app/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -31,8 +31,64 @@ export declare class AppStore {
31
31
  removeApp(appName: string): void;
32
32
  }
33
33
  export declare const defaultAppStore: AppStore;
34
+ /**
35
+ * Initializes the `App` instance.
36
+ *
37
+ * Creates a new instance of {@link App} if one doesn't exist, or returns an existing
38
+ * `App` instance if one exists with the same `appName` and `options`.
39
+ *
40
+ * Note, due to the inablity to compare `http.Agent` objects and `Credential` objects,
41
+ * this function cannot support idempotency if either of `options.httpAgent` or
42
+ * `options.credential` are defined. When either is defined, subsequent invocations will
43
+ * throw a `FirebaseAppError` instead of returning an `App` object.
44
+ *
45
+ * For example, to safely initialize an app that may already exist:
46
+ *
47
+ * ```javascript
48
+ * let app;
49
+ * try {
50
+ * app = getApp("myApp");
51
+ * } catch (error) {
52
+ * app = initializeApp({ credential: myCredential }, "myApp");
53
+ * }
54
+ * ```
55
+ *
56
+ * @param options - Optional A set of {@link AppOptions} for the `App` instance.
57
+ * If not present, `initializeApp` will try to initialize with the options from the
58
+ * `FIREBASE_CONFIG` environment variable. If the environment variable contains a
59
+ * string that starts with `{` it will be parsed as JSON, otherwise it will be
60
+ * assumed to be pointing to a file.
61
+ * @param appName - Optional name of the `App` instance.
62
+ *
63
+ * @returns A new App instance, or the existing App if the instance already exists with
64
+ * the provided configuration.
65
+ *
66
+ * @throws FirebaseAppError if an `App` with the same name has already been
67
+ * initialized with a different set of `AppOptions`.
68
+ * @throws FirebaseAppError if an existing `App` exists and `options.httpAgent`
69
+ * or `options.credential` are defined. This is due to the function's inability to
70
+ * determine if the existing `App`'s `options` equate to the `options` parameter
71
+ * of this function. It's recommended to use {@link getApp} or {@link getApps} if your
72
+ * implementation uses either of these two fields in `AppOptions`.
73
+ */
34
74
  export declare function initializeApp(options?: AppOptions, appName?: string): App;
75
+ /**
76
+ * Returns an existing {@link App} instance for the provided name. If no name
77
+ * is provided the the default app name is used.
78
+ *
79
+ * @param appName - Optional name of the `App` instance.
80
+ *
81
+ * @returns An existing `App` instance that matches the name provided.
82
+ *
83
+ * @throws FirebaseAppError if no `App` exists for the given name.
84
+ * @throws FirebaseAppError if the `appName` is malformed.
85
+ */
35
86
  export declare function getApp(appName?: string): App;
87
+ /**
88
+ * A (read-only) array of all initialized apps.
89
+ *
90
+ * @returns An array containing all initialized apps.
91
+ */
36
92
  export declare function getApps(): App[];
37
93
  /**
38
94
  * Renders this given `App` unusable and frees the resources of
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -27,42 +27,52 @@ const validator = require("../utils/validator");
27
27
  const error_1 = require("../utils/error");
28
28
  const credential_internal_1 = require("./credential-internal");
29
29
  const firebase_app_1 = require("./firebase-app");
30
+ const fastDeepEqual = require('fast-deep-equal');
30
31
  const DEFAULT_APP_NAME = '[DEFAULT]';
31
32
  class AppStore {
32
33
  constructor() {
33
34
  this.appStore = new Map();
34
35
  }
35
36
  initializeApp(options, appName = DEFAULT_APP_NAME) {
37
+ validateAppNameFormat(appName);
38
+ let autoInit = false;
36
39
  if (typeof options === 'undefined') {
40
+ autoInit = true;
37
41
  options = loadOptionsFromEnvVar();
38
42
  options.credential = (0, credential_internal_1.getApplicationDefault)();
39
43
  }
40
- if (typeof appName !== 'string' || appName === '') {
41
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, `Invalid Firebase app name "${appName}" provided. App name must be a non-empty string.`);
44
+ // Check if an app already exists and, if so, ensure its `AppOptions` match
45
+ // those of this `initializeApp` request.
46
+ if (!this.appStore.has(appName)) {
47
+ const app = new firebase_app_1.FirebaseApp(options, appName, autoInit, this);
48
+ this.appStore.set(app.name, app);
49
+ return app;
42
50
  }
43
- else if (this.appStore.has(appName)) {
44
- if (appName === DEFAULT_APP_NAME) {
45
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, 'The default Firebase app already exists. This means you called initializeApp() ' +
46
- 'more than once without providing an app name as the second argument. In most cases ' +
47
- 'you only need to call initializeApp() once. But if you do want to initialize ' +
48
- 'multiple apps, pass a second argument to initializeApp() to give each app a unique ' +
49
- 'name.');
50
- }
51
- else {
52
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, `Firebase app named "${appName}" already exists. This means you called initializeApp() ` +
53
- 'more than once with the same app name as the second argument. Make sure you provide a ' +
54
- 'unique name every time you call initializeApp().');
55
- }
51
+ const currentApp = this.appStore.get(appName);
52
+ // Ensure the `autoInit` state matches the existing app's. If not, throw.
53
+ if (currentApp.autoInit() !== autoInit) {
54
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, `A Firebase app named "${appName}" already exists with a different configuration.`);
56
55
  }
57
- const app = new firebase_app_1.FirebaseApp(options, appName, this);
58
- this.appStore.set(app.name, app);
59
- return app;
56
+ if (autoInit) {
57
+ // Auto-initialization is triggered when no options were passed to
58
+ // `initializeApp`. With no options to compare, simply return the App.
59
+ return currentApp;
60
+ }
61
+ // Ensure the options objects don't break deep equal comparisons.
62
+ validateAppOptionsSupportDeepEquals(options, currentApp);
63
+ // `FirebaseApp()` adds a synthesized `Credential` to `app.options` upon
64
+ // app construction. Run a comparison w/o `Credential` to see if the base
65
+ // configurations match. Return the existing app if so.
66
+ const currentAppOptions = { ...currentApp.options };
67
+ delete currentAppOptions.credential;
68
+ if (!fastDeepEqual(options, currentAppOptions)) {
69
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, `A Firebase app named "${appName}" already exists with a different configuration.`);
70
+ }
71
+ return currentApp;
60
72
  }
61
73
  getApp(appName = DEFAULT_APP_NAME) {
62
- if (typeof appName !== 'string' || appName === '') {
63
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, `Invalid Firebase app name "${appName}" provided. App name must be a non-empty string.`);
64
- }
65
- else if (!this.appStore.has(appName)) {
74
+ validateAppNameFormat(appName);
75
+ if (!this.appStore.has(appName)) {
66
76
  let errorMessage = (appName === DEFAULT_APP_NAME)
67
77
  ? 'The default Firebase app does not exist. ' : `Firebase app named "${appName}" does not exist. `;
68
78
  errorMessage += 'Make sure you call initializeApp() before using any of the Firebase services.';
@@ -101,13 +111,121 @@ class AppStore {
101
111
  }
102
112
  }
103
113
  exports.AppStore = AppStore;
114
+ /**
115
+ * Validates that the `requestedOptions` and the `existingApp` options objects
116
+ * do not have fields that would break deep equals comparisons.
117
+ *
118
+ * @param requestedOptions The incoming `AppOptions` of a new `initailizeApp`
119
+ * request.
120
+ * @param existingApp An existing `FirebaseApp` with internal `options` to
121
+ * compare against.
122
+ *
123
+ * @throws FirebaseAppError if the objects cannot be deeply compared.
124
+ *
125
+ * @internal
126
+ */
127
+ function validateAppOptionsSupportDeepEquals(requestedOptions, existingApp) {
128
+ // http.Agent checks.
129
+ if (typeof requestedOptions.httpAgent !== 'undefined') {
130
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, `Firebase app named "${existingApp.name}" already exists and initializeApp was` +
131
+ ' invoked with an optional http.Agent. The SDK cannot confirm the equality' +
132
+ ' of http.Agent objects with the existing app. Please use getApp or getApps to reuse' +
133
+ ' the existing app instead.');
134
+ }
135
+ else if (typeof existingApp.options.httpAgent !== 'undefined') {
136
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, `An existing app named "${existingApp.name}" already exists with a different` +
137
+ ' options configuration: httpAgent.');
138
+ }
139
+ // Credential checks.
140
+ if (typeof requestedOptions.credential !== 'undefined') {
141
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, `Firebase app named "${existingApp.name}" already exists and initializeApp was` +
142
+ ' invoked with an optional Credential. The SDK cannot confirm the equality' +
143
+ ' of Credential objects with the existing app. Please use getApp or getApps' +
144
+ ' to reuse the existing app instead.');
145
+ }
146
+ if (existingApp.customCredential()) {
147
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, `An existing app named "${existingApp.name}" already exists with a different` +
148
+ ' options configuration: Credential.');
149
+ }
150
+ }
151
+ /**
152
+ * Checks to see if the provided appName is a non-empty string and throws if it
153
+ * is not.
154
+ *
155
+ * @param appName A string representation of an App name.
156
+ *
157
+ * @throws FirebaseAppError if appName is not of type string or is empty.
158
+ *
159
+ * @internal
160
+ */
161
+ function validateAppNameFormat(appName) {
162
+ if (!validator.isNonEmptyString(appName)) {
163
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, `Invalid Firebase app name "${appName}" provided. App name must be a non-empty string.`);
164
+ }
165
+ }
104
166
  exports.defaultAppStore = new AppStore();
167
+ /**
168
+ * Initializes the `App` instance.
169
+ *
170
+ * Creates a new instance of {@link App} if one doesn't exist, or returns an existing
171
+ * `App` instance if one exists with the same `appName` and `options`.
172
+ *
173
+ * Note, due to the inablity to compare `http.Agent` objects and `Credential` objects,
174
+ * this function cannot support idempotency if either of `options.httpAgent` or
175
+ * `options.credential` are defined. When either is defined, subsequent invocations will
176
+ * throw a `FirebaseAppError` instead of returning an `App` object.
177
+ *
178
+ * For example, to safely initialize an app that may already exist:
179
+ *
180
+ * ```javascript
181
+ * let app;
182
+ * try {
183
+ * app = getApp("myApp");
184
+ * } catch (error) {
185
+ * app = initializeApp({ credential: myCredential }, "myApp");
186
+ * }
187
+ * ```
188
+ *
189
+ * @param options - Optional A set of {@link AppOptions} for the `App` instance.
190
+ * If not present, `initializeApp` will try to initialize with the options from the
191
+ * `FIREBASE_CONFIG` environment variable. If the environment variable contains a
192
+ * string that starts with `{` it will be parsed as JSON, otherwise it will be
193
+ * assumed to be pointing to a file.
194
+ * @param appName - Optional name of the `App` instance.
195
+ *
196
+ * @returns A new App instance, or the existing App if the instance already exists with
197
+ * the provided configuration.
198
+ *
199
+ * @throws FirebaseAppError if an `App` with the same name has already been
200
+ * initialized with a different set of `AppOptions`.
201
+ * @throws FirebaseAppError if an existing `App` exists and `options.httpAgent`
202
+ * or `options.credential` are defined. This is due to the function's inability to
203
+ * determine if the existing `App`'s `options` equate to the `options` parameter
204
+ * of this function. It's recommended to use {@link getApp} or {@link getApps} if your
205
+ * implementation uses either of these two fields in `AppOptions`.
206
+ */
105
207
  function initializeApp(options, appName = DEFAULT_APP_NAME) {
106
208
  return exports.defaultAppStore.initializeApp(options, appName);
107
209
  }
210
+ /**
211
+ * Returns an existing {@link App} instance for the provided name. If no name
212
+ * is provided the the default app name is used.
213
+ *
214
+ * @param appName - Optional name of the `App` instance.
215
+ *
216
+ * @returns An existing `App` instance that matches the name provided.
217
+ *
218
+ * @throws FirebaseAppError if no `App` exists for the given name.
219
+ * @throws FirebaseAppError if the `appName` is malformed.
220
+ */
108
221
  function getApp(appName = DEFAULT_APP_NAME) {
109
222
  return exports.defaultAppStore.getApp(appName);
110
223
  }
224
+ /**
225
+ * A (read-only) array of all initialized apps.
226
+ *
227
+ * @returns An array containing all initialized apps.
228
+ */
111
229
  function getApps() {
112
230
  return exports.defaultAppStore.getApps();
113
231
  }
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2018 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2018 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2018 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2018 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
package/lib/auth/auth.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2020 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
package/lib/auth/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2020 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v13.4.0 */
1
+ /*! firebase-admin v13.5.0 */
2
2
  import { ProjectConfig, UpdateProjectConfigRequest } from './project-config';
3
3
  /**
4
4
  * Manages (gets and updates) the current project config.