@chainnew/client 0.4.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/README.md +30 -0
- package/dist/client.d.ts +78 -0
- package/dist/client.js +143 -0
- package/dist/generated.d.ts +1654 -0
- package/dist/generated.js +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/package.json +38 -0
- package/src/client.ts +189 -0
- package/src/generated.ts +1658 -0
- package/src/index.ts +6 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HyperClient, HyperApiError } from "./client";
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chainnew/client",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Generated TypeScript client for hyper.chain.new API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/chainnew/hyper.chain.new.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/chainnew/hyper.chain.new",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/chainnew/hyper.chain.new/issues"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src/generated.ts",
|
|
17
|
+
"src/client.ts",
|
|
18
|
+
"src/index.ts",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"generate": "../scripts/generate-clients.sh",
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"prepack": "npm run build",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// AUTO-GENERATED from docs/api/openapi.yaml — do not edit manually.
|
|
2
|
+
// Regenerate: ./scripts/generate-clients.sh
|
|
3
|
+
|
|
4
|
+
import type { components } from "./generated";
|
|
5
|
+
|
|
6
|
+
/** API error with status code and typed body. */
|
|
7
|
+
export class HyperApiError extends Error {
|
|
8
|
+
constructor(
|
|
9
|
+
public readonly status: number,
|
|
10
|
+
public readonly body: components["schemas"]["ErrorResponse"],
|
|
11
|
+
) {
|
|
12
|
+
super(`${body.error}: ${body.message}`);
|
|
13
|
+
this.name = "HyperApiError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Configuration for the HyperClient. */
|
|
18
|
+
export interface HyperClientConfig {
|
|
19
|
+
/** Base URL of the hyper.chain.new API (e.g. https://localhost:8443). */
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
/** Auth credentials injected into every request. */
|
|
22
|
+
auth?:
|
|
23
|
+
| { type: "bearer"; token: string }
|
|
24
|
+
| { type: "serviceToken"; token: string };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Typed HTTP client for the hyper.chain.new API. Uses native fetch. */
|
|
28
|
+
export class HyperClient {
|
|
29
|
+
private readonly baseUrl: string;
|
|
30
|
+
private readonly auth: HyperClientConfig["auth"];
|
|
31
|
+
|
|
32
|
+
constructor(config: HyperClientConfig) {
|
|
33
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
34
|
+
this.auth = config.auth;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private headers(): Record<string, string> {
|
|
38
|
+
const h: Record<string, string> = { "Content-Type": "application/json" };
|
|
39
|
+
if (this.auth) {
|
|
40
|
+
if (this.auth.type === "bearer") {
|
|
41
|
+
h.Authorization = `Bearer ${this.auth.token}`;
|
|
42
|
+
} else {
|
|
43
|
+
h["x-service-token"] = this.auth.token;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return h;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
50
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
51
|
+
method,
|
|
52
|
+
headers: this.headers(),
|
|
53
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const errBody = (await res.json()) as components["schemas"]["ErrorResponse"];
|
|
57
|
+
throw new HyperApiError(res.status, errBody);
|
|
58
|
+
}
|
|
59
|
+
return (await res.json()) as T;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// --- generated methods ------------------------------------------------
|
|
63
|
+
|
|
64
|
+
/** POST /api/v1/auth/bootstrap */
|
|
65
|
+
async authBootstrap(body: components["schemas"]["BootstrapAuthRequest"]): Promise<components["schemas"]["TokenResponse"]> {
|
|
66
|
+
return this.request<components["schemas"]["TokenResponse"]>("POST", "/api/v1/auth/bootstrap", body);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** POST /api/v1/auth/rotate */
|
|
70
|
+
async authRotate(): Promise<components["schemas"]["TokenResponse"]> {
|
|
71
|
+
return this.request<components["schemas"]["TokenResponse"]>("POST", "/api/v1/auth/rotate");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** POST /api/v1/auth/service-token */
|
|
75
|
+
async authServiceToken(body: components["schemas"]["ServiceTokenRequest"]): Promise<components["schemas"]["TokenResponse"]> {
|
|
76
|
+
return this.request<components["schemas"]["TokenResponse"]>("POST", "/api/v1/auth/service-token", body);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** POST /api/v1/cyber/session/create */
|
|
80
|
+
async cyberSessionCreate(body: components["schemas"]["CyberSessionCreateRequest"]): Promise<components["schemas"]["CyberSessionResponse"]> {
|
|
81
|
+
return this.request<components["schemas"]["CyberSessionResponse"]>("POST", "/api/v1/cyber/session/create", body);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** DELETE /api/v1/cyber/session/{session_id}/artifacts/{sample_id} */
|
|
85
|
+
async cyberArtifactDelete(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]> {
|
|
86
|
+
return this.request<components["schemas"]["CyberArtifactActionResponse"]>("DELETE", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/pin */
|
|
90
|
+
async cyberArtifactPin(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]> {
|
|
91
|
+
return this.request<components["schemas"]["CyberArtifactActionResponse"]>("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}/pin`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/unpin */
|
|
95
|
+
async cyberArtifactUnpin(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]> {
|
|
96
|
+
return this.request<components["schemas"]["CyberArtifactActionResponse"]>("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}/unpin`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** POST /api/v1/cyber/session/{session_id}/ingest */
|
|
100
|
+
async cyberSampleIngest(session_id: string, body: components["schemas"]["CyberIngestRequest"]): Promise<components["schemas"]["CyberArtifactResponse"]> {
|
|
101
|
+
return this.request<components["schemas"]["CyberArtifactResponse"]>("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/ingest`, body);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** GET /api/v1/image-cache/status */
|
|
105
|
+
async imageCacheStatus(): Promise<components["schemas"]["ImageCacheStatus"]> {
|
|
106
|
+
return this.request<components["schemas"]["ImageCacheStatus"]>("GET", "/api/v1/image-cache/status");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** GET /api/v1/operations */
|
|
110
|
+
async operationsList(): Promise<components["schemas"]["OperationsPageResponse"]> {
|
|
111
|
+
return this.request<components["schemas"]["OperationsPageResponse"]>("GET", "/api/v1/operations");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** GET /api/v1/operations/failed */
|
|
115
|
+
async operationsFailed(): Promise<components["schemas"]["DlqPageResponse"]> {
|
|
116
|
+
return this.request<components["schemas"]["DlqPageResponse"]>("GET", "/api/v1/operations/failed");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** GET /api/v1/ops/{id} */
|
|
120
|
+
async operationStatus(id: string): Promise<components["schemas"]["OperationRecord"]> {
|
|
121
|
+
return this.request<components["schemas"]["OperationRecord"]>("GET", `/api/v1/ops/${encodeURIComponent(id)}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** GET /api/v1/service/ping */
|
|
125
|
+
async servicePing(): Promise<components["schemas"]["ServicePingResponse"]> {
|
|
126
|
+
return this.request<components["schemas"]["ServicePingResponse"]>("GET", "/api/v1/service/ping");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** POST /api/v1/snapshot/{id}/clone */
|
|
130
|
+
async snapshotClone(id: string, body: components["schemas"]["SnapshotCloneHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]> {
|
|
131
|
+
return this.request<components["schemas"]["SnapshotResponse"]>("POST", `/api/v1/snapshot/${encodeURIComponent(id)}/clone`, body);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** POST /api/v1/snapshot/{id}/restore */
|
|
135
|
+
async snapshotRestore(id: string, body: components["schemas"]["SnapshotRestoreHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]> {
|
|
136
|
+
return this.request<components["schemas"]["SnapshotResponse"]>("POST", `/api/v1/snapshot/${encodeURIComponent(id)}/restore`, body);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** GET /api/v1/system/safety */
|
|
140
|
+
async systemSafety(): Promise<components["schemas"]["SystemSafety"]> {
|
|
141
|
+
return this.request<components["schemas"]["SystemSafety"]>("GET", "/api/v1/system/safety");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** GET /api/v1/ui/state */
|
|
145
|
+
async uiState(): Promise<components["schemas"]["UiState"]> {
|
|
146
|
+
return this.request<components["schemas"]["UiState"]>("GET", "/api/v1/ui/state");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** POST /api/v1/vault/prepare-operation */
|
|
150
|
+
async vaultPrepareOperation(body: components["schemas"]["PrepareOperationRequest"]): Promise<components["schemas"]["PrepareOperationResponse"]> {
|
|
151
|
+
return this.request<components["schemas"]["PrepareOperationResponse"]>("POST", "/api/v1/vault/prepare-operation", body);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** POST /api/v1/vm/create */
|
|
155
|
+
async vmCreate(body: components["schemas"]["CreateVmRequest"]): Promise<components["schemas"]["OperationRecord"]> {
|
|
156
|
+
return this.request<components["schemas"]["OperationRecord"]>("POST", "/api/v1/vm/create", body);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** POST /api/v1/vm/{id}/destroy */
|
|
160
|
+
async vmDestroy(id: string): Promise<components["schemas"]["OperationRecord"]> {
|
|
161
|
+
return this.request<components["schemas"]["OperationRecord"]>("POST", `/api/v1/vm/${encodeURIComponent(id)}/destroy`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** POST /api/v1/vm/{id}/snapshot */
|
|
165
|
+
async snapshotCreate(id: string, body: components["schemas"]["SnapshotCreateHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]> {
|
|
166
|
+
return this.request<components["schemas"]["SnapshotResponse"]>("POST", `/api/v1/vm/${encodeURIComponent(id)}/snapshot`, body);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** GET /api/v1/vm/{id}/snapshots */
|
|
170
|
+
async snapshotList(id: string): Promise<components["schemas"]["SnapshotPageResponse"]> {
|
|
171
|
+
return this.request<components["schemas"]["SnapshotPageResponse"]>("GET", `/api/v1/vm/${encodeURIComponent(id)}/snapshots`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** POST /api/v1/vm/{id}/start */
|
|
175
|
+
async vmStart(id: string): Promise<components["schemas"]["OperationRecord"]> {
|
|
176
|
+
return this.request<components["schemas"]["OperationRecord"]>("POST", `/api/v1/vm/${encodeURIComponent(id)}/start`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** POST /api/v1/vm/{id}/stop */
|
|
180
|
+
async vmStop(id: string): Promise<components["schemas"]["OperationRecord"]> {
|
|
181
|
+
return this.request<components["schemas"]["OperationRecord"]>("POST", `/api/v1/vm/${encodeURIComponent(id)}/stop`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** GET /health */
|
|
185
|
+
async health(): Promise<components["schemas"]["HealthResponse"]> {
|
|
186
|
+
return this.request<components["schemas"]["HealthResponse"]>("GET", "/health");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
}
|