@le-space/core 0.3.32 → 0.4.1

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 +3 -28
  2. package/index.js +13 -104
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _le_space_shared_types from '@le-space/shared-types';
2
- import { RootfsResolution, RootfsManifest, RootfsManifestState, CrnRecord, RootfsRequiredPortForward, PortForwardAggregate, PortForwardFlags, PortForwardAggregateEntry, MessageReference, InstanceExecution, MessageStatus, DeploymentInspectionResult, MessageInspectionResult, AlephBroadcastMessage, AlephBroadcastResponse, MessageSigner, MessageHasher, DeploymentProgressListener, AlephAggregateContent, AlephInstanceContent, DeploymentIntentEnvelope, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping, VmBootstrapConfigRecord, VmBootstrapConfigAggregate, VmBootstrapConfigSignalRecord, VmBootstrapConfigSignalType } from '@le-space/shared-types';
2
+ import { RootfsResolution, RootfsManifest, RootfsManifestState, CrnRecord, RootfsRequiredPortForward, PortForwardAggregate, PortForwardFlags, PortForwardAggregateEntry, MessageReference, InstanceExecution, MessageStatus, DeploymentInspectionResult, MessageInspectionResult, AlephBroadcastMessage, AlephBroadcastResponse, MessageSigner, MessageHasher, DeploymentProgressListener, AlephAggregateContent, AlephInstanceContent, DeploymentIntentEnvelope, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping, VmBootstrapConfigRecord, VmBootstrapConfigAggregate } from '@le-space/shared-types';
3
3
 
4
4
  declare const DEFAULT_ALEPH_CHANNEL = "TEST";
5
5
 
@@ -724,6 +724,7 @@ declare function waitForRelayBootstrapRegistration(args: {
724
724
  postType?: string;
725
725
  attempts?: number;
726
726
  delayMs?: number;
727
+ onAttempt?: (match: RelayBootstrapVisibilityResult | null, attempt: number, attempts: number) => void;
727
728
  }): Promise<RelayBootstrapVisibilityResult | null>;
728
729
  declare function publishRelayBootstrapRegistration(args: {
729
730
  sender: string;
@@ -756,8 +757,6 @@ declare function publishRelayBootstrapRegistration(args: {
756
757
  }): Promise<RelayBootstrapPublicationResult>;
757
758
 
758
759
  declare const VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
759
- declare const VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
760
- declare const VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
761
760
  declare function fetchVmBootstrapConfigAggregate(address: string, options: {
762
761
  apiHost?: string;
763
762
  fetch: JsonFetchLike$1;
@@ -796,30 +795,6 @@ declare function deleteVmBootstrapConfig(args: {
796
795
  aggregateStatus: MessageStatus;
797
796
  aggregate: VmBootstrapConfigAggregate;
798
797
  }>;
799
- declare function fetchVmBootstrapConfigSignals(args: {
800
- deploymentToken?: string;
801
- ownerAddress?: string;
802
- instanceItemHash?: string;
803
- fetch: JsonFetchLike$1;
804
- apiHost?: string;
805
- ref?: string;
806
- postType?: string;
807
- page?: number;
808
- pagination?: number;
809
- }): Promise<VmBootstrapConfigSignalRecord[]>;
810
- declare function waitForVmBootstrapConfigSignal(args: {
811
- deploymentToken: string;
812
- ownerAddress: string;
813
- instanceItemHash: string;
814
- expectedStatus?: VmBootstrapConfigSignalType;
815
- fetch: JsonFetchLike$1;
816
- apiHost?: string;
817
- ref?: string;
818
- postType?: string;
819
- attempts?: number;
820
- delayMs?: number;
821
- sleep?: (ms: number) => Promise<void>;
822
- }): Promise<VmBootstrapConfigSignalRecord | null>;
823
798
 
824
799
  type JsonFetchLike = FetchLike;
825
800
  type RelayMetadataShape = {
@@ -888,4 +863,4 @@ declare function reconcileOwnerRelayBootstrapRegistrations(args: {
888
863
  } | null;
889
864
  }): Promise<OwnerRelayBootstrapReconcileResult>;
890
865
 
891
- export { type CrnCapacitySpec, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike$1 as JsonFetchLike, type JsonFetchLikeResponse, type OwnerRelayBootstrapReconcileResult, type PaymentQuote, type RelayBootstrapPublicationResult, type RelayBootstrapVisibilityResult, type RelayMetadataShape, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY, VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE, VM_BOOTSTRAP_CONFIG_SIGNAL_REF, appendDeploymentTokenToSshPublicKey, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureOrbitdbRelaySetup, configureUcGoPeer, createDeploymentIntent, createDeploymentToken, createInstanceContent, createPortForwardAggregateContent, createRelayBootstrapRegistrationId, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, createVmBootstrapConfigAggregateContent, deleteVmBootstrapConfig, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractInsufficientBalanceMessage, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchRelayMetadataForRuntime, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmBootstrapConfigAggregate, fetchVmBootstrapConfigSignals, fetchVmRuntime, filterDeployableCrns, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, notifyCrnAllocationWithRetry, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, publishRelayBootstrapRegistration, publishVmBootstrapConfig, quoteRequiredBudgetUnits, rankCandidateCrns, reconcileOwnerRelayBootstrapRegistrations, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForRelayBootstrapRegistration, waitForSetupEndpoint, waitForVmBootstrapConfigSignal, waitForVmRuntime };
866
+ export { type CrnCapacitySpec, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike$1 as JsonFetchLike, type JsonFetchLikeResponse, type OwnerRelayBootstrapReconcileResult, type PaymentQuote, type RelayBootstrapPublicationResult, type RelayBootstrapVisibilityResult, type RelayMetadataShape, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY, appendDeploymentTokenToSshPublicKey, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureOrbitdbRelaySetup, configureUcGoPeer, createDeploymentIntent, createDeploymentToken, createInstanceContent, createPortForwardAggregateContent, createRelayBootstrapRegistrationId, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, createVmBootstrapConfigAggregateContent, deleteVmBootstrapConfig, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractInsufficientBalanceMessage, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchRelayMetadataForRuntime, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmBootstrapConfigAggregate, fetchVmRuntime, filterDeployableCrns, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, notifyCrnAllocationWithRetry, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, publishRelayBootstrapRegistration, publishVmBootstrapConfig, quoteRequiredBudgetUnits, rankCandidateCrns, reconcileOwnerRelayBootstrapRegistrations, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForRelayBootstrapRegistration, waitForSetupEndpoint, waitForVmRuntime };
package/index.js CHANGED
@@ -739,22 +739,25 @@ async function postBroadcastPayload(body, options) {
739
739
  };
740
740
  }
741
741
  async function broadcastAlephMessage(message, options) {
742
- const requestBody = { sync: options.sync ?? false, message };
743
- const maxAttempts = 3;
744
- for (let index = 0; index < maxAttempts; index += 1) {
745
- const result = await postBroadcastPayload(requestBody, {
742
+ const attempts = [
743
+ { sync: options.sync ?? false, message },
744
+ { ...message, sync: options.sync ?? false },
745
+ { ...message }
746
+ ];
747
+ for (let index = 0; index < attempts.length; index += 1) {
748
+ const result = await postBroadcastPayload(attempts[index], {
746
749
  apiHost: options.apiHost,
747
750
  fetch: options.fetch
748
751
  });
749
752
  if (result.httpStatus === 202 || normalizeBroadcastStatus(result.httpStatus, result.response?.message_status) !== "unknown" || result.httpStatus >= 200 && result.httpStatus < 300) {
750
753
  return result;
751
754
  }
752
- const canRetry = index < maxAttempts - 1 && isRetryableBroadcastFailure({ status: result.httpStatus }, result.response);
755
+ const canRetry = index < attempts.length - 1 && (isInvalidMessageFormatResponse({ status: result.httpStatus }, result.response) || isRetryableBroadcastFailure({ status: result.httpStatus }, result.response));
753
756
  if (!canRetry) {
754
757
  throw new Error(`Broadcast failed: ${result.httpStatus} ${JSON.stringify(result.response ?? {})}`);
755
758
  }
756
759
  }
757
- throw new Error("Broadcast failed: retry budget exhausted");
760
+ throw new Error("Broadcast failed: no compatible request format was accepted");
758
761
  }
759
762
 
760
763
  // src/forget.ts
@@ -2509,7 +2512,7 @@ async function waitForRelayBootstrapRegistration(args) {
2509
2512
  return false;
2510
2513
  });
2511
2514
  if (match?.content) {
2512
- return {
2515
+ const visibleRegistration = {
2513
2516
  itemHash: match.itemHash ?? null,
2514
2517
  hash: match.hash ?? null,
2515
2518
  sender: typeof match.address === "string" ? match.address : null,
@@ -2518,7 +2521,10 @@ async function waitForRelayBootstrapRegistration(args) {
2518
2521
  multiaddrs: Array.isArray(match.content.multiaddrs) ? match.content.multiaddrs : [],
2519
2522
  browserMultiaddrs: Array.isArray(match.content.browserMultiaddrs) ? match.content.browserMultiaddrs : []
2520
2523
  };
2524
+ args.onAttempt?.(visibleRegistration, attempt + 1, attempts);
2525
+ return visibleRegistration;
2521
2526
  }
2527
+ args.onAttempt?.(null, attempt + 1, attempts);
2522
2528
  if (attempt < attempts - 1) {
2523
2529
  await sleep(delayMs);
2524
2530
  }
@@ -2631,16 +2637,6 @@ async function publishRelayBootstrapRegistration(args) {
2631
2637
 
2632
2638
  // src/bootstrap-config.ts
2633
2639
  var VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
2634
- var VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
2635
- var VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
2636
- function parseJsonObject(value) {
2637
- try {
2638
- const parsed = JSON.parse(value);
2639
- return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
2640
- } catch {
2641
- return null;
2642
- }
2643
- }
2644
2640
  async function fetchVmBootstrapConfigAggregate(address, options) {
2645
2641
  const requestUrl = new URL(`/api/v0/aggregates/${address}.json`, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
2646
2642
  requestUrl.searchParams.set("keys", VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY);
@@ -2760,89 +2756,6 @@ async function deleteVmBootstrapConfig(args) {
2760
2756
  aggregate: content
2761
2757
  };
2762
2758
  }
2763
- function normalizeVmBootstrapConfigSignalRecord(value) {
2764
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
2765
- const candidate = value;
2766
- const deploymentToken = typeof candidate.deploymentToken === "string" ? candidate.deploymentToken.trim() : "";
2767
- const status = typeof candidate.status === "string" ? candidate.status.trim() : "";
2768
- const profile = typeof candidate.profile === "string" ? candidate.profile.trim() : "";
2769
- const ownerAddress = typeof candidate.ownerAddress === "string" ? candidate.ownerAddress.trim() : "";
2770
- const instanceItemHash = typeof candidate.instanceItemHash === "string" ? candidate.instanceItemHash.trim() : "";
2771
- const updatedAt = typeof candidate.updatedAt === "string" ? candidate.updatedAt.trim() : "";
2772
- if (!deploymentToken || !status || !profile || !ownerAddress || !instanceItemHash || !updatedAt) {
2773
- return null;
2774
- }
2775
- return {
2776
- deploymentToken,
2777
- status,
2778
- profile,
2779
- ownerAddress,
2780
- instanceItemHash,
2781
- updatedAt,
2782
- publisherAddress: typeof candidate.publisherAddress === "string" && candidate.publisherAddress.trim() ? candidate.publisherAddress.trim() : null,
2783
- authorization: candidate.authorization,
2784
- peerId: typeof candidate.peerId === "string" && candidate.peerId.trim() ? candidate.peerId.trim() : null,
2785
- probeMultiaddrs: Array.isArray(candidate.probeMultiaddrs) ? candidate.probeMultiaddrs.filter(
2786
- (entry) => typeof entry === "string" && entry.trim().length > 0
2787
- ) : [],
2788
- browserBootstrapMultiaddrs: Array.isArray(candidate.browserBootstrapMultiaddrs) ? candidate.browserBootstrapMultiaddrs.filter(
2789
- (entry) => typeof entry === "string" && entry.trim().length > 0
2790
- ) : []
2791
- };
2792
- }
2793
- async function fetchVmBootstrapConfigSignals(args) {
2794
- const requestUrl = new URL("/api/v0/posts.json", args.apiHost ?? DEFAULT_ALEPH_API_HOST);
2795
- requestUrl.searchParams.set("refs", args.ref ?? VM_BOOTSTRAP_CONFIG_SIGNAL_REF);
2796
- requestUrl.searchParams.set("types", args.postType ?? VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE);
2797
- requestUrl.searchParams.set("pagination", String(Math.max(1, Number(args.pagination ?? 100))));
2798
- requestUrl.searchParams.set("page", String(Math.max(1, Number(args.page ?? 1))));
2799
- requestUrl.searchParams.set("sortOrder", "-1");
2800
- const response = await args.fetch(requestUrl.toString(), { cache: "no-cache" });
2801
- if (!response.ok) {
2802
- throw new Error(`VM bootstrap config signal request failed: ${response.status}`);
2803
- }
2804
- const payload = await response.json();
2805
- const expectedDeploymentToken = args.deploymentToken?.trim() ?? "";
2806
- const expectedOwnerAddress = args.ownerAddress?.trim().toLowerCase() ?? "";
2807
- const expectedInstanceItemHash = args.instanceItemHash?.trim() ?? "";
2808
- return (payload.posts ?? []).map((entry) => {
2809
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) return null;
2810
- const parsed = "content" in entry && entry.content && typeof entry.content === "object" && !Array.isArray(entry.content) ? entry.content : "item_content" in entry && typeof entry.item_content === "string" ? parseJsonObject(entry.item_content) : null;
2811
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
2812
- const content = "deploymentToken" in parsed ? parsed : "content" in parsed && parsed.content && typeof parsed.content === "object" && !Array.isArray(parsed.content) ? parsed.content : null;
2813
- if (!content || typeof content !== "object" || Array.isArray(content)) return null;
2814
- return normalizeVmBootstrapConfigSignalRecord(content);
2815
- }).filter((entry) => {
2816
- if (!entry) return false;
2817
- if (expectedDeploymentToken && entry.deploymentToken !== expectedDeploymentToken) return false;
2818
- if (expectedOwnerAddress && entry.ownerAddress.toLowerCase() !== expectedOwnerAddress) return false;
2819
- if (expectedInstanceItemHash && entry.instanceItemHash !== expectedInstanceItemHash) return false;
2820
- return true;
2821
- });
2822
- }
2823
- async function waitForVmBootstrapConfigSignal(args) {
2824
- const attempts = Math.max(1, Number(args.attempts ?? 24));
2825
- const delayMs = Math.max(0, Number(args.delayMs ?? 2500));
2826
- const sleep2 = args.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
2827
- const expectedStatus = args.expectedStatus ?? "applied";
2828
- for (let attempt = 0; attempt < attempts; attempt += 1) {
2829
- const signals = await fetchVmBootstrapConfigSignals({
2830
- deploymentToken: args.deploymentToken,
2831
- ownerAddress: args.ownerAddress,
2832
- instanceItemHash: args.instanceItemHash,
2833
- fetch: args.fetch,
2834
- apiHost: args.apiHost,
2835
- ref: args.ref,
2836
- postType: args.postType
2837
- }).catch(() => []);
2838
- const match = signals.find((entry) => entry.status === expectedStatus) ?? null;
2839
- if (match) return match;
2840
- if (attempt < attempts - 1) {
2841
- await sleep2(delayMs);
2842
- }
2843
- }
2844
- return null;
2845
- }
2846
2759
 
2847
2760
  // src/bootstrap-reconcile.ts
2848
2761
  function createRelayBootstrapRegistrationId(profile, instanceName, itemHash) {
@@ -3049,8 +2962,6 @@ export {
3049
2962
  SSH_PUBLIC_KEY_PATTERN,
3050
2963
  SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
3051
2964
  VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
3052
- VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE,
3053
- VM_BOOTSTRAP_CONFIG_SIGNAL_REF,
3054
2965
  appendDeploymentTokenToSshPublicKey,
3055
2966
  broadcastAlephMessage,
3056
2967
  buildPaymentQuote,
@@ -3086,7 +2997,6 @@ export {
3086
2997
  fetchSchedulerAllocation,
3087
2998
  fetchUcGoPeerMetadata,
3088
2999
  fetchVmBootstrapConfigAggregate,
3089
- fetchVmBootstrapConfigSignals,
3090
3000
  fetchVmRuntime,
3091
3001
  filterDeployableCrns,
3092
3002
  findCrnByHash,
@@ -3132,6 +3042,5 @@ export {
3132
3042
  waitForDeploymentResult,
3133
3043
  waitForRelayBootstrapRegistration,
3134
3044
  waitForSetupEndpoint,
3135
- waitForVmBootstrapConfigSignal,
3136
3045
  waitForVmRuntime
3137
3046
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.3.32",
3
+ "version": "0.4.1",
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.32",
20
- "@le-space/shared-types": "0.3.32"
19
+ "@le-space/aleph-bootstrap": "0.4.1",
20
+ "@le-space/shared-types": "0.4.1"
21
21
  }
22
22
  }