@pnp/cli-microsoft365 11.4.0-beta.40f818c → 11.4.0-beta.810a987

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Auth.js CHANGED
@@ -798,7 +798,7 @@ export class Auth {
798
798
  const existingConnection = allConnections.find(c => c.name === newName);
799
799
  const oldName = connection.name;
800
800
  if (existingConnection) {
801
- throw new CommandError(`The connection name '${newName}' is already in use`);
801
+ throw new CommandError(`The connection name '${newName}' is already in use.`);
802
802
  }
803
803
  connection.name = newName;
804
804
  if (this.connection.name === oldName) {
package/dist/cli/cli.js CHANGED
@@ -145,7 +145,7 @@ async function execute(rawArgs) {
145
145
  if (cli.commandToExecute?.command.schema) {
146
146
  while (true) {
147
147
  const startValidation = process.hrtime.bigint();
148
- const result = cli.commandToExecute.command.getSchemaToParse().safeParse(cli.optionsFromArgs.options);
148
+ const result = await cli.commandToExecute.command.getSchemaToParse().safeParseAsync(cli.optionsFromArgs.options);
149
149
  const endValidation = process.hrtime.bigint();
150
150
  timings.validation.push(Number(endValidation - startValidation));
151
151
  if (result.success) {
@@ -21,7 +21,11 @@ export const options = z.strictObject({
21
21
  appId: z.string().optional(),
22
22
  tenant: z.string().optional(),
23
23
  secret: z.string().optional().alias('s'),
24
- connectionName: z.string().optional(),
24
+ connectionName: z.string()
25
+ .refine(async (name) => !(await auth.getAllConnections()).some(c => c.name === name), {
26
+ error: e => `Connection with name '${e.input}' already exists.`
27
+ })
28
+ .optional(),
25
29
  ensure: z.boolean().optional()
26
30
  });
27
31
  class LoginCommand extends Command {
@@ -1,12 +1,18 @@
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 _ConnectionSetCommand_instances, _ConnectionSetCommand_initOptions, _ConnectionSetCommand_initValidators, _ConnectionSetCommand_initTypes;
7
1
  import auth from '../../../Auth.js';
8
2
  import commands from '../commands.js';
9
- import Command, { CommandError } from '../../../Command.js';
3
+ import Command, { CommandError, globalOptionsZod } from '../../../Command.js';
4
+ import z from 'zod';
5
+ export const options = z.strictObject({
6
+ ...globalOptionsZod.shape,
7
+ name: z.string().alias('n')
8
+ .refine(async (name) => (await auth.getAllConnections()).some(c => c.name === name), {
9
+ error: e => `Connection with name '${e.input}' does not exist.`
10
+ }),
11
+ newName: z.string()
12
+ .refine(async (newName) => !(await auth.getAllConnections()).some(c => c.name === newName), {
13
+ error: e => `Connection with name '${e.input}' already exists.`
14
+ })
15
+ });
10
16
  class ConnectionSetCommand extends Command {
11
17
  get name() {
12
18
  return commands.SET;
@@ -14,12 +20,8 @@ class ConnectionSetCommand extends Command {
14
20
  get description() {
15
21
  return 'Rename the specified connection';
16
22
  }
17
- constructor() {
18
- super();
19
- _ConnectionSetCommand_instances.add(this);
20
- __classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initOptions).call(this);
21
- __classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initValidators).call(this);
22
- __classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initTypes).call(this);
23
+ get schema() {
24
+ return options;
23
25
  }
24
26
  async commandAction(logger, args) {
25
27
  const connection = await auth.getConnection(args.options.name);
@@ -39,21 +41,5 @@ class ConnectionSetCommand extends Command {
39
41
  await this.commandAction(logger, args);
40
42
  }
41
43
  }
42
- _ConnectionSetCommand_instances = new WeakSet(), _ConnectionSetCommand_initOptions = function _ConnectionSetCommand_initOptions() {
43
- this.options.unshift({
44
- option: '-n, --name <name>'
45
- }, {
46
- option: '--newName <newName>'
47
- });
48
- }, _ConnectionSetCommand_initValidators = function _ConnectionSetCommand_initValidators() {
49
- this.validators.push(async (args) => {
50
- if (args.options.name === args.options.newName) {
51
- return `Choose a name different from the current one`;
52
- }
53
- return true;
54
- });
55
- }, _ConnectionSetCommand_initTypes = function _ConnectionSetCommand_initTypes() {
56
- this.types.string.push('name', 'newName');
57
- };
58
44
  export default new ConnectionSetCommand();
59
45
  //# sourceMappingURL=connection-set.js.map
@@ -0,0 +1,96 @@
1
+ import { globalOptionsZod } from '../../../../Command.js';
2
+ import { z } from 'zod';
3
+ import commands from '../../commands.js';
4
+ import GraphCommand from '../../../base/GraphCommand.js';
5
+ import { spe } from '../../../../utils/spe.js';
6
+ import { odata } from '../../../../utils/odata.js';
7
+ import { formatting } from '../../../../utils/formatting.js';
8
+ import { cli } from '../../../../cli/cli.js';
9
+ import request from '../../../../request.js';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ id: z.string().optional().alias('i'),
13
+ name: z.string().optional().alias('n'),
14
+ containerTypeId: z.uuid().optional(),
15
+ containerTypeName: z.string().optional(),
16
+ force: z.boolean().optional().alias('f')
17
+ });
18
+ class SpeContainerRecycleBinItemRemoveCommand extends GraphCommand {
19
+ get name() {
20
+ return commands.CONTAINER_RECYCLEBINITEM_REMOVE;
21
+ }
22
+ get description() {
23
+ return 'Permanently removes a container from the recycle bin';
24
+ }
25
+ get schema() {
26
+ return options;
27
+ }
28
+ getRefinedSchema(schema) {
29
+ return schema
30
+ .refine((options) => [options.id, options.name].filter(o => o !== undefined).length === 1, {
31
+ error: 'Use one of the following options: id or name.'
32
+ })
33
+ .refine((options) => !options.name || [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 1, {
34
+ error: 'Use one of the following options when specifying the container name: containerTypeId or containerTypeName.'
35
+ })
36
+ .refine((options) => options.name || [options.containerTypeId, options.containerTypeName].filter(o => o !== undefined).length === 0, {
37
+ error: 'Options containerTypeId and containerTypeName are only required when removing a container by name.'
38
+ });
39
+ }
40
+ async commandAction(logger, args) {
41
+ if (!args.options.force) {
42
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to permanently remove deleted container '${args.options.id || args.options.name}'?` });
43
+ if (!result) {
44
+ return;
45
+ }
46
+ }
47
+ try {
48
+ const containerId = await this.getContainerId(args.options, logger);
49
+ if (this.verbose) {
50
+ await logger.logToStderr(`Permanently removing deleted container with ID '${containerId}'...`);
51
+ }
52
+ const requestOptions = {
53
+ url: `${this.resource}/v1.0/storage/fileStorage/deletedContainers/${containerId}`,
54
+ headers: {
55
+ accept: 'application/json;odata.metadata=none'
56
+ },
57
+ responseType: 'json'
58
+ };
59
+ await request.delete(requestOptions);
60
+ }
61
+ catch (err) {
62
+ this.handleRejectedODataJsonPromise(err);
63
+ }
64
+ }
65
+ async getContainerId(options, logger) {
66
+ if (options.id) {
67
+ return options.id;
68
+ }
69
+ if (this.verbose) {
70
+ await logger.logToStderr(`Retrieving container with name '${options.name}'...`);
71
+ }
72
+ const containerTypeId = await this.getContainerTypeId(options, logger);
73
+ const containers = await odata.getAllItems(`${this.resource}/v1.0/storage/fileStorage/deletedContainers?$filter=containerTypeId eq ${containerTypeId}&$select=id,displayName`);
74
+ const matchingContainers = containers.filter(c => c.displayName.toLowerCase() === options.name.toLowerCase());
75
+ if (matchingContainers.length === 0) {
76
+ throw new Error(`The specified container '${options.name}' does not exist.`);
77
+ }
78
+ if (matchingContainers.length > 1) {
79
+ const containerKeyValuePair = formatting.convertArrayToHashTable('id', matchingContainers);
80
+ const container = await cli.handleMultipleResultsFound(`Multiple containers with name '${options.name}' found.`, containerKeyValuePair);
81
+ return container.id;
82
+ }
83
+ return matchingContainers[0].id;
84
+ }
85
+ async getContainerTypeId(options, logger) {
86
+ if (options.containerTypeId) {
87
+ return options.containerTypeId;
88
+ }
89
+ if (this.verbose) {
90
+ await logger.logToStderr(`Getting container type with name '${options.containerTypeName}'...`);
91
+ }
92
+ return spe.getContainerTypeIdByName(options.containerTypeName);
93
+ }
94
+ }
95
+ export default new SpeContainerRecycleBinItemRemoveCommand();
96
+ //# sourceMappingURL=container-recyclebinitem-remove.js.map
@@ -7,6 +7,7 @@ export default {
7
7
  CONTAINER_REMOVE: `${prefix} container remove`,
8
8
  CONTAINER_PERMISSION_LIST: `${prefix} container permission list`,
9
9
  CONTAINER_RECYCLEBINITEM_LIST: `${prefix} container recyclebinitem list`,
10
+ CONTAINER_RECYCLEBINITEM_REMOVE: `${prefix} container recyclebinitem remove`,
10
11
  CONTAINER_RECYCLEBINITEM_RESTORE: `${prefix} container recyclebinitem restore`,
11
12
  CONTAINERTYPE_ADD: `${prefix} containertype add`,
12
13
  CONTAINERTYPE_GET: `${prefix} containertype get`,
@@ -39,14 +39,38 @@ class SpoFileAddCommand extends SpoCommand {
39
39
  async commandAction(logger, args) {
40
40
  const folderPath = urlUtil.getServerRelativePath(args.options.webUrl, args.options.folder);
41
41
  const fullPath = path.resolve(args.options.path);
42
- const fileName = fsUtil.getSafeFileName(path.basename(fullPath));
42
+ const fileName = fsUtil.getSafeFileName(args.options.fileName ?? path.basename(fullPath));
43
43
  let isCheckedOut = false;
44
44
  let listSettings;
45
45
  if (this.verbose) {
46
46
  await logger.logToStderr(`file name: ${fileName}...`);
47
47
  await logger.logToStderr(`folder path: ${folderPath}...`);
48
48
  }
49
+ if (args.options.overwrite === undefined) {
50
+ await this.warn(logger, 'In the next major version, the --overwrite option will default to false. To avoid this warning, please set the --overwrite option explicitly to true or false.');
51
+ }
49
52
  try {
53
+ if (args.options.overwrite === false) {
54
+ try {
55
+ const requestOptions = {
56
+ url: `${args.options.webUrl}/_api/Web/GetFileByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(folderPath + '/' + fileName)}')?$select=Exists`,
57
+ headers: {
58
+ accept: 'application/json;odata=nometadata'
59
+ },
60
+ responseType: 'json'
61
+ };
62
+ await request.get(requestOptions);
63
+ throw `File '${fileName}' already exists in folder '${folderPath}'. To overwrite the file, use the --overwrite option.`;
64
+ }
65
+ catch (err) {
66
+ if (typeof err === 'string') {
67
+ throw err;
68
+ }
69
+ if (this.verbose) {
70
+ await logger.logToStderr(`File '${fileName}' does not exist in folder '${folderPath}'. Proceeding with upload.`);
71
+ }
72
+ }
73
+ }
50
74
  try {
51
75
  if (this.verbose) {
52
76
  await logger.logToStderr('Check if the specified folder exists.');
@@ -78,6 +102,7 @@ class SpoFileAddCommand extends SpoCommand {
78
102
  if (this.verbose) {
79
103
  await logger.logToStderr(`File size is ${fileSize} bytes`);
80
104
  }
105
+ let fileUploadResult;
81
106
  // only up to 250 MB are allowed in a single request
82
107
  if (fileSize > this.fileChunkingThreshold) {
83
108
  const fileChunkCount = Math.ceil(fileSize / this.fileChunkSize);
@@ -106,7 +131,7 @@ class SpoFileAddCommand extends SpoCommand {
106
131
  Size: fileSize
107
132
  };
108
133
  try {
109
- await this.uploadFileChunks(fileUploadInfo, logger);
134
+ fileUploadResult = await this.uploadFileChunks(fileUploadInfo, logger);
110
135
  if (this.verbose) {
111
136
  await logger.logToStderr(`Finished uploading ${fileUploadInfo.Position} bytes in ${fileChunkCount} chunks`);
112
137
  }
@@ -127,7 +152,7 @@ class SpoFileAddCommand extends SpoCommand {
127
152
  throw err;
128
153
  }
129
154
  catch (err) {
130
- if (this.debug) {
155
+ if (this.verbose) {
131
156
  await logger.logToStderr(`Failed to cancel upload session: ${err}`);
132
157
  }
133
158
  throw err;
@@ -145,9 +170,10 @@ class SpoFileAddCommand extends SpoCommand {
145
170
  accept: 'application/json;odata=nometadata',
146
171
  'content-length': bodyLength
147
172
  },
148
- maxBodyLength: this.fileChunkingThreshold
173
+ maxBodyLength: this.fileChunkingThreshold,
174
+ responseType: 'json'
149
175
  };
150
- await request.post(requestOptions);
176
+ fileUploadResult = await request.post(requestOptions);
151
177
  }
152
178
  if (args.options.contentType || args.options.publish || args.options.approve) {
153
179
  listSettings = await this.getFileParentList(fileName, args.options.webUrl, folderPath, logger);
@@ -206,6 +232,7 @@ class SpoFileAddCommand extends SpoCommand {
206
232
  };
207
233
  await request.post(requestOptions);
208
234
  }
235
+ await logger.log(fileUploadResult);
209
236
  }
210
237
  catch (err) {
211
238
  if (isCheckedOut) {
@@ -292,15 +319,16 @@ class SpoFileAddCommand extends SpoCommand {
292
319
  accept: 'application/json;odata=nometadata',
293
320
  'content-length': readCount
294
321
  },
295
- maxBodyLength: this.fileChunkingThreshold
322
+ maxBodyLength: this.fileChunkingThreshold,
323
+ responseType: 'json'
296
324
  };
297
325
  try {
298
- await request.post(requestOptions);
326
+ const uploadResponse = await request.post(requestOptions);
299
327
  if (this.verbose) {
300
328
  await logger.logToStderr(`Uploaded ${info.Position} of ${info.Size} bytes (${Math.round(100 * info.Position / info.Size)}%)`);
301
329
  }
302
330
  if (isLastChunk) {
303
- return;
331
+ return uploadResponse;
304
332
  }
305
333
  else {
306
334
  return this.uploadFileChunks(info, logger);
@@ -407,9 +435,12 @@ class SpoFileAddCommand extends SpoCommand {
407
435
  'approveComment',
408
436
  'publish',
409
437
  'publishComment',
438
+ 'overwrite',
439
+ 'fileName',
410
440
  'debug',
411
441
  'verbose',
412
442
  'output',
443
+ 'query',
413
444
  '_',
414
445
  'u',
415
446
  'p',
@@ -434,7 +465,9 @@ _SpoFileAddCommand_instances = new WeakSet(), _SpoFileAddCommand_initTelemetry =
434
465
  approve: !!args.options.approve,
435
466
  approveComment: typeof args.options.approveComment !== 'undefined',
436
467
  publish: !!args.options.publish,
437
- publishComment: typeof args.options.publishComment !== 'undefined'
468
+ publishComment: typeof args.options.publishComment !== 'undefined',
469
+ overwrite: !!args.options.overwrite,
470
+ fileName: typeof args.options.fileName !== 'undefined'
438
471
  });
439
472
  });
440
473
  }, _SpoFileAddCommand_initOptions = function _SpoFileAddCommand_initOptions() {
@@ -458,6 +491,11 @@ _SpoFileAddCommand_instances = new WeakSet(), _SpoFileAddCommand_initTelemetry =
458
491
  option: '--publish'
459
492
  }, {
460
493
  option: '--publishComment [publishComment]'
494
+ }, {
495
+ option: '--overwrite [overwrite]',
496
+ autocomplete: ['true', 'false']
497
+ }, {
498
+ option: '--fileName [fileName]'
461
499
  });
462
500
  }, _SpoFileAddCommand_initValidators = function _SpoFileAddCommand_initValidators() {
463
501
  this.validators.push(async (args) => {
@@ -477,8 +515,8 @@ _SpoFileAddCommand_instances = new WeakSet(), _SpoFileAddCommand_initTelemetry =
477
515
  return true;
478
516
  });
479
517
  }, _SpoFileAddCommand_initTypes = function _SpoFileAddCommand_initTypes() {
480
- this.types.string.push('webUrl', 'folder', 'path', 'contentType', 'checkInComment', 'approveComment', 'publishComment');
481
- this.types.boolean.push('checkOut', 'approve', 'publish');
518
+ this.types.string.push('webUrl', 'folder', 'path', 'contentType', 'checkInComment', 'approveComment', 'publishComment', 'fileName');
519
+ this.types.boolean.push('checkOut', 'approve', 'publish', 'overwrite');
482
520
  };
483
521
  export default new SpoFileAddCommand();
484
522
  //# sourceMappingURL=file-add.js.map
@@ -85,7 +85,7 @@ class SpoListItemSetCommand extends SpoCommand {
85
85
  }
86
86
  const properties = this.mapRequestBody(args.options);
87
87
  const item = args.options.systemUpdate ?
88
- await spo.systemUpdateListItem(requestUrl, args.options.id, logger, this.verbose, properties, contentTypeName)
88
+ await spo.systemUpdateListItem(requestUrl, +args.options.id, logger, this.verbose, properties, contentTypeName)
89
89
  : await spo.updateListItem(requestUrl, args.options.id, properties, contentTypeName);
90
90
  delete item.ID;
91
91
  await logger.log(item);
@@ -3,7 +3,8 @@ 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 _SpoPageHeaderSetCommand_instances, _SpoPageHeaderSetCommand_initTelemetry, _SpoPageHeaderSetCommand_initOptions, _SpoPageHeaderSetCommand_initValidators;
6
+ var _SpoPageHeaderSetCommand_instances, _SpoPageHeaderSetCommand_initTelemetry, _SpoPageHeaderSetCommand_initOptions, _SpoPageHeaderSetCommand_initValidators, _SpoPageHeaderSetCommand_initTypes;
7
+ import { CommandError } from '../../../../Command.js';
7
8
  import request from '../../../../request.js';
8
9
  import { formatting } from '../../../../utils/formatting.js';
9
10
  import { spo } from '../../../../utils/spo.js';
@@ -25,98 +26,102 @@ class SpoPageHeaderSetCommand extends SpoCommand {
25
26
  __classPrivateFieldGet(this, _SpoPageHeaderSetCommand_instances, "m", _SpoPageHeaderSetCommand_initTelemetry).call(this);
26
27
  __classPrivateFieldGet(this, _SpoPageHeaderSetCommand_instances, "m", _SpoPageHeaderSetCommand_initOptions).call(this);
27
28
  __classPrivateFieldGet(this, _SpoPageHeaderSetCommand_instances, "m", _SpoPageHeaderSetCommand_initValidators).call(this);
29
+ __classPrivateFieldGet(this, _SpoPageHeaderSetCommand_instances, "m", _SpoPageHeaderSetCommand_initTypes).call(this);
28
30
  }
29
31
  getExcludedOptionsWithUrls() {
30
32
  return ['imageUrl'];
31
33
  }
32
34
  async commandAction(logger, args) {
33
35
  const noPageHeader = {
34
- "id": BannerWebPartId,
35
- "instanceId": BannerWebPartId,
36
- "title": "Title Region",
37
- "description": "Title Region Description",
38
- "serverProcessedContent": {
39
- "htmlStrings": {},
40
- "searchablePlainTexts": {},
41
- "imageSources": {},
42
- "links": {}
36
+ id: BannerWebPartId,
37
+ instanceId: BannerWebPartId,
38
+ title: 'Title Region',
39
+ description: 'Title Region Description',
40
+ serverProcessedContent: {
41
+ htmlStrings: {},
42
+ searchablePlainTexts: {},
43
+ imageSources: {},
44
+ links: {}
43
45
  },
44
- "dataVersion": "1.4",
45
- "properties": {
46
- "title": "",
47
- "imageSourceType": 4,
48
- "layoutType": "NoImage",
49
- "textAlignment": "Left",
50
- "showTopicHeader": false,
51
- "showPublishDate": false,
52
- "topicHeader": ""
46
+ dataVersion: '1.4',
47
+ properties: {
48
+ title: '',
49
+ imageSourceType: 4,
50
+ layoutType: 'NoImage',
51
+ textAlignment: 'Left',
52
+ showTopicHeader: false,
53
+ showPublishDate: false,
54
+ showTimeToRead: false,
55
+ topicHeader: ''
53
56
  }
54
57
  };
55
58
  const defaultPageHeader = {
56
- "id": BannerWebPartId,
57
- "instanceId": BannerWebPartId,
58
- "title": "Title Region",
59
- "description": "Title Region Description",
60
- "serverProcessedContent": {
61
- "htmlStrings": {},
62
- "searchablePlainTexts": {},
63
- "imageSources": {},
64
- "links": {}
59
+ id: BannerWebPartId,
60
+ instanceId: BannerWebPartId,
61
+ title: 'Title Region',
62
+ description: 'Title Region Description',
63
+ serverProcessedContent: {
64
+ htmlStrings: {},
65
+ searchablePlainTexts: {},
66
+ imageSources: {},
67
+ links: {}
65
68
  },
66
- "dataVersion": "1.4",
67
- "properties": {
68
- "title": "",
69
- "imageSourceType": 4,
70
- "layoutType": "FullWidthImage",
71
- "textAlignment": "Left",
72
- "showTopicHeader": false,
73
- "showPublishDate": false,
74
- "topicHeader": ""
69
+ dataVersion: '1.4',
70
+ properties: {
71
+ title: '',
72
+ imageSourceType: 4,
73
+ layoutType: 'FullWidthImage',
74
+ textAlignment: 'Left',
75
+ showTopicHeader: false,
76
+ showPublishDate: false,
77
+ showTimeToRead: false,
78
+ topicHeader: ''
75
79
  }
76
80
  };
77
81
  const customPageHeader = {
78
- "id": BannerWebPartId,
79
- "instanceId": BannerWebPartId,
80
- "title": "Title Region",
81
- "description": "Title Region Description",
82
- "serverProcessedContent": {
83
- "htmlStrings": {},
84
- "searchablePlainTexts": {},
85
- "imageSources": {
86
- "imageSource": ""
82
+ id: BannerWebPartId,
83
+ instanceId: BannerWebPartId,
84
+ title: 'Title Region',
85
+ description: 'Title Region Description',
86
+ serverProcessedContent: {
87
+ htmlStrings: {},
88
+ searchablePlainTexts: {},
89
+ imageSources: {
90
+ imageSource: ''
87
91
  },
88
- "links": {},
89
- "customMetadata": {
90
- "imageSource": {
91
- "siteId": "",
92
- "webId": "",
93
- "listId": "",
94
- "uniqueId": ""
92
+ links: {},
93
+ customMetadata: {
94
+ imageSource: {
95
+ siteId: '',
96
+ webId: '',
97
+ listId: '',
98
+ uniqueId: ''
95
99
  }
96
100
  }
97
101
  },
98
- "dataVersion": "1.4",
99
- "properties": {
100
- "title": "",
101
- "imageSourceType": 2,
102
- "layoutType": "FullWidthImage",
103
- "textAlignment": "Left",
104
- "showTopicHeader": false,
105
- "showPublishDate": false,
106
- "topicHeader": "",
107
- "authors": [],
108
- "altText": "",
109
- "webId": "",
110
- "siteId": "",
111
- "listId": "",
112
- "uniqueId": "",
113
- "translateX": 0,
114
- "translateY": 0
102
+ dataVersion: '1.4',
103
+ properties: {
104
+ title: '',
105
+ imageSourceType: 2,
106
+ layoutType: 'FullWidthImage',
107
+ textAlignment: 'Left',
108
+ showTopicHeader: false,
109
+ showPublishDate: false,
110
+ showTimeToRead: false,
111
+ topicHeader: '',
112
+ authors: [],
113
+ altText: '',
114
+ webId: '',
115
+ siteId: '',
116
+ listId: '',
117
+ uniqueId: '',
118
+ translateX: 0,
119
+ translateY: 0
115
120
  }
116
121
  };
117
122
  let header = defaultPageHeader;
118
123
  let pageFullName = args.options.pageName.toLowerCase();
119
- if (pageFullName.indexOf('.aspx') < 0) {
124
+ if (!pageFullName.endsWith('.aspx')) {
120
125
  pageFullName += '.aspx';
121
126
  }
122
127
  let canvasContent = "";
@@ -132,7 +137,7 @@ class SpoPageHeaderSetCommand extends SpoCommand {
132
137
  let requestOptions = {
133
138
  url: `${args.options.webUrl}/_api/sitepages/pages/GetByUrl('sitepages/${formatting.encodeQueryParameter(pageFullName)}')?$select=IsPageCheckedOutToCurrentUser,Title`,
134
139
  headers: {
135
- 'accept': 'application/json;odata=nometadata'
140
+ accept: 'application/json;odata=nometadata'
136
141
  },
137
142
  responseType: 'json'
138
143
  };
@@ -143,7 +148,7 @@ class SpoPageHeaderSetCommand extends SpoCommand {
143
148
  const requestOptions = {
144
149
  url: `${args.options.webUrl}/_api/sitepages/pages/GetByUrl('sitepages/${formatting.encodeQueryParameter(pageFullName)}')?$expand=ListItemAllFields`,
145
150
  headers: {
146
- 'accept': 'application/json;odata=nometadata'
151
+ accept: 'application/json;odata=nometadata'
147
152
  },
148
153
  responseType: 'json'
149
154
  };
@@ -186,6 +191,7 @@ class SpoPageHeaderSetCommand extends SpoCommand {
186
191
  header.properties.showTopicHeader = args.options.showTopicHeader || false;
187
192
  header.properties.topicHeader = args.options.topicHeader || '';
188
193
  header.properties.showPublishDate = args.options.showPublishDate || false;
194
+ header.properties.showTimeToRead = args.options.showTimeToRead || false;
189
195
  if (args.options.type !== 'None') {
190
196
  header.properties.layoutType = args.options.layout || 'FullWidthImage';
191
197
  }
@@ -298,6 +304,9 @@ class SpoPageHeaderSetCommand extends SpoCommand {
298
304
  return request.post(requestOptions);
299
305
  }
300
306
  catch (err) {
307
+ if (err.status === 404) {
308
+ throw new CommandError(`The specified page '${pageFullName}' does not exist.`);
309
+ }
301
310
  this.handleRejectedODataJsonPromise(err);
302
311
  }
303
312
  }
@@ -323,8 +332,9 @@ _SpoPageHeaderSetCommand_instances = new WeakSet(), _SpoPageHeaderSetCommand_ini
323
332
  imageUrl: typeof args.options.imageUrl !== 'undefined',
324
333
  topicHeader: typeof args.options.topicHeader !== 'undefined',
325
334
  layout: args.options.layout,
326
- showTopicHeader: args.options.showTopicHeader,
327
- showPublishDate: args.options.showPublishDate,
335
+ showTopicHeader: !!args.options.showTopicHeader,
336
+ showPublishDate: !!args.options.showPublishDate,
337
+ showTimeToRead: !!args.options.showTimeToRead,
328
338
  textAlignment: args.options.textAlignment,
329
339
  translateX: typeof args.options.translateX !== 'undefined',
330
340
  translateY: typeof args.options.translateY !== 'undefined',
@@ -354,9 +364,14 @@ _SpoPageHeaderSetCommand_instances = new WeakSet(), _SpoPageHeaderSetCommand_ini
354
364
  option: '--textAlignment [textAlignment]',
355
365
  autocomplete: ['Left', 'Center']
356
366
  }, {
357
- option: '--showTopicHeader'
367
+ option: '--showTopicHeader [showTopicHeader]',
368
+ autocomplete: ['true', 'false']
369
+ }, {
370
+ option: '--showPublishDate [showPublishDate]',
371
+ autocomplete: ['true', 'false']
358
372
  }, {
359
- option: '--showPublishDate'
373
+ option: '--showTimeToRead [showTimeToRead]',
374
+ autocomplete: ['true', 'false']
360
375
  }, {
361
376
  option: '--topicHeader [topicHeader]'
362
377
  }, {
@@ -364,10 +379,7 @@ _SpoPageHeaderSetCommand_instances = new WeakSet(), _SpoPageHeaderSetCommand_ini
364
379
  });
365
380
  }, _SpoPageHeaderSetCommand_initValidators = function _SpoPageHeaderSetCommand_initValidators() {
366
381
  this.validators.push(async (args) => {
367
- if (args.options.type &&
368
- args.options.type !== 'None' &&
369
- args.options.type !== 'Default' &&
370
- args.options.type !== 'Custom') {
382
+ if (args.options.type && !['None', 'Default', 'Custom'].includes(args.options.type)) {
371
383
  return `${args.options.type} is not a valid type value. Allowed values None|Default|Custom`;
372
384
  }
373
385
  if (args.options.translateX && isNaN(args.options.translateX)) {
@@ -376,20 +388,16 @@ _SpoPageHeaderSetCommand_instances = new WeakSet(), _SpoPageHeaderSetCommand_ini
376
388
  if (args.options.translateY && isNaN(args.options.translateY)) {
377
389
  return `${args.options.translateY} is not a valid number`;
378
390
  }
379
- if (args.options.layout &&
380
- args.options.layout !== 'FullWidthImage' &&
381
- args.options.layout !== 'NoImage' &&
382
- args.options.layout !== 'ColorBlock' &&
383
- args.options.layout !== 'CutInShape') {
391
+ if (args.options.layout && !['FullWidthImage', 'NoImage', 'ColorBlock', 'CutInShape'].includes(args.options.layout)) {
384
392
  return `${args.options.layout} is not a valid layout value. Allowed values FullWidthImage|NoImage|ColorBlock|CutInShape`;
385
393
  }
386
- if (args.options.textAlignment &&
387
- args.options.textAlignment !== 'Left' &&
388
- args.options.textAlignment !== 'Center') {
394
+ if (args.options.textAlignment && !['Left', 'Center'].includes(args.options.textAlignment)) {
389
395
  return `${args.options.textAlignment} is not a valid textAlignment value. Allowed values Left|Center`;
390
396
  }
391
397
  return validation.isValidSharePointUrl(args.options.webUrl);
392
398
  });
399
+ }, _SpoPageHeaderSetCommand_initTypes = function _SpoPageHeaderSetCommand_initTypes() {
400
+ this.types.boolean.push('showTimeToRead', 'showPublishDate', 'showTopicHeader');
393
401
  };
394
402
  export default new SpoPageHeaderSetCommand();
395
403
  //# sourceMappingURL=page-header-set.js.map