@le-space/browser 0.1.31 → 0.1.32
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 +92 -1
- package/index.js +119 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ That client should remain small and stable. It currently owns:
|
|
|
27
27
|
- 2n6 web access lookup
|
|
28
28
|
- message envelope lookup
|
|
29
29
|
- scheduler allocation lookup
|
|
30
|
+
- CRN execution list lookup and normalization
|
|
30
31
|
- CRN allocation notify
|
|
31
32
|
- relay setup-server configure request
|
|
32
33
|
- deployment result inspection and polling
|
package/index.d.ts
CHANGED
|
@@ -161,6 +161,44 @@ interface InstanceAllocation {
|
|
|
161
161
|
vmIpv6?: string | null;
|
|
162
162
|
period?: InstanceAllocationPeriod | null;
|
|
163
163
|
}
|
|
164
|
+
interface InstancePortMapping {
|
|
165
|
+
host?: number;
|
|
166
|
+
tcp?: boolean;
|
|
167
|
+
udp?: boolean;
|
|
168
|
+
}
|
|
169
|
+
interface InstanceExecutionStatus {
|
|
170
|
+
defined_at?: string | null;
|
|
171
|
+
preparing_at?: string | null;
|
|
172
|
+
prepared_at?: string | null;
|
|
173
|
+
starting_at?: string | null;
|
|
174
|
+
started_at?: string | null;
|
|
175
|
+
stopping_at?: string | null;
|
|
176
|
+
stopped_at?: string | null;
|
|
177
|
+
}
|
|
178
|
+
interface InstanceExecutionNetworking {
|
|
179
|
+
ipv4?: string | null;
|
|
180
|
+
ipv6?: string | null;
|
|
181
|
+
ipv4_network?: string | null;
|
|
182
|
+
host_ipv4?: string | null;
|
|
183
|
+
ipv6_network?: string | null;
|
|
184
|
+
ipv6_ip?: string | null;
|
|
185
|
+
ipv4_ip?: string | null;
|
|
186
|
+
proxy_url?: string | null;
|
|
187
|
+
mapped_ports?: Record<string, InstancePortMapping>;
|
|
188
|
+
}
|
|
189
|
+
interface InstanceExecution {
|
|
190
|
+
crnUrl: string;
|
|
191
|
+
version: 'v1' | 'v2';
|
|
192
|
+
running?: boolean;
|
|
193
|
+
networking: InstanceExecutionNetworking;
|
|
194
|
+
status?: InstanceExecutionStatus | null;
|
|
195
|
+
}
|
|
196
|
+
interface CrnExecutionLookupResult {
|
|
197
|
+
payload: Record<string, unknown> | null;
|
|
198
|
+
blocked: boolean;
|
|
199
|
+
requestUrl?: string;
|
|
200
|
+
version?: 'v1' | 'v2';
|
|
201
|
+
}
|
|
164
202
|
interface AllocationNotifyResult {
|
|
165
203
|
status: 'confirmed' | 'unconfirmed';
|
|
166
204
|
}
|
|
@@ -212,6 +250,7 @@ interface AlephBrowserClient {
|
|
|
212
250
|
fetch2n6WebAccessUrl(itemHash: string): Promise<string | null>;
|
|
213
251
|
fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
|
|
214
252
|
fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
|
|
253
|
+
fetchCrnExecutionMap(crnUrl: string): Promise<CrnExecutionLookupResult>;
|
|
215
254
|
notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
216
255
|
configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
|
|
217
256
|
inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
|
|
@@ -263,12 +302,64 @@ declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
|
263
302
|
declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
264
303
|
declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
|
|
265
304
|
declare const DEFAULT_2N6_API_HOST = "https://api.2n6.me";
|
|
305
|
+
type CrnExecutionV1Payload = {
|
|
306
|
+
networking?: {
|
|
307
|
+
ipv4?: unknown;
|
|
308
|
+
ipv6?: unknown;
|
|
309
|
+
} | null;
|
|
310
|
+
};
|
|
311
|
+
type CrnExecutionV2Payload = {
|
|
312
|
+
networking?: {
|
|
313
|
+
ipv4_network?: unknown;
|
|
314
|
+
host_ipv4?: unknown;
|
|
315
|
+
ipv6_network?: unknown;
|
|
316
|
+
ipv6_ip?: unknown;
|
|
317
|
+
ipv4_ip?: unknown;
|
|
318
|
+
proxy_url?: unknown;
|
|
319
|
+
proxyUrl?: unknown;
|
|
320
|
+
web_access_url?: unknown;
|
|
321
|
+
webAccessUrl?: unknown;
|
|
322
|
+
proxy_hostname?: unknown;
|
|
323
|
+
proxyHostname?: unknown;
|
|
324
|
+
domain?: unknown;
|
|
325
|
+
hostname?: unknown;
|
|
326
|
+
mapped_ports?: Record<string, {
|
|
327
|
+
host?: unknown;
|
|
328
|
+
tcp?: unknown;
|
|
329
|
+
udp?: unknown;
|
|
330
|
+
}> | null;
|
|
331
|
+
} | null;
|
|
332
|
+
web_access?: {
|
|
333
|
+
url?: unknown;
|
|
334
|
+
proxy_url?: unknown;
|
|
335
|
+
hostname?: unknown;
|
|
336
|
+
domain?: unknown;
|
|
337
|
+
} | null;
|
|
338
|
+
webAccess?: {
|
|
339
|
+
url?: unknown;
|
|
340
|
+
proxy_url?: unknown;
|
|
341
|
+
hostname?: unknown;
|
|
342
|
+
domain?: unknown;
|
|
343
|
+
} | null;
|
|
344
|
+
status?: {
|
|
345
|
+
defined_at?: unknown;
|
|
346
|
+
preparing_at?: unknown;
|
|
347
|
+
prepared_at?: unknown;
|
|
348
|
+
starting_at?: unknown;
|
|
349
|
+
started_at?: unknown;
|
|
350
|
+
stopping_at?: unknown;
|
|
351
|
+
stopped_at?: unknown;
|
|
352
|
+
} | null;
|
|
353
|
+
running?: unknown;
|
|
354
|
+
};
|
|
266
355
|
declare function normalizeMessageStatus(status: unknown): MessageStatus;
|
|
267
356
|
declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
|
|
268
357
|
declare function fetchCrns(url?: string): Promise<Crn[]>;
|
|
269
358
|
declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
|
|
270
359
|
declare function fetch2n6WebAccessUrl(itemHash: string, twoN6ApiHost?: string): Promise<string | null>;
|
|
271
360
|
declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
|
|
361
|
+
declare function fetchCrnExecutionMap(crnUrl: string): Promise<CrnExecutionLookupResult>;
|
|
362
|
+
declare function normalizeExecution(item: CrnExecutionV1Payload | CrnExecutionV2Payload, crnUrl: string): InstanceExecution;
|
|
272
363
|
declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
273
364
|
declare function configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
|
|
274
365
|
declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
|
|
@@ -300,4 +391,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
|
|
|
300
391
|
declare function parseInstancePricing(payload: unknown): InstancePricing;
|
|
301
392
|
declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
|
|
302
393
|
|
|
303
|
-
export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, type AllocationNotifyResult, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_2N6_API_HOST, 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 RelaySetupRequest, type RelaySetupResult, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, broadcastAlephMessage, broadcastInstanceMessage, configureOrbitdbRelaySetup, createAlephBrowserClient, fetch2n6WebAccessUrl, fetchBalance, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, inspectDeploymentResult, loadRootfsManifest, normalizeMessageStatus, notifyCrnAllocation, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
|
|
394
|
+
export { type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephBrowserClient, type AlephMessageEnvelope, type AlephMessageType, type AlephSenderChain, type AllocationNotifyResult, BROWSER_PACKAGE_PLAN, type BalanceResponse, type BroadcastResult, type BrowserExtractionPhase, type BrowserPackagePlan, type ComputeUnit, type CreateAlephBrowserClientOptions, type Crn, type CrnExecutionLookupResult, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_2N6_API_HOST, 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 InstanceExecution, type InstanceExecutionNetworking, type InstanceExecutionStatus, type InstanceMessage, type InstancePortMapping, type InstancePricing, type LoadRootfsManifestOptions, type MessageReference, type MessageStatus, type PaymentMode, type Price, type PricingState, type ReferenceStatus, type RelaySetupRequest, type RelaySetupResult, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, broadcastAlephMessage, broadcastInstanceMessage, configureOrbitdbRelaySetup, createAlephBrowserClient, fetch2n6WebAccessUrl, fetchBalance, fetchCrnExecutionMap, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, inspectDeploymentResult, loadRootfsManifest, normalizeExecution, normalizeMessageStatus, notifyCrnAllocation, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
|
package/index.js
CHANGED
|
@@ -76,6 +76,27 @@ function normalizeProxyUrl(value) {
|
|
|
76
76
|
if (/^https?:\/\//i.test(stringValue)) return stringValue;
|
|
77
77
|
return `https://${stringValue}`;
|
|
78
78
|
}
|
|
79
|
+
function extractProxyUrl(value, networking) {
|
|
80
|
+
const networkingCandidates = [
|
|
81
|
+
networking?.proxy_url,
|
|
82
|
+
networking?.proxyUrl,
|
|
83
|
+
networking?.web_access_url,
|
|
84
|
+
networking?.webAccessUrl,
|
|
85
|
+
networking?.proxy_hostname,
|
|
86
|
+
networking?.proxyHostname,
|
|
87
|
+
networking?.domain,
|
|
88
|
+
networking?.hostname
|
|
89
|
+
];
|
|
90
|
+
for (const candidate of networkingCandidates) {
|
|
91
|
+
const normalized = normalizeProxyUrl(candidate);
|
|
92
|
+
if (normalized) return normalized;
|
|
93
|
+
}
|
|
94
|
+
for (const entry of [value.web_access, value.webAccess]) {
|
|
95
|
+
const normalized = normalizeProxyUrl(entry?.url) ?? normalizeProxyUrl(entry?.proxy_url) ?? normalizeProxyUrl(entry?.hostname) ?? normalizeProxyUrl(entry?.domain);
|
|
96
|
+
if (normalized) return normalized;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
79
100
|
async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
|
|
80
101
|
const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
|
|
81
102
|
cache: "no-cache"
|
|
@@ -144,6 +165,99 @@ async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALE
|
|
|
144
165
|
} : null
|
|
145
166
|
};
|
|
146
167
|
}
|
|
168
|
+
async function fetchCrnExecutionMap(crnUrl) {
|
|
169
|
+
const normalizedCrnUrl = crnUrl.replace(/\/+$/, "");
|
|
170
|
+
const v2Url = `${normalizedCrnUrl}/v2/about/executions/list`;
|
|
171
|
+
const v1Url = `${normalizedCrnUrl}/about/executions/list`;
|
|
172
|
+
try {
|
|
173
|
+
const v2Response = await fetchWithTimeout(v2Url, { cache: "no-cache" });
|
|
174
|
+
if (v2Response.ok) {
|
|
175
|
+
const payload = await v2Response.json();
|
|
176
|
+
return {
|
|
177
|
+
payload,
|
|
178
|
+
blocked: false,
|
|
179
|
+
requestUrl: v2Url,
|
|
180
|
+
version: "v2"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (v2Response.status !== 404) {
|
|
184
|
+
return { payload: null, blocked: false, requestUrl: v2Url, version: "v2" };
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
188
|
+
if (error instanceof TypeError || message.includes("Failed to fetch")) {
|
|
189
|
+
return { payload: null, blocked: true, requestUrl: v2Url, version: "v2" };
|
|
190
|
+
}
|
|
191
|
+
return { payload: null, blocked: false, requestUrl: v2Url, version: "v2" };
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const v1Response = await fetchWithTimeout(v1Url, { cache: "no-cache" });
|
|
195
|
+
if (!v1Response.ok) {
|
|
196
|
+
return { payload: null, blocked: false, requestUrl: v1Url, version: "v1" };
|
|
197
|
+
}
|
|
198
|
+
const payload = await v1Response.json();
|
|
199
|
+
return {
|
|
200
|
+
payload,
|
|
201
|
+
blocked: false,
|
|
202
|
+
requestUrl: v1Url,
|
|
203
|
+
version: "v1"
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
207
|
+
if (error instanceof TypeError || message.includes("Failed to fetch")) {
|
|
208
|
+
return { payload: null, blocked: true, requestUrl: v1Url, version: "v1" };
|
|
209
|
+
}
|
|
210
|
+
return { payload: null, blocked: false, requestUrl: v1Url, version: "v1" };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function normalizeExecution(item, crnUrl) {
|
|
214
|
+
const networking = item.networking ?? null;
|
|
215
|
+
const mappedPorts = networking && "mapped_ports" in networking && networking.mapped_ports && typeof networking.mapped_ports === "object" ? Object.fromEntries(
|
|
216
|
+
Object.entries(networking.mapped_ports).map(([port, mapping]) => [
|
|
217
|
+
port,
|
|
218
|
+
{
|
|
219
|
+
host: asNumber(mapping?.host) ?? void 0,
|
|
220
|
+
tcp: typeof mapping?.tcp === "boolean" ? mapping.tcp : void 0,
|
|
221
|
+
udp: typeof mapping?.udp === "boolean" ? mapping.udp : void 0
|
|
222
|
+
}
|
|
223
|
+
])
|
|
224
|
+
) : void 0;
|
|
225
|
+
if (networking && ("host_ipv4" in networking || "ipv6_ip" in networking || "ipv4_network" in networking)) {
|
|
226
|
+
const v2Item = item;
|
|
227
|
+
return {
|
|
228
|
+
crnUrl,
|
|
229
|
+
version: "v2",
|
|
230
|
+
running: typeof v2Item.running === "boolean" ? v2Item.running : void 0,
|
|
231
|
+
networking: {
|
|
232
|
+
ipv4_network: asString(networking.ipv4_network),
|
|
233
|
+
host_ipv4: asString(networking.host_ipv4),
|
|
234
|
+
ipv6_network: asString(networking.ipv6_network),
|
|
235
|
+
ipv6_ip: asString(networking.ipv6_ip),
|
|
236
|
+
ipv4_ip: asString(networking.ipv4_ip),
|
|
237
|
+
proxy_url: extractProxyUrl(v2Item, networking),
|
|
238
|
+
mapped_ports: mappedPorts
|
|
239
|
+
},
|
|
240
|
+
status: v2Item.status ? {
|
|
241
|
+
defined_at: asString(v2Item.status.defined_at),
|
|
242
|
+
preparing_at: asString(v2Item.status.preparing_at),
|
|
243
|
+
prepared_at: asString(v2Item.status.prepared_at),
|
|
244
|
+
starting_at: asString(v2Item.status.starting_at),
|
|
245
|
+
started_at: asString(v2Item.status.started_at),
|
|
246
|
+
stopping_at: asString(v2Item.status.stopping_at),
|
|
247
|
+
stopped_at: asString(v2Item.status.stopped_at)
|
|
248
|
+
} : null
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
crnUrl,
|
|
253
|
+
version: "v1",
|
|
254
|
+
networking: {
|
|
255
|
+
ipv4: networking && "ipv4" in networking ? asString(networking.ipv4) : null,
|
|
256
|
+
ipv6: networking && "ipv6" in networking ? asString(networking.ipv6) : null
|
|
257
|
+
},
|
|
258
|
+
status: null
|
|
259
|
+
};
|
|
260
|
+
}
|
|
147
261
|
async function notifyCrnAllocation(crnUrl, itemHash) {
|
|
148
262
|
const normalizedCrnUrl = crnUrl.replace(/\/+$/, "");
|
|
149
263
|
try {
|
|
@@ -368,6 +482,9 @@ function createAlephBrowserClient(options = {}) {
|
|
|
368
482
|
fetchSchedulerAllocation(itemHash) {
|
|
369
483
|
return fetchSchedulerAllocation(itemHash, schedulerApiHost);
|
|
370
484
|
},
|
|
485
|
+
fetchCrnExecutionMap(crnUrl) {
|
|
486
|
+
return fetchCrnExecutionMap(crnUrl);
|
|
487
|
+
},
|
|
371
488
|
notifyCrnAllocation(crnUrl, itemHash) {
|
|
372
489
|
return notifyCrnAllocation(crnUrl, itemHash);
|
|
373
490
|
},
|
|
@@ -614,6 +731,7 @@ export {
|
|
|
614
731
|
createAlephBrowserClient,
|
|
615
732
|
fetch2n6WebAccessUrl,
|
|
616
733
|
fetchBalance,
|
|
734
|
+
fetchCrnExecutionMap,
|
|
617
735
|
fetchCrns,
|
|
618
736
|
fetchInstancePricing,
|
|
619
737
|
fetchInstances,
|
|
@@ -622,6 +740,7 @@ export {
|
|
|
622
740
|
fetchWithTimeout,
|
|
623
741
|
inspectDeploymentResult,
|
|
624
742
|
loadRootfsManifest,
|
|
743
|
+
normalizeExecution,
|
|
625
744
|
normalizeMessageStatus,
|
|
626
745
|
notifyCrnAllocation,
|
|
627
746
|
parseInstancePricing,
|