UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

81 lines 3.12 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import { odata } from '../../../../utils/odata.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; const allowedTypes = ['mail', 'file', 'emailFile', 'url']; export const options = z.strictObject({ ...globalOptionsZod.shape, type: z.enum(allowedTypes).optional().alias('t') }); class PurviewThreatAssessmentListCommand extends GraphCommand { get name() { return commands.THREATASSESSMENT_LIST; } get description() { return 'Gets a list of threat assessments'; } get schema() { return options; } defaultProperties() { return ['id', 'type', 'category']; } async commandAction(logger, args) { if (this.verbose) { await logger.logToStderr('Retrieving a list of threat assessments'); } try { const filter = this.getFilterQuery(args.options); const items = await odata.getAllItems(`${this.resource}/v1.0/informationProtection/threatAssessmentRequests${filter}`, 'minimal'); let itemsToReturn = []; switch (args.options.type) { case 'mail': itemsToReturn = items.filter(item => item['@odata.type'] === '#microsoft.graph.mailAssessmentRequest'); break; case 'emailFile': itemsToReturn = items.filter(item => item['@odata.type'] === '#microsoft.graph.emailFileAssessmentRequest'); break; default: itemsToReturn = items; break; } for (const item of itemsToReturn) { item['type'] = this.getConvertedType(item['@odata.type']); delete item['@odata.type']; } await logger.log(itemsToReturn); } catch (err) { this.handleRejectedODataJsonPromise(err); } } // Content type is not equal to type. // Threat assessments of type emailFile have contentType mail as well. // This function gets the correct filter URL to be able to query the least amount of data getFilterQuery(options) { if (options.type === undefined) { return ''; } if (options.type === 'emailFile') { return `?$filter=contentType eq 'mail'`; } return `?$filter=contentType eq '${options.type}'`; } getConvertedType(type) { switch (type) { case '#microsoft.graph.mailAssessmentRequest': return 'mail'; case '#microsoft.graph.fileAssessmentRequest': return 'file'; case '#microsoft.graph.emailFileAssessmentRequest': return 'emailFile'; case '#microsoft.graph.urlAssessmentRequest': return 'url'; default: return 'Unknown'; } } } export default new PurviewThreatAssessmentListCommand(); //# sourceMappingURL=threatassessment-list.js.map