UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

62 lines 2.37 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import request from '../../../../request.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; export const options = z.strictObject({ ...globalOptionsZod.shape, emailAddress: z.string(), displayName: z.string().optional(), inviteRedirectUrl: z.string().optional(), welcomeMessage: z.string().optional(), messageLanguage: z.string().optional(), ccRecipients: z.string().optional(), sendInvitationMessage: z.boolean().optional() }); class EntraUserGuestAddCommand extends GraphCommand { get name() { return commands.USER_GUEST_ADD; } get description() { return 'Invites an external user to the organization'; } get schema() { return options; } async commandAction(logger, args) { try { const requestOptions = { url: `${this.resource}/v1.0/invitations`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json', data: { invitedUserEmailAddress: args.options.emailAddress, inviteRedirectUrl: args.options.inviteRedirectUrl || 'https://myapplications.microsoft.com', invitedUserDisplayName: args.options.displayName, sendInvitationMessage: args.options.sendInvitationMessage, invitedUserMessageInfo: { customizedMessageBody: args.options.welcomeMessage, messageLanguage: args.options.messageLanguage || 'en-US', ccRecipients: args.options.ccRecipients ? this.mapEmailsToRecipients([args.options.ccRecipients]) : undefined } } }; const result = await request.post(requestOptions); await logger.log(result); } catch (err) { this.handleRejectedODataJsonPromise(err); } } mapEmailsToRecipients(emails) { return emails.map(mail => ({ emailAddress: { address: mail.trim() } })); } } export default new EntraUserGuestAddCommand(); //# sourceMappingURL=user-guest-add.js.map