Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const axios = require('axios').default;
const sleep = require('sleep-promise');

/**
Expand All @@ -12,7 +11,6 @@ const sleep = require('sleep-promise');
* - maxTries: the maximum number of times to try to fetch the keys, in case of transient errors
* (defaults to 1)
* - retryInterval: the number of milliseconds to delay between retries (defaults to 1000)
* - agent: the HTTP(S) agent to use when requesting data.
* @return A promise that resolves to an array of key strings.
*/
module.exports = async (ref, options = {}) => {
Expand All @@ -34,22 +32,18 @@ module.exports = async (ref, options = {}) => {
// ref.ref ensures we are dealing with an admin.database.Reference instance.
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;
const url = new URL(ref.toString() + '.json');
url.searchParams.set('shallow', 'true');
url.searchParams.set('access_token', accessTokenObj.access_token);
let tries = 0;

async function tryRequest() {
tries++;
let data;
try {
const response = await axios.get(uri, {
params: qs, agent, responseType: 'text', transformResponse: [x => x]
});
data = response.data;
const response = await fetch(url);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore custom agent support for REST requests

The switch from axios.get(..., { agent }) to fetch(url) drops the transport override path entirely, so callers that pass options.agent (for proxies, custom CA trust, or mTLS) now have that option silently ignored and requests can fail in those environments. This is a functional regression introduced by this commit; please wire options.agent into the fetch call (e.g., via a compatible dispatcher) or explicitly reject the option so failures are not silent.

Useful? React with 👍 / 👎.

data = await response.text();
if (!response.ok) throw new Error(`HTTP ${response.status}: ${data}`);
} catch (error) {
if (options.maxTries && tries < options.maxTries) {
await sleep(options.retryInterval || 1000);
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "firebase-childrenkeys",
"version": "2.6.2",
"version": "3.0.0",
"packageManager": "yarn@4.13.0",
"description": "Fetch children keys of Firebase Admin Database References via the REST API",
"main": "index.js",
"engines": {
"node": ">=8.0"
"node": ">=18.0"
},
"scripts": {
"update": "yarn up -R '*' && yarn dedupe --strategy highest",
Expand All @@ -26,7 +26,6 @@
},
"homepage": "https://github.com/Reviewable/firebase-childrenkeys",
"dependencies": {
"axios": "^1.2.1",
"sleep-promise": "^9.1.0"
},
"peerDependencies": {
Expand Down
54 changes: 6 additions & 48 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,6 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.2.1":
version: 1.14.0
resolution: "axios@npm:1.14.0"
dependencies:
follow-redirects: "npm:^1.15.11"
form-data: "npm:^4.0.5"
proxy-from-env: "npm:^2.1.0"
checksum: 10c0/2541f4aa215a7d1842429dad006fc682d82bc0e74bd14500823f7d8cce3bbae0e0a8c328c8538946718f366ab8ce5a4c12e9ad40e5a0f3482ff8bff0cd115d45
languageName: node
linkType: hard

"balanced-match@npm:^1.0.0":
version: 1.0.2
resolution: "balanced-match@npm:1.0.2"
Expand Down Expand Up @@ -1151,11 +1140,10 @@ __metadata:
resolution: "firebase-childrenkeys@workspace:."
dependencies:
assert: "npm:^2.1.0"
axios: "npm:^1.2.1"
eslint: "npm:^8.21.0"
firebase-admin: "npm:^13.7.0"
lodash: "npm:^4.17.21"
npm-check-updates: "npm:20.0.0"
npm-check-updates: "npm:^20.0.0"
sleep-promise: "npm:^9.1.0"
peerDependencies:
firebase-admin: 5.x || 6.x || 7.x || 8.x || 9.x || 10.x || 11.x || 12.x || 13.x
Expand All @@ -1180,16 +1168,6 @@ __metadata:
languageName: node
linkType: hard

"follow-redirects@npm:^1.15.11":
version: 1.15.11
resolution: "follow-redirects@npm:1.15.11"
peerDependenciesMeta:
debug:
optional: true
checksum: 10c0/d301f430542520a54058d4aeeb453233c564aaccac835d29d15e050beb33f339ad67d9bddbce01739c5dc46a6716dbe3d9d0d5134b1ca203effa11a7ef092343
languageName: node
linkType: hard

"for-each@npm:^0.3.5":
version: 0.3.5
resolution: "for-each@npm:0.3.5"
Expand All @@ -1213,19 +1191,6 @@ __metadata:
languageName: node
linkType: hard

"form-data@npm:^4.0.5":
version: 4.0.5
resolution: "form-data@npm:4.0.5"
dependencies:
asynckit: "npm:^0.4.0"
combined-stream: "npm:^1.0.8"
es-set-tostringtag: "npm:^2.1.0"
hasown: "npm:^2.0.2"
mime-types: "npm:^2.1.12"
checksum: 10c0/dd6b767ee0bbd6d84039db12a0fa5a2028160ffbfaba1800695713b46ae974a5f6e08b3356c3195137f8530dcd9dfcb5d5ae1eeff53d0db1e5aad863b619ce3b
languageName: node
linkType: hard

"formdata-polyfill@npm:^4.0.10":
version: 4.0.10
resolution: "formdata-polyfill@npm:4.0.10"
Expand Down Expand Up @@ -1949,7 +1914,7 @@ __metadata:
languageName: node
linkType: hard

"mime-types@npm:^2.1.12, mime-types@npm:^2.1.35":
"mime-types@npm:^2.1.35":
version: 2.1.35
resolution: "mime-types@npm:2.1.35"
dependencies:
Expand Down Expand Up @@ -2029,13 +1994,13 @@ __metadata:
languageName: node
linkType: hard

"npm-check-updates@npm:20.0.0":
version: 20.0.0
resolution: "npm-check-updates@npm:20.0.0"
"npm-check-updates@npm:^20.0.0":
version: 20.0.2
resolution: "npm-check-updates@npm:20.0.2"
bin:
ncu: build/cli.js
npm-check-updates: build/cli.js
checksum: 10c0/cf34e509aef8a801b567aea6c836b2064f824d854021e69c5c773afc5eae981d29ad06068a3fa0bcb85ccf765f0771fb925250c12f6f6a10c91f1e43c2aec621
checksum: 10c0/28e2dcf4d1524cdba505f162a958af4515be3f41dd85472153029306d0c8a7c0998c605bd8d94d76b93d23e8de2605e0988cbae980233d9a156ef1a3c0266b0b
languageName: node
linkType: hard

Expand Down Expand Up @@ -2198,13 +2163,6 @@ __metadata:
languageName: node
linkType: hard

"proxy-from-env@npm:^2.1.0":
version: 2.1.0
resolution: "proxy-from-env@npm:2.1.0"
checksum: 10c0/ed01729fd4d094eab619cd7e17ce3698b3413b31eb102c4904f9875e677cd207392795d5b4adee9cec359dfd31c44d5ad7595a3a3ad51c40250e141512281c58
languageName: node
linkType: hard

"punycode@npm:^2.1.0":
version: 2.3.1
resolution: "punycode@npm:2.3.1"
Expand Down
Loading