Skip to content

Commit

Permalink
add and remove external domains
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeseda committed Nov 30, 2023
1 parent 6278d45 commit eb994ad
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@architect/inventory": "3.6.1",
"@architect/parser": "6.0.3",
"@architect/utils": "3.1.9",
"@begin/api": "1.9.1",
"@begin/api": "1.9.2",
"@colors/colors": "1.6.0",
"@enhance/cli": "1.0.5",
"@enhance/starter-project": "5.1.7",
Expand Down Expand Up @@ -58,8 +58,8 @@
"pkg": "5.8.1",
"proxyquire": "~2.1.3",
"string-argv": "~0.3.2",
"tap-arc": "~0.4.0",
"tape": "~5.6.6"
"tap-arc": "~1.2.2",
"tape": "~5.7.2"
},
"eslintConfig": {
"extends": "@architect/eslint-config",
Expand Down
13 changes: 11 additions & 2 deletions src/commands/domains/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ async function checkDomain ({ domain, token, _staging }) {

async function action (params) {
let c = require('@colors/colors/safe')
let { config, domain, verbose } = params
let { config, domain, verbose, external } = params
let { access_token: token, stagingAPI: _staging } = config

if (!domain)
return Error('Please specify a domain name like: begin domains add --domain begin.com')

if (external) {
let client = require('@begin/api')
let { domain: externalDomain } = await client.domains.add({ token, domain, _staging })
return `External domain ${c.green(c.bold(externalDomain))} added!`
}

let check
let available
let availability
Expand All @@ -33,7 +39,10 @@ async function action (params) {
if (available) { // domain is definitely available
output.push(`${c.green(c.bold(domain))} is available!`)
output.push(`Subscribe here: ${c.bold(c.cyan(check.purchaseLink))}`)
output.push(`Learn more about domain subscriptions: ${c.cyan('https://begin.com/docs/cli/commands/domain-subscriptions')}.`)
output.push([
`Learn more about domain subscriptions:`,
c.cyan('https://begin.com/docs/cli/commands/domain-subscriptions'),
].join(' '))
}
else if (availability === 'PENDING' || availability === 'DONT_KNOW') {
output.push(`${c.cyan(c.bold(domain))} availability is unknown, please try again.`)
Expand Down
14 changes: 12 additions & 2 deletions src/commands/domains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const help = require('./help').bind({})

async function action (params) {
const { args } = params
let { domain, env, verbose, yes, _ } = args
let { domain, env, external, verbose, yes, _ } = args
let subcommand = _[1] || defaultCommand
const alias = Object.keys(aliases).includes(subcommand) && aliases[subcommand]
subcommand = alias || subcommand
Expand All @@ -42,7 +42,17 @@ async function action (params) {
appID = null
}

return action({ config, appID, env, domain, verbose, yes, inventory, ...params })
return action({
appID,
config,
domain,
env,
external,
inventory,
verbose,
yes,
...params,
})
}
else {
let err = new Error('Please specify an domains subcommand')
Expand Down
2 changes: 1 addition & 1 deletion src/commands/domains/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function action (params) {
if (!theDomain)
return Error([
`You do not subscribe to the domain "${domain}".`,
`To subscribe, run: begin domains check ${domain}`,
`To subscribe, run: begin domains add ${domain}`,
].join('\n'))

if (!appID || (typeof appID === 'string' && appID.length === 0)){
Expand Down
45 changes: 39 additions & 6 deletions src/commands/domains/remove.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
async function action () {
async function action (params) {
let c = require('@colors/colors/safe')
// TODO: create link for Stripe customer dashbaord
return [
c.bold(c.red('This feature is not yet implemented')),
c.gray('Please contact support@begin.com regarding domain subscriptions.'),
].join('\n')
const client = require('@begin/api')
let { config, domain } = params
let { access_token: token, stagingAPI: _staging } = config

const domains = await client.domains.list({ _staging, token })
const theDomain = domains.find(d => d.domain === domain)

if (!theDomain)
return Error([
`You do not subscribe to the domain "${domain}".`,
`To subscribe, run: begin domains add ${domain}`,
].join('\n'))

const { managed, domainID } = theDomain

if (managed) {
// TODO: create link for Stripe customer dashbaord
return [
c.bold(c.red('Sorry, this feature is not yet implemented')),
c.gray('Please contact support@begin.com regarding domain subscriptions.'),
].join('\n')
}
else {
const { Confirm } = require('enquirer')
const prompt = new Confirm({
name: 'remove',
message: `Are you sure you want to remove ${c.bold(domain)}?`,
})
const confirm = await prompt.run()
if (confirm) {
await client.domains.remove({ _staging, token, domainID })
return `External domain ${c.green(c.bold(domain))} removed!`
}
else {
return `External domain ${c.green(c.bold(domain))} not removed.`
}
}

}

module.exports = {
Expand Down

0 comments on commit eb994ad

Please sign in to comment.