caa 9.0.0 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -6
  2. package/index.js +8 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,17 @@
1
1
  # caa
2
- [![](https://img.shields.io/npm/v/caa.svg?style=flat)](https://www.npmjs.org/package/caa) [![](https://img.shields.io/npm/dm/caa.svg)](https://www.npmjs.org/package/caa)
2
+ [![](https://img.shields.io/npm/v/caa.svg?style=flat)](https://www.npmjs.org/package/caa) [![](https://img.shields.io/npm/dm/caa.svg)](https://www.npmjs.org/package/caa) [![](https://packagephobia.com/badge?p=caa)](https://packagephobia.com/result?p=caa)
3
3
 
4
4
  > [rfc6844](https://tools.ietf.org/html/rfc6844)-conform CAA record lookup and validation
5
5
 
6
6
  ## Usage
7
7
 
8
- ```sh
9
- npm i caa
10
- ```
11
8
  ```js
12
9
  import {caa, caaMatches} from "caa";
13
10
 
14
- await caa("subdomain.example.com");
11
+ await caa("example.com");
15
12
  // => [{flags: 0, tag: 'issue', value: 'letsencrypt.org', issuerCritical: false}]
16
13
 
17
- await caa.matches("subdomain.example.com", "letsencrypt.org");
14
+ await caa.matches("example.com", "letsencrypt.org");
18
15
  // => true
19
16
 
20
17
  ```
package/index.js CHANGED
@@ -51,7 +51,7 @@ const resolve = async ({name, query, servers, port, recursions, retries, tries,
51
51
 
52
52
  // parse DNS answers to {type: [{name, data}]}
53
53
  const records = {};
54
- if (res && res.answers && res.answers.length) {
54
+ if (res?.answers?.length) {
55
55
  for (const {name, type, data} of res.answers || {}) {
56
56
  if (!name || !type || !data) continue;
57
57
  if (!records[type]) records[type] = [];
@@ -60,22 +60,22 @@ const resolve = async ({name, query, servers, port, recursions, retries, tries,
60
60
  }
61
61
 
62
62
  // If CAA(X) is not empty, R(X) = CAA (X)
63
- if (records.CAA && records.CAA.length) {
63
+ if (records.CAA?.length) {
64
64
  const caas = records.CAA.filter(record => record.name === name).map(record => record.data);
65
65
  if (caas.length) return caas;
66
66
  }
67
67
 
68
68
  let alias;
69
- if (records.CNAME && records.CNAME.length) {
69
+ if (records.CNAME?.length) {
70
70
  const dest = records.CNAME.find(record => record.name === name);
71
71
  alias = dest.data;
72
- } else if (records.DNAME && records.DNAME.length) {
72
+ } else if (records.DNAME?.length) {
73
73
  const dest = records.DNAME.find(record => record.name === name);
74
74
  alias = name.replace(dest.name, dest.data);
75
75
  }
76
76
 
77
77
  // If A(X) is not null, and CAA(A(X)) is not empty, then R(X) = CAA(A(X)), otherwise
78
- if (alias && records.CAA && records.CAA.length) {
78
+ if (alias && records.CAA?.length) {
79
79
  return records.CAA.filter(record => record.name === alias && record.data).map(record => record.data);
80
80
  }
81
81
 
@@ -94,7 +94,7 @@ export async function caa(name, opts = {}) {
94
94
 
95
95
  if (!opts.servers) {
96
96
  const systemServers = getServers();
97
- opts.servers = (systemServers && systemServers.length) ? systemServers : defaults.servers;
97
+ opts.servers = systemServers?.length ? systemServers : defaults.servers;
98
98
  }
99
99
 
100
100
  opts = {...defaults, ...opts};
@@ -127,10 +127,10 @@ export async function caaMatches(name, ca, opts = {}) {
127
127
  if (!caas.length) return true;
128
128
 
129
129
  const issueNames = caas
130
- .filter(caa => caa && caa.tag === "issue")
130
+ .filter(caa => caa?.tag === "issue")
131
131
  .map(name => normalizeName(name.value.split(";")[0].trim()));
132
132
  const issueWildNames = caas
133
- .filter(caa => caa && caa.tag === "issuewild")
133
+ .filter(caa => caa?.tag === "issuewild")
134
134
  .map(name => normalizeName(name.value.split(";")[0].trim()));
135
135
 
136
136
  const names = isWildcard(name) ? (issueWildNames.length ? issueWildNames : issueNames) : issueNames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caa",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "rfc6844-conform CAA record lookup and validation",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/caa",