Skip to content

Commit

Permalink
Merge pull request #29 from StauroDEV/verbose-logs-dnslink
Browse files Browse the repository at this point in the history
fix: a dumb dnslink bug and add verbose mode to dnslink
  • Loading branch information
talentlessguy authored Mar 30, 2024
2 parents d3e7347 + 5b8f4ae commit 78d5d21
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/actions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const deployAction = async (
dir: string,
{
strict, ens, chain = 'mainnet', safe, name: customName,
dist, verbose, providers: providersList, resolverAddress,
dist, verbose = false, providers: providersList, resolverAddress,
dnslink,
}: DeployActionArgs,
) => {
Expand Down Expand Up @@ -128,6 +128,6 @@ export const deployAction = async (
}

if (dnslink) {
await dnsLinkAction(cid, dnslink)
await dnsLinkAction(cid, dnslink, {verbose})

Check failure on line 131 in src/actions/deploy.ts

View workflow job for this annotation

GitHub Actions / test

A space is required after '{'

Check failure on line 131 in src/actions/deploy.ts

View workflow job for this annotation

GitHub Actions / test

A space is required before '}'
}
}
6 changes: 3 additions & 3 deletions src/actions/dnslink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { updateDnsLink } from '../utils/dnslink.js'
import { logger } from '../utils/logger.js'

export const dnsLinkAction = async (
cid: string, name: string, /* { init = false }: { init?: boolean } */
cid: string, name: string, {verbose}:{verbose:boolean} /* { init = false }: { init?: boolean } */

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

A space is required after '{'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

A space is required before '}'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

Expected a space after the ':'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

Requires a space after '{'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

A space is required after '{'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

Missing space before value for key 'verbose'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

Expected a space after the ':'

Check failure on line 6 in src/actions/dnslink.ts

View workflow job for this annotation

GitHub Actions / test

Requires a space before '}'
) => {
const apiKey = process.env.BLUMEN_CF_KEY
const zoneId = process.env.BLUMEN_CF_ZONE_ID
Expand All @@ -20,9 +20,9 @@ export const dnsLinkAction = async (
// else {
logger.info(`Updating DNSLink`)
try {
const response = await updateDnsLink({ cid, zoneId, apiKey, name })
const response = await updateDnsLink({ cid, zoneId, apiKey, name, verbose })

if (response.errors) return logger.error(response.errors[0].message)
if (response.errors.length !== 0) return logger.error(response.errors[0].message)

logger.success(`${response.result.name} now points to ${response.result.dnslink}`)
}
Expand Down
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cli.command('ping <cid> <endpoint>', 'Ping an endpoint until it resolves content

cli.command('dnslink <cid> <name>', 'Update DNSLink with a given CID using Cloudflare')
// .option('--init', 'Create a DNSLink gateway', { default: false })
.option('--verbose', 'More verbose logs', {default:false})
.action(dnsLinkAction)

cli.help()
Expand Down
11 changes: 7 additions & 4 deletions src/utils/dnslink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CLOUDFLARE_API_URL } from '../constants.js'
import { DnsLinkError, MissingDnsLinkError } from '../errors.js'
import { logger } from './logger.js';

// export const createDnsLink = async (
// { cid, zoneId, apiKey }:
Expand All @@ -25,14 +26,15 @@ import { DnsLinkError, MissingDnsLinkError } from '../errors.js'
// }

export const updateDnsLink = async (
{ cid, zoneId, apiKey, name }:
{ cid: string, zoneId: string, apiKey: string, name: string },
{ cid, zoneId, apiKey, name,verbose }:
{ cid: string, zoneId: string, apiKey: string, name: string; verbose: boolean },
) => {
const res = await fetch(`${CLOUDFLARE_API_URL}/zones/${zoneId}/web3/hostnames`, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
})
if (verbose) logger.request('GET', res.url, res.status)
const json = await res.json() as {
result: { name: string, id: string }[]
errors: { message: string, code: number }[]
Expand All @@ -46,7 +48,7 @@ export const updateDnsLink = async (

if (!record) throw new MissingDnsLinkError()

return await fetch(`${CLOUDFLARE_API_URL}/zones/${zoneId}/web3/hostnames/${record.id}`, {
const res2 = await fetch(`${CLOUDFLARE_API_URL}/zones/${zoneId}/web3/hostnames/${record.id}`, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${apiKey}`,
Expand All @@ -57,5 +59,6 @@ export const updateDnsLink = async (
description: `Powered by Blumen`,
}),
})
.then(res => res.json())
if (verbose) logger.request('POST', res.url, res.status)
return res2.json()
}

0 comments on commit 78d5d21

Please sign in to comment.