@miosa/sdk 1.2.4 → 1.2.6
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 +75 -3
- package/dist/index.d.ts +323 -175
- package/dist/index.js +441 -386
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/src/client.ts +0 -293
- package/src/errors.ts +0 -136
- package/src/http.test.ts +0 -374
- package/src/http.ts +0 -390
- package/src/index.ts +0 -564
- package/src/resources/admin.ts +0 -359
- package/src/resources/analytics.ts +0 -60
- package/src/resources/api-keys.ts +0 -135
- package/src/resources/audit-log.ts +0 -64
- package/src/resources/benchmarks.ts +0 -104
- package/src/resources/builder-sessions.ts +0 -75
- package/src/resources/channels.ts +0 -143
- package/src/resources/checkpoints.ts +0 -225
- package/src/resources/command-center.ts +0 -73
- package/src/resources/community.ts +0 -103
- package/src/resources/completions.ts +0 -104
- package/src/resources/computer-auto-stop.ts +0 -43
- package/src/resources/computer-env.ts +0 -76
- package/src/resources/computer-logs.ts +0 -50
- package/src/resources/computer-osa.ts +0 -76
- package/src/resources/computer-ports.ts +0 -91
- package/src/resources/computer-terminal.ts +0 -61
- package/src/resources/computer-volumes.ts +0 -64
- package/src/resources/computer.ts +0 -551
- package/src/resources/computers.ts +0 -75
- package/src/resources/credits.ts +0 -43
- package/src/resources/cron-jobs.ts +0 -191
- package/src/resources/custom_domains.ts +0 -123
- package/src/resources/dashboard.ts +0 -49
- package/src/resources/databases.ts +0 -218
- package/src/resources/deployments.test.ts +0 -194
- package/src/resources/deployments.ts +0 -1060
- package/src/resources/desktop.ts +0 -134
- package/src/resources/docker-deploy.test.ts +0 -102
- package/src/resources/docker-deploy.ts +0 -183
- package/src/resources/egress.test.ts +0 -318
- package/src/resources/egressAudit.ts +0 -245
- package/src/resources/egressNetwork.ts +0 -450
- package/src/resources/egressSecrets.ts +0 -577
- package/src/resources/email.ts +0 -212
- package/src/resources/embeddings.ts +0 -36
- package/src/resources/events.ts +0 -296
- package/src/resources/exec.ts +0 -319
- package/src/resources/external-keys.ts +0 -79
- package/src/resources/files.test.ts +0 -339
- package/src/resources/files.ts +0 -220
- package/src/resources/flat-custom-domains.ts +0 -127
- package/src/resources/functions.ts +0 -178
- package/src/resources/governance.test.ts +0 -355
- package/src/resources/governance.ts +0 -528
- package/src/resources/health-checks.ts +0 -165
- package/src/resources/integrations.ts +0 -183
- package/src/resources/mcp.ts +0 -70
- package/src/resources/models.ts +0 -45
- package/src/resources/network_policy.ts +0 -73
- package/src/resources/open-computers/agents.ts +0 -91
- package/src/resources/open-computers/apps.ts +0 -102
- package/src/resources/open-computers/clusters.ts +0 -88
- package/src/resources/open-computers/desktop.ts +0 -34
- package/src/resources/open-computers/files.ts +0 -97
- package/src/resources/open-computers/hosts.ts +0 -85
- package/src/resources/open-computers/index.ts +0 -98
- package/src/resources/open-computers/jobs.ts +0 -75
- package/src/resources/open-computers/open_computers.test.ts +0 -288
- package/src/resources/open-computers/secrets.ts +0 -115
- package/src/resources/open-computers/terminal.ts +0 -33
- package/src/resources/open-computers/tunnels.ts +0 -87
- package/src/resources/open-computers/types.ts +0 -343
- package/src/resources/open-computers/workspaces.ts +0 -135
- package/src/resources/org-invites.ts +0 -189
- package/src/resources/phase1.test.ts +0 -187
- package/src/resources/project-auth.ts +0 -142
- package/src/resources/project-integrations.ts +0 -133
- package/src/resources/provider-defaults.ts +0 -89
- package/src/resources/quotas.ts +0 -77
- package/src/resources/regions.ts +0 -94
- package/src/resources/sandbox-processes.ts +0 -112
- package/src/resources/sandbox-shares.ts +0 -83
- package/src/resources/sandbox-templates.ts +0 -195
- package/src/resources/sandboxes.live.test.ts +0 -92
- package/src/resources/sandboxes.test.ts +0 -653
- package/src/resources/sandboxes.ts +0 -1433
- package/src/resources/settings.ts +0 -143
- package/src/resources/snapshots-standalone.ts +0 -51
- package/src/resources/storage.ts +0 -221
- package/src/resources/tenant-events.ts +0 -32
- package/src/resources/tenant.ts +0 -148
- package/src/resources/usage.ts +0 -85
- package/src/resources/volumes.ts +0 -117
- package/src/resources/webhooks.ts +0 -224
- package/src/resources/workspace-invites.ts +0 -188
- package/src/resources/workspace-members.test.ts +0 -121
- package/src/resources/workspace-members.ts +0 -143
- package/src/resources/workspaces.ts +0 -285
- package/src/types.ts +0 -463
package/src/resources/exec.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from "../http.js";
|
|
2
|
-
import type { ExecParams, ExecPythonParams, ExecResult } from "../types.js";
|
|
3
|
-
|
|
4
|
-
// ── Exec stream types ────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
/** Options for `Exec.stream()`. */
|
|
7
|
-
export interface ExecStreamOptions {
|
|
8
|
-
/** Command to execute. */
|
|
9
|
-
command: string;
|
|
10
|
-
/** Optional arguments. */
|
|
11
|
-
args?: string[];
|
|
12
|
-
/** Optional environment variables as KEY=VALUE strings. */
|
|
13
|
-
env?: string[];
|
|
14
|
-
/** Working directory inside the VM. */
|
|
15
|
-
cwd?: string;
|
|
16
|
-
/** Allocate a PTY. Defaults to false. */
|
|
17
|
-
tty?: boolean;
|
|
18
|
-
/** Terminal rows (when tty=true). */
|
|
19
|
-
rows?: number;
|
|
20
|
-
/** Terminal columns (when tty=true). */
|
|
21
|
-
cols?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type ExecStreamEventMap = {
|
|
25
|
-
stdout: [data: Uint8Array];
|
|
26
|
-
stderr: [data: Uint8Array];
|
|
27
|
-
exit: [code: number];
|
|
28
|
-
error: [err: Error];
|
|
29
|
-
close: [code: number, reason: string];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Live bidirectional exec stream backed by a `miosa-exec-v1` WebSocket.
|
|
34
|
-
*
|
|
35
|
-
* The binary wire protocol (1-byte frame ID) is handled by the server-side
|
|
36
|
-
* proxy and envd. The SDK exposes typed events on the received frames:
|
|
37
|
-
*
|
|
38
|
-
* - `stdout` — chunk of stdout bytes
|
|
39
|
-
* - `stderr` — chunk of stderr bytes
|
|
40
|
-
* - `exit` — process exit code (stream ends after this)
|
|
41
|
-
* - `error` — WebSocket error
|
|
42
|
-
* - `close` — WebSocket closed
|
|
43
|
-
*
|
|
44
|
-
* Obtain via `computer.exec.stream({ command: "bash", tty: true })`.
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* const s = computer.exec.stream({ command: "python3", args: ["script.py"] });
|
|
48
|
-
* s.on("stdout", chunk => process.stdout.write(chunk));
|
|
49
|
-
* s.on("exit", code => console.log("exit:", code));
|
|
50
|
-
* s.sendStdin(new TextEncoder().encode("hello\n"));
|
|
51
|
-
* await s.close();
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export class ExecStreamHandle {
|
|
55
|
-
private ws: WebSocket | import("ws").WebSocket | null = null;
|
|
56
|
-
private closed = false;
|
|
57
|
-
private readonly listeners = new Map<
|
|
58
|
-
keyof ExecStreamEventMap,
|
|
59
|
-
Array<(...args: unknown[]) => void>
|
|
60
|
-
>();
|
|
61
|
-
|
|
62
|
-
// Frame IDs — must match the envd binary protocol.
|
|
63
|
-
private static readonly FRAME_STDIN = 0x00;
|
|
64
|
-
private static readonly FRAME_STDOUT = 0x01;
|
|
65
|
-
private static readonly FRAME_STDERR = 0x02;
|
|
66
|
-
private static readonly FRAME_EXIT = 0x03;
|
|
67
|
-
|
|
68
|
-
/** @internal — use `Exec.stream()` instead. */
|
|
69
|
-
constructor(ws: WebSocket | import("ws").WebSocket) {
|
|
70
|
-
this.ws = ws;
|
|
71
|
-
this.attachHandlers();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ── EventEmitter-style API ──────────────────────────────────────────────────
|
|
75
|
-
|
|
76
|
-
on<K extends keyof ExecStreamEventMap>(
|
|
77
|
-
event: K,
|
|
78
|
-
handler: (...args: ExecStreamEventMap[K]) => void,
|
|
79
|
-
): this {
|
|
80
|
-
const list = this.listeners.get(event) ?? [];
|
|
81
|
-
list.push(handler as (...args: unknown[]) => void);
|
|
82
|
-
this.listeners.set(event, list);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
off<K extends keyof ExecStreamEventMap>(
|
|
87
|
-
event: K,
|
|
88
|
-
handler: (...args: ExecStreamEventMap[K]) => void,
|
|
89
|
-
): this {
|
|
90
|
-
const list = this.listeners.get(event) ?? [];
|
|
91
|
-
const idx = list.indexOf(handler as (...args: unknown[]) => void);
|
|
92
|
-
if (idx !== -1) list.splice(idx, 1);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private emit<K extends keyof ExecStreamEventMap>(
|
|
97
|
-
event: K,
|
|
98
|
-
...args: ExecStreamEventMap[K]
|
|
99
|
-
): void {
|
|
100
|
-
for (const fn of this.listeners.get(event) ?? []) {
|
|
101
|
-
fn(...(args as unknown[]));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ── Write API ───────────────────────────────────────────────────────────────
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Send stdin bytes to the running process.
|
|
109
|
-
* Prepends the 0x00 frame ID byte automatically.
|
|
110
|
-
*/
|
|
111
|
-
sendStdin(data: Uint8Array): void {
|
|
112
|
-
if (this.closed || !this.ws) return;
|
|
113
|
-
const frame = new Uint8Array(1 + data.length);
|
|
114
|
-
frame[0] = ExecStreamHandle.FRAME_STDIN;
|
|
115
|
-
frame.set(data, 1);
|
|
116
|
-
(this.ws as WebSocket).send(frame);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Send a terminal resize event.
|
|
121
|
-
* Encodes as 0x05 + rows (u16 BE) + cols (u16 BE).
|
|
122
|
-
*/
|
|
123
|
-
sendResize(rows: number, cols: number): void {
|
|
124
|
-
if (this.closed || !this.ws) return;
|
|
125
|
-
const frame = new Uint8Array(5);
|
|
126
|
-
const view = new DataView(frame.buffer);
|
|
127
|
-
frame[0] = 0x05;
|
|
128
|
-
view.setUint16(1, rows, false);
|
|
129
|
-
view.setUint16(3, cols, false);
|
|
130
|
-
(this.ws as WebSocket).send(frame);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Close the stream. Idempotent. */
|
|
134
|
-
async close(): Promise<void> {
|
|
135
|
-
if (this.closed || !this.ws) return;
|
|
136
|
-
this.closed = true;
|
|
137
|
-
(this.ws as WebSocket).close(1000, "client closed");
|
|
138
|
-
this.ws = null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Whether the stream has ended (by client or server). */
|
|
142
|
-
get isClosed(): boolean {
|
|
143
|
-
return this.closed;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ── Internal ────────────────────────────────────────────────────────────────
|
|
147
|
-
|
|
148
|
-
private attachHandlers() {
|
|
149
|
-
if (!this.ws) return;
|
|
150
|
-
const ws = this.ws;
|
|
151
|
-
|
|
152
|
-
ws.onmessage = (ev: MessageEvent) => {
|
|
153
|
-
let bytes: Uint8Array;
|
|
154
|
-
if (ev.data instanceof ArrayBuffer) {
|
|
155
|
-
bytes = new Uint8Array(ev.data);
|
|
156
|
-
} else if (ev.data instanceof Uint8Array) {
|
|
157
|
-
bytes = ev.data;
|
|
158
|
-
} else {
|
|
159
|
-
// Unexpected type (e.g. string on a text frame) — ignore.
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (bytes.length === 0) return;
|
|
163
|
-
|
|
164
|
-
const frameId = bytes[0];
|
|
165
|
-
const payload = bytes.slice(1);
|
|
166
|
-
|
|
167
|
-
switch (frameId) {
|
|
168
|
-
case ExecStreamHandle.FRAME_STDOUT:
|
|
169
|
-
this.emit("stdout", payload);
|
|
170
|
-
break;
|
|
171
|
-
case ExecStreamHandle.FRAME_STDERR:
|
|
172
|
-
this.emit("stderr", payload);
|
|
173
|
-
break;
|
|
174
|
-
case ExecStreamHandle.FRAME_EXIT: {
|
|
175
|
-
const view = new DataView(payload.buffer, payload.byteOffset);
|
|
176
|
-
const code = view.getUint32(0, false);
|
|
177
|
-
this.emit("exit", code);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
default:
|
|
181
|
-
// Unknown frame IDs — ignore, per protocol spec.
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
ws.onerror = (ev: Event) => {
|
|
187
|
-
const err =
|
|
188
|
-
ev instanceof ErrorEvent ? ev.error : new Error("WebSocket error");
|
|
189
|
-
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
ws.onclose = (ev: CloseEvent) => {
|
|
193
|
-
this.closed = true;
|
|
194
|
-
this.emit("close", ev.code, ev.reason);
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// ── Exec resource ─────────────────────────────────────────────────────────────
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Exec resource attached to every `Computer` instance.
|
|
203
|
-
* Exposes `bash()`, `python()`, and `stream()` for command execution.
|
|
204
|
-
*/
|
|
205
|
-
export class Exec {
|
|
206
|
-
private readonly http: HttpClient;
|
|
207
|
-
private readonly computerId: string;
|
|
208
|
-
|
|
209
|
-
constructor(http: HttpClient, computerId: string) {
|
|
210
|
-
this.http = http;
|
|
211
|
-
this.computerId = computerId;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private base(): string {
|
|
215
|
-
return `/computers/${this.computerId}/exec`;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Run a shell command inside the computer.
|
|
220
|
-
* @param command - Shell command string to execute.
|
|
221
|
-
* @param timeout - Optional timeout in seconds.
|
|
222
|
-
*/
|
|
223
|
-
async bash(command: string, timeout?: number): Promise<ExecResult> {
|
|
224
|
-
const params: ExecParams = {
|
|
225
|
-
command,
|
|
226
|
-
...(timeout !== undefined && { timeout }),
|
|
227
|
-
};
|
|
228
|
-
return this.http.post<ExecResult>(this.base(), params);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Execute Python code inside the computer.
|
|
233
|
-
* @param code - Python source code string.
|
|
234
|
-
* @param timeout - Optional timeout in seconds.
|
|
235
|
-
*/
|
|
236
|
-
async python(code: string, timeout?: number): Promise<ExecResult> {
|
|
237
|
-
const params: ExecPythonParams = {
|
|
238
|
-
code,
|
|
239
|
-
...(timeout !== undefined && { timeout }),
|
|
240
|
-
};
|
|
241
|
-
return this.http.post<ExecResult>(`${this.base()}/python`, params);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Open a live binary exec stream using the `miosa-exec-v1` subprotocol.
|
|
246
|
-
*
|
|
247
|
-
* The WebSocket negotiates `Sec-WebSocket-Protocol: miosa-exec-v1` to
|
|
248
|
-
* ensure version compatibility. Future protocol versions can be added
|
|
249
|
-
* server-side without breaking v1 clients.
|
|
250
|
-
*
|
|
251
|
-
* ```ts
|
|
252
|
-
* const stream = computer.exec.stream({ command: "bash", tty: true, rows: 24, cols: 80 });
|
|
253
|
-
* stream.on("stdout", data => process.stdout.write(data));
|
|
254
|
-
* stream.on("exit", code => console.log("done:", code));
|
|
255
|
-
* stream.sendStdin(new TextEncoder().encode("echo hello\n"));
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
stream(options: ExecStreamOptions): ExecStreamHandle {
|
|
259
|
-
const wsUrl = this.buildWsUrl(options);
|
|
260
|
-
const ws = createWebSocket(wsUrl, this.http.apiKey, "miosa-exec-v1");
|
|
261
|
-
return new ExecStreamHandle(ws);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private buildWsUrl(options: ExecStreamOptions): string {
|
|
265
|
-
const wsBase = this.http.baseUrl
|
|
266
|
-
.replace(/^https:\/\//, "wss://")
|
|
267
|
-
.replace(/^http:\/\//, "ws://")
|
|
268
|
-
.replace(/\/$/, "");
|
|
269
|
-
|
|
270
|
-
const params = new URLSearchParams();
|
|
271
|
-
params.set("command", options.command);
|
|
272
|
-
|
|
273
|
-
if (options.args && options.args.length > 0) {
|
|
274
|
-
for (const arg of options.args) params.append("args", arg);
|
|
275
|
-
}
|
|
276
|
-
if (options.env && options.env.length > 0) {
|
|
277
|
-
for (const e of options.env) params.append("env", e);
|
|
278
|
-
}
|
|
279
|
-
if (options.cwd) params.set("cwd", options.cwd);
|
|
280
|
-
if (options.tty) params.set("tty", "true");
|
|
281
|
-
if (options.rows !== undefined) params.set("rows", String(options.rows));
|
|
282
|
-
if (options.cols !== undefined) params.set("cols", String(options.cols));
|
|
283
|
-
|
|
284
|
-
return `${wsBase}/computers/${this.computerId}/exec/stream?${params.toString()}`;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// ── WebSocket factory (Node vs browser) ──────────────────────────────────────
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Creates a WebSocket connection with the given subprotocol.
|
|
292
|
-
*
|
|
293
|
-
* In the browser the `Authorization` header cannot be set directly — the API
|
|
294
|
-
* key is passed via a `bearer.<key>` subprotocol as a fallback; the real
|
|
295
|
-
* protocol is the first entry in the list and is what the server echoes back.
|
|
296
|
-
*
|
|
297
|
-
* In Node.js the `Authorization` header is set directly and only the protocol
|
|
298
|
-
* string is offered.
|
|
299
|
-
*/
|
|
300
|
-
function createWebSocket(
|
|
301
|
-
url: string,
|
|
302
|
-
apiKey: string,
|
|
303
|
-
protocol: string,
|
|
304
|
-
): WebSocket | import("ws").WebSocket {
|
|
305
|
-
if (
|
|
306
|
-
typeof window !== "undefined" &&
|
|
307
|
-
typeof window.WebSocket !== "undefined"
|
|
308
|
-
) {
|
|
309
|
-
// Browser: protocol first, then the auth fallback.
|
|
310
|
-
return new window.WebSocket(url, [protocol, `bearer.${apiKey}`]);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Node.js
|
|
314
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
315
|
-
const WS = require("ws") as typeof import("ws").WebSocket;
|
|
316
|
-
return new WS(url, [protocol], {
|
|
317
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
318
|
-
});
|
|
319
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External keys — BYOK encrypted per-user provider keys.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { HttpClient } from "../http.js";
|
|
6
|
-
|
|
7
|
-
// ── Resource shapes ──────────────────────────────────────────────────────────
|
|
8
|
-
|
|
9
|
-
export interface ExternalKeyData {
|
|
10
|
-
provider?: string;
|
|
11
|
-
masked_key?: string;
|
|
12
|
-
created_at?: string;
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ── Request payloads ─────────────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
export interface ExternalKeyCreateParams {
|
|
19
|
-
provider: string;
|
|
20
|
-
key: string;
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
function unwrap<T>(payload: unknown): T {
|
|
27
|
-
if (payload && typeof payload === "object") {
|
|
28
|
-
const p = payload as Record<string, unknown>;
|
|
29
|
-
for (const k of ["data", "external_keys", "items"]) {
|
|
30
|
-
if (k in p) return p[k] as T;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return payload as T;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function stripUndefined(
|
|
37
|
-
input: Record<string, unknown>,
|
|
38
|
-
): Record<string, unknown> {
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
Object.entries(input).filter(([, v]) => v !== undefined),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ── Main resource ─────────────────────────────────────────────────────────────
|
|
45
|
-
|
|
46
|
-
export class ExternalKeys {
|
|
47
|
-
constructor(private readonly http: HttpClient) {}
|
|
48
|
-
|
|
49
|
-
/** List configured external keys. */
|
|
50
|
-
async list(): Promise<ExternalKeyData[]> {
|
|
51
|
-
const data = await this.http.get<unknown>("/external-keys");
|
|
52
|
-
const result = unwrap<ExternalKeyData[] | unknown>(data);
|
|
53
|
-
if (Array.isArray(result)) return result;
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Create / register an external provider key. */
|
|
58
|
-
async create(params: ExternalKeyCreateParams): Promise<ExternalKeyData> {
|
|
59
|
-
const body = stripUndefined(params as Record<string, unknown>);
|
|
60
|
-
const data = await this.http.post<unknown>("/external-keys", body);
|
|
61
|
-
return unwrap<ExternalKeyData>(data);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Resolve (preview) the stored key for a provider. */
|
|
65
|
-
async resolve(provider: string): Promise<ExternalKeyData> {
|
|
66
|
-
const data = await this.http.get<unknown>(
|
|
67
|
-
`/external-keys/${provider}/resolve`,
|
|
68
|
-
);
|
|
69
|
-
return unwrap<ExternalKeyData>(data);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Delete the stored key for a provider.
|
|
74
|
-
* Keys are addressed by provider name, not by id.
|
|
75
|
-
*/
|
|
76
|
-
async delete(provider: string): Promise<void> {
|
|
77
|
-
await this.http.delete<unknown>(`/external-keys/${provider}`);
|
|
78
|
-
}
|
|
79
|
-
}
|