Comparing version 0.0.4 to 0.1.0
declare module 'dnslink' { | ||
export default function dnslink(domain: string): Promise<string>; | ||
function resolve(domain: string): Promise<string>; | ||
function update(domain: string, cid: string): Promise<void>; | ||
} |
37
index.js
@@ -1,32 +0,7 @@ | ||
const dns = require('dns'); | ||
const resolve = require('./cmds/resolve'); | ||
const update = require('./cmds/update'); | ||
const DNSLINK_REGEX = /^dnslink=.+/; | ||
/** | ||
* Return the string path that is dnslinked in the txt records. | ||
**/ | ||
module.exports = function dnslink(_domain) { | ||
return new Promise((rs, rj) => { | ||
const domainParts = _domain.split('.'); | ||
// We've got a subdomain, add _dnslink subdomain prefix | ||
if (domainParts.length > 2) { | ||
domainParts.unshift('_dnslink'); | ||
} | ||
const domain = domainParts.join('.'); | ||
dns.resolveTxt(domain, (err, records) => { | ||
if (err) return rj(err); | ||
const flatRecords = [].concat(...records); | ||
const dnslinks = flatRecords.filter(item => { | ||
return DNSLINK_REGEX.test(item); | ||
}); | ||
if (dnslinks.length > 1) { | ||
rj(`Found multiple dnslink entries for ${domain}. Rejecting as there should only be 1.`); | ||
return; | ||
} else if (dnslinks.length === 0) { | ||
rj(`Unable to find dnslink TXT record for domain ${domain}`); | ||
return; | ||
} | ||
rs(dnslinks[0].slice('dnslink='.length)); | ||
}); | ||
}); | ||
} | ||
module.exports = { | ||
resolve, | ||
update, | ||
}; |
@@ -9,6 +9,6 @@ const assert = require('assert'); | ||
assert.rejects(() => dnslink(`${random()}.commontheory.io`)); | ||
assert.doesNotReject(() => dnslink(`commontheory.io`)); | ||
assert.doesNotReject(() => dnslink(`coverage.commontheory.io`)); | ||
assert.rejects(() => dnslink.resolve(`${random()}.commontheory.io`)); | ||
assert.doesNotReject(() => dnslink.resolve(`commontheory.io`)); | ||
assert.doesNotReject(() => dnslink.resolve(`coverage.commontheory.io`)); | ||
console.log('Test passed'); | ||
console.log('Tests passed'); |
{ | ||
"name": "dnslink", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Resolve dnslink TXT records for domains", | ||
"main": "index.js", | ||
"bin": { | ||
"dnslink": "./cli.js" | ||
}, | ||
"types": "index.d.ts", | ||
@@ -19,3 +22,7 @@ "scripts": { | ||
}, | ||
"homepage": "https://github.com/common-theory/dnslink#readme" | ||
"homepage": "https://github.com/common-theory/dnslink#readme", | ||
"dependencies": { | ||
"digitalocean": "^1.2.0", | ||
"yargs": "^12.0.2" | ||
} | ||
} |
# dnslink [![Build Status](https://travis-ci.org/common-theory/dnslink.svg?branch=master)](https://travis-ci.org/common-theory/dnslink) [![npm](https://img.shields.io/npm/v/dnslink.svg)](https://www.npmjs.com/package/dnslink) [![npm type definitions](https://img.shields.io/npm/types/dnslink.svg)](https://github.com/common-theory/dnslink) | ||
A javascript [dnslink](https://docs.ipfs.io/guides/concepts/dnslink/) resolution implementation. | ||
## Usage | ||
### `update` | ||
#### Command Line | ||
Create a dnslink binding via digitalocean. | ||
An environment variable called `DIGITAL_OCEAN_TOKEN` should be set. | ||
```sh | ||
$ dnslink update commontheory.io /ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy | ||
Unable to find dnslink record, creating a new one | ||
DNS record updated | ||
``` | ||
#### JS/TS | ||
```ts | ||
import { update } from 'dnslink'; | ||
// async/await | ||
await update('commontheory.io', '/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy'); | ||
// promises | ||
update('commontheory.io', '/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy') | ||
.then(cid => /* Your logic */); | ||
``` | ||
### `resolve` | ||
Get the CID associated with a domain. | ||
#### Command Line | ||
```sh | ||
$ dnslink resolve commontheory.io | ||
/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy | ||
``` | ||
#### JS/TS | ||
```ts | ||
import { resolve } from 'dnslink'; | ||
// async/await | ||
const cid = await resolve('commontheory.io'); | ||
// promises | ||
resolve('commontheory.io') | ||
.then(cid => /* Your logic */); | ||
``` | ||
## Note | ||
This package is not maintained by, or affiliated with IPFS or Protocol Labs. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6900
9
135
61
2
1
+ Addeddigitalocean@^1.2.0
+ Addedyargs@^12.0.2
+ Addedajv@6.12.6(transitive)
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcross-spawn@6.0.5(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddigitalocean@1.2.1(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@12.0.5(transitive)
+ Addedyargs-parser@11.1.1(transitive)