@veertu/anka-controller 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +145 -2
- package/dist/index.cjs +399 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +156 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +361 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Veertu Inc.
|
|
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
CHANGED
|
@@ -1,3 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @veertu/anka-controller
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Client for the Anka Build Cloud Controller API.
|
|
4
|
+
|
|
5
|
+
One client talks to one Controller. It has two groups: `instances` and `templates`. The package sends the HTTP request, reads the `{ status, message, body }` envelope, and throws when `status` is not `OK`.
|
|
6
|
+
|
|
7
|
+
Node 22.18 or newer. The package has no runtime dependencies.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @veertu/anka-controller
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
ES module:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createControllerClient } from '@veertu/anka-controller'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
CommonJS:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
const { createControllerClient } = require('@veertu/anka-controller')
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Create a client
|
|
28
|
+
|
|
29
|
+
Use one auth mode. If you set both `rootToken` and `authorization`, creating the client throws.
|
|
30
|
+
|
|
31
|
+
Root token. This is Basic auth with an empty username, the same header `anka-actions` sends today:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const client = createControllerClient({
|
|
35
|
+
url: 'https://controller.example:8090',
|
|
36
|
+
rootToken: process.env.ANKA_ROOT_TOKEN
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Raw `Authorization` header. Pass the header value unchanged, the same way `anka-mcp` does today:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const client = createControllerClient({
|
|
44
|
+
url: 'https://controller.example:8090',
|
|
45
|
+
authorization: process.env.ANKA_CONTROLLER_AUTH
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Client certificate. These settings apply only to this client:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const client = createControllerClient({
|
|
53
|
+
url: 'https://controller.example:8090',
|
|
54
|
+
tls: {
|
|
55
|
+
ca: caPem,
|
|
56
|
+
cert: certPem,
|
|
57
|
+
key: keyPem,
|
|
58
|
+
passphrase: 'secret',
|
|
59
|
+
rejectUnauthorized: true
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`tls` requires an `https` URL. `rejectUnauthorized: false` skips certificate checks for this client only. It does not change `NODE_TLS_REJECT_UNAUTHORIZED`.
|
|
65
|
+
|
|
66
|
+
## Instances
|
|
67
|
+
|
|
68
|
+
`start` sends `POST /api/v1/vm`. `vmid` is required. The other fields use the Controller names. Extra fields are sent too. The return value is the array of instance ids.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const [instanceId] = await client.instances.start({
|
|
72
|
+
vmid: templateId,
|
|
73
|
+
tag: 'v1',
|
|
74
|
+
external_id: 'job-42',
|
|
75
|
+
startup_script: startupScriptBase64,
|
|
76
|
+
startup_script_condition: 1,
|
|
77
|
+
port_forwarding_override: [{ name: 'ssh', guest_port: '22' }]
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`get` sends `GET /api/v1/vm?id=...` and returns one instance.
|
|
82
|
+
|
|
83
|
+
`list` sends `GET /api/v1/vm` and returns an array of instances. When the Controller wraps an instance in `vm`, `list` copies those fields out. Fields on the outer object win. Filter `external_id` in your own code.
|
|
84
|
+
|
|
85
|
+
`terminate` sends `DELETE /api/v1/vm` with `{ id }`.
|
|
86
|
+
|
|
87
|
+
## Wait
|
|
88
|
+
|
|
89
|
+
`waitFor` calls `get` in a loop. The default interval is 3 seconds. Omit `timeoutMs`, or pass `0`, and there is no time limit.
|
|
90
|
+
|
|
91
|
+
After each get, the checks run in this order:
|
|
92
|
+
|
|
93
|
+
1. `isFailed` throws `ControllerError`. The default matches `Error`, `Terminating`, and `Terminated`.
|
|
94
|
+
2. `isReady` returns `{ done: 'ready', instance }`. The default matches `instance_state === 'Started'`.
|
|
95
|
+
3. `isStop` returns `{ done: 'stop', instance }`. The default never matches.
|
|
96
|
+
4. A passed time limit throws `ControllerError`. The error keeps the last instance.
|
|
97
|
+
5. Otherwise the helper sleeps and gets again.
|
|
98
|
+
|
|
99
|
+
`anka-actions` can wait with the defaults and log each poll:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const result = await client.instances.waitFor(instanceId, {
|
|
103
|
+
intervalMs: pollDelaySeconds * 1000,
|
|
104
|
+
onPoll(instance) {
|
|
105
|
+
console.log(instance.instance_state, instance.progress)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`anka-mcp` can pass its own checks. `done: 'stop'` means the helper returned the instance and did not throw:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const result = await client.instances.waitFor(instanceId, {
|
|
114
|
+
intervalMs: 3000,
|
|
115
|
+
timeoutMs: 180000,
|
|
116
|
+
isReady: instance =>
|
|
117
|
+
instance.instance_state === 'Started' && instance.vminfo?.status === 'running',
|
|
118
|
+
isStop: instance => instance.instance_state === 'Pulling'
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
if (result.done === 'stop') {
|
|
122
|
+
// Tell the caller to poll again later.
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A failed check wins when a ready check would also match.
|
|
127
|
+
|
|
128
|
+
## Templates
|
|
129
|
+
|
|
130
|
+
`templates.list` sends `GET /api/v1/registry/vm` once. That payload has `id`, `name`, `size`, and `arch`. It does not include version tags.
|
|
131
|
+
|
|
132
|
+
`templates.get` sends `GET /api/v1/registry/vm?id=...` and returns one template, including `versions`.
|
|
133
|
+
|
|
134
|
+
## Errors
|
|
135
|
+
|
|
136
|
+
Request failures throw `ControllerError`. The message includes the method, the path, and a redacted copy of the Controller response. `statusCode` is the HTTP status. `controllerStatus` is the envelope `status` when the Controller sent one.
|
|
137
|
+
|
|
138
|
+
`waitFor` puts the last instance on `error.instance` when the instance fails or the time limit passes.
|
|
139
|
+
|
|
140
|
+
The redaction removes the root token, the authorization value, and fields such as `startup_script`, `password`, `token`, and `secret`. The returned instance objects are unchanged.
|
|
141
|
+
|
|
142
|
+
## Release
|
|
143
|
+
|
|
144
|
+
The package version in `package.json` is the npm version. To publish, push a tag `v` plus that version, for example `v0.1.0`. The publish workflow uses npm trusted publishing, the same way `@veertu/anka-mcp` does.
|
|
145
|
+
|
|
146
|
+
Before the first publish, add this GitHub repo as a trusted publisher for `@veertu/anka-controller` on npm. Workflow file: `.github/workflows/publish.yml`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ControllerError: () => ControllerError,
|
|
34
|
+
createControllerClient: () => createControllerClient
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/client.ts
|
|
39
|
+
var import_node_https2 = __toESM(require("https"), 1);
|
|
40
|
+
|
|
41
|
+
// src/errors.ts
|
|
42
|
+
var ControllerError = class extends Error {
|
|
43
|
+
method;
|
|
44
|
+
path;
|
|
45
|
+
statusCode;
|
|
46
|
+
controllerStatus;
|
|
47
|
+
instance;
|
|
48
|
+
constructor(details) {
|
|
49
|
+
super(details.message);
|
|
50
|
+
this.name = "ControllerError";
|
|
51
|
+
this.method = details.method;
|
|
52
|
+
this.path = details.path;
|
|
53
|
+
this.statusCode = details.statusCode;
|
|
54
|
+
this.controllerStatus = details.controllerStatus;
|
|
55
|
+
this.instance = details.instance;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/normalize.ts
|
|
60
|
+
function normalizeInstance(value) {
|
|
61
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
62
|
+
throw new Error("Instance record is missing");
|
|
63
|
+
}
|
|
64
|
+
const record = value;
|
|
65
|
+
const nested = record.vm;
|
|
66
|
+
if (!nested || typeof nested !== "object" || Array.isArray(nested)) {
|
|
67
|
+
return record;
|
|
68
|
+
}
|
|
69
|
+
const outer = { ...record };
|
|
70
|
+
delete outer.vm;
|
|
71
|
+
return { ...nested, ...outer };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/request.ts
|
|
75
|
+
var import_node_http = __toESM(require("http"), 1);
|
|
76
|
+
var import_node_https = __toESM(require("https"), 1);
|
|
77
|
+
|
|
78
|
+
// src/redact.ts
|
|
79
|
+
var REDACTED = "[REDACTED]";
|
|
80
|
+
var SENSITIVE_FIELD_NAMES = /* @__PURE__ */ new Set([
|
|
81
|
+
"authorization",
|
|
82
|
+
"cookie",
|
|
83
|
+
"set-cookie",
|
|
84
|
+
"proxy-authorization",
|
|
85
|
+
"x-api-key",
|
|
86
|
+
"x-auth-token",
|
|
87
|
+
"token",
|
|
88
|
+
"password",
|
|
89
|
+
"secret",
|
|
90
|
+
"passphrase",
|
|
91
|
+
"startup_script",
|
|
92
|
+
"gh-pat",
|
|
93
|
+
"gh_pat",
|
|
94
|
+
"controller-auth-cert",
|
|
95
|
+
"controller-auth-cert-key",
|
|
96
|
+
"controller-root-token",
|
|
97
|
+
"root_token",
|
|
98
|
+
"roottoken",
|
|
99
|
+
"cert",
|
|
100
|
+
"key",
|
|
101
|
+
"ca"
|
|
102
|
+
]);
|
|
103
|
+
function redactString(value, secrets) {
|
|
104
|
+
let redacted = value;
|
|
105
|
+
for (const secret of secrets) {
|
|
106
|
+
if (secret.length >= 4) {
|
|
107
|
+
redacted = redacted.split(secret).join(REDACTED);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return redacted;
|
|
111
|
+
}
|
|
112
|
+
function redactValue(value, secrets) {
|
|
113
|
+
if (typeof value === "string") {
|
|
114
|
+
return redactString(value, secrets);
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
return value.map((item) => redactValue(item, secrets));
|
|
118
|
+
}
|
|
119
|
+
if (value && typeof value === "object") {
|
|
120
|
+
return Object.fromEntries(
|
|
121
|
+
Object.entries(value).map(([key, fieldValue]) => [
|
|
122
|
+
key,
|
|
123
|
+
SENSITIVE_FIELD_NAMES.has(key.toLowerCase()) ? REDACTED : redactValue(fieldValue, secrets)
|
|
124
|
+
])
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/request.ts
|
|
131
|
+
function request(controller, method, requestPath, body) {
|
|
132
|
+
const target = new URL(`${controller.baseUrl}${requestPath}`);
|
|
133
|
+
const transport = target.protocol === "https:" ? import_node_https.default : import_node_http.default;
|
|
134
|
+
const bodyText = body === void 0 ? void 0 : JSON.stringify(body);
|
|
135
|
+
const headers = { accept: "application/json" };
|
|
136
|
+
if (bodyText !== void 0) {
|
|
137
|
+
headers["content-type"] = "application/json";
|
|
138
|
+
headers["content-length"] = Buffer.byteLength(bodyText);
|
|
139
|
+
}
|
|
140
|
+
if (controller.authorization) {
|
|
141
|
+
headers.authorization = controller.authorization;
|
|
142
|
+
}
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
const incoming = transport.request(
|
|
145
|
+
target,
|
|
146
|
+
{
|
|
147
|
+
method,
|
|
148
|
+
headers,
|
|
149
|
+
agent: target.protocol === "https:" ? controller.agent : void 0
|
|
150
|
+
},
|
|
151
|
+
(response) => {
|
|
152
|
+
const chunks = [];
|
|
153
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
154
|
+
response.on("end", () => {
|
|
155
|
+
try {
|
|
156
|
+
resolve(
|
|
157
|
+
readEnvelope(
|
|
158
|
+
method,
|
|
159
|
+
requestPath,
|
|
160
|
+
response.statusCode ?? 0,
|
|
161
|
+
Buffer.concat(chunks).toString("utf8"),
|
|
162
|
+
controller.secrets
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
reject(error);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
incoming.on("error", (error) => {
|
|
172
|
+
reject(
|
|
173
|
+
new ControllerError({
|
|
174
|
+
message: `Failed to reach controller at ${controller.baseUrl}: ${redactString(error.message, controller.secrets)}`,
|
|
175
|
+
method,
|
|
176
|
+
path: requestPath
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
if (bodyText !== void 0) {
|
|
181
|
+
incoming.write(bodyText);
|
|
182
|
+
}
|
|
183
|
+
incoming.end();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function readEnvelope(method, requestPath, statusCode, text, secrets) {
|
|
187
|
+
let parsed;
|
|
188
|
+
if (text.trim()) {
|
|
189
|
+
try {
|
|
190
|
+
const value = JSON.parse(text);
|
|
191
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
192
|
+
parsed = value;
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
parsed = void 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const httpFailed = statusCode < 200 || statusCode >= 300;
|
|
199
|
+
const statusFailed = !parsed || parsed.status !== "OK";
|
|
200
|
+
if (httpFailed || statusFailed) {
|
|
201
|
+
const detail = parsed ? redactString(JSON.stringify(redactValue(parsed, secrets)), secrets) : redactString(text, secrets) || `HTTP ${statusCode}`;
|
|
202
|
+
throw new ControllerError({
|
|
203
|
+
message: `Controller request failed (${method} ${requestPath}): ${detail}`,
|
|
204
|
+
method,
|
|
205
|
+
path: requestPath,
|
|
206
|
+
statusCode,
|
|
207
|
+
controllerStatus: parsed?.status
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return parsed?.body;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/wait.ts
|
|
214
|
+
var DEFAULT_INTERVAL_MS = 3e3;
|
|
215
|
+
var FAILED_STATES = /* @__PURE__ */ new Set(["Error", "Terminating", "Terminated"]);
|
|
216
|
+
async function waitForInstance(getInstance, id, options = {}) {
|
|
217
|
+
const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
218
|
+
const timeoutMs = options.timeoutMs ?? 0;
|
|
219
|
+
const isReady = options.isReady ?? ((instance) => instance.instance_state === "Started");
|
|
220
|
+
const isFailed = options.isFailed ?? ((instance) => !!instance.instance_state && FAILED_STATES.has(instance.instance_state));
|
|
221
|
+
const isStop = options.isStop ?? (() => false);
|
|
222
|
+
const startedAt = Date.now();
|
|
223
|
+
const requestPath = `/api/v1/vm?id=${encodeURIComponent(id)}`;
|
|
224
|
+
for (; ; ) {
|
|
225
|
+
const instance = await getInstance(id);
|
|
226
|
+
options.onPoll?.(instance);
|
|
227
|
+
if (isFailed(instance)) {
|
|
228
|
+
throw new ControllerError({
|
|
229
|
+
message: formatFailure(instance),
|
|
230
|
+
method: "GET",
|
|
231
|
+
path: requestPath,
|
|
232
|
+
controllerStatus: instance.instance_state,
|
|
233
|
+
instance
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (isReady(instance)) {
|
|
237
|
+
return { done: "ready", instance };
|
|
238
|
+
}
|
|
239
|
+
if (isStop(instance)) {
|
|
240
|
+
return { done: "stop", instance };
|
|
241
|
+
}
|
|
242
|
+
if (timeoutMs > 0 && Date.now() - startedAt >= timeoutMs) {
|
|
243
|
+
const state = instance.instance_state ?? "unknown";
|
|
244
|
+
throw new ControllerError({
|
|
245
|
+
message: `Timed out after ${timeoutMs}ms waiting for instance ${id} (instance_state: ${state})`,
|
|
246
|
+
method: "GET",
|
|
247
|
+
path: requestPath,
|
|
248
|
+
controllerStatus: state,
|
|
249
|
+
instance
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
await delay(intervalMs);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function formatFailure(instance) {
|
|
256
|
+
const state = instance.instance_state ?? "unknown";
|
|
257
|
+
let text = `Instance entered ${state} state`;
|
|
258
|
+
if (typeof instance.message === "string" && instance.message) {
|
|
259
|
+
text += `: ${instance.message}`;
|
|
260
|
+
}
|
|
261
|
+
const stderr = instance.startup_script?.stderr;
|
|
262
|
+
if (typeof stderr === "string" && stderr) {
|
|
263
|
+
text += `: ${stderr}`;
|
|
264
|
+
}
|
|
265
|
+
return text;
|
|
266
|
+
}
|
|
267
|
+
function delay(ms) {
|
|
268
|
+
return new Promise((resolve) => {
|
|
269
|
+
setTimeout(resolve, ms);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/client.ts
|
|
274
|
+
function createControllerClient(options) {
|
|
275
|
+
const url = options.url?.trim() ?? "";
|
|
276
|
+
if (!url) {
|
|
277
|
+
throw new Error("url is required");
|
|
278
|
+
}
|
|
279
|
+
const rootToken = options.rootToken?.trim() ?? "";
|
|
280
|
+
const authorizationValue = options.authorization?.trim() ?? "";
|
|
281
|
+
if (rootToken && authorizationValue) {
|
|
282
|
+
throw new Error("Set rootToken or authorization, not both");
|
|
283
|
+
}
|
|
284
|
+
if (options.tls && !url.startsWith("https://")) {
|
|
285
|
+
throw new Error("tls options require an https url");
|
|
286
|
+
}
|
|
287
|
+
const baseUrl = url.replace(/\/+$/, "");
|
|
288
|
+
const authorization = authorizationValue || basicAuthorization(rootToken);
|
|
289
|
+
const secrets = [rootToken, authorizationValue, authorization].filter((secret) => secret.length > 0);
|
|
290
|
+
const controllerRequest = {
|
|
291
|
+
baseUrl,
|
|
292
|
+
authorization,
|
|
293
|
+
agent: options.tls ? createTlsAgent(options.tls) : void 0,
|
|
294
|
+
secrets
|
|
295
|
+
};
|
|
296
|
+
async function getInstance(id) {
|
|
297
|
+
const requestPath = `/api/v1/vm?id=${encodeURIComponent(id)}`;
|
|
298
|
+
const body = await request(controllerRequest, "GET", requestPath);
|
|
299
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
300
|
+
throw new ControllerError({
|
|
301
|
+
message: `Instance ${id} not found`,
|
|
302
|
+
method: "GET",
|
|
303
|
+
path: requestPath
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return normalizeInstance(body);
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
instances: {
|
|
310
|
+
async start(body) {
|
|
311
|
+
if (!body.vmid || !body.vmid.trim()) {
|
|
312
|
+
throw new Error("vmid is required");
|
|
313
|
+
}
|
|
314
|
+
const ids = await request(controllerRequest, "POST", "/api/v1/vm", body);
|
|
315
|
+
const idsAreMissing = !Array.isArray(ids) || ids.length === 0 || ids.some((id) => typeof id !== "string" || !id);
|
|
316
|
+
if (idsAreMissing) {
|
|
317
|
+
throw new ControllerError({
|
|
318
|
+
message: "Controller did not return an instance id (POST /api/v1/vm)",
|
|
319
|
+
method: "POST",
|
|
320
|
+
path: "/api/v1/vm"
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
return ids;
|
|
324
|
+
},
|
|
325
|
+
get: getInstance,
|
|
326
|
+
async list() {
|
|
327
|
+
const body = await request(controllerRequest, "GET", "/api/v1/vm");
|
|
328
|
+
if (body == null) {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
if (!Array.isArray(body)) {
|
|
332
|
+
throw new ControllerError({
|
|
333
|
+
message: "Controller request failed (GET /api/v1/vm): instance list body must be an array",
|
|
334
|
+
method: "GET",
|
|
335
|
+
path: "/api/v1/vm"
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return body.map((item) => normalizeInstance(item));
|
|
339
|
+
},
|
|
340
|
+
async terminate(id) {
|
|
341
|
+
await request(controllerRequest, "DELETE", "/api/v1/vm", { id });
|
|
342
|
+
},
|
|
343
|
+
waitFor(id, waitOptions) {
|
|
344
|
+
return waitForInstance(getInstance, id, waitOptions);
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
templates: {
|
|
348
|
+
async list() {
|
|
349
|
+
const body = await request(controllerRequest, "GET", "/api/v1/registry/vm");
|
|
350
|
+
if (body == null) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
if (!Array.isArray(body)) {
|
|
354
|
+
throw new ControllerError({
|
|
355
|
+
message: "Controller request failed (GET /api/v1/registry/vm): template list body must be an array",
|
|
356
|
+
method: "GET",
|
|
357
|
+
path: "/api/v1/registry/vm"
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return body;
|
|
361
|
+
},
|
|
362
|
+
async get(id) {
|
|
363
|
+
const requestPath = `/api/v1/registry/vm?id=${encodeURIComponent(id)}`;
|
|
364
|
+
const body = await request(controllerRequest, "GET", requestPath);
|
|
365
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
366
|
+
throw new ControllerError({
|
|
367
|
+
message: `Template ${id} not found`,
|
|
368
|
+
method: "GET",
|
|
369
|
+
path: requestPath
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return body;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function basicAuthorization(rootToken) {
|
|
378
|
+
if (!rootToken) {
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
return `Basic ${Buffer.from(`:${rootToken}`).toString("base64")}`;
|
|
382
|
+
}
|
|
383
|
+
function createTlsAgent(tls) {
|
|
384
|
+
const agentOptions = {};
|
|
385
|
+
if (tls.ca !== void 0) agentOptions.ca = tls.ca;
|
|
386
|
+
if (tls.cert !== void 0) agentOptions.cert = tls.cert;
|
|
387
|
+
if (tls.key !== void 0) agentOptions.key = tls.key;
|
|
388
|
+
if (tls.passphrase !== void 0) agentOptions.passphrase = tls.passphrase;
|
|
389
|
+
if (tls.rejectUnauthorized !== void 0) {
|
|
390
|
+
agentOptions.rejectUnauthorized = tls.rejectUnauthorized;
|
|
391
|
+
}
|
|
392
|
+
return new import_node_https2.default.Agent(agentOptions);
|
|
393
|
+
}
|
|
394
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
395
|
+
0 && (module.exports = {
|
|
396
|
+
ControllerError,
|
|
397
|
+
createControllerClient
|
|
398
|
+
});
|
|
399
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/errors.ts","../src/normalize.ts","../src/request.ts","../src/redact.ts","../src/wait.ts"],"sourcesContent":["export { createControllerClient } from './client'\nexport { ControllerError } from './errors'\nexport type {\n ControllerClient,\n ControllerClientOptions,\n DiskRequest,\n Instance,\n PortForwardRule,\n PortForwardingRule,\n StartInstanceRequest,\n StartupScriptResult,\n Template,\n TemplateVersion,\n TlsOptions,\n VmInfo,\n WaitForOptions,\n WaitForResult\n} from './types'\n","import https from 'node:https'\nimport { ControllerError } from './errors'\nimport { normalizeInstance } from './normalize'\nimport { request, type ControllerRequest } from './request'\nimport type {\n ControllerClient,\n ControllerClientOptions,\n Instance,\n StartInstanceRequest,\n Template,\n TlsOptions\n} from './types'\nimport { waitForInstance } from './wait'\n\nexport function createControllerClient(options: ControllerClientOptions): ControllerClient {\n const url = options.url?.trim() ?? ''\n if (!url) {\n throw new Error('url is required')\n }\n\n const rootToken = options.rootToken?.trim() ?? ''\n const authorizationValue = options.authorization?.trim() ?? ''\n if (rootToken && authorizationValue) {\n throw new Error('Set rootToken or authorization, not both')\n }\n\n if (options.tls && !url.startsWith('https://')) {\n throw new Error('tls options require an https url')\n }\n\n const baseUrl = url.replace(/\\/+$/, '')\n const authorization = authorizationValue || basicAuthorization(rootToken)\n const secrets = [rootToken, authorizationValue, authorization].filter(secret => secret.length > 0)\n const controllerRequest: ControllerRequest = {\n baseUrl,\n authorization,\n agent: options.tls ? createTlsAgent(options.tls) : undefined,\n secrets\n }\n\n async function getInstance(id: string): Promise<Instance> {\n const requestPath = `/api/v1/vm?id=${encodeURIComponent(id)}`\n const body = await request(controllerRequest, 'GET', requestPath)\n if (!body || typeof body !== 'object' || Array.isArray(body)) {\n throw new ControllerError({\n message: `Instance ${id} not found`,\n method: 'GET',\n path: requestPath\n })\n }\n return normalizeInstance(body)\n }\n\n return {\n instances: {\n async start(body: StartInstanceRequest): Promise<string[]> {\n if (!body.vmid || !body.vmid.trim()) {\n throw new Error('vmid is required')\n }\n\n const ids = await request(controllerRequest, 'POST', '/api/v1/vm', body)\n const idsAreMissing =\n !Array.isArray(ids) || ids.length === 0 || ids.some(id => typeof id !== 'string' || !id)\n if (idsAreMissing) {\n throw new ControllerError({\n message: 'Controller did not return an instance id (POST /api/v1/vm)',\n method: 'POST',\n path: '/api/v1/vm'\n })\n }\n return ids\n },\n\n get: getInstance,\n\n async list(): Promise<Instance[]> {\n const body = await request(controllerRequest, 'GET', '/api/v1/vm')\n if (body == null) {\n return []\n }\n if (!Array.isArray(body)) {\n throw new ControllerError({\n message: 'Controller request failed (GET /api/v1/vm): instance list body must be an array',\n method: 'GET',\n path: '/api/v1/vm'\n })\n }\n return body.map(item => normalizeInstance(item))\n },\n\n async terminate(id: string): Promise<void> {\n await request(controllerRequest, 'DELETE', '/api/v1/vm', { id })\n },\n\n waitFor(id, waitOptions) {\n return waitForInstance(getInstance, id, waitOptions)\n }\n },\n\n templates: {\n async list(): Promise<Template[]> {\n const body = await request(controllerRequest, 'GET', '/api/v1/registry/vm')\n if (body == null) {\n return []\n }\n if (!Array.isArray(body)) {\n throw new ControllerError({\n message:\n 'Controller request failed (GET /api/v1/registry/vm): template list body must be an array',\n method: 'GET',\n path: '/api/v1/registry/vm'\n })\n }\n return body as Template[]\n },\n\n async get(id: string): Promise<Template> {\n const requestPath = `/api/v1/registry/vm?id=${encodeURIComponent(id)}`\n const body = await request(controllerRequest, 'GET', requestPath)\n if (!body || typeof body !== 'object' || Array.isArray(body)) {\n throw new ControllerError({\n message: `Template ${id} not found`,\n method: 'GET',\n path: requestPath\n })\n }\n return body as Template\n }\n }\n }\n}\n\nfunction basicAuthorization(rootToken: string): string {\n if (!rootToken) {\n return ''\n }\n return `Basic ${Buffer.from(`:${rootToken}`).toString('base64')}`\n}\n\nfunction createTlsAgent(tls: TlsOptions): https.Agent {\n const agentOptions: https.AgentOptions = {}\n if (tls.ca !== undefined) agentOptions.ca = tls.ca\n if (tls.cert !== undefined) agentOptions.cert = tls.cert\n if (tls.key !== undefined) agentOptions.key = tls.key\n if (tls.passphrase !== undefined) agentOptions.passphrase = tls.passphrase\n if (tls.rejectUnauthorized !== undefined) {\n agentOptions.rejectUnauthorized = tls.rejectUnauthorized\n }\n return new https.Agent(agentOptions)\n}\n","import type { Instance } from './types'\n\nexport class ControllerError extends Error {\n readonly method: string\n readonly path: string\n readonly statusCode?: number\n readonly controllerStatus?: string\n readonly instance?: Instance\n\n constructor(details: {\n message: string\n method: string\n path: string\n statusCode?: number\n controllerStatus?: string\n instance?: Instance\n }) {\n super(details.message)\n this.name = 'ControllerError'\n this.method = details.method\n this.path = details.path\n this.statusCode = details.statusCode\n this.controllerStatus = details.controllerStatus\n this.instance = details.instance\n }\n}\n","import type { Instance } from './types'\n\n// The list endpoint sometimes returns { ...fields, vm: { ...fields } }.\n// Fields on the outer object win. get returns the instance itself.\nexport function normalizeInstance(value: unknown): Instance {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new Error('Instance record is missing')\n }\n\n const record = value as Record<string, unknown>\n const nested = record.vm\n if (!nested || typeof nested !== 'object' || Array.isArray(nested)) {\n return record as Instance\n }\n\n const outer = { ...record }\n delete outer.vm\n return { ...(nested as Record<string, unknown>), ...outer } as Instance\n}\n","import http from 'node:http'\nimport https from 'node:https'\nimport { ControllerError } from './errors'\nimport { redactString, redactValue } from './redact'\n\ninterface Envelope {\n status?: string\n message?: string\n body?: unknown\n}\n\nexport interface ControllerRequest {\n baseUrl: string\n authorization: string\n agent?: https.Agent\n secrets: readonly string[]\n}\n\nexport function request(\n controller: ControllerRequest,\n method: string,\n requestPath: string,\n body?: unknown\n): Promise<unknown> {\n const target = new URL(`${controller.baseUrl}${requestPath}`)\n const transport = target.protocol === 'https:' ? https : http\n const bodyText = body === undefined ? undefined : JSON.stringify(body)\n const headers: http.OutgoingHttpHeaders = { accept: 'application/json' }\n\n if (bodyText !== undefined) {\n headers['content-type'] = 'application/json'\n headers['content-length'] = Buffer.byteLength(bodyText)\n }\n\n if (controller.authorization) {\n headers.authorization = controller.authorization\n }\n\n return new Promise((resolve, reject) => {\n const incoming = transport.request(\n target,\n {\n method,\n headers,\n agent: target.protocol === 'https:' ? controller.agent : undefined\n },\n response => {\n const chunks: Buffer[] = []\n response.on('data', (chunk: Buffer) => chunks.push(chunk))\n response.on('end', () => {\n try {\n resolve(\n readEnvelope(\n method,\n requestPath,\n response.statusCode ?? 0,\n Buffer.concat(chunks).toString('utf8'),\n controller.secrets\n )\n )\n } catch (error) {\n reject(error)\n }\n })\n }\n )\n\n incoming.on('error', error => {\n reject(\n new ControllerError({\n message: `Failed to reach controller at ${controller.baseUrl}: ${redactString(error.message, controller.secrets)}`,\n method,\n path: requestPath\n })\n )\n })\n\n if (bodyText !== undefined) {\n incoming.write(bodyText)\n }\n incoming.end()\n })\n}\n\nfunction readEnvelope(\n method: string,\n requestPath: string,\n statusCode: number,\n text: string,\n secrets: readonly string[]\n): unknown {\n let parsed: Envelope | undefined\n if (text.trim()) {\n try {\n const value = JSON.parse(text) as unknown\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n parsed = value as Envelope\n }\n } catch {\n parsed = undefined\n }\n }\n\n const httpFailed = statusCode < 200 || statusCode >= 300\n const statusFailed = !parsed || parsed.status !== 'OK'\n if (httpFailed || statusFailed) {\n const detail = parsed\n ? redactString(JSON.stringify(redactValue(parsed, secrets)), secrets)\n : redactString(text, secrets) || `HTTP ${statusCode}`\n throw new ControllerError({\n message: `Controller request failed (${method} ${requestPath}): ${detail}`,\n method,\n path: requestPath,\n statusCode,\n controllerStatus: parsed?.status\n })\n }\n\n return parsed?.body\n}\n","const REDACTED = '[REDACTED]'\n\nconst SENSITIVE_FIELD_NAMES = new Set([\n 'authorization',\n 'cookie',\n 'set-cookie',\n 'proxy-authorization',\n 'x-api-key',\n 'x-auth-token',\n 'token',\n 'password',\n 'secret',\n 'passphrase',\n 'startup_script',\n 'gh-pat',\n 'gh_pat',\n 'controller-auth-cert',\n 'controller-auth-cert-key',\n 'controller-root-token',\n 'root_token',\n 'roottoken',\n 'cert',\n 'key',\n 'ca'\n])\n\nexport function redactString(value: string, secrets: readonly string[]): string {\n let redacted = value\n for (const secret of secrets) {\n if (secret.length >= 4) {\n redacted = redacted.split(secret).join(REDACTED)\n }\n }\n return redacted\n}\n\nexport function redactValue(value: unknown, secrets: readonly string[]): unknown {\n if (typeof value === 'string') {\n return redactString(value, secrets)\n }\n\n if (Array.isArray(value)) {\n return value.map(item => redactValue(item, secrets))\n }\n\n if (value && typeof value === 'object') {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, fieldValue]) => [\n key,\n SENSITIVE_FIELD_NAMES.has(key.toLowerCase())\n ? REDACTED\n : redactValue(fieldValue, secrets)\n ])\n )\n }\n\n return value\n}\n","import { ControllerError } from './errors'\nimport type { Instance, WaitForOptions, WaitForResult } from './types'\n\nconst DEFAULT_INTERVAL_MS = 3000\nconst FAILED_STATES = new Set(['Error', 'Terminating', 'Terminated'])\n\nexport async function waitForInstance(\n getInstance: (id: string) => Promise<Instance>,\n id: string,\n options: WaitForOptions = {}\n): Promise<WaitForResult> {\n const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS\n const timeoutMs = options.timeoutMs ?? 0\n const isReady = options.isReady ?? (instance => instance.instance_state === 'Started')\n const isFailed =\n options.isFailed ??\n (instance => !!instance.instance_state && FAILED_STATES.has(instance.instance_state))\n const isStop = options.isStop ?? (() => false)\n const startedAt = Date.now()\n const requestPath = `/api/v1/vm?id=${encodeURIComponent(id)}`\n\n for (;;) {\n const instance = await getInstance(id)\n options.onPoll?.(instance)\n\n if (isFailed(instance)) {\n throw new ControllerError({\n message: formatFailure(instance),\n method: 'GET',\n path: requestPath,\n controllerStatus: instance.instance_state,\n instance\n })\n }\n\n if (isReady(instance)) {\n return { done: 'ready', instance }\n }\n\n if (isStop(instance)) {\n return { done: 'stop', instance }\n }\n\n if (timeoutMs > 0 && Date.now() - startedAt >= timeoutMs) {\n const state = instance.instance_state ?? 'unknown'\n throw new ControllerError({\n message: `Timed out after ${timeoutMs}ms waiting for instance ${id} (instance_state: ${state})`,\n method: 'GET',\n path: requestPath,\n controllerStatus: state,\n instance\n })\n }\n\n await delay(intervalMs)\n }\n}\n\nfunction formatFailure(instance: Instance): string {\n const state = instance.instance_state ?? 'unknown'\n let text = `Instance entered ${state} state`\n if (typeof instance.message === 'string' && instance.message) {\n text += `: ${instance.message}`\n }\n\n const stderr = instance.startup_script?.stderr\n if (typeof stderr === 'string' && stderr) {\n text += `: ${stderr}`\n }\n\n return text\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms)\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,qBAAkB;;;ACEX,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAOT;AACD,UAAM,QAAQ,OAAO;AACrB,SAAK,OAAO;AACZ,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,QAAQ;AACpB,SAAK,aAAa,QAAQ;AAC1B,SAAK,mBAAmB,QAAQ;AAChC,SAAK,WAAW,QAAQ;AAAA,EAC1B;AACF;;;ACrBO,SAAS,kBAAkB,OAA0B;AAC1D,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAC/D,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAEA,QAAM,SAAS;AACf,QAAM,SAAS,OAAO;AACtB,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG;AAClE,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,EAAE,GAAG,OAAO;AAC1B,SAAO,MAAM;AACb,SAAO,EAAE,GAAI,QAAoC,GAAG,MAAM;AAC5D;;;AClBA,uBAAiB;AACjB,wBAAkB;;;ACDlB,IAAM,WAAW;AAEjB,IAAM,wBAAwB,oBAAI,IAAI;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAA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