From 7b3d68e401ac6c3f1bb115f7567f7c094b18c348 Mon Sep 17 00:00:00 2001 From: Anders Pitman <&ers@apitman.com> Date: Tue, 12 Nov 2024 12:37:56 -0700 Subject: [PATCH] Fix deleteRecords --- index.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 7a3e994..26698a3 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ let prefix = "namedrop_"; -let DEFAULT_API_URI = 'https://takingnames.io/namedrop'; +const DEFAULT_API_URI = 'https://takingnames.io/namedrop'; const SCOPE_HOSTS = 'namedrop-hosts'; const SCOPE_MAIL = 'namedrop-mail'; @@ -11,6 +11,11 @@ class NotAuthenticatedError extends Error {} const validScopes = [ SCOPE_HOSTS, SCOPE_MAIL, SCOPE_ACME, SCOPE_ATPROTO_HANDLE ]; +let apiUri = DEFAULT_API_URI; +function setApiUri(newUri) { + apiUri = newUri; +} + function setPrefix(newPrefix) { prefix = newPrefix; }; @@ -127,9 +132,8 @@ class Client { } } -async function getRecords(apiUri, opt) { - const result = await this.doRecords(apiUri, 'get-records', opt || { records: [] }); - return result.records; +async function getRecords({ apiUri, request }) { + return doRecords(apiUri, 'get-records', request); } async function createRecords(apiUri, opt) { @@ -140,11 +144,11 @@ async function setRecords({ apiUri, request }) { return doRecords(apiUri, 'set-records', request); } -async function deleteRecords(apiUri, opt) { - return doRecords(apiUri, 'delete-records', opt); +async function deleteRecords({ apiUri, request }) { + return doRecords(apiUri, 'delete-records', request); } -async function doRecords(apiUriIn, endpoint, { token, domain, host, records }) { +async function doRecords(apiUriIn, endpoint, { token, domain, host, records, deleteConflicting }) { const apiUri = apiUriIn ? apiUriIn : DEFAULT_API_URI; @@ -163,6 +167,7 @@ async function doRecords(apiUriIn, endpoint, { token, domain, host, records }) { host, token, records: recsCopy, + delete_conflicting: deleteConflicting, }), }); @@ -182,10 +187,6 @@ async function doRecords(apiUriIn, endpoint, { token, domain, host, records }) { return result; } -function setApiUri(newUri) { - apiUri = newUri; -} - function buildScope(req) { for (const scope of req.scopes) { @@ -378,6 +379,8 @@ export { Client, startAuthCodeFlow, completeAuthCodeFlow, + getRecords, setRecords, + deleteRecords, createClient, };