sandforge 0.0.0-stage → 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 (221) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -2
  3. package/THIRD-PARTY-NOTICES.md +1624 -0
  4. package/bin/sandforge-autopilot.mjs +12 -0
  5. package/bin/sandforge-backup.mjs +12 -0
  6. package/bin/sandforge-checkpoint.mjs +12 -0
  7. package/bin/sandforge-cleanup.mjs +12 -0
  8. package/bin/sandforge-clone.mjs +12 -0
  9. package/bin/sandforge-compare.mjs +12 -0
  10. package/bin/sandforge-dataops.mjs +12 -0
  11. package/bin/sandforge-empty.mjs +12 -0
  12. package/bin/sandforge-env.mjs +12 -0
  13. package/bin/sandforge-frozen.mjs +12 -0
  14. package/bin/sandforge-mcp.mjs +12 -0
  15. package/bin/sandforge-monitor.mjs +12 -0
  16. package/bin/sandforge-seed.mjs +12 -0
  17. package/bin/sandforge-sync.mjs +12 -0
  18. package/bin/sandforge.mjs +12 -0
  19. package/lib/catalogue.en.json +1 -0
  20. package/lib/chunk-2BA2XKAY.mjs +7 -0
  21. package/lib/chunk-2CNCDM56.mjs +7 -0
  22. package/lib/chunk-2GTBABKU.mjs +7 -0
  23. package/lib/chunk-2NBYT7GR.mjs +7 -0
  24. package/lib/chunk-2UZPIMUC.mjs +7 -0
  25. package/lib/chunk-2YIV2OB2.mjs +7 -0
  26. package/lib/chunk-3F6Q5E7I.mjs +14 -0
  27. package/lib/chunk-3RZQZHEB.mjs +7 -0
  28. package/lib/chunk-3TJON4F3.mjs +7 -0
  29. package/lib/chunk-4HW535YJ.mjs +7 -0
  30. package/lib/chunk-4TLYUZD5.mjs +7 -0
  31. package/lib/chunk-4VS2V6WU.mjs +25 -0
  32. package/lib/chunk-5K5VLULK.mjs +7 -0
  33. package/lib/chunk-5LFSFYFJ.mjs +7 -0
  34. package/lib/chunk-5P4PHJRL.mjs +9 -0
  35. package/lib/chunk-5TC3QB4U.mjs +10 -0
  36. package/lib/chunk-66NMFCWX.mjs +7 -0
  37. package/lib/chunk-6XYKJSGX.mjs +7 -0
  38. package/lib/chunk-74Q6DORA.mjs +7 -0
  39. package/lib/chunk-7ABODJ4G.mjs +7 -0
  40. package/lib/chunk-7EANH5PY.mjs +68 -0
  41. package/lib/chunk-7EGQP6S4.mjs +7 -0
  42. package/lib/chunk-7F54PZUS.mjs +7 -0
  43. package/lib/chunk-7FFGJWHN.mjs +7 -0
  44. package/lib/chunk-7YDNUBO5.mjs +7 -0
  45. package/lib/chunk-A527W53V.mjs +7 -0
  46. package/lib/chunk-ADOAS63R.mjs +7 -0
  47. package/lib/chunk-AEKONPF4.mjs +7 -0
  48. package/lib/chunk-AV5SWEHP.mjs +9 -0
  49. package/lib/chunk-B5QQJ4SI.mjs +7 -0
  50. package/lib/chunk-BGUEWRK2.mjs +7 -0
  51. package/lib/chunk-BKDV4ENO.mjs +7 -0
  52. package/lib/chunk-BOGNK4LV.mjs +7 -0
  53. package/lib/chunk-BTWDMNN3.mjs +7 -0
  54. package/lib/chunk-BV6VTP3J.mjs +7 -0
  55. package/lib/chunk-BXU6WFMH.mjs +7 -0
  56. package/lib/chunk-BY2HJFFG.mjs +7 -0
  57. package/lib/chunk-BZ24IAP5.mjs +7 -0
  58. package/lib/chunk-CA5NAXSU.mjs +7 -0
  59. package/lib/chunk-CE6ZDGBB.mjs +7 -0
  60. package/lib/chunk-CEX3NEZL.mjs +7 -0
  61. package/lib/chunk-CHCHAE4B.mjs +7 -0
  62. package/lib/chunk-CHYDMRSV.mjs +7 -0
  63. package/lib/chunk-CION3VMZ.mjs +7 -0
  64. package/lib/chunk-COFG7Q6R.mjs +7 -0
  65. package/lib/chunk-CSBS5U5I.mjs +7 -0
  66. package/lib/chunk-CU2INBND.mjs +7 -0
  67. package/lib/chunk-DB7RBE5D.mjs +7 -0
  68. package/lib/chunk-DBB3EMIN.mjs +7 -0
  69. package/lib/chunk-DBFJB2B6.mjs +7 -0
  70. package/lib/chunk-DYFALGRT.mjs +7 -0
  71. package/lib/chunk-E5AHXLS6.mjs +7 -0
  72. package/lib/chunk-E5ZB3LU5.mjs +7 -0
  73. package/lib/chunk-EADHKH3A.mjs +7 -0
  74. package/lib/chunk-EFR2Y7E4.mjs +7 -0
  75. package/lib/chunk-EHQ3FX6X.mjs +7 -0
  76. package/lib/chunk-ELFXJHU7.mjs +7 -0
  77. package/lib/chunk-EMNC6YI4.mjs +7 -0
  78. package/lib/chunk-EQNW3UC2.mjs +7 -0
  79. package/lib/chunk-F2424IKX.mjs +7 -0
  80. package/lib/chunk-F43REJDZ.mjs +10 -0
  81. package/lib/chunk-F6GUDTOB.mjs +7 -0
  82. package/lib/chunk-FGRG7ANU.mjs +7 -0
  83. package/lib/chunk-FKG7Q3WH.mjs +7 -0
  84. package/lib/chunk-FPKYYFM7.mjs +7 -0
  85. package/lib/chunk-FQGHL7GR.mjs +259 -0
  86. package/lib/chunk-FXXLX4O6.mjs +7 -0
  87. package/lib/chunk-G35N4P7D.mjs +7 -0
  88. package/lib/chunk-GCOB7K5N.mjs +7 -0
  89. package/lib/chunk-GGD7ON3M.mjs +7 -0
  90. package/lib/chunk-GMY5427L.mjs +7 -0
  91. package/lib/chunk-GSG7WZHM.mjs +7 -0
  92. package/lib/chunk-GSKCGQIP.mjs +7 -0
  93. package/lib/chunk-HEKAZJRH.mjs +7 -0
  94. package/lib/chunk-HF6LAK3G.mjs +7 -0
  95. package/lib/chunk-HLWMJF6Y.mjs +7 -0
  96. package/lib/chunk-HOJYWTP7.mjs +20 -0
  97. package/lib/chunk-HS4YRX4J.mjs +7 -0
  98. package/lib/chunk-HXS7ORUF.mjs +11 -0
  99. package/lib/chunk-I7O6C2B5.mjs +8 -0
  100. package/lib/chunk-IC2C2GOF.mjs +8 -0
  101. package/lib/chunk-IFETCRWE.mjs +10 -0
  102. package/lib/chunk-IG2MTQRP.mjs +8 -0
  103. package/lib/chunk-IGYH7GMA.mjs +7 -0
  104. package/lib/chunk-INIQ23K6.mjs +7 -0
  105. package/lib/chunk-INIT2UKJ.mjs +7 -0
  106. package/lib/chunk-IOIWJ3DJ.mjs +7 -0
  107. package/lib/chunk-IQXHJEYB.mjs +7 -0
  108. package/lib/chunk-IWDREM66.mjs +7 -0
  109. package/lib/chunk-IZQZ6ZUF.mjs +7 -0
  110. package/lib/chunk-J525F5KI.mjs +7 -0
  111. package/lib/chunk-JEERQRLW.mjs +7 -0
  112. package/lib/chunk-JPUR2CFX.mjs +10 -0
  113. package/lib/chunk-JWTSEDIQ.mjs +7 -0
  114. package/lib/chunk-K2FBZIXY.mjs +7 -0
  115. package/lib/chunk-K327QKMD.mjs +7 -0
  116. package/lib/chunk-KBJ5VERV.mjs +7 -0
  117. package/lib/chunk-KDGMAGQR.mjs +7 -0
  118. package/lib/chunk-KRCA6IPH.mjs +8 -0
  119. package/lib/chunk-KYEDBS54.mjs +7 -0
  120. package/lib/chunk-L5FGY6YA.mjs +7 -0
  121. package/lib/chunk-L77FJZEP.mjs +10 -0
  122. package/lib/chunk-LKQ5RKIV.mjs +9 -0
  123. package/lib/chunk-LPBMBW3O.mjs +13 -0
  124. package/lib/chunk-LWW4U276.mjs +7 -0
  125. package/lib/chunk-M3ROUWDX.mjs +7 -0
  126. package/lib/chunk-M6P5ZZLE.mjs +7 -0
  127. package/lib/chunk-MFG4MUIO.mjs +9 -0
  128. package/lib/chunk-MHMH6MTP.mjs +7 -0
  129. package/lib/chunk-MILU7WFN.mjs +7 -0
  130. package/lib/chunk-MJU2PGZQ.mjs +15 -0
  131. package/lib/chunk-MJVTDA5Q.mjs +7 -0
  132. package/lib/chunk-MS4FJDFD.mjs +101 -0
  133. package/lib/chunk-MTMH6H2A.mjs +8 -0
  134. package/lib/chunk-MYW5QNGI.mjs +7 -0
  135. package/lib/chunk-N652NMZ4.mjs +441 -0
  136. package/lib/chunk-NTFIRZP6.mjs +7 -0
  137. package/lib/chunk-NTOVCTRS.mjs +7 -0
  138. package/lib/chunk-NZC67CGR.mjs +9 -0
  139. package/lib/chunk-O2HDYYUV.mjs +8 -0
  140. package/lib/chunk-OAZRPP4I.mjs +7 -0
  141. package/lib/chunk-OHWNPXWW.mjs +7 -0
  142. package/lib/chunk-OLSGVAIL.mjs +341 -0
  143. package/lib/chunk-OO6CLPEH.mjs +7 -0
  144. package/lib/chunk-OPXCV2KL.mjs +7 -0
  145. package/lib/chunk-P33PSCXK.mjs +7 -0
  146. package/lib/chunk-PJ5I73CK.mjs +7 -0
  147. package/lib/chunk-PTTHSSQO.mjs +7 -0
  148. package/lib/chunk-PZPJKATS.mjs +19 -0
  149. package/lib/chunk-Q3DM32KF.mjs +11 -0
  150. package/lib/chunk-QR3WELJQ.mjs +7 -0
  151. package/lib/chunk-QROPNEGY.mjs +14 -0
  152. package/lib/chunk-QSRAEUGZ.mjs +7 -0
  153. package/lib/chunk-QWT2C74M.mjs +7 -0
  154. package/lib/chunk-R3X3LV64.mjs +14 -0
  155. package/lib/chunk-RMBPOTD7.mjs +7 -0
  156. package/lib/chunk-RPI7LRTW.mjs +7 -0
  157. package/lib/chunk-RSWDYIHY.mjs +37 -0
  158. package/lib/chunk-SAR5622P.mjs +7 -0
  159. package/lib/chunk-SCKUIE3R.mjs +7 -0
  160. package/lib/chunk-SE4QEZUG.mjs +7 -0
  161. package/lib/chunk-SIHORWVK.mjs +7 -0
  162. package/lib/chunk-SOGQW4IG.mjs +7 -0
  163. package/lib/chunk-SOU4FRYN.mjs +7 -0
  164. package/lib/chunk-SRPWW4A2.mjs +10 -0
  165. package/lib/chunk-SU65Z2BA.mjs +7 -0
  166. package/lib/chunk-T62WNR54.mjs +7 -0
  167. package/lib/chunk-T63U4OZJ.mjs +7 -0
  168. package/lib/chunk-TLH7AD35.mjs +7 -0
  169. package/lib/chunk-TSLJUSLW.mjs +13 -0
  170. package/lib/chunk-TTFDUKUS.mjs +47 -0
  171. package/lib/chunk-TTKXMDBN.mjs +10 -0
  172. package/lib/chunk-TUACWKIH.mjs +7 -0
  173. package/lib/chunk-TW3N6W5Z.mjs +7 -0
  174. package/lib/chunk-TYYOBZMU.mjs +10 -0
  175. package/lib/chunk-TZE3Y7IQ.mjs +7 -0
  176. package/lib/chunk-UCD54V2M.mjs +7 -0
  177. package/lib/chunk-UNDIBZWG.mjs +7 -0
  178. package/lib/chunk-UNJA4J37.mjs +11 -0
  179. package/lib/chunk-VE6XKGGD.mjs +7 -0
  180. package/lib/chunk-VGW4MXXZ.mjs +7 -0
  181. package/lib/chunk-VS7ZXUII.mjs +824 -0
  182. package/lib/chunk-VXQLDM4R.mjs +7 -0
  183. package/lib/chunk-VYXMVJL5.mjs +7 -0
  184. package/lib/chunk-W622GUAW.mjs +8 -0
  185. package/lib/chunk-W7U5E5ZL.mjs +9 -0
  186. package/lib/chunk-WA7EYLAQ.mjs +7 -0
  187. package/lib/chunk-WIO4XO4F.mjs +7 -0
  188. package/lib/chunk-WR2GIKWE.mjs +7 -0
  189. package/lib/chunk-WR4Q363I.mjs +11 -0
  190. package/lib/chunk-WU3GLFZO.mjs +7 -0
  191. package/lib/chunk-WXAQ7FK3.mjs +115 -0
  192. package/lib/chunk-X5JYBPXP.mjs +7 -0
  193. package/lib/chunk-XAMBCQPU.mjs +7 -0
  194. package/lib/chunk-XCA5AONB.mjs +7 -0
  195. package/lib/chunk-XLXIPIEW.mjs +9 -0
  196. package/lib/chunk-XUWL6ZPC.mjs +7 -0
  197. package/lib/chunk-YAZO75G2.mjs +8 -0
  198. package/lib/chunk-YKKRIEH4.mjs +7 -0
  199. package/lib/chunk-YRQGKDHM.mjs +7 -0
  200. package/lib/chunk-YS4G22C2.mjs +7 -0
  201. package/lib/chunk-YYZL7UGV.mjs +7 -0
  202. package/lib/chunk-ZHJP7L3K.mjs +7 -0
  203. package/lib/chunk-ZM6OJGIG.mjs +7 -0
  204. package/lib/chunk-ZUTYVST5.mjs +7 -0
  205. package/lib/chunk-ZVAED4QV.mjs +7 -0
  206. package/lib/sandforge-autopilot.mjs +162 -0
  207. package/lib/sandforge-backup.mjs +103 -0
  208. package/lib/sandforge-checkpoint.mjs +354 -0
  209. package/lib/sandforge-cleanup.mjs +60 -0
  210. package/lib/sandforge-clone.mjs +7 -0
  211. package/lib/sandforge-compare.mjs +55 -0
  212. package/lib/sandforge-dataops.mjs +7 -0
  213. package/lib/sandforge-empty.mjs +140 -0
  214. package/lib/sandforge-env.mjs +355 -0
  215. package/lib/sandforge-frozen.mjs +272 -0
  216. package/lib/sandforge-mcp.mjs +40 -0
  217. package/lib/sandforge-monitor.mjs +43 -0
  218. package/lib/sandforge-seed.mjs +7 -0
  219. package/lib/sandforge-sync.mjs +7 -0
  220. package/lib/sandforge.mjs +28 -0
  221. package/package.json +52 -4
@@ -0,0 +1,354 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
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
+
9
+ Usage:
10
+ npx sandforge checkpoint <command> --org <alias> [options]
11
+
12
+ Commands:
13
+ take read the org's records and keep them as a checkpoint on this machine
14
+ list name the checkpoints kept, newest first, with what a rewind and an undo can still reach
15
+ preview say what a rewind would delete, give back and bring back, who last changed it, and what
16
+ it and an undo cannot take back; writes nothing
17
+ rewind return the org to a checkpoint: bring back from the recycle bin the records deleted
18
+ since, give the records changed since their values back, delete the records created
19
+ since, and put the files attached to its records back as they were \u2014 whoever made the
20
+ changes; keep what it changes so it can be undone; then read the org again
21
+ undo take back the org's last rewind: bring back what it deleted, give back what it wrote
22
+ over, send back to the bin what it brought back; what anyone changed since the rewind
23
+ stays, and is said
24
+ delete delete a checkpoint from this machine; the org is not touched
25
+ export write a checkpoint to a .sfcheckpoint file, encrypted, for a teammate who rewinds the
26
+ same org from another machine; the org is not contacted
27
+ import keep a .sfcheckpoint file a teammate exported as a checkpoint of the org on this
28
+ machine, once the org answers that it is the file's, and its user sees all data
29
+
30
+ Required:
31
+ --org <alias> sf CLI alias of the org (list: every org of the store without it)
32
+
33
+ take:
34
+ --name <text> what it is called (default: the date and time)
35
+ --object <ApiName> an object to keep; repeat for more (default: every object people
36
+ work in, empty ones included, setup and log objects left out)
37
+ --exclude-object <ApiName> leave an object out; repeat for more
38
+ --custom-setting <ApiName|all> keep a custom setting, or all of them, which a checkpoint leaves
39
+ out unless named: a rewind sets their rows back, an integration's
40
+ endpoint or an admin's switch among them; repeat for more; needs
41
+ Customize Application
42
+ --ignore-field <Object.Field> do not compare a field, nor write it back (one your automation sets
43
+ on every save); repeat for more
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)
47
+ --estimate say the records, API requests, time and disk it would take, then stop
48
+ preview, rewind, undo, delete, export:
49
+ --checkpoint <id|name|latest> which one (default: latest, for undo the one the last rewind went
50
+ back to; rewind and undo with --yes need it named, by id or name)
51
+ preview, rewind:
52
+ --object <ApiName> limit the rewind to an object of the checkpoint; repeat for more
53
+ (default: every object). It writes the others only to delete again
54
+ the records made since that come back with a record it brings
55
+ back, and never adds what the objects named depend on: what it
56
+ leaves of them for that is said, with the --object to add
57
+ preview:
58
+ --fail-on-change exit 3 when the org differs from the checkpoint
59
+ rewind:
60
+ --dry-run the preview, then stop
61
+ --accept-automation rewind even when the org runs flows, Apex triggers, processes or
62
+ workflow rules as records are updated, deleted or brought back;
63
+ without it such a rewind writes nothing, exit 1
64
+ --accept-emails rewind even when the org delivers every email its automation
65
+ sends (Setup > Deliverability: All email), or would not say
66
+ whether it does, and what still runs as it writes sends some:
67
+ they go to the addresses the records and the alerts name, and to
68
+ the records' owners. Without it such a rewind writes nothing,
69
+ exit 1. --accept-automation never stands for it. Read with one
70
+ line of anonymous Apex that sends nothing, only when something
71
+ that still runs sends an email; what Apex triggers send is not
72
+ read
73
+ --mute-automation mute the org's automation for the rewind through its own bypass:
74
+ assign the user it writes as, for the rewind alone, the permission
75
+ sets holding the custom permissions its flows, processes and
76
+ workflow rules test to stay quiet, and take them back as it ends;
77
+ what no bypass keeps quiet still runs, and still needs
78
+ --accept-automation. Refused on a production org and for a user
79
+ who cannot assign permission sets, exit 1; with --dry-run, says
80
+ what would be muted, or why it would be refused, and assigns
81
+ nothing
82
+ --accept-no-undo rewind even when undo could not bring back some records it deletes
83
+ (objects Salesforce undeletes only with their parent, such as
84
+ OpportunityLineItem); without it such a rewind writes nothing, exit 1
85
+ --accept-recreate make again, with new Ids, the records deleted since that the
86
+ recycle bin no longer gives back: what outside Salesforce names
87
+ their old Ids no longer finds them; without it a rewind that
88
+ counts such records writes nothing, exit 1, and one Salesforce
89
+ answers is no longer in the bin as it brings it back is left,
90
+ named
91
+ --accept-outside (a checkpoint of picked objects) also delete the records outside it
92
+ created under records it deletes, and the files it deletes that are
93
+ attached outside it too; without it those parents stay, and those
94
+ files are only removed from its records
95
+ --accept-unseen (a user without View All Data and Modify All Data) delete records
96
+ whose delete takes along records of objects the user is not
97
+ proven to see whole \u2014 tasks and events always: the preview names
98
+ those objects, and no count holds what goes with them; without it
99
+ such a rewind writes nothing, exit 1
100
+ --max-records <n> refuse, before it writes, a rewind that would delete, give back,
101
+ bring back and make again more than <n> records together, exit 1:
102
+ with --yes in a cron job or a CI step, what stands in for reading
103
+ the preview
104
+ --refuse-when-active refuse, before it writes, a rewind of an org where anyone but the
105
+ user it writes as and the org's Automated Process changed records
106
+ of the checkpoint's objects in the hour before it read the org,
107
+ whose work it would take back, exit 1; the refusal says how many
108
+ people. Where people sign in as the user SandForge connects as,
109
+ their changes are that user's, and are not told apart
110
+ --ignore-field <Object.Field> stop comparing a field from now on; kept in the checkpoint
111
+ --yes do not ask before writing; without it and with no terminal \u2014 a CI
112
+ step \u2014 it stops at its question, exit 2, having written nothing
113
+ undo:
114
+ --accept-automation as for rewind
115
+ --accept-emails as for rewind
116
+ --mute-automation as for rewind
117
+ --yes as for rewind
118
+ delete:
119
+ --all every checkpoint of the org
120
+ --yes do not ask
121
+ export:
122
+ --out <file> the file to write; refused when one is there already
123
+ --key-env <VAR> encrypt under the key this environment variable holds, one an
124
+ export showed (a CI step's secret); without it a new key is
125
+ drawn and shown once, on stderr
126
+ import:
127
+ --file <file> the .sfcheckpoint file
128
+ --key-env <VAR> read the key from this environment variable; without it the key
129
+ is asked on the terminal, not echoed, and with no terminal it
130
+ stops, exit 2, having imported nothing
131
+ --keep-days <n> when it expires on this machine (default: ${J}; 0 keeps it until
132
+ deleted)
133
+ Options:
134
+ --store <dir> where checkpoints live (default: ~/.sandforge/checkpoints, or
135
+ checkpoints/ in the folder SANDFORGE_JOURNAL_DIR names)
136
+ --json the answer alone on stdout, every other line on stderr
137
+ --help this text
138
+
139
+ A production org is refused before anything is read or written, exit 1. No flag lifts it.
140
+ With View All Data and Modify All Data, the user the alias connects as sees every record and
141
+ rewinds whoever changed it; import needs both. Without them, take holds only the objects the
142
+ user has View All and Modify All on, or, for an object with no permissions of its own, on every
143
+ record it hangs from \u2014 never tasks and events, products and price books, files or custom
144
+ settings \u2014 and preview, rewind and undo read those permissions again: an object no longer held
145
+ is not read, and is left as it is; what another user deleted since stays in the recycle bin,
146
+ named; undo takes back the user's own rewind alone. A checkpoint that keeps custom settings
147
+ needs Customize Application too: View All Custom Settings reads them, never writes them.
148
+ A checkpoint holds the records' values as the org held them, personal data among them,
149
+ unencrypted, in files only you can read (on Windows: in your user profile). Expired checkpoints
150
+ are deleted as any command starts, each named.
151
+ list and delete read this machine alone and never contact the org. An org's checkpoints are the
152
+ ones taken under its alias or username, and the others kept of the same Organization Id.
153
+ export never writes a checkpoint unencrypted: AES-256-GCM, under a key of 52 letters and digits
154
+ shown once and kept nowhere. Anyone who has the file and its key reads every record it holds:
155
+ send the key another way than the file, and only to people who already see all data in the org.
156
+ The file does not expire: delete it once it has served. It carries neither the journals of
157
+ rewinds nor their undo, which stay on this machine.
158
+ import reads the file's header, then asks the org: another org, a production org, a user without
159
+ View All Data and Modify All Data, a file a newer SandForge made, are each refused before the key
160
+ is asked. A wrong key, or a file changed since it was exported, is refused before anything is
161
+ kept. A checkpoint kept already the same is left as it is, exit 0; another of its id is refused.
162
+ The lock against two rewinds at once is per machine: agree on who rewinds the org.
163
+ rewind shows its preview and asks you to type the org's alias exactly as --org gives it before it
164
+ writes, then rewinds from that preview as it read the org: a record someone changes after it read
165
+ is left as they made it, and said. undo says what it takes back and asks the same before it
166
+ writes. A take, a rewind or an undo of the org under way on this machine, in the editor or in
167
+ another command line, refuses a rewind and an undo; other runs writing to the org are not seen
168
+ here, and what one of them changes after the preview read the org is left and said the same way.
169
+ Ctrl-C stops a take between two reads, and nothing of it is kept; a second Ctrl-C ends it at once,
170
+ and leaves a checkpoint listed as never taken, which delete removes. Ctrl-C stops a rewind or an
171
+ undo before its next call to the org, and leaves its journal: rewind again takes up from what still
172
+ differs, and undo still returns the org to how it was before the rewind. A rewind stopped before
173
+ it sent anything leaves none, and the undo of the rewind before it stays offered.
174
+
175
+ A record deleted since that the recycle bin no longer gives back is made again from the
176
+ checkpoint, with a new Id, once --accept-recreate says so: the lookups the checkpoint holds that
177
+ named it name the new Id, and undo deletes it again. Salesforce still lists a record emptied from
178
+ the bin as deleted, for minutes to hours, and says the bin no longer holds it only as the rewind
179
+ asks it back: such a record, with what was to come back with it, is made again then, or left
180
+ and named without --accept-recreate.
181
+ A record the checkpoint does not hold that took records of it along when it was deleted since is
182
+ brought back for a moment with them, then deleted again with what came back with it.
183
+ A custom setting is kept only when --custom-setting names it. A rewind brings a row of one back
184
+ only once no other row holds its owner (a hierarchy: the org's default, a profile, a user) or
185
+ its name (a list): it deletes the row made since first, then brings the row back with its Id.
186
+ A checkpoint holds the files attached to its records, Salesforce Files and classic attachments:
187
+ which records each is attached to, its latest version and its size, never its content. A rewind
188
+ deletes the files attached to them since, brings back those deleted since with their links,
189
+ removes the links added since and puts back those removed since, under new Ids; a file
190
+ attached to no record of the checkpoint, a user's own or a library's, is left and counted.
191
+ Bringing files back from the recycle bin takes file storage again: a rewind or an undo that would
192
+ take more than the org has left is refused before it writes. Without Query All Files, other
193
+ users' files that no record of the checkpoint is attached to are not seen.
194
+ What a rewind cannot undo: a file deleted since and no longer in the recycle bin, whose body the
195
+ checkpoint does not hold, a file given a new version since, which keeps it, a lead converted
196
+ since, a contract activated since, a record deleted with a parent created since that Salesforce
197
+ does not undelete on its own, or with its parent of an object the checkpoint does not hold
198
+ (preview counts them); without View All Data and Modify All Data, a record another user deleted
199
+ since, and a record of an object held through what it hangs from that the recycle bin does not
200
+ show the user (preview counts them too); a field added since, deleted since, or hidden since from
201
+ the user by field-level security, which the preview tells apart and names in an object something
202
+ changed in since \u2014 in an object nothing changed in, which a rewind writes nothing to, the fields
203
+ are not checked, and the preview counts those objects; the values the org computes or keeps
204
+ itself (formulas, roll-ups, auto-numbers, created and modified dates); what left the org
205
+ (emails, callouts, outbound messages, platform events); metadata; the files of a checkpoint taken
206
+ before SandForge 1.70, which holds none. A record the org refuses to put back, or to make again,
207
+ is named by rewind, with its words.
208
+
209
+ JSON (--json), one value on stdout:
210
+ list [{id, name, org, organizationId, takenAt, records, bytes, expiresAt,
211
+ expiresSoon, binReachSince, lastRewind?, valid, why?, refreshedAt?}]
212
+ (name, org, takenAt, records and bytes are null for a damaged checkpoint;
213
+ expiresAt is null for one kept until deleted)
214
+ take {checkpoint, requests?, estimate}: the checkpoint as kept (its
215
+ checkpoint.json; files?, {documents, links, anchored, readByIds?}, for one
216
+ that holds files); requests, {total, byPhase}, the API requests the take sent
217
+ the org, SOAP calls among them; estimate, what it said before reading a record
218
+ take --estimate {mode, objects, leftOut, estimate, refusal?, files?, customSettings?}:
219
+ estimate.requestsByPhase splits the requests over a take's phases as
220
+ requests.byPhase does: guard, scope, start, counts, bin, snapshot, stability;
221
+ files, {held, queryAllFiles, addedToPicked}; customSettings, every custom
222
+ setting of the org, kept or not, [{objectApiName, label, kind?, records?}],
223
+ kind hierarchy or list, and objects[].customSetting for one kept; {mode,
224
+ refusal} for a take refused before its scope is read (a production org, a
225
+ user without the permissions)
226
+ preview {checkpoint: {id, name, takenAt, org}, toDelete, toGiveBack, toBringBack,
227
+ toRecreate, carriers, differs, diff, estimate, automation?, emails?,
228
+ emailsUncounted?, deliverability?, refusal?}: carriers, the records
229
+ brought back for a moment and deleted again, in none of the other numbers;
230
+ diff, estimate
231
+ and automation as the extension answers them; refusal, the first a rewind
232
+ given no flag would meet now, of those its lines name with what lifts
233
+ each, as rewind --dry-run lists them: the extension's own (the org's lock,
234
+ a run writing, the day's API requests or emails, file storage), then an
235
+ acceptance it needs (NO_UNDO, RECREATE, UNSEEN, AUTOMATION,
236
+ EMAILS_DELIVERED, in that order); emails, one per daily limit its writes send
237
+ against: {limit, emails, verdict, remaining?, max?, alertsCounted?,
238
+ objects: [{objectApiName, write, records, perRecord, sentBy}]};
239
+ emailsUncounted, what sends emails as it writes that could not be read \u2014 a
240
+ flow whose definition was refused, a package's, which no user reads \u2014 its
241
+ emails not counted, which --accept-automation covers; deliverability,
242
+ when something that still runs may send an email: {reading: {level: all
243
+ or withheld} or {unread}, senders: [{objectApiName, kind, name, why}]},
244
+ which --accept-emails answers for all and unread;
245
+ diff.objects[].schemaDrift, of an object whose fields changed since:
246
+ {removed, added, changed, hidden?, uncertain?: {fields, reason?}}, removed
247
+ the custom fields deleted since, hidden those field-level security hides
248
+ from the user, uncertain those the org would not say which of;
249
+ diff.described, {first, later}, the objects it described again, asked
250
+ whether their fields changed since the take: first those something moved
251
+ in, later those nothing moved in that hold fewer records than the
252
+ checkpoint; diff.fieldsNotChecked, the objects nothing changed in whose
253
+ fields it did not describe: a rewind writes nothing there, and a field
254
+ deleted or hidden since in one of them is not known; diff.files,
255
+ for a checkpoint that holds files: {unlink, relink, updateLinks,
256
+ outsideAdded, outsideDeleted, storage: {bringBack, remaining?, undo},
257
+ blindSpot?}, the links to remove, put back and give their sharing back, the
258
+ files left, and file storage in bytes; diff.access, {kind, requests?}, org
259
+ for a user with View All Data and Modify All Data, perObject for one read
260
+ object by object, with the API requests that read; diff.unseen, read
261
+ object by object: [{objectApiName, children, records}], of the records to
262
+ delete of an object, the objects whose records their delete takes along
263
+ out of the user's sight; with --object, objects, the objects named, and
264
+ selection, {objects, acts: [{objectApiName, picked, toDelete, toGiveBack,
265
+ toBringBack, toRecreate}], left: [{objectApiName, reason, count}], needs:
266
+ [{objectApiName, records}], undoCannot}, what a rewind of them alone would
267
+ do and leave \u2014 reason needsUnpickedParent, heldByUnpicked,
268
+ outsideNotAccepted, holdsLeft or keyTaken \u2014 and the objects to add; the
269
+ numbers, differs and estimate are then the rewind's of those objects,
270
+ diff the whole diff; of a checkpoint of picked objects whose records
271
+ outside it were made since under records a rewind would delete, kept:
272
+ [{objectApiName, reason, count}], what a rewind without --accept-outside
273
+ keeps for them \u2014 reason outsideNotAccepted or holdsLeft \u2014, the numbers
274
+ then those of what it writes, differs the whole diff's (preview previews
275
+ that rewind)
276
+ rewind --dry-run as preview, with wouldBeRefused: ["refused (CODE): message"] and
277
+ wouldBeRefusedCodes: ["CODE"], one for each refusal a rewind with these
278
+ flags would meet, in order; asked to mute, emails and deliverability are
279
+ of what still runs, with mutedAutomation and mutePlan
280
+ rewind {checkpoint: {id, name, takenAt, org}, rewindId, status, deleted, givenBack,
281
+ broughtBack, recreated (each {planned, done, left}), cannotUndo: [{object,
282
+ reason, count}], carriers?: [{object, count}], draftsLeft?: [{object,
283
+ count, ids}], undo?: {until, cannot: [{object, count, reason?}]}, verify:
284
+ {differences, stable, passes, notCompared}, residual: [{object, reason,
285
+ by?, count, message?}], unread: [{object, reason}], objects: [{object,
286
+ deleted, givenBack, broughtBack, refused}], apiRequests: {used,
287
+ leftToday}, result}:
288
+ status success, partial, unstable, failure or cancelled; result as the
289
+ extension answers it; undo.cannot's reason deletedBeforeParent: deleted
290
+ before a record they point at, which the rewind deleted next; carriers, of
291
+ what it brought back and deleted, the records brought back for a moment;
292
+ draftsLeft, of a rewind stopped part way, the orders and contracts it made
293
+ again as drafts and had not given their status back yet, by their new Ids;
294
+ files?: {unlinked, relinked, linksUpdated, linksRefused}, the links between
295
+ files and records it wrote, when it wrote one; with --object, limitedTo,
296
+ the objects named, and notRewound, {objects, records}, the objects not
297
+ named that still differ and their records that do, which the status
298
+ does not count
299
+ undo as rewind, without recreated, cannotUndo, carriers, draftsLeft and undo,
300
+ with carriedAlone?: [{object, count}], the records sent back to the
301
+ recycle bin on their own that had gone there with a record the rewind
302
+ brought back for a moment
303
+ delete {deleted: [id], kept: [id]}
304
+ export {checkpoint: {id, name, takenAt, org}, file, bytes, sha256, records, objects,
305
+ keyShown}: keyShown, whether a new key was drawn and shown on stderr; never
306
+ the key itself
307
+ import {outcome, checkpoint: {id, name, takenAt, org}, records, objects, expiresAt,
308
+ warnings}: outcome imported, or alreadyKept for the same checkpoint kept here
309
+ already
310
+ refused or failed {refusal: {code, message}}; a rewind or an undo refused before it wrote
311
+ for more than one reason adds wouldBeRefused and wouldBeRefusedCodes, as
312
+ rewind --dry-run gives them: every refusal, the first among them, each other
313
+ also on a line of its own, refused (CODE): message
314
+ A bad command line (exit 2) prints nothing on stdout.
315
+
316
+ Exit codes: 0 done (take: every record of its objects is kept; rewind and undo: read again, the
317
+ org matches among the objects and fields compared \u2014 with --object, among the objects named,
318
+ whatever still differs in the others; preview, rewind --dry-run and list answered;
319
+ delete: every checkpoint named is deleted; export: the file is written; import: the checkpoint is
320
+ kept, or was already); 1 refused before it read or wrote (a production org,
321
+ missing permissions, automation without --accept-automation, emails the org delivers or would not
322
+ say it withholds without --accept-emails (refusal code EMAILS_DELIVERED), deletions undo could not
323
+ bring back without --accept-no-undo, records to make again with new Ids without --accept-recreate,
324
+ deletions taking along records the user is not proven to see without --accept-unseen, more than
325
+ --max-total records, more records to rewind than --max-records, people working in the org in the
326
+ hour before with --refuse-when-active, more API requests or emails than the org
327
+ has left today, files to bring back taking more file storage than it has left, a checkpoint of
328
+ the org before a refresh or of an expired scratch org, a SandForge run writing to it; an import
329
+ of another org's file, with the wrong key, of a file changed since its export), or nothing
330
+ done; 2 a bad command line, a --checkpoint name several checkpoints
331
+ have, an --object the checkpoint does not hold,
332
+ rewind or undo with --yes and no checkpoint named, or a question with no terminal (give
333
+ --yes; import's key: --key-env); 3 partial (rewind and undo: records still differ, each said
334
+ with why; with
335
+ --fail-on-change, the org differs: records to delete, give back, bring back or make again,
336
+ links between files and records to remove, put back or give their sharing back, records the
337
+ rewind cannot take back or the checkpoint does not hold although they are dated before it, files
338
+ added or deleted since that no record of it is attached to, a field it compares deleted or
339
+ hidden since in an object something moved in, an object that could not be read; delete: some
340
+ were kept, each said with why); 4 unstable (someone else changed
341
+ records during the rewind or the undo: left as they made them); 130, 143, 129 Ctrl-C, SIGTERM or
342
+ SIGHUP stopped it \u2014 run rewind again: it takes up from what still differs, and undo still reaches
343
+ the state before it.
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(`
352
+ interrupted: ${n} (Ctrl-C again ends it at once)
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};
@@ -0,0 +1,60 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{b as k}from"./chunk-W7U5E5ZL.mjs";import{a as Z,b as Q,c as K,d as V}from"./chunk-RSWDYIHY.mjs";import{c as I,e as Y}from"./chunk-AV5SWEHP.mjs";import{g as U,h as H,i as B}from"./chunk-B5QQJ4SI.mjs";import"./chunk-NZC67CGR.mjs";import"./chunk-BOGNK4LV.mjs";import{b as L,c as P}from"./chunk-KDGMAGQR.mjs";import{B as W}from"./chunk-MFG4MUIO.mjs";import"./chunk-EQNW3UC2.mjs";import"./chunk-GSKCGQIP.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-TYYOBZMU.mjs";import{b as D,c as M}from"./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{fa as z,wa as J}from"./chunk-CION3VMZ.mjs";import"./chunk-WIO4XO4F.mjs";import{a as F}from"./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{a as j,h as R}from"./chunk-TZE3Y7IQ.mjs";import"./chunk-GGD7ON3M.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import{a as v,b as N,e as q,g as X}from"./chunk-MTMH6H2A.mjs";import"./chunk-TTFDUKUS.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-MS4FJDFD.mjs";import"./chunk-NTOVCTRS.mjs";var te=/^[A-Za-z0-9]{15}([A-Za-z0-9]{3})?$/,re=/^\d{4}-\d{2}-\d{2}$/,se=["CaseComment","EmailMessage","Asset","Contract","Case","Contact","Account"],ne=`sandforge cleanup \u2014 Bulk delete records you created on a sandbox in the
8
+ --since window, whether or not a clone wrote them. Preview with --dry-run and
9
+ narrow with --objects before deleting.
10
+
11
+ Usage:
12
+ npx sandforge cleanup --target <alias> [options]
13
+
14
+ Required:
15
+ --target <alias> sf CLI alias of the target sandbox, or Developer
16
+ Edition org. A production org is refused.
17
+
18
+ Options:
19
+ --since <when> the records created from the start of: today
20
+ (default), yesterday, last_week, this_week,
21
+ last_n_days:N (N days ago), or an ISO date
22
+ YYYY-MM-DD (midnight UTC), up to now.
23
+ --objects <a,b,c> Comma-separated object API names. Defaults to a
24
+ whitelist of common Forge targets.
25
+ --max <n> Max records to delete per object (default: 200).
26
+ Past it, the rest is left, named per object, and the
27
+ cleanup exits 3: run it again, or give a higher --max.
28
+ --dry-run Print counts and what the target runs as they would
29
+ go, don't delete.
30
+ ${K("deleted","--dry-run")} --json print per object the records found, deleted and
31
+ refused as JSON on stdout, every other line on stderr
32
+ -h, --help Show this help.
33
+
34
+ Before it deletes, the cleanup says what the target runs as the records go:
35
+ its record-triggered flows, Apex triggers, processes and workflow rules on
36
+ delete, before and after, the emails that sends against what the target has
37
+ left today, and whether it delivers them (with --json, under automation).
38
+ What the target deletes along with the records (a contact's tasks, an
39
+ account's contacts) goes too, uncounted, and runs none of its delete
40
+ automation: Salesforce runs none on a record deleted with its parent, so it
41
+ is not read.
42
+
43
+ Exit codes: 0 every record found was deleted (or counted, with --dry-run);
44
+ 1 the cleanup could not start, the target is a production org, an object
45
+ could not be read or deleted (one the target does not have is passed over),
46
+ or the cleanup was refused for what the target runs as it deletes, without
47
+ --accept-automation (AUTOMATION_NOT_ACCEPTED), emails it delivers, without
48
+ --accept-emails (EMAILS_NOT_ACCEPTED), more emails than it has left today
49
+ (EMAILS_EXCEEDED), or a mute refused \u2014 a --dry-run that saw a real run would be
50
+ refused among them; 2 a bad command line; 3 the target refused to delete some
51
+ of the records found, or an object holds more than --max of them, the rest
52
+ left (with --dry-run too).
53
+ `,oe={switches:["--dry-run","--json",...Z],values:["--target","--since","--objects","--max"]},w=1,ae=3;function ie(n){return` what ${n} deletes along with them (a contact's tasks, an account's contacts) goes too, uncounted, and runs none of its delete automation: Salesforce runs none on a record deleted with its parent`}function h(n){process.stderr.write(`${n}
54
+ `),process.exit(2)}function de(n){let s=n.slice(2);(s.includes("-h")||s.includes("--help"))&&(process.stdout.write(ne),process.exit(0)),v(s,oe);let t=(c,b)=>{let l=s.indexOf(c);return l>=0&&l+1<s.length?s[l+1]:b},r=c=>s.includes(c),f=t("--target");f||h("Missing --target. Run with --help."),N.test(f)||h(`Invalid --target alias: ${f}. An sf alias or a username: letters, digits, _ . @ + and -, not starting with . @ + or -.`);let g=t("--objects"),y=g?g.split(",").map(c=>c.trim()).filter(Boolean):se;for(let c of y)try{R(c)}catch{h(`Invalid object name in --objects: ${c}`)}let A=t("--since","today")??"today",p="";try{p=ce(A)}catch(c){h(c instanceof Error?c.message:`Invalid --since: ${A}`)}let d=t("--max","200")??"200",m=Number(d);return(!Number.isInteger(m)||m<=0)&&h(`Invalid --max: ${d}. Expected a whole number above 0.`),{target:f,since:A,sinceSoql:p,objects:y,max:m,dryRun:r("--dry-run"),json:r("--json"),accord:Q(s)}}function ce(n){let s=n.toLowerCase();if(s==="today")return"TODAY";if(s==="yesterday")return"YESTERDAY";if(s==="this_week")return"THIS_WEEK";if(s==="last_week")return"LAST_WEEK";if(s.startsWith("last_n_days:")){let t=s.slice(12),r=Number(t);if(!/^\d+$/.test(t)||!Number.isInteger(r)||r<=0)throw new Error(`Invalid --since: ${n}`);return`LAST_N_DAYS:${r}`}if(re.test(n)){let t=new Date(`${n}T00:00:00Z`);if(!Number.isNaN(t.getTime())&&t.toISOString().startsWith(n))return`${n}T00:00:00Z`}throw new Error(`Invalid --since: ${n}. Allowed: today, yesterday, this_week, last_week, last_n_days:N, YYYY-MM-DD.`)}function le(n,s,t,r){return`SELECT Id FROM ${R(n)} WHERE CreatedDate >= ${s} AND CreatedById = '${j(t)}' LIMIT ${r}`}var ue=3;function fe(n){let s=new Set;for(let t of n)if(!t.success)for(let r of t.errors??[])s.add(typeof r=="string"?r:r.message??"refused");return[...s].slice(0,ue)}function ge(n){return n.some(s=>s.error!==void 0)?w:n.some(s=>s.failed>0||s.pastMax===!0)?ae:0}async function me(n=process.argv){let s=Date.now(),t=de(n),r=e=>t.json?console.error(e):console.log(e);r(`sandforge cleanup target=${t.target} since=${t.since} ${t.dryRun?"DRY-RUN":"REAL"}`);let f;try{f=await L(t.target)}catch(e){process.stderr.write(`${e instanceof Error?e.message:String(e)}
55
+ `),process.exit(w)}let g=P(f),y=t.dryRun?await D(g).then(M,()=>!0):!await k(g,t.target,{tool:"sandforge cleanup",action:"delete",readOnly:"--dry-run"}),p=(await g.query(`SELECT Id FROM User WHERE Username = '${j(f.username)}' LIMIT 1`)).records[0]?.Id??"";p||(console.error(`Could not resolve userId for ${f.username} on ${f.alias}.`),process.exit(1)),te.test(p)||(console.error(`Invalid userId returned by org: ${p}`),process.exit(1)),r(`user: ${f.username} (${p})
56
+ `);let d=[],m=new Map;for(let e of t.objects){let o={objectApiName:e,found:0,deleted:0,failed:0};d.push(o);try{let{records:i}=await F({query:async u=>g.query(u),queryMore:async u=>g.queryMore(u)},le(e,t.sinceSoql,p,t.max+1)),a=i.slice(0,t.max).map(u=>u.Id);i.length>t.max&&(o.pastMax=!0),o.found=a.length,a.length===0?r(` ${e.padEnd(40)} 0`):t.dryRun&&r(` ${e.padEnd(40)} ${a.length} [dry-run]`),a.length>0&&m.set(e,a),o.pastMax&&r(` ${e.padEnd(40)} more past --max ${t.max} left: run it again, or give a higher --max`)}catch(i){let a=i instanceof Error?i.message:String(i);if(a.includes("INVALID_TYPE")||a.includes("sObject type '")){o.notPresent=!0,r(` ${e.padEnd(40)} - (object not present on target)`);continue}o.error=a,r(` ${e.padEnd(40)} ERROR: ${a.slice(0,200)}`)}}let c=new J(z(async()=>g)),b=await B({act:"cleanup",target:t.target,objects:[...m].map(([e,o])=>({objectApiName:e,records:o.length})),org:U(g,e=>c.read(t.target,e),y),accord:t.accord,mayMute:!0}),l=b.answer;r("");for(let e of l.lines)r(e);m.size>0&&r(ie(t.target));let E;if(t.dryRun){for(let e of V(l))r(e);l.refusals.length>0&&(process.exitCode=w)}else if(l.refusals.length>0){for(let e of l.refusals)process.stderr.write(`${I(e)}
57
+ `);m.clear(),process.exitCode=w}else{let e=await H(b,`sandforge-cleanup-${Date.now()}`,t.accord.acceptEmails===!0);"refused"in e?(process.stderr.write(`${I(e.refused)}
58
+ `),m.clear(),process.exitCode=w):E=e.held}try{for(let e of d){let o=e.objectApiName,i=m.get(o);if(!(t.dryRun||!i))try{await G(o,i,e)}catch(a){let u=a instanceof Error?a.message:String(a);e.error=u,r(` ${o.padEnd(40)} ERROR: ${u.slice(0,200)}`)}}}finally{if(E){let e=await E.release();for(let o of W(e,t.target))r(` ${o}`)}}async function G(e,o,i){let a=await g.sobject(e).destroy(o,{allowRecursive:!0}),u=Array.isArray(a)?a:[a];i.deleted=u.filter(O=>O.success).length,i.failed=u.length-i.deleted;let x=fe(u);x.length>0&&(i.reasons=x);let ee=i.failed>0?` \x1B[31m(${i.failed} failed)\x1B[0m`:"";r(` ${e.padEnd(40)} ${o.length} deleted ${i.deleted}${ee}`);for(let O of x)r(` ${O.slice(0,200)}`)}let C=d.reduce((e,o)=>e+o.found,0),S=d.reduce((e,o)=>e+o.deleted,0),$=d.reduce((e,o)=>e+o.failed,0),T=Date.now()-s;if(q(ge(d)),t.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-cleanup",target:t.target,since:t.since,condition:`CreatedDate >= ${t.sinceSoql}`,dryRun:t.dryRun,objects:d,automation:l,...t.dryRun?Y(l.refusals):{},...!t.dryRun&&l.refusals[0]?{refused:l.refusals[0]}:{},found:C,deleted:S,failed:$,...d.some(e=>e.pastMax===!0)?{pastMax:d.filter(e=>e.pastMax===!0).map(e=>e.objectApiName)}:{},elapsedMs:T},null,2)}
59
+ `);return}let _=d.filter(e=>e.pastMax===!0).length;console.log(`
60
+ ${t.dryRun?"would delete":"deleted"} ${t.dryRun?C:S} record(s)${$>0?`, ${$} refused`:""}${_>0?`; ${_} object(s) hold more past --max ${t.max}`:""} in ${T}ms`)}/sandforge-cleanup\.[cm]?[jt]s$/.test(process.argv[1]??"")&&(X(),me().then(()=>process.exit(process.exitCode??0)).catch(n=>{console.error("FATAL:",n instanceof Error?n.stack:n),process.exit(1)}));export{ie as alongLine,ge as cleanupExitCode,le as cleanupSoql,me as main,ce as sinceClause};