@le-space/core 0.6.23 → 0.6.25

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 +0 -3
  2. package/index.js +47 -45
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -790,7 +790,6 @@ declare function waitForRelayBootstrapRegistration(args: {
790
790
  apiHost?: string;
791
791
  channel?: string;
792
792
  ref?: string;
793
- postType?: string;
794
793
  attempts?: number;
795
794
  delayMs?: number;
796
795
  sleep?: (ms: number) => Promise<void>;
@@ -808,7 +807,6 @@ declare function publishRelayBootstrapRegistration(args: {
808
807
  apiHost?: string;
809
808
  channel?: string;
810
809
  ref?: string;
811
- postType?: string;
812
810
  compactMultiaddrLimit?: number;
813
811
  profile?: string;
814
812
  version?: string;
@@ -954,7 +952,6 @@ declare function reconcileOwnerRelayBootstrapRegistrations(args: {
954
952
  apiHost?: string;
955
953
  channel?: string;
956
954
  ref?: string;
957
- postType?: string;
958
955
  version?: string;
959
956
  ownerAddress?: string;
960
957
  ownerSigner?: MessageSigner;
package/index.js CHANGED
@@ -73,7 +73,7 @@ function validateRootfsManifest(manifest) {
73
73
  function normalizeStatus(status) {
74
74
  if (typeof status !== "string") return "unknown";
75
75
  const normalized = status.toLowerCase();
76
- if (normalized === "processed" || normalized === "pending" || normalized === "rejected") {
76
+ if (normalized === "processed" || normalized === "pending" || normalized === "rejected" || normalized === "removing" || normalized === "removed") {
77
77
  return normalized;
78
78
  }
79
79
  return "unknown";
@@ -98,6 +98,7 @@ function parseCidFromPayload(payload) {
98
98
  }
99
99
  function parseRejectionReason(payload) {
100
100
  const errorCode = typeof payload.error_code === "number" ? payload.error_code : null;
101
+ const reason = typeof payload.reason === "string" ? payload.reason.trim() : "";
101
102
  const details = payload.details && typeof payload.details === "object" ? payload.details : null;
102
103
  const rawErrors = Array.isArray(details?.errors) ? details.errors : [];
103
104
  const firstError = rawErrors[0] && typeof rawErrors[0] === "object" ? rawErrors[0] : null;
@@ -112,6 +113,18 @@ function parseRejectionReason(payload) {
112
113
  };
113
114
  }
114
115
  }
116
+ if (reason === "balance_insufficient") {
117
+ return {
118
+ rejectionErrorCode: errorCode,
119
+ rejectionReason: "The rootfs STORE is being removed because its publisher no longer has enough Aleph credits. Your connected MetaMask balance may be sufficient, but this manifest must point to a newly published, processed rootfs STORE."
120
+ };
121
+ }
122
+ if (reason) {
123
+ return {
124
+ rejectionErrorCode: errorCode,
125
+ rejectionReason: `Aleph marked the rootfs STORE as unavailable: ${reason.replaceAll("_", " ")}.`
126
+ };
127
+ }
115
128
  return {
116
129
  rejectionErrorCode: errorCode,
117
130
  rejectionReason: errorCode != null ? `Rejected by Aleph (error code ${errorCode}).` : null
@@ -162,14 +175,15 @@ async function resolveRootfsReference(itemHash, options) {
162
175
  const firstMessage = Array.isArray(payload.messages) && payload.messages[0] && typeof payload.messages[0] === "object" ? payload.messages[0] : null;
163
176
  const messageObject = payload.message && typeof payload.message === "object" ? payload.message : null;
164
177
  const cid = parseCidFromPayload(payload);
165
- const rejection = normalizeStatus(payload.status) === "rejected" ? parseRejectionReason(payload) : { rejectionErrorCode: null, rejectionReason: null };
178
+ const messageStatus = normalizeStatus(payload.status);
179
+ const rejection = messageStatus === "processed" || messageStatus === "pending" ? { rejectionErrorCode: null, rejectionReason: null } : parseRejectionReason(payload);
166
180
  const gateway = cid ? await probeRootfsGateway(cid, {
167
181
  gatewayBaseUrl: options.gatewayBaseUrl,
168
182
  fetch: options.fetch
169
183
  }) : { gatewayUrl: null, gatewayStatus: "unknown", gatewayError: null };
170
184
  return {
171
185
  itemHash,
172
- messageStatus: normalizeStatus(payload.status),
186
+ messageStatus,
173
187
  messageType: String(payload.type || messageObject?.type || firstMessage?.type || "").toUpperCase() || null,
174
188
  cid,
175
189
  receptionTime: typeof payload.reception_time === "string" ? payload.reception_time : null,
@@ -2417,8 +2431,7 @@ async function verifyUcGoPeerReachability(args) {
2417
2431
  var DEFAULT_ALEPH_API_HOST2 = "https://api.aleph.im";
2418
2432
  var DEFAULT_ALEPH_BOOTSTRAP_CHANNEL = "simple-todo";
2419
2433
  var DEFAULT_ALEPH_BOOTSTRAP_REF = "simple-todo-bootstrap";
2420
- var DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE = "relay-bootstrap";
2421
- var DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE = "relay-bootstrap-v2";
2434
+ var DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE = "relay-bootstrap-v2";
2422
2435
  var DEFAULT_BOOTSTRAP_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
2423
2436
  var DEFAULT_BOOTSTRAP_PAGINATION = 50;
2424
2437
  var DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT = 3;
@@ -2452,9 +2465,6 @@ function serializeRelayProofPayload(payload) {
2452
2465
  function relayBootstrapMultiaddrsHash(addrs) {
2453
2466
  return keccak256(stringToHex(JSON.stringify(dedupeMultiaddrs(addrs))));
2454
2467
  }
2455
- function compactPostType(postType) {
2456
- return (postType ?? DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE) === DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE;
2457
- }
2458
2468
  function browserMultiaddrPreference(addr) {
2459
2469
  const normalized = addr.toLowerCase();
2460
2470
  if (normalized.includes("/tcp/443/tls/ws/")) return 0;
@@ -2684,8 +2694,6 @@ function normalizeRelayBootstrapPostRecord(value) {
2684
2694
  function buildRelayBootstrapPostContent(args) {
2685
2695
  const now = args.now ?? Date.now() / 1e3;
2686
2696
  const updatedAt = args.now ?? Date.now();
2687
- const postType = args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE;
2688
- const compact = args.compact ?? compactPostType(postType);
2689
2697
  const fullMultiaddrs = filterPublicMultiaddrs(args.multiaddrs);
2690
2698
  const fullBrowserMultiaddrs = args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
2691
2699
  browserDialableOnly: true
@@ -2695,13 +2703,13 @@ function buildRelayBootstrapPostContent(args) {
2695
2703
  args.compactMultiaddrLimit
2696
2704
  );
2697
2705
  return {
2698
- type: postType,
2706
+ type: DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE,
2699
2707
  address: args.sender,
2700
2708
  ...args.ref ? { ref: args.ref } : {},
2701
2709
  content: {
2702
2710
  peerId: args.peerId,
2703
- multiaddrs: compact ? compactMultiaddrs : fullMultiaddrs,
2704
- browserMultiaddrs: compact ? void 0 : fullBrowserMultiaddrs,
2711
+ multiaddrs: compactMultiaddrs,
2712
+ browserMultiaddrs: void 0,
2705
2713
  registrationId: args.registrationId,
2706
2714
  profile: args.profile,
2707
2715
  version: args.version,
@@ -2724,14 +2732,12 @@ async function createRelayBootstrapPost(args) {
2724
2732
  browserMultiaddrs: args.browserMultiaddrs,
2725
2733
  registrationId: args.registrationId,
2726
2734
  ref: args.ref ?? DEFAULT_ALEPH_BOOTSTRAP_REF,
2727
- postType: args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE,
2728
2735
  profile: args.profile,
2729
2736
  version: args.version,
2730
2737
  ownerAddress: args.ownerAddress,
2731
2738
  publisherAddress: args.publisherAddress,
2732
2739
  authorization: args.authorization,
2733
2740
  relayProof: args.relayProof,
2734
- compact: args.compact,
2735
2741
  compactMultiaddrLimit: args.compactMultiaddrLimit,
2736
2742
  now: nowMillis
2737
2743
  });
@@ -2778,12 +2784,11 @@ async function signRelayBootstrapProof(args) {
2778
2784
  fullBrowserMultiaddrs && fullBrowserMultiaddrs.length > 0 ? fullBrowserMultiaddrs : fullMultiaddrs,
2779
2785
  args.compactMultiaddrLimit
2780
2786
  );
2781
- const compact = args.compact ?? false;
2782
2787
  const payload = {
2783
2788
  peerId: args.peerId,
2784
- multiaddrs: compact ? void 0 : fullMultiaddrs,
2785
- browserMultiaddrs: compact ? void 0 : fullBrowserMultiaddrs,
2786
- multiaddrsHash: compact ? relayBootstrapMultiaddrsHash(compactMultiaddrs) : void 0,
2789
+ multiaddrs: void 0,
2790
+ browserMultiaddrs: void 0,
2791
+ multiaddrsHash: relayBootstrapMultiaddrsHash(compactMultiaddrs),
2787
2792
  registrationId: args.registrationId,
2788
2793
  profile: args.profile,
2789
2794
  version: args.version,
@@ -2813,10 +2818,7 @@ async function fetchAlephBootstrapPosts(options = {}) {
2813
2818
  options.channel ?? DEFAULT_ALEPH_BOOTSTRAP_CHANNEL
2814
2819
  );
2815
2820
  url.searchParams.set("refs", options.ref ?? DEFAULT_ALEPH_BOOTSTRAP_REF);
2816
- url.searchParams.set(
2817
- "types",
2818
- options.postType ?? DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE
2819
- );
2821
+ url.searchParams.set("types", DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE);
2820
2822
  url.searchParams.set(
2821
2823
  "pagination",
2822
2824
  String(options.pagination ?? DEFAULT_BOOTSTRAP_PAGINATION)
@@ -2830,7 +2832,21 @@ async function fetchAlephBootstrapPosts(options = {}) {
2830
2832
  throw new Error(`Aleph bootstrap post lookup failed: ${response.status}`);
2831
2833
  }
2832
2834
  const payload = await response.json();
2833
- return (payload.posts ?? []).map((entry) => normalizeRelayBootstrapPostRecord(entry)).filter((entry) => entry != null).sort((left, right) => compareRelayBootstrapPostRecency(right, left));
2835
+ const posts = (payload.posts ?? []).map((entry) => normalizeRelayBootstrapPostRecord(entry)).filter((entry) => entry != null).sort((left, right) => compareRelayBootstrapPostRecency(right, left));
2836
+ posts.forEach(assertSupportedRelayBootstrapPost);
2837
+ return posts;
2838
+ }
2839
+ function assertSupportedRelayBootstrapPost(post) {
2840
+ if (post.type === "relay-bootstrap") {
2841
+ throw new Error(
2842
+ "Legacy relay-bootstrap record encountered. Only relay-bootstrap-v2 is supported."
2843
+ );
2844
+ }
2845
+ if (post.type && post.type !== DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE) {
2846
+ throw new Error(
2847
+ `Unsupported relay bootstrap post type: ${post.type}. Expected ${DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE}.`
2848
+ );
2849
+ }
2834
2850
  }
2835
2851
  function compareRelayBootstrapPostRecency(left, right) {
2836
2852
  const leftUpdatedAt = left.content?.updatedAt ?? 0;
@@ -2852,6 +2868,7 @@ function selectCurrentRelayBootstrapPosts(posts, options = {}) {
2852
2868
  const now = options.now ?? Date.now();
2853
2869
  const selected = /* @__PURE__ */ new Map();
2854
2870
  for (const post of posts) {
2871
+ assertSupportedRelayBootstrapPost(post);
2855
2872
  const content = post.content;
2856
2873
  if (!content) continue;
2857
2874
  if (now - content.updatedAt > maxAgeMs) continue;
@@ -2877,14 +2894,12 @@ async function waitForRelayBootstrapRegistration(args) {
2877
2894
  const expectedSender = args.sender?.trim().toLowerCase() || null;
2878
2895
  const expectedRegistrationId = args.registrationId?.trim() || null;
2879
2896
  const expectedPeerId = args.peerId?.trim() || null;
2880
- const postType = args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE;
2881
2897
  const sleepImpl = args.sleep ?? sleep;
2882
2898
  for (let attempt = 0; attempt < attempts; attempt += 1) {
2883
2899
  const posts = await fetchAlephBootstrapPosts({
2884
2900
  apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST2,
2885
2901
  channel: args.channel,
2886
2902
  ref: args.ref,
2887
- postType,
2888
2903
  fetch: args.fetch
2889
2904
  });
2890
2905
  const currentPosts = selectCurrentRelayBootstrapPosts(posts);
@@ -2923,8 +2938,6 @@ async function waitForRelayBootstrapRegistration(args) {
2923
2938
  async function publishRelayBootstrapRegistration(args) {
2924
2939
  const publisherAddress = args.publisherAddress ?? args.sender;
2925
2940
  const ownerAddress = args.ownerAddress;
2926
- const postType = args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE;
2927
- const compact = postType === DEFAULT_ALEPH_BOOTSTRAP_COMPACT_POST_TYPE;
2928
2941
  let ownerAuthorization = args.ownerAuthorization;
2929
2942
  let relayProof = args.relayProof;
2930
2943
  if (!ownerAuthorization && ownerAddress && args.ownerSigner) {
@@ -2951,7 +2964,6 @@ async function publishRelayBootstrapRegistration(args) {
2951
2964
  profile: args.profile,
2952
2965
  version: args.version,
2953
2966
  updatedAt: args.now ?? Date.now(),
2954
- compact,
2955
2967
  compactMultiaddrLimit: args.compactMultiaddrLimit,
2956
2968
  signer: args.publisherSigner
2957
2969
  });
@@ -2964,14 +2976,12 @@ async function publishRelayBootstrapRegistration(args) {
2964
2976
  registrationId: args.registrationId,
2965
2977
  channel: args.channel,
2966
2978
  ref: args.ref,
2967
- postType,
2968
2979
  profile: args.profile,
2969
2980
  version: args.version,
2970
2981
  ownerAddress,
2971
2982
  publisherAddress,
2972
2983
  authorization: ownerAuthorization,
2973
2984
  relayProof,
2974
- compact,
2975
2985
  compactMultiaddrLimit: args.compactMultiaddrLimit,
2976
2986
  now: args.now,
2977
2987
  hasher: args.hasher
@@ -2994,18 +3004,12 @@ async function publishRelayBootstrapRegistration(args) {
2994
3004
  let forgottenHashes = [];
2995
3005
  let forgetResult;
2996
3006
  if (args.forgetPrevious && args.registrationId) {
2997
- const previousPostTypes = compact ? [postType, DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE] : [postType];
2998
- const previousPosts = (await Promise.all(
2999
- previousPostTypes.map(
3000
- (previousPostType) => fetchAlephBootstrapPosts({
3001
- apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST2,
3002
- channel: args.channel,
3003
- ref: args.ref,
3004
- postType: previousPostType,
3005
- fetch: args.fetch
3006
- })
3007
- )
3008
- )).flat();
3007
+ const previousPosts = await fetchAlephBootstrapPosts({
3008
+ apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST2,
3009
+ channel: args.channel,
3010
+ ref: args.ref,
3011
+ fetch: args.fetch
3012
+ });
3009
3013
  const forgottenHashSet = new Set(
3010
3014
  previousPosts.filter((post) => {
3011
3015
  const hash = post.itemHash ?? post.hash;
@@ -3491,7 +3495,6 @@ async function reconcileOwnerRelayBootstrapRegistrations(args) {
3491
3495
  apiHost: args.apiHost,
3492
3496
  channel: args.channel,
3493
3497
  ref: args.ref,
3494
- postType: args.postType,
3495
3498
  peerId: relayMetadata.peerId,
3496
3499
  multiaddrs: relayMetadata.probeMultiaddrs,
3497
3500
  browserMultiaddrs: relayMetadata.browserBootstrapMultiaddrs,
@@ -3521,7 +3524,6 @@ async function reconcileOwnerRelayBootstrapRegistrations(args) {
3521
3524
  apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST,
3522
3525
  channel: args.channel,
3523
3526
  ref: args.ref,
3524
- postType: args.postType,
3525
3527
  fetch: args.fetch
3526
3528
  });
3527
3529
  const currentPosts = selectCurrentRelayBootstrapPosts(bootstrapPosts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.6.23",
3
+ "version": "0.6.25",
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.6.23",
28
- "@le-space/shared-types": "0.6.23"
27
+ "@le-space/aleph-bootstrap": "0.6.25",
28
+ "@le-space/shared-types": "0.6.25"
29
29
  }
30
30
  }