@altostra/core
Version:
Core library for shared types and logic
1 lines • 5.42 kB
JavaScript
"use strict";var _EnvironmentsManager_backofficeUrl,__awaiter=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,a){function o(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((i=i.apply(e,t||[])).next())}))},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EnvironmentsManager=void 0;const type_validations_1=require("@altostra/type-validations"),primitives_1=require("@altostra/type-validations/lib/primitives"),Types_1=require("../AltostraProjectsManager/Types"),ItemSelection_1=require("../ItemSelection"),ServiceClientBase_1=require("../ServiceClientBase"),Types_2=require("./Types");class EnvironmentsManager extends ServiceClientBase_1.ServiceClientBase{constructor({axios:e,endpoints:t,getToken:n,logger:i,config:r,errorMapping:a={}}){super({axios:e,getToken:n,logger:i,errorMapping:a}),_EnvironmentsManager_backofficeUrl.set(this,void 0),__classPrivateFieldSet(this,_EnvironmentsManager_backofficeUrl,t.backoffice,"f")}getEffectiveConfig(e){return __awaiter(this,void 0,void 0,(function*(){const{config:t}=yield this._request({request:t=>__awaiter(this,void 0,void 0,(function*(){return yield t.get(configEndpoint(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f"),e),{headers:yield this._getHeaders()})})),dataValidation:Types_2.isEnvironmentConfigResponse,errorWrapping:{message:"Failed to get environment config",data:{envName:e},type:"get-environment-config"}});return t}))}list(){return __awaiter(this,void 0,void 0,(function*(){return yield this._request({request:e=>__awaiter(this,void 0,void 0,(function*(){return yield e.get(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f")+"/environments",{headers:yield this._getHeaders()})})),dataValidation:(0,type_validations_1.arrayOf)(Types_2.isListedEnvironmentResponse),errorWrapping:{message:"Failed to get environments list",type:"get-environments"}})}))}get(e){return __awaiter(this,void 0,void 0,(function*(){return yield this._request({request:t=>__awaiter(this,void 0,void 0,(function*(){return yield t.get(`${__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f")}/environments/by-name/${e}`,{headers:yield this._getHeaders()})})),dataValidation:Types_2.isEnvironmentResponse,errorWrapping:{message:"Failed to get environment "+e,type:"get-environment"}})}))}create(e){return this._request({request:t=>__awaiter(this,void 0,void 0,(function*(){return yield t.post(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f")+"/environments",e,{headers:yield this._getHeaders()})})),dataValidation:Types_2.isEnvironmentResponse,errorWrapping:{message:"An error occurred while creating the environment.\nPlease try again or contact support.",type:"create-environment"}})}listProjects(e){return this._request({request:t=>__awaiter(this,void 0,void 0,(function*(){return yield t.get((0,ItemSelection_1.appendUrlQuery)(envProjectsEndpoint(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f"),(0,ItemSelection_1.selectionValue)(e)),(0,ItemSelection_1.selectionQueryParam)(e)),{headers:yield this._getHeaders()})})),dataValidation:Types_1.isProjectsArrayResponse,errorWrapping:{message:"An error occurred while listing projects in the environment.\nPlease try again or contact support.",type:"env-projects-listing"}})}update(e,t){return this._request({request:n=>__awaiter(this,void 0,void 0,(function*(){return yield n.put((0,ItemSelection_1.appendUrlQuery)(envEndpoint(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f"),(0,ItemSelection_1.selectionValue)(e)),(0,ItemSelection_1.selectionQueryParam)(e)),t,{headers:yield this._getHeaders()})})),dataValidation:primitives_1.any,errorWrapping:{message:"An error occurred while updating an environment.\nPlease try again or contact support.",type:"env-update"}})}delete(e){return this._request({request:t=>__awaiter(this,void 0,void 0,(function*(){return yield t.delete(envEndpoint(__classPrivateFieldGet(this,_EnvironmentsManager_backofficeUrl,"f"),e),{headers:yield this._getHeaders()})})),dataValidation:primitives_1.any,errorWrapping:{message:"An error occurred while deleting an environment.\nPlease try again or contact support.",type:"env-delete"}})}}function envEndpoint(e,t){return`${e}/environments/${encodeURIComponent(t)}`}function envProjectsEndpoint(e,t){return envEndpoint(e,t)+"/projects"}function configEndpoint(e,t){return envEndpoint(e,t)+"/effective-config"}exports.EnvironmentsManager=EnvironmentsManager,_EnvironmentsManager_backofficeUrl=new WeakMap;