@le-space/browser 0.1.29 → 0.1.31

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,9 +24,11 @@ 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
29
30
  - CRN allocation notify
31
+ - relay setup-server configure request
30
32
  - deployment result inspection and polling
31
33
  - Aleph message broadcast helpers
32
34
 
package/index.d.ts CHANGED
@@ -164,6 +164,21 @@ interface InstanceAllocation {
164
164
  interface AllocationNotifyResult {
165
165
  status: 'confirmed' | 'unconfirmed';
166
166
  }
167
+ interface RelaySetupRequest {
168
+ hostIpv4: string;
169
+ publicIpv6?: string | null;
170
+ setupPort: number;
171
+ tcpPort: number;
172
+ wsPort: number;
173
+ proxyUrl?: string | null;
174
+ metricsPort?: number | null;
175
+ metricsHttpsPort?: number | null;
176
+ webrtcPort?: number | null;
177
+ quicPort?: number | null;
178
+ }
179
+ interface RelaySetupResult {
180
+ status: 'configured' | 'unconfirmed';
181
+ }
167
182
  interface AlephBroadcastMessage {
168
183
  sender: string;
169
184
  chain: AlephSenderChain;
@@ -194,9 +209,11 @@ interface AlephBrowserClient {
194
209
  fetchBalance(address: string): Promise<BalanceResponse>;
195
210
  fetchCrns(): Promise<Crn[]>;
196
211
  fetchInstances(address: string): Promise<InstanceMessage[]>;
212
+ fetch2n6WebAccessUrl(itemHash: string): Promise<string | null>;
197
213
  fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
198
214
  fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
199
215
  notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
216
+ configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
200
217
  inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
201
218
  waitForDeploymentResult(itemHash: string, rootfsRef?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
202
219
  broadcastInstanceMessage(message: AlephBroadcastMessage, sync?: boolean): Promise<BroadcastResult>;
@@ -245,12 +262,15 @@ declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit,
245
262
  declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
246
263
  declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
247
264
  declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
265
+ declare const DEFAULT_2N6_API_HOST = "https://api.2n6.me";
248
266
  declare function normalizeMessageStatus(status: unknown): MessageStatus;
249
267
  declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
250
268
  declare function fetchCrns(url?: string): Promise<Crn[]>;
251
269
  declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
270
+ declare function fetch2n6WebAccessUrl(itemHash: string, twoN6ApiHost?: string): Promise<string | null>;
252
271
  declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
253
272
  declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
273
+ declare function configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
254
274
  declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
255
275
  declare function inspectDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string): Promise<DeploymentInspectionResult>;
256
276
  declare function waitForDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
@@ -261,6 +281,7 @@ interface CreateAlephBrowserClientOptions {
261
281
  apiHost?: string;
262
282
  crnListUrl?: string;
263
283
  schedulerApiHost?: string;
284
+ twoN6ApiHost?: string;
264
285
  }
265
286
  declare function createAlephBrowserClient(options?: CreateAlephBrowserClientOptions): AlephBrowserClient;
266
287
 
@@ -279,4 +300,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
279
300
  declare function parseInstancePricing(payload: unknown): InstancePricing;
280
301
  declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
281
302
 
282
- 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 RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type Tier, broadcastAlephMessage, broadcastInstanceMessage, createAlephBrowserClient, fetchBalance, fetchCrns, fetchInstancePricing, fetchInstances, fetchMessageEnvelope, fetchSchedulerAllocation, fetchWithTimeout, inspectDeploymentResult, loadRootfsManifest, normalizeMessageStatus, notifyCrnAllocation, parseInstancePricing, resolveRootfsReference, validateRootfsManifest, verifyRootfsExists, waitForDeploymentResult };
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 };
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,12 @@ 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
+ }
72
79
  async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
73
80
  const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
74
81
  cache: "no-cache"
@@ -100,6 +107,19 @@ async function fetchInstances(address, apiHost = DEFAULT_ALEPH_API_HOST) {
100
107
  status: typeof message.status === "string" && message.status.trim() ? message.status : message.confirmed ? "processed" : message.status
101
108
  }));
102
109
  }
110
+ async function fetch2n6WebAccessUrl(itemHash, twoN6ApiHost = DEFAULT_2N6_API_HOST) {
111
+ const requestUrl = new URL(`/api/hash/${itemHash}`, twoN6ApiHost).toString();
112
+ try {
113
+ const response = await fetchWithTimeout(requestUrl, { cache: "no-cache" });
114
+ if (response.status === 404 || !response.ok) {
115
+ return null;
116
+ }
117
+ const payload = await response.json();
118
+ return normalizeProxyUrl(payload.url ?? payload.subdomain);
119
+ } catch {
120
+ return null;
121
+ }
122
+ }
103
123
  async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALEPH_SCHEDULER_API_HOST) {
104
124
  const response = await fetchWithTimeout(`${schedulerApiHost}/api/v0/allocation/${itemHash}`, {
105
125
  cache: "no-cache"
@@ -147,6 +167,43 @@ async function notifyCrnAllocation(crnUrl, itemHash) {
147
167
  throw error;
148
168
  }
149
169
  }
170
+ async function configureOrbitdbRelaySetup(args) {
171
+ const targetUrl = `http://${args.hostIpv4}:${args.setupPort}/configure`;
172
+ try {
173
+ const response = await fetchWithTimeout(
174
+ targetUrl,
175
+ {
176
+ method: "POST",
177
+ headers: {
178
+ "content-type": "text/plain;charset=UTF-8"
179
+ },
180
+ body: JSON.stringify({
181
+ public_ipv4: args.hostIpv4,
182
+ public_ipv6: args.publicIpv6 ?? void 0,
183
+ tcp_port: args.tcpPort,
184
+ ws_port: args.wsPort,
185
+ proxy_url: args.proxyUrl ?? void 0,
186
+ metrics_port: args.metricsPort ?? void 0,
187
+ metrics_https_port: args.metricsHttpsPort ?? void 0,
188
+ webrtc_port: args.webrtcPort ?? void 0,
189
+ quic_port: args.quicPort ?? void 0
190
+ }),
191
+ mode: "cors"
192
+ },
193
+ 3e4
194
+ );
195
+ if (!response.ok) {
196
+ const responseText = await response.text().catch(() => "");
197
+ throw new Error(`Relay setup request failed: ${response.status}${responseText ? ` ${responseText}` : ""}`);
198
+ }
199
+ return { status: "configured" };
200
+ } catch (error) {
201
+ if (isUnconfirmedNetworkError(error)) {
202
+ return { status: "unconfirmed" };
203
+ }
204
+ throw error;
205
+ }
206
+ }
150
207
  function messageTypeFromEnvelope(payload) {
151
208
  if (!payload) return null;
152
209
  const type = payload.type ?? payload.message?.type ?? (Array.isArray(payload.messages) ? payload.messages[0]?.type : void 0);
@@ -288,6 +345,7 @@ function createAlephBrowserClient(options = {}) {
288
345
  const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
289
346
  const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
290
347
  const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
348
+ const twoN6ApiHost = options.twoN6ApiHost ?? DEFAULT_2N6_API_HOST;
291
349
  return {
292
350
  apiHost,
293
351
  crnListUrl,
@@ -301,6 +359,9 @@ function createAlephBrowserClient(options = {}) {
301
359
  fetchInstances(address) {
302
360
  return fetchInstances(address, apiHost);
303
361
  },
362
+ fetch2n6WebAccessUrl(itemHash) {
363
+ return fetch2n6WebAccessUrl(itemHash, twoN6ApiHost);
364
+ },
304
365
  fetchMessageEnvelope(itemHash) {
305
366
  return fetchMessageEnvelope(itemHash, apiHost);
306
367
  },
@@ -310,6 +371,9 @@ function createAlephBrowserClient(options = {}) {
310
371
  notifyCrnAllocation(crnUrl, itemHash) {
311
372
  return notifyCrnAllocation(crnUrl, itemHash);
312
373
  },
374
+ configureOrbitdbRelaySetup(args) {
375
+ return configureOrbitdbRelaySetup(args);
376
+ },
313
377
  inspectDeploymentResult(itemHash, rootfsRef) {
314
378
  return inspectDeploymentResult(itemHash, rootfsRef, apiHost);
315
379
  },
@@ -536,6 +600,7 @@ async function fetchInstancePricing(apiHost = DEFAULT_ALEPH_API_HOST, aggregateA
536
600
  }
537
601
  export {
538
602
  BROWSER_PACKAGE_PLAN,
603
+ DEFAULT_2N6_API_HOST,
539
604
  DEFAULT_ALEPH_AGGREGATE_ADDRESS,
540
605
  DEFAULT_ALEPH_API_HOST,
541
606
  DEFAULT_ALEPH_SCHEDULER_API_HOST,
@@ -545,7 +610,9 @@ export {
545
610
  ITEM_HASH_RE,
546
611
  broadcastAlephMessage,
547
612
  broadcastInstanceMessage,
613
+ configureOrbitdbRelaySetup,
548
614
  createAlephBrowserClient,
615
+ fetch2n6WebAccessUrl,
549
616
  fetchBalance,
550
617
  fetchCrns,
551
618
  fetchInstancePricing,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",