Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const _getRuntime = async (credentials: AuthConfig): Promise => {
const runtime = await getRuntime(credentials, true);
const environmentClient = new EnvironmentClient(credentials, runtime.service.sid);
try {
const environment = await environmentClient.get(false);
return {
environment,
service: runtime.service,
};
} catch (e) {
const pluginName = logger.colors.blue(paths.packageName);
logger.newline();
logger.info(`⚠️ Plugin ${pluginName} was not found or was already removed.`);
return process.exit(0);
}
};
export const _doList = async (visibilities: Visibility[], order: Order = 'asc') => {
logger.info('Fetching all available versions of plugin %s', paths.packageName);
const credentials = await getCredential();
const runtime = await getRuntime(credentials);
const regex = new RegExp(PLUGIN_REGEX_STR.replace('%PLUGIN_NAME%', paths.packageName));
const assets = runtime.build && runtime.build.asset_versions || [];
const versions = assets
.filter((a) => regex.test(a.path))
.filter((a) => visibilities.includes(a.visibility));
if (versions.length === 0) {
logger.newline();
logger.info('No versions of plugin %s have been deployed', paths.packageName);
logger.newline();
return process.exit(0);
}
pluginVersions(runtime.environment.domain_name, versions, order);
};
const clear = async () => {
logger.info('Clearing caches and stored credentials');
await progress('Removing stored credentials', async () => await clearCredentials());
logger.newline();
logger.info('✨ Successfully cleared all caches and stored credentials');
logger.newline();
};
logger.info('Your plugin has the following packages installed:');
logger.newline();
foundPackages
.forEach((detail) => {
logger.info(`\t ${headline(`"${detail.name}": "${detail.package.version}"`)}`);
});
if (notFoundPackages.length) {
logger.newline();
logger.error('However, some required packages were not found:');
logger.newline();
notFoundPackages
.forEach((detail) => {
logger.info(`\t ${headline(`"${detail.name}"`)}`);
});
logger.newline();
instructionToReinstall();
}
};
const routeCollision = await progress('Validating the new plugin bundle', async () => {
const collision = runtime.build ? !_verifyPath(pluginBaseUrl, runtime.build) : false;
if (collision) {
if (options.overwrite) {
if (!options.disallowVersioning) {
logger.newline();
logger.warning('Plugin already exists and the flag --overwrite is going to overwrite this plugin.');
}
} else {
throw new FlexPluginError(`You already have a plugin with the same version: ${pluginUrl}`);
}
}
return collision;
});
export default (url: string, isPublic: boolean, account: Account) => {
const availability = isPublic ? 'publicly' : 'privately';
const nameLogger = logger.coloredStrings.name;
logger.newline();
logger.success(singleLineString(
'🚀 Your plugin has been successfully deployed to your Flex project',
`${nameLogger(account.friendly_name)} (${nameLogger(account.sid)}).`,
`It is hosted (${availability}) as a Twilio Asset on ${logger.coloredStrings.link(url)}.`,
));
logger.newline();
};
logger.newline();
logger.error(singleLineString(
'There might be a problem with your project dependency tree.',
));
logger.newline();
logger.info(`The ${flexUIName} requires the following package:`);
logger.newline();
logger.info(`\t ${headline(`"${packageName}": "${requiredVersion}"`)}`);
logger.newline();
const versionPrint = red(installedVersion);
logger.info(`However, a different version of this package was detected: ${versionPrint}.`);
logger.info(`Do not try to install this manually; ${scriptName} manages that for you.`);
logger.info('Managing this package yourself is known to cause issues in production environments.');
logger.newline();
instructionToReinstall(
`Remove ${nameColor(packageName)} from your ${nameColor('package.json')} file`,
);
preFlightByPass(skip);
logger.newline();
};
export default (packageName: string) => {
const nameColor = logger.coloredStrings.name;
const flexUIName = nameColor('@twilio/flex-ui');
logger.newline();
logger.error('An expected package was not found.');
logger.newline();
logger.info(`Expected package ${nameColor(packageName)} was not found in ${flexUIName}.`);
logger.newline();
instructionToReinstall();
};