@le-space/browser 0.1.30 → 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 +1 -0
- package/index.d.ts +5 -1
- package/index.js +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -209,6 +209,7 @@ interface AlephBrowserClient {
|
|
|
209
209
|
fetchBalance(address: string): Promise<BalanceResponse>;
|
|
210
210
|
fetchCrns(): Promise<Crn[]>;
|
|
211
211
|
fetchInstances(address: string): Promise<InstanceMessage[]>;
|
|
212
|
+
fetch2n6WebAccessUrl(itemHash: string): Promise<string | null>;
|
|
212
213
|
fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
|
|
213
214
|
fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
|
|
214
215
|
notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
@@ -261,10 +262,12 @@ declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit,
|
|
|
261
262
|
declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
262
263
|
declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
263
264
|
declare const DEFAULT_ALEPH_SCHEDULER_API_HOST = "https://scheduler.api.aleph.cloud";
|
|
265
|
+
declare const DEFAULT_2N6_API_HOST = "https://api.2n6.me";
|
|
264
266
|
declare function normalizeMessageStatus(status: unknown): MessageStatus;
|
|
265
267
|
declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
|
|
266
268
|
declare function fetchCrns(url?: string): Promise<Crn[]>;
|
|
267
269
|
declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
|
|
270
|
+
declare function fetch2n6WebAccessUrl(itemHash: string, twoN6ApiHost?: string): Promise<string | null>;
|
|
268
271
|
declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
|
|
269
272
|
declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
270
273
|
declare function configureOrbitdbRelaySetup(args: RelaySetupRequest): Promise<RelaySetupResult>;
|
|
@@ -278,6 +281,7 @@ interface CreateAlephBrowserClientOptions {
|
|
|
278
281
|
apiHost?: string;
|
|
279
282
|
crnListUrl?: string;
|
|
280
283
|
schedulerApiHost?: string;
|
|
284
|
+
twoN6ApiHost?: string;
|
|
281
285
|
}
|
|
282
286
|
declare function createAlephBrowserClient(options?: CreateAlephBrowserClientOptions): AlephBrowserClient;
|
|
283
287
|
|
|
@@ -296,4 +300,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
|
|
|
296
300
|
declare function parseInstancePricing(payload: unknown): InstancePricing;
|
|
297
301
|
declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
|
|
298
302
|
|
|
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 };
|
|
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"
|
|
@@ -325,6 +345,7 @@ function createAlephBrowserClient(options = {}) {
|
|
|
325
345
|
const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
|
|
326
346
|
const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
|
|
327
347
|
const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
|
|
348
|
+
const twoN6ApiHost = options.twoN6ApiHost ?? DEFAULT_2N6_API_HOST;
|
|
328
349
|
return {
|
|
329
350
|
apiHost,
|
|
330
351
|
crnListUrl,
|
|
@@ -338,6 +359,9 @@ function createAlephBrowserClient(options = {}) {
|
|
|
338
359
|
fetchInstances(address) {
|
|
339
360
|
return fetchInstances(address, apiHost);
|
|
340
361
|
},
|
|
362
|
+
fetch2n6WebAccessUrl(itemHash) {
|
|
363
|
+
return fetch2n6WebAccessUrl(itemHash, twoN6ApiHost);
|
|
364
|
+
},
|
|
341
365
|
fetchMessageEnvelope(itemHash) {
|
|
342
366
|
return fetchMessageEnvelope(itemHash, apiHost);
|
|
343
367
|
},
|
|
@@ -576,6 +600,7 @@ async function fetchInstancePricing(apiHost = DEFAULT_ALEPH_API_HOST, aggregateA
|
|
|
576
600
|
}
|
|
577
601
|
export {
|
|
578
602
|
BROWSER_PACKAGE_PLAN,
|
|
603
|
+
DEFAULT_2N6_API_HOST,
|
|
579
604
|
DEFAULT_ALEPH_AGGREGATE_ADDRESS,
|
|
580
605
|
DEFAULT_ALEPH_API_HOST,
|
|
581
606
|
DEFAULT_ALEPH_SCHEDULER_API_HOST,
|
|
@@ -587,6 +612,7 @@ export {
|
|
|
587
612
|
broadcastInstanceMessage,
|
|
588
613
|
configureOrbitdbRelaySetup,
|
|
589
614
|
createAlephBrowserClient,
|
|
615
|
+
fetch2n6WebAccessUrl,
|
|
590
616
|
fetchBalance,
|
|
591
617
|
fetchCrns,
|
|
592
618
|
fetchInstancePricing,
|