Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
// eslint-disable-next-line no-console
console.warn(
`Warning: A firebase.perf.HttpMetric (${this._httpMethod}: ${
this._url
}) failed to provide a httpResponseCode; this metric will not be visible on the Firebase console.`,
);
}
if (!isNull(this._requestPayloadSize)) {
metricData.requestPayloadSize = this._requestPayloadSize;
}
if (!isNull(this._responsePayloadSize)) {
metricData.responsePayloadSize = this._responsePayloadSize;
}
if (!isNull(this._responseContentType)) {
metricData.responseContentType = this._responseContentType;
}
return this.native.stopHttpMetric(this._id, metricData);
}
}
}
const metadataEntries = Object.entries(metadata);
for (let i = 0; i < metadataEntries.length; i++) {
const [key, value] = metadataEntries[i];
// validate keys
if (!SETTABLE_FIELDS.includes(key)) {
throw new Error(
`firebase.storage.SettableMetadata unknown property '${key}' provided for metadata.`,
);
}
// validate values
if (key !== 'customMetadata') {
if (!isString(value) && !isNull(value)) {
throw new Error(
`firebase.storage.SettableMetadata invalid property '${key}' should be a string or null value.`,
);
}
} else if (!isObject(value)) {
throw new Error(
'firebase.storage.SettableMetadata.customMetadata must be an object of keys and string values.',
);
}
}
return metadata;
}
push(value, onComplete) {
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().push(_, *) 'onComplete' must be a function if provided.",
);
}
const id = generateDatabaseId(this._database._serverTimeOffset);
if (isUndefined(value) || isNull(value)) {
return new DatabaseThenableReference(
this._database,
pathChild(this.path, id),
Promise.resolve(this.child(id)),
);
}
const pushRef = this.child(id);
const promise = pushRef.set(value, onComplete).then(() => pushRef);
// Prevent unhandled promise rejection if onComplete is passed
if (onComplete) {
promise.catch(() => {});
}
setWithPriority(newVal, newPriority, onComplete) {
if (isUndefined(newVal)) {
throw new Error("firebase.database().ref().setWithPriority(*) 'newVal' must be defined.");
}
if (!isNumber(newPriority) && !isString(newPriority) && !isNull(newPriority)) {
throw new Error(
"firebase.database().ref().setWithPriority(_, *) 'newPriority' must be a number, string or null value.",
);
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().setWithPriority(_, _, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._database.native.setWithPriority(this.path, {
value: newVal,
priority: newPriority,
}),
setUserProperties(properties) {
if (!isObject(properties)) {
throw new Error(
"firebase.analytics().setUserProperties(*) 'properties' expected an object of key/value pairs.",
);
}
const entries = Object.entries(properties);
for (let i = 0; i < entries.length; i++) {
const [key, value] = entries[i];
if (!isNull(value) && !isString(value)) {
throw new Error(
`firebase.analytics().setUserProperties(*) 'properties' value for parameter '${key}' is invalid, expected a string.`,
);
}
}
return this.native.setUserProperties(properties);
}
export function initializeApp(options = {}, configOrName) {
let appConfig = configOrName;
if (!isObject(configOrName) || isNull(configOrName)) {
appConfig = {
name: configOrName,
automaticResourceManagement: false,
automaticDataCollectionEnabled: true,
};
}
if (isUndefined(appConfig.name)) {
appConfig.name = DEFAULT_APP_NAME;
}
const { name } = appConfig;
if (!name || !isString(name)) {
return Promise.reject(new Error(`Illegal App name: '${name}'`));
}
setUserId(id) {
if (!isNull(id) && !isString(id)) {
throw new Error("firebase.analytics().setUserId(*) 'id' expected a string value.");
}
return this.native.setUserId(id);
}
export function generateNativeData(value) {
if (Number.isNaN(value)) {
return getTypeMapInt('nan');
}
if (value === Number.NEGATIVE_INFINITY) {
return getTypeMapInt('-infinity');
}
if (value === Number.POSITIVE_INFINITY) {
return getTypeMapInt('infinity');
}
if (isNull(value) || isUndefined(value)) {
return getTypeMapInt('null');
}
if (value === DOCUMENT_ID) {
return getTypeMapInt('documentid');
}
if (isBoolean(value)) {
if (value === true) {
return getTypeMapInt('booleanTrue');
}
return getTypeMapInt('booleanFalse');
}
if (isNumber(value)) {
return getTypeMapInt('number', value);