@@ -46,7 +46,7 @@ export class AppStore {
4646 const currentApp = this . appStore . get ( appName ) ! ;
4747 if ( currentApp . autoInit ( ) !== autoInit ) {
4848 throw new FirebaseAppError (
49- AppErrorCodes . INVALID_ARGUMENT ,
49+ AppErrorCodes . INVALID_APP_OPTIONS ,
5050 `Firebase app named "${ appName } " attempted mismatch between custom AppOptions` +
5151 ' and an App created via Auto Init.'
5252 )
@@ -172,6 +172,35 @@ function validateAppNameFormat(appName: string): void {
172172
173173export const defaultAppStore = new AppStore ( ) ;
174174
175+ /**
176+ * Initializes the App instance.
177+ *
178+ * Creates a new instance of {@link App} if one doesn't exist, or returns an existing
179+ * {@link App} instance if one exists with the same `appName` and `options`.
180+ *
181+ * Note, due to the inablity to compare `http.Agent` objects and `Credential` objects,
182+ * this function cannot support idempotency if either of `options.httpAgent` or
183+ * `options.credential` are defined. When either is defined, subsequent invocations will
184+ * throw instead of returning an {@link App} object.
185+ *
186+ * @param options - Optional A set of {@link AppOptions} for the {@link App} instance.
187+ * If not present, `initializeApp` will try to initialize with the options from the
188+ * `FIREBASE_CONFIG` environment variable. If the environment variable contains a string
189+ * that starts with `{` it will be parsed as JSON, otherwise it will be assumed to be
190+ * pointing to a file.
191+ * @param appName - Optional name of the FirebaseApp instance.
192+ *
193+ * @returns A new App instance, or the existing App if the instance already exists with
194+ * the provided configuration.
195+ *
196+ * @throws FirebaseAppError if an {@link App} with the same name has already been
197+ * initialized with a different set of AppOptions.
198+ * @throws FirebaseAppError if an existing {@link App} exists and `options.httpAgent`
199+ * or `options.credential` are defined. This is due to the function's inability to
200+ * determine if the existing {@link App}'s `options` compare to the `options` parameter
201+ * of this function. It's recommended to use {@link getApp} or {@link getApps} if your
202+ * implementation uses either of these two fields in {@link AppOptions}.
203+ */
175204export function initializeApp ( options ?: AppOptions , appName : string = DEFAULT_APP_NAME ) : App {
176205 return defaultAppStore . initializeApp ( options , appName ) ;
177206}
0 commit comments