@hardkas/client 0.8.0-alpha
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/index.cjs +111 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +85 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javier Rodriguez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @hardkas/client
|
|
2
|
+
|
|
3
|
+
The official HTTP client for the HardKAS Dev Server.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> **DO NOT import `@hardkas/sdk` in the browser!**
|
|
7
|
+
> The main `@hardkas/sdk` package contains Node.js-specific native dependencies (like `fs`, `crypto`, and `better-sqlite3`) and will crash your web application.
|
|
8
|
+
>
|
|
9
|
+
> Always use `@hardkas/client` (or framework wrappers like `@hardkas/react`) to communicate with the HardKAS Dev Server.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Zero Dependencies**: Uses native `fetch` API.
|
|
14
|
+
- **Framework Agnostic**: Works with React, Vue, Angular, Svelte, or Vanilla JS.
|
|
15
|
+
- **Type-Safe**: Full TypeScript support with standardized `{ ok: true, data }` responses.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @hardkas/client
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createClient } from '@hardkas/client';
|
|
27
|
+
|
|
28
|
+
const client = createClient({
|
|
29
|
+
baseUrl: 'http://127.0.0.1:7420',
|
|
30
|
+
timeout: 5000,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
async function run() {
|
|
34
|
+
const response = await client.getWallet('alice');
|
|
35
|
+
if (response.ok) {
|
|
36
|
+
console.log('Wallet data:', response.data);
|
|
37
|
+
} else {
|
|
38
|
+
console.error('Error:', response.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
> [!NOTE]
|
|
44
|
+
> The Dev Server blocks mainnet transaction signing by default to protect your keys. It is intended for `simulated` local development.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
HardKASClient: () => HardKASClient,
|
|
24
|
+
createClient: () => createClient
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var HardKASClient = class {
|
|
28
|
+
baseUrl;
|
|
29
|
+
timeout;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.baseUrl = config?.baseUrl || "http://127.0.0.1:3000";
|
|
32
|
+
this.timeout = config?.timeout || 1e4;
|
|
33
|
+
}
|
|
34
|
+
async fetchWithTimeout(url, options) {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const id = setTimeout(() => controller.abort(), this.timeout);
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(url, {
|
|
39
|
+
...options,
|
|
40
|
+
signal: controller.signal
|
|
41
|
+
});
|
|
42
|
+
clearTimeout(id);
|
|
43
|
+
return response;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
clearTimeout(id);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async request(path, options) {
|
|
50
|
+
try {
|
|
51
|
+
const response = await this.fetchWithTimeout(`${this.baseUrl}${path}`, {
|
|
52
|
+
...options,
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
...options?.headers
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
return data;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error.name === "AbortError") {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
code: "TIMEOUT_ERROR",
|
|
65
|
+
message: `Request to ${path} timed out after ${this.timeout}ms.`
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
code: "NETWORK_ERROR",
|
|
71
|
+
message: error.message || "Unknown network error"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// --- API Endpoints ---
|
|
76
|
+
async getWallet(address) {
|
|
77
|
+
return this.request(`/api/wallet/${address}`);
|
|
78
|
+
}
|
|
79
|
+
async txPlan(payload) {
|
|
80
|
+
return this.request("/api/tx/plan", {
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: JSON.stringify(payload)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async txSimulate(payload) {
|
|
86
|
+
return this.request("/api/tx/simulate", {
|
|
87
|
+
method: "POST",
|
|
88
|
+
body: JSON.stringify(payload)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async txSign(payload) {
|
|
92
|
+
return this.request("/api/tx/sign", {
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: JSON.stringify(payload)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async txSend(payload) {
|
|
98
|
+
return this.request("/api/tx/send", {
|
|
99
|
+
method: "POST",
|
|
100
|
+
body: JSON.stringify(payload)
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function createClient(config) {
|
|
105
|
+
return new HardKASClient(config);
|
|
106
|
+
}
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
HardKASClient,
|
|
110
|
+
createClient
|
|
111
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface HardKASResponseSuccess<T> {
|
|
2
|
+
ok: true;
|
|
3
|
+
data: T;
|
|
4
|
+
}
|
|
5
|
+
interface HardKASResponseError {
|
|
6
|
+
ok: false;
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
details?: any;
|
|
10
|
+
}
|
|
11
|
+
type HardKASResponse<T> = HardKASResponseSuccess<T> | HardKASResponseError;
|
|
12
|
+
interface HardKASClientConfig {
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}
|
|
16
|
+
declare class HardKASClient {
|
|
17
|
+
private baseUrl;
|
|
18
|
+
private timeout;
|
|
19
|
+
constructor(config?: HardKASClientConfig);
|
|
20
|
+
private fetchWithTimeout;
|
|
21
|
+
private request;
|
|
22
|
+
getWallet(address: string): Promise<HardKASResponse<any>>;
|
|
23
|
+
txPlan(payload: any): Promise<HardKASResponse<any>>;
|
|
24
|
+
txSimulate(payload: any): Promise<HardKASResponse<any>>;
|
|
25
|
+
txSign(payload: any): Promise<HardKASResponse<any>>;
|
|
26
|
+
txSend(payload: any): Promise<HardKASResponse<any>>;
|
|
27
|
+
}
|
|
28
|
+
declare function createClient(config?: HardKASClientConfig): HardKASClient;
|
|
29
|
+
|
|
30
|
+
export { HardKASClient, type HardKASClientConfig, type HardKASResponse, type HardKASResponseError, type HardKASResponseSuccess, createClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface HardKASResponseSuccess<T> {
|
|
2
|
+
ok: true;
|
|
3
|
+
data: T;
|
|
4
|
+
}
|
|
5
|
+
interface HardKASResponseError {
|
|
6
|
+
ok: false;
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
details?: any;
|
|
10
|
+
}
|
|
11
|
+
type HardKASResponse<T> = HardKASResponseSuccess<T> | HardKASResponseError;
|
|
12
|
+
interface HardKASClientConfig {
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}
|
|
16
|
+
declare class HardKASClient {
|
|
17
|
+
private baseUrl;
|
|
18
|
+
private timeout;
|
|
19
|
+
constructor(config?: HardKASClientConfig);
|
|
20
|
+
private fetchWithTimeout;
|
|
21
|
+
private request;
|
|
22
|
+
getWallet(address: string): Promise<HardKASResponse<any>>;
|
|
23
|
+
txPlan(payload: any): Promise<HardKASResponse<any>>;
|
|
24
|
+
txSimulate(payload: any): Promise<HardKASResponse<any>>;
|
|
25
|
+
txSign(payload: any): Promise<HardKASResponse<any>>;
|
|
26
|
+
txSend(payload: any): Promise<HardKASResponse<any>>;
|
|
27
|
+
}
|
|
28
|
+
declare function createClient(config?: HardKASClientConfig): HardKASClient;
|
|
29
|
+
|
|
30
|
+
export { HardKASClient, type HardKASClientConfig, type HardKASResponse, type HardKASResponseError, type HardKASResponseSuccess, createClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var HardKASClient = class {
|
|
3
|
+
baseUrl;
|
|
4
|
+
timeout;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.baseUrl = config?.baseUrl || "http://127.0.0.1:3000";
|
|
7
|
+
this.timeout = config?.timeout || 1e4;
|
|
8
|
+
}
|
|
9
|
+
async fetchWithTimeout(url, options) {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const id = setTimeout(() => controller.abort(), this.timeout);
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
...options,
|
|
15
|
+
signal: controller.signal
|
|
16
|
+
});
|
|
17
|
+
clearTimeout(id);
|
|
18
|
+
return response;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
clearTimeout(id);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async request(path, options) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.fetchWithTimeout(`${this.baseUrl}${path}`, {
|
|
27
|
+
...options,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
...options?.headers
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
return data;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.name === "AbortError") {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
code: "TIMEOUT_ERROR",
|
|
40
|
+
message: `Request to ${path} timed out after ${this.timeout}ms.`
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
code: "NETWORK_ERROR",
|
|
46
|
+
message: error.message || "Unknown network error"
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// --- API Endpoints ---
|
|
51
|
+
async getWallet(address) {
|
|
52
|
+
return this.request(`/api/wallet/${address}`);
|
|
53
|
+
}
|
|
54
|
+
async txPlan(payload) {
|
|
55
|
+
return this.request("/api/tx/plan", {
|
|
56
|
+
method: "POST",
|
|
57
|
+
body: JSON.stringify(payload)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async txSimulate(payload) {
|
|
61
|
+
return this.request("/api/tx/simulate", {
|
|
62
|
+
method: "POST",
|
|
63
|
+
body: JSON.stringify(payload)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async txSign(payload) {
|
|
67
|
+
return this.request("/api/tx/sign", {
|
|
68
|
+
method: "POST",
|
|
69
|
+
body: JSON.stringify(payload)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async txSend(payload) {
|
|
73
|
+
return this.request("/api/tx/send", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: JSON.stringify(payload)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function createClient(config) {
|
|
80
|
+
return new HardKASClient(config);
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
HardKASClient,
|
|
84
|
+
createClient
|
|
85
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hardkas/client",
|
|
3
|
+
"version": "0.8.0-alpha",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"tsup": "^8.3.5",
|
|
14
|
+
"typescript": "^5.7.2"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Javier Rodriguez",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
}
|
|
26
|
+
}
|