@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
49 lines • 2.13 kB
JavaScript
import { z } from 'zod';
import auth from '../../../../Auth.js';
import { globalOptionsZod } from '../../../../Command.js';
import { accessToken } from '../../../../utils/accessToken.js';
import { odata } from '../../../../utils/odata.js';
import { validation } from '../../../../utils/validation.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
export const options = z.strictObject({
...globalOptionsZod.shape,
userId: z.string().refine(val => validation.isValidGuid(val), {
error: 'The value must be a valid GUID.'
}).optional(),
userName: z.string().refine(val => validation.isValidUserPrincipalName(val), {
error: 'The value must be a valid user principal name (UPN).'
}).optional()
});
class PurviewSensitivityLabelListCommand extends GraphCommand {
get name() {
return commands.SENSITIVITYLABEL_LIST;
}
get description() {
return 'Gets a list of sensitivity labels';
}
get schema() {
return options;
}
defaultProperties() {
return ['id', 'name', 'isActive'];
}
async commandAction(logger, args) {
const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[this.resource].accessToken);
if (isAppOnlyAccessToken && !args.options.userId && !args.options.userName) {
this.handleError(`Specify at least 'userId' or 'userName' when using application permissions.`);
}
const requestUrl = args.options.userId || args.options.userName
? `${this.resource}/beta/users/${args.options.userId || args.options.userName}/security/informationProtection/sensitivityLabels`
: `${this.resource}/beta/me/security/informationProtection/sensitivityLabels`;
try {
const items = await odata.getAllItems(requestUrl);
await logger.log(items);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
export default new PurviewSensitivityLabelListCommand();
//# sourceMappingURL=sensitivitylabel-list.js.map