@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
61 lines • 2.6 kB
JavaScript
import { globalOptionsZod } from '../../../../Command.js';
import { powerPlatform } from '../../../../utils/powerPlatform.js';
import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js';
import commands from '../../commands.js';
import { odata } from '../../../../utils/odata.js';
import { z } from 'zod';
export const options = z.strictObject({
...globalOptionsZod.shape,
websiteId: z.uuid().optional(),
websiteName: z.string().optional(),
environmentName: z.string().alias('e'),
asAdmin: z.boolean().optional()
});
class PpWebSiteWebRoleListCommand extends PowerPlatformCommand {
get name() {
return commands.WEBSITE_WEBROLE_LIST;
}
get description() {
return 'Lists all webroles for the specified Power Pages website.';
}
get schema() {
return options;
}
defaultProperties() {
return ['mspp_webroleid', 'mspp_name', 'statuscode'];
}
getRefinedSchema(schema) {
return schema
.refine(options => [options.websiteId, options.websiteName].filter(x => x !== undefined).length === 1, {
error: `Specify either websiteId or websiteName, but not both.`
});
}
async commandAction(logger, args) {
if (this.verbose) {
await logger.logToStderr(`Retrieving the webroles for '${args.options.websiteId || args.options.websiteName}'...`);
}
try {
const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environmentName, args.options.asAdmin);
const websiteRecordId = await this.getWebsiteRecordId(args, dynamicsApiUrl);
const roles = await this.getWebsiteRoles(dynamicsApiUrl, websiteRecordId);
await logger.log(roles);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
async getWebsiteRecordId(args, dynamicsApiUrl) {
if (args.options.websiteId) {
const website = await powerPlatform.getWebsiteById(args.options.environmentName, args.options.websiteId);
return website.websiteRecordId;
}
return powerPlatform.getWebsiteIdByUniqueName(dynamicsApiUrl, args.options.websiteName);
}
async getWebsiteRoles(dynamicsApiUrl, websiteId) {
const requestUrl = `${dynamicsApiUrl}/api/data/v9.2/mspp_webroles?$filter=_mspp_websiteid_value eq ${websiteId}`;
const result = await odata.getAllItems(requestUrl);
return result;
}
}
export default new PpWebSiteWebRoleListCommand();
//# sourceMappingURL=website-webrole-list.js.map