@commercelayer/cli
Version:
36 lines (35 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@commercelayer/cli-core");
const applicationsCheck = {
resources: ['integration', 'sales_channel'],
seeder: ['integration'],
imports: ['integration'],
webhooks: ['integration'],
orders: ['integration', 'sales_channel'],
checkout: ['sales_channel'],
triggers: ['integration', 'sales_chasnnel'],
token: ['integration'],
microstore: ['sales_channel'],
exports: ['integration'],
cleanups: ['integration'],
tags: ['integration', 'sales_channel'],
provisioning: ['user']
};
const hook = async function (opts) {
// Only for test purpouses to avoid an error of undefined object
if (!opts.Command || !opts.argv)
return;
const accessToken = cli_core_1.clCommand.findLongStringFlag(opts.argv, 'accessToken');
if (accessToken) {
const tokenInfo = cli_core_1.clToken.decodeAccessToken(accessToken.value);
const appKind = tokenInfo.application.kind;
const plugin = opts.Command.id.split(':')[0];
const enabledApps = applicationsCheck[plugin];
if ((tokenInfo.scope === 'provisioning-api') && (plugin !== 'provisioning'))
this.error(`${cli_core_1.clColor.yellowBright('Provisioning')} applications can be used only to run ${cli_core_1.clColor.cli.plugin('provisioning')} plugin commands`);
if (!enabledApps.includes(appKind))
this.error(`Wrong application kind: ${cli_core_1.clColor.msg.error(appKind)}. Only these kinds of applications are enabled to use the ${cli_core_1.clColor.cli.plugin(plugin)} plugin: ${enabledApps.map(a => cli_core_1.clColor.yellowBright(a)).join(', ')}`);
}
};
exports.default = hook;