@pnp/cli-microsoft365 6.0.0-beta.1254da3 → 6.0.0-beta.1cd4e45

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 (184) hide show
  1. package/dist/cli/Cli.js +7 -10
  2. package/dist/m365/aad/commands/app/app-get.js +3 -2
  3. package/dist/m365/aad/commands/app/app-remove.js +3 -2
  4. package/dist/m365/aad/commands/app/app-role-add.js +3 -2
  5. package/dist/m365/aad/commands/app/app-role-list.js +3 -2
  6. package/dist/m365/aad/commands/app/app-role-remove.js +3 -2
  7. package/dist/m365/aad/commands/app/app-set.js +3 -2
  8. package/dist/m365/aad/commands/approleassignment/approleassignment-add.js +5 -4
  9. package/dist/m365/aad/commands/approleassignment/approleassignment-list.js +3 -2
  10. package/dist/m365/aad/commands/approleassignment/approleassignment-remove.js +5 -4
  11. package/dist/m365/aad/commands/o365group/o365group-conversation-post-list.js +2 -1
  12. package/dist/m365/aad/commands/o365group/o365group-list.js +3 -2
  13. package/dist/m365/aad/commands/o365group/o365group-recyclebinitem-list.js +3 -2
  14. package/dist/m365/aad/commands/o365group/o365group-teamify.js +3 -2
  15. package/dist/m365/aad/commands/o365group/o365group-user-add.js +2 -1
  16. package/dist/m365/aad/commands/o365group/o365group-user-remove.js +2 -1
  17. package/dist/m365/aad/commands/oauth2grant/oauth2grant-list.js +2 -1
  18. package/dist/m365/aad/commands/oauth2grant/oauth2grant-remove.js +2 -1
  19. package/dist/m365/aad/commands/oauth2grant/oauth2grant-set.js +2 -1
  20. package/dist/m365/aad/commands/sp/sp-add.js +3 -2
  21. package/dist/m365/aad/commands/sp/sp-get.js +3 -2
  22. package/dist/m365/aad/commands/user/user-get.js +5 -4
  23. package/dist/m365/aad/commands/user/user-hibp.js +2 -1
  24. package/dist/m365/aad/commands/user/user-list.js +2 -1
  25. package/dist/m365/aad/commands/user/user-set.js +2 -1
  26. package/dist/m365/aad/commands/user/user-signin-list.js +5 -4
  27. package/dist/m365/base/DateAndPeriodBasedReport.js +3 -2
  28. package/dist/m365/base/PeriodBasedReport.js +2 -1
  29. package/dist/m365/booking/commands/business/business-get.js +2 -1
  30. package/dist/m365/cli/commands/config/config-set.js +1 -0
  31. package/dist/m365/file/commands/file-list.js +2 -1
  32. package/dist/m365/flow/commands/environment/environment-get.js +2 -1
  33. package/dist/m365/flow/commands/flow-disable.js +2 -1
  34. package/dist/m365/flow/commands/flow-enable.js +2 -1
  35. package/dist/m365/flow/commands/flow-export.js +5 -4
  36. package/dist/m365/flow/commands/flow-get.js +2 -1
  37. package/dist/m365/flow/commands/flow-list.js +2 -1
  38. package/dist/m365/flow/commands/flow-remove.js +2 -1
  39. package/dist/m365/flow/commands/run/run-cancel.js +2 -1
  40. package/dist/m365/flow/commands/run/run-get.js +2 -1
  41. package/dist/m365/flow/commands/run/run-list.js +2 -1
  42. package/dist/m365/flow/commands/run/run-resubmit.js +3 -2
  43. package/dist/m365/outlook/commands/mail/mail-send.js +2 -1
  44. package/dist/m365/outlook/commands/message/message-list.js +2 -1
  45. package/dist/m365/outlook/commands/message/message-move.js +2 -1
  46. package/dist/m365/pa/commands/app/app-get.js +2 -1
  47. package/dist/m365/pa/commands/app/app-list.js +2 -1
  48. package/dist/m365/pa/commands/app/app-remove.js +2 -1
  49. package/dist/m365/pa/commands/connector/connector-export.js +2 -1
  50. package/dist/m365/pa/commands/connector/connector-list.js +2 -1
  51. package/dist/m365/pa/commands/environment/environment-get.js +2 -1
  52. package/dist/m365/planner/commands/task/task-add.js +1 -1
  53. package/dist/m365/planner/commands/task/task-checklistitem-add.js +3 -2
  54. package/dist/m365/planner/commands/task/task-checklistitem-list.js +2 -1
  55. package/dist/m365/planner/commands/task/task-checklistitem-remove.js +2 -1
  56. package/dist/m365/planner/commands/task/task-get.js +2 -1
  57. package/dist/m365/planner/commands/task/task-list.js +4 -3
  58. package/dist/m365/planner/commands/task/task-reference-add.js +2 -2
  59. package/dist/m365/planner/commands/task/task-reference-list.js +2 -1
  60. package/dist/m365/planner/commands/task/task-reference-remove.js +1 -1
  61. package/dist/m365/planner/commands/task/task-set.js +2 -2
  62. package/dist/m365/pp/commands/gateway/gateway-get.js +2 -1
  63. package/dist/m365/pp/commands/managementapp/managementapp-add.js +3 -2
  64. package/dist/m365/pp/commands/solution/solution-list.js +5 -11
  65. package/dist/m365/search/commands/externalconnection/externalconnection-get.js +3 -2
  66. package/dist/m365/search/commands/externalconnection/externalconnection-remove.js +3 -2
  67. package/dist/m365/spo/commands/app/app-get.js +2 -1
  68. package/dist/m365/spo/commands/app/app-install.js +2 -1
  69. package/dist/m365/spo/commands/app/app-remove.js +2 -1
  70. package/dist/m365/spo/commands/app/app-retract.js +2 -1
  71. package/dist/m365/spo/commands/app/app-teamspackage-download.js +2 -1
  72. package/dist/m365/spo/commands/app/app-uninstall.js +2 -1
  73. package/dist/m365/spo/commands/app/app-upgrade.js +2 -1
  74. package/dist/m365/spo/commands/contenttype/contenttype-field-set.js +2 -2
  75. package/dist/m365/spo/commands/contenttype/contenttype-get.js +2 -2
  76. package/dist/m365/spo/commands/contenttype/contenttype-list.js +2 -1
  77. package/dist/m365/spo/commands/contenttype/contenttype-remove.js +3 -2
  78. package/dist/m365/spo/commands/customaction/customaction-get.js +3 -2
  79. package/dist/m365/spo/commands/customaction/customaction-remove.js +3 -2
  80. package/dist/m365/spo/commands/customaction/customaction-set.js +2 -1
  81. package/dist/m365/spo/commands/eventreceiver/eventreceiver-list.js +4 -3
  82. package/dist/m365/spo/commands/file/file-add.js +14 -13
  83. package/dist/m365/spo/commands/file/file-checkin.js +4 -3
  84. package/dist/m365/spo/commands/file/file-checkout.js +3 -2
  85. package/dist/m365/spo/commands/file/file-copy.js +2 -1
  86. package/dist/m365/spo/commands/file/file-get.js +3 -2
  87. package/dist/m365/spo/commands/file/file-move.js +2 -1
  88. package/dist/m365/spo/commands/file/file-remove.js +3 -2
  89. package/dist/m365/spo/commands/file/file-rename.js +3 -2
  90. package/dist/m365/spo/commands/file/file-sharinginfo-get.js +1 -1
  91. package/dist/m365/spo/commands/file/file-version-clear.js +114 -0
  92. package/dist/m365/spo/commands/file/file-version-get.js +104 -0
  93. package/dist/m365/spo/commands/file/file-version-list.js +1 -1
  94. package/dist/m365/spo/commands/file/file-version-remove.js +119 -0
  95. package/dist/m365/spo/commands/file/file-version-restore.js +119 -0
  96. package/dist/m365/spo/commands/folder/folder-get.js +3 -2
  97. package/dist/m365/spo/commands/folder/folder-remove.js +2 -1
  98. package/dist/m365/spo/commands/folder/folder-roleassignment-add.js +1 -1
  99. package/dist/m365/spo/commands/folder/folder-roleassignment-remove.js +2 -1
  100. package/dist/m365/spo/commands/folder/folder-roleinheritance-break.js +1 -1
  101. package/dist/m365/spo/commands/folder/folder-roleinheritance-reset.js +1 -1
  102. package/dist/m365/spo/commands/group/group-get.js +3 -2
  103. package/dist/m365/spo/commands/group/group-user-add.js +2 -1
  104. package/dist/m365/spo/commands/group/group-user-list.js +3 -2
  105. package/dist/m365/spo/commands/group/group-user-remove.js +3 -2
  106. package/dist/m365/spo/commands/list/list-contenttype-remove.js +1 -1
  107. package/dist/m365/spo/commands/list/list-get.js +1 -1
  108. package/dist/m365/spo/commands/list/list-view-field-add.js +1 -1
  109. package/dist/m365/spo/commands/list/list-view-field-remove.js +1 -1
  110. package/dist/m365/spo/commands/list/list-view-field-set.js +1 -1
  111. package/dist/m365/spo/commands/listitem/listitem-get.js +1 -1
  112. package/dist/m365/spo/commands/listitem/listitem-list.js +3 -3
  113. package/dist/m365/spo/commands/page/Page.js +3 -2
  114. package/dist/m365/spo/commands/page/page-add.js +2 -1
  115. package/dist/m365/spo/commands/page/page-clientsidewebpart-add.js +4 -3
  116. package/dist/m365/spo/commands/page/page-control-get.js +2 -1
  117. package/dist/m365/spo/commands/page/page-control-list.js +2 -1
  118. package/dist/m365/spo/commands/page/page-control-set.js +3 -2
  119. package/dist/m365/spo/commands/page/page-get.js +2 -1
  120. package/dist/m365/spo/commands/page/page-header-set.js +6 -5
  121. package/dist/m365/spo/commands/page/page-section-add.js +4 -3
  122. package/dist/m365/spo/commands/page/page-set.js +2 -1
  123. package/dist/m365/spo/commands/site/site-apppermission-add.js +3 -2
  124. package/dist/m365/spo/commands/site/site-hubsite-connect.js +2 -1
  125. package/dist/m365/spo/commands/site/site-rename.js +2 -1
  126. package/dist/m365/spo/commands/site/site-set.js +1 -1
  127. package/dist/m365/spo/commands/sitescript/sitescript-add.js +2 -1
  128. package/dist/m365/spo/commands/spo-search.js +3 -2
  129. package/dist/m365/spo/commands/storageentity/storageentity-get.js +2 -1
  130. package/dist/m365/spo/commands/user/user-get.js +4 -3
  131. package/dist/m365/spo/commands/user/user-remove.js +2 -1
  132. package/dist/m365/spo/commands/userprofile/userprofile-get.js +2 -1
  133. package/dist/m365/spo/commands/web/web-add.js +2 -1
  134. package/dist/m365/spo/commands.js +4 -0
  135. package/dist/m365/teams/commands/app/app-install.js +3 -2
  136. package/dist/m365/teams/commands/app/app-list.js +2 -1
  137. package/dist/m365/teams/commands/app/app-publish.js +14 -15
  138. package/dist/m365/teams/commands/app/app-update.js +2 -1
  139. package/dist/m365/teams/commands/channel/channel-get.js +4 -3
  140. package/dist/m365/teams/commands/channel/channel-member-add.js +4 -3
  141. package/dist/m365/teams/commands/channel/channel-member-list.js +2 -1
  142. package/dist/m365/teams/commands/channel/channel-member-remove.js +2 -1
  143. package/dist/m365/teams/commands/channel/channel-member-set.js +2 -1
  144. package/dist/m365/teams/commands/channel/channel-remove.js +3 -2
  145. package/dist/m365/teams/commands/channel/channel-set.js +3 -2
  146. package/dist/m365/teams/commands/chat/chat-get.js +2 -1
  147. package/dist/m365/teams/commands/chat/chatUtil.js +2 -1
  148. package/dist/m365/teams/commands/funsettings/funsettings-list.js +2 -1
  149. package/dist/m365/teams/commands/funsettings/funsettings-set.js +2 -1
  150. package/dist/m365/teams/commands/guestsettings/guestsettings-list.js +2 -1
  151. package/dist/m365/teams/commands/guestsettings/guestsettings-set.js +2 -1
  152. package/dist/m365/teams/commands/membersettings/membersettings-list.js +2 -1
  153. package/dist/m365/teams/commands/membersettings/membersettings-set.js +2 -1
  154. package/dist/m365/teams/commands/messagingsettings/messagingsettings-list.js +2 -1
  155. package/dist/m365/teams/commands/messagingsettings/messagingsettings-set.js +2 -1
  156. package/dist/m365/teams/commands/report/report-directroutingcalls.js +3 -2
  157. package/dist/m365/teams/commands/report/report-pstncalls.js +3 -2
  158. package/dist/m365/teams/commands/tab/tab-add.js +2 -1
  159. package/dist/m365/teams/commands/tab/tab-get.js +4 -3
  160. package/dist/m365/teams/commands/tab/tab-list.js +2 -1
  161. package/dist/m365/teams/commands/tab/tab-remove.js +2 -1
  162. package/dist/m365/teams/commands/team/team-archive.js +2 -1
  163. package/dist/m365/teams/commands/team/team-clone.js +2 -1
  164. package/dist/m365/teams/commands/team/team-get.js +2 -1
  165. package/dist/m365/teams/commands/team/team-remove.js +2 -1
  166. package/dist/m365/teams/commands/team/team-set.js +2 -1
  167. package/dist/m365/teams/commands/team/team-unarchive.js +2 -1
  168. package/dist/m365/teams/commands/user/user-app-list.js +3 -2
  169. package/dist/m365/tenant/commands/security/security-alerts-list.js +2 -1
  170. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-healthissue-get.js +2 -1
  171. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-healthissue-list.js +2 -1
  172. package/dist/m365/tenant/commands/serviceannouncement/serviceannouncement-message-list.js +2 -1
  173. package/dist/m365/todo/commands/task/task-set.js +2 -1
  174. package/dist/m365/yammer/commands/user/user-get.js +3 -2
  175. package/dist/m365/yammer/commands/yammer-search.js +2 -1
  176. package/dist/utils/aadGroup.js +2 -1
  177. package/dist/utils/powerPlatform.js +3 -2
  178. package/dist/utils/spo.js +3 -2
  179. package/docs/docs/cmd/spo/file/file-version-clear.md +55 -0
  180. package/docs/docs/cmd/spo/file/file-version-get.md +76 -0
  181. package/docs/docs/cmd/spo/file/file-version-remove.md +58 -0
  182. package/docs/docs/cmd/spo/file/file-version-restore.md +58 -0
  183. package/docs/docs/cmd/teams/app/app-publish.md +14 -4
  184. package/package.json +1 -1
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _SpoFileCheckinCommand_instances, _SpoFileCheckinCommand_initTelemetry, _SpoFileCheckinCommand_initOptions, _SpoFileCheckinCommand_initValidators, _SpoFileCheckinCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
+ const formatting_1 = require("../../../../utils/formatting");
19
20
  const validation_1 = require("../../../../utils/validation");
20
21
  const SpoCommand_1 = require("../../../base/SpoCommand");
21
22
  const commands_1 = require("../../commands");
@@ -54,14 +55,14 @@ class SpoFileCheckinCommand extends SpoCommand_1.default {
54
55
  }
55
56
  let comment = '';
56
57
  if (args.options.comment) {
57
- comment = encodeURIComponent(args.options.comment);
58
+ comment = formatting_1.formatting.encodeQueryParameter(args.options.comment);
58
59
  }
59
60
  let requestUrl = '';
60
61
  if (args.options.id) {
61
- requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${encodeURIComponent(args.options.id)}')/checkin(comment='${comment}',checkintype=${type})`;
62
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${formatting_1.formatting.encodeQueryParameter(args.options.id)}')/checkin(comment='${comment}',checkintype=${type})`;
62
63
  }
63
64
  if (args.options.url) {
64
- requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(args.options.url)}')/checkin(comment='${comment}',checkintype=${type})`;
65
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.url)}')/checkin(comment='${comment}',checkintype=${type})`;
65
66
  }
66
67
  const requestOptions = {
67
68
  url: requestUrl,
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _SpoFileCheckoutCommand_instances, _SpoFileCheckoutCommand_initTelemetry, _SpoFileCheckoutCommand_initOptions, _SpoFileCheckoutCommand_initValidators, _SpoFileCheckoutCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
+ const formatting_1 = require("../../../../utils/formatting");
19
20
  const validation_1 = require("../../../../utils/validation");
20
21
  const SpoCommand_1 = require("../../../base/SpoCommand");
21
22
  const commands_1 = require("../../commands");
@@ -38,10 +39,10 @@ class SpoFileCheckoutCommand extends SpoCommand_1.default {
38
39
  return __awaiter(this, void 0, void 0, function* () {
39
40
  let requestUrl = '';
40
41
  if (args.options.id) {
41
- requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${encodeURIComponent(args.options.id)}')/checkout`;
42
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${formatting_1.formatting.encodeQueryParameter(args.options.id)}')/checkout`;
42
43
  }
43
44
  if (args.options.url) {
44
- requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(args.options.url)}')/checkout`;
45
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.url)}')/checkout`;
45
46
  }
46
47
  const requestOptions = {
47
48
  url: requestUrl,
@@ -23,6 +23,7 @@ const urlUtil_1 = require("../../../../utils/urlUtil");
23
23
  const validation_1 = require("../../../../utils/validation");
24
24
  const SpoCommand_1 = require("../../../base/SpoCommand");
25
25
  const commands_1 = require("../../commands");
26
+ const formatting_1 = require("../../../../utils/formatting");
26
27
  const removeCommand = require('./file-remove');
27
28
  class SpoFileCopyCommand extends SpoCommand_1.default {
28
29
  constructor() {
@@ -110,7 +111,7 @@ class SpoFileCopyCommand extends SpoCommand_1.default {
110
111
  fileExists(tenantUrl, webUrl, sourceUrl) {
111
112
  const webServerRelativeUrl = webUrl.replace(tenantUrl, '');
112
113
  const fileServerRelativeUrl = `${webServerRelativeUrl}${sourceUrl}`;
113
- const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(fileServerRelativeUrl)}')/`;
114
+ const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(fileServerRelativeUrl)}')/`;
114
115
  const requestOptions = {
115
116
  url: requestUrl,
116
117
  method: 'GET',
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const fs = require("fs");
19
19
  const path = require("path");
20
20
  const request_1 = require("../../../../request");
21
+ const formatting_1 = require("../../../../utils/formatting");
21
22
  const validation_1 = require("../../../../utils/validation");
22
23
  const SpoCommand_1 = require("../../../base/SpoCommand");
23
24
  const commands_1 = require("../../commands");
@@ -47,7 +48,7 @@ class SpoFileGetCommand extends SpoCommand_1.default {
47
48
  let requestUrl = '';
48
49
  let options = '';
49
50
  if (args.options.id) {
50
- requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${encodeURIComponent(args.options.id)}')`;
51
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${formatting_1.formatting.encodeQueryParameter(args.options.id)}')`;
51
52
  }
52
53
  else if (args.options.url) {
53
54
  requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl=@f)`;
@@ -65,7 +66,7 @@ class SpoFileGetCommand extends SpoCommand_1.default {
65
66
  else {
66
67
  options += '&';
67
68
  }
68
- options += `@f='${encodeURIComponent(args.options.url)}'`;
69
+ options += `@f='${formatting_1.formatting.encodeQueryParameter(args.options.url)}'`;
69
70
  }
70
71
  const requestOptions = {
71
72
  url: requestUrl + options,
@@ -23,6 +23,7 @@ const urlUtil_1 = require("../../../../utils/urlUtil");
23
23
  const validation_1 = require("../../../../utils/validation");
24
24
  const SpoCommand_1 = require("../../../base/SpoCommand");
25
25
  const commands_1 = require("../../commands");
26
+ const formatting_1 = require("../../../../utils/formatting");
26
27
  const removeCommand = require('./file-remove');
27
28
  class SpoFileMoveCommand extends SpoCommand_1.default {
28
29
  constructor() {
@@ -111,7 +112,7 @@ class SpoFileMoveCommand extends SpoCommand_1.default {
111
112
  fileExists(tenantUrl, webUrl, sourceUrl) {
112
113
  const webServerRelativeUrl = webUrl.replace(tenantUrl, '');
113
114
  const fileServerRelativeUrl = `${webServerRelativeUrl}${sourceUrl}`;
114
- const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(fileServerRelativeUrl)}')/`;
115
+ const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(fileServerRelativeUrl)}')/`;
115
116
  const requestOptions = {
116
117
  url: requestUrl,
117
118
  method: 'GET',
@@ -17,6 +17,7 @@ var _SpoFileRemoveCommand_instances, _SpoFileRemoveCommand_initTelemetry, _SpoFi
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const Cli_1 = require("../../../../cli/Cli");
19
19
  const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
20
21
  const validation_1 = require("../../../../utils/validation");
21
22
  const SpoCommand_1 = require("../../../base/SpoCommand");
22
23
  const commands_1 = require("../../commands");
@@ -46,7 +47,7 @@ class SpoFileRemoveCommand extends SpoCommand_1.default {
46
47
  }
47
48
  let requestUrl = '';
48
49
  if (args.options.id) {
49
- requestUrl = `${args.options.webUrl}/_api/web/GetFileById(guid'${encodeURIComponent(args.options.id)}')`;
50
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileById(guid'${formatting_1.formatting.encodeQueryParameter(args.options.id)}')`;
50
51
  }
51
52
  else {
52
53
  // concatenate trailing '/' if not provided
@@ -60,7 +61,7 @@ class SpoFileRemoveCommand extends SpoCommand_1.default {
60
61
  if (!fileUrl.startsWith(serverRelativeSiteUrl)) {
61
62
  fileUrl = `${serverRelativeSiteUrl}${fileUrl}`;
62
63
  }
63
- requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(fileUrl)}')`;
64
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(fileUrl)}')`;
64
65
  }
65
66
  if (args.options.recycle) {
66
67
  requestUrl += `/recycle()`;
@@ -17,6 +17,7 @@ var _SpoFileRenameCommand_instances, _SpoFileRenameCommand_initTelemetry, _SpoFi
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const Cli_1 = require("../../../../cli/Cli");
19
19
  const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
20
21
  const urlUtil_1 = require("../../../../utils/urlUtil");
21
22
  const validation_1 = require("../../../../utils/validation");
22
23
  const SpoCommand_1 = require("../../../base/SpoCommand");
@@ -52,7 +53,7 @@ class SpoFileRenameCommand extends SpoCommand_1.default {
52
53
  }]
53
54
  };
54
55
  const requestOptions = {
55
- url: `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(originalFileServerRelativeUrl)}')/ListItemAllFields/ValidateUpdateListItem()`,
56
+ url: `${webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(originalFileServerRelativeUrl)}')/ListItemAllFields/ValidateUpdateListItem()`,
56
57
  headers: {
57
58
  'accept': 'application/json;odata=nometadata'
58
59
  },
@@ -68,7 +69,7 @@ class SpoFileRenameCommand extends SpoCommand_1.default {
68
69
  });
69
70
  }
70
71
  getFile(originalFileServerRelativeUrl, webUrl) {
71
- const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(originalFileServerRelativeUrl)}')?$select=UniqueId`;
72
+ const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(originalFileServerRelativeUrl)}')?$select=UniqueId`;
72
73
  const requestOptions = {
73
74
  url: requestUrl,
74
75
  headers: {
@@ -97,7 +97,7 @@ class SpoFileSharinginfoGetCommand extends SpoCommand_1.default {
97
97
  requestUrl = `${args.options.webUrl}/_api/web/GetFileById('${escape(args.options.fileId)}')/?$select=ListItemAllFields/Id,ListItemAllFields/ParentList/Title&$expand=ListItemAllFields/ParentList`;
98
98
  }
99
99
  else {
100
- requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativePath(decodedUrl='${encodeURIComponent(args.options.fileUrl)}')?$select=ListItemAllFields/Id,ListItemAllFields/ParentList/Title&$expand=ListItemAllFields/ParentList`;
100
+ requestUrl = `${args.options.webUrl}/_api/web/GetFileByServerRelativePath(decodedUrl='${formatting_1.formatting.encodeQueryParameter(args.options.fileUrl)}')?$select=ListItemAllFields/Id,ListItemAllFields/ParentList/Title&$expand=ListItemAllFields/ParentList`;
101
101
  }
102
102
  const requestOptions = {
103
103
  url: requestUrl,
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoFileVersionClearCommand_instances, _SpoFileVersionClearCommand_initTelemetry, _SpoFileVersionClearCommand_initOptions, _SpoFileVersionClearCommand_initValidators, _SpoFileVersionClearCommand_initOptionSets;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const Cli_1 = require("../../../../cli/Cli");
19
+ const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
21
+ const validation_1 = require("../../../../utils/validation");
22
+ const SpoCommand_1 = require("../../../base/SpoCommand");
23
+ const commands_1 = require("../../commands");
24
+ class SpoFileVersionClearCommand extends SpoCommand_1.default {
25
+ constructor() {
26
+ super();
27
+ _SpoFileVersionClearCommand_instances.add(this);
28
+ __classPrivateFieldGet(this, _SpoFileVersionClearCommand_instances, "m", _SpoFileVersionClearCommand_initTelemetry).call(this);
29
+ __classPrivateFieldGet(this, _SpoFileVersionClearCommand_instances, "m", _SpoFileVersionClearCommand_initOptions).call(this);
30
+ __classPrivateFieldGet(this, _SpoFileVersionClearCommand_instances, "m", _SpoFileVersionClearCommand_initValidators).call(this);
31
+ __classPrivateFieldGet(this, _SpoFileVersionClearCommand_instances, "m", _SpoFileVersionClearCommand_initOptionSets).call(this);
32
+ }
33
+ get name() {
34
+ return commands_1.default.FILE_VERSION_CLEAR;
35
+ }
36
+ get description() {
37
+ return 'Deletes all file version history of a file in a SharePoint Document library';
38
+ }
39
+ commandAction(logger, args) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (this.verbose) {
42
+ logger.logToStderr(`Deletes all version history of the file ${args.options.fileUrl || args.options.fileId} at site ${args.options.webUrl}...`);
43
+ }
44
+ try {
45
+ if (args.options.confirm) {
46
+ yield this.clearVersions(args);
47
+ }
48
+ else {
49
+ const result = yield Cli_1.Cli.prompt({
50
+ type: 'confirm',
51
+ name: 'continue',
52
+ default: false,
53
+ message: `Are you sure you want to delete all version history for file ${args.options.fileId || args.options.fileUrl}'?`
54
+ });
55
+ if (result.continue) {
56
+ yield this.clearVersions(args);
57
+ }
58
+ }
59
+ }
60
+ catch (err) {
61
+ this.handleRejectedODataJsonPromise(err);
62
+ }
63
+ });
64
+ }
65
+ clearVersions(args) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ let requestUrl = `${args.options.webUrl}/_api/web/`;
68
+ if (args.options.fileUrl) {
69
+ requestUrl += `GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.fileUrl)}')/versions/DeleteAll()`;
70
+ }
71
+ else {
72
+ requestUrl += `GetFileById('${args.options.fileId}')/versions/DeleteAll()`;
73
+ }
74
+ const requestOptions = {
75
+ url: requestUrl,
76
+ headers: {
77
+ 'accept': 'application/json;odata=nometadata'
78
+ },
79
+ responseType: 'json'
80
+ };
81
+ yield request_1.default.post(requestOptions);
82
+ });
83
+ }
84
+ }
85
+ _SpoFileVersionClearCommand_instances = new WeakSet(), _SpoFileVersionClearCommand_initTelemetry = function _SpoFileVersionClearCommand_initTelemetry() {
86
+ this.telemetry.push((args) => {
87
+ Object.assign(this.telemetryProperties, {
88
+ fileUrl: args.options.fileUrl,
89
+ fileId: args.options.fileId,
90
+ confirm: (!!args.options.confirm).toString()
91
+ });
92
+ });
93
+ }, _SpoFileVersionClearCommand_initOptions = function _SpoFileVersionClearCommand_initOptions() {
94
+ this.options.unshift({
95
+ option: '-w, --webUrl <webUrl>'
96
+ }, {
97
+ option: '-u, --fileUrl [fileUrl]'
98
+ }, {
99
+ option: '-i, --fileId [fileId]'
100
+ }, {
101
+ option: '--confirm'
102
+ });
103
+ }, _SpoFileVersionClearCommand_initValidators = function _SpoFileVersionClearCommand_initValidators() {
104
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
105
+ if (args.options.fileId && !validation_1.validation.isValidGuid(args.options.fileId)) {
106
+ return `${args.options.fileId} is not a valid GUID`;
107
+ }
108
+ return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
109
+ }));
110
+ }, _SpoFileVersionClearCommand_initOptionSets = function _SpoFileVersionClearCommand_initOptionSets() {
111
+ this.optionSets.push(['fileUrl', 'fileId']);
112
+ };
113
+ module.exports = new SpoFileVersionClearCommand();
114
+ //# sourceMappingURL=file-version-clear.js.map
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoFileVersionGetCommand_instances, _SpoFileVersionGetCommand_initTelemetry, _SpoFileVersionGetCommand_initOptions, _SpoFileVersionGetCommand_initValidators, _SpoFileVersionGetCommand_initOptionSets, _SpoFileVersionGetCommand_initTypes;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const request_1 = require("../../../../request");
19
+ const formatting_1 = require("../../../../utils/formatting");
20
+ const validation_1 = require("../../../../utils/validation");
21
+ const SpoCommand_1 = require("../../../base/SpoCommand");
22
+ const commands_1 = require("../../commands");
23
+ class SpoFileVersionGetCommand extends SpoCommand_1.default {
24
+ constructor() {
25
+ super();
26
+ _SpoFileVersionGetCommand_instances.add(this);
27
+ __classPrivateFieldGet(this, _SpoFileVersionGetCommand_instances, "m", _SpoFileVersionGetCommand_initTelemetry).call(this);
28
+ __classPrivateFieldGet(this, _SpoFileVersionGetCommand_instances, "m", _SpoFileVersionGetCommand_initOptions).call(this);
29
+ __classPrivateFieldGet(this, _SpoFileVersionGetCommand_instances, "m", _SpoFileVersionGetCommand_initValidators).call(this);
30
+ __classPrivateFieldGet(this, _SpoFileVersionGetCommand_instances, "m", _SpoFileVersionGetCommand_initOptionSets).call(this);
31
+ __classPrivateFieldGet(this, _SpoFileVersionGetCommand_instances, "m", _SpoFileVersionGetCommand_initTypes).call(this);
32
+ }
33
+ get name() {
34
+ return commands_1.default.FILE_VERSION_GET;
35
+ }
36
+ get description() {
37
+ return 'Get a specific version of a file in a SharePoint Document library';
38
+ }
39
+ commandAction(logger, args) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (this.verbose) {
42
+ logger.logToStderr(`Retrieving version ${args.options.label} of the file ${args.options.fileUrl || args.options.fileId} at site ${args.options.webUrl}...`);
43
+ }
44
+ try {
45
+ const version = yield this.getVersion(args);
46
+ logger.log(version.value[0]);
47
+ }
48
+ catch (err) {
49
+ this.handleRejectedODataJsonPromise(err);
50
+ }
51
+ });
52
+ }
53
+ getVersion(args) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ let requestUrl = `${args.options.webUrl}/_api/web/`;
56
+ if (args.options.fileUrl) {
57
+ requestUrl += `GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.fileUrl)}')/versions/?$filter=VersionLabel eq '${args.options.label}'`;
58
+ }
59
+ else {
60
+ requestUrl += `GetFileById('${args.options.fileId}')/versions/?$filter=VersionLabel eq '${args.options.label}'`;
61
+ }
62
+ const requestOptions = {
63
+ url: requestUrl,
64
+ headers: {
65
+ 'accept': 'application/json;odata=nometadata'
66
+ },
67
+ responseType: 'json'
68
+ };
69
+ const response = yield request_1.default.get(requestOptions);
70
+ return response;
71
+ });
72
+ }
73
+ }
74
+ _SpoFileVersionGetCommand_instances = new WeakSet(), _SpoFileVersionGetCommand_initTelemetry = function _SpoFileVersionGetCommand_initTelemetry() {
75
+ this.telemetry.push((args) => {
76
+ Object.assign(this.telemetryProperties, {
77
+ fileUrl: args.options.fileUrl,
78
+ fileId: args.options.fileId
79
+ });
80
+ });
81
+ }, _SpoFileVersionGetCommand_initOptions = function _SpoFileVersionGetCommand_initOptions() {
82
+ this.options.unshift({
83
+ option: '-w, --webUrl <webUrl>'
84
+ }, {
85
+ option: '--label <label>'
86
+ }, {
87
+ option: '-u, --fileUrl [fileUrl]'
88
+ }, {
89
+ option: '-i, --fileId [fileId]'
90
+ });
91
+ }, _SpoFileVersionGetCommand_initValidators = function _SpoFileVersionGetCommand_initValidators() {
92
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
93
+ if (args.options.fileId && !validation_1.validation.isValidGuid(args.options.fileId)) {
94
+ return `${args.options.fileId} is not a valid GUID`;
95
+ }
96
+ return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
97
+ }));
98
+ }, _SpoFileVersionGetCommand_initOptionSets = function _SpoFileVersionGetCommand_initOptionSets() {
99
+ this.optionSets.push(['fileUrl', 'fileId']);
100
+ }, _SpoFileVersionGetCommand_initTypes = function _SpoFileVersionGetCommand_initTypes() {
101
+ this.types.string.push('label');
102
+ };
103
+ module.exports = new SpoFileVersionGetCommand();
104
+ //# sourceMappingURL=file-version-get.js.map
@@ -50,7 +50,7 @@ class SpoFileVersionListCommand extends SpoCommand_1.default {
50
50
  else {
51
51
  requestUrl += `/GetFileById('${args.options.fileId}')`;
52
52
  }
53
- requestUrl += `/versions?$top=5000`;
53
+ requestUrl += `/versions`;
54
54
  const requestOptions = {
55
55
  url: requestUrl,
56
56
  headers: {
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoFileVersionRemoveCommand_instances, _SpoFileVersionRemoveCommand_initTelemetry, _SpoFileVersionRemoveCommand_initOptions, _SpoFileVersionRemoveCommand_initValidators, _SpoFileVersionRemoveCommand_initOptionSets, _SpoFileVersionRemoveCommand_initTypes;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const Cli_1 = require("../../../../cli/Cli");
19
+ const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
21
+ const validation_1 = require("../../../../utils/validation");
22
+ const SpoCommand_1 = require("../../../base/SpoCommand");
23
+ const commands_1 = require("../../commands");
24
+ class SpoFileVersionRemoveCommand extends SpoCommand_1.default {
25
+ constructor() {
26
+ super();
27
+ _SpoFileVersionRemoveCommand_instances.add(this);
28
+ __classPrivateFieldGet(this, _SpoFileVersionRemoveCommand_instances, "m", _SpoFileVersionRemoveCommand_initTelemetry).call(this);
29
+ __classPrivateFieldGet(this, _SpoFileVersionRemoveCommand_instances, "m", _SpoFileVersionRemoveCommand_initOptions).call(this);
30
+ __classPrivateFieldGet(this, _SpoFileVersionRemoveCommand_instances, "m", _SpoFileVersionRemoveCommand_initValidators).call(this);
31
+ __classPrivateFieldGet(this, _SpoFileVersionRemoveCommand_instances, "m", _SpoFileVersionRemoveCommand_initOptionSets).call(this);
32
+ __classPrivateFieldGet(this, _SpoFileVersionRemoveCommand_instances, "m", _SpoFileVersionRemoveCommand_initTypes).call(this);
33
+ }
34
+ get name() {
35
+ return commands_1.default.FILE_VERSION_REMOVE;
36
+ }
37
+ get description() {
38
+ return 'Removes a specific version of a file in a SharePoint Document library';
39
+ }
40
+ commandAction(logger, args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (this.verbose) {
43
+ logger.logToStderr(`Removes version ${args.options.label} of the file ${args.options.fileUrl || args.options.fileId} at site ${args.options.webUrl}...`);
44
+ }
45
+ try {
46
+ if (args.options.confirm) {
47
+ yield this.removeVersion(args);
48
+ }
49
+ else {
50
+ const result = yield Cli_1.Cli.prompt({
51
+ type: 'confirm',
52
+ name: 'continue',
53
+ default: false,
54
+ message: `Are you sure you want to remove the version ${args.options.label} from file ${args.options.fileId || args.options.fileUrl}'?`
55
+ });
56
+ if (result.continue) {
57
+ yield this.removeVersion(args);
58
+ }
59
+ }
60
+ }
61
+ catch (err) {
62
+ this.handleRejectedODataJsonPromise(err);
63
+ }
64
+ });
65
+ }
66
+ removeVersion(args) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ let requestUrl = `${args.options.webUrl}/_api/web/`;
69
+ if (args.options.fileUrl) {
70
+ requestUrl += `GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.fileUrl)}')/versions/DeleteByLabel('${args.options.label}')`;
71
+ }
72
+ else {
73
+ requestUrl += `GetFileById('${args.options.fileId}')/versions/DeleteByLabel('${args.options.label}')`;
74
+ }
75
+ const requestOptions = {
76
+ url: requestUrl,
77
+ headers: {
78
+ 'accept': 'application/json;odata=nometadata'
79
+ },
80
+ responseType: 'json'
81
+ };
82
+ yield request_1.default.delete(requestOptions);
83
+ });
84
+ }
85
+ }
86
+ _SpoFileVersionRemoveCommand_instances = new WeakSet(), _SpoFileVersionRemoveCommand_initTelemetry = function _SpoFileVersionRemoveCommand_initTelemetry() {
87
+ this.telemetry.push((args) => {
88
+ Object.assign(this.telemetryProperties, {
89
+ fileUrl: args.options.fileUrl,
90
+ fileId: args.options.fileId,
91
+ confirm: (!!args.options.confirm).toString()
92
+ });
93
+ });
94
+ }, _SpoFileVersionRemoveCommand_initOptions = function _SpoFileVersionRemoveCommand_initOptions() {
95
+ this.options.unshift({
96
+ option: '-w, --webUrl <webUrl>'
97
+ }, {
98
+ option: '--label <label>'
99
+ }, {
100
+ option: '-u, --fileUrl [fileUrl]'
101
+ }, {
102
+ option: '-i, --fileId [fileId]'
103
+ }, {
104
+ option: '--confirm'
105
+ });
106
+ }, _SpoFileVersionRemoveCommand_initValidators = function _SpoFileVersionRemoveCommand_initValidators() {
107
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
108
+ if (args.options.fileId && !validation_1.validation.isValidGuid(args.options.fileId)) {
109
+ return `${args.options.fileId} is not a valid GUID`;
110
+ }
111
+ return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
112
+ }));
113
+ }, _SpoFileVersionRemoveCommand_initOptionSets = function _SpoFileVersionRemoveCommand_initOptionSets() {
114
+ this.optionSets.push(['fileUrl', 'fileId']);
115
+ }, _SpoFileVersionRemoveCommand_initTypes = function _SpoFileVersionRemoveCommand_initTypes() {
116
+ this.types.string.push('label');
117
+ };
118
+ module.exports = new SpoFileVersionRemoveCommand();
119
+ //# sourceMappingURL=file-version-remove.js.map
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoFileVersionRestoreCommand_instances, _SpoFileVersionRestoreCommand_initTelemetry, _SpoFileVersionRestoreCommand_initOptions, _SpoFileVersionRestoreCommand_initValidators, _SpoFileVersionRestoreCommand_initOptionSets, _SpoFileVersionRestoreCommand_initTypes;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const Cli_1 = require("../../../../cli/Cli");
19
+ const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
21
+ const validation_1 = require("../../../../utils/validation");
22
+ const SpoCommand_1 = require("../../../base/SpoCommand");
23
+ const commands_1 = require("../../commands");
24
+ class SpoFileVersionRestoreCommand extends SpoCommand_1.default {
25
+ constructor() {
26
+ super();
27
+ _SpoFileVersionRestoreCommand_instances.add(this);
28
+ __classPrivateFieldGet(this, _SpoFileVersionRestoreCommand_instances, "m", _SpoFileVersionRestoreCommand_initTelemetry).call(this);
29
+ __classPrivateFieldGet(this, _SpoFileVersionRestoreCommand_instances, "m", _SpoFileVersionRestoreCommand_initOptions).call(this);
30
+ __classPrivateFieldGet(this, _SpoFileVersionRestoreCommand_instances, "m", _SpoFileVersionRestoreCommand_initValidators).call(this);
31
+ __classPrivateFieldGet(this, _SpoFileVersionRestoreCommand_instances, "m", _SpoFileVersionRestoreCommand_initOptionSets).call(this);
32
+ __classPrivateFieldGet(this, _SpoFileVersionRestoreCommand_instances, "m", _SpoFileVersionRestoreCommand_initTypes).call(this);
33
+ }
34
+ get name() {
35
+ return commands_1.default.FILE_VERSION_RESTORE;
36
+ }
37
+ get description() {
38
+ return 'Restores a specific version of a file in a SharePoint Document library';
39
+ }
40
+ commandAction(logger, args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (this.verbose) {
43
+ logger.logToStderr(`Restores version ${args.options.label} of the file ${args.options.fileUrl || args.options.fileId} at site ${args.options.webUrl}...`);
44
+ }
45
+ try {
46
+ if (args.options.confirm) {
47
+ yield this.restoreVersion(args);
48
+ }
49
+ else {
50
+ const result = yield Cli_1.Cli.prompt({
51
+ type: 'confirm',
52
+ name: 'continue',
53
+ default: false,
54
+ message: `Are you sure you want to restore the version ${args.options.label} from file ${args.options.fileId || args.options.fileUrl}'?`
55
+ });
56
+ if (result.continue) {
57
+ yield this.restoreVersion(args);
58
+ }
59
+ }
60
+ }
61
+ catch (err) {
62
+ this.handleRejectedODataJsonPromise(err);
63
+ }
64
+ });
65
+ }
66
+ restoreVersion(args) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ let requestUrl = `${args.options.webUrl}/_api/web/`;
69
+ if (args.options.fileUrl) {
70
+ requestUrl += `GetFileByServerRelativeUrl('${formatting_1.formatting.encodeQueryParameter(args.options.fileUrl)}')/versions/RestoreByLabel('${args.options.label}')`;
71
+ }
72
+ else {
73
+ requestUrl += `GetFileById('${args.options.fileId}')/versions/RestoreByLabel('${args.options.label}')`;
74
+ }
75
+ const requestOptions = {
76
+ url: requestUrl,
77
+ headers: {
78
+ 'accept': 'application/json;odata=nometadata'
79
+ },
80
+ responseType: 'json'
81
+ };
82
+ yield request_1.default.post(requestOptions);
83
+ });
84
+ }
85
+ }
86
+ _SpoFileVersionRestoreCommand_instances = new WeakSet(), _SpoFileVersionRestoreCommand_initTelemetry = function _SpoFileVersionRestoreCommand_initTelemetry() {
87
+ this.telemetry.push((args) => {
88
+ Object.assign(this.telemetryProperties, {
89
+ fileUrl: args.options.fileUrl,
90
+ fileId: args.options.fileId,
91
+ confirm: (!!args.options.confirm).toString()
92
+ });
93
+ });
94
+ }, _SpoFileVersionRestoreCommand_initOptions = function _SpoFileVersionRestoreCommand_initOptions() {
95
+ this.options.unshift({
96
+ option: '-w, --webUrl <webUrl>'
97
+ }, {
98
+ option: '--label <label>'
99
+ }, {
100
+ option: '-u, --fileUrl [fileUrl]'
101
+ }, {
102
+ option: '-i, --fileId [fileId]'
103
+ }, {
104
+ option: '--confirm'
105
+ });
106
+ }, _SpoFileVersionRestoreCommand_initValidators = function _SpoFileVersionRestoreCommand_initValidators() {
107
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
108
+ if (args.options.fileId && !validation_1.validation.isValidGuid(args.options.fileId)) {
109
+ return `${args.options.fileId} is not a valid GUID`;
110
+ }
111
+ return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
112
+ }));
113
+ }, _SpoFileVersionRestoreCommand_initOptionSets = function _SpoFileVersionRestoreCommand_initOptionSets() {
114
+ this.optionSets.push(['fileUrl', 'fileId']);
115
+ }, _SpoFileVersionRestoreCommand_initTypes = function _SpoFileVersionRestoreCommand_initTypes() {
116
+ this.types.string.push('label');
117
+ };
118
+ module.exports = new SpoFileVersionRestoreCommand();
119
+ //# sourceMappingURL=file-version-restore.js.map