@le-space/core 0.4.2 → 0.4.4

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 +13 -1
  2. package/index.js +108 -9
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -762,6 +762,7 @@ declare function publishRelayBootstrapRegistration(args: {
762
762
  declare const VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
763
763
  declare const VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
764
764
  declare const VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
765
+ declare const VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS: number;
765
766
  declare function fetchVmBootstrapConfigAggregate(address: string, options: {
766
767
  apiHost?: string;
767
768
  fetch: JsonFetchLike$1;
@@ -771,7 +772,18 @@ declare function createVmBootstrapConfigAggregateContent(args: {
771
772
  record: VmBootstrapConfigRecord;
772
773
  existingAggregate?: VmBootstrapConfigAggregate | null;
773
774
  now?: number;
775
+ maxRecordAgeMs?: number;
774
776
  }): AlephAggregateContent<VmBootstrapConfigAggregate>;
777
+ declare function listStaleVmBootstrapConfigAggregateMessageHashes(args: {
778
+ address: string;
779
+ currentAggregateItemHash?: string | null;
780
+ olderThanMs?: number;
781
+ fetch: JsonFetchLike$1;
782
+ apiHost?: string;
783
+ pagination?: number;
784
+ maxPages?: number;
785
+ nowMs?: number;
786
+ }): Promise<string[]>;
775
787
  declare function publishVmBootstrapConfig(args: {
776
788
  sender: string;
777
789
  record: VmBootstrapConfigRecord;
@@ -892,4 +904,4 @@ declare function reconcileOwnerRelayBootstrapRegistrations(args: {
892
904
  } | null;
893
905
  }): Promise<OwnerRelayBootstrapReconcileResult>;
894
906
 
895
- 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 };
907
+ 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_HISTORY_RETENTION_MS, 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, listStaleVmBootstrapConfigAggregateMessageHashes, 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 };
package/index.js CHANGED
@@ -1608,14 +1608,15 @@ function describeRuntimeAvailability(runtime) {
1608
1608
  const mappedPorts = runtime.mappedPorts ?? {};
1609
1609
  const hostIpv4 = runtime.hostIpv4 ?? null;
1610
1610
  const ipv6 = runtime.ipv6 ?? null;
1611
+ const executionGuestIpv6 = execution?.networking?.ipv6_ip ?? null;
1611
1612
  const proxyUrl = runtime.proxyUrl ?? null;
1612
1613
  const schedulerSource = runtime.allocation?.source ?? null;
1613
1614
  const webAccessActive = runtime.webAccess?.active ?? null;
1614
1615
  const mappedPortCount = Object.keys(mappedPorts).length;
1615
- if (hostIpv4 && mappedPortCount > 0 && runtime.requirePublicGuestIpv6ForProxy === true && proxyUrl && !isLikelyGlobalIpv6(ipv6)) {
1616
+ if (hostIpv4 && mappedPortCount > 0 && runtime.requirePublicGuestIpv6ForProxy === true && proxyUrl && executionGuestIpv6 && !isLikelyGlobalIpv6(executionGuestIpv6)) {
1616
1617
  return {
1617
1618
  state: "execution-invalid-public-ipv6",
1618
- reason: `The CRN exposed runtime networking, but the guest IPv6${ipv6 ? ` (${ipv6})` : ""} is not globally routable. Proxy-backed HTTPS activation cannot succeed until the CRN reports a public guest IPv6.`,
1619
+ reason: `The CRN exposed runtime networking, but the guest IPv6 (${executionGuestIpv6}) is not globally routable. Proxy-backed HTTPS activation cannot succeed until the CRN reports a public guest IPv6.`,
1619
1620
  schedulerSource,
1620
1621
  executionSeen: Boolean(execution),
1621
1622
  webAccessActive,
@@ -2669,6 +2670,7 @@ async function publishRelayBootstrapRegistration(args) {
2669
2670
  var VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
2670
2671
  var VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
2671
2672
  var VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
2673
+ var VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS = 6 * 60 * 60 * 1e3;
2672
2674
  function parseJsonObject(value) {
2673
2675
  try {
2674
2676
  const parsed = JSON.parse(value);
@@ -2677,6 +2679,44 @@ function parseJsonObject(value) {
2677
2679
  return null;
2678
2680
  }
2679
2681
  }
2682
+ function parseTimestampMs(value) {
2683
+ if (typeof value === "number" && Number.isFinite(value)) {
2684
+ return value > 1e12 ? value : value * 1e3;
2685
+ }
2686
+ if (typeof value === "string" && value.trim()) {
2687
+ const numeric = Number(value);
2688
+ if (Number.isFinite(numeric)) {
2689
+ return numeric > 1e12 ? numeric : numeric * 1e3;
2690
+ }
2691
+ const parsed = Date.parse(value);
2692
+ return Number.isFinite(parsed) ? parsed : null;
2693
+ }
2694
+ return null;
2695
+ }
2696
+ function normalizeVmBootstrapConfigRecord(deploymentTokenKey, value, options = {}) {
2697
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
2698
+ const candidate = value;
2699
+ const deploymentToken = typeof candidate.deploymentToken === "string" ? candidate.deploymentToken.trim() : "";
2700
+ const profile = typeof candidate.profile === "string" ? candidate.profile.trim() : "";
2701
+ const ownerAddress = typeof candidate.ownerAddress === "string" ? candidate.ownerAddress.trim() : "";
2702
+ const instanceItemHash = typeof candidate.instanceItemHash === "string" ? candidate.instanceItemHash.trim() : "";
2703
+ const createdAt = typeof candidate.createdAt === "string" ? candidate.createdAt.trim() : "";
2704
+ const expiresAt = typeof candidate.expiresAt === "string" ? candidate.expiresAt.trim() : "";
2705
+ if (!deploymentTokenKey.trim() || !deploymentToken || deploymentToken !== deploymentTokenKey.trim() || !profile || !ownerAddress || !instanceItemHash || !createdAt || !expiresAt) {
2706
+ return null;
2707
+ }
2708
+ const nowMs = Math.max(0, Number(options.nowMs ?? Date.now()));
2709
+ const maxRecordAgeMs = Math.max(
2710
+ 6e4,
2711
+ Number(options.maxRecordAgeMs ?? VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS)
2712
+ );
2713
+ const createdAtMs = parseTimestampMs(createdAt);
2714
+ const expiresAtMs = parseTimestampMs(expiresAt);
2715
+ if (createdAtMs == null || expiresAtMs == null) return null;
2716
+ if (expiresAtMs <= nowMs) return null;
2717
+ if (createdAtMs < nowMs - maxRecordAgeMs) return null;
2718
+ return candidate;
2719
+ }
2680
2720
  async function fetchVmBootstrapConfigAggregate(address, options) {
2681
2721
  const requestUrl = new URL(`/api/v0/aggregates/${address}.json`, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
2682
2722
  requestUrl.searchParams.set("keys", VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY);
@@ -2690,16 +2730,21 @@ async function fetchVmBootstrapConfigAggregate(address, options) {
2690
2730
  if (!aggregate || typeof aggregate !== "object" || Array.isArray(aggregate)) return {};
2691
2731
  return aggregate;
2692
2732
  }
2693
- function normalizeVmBootstrapConfigAggregate(aggregate) {
2733
+ function normalizeVmBootstrapConfigAggregate(aggregate, options = {}) {
2694
2734
  if (!aggregate || typeof aggregate !== "object") return {};
2695
2735
  return Object.fromEntries(
2696
- Object.entries(aggregate).filter(
2697
- (entry) => Boolean(entry[1] && typeof entry[1] === "object" && !Array.isArray(entry[1]))
2698
- )
2736
+ Object.entries(aggregate).map(([deploymentToken, record]) => [
2737
+ deploymentToken,
2738
+ normalizeVmBootstrapConfigRecord(deploymentToken, record, options)
2739
+ ]).filter((entry) => entry[1] != null)
2699
2740
  );
2700
2741
  }
2701
2742
  function createVmBootstrapConfigAggregateContent(args) {
2702
- const content = normalizeVmBootstrapConfigAggregate(args.existingAggregate);
2743
+ const nowMs = Math.max(0, Number(args.now ?? Date.now() / 1e3) * 1e3);
2744
+ const content = normalizeVmBootstrapConfigAggregate(args.existingAggregate, {
2745
+ nowMs,
2746
+ maxRecordAgeMs: args.maxRecordAgeMs
2747
+ });
2703
2748
  content[args.record.deploymentToken] = args.record;
2704
2749
  return {
2705
2750
  address: args.sender,
@@ -2744,6 +2789,55 @@ async function publishVmBootstrapConfigAggregate(args) {
2744
2789
  aggregateStatus
2745
2790
  };
2746
2791
  }
2792
+ function normalizeAggregateMessageHashRecord(value) {
2793
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
2794
+ const candidate = value;
2795
+ const itemHash = typeof candidate.item_hash === "string" ? candidate.item_hash.trim() : "";
2796
+ if (!itemHash) return null;
2797
+ const content = candidate.content && typeof candidate.content === "object" && !Array.isArray(candidate.content) ? candidate.content : typeof candidate.item_content === "string" ? parseJsonObject(candidate.item_content) : null;
2798
+ if (!content || content.key !== VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY) return null;
2799
+ const timeMs = parseTimestampMs(candidate.time);
2800
+ if (timeMs == null) return null;
2801
+ return { itemHash, timeMs };
2802
+ }
2803
+ async function listStaleVmBootstrapConfigAggregateMessageHashes(args) {
2804
+ const address = args.address.trim();
2805
+ if (!address) return [];
2806
+ const currentAggregateItemHash = args.currentAggregateItemHash?.trim() ?? "";
2807
+ const olderThanMs = Math.max(
2808
+ 6e4,
2809
+ Number(args.olderThanMs ?? VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS)
2810
+ );
2811
+ const cutoffMs = Math.max(0, Number(args.nowMs ?? Date.now()) - olderThanMs);
2812
+ const pagination = Math.max(1, Number(args.pagination ?? 100));
2813
+ const maxPages = Math.max(1, Number(args.maxPages ?? 10));
2814
+ const hashes = /* @__PURE__ */ new Set();
2815
+ for (let page = 1; page <= maxPages; page += 1) {
2816
+ const requestUrl = new URL("/api/v0/messages.json", args.apiHost ?? DEFAULT_ALEPH_API_HOST);
2817
+ requestUrl.searchParams.set("msgType", "AGGREGATE");
2818
+ requestUrl.searchParams.set("addresses", address);
2819
+ requestUrl.searchParams.set("message_statuses", "processed,pending,rejected,removing");
2820
+ requestUrl.searchParams.set("pagination", String(pagination));
2821
+ requestUrl.searchParams.set("page", String(page));
2822
+ requestUrl.searchParams.set("sortOrder", "-1");
2823
+ const response = await args.fetch(requestUrl.toString(), { cache: "no-cache" });
2824
+ if (!response.ok) {
2825
+ throw new Error(`VM bootstrap config aggregate history request failed: ${response.status}`);
2826
+ }
2827
+ const payload = await response.json();
2828
+ const messages = Array.isArray(payload.messages) ? payload.messages : [];
2829
+ if (messages.length === 0) break;
2830
+ for (const message of messages) {
2831
+ const normalized = normalizeAggregateMessageHashRecord(message);
2832
+ if (!normalized) continue;
2833
+ if (normalized.itemHash === currentAggregateItemHash) continue;
2834
+ if (normalized.timeMs > cutoffMs) continue;
2835
+ hashes.add(normalized.itemHash);
2836
+ }
2837
+ if (messages.length < pagination) break;
2838
+ }
2839
+ return [...hashes];
2840
+ }
2747
2841
  async function publishVmBootstrapConfig(args) {
2748
2842
  const aggregate = await fetchVmBootstrapConfigAggregate(args.sender, {
2749
2843
  apiHost: args.apiHost,
@@ -2752,7 +2846,8 @@ async function publishVmBootstrapConfig(args) {
2752
2846
  const content = createVmBootstrapConfigAggregateContent({
2753
2847
  sender: args.sender,
2754
2848
  record: args.record,
2755
- existingAggregate: aggregate
2849
+ existingAggregate: aggregate,
2850
+ maxRecordAgeMs: VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS
2756
2851
  });
2757
2852
  const result = await publishVmBootstrapConfigAggregate({
2758
2853
  sender: args.sender,
@@ -2774,7 +2869,9 @@ async function deleteVmBootstrapConfig(args) {
2774
2869
  apiHost: args.apiHost,
2775
2870
  fetch: args.fetch
2776
2871
  });
2777
- const content = normalizeVmBootstrapConfigAggregate(aggregate);
2872
+ const content = normalizeVmBootstrapConfigAggregate(aggregate, {
2873
+ maxRecordAgeMs: VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS
2874
+ });
2778
2875
  delete content[args.deploymentToken];
2779
2876
  const publishResult = await publishVmBootstrapConfigAggregate({
2780
2877
  sender: args.sender,
@@ -3085,6 +3182,7 @@ export {
3085
3182
  SSH_PUBLIC_KEY_PATTERN,
3086
3183
  SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
3087
3184
  VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
3185
+ VM_BOOTSTRAP_CONFIG_HISTORY_RETENTION_MS,
3088
3186
  VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE,
3089
3187
  VM_BOOTSTRAP_CONFIG_SIGNAL_REF,
3090
3188
  appendDeploymentTokenToSshPublicKey,
@@ -3133,6 +3231,7 @@ export {
3133
3231
  isRetryableBroadcastFailure,
3134
3232
  isValidSshPublicKey,
3135
3233
  listGeocodedCrns,
3234
+ listStaleVmBootstrapConfigAggregateMessageHashes,
3136
3235
  mergePortFlagMaps,
3137
3236
  mergeRequiredPortForwards,
3138
3237
  messageTypeFromEnvelope,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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.4.2",
20
- "@le-space/shared-types": "0.4.2"
19
+ "@le-space/aleph-bootstrap": "0.4.4",
20
+ "@le-space/shared-types": "0.4.4"
21
21
  }
22
22
  }