@pnp/cli-microsoft365 7.7.0-beta.d874bca → 7.8.0-beta.3152fc7

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.
@@ -19,14 +19,6 @@ var PackageSearchMode;
19
19
  PackageSearchMode[PackageSearchMode["GlobalOnly"] = 1] = "GlobalOnly";
20
20
  PackageSearchMode[PackageSearchMode["LocalAndGlobal"] = 2] = "LocalAndGlobal";
21
21
  })(PackageSearchMode || (PackageSearchMode = {}));
22
- /**
23
- * Is the particular check optional or required
24
- */
25
- var OptionalOrRequired;
26
- (function (OptionalOrRequired) {
27
- OptionalOrRequired[OptionalOrRequired["Optional"] = 0] = "Optional";
28
- OptionalOrRequired[OptionalOrRequired["Required"] = 1] = "Required";
29
- })(OptionalOrRequired || (OptionalOrRequired = {}));
30
22
  /**
31
23
  * Should the method continue or fail on a rejected Promise
32
24
  */
@@ -47,7 +39,7 @@ var SharePointVersion;
47
39
  })(SharePointVersion || (SharePointVersion = {}));
48
40
  class SpfxDoctorCommand extends BaseProjectCommand {
49
41
  get allowedOutputs() {
50
- return ['text'];
42
+ return ['text', 'json'];
51
43
  }
52
44
  get name() {
53
45
  return commands.DOCTOR;
@@ -585,6 +577,8 @@ class SpfxDoctorCommand extends BaseProjectCommand {
585
577
  }
586
578
  }
587
579
  };
580
+ this.output = '';
581
+ this.resultsObject = [];
588
582
  __classPrivateFieldGet(this, _SpfxDoctorCommand_instances, "m", _SpfxDoctorCommand_initTelemetry).call(this);
589
583
  __classPrivateFieldGet(this, _SpfxDoctorCommand_instances, "m", _SpfxDoctorCommand_initOptions).call(this);
590
584
  __classPrivateFieldGet(this, _SpfxDoctorCommand_instances, "m", _SpfxDoctorCommand_initValidators).call(this);
@@ -593,168 +587,265 @@ class SpfxDoctorCommand extends BaseProjectCommand {
593
587
  if (!args.options.output) {
594
588
  args.options.output = 'text';
595
589
  }
590
+ this.output = args.options.output;
596
591
  this.projectRootPath = this.getProjectRoot(process.cwd());
597
- await logger.log(' ');
598
- await logger.log('CLI for Microsoft 365 SharePoint Framework doctor');
599
- await logger.log('Verifying configuration of your system for working with the SharePoint Framework');
600
- await logger.log(' ');
592
+ this.logger = logger;
593
+ await this.logMessage(' ');
594
+ await this.logMessage('CLI for Microsoft 365 SharePoint Framework doctor');
595
+ await this.logMessage('Verifying configuration of your system for working with the SharePoint Framework');
596
+ await this.logMessage(' ');
601
597
  let spfxVersion = '';
602
598
  let prerequisites;
603
- const fixes = [];
604
599
  try {
605
- spfxVersion = args.options.spfxVersion ?? await this.getSharePointFrameworkVersion(logger);
600
+ spfxVersion = args.options.spfxVersion ?? await this.getSharePointFrameworkVersion();
606
601
  if (!spfxVersion) {
607
- await logger.log(formatting.getStatus(CheckStatus.Failure, `SharePoint Framework`));
602
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, `SharePoint Framework`));
603
+ this.resultsObject.push({
604
+ check: 'SharePoint Framework',
605
+ passed: false,
606
+ message: `SharePoint Framework not found`
607
+ });
608
608
  throw `SharePoint Framework not found`;
609
609
  }
610
610
  prerequisites = this.versions[spfxVersion];
611
611
  if (!prerequisites) {
612
- await logger.log(formatting.getStatus(CheckStatus.Failure, `SharePoint Framework v${spfxVersion}`));
613
- throw `spfx doctor doesn't support SPFx v${spfxVersion} at this moment`;
612
+ const message = `spfx doctor doesn't support SPFx v${spfxVersion} at this moment`;
613
+ this.resultsObject.push({
614
+ check: 'SharePoint Framework',
615
+ passed: true,
616
+ version: spfxVersion,
617
+ message: message
618
+ });
619
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, `SharePoint Framework v${spfxVersion}`));
620
+ throw message;
621
+ }
622
+ else {
623
+ this.resultsObject.push({
624
+ check: 'SharePoint Framework',
625
+ passed: true,
626
+ version: spfxVersion,
627
+ message: `SharePoint Framework v${spfxVersion} valid.`
628
+ });
614
629
  }
615
630
  if (args.options.spfxVersion) {
616
- await this.checkSharePointFrameworkVersion(args.options.spfxVersion, fixes, logger);
631
+ await this.checkSharePointFrameworkVersion(args.options.spfxVersion);
617
632
  }
618
633
  else {
619
634
  // spfx was detected and if we are here, it means that we support it
620
- await logger.log(formatting.getStatus(CheckStatus.Success, `SharePoint Framework v${spfxVersion}`));
635
+ const message = `SharePoint Framework v${spfxVersion}`;
636
+ this.resultsObject.push({
637
+ check: 'SharePoint Framework',
638
+ passed: true,
639
+ version: spfxVersion,
640
+ message: message
641
+ });
642
+ await this.logMessage(formatting.getStatus(CheckStatus.Success, message));
621
643
  }
622
- await this.checkSharePointCompatibility(spfxVersion, prerequisites, args, fixes, logger);
623
- await this.checkNodeVersion(prerequisites, fixes, logger);
624
- await this.checkYo(prerequisites, fixes, logger);
625
- await this.checkGulp(fixes, logger);
626
- await this.checkGulpCli(prerequisites, fixes, logger);
627
- await this.checkTypeScript(fixes, logger);
628
- if (fixes.length > 0) {
629
- await logger.log(' ');
630
- await logger.log('Recommended fixes:');
631
- await logger.log(' ');
632
- for (const f of fixes) {
633
- await logger.log(`- ${f}`);
634
- }
635
- await logger.log(' ');
644
+ await this.checkSharePointCompatibility(spfxVersion, prerequisites, args);
645
+ await this.checkNodeVersion(prerequisites);
646
+ await this.checkYo(prerequisites);
647
+ await this.checkGulp();
648
+ await this.checkGulpCli(prerequisites);
649
+ await this.checkTypeScript();
650
+ if (this.resultsObject.some(y => y.fix !== undefined)) {
651
+ await this.logMessage('Recommended fixes:');
652
+ await this.logMessage(' ');
653
+ for (const f of this.resultsObject.filter(y => y.fix !== undefined)) {
654
+ await this.logMessage(`- ${f.fix}`);
655
+ }
656
+ await this.logMessage(' ');
636
657
  }
637
658
  }
638
659
  catch (err) {
639
- await logger.log(' ');
640
- if (fixes.length > 0) {
641
- await logger.log('Recommended fixes:');
642
- await logger.log(' ');
643
- for (const f of fixes) {
644
- await logger.log(`- ${f}`);
645
- }
646
- await logger.log(' ');
660
+ await this.logMessage(' ');
661
+ if (this.resultsObject.some(y => y.fix !== undefined)) {
662
+ await this.logMessage('Recommended fixes:');
663
+ await this.logMessage(' ');
664
+ for (const f of this.resultsObject.filter(y => y.fix !== undefined)) {
665
+ await this.logMessage(`- ${f.fix}`);
666
+ }
667
+ await this.logMessage(' ');
668
+ }
669
+ if (this.output === 'text') {
670
+ this.handleRejectedPromise(err);
647
671
  }
648
- this.handleRejectedPromise(err);
672
+ }
673
+ finally {
674
+ if (args.options.output === 'json' && this.resultsObject.length > 0) {
675
+ await logger.log(this.resultsObject);
676
+ }
677
+ }
678
+ }
679
+ async logMessage(message) {
680
+ if (this.output === 'json') {
681
+ await this.logger.logToStderr(message);
682
+ }
683
+ else {
684
+ await this.logger.log(message);
649
685
  }
650
686
  }
651
- async checkSharePointCompatibility(spfxVersion, prerequisites, args, fixes, logger) {
687
+ async checkSharePointCompatibility(spfxVersion, prerequisites, args) {
652
688
  if (args.options.env) {
653
689
  const sp = this.spVersionStringToEnum(args.options.env);
654
690
  if ((prerequisites.sp & sp) === sp) {
655
- await logger.log(formatting.getStatus(CheckStatus.Success, `Supported in ${SharePointVersion[sp]}`));
691
+ const message = `Supported in ${SharePointVersion[sp]}`;
692
+ this.resultsObject.push({
693
+ check: 'env',
694
+ passed: true,
695
+ message: message,
696
+ version: args.options.env
697
+ });
698
+ await this.logMessage(formatting.getStatus(CheckStatus.Success, message));
656
699
  return;
657
700
  }
658
- await logger.log(formatting.getStatus(CheckStatus.Failure, `Not supported in ${SharePointVersion[sp]}`));
659
- fixes.push(`Use SharePoint Framework v${(sp === SharePointVersion.SP2016 ? '1.1' : '1.4.1')}`);
701
+ const fix = `Use SharePoint Framework v${(sp === SharePointVersion.SP2016 ? '1.1' : '1.4.1')}`;
702
+ const message = `Not supported in ${SharePointVersion[sp]}`;
703
+ this.resultsObject.push({
704
+ check: 'env',
705
+ passed: false,
706
+ fix: fix,
707
+ message: message,
708
+ version: args.options.env
709
+ });
710
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
660
711
  throw `SharePoint Framework v${spfxVersion} is not supported in ${SharePointVersion[sp]}`;
661
712
  }
662
713
  }
663
- async checkNodeVersion(prerequisites, fixes, logger) {
714
+ async checkNodeVersion(prerequisites) {
664
715
  const nodeVersion = this.getNodeVersion();
665
- this.checkStatus('Node', nodeVersion, prerequisites.node, OptionalOrRequired.Required, fixes, logger);
716
+ this.checkStatus('Node', nodeVersion, prerequisites.node);
666
717
  }
667
- async checkSharePointFrameworkVersion(spfxVersionRequested, fixes, logger) {
668
- let spfxVersionDetected = await this.getSPFxVersionFromYoRcFile(logger);
718
+ async checkSharePointFrameworkVersion(spfxVersionRequested) {
719
+ let spfxVersionDetected = await this.getSPFxVersionFromYoRcFile();
669
720
  if (!spfxVersionDetected) {
670
- spfxVersionDetected = await this.getPackageVersion('@microsoft/generator-sharepoint', PackageSearchMode.GlobalOnly, HandlePromise.Continue, logger);
721
+ spfxVersionDetected = await this.getPackageVersion('@microsoft/generator-sharepoint', PackageSearchMode.GlobalOnly, HandlePromise.Continue);
671
722
  }
672
723
  const versionCheck = {
673
724
  range: spfxVersionRequested,
674
725
  fix: `npm i -g @microsoft/generator-sharepoint@${spfxVersionRequested}`
675
726
  };
676
727
  if (spfxVersionDetected) {
677
- this.checkStatus(`SharePoint Framework`, spfxVersionDetected, versionCheck, OptionalOrRequired.Required, fixes, logger);
728
+ this.checkStatus(`SharePoint Framework`, spfxVersionDetected, versionCheck);
678
729
  }
679
730
  else {
680
- await logger.log(formatting.getStatus(CheckStatus.Failure, `SharePoint Framework v${spfxVersionRequested} not found`));
681
- fixes.push(versionCheck.fix);
731
+ const message = `SharePoint Framework v${spfxVersionRequested} not found`;
732
+ this.resultsObject.push({
733
+ check: 'SharePoint Framework',
734
+ passed: false,
735
+ version: spfxVersionRequested,
736
+ message: message,
737
+ fix: versionCheck.fix
738
+ });
739
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
682
740
  }
683
741
  }
684
- async checkYo(prerequisites, fixes, logger) {
685
- const yoVersion = await this.getPackageVersion('yo', PackageSearchMode.GlobalOnly, HandlePromise.Continue, logger);
742
+ async checkYo(prerequisites) {
743
+ const yoVersion = await this.getPackageVersion('yo', PackageSearchMode.GlobalOnly, HandlePromise.Continue);
686
744
  if (yoVersion) {
687
- this.checkStatus('yo', yoVersion, prerequisites.yo, OptionalOrRequired.Required, fixes, logger);
745
+ this.checkStatus('yo', yoVersion, prerequisites.yo);
688
746
  }
689
747
  else {
690
- await logger.log(formatting.getStatus(CheckStatus.Failure, `yo not found`));
691
- fixes.push(prerequisites.yo.fix);
748
+ const message = 'yo not found';
749
+ this.resultsObject.push({
750
+ check: 'yo',
751
+ passed: false,
752
+ message: message,
753
+ fix: prerequisites.yo.fix
754
+ });
755
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
692
756
  }
693
757
  }
694
- async checkGulpCli(prerequisites, fixes, logger) {
695
- const gulpCliVersion = await this.getPackageVersion('gulp-cli', PackageSearchMode.GlobalOnly, HandlePromise.Continue, logger);
758
+ async checkGulpCli(prerequisites) {
759
+ const gulpCliVersion = await this.getPackageVersion('gulp-cli', PackageSearchMode.GlobalOnly, HandlePromise.Continue);
696
760
  if (gulpCliVersion) {
697
- this.checkStatus('gulp-cli', gulpCliVersion, prerequisites.gulpCli, OptionalOrRequired.Required, fixes, logger);
761
+ this.checkStatus('gulp-cli', gulpCliVersion, prerequisites.gulpCli);
698
762
  }
699
763
  else {
700
- await logger.log(formatting.getStatus(CheckStatus.Failure, `gulp-cli not found`));
701
- fixes.push(prerequisites.gulpCli.fix);
764
+ const message = 'gulp-cli not found';
765
+ this.resultsObject.push({
766
+ check: 'gulp-cli',
767
+ passed: false,
768
+ message: message,
769
+ fix: prerequisites.gulpCli.fix
770
+ });
771
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
702
772
  }
703
773
  }
704
- async checkGulp(fixes, logger) {
705
- const gulpVersion = await this.getPackageVersion('gulp', PackageSearchMode.GlobalOnly, HandlePromise.Continue, logger);
774
+ async checkGulp() {
775
+ const gulpVersion = await this.getPackageVersion('gulp', PackageSearchMode.GlobalOnly, HandlePromise.Continue);
706
776
  if (gulpVersion) {
707
- await logger.log(formatting.getStatus(CheckStatus.Failure, `gulp should be removed`));
708
- fixes.push('npm un -g gulp');
777
+ const message = 'gulp should be removed';
778
+ const fix = 'npm un -g gulp';
779
+ this.resultsObject.push({
780
+ check: 'gulp',
781
+ passed: false,
782
+ version: gulpVersion,
783
+ message: message,
784
+ fix: fix
785
+ });
786
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
709
787
  }
710
788
  }
711
- async checkTypeScript(fixes, logger) {
712
- const typeScriptVersion = await this.getPackageVersion('typescript', PackageSearchMode.LocalOnly, HandlePromise.Continue, logger);
789
+ async checkTypeScript() {
790
+ const typeScriptVersion = await this.getPackageVersion('typescript', PackageSearchMode.LocalOnly, HandlePromise.Continue);
713
791
  if (typeScriptVersion) {
714
- await logger.log(formatting.getStatus(CheckStatus.Failure, `typescript v${typeScriptVersion} installed in the project`));
715
- fixes.push('npm un typescript');
792
+ const fix = 'npm un typescript';
793
+ const message = `typescript v${typeScriptVersion} installed in the project`;
794
+ this.resultsObject.push({
795
+ check: 'typescript',
796
+ passed: false,
797
+ message: message,
798
+ fix: fix
799
+ });
800
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
716
801
  }
717
802
  else {
718
- await logger.log(formatting.getStatus(CheckStatus.Success, `bundled typescript used`));
803
+ const message = 'bundled typescript used';
804
+ this.resultsObject.push({
805
+ check: 'typescript',
806
+ passed: true,
807
+ message: message
808
+ });
809
+ await this.logMessage(formatting.getStatus(CheckStatus.Success, message));
719
810
  }
720
811
  }
721
812
  spVersionStringToEnum(sp) {
722
813
  return SharePointVersion[sp.toUpperCase()];
723
814
  }
724
- async getSPFxVersionFromYoRcFile(logger) {
815
+ async getSPFxVersionFromYoRcFile() {
725
816
  if (this.projectRootPath !== null) {
726
817
  const spfxVersion = this.getProjectVersion();
727
818
  if (spfxVersion) {
728
819
  if (this.debug) {
729
- await logger.logToStderr(`SPFx version retrieved from .yo-rc.json file. Retrieved version: ${spfxVersion}`);
820
+ await this.logger.logToStderr(`SPFx version retrieved from .yo-rc.json file. Retrieved version: ${spfxVersion}`);
730
821
  }
731
822
  return spfxVersion;
732
823
  }
733
824
  }
734
825
  return undefined;
735
826
  }
736
- async getSharePointFrameworkVersion(logger) {
737
- let spfxVersion = await this.getSPFxVersionFromYoRcFile(logger);
827
+ async getSharePointFrameworkVersion() {
828
+ let spfxVersion = await this.getSPFxVersionFromYoRcFile();
738
829
  if (spfxVersion) {
739
830
  return spfxVersion;
740
831
  }
741
832
  try {
742
- spfxVersion = await this.getPackageVersion('@microsoft/sp-core-library', PackageSearchMode.LocalOnly, HandlePromise.Fail, logger);
833
+ spfxVersion = await this.getPackageVersion('@microsoft/sp-core-library', PackageSearchMode.LocalOnly, HandlePromise.Fail);
743
834
  if (this.debug) {
744
- await logger.logToStderr(`Found @microsoft/sp-core-library@${spfxVersion}`);
835
+ await this.logger.logToStderr(`Found @microsoft/sp-core-library@${spfxVersion}`);
745
836
  }
746
837
  return spfxVersion;
747
838
  }
748
839
  catch {
749
840
  if (this.debug) {
750
- await logger.logToStderr(`@microsoft/sp-core-library not found. Search for @microsoft/generator-sharepoint local or global...`);
841
+ await this.logger.logToStderr(`@microsoft/sp-core-library not found. Search for @microsoft/generator-sharepoint local or global...`);
751
842
  }
752
843
  try {
753
- return await this.getPackageVersion('@microsoft/generator-sharepoint', PackageSearchMode.LocalAndGlobal, HandlePromise.Fail, logger);
844
+ return await this.getPackageVersion('@microsoft/generator-sharepoint', PackageSearchMode.LocalAndGlobal, HandlePromise.Fail);
754
845
  }
755
846
  catch (error) {
756
847
  if (this.debug) {
757
- await logger.logToStderr('@microsoft/generator-sharepoint not found');
848
+ await this.logger.logToStderr('@microsoft/generator-sharepoint not found');
758
849
  }
759
850
  if (error && error.indexOf('ENOENT') > -1) {
760
851
  throw 'npm not found';
@@ -765,19 +856,19 @@ class SpfxDoctorCommand extends BaseProjectCommand {
765
856
  }
766
857
  }
767
858
  }
768
- async getPackageVersion(packageName, searchMode, handlePromise, logger) {
859
+ async getPackageVersion(packageName, searchMode, handlePromise) {
769
860
  const args = ['ls', packageName, '--depth=0', '--json'];
770
861
  if (searchMode === PackageSearchMode.GlobalOnly) {
771
862
  args.push('-g');
772
863
  }
773
864
  let version;
774
865
  try {
775
- version = await this.getPackageVersionFromNpm(args, logger);
866
+ version = await this.getPackageVersionFromNpm(args);
776
867
  }
777
868
  catch {
778
869
  if (searchMode === PackageSearchMode.LocalAndGlobal) {
779
870
  args.push('-g');
780
- version = await this.getPackageVersionFromNpm(args, logger);
871
+ version = await this.getPackageVersionFromNpm(args);
781
872
  }
782
873
  else {
783
874
  version = '';
@@ -795,11 +886,11 @@ class SpfxDoctorCommand extends BaseProjectCommand {
795
886
  }
796
887
  }
797
888
  }
798
- getPackageVersionFromNpm(args, logger) {
889
+ getPackageVersionFromNpm(args) {
799
890
  return new Promise(async (resolve, reject) => {
800
891
  const packageName = args[1];
801
892
  if (this.debug) {
802
- await logger.logToStderr(`Executing npm: ${args.join(' ')}...`);
893
+ await this.logger.logToStderr(`Executing npm: ${args.join(' ')}...`);
803
894
  }
804
895
  child_process.exec(`npm ${args.join(' ')}`, (err, stdout) => {
805
896
  if (err) {
@@ -825,14 +916,28 @@ class SpfxDoctorCommand extends BaseProjectCommand {
825
916
  getNodeVersion() {
826
917
  return process.version.substr(1);
827
918
  }
828
- async checkStatus(what, versionFound, versionCheck, optionalOrRequired, fixes, logger) {
919
+ async checkStatus(what, versionFound, versionCheck) {
829
920
  if (versionFound) {
830
921
  if (satisfies(versionFound, versionCheck.range)) {
831
- await logger.log(formatting.getStatus(CheckStatus.Success, `${what} v${versionFound}`));
922
+ const message = `${what} v${versionFound}`;
923
+ this.resultsObject.push({
924
+ check: what,
925
+ passed: true,
926
+ message: message,
927
+ version: versionFound
928
+ });
929
+ await this.logMessage(formatting.getStatus(CheckStatus.Success, message));
832
930
  }
833
931
  else {
834
- await logger.log(formatting.getStatus(CheckStatus.Failure, `${what} v${versionFound} found, v${versionCheck.range} required`));
835
- fixes.push(versionCheck.fix);
932
+ const message = `${what} v${versionFound} found, v${versionCheck.range} required`;
933
+ this.resultsObject.push({
934
+ check: what,
935
+ passed: false,
936
+ version: versionFound,
937
+ message: message,
938
+ fix: versionCheck.fix
939
+ });
940
+ await this.logMessage(formatting.getStatus(CheckStatus.Failure, message));
836
941
  }
837
942
  }
838
943
  }
@@ -4,8 +4,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _SpoListItemSetCommand_instances, _SpoListItemSetCommand_initTelemetry, _SpoListItemSetCommand_initOptions, _SpoListItemSetCommand_initValidators, _SpoListItemSetCommand_initTypes, _SpoListItemSetCommand_initOptionSets;
7
- import os from 'os';
8
- import config from '../../../../config.js';
9
7
  import request from '../../../../request.js';
10
8
  import { basic } from '../../../../utils/basic.js';
11
9
  import { formatting } from '../../../../utils/formatting.js';
@@ -35,11 +33,9 @@ class SpoListItemSetCommand extends SpoCommand {
35
33
  }
36
34
  async commandAction(logger, args) {
37
35
  let contentTypeName = '';
38
- let listId = '';
39
36
  try {
40
37
  let requestUrl = `${args.options.webUrl}/_api/web`;
41
38
  if (args.options.listId) {
42
- listId = args.options.listId;
43
39
  requestUrl += `/lists(guid'${formatting.encodeQueryParameter(args.options.listId)}')`;
44
40
  }
45
41
  else if (args.options.listTitle) {
@@ -49,20 +45,6 @@ class SpoListItemSetCommand extends SpoCommand {
49
45
  const listServerRelativeUrl = urlUtil.getServerRelativePath(args.options.webUrl, args.options.listUrl);
50
46
  requestUrl += `/GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')`;
51
47
  }
52
- if (args.options.systemUpdate && !args.options.listId) {
53
- if (this.verbose) {
54
- await logger.logToStderr(`Getting list id...`);
55
- }
56
- const listRequestOptions = {
57
- url: `${requestUrl}?$select=Id`,
58
- headers: {
59
- 'accept': 'application/json;odata=nometadata'
60
- },
61
- responseType: 'json'
62
- };
63
- const list = await request.get(listRequestOptions);
64
- listId = list.Id;
65
- }
66
48
  if (args.options.contentType) {
67
49
  if (this.verbose) {
68
50
  await logger.logToStderr(`Getting content types for list...`);
@@ -101,94 +83,10 @@ class SpoListItemSetCommand extends SpoCommand {
101
83
  await logger.logToStderr(`using content type name: ${contentTypeName}`);
102
84
  }
103
85
  }
104
- let res = undefined;
105
- if (args.options.systemUpdate) {
106
- if (this.debug) {
107
- await logger.logToStderr(`getting request digest for systemUpdate request`);
108
- }
109
- res = await spo.getRequestDigest(args.options.webUrl);
110
- }
111
- if (this.verbose) {
112
- await logger.logToStderr(`Updating item in list ${args.options.listId || args.options.listTitle || args.options.listUrl} in site ${args.options.webUrl}...`);
113
- }
114
- const formDigestValue = args.options.systemUpdate ? res['FormDigestValue'] : '';
115
- let objectIdentity = '';
116
- if (args.options.systemUpdate) {
117
- objectIdentity = await this.requestObjectIdentity(args.options.webUrl, logger, formDigestValue);
118
- }
119
- const additionalContentType = (args.options.systemUpdate && args.options.contentType && contentTypeName !== '') ? `
120
- <Method Name="ParseAndSetFieldValue" Id="1" ObjectPathId="147">
121
- <Parameters>
122
- <Parameter Type="String">ContentType</Parameter>
123
- <Parameter Type="String">${contentTypeName}</Parameter>
124
- </Parameters>
125
- </Method>`
126
- : ``;
127
- const requestBody = args.options.systemUpdate ?
128
- `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
129
- <Actions>
130
- ${this.mapRequestBody(args.options).join('')}${additionalContentType}
131
- <Method Name="SystemUpdate" Id="2" ObjectPathId="147" />
132
- </Actions>
133
- <ObjectPaths>
134
- <Identity Id="147" Name="${objectIdentity}:list:${listId}:item:${args.options.id},1" />
135
- </ObjectPaths>
136
- </Request>`
137
- : {
138
- formValues: this.mapRequestBody(args.options)
139
- };
140
- if (args.options.contentType && contentTypeName !== '' && !args.options.systemUpdate) {
141
- if (this.debug) {
142
- await logger.logToStderr(`Specifying content type name [${contentTypeName}] in request body`);
143
- }
144
- requestBody.formValues.push({
145
- FieldName: 'ContentType',
146
- FieldValue: contentTypeName
147
- });
148
- }
149
- const requestOptions = args.options.systemUpdate ?
150
- {
151
- url: `${args.options.webUrl}/_vti_bin/client.svc/ProcessQuery`,
152
- headers: {
153
- 'Content-Type': 'text/xml',
154
- 'X-RequestDigest': formDigestValue
155
- },
156
- data: requestBody
157
- } :
158
- {
159
- url: `${requestUrl}/items(${args.options.id})/ValidateUpdateListItem()`,
160
- headers: {
161
- 'accept': 'application/json;odata=nometadata'
162
- },
163
- data: requestBody,
164
- responseType: 'json'
165
- };
166
- const response = await request.post(requestOptions);
167
- let itemId = 0;
168
- if (args.options.systemUpdate) {
169
- if (response.indexOf("ErrorMessage") > -1) {
170
- throw `Error occurred in systemUpdate operation - ${response}`;
171
- }
172
- else {
173
- itemId = Number(args.options.id);
174
- }
175
- }
176
- else {
177
- // Response is from /ValidateUpdateListItem POST call, perform get on updated item to get all field values
178
- const fieldValues = response.value;
179
- if (fieldValues.some(f => f.HasException)) {
180
- throw `Updating the items has failed with the following errors: ${os.EOL}${fieldValues.filter(f => f.HasException).map(f => { return `- ${f.FieldName} - ${f.ErrorMessage}`; }).join(os.EOL)}`;
181
- }
182
- itemId = fieldValues[0].ItemId;
183
- }
184
- const requestOptionsItems = {
185
- url: `${requestUrl}/items(${itemId})`,
186
- headers: {
187
- 'accept': 'application/json;odata=nometadata'
188
- },
189
- responseType: 'json'
190
- };
191
- const item = await request.get(requestOptionsItems);
86
+ const properties = this.mapRequestBody(args.options);
87
+ const item = args.options.systemUpdate ?
88
+ await spo.systemUpdateListItem(requestUrl, args.options.id, logger, this.verbose, properties, contentTypeName)
89
+ : await spo.updateListItem(requestUrl, args.options.id, properties, contentTypeName);
192
90
  delete item.ID;
193
91
  await logger.log(item);
194
92
  }
@@ -197,7 +95,7 @@ class SpoListItemSetCommand extends SpoCommand {
197
95
  }
198
96
  }
199
97
  mapRequestBody(options) {
200
- const requestBody = [];
98
+ const filteredData = {};
201
99
  const excludeOptions = [
202
100
  'listTitle',
203
101
  'listId',
@@ -216,57 +114,12 @@ class SpoListItemSetCommand extends SpoCommand {
216
114
  't',
217
115
  '_'
218
116
  ];
219
- Object.keys(options).forEach(key => {
220
- if (excludeOptions.indexOf(key) === -1) {
221
- if (options.systemUpdate) {
222
- requestBody.push(`
223
- <Method Name="ParseAndSetFieldValue" Id="1" ObjectPathId="147">
224
- <Parameters>
225
- <Parameter Type="String">${key}</Parameter>
226
- <Parameter Type="String">${options[key].toString()}</Parameter>
227
- </Parameters>
228
- </Method>`);
229
- }
230
- else {
231
- requestBody.push({ FieldName: key, FieldValue: options[key].toString() });
232
- }
117
+ for (const key of Object.keys(options)) {
118
+ if (!excludeOptions.includes(key)) {
119
+ filteredData[key] = options[key];
233
120
  }
234
- });
235
- return requestBody;
236
- }
237
- /**
238
- * Requests web object identity for the current web.
239
- * This request has to be send before we can construct the property bag request.
240
- * The response data looks like:
241
- * _ObjectIdentity_=<GUID>|<GUID>:site:<GUID>:web:<GUID>
242
- * _ObjectType_=SP.Web
243
- * ServerRelativeUrl=/sites/contoso
244
- * The ObjectIdentity is needed to create another request to retrieve the property bag or set property.
245
- * @param webUrl web url
246
- * @param cmd command cmd
247
- */
248
- async requestObjectIdentity(webUrl, logger, formDigestValue) {
249
- const requestOptions = {
250
- url: `${webUrl}/_vti_bin/client.svc/ProcessQuery`,
251
- headers: {
252
- 'X-RequestDigest': formDigestValue
253
- },
254
- data: `<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><Query Id="1" ObjectPathId="5"><Query SelectAllProperties="false"><Properties><Property Name="ServerRelativeUrl" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Property Id="5" ParentId="3" Name="Web" /><StaticProperty Id="3" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`
255
- };
256
- const response = await request.post(requestOptions);
257
- if (this.debug) {
258
- await logger.logToStderr('Attempt to get _ObjectIdentity_ key values');
259
- }
260
- const json = JSON.parse(response);
261
- const contents = json.find(x => { return x['ErrorInfo']; });
262
- if (contents && contents.ErrorInfo) {
263
- throw contents.ErrorInfo.ErrorMessage || 'ClientSvc unknown error';
264
- }
265
- const identityObject = json.find(x => { return x['_ObjectIdentity_']; });
266
- if (identityObject) {
267
- return identityObject['_ObjectIdentity_'];
268
121
  }
269
- throw 'Cannot proceed. _ObjectIdentity_ not found'; // this is not supposed to happen
122
+ return filteredData;
270
123
  }
271
124
  }
272
125
  _SpoListItemSetCommand_instances = new WeakSet(), _SpoListItemSetCommand_initTelemetry = function _SpoListItemSetCommand_initTelemetry() {