Skip to content

Commit

Permalink
add domains.validate and simple param checks for other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeseda committed Dec 22, 2023
1 parent 20eb4cd commit 99c3403
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit 99c3403

Please sign in to comment.