@le-space/browser 0.1.28 → 0.1.29
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 +8 -1
- package/index.js +34 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -161,6 +161,9 @@ interface InstanceAllocation {
|
|
|
161
161
|
vmIpv6?: string | null;
|
|
162
162
|
period?: InstanceAllocationPeriod | null;
|
|
163
163
|
}
|
|
164
|
+
interface AllocationNotifyResult {
|
|
165
|
+
status: 'confirmed' | 'unconfirmed';
|
|
166
|
+
}
|
|
164
167
|
interface AlephBroadcastMessage {
|
|
165
168
|
sender: string;
|
|
166
169
|
chain: AlephSenderChain;
|
|
@@ -187,11 +190,13 @@ interface BroadcastResult {
|
|
|
187
190
|
interface AlephBrowserClient {
|
|
188
191
|
apiHost: string;
|
|
189
192
|
crnListUrl: string;
|
|
193
|
+
schedulerApiHost: string;
|
|
190
194
|
fetchBalance(address: string): Promise<BalanceResponse>;
|
|
191
195
|
fetchCrns(): Promise<Crn[]>;
|
|
192
196
|
fetchInstances(address: string): Promise<InstanceMessage[]>;
|
|
193
197
|
fetchMessageEnvelope(itemHash: string): Promise<AlephMessageEnvelope | null>;
|
|
194
198
|
fetchSchedulerAllocation(itemHash: string): Promise<InstanceAllocation | null>;
|
|
199
|
+
notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
195
200
|
inspectDeploymentResult(itemHash: string, rootfsRef?: string): Promise<DeploymentInspectionResult>;
|
|
196
201
|
waitForDeploymentResult(itemHash: string, rootfsRef?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
|
|
197
202
|
broadcastInstanceMessage(message: AlephBroadcastMessage, sync?: boolean): Promise<BroadcastResult>;
|
|
@@ -245,6 +250,7 @@ declare function fetchBalance(address: string, apiHost?: string): Promise<Balanc
|
|
|
245
250
|
declare function fetchCrns(url?: string): Promise<Crn[]>;
|
|
246
251
|
declare function fetchInstances(address: string, apiHost?: string): Promise<InstanceMessage[]>;
|
|
247
252
|
declare function fetchSchedulerAllocation(itemHash: string, schedulerApiHost?: string): Promise<InstanceAllocation | null>;
|
|
253
|
+
declare function notifyCrnAllocation(crnUrl: string, itemHash: string): Promise<AllocationNotifyResult>;
|
|
248
254
|
declare function fetchMessageEnvelope(itemHash: string, apiHost?: string): Promise<AlephMessageEnvelope | null>;
|
|
249
255
|
declare function inspectDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string): Promise<DeploymentInspectionResult>;
|
|
250
256
|
declare function waitForDeploymentResult(itemHash: string, rootfsRef?: string, apiHost?: string, attempts?: number, delayMs?: number): Promise<DeploymentInspectionResult>;
|
|
@@ -254,6 +260,7 @@ declare function broadcastAlephMessage(message: AlephBroadcastMessage, apiHost?:
|
|
|
254
260
|
interface CreateAlephBrowserClientOptions {
|
|
255
261
|
apiHost?: string;
|
|
256
262
|
crnListUrl?: string;
|
|
263
|
+
schedulerApiHost?: string;
|
|
257
264
|
}
|
|
258
265
|
declare function createAlephBrowserClient(options?: CreateAlephBrowserClientOptions): AlephBrowserClient;
|
|
259
266
|
|
|
@@ -272,4 +279,4 @@ declare const DEFAULT_ALEPH_AGGREGATE_ADDRESS = "0xFba561a84A537fCaa567bb7A2257e
|
|
|
272
279
|
declare function parseInstancePricing(payload: unknown): InstancePricing;
|
|
273
280
|
declare function fetchInstancePricing(apiHost?: string, aggregateAddress?: string): Promise<PricingState>;
|
|
274
281
|
|
|
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 };
|
|
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 };
|
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,29 @@ 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
|
+
}
|
|
123
150
|
function messageTypeFromEnvelope(payload) {
|
|
124
151
|
if (!payload) return null;
|
|
125
152
|
const type = payload.type ?? payload.message?.type ?? (Array.isArray(payload.messages) ? payload.messages[0]?.type : void 0);
|
|
@@ -260,9 +287,11 @@ async function broadcastAlephMessage(message, apiHost = DEFAULT_ALEPH_API_HOST,
|
|
|
260
287
|
function createAlephBrowserClient(options = {}) {
|
|
261
288
|
const apiHost = options.apiHost ?? DEFAULT_ALEPH_API_HOST;
|
|
262
289
|
const crnListUrl = options.crnListUrl ?? DEFAULT_CRN_LIST_URL;
|
|
290
|
+
const schedulerApiHost = options.schedulerApiHost ?? DEFAULT_ALEPH_SCHEDULER_API_HOST;
|
|
263
291
|
return {
|
|
264
292
|
apiHost,
|
|
265
293
|
crnListUrl,
|
|
294
|
+
schedulerApiHost,
|
|
266
295
|
fetchBalance(address) {
|
|
267
296
|
return fetchBalance(address, apiHost);
|
|
268
297
|
},
|
|
@@ -276,7 +305,10 @@ function createAlephBrowserClient(options = {}) {
|
|
|
276
305
|
return fetchMessageEnvelope(itemHash, apiHost);
|
|
277
306
|
},
|
|
278
307
|
fetchSchedulerAllocation(itemHash) {
|
|
279
|
-
return fetchSchedulerAllocation(itemHash);
|
|
308
|
+
return fetchSchedulerAllocation(itemHash, schedulerApiHost);
|
|
309
|
+
},
|
|
310
|
+
notifyCrnAllocation(crnUrl, itemHash) {
|
|
311
|
+
return notifyCrnAllocation(crnUrl, itemHash);
|
|
280
312
|
},
|
|
281
313
|
inspectDeploymentResult(itemHash, rootfsRef) {
|
|
282
314
|
return inspectDeploymentResult(itemHash, rootfsRef, apiHost);
|
|
@@ -524,6 +556,7 @@ export {
|
|
|
524
556
|
inspectDeploymentResult,
|
|
525
557
|
loadRootfsManifest,
|
|
526
558
|
normalizeMessageStatus,
|
|
559
|
+
notifyCrnAllocation,
|
|
527
560
|
parseInstancePricing,
|
|
528
561
|
resolveRootfsReference,
|
|
529
562
|
validateRootfsManifest,
|