@pnp/cli-microsoft365 8.1.0-beta.3dec9fa → 8.1.0-beta.96dc207

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.
Files changed (105) hide show
  1. package/allCommands.json +1 -1
  2. package/allCommandsFull.json +1 -1
  3. package/dist/Auth.js +20 -21
  4. package/dist/Command.js +50 -5
  5. package/dist/cli/cli.js +115 -39
  6. package/dist/config.js +60 -5
  7. package/dist/m365/base/SpoCommand.js +1 -1
  8. package/dist/m365/cli/commands/cli-consent.js +2 -2
  9. package/dist/m365/cli/commands/cli-doctor.js +2 -2
  10. package/dist/m365/cli/commands/cli-reconsent.js +2 -3
  11. package/dist/m365/cli/commands/config/config-set.js +12 -3
  12. package/dist/m365/commands/login.js +74 -102
  13. package/dist/m365/commands/setup.js +256 -33
  14. package/dist/m365/connection/commands/connection-list.js +4 -4
  15. package/dist/m365/connection/commands/connection-remove.js +6 -2
  16. package/dist/m365/connection/commands/connection-set.js +4 -1
  17. package/dist/m365/connection/commands/connection-use.js +25 -4
  18. package/dist/m365/entra/commands/app/app-add.js +52 -288
  19. package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-remove.js +123 -0
  20. package/dist/m365/entra/commands/group/group-set.js +256 -0
  21. package/dist/m365/entra/commands/m365group/m365group-user-add.js +109 -32
  22. package/dist/m365/entra/commands/m365group/m365group-user-set.js +159 -84
  23. package/dist/m365/entra/commands/multitenant/multitenant-add.js +65 -0
  24. package/dist/m365/entra/commands/multitenant/multitenant-remove.js +118 -0
  25. package/dist/m365/entra/commands/multitenant/multitenant-set.js +72 -0
  26. package/dist/m365/entra/commands.js +6 -0
  27. package/dist/m365/flow/commands/flow-get.js +1 -1
  28. package/dist/m365/onenote/commands/notebook/notebook-add.js +132 -0
  29. package/dist/m365/onenote/commands.js +1 -0
  30. package/dist/m365/pa/commands/app/app-export.js +13 -7
  31. package/dist/m365/spe/ContainerTypeProperties.js +2 -0
  32. package/dist/m365/spe/commands/containertype/containertype-list.js +49 -0
  33. package/dist/m365/spe/commands.js +2 -1
  34. package/dist/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.js +16 -21
  35. package/dist/m365/spo/commands/commandset/commandset-get.js +31 -17
  36. package/dist/m365/spo/commands/file/file-roleassignment-add.js +1 -1
  37. package/dist/m365/spo/commands/file/file-roleinheritance-break.js +1 -1
  38. package/dist/m365/spo/commands/file/file-roleinheritance-reset.js +1 -1
  39. package/dist/m365/spo/commands/folder/folder-retentionlabel-ensure.js +1 -1
  40. package/dist/m365/spo/commands/folder/folder-sharinglink-get.js +86 -0
  41. package/dist/m365/spo/commands/folder/folder-sharinglink-list.js +110 -0
  42. package/dist/m365/spo/commands/list/ListInstance.js +6 -1
  43. package/dist/m365/spo/commands/list/list-get.js +9 -3
  44. package/dist/m365/spo/commands/list/list-roleassignment-add.js +46 -21
  45. package/dist/m365/spo/commands/list/list-roleassignment-remove.js +48 -46
  46. package/dist/m365/spo/commands/site/site-get.js +12 -16
  47. package/dist/m365/spo/commands/tenant/tenant-applicationcustomizer-get.js +19 -5
  48. package/dist/m365/spo/commands/tenant/tenant-commandset-get.js +20 -6
  49. package/dist/m365/spo/commands.js +2 -0
  50. package/dist/m365/teams/commands/message/message-restore.js +106 -0
  51. package/dist/m365/teams/commands.js +1 -0
  52. package/dist/settingsNames.js +7 -1
  53. package/dist/utils/drive.js +61 -0
  54. package/dist/utils/entraApp.js +283 -0
  55. package/dist/utils/formatting.js +16 -0
  56. package/dist/utils/spo.js +69 -6
  57. package/dist/utils/zod.js +124 -0
  58. package/docs/docs/_clisettings.mdx +6 -0
  59. package/docs/docs/cmd/connection/connection-use.mdx +8 -2
  60. package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-remove.mdx +65 -0
  61. package/docs/docs/cmd/entra/group/group-add.mdx +0 -4
  62. package/docs/docs/cmd/entra/group/group-set.mdx +89 -0
  63. package/docs/docs/cmd/entra/m365group/m365group-user-add.mdx +28 -10
  64. package/docs/docs/cmd/entra/m365group/m365group-user-set.mdx +35 -11
  65. package/docs/docs/cmd/entra/multitenant/multitenant-add.mdx +107 -0
  66. package/docs/docs/cmd/entra/multitenant/multitenant-remove.mdx +58 -0
  67. package/docs/docs/cmd/entra/multitenant/multitenant-set.mdx +53 -0
  68. package/docs/docs/cmd/flow/flow-get.mdx +149 -283
  69. package/docs/docs/cmd/onenote/notebook/notebook-add.mdx +169 -0
  70. package/docs/docs/cmd/pa/app/app-export.mdx +15 -9
  71. package/docs/docs/cmd/planner/plan/plan-remove.mdx +1 -1
  72. package/docs/docs/cmd/setup.mdx +16 -3
  73. package/docs/docs/cmd/spe/containertype/containertype-list.mdx +102 -0
  74. package/docs/docs/cmd/spo/app/app-uninstall.mdx +1 -1
  75. package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-get.mdx +87 -38
  76. package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-list.mdx +22 -28
  77. package/docs/docs/cmd/spo/commandset/commandset-get.mdx +75 -24
  78. package/docs/docs/cmd/spo/commandset/commandset-list.mdx +26 -32
  79. package/docs/docs/cmd/spo/file/file-retentionlabel-ensure.mdx +1 -1
  80. package/docs/docs/cmd/spo/file/file-roleassignment-add.mdx +2 -2
  81. package/docs/docs/cmd/spo/file/file-roleassignment-remove.mdx +1 -1
  82. package/docs/docs/cmd/spo/file/file-roleinheritance-break.mdx +1 -1
  83. package/docs/docs/cmd/spo/file/file-roleinheritance-reset.mdx +1 -1
  84. package/docs/docs/cmd/spo/folder/folder-retentionlabel-ensure.mdx +2 -2
  85. package/docs/docs/cmd/spo/folder/folder-sharinglink-get.mdx +110 -0
  86. package/docs/docs/cmd/spo/folder/folder-sharinglink-list.mdx +114 -0
  87. package/docs/docs/cmd/spo/list/list-get.mdx +6 -0
  88. package/docs/docs/cmd/spo/list/list-roleassignment-add.mdx +15 -3
  89. package/docs/docs/cmd/spo/list/list-roleassignment-remove.mdx +15 -3
  90. package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-ensure.mdx +4 -4
  91. package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-remove.mdx +1 -1
  92. package/docs/docs/cmd/spo/listitem/listitem-roleassignment-add.mdx +9 -9
  93. package/docs/docs/cmd/spo/listitem/listitem-roleassignment-remove.mdx +7 -7
  94. package/docs/docs/cmd/spo/site/site-recyclebinitem-list.mdx +1 -1
  95. package/docs/docs/cmd/spo/tenant/tenant-applicationcustomizer-get.mdx +79 -30
  96. package/docs/docs/cmd/spo/tenant/tenant-applicationcustomizer-list.mdx +20 -19
  97. package/docs/docs/cmd/spo/tenant/tenant-commandset-get.mdx +84 -38
  98. package/docs/docs/cmd/spo/tenant/tenant-commandset-list.mdx +20 -19
  99. package/docs/docs/cmd/spo/web/web-roleassignment-add.mdx +1 -1
  100. package/docs/docs/cmd/spo/web/web-roleassignment-remove.mdx +1 -1
  101. package/docs/docs/cmd/teams/meeting/meeting-list.mdx +7 -3
  102. package/docs/docs/cmd/teams/message/message-remove.mdx +2 -1
  103. package/docs/docs/cmd/teams/message/message-restore.mdx +62 -0
  104. package/npm-shrinkwrap.json +1002 -1147
  105. package/package.json +26 -23
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
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
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _SpoTenantCommandSetGetCommand_instances, _SpoTenantCommandSetGetCommand_initTelemetry, _SpoTenantCommandSetGetCommand_initOptions, _SpoTenantCommandSetGetCommand_initValidators, _SpoTenantCommandSetGetCommand_initOptionSets;
6
+ var _SpoTenantCommandSetGetCommand_instances, _SpoTenantCommandSetGetCommand_initTelemetry, _SpoTenantCommandSetGetCommand_initOptions, _SpoTenantCommandSetGetCommand_initValidators, _SpoTenantCommandSetGetCommand_initOptionSets, _SpoTenantCommandSetGetCommand_initTypes;
7
7
  import { cli } from '../../../../cli/cli.js';
8
8
  import { CommandError } from '../../../../Command.js';
9
9
  import request from '../../../../request.js';
@@ -27,6 +27,7 @@ class SpoTenantCommandSetGetCommand extends SpoCommand {
27
27
  __classPrivateFieldGet(this, _SpoTenantCommandSetGetCommand_instances, "m", _SpoTenantCommandSetGetCommand_initOptions).call(this);
28
28
  __classPrivateFieldGet(this, _SpoTenantCommandSetGetCommand_instances, "m", _SpoTenantCommandSetGetCommand_initValidators).call(this);
29
29
  __classPrivateFieldGet(this, _SpoTenantCommandSetGetCommand_instances, "m", _SpoTenantCommandSetGetCommand_initOptionSets).call(this);
30
+ __classPrivateFieldGet(this, _SpoTenantCommandSetGetCommand_instances, "m", _SpoTenantCommandSetGetCommand_initTypes).call(this);
30
31
  }
31
32
  async commandAction(logger, args) {
32
33
  const appCatalogUrl = await spo.getTenantAppCatalogUrl(logger, this.debug);
@@ -47,7 +48,7 @@ class SpoTenantCommandSetGetCommand extends SpoCommand {
47
48
  const reqOptions = {
48
49
  url: `${appCatalogUrl}/_api/web/GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')/items?$filter=${filter}`,
49
50
  headers: {
50
- 'accept': 'application/json;odata=nometadata'
51
+ accept: 'application/json;odata=nometadata'
51
52
  },
52
53
  responseType: 'json'
53
54
  };
@@ -55,13 +56,20 @@ class SpoTenantCommandSetGetCommand extends SpoCommand {
55
56
  const listItemInstances = await request.get(reqOptions);
56
57
  if (listItemInstances?.value.length > 0) {
57
58
  listItemInstances.value.forEach(v => delete v['ID']);
59
+ let listItemInstance;
58
60
  if (listItemInstances.value.length > 1) {
59
61
  const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances.value);
60
- const result = await cli.handleMultipleResultsFound(`Multiple ListView Command Sets with ${args.options.title || args.options.clientSideComponentId} were found.`, resultAsKeyValuePair);
61
- await logger.log(result);
62
+ listItemInstance = await cli.handleMultipleResultsFound(`Multiple ListView Command Sets with ${args.options.title || args.options.clientSideComponentId} were found.`, resultAsKeyValuePair);
62
63
  }
63
64
  else {
64
- await logger.log(listItemInstances.value[0]);
65
+ listItemInstance = listItemInstances.value[0];
66
+ }
67
+ if (!args.options.tenantWideExtensionComponentProperties) {
68
+ await logger.log(listItemInstance);
69
+ }
70
+ else {
71
+ const properties = formatting.tryParseJson(listItemInstance.TenantWideExtensionComponentProperties);
72
+ await logger.log(properties);
65
73
  }
66
74
  }
67
75
  else {
@@ -78,7 +86,8 @@ _SpoTenantCommandSetGetCommand_instances = new WeakSet(), _SpoTenantCommandSetGe
78
86
  Object.assign(this.telemetryProperties, {
79
87
  title: typeof args.options.title !== 'undefined',
80
88
  id: typeof args.options.id !== 'undefined',
81
- clientSideComponentId: typeof args.options.clientSideComponentId !== 'undefined'
89
+ clientSideComponentId: typeof args.options.clientSideComponentId !== 'undefined',
90
+ tenantWideExtensionComponentProperties: !!args.options.tenantWideExtensionComponentProperties
82
91
  });
83
92
  });
84
93
  }, _SpoTenantCommandSetGetCommand_initOptions = function _SpoTenantCommandSetGetCommand_initOptions() {
@@ -88,6 +97,8 @@ _SpoTenantCommandSetGetCommand_instances = new WeakSet(), _SpoTenantCommandSetGe
88
97
  option: '-i, --id [id]'
89
98
  }, {
90
99
  option: '-c, --clientSideComponentId [clientSideComponentId]'
100
+ }, {
101
+ option: '-p, --tenantWideExtensionComponentProperties'
91
102
  });
92
103
  }, _SpoTenantCommandSetGetCommand_initValidators = function _SpoTenantCommandSetGetCommand_initValidators() {
93
104
  this.validators.push(async (args) => {
@@ -101,6 +112,9 @@ _SpoTenantCommandSetGetCommand_instances = new WeakSet(), _SpoTenantCommandSetGe
101
112
  });
102
113
  }, _SpoTenantCommandSetGetCommand_initOptionSets = function _SpoTenantCommandSetGetCommand_initOptionSets() {
103
114
  this.optionSets.push({ options: ['title', 'id', 'clientSideComponentId'] });
115
+ }, _SpoTenantCommandSetGetCommand_initTypes = function _SpoTenantCommandSetGetCommand_initTypes() {
116
+ this.types.string.push('title', 'id', 'clientSideComponentId');
117
+ this.types.boolean.push('tenantWideExtensionComponentProperties');
104
118
  };
105
119
  export default new SpoTenantCommandSetGetCommand();
106
120
  //# sourceMappingURL=tenant-commandset-get.js.map
@@ -100,6 +100,8 @@ export default {
100
100
  FOLDER_ROLEASSIGNMENT_ADD: `${prefix} folder roleassignment add`,
101
101
  FOLDER_ROLEINHERITANCE_BREAK: `${prefix} folder roleinheritance break`,
102
102
  FOLDER_ROLEINHERITANCE_RESET: `${prefix} folder roleinheritance reset`,
103
+ FOLDER_SHARINGLINK_GET: `${prefix} folder sharinglink get`,
104
+ FOLDER_SHARINGLINK_LIST: `${prefix} folder sharinglink list`,
103
105
  GET: `${prefix} get`,
104
106
  GROUP_ADD: `${prefix} group add`,
105
107
  GROUP_GET: `${prefix} group get`,
@@ -0,0 +1,106 @@
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 _TeamsMessageRestoreCommand_instances, _TeamsMessageRestoreCommand_initTelemetry, _TeamsMessageRestoreCommand_initOptions, _TeamsMessageRestoreCommand_initValidators, _TeamsMessageRestoreCommand_initOptionSets, _TeamsMessageRestoreCommand_initTypes;
7
+ import request from '../../../../request.js';
8
+ import { validation } from '../../../../utils/validation.js';
9
+ import commands from '../../commands.js';
10
+ import DelegatedGraphCommand from '../../../base/DelegatedGraphCommand.js';
11
+ import { teams } from '../../../../utils/teams.js';
12
+ class TeamsMessageRestoreCommand extends DelegatedGraphCommand {
13
+ get name() {
14
+ return commands.MESSAGE_RESTORE;
15
+ }
16
+ get description() {
17
+ return 'Restores a deleted message from a channel in a Microsoft Teams team';
18
+ }
19
+ constructor() {
20
+ super();
21
+ _TeamsMessageRestoreCommand_instances.add(this);
22
+ __classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initTelemetry).call(this);
23
+ __classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initOptions).call(this);
24
+ __classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initValidators).call(this);
25
+ __classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initOptionSets).call(this);
26
+ __classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initTypes).call(this);
27
+ }
28
+ async commandAction(logger, args) {
29
+ try {
30
+ if (this.verbose) {
31
+ await logger.logToStderr(`Restoring deleted message '${args.options.id}' from channel '${args.options.channelId || args.options.channelName}' in the Microsoft Teams team '${args.options.teamId || args.options.teamName}'.`);
32
+ }
33
+ const teamId = await this.getTeamId(args.options, logger);
34
+ const channelId = await this.getChannelId(args.options, teamId, logger);
35
+ const requestOptions = {
36
+ url: `${this.resource}/v1.0/teams/${teamId}/channels/${channelId}/messages/${args.options.id}/undoSoftDelete`,
37
+ headers: {
38
+ accept: 'application/json;odata.metadata=none'
39
+ },
40
+ responseType: 'json'
41
+ };
42
+ await request.post(requestOptions);
43
+ }
44
+ catch (err) {
45
+ this.handleRejectedODataJsonPromise(err);
46
+ }
47
+ }
48
+ async getTeamId(options, logger) {
49
+ if (options.teamId) {
50
+ return options.teamId;
51
+ }
52
+ if (this.verbose) {
53
+ await logger.logToStderr(`Getting the Team ID.`);
54
+ }
55
+ const groupId = await teams.getTeamIdByDisplayName(options.teamName);
56
+ return groupId;
57
+ }
58
+ async getChannelId(options, teamId, logger) {
59
+ if (options.channelId) {
60
+ return options.channelId;
61
+ }
62
+ if (this.verbose) {
63
+ await logger.logToStderr(`Getting the channel ID.`);
64
+ }
65
+ const channelId = await teams.getChannelIdByDisplayName(teamId, options.channelName);
66
+ return channelId;
67
+ }
68
+ }
69
+ _TeamsMessageRestoreCommand_instances = new WeakSet(), _TeamsMessageRestoreCommand_initTelemetry = function _TeamsMessageRestoreCommand_initTelemetry() {
70
+ this.telemetry.push((args) => {
71
+ Object.assign(this.telemetryProperties, {
72
+ teamId: typeof args.options.teamId !== 'undefined',
73
+ teamName: typeof args.options.teamName !== 'undefined',
74
+ channelId: typeof args.options.channelId !== 'undefined',
75
+ channelName: typeof args.options.channelName !== 'undefined'
76
+ });
77
+ });
78
+ }, _TeamsMessageRestoreCommand_initOptions = function _TeamsMessageRestoreCommand_initOptions() {
79
+ this.options.unshift({
80
+ option: '--teamId [teamId]'
81
+ }, {
82
+ option: '--teamName [teamName]'
83
+ }, {
84
+ option: '--channelId [channelId]'
85
+ }, {
86
+ option: '--channelName [channelName]'
87
+ }, {
88
+ option: '-i, --id <id>'
89
+ });
90
+ }, _TeamsMessageRestoreCommand_initValidators = function _TeamsMessageRestoreCommand_initValidators() {
91
+ this.validators.push(async (args) => {
92
+ if (args.options.teamId && !validation.isValidGuid(args.options.teamId)) {
93
+ return `'${args.options.teamId}' is not a valid GUID for 'teamId'.`;
94
+ }
95
+ if (args.options.channelId && !validation.isValidTeamsChannelId(args.options.channelId)) {
96
+ return `'${args.options.channelId}' is not a valid ID for 'channelId'.`;
97
+ }
98
+ return true;
99
+ });
100
+ }, _TeamsMessageRestoreCommand_initOptionSets = function _TeamsMessageRestoreCommand_initOptionSets() {
101
+ this.optionSets.push({ options: ['teamId', 'teamName'] }, { options: ['channelId', 'channelName'] });
102
+ }, _TeamsMessageRestoreCommand_initTypes = function _TeamsMessageRestoreCommand_initTypes() {
103
+ this.types.string.push('teamId', 'teamName', 'channelId', 'channelName', 'id');
104
+ };
105
+ export default new TeamsMessageRestoreCommand();
106
+ //# sourceMappingURL=message-restore.js.map
@@ -39,6 +39,7 @@ export default {
39
39
  MESSAGE_LIST: `${prefix} message list`,
40
40
  MESSAGE_REMOVE: `${prefix} message remove`,
41
41
  MESSAGE_REPLY_LIST: `${prefix} message reply list`,
42
+ MESSAGE_RESTORE: `${prefix} message restore`,
42
43
  MESSAGE_SEND: `${prefix} message send`,
43
44
  MESSAGINGSETTINGS_LIST: `${prefix} messagingsettings list`,
44
45
  MESSAGINGSETTINGS_SET: `${prefix} messagingsettings set`,
@@ -1,6 +1,11 @@
1
1
  const settingsNames = {
2
2
  authType: 'authType',
3
3
  autoOpenLinksInBrowser: 'autoOpenLinksInBrowser',
4
+ clientId: 'clientId',
5
+ clientSecret: 'clientSecret',
6
+ clientCertificateFile: 'clientCertificateFile',
7
+ clientCertificateBase64Encoded: 'clientCertificateBase64Encoded',
8
+ clientCertificatePassword: 'clientCertificatePassword',
4
9
  copyDeviceCodeToClipboard: 'copyDeviceCodeToClipboard',
5
10
  csvEscape: 'csvEscape',
6
11
  csvHeader: 'csvHeader',
@@ -16,7 +21,8 @@ const settingsNames = {
16
21
  prompt: 'prompt',
17
22
  promptListPageSize: 'promptListPageSize',
18
23
  showHelpOnFailure: 'showHelpOnFailure',
19
- showSpinner: 'showSpinner'
24
+ showSpinner: 'showSpinner',
25
+ tenantId: 'tenantId'
20
26
  };
21
27
  export { settingsNames };
22
28
  //# sourceMappingURL=settingsNames.js.map
@@ -0,0 +1,61 @@
1
+ import request from "../request.js";
2
+ export const drive = {
3
+ /**
4
+ * Retrieves the Drive associated with the specified site and URL.
5
+ * @param siteId Site ID
6
+ * @param url Drive URL
7
+ * @param logger The logger object
8
+ * @param verbose Set for verbose logging
9
+ * @returns The Drive associated with the drive URL.
10
+ */
11
+ async getDriveByUrl(siteId, url, logger, verbose) {
12
+ if (verbose && logger) {
13
+ await logger.logToStderr(`Retrieving drive information for URL: ${url.href}`);
14
+ }
15
+ const requestOptions = {
16
+ url: `https://graph.microsoft.com/v1.0/sites/${siteId}/drives?$select=webUrl,id`,
17
+ headers: {
18
+ accept: 'application/json;odata.metadata=none'
19
+ },
20
+ responseType: 'json'
21
+ };
22
+ const drives = await request.get(requestOptions);
23
+ const lowerCaseFolderUrl = url.href.toLowerCase();
24
+ const drive = drives.value
25
+ .sort((a, b) => b.webUrl.localeCompare(a.webUrl))
26
+ .find((d) => {
27
+ const driveUrl = d.webUrl.toLowerCase();
28
+ return lowerCaseFolderUrl.startsWith(driveUrl) &&
29
+ (driveUrl.length === lowerCaseFolderUrl.length ||
30
+ lowerCaseFolderUrl[driveUrl.length] === '/');
31
+ });
32
+ if (!drive) {
33
+ throw new Error(`Drive '${url.href}' not found`);
34
+ }
35
+ return drive;
36
+ },
37
+ /**
38
+ * Retrieves the ID of a drive item (file, folder, etc.) associated with the given drive and item URL.
39
+ * @param drive The Drive object containing the item
40
+ * @param itemUrl Item URL
41
+ * @param logger The logger object
42
+ * @param verbose Set for verbose logging
43
+ * @returns Drive item ID
44
+ */
45
+ async getDriveItemId(drive, itemUrl, logger, verbose) {
46
+ const relativeItemUrl = itemUrl.href.replace(new RegExp(`${drive.webUrl}`, 'i'), '').replace(/\/+$/, '');
47
+ if (verbose && logger) {
48
+ await logger.logToStderr(`Retrieving drive item ID for URL: ${relativeItemUrl}`);
49
+ }
50
+ const requestOptions = {
51
+ url: `https://graph.microsoft.com/v1.0/drives/${drive.id}/root${relativeItemUrl ? `:${relativeItemUrl}` : ''}?$select=id`,
52
+ headers: {
53
+ accept: 'application/json;odata.metadata=none'
54
+ },
55
+ responseType: 'json'
56
+ };
57
+ const driveItem = await request.get(requestOptions);
58
+ return driveItem?.id;
59
+ }
60
+ };
61
+ //# sourceMappingURL=drive.js.map
@@ -0,0 +1,283 @@
1
+ import fs from 'fs';
2
+ import request from '../request.js';
3
+ import { odata } from './odata.js';
4
+ async function getCertificateBase64Encoded({ options, logger, debug }) {
5
+ if (options.certificateBase64Encoded) {
6
+ return options.certificateBase64Encoded;
7
+ }
8
+ if (debug) {
9
+ await logger.logToStderr(`Reading existing ${options.certificateFile}...`);
10
+ }
11
+ try {
12
+ return fs.readFileSync(options.certificateFile, { encoding: 'base64' });
13
+ }
14
+ catch (e) {
15
+ throw new Error(`Error reading certificate file: ${e}. Please add the certificate using base64 option '--certificateBase64Encoded'.`);
16
+ }
17
+ }
18
+ async function createServicePrincipal(appId) {
19
+ const requestOptions = {
20
+ url: `https://graph.microsoft.com/v1.0/myorganization/servicePrincipals`,
21
+ headers: {
22
+ 'content-type': 'application/json'
23
+ },
24
+ data: {
25
+ appId: appId
26
+ },
27
+ responseType: 'json'
28
+ };
29
+ return request.post(requestOptions);
30
+ }
31
+ async function grantOAuth2Permission({ appId, resourceId, scopeName }) {
32
+ const grantAdminConsentApplicationRequestOptions = {
33
+ url: `https://graph.microsoft.com/v1.0/myorganization/oauth2PermissionGrants`,
34
+ headers: {
35
+ accept: 'application/json;odata.metadata=none'
36
+ },
37
+ responseType: 'json',
38
+ data: {
39
+ clientId: appId,
40
+ consentType: "AllPrincipals",
41
+ principalId: null,
42
+ resourceId: resourceId,
43
+ scope: scopeName
44
+ }
45
+ };
46
+ return request.post(grantAdminConsentApplicationRequestOptions);
47
+ }
48
+ async function addRoleToServicePrincipal({ objectId, resourceId, appRoleId }) {
49
+ const requestOptions = {
50
+ url: `https://graph.microsoft.com/v1.0/myorganization/servicePrincipals/${objectId}/appRoleAssignments`,
51
+ headers: {
52
+ 'Content-Type': 'application/json'
53
+ },
54
+ responseType: 'json',
55
+ data: {
56
+ appRoleId: appRoleId,
57
+ principalId: objectId,
58
+ resourceId: resourceId
59
+ }
60
+ };
61
+ return request.post(requestOptions);
62
+ }
63
+ async function getRequiredResourceAccessForApis({ servicePrincipals, apis, scopeType, logger, debug }) {
64
+ if (!apis) {
65
+ return [];
66
+ }
67
+ const resolvedApis = [];
68
+ const requestedApis = apis.split(',').map(a => a.trim());
69
+ for (const api of requestedApis) {
70
+ const pos = api.lastIndexOf('/');
71
+ const permissionName = api.substring(pos + 1);
72
+ const servicePrincipalName = api.substring(0, pos);
73
+ if (debug) {
74
+ await logger.logToStderr(`Resolving ${api}...`);
75
+ await logger.logToStderr(`Permission name: ${permissionName}`);
76
+ await logger.logToStderr(`Service principal name: ${servicePrincipalName}`);
77
+ }
78
+ const servicePrincipal = servicePrincipals.find(sp => (sp.servicePrincipalNames.indexOf(servicePrincipalName) > -1 ||
79
+ sp.servicePrincipalNames.indexOf(`${servicePrincipalName}/`) > -1));
80
+ if (!servicePrincipal) {
81
+ throw `Service principal ${servicePrincipalName} not found`;
82
+ }
83
+ const scopesOfType = scopeType === 'Scope' ? servicePrincipal.oauth2PermissionScopes : servicePrincipal.appRoles;
84
+ const permission = scopesOfType.find(scope => scope.value === permissionName);
85
+ if (!permission) {
86
+ throw `Permission ${permissionName} for service principal ${servicePrincipalName} not found`;
87
+ }
88
+ let resolvedApi = resolvedApis.find(a => a.resourceAppId === servicePrincipal.appId);
89
+ if (!resolvedApi) {
90
+ resolvedApi = {
91
+ resourceAppId: servicePrincipal.appId,
92
+ resourceAccess: []
93
+ };
94
+ resolvedApis.push(resolvedApi);
95
+ }
96
+ const resourceAccessPermission = {
97
+ id: permission.id,
98
+ type: scopeType
99
+ };
100
+ resolvedApi.resourceAccess.push(resourceAccessPermission);
101
+ updateAppPermissions({
102
+ spId: servicePrincipal.id,
103
+ resourceAccessPermission,
104
+ oAuth2PermissionValue: permission.value
105
+ });
106
+ }
107
+ return resolvedApis;
108
+ }
109
+ function updateAppPermissions({ spId, resourceAccessPermission, oAuth2PermissionValue }) {
110
+ // During API resolution, we store globally both app role assignments and oauth2permissions
111
+ // So that we'll be able to parse them during the admin consent process
112
+ let existingPermission = entraApp.appPermissions.find(oauth => oauth.resourceId === spId);
113
+ if (!existingPermission) {
114
+ existingPermission = {
115
+ resourceId: spId,
116
+ resourceAccess: [],
117
+ scope: []
118
+ };
119
+ entraApp.appPermissions.push(existingPermission);
120
+ }
121
+ if (resourceAccessPermission.type === 'Scope' && oAuth2PermissionValue && !existingPermission.scope.find(scp => scp === oAuth2PermissionValue)) {
122
+ existingPermission.scope.push(oAuth2PermissionValue);
123
+ }
124
+ if (!existingPermission.resourceAccess.find(res => res.id === resourceAccessPermission.id)) {
125
+ existingPermission.resourceAccess.push(resourceAccessPermission);
126
+ }
127
+ }
128
+ export const entraApp = {
129
+ appPermissions: [],
130
+ createAppRegistration: async ({ options, apis, logger, verbose, debug }) => {
131
+ const applicationInfo = {
132
+ displayName: options.name,
133
+ signInAudience: options.multitenant ? 'AzureADMultipleOrgs' : 'AzureADMyOrg'
134
+ };
135
+ if (apis.length > 0) {
136
+ applicationInfo.requiredResourceAccess = apis;
137
+ }
138
+ if (options.redirectUris) {
139
+ applicationInfo[options.platform] = {
140
+ redirectUris: options.redirectUris.split(',').map(u => u.trim())
141
+ };
142
+ }
143
+ if (options.implicitFlow) {
144
+ if (!applicationInfo.web) {
145
+ applicationInfo.web = {};
146
+ }
147
+ applicationInfo.web.implicitGrantSettings = {
148
+ enableAccessTokenIssuance: true,
149
+ enableIdTokenIssuance: true
150
+ };
151
+ }
152
+ if (options.certificateFile || options.certificateBase64Encoded) {
153
+ const certificateBase64Encoded = await getCertificateBase64Encoded({ options, logger, debug });
154
+ const newKeyCredential = {
155
+ type: 'AsymmetricX509Cert',
156
+ usage: 'Verify',
157
+ displayName: options.certificateDisplayName,
158
+ key: certificateBase64Encoded
159
+ };
160
+ applicationInfo.keyCredentials = [newKeyCredential];
161
+ }
162
+ if (options.allowPublicClientFlows) {
163
+ applicationInfo.isFallbackPublicClient = true;
164
+ }
165
+ if (verbose) {
166
+ await logger.logToStderr(`Creating Microsoft Entra app registration...`);
167
+ }
168
+ const createApplicationRequestOptions = {
169
+ url: `https://graph.microsoft.com/v1.0/myorganization/applications`,
170
+ headers: {
171
+ accept: 'application/json;odata.metadata=none'
172
+ },
173
+ responseType: 'json',
174
+ data: applicationInfo
175
+ };
176
+ return request.post(createApplicationRequestOptions);
177
+ },
178
+ grantAdminConsent: async ({ appInfo, appPermissions, adminConsent, logger, debug }) => {
179
+ if (!adminConsent || appPermissions.length === 0) {
180
+ return appInfo;
181
+ }
182
+ const sp = await createServicePrincipal(appInfo.appId);
183
+ if (debug) {
184
+ await logger.logToStderr("Service principal created, returned object id: " + sp.id);
185
+ }
186
+ const tasks = [];
187
+ appPermissions.forEach(async (permission) => {
188
+ if (permission.scope.length > 0) {
189
+ tasks.push(grantOAuth2Permission({
190
+ appId: sp.id,
191
+ resourceId: permission.resourceId,
192
+ scopeName: permission.scope.join(' ')
193
+ }));
194
+ if (debug) {
195
+ await logger.logToStderr(`Admin consent granted for following resource ${permission.resourceId}, with delegated permissions: ${permission.scope.join(',')}`);
196
+ }
197
+ }
198
+ permission.resourceAccess.filter(access => access.type === "Role").forEach(async (access) => {
199
+ tasks.push(addRoleToServicePrincipal({
200
+ objectId: sp.id,
201
+ resourceId: permission.resourceId,
202
+ appRoleId: access.id
203
+ }));
204
+ if (debug) {
205
+ await logger.logToStderr(`Admin consent granted for following resource ${permission.resourceId}, with application permission: ${access.id}`);
206
+ }
207
+ });
208
+ });
209
+ await Promise.all(tasks);
210
+ return appInfo;
211
+ },
212
+ resolveApis: async ({ options, manifest, logger, verbose, debug }) => {
213
+ if (!options.apisDelegated && !options.apisApplication
214
+ && (typeof manifest?.requiredResourceAccess === 'undefined' || manifest.requiredResourceAccess.length === 0)) {
215
+ return [];
216
+ }
217
+ if (verbose) {
218
+ await logger.logToStderr('Resolving requested APIs...');
219
+ }
220
+ const servicePrincipals = await odata.getAllItems(`https://graph.microsoft.com/v1.0/myorganization/servicePrincipals?$select=appId,appRoles,id,oauth2PermissionScopes,servicePrincipalNames`);
221
+ let resolvedApis = [];
222
+ if (options.apisDelegated || options.apisApplication) {
223
+ resolvedApis = await getRequiredResourceAccessForApis({
224
+ servicePrincipals,
225
+ apis: options.apisDelegated,
226
+ scopeType: 'Scope',
227
+ logger,
228
+ debug
229
+ });
230
+ if (verbose) {
231
+ await logger.logToStderr(`Resolved delegated permissions: ${JSON.stringify(resolvedApis, null, 2)}`);
232
+ }
233
+ const resolvedApplicationApis = await getRequiredResourceAccessForApis({
234
+ servicePrincipals,
235
+ apis: options.apisApplication,
236
+ scopeType: 'Role',
237
+ logger,
238
+ debug
239
+ });
240
+ if (verbose) {
241
+ await logger.logToStderr(`Resolved application permissions: ${JSON.stringify(resolvedApplicationApis, null, 2)}`);
242
+ }
243
+ // merge resolved application APIs onto resolved delegated APIs
244
+ resolvedApplicationApis.forEach(resolvedRequiredResource => {
245
+ const requiredResource = resolvedApis.find(api => api.resourceAppId === resolvedRequiredResource.resourceAppId);
246
+ if (requiredResource) {
247
+ requiredResource.resourceAccess.push(...resolvedRequiredResource.resourceAccess);
248
+ }
249
+ else {
250
+ resolvedApis.push(resolvedRequiredResource);
251
+ }
252
+ });
253
+ }
254
+ else {
255
+ const manifestApis = manifest.requiredResourceAccess;
256
+ manifestApis.forEach(manifestApi => {
257
+ resolvedApis.push(manifestApi);
258
+ const app = servicePrincipals.find(servicePrincipals => servicePrincipals.appId === manifestApi.resourceAppId);
259
+ if (app) {
260
+ manifestApi.resourceAccess.forEach((res => {
261
+ const resourceAccessPermission = {
262
+ id: res.id,
263
+ type: res.type
264
+ };
265
+ const oAuthValue = app.oauth2PermissionScopes.find(scp => scp.id === res.id)?.value;
266
+ updateAppPermissions({
267
+ spId: app.id,
268
+ resourceAccessPermission,
269
+ oAuth2PermissionValue: oAuthValue
270
+ });
271
+ }));
272
+ }
273
+ });
274
+ }
275
+ if (verbose) {
276
+ await logger.logToStderr(`Merged delegated and application permissions: ${JSON.stringify(resolvedApis, null, 2)}`);
277
+ await logger.logToStderr(`App role assignments: ${JSON.stringify(entraApp.appPermissions.flatMap(permission => permission.resourceAccess.filter(access => access.type === "Role")), null, 2)}`);
278
+ await logger.logToStderr(`OAuth2 permissions: ${JSON.stringify(entraApp.appPermissions.flatMap(permission => permission.scope), null, 2)}`);
279
+ }
280
+ return resolvedApis;
281
+ }
282
+ };
283
+ //# sourceMappingURL=entraApp.js.map
@@ -39,6 +39,22 @@ export const formatting = {
39
39
  parseJsonWithBom(s) {
40
40
  return JSON.parse(s.replace(/^\uFEFF/, ''));
41
41
  },
42
+ /**
43
+ * Tries to parse a string as JSON. If it fails, returns the original string.
44
+ * @param value JSON string to parse.
45
+ * @returns JSON object or the original string if parsing fails.
46
+ */
47
+ tryParseJson(value) {
48
+ try {
49
+ if (typeof value !== 'string') {
50
+ return value;
51
+ }
52
+ return JSON.parse(value);
53
+ }
54
+ catch {
55
+ return value;
56
+ }
57
+ },
42
58
  filterObject(obj, propertiesToInclude) {
43
59
  const objKeys = Object.keys(obj);
44
60
  return propertiesToInclude