@pnp/cli-microsoft365 7.10.0-beta.a743796 → 7.10.0-beta.ebb7426

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.
package/dist/Auth.js CHANGED
@@ -235,12 +235,12 @@ export class Auth {
235
235
  let azureCloudInstance = AzureCloudInstance.None;
236
236
  switch (this.connection.cloudType) {
237
237
  case CloudType.Public:
238
+ case CloudType.USGov:
238
239
  azureCloudInstance = AzureCloudInstance.AzurePublic;
239
240
  break;
240
241
  case CloudType.China:
241
242
  azureCloudInstance = AzureCloudInstance.AzureChina;
242
243
  break;
243
- case CloudType.USGov:
244
244
  case CloudType.USGovHigh:
245
245
  case CloudType.USGovDoD:
246
246
  azureCloudInstance = AzureCloudInstance.AzureUsGovernment;
@@ -8,10 +8,11 @@ import { settingsNames } from '../settingsNames.js';
8
8
  import { md } from '../utils/md.js';
9
9
  import { prompt } from '../utils/prompt.js';
10
10
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
11
+ const mendableBaseUrl = 'https://api.mendable.ai/v1';
11
12
  const mendableApiKey = 'd3313d54-6f8e-40e0-90d3-4095019d4be7';
13
+ const spinner = ora({ discardStdin: false });
12
14
  let showHelp = false;
13
15
  let debug = false;
14
- let promptForRating = true;
15
16
  let conversationId = 0;
16
17
  let initialPrompt = '';
17
18
  let history = [];
@@ -54,15 +55,6 @@ function getPromptFromArgs(args) {
54
55
  // reset to default. needed for tests
55
56
  debug = false;
56
57
  }
57
- const noRatingPos = args.indexOf('--no-rating');
58
- if (noRatingPos > -1) {
59
- promptForRating = false;
60
- args.splice(noRatingPos, 1);
61
- }
62
- else {
63
- // reset to default. needed for tests
64
- promptForRating = true;
65
- }
66
58
  return args.join(' ');
67
59
  }
68
60
  async function startConversation(args) {
@@ -82,9 +74,9 @@ async function promptForPrompt() {
82
74
  }
83
75
  async function runConversationTurn(conversationId, question) {
84
76
  console.log('');
85
- const spinner = ora('Searching documentation...');
86
- /* c8 ignore next 3 */
77
+ /* c8 ignore next 4 */
87
78
  if (showSpinner) {
79
+ spinner.text = 'Searching documentation...';
88
80
  spinner.start();
89
81
  }
90
82
  const response = await runMendableChat(conversationId, question);
@@ -103,17 +95,6 @@ async function runConversationTurn(conversationId, question) {
103
95
  const sources = response.sources.filter((src, index, self) => index === self.findIndex(s => s.link === src.link));
104
96
  sources.forEach(src => console.log(`⬥ ${src.link}`));
105
97
  console.log('');
106
- if (promptForRating) {
107
- try {
108
- await rateResponse(response.message_id);
109
- }
110
- catch (err) {
111
- if (debug) {
112
- console.error(`An error has occurred while rating the response: ${err}`);
113
- }
114
- }
115
- console.log('');
116
- }
117
98
  const choices = [
118
99
  {
119
100
  name: '📝 I want to know more',
@@ -145,58 +126,9 @@ async function runConversationTurn(conversationId, question) {
145
126
  break;
146
127
  }
147
128
  }
148
- async function rateResponse(messageId) {
149
- const choices = [
150
- {
151
- name: '👍 Yes',
152
- value: 1
153
- },
154
- {
155
- name: '👎 No',
156
- value: -1
157
- },
158
- {
159
- name: '🤔 Not sure/skip',
160
- value: 0
161
- }
162
- ];
163
- const rating = await prompt.forSelection({ message: 'Was this helpful?', choices });
164
- if (rating === 0) {
165
- return;
166
- }
167
- console.log('Thanks for letting us know! 😊');
168
- const requestOptions = {
169
- url: 'https://api.mendable.ai/v0/rateMessage',
170
- headers: {
171
- 'content-type': 'application/json',
172
- 'x-anonymous': true
173
- },
174
- responseType: 'json',
175
- data: {
176
- // eslint-disable-next-line camelcase
177
- api_key: mendableApiKey,
178
- // eslint-disable-next-line camelcase
179
- conversation_id: conversationId,
180
- // eslint-disable-next-line camelcase
181
- message_id: messageId,
182
- // eslint-disable-next-line camelcase
183
- rating_value: rating
184
- }
185
- };
186
- const spinner = ora('Sending rating...');
187
- /* c8 ignore next 3 */
188
- if (showSpinner) {
189
- spinner.start();
190
- }
191
- await request.post(requestOptions);
192
- /* c8 ignore next 3 */
193
- if (showSpinner) {
194
- spinner.stop();
195
- }
196
- }
197
129
  async function endConversation(conversationId) {
198
130
  const requestOptions = {
199
- url: 'https://api.mendable.ai/v0/endConversation',
131
+ url: `${mendableBaseUrl}/endConversation`,
200
132
  headers: {
201
133
  'content-type': 'application/json',
202
134
  'x-anonymous': true
@@ -209,9 +141,9 @@ async function endConversation(conversationId) {
209
141
  conversation_id: conversationId
210
142
  }
211
143
  };
212
- const spinner = ora('Ending conversation...');
213
- /* c8 ignore next 3 */
144
+ /* c8 ignore next 4 */
214
145
  if (showSpinner) {
146
+ spinner.text = 'Ending conversation...';
215
147
  spinner.start();
216
148
  }
217
149
  await request.post(requestOptions);
@@ -222,7 +154,7 @@ async function endConversation(conversationId) {
222
154
  }
223
155
  async function runMendableChat(conversationId, question) {
224
156
  const requestOptions = {
225
- url: 'https://api.mendable.ai/v0/mendableChat',
157
+ url: `${mendableBaseUrl}/mendableChat`,
226
158
  headers: {
227
159
  'content-type': 'application/json',
228
160
  'x-anonymous': true
@@ -242,7 +174,7 @@ async function runMendableChat(conversationId, question) {
242
174
  }
243
175
  async function getConversationId() {
244
176
  const requestOptions = {
245
- url: 'https://api.mendable.ai/v0/newConversation',
177
+ url: `${mendableBaseUrl}/newConversation`,
246
178
  headers: {
247
179
  'content-type': 'application/json',
248
180
  'x-anonymous': true
@@ -0,0 +1,287 @@
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 _EntraAppPermissionRemoveCommand_instances, _EntraAppPermissionRemoveCommand_initTelemetry, _EntraAppPermissionRemoveCommand_initOptions, _EntraAppPermissionRemoveCommand_initValidators, _EntraAppPermissionRemoveCommand_initOptionSets, _EntraAppPermissionRemoveCommand_initTypes;
7
+ import { odata } from "../../../../utils/odata.js";
8
+ import GraphCommand from "../../../base/GraphCommand.js";
9
+ import commands from "../../commands.js";
10
+ import request from "../../../../request.js";
11
+ import { validation } from "../../../../utils/validation.js";
12
+ import { cli } from "../../../../cli/cli.js";
13
+ import { formatting } from "../../../../utils/formatting.js";
14
+ var ScopeType;
15
+ (function (ScopeType) {
16
+ ScopeType["Role"] = "Role";
17
+ ScopeType["Scope"] = "Scope";
18
+ })(ScopeType || (ScopeType = {}));
19
+ class EntraAppPermissionRemoveCommand extends GraphCommand {
20
+ get name() {
21
+ return commands.APP_PERMISSION_REMOVE;
22
+ }
23
+ get description() {
24
+ return 'Removes the specified application and/or delegated permissions from a specified Microsoft Entra app';
25
+ }
26
+ constructor() {
27
+ super();
28
+ _EntraAppPermissionRemoveCommand_instances.add(this);
29
+ __classPrivateFieldGet(this, _EntraAppPermissionRemoveCommand_instances, "m", _EntraAppPermissionRemoveCommand_initTelemetry).call(this);
30
+ __classPrivateFieldGet(this, _EntraAppPermissionRemoveCommand_instances, "m", _EntraAppPermissionRemoveCommand_initOptions).call(this);
31
+ __classPrivateFieldGet(this, _EntraAppPermissionRemoveCommand_instances, "m", _EntraAppPermissionRemoveCommand_initValidators).call(this);
32
+ __classPrivateFieldGet(this, _EntraAppPermissionRemoveCommand_instances, "m", _EntraAppPermissionRemoveCommand_initOptionSets).call(this);
33
+ __classPrivateFieldGet(this, _EntraAppPermissionRemoveCommand_instances, "m", _EntraAppPermissionRemoveCommand_initTypes).call(this);
34
+ }
35
+ async commandAction(logger, args) {
36
+ const removeAppPermissions = async () => {
37
+ try {
38
+ if (this.verbose) {
39
+ await logger.logToStderr(`Removing permissions from application ${args.options.appId || args.options.appObjectId || args.options.appName}...`);
40
+ }
41
+ const appObject = await this.getAppObject(args.options);
42
+ const servicePrincipals = await odata.getAllItems(`${this.resource}/v1.0/servicePrincipals?$select=appId,appRoles,id,oauth2PermissionScopes,servicePrincipalNames`);
43
+ const appPermissions = [];
44
+ if (args.options.delegatedPermissions) {
45
+ const delegatedPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.delegatedPermissions, ScopeType.Scope, appPermissions, logger);
46
+ this.removePermissionsFromResourceArray(delegatedPermissions, appObject.requiredResourceAccess);
47
+ }
48
+ if (args.options.applicationPermissions) {
49
+ const applicationPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.applicationPermissions, ScopeType.Role, appPermissions, logger);
50
+ this.removePermissionsFromResourceArray(applicationPermissions, appObject.requiredResourceAccess);
51
+ }
52
+ const removePermissionRequestOptions = {
53
+ url: `${this.resource}/v1.0/applications/${appObject.id}`,
54
+ headers: {
55
+ accept: 'application/json;odata.metadata=none'
56
+ },
57
+ responseType: 'json',
58
+ data: {
59
+ requiredResourceAccess: appObject.requiredResourceAccess
60
+ }
61
+ };
62
+ await request.patch(removePermissionRequestOptions);
63
+ if (args.options.revokeAdminConsent) {
64
+ const appServicePrincipal = servicePrincipals.find(sp => sp.appId === appObject.appId);
65
+ await this.revokeAdminConsent(appServicePrincipal, appPermissions, logger);
66
+ }
67
+ }
68
+ catch (err) {
69
+ this.handleRejectedODataJsonPromise(err);
70
+ }
71
+ };
72
+ if (args.options.force) {
73
+ await removeAppPermissions();
74
+ }
75
+ else {
76
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the permissions from the specified application ${args.options.appId || args.options.appObjectId || args.options.appName}?` });
77
+ if (result) {
78
+ await removeAppPermissions();
79
+ }
80
+ }
81
+ }
82
+ async getAppObject(options) {
83
+ const selectProperties = '$select=id,appId,requiredResourceAccess';
84
+ if (options.appObjectId) {
85
+ const requestOptions = {
86
+ url: `${this.resource}/v1.0/applications/${options.appObjectId}?${selectProperties}`,
87
+ headers: {
88
+ 'content-type': 'application/json;odata.metadata=none'
89
+ },
90
+ responseType: 'json'
91
+ };
92
+ return request.get(requestOptions);
93
+ }
94
+ const apps = options.appId
95
+ ? await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=appId eq '${options.appId}'&${selectProperties}`)
96
+ : await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=displayName eq '${options.appName}'&${selectProperties}`);
97
+ if (apps.length === 0) {
98
+ throw `App with ${options.appId ? 'id' : 'name'} ${options.appId || options.appName} not found in Microsoft Entra ID`;
99
+ }
100
+ if (apps.length > 1) {
101
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps);
102
+ return cli.handleMultipleResultsFound(`Multiple apps with name '${options.appName}' found.`, resultAsKeyValuePair);
103
+ }
104
+ return apps[0];
105
+ }
106
+ async revokeAdminConsent(servicePrincipal, appPermissions, logger) {
107
+ // Check if contains app permissions
108
+ let appRoleAssignments;
109
+ let oAuth2RoleAssignments;
110
+ if (appPermissions.some(perm => perm.resourceAccess.filter(acc => acc.type === ScopeType.Role).length > 0)) {
111
+ // Retrieve app role assignments from service application
112
+ appRoleAssignments = await odata.getAllItems(`${this.resource}/v1.0/servicePrincipals/${servicePrincipal.id}/appRoleAssignments?$select=id,appRoleId,resourceId`);
113
+ }
114
+ if (appPermissions.filter(perm => perm.scope.length > 0).length > 0) {
115
+ // Retrieve app role assignments from service application
116
+ oAuth2RoleAssignments = await odata.getAllItems(`${this.resource}/v1.0/servicePrincipals/${servicePrincipal.id}/oAuth2PermissionGrants?$select=id,resourceId,scope`);
117
+ }
118
+ for await (const permission of appPermissions) {
119
+ if (permission.scope.length > 0) {
120
+ if (this.verbose) {
121
+ await logger.logToStderr(`Revoking consent for delegated permission(s) with resourceId ${permission.resourceId} and scope(s) ${permission.scope.join(' ')}`);
122
+ }
123
+ const oAuth2RoleAssignment = oAuth2RoleAssignments.find(y => y.resourceId === permission.resourceId);
124
+ if (oAuth2RoleAssignment) {
125
+ const scopes = oAuth2RoleAssignment?.scope?.split(' ');
126
+ permission.scope.forEach(scope => {
127
+ scopes.splice(scopes.indexOf(scope), 1);
128
+ });
129
+ oAuth2RoleAssignment.scope = scopes.join(' ');
130
+ await this.revokeOAuth2Permission(oAuth2RoleAssignment);
131
+ }
132
+ }
133
+ for await (const access of permission.resourceAccess.filter(acc => acc.type === ScopeType.Role)) {
134
+ if (this.verbose) {
135
+ await logger.logToStderr(`Revoking consent for application permission with resourceId ${permission.resourceId} and appRoleId ${access.id}`);
136
+ }
137
+ const appRoleAssignmentToRemove = appRoleAssignments.find(y => y.resourceId === permission.resourceId && y.appRoleId === access.id);
138
+ if (appRoleAssignmentToRemove) {
139
+ await this.revokeApplicationPermission(servicePrincipal.id, appRoleAssignmentToRemove.id);
140
+ }
141
+ }
142
+ }
143
+ }
144
+ async revokeOAuth2Permission(oAuth2RoleAssignment) {
145
+ const revokeRequestOptions = {
146
+ url: `${this.resource}/v1.0/oauth2PermissionGrants/${oAuth2RoleAssignment.id}`,
147
+ headers: {
148
+ accept: 'application/json;odata.metadata=none'
149
+ },
150
+ responseType: 'json',
151
+ data: oAuth2RoleAssignment
152
+ };
153
+ return request.patch(revokeRequestOptions);
154
+ }
155
+ async revokeApplicationPermission(servicePrincipalId, id) {
156
+ const requestOptions = {
157
+ url: `${this.resource}/v1.0/servicePrincipals/${servicePrincipalId}/appRoleAssignments/${id}`,
158
+ headers: {
159
+ accept: 'application/json;odata.metadata=none'
160
+ },
161
+ responseType: 'json'
162
+ };
163
+ return request.delete(requestOptions);
164
+ }
165
+ async getRequiredResourceAccessForApis(servicePrincipals, apis, scopeType, appPermissions, logger) {
166
+ const resolvedApis = [];
167
+ const requestedApis = apis.split(' ').map(a => a.trim());
168
+ for await (const api of requestedApis) {
169
+ const pos = api.lastIndexOf('/');
170
+ const permissionName = api.substring(pos + 1);
171
+ const servicePrincipalName = api.substring(0, pos);
172
+ if (this.verbose) {
173
+ await logger.logToStderr(`Resolving ${api}...`);
174
+ await logger.logToStderr(`Permission name: ${permissionName}`);
175
+ await logger.logToStderr(`Service principal name: ${servicePrincipalName}`);
176
+ }
177
+ const servicePrincipal = servicePrincipals.find(sp => (sp.servicePrincipalNames.indexOf(servicePrincipalName) > -1 ||
178
+ sp.servicePrincipalNames.indexOf(`${servicePrincipalName}/`) > -1));
179
+ if (!servicePrincipal) {
180
+ throw `Service principal ${servicePrincipalName} not found`;
181
+ }
182
+ let permission;
183
+ if (scopeType === ScopeType.Scope) {
184
+ permission = servicePrincipal.oauth2PermissionScopes.find(scope => scope.value === permissionName);
185
+ }
186
+ else if (scopeType === ScopeType.Role) {
187
+ permission = servicePrincipal.appRoles.find(scope => scope.value === permissionName);
188
+ }
189
+ if (!permission) {
190
+ throw `Permission ${permissionName} for service principal ${servicePrincipalName} not found`;
191
+ }
192
+ let resolvedApi = resolvedApis.find(a => a.resourceAppId === servicePrincipal.appId);
193
+ if (!resolvedApi) {
194
+ resolvedApi = {
195
+ resourceAppId: servicePrincipal.appId,
196
+ resourceAccess: []
197
+ };
198
+ resolvedApis.push(resolvedApi);
199
+ }
200
+ const resourceAccessPermission = {
201
+ id: permission.id,
202
+ type: scopeType
203
+ };
204
+ resolvedApi.resourceAccess.push(resourceAccessPermission);
205
+ this.updateAppPermissions(servicePrincipal.id, resourceAccessPermission, permission.value, appPermissions);
206
+ }
207
+ return resolvedApis;
208
+ }
209
+ updateAppPermissions(spId, resourceAccessPermission, oAuth2PermissionValue, appPermissions) {
210
+ let existingPermission = appPermissions.find(oauth => oauth.resourceId === spId);
211
+ if (!existingPermission) {
212
+ existingPermission = {
213
+ resourceId: spId,
214
+ resourceAccess: [],
215
+ scope: []
216
+ };
217
+ appPermissions.push(existingPermission);
218
+ }
219
+ if (resourceAccessPermission.type === ScopeType.Scope && oAuth2PermissionValue && !existingPermission.scope.find(scp => scp === oAuth2PermissionValue)) {
220
+ existingPermission.scope.push(oAuth2PermissionValue);
221
+ }
222
+ if (!existingPermission.resourceAccess.find(res => res.id === resourceAccessPermission.id)) {
223
+ existingPermission.resourceAccess.push(resourceAccessPermission);
224
+ }
225
+ }
226
+ removePermissionsFromResourceArray(permissions, existingArray) {
227
+ permissions.forEach(resolvedRequiredResource => {
228
+ const requiredResource = existingArray?.find(api => api.resourceAppId === resolvedRequiredResource.resourceAppId);
229
+ if (requiredResource) {
230
+ resolvedRequiredResource.resourceAccess.forEach(resolvedResourceAccess => {
231
+ requiredResource.resourceAccess = requiredResource.resourceAccess.filter(ra => ra.id !== resolvedResourceAccess.id);
232
+ });
233
+ }
234
+ });
235
+ }
236
+ }
237
+ _EntraAppPermissionRemoveCommand_instances = new WeakSet(), _EntraAppPermissionRemoveCommand_initTelemetry = function _EntraAppPermissionRemoveCommand_initTelemetry() {
238
+ this.telemetry.push((args) => {
239
+ Object.assign(this.telemetryProperties, {
240
+ appId: typeof args.options.appId !== 'undefined',
241
+ appObjectId: typeof args.options.appObjectId !== 'undefined',
242
+ appName: typeof args.options.appName !== 'undefined',
243
+ applicationPermissions: typeof args.options.applicationPermissions !== 'undefined',
244
+ delegatedPermissions: typeof args.options.delegatedPermissions !== 'undefined',
245
+ revokeAdminConsent: !!args.options.revokeAdminConsent,
246
+ force: !!args.options.force
247
+ });
248
+ });
249
+ }, _EntraAppPermissionRemoveCommand_initOptions = function _EntraAppPermissionRemoveCommand_initOptions() {
250
+ this.options.unshift({
251
+ option: '-i, --appId [appId]'
252
+ }, {
253
+ option: '--appObjectId [appObjectId]'
254
+ }, {
255
+ option: '-n, --appName [appName]'
256
+ }, {
257
+ option: '-a, --applicationPermissions [applicationPermissions]'
258
+ }, {
259
+ option: '-d, --delegatedPermissions [delegatedPermissions]'
260
+ }, {
261
+ option: '--revokeAdminConsent'
262
+ }, {
263
+ option: '--force'
264
+ });
265
+ }, _EntraAppPermissionRemoveCommand_initValidators = function _EntraAppPermissionRemoveCommand_initValidators() {
266
+ this.validators.push(async (args) => {
267
+ if (args.options.appId && !validation.isValidGuid(args.options.appId)) {
268
+ return `${args.options.appId} is not a valid GUID`;
269
+ }
270
+ if (args.options.appObjectId && !validation.isValidGuid(args.options.appObjectId)) {
271
+ return `${args.options.appObjectId} is not a valid GUID`;
272
+ }
273
+ return true;
274
+ });
275
+ }, _EntraAppPermissionRemoveCommand_initOptionSets = function _EntraAppPermissionRemoveCommand_initOptionSets() {
276
+ this.optionSets.push({
277
+ options: ['appId', 'appObjectId', 'appName']
278
+ }, {
279
+ options: ['applicationPermissions', 'delegatedPermissions'],
280
+ runsWhen: (args) => args.options.delegatedPermissions === undefined && args.options.applicationPermissions === undefined
281
+ });
282
+ }, _EntraAppPermissionRemoveCommand_initTypes = function _EntraAppPermissionRemoveCommand_initTypes() {
283
+ this.types.string.push('appId', 'appObjectId', 'appName', 'applicationPermissions', 'delegatedPermissions');
284
+ this.types.boolean.push('revokeAdminConsent');
285
+ };
286
+ export default new EntraAppPermissionRemoveCommand();
287
+ //# sourceMappingURL=app-permission-remove.js.map
@@ -16,6 +16,7 @@ export default {
16
16
  APP_SET: `${prefix} app set`,
17
17
  APP_PERMISSION_ADD: `${prefix} app permission add`,
18
18
  APP_PERMISSION_LIST: `${prefix} app permission list`,
19
+ APP_PERMISSION_REMOVE: `${prefix} app permission remove`,
19
20
  APP_ROLE_ADD: `${prefix} app role add`,
20
21
  APP_ROLE_LIST: `${prefix} app role list`,
21
22
  APP_ROLE_REMOVE: `${prefix} app role remove`,