@pnp/cli-microsoft365 8.0.0 → 8.1.0-beta.32d2e69
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 +49 -2
- package/dist/cli/cli.js +60 -38
- package/dist/m365/commands/login.js +44 -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/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 +3 -0
- package/dist/m365/flow/commands/flow-get.js +1 -1
- 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/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/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/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/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/npm-shrinkwrap.json +1003 -1147
- package/package.json +27 -23
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);
|
|
@@ -410,8 +431,34 @@ class Command {
|
|
|
410
431
|
return '';
|
|
411
432
|
}
|
|
412
433
|
getTelemetryProperties(args) {
|
|
413
|
-
this.
|
|
414
|
-
|
|
434
|
+
if (this.schema) {
|
|
435
|
+
const telemetryProperties = {};
|
|
436
|
+
this.optionsInfo.forEach(o => {
|
|
437
|
+
if (o.required) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (typeof args.options[o.name] === 'undefined') {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
switch (o.type) {
|
|
444
|
+
case 'string':
|
|
445
|
+
telemetryProperties[o.name] = o.autocomplete ? args.options[o.name] : typeof args.options[o.name] !== 'undefined';
|
|
446
|
+
break;
|
|
447
|
+
case 'boolean':
|
|
448
|
+
telemetryProperties[o.name] = args.options[o.name];
|
|
449
|
+
break;
|
|
450
|
+
case 'number':
|
|
451
|
+
telemetryProperties[o.name] = typeof args.options[o.name] !== 'undefined';
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
;
|
|
455
|
+
});
|
|
456
|
+
return telemetryProperties;
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
this.telemetry.forEach(t => t(args));
|
|
460
|
+
return this.telemetryProperties;
|
|
461
|
+
}
|
|
415
462
|
}
|
|
416
463
|
async getTextOutput(logStatement) {
|
|
417
464
|
// 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;
|
|
@@ -64,7 +66,7 @@ async function execute(rawArgs) {
|
|
|
64
66
|
rawArgs.shift();
|
|
65
67
|
}
|
|
66
68
|
// parse args to see if a command has been specified
|
|
67
|
-
const parsedArgs =
|
|
69
|
+
const parsedArgs = yargs(rawArgs);
|
|
68
70
|
// load command
|
|
69
71
|
await cli.loadCommandFromArgs(parsedArgs._);
|
|
70
72
|
if (cli.commandToExecute) {
|
|
@@ -77,8 +79,7 @@ async function execute(rawArgs) {
|
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
catch (e) {
|
|
80
|
-
|
|
81
|
-
return cli.closeWithError(e.message, optionsWithoutShorts, false);
|
|
82
|
+
return cli.closeWithError(e.message, { options: parsedArgs }, false);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
@@ -126,18 +127,30 @@ async function execute(rawArgs) {
|
|
|
126
127
|
if (cli.optionsFromArgs.options.output === undefined) {
|
|
127
128
|
cli.optionsFromArgs.options.output = cli.getSettingWithDefaultValue(settingsNames.output, 'json');
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
let finalArgs = cli.optionsFromArgs.options;
|
|
131
|
+
if (cli.commandToExecute?.command.schema) {
|
|
132
|
+
const startValidation = process.hrtime.bigint();
|
|
133
|
+
const result = cli.commandToExecute.command.getSchemaToParse().safeParse(cli.optionsFromArgs.options);
|
|
134
|
+
const endValidation = process.hrtime.bigint();
|
|
135
|
+
timings.validation.push(Number(endValidation - startValidation));
|
|
136
|
+
if (!result.success) {
|
|
137
|
+
return cli.closeWithError(result.error, cli.optionsFromArgs, true);
|
|
138
|
+
}
|
|
139
|
+
finalArgs = result.data;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const startValidation = process.hrtime.bigint();
|
|
143
|
+
const validationResult = await cli.commandToExecute.command.validate(cli.optionsFromArgs, cli.commandToExecute);
|
|
144
|
+
const endValidation = process.hrtime.bigint();
|
|
145
|
+
timings.validation.push(Number(endValidation - startValidation));
|
|
146
|
+
if (validationResult !== true) {
|
|
147
|
+
return cli.closeWithError(validationResult, cli.optionsFromArgs, true);
|
|
148
|
+
}
|
|
135
149
|
}
|
|
136
|
-
cli.optionsFromArgs = removeShortOptions(cli.optionsFromArgs);
|
|
137
150
|
const end = process.hrtime.bigint();
|
|
138
151
|
timings.core.push(Number(end - start));
|
|
139
152
|
try {
|
|
140
|
-
await cli.executeCommand(cli.commandToExecute.command,
|
|
153
|
+
await cli.executeCommand(cli.commandToExecute.command, { options: finalArgs });
|
|
141
154
|
const endTotal = process.hrtime.bigint();
|
|
142
155
|
timings.total.push(Number(endTotal - start));
|
|
143
156
|
await printTimings(rawArgs);
|
|
@@ -347,12 +360,14 @@ async function loadCommandFromFile(commandFileUrl) {
|
|
|
347
360
|
catch { }
|
|
348
361
|
}
|
|
349
362
|
function getCommandInfo(command, filePath = '', helpFilePath = '') {
|
|
363
|
+
const options = command.schema ? zod.schemaToOptions(command.schema) : getCommandOptions(command);
|
|
364
|
+
command.optionsInfo = options;
|
|
350
365
|
return {
|
|
351
366
|
aliases: command.alias(),
|
|
352
367
|
name: command.name,
|
|
353
368
|
description: command.description,
|
|
354
369
|
command: command,
|
|
355
|
-
options
|
|
370
|
+
options,
|
|
356
371
|
defaultProperties: command.defaultProperties(),
|
|
357
372
|
file: filePath,
|
|
358
373
|
help: helpFilePath
|
|
@@ -387,36 +402,47 @@ function getCommandOptions(command) {
|
|
|
387
402
|
return options;
|
|
388
403
|
}
|
|
389
404
|
function getCommandOptionsFromArgs(args, commandInfo) {
|
|
390
|
-
const
|
|
391
|
-
alias: {}
|
|
405
|
+
const yargsOptions = {
|
|
406
|
+
alias: {},
|
|
407
|
+
configuration: {
|
|
408
|
+
"parse-numbers": false,
|
|
409
|
+
"strip-aliased": true,
|
|
410
|
+
"strip-dashed": true
|
|
411
|
+
}
|
|
392
412
|
};
|
|
393
413
|
let argsToParse = args;
|
|
394
414
|
if (commandInfo) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
415
|
+
if (commandInfo.command.schema) {
|
|
416
|
+
yargsOptions.string = commandInfo.options.filter(o => o.type === 'string').map(o => o.name);
|
|
417
|
+
yargsOptions.boolean = commandInfo.options.filter(o => o.type === 'boolean').map(o => o.name);
|
|
418
|
+
yargsOptions.number = commandInfo.options.filter(o => o.type === 'number').map(o => o.name);
|
|
419
|
+
argsToParse = getRewrittenArgs(args, yargsOptions.boolean);
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
const commandTypes = commandInfo.command.types;
|
|
423
|
+
if (commandTypes) {
|
|
424
|
+
yargsOptions.string = commandTypes.string;
|
|
425
|
+
// minimist will parse unused boolean options to 'false' (unused options => options that are not included in the args)
|
|
426
|
+
// But in the CLI booleans are nullable. They can can be true, false or undefined.
|
|
427
|
+
// For this reason we only pass boolean types that are actually used as arg.
|
|
428
|
+
yargsOptions.boolean = commandTypes.boolean.filter(optionName => args.some(arg => `--${optionName}` === arg || `-${optionName}` === arg));
|
|
429
|
+
}
|
|
430
|
+
argsToParse = getRewrittenArgs(args, commandTypes.boolean);
|
|
431
|
+
}
|
|
404
432
|
commandInfo.options.forEach(option => {
|
|
405
433
|
if (option.short && option.long) {
|
|
406
|
-
|
|
434
|
+
yargsOptions.alias[option.long] = option.short;
|
|
407
435
|
}
|
|
408
436
|
});
|
|
409
|
-
argsToParse = getRewrittenArgs(args, commandTypes);
|
|
410
437
|
}
|
|
411
|
-
return
|
|
438
|
+
return yargs(argsToParse, yargsOptions);
|
|
412
439
|
}
|
|
413
440
|
/**
|
|
414
441
|
* Rewrites arguments (if necessary) before passing them into minimist.
|
|
415
442
|
* Currently only boolean values are checked and fixed.
|
|
416
443
|
* Args are only checked and rewritten if the option has been added to the 'types.boolean' array.
|
|
417
444
|
*/
|
|
418
|
-
function getRewrittenArgs(args,
|
|
419
|
-
const booleanTypes = commandTypes.boolean;
|
|
445
|
+
function getRewrittenArgs(args, booleanTypes) {
|
|
420
446
|
if (booleanTypes.length === 0) {
|
|
421
447
|
return args;
|
|
422
448
|
}
|
|
@@ -722,6 +748,9 @@ async function closeWithError(error, args, showHelpIfEnabled = false) {
|
|
|
722
748
|
return process.exit(exitCode);
|
|
723
749
|
}
|
|
724
750
|
let errorMessage = error instanceof CommandError ? error.message : error;
|
|
751
|
+
if (error instanceof ZodError) {
|
|
752
|
+
errorMessage = error.errors.map(e => `${e.path}: ${e.message}`).join(os.EOL);
|
|
753
|
+
}
|
|
725
754
|
if ((!args.options.output || args.options.output === 'json') &&
|
|
726
755
|
!cli.getSettingWithDefaultValue(settingsNames.printErrorsAsPlainText, true)) {
|
|
727
756
|
errorMessage = JSON.stringify({ error: errorMessage });
|
|
@@ -780,13 +809,6 @@ async function handleMultipleResultsFound(message, values) {
|
|
|
780
809
|
const response = await cli.promptForSelection({ message: `Please choose one:`, choices });
|
|
781
810
|
return values[response];
|
|
782
811
|
}
|
|
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
812
|
function loadOptionValuesFromFiles(args) {
|
|
791
813
|
const optionNames = Object.getOwnPropertyNames(args.options);
|
|
792
814
|
optionNames.forEach(option => {
|
|
@@ -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,26 @@ 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
|
+
})
|
|
43
|
+
.refine(options => options.authType !== 'password' || options.password, {
|
|
44
|
+
message: 'Password is required when using password authentication'
|
|
45
|
+
})
|
|
46
|
+
.refine(options => options.authType !== 'certificate' || !(options.certificateFile && options.certificateBase64Encoded), {
|
|
47
|
+
message: 'Specify either certificateFile or certificateBase64Encoded, but not both.'
|
|
48
|
+
})
|
|
49
|
+
.refine(options => options.authType !== 'certificate' || options.certificateFile || options.certificateBase64Encoded, {
|
|
50
|
+
message: 'Specify either certificateFile or certificateBase64Encoded'
|
|
51
|
+
})
|
|
52
|
+
.refine(options => options.authType !== 'secret' || options.secret, {
|
|
53
|
+
message: 'Secret is required when using secret authentication'
|
|
54
|
+
});
|
|
28
55
|
}
|
|
29
56
|
async commandAction(logger, args) {
|
|
30
57
|
// disconnect before re-connecting
|
|
@@ -64,12 +91,7 @@ class LoginCommand extends Command {
|
|
|
64
91
|
auth.connection.secret = args.options.secret;
|
|
65
92
|
break;
|
|
66
93
|
}
|
|
67
|
-
|
|
68
|
-
auth.connection.cloudType = CloudType[args.options.cloud];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
auth.connection.cloudType = CloudType.Public;
|
|
72
|
-
}
|
|
94
|
+
auth.connection.cloudType = args.options.cloud;
|
|
73
95
|
try {
|
|
74
96
|
await auth.ensureAccessToken(auth.defaultResource, logger, this.debug);
|
|
75
97
|
auth.connection.active = true;
|
|
@@ -102,79 +124,5 @@ class LoginCommand extends Command {
|
|
|
102
124
|
await this.commandAction(logger, args);
|
|
103
125
|
}
|
|
104
126
|
}
|
|
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
127
|
export default new LoginCommand();
|
|
180
128
|
//# 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
|
|
@@ -3,10 +3,12 @@ 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 _ConnectionUseCommand_instances, _ConnectionUseCommand_initOptions;
|
|
6
|
+
var _ConnectionUseCommand_instances, _ConnectionUseCommand_initTelemetry, _ConnectionUseCommand_initOptions, _ConnectionUseCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
10
|
+
import { formatting } from '../../../utils/formatting.js';
|
|
11
|
+
import { cli } from '../../../cli/cli.js';
|
|
10
12
|
class ConnectionUseCommand extends Command {
|
|
11
13
|
get name() {
|
|
12
14
|
return commands.USE;
|
|
@@ -18,9 +20,20 @@ class ConnectionUseCommand extends Command {
|
|
|
18
20
|
super();
|
|
19
21
|
_ConnectionUseCommand_instances.add(this);
|
|
20
22
|
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initOptions).call(this);
|
|
23
|
+
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initTelemetry).call(this);
|
|
24
|
+
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initTypes).call(this);
|
|
21
25
|
}
|
|
22
26
|
async commandAction(logger, args) {
|
|
23
|
-
|
|
27
|
+
let connection;
|
|
28
|
+
if (args.options.name) {
|
|
29
|
+
connection = await auth.getConnection(args.options.name);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const connections = await auth.getAllConnections();
|
|
33
|
+
connections.sort((a, b) => a.name.localeCompare(b.name));
|
|
34
|
+
const keyValuePair = formatting.convertArrayToHashTable('name', connections);
|
|
35
|
+
connection = await cli.handleMultipleResultsFound('Please select the connection you want to activate.', keyValuePair);
|
|
36
|
+
}
|
|
24
37
|
if (this.verbose) {
|
|
25
38
|
await logger.logToStderr(`Switching to connection '${connection.identityName}', appId: ${connection.appId}, tenantId: ${connection.identityTenantId}...`);
|
|
26
39
|
}
|
|
@@ -42,10 +55,18 @@ class ConnectionUseCommand extends Command {
|
|
|
42
55
|
await this.commandAction(logger, args);
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
|
-
_ConnectionUseCommand_instances = new WeakSet(),
|
|
58
|
+
_ConnectionUseCommand_instances = new WeakSet(), _ConnectionUseCommand_initTelemetry = function _ConnectionUseCommand_initTelemetry() {
|
|
59
|
+
this.telemetry.push((args) => {
|
|
60
|
+
Object.assign(this.telemetryProperties, {
|
|
61
|
+
name: typeof args.options.name !== 'undefined'
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, _ConnectionUseCommand_initOptions = function _ConnectionUseCommand_initOptions() {
|
|
46
65
|
this.options.unshift({
|
|
47
|
-
option: '-n, --name
|
|
66
|
+
option: '-n, --name [name]'
|
|
48
67
|
});
|
|
68
|
+
}, _ConnectionUseCommand_initTypes = function _ConnectionUseCommand_initTypes() {
|
|
69
|
+
this.types.string.push('name');
|
|
49
70
|
};
|
|
50
71
|
export default new ConnectionUseCommand();
|
|
51
72
|
//# sourceMappingURL=connection-use.js.map
|