@codesandbox/api
Version:
The CodeSandbox API
45 lines (44 loc) • 1.11 kB
TypeScript
import type { User } from "./RESTTypes";
export type BaseRequestOptions = {
method: "POST";
data?: Record<string, unknown>;
} | {
method: "GET";
} | {
method: "PATCH";
data: Record<string, unknown>;
} | {
method: "PUT";
data: Record<string, unknown>;
} | {
method: "DELETE";
};
export type RequestOptions = {
headers: Record<string, string>;
url: string;
} & BaseRequestOptions;
export type OnRequest = (options: RequestOptions) => Promise<Response>;
export type Response = {
status: number;
data?: string;
cookies: string;
};
export type ClientType = "web" | "vscode";
export type CodeSandboxApiOptions = {
clientType: ClientType;
useCliAuthentication: boolean;
/**
* In the format of https://codesandbox.io
*/
apiUrl: string;
apiVersion?: string;
/**
* You can pass an initial user, for example rehydrating from server
* authentication
*/
user?: User;
};
export type RESTRequest = <T>({ path, ...options }: BaseRequestOptions & {
path: string;
headers?: Record<string, string>;
}) => Promise<T>;