Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain validate #47

Merged
merged 2 commits into from
Dec 22, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
19 changes: 17 additions & 2 deletions src/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
},

Expand All @@ -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, })
},

Expand All @@ -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 },
Expand All @@ -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
Expand All @@ -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 },
Expand All @@ -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 },
Expand Down
5 changes: 4 additions & 1 deletion test/domains-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down