caprover-api-js
Version:
An unofficial TypeScript-based, promise-driven Node.js library for interacting with the CapRover API.
135 lines (134 loc) • 4.82 kB
TypeScript
/**
* A generic wrapper for the standard CapRover API response structure.
*/
interface CaproverResponse<T> {
status: number;
description: string;
data: T;
}
type AppDefinition = {
appName: string;
hasPersistentData: boolean;
instanceCount: number;
volumes: {
volumeName: string;
}[];
envVars: {
key: string;
value: any;
}[];
[key: string]: any;
};
/**
* Options for initializing the CaproverAPI client.
*/
export interface CaproverApiOptions {
dashboardUrl: string;
password: string;
protocol?: 'http://' | 'https://';
schemaVersion?: number;
captainNamespace?: string;
}
export declare class CaproverAPI {
static Status: {
STATUS_ERROR_GENERIC: number;
STATUS_OK: number;
STATUS_OK_DEPLOY_STARTED: number;
STATUS_OK_PARTIALLY: number;
STATUS_ERROR_CAPTAIN_NOT_INITIALIZED: number;
STATUS_ERROR_USER_NOT_INITIALIZED: number;
STATUS_ERROR_NOT_AUTHORIZED: number;
STATUS_ERROR_ALREADY_EXIST: number;
STATUS_ERROR_BAD_NAME: number;
STATUS_WRONG_PASSWORD: number;
STATUS_AUTH_TOKEN_INVALID: number;
VERIFICATION_FAILED: number;
ILLEGAL_OPERATION: number;
BUILD_ERROR: number;
ILLEGAL_PARAMETER: number;
NOT_FOUND: number;
AUTHENTICATION_FAILED: number;
STATUS_PASSWORD_BACK_OFF: number;
};
private static LOGIN_PATH;
private static SYSTEM_INFO_PATH;
private static APP_LIST_PATH;
private static APP_REGISTER_PATH;
private static APP_DELETE_PATH;
private static ADD_CUSTOM_DOMAIN_PATH;
private static UPDATE_APP_PATH;
private static ENABLE_BASE_DOMAIN_SSL_PATH;
private static ENABLE_CUSTOM_DOMAIN_SSL_PATH;
private static APP_DATA_PATH;
private static CREATE_BACKUP_PATH;
private static DOWNLOAD_BACKUP_PATH;
private static TRIGGER_BUILD_PATH;
private axios;
private readonly baseUrl;
private readonly password;
private readonly captainNamespace;
private readonly schemaVersion;
private rootDomain;
/**
* The constructor is private to enforce async initialization via `CaproverAPI.create()`.
*/
private constructor();
/**
* Creates and initializes a new CaproverAPI instance.
* This is the correct way to instantiate the class due to async login requirements.
* @param options - Configuration for the API client.
* @returns A promise that resolves to a fully authenticated CaproverAPI instance.
*/
static create(options: CaproverApiOptions): Promise<CaproverAPI>;
/**
* A retry helper to wrap around API calls, replacing the Python decorator.
* @param asyncFunc The async function to execute.
* @param times The number of times to retry.
* @param delay The delay in ms between retries.
*/
private _retry;
/**
* Checks the response from the CapRover API for errors.
* Throws an exception if the status is not 'OK'.
* @param response - The API response object.
*/
private _checkErrors;
private _login;
getSystemInfo(): Promise<CaproverResponse<{
rootDomain: string;
}>>;
listApps(): Promise<CaproverResponse<{
appDefinitions: AppDefinition[];
}>>;
getApp(appName: string): Promise<AppDefinition | null>;
createApp(appName: string, hasPersistentData: boolean, wait?: boolean): Promise<any>;
addDomain(appName: string, customDomain: string): Promise<CaproverResponse<any>>;
enableSsl(appName: string, customDomain?: string): Promise<CaproverResponse<any>>;
updateApp(appName: string, updates: Partial<AppDefinition> & {
[key: string]: any;
}): Promise<CaproverResponse<unknown>>;
/**
* Triggers a new build for an app configured to deploy from Git.
* This is the programmatic equivalent of clicking the "Save & Update" button.
* @param appName The name of the app to trigger the build for.
*/
triggerBuild(appName: string): Promise<CaproverResponse<any>>;
deployApp(appName: string, options: {
imageName?: string;
dockerfileLines?: string[];
}): Promise<any>;
deleteApp(appName: string, deleteVolumes?: boolean): Promise<CaproverResponse<unknown>>;
/**
* Deploys a one-click app from a public or private repository.
*/
deployOneClickApp(oneClickAppName: string, appName: string, appVariables: Record<string, string | number>, oneClickRepository?: string): Promise<CaproverResponse<{
success: boolean;
}>>;
createBackup(fileName?: string): Promise<string>;
private getAppInfo;
private _waitUntilAppReady;
private _ensureAppBuildSuccess;
private _downloadOneClickAppDefn;
private _resolveAppVariables;
}
export {};