@le-space/browser 0.1.30 → 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 CHANGED
@@ -24,8 +24,10 @@ That client should remain small and stable. It currently owns:
24
24
  - balance lookup
25
25
  - CRN listing
26
26
  - instance listing
27
+ - 2n6 web access lookup
27
28
  - message envelope lookup
28
29
  - scheduler allocation lookup
30
+ - CRN execution list lookup and normalization
29
31
  - CRN allocation notify
30
32
  - relay setup-server configure request
31
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
  }
@@ -209,8 +247,10 @@ interface AlephBrowserClient {
209
247
  fetchBalance(address: string): Promise<BalanceResponse>;
210
248
  fetchCrns(): Promise<Crn[]>;
211
249
  fetchInstances(address: string): Promise<InstanceMessage[]>;
250
+ fetch2n6WebAccessUrl(itemHash: string): Promise<string | null>;
212
251
  fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
213
252
  fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
253
+ fetchCrnExecutionMap(crnUrl: string): Promise<CrnExecutionLookupResult>;
214
254
  notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
215
255
  configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
216
256
  inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
@@ -261,11 +301,65 @@ declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit,
261
301
  declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
262
302
  declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
263
303
  declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
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
+ };
264
355
  declare function normalizeMessageStatus(status: unknown): MessageStatus;
265
356
  declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
266
357
  declare function fetchCrns(url?: string): Promise<Crn[]>;
267
358
  declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
359
+ declare function fetch2n6WebAccessUrl(itemHash: string, twoN6ApiHost?: string): Promise<string | null>;
268
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;
269
363
  declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
270
364
  declare function configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
271
365
  declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
@@ -278,6 +372,7 @@ interface CreateAlephBrowserClientOptions {
278
372
  apiHost?: string;
279
373
  crnListUrl?: string;
280
374
  schedulerApiHost?: string;
375
+ twoN6ApiHost?: string;
281
376
  }
282
377
  declare function createAlephBrowserClient(options?: CreateAlephBrowserClientOptions): AlephBrowserClient;
283
378
 
@@ -296,4 +391,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
296
391
  declare function parseInstancePricing(payload: unknown): InstancePricing;
297
392
  declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
298
393
 
299
- 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_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, 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
@@ -51,6 +51,7 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15e3) {
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
53
  var DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
54
+ var DEFAULT_2N6_API_HOST = "https://api.2n6.me";
54
55
  function normalizeMessageStatus(status) {
55
56
  if (typeof status !== "string") return "unknown";
56
57
  const normalized = status.toLowerCase();
@@ -69,6 +70,33 @@ function isUnconfirmedNetworkError(error) {
69
70
  const message = error instanceof Error ? error.message : String(error);
70
71
  return error instanceof TypeError || message.includes("Failed to fetch") || message.includes("Request timed out");
71
72
  }
73
+ function normalizeProxyUrl(value) {
74
+ const stringValue = asString(value);
75
+ if (!stringValue) return null;
76
+ if (/^https?:\/\//i.test(stringValue)) return stringValue;
77
+ return `https://${stringValue}`;
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
+ }
72
100
  async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
73
101
  const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
74
102
  cache: "no-cache"
@@ -100,6 +128,19 @@ async function fetchInstances(address, apiHost = DEFAULT_ALEPH_API_HOST) {
100
128
  status: typeof message.status === "string" && message.status.trim() ? message.status : message.confirmed ? "processed" : message.status
101
129
  }));
102
130
  }
131
+ async function fetch2n6WebAccessUrl(itemHash, twoN6ApiHost = DEFAULT_2N6_API_HOST) {
132
+ const requestUrl = new URL(`/api/hash/${itemHash}`, twoN6ApiHost).toString();
133
+ try {
134
+ const response = await fetchWithTimeout(requestUrl, { cache: "no-cache" });
135
+ if (response.status === 404 || !response.ok) {
136
+ return null;
137
+ }
138
+ const payload = await response.json();
139
+ return normalizeProxyUrl(payload.url ?? payload.subdomain);
140
+ } catch {
141
+ return null;
142
+ }
143
+ }
103
144
  async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALEPH_SCHEDULER_API_HOST) {
104
145
  const response = await fetchWithTimeout(`${schedulerApiHost}/api/v0/allocation/${itemHash}`, {
105
146
  cache: "no-cache"
@@ -124,6 +165,99 @@ async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALE
124
165
  } : null
125
166
  };
126
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
+ }
127
261
  async function notifyCrnAllocation(crnUrl, itemHash) {
128
262
  const normalizedCrnUrl = crnUrl.replace(/\/+$/, "");
129
263
  try {
@@ -325,6 +459,7 @@ function createAlephBrowserClient(options = {}) {
325
459
  const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
326
460
  const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
327
461
  const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
462
+ const twoN6ApiHost = options.twoN6ApiHost ?? DEFAULT_2N6_API_HOST;
328
463
  return {
329
464
  apiHost,
330
465
  crnListUrl,
@@ -338,12 +473,18 @@ function createAlephBrowserClient(options = {}) {
338
473
  fetchInstances(address) {
339
474
  return fetchInstances(address, apiHost);
340
475
  },
476
+ fetch2n6WebAccessUrl(itemHash) {
477
+ return fetch2n6WebAccessUrl(itemHash, twoN6ApiHost);
478
+ },
341
479
  fetchMessageEnvelope(itemHash) {
342
480
  return fetchMessageEnvelope(itemHash, apiHost);
343
481
  },
344
482
  fetchSchedulerAllocation(itemHash) {
345
483
  return fetchSchedulerAllocation(itemHash, schedulerApiHost);
346
484
  },
485
+ fetchCrnExecutionMap(crnUrl) {
486
+ return fetchCrnExecutionMap(crnUrl);
487
+ },
347
488
  notifyCrnAllocation(crnUrl, itemHash) {
348
489
  return notifyCrnAllocation(crnUrl, itemHash);
349
490
  },
@@ -576,6 +717,7 @@ async function fetchInstancePricing(apiHost = DEFAULT_ALEPH_API_HOST, aggregateA
576
717
  }
577
718
  export {
578
719
  BROWSER_PACKAGE_PLAN,
720
+ DEFAULT_2N6_API_HOST,
579
721
  DEFAULT_ALEPH_AGGREGATE_ADDRESS,
580
722
  DEFAULT_ALEPH_API_HOST,
581
723
  DEFAULT_ALEPH_SCHEDULER_API_HOST,
@@ -587,7 +729,9 @@ export {
587
729
  broadcastInstanceMessage,
588
730
  configureOrbitdbRelaySetup,
589
731
  createAlephBrowserClient,
732
+ fetch2n6WebAccessUrl,
590
733
  fetchBalance,
734
+ fetchCrnExecutionMap,
591
735
  fetchCrns,
592
736
  fetchInstancePricing,
593
737
  fetchInstances,
@@ -596,6 +740,7 @@ export {
596
740
  fetchWithTimeout,
597
741
  inspectDeploymentResult,
598
742
  loadRootfsManifest,
743
+ normalizeExecution,
599
744
  normalizeMessageStatus,
600
745
  notifyCrnAllocation,
601
746
  parseInstancePricing,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",