sandforge 1.79.0 → 1.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/lib/{chunk-JVL444U5.mjs → chunk-2BA2XKAY.mjs} +1 -1
  2. package/lib/chunk-2CNCDM56.mjs +7 -0
  3. package/lib/{chunk-W7KFAY55.mjs → chunk-2GTBABKU.mjs} +1 -1
  4. package/lib/{chunk-DLDX6RRC.mjs → chunk-2NBYT7GR.mjs} +1 -1
  5. package/lib/{chunk-HV2MXMGI.mjs → chunk-2UZPIMUC.mjs} +1 -1
  6. package/lib/chunk-3F6Q5E7I.mjs +14 -0
  7. package/lib/{chunk-PBI4BYWW.mjs → chunk-3RZQZHEB.mjs} +1 -1
  8. package/lib/{chunk-P7GSGFJO.mjs → chunk-3TJON4F3.mjs} +1 -1
  9. package/lib/chunk-4VS2V6WU.mjs +25 -0
  10. package/lib/{chunk-TQX3PURV.mjs → chunk-5K5VLULK.mjs} +1 -1
  11. package/lib/{chunk-MYTIL2JD.mjs → chunk-5TC3QB4U.mjs} +1 -1
  12. package/lib/{chunk-NM4MDLK4.mjs → chunk-6XYKJSGX.mjs} +1 -1
  13. package/lib/{chunk-RFEO2KAN.mjs → chunk-74Q6DORA.mjs} +1 -1
  14. package/lib/chunk-7ABODJ4G.mjs +7 -0
  15. package/lib/{chunk-ZPYJPGDK.mjs → chunk-7EGQP6S4.mjs} +1 -1
  16. package/lib/chunk-7FFGJWHN.mjs +7 -0
  17. package/lib/chunk-7YDNUBO5.mjs +7 -0
  18. package/lib/{chunk-CGWXQX75.mjs → chunk-A527W53V.mjs} +1 -1
  19. package/lib/chunk-ADOAS63R.mjs +7 -0
  20. package/lib/chunk-AEKONPF4.mjs +7 -0
  21. package/lib/{chunk-4HFRHFGQ.mjs → chunk-B5QQJ4SI.mjs} +1 -1
  22. package/lib/{chunk-2BVTCNWA.mjs → chunk-BGUEWRK2.mjs} +1 -1
  23. package/lib/{chunk-GNC27UEU.mjs → chunk-BKDV4ENO.mjs} +1 -1
  24. package/lib/{chunk-QRV2OSIS.mjs → chunk-BTWDMNN3.mjs} +1 -1
  25. package/lib/{chunk-FOVVHGEP.mjs → chunk-BV6VTP3J.mjs} +1 -1
  26. package/lib/{chunk-PZTSVQSF.mjs → chunk-BXU6WFMH.mjs} +1 -1
  27. package/lib/{chunk-ZQOZ4EFW.mjs → chunk-BY2HJFFG.mjs} +1 -1
  28. package/lib/{chunk-NZ5ZZLKS.mjs → chunk-CEX3NEZL.mjs} +1 -1
  29. package/lib/{chunk-HTJ5OGP5.mjs → chunk-CHYDMRSV.mjs} +1 -1
  30. package/lib/chunk-CION3VMZ.mjs +7 -0
  31. package/lib/chunk-COFG7Q6R.mjs +7 -0
  32. package/lib/chunk-CSBS5U5I.mjs +7 -0
  33. package/lib/{chunk-55HEMHEG.mjs → chunk-CU2INBND.mjs} +1 -1
  34. package/lib/chunk-DB7RBE5D.mjs +7 -0
  35. package/lib/{chunk-QPF6C5MX.mjs → chunk-DBB3EMIN.mjs} +1 -1
  36. package/lib/{chunk-F74IHMGL.mjs → chunk-DYFALGRT.mjs} +1 -1
  37. package/lib/{chunk-TEOLMRDO.mjs → chunk-E5AHXLS6.mjs} +1 -1
  38. package/lib/{chunk-LRFAIUN7.mjs → chunk-E5ZB3LU5.mjs} +1 -1
  39. package/lib/chunk-EFR2Y7E4.mjs +7 -0
  40. package/lib/chunk-EHQ3FX6X.mjs +7 -0
  41. package/lib/{chunk-RAAANPPG.mjs → chunk-ELFXJHU7.mjs} +1 -1
  42. package/lib/{chunk-BN7A4GRQ.mjs → chunk-EMNC6YI4.mjs} +1 -1
  43. package/lib/{chunk-HJC7AIBK.mjs → chunk-EQNW3UC2.mjs} +1 -1
  44. package/lib/{chunk-Z7X534S4.mjs → chunk-F43REJDZ.mjs} +2 -2
  45. package/lib/{chunk-QQZZMKU3.mjs → chunk-F6GUDTOB.mjs} +1 -1
  46. package/lib/{chunk-6EBMEGZB.mjs → chunk-FGRG7ANU.mjs} +1 -1
  47. package/lib/{chunk-4NAHW2D3.mjs → chunk-FKG7Q3WH.mjs} +1 -1
  48. package/lib/{chunk-7UQD6V6F.mjs → chunk-FPKYYFM7.mjs} +1 -1
  49. package/lib/{chunk-ZJKCWBRJ.mjs → chunk-FXXLX4O6.mjs} +1 -1
  50. package/lib/chunk-G35N4P7D.mjs +7 -0
  51. package/lib/{chunk-SIOZXPFG.mjs → chunk-GGD7ON3M.mjs} +1 -1
  52. package/lib/chunk-GSG7WZHM.mjs +7 -0
  53. package/lib/{chunk-OTWRDD6L.mjs → chunk-GSKCGQIP.mjs} +1 -1
  54. package/lib/{chunk-3CA767QB.mjs → chunk-HEKAZJRH.mjs} +1 -1
  55. package/lib/{chunk-4SNDMJP2.mjs → chunk-HLWMJF6Y.mjs} +1 -1
  56. package/lib/chunk-HOJYWTP7.mjs +20 -0
  57. package/lib/chunk-HS4YRX4J.mjs +7 -0
  58. package/lib/chunk-IFETCRWE.mjs +10 -0
  59. package/lib/{chunk-PUOX4NBJ.mjs → chunk-IG2MTQRP.mjs} +1 -1
  60. package/lib/{chunk-RACDTRZA.mjs → chunk-IGYH7GMA.mjs} +1 -1
  61. package/lib/{chunk-X65MT4W3.mjs → chunk-IOIWJ3DJ.mjs} +1 -1
  62. package/lib/{chunk-4U6NXJNL.mjs → chunk-IQXHJEYB.mjs} +1 -1
  63. package/lib/{chunk-P2PJYWGQ.mjs → chunk-IWDREM66.mjs} +1 -1
  64. package/lib/{chunk-ZOVSMN5C.mjs → chunk-IZQZ6ZUF.mjs} +1 -1
  65. package/lib/{chunk-XBG5SP6Q.mjs → chunk-J525F5KI.mjs} +1 -1
  66. package/lib/{chunk-5CD257T7.mjs → chunk-JEERQRLW.mjs} +1 -1
  67. package/lib/{chunk-6QSM2WIH.mjs → chunk-JPUR2CFX.mjs} +1 -1
  68. package/lib/chunk-JWTSEDIQ.mjs +7 -0
  69. package/lib/chunk-K327QKMD.mjs +7 -0
  70. package/lib/{chunk-J7HVXMSW.mjs → chunk-KBJ5VERV.mjs} +1 -1
  71. package/lib/chunk-KDGMAGQR.mjs +7 -0
  72. package/lib/chunk-KRCA6IPH.mjs +8 -0
  73. package/lib/chunk-KYEDBS54.mjs +7 -0
  74. package/lib/chunk-L5FGY6YA.mjs +7 -0
  75. package/lib/{chunk-PNCONNFJ.mjs → chunk-L77FJZEP.mjs} +1 -1
  76. package/lib/{chunk-3OHPD72J.mjs → chunk-LKQ5RKIV.mjs} +1 -1
  77. package/lib/{chunk-WJY54JO7.mjs → chunk-LPBMBW3O.mjs} +1 -1
  78. package/lib/{chunk-LV6G4XTK.mjs → chunk-LWW4U276.mjs} +1 -1
  79. package/lib/{chunk-IAZB4WIL.mjs → chunk-M3ROUWDX.mjs} +1 -1
  80. package/lib/chunk-MFG4MUIO.mjs +9 -0
  81. package/lib/{chunk-H45UXY6G.mjs → chunk-MHMH6MTP.mjs} +1 -1
  82. package/lib/{chunk-HCIDVIOW.mjs → chunk-MILU7WFN.mjs} +1 -1
  83. package/lib/chunk-MJU2PGZQ.mjs +15 -0
  84. package/lib/{chunk-HJKM3E56.mjs → chunk-MJVTDA5Q.mjs} +1 -1
  85. package/lib/{chunk-SBIMVCXT.mjs → chunk-MS4FJDFD.mjs} +9 -9
  86. package/lib/{chunk-3SRXFZSD.mjs → chunk-MYW5QNGI.mjs} +1 -1
  87. package/lib/{chunk-VHI54FBK.mjs → chunk-N652NMZ4.mjs} +26 -26
  88. package/lib/{chunk-3DCUADVK.mjs → chunk-NTFIRZP6.mjs} +1 -1
  89. package/lib/{chunk-342FN7AO.mjs → chunk-NZC67CGR.mjs} +1 -1
  90. package/lib/{chunk-RSYICMZG.mjs → chunk-O2HDYYUV.mjs} +1 -1
  91. package/lib/chunk-OAZRPP4I.mjs +7 -0
  92. package/lib/{chunk-BILZ3SSR.mjs → chunk-OHWNPXWW.mjs} +1 -1
  93. package/lib/chunk-OLSGVAIL.mjs +341 -0
  94. package/lib/chunk-OO6CLPEH.mjs +7 -0
  95. package/lib/chunk-OPXCV2KL.mjs +7 -0
  96. package/lib/chunk-P33PSCXK.mjs +7 -0
  97. package/lib/{chunk-AUTM6H6Z.mjs → chunk-PJ5I73CK.mjs} +1 -1
  98. package/lib/{chunk-NTDN2JQZ.mjs → chunk-PZPJKATS.mjs} +1 -1
  99. package/lib/{chunk-5QKTYCWE.mjs → chunk-Q3DM32KF.mjs} +1 -1
  100. package/lib/{chunk-K22PA4XL.mjs → chunk-QR3WELJQ.mjs} +1 -1
  101. package/lib/{chunk-42RER7V4.mjs → chunk-R3X3LV64.mjs} +1 -1
  102. package/lib/chunk-RMBPOTD7.mjs +7 -0
  103. package/lib/{chunk-IEYG5ATY.mjs → chunk-RPI7LRTW.mjs} +1 -1
  104. package/lib/{chunk-5MMXFWPD.mjs → chunk-SE4QEZUG.mjs} +1 -1
  105. package/lib/{chunk-ALJVEUUS.mjs → chunk-SIHORWVK.mjs} +1 -1
  106. package/lib/{chunk-AAVJ5XVX.mjs → chunk-SOGQW4IG.mjs} +1 -1
  107. package/lib/chunk-SOU4FRYN.mjs +7 -0
  108. package/lib/chunk-SU65Z2BA.mjs +7 -0
  109. package/lib/chunk-T62WNR54.mjs +7 -0
  110. package/lib/{chunk-5O6JOMHS.mjs → chunk-TSLJUSLW.mjs} +1 -1
  111. package/lib/chunk-TTFDUKUS.mjs +47 -0
  112. package/lib/{chunk-57VHUYNG.mjs → chunk-TTKXMDBN.mjs} +1 -1
  113. package/lib/chunk-UCD54V2M.mjs +7 -0
  114. package/lib/{chunk-TBZMC2VV.mjs → chunk-UNJA4J37.mjs} +1 -1
  115. package/lib/{chunk-NGSMZZDA.mjs → chunk-VE6XKGGD.mjs} +1 -1
  116. package/lib/chunk-VS7ZXUII.mjs +824 -0
  117. package/lib/{chunk-ALUFROGA.mjs → chunk-VXQLDM4R.mjs} +1 -1
  118. package/lib/chunk-VYXMVJL5.mjs +7 -0
  119. package/lib/{chunk-WFEB5X4U.mjs → chunk-W622GUAW.mjs} +1 -1
  120. package/lib/chunk-W7U5E5ZL.mjs +9 -0
  121. package/lib/{chunk-AR7BE5O2.mjs → chunk-WA7EYLAQ.mjs} +1 -1
  122. package/lib/{chunk-EQF2IJS2.mjs → chunk-WR4Q363I.mjs} +1 -1
  123. package/lib/{chunk-ZXH4MBWP.mjs → chunk-WU3GLFZO.mjs} +1 -1
  124. package/lib/chunk-WXAQ7FK3.mjs +115 -0
  125. package/lib/{chunk-YBU4Z4QV.mjs → chunk-X5JYBPXP.mjs} +1 -1
  126. package/lib/chunk-XAMBCQPU.mjs +7 -0
  127. package/lib/{chunk-LQ4DRFUH.mjs → chunk-XLXIPIEW.mjs} +1 -1
  128. package/lib/{chunk-H2PJNIYJ.mjs → chunk-XUWL6ZPC.mjs} +1 -1
  129. package/lib/{chunk-P42X3B4D.mjs → chunk-YKKRIEH4.mjs} +1 -1
  130. package/lib/chunk-YRQGKDHM.mjs +7 -0
  131. package/lib/chunk-ZM6OJGIG.mjs +7 -0
  132. package/lib/{chunk-SFURUNJM.mjs → chunk-ZVAED4QV.mjs} +1 -1
  133. package/lib/sandforge-autopilot.mjs +29 -24
  134. package/lib/sandforge-backup.mjs +25 -21
  135. package/lib/sandforge-checkpoint.mjs +15 -14
  136. package/lib/sandforge-cleanup.mjs +14 -10
  137. package/lib/sandforge-clone.mjs +1 -1
  138. package/lib/sandforge-compare.mjs +9 -8
  139. package/lib/sandforge-dataops.mjs +1 -1
  140. package/lib/sandforge-empty.mjs +15 -15
  141. package/lib/sandforge-env.mjs +88 -88
  142. package/lib/sandforge-frozen.mjs +43 -34
  143. package/lib/sandforge-mcp.mjs +12 -12
  144. package/lib/sandforge-monitor.mjs +7 -7
  145. package/lib/sandforge-seed.mjs +1 -1
  146. package/lib/sandforge-sync.mjs +1 -1
  147. package/lib/sandforge.mjs +4 -4
  148. package/package.json +1 -1
  149. package/lib/chunk-2S5OMIIA.mjs +0 -7
  150. package/lib/chunk-36U7IQ6Y.mjs +0 -25
  151. package/lib/chunk-3F5YMM2F.mjs +0 -7
  152. package/lib/chunk-3RYLICRX.mjs +0 -7
  153. package/lib/chunk-4GL773D5.mjs +0 -7
  154. package/lib/chunk-4XZ5YT5O.mjs +0 -7
  155. package/lib/chunk-5AJRHRXA.mjs +0 -20
  156. package/lib/chunk-5HMAPZBV.mjs +0 -7
  157. package/lib/chunk-6LAXTAVN.mjs +0 -7
  158. package/lib/chunk-6MUEPV7M.mjs +0 -9
  159. package/lib/chunk-75ADZS6B.mjs +0 -7
  160. package/lib/chunk-B45CNPUX.mjs +0 -47
  161. package/lib/chunk-BS5T3MOQ.mjs +0 -7
  162. package/lib/chunk-D3QRXG63.mjs +0 -787
  163. package/lib/chunk-EEVVGGM6.mjs +0 -7
  164. package/lib/chunk-ENLBYECD.mjs +0 -7
  165. package/lib/chunk-EQOQASDQ.mjs +0 -7
  166. package/lib/chunk-FQBRBBY4.mjs +0 -7
  167. package/lib/chunk-GAM726CK.mjs +0 -7
  168. package/lib/chunk-HUMEKZT5.mjs +0 -8
  169. package/lib/chunk-I3JKJTLO.mjs +0 -110
  170. package/lib/chunk-KLX67VPL.mjs +0 -7
  171. package/lib/chunk-L776PUMV.mjs +0 -7
  172. package/lib/chunk-NEVXIGR6.mjs +0 -10
  173. package/lib/chunk-NHWE66K5.mjs +0 -7
  174. package/lib/chunk-OQOZAPCI.mjs +0 -7
  175. package/lib/chunk-PA3MKJVH.mjs +0 -7
  176. package/lib/chunk-RH3N2H7P.mjs +0 -7
  177. package/lib/chunk-SRQDABQ2.mjs +0 -15
  178. package/lib/chunk-SVS6UMDU.mjs +0 -323
  179. package/lib/chunk-TNXUU6W7.mjs +0 -14
  180. package/lib/chunk-VXHDBYMI.mjs +0 -7
  181. package/lib/chunk-WRU5FJFC.mjs +0 -7
  182. package/lib/chunk-X2PY6MWZ.mjs +0 -7
  183. package/lib/chunk-XEFDB2R4.mjs +0 -7
  184. package/lib/chunk-XETCPL7E.mjs +0 -7
  185. package/lib/chunk-Y5CGXLUB.mjs +0 -7
  186. package/lib/chunk-Y6J6QFI2.mjs +0 -7
  187. package/lib/chunk-YMJVMFPY.mjs +0 -7
  188. package/lib/chunk-YPSRZRIT.mjs +0 -7
  189. package/lib/chunk-YW2SBL4Z.mjs +0 -7
  190. package/lib/chunk-ZE6HKRR4.mjs +0 -9
  191. package/lib/chunk-ZLZRU6MO.mjs +0 -7
  192. package/lib/chunk-ZYEE34WO.mjs +0 -7
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a as W}from"./chunk-PBI4BYWW.mjs";import{a as C,b as R}from"./chunk-5P4PHJRL.mjs";import{a as A,b as U,c as M}from"./chunk-RSWDYIHY.mjs";import{K as T}from"./chunk-D3QRXG63.mjs";import"./chunk-NM4MDLK4.mjs";import"./chunk-BS5T3MOQ.mjs";import"./chunk-TEOLMRDO.mjs";import"./chunk-FQBRBBY4.mjs";import"./chunk-YS4G22C2.mjs";import"./chunk-SCKUIE3R.mjs";import{a as k}from"./chunk-QROPNEGY.mjs";import"./chunk-BZ24IAP5.mjs";import{c as v}from"./chunk-AV5SWEHP.mjs";import{a as E,c as L,d as _,e as P,f as z}from"./chunk-I7O6C2B5.mjs";import{a as B}from"./chunk-4GL773D5.mjs";import{j as O}from"./chunk-SRQDABQ2.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-LV6G4XTK.mjs";import"./chunk-HJKM3E56.mjs";import"./chunk-XCA5AONB.mjs";import"./chunk-WR2GIKWE.mjs";import"./chunk-YMJVMFPY.mjs";import"./chunk-ALJVEUUS.mjs";import"./chunk-CE6ZDGBB.mjs";import"./chunk-4HFRHFGQ.mjs";import"./chunk-342FN7AO.mjs";import"./chunk-BOGNK4LV.mjs";import{x as D}from"./chunk-36U7IQ6Y.mjs";import"./chunk-XETCPL7E.mjs";import"./chunk-K2FBZIXY.mjs";import"./chunk-Z7X534S4.mjs";import"./chunk-6QSM2WIH.mjs";import"./chunk-WJY54JO7.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-DBFJB2B6.mjs";import"./chunk-NEVXIGR6.mjs";import{h as S}from"./chunk-NTDN2JQZ.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-F74IHMGL.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-Y5CGXLUB.mjs";import"./chunk-3F5YMM2F.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-SAR5622P.mjs";import{b as I}from"./chunk-L776PUMV.mjs";import"./chunk-6MUEPV7M.mjs";import"./chunk-HJC7AIBK.mjs";import"./chunk-OTWRDD6L.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-TYYOBZMU.mjs";import"./chunk-RH3N2H7P.mjs";import"./chunk-ZUTYVST5.mjs";import"./chunk-55HEMHEG.mjs";import"./chunk-P42X3B4D.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-VXHDBYMI.mjs";import"./chunk-ENLBYECD.mjs";import"./chunk-PA3MKJVH.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-ZLZRU6MO.mjs";import"./chunk-WIO4XO4F.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-GCOB7K5N.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-PNCONNFJ.mjs";import"./chunk-CGWXQX75.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-SIOZXPFG.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import{a as x,d as j,e as y,g as N}from"./chunk-MTMH6H2A.mjs";import{Vb as $}from"./chunk-B45CNPUX.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-SBIMVCXT.mjs";import"./chunk-NTOVCTRS.mjs";import{join as F}from"node:path";var G=`sandforge backup \u2014 take and restore DataOps snapshots, without the editor.
7
+ import{a as F}from"./chunk-3RZQZHEB.mjs";import{a as N,b as D}from"./chunk-5P4PHJRL.mjs";import{a as A,b as W,c as B}from"./chunk-RSWDYIHY.mjs";import{O as L}from"./chunk-VS7ZXUII.mjs";import"./chunk-SOU4FRYN.mjs";import"./chunk-E5AHXLS6.mjs";import"./chunk-OO6CLPEH.mjs";import"./chunk-YS4G22C2.mjs";import{a as k}from"./chunk-QROPNEGY.mjs";import"./chunk-BZ24IAP5.mjs";import{a as x}from"./chunk-SCKUIE3R.mjs";import{c as v}from"./chunk-AV5SWEHP.mjs";import{a as _,c as P,d as U,e as z,f as M}from"./chunk-I7O6C2B5.mjs";import{a as J}from"./chunk-YRQGKDHM.mjs";import{m as R}from"./chunk-MJU2PGZQ.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-LWW4U276.mjs";import"./chunk-MJVTDA5Q.mjs";import"./chunk-XCA5AONB.mjs";import"./chunk-WR2GIKWE.mjs";import"./chunk-2CNCDM56.mjs";import"./chunk-SIHORWVK.mjs";import"./chunk-CE6ZDGBB.mjs";import"./chunk-B5QQJ4SI.mjs";import"./chunk-NZC67CGR.mjs";import"./chunk-BOGNK4LV.mjs";import{y as T}from"./chunk-4VS2V6WU.mjs";import"./chunk-KYEDBS54.mjs";import"./chunk-6XYKJSGX.mjs";import"./chunk-K2FBZIXY.mjs";import"./chunk-F43REJDZ.mjs";import"./chunk-JPUR2CFX.mjs";import"./chunk-LPBMBW3O.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-DBFJB2B6.mjs";import"./chunk-IFETCRWE.mjs";import{h as C}from"./chunk-PZPJKATS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-DYFALGRT.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-7FFGJWHN.mjs";import"./chunk-G35N4P7D.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-SAR5622P.mjs";import{b as S}from"./chunk-KDGMAGQR.mjs";import"./chunk-MFG4MUIO.mjs";import"./chunk-EQNW3UC2.mjs";import"./chunk-GSKCGQIP.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-TYYOBZMU.mjs";import"./chunk-HS4YRX4J.mjs";import"./chunk-ZUTYVST5.mjs";import"./chunk-CU2INBND.mjs";import"./chunk-YKKRIEH4.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-VYXMVJL5.mjs";import"./chunk-AEKONPF4.mjs";import"./chunk-JWTSEDIQ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-CION3VMZ.mjs";import"./chunk-WIO4XO4F.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-GCOB7K5N.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-L77FJZEP.mjs";import"./chunk-A527W53V.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-GGD7ON3M.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import{a as I,d as O,e as y,g as E}from"./chunk-MTMH6H2A.mjs";import{Yb as j}from"./chunk-TTFDUKUS.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-MS4FJDFD.mjs";import"./chunk-NTOVCTRS.mjs";import{join as H}from"node:path";var Q=`sandforge backup \u2014 take and restore DataOps snapshots, without the editor.
8
8
 
9
9
  Usage:
10
10
  npx sandforge backup --org <alias> [options]
@@ -35,7 +35,7 @@ Options:
35
35
  included
36
36
  --include-changed with --restore of the snapshot a Sync run kept: put
37
37
  back the records changed or deleted since the run too
38
- ${M("written back")} --max-age-days <n> the retention, as sandforge.backup.maxAgeDays sets it:
38
+ ${B("written back")} --max-age-days <n> the retention, as sandforge.backup.maxAgeDays sets it:
39
39
  snapshots taken more than <n> days ago are removed as
40
40
  the command starts, each named on stderr \u2014 the one a
41
41
  Sync run kept of what it wrote over too, which removing
@@ -43,7 +43,10 @@ ${M("written back")} --max-age-days <n> the retention, as sandforge.backup.
43
43
  (default: 30)
44
44
  --yes do not ask before a restore writes. Without it, a
45
45
  command with no terminal to answer the question \u2014 a
46
- CI step \u2014 stops there, exit 2, and writes nothing
46
+ CI step \u2014 stops there, exit 2, and writes nothing.
47
+ Into an org that is not the one the snapshot was
48
+ taken of \u2014 a sandbox refreshed since \u2014 --yes counts
49
+ as no, exit 1: run it without --yes, in a terminal
47
50
  --json emit what the panel would receive, or with --list the
48
51
  snapshots, every other line on stderr
49
52
  --help this text
@@ -77,23 +80,24 @@ terminal to answer it (give --yes); 3 the snapshot holds part of an object's
77
80
  records, or the restore left values as they are (rows the org refused, a
78
81
  snapshot that holds part of the records, or records of a Sync run's snapshot
79
82
  changed since the run, held back without --include-changed).
80
- `,H=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,q={switches:["--list","--rewrite-all","--include-changed","--yes","--json",...A],values:["--org","--object","--restore","--store","--max-records","--max-age-days"]};function Q(o){let e=o.slice(2);(e.includes("--help")||e.includes("-h"))&&(process.stdout.write(G),process.exit(0)),x(e,q);let t=(h,u)=>{let n=e.indexOf(h);return n>=0&&n+1<e.length?e[n+1]:u},a=h=>{let u=[];for(let n=0;n<e.length;n++)e[n]===h&&n+1<e.length&&u.push(e[n+1]);return u},d=t("--org"),i=e.includes("--list");!d&&!i&&(process.stderr.write(`Missing --org. Run with --help.
81
- `),process.exit(2));let g=a("--object"),f=t("--restore"),p=[g.length>0,i,f!==void 0].filter(Boolean).length;p===0&&(process.stderr.write(`Nothing to do: give --object, --list or --restore.
82
- `),process.exit(2)),p>1&&(process.stderr.write(`Give one of --object, --list or --restore.
83
- `),process.exit(2));for(let h of g)H.test(h)||(process.stderr.write(`Not an SObject API name: "${h}"
84
- `),process.exit(2));let c=t("--max-records");c!==void 0&&!/^[1-9]\d*$/.test(c)&&(process.stderr.write(`Not a number of records: "${c}"
83
+ `,X=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,Z={switches:["--list","--rewrite-all","--include-changed","--yes","--json",...A],values:["--org","--object","--restore","--store","--max-records","--max-age-days"]};function K(t){let e=t.slice(2);(e.includes("--help")||e.includes("-h"))&&(process.stdout.write(Q),process.exit(0)),I(e,Z);let o=(l,g)=>{let a=e.indexOf(l);return a>=0&&a+1<e.length?e[a+1]:g},i=l=>{let g=[];for(let a=0;a<e.length;a++)e[a]===l&&a+1<e.length&&g.push(e[a+1]);return g},n=o("--org"),r=e.includes("--list");!n&&!r&&(process.stderr.write(`Missing --org. Run with --help.
84
+ `),process.exit(2));let c=i("--object"),f=o("--restore"),h=[c.length>0,r,f!==void 0].filter(Boolean).length;h===0&&(process.stderr.write(`Nothing to do: give --object, --list or --restore.
85
+ `),process.exit(2)),h>1&&(process.stderr.write(`Give one of --object, --list or --restore.
86
+ `),process.exit(2));for(let l of c)X.test(l)||(process.stderr.write(`Not an SObject API name: "${l}"
87
+ `),process.exit(2));let p=o("--max-records");p!==void 0&&!/^[1-9]\d*$/.test(p)&&(process.stderr.write(`Not a number of records: "${p}"
85
88
  `),process.exit(2));let b=e.includes("--rewrite-all");b&&f===void 0&&(process.stderr.write(`--rewrite-all goes with --restore.
86
89
  `),process.exit(2));let w=e.includes("--include-changed");w&&f===void 0&&(process.stderr.write(`--include-changed goes with --restore.
87
- `),process.exit(2));let r=_(t("--max-age-days")),s=U(e),l=A.filter(h=>e.includes(h));l.length>0&&f===void 0&&(process.stderr.write(`${l.join(", ")} go${l.length===1?"es":""} with --restore.
88
- `),process.exit(2));let m={objects:g,restoreId:f,storeDir:t("--store",E())??"",...c!==void 0?{maxRecords:Number(c)}:{},rewriteAll:b,includeChanged:w,...r!==void 0?{maxAgeDays:r}:{},yes:e.includes("--yes"),json:e.includes("--json"),accord:s};return d?i?{...m,list:!0,org:d}:{...m,list:!1,org:d}:{...m,list:!0}}async function X(o=process.argv){let e=Q(o),t=r=>{process[e.json?"stderr":"stdout"].write(`${r}
89
- `)},a=L(e.storeDir);if(a!==void 0){process.stderr.write(`${a}
90
- `),process.exitCode=1;return}t(`store: ${e.storeDir}`);let d=D(F(e.storeDir,"snapshots.json"));if(e.list){let r=d.getKeysByPrefix("backup:").map(l=>d.get(l)),s=e.org!==void 0?K(r,e.org):r;if(e.json){process.stdout.write(`${JSON.stringify(Y(s),null,2)}
91
- `);return}s.length===0&&t(e.org!==void 0?`No snapshot of ${e.org} in this store.`:"No snapshot in this store.");for(let l of s.map(V))t(l);return}let i=await I(e.org),g=await new B().validateConnection(i.accessToken,i.instanceUrl),f={alias:i.alias,orgType:$({isSandbox:g.isSandbox,edition:g.orgType}),metadata:{apiVersion:"66.0",edition:g.orgType}},p=[],c=new O({log:r=>t(` ${r}`),broker:{postToWebview:r=>{p.push(r);let s=String(r.type??"");(s.endsWith(":error")||s.includes("failed"))&&(t(` ! ${JSON.stringify(r.payload??r)}`),process.exitCode=1)}},orgManager:{getOrg:()=>f},orgRegistry:{getCredentials:async()=>({accessToken:i.accessToken,instanceUrl:i.instanceUrl})},configStore:d,services:{getSandforgeSetting:P(e)},infraServices:{productionGuard:W(t,e.org),confirmRestoreIntoReplacedOrg:({alias:r,backedUpFrom:s,now:l})=>e.yes?Promise.resolve(!1):k(`${r} answered as org ${s} when this snapshot was taken and answers as org ${l} now. Write its saved values into the org it is now?`)},nextId:()=>`cli-${Date.now()}-${Math.random().toString(36).slice(2,8)}`});c.setExpiryListener(r=>process.stderr.write(`${z(r)}
92
- `)),c.setBackupRecordStore(new R(C(e.storeDir))),await c.swept(),c.setSyncRuns(S(T()));let b=r=>p.find(s=>s.correlationId===r);if(e.restoreId){let r=d.get(`backup:${e.restoreId}`);r||(process.stderr.write(`No snapshot "${e.restoreId}" in ${e.storeDir}.
93
- `),process.exit(1));let s=`cli-restore-automation-${Date.now()}`;await c.handle({id:s,type:"dataops:automation",payload:{orgId:e.org,act:"restore",objects:(r.objects??[]).map(n=>({objectApiName:n.objectApiName,records:n.recordCount??0})),...e.accord}});let l=b(s);if(l?.type!=="dataops:automation:response"){process.exitCode=1,e.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:p},null,2)}
94
- `);return}let m=l.payload;for(let n of m.lines)t(n);if(m.refusals.length>0){for(let n of m.refusals)process.stderr.write(`${v(n)}
95
- `);process.exitCode=1,e.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:p},null,2)}
96
- `);return}if(!e.yes&&!await k(`Upsert snapshot ${e.restoreId} back into ${e.org}? Records with these Ids will have their fields overwritten.`)){t("Nothing written.");return}t(`restoring ${e.restoreId} into ${e.org}${e.rewriteAll?", every row written back":""}\u2026`),await c.handle({id:`cli-restore-${Date.now()}`,type:"dataops:rollback",payload:{orgId:e.org,operationId:e.restoreId,...e.rewriteAll?{rewriteAll:!0}:{},...e.includeChanged?{includeChanged:!0}:{},...e.accord}});let h=p.find(n=>n.type==="dataops:rollback:response"),u=h?.payload??{};typeof u.message=="string"&&t(u.message),h&&y(j(u))}else{t(`snapshot ${e.org}: ${e.objects.join(", ")}`),await c.handle({id:`cli-backup-${Date.now()}`,type:"backup:execute",payload:{orgId:e.org,objects:e.objects}});let r=p.find(s=>s.type==="dataops:backup:response");if(r){let s=ee(r.payload??{});t(s.line),y(s.exitCode)}}if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:p},null,2)}
97
- `);return}let w=p[p.length-1];w&&t(`
98
- last message: ${String(w.type)}`)}function Z(o,e){return o!==void 0&&e!==void 0&&o.length>=15&&o.slice(0,15)===e.slice(0,15)}function K(o,e){let t=o.flatMap(a=>a.orgId===e&&a.organizationId!==void 0?[a.organizationId]:[]);return o.filter(a=>a.orgId===e||t.some(d=>Z(d,a.organizationId)))}function V(o){let e=o.objects.map(t=>`${t.objectApiName}:${t.recordCount}`+(t.stoppedAt!==void 0?`/${t.orgCount??"?"}(${t.stoppedAt})`:""));return`${o.operationId} ${o.timestamp} ${o.orgId??"?"} ${o.totalRecords} record(s)${o.status==="failed"?" failed part-way":""} ${e.join(" ")}`}function Y(o){return{tool:"sandforge-backup",snapshots:o.map(e=>({operationId:e.operationId,timestamp:e.timestamp,...e.orgId!==void 0?{orgId:e.orgId}:{},...e.organizationId!==void 0?{organizationId:e.organizationId}:{},totalRecords:e.totalRecords,...e.status!==void 0?{status:e.status}:{},objects:e.objects}))}}function ee(o){let e=String(o.operationId??"?"),t=(o.objects??[]).filter(i=>i.truncated===!0),a=`snapshot ${e}: ${String(o.totalRecords??0)} record(s)`;if(o.partial!==!0&&t.length===0)return{line:`${a} (--restore ${e} puts them back)`,exitCode:0};let d=t.map(i=>`${i.objectApiName} ${i.recordCount} of ${i.orgCount??"?"}`+(i.stoppedAt!==void 0?` (${i.stoppedAt})`:""));return{line:`${a} (partial: ${d.join(", ")||"an object holds fewer records than the org"})`,exitCode:3}}process.argv[1]?.includes("sandforge-backup")&&(N(),X().then(()=>process.exit(process.exitCode??0)).catch(o=>{process.stderr.write(`${o instanceof Error?o.message:String(o)}
99
- `),process.exit(1)}));export{X as main,Q as parseArgs,Y as snapshotListing,ee as snapshotTaken};
90
+ `),process.exit(2));let s=U(o("--max-age-days")),d=W(e),u=A.filter(l=>e.includes(l));u.length>0&&f===void 0&&(process.stderr.write(`${u.join(", ")} go${u.length===1?"es":""} with --restore.
91
+ `),process.exit(2));let m={objects:c,restoreId:f,storeDir:o("--store",_())??"",...p!==void 0?{maxRecords:Number(p)}:{},rewriteAll:b,includeChanged:w,...s!==void 0?{maxAgeDays:s}:{},yes:e.includes("--yes"),json:e.includes("--json"),accord:d};return n?r?{...m,list:!0,org:n}:{...m,list:!1,org:n}:{...m,list:!0}}async function V(t=process.argv){let e=K(t),o=s=>{process[e.json?"stderr":"stdout"].write(`${s}
92
+ `)},i=P(e.storeDir);if(i!==void 0){process.stderr.write(`${i}
93
+ `),process.exitCode=1;return}o(`store: ${e.storeDir}`);let n=T(H(e.storeDir,"snapshots.json"));if(e.list){let s=n.getKeysByPrefix("backup:").map(u=>n.get(u)),d=e.org!==void 0?q(s,e.org):s;if(e.json){process.stdout.write(`${JSON.stringify(oe(d),null,2)}
94
+ `);return}d.length===0&&o(e.org!==void 0?`No snapshot of ${e.org} in this store.`:"No snapshot in this store.");for(let u of d.map(ee))o(u);return}let r=await S(e.org),c=await new J().validateConnection(r.accessToken,r.instanceUrl),f={alias:r.alias,orgType:j({isSandbox:c.isSandbox,edition:c.orgType}),metadata:{apiVersion:"66.0",edition:c.orgType}},h=[],p=new R({log:s=>o(` ${s}`),broker:{postToWebview:s=>{h.push(s);let d=String(s.type??"");(d.endsWith(":error")||d.includes("failed"))&&(o(` ! ${JSON.stringify(s.payload??s)}`),process.exitCode=1)}},orgManager:{getOrg:()=>f},orgRegistry:{getCredentials:async()=>({accessToken:r.accessToken,instanceUrl:r.instanceUrl})},configStore:n,services:{getSandforgeSetting:z(e)},infraServices:{productionGuard:F(o,e.org),confirmRestoreIntoReplacedOrg:s=>e.yes?(process.stderr.write(`${te(s)}
95
+ `),Promise.resolve(!1)):k(`${s.alias} answered as org ${s.backedUpFrom} when this snapshot was taken and answers as org ${s.now} now. Write its saved values into the org it is now?`)},nextId:()=>`cli-${Date.now()}-${Math.random().toString(36).slice(2,8)}`});p.setExpiryListener(s=>process.stderr.write(`${M(s)}
96
+ `)),p.setBackupRecordStore(new D(N(e.storeDir))),await p.swept(),p.setSyncRuns(C(L()));let b=s=>h.find(d=>d.correlationId===s);if(e.restoreId){let s=n.get(`backup:${e.restoreId}`);s||(process.stderr.write(`No snapshot "${e.restoreId}" in ${e.storeDir}. "${x("backup")} --list --org ${e.org} --store ${e.storeDir}" names those it keeps; a snapshot taken with another --store, or with SANDFORGE_JOURNAL_DIR set otherwise, is restored with that --store. Nothing was written.
97
+ `),process.exit(1));let d=`cli-restore-automation-${Date.now()}`;await p.handle({id:d,type:"dataops:automation",payload:{orgId:e.org,act:"restore",objects:(s.objects??[]).map(a=>({objectApiName:a.objectApiName,records:a.recordCount??0})),...e.accord}});let u=b(d);if(u?.type!=="dataops:automation:response"){process.exitCode=1,e.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:h},null,2)}
98
+ `);return}let m=u.payload;for(let a of m.lines)o(a);if(m.refusals.length>0){for(let a of m.refusals)process.stderr.write(`${v(a)}
99
+ `);process.exitCode=1,e.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:h},null,2)}
100
+ `);return}if(!e.yes&&!await k(`Upsert snapshot ${e.restoreId} back into ${e.org}? Records with these Ids will have their fields overwritten.`)){o("Nothing written.");return}o(`restoring ${e.restoreId} into ${e.org}${e.rewriteAll?", every row written back":""}\u2026`),await p.handle({id:`cli-restore-${Date.now()}`,type:"dataops:rollback",payload:{orgId:e.org,operationId:e.restoreId,...e.rewriteAll?{rewriteAll:!0}:{},...e.includeChanged?{includeChanged:!0}:{},...e.accord}});let l=h.find(a=>a.type==="dataops:rollback:response"),g=l?.payload??{};typeof g.message=="string"&&o(g.message),l&&y(O(g))}else{o(`snapshot ${e.org}: ${e.objects.join(", ")}`),await p.handle({id:`cli-backup-${Date.now()}`,type:"backup:execute",payload:{orgId:e.org,objects:e.objects}});let s=h.find(d=>d.type==="dataops:backup:response");if(s){let d=re(s.payload??{});o(d.line),y(d.exitCode)}}if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-backup",posted:h},null,2)}
101
+ `);return}let w=h[h.length-1];w&&o(`
102
+ last message: ${String(w.type)}`)}function Y(t,e){return t!==void 0&&e!==void 0&&t.length>=15&&t.slice(0,15)===e.slice(0,15)}function q(t,e){let o=t.flatMap(i=>i.orgId===e&&i.organizationId!==void 0?[i.organizationId]:[]);return t.filter(i=>i.orgId===e||o.some(n=>Y(n,i.organizationId)))}function ee(t){let e=t.objects.map(o=>`${o.objectApiName}:${o.recordCount}`+(o.stoppedAt!==void 0?`/${o.orgCount??"?"}(${o.stoppedAt})`:""));return`${t.operationId} ${t.timestamp} ${t.orgId??"?"} ${t.totalRecords} record(s)${t.status==="failed"?" failed part-way":""} ${e.join(" ")}`}function te(t){return`${t.alias} answered as org ${t.backedUpFrom} when this snapshot was taken, and answers as org ${t.now} now: a sandbox refreshed since, or another org. --yes does not answer whether to write the snapshot's values into the org it is now, and counts as no: nothing is written. Run the restore again without --yes, in a terminal, to answer it.`}function oe(t){return{tool:"sandforge-backup",snapshots:t.map(e=>({operationId:e.operationId,timestamp:e.timestamp,...e.orgId!==void 0?{orgId:e.orgId}:{},...e.organizationId!==void 0?{organizationId:e.organizationId}:{},totalRecords:e.totalRecords,...e.status!==void 0?{status:e.status}:{},objects:e.objects}))}}function re(t){let e=String(t.operationId??"?"),o=(t.objects??[]).filter(r=>r.truncated===!0),i=`snapshot ${e}: ${String(t.totalRecords??0)} record(s)`;if(t.partial!==!0&&o.length===0)return{line:`${i} (--restore ${e} puts them back)`,exitCode:0};let n=o.map(r=>`${r.objectApiName} ${r.recordCount} of ${r.orgCount??"?"}`+(r.stoppedAt!==void 0?` (${r.stoppedAt})`:""));return{line:`${i} (partial: ${n.join(", ")||"an object holds fewer records than the org"})`+se(o),exitCode:3}}var $=1e6;function se(t){let e=t.filter(r=>r.stoppedAt==="cap"&&r.orgCount!==void 0),o=e.filter(r=>(r.orgCount??0)<=$),i=e.filter(r=>(r.orgCount??0)>$),n=[];if(o.length>0){let r=Math.max(...o.map(c=>c.orgCount??0));n.push(`--max-records ${r} takes ${o.map(c=>c.objectApiName).join(", ")} whole`)}if(i.length>0){let r=i.map(c=>c.objectApiName).join(", ");n.push(`No snapshot holds more than ${$} records of one object: ${r} ${i.length===1?"is":"are"} not whole, and a restore puts back only what it holds; Data Export, in Setup, or a Bulk API query keeps a copy of it`)}return t.some(r=>r.stoppedAt==="not_reached"||r.stoppedAt==="failure")&&n.push("Run it again for an object not reached"),n.length>0?`. ${n.join(". ")}`:""}process.argv[1]?.includes("sandforge-backup")&&(E(),V().then(()=>process.exit(process.exitCode??0)).catch(t=>{process.stderr.write(`${t instanceof Error?t.message:String(t)}
103
+ `),process.exit(1)}));export{V as main,K as parseArgs,te as replacedOrgYesWords,oe as snapshotListing,re as snapshotTaken};
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import"./chunk-RFEO2KAN.mjs";import{b as tt}from"./chunk-ALUFROGA.mjs";import{b as Qe,n as et}from"./chunk-TBZMC2VV.mjs";import{e as ne}from"./chunk-5QKTYCWE.mjs";import{a as Ke,b as J,c as Ye,d as V,f as Xe,i as Ze,k as re}from"./chunk-LQ4DRFUH.mjs";import{f as ze}from"./chunk-57VHUYNG.mjs";import"./chunk-5O6JOMHS.mjs";import{a as We,b as qe}from"./chunk-HUMEKZT5.mjs";import"./chunk-MYTIL2JD.mjs";import{e as nt}from"./chunk-TNXUU6W7.mjs";import"./chunk-IC2C2GOF.mjs";import"./chunk-VGW4MXXZ.mjs";import"./chunk-JVL444U5.mjs";import"./chunk-KLX67VPL.mjs";import"./chunk-5CD257T7.mjs";import"./chunk-5AJRHRXA.mjs";import"./chunk-42RER7V4.mjs";import"./chunk-LRFAIUN7.mjs";import"./chunk-OQOZAPCI.mjs";import"./chunk-RSYICMZG.mjs";import"./chunk-IAZB4WIL.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-XEFDB2R4.mjs";import"./chunk-H45UXY6G.mjs";import"./chunk-WRU5FJFC.mjs";import"./chunk-GMY5427L.mjs";import"./chunk-GNC27UEU.mjs";import"./chunk-YBU4Z4QV.mjs";import{a as ot}from"./chunk-TW3N6W5Z.mjs";import"./chunk-5P4PHJRL.mjs";import{a as Ge,b as ae,c as Je}from"./chunk-QROPNEGY.mjs";import{b as Q,e as Ie}from"./chunk-BZ24IAP5.mjs";import{c as ee}from"./chunk-AV5SWEHP.mjs";import"./chunk-4GL773D5.mjs";import"./chunk-SRQDABQ2.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-LV6G4XTK.mjs";import"./chunk-HJKM3E56.mjs";import"./chunk-XCA5AONB.mjs";import"./chunk-WR2GIKWE.mjs";import{hb as Pe}from"./chunk-YMJVMFPY.mjs";import"./chunk-ALJVEUUS.mjs";import"./chunk-CE6ZDGBB.mjs";import"./chunk-4HFRHFGQ.mjs";import{a as Be,n as Fe,o as Ue}from"./chunk-342FN7AO.mjs";import"./chunk-BOGNK4LV.mjs";import"./chunk-36U7IQ6Y.mjs";import"./chunk-XETCPL7E.mjs";import"./chunk-K2FBZIXY.mjs";import"./chunk-Z7X534S4.mjs";import{C as Le}from"./chunk-6QSM2WIH.mjs";import"./chunk-WJY54JO7.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-DBFJB2B6.mjs";import{H as Me,e as G,i as _e}from"./chunk-NEVXIGR6.mjs";import"./chunk-NTDN2JQZ.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-F74IHMGL.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-Y5CGXLUB.mjs";import"./chunk-3F5YMM2F.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-SAR5622P.mjs";import{a as Ne}from"./chunk-L776PUMV.mjs";import{A as te,q as Oe,u as Te}from"./chunk-6MUEPV7M.mjs";import"./chunk-HJC7AIBK.mjs";import"./chunk-OTWRDD6L.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-TYYOBZMU.mjs";import"./chunk-RH3N2H7P.mjs";import"./chunk-ZUTYVST5.mjs";import"./chunk-55HEMHEG.mjs";import"./chunk-P42X3B4D.mjs";import"./chunk-TUACWKIH.mjs";import{Ia as He}from"./chunk-VXHDBYMI.mjs";import"./chunk-ENLBYECD.mjs";import{k as De}from"./chunk-PA3MKJVH.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-ZLZRU6MO.mjs";import"./chunk-WIO4XO4F.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-GCOB7K5N.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-PNCONNFJ.mjs";import{ca as Ee}from"./chunk-CGWXQX75.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-SIOZXPFG.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import{a as xe,e as B,g as Ve}from"./chunk-MTMH6H2A.mjs";import{Sc as se,Vc as Se,cc as Ce,ra as je,va as Re}from"./chunk-B45CNPUX.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-SBIMVCXT.mjs";import"./chunk-NTOVCTRS.mjs";import{mkdtempSync as Jt,readFileSync as Vt,rmSync as zt}from"node:fs";import{tmpdir as Kt}from"node:os";import{join as ct,resolve as de}from"node:path";var Yt=`sandforge checkpoint \u2014 take a checkpoint of an org's data, and rewind the org to it, without the editor.
7
+ import"./chunk-74Q6DORA.mjs";import{b as ht}from"./chunk-VXQLDM4R.mjs";import{b as dt,n as ct}from"./chunk-UNJA4J37.mjs";import{e as se}from"./chunk-Q3DM32KF.mjs";import{a as it,b as z,c as st,d as V,f as at,i as rt,k as me}from"./chunk-XLXIPIEW.mjs";import{f as ot}from"./chunk-TTKXMDBN.mjs";import"./chunk-TSLJUSLW.mjs";import{a as fe,b as F,c as Xe,f as Ze}from"./chunk-KRCA6IPH.mjs";import"./chunk-5TC3QB4U.mjs";import{f as lt}from"./chunk-3F6Q5E7I.mjs";import"./chunk-IC2C2GOF.mjs";import"./chunk-VGW4MXXZ.mjs";import"./chunk-2BA2XKAY.mjs";import"./chunk-OAZRPP4I.mjs";import"./chunk-JEERQRLW.mjs";import"./chunk-HOJYWTP7.mjs";import"./chunk-R3X3LV64.mjs";import"./chunk-E5ZB3LU5.mjs";import"./chunk-EFR2Y7E4.mjs";import"./chunk-O2HDYYUV.mjs";import"./chunk-M3ROUWDX.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-ZM6OJGIG.mjs";import"./chunk-MHMH6MTP.mjs";import"./chunk-COFG7Q6R.mjs";import"./chunk-GMY5427L.mjs";import"./chunk-PJ5I73CK.mjs";import"./chunk-BKDV4ENO.mjs";import"./chunk-X5JYBPXP.mjs";import{a as ut}from"./chunk-TW3N6W5Z.mjs";import"./chunk-5P4PHJRL.mjs";import{a as et,b as pe,c as tt}from"./chunk-QROPNEGY.mjs";import{b as ne,e as Ue}from"./chunk-BZ24IAP5.mjs";import{a as te,b as he}from"./chunk-SCKUIE3R.mjs";import{c as oe}from"./chunk-AV5SWEHP.mjs";import"./chunk-YRQGKDHM.mjs";import"./chunk-MJU2PGZQ.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-LWW4U276.mjs";import"./chunk-MJVTDA5Q.mjs";import"./chunk-XCA5AONB.mjs";import"./chunk-WR2GIKWE.mjs";import{hb as qe}from"./chunk-2CNCDM56.mjs";import"./chunk-SIHORWVK.mjs";import"./chunk-CE6ZDGBB.mjs";import"./chunk-B5QQJ4SI.mjs";import{a as Je,n as ze,o as Ve}from"./chunk-NZC67CGR.mjs";import"./chunk-BOGNK4LV.mjs";import"./chunk-4VS2V6WU.mjs";import"./chunk-KYEDBS54.mjs";import"./chunk-6XYKJSGX.mjs";import"./chunk-K2FBZIXY.mjs";import"./chunk-F43REJDZ.mjs";import{C as He}from"./chunk-JPUR2CFX.mjs";import"./chunk-LPBMBW3O.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-DBFJB2B6.mjs";import{G as Ke,J as Ye,e as J,i as ue}from"./chunk-IFETCRWE.mjs";import"./chunk-PZPJKATS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-DYFALGRT.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-7FFGJWHN.mjs";import"./chunk-G35N4P7D.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-SAR5622P.mjs";import{a as _e}from"./chunk-KDGMAGQR.mjs";import{B as ie,r as Be,v as Ge}from"./chunk-MFG4MUIO.mjs";import"./chunk-EQNW3UC2.mjs";import"./chunk-GSKCGQIP.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-TYYOBZMU.mjs";import"./chunk-HS4YRX4J.mjs";import"./chunk-ZUTYVST5.mjs";import"./chunk-CU2INBND.mjs";import"./chunk-YKKRIEH4.mjs";import"./chunk-TUACWKIH.mjs";import{Ia as Qe}from"./chunk-VYXMVJL5.mjs";import"./chunk-AEKONPF4.mjs";import{k as We}from"./chunk-JWTSEDIQ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-CION3VMZ.mjs";import"./chunk-WIO4XO4F.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-GCOB7K5N.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-L77FJZEP.mjs";import{ca as Me}from"./chunk-A527W53V.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-GGD7ON3M.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import{a as Fe,e as B,g as nt}from"./chunk-MTMH6H2A.mjs";import{Vc as le,Yc as Te,fc as Pe,ta as De,xa as Le,y as Ie}from"./chunk-TTFDUKUS.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-MS4FJDFD.mjs";import"./chunk-NTOVCTRS.mjs";import{mkdtempSync as nn,readFileSync as on,rmSync as sn}from"node:fs";import{tmpdir as an}from"node:os";import{join as kt,resolve as we}from"node:path";var rn=`sandforge checkpoint \u2014 take a checkpoint of an org's data, and rewind the org to it, without the editor.
8
8
 
9
9
  Usage:
10
10
  npx sandforge checkpoint <command> --org <alias> [options]
@@ -41,8 +41,9 @@ take:
41
41
  Customize Application
42
42
  --ignore-field <Object.Field> do not compare a field, nor write it back (one your automation sets
43
43
  on every save); repeat for more
44
- --max-total <n> refuse, before reading, more than <n> records (default: ${We})
45
- --keep-days <n> when it expires (default: ${G}; 0 keeps it until deleted)
44
+ --max-total <n> refuse, before reading, more than <n> records (default: ${fe},
45
+ ${F} at most)
46
+ --keep-days <n> when it expires (default: ${J}; 0 keeps it until deleted)
46
47
  --estimate say the records, API requests, time and disk it would take, then stop
47
48
  preview, rewind, undo, delete, export:
48
49
  --checkpoint <id|name|latest> which one (default: latest, for undo the one the last rewind went
@@ -127,7 +128,7 @@ import:
127
128
  --key-env <VAR> read the key from this environment variable; without it the key
128
129
  is asked on the terminal, not echoed, and with no terminal it
129
130
  stops, exit 2, having imported nothing
130
- --keep-days <n> when it expires on this machine (default: ${G}; 0 keeps it until
131
+ --keep-days <n> when it expires on this machine (default: ${J}; 0 keeps it until
131
132
  deleted)
132
133
  Options:
133
134
  --store <dir> where checkpoints live (default: ~/.sandforge/checkpoints, or
@@ -340,14 +341,14 @@ were kept, each said with why); 4 unstable (someone else changed
340
341
  records during the rewind or the undo: left as they made them); 130, 143, 129 Ctrl-C, SIGTERM or
341
342
  SIGHUP stopped it \u2014 run rewind again: it takes up from what still differs, and undo still reaches
342
343
  the state before it.
343
- `,Xt=["take","list","preview","rewind","undo","delete","export","import"],Zt=e=>Xt.includes(e),x={switches:["--json"],values:["--org","--store"]},Qt={take:{words:1,switches:[...x.switches,"--estimate"],values:[...x.values,"--name","--object","--exclude-object","--custom-setting","--ignore-field","--max-total","--keep-days"]},list:{words:1,...x},preview:{words:1,switches:[...x.switches,"--fail-on-change"],values:[...x.values,"--checkpoint","--object"]},rewind:{words:1,switches:[...x.switches,"--dry-run","--accept-automation","--accept-emails","--mute-automation","--accept-no-undo","--accept-recreate","--accept-outside","--accept-unseen","--refuse-when-active","--yes"],values:[...x.values,"--checkpoint","--ignore-field","--object","--max-records"]},undo:{words:1,switches:[...x.switches,"--accept-automation","--accept-emails","--mute-automation","--yes"],values:[...x.values,"--checkpoint"]},delete:{words:1,switches:[...x.switches,"--all","--yes"],values:[...x.values,"--checkpoint"]},export:{words:1,switches:x.switches,values:[...x.values,"--checkpoint","--out","--key-env"]},import:{words:1,switches:x.switches,values:[...x.values,"--file","--key-env","--keep-days"]}},en={name:"--name",objects:"--object",excluded:"--exclude-object",customSettings:"--custom-setting",ignoredFields:"--ignore-field",maxTotal:"--max-total",keepDays:"--keep-days"},tn=/^[A-Za-z][A-Za-z0-9_]{0,79}$/;function O(e){process.stderr.write(`${e}
344
- `),process.exit(2)}function nn(e){let n=e.toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function on(e,n=new Date){let t=e.slice(2);(t.includes("--help")||t.includes("-h"))&&(process.stdout.write(Yt),process.exit(0));let o=t[0];if(o===void 0||o.startsWith("-"))return O("Name the command first: take, list, preview, rewind, undo, delete, export or import. Run with --help.");if(!Zt(o))return O(`"${o}" is not a command of sandforge checkpoint: take, list, preview, rewind, undo, delete, export or import. Nothing was run. Run with --help.`);xe(t,Qt[o]);let i=h=>{let l=[];for(let m=1;m<t.length;m++){if(t[m]!==h)continue;let g=t[m+1];if(g===void 0||g.startsWith("--"))return O(`${h} wants a value.`);l.push(g),m++}return l},a=h=>{let l=i(h);return l.length>1&&O(`${h} is given ${l.length} times: give it once.`),l[0]},c=h=>{let l=a(h);if(l!==void 0)return/^\d{1,15}$/.test(l)||O(`${h} takes a whole number, not "${l}".`),Number(l)},s=a("--store"),r={storeRoot:s!==void 0?de(s):_e(),json:t.includes("--json")},p=a("--org"),w=()=>p??O(`${o} needs --org. Run with --help.`),k=h=>{t.includes("--yes")&&(h===void 0&&O(`${o} --yes needs --checkpoint <id|name>: one that does not ask is told which checkpoint it acts on. Nothing was run.`),h==="latest"&&O(`${o} --yes needs the checkpoint named by its id or its name, not latest: a checkpoint taken since would be the one it acts on. Nothing was run.`))},$=()=>{let h=i("--object"),l=h.find(m=>!tn.test(m));return l!==void 0&&O(`--object takes an object's API name, not "${l}".`),h.filter((m,g)=>h.findIndex(A=>A.toLowerCase()===m.toLowerCase())===g)};switch(o){case"list":return{...r,command:o,...p!==void 0?{org:p}:{}};case"take":{let h=w(),l=i("--object"),m=i("--exclude-object"),g=i("--custom-setting"),A=g.includes("all")?"all":g,d=i("--ignore-field"),f=c("--max-total"),j={name:a("--name")??nn(n),mode:l.length>0?"picked":"everything",...l.length>0?{objects:l}:{},...m.length>0?{excluded:m}:{},...A.length>0?{customSettings:A}:{},...d.length>0?{ignoredFields:d}:{},...f!==void 0?{maxTotal:f}:{},keepDays:c("--keep-days")??G},C=Pe.safeParse({...j,orgId:"command-line"});if(!C.success){let S=C.error.issues[0],_=String(S?.path[0]??"");return O(`${en[_]??_}: ${S?.message??"not read"}. Nothing was run.`)}return{...r,command:o,org:h,take:{...j,name:C.data.name},estimate:t.includes("--estimate")}}case"preview":return{...r,command:o,org:w(),checkpoint:a("--checkpoint")??"latest",failOnChange:t.includes("--fail-on-change"),objects:$()};case"rewind":{let h=w(),l=a("--checkpoint");k(l);let m=i("--ignore-field"),g=Re.safeParse(m);if(!g.success)return O(`--ignore-field: ${g.error.issues[0]?.message??"not read"}. Nothing was run.`);let A=c("--max-records");return A===0&&O('--max-records takes a whole number of 1 or more, not "0". Nothing was run.'),{...r,command:o,org:h,checkpoint:l??"latest",objects:$(),dryRun:t.includes("--dry-run"),acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),acceptNoUndo:t.includes("--accept-no-undo"),acceptRecreate:t.includes("--accept-recreate"),acceptOutside:t.includes("--accept-outside"),acceptUnseen:t.includes("--accept-unseen"),...A!==void 0?{maxRecords:A}:{},refuseWhenActive:t.includes("--refuse-when-active"),ignoreFields:m,yes:t.includes("--yes")}}case"undo":{let h=w(),l=a("--checkpoint");return k(l),{...r,command:o,org:h,...l!==void 0?{checkpoint:l}:{},acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),yes:t.includes("--yes")}}case"delete":{let h=w(),l=a("--checkpoint"),m=t.includes("--all");return m&&l!==void 0&&O("Give --checkpoint or --all, not both."),{...r,command:o,org:h,...m?{}:{checkpoint:l??"latest"},all:m,yes:t.includes("--yes")}}case"export":{let h=w(),l=a("--out")??O("export needs --out <file>. Run with --help."),m=it(a("--key-env"));return{...r,command:o,org:h,checkpoint:a("--checkpoint")??"latest",out:de(l),...m!==void 0?{keyEnv:m}:{}}}case"import":{let h=w(),l=a("--file")??O("import needs --file <file>. Run with --help."),m=it(a("--key-env"));return{...r,command:o,org:h,file:de(l),...m!==void 0?{keyEnv:m}:{},keepDays:c("--keep-days")??G}}}}function it(e){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||ne(e)!==void 0?O("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}function ht(e,n){return e!==void 0&&n!==void 0&&e.length>=15&&e.slice(0,15)===n.slice(0,15)}function M(e,n,t){let o=t!==void 0?[t]:[];for(let i of e){let a=i.checkpoint?.org;a!==void 0&&(a.alias===n||a.username.toLowerCase()===n.toLowerCase())&&o.push(i.organizationId)}return e.filter(i=>o.some(a=>ht(a,i.organizationId)))}function X(e,n,t,o){if(je.safeParse(t).success){let a=e.find(c=>c.checkpointId===t);return a?{entry:a}:{none:`No checkpoint ${t} is kept on this machine.`}}if(t==="latest"){let a=n[0];return a?{entry:a}:{none:`No checkpoint of ${o} is kept on this machine.`}}let i=n.filter(a=>a.checkpoint?.name===t);return i.length===1?{entry:i[0]}:i.length===0?{none:`No checkpoint of ${o} named '${t}' is kept on this machine.`}:{ambiguous:`${i.length} checkpoints of ${o} are named '${t}': give the id of the one you mean with --checkpoint (${i.map(a=>a.checkpointId).join(", ")}).`}}function fe(e){if(e.valid)return;let n=e.checkpoint?`'${e.checkpoint.name}'`:e.checkpointId;switch(e.why){case"damaged":return{code:"DAMAGED",message:`The file of checkpoint ${e.checkpointId} cannot be read: it can only be deleted.`};case"taking":return{code:"TAKING",message:`The checkpoint ${n} is being taken, or its take never ended: it can be previewed once taken, or deleted.`};case"failed":return{code:"FAILED",message:`The take of checkpoint ${n} failed: it can only be deleted.`};case"refreshed":return{code:"OTHER_ORG",message:`This sandbox was refreshed${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}: it is another org now, and the checkpoint ${n} is of the org before it. It can only be deleted.`};case"scratchExpired":return{code:"SCRATCH_EXPIRED",message:`The scratch org of checkpoint ${n} has expired: its checkpoints can only be deleted.`};default:return{code:"INVALID",message:`The checkpoint ${n} cannot be previewed.`}}}var u=e=>e.toLocaleString("en-US");function N(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function ce(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,19)} UTC`}var F=e=>`${He(e/(1024*1024))} MB`;function y(e,n=8){if(e.length===0)return"\u2014";let t=e.slice(0,n).join(", ");return e.length>n?`${t} \u2026 (+${e.length-n})`:t}function K(e){return e.objects.reduce((n,t)=>n+t.records,0)}function pe(e){return e===null?"kept until you delete it":`kept until ${N(e)}`}function q(e){return e.org.alias??e.org.username}var sn=/^Left out(?::\s*|\s+(?=as asked\b))/;function lt(e){let n=new Map;for(let{objectApiName:t,reason:o}of e)n.set(o,[...n.get(o)??[],t]);return[...n].map(([t,o])=>` left out: ${y(o)} \u2014 ${t.replace(sn,"")}`)}var an={fls:"hidden from the user SandForge connects as by field-level security: Rewind won\u2019t put them back",encrypted:"encrypted, and the user SandForge connects as can\u2019t view encrypted data: Rewind won\u2019t touch them",base64:"the content of files and other binary values, which a checkpoint doesn\u2019t hold",compound:"compound fields, kept through the fields they are made of"};function ut(e){let n=new Map;for(let t of e)for(let{field:o,reason:i}of t.leftOutFields)n.set(i,[...n.get(i)??[],`${t.objectApiName}.${o}`]);return[...n].map(([t,o])=>` fields left out (${o.length}): ${y(o)} \u2014 ${an[t]??t}`)}function ft(e){let n=e.filter(t=>!t.undeletable).map(t=>t.objectApiName);return n.length===0?[]:[` deleted ${y(n)} records come back from the recycle bin only with their parent`]}function pt(e){return` about ${u(e.seconds)} s \xB7 about ${u(e.apiRequests)} API requests of the ${u(e.apiRequestsLeft)} left today`+(e.bytes>0?` \xB7 about ${F(e.bytes)} on this machine`:"")}var st={damaged:"its file cannot be read: it can only be deleted",taking:"being taken, or its take never ended: it can only be deleted unless it ends",failed:"its take failed: it can only be deleted",refreshed:"of the org before its refresh: it can only be deleted",scratchExpired:"its scratch org has expired: it can only be deleted"};function rn(e,n){if(e.length===0)return[`No checkpoint is kept in ${n}.`];let t=[];for(let o of e){let i=o.checkpoint;if(!i){t.push(`${o.checkpointId} ${st.damaged}`);continue}if(t.push(`${o.checkpointId} '${i.name}' ${q(i)} taken ${N(i.takenAt)} ${u(K(i))} records in ${i.objects.length} objects ${F(i.bytes)} `+pe(i.expiresAt)),!o.valid){let a=o.why==="refreshed"&&o.refreshedAt?`refreshed on ${o.refreshedAt.slice(0,10)}: `:"";t.push(` ${a}${st[o.why??""]??"it cannot be previewed"}`)}o.expiresSoon&&i.expiresAt!==null&&t.push(` expires on ${N(i.expiresAt)}: take a new one, or keep this one in the editor`),o.binReachSince&&t.push(` records deleted before ${o.binReachSince.slice(0,10)} can't come back with their Id (recycle bin), sooner if the bin fills: a rewind makes them again, with new Ids`),o.undo&&t.push(` rewound: the rewind can be undone until ${N(o.undo.until)}`)}return t}function dn(e){let n=e.checkpoint;return{id:e.checkpointId,name:n?.name??null,org:n?q(n):null,organizationId:e.organizationId,takenAt:n?.takenAt??null,records:n?K(n):null,bytes:n?.bytes??null,expiresAt:n?n.expiresAt:null,expiresSoon:e.expiresSoon===!0,binReachSince:e.binReachSince??null,...n?.lastRewind?{lastRewind:{...n.lastRewind,undoable:e.undo!==void 0}}:{},valid:e.valid,...e.why!==void 0?{why:e.why}:{},...e.refreshedAt!==void 0?{refreshedAt:e.refreshedAt}:{}}}function mt(e){return e.refusal!==void 0&&e.objects.length===0&&e.leftOut.length===0}function cn(e){return mt(e)?{mode:e.mode,refusal:e.refusal}:{...e}}function hn(e,n){if(mt(n))return[`refused: ${n.refusal.message}`];let t=n.objects.filter(i=>i.records>0).length,o=new Map;for(let{namespace:i}of n.objects)i!==void 0&&o.set(i,(o.get(i)??0)+1);return[`a checkpoint of ${e} would keep ${n.objects.length} objects (${t} hold records; ${n.objects.length-t} are empty \u2014 what is created there later is caught too), about ${u(n.estimate.records)} records`,...[...o].map(([i,a])=>` includes ${a} objects of the ${i} package`),pt(n.estimate),...lt(n.leftOut),...ut(n.objects),...ft(n.objects),...n.files?un(n.files):[],...ln(n),...n.refusal?[`refused: ${n.refusal.message}`]:[]]}function wt(e){let n=e.records===void 0?void 0:`${u(e.records)} ${e.records===1?"row":"rows"}`,t=[e.kind,n].filter(o=>o!==void 0);return t.length>0?`${e.objectApiName} (${t.join(", ")})`:e.objectApiName}function gt(e){return wt({objectApiName:e.objectApiName,...e.customSetting!==void 0?{kind:e.customSetting}:{},records:e.records})}function ln(e){let n=e.objects.filter(i=>i.customSetting!==void 0),t=new Set(n.map(i=>i.objectApiName)),o=(e.customSettings??[]).filter(i=>!t.has(i.objectApiName));return[...n.length>0?[` custom settings kept: ${y(n.map(gt))} \u2014 a rewind sets their rows back as the checkpoint holds them, whoever changed them since`]:[],...o.length>0?[` custom settings not kept: ${y(o.map(wt))} \u2014 --custom-setting <ApiName|all> keeps them`]:[]]}function un(e){return e.held?[" files: it keeps which files are attached to its records (Salesforce Files, classic attachments) and each file's latest version, not its content; a rewind deletes the files attached to them since and brings back those deleted since. A file attached to no record it holds, a user's own or a library's, is left as it is",...kt(e.addedToPicked),...e.queryAllFiles?[]:[me]]:[" files: not kept \u2014 a rewind leaves the files attached since as they are"]}function kt(e){return e.length>0?[` added to the objects picked: ${e.join(", ")} \u2014 without them a rewind would leave the files attached since as they are`]:[]}var me=" the user the alias connects as doesn't have Query All Files: other users' files that no record of the checkpoint is attached to (in a library the user is not a member of, say) are not seen, nor counted among the files left; files attached to its records are seen";function fn(e,n,t=[]){let o=e.movedWhileTaken,i=o.changed+o.deleted+o.created;return[`taken '${e.name}' (${e.checkpointId}) of ${q(e)}: ${u(K(e))} records in ${e.objects.length} objects, ${F(e.bytes)} on this machine, ${pe(e.expiresAt)}`,` of ${ce(e.readFrom)}, read until ${ce(e.takenAt)} on the org's clock`,...i>0?[` ${u(i)} records changed while it was taken (${o.changed} changed, ${o.deleted} deleted, ${o.created} created): it holds them as they were read, and a rewind treats them as changed since. Take checkpoints when nobody works in the org.`]:[],...lt(e.scope.leftOut),...ut(e.objects),...e.ignoredFields.length>0?[` not compared, nor written back (you chose): ${e.ignoredFields.join(", ")}`]:[],...ft(e.objects),...pn(e.objects),...e.files?mn(e,e.files,t):[],` it holds the records' values unencrypted, in files only you can read: ${n}`]}function pn(e){let n=e.filter(t=>t.customSetting!==void 0);return n.length===0?[]:[` custom settings kept: ${y(n.map(gt))} \u2014 a rewind sets their rows back as the checkpoint holds them`]}function mn(e,n,t){let o=n.readByIds??[],i=new Set(t.map(s=>s.toLowerCase())),a=new Set(e.objects.map(({objectApiName:s})=>s.toLowerCase())),c=e.scope.mode==="picked"?De.filter(s=>a.has(s.toLowerCase())&&!i.has(s.toLowerCase())):[];return[` files: ${u(n.anchored)} attached to its records by ${u(n.links)} link(s): a rewind takes back what is attached to them since`,...kt(c),...o.length>0?[` the links of ${y(o)} were read by lists of record Ids: ${q(e)} refused one query, or answered too late`]:[],...e.takenBy.queryAllFiles===!1?[me]:[]]}function wn(e,n){let t=Object.entries(e.byPhase).map(([i,a])=>{let c=n?.requestsByPhase?.[i];return c===void 0||c===a?`${i} ${a}`:`${i} ${a} (${c})`}),o=n?`, about ${u(n.apiRequests)} estimated`:"";return` sent ${u(e.total)} API requests to the org${o}: ${t.join(", ")}`}var at=e=>e.toDelete.createdSince+e.toDelete.broughtBackSince+e.toDelete.comesBackWithParent,H=e=>e.toBringBack.inBin+e.toBringBack.withParent+e.toBringBack.deletedWhileTaken,he=e=>e.cannotUndo.reduce((n,t)=>n+t.count,0),z=e=>e.toRecreate??0,oe=e=>e.toBringBack.carriers??0;function bt(e){let n=e.files;return n===void 0?0:n.unlink+n.relink+n.updateLinks}function gn(e){let n=e.files;return n===void 0?0:n.outsideAdded+n.outsideDeleted}function kn(e){let n=e.schemaDrift;return n===void 0?0:n.removed.length+(n.hidden?.length??0)+(n.uncertain?.fields.length??0)}function we(e){let n=J(e);return n.toDelete+n.toGiveBack+n.toBringBack+n.toRecreate>0||bt(e)+gn(e)>0||e.objects.some(t=>he(t)>0||t.unexplained>0||kn(t)>0)||e.unread.length>0}var bn={goneForGood:"deleted since and no longer in the recycle bin, and not made again \u2014 a file, whose body the checkpoint does not hold, or a record deleted while it was taken: they can\u2019t come back",convertedLead:"leads converted since: Salesforce can\u2019t unconvert a lead",activatedContract:"contracts activated since: Salesforce won\u2019t set them back to Draft",deletedWithCreatedParent:"deleted with a parent created since that Salesforce does not undelete on its own: they come back with that parent only",deletedWithParentOutside:"deleted with their parent, a record of an object the checkpoint does not hold: they come back with that parent only, which a checkpoint that holds its object brings back",newFileVersion:"files given a new version since: Salesforce deletes no version and won\u2019t make an older one the latest again, so they keep their new content; the content each had is still in its version history, and their titles are given back",deletedByOther:"deleted since by another user: only View All Data and Modify All Data restore those; they stay in the recycle bin, never made again",outOfReach:"out of reach: without View All Data and Modify All Data, nothing shows what others deleted of an object held through the records it hangs from; they may be in the recycle bin out of sight, and are never made again"},yn=[{reason:"onlyWithParent",preview:"Salesforce undeletes them only with their parent, and their parent stays",result:"Salesforce undeletes them only with their parent"},{reason:"deletedBeforeParent",preview:"deleted before a record they point at, which the rewind deletes next: Salesforce cannot bring them back after that",result:"deleted before a record they point at, which the rewind deleted next: Salesforce cannot bring them back after that"}];function yt(e){return yn.flatMap(n=>{let t=e.filter(o=>(o.reason??"onlyWithParent")===n.reason);return t.length>0?[{words:n,of:t}]:[]})}function $n(e,n){let{automation:t,deliverability:o}=n;if(!t||!o)return[];let i=V(n.diff),{line:a}=Ue({act:"rewind",orgName:e,automation:t,steps:i,accepted:!0,mayMute:!1,...Fe({automation:t,steps:i}),reading:o.reading}).gate;return a!==void 0?[` ${a}`]:[]}function vn(e,n){return n.map(t=>{let o=[...new Set(t.objects.flatMap(a=>a.sentBy))],i=` emails: ${e}'s automation sends about ${Be(t.emails,t.limit)} as the rewind writes (${y(o,4)})`+(t.alertsCounted?`, its email alerts among them: ${e} counts them against its single emails, as a Developer Edition does`:"");return t.verdict==="unread"?`${i}; what it has left today could not be read (${t.unread??""})`:t.verdict==="fits"?`${i}; ${t.remaining??0} of ${t.max??0} left today`:`${i}, more than the ${t.remaining??0} of ${t.max??0} left today: a rewind is refused`})}function An(e,n){if(!e||n.length===0)return"";let t=se(e,{giveBack:n}).map(o=>`${o.objectApiName}: '${o.name}'`);return t.length>0?`, on which runs ${y(t,4)}`:""}function jn(e,n,t=[]){let o=e.objects.filter(s=>Ee[s.objectApiName]!==void 0),i=o.filter(s=>z(s)>0),a=o.filter(s=>H(s)>0&&!t.includes(s.objectApiName)),c=[];return i.length>0&&c.push(` made as drafts first: ${y(i.map(s=>`${s.objectApiName} ${u(z(s))}`))} \u2014 Salesforce refuses an order or a contract made past Draft, and an order takes its products only as a draft: one past Draft at the checkpoint is made at the org's Draft status, the records under it next, then given its status back, an update`+An(n,i.map(s=>s.objectApiName))),a.length>0&&c.push(` if Salesforce answers that an order or a contract to bring back is no longer in the recycle bin, --accept-recreate makes it again as a draft, then gives it its status back, an update: ${y(a.map(s=>`${s.objectApiName} ${u(H(s))}`))}`),c}function Rn(e,n,t=!1){if(!n)return{objects:[],fired:[]};let o=V(e),i=[],a=new Set;for(let c of e.objects){if(H(c)===0)continue;let s=Xe(n,o,[c.objectApiName],t);if(!(s.fired.length===0&&!s.blind)){i.push(c.objectApiName);for(let r of s.fired)a.add(`${r.objectApiName}: '${r.name}'`)}}return{objects:i,fired:[...a]}}function Cn(e,n,t){let o=se(n,t),i=[];for(let c of n.objects){let s=o.filter(k=>k.objectApiName===c.objectApiName),r=[...new Set(s.filter(k=>k.kind!=="trigger").map(k=>`'${k.name}'`))],p=[...new Set(s.filter(k=>k.kind==="trigger").map(k=>k.name))],w=[...r.length>0?[`${r.length} flow(s) or rule(s): ${y(r,4)}`]:[],...p.length>0?[`${p.length} Apex trigger(s): ${y(p,4)}`]:[]];w.length>0&&i.push(` ${c.objectApiName}: ${w.join("; ")}`)}return[...i.length>0?[` what ${e} runs as a rewind writes (updates, deletes, records brought back):`]:[],...i,...n.unread.map(c=>` not read of its automation: ${c.part} \u2014 ${c.reason}`)]}function $t(e,n,t,o="the user SandForge connects as",i=!1){let{diff:a}=t,c=J(a),s=[`Rewind ${e} to '${n.name}' (${N(n.takenAt)}), read at ${ce(a.readAt)}:`,` ${u(c.toDelete)} to delete \xB7 ${u(c.toGiveBack)} to give back \xB7 ${u(c.toBringBack)} to bring back`+(c.toRecreate>0?` \xB7 ${u(c.toRecreate)} to make again`:"")];!we(a)&&!a.objects.some(d=>d.outside.length>0)&&s.push(` ${e} is as it was at '${n.name}' among the objects and fields it holds: nothing to rewind.`);let r=a.objects.filter(d=>at(d)+d.toGiveBack.records+H(d)+z(d)+he(d)>0);if(r.length>0){let d=Math.max(6,...r.map(f=>f.objectApiName.length));s.push(` ${"Object".padEnd(d)} ${"Delete".padStart(8)} ${"Give back".padStart(9)} ${"Bring back".padStart(10)} ${"Can't undo".padStart(10)}`);for(let f of r)s.push(` ${f.objectApiName.padEnd(d)} ${u(at(f)).padStart(8)} ${u(f.toGiveBack.records).padStart(9)} ${u(H(f)).padStart(10)} ${u(he(f)).padStart(10)}`)}let p=new Map;for(let d of a.objects)for(let[f,j]of Object.entries(d.lastChangedBy))p.set(f,(p.get(f)??0)+j);p.size>0&&s.push(` last changed by: ${[...p].sort((d,f)=>f[1]-d[1]).map(([d,f])=>`${a.userNames[d]??d} ${u(f)}`).join(" \xB7 ")}`),a.activeLastHour.length>0&&s.push(` people working in ${e} in the last hour: ${a.activeLastHour.map(d=>a.userNames[d]??d).join(", ")}`);let w=a.objects.filter(d=>d.touched>0);w.length>0&&s.push(` touched since but holding their checkpoint values: ${y(w.map(d=>`${d.objectApiName} ${u(d.touched)}`))}`);let k=a.objects.filter(d=>oe(d)>0);k.length>0&&s.push(` brought back for a moment: ${y(k.map(d=>`${d.objectApiName} ${u(oe(d))}`))} \u2014 records the checkpoint does not hold that took records of it along when deleted since: Salesforce gives those back with them only, so they come back, then go back to the recycle bin with what came back with them; what the org runs on them runs twice`);let $=new Map;for(let d of a.objects)for(let f of d.cannotUndo)f.count!==0&&$.set(f.reason,[...$.get(f.reason)??[],`${d.objectApiName} ${u(f.count)}`]);for(let[d,f]of $)s.push(` can't be taken back: ${y(f)} \u2014 ${bn[d]??d}`);let h=a.objects.filter(d=>z(d)>0);h.length>0&&s.push(` to make again, with new Ids: ${y(h.map(d=>`${d.objectApiName} ${u(z(d))}`))} \u2014 deleted since and no longer in the recycle bin: made again from the checkpoint, the lookups it holds that named them naming the new Ids; anything outside Salesforce that names their old Ids no longer finds them`);let l=c.toBringBack>0?Rn(a,t.automation,i):void 0;if(l){let d=l.fired.length>0?`making them again runs ${y(l.fired,4)}`:"what runs as they are made again could not all be read";s.push(" if Salesforce answers that a record to bring back is no longer in the recycle bin \u2014 it still lists one emptied from it as deleted \u2014, --accept-recreate makes it again with a new Id, with what was to come back with it; without it, the rewind leaves them and names them"+(l.objects.length>0?`; ${y(l.objects)} records it leaves all the same, with what was to come back with them, and names them: ${d}, which this rewind does not ask about \u2014 a rewind after it counts them to make again, and asks`:""))}s.push(...jn(a,t.automation,l?.objects));let m=a.objects.filter(d=>d.unexplained>0);m.length>0&&s.push(` left as they are: ${y(m.map(d=>`${d.objectApiName} ${u(d.unexplained)}`))} \u2014 records the checkpoint doesn't hold although they're dated before it (a load with back-dated creation dates?); a rewind deletes nothing it cannot prove was created since`);for(let{words:d,of:f}of yt(a.undoCannot))s.push(` undo couldn't bring back: ${y(f.map(j=>`${j.objectApiName} ${u(j.count)}`))} \u2014 ${d.preview}`);for(let{objectApiName:d,children:f,records:j}of a.unseen??[])s.push(` also deleted with them, out of sight: deleting ${u(j)} ${d} also deletes what ${o} can't see under them in ${y(f)}; Rewind can't count those, and deletes them only with --accept-unseen`);for(let d of a.objects)for(let f of d.outside)s.push(d.objectApiName===vt&&f.objectApiName===Sn?` also attached outside the checkpoint: ${u(f.parents)} file(s) it deletes, by ${u(f.count)} link(s) to a library, a group or a record of another object \u2014 deleting them removes them from there as well`:` also deleted with them, outside the checkpoint: ${u(f.count)} ${f.objectApiName} created under ${u(f.parents)} ${d.objectApiName}`);s.push(...On(e,a));let g=a.objects.flatMap(d=>{let f=d.schemaDrift,j=new Set([...f?.removed??[],...f?.hidden??[],...f?.uncertain?.fields??[]]);return d.notCompared.filter(C=>!j.has(C)).map(C=>`${d.objectApiName}.${C}`)});g.length>0&&s.push(` not compared (you chose): ${y(g)}`);for(let d of a.objects){let f=d.schemaDrift;if(!f)continue;let j=C=>C.map(S=>`${d.objectApiName}.${S}`);f.removed.length>0&&s.push(` fields deleted since: ${y(j(f.removed))} \u2014 restore them from Deleted Fields, then rewind`),(f.hidden??[]).length>0&&s.push(` fields hidden from ${o} by field-level security since: ${y(j(f.hidden??[]))} \u2014 rewind does not put them back; give ${o} read and edit access to them, then rewind again`),f.uncertain!==void 0&&f.uncertain.fields.length>0&&s.push(` fields gone from what ${e} shows ${o}: ${y(j(f.uncertain.fields))} \u2014 deleted since (restore them from Deleted Fields within 15 days), or hidden by field-level security (give ${o} read and edit access); rewind does not put them back`+(f.uncertain.reason!==void 0?` (which, ${e} would not say: ${f.uncertain.reason})`:"")),f.added.length>0&&s.push(` fields added since, their values left alone: ${y(j(f.added))}`),f.changed.length>0&&s.push(` fields changed since, tried one by one: ${y(j(f.changed))}`)}let A=a.fieldsNotChecked??0;A>0&&s.push(` fields not checked for changes in ${u(A)} objects nothing changed in: a rewind writes nothing there`);for(let d of a.unread)s.push(` could not be read: ${d.objectApiName} \u2014 ${d.reason} (never taken for unchanged)`);return t.automation&&s.push(...Cn(e,t.automation,V(a))),t.emails&&s.push(...vn(e,t.emails)),t.emailsUncounted!==void 0&&s.push(` emails: not counted, ${t.emailsUncounted} could not be read \u2014 what they send as the rewind writes is not known; --accept-automation covers it`),s.push(...$n(e,t)),s.push(pt(t.estimate)),t.refusal&&s.push(` a rewind now would be refused (${t.refusal.code}): ${t.refusal.message}`),s}var vt="ContentDocument",Sn="ContentDocumentLink";function On(e,n){let t=n.files;if(t===void 0)return[];let o=[];t.unlink>0&&o.push(` links to remove: ${u(t.unlink)} added since between a file and a record that both stay \u2014 the file stays, no longer attached to that record`),t.relink>0&&o.push(` links to put back: ${u(t.relink)} removed since between a file and a record that both stay, each under a new Id: Salesforce keeps no removed link in the recycle bin`),t.updateLinks>0&&o.push(` links to give their sharing back: ${u(t.updateLinks)} \u2014 who sees the file from the record, and with what access; a link to an account keeps its access, which Salesforce doesn't let change`),t.outsideAdded>0&&o.push(` kept: ${u(t.outsideAdded)} file(s) added since, as no record of this checkpoint links to them (a user's own, a library's)`),t.outsideDeleted>0&&o.push(` left in the recycle bin: ${u(t.outsideDeleted)} file(s) deleted since, as no record of this checkpoint linked to them`);let i=n.objects.find(s=>s.objectApiName===vt),a=i===void 0?0:H(i),{storage:c}=t;return a>0&&c.bringBack>0&&o.push(` file storage: bringing back ${u(a)} file(s) takes ${F(c.bringBack)} again; `+(c.remaining===void 0?`${e} did not say how much it has left`:`${e} has ${F(c.remaining)} left`)),c.undo>0&&o.push(` undo would bring back the files this rewind deletes: ${F(c.undo)} of file storage again`),t.blindSpot&&o.push(me),o}function At(e,n,t,o,i){let a=o?.diff??i?.diff??t.diff;return{checkpoint:{id:n.checkpointId,name:n.name,takenAt:n.takenAt,org:e},...o?{objects:[...o.plan.objects]}:{},...J(a),carriers:a.objects.reduce((c,s)=>c+oe(s),0),differs:we(o?.diff??t.diff),...o?{selection:o.plan}:{},...i?{kept:i.plan.left}:{},diff:t.diff,estimate:t.estimate,...t.automation?{automation:t.automation}:{},...t.emails?{emails:t.emails}:{},...t.emailsUncounted!==void 0?{emailsUncounted:t.emailsUncounted}:{},...t.deliverability?{deliverability:t.deliverability}:{},...t.refusal?{refusal:t.refusal}:{}}}function xn(e,n){return n&&we(e)?3:0}var jt={needsUnpickedParent:"they come back only with a parent this rewind leaves deleted, or look up a record it leaves deleted, which Salesforce refuses: those lookups are left, the rest written",heldByUnpicked:"records of an object not named made since hang from them and hold some of their values in place: given back but for those",outsideNotAccepted:"records of an object not named made since hang from them, which their deletion would take along: kept, unless --accept-outside",holdsLeft:"records this rewind leaves as they are hang from them, which their deletion would take along: kept",keyTaken:"rows of a custom setting whose owner or name a row made since holds: brought back once it is gone"};function Rt(e){let n=[` limited to ${e.objects.join(", ")}: the other objects are left as they are, and what still differs in them is counted apart`],t=e.acts.filter(o=>!o.picked&&o.toDelete>0);t.length>0&&n.push(` also deletes again ${y(t.map(o=>`${o.objectApiName} ${u(o.toDelete)}`))} \u2014 made since, they come back with a record it brings back: leaving them would make a state that never existed`);for(let o of e.left)n.push(` left: ${u(o.count)} ${o.objectApiName} record(s) \u2014 ${jt[o.reason]}`);return e.needs.length>0&&n.push(` to rewind those too, add ${e.needs.map(o=>`--object ${o.objectApiName} (${u(o.records)} record(s) need it)`).join(", ")}`),e.acts.some(o=>o.picked&&o.toDelete>0)&&n.push(" a record of an object not named that looks up a record it deletes has that lookup emptied by Salesforce, and is dated that second"),n}function Ct(e,n,t){return!t&&e.scope.mode==="picked"&&n.objects.some(o=>o.outside.length>0)}function St(e){return e.left.map(n=>` kept: ${u(n.count)} ${n.objectApiName} record(s) \u2014 `+(n.reason==="outsideNotAccepted"?"records outside the checkpoint made since hang from them, which their deletion would take along: kept, unless --accept-outside":jt[n.reason]))}async function Ot(e,n,t,o){if(!Ct(n,t,o))return;let i=n.objects.map(({objectApiName:a})=>a);return ge(e,t,i,!1)}function xt(e,n){let t=new Map(e.objects.map(({objectApiName:i})=>[i.toLowerCase(),i])),o=n.filter(i=>!t.has(i.toLowerCase()));if(o.length>0)throw new b({code:"NOT_HELD",message:`--object: '${e.name}' holds no ${o.join(", ")}. It holds ${y(e.objects.map(i=>i.objectApiName))}. Nothing was run.`},2);return n.flatMap(i=>t.get(i.toLowerCase())??[])}async function ge(e,n,t,o){let i=await e.request({type:"checkpoint:plan-selection",payload:{checkpointId:n.checkpointId,previewId:n.previewId,objects:[...t],acceptOutside:o},timeoutMs:ie});if(i.outcome!=="answered")throw new b(P(i,"The plan of the objects named"));let a=D(i).plan;return{plan:a,diff:Ye(n,a)}}var Y={limit:e=>`--max-records ${e}`,mutes:!0,lift:{acceptAutomation:"give --accept-automation to rewind all the same",acceptEmails:"add --accept-emails to rewind all the same",acceptNoUndo:"give --accept-no-undo to rewind all the same",acceptRecreate:"give --accept-recreate to rewind all the same",acceptUnseen:"give --accept-unseen to rewind all the same",maxRecords:"read its preview (--dry-run), then give a --max-records that holds it",refuseWhenActive:"rewind once they are done, or without --refuse-when-active"}};function Nn(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(et,Y.lift.acceptAutomation)}:e}function In(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(tt,"give --accept-automation to undo the rewind all the same")}:e}function Io(e,n,t,o="the user SandForge connects as"){return Ze(e,n,t,Y.lift,o,Y.mutes)}var En={acceptAutomation:!1,acceptNoUndo:!1,acceptRecreate:!1};function Nt(e,n){return[...e?[e]:[],...n.filter(t=>t.code!==e?.code)]}function Dn(e,n,t,o){let i=o!==void 0&&o.length>0?`${o.join(", ")} of ${e}`:e,a=J(t),c=a.toRecreate>0?`, and makes ${u(a.toRecreate)} record(s) the recycle bin no longer holds again, with new Ids`:"",s=t.objects.reduce((k,$)=>k+oe($),0),r=s>0?`, with ${u(s)} record(s) brought back for a moment that had taken records of the checkpoint along, then deleted again`:"",p=bt(t),w=p>0?`, and puts ${u(p)} link(s) between files and records back as they were`:"";return`Rewind ${i} to '${n.name}': it deletes the ${u(a.toDelete)} record(s) created since ${N(n.takenAt)}, gives ${u(a.toGiveBack)} record(s) their values from then back, and brings back ${u(a.toBringBack)} record(s) from the recycle bin${r}${c}${w} \u2014 whoever made these changes. What it changes is kept, so it can be undone. Type ${e} to rewind it:`}var R=(e,n)=>e.reduce((t,o)=>t+n(o),0);function ke(e){let n=R(e.deleted,s=>s.deleted),t=R(e.deleted,s=>s.planned),o=R(e.restored,s=>s.restored+(s.restoredWithout??0)),i=R(e.restored,s=>s.planned),a=R(e.undeleted,s=>s.undeleted+s.alreadyBack),c=R(e.undeleted,s=>s.planned);return{deleted:{planned:t,done:n,left:Math.max(0,t-n-R(e.deleted,s=>s.alreadyGone))},givenBack:{planned:i,done:o,left:Math.max(0,i-o-R(e.restored,s=>s.alreadyGone))},broughtBack:{planned:c,done:a,left:Math.max(0,c-a)}}}function It(e){let n=e.recreated??[],t=R(n,i=>i.planned),o=R(n,i=>i.created);return{planned:t,done:o,left:Math.max(0,t-o)}}function Pn(e){return(e.remade??[]).reduce((n,t)=>{let o=R(e.deleted.filter(i=>i.objectApiName===t.objectApiName),i=>i.deleted);return n+Math.min(o,t.count)},0)}function Et(e,n){return e===void 0?"another user":n[e]??e}function Ln(e,n,t){switch(n.reason){case"automation":return e==="rewind"?"kept by your automation, which sets them again on save: rewind --ignore-field <Object.Field> stops comparing such a field":"set again on save by your automation, since the undo gave them back their values";case"changedDuringRewind":return`changed during the ${e} by ${Et(n.by,t)}: left as they made them`;case"changedSincePreview":return"changed since the preview: rewind again to take them";case"refused":return`refused: ${n.message??"the org gave no reason"}`;case"notInBin":return"no longer in the recycle bin \u2014 emptied from it, or kept there for good \u2014: Salesforce still lists them as deleted but will not bring them back; --accept-recreate makes them again with new Ids";case"goneForGood":return"deleted since and no longer in the recycle bin, and not made again (a file, whose body the checkpoint does not hold, or a record deleted while it was taken): they can't come back";case"kept":return n.message??"kept as they are"}}function Dt(e,n){return`Stopped before it wrote anything: ${e} is as it was before this rewind. Rewind again to rewind it to '${n}'.`}function Tn(e,n,t,o={}){let i=R(t.residual,h=>h.count),a=t.residual.filter(h=>h.reason==="changedDuringRewind"),c={success:`${e} is back at '${n.name}': read again, nothing differs among the objects and fields it holds.`,partial:`${e} is back at '${n.name}' but for ${u(i)} record(s) that still differ, each said with why:`,unstable:`Someone kept writing to ${e} during the rewind: ${[...new Set(a.map(h=>Et(h.by,o)))].join(", ")} changed ${u(R(a,h=>h.count))} record(s), left as they made them. Rewind again once they have stopped.`,failure:`Nothing of the rewind of ${e} to '${n.name}' went through: what still differs is said with why:`,cancelled:t.undo===void 0?Dt(e,n.name):`Stopped part way: ${e} is between '${n.name}' and now. Rewind again to finish: it takes up from what still differs, and undo still returns ${e} to how it was before the rewind.`},s=t.scope;s!==void 0&&t.status==="success"&&(c.success=`${s.objects.join(", ")} of ${e} ${s.objects.length>1?"are":"is"} back at '${n.name}': read again, nothing differs among them.`);let r=ke(t),p=R(t.undeleted,h=>h.alreadyBack),w=[c[t.status]];if(s!==void 0){let{objects:h,records:l}=s.notRewound;w.push(l>0?` not rewound: ${u(l)} record(s) of ${y(h)} still differ, left as they are \u2014 the rewind was limited to the objects named; add them with --object`:" the objects not named match the checkpoint too")}r.deleted.done>0&&w.push(` deleted ${u(r.deleted.done)} record(s) added since the checkpoint \u2014 created, or brought back from the recycle bin they were in when it was taken \u2014 (in the recycle bin for up to 15 days)`),r.givenBack.done>0&&w.push(` gave ${u(r.givenBack.done)} record(s) back their checkpoint values`),r.broughtBack.done>0&&w.push(` brought back ${u(r.broughtBack.done-p)} record(s) deleted since the checkpoint, with their original Ids`+(p>0?`, and ${u(p)} that came back with them`:""));let k=t.status==="failure"?[]:t.carriers??[];if(k.length>0){let h=y(k.map(l=>`${l.objectApiName} ${u(l.count)}`));w.push(t.status==="cancelled"?` of them, brought back for a moment: ${h} \u2014 records the checkpoint does not hold that had taken records of it along; stopped before it was through, those it had not deleted again yet are still in the org: rewind again deletes them, with what came back with them`:` of them, brought back for a moment and deleted again: ${h} \u2014 records the checkpoint does not hold that had taken records of it along, back in the recycle bin with what came back with them`)}let $=It(t);$.done>0&&w.push(` made again ${u($.done)} record(s) the recycle bin no longer held, with new Ids`);for(let h of t.draftsLeft??[])w.push(` left as drafts: ${h.objectApiName} ${u(h.count)} (${y(h.ids,3)}) \u2014 made again as drafts, the rewind stopped before it gave them back the status the checkpoint holds: rewind again gives it back to them, an update`);if(w.push(...Lt("rewind",e,t)),w.push(...Tt("rewind",t,o)),t.undo){w.push(` undo it until ${N(t.undo.until)}, sooner if the recycle bin fills: undo --org ${e} --checkpoint ${n.checkpointId}`);for(let{words:h,of:l}of yt(t.undo.cannot))w.push(` undo couldn't bring back: ${y(l.map(m=>`${m.objectApiName} ${u(m.count)}`))} \u2014 ${h.result}`)}for(let h of t.removedJournals??[])w.push(` removed the journal of rewind ${h.rewindId} of '${h.name}': undo reaches the last rewind of the org alone`);return w.push(Bt(t)),w}function Pt(e){return`Stopped before it wrote anything: ${e} is as the rewind left it, and the rewind can still be undone.`}function Bn(e,n,t){let o=R(t.restored,l=>l.keptChanged)+R(t.deleted,l=>l.keptChanged),i=R([...t.deleted,...t.restored,...t.undeleted],l=>l.refused),a=R(t.residual,l=>l.count)+i,c=`${e} is back as it was before its rewind to '${n.name}'`,s={success:`${c}.`,partial:o>0&&a===0?`${c}, except ${u(o)} record(s) changed since the rewind, left as they are now.`:`${c}, except ${u(a+o)} record(s), each said with why:`,unstable:`Someone changed records of ${e} during the undo: left as they made them, each said below.`,failure:`Nothing of the undo of ${e}'s rewind went through: its reasons are said below.`,cancelled:Ce(t)?Pt(e):`Stopped part way: ${e} is between the rewind and how it was before it. Undo again to finish: it takes up what this one left.`},r=ke(t),p=[s[t.status]],w=Pn(t),k=R(t.wentAlong??[],l=>l.count),$=r.deleted.done-w-k;$>0&&p.push(` sent back to the recycle bin ${u($)} record(s) the rewind brought back`+(k>0?", with what came back with them":"")),w>0&&p.push(` deleted again ${u(w)} record(s) the rewind made again, with what went with them`);let h=t.carriedAlone??[];return h.length>0&&p.push(` of them, back in the recycle bin on their own: ${y(h.map(l=>`${l.objectApiName} ${u(l.count)}`))} \u2014 they had gone there with a record the rewind brought back for a moment, which stays there; they come back alone, under the parent the checkpoint gave them`),r.broughtBack.done>0&&p.push(` brought back ${u(r.broughtBack.done)} record(s) the rewind deleted`),r.givenBack.done>0&&p.push(` gave ${u(r.givenBack.done)} record(s) back the values they had before the rewind`),o>0&&p.push(` kept ${u(o)} record(s) changed since the rewind: undo leaves them as they are now`),p.push(...Lt("undo",e,t)),p.push(...Tt("undo",t,{})),p.push(Bt(t)),p}function Lt(e,n,t){let o=t.files;if(o===void 0)return[];let i=e==="rewind"?{unlinked:"removed {n} link(s) added since between files and records: the files stay",relinked:"put back {n} link(s) removed since between files and records, under new Ids",linksUpdated:"gave {n} link(s) between files and records their sharing back"}:{unlinked:"removed again {n} link(s) between files and records the rewind put back",relinked:"put back {n} link(s) between files and records the rewind removed, under new Ids",linksUpdated:"gave {n} link(s) between files and records back the sharing they had before the rewind"},a=["unlinked","relinked","linksUpdated"].filter(c=>o[c]>0).map(c=>` ${i[c].replace("{n}",u(o[c]))}`);return o.linksRefused>0&&a.push(` ${n} refused to write ${u(o.linksRefused)} link(s) between files and records`),a}function Tt(e,n,t){let o=n.residual.map(i=>` ${i.objectApiName} ${u(i.count)} \u2014 ${Ln(e,i,t)}`);if(e==="undo")for(let i of[...n.deleted,...n.restored,...n.undeleted])i.refused!==0&&o.push(` ${i.objectApiName} ${u(i.refused)} \u2014 refused: ${i.reasons[0]??"the org gave no reason"}`);for(let i of n.unread??[])o.push(` could not be read again: ${i.objectApiName} \u2014 ${i.reason} (never taken for unchanged)`);return o}function Bt(e){return` sent ${u(e.apiRequests.used)} API requests to the org; ${u(e.apiRequests.leftToday)} left today`}function Ft(e,n,t,o,i){let a=new Map,c=r=>{let p=a.get(r);return p||(p={object:r,deleted:0,givenBack:0,broughtBack:0,refused:0},a.set(r,p)),p};for(let r of o.deleted)c(r.objectApiName).deleted+=r.deleted,c(r.objectApiName).refused+=r.refused;for(let r of o.restored)c(r.objectApiName).givenBack+=r.restored+(r.restoredWithout??0),c(r.objectApiName).refused+=r.refused;for(let r of o.undeleted)c(r.objectApiName).broughtBack+=r.undeleted+r.alreadyBack,c(r.objectApiName).refused+=r.refused;for(let r of o.recreated??[])c(r.objectApiName).refused+=r.refused;let s=(o.unread??[]).map(r=>({object:r.objectApiName,reason:r.reason}));return{checkpoint:{id:t.checkpointId,name:t.name,takenAt:t.takenAt,org:n},rewindId:o.rewindId,status:o.status,...o.scope?{limitedTo:[...o.scope.objects],notRewound:{...o.scope.notRewound}}:{},...ke(o),...e==="rewind"?{recreated:It(o),cannotUndo:(i?.objects??[]).flatMap(r=>r.cannotUndo.filter(p=>p.count>0).map(p=>({object:r.objectApiName,reason:p.reason,count:p.count})))}:{},...e==="rewind"&&(o.carriers??[]).length>0?{carriers:(o.carriers??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...e==="rewind"&&(o.draftsLeft??[]).length>0?{draftsLeft:(o.draftsLeft??[]).map(r=>({object:r.objectApiName,count:r.count,ids:[...r.ids]}))}:{},...e==="undo"&&(o.carriedAlone??[]).length>0?{carriedAlone:(o.carriedAlone??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...o.files?{files:{...o.files}}:{},...o.undo?{undo:{until:o.undo.until,cannot:o.undo.cannot.map(r=>({object:r.objectApiName,count:r.count,...r.reason!==void 0?{reason:r.reason}:{}}))}}:{},verify:{differences:R(o.residual,r=>r.count)+s.length,stable:o.status!=="unstable",passes:o.passes,notCompared:[...t.ignoredFields]},residual:o.residual.map(r=>({object:r.objectApiName,reason:r.reason,...r.by!==void 0?{by:r.by}:{},count:r.count,...r.message!==void 0?{message:r.message}:{}})),unread:s,objects:[...a.values()],apiRequests:o.apiRequests,result:o}}function Ut(e,n){switch(e){case"success":return 0;case"partial":return 3;case"unstable":return 4;case"failure":return 1;case"cancelled":return n!==void 0?Q(n):1}}var Fn=10*6e4,Un=720*6e4,_t=60*6e4,ie=5*6e4,rt=200,b=class extends Error{constructor(t,o=1,i=[]){super(t.message);this.refusal=t;this.code=o;this.also=i;this.name="Stop"}refusal;code;also};function _n(e){let n=[e.refusal,...e.also];return{refusal:e.refusal,...e.also.length>0?{wouldBeRefused:n.map(t=>ee(t)),wouldBeRefusedCodes:n.map(t=>t.code)}:{}}}function D(e){return e.message?.payload??{}}function P(e,n){let t=D(e);if(e.outcome==="unanswered")return{code:"UNANSWERED",message:`${n}: no answer came in time.`};let o=typeof t.message=="string"?t.message:JSON.stringify(t);return{code:typeof t.code=="string"?t.code:e.outcome.toUpperCase(),message:o}}function Mn(e){let n=D(e).alsoRefused;return e.outcome!=="failed"||!Array.isArray(n)?[]:n.flatMap(t=>{let{code:o,message:i}=t??{};return typeof o=="string"&&typeof i=="string"?[{code:o,message:i}]:[]})}async function Wn(e=process.argv,n={}){let t=on(e),o=l=>{process[t.json?"stderr":"stdout"].write(`${l}
345
- `)},i=l=>{t.json&&process.stdout.write(`${JSON.stringify(l,null,2)}
346
- `)},a=Me({root:t.storeRoot,...n.locksDir!==void 0?{locksDir:n.locksDir}:{}});if("refusal"in a){let{reason:l,path:m}=a.refusal,g=l==="otherOwner"?`The checkpoints cannot be kept in ${m}: another user of this machine owns it, and could read and replace the checkpoints in it. Name a folder of your own with --store.`:l==="notAFolder"?`The checkpoints cannot be kept in ${m}: it is a file, not a folder.`:`The checkpoints cannot be kept in ${m}: it could not be made${a.refusal.detail?` (${a.refusal.detail})`:""}.`;process.stderr.write(`${g}
347
- `),i({refusal:{code:"STORE_REFUSED",message:g}}),B(1);return}let c=a.store,s=Jt(ct(Kt(),"sandforge-checkpoint-")),r=new ot,p=!1,w,k=()=>Promise.resolve(),$,h;try{let l=(n.createHost??nt)({storeDir:s,log:d=>{p&&d.startsWith("[INFO] ")?o(d.slice(7)):d.startsWith("[WARN] ")&&o(`warning: ${d.slice(7)}`)},compose:d=>{d.handlers.setCheckpointStore(c),d.handlers.rewindCheckpointsFromPreviewsAnswered(),d.handlers.setInfraServices({backgroundRegistry:r}),k=()=>d.handlers.sweepCheckpoints(),$=d.handlers,h=d},onPost:d=>{if(d.type!=="operation:progress")return;let f=d.payload?.currentStep;typeof f!="string"||f===w||(w=f,o(` ${f}`))}});p=!0;try{await k()}finally{p=!1}let m=async()=>{let d=await l.request({type:"checkpoint:list",timeoutMs:ie});if(d.outcome!=="answered")throw new b(P(d,"The list of checkpoints"));return D(d).checkpoints??[]},g=async d=>{try{return await l.connect(d)}catch(f){throw new b({code:"NOT_CONNECTED",message:f instanceof Ne?f.message:`${d} could not be reached: ${f instanceof Error?f.message:String(f)}`})}},A=async d=>{if(h===void 0)throw new Error("The host composed no handlers.");return qe(await Oe(d.id,h.orgRegistry,h.orgManager)).userId()};switch(t.command){case"list":{let d=await m(),f=t.org!==void 0?M(d,t.org):d;for(let j of rn(f,c.root))o(j);i(f.map(dn));return}case"take":await Vn(t,l,await g(t.org),c,r,o,i);return;case"preview":{let d=await m(),f=Z(X(d,M(d,t.org),t.checkpoint,t.org)),j=fe(f);if(j)throw new b(j);let C=f.checkpoint,S=t.objects.length>0?xt(C,t.objects):void 0,_=await g(t.org);be(_,f,C,t.org,"preview");let W=await l.request({type:"checkpoint:preview",payload:{checkpointId:f.checkpointId,...S?{objects:S}:{},acceptOutside:!1},timeoutMs:_t});if(W.outcome!=="answered")throw new b(P(W,"The preview"));let I=D(W),L=S?await ge(l,I.diff,S,!1):void 0,E=S?void 0:await Ot(l,C,I.diff,!1),v=L??E,$e=v?{...I,diff:v.diff}:I,ve=Nt(I.refusal,await re({orgName:t.org,preview:$e,bounds:{refuseWhenActive:!1},accepted:En,writers:()=>Promise.resolve([]),words:Y,user:_.username})),[Ae]=ve;for(let T of $t(t.org,C,$e,_.username))o(T);for(let T of L?Rt(L.plan):[])o(T);for(let T of E?St(E.plan):[])o(T);for(let T of ve.slice(I.refusal?1:0))o(` a rewind now would be refused (${T.code}): ${T.message}`);i(At(t.org,C,{...I,...Ae?{refusal:Ae}:{}},L,E)),B(xn(L?.diff??I.diff,t.failOnChange));return}case"rewind":case"undo":{let d={host:l,registry:r,store:c,listAll:m,connect:g,userIdOf:A,say:o,answerJson:i};t.command==="rewind"?await Kn(t,d):await Zn(t,d);return}case"delete":await zn(t,l,m,o,i);return;case"export":await Hn(t,{transfers:dt($),listAll:m,say:o,answerJson:i});return;case"import":await Gn(t,{transfers:dt($),connect:g,say:o,answerJson:i});return}}catch(l){let m=l instanceof b?l:new b({code:"FAILED",message:l instanceof Error?l.message:String(l)});process.stderr.write(`${m.message}
348
- `);for(let g of m.also)process.stderr.write(`${ee(g)}
349
- `);m.code!==2&&i(_n(m)),B(m.code)}finally{r.dispose(),zt(s,{recursive:!0,force:!0})}}function dt(e){if(e===void 0)throw new Error("The host composed no handlers.");return e}function qn(){try{let e=JSON.parse(Vt(ct(__dirname,"..","package.json"),"utf8"));return typeof e.version=="string"?e.version:"0.0.0"}catch{return"0.0.0"}}function Mt(e){let n=process.env[e];if(n===void 0||n.trim()==="")throw new b({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let t=ne(n);if(t===void 0)throw new b({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return t}function Wt(e,n){return{id:e.checkpointId,name:e.name,takenAt:e.takenAt,org:n}}async function Hn(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?Mt(e.keyEnv):void 0,a=await n.listAll(),c=Z(X(a,M(a,e.org),e.checkpoint,e.org)),s=await n.transfers.exportCheckpoint({checkpointId:c.checkpointId,out:e.out,...i!==void 0?{key:i}:{},sandforgeVersion:qn()});if(!s.exported)throw new b(s.refusal);let{checkpoint:r,header:p}=s;t(`exported '${r.name}' (${r.checkpointId}) of ${e.org}, taken ${N(r.takenAt)}: ${u(p.records)} record(s) of ${u(p.objects)} object(s), ${F(s.bytes)}, to ${e.out}`),t(` sha256 ${s.sha256}`),s.key!==void 0&&process.stderr.write(` key, shown this once and kept nowhere: ${s.key}
350
- `),t(` Anyone who has this file and its key can read the ${u(p.records)} records it holds of ${e.org}, personal data among them. Send the key another way than the file, and only to people who already see all data in ${e.org}.`),t(" The file does not expire: delete it once it has served."),o({checkpoint:Wt(r,e.org),file:e.out,bytes:s.bytes,sha256:s.sha256,records:p.records,objects:p.objects,keyShown:s.key!==void 0})}async function Gn(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?Mt(e.keyEnv):void 0,a=await n.connect(e.org),c=await n.transfers.readCheckpointImport({orgId:a.id,file:e.file});if(c.header!==void 0){let{header:w}=c;t(`the file holds checkpoint ${w.checkpointId}, taken ${N(w.takenAt)}: ${u(w.records)} record(s) of ${u(w.objects)} object(s), ${F(w.bytes)}, exported by SandForge ${w.sandforgeVersion}`)}if(!c.allowed)throw new b(c.refusal);let s=i??await Jn(),r=await n.transfers.importCheckpoint({orgId:a.id,file:e.file,key:s,keepDays:e.keepDays});if(!r.imported)throw new b(r.refusal);let{checkpoint:p}=r;t(r.outcome==="imported"?`imported '${p.name}' (${p.checkpointId}) of ${e.org}: ${u(K(p))} record(s) of ${u(p.objects.length)} object(s), ${pe(p.expiresAt)}`:`'${p.name}' (${p.checkpointId}) is kept on this machine already, the same: left as it is`);for(let w of r.warnings)t(` ${w}`);o({outcome:r.outcome,checkpoint:Wt(p,e.org),records:K(p),objects:p.objects.length,expiresAt:p.expiresAt,warnings:r.warnings})}async function Jn(){let e=await Je("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new b({code:"DECLINED",message:"No key was typed. Nothing was imported."});let n=ne(e);if(n===void 0)throw new b({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was imported."});return n}function Z(e){if("entry"in e)return e.entry;throw"ambiguous"in e?new b({code:"AMBIGUOUS",message:e.ambiguous},2):new b({code:"NOT_FOUND",message:e.none})}async function Vn(e,n,t,o,i,a,c){let{take:s}=e;if(e.estimate){let m={orgId:t.id,mode:s.mode,...s.objects?{objects:s.objects}:{},...s.excluded?{excluded:s.excluded}:{},...s.customSettings?{customSettings:s.customSettings}:{},...s.maxTotal!==void 0?{maxTotal:s.maxTotal}:{}},g=await n.request({type:"checkpoint:scope",payload:m,timeoutMs:Fn});if(g.outcome!=="answered")throw new b(P(g,"The estimate"));let A=D(g),d={mode:A.mode,objects:A.objects,leftOut:A.leftOut,estimate:A.estimate,...A.refusal?{refusal:A.refusal}:{},...A.files?{files:A.files}:{},...A.customSettings?{customSettings:A.customSettings}:{}};for(let f of hn(e.org,d))a(f);c(cn(d)),B(d.refusal?1:0);return}a(`taking a checkpoint of ${e.org}: it reads every record of its objects (Ctrl-C stops it, and nothing of it is kept)`);let{answer:r,stoppedBy:p}=await ye(i,"the take stops after the read under way, and keeps nothing",()=>n.request({type:"checkpoint:take",payload:{orgId:t.id,...s},timeoutMs:Un}));if(r.outcome!=="answered"){let m=P(r,"The take");throw p!==void 0&&m.code==="CANCELLED"?new b(m,Q(p)):new b(m)}let w=D(r),k=w.checkpoint,$=w.requests,h=w.estimate,l=o.folderOf(k.org.organizationId,k.checkpointId).dir;for(let m of fn(k,l,s.objects??[]))a(m);$&&a(wn($,h)),c({checkpoint:k,...$?{requests:$}:{},...h?{estimate:h}:{}})}async function zn(e,n,t,o,i){let a=await t(),c=M(a,e.org),s=e.checkpoint===void 0?c:[Z(X(a,c,e.checkpoint,e.org))];if(s.length===0)throw new b({code:"NOT_FOUND",message:`No checkpoint of ${e.org} is kept on this machine. Nothing was deleted.`});let r=h=>h.checkpoint?`'${h.checkpoint.name}' (${h.checkpointId})`:h.checkpointId;if(!e.yes){let h=s.filter(g=>g.undo!==void 0),m=`${s.length===1?`Delete ${r(s[0])}${s[0].checkpoint?`, taken ${N(s[0].checkpoint.takenAt)},`:""} from this machine? ${e.org} can no longer be rewound to it`:`Delete the ${s.length} checkpoints of ${e.org} from this machine (${y(s.map(r),4)})? ${e.org} can no longer be rewound to them`}${h.length>0?", and its last rewind can no longer be undone":""}. The org is not touched.`;if(!await Ge(m))throw new b({code:"DECLINED",message:"Nothing was deleted."})}let p=s.map(h=>h.checkpointId);for(let h=0;h<p.length;h+=rt){let l=await n.request({type:"checkpoint:delete",payload:{checkpointIds:p.slice(h,h+rt)},timeoutMs:ie});if(l.outcome!=="answered"){let m=P(l,"The delete");if(h===0)throw new b(m);o(`refused: ${m.message}`);break}}let w=new Set((await t()).map(h=>h.checkpointId)),k=s.filter(h=>!w.has(h.checkpointId)),$=s.filter(h=>w.has(h.checkpointId));for(let h of k)o(`deleted ${r(h)}`);for(let h of $)o(`kept ${r(h)}: a take, a rewind or an undo of its org is running; delete it once it has ended`);i({deleted:k.map(h=>h.checkpointId),kept:$.map(h=>h.checkpointId)}),$.length>0&&B(k.length>0?3:1)}function be(e,n,t,o,i){if(ht(e.orgId,n.organizationId))return;let a=M([n],o).length>0,c=i==="preview"?"preview it":i==="rewind"?"rewind to it":"undo it";throw new b({code:"OTHER_ORG",message:a?`${o} answers as another org than the one '${t.name}' was taken of: a sandbox refreshed since is another org, and this checkpoint can only be deleted. No record was read.`:`'${t.name}' is a checkpoint of ${q(t)}, not of ${o}: ${c} with --org ${q(t)}. No record was read.`})}async function ye(e,n,t){let o,i=e.onEvent((c,s,r)=>{o!==void 0&&s==="started"&&r.module==="checkpoint"&&e.abort(c)}),a=Ie(c=>{o=c,process.stderr.write(`
344
+ `,dn=["take","list","preview","rewind","undo","delete","export","import"],cn=e=>dn.includes(e),x={switches:["--json"],values:["--org","--store"]},hn={take:{words:1,switches:[...x.switches,"--estimate"],values:[...x.values,"--name","--object","--exclude-object","--custom-setting","--ignore-field","--max-total","--keep-days"]},list:{words:1,...x},preview:{words:1,switches:[...x.switches,"--fail-on-change"],values:[...x.values,"--checkpoint","--object"]},rewind:{words:1,switches:[...x.switches,"--dry-run","--accept-automation","--accept-emails","--mute-automation","--accept-no-undo","--accept-recreate","--accept-outside","--accept-unseen","--refuse-when-active","--yes"],values:[...x.values,"--checkpoint","--ignore-field","--object","--max-records"]},undo:{words:1,switches:[...x.switches,"--accept-automation","--accept-emails","--mute-automation","--yes"],values:[...x.values,"--checkpoint"]},delete:{words:1,switches:[...x.switches,"--all","--yes"],values:[...x.values,"--checkpoint"]},export:{words:1,switches:x.switches,values:[...x.values,"--checkpoint","--out","--key-env"]},import:{words:1,switches:x.switches,values:[...x.values,"--file","--key-env","--keep-days"]}},ln={name:"--name",objects:"--object",excluded:"--exclude-object",customSettings:"--custom-setting",ignoredFields:"--ignore-field",maxTotal:"--max-total",keepDays:"--keep-days"},un=/^[A-Za-z][A-Za-z0-9_]{0,79}$/;function O(e){process.stderr.write(`${e}
345
+ `),process.exit(2)}function fn(e){let n=e.toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function pn(e,n=new Date){let t=e.slice(2);(t.includes("--help")||t.includes("-h"))&&(process.stdout.write(rn),process.exit(0));let o=t[0];if(o===void 0||o.startsWith("-"))return O("Name the command first: take, list, preview, rewind, undo, delete, export or import. Run with --help.");if(!cn(o))return O(`"${o}" is not a command of sandforge checkpoint: take, list, preview, rewind, undo, delete, export or import. Nothing was run. Run with --help.`);Fe(t,hn[o]);let i=p=>{let h=[];for(let m=1;m<t.length;m++){if(t[m]!==p)continue;let k=t[m+1];if(k===void 0||k.startsWith("--"))return O(`${p} wants a value.`);h.push(k),m++}return h},s=p=>{let h=i(p);return h.length>1&&O(`${p} is given ${h.length} times: give it once.`),h[0]},d=p=>{let h=s(p);if(h!==void 0)return/^\d{1,15}$/.test(h)||O(`${p} takes a whole number, not "${h}".`),Number(h)},a=s("--store"),r={storeRoot:a!==void 0?we(a):ue(),json:t.includes("--json")},u=s("--org"),w=()=>u??O(`${o} needs --org. Run with --help.`),g=p=>{t.includes("--yes")&&(p===void 0&&O(`${o} --yes needs --checkpoint <id|name>: one that does not ask is told which checkpoint it acts on. Nothing was run.`),p==="latest"&&O(`${o} --yes needs the checkpoint named by its id or its name, not latest: a checkpoint taken since would be the one it acts on. Nothing was run.`))},$=()=>{let p=i("--object"),h=p.find(m=>!un.test(m));return h!==void 0&&O(`--object takes an object's API name, not "${h}".`),p.filter((m,k)=>p.findIndex(A=>A.toLowerCase()===m.toLowerCase())===k)};switch(o){case"list":return{...r,command:o,...u!==void 0?{org:u}:{}};case"take":{let p=w(),h=i("--object"),m=i("--exclude-object"),k=i("--custom-setting"),A=k.includes("all")?"all":k,c=i("--ignore-field"),f=d("--max-total"),j={name:s("--name")??fn(n),mode:h.length>0?"picked":"everything",...h.length>0?{objects:h}:{},...m.length>0?{excluded:m}:{},...A.length>0?{customSettings:A}:{},...c.length>0?{ignoredFields:c}:{},...f!==void 0?{maxTotal:f}:{},keepDays:d("--keep-days")??J},C=qe.safeParse({...j,orgId:"command-line"});if(!C.success){let S=C.error.issues[0],M=String(S?.path[0]??"");return O(`${ln[M]??M}: ${S?.message??"not read"}. Nothing was run.`)}return{...r,command:o,org:p,take:{...j,name:C.data.name},estimate:t.includes("--estimate")}}case"preview":return{...r,command:o,org:w(),checkpoint:s("--checkpoint")??"latest",failOnChange:t.includes("--fail-on-change"),objects:$()};case"rewind":{let p=w(),h=s("--checkpoint");g(h);let m=i("--ignore-field"),k=Le.safeParse(m);if(!k.success)return O(`--ignore-field: ${k.error.issues[0]?.message??"not read"}. Nothing was run.`);let A=d("--max-records");return A===0&&O('--max-records takes a whole number of 1 or more, not "0". Nothing was run.'),{...r,command:o,org:p,checkpoint:h??"latest",objects:$(),dryRun:t.includes("--dry-run"),acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),acceptNoUndo:t.includes("--accept-no-undo"),acceptRecreate:t.includes("--accept-recreate"),acceptOutside:t.includes("--accept-outside"),acceptUnseen:t.includes("--accept-unseen"),...A!==void 0?{maxRecords:A}:{},refuseWhenActive:t.includes("--refuse-when-active"),ignoreFields:m,yes:t.includes("--yes")}}case"undo":{let p=w(),h=s("--checkpoint");return g(h),{...r,command:o,org:p,...h!==void 0?{checkpoint:h}:{},acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),yes:t.includes("--yes")}}case"delete":{let p=w(),h=s("--checkpoint"),m=t.includes("--all");return m&&h!==void 0&&O("Give --checkpoint or --all, not both."),{...r,command:o,org:p,...m?{}:{checkpoint:h??"latest"},all:m,yes:t.includes("--yes")}}case"export":{let p=w(),h=s("--out")??O("export needs --out <file>. Run with --help."),m=ft(s("--key-env"));return{...r,command:o,org:p,checkpoint:s("--checkpoint")??"latest",out:we(h),...m!==void 0?{keyEnv:m}:{}}}case"import":{let p=w(),h=s("--file")??O("import needs --file <file>. Run with --help."),m=ft(s("--key-env"));return{...r,command:o,org:p,file:we(h),...m!==void 0?{keyEnv:m}:{},keepDays:d("--keep-days")??J}}}}function ft(e){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||se(e)!==void 0?O("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}function bt(e,n){return e!==void 0&&n!==void 0&&e.length>=15&&e.slice(0,15)===n.slice(0,15)}function W(e,n,t){let o=t!==void 0?[t]:[];for(let i of e){let s=i.checkpoint?.org;s!==void 0&&(s.alias===n||s.username.toLowerCase()===n.toLowerCase())&&o.push(i.organizationId)}return e.filter(i=>o.some(s=>bt(s,i.organizationId)))}var yt="One kept in another folder is read with --store <folder>, or with SANDFORGE_JOURNAL_DIR set as when it was taken \u2014 in a CI job, a folder its cache restores; one taken on another machine comes here by export there, then import here.";function ae(e){return`"${te("checkpoint")} list --org ${e}" names those it holds. ${yt}`}function Z(e,n,t,o){if(De.safeParse(t).success){let s=e.find(d=>d.checkpointId===t);return s?{entry:s}:{none:`No checkpoint ${t} is kept in the folder read. ${ae(o)}`}}if(t==="latest"){let s=n[0];return s?{entry:s}:{none:`No checkpoint of ${o} is kept in the folder read. ${ae(o)}`}}let i=n.filter(s=>s.checkpoint?.name===t);return i.length===1?{entry:i[0]}:i.length===0?{none:`No checkpoint of ${o} named '${t}' is kept in the folder read. `+ae(o)}:{ambiguous:`${i.length} checkpoints of ${o} are named '${t}': give the id of the one you mean with --checkpoint (${i.map(s=>s.checkpointId).join(", ")}).`}}function ve(e){if(e.valid)return;let n=e.checkpoint?`'${e.checkpoint.name}'`:e.checkpointId;switch(e.why){case"damaged":return{code:"DAMAGED",message:`The file of checkpoint ${e.checkpointId} cannot be read: it can only be deleted.`};case"taking":return{code:"TAKING",message:`The checkpoint ${n} is being taken, or its take never ended: it can be previewed once taken, or deleted.`};case"failed":return{code:"FAILED",message:`The take of checkpoint ${n} failed: it can only be deleted.`};case"refreshed":return{code:"OTHER_ORG",message:`This sandbox was refreshed${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}: it is another org now, and the checkpoint ${n} is of the org before it. It can only be deleted. `+re};case"scratchExpired":return{code:"SCRATCH_EXPIRED",message:`The scratch org of checkpoint ${n} has expired: its checkpoints can only be deleted. `+re};default:return{code:"INVALID",message:`The checkpoint ${n} cannot be previewed.`}}}var re=`${Ie.replace(/\.$/,"")} (${he("sandforge-frozen")} select, then extract).`,l=e=>e.toLocaleString("en-US");function E(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function ge(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,19)} UTC`}var _=e=>`${Qe(e/(1024*1024))} MB`;function y(e,n=8){if(e.length===0)return"\u2014";let t=e.slice(0,n).join(", ");return e.length>n?`${t} \u2026 (+${e.length-n})`:t}function Y(e){return e.objects.reduce((n,t)=>n+t.records,0)}function Ae(e){return e===null?"kept until you delete it":`kept until ${E(e)}`}function H(e){return e.org.alias??e.org.username}var mn=/^Left out(?::\s*|\s+(?=as asked\b))/;function $t(e,n){let t=[...n,...e.flatMap(({code:s,records:d})=>s==="pastTheLimit"&&d!==void 0?[d]:[])],o=t.filter(s=>s<=F).reduce((s,d)=>s+d,0),i=new Map;for(let{objectApiName:s,reason:d,code:a,records:r}of e){let u=d;if(a==="pastTheLimit"&&r!==void 0&&r<=F){let w=Ze(t,r);u=w>F?`${d} With it, every object no larger is kept, more than ${F} records in all, past any --max-total: --exclude-object <ApiName> leaves some out.`:`${d} --max-total ${w}${w===o?" or more":""} holds it.`}i.set(u,[...i.get(u)??[],s])}return[...i].map(([s,d])=>` left out: ${y(d)} \u2014 ${s.replace(mn,"")}`)}var wn={fls:"hidden from the user SandForge connects as by field-level security: Rewind won\u2019t put them back",encrypted:"encrypted, and the user SandForge connects as can\u2019t view encrypted data: Rewind won\u2019t touch them",base64:"the content of files and other binary values, which a checkpoint doesn\u2019t hold",compound:"compound fields, kept through the fields they are made of"};function vt(e){let n=new Map;for(let t of e)for(let{field:o,reason:i}of t.leftOutFields)n.set(i,[...n.get(i)??[],`${t.objectApiName}.${o}`]);return[...n].map(([t,o])=>` fields left out (${o.length}): ${y(o)} \u2014 ${wn[t]??t}`)}function At(e){let n=e.filter(t=>!t.undeletable).map(t=>t.objectApiName);return n.length===0?[]:[` deleted ${y(n)} records come back from the recycle bin only with their parent`]}function jt(e){return` about ${l(e.seconds)} s \xB7 about ${l(e.apiRequests)} API requests of the ${l(e.apiRequestsLeft)} left today`+(e.bytes>0?` \xB7 about ${_(e.bytes)} on this machine`:"")}var pt={damaged:"its file cannot be read: it can only be deleted",taking:"being taken, or its take never ended: it can only be deleted unless it ends",failed:"its take failed: it can only be deleted",refreshed:"of the org before its refresh: it can only be deleted",scratchExpired:"its scratch org has expired: it can only be deleted"};function gn(e,n,t){if(e.length===0&&t!==void 0){let i=t.kept===0?"":`, which keeps ${t.kept===1?"1 of another org":`${t.kept} of other orgs`}: "${te("checkpoint")} list" names ${t.kept===1?"it":"them"}`;return[`No checkpoint of ${t.org} is kept in ${n}${i}. ${yt}`]}if(e.length===0)return[`No checkpoint is kept in ${n}.`];let o=[];for(let i of e){let s=i.checkpoint;if(!s){o.push(`${i.checkpointId} ${pt.damaged}`);continue}if(o.push(`${i.checkpointId} '${s.name}' ${H(s)} taken ${E(s.takenAt)} ${l(Y(s))} records in ${s.objects.length} objects ${_(s.bytes)} `+Ae(s.expiresAt)),!i.valid){let d=i.why==="refreshed"&&i.refreshedAt?`refreshed on ${i.refreshedAt.slice(0,10)}: `:"";o.push(` ${d}${pt[i.why??""]??"it cannot be previewed"}`),(i.why==="refreshed"||i.why==="scratchExpired")&&o.push(` ${re}`)}i.scratchExpiresSoon&&s.org.scratchExpiresAt!==void 0&&o.push(` its scratch org expires on ${s.org.scratchExpiresAt.slice(0,10)}: its checkpoints then can only be deleted, whatever --keep-days said. To set up its data again in another org, freeze it as a Frozen Dataset before (${he("sandforge-frozen")} select, then extract)`),i.expiresSoon&&s.expiresAt!==null&&o.push(` expires on ${E(s.expiresAt)}: take a new one, or keep this one in the editor`),i.binReachSince&&o.push(` records deleted before ${i.binReachSince.slice(0,10)} can't come back with their Id (recycle bin), sooner if the bin fills: a rewind makes them again, with new Ids`),i.undo&&o.push(` rewound: the rewind can be undone until ${E(i.undo.until)}`)}return o}function kn(e){let n=e.checkpoint;return{id:e.checkpointId,name:n?.name??null,org:n?H(n):null,organizationId:e.organizationId,takenAt:n?.takenAt??null,records:n?Y(n):null,bytes:n?.bytes??null,expiresAt:n?n.expiresAt:null,expiresSoon:e.expiresSoon===!0,scratchExpiresSoon:e.scratchExpiresSoon===!0,binReachSince:e.binReachSince??null,...n?.lastRewind?{lastRewind:{...n.lastRewind,undoable:e.undo!==void 0}}:{},valid:e.valid,...e.why!==void 0?{why:e.why}:{},...e.refreshedAt!==void 0?{refreshedAt:e.refreshedAt}:{}}}function Rt(e){return e.refusal!==void 0&&e.objects.length===0&&e.leftOut.length===0}function bn(e){return Rt(e)?{mode:e.mode,refusal:e.refusal}:{...e}}function ke(e){if(e.code!=="TOO_MANY_RECORDS")return e;let n="pick fewer objects (--exclude-object <ApiName> leaves one out)",t=`(${l(fe)} unless given)`,o=e.holdingLimit,i=o===void 0?`${n}, or raise the limit with --max-total <n> ${t}`:o>F?`${n}: no --max-total holds them all, ${l(F)} at most`:`${n}, or raise the limit with --max-total ${o} ${t}`;return{...e,message:e.message.replace(/: pick fewer objects\./,`: ${i}.`)}}function yn(e,n){if(Rt(n))return[`refused: ${n.refusal.message}`];let t=n.objects.filter(i=>i.records>0).length,o=new Map;for(let{namespace:i}of n.objects)i!==void 0&&o.set(i,(o.get(i)??0)+1);return[`a checkpoint of ${e} would keep ${n.objects.length} objects (${t} hold records; ${n.objects.length-t} are empty \u2014 what is created there later is caught too), about ${l(n.estimate.records)} records`,...[...o].map(([i,s])=>` includes ${s} objects of the ${i} package`),jt(n.estimate),...$t(n.leftOut,n.objects.map(i=>i.records)),...vt(n.objects),...At(n.objects),...n.files?vn(n.files):[],...$n(n),...n.refusal?[`refused: ${ke(n.refusal).message}`]:[]]}function Ct(e){let n=e.records===void 0?void 0:`${l(e.records)} ${e.records===1?"row":"rows"}`,t=[e.kind,n].filter(o=>o!==void 0);return t.length>0?`${e.objectApiName} (${t.join(", ")})`:e.objectApiName}function St(e){return Ct({objectApiName:e.objectApiName,...e.customSetting!==void 0?{kind:e.customSetting}:{},records:e.records})}function $n(e){let n=e.objects.filter(i=>i.customSetting!==void 0),t=new Set(n.map(i=>i.objectApiName)),o=(e.customSettings??[]).filter(i=>!t.has(i.objectApiName));return[...n.length>0?[` custom settings kept: ${y(n.map(St))} \u2014 a rewind sets their rows back as the checkpoint holds them, whoever changed them since`]:[],...o.length>0?[` custom settings not kept: ${y(o.map(Ct))} \u2014 --custom-setting <ApiName|all> keeps them`]:[]]}function vn(e){return e.held?[" files: it keeps which files are attached to its records (Salesforce Files, classic attachments) and each file's latest version, not its content; a rewind deletes the files attached to them since and brings back those deleted since. A file attached to no record it holds, a user's own or a library's, is left as it is",...Ot(e.addedToPicked),...e.queryAllFiles?[]:[je]]:[" files: not kept \u2014 a rewind leaves the files attached since as they are"]}function Ot(e){return e.length>0?[` added to the objects picked: ${e.join(", ")} \u2014 without them a rewind would leave the files attached since as they are`]:[]}var je=" the user the alias connects as doesn't have Query All Files: other users' files that no record of the checkpoint is attached to (in a library the user is not a member of, say) are not seen, nor counted among the files left; files attached to its records are seen";function An(e,n,t=[]){let o=e.movedWhileTaken,i=o.changed+o.deleted+o.created;return[`taken '${e.name}' (${e.checkpointId}) of ${H(e)}: ${l(Y(e))} records in ${e.objects.length} objects, ${_(e.bytes)} on this machine, ${Ae(e.expiresAt)}`,` of ${ge(e.readFrom)}, read until ${ge(e.takenAt)} on the org's clock`,...i>0?[` ${l(i)} records changed while it was taken (${o.changed} changed, ${o.deleted} deleted, ${o.created} created): it holds them as they were read, and a rewind treats them as changed since. Take checkpoints when nobody works in the org.`]:[],...$t(e.scope.leftOut,e.objects.map(s=>s.records)),...vt(e.objects),...e.ignoredFields.length>0?[` not compared, nor written back (you chose): ${e.ignoredFields.join(", ")}`]:[],...At(e.objects),...jn(e.objects),...e.files?Rn(e,e.files,t):[],` it holds the records' values unencrypted, in files only you can read: ${n}`]}function jn(e){let n=e.filter(t=>t.customSetting!==void 0);return n.length===0?[]:[` custom settings kept: ${y(n.map(St))} \u2014 a rewind sets their rows back as the checkpoint holds them`]}function Rn(e,n,t){let o=n.readByIds??[],i=new Set(t.map(a=>a.toLowerCase())),s=new Set(e.objects.map(({objectApiName:a})=>a.toLowerCase())),d=e.scope.mode==="picked"?We.filter(a=>s.has(a.toLowerCase())&&!i.has(a.toLowerCase())):[];return[` files: ${l(n.anchored)} attached to its records by ${l(n.links)} link(s): a rewind takes back what is attached to them since`,...Ot(d),...o.length>0?[` the links of ${y(o)} were read by lists of record Ids: ${H(e)} refused one query, or answered too late`]:[],...e.takenBy.queryAllFiles===!1?[je]:[]]}function Cn(e,n){let t=Object.entries(e.byPhase).map(([i,s])=>{let d=n?.requestsByPhase?.[i];return d===void 0||d===s?`${i} ${s}`:`${i} ${s} (${d})`}),o=n?`, about ${l(n.apiRequests)} estimated`:"";return` sent ${l(e.total)} API requests to the org${o}: ${t.join(", ")}`}var mt=e=>e.toDelete.createdSince+e.toDelete.broughtBackSince+e.toDelete.comesBackWithParent,G=e=>e.toBringBack.inBin+e.toBringBack.withParent+e.toBringBack.deletedWhileTaken,be=e=>e.cannotUndo.reduce((n,t)=>n+t.count,0),K=e=>e.toRecreate??0,de=e=>e.toBringBack.carriers??0;function xt(e){let n=e.files;return n===void 0?0:n.unlink+n.relink+n.updateLinks}function Sn(e){let n=e.files;return n===void 0?0:n.outsideAdded+n.outsideDeleted}function On(e){let n=e.schemaDrift;return n===void 0?0:n.removed.length+(n.hidden?.length??0)+(n.uncertain?.fields.length??0)}function Re(e){let n=z(e);return n.toDelete+n.toGiveBack+n.toBringBack+n.toRecreate>0||xt(e)+Sn(e)>0||e.objects.some(t=>be(t)>0||t.unexplained>0||On(t)>0)||e.unread.length>0}var xn={goneForGood:"deleted since and no longer in the recycle bin, and not made again \u2014 a file, whose body the checkpoint does not hold, or a record deleted while it was taken: they can\u2019t come back",convertedLead:"leads converted since: Salesforce can\u2019t unconvert a lead",activatedContract:"contracts activated since: Salesforce won\u2019t set them back to Draft",deletedWithCreatedParent:"deleted with a parent created since that Salesforce does not undelete on its own: they come back with that parent only",deletedWithParentOutside:"deleted with their parent, a record of an object the checkpoint does not hold: they come back with that parent only, which a checkpoint that holds its object brings back",newFileVersion:"files given a new version since: Salesforce deletes no version and won\u2019t make an older one the latest again, so they keep their new content; the content each had is still in its version history, and their titles are given back",deletedByOther:"deleted since by another user: only View All Data and Modify All Data restore those; they stay in the recycle bin, never made again",outOfReach:"out of reach: without View All Data and Modify All Data, nothing shows what others deleted of an object held through the records it hangs from; they may be in the recycle bin out of sight, and are never made again"},En=[{reason:"onlyWithParent",preview:"Salesforce undeletes them only with their parent, and their parent stays",result:"Salesforce undeletes them only with their parent"},{reason:"deletedBeforeParent",preview:"deleted before a record they point at, which the rewind deletes next: Salesforce cannot bring them back after that",result:"deleted before a record they point at, which the rewind deleted next: Salesforce cannot bring them back after that"}];function Et(e){return En.flatMap(n=>{let t=e.filter(o=>(o.reason??"onlyWithParent")===n.reason);return t.length>0?[{words:n,of:t}]:[]})}function Nn(e,n){let{automation:t,deliverability:o}=n;if(!t||!o)return[];let i=V(n.diff),{line:s}=Ve({act:"rewind",orgName:e,automation:t,steps:i,accepted:!0,mayMute:!1,...ze({automation:t,steps:i}),reading:o.reading}).gate;return s!==void 0?[` ${s}`]:[]}function In(e,n){return n.map(t=>{let o=[...new Set(t.objects.flatMap(s=>s.sentBy))],i=` emails: ${e}'s automation sends about ${Je(t.emails,t.limit)} as the rewind writes (${y(o,4)})`+(t.alertsCounted?`, its email alerts among them: ${e} counts them against its single emails, as a Developer Edition does`:"");return t.verdict==="unread"?`${i}; what it has left today could not be read (${t.unread??""})`:t.verdict==="fits"?`${i}; ${t.remaining??0} of ${t.max??0} left today`:`${i}, more than the ${t.remaining??0} of ${t.max??0} left today: a rewind is refused`})}function Dn(e,n){if(!e||n.length===0)return"";let t=le(e,{giveBack:n}).map(o=>`${o.objectApiName}: '${o.name}'`);return t.length>0?`, on which runs ${y(t,4)}`:""}function Ln(e,n,t=[]){let o=e.objects.filter(a=>Me[a.objectApiName]!==void 0),i=o.filter(a=>K(a)>0),s=o.filter(a=>G(a)>0&&!t.includes(a.objectApiName)),d=[];return i.length>0&&d.push(` made as drafts first: ${y(i.map(a=>`${a.objectApiName} ${l(K(a))}`))} \u2014 Salesforce refuses an order or a contract made past Draft, and an order takes its products only as a draft: one past Draft at the checkpoint is made at the org's Draft status, the records under it next, then given its status back, an update`+Dn(n,i.map(a=>a.objectApiName))),s.length>0&&d.push(` if Salesforce answers that an order or a contract to bring back is no longer in the recycle bin, --accept-recreate makes it again as a draft, then gives it its status back, an update: ${y(s.map(a=>`${a.objectApiName} ${l(G(a))}`))}`),d}function Pn(e,n,t=!1){if(!n)return{objects:[],fired:[]};let o=V(e),i=[],s=new Set;for(let d of e.objects){if(G(d)===0)continue;let a=at(n,o,[d.objectApiName],t);if(!(a.fired.length===0&&!a.blind)){i.push(d.objectApiName);for(let r of a.fired)s.add(`${r.objectApiName}: '${r.name}'`)}}return{objects:i,fired:[...s]}}function Tn(e,n,t){let o=le(n,t),i=[];for(let d of n.objects){let a=o.filter(g=>g.objectApiName===d.objectApiName),r=[...new Set(a.filter(g=>g.kind!=="trigger").map(g=>`'${g.name}'`))],u=[...new Set(a.filter(g=>g.kind==="trigger").map(g=>g.name))],w=[...r.length>0?[`${r.length} flow(s) or rule(s): ${y(r,4)}`]:[],...u.length>0?[`${u.length} Apex trigger(s): ${y(u,4)}`]:[]];w.length>0&&i.push(` ${d.objectApiName}: ${w.join("; ")}`)}return[...i.length>0?[` what ${e} runs as a rewind writes (updates, deletes, records brought back):`]:[],...i,...n.unread.map(d=>` not read of its automation: ${d.part} \u2014 ${d.reason}`)]}function Nt(e,n,t,o="the user SandForge connects as",i=!1){let{diff:s}=t,d=z(s),a=[`Rewind ${e} to '${n.name}' (${E(n.takenAt)}), read at ${ge(s.readAt)}:`,` ${l(d.toDelete)} to delete \xB7 ${l(d.toGiveBack)} to give back \xB7 ${l(d.toBringBack)} to bring back`+(d.toRecreate>0?` \xB7 ${l(d.toRecreate)} to make again`:"")];!Re(s)&&!s.objects.some(c=>c.outside.length>0)&&a.push(` ${e} is as it was at '${n.name}' among the objects and fields it holds: nothing to rewind.`);let r=s.objects.filter(c=>mt(c)+c.toGiveBack.records+G(c)+K(c)+be(c)>0);if(r.length>0){let c=Math.max(6,...r.map(f=>f.objectApiName.length));a.push(` ${"Object".padEnd(c)} ${"Delete".padStart(8)} ${"Give back".padStart(9)} ${"Bring back".padStart(10)} ${"Can't undo".padStart(10)}`);for(let f of r)a.push(` ${f.objectApiName.padEnd(c)} ${l(mt(f)).padStart(8)} ${l(f.toGiveBack.records).padStart(9)} ${l(G(f)).padStart(10)} ${l(be(f)).padStart(10)}`)}let u=new Map;for(let c of s.objects)for(let[f,j]of Object.entries(c.lastChangedBy))u.set(f,(u.get(f)??0)+j);u.size>0&&a.push(` last changed by: ${[...u].sort((c,f)=>f[1]-c[1]).map(([c,f])=>`${s.userNames[c]??c} ${l(f)}`).join(" \xB7 ")}`),s.activeLastHour.length>0&&a.push(` people working in ${e} in the last hour: ${s.activeLastHour.map(c=>s.userNames[c]??c).join(", ")}`);let w=s.objects.filter(c=>c.touched>0);w.length>0&&a.push(` touched since but holding their checkpoint values: ${y(w.map(c=>`${c.objectApiName} ${l(c.touched)}`))}`);let g=s.objects.filter(c=>de(c)>0);g.length>0&&a.push(` brought back for a moment: ${y(g.map(c=>`${c.objectApiName} ${l(de(c))}`))} \u2014 records the checkpoint does not hold that took records of it along when deleted since: Salesforce gives those back with them only, so they come back, then go back to the recycle bin with what came back with them; what the org runs on them runs twice`);let $=new Map;for(let c of s.objects)for(let f of c.cannotUndo)f.count!==0&&$.set(f.reason,[...$.get(f.reason)??[],`${c.objectApiName} ${l(f.count)}`]);for(let[c,f]of $)a.push(` can't be taken back: ${y(f)} \u2014 ${xn[c]??c}`);let p=s.objects.filter(c=>K(c)>0);p.length>0&&a.push(` to make again, with new Ids: ${y(p.map(c=>`${c.objectApiName} ${l(K(c))}`))} \u2014 deleted since and no longer in the recycle bin: made again from the checkpoint, the lookups it holds that named them naming the new Ids; anything outside Salesforce that names their old Ids no longer finds them`);let h=d.toBringBack>0?Pn(s,t.automation,i):void 0;if(h){let c=h.fired.length>0?`making them again runs ${y(h.fired,4)}`:"what runs as they are made again could not all be read";a.push(" if Salesforce answers that a record to bring back is no longer in the recycle bin \u2014 it still lists one emptied from it as deleted \u2014, --accept-recreate makes it again with a new Id, with what was to come back with it; without it, the rewind leaves them and names them"+(h.objects.length>0?`; ${y(h.objects)} records it leaves all the same, with what was to come back with them, and names them: ${c}, which this rewind does not ask about \u2014 a rewind after it counts them to make again, and asks`:""))}a.push(...Ln(s,t.automation,h?.objects));let m=s.objects.filter(c=>c.unexplained>0);m.length>0&&a.push(` left as they are: ${y(m.map(c=>`${c.objectApiName} ${l(c.unexplained)}`))} \u2014 records the checkpoint doesn't hold although they're dated before it (a load with back-dated creation dates?); a rewind deletes nothing it cannot prove was created since`);for(let{words:c,of:f}of Et(s.undoCannot))a.push(` undo couldn't bring back: ${y(f.map(j=>`${j.objectApiName} ${l(j.count)}`))} \u2014 ${c.preview}`);for(let{objectApiName:c,children:f,records:j}of s.unseen??[])a.push(` also deleted with them, out of sight: deleting ${l(j)} ${c} also deletes what ${o} can't see under them in ${y(f)}; Rewind can't count those, and deletes them only with --accept-unseen`);for(let c of s.objects)for(let f of c.outside)a.push(c.objectApiName===It&&f.objectApiName===Bn?` also attached outside the checkpoint: ${l(f.parents)} file(s) it deletes, by ${l(f.count)} link(s) to a library, a group or a record of another object \u2014 deleting them removes them from there as well`:` also deleted with them, outside the checkpoint: ${l(f.count)} ${f.objectApiName} created under ${l(f.parents)} ${c.objectApiName}`);a.push(...Fn(e,s));let k=s.objects.flatMap(c=>{let f=c.schemaDrift,j=new Set([...f?.removed??[],...f?.hidden??[],...f?.uncertain?.fields??[]]);return c.notCompared.filter(C=>!j.has(C)).map(C=>`${c.objectApiName}.${C}`)});k.length>0&&a.push(` not compared (you chose): ${y(k)}`);for(let c of s.objects){let f=c.schemaDrift;if(!f)continue;let j=C=>C.map(S=>`${c.objectApiName}.${S}`);f.removed.length>0&&a.push(` fields deleted since: ${y(j(f.removed))} \u2014 restore them from Deleted Fields, then rewind`),(f.hidden??[]).length>0&&a.push(` fields hidden from ${o} by field-level security since: ${y(j(f.hidden??[]))} \u2014 rewind does not put them back; give ${o} read and edit access to them, then rewind again`),f.uncertain!==void 0&&f.uncertain.fields.length>0&&a.push(` fields gone from what ${e} shows ${o}: ${y(j(f.uncertain.fields))} \u2014 deleted since (restore them from Deleted Fields within 15 days), or hidden by field-level security (give ${o} read and edit access); rewind does not put them back`+(f.uncertain.reason!==void 0?` (which, ${e} would not say: ${f.uncertain.reason})`:"")),f.added.length>0&&a.push(` fields added since, their values left alone: ${y(j(f.added))}`),f.changed.length>0&&a.push(` fields changed since, tried one by one: ${y(j(f.changed))}`)}let A=s.fieldsNotChecked??0;A>0&&a.push(` fields not checked for changes in ${l(A)} objects nothing changed in: a rewind writes nothing there`);for(let c of s.unread)a.push(` could not be read: ${c.objectApiName} \u2014 ${c.reason} (never taken for unchanged)`);return t.automation&&a.push(...Tn(e,t.automation,V(s))),t.emails&&a.push(...In(e,t.emails)),t.emailsUncounted!==void 0&&a.push(` emails: not counted, ${t.emailsUncounted} could not be read \u2014 what they send as the rewind writes is not known; --accept-automation covers it`),a.push(...Nn(e,t)),a.push(jt(t.estimate)),t.refusal&&a.push(` a rewind now would be refused (${t.refusal.code}): ${t.refusal.message}`),a}var It="ContentDocument",Bn="ContentDocumentLink";function Fn(e,n){let t=n.files;if(t===void 0)return[];let o=[];t.unlink>0&&o.push(` links to remove: ${l(t.unlink)} added since between a file and a record that both stay \u2014 the file stays, no longer attached to that record`),t.relink>0&&o.push(` links to put back: ${l(t.relink)} removed since between a file and a record that both stay, each under a new Id: Salesforce keeps no removed link in the recycle bin`),t.updateLinks>0&&o.push(` links to give their sharing back: ${l(t.updateLinks)} \u2014 who sees the file from the record, and with what access; a link to an account keeps its access, which Salesforce doesn't let change`),t.outsideAdded>0&&o.push(` kept: ${l(t.outsideAdded)} file(s) added since, as no record of this checkpoint links to them (a user's own, a library's)`),t.outsideDeleted>0&&o.push(` left in the recycle bin: ${l(t.outsideDeleted)} file(s) deleted since, as no record of this checkpoint linked to them`);let i=n.objects.find(a=>a.objectApiName===It),s=i===void 0?0:G(i),{storage:d}=t;return s>0&&d.bringBack>0&&o.push(` file storage: bringing back ${l(s)} file(s) takes ${_(d.bringBack)} again; `+(d.remaining===void 0?`${e} did not say how much it has left`:`${e} has ${_(d.remaining)} left`)),d.undo>0&&o.push(` undo would bring back the files this rewind deletes: ${_(d.undo)} of file storage again`),t.blindSpot&&o.push(je),o}function Dt(e,n,t,o,i){let s=o?.diff??i?.diff??t.diff;return{checkpoint:{id:n.checkpointId,name:n.name,takenAt:n.takenAt,org:e},...o?{objects:[...o.plan.objects]}:{},...z(s),carriers:s.objects.reduce((d,a)=>d+de(a),0),differs:Re(o?.diff??t.diff),...o?{selection:o.plan}:{},...i?{kept:i.plan.left}:{},diff:t.diff,estimate:t.estimate,...t.automation?{automation:t.automation}:{},...t.emails?{emails:t.emails}:{},...t.emailsUncounted!==void 0?{emailsUncounted:t.emailsUncounted}:{},...t.deliverability?{deliverability:t.deliverability}:{},...t.refusal?{refusal:t.refusal}:{}}}function _n(e,n){return n&&Re(e)?3:0}var Lt={needsUnpickedParent:"they come back only with a parent this rewind leaves deleted, or look up a record it leaves deleted, which Salesforce refuses: those lookups are left, the rest written",heldByUnpicked:"records of an object not named made since hang from them and hold some of their values in place: given back but for those",outsideNotAccepted:"records of an object not named made since hang from them, which their deletion would take along: kept, unless --accept-outside",holdsLeft:"records this rewind leaves as they are hang from them, which their deletion would take along: kept",keyTaken:"rows of a custom setting whose owner or name a row made since holds: brought back once it is gone"};function Pt(e){let n=[` limited to ${e.objects.join(", ")}: the other objects are left as they are, and what still differs in them is counted apart`],t=e.acts.filter(o=>!o.picked&&o.toDelete>0);t.length>0&&n.push(` also deletes again ${y(t.map(o=>`${o.objectApiName} ${l(o.toDelete)}`))} \u2014 made since, they come back with a record it brings back: leaving them would make a state that never existed`);for(let o of e.left)n.push(` left: ${l(o.count)} ${o.objectApiName} record(s) \u2014 ${Lt[o.reason]}`);return e.needs.length>0&&n.push(` to rewind those too, add ${e.needs.map(o=>`--object ${o.objectApiName} (${l(o.records)} record(s) need it)`).join(", ")}`),e.acts.some(o=>o.picked&&o.toDelete>0)&&n.push(" a record of an object not named that looks up a record it deletes has that lookup emptied by Salesforce, and is dated that second"),n}function Tt(e,n,t){return!t&&e.scope.mode==="picked"&&n.objects.some(o=>o.outside.length>0)}function Bt(e){return e.left.map(n=>` kept: ${l(n.count)} ${n.objectApiName} record(s) \u2014 `+(n.reason==="outsideNotAccepted"?"records outside the checkpoint made since hang from them, which their deletion would take along: kept, unless --accept-outside":Lt[n.reason]))}async function Ft(e,n,t,o){if(!Tt(n,t,o))return;let i=n.objects.map(({objectApiName:s})=>s);return Ce(e,t,i,!1)}function _t(e,n){let t=new Map(e.objects.map(({objectApiName:i})=>[i.toLowerCase(),i])),o=n.filter(i=>!t.has(i.toLowerCase()));if(o.length>0)throw new b({code:"NOT_HELD",message:`--object: '${e.name}' holds no ${o.join(", ")}. It holds ${y(e.objects.map(i=>i.objectApiName))}. Nothing was run.`},2);return n.flatMap(i=>t.get(i.toLowerCase())??[])}async function Ce(e,n,t,o){let i=await e.request({type:"checkpoint:plan-selection",payload:{checkpointId:n.checkpointId,previewId:n.previewId,objects:[...t],acceptOutside:o},timeoutMs:ce});if(i.outcome!=="answered")throw new b(L(i,"The plan of the objects named"));let s=D(i).plan;return{plan:s,diff:st(n,s)}}var X={limit:e=>`--max-records ${e}`,mutes:!0,lift:{acceptAutomation:"give --accept-automation to rewind all the same",acceptEmails:"add --accept-emails to rewind all the same",acceptNoUndo:"give --accept-no-undo to rewind all the same",acceptRecreate:"give --accept-recreate to rewind all the same",acceptUnseen:"give --accept-unseen to rewind all the same",maxRecords:"read its preview (--dry-run), then give a --max-records that holds it",refuseWhenActive:"rewind once they are done, or without --refuse-when-active"}};function Un(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(ct,X.lift.acceptAutomation)}:e}function Mn(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(ht,"give --accept-automation to undo the rewind all the same")}:e}function Wo(e,n,t,o="the user SandForge connects as"){return rt(e,n,t,X.lift,o,X.mutes)}var Wn={acceptAutomation:!1,acceptNoUndo:!1,acceptRecreate:!1};function Ut(e,n){return[...e?[e]:[],...n.filter(t=>t.code!==e?.code)]}function qn(e,n,t,o){let i=o!==void 0&&o.length>0?`${o.join(", ")} of ${e}`:e,s=z(t),d=s.toRecreate>0?`, and makes ${l(s.toRecreate)} record(s) the recycle bin no longer holds again, with new Ids`:"",a=t.objects.reduce((g,$)=>g+de($),0),r=a>0?`, with ${l(a)} record(s) brought back for a moment that had taken records of the checkpoint along, then deleted again`:"",u=xt(t),w=u>0?`, and puts ${l(u)} link(s) between files and records back as they were`:"";return`Rewind ${i} to '${n.name}': it deletes the ${l(s.toDelete)} record(s) created since ${E(n.takenAt)}, gives ${l(s.toGiveBack)} record(s) their values from then back, and brings back ${l(s.toBringBack)} record(s) from the recycle bin${r}${d}${w} \u2014 whoever made these changes. What it changes is kept, so it can be undone. Type ${e} to rewind it:`}var R=(e,n)=>e.reduce((t,o)=>t+n(o),0);function Se(e){let n=R(e.deleted,a=>a.deleted),t=R(e.deleted,a=>a.planned),o=R(e.restored,a=>a.restored+(a.restoredWithout??0)),i=R(e.restored,a=>a.planned),s=R(e.undeleted,a=>a.undeleted+a.alreadyBack),d=R(e.undeleted,a=>a.planned);return{deleted:{planned:t,done:n,left:Math.max(0,t-n-R(e.deleted,a=>a.alreadyGone))},givenBack:{planned:i,done:o,left:Math.max(0,i-o-R(e.restored,a=>a.alreadyGone))},broughtBack:{planned:d,done:s,left:Math.max(0,d-s)}}}function Mt(e){let n=e.recreated??[],t=R(n,i=>i.planned),o=R(n,i=>i.created);return{planned:t,done:o,left:Math.max(0,t-o)}}function Hn(e){return(e.remade??[]).reduce((n,t)=>{let o=R(e.deleted.filter(i=>i.objectApiName===t.objectApiName),i=>i.deleted);return n+Math.min(o,t.count)},0)}function Wt(e,n){return e===void 0?"another user":n[e]??e}function Gn(e,n,t){switch(n.reason){case"automation":return e==="rewind"?"kept by your automation, which sets them again on save: rewind --ignore-field <Object.Field> stops comparing such a field":"set again on save by your automation, since the undo gave them back their values";case"changedDuringRewind":return`changed during the ${e} by ${Wt(n.by,t)}: left as they made them`;case"changedSincePreview":return"changed since the preview: rewind again to take them";case"refused":return`refused: ${n.message??"the org gave no reason"}`;case"notInBin":return"no longer in the recycle bin \u2014 emptied from it, or kept there for good \u2014: Salesforce still lists them as deleted but will not bring them back; --accept-recreate makes them again with new Ids";case"goneForGood":return"deleted since and no longer in the recycle bin, and not made again (a file, whose body the checkpoint does not hold, or a record deleted while it was taken): they can't come back";case"kept":return n.message??"kept as they are"}}function qt(e,n){return`Stopped before it wrote anything: ${e} is as it was before this rewind. Rewind again to rewind it to '${n}'.`}function Jn(e,n,t,o={},i){let s=R(t.residual,h=>h.count),d=t.residual.filter(h=>h.reason==="changedDuringRewind"),a={success:`${e} is back at '${n.name}': read again, nothing differs among the objects and fields it holds.`,partial:`${e} is back at '${n.name}' but for ${l(s)} record(s) that still differ, each said with why:`,unstable:`Someone kept writing to ${e} during the rewind: ${[...new Set(d.map(h=>Wt(h.by,o)))].join(", ")} changed ${l(R(d,h=>h.count))} record(s), left as they made them. Rewind again once they have stopped.`,failure:`Nothing of the rewind of ${e} to '${n.name}' went through: what still differs is said with why:`,cancelled:t.undo===void 0?qt(e,n.name):`Stopped part way: ${e} is between '${n.name}' and now. Rewind again to finish: it takes up from what still differs, and undo still returns ${e} to how it was before the rewind.`},r=t.scope;r!==void 0&&t.status==="success"&&(a.success=`${r.objects.join(", ")} of ${e} ${r.objects.length>1?"are":"is"} back at '${n.name}': read again, nothing differs among them.`);let u=Se(t),w=R(t.undeleted,h=>h.alreadyBack),g=[a[t.status]];if(r!==void 0){let{objects:h,records:m}=r.notRewound;g.push(m>0?` not rewound: ${l(m)} record(s) of ${y(h)} still differ, left as they are \u2014 the rewind was limited to the objects named; add them with --object`:" the objects not named match the checkpoint too")}u.deleted.done>0&&g.push(` deleted ${l(u.deleted.done)} record(s) added since the checkpoint \u2014 created, or brought back from the recycle bin they were in when it was taken \u2014 (in the recycle bin for up to 15 days)`),u.givenBack.done>0&&g.push(` gave ${l(u.givenBack.done)} record(s) back their checkpoint values`),u.broughtBack.done>0&&g.push(` brought back ${l(u.broughtBack.done-w)} record(s) deleted since the checkpoint, with their original Ids`+(w>0?`, and ${l(w)} that came back with them`:""));let $=t.status==="failure"?[]:t.carriers??[];if($.length>0){let h=y($.map(m=>`${m.objectApiName} ${l(m.count)}`));g.push(t.status==="cancelled"?` of them, brought back for a moment: ${h} \u2014 records the checkpoint does not hold that had taken records of it along; stopped before it was through, those it had not deleted again yet are still in the org: rewind again deletes them, with what came back with them`:` of them, brought back for a moment and deleted again: ${h} \u2014 records the checkpoint does not hold that had taken records of it along, back in the recycle bin with what came back with them`)}let p=Mt(t);p.done>0&&g.push(` made again ${l(p.done)} record(s) the recycle bin no longer held, with new Ids`);for(let h of t.draftsLeft??[])g.push(` left as drafts: ${h.objectApiName} ${l(h.count)} (${y(h.ids,3)}) \u2014 made again as drafts, the rewind stopped before it gave them back the status the checkpoint holds: rewind again gives it back to them, an update`);if(g.push(...Gt("rewind",e,t)),g.push(...Jt("rewind",t,o)),t.undo){g.push(` undo it until ${E(t.undo.until)}, sooner if the recycle bin fills: ${te("checkpoint")} undo --org ${e} --checkpoint ${n.checkpointId}`+(i!==void 0?` --store ${i}`:""));for(let{words:h,of:m}of Et(t.undo.cannot))g.push(` undo couldn't bring back: ${y(m.map(k=>`${k.objectApiName} ${l(k.count)}`))} \u2014 ${h.result}`)}for(let h of t.removedJournals??[])g.push(` removed the journal of rewind ${h.rewindId} of '${h.name}': undo reaches the last rewind of the org alone`);return g.push(zt(t)),g}function Ht(e){return`Stopped before it wrote anything: ${e} is as the rewind left it, and the rewind can still be undone.`}function zn(e,n,t){let o=R(t.restored,h=>h.keptChanged)+R(t.deleted,h=>h.keptChanged),i=R([...t.deleted,...t.restored,...t.undeleted],h=>h.refused),s=R(t.residual,h=>h.count)+i,d=`${e} is back as it was before its rewind to '${n.name}'`,a={success:`${d}.`,partial:o>0&&s===0?`${d}, except ${l(o)} record(s) changed since the rewind, left as they are now.`:`${d}, except ${l(s+o)} record(s), each said with why:`,unstable:`Someone changed records of ${e} during the undo: left as they made them, each said below.`,failure:`Nothing of the undo of ${e}'s rewind went through: its reasons are said below.`,cancelled:Pe(t)?Ht(e):`Stopped part way: ${e} is between the rewind and how it was before it. Undo again to finish: it takes up what this one left.`},r=Se(t),u=[a[t.status]],w=Hn(t),g=R(t.wentAlong??[],h=>h.count),$=r.deleted.done-w-g;$>0&&u.push(` sent back to the recycle bin ${l($)} record(s) the rewind brought back`+(g>0?", with what came back with them":"")),w>0&&u.push(` deleted again ${l(w)} record(s) the rewind made again, with what went with them`);let p=t.carriedAlone??[];return p.length>0&&u.push(` of them, back in the recycle bin on their own: ${y(p.map(h=>`${h.objectApiName} ${l(h.count)}`))} \u2014 they had gone there with a record the rewind brought back for a moment, which stays there; they come back alone, under the parent the checkpoint gave them`),r.broughtBack.done>0&&u.push(` brought back ${l(r.broughtBack.done)} record(s) the rewind deleted`),r.givenBack.done>0&&u.push(` gave ${l(r.givenBack.done)} record(s) back the values they had before the rewind`),o>0&&u.push(` kept ${l(o)} record(s) changed since the rewind: undo leaves them as they are now`),u.push(...Gt("undo",e,t)),u.push(...Jt("undo",t,{})),u.push(zt(t)),u}function Gt(e,n,t){let o=t.files;if(o===void 0)return[];let i=e==="rewind"?{unlinked:"removed {n} link(s) added since between files and records: the files stay",relinked:"put back {n} link(s) removed since between files and records, under new Ids",linksUpdated:"gave {n} link(s) between files and records their sharing back"}:{unlinked:"removed again {n} link(s) between files and records the rewind put back",relinked:"put back {n} link(s) between files and records the rewind removed, under new Ids",linksUpdated:"gave {n} link(s) between files and records back the sharing they had before the rewind"},s=["unlinked","relinked","linksUpdated"].filter(d=>o[d]>0).map(d=>` ${i[d].replace("{n}",l(o[d]))}`);return o.linksRefused>0&&s.push(` ${n} refused to write ${l(o.linksRefused)} link(s) between files and records`),s}function Jt(e,n,t){let o=n.residual.map(i=>` ${i.objectApiName} ${l(i.count)} \u2014 ${Gn(e,i,t)}`);if(e==="undo")for(let i of[...n.deleted,...n.restored,...n.undeleted])i.refused!==0&&o.push(` ${i.objectApiName} ${l(i.refused)} \u2014 refused: ${i.reasons[0]??"the org gave no reason"}`);for(let i of n.unread??[])o.push(` could not be read again: ${i.objectApiName} \u2014 ${i.reason} (never taken for unchanged)`);return o}function zt(e){return` sent ${l(e.apiRequests.used)} API requests to the org; ${l(e.apiRequests.leftToday)} left today`}function Vt(e,n,t,o,i){let s=new Map,d=r=>{let u=s.get(r);return u||(u={object:r,deleted:0,givenBack:0,broughtBack:0,refused:0},s.set(r,u)),u};for(let r of o.deleted)d(r.objectApiName).deleted+=r.deleted,d(r.objectApiName).refused+=r.refused;for(let r of o.restored)d(r.objectApiName).givenBack+=r.restored+(r.restoredWithout??0),d(r.objectApiName).refused+=r.refused;for(let r of o.undeleted)d(r.objectApiName).broughtBack+=r.undeleted+r.alreadyBack,d(r.objectApiName).refused+=r.refused;for(let r of o.recreated??[])d(r.objectApiName).refused+=r.refused;let a=(o.unread??[]).map(r=>({object:r.objectApiName,reason:r.reason}));return{checkpoint:{id:t.checkpointId,name:t.name,takenAt:t.takenAt,org:n},rewindId:o.rewindId,status:o.status,...o.scope?{limitedTo:[...o.scope.objects],notRewound:{...o.scope.notRewound}}:{},...Se(o),...e==="rewind"?{recreated:Mt(o),cannotUndo:(i?.objects??[]).flatMap(r=>r.cannotUndo.filter(u=>u.count>0).map(u=>({object:r.objectApiName,reason:u.reason,count:u.count})))}:{},...e==="rewind"&&(o.carriers??[]).length>0?{carriers:(o.carriers??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...e==="rewind"&&(o.draftsLeft??[]).length>0?{draftsLeft:(o.draftsLeft??[]).map(r=>({object:r.objectApiName,count:r.count,ids:[...r.ids]}))}:{},...e==="undo"&&(o.carriedAlone??[]).length>0?{carriedAlone:(o.carriedAlone??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...o.files?{files:{...o.files}}:{},...o.undo?{undo:{until:o.undo.until,cannot:o.undo.cannot.map(r=>({object:r.objectApiName,count:r.count,...r.reason!==void 0?{reason:r.reason}:{}}))}}:{},verify:{differences:R(o.residual,r=>r.count)+a.length,stable:o.status!=="unstable",passes:o.passes,notCompared:[...t.ignoredFields]},residual:o.residual.map(r=>({object:r.objectApiName,reason:r.reason,...r.by!==void 0?{by:r.by}:{},count:r.count,...r.message!==void 0?{message:r.message}:{}})),unread:a,objects:[...s.values()],apiRequests:o.apiRequests,result:o}}function Kt(e,n){switch(e){case"success":return 0;case"partial":return 3;case"unstable":return 4;case"failure":return 1;case"cancelled":return n!==void 0?ne(n):1}}var Vn=10*6e4,Kn=720*6e4,Yt=60*6e4,ce=5*6e4,wt=200,b=class extends Error{constructor(t,o=1,i=[]){super(t.message);this.refusal=t;this.code=o;this.also=i;this.name="Stop"}refusal;code;also};function Yn(e){let n=[e.refusal,...e.also];return{refusal:e.refusal,...e.also.length>0?{wouldBeRefused:n.map(t=>oe(t)),wouldBeRefusedCodes:n.map(t=>t.code)}:{}}}function D(e){return e.message?.payload??{}}function L(e,n){let t=D(e);if(e.outcome==="unanswered")return{code:"UNANSWERED",message:`${n}: no answer came in time.`};let o=typeof t.message=="string"?t.message:JSON.stringify(t),i=typeof t.code=="string"?t.code:e.outcome.toUpperCase(),{holdingLimit:s}=t;return{code:i,message:o,...typeof s=="number"?{holdingLimit:s}:{}}}function Xn(e){let n=D(e).alsoRefused;return e.outcome!=="failed"||!Array.isArray(n)?[]:n.flatMap(t=>{let{code:o,message:i}=t??{};return typeof o=="string"&&typeof i=="string"?[{code:o,message:i}]:[]})}async function Zn(e=process.argv,n={}){let t=pn(e),o=h=>{process[t.json?"stderr":"stdout"].write(`${h}
346
+ `)},i=h=>{t.json&&process.stdout.write(`${JSON.stringify(h,null,2)}
347
+ `)},s=Ye({root:t.storeRoot,...n.locksDir!==void 0?{locksDir:n.locksDir}:{}});if("refusal"in s){let h=`The checkpoints cannot be kept in ${s.refusal.path}: `+Ke(s.refusal,t.storeRoot,"--store <folder>");process.stderr.write(`${h}
348
+ `),i({refusal:{code:"STORE_REFUSED",message:h}}),B(1);return}let d=s.store,a=nn(kt(an(),"sandforge-checkpoint-")),r=new ut,u=!1,w,g=()=>Promise.resolve(),$,p;try{let h=(n.createHost??lt)({storeDir:a,log:c=>{u&&c.startsWith("[INFO] ")?o(c.slice(7)):c.startsWith("[WARN] ")&&o(`warning: ${c.slice(7)}`)},compose:c=>{c.handlers.setCheckpointStore(d),c.handlers.rewindCheckpointsFromPreviewsAnswered(),c.handlers.setInfraServices({backgroundRegistry:r}),g=()=>c.handlers.sweepCheckpoints(),$=c.handlers,p=c},onPost:c=>{if(c.type!=="operation:progress")return;let f=c.payload?.currentStep;typeof f!="string"||f===w||(w=f,o(` ${f}`))}});u=!0;try{await g()}finally{u=!1}let m=async()=>{let c=await h.request({type:"checkpoint:list",timeoutMs:ce});if(c.outcome!=="answered")throw new b(L(c,"The list of checkpoints"));return D(c).checkpoints??[]},k=async c=>{try{return await h.connect(c)}catch(f){throw new b({code:"NOT_CONNECTED",message:f instanceof _e?f.message:`${c} could not be reached: ${f instanceof Error?f.message:String(f)}`})}},A=async c=>{if(p===void 0)throw new Error("The host composed no handlers.");return Xe(await Be(c.id,p.orgRegistry,p.orgManager)).userId()};switch(t.command){case"list":{let c=await m(),f=t.org!==void 0?W(c,t.org):c,j=t.org!==void 0?{org:t.org,kept:c.length}:void 0;for(let C of gn(f,d.root,j))o(C);i(f.map(kn));return}case"take":await oo(t,h,await k(t.org),d,r,o,i);return;case"preview":{let c=await m(),f=Q(Z(c,W(c,t.org),t.checkpoint,t.org)),j=ve(f);if(j)throw new b(j);let C=f.checkpoint,S=t.objects.length>0?_t(C,t.objects):void 0,M=await k(t.org);Oe(M,f,C,t.org,"preview");let q=await h.request({type:"checkpoint:preview",payload:{checkpointId:f.checkpointId,...S?{objects:S}:{},acceptOutside:!1},timeoutMs:Yt});if(q.outcome!=="answered")throw new b(L(q,"The preview"));let N=D(q),P=S?await Ce(h,N.diff,S,!1):void 0,I=S?void 0:await Ft(h,C,N.diff,!1),ee=P??I,v=ee?{...N,diff:ee.diff}:N,Ee=Ut(N.refusal,await me({orgName:t.org,preview:v,bounds:{refuseWhenActive:!1},accepted:Wn,writers:()=>Promise.resolve([]),words:X,user:M.username})),[Ne]=Ee;for(let T of Nt(t.org,C,v,M.username))o(T);for(let T of P?Pt(P.plan):[])o(T);for(let T of I?Bt(I.plan):[])o(T);for(let T of Ee.slice(N.refusal?1:0))o(` a rewind now would be refused (${T.code}): ${T.message}`);i(Dt(t.org,C,{...N,...Ne?{refusal:Ne}:{}},P,I)),B(_n(P?.diff??N.diff,t.failOnChange));return}case"rewind":case"undo":{let c={host:h,registry:r,store:d,listAll:m,connect:k,userIdOf:A,say:o,answerJson:i};t.command==="rewind"?await so(t,c):await co(t,c);return}case"delete":await io(t,h,m,o,i);return;case"export":await eo(t,{transfers:gt($),listAll:m,say:o,answerJson:i});return;case"import":await to(t,{transfers:gt($),connect:k,say:o,answerJson:i});return}}catch(h){let m=h instanceof b?h:new b({code:"FAILED",message:h instanceof Error?h.message:String(h)});process.stderr.write(`${m.message}
349
+ `);for(let k of m.also)process.stderr.write(`${oe(k)}
350
+ `);m.code!==2&&i(Yn(m)),B(m.code)}finally{r.dispose(),sn(a,{recursive:!0,force:!0})}}function gt(e){if(e===void 0)throw new Error("The host composed no handlers.");return e}function Qn(){try{let e=JSON.parse(on(kt(__dirname,"..","package.json"),"utf8"));return typeof e.version=="string"?e.version:"0.0.0"}catch{return"0.0.0"}}function Xt(e){let n=process.env[e];if(n===void 0||n.trim()==="")throw new b({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let t=se(n);if(t===void 0)throw new b({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return t}function Zt(e,n){return{id:e.checkpointId,name:e.name,takenAt:e.takenAt,org:n}}async function eo(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?Xt(e.keyEnv):void 0,s=await n.listAll(),d=Q(Z(s,W(s,e.org),e.checkpoint,e.org)),a=await n.transfers.exportCheckpoint({checkpointId:d.checkpointId,out:e.out,...i!==void 0?{key:i}:{},sandforgeVersion:Qn()});if(!a.exported)throw new b(a.refusal);let{checkpoint:r,header:u}=a;t(`exported '${r.name}' (${r.checkpointId}) of ${e.org}, taken ${E(r.takenAt)}: ${l(u.records)} record(s) of ${l(u.objects)} object(s), ${_(a.bytes)}, to ${e.out}`),t(` sha256 ${a.sha256}`),a.key!==void 0&&process.stderr.write(` key, shown this once and kept nowhere: ${a.key}
351
+ `),t(` Anyone who has this file and its key can read the ${l(u.records)} records it holds of ${e.org}, personal data among them. Send the key another way than the file, and only to people who already see all data in ${e.org}.`),t(" The file does not expire: delete it once it has served."),o({checkpoint:Zt(r,e.org),file:e.out,bytes:a.bytes,sha256:a.sha256,records:u.records,objects:u.objects,keyShown:a.key!==void 0})}async function to(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?Xt(e.keyEnv):void 0,s=await n.connect(e.org),d=await n.transfers.readCheckpointImport({orgId:s.id,file:e.file});if(d.header!==void 0){let{header:w}=d;t(`the file holds checkpoint ${w.checkpointId}, taken ${E(w.takenAt)}: ${l(w.records)} record(s) of ${l(w.objects)} object(s), ${_(w.bytes)}, exported by SandForge ${w.sandforgeVersion}`)}if(!d.allowed)throw new b(d.refusal);let a=i??await no(),r=await n.transfers.importCheckpoint({orgId:s.id,file:e.file,key:a,keepDays:e.keepDays});if(!r.imported)throw new b(r.refusal);let{checkpoint:u}=r;t(r.outcome==="imported"?`imported '${u.name}' (${u.checkpointId}) of ${e.org}: ${l(Y(u))} record(s) of ${l(u.objects.length)} object(s), ${Ae(u.expiresAt)}`:`'${u.name}' (${u.checkpointId}) is kept on this machine already, the same: left as it is`);for(let w of r.warnings)t(` ${w}`);o({outcome:r.outcome,checkpoint:Zt(u,e.org),records:Y(u),objects:u.objects.length,expiresAt:u.expiresAt,warnings:r.warnings})}async function no(){let e=await tt("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new b({code:"DECLINED",message:"No key was typed. Nothing was imported."});let n=se(e);if(n===void 0)throw new b({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was imported."});return n}function Q(e){if("entry"in e)return e.entry;throw"ambiguous"in e?new b({code:"AMBIGUOUS",message:e.ambiguous},2):new b({code:"NOT_FOUND",message:e.none})}async function oo(e,n,t,o,i,s,d){let{take:a}=e;if(e.estimate){let m={orgId:t.id,mode:a.mode,...a.objects?{objects:a.objects}:{},...a.excluded?{excluded:a.excluded}:{},...a.customSettings?{customSettings:a.customSettings}:{},...a.maxTotal!==void 0?{maxTotal:a.maxTotal}:{}},k=await n.request({type:"checkpoint:scope",payload:m,timeoutMs:Vn});if(k.outcome!=="answered")throw new b(L(k,"The estimate"));let A=D(k),c={mode:A.mode,objects:A.objects,leftOut:A.leftOut,estimate:A.estimate,...A.refusal?{refusal:ke(A.refusal)}:{},...A.files?{files:A.files}:{},...A.customSettings?{customSettings:A.customSettings}:{}};for(let f of yn(e.org,c))s(f);d(bn(c)),B(c.refusal?1:0);return}s(`taking a checkpoint of ${e.org}: it reads every record of its objects (Ctrl-C stops it, and nothing of it is kept)`);let{answer:r,stoppedBy:u}=await xe(i,"the take stops after the read under way, and keeps nothing",()=>n.request({type:"checkpoint:take",payload:{orgId:t.id,...a},timeoutMs:Kn}));if(r.outcome!=="answered"){let m=ke(L(r,"The take"));throw u!==void 0&&m.code==="CANCELLED"?new b(m,ne(u)):new b(m)}let w=D(r),g=w.checkpoint,$=w.requests,p=w.estimate,h=o.folderOf(g.org.organizationId,g.checkpointId).dir;for(let m of An(g,h,a.objects??[]))s(m);$&&s(Cn($,p)),d({checkpoint:g,...$?{requests:$}:{},...p?{estimate:p}:{}})}async function io(e,n,t,o,i){let s=await t(),d=W(s,e.org),a=e.checkpoint===void 0?d:[Q(Z(s,d,e.checkpoint,e.org))];if(a.length===0)throw new b({code:"NOT_FOUND",message:`No checkpoint of ${e.org} is kept in the folder read. ${ae(e.org)} Nothing was deleted.`});let r=p=>p.checkpoint?`'${p.checkpoint.name}' (${p.checkpointId})`:p.checkpointId;if(!e.yes){let p=a.filter(k=>k.undo!==void 0),m=`${a.length===1?`Delete ${r(a[0])}${a[0].checkpoint?`, taken ${E(a[0].checkpoint.takenAt)},`:""} from this machine? ${e.org} can no longer be rewound to it`:`Delete the ${a.length} checkpoints of ${e.org} from this machine (${y(a.map(r),4)})? ${e.org} can no longer be rewound to them`}${p.length>0?", and its last rewind can no longer be undone":""}. The org is not touched.`;if(!await et(m))throw new b({code:"DECLINED",message:"Nothing was deleted."})}let u=a.map(p=>p.checkpointId);for(let p=0;p<u.length;p+=wt){let h=await n.request({type:"checkpoint:delete",payload:{checkpointIds:u.slice(p,p+wt)},timeoutMs:ce});if(h.outcome!=="answered"){let m=L(h,"The delete");if(p===0)throw new b(m);o(`refused: ${m.message}`);break}}let w=new Set((await t()).map(p=>p.checkpointId)),g=a.filter(p=>!w.has(p.checkpointId)),$=a.filter(p=>w.has(p.checkpointId));for(let p of g)o(`deleted ${r(p)}`);for(let p of $)o(`kept ${r(p)}: a take, a rewind or an undo of its org is running; delete it once it has ended`);i({deleted:g.map(p=>p.checkpointId),kept:$.map(p=>p.checkpointId)}),$.length>0&&B(g.length>0?3:1)}function Oe(e,n,t,o,i){if(bt(e.orgId,n.organizationId))return;let s=W([n],o).length>0,d=i==="preview"?"preview it":i==="rewind"?"rewind to it":"undo it";throw new b({code:"OTHER_ORG",message:s?`${o} answers as another org than the one '${t.name}' was taken of: a sandbox refreshed since is another org, and this checkpoint can only be deleted. ${re} No record was read.`:`'${t.name}' is a checkpoint of ${H(t)}, not of ${o}: ${d} with --org ${H(t)}. No record was read.`})}async function xe(e,n,t){let o,i=e.onEvent((d,a,r)=>{o!==void 0&&a==="started"&&r.module==="checkpoint"&&e.abort(d)}),s=Ue(d=>{o=d,process.stderr.write(`
351
352
  interrupted: ${n} (Ctrl-C again ends it at once)
352
- `);for(let s of e.getRunning())s.module==="checkpoint"&&e.abort(s.operationId)});try{let c=await t();return o!==void 0?{answer:c,stoppedBy:o}:{answer:c}}finally{a(),i()}}var qt=720*6e4;function Ht(e,n,t=o=>o){let{answer:o,stoppedBy:i}=e;if(o.outcome!=="answered"){let a=t(P(o,n));throw i!==void 0&&a.code==="CANCELLED"?new b(a,Q(i)):new b(a,1,Mn(o).map(t))}return D(o).result}async function Kn(e,n){let{host:t,say:o,answerJson:i}=n,a=await n.listAll(),c=Z(X(a,M(a,e.org),e.checkpoint,e.org)),s=fe(c);if(s)throw new b(s);let r=c.checkpoint,p=e.ignoreFields.filter(v=>!r.ignoredFields.includes(v));if(p.length>0){let v=await t.request({type:"checkpoint:ignore-fields",payload:{checkpointId:c.checkpointId,fields:[...r.ignoredFields,...p]},timeoutMs:ie});if(v.outcome!=="answered")throw new b(P(v,"The fields not to compare"));r=D(v).checkpoint,o(`not compared from now on, nor written back: ${p.join(", ")} (kept in '${r.name}')`)}let w=e.objects.length>0?xt(r,e.objects):void 0,k=await n.connect(e.org);be(k,c,r,e.org,"rewind");let $=await t.request({type:"checkpoint:preview",payload:{checkpointId:c.checkpointId,...w?{objects:w}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptOutside:e.acceptOutside},timeoutMs:_t});if($.outcome!=="answered")throw new b(P($,"The preview"));let h=D($),l=w?await ge(t,h.diff,w,e.acceptOutside):void 0,m=w?void 0:await Ot(t,r,h.diff,e.acceptOutside),g=l??m,A=g?{...h,diff:g.diff}:h,d=e.muteAutomation&&A.automation?Te(A.automation,Se(V(A.diff))):void 0,f=d?{...A,automation:d.automation}:A;for(let v of $t(e.org,r,f,k.username,e.acceptAutomation))o(v);for(let v of l?Rt(l.plan):[])o(v);for(let v of m?St(m.plan):[])o(v);for(let v of d?te(d.planned,e.org):[])o(` ${v}`);let j=Ke(f.diff).length>0,C=await re({orgName:e.org,preview:f,bounds:{...e.maxRecords!==void 0?{maxRecords:e.maxRecords}:{},refuseWhenActive:e.refuseWhenActive},accepted:e,writers:async()=>ze(r.takenBy,await n.userIdOf(k)),words:Y,user:k.username}),S=Nt(f.refusal,C);if(Ct(r,f.diff,e.acceptOutside)&&o(" without --accept-outside, the records they hang from stay, and so do they: each is said once the rewind is through"),e.dryRun){for(let v of S.slice(f.refusal?1:0))o(` a rewind now would be refused (${v.code}): ${v.message}`);i({...At(e.org,r,h,l,m),...d?{mutedAutomation:d.planned,mutePlan:d.plan}:{},...S.length>0?{wouldBeRefused:S.map(v=>ee(v)),wouldBeRefusedCodes:S.map(v=>v.code)}:{}});return}let[W,...I]=S;if(W)throw new b(W,1,I);if(j&&!e.yes&&await ae(Dn(e.org,r,f.diff,w))!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let L=await ye(n.registry,"the rewind stops before its next call to the org, and leaves its journal: rewind again takes up from what still differs",()=>t.request({type:"checkpoint:rewind",payload:{checkpointId:c.checkpointId,previewId:f.diff.previewId,...w?{objects:w}:{},acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptNoUndo:e.acceptNoUndo,acceptRecreate:e.acceptRecreate,acceptOutside:e.acceptOutside,acceptUnseen:e.acceptUnseen},timeoutMs:qt})),E=Ht(L,"The rewind",v=>v.code==="CANCELLED"?{...v,message:Dt(e.org,r.name)}:Nn(v));for(let v of Tn(e.org,r,E,f.diff.userNames))o(v);for(let v of E.mutedAutomation?te(E.mutedAutomation,e.org):[])o(v);i(Ft("rewind",e.org,r,E,f.diff)),B(Ut(E.status,L.stoppedBy))}function Yn(e,n,t,o,i){return`undo the rewind ${t} of ${e} to '${n.name}' (open until ${N(o)}, sooner if the recycle bin fills)`+(i?`: it brings back ${u(i.bringBack)} record(s) the rewind deleted, gives ${u(i.giveBack)} record(s) back the values they had before it, and sends ${u(i.remove-i.remade)} record(s) it brought back to the recycle bin`+(i.along>0?", with what came back with them":"")+(i.remade>0?`, deleting again the ${u(i.remade)} record(s) it made again`:"")+(i.drafted>0?` \u2014 of them, ${u(i.drafted)} order(s) set back to Draft first if past it, the one way Salesforce deletes one: an update, which what runs on an order's update fires on`:"")+"; what anyone changed since the rewind stays":"")}async function Xn(e,n,t,o){try{let i=e.folderOf(n.organizationId,n.checkpointId),a=await Qe(i,o,t.objects);try{return{bringBack:a.bringBack.count,giveBack:a.giveBack.count,remove:a.remove.spool.count,along:a.goesWithParent.count,remade:a.remade.keys.size,drafted:a.remade.objects.filter(({objectApiName:c})=>Le([c]).length>0).reduce((c,{count:s})=>c+s,0)}}finally{await a.dispose()}}catch{return}}async function Zn(e,n){let{host:t,say:o,answerJson:i}=n,a=await n.listAll(),c=M(a,e.org),s=e.checkpoint===void 0?c.find(g=>g.undo!==void 0):Z(X(a,c,e.checkpoint,e.org));if(!s)throw new b({code:"NOT_FOUND",message:`No rewind of ${e.org} can be undone from this machine: Undo is offered for the last rewind of an org, for 15 days after it, until it is undone. Nothing was written.`});let r=fe(s);if(r)throw new b(r);let p=s.checkpoint;if(!s.undo)throw new b({code:"UNDO_CLOSED",message:`'${p.name}' has no rewind that can be undone: Undo is offered for the last rewind of an org only, for 15 days after it, until it is undone. Nothing was written.`});let{rewindId:w,until:k}=s.undo,$=await Xn(n.store,s,p,w);o(Yn(e.org,p,w,k,$));let h=await n.connect(e.org);if(be(h,s,p,e.org,"undo"),!e.yes&&await ae(`Type ${e.org} to undo its rewind:`)!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let l=await ye(n.registry,"the undo stops before its next call to the org: undo again takes up what it left",()=>t.request({type:"checkpoint:undo",payload:{checkpointId:s.checkpointId,rewindId:w,acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{}},timeoutMs:qt})),m=Ht(l,"The undo",g=>g.code==="CANCELLED"?{...g,message:Pt(e.org)}:In(g));for(let g of Bn(e.org,p,m))o(g);for(let g of m.mutedAutomation?te(m.mutedAutomation,e.org):[])o(g);i(Ft("undo",e.org,p,m)),B(Ut(m.status,l.stoppedBy))}process.argv[1]?.includes("sandforge-checkpoint")&&(Ve(),Wn().then(()=>process.exit(process.exitCode??0)).catch(e=>{process.stderr.write(`${e instanceof Error?e.message:String(e)}
353
- `),process.exit(1)}));export{Io as acceptanceRefusal,M as checkpointsOf,nn as defaultName,xt as heldObjectsOrStop,fe as invalidRefusal,Ct as keepsOutside,St as keptLines,bt as linkWritesOf,dn as listEntryJson,rn as listLines,Wn as main,we as orgDiffers,on as parseArgs,xn as previewExitCode,At as previewJson,$t as previewLines,J as previewTotals,wn as requestsLine,X as resolveCheckpoint,Ut as resultExitCode,Ft as resultJson,Tn as rewindLines,Dn as rewindQuestion,V as rewindStepsOf,cn as scopeJson,hn as scopeLines,Ye as selectionDiff,Rt as selectionLines,fn as takeLines,Yn as undoLine,Bn as undoLines};
353
+ `);for(let a of e.getRunning())a.module==="checkpoint"&&e.abort(a.operationId)});try{let d=await t();return o!==void 0?{answer:d,stoppedBy:o}:{answer:d}}finally{s(),i()}}var Qt=720*6e4;function en(e,n,t=o=>o){let{answer:o,stoppedBy:i}=e;if(o.outcome!=="answered"){let s=t(L(o,n));throw i!==void 0&&s.code==="CANCELLED"?new b(s,ne(i)):new b(s,1,Xn(o).map(t))}return D(o).result}async function so(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=Q(Z(s,W(s,e.org),e.checkpoint,e.org)),a=ve(d);if(a)throw new b(a);let r=d.checkpoint,u=e.ignoreFields.filter(v=>!r.ignoredFields.includes(v));if(u.length>0){let v=await t.request({type:"checkpoint:ignore-fields",payload:{checkpointId:d.checkpointId,fields:[...r.ignoredFields,...u]},timeoutMs:ce});if(v.outcome!=="answered")throw new b(L(v,"The fields not to compare"));r=D(v).checkpoint,o(`not compared from now on, nor written back: ${u.join(", ")} (kept in '${r.name}')`)}let w=e.objects.length>0?_t(r,e.objects):void 0,g=await n.connect(e.org);Oe(g,d,r,e.org,"rewind");let $=await t.request({type:"checkpoint:preview",payload:{checkpointId:d.checkpointId,...w?{objects:w}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptOutside:e.acceptOutside},timeoutMs:Yt});if($.outcome!=="answered")throw new b(L($,"The preview"));let p=D($),h=w?await Ce(t,p.diff,w,e.acceptOutside):void 0,m=w?void 0:await Ft(t,r,p.diff,e.acceptOutside),k=h??m,A=k?{...p,diff:k.diff}:p,c=e.muteAutomation&&A.automation?Ge(A.automation,Te(V(A.diff))):void 0,f=c?{...A,automation:c.automation}:A;for(let v of Nt(e.org,r,f,g.username,e.acceptAutomation))o(v);for(let v of h?Pt(h.plan):[])o(v);for(let v of m?Bt(m.plan):[])o(v);for(let v of c?ie(c.planned,e.org):[])o(` ${v}`);let j=it(f.diff).length>0,C=await me({orgName:e.org,preview:f,bounds:{...e.maxRecords!==void 0?{maxRecords:e.maxRecords}:{},refuseWhenActive:e.refuseWhenActive},accepted:e,writers:async()=>ot(r.takenBy,await n.userIdOf(g)),words:X,user:g.username}),S=Ut(f.refusal,C);if(Tt(r,f.diff,e.acceptOutside)&&o(" without --accept-outside, the records they hang from stay, and so do they: each is said once the rewind is through"),e.dryRun){for(let v of S.slice(f.refusal?1:0))o(` a rewind now would be refused (${v.code}): ${v.message}`);i({...Dt(e.org,r,p,h,m),...c?{mutedAutomation:c.planned,mutePlan:c.plan}:{},...S.length>0?{wouldBeRefused:S.map(v=>oe(v)),wouldBeRefusedCodes:S.map(v=>v.code)}:{}});return}let[q,...N]=S;if(q)throw new b(q,1,N);if(j&&!e.yes&&await pe(qn(e.org,r,f.diff,w))!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let P=await xe(n.registry,"the rewind stops before its next call to the org, and leaves its journal: rewind again takes up from what still differs",()=>t.request({type:"checkpoint:rewind",payload:{checkpointId:d.checkpointId,previewId:f.diff.previewId,...w?{objects:w}:{},acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptNoUndo:e.acceptNoUndo,acceptRecreate:e.acceptRecreate,acceptOutside:e.acceptOutside,acceptUnseen:e.acceptUnseen},timeoutMs:Qt})),I=en(P,"The rewind",v=>v.code==="CANCELLED"?{...v,message:qt(e.org,r.name)}:Un(v)),ee=e.storeRoot!==ue()?e.storeRoot:void 0;for(let v of Jn(e.org,r,I,f.diff.userNames,ee))o(v);for(let v of I.mutedAutomation?ie(I.mutedAutomation,e.org):[])o(v);i(Vt("rewind",e.org,r,I,f.diff)),B(Kt(I.status,P.stoppedBy))}function ao(e,n,t,o,i){return`undo the rewind ${t} of ${e} to '${n.name}' (open until ${E(o)}, sooner if the recycle bin fills)`+(i?`: it brings back ${l(i.bringBack)} record(s) the rewind deleted, gives ${l(i.giveBack)} record(s) back the values they had before it, and sends ${l(i.remove-i.remade)} record(s) it brought back to the recycle bin`+(i.along>0?", with what came back with them":"")+(i.remade>0?`, deleting again the ${l(i.remade)} record(s) it made again`:"")+(i.drafted>0?` \u2014 of them, ${l(i.drafted)} order(s) set back to Draft first if past it, the one way Salesforce deletes one: an update, which what runs on an order's update fires on`:"")+"; what anyone changed since the rewind stays":"")}async function ro(e,n,t,o){try{let i=e.folderOf(n.organizationId,n.checkpointId),s=await dt(i,o,t.objects);try{return{bringBack:s.bringBack.count,giveBack:s.giveBack.count,remove:s.remove.spool.count,along:s.goesWithParent.count,remade:s.remade.keys.size,drafted:s.remade.objects.filter(({objectApiName:d})=>He([d]).length>0).reduce((d,{count:a})=>d+a,0)}}finally{await s.dispose()}}catch{return}}async function co(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=W(s,e.org),a=e.checkpoint===void 0?d.find(k=>k.undo!==void 0):Q(Z(s,d,e.checkpoint,e.org));if(!a)throw new b({code:"NOT_FOUND",message:`No rewind of ${e.org} can be undone from this machine: Undo is offered for the last rewind of an org, for 15 days after it, until it is undone. Nothing was written.`});let r=ve(a);if(r)throw new b(r);let u=a.checkpoint;if(!a.undo)throw new b({code:"UNDO_CLOSED",message:`'${u.name}' has no rewind that can be undone: Undo is offered for the last rewind of an org only, for 15 days after it, until it is undone. Nothing was written.`});let{rewindId:w,until:g}=a.undo,$=await ro(n.store,a,u,w);o(ao(e.org,u,w,g,$));let p=await n.connect(e.org);if(Oe(p,a,u,e.org,"undo"),!e.yes&&await pe(`Type ${e.org} to undo its rewind:`)!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let h=await xe(n.registry,"the undo stops before its next call to the org: undo again takes up what it left",()=>t.request({type:"checkpoint:undo",payload:{checkpointId:a.checkpointId,rewindId:w,acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{}},timeoutMs:Qt})),m=en(h,"The undo",k=>k.code==="CANCELLED"?{...k,message:Ht(e.org)}:Mn(k));for(let k of zn(e.org,u,m))o(k);for(let k of m.mutedAutomation?ie(m.mutedAutomation,e.org):[])o(k);i(Vt("undo",e.org,u,m)),B(Kt(m.status,h.stoppedBy))}process.argv[1]?.includes("sandforge-checkpoint")&&(nt(),Zn().then(()=>process.exit(process.exitCode??0)).catch(e=>{process.stderr.write(`${e instanceof Error?e.message:String(e)}
354
+ `),process.exit(1)}));export{Wo as acceptanceRefusal,W as checkpointsOf,fn as defaultName,_t as heldObjectsOrStop,ve as invalidRefusal,Tt as keepsOutside,Bt as keptLines,xt as linkWritesOf,kn as listEntryJson,gn as listLines,Zn as main,Re as orgDiffers,pn as parseArgs,_n as previewExitCode,Dt as previewJson,Nt as previewLines,z as previewTotals,Cn as requestsLine,Z as resolveCheckpoint,Kt as resultExitCode,Vt as resultJson,Jn as rewindLines,qn as rewindQuestion,V as rewindStepsOf,bn as scopeJson,yn as scopeLines,st as selectionDiff,Pt as selectionLines,An as takeLines,ke as takeRefusalWords,ao as undoLine,zn as undoLines};