import { SecretBundle } from 'ts/manager.secret/classes.secretbundle.js'; import * as plugins from '../plugins.js'; import { ServiceManager } from './classes.servicemanager.js'; export class Service extends plugins.smartdata.SmartDataDbDoc< Service, plugins.servezoneInterfaces.data.IService, ServiceManager > { // STATIC public static async getServiceById(serviceIdArg: string) { const service = await this.getInstance({ id: serviceIdArg, }); return service; } public static async getServices() { const services = await this.getInstances({}); return services; } public static async createService(serviceDataArg: Partial) { const service = new Service(); service.id = await Service.getNewId(); Object.assign(service, serviceDataArg); await service.save(); return service; } // INSTANCE @plugins.smartdata.svDb() public id: string; @plugins.smartdata.svDb() public data: plugins.servezoneInterfaces.data.IService['data']; /** * a service runs in a specific environment * so -> this method returns the secret bundles as a flat object accordingly. * in other words, it resolves secret groups for the relevant environment * @param environmentArg */ public async getSecretBundlesAsFlatObject(environmentArg: string = 'production') { const secreBundleIds = this.data.additionalSecretBundleIds || []; secreBundleIds.push(this.data.secretBundleId); // put this last, so it overwrites any other secret bundles. let finalFlatObject = {}; for (const secretBundleId of secreBundleIds) { const secretBundle = await SecretBundle.getInstance({ id: secretBundleId, }); const flatObject = await secretBundle.getFlatKeyValueObject(environmentArg); Object.assign(finalFlatObject, flatObject); } return finalFlatObject; } }