@caatinga/client 2.2.1 → 2.3.1

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
@@ -383,28 +383,62 @@ function splitReadArgsAndOptions(argsOrOptions, maybeOptions) {
383
383
  var import_browser5 = require("@caatinga/core/browser");
384
384
  async function prepareReadTransaction(transaction, contractName, method, rpcUrl) {
385
385
  const candidate = transaction;
386
- if (typeof candidate.prepare !== "function") {
387
- return transaction;
386
+ if (typeof candidate.prepare === "function") {
387
+ try {
388
+ return await candidate.prepare.call(transaction);
389
+ } catch (error) {
390
+ if (error instanceof import_browser5.CaatingaError) {
391
+ throw error;
392
+ }
393
+ throw new import_browser5.CaatingaError(
394
+ `Failed to prepare XDR for "${contractName}.${method}".`,
395
+ import_browser5.CaatingaErrorCode.XDR_PREPARE_FAILED,
396
+ `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
397
+ error
398
+ );
399
+ }
388
400
  }
389
- try {
390
- return await candidate.prepare.call(transaction);
391
- } catch (error) {
392
- if (error instanceof import_browser5.CaatingaError) {
393
- throw error;
401
+ if (typeof candidate.simulate === "function") {
402
+ try {
403
+ return await candidate.simulate.call(transaction);
404
+ } catch (error) {
405
+ if (error instanceof import_browser5.CaatingaError) {
406
+ throw error;
407
+ }
408
+ throw new import_browser5.CaatingaError(
409
+ `Failed to simulate "${contractName}.${method}".`,
410
+ import_browser5.CaatingaErrorCode.XDR_PREPARE_FAILED,
411
+ `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
412
+ error
413
+ );
394
414
  }
415
+ }
416
+ return transaction;
417
+ }
418
+ function isStellarContractResult(value) {
419
+ return value !== null && typeof value === "object" && typeof value.isOk === "function" && typeof value.unwrap === "function";
420
+ }
421
+ function normalizeSimulationValue(value, contractName, method) {
422
+ if (!isStellarContractResult(value)) {
423
+ return value;
424
+ }
425
+ if (value.isErr()) {
426
+ const err = value.unwrapErr();
427
+ const message = err !== null && typeof err === "object" && "message" in err ? String(err.message) : String(err);
395
428
  throw new import_browser5.CaatingaError(
396
- `Failed to prepare XDR for "${contractName}.${method}".`,
397
- import_browser5.CaatingaErrorCode.XDR_PREPARE_FAILED,
398
- `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
399
- error
429
+ `Simulation for "${contractName}.${method}" returned a contract error: ${message}.`,
430
+ import_browser5.CaatingaErrorCode.XDR_RESULT_FAILED,
431
+ "Check contract inputs and binding argument encoding.",
432
+ err
400
433
  );
401
434
  }
435
+ return value.unwrap();
402
436
  }
403
437
  function readSimulationResult(raw, contractName, method) {
404
438
  if (raw !== null && typeof raw === "object" && "result" in raw) {
405
439
  const result = raw.result;
406
440
  if (result !== void 0) {
407
- return result;
441
+ return normalizeSimulationValue(result, contractName, method);
408
442
  }
409
443
  }
410
444
  throw new import_browser5.CaatingaError(
package/dist/index.js CHANGED
@@ -193,28 +193,62 @@ function splitReadArgsAndOptions(argsOrOptions, maybeOptions) {
193
193
  import { CaatingaError as CaatingaError4, CaatingaErrorCode as CaatingaErrorCode4 } from "@caatinga/core/browser";
194
194
  async function prepareReadTransaction(transaction, contractName, method, rpcUrl) {
195
195
  const candidate = transaction;
196
- if (typeof candidate.prepare !== "function") {
197
- return transaction;
196
+ if (typeof candidate.prepare === "function") {
197
+ try {
198
+ return await candidate.prepare.call(transaction);
199
+ } catch (error) {
200
+ if (error instanceof CaatingaError4) {
201
+ throw error;
202
+ }
203
+ throw new CaatingaError4(
204
+ `Failed to prepare XDR for "${contractName}.${method}".`,
205
+ CaatingaErrorCode4.XDR_PREPARE_FAILED,
206
+ `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
207
+ error
208
+ );
209
+ }
198
210
  }
199
- try {
200
- return await candidate.prepare.call(transaction);
201
- } catch (error) {
202
- if (error instanceof CaatingaError4) {
203
- throw error;
211
+ if (typeof candidate.simulate === "function") {
212
+ try {
213
+ return await candidate.simulate.call(transaction);
214
+ } catch (error) {
215
+ if (error instanceof CaatingaError4) {
216
+ throw error;
217
+ }
218
+ throw new CaatingaError4(
219
+ `Failed to simulate "${contractName}.${method}".`,
220
+ CaatingaErrorCode4.XDR_PREPARE_FAILED,
221
+ `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
222
+ error
223
+ );
204
224
  }
225
+ }
226
+ return transaction;
227
+ }
228
+ function isStellarContractResult(value) {
229
+ return value !== null && typeof value === "object" && typeof value.isOk === "function" && typeof value.unwrap === "function";
230
+ }
231
+ function normalizeSimulationValue(value, contractName, method) {
232
+ if (!isStellarContractResult(value)) {
233
+ return value;
234
+ }
235
+ if (value.isErr()) {
236
+ const err = value.unwrapErr();
237
+ const message = err !== null && typeof err === "object" && "message" in err ? String(err.message) : String(err);
205
238
  throw new CaatingaError4(
206
- `Failed to prepare XDR for "${contractName}.${method}".`,
207
- CaatingaErrorCode4.XDR_PREPARE_FAILED,
208
- `RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
209
- error
239
+ `Simulation for "${contractName}.${method}" returned a contract error: ${message}.`,
240
+ CaatingaErrorCode4.XDR_RESULT_FAILED,
241
+ "Check contract inputs and binding argument encoding.",
242
+ err
210
243
  );
211
244
  }
245
+ return value.unwrap();
212
246
  }
213
247
  function readSimulationResult(raw, contractName, method) {
214
248
  if (raw !== null && typeof raw === "object" && "result" in raw) {
215
249
  const result = raw.result;
216
250
  if (result !== void 0) {
217
- return result;
251
+ return normalizeSimulationValue(result, contractName, method);
218
252
  }
219
253
  }
220
254
  throw new CaatingaError4(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caatinga/client",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "Browser and Node client for Soroban smart contracts — connects generated bindings, Caatinga artifacts, and wallet adapters",
5
5
  "keywords": [
6
6
  "stellar",
@@ -56,7 +56,7 @@
56
56
  "LICENSE"
57
57
  ],
58
58
  "dependencies": {
59
- "@caatinga/core": "^2.2.1"
59
+ "@caatinga/core": "^2.3.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "tsup": "^8.3.5",
@@ -89,7 +89,6 @@
89
89
  "scripts": {
90
90
  "build": "tsup src/index.ts src/freighter.ts src/stellar-wallets-kit.ts src/react.ts --format esm,cjs --dts",
91
91
  "test": "vitest run --pool=threads",
92
- "pretypecheck": "pnpm --filter @caatinga/core run build",
93
92
  "typecheck": "tsc --noEmit"
94
93
  }
95
94
  }