import * as plugins from './plugins.js'; import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; export type TCreateServiceOptions = Omit< plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_CreateService['request'], 'identity' >; export class Service implements plugins.servezoneInterfaces.data.IService { public static async getServices(cloudlyClientRef: CloudlyApiClient) { const getAllServicesTR = cloudlyClientRef.requireTypedSocket().createTypedRequest( 'getServices' ); const response = await getAllServicesTR.fire({ identity: cloudlyClientRef.requireIdentity(), }); 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.requireTypedSocket().createTypedRequest( 'getServiceById' ); const response = await getServiceByIdTR.fire({ identity: cloudlyClientRef.requireIdentity(), serviceId: serviceIdArg, }); const newService = new Service(cloudlyClientRef); Object.assign(newService, response.service); return newService; } public static async getServiceRegistryTarget( cloudlyClientRef: CloudlyApiClient, serviceIdArg: string, tagArg = 'latest', ) { const getServiceRegistryTargetTR = cloudlyClientRef.requireTypedSocket().createTypedRequest( 'getServiceRegistryTarget' ); const response = await getServiceRegistryTargetTR.fire({ identity: cloudlyClientRef.requireIdentity(), serviceId: serviceIdArg, tag: tagArg, }); return response.registryTarget; } /** * creates a new service */ public static async createService( cloudlyClientRef: CloudlyApiClient, optionsArg: TCreateServiceOptions, ) { const createServiceTR = cloudlyClientRef.requireTypedSocket().createTypedRequest( 'createService' ); const response = await createServiceTR.fire({ identity: cloudlyClientRef.requireIdentity(), organizationId: optionsArg.organizationId, serviceData: optionsArg.serviceData, }); 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; } public async getRegistryTarget(tagArg = 'latest') { return Service.getServiceRegistryTarget(this.cloudlyClientRef, this.id, tagArg); } }