UNPKG

@smartsamurai/krapi-sdk

Version:

KRAPI TypeScript SDK - Easy-to-use client SDK for connecting to self-hosted KRAPI servers (like Appwrite SDK)

116 lines (105 loc) 2.57 kB
import { AxiosInstance } from "axios"; import { ApiResponse } from "../types"; /** * Backup API Manager * * Handles all backup-related API operations for the KRAPI client SDK. */ export class BackupApiManager { constructor(private axiosInstance: AxiosInstance) {} /** * Create a project backup */ async createProject( projectId: string, options?: { description?: string; password?: string; } ): Promise< ApiResponse<{ backup_id: string; password: string; created_at: string; size: number; }> > { const response = await this.axiosInstance.post< ApiResponse<{ backup_id: string; password: string; created_at: string; size: number; }> >(`/krapi/k1/projects/${projectId}/backup`, options || {}); return response.data; } /** * Restore a project from backup */ async restoreProject( projectId: string, backupId: string, password: string, options?: { overwrite?: boolean; } ): Promise<ApiResponse<{ success: boolean }>> { const response = await this.axiosInstance.post< ApiResponse<{ success: boolean }> >(`/krapi/k1/projects/${projectId}/restore`, { backup_id: backupId, password, ...options, }); return response.data; } /** * List backups */ async list( projectId?: string, type?: "project" | "system" ): Promise<ApiResponse<unknown[]>> { const url = projectId ? `/krapi/k1/projects/${projectId}/backups${type ? `?type=${type}` : ""}` : `/krapi/k1/backups${type ? `?type=${type}` : ""}`; const response = await this.axiosInstance.get<ApiResponse<unknown[]>>( url ); return response.data; } /** * Delete a backup */ async delete(backupId: string): Promise<ApiResponse<{ success: boolean }>> { const response = await this.axiosInstance.delete< ApiResponse<{ success: boolean }> >(`/krapi/k1/backups/${backupId}`); return response.data; } /** * Create a system backup */ async createSystem(options?: { description?: string; password?: string; }): Promise< ApiResponse<{ backup_id: string; password: string; created_at: string; size: number; }> > { const response = await this.axiosInstance.post< ApiResponse<{ backup_id: string; password: string; created_at: string; size: number; }> >("/krapi/k1/backup/system", options || {}); return response.data; } }