diff --git a/package.json b/package.json index 644e1db..7e233a6 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "devDependencies": { "@architect/eslint-config": "^2.1.2", "dotenv": "^16.3.1", - "eslint": "^8.54.0", + "eslint": "^8.56.0", "tap-arc": "^1.2.2", "tape": "^5.7.2" }, diff --git a/src/index.cjs b/src/index.cjs index 686fef1..439ea0a 100644 --- a/src/index.cjs +++ b/src/index.cjs @@ -69,6 +69,7 @@ module.exports = { * @param {BaseParams & {domain: string}} options */ async add ({ token, domain, _staging }) { + if (!domain) throw Error('missing_domain') return write({ token, _staging, scope: 'domains' }, { domain }) }, @@ -86,6 +87,7 @@ module.exports = { * @param {BaseParams & {domain: string}} options */ async check ({ token, domain, _staging }) { + if (!domain) throw Error('missing_domain') return read({ token, _staging, scope: 'domains', path: domain, }) }, @@ -97,7 +99,6 @@ module.exports = { if (!appID) throw Error('missing_appID') if (!envID) throw Error('missing_envID') if (!domainID) throw Error('missing_domainID') - return write( { token, _staging, scope: 'domains', path: `${domainID}/link` }, { appID, envID }, @@ -109,14 +110,26 @@ module.exports = { * @param {BaseParams & {domainID: string, appID?: string, envID?: string}} options */ async unlink ({ token, domainID, appID, envID, _staging }) { + if (!appID) throw Error('missing_appID') + if (!envID) throw Error('missing_envID') if (!domainID) throw Error('missing_domainID') - return write( { token, _staging, scope: 'domains', path: `${domainID}/unlink` }, { appID, envID }, ) }, + /** + * @description validate an external domain + * repeat this operation until the domain is validated + * @param {BaseParams & {domainID: string}} options + * returns DNS validation records + */ + async validate ({ token, domainID, _staging }) { + if (!domainID) throw Error('missing_domainID') + return write({ token, _staging, scope: 'domains', path: `${domainID}/validate` }) + }, + records: { /** * @description list domain records @@ -136,6 +149,7 @@ module.exports = { */ async upsert ({ token, domainID, changes, _staging }) { if (!domainID) throw Error('missing_domainID') + if (!changes) throw Error('missing_changes') return write( { token, _staging, scope: 'domains', path: `${domainID}/records` }, { changes }, @@ -152,6 +166,7 @@ module.exports = { */ async delete ({ token, domainID, record, _staging }) { if (!domainID) throw Error('missing_domainID') + if (!record) throw Error('missing_record') return write( { token, _staging, scope: 'domains', path: `${domainID}/records/delete` }, { ...record }, diff --git a/test/domains-test.mjs b/test/domains-test.mjs index 49a0d51..ec680a6 100644 --- a/test/domains-test.mjs +++ b/test/domains-test.mjs @@ -7,13 +7,16 @@ e.config() const token = process.env.ACCESS_TOKEN || '123' test('begin', t => { - t.plan(10) + t.plan(13) t.ok(begin, 'begin') t.ok(begin.domains, 'begin.domains') t.ok(begin.domains.list, 'begin.domains.list') + t.ok(begin.domains.add, 'begin.domains.add') + t.ok(begin.domains.remove, 'begin.domains.remove') t.ok(begin.domains.check, 'begin.domains.check') t.ok(begin.domains.link, 'begin.domains.link') t.ok(begin.domains.unlink, 'begin.domains.unlink') + t.ok(begin.domains.validate, 'begin.domains.validate') t.ok(begin.domains.records, 'begin.domains.records') t.ok(begin.domains.records.list, 'begin.domains.records.list') t.ok(begin.domains.records.upsert, 'begin.domains.records.upsert')