@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
62 lines • 2.65 kB
JavaScript
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { zod } from '../../../../utils/zod.js';
import { validation } from '../../../../utils/validation.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import { odata } from '../../../../utils/odata.js';
const options = globalOptionsZod
.extend({
resourceId: zod.alias('i', z.string()),
resourceType: zod.alias('t', z.enum(['user', 'group', 'device', 'organization']))
})
.strict();
class GraphOpenExtensionListCommand extends GraphCommand {
get name() {
return commands.OPENEXTENSION_LIST;
}
get description() {
return 'Retrieves all open extensions for a resource';
}
defaultProperties() {
return ['id', 'extensionName'];
}
get schema() {
return options;
}
getRefinedSchema(schema) {
return schema
.refine(options => options.resourceType !== 'group' && options.resourceType !== 'device' && options.resourceType !== 'organization' ||
(options.resourceId && validation.isValidGuid(options.resourceId)), options => ({
message: `The '${options.resourceId}' must be a valid GUID`,
path: ['resourceId']
}))
.refine(options => options.resourceType !== 'user' ||
(options.resourceId && (validation.isValidGuid(options.resourceId) || validation.isValidUserPrincipalName(options.resourceId))), options => ({
message: `The '${options.resourceId}' must be a valid GUID or user principal name`,
path: ['resourceId']
}));
}
async commandAction(logger, args) {
try {
const requestOptions = {
url: `${this.resource}/v1.0/${args.options.resourceType}${args.options.resourceType === 'organization' ? '' : 's'}/${args.options.resourceId}/extensions`,
headers: {
accept: 'application/json;odata.metadata=none',
'content-type': 'application/json'
},
responseType: 'json'
};
if (args.options.verbose) {
await logger.logToStderr(`Retrieving open extensions for the ${args.options.resourceType} with id '${args.options.resourceId}'...`);
}
const res = await odata.getAllItems(requestOptions);
await logger.log(res);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
export default new GraphOpenExtensionListCommand();
//# sourceMappingURL=openextension-list.js.map