@pnp/cli-microsoft365 7.6.0-beta.682272b → 7.6.0-beta.c74fe4b

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/cli/cli.js CHANGED
@@ -98,7 +98,7 @@ async function execute(rawArgs) {
98
98
  if (parsedArgs.output !== 'none') {
99
99
  printHelp(await getHelpMode(parsedArgs));
100
100
  }
101
- return Promise.resolve();
101
+ return;
102
102
  }
103
103
  delete cli.optionsFromArgs.options._;
104
104
  delete cli.optionsFromArgs.options['--'];
@@ -0,0 +1,123 @@
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 _PurviewThreatAssessmentAddCommand_instances, _PurviewThreatAssessmentAddCommand_initTelemetry, _PurviewThreatAssessmentAddCommand_initOptions, _PurviewThreatAssessmentAddCommand_initValidators, _PurviewThreatAssessmentAddCommand_initOptionSets;
7
+ import request from '../../../../request.js';
8
+ import { accessToken } from '../../../../utils/accessToken.js';
9
+ import GraphCommand from '../../../base/GraphCommand.js';
10
+ import commands from '../../commands.js';
11
+ import auth from '../../../../Auth.js';
12
+ import fs from 'fs';
13
+ import path from 'path';
14
+ class PurviewThreatAssessmentAddCommand extends GraphCommand {
15
+ get name() {
16
+ return commands.THREATASSESSMENT_ADD;
17
+ }
18
+ get description() {
19
+ return 'Create a threat assessment';
20
+ }
21
+ constructor() {
22
+ super();
23
+ _PurviewThreatAssessmentAddCommand_instances.add(this);
24
+ this.allowedTypes = ['file', 'url'];
25
+ this.allowedExpectedAssessments = ['block', 'unblock'];
26
+ this.allowedCategories = ['spam', 'phishing', 'malware'];
27
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentAddCommand_instances, "m", _PurviewThreatAssessmentAddCommand_initTelemetry).call(this);
28
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentAddCommand_instances, "m", _PurviewThreatAssessmentAddCommand_initOptions).call(this);
29
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentAddCommand_instances, "m", _PurviewThreatAssessmentAddCommand_initValidators).call(this);
30
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentAddCommand_instances, "m", _PurviewThreatAssessmentAddCommand_initOptionSets).call(this);
31
+ }
32
+ async commandAction(logger, args) {
33
+ try {
34
+ if (accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[this.resource].accessToken)) {
35
+ throw 'This command currently does not support app only permissions.';
36
+ }
37
+ if (this.verbose) {
38
+ await logger.logToStderr(`Adding threat assessment of type ${args.options.type} with expected assessment ${args.options.expectedAssessment} and category ${args.options.category}`);
39
+ }
40
+ const requestBody = {
41
+ expectedAssessment: args.options.expectedAssessment,
42
+ category: args.options.category,
43
+ url: args.options.url,
44
+ contentData: args.options.path && fs.readFileSync(args.options.path).toString('base64'),
45
+ fileName: args.options.path && path.basename(args.options.path)
46
+ };
47
+ switch (args.options.type) {
48
+ case 'file':
49
+ requestBody['@odata.type'] = '#microsoft.graph.fileAssessmentRequest';
50
+ break;
51
+ case 'url':
52
+ requestBody['@odata.type'] = '#microsoft.graph.urlAssessmentRequest';
53
+ break;
54
+ }
55
+ const requestOptions = {
56
+ url: `${this.resource}/v1.0/informationProtection/threatAssessmentRequests`,
57
+ headers: {
58
+ accept: 'application/json;odata.metadata=none'
59
+ },
60
+ data: requestBody,
61
+ responseType: 'json'
62
+ };
63
+ const response = await request.post(requestOptions);
64
+ await logger.log(response);
65
+ }
66
+ catch (err) {
67
+ this.handleRejectedODataPromise(err);
68
+ }
69
+ }
70
+ }
71
+ _PurviewThreatAssessmentAddCommand_instances = new WeakSet(), _PurviewThreatAssessmentAddCommand_initTelemetry = function _PurviewThreatAssessmentAddCommand_initTelemetry() {
72
+ this.telemetry.push((args) => {
73
+ Object.assign(this.telemetryProperties, {
74
+ path: typeof args.options.path !== 'undefined',
75
+ url: typeof args.options.url !== 'undefined'
76
+ });
77
+ });
78
+ }, _PurviewThreatAssessmentAddCommand_initOptions = function _PurviewThreatAssessmentAddCommand_initOptions() {
79
+ this.options.unshift({
80
+ option: '-t, --type <type>',
81
+ autocomplete: this.allowedTypes
82
+ }, {
83
+ option: '-e, --expectedAssessment <expectedAssessment>',
84
+ autocomplete: this.allowedExpectedAssessments
85
+ }, {
86
+ option: '-c, --category <category>',
87
+ autocomplete: this.allowedCategories
88
+ }, {
89
+ option: '-p, --path [path]'
90
+ }, {
91
+ option: '-u, --url [url]'
92
+ });
93
+ }, _PurviewThreatAssessmentAddCommand_initValidators = function _PurviewThreatAssessmentAddCommand_initValidators() {
94
+ this.validators.push(async (args) => {
95
+ if (!this.allowedTypes.some(type => type === args.options.type)) {
96
+ return `${args.options.type} is not an allowed type. Allowed types are ${this.allowedTypes.join('|')}`;
97
+ }
98
+ if (!this.allowedExpectedAssessments.some(expectedAssessment => expectedAssessment === args.options.expectedAssessment)) {
99
+ return `${args.options.expectedAssessment} is not an allowed expected assessment. Allowed expected assessments are ${this.allowedExpectedAssessments.join('|')}`;
100
+ }
101
+ if (!this.allowedCategories.some(category => category === args.options.category)) {
102
+ return `${args.options.category} is not an allowed category. Allowed categories are ${this.allowedCategories.join('|')}`;
103
+ }
104
+ if (args.options.path && !fs.existsSync(args.options.path)) {
105
+ return `File '${args.options.path}' not found. Please provide a valid path to the file.`;
106
+ }
107
+ return true;
108
+ });
109
+ }, _PurviewThreatAssessmentAddCommand_initOptionSets = function _PurviewThreatAssessmentAddCommand_initOptionSets() {
110
+ this.optionSets.push({
111
+ options: ['path'],
112
+ runsWhen: (args) => {
113
+ return args.options.type === 'file';
114
+ }
115
+ }, {
116
+ options: ['url'],
117
+ runsWhen: (args) => {
118
+ return args.options.type === 'url';
119
+ }
120
+ });
121
+ };
122
+ export default new PurviewThreatAssessmentAddCommand();
123
+ //# sourceMappingURL=threatassessment-add.js.map
@@ -0,0 +1,104 @@
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 _PurviewThreatAssessmentListCommand_instances, _a, _PurviewThreatAssessmentListCommand_initTelemetry, _PurviewThreatAssessmentListCommand_initOptions, _PurviewThreatAssessmentListCommand_initValidators;
7
+ import { odata } from '../../../../utils/odata.js';
8
+ import GraphCommand from '../../../base/GraphCommand.js';
9
+ import commands from '../../commands.js';
10
+ class PurviewThreatAssessmentListCommand extends GraphCommand {
11
+ get name() {
12
+ return commands.THREATASSESSMENT_LIST;
13
+ }
14
+ get description() {
15
+ return 'Get a list of threat assessments';
16
+ }
17
+ defaultProperties() {
18
+ return ['id', 'type', 'category'];
19
+ }
20
+ constructor() {
21
+ super();
22
+ _PurviewThreatAssessmentListCommand_instances.add(this);
23
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentListCommand_instances, "m", _PurviewThreatAssessmentListCommand_initTelemetry).call(this);
24
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentListCommand_instances, "m", _PurviewThreatAssessmentListCommand_initOptions).call(this);
25
+ __classPrivateFieldGet(this, _PurviewThreatAssessmentListCommand_instances, "m", _PurviewThreatAssessmentListCommand_initValidators).call(this);
26
+ }
27
+ async commandAction(logger, args) {
28
+ if (this.verbose) {
29
+ logger.logToStderr('Retrieving a list of threat assessments');
30
+ }
31
+ try {
32
+ const filter = this.getFilterQuery(args.options);
33
+ const items = await odata.getAllItems(`${this.resource}/v1.0/informationProtection/threatAssessmentRequests${filter}`, 'minimal');
34
+ let itemsToReturn = [];
35
+ switch (args.options.type) {
36
+ case 'mail':
37
+ itemsToReturn = items.filter(item => item['@odata.type'] === '#microsoft.graph.mailAssessmentRequest');
38
+ break;
39
+ case 'emailFile':
40
+ itemsToReturn = items.filter(item => item['@odata.type'] === '#microsoft.graph.emailFileAssessmentRequest');
41
+ break;
42
+ default:
43
+ itemsToReturn = items;
44
+ break;
45
+ }
46
+ for (const item of itemsToReturn) {
47
+ item['type'] = this.getConvertedType(item['@odata.type']);
48
+ delete item['@odata.type'];
49
+ }
50
+ await logger.log(itemsToReturn);
51
+ }
52
+ catch (err) {
53
+ this.handleRejectedODataJsonPromise(err);
54
+ }
55
+ }
56
+ // Content type is not equal to type.
57
+ // Threat assessments of type emailFile have contentType mail as well.
58
+ // This function gets the correct filter URL to be able to query the least amount of data
59
+ getFilterQuery(options) {
60
+ if (options.type === undefined) {
61
+ return '';
62
+ }
63
+ if (options.type === 'emailFile') {
64
+ return `?$filter=contentType eq 'mail'`;
65
+ }
66
+ return `?$filter=contentType eq '${options.type}'`;
67
+ }
68
+ getConvertedType(type) {
69
+ switch (type) {
70
+ case '#microsoft.graph.mailAssessmentRequest':
71
+ return 'mail';
72
+ case '#microsoft.graph.fileAssessmentRequest':
73
+ return 'file';
74
+ case '#microsoft.graph.emailFileAssessmentRequest':
75
+ return 'emailFile';
76
+ case '#microsoft.graph.urlAssessmentRequest':
77
+ return 'url';
78
+ default:
79
+ return 'Unknown';
80
+ }
81
+ }
82
+ }
83
+ _a = PurviewThreatAssessmentListCommand, _PurviewThreatAssessmentListCommand_instances = new WeakSet(), _PurviewThreatAssessmentListCommand_initTelemetry = function _PurviewThreatAssessmentListCommand_initTelemetry() {
84
+ this.telemetry.push((args) => {
85
+ Object.assign(this.telemetryProperties, {
86
+ type: typeof args.options.type !== 'undefined'
87
+ });
88
+ });
89
+ }, _PurviewThreatAssessmentListCommand_initOptions = function _PurviewThreatAssessmentListCommand_initOptions() {
90
+ this.options.unshift({
91
+ option: '-t, --type [type]',
92
+ autocomplete: _a.allowedTypes
93
+ });
94
+ }, _PurviewThreatAssessmentListCommand_initValidators = function _PurviewThreatAssessmentListCommand_initValidators() {
95
+ this.validators.push(async (args) => {
96
+ if (args.options.type && _a.allowedTypes.indexOf(args.options.type) < 0) {
97
+ return `${args.options.type} is not a valid type. Allowed values are ${_a.allowedTypes.join(', ')}`;
98
+ }
99
+ return true;
100
+ });
101
+ };
102
+ PurviewThreatAssessmentListCommand.allowedTypes = ['mail', 'file', 'emailFile', 'url'];
103
+ export default new PurviewThreatAssessmentListCommand();
104
+ //# sourceMappingURL=threatassessment-list.js.map
@@ -18,6 +18,8 @@ export default {
18
18
  SENSITIVITYLABEL_GET: `${prefix} sensitivitylabel get`,
19
19
  SENSITIVITYLABEL_LIST: `${prefix} sensitivitylabel list`,
20
20
  SENSITIVITYLABEL_POLICYSETTINGS_LIST: `${prefix} sensitivitylabel policysettings list`,
21
- THREATASSESSMENT_GET: `${prefix} threatassessment get`
21
+ THREATASSESSMENT_ADD: `${prefix} threatassessment add`,
22
+ THREATASSESSMENT_GET: `${prefix} threatassessment get`,
23
+ THREATASSESSMENT_LIST: `${prefix} threatassessment list`
22
24
  };
23
25
  //# sourceMappingURL=commands.js.map
@@ -0,0 +1,131 @@
1
+ import Global from '/docs/cmd/_global.mdx';
2
+ import Tabs from '@theme/Tabs';
3
+ import TabItem from '@theme/TabItem';
4
+
5
+ # purview threatassessment add
6
+
7
+ Create a threat assessment
8
+
9
+ ## Usage
10
+
11
+ ```sh
12
+ m365 purview threatassessment add [options]
13
+ ```
14
+
15
+ ## Options
16
+
17
+ ```md definition-list
18
+ `-t, --type <type>`
19
+ : The type of threat assessment to retrieve. Supports `file` and `url`.
20
+
21
+ `-e, --expectedAssessment <expectedAssessment>`
22
+ : The expected assessment from submitter. Possible values are: `block` and `unblock`.
23
+
24
+ `-c, --category <category>`
25
+ : The threat category. Possible values are: `spam`, `phishing`, `malware`.
26
+
27
+ `-p, --path [path]`
28
+ : Local path to the file to upload. Can only be used for threat assessment with type `file`.
29
+
30
+ `-u, --url [url]`
31
+ : The URL string. Can only be used for threat assessment with type `url`.
32
+ ```
33
+
34
+ <Global />
35
+
36
+ ## Remarks
37
+
38
+ :::info
39
+
40
+ This command currently only supports delegated permissions.
41
+
42
+ :::
43
+
44
+ ## Examples
45
+
46
+ Create a file threat assessment
47
+
48
+ ```sh
49
+ m365 purview threatassessment add --type file --expectedAssessment block --category malware --fileName 'test.txt' --path 'C:\Path\To\File.txt'
50
+ ```
51
+
52
+ Create a url threat assessment
53
+
54
+ ```sh
55
+ m365 purview threatassessment add --type url --expectedAssessment block --category phishing --url 'http://contoso.com'
56
+ ```
57
+
58
+ ## Response
59
+
60
+ <Tabs>
61
+ <TabItem value="JSON">
62
+
63
+ ```json
64
+ {
65
+ "id": "b0e69f1c-adda-4df2-2906-08dc2caa6b3f",
66
+ "createdDateTime": "2024-02-13T15:42:43.5131654Z",
67
+ "contentType": "file",
68
+ "expectedAssessment": "block",
69
+ "category": "malware",
70
+ "status": "pending",
71
+ "requestSource": "administrator",
72
+ "fileName": "test.txt",
73
+ "contentData": "dGVzdC50eHQ=",
74
+ "createdBy": {
75
+ "user": {
76
+ "id": "fe36f75e-c103-410b-a18a-2bf6df06ac3a",
77
+ "displayName": "John Doe"
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ </TabItem>
84
+ <TabItem value="Text">
85
+
86
+ ```text
87
+ category : malware
88
+ contentData : dGVzdC50eHQ=
89
+ contentType : file
90
+ createdBy : {"user":{"id":"fe36f75e-c103-410b-a18a-2bf6df06ac3a","displayName":"John Doe"}}
91
+ createdDateTime : 2024-02-13T16:15:00.4125206Z
92
+ expectedAssessment: block
93
+ fileName : test.txt
94
+ id : be1223c4-4e92-4a4c-8c16-08dc2caeedba
95
+ requestSource : administrator
96
+ status : pending
97
+ ```
98
+
99
+ </TabItem>
100
+ <TabItem value="CSV">
101
+
102
+ ```csv
103
+ id,createdDateTime,contentType,expectedAssessment,category,status,requestSource,fileName,contentData
104
+ d31eb5f5-ecd5-4a8e-fb2a-08dc2caf00a8,2024-02-13T16:15:32.1741098Z,file,block,malware,pending,administrator,test.txt,dGVzdC50eHQ=
105
+ ```
106
+
107
+ </TabItem>
108
+ <TabItem value="Markdown">
109
+
110
+ ```md
111
+ # purview threatassessment add --type "file" --expectedAssessment "block" --category "malware" --path "C:\temp\test.txt"
112
+
113
+ Date: 13/02/2024
114
+
115
+ ## e3524baf-6ea6-4fab-68af-08dc2caf0ae3
116
+
117
+ Property | Value
118
+ ---------|-------
119
+ id | e3524baf-6ea6-4fab-68af-08dc2caf0ae3
120
+ createdDateTime | 2024-02-13T16:15:49.3342383Z
121
+ contentType | file
122
+ expectedAssessment | block
123
+ category | malware
124
+ status | pending
125
+ requestSource | administrator
126
+ fileName | test.txt
127
+ contentData | dGVzdC50eHQ=
128
+ ```
129
+
130
+ </TabItem>
131
+ </Tabs>
@@ -0,0 +1,110 @@
1
+ import Global from '/docs/cmd/_global.mdx';
2
+ import Tabs from '@theme/Tabs';
3
+ import TabItem from '@theme/TabItem';
4
+
5
+ # purview threatassessment list
6
+
7
+ Get a list of threat assessments
8
+
9
+ ## Usage
10
+
11
+ ```sh
12
+ m365 purview threatassessment list [options]
13
+ ```
14
+
15
+ ## Options
16
+
17
+ ```md definition-list
18
+ `-t, --type [type]`
19
+ : The type of threat assessment to retrieve. Allowed values are `mail`, `file`, `emailFile` and `url`.
20
+ ```
21
+
22
+ <Global />
23
+
24
+ ## Examples
25
+
26
+ Get a list of threat assessments
27
+
28
+ ```sh
29
+ m365 purview threatassessment list
30
+ ```
31
+
32
+ Get a list of threat assessments of type _mail_
33
+
34
+ ```sh
35
+ m365 purview threatassessment list --type mail
36
+ ```
37
+
38
+ ## Response
39
+
40
+ <Tabs>
41
+ <TabItem value="JSON">
42
+
43
+ ```json
44
+ [
45
+ {
46
+ "type": "mail",
47
+ "id": "49c5ef5b-1f65-444a-e6b9-08d772ea2059",
48
+ "createdDateTime": "2019-11-27T03:30:18.6890937Z",
49
+ "contentType": "mail",
50
+ "expectedAssessment": "block",
51
+ "category": "spam",
52
+ "status": "pending",
53
+ "requestSource": "administrator",
54
+ "recipientEmail": "john@contoso.onmicrosoft.com",
55
+ "destinationRoutingReason": "notJunk",
56
+ "messageUri": "https://graph.microsoft.com/v1.0/users/c52ce8db-3e4b-4181-93c4-7d6b6bffaf60/messages/AAMkADU3MWUxOTU0LWNlOTEt=",
57
+ "createdBy": {
58
+ "user": {
59
+ "id": "c52ce8db-3e4b-4181-93c4-7d6b6bffaf60",
60
+ "displayName": "John Doe"
61
+ }
62
+ }
63
+ }
64
+ ];
65
+ ```
66
+
67
+ </TabItem>
68
+ <TabItem value="Text">
69
+
70
+ ```text
71
+ id type category
72
+ ------------------------------------ ----------- --------
73
+ 49c5ef5b-1f65-444a-e6b9-08d772ea2059 mail spam
74
+ ```
75
+
76
+ </TabItem>
77
+ <TabItem value="CSV">
78
+
79
+ ```csv
80
+ id,type,category
81
+ 49c5ef5b-1f65-444a-e6b9-08d772ea2059,mail,spam
82
+ ```
83
+
84
+ </TabItem>
85
+ <TabItem value="Markdown">
86
+
87
+ ```md
88
+ # purview threatassessment list
89
+
90
+ Date: 16/2/2023
91
+
92
+ ## a47e428c-a7bd-4cf2-f061-08db0f58b736
93
+
94
+ Property | Value
95
+ ---------|-------
96
+ type | mail
97
+ id | 49c5ef5b-1f65-444a-e6b9-08d772ea2059
98
+ createdDateTime | 2019-11-27T03:30:18.6890937Z
99
+ contentType | mail
100
+ expectedAssessment | block
101
+ category | spam
102
+ status | pending
103
+ recipientEmail | john@contoso.onmicrosoft.com
104
+ destinationRoutingReason | notJunk
105
+ messageUri | https://graph.microsoft.com/v1.0/users/c52ce8db-3e4b-4181-93c4-7d6b6bffaf60/messages/AAMkADU3MWUxOTU0LWNlOTEt=
106
+ createdBy | {"user":{"id":"c52ce8db-3e4b-4181-93c4-7d6b6bffaf60","displayName":"John Doe"}}
107
+ ```
108
+
109
+ </TabItem>
110
+ </Tabs>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "7.6.0-beta.682272b",
3
+ "version": "7.6.0-beta.c74fe4b",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",