Skip to content

Commit

Permalink
fix: add request library
Browse files Browse the repository at this point in the history
closes #46
  • Loading branch information
Kikobeats committed Jun 21, 2023
1 parent 5650308 commit 339d85b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"hubspot",
"mail"
],
"dependencies": {
"simple-get": "~4.0.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
Expand All @@ -66,7 +69,7 @@
"standard-version": "latest"
},
"engines": {
"node": ">= 18"
"node": ">= 14"
},
"files": [
"domains.js",
Expand Down
12 changes: 10 additions & 2 deletions scripts/postinstall.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { writeFile } from 'node:fs/promises'
import simpleGet from 'simple-get'

const get = (url, opts) =>
new Promise((resolve, reject) =>
simpleGet.concat({ url: url.toString(), ...opts }, (err, res, data) =>
err ? reject(err) : resolve({ res, data })
)
)

/* List of free email domains by HubSpot
https://knowledge.hubspot.com/forms/what-domains-are-blocked-when-using-the-forms-email-domains-to-block-feature */
Expand All @@ -13,8 +21,8 @@ const trim = text => text.replace(/^\s+|\s+$/g, '')
const sanetize = text => text.split(/[,\n]/g).map(trim).filter(Boolean)

try {
const raw = await fetch(URL).then(res => res.text())
const domains = new Set(sanetize(raw))
const data = await get(URL).then(res => res.data.toString())
const domains = new Set(sanetize(data))
for (const domain of DOMAINS) domains.add(domain)
const sorted = Array.from(domains).sort()
await writeFile('domains.json', JSON.stringify(sorted, null, 2))
Expand Down

0 comments on commit 339d85b

Please sign in to comment.