@pnp/cli-microsoft365 5.0.0-beta.a1bb50f → 5.0.0-beta.c4100fe

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 (89) hide show
  1. package/.devcontainer/devcontainer.json +12 -9
  2. package/.eslintrc.js +2 -0
  3. package/.mocharc.json +9 -0
  4. package/README.md +2 -2
  5. package/dist/Command.js +1 -1
  6. package/dist/Utils.js +4 -0
  7. package/dist/api.d.ts +11 -0
  8. package/dist/api.js +17 -0
  9. package/dist/cli/Cli.js +26 -13
  10. package/dist/m365/aad/commands/app/app-add.js +43 -7
  11. package/dist/m365/aad/commands/app/app-delete.js +123 -0
  12. package/dist/m365/aad/commands/app/app-get.js +56 -11
  13. package/dist/m365/aad/commands/app/app-set.js +98 -3
  14. package/dist/m365/aad/commands/group/group-list.js +14 -1
  15. package/dist/m365/aad/commands/o365group/o365group-conversation-list.js +41 -0
  16. package/dist/m365/aad/commands/user/user-hibp.js +67 -0
  17. package/dist/m365/aad/commands/user/user-list.js +7 -4
  18. package/dist/m365/aad/commands.js +3 -0
  19. package/dist/m365/cli/commands/config/config-set.js +4 -1
  20. package/dist/m365/flow/commands/flow-get.js +2 -2
  21. package/dist/m365/outlook/commands/room/room-list.js +43 -0
  22. package/dist/m365/outlook/commands/roomlist/roomlist-list.js +25 -0
  23. package/dist/m365/outlook/commands.js +2 -0
  24. package/dist/m365/planner/AppliedCategories.js +3 -0
  25. package/dist/m365/planner/commands/task/task-details-get.js +39 -0
  26. package/dist/m365/planner/commands/task/task-get.js +37 -0
  27. package/dist/m365/planner/commands/task/task-list.js +37 -7
  28. package/dist/m365/planner/commands/task/task-set.js +357 -0
  29. package/dist/m365/planner/commands.js +4 -1
  30. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN014008_CODE_launch_hostedWorkbench_type.js +62 -0
  31. package/dist/m365/spfx/commands/project/project-upgrade/{upgrade-1.14.0-beta.4.js → upgrade-1.14.0.js} +27 -25
  32. package/dist/m365/spfx/commands/project/project-upgrade.js +13 -15
  33. package/dist/m365/spfx/commands/spfx-doctor.js +25 -6
  34. package/dist/m365/spo/commands/group/group-user-add.js +74 -16
  35. package/dist/m365/spo/commands/group/group-user-remove.js +100 -0
  36. package/dist/m365/spo/commands/site/site-recyclebinitem-list.js +76 -0
  37. package/dist/m365/spo/commands.js +2 -0
  38. package/dist/m365/teams/commands/app/app-install.js +75 -21
  39. package/dist/m365/teams/commands/app/app-list.js +9 -6
  40. package/dist/m365/teams/commands/app/app-update.js +55 -12
  41. package/dist/m365/teams/commands/channel/channel-get.js +29 -7
  42. package/dist/m365/teams/commands/chat/chat-list.js +43 -0
  43. package/dist/m365/teams/commands/chat/chat-member-list.js +42 -0
  44. package/dist/m365/teams/commands/chat/chat-message-list.js +60 -0
  45. package/dist/m365/teams/commands/chat/chat-message-send.js +225 -0
  46. package/dist/m365/teams/commands/tab/tab-get.js +9 -6
  47. package/dist/m365/teams/commands.js +4 -0
  48. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-health-get.js +57 -0
  49. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-health-list.js +56 -0
  50. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-healthissue-get.js +39 -0
  51. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-healthissue-list.js +38 -0
  52. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-message-get.js +51 -0
  53. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-message-list.js +38 -0
  54. package/dist/m365/tenant/commands.js +6 -0
  55. package/dist/settingsNames.js +6 -1
  56. package/docs/docs/cmd/aad/app/app-delete.md +51 -0
  57. package/docs/docs/cmd/aad/app/app-get.md +12 -1
  58. package/docs/docs/cmd/aad/app/app-set.md +21 -0
  59. package/docs/docs/cmd/aad/group/group-list.md +9 -0
  60. package/docs/docs/cmd/aad/o365group/o365group-conversation-list.md +24 -0
  61. package/docs/docs/cmd/aad/user/user-hibp.md +46 -0
  62. package/docs/docs/cmd/aad/user/user-list.md +9 -0
  63. package/docs/docs/cmd/outlook/room/room-list.md +30 -0
  64. package/docs/docs/cmd/outlook/roomlist/roomlist-list.md +21 -0
  65. package/docs/docs/cmd/planner/task/task-details-get.md +24 -0
  66. package/docs/docs/cmd/planner/task/task-get.md +29 -0
  67. package/docs/docs/cmd/planner/task/task-list.md +5 -0
  68. package/docs/docs/cmd/planner/task/task-set.md +99 -0
  69. package/docs/docs/cmd/search/externalconnection/externalconnection-add.md +3 -3
  70. package/docs/docs/cmd/spfx/project/project-upgrade.md +8 -8
  71. package/docs/docs/cmd/spo/group/group-user-add.md +28 -6
  72. package/docs/docs/cmd/spo/group/group-user-remove.md +39 -0
  73. package/docs/docs/cmd/spo/site/site-recyclebinitem-list.md +40 -0
  74. package/docs/docs/cmd/teams/app/app-install.md +22 -4
  75. package/docs/docs/cmd/teams/app/app-update.md +12 -3
  76. package/docs/docs/cmd/teams/channel/channel-get.md +11 -2
  77. package/docs/docs/cmd/teams/chat/chat-list.md +30 -0
  78. package/docs/docs/cmd/teams/chat/chat-member-list.md +24 -0
  79. package/docs/docs/cmd/teams/chat/chat-message-list.md +24 -0
  80. package/docs/docs/cmd/teams/chat/chat-message-send.md +55 -0
  81. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-health-get.md +33 -0
  82. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-health-list.md +30 -0
  83. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-healthissue-get.md +24 -0
  84. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-healthissue-list.md +34 -0
  85. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-message-get.md +28 -0
  86. package/docs/docs/cmd/tenant/serviceannouncement/serviceannouncement-message-list.md +34 -0
  87. package/npm-shrinkwrap.json +838 -767
  88. package/package.json +24 -18
  89. package/dist/m365/base/AadCommand.js +0 -10
@@ -3,17 +3,20 @@
3
3
  "dockerFile": "Dockerfile",
4
4
  "settings": {
5
5
  "terminal.integrated.profiles.linux": {
6
- "zsh": {
7
- "path": "/bin/zsh",
8
- "args": [
9
- "-l"
10
- ]
11
- }
12
- },
13
- "terminal.integrated.defaultProfile.linux": "zsh"
6
+ "zsh": {
7
+ "path": "/bin/zsh",
8
+ "args": [
9
+ "-l"
10
+ ]
11
+ }
12
+ },
13
+ "terminal.integrated.defaultProfile.linux": "zsh"
14
14
  },
15
15
  "postCreateCommand": "npm i && npm run clean && npm run build && npm link",
16
16
  "extensions": [
17
- "dbaeumer.vscode-eslint"
17
+ "dbaeumer.vscode-eslint",
18
+ "hbenl.vscode-test-explorer",
19
+ "hbenl.vscode-mocha-test-adapter",
20
+ "eamodio.gitlens"
18
21
  ]
19
22
  }
package/.eslintrc.js CHANGED
@@ -23,6 +23,7 @@ const dictionary = [
23
23
  'group',
24
24
  'groupify',
25
25
  'guest',
26
+ 'health',
26
27
  'hide',
27
28
  'historical',
28
29
  'home',
@@ -48,6 +49,7 @@ const dictionary = [
48
49
  'records',
49
50
  'recycle',
50
51
  'role',
52
+ 'room',
51
53
  'schema',
52
54
  'service',
53
55
  'setting',
package/.mocharc.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extension": [
3
+ "ts"
4
+ ],
5
+ "spec": "dist/**/*.spec.js",
6
+ "require": "source-map-support/register",
7
+ "watch": "dist/**/*.js",
8
+ "logpanel": true
9
+ }
package/README.md CHANGED
@@ -208,9 +208,9 @@ If you want to get involved with helping us grow the CLI, whether that is sugges
208
208
 
209
209
  Checkout our [Wiki](https://github.com/pnp/cli-microsoft365/wiki) for guides on how to contribute to this project.
210
210
 
211
- ## Sharing is Caring
211
+ ## Microsoft 365 Platform Community
212
212
 
213
- This project is associated with the [Microsoft 365 Patterns and Practices](https://pnp.github.io) (PnP) organisation, which is a virtual team consisting of Microsoft employees and community members focused on helping the community make the best use of Microsoft products.
213
+ CLI for Microsoft 365 is a [Microsoft 365 Platform Community](https://pnp.github.io) (PnP) project. Microsoft 365 Platform Community is a virtual team consisting of Microsoft employees and community members focused on helping the community make the best use of Microsoft products. CLI for Microsoft 365 is an open-source project not affiliated with Microsoft and not covered by Microsoft support. If you experience any issues using the CLI, please submit an issue in the [issues list](https://github.com/pnp/cli-microsoft365/issues).
214
214
 
215
215
  ## Disclaimer
216
216
 
package/dist/Command.js CHANGED
@@ -113,7 +113,7 @@ class Command {
113
113
  },
114
114
  {
115
115
  option: '-o, --output [output]',
116
- autocomplete: ['json', 'text']
116
+ autocomplete: ['csv', 'json', 'text']
117
117
  },
118
118
  {
119
119
  option: '--verbose'
package/dist/Utils.js CHANGED
@@ -51,6 +51,10 @@ class Utils {
51
51
  const guidRegEx = new RegExp(/^19:[0-9a-zA-Z-_]+@thread\.(skype|tacv2)$/i);
52
52
  return guidRegEx.test(guid);
53
53
  }
54
+ static isValidTeamsChatId(guid) {
55
+ const guidRegEx = new RegExp(/^19:[0-9a-zA-Z-_]+(@thread\.v2|@unq\.gbl\.spaces)$/i);
56
+ return guidRegEx.test(guid);
57
+ }
54
58
  static isValidUserPrincipalName(upn) {
55
59
  const upnRegEx = new RegExp(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/i);
56
60
  return upnRegEx.test(upn);
package/dist/api.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface CommandOutput {
2
+ error?: {
3
+ message: string;
4
+ code?: number;
5
+ }
6
+ stdout: string;
7
+ stderr: string;
8
+ }
9
+
10
+ export declare function executeCommand(commandName: string, options: any): Promise<CommandOutput>;
11
+ export declare function on(eventName: string, listener: (...args: any[]) => void): void;
package/dist/api.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeCommand = void 0;
4
+ const cli_1 = require("./cli");
5
+ const path = require("path");
6
+ function executeCommand(commandName, options, listener) {
7
+ const cli = cli_1.Cli.getInstance();
8
+ cli.commandsFolder = path.join(__dirname, 'm365');
9
+ cli.commands = [];
10
+ cli.loadCommandFromArgs(commandName.split(' '));
11
+ if (cli.commands.length !== 1) {
12
+ return Promise.reject(`Command not found: ${commandName}`);
13
+ }
14
+ return cli_1.Cli.executeCommandWithOutput(cli.commands[0].command, { options: options !== null && options !== void 0 ? options : {} }, listener);
15
+ }
16
+ exports.executeCommand = executeCommand;
17
+ //# sourceMappingURL=api.js.map
package/dist/cli/Cli.js CHANGED
@@ -189,23 +189,38 @@ class Cli {
189
189
  });
190
190
  });
191
191
  }
192
- static executeCommandWithOutput(command, args) {
192
+ static executeCommandWithOutput(command, args, listener) {
193
193
  return new Promise((resolve, reject) => {
194
194
  const log = [];
195
195
  const logErr = [];
196
196
  const logger = {
197
197
  log: (message) => {
198
- log.push(Cli.formatOutput(message, args.options));
198
+ const formattedMessage = Cli.formatOutput(message, args.options);
199
+ if (listener && listener.stdout) {
200
+ listener.stdout(formattedMessage);
201
+ }
202
+ log.push(formattedMessage);
199
203
  },
200
204
  logRaw: (message) => {
201
- log.push(Cli.formatOutput(message, args.options));
205
+ const formattedMessage = Cli.formatOutput(message, args.options);
206
+ if (listener && listener.stdout) {
207
+ listener.stdout(formattedMessage);
208
+ }
209
+ log.push(formattedMessage);
202
210
  },
203
211
  logToStderr: (message) => {
212
+ if (listener && listener.stderr) {
213
+ listener.stderr(message);
214
+ }
204
215
  logErr.push(message);
205
216
  }
206
217
  };
207
218
  if (args.options.debug) {
208
- logErr.push(`Executing command ${command.name} with options ${JSON.stringify(args)}`);
219
+ const message = `Executing command ${command.name} with options ${JSON.stringify(args)}`;
220
+ if (listener && listener.stderr) {
221
+ listener.stderr(message);
222
+ }
223
+ logErr.push(message);
209
224
  }
210
225
  // store the current command name, if any and set the name to the name of
211
226
  // the command to execute
@@ -447,16 +462,14 @@ class Cli {
447
462
  }
448
463
  if (options.output === 'csv') {
449
464
  const { stringify } = require('csv-stringify/sync');
450
- /*
451
- https://csv.js.org/stringify/options/
452
- header: Display the column names on the first line if the columns option is provided or discovered.
453
- escape: Single character used for escaping; only apply to characters matching the quote and the escape options default to ".
454
- quote: The quote characters surrounding a field, defaults to the " (double quotation marks), an empty quote value will preserve the original field, whether it contains quotation marks or not.
455
- quoted: Boolean, default to false, quote all the non-empty fields even if not required.
456
- quotedEmpty: Quote empty strings and overrides quoted_string on empty strings when defined; default is false.
457
- */
465
+ const cli = Cli.getInstance();
466
+ // https://csv.js.org/stringify/options/
458
467
  return stringify(logStatement, {
459
- header: true
468
+ header: cli.getSettingWithDefaultValue(settingsNames_1.settingsNames.csvHeader, true),
469
+ escape: cli.getSettingWithDefaultValue(settingsNames_1.settingsNames.csvEscape, '"'),
470
+ quote: cli.config.get(settingsNames_1.settingsNames.csvQuote),
471
+ quoted: cli.getSettingWithDefaultValue(settingsNames_1.settingsNames.csvQuoted, false),
472
+ quotedEmpty: cli.getSettingWithDefaultValue(settingsNames_1.settingsNames.csvQuotedEmpty, false)
460
473
  });
461
474
  }
462
475
  // display object as a list of key-value pairs
@@ -105,21 +105,49 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
105
105
  if (!args.options.manifest) {
106
106
  return Promise.resolve(appInfo);
107
107
  }
108
- const manifest = JSON.parse(args.options.manifest);
108
+ const v2Manifest = JSON.parse(args.options.manifest);
109
109
  // remove properties that might be coming from the original app that was
110
110
  // used to create the manifest and which can't be updated
111
- delete manifest.id;
112
- delete manifest.appId;
113
- delete manifest.publisherDomain;
111
+ delete v2Manifest.id;
112
+ delete v2Manifest.appId;
113
+ delete v2Manifest.publisherDomain;
114
114
  // Azure Portal returns v2 manifest whereas the Graph API expects a v1.6
115
- const transformedManifest = this.transformManifest(manifest);
115
+ const graphManifest = this.transformManifest(v2Manifest);
116
116
  const updateAppRequestOptions = {
117
117
  url: `${this.resource}/v1.0/myorganization/applications/${appInfo.id}`,
118
118
  headers: {
119
119
  'content-type': 'application/json'
120
120
  },
121
121
  responseType: 'json',
122
- data: transformedManifest
122
+ data: graphManifest
123
+ };
124
+ return request_1.default
125
+ .patch(updateAppRequestOptions)
126
+ .then(_ => this.updatePreAuthorizedAppsFromManifest(v2Manifest, appInfo))
127
+ .then(_ => Promise.resolve(appInfo));
128
+ }
129
+ updatePreAuthorizedAppsFromManifest(manifest, appInfo) {
130
+ if (!manifest ||
131
+ !manifest.preAuthorizedApplications ||
132
+ manifest.preAuthorizedApplications.length === 0) {
133
+ return Promise.resolve(appInfo);
134
+ }
135
+ const graphManifest = {
136
+ api: {
137
+ preAuthorizedApplications: manifest.preAuthorizedApplications
138
+ }
139
+ };
140
+ graphManifest.api.preAuthorizedApplications.forEach((p) => {
141
+ p.delegatedPermissionIds = p.permissionIds;
142
+ delete p.permissionIds;
143
+ });
144
+ const updateAppRequestOptions = {
145
+ url: `${this.resource}/v1.0/myorganization/applications/${appInfo.id}`,
146
+ headers: {
147
+ 'content-type': 'application/json'
148
+ },
149
+ responseType: 'json',
150
+ data: graphManifest
123
151
  };
124
152
  return request_1.default
125
153
  .patch(updateAppRequestOptions)
@@ -180,8 +208,16 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
180
208
  delete graphManifest.oauth2AllowIdTokenImplicitFlow;
181
209
  graphManifest.api.oauth2PermissionScopes = v2Manifest.oauth2Permissions;
182
210
  delete graphManifest.oauth2Permissions;
211
+ if (graphManifest.api.oauth2PermissionScopes) {
212
+ graphManifest.api.oauth2PermissionScopes.forEach((scope) => {
213
+ delete scope.lang;
214
+ delete scope.origin;
215
+ });
216
+ }
183
217
  delete graphManifest.oauth2RequiredPostResponse;
184
- graphManifest.api.preAuthorizedApplications = v2Manifest.preAuthorizedApplications;
218
+ // MS Graph doesn't support creating OAuth2 permissions and pre-authorized
219
+ // apps in one request. This is why we need to remove it here and do it in
220
+ // the next request
185
221
  delete graphManifest.preAuthorizedApplications;
186
222
  if (v2Manifest.replyUrlsWithType) {
187
223
  v2Manifest.replyUrlsWithType.forEach((urlWithType) => {
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("../../../../cli");
4
+ const request_1 = require("../../../../request");
5
+ const Utils_1 = require("../../../../Utils");
6
+ const GraphCommand_1 = require("../../../base/GraphCommand");
7
+ const commands_1 = require("../../commands");
8
+ class AadAppDeleteCommand extends GraphCommand_1.default {
9
+ get name() {
10
+ return commands_1.default.APP_DELETE;
11
+ }
12
+ get description() {
13
+ return 'Removes an Azure AD app registration';
14
+ }
15
+ getTelemetryProperties(args) {
16
+ const telemetryProps = super.getTelemetryProperties(args);
17
+ telemetryProps.appId = typeof args.options.appId !== 'undefined';
18
+ telemetryProps.objectId = typeof args.options.objectId !== 'undefined';
19
+ telemetryProps.name = typeof args.options.name !== 'undefined';
20
+ telemetryProps.confirm = (!(!args.options.confirm)).toString();
21
+ return telemetryProps;
22
+ }
23
+ commandAction(logger, args, cb) {
24
+ const deleteApp = () => {
25
+ this
26
+ .getObjectId(args, logger)
27
+ .then((objectId) => {
28
+ if (this.verbose) {
29
+ logger.logToStderr(`Deleting Azure AD app ${objectId}...`);
30
+ }
31
+ const requestOptions = {
32
+ url: `${this.resource}/v1.0/myorganization/applications/${objectId}`,
33
+ headers: {
34
+ accept: 'application/json;odata.metadata=none'
35
+ },
36
+ responseType: 'json'
37
+ };
38
+ return request_1.default.delete(requestOptions);
39
+ })
40
+ .then(_ => cb(), (rawRes) => this.handleRejectedODataJsonPromise(rawRes, logger, cb));
41
+ };
42
+ if (args.options.confirm) {
43
+ deleteApp();
44
+ }
45
+ else {
46
+ cli_1.Cli.prompt({
47
+ type: 'confirm',
48
+ name: 'continue',
49
+ default: false,
50
+ message: `Are you sure you want to delete the App?`
51
+ }, (result) => {
52
+ if (!result.continue) {
53
+ cb();
54
+ }
55
+ else {
56
+ deleteApp();
57
+ }
58
+ });
59
+ }
60
+ }
61
+ getObjectId(args, logger) {
62
+ if (args.options.objectId) {
63
+ return Promise.resolve(args.options.objectId);
64
+ }
65
+ const { appId, name } = args.options;
66
+ if (this.verbose) {
67
+ logger.logToStderr(`Retrieving information about Azure AD app ${appId ? appId : name}...`);
68
+ }
69
+ const filter = appId ?
70
+ `appId eq '${encodeURIComponent(appId)}'` :
71
+ `displayName eq '${encodeURIComponent(name)}'`;
72
+ const requestOptions = {
73
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
74
+ headers: {
75
+ accept: 'application/json;odata.metadata=none'
76
+ },
77
+ responseType: 'json'
78
+ };
79
+ return request_1.default
80
+ .get(requestOptions)
81
+ .then((res) => {
82
+ if (res.value.length === 1) {
83
+ return Promise.resolve(res.value[0].id);
84
+ }
85
+ if (res.value.length === 0) {
86
+ const applicationIdentifier = appId ? `ID ${appId}` : `name ${name}`;
87
+ return Promise.reject(`No Azure AD application registration with ${applicationIdentifier} found`);
88
+ }
89
+ return Promise.reject(`Multiple Azure AD application registration with name ${name} found. Please choose one of the object IDs: ${res.value.map(a => a.id).join(', ')}`);
90
+ });
91
+ }
92
+ options() {
93
+ const options = [
94
+ { option: '--appId [appId]' },
95
+ { option: '--objectId [objectId]' },
96
+ { option: '--name [name]' },
97
+ { option: '--confirm' }
98
+ ];
99
+ const parentOptions = super.options();
100
+ return options.concat(parentOptions);
101
+ }
102
+ validate(args) {
103
+ if (!args.options.appId &&
104
+ !args.options.objectId &&
105
+ !args.options.name) {
106
+ return 'Specify either appId, objectId, or name';
107
+ }
108
+ if ((args.options.appId && args.options.objectId) ||
109
+ (args.options.appId && args.options.name) ||
110
+ (args.options.objectId && args.options.name)) {
111
+ return 'Specify either appId, objectId, or name';
112
+ }
113
+ if (args.options.appId && !Utils_1.default.isValidGuid(args.options.appId)) {
114
+ return `${args.options.appId} is not a valid GUID`;
115
+ }
116
+ if (args.options.objectId && !Utils_1.default.isValidGuid(args.options.objectId)) {
117
+ return `${args.options.objectId} is not a valid GUID`;
118
+ }
119
+ return true;
120
+ }
121
+ }
122
+ module.exports = new AadAppDeleteCommand();
123
+ //# sourceMappingURL=app-delete.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
3
4
  const request_1 = require("../../../../request");
4
5
  const Utils_1 = require("../../../../Utils");
5
6
  const GraphCommand_1 = require("../../../base/GraphCommand");
@@ -21,16 +22,8 @@ class AadAppGetCommand extends GraphCommand_1.default {
21
22
  commandAction(logger, args, cb) {
22
23
  this
23
24
  .getAppObjectId(args)
24
- .then((appObjectId) => {
25
- const requestOptions = {
26
- url: `${this.resource}/v1.0/myorganization/applications/${appObjectId}`,
27
- headers: {
28
- accept: 'application/json;odata.metadata=none'
29
- },
30
- responseType: 'json'
31
- };
32
- return request_1.default.get(requestOptions);
33
- })
25
+ .then(appObjectId => this.getAppInfo(appObjectId))
26
+ .then(appInfo => this.saveAppInfo(args, appInfo, logger))
34
27
  .then((res) => {
35
28
  logger.log(res);
36
29
  cb();
@@ -64,11 +57,63 @@ class AadAppGetCommand extends GraphCommand_1.default {
64
57
  return Promise.reject(`Multiple Azure AD application registration with name ${name} found. Please disambiguate (app object IDs): ${res.value.map(a => a.id).join(', ')}`);
65
58
  });
66
59
  }
60
+ getAppInfo(appObjectId) {
61
+ const requestOptions = {
62
+ url: `${this.resource}/v1.0/myorganization/applications/${appObjectId}`,
63
+ headers: {
64
+ accept: 'application/json;odata.metadata=none'
65
+ },
66
+ responseType: 'json'
67
+ };
68
+ return request_1.default.get(requestOptions);
69
+ }
70
+ saveAppInfo(args, appInfo, logger) {
71
+ if (!args.options.save) {
72
+ return Promise.resolve(appInfo);
73
+ }
74
+ const filePath = '.m365rc.json';
75
+ if (this.verbose) {
76
+ logger.logToStderr(`Saving Azure AD app registration information to the ${filePath} file...`);
77
+ }
78
+ let m365rc = {};
79
+ if (fs.existsSync(filePath)) {
80
+ if (this.debug) {
81
+ logger.logToStderr(`Reading existing ${filePath}...`);
82
+ }
83
+ try {
84
+ const fileContents = fs.readFileSync(filePath, 'utf8');
85
+ if (fileContents) {
86
+ m365rc = JSON.parse(fileContents);
87
+ }
88
+ }
89
+ catch (e) {
90
+ logger.logToStderr(`Error reading ${filePath}: ${e}. Please add app info to ${filePath} manually.`);
91
+ return Promise.resolve(appInfo);
92
+ }
93
+ }
94
+ if (!m365rc.apps) {
95
+ m365rc.apps = [];
96
+ }
97
+ if (!m365rc.apps.some(a => a.appId === appInfo.appId)) {
98
+ m365rc.apps.push({
99
+ appId: appInfo.appId,
100
+ name: appInfo.displayName
101
+ });
102
+ try {
103
+ fs.writeFileSync(filePath, JSON.stringify(m365rc, null, 2));
104
+ }
105
+ catch (e) {
106
+ logger.logToStderr(`Error writing ${filePath}: ${e}. Please add app info to ${filePath} manually.`);
107
+ }
108
+ }
109
+ return Promise.resolve(appInfo);
110
+ }
67
111
  options() {
68
112
  const options = [
69
113
  { option: '--appId [appId]' },
70
114
  { option: '--objectId [objectId]' },
71
- { option: '--name [name]' }
115
+ { option: '--name [name]' },
116
+ { option: '--save' }
72
117
  ];
73
118
  const parentOptions = super.options();
74
119
  return options.concat(parentOptions);
@@ -15,6 +15,9 @@ class AadAppSetCommand extends GraphCommand_1.default {
15
15
  telemetryProps.appId = typeof args.options.appId !== 'undefined';
16
16
  telemetryProps.objectId = typeof args.options.objectId !== 'undefined';
17
17
  telemetryProps.name = typeof args.options.name !== 'undefined';
18
+ telemetryProps.platform = typeof args.options.platform !== 'undefined';
19
+ telemetryProps.redirectUris = typeof args.options.redirectUris !== 'undefined';
20
+ telemetryProps.redirectUrisToRemove = typeof args.options.redirectUrisToRemove !== 'undefined';
18
21
  telemetryProps.uri = typeof args.options.uri !== 'undefined';
19
22
  return telemetryProps;
20
23
  }
@@ -22,6 +25,7 @@ class AadAppSetCommand extends GraphCommand_1.default {
22
25
  this
23
26
  .getAppObjectId(args, logger)
24
27
  .then(objectId => this.configureUri(args, objectId, logger))
28
+ .then(objectId => this.configureRedirectUris(args, objectId, logger))
25
29
  .then(_ => cb(), (rawRes) => this.handleRejectedODataJsonPromise(rawRes, logger, cb));
26
30
  }
27
31
  getAppObjectId(args, logger) {
@@ -57,7 +61,7 @@ class AadAppSetCommand extends GraphCommand_1.default {
57
61
  }
58
62
  configureUri(args, objectId, logger) {
59
63
  if (!args.options.uri) {
60
- return Promise.resolve();
64
+ return Promise.resolve(objectId);
61
65
  }
62
66
  if (this.verbose) {
63
67
  logger.logToStderr(`Configuring Azure AD application ID URI...`);
@@ -73,14 +77,97 @@ class AadAppSetCommand extends GraphCommand_1.default {
73
77
  responseType: 'json',
74
78
  data: applicationInfo
75
79
  };
76
- return request_1.default.patch(requestOptions);
80
+ return request_1.default
81
+ .patch(requestOptions)
82
+ .then(_ => Promise.resolve(objectId));
83
+ }
84
+ configureRedirectUris(args, objectId, logger) {
85
+ if (!args.options.redirectUris && !args.options.redirectUrisToRemove) {
86
+ return Promise.resolve(objectId);
87
+ }
88
+ if (this.verbose) {
89
+ logger.logToStderr(`Configuring Azure AD application redirect URIs...`);
90
+ }
91
+ const getAppRequestOptions = {
92
+ url: `${this.resource}/v1.0/myorganization/applications/${objectId}`,
93
+ headers: {
94
+ 'content-type': 'application/json;odata.metadata=none'
95
+ },
96
+ responseType: 'json'
97
+ };
98
+ return request_1.default
99
+ .get(getAppRequestOptions)
100
+ .then((application) => {
101
+ const publicClientRedirectUris = application.publicClient.redirectUris;
102
+ const spaRedirectUris = application.spa.redirectUris;
103
+ const webRedirectUris = application.web.redirectUris;
104
+ // start with existing redirect URIs
105
+ const applicationPatch = {
106
+ publicClient: {
107
+ redirectUris: publicClientRedirectUris
108
+ },
109
+ spa: {
110
+ redirectUris: spaRedirectUris
111
+ },
112
+ web: {
113
+ redirectUris: webRedirectUris
114
+ }
115
+ };
116
+ if (args.options.redirectUrisToRemove) {
117
+ // remove redirect URIs from all platforms
118
+ const redirectUrisToRemove = args.options.redirectUrisToRemove
119
+ .split(',')
120
+ .map(u => u.trim());
121
+ applicationPatch.publicClient.redirectUris =
122
+ publicClientRedirectUris.filter(u => !redirectUrisToRemove.includes(u));
123
+ applicationPatch.spa.redirectUris =
124
+ spaRedirectUris.filter(u => !redirectUrisToRemove.includes(u));
125
+ applicationPatch.web.redirectUris =
126
+ webRedirectUris.filter(u => !redirectUrisToRemove.includes(u));
127
+ }
128
+ if (args.options.redirectUris) {
129
+ const urlsToAdd = args.options.redirectUris
130
+ .split(',')
131
+ .map(u => u.trim());
132
+ // add new redirect URIs. If the URI is already present, it will be ignored
133
+ switch (args.options.platform) {
134
+ case 'spa':
135
+ applicationPatch.spa.redirectUris
136
+ .push(...urlsToAdd.filter(u => !spaRedirectUris.includes(u)));
137
+ break;
138
+ case 'publicClient':
139
+ applicationPatch.publicClient.redirectUris
140
+ .push(...urlsToAdd.filter(u => !publicClientRedirectUris.includes(u)));
141
+ break;
142
+ case 'web':
143
+ applicationPatch.web.redirectUris
144
+ .push(...urlsToAdd.filter(u => !webRedirectUris.includes(u)));
145
+ }
146
+ }
147
+ const requestOptions = {
148
+ url: `${this.resource}/v1.0/myorganization/applications/${objectId}`,
149
+ headers: {
150
+ 'content-type': 'application/json;odata.metadata=none'
151
+ },
152
+ responseType: 'json',
153
+ data: applicationPatch
154
+ };
155
+ return request_1.default.patch(requestOptions);
156
+ })
157
+ .then(_ => Promise.resolve(objectId));
77
158
  }
78
159
  options() {
79
160
  const options = [
80
161
  { option: '--appId [appId]' },
81
162
  { option: '--objectId [objectId]' },
82
163
  { option: '-n, --name [name]' },
83
- { option: '-u, --uri [uri]' }
164
+ { option: '-u, --uri [uri]' },
165
+ { option: '-r, --redirectUris [redirectUris]' },
166
+ {
167
+ option: '--platform [platform]',
168
+ autocomplete: AadAppSetCommand.aadApplicationPlatform
169
+ },
170
+ { option: '--redirectUrisToRemove [redirectUrisToRemove]' }
84
171
  ];
85
172
  const parentOptions = super.options();
86
173
  return options.concat(parentOptions);
@@ -96,8 +183,16 @@ class AadAppSetCommand extends GraphCommand_1.default {
96
183
  (args.options.objectId && args.options.name)) {
97
184
  return 'Specify either appId, objectId or name but not both';
98
185
  }
186
+ if (args.options.redirectUris && !args.options.platform) {
187
+ return `When you specify redirectUris you also need to specify platform`;
188
+ }
189
+ if (args.options.platform &&
190
+ AadAppSetCommand.aadApplicationPlatform.indexOf(args.options.platform) < 0) {
191
+ return `${args.options.platform} is not a valid value for platform. Allowed values are ${AadAppSetCommand.aadApplicationPlatform.join(', ')}`;
192
+ }
99
193
  return true;
100
194
  }
101
195
  }
196
+ AadAppSetCommand.aadApplicationPlatform = ['spa', 'web', 'publicClient'];
102
197
  module.exports = new AadAppSetCommand();
103
198
  //# sourceMappingURL=app-set.js.map
@@ -9,12 +9,18 @@ class AadGroupListCommand extends GraphItemsListCommand_1.GraphItemsListCommand
9
9
  get description() {
10
10
  return 'Lists all groups defined in Azure Active Directory.';
11
11
  }
12
+ getTelemetryProperties(args) {
13
+ const telemetryProps = super.getTelemetryProperties(args);
14
+ telemetryProps.deleted = args.options.deleted;
15
+ return telemetryProps;
16
+ }
12
17
  defaultProperties() {
13
18
  return ['id', 'displayName', 'groupType'];
14
19
  }
15
20
  commandAction(logger, args, cb) {
21
+ const endpoint = args.options.deleted ? 'directory/deletedItems/microsoft.graph.group' : 'groups';
16
22
  this
17
- .getAllItems(`${this.resource}/v1.0/groups`, logger, true)
23
+ .getAllItems(`${this.resource}/v1.0/${endpoint}`, logger, true)
18
24
  .then(() => {
19
25
  if (args.options.output === 'text') {
20
26
  this.items.forEach((group) => {
@@ -36,6 +42,13 @@ class AadGroupListCommand extends GraphItemsListCommand_1.GraphItemsListCommand
36
42
  cb();
37
43
  }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
38
44
  }
45
+ options() {
46
+ const options = [
47
+ { option: '-d, --deleted' }
48
+ ];
49
+ const parentOptions = super.options();
50
+ return options.concat(parentOptions);
51
+ }
39
52
  }
40
53
  module.exports = new AadGroupListCommand();
41
54
  //# sourceMappingURL=group-list.js.map