@le-space/core 0.3.13 → 0.3.14

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.
Files changed (3) hide show
  1. package/index.d.ts +6 -0
  2. package/index.js +15 -9
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -627,6 +627,12 @@ declare function fetchUcGoPeerMetadata(args: {
627
627
  delayMs?: number;
628
628
  timeoutMs?: number;
629
629
  sleep?: (ms: number) => Promise<void>;
630
+ isReady?: (result: {
631
+ payload: unknown;
632
+ ok: boolean;
633
+ status: number | null;
634
+ requestUrl: string;
635
+ }) => boolean;
630
636
  onAttempt?: (result: {
631
637
  payload: unknown;
632
638
  ready: boolean;
package/index.js CHANGED
@@ -1976,6 +1976,7 @@ async function fetchUcGoPeerMetadata(args) {
1976
1976
  const delayMs = Math.max(0, Number(args.delayMs ?? 3e3));
1977
1977
  const sleep = args.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
1978
1978
  let lastPayload = null;
1979
+ let lastError = null;
1979
1980
  for (let attempt = 0; attempt < attempts; attempt += 1) {
1980
1981
  const controller = new AbortController();
1981
1982
  const timeout = setTimeout(
@@ -1992,8 +1993,14 @@ async function fetchUcGoPeerMetadata(args) {
1992
1993
  );
1993
1994
  const payload = await response.json().catch(() => null);
1994
1995
  lastPayload = payload;
1996
+ lastError = null;
1995
1997
  const ready = Boolean(
1996
- response.ok && payload && typeof payload === "object" && payload.status === "ready"
1998
+ args.isReady ? args.isReady({
1999
+ payload,
2000
+ ok: response.ok,
2001
+ status: response.status,
2002
+ requestUrl
2003
+ }) : response.ok && payload && typeof payload === "object" && payload.status === "ready"
1997
2004
  );
1998
2005
  args.onAttempt?.({
1999
2006
  payload,
@@ -2008,12 +2015,11 @@ async function fetchUcGoPeerMetadata(args) {
2008
2015
  if (ready) {
2009
2016
  return payload;
2010
2017
  }
2011
- if (response.status >= 500) {
2012
- throw new Error(
2013
- `Relay metadata request failed: ${response.status} ${typeof payload === "string" ? payload : JSON.stringify(payload ?? {})}`
2014
- );
2015
- }
2016
2018
  } catch (error) {
2019
+ lastError = error instanceof Error ? error.message : String(error);
2020
+ lastPayload = {
2021
+ error: lastError
2022
+ };
2017
2023
  args.onAttempt?.({
2018
2024
  payload: null,
2019
2025
  ready: false,
@@ -2022,9 +2028,8 @@ async function fetchUcGoPeerMetadata(args) {
2022
2028
  requestUrl,
2023
2029
  ok: false,
2024
2030
  status: null,
2025
- error: error instanceof Error ? error.message : String(error)
2031
+ error: lastError
2026
2032
  });
2027
- throw error;
2028
2033
  } finally {
2029
2034
  clearTimeout(timeout);
2030
2035
  }
@@ -2033,7 +2038,7 @@ async function fetchUcGoPeerMetadata(args) {
2033
2038
  }
2034
2039
  }
2035
2040
  throw new Error(
2036
- `Relay metadata did not become ready after ${attempts} attempts: ${typeof lastPayload === "string" ? lastPayload : JSON.stringify(lastPayload ?? {})}`
2041
+ `Relay metadata did not become ready after ${attempts} attempts: ${lastError ? lastError : typeof lastPayload === "string" ? lastPayload : JSON.stringify(lastPayload ?? {})}`
2037
2042
  );
2038
2043
  }
2039
2044
  async function verifyUcGoPeerReachability(args) {
@@ -2764,6 +2769,7 @@ async function fetchRelayMetadataForRuntime(args) {
2764
2769
  attempts: args.attempts,
2765
2770
  delayMs: args.delayMs,
2766
2771
  timeoutMs: args.timeoutMs,
2772
+ isReady: (result) => extractRelayMetadata(result.payload) != null,
2767
2773
  onAttempt: (result) => {
2768
2774
  args.onAttempt?.({
2769
2775
  ...result,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@le-space/aleph-bootstrap": "0.3.13",
20
- "@le-space/shared-types": "0.3.13"
19
+ "@le-space/aleph-bootstrap": "0.3.14",
20
+ "@le-space/shared-types": "0.3.14"
21
21
  }
22
22
  }