@codesandbox/sdk
Version:
The CodeSandbox SDK
76 lines (75 loc) • 2.24 kB
TypeScript
import { Disposable } from "./utils/disposable";
import { API } from "./API";
interface BaseHostTokenInfo {
expiresAt: Date | null;
tokenId: string;
lastUsedAt: Date | null;
}
export interface HostTokenInfo extends BaseHostTokenInfo {
tokenPrefix: string;
}
export interface HostToken extends BaseHostTokenInfo {
token: string;
sandboxId: string;
}
/**
* Provider for generating host tokens that can be used to access
* private sandbox hosts. This provider is only available in environments
* with an authenticated API client (like Node.js).
*/
export declare class HostTokens extends Disposable {
private api;
constructor(api: API);
/**
* Get url to access a private host using a host token.
* The PORT argument is needed as all hosts are exposed with
* a port.
*/
getUrl(token: {
sandboxId: string;
token: string;
}, port: number, protocol?: string): string;
/**
* Get headers to access a private host using a host token.
*/
getHeaders(token: {
sandboxId: string;
token: string;
}): {
"csb-preview-token": string;
};
/**
* Get cookies to access a private host using a host token.
*/
getCookies(token: {
sandboxId: string;
token: string;
}): {
csb_preview_token: string;
};
/**
* Generate a new host token that can be used to access private sandbox hosts.
*/
createToken(sandboxId: string, opts: {
expiresAt: Date;
}): Promise<HostToken>;
/**
* List all active host tokens for this sandbox.
*/
listTokens(sandboxId: string): Promise<HostTokenInfo[]>;
/**
* Revoke a single host token for this sandbox.
*/
revokeToken(sandboxId: string, tokenId: string): Promise<void>;
/**
* Revoke all active host tokens for this sandbox.
* This will immediately invalidate all tokens, and they can no longer be used
* to access the sandbox host.
*/
revokeAllTokens(sandboxId: string): Promise<void>;
/**
* Update a host token's expiration date.
*/
updateToken(sandboxId: string, tokenId: string, expiresAt: Date | null): Promise<HostTokenInfo>;
}
export {};