@pnp/cli-microsoft365 10.8.0-beta.a51d886 → 10.8.0

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 (60) hide show
  1. package/.eslintrc.cjs +2 -1
  2. package/README.md +3 -1
  3. package/allCommands.json +1 -1
  4. package/allCommandsFull.json +1 -1
  5. package/dist/cli/cli.js +1 -1
  6. package/dist/config.js +1 -0
  7. package/dist/m365/adaptivecard/commands/adaptivecard-send.js +54 -67
  8. package/dist/m365/app/commands/app-get.js +5 -2
  9. package/dist/m365/app/commands/app-open.js +9 -22
  10. package/dist/m365/app/commands/permission/permission-add.js +18 -30
  11. package/dist/m365/app/commands/permission/permission-list.js +5 -2
  12. package/dist/m365/base/AppCommand.js +9 -25
  13. package/dist/m365/booking/commands/business/business-get.js +18 -25
  14. package/dist/m365/cli/commands/app/app-reconsent.js +103 -0
  15. package/dist/m365/cli/commands.js +1 -0
  16. package/dist/m365/context/commands/context-remove.js +12 -25
  17. package/dist/m365/context/commands/option/option-remove.js +11 -25
  18. package/dist/m365/entra/commands/organization/organization-list.js +51 -0
  19. package/dist/m365/entra/commands.js +1 -0
  20. package/dist/m365/graph/commands/directoryextension/directoryextension-list.js +74 -0
  21. package/dist/m365/graph/commands/openextension/openextension-set.js +107 -0
  22. package/dist/m365/graph/commands.js +2 -0
  23. package/dist/m365/spe/commands/container/container-add.js +85 -0
  24. package/dist/m365/spe/commands/container/container-list.js +2 -9
  25. package/dist/m365/spe/commands/container/container-recyclebinitem-list.js +62 -0
  26. package/dist/m365/spe/commands/container/container-remove.js +99 -0
  27. package/dist/m365/spe/commands/containertype/containertype-add.js +11 -11
  28. package/dist/m365/spe/commands/containertype/containertype-get.js +28 -32
  29. package/dist/m365/spe/commands/containertype/containertype-list.js +14 -4
  30. package/dist/m365/spe/commands/containertype/containertype-remove.js +81 -0
  31. package/dist/m365/spe/commands.js +5 -1
  32. package/dist/m365/spo/commands/list/list-get.js +12 -6
  33. package/dist/m365/spp/commands/model/model-apply.js +130 -0
  34. package/dist/m365/spp/commands/model/model-get.js +7 -24
  35. package/dist/m365/spp/commands/model/model-list.js +1 -1
  36. package/dist/m365/spp/commands/model/model-remove.js +1 -1
  37. package/dist/m365/spp/commands.js +1 -0
  38. package/dist/utils/entraServicePrincipal.js +11 -0
  39. package/dist/utils/formatting.js +12 -0
  40. package/dist/utils/spe.js +77 -0
  41. package/dist/utils/spo.js +0 -18
  42. package/dist/utils/spp.js +59 -1
  43. package/dist/utils/zod.js +26 -1
  44. package/docs/docs/cmd/adaptivecard/adaptivecard-send.mdx +1 -1
  45. package/docs/docs/cmd/cli/app/app-reconsent.mdx +63 -0
  46. package/docs/docs/cmd/entra/organization/organization-list.mdx +154 -0
  47. package/docs/docs/cmd/graph/directoryextension/directoryextension-list.mdx +135 -0
  48. package/docs/docs/cmd/graph/openextension/openextension-set.mdx +97 -0
  49. package/docs/docs/cmd/spe/container/container-activate.mdx +0 -2
  50. package/docs/docs/cmd/spe/container/container-add.mdx +128 -0
  51. package/docs/docs/cmd/spe/container/container-recyclebinitem-list.mdx +96 -0
  52. package/docs/docs/cmd/spe/container/container-remove.mdx +65 -0
  53. package/docs/docs/cmd/spe/containertype/containertype-add.mdx +9 -1
  54. package/docs/docs/cmd/spe/containertype/containertype-get.mdx +8 -0
  55. package/docs/docs/cmd/spe/containertype/containertype-list.mdx +8 -0
  56. package/docs/docs/cmd/spe/containertype/containertype-remove.mdx +52 -0
  57. package/docs/docs/cmd/spo/list/list-get.mdx +12 -3
  58. package/docs/docs/cmd/spp/model/model-apply.mdx +79 -0
  59. package/package.json +3 -3
  60. package/dist/m365/spe/ContainerProperties.js +0 -2
@@ -1,14 +1,16 @@
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 _ContextOptionRemoveCommand_instances, _ContextOptionRemoveCommand_initTelemetry, _ContextOptionRemoveCommand_initOptions;
7
1
  import fs from 'fs';
2
+ import { z } from 'zod';
8
3
  import { cli } from '../../../../cli/cli.js';
9
- import { CommandError } from '../../../../Command.js';
4
+ import { CommandError, globalOptionsZod } from '../../../../Command.js';
5
+ import { zod } from '../../../../utils/zod.js';
10
6
  import ContextCommand from '../../../base/ContextCommand.js';
11
7
  import commands from '../../commands.js';
8
+ const options = globalOptionsZod
9
+ .extend({
10
+ name: zod.alias('n', z.string()),
11
+ force: zod.alias('f', z.boolean().optional())
12
+ })
13
+ .strict();
12
14
  class ContextOptionRemoveCommand extends ContextCommand {
13
15
  get name() {
14
16
  return commands.OPTION_REMOVE;
@@ -16,11 +18,8 @@ class ContextOptionRemoveCommand extends ContextCommand {
16
18
  get description() {
17
19
  return 'Removes an already available name from local context file.';
18
20
  }
19
- constructor() {
20
- super();
21
- _ContextOptionRemoveCommand_instances.add(this);
22
- __classPrivateFieldGet(this, _ContextOptionRemoveCommand_instances, "m", _ContextOptionRemoveCommand_initOptions).call(this);
23
- __classPrivateFieldGet(this, _ContextOptionRemoveCommand_instances, "m", _ContextOptionRemoveCommand_initTelemetry).call(this);
21
+ get schema() {
22
+ return options;
24
23
  }
25
24
  async commandAction(logger, args) {
26
25
  if (this.verbose) {
@@ -70,18 +69,5 @@ class ContextOptionRemoveCommand extends ContextCommand {
70
69
  }
71
70
  }
72
71
  }
73
- _ContextOptionRemoveCommand_instances = new WeakSet(), _ContextOptionRemoveCommand_initTelemetry = function _ContextOptionRemoveCommand_initTelemetry() {
74
- this.telemetry.push((args) => {
75
- Object.assign(this.telemetryProperties, {
76
- force: !!args.options.force
77
- });
78
- });
79
- }, _ContextOptionRemoveCommand_initOptions = function _ContextOptionRemoveCommand_initOptions() {
80
- this.options.unshift({
81
- option: '-n, --name <name>'
82
- }, {
83
- option: '-f, --force'
84
- });
85
- };
86
72
  export default new ContextOptionRemoveCommand();
87
73
  //# sourceMappingURL=option-remove.js.map
@@ -0,0 +1,51 @@
1
+ import { z } from 'zod';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import { zod } from '../../../../utils/zod.js';
4
+ import GraphCommand from '../../../base/GraphCommand.js';
5
+ import commands from '../../commands.js';
6
+ import { odata } from '../../../../utils/odata.js';
7
+ const options = globalOptionsZod
8
+ .extend({
9
+ properties: zod.alias('p', z.string().optional())
10
+ })
11
+ .strict();
12
+ class EntraOrganizationListCommand extends GraphCommand {
13
+ get name() {
14
+ return commands.ORGANIZATION_LIST;
15
+ }
16
+ get description() {
17
+ return 'Lists all Microsoft Entra ID organizations';
18
+ }
19
+ defaultProperties() {
20
+ return ['id', 'displayName', 'tenantType'];
21
+ }
22
+ get schema() {
23
+ return options;
24
+ }
25
+ async commandAction(logger, args) {
26
+ try {
27
+ let url = `${this.resource}/v1.0/organization`;
28
+ if (args.options.properties) {
29
+ url += `?$select=${args.options.properties}`;
30
+ }
31
+ const requestOptions = {
32
+ url: url,
33
+ headers: {
34
+ accept: 'application/json;odata.metadata=none',
35
+ 'content-type': 'application/json'
36
+ },
37
+ responseType: 'json'
38
+ };
39
+ if (args.options.verbose) {
40
+ await logger.logToStderr(`Retrieving organizations...`);
41
+ }
42
+ const res = await odata.getAllItems(requestOptions);
43
+ await logger.log(res);
44
+ }
45
+ catch (err) {
46
+ this.handleRejectedODataJsonPromise(err);
47
+ }
48
+ }
49
+ }
50
+ export default new EntraOrganizationListCommand();
51
+ //# sourceMappingURL=organization-list.js.map
@@ -83,6 +83,7 @@ export default {
83
83
  OAUTH2GRANT_LIST: `${prefix} oauth2grant list`,
84
84
  OAUTH2GRANT_REMOVE: `${prefix} oauth2grant remove`,
85
85
  OAUTH2GRANT_SET: `${prefix} oauth2grant set`,
86
+ ORGANIZATION_LIST: `${prefix} organization list`,
86
87
  PIM_ROLE_ASSIGNMENT_ADD: `${prefix} pim role assignment add`,
87
88
  PIM_ROLE_ASSIGNMENT_LIST: `${prefix} pim role assignment list`,
88
89
  PIM_ROLE_ASSIGNMENT_REMOVE: `${prefix} pim role assignment remove`,
@@ -0,0 +1,74 @@
1
+ import { z } from 'zod';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import request from '../../../../request.js';
4
+ import commands from '../../commands.js';
5
+ import GraphCommand from '../../../base/GraphCommand.js';
6
+ import { validation } from '../../../../utils/validation.js';
7
+ import { entraApp } from '../../../../utils/entraApp.js';
8
+ import { odata } from '../../../../utils/odata.js';
9
+ const options = globalOptionsZod
10
+ .extend({
11
+ appId: z.string().refine(id => validation.isValidGuid(id), id => ({
12
+ message: `'${id}' is not a valid GUID.`
13
+ })).optional(),
14
+ appObjectId: z.string().refine(id => validation.isValidGuid(id), id => ({
15
+ message: `'${id}' is not a valid GUID.`
16
+ })).optional(),
17
+ appName: z.string().optional()
18
+ })
19
+ .strict();
20
+ class GraphDirectoryExtensionListCommand extends GraphCommand {
21
+ get name() {
22
+ return commands.DIRECTORYEXTENSION_LIST;
23
+ }
24
+ get description() {
25
+ return 'Retrieves a list of directory extensions';
26
+ }
27
+ defaultProperties() {
28
+ return ['id', 'name', 'appDisplayName'];
29
+ }
30
+ get schema() {
31
+ return options;
32
+ }
33
+ getRefinedSchema(schema) {
34
+ return schema
35
+ .refine(options => ([options.appId, options.appObjectId, options.appName].filter(x => x !== undefined).length <= 1), {
36
+ message: 'Specify either appId, appObjectId, or appName, but not multiple.'
37
+ });
38
+ }
39
+ async commandAction(logger, args) {
40
+ try {
41
+ if (args.options.appId || args.options.appObjectId || args.options.appName) {
42
+ const appObjectId = await this.getAppObjectId(args.options);
43
+ const endpoint = `${this.resource}/v1.0/applications/${appObjectId}/extensionProperties/`;
44
+ const items = await odata.getAllItems(endpoint);
45
+ await logger.log(items);
46
+ }
47
+ else {
48
+ const requestOptions = {
49
+ url: `${this.resource}/v1.0/directoryObjects/getAvailableExtensionProperties`,
50
+ headers: {
51
+ 'content-type': 'application/json;odata.metadata=none'
52
+ },
53
+ responseType: 'json'
54
+ };
55
+ const res = await request.post(requestOptions);
56
+ await logger.log(res.value);
57
+ }
58
+ }
59
+ catch (err) {
60
+ this.handleRejectedODataJsonPromise(err);
61
+ }
62
+ }
63
+ async getAppObjectId(options) {
64
+ if (options.appObjectId) {
65
+ return options.appObjectId;
66
+ }
67
+ if (options.appId) {
68
+ return (await entraApp.getAppRegistrationByAppId(options.appId, ["id"])).id;
69
+ }
70
+ return (await entraApp.getAppRegistrationByAppName(options.appName, ["id"])).id;
71
+ }
72
+ }
73
+ export default new GraphDirectoryExtensionListCommand();
74
+ //# sourceMappingURL=directoryextension-list.js.map
@@ -0,0 +1,107 @@
1
+ import { z } from 'zod';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import { zod } from '../../../../utils/zod.js';
4
+ import { validation } from '../../../../utils/validation.js';
5
+ import GraphCommand from '../../../base/GraphCommand.js';
6
+ import commands from '../../commands.js';
7
+ import request from '../../../../request.js';
8
+ import { optionsUtils } from '../../../../utils/optionsUtils.js';
9
+ const options = globalOptionsZod
10
+ .extend({
11
+ name: zod.alias('n', z.string()),
12
+ resourceId: zod.alias('i', z.string()),
13
+ resourceType: zod.alias('t', z.enum(['user', 'group', 'device', 'organization'])),
14
+ keepUnchangedProperties: zod.alias('k', z.boolean().optional())
15
+ })
16
+ .and(z.any());
17
+ class GraphOpenExtensionSetCommand extends GraphCommand {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.commandOptions = ['keepUnchangedProperties', 'resourceType', 'resourceId', 'name'];
21
+ this.defaultOpenExtensionProperties = ['id', 'extensionName'];
22
+ }
23
+ get name() {
24
+ return commands.OPENEXTENSION_SET;
25
+ }
26
+ get description() {
27
+ return 'Updates an open extension for a resource';
28
+ }
29
+ get schema() {
30
+ return options;
31
+ }
32
+ getRefinedSchema(schema) {
33
+ return schema
34
+ .refine(options => options.resourceType !== 'group' && options.resourceType !== 'device' && options.resourceType !== 'organization' || (options.resourceId && validation.isValidGuid(options.resourceId)), options => ({
35
+ message: `The '${options.resourceId}' must be a valid GUID`,
36
+ path: ['resourceId']
37
+ }))
38
+ .refine(options => options.resourceType !== 'user' || (options.resourceId && (validation.isValidGuid(options.resourceId) || validation.isValidUserPrincipalName(options.resourceId))), options => ({
39
+ message: `The '${options.resourceId}' must be a valid GUID or user principal name`,
40
+ path: ['resourceId']
41
+ }));
42
+ }
43
+ async commandAction(logger, args) {
44
+ try {
45
+ const currentExtension = await this.getOpenExtension(logger, args);
46
+ const currentExtensionNames = Object.getOwnPropertyNames(currentExtension);
47
+ const requestBody = {};
48
+ requestBody["@odata.type"] = '#microsoft.graph.openTypeExtension';
49
+ const unknownOptions = optionsUtils.getUnknownOptions(args.options, this.options);
50
+ const unknownOptionsNames = Object.getOwnPropertyNames(unknownOptions);
51
+ unknownOptionsNames.forEach(async (option) => {
52
+ if (this.commandOptions.includes(option)) {
53
+ return;
54
+ }
55
+ const value = unknownOptions[option];
56
+ if (value === "") {
57
+ requestBody[option] = null;
58
+ }
59
+ else {
60
+ try {
61
+ const jsonObject = JSON.parse(value);
62
+ requestBody[option] = jsonObject;
63
+ }
64
+ catch {
65
+ requestBody[option] = value;
66
+ }
67
+ }
68
+ });
69
+ currentExtensionNames.forEach(async (name) => {
70
+ if (!unknownOptionsNames.includes(name) && (args.options.keepUnchangedProperties || this.defaultOpenExtensionProperties.includes(name))) {
71
+ requestBody[name] = currentExtension[name];
72
+ }
73
+ });
74
+ const requestOptions = {
75
+ url: `${this.resource}/v1.0/${args.options.resourceType}${args.options.resourceType === 'organization' ? '' : 's'}/${args.options.resourceId}/extensions/${args.options.name}`,
76
+ headers: {
77
+ accept: 'application/json;odata.metadata=none',
78
+ 'content-type': 'application/json'
79
+ },
80
+ data: requestBody,
81
+ responseType: 'json'
82
+ };
83
+ if (args.options.verbose) {
84
+ await logger.logToStderr(`Updating open extension of the ${args.options.resourceType} with id '${args.options.resourceId}'...`);
85
+ }
86
+ await request.patch(requestOptions);
87
+ }
88
+ catch (err) {
89
+ this.handleRejectedODataJsonPromise(err);
90
+ }
91
+ }
92
+ async getOpenExtension(logger, args) {
93
+ if (this.verbose) {
94
+ await logger.logToStderr(`Retrieving open extension for resource ${args.options.resourceId}...`);
95
+ }
96
+ const requestOptions = {
97
+ url: `${this.resource}/v1.0/${args.options.resourceType}${args.options.resourceType === 'organization' ? '' : 's'}/${args.options.resourceId}/extensions/${args.options.name}`,
98
+ headers: {
99
+ accept: 'application/json;odata.metadata=none'
100
+ },
101
+ responseType: 'json'
102
+ };
103
+ return await request.get(requestOptions);
104
+ }
105
+ }
106
+ export default new GraphOpenExtensionSetCommand();
107
+ //# sourceMappingURL=openextension-set.js.map
@@ -3,11 +3,13 @@ export default {
3
3
  CHANGELOG_LIST: `${prefix} changelog list`,
4
4
  DIRECTORYEXTENSION_ADD: `${prefix} directoryextension add`,
5
5
  DIRECTORYEXTENSION_GET: `${prefix} directoryextension get`,
6
+ DIRECTORYEXTENSION_LIST: `${prefix} directoryextension list`,
6
7
  DIRECTORYEXTENSION_REMOVE: `${prefix} directoryextension remove`,
7
8
  OPENEXTENSION_ADD: `${prefix} openextension add`,
8
9
  OPENEXTENSION_GET: `${prefix} openextension get`,
9
10
  OPENEXTENSION_LIST: `${prefix} openextension list`,
10
11
  OPENEXTENSION_REMOVE: `${prefix} openextension remove`,
12
+ OPENEXTENSION_SET: `${prefix} openextension set`,
11
13
  SCHEMAEXTENSION_ADD: `${prefix} schemaextension add`,
12
14
  SCHEMAEXTENSION_GET: `${prefix} schemaextension get`,
13
15
  SCHEMAEXTENSION_LIST: `${prefix} schemaextension list`,
@@ -0,0 +1,85 @@
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { z } from 'zod';
3
+ import { zod } from '../../../../utils/zod.js';
4
+ import commands from '../../commands.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import { spe } from '../../../../utils/spe.js';
7
+ import { spo } from '../../../../utils/spo.js';
8
+ import GraphCommand from '../../../base/GraphCommand.js';
9
+ import request from '../../../../request.js';
10
+ const options = globalOptionsZod
11
+ .extend({
12
+ name: zod.alias('n', z.string()),
13
+ description: zod.alias('d', z.string()).optional(),
14
+ containerTypeId: z.string()
15
+ .refine(id => validation.isValidGuid(id), id => ({
16
+ message: `'${id}' is not a valid GUID.`
17
+ })).optional(),
18
+ containerTypeName: z.string().optional(),
19
+ ocrEnabled: z.boolean().optional(),
20
+ itemMajorVersionLimit: z.number()
21
+ .refine(numb => validation.isValidPositiveInteger(numb), numb => ({
22
+ message: `'${numb}' is not a valid positive integer.`
23
+ })).optional(),
24
+ itemVersioningEnabled: z.boolean().optional()
25
+ })
26
+ .strict();
27
+ class SpeContainerAddCommand extends GraphCommand {
28
+ get name() {
29
+ return commands.CONTAINER_ADD;
30
+ }
31
+ get description() {
32
+ return 'Creates a new container';
33
+ }
34
+ get schema() {
35
+ return options;
36
+ }
37
+ getRefinedSchema(schema) {
38
+ return schema
39
+ .refine((options) => [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 1, {
40
+ message: 'Use one of the following options: containerTypeId or containerTypeName.'
41
+ });
42
+ }
43
+ async commandAction(logger, args) {
44
+ try {
45
+ const containerTypeId = await this.getContainerTypeId(args.options, logger);
46
+ if (this.verbose) {
47
+ await logger.logToStderr(`Creating container with name '${args.options.name}'...`);
48
+ }
49
+ const requestOptions = {
50
+ url: `${this.resource}/v1.0/storage/fileStorage/containers`,
51
+ headers: {
52
+ accept: 'application/json;odata.metadata=none'
53
+ },
54
+ responseType: 'json',
55
+ data: {
56
+ displayName: args.options.name,
57
+ description: args.options.description,
58
+ containerTypeId: containerTypeId,
59
+ settings: {
60
+ isOcrEnabled: args.options.ocrEnabled,
61
+ itemMajorVersionLimit: args.options.itemMajorVersionLimit,
62
+ isItemVersioningEnabled: args.options.itemVersioningEnabled
63
+ }
64
+ }
65
+ };
66
+ const container = await request.post(requestOptions);
67
+ await logger.log(container);
68
+ }
69
+ catch (err) {
70
+ this.handleRejectedODataJsonPromise(err);
71
+ }
72
+ }
73
+ async getContainerTypeId(options, logger) {
74
+ if (options.containerTypeId) {
75
+ return options.containerTypeId;
76
+ }
77
+ if (this.verbose) {
78
+ await logger.logToStderr(`Getting container type with name '${options.containerTypeName}'...`);
79
+ }
80
+ const adminUrl = await spo.getSpoAdminUrl(logger, this.verbose);
81
+ return spe.getContainerTypeIdByName(adminUrl, options.containerTypeName);
82
+ }
83
+ }
84
+ export default new SpeContainerAddCommand();
85
+ //# sourceMappingURL=container-add.js.map
@@ -9,6 +9,7 @@ import { odata } from '../../../../utils/odata.js';
9
9
  import { validation } from '../../../../utils/validation.js';
10
10
  import GraphCommand from '../../../base/GraphCommand.js';
11
11
  import commands from '../../commands.js';
12
+ import { spe } from '../../../../utils/spe.js';
12
13
  import { spo } from '../../../../utils/spo.js';
13
14
  class SpeContainerListCommand extends GraphCommand {
14
15
  get name() {
@@ -47,15 +48,7 @@ class SpeContainerListCommand extends GraphCommand {
47
48
  return options.containerTypeId;
48
49
  }
49
50
  const spoAdminUrl = await spo.getSpoAdminUrl(logger, this.debug);
50
- const containerTypes = await spo.getAllContainerTypes(spoAdminUrl, logger, this.debug);
51
- // Get id of the container type by name
52
- const containerType = containerTypes.find(c => c.DisplayName === options.containerTypeName);
53
- if (!containerType) {
54
- throw new Error(`Container type with name ${options.containerTypeName} not found`);
55
- }
56
- // The value is returned as "/Guid(073269af-f1d2-042d-2ef5-5bdd6ac83115)/". We need to extract the GUID from it.
57
- const containerTypeValue = containerType.ContainerTypeId.toString();
58
- return containerTypeValue.substring(containerTypeValue.indexOf('(') + 1, containerTypeValue.lastIndexOf(')'));
51
+ return spe.getContainerTypeIdByName(spoAdminUrl, options.containerTypeName);
59
52
  }
60
53
  }
61
54
  _SpeContainerListCommand_instances = new WeakSet(), _SpeContainerListCommand_initTelemetry = function _SpeContainerListCommand_initTelemetry() {
@@ -0,0 +1,62 @@
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { z } from 'zod';
3
+ import commands from '../../commands.js';
4
+ import { validation } from '../../../../utils/validation.js';
5
+ import { spo } from '../../../../utils/spo.js';
6
+ import GraphCommand from '../../../base/GraphCommand.js';
7
+ import { spe } from '../../../../utils/spe.js';
8
+ import { odata } from '../../../../utils/odata.js';
9
+ const options = globalOptionsZod
10
+ .extend({
11
+ containerTypeId: z.string()
12
+ .refine(id => validation.isValidGuid(id), id => ({
13
+ message: `'${id}' is not a valid GUID.`
14
+ })).optional(),
15
+ containerTypeName: z.string().optional()
16
+ })
17
+ .strict();
18
+ class SpeContainerRecycleBinItemListCommand extends GraphCommand {
19
+ get name() {
20
+ return commands.CONTAINER_RECYCLEBINITEM_LIST;
21
+ }
22
+ get description() {
23
+ return 'Lists deleted containers of a specific container type';
24
+ }
25
+ get schema() {
26
+ return options;
27
+ }
28
+ defaultProperties() {
29
+ return ['id', 'displayName'];
30
+ }
31
+ getRefinedSchema(schema) {
32
+ return schema
33
+ .refine((options) => [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 1, {
34
+ message: 'Use one of the following options: containerTypeId or containerTypeName.'
35
+ });
36
+ }
37
+ async commandAction(logger, args) {
38
+ try {
39
+ const containerTypeId = await this.getContainerTypeId(args.options, logger);
40
+ if (this.verbose) {
41
+ await logger.logToStderr(`Retrieving deleted containers of container type with ID '${containerTypeId}'...`);
42
+ }
43
+ const deletedContainers = await odata.getAllItems(`${this.resource}/v1.0/storage/fileStorage/deletedContainers?$filter=containerTypeId eq ${containerTypeId}`);
44
+ await logger.log(deletedContainers);
45
+ }
46
+ catch (err) {
47
+ this.handleRejectedODataJsonPromise(err);
48
+ }
49
+ }
50
+ async getContainerTypeId(options, logger) {
51
+ if (options.containerTypeId) {
52
+ return options.containerTypeId;
53
+ }
54
+ if (this.verbose) {
55
+ await logger.logToStderr(`Retrieving container type id for container type '${options.containerTypeName}'...`);
56
+ }
57
+ const adminUrl = await spo.getSpoAdminUrl(logger, this.verbose);
58
+ return spe.getContainerTypeIdByName(adminUrl, options.containerTypeName);
59
+ }
60
+ }
61
+ export default new SpeContainerRecycleBinItemListCommand();
62
+ //# sourceMappingURL=container-recyclebinitem-list.js.map
@@ -0,0 +1,99 @@
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { z } from 'zod';
3
+ import { zod } from '../../../../utils/zod.js';
4
+ import commands from '../../commands.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import { spe } from '../../../../utils/spe.js';
7
+ import { spo } from '../../../../utils/spo.js';
8
+ import GraphCommand from '../../../base/GraphCommand.js';
9
+ import request from '../../../../request.js';
10
+ import { cli } from '../../../../cli/cli.js';
11
+ const options = globalOptionsZod
12
+ .extend({
13
+ id: zod.alias('i', z.string()).optional(),
14
+ name: zod.alias('n', z.string()).optional(),
15
+ containerTypeId: z.string()
16
+ .refine(id => validation.isValidGuid(id), id => ({
17
+ message: `'${id}' is not a valid GUID.`
18
+ })).optional(),
19
+ containerTypeName: z.string().optional(),
20
+ recycle: z.boolean().optional(),
21
+ force: zod.alias('f', z.boolean().optional())
22
+ })
23
+ .strict();
24
+ class SpeContainerRemoveCommand extends GraphCommand {
25
+ get name() {
26
+ return commands.CONTAINER_REMOVE;
27
+ }
28
+ get description() {
29
+ return 'Removes a container';
30
+ }
31
+ get schema() {
32
+ return options;
33
+ }
34
+ getRefinedSchema(schema) {
35
+ return schema
36
+ .refine((options) => [options.id, options.name].filter(o => o !== undefined).length === 1, {
37
+ message: 'Use one of the following options: id or name.'
38
+ })
39
+ .refine((options) => !options.name || [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 1, {
40
+ message: 'Use one of the following options when specifying the container name: containerTypeId or containerTypeName.'
41
+ })
42
+ .refine((options) => options.name || [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 0, {
43
+ message: 'Options containerTypeId and containerTypeName are only required when deleting a container by name.'
44
+ });
45
+ }
46
+ async commandAction(logger, args) {
47
+ if (!args.options.force) {
48
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove container '${args.options.id || args.options.name}'${!args.options.recycle ? ' permanently' : ''}?` });
49
+ if (!result) {
50
+ return;
51
+ }
52
+ }
53
+ try {
54
+ const containerId = await this.getContainerId(args.options, logger);
55
+ if (this.verbose) {
56
+ await logger.logToStderr(`Removing container with ID '${containerId}'...`);
57
+ }
58
+ const requestOptions = {
59
+ url: `${this.resource}/v1.0/storage/fileStorage/containers/${containerId}`,
60
+ headers: {
61
+ accept: 'application/json;odata.metadata=none'
62
+ },
63
+ responseType: 'json'
64
+ };
65
+ if (args.options.recycle) {
66
+ await request.delete(requestOptions);
67
+ return;
68
+ }
69
+ // Container should be permanently deleted
70
+ requestOptions.url += '/permanentDelete';
71
+ await request.post(requestOptions);
72
+ }
73
+ catch (err) {
74
+ this.handleRejectedODataJsonPromise(err);
75
+ }
76
+ }
77
+ async getContainerId(options, logger) {
78
+ if (options.id) {
79
+ return options.id;
80
+ }
81
+ const containerTypeId = await this.getContainerTypeId(options, logger);
82
+ if (this.verbose) {
83
+ await logger.logToStderr(`Getting container ID for container with name '${options.name}'...`);
84
+ }
85
+ return spe.getContainerIdByName(containerTypeId, options.name);
86
+ }
87
+ async getContainerTypeId(options, logger) {
88
+ if (options.containerTypeId) {
89
+ return options.containerTypeId;
90
+ }
91
+ if (this.verbose) {
92
+ await logger.logToStderr(`Getting container type with name '${options.containerTypeName}'...`);
93
+ }
94
+ const adminUrl = await spo.getSpoAdminUrl(logger, this.verbose);
95
+ return spe.getContainerTypeIdByName(adminUrl, options.containerTypeName);
96
+ }
97
+ }
98
+ export default new SpeContainerRemoveCommand();
99
+ //# sourceMappingURL=container-remove.js.map
@@ -3,14 +3,14 @@ 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 _SpeContainertypeAddCommand_instances, _SpeContainertypeAddCommand_initTelemetry, _SpeContainertypeAddCommand_initOptions, _SpeContainertypeAddCommand_initValidators;
6
+ var _SpeContainerTypeAddCommand_instances, _SpeContainerTypeAddCommand_initTelemetry, _SpeContainerTypeAddCommand_initOptions, _SpeContainerTypeAddCommand_initValidators;
7
7
  import config from '../../../../config.js';
8
8
  import request from '../../../../request.js';
9
9
  import { spo } from '../../../../utils/spo.js';
10
10
  import { validation } from '../../../../utils/validation.js';
11
11
  import SpoCommand from '../../../base/SpoCommand.js';
12
12
  import commands from '../../commands.js';
13
- class SpeContainertypeAddCommand extends SpoCommand {
13
+ class SpeContainerTypeAddCommand extends SpoCommand {
14
14
  get name() {
15
15
  return commands.CONTAINERTYPE_ADD;
16
16
  }
@@ -19,10 +19,10 @@ class SpeContainertypeAddCommand extends SpoCommand {
19
19
  }
20
20
  constructor() {
21
21
  super();
22
- _SpeContainertypeAddCommand_instances.add(this);
23
- __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initTelemetry).call(this);
24
- __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initOptions).call(this);
25
- __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initValidators).call(this);
22
+ _SpeContainerTypeAddCommand_instances.add(this);
23
+ __classPrivateFieldGet(this, _SpeContainerTypeAddCommand_instances, "m", _SpeContainerTypeAddCommand_initTelemetry).call(this);
24
+ __classPrivateFieldGet(this, _SpeContainerTypeAddCommand_instances, "m", _SpeContainerTypeAddCommand_initOptions).call(this);
25
+ __classPrivateFieldGet(this, _SpeContainerTypeAddCommand_instances, "m", _SpeContainerTypeAddCommand_initValidators).call(this);
26
26
  }
27
27
  async commandAction(logger, args) {
28
28
  try {
@@ -55,7 +55,7 @@ class SpeContainertypeAddCommand extends SpoCommand {
55
55
  await logger.log(result);
56
56
  }
57
57
  catch (err) {
58
- this.handleRejectedPromise(err);
58
+ this.handleRejectedODataJsonPromise(err);
59
59
  }
60
60
  }
61
61
  replaceString(s) {
@@ -68,7 +68,7 @@ class SpeContainertypeAddCommand extends SpoCommand {
68
68
  return `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><Method Name="NewSPOContainerType" Id="4" ObjectPathId="1"><Parameters><Parameter TypeId="{5466648e-c306-441b-9df4-c09deef25cb1}"><Property Name="AzureSubscriptionId" Type="Guid">{${options.azureSubscriptionId}}</Property><Property Name="ContainerTypeId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="CreationDate" Type="Null" /><Property Name="DisplayName" Type="String">${options.name}</Property><Property Name="ExpiryDate" Type="Null" /><Property Name="IsBillingProfileRequired" Type="Boolean">false</Property><Property Name="OwningAppId" Type="Guid">{${options.applicationId}}</Property><Property Name="OwningTenantId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="Region" Type="String">${options.region}</Property><Property Name="ResourceGroup" Type="String">${options.resourceGroup}</Property><Property Name="SPContainerTypeBillingClassification" Type="Enum">0</Property></Parameter></Parameters></Method></Actions><ObjectPaths><Constructor Id="1" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`;
69
69
  }
70
70
  }
71
- _SpeContainertypeAddCommand_instances = new WeakSet(), _SpeContainertypeAddCommand_initTelemetry = function _SpeContainertypeAddCommand_initTelemetry() {
71
+ _SpeContainerTypeAddCommand_instances = new WeakSet(), _SpeContainerTypeAddCommand_initTelemetry = function _SpeContainerTypeAddCommand_initTelemetry() {
72
72
  this.telemetry.push((args) => {
73
73
  Object.assign(this.telemetryProperties, {
74
74
  trial: !!args.options.trial,
@@ -77,7 +77,7 @@ _SpeContainertypeAddCommand_instances = new WeakSet(), _SpeContainertypeAddComma
77
77
  region: typeof args.options.region !== 'undefined'
78
78
  });
79
79
  });
80
- }, _SpeContainertypeAddCommand_initOptions = function _SpeContainertypeAddCommand_initOptions() {
80
+ }, _SpeContainerTypeAddCommand_initOptions = function _SpeContainerTypeAddCommand_initOptions() {
81
81
  this.options.unshift({
82
82
  option: '-n, --name <name>'
83
83
  }, {
@@ -91,7 +91,7 @@ _SpeContainertypeAddCommand_instances = new WeakSet(), _SpeContainertypeAddComma
91
91
  }, {
92
92
  option: '--region [region]'
93
93
  });
94
- }, _SpeContainertypeAddCommand_initValidators = function _SpeContainertypeAddCommand_initValidators() {
94
+ }, _SpeContainerTypeAddCommand_initValidators = function _SpeContainerTypeAddCommand_initValidators() {
95
95
  this.validators.push(async (args) => {
96
96
  if (!validation.isValidGuid(args.options.applicationId)) {
97
97
  return `${args.options.applicationId} is not a valid GUID for option applicationId.`;
@@ -111,5 +111,5 @@ _SpeContainertypeAddCommand_instances = new WeakSet(), _SpeContainertypeAddComma
111
111
  return true;
112
112
  });
113
113
  };
114
- export default new SpeContainertypeAddCommand();
114
+ export default new SpeContainerTypeAddCommand();
115
115
  //# sourceMappingURL=containertype-add.js.map