|
1 | 1 | import process from 'node:process'
|
2 | 2 | import { handleError } from '@stacksjs/error-handling'
|
3 |
| -import { log, parseOptions } from '@stacksjs/cli' |
| 3 | +import { dd, log, parseOptions } from '@stacksjs/cli' |
4 | 4 | import { ExitCode } from '@stacksjs/types'
|
| 5 | +import { config } from '@stacksjs/config' |
5 | 6 | import type { PurchaseOptions } from '@stacksjs/cloud'
|
6 | 7 | import { purchaseDomain } from '@stacksjs/cloud'
|
7 | 8 |
|
| 9 | +const c = config.dns.contactInfo |
| 10 | +if (!c) { |
| 11 | + handleError('You must provide contact info in your config file.') |
| 12 | + process.exit(ExitCode.FatalError) |
| 13 | +} |
| 14 | + |
8 | 15 | const defaultOptions: PurchaseOptions = {
|
9 | 16 | domain: '',
|
10 | 17 | years: 1,
|
11 | 18 | privacy: true,
|
12 | 19 | autoRenew: true,
|
13 |
| - registrantFirstName: config.dns.contactInfo.firstName, |
14 |
| - registrantLastName: config.dns.contactInfo?.lastName, |
15 |
| - registrantOrganizationName: config.dns.contactInfo?.organizationName, |
16 |
| - registrantAddressLine1: config.dns.contactInfo?.addressLine1, |
17 |
| - registrantAddressLine2: config.dns.contactInfo?.addressLine2, |
18 |
| - registrantCity: config.dns.contactInfo?.city, |
19 |
| - registrantState: config.dns.contactInfo?.state, |
20 |
| - registrantCountryCode: config.dns.contactInfo?.countryCode, |
21 |
| - registrantZip: config.dns.contactInfo?.zip, |
22 |
| - registrantPhoneNumber: config.dns.contactInfo?.phoneNumber, |
23 |
| - registrantEmail: config.dns.contactInfo?.email, |
24 |
| - admin: { |
25 |
| - firstName: config.dns.contactInfo?.admin?.firstName || config.dns.contactInfo?.firstName, |
26 |
| - lastName: config.dns.contactInfo?.admin?.lastName || config.dns.contactInfo?.lastName, |
27 |
| - organizationName: config.dns.contactInfo?.admin?.organizationName || config.dns.contactInfo?.organizationName, |
28 |
| - addressLine1: config.dns.contactInfo?.admin?.addressLine1 || config.dns.contactInfo?.addressLine1, |
29 |
| - addressLine2: config.dns.contactInfo?.admin?.addressLine2 || config.dns.contactInfo?.addressLine2, |
30 |
| - city: config.dns.contactInfo?.admin?.city || config.dns.contactInfo?.city, |
31 |
| - state: config.dns.contactInfo?.admin?.state || config.dns.contactInfo?.state, |
32 |
| - countryCode: config.dns.contactInfo?.admin?.countryCode || config.dns.contactInfo?.countryCode, |
33 |
| - zip: config.dns.contactInfo?.admin?.zip || config.dns.contactInfo?.zip, |
34 |
| - phoneNumber: config.dns.contactInfo?.admin?.phoneNumber || config.dns.contactInfo?.phoneNumber, |
35 |
| - email: config.dns.contactInfo?.admin?.email || config.dns.contactInfo?.email, |
36 |
| - }, |
37 |
| - tech: { |
38 |
| - firstName: config.dns.contactInfo?.tech?.firstName || config.dns.contactInfo?.firstName, |
39 |
| - lastName: config.dns.contactInfo?.tech?.lastName || config.dns.contactInfo?.lastName, |
40 |
| - organizationName: config.dns.contactInfo?.tech?.organizationName || config.dns.contactInfo?.organizationName, |
41 |
| - addressLine1: config.dns.contactInfo?.tech?.addressLine1 || config.dns.contactInfo?.addressLine1, |
42 |
| - addressLine2: config.dns.contactInfo?.tech?.addressLine2 || config.dns.contactInfo?.addressLine2, |
43 |
| - city: config.dns.contactInfo?.tech?.city || config.dns.contactInfo?.city, |
44 |
| - state: config.dns.contactInfo?.tech?.state || config.dns.contactInfo?.state, |
45 |
| - countryCode: config.dns.contactInfo?.tech?.countryCode || config.dns.contactInfo?.countryCode, |
46 |
| - zip: config.dns.contactInfo?.tech?.zip || config.dns.contactInfo?.zip, |
47 |
| - phoneNumber: config.dns.contactInfo?.tech?.phoneNumber || config.dns.contactInfo?.phoneNumber, |
48 |
| - email: config.dns.contactInfo?.tech?.email || config.dns.contactInfo?.email, |
49 |
| - }, |
50 |
| - privacyAdmin: config.dns.contactInfo?.privacyAdmin || config.dns.contactInfo?.privacy || true, |
51 |
| - privacyTech: config.dns.contactInfo?.privacyTech || config.dns.contactInfo?.privacy || true, |
52 |
| - privacyRegistrant: config.dns.contactInfo?.privacyRegistrant || config.dns.contactInfo?.privacy || true, |
53 |
| - contactType: 'person', |
54 |
| - }, |
55 |
| - |
56 |
| -] |
57 |
| - |
58 |
| - // ... add the rest of the 38 properties here with their default values |
| 20 | + registrantFirstName: c.firstName as string, |
| 21 | + registrantLastName: c.lastName as string, |
| 22 | + registrantOrganization: c.organizationName as string, |
| 23 | + registrantAddressLine1: c.addressLine1 as string, |
| 24 | + registrantAddressLine2: c.addressLine2 as string, |
| 25 | + registrantCity: c.city as string, |
| 26 | + registrantState: c.state as string, |
| 27 | + registrantCountry: c.countryCode as string, |
| 28 | + registrantZip: c.zip as string, |
| 29 | + registrantPhone: c.phoneNumber as string, |
| 30 | + registrantEmail: c.email as string, |
| 31 | + adminFirstName: c.admin?.firstName || c.firstName as string, |
| 32 | + adminLastName: c.admin?.lastName || c.lastName as string, |
| 33 | + adminOrganization: c.admin?.organizationName || c.organizationName as string, |
| 34 | + adminAddressLine1: c.admin?.addressLine1 || c.addressLine1 as string, |
| 35 | + adminAddressLine2: c.admin?.addressLine2 || c.addressLine2 as string, |
| 36 | + adminCity: c.admin?.city || c.city as string, |
| 37 | + adminState: c.admin?.state || c.state as string, |
| 38 | + adminCountry: c.admin?.countryCode || c.countryCode as string, |
| 39 | + adminZip: c.admin?.zip || c.zip as string, |
| 40 | + adminPhone: c.admin?.phoneNumber as string || c.phoneNumber as string, |
| 41 | + adminEmail: c.admin?.email || c.email as string, |
| 42 | + techFirstName: c.tech?.firstName || c.firstName as string, |
| 43 | + techLastName: c.tech?.lastName || c.lastName as string, |
| 44 | + techOrganization: c.tech?.organizationName || c.organizationName as string, |
| 45 | + techAddressLine1: c.tech?.addressLine1 || c.addressLine1 as string, |
| 46 | + techAddressLine2: c.tech?.addressLine2 || c.addressLine2 as string, |
| 47 | + techCity: c.tech?.city || c.city as string, |
| 48 | + techState: c.tech?.state || c.state as string, |
| 49 | + techCountry: c.tech?.countryCode || c.countryCode as string, |
| 50 | + techZip: c.tech?.zip || c.zip as string, |
| 51 | + techPhone: c.tech?.phoneNumber as string || c.phoneNumber as string, |
| 52 | + techEmail: c.tech?.email || c.email as string, |
| 53 | + privacyAdmin: c.privacyAdmin || c.privacy || true, |
| 54 | + privacyTech: c.privacyTech || c.privacy || true, |
| 55 | + privacyRegistrant: c.privacyRegistrant || c.privacy || true, |
| 56 | + contactType: 'person', |
| 57 | + verbose: false, |
59 | 58 | }
|
60 | 59 |
|
61 | 60 | const options: PurchaseOptions = { ...defaultOptions, ...parseOptions() }
|
62 | 61 |
|
63 |
| -const options: PurchaseOptions = parseOptions() |
64 |
| - |
65 |
| -log.info('options is', options) |
66 |
| -log.dd('domain is', options.domain) |
67 |
| - |
68 | 62 | if (!options.domain) {
|
69 | 63 | handleError('You must provide a domain name to purchase.')
|
70 | 64 | process.exit(ExitCode.FatalError)
|
71 | 65 | }
|
72 | 66 |
|
73 |
| -const result = purchaseDomain(options.domain, options) |
| 67 | +const result = await purchaseDomain(options.domain, options) |
74 | 68 |
|
75 | 69 | if (result.isErr()) {
|
| 70 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
76 | 71 | handleError(result.error)
|
77 | 72 | process.exit(ExitCode.FatalError)
|
78 | 73 | }
|
79 | 74 |
|
80 |
| -log.info(result.value) |
| 75 | +log.info('Domain purchased successfully.') |
| 76 | + |
81 | 77 | process.exit(ExitCode.Success)
|
0 commit comments