@pnp/cli-microsoft365 10.3.0-beta.d1b978f → 10.3.0-beta.ea113b7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,186 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _EntraPimRoleAssignmentRemoveCommand_instances, _EntraPimRoleAssignmentRemoveCommand_initTelemetry, _EntraPimRoleAssignmentRemoveCommand_initOptions, _EntraPimRoleAssignmentRemoveCommand_initValidators, _EntraPimRoleAssignmentRemoveCommand_initOptionSets, _EntraPimRoleAssignmentRemoveCommand_initTypes;
7
+ import request from '../../../../request.js';
8
+ import GraphCommand from '../../../base/GraphCommand.js';
9
+ import commands from '../../commands.js';
10
+ import { roleDefinition } from '../../../../utils/roleDefinition.js';
11
+ import { validation } from '../../../../utils/validation.js';
12
+ import { entraUser } from '../../../../utils/entraUser.js';
13
+ import { entraGroup } from '../../../../utils/entraGroup.js';
14
+ import { accessToken } from '../../../../utils/accessToken.js';
15
+ import auth from '../../../../Auth.js';
16
+ class EntraPimRoleAssignmentRemoveCommand extends GraphCommand {
17
+ get name() {
18
+ return commands.PIM_ROLE_ASSIGNMENT_REMOVE;
19
+ }
20
+ get description() {
21
+ return 'Request deactivation of an Entra role assignment for a user or group';
22
+ }
23
+ constructor() {
24
+ super();
25
+ _EntraPimRoleAssignmentRemoveCommand_instances.add(this);
26
+ __classPrivateFieldGet(this, _EntraPimRoleAssignmentRemoveCommand_instances, "m", _EntraPimRoleAssignmentRemoveCommand_initTelemetry).call(this);
27
+ __classPrivateFieldGet(this, _EntraPimRoleAssignmentRemoveCommand_instances, "m", _EntraPimRoleAssignmentRemoveCommand_initOptions).call(this);
28
+ __classPrivateFieldGet(this, _EntraPimRoleAssignmentRemoveCommand_instances, "m", _EntraPimRoleAssignmentRemoveCommand_initValidators).call(this);
29
+ __classPrivateFieldGet(this, _EntraPimRoleAssignmentRemoveCommand_instances, "m", _EntraPimRoleAssignmentRemoveCommand_initOptionSets).call(this);
30
+ __classPrivateFieldGet(this, _EntraPimRoleAssignmentRemoveCommand_instances, "m", _EntraPimRoleAssignmentRemoveCommand_initTypes).call(this);
31
+ }
32
+ async commandAction(logger, args) {
33
+ const { userId, userName, groupId, groupName, ticketNumber, ticketSystem } = args.options;
34
+ try {
35
+ const token = auth.connection.accessTokens[auth.defaultResource].accessToken;
36
+ const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(token);
37
+ if (isAppOnlyAccessToken && !userId && !userName && !groupId && !groupName) {
38
+ throw 'When running with application permissions either userId, userName, groupId or groupName is required';
39
+ }
40
+ const roleDefinitionId = await this.getRoleDefinitionId(args.options, logger);
41
+ const principalId = await this.getPrincipalId(args.options, logger);
42
+ const requestOptions = {
43
+ url: `${this.resource}/v1.0/roleManagement/directory/roleAssignmentScheduleRequests`,
44
+ headers: {
45
+ 'accept': 'application/json;odata.metadata=none'
46
+ },
47
+ responseType: 'json',
48
+ data: {
49
+ principalId: principalId,
50
+ roleDefinitionId: roleDefinitionId,
51
+ directoryScopeId: this.getDirectoryScope(args.options),
52
+ action: !userId && !userName && !groupId && !groupName ? 'selfDeactivate' : 'adminRemove',
53
+ justification: args.options.justification,
54
+ ticketInfo: {
55
+ ticketNumber: ticketNumber,
56
+ ticketSystem: ticketSystem
57
+ }
58
+ }
59
+ };
60
+ const response = await request.post(requestOptions);
61
+ await logger.log(response);
62
+ }
63
+ catch (err) {
64
+ this.handleRejectedODataJsonPromise(err);
65
+ }
66
+ }
67
+ async getRoleDefinitionId(options, logger) {
68
+ if (options.roleDefinitionId) {
69
+ return options.roleDefinitionId;
70
+ }
71
+ if (this.verbose) {
72
+ await logger.logToStderr(`Retrieving role definition by its name '${options.roleDefinitionName}'`);
73
+ }
74
+ const role = await roleDefinition.getRoleDefinitionByDisplayName(options.roleDefinitionName);
75
+ return role.id;
76
+ }
77
+ async getPrincipalId(options, logger) {
78
+ if (options.userId || options.groupId) {
79
+ return options.userId || options.groupId;
80
+ }
81
+ if (options.userName) {
82
+ if (this.verbose) {
83
+ await logger.logToStderr(`Retrieving user by its name '${options.userName}'`);
84
+ }
85
+ return await entraUser.getUserIdByUpn(options.userName);
86
+ }
87
+ else if (options.groupName) {
88
+ if (this.verbose) {
89
+ await logger.logToStderr(`Retrieving group by its name '${options.groupName}'`);
90
+ }
91
+ return await entraGroup.getGroupIdByDisplayName(options.groupName);
92
+ }
93
+ if (this.verbose) {
94
+ await logger.logToStderr(`Retrieving id of the current user`);
95
+ }
96
+ const token = auth.connection.accessTokens[auth.defaultResource].accessToken;
97
+ return accessToken.getUserIdFromAccessToken(token);
98
+ }
99
+ getDirectoryScope(options) {
100
+ if (options.administrativeUnitId) {
101
+ return `/administrativeUnits/${options.administrativeUnitId}`;
102
+ }
103
+ if (options.applicationId) {
104
+ return `/${options.applicationId}`;
105
+ }
106
+ return '/';
107
+ }
108
+ }
109
+ _EntraPimRoleAssignmentRemoveCommand_instances = new WeakSet(), _EntraPimRoleAssignmentRemoveCommand_initTelemetry = function _EntraPimRoleAssignmentRemoveCommand_initTelemetry() {
110
+ this.telemetry.push((args) => {
111
+ Object.assign(this.telemetryProperties, {
112
+ roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined',
113
+ roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
114
+ userId: typeof args.options.userId !== 'undefined',
115
+ userName: typeof args.options.userName !== 'undefined',
116
+ groupId: typeof args.options.groupId !== 'undefined',
117
+ groupName: typeof args.options.groupName !== 'undefined',
118
+ administrativeUnitId: typeof args.options.administrativeUnitId !== 'undefined',
119
+ applicationId: typeof args.options.applicationId !== 'undefined',
120
+ justification: typeof args.options.justification !== 'undefined',
121
+ ticketNumber: typeof args.options.ticketNumber !== 'undefined',
122
+ ticketSystem: typeof args.options.ticketSystem !== 'undefined'
123
+ });
124
+ });
125
+ }, _EntraPimRoleAssignmentRemoveCommand_initOptions = function _EntraPimRoleAssignmentRemoveCommand_initOptions() {
126
+ this.options.unshift({
127
+ option: '-n, --roleDefinitionName [roleDefinitionName]'
128
+ }, {
129
+ option: '-i, --roleDefinitionId [roleDefinitionId]'
130
+ }, {
131
+ option: "--userId [userId]"
132
+ }, {
133
+ option: "--userName [userName]"
134
+ }, {
135
+ option: "--groupId [groupId]"
136
+ }, {
137
+ option: "--groupName [groupName]"
138
+ }, {
139
+ option: "--administrativeUnitId [administrativeUnitId]"
140
+ }, {
141
+ option: "--applicationId [applicationId]"
142
+ }, {
143
+ option: "-j, --justification [justification]"
144
+ }, {
145
+ option: "--ticketNumber [ticketNumber]"
146
+ }, {
147
+ option: "--ticketSystem [ticketSystem]"
148
+ });
149
+ }, _EntraPimRoleAssignmentRemoveCommand_initValidators = function _EntraPimRoleAssignmentRemoveCommand_initValidators() {
150
+ this.validators.push(async (args) => {
151
+ if (args.options.roleDefinitionId && !validation.isValidGuid(args.options.roleDefinitionId)) {
152
+ return `${args.options.roleDefinitionId} is not a valid GUID`;
153
+ }
154
+ if (args.options.userId && !validation.isValidGuid(args.options.userId)) {
155
+ return `${args.options.userId} is not a valid GUID`;
156
+ }
157
+ if (args.options.groupId && !validation.isValidGuid(args.options.groupId)) {
158
+ return `${args.options.groupId} is not a valid GUID`;
159
+ }
160
+ if (args.options.administrativeUnitId && !validation.isValidGuid(args.options.administrativeUnitId)) {
161
+ return `${args.options.administrativeUnitId} is not a valid GUID`;
162
+ }
163
+ if (args.options.applicationId && !validation.isValidGuid(args.options.applicationId)) {
164
+ return `${args.options.applicationId} is not a valid GUID`;
165
+ }
166
+ return true;
167
+ });
168
+ }, _EntraPimRoleAssignmentRemoveCommand_initOptionSets = function _EntraPimRoleAssignmentRemoveCommand_initOptionSets() {
169
+ this.optionSets.push({ options: ['roleDefinitionName', 'roleDefinitionId'] });
170
+ this.optionSets.push({
171
+ options: ['userId', 'userName', 'groupId', 'groupName'],
172
+ runsWhen: (args) => {
173
+ return args.options.userId !== undefined || args.options.userName !== undefined || args.options.groupId !== undefined || args.options.groupName !== undefined;
174
+ }
175
+ });
176
+ this.optionSets.push({
177
+ options: ['administrativeUnitId', 'applicationId'],
178
+ runsWhen: (args) => {
179
+ return args.options.administrativeUnitId !== undefined || args.options.applicationId !== undefined;
180
+ }
181
+ });
182
+ }, _EntraPimRoleAssignmentRemoveCommand_initTypes = function _EntraPimRoleAssignmentRemoveCommand_initTypes() {
183
+ this.types.string.push('userId', 'userName', 'groupId', 'groupName', 'administrativeUnitId', 'applicationId', 'roleDefinitionName', 'roleDefinitionId', 'justification', 'ticketNumber', 'ticketSystem');
184
+ };
185
+ export default new EntraPimRoleAssignmentRemoveCommand();
186
+ //# sourceMappingURL=pim-role-assignment-remove.js.map
@@ -84,6 +84,7 @@ export default {
84
84
  OAUTH2GRANT_SET: `${prefix} oauth2grant set`,
85
85
  PIM_ROLE_ASSIGNMENT_ADD: `${prefix} pim role assignment add`,
86
86
  PIM_ROLE_ASSIGNMENT_LIST: `${prefix} pim role assignment list`,
87
+ PIM_ROLE_ASSIGNMENT_REMOVE: `${prefix} pim role assignment remove`,
87
88
  PIM_ROLE_ASSIGNMENT_ELIGIBILITY_LIST: `${prefix} pim role assignment eligibility list`,
88
89
  PIM_ROLE_REQUEST_LIST: `${prefix} pim role request list`,
89
90
  POLICY_LIST: `${prefix} policy list`,
@@ -0,0 +1,235 @@
1
+ import { z } from 'zod';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import { roleDefinition } from '../../../../utils/roleDefinition.js';
4
+ import { validation } from '../../../../utils/validation.js';
5
+ import GraphCommand from '../../../base/GraphCommand.js';
6
+ import commands from '../../commands.js';
7
+ import request from '../../../../request.js';
8
+ import { entraUser } from '../../../../utils/entraUser.js';
9
+ import { entraGroup } from '../../../../utils/entraGroup.js';
10
+ import { entraAdministrativeUnit } from '../../../../utils/entraAdministrativeUnit.js';
11
+ import { entraServicePrincipal } from '../../../../utils/entraServicePrincipal.js';
12
+ import { zod } from '../../../../utils/zod.js';
13
+ import { customAppScope } from '../../../../utils/customAppScope.js';
14
+ const options = globalOptionsZod
15
+ .extend({
16
+ roleDefinitionId: z.string().optional(),
17
+ roleDefinitionName: z.string().optional(),
18
+ principalId: z.string().optional(),
19
+ principalName: z.string().optional(),
20
+ scope: zod.alias('s', z.enum(['tenant', 'user', 'group', 'administrativeUnit', 'custom'])),
21
+ userId: z.string().optional(),
22
+ userName: z.string().optional(),
23
+ groupId: z.string().optional(),
24
+ groupName: z.string().optional(),
25
+ administrativeUnitId: z.string().optional(),
26
+ administrativeUnitName: z.string().optional(),
27
+ customAppScopeId: z.string().optional(),
28
+ customAppScopeName: z.string().optional()
29
+ })
30
+ .strict();
31
+ class ExoAppRoleAssignmentAddCommand extends GraphCommand {
32
+ get name() {
33
+ return commands.APPROLEASSIGNMENT_ADD;
34
+ }
35
+ get description() {
36
+ return `Grant permissions to an application that's accessing data in Exchange Online and specify which mailboxes an app can access.`;
37
+ }
38
+ get schema() {
39
+ return options;
40
+ }
41
+ getRefinedSchema(schema) {
42
+ return schema
43
+ .refine(options => !options.roleDefinitionId !== !options.roleDefinitionName, {
44
+ message: 'Specify either roleDefinitionId or roleDefinitionName, but not both'
45
+ })
46
+ .refine(options => options.roleDefinitionId || options.roleDefinitionName, {
47
+ message: 'Specify either roleDefinitionId or roleDefinitionName'
48
+ })
49
+ .refine(options => (!options.roleDefinitionId && !options.roleDefinitionName) || options.roleDefinitionName || (options.roleDefinitionId && validation.isValidGuid(options.roleDefinitionId)), options => ({
50
+ message: `The '${options.roleDefinitionId}' must be a valid GUID`,
51
+ path: ['roleDefinitionId']
52
+ }))
53
+ .refine(options => !options.principalId !== !options.principalName, {
54
+ message: 'Specify either principalId or principalName, but not both'
55
+ })
56
+ .refine(options => options.principalId || options.principalName, {
57
+ message: 'Specify either principalId or principalName'
58
+ })
59
+ .refine(options => (!options.principalId && !options.principalName) || options.principalName || (options.principalId && validation.isValidGuid(options.principalId)), options => ({
60
+ message: `The '${options.principalId}' must be a valid GUID`,
61
+ path: ['principalId']
62
+ }))
63
+ .refine(options => options.scope !== 'tenant' || Object.values([options.userId, options.userName, options.groupId, options.groupName, options.administrativeUnitId, options.administrativeUnitName, options.customAppScopeId, options.customAppScopeName]).filter(v => typeof v !== 'undefined').length === 0, {
64
+ message: "When the scope is set to 'tenant' then do not specify neither userId, userName, groupId, groupName, administrativeUnitId, administrativeUnitName, customAppScopeId nor customAppScopeName",
65
+ path: ['scope']
66
+ })
67
+ .refine(options => options.scope !== 'user' || Object.values([options.groupId, options.groupName, options.administrativeUnitId, options.administrativeUnitName, options.customAppScopeId, options.customAppScopeName]).filter(v => typeof v !== 'undefined').length === 0, {
68
+ message: "When the scope is set to 'user' then do not specify groupId, groupName, administrativeUnitId, administrativeUnitName, customAppScopeId nor customAppScopeName",
69
+ path: ['scope']
70
+ })
71
+ .refine(options => options.scope !== 'user' || (!options.userId !== !options.userName), {
72
+ message: "When the scope is set to 'user' specify either userId or userName, but not both",
73
+ path: ['scope']
74
+ })
75
+ .refine(options => options.scope !== 'user' || (options.userId || options.userName), {
76
+ message: "When the scope is set to 'user' specify either userId or userName",
77
+ path: ['scope']
78
+ })
79
+ .refine(options => options.scope !== 'user' || (!options.userId && !options.userName) || options.userName || (options.userId && validation.isValidGuid(options.userId)), options => ({
80
+ message: `The '${options.userId}' must be a valid GUID`,
81
+ path: ['userId']
82
+ }))
83
+ .refine(options => options.scope !== 'user' || (!options.userId && !options.userName) || options.userId || (options.userName && validation.isValidUserPrincipalName(options.userName)), options => ({
84
+ message: `The '${options.userId}' must be a valid GUID`,
85
+ path: ['userName']
86
+ }))
87
+ .refine(options => options.scope !== 'group' || Object.values([options.userId, options.userName, options.administrativeUnitId, options.administrativeUnitName, options.customAppScopeId, options.customAppScopeName]).filter(v => typeof v !== 'undefined').length === 0, {
88
+ message: "When the scope is set to 'group' then do not specify userId, userName, administrativeUnitId, administrativeUnitName, customAppScopeId nor customAppScopeName",
89
+ path: ['scope']
90
+ })
91
+ .refine(options => options.scope !== 'group' || (!options.groupId !== !options.groupName), {
92
+ message: "When the scope is set to 'group' specify either groupId or groupName, but not both",
93
+ path: ['scope']
94
+ })
95
+ .refine(options => options.scope !== 'group' || (options.groupId || options.groupName), {
96
+ message: "When the scope is set to 'group' specify either groupId or groupName",
97
+ path: ['scope']
98
+ })
99
+ .refine(options => options.scope !== 'group' || (!options.groupId && !options.groupName) || options.groupName || (options.groupId && validation.isValidGuid(options.groupId)), options => ({
100
+ message: `The '${options.groupId}' must be a valid GUID`,
101
+ path: ['groupId']
102
+ }))
103
+ .refine(options => options.scope !== 'administrativeUnit' || Object.values([options.userId, options.userName, options.groupId, options.groupName, options.customAppScopeId, options.customAppScopeName]).filter(v => typeof v !== 'undefined').length === 0, {
104
+ message: "When the scope is set to 'administrativeUnit' then do not specify userId, userName, groupId, groupName, customAppScopeId nor customAppScopeName",
105
+ path: ['scope']
106
+ })
107
+ .refine(options => options.scope !== 'administrativeUnit' || (!options.administrativeUnitId !== !options.administrativeUnitName), {
108
+ message: "When the scope is set to 'administrativeUnit' specify either administrativeUnitId or administrativeUnitName, but not both",
109
+ path: ['scope']
110
+ })
111
+ .refine(options => options.scope !== 'administrativeUnit' || (options.administrativeUnitId || options.administrativeUnitName), {
112
+ message: "When the scope is set to 'administrativeUnit' specify either administrativeUnitId or administrativeUnitName",
113
+ path: ['scope']
114
+ })
115
+ .refine(options => options.scope !== 'administrativeUnit' || (!options.administrativeUnitId && !options.administrativeUnitName) || options.administrativeUnitName || (options.administrativeUnitId && validation.isValidGuid(options.administrativeUnitId)), options => ({
116
+ message: `The '${options.administrativeUnitId}' must be a valid GUID`,
117
+ path: ['administrativeUnitId']
118
+ }))
119
+ .refine(options => options.scope !== 'custom' || Object.values([options.userId, options.userName, options.groupId, options.groupName, options.administrativeUnitId, options.administrativeUnitName]).filter(v => typeof v !== 'undefined').length === 0, {
120
+ message: "When the scope is set to 'custom' then do not specify userId, userName, groupId, groupName, administrativeUnitId nor administrativeUnitName",
121
+ path: ['scope']
122
+ })
123
+ .refine(options => options.scope !== 'custom' || (!options.customAppScopeId !== !options.customAppScopeName), {
124
+ message: "When the scope is set to 'custom' specify either customAppScopeId or customAppScopeName, but not both",
125
+ path: ['scope']
126
+ })
127
+ .refine(options => options.scope !== 'custom' || (options.customAppScopeId || options.customAppScopeName), {
128
+ message: "When the scope is set to 'custom' specify either customAppScopeId or customAppScopeName",
129
+ path: ['scope']
130
+ })
131
+ .refine(options => options.scope !== 'custom' || (!options.customAppScopeId && !options.customAppScopeName) || options.customAppScopeName || (options.customAppScopeId && validation.isValidGuid(options.customAppScopeId)), options => ({
132
+ message: `The '${options.customAppScopeId}' must be a valid GUID`,
133
+ path: ['customAppScopeId']
134
+ }));
135
+ }
136
+ async commandAction(logger, args) {
137
+ try {
138
+ const roleDefinitionId = await this.getRoleDefinitionId(args.options, logger);
139
+ const data = {
140
+ roleDefinitionId: roleDefinitionId,
141
+ principalId: await this.getPrincipalId(args.options, logger),
142
+ directoryScopeId: await this.getDirectoryScopeId(args.options),
143
+ appScopeId: await this.getAppScopeId(args.options, logger)
144
+ };
145
+ const requestOptions = {
146
+ url: `${this.resource}/beta/roleManagement/exchange/roleAssignments`,
147
+ headers: {
148
+ accept: 'application/json;odata.metadata=none'
149
+ },
150
+ responseType: 'json',
151
+ data: data
152
+ };
153
+ const response = await request.post(requestOptions);
154
+ await logger.log(response);
155
+ }
156
+ catch (err) {
157
+ this.handleRejectedODataJsonPromise(err);
158
+ }
159
+ }
160
+ async getRoleDefinitionId(options, logger) {
161
+ if (options.roleDefinitionId) {
162
+ return options.roleDefinitionId;
163
+ }
164
+ if (this.verbose) {
165
+ await logger.logToStderr(`Retrieving role definition by its name '${options.roleDefinitionName}'`);
166
+ }
167
+ const role = await roleDefinition.getExchangeRoleDefinitionByDisplayName(options.roleDefinitionName);
168
+ return role.id;
169
+ }
170
+ async getPrincipalId(options, logger) {
171
+ if (options.principalId) {
172
+ return `/ServicePrincipals/${options.principalId}`;
173
+ }
174
+ if (this.verbose) {
175
+ await logger.logToStderr(`Retrieving service principal by its name '${options.principalName}'`);
176
+ }
177
+ const principal = await entraServicePrincipal.getServicePrincipalByAppName(options.principalName, 'id');
178
+ return `/ServicePrincipals/${principal.id}`;
179
+ }
180
+ async getDirectoryScopeId(options) {
181
+ if (options.scope === 'custom') {
182
+ return null;
183
+ }
184
+ let prefix = '/';
185
+ let resourceId = '';
186
+ switch (options.scope) {
187
+ case 'tenant':
188
+ break;
189
+ case 'user':
190
+ prefix = '/users/';
191
+ if (options.userId) {
192
+ resourceId = options.userId;
193
+ }
194
+ else if (options.userName) {
195
+ resourceId = await entraUser.getUserIdByUpn(options.userName);
196
+ }
197
+ break;
198
+ case 'group':
199
+ prefix = '/groups/';
200
+ if (options.groupId) {
201
+ resourceId = options.groupId;
202
+ }
203
+ else if (options.groupName) {
204
+ resourceId = await entraGroup.getGroupIdByDisplayName(options.groupName);
205
+ }
206
+ break;
207
+ case 'administrativeUnit':
208
+ prefix = '/administrativeUnits/';
209
+ if (options.administrativeUnitId) {
210
+ resourceId = options.administrativeUnitId;
211
+ }
212
+ else if (options.administrativeUnitName) {
213
+ const administrativeUnit = await entraAdministrativeUnit.getAdministrativeUnitByDisplayName(options.administrativeUnitName);
214
+ resourceId = administrativeUnit.id;
215
+ }
216
+ break;
217
+ }
218
+ return `${prefix}${resourceId}`;
219
+ }
220
+ async getAppScopeId(options, logger) {
221
+ if (options.scope !== 'custom') {
222
+ return null;
223
+ }
224
+ if (options.customAppScopeId) {
225
+ return options.customAppScopeId;
226
+ }
227
+ if (this.verbose) {
228
+ await logger.logToStderr(`Retrieving custom application scope by its name '${options.customAppScopeName}'`);
229
+ }
230
+ const applicationScopeId = (await customAppScope.getCustomAppScopeByDisplayName(options.customAppScopeName, 'id')).id;
231
+ return applicationScopeId;
232
+ }
233
+ }
234
+ export default new ExoAppRoleAssignmentAddCommand();
235
+ //# sourceMappingURL=approleassignment-add.js.map
@@ -0,0 +1,5 @@
1
+ const prefix = 'exo';
2
+ export default {
3
+ APPROLEASSIGNMENT_ADD: `${prefix} approleassignment add`
4
+ };
5
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1,60 @@
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { powerPlatform } from '../../../../utils/powerPlatform.js';
3
+ import { validation } from '../../../../utils/validation.js';
4
+ import { zod } from '../../../../utils/zod.js';
5
+ import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js';
6
+ import commands from '../../commands.js';
7
+ import { z } from 'zod';
8
+ const options = globalOptionsZod
9
+ .extend({
10
+ url: zod.alias('u', z.string().optional()
11
+ .refine(url => url === undefined || validation.isValidPowerPagesUrl(url) === true, url => ({
12
+ message: `'${url}' is not a valid Power Pages URL.`
13
+ }))),
14
+ id: zod.alias('i', z.string().uuid().optional()),
15
+ name: zod.alias('n', z.string().optional()),
16
+ environmentName: zod.alias('e', z.string())
17
+ }).strict();
18
+ class PpWebSiteGetCommand extends PowerPlatformCommand {
19
+ get name() {
20
+ return commands.WEBSITE_GET;
21
+ }
22
+ get description() {
23
+ return 'Gets information about the specified Power Pages website.';
24
+ }
25
+ defaultProperties() {
26
+ return ['id', 'name', 'websiteUrl', 'tenantId', 'subdomain', 'type', 'status', 'siteVisibility'];
27
+ }
28
+ get schema() {
29
+ return options;
30
+ }
31
+ getRefinedSchema(schema) {
32
+ return schema
33
+ .refine(options => [options.url, options.id, options.name].filter(x => x !== undefined).length === 1, {
34
+ message: `Specify either url, id or name, but not multiple.`
35
+ });
36
+ }
37
+ async commandAction(logger, args) {
38
+ if (this.verbose) {
39
+ await logger.logToStderr(`Retrieving the website...`);
40
+ }
41
+ try {
42
+ let item = null;
43
+ if (args.options.id) {
44
+ item = await powerPlatform.getWebsiteById(args.options.environmentName, args.options.id);
45
+ }
46
+ else if (args.options.name) {
47
+ item = await powerPlatform.getWebsiteByName(args.options.environmentName, args.options.name);
48
+ }
49
+ else if (args.options.url) {
50
+ item = await powerPlatform.getWebsiteByUrl(args.options.environmentName, args.options.url);
51
+ }
52
+ await logger.log(item);
53
+ }
54
+ catch (err) {
55
+ this.handleRejectedODataJsonPromise(err);
56
+ }
57
+ }
58
+ }
59
+ export default new PpWebSiteGetCommand();
60
+ //# sourceMappingURL=website-get.js.map
@@ -33,6 +33,7 @@ export default {
33
33
  SOLUTION_PUBLISHER_LIST: `${prefix} solution publisher list`,
34
34
  SOLUTION_PUBLISHER_REMOVE: `${prefix} solution publisher remove`,
35
35
  TENANT_SETTINGS_LIST: `${prefix} tenant settings list`,
36
- TENANT_SETTINGS_SET: `${prefix} tenant settings set`
36
+ TENANT_SETTINGS_SET: `${prefix} tenant settings set`,
37
+ WEBSITE_GET: `${prefix} website get`
37
38
  };
38
39
  //# sourceMappingURL=commands.js.map
@@ -64,25 +64,12 @@ class SpoFolderRoleAssignmentAddCommand extends SpoCommand {
64
64
  const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
65
65
  principalId = siteUser.Id;
66
66
  }
67
- await this.breakRoleAssignment(requestUrl);
68
67
  await this.addRoleAssignment(requestUrl, principalId, roleDefinitionId);
69
68
  }
70
69
  catch (err) {
71
70
  this.handleRejectedODataJsonPromise(err);
72
71
  }
73
72
  }
74
- async breakRoleAssignment(requestUrl) {
75
- const requestOptions = {
76
- url: `${requestUrl}/breakroleinheritance(true)`,
77
- method: 'POST',
78
- headers: {
79
- 'accept': 'application/json;odata=nometadata',
80
- 'content-type': 'application/json'
81
- },
82
- responseType: 'json'
83
- };
84
- return request.post(requestOptions);
85
- }
86
73
  async addRoleAssignment(requestUrl, principalId, roleDefinitionId) {
87
74
  const requestOptions = {
88
75
  url: `${requestUrl}/roleassignments/addroleassignment(principalid='${principalId}',roledefid='${roleDefinitionId}')`,
@@ -0,0 +1,29 @@
1
+ import { cli } from '../cli/cli.js';
2
+ import { formatting } from './formatting.js';
3
+ import { odata } from './odata.js';
4
+ export const customAppScope = {
5
+ /**
6
+ * Get a custom application scope by its name
7
+ * @param displayName Custom application scope display name.
8
+ * @param properties Comma-separated list of properties to include in the response.
9
+ * @returns The custom application scope.
10
+ * @throws Error when role definition was not found.
11
+ */
12
+ async getCustomAppScopeByDisplayName(displayName, properties) {
13
+ let url = `https://graph.microsoft.com/beta/roleManagement/exchange/customAppScopes?$filter=displayName eq '${formatting.encodeQueryParameter(displayName)}'`;
14
+ if (properties) {
15
+ url += `&$select=${properties}`;
16
+ }
17
+ const customAppScopes = await odata.getAllItems(url);
18
+ if (customAppScopes.length === 0) {
19
+ throw `The specified custom application scope '${displayName}' does not exist.`;
20
+ }
21
+ if (customAppScopes.length > 1) {
22
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', customAppScopes);
23
+ const selectedCustomAppScope = await cli.handleMultipleResultsFound(`Multiple custom application scopes with name '${displayName}' found.`, resultAsKeyValuePair);
24
+ return selectedCustomAppScope;
25
+ }
26
+ return customAppScopes[0];
27
+ }
28
+ };
29
+ //# sourceMappingURL=customAppScope.js.map
@@ -0,0 +1,46 @@
1
+ import { odata } from './odata.js';
2
+ import { formatting } from './formatting.js';
3
+ import { cli } from '../cli/cli.js';
4
+ export const entraServicePrincipal = {
5
+ /**
6
+ * Get service principal by its appId
7
+ * @param appId App id.
8
+ * @param properties Comma-separated list of properties to include in the response.
9
+ * @returns The service principal.
10
+ * @throws Error when service principal was not found.
11
+ */
12
+ async getServicePrincipalByAppId(appId, properties) {
13
+ let url = `https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '${appId}'`;
14
+ if (properties) {
15
+ url += `&$select=${properties}`;
16
+ }
17
+ const apps = await odata.getAllItems(url);
18
+ if (apps.length === 0) {
19
+ throw `Service principal with appId '${appId}' not found in Microsoft Entra ID`;
20
+ }
21
+ return apps[0];
22
+ },
23
+ /**
24
+ * Get service principal by its name
25
+ * @param appName Service principal name.
26
+ * @param properties Comma-separated list of properties to include in the response.
27
+ * @returns The service principal.
28
+ * @throws Error when service principal was not found.
29
+ */
30
+ async getServicePrincipalByAppName(appName, properties) {
31
+ let url = `https://graph.microsoft.com/v1.0/servicePrincipals?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'`;
32
+ if (properties) {
33
+ url += `&$select=${properties}`;
34
+ }
35
+ const apps = await odata.getAllItems(url);
36
+ if (apps.length === 0) {
37
+ throw `Service principal with name '${appName}' not found in Microsoft Entra ID`;
38
+ }
39
+ if (apps.length > 1) {
40
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps);
41
+ return await cli.handleMultipleResultsFound(`Multiple service principals with name '${appName}' found in Microsoft Entra ID.`, resultAsKeyValuePair);
42
+ }
43
+ return apps[0];
44
+ }
45
+ };
46
+ //# sourceMappingURL=entraServicePrincipal.js.map