@neuraiproject/neurai-rpc 0.4.7 → 0.5.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/index.ts CHANGED
@@ -2,13 +2,9 @@ import { methods } from "./docs";
2
2
 
3
3
  export { methods };
4
4
 
5
- // Export DePIN RPC functionality
6
- export {
7
- getDePinRPC,
8
- requestDePinChallenge,
9
- type DePinAuthOptions,
10
- type DePinChallenge,
11
- } from "./depin";
5
+ // The DePIN client is Node.js-only (raw TCP against the gateway) and lives in
6
+ // its own entry so this root module stays free of Node built-ins and safe to
7
+ // bundle for the browser. Import it from "@neuraiproject/neurai-rpc/depin".
12
8
 
13
9
  function throwSyntaxError() {
14
10
  throw new Error("Syntax error, call getRPC with (username, password, URL)");
@@ -46,9 +42,17 @@ export function getRPC(username: string, password: string, URL: string) {
46
42
  */
47
43
 
48
44
  if (response.ok) {
49
- //Happy flow
50
45
  const obj = await response.json(); //Convert to JSON
51
- resolutionFunc(obj.result);
46
+ // A JSON-RPC error can arrive with HTTP 200 — it must reject,
47
+ // not resolve undefined.
48
+ if (obj && obj.error) {
49
+ rejectionFunc({
50
+ error: obj.error,
51
+ description: obj.error.message || "Unknown RPC error",
52
+ });
53
+ } else {
54
+ resolutionFunc(obj.result);
55
+ }
52
56
  } else if (response.status !== 200) {
53
57
  //OK something is wrong
54
58
  let obj = {