@calimero-network/mero-js 26.0.1 → 26.1.0

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/dist/index.cjs CHANGED
@@ -1463,6 +1463,25 @@ function isSettled(outcome) {
1463
1463
  function shouldRetain(outcome) {
1464
1464
  return !isSettled(outcome);
1465
1465
  }
1466
+ var REASON_FOR_CODE = {
1467
+ invitation_expired: "expired",
1468
+ invitation_invalid: "invalid",
1469
+ invitation_already_used: "already-used",
1470
+ removed_from_group: "removed",
1471
+ reentry_blocked: "refused"
1472
+ };
1473
+ function refusalCodeOf(err) {
1474
+ if (!err || typeof err !== "object") return void 0;
1475
+ const shaped = err;
1476
+ if (typeof shaped.response?.data?.code === "string") return shaped.response.data.code;
1477
+ if (typeof shaped.bodyText !== "string") return void 0;
1478
+ try {
1479
+ const body = JSON.parse(shaped.bodyText);
1480
+ return typeof body?.code === "string" ? body.code : void 0;
1481
+ } catch {
1482
+ return void 0;
1483
+ }
1484
+ }
1466
1485
  function reasonFromMessage(message) {
1467
1486
  const m = message.toLowerCase();
1468
1487
  if (m.includes("invitation has expired") || m.includes("invitation expired") || // Core rc.56+ names the group between the words: "invitation for group
@@ -1473,11 +1492,19 @@ function reasonFromMessage(message) {
1473
1492
  if (m.includes("malformed") || m.includes("does not match namespace_id") || m.includes("invalid invitation") || /\binvitation for group .+? is invalid:/.test(m)) {
1474
1493
  return "invalid";
1475
1494
  }
1495
+ if (m.includes("has already used this invitation")) return "already-used";
1496
+ if (/\bwas removed from group\b/.test(m)) return "removed";
1476
1497
  return null;
1477
1498
  }
1499
+ var FINAL_FROM_TEXT = /* @__PURE__ */ new Set(["already-used", "removed"]);
1478
1500
  function classifyJoinFailure(err, message) {
1479
1501
  const { kind, status } = classifyError(err);
1480
1502
  const fromText = reasonFromMessage(message);
1503
+ const code = refusalCodeOf(err);
1504
+ const fromCode = code ? REASON_FOR_CODE[code] : void 0;
1505
+ if (fromCode) return { reason: fromCode, retryable: false };
1506
+ if (fromText && FINAL_FROM_TEXT.has(fromText)) return { reason: fromText, retryable: false };
1507
+ if (code === "join_refused_by_member") return { reason: "unknown", retryable: true };
1481
1508
  if (status === 401) return { reason: "signed-out", retryable: true };
1482
1509
  if (status === 400) return { reason: fromText ?? "invalid", retryable: false };
1483
1510
  if (status === 410) return { reason: "expired", retryable: false };