@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/CHANGELOG.md +80 -0
- package/DEPIN_EXAMPLES.md +148 -220
- package/DEPIN_IMPLEMENTATION_GUIDE_EN.md +239 -70
- package/README.md +98 -46
- package/depin.ts +465 -214
- package/dist/depin.cjs +305 -0
- package/dist/depin.d.cts +96 -0
- package/dist/depin.d.ts +96 -0
- package/dist/depin.mjs +280 -0
- package/dist/index.cjs +5251 -4941
- package/dist/{types.d.ts → index.d.cts} +10 -63
- package/dist/index.d.ts +200 -0
- package/dist/index.mjs +5224 -4933
- package/docs.json +140 -134
- package/docs.ts +512 -64
- package/index.ts +13 -9
- package/neurai_methods.md +482 -64
- package/package.json +39 -11
- package/createDocs.mjs +0 -61
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/test-depin.ts +0 -187
- package/test.js +0 -56
- package/tsconfig.json +0 -26
package/index.ts
CHANGED
|
@@ -2,13 +2,9 @@ import { methods } from "./docs";
|
|
|
2
2
|
|
|
3
3
|
export { methods };
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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 = {
|