@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
38 lines • 1.96 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());
});
};
/**
* Publishes app config to the apps-service endpoint
* @param endpoint string The endpoint to upload to
* @param appKey The application key
* @param config Object with app config
* @returns HTTP response as json
*/
export const publishAppConfig = (endpoint, appKey, config) => __awaiter(void 0, void 0, void 0, function* () {
const requestConfig = yield fetch(endpoint, {
method: 'PUT',
body: JSON.stringify(config),
headers: {
Authorization: `Bearer ${process.env.FUSION_TOKEN}`,
'Content-Type': 'application/json',
},
});
// if the status is 410, the app is deleted from apps-service
if (requestConfig.status === 410) {
throw new Error(`App ${appKey} is deleted from apps-service. HTTP status ${requestConfig.status}, ${requestConfig.statusText}`);
}
// if the request is not ok or the status is 400 or higher, throw an error
if (!requestConfig.ok || requestConfig.status >= 400) {
const response = yield requestConfig.json();
console.error(response);
throw new Error(`Failed to upload config. HTTP status ${requestConfig.status}, ${requestConfig.statusText}`);
}
return requestConfig.json();
});
//# sourceMappingURL=publishAppConfig.js.map