@shipengine/connect
Version:
The official developer tooling for building ShipEngine connect apps
67 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs = tslib_1.__importStar(require("fs"));
const form_data_1 = tslib_1.__importDefault(require("form-data"));
const log_types_1 = require("../../types/log-types");
class Deployments {
client;
constructor(apiClient) {
this.client = apiClient;
}
/**
* Create a new deployment for the given appID
* @returns {Promise<Deployment>} Promise object that resolves to a Deployment object.
*/
async create({ appId, pathToTarball, }) {
const form = new form_data_1.default();
form.append('deployment', fs.createReadStream(pathToTarball));
const response = await this.client.call({
endpoint: `apps/${appId}/deploys`,
method: 'POST',
body: form,
headers: {
'content-type': `multipart/form-data; boundary=${form.getBoundary()}`,
},
isFileUpload: true,
});
return response;
}
/**
* Gets all deploys for the given appID
* @returns {Promise<PaginatedItems<Deployment>>} Promise object that resolves to an Array of Deployment objects.
*/
async getAllForAppId(appId) {
const response = await this.client.call({
endpoint: `apps/${appId}/deploys`,
method: 'GET',
});
return response;
}
/**
* Gets the deploy for the given appId and deployID
* @returns {Promise<Deployment>} Promise object that resolves to a Deployment object.
*/
async getById({ appId, deployId }) {
const response = await this.client.call({
endpoint: `apps/${appId}/deploys/${deployId}`,
method: 'GET',
});
return response;
}
/**
* Gets the logs for a deployment for the given appId and deployID
* @returns {Promise<string>} Promise object that resolves to a Deployment object.
*/
async getLogsById({ appId, deployId, type, }) {
const typeLower = type?.toLowerCase() || '';
const query = log_types_1.logTypes.includes(typeLower) ? `?type=${typeLower}` : '';
const response = await this.client.call({
endpoint: `apps/${appId}/deploys/${deployId}/logs${query}`,
method: 'GET',
});
return response;
}
}
exports.default = Deployments;
//# sourceMappingURL=deployments.js.map