Skip to content

Commit

Permalink
Fix deleteRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
anderspitman committed Nov 12, 2024
1 parent afd6609 commit 7b3d68e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -163,6 +167,7 @@ async function doRecords(apiUriIn, endpoint, { token, domain, host, records }) {
host,
token,
records: recsCopy,
delete_conflicting: deleteConflicting,
}),
});

Expand All @@ -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) {
Expand Down Expand Up @@ -378,6 +379,8 @@ export {
Client,
startAuthCodeFlow,
completeAuthCodeFlow,
getRecords,
setRecords,
deleteRecords,
createClient,
};

0 comments on commit 7b3d68e

Please sign in to comment.