@pnp/cli-microsoft365 8.0.0 → 8.1.0-beta.309a9b8
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/allCommands.json +1 -1
- package/allCommandsFull.json +1 -1
- package/dist/Auth.js +9 -9
- package/dist/Command.js +50 -5
- package/dist/cli/cli.js +101 -39
- package/dist/m365/commands/login.js +49 -96
- package/dist/m365/connection/commands/connection-remove.js +6 -2
- package/dist/m365/connection/commands/connection-set.js +4 -1
- package/dist/m365/connection/commands/connection-use.js +25 -4
- package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-remove.js +123 -0
- package/dist/m365/entra/commands/group/group-set.js +256 -0
- package/dist/m365/entra/commands/m365group/m365group-user-add.js +109 -32
- package/dist/m365/entra/commands/m365group/m365group-user-set.js +159 -84
- package/dist/m365/entra/commands/multitenant/multitenant-add.js +65 -0
- package/dist/m365/entra/commands/multitenant/multitenant-remove.js +118 -0
- package/dist/m365/entra/commands/multitenant/multitenant-set.js +72 -0
- package/dist/m365/entra/commands.js +6 -0
- package/dist/m365/flow/commands/flow-get.js +1 -1
- package/dist/m365/onenote/commands/notebook/notebook-add.js +132 -0
- package/dist/m365/onenote/commands.js +1 -0
- package/dist/m365/pa/commands/app/app-export.js +13 -7
- package/dist/m365/spe/ContainerTypeProperties.js +2 -0
- package/dist/m365/spe/commands/containertype/containertype-list.js +49 -0
- package/dist/m365/spe/commands.js +2 -1
- package/dist/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.js +16 -21
- package/dist/m365/spo/commands/commandset/commandset-get.js +31 -17
- package/dist/m365/spo/commands/file/file-roleassignment-add.js +1 -1
- package/dist/m365/spo/commands/file/file-roleinheritance-break.js +1 -1
- package/dist/m365/spo/commands/file/file-roleinheritance-reset.js +1 -1
- package/dist/m365/spo/commands/folder/folder-retentionlabel-ensure.js +1 -1
- package/dist/m365/spo/commands/folder/folder-sharinglink-get.js +86 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-list.js +110 -0
- package/dist/m365/spo/commands/list/ListInstance.js +6 -1
- package/dist/m365/spo/commands/list/list-get.js +9 -3
- package/dist/m365/spo/commands/list/list-roleassignment-add.js +46 -21
- package/dist/m365/spo/commands/list/list-roleassignment-remove.js +48 -46
- package/dist/m365/spo/commands/site/site-get.js +12 -16
- package/dist/m365/spo/commands/tenant/tenant-applicationcustomizer-get.js +19 -5
- package/dist/m365/spo/commands/tenant/tenant-commandset-get.js +20 -6
- package/dist/m365/spo/commands.js +2 -0
- package/dist/m365/teams/commands/message/message-restore.js +106 -0
- package/dist/m365/teams/commands.js +1 -0
- package/dist/utils/drive.js +61 -0
- package/dist/utils/formatting.js +16 -0
- package/dist/utils/spo.js +69 -6
- package/dist/utils/zod.js +124 -0
- package/docs/docs/cmd/connection/connection-use.mdx +8 -2
- package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-remove.mdx +65 -0
- package/docs/docs/cmd/entra/group/group-add.mdx +0 -4
- package/docs/docs/cmd/entra/group/group-set.mdx +89 -0
- package/docs/docs/cmd/entra/m365group/m365group-user-add.mdx +28 -10
- package/docs/docs/cmd/entra/m365group/m365group-user-set.mdx +35 -11
- package/docs/docs/cmd/entra/multitenant/multitenant-add.mdx +107 -0
- package/docs/docs/cmd/entra/multitenant/multitenant-remove.mdx +58 -0
- package/docs/docs/cmd/entra/multitenant/multitenant-set.mdx +53 -0
- package/docs/docs/cmd/flow/flow-get.mdx +149 -283
- package/docs/docs/cmd/onenote/notebook/notebook-add.mdx +169 -0
- package/docs/docs/cmd/pa/app/app-export.mdx +15 -9
- package/docs/docs/cmd/planner/plan/plan-remove.mdx +1 -1
- package/docs/docs/cmd/spe/containertype/containertype-list.mdx +102 -0
- package/docs/docs/cmd/spo/app/app-uninstall.mdx +1 -1
- package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-get.mdx +87 -38
- package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-list.mdx +22 -28
- package/docs/docs/cmd/spo/commandset/commandset-get.mdx +75 -24
- package/docs/docs/cmd/spo/commandset/commandset-list.mdx +26 -32
- package/docs/docs/cmd/spo/file/file-retentionlabel-ensure.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleassignment-add.mdx +2 -2
- package/docs/docs/cmd/spo/file/file-roleassignment-remove.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleinheritance-break.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleinheritance-reset.mdx +1 -1
- package/docs/docs/cmd/spo/folder/folder-retentionlabel-ensure.mdx +2 -2
- package/docs/docs/cmd/spo/folder/folder-sharinglink-get.mdx +110 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-list.mdx +114 -0
- package/docs/docs/cmd/spo/list/list-get.mdx +6 -0
- package/docs/docs/cmd/spo/list/list-roleassignment-add.mdx +15 -3
- package/docs/docs/cmd/spo/list/list-roleassignment-remove.mdx +15 -3
- package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-ensure.mdx +4 -4
- package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-remove.mdx +1 -1
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-add.mdx +9 -9
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-remove.mdx +7 -7
- package/docs/docs/cmd/spo/site/site-recyclebinitem-list.mdx +1 -1
- package/docs/docs/cmd/spo/tenant/tenant-applicationcustomizer-get.mdx +79 -30
- package/docs/docs/cmd/spo/tenant/tenant-applicationcustomizer-list.mdx +20 -19
- package/docs/docs/cmd/spo/tenant/tenant-commandset-get.mdx +84 -38
- package/docs/docs/cmd/spo/tenant/tenant-commandset-list.mdx +20 -19
- package/docs/docs/cmd/spo/web/web-roleassignment-add.mdx +1 -1
- package/docs/docs/cmd/spo/web/web-roleassignment-remove.mdx +1 -1
- package/docs/docs/cmd/teams/meeting/meeting-list.mdx +7 -3
- package/docs/docs/cmd/teams/message/message-remove.mdx +2 -1
- package/docs/docs/cmd/teams/message/message-restore.mdx +62 -0
- package/npm-shrinkwrap.json +1003 -1148
- package/package.json +27 -24
package/dist/Auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AzureCloudInstance } from '@azure/msal-common';
|
|
2
|
+
import assert from 'assert';
|
|
2
3
|
import { CommandError } from './Command.js';
|
|
3
4
|
import { FileTokenStorage } from './auth/FileTokenStorage.js';
|
|
4
5
|
import { msalCachePlugin } from './auth/msalCachePlugin.js';
|
|
@@ -6,16 +7,15 @@ import { cli } from './cli/cli.js';
|
|
|
6
7
|
import config from './config.js';
|
|
7
8
|
import request from './request.js';
|
|
8
9
|
import { settingsNames } from './settingsNames.js';
|
|
9
|
-
import { browserUtil } from './utils/browserUtil.js';
|
|
10
10
|
import * as accessTokenUtil from './utils/accessToken.js';
|
|
11
|
-
import
|
|
11
|
+
import { browserUtil } from './utils/browserUtil.js';
|
|
12
12
|
export var CloudType;
|
|
13
13
|
(function (CloudType) {
|
|
14
|
-
CloudType[
|
|
15
|
-
CloudType[
|
|
16
|
-
CloudType[
|
|
17
|
-
CloudType[
|
|
18
|
-
CloudType[
|
|
14
|
+
CloudType["Public"] = "Public";
|
|
15
|
+
CloudType["USGov"] = "USGov";
|
|
16
|
+
CloudType["USGovHigh"] = "USGovHigh";
|
|
17
|
+
CloudType["USGovDoD"] = "USGovDoD";
|
|
18
|
+
CloudType["China"] = "China";
|
|
19
19
|
})(CloudType || (CloudType = {}));
|
|
20
20
|
export class Connection {
|
|
21
21
|
constructor() {
|
|
@@ -691,7 +691,7 @@ export class Auth {
|
|
|
691
691
|
const allConnections = await this.getAllConnections();
|
|
692
692
|
const connection = allConnections.find(i => i.name === name);
|
|
693
693
|
if (!connection) {
|
|
694
|
-
throw new CommandError(`The connection '${name}' cannot be found
|
|
694
|
+
throw new CommandError(`The connection '${name}' cannot be found.`);
|
|
695
695
|
}
|
|
696
696
|
return connection;
|
|
697
697
|
}
|
|
@@ -710,7 +710,7 @@ export class Auth {
|
|
|
710
710
|
return details;
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
|
-
Auth.cloudEndpoints =
|
|
713
|
+
Auth.cloudEndpoints = {};
|
|
714
714
|
Auth.initialize();
|
|
715
715
|
export default new Auth();
|
|
716
716
|
//# sourceMappingURL=Auth.js.map
|
package/dist/Command.js
CHANGED
|
@@ -5,6 +5,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _Command_instances, _Command_initTelemetry, _Command_initOptions, _Command_initValidators;
|
|
7
7
|
import os from 'os';
|
|
8
|
+
import { z } from 'zod';
|
|
8
9
|
import auth from './Auth.js';
|
|
9
10
|
import { cli } from './cli/cli.js';
|
|
10
11
|
import request from './request.js';
|
|
@@ -13,6 +14,7 @@ import { telemetry } from './telemetry.js';
|
|
|
13
14
|
import { accessToken } from './utils/accessToken.js';
|
|
14
15
|
import { md } from './utils/md.js';
|
|
15
16
|
import { prompt } from './utils/prompt.js';
|
|
17
|
+
import { zod } from './utils/zod.js';
|
|
16
18
|
export class CommandError {
|
|
17
19
|
constructor(message, code) {
|
|
18
20
|
this.message = message;
|
|
@@ -25,10 +27,26 @@ export class CommandErrorWithOutput {
|
|
|
25
27
|
this.stderr = stderr;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
export const globalOptionsZod = z.object({
|
|
31
|
+
query: z.string().optional(),
|
|
32
|
+
output: zod.alias('o', z.enum(['csv', 'json', 'md', 'text', 'none']).optional()),
|
|
33
|
+
debug: z.boolean().default(false),
|
|
34
|
+
verbose: z.boolean().default(false)
|
|
35
|
+
});
|
|
28
36
|
class Command {
|
|
29
37
|
get allowedOutputs() {
|
|
30
38
|
return ['csv', 'json', 'md', 'text', 'none'];
|
|
31
39
|
}
|
|
40
|
+
get schema() {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
|
+
getRefinedSchema(schema) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
getSchemaToParse() {
|
|
48
|
+
return this.getRefinedSchema(this.schema) ?? this.schema;
|
|
49
|
+
}
|
|
32
50
|
constructor() {
|
|
33
51
|
// These functions must be defined with # so that they're truly private
|
|
34
52
|
// otherwise you'll get a ts2415 error (Types have separate declarations of
|
|
@@ -48,6 +66,9 @@ class Command {
|
|
|
48
66
|
string: []
|
|
49
67
|
};
|
|
50
68
|
this.validators = [];
|
|
69
|
+
// metadata for command's options
|
|
70
|
+
// used for building telemetry
|
|
71
|
+
this.optionsInfo = [];
|
|
51
72
|
__classPrivateFieldGet(this, _Command_instances, "m", _Command_initTelemetry).call(this);
|
|
52
73
|
__classPrivateFieldGet(this, _Command_instances, "m", _Command_initOptions).call(this);
|
|
53
74
|
__classPrivateFieldGet(this, _Command_instances, "m", _Command_initValidators).call(this);
|
|
@@ -90,9 +111,7 @@ class Command {
|
|
|
90
111
|
prompted = true;
|
|
91
112
|
await cli.error('🌶️ Provide values for the following parameters:');
|
|
92
113
|
}
|
|
93
|
-
const answer = optionInfo
|
|
94
|
-
? await prompt.forSelection({ message: `${optionInfo.name}: `, choices: optionInfo.autocomplete.map((choice) => { return { name: choice, value: choice }; }) })
|
|
95
|
-
: await prompt.forInput({ message: `${optionInfo.name}: ` });
|
|
114
|
+
const answer = await cli.promptForValue(optionInfo);
|
|
96
115
|
args.options[optionInfo.name] = answer;
|
|
97
116
|
}
|
|
98
117
|
if (prompted) {
|
|
@@ -410,8 +429,34 @@ class Command {
|
|
|
410
429
|
return '';
|
|
411
430
|
}
|
|
412
431
|
getTelemetryProperties(args) {
|
|
413
|
-
this.
|
|
414
|
-
|
|
432
|
+
if (this.schema) {
|
|
433
|
+
const telemetryProperties = {};
|
|
434
|
+
this.optionsInfo.forEach(o => {
|
|
435
|
+
if (o.required) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (typeof args.options[o.name] === 'undefined') {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
switch (o.type) {
|
|
442
|
+
case 'string':
|
|
443
|
+
telemetryProperties[o.name] = o.autocomplete ? args.options[o.name] : typeof args.options[o.name] !== 'undefined';
|
|
444
|
+
break;
|
|
445
|
+
case 'boolean':
|
|
446
|
+
telemetryProperties[o.name] = args.options[o.name];
|
|
447
|
+
break;
|
|
448
|
+
case 'number':
|
|
449
|
+
telemetryProperties[o.name] = typeof args.options[o.name] !== 'undefined';
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
;
|
|
453
|
+
});
|
|
454
|
+
return telemetryProperties;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
this.telemetry.forEach(t => t(args));
|
|
458
|
+
return this.telemetryProperties;
|
|
459
|
+
}
|
|
415
460
|
}
|
|
416
461
|
async getTextOutput(logStatement) {
|
|
417
462
|
// display object as a list of key-value pairs
|
package/dist/cli/cli.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import Configstore from 'configstore';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import minimist from 'minimist';
|
|
4
3
|
import { createRequire } from 'module';
|
|
5
4
|
import os from 'os';
|
|
6
5
|
import path from 'path';
|
|
7
6
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
7
|
+
import yargs from 'yargs-parser';
|
|
8
|
+
import { ZodError } from 'zod';
|
|
8
9
|
import Command, { CommandError } from '../Command.js';
|
|
9
10
|
import config from '../config.js';
|
|
10
11
|
import request from '../request.js';
|
|
11
12
|
import { settingsNames } from '../settingsNames.js';
|
|
12
13
|
import { telemetry } from '../telemetry.js';
|
|
13
14
|
import { app } from '../utils/app.js';
|
|
15
|
+
import { browserUtil } from '../utils/browserUtil.js';
|
|
14
16
|
import { formatting } from '../utils/formatting.js';
|
|
15
17
|
import { md } from '../utils/md.js';
|
|
16
|
-
import { validation } from '../utils/validation.js';
|
|
17
18
|
import { prompt } from '../utils/prompt.js';
|
|
19
|
+
import { validation } from '../utils/validation.js';
|
|
20
|
+
import { zod } from '../utils/zod.js';
|
|
18
21
|
import { timings } from './timings.js';
|
|
19
|
-
import { browserUtil } from '../utils/browserUtil.js';
|
|
20
22
|
const require = createRequire(import.meta.url);
|
|
21
23
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
22
24
|
let _config;
|
|
@@ -34,6 +36,14 @@ const defaultHelpMode = 'options';
|
|
|
34
36
|
const defaultHelpTarget = 'console';
|
|
35
37
|
const helpModes = ['options', 'examples', 'remarks', 'response', 'full'];
|
|
36
38
|
const helpTargets = ['console', 'web'];
|
|
39
|
+
const yargsConfiguration = {
|
|
40
|
+
'parse-numbers': true,
|
|
41
|
+
'strip-aliased': true,
|
|
42
|
+
'strip-dashed': true,
|
|
43
|
+
'dot-notation': false,
|
|
44
|
+
'boolean-negation': true,
|
|
45
|
+
'camel-case-expansion': false
|
|
46
|
+
};
|
|
37
47
|
function getConfig() {
|
|
38
48
|
if (!_config) {
|
|
39
49
|
_config = new Configstore(config.configstoreName);
|
|
@@ -64,7 +74,7 @@ async function execute(rawArgs) {
|
|
|
64
74
|
rawArgs.shift();
|
|
65
75
|
}
|
|
66
76
|
// parse args to see if a command has been specified
|
|
67
|
-
const parsedArgs =
|
|
77
|
+
const parsedArgs = yargs(rawArgs);
|
|
68
78
|
// load command
|
|
69
79
|
await cli.loadCommandFromArgs(parsedArgs._);
|
|
70
80
|
if (cli.commandToExecute) {
|
|
@@ -77,8 +87,7 @@ async function execute(rawArgs) {
|
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
catch (e) {
|
|
80
|
-
|
|
81
|
-
return cli.closeWithError(e.message, optionsWithoutShorts, false);
|
|
90
|
+
return cli.closeWithError(e.message, { options: parsedArgs }, false);
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
else {
|
|
@@ -126,18 +135,54 @@ async function execute(rawArgs) {
|
|
|
126
135
|
if (cli.optionsFromArgs.options.output === undefined) {
|
|
127
136
|
cli.optionsFromArgs.options.output = cli.getSettingWithDefaultValue(settingsNames.output, 'json');
|
|
128
137
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
let finalArgs = cli.optionsFromArgs.options;
|
|
139
|
+
if (cli.commandToExecute?.command.schema) {
|
|
140
|
+
while (true) {
|
|
141
|
+
const startValidation = process.hrtime.bigint();
|
|
142
|
+
const result = cli.commandToExecute.command.getSchemaToParse().safeParse(cli.optionsFromArgs.options);
|
|
143
|
+
const endValidation = process.hrtime.bigint();
|
|
144
|
+
timings.validation.push(Number(endValidation - startValidation));
|
|
145
|
+
if (result.success) {
|
|
146
|
+
finalArgs = result.data;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const hasNonRequiredErrors = result.error.errors.some(e => e.code !== 'invalid_type' || e.received !== 'undefined');
|
|
151
|
+
const shouldPrompt = cli.getSettingWithDefaultValue(settingsNames.prompt, true);
|
|
152
|
+
if (hasNonRequiredErrors === false &&
|
|
153
|
+
shouldPrompt) {
|
|
154
|
+
await cli.error('🌶️ Provide values for the following parameters:');
|
|
155
|
+
for (const error of result.error.errors) {
|
|
156
|
+
const optionInfo = cli.commandToExecute.options.find(o => o.name === error.path.join('.'));
|
|
157
|
+
const answer = await cli.promptForValue(optionInfo);
|
|
158
|
+
cli.optionsFromArgs.options[error.path.join('.')] = answer;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
result.error.errors.forEach(e => {
|
|
163
|
+
if (e.code === 'invalid_type' &&
|
|
164
|
+
e.received === 'undefined') {
|
|
165
|
+
e.message = `Required option not specified`;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return cli.closeWithError(result.error, cli.optionsFromArgs, true);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const startValidation = process.hrtime.bigint();
|
|
175
|
+
const validationResult = await cli.commandToExecute.command.validate(cli.optionsFromArgs, cli.commandToExecute);
|
|
176
|
+
const endValidation = process.hrtime.bigint();
|
|
177
|
+
timings.validation.push(Number(endValidation - startValidation));
|
|
178
|
+
if (validationResult !== true) {
|
|
179
|
+
return cli.closeWithError(validationResult, cli.optionsFromArgs, true);
|
|
180
|
+
}
|
|
135
181
|
}
|
|
136
|
-
cli.optionsFromArgs = removeShortOptions(cli.optionsFromArgs);
|
|
137
182
|
const end = process.hrtime.bigint();
|
|
138
183
|
timings.core.push(Number(end - start));
|
|
139
184
|
try {
|
|
140
|
-
await cli.executeCommand(cli.commandToExecute.command,
|
|
185
|
+
await cli.executeCommand(cli.commandToExecute.command, { options: finalArgs });
|
|
141
186
|
const endTotal = process.hrtime.bigint();
|
|
142
187
|
timings.total.push(Number(endTotal - start));
|
|
143
188
|
await printTimings(rawArgs);
|
|
@@ -347,12 +392,14 @@ async function loadCommandFromFile(commandFileUrl) {
|
|
|
347
392
|
catch { }
|
|
348
393
|
}
|
|
349
394
|
function getCommandInfo(command, filePath = '', helpFilePath = '') {
|
|
395
|
+
const options = command.schema ? zod.schemaToOptions(command.schema) : getCommandOptions(command);
|
|
396
|
+
command.optionsInfo = options;
|
|
350
397
|
return {
|
|
351
398
|
aliases: command.alias(),
|
|
352
399
|
name: command.name,
|
|
353
400
|
description: command.description,
|
|
354
401
|
command: command,
|
|
355
|
-
options
|
|
402
|
+
options,
|
|
356
403
|
defaultProperties: command.defaultProperties(),
|
|
357
404
|
file: filePath,
|
|
358
405
|
help: helpFilePath
|
|
@@ -387,36 +434,43 @@ function getCommandOptions(command) {
|
|
|
387
434
|
return options;
|
|
388
435
|
}
|
|
389
436
|
function getCommandOptionsFromArgs(args, commandInfo) {
|
|
390
|
-
const
|
|
391
|
-
alias: {}
|
|
437
|
+
const yargsOptions = {
|
|
438
|
+
alias: {},
|
|
439
|
+
configuration: yargsConfiguration
|
|
392
440
|
};
|
|
393
441
|
let argsToParse = args;
|
|
394
442
|
if (commandInfo) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
443
|
+
if (commandInfo.command.schema) {
|
|
444
|
+
yargsOptions.string = commandInfo.options.filter(o => o.type === 'string').map(o => o.name);
|
|
445
|
+
yargsOptions.boolean = commandInfo.options.filter(o => o.type === 'boolean').map(o => o.name);
|
|
446
|
+
yargsOptions.number = commandInfo.options.filter(o => o.type === 'number').map(o => o.name);
|
|
447
|
+
argsToParse = getRewrittenArgs(args, yargsOptions.boolean);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
const commandTypes = commandInfo.command.types;
|
|
451
|
+
if (commandTypes) {
|
|
452
|
+
yargsOptions.string = commandTypes.string;
|
|
453
|
+
// minimist will parse unused boolean options to 'false' (unused options => options that are not included in the args)
|
|
454
|
+
// But in the CLI booleans are nullable. They can can be true, false or undefined.
|
|
455
|
+
// For this reason we only pass boolean types that are actually used as arg.
|
|
456
|
+
yargsOptions.boolean = commandTypes.boolean.filter(optionName => args.some(arg => `--${optionName}` === arg || `-${optionName}` === arg));
|
|
457
|
+
}
|
|
458
|
+
argsToParse = getRewrittenArgs(args, commandTypes.boolean);
|
|
459
|
+
}
|
|
404
460
|
commandInfo.options.forEach(option => {
|
|
405
461
|
if (option.short && option.long) {
|
|
406
|
-
|
|
462
|
+
yargsOptions.alias[option.long] = option.short;
|
|
407
463
|
}
|
|
408
464
|
});
|
|
409
|
-
argsToParse = getRewrittenArgs(args, commandTypes);
|
|
410
465
|
}
|
|
411
|
-
return
|
|
466
|
+
return yargs(argsToParse, yargsOptions);
|
|
412
467
|
}
|
|
413
468
|
/**
|
|
414
469
|
* Rewrites arguments (if necessary) before passing them into minimist.
|
|
415
470
|
* Currently only boolean values are checked and fixed.
|
|
416
471
|
* Args are only checked and rewritten if the option has been added to the 'types.boolean' array.
|
|
417
472
|
*/
|
|
418
|
-
function getRewrittenArgs(args,
|
|
419
|
-
const booleanTypes = commandTypes.boolean;
|
|
473
|
+
function getRewrittenArgs(args, booleanTypes) {
|
|
420
474
|
if (booleanTypes.length === 0) {
|
|
421
475
|
return args;
|
|
422
476
|
}
|
|
@@ -722,6 +776,9 @@ async function closeWithError(error, args, showHelpIfEnabled = false) {
|
|
|
722
776
|
return process.exit(exitCode);
|
|
723
777
|
}
|
|
724
778
|
let errorMessage = error instanceof CommandError ? error.message : error;
|
|
779
|
+
if (error instanceof ZodError) {
|
|
780
|
+
errorMessage = error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(os.EOL);
|
|
781
|
+
}
|
|
725
782
|
if ((!args.options.output || args.options.output === 'json') &&
|
|
726
783
|
!cli.getSettingWithDefaultValue(settingsNames.printErrorsAsPlainText, true)) {
|
|
727
784
|
errorMessage = JSON.stringify({ error: errorMessage });
|
|
@@ -760,6 +817,16 @@ async function error(message, ...optionalParams) {
|
|
|
760
817
|
console.error(message, ...optionalParams);
|
|
761
818
|
}
|
|
762
819
|
}
|
|
820
|
+
async function promptForValue(optionInfo) {
|
|
821
|
+
return optionInfo.autocomplete !== undefined
|
|
822
|
+
? await prompt.forSelection({
|
|
823
|
+
message: `${optionInfo.name}: `,
|
|
824
|
+
choices: optionInfo.autocomplete.map((choice) => {
|
|
825
|
+
return { name: choice, value: choice };
|
|
826
|
+
})
|
|
827
|
+
})
|
|
828
|
+
: await prompt.forInput({ message: `${optionInfo.name}: ` });
|
|
829
|
+
}
|
|
763
830
|
async function promptForSelection(config) {
|
|
764
831
|
const answer = await prompt.forSelection(config);
|
|
765
832
|
await cli.error('');
|
|
@@ -780,13 +847,6 @@ async function handleMultipleResultsFound(message, values) {
|
|
|
780
847
|
const response = await cli.promptForSelection({ message: `Please choose one:`, choices });
|
|
781
848
|
return values[response];
|
|
782
849
|
}
|
|
783
|
-
function removeShortOptions(args) {
|
|
784
|
-
const filteredArgs = JSON.parse(JSON.stringify(args));
|
|
785
|
-
const optionsToRemove = Object.getOwnPropertyNames(args.options)
|
|
786
|
-
.filter(option => option.length === 1 || option === '--');
|
|
787
|
-
optionsToRemove.forEach(option => delete filteredArgs.options[option]);
|
|
788
|
-
return filteredArgs;
|
|
789
|
-
}
|
|
790
850
|
function loadOptionValuesFromFiles(args) {
|
|
791
851
|
const optionNames = Object.getOwnPropertyNames(args.options);
|
|
792
852
|
optionNames.forEach(option => {
|
|
@@ -831,6 +891,8 @@ export const cli = {
|
|
|
831
891
|
printAvailableCommands,
|
|
832
892
|
promptForConfirmation,
|
|
833
893
|
promptForSelection,
|
|
834
|
-
|
|
894
|
+
promptForValue,
|
|
895
|
+
shouldTrimOutput,
|
|
896
|
+
yargsConfiguration
|
|
835
897
|
};
|
|
836
898
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1,17 +1,30 @@
|
|
|
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 _LoginCommand_instances, _a, _LoginCommand_initTelemetry, _LoginCommand_initOptions, _LoginCommand_initValidators;
|
|
7
1
|
import fs from 'fs';
|
|
2
|
+
import { z } from 'zod';
|
|
8
3
|
import auth, { AuthType, CloudType } from '../../Auth.js';
|
|
9
|
-
import Command, { CommandError } from '../../Command.js';
|
|
4
|
+
import Command, { CommandError, globalOptionsZod } from '../../Command.js';
|
|
5
|
+
import { cli } from '../../cli/cli.js';
|
|
10
6
|
import config from '../../config.js';
|
|
11
|
-
import { misc } from '../../utils/misc.js';
|
|
12
|
-
import commands from './commands.js';
|
|
13
7
|
import { settingsNames } from '../../settingsNames.js';
|
|
14
|
-
import {
|
|
8
|
+
import { zod } from '../../utils/zod.js';
|
|
9
|
+
import commands from './commands.js';
|
|
10
|
+
const options = globalOptionsZod
|
|
11
|
+
.extend({
|
|
12
|
+
authType: zod.alias('t', z.enum(['certificate', 'deviceCode', 'password', 'identity', 'browser', 'secret']).optional()),
|
|
13
|
+
cloud: z.nativeEnum(CloudType).optional().default(CloudType.Public),
|
|
14
|
+
userName: zod.alias('u', z.string().optional()),
|
|
15
|
+
password: zod.alias('p', z.string().optional()),
|
|
16
|
+
certificateFile: zod.alias('c', z.string().optional()
|
|
17
|
+
.refine(filePath => !filePath || fs.existsSync(filePath), filePath => ({
|
|
18
|
+
message: `Certificate file ${filePath} does not exist`
|
|
19
|
+
}))),
|
|
20
|
+
certificateBase64Encoded: z.string().optional(),
|
|
21
|
+
thumbprint: z.string().optional(),
|
|
22
|
+
appId: z.string().optional(),
|
|
23
|
+
tenant: z.string().optional(),
|
|
24
|
+
secret: zod.alias('s', z.string().optional()),
|
|
25
|
+
connectionName: z.string().optional()
|
|
26
|
+
})
|
|
27
|
+
.strict();
|
|
15
28
|
class LoginCommand extends Command {
|
|
16
29
|
get name() {
|
|
17
30
|
return commands.LOGIN;
|
|
@@ -19,12 +32,31 @@ class LoginCommand extends Command {
|
|
|
19
32
|
get description() {
|
|
20
33
|
return 'Log in to Microsoft 365';
|
|
21
34
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
get schema() {
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
getRefinedSchema(schema) {
|
|
39
|
+
return schema
|
|
40
|
+
.refine(options => options.authType !== 'password' || options.userName, {
|
|
41
|
+
message: 'Username is required when using password authentication',
|
|
42
|
+
path: ['userName']
|
|
43
|
+
})
|
|
44
|
+
.refine(options => options.authType !== 'password' || options.password, {
|
|
45
|
+
message: 'Password is required when using password authentication',
|
|
46
|
+
path: ['password']
|
|
47
|
+
})
|
|
48
|
+
.refine(options => options.authType !== 'certificate' || !(options.certificateFile && options.certificateBase64Encoded), {
|
|
49
|
+
message: 'Specify either certificateFile or certificateBase64Encoded, but not both.',
|
|
50
|
+
path: ['certificateBase64Encoded']
|
|
51
|
+
})
|
|
52
|
+
.refine(options => options.authType !== 'certificate' || options.certificateFile || options.certificateBase64Encoded, {
|
|
53
|
+
message: 'Specify either certificateFile or certificateBase64Encoded',
|
|
54
|
+
path: ['certificateFile']
|
|
55
|
+
})
|
|
56
|
+
.refine(options => options.authType !== 'secret' || options.secret, {
|
|
57
|
+
message: 'Secret is required when using secret authentication',
|
|
58
|
+
path: ['secret']
|
|
59
|
+
});
|
|
28
60
|
}
|
|
29
61
|
async commandAction(logger, args) {
|
|
30
62
|
// disconnect before re-connecting
|
|
@@ -64,12 +96,7 @@ class LoginCommand extends Command {
|
|
|
64
96
|
auth.connection.secret = args.options.secret;
|
|
65
97
|
break;
|
|
66
98
|
}
|
|
67
|
-
|
|
68
|
-
auth.connection.cloudType = CloudType[args.options.cloud];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
auth.connection.cloudType = CloudType.Public;
|
|
72
|
-
}
|
|
99
|
+
auth.connection.cloudType = args.options.cloud;
|
|
73
100
|
try {
|
|
74
101
|
await auth.ensureAccessToken(auth.defaultResource, logger, this.debug);
|
|
75
102
|
auth.connection.active = true;
|
|
@@ -102,79 +129,5 @@ class LoginCommand extends Command {
|
|
|
102
129
|
await this.commandAction(logger, args);
|
|
103
130
|
}
|
|
104
131
|
}
|
|
105
|
-
_a = LoginCommand, _LoginCommand_instances = new WeakSet(), _LoginCommand_initTelemetry = function _LoginCommand_initTelemetry() {
|
|
106
|
-
this.telemetry.push((args) => {
|
|
107
|
-
Object.assign(this.telemetryProperties, {
|
|
108
|
-
authType: args.options.authType || cli.getSettingWithDefaultValue(settingsNames.authType, 'deviceCode'),
|
|
109
|
-
cloud: args.options.cloud ?? CloudType.Public
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}, _LoginCommand_initOptions = function _LoginCommand_initOptions() {
|
|
113
|
-
this.options.unshift({
|
|
114
|
-
option: '-t, --authType [authType]',
|
|
115
|
-
autocomplete: _a.allowedAuthTypes
|
|
116
|
-
}, {
|
|
117
|
-
option: '-u, --userName [userName]'
|
|
118
|
-
}, {
|
|
119
|
-
option: '-p, --password [password]'
|
|
120
|
-
}, {
|
|
121
|
-
option: '-c, --certificateFile [certificateFile]'
|
|
122
|
-
}, {
|
|
123
|
-
option: '--certificateBase64Encoded [certificateBase64Encoded]'
|
|
124
|
-
}, {
|
|
125
|
-
option: '--thumbprint [thumbprint]'
|
|
126
|
-
}, {
|
|
127
|
-
option: '--appId [appId]'
|
|
128
|
-
}, {
|
|
129
|
-
option: '--tenant [tenant]'
|
|
130
|
-
}, {
|
|
131
|
-
option: '-s, --secret [secret]'
|
|
132
|
-
}, {
|
|
133
|
-
option: '--cloud [cloud]',
|
|
134
|
-
autocomplete: misc.getEnums(CloudType)
|
|
135
|
-
}, {
|
|
136
|
-
option: '--connectionName [connectionName]'
|
|
137
|
-
});
|
|
138
|
-
}, _LoginCommand_initValidators = function _LoginCommand_initValidators() {
|
|
139
|
-
this.validators.push(async (args) => {
|
|
140
|
-
const authType = args.options.authType || cli.getSettingWithDefaultValue(settingsNames.authType, 'deviceCode');
|
|
141
|
-
if (authType === 'password') {
|
|
142
|
-
if (!args.options.userName) {
|
|
143
|
-
return 'Required option userName missing';
|
|
144
|
-
}
|
|
145
|
-
if (!args.options.password) {
|
|
146
|
-
return 'Required option password missing';
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (authType === 'certificate') {
|
|
150
|
-
if (args.options.certificateFile && args.options.certificateBase64Encoded) {
|
|
151
|
-
return 'Specify either certificateFile or certificateBase64Encoded, but not both.';
|
|
152
|
-
}
|
|
153
|
-
if (!args.options.certificateFile && !args.options.certificateBase64Encoded) {
|
|
154
|
-
return 'Specify either certificateFile or certificateBase64Encoded';
|
|
155
|
-
}
|
|
156
|
-
if (args.options.certificateFile) {
|
|
157
|
-
if (!fs.existsSync(args.options.certificateFile)) {
|
|
158
|
-
return `File '${args.options.certificateFile}' does not exist`;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (authType &&
|
|
163
|
-
_a.allowedAuthTypes.indexOf(authType) < 0) {
|
|
164
|
-
return `'${authType}' is not a valid authentication type. Allowed authentication types are ${_a.allowedAuthTypes.join(', ')}`;
|
|
165
|
-
}
|
|
166
|
-
if (authType === 'secret') {
|
|
167
|
-
if (!args.options.secret) {
|
|
168
|
-
return 'Required option secret missing';
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (args.options.cloud &&
|
|
172
|
-
typeof CloudType[args.options.cloud] === 'undefined') {
|
|
173
|
-
return `${args.options.cloud} is not a valid value for cloud. Valid options are ${misc.getEnums(CloudType).join(', ')}`;
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
LoginCommand.allowedAuthTypes = ['certificate', 'deviceCode', 'password', 'identity', 'browser', 'secret'];
|
|
179
132
|
export default new LoginCommand();
|
|
180
133
|
//# sourceMappingURL=login.js.map
|
|
@@ -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 _ConnectionRemoveCommand_instances, _ConnectionRemoveCommand_initTelemetry, _ConnectionRemoveCommand_initOptions;
|
|
6
|
+
var _ConnectionRemoveCommand_instances, _ConnectionRemoveCommand_initTelemetry, _ConnectionRemoveCommand_initOptions, _ConnectionRemoveCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
@@ -20,6 +20,7 @@ class ConnectionRemoveCommand extends Command {
|
|
|
20
20
|
_ConnectionRemoveCommand_instances.add(this);
|
|
21
21
|
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initTelemetry).call(this);
|
|
22
22
|
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initOptions).call(this);
|
|
23
|
+
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initTypes).call(this);
|
|
23
24
|
}
|
|
24
25
|
async commandAction(logger, args) {
|
|
25
26
|
const deleteConnection = async () => {
|
|
@@ -53,7 +54,7 @@ class ConnectionRemoveCommand extends Command {
|
|
|
53
54
|
_ConnectionRemoveCommand_instances = new WeakSet(), _ConnectionRemoveCommand_initTelemetry = function _ConnectionRemoveCommand_initTelemetry() {
|
|
54
55
|
this.telemetry.push((args) => {
|
|
55
56
|
Object.assign(this.telemetryProperties, {
|
|
56
|
-
force:
|
|
57
|
+
force: !!args.options.force
|
|
57
58
|
});
|
|
58
59
|
});
|
|
59
60
|
}, _ConnectionRemoveCommand_initOptions = function _ConnectionRemoveCommand_initOptions() {
|
|
@@ -62,6 +63,9 @@ _ConnectionRemoveCommand_instances = new WeakSet(), _ConnectionRemoveCommand_ini
|
|
|
62
63
|
}, {
|
|
63
64
|
option: '-f, --force'
|
|
64
65
|
});
|
|
66
|
+
}, _ConnectionRemoveCommand_initTypes = function _ConnectionRemoveCommand_initTypes() {
|
|
67
|
+
this.types.string.push('name');
|
|
68
|
+
this.types.boolean.push('force');
|
|
65
69
|
};
|
|
66
70
|
export default new ConnectionRemoveCommand();
|
|
67
71
|
//# sourceMappingURL=connection-remove.js.map
|
|
@@ -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 _ConnectionSetCommand_instances, _ConnectionSetCommand_initOptions, _ConnectionSetCommand_initValidators;
|
|
6
|
+
var _ConnectionSetCommand_instances, _ConnectionSetCommand_initOptions, _ConnectionSetCommand_initValidators, _ConnectionSetCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
@@ -19,6 +19,7 @@ class ConnectionSetCommand extends Command {
|
|
|
19
19
|
_ConnectionSetCommand_instances.add(this);
|
|
20
20
|
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initOptions).call(this);
|
|
21
21
|
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initValidators).call(this);
|
|
22
|
+
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initTypes).call(this);
|
|
22
23
|
}
|
|
23
24
|
async commandAction(logger, args) {
|
|
24
25
|
const connection = await auth.getConnection(args.options.name);
|
|
@@ -51,6 +52,8 @@ _ConnectionSetCommand_instances = new WeakSet(), _ConnectionSetCommand_initOptio
|
|
|
51
52
|
}
|
|
52
53
|
return true;
|
|
53
54
|
});
|
|
55
|
+
}, _ConnectionSetCommand_initTypes = function _ConnectionSetCommand_initTypes() {
|
|
56
|
+
this.types.string.push('name', 'newName');
|
|
54
57
|
};
|
|
55
58
|
export default new ConnectionSetCommand();
|
|
56
59
|
//# sourceMappingURL=connection-set.js.map
|