@medialane/sdk 0.119.1 → 0.119.2

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.
@@ -12029,10 +12029,14 @@ function mintedTokenIdFromReceipt(receipt, contract) {
12029
12029
  // src/starknet/services/sponsoredExecutor.ts
12030
12030
  var SponsoredCallRejectedError = class extends Error {
12031
12031
  };
12032
- var SPONSOR_UNAVAILABLE_STATUS = 503;
12033
- async function errorReason(res, fallback) {
12032
+ var USER_MAY_PAY = /* @__PURE__ */ new Set(["sponsor_unavailable", "credits_exhausted"]);
12033
+ function userMayPayInstead(code, status, stage) {
12034
+ if (code) return USER_MAY_PAY.has(code);
12035
+ return stage === "build" ? status >= 500 : status === 503;
12036
+ }
12037
+ async function failureOf(res, fallback) {
12034
12038
  const body = await res.json().catch(() => null);
12035
- return body?.error || fallback;
12039
+ return { reason: body?.error || fallback, code: typeof body?.code === "string" ? body.code : void 0 };
12036
12040
  }
12037
12041
  async function executeSponsored(config, signer, calls) {
12038
12042
  const doFetch = config.fetchImpl ?? fetch;
@@ -12043,8 +12047,8 @@ async function executeSponsored(config, signer, calls) {
12043
12047
  body: JSON.stringify({ userAddress: signer.address, calls })
12044
12048
  });
12045
12049
  if (!buildRes.ok) {
12046
- const reason = await errorReason(buildRes, "We couldn't prepare this transaction.");
12047
- if (buildRes.status >= 500) return { status: "unavailable", reason };
12050
+ const { reason, code } = await failureOf(buildRes, "We couldn't prepare this transaction.");
12051
+ if (userMayPayInstead(code, buildRes.status, "build")) return { status: "unavailable", reason };
12048
12052
  throw new SponsoredCallRejectedError(reason);
12049
12053
  }
12050
12054
  const { typedData } = await buildRes.json();
@@ -12055,8 +12059,8 @@ async function executeSponsored(config, signer, calls) {
12055
12059
  body: JSON.stringify({ userAddress: signer.address, typedData, signature, calls })
12056
12060
  });
12057
12061
  if (!executeRes.ok) {
12058
- const reason = await errorReason(executeRes, "We couldn't submit this transaction.");
12059
- if (executeRes.status === SPONSOR_UNAVAILABLE_STATUS) {
12062
+ const { reason, code } = await failureOf(executeRes, "We couldn't submit this transaction.");
12063
+ if (userMayPayInstead(code, executeRes.status, "execute")) {
12060
12064
  return { status: "unavailable", reason };
12061
12065
  }
12062
12066
  throw new SponsoredCallRejectedError(reason);
@@ -12430,6 +12434,7 @@ exports.syncTransactionBestEffort = syncTransactionBestEffort;
12430
12434
  exports.teamCoinsRaw = teamCoinsRaw;
12431
12435
  exports.toDropContractConditions = toContractConditions;
12432
12436
  exports.unsealPrivateKey = unsealPrivateKey;
12437
+ exports.userMayPayInstead = userMayPayInstead;
12433
12438
  exports.validateCoinName = validateName;
12434
12439
  exports.validateCoinSupply = validateSupply;
12435
12440
  exports.validateCoinSymbol = validateSymbol;