import * as plugins from './plugins.js'; import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; export class Service implements plugins.servezoneInterfaces.data.IService { public static async getServices(cloudlyClientRef: CloudlyApiClient) { const getAllServicesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( 'getServices' ); const response = await getAllServicesTR.fire({ identity: cloudlyClientRef.identity, }); const resultServices: Service[] = []; for (const service of response.services) { const newService = new Service(cloudlyClientRef); Object.assign(newService, service); resultServices.push(newService); } return resultServices; } public static async getServiceById(cloudlyClientRef: CloudlyApiClient, serviceIdArg: string) { const getServiceByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( 'getServiceById' ); const response = await getServiceByIdTR.fire({ identity: cloudlyClientRef.identity, serviceId: serviceIdArg, }); const newService = new Service(cloudlyClientRef); Object.assign(newService, response.service); return newService; } /** * creates a new service */ public static async createService(cloudlyClientRef: CloudlyApiClient, serviceDataArg: Partial) { const createServiceTR = cloudlyClientRef.typedsocketClient.createTypedRequest( 'createService' ); const response = await createServiceTR.fire({ identity: cloudlyClientRef.identity, name: serviceDataArg.name, description: serviceDataArg.description, imageId: serviceDataArg.imageId, imageVersion: serviceDataArg.imageVersion, environment: {}, secretBundleId: null, scaleFactor: 1, balancingStrategy: serviceDataArg.balancingStrategy, ports: { web: null, }, resources: serviceDataArg.resources, domains: [], }); const newService = new Service(cloudlyClientRef); Object.assign(newService, response.service); return newService; } // INSTANCE cloudlyClientRef: CloudlyApiClient; public id: string; public data: plugins.servezoneInterfaces.data.IService['data']; constructor(cloudlyClientRef: CloudlyApiClient) { this.cloudlyClientRef = cloudlyClientRef; } /** * The service has a secret bundle. * This function essentially returns the secret bundle as a flat object. * In other words, it resolves secret groups and */ public async getSecretBundleAsFlatObject(environmentArg: string = 'production') { } }