@learncard/network-brain-client 2.5.45 → 2.5.47

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.
@@ -35466,7 +35466,24 @@ var getClient = /* @__PURE__ */ __name(async (url2, didAuthFunction, guardianApp
35466
35466
  const getChallenges = /* @__PURE__ */ __name(async (amount = 95 + Math.round((Math.random() - 0.5) * 5)) => {
35467
35467
  return challengeRequester.utilities.getChallenges.query({ amount });
35468
35468
  }, "getChallenges");
35469
- getChallenges().then((result) => challenges = result);
35469
+ let refillPromise;
35470
+ const refillChallenges = /* @__PURE__ */ __name(() => {
35471
+ refillPromise ??= getChallenges().then((result) => {
35472
+ if (result.length === 0) throw new Error("Challenge refill returned no challenges");
35473
+ challenges.push(...result);
35474
+ }).finally(() => {
35475
+ refillPromise = void 0;
35476
+ });
35477
+ return refillPromise;
35478
+ }, "refillChallenges");
35479
+ const takeChallenge = /* @__PURE__ */ __name(async () => {
35480
+ while (true) {
35481
+ const challenge = challenges.pop();
35482
+ if (challenge !== void 0) return challenge;
35483
+ await refillChallenges();
35484
+ }
35485
+ }, "takeChallenge");
35486
+ void refillChallenges().catch(() => void 0);
35470
35487
  const trpc = createTRPCClient({
35471
35488
  links: [
35472
35489
  callbackLink(async () => {
@@ -35477,10 +35494,10 @@ var getClient = /* @__PURE__ */ __name(async (url2, didAuthFunction, guardianApp
35477
35494
  maxURLLength: 3072,
35478
35495
  url: url2,
35479
35496
  headers: /* @__PURE__ */ __name(async () => {
35480
- if (challenges.length === 0) challenges.push(...await getChallenges());
35497
+ const challenge = await takeChallenge();
35481
35498
  const guardianApproval = guardianApprovalGetter ? await guardianApprovalGetter() : void 0;
35482
35499
  return {
35483
- Authorization: `Bearer ${await didAuthFunction(challenges.pop())}`,
35500
+ Authorization: `Bearer ${await didAuthFunction(challenge)}`,
35484
35501
  ...guardianApproval ? { "x-guardian-approval": guardianApproval } : {},
35485
35502
  ...extraHeaders
35486
35503
  };