Socket
Socket
Sign inDemoInstall

firebase-childrenkeys

Package Overview
Dependencies
213
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.3.0

6

.eslintrc.js

@@ -0,1 +1,3 @@

'use strict';
module.exports = {

@@ -114,3 +116,5 @@ env: {

'space-before-blocks': 'warn',
'space-before-function-paren': ['warn', 'never'],
'space-before-function-paren': [
'warn', {anonymous: 'never', named: 'never', asyncArrow: 'always'}
],
'space-in-parens': 'warn',

@@ -117,0 +121,0 @@ 'space-infix-ops': 'warn',

78

index.js
'use strict';
const request = require('request');
const axios = require('axios').default;
const sleep = require('sleep-promise');

@@ -17,3 +18,3 @@ /**

*/
module.exports = (ref, options = {}) => {
module.exports = async (ref, options = {}) => {
const refIsNonNullObject = typeof ref === 'object' && ref !== null;

@@ -35,41 +36,36 @@ if (!refIsNonNullObject || typeof ref.ref !== 'object' ||

// ref.ref ensures we are dealing with an admin.database.Reference instance.
return ref.ref.database.app.options.credential.getAccessToken()
.then((accessTokenObj) => {
const uri = ref.toString() + '.json';
const qs = {
shallow: true,
access_token: accessTokenObj.access_token, // eslint-disable-line camelcase
};
const agent = options.agent;
return new Promise((resolve, reject) => {
let tries = 0;
function tryRequest() {
tries++;
request({uri, qs, agent}, (error, response, data) => {
if (error && options.maxTries && tries < options.maxTries) {
setTimeout(tryRequest, options.retryInterval || 1000);
} else if (error) {
reject(error);
} else {
try {
let match;
match = data.match(/"error"\s*:\s*"([^"]*)"/);
if (match) {
throw new Error(
'Failed to fetch children keys from Firebase REST API: ' + match[1]);
}
const regex = /"(.*?)"/g;
const keys = [];
// eslint-disable-next-line no-cond-assign
while (match = regex.exec(data)) keys.push(match[1]); // don't unescape keys!
resolve(keys);
} catch (e) {
reject(e);
}
}
});
}
tryRequest();
});
});
const accessTokenObj = await ref.ref.database.app.options.credential.getAccessToken();
const uri = ref.toString() + '.json';
const qs = {
shallow: true,
access_token: accessTokenObj.access_token, // eslint-disable-line camelcase
};
const agent = options.agent;
let tries = 0;
async function tryRequest() {
tries++;
let data;
try {
const response = await axios.get(uri, {params: qs, agent, responseType: 'text'});
data = response.data;
} catch (error) {
if (options.maxTries && tries < options.maxTries) {
await sleep(options.retryInterval || 1000);
return tryRequest();
}
throw error;
}
let match;
match = data.match(/"error"\s*:\s*"([^"]*)"/);
if (match) throw new Error(`Failed to fetch children keys from Firebase REST API: ${match[1]}`);
const regex = /"(.*?)"/g;
const keys = [];
// eslint-disable-next-line no-cond-assign
while (match = regex.exec(data)) keys.push(match[1]); // don't unescape keys!
return keys;
}
return tryRequest();
};
{
"name": "firebase-childrenkeys",
"version": "2.2.0",
"version": "2.3.0",
"description": "Fetch children keys of Firebase Admin Database References via the REST API",

@@ -29,3 +29,4 @@ "main": "index.js",

"dependencies": {
"request": "^2.81.0"
"axios": "^0.19.2",
"sleep-promise": "^8.0.1"
},

@@ -32,0 +33,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc