@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
77 lines (76 loc) • 3.08 kB
JavaScript
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import analytics from '@react-native-firebase/analytics';
import initializeRemoteConfig from '@react-native-firebase/remote-config';
import { timeout } from '../../index';
import { Plugin } from '../Plugin';
export class FirebasePlugin extends Plugin {
get instance() {
return {
analytics: analytics()
};
}
get remoteValues() {
return this._remoteConfig;
}
constructor(options) {
super();
_defineProperty(this, "name", 'FirebasePlugin');
_defineProperty(this, "features", ['RemoteConfig', 'Analytics']);
_defineProperty(this, "initializationTimeout", null);
_defineProperty(this, "_remoteConfig", void 0);
_defineProperty(this, "_firebaseConfig", void 0);
this._remoteConfig = options.remoteConfig ?? {};
this._firebaseConfig = options.firebaseConfig ?? {
minimumFetchIntervalMillis: 0,
fetchTimeMillis: 5000
};
}
async initialize() {
if (this._remoteConfig) {
const config = initializeRemoteConfig();
try {
await timeout(async () => {
await config.setConfigSettings(this._firebaseConfig);
await config.setDefaults({
...this._remoteConfig
});
await config.fetch(0);
await config.activate();
});
this._remoteConfig = Object.fromEntries(Object.entries(config.getAll()).map(_ref => {
let [key, entry] = _ref;
// @ts-ignore
const defaultValue = this._remoteConfig[key];
if (!defaultValue) {
try {
// @ts-ignore
const parsed = JSON.parse(entry._value);
return [key, parsed];
} catch {
return [key, entry.asString()];
}
}
if (typeof defaultValue === 'string') {
return [key, entry.asString()];
}
if (typeof defaultValue === 'boolean') {
return [key, entry.asBoolean()];
}
if (typeof defaultValue === 'number') {
return [key, entry.asNumber()];
}
// @ts-ignore
return [key, JSON.parse(entry._value)];
}));
} catch {
// no op
}
}
}
async logEvent(event, parameters) {
await analytics().logEvent(event, parameters);
}
}
//# sourceMappingURL=FirebasePlugin.js.map