@le-space/browser 0.1.27 → 0.1.28
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/README.md +1 -0
- package/index.d.ts +22 -1
- package/index.js +36 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -143,6 +143,24 @@ interface DeploymentInspectionResult {
|
|
|
143
143
|
rejectionReason: string | null;
|
|
144
144
|
references: MessageReference[];
|
|
145
145
|
}
|
|
146
|
+
interface InstanceAllocationNode {
|
|
147
|
+
node_id?: string;
|
|
148
|
+
url?: string;
|
|
149
|
+
ipv6?: string | null;
|
|
150
|
+
supports_ipv6?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface InstanceAllocationPeriod {
|
|
153
|
+
start_timestamp?: string;
|
|
154
|
+
duration_seconds?: number;
|
|
155
|
+
}
|
|
156
|
+
interface InstanceAllocation {
|
|
157
|
+
source: 'scheduler' | 'manual';
|
|
158
|
+
crnHash?: string | null;
|
|
159
|
+
crnUrl?: string | null;
|
|
160
|
+
node?: InstanceAllocationNode | null;
|
|
161
|
+
vmIpv6?: string | null;
|
|
162
|
+
period?: InstanceAllocationPeriod | null;
|
|
163
|
+
}
|
|
146
164
|
interface AlephBroadcastMessage {
|
|
147
165
|
sender: string;
|
|
148
166
|
chain: AlephSenderChain;
|
|
@@ -173,6 +191,7 @@ interface AlephBrowserClient {
|
|
|
173
191
|
fetchCrns(): Promise<Crn[]>;
|
|
174
192
|
fetchInstances(address: string): Promise<InstanceMessage[]>;
|
|
175
193
|
fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
|
|
194
|
+
fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
|
|
176
195
|
inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
|
|
177
196
|
waitForDeploymentResult(itemHash: string, rootfsRef?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
|
|
178
197
|
broadcastInstanceMessage(message: AlephBroadcastMessage, sync?: boolean): Promise<BroadcastResult>;
|
|
@@ -220,10 +239,12 @@ declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit,
|
|
|
220
239
|
|
|
221
240
|
declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
222
241
|
declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
242
|
+
declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
|
|
223
243
|
declare function normalizeMessageStatus(status: unknown): MessageStatus;
|
|
224
244
|
declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
|
|
225
245
|
declare function fetchCrns(url?: string): Promise<Crn[]>;
|
|
226
246
|
declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
|
|
247
|
+
declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
|
|
227
248
|
declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
|
|
228
249
|
declare function inspectDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string): Promise<DeploymentInspectionResult>;
|
|
229
250
|
declare function waitForDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
|
|
@@ -251,4 +272,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
|
|
|
251
272
|
declare function parseInstancePricing(payload: unknown): InstancePricing;
|
|
252
273
|
declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
|
|
253
274
|
|
|
254
|
-
export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_ALEPH_AGGREGATE_ADDRESS, DEFAULT_ALEPH_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type DeploymentInspectionResult, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceMessage, type InstancePricing, type LoadRootfsManifestOptions, type MessageReference, type MessageStatus, type PaymentMode, type Price, type PricingState, type ReferenceStatus, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, broadcastAlephMessage, broadcastInstanceMessage, createAlephBrowserClient, fetchBalance, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchWithTimeout, inspectDeploymentResult, loadRootfsManifest, normalizeMessageStatus, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
|
|
275
|
+
export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_ALEPH_AGGREGATE_ADDRESS, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_SCHEDULER_API_HOST, DEFAULT_CRN_LIST_URL, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_ROOTFS_MANIFEST_URL, type DeploymentInspectionResult, type GatewayProbeStatus, ITEM_HASH_RE, type InstanceAllocation, type InstanceAllocationNode, type InstanceAllocationPeriod, type InstanceMessage, type InstancePricing, type LoadRootfsManifestOptions, type MessageReference, type MessageStatus, type PaymentMode, type Price, type PricingState, type ReferenceStatus, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, broadcastAlephMessage, broadcastInstanceMessage, createAlephBrowserClient, fetchBalance, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, inspectDeploymentResult, loadRootfsManifest, normalizeMessageStatus, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
|
package/index.js
CHANGED
|
@@ -50,6 +50,7 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15e3) {
|
|
|
50
50
|
// src/aleph-api.ts
|
|
51
51
|
var DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
52
52
|
var DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
53
|
+
var DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
|
|
53
54
|
function normalizeMessageStatus(status) {
|
|
54
55
|
if (typeof status !== "string") return "unknown";
|
|
55
56
|
const normalized = status.toLowerCase();
|
|
@@ -58,6 +59,12 @@ function normalizeMessageStatus(status) {
|
|
|
58
59
|
}
|
|
59
60
|
return "unknown";
|
|
60
61
|
}
|
|
62
|
+
function asString(value) {
|
|
63
|
+
return typeof value === "string" && value.trim() ? value : null;
|
|
64
|
+
}
|
|
65
|
+
function asNumber(value) {
|
|
66
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
67
|
+
}
|
|
61
68
|
async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
|
|
62
69
|
const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
|
|
63
70
|
cache: "no-cache"
|
|
@@ -89,6 +96,30 @@ async function fetchInstances(address, apiHost = DEFAULT_ALEPH_API_HOST) {
|
|
|
89
96
|
status: typeof message.status === "string" && message.status.trim() ? message.status : message.confirmed ? "processed" : message.status
|
|
90
97
|
}));
|
|
91
98
|
}
|
|
99
|
+
async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALEPH_SCHEDULER_API_HOST) {
|
|
100
|
+
const response = await fetchWithTimeout(`${schedulerApiHost}/api/v0/allocation/${itemHash}`, {
|
|
101
|
+
cache: "no-cache"
|
|
102
|
+
});
|
|
103
|
+
if (response.status === 404) return null;
|
|
104
|
+
if (!response.ok) throw new Error(`Scheduler allocation request failed: ${response.status}`);
|
|
105
|
+
const payload = await response.json();
|
|
106
|
+
const node = payload.node;
|
|
107
|
+
return {
|
|
108
|
+
source: "scheduler",
|
|
109
|
+
crnUrl: asString(node?.url),
|
|
110
|
+
node: node ? {
|
|
111
|
+
node_id: asString(node.node_id) ?? void 0,
|
|
112
|
+
url: asString(node.url) ?? void 0,
|
|
113
|
+
ipv6: asString(node.ipv6),
|
|
114
|
+
supports_ipv6: typeof node.supports_ipv6 === "boolean" ? node.supports_ipv6 : void 0
|
|
115
|
+
} : null,
|
|
116
|
+
vmIpv6: asString(payload.vm_ipv6),
|
|
117
|
+
period: payload.period ? {
|
|
118
|
+
start_timestamp: asString(payload.period.start_timestamp) ?? void 0,
|
|
119
|
+
duration_seconds: asNumber(payload.period.duration_seconds) ?? void 0
|
|
120
|
+
} : null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
92
123
|
function messageTypeFromEnvelope(payload) {
|
|
93
124
|
if (!payload) return null;
|
|
94
125
|
const type = payload.type ?? payload.message?.type ?? (Array.isArray(payload.messages) ? payload.messages[0]?.type : void 0);
|
|
@@ -244,6 +275,9 @@ function createAlephBrowserClient(options = {}) {
|
|
|
244
275
|
fetchMessageEnvelope(itemHash) {
|
|
245
276
|
return fetchMessageEnvelope(itemHash, apiHost);
|
|
246
277
|
},
|
|
278
|
+
fetchSchedulerAllocation(itemHash) {
|
|
279
|
+
return fetchSchedulerAllocation(itemHash);
|
|
280
|
+
},
|
|
247
281
|
inspectDeploymentResult(itemHash, rootfsRef) {
|
|
248
282
|
return inspectDeploymentResult(itemHash, rootfsRef, apiHost);
|
|
249
283
|
},
|
|
@@ -472,6 +506,7 @@ export {
|
|
|
472
506
|
BROWSER_PACKAGE_PLAN,
|
|
473
507
|
DEFAULT_ALEPH_AGGREGATE_ADDRESS,
|
|
474
508
|
DEFAULT_ALEPH_API_HOST,
|
|
509
|
+
DEFAULT_ALEPH_SCHEDULER_API_HOST,
|
|
475
510
|
DEFAULT_CRN_LIST_URL,
|
|
476
511
|
DEFAULT_IPFS_GATEWAY_BASE_URL,
|
|
477
512
|
DEFAULT_ROOTFS_MANIFEST_URL,
|
|
@@ -484,6 +519,7 @@ export {
|
|
|
484
519
|
fetchInstancePricing,
|
|
485
520
|
fetchInstances,
|
|
486
521
|
fetchMessageEnvelope,
|
|
522
|
+
fetchSchedulerAllocation,
|
|
487
523
|
fetchWithTimeout,
|
|
488
524
|
inspectDeploymentResult,
|
|
489
525
|
loadRootfsManifest,
|