@pnp/cli-microsoft365 6.2.0 → 6.3.0-beta.1140b31

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
@@ -573,24 +573,6 @@ class Auth {
573
573
  getMsalCacheStorage() {
574
574
  return new FileTokenStorage_1.FileTokenStorage(FileTokenStorage_1.FileTokenStorage.msalCacheFilePath());
575
575
  }
576
- static isAppOnlyAuth(accessToken) {
577
- let isAppOnlyAuth;
578
- if (!accessToken || accessToken.length === 0) {
579
- return isAppOnlyAuth;
580
- }
581
- const chunks = accessToken.split('.');
582
- if (chunks.length !== 3) {
583
- return isAppOnlyAuth;
584
- }
585
- const tokenString = Buffer.from(chunks[1], 'base64').toString();
586
- try {
587
- const token = JSON.parse(tokenString);
588
- isAppOnlyAuth = !token.upn;
589
- }
590
- catch (_a) {
591
- }
592
- return isAppOnlyAuth;
593
- }
594
576
  }
595
577
  exports.Auth = Auth;
596
578
  exports.default = new Auth();
@@ -23,6 +23,7 @@ const uuid_1 = require("uuid");
23
23
  const Auth_1 = require("../../../../Auth");
24
24
  const Command_1 = require("../../../../Command");
25
25
  const request_1 = require("../../../../request");
26
+ const accessToken_1 = require("../../../../utils/accessToken");
26
27
  const GraphCommand_1 = require("../../../base/GraphCommand");
27
28
  const commands_1 = require("../../commands");
28
29
  class FileConvertPdfCommand extends GraphCommand_1.default {
@@ -46,8 +47,8 @@ class FileConvertPdfCommand extends GraphCommand_1.default {
46
47
  let sourceIsLocalFile = true;
47
48
  let targetIsLocalFile = true;
48
49
  let error;
49
- const isAppOnlyAuth = Auth_1.Auth.isAppOnlyAuth(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken);
50
- if (typeof isAppOnlyAuth === 'undefined') {
50
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken);
51
+ if (typeof isAppOnlyAccessToken === 'undefined') {
51
52
  throw 'Unable to determine authentication type';
52
53
  }
53
54
  if (args.options.sourceFile.toLowerCase().startsWith('https://')) {
@@ -62,7 +63,7 @@ class FileConvertPdfCommand extends GraphCommand_1.default {
62
63
  }
63
64
  try {
64
65
  try {
65
- sourceFileUrl = yield this.getSourceFileUrl(logger, args, isAppOnlyAuth);
66
+ sourceFileUrl = yield this.getSourceFileUrl(logger, args, isAppOnlyAccessToken);
66
67
  const graphFileUrl = yield this.getGraphFileUrl(logger, sourceFileUrl, this.sourceFileGraphUrl);
67
68
  const fileResponse = yield this.convertFile(logger, graphFileUrl);
68
69
  yield this.writeFileToDisk(logger, fileResponse, localTargetFilePath);
@@ -114,17 +115,17 @@ class FileConvertPdfCommand extends GraphCommand_1.default {
114
115
  * file to the user's OneDrive for Business
115
116
  * @param logger Logger instance
116
117
  * @param args Command args
117
- * @param isAppOnlyAuth True if CLI is authenticated in app-only mode
118
+ * @param isAppOnlyAccessToken True if CLI is authenticated in app-only mode
118
119
  * @returns Web URL of the file to upload
119
120
  */
120
- getSourceFileUrl(logger, args, isAppOnlyAuth) {
121
+ getSourceFileUrl(logger, args, isAppOnlyAccessToken) {
121
122
  if (args.options.sourceFile.toLowerCase().startsWith('https://')) {
122
123
  return Promise.resolve(args.options.sourceFile);
123
124
  }
124
125
  if (this.verbose) {
125
126
  logger.logToStderr('Uploading local file temporarily for conversion...');
126
127
  }
127
- const driveUrl = `${this.resource}/v1.0/${isAppOnlyAuth ? 'drive/root' : 'me/drive/root'}`;
128
+ const driveUrl = `${this.resource}/v1.0/${isAppOnlyAccessToken ? 'drive/root' : 'me/drive/root'}`;
128
129
  // we need the original file extension because otherwise Graph won't be able
129
130
  // to convert the file to PDF
130
131
  this.sourceFileGraphUrl = `${driveUrl}:/${(0, uuid_1.v4)()}${path.extname(args.options.sourceFile)}`;
@@ -15,12 +15,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  };
16
16
  var _OneNoteNotebookListCommand_instances, _OneNoteNotebookListCommand_initTelemetry, _OneNoteNotebookListCommand_initOptions, _OneNoteNotebookListCommand_initValidators;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const request_1 = require("../../../../request");
19
18
  const odata_1 = require("../../../../utils/odata");
20
19
  const validation_1 = require("../../../../utils/validation");
21
20
  const aadGroup_1 = require("../../../../utils/aadGroup");
22
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
23
22
  const commands_1 = require("../../commands");
23
+ const spo_1 = require("../../../../utils/spo");
24
24
  class OneNoteNotebookListCommand extends GraphCommand_1.default {
25
25
  get name() {
26
26
  return commands_1.default.NOTEBOOK_LIST;
@@ -62,8 +62,7 @@ class OneNoteNotebookListCommand extends GraphCommand_1.default {
62
62
  });
63
63
  }
64
64
  else if (args.options.webUrl) {
65
- this
66
- .getSpoSiteId(args)
65
+ spo_1.spo.getSpoGraphSiteId(args.options.webUrl)
67
66
  .then((siteId) => {
68
67
  endpoint = `${this.resource}/v1.0/sites/${siteId}/onenote/notebooks`;
69
68
  return resolve(endpoint);
@@ -85,19 +84,6 @@ class OneNoteNotebookListCommand extends GraphCommand_1.default {
85
84
  .getGroupByDisplayName(args.options.groupName)
86
85
  .then(group => group.id);
87
86
  }
88
- getSpoSiteId(args) {
89
- const url = new URL(args.options.webUrl);
90
- const requestOptions = {
91
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
92
- headers: {
93
- accept: 'application/json;odata.metadata=none'
94
- },
95
- responseType: 'json'
96
- };
97
- return request_1.default
98
- .get(requestOptions)
99
- .then((site) => site.id);
100
- }
101
87
  commandAction(logger, args) {
102
88
  return __awaiter(this, void 0, void 0, function* () {
103
89
  try {
@@ -15,12 +15,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  };
16
16
  var _OneNotePageListCommand_instances, _OneNotePageListCommand_initTelemetry, _OneNotePageListCommand_initOptions, _OneNotePageListCommand_initValidators, _OneNotePageListCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const request_1 = require("../../../../request");
19
18
  const odata_1 = require("../../../../utils/odata");
20
19
  const validation_1 = require("../../../../utils/validation");
21
20
  const aadGroup_1 = require("../../../../utils/aadGroup");
22
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
23
22
  const commands_1 = require("../../commands");
23
+ const spo_1 = require("../../../../utils/spo");
24
24
  class OneNotePageListCommand extends GraphCommand_1.default {
25
25
  get name() {
26
26
  return commands_1.default.PAGE_LIST;
@@ -56,7 +56,7 @@ class OneNotePageListCommand extends GraphCommand_1.default {
56
56
  endpoint += `groups/${groupId}`;
57
57
  }
58
58
  else if (args.options.webUrl) {
59
- const siteId = yield this.getSpoSiteId(args.options.webUrl);
59
+ const siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.webUrl);
60
60
  endpoint += `sites/${siteId}`;
61
61
  }
62
62
  else {
@@ -72,20 +72,6 @@ class OneNotePageListCommand extends GraphCommand_1.default {
72
72
  return group.id;
73
73
  });
74
74
  }
75
- getSpoSiteId(webUrl) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const url = new URL(webUrl);
78
- const requestOptions = {
79
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
80
- headers: {
81
- accept: 'application/json;odata.metadata=none'
82
- },
83
- responseType: 'json'
84
- };
85
- const site = yield request_1.default.get(requestOptions);
86
- return site.id;
87
- });
88
- }
89
75
  commandAction(logger, args) {
90
76
  return __awaiter(this, void 0, void 0, function* () {
91
77
  try {
@@ -22,6 +22,7 @@ const request_1 = require("../../../../request");
22
22
  const GraphCommand_1 = require("../../../base/GraphCommand");
23
23
  const commands_1 = require("../../commands");
24
24
  const formatting_1 = require("../../../../utils/formatting");
25
+ const accessToken_1 = require("../../../../utils/accessToken");
25
26
  class OutlookMailSendCommand extends GraphCommand_1.default {
26
27
  get name() {
27
28
  return commands_1.default.MAIL_SEND;
@@ -40,8 +41,8 @@ class OutlookMailSendCommand extends GraphCommand_1.default {
40
41
  commandAction(logger, args) {
41
42
  return __awaiter(this, void 0, void 0, function* () {
42
43
  try {
43
- const isAppOnlyAuth = Auth_1.Auth.isAppOnlyAuth(Auth_1.default.service.accessTokens[this.resource].accessToken);
44
- if (isAppOnlyAuth === true && !args.options.sender) {
44
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
45
+ if (isAppOnlyAccessToken === true && !args.options.sender) {
45
46
  throw `Specify a upn or user id in the 'sender' option when using app only authentication.`;
46
47
  }
47
48
  const requestOptions = {
@@ -17,6 +17,7 @@ var _OutlookMessageGetCommand_instances, _OutlookMessageGetCommand_initTelemetry
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const Auth_1 = require("../../../../Auth");
19
19
  const request_1 = require("../../../../request");
20
+ const accessToken_1 = require("../../../../utils/accessToken");
20
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
21
22
  const commands_1 = require("../../commands");
22
23
  class OutlookMessageGetCommand extends GraphCommand_1.default {
@@ -35,12 +36,12 @@ class OutlookMessageGetCommand extends GraphCommand_1.default {
35
36
  commandAction(logger, args) {
36
37
  return __awaiter(this, void 0, void 0, function* () {
37
38
  try {
38
- const isAppOnlyAuth = Auth_1.Auth.isAppOnlyAuth(Auth_1.default.service.accessTokens[this.resource].accessToken);
39
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
39
40
  if (this.verbose) {
40
- logger.logToStderr(`Retrieving message with id ${args.options.id} using ${isAppOnlyAuth ? 'app only permissions' : 'delegated permissions'}`);
41
+ logger.logToStderr(`Retrieving message with id ${args.options.id} using ${isAppOnlyAccessToken ? 'app only permissions' : 'delegated permissions'}`);
41
42
  }
42
43
  let requestUrl = '';
43
- if (isAppOnlyAuth) {
44
+ if (isAppOnlyAccessToken) {
44
45
  if (!args.options.userId && !args.options.userPrincipalName) {
45
46
  throw `The option 'userId' or 'userPrincipalName' is required when retrieving an email using app only credentials`;
46
47
  }
@@ -17,6 +17,7 @@ var _SpoSiteAppPermissionAddCommand_instances, _SpoSiteAppPermissionAddCommand_i
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
19
  const formatting_1 = require("../../../../utils/formatting");
20
+ const spo_1 = require("../../../../utils/spo");
20
21
  const validation_1 = require("../../../../utils/validation");
21
22
  const GraphCommand_1 = require("../../../base/GraphCommand");
22
23
  const commands_1 = require("../../commands");
@@ -37,19 +38,6 @@ class SpoSiteAppPermissionAddCommand extends GraphCommand_1.default {
37
38
  __classPrivateFieldGet(this, _SpoSiteAppPermissionAddCommand_instances, "m", _SpoSiteAppPermissionAddCommand_initValidators).call(this);
38
39
  __classPrivateFieldGet(this, _SpoSiteAppPermissionAddCommand_instances, "m", _SpoSiteAppPermissionAddCommand_initOptionSets).call(this);
39
40
  }
40
- getSpoSiteId(args) {
41
- const url = new URL(args.options.siteUrl);
42
- const requestOptions = {
43
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
44
- headers: {
45
- accept: 'application/json;odata.metadata=none'
46
- },
47
- responseType: 'json'
48
- };
49
- return request_1.default
50
- .get(requestOptions)
51
- .then((site) => site.id);
52
- }
53
41
  getAppInfo(args) {
54
42
  if (args.options.appId && args.options.appDisplayName) {
55
43
  return Promise.resolve({
@@ -136,7 +124,7 @@ class SpoSiteAppPermissionAddCommand extends GraphCommand_1.default {
136
124
  commandAction(logger, args) {
137
125
  return __awaiter(this, void 0, void 0, function* () {
138
126
  try {
139
- this.siteId = yield this.getSpoSiteId(args);
127
+ this.siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.siteUrl);
140
128
  const appInfo = yield this.getAppInfo(args);
141
129
  let permission = yield this.addPermissions(args, appInfo);
142
130
  if (this.roleNeedsElevation(args.options.permission)) {
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _SpoSiteAppPermissionGetCommand_instances, _SpoSiteAppPermissionGetCommand_initOptions, _SpoSiteAppPermissionGetCommand_initValidators;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
+ const spo_1 = require("../../../../utils/spo");
19
20
  const validation_1 = require("../../../../utils/validation");
20
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
21
22
  const commands_1 = require("../../commands");
@@ -32,19 +33,6 @@ class SpoSiteAppPermissionGetCommand extends GraphCommand_1.default {
32
33
  __classPrivateFieldGet(this, _SpoSiteAppPermissionGetCommand_instances, "m", _SpoSiteAppPermissionGetCommand_initOptions).call(this);
33
34
  __classPrivateFieldGet(this, _SpoSiteAppPermissionGetCommand_instances, "m", _SpoSiteAppPermissionGetCommand_initValidators).call(this);
34
35
  }
35
- getSpoSiteId(args) {
36
- const url = new URL(args.options.siteUrl);
37
- const requestOptions = {
38
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
39
- headers: {
40
- accept: 'application/json;odata.metadata=none'
41
- },
42
- responseType: 'json'
43
- };
44
- return request_1.default
45
- .get(requestOptions)
46
- .then((site) => site.id);
47
- }
48
36
  getApplicationPermission(args, siteId) {
49
37
  const requestOptions = {
50
38
  url: `${this.resource}/v1.0/sites/${siteId}/permissions/${args.options.id}`,
@@ -58,7 +46,7 @@ class SpoSiteAppPermissionGetCommand extends GraphCommand_1.default {
58
46
  commandAction(logger, args) {
59
47
  return __awaiter(this, void 0, void 0, function* () {
60
48
  try {
61
- const siteId = yield this.getSpoSiteId(args);
49
+ const siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.siteUrl);
62
50
  const permissionObject = yield this.getApplicationPermission(args, siteId);
63
51
  const transposed = [];
64
52
  permissionObject.grantedToIdentities.forEach((permissionEntity) => {
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _SpoSiteAppPermissionListCommand_instances, _SpoSiteAppPermissionListCommand_initTelemetry, _SpoSiteAppPermissionListCommand_initOptions, _SpoSiteAppPermissionListCommand_initValidators;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
+ const spo_1 = require("../../../../utils/spo");
19
20
  const validation_1 = require("../../../../utils/validation");
20
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
21
22
  const commands_1 = require("../../commands");
@@ -34,19 +35,6 @@ class SpoSiteAppPermissionListCommand extends GraphCommand_1.default {
34
35
  __classPrivateFieldGet(this, _SpoSiteAppPermissionListCommand_instances, "m", _SpoSiteAppPermissionListCommand_initOptions).call(this);
35
36
  __classPrivateFieldGet(this, _SpoSiteAppPermissionListCommand_instances, "m", _SpoSiteAppPermissionListCommand_initValidators).call(this);
36
37
  }
37
- getSpoSiteId(args) {
38
- const url = new URL(args.options.siteUrl);
39
- const requestOptions = {
40
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
41
- headers: {
42
- accept: 'application/json;odata.metadata=none'
43
- },
44
- responseType: 'json'
45
- };
46
- return request_1.default
47
- .get(requestOptions)
48
- .then((site) => site.id);
49
- }
50
38
  getFilteredPermissions(args, permissions) {
51
39
  let filterProperty = 'displayName';
52
40
  let filterValue = args.options.appDisplayName;
@@ -95,7 +83,7 @@ class SpoSiteAppPermissionListCommand extends GraphCommand_1.default {
95
83
  commandAction(logger, args) {
96
84
  return __awaiter(this, void 0, void 0, function* () {
97
85
  try {
98
- this.siteId = yield this.getSpoSiteId(args);
86
+ this.siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.siteUrl);
99
87
  const permRes = yield this.getPermissions();
100
88
  let permissions = permRes.value;
101
89
  if (args.options.appId || args.options.appDisplayName) {
@@ -17,6 +17,7 @@ var _SpoSiteAppPermissionRemoveCommand_instances, _SpoSiteAppPermissionRemoveCom
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const Cli_1 = require("../../../../cli/Cli");
19
19
  const request_1 = require("../../../../request");
20
+ const spo_1 = require("../../../../utils/spo");
20
21
  const validation_1 = require("../../../../utils/validation");
21
22
  const GraphCommand_1 = require("../../../base/GraphCommand");
22
23
  const commands_1 = require("../../commands");
@@ -36,19 +37,6 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand_1.default {
36
37
  __classPrivateFieldGet(this, _SpoSiteAppPermissionRemoveCommand_instances, "m", _SpoSiteAppPermissionRemoveCommand_initValidators).call(this);
37
38
  __classPrivateFieldGet(this, _SpoSiteAppPermissionRemoveCommand_instances, "m", _SpoSiteAppPermissionRemoveCommand_initOptionSets).call(this);
38
39
  }
39
- getSpoSiteId(args) {
40
- const url = new URL(args.options.siteUrl);
41
- const requestOptions = {
42
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
43
- headers: {
44
- accept: 'application/json;odata.metadata=none'
45
- },
46
- responseType: 'json'
47
- };
48
- return request_1.default
49
- .get(requestOptions)
50
- .then((site) => site.id);
51
- }
52
40
  getPermissions() {
53
41
  const requestOptions = {
54
42
  url: `${this.resource}/v1.0/sites/${this.siteId}/permissions`,
@@ -98,7 +86,7 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand_1.default {
98
86
  return __awaiter(this, void 0, void 0, function* () {
99
87
  const removeSiteAppPermission = () => __awaiter(this, void 0, void 0, function* () {
100
88
  try {
101
- this.siteId = yield this.getSpoSiteId(args);
89
+ this.siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.siteUrl);
102
90
  const permissionIdsToRemove = yield this.getPermissionIds(args);
103
91
  const tasks = [];
104
92
  for (const permissionId of permissionIdsToRemove) {
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _SpoSiteAppPermissionSetCommand_instances, _SpoSiteAppPermissionSetCommand_initTelemetry, _SpoSiteAppPermissionSetCommand_initOptions, _SpoSiteAppPermissionSetCommand_initValidators, _SpoSiteAppPermissionSetCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
+ const spo_1 = require("../../../../utils/spo");
19
20
  const validation_1 = require("../../../../utils/validation");
20
21
  const GraphCommand_1 = require("../../../base/GraphCommand");
21
22
  const commands_1 = require("../../commands");
@@ -36,19 +37,6 @@ class SpoSiteAppPermissionSetCommand extends GraphCommand_1.default {
36
37
  __classPrivateFieldGet(this, _SpoSiteAppPermissionSetCommand_instances, "m", _SpoSiteAppPermissionSetCommand_initValidators).call(this);
37
38
  __classPrivateFieldGet(this, _SpoSiteAppPermissionSetCommand_instances, "m", _SpoSiteAppPermissionSetCommand_initOptionSets).call(this);
38
39
  }
39
- getSpoSiteId(args) {
40
- const url = new URL(args.options.siteUrl);
41
- const siteRequestOptions = {
42
- url: `${this.resource}/v1.0/sites/${url.hostname}:${url.pathname}`,
43
- headers: {
44
- accept: 'application/json;odata.metadata=none'
45
- },
46
- responseType: 'json'
47
- };
48
- return request_1.default
49
- .get(siteRequestOptions)
50
- .then((site) => site.id);
51
- }
52
40
  getFilteredPermissions(args, permissions) {
53
41
  let filterProperty = 'displayName';
54
42
  let filterValue = args.options.appDisplayName;
@@ -85,7 +73,7 @@ class SpoSiteAppPermissionSetCommand extends GraphCommand_1.default {
85
73
  commandAction(logger, args) {
86
74
  return __awaiter(this, void 0, void 0, function* () {
87
75
  try {
88
- this.siteId = yield this.getSpoSiteId(args);
76
+ this.siteId = yield spo_1.spo.getSpoGraphSiteId(args.options.siteUrl);
89
77
  const sitePermissionId = yield this.getPermission(args);
90
78
  const requestOptions = {
91
79
  url: `${this.resource}/v1.0/sites/${this.siteId}/permissions/${sitePermissionId}`,
@@ -41,14 +41,14 @@ class TeamsChatListCommand extends GraphCommand_1.default {
41
41
  }
42
42
  commandAction(logger, args) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- const isAppOnlyAuth = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
45
- if (isAppOnlyAuth && !args.options.userId && !args.options.userName) {
44
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
45
+ if (isAppOnlyAccessToken && !args.options.userId && !args.options.userName) {
46
46
  throw `The option 'userId' or 'userName' is required when obtaining chats using app only permissions`;
47
47
  }
48
- else if (!isAppOnlyAuth && (args.options.userId || args.options.userName)) {
48
+ else if (!isAppOnlyAccessToken && (args.options.userId || args.options.userName)) {
49
49
  throw `The options 'userId' or 'userName' cannot be used when obtaining chats using delegated permissions`;
50
50
  }
51
- let requestUrl = `${this.resource}/v1.0/${!isAppOnlyAuth ? 'me' : `users/${args.options.userId || args.options.userName}`}/chats`;
51
+ let requestUrl = `${this.resource}/v1.0/${!isAppOnlyAccessToken ? 'me' : `users/${args.options.userId || args.options.userName}`}/chats`;
52
52
  if (args.options.type) {
53
53
  requestUrl += `?$filter=chatType eq '${args.options.type}'`;
54
54
  }
@@ -42,19 +42,19 @@ class TeamsMeetingAttendancereportListCommand extends GraphCommand_1.default {
42
42
  }
43
43
  commandAction(logger, args) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
- const isAppOnlyAuth = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
46
- if (isAppOnlyAuth && !args.options.userId && !args.options.userName && !args.options.email) {
45
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
46
+ if (isAppOnlyAccessToken && !args.options.userId && !args.options.userName && !args.options.email) {
47
47
  this.handleError(`The option 'userId', 'userName' or 'email' is required when retrieving meeting attendance report using app only permissions`);
48
48
  }
49
- else if (!isAppOnlyAuth && (args.options.userId || args.options.userName || args.options.email)) {
49
+ else if (!isAppOnlyAccessToken && (args.options.userId || args.options.userName || args.options.email)) {
50
50
  this.handleError(`The options 'userId', 'userName' and 'email' cannot be used when retrieving meeting attendance reports using delegated permissions`);
51
51
  }
52
52
  try {
53
53
  if (this.verbose) {
54
- logger.logToStderr(`Retrieving attendance report for ${isAppOnlyAuth ? 'specific user' : 'currently logged in user'}`);
54
+ logger.logToStderr(`Retrieving attendance report for ${isAppOnlyAccessToken ? 'specific user' : 'currently logged in user'}`);
55
55
  }
56
56
  let requestUrl = `${this.resource}/v1.0/`;
57
- if (isAppOnlyAuth) {
57
+ if (isAppOnlyAccessToken) {
58
58
  requestUrl += 'users/';
59
59
  if (args.options.userId) {
60
60
  requestUrl += args.options.userId;
@@ -53,23 +53,23 @@ class TeamsMeetingGetCommand extends GraphCommand_1.default {
53
53
  }
54
54
  commandAction(logger, args) {
55
55
  return __awaiter(this, void 0, void 0, function* () {
56
- const isAppOnlyAuth = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
57
- if (isAppOnlyAuth) {
56
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
57
+ if (isAppOnlyAccessToken) {
58
58
  if (!args.options.userId && !args.options.userName && !args.options.email) {
59
59
  this.handleError(`The option 'userId', 'userName' or 'email' is required when retrieving meetings using app only permissions`);
60
60
  }
61
61
  }
62
62
  else {
63
- if (!isAppOnlyAuth && (args.options.userId || args.options.userName || args.options.email)) {
63
+ if (!isAppOnlyAccessToken && (args.options.userId || args.options.userName || args.options.email)) {
64
64
  this.handleError(`The options 'userId', 'userName' and 'email' cannot be used when retrieving meetings using delegated permissions`);
65
65
  }
66
66
  }
67
67
  if (this.verbose) {
68
- logger.logToStderr(`Retrieving meeting for ${isAppOnlyAuth ? 'specific user' : 'currently logged in user'}`);
68
+ logger.logToStderr(`Retrieving meeting for ${isAppOnlyAccessToken ? 'specific user' : 'currently logged in user'}`);
69
69
  }
70
70
  try {
71
71
  let requestUrl = `${this.resource}/v1.0/`;
72
- if (isAppOnlyAuth) {
72
+ if (isAppOnlyAccessToken) {
73
73
  requestUrl += 'users/';
74
74
  if (args.options.userId) {
75
75
  requestUrl += args.options.userId;
@@ -22,6 +22,7 @@ const commands_1 = require("../../commands");
22
22
  const odata_1 = require("../../../../utils/odata");
23
23
  const validation_1 = require("../../../../utils/validation");
24
24
  const AadUserGetCommand = require("../../../aad/commands/user/user-get");
25
+ const accessToken_1 = require("../../../../utils/accessToken");
25
26
  class TeamsMeetingListCommand extends GraphCommand_1.default {
26
27
  get name() {
27
28
  return commands_1.default.MEETING_LIST;
@@ -42,12 +43,12 @@ class TeamsMeetingListCommand extends GraphCommand_1.default {
42
43
  commandAction(logger, args) {
43
44
  return __awaiter(this, void 0, void 0, function* () {
44
45
  try {
45
- const isAppOnlyAuth = Auth_1.Auth.isAppOnlyAuth(Auth_1.default.service.accessTokens[this.resource].accessToken);
46
+ const isAppOnlyAccessToken = accessToken_1.accessToken.isAppOnlyAccessToken(Auth_1.default.service.accessTokens[this.resource].accessToken);
46
47
  if (this.verbose) {
47
- logger.logToStderr(`Retrieving meetings for ${isAppOnlyAuth ? 'specific user' : 'currently logged in user'}`);
48
+ logger.logToStderr(`Retrieving meetings for ${isAppOnlyAccessToken ? 'specific user' : 'currently logged in user'}`);
48
49
  }
49
50
  let requestUrl = `${this.resource}/v1.0/`;
50
- if (isAppOnlyAuth) {
51
+ if (isAppOnlyAccessToken) {
51
52
  if (!args.options.userId && !args.options.userName && !args.options.email) {
52
53
  throw `The option 'userId', 'userName' or 'email' is required when retrieving meetings using app only permissions`;
53
54
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.accessToken = void 0;
4
4
  exports.accessToken = {
5
5
  isAppOnlyAccessToken(accessToken) {
6
- let isAppOnlyAccessToken = false;
6
+ let isAppOnlyAccessToken;
7
7
  if (!accessToken || accessToken.length === 0) {
8
8
  return isAppOnlyAccessToken;
9
9
  }
package/dist/utils/spo.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.spo = void 0;
4
13
  const url = require("url");
@@ -237,6 +246,24 @@ exports.spo = {
237
246
  });
238
247
  });
239
248
  },
249
+ /**
250
+ * Returns the Graph id of a site
251
+ * @param webUrl web url e.g. https://contoso.sharepoint.com/sites/site1
252
+ */
253
+ getSpoGraphSiteId(webUrl) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ const url = new URL(webUrl);
256
+ const requestOptions = {
257
+ url: `https://graph.microsoft.com/v1.0/sites/${url.hostname}:${url.pathname}?$select=id`,
258
+ headers: {
259
+ 'accept': 'application/json;odata.metadata=none'
260
+ },
261
+ responseType: 'json'
262
+ };
263
+ const result = yield request_1.default.get(requestOptions);
264
+ return result.id;
265
+ });
266
+ },
240
267
  /**
241
268
  * Ensures the folder path exists
242
269
  * @param webFullUrl web full url e.g. https://contoso.sharepoint.com/sites/site1
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pnp/cli-microsoft365",
9
- "version": "6.2.0",
9
+ "version": "6.3.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@azure/msal-node": "^1.14.5",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "6.2.0",
3
+ "version": "6.3.0-beta.1140b31",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",
@@ -272,4 +272,4 @@
272
272
  "sinon": "^15.0.1",
273
273
  "source-map-support": "^0.5.21"
274
274
  }
275
- }
275
+ }