edge-core-js
Advanced tools
Comparing version 1.3.2 to 1.3.3
# edge-core-js | ||
## v1.3.3 (2023-07-24) | ||
- changed: Add fallback to bridged `fetch` if request to edge-cors-proxy server fails | ||
## v1.3.2 (2023-07-13) | ||
@@ -4,0 +8,0 @@ |
@@ -1,2 +0,2 @@ | ||
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }import './polyfills' | ||
import './polyfills' | ||
@@ -6,2 +6,3 @@ import hashjs from 'hash.js' | ||
import { base64 } from 'rfc4648' | ||
import { makeFetchResponse } from 'serverlet' | ||
import { Bridge, bridgifyObject } from 'yaob' | ||
@@ -26,2 +27,4 @@ | ||
const hostnameProxyWhitelist = new Map() | ||
// A map of domains that failed CORS and failed via the CORS proxy server and succeeded via native fetch | ||
const hostnameBridgeProxyWhitelist = new Map() | ||
@@ -92,2 +95,10 @@ // Set up the bridges: | ||
const bridgeFetch = async ( | ||
uri, | ||
opts | ||
) => { | ||
const response = await clientIo.fetchCors(uri, opts) | ||
return makeFetchResponse(response) | ||
} | ||
const io = { | ||
@@ -141,9 +152,13 @@ disklet: { | ||
uri, | ||
opts | ||
opts = {} | ||
) { | ||
const { hostname } = new URL(uri) | ||
// Proactively use bridgeFetch for any hostnames added to whitelist: | ||
if (hostnameBridgeProxyWhitelist.get(hostname) === true) { | ||
return await bridgeFetch(uri, opts) | ||
} | ||
// Proactively use fetchCorsProxy for any hostnames added to whitelist: | ||
if (hostnameProxyWhitelist.get(hostname) === true) { | ||
return await fetchCorsProxy(uri, _nullishCoalesce(opts, () => ( {}))) | ||
return await fetchCorsProxy(uri, opts) | ||
} | ||
@@ -162,2 +177,8 @@ | ||
} catch (_) { | ||
// Fallback to bridge fetch if everything else fails | ||
try { | ||
const response = await bridgeFetch(uri, opts) | ||
hostnameBridgeProxyWhitelist.set(hostname, true) | ||
return response | ||
} catch (_) {} | ||
// Throw the error from the first fetch instead of the one from | ||
@@ -231,3 +252,3 @@ // proxy server. | ||
uri, | ||
opts = {} | ||
opts | ||
) => { | ||
@@ -234,0 +255,0 @@ const shuffledUrls = shuffle([...PROXY_SERVER_URLS]) |
{ | ||
"name": "edge-core-js", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Edge account & wallet management library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
3440049
32277
159