@le-space/core 0.3.31 → 0.4.0
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 +2 -28
- package/index.js +9 -103
- 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
|
|
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
|
|
|
@@ -756,8 +756,6 @@ declare function publishRelayBootstrapRegistration(args: {
|
|
|
756
756
|
}): Promise<RelayBootstrapPublicationResult>;
|
|
757
757
|
|
|
758
758
|
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
759
|
declare function fetchVmBootstrapConfigAggregate(address: string, options: {
|
|
762
760
|
apiHost?: string;
|
|
763
761
|
fetch: JsonFetchLike$1;
|
|
@@ -796,30 +794,6 @@ declare function deleteVmBootstrapConfig(args: {
|
|
|
796
794
|
aggregateStatus: MessageStatus;
|
|
797
795
|
aggregate: VmBootstrapConfigAggregate;
|
|
798
796
|
}>;
|
|
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
797
|
|
|
824
798
|
type JsonFetchLike = FetchLike;
|
|
825
799
|
type RelayMetadataShape = {
|
|
@@ -888,4 +862,4 @@ declare function reconcileOwnerRelayBootstrapRegistrations(args: {
|
|
|
888
862
|
} | null;
|
|
889
863
|
}): Promise<OwnerRelayBootstrapReconcileResult>;
|
|
890
864
|
|
|
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,
|
|
865
|
+
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
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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 <
|
|
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:
|
|
760
|
+
throw new Error("Broadcast failed: no compatible request format was accepted");
|
|
758
761
|
}
|
|
759
762
|
|
|
760
763
|
// src/forget.ts
|
|
@@ -2631,16 +2634,6 @@ async function publishRelayBootstrapRegistration(args) {
|
|
|
2631
2634
|
|
|
2632
2635
|
// src/bootstrap-config.ts
|
|
2633
2636
|
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
2637
|
async function fetchVmBootstrapConfigAggregate(address, options) {
|
|
2645
2638
|
const requestUrl = new URL(`/api/v0/aggregates/${address}.json`, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
|
|
2646
2639
|
requestUrl.searchParams.set("keys", VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY);
|
|
@@ -2760,89 +2753,6 @@ async function deleteVmBootstrapConfig(args) {
|
|
|
2760
2753
|
aggregate: content
|
|
2761
2754
|
};
|
|
2762
2755
|
}
|
|
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
2756
|
|
|
2847
2757
|
// src/bootstrap-reconcile.ts
|
|
2848
2758
|
function createRelayBootstrapRegistrationId(profile, instanceName, itemHash) {
|
|
@@ -3049,8 +2959,6 @@ export {
|
|
|
3049
2959
|
SSH_PUBLIC_KEY_PATTERN,
|
|
3050
2960
|
SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
|
|
3051
2961
|
VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
|
|
3052
|
-
VM_BOOTSTRAP_CONFIG_SIGNAL_POST_TYPE,
|
|
3053
|
-
VM_BOOTSTRAP_CONFIG_SIGNAL_REF,
|
|
3054
2962
|
appendDeploymentTokenToSshPublicKey,
|
|
3055
2963
|
broadcastAlephMessage,
|
|
3056
2964
|
buildPaymentQuote,
|
|
@@ -3086,7 +2994,6 @@ export {
|
|
|
3086
2994
|
fetchSchedulerAllocation,
|
|
3087
2995
|
fetchUcGoPeerMetadata,
|
|
3088
2996
|
fetchVmBootstrapConfigAggregate,
|
|
3089
|
-
fetchVmBootstrapConfigSignals,
|
|
3090
2997
|
fetchVmRuntime,
|
|
3091
2998
|
filterDeployableCrns,
|
|
3092
2999
|
findCrnByHash,
|
|
@@ -3132,6 +3039,5 @@ export {
|
|
|
3132
3039
|
waitForDeploymentResult,
|
|
3133
3040
|
waitForRelayBootstrapRegistration,
|
|
3134
3041
|
waitForSetupEndpoint,
|
|
3135
|
-
waitForVmBootstrapConfigSignal,
|
|
3136
3042
|
waitForVmRuntime
|
|
3137
3043
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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.
|
|
20
|
-
"@le-space/shared-types": "0.
|
|
19
|
+
"@le-space/aleph-bootstrap": "0.4.0",
|
|
20
|
+
"@le-space/shared-types": "0.4.0"
|
|
21
21
|
}
|
|
22
22
|
}
|