UNPKG

@codesandbox/api

Version:
52 lines (51 loc) 1.67 kB
import type { GHScopeOption } from "./RESTTypes"; import type { ClientType, OnRequest, Response, RESTRequest } from "./types"; export declare class ApiResponseError extends Error { type: "NOT_FOUND" | "ERROR" | "WORKSPACE_FROZEN"; parsedErrorMessage?: string; constructor(status: number, message: string, parsedErrorMessage?: string); } export type ErrorResponse = { error: { code: number; message: string; } | string; } | { errors: string[] | { detail?: string[]; } | { id: string[]; } | { code: string[]; }; } | { code: number; message: string; } | { code: number; error: string; }; export declare const onRequest: OnRequest; /** * Combines the passed in OnRequest with custom headers, including authorization. Also detects * if a response indicates being unauthorized */ export declare function createRESTRequester(options: { baseUrl: string; onRequest: OnRequest; clientType: ClientType; getBearerToken: () => string | undefined; onResponse: (response: Response) => void; }): RESTRequest; /** * The response of REST is in the format of { data?, errors? } | data */ export declare function handleRestResponse<T>(responsePromise: Promise<Response>, requestUrl: string): Promise<T>; export declare function openPopup(url: string, name: string): { close: () => void; closePromise: Promise<void>; }; export declare function waitForMessage<T>(cb: (message: T) => T | undefined): Promise<T>; /** Auth utils */ export declare const GITHUB_BASE_SCOPE = "user:email"; export declare const MAP_GITHUB_SCOPE_OPTIONS: Record<GHScopeOption, string>;