diff --git a/ts/classes.backup.ts b/ts/classes.backup.ts new file mode 100644 index 0000000..15cf0cc --- /dev/null +++ b/ts/classes.backup.ts @@ -0,0 +1,61 @@ +import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; + +export class Backup { + public static async createServiceBackup( + cloudlyClientRef: CloudlyApiClient, + optionsArg: { + serviceId: string; + clusterId?: string; + tags?: Record; + }, + ) { + const request = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'createServiceBackup', + ); + return await request.fire({ + identity: cloudlyClientRef.identity, + ...optionsArg, + }); + } + + public static async getServiceBackups( + cloudlyClientRef: CloudlyApiClient, + optionsArg: { + serviceId?: string; + status?: string; + } = {}, + ) { + const request = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'getServiceBackups', + ); + return await request.fire({ + identity: cloudlyClientRef.identity, + ...optionsArg, + }); + } + + public static async getBackupById(cloudlyClientRef: CloudlyApiClient, backupIdArg: string) { + const request = cloudlyClientRef.typedsocketClient.createTypedRequest('getBackupById'); + return await request.fire({ + identity: cloudlyClientRef.identity, + backupId: backupIdArg, + }); + } + + public static async restoreServiceBackup( + cloudlyClientRef: CloudlyApiClient, + optionsArg: { + backupId: string; + clear?: boolean; + resourceTypes?: Array<'volume' | 'database' | 'objectstorage'>; + }, + ) { + const request = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'restoreServiceBackup', + ); + return await request.fire({ + identity: cloudlyClientRef.identity, + ...optionsArg, + }); + } +} diff --git a/ts/classes.cloudlyapiclient.ts b/ts/classes.cloudlyapiclient.ts index 9843d81..20f72ae 100644 --- a/ts/classes.cloudlyapiclient.ts +++ b/ts/classes.cloudlyapiclient.ts @@ -9,6 +9,7 @@ import { SecretBundle } from './classes.secretbundle.js'; import { SecretGroup } from './classes.secretgroup.js'; import { ExternalRegistry } from './classes.externalregistry.js'; import { Platform } from './classes.platform.js'; +import { Backup } from './classes.backup.js'; export class CloudlyApiClient { private cloudlyUrl: string; @@ -386,6 +387,21 @@ export class CloudlyApiClient { }, } + public backup = { + createServiceBackup: async (optionsArg: Parameters[1]) => { + return Backup.createServiceBackup(this, optionsArg); + }, + getServiceBackups: async (optionsArg: Parameters[1] = {}) => { + return Backup.getServiceBackups(this, optionsArg); + }, + getBackupById: async (backupIdArg: string) => { + return Backup.getBackupById(this, backupIdArg); + }, + restoreServiceBackup: async (optionsArg: Parameters[1]) => { + return Backup.restoreServiceBackup(this, optionsArg); + }, + } + // Settings API public settings = { getSettings: async (): Promise<{