import { ErrorFactory, deepCopy, contains, deepExtend } from '@firebase/util'; import { ComponentContainer, Component } from '@firebase/component'; import { Logger } from '@firebase/logger'; /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ERRORS = { ["no-app" /* NO_APP */]: "No Firebase App '{$appName}' has been created - " + 'call Firebase App.initializeApp()', ["bad-app-name" /* BAD_APP_NAME */]: "Illegal App name: '{$appName}", ["duplicate-app" /* DUPLICATE_APP */]: "Firebase App named '{$appName}' already exists", ["app-deleted" /* APP_DELETED */]: "Firebase App named '{$appName}' already deleted", ["invalid-app-argument" /* INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' + 'Firebase App instance.' }; const ERROR_FACTORY = new ErrorFactory('app', 'Firebase', ERRORS); const name$1 = "@firebase/app"; const version = "0.5.3"; const name$2 = "@firebase/analytics"; const name$3 = "@firebase/auth"; const name$4 = "@firebase/database"; const name$5 = "@firebase/functions"; const name$6 = "@firebase/installations"; const name$7 = "@firebase/messaging"; const name$8 = "@firebase/performance"; const name$9 = "@firebase/remote-config"; const name$a = "@firebase/storage"; const name$b = "@firebase/firestore"; const name$c = "firebase-wrapper"; /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const DEFAULT_ENTRY_NAME = '[DEFAULT]'; const PLATFORM_LOG_STRING = { [name$1]: 'fire-core', [name$2]: 'fire-analytics', [name$3]: 'fire-auth', [name$4]: 'fire-rtdb', [name$5]: 'fire-fn', [name$6]: 'fire-iid', [name$7]: 'fire-fcm', [name$8]: 'fire-perf', [name$9]: 'fire-rc', [name$a]: 'fire-gcs', [name$b]: 'fire-fst', 'fire-js': 'fire-js', [name$c]: 'fire-js-all' }; /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Global context object for a collection of services using * a shared authentication state. */ class FirebaseAppLiteImpl { constructor(options, config, firebase_) { this.firebase_ = firebase_; this.isDeleted_ = false; // lite version has an empty INTERNAL namespace this.INTERNAL = {}; this.name_ = config.name; this.automaticDataCollectionEnabled_ = config.automaticDataCollectionEnabled || false; this.options_ = deepCopy(options); this.container = new ComponentContainer(config.name); // add itself to container this.container.addComponent(new Component('app', () => this, "PUBLIC" /* PUBLIC */)); // populate ComponentContainer with existing components for (const component of this.firebase_.INTERNAL.components.values()) { this.container.addComponent(component); } } get automaticDataCollectionEnabled() { this.checkDestroyed_(); return this.automaticDataCollectionEnabled_; } set automaticDataCollectionEnabled(val) { this.checkDestroyed_(); this.automaticDataCollectionEnabled_ = val; } get name() { this.checkDestroyed_(); return this.name_; } get options() { this.checkDestroyed_(); return this.options_; } delete() { return new Promise(resolve => { this.checkDestroyed_(); resolve(); }) .then(() => { this.firebase_.INTERNAL.removeApp(this.name_); return Promise.all(this.container.getProviders().map(provider => provider.delete())); }) .then(() => { this.isDeleted_ = true; }); } /** * Return a service instance associated with this app (creating it * on demand), identified by the passed instanceIdentifier. * * NOTE: Currently storage is the only one that is leveraging this * functionality. They invoke it by calling: * * ```javascript * firebase.app().storage('STORAGE BUCKET ID') * ``` * * The service name is passed to this already * @internal */ _getService(name, instanceIdentifier = DEFAULT_ENTRY_NAME) { this.checkDestroyed_(); // getImmediate will always succeed because _getService is only called for registered components. return this.container.getProvider(name).getImmediate({ identifier: instanceIdentifier }); } /** * This function will throw an Error if the App has already been deleted - * use before performing API actions on the App. */ checkDestroyed_() { if (this.isDeleted_) { throw ERROR_FACTORY.create("app-deleted" /* APP_DELETED */, { appName: this.name_ }); } } } const version$1 = "7.8.0"; /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const logger = new Logger('@firebase/app'); /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Because auth can't share code with other components, we attach the utility functions * in an internal namespace to share code. * This function return a firebase namespace object without * any utility functions, so it can be shared between the regular firebaseNamespace and * the lite version. */ function createFirebaseNamespaceCore(firebaseAppImpl) { const apps = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any const components = new Map(); // A namespace is a plain JavaScript Object. const namespace = { // Hack to prevent Babel from modifying the object returned // as the firebase namespace. // @ts-ignore __esModule: true, initializeApp, // @ts-ignore app, registerVersion, // @ts-ignore apps: null, SDK_VERSION: version$1, INTERNAL: { registerComponent, removeApp, components, useAsService } }; // Inject a circular default export to allow Babel users who were previously // using: // // import firebase from 'firebase'; // which becomes: var firebase = require('firebase').default; // // instead of // // import * as firebase from 'firebase'; // which becomes: var firebase = require('firebase'); // eslint-disable-next-line @typescript-eslint/no-explicit-any namespace['default'] = namespace; // firebase.apps is a read-only getter. Object.defineProperty(namespace, 'apps', { get: getApps }); /** * Called by App.delete() - but before any services associated with the App * are deleted. */ function removeApp(name) { delete apps[name]; } /** * Get the App object for a given name (or DEFAULT). */ function app(name) { name = name || DEFAULT_ENTRY_NAME; if (!contains(apps, name)) { throw ERROR_FACTORY.create("no-app" /* NO_APP */, { appName: name }); } return apps[name]; } // @ts-ignore app['App'] = firebaseAppImpl; function initializeApp(options, rawConfig = {}) { if (typeof rawConfig !== 'object' || rawConfig === null) { const name = rawConfig; rawConfig = { name }; } const config = rawConfig; if (config.name === undefined) { config.name = DEFAULT_ENTRY_NAME; } const { name } = config; if (typeof name !== 'string' || !name) { throw ERROR_FACTORY.create("bad-app-name" /* BAD_APP_NAME */, { appName: String(name) }); } if (contains(apps, name)) { throw ERROR_FACTORY.create("duplicate-app" /* DUPLICATE_APP */, { appName: name }); } const app = new firebaseAppImpl(options, config, namespace); apps[name] = app; return app; } /* * Return an array of all the non-deleted FirebaseApps. */ function getApps() { // Make a copy so caller cannot mutate the apps list. return Object.keys(apps).map(name => apps[name]); } function registerComponent(component) { const componentName = component.name; if (components.has(componentName)) { logger.debug(`There were multiple attempts to register component ${componentName}.`); return component.type === "PUBLIC" /* PUBLIC */ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any namespace[componentName] : null; } components.set(componentName, component); // create service namespace for public components if (component.type === "PUBLIC" /* PUBLIC */) { // The Service namespace is an accessor function ... const serviceNamespace = (appArg = app()) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any if (typeof appArg[componentName] !== 'function') { // Invalid argument. // This happens in the following case: firebase.storage('gs:/') throw ERROR_FACTORY.create("invalid-app-argument" /* INVALID_APP_ARGUMENT */, { appName: componentName }); } // Forward service instance lookup to the FirebaseApp. // eslint-disable-next-line @typescript-eslint/no-explicit-any return appArg[componentName](); }; // ... and a container for service-level properties. if (component.serviceProps !== undefined) { deepExtend(serviceNamespace, component.serviceProps); } // eslint-disable-next-line @typescript-eslint/no-explicit-any namespace[componentName] = serviceNamespace; // Patch the FirebaseAppImpl prototype // eslint-disable-next-line @typescript-eslint/no-explicit-any firebaseAppImpl.prototype[componentName] = // TODO: The eslint disable can be removed and the 'ignoreRestArgs' // option added to the no-explicit-any rule when ESlint releases it. // eslint-disable-next-line @typescript-eslint/no-explicit-any function (...args) { const serviceFxn = this._getService.bind(this, componentName); return serviceFxn.apply(this, component.multipleInstances ? args : []); }; } // add the component to existing app instances for (const appName of Object.keys(apps)) { apps[appName]._addComponent(component); } return component.type === "PUBLIC" /* PUBLIC */ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any namespace[componentName] : null; } function registerVersion(libraryKeyOrName, version, variant) { var _a; // TODO: We can use this check to whitelist strings when/if we set up // a good whitelist system. let library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName], (_a !== null && _a !== void 0 ? _a : libraryKeyOrName)); if (variant) { library += `-${variant}`; } const libraryMismatch = library.match(/\s|\//); const versionMismatch = version.match(/\s|\//); if (libraryMismatch || versionMismatch) { const warning = [ `Unable to register library "${library}" with version "${version}":` ]; if (libraryMismatch) { warning.push(`library name "${library}" contains illegal characters (whitespace or "/")`); } if (libraryMismatch && versionMismatch) { warning.push('and'); } if (versionMismatch) { warning.push(`version name "${version}" contains illegal characters (whitespace or "/")`); } logger.warn(warning.join(' ')); return; } registerComponent(new Component(`${library}-version`, () => ({ library, version }), "VERSION" /* VERSION */)); } // Map the requested service to a registered service name // (used to map auth to serverAuth service when needed). function useAsService(app, name) { if (name === 'serverAuth') { return null; } const useService = name; return useService; } return namespace; } /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function createFirebaseNamespaceLite() { const namespace = createFirebaseNamespaceCore(FirebaseAppLiteImpl); namespace.SDK_VERSION = `${namespace.SDK_VERSION}_LITE`; const registerComponent = namespace.INTERNAL .registerComponent; namespace.INTERNAL.registerComponent = registerComponentForLite; /** * This is a special implementation, so it only works with performance. * only allow performance SDK to register. */ function registerComponentForLite( // eslint-disable-next-line @typescript-eslint/no-explicit-any component) { // only allow performance to register with firebase lite if (component.type === "PUBLIC" /* PUBLIC */ && component.name !== 'performance' && component.name !== 'installations') { throw Error(`${name} cannot register with the standalone perf instance`); } return registerComponent(component); } return namespace; } /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class PlatformLoggerService { constructor(container) { this.container = container; } // In initial implementation, this will be called by installations on // auth token refresh, and installations will send this string. getPlatformInfoString() { const providers = this.container.getProviders(); // Loop through providers and get library/version pairs from any that are // version components. return providers .map(provider => { if (isVersionServiceProvider(provider)) { const service = provider.getImmediate(); return `${service.library}/${service.version}`; } else { return null; } }) .filter(logString => logString) .join(' '); } } /** * * @param provider check if this provider provides a VersionService * * NOTE: Using Provider<'app-version'> is a hack to indicate that the provider * provides VersionService. The provider is not necessarily a 'app-version' * provider. */ function isVersionServiceProvider(provider) { var _a; const component = provider.getComponent(); return ((_a = component) === null || _a === void 0 ? void 0 : _a.type) === "VERSION" /* VERSION */; } /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function registerCoreComponents(firebase, variant) { firebase.INTERNAL.registerComponent(new Component('platform-logger', container => new PlatformLoggerService(container), "PRIVATE" /* PRIVATE */)); // Register `app` package. firebase.registerVersion(name$1, version, variant); // Register platform SDK identifier (no version). firebase.registerVersion('fire-js', ''); } /** * @license * Copyright 2019 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const firebase = createFirebaseNamespaceLite(); registerCoreComponents(firebase, 'lite'); export default firebase; export { firebase }; //# sourceMappingURL=index.lite.esm2017.js.map