@web3-storage/access
Advanced tools
Comparing version 12.0.1 to 12.0.2
{ | ||
"name": "@web3-storage/access", | ||
"version": "12.0.1", | ||
"version": "12.0.2", | ||
"description": "w3access client", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/web3-storage/w3-protocol/tree/main/packages/access-client", |
@@ -118,38 +118,15 @@ import { addSpacesFromDelegations, Agent as AccessAgent } from './agent.js' | ||
const interval = opts?.interval || 250 | ||
/** @type {ReturnType<typeof setTimeout>} */ | ||
let pollingTimeoutId | ||
const claimed = await new Promise((resolve, reject) => { | ||
opts?.signal?.addEventListener('abort', (e) => { | ||
pollingTimeoutId && clearTimeout(pollingTimeoutId) | ||
reject( | ||
new Error('pollAccessClaimUntilSessionProof aborted', { cause: e }) | ||
) | ||
while (true) { | ||
if (opts?.signal?.aborted) | ||
throw opts.signal.reason ?? new Error('operation aborted') | ||
const res = await access.invokeAndExecute(w3caps.Access.claim, { | ||
with: delegee, | ||
}) | ||
poll(interval) | ||
/** | ||
* @param {number} retryAfter | ||
*/ | ||
async function poll(retryAfter) { | ||
const pollClaimResult = await access.invokeAndExecute( | ||
w3caps.Access.claim, | ||
{ with: delegee } | ||
) | ||
if (pollClaimResult.error) { | ||
return reject(pollClaimResult) | ||
} | ||
try { | ||
const claimedDelegations = Object.values( | ||
pollClaimResult.delegations | ||
).flatMap((d) => bytesToDelegations(d)) | ||
if (delegationsMatch(claimedDelegations)) { | ||
resolve(claimedDelegations) | ||
} else { | ||
pollingTimeoutId = setTimeout(() => poll(retryAfter), retryAfter) | ||
} | ||
} catch (error) { | ||
reject(error) | ||
} | ||
} | ||
}) | ||
return claimed | ||
if (res.error) throw res | ||
const claims = Object.values(res.delegations).flatMap((d) => | ||
bytesToDelegations(d) | ||
) | ||
if (delegationsMatch(claims)) return claims | ||
await new Promise((resolve) => setTimeout(resolve, interval)) | ||
} | ||
} | ||
@@ -156,0 +133,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
195111
5234