@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
91 lines • 3.9 kB
JavaScript
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import request from '../../../../request.js';
import { validation } from '../../../../utils/validation.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
const behaviorDuringRetentionPeriodValues = ['doNotRetain', 'retain', 'retainAsRecord', 'retainAsRegulatoryRecord'];
const actionAfterRetentionPeriodValues = ['none', 'delete', 'startDispositionReview'];
const retentionTriggerValues = ['dateLabeled', 'dateCreated', 'dateModified', 'dateOfEvent'];
const defaultRecordBehaviorValues = ['startLocked', 'startUnlocked'];
export const options = z.strictObject({
...globalOptionsZod.shape,
id: z.string().refine(val => validation.isValidGuid(val), {
error: 'The value must be a valid GUID.'
}).alias('i'),
behaviorDuringRetentionPeriod: z.enum(behaviorDuringRetentionPeriodValues).optional(),
actionAfterRetentionPeriod: z.enum(actionAfterRetentionPeriodValues).optional(),
retentionDuration: z.string().refine(val => !isNaN(Number(val)), {
error: 'retentionDuration must be a number'
}).optional(),
retentionTrigger: z.enum(retentionTriggerValues).optional().alias('t'),
defaultRecordBehavior: z.enum(defaultRecordBehaviorValues).optional(),
descriptionForUsers: z.string().optional(),
descriptionForAdmins: z.string().optional(),
labelToBeApplied: z.string().optional()
});
class PurviewRetentionLabelSetCommand extends GraphCommand {
get name() {
return commands.RETENTIONLABEL_SET;
}
get description() {
return 'Updates a retention label';
}
get schema() {
return options;
}
getRefinedSchema(schema) {
return schema
.refine(opts => opts.behaviorDuringRetentionPeriod || opts.actionAfterRetentionPeriod || opts.retentionDuration || opts.retentionTrigger || opts.defaultRecordBehavior || opts.descriptionForUsers || opts.descriptionForAdmins || opts.labelToBeApplied, {
error: 'Specify at least one property to update.',
params: {
customCode: 'optionSet',
options: ['behaviorDuringRetentionPeriod', 'actionAfterRetentionPeriod', 'retentionDuration', 'retentionTrigger', 'defaultRecordBehavior', 'descriptionForUsers', 'descriptionForAdmins', 'labelToBeApplied']
}
});
}
async commandAction(logger, args) {
if (this.verbose) {
await logger.log(`Starting to update retention label with id ${args.options.id}`);
}
const requestBody = this.mapRequestBody(args.options);
const requestOptions = {
url: `${this.resource}/beta/security/labels/retentionLabels/${args.options.id}`,
headers: {
accept: 'application/json'
},
responseType: 'json',
data: requestBody
};
try {
await request.patch(requestOptions);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
mapRequestBody(options) {
const requestBody = {};
const excludeOptions = [
'debug',
'verbose',
'output',
'id',
'retentionDuration'
];
Object.keys(options).forEach(key => {
if (excludeOptions.indexOf(key) === -1) {
requestBody[key] = `${options[key]}`;
}
});
if (options.retentionDuration) {
requestBody['retentionDuration'] = {
'@odata.type': 'microsoft.graph.security.retentionDurationInDays',
'days': Number(options.retentionDuration)
};
}
return requestBody;
}
}
export default new PurviewRetentionLabelSetCommand();
//# sourceMappingURL=retentionlabel-set.js.map