@pnp/cli-microsoft365 7.10.0-beta.ebb7426 → 7.11.0-beta.c513557

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,144 @@
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 _SpoSiteAdminListCommand_instances, _SpoSiteAdminListCommand_initTelemetry, _SpoSiteAdminListCommand_initOptions, _SpoSiteAdminListCommand_initValidators, _SpoSiteAdminListCommand_initTypes;
7
+ import request from '../../../../request.js';
8
+ import { spo } from '../../../../utils/spo.js';
9
+ import { validation } from '../../../../utils/validation.js';
10
+ import SpoCommand from '../../../base/SpoCommand.js';
11
+ import commands from '../../commands.js';
12
+ import { ListPrincipalType } from '../list/ListPrincipalType.js';
13
+ class SpoSiteAdminListCommand extends SpoCommand {
14
+ get name() {
15
+ return commands.SITE_ADMIN_LIST;
16
+ }
17
+ get description() {
18
+ return 'Lists all administrators of a specific SharePoint site';
19
+ }
20
+ constructor() {
21
+ super();
22
+ _SpoSiteAdminListCommand_instances.add(this);
23
+ __classPrivateFieldGet(this, _SpoSiteAdminListCommand_instances, "m", _SpoSiteAdminListCommand_initTelemetry).call(this);
24
+ __classPrivateFieldGet(this, _SpoSiteAdminListCommand_instances, "m", _SpoSiteAdminListCommand_initOptions).call(this);
25
+ __classPrivateFieldGet(this, _SpoSiteAdminListCommand_instances, "m", _SpoSiteAdminListCommand_initValidators).call(this);
26
+ __classPrivateFieldGet(this, _SpoSiteAdminListCommand_instances, "m", _SpoSiteAdminListCommand_initTypes).call(this);
27
+ }
28
+ async commandAction(logger, args) {
29
+ try {
30
+ if (args.options.asAdmin) {
31
+ await this.callActionAsAdmin(logger, args);
32
+ return;
33
+ }
34
+ await this.callAction(logger, args);
35
+ }
36
+ catch (err) {
37
+ this.handleRejectedODataJsonPromise(err);
38
+ }
39
+ }
40
+ async callActionAsAdmin(logger, args) {
41
+ if (this.verbose) {
42
+ await logger.logToStderr('Retrieving site administrators as an administrator...');
43
+ }
44
+ const adminUrl = await spo.getSpoAdminUrl(logger, this.debug);
45
+ const siteId = await this.getSiteId(args.options.siteUrl, logger);
46
+ const requestOptions = {
47
+ url: `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`,
48
+ headers: {
49
+ accept: 'application/json;odata=nometadata',
50
+ 'content-type': 'application/json;charset=utf-8'
51
+ }
52
+ };
53
+ const response = await request.post(requestOptions);
54
+ const responseContent = JSON.parse(response);
55
+ const primaryAdminLoginName = await this.getPrimaryAdminLoginNameFromAdmin(adminUrl, siteId);
56
+ const mappedResult = responseContent.value.map((u) => ({
57
+ Id: null,
58
+ Email: u.email,
59
+ LoginName: u.loginName,
60
+ Title: u.name,
61
+ PrincipalType: null,
62
+ PrincipalTypeString: null,
63
+ IsPrimaryAdmin: u.loginName === primaryAdminLoginName
64
+ }));
65
+ await logger.log(mappedResult);
66
+ }
67
+ async getSiteId(siteUrl, logger) {
68
+ const siteGraphId = await spo.getSiteId(siteUrl, logger, this.verbose);
69
+ const match = siteGraphId.match(/,([a-f0-9\-]{36}),/i);
70
+ if (!match) {
71
+ throw `Site with URL ${siteUrl} not found`;
72
+ }
73
+ return match[1];
74
+ }
75
+ async getPrimaryAdminLoginNameFromAdmin(adminUrl, siteId) {
76
+ const requestOptions = {
77
+ url: `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`,
78
+ headers: {
79
+ accept: 'application/json;odata=nometadata',
80
+ 'content-type': 'application/json;charset=utf-8'
81
+ }
82
+ };
83
+ const response = await request.get(requestOptions);
84
+ const responseContent = JSON.parse(response);
85
+ return responseContent.OwnerLoginName;
86
+ }
87
+ async callAction(logger, args) {
88
+ if (this.verbose) {
89
+ await logger.logToStderr('Retrieving site administrators...');
90
+ }
91
+ const requestOptions = {
92
+ url: `${args.options.siteUrl}/_api/web/siteusers?$filter=IsSiteAdmin eq true`,
93
+ method: 'GET',
94
+ headers: {
95
+ 'accept': 'application/json;odata=nometadata'
96
+ },
97
+ responseType: 'json'
98
+ };
99
+ const responseContent = await request.get(requestOptions);
100
+ const primaryOwnerLogin = await this.getPrimaryOwnerLoginFromSite(args.options.siteUrl);
101
+ const mappedResult = responseContent.value.map((u) => ({
102
+ Id: u.Id,
103
+ LoginName: u.LoginName,
104
+ Title: u.Title,
105
+ PrincipalType: u.PrincipalType,
106
+ PrincipalTypeString: ListPrincipalType[u.PrincipalType],
107
+ Email: u.Email,
108
+ IsPrimaryAdmin: u.LoginName === primaryOwnerLogin
109
+ }));
110
+ await logger.log(mappedResult);
111
+ }
112
+ async getPrimaryOwnerLoginFromSite(siteUrl) {
113
+ const requestOptions = {
114
+ url: `${siteUrl}/_api/site/owner`,
115
+ method: 'GET',
116
+ headers: {
117
+ 'accept': 'application/json;odata=nometadata'
118
+ },
119
+ responseType: 'json'
120
+ };
121
+ const responseContent = await request.get(requestOptions);
122
+ return responseContent?.LoginName ?? null;
123
+ }
124
+ }
125
+ _SpoSiteAdminListCommand_instances = new WeakSet(), _SpoSiteAdminListCommand_initTelemetry = function _SpoSiteAdminListCommand_initTelemetry() {
126
+ this.telemetry.push((args) => {
127
+ Object.assign(this.telemetryProperties, {
128
+ siteUrl: typeof args.options.siteUrl !== 'undefined',
129
+ asAdmin: !!args.options.asAdmin
130
+ });
131
+ });
132
+ }, _SpoSiteAdminListCommand_initOptions = function _SpoSiteAdminListCommand_initOptions() {
133
+ this.options.unshift({
134
+ option: '-u, --siteUrl <siteUrl>'
135
+ }, {
136
+ option: '--asAdmin'
137
+ });
138
+ }, _SpoSiteAdminListCommand_initValidators = function _SpoSiteAdminListCommand_initValidators() {
139
+ this.validators.push(async (args) => validation.isValidSharePointUrl(args.options.siteUrl));
140
+ }, _SpoSiteAdminListCommand_initTypes = function _SpoSiteAdminListCommand_initTypes() {
141
+ this.types.string.push('siteUrl');
142
+ };
143
+ export default new SpoSiteAdminListCommand();
144
+ //# sourceMappingURL=site-admin-list.js.map
@@ -239,6 +239,7 @@ export default {
239
239
  SERVICEPRINCIPAL_SET: `${prefix} serviceprincipal set`,
240
240
  SET: `${prefix} set`,
241
241
  SITE_ADD: `${prefix} site add`,
242
+ SITE_ADMIN_LIST: `${prefix} site admin list`,
242
243
  SITE_APPCATALOG_ADD: `${prefix} site appcatalog add`,
243
244
  SITE_APPCATALOG_LIST: `${prefix} site appcatalog list`,
244
245
  SITE_APPCATALOG_REMOVE: `${prefix} site appcatalog remove`,
@@ -14,19 +14,19 @@ m365 entra app permission remove [options]
14
14
 
15
15
  ```md definition-list
16
16
  `-i, --appId [appId]`
17
- : Client ID of the Microsoft Entra app to add the API permissions to. Specify either `appId`, `appName` or `appObjectId`.
17
+ : Client ID of the Microsoft Entra app to remove the API permissions from. Specify either `appId`, `appName` or `appObjectId`.
18
18
 
19
19
  `--appObjectId [appObjectId]`
20
- : Object ID of the Microsoft Entra app to add the API permissions to. Specify either `appId`, `appName` or `appObjectId`.
20
+ : Object ID of the Microsoft Entra app to remove the API permissions from. Specify either `appId`, `appName` or `appObjectId`.
21
21
 
22
22
  `-n, --appName [appName]`
23
23
  : Display name of the Entra app to remove the API permissions from. Specify either `appId`, `appName` or `appObjectId`.
24
24
 
25
25
  `-a, --applicationPermissions [applicationPermissions]`
26
- : Space-separated list of application permissions to add. Specify at least `applicationPermissions` or `delegatedPermissions`.
26
+ : Space-separated list of application permissions to remove. Specify at least `applicationPermissions` or `delegatedPermissions`.
27
27
 
28
28
  `-d, --delegatedPermissions [delegatedPermissions]`
29
- : Space-separated list of delegated permissions to add. Specify at least `applicationPermissions` or `delegatedPermissions`.
29
+ : Space-separated list of delegated permissions to remove. Specify at least `applicationPermissions` or `delegatedPermissions`.
30
30
 
31
31
  `--revokeAdminConsent`
32
32
  : When specified, revokes the admin consent for the specified permissions as well.
@@ -0,0 +1,115 @@
1
+ import Global from '/docs/cmd/_global.mdx';
2
+ import Tabs from '@theme/Tabs';
3
+ import TabItem from '@theme/TabItem';
4
+
5
+ # spo site admin list
6
+
7
+ Lists all administrators of a specific SharePoint site
8
+
9
+ ## Usage
10
+
11
+ ```sh
12
+ m365 spo site admin list [options]
13
+ ```
14
+
15
+ ## Options
16
+
17
+ ```md definition-list
18
+ `-u, --siteUrl <siteUrl>`
19
+ : The URL of the SharePoint site
20
+
21
+ `--asAdmin`
22
+ : List admins as admin for sites you don't have permission to
23
+ ```
24
+
25
+ <Global />
26
+
27
+ ## Remarks
28
+
29
+ :::info
30
+
31
+ To use this command with the `--asAdmin` mode, you must have permission to access the tenant admin site.
32
+
33
+ Without this parameter, you must have site collection admin permissions for the requested site.
34
+
35
+ In `--asAdmin` mode, the Id, PrincipalType, and PrincipalTypeString properties are not exported.
36
+
37
+ :::
38
+
39
+ ## Examples
40
+
41
+ Lists all admins of a SharePoint site
42
+
43
+ ```sh
44
+ m365 spo site admin list --siteUrl https://contoso.sharepoint.com
45
+ ```
46
+
47
+ Lists all admins of a SharePoint site as admin
48
+
49
+ ```sh
50
+ m365 spo site admin list --siteUrl https://contoso.sharepoint.com --asAdmin
51
+ ```
52
+
53
+ ## Response
54
+
55
+ <Tabs>
56
+ <TabItem value="JSON">
57
+
58
+ ```json
59
+ [
60
+ {
61
+ "Id": 6,
62
+ "LoginName": "i:0#.f|membership|user@contoso.com",
63
+ "Title": "User Example",
64
+ "PrincipalType": 1,
65
+ "PrincipalTypeString": "User",
66
+ "Email": "user@contoso.com",
67
+ "IsPrimaryAdmin": true
68
+ }
69
+ ]
70
+ ```
71
+
72
+ </TabItem>
73
+ <TabItem value="Text">
74
+
75
+ ```text
76
+ Email : user@contoso.com
77
+ Id : 6
78
+ LoginName : i:0#.f|membership|user@contoso.com
79
+ PrincipalType : 1
80
+ PrincipalTypeString : User
81
+ Title : User Example
82
+ IsPrimaryAdmin : true
83
+ ```
84
+
85
+ </TabItem>
86
+ <TabItem value="CSV">
87
+
88
+ ```csv
89
+ Id,LoginName,Title,PrincipalType,PrincipalTypeString,Email,IsPrimaryAdmin
90
+ 6,i:0#.f|membership|user@contoso.com,User Example,1,User,user@contoso.com,1
91
+ ```
92
+
93
+ </TabItem>
94
+ <TabItem value="Markdown">
95
+
96
+ ```md
97
+ # spo site admin list --siteUrl "https://contoso.sharepoint.com/sites/Test"
98
+
99
+ Date: 20/03/2024
100
+
101
+ ## User
102
+
103
+ Property | Value
104
+ ---------|-------
105
+ Id | 6
106
+ LoginName | i:0#.f\|membership\|user@contoso.com
107
+ Title | User Example
108
+ PrincipalType | 1
109
+ PrincipalTypeString | User
110
+ Email | user@contoso.com
111
+ IsPrimaryAdmin | true
112
+ ```
113
+
114
+ </TabItem>
115
+ </Tabs>
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "7.10.0",
3
+ "version": "7.11.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pnp/cli-microsoft365",
9
- "version": "7.10.0",
9
+ "version": "7.11.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@azure/msal-common": "^14.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "7.10.0-beta.ebb7426",
3
+ "version": "7.11.0-beta.c513557",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",