@le-space/browser 0.3.0 → 0.3.3

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.js CHANGED
@@ -329,6 +329,18 @@ function extractReferenceHashes(details) {
329
329
  if (!Array.isArray(errors)) return [];
330
330
  return errors.filter((value) => typeof value === "string");
331
331
  }
332
+ function extractInsufficientBalanceMessage(details) {
333
+ if (!details || typeof details !== "object" || !("errors" in details)) return null;
334
+ const errors = details.errors;
335
+ const firstError = Array.isArray(errors) && errors[0] && typeof errors[0] === "object" ? errors[0] : null;
336
+ const accountBalance = typeof firstError?.account_balance === "number" || typeof firstError?.account_balance === "string" ? Number(firstError.account_balance) : Number.NaN;
337
+ const requiredBalance = typeof firstError?.required_balance === "number" || typeof firstError?.required_balance === "string" ? Number(firstError.required_balance) : Number.NaN;
338
+ if (!Number.isFinite(accountBalance) || !Number.isFinite(requiredBalance)) {
339
+ return null;
340
+ }
341
+ const shortfall = requiredBalance - accountBalance;
342
+ return shortfall > 0 ? `insufficient Aleph balance: ${accountBalance.toFixed(3)} available, ${requiredBalance.toFixed(3)} required, ${shortfall.toFixed(3)} short` : `insufficient Aleph balance: ${accountBalance.toFixed(3)} available, ${requiredBalance.toFixed(3)} required`;
343
+ }
332
344
  function describeRejectedDeployment(payload, references, rootfsRef) {
333
345
  const errorCode = typeof payload.error_code === "number" ? payload.error_code : null;
334
346
  const pendingReferences = references.filter((reference) => reference.status === "pending");
@@ -343,6 +355,10 @@ function describeRejectedDeployment(payload, references, rootfsRef) {
343
355
  if (missingReferences.length > 0) {
344
356
  return `Aleph rejected this deployment because referenced message(s) were not found on Aleph: ${missingReferences.map((reference) => reference.itemHash).join(", ")}.`;
345
357
  }
358
+ const insufficientBalanceMessage = extractInsufficientBalanceMessage(payload.details);
359
+ if (insufficientBalanceMessage) {
360
+ return `Aleph rejected this deployment due to ${insufficientBalanceMessage}.`;
361
+ }
346
362
  const referencedHashes = extractReferenceHashes(payload.details);
347
363
  if (referencedHashes.length > 0) {
348
364
  return `Aleph rejected this deployment${errorCode ? ` (error ${errorCode})` : ""}. Referenced message(s): ${referencedHashes.join(", ")}.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/browser",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "Shared browser-safe Aleph deployment and polling helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
Binary file