replace with custom superagent based on fetch API

This commit is contained in:
Girish Ramakrishnan
2025-02-14 17:26:54 +01:00
parent 68a08b1f62
commit 8e58349bfa
66 changed files with 1086 additions and 1031 deletions
+12 -12
View File
@@ -17,13 +17,13 @@ const assert = require('assert'),
dig = require('../dig.js'),
dns = require('../dns.js'),
safe = require('safetydance'),
superagent = require('superagent'),
superagent = require('../superagent.js'),
waitForDns = require('./waitfordns.js');
const GANDI_API = 'https://dns.api.gandi.net/api/v5';
function formatError(response) {
return `Gandi DNS error [${response.statusCode}] ${response.body.message}`;
return `Gandi DNS error [${response.status}] ${response.text}`;
}
function removePrivateFields(domainObject) {
@@ -40,7 +40,7 @@ function createRequest(method, url, domainConfig) {
assert.strictEqual(typeof url, 'string');
assert.strictEqual(typeof domainConfig, 'object');
const request = superagent(method, url).timeout(30 * 1000).ok(() => true);
const request = superagent.request(method, url).timeout(30 * 1000).ok(() => true);
// https://api.gandi.net/docs/authentication/
if (domainConfig.tokenType === 'ApiKey') {
@@ -74,9 +74,9 @@ async function upsert(domainObject, location, type, values) {
.send(data));
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response));
if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.status === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response));
if (response.status !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
}
async function get(domainObject, location, type) {
@@ -93,9 +93,9 @@ async function get(domainObject, location, type) {
const [error, response] = await safe(createRequest('GET', `${GANDI_API}/domains/${zoneName}/records/${name}/${type}`, domainConfig));
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.statusCode === 404) return [];
if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.status === 404) return [];
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
return response.body.rrset_values;
}
@@ -115,9 +115,9 @@ async function del(domainObject, location, type, values) {
const [error, response] = await safe(createRequest('DELETE', `${GANDI_API}/domains/${zoneName}/records/${name}/${type}`, domainConfig));
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
if (response.statusCode === 404) return;
if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
if (response.status === 404) return;
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
if (response.status !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
}
async function wait(domainObject, subdomain, type, value, options) {