@runblackcat/sdk 0.1.0-alpha.91 → 0.1.0-alpha.93
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/package.json +1 -1
- package/sdk/dist/index.d.ts +24 -0
- package/sdk/dist/index.js +26 -12
package/package.json
CHANGED
package/sdk/dist/index.d.ts
CHANGED
|
@@ -535,6 +535,21 @@ export interface SshKeyGrant {
|
|
|
535
535
|
/** The sandbox's SSH host public key; pin it before connecting. */
|
|
536
536
|
host_key: string;
|
|
537
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Where and how to reach a port inside a sandbox through the gateway. Send
|
|
540
|
+
* `headers` with every request and with the WebSocket handshake; the gateway
|
|
541
|
+
* strips them before the application sees the request. A browser `WebSocket`
|
|
542
|
+
* cannot send headers, so the WebSocket form is for server-side clients.
|
|
543
|
+
*/
|
|
544
|
+
export interface PortConnection {
|
|
545
|
+
/** HTTPS URL of the path on the port. */
|
|
546
|
+
url: string;
|
|
547
|
+
/** The same target as a `wss:` URL. */
|
|
548
|
+
websocketUrl: string;
|
|
549
|
+
headers: {
|
|
550
|
+
Authorization: string;
|
|
551
|
+
};
|
|
552
|
+
}
|
|
538
553
|
export interface RenewSandboxResponse {
|
|
539
554
|
id: string;
|
|
540
555
|
expires_at: SystemTimeValue;
|
|
@@ -913,6 +928,15 @@ declare class SandboxesResource {
|
|
|
913
928
|
* with `CONNECT /v1/sandboxes/{id}/ssh`, or let `blackcat sandbox ssh` do it.
|
|
914
929
|
*/
|
|
915
930
|
grantSshKey(id: string, input: GrantSshKeyInput): Promise<SshKeyGrant>;
|
|
931
|
+
/**
|
|
932
|
+
* Describe a tunnel to `port` (any TCP port the sandbox listens on, not only
|
|
933
|
+
* a declared preview port), at `path` on that port. Needs the sandbox-scoped
|
|
934
|
+
* exec capability, which is checked once when a connection opens: an open
|
|
935
|
+
* WebSocket outlives it. Renews a nearly expired capability first, so call
|
|
936
|
+
* this again for each new connection. A `CONNECT` to `url` instead returns
|
|
937
|
+
* a raw byte stream, as `blackcat sandbox port-forward` uses.
|
|
938
|
+
*/
|
|
939
|
+
portConnection(id: string, port: number, path?: string): Promise<PortConnection>;
|
|
916
940
|
exec(id: string, input: ExecInput): Promise<ExecResult>;
|
|
917
941
|
execStream(id: string, input: ExecInput): AsyncGenerator<ExecStreamChunk>;
|
|
918
942
|
startProcess(id: string, requestId: string, input: ProcessStartInput): Promise<ProcessRecord>;
|
package/sdk/dist/index.js
CHANGED
|
@@ -482,6 +482,20 @@ class SandboxesResource {
|
|
|
482
482
|
grantSshKey(id, input) {
|
|
483
483
|
return this.client.json("POST", `/v1/sandboxes/${pathSegment(id)}/ssh-keys`, input, "either");
|
|
484
484
|
}
|
|
485
|
+
async portConnection(id, port, path = "/") {
|
|
486
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
487
|
+
throw new RangeError("port must be 1-65535");
|
|
488
|
+
if (!path.startsWith("/"))
|
|
489
|
+
throw new RangeError("path must start with /");
|
|
490
|
+
await this.client.renewIfNeeded();
|
|
491
|
+
const base = new URL(`v1/sandboxes/${pathSegment(id)}/ports/${port}/connect`, this.client.baseUrl);
|
|
492
|
+
const url = `${base.href}${path.startsWith("/?") || path === "/" ? path.slice(1) : path}`;
|
|
493
|
+
return {
|
|
494
|
+
url,
|
|
495
|
+
websocketUrl: url.replace(/^http/, "ws"),
|
|
496
|
+
headers: { Authorization: `Bearer ${this.client.credential("either")}` }
|
|
497
|
+
};
|
|
498
|
+
}
|
|
485
499
|
async exec(id, input) {
|
|
486
500
|
return this.client.json("POST", `/v1/sandboxes/${pathSegment(id)}/exec`, input, "either", false, execDeadline(input)).then(execResult);
|
|
487
501
|
}
|
|
@@ -721,17 +735,17 @@ class BlackcatClient extends GatewayClient {
|
|
|
721
735
|
}
|
|
722
736
|
}
|
|
723
737
|
export {
|
|
724
|
-
|
|
725
|
-
BlackcatApiError,
|
|
726
|
-
BlackcatClient,
|
|
727
|
-
CAPABILITY_OPS,
|
|
728
|
-
MAX_EXEC_STDIN,
|
|
729
|
-
MAX_FILE_CHUNK,
|
|
730
|
-
MAX_FILE_READ_CHUNK,
|
|
731
|
-
MAX_FILE_CHUNK as MAX_FILE_WRITE_CHUNK,
|
|
732
|
-
MAX_PROCESS_STDIN,
|
|
733
|
-
assertSecureBlackcatGatewayUrl,
|
|
734
|
-
epochMillis,
|
|
738
|
+
parseSandboxBatch,
|
|
735
739
|
parseCreateSandboxResponse,
|
|
736
|
-
|
|
740
|
+
epochMillis,
|
|
741
|
+
assertSecureBlackcatGatewayUrl,
|
|
742
|
+
MAX_PROCESS_STDIN,
|
|
743
|
+
MAX_FILE_CHUNK as MAX_FILE_WRITE_CHUNK,
|
|
744
|
+
MAX_FILE_READ_CHUNK,
|
|
745
|
+
MAX_FILE_CHUNK,
|
|
746
|
+
MAX_EXEC_STDIN,
|
|
747
|
+
CAPABILITY_OPS,
|
|
748
|
+
BlackcatClient,
|
|
749
|
+
BlackcatApiError,
|
|
750
|
+
BLACKCAT_ERROR_CODES
|
|
737
751
|
};
|