@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
63 lines • 2.38 kB
JavaScript
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { cli } from '../../../../cli/cli.js';
import request from '../../../../request.js';
import { validation } from '../../../../utils/validation.js';
import PowerAppsCommand from '../../../base/PowerAppsCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
...globalOptionsZod.shape,
environmentName: z.string().alias('e'),
name: z.string()
.refine(val => validation.isValidGuid(val), {
message: 'The value is not a valid GUID.'
})
.alias('n'),
bypass: z.boolean().alias('b'),
force: z.boolean().optional().alias('f')
});
class PaAppConsentSetCommand extends PowerAppsCommand {
get name() {
return commands.APP_CONSENT_SET;
}
get description() {
return 'Configures if users can bypass the API Consent window for the selected canvas app';
}
get schema() {
return options;
}
async commandAction(logger, args) {
if (this.verbose) {
await logger.logToStderr(`Setting the bypass consent for the Microsoft Power App ${args.options.name}... to ${args.options.bypass}`);
}
if (args.options.force) {
await this.consentPaApp(args);
}
else {
const result = await cli.promptForConfirmation({ message: `Are you sure you bypass the consent for the Microsoft Power App ${args.options.name} to ${args.options.bypass}?` });
if (result) {
await this.consentPaApp(args);
}
}
}
async consentPaApp(args) {
const requestOptions = {
url: `${this.resource}/providers/Microsoft.PowerApps/scopes/admin/environments/${args.options.environmentName}/apps/${args.options.name}/setPowerAppConnectionDirectConsentBypass?api-version=2021-02-01`,
headers: {
accept: 'application/json;odata.metadata=none'
},
responseType: 'json',
data: {
bypassconsent: args.options.bypass
}
};
try {
await request.post(requestOptions);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
export default new PaAppConsentSetCommand();
//# sourceMappingURL=app-consent-set.js.map