mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Remove dotenv and better handle options
This commit is contained in:
parent
93cab2c126
commit
86aa366ccc
5 changed files with 12 additions and 18 deletions
|
@ -6,7 +6,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bent": "^7.3.12",
|
"bent": "^7.3.12",
|
||||||
"browserify": "^17.0.0",
|
"browserify": "^17.0.0",
|
||||||
"dotenv": "^8.2.0",
|
|
||||||
"valid-url": "^1.0.9"
|
"valid-url": "^1.0.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
10
src/index.js
10
src/index.js
|
@ -22,6 +22,10 @@ const verify = async (uri, fingerprint, opts) => {
|
||||||
if (!fingerprint) { fingerprint = null }
|
if (!fingerprint) { fingerprint = null }
|
||||||
if (!opts) { opts = {} }
|
if (!opts) { opts = {} }
|
||||||
|
|
||||||
|
if (!('doipProxyHostname' in opts) || !opts.doipProxyHostname) {
|
||||||
|
opts.doipProxyHostname = 'proxy.keyoxide.org'
|
||||||
|
}
|
||||||
|
|
||||||
if (!validUrl.isUri(uri)) {
|
if (!validUrl.isUri(uri)) {
|
||||||
throw new Error('Not a valid URI')
|
throw new Error('Not a valid URI')
|
||||||
}
|
}
|
||||||
|
@ -40,10 +44,10 @@ const verify = async (uri, fingerprint, opts) => {
|
||||||
|
|
||||||
if (spData.customRequestHandler instanceof Function) {
|
if (spData.customRequestHandler instanceof Function) {
|
||||||
proofData = await spData.customRequestHandler(spData, opts)
|
proofData = await spData.customRequestHandler(spData, opts)
|
||||||
} else if (!spData.proof.useProxy || 'useProxyWhenNeeded' in opts && !opts.useProxyWhenNeeded) {
|
} else if (!spData.proof.useProxy || 'proxyPolicy' in opts && !opts.useProxyWhenNeeded) {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData)
|
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
||||||
} else {
|
} else {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData)
|
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proofData) {
|
if (proofData) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ const match = (uri, opts) => {
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
const directRequestHandler = async (spData) => {
|
const directRequestHandler = async (spData, opts) => {
|
||||||
const res = await req(spData.proof.fetch ? spData.proof.fetch : spData.proof.uri, null, { Accept: 'application/json' })
|
const res = await req(spData.proof.fetch ? spData.proof.fetch : spData.proof.uri, null, { Accept: 'application/json' })
|
||||||
|
|
||||||
switch (spData.proof.format) {
|
switch (spData.proof.format) {
|
||||||
|
@ -80,9 +80,9 @@ const directRequestHandler = async (spData) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxyRequestHandler = async (spData) => {
|
const proxyRequestHandler = async (spData, opts) => {
|
||||||
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
|
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
|
||||||
const res = await req(utils.generateProxyURL(spData.proof.format, url), null, { Accept: 'application/json' })
|
const res = await req(utils.generateProxyURL(spData.proof.format, url, opts), null, { Accept: 'application/json' })
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
return json.content
|
return json.content
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
require('dotenv').config()
|
const generateProxyURL = (type, url, opts) => {
|
||||||
|
return `https://${opts.doipProxyHostname}/api/1/get/${type}/${encodeURIComponent(url)}`
|
||||||
const DOIP_PROXY_HOSTNAME = process.env.DOIP_PROXY_HOSTNAME || 'proxy.keyoxide.org'
|
|
||||||
|
|
||||||
const generateProxyURL = (type, url) => {
|
|
||||||
return `https://${DOIP_PROXY_HOSTNAME}/api/1/get/${type}/${encodeURIComponent(url)}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateClaim = (fingerprint, format) => {
|
const generateClaim = (fingerprint, format) => {
|
||||||
|
|
|
@ -734,11 +734,6 @@ dot-case@^3.0.3:
|
||||||
no-case "^3.0.3"
|
no-case "^3.0.3"
|
||||||
tslib "^1.10.0"
|
tslib "^1.10.0"
|
||||||
|
|
||||||
dotenv@^8.2.0:
|
|
||||||
version "8.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
|
|
||||||
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
|
|
||||||
|
|
||||||
duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2:
|
duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
|
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
|
||||||
|
|
Loading…
Reference in a new issue