@le-space/core 0.1.32 → 0.1.34
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 +49 -2
- package/index.js +58 -0
- package/package.json +2 -2
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, AlephAggregateContent, AlephInstanceContent, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping } from '@le-space/shared-types';
|
|
2
|
+
import { RootfsResolution, RootfsManifest, RootfsManifestState, CrnRecord, RootfsRequiredPortForward, PortForwardAggregate, PortForwardFlags, PortForwardAggregateEntry, MessageReference, InstanceExecution, MessageStatus, DeploymentInspectionResult, MessageInspectionResult, AlephBroadcastMessage, AlephBroadcastResponse, MessageSigner, MessageHasher, AlephAggregateContent, AlephInstanceContent, DeploymentIntentEnvelope, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping } from '@le-space/shared-types';
|
|
3
3
|
|
|
4
4
|
declare const DEFAULT_ALEPH_CHANNEL = "TEST";
|
|
5
5
|
|
|
@@ -381,6 +381,18 @@ declare function ensureInstancePortForwards(args: {
|
|
|
381
381
|
}>;
|
|
382
382
|
|
|
383
383
|
declare const SSH_PUBLIC_KEY_PATTERN: RegExp;
|
|
384
|
+
interface TierSpec {
|
|
385
|
+
vcpus: number;
|
|
386
|
+
memoryMiB: number;
|
|
387
|
+
diskMiB: number;
|
|
388
|
+
}
|
|
389
|
+
interface PaymentQuote {
|
|
390
|
+
required: number;
|
|
391
|
+
available: number;
|
|
392
|
+
computeUnits: number;
|
|
393
|
+
unitPrice: number;
|
|
394
|
+
label: 'credits';
|
|
395
|
+
}
|
|
384
396
|
declare function normalizeSshPublicKey(value: string): string;
|
|
385
397
|
declare function isValidSshPublicKey(value: string): boolean;
|
|
386
398
|
declare function createReleaseMetadata(name: string, rootfsVersion: string, deployer?: string): {
|
|
@@ -388,6 +400,32 @@ declare function createReleaseMetadata(name: string, rootfsVersion: string, depl
|
|
|
388
400
|
rootfs_version: string;
|
|
389
401
|
deployer: string;
|
|
390
402
|
};
|
|
403
|
+
declare function selectedTier<TTier extends {
|
|
404
|
+
id: string;
|
|
405
|
+
}>(pricing: {
|
|
406
|
+
tiers: TTier[];
|
|
407
|
+
} | null, tierId: string): TTier | null;
|
|
408
|
+
declare function tierSpec<TTier extends {
|
|
409
|
+
compute_units: number;
|
|
410
|
+
}>(pricing: {
|
|
411
|
+
compute_unit: {
|
|
412
|
+
vcpus: number;
|
|
413
|
+
memory_mib: number;
|
|
414
|
+
disk_mib: number;
|
|
415
|
+
};
|
|
416
|
+
}, tier: TTier): TierSpec;
|
|
417
|
+
declare function buildPaymentQuote<TTier extends {
|
|
418
|
+
compute_units: number;
|
|
419
|
+
}>(tier: TTier, pricing: {
|
|
420
|
+
price: {
|
|
421
|
+
compute_unit?: {
|
|
422
|
+
credit?: string | number | null;
|
|
423
|
+
} | null;
|
|
424
|
+
};
|
|
425
|
+
}, balance: {
|
|
426
|
+
credit_balance?: number | null;
|
|
427
|
+
}): PaymentQuote | null;
|
|
428
|
+
declare function quoteRequiredBudgetUnits(quote: PaymentQuote | null): bigint;
|
|
391
429
|
declare function createInstanceContent(args: {
|
|
392
430
|
address: string;
|
|
393
431
|
name: string;
|
|
@@ -409,6 +447,15 @@ declare function createUnsignedInstanceMessage(args: {
|
|
|
409
447
|
channel?: string;
|
|
410
448
|
now?: number;
|
|
411
449
|
}): Promise<Omit<AlephBroadcastMessage, 'signature'>>;
|
|
450
|
+
declare function createDeploymentIntent(args: {
|
|
451
|
+
sender: string;
|
|
452
|
+
unsignedMessage: Omit<AlephBroadcastMessage, 'signature'>;
|
|
453
|
+
content: AlephInstanceContent;
|
|
454
|
+
computeUnits: number;
|
|
455
|
+
expiresAt: number;
|
|
456
|
+
maxCost: string;
|
|
457
|
+
hasher: MessageHasher;
|
|
458
|
+
}): Promise<DeploymentIntentEnvelope>;
|
|
412
459
|
declare function deployInstance(args: {
|
|
413
460
|
sender: string;
|
|
414
461
|
content: AlephInstanceContent;
|
|
@@ -544,4 +591,4 @@ declare function verifyUcGoPeerReachability(args: {
|
|
|
544
591
|
checks: Record<string, Record<string, unknown>>;
|
|
545
592
|
}>;
|
|
546
593
|
|
|
547
|
-
export { 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, type JsonFetchLikeResponse, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, broadcastAlephMessage, cleanupFailedDeployment, configureUcGoPeer, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, signAlephMessage, signaturePayload, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
|
|
594
|
+
export { 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, type JsonFetchLikeResponse, type PaymentQuote, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureUcGoPeer, createDeploymentIntent, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, quoteRequiredBudgetUnits, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
|
package/index.js
CHANGED
|
@@ -1210,6 +1210,11 @@ async function ensureInstancePortForwards(args) {
|
|
|
1210
1210
|
|
|
1211
1211
|
// src/instance-deployment.ts
|
|
1212
1212
|
var SSH_PUBLIC_KEY_PATTERN = /^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521|sk-ssh-ed25519@openssh\.com|sk-ecdsa-sha2-nistp256@openssh\.com)\s+[A-Za-z0-9+/]+={0,3}(?:\s+.+)?$/;
|
|
1213
|
+
function toFiniteNumber(value) {
|
|
1214
|
+
if (typeof value === "number") return value;
|
|
1215
|
+
if (typeof value === "string" && value.trim()) return Number(value);
|
|
1216
|
+
return Number.NaN;
|
|
1217
|
+
}
|
|
1213
1218
|
function normalizeSshPublicKey(value) {
|
|
1214
1219
|
return value.split(/\r?\n/g).map((line) => line.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
1215
1220
|
}
|
|
@@ -1223,6 +1228,33 @@ function createReleaseMetadata(name, rootfsVersion, deployer = "shared-aleph-too
|
|
|
1223
1228
|
deployer
|
|
1224
1229
|
};
|
|
1225
1230
|
}
|
|
1231
|
+
function selectedTier(pricing, tierId) {
|
|
1232
|
+
return pricing?.tiers.find((tier) => tier.id === tierId) ?? null;
|
|
1233
|
+
}
|
|
1234
|
+
function tierSpec(pricing, tier) {
|
|
1235
|
+
return {
|
|
1236
|
+
vcpus: pricing.compute_unit.vcpus * tier.compute_units,
|
|
1237
|
+
memoryMiB: pricing.compute_unit.memory_mib * tier.compute_units,
|
|
1238
|
+
diskMiB: pricing.compute_unit.disk_mib * tier.compute_units
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
function buildPaymentQuote(tier, pricing, balance) {
|
|
1242
|
+
const computeUnitPrice = pricing.price.compute_unit;
|
|
1243
|
+
if (!computeUnitPrice) return null;
|
|
1244
|
+
const unitPrice = toFiniteNumber(computeUnitPrice.credit);
|
|
1245
|
+
if (!Number.isFinite(unitPrice)) return null;
|
|
1246
|
+
return {
|
|
1247
|
+
required: unitPrice * tier.compute_units,
|
|
1248
|
+
available: Number(balance.credit_balance ?? 0),
|
|
1249
|
+
computeUnits: tier.compute_units,
|
|
1250
|
+
unitPrice,
|
|
1251
|
+
label: "credits"
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function quoteRequiredBudgetUnits(quote) {
|
|
1255
|
+
if (!quote) return 0n;
|
|
1256
|
+
return BigInt(Math.ceil(quote.required * 1e18));
|
|
1257
|
+
}
|
|
1226
1258
|
function createInstanceContent(args) {
|
|
1227
1259
|
const sshKey = normalizeSshPublicKey(args.sshPublicKey);
|
|
1228
1260
|
if (!sshKey) {
|
|
@@ -1285,6 +1317,27 @@ async function createUnsignedInstanceMessage(args) {
|
|
|
1285
1317
|
channel: args.channel ?? DEFAULT_ALEPH_CHANNEL
|
|
1286
1318
|
};
|
|
1287
1319
|
}
|
|
1320
|
+
async function createDeploymentIntent(args) {
|
|
1321
|
+
const intent = {
|
|
1322
|
+
ownerAddress: args.sender,
|
|
1323
|
+
messageTime: args.unsignedMessage.time,
|
|
1324
|
+
itemHash: args.unsignedMessage.item_hash,
|
|
1325
|
+
paymentType: args.content.payment.type,
|
|
1326
|
+
rootfsRef: args.content.rootfs.parent.ref,
|
|
1327
|
+
rootfsSizeMiB: args.content.rootfs.size_mib,
|
|
1328
|
+
computeUnits: args.computeUnits,
|
|
1329
|
+
vcpus: args.content.resources.vcpus,
|
|
1330
|
+
memoryMiB: args.content.resources.memory,
|
|
1331
|
+
crnHash: args.content.requirements?.node?.node_hash ?? null,
|
|
1332
|
+
channel: args.unsignedMessage.channel,
|
|
1333
|
+
expiresAt: args.expiresAt,
|
|
1334
|
+
maxCost: args.maxCost
|
|
1335
|
+
};
|
|
1336
|
+
return {
|
|
1337
|
+
intent,
|
|
1338
|
+
intentHash: await args.hasher(JSON.stringify(intent))
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1288
1341
|
async function deployInstance(args) {
|
|
1289
1342
|
const unsignedMessage = await createUnsignedInstanceMessage({
|
|
1290
1343
|
sender: args.sender,
|
|
@@ -1764,8 +1817,10 @@ export {
|
|
|
1764
1817
|
SSH_PUBLIC_KEY_PATTERN,
|
|
1765
1818
|
SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
|
|
1766
1819
|
broadcastAlephMessage,
|
|
1820
|
+
buildPaymentQuote,
|
|
1767
1821
|
cleanupFailedDeployment,
|
|
1768
1822
|
configureUcGoPeer,
|
|
1823
|
+
createDeploymentIntent,
|
|
1769
1824
|
createInstanceContent,
|
|
1770
1825
|
createPortForwardAggregateContent,
|
|
1771
1826
|
createReleaseMetadata,
|
|
@@ -1810,14 +1865,17 @@ export {
|
|
|
1810
1865
|
postBroadcastPayload,
|
|
1811
1866
|
probeRootfsGateway,
|
|
1812
1867
|
publishAggregateKey,
|
|
1868
|
+
quoteRequiredBudgetUnits,
|
|
1813
1869
|
rankCandidateCrns,
|
|
1814
1870
|
requestedPortFlags,
|
|
1815
1871
|
requiredInstancePortForwards,
|
|
1816
1872
|
resolveRootfsReference,
|
|
1817
1873
|
retainSuccessfulDeployments,
|
|
1818
1874
|
selectPreferredCrn,
|
|
1875
|
+
selectedTier,
|
|
1819
1876
|
signAlephMessage,
|
|
1820
1877
|
signaturePayload,
|
|
1878
|
+
tierSpec,
|
|
1821
1879
|
validateRootfsManifest,
|
|
1822
1880
|
verifyRootfsExists,
|
|
1823
1881
|
verifyUcGoPeerReachability,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@le-space/shared-types": "0.1.
|
|
19
|
+
"@le-space/shared-types": "0.1.34"
|
|
20
20
|
}
|
|
21
21
|
}
|