@le-space/core 0.9.4 → 0.9.5

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 (2) hide show
  1. package/index.js +14 -11
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -3005,20 +3005,24 @@ async function fetchAlephBootstrapPosts(options = {}) {
3005
3005
  }
3006
3006
  const payload = await response.json();
3007
3007
  const posts = (payload.posts ?? []).map((entry) => normalizeRelayBootstrapPostRecord(entry)).filter((entry) => entry != null).sort((left, right) => compareRelayBootstrapPostRecency(right, left));
3008
- posts.forEach(assertSupportedRelayBootstrapPost);
3009
- return posts;
3008
+ return usableRelayBootstrapPosts(posts, options.onUnsupportedPost);
3010
3009
  }
3011
- function assertSupportedRelayBootstrapPost(post) {
3010
+ function unsupportedRelayBootstrapReason(post) {
3012
3011
  if (post.type === "relay-bootstrap") {
3013
- throw new Error(
3014
- "Legacy relay-bootstrap record encountered. Only relay-bootstrap-v2 is supported."
3015
- );
3012
+ return "legacy relay-bootstrap record; only relay-bootstrap-v2 is supported";
3016
3013
  }
3017
3014
  if (post.type && post.type !== DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE) {
3018
- throw new Error(
3019
- `Unsupported relay bootstrap post type: ${post.type}. Expected ${DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE}.`
3020
- );
3015
+ return `unsupported post type ${post.type}; expected ${DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE}`;
3021
3016
  }
3017
+ return null;
3018
+ }
3019
+ function usableRelayBootstrapPosts(posts, onUnsupportedPost) {
3020
+ return posts.filter((post) => {
3021
+ const reason = unsupportedRelayBootstrapReason(post);
3022
+ if (!reason) return true;
3023
+ onUnsupportedPost?.({ hash: post.itemHash ?? post.hash, reason });
3024
+ return false;
3025
+ });
3022
3026
  }
3023
3027
  function compareRelayBootstrapPostRecency(left, right) {
3024
3028
  const leftUpdatedAt = left.content?.updatedAt ?? 0;
@@ -3039,8 +3043,7 @@ function selectCurrentRelayBootstrapPosts(posts, options = {}) {
3039
3043
  const maxAgeMs = options.maxAgeMs ?? DEFAULT_BOOTSTRAP_MAX_AGE_MS;
3040
3044
  const now = options.now ?? Date.now();
3041
3045
  const selected = /* @__PURE__ */ new Map();
3042
- for (const post of posts) {
3043
- assertSupportedRelayBootstrapPost(post);
3046
+ for (const post of usableRelayBootstrapPosts(posts, options.onUnsupportedPost)) {
3044
3047
  const content = post.content;
3045
3048
  if (!content) continue;
3046
3049
  if (now - content.updatedAt > maxAgeMs) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/NiKrause/relay-button/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@le-space/aleph-bootstrap": "0.9.4",
28
- "@le-space/shared-types": "0.9.4"
27
+ "@le-space/aleph-bootstrap": "0.9.5",
28
+ "@le-space/shared-types": "0.9.5"
29
29
  }
30
30
  }