@le-space/core 0.4.1 → 0.4.2
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.
- package/index.d.ts +31 -2
- package/index.js +138 -11
- 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 } 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';
|
|
3
3
|
|
|
4
4
|
declare const DEFAULT_ALEPH_CHANNEL = "TEST";
|
|
5
5
|
|
|
@@ -513,6 +513,7 @@ declare function describeRuntimeAvailability(runtime: {
|
|
|
513
513
|
ipv6?: string | null;
|
|
514
514
|
proxyUrl?: string | null;
|
|
515
515
|
mappedPorts?: Record<string, unknown>;
|
|
516
|
+
requirePublicGuestIpv6ForProxy?: boolean;
|
|
516
517
|
}): RuntimeDiagnostics;
|
|
517
518
|
declare function fetchVmRuntime(args: {
|
|
518
519
|
itemHash: string;
|
|
@@ -522,6 +523,7 @@ declare function fetchVmRuntime(args: {
|
|
|
522
523
|
crnListUrl?: string;
|
|
523
524
|
schedulerAllocationUrl?: string;
|
|
524
525
|
twoN6HashUrl?: string;
|
|
526
|
+
requirePublicGuestIpv6ForProxy?: boolean;
|
|
525
527
|
}): Promise<Omit<InstanceRuntimeDetails, 'messageStatus'>>;
|
|
526
528
|
declare function waitForVmRuntime(args: {
|
|
527
529
|
itemHash: string;
|
|
@@ -531,6 +533,7 @@ declare function waitForVmRuntime(args: {
|
|
|
531
533
|
crnListUrl?: string;
|
|
532
534
|
schedulerAllocationUrl?: string;
|
|
533
535
|
twoN6HashUrl?: string;
|
|
536
|
+
requirePublicGuestIpv6ForProxy?: boolean;
|
|
534
537
|
attempts?: number;
|
|
535
538
|
delayMs?: number;
|
|
536
539
|
sleep?: (ms: number) => Promise<void>;
|
|
@@ -757,6 +760,8 @@ declare function publishRelayBootstrapRegistration(args: {
|
|
|
757
760
|
}): Promise<RelayBootstrapPublicationResult>;
|
|
758
761
|
|
|
759
762
|
declare const VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
|
|
763
|
+
declare const VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
|
|
764
|
+
declare const VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
|
|
760
765
|
declare function fetchVmBootstrapConfigAggregate(address: string, options: {
|
|
761
766
|
apiHost?: string;
|
|
762
767
|
fetch: JsonFetchLike$1;
|
|
@@ -795,6 +800,30 @@ declare function deleteVmBootstrapConfig(args: {
|
|
|
795
800
|
aggregateStatus: MessageStatus;
|
|
796
801
|
aggregate: VmBootstrapConfigAggregate;
|
|
797
802
|
}>;
|
|
803
|
+
declare function fetchVmBootstrapConfigSignals(args: {
|
|
804
|
+
deploymentToken?: string;
|
|
805
|
+
ownerAddress?: string;
|
|
806
|
+
instanceItemHash?: string;
|
|
807
|
+
fetch: JsonFetchLike$1;
|
|
808
|
+
apiHost?: string;
|
|
809
|
+
ref?: string;
|
|
810
|
+
postType?: string;
|
|
811
|
+
page?: number;
|
|
812
|
+
pagination?: number;
|
|
813
|
+
}): Promise<VmBootstrapConfigSignalRecord[]>;
|
|
814
|
+
declare function waitForVmBootstrapConfigSignal(args: {
|
|
815
|
+
deploymentToken: string;
|
|
816
|
+
ownerAddress: string;
|
|
817
|
+
instanceItemHash: string;
|
|
818
|
+
expectedStatus?: VmBootstrapConfigSignalType;
|
|
819
|
+
fetch: JsonFetchLike$1;
|
|
820
|
+
apiHost?: string;
|
|
821
|
+
ref?: string;
|
|
822
|
+
postType?: string;
|
|
823
|
+
attempts?: number;
|
|
824
|
+
delayMs?: number;
|
|
825
|
+
sleep?: (ms: number) => Promise<void>;
|
|
826
|
+
}): Promise<VmBootstrapConfigSignalRecord | null>;
|
|
798
827
|
|
|
799
828
|
type JsonFetchLike = FetchLike;
|
|
800
829
|
type RelayMetadataShape = {
|
|
@@ -863,4 +892,4 @@ declare function reconcileOwnerRelayBootstrapRegistrations(args: {
|
|
|
863
892
|
} | null;
|
|
864
893
|
}): Promise<OwnerRelayBootstrapReconcileResult>;
|
|
865
894
|
|
|
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 };
|
|
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 };
|
package/index.js
CHANGED
|
@@ -739,25 +739,22 @@ async function postBroadcastPayload(body, options) {
|
|
|
739
739
|
};
|
|
740
740
|
}
|
|
741
741
|
async function broadcastAlephMessage(message, options) {
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
];
|
|
747
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
748
|
-
const result = await postBroadcastPayload(attempts[index], {
|
|
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, {
|
|
749
746
|
apiHost: options.apiHost,
|
|
750
747
|
fetch: options.fetch
|
|
751
748
|
});
|
|
752
749
|
if (result.httpStatus === 202 || normalizeBroadcastStatus(result.httpStatus, result.response?.message_status) !== "unknown" || result.httpStatus >= 200 && result.httpStatus < 300) {
|
|
753
750
|
return result;
|
|
754
751
|
}
|
|
755
|
-
const canRetry = index <
|
|
752
|
+
const canRetry = index < maxAttempts - 1 && isRetryableBroadcastFailure({ status: result.httpStatus }, result.response);
|
|
756
753
|
if (!canRetry) {
|
|
757
754
|
throw new Error(`Broadcast failed: ${result.httpStatus} ${JSON.stringify(result.response ?? {})}`);
|
|
758
755
|
}
|
|
759
756
|
}
|
|
760
|
-
throw new Error("Broadcast failed:
|
|
757
|
+
throw new Error("Broadcast failed: retry budget exhausted");
|
|
761
758
|
}
|
|
762
759
|
|
|
763
760
|
// src/forget.ts
|
|
@@ -1510,6 +1507,26 @@ function asString4(value) {
|
|
|
1510
1507
|
function asNumber2(value) {
|
|
1511
1508
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1512
1509
|
}
|
|
1510
|
+
function normalizeIpv6(value) {
|
|
1511
|
+
if (typeof value !== "string") return null;
|
|
1512
|
+
const normalized = value.trim().toLowerCase();
|
|
1513
|
+
if (!normalized) return null;
|
|
1514
|
+
const zoneIndex = normalized.indexOf("%");
|
|
1515
|
+
return zoneIndex >= 0 ? normalized.slice(0, zoneIndex) : normalized;
|
|
1516
|
+
}
|
|
1517
|
+
function isLikelyGlobalIpv6(value) {
|
|
1518
|
+
const normalized = normalizeIpv6(value);
|
|
1519
|
+
if (!normalized || normalized === "::" || normalized === "::1") return false;
|
|
1520
|
+
const firstHextetText = normalized.split(":", 1)[0];
|
|
1521
|
+
if (!firstHextetText) return false;
|
|
1522
|
+
const firstHextet = Number.parseInt(firstHextetText, 16);
|
|
1523
|
+
if (!Number.isFinite(firstHextet)) return false;
|
|
1524
|
+
if ((firstHextet & 65024) === 64512) return false;
|
|
1525
|
+
if ((firstHextet & 65472) === 65152) return false;
|
|
1526
|
+
if ((firstHextet & 65280) === 65280) return false;
|
|
1527
|
+
if ((firstHextet & 65472) === 65216) return false;
|
|
1528
|
+
return true;
|
|
1529
|
+
}
|
|
1513
1530
|
function findCrnByHash(crns, crnHash) {
|
|
1514
1531
|
return crns.find((crn) => crn.hash === crnHash) ?? null;
|
|
1515
1532
|
}
|
|
@@ -1590,10 +1607,22 @@ function describeRuntimeAvailability(runtime) {
|
|
|
1590
1607
|
const execution = runtime.execution ?? null;
|
|
1591
1608
|
const mappedPorts = runtime.mappedPorts ?? {};
|
|
1592
1609
|
const hostIpv4 = runtime.hostIpv4 ?? null;
|
|
1610
|
+
const ipv6 = runtime.ipv6 ?? null;
|
|
1593
1611
|
const proxyUrl = runtime.proxyUrl ?? null;
|
|
1594
1612
|
const schedulerSource = runtime.allocation?.source ?? null;
|
|
1595
1613
|
const webAccessActive = runtime.webAccess?.active ?? null;
|
|
1596
1614
|
const mappedPortCount = Object.keys(mappedPorts).length;
|
|
1615
|
+
if (hostIpv4 && mappedPortCount > 0 && runtime.requirePublicGuestIpv6ForProxy === true && proxyUrl && !isLikelyGlobalIpv6(ipv6)) {
|
|
1616
|
+
return {
|
|
1617
|
+
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
|
+
schedulerSource,
|
|
1620
|
+
executionSeen: Boolean(execution),
|
|
1621
|
+
webAccessActive,
|
|
1622
|
+
mappedPortCount,
|
|
1623
|
+
proxyUrl
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1597
1626
|
if (hostIpv4 && mappedPortCount > 0) {
|
|
1598
1627
|
return {
|
|
1599
1628
|
state: "ready",
|
|
@@ -1710,7 +1739,8 @@ async function fetchVmRuntime(args) {
|
|
|
1710
1739
|
hostIpv4,
|
|
1711
1740
|
ipv6,
|
|
1712
1741
|
proxyUrl,
|
|
1713
|
-
mappedPorts
|
|
1742
|
+
mappedPorts,
|
|
1743
|
+
requirePublicGuestIpv6ForProxy: args.requirePublicGuestIpv6ForProxy
|
|
1714
1744
|
});
|
|
1715
1745
|
return {
|
|
1716
1746
|
allocation,
|
|
@@ -1734,7 +1764,7 @@ async function waitForVmRuntime(args) {
|
|
|
1734
1764
|
let lastRuntime = await fetchVmRuntime(args);
|
|
1735
1765
|
args.onAttempt?.(lastRuntime, 1, attempts);
|
|
1736
1766
|
for (let attempt = 0; attempt < attempts - 1; attempt += 1) {
|
|
1737
|
-
if (lastRuntime.
|
|
1767
|
+
if (lastRuntime.diagnostics?.state === "ready" || lastRuntime.diagnostics?.state === "execution-invalid-public-ipv6") {
|
|
1738
1768
|
return lastRuntime;
|
|
1739
1769
|
}
|
|
1740
1770
|
await sleep2(delayMs);
|
|
@@ -2637,6 +2667,16 @@ async function publishRelayBootstrapRegistration(args) {
|
|
|
2637
2667
|
|
|
2638
2668
|
// src/bootstrap-config.ts
|
|
2639
2669
|
var VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
|
|
2670
|
+
var VM_BOOTSTRAP_CONFIG_SIGNAL_REF = "vm-bootstrap-config";
|
|
2671
|
+
var VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE = "vm-bootstrap-config-status";
|
|
2672
|
+
function parseJsonObject(value) {
|
|
2673
|
+
try {
|
|
2674
|
+
const parsed = JSON.parse(value);
|
|
2675
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
2676
|
+
} catch {
|
|
2677
|
+
return null;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2640
2680
|
async function fetchVmBootstrapConfigAggregate(address, options) {
|
|
2641
2681
|
const requestUrl = new URL(`/api/v0/aggregates/${address}.json`, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
|
|
2642
2682
|
requestUrl.searchParams.set("keys", VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY);
|
|
@@ -2756,6 +2796,89 @@ async function deleteVmBootstrapConfig(args) {
|
|
|
2756
2796
|
aggregate: content
|
|
2757
2797
|
};
|
|
2758
2798
|
}
|
|
2799
|
+
function normalizeVmBootstrapConfigSignalRecord(value) {
|
|
2800
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
2801
|
+
const candidate = value;
|
|
2802
|
+
const deploymentToken = typeof candidate.deploymentToken === "string" ? candidate.deploymentToken.trim() : "";
|
|
2803
|
+
const status = typeof candidate.status === "string" ? candidate.status.trim() : "";
|
|
2804
|
+
const profile = typeof candidate.profile === "string" ? candidate.profile.trim() : "";
|
|
2805
|
+
const ownerAddress = typeof candidate.ownerAddress === "string" ? candidate.ownerAddress.trim() : "";
|
|
2806
|
+
const instanceItemHash = typeof candidate.instanceItemHash === "string" ? candidate.instanceItemHash.trim() : "";
|
|
2807
|
+
const updatedAt = typeof candidate.updatedAt === "string" ? candidate.updatedAt.trim() : "";
|
|
2808
|
+
if (!deploymentToken || !status || !profile || !ownerAddress || !instanceItemHash || !updatedAt) {
|
|
2809
|
+
return null;
|
|
2810
|
+
}
|
|
2811
|
+
return {
|
|
2812
|
+
deploymentToken,
|
|
2813
|
+
status,
|
|
2814
|
+
profile,
|
|
2815
|
+
ownerAddress,
|
|
2816
|
+
instanceItemHash,
|
|
2817
|
+
updatedAt,
|
|
2818
|
+
publisherAddress: typeof candidate.publisherAddress === "string" && candidate.publisherAddress.trim() ? candidate.publisherAddress.trim() : null,
|
|
2819
|
+
authorization: candidate.authorization,
|
|
2820
|
+
peerId: typeof candidate.peerId === "string" && candidate.peerId.trim() ? candidate.peerId.trim() : null,
|
|
2821
|
+
probeMultiaddrs: Array.isArray(candidate.probeMultiaddrs) ? candidate.probeMultiaddrs.filter(
|
|
2822
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
2823
|
+
) : [],
|
|
2824
|
+
browserBootstrapMultiaddrs: Array.isArray(candidate.browserBootstrapMultiaddrs) ? candidate.browserBootstrapMultiaddrs.filter(
|
|
2825
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
2826
|
+
) : []
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
async function fetchVmBootstrapConfigSignals(args) {
|
|
2830
|
+
const requestUrl = new URL("/api/v0/posts.json", args.apiHost ?? DEFAULT_ALEPH_API_HOST);
|
|
2831
|
+
requestUrl.searchParams.set("refs", args.ref ?? VM_BOOTSTRAP_CONFIG_SIGNAL_REF);
|
|
2832
|
+
requestUrl.searchParams.set("types", args.postType ?? VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE);
|
|
2833
|
+
requestUrl.searchParams.set("pagination", String(Math.max(1, Number(args.pagination ?? 100))));
|
|
2834
|
+
requestUrl.searchParams.set("page", String(Math.max(1, Number(args.page ?? 1))));
|
|
2835
|
+
requestUrl.searchParams.set("sortOrder", "-1");
|
|
2836
|
+
const response = await args.fetch(requestUrl.toString(), { cache: "no-cache" });
|
|
2837
|
+
if (!response.ok) {
|
|
2838
|
+
throw new Error(`VM bootstrap config signal request failed: ${response.status}`);
|
|
2839
|
+
}
|
|
2840
|
+
const payload = await response.json();
|
|
2841
|
+
const expectedDeploymentToken = args.deploymentToken?.trim() ?? "";
|
|
2842
|
+
const expectedOwnerAddress = args.ownerAddress?.trim().toLowerCase() ?? "";
|
|
2843
|
+
const expectedInstanceItemHash = args.instanceItemHash?.trim() ?? "";
|
|
2844
|
+
return (payload.posts ?? []).map((entry) => {
|
|
2845
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return null;
|
|
2846
|
+
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;
|
|
2847
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
2848
|
+
const content = "deploymentToken" in parsed ? parsed : "content" in parsed && parsed.content && typeof parsed.content === "object" && !Array.isArray(parsed.content) ? parsed.content : null;
|
|
2849
|
+
if (!content || typeof content !== "object" || Array.isArray(content)) return null;
|
|
2850
|
+
return normalizeVmBootstrapConfigSignalRecord(content);
|
|
2851
|
+
}).filter((entry) => {
|
|
2852
|
+
if (!entry) return false;
|
|
2853
|
+
if (expectedDeploymentToken && entry.deploymentToken !== expectedDeploymentToken) return false;
|
|
2854
|
+
if (expectedOwnerAddress && entry.ownerAddress.toLowerCase() !== expectedOwnerAddress) return false;
|
|
2855
|
+
if (expectedInstanceItemHash && entry.instanceItemHash !== expectedInstanceItemHash) return false;
|
|
2856
|
+
return true;
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
async function waitForVmBootstrapConfigSignal(args) {
|
|
2860
|
+
const attempts = Math.max(1, Number(args.attempts ?? 24));
|
|
2861
|
+
const delayMs = Math.max(0, Number(args.delayMs ?? 2500));
|
|
2862
|
+
const sleep2 = args.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
2863
|
+
const expectedStatus = args.expectedStatus ?? "applied";
|
|
2864
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
2865
|
+
const signals = await fetchVmBootstrapConfigSignals({
|
|
2866
|
+
deploymentToken: args.deploymentToken,
|
|
2867
|
+
ownerAddress: args.ownerAddress,
|
|
2868
|
+
instanceItemHash: args.instanceItemHash,
|
|
2869
|
+
fetch: args.fetch,
|
|
2870
|
+
apiHost: args.apiHost,
|
|
2871
|
+
ref: args.ref,
|
|
2872
|
+
postType: args.postType
|
|
2873
|
+
}).catch(() => []);
|
|
2874
|
+
const match = signals.find((entry) => entry.status === expectedStatus) ?? null;
|
|
2875
|
+
if (match) return match;
|
|
2876
|
+
if (attempt < attempts - 1) {
|
|
2877
|
+
await sleep2(delayMs);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2759
2882
|
|
|
2760
2883
|
// src/bootstrap-reconcile.ts
|
|
2761
2884
|
function createRelayBootstrapRegistrationId(profile, instanceName, itemHash) {
|
|
@@ -2962,6 +3085,8 @@ export {
|
|
|
2962
3085
|
SSH_PUBLIC_KEY_PATTERN,
|
|
2963
3086
|
SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
|
|
2964
3087
|
VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
|
|
3088
|
+
VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE,
|
|
3089
|
+
VM_BOOTSTRAP_CONFIG_SIGNAL_REF,
|
|
2965
3090
|
appendDeploymentTokenToSshPublicKey,
|
|
2966
3091
|
broadcastAlephMessage,
|
|
2967
3092
|
buildPaymentQuote,
|
|
@@ -2997,6 +3122,7 @@ export {
|
|
|
2997
3122
|
fetchSchedulerAllocation,
|
|
2998
3123
|
fetchUcGoPeerMetadata,
|
|
2999
3124
|
fetchVmBootstrapConfigAggregate,
|
|
3125
|
+
fetchVmBootstrapConfigSignals,
|
|
3000
3126
|
fetchVmRuntime,
|
|
3001
3127
|
filterDeployableCrns,
|
|
3002
3128
|
findCrnByHash,
|
|
@@ -3042,5 +3168,6 @@ export {
|
|
|
3042
3168
|
waitForDeploymentResult,
|
|
3043
3169
|
waitForRelayBootstrapRegistration,
|
|
3044
3170
|
waitForSetupEndpoint,
|
|
3171
|
+
waitForVmBootstrapConfigSignal,
|
|
3045
3172
|
waitForVmRuntime
|
|
3046
3173
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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.
|
|
20
|
-
"@le-space/shared-types": "0.4.
|
|
19
|
+
"@le-space/aleph-bootstrap": "0.4.2",
|
|
20
|
+
"@le-space/shared-types": "0.4.2"
|
|
21
21
|
}
|
|
22
22
|
}
|