@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
54 lines • 2.4 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { readFileSync } from 'node:fs';
/**
* Function that uploads a zip bundle to the endpoint.
* @param endpoint string The endpoint to upload to
* @param bundle string The filename to upload
* @returns Object
*/
export const uploadAppBundle = (endpoint, bundle) => __awaiter(void 0, void 0, void 0, function* () {
const state = {
buffer: null,
};
try {
state.buffer = readFileSync(bundle);
}
catch (_a) {
throw new Error(`😞 Could not read bundle ${bundle}, does it exist?`);
}
const requestBundle = yield fetch(endpoint, {
method: 'POST',
body: state.buffer,
headers: {
Authorization: `Bearer ${process.env.FUSION_TOKEN}`,
'Content-Type': 'application/zip',
},
});
if (requestBundle.status === 401 || requestBundle.status === 403) {
throw new Error(`This is not allowed for this role on this app. HTTP message: ${requestBundle.statusText}`);
}
if (requestBundle.status === 404) {
throw new Error(`This app do not exist. HTTP message: ${requestBundle.statusText}`);
}
if (requestBundle.status === 409) {
throw new Error(`This version is already published. HTTP message: ${requestBundle.statusText}`);
}
if (requestBundle.status === 410) {
throw new Error(`This app is deleted. HTTP message: ${requestBundle.statusText}`);
}
if (!requestBundle.ok) {
const json = yield requestBundle.json();
console.error(json);
throw new Error(`Failed to publish bundle. HTTP status ${requestBundle.status}, ${requestBundle.statusText}`);
}
return requestBundle.json();
});
//# sourceMappingURL=uploadAppBundle.js.map