@le-space/browser 0.1.28 → 0.1.30

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
@@ -26,6 +26,8 @@ That client should remain small and stable. It currently owns:
26
26
  - instance listing
27
27
  - message envelope lookup
28
28
  - scheduler allocation lookup
29
+ - CRN allocation notify
30
+ - relay setup-server configure request
29
31
  - deployment result inspection and polling
30
32
  - Aleph message broadcast helpers
31
33
 
package/index.d.ts CHANGED
@@ -161,6 +161,24 @@ interface InstanceAllocation {
161
161
  vmIpv6?: string | null;
162
162
  period?: InstanceAllocationPeriod | null;
163
163
  }
164
+ interface AllocationNotifyResult {
165
+ status: 'confirmed' | 'unconfirmed';
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
+ }
164
182
  interface AlephBroadcastMessage {
165
183
  sender: string;
166
184
  chain: AlephSenderChain;
@@ -187,11 +205,14 @@ interface BroadcastResult {
187
205
  interface AlephBrowserClient {
188
206
  apiHost: string;
189
207
  crnListUrl: string;
208
+ schedulerApiHost: string;
190
209
  fetchBalance(address: string): Promise<BalanceResponse>;
191
210
  fetchCrns(): Promise<Crn[]>;
192
211
  fetchInstances(address: string): Promise<InstanceMessage[]>;
193
212
  fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
194
213
  fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
214
+ notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
215
+ configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
195
216
  inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
196
217
  waitForDeploymentResult(itemHash: string, rootfsRef?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
197
218
  broadcastInstanceMessage(message: AlephBroadcastMessage, sync?: boolean): Promise<BroadcastResult>;
@@ -245,6 +266,8 @@ declare function fetchBalance(address: string, apiHost?: string): Promise<Balanc
245
266
  declare function fetchCrns(url?: string): Promise<Crn[]>;
246
267
  declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
247
268
  declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
269
+ declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
270
+ declare function configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
248
271
  declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
249
272
  declare function inspectDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string): Promise<DeploymentInspectionResult>;
250
273
  declare function waitForDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
@@ -254,6 +277,7 @@ declare function broadcastAlephMessage(message: AlephBroadcastMessage, apiHost?:
254
277
  interface CreateAlephBrowserClientOptions {
255
278
  apiHost?: string;
256
279
  crnListUrl?: string;
280
+ schedulerApiHost?: string;
257
281
  }
258
282
  declare function createAlephBrowserClient(options?: CreateAlephBrowserClientOptions): AlephBrowserClient;
259
283
 
@@ -272,4 +296,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
272
296
  declare function parseInstancePricing(payload: unknown): InstancePricing;
273
297
  declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
274
298
 
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 };
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 };
package/index.js CHANGED
@@ -65,6 +65,10 @@ function asString(value) {
65
65
  function asNumber(value) {
66
66
  return typeof value === "number" && Number.isFinite(value) ? value : null;
67
67
  }
68
+ function isUnconfirmedNetworkError(error) {
69
+ const message = error instanceof Error ? error.message : String(error);
70
+ return error instanceof TypeError || message.includes("Failed to fetch") || message.includes("Request timed out");
71
+ }
68
72
  async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
69
73
  const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
70
74
  cache: "no-cache"
@@ -120,6 +124,66 @@ async function fetchSchedulerAllocation(itemHash, schedulerApiHost = DEFAULT_ALE
120
124
  } : null
121
125
  };
122
126
  }
127
+ async function notifyCrnAllocation(crnUrl, itemHash) {
128
+ const normalizedCrnUrl = crnUrl.replace(/\/+$/, "");
129
+ try {
130
+ const response = await fetchWithTimeout(`${normalizedCrnUrl}/control/allocation/notify`, {
131
+ method: "POST",
132
+ headers: {
133
+ "content-type": "text/plain;charset=UTF-8"
134
+ },
135
+ body: JSON.stringify({ instance: itemHash }),
136
+ mode: "cors"
137
+ });
138
+ if (!response.ok) {
139
+ const responseText = await response.text().catch(() => "");
140
+ throw new Error(`CRN allocation notify failed: ${response.status}${responseText ? ` ${responseText}` : ""}`);
141
+ }
142
+ return { status: "confirmed" };
143
+ } catch (error) {
144
+ if (isUnconfirmedNetworkError(error)) {
145
+ return { status: "unconfirmed" };
146
+ }
147
+ throw error;
148
+ }
149
+ }
150
+ async function configureOrbitdbRelaySetup(args) {
151
+ const targetUrl = `http://${args.hostIpv4}:${args.setupPort}/configure`;
152
+ try {
153
+ const response = await fetchWithTimeout(
154
+ targetUrl,
155
+ {
156
+ method: "POST",
157
+ headers: {
158
+ "content-type": "text/plain;charset=UTF-8"
159
+ },
160
+ body: JSON.stringify({
161
+ public_ipv4: args.hostIpv4,
162
+ public_ipv6: args.publicIpv6 ?? void 0,
163
+ tcp_port: args.tcpPort,
164
+ ws_port: args.wsPort,
165
+ proxy_url: args.proxyUrl ?? void 0,
166
+ metrics_port: args.metricsPort ?? void 0,
167
+ metrics_https_port: args.metricsHttpsPort ?? void 0,
168
+ webrtc_port: args.webrtcPort ?? void 0,
169
+ quic_port: args.quicPort ?? void 0
170
+ }),
171
+ mode: "cors"
172
+ },
173
+ 3e4
174
+ );
175
+ if (!response.ok) {
176
+ const responseText = await response.text().catch(() => "");
177
+ throw new Error(`Relay setup request failed: ${response.status}${responseText ? ` ${responseText}` : ""}`);
178
+ }
179
+ return { status: "configured" };
180
+ } catch (error) {
181
+ if (isUnconfirmedNetworkError(error)) {
182
+ return { status: "unconfirmed" };
183
+ }
184
+ throw error;
185
+ }
186
+ }
123
187
  function messageTypeFromEnvelope(payload) {
124
188
  if (!payload) return null;
125
189
  const type = payload.type ?? payload.message?.type ?? (Array.isArray(payload.messages) ? payload.messages[0]?.type : void 0);
@@ -260,9 +324,11 @@ async function broadcastAlephMessage(message, apiHost = DEFAULT_ALEPH_API_HOST,
260
324
  function createAlephBrowserClient(options = {}) {
261
325
  const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
262
326
  const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
327
+ const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
263
328
  return {
264
329
  apiHost,
265
330
  crnListUrl,
331
+ schedulerApiHost,
266
332
  fetchBalance(address) {
267
333
  return fetchBalance(address, apiHost);
268
334
  },
@@ -276,7 +342,13 @@ function createAlephBrowserClient(options = {}) {
276
342
  return fetchMessageEnvelope(itemHash, apiHost);
277
343
  },
278
344
  fetchSchedulerAllocation(itemHash) {
279
- return fetchSchedulerAllocation(itemHash);
345
+ return fetchSchedulerAllocation(itemHash, schedulerApiHost);
346
+ },
347
+ notifyCrnAllocation(crnUrl, itemHash) {
348
+ return notifyCrnAllocation(crnUrl, itemHash);
349
+ },
350
+ configureOrbitdbRelaySetup(args) {
351
+ return configureOrbitdbRelaySetup(args);
280
352
  },
281
353
  inspectDeploymentResult(itemHash, rootfsRef) {
282
354
  return inspectDeploymentResult(itemHash, rootfsRef, apiHost);
@@ -513,6 +585,7 @@ export {
513
585
  ITEM_HASH_RE,
514
586
  broadcastAlephMessage,
515
587
  broadcastInstanceMessage,
588
+ configureOrbitdbRelaySetup,
516
589
  createAlephBrowserClient,
517
590
  fetchBalance,
518
591
  fetchCrns,
@@ -524,6 +597,7 @@ export {
524
597
  inspectDeploymentResult,
525
598
  loadRootfsManifest,
526
599
  normalizeMessageStatus,
600
+ notifyCrnAllocation,
527
601
  parseInstancePricing,
528
602
  resolveRootfsReference,
529
603
  validateRootfsManifest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",