@capawesome/cli
Version:
The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.
85 lines (84 loc) • 3.28 kB
JavaScript
import authorizationService from '../services/authorization-service.js';
import httpClient from '../utils/http-client.js';
class AppEnvironmentsServiceImpl {
httpClient;
constructor(httpClient) {
this.httpClient = httpClient;
}
async create(dto) {
const response = await this.httpClient.post(`/v1/apps/${dto.appId}/environments`, dto, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
return response.data;
}
async delete(dto) {
if (dto.id) {
await this.httpClient.delete(`/v1/apps/${dto.appId}/environments/${dto.id}`, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
}
else if (dto.name) {
await this.httpClient.delete(`/v1/apps/${dto.appId}/environments`, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
params: {
name: dto.name,
},
});
}
}
async findAll(dto) {
const queryParams = new URLSearchParams();
if (dto.limit) {
queryParams.append('limit', dto.limit.toString());
}
if (dto.offset) {
queryParams.append('offset', dto.offset.toString());
}
const queryString = queryParams.toString();
const url = queryString
? `/v1/apps/${dto.appId}/environments?${queryString}`
: `/v1/apps/${dto.appId}/environments`;
const response = await this.httpClient.get(url, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
return response.data;
}
async setVariables(dto) {
await this.httpClient.post(`/v1/apps/${dto.appId}/environments/${dto.environmentId}/variables/set`, dto.variables, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
}
async setSecrets(dto) {
await this.httpClient.post(`/v1/apps/${dto.appId}/environments/${dto.environmentId}/secrets/set`, dto.secrets, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
}
async unsetVariables(dto) {
await this.httpClient.post(`/v1/apps/${dto.appId}/environments/${dto.environmentId}/variables/unset`, dto.keys, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
}
async unsetSecrets(dto) {
await this.httpClient.post(`/v1/apps/${dto.appId}/environments/${dto.environmentId}/secrets/unset`, dto.keys, {
headers: {
Authorization: `Bearer ${authorizationService.getCurrentAuthorizationToken()}`,
},
});
}
}
const appEnvironmentsService = new AppEnvironmentsServiceImpl(httpClient);
export default appEnvironmentsService;