@le-space/browser 0.1.22 → 0.1.23
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/index.d.ts +89 -2
- package/index.js +48 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -4,13 +4,100 @@ interface BrowserPackagePlan {
|
|
|
4
4
|
modules: string[];
|
|
5
5
|
}
|
|
6
6
|
declare const BROWSER_PACKAGE_PLAN: BrowserPackagePlan;
|
|
7
|
+
type MessageStatus = 'processed' | 'pending' | 'rejected' | 'unknown';
|
|
8
|
+
interface BalanceResponse {
|
|
9
|
+
address: string;
|
|
10
|
+
balance: string;
|
|
11
|
+
locked_amount: string;
|
|
12
|
+
details?: Record<string, string>;
|
|
13
|
+
credit_balance: number;
|
|
14
|
+
}
|
|
15
|
+
interface CrnUsage {
|
|
16
|
+
cpu?: {
|
|
17
|
+
count?: number;
|
|
18
|
+
};
|
|
19
|
+
mem?: {
|
|
20
|
+
available_kB?: number;
|
|
21
|
+
};
|
|
22
|
+
disk?: {
|
|
23
|
+
available_kB?: number;
|
|
24
|
+
};
|
|
25
|
+
active?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface CrnLocation {
|
|
28
|
+
city?: string | null;
|
|
29
|
+
region?: string | null;
|
|
30
|
+
country?: string | null;
|
|
31
|
+
country_code?: string | null;
|
|
32
|
+
}
|
|
33
|
+
interface Crn {
|
|
34
|
+
hash: string;
|
|
35
|
+
name: string;
|
|
36
|
+
address: string;
|
|
37
|
+
score?: number | string | null;
|
|
38
|
+
performance?: number | string | null;
|
|
39
|
+
decentralization?: number | string | null;
|
|
40
|
+
qemu_support?: boolean;
|
|
41
|
+
confidential_support?: boolean;
|
|
42
|
+
gpu_support?: boolean;
|
|
43
|
+
system_usage?: CrnUsage | null;
|
|
44
|
+
payment_receiver_address?: string | null;
|
|
45
|
+
version?: string | null;
|
|
46
|
+
city?: string | null;
|
|
47
|
+
region?: string | null;
|
|
48
|
+
country?: string | null;
|
|
49
|
+
country_code?: string | null;
|
|
50
|
+
location?: CrnLocation | string | null;
|
|
51
|
+
resolved_ip?: string | null;
|
|
52
|
+
geo_source?: string | null;
|
|
53
|
+
}
|
|
54
|
+
interface CrnListResponse {
|
|
55
|
+
crns: Crn[];
|
|
56
|
+
}
|
|
57
|
+
type PaymentMode = 'hold' | 'credit';
|
|
58
|
+
interface InstanceMessage {
|
|
59
|
+
item_hash: string;
|
|
60
|
+
sender: string;
|
|
61
|
+
chain: string;
|
|
62
|
+
type: 'INSTANCE';
|
|
63
|
+
channel?: string;
|
|
64
|
+
content?: {
|
|
65
|
+
metadata?: {
|
|
66
|
+
name?: string;
|
|
67
|
+
};
|
|
68
|
+
payment?: {
|
|
69
|
+
type?: PaymentMode;
|
|
70
|
+
chain?: string;
|
|
71
|
+
};
|
|
72
|
+
rootfs?: {
|
|
73
|
+
parent?: {
|
|
74
|
+
ref?: string;
|
|
75
|
+
};
|
|
76
|
+
size_mib?: number;
|
|
77
|
+
};
|
|
78
|
+
requirements?: {
|
|
79
|
+
node?: {
|
|
80
|
+
node_hash?: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
time?: string | number;
|
|
85
|
+
reception_time?: string;
|
|
86
|
+
confirmed?: boolean;
|
|
87
|
+
status?: string;
|
|
88
|
+
}
|
|
7
89
|
|
|
8
90
|
declare function fetchWithTimeout(input: RequestInfo | URL, init?: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
9
91
|
|
|
10
|
-
declare const
|
|
92
|
+
declare const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
93
|
+
declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
94
|
+
declare function normalizeMessageStatus(status: unknown): MessageStatus;
|
|
95
|
+
declare function fetchBalance(address: string, apiHost?: string): Promise<BalanceResponse>;
|
|
96
|
+
declare function fetchCrns(url?: string): Promise<Crn[]>;
|
|
97
|
+
declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
|
|
11
98
|
|
|
12
99
|
declare const BROWSER_ROOTFS_MODULE = "planned";
|
|
13
100
|
|
|
14
101
|
declare const BROWSER_PRICING_MODULE = "planned";
|
|
15
102
|
|
|
16
|
-
export {
|
|
103
|
+
export { BROWSER_PACKAGE_PLAN, BROWSER_PRICING_MODULE, BROWSER_ROOTFS_MODULE, type BalanceResponse, type BrowserExtractionPhase, type BrowserPackagePlan, type Crn, type CrnListResponse, type CrnLocation, type CrnUsage, DEFAULT_ALEPH_API_HOST, DEFAULT_CRN_LIST_URL, type InstanceMessage, type MessageStatus, type PaymentMode, fetchBalance, fetchCrns, fetchInstances, fetchWithTimeout, normalizeMessageStatus };
|
package/index.js
CHANGED
|
@@ -34,7 +34,47 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15e3) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// src/aleph-api.ts
|
|
37
|
-
var
|
|
37
|
+
var DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
38
|
+
var DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
|
|
39
|
+
function normalizeMessageStatus(status) {
|
|
40
|
+
if (typeof status !== "string") return "unknown";
|
|
41
|
+
const normalized = status.toLowerCase();
|
|
42
|
+
if (normalized === "processed" || normalized === "pending" || normalized === "rejected") {
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
return "unknown";
|
|
46
|
+
}
|
|
47
|
+
async function fetchBalance(address, apiHost = DEFAULT_ALEPH_API_HOST) {
|
|
48
|
+
const response = await fetchWithTimeout(`${apiHost}/api/v0/addresses/${address}/balance`, {
|
|
49
|
+
cache: "no-cache"
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) throw new Error(`Balance request failed: ${response.status}`);
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
async function fetchCrns(url = DEFAULT_CRN_LIST_URL) {
|
|
55
|
+
const requestUrl = new URL(url);
|
|
56
|
+
requestUrl.searchParams.set("filter_inactive", "true");
|
|
57
|
+
const response = await fetchWithTimeout(requestUrl, { cache: "no-cache" });
|
|
58
|
+
if (!response.ok) throw new Error(`CRN list request failed: ${response.status}`);
|
|
59
|
+
const payload = await response.json();
|
|
60
|
+
return payload.crns ?? [];
|
|
61
|
+
}
|
|
62
|
+
async function fetchInstances(address, apiHost = DEFAULT_ALEPH_API_HOST) {
|
|
63
|
+
const url = new URL("/api/v0/messages.json", apiHost);
|
|
64
|
+
url.searchParams.set("msgTypes", "INSTANCE");
|
|
65
|
+
url.searchParams.set("addresses", address);
|
|
66
|
+
url.searchParams.set("message_statuses", "processed,pending,rejected,removing");
|
|
67
|
+
url.searchParams.set("pagination", "100");
|
|
68
|
+
url.searchParams.set("page", "1");
|
|
69
|
+
url.searchParams.set("sortOrder", "-1");
|
|
70
|
+
const response = await fetchWithTimeout(url, { cache: "no-cache" });
|
|
71
|
+
if (!response.ok) throw new Error(`Instance list request failed: ${response.status}`);
|
|
72
|
+
const payload = await response.json();
|
|
73
|
+
return (payload.messages ?? []).map((message) => ({
|
|
74
|
+
...message,
|
|
75
|
+
status: typeof message.status === "string" && message.status.trim() ? message.status : message.confirmed ? "processed" : message.status
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
38
78
|
|
|
39
79
|
// src/rootfs.ts
|
|
40
80
|
var BROWSER_ROOTFS_MODULE = "planned";
|
|
@@ -42,9 +82,14 @@ var BROWSER_ROOTFS_MODULE = "planned";
|
|
|
42
82
|
// src/pricing.ts
|
|
43
83
|
var BROWSER_PRICING_MODULE = "planned";
|
|
44
84
|
export {
|
|
45
|
-
BROWSER_ALEPH_API_MODULE,
|
|
46
85
|
BROWSER_PACKAGE_PLAN,
|
|
47
86
|
BROWSER_PRICING_MODULE,
|
|
48
87
|
BROWSER_ROOTFS_MODULE,
|
|
49
|
-
|
|
88
|
+
DEFAULT_ALEPH_API_HOST,
|
|
89
|
+
DEFAULT_CRN_LIST_URL,
|
|
90
|
+
fetchBalance,
|
|
91
|
+
fetchCrns,
|
|
92
|
+
fetchInstances,
|
|
93
|
+
fetchWithTimeout,
|
|
94
|
+
normalizeMessageStatus
|
|
50
95
|
};
|