import { paths as PlatformDeploymentPaths } from "@convex-dev/platform/deploymentApi"; import { paths as PlatformManagementPaths } from "@convex-dev/platform/managementApi"; import { ProjectConfig } from "../config.js"; import { RequestInitRetryParams } from "fetch-retry"; import { Context } from "../../../bundler/context.js"; import type { CloudDeploymentType } from "../api.js"; import type { paths as CliManagementPaths, RegionName, TeamResponse } from "../../generatedApi.js"; export declare const productionProvisionHost = "https://api.convex.dev"; export declare const provisionHost: string; export declare const BIG_BRAIN_URL: string; export declare const ENV_VAR_FILE_PATH = ".env.local"; export declare const CONVEX_DEPLOY_KEY_ENV_VAR_NAME = "CONVEX_DEPLOY_KEY"; export declare const CONVEX_DEPLOYMENT_TOKEN_ENV_VAR_NAME = "CONVEX_DEPLOYMENT_TOKEN"; export declare const CONVEX_DEPLOYMENT_ENV_VAR_NAME = "CONVEX_DEPLOYMENT"; export declare const CONVEX_SELF_HOSTED_URL_VAR_NAME = "CONVEX_SELF_HOSTED_URL"; export declare const CONVEX_SELF_HOSTED_ADMIN_KEY_VAR_NAME = "CONVEX_SELF_HOSTED_ADMIN_KEY"; /** * Processes the CONVEX_DEPLOY_KEY value to handle special sentinel values. * * - If the value is ``, treats it as if the env var isn't set (returns undefined) * - If the value matches ``, crashes with the message in $STRING * - Otherwise returns the value as-is * * @param ctx Context for crashing if needed * @param deployKey The raw deploy key value from environment or config * @returns The processed deploy key value or undefined */ export declare function processDeployKeyValue(ctx: Context, deployKey: string | undefined): Promise; /** * Reads the deploy key from environment variables, accepting either * CONVEX_DEPLOY_KEY or its alias CONVEX_DEPLOYMENT_TOKEN. CONVEX_DEPLOY_KEY * takes precedence when both are set. */ export declare function readDeployKeyFromEnv(getEnv: (name: string) => string | undefined | null): string | undefined; export declare function parsePositiveInteger(value: string): number; export declare function parseInteger(value: string): number; export type ErrorData = { code: string; message: string; }; /** * Error thrown on non-2XX reponse codes to make most `fetch()` error handling * follow a single code path. */ export declare class ThrowingFetchError extends Error { response: Response; serverErrorData?: ErrorData; constructor(msg: string, { code, message, response, }: { cause?: Error; code?: string; message?: string; response: Response; }); static fromResponse(response: Response, msg?: string): Promise; handle(ctx: Context): Promise; } /** * Thin wrapper around `fetch()` which throws a FetchDataError on non-2XX * responses which includes error code and message from the response JSON. * (Axios-style) * * It also accepts retry options from fetch-retry. */ export declare function throwingFetch(resource: RequestInfo | URL, options: (RequestInit & RequestInitRetryParams) | undefined): Promise; /** * Handle an error a fetch error or non-2xx response. */ export declare function logAndHandleFetchError(ctx: Context, err: unknown): Promise; export declare function deprecationCheckWarning(ctx: Context, resp: Response): void; export declare function hasTeam(ctx: Context, teamSlug: string): Promise; export declare function validateOrSelectTeam(ctx: Context, teamSlug: string | undefined, promptMessage: string): Promise<{ team: TeamResponse; chosen: boolean; }>; export declare function selectDevDeploymentType(ctx: Context, { chosenConfiguration, newOrExisting, teamSlug, projectSlug, userHasChosenSomethingInteractively, devDeploymentFromFlag, forceDevDeployment, }: { chosenConfiguration: "new" | "existing" | "ask" | null; newOrExisting: "existing"; teamSlug: string; projectSlug: string; userHasChosenSomethingInteractively: boolean; devDeploymentFromFlag: "cloud" | "local" | undefined; forceDevDeployment: "cloud" | "local" | undefined; } | { chosenConfiguration: "new" | "existing" | "ask" | null; newOrExisting: "new"; teamSlug: string; projectSlug: undefined; userHasChosenSomethingInteractively: boolean; devDeploymentFromFlag: "cloud" | "local" | undefined; forceDevDeployment: "cloud" | "local" | undefined; }): Promise<{ devDeployment: "cloud" | "local"; }>; export declare function logNoDefaultRegionMessage(teamSlug: string): Promise; export declare function selectRegionOrUseDefault(ctx: Context, selectedTeam: TeamResponse, deploymentType: CloudDeploymentType): Promise<"aws-us-east-1" | "aws-eu-west-1" | null>; export declare function selectRegion(ctx: Context, teamId: number, deploymentType: CloudDeploymentType): Promise; export declare function hasProject(ctx: Context, teamSlug: string, projectSlug: string): Promise; export declare function hasProjects(ctx: Context): Promise; export declare function validateOrSelectProject(ctx: Context, projectSlug: string | undefined, teamSlug: string, singleProjectPrompt: string, multiProjectPrompt: string): Promise; /** * @param ctx * @returns a Record of dependency name to dependency version for dependencies * and devDependencies */ export declare function loadPackageJson(ctx: Context, includePeerDeps?: boolean): Promise>; export declare function ensureHasConvexDependency(ctx: Context, cmd: string): Promise; /** Return a new array with elements of the passed in array sorted by a key lambda */ export declare const sorted: (arr: T[], key: (el: T) => any) => T[]; export declare function functionsDir(configPath: string, projectConfig: ProjectConfig): string; export declare function rootDirectory(): string; export declare function cacheDir(): string; /** * Fetch with appropriate headers for the Convex Management API. * * This fetch() also has retries and throws if the response is not ok. */ export declare function bigBrainFetch(ctx: Context): typeof fetch; export declare function bigBrainAPI({ ctx, method, path, data, }: { ctx: Context; method: "GET" | "POST" | "HEAD"; path: string; data?: any; }): Promise; export declare const typedBigBrainClient: (ctx: Context, options?: { throw?: boolean; }) => import("openapi-fetch").Client; export declare const typedPlatformClient: (ctx: Context, options?: { throw?: boolean; }) => import("openapi-fetch").Client; export declare function typedDeploymentClient(ctx: Context, args: { deploymentUrl: string; adminKey: string; }, options?: { throw?: boolean; }): import("openapi-fetch").Client; export declare function bigBrainAPIMaybeThrows({ ctx, method, path, data, }: { ctx: Context; method: "GET" | "POST" | "HEAD"; path: string; data?: any; }): Promise; /** * Polls an arbitrary function until a condition is met. * * @param fetch Function performing a fetch, returning resulting data. * @param condition This function will terminate polling when it returns `true`. * @param waitMs How long to wait in between fetches. * @returns The resulting data from `fetch`. */ export declare const poll: (fetch: () => Promise, condition: (data: Result) => boolean, waitMs?: number) => Promise; export declare function waitForever(): Promise; export declare function waitUntilCalled(): [Promise, () => void]; /** * Format a byte count into a human-friendly string. * * Picks the unit (binary or decimal) that divides most cleanly. * Shows one decimal place only when it divides exactly (e.g. "4.1 MiB"). * Falls back to raw bytes when no unit divides cleanly. */ export declare function formatSize(n: number): string; export declare function formatDuration(ms: number): string; export declare function getCurrentTimeString(): string; export declare function findParentConfigs(ctx: Context): Promise<{ parentPackageJson: string; parentConvexJson?: string | undefined; }>; /** * Returns whether there's an existing project config. Throws * if this is not a valid directory for a project config. */ export declare function isInExistingProject(ctx: Context): Promise; export declare function spawnAsync(ctx: Context, command: string, args: ReadonlyArray): Promise<{ stdout: string; stderr: string; status: null | number; error?: Error | undefined; }>; export declare function spawnAsync(ctx: Context, command: string, args: ReadonlyArray, options: { stdio: "inherit"; shell?: boolean; }): Promise; /** * Unlike `deploymentFetch`, this does not add on any headers, so the caller * must supply any headers. */ export declare function bareDeploymentFetch(_ctx: Context, options: { deploymentUrl: string; onError?: (err: any) => void; }): typeof throwingFetch; /** * This returns a `fetch` function that will fetch against `deploymentUrl`. * * It will also set the `Authorization` header, `Content-Type` header, and * the `Convex-Client` header if they are not set in the `fetch`. */ export declare function deploymentFetch(_ctx: Context, options: { deploymentUrl: string; adminKey: string; onError?: (err: any) => void; }): typeof fetch; /** * Whether this is likely to be a WebContainer, * WebContainers can't complete the WorkOS login but where that login flow * fails has changed with the environment. */ export declare function isWebContainer(): boolean; export declare function currentPackageHomepage(ctx: Context): Promise; //# sourceMappingURL=utils.d.ts.map