@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
60 lines • 2.23 kB
JavaScript
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { odata } from '../../../../utils/odata.js';
import { formatting } from '../../../../utils/formatting.js';
import { validation } from '../../../../utils/validation.js';
import commands from '../../commands.js';
import GraphDelegatedCommand from '../../../base/GraphDelegatedCommand.js';
export const options = z.strictObject({
...globalOptionsZod.shape,
userId: z.uuid().optional(),
userName: z.string().refine(name => validation.isValidUserPrincipalName(name), {
error: e => `'${e.input}' is not a valid user principal name (UPN).`
}).optional()
});
class EntraUserLicenseListCommand extends GraphDelegatedCommand {
get name() {
return commands.USER_LICENSE_LIST;
}
get description() {
return 'Lists the license details for a given user';
}
defaultProperties() {
return ['id', 'skuId', 'skuPartNumber'];
}
get schema() {
return options;
}
getRefinedSchema(schema) {
return schema
.refine(options => !options.userId || !options.userName, {
error: `Specify either 'userId' or 'userName', but not both.`,
params: {
customCode: 'optionSet',
options: ['userId', 'userName']
}
});
}
async commandAction(logger, args) {
if (this.verbose) {
await logger.logToStderr(`Retrieving licenses from user: ${args.options.userId || args.options.userName || 'current user'}.`);
}
let requestUrl = `${this.resource}/v1.0/`;
if (args.options.userId || args.options.userName) {
requestUrl += `users/${formatting.encodeQueryParameter(args.options.userId || args.options.userName)}`;
}
else {
requestUrl += 'me';
}
requestUrl += '/licenseDetails';
try {
const items = await odata.getAllItems(requestUrl);
await logger.log(items);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
export default new EntraUserLicenseListCommand();
//# sourceMappingURL=user-license-list.js.map