@pnp/cli-microsoft365 12.0.0-beta.1752794 → 12.0.0-beta.47b768f

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 (52) hide show
  1. package/allCommands.json +1 -1
  2. package/allCommandsFull.json +1 -1
  3. package/dist/Auth.js +15 -1
  4. package/dist/m365/spfx/commands/SpfxCompatibilityMatrix.js +15 -0
  5. package/dist/m365/spfx/commands/project/project-doctor/doctor-1.24.0-rc.0.js +19 -0
  6. package/dist/m365/spfx/commands/project/project-doctor.js +2 -1
  7. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN012021_TSC_excludeDirectories.js +43 -0
  8. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN027002_OVERRIDES_qs.js +33 -0
  9. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN027003_OVERRIDES_uuid.js +33 -0
  10. package/dist/m365/spfx/commands/project/project-upgrade/upgrade-1.24.0-rc.0.js +77 -0
  11. package/dist/m365/spfx/commands/project/project-upgrade.js +12 -11
  12. package/dist/m365/spo/commands/commandset/commandset-add.js +17 -59
  13. package/dist/m365/spo/commands/commandset/commandset-get.js +24 -62
  14. package/dist/m365/spo/commands/commandset/commandset-list.js +11 -34
  15. package/dist/m365/spo/commands/commandset/commandset-remove.js +21 -54
  16. package/dist/m365/spo/commands/commandset/commandset-set.js +30 -83
  17. package/dist/m365/spo/commands/navigation/navigation-node-add.js +74 -120
  18. package/dist/m365/spo/commands/navigation/navigation-node-get.js +4 -13
  19. package/dist/m365/spo/commands/navigation/navigation-node-set.js +53 -114
  20. package/dist/m365/spo/commands/page/page-unpublish.js +53 -0
  21. package/dist/m365/spo/commands/sitescript/sitescript-add.js +22 -37
  22. package/dist/m365/spo/commands/sitescript/sitescript-get.js +9 -26
  23. package/dist/m365/spo/commands/sitescript/sitescript-list.js +5 -0
  24. package/dist/m365/spo/commands/sitescript/sitescript-remove.js +9 -33
  25. package/dist/m365/spo/commands/sitescript/sitescript-set.js +29 -56
  26. package/dist/m365/spo/commands.js +1 -0
  27. package/dist/m365/spp/commands/contentcenter/contentcenter-list.js +5 -0
  28. package/dist/m365/spp/commands/model/model-get.js +25 -45
  29. package/dist/m365/spp/commands/model/model-list.js +12 -23
  30. package/dist/m365/spp/commands/model/model-remove.js +25 -45
  31. package/dist/m365/teams/commands/meeting/meeting-add.js +57 -68
  32. package/dist/m365/teams/commands/meeting/meeting-attendancereport-get.js +33 -58
  33. package/dist/m365/teams/commands/meeting/meeting-attendancereport-list.js +14 -38
  34. package/dist/m365/teams/commands/meeting/meeting-get.js +14 -38
  35. package/dist/m365/teams/commands/meeting/meeting-list.js +34 -59
  36. package/dist/m365/teams/commands/meeting/meeting-transcript-get.js +34 -58
  37. package/dist/m365/teams/commands/meeting/meeting-transcript-list.js +29 -50
  38. package/dist/utils/spo.js +39 -0
  39. package/docs/docs/cmd/login.mdx +15 -2
  40. package/docs/docs/cmd/spo/navigation/navigation-node-add.mdx +45 -30
  41. package/docs/docs/cmd/spo/navigation/navigation-node-get.mdx +64 -42
  42. package/docs/docs/cmd/spo/navigation/navigation-node-set.mdx +10 -8
  43. package/docs/docs/cmd/spo/page/page-unpublish.mdx +63 -0
  44. package/docs/docs/cmd/teams/tab/tab-add.mdx +19 -0
  45. package/docs/docs/cmd/teams/tab/tab-get.mdx +19 -0
  46. package/docs/docs/cmd/teams/tab/tab-list.mdx +19 -0
  47. package/docs/docs/cmd/teams/tab/tab-remove.mdx +21 -0
  48. package/docs/docs/cmd/viva/engage/engage-message-add.mdx +17 -0
  49. package/docs/docs/cmd/viva/engage/engage-message-get.mdx +17 -0
  50. package/docs/docs/cmd/viva/engage/engage-message-list.mdx +17 -0
  51. package/docs/docs/cmd/viva/engage/engage-message-remove.mdx +19 -0
  52. package/package.json +4 -6
@@ -1,9 +1,4 @@
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 _SpoCommandSetRemoveCommand_instances, _a, _SpoCommandSetRemoveCommand_initTelemetry, _SpoCommandSetRemoveCommand_initOptions, _SpoCommandSetRemoveCommand_initValidators, _SpoCommandSetRemoveCommand_initOptionSets;
1
+ import { globalOptionsZod } from '../../../../Command.js';
7
2
  import commands from '../../commands.js';
8
3
  import { validation } from '../../../../utils/validation.js';
9
4
  import SpoCommand from '../../../base/SpoCommand.js';
@@ -11,6 +6,18 @@ import request from '../../../../request.js';
11
6
  import { formatting } from '../../../../utils/formatting.js';
12
7
  import { spo } from '../../../../utils/spo.js';
13
8
  import { cli } from '../../../../cli/cli.js';
9
+ import { z } from 'zod';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ webUrl: z.string().refine(url => validation.isValidSharePointUrl(url) === true, {
13
+ error: e => `'${e.input}' is not a valid SharePoint Online site URL.`
14
+ }).alias('u'),
15
+ title: z.string().optional().alias('t'),
16
+ id: z.string().refine(validation.isValidGuid, { message: 'The value must be a valid GUID.' }).optional().alias('i'),
17
+ clientSideComponentId: z.string().refine(validation.isValidGuid, { message: 'The value must be a valid GUID.' }).optional().alias('c'),
18
+ scope: z.enum(['All', 'Site', 'Web']).optional().alias('s'),
19
+ force: z.boolean().optional().alias('f')
20
+ });
14
21
  class SpoCommandSetRemoveCommand extends SpoCommand {
15
22
  get name() {
16
23
  return commands.COMMANDSET_REMOVE;
@@ -18,13 +25,14 @@ class SpoCommandSetRemoveCommand extends SpoCommand {
18
25
  get description() {
19
26
  return 'Removes a ListView Command Set that is added to a site.';
20
27
  }
21
- constructor() {
22
- super();
23
- _SpoCommandSetRemoveCommand_instances.add(this);
24
- __classPrivateFieldGet(this, _SpoCommandSetRemoveCommand_instances, "m", _SpoCommandSetRemoveCommand_initTelemetry).call(this);
25
- __classPrivateFieldGet(this, _SpoCommandSetRemoveCommand_instances, "m", _SpoCommandSetRemoveCommand_initOptions).call(this);
26
- __classPrivateFieldGet(this, _SpoCommandSetRemoveCommand_instances, "m", _SpoCommandSetRemoveCommand_initValidators).call(this);
27
- __classPrivateFieldGet(this, _SpoCommandSetRemoveCommand_instances, "m", _SpoCommandSetRemoveCommand_initOptionSets).call(this);
28
+ get schema() {
29
+ return options;
30
+ }
31
+ getRefinedSchema(schema) {
32
+ return schema.refine(opts => [opts.title, opts.id, opts.clientSideComponentId].filter(x => x !== undefined).length === 1, {
33
+ message: `Specify either 'title', 'id' or 'clientSideComponentId', but not multiple.`,
34
+ params: { customCode: 'optionSet', options: ['title', 'id', 'clientSideComponentId'] }
35
+ });
28
36
  }
29
37
  async commandAction(logger, args) {
30
38
  if (this.verbose) {
@@ -83,46 +91,5 @@ class SpoCommandSetRemoveCommand extends SpoCommand {
83
91
  }
84
92
  }
85
93
  }
86
- _a = SpoCommandSetRemoveCommand, _SpoCommandSetRemoveCommand_instances = new WeakSet(), _SpoCommandSetRemoveCommand_initTelemetry = function _SpoCommandSetRemoveCommand_initTelemetry() {
87
- this.telemetry.push((args) => {
88
- Object.assign(this.telemetryProperties, {
89
- title: typeof args.options.title !== 'undefined',
90
- id: typeof args.options.id !== 'undefined',
91
- clientSideComponentId: typeof args.options.clientSideComponentId !== 'undefined',
92
- scope: typeof args.options.scope !== 'undefined',
93
- force: !!args.options.force
94
- });
95
- });
96
- }, _SpoCommandSetRemoveCommand_initOptions = function _SpoCommandSetRemoveCommand_initOptions() {
97
- this.options.unshift({
98
- option: '-u, --webUrl <webUrl>'
99
- }, {
100
- option: '-t, --title [title]'
101
- }, {
102
- option: '-i, --id [id]'
103
- }, {
104
- option: '-c, --clientSideComponentId [clientSideComponentId]'
105
- }, {
106
- option: '-s, --scope [scope]', autocomplete: _a.scopes
107
- }, {
108
- option: '-f, --force'
109
- });
110
- }, _SpoCommandSetRemoveCommand_initValidators = function _SpoCommandSetRemoveCommand_initValidators() {
111
- this.validators.push(async (args) => {
112
- if (args.options.id && !validation.isValidGuid(args.options.id)) {
113
- return `${args.options.id} is not a valid GUID`;
114
- }
115
- if (args.options.clientSideComponentId && !validation.isValidGuid(args.options.clientSideComponentId)) {
116
- return `${args.options.clientSideComponentId} is not a valid GUID`;
117
- }
118
- if (args.options.scope && _a.scopes.indexOf(args.options.scope) < 0) {
119
- return `${args.options.scope} is not a valid scope. Allowed values are ${_a.scopes.join(', ')}`;
120
- }
121
- return validation.isValidSharePointUrl(args.options.webUrl);
122
- });
123
- }, _SpoCommandSetRemoveCommand_initOptionSets = function _SpoCommandSetRemoveCommand_initOptionSets() {
124
- this.optionSets.push({ options: ['id', 'title', 'clientSideComponentId'] });
125
- };
126
- SpoCommandSetRemoveCommand.scopes = ['All', 'Site', 'Web'];
127
94
  export default new SpoCommandSetRemoveCommand();
128
95
  //# sourceMappingURL=commandset-remove.js.map
@@ -1,9 +1,4 @@
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 _SpoCommandSetSetCommand_instances, _a, _SpoCommandSetSetCommand_initTelemetry, _SpoCommandSetSetCommand_initOptions, _SpoCommandSetSetCommand_initValidators, _SpoCommandSetSetCommand_initOptionSets;
1
+ import { globalOptionsZod } from '../../../../Command.js';
7
2
  import commands from '../../commands.js';
8
3
  import { validation } from '../../../../utils/validation.js';
9
4
  import SpoCommand from '../../../base/SpoCommand.js';
@@ -11,6 +6,23 @@ import request from '../../../../request.js';
11
6
  import { formatting } from '../../../../utils/formatting.js';
12
7
  import { spo } from '../../../../utils/spo.js';
13
8
  import { cli } from '../../../../cli/cli.js';
9
+ import { z } from 'zod';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ webUrl: z.string().refine(url => validation.isValidSharePointUrl(url) === true, {
13
+ error: e => `'${e.input}' is not a valid SharePoint Online site URL.`
14
+ }).alias('u'),
15
+ title: z.string().optional().alias('t'),
16
+ id: z.string().refine(validation.isValidGuid, { message: 'The value must be a valid GUID.' }).optional().alias('i'),
17
+ clientSideComponentId: z.string().refine(validation.isValidGuid, { message: 'The value must be a valid GUID.' }).optional().alias('c'),
18
+ newClientSideComponentId: z.string().refine(validation.isValidGuid, { message: 'The value must be a valid GUID.' }).optional(),
19
+ newTitle: z.string().optional(),
20
+ description: z.string().optional(),
21
+ listType: z.enum(['List', 'Library', 'SitePages']).optional().alias('l'),
22
+ clientSideComponentProperties: z.string().optional(),
23
+ scope: z.enum(['All', 'Site', 'Web']).optional().alias('s'),
24
+ location: z.enum(['ContextMenu', 'CommandBar', 'Both']).optional()
25
+ });
14
26
  class SpoCommandSetSetCommand extends SpoCommand {
15
27
  get name() {
16
28
  return commands.COMMANDSET_SET;
@@ -18,13 +30,18 @@ class SpoCommandSetSetCommand extends SpoCommand {
18
30
  get description() {
19
31
  return 'Updates a ListView Command Set on a site.';
20
32
  }
21
- constructor() {
22
- super();
23
- _SpoCommandSetSetCommand_instances.add(this);
24
- __classPrivateFieldGet(this, _SpoCommandSetSetCommand_instances, "m", _SpoCommandSetSetCommand_initTelemetry).call(this);
25
- __classPrivateFieldGet(this, _SpoCommandSetSetCommand_instances, "m", _SpoCommandSetSetCommand_initOptions).call(this);
26
- __classPrivateFieldGet(this, _SpoCommandSetSetCommand_instances, "m", _SpoCommandSetSetCommand_initValidators).call(this);
27
- __classPrivateFieldGet(this, _SpoCommandSetSetCommand_instances, "m", _SpoCommandSetSetCommand_initOptionSets).call(this);
33
+ get schema() {
34
+ return options;
35
+ }
36
+ getRefinedSchema(schema) {
37
+ return schema
38
+ .refine(opts => [opts.title, opts.id, opts.clientSideComponentId].filter(x => x !== undefined).length === 1, {
39
+ message: `Specify either 'title', 'id' or 'clientSideComponentId', but not multiple.`,
40
+ params: { customCode: 'optionSet', options: ['title', 'id', 'clientSideComponentId'] }
41
+ })
42
+ .refine(opts => !!opts.newTitle || opts.description !== undefined || !!opts.listType || !!opts.clientSideComponentProperties || !!opts.location || !!opts.newClientSideComponentId, {
43
+ message: 'Please specify option to be updated'
44
+ });
28
45
  }
29
46
  async commandAction(logger, args) {
30
47
  if (this.verbose) {
@@ -114,75 +131,5 @@ class SpoCommandSetSetCommand extends SpoCommand {
114
131
  }
115
132
  }
116
133
  }
117
- _a = SpoCommandSetSetCommand, _SpoCommandSetSetCommand_instances = new WeakSet(), _SpoCommandSetSetCommand_initTelemetry = function _SpoCommandSetSetCommand_initTelemetry() {
118
- this.telemetry.push((args) => {
119
- Object.assign(this.telemetryProperties, {
120
- title: typeof args.options.title !== 'undefined',
121
- id: typeof args.options.id !== 'undefined',
122
- clientSideComponentId: typeof args.options.clientSideComponentId !== 'undefined',
123
- newClientSideComponentId: typeof args.options.newClientSideComponentId !== 'undefined',
124
- newTitle: typeof args.options.newTitle !== 'undefined',
125
- description: typeof args.options.description !== 'undefined',
126
- listType: typeof args.options.listType !== 'undefined',
127
- clientSideComponentProperties: typeof args.options.clientSideComponentProperties !== 'undefined',
128
- scope: typeof args.options.scope !== 'undefined',
129
- location: typeof args.options.location !== 'undefined'
130
- });
131
- });
132
- }, _SpoCommandSetSetCommand_initOptions = function _SpoCommandSetSetCommand_initOptions() {
133
- this.options.unshift({
134
- option: '-u, --webUrl <webUrl>'
135
- }, {
136
- option: '-t, --title [title]'
137
- }, {
138
- option: '-i, --id [id]'
139
- }, {
140
- option: '-c, --clientSideComponentId [clientSideComponentId]'
141
- }, {
142
- option: '--newClientSideComponentId [newClientSideComponentId]'
143
- }, {
144
- option: '--newTitle [newTitle]'
145
- }, {
146
- option: '--description [description]'
147
- }, {
148
- option: '-l, --listType [listType]', autocomplete: _a.listTypes
149
- }, {
150
- option: '--clientSideComponentProperties [clientSideComponentProperties]'
151
- }, {
152
- option: '-s, --scope [scope]', autocomplete: _a.scopes
153
- }, {
154
- option: '--location [location]', autocomplete: _a.locations
155
- });
156
- }, _SpoCommandSetSetCommand_initValidators = function _SpoCommandSetSetCommand_initValidators() {
157
- this.validators.push(async (args) => {
158
- if (args.options.id && !validation.isValidGuid(args.options.id)) {
159
- return `${args.options.id} is not a valid GUID`;
160
- }
161
- if (args.options.clientSideComponentId && !validation.isValidGuid(args.options.clientSideComponentId)) {
162
- return `${args.options.clientSideComponentId} is not a valid GUID`;
163
- }
164
- if (args.options.newClientSideComponentId && !validation.isValidGuid(args.options.newClientSideComponentId)) {
165
- return `${args.options.newClientSideComponentId} is not a valid GUID`;
166
- }
167
- if (args.options.listType && _a.listTypes.indexOf(args.options.listType) < 0) {
168
- return `${args.options.listType} is not a valid list type. Allowed values are ${_a.listTypes.join(', ')}`;
169
- }
170
- if (args.options.scope && _a.scopes.indexOf(args.options.scope) < 0) {
171
- return `${args.options.scope} is not a valid scope. Allowed values are ${_a.scopes.join(', ')}`;
172
- }
173
- if (args.options.location && _a.locations.indexOf(args.options.location) < 0) {
174
- return `${args.options.location} is not a valid location. Allowed values are ${_a.locations.join(', ')}`;
175
- }
176
- if (!args.options.newTitle && args.options.description === undefined && !args.options.listType && !args.options.clientSideComponentProperties && !args.options.location && !args.options.newClientSideComponentId) {
177
- return `Please specify option to be updated`;
178
- }
179
- return validation.isValidSharePointUrl(args.options.webUrl);
180
- });
181
- }, _SpoCommandSetSetCommand_initOptionSets = function _SpoCommandSetSetCommand_initOptionSets() {
182
- this.optionSets.push({ options: ['id', 'title', 'clientSideComponentId'] });
183
- };
184
- SpoCommandSetSetCommand.listTypes = ['List', 'Library', 'SitePages'];
185
- SpoCommandSetSetCommand.scopes = ['All', 'Site', 'Web'];
186
- SpoCommandSetSetCommand.locations = ['ContextMenu', 'CommandBar', 'Both'];
187
134
  export default new SpoCommandSetSetCommand();
188
135
  //# sourceMappingURL=commandset-set.js.map
@@ -1,14 +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 _SpoNavigationNodeAddCommand_instances, _SpoNavigationNodeAddCommand_initTelemetry, _SpoNavigationNodeAddCommand_initOptions, _SpoNavigationNodeAddCommand_initValidators, _SpoNavigationNodeAddCommand_initOptionSets;
7
- import request from '../../../../request.js';
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { z } from 'zod';
8
3
  import { spo } from '../../../../utils/spo.js';
9
4
  import { validation } from '../../../../utils/validation.js';
10
5
  import SpoCommand from '../../../base/SpoCommand.js';
11
6
  import commands from '../../commands.js';
7
+ export const options = z.strictObject({
8
+ ...globalOptionsZod.shape,
9
+ webUrl: z.string()
10
+ .refine(url => validation.isValidSharePointUrl(url) === true, {
11
+ error: e => `'${e.input}' is not a valid SharePoint Online site URL.`
12
+ })
13
+ .alias('u'),
14
+ location: z.enum(['QuickLaunch', 'TopNavigationBar']).optional().alias('l'),
15
+ title: z.string().min(1, 'Cannot be empty.').alias('t'),
16
+ url: z.string().optional(),
17
+ parentNodeId: z.int().positive().optional(),
18
+ audienceIds: z.string()
19
+ .refine(audienceIds => audienceIds.split(',').length <= 10, {
20
+ error: 'The maximum amount of audienceIds per navigation node exceeded. The maximum amount of audienceIds is 10.'
21
+ })
22
+ .refine(audienceIds => validation.isValidGuidArray(audienceIds) === true, {
23
+ error: e => `The following GUIDs are invalid for the option 'audienceIds': ${validation.isValidGuidArray(e.input)}.`
24
+ })
25
+ .optional(),
26
+ openInNewWindow: z.boolean().optional()
27
+ });
12
28
  class SpoNavigationNodeAddCommand extends SpoCommand {
13
29
  get name() {
14
30
  return commands.NAVIGATION_NODE_ADD;
@@ -16,134 +32,72 @@ class SpoNavigationNodeAddCommand extends SpoCommand {
16
32
  get description() {
17
33
  return 'Adds a navigation node to the specified site navigation';
18
34
  }
19
- constructor() {
20
- super();
21
- _SpoNavigationNodeAddCommand_instances.add(this);
22
- __classPrivateFieldGet(this, _SpoNavigationNodeAddCommand_instances, "m", _SpoNavigationNodeAddCommand_initTelemetry).call(this);
23
- __classPrivateFieldGet(this, _SpoNavigationNodeAddCommand_instances, "m", _SpoNavigationNodeAddCommand_initOptions).call(this);
24
- __classPrivateFieldGet(this, _SpoNavigationNodeAddCommand_instances, "m", _SpoNavigationNodeAddCommand_initValidators).call(this);
25
- __classPrivateFieldGet(this, _SpoNavigationNodeAddCommand_instances, "m", _SpoNavigationNodeAddCommand_initOptionSets).call(this);
35
+ get schema() {
36
+ return options;
37
+ }
38
+ getRefinedSchema(schema) {
39
+ return schema
40
+ .refine(options => [options.location, options.parentNodeId].filter(o => o !== undefined).length === 1, {
41
+ error: `Specify either 'location' or 'parentNodeId', but not both.`,
42
+ params: {
43
+ customCode: 'optionSet',
44
+ options: ['location', 'parentNodeId']
45
+ }
46
+ });
26
47
  }
27
48
  getExcludedOptionsWithUrls() {
28
49
  return ['url'];
29
50
  }
30
51
  async commandAction(logger, args) {
52
+ const { webUrl, location, parentNodeId, title, url, audienceIds, openInNewWindow } = args.options;
31
53
  if (this.verbose) {
32
54
  await logger.logToStderr(`Adding navigation node...`);
33
55
  }
34
- const nodesCollection = args.options.parentNodeId ?
35
- `GetNodeById(${args.options.parentNodeId})/Children` :
36
- args.options.location.toLowerCase();
37
- const requestOptions = {
38
- url: `${args.options.webUrl}/_api/web/navigation/${nodesCollection}`,
39
- headers: {
40
- accept: 'application/json;odata=nometadata',
41
- 'content-type': 'application/json;odata=nometadata'
42
- },
43
- responseType: 'json',
44
- data: {
45
- AudienceIds: args.options.audienceIds?.split(','),
46
- Title: args.options.title,
47
- Url: args.options.url ?? 'http://linkless.header/',
48
- IsExternal: args.options.isExternal === true
49
- }
50
- };
51
56
  try {
52
- const res = await request.post(requestOptions);
53
- if (args.options.openInNewWindow) {
54
- if (this.verbose) {
55
- await logger.logToStderr(`Making sure that the newly added navigation node opens in a new window.`);
56
- }
57
- const id = res.Id.toString();
58
- let menuState = args.options.location === 'TopNavigationBar' ? await spo.getTopNavigationMenuState(args.options.webUrl) : await spo.getQuickLaunchMenuState(args.options.webUrl);
59
- let menuStateItem = this.getMenuStateNode(menuState.Nodes, id);
60
- if (args.options.parentNodeId && !menuStateItem) {
61
- menuState = await spo.getTopNavigationMenuState(args.options.webUrl);
62
- menuStateItem = this.getMenuStateNode(menuState.Nodes, id);
63
- }
64
- menuStateItem.OpenInNewWindow = true;
65
- await spo.saveMenuState(args.options.webUrl, menuState);
57
+ let menuState;
58
+ let siblingNodes;
59
+ if (parentNodeId) {
60
+ const parent = await spo.getMenuStateNodeByKey(webUrl, parentNodeId.toString());
61
+ menuState = parent.menuState;
62
+ siblingNodes = parent.node.Nodes;
63
+ }
64
+ else {
65
+ menuState = location === 'TopNavigationBar'
66
+ ? await spo.getTopNavigationMenuState(webUrl)
67
+ : await spo.getQuickLaunchMenuState(webUrl);
68
+ siblingNodes = menuState.Nodes;
66
69
  }
67
- await logger.log(res);
70
+ const existingKeys = siblingNodes.map(node => node.Key);
71
+ const newNode = {
72
+ AudienceIds: audienceIds ? audienceIds.split(',') : [],
73
+ IsDeleted: false,
74
+ IsHidden: false,
75
+ Key: null,
76
+ Nodes: [],
77
+ NodeType: 0,
78
+ OpenInNewWindow: openInNewWindow ? true : null,
79
+ SimpleUrl: url ?? '',
80
+ Title: title
81
+ };
82
+ siblingNodes.push(newNode);
83
+ await spo.saveMenuState(webUrl, menuState);
84
+ if (this.verbose) {
85
+ await logger.logToStderr(`Retrieving the added navigation node...`);
86
+ }
87
+ const updatedMenuState = await spo.getMenuState(webUrl, menuState.StartingNodeKey);
88
+ const updatedSiblingNodes = parentNodeId
89
+ ? spo.findMenuStateNode(updatedMenuState.Nodes, parentNodeId.toString())?.Nodes
90
+ : updatedMenuState.Nodes;
91
+ const addedNode = updatedSiblingNodes?.find(node => !existingKeys.includes(node.Key) && node.Title === title);
92
+ if (!addedNode) {
93
+ throw `The navigation node was added, but it couldn't be retrieved.`;
94
+ }
95
+ await logger.log(addedNode);
68
96
  }
69
97
  catch (err) {
70
98
  this.handleRejectedODataJsonPromise(err);
71
99
  }
72
100
  }
73
- getMenuStateNode(nodes, id) {
74
- let menuNode = nodes.find((node) => node.Key !== null && node.Key === id);
75
- if (menuNode === undefined) {
76
- for (const node of nodes.filter(node => node.Nodes.length > 0)) {
77
- menuNode = this.getMenuStateNode(node.Nodes, id);
78
- if (menuNode) {
79
- break;
80
- }
81
- }
82
- }
83
- return menuNode;
84
- }
85
101
  }
86
- _SpoNavigationNodeAddCommand_instances = new WeakSet(), _SpoNavigationNodeAddCommand_initTelemetry = function _SpoNavigationNodeAddCommand_initTelemetry() {
87
- this.telemetry.push((args) => {
88
- Object.assign(this.telemetryProperties, {
89
- isExternal: args.options.isExternal,
90
- location: typeof args.options.location !== 'undefined',
91
- parentNodeId: typeof args.options.parentNodeId !== 'undefined',
92
- audienceIds: typeof args.options.audienceIds !== 'undefined',
93
- url: typeof args.options.url !== 'undefined',
94
- openInNewWindow: !!args.options.openInNewWindow
95
- });
96
- });
97
- }, _SpoNavigationNodeAddCommand_initOptions = function _SpoNavigationNodeAddCommand_initOptions() {
98
- this.options.unshift({
99
- option: '-u, --webUrl <webUrl>'
100
- }, {
101
- option: '-l, --location [location]',
102
- autocomplete: ['QuickLaunch', 'TopNavigationBar']
103
- }, {
104
- option: '-t, --title <title>'
105
- }, {
106
- option: '--url [url]'
107
- }, {
108
- option: '--parentNodeId [parentNodeId]'
109
- }, {
110
- option: '--isExternal'
111
- }, {
112
- option: '--audienceIds [audienceIds]'
113
- }, {
114
- option: '--openInNewWindow'
115
- });
116
- }, _SpoNavigationNodeAddCommand_initValidators = function _SpoNavigationNodeAddCommand_initValidators() {
117
- this.validators.push(async (args) => {
118
- const isValidSharePointUrl = validation.isValidSharePointUrl(args.options.webUrl);
119
- if (isValidSharePointUrl !== true) {
120
- return isValidSharePointUrl;
121
- }
122
- if (args.options.parentNodeId) {
123
- if (isNaN(args.options.parentNodeId)) {
124
- return `${args.options.parentNodeId} is not a number`;
125
- }
126
- }
127
- else {
128
- if (args.options.location !== 'QuickLaunch' &&
129
- args.options.location !== 'TopNavigationBar') {
130
- return `${args.options.location} is not a valid value for the location option. Allowed values are QuickLaunch|TopNavigationBar`;
131
- }
132
- }
133
- if (args.options.audienceIds) {
134
- const audienceIdsSplitted = args.options.audienceIds.split(',');
135
- if (audienceIdsSplitted.length > 10) {
136
- return 'The maximum amount of audienceIds per navigation node exceeded. The maximum amount of auciendeIds is 10.';
137
- }
138
- const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.audienceIds);
139
- if (isValidGUIDArrayResult !== true) {
140
- return `The following GUIDs are invalid for the option 'audienceIds': ${isValidGUIDArrayResult}.`;
141
- }
142
- }
143
- return true;
144
- });
145
- }, _SpoNavigationNodeAddCommand_initOptionSets = function _SpoNavigationNodeAddCommand_initOptionSets() {
146
- this.optionSets.push({ options: ['location', 'parentNodeId'] });
147
- };
148
102
  export default new SpoNavigationNodeAddCommand();
149
103
  //# sourceMappingURL=navigation-node-add.js.map
@@ -1,6 +1,6 @@
1
1
  import { globalOptionsZod } from '../../../../Command.js';
2
2
  import { z } from 'zod';
3
- import request from '../../../../request.js';
3
+ import { spo } from '../../../../utils/spo.js';
4
4
  import { validation } from '../../../../utils/validation.js';
5
5
  import SpoCommand from '../../../base/SpoCommand.js';
6
6
  import commands from '../../commands.js';
@@ -11,6 +11,7 @@ export const options = z.strictObject({
11
11
  error: e => `'${e.input}' is not a valid SharePoint Online site URL.`
12
12
  })
13
13
  .alias('u'),
14
+ location: z.enum(['QuickLaunch', 'TopNavigationBar']).alias('l'),
14
15
  id: z.int().positive()
15
16
  });
16
17
  class SpoNavigationNodeGetCommand extends SpoCommand {
@@ -27,19 +28,9 @@ class SpoNavigationNodeGetCommand extends SpoCommand {
27
28
  if (this.verbose) {
28
29
  await logger.logToStderr(`Retrieving information about navigation node with id ${args.options.id}`);
29
30
  }
30
- const requestOptions = {
31
- url: `${args.options.webUrl}/_api/web/navigation/GetNodeById(${args.options.id})?$expand=Children,Children/Children,Children/Children/Children`,
32
- headers: {
33
- accept: 'application/json;odata=nometadata'
34
- },
35
- responseType: 'json'
36
- };
37
31
  try {
38
- const listInstance = await request.get(requestOptions);
39
- if (listInstance['odata.null']) {
40
- throw `No navigation node found with id ${args.options.id}.`;
41
- }
42
- await logger.log(listInstance);
32
+ const { node } = await spo.getMenuStateNodeByKey(args.options.webUrl, args.options.id.toString(), args.options.location);
33
+ await logger.log(node);
43
34
  }
44
35
  catch (err) {
45
36
  this.handleRejectedODataJsonPromise(err);