@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 ADDED
@@ -0,0 +1,30 @@
1
+ # @chainnew/client
2
+
3
+ Typed TypeScript client for the `hyper.chain.new` control-plane API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @chainnew/client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { HyperClient } from "@chainnew/client";
15
+
16
+ const client = new HyperClient({
17
+ baseUrl: "http://127.0.0.1:9090",
18
+ });
19
+
20
+ const health = await client.health();
21
+ console.log(health.status, health.api_version);
22
+ ```
23
+
24
+ ## Regeneration
25
+
26
+ `src/generated.ts` and `src/client.ts` are generated from `docs/api/openapi.yaml`:
27
+
28
+ ```bash
29
+ ./scripts/generate-clients.sh
30
+ ```
@@ -0,0 +1,78 @@
1
+ import type { components } from "./generated";
2
+ /** API error with status code and typed body. */
3
+ export declare class HyperApiError extends Error {
4
+ readonly status: number;
5
+ readonly body: components["schemas"]["ErrorResponse"];
6
+ constructor(status: number, body: components["schemas"]["ErrorResponse"]);
7
+ }
8
+ /** Configuration for the HyperClient. */
9
+ export interface HyperClientConfig {
10
+ /** Base URL of the hyper.chain.new API (e.g. https://localhost:8443). */
11
+ baseUrl: string;
12
+ /** Auth credentials injected into every request. */
13
+ auth?: {
14
+ type: "bearer";
15
+ token: string;
16
+ } | {
17
+ type: "serviceToken";
18
+ token: string;
19
+ };
20
+ }
21
+ /** Typed HTTP client for the hyper.chain.new API. Uses native fetch. */
22
+ export declare class HyperClient {
23
+ private readonly baseUrl;
24
+ private readonly auth;
25
+ constructor(config: HyperClientConfig);
26
+ private headers;
27
+ private request;
28
+ /** POST /api/v1/auth/bootstrap */
29
+ authBootstrap(body: components["schemas"]["BootstrapAuthRequest"]): Promise<components["schemas"]["TokenResponse"]>;
30
+ /** POST /api/v1/auth/rotate */
31
+ authRotate(): Promise<components["schemas"]["TokenResponse"]>;
32
+ /** POST /api/v1/auth/service-token */
33
+ authServiceToken(body: components["schemas"]["ServiceTokenRequest"]): Promise<components["schemas"]["TokenResponse"]>;
34
+ /** POST /api/v1/cyber/session/create */
35
+ cyberSessionCreate(body: components["schemas"]["CyberSessionCreateRequest"]): Promise<components["schemas"]["CyberSessionResponse"]>;
36
+ /** DELETE /api/v1/cyber/session/{session_id}/artifacts/{sample_id} */
37
+ cyberArtifactDelete(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]>;
38
+ /** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/pin */
39
+ cyberArtifactPin(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]>;
40
+ /** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/unpin */
41
+ cyberArtifactUnpin(session_id: string, sample_id: string): Promise<components["schemas"]["CyberArtifactActionResponse"]>;
42
+ /** POST /api/v1/cyber/session/{session_id}/ingest */
43
+ cyberSampleIngest(session_id: string, body: components["schemas"]["CyberIngestRequest"]): Promise<components["schemas"]["CyberArtifactResponse"]>;
44
+ /** GET /api/v1/image-cache/status */
45
+ imageCacheStatus(): Promise<components["schemas"]["ImageCacheStatus"]>;
46
+ /** GET /api/v1/operations */
47
+ operationsList(): Promise<components["schemas"]["OperationsPageResponse"]>;
48
+ /** GET /api/v1/operations/failed */
49
+ operationsFailed(): Promise<components["schemas"]["DlqPageResponse"]>;
50
+ /** GET /api/v1/ops/{id} */
51
+ operationStatus(id: string): Promise<components["schemas"]["OperationRecord"]>;
52
+ /** GET /api/v1/service/ping */
53
+ servicePing(): Promise<components["schemas"]["ServicePingResponse"]>;
54
+ /** POST /api/v1/snapshot/{id}/clone */
55
+ snapshotClone(id: string, body: components["schemas"]["SnapshotCloneHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]>;
56
+ /** POST /api/v1/snapshot/{id}/restore */
57
+ snapshotRestore(id: string, body: components["schemas"]["SnapshotRestoreHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]>;
58
+ /** GET /api/v1/system/safety */
59
+ systemSafety(): Promise<components["schemas"]["SystemSafety"]>;
60
+ /** GET /api/v1/ui/state */
61
+ uiState(): Promise<components["schemas"]["UiState"]>;
62
+ /** POST /api/v1/vault/prepare-operation */
63
+ vaultPrepareOperation(body: components["schemas"]["PrepareOperationRequest"]): Promise<components["schemas"]["PrepareOperationResponse"]>;
64
+ /** POST /api/v1/vm/create */
65
+ vmCreate(body: components["schemas"]["CreateVmRequest"]): Promise<components["schemas"]["OperationRecord"]>;
66
+ /** POST /api/v1/vm/{id}/destroy */
67
+ vmDestroy(id: string): Promise<components["schemas"]["OperationRecord"]>;
68
+ /** POST /api/v1/vm/{id}/snapshot */
69
+ snapshotCreate(id: string, body: components["schemas"]["SnapshotCreateHttpRequest"]): Promise<components["schemas"]["SnapshotResponse"]>;
70
+ /** GET /api/v1/vm/{id}/snapshots */
71
+ snapshotList(id: string): Promise<components["schemas"]["SnapshotPageResponse"]>;
72
+ /** POST /api/v1/vm/{id}/start */
73
+ vmStart(id: string): Promise<components["schemas"]["OperationRecord"]>;
74
+ /** POST /api/v1/vm/{id}/stop */
75
+ vmStop(id: string): Promise<components["schemas"]["OperationRecord"]>;
76
+ /** GET /health */
77
+ health(): Promise<components["schemas"]["HealthResponse"]>;
78
+ }
package/dist/client.js ADDED
@@ -0,0 +1,143 @@
1
+ // AUTO-GENERATED from docs/api/openapi.yaml — do not edit manually.
2
+ // Regenerate: ./scripts/generate-clients.sh
3
+ /** API error with status code and typed body. */
4
+ export class HyperApiError extends Error {
5
+ constructor(status, body) {
6
+ super(`${body.error}: ${body.message}`);
7
+ this.status = status;
8
+ this.body = body;
9
+ this.name = "HyperApiError";
10
+ }
11
+ }
12
+ /** Typed HTTP client for the hyper.chain.new API. Uses native fetch. */
13
+ export class HyperClient {
14
+ constructor(config) {
15
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
16
+ this.auth = config.auth;
17
+ }
18
+ headers() {
19
+ const h = { "Content-Type": "application/json" };
20
+ if (this.auth) {
21
+ if (this.auth.type === "bearer") {
22
+ h.Authorization = `Bearer ${this.auth.token}`;
23
+ }
24
+ else {
25
+ h["x-service-token"] = this.auth.token;
26
+ }
27
+ }
28
+ return h;
29
+ }
30
+ async request(method, path, body) {
31
+ const res = await fetch(`${this.baseUrl}${path}`, {
32
+ method,
33
+ headers: this.headers(),
34
+ body: body !== undefined ? JSON.stringify(body) : undefined,
35
+ });
36
+ if (!res.ok) {
37
+ const errBody = (await res.json());
38
+ throw new HyperApiError(res.status, errBody);
39
+ }
40
+ return (await res.json());
41
+ }
42
+ // --- generated methods ------------------------------------------------
43
+ /** POST /api/v1/auth/bootstrap */
44
+ async authBootstrap(body) {
45
+ return this.request("POST", "/api/v1/auth/bootstrap", body);
46
+ }
47
+ /** POST /api/v1/auth/rotate */
48
+ async authRotate() {
49
+ return this.request("POST", "/api/v1/auth/rotate");
50
+ }
51
+ /** POST /api/v1/auth/service-token */
52
+ async authServiceToken(body) {
53
+ return this.request("POST", "/api/v1/auth/service-token", body);
54
+ }
55
+ /** POST /api/v1/cyber/session/create */
56
+ async cyberSessionCreate(body) {
57
+ return this.request("POST", "/api/v1/cyber/session/create", body);
58
+ }
59
+ /** DELETE /api/v1/cyber/session/{session_id}/artifacts/{sample_id} */
60
+ async cyberArtifactDelete(session_id, sample_id) {
61
+ return this.request("DELETE", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}`);
62
+ }
63
+ /** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/pin */
64
+ async cyberArtifactPin(session_id, sample_id) {
65
+ return this.request("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}/pin`);
66
+ }
67
+ /** POST /api/v1/cyber/session/{session_id}/artifacts/{sample_id}/unpin */
68
+ async cyberArtifactUnpin(session_id, sample_id) {
69
+ return this.request("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/artifacts/${encodeURIComponent(sample_id)}/unpin`);
70
+ }
71
+ /** POST /api/v1/cyber/session/{session_id}/ingest */
72
+ async cyberSampleIngest(session_id, body) {
73
+ return this.request("POST", `/api/v1/cyber/session/${encodeURIComponent(session_id)}/ingest`, body);
74
+ }
75
+ /** GET /api/v1/image-cache/status */
76
+ async imageCacheStatus() {
77
+ return this.request("GET", "/api/v1/image-cache/status");
78
+ }
79
+ /** GET /api/v1/operations */
80
+ async operationsList() {
81
+ return this.request("GET", "/api/v1/operations");
82
+ }
83
+ /** GET /api/v1/operations/failed */
84
+ async operationsFailed() {
85
+ return this.request("GET", "/api/v1/operations/failed");
86
+ }
87
+ /** GET /api/v1/ops/{id} */
88
+ async operationStatus(id) {
89
+ return this.request("GET", `/api/v1/ops/${encodeURIComponent(id)}`);
90
+ }
91
+ /** GET /api/v1/service/ping */
92
+ async servicePing() {
93
+ return this.request("GET", "/api/v1/service/ping");
94
+ }
95
+ /** POST /api/v1/snapshot/{id}/clone */
96
+ async snapshotClone(id, body) {
97
+ return this.request("POST", `/api/v1/snapshot/${encodeURIComponent(id)}/clone`, body);
98
+ }
99
+ /** POST /api/v1/snapshot/{id}/restore */
100
+ async snapshotRestore(id, body) {
101
+ return this.request("POST", `/api/v1/snapshot/${encodeURIComponent(id)}/restore`, body);
102
+ }
103
+ /** GET /api/v1/system/safety */
104
+ async systemSafety() {
105
+ return this.request("GET", "/api/v1/system/safety");
106
+ }
107
+ /** GET /api/v1/ui/state */
108
+ async uiState() {
109
+ return this.request("GET", "/api/v1/ui/state");
110
+ }
111
+ /** POST /api/v1/vault/prepare-operation */
112
+ async vaultPrepareOperation(body) {
113
+ return this.request("POST", "/api/v1/vault/prepare-operation", body);
114
+ }
115
+ /** POST /api/v1/vm/create */
116
+ async vmCreate(body) {
117
+ return this.request("POST", "/api/v1/vm/create", body);
118
+ }
119
+ /** POST /api/v1/vm/{id}/destroy */
120
+ async vmDestroy(id) {
121
+ return this.request("POST", `/api/v1/vm/${encodeURIComponent(id)}/destroy`);
122
+ }
123
+ /** POST /api/v1/vm/{id}/snapshot */
124
+ async snapshotCreate(id, body) {
125
+ return this.request("POST", `/api/v1/vm/${encodeURIComponent(id)}/snapshot`, body);
126
+ }
127
+ /** GET /api/v1/vm/{id}/snapshots */
128
+ async snapshotList(id) {
129
+ return this.request("GET", `/api/v1/vm/${encodeURIComponent(id)}/snapshots`);
130
+ }
131
+ /** POST /api/v1/vm/{id}/start */
132
+ async vmStart(id) {
133
+ return this.request("POST", `/api/v1/vm/${encodeURIComponent(id)}/start`);
134
+ }
135
+ /** POST /api/v1/vm/{id}/stop */
136
+ async vmStop(id) {
137
+ return this.request("POST", `/api/v1/vm/${encodeURIComponent(id)}/stop`);
138
+ }
139
+ /** GET /health */
140
+ async health() {
141
+ return this.request("GET", "/health");
142
+ }
143
+ }