@kushbitx/sdk 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -9,9 +9,9 @@ Zero-dependency ESM client and runnable Node.js example for the complete KushBit
9
9
  | Token market preview | Free | Inspect basic Base token market data without connecting a wallet. |
10
10
  | Data coverage check | Free | See which risk checks have enough evidence before buying a report. |
11
11
  | SpendGuard | Free pilot | Evaluate payment policy before money moves, with optional protected policies and human approval. |
12
- | Token-risk report | 0.25 USDC | Receive structured token-risk evidence with missing checks identified. |
13
- | Transaction preflight | 0.05 USDC | Inspect an unsigned Base transaction before signing. |
14
- | Payment verification | 0.01 USDC | Verify an existing Base USDC payment against the expected recipient and amount. |
12
+ | Token-risk report | 0.00098 USDC | Receive structured token-risk evidence with missing checks identified. |
13
+ | Transaction preflight | 0.00098 USDC | Inspect an unsigned Base transaction before signing. |
14
+ | Payment verification | 0.00288 USDC | Verify an existing Base USDC payment against the expected recipient and amount. |
15
15
 
16
16
  Paid endpoints use x402 and require explicit payment. There is no subscription. A delivered report can be `INCOMPLETE` when evidence is unavailable and may still incur the displayed fee.
17
17
 
@@ -62,11 +62,16 @@ import { KushBitxClient } from 'https://kushbitx.com/sdk/kushbitx.mjs';
62
62
  ## Links
63
63
 
64
64
  - Website: https://kushbitx.com
65
+ - Source: https://github.com/BHamim/kushbitx-sdk
65
66
  - Tools: https://kushbitx.com/#tools
66
67
  - SpendGuard: https://kushbitx.com/spendguard
67
68
  - Integration example: https://kushbitx.com/examples/agent.mjs
68
69
  - Contact: Admin@kushbitx.com
69
70
 
71
+ ## Community contributions
72
+
73
+ - [@mengxin10086](https://github.com/mengxin10086) built an independent MCP bridge for the free KushBitx endpoints. KushBitx reviewed and accepted commit `0e4d3226` ([source at that commit](https://github.com/mengxin10086/kushbitx-mcp-agent/tree/0e4d32267d4692d32cfb7c451d391cd59093a883)). It is third-party code, maintained by its author.
74
+
70
75
  ## Security
71
76
 
72
77
  Do not disclose suspected vulnerabilities in public issues. Report them privately to Admin@kushbitx.com.
package/kushbitx.mjs CHANGED
@@ -12,6 +12,17 @@ function required(value, name) {
12
12
  return value;
13
13
  }
14
14
 
15
+ function errorMessage(data) {
16
+ return data && typeof data === 'object' && typeof data.error === 'string' ? data.error : '';
17
+ }
18
+
19
+ // A success needs a JSON object body. null, arrays, scalars and invalid JSON are errors.
20
+ function jsonObject({ data, parseError }, status) {
21
+ if (parseError) throw new Error('KushBitx returned invalid JSON with HTTP ' + status, { cause: parseError });
22
+ if (data === null || typeof data !== 'object' || Array.isArray(data)) throw new Error('KushBitx returned an empty or non-object JSON body with HTTP ' + status);
23
+ return data;
24
+ }
25
+
15
26
  export class KushBitxClient {
16
27
  constructor({ baseUrl = 'https://kushbitx.com', fetchFn = globalThis.fetch } = {}) {
17
28
  if (typeof fetchFn !== 'function') throw new Error('A fetch implementation is required');
@@ -29,14 +40,22 @@ export class KushBitxClient {
29
40
  },
30
41
  ...(body === undefined ? {} : { body: JSON.stringify(body) })
31
42
  });
32
- const data = await response.json().catch(() => ({}));
33
- return { response, data };
43
+ // An unreadable body stays visible as data=null; it is never replaced by an empty object.
44
+ let data = null;
45
+ let parseError = null;
46
+ try {
47
+ data = await response.json();
48
+ } catch (error) {
49
+ parseError = error;
50
+ }
51
+ return { response, data, parseError };
34
52
  }
35
53
 
36
54
  async expect(path, options, statuses = [200]) {
37
55
  const result = await this.request(path, options);
38
- if (!statuses.includes(result.response.status)) throw new Error(result.data.error || 'KushBitx request failed with HTTP ' + result.response.status);
39
- return result.data;
56
+ const { status } = result.response;
57
+ if (!statuses.includes(status)) throw new Error(errorMessage(result.data) || 'KushBitx request failed with HTTP ' + status);
58
+ return jsonObject(result, status);
40
59
  }
41
60
 
42
61
  previewToken(address) {
@@ -75,8 +94,8 @@ export class KushBitxClient {
75
94
  const path = PAID_SERVICES[service];
76
95
  if (!path) throw new Error('Unknown paid service');
77
96
  const result = await this.request(path, { body: input });
78
- if (result.response.status !== 402) throw new Error(result.data.error || 'Expected an HTTP 402 payment challenge');
79
- return { service, path, challenge: result.data, paymentRequired: result.response.headers.get('PAYMENT-REQUIRED') };
97
+ if (result.response.status !== 402) throw new Error(errorMessage(result.data) || 'Expected an HTTP 402 payment challenge');
98
+ return { service, path, challenge: jsonObject(result, 402), paymentRequired: result.response.headers.get('PAYMENT-REQUIRED') };
80
99
  }
81
100
 
82
101
  prepareRecovery(service, input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kushbitx/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Zero-dependency ESM client for KushBitx AgentProof services on Base",
5
5
  "type": "module",
6
6
  "exports": "./kushbitx.mjs",
@@ -20,13 +20,14 @@
20
20
  "payment-security",
21
21
  "spendguard"
22
22
  ],
23
- "homepage": "https://kushbitx.com",
23
+ "homepage": "https://github.com/BHamim/kushbitx-sdk#readme",
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "https://github.com/kushBitxHQ/kushbitx-sdk"
26
+ "url": "git+https://github.com/BHamim/kushbitx-sdk.git"
27
27
  },
28
28
  "bugs": {
29
- "url": "https://github.com/kushBitxHQ/kushbitx-sdk/issues"
29
+ "url": "https://github.com/BHamim/kushbitx-sdk/issues",
30
+ "email": "admin@kushbitx.com"
30
31
  },
31
32
  "license": "Apache-2.0"
32
33
  }