UNPKG

@enplug/scripts

Version:
51 lines (46 loc) 1.61 kB
const sendSecureRequest = require('./sendSecureRequest'); const backendUrls = require('./backendUrls'); const chalk = require('chalk'); const getEnvToken = require('./getEnvToken'); function replaceAppUrls(appId, dashboardUrl, playerSideUrl, suffix, env) { const getAppUrl = `${backendUrls[env]['adserver']}/v1/appframework/app`; const token = getEnvToken(env); return sendSecureRequest(env, token, getAppUrl, 'GET', { appid: appId }, null) .then(response => { const jsonResp = JSON.parse(response); if (jsonResp.Success !== true) { throw jsonResp.ErrorMessage; } const appDefinition = jsonResp.Result; if (dashboardUrl) { if (suffix) { dashboardUrl = addSuffixToUrl(dashboardUrl, suffix); } appDefinition.ConfigureUrl = dashboardUrl; } if (playerSideUrl) { if (suffix) { playerSideUrl = addSuffixToUrl(playerSideUrl, suffix); } appDefinition.AppUrl = playerSideUrl; } return appDefinition; }) .then(appDefinition => { return sendSecureRequest(env, token, `${backendUrls[env]['adserver']}/v1/appframework/app/update`, 'POST', null, appDefinition); }) .then(response => { console.log(`${chalk.default.greenBright('App')} ${appId} ${chalk.default.greenBright('updated on')} ${env}`); return true; }); } function ensureEndingSlash(url) { if (!url.endsWith('/')) { url = `${url}/`; } return url; } function addSuffixToUrl(url, suffix) { return `${ensureEndingSlash(url)}${suffix}`; } module.exports = replaceAppUrls;