react-native-firebase-compiled
Version:
A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto
232 lines (160 loc) • 7.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _apps = _interopRequireDefault(require("../../utils/apps"));
var _events = require("../../utils/events");
var _internals = _interopRequireDefault(require("../../utils/internals"));
var _utils = require("../../utils");
var _admob = _interopRequireWildcard(require("../admob"));
var _auth = _interopRequireWildcard(require("../auth"));
var _analytics = _interopRequireWildcard(require("../analytics"));
var _config = _interopRequireWildcard(require("../config"));
var _crashlytics = _interopRequireWildcard(require("../crashlytics"));
var _database = _interopRequireWildcard(require("../database"));
var _firestore = _interopRequireWildcard(require("../firestore"));
var _functions = _interopRequireWildcard(require("../functions"));
var _iid = _interopRequireWildcard(require("../iid"));
var _invites = _interopRequireWildcard(require("../invites"));
var _links = _interopRequireWildcard(require("../links"));
var _messaging = _interopRequireWildcard(require("../messaging"));
var _notifications = _interopRequireWildcard(require("../notifications"));
var _perf = _interopRequireWildcard(require("../perf"));
var _storage = _interopRequireWildcard(require("../storage"));
var _utils2 = _interopRequireWildcard(require("../utils"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const FirebaseCoreModule = _reactNative.NativeModules.RNFirebase;
class App {
constructor(name, options, fromNative = false) {
_defineProperty(this, "_extendedProps", void 0);
_defineProperty(this, "_initialized", false);
_defineProperty(this, "_name", void 0);
_defineProperty(this, "_nativeInitialized", false);
_defineProperty(this, "_options", void 0);
_defineProperty(this, "admob", void 0);
_defineProperty(this, "analytics", void 0);
_defineProperty(this, "auth", void 0);
_defineProperty(this, "config", void 0);
_defineProperty(this, "crashlytics", void 0);
_defineProperty(this, "database", void 0);
_defineProperty(this, "firestore", void 0);
_defineProperty(this, "functions", void 0);
_defineProperty(this, "iid", void 0);
_defineProperty(this, "invites", void 0);
_defineProperty(this, "links", void 0);
_defineProperty(this, "messaging", void 0);
_defineProperty(this, "notifications", void 0);
_defineProperty(this, "perf", void 0);
_defineProperty(this, "storage", void 0);
_defineProperty(this, "utils", void 0);
this._name = name;
this._options = Object.assign({}, options);
if (fromNative) {
this._initialized = true;
this._nativeInitialized = true;
} else if (options.databaseURL && options.apiKey) {
FirebaseCoreModule.initializeApp(this._name, this._options, (error, result) => {
this._initialized = true;
_events.SharedEventEmitter.emit(`AppReady:${this._name}`, {
error,
result
});
});
} // modules
this.admob = _apps.default.appModule(this, _admob.NAMESPACE, _admob.default);
this.analytics = _apps.default.appModule(this, _analytics.NAMESPACE, _analytics.default);
this.auth = _apps.default.appModule(this, _auth.NAMESPACE, _auth.default);
this.config = _apps.default.appModule(this, _config.NAMESPACE, _config.default);
this.crashlytics = _apps.default.appModule(this, _crashlytics.NAMESPACE, _crashlytics.default);
this.database = _apps.default.appModule(this, _database.NAMESPACE, _database.default);
this.firestore = _apps.default.appModule(this, _firestore.NAMESPACE, _firestore.default);
this.functions = _apps.default.appModule(this, _functions.NAMESPACE, _functions.default);
this.iid = _apps.default.appModule(this, _iid.NAMESPACE, _iid.default);
this.invites = _apps.default.appModule(this, _invites.NAMESPACE, _invites.default);
this.links = _apps.default.appModule(this, _links.NAMESPACE, _links.default);
this.messaging = _apps.default.appModule(this, _messaging.NAMESPACE, _messaging.default);
this.notifications = _apps.default.appModule(this, _notifications.NAMESPACE, _notifications.default);
this.perf = _apps.default.appModule(this, _perf.NAMESPACE, _perf.default);
this.storage = _apps.default.appModule(this, _storage.NAMESPACE, _storage.default);
this.utils = _apps.default.appModule(this, _utils2.NAMESPACE, _utils2.default);
this._extendedProps = {};
}
/**
*
* @return {*}
*/
get name() {
return this._name;
}
/**
*
* @return {*}
*/
get options() {
return Object.assign({}, this._options);
}
/**
* Undocumented firebase web sdk method that allows adding additional properties onto
* a firebase app instance.
*
* See: https://github.com/firebase/firebase-js-sdk/blob/master/tests/app/firebase_app.test.ts#L328
*
* @param props
*/
extendApp(props) {
if (!(0, _utils.isObject)(props)) {
throw new Error(_internals.default.STRINGS.ERROR_MISSING_ARG('Object', 'extendApp'));
}
const keys = Object.keys(props);
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i];
if (!this._extendedProps[key] && Object.hasOwnProperty.call(this, key)) {
throw new Error(_internals.default.STRINGS.ERROR_PROTECTED_PROP(key));
} // $FlowExpectedError: Flow doesn't support indexable signatures on classes: https://github.com/facebook/flow/issues/1323
this[key] = props[key];
this._extendedProps[key] = true;
}
}
/**
*
* @return {Promise}
*/
delete() {
throw new Error(_internals.default.STRINGS.ERROR_UNSUPPORTED_CLASS_METHOD('app', 'delete')); // TODO only the ios sdk currently supports delete, add back in when android also supports it
// if (this._name === APPS.DEFAULT_APP_NAME && this._nativeInitialized) {
// return Promise.reject(
// new Error('Unable to delete the default native firebase app instance.'),
// );
// }
//
// return FirebaseCoreModule.deleteApp(this._name);
}
/**
*
* @return {*}
*/
onReady() {
if (this._initialized) return Promise.resolve(this);
return new Promise((resolve, reject) => {
_events.SharedEventEmitter.once(`AppReady:${this._name}`, ({
error
}) => {
if (error) return reject(new Error(error)); // error is a string as it's from native
return resolve(this); // return app
});
});
}
/**
* toString returns the name of the app.
*
* @return {string}
*/
toString() {
return this._name;
}
}
exports.default = App;