sandforge 1.83.0 → 1.84.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 (254) hide show
  1. package/README.md +1 -1
  2. package/lib/chunk-23SEDORH.mjs +11 -0
  3. package/lib/{chunk-I5C4O3VA.mjs → chunk-24RFOFYT.mjs} +1 -1
  4. package/lib/chunk-26POJDIT.mjs +7 -0
  5. package/lib/{chunk-WJAZ5LHL.mjs → chunk-2AZQHBEF.mjs} +1 -1
  6. package/lib/{chunk-IHGYJZZ2.mjs → chunk-2HVOZUM4.mjs} +1 -1
  7. package/lib/{chunk-3V4YH5KO.mjs → chunk-2JDAOWUW.mjs} +1 -1
  8. package/lib/{chunk-BNKT3R3F.mjs → chunk-2METQHGG.mjs} +1 -1
  9. package/lib/chunk-2WFIVO4F.mjs +13 -0
  10. package/lib/chunk-2YHZBUZE.mjs +7 -0
  11. package/lib/{chunk-7DPHZWA4.mjs → chunk-326AJTIU.mjs} +14 -14
  12. package/lib/{chunk-UIR77ZJD.mjs → chunk-36JOHEJL.mjs} +1 -1
  13. package/lib/chunk-3PVRGTVK.mjs +7 -0
  14. package/lib/{chunk-2WMKJVD2.mjs → chunk-3Q353S2R.mjs} +1 -1
  15. package/lib/chunk-3TZSBHEY.mjs +7 -0
  16. package/lib/{chunk-T36DZJPH.mjs → chunk-43TOMFV4.mjs} +1 -1
  17. package/lib/{chunk-XAMMIPZ4.mjs → chunk-4CVUUVGJ.mjs} +1 -1
  18. package/lib/{chunk-6YC2ELCU.mjs → chunk-4EOHEDFP.mjs} +1 -1
  19. package/lib/{chunk-ZB5E7NHU.mjs → chunk-4JE4BYXK.mjs} +1 -1
  20. package/lib/{chunk-JREKJO3D.mjs → chunk-54WZUS7J.mjs} +1 -1
  21. package/lib/{chunk-CGZGL6VT.mjs → chunk-5CRLRHOJ.mjs} +1 -1
  22. package/lib/{chunk-UOHZW2L4.mjs → chunk-5IZTFMJM.mjs} +1 -1
  23. package/lib/{chunk-6VOQFISN.mjs → chunk-5M5FQ7RP.mjs} +1 -1
  24. package/lib/{chunk-U4YFYSF3.mjs → chunk-5SMWFNE7.mjs} +1 -1
  25. package/lib/{chunk-HQZUQXDC.mjs → chunk-5XTUSN72.mjs} +1 -1
  26. package/lib/chunk-6I6TWNV5.mjs +7 -0
  27. package/lib/{chunk-QLRWU3MB.mjs → chunk-6JWWSDM6.mjs} +1 -1
  28. package/lib/chunk-6O222PW6.mjs +7 -0
  29. package/lib/{chunk-J3TIHLWG.mjs → chunk-6PD6K7LP.mjs} +1 -1
  30. package/lib/{chunk-ISAUCWYK.mjs → chunk-6QE6R6RL.mjs} +1 -1
  31. package/lib/{chunk-2KTGDYUH.mjs → chunk-6WX5ZU7Q.mjs} +1 -1
  32. package/lib/{chunk-XAUQXYPW.mjs → chunk-6YL7BNYD.mjs} +1 -1
  33. package/lib/chunk-6ZLKIT3H.mjs +7 -0
  34. package/lib/{chunk-XKFHTBAB.mjs → chunk-7QYHEHMA.mjs} +1 -1
  35. package/lib/chunk-7SQSWVAU.mjs +9 -0
  36. package/lib/{chunk-NNV7IGM7.mjs → chunk-7UVKIWKV.mjs} +1 -1
  37. package/lib/{chunk-RZKJQOOC.mjs → chunk-7WATA4SB.mjs} +1 -1
  38. package/lib/{chunk-DMT5SCO3.mjs → chunk-7YNM6KFZ.mjs} +1 -1
  39. package/lib/{chunk-TMIESDE5.mjs → chunk-A3MYSOOC.mjs} +1 -1
  40. package/lib/chunk-AL4C3GFT.mjs +7 -0
  41. package/lib/chunk-B3FBHVNN.mjs +21 -0
  42. package/lib/{chunk-CDWZGQAJ.mjs → chunk-B63POIPQ.mjs} +1 -1
  43. package/lib/{chunk-YEVB7LVK.mjs → chunk-BAWCOKRW.mjs} +1 -1
  44. package/lib/{chunk-FVLFO2S6.mjs → chunk-BBRWFKS5.mjs} +1 -1
  45. package/lib/chunk-BEA27DLS.mjs +7 -0
  46. package/lib/chunk-BRY3PLIZ.mjs +7 -0
  47. package/lib/chunk-CBH3TOWK.mjs +341 -0
  48. package/lib/{chunk-7V2UYZ6S.mjs → chunk-CPQIZGG5.mjs} +1 -1
  49. package/lib/chunk-CVHNXJH3.mjs +7 -0
  50. package/lib/{chunk-ZOSESZ22.mjs → chunk-D4GF4FAB.mjs} +1 -1
  51. package/lib/chunk-DGDRQRCW.mjs +7 -0
  52. package/lib/{chunk-2N73W63D.mjs → chunk-DPMRIMUC.mjs} +1 -1
  53. package/lib/chunk-DUN2EPRC.mjs +7 -0
  54. package/lib/chunk-E3A3LOCY.mjs +7 -0
  55. package/lib/{chunk-KWAVSZ2B.mjs → chunk-EAC5QCE3.mjs} +1 -1
  56. package/lib/{chunk-JUOQUG7U.mjs → chunk-EC72TIEG.mjs} +1 -1
  57. package/lib/chunk-EPFCERGL.mjs +7 -0
  58. package/lib/{chunk-6KOUYHEY.mjs → chunk-ETDCBLGU.mjs} +1 -1
  59. package/lib/{chunk-2R6GFNKF.mjs → chunk-F3AQW6IU.mjs} +1 -1
  60. package/lib/{chunk-AHUGG3WU.mjs → chunk-FITPY3L4.mjs} +1 -1
  61. package/lib/chunk-FNJ4SGWO.mjs +7 -0
  62. package/lib/{chunk-EOQON3E5.mjs → chunk-FP7CYB2F.mjs} +1 -1
  63. package/lib/{chunk-262TP6UU.mjs → chunk-GKY2JMHY.mjs} +1 -1
  64. package/lib/{chunk-JBWJ6UEZ.mjs → chunk-GMIGWR6U.mjs} +1 -1
  65. package/lib/{chunk-OS5GE52G.mjs → chunk-GNRSF65U.mjs} +1 -1
  66. package/lib/chunk-GOOVPVWX.mjs +7 -0
  67. package/lib/{chunk-DB5RVDC5.mjs → chunk-GWZRR3MM.mjs} +1 -1
  68. package/lib/{chunk-SX6QWYCQ.mjs → chunk-H2BHESDA.mjs} +2 -2
  69. package/lib/chunk-H4CGM6YO.mjs +7 -0
  70. package/lib/{chunk-NFEBX75O.mjs → chunk-HCGXK7G7.mjs} +1 -1
  71. package/lib/{chunk-4X5D3MSV.mjs → chunk-HIDW7FNV.mjs} +1 -1
  72. package/lib/chunk-HSBXRQTI.mjs +7 -0
  73. package/lib/chunk-HUZPBE47.mjs +7 -0
  74. package/lib/{chunk-F5SBGJWW.mjs → chunk-HV7VPEXP.mjs} +1 -1
  75. package/lib/chunk-I6E6T6YY.mjs +7 -0
  76. package/lib/chunk-IUM4NFKI.mjs +10 -0
  77. package/lib/chunk-IVFVNNGB.mjs +37 -0
  78. package/lib/{chunk-L4MSL4U7.mjs → chunk-IZGCEOYO.mjs} +1 -1
  79. package/lib/{chunk-E3RQ575Y.mjs → chunk-J3DND3BC.mjs} +1 -1
  80. package/lib/{chunk-MJD6CPZZ.mjs → chunk-JAEDM4SI.mjs} +1 -1
  81. package/lib/chunk-JCFBFF4Y.mjs +7 -0
  82. package/lib/{chunk-U2CTKIPE.mjs → chunk-JE6SCT6R.mjs} +1 -1
  83. package/lib/{chunk-XJICAOAQ.mjs → chunk-JGZPD4IM.mjs} +1 -1
  84. package/lib/{chunk-XCJUNX63.mjs → chunk-JKJ74BX5.mjs} +1 -1
  85. package/lib/{chunk-WAYQLQAD.mjs → chunk-JLSIWO4Z.mjs} +1 -1
  86. package/lib/{chunk-D7XUNWWU.mjs → chunk-JSAJS3MY.mjs} +1 -1
  87. package/lib/chunk-JTJK2D36.mjs +7 -0
  88. package/lib/{chunk-OTJH6AEA.mjs → chunk-KAZS5Z6W.mjs} +1 -1
  89. package/lib/chunk-KB4ZHM4Q.mjs +10 -0
  90. package/lib/{chunk-N2HYG3BL.mjs → chunk-KGU4SVIT.mjs} +1 -1
  91. package/lib/{chunk-FKCIGJOI.mjs → chunk-KJWFYBMU.mjs} +2 -2
  92. package/lib/{chunk-KXUOHACP.mjs → chunk-KZTZDC7H.mjs} +1 -1
  93. package/lib/{chunk-S4PRKKGC.mjs → chunk-L2E5WBGD.mjs} +1 -1
  94. package/lib/{chunk-X2XZQ434.mjs → chunk-L53JWJ3S.mjs} +1 -1
  95. package/lib/{chunk-CQAFVEKP.mjs → chunk-LA4KIATH.mjs} +6 -6
  96. package/lib/chunk-LC3NDW4N.mjs +7 -0
  97. package/lib/{chunk-4V3QO7HF.mjs → chunk-LKTNQEBS.mjs} +1 -1
  98. package/lib/chunk-M2ABR4JM.mjs +7 -0
  99. package/lib/{chunk-3CM7LAPE.mjs → chunk-M4BLK6HJ.mjs} +1 -1
  100. package/lib/{chunk-Z3MGN42K.mjs → chunk-M6K34KGF.mjs} +1 -1
  101. package/lib/{chunk-TUPZY2QJ.mjs → chunk-MDMPJEV3.mjs} +1 -1
  102. package/lib/{chunk-BVZ5H3N4.mjs → chunk-MJZU3U5O.mjs} +68 -63
  103. package/lib/{chunk-OUU47Y7A.mjs → chunk-MSIEU5MR.mjs} +1 -1
  104. package/lib/{chunk-QQDZQCO2.mjs → chunk-N4WPCWJO.mjs} +1 -1
  105. package/lib/{chunk-MTM4KG3T.mjs → chunk-NCZKWSC7.mjs} +1 -1
  106. package/lib/{chunk-Y7YUNRKK.mjs → chunk-NED4MBIM.mjs} +1 -1
  107. package/lib/{chunk-QKJXIY6L.mjs → chunk-NOBQTEQD.mjs} +1 -1
  108. package/lib/{chunk-WBELLGNE.mjs → chunk-NSQWI7ZY.mjs} +1 -1
  109. package/lib/{chunk-BPHTA6KP.mjs → chunk-O677VOGO.mjs} +1 -1
  110. package/lib/chunk-OFTT7J2M.mjs +7 -0
  111. package/lib/{chunk-JH4ZTVQN.mjs → chunk-OLCVHL7I.mjs} +1 -1
  112. package/lib/chunk-OM5NORJG.mjs +7 -0
  113. package/lib/{chunk-QP3JLFIO.mjs → chunk-OMNMLKDT.mjs} +1 -1
  114. package/lib/{chunk-WABXKL4N.mjs → chunk-OPMO6I45.mjs} +1 -1
  115. package/lib/{chunk-7ZBDACVG.mjs → chunk-OUZQPYT3.mjs} +1 -1
  116. package/lib/chunk-OVNMB6Q2.mjs +7 -0
  117. package/lib/{chunk-DKDKCGXV.mjs → chunk-PAXNWTYK.mjs} +1 -1
  118. package/lib/{chunk-GLN4PI5P.mjs → chunk-PBY2O6OF.mjs} +1 -1
  119. package/lib/chunk-PEDQPM2P.mjs +926 -0
  120. package/lib/chunk-PH7SP4YK.mjs +21 -0
  121. package/lib/{chunk-BT43WSOS.mjs → chunk-PMN4PAC3.mjs} +1 -1
  122. package/lib/chunk-PMWAFDUB.mjs +48 -0
  123. package/lib/chunk-PPLVFX6N.mjs +7 -0
  124. package/lib/{chunk-L3I6DAHX.mjs → chunk-PR3XCSPO.mjs} +1 -1
  125. package/lib/{chunk-WZN36ACK.mjs → chunk-PR42EZSR.mjs} +1 -1
  126. package/lib/{chunk-NDFFIJL5.mjs → chunk-PWRJRL5U.mjs} +1 -1
  127. package/lib/{chunk-NS6ONPWL.mjs → chunk-Q7GIJBCD.mjs} +1 -1
  128. package/lib/chunk-Q7TLC3I2.mjs +7 -0
  129. package/lib/{chunk-ALBY5SOH.mjs → chunk-QAFPQ3YB.mjs} +1 -1
  130. package/lib/{chunk-KKS2KFBT.mjs → chunk-QKEKG2LD.mjs} +1 -1
  131. package/lib/{chunk-OOIDCHBQ.mjs → chunk-QO53K5W2.mjs} +2 -2
  132. package/lib/{chunk-HVX2AFYW.mjs → chunk-QTG6LUZT.mjs} +1 -1
  133. package/lib/{chunk-K7G3W7XH.mjs → chunk-RE7RYF3B.mjs} +1 -1
  134. package/lib/{chunk-JIPT5FUD.mjs → chunk-RGBGUCJA.mjs} +1 -1
  135. package/lib/{chunk-GT5ZKU6V.mjs → chunk-RGUQOSBU.mjs} +1 -1
  136. package/lib/{chunk-VXZ5PTOM.mjs → chunk-RHNTHGNU.mjs} +1 -1
  137. package/lib/chunk-RKTFFCNS.mjs +7 -0
  138. package/lib/chunk-RMFU4BAL.mjs +28 -0
  139. package/lib/{chunk-DNQKVCUV.mjs → chunk-ROV3QXEF.mjs} +11 -11
  140. package/lib/chunk-RT47RKLY.mjs +7 -0
  141. package/lib/{chunk-ISOSTAJR.mjs → chunk-S42RBRH2.mjs} +1 -1
  142. package/lib/{chunk-27BBEGUD.mjs → chunk-SI267LYR.mjs} +1 -1
  143. package/lib/chunk-T3G6VZNS.mjs +7 -0
  144. package/lib/chunk-TNT27RBG.mjs +7 -0
  145. package/lib/chunk-UBIKR5VO.mjs +7 -0
  146. package/lib/chunk-UI3JQVRU.mjs +8 -0
  147. package/lib/{chunk-RVCPQVKM.mjs → chunk-UIOMAX56.mjs} +1 -1
  148. package/lib/chunk-UX3BVH2Y.mjs +7 -0
  149. package/lib/{chunk-L4RJX7DG.mjs → chunk-VCUXCK36.mjs} +1 -1
  150. package/lib/chunk-VINGECAJ.mjs +10 -0
  151. package/lib/chunk-VOXJHJIE.mjs +7 -0
  152. package/lib/chunk-W6PN6TJG.mjs +7 -0
  153. package/lib/{chunk-D6JT4PAB.mjs → chunk-WAPSSYMT.mjs} +1 -1
  154. package/lib/{chunk-7BQMBXKX.mjs → chunk-WUUKFE2U.mjs} +1 -1
  155. package/lib/chunk-WWTCWWZI.mjs +7 -0
  156. package/lib/chunk-WXDLQT2O.mjs +10 -0
  157. package/lib/{chunk-TCEXCHXR.mjs → chunk-WY5V5PR3.mjs} +1 -1
  158. package/lib/chunk-X4BXESMQ.mjs +7 -0
  159. package/lib/chunk-XBQGZGWR.mjs +7 -0
  160. package/lib/{chunk-AXFD2OH6.mjs → chunk-XGGOUNPP.mjs} +1 -1
  161. package/lib/chunk-XKWW3GKF.mjs +7 -0
  162. package/lib/{chunk-PDRXM5WN.mjs → chunk-Y2DRK37K.mjs} +1 -1
  163. package/lib/{chunk-ZXOUWHYE.mjs → chunk-YA6ATMTB.mjs} +1 -1
  164. package/lib/{chunk-54HYHHVL.mjs → chunk-YDXMTWAT.mjs} +1 -1
  165. package/lib/chunk-YHR4WQPR.mjs +7 -0
  166. package/lib/{chunk-LWES2KZE.mjs → chunk-YTLUYSMF.mjs} +1 -1
  167. package/lib/{chunk-2K5BYZQM.mjs → chunk-YWEQQL3C.mjs} +1 -1
  168. package/lib/{chunk-C6RKM4BB.mjs → chunk-Z4LKKOFY.mjs} +1 -1
  169. package/lib/chunk-ZBAWJUG2.mjs +7 -0
  170. package/lib/{chunk-446GBKAC.mjs → chunk-ZJW6YOMV.mjs} +1 -1
  171. package/lib/chunk-ZQQXSCVI.mjs +7 -0
  172. package/lib/{chunk-L6CLN664.mjs → chunk-ZQWIVYVM.mjs} +1 -1
  173. package/lib/{chunk-CXKZ6TYV.mjs → chunk-ZV7ZFQQC.mjs} +1 -1
  174. package/lib/sandforge-autopilot.mjs +25 -25
  175. package/lib/sandforge-backup.mjs +1 -1
  176. package/lib/sandforge-checkpoint.mjs +1 -1
  177. package/lib/sandforge-cleanup.mjs +1 -1
  178. package/lib/sandforge-clone.mjs +1 -1
  179. package/lib/sandforge-compare.mjs +52 -21
  180. package/lib/sandforge-dataops.mjs +1 -1
  181. package/lib/sandforge-empty.mjs +1 -1
  182. package/lib/sandforge-env.mjs +95 -95
  183. package/lib/sandforge-frozen.mjs +1 -1
  184. package/lib/sandforge-mcp.mjs +12 -12
  185. package/lib/sandforge-monitor.mjs +1 -1
  186. package/lib/sandforge-pipeline.mjs +1 -1
  187. package/lib/sandforge-seed.mjs +1 -1
  188. package/lib/sandforge-sync.mjs +1 -1
  189. package/lib/sandforge-users.mjs +1 -1
  190. package/lib/sandforge.mjs +1 -1
  191. package/lib/sf/sandforge/compare.mjs +2 -2
  192. package/lib/sfPlugin.mjs +1 -1
  193. package/oclif.manifest.json +1 -1
  194. package/package.json +1 -1
  195. package/lib/chunk-2ADSD5WK.mjs +0 -7
  196. package/lib/chunk-2GSMHGIV.mjs +0 -7
  197. package/lib/chunk-36Y225OM.mjs +0 -7
  198. package/lib/chunk-3OVTKRS4.mjs +0 -7
  199. package/lib/chunk-4GCYGQXD.mjs +0 -7
  200. package/lib/chunk-4JKR4PTZ.mjs +0 -8
  201. package/lib/chunk-5OGNK3JP.mjs +0 -37
  202. package/lib/chunk-6QSHWIZI.mjs +0 -48
  203. package/lib/chunk-77IVKH7R.mjs +0 -7
  204. package/lib/chunk-77MZRBWX.mjs +0 -7
  205. package/lib/chunk-7WSQ65WG.mjs +0 -9
  206. package/lib/chunk-A32ISQ6M.mjs +0 -28
  207. package/lib/chunk-AG24QMSY.mjs +0 -7
  208. package/lib/chunk-BH76USTQ.mjs +0 -11
  209. package/lib/chunk-BZ24IAP5.mjs +0 -7
  210. package/lib/chunk-CN5HGFG4.mjs +0 -7
  211. package/lib/chunk-CTPLYUXA.mjs +0 -7
  212. package/lib/chunk-DIGUC7S4.mjs +0 -341
  213. package/lib/chunk-DSR2MSBH.mjs +0 -7
  214. package/lib/chunk-ETNQHIDI.mjs +0 -9
  215. package/lib/chunk-FBXH4VRQ.mjs +0 -7
  216. package/lib/chunk-FYWNSMOZ.mjs +0 -10
  217. package/lib/chunk-GEEWPTV5.mjs +0 -7
  218. package/lib/chunk-GTRU5AV5.mjs +0 -7
  219. package/lib/chunk-I3ZO76LL.mjs +0 -21
  220. package/lib/chunk-ISA2NYJV.mjs +0 -7
  221. package/lib/chunk-IXIY6Q4M.mjs +0 -7
  222. package/lib/chunk-JAV6F6OA.mjs +0 -7
  223. package/lib/chunk-JYUMD357.mjs +0 -7
  224. package/lib/chunk-L47JCNP3.mjs +0 -7
  225. package/lib/chunk-LI2XNV7F.mjs +0 -7
  226. package/lib/chunk-LP2D3JJP.mjs +0 -7
  227. package/lib/chunk-LYOGCIYD.mjs +0 -925
  228. package/lib/chunk-N5UIE4IR.mjs +0 -7
  229. package/lib/chunk-O7GCCRPW.mjs +0 -7
  230. package/lib/chunk-OO24ZYYJ.mjs +0 -7
  231. package/lib/chunk-OS6HFJ7L.mjs +0 -7
  232. package/lib/chunk-P6WRYJN3.mjs +0 -7
  233. package/lib/chunk-PGRY365W.mjs +0 -7
  234. package/lib/chunk-PPGDAUEQ.mjs +0 -7
  235. package/lib/chunk-Q4PPI3KG.mjs +0 -7
  236. package/lib/chunk-QFTF2PGS.mjs +0 -21
  237. package/lib/chunk-QO4MPHZD.mjs +0 -7
  238. package/lib/chunk-QXB6U3ZP.mjs +0 -7
  239. package/lib/chunk-R3OM3X4L.mjs +0 -8
  240. package/lib/chunk-R7GKMAT4.mjs +0 -7
  241. package/lib/chunk-SCKUIE3R.mjs +0 -7
  242. package/lib/chunk-SU65Z2BA.mjs +0 -7
  243. package/lib/chunk-T7DDS4UQ.mjs +0 -7
  244. package/lib/chunk-TQJ5NPRC.mjs +0 -7
  245. package/lib/chunk-VZLJZEV2.mjs +0 -7
  246. package/lib/chunk-W3BQGMTR.mjs +0 -7
  247. package/lib/chunk-WXU6ZJIV.mjs +0 -7
  248. package/lib/chunk-X4HZD5U2.mjs +0 -7
  249. package/lib/chunk-X6XNTOGO.mjs +0 -7
  250. package/lib/chunk-XMQ5R6TC.mjs +0 -10
  251. package/lib/chunk-XPXEQKLR.mjs +0 -7
  252. package/lib/chunk-YBZIDW6W.mjs +0 -7
  253. package/lib/chunk-ZCOSME6P.mjs +0 -7
  254. package/lib/chunk-ZTHC42X6.mjs +0 -7
@@ -4,6 +4,6 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{e as k,f as w}from"./chunk-27BBEGUD.mjs";import{g as A,k as S}from"./chunk-H4OBZIX3.mjs";import{Sb as T,Tb as h}from"./chunk-6QSHWIZI.mjs";import{mkdir as v,rename as D,writeFile as x}from"node:fs/promises";import*as f from"node:path";var y="CaseId",O=80;function $(e){let t=T.safeParse(e.choice);if(!t.success)return{ok:!1,refusals:t.error.issues.map(a=>({code:"choice-invalid",name:a.path.join("."),message:a.message}))};let n=t.data,s=A(e.catalog,n.agent);if(!s)return{ok:!1,refusals:[{code:"agent-absent",name:n.agent,message:`"${n.agent}" is not one of this org's agents`}]};let r=P(n,s,E(e.compiled.tests));if(r.length>0)return{ok:!1,refusals:r};let i=new Map(n.topics.map(a=>[a.packTopic,a])),c=S(s,y)?y:void 0,g=[],o=[];for(let a of e.compiled.tests){if(a.topicKey===null){if(n.guardTopic===null){o.push({test:a.key,reason:"no-guard-topic",message:`"${a.utterance}" is on no topic of the scenario, and no topic of the agent is chosen to decline it: the test is left out`});continue}g.push({key:a.key,utterance:a.utterance,expectedTopic:n.guardTopic,expectedActions:[],expectedOutcome:a.expectedOutcome,contextVariables:[]});continue}let u=i.get(a.topicKey),p=[];if(a.openCase){let m=e.openCaseIds[a.openCase.caseKey];if(m===void 0){o.push({test:a.key,reason:"case-not-written",message:`The case ${a.openCase.caseKey} the test is about was not written by the run: the test is left out`});continue}c!==void 0&&p.push({name:c,value:m})}g.push({key:a.key,utterance:a.utterance,expectedTopic:u.agentTopic,expectedActions:[...u.actions],expectedOutcome:j(a),contextVariables:p})}return g.length===0?{ok:!1,refusals:[{code:"no-test-left",name:e.compiled.packId,message:"No test of the scenario is left to write: "+o.map(a=>a.message).join("; ")}]}:{ok:!0,spec:{name:M(e.compiled.template.name),description:F(e.compiled.packId,e.compiled.seed,e.runId),subjectName:s.name,testCases:g},choice:n,leftOut:o,...c!==void 0?{contextVariable:c}:{}}}function E(e){return[...new Set(e.flatMap(t=>t.topicKey===null?[]:[t.topicKey]))]}function P(e,t,n){let s=[],r=new Map(t.topics.map(o=>[o.name,o])),i=new Set(t.topics.flatMap(o=>o.actions.map(a=>a.name))),c=o=>({code:"topic-absent",name:o,message:`"${o}" is not a topic of the agent ${t.name}`});for(let o of e.topics){n.includes(o.packTopic)||s.push({code:"pack-topic-unknown",name:o.packTopic,message:`"${o.packTopic}" is not a topic of the scenario`});let a=r.get(o.agentTopic);if(!a){s.push(c(o.agentTopic));continue}let u=new Set(a.actions.map(p=>p.name));for(let p of o.actions)u.has(p)||s.push(i.has(p)?{code:"action-not-of-topic",name:p,message:`"${p}" is not an action of the topic ${a.name}, which the agent answers "${o.packTopic}" from`}:{code:"action-absent",name:p,message:`"${p}" is not an action of the agent ${t.name}`})}let g=new Set(e.topics.map(o=>o.packTopic));for(let o of n)g.has(o)||s.push({code:"pack-topic-unmatched",name:o,message:`The topic "${o}" of the scenario is matched to no topic of the agent`});return e.guardTopic!==null&&!r.has(e.guardTopic)&&s.push(c(e.guardTopic)),s}function j(e){if(!e.article)return e.expectedOutcome;let t=e.article.facts.length>0?`, which states: ${e.article.facts.join("; ")}`:"";return`${e.expectedOutcome} The answer draws on the article "${e.article.title}"${t}.`}function M(e){let t=" (SandForge)",n=O-t.length;return`${e.length>n?e.slice(0,n).trimEnd():e}${t}`}function F(e,t,n){let s=n!==void 0?`, written by the seed run ${n}`:"";return`SandForge scenario ${e}, seed ${t}${s}. Its cases are about the records that run wrote: once it is removed, they are about none.`}var C="specs",L=80,V=10;function K(e,t){return G(h(e,t))}function W(e,t,n){let s=n==="agentforce-studio"?"ngtTestSpec":"testSpec";return`${b(e)}-${b(t)}-sandforge-${s}.yaml`}function z(e,t){let n=c=>c.replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,""),s=`${n(t)}_SandForge`,r=n(e);/^[A-Za-z]/.test(r)||(r=`Agent_${r}`.replace(/_+$/,""));let i=L-s.length-1;return r=r.slice(0,i).replace(/_+$/,""),`${r}_${s}`}function Z(e){let t=e.runner==="agentforce-studio"?["--test-runner","agentforce-studio"]:[],n=["sf","agent","test","create","--spec",e.specPath,"--api-name",e.apiName,...t,"-o",e.alias],s=["sf","agent","test","run","--api-name",e.apiName,"--wait",String(V),...t,"-o",e.alias];return{create:{argv:n,line:R(n)},run:{argv:s,line:R(s)}}}function te(){return{mkdir:async e=>{await v(e,{recursive:!0})},writeNew:async(e,t)=>{try{return await x(e,t,{encoding:"utf8",flag:"wx"}),!0}catch(n){if(n.code==="EEXIST")return!1;throw n}},replace:async(e,t)=>{let n=`${e}.${process.pid}.tmp`;await x(n,t,"utf8"),await D(n,e)}}}async function X(e,t){let n=W(t.model.subjectName,t.packId,t.runner),s=`${C}/${n}`,r=f.join(t.projectDir,C,n),i=K(t.model,t.runner);if(await e.mkdir(f.dirname(r)),t.overwrite===!0)await e.replace(r,i);else if(!await e.writeNew(r,i))return{kind:"exists",path:r,specPath:s};let c=z(t.model.subjectName,t.packId);return{kind:"written",path:r,specPath:s,apiName:c,commands:Z({specPath:s,apiName:c,alias:t.alias,runner:t.runner})}}async function ne(e,t){let n=w(t.sidecar,t.pack);if(!n.ok)return{kind:"refused",refusals:[{code:"pack-changed",name:t.pack.id,message:n.message}]};let s=$({compiled:n.compiled,catalog:t.catalog,choice:t.choice,openCaseIds:t.sidecar.openCases,runId:t.sidecar.runId});if(!s.ok)return{kind:"refused",refusals:s.refusals};let{choice:r}=s,i=await X(e,{projectDir:t.projectDir,model:s.spec,runner:r.runner,packId:t.pack.id,alias:t.alias,...t.overwrite!==void 0?{overwrite:t.overwrite}:{}});return i.kind==="exists"?i:{...i,leftOut:s.leftOut,sidecar:k(t.sidecar,r)}}function G(e){return`${l(e,0).join(`
7
+ import{e as k,f as w}from"./chunk-SI267LYR.mjs";import{g as A,k as S}from"./chunk-H4OBZIX3.mjs";import{Sb as T,Tb as h}from"./chunk-PMWAFDUB.mjs";import{mkdir as v,rename as D,writeFile as x}from"node:fs/promises";import*as f from"node:path";var y="CaseId",O=80;function $(e){let t=T.safeParse(e.choice);if(!t.success)return{ok:!1,refusals:t.error.issues.map(a=>({code:"choice-invalid",name:a.path.join("."),message:a.message}))};let n=t.data,s=A(e.catalog,n.agent);if(!s)return{ok:!1,refusals:[{code:"agent-absent",name:n.agent,message:`"${n.agent}" is not one of this org's agents`}]};let r=P(n,s,E(e.compiled.tests));if(r.length>0)return{ok:!1,refusals:r};let i=new Map(n.topics.map(a=>[a.packTopic,a])),c=S(s,y)?y:void 0,g=[],o=[];for(let a of e.compiled.tests){if(a.topicKey===null){if(n.guardTopic===null){o.push({test:a.key,reason:"no-guard-topic",message:`"${a.utterance}" is on no topic of the scenario, and no topic of the agent is chosen to decline it: the test is left out`});continue}g.push({key:a.key,utterance:a.utterance,expectedTopic:n.guardTopic,expectedActions:[],expectedOutcome:a.expectedOutcome,contextVariables:[]});continue}let u=i.get(a.topicKey),p=[];if(a.openCase){let m=e.openCaseIds[a.openCase.caseKey];if(m===void 0){o.push({test:a.key,reason:"case-not-written",message:`The case ${a.openCase.caseKey} the test is about was not written by the run: the test is left out`});continue}c!==void 0&&p.push({name:c,value:m})}g.push({key:a.key,utterance:a.utterance,expectedTopic:u.agentTopic,expectedActions:[...u.actions],expectedOutcome:j(a),contextVariables:p})}return g.length===0?{ok:!1,refusals:[{code:"no-test-left",name:e.compiled.packId,message:"No test of the scenario is left to write: "+o.map(a=>a.message).join("; ")}]}:{ok:!0,spec:{name:M(e.compiled.template.name),description:F(e.compiled.packId,e.compiled.seed,e.runId),subjectName:s.name,testCases:g},choice:n,leftOut:o,...c!==void 0?{contextVariable:c}:{}}}function E(e){return[...new Set(e.flatMap(t=>t.topicKey===null?[]:[t.topicKey]))]}function P(e,t,n){let s=[],r=new Map(t.topics.map(o=>[o.name,o])),i=new Set(t.topics.flatMap(o=>o.actions.map(a=>a.name))),c=o=>({code:"topic-absent",name:o,message:`"${o}" is not a topic of the agent ${t.name}`});for(let o of e.topics){n.includes(o.packTopic)||s.push({code:"pack-topic-unknown",name:o.packTopic,message:`"${o.packTopic}" is not a topic of the scenario`});let a=r.get(o.agentTopic);if(!a){s.push(c(o.agentTopic));continue}let u=new Set(a.actions.map(p=>p.name));for(let p of o.actions)u.has(p)||s.push(i.has(p)?{code:"action-not-of-topic",name:p,message:`"${p}" is not an action of the topic ${a.name}, which the agent answers "${o.packTopic}" from`}:{code:"action-absent",name:p,message:`"${p}" is not an action of the agent ${t.name}`})}let g=new Set(e.topics.map(o=>o.packTopic));for(let o of n)g.has(o)||s.push({code:"pack-topic-unmatched",name:o,message:`The topic "${o}" of the scenario is matched to no topic of the agent`});return e.guardTopic!==null&&!r.has(e.guardTopic)&&s.push(c(e.guardTopic)),s}function j(e){if(!e.article)return e.expectedOutcome;let t=e.article.facts.length>0?`, which states: ${e.article.facts.join("; ")}`:"";return`${e.expectedOutcome} The answer draws on the article "${e.article.title}"${t}.`}function M(e){let t=" (SandForge)",n=O-t.length;return`${e.length>n?e.slice(0,n).trimEnd():e}${t}`}function F(e,t,n){let s=n!==void 0?`, written by the seed run ${n}`:"";return`SandForge scenario ${e}, seed ${t}${s}. Its cases are about the records that run wrote: once it is removed, they are about none.`}var C="specs",L=80,V=10;function K(e,t){return G(h(e,t))}function W(e,t,n){let s=n==="agentforce-studio"?"ngtTestSpec":"testSpec";return`${b(e)}-${b(t)}-sandforge-${s}.yaml`}function z(e,t){let n=c=>c.replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,""),s=`${n(t)}_SandForge`,r=n(e);/^[A-Za-z]/.test(r)||(r=`Agent_${r}`.replace(/_+$/,""));let i=L-s.length-1;return r=r.slice(0,i).replace(/_+$/,""),`${r}_${s}`}function Z(e){let t=e.runner==="agentforce-studio"?["--test-runner","agentforce-studio"]:[],n=["sf","agent","test","create","--spec",e.specPath,"--api-name",e.apiName,...t,"-o",e.alias],s=["sf","agent","test","run","--api-name",e.apiName,"--wait",String(V),...t,"-o",e.alias];return{create:{argv:n,line:R(n)},run:{argv:s,line:R(s)}}}function te(){return{mkdir:async e=>{await v(e,{recursive:!0})},writeNew:async(e,t)=>{try{return await x(e,t,{encoding:"utf8",flag:"wx"}),!0}catch(n){if(n.code==="EEXIST")return!1;throw n}},replace:async(e,t)=>{let n=`${e}.${process.pid}.tmp`;await x(n,t,"utf8"),await D(n,e)}}}async function X(e,t){let n=W(t.model.subjectName,t.packId,t.runner),s=`${C}/${n}`,r=f.join(t.projectDir,C,n),i=K(t.model,t.runner);if(await e.mkdir(f.dirname(r)),t.overwrite===!0)await e.replace(r,i);else if(!await e.writeNew(r,i))return{kind:"exists",path:r,specPath:s};let c=z(t.model.subjectName,t.packId);return{kind:"written",path:r,specPath:s,apiName:c,commands:Z({specPath:s,apiName:c,alias:t.alias,runner:t.runner})}}async function ne(e,t){let n=w(t.sidecar,t.pack);if(!n.ok)return{kind:"refused",refusals:[{code:"pack-changed",name:t.pack.id,message:n.message}]};let s=$({compiled:n.compiled,catalog:t.catalog,choice:t.choice,openCaseIds:t.sidecar.openCases,runId:t.sidecar.runId});if(!s.ok)return{kind:"refused",refusals:s.refusals};let{choice:r}=s,i=await X(e,{projectDir:t.projectDir,model:s.spec,runner:r.runner,packId:t.pack.id,alias:t.alias,...t.overwrite!==void 0?{overwrite:t.overwrite}:{}});return i.kind==="exists"?i:{...i,leftOut:s.leftOut,sidecar:k(t.sidecar,r)}}function G(e){return`${l(e,0).join(`
8
8
  `)}
9
9
  `}function l(e,t){let n=" ".repeat(t),s=[];for(let[r,i]of Object.entries(e)){if(i===void 0)continue;let c=`${n}${J(r)}:`;Array.isArray(i)?i.length===0?s.push(`${c} []`):s.push(c,...I(i,t+2)):d(i)?Object.values(i).every(g=>g===void 0)?s.push(`${c} {}`):s.push(c,...l(i,t+2)):s.push(`${c} ${_(i)}`)}return s}function I(e,t){let n=" ".repeat(t),s=[];for(let r of e){let i=Array.isArray(r)?r.length===0?void 0:I(r,t+2):d(r)&&Object.values(r).some(c=>c!==void 0)?l(r,t+2):void 0;if(i===void 0){s.push(`${n}- ${Array.isArray(r)?"[]":d(r)?"{}":_(r)}`);continue}s.push(`${n}- ${i[0].slice(t+2)}`,...i.slice(1))}return s}function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function J(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)?e:N(e)}function _(e){if(typeof e=="string")return N(e);if(typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return String(e);if(e===null)return"null";throw new TypeError(`No YAML scalar for ${typeof e}`)}function N(e){return JSON.stringify(e).replace(/[\u007f-\u009f\u2028\u2029\ufeff\ufffe\uffff]/g,t=>`\\u${t.charCodeAt(0).toString(16).padStart(4,"0")}`)}function b(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}function R(e){return e.map(t=>/^[A-Za-z0-9_./:@=+,-]+$/.test(t)?t:`"${t.replace(/(["\\])/g,"\\$1")}"`).join(" ")}export{C as a,V as b,K as c,W as d,z as e,Z as f,te as g,X as h,ne as i,G as j};
@@ -0,0 +1,7 @@
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{f as a,g as b,h as c,i as d,j as e,k as f,l as g}from"./chunk-WXDLQT2O.mjs";import"./chunk-JE6SCT6R.mjs";import"./chunk-PWRJRL5U.mjs";import"./chunk-UIOMAX56.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-L53JWJ3S.mjs";import"./chunk-H4CGM6YO.mjs";import"./chunk-YDXMTWAT.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-FP7CYB2F.mjs";import"./chunk-NED4MBIM.mjs";import"./chunk-UI3JQVRU.mjs";import"./chunk-KGU4SVIT.mjs";import"./chunk-JAEDM4SI.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-D4GF4FAB.mjs";import"./chunk-CVHNXJH3.mjs";import"./chunk-YA6ATMTB.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-M6K34KGF.mjs";import"./chunk-TNT27RBG.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-S42RBRH2.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-ICIYL45C.mjs";import"./chunk-WUUKFE2U.mjs";import"./chunk-EAC5QCE3.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{d as diffOfPicked,b as heldInPlaceReason,g as planSelection,c as rewindPlan,a as rewindWriters,f as selectionPlanOf,e as snapshotRowsOf};
@@ -0,0 +1,7 @@
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{d as Y,f as Z}from"./chunk-OMNMLKDT.mjs";import{h as J}from"./chunk-QO53K5W2.mjs";import"./chunk-ZV7ZFQQC.mjs";import{b as G}from"./chunk-L2E5WBGD.mjs";import"./chunk-7YNM6KFZ.mjs";import"./chunk-H33DVU3D.mjs";import{a as V}from"./chunk-MDMPJEV3.mjs";import{a as K}from"./chunk-CPQIZGG5.mjs";import{d as H}from"./chunk-YWEQQL3C.mjs";import"./chunk-GMIGWR6U.mjs";import"./chunk-UV74P4H2.mjs";import{k as D}from"./chunk-KGU4SVIT.mjs";import{e as R}from"./chunk-23SEDORH.mjs";import"./chunk-W6PN6TJG.mjs";import"./chunk-VV3B6IC3.mjs";import"./chunk-Q7TLC3I2.mjs";import"./chunk-M6K34KGF.mjs";import"./chunk-TNT27RBG.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-S42RBRH2.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import{Jb as C,Kb as B,Lb as M,Ua as E,Zc as U,_c as L,dd as h,s as v,zb as F}from"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";import{readFile as W}from"node:fs/promises";import{homedir as ee}from"node:os";import{join as b}from"node:path";var ne="none";function p(e){return e!==void 0&&E.safeParse(e).success?e:void 0}function te(e,n){return D(e)===D(n)}function l(e,n){return e!==void 0&&e!==""&&e.length<=n?e:void 0}function re(e,n,t){return B(e,n!==void 0?K(n,t):ne)}function oe(e,n){let t=M.safeParse(e.get(n));return t.success?t.data:{steps:{}}}function be(e,n=ee()){let t=e.get("frozen:config");if(typeof t?.datasetDir=="string"&&t.datasetDir!=="")return t.datasetDir;let i=typeof t?.sasDir=="string"&&t.sasDir!==""?t.sasDir:b(n,".sandforge-sas");return b(i,"dataset")}async function ie(e){let n;try{n=await W(b(e,"manifest.json"),"utf8")}catch{return}try{let t=H(JSON.parse(n)),i=Object.values(t.volumetry.measured),s=l(t.source.orgAlias,255);return{frozenAt:new Date(t.frozenAt).toISOString(),...s!==void 0?{sourceAlias:s}:{},objects:i.length,records:i.reduce((r,o)=>r+Math.max(0,Math.trunc(o)),0)}}catch{return}}function X(e,n,t,i){let s=i!==void 0?Date.parse(i):Number.NEGATIVE_INFINITY;return new R(e).list({orgId:n,limit:v}).entries.find(o=>o.action===t&&o.outcome==="success"&&Date.parse(o.timestamp)>s)?.timestamp}var se=/^[A-Za-z][A-Za-z0-9_]{0,79}$/;function ae(e,n){let t=new R(e).list({limit:v}).entries.filter(r=>r.action==="anonymize_execute").map(r=>({orgId:r.orgId,objects:[...new Set((Array.isArray(r.objects)?r.objects:[]).map(o=>o.objectApiName).filter(o=>typeof o=="string"&&se.test(o)))].slice(0,C)})).filter(r=>r.objects.length>0),i=t.find(r=>r.orgId===n),s=i??t[0];return s!==void 0?{objects:s.objects,from:i!==void 0?"org":"machine"}:void 0}function de(e){return(e.removals??[]).some(n=>n.status==="success"||n.undone>0)}function ce(e,n){return Object.values(e.getByCategory("pipelines")).some(t=>{let i=t?.triggers;return Array.isArray(i)&&i.some(s=>{let r=s;return r?.type==="sandbox_refresh"&&r.enabled!==!1&&r.config?.orgId===n})})}function fe(e,n,t){let i=p(e.organizationId),s=l(e.previousInstanceName,40),r=l(e.instanceName,40),o=e.reportedBy!==void 0?t(e.reportedBy):void 0,d=l(o!==void 0?h(o,o.username):void 0,255);return{detectedAt:new Date(e.detectedAt).toISOString(),evidence:e.evidence,...n!==void 0?{previousOrganizationId:n}:{},...i!==void 0?{organizationId:i}:{},...s!==void 0?{previousInstanceName:s}:{},...r!==void 0?{instanceName:r}:{},...d!==void 0?{reportedBy:d}:{},cachesForgotten:!0}}async function $(e,n){return(await e.list({organizationId:n})).flatMap(i=>i.checkpoint?.status==="ready"?[{checkpointId:i.checkpointId,name:i.checkpoint.name,takenAt:new Date(i.checkpoint.takenAt).toISOString(),keptUntilDeleted:i.checkpoint.expiresAt===null}]:[]).sort((i,s)=>Date.parse(s.takenAt)-Date.parse(i.takenAt))}async function Ie(e,n){let t=e.orgOf(n);if(t===void 0)return{refused:"ORG_NOT_FOUND"};if(!L(t))return{refused:"NOT_A_DEVELOPMENT_ORG"};let i=U(t);if(i==="production")return{refused:"NOT_A_DEVELOPMENT_ORG"};let s=t.orgType==="Sandbox"?"sandbox":t.orgType==="Scratch"?"scratch":"developer",r=s==="sandbox"?e.refreshesOf(n)[0]:void 0,o=p(r!==void 0?r.organizationId:e.organizationIdOf(n)??t.orgId),d=r!==void 0?p(r.previousOrganizationId??(r.organizationId===void 0?e.organizationIdOf(n):void 0)):void 0,y=V(t.instanceUrl),f=y!==void 0&&F.safeParse(y).success?y:void 0,I=r?.detectedAt,z=await e.checkpoints(),q=d!==void 0?await $(z,d):[],Q=o!==void 0?await $(z,o):[],u=q[0],k;d!==void 0&&o!==void 0&&(k=(await e.replays().list({sourceOrganizationId:d,targetOrganizationId:o})).flatMap(a=>a.replayedAt!==void 0&&a.removed!==!0?[a.replayedAt]:[]).sort().at(-1));let c=(o!==void 0?await e.users().list(o):[]).find(a=>a.status!=="running"),O,A;if(f!==void 0){let{kept:a}=await G(e.journalDir,f),g=S=>o!==void 0&&te(S.inventory.organizationId,o),m=a.find(S=>!g(S));m!==void 0&&(O={savedAt:m.inventory.savedAt,organizationId:m.inventory.organizationId,jobs:m.inventory.jobs.length}),A=a.find(g)?.inventory.savedAt}let N=Z(e.configStore,Y(f,n)),w=await ie(e.frozenDatasetDir()),_=o!==void 0?await J(e.journalDir,o):void 0,T=o!==void 0?e.usersListed?.(n,o):void 0,j=X(e.configStore,n,"anonymize_execute",I),P=X(e.configStore,n,"frozen_load",I),x=ae(e.configStore,n);return{facts:{orgId:n,alias:h(t,t.username)||n,tier:i,kind:s,...s==="sandbox"&&t.sandboxType!==void 0?{sandboxType:t.sandboxType}:{},...f!==void 0?{myDomainHost:f}:{},...o!==void 0?{organizationId:o}:{},...r!==void 0?{refresh:fe(r,d,e.orgOf)}:{},acks:oe(e.configStore,re(n,r,a=>e.organizationIdOf(a))),...u!==void 0?{checkpointBefore:{checkpointId:u.checkpointId,name:u.name,takenAt:u.takenAt}}:{},...k!==void 0?{replayedAt:k}:{},checkpointsNow:Q.map(({takenAt:a,keptUntilDeleted:g})=>({takenAt:a,keptUntilDeleted:g})),...c!==void 0?{lastUsersRun:{run:c.run,at:c.endedAt??c.startedAt,status:c.status}}:{},...c!==void 0&&de(c)?{lastUsersRunTakenBack:!0}:{},...T!==void 0?{usersToBringBack:T}:{},...j!==void 0?{maskedAt:j}:{},...x!==void 0?{maskObjects:x}:{},...P!==void 0?{frozenLoadedAt:P}:{},...w!==void 0?{frozenManifest:w}:{},...O!==void 0?{inventoryBefore:O}:{},...A!==void 0?{inventoryNowAt:A}:{},..._!==void 0?{handoffAt:_}:{},...N!==void 0?{testersSavedAt:N.savedAt}:{},refreshPipeline:ce(e.configStore,n)}}}export{ne as NO_REFRESH_KEY,be as frozenDatasetDirOf,oe as readAcks,re as recoveryAckKeyOf,Ie as recoveryFactsOf};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{ld as c,md as l,od as d,pd as m}from"./chunk-6QSHWIZI.mjs";var g=class{transform(n,r){let t=n;for(let o of r)t=p(t,o.type,o.config);return t}transformRecord(n,r){let t=d([{objectApiName:r.objectApiName,transformRules:r.transformRules}]);if(t.length>0)throw new Error(m(t));let o={...n},s=(r.externalIdField??"Id").toLowerCase(),R=a=>{let i=a.toLowerCase();return i!==s&&i!=="id"};for(let a of r.transformRules){let i=a.field?.trim();if(!i)throw new Error(l(c([r])));for(let f of h(o,i))R(f)&&(o[f]=p(o[f],a.type,a.config))}return o}};function h(e,n){let r=n.toLowerCase();return Object.keys(e).filter(t=>t.toLowerCase()===r)}function u(e){return(n,r)=>typeof n=="string"?e(n,r):n}function w(e){if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string"||e.trim()==="")return;let n=Number(e);return Number.isNaN(n)?void 0:n}var b={uppercase:u(e=>e.toUpperCase()),lowercase:u(e=>e.toLowerCase()),trim:u(e=>e.trim()),truncate:u((e,n)=>e.slice(0,n.length??e.length)),prefix:u((e,n)=>`${n.prefix??""}${e}`),suffix:u((e,n)=>`${e}${n.suffix??""}`),replace:u((e,n)=>n.search?e.split(n.search).join(n.replace??""):e),regex_replace:u((e,n)=>n.regex?e.replace(y(n.regex),n.replace??""):e),map_value:(e,n)=>{let r=String(e??""),t=n.valueMap??{};return r in t?t[r]:e},default_value:(e,n)=>e==null||e===""?n.defaultValue??"":e,format_date:u((e,n)=>T(e,n.dateFormat??"YYYY-MM-DD")),format_number:(e,n)=>{let r=w(e);if(r===void 0)return e;let t=n.numberFormat??"0";return k(r,t)},custom_formula:(e,n)=>{let r=n.formula??"";return x(e,r)}};function y(e){try{return new RegExp(e,"g")}catch(n){throw new Error(`The pattern "${e}" of a Regex replace rule is no regular expression: `+(n instanceof Error?n.message:String(n)))}}function p(e,n,r){let t=b[n];return t(e,r)}function T(e,n){let r=new Date(e);if(isNaN(r.getTime()))return e;let t=r.getUTCFullYear().toString(),o=(r.getUTCMonth()+1).toString().padStart(2,"0"),s=r.getUTCDate().toString().padStart(2,"0");return n.replace("YYYY",t).replace("MM",o).replace("DD",s)}function k(e,n){let r=n.indexOf(".");if(r===-1)return Math.round(e).toString();let t=n.length-r-1;return e.toFixed(t)}function x(e,n){if(n.includes("VALUE")){let r=w(e);if(r!==void 0){let t=n.replace(/VALUE/g,r.toString());return N(t)??e}}return e}function N(e){let n=e.replace(/\s/g,""),r=/^(-?\d+(?:\.\d+)?)([-+*/])(-?\d+(?:\.\d+)?)$/.exec(n);if(!r)return;let t=Number(r[1]),o=r[2],s=Number(r[3]);switch(o){case"+":return t+s;case"-":return t-s;case"*":return t*s;case"/":return s===0?void 0:t/s;default:return}}export{g as a};
7
+ import{ld as c,md as l,od as d,pd as m}from"./chunk-PMWAFDUB.mjs";var g=class{transform(n,r){let t=n;for(let o of r)t=p(t,o.type,o.config);return t}transformRecord(n,r){let t=d([{objectApiName:r.objectApiName,transformRules:r.transformRules}]);if(t.length>0)throw new Error(m(t));let o={...n},s=(r.externalIdField??"Id").toLowerCase(),R=a=>{let i=a.toLowerCase();return i!==s&&i!=="id"};for(let a of r.transformRules){let i=a.field?.trim();if(!i)throw new Error(l(c([r])));for(let f of h(o,i))R(f)&&(o[f]=p(o[f],a.type,a.config))}return o}};function h(e,n){let r=n.toLowerCase();return Object.keys(e).filter(t=>t.toLowerCase()===r)}function u(e){return(n,r)=>typeof n=="string"?e(n,r):n}function w(e){if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string"||e.trim()==="")return;let n=Number(e);return Number.isNaN(n)?void 0:n}var b={uppercase:u(e=>e.toUpperCase()),lowercase:u(e=>e.toLowerCase()),trim:u(e=>e.trim()),truncate:u((e,n)=>e.slice(0,n.length??e.length)),prefix:u((e,n)=>`${n.prefix??""}${e}`),suffix:u((e,n)=>`${e}${n.suffix??""}`),replace:u((e,n)=>n.search?e.split(n.search).join(n.replace??""):e),regex_replace:u((e,n)=>n.regex?e.replace(y(n.regex),n.replace??""):e),map_value:(e,n)=>{let r=String(e??""),t=n.valueMap??{};return r in t?t[r]:e},default_value:(e,n)=>e==null||e===""?n.defaultValue??"":e,format_date:u((e,n)=>T(e,n.dateFormat??"YYYY-MM-DD")),format_number:(e,n)=>{let r=w(e);if(r===void 0)return e;let t=n.numberFormat??"0";return k(r,t)},custom_formula:(e,n)=>{let r=n.formula??"";return x(e,r)}};function y(e){try{return new RegExp(e,"g")}catch(n){throw new Error(`The pattern "${e}" of a Regex replace rule is no regular expression: `+(n instanceof Error?n.message:String(n)))}}function p(e,n,r){let t=b[n];return t(e,r)}function T(e,n){let r=new Date(e);if(isNaN(r.getTime()))return e;let t=r.getUTCFullYear().toString(),o=(r.getUTCMonth()+1).toString().padStart(2,"0"),s=r.getUTCDate().toString().padStart(2,"0");return n.replace("YYYY",t).replace("MM",o).replace("DD",s)}function k(e,n){let r=n.indexOf(".");if(r===-1)return Math.round(e).toString();let t=n.length-r-1;return e.toFixed(t)}function x(e,n){if(n.includes("VALUE")){let r=w(e);if(r!==void 0){let t=n.replace(/VALUE/g,r.toString());return N(t)??e}}return e}function N(e){let n=e.replace(/\s/g,""),r=/^(-?\d+(?:\.\d+)?)([-+*/])(-?\d+(?:\.\d+)?)$/.exec(n);if(!r)return;let t=Number(r[1]),o=r[2],s=Number(r[3]);switch(o){case"+":return t+s;case"-":return t-s;case"*":return t*s;case"/":return s===0?void 0:t/s;default:return}}export{g as a};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a,b,c,d,e,f,g}from"./chunk-D6JT4PAB.mjs";import"./chunk-N2HYG3BL.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-ISOSTAJR.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{c as acquireEnvLock,g as checkpointLockRefusal,a as defaultEnvLocksDir,b as envLockFileOf,d as envLockHolder,f as envLockLine,e as envLockRefusal};
7
+ import{a,b,c,d,e,f,g}from"./chunk-WAPSSYMT.mjs";import"./chunk-KGU4SVIT.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-S42RBRH2.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{c as acquireEnvLock,g as checkpointLockRefusal,a as defaultEnvLocksDir,b as envLockFileOf,d as envLockHolder,f as envLockLine,e as envLockRefusal};
@@ -0,0 +1,7 @@
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{a as h}from"./chunk-IUM4NFKI.mjs";import{h as R,i as u,j as S,v as m}from"./chunk-PMN4PAC3.mjs";var y=20,w="seed-runs",l="sandforge-seed",A=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function U(d,e){let n=d.finishedAt??new Date().toISOString();return{runId:d.runId,configId:l,configName:l,sourceOrgId:d.targetOrgId,targetOrgId:d.targetOrgId,startedAt:d.startedAt??n,end:{at:n,status:d.status},lastWrittenAt:n,created:d.objectResults.filter(i=>i.createdIds.length>0).map(i=>({objectApiName:i.objectApiName,ids:[...i.createdIds]})),...d.runUserId!==void 0&&A.test(d.runUserId)?{runUserId:d.runUserId}:{},...e?{removal:e}:{}}}function E(d,e){let n=h(d);return new p(R(d,w,i=>{n.note(i),e?.(i)}),y,n)}var p=class{constructor(e,n=y,i){this.runs=e;this.max=n;this.droppedRuns=i}runs;max;droppedRuns;recorder(e){let n=this.runs.recorder({runId:e.runId,configId:l,configName:l,sourceOrgId:e.sourceOrgId??e.targetOrgId,targetOrgId:e.targetOrgId,...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.origin!==void 0?{origin:e.origin}:{},...e.pipeline!==void 0?{pipeline:{name:e.pipeline.name.slice(0,S)}}:{},...e.targetOrganizationId!==void 0?{targetOrganizationId:e.targetOrganizationId}:{},...e.targetAlias!==void 0?{targetAlias:e.targetAlias}:{},...e.runUserId!==void 0&&A.test(e.runUserId)?{runUserId:e.runUserId}:{}}),i=new Set,g=t=>{let s=t.filter(r=>!i.has(r.slice(0,15)));for(let r of s)i.add(r.slice(0,15));return s},o=(t,s)=>{for(let r=0;r<t.length;r+=u)s(t.slice(r,r+u))},f=(t,s,r)=>o(g(s),a=>n.note(t,a,r)),c=new Map,I=!1;return{runId:e.runId,note:(t,s)=>f(t,s),sending:(t,s,r)=>{r?.job!==void 0?c.set(t,r.job):c.delete(t),n.sending?.(t,s,r)},answered:(t,s)=>{c.delete(t);let r=g(s);n.answered?.(t,r.slice(0,u)),o(r.slice(u),a=>n.note(t,a))},wroteAgain:(t,s)=>o(s.filter(r=>i.has(r.slice(0,15))),r=>n.note(t,r)),checkpoint:t=>n.checkpoint?.(t),runUser:t=>{I||n.runUser?.(t)},end:async t=>{let s=t.finishedAt??new Date().toISOString();for(let{objectApiName:a,createdIds:v}of t.objectResults)f(a,v,s);if(i.size===0&&c.size===0){I=!0,await n.flush(),await this.runs.forget(e.runId);return}await n.end({status:t.status,...t.cancelled?{cancelled:!0}:{},at:s});let r=await n.flush();if(r!==void 0)throw new Error(r);await this.keepTheLatest()}}}record(e){let n=e.startedAt??e.finishedAt;return this.recorder({runId:e.runId,targetOrgId:e.targetOrgId,...n!==void 0?{startedAt:n}:{},...e.runUserId!==void 0?{runUserId:e.runUserId}:{}}).end(e)}async keepTheLatest(){let e=(await this.runs.list()).filter(m),n=e.length-this.max;for(let i of[...e].reverse()){if(n<=0)return;await this.runs.forget(i.runId),n--}}pathOf(e){return this.runs.pathOf(e)}get storagePath(){return this.runs.storagePath}get(e){return this.runs.get(e)}async dropped(e){return this.droppedRuns?.find(e)}list(){return this.runs.list()}answerInFlight(e,n,i,g,o){return this.runs.answerInFlight(e,n,i,g,o)}async updateRemoval(e,n){await this.runs.get(e)&&await this.runs.updateRemoval(e,n)}};export{y as a,w as b,U as c,E as d,p as e};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a,b,c,d}from"./chunk-AHUGG3WU.mjs";import"./chunk-MJD6CPZZ.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as ARTICLE_VERSION_OBJECT,b as articleBodyFields,c as articleBodyOptions,d as seedKnowledge};
7
+ import{a,b,c,d}from"./chunk-FITPY3L4.mjs";import"./chunk-JAEDM4SI.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as ARTICLE_VERSION_OBJECT,b as articleBodyFields,c as articleBodyOptions,d as seedKnowledge};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,k as i,l as j,m as k,n as l,o as m,p as n,q as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"./chunk-BT43WSOS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{g as IDS_PER_LINE,m as OverwritesRead,h as PIPELINE_NAME_KEPT,e as SCENARIO_COMPANION_SUFFIX,d as SYNC_FILE_OBJECTS,a as SYNC_RUNS_DIR,c as SYNC_RUNS_HARD_MAX_BYTES,b as SYNC_RUNS_MAX_BYTES,x as SyncRunCreations,i as backupIdSchema,u as configTargetOf,o as createdCount,r as deletedCount,v as earlierRunsOf,f as nodeSyncRunCreations,p as overwrittenCount,j as readRemovalState,l as readRunFile,t as settled,n as syncRemovalPlan,q as syncRestorePlan,k as syncRunFileId,s as syncUndeletePlan,w as writtenAgainBy};
7
+ import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,k as i,l as j,m as k,n as l,o as m,p as n,q as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"./chunk-PMN4PAC3.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{g as IDS_PER_LINE,m as OverwritesRead,h as PIPELINE_NAME_KEPT,e as SCENARIO_COMPANION_SUFFIX,d as SYNC_FILE_OBJECTS,a as SYNC_RUNS_DIR,c as SYNC_RUNS_HARD_MAX_BYTES,b as SYNC_RUNS_MAX_BYTES,x as SyncRunCreations,i as backupIdSchema,u as configTargetOf,o as createdCount,r as deletedCount,v as earlierRunsOf,f as nodeSyncRunCreations,p as overwrittenCount,j as readRemovalState,l as readRunFile,t as settled,n as syncRemovalPlan,q as syncRestorePlan,k as syncRunFileId,s as syncUndeletePlan,w as writtenAgainBy};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{b as S,d as z}from"./chunk-MJD6CPZZ.mjs";import{h as I}from"./chunk-TZE3Y7IQ.mjs";import{b as h}from"./chunk-CA5NAXSU.mjs";import{vc as R}from"./chunk-6QSHWIZI.mjs";import{b as f,e as b,f as y,i as A,k,l as m,o as K}from"./chunk-WZQEK4WT.mjs";var w="Knowledge__kav",j="CaseArticle",T="Case",P="Summary",B=255,D=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,L=m({name:f(),type:f(),length:b().optional(),extraTypeInfo:f().nullish(),htmlFormatted:y().optional(),createable:y().optional()}).loose(),F=m({fields:k(A())}).loose();function M(e){if(!(e.type!=="textarea"||e.createable!==!0))return e.name===P?"summary":e.extraTypeInfo==="richtextarea"||e.htmlFormatted===!0?"richText":(e.length??0)>B?"longText":void 0}var O={richText:0,longText:1,summary:2};function G(e){let r=F.safeParse(e);if(!r.success)return[];let o=[];for(let t of r.data.fields){let n=L.safeParse(t);if(!n.success)continue;let d=M(n.data);d===void 0||typeof n.data.length!="number"||o.push({name:n.data.name,length:n.data.length,kind:d})}return o.sort((t,n)=>O[t.kind]-O[n.kind]||n.length-t.length||t.name.localeCompare(n.name))}function U(e){return{articleBodyField:e.name,articleBodyLength:e.length,...e.kind==="richText"?{articleBodyHtml:!0}:{}}}var x=m({success:y(),errors:k(K([m({statusCode:f().optional(),message:f().optional()}).loose(),f()])).optional()}).loose();function $(e){let r=x.safeParse(e),o=r.success?r.data.errors?.[0]:void 0;return o===void 0?"The org gave no reason.":typeof o=="string"?o:[o.statusCode,o.message].filter(Boolean).join(": ")||"The org gave no reason."}function N(e){let r=x.safeParse(e);return r.success&&r.data.success}function C(e){return e.slice(0,15)}function X(e){return async({ids:r,results:o})=>{let t=r.get(w)??new Map;if(t.size===0)return{skipped:o.find(u=>u.objectApiName===w)?.errors[0]??`The run wrote no ${w} article, so none was published or linked.`};let n={};return e.plan.publish&&(n.publish=await _(e,t)),e.plan.links.length>0&&(n.links=await v(e,t,r.get(T)??new Map)),n}}async function _(e,r){let o={asked:r.size,done:0,notDone:[]};for(let[t,n]of r){if(e.signal?.aborted){o.notDone.push({key:t,reason:"Left a draft: the run was stopped before it was published."});continue}if(!D.test(n)){o.notDone.push({key:t,reason:`Left a draft: ${n} is not a record id.`});continue}try{await e.org.request({method:"PATCH",url:`/knowledgeManagement/articleVersions/masterVersions/${n}`,body:JSON.stringify({publishStatus:"Online"}),headers:{"Content-Type":"application/json"}}),o.done++}catch(d){o.notDone.push({key:t,reason:`Left a draft: ${h(d)}`})}finally{e.journal?.wroteAgain(w,[n])}}return o}async function v(e,r,o){let t={asked:e.plan.links.length,done:0,notDone:[]},n,d;try{n=await q(e.org,[...r.values()])}catch(s){n=new Map,d=h(s)}let u=[],c=(s,a)=>{t.notDone.push({key:s,reason:`Not linked: ${a}.`})};for(let{caseKey:s,articleKey:a}of e.plan.links){let l=o.get(s),g=r.get(a);if(l===void 0){c(s,"its case was not written");continue}if(g===void 0){c(s,`its article ${a} was not written`);continue}let i=n.get(C(g));if(i===void 0){c(s,`the article of ${a} could not be read back`+(d?` (${d})`:": the org no longer holds its version"));continue}u.push({caseKey:s,caseId:l,articleId:i,versionId:g})}for(let s=0;s<u.length;s+=S){let a=u.slice(s,s+S);if(e.signal?.aborted){for(let{caseKey:i}of a)t.notDone.push({key:i,reason:"Not linked: the run was stopped before it."});continue}let l;try{l=await e.org.sobject(j).create(a.map(({caseId:i,articleId:p})=>({CaseId:i,KnowledgeArticleId:p})),{headers:R()})}catch(i){let p=`Not linked: ${h(i)}`;for(let{caseKey:E}of a)t.notDone.push({key:E,reason:p});l=[]}finally{e.journal?.wroteAgain(T,a.map(({caseId:i})=>i)),e.journal?.wroteAgain(w,[...new Set(a.map(({versionId:i})=>i))])}let g=Array.isArray(l)?l:[l];g.length!==0&&a.forEach(({caseKey:i},p)=>{N(g[p])?t.done++:t.notDone.push({key:i,reason:`Not linked: ${$(g[p])}`})})}return t}async function q(e,r){let o=I(w),t=new Map;for(let n of z(r)){let d=await e.query(`SELECT Id, KnowledgeArticleId FROM ${o} WHERE Id IN (${n})`);for(let u of d.records){let c=u;typeof c?.Id=="string"&&typeof c.KnowledgeArticleId=="string"&&t.set(C(c.Id),c.KnowledgeArticleId)}}return t}export{w as a,G as b,U as c,X as d};
7
+ import{b as S,d as z}from"./chunk-JAEDM4SI.mjs";import{h as I}from"./chunk-TZE3Y7IQ.mjs";import{b as h}from"./chunk-CA5NAXSU.mjs";import{vc as R}from"./chunk-PMWAFDUB.mjs";import{b as f,e as b,f as y,i as A,k,l as m,o as K}from"./chunk-WZQEK4WT.mjs";var w="Knowledge__kav",j="CaseArticle",T="Case",P="Summary",B=255,D=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,L=m({name:f(),type:f(),length:b().optional(),extraTypeInfo:f().nullish(),htmlFormatted:y().optional(),createable:y().optional()}).loose(),F=m({fields:k(A())}).loose();function M(e){if(!(e.type!=="textarea"||e.createable!==!0))return e.name===P?"summary":e.extraTypeInfo==="richtextarea"||e.htmlFormatted===!0?"richText":(e.length??0)>B?"longText":void 0}var O={richText:0,longText:1,summary:2};function G(e){let r=F.safeParse(e);if(!r.success)return[];let o=[];for(let t of r.data.fields){let n=L.safeParse(t);if(!n.success)continue;let d=M(n.data);d===void 0||typeof n.data.length!="number"||o.push({name:n.data.name,length:n.data.length,kind:d})}return o.sort((t,n)=>O[t.kind]-O[n.kind]||n.length-t.length||t.name.localeCompare(n.name))}function U(e){return{articleBodyField:e.name,articleBodyLength:e.length,...e.kind==="richText"?{articleBodyHtml:!0}:{}}}var x=m({success:y(),errors:k(K([m({statusCode:f().optional(),message:f().optional()}).loose(),f()])).optional()}).loose();function $(e){let r=x.safeParse(e),o=r.success?r.data.errors?.[0]:void 0;return o===void 0?"The org gave no reason.":typeof o=="string"?o:[o.statusCode,o.message].filter(Boolean).join(": ")||"The org gave no reason."}function N(e){let r=x.safeParse(e);return r.success&&r.data.success}function C(e){return e.slice(0,15)}function X(e){return async({ids:r,results:o})=>{let t=r.get(w)??new Map;if(t.size===0)return{skipped:o.find(u=>u.objectApiName===w)?.errors[0]??`The run wrote no ${w} article, so none was published or linked.`};let n={};return e.plan.publish&&(n.publish=await _(e,t)),e.plan.links.length>0&&(n.links=await v(e,t,r.get(T)??new Map)),n}}async function _(e,r){let o={asked:r.size,done:0,notDone:[]};for(let[t,n]of r){if(e.signal?.aborted){o.notDone.push({key:t,reason:"Left a draft: the run was stopped before it was published."});continue}if(!D.test(n)){o.notDone.push({key:t,reason:`Left a draft: ${n} is not a record id.`});continue}try{await e.org.request({method:"PATCH",url:`/knowledgeManagement/articleVersions/masterVersions/${n}`,body:JSON.stringify({publishStatus:"Online"}),headers:{"Content-Type":"application/json"}}),o.done++}catch(d){o.notDone.push({key:t,reason:`Left a draft: ${h(d)}`})}finally{e.journal?.wroteAgain(w,[n])}}return o}async function v(e,r,o){let t={asked:e.plan.links.length,done:0,notDone:[]},n,d;try{n=await q(e.org,[...r.values()])}catch(s){n=new Map,d=h(s)}let u=[],c=(s,a)=>{t.notDone.push({key:s,reason:`Not linked: ${a}.`})};for(let{caseKey:s,articleKey:a}of e.plan.links){let l=o.get(s),g=r.get(a);if(l===void 0){c(s,"its case was not written");continue}if(g===void 0){c(s,`its article ${a} was not written`);continue}let i=n.get(C(g));if(i===void 0){c(s,`the article of ${a} could not be read back`+(d?` (${d})`:": the org no longer holds its version"));continue}u.push({caseKey:s,caseId:l,articleId:i,versionId:g})}for(let s=0;s<u.length;s+=S){let a=u.slice(s,s+S);if(e.signal?.aborted){for(let{caseKey:i}of a)t.notDone.push({key:i,reason:"Not linked: the run was stopped before it."});continue}let l;try{l=await e.org.sobject(j).create(a.map(({caseId:i,articleId:p})=>({CaseId:i,KnowledgeArticleId:p})),{headers:R()})}catch(i){let p=`Not linked: ${h(i)}`;for(let{caseKey:E}of a)t.notDone.push({key:E,reason:p});l=[]}finally{e.journal?.wroteAgain(T,a.map(({caseId:i})=>i)),e.journal?.wroteAgain(w,[...new Set(a.map(({versionId:i})=>i))])}let g=Array.isArray(l)?l:[l];g.length!==0&&a.forEach(({caseKey:i},p)=>{N(g[p])?t.done++:t.notDone.push({key:i,reason:`Not linked: ${$(g[p])}`})})}return t}async function q(e,r){let o=I(w),t=new Map;for(let n of z(r)){let d=await e.query(`SELECT Id, KnowledgeArticleId FROM ${o} WHERE Id IN (${n})`);for(let u of d.records){let c=u;typeof c?.Id=="string"&&typeof c.KnowledgeArticleId=="string"&&t.set(C(c.Id),c.KnowledgeArticleId)}}return t}export{w as a,G as b,U as c,X as d};
@@ -0,0 +1,7 @@
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{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"./chunk-A3MYSOOC.mjs";import"./chunk-WY5V5PR3.mjs";import"./chunk-LC3NDW4N.mjs";import"./chunk-KB4ZHM4Q.mjs";import"./chunk-23SEDORH.mjs";import"./chunk-W6PN6TJG.mjs";import"./chunk-3Q353S2R.mjs";import"./chunk-VV3B6IC3.mjs";import"./chunk-RHNTHGNU.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-Q7TLC3I2.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-D4GF4FAB.mjs";import"./chunk-CVHNXJH3.mjs";import"./chunk-TQ2TQHTT.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-M6K34KGF.mjs";import"./chunk-TNT27RBG.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-S42RBRH2.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as AUTOMATION_NOT_ACCEPTED,h as automationNamedOf,j as automationRequestsOf,m as deliverabilityOf,d as firedEntryWords,g as firedOf,o as gatedPlanAnswerOf,c as guardUsersOrg,n as planUsersGated,b as reachUsersOrg,f as readUsersAutomation,e as unreadPartWords,i as usersAutomationRefusal,p as usersToRestoreOf,k as writtenByPlan,l as writtenByRemoval};
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{o as ne}from"./chunk-4JKR4PTZ.mjs";import{H as v,d as z,l as oe,m as se,n as ie}from"./chunk-N2HYG3BL.mjs";import{E as J,x as Be}from"./chunk-ZXOUWHYE.mjs";import{c as Pe}from"./chunk-EADHKH3A.mjs";import{h as Oe}from"./chunk-TZE3Y7IQ.mjs";import{b as L}from"./chunk-CA5NAXSU.mjs";import{a as re}from"./chunk-ISOSTAJR.mjs";import{Uc as I}from"./chunk-6QSHWIZI.mjs";import{b as N,e as ee,f as ke,i as te,k as Q,l as D,s as xe}from"./chunk-WZQEK4WT.mjs";var rt="encryptedstring";async function nt(o){try{let[e]=await o("SELECT PermissionsViewEncryptedData FROM UserPermissionAccess");return e?.PermissionsViewEncryptedData===!0}catch{return!1}}function lr(o){let e;return()=>(e??=nt(o),e)}function ur(o,e){let r=new Map;return t=>{let n=r.get(t);return n||(n=(async()=>{let s;try{s=(await e(t)).fields.filter(i=>i.type===rt).map(i=>i.name)}catch{return[]}return s.length>0&&!await o()?s:[]})(),r.set(t,n)),n}}var _=5,ce=25,de=3;function mr(o){return{get version(){return o.version},request:async e=>await o.request(e),query:async(e,r)=>await o.query(e,{scanAll:r?.scanAll===!0}),queryMore:async e=>await o.queryMore(e)}}var j=class extends Error{constructor(){super("The read was stopped."),this.name="OrgReadStopped"}},st="PROCESSING_HALTED",Ce="If-Modified-Since",it=/^\d{1,3}\.\d$/,at=/^\/services\/data\/v\d{1,3}\.\d\/query(?:All)?\/[A-Za-z0-9-]+$/,ct=D({records:Q(xe(N(),te())),done:ke(),totalSize:ee().optional(),nextRecordsUrl:N().optional()}).loose(),dt=D({compositeResponse:Q(D({body:te(),httpStatusCode:ee(),referenceId:N()}).loose())}),lt=Q(D({errorCode:N().optional(),message:N().optional()}).loose());function ut(o,e,r){if(!it.test(o))throw new Error(`Not an API version: ${o}`);if(e.length>_)throw new Error(`A composite runs ${_} queries, not ${e.length}`);if(e.length+r.length>ce)throw new Error(`A composite holds ${ce} subrequests, not ${e.length+r.length}`);let t=`/services/data/v${o}`;return{allOrNone:!1,compositeRequest:[...e.map((n,s)=>({method:"GET",url:n.kind==="first"?`${t}/${n.scanAll?"queryAll":"query"}?q=${encodeURIComponent(n.soql)}`:n.path,referenceId:`q${s}`})),...r.map(({path:n,headers:s},a)=>({method:"GET",url:`${t}/${n}`,referenceId:`d${a}`,...s?{httpHeaders:s}:{}}))]}}function ft(o){let e=dt.safeParse(o);if(!e.success)return;let r=new Map;for(let t of e.data.compositeResponse){if(t.httpStatusCode<400){r.set(t.referenceId,{ok:!0,status:t.httpStatusCode,body:t.body});continue}let n=lt.safeParse(t.body),s=n.success?n.data[0]:void 0;r.set(t.referenceId,{ok:!1,refused:s?[s.errorCode,s.message].filter(Boolean).join(": "):`status ${t.httpStatusCode}`,halted:s?.errorCode===st})}return r}function ae(o){let e=ct.safeParse(o);return e.success?e.data:void 0}function ht(o){return typeof o=="object"&&o!==null&&typeof o.errorCode=="string"}function pt(o){let e=/^https:\/\//i.test(o)?new URL(o).pathname:o;if(!at.test(e))throw new Error(`Not the next page of a query: ${o}`);return e}function wr(o,e){let r=new Set,t=[],n=_,s="composite",a=0,i=!1,c=!1,d=0,p=0,f=!1,m=()=>{for(let u of r)u.state==="pending"&&(u.state="idle",u.settle?.reject(new j));for(let u of t.splice(0))u.settle.reject(new j)},A=()=>{c||(c=!0,queueMicrotask(()=>{c=!1,B()}))},h=(u,w)=>{u.state="idle";let y=u.settle;u.ask=void 0,u.settle=void 0,w instanceof Error?y?.reject(w):y?.resolve(w)},l=async(u,w)=>{let y=ut(o.version,u.map(E=>E.ask),w),g;p++;try{g=await o.request({method:"POST",url:"/composite",body:JSON.stringify(y),headers:{"Content-Type":"application/json"}})}catch(E){if(ht(E)){s="single";for(let R of u)R.state="pending";t.unshift(...w);return}let x=new Error(L(E));for(let R of u)h(R,x);for(let R of w)R.settle.reject(x);return}let k=ft(g);if(!k){s="single";for(let E of u)E.state="pending";t.unshift(...w);return}let P=0;if(u.forEach((E,x)=>{let R=k.get(`q${x}`);if(R&&!R.ok&&R.halted){P++,E.state="pending";return}if(!R){h(E,new Error("The org gave no answer to this query of the composite"));return}if(!R.ok){h(E,new Error(R.refused));return}let tt=ae(R.body);h(E,tt??new Error(`The org answered a query with status ${R.status} and no page`))}),P>0){let E=u.length-P;E===0?s="single":n=Math.min(n,E)}w.forEach((E,x)=>{let R=k.get(`d${x}`);R?R.ok?E.settle.resolve(R.status===304?{notModified:!0}:{body:R.body}):E.settle.reject(new Error(R.refused)):E.settle.reject(new Error("The org gave no answer to this describe of the composite"))})},b=async(u,w)=>{for(let y of u){let g=y.ask;p++;try{let k=g.kind==="first"?await o.query(g.soql,{scanAll:g.scanAll}):await o.queryMore(g.path);h(y,ae(k)??new Error("The org answered a query with no page"))}catch(k){h(y,new Error(L(k)))}}for(let y of w){p++;try{let g=await o.request({method:"GET",url:`/services/data/v${o.version}/${y.path}`,...y.headers?{headers:y.headers}:{}}),k=y.headers?.[Ce]!==void 0&&(g==null||g==="");y.settle.resolve(k?{notModified:!0}:{body:g})}catch(g){y.settle.reject(new Error(L(g)))}}},S=async(u,w,y)=>{try{s==="composite"?await l(u,w):await b(u,w)}catch(g){let k=new Error(L(g));for(let P of u)P.state==="sent"&&h(P,k);for(let P of w)P.settle.reject(k)}finally{a--,y||(i=!1),A(),Se()}},B=()=>{if(e?.aborted){m();return}for(;;){if(i)return;let u=[...r],w=u.filter(x=>x.state==="pending").sort((x,R)=>x.order-R.order);if(!(w.length>0&&!u.some(x=>x.state==="idle"))&&t.length===0)return;let g=w.slice(0,n),k=ce-g.length,P=s==="composite"&&t.length===0&&g.length>0&&g.every(x=>x.oneRow&&x.ask?.kind==="first");if(a>=(P?de:1))return;let E=t.splice(0,k);if(g.length===0&&E.length===0)return;for(let x of g)x.state="sent";a++,P||(i=!0),S(g,E,P)}},O=()=>{f=!1,A()},Y=()=>{f||e===void 0||e.aborted||(e.addEventListener("abort",O,{once:!0}),f=!0)},Se=()=>{!f||a>0||r.size>0||t.length>0||(e?.removeEventListener("abort",O),f=!1)},Re=(u,w)=>r.has(u)?u.state!=="idle"?Promise.reject(new Error("A read asks one page at a time.")):e?.aborted?Promise.reject(new j):new Promise((y,g)=>{u.ask=w,u.settle={resolve:y,reject:g},u.state="pending",u.order=++d,A()}):Promise.reject(new Error("This read is closed."));return{lane(u){let w={state:"idle",order:0,oneRow:u?.oneRow===!0};return r.add(w),Y(),{query:(y,g)=>Re(w,{kind:"first",soql:y,scanAll:g?.scanAll===!0}),queryMore:y=>{let g;try{g=pt(y)}catch(k){return Promise.reject(k instanceof Error?k:new Error(String(k)))}return Re(w,{kind:"next",path:g})},close(){r.delete(w)&&(w.state==="pending"&&h(w,new Error("This read is closed.")),A(),Se())}}},describe(u,w){return e?.aborted?Promise.reject(new j):new Promise((y,g)=>{let k=I(u),P;if(w!==void 0){let E=Date.parse(w);if(!Number.isFinite(E))throw new Error(`Not a date: ${w}`);P={[Ce]:new Date(E).toUTCString()}}Y(),t.push({path:`sobjects/${k}/describe`,...P?{headers:P}:{},settle:{resolve:y,reject:g}}),A()})},async tooling(u){if(e?.aborted)throw new j;p++;let w;try{w=await o.request({method:"GET",url:`/services/data/v${o.version}/tooling/query?q=${encodeURIComponent(u)}`})}catch(g){throw new Error(L(g))}let y=ae(w);if(!y)throw new Error("The org answered a Tooling API query with no page");return y},calls:()=>p}}import{createReadStream as mt}from"node:fs";import{appendFile as wt,stat as gt,writeFile as yt}from"node:fs/promises";import{StringDecoder as bt}from"node:string_decoder";import{promisify as je}from"node:util";import{createGunzip as At,gunzip as Et,gzip as St}from"node:zlib";var Rt=je(St),kt=je(Et),xt=64*1024,Ot=".gz",Pt=6,M=10,Ie=4,ve=Buffer.from("SF","latin1"),ue=8,H=6+ue,fe=M+H,he=fe+2+8;function $(o){return`${o}${Ot}`}async function Bt(o){let e=await Rt(o,{level:Pt});if(e[3]!==0)throw new Error("zlib wrote a gzip header with flags set");let r=Buffer.from(e.subarray(0,M));r[3]=Ie;let t=Buffer.alloc(H);return t.writeUInt16LE(H-2,0),ve.copy(t,2),t.writeUInt16LE(ue,4),t.writeUInt32LE(e.length+H,6),t.writeUInt32LE(o.length,10),Buffer.concat([r,t,e.subarray(M)])}function Me(o){if(o.length<fe||o[0]!==31||o[1]!==139||o[2]!==8||o[3]!==Ie||o.readUInt16LE(M)!==H-2||!o.subarray(M+2,M+4).equals(ve)||o.readUInt16LE(M+4)!==ue)return;let e=o.readUInt32LE(M+6),r=o.readUInt32LE(M+10);return e>=he&&r>0?{total:e,raw:r}:void 0}function Ct(o,e=xt){let r=[],t=0,n=0;for(;n<o.length;){let s=o.indexOf(10,n),a=s<0?o.length:s+1;a-t>e&&n>t&&(r.push(o.subarray(t,n)),t=n),n=a,n-t>=e&&(r.push(o.subarray(t,n)),t=n)}return n>t&&r.push(o.subarray(t,n)),r}async function Ne(o){let e=Ct(Buffer.from(o,"utf8"));return Buffer.concat(await Promise.all(e.map(r=>Bt(r))))}function U(o){return o.endsWith(".ndjson")}function kr(o){let e=new Map,r=(t,n)=>{let s=n(e.get(t)??Promise.resolve());return e.set(t,s),s.then(()=>{e.get(t)===s&&e.delete(t)},()=>{}),s};return{...o,writeFile:(t,n)=>{if(!U(t))return o.writeFile(t,n);let s=$(t);return r(s,a=>a.catch(()=>{}).then(async()=>{let i=n===""?Buffer.alloc(0):await Ne(n);await yt(s,i,{mode:z})}))},appendFile:(t,n)=>{if(!U(t))return o.appendFile(t,n);let s=$(t);return r(s,a=>a.then(async()=>{n!==""&&await wt(s,await Ne(n),{mode:z})}))},exists:t=>o.exists(U(t)?$(t):t),rm:t=>o.rm(U(t)?$(t):t),readLines:t=>U(t)?Nt($(t)):o.readLines(t)}}async function*Nt(o){if((await gt(o)).size===0)return;let e=mt(o),r=At(),t=a=>{r.destroy(a)};e.on("error",t),e.pipe(r);let n=new bt("utf8"),s="";try{for await(let a of r){let i=(s+n.write(a)).split(`
7
+ import{o as ne}from"./chunk-UI3JQVRU.mjs";import{H as v,d as z,l as oe,m as se,n as ie}from"./chunk-KGU4SVIT.mjs";import{E as J,x as Be}from"./chunk-YA6ATMTB.mjs";import{c as Pe}from"./chunk-EADHKH3A.mjs";import{h as Oe}from"./chunk-TZE3Y7IQ.mjs";import{b as L}from"./chunk-CA5NAXSU.mjs";import{a as re}from"./chunk-S42RBRH2.mjs";import{Uc as I}from"./chunk-PMWAFDUB.mjs";import{b as N,e as ee,f as ke,i as te,k as Q,l as D,s as xe}from"./chunk-WZQEK4WT.mjs";var rt="encryptedstring";async function nt(o){try{let[e]=await o("SELECT PermissionsViewEncryptedData FROM UserPermissionAccess");return e?.PermissionsViewEncryptedData===!0}catch{return!1}}function lr(o){let e;return()=>(e??=nt(o),e)}function ur(o,e){let r=new Map;return t=>{let n=r.get(t);return n||(n=(async()=>{let s;try{s=(await e(t)).fields.filter(i=>i.type===rt).map(i=>i.name)}catch{return[]}return s.length>0&&!await o()?s:[]})(),r.set(t,n)),n}}var _=5,ce=25,de=3;function mr(o){return{get version(){return o.version},request:async e=>await o.request(e),query:async(e,r)=>await o.query(e,{scanAll:r?.scanAll===!0}),queryMore:async e=>await o.queryMore(e)}}var j=class extends Error{constructor(){super("The read was stopped."),this.name="OrgReadStopped"}},st="PROCESSING_HALTED",Ce="If-Modified-Since",it=/^\d{1,3}\.\d$/,at=/^\/services\/data\/v\d{1,3}\.\d\/query(?:All)?\/[A-Za-z0-9-]+$/,ct=D({records:Q(xe(N(),te())),done:ke(),totalSize:ee().optional(),nextRecordsUrl:N().optional()}).loose(),dt=D({compositeResponse:Q(D({body:te(),httpStatusCode:ee(),referenceId:N()}).loose())}),lt=Q(D({errorCode:N().optional(),message:N().optional()}).loose());function ut(o,e,r){if(!it.test(o))throw new Error(`Not an API version: ${o}`);if(e.length>_)throw new Error(`A composite runs ${_} queries, not ${e.length}`);if(e.length+r.length>ce)throw new Error(`A composite holds ${ce} subrequests, not ${e.length+r.length}`);let t=`/services/data/v${o}`;return{allOrNone:!1,compositeRequest:[...e.map((n,s)=>({method:"GET",url:n.kind==="first"?`${t}/${n.scanAll?"queryAll":"query"}?q=${encodeURIComponent(n.soql)}`:n.path,referenceId:`q${s}`})),...r.map(({path:n,headers:s},a)=>({method:"GET",url:`${t}/${n}`,referenceId:`d${a}`,...s?{httpHeaders:s}:{}}))]}}function ft(o){let e=dt.safeParse(o);if(!e.success)return;let r=new Map;for(let t of e.data.compositeResponse){if(t.httpStatusCode<400){r.set(t.referenceId,{ok:!0,status:t.httpStatusCode,body:t.body});continue}let n=lt.safeParse(t.body),s=n.success?n.data[0]:void 0;r.set(t.referenceId,{ok:!1,refused:s?[s.errorCode,s.message].filter(Boolean).join(": "):`status ${t.httpStatusCode}`,halted:s?.errorCode===st})}return r}function ae(o){let e=ct.safeParse(o);return e.success?e.data:void 0}function ht(o){return typeof o=="object"&&o!==null&&typeof o.errorCode=="string"}function pt(o){let e=/^https:\/\//i.test(o)?new URL(o).pathname:o;if(!at.test(e))throw new Error(`Not the next page of a query: ${o}`);return e}function wr(o,e){let r=new Set,t=[],n=_,s="composite",a=0,i=!1,c=!1,d=0,p=0,f=!1,m=()=>{for(let u of r)u.state==="pending"&&(u.state="idle",u.settle?.reject(new j));for(let u of t.splice(0))u.settle.reject(new j)},A=()=>{c||(c=!0,queueMicrotask(()=>{c=!1,B()}))},h=(u,w)=>{u.state="idle";let y=u.settle;u.ask=void 0,u.settle=void 0,w instanceof Error?y?.reject(w):y?.resolve(w)},l=async(u,w)=>{let y=ut(o.version,u.map(E=>E.ask),w),g;p++;try{g=await o.request({method:"POST",url:"/composite",body:JSON.stringify(y),headers:{"Content-Type":"application/json"}})}catch(E){if(ht(E)){s="single";for(let R of u)R.state="pending";t.unshift(...w);return}let x=new Error(L(E));for(let R of u)h(R,x);for(let R of w)R.settle.reject(x);return}let k=ft(g);if(!k){s="single";for(let E of u)E.state="pending";t.unshift(...w);return}let P=0;if(u.forEach((E,x)=>{let R=k.get(`q${x}`);if(R&&!R.ok&&R.halted){P++,E.state="pending";return}if(!R){h(E,new Error("The org gave no answer to this query of the composite"));return}if(!R.ok){h(E,new Error(R.refused));return}let tt=ae(R.body);h(E,tt??new Error(`The org answered a query with status ${R.status} and no page`))}),P>0){let E=u.length-P;E===0?s="single":n=Math.min(n,E)}w.forEach((E,x)=>{let R=k.get(`d${x}`);R?R.ok?E.settle.resolve(R.status===304?{notModified:!0}:{body:R.body}):E.settle.reject(new Error(R.refused)):E.settle.reject(new Error("The org gave no answer to this describe of the composite"))})},b=async(u,w)=>{for(let y of u){let g=y.ask;p++;try{let k=g.kind==="first"?await o.query(g.soql,{scanAll:g.scanAll}):await o.queryMore(g.path);h(y,ae(k)??new Error("The org answered a query with no page"))}catch(k){h(y,new Error(L(k)))}}for(let y of w){p++;try{let g=await o.request({method:"GET",url:`/services/data/v${o.version}/${y.path}`,...y.headers?{headers:y.headers}:{}}),k=y.headers?.[Ce]!==void 0&&(g==null||g==="");y.settle.resolve(k?{notModified:!0}:{body:g})}catch(g){y.settle.reject(new Error(L(g)))}}},S=async(u,w,y)=>{try{s==="composite"?await l(u,w):await b(u,w)}catch(g){let k=new Error(L(g));for(let P of u)P.state==="sent"&&h(P,k);for(let P of w)P.settle.reject(k)}finally{a--,y||(i=!1),A(),Se()}},B=()=>{if(e?.aborted){m();return}for(;;){if(i)return;let u=[...r],w=u.filter(x=>x.state==="pending").sort((x,R)=>x.order-R.order);if(!(w.length>0&&!u.some(x=>x.state==="idle"))&&t.length===0)return;let g=w.slice(0,n),k=ce-g.length,P=s==="composite"&&t.length===0&&g.length>0&&g.every(x=>x.oneRow&&x.ask?.kind==="first");if(a>=(P?de:1))return;let E=t.splice(0,k);if(g.length===0&&E.length===0)return;for(let x of g)x.state="sent";a++,P||(i=!0),S(g,E,P)}},O=()=>{f=!1,A()},Y=()=>{f||e===void 0||e.aborted||(e.addEventListener("abort",O,{once:!0}),f=!0)},Se=()=>{!f||a>0||r.size>0||t.length>0||(e?.removeEventListener("abort",O),f=!1)},Re=(u,w)=>r.has(u)?u.state!=="idle"?Promise.reject(new Error("A read asks one page at a time.")):e?.aborted?Promise.reject(new j):new Promise((y,g)=>{u.ask=w,u.settle={resolve:y,reject:g},u.state="pending",u.order=++d,A()}):Promise.reject(new Error("This read is closed."));return{lane(u){let w={state:"idle",order:0,oneRow:u?.oneRow===!0};return r.add(w),Y(),{query:(y,g)=>Re(w,{kind:"first",soql:y,scanAll:g?.scanAll===!0}),queryMore:y=>{let g;try{g=pt(y)}catch(k){return Promise.reject(k instanceof Error?k:new Error(String(k)))}return Re(w,{kind:"next",path:g})},close(){r.delete(w)&&(w.state==="pending"&&h(w,new Error("This read is closed.")),A(),Se())}}},describe(u,w){return e?.aborted?Promise.reject(new j):new Promise((y,g)=>{let k=I(u),P;if(w!==void 0){let E=Date.parse(w);if(!Number.isFinite(E))throw new Error(`Not a date: ${w}`);P={[Ce]:new Date(E).toUTCString()}}Y(),t.push({path:`sobjects/${k}/describe`,...P?{headers:P}:{},settle:{resolve:y,reject:g}}),A()})},async tooling(u){if(e?.aborted)throw new j;p++;let w;try{w=await o.request({method:"GET",url:`/services/data/v${o.version}/tooling/query?q=${encodeURIComponent(u)}`})}catch(g){throw new Error(L(g))}let y=ae(w);if(!y)throw new Error("The org answered a Tooling API query with no page");return y},calls:()=>p}}import{createReadStream as mt}from"node:fs";import{appendFile as wt,stat as gt,writeFile as yt}from"node:fs/promises";import{StringDecoder as bt}from"node:string_decoder";import{promisify as je}from"node:util";import{createGunzip as At,gunzip as Et,gzip as St}from"node:zlib";var Rt=je(St),kt=je(Et),xt=64*1024,Ot=".gz",Pt=6,M=10,Ie=4,ve=Buffer.from("SF","latin1"),ue=8,H=6+ue,fe=M+H,he=fe+2+8;function $(o){return`${o}${Ot}`}async function Bt(o){let e=await Rt(o,{level:Pt});if(e[3]!==0)throw new Error("zlib wrote a gzip header with flags set");let r=Buffer.from(e.subarray(0,M));r[3]=Ie;let t=Buffer.alloc(H);return t.writeUInt16LE(H-2,0),ve.copy(t,2),t.writeUInt16LE(ue,4),t.writeUInt32LE(e.length+H,6),t.writeUInt32LE(o.length,10),Buffer.concat([r,t,e.subarray(M)])}function Me(o){if(o.length<fe||o[0]!==31||o[1]!==139||o[2]!==8||o[3]!==Ie||o.readUInt16LE(M)!==H-2||!o.subarray(M+2,M+4).equals(ve)||o.readUInt16LE(M+4)!==ue)return;let e=o.readUInt32LE(M+6),r=o.readUInt32LE(M+10);return e>=he&&r>0?{total:e,raw:r}:void 0}function Ct(o,e=xt){let r=[],t=0,n=0;for(;n<o.length;){let s=o.indexOf(10,n),a=s<0?o.length:s+1;a-t>e&&n>t&&(r.push(o.subarray(t,n)),t=n),n=a,n-t>=e&&(r.push(o.subarray(t,n)),t=n)}return n>t&&r.push(o.subarray(t,n)),r}async function Ne(o){let e=Ct(Buffer.from(o,"utf8"));return Buffer.concat(await Promise.all(e.map(r=>Bt(r))))}function U(o){return o.endsWith(".ndjson")}function kr(o){let e=new Map,r=(t,n)=>{let s=n(e.get(t)??Promise.resolve());return e.set(t,s),s.then(()=>{e.get(t)===s&&e.delete(t)},()=>{}),s};return{...o,writeFile:(t,n)=>{if(!U(t))return o.writeFile(t,n);let s=$(t);return r(s,a=>a.catch(()=>{}).then(async()=>{let i=n===""?Buffer.alloc(0):await Ne(n);await yt(s,i,{mode:z})}))},appendFile:(t,n)=>{if(!U(t))return o.appendFile(t,n);let s=$(t);return r(s,a=>a.then(async()=>{n!==""&&await wt(s,await Ne(n),{mode:z})}))},exists:t=>o.exists(U(t)?$(t):t),rm:t=>o.rm(U(t)?$(t):t),readLines:t=>U(t)?Nt($(t)):o.readLines(t)}}async function*Nt(o){if((await gt(o)).size===0)return;let e=mt(o),r=At(),t=a=>{r.destroy(a)};e.on("error",t),e.pipe(r);let n=new bt("utf8"),s="";try{for await(let a of r){let i=(s+n.write(a)).split(`
8
8
  `);s=i.pop()??"",yield*i}s+=n.end(),s!==""&&(yield s)}finally{e.off("error",t),e.destroy(),r.destroy()}}async function le(o,e,r){let t=Buffer.alloc(r),n=0;for(;n<r;){let{bytesRead:s}=await o.read(t,n,r-n,e+n);if(s===0)break;n+=s}return n===r?t:t.subarray(0,n)}async function De(o,e,r,t){let n;try{n=await kt(o,{maxOutputLength:e.raw})}catch{throw t(`holds a block that does not inflate at byte ${r}`)}if(n.length!==e.raw)throw t(`holds a block at byte ${r} that inflates to other than its header says`);return n}async function Le(o,e,r,t){let n=await le(o,e,r);if(n.length<r)throw t(`is cut short at byte ${e+n.length}`);let s=Me(n);if(s===void 0)throw t(`holds no block where its index says, at byte ${e}`);if(s.total!==r)throw t(`holds another block than its index says at byte ${e}`);return De(n,s,e,t)}async function*$e(o,e,r){for(let t=0;t<e;){let n=Me(await le(o,t,Math.min(fe,e-t)));if(n===void 0)throw r(`holds no block at byte ${t}`);if(n.total>e-t)throw r(`is cut short: its block at byte ${t} ends past the file's end`);let s=await le(o,t,n.total);yield{at:t,total:n.total,lines:await De(s,n,t,r)},t+=n.total}}function*Te(o){let e=0;for(;e<o.length;){let r=o.indexOf(10,e),t=r<0?o.length:r;yield{at:e,length:t-e},e=t+1}}import{randomBytes as jt}from"node:crypto";import{open as W,readFile as we,rename as It,rm as vt,stat as Mt}from"node:fs/promises";import{dirname as Ge,join as Dt}from"node:path";var Fe=2e3,C=15,pe=C,T=pe+8,ge={format:1,head:Buffer.from("SFCKIDX1","latin1"),lengthAt:T+8,rowBytes:T+8+4},We={format:2,head:Buffer.from("SFCKIDX2","latin1"),memberBytesAt:T+8,lineAt:T+12,lengthAt:T+16,rowBytes:T+20},Ye={1:ge,2:We},G=ge.head.length,ze=1<<20,Lt=500,F=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,$t=/^[A-Za-z0-9]{15}$/,ye=/^[A-Za-z][A-Za-z0-9_]*$/;function Mr(o,e){return G+o*Ye[e].rowBytes}function _e(o){return o.replace(/[^A-Za-z0-9_-]/g,"_")}function Qe(o,e,r){if(!ye.test(r)||r.length>80)throw new v("invalid","Not a Salesforce API name");return Dt(o.dir,"backups",`${_e(e)}__${_e(r)}.ndjson`)}var Z=class{constructor(e,r){this.layout=e;this.rowBytes=e.rowBytes,this.bytes=r??Buffer.alloc(this.rowBytes*1024),this.size=r?r.length/this.rowBytes:0}layout;bytes;rowBytes;size;push(e,r,t){let n=this.size*this.rowBytes;if(n+this.rowBytes>this.bytes.length){let c=Buffer.alloc(Math.max(this.bytes.length*2,this.rowBytes*1024));this.bytes.copy(c,0,0,n),this.bytes=c}let{memberBytesAt:s,lineAt:a,lengthAt:i}=this.layout;return this.bytes.write(e,n,C,"latin1"),this.bytes.writeDoubleLE(r,n+pe),this.bytes.writeDoubleLE(t.offset,n+T),s!==void 0&&this.bytes.writeUInt32LE(t.memberBytes??0,n+s),a!==void 0&&this.bytes.writeUInt32LE(t.line??0,n+a),this.bytes.writeUInt32LE(t.length,n+i),this.size++}keyAt(e){let r=e*this.rowBytes;return this.bytes.toString("latin1",r,r+C)}holds(e,r){let t=e*this.rowBytes;for(let n=0;n<C;n++)if(this.bytes[t+n]!==r.charCodeAt(n))return!1;return!0}stampAt(e){return this.bytes.readDoubleLE(e*this.rowBytes+pe)}offsetAt(e){return this.bytes.readDoubleLE(e*this.rowBytes+T)}memberBytesAt(e){let r=this.layout.memberBytesAt;return r===void 0?0:this.bytes.readUInt32LE(e*this.rowBytes+r)}lineAt(e){let r=this.layout.lineAt;return r===void 0?0:this.bytes.readUInt32LE(e*this.rowBytes+r)}lengthAt(e){return this.bytes.readUInt32LE(e*this.rowBytes+this.layout.lengthAt)}before(e,r){return this.offsetAt(e)-this.offsetAt(r)||this.lineAt(e)-this.lineAt(r)}wellFormed(e){let r=this.stampAt(e),t=this.offsetAt(e);return $t.test(this.keyAt(e))&&Number.isFinite(r)&&Number.isSafeInteger(t)&&t>=0&&this.lengthAt(e)>0&&(this.layout.format===1||this.memberBytesAt(e)>=he)}written(){return this.bytes.subarray(0,this.size*this.rowBytes)}},X=class{constructor(e,r){this.rows=e;let t=1024;for(;t<r*2;)t*=2;this.slots=new Uint32Array(t)}rows;slots;used=0;find(e){let r=this.slots.length-1;for(let t=ne(e)&r;;t=t+1&r){let n=this.slots[t];if(n===0)return-1;if(this.rows.holds(n-1,e))return n-1}}add(e){let r=this.rows.keyAt(e),t=this.find(r);return t>=0?t:((this.used+1)*2>this.slots.length&&this.grow(),this.place(e,r),this.used++,-1)}place(e,r){let t=this.slots.length-1,n=ne(r)&t;for(;this.slots[n]!==0;)n=n+1&t;this.slots[n]=e+1}grow(){let e=this.slots;this.slots=new Uint32Array(e.length*2);for(let r of e)r!==0&&this.place(r-1,this.rows.keyAt(r-1))}};async function V(o,e){try{return await W(o,"r")}catch(r){throw r.code!=="ENOENT"?r:new v("damaged",`The checkpoint\u2019s snapshot of ${e} is not on this machine.`)}}async function*Je(o,e){let r=await V(o,e);try{let t=Buffer.alloc(ze),n=Buffer.alloc(0),s=0,a=0,i=0;for(;;){let{bytesRead:c}=await r.read(t,0,ze,a);if(c===0)break;a+=c;let d=n.length>0?Buffer.concat([n,t.subarray(0,c)]):t.subarray(0,c),p=0;for(let f=d.indexOf(10);f>=0;f=d.indexOf(10,p))i++,f>p&&(yield{number:i,offset:s+p,length:f-p,text:d.toString("utf8",p,f)}),p=f+1;n=Buffer.from(d.subarray(p)),s+=p}n.length>0&&(yield{number:i+1,offset:s,length:n.length,text:n.toString("utf8")})}finally{await r.close()}}async function*Tt(o,e,r){let t=await V(o,e);try{let n=0;for await(let s of $e(t,(await t.stat()).size,r))for(let a of Te(s.lines))n++,a.length!==0&&(yield{number:n,offset:s.at,memberBytes:s.total,line:a.at,length:a.length,text:s.lines.toString("utf8",a.at,a.at+a.length)})}finally{await t.close()}}async function Ft(o){try{return await Mt(o),!0}catch(e){if(e.code==="ENOENT")return!1;throw e}}function Ke(o){let e=J(o);return e===null?Number.NaN:Date.parse(e)}function K(o){let e;try{e=JSON.parse(o)}catch{return}return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}async function zt(o,e){let r=`${o}.${process.pid}-${jt(4).toString("hex")}.tmp`,t=await W(r,"wx",z);try{try{await t.writeFile(e),await t.sync()}finally{await t.close()}await It(r,o)}catch(n){throw await vt(r,{force:!0}),n}}async function Dr(o,e,r){let t=Qe(o,e,r),n=$(t),s=await Ft(n)?2:1,a=oe(o,r),i=new Z(Ye[s]),c=new X(i,0),d=(m,A)=>new v("damaged",`The snapshot of ${r} holds ${A} at line ${m} of its file: it cannot be indexed.`),p=s===2?Tt(n,r,m=>new v("damaged",`The snapshot of ${r} ${m}: it cannot be indexed.`)):Je(t,r);for await(let m of p){let A=K(m.text);if(!A)throw d(m.number,"no record");let h=A.Id;if(typeof h!="string"||!F.test(h))throw d(m.number,"a record without its Id");let l=Ke(A.SystemModstamp);if(!Number.isFinite(l))throw d(m.number,`record ${h} without its SystemModstamp`);let b=i.push(h.slice(0,C),l,m);if(c.add(b)>=0)throw d(m.number,`record ${h} a second time`)}let f=Buffer.concat([i.layout.head,i.written()]);return await zt(a,f),{rows:i.size,bytes:f.length}}var _t=D({objectApiName:N().regex(ye).max(80),from:N().regex(F),to:N().regex(F)});async function Ze(o){let e;try{e=await W(o,"r"),await e.sync()}catch{}finally{await e?.close().catch(()=>{})}}var me=class o{constructor(e,r){this.current=e;this.original=r}current;original;static none=new o(new Map,new Map);static of(e){let r=new Map;for(let{from:n,to:s}of e)r.set(n.slice(0,C),s);let t=new Map;for(let[n,s]of r)t.set(s.slice(0,C),n);return new o(r,t)}static async read(e){let r;try{r=await we(se(e),"utf8")}catch(s){if(s.code==="ENOENT")return o.none;throw s}let t=r.split(`
9
9
  `).slice(0,-1),n=[];for(let[s,a]of t.entries()){if(a==="")continue;let i;try{i=JSON.parse(a)}catch{i=void 0}let c=_t.safeParse(i);if(!c.success)throw new v("damaged",`The checkpoint\u2019s list of the records a rewind made again is damaged at line ${s+1}.`);n.push(c.data)}return o.of(n)}static async add(e,r){if(r.length===0)return;let t=se(e),n=r.map(({objectApiName:i,from:c,to:d})=>`${JSON.stringify({objectApiName:i,from:c,to:d})}
10
10
  `).join(""),s=await W(t,"a",z),a=!1;try{a=(await s.stat()).size===0,await s.appendFile(n,"utf8"),await s.sync()}finally{await s.close()}a&&await Ze(Ge(t))}get empty(){return this.current.size===0}currentOf(e){return this.current.get(e)}originalOf(e){return this.original.get(e)}retired(e){return typeof e=="string"&&F.test(e)&&this.current.has(e.slice(0,C))}remapped(e){return typeof e!="string"||!F.test(e)?e:this.current.get(e.slice(0,C))??e}rowAsNow(e){if(this.empty)return e;let r={...e};for(let[t,n]of Object.entries(e)){if(t==="attributes")continue;let s=this.remapped(n);s!==n&&(r[t]=s)}return r}},qt=D({objectApiName:N().regex(ye).max(80),id:N().regex(F)}),qe=class o{constructor(e){this.held=e}held;static none=new o(new Set);static async read(e){let r;try{r=await we(ie(e),"utf8")}catch(n){if(n.code==="ENOENT")return o.none;throw n}let t=new Set;for(let n of r.split(`
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a,b,c,d}from"./chunk-XCJUNX63.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{b as PARENT_IDS_PER_QUERY,a as readExistingParentIds,c as readPresentParentIds,d as recordParentsRefusals};
7
+ import{a,b,c,d}from"./chunk-JKJ74BX5.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{b as PARENT_IDS_PER_QUERY,a as readExistingParentIds,c as readPresentParentIds,d as recordParentsRefusals};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a as M,b as T,d as $,e as N}from"./chunk-4GCYGQXD.mjs";import{g as L,i as _,j}from"./chunk-Z3MGN42K.mjs";import{h as I}from"./chunk-TZE3Y7IQ.mjs";import{b as p}from"./chunk-CA5NAXSU.mjs";import{B as D,Zc as P,_c as C}from"./chunk-6QSHWIZI.mjs";import{e as A,l as E}from"./chunk-WZQEK4WT.mjs";var g="No record was read or deleted.",V="Nothing was deleted.";function m(e,t){return{allowed:!1,refusal:{code:"PRODUCTION",message:`${e} is a production org, or cannot be told from one: ${t}. Emptying is for sandboxes, scratch orgs and Developer Edition orgs: SandForge never empties objects of a production org, and nothing lifts this. ${g}`}}}async function ce(e,t){let{orgName:n,registered:a}=t;if(a===void 0)return m(n,"SandForge has no record of what kind of org it is");if(!C(a))return m(n,"SandForge has it registered as a production org");let o;try{o=await M(e)}catch(s){let d=$(s);return d!==void 0?{allowed:!1,refusal:{code:"ORG_UNTYPED",message:`${N(n,s,d)} SandForge empties no org it cannot tell from a production one. ${g}`}}:m(n,`it did not say what org it is (${p(s)})`)}if(T(o))return m(n,o.edition?`its Organization record says IsSandbox false, edition ${o.edition}`:"its Organization record says IsSandbox false, and no edition");let r=P(a);return r==="production"?m(n,"SandForge has it registered as a production org"):r==="staging"&&t.mode==="org"?{allowed:!1,refusal:{code:"STAGING_ORG",message:`${n} is a sandbox marked Staging: it holds real data, and SandForge never empties the whole of it. Pick the objects to empty instead, which Production Guard asks about, or unmark it on the Organizations page if it holds nobody's work. ${g}`}}:{allowed:!0,org:o,tier:r}}var B=["PermissionsViewAllData","PermissionsModifyAllData","PermissionsBulkApiHardDelete"];async function le(e){let t=async o=>(await e.query(`SELECT ${o.join(", ")} FROM UserPermissionAccess`)).records[0]??{},n,a;try{n=await t(B)}catch(o){try{n=await t(B.slice(0,2)),a=`whether the user has Bulk API Hard Delete could not be read: ${p(o)}`}catch(r){return{viewAllData:!1,modifyAllData:!1,hardDelete:!1,unread:p(r)}}}return{viewAllData:n.PermissionsViewAllData===!0,modifyAllData:n.PermissionsModifyAllData===!0,hardDelete:n.PermissionsBulkApiHardDelete===!0,...a!==void 0?{unread:a}:{}}}function pe(e){return{code:"HARD_DELETE_NOT_PERMITTED",message:"Deleting for good needs Bulk API Hard Delete, and the user SandForge deletes as "+(e.unread!==void 0?`could not be read to have it (${e.unread}). `:"doesn't have it: Salesforce refuses the job as it is opened. ")+"Give the user a permission set with Bulk API Hard Delete, or empty to the recycle bin, which Undo brings back. Nothing was deleted."}}var ue=60*6e4,v=2e3,G=/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/;async function fe(e,t,n,a){let o=n.filter(c=>G.test(c)).map(c=>c.slice(0,15)),r=o.length>0?` AND LastModifiedById NOT IN (${o.map(c=>`'${c}'`).join(", ")})`:"",s=new Map,d=[],i=!1;for(let c of t){let O=I(c);try{let y=await e.query(`SELECT LastModifiedById, LastModifiedDate FROM ${O} WHERE LastModifiedDate >= ${a}${r} LIMIT ${v}`);y.records.length>=v&&(i=!0);for(let W of y.records){let{LastModifiedById:k,LastModifiedDate:b}=W;if(typeof k!="string"||!G.test(k))continue;let S=k.slice(0,15),w=typeof b=="string"&&!Number.isNaN(Date.parse(b))?b:"",f=s.get(S);if(!f){s.set(S,{userId:k,records:1,lastChangedAt:w});continue}f.records+=1,w!==""&&(f.lastChangedAt===""||Date.parse(w)>Date.parse(f.lastChangedAt))&&(f.lastChangedAt=w)}}catch(y){d.push(`${c}: ${p(y)}`)}}let l=[...s.keys()].sort();return{people:l.map(c=>s.get(c).userId),...i?{atLeast:!0}:{},who:l.map(c=>s.get(c)),unread:d}}var q=200;async function me(e,t){let n=t.who.map(r=>r.userId).slice(0,q);if(n.length===0)return t;let a;try{a=(await e.query(`SELECT Id, Name FROM User WHERE Id IN (${n.map(r=>`'${r}'`).join(", ")})`)).records}catch{return t}let o=new Map;for(let r of a){let{Id:s,Name:d}=r;typeof s=="string"&&typeof d=="string"&&d.trim()!==""&&o.set(s.slice(0,15),d.trim())}return{...t,who:t.who.map(r=>{let s=o.get(r.userId.slice(0,15));return s!==void 0?{...r,name:s}:r})}}function K(e){let t;for(let n of e)n.lastChangedAt!==""&&(t===void 0||Date.parse(n.lastChangedAt)>Date.parse(t))&&(t=n.lastChangedAt);return t}function ge(e,t,n={}){if(n.accepted===!0)return;let a=new Set((n.accepted??[]).map(c=>c.slice(0,15))),o=t.people.filter(c=>!a.has(c.slice(0,15)));if(o.length===0)return;let r=o.length,s=`${t.atLeast?"At least ":""}${r} ${r===1?"person":"people"}`,d=K(t.who.filter(c=>o.includes(c.userId))),i=a.size>0?" the simulation did not name":"",l=n.voice==="page"?"or tick the box that lets their work go, to empty all the same":"or add --accept-people-active to empty all the same";return{code:"PEOPLE_ACTIVE",message:`${s}${i} other than the user SandForge deletes as changed records of these objects in ${e} in the last hour${d!==void 0?`, the last at ${d}`:""}: emptying them would take their work. Empty once they have stopped, ${l}. `+V}}var h=1024,z="COPY_SANDBOX",J=E({DataStorageMB:E({Max:A()}).loose()}).loose();async function Re(e){if(e.orgType!=="Sandbox")return;let t="Empty it whole from DataOps Emptying in the panel, which knows whether it is marked Staging, or pick the objects to empty with --objects, which Production Guard asks about. "+g,n;try{n=J.parse(await e.limits()).DataStorageMB.Max}catch(a){return{code:z,message:`${e.target} is a sandbox whose data storage could not be read (${p(a)}): this command cannot tell a Partial Copy or Full sandbox, which may hold real data, from a developer's. ${t}`}}if(!(n<=h))return{code:z,message:`${e.target} is a Partial Copy or Full sandbox, by its data storage (${n.toLocaleString("en-US")} MB, past the ${h.toLocaleString("en-US")} MB of a Developer Pro): it may hold real data, and this command cannot see whether it is marked Staging in the extension, where such a sandbox is never emptied whole. ${t}`}}var X="Nothing was read or written.",Z=new Set([L,_,j,"Document"].map(e=>e.toLowerCase()));function Q(e){return Z.has(e.toLowerCase())}function ee(e,t){let n=new Map(e.objects.map(i=>[i.objectApiName.toLowerCase(),i])),a=new Set(t.objects.map(i=>i.toLowerCase())),o=new Set(t.excluded.map(i=>i.toLowerCase())),r=[...t.objects,...t.excluded].filter(i=>!n.has(i.toLowerCase())),s=[],d=[];for(let i of e.objects){let l=i.objectApiName.toLowerCase(),c=O=>{d.push({objectApiName:i.objectApiName,records:i.records,reason:O})};Q(i.objectApiName)?c("fileContentNotKept"):a.size>0&&!a.has(l)||o.has(l)||i.customSetting!==void 0&&!t.customSettings?c("excluded"):s.push(i)}return{replayed:s,leftOut:d,unknown:[...new Set(r)],records:s.reduce((i,l)=>i+l.records,0)}}function U(e){let t=e.dataStorageMaxMB!==void 0?{dataStorageMaxMB:e.dataStorageMaxMB}:{};return e.staging===!0?{kind:"real",why:"staging",...t}:e.tier==="scratch"?{kind:"free",why:"scratch",...t}:e.tier==="developer"?{kind:"free",why:"developer",...t}:e.dataStorageMaxMB===void 0?{kind:"unknown"}:e.dataStorageMaxMB>h?{kind:"real",why:"storage",dataStorageMaxMB:e.dataStorageMaxMB}:{kind:"free",why:"developerSandbox",dataStorageMaxMB:e.dataStorageMaxMB}}function H(e,t){return e!==void 0&&t!==void 0&&e.slice(0,15)===t.slice(0,15)}var te=/\.my\.salesforce\.com$/;function F(e){if(e!==void 0)try{let t=new URL(e).hostname.toLowerCase();return te.test(t)?t:void 0}catch{return}}function Y(e,t){if(e.tier!=="sandbox")return;if((t.formerOrganizationIds??[]).some(a=>H(a,e.organizationId)))return"formerOrganizationId";if(t.username!==void 0&&t.username.trim().toLowerCase()===e.username.trim().toLowerCase())return"username";let n=F(t.instanceUrl);if(n!==void 0&&n===F(e.instanceUrl))return"myDomain"}var x={mask:"replay it masked (--mask)",noRealData:"declare that it holds no real data (--no-real-data), which the audit trail keeps",fewerObjects:"name the objects to replay (--objects A,B) or leave some out (--exclude-object X)",rewind:"rewind that org to the checkpoint instead"};function u(e,t,n){return{code:e,message:`${t} ${X}`,params:n}}function R(e){return e.toLocaleString("en-US")}function Se(e){let t={...x,...e.words},{checkpoint:n,target:a}=e;if(n===void 0)return u("REPLAY_CHECKPOINT_UNUSABLE",`Checkpoint ${e.checkpointId} does not read: its file is damaged, and what it holds cannot be told.`,{checkpoint:e.checkpointId,why:"damaged"});let o=n.name;if(n.status!=="ready")return u("REPLAY_CHECKPOINT_UNUSABLE",n.status==="taking"?`Checkpoint '${o}' is still being taken, or its take stopped before its end: it holds part of its org at most.`:`The take of checkpoint '${o}' failed: it holds part of its org at most.`,{checkpoint:o,why:n.status});let r=ae(n,a,t);if(r!==void 0)return r;let s=oe(n,e.choices,a,t);if(s!==void 0)return s;let d=ee(n,e.choices);if(d.records===0){let l=d.replayed.length===0?"every object it holds is left out":"the objects replayed hold no record";return u("REPLAY_NOTHING",`Nothing of checkpoint '${o}' is left to replay into ${a.name}: ${l}${ne(d)?", and a checkpoint keeps no file\u2019s content":""}.`,{checkpoint:o,target:a.name})}let i=e.maxRecords??D;if(d.records>i)return u("REPLAY_TOO_MANY",`Checkpoint '${o}' would replay ${R(d.records)} records into ${a.name}, past the ${R(i)} a replay sets up at once: ${t.fewerObjects}.`,{checkpoint:o,target:a.name,records:d.records,max:i})}function ne(e){return e.leftOut.length>0&&e.leftOut.every(t=>t.reason==="fileContentNotKept")}function ae(e,t,n={}){if(!H(t.organizationId,e.org.organizationId))return;let a=n.rewind??x.rewind;return u("REPLAY_SAME_ORG",`${t.name} is the org checkpoint '${e.name}' was taken of: a replay creates copies of its records in another org, beside what that org holds. To bring ${t.name} back to that moment, ${a}.`,{checkpoint:e.name,target:t.name})}function oe(e,t,n,a={}){let o={...x,...a},r=U(e.org);if(r.kind==="free"||t.mask||Y(e.org,n)!==void 0)return;let s=e.name;if(r.kind==="unknown")return t.noRealData===!0?void 0:u("REPLAY_COPY_UNKNOWN",`Checkpoint '${s}' is of a sandbox and does not say which: taken before SandForge 1.81, it keeps no data storage, and a Partial Copy or a Full sandbox holds production\u2019s records. To replay it into ${n.name}, ${o.mask}, or ${o.noRealData}.`,{checkpoint:s,target:n.name});let d=r.why==="staging"?"a sandbox marked Staging, which holds real data":`a Partial Copy or Full sandbox, by its data storage (${R(r.dataStorageMaxMB??0)} MB, past the ${R(h)} MB of a Developer Pro), which may hold real data`;return u("REPLAY_REAL_DATA",`Checkpoint '${s}' is of ${d}: it goes into another org masked only. To replay it into ${n.name}, ${o.mask}.`,{checkpoint:s,target:n.name,why:r.why,...r.dataStorageMaxMB!==void 0?{mb:r.dataStorageMaxMB}:{}})}function Ae(e,t,n){let a=U(e.org),o=Y(e.org,n),r=a.kind==="unknown"&&!t.mask&&t.noRealData===!0;return{replaySource:a.kind==="free"||a.kind==="real"?a.why:"unknown",...a.kind!=="unknown"&&a.dataStorageMaxMB!==void 0?{replaySourceStorageMB:a.dataStorageMaxMB}:{},replayMasked:t.mask,replayContactPoints:t.contactPoints,...r?{replayNoRealDataDeclared:!0}:{},...o!==void 0&&!t.mask&&a.kind!=="free"?{replayIntoSameSandbox:o}:{}}}export{g as a,ce as b,le as c,pe as d,ue as e,fe as f,me as g,ge as h,Re as i,Q as j,ee as k,U as l,Y as m,x as n,Se as o,Ae as p};
7
+ import{a as M,b as T,d as $,e as N}from"./chunk-W6PN6TJG.mjs";import{g as L,i as _,j}from"./chunk-M6K34KGF.mjs";import{h as I}from"./chunk-TZE3Y7IQ.mjs";import{b as p}from"./chunk-CA5NAXSU.mjs";import{B as D,Zc as P,_c as C}from"./chunk-PMWAFDUB.mjs";import{e as A,l as E}from"./chunk-WZQEK4WT.mjs";var g="No record was read or deleted.",V="Nothing was deleted.";function m(e,t){return{allowed:!1,refusal:{code:"PRODUCTION",message:`${e} is a production org, or cannot be told from one: ${t}. Emptying is for sandboxes, scratch orgs and Developer Edition orgs: SandForge never empties objects of a production org, and nothing lifts this. ${g}`}}}async function ce(e,t){let{orgName:n,registered:a}=t;if(a===void 0)return m(n,"SandForge has no record of what kind of org it is");if(!C(a))return m(n,"SandForge has it registered as a production org");let o;try{o=await M(e)}catch(s){let d=$(s);return d!==void 0?{allowed:!1,refusal:{code:"ORG_UNTYPED",message:`${N(n,s,d)} SandForge empties no org it cannot tell from a production one. ${g}`}}:m(n,`it did not say what org it is (${p(s)})`)}if(T(o))return m(n,o.edition?`its Organization record says IsSandbox false, edition ${o.edition}`:"its Organization record says IsSandbox false, and no edition");let r=P(a);return r==="production"?m(n,"SandForge has it registered as a production org"):r==="staging"&&t.mode==="org"?{allowed:!1,refusal:{code:"STAGING_ORG",message:`${n} is a sandbox marked Staging: it holds real data, and SandForge never empties the whole of it. Pick the objects to empty instead, which Production Guard asks about, or unmark it on the Organizations page if it holds nobody's work. ${g}`}}:{allowed:!0,org:o,tier:r}}var B=["PermissionsViewAllData","PermissionsModifyAllData","PermissionsBulkApiHardDelete"];async function le(e){let t=async o=>(await e.query(`SELECT ${o.join(", ")} FROM UserPermissionAccess`)).records[0]??{},n,a;try{n=await t(B)}catch(o){try{n=await t(B.slice(0,2)),a=`whether the user has Bulk API Hard Delete could not be read: ${p(o)}`}catch(r){return{viewAllData:!1,modifyAllData:!1,hardDelete:!1,unread:p(r)}}}return{viewAllData:n.PermissionsViewAllData===!0,modifyAllData:n.PermissionsModifyAllData===!0,hardDelete:n.PermissionsBulkApiHardDelete===!0,...a!==void 0?{unread:a}:{}}}function pe(e){return{code:"HARD_DELETE_NOT_PERMITTED",message:"Deleting for good needs Bulk API Hard Delete, and the user SandForge deletes as "+(e.unread!==void 0?`could not be read to have it (${e.unread}). `:"doesn't have it: Salesforce refuses the job as it is opened. ")+"Give the user a permission set with Bulk API Hard Delete, or empty to the recycle bin, which Undo brings back. Nothing was deleted."}}var ue=60*6e4,v=2e3,G=/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/;async function fe(e,t,n,a){let o=n.filter(c=>G.test(c)).map(c=>c.slice(0,15)),r=o.length>0?` AND LastModifiedById NOT IN (${o.map(c=>`'${c}'`).join(", ")})`:"",s=new Map,d=[],i=!1;for(let c of t){let O=I(c);try{let y=await e.query(`SELECT LastModifiedById, LastModifiedDate FROM ${O} WHERE LastModifiedDate >= ${a}${r} LIMIT ${v}`);y.records.length>=v&&(i=!0);for(let W of y.records){let{LastModifiedById:k,LastModifiedDate:b}=W;if(typeof k!="string"||!G.test(k))continue;let S=k.slice(0,15),w=typeof b=="string"&&!Number.isNaN(Date.parse(b))?b:"",f=s.get(S);if(!f){s.set(S,{userId:k,records:1,lastChangedAt:w});continue}f.records+=1,w!==""&&(f.lastChangedAt===""||Date.parse(w)>Date.parse(f.lastChangedAt))&&(f.lastChangedAt=w)}}catch(y){d.push(`${c}: ${p(y)}`)}}let l=[...s.keys()].sort();return{people:l.map(c=>s.get(c).userId),...i?{atLeast:!0}:{},who:l.map(c=>s.get(c)),unread:d}}var q=200;async function me(e,t){let n=t.who.map(r=>r.userId).slice(0,q);if(n.length===0)return t;let a;try{a=(await e.query(`SELECT Id, Name FROM User WHERE Id IN (${n.map(r=>`'${r}'`).join(", ")})`)).records}catch{return t}let o=new Map;for(let r of a){let{Id:s,Name:d}=r;typeof s=="string"&&typeof d=="string"&&d.trim()!==""&&o.set(s.slice(0,15),d.trim())}return{...t,who:t.who.map(r=>{let s=o.get(r.userId.slice(0,15));return s!==void 0?{...r,name:s}:r})}}function K(e){let t;for(let n of e)n.lastChangedAt!==""&&(t===void 0||Date.parse(n.lastChangedAt)>Date.parse(t))&&(t=n.lastChangedAt);return t}function ge(e,t,n={}){if(n.accepted===!0)return;let a=new Set((n.accepted??[]).map(c=>c.slice(0,15))),o=t.people.filter(c=>!a.has(c.slice(0,15)));if(o.length===0)return;let r=o.length,s=`${t.atLeast?"At least ":""}${r} ${r===1?"person":"people"}`,d=K(t.who.filter(c=>o.includes(c.userId))),i=a.size>0?" the simulation did not name":"",l=n.voice==="page"?"or tick the box that lets their work go, to empty all the same":"or add --accept-people-active to empty all the same";return{code:"PEOPLE_ACTIVE",message:`${s}${i} other than the user SandForge deletes as changed records of these objects in ${e} in the last hour${d!==void 0?`, the last at ${d}`:""}: emptying them would take their work. Empty once they have stopped, ${l}. `+V}}var h=1024,z="COPY_SANDBOX",J=E({DataStorageMB:E({Max:A()}).loose()}).loose();async function Re(e){if(e.orgType!=="Sandbox")return;let t="Empty it whole from DataOps Emptying in the panel, which knows whether it is marked Staging, or pick the objects to empty with --objects, which Production Guard asks about. "+g,n;try{n=J.parse(await e.limits()).DataStorageMB.Max}catch(a){return{code:z,message:`${e.target} is a sandbox whose data storage could not be read (${p(a)}): this command cannot tell a Partial Copy or Full sandbox, which may hold real data, from a developer's. ${t}`}}if(!(n<=h))return{code:z,message:`${e.target} is a Partial Copy or Full sandbox, by its data storage (${n.toLocaleString("en-US")} MB, past the ${h.toLocaleString("en-US")} MB of a Developer Pro): it may hold real data, and this command cannot see whether it is marked Staging in the extension, where such a sandbox is never emptied whole. ${t}`}}var X="Nothing was read or written.",Z=new Set([L,_,j,"Document"].map(e=>e.toLowerCase()));function Q(e){return Z.has(e.toLowerCase())}function ee(e,t){let n=new Map(e.objects.map(i=>[i.objectApiName.toLowerCase(),i])),a=new Set(t.objects.map(i=>i.toLowerCase())),o=new Set(t.excluded.map(i=>i.toLowerCase())),r=[...t.objects,...t.excluded].filter(i=>!n.has(i.toLowerCase())),s=[],d=[];for(let i of e.objects){let l=i.objectApiName.toLowerCase(),c=O=>{d.push({objectApiName:i.objectApiName,records:i.records,reason:O})};Q(i.objectApiName)?c("fileContentNotKept"):a.size>0&&!a.has(l)||o.has(l)||i.customSetting!==void 0&&!t.customSettings?c("excluded"):s.push(i)}return{replayed:s,leftOut:d,unknown:[...new Set(r)],records:s.reduce((i,l)=>i+l.records,0)}}function U(e){let t=e.dataStorageMaxMB!==void 0?{dataStorageMaxMB:e.dataStorageMaxMB}:{};return e.staging===!0?{kind:"real",why:"staging",...t}:e.tier==="scratch"?{kind:"free",why:"scratch",...t}:e.tier==="developer"?{kind:"free",why:"developer",...t}:e.dataStorageMaxMB===void 0?{kind:"unknown"}:e.dataStorageMaxMB>h?{kind:"real",why:"storage",dataStorageMaxMB:e.dataStorageMaxMB}:{kind:"free",why:"developerSandbox",dataStorageMaxMB:e.dataStorageMaxMB}}function H(e,t){return e!==void 0&&t!==void 0&&e.slice(0,15)===t.slice(0,15)}var te=/\.my\.salesforce\.com$/;function F(e){if(e!==void 0)try{let t=new URL(e).hostname.toLowerCase();return te.test(t)?t:void 0}catch{return}}function Y(e,t){if(e.tier!=="sandbox")return;if((t.formerOrganizationIds??[]).some(a=>H(a,e.organizationId)))return"formerOrganizationId";if(t.username!==void 0&&t.username.trim().toLowerCase()===e.username.trim().toLowerCase())return"username";let n=F(t.instanceUrl);if(n!==void 0&&n===F(e.instanceUrl))return"myDomain"}var x={mask:"replay it masked (--mask)",noRealData:"declare that it holds no real data (--no-real-data), which the audit trail keeps",fewerObjects:"name the objects to replay (--objects A,B) or leave some out (--exclude-object X)",rewind:"rewind that org to the checkpoint instead"};function u(e,t,n){return{code:e,message:`${t} ${X}`,params:n}}function R(e){return e.toLocaleString("en-US")}function Se(e){let t={...x,...e.words},{checkpoint:n,target:a}=e;if(n===void 0)return u("REPLAY_CHECKPOINT_UNUSABLE",`Checkpoint ${e.checkpointId} does not read: its file is damaged, and what it holds cannot be told.`,{checkpoint:e.checkpointId,why:"damaged"});let o=n.name;if(n.status!=="ready")return u("REPLAY_CHECKPOINT_UNUSABLE",n.status==="taking"?`Checkpoint '${o}' is still being taken, or its take stopped before its end: it holds part of its org at most.`:`The take of checkpoint '${o}' failed: it holds part of its org at most.`,{checkpoint:o,why:n.status});let r=ae(n,a,t);if(r!==void 0)return r;let s=oe(n,e.choices,a,t);if(s!==void 0)return s;let d=ee(n,e.choices);if(d.records===0){let l=d.replayed.length===0?"every object it holds is left out":"the objects replayed hold no record";return u("REPLAY_NOTHING",`Nothing of checkpoint '${o}' is left to replay into ${a.name}: ${l}${ne(d)?", and a checkpoint keeps no file\u2019s content":""}.`,{checkpoint:o,target:a.name})}let i=e.maxRecords??D;if(d.records>i)return u("REPLAY_TOO_MANY",`Checkpoint '${o}' would replay ${R(d.records)} records into ${a.name}, past the ${R(i)} a replay sets up at once: ${t.fewerObjects}.`,{checkpoint:o,target:a.name,records:d.records,max:i})}function ne(e){return e.leftOut.length>0&&e.leftOut.every(t=>t.reason==="fileContentNotKept")}function ae(e,t,n={}){if(!H(t.organizationId,e.org.organizationId))return;let a=n.rewind??x.rewind;return u("REPLAY_SAME_ORG",`${t.name} is the org checkpoint '${e.name}' was taken of: a replay creates copies of its records in another org, beside what that org holds. To bring ${t.name} back to that moment, ${a}.`,{checkpoint:e.name,target:t.name})}function oe(e,t,n,a={}){let o={...x,...a},r=U(e.org);if(r.kind==="free"||t.mask||Y(e.org,n)!==void 0)return;let s=e.name;if(r.kind==="unknown")return t.noRealData===!0?void 0:u("REPLAY_COPY_UNKNOWN",`Checkpoint '${s}' is of a sandbox and does not say which: taken before SandForge 1.81, it keeps no data storage, and a Partial Copy or a Full sandbox holds production\u2019s records. To replay it into ${n.name}, ${o.mask}, or ${o.noRealData}.`,{checkpoint:s,target:n.name});let d=r.why==="staging"?"a sandbox marked Staging, which holds real data":`a Partial Copy or Full sandbox, by its data storage (${R(r.dataStorageMaxMB??0)} MB, past the ${R(h)} MB of a Developer Pro), which may hold real data`;return u("REPLAY_REAL_DATA",`Checkpoint '${s}' is of ${d}: it goes into another org masked only. To replay it into ${n.name}, ${o.mask}.`,{checkpoint:s,target:n.name,why:r.why,...r.dataStorageMaxMB!==void 0?{mb:r.dataStorageMaxMB}:{}})}function Ae(e,t,n){let a=U(e.org),o=Y(e.org,n),r=a.kind==="unknown"&&!t.mask&&t.noRealData===!0;return{replaySource:a.kind==="free"||a.kind==="real"?a.why:"unknown",...a.kind!=="unknown"&&a.dataStorageMaxMB!==void 0?{replaySourceStorageMB:a.dataStorageMaxMB}:{},replayMasked:t.mask,replayContactPoints:t.contactPoints,...r?{replayNoRealDataDeclared:!0}:{},...o!==void 0&&!t.mask&&a.kind!=="free"?{replayIntoSameSandbox:o}:{}}}export{g as a,ce as b,le as c,pe as d,ue as e,fe as f,me as g,ge as h,Re as i,Q as j,ee as k,U as l,Y as m,x as n,Se as o,Ae as p};
@@ -4,5 +4,5 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{b as te}from"./chunk-BPHTA6KP.mjs";import{c as nt,d as ot}from"./chunk-U2CTKIPE.mjs";import{i as et,k as tt}from"./chunk-NDFFIJL5.mjs";import{a as st,b as it,c as rt,d as at,e as ct,f as dt,h as lt}from"./chunk-I5C4O3VA.mjs";import{d as He,j as Ke}from"./chunk-RVCPQVKM.mjs";import{c as Oe,d as Ce,p as Ge}from"./chunk-FKCIGJOI.mjs";import{a as Te}from"./chunk-C6RKM4BB.mjs";import{h as ze,i as Ve}from"./chunk-X2XZQ434.mjs";import{A as _e,C as Ue,t as Be,u as We,z as q}from"./chunk-XMQ5R6TC.mjs";import{A as qe,B as x,D as ee,G as Ze,b as je,f as Re,h as Ne,i as Q,j as X,k as Fe,n as Le,o as Ie,r as xe,t as Z,u as Je,v as Qe,w as Xe,z as Ye}from"./chunk-EOQON3E5.mjs";import{A as ve,B as I,H as Ee,K as $e,a as De,e as Me,o as Y,z as Pe}from"./chunk-N2HYG3BL.mjs";import{f as H}from"./chunk-4GCYGQXD.mjs";import{E as Se}from"./chunk-ZXOUWHYE.mjs";import{f as be,g as ke,h as L,m as we,n as ye,o as K,t as Ae,u as J}from"./chunk-Z3MGN42K.mjs";import{b as v}from"./chunk-CA5NAXSU.mjs";import{Uc as F,Va as me,Wa as $,Za as ge,ye as he}from"./chunk-6QSHWIZI.mjs";import{b as pe,k as fe,l as V}from"./chunk-WZQEK4WT.mjs";import{readdir as It,rm as gt,stat as ht}from"node:fs/promises";import{existsSync as xt,readFileSync as Bt,writeFileSync as Wt}from"node:fs";import{hostname as _t}from"node:os";import{join as oe}from"node:path";var Gt=5e5,B=1e6,Ut=100,zt="taking",ut=500;function Xn(e){let t=Ne(e),n=[H(e)];return{get version(){return e.version},request:o=>t.request(o),query:(o,s)=>t.query(o,s),queryMore:o=>t.queryMore(o),describeGlobal:async()=>await e.describeGlobal(),toolingObjects:async()=>{try{return(await e.tooling.describeGlobal()).sobjects.map(s=>s.name)}catch{return[]}},serverTime:async()=>(await e.soap.getServerTimestamp()).timestamp,userId:async()=>(await e.soap.getUserInfo()).userId,requestsSent:()=>n.reduce((o,s)=>o+s(),0),countAlso:o=>{n.push(H(o))}}}function Vt(e){return Fe(ze(e))}var D=class extends Error{constructor(){super("The checkpoint was stopped before it was taken: nothing of it was kept."),this.name="CheckpointTakeStopped"}},W="No record was read.",Ht={excludedByUser:"Left out as asked.",notFound:"The org has no object of this name.",chatter:"Chatter posts, comments and feeds are left out: Salesforce brings a post back only with what it was posted on.",history:"History is left out: it is the org's own trace of changes.",sharing:"Sharing is left out: the org keeps it itself.",changeEvent:"Change events are left out.",unsupportedKind:"Left out: neither the recycle bin nor an update reaches this kind of object as it reaches a record.",customSetting:"Custom settings are left out unless you pick them as custom settings: they are configuration, which a rewind sets back.",notCustomSetting:"Picked as a custom setting: the org has no custom setting of this name.",files:"Documents of the Documents tab are left out: they are shared content kept in folders, as setup is.",heldWithFiles:"Held with its file (ContentDocument): Salesforce neither deletes nor brings back a file's version on its own, and reads the links of a file through the records they tie it to.",setup:"Users, permissions and setup are left out, and so are the org's own logs and jobs.",platformCreated:"Left out: Salesforce alone creates its records, such as approvals, Einstein insights, Data.com clean info and invoices, and no permission lets a user create one.",metadata:"Left out: it is metadata, which a checkpoint doesn't hold.",notWritable:"Left out: the user SandForge connects as may not create, edit and delete its records.",notDescribed:"Left out: the org would not describe it.",noSystemModstamp:"Left out: it has no SystemModstamp, so nothing would tell a record changed since.",noRecycleBin:"Left out: the org deletes its records for good, with no recycle bin, so nothing would tell one deleted since, nor bring it back.",unreadable:"Left out: the org refuses to read it whole.",noViewAll:"Without View All Data and Modify All Data, an object is held only with View All and Modify All on it, and the user SandForge connects as has neither on this one: a record they cannot see would read as deleted since.",noModifyAll:"Without View All Data and Modify All Data, an object is held only with View All and Modify All on it, and the user SandForge connects as has View All on this one, not Modify All: a rewind could not put back what others changed.",activities:"Without View All Data and Modify All Data, tasks and events are left out: Salesforce has no View All for activities, and a private one linked to no record stays out of sight.",catalog:"Without View All Data and Modify All Data, products and price books are left out: Salesforce has no View All or Modify All for them.",filesNotProven:"Without View All Data and Modify All Data, files are left out: nothing proves the user sees every file.",settingNotProven:"Without View All Data and Modify All Data, custom settings are left out: no permission on an object proves the user sees and writes every row.",parentNotSeen:"Without View All Data and Modify All Data, an object with no permissions of its own is held only when the user has View All and Modify All on every record it hangs from, which is not proven here."};function bt(e){let t=Ht[e.reason],n=e.detail===void 0?t:`${t.replace(/\.$/,"")} (${e.detail}).`;return{objectApiName:e.objectApiName,code:e.reason,reason:pt(n),...e.detail===void 0?{}:{detail:pt(e.detail)}}}function Kt(e,t,n){return{objectApiName:e,code:"pastTheLimit",records:t,limit:n,reason:t>B?`${e} has ${t} records, more than any checkpoint holds of one object (${B}): left out of the checkpoint, and a rewind to it does not touch ${e}. Data Export, in Setup, or a Bulk API query keeps a copy of it.`:`${e} has ${t} records, past the checkpoint's limit of ${n} for one object: left out of the checkpoint, as part of it would be taken for all of it.`}}function Jt(e,t){let n=t;for(;;){let o=e.filter(s=>s<=Math.min(n,B)).reduce((s,r)=>s+r,0);if(o<=n)return n;n=o}}function pt(e){return e.length<=ut?e:`${e.slice(0,ut-1)}\u2026`}function kt(e,t){return{code:"RUN_WRITING",message:`${t.operation==="take"?`A checkpoint of ${e} is being taken`:t.operation==="rewind"?`A rewind is writing to ${e}`:t.operation==="undo"?`An undo is writing to ${e}`:t.operation==="empty"?`An emptying of its objects is writing to ${e}`:`SandForge is deleting checkpoints of ${e}`} (process ${t.pid} on ${t.host}): take the checkpoint once it has ended. ${W}`}}function wt(e){return typeof e!="object"||e===null?void 0:typeof e.errorCode=="string"?v(e):void 0}function _(e,t){return e instanceof Q||e instanceof Te||e instanceof D||t?.aborted===!0}var Qt=V({sobjects:fe(be)}).loose();function M(e){return e.toLowerCase()===ke.toLowerCase()}function Xt(e,t,n){if(e===void 0)return{why:`the org lists no ${L}`};let o=t.get(e);if(o===void 0)return{why:n.get(e)??"it was not described"};let r=o.fields.find(d=>d.name.toLowerCase()==="linkedentityid")?.referenceTo??[];return r.length===0?{why:"its describe names no record a link ties a file to"}:{linkable:new Set(r.map(d=>d.toLowerCase()))}}async function se(e,t,n){let o=new Map,s=new Map,r=0,d=await Promise.allSettled(n.map(p=>t.describe(p)));for(let[p,i]of d.entries()){let c=n[p],l;if(i.status==="fulfilled"&&"body"in i.value)l=i.value.body;else{if(i.status==="rejected"&&i.reason instanceof Q)throw i.reason;r++;try{l=await e.request({method:"GET",url:`/services/data/v${e.version}/sobjects/${F(c)}/describe`})}catch(h){let a=wt(h);if(a===void 0)throw new Error(`The org did not answer the describe of ${c}: ${v(h)}`);s.set(c,a);continue}}let u=He.safeParse(l);u.success?o.set(c,u.data):s.set(c,"its describe does not read as one")}return{describes:o,errors:s,alone:r}}async function yt(e,t,n){let o=Qt.parse(await e.describeGlobal()),s=await e.toolingObjects?.()??[],r=ye(o.sobjects,{mode:n.mode,...n.objects?{objects:n.objects}:{},...n.excluded?{excluded:n.excluded}:{},...n.customSettings?{customSettings:n.customSettings}:{}},s),d=r.candidates.some(M),p=d?o.sobjects.find(m=>m.name.toLowerCase()===L.toLowerCase())?.name:void 0,i=p===void 0?r.candidates:[...r.candidates,p],{describes:c,errors:l,alone:u}=await se(e,t,i),h,a;if(d){let m=Xt(p,c,l);"linkable"in m?h=m.linkable:a=m.why,p!==void 0&&c.delete(p)}let g=Ae(r,c,l);if(a!==void 0){let m=g.objects.find(({objectApiName:C})=>M(C));m!==void 0&&(g=J(g,new Map([[m.objectApiName,`its links to records, ${L}, could not be described: ${a}`]])))}let w=await je(async m=>(await e.query(m)).records),A=new Map(o.sobjects.map(m=>[m.name,ft(m)])),S=o.sobjects.filter(we),f=new Set(S.map(m=>m.name)),k=[...c.values()],y=[];for(let m of g.objects){let C=c.get(m.objectApiName);C&&y.push({scoped:m,label:A.get(m.objectApiName)??m.objectApiName,describe:C,capture:await Ke(C,k,{viewsEncryptedData:w}),...f.has(m.objectApiName)?{customSetting:K(C)}:{}})}return{described:i.length,describedAlone:u,objects:y,leftOut:g.leftOut,addedToPicked:r.addedToPicked,...h!==void 0&&y.some(({scoped:m})=>M(m.objectApiName))?{linkable:h}:{},settings:S.map(m=>({objectApiName:m.name,label:ft(m)}))}}function ft(e){let t=e.label;return typeof t=="string"&&t!==""?t:e.name}async function Yt(e,t,n,o){let s=await ee(t,n.map(({capture:i})=>({objectApiName:i.objectApiName,readMode:i.readMode})),o),r=new Map,d=new Map,p=0;for(let[i,c]of s.entries()){let{objectApiName:l,readMode:u}=n[i].capture;if("count"in c){r.set(l,c.count);continue}p++;let h=Qe(l,u);try{let a=await e.query(h.soql,{scanAll:h.scanAll});if(typeof a.totalSize!="number")throw new Error("The org gave no count of its records.");r.set(l,a.totalSize)}catch(a){let g=wt(a);if(g===void 0)throw new Error(`The org did not count the records of ${l}: ${v(a)}`);d.set(l,g)}}return{counts:r,refused:d,alone:p}}function At(e,t){return t?.has(e.toLowerCase())===!0&&!M(e)}async function qt(e,t,n,o,s){let r=[];for(let{objectApiName:i,records:c}of t){let l=F(i);r.push({objectApiName:l,soql:`SELECT COUNT() FROM ${l} WHERE IsDeleted = true AND SystemModstamp < ${Z(o)}`,scanAll:!0,counts:"inBin"}),c!==0&&(r.push({objectApiName:l,soql:`SELECT COUNT() FROM ${l} WHERE SystemModstamp >= ${Je(o)}`,scanAll:!0,counts:"stampedSince"}),At(l,n)&&r.push({...et(l),counts:"links"}))}let d=await Ye(e,r,()=>{},s),p=new Map;return d.forEach((i,c)=>{let{objectApiName:l,counts:u}=r[c],h=i.read?i.totalSize:void 0,a=p.get(l)??{};u==="links"?a.links=h??null:h!==void 0&&(a[u]=h),p.set(l,a)}),{asked:r.length,of:p}}function St({scoped:e,capture:t,customSetting:n,access:o},s,r,d){return{objectApiName:e.objectApiName,records:s,inBin:r,readOrder:e.readOrder,readMode:t.readMode,undeletable:t.undeletable,cascadeParents:t.cascadeParents,restrictParents:t.restrictParents,fingerprint:d,fields:t.fields,leftOutFields:t.leftOutFields,...n!==void 0?{customSetting:n}:{},...o!==void 0?{access:o}:{}}}function Ot(e){return{personAccounts:rt(e.map(({describe:t})=>t)),catalog:at(e.map(({scoped:t})=>t.objectApiName))}}function Zt(e){let t=e?.orgType==="Sandbox"||e?.orgType==="Scratch";return Oe(Ce(t)).defaultQueryLimit}async function Ct(e,t,n,o,s,r,d,p=Tt){let i=n.maxTotal??Gt;if(!Number.isInteger(i)||i<1)throw new RangeError(`Not a number of records: ${i}`);let c=Math.min(i,B),{counts:l,refused:u,alone:h}=await Yt(e,t,o.objects,d),a=J({mode:n.mode,objects:o.objects.map(({scoped:b})=>b),leftOut:o.leftOut,packages:[]},u),g=new Map(o.objects.map(b=>[b.scoped.objectApiName,b])),w=a.leftOut.map(bt),A=[];for(let b of a.objects){let O=g.get(b.objectApiName),P=l.get(b.objectApiName);if(!(O===void 0||P===void 0)){if(P>c){w.push(Kt(b.objectApiName,P,c));continue}A.push({...O,scoped:{...b,readOrder:A.length},records:P,otherGroups:Be(b.objectApiName,O.capture.fields,O.capture.readMode),recount:{}})}}let S=A.some(({scoped:b})=>M(b.objectApiName))?o.linkable:void 0,f=await qt(t,A.map(({scoped:b,records:O})=>({objectApiName:b.objectApiName,records:O})),S,r,d);for(let b of A)b.recount=f.of.get(b.scoped.objectApiName)??{};w.sort((b,O)=>b.objectApiName<O.objectApiName?-1:b.objectApiName>O.objectApiName?1:0);let k={};for(let{scoped:b,describe:O}of A)k[b.objectApiName]=De(O.fields);let y=en(p,We({described:o.described,describedAlone:o.describedAlone,counted:o.objects.length,countedAlone:h,recounted:f.asked,objects:A.map(b=>({records:b.records,otherGroups:b.otherGroups,...b.recount,entry:St(b,b.records,0,k[b.scoped.objectApiName].digest)})),pageRows:Zt(n.registered),leftOut:w,printsBytes:(await $e(k)).length,annexCalls:ct(Ot(A))})),m={...y,apiRequestsLeft:s.remaining},C={objects:A,leftOut:w,estimate:m,objectLimit:c,prints:k,...S!==void 0?{linkable:S}:{}};if(y.records>i){let b=[...A.map(O=>O.records),...w.flatMap(O=>O.code==="pastTheLimit"?[O.records??0]:[])];return{...C,refusal:{code:"TOO_MANY_RECORDS",message:`The objects this checkpoint would keep hold ${y.records} records in ${n.orgName}, past its limit of ${i}: pick fewer objects. ${W}`,holdingLimit:Jt(b,y.records)}}}let R=_e("take",y.apiRequests,s,n.orgName);return R===void 0?C:{...C,refusal:R}}function jt(e){return{query:t=>e.query(t),queryMore:t=>e.queryMore(t)}}var Tt={guard:0,scope:0};function en(e,t){if(e.guard+e.scope===0)return t;let n=t.requestsByPhase;return{...t,apiRequests:t.apiRequests+e.guard+e.scope,...n!==void 0?{requestsByPhase:{...n,guard:n.guard+e.guard,scope:n.scope+e.scope}}:{}}}function tn(e){let t=[...e.mode==="picked"?e.objects??[]:[],...Array.isArray(e.customSettings)?e.customSettings:[]];return new Set(t.map(n=>n.toLowerCase()))}function nn(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}async function Rt(e,t,n,o,s,r){if(s.kind==="org")return{scope:{...o,objects:o.objects.map(f=>({...f,access:"org"}))},reads:Tt};let d=o.objects.map(({scoped:f})=>f.objectApiName),p={grants:s.objects,describes:o.objects.map(({describe:f})=>f),customSettings:o.objects.filter(({customSetting:f})=>f!==void 0).map(({scoped:f})=>f.objectApiName)},i=nt(d,p),c=[],l=0;if(i.length>0)try{let f=await se(e,t,i);c=[...f.describes.values()],l=Math.ceil(i.length/Re)+f.alone}catch(f){if(_(f,r))throw f}let u=ot(d,{...p,describes:[...p.describes,...c]}),h=tn(n),a=[],g=[...o.leftOut],w=[];for(let f of o.objects){let k=f.scoped.objectApiName,y=u.get(k);if(y!==void 0&&"access"in y){a.push({...f,access:y.access});continue}let m={objectApiName:k,reason:y?.reason??"noViewAll",...y?.detail!==void 0?{detail:y.detail}:{}};g.push(m),h.has(k.toLowerCase())&&n.unprovenLeftOut!==!0&&w.push(m)}let A=new Set(a.map(({scoped:f})=>f.objectApiName)),S={scope:{...o,objects:a,leftOut:g,addedToPicked:o.addedToPicked.filter(f=>A.has(f))},reads:{guard:s.requests,scope:l}};if(w.length>0){let f=w.length===1;return{...S,refusal:{code:"PERMISSIONS",message:`${n.username} doesn't have View All Data and Modify All Data, and the checkpoint can't hold ${nn(w.map(k=>k.objectApiName))}, asked for by name. ${w.map(k=>`${k.objectApiName}: ${bt(k).reason}`).join(" ")} Leave ${f?"it":"them"} out, or give the user View All Data and Modify All Data. ${W}`}}}return a.length===0&&o.objects.length>0?{...S,refusal:{code:"PERMISSIONS",message:`${n.username} doesn't have View All Data and Modify All Data, nor View All and Modify All on any object this checkpoint would hold: without them, a checkpoint holds only the objects its user sees and puts back whole. Give the user View All and Modify All on the objects to hold, or View All Data and Modify All Data. `+W}}:S}function on(e){return e.objects.map(({scoped:t,label:n,capture:o,records:s,customSetting:r,access:d})=>({objectApiName:t.objectApiName,label:n,...t.namespace!==void 0?{namespace:t.namespace}:{},records:s,undeletable:o.undeletable,leftOutFields:o.leftOutFields,...r!==void 0?{customSetting:r}:{},...d!==void 0?{access:d}:{}}))}function Nt(e){let t=e.customSettings;return t!==void 0&&(t==="all"||t.length>0)}async function sn(e,t,n,o,s){let r=new Map(o.objects.map(u=>[u.scoped.objectApiName,u])),d=n.settings.filter(({objectApiName:u})=>!r.has(u)),p=new Map;if(d.length>0)try{({describes:p}=await se(e,t,d.map(({objectApiName:u})=>u)))}catch(u){if(_(u,s))throw u}let i=d.filter(({objectApiName:u})=>p.has(u)),c=await ee(t,i.map(({objectApiName:u})=>({objectApiName:u,readMode:"query"})),s),l=new Map;return c.forEach((u,h)=>{"count"in u&&l.set(i[h].objectApiName,u.count)}),n.settings.map(({objectApiName:u,label:h})=>{let a=r.get(u);if(a?.customSetting!==void 0)return{objectApiName:u,label:h,kind:a.customSetting,records:a.records};let g=p.get(u),w=l.get(u);return{objectApiName:u,label:h,...g!==void 0?{kind:K(g)}:{},...w!==void 0?{records:w}:{}}})}var rn={records:0,apiRequests:0,apiRequestsLeft:0,seconds:0,bytes:0};async function Yn(e,t){let n={mode:t.mode,objects:[],leftOut:[],estimate:rn},o=await te(jt(e.org),{act:"take",orgName:t.orgName,registered:t.registered,username:t.username,customSettings:Nt(t)},{userId:()=>e.org.userId()});if(!o.allowed)return{...n,refusal:o.refusal};let s=e.store.heldBy(o.org.id),r=s===void 0?await e.runWriting?.(o.org.id):void 0,d=X(e.org,e.signal);try{let p=await q(e.org,t.orgName),i=await Rt(e.org,d,t,await yt(e.org,d,t),o.grants,e.signal),{scope:c}=i,l=await e.org.serverTime(),u=await Ct(e.org,d,t,c,p,l,e.signal,i.reads),h={mode:t.mode,objects:on(u),leftOut:u.leftOut,estimate:u.estimate,files:{held:u.objects.some(({scoped:g})=>M(g.objectApiName)),queryAllFiles:o.queryAllFiles,addedToPicked:c.addedToPicked},customSettings:await sn(e.org,d,c,u,e.signal)},a=s!==void 0?kt(t.orgName,s):r!==void 0?{code:"RUN_WRITING",message:r}:i.refusal??u.refusal;return a===void 0?h:{...h,refusal:a}}catch(p){throw _(p,e.signal)?new D:p}}function an(e){let t=e.requestsSent?()=>e.requestsSent?.()??0:void 0,n={guard:0,scope:0,start:0,counts:0,bin:0,snapshot:0,stability:0},o="guard",s=t?.()??0,r=()=>{if(!t)return;let d=t();n[o]+=d-s,s=d};return{enter(d){r(),o=d},requests(){return t?(r(),{total:Object.values(n).reduce((p,i)=>p+i,0),byPhase:{...n}}):void 0}}}async function cn(e,t){if(t.edition!==void 0)return t.edition;let o=(await e.query("SELECT OrganizationType FROM Organization LIMIT 1")).records[0]?.OrganizationType;if(typeof o!="string"||o==="")throw new Error("The org did not say its edition (Organization.OrganizationType).");return o}var dn="Automated Process";async function ln(e){let n=(await e.query("SELECT Id, Name FROM User WHERE UserType = 'AutomatedProcess'")).records.filter(s=>typeof s.Id=="string"),o=n.find(s=>s.Name===dn);return o!==void 0?o.Id:n.length===1?n[0].Id:void 0}function Dt(e){let t=new Date(Date.parse(e)).toISOString();return`${t.slice(0,10)} ${t.slice(11,16)} UTC`}function mt(e,t){return e.split(he).join(Dt(t))}function ne(e){let t=Se(e);return t===null?Number.NaN:Date.parse(t)}function Mt(e){return typeof e=="string"&&e.length>=15?e.slice(0,15):void 0}async function un(e,t){let n=new Set;for await(let o of x(Y(e,t))){let s=Mt(o.Id);s!==void 0&&n.add(s)}return n}async function pn(e,t,n,o,s,r){let d={changed:0,deleted:0,created:0};if(!o.live&&!o.deleted)return d;let p=await xe.read(e,t,n);if(o.live)for await(let i of x(o.live.file)){let c=ne(i.SystemModstamp);if(!(c<=r))continue;let l=p.stampOf(i.Id);l===void 0?d.created++:l!==c&&d.changed++}if(o.deleted){let i;for await(let c of x(o.deleted.file)){if(!(ne(c.SystemModstamp)<=r))continue;if(p.has(c.Id)){d.deleted++;continue}if(!(ne(c.CreatedDate)<s))continue;i??=await un(e,n);let l=Mt(c.Id);l!==void 0&&!i.has(l)&&d.deleted++}}return d}async function Pt(e){let t=0;for(let n of await It(e,{withFileTypes:!0})){let o=oe(e,n.name);n.isDirectory()?t+=await Pt(o):n.isFile()&&(t+=(await ht(o)).size)}return t}async function fn(e,t){let n=await Pt(e.dir)-(await ht(e.checkpointFile)).size,o=r=>Buffer.byteLength(`${JSON.stringify({...t,bytes:r},null,2)}
7
+ import{b as te}from"./chunk-O677VOGO.mjs";import{c as nt,d as ot}from"./chunk-JE6SCT6R.mjs";import{i as et,k as tt}from"./chunk-PWRJRL5U.mjs";import{a as st,b as it,c as rt,d as at,e as ct,f as dt,h as lt}from"./chunk-24RFOFYT.mjs";import{d as He,j as Ke}from"./chunk-UIOMAX56.mjs";import{c as Oe,d as Ce,p as Ge}from"./chunk-KJWFYBMU.mjs";import{a as Te}from"./chunk-Z4LKKOFY.mjs";import{h as ze,i as Ve}from"./chunk-L53JWJ3S.mjs";import{B as q,C as _e,E as Ue,u as Be,v as We}from"./chunk-VINGECAJ.mjs";import{A as qe,B as x,D as ee,G as Ze,b as je,f as Re,h as Ne,i as Q,j as X,k as Fe,n as Le,o as Ie,r as xe,t as Z,u as Je,v as Qe,w as Xe,z as Ye}from"./chunk-FP7CYB2F.mjs";import{A as ve,B as I,H as Ee,K as $e,a as De,e as Me,o as Y,z as Pe}from"./chunk-KGU4SVIT.mjs";import{f as H}from"./chunk-W6PN6TJG.mjs";import{E as Se}from"./chunk-YA6ATMTB.mjs";import{f as be,g as ke,h as L,m as we,n as ye,o as K,t as Ae,u as J}from"./chunk-M6K34KGF.mjs";import{b as v}from"./chunk-CA5NAXSU.mjs";import{Uc as F,Va as me,Wa as $,Za as ge,ye as he}from"./chunk-PMWAFDUB.mjs";import{b as pe,k as fe,l as V}from"./chunk-WZQEK4WT.mjs";import{readdir as It,rm as gt,stat as ht}from"node:fs/promises";import{existsSync as xt,readFileSync as Bt,writeFileSync as Wt}from"node:fs";import{hostname as _t}from"node:os";import{join as oe}from"node:path";var Gt=5e5,B=1e6,Ut=100,zt="taking",ut=500;function Xn(e){let t=Ne(e),n=[H(e)];return{get version(){return e.version},request:o=>t.request(o),query:(o,s)=>t.query(o,s),queryMore:o=>t.queryMore(o),describeGlobal:async()=>await e.describeGlobal(),toolingObjects:async()=>{try{return(await e.tooling.describeGlobal()).sobjects.map(s=>s.name)}catch{return[]}},serverTime:async()=>(await e.soap.getServerTimestamp()).timestamp,userId:async()=>(await e.soap.getUserInfo()).userId,requestsSent:()=>n.reduce((o,s)=>o+s(),0),countAlso:o=>{n.push(H(o))}}}function Vt(e){return Fe(ze(e))}var D=class extends Error{constructor(){super("The checkpoint was stopped before it was taken: nothing of it was kept."),this.name="CheckpointTakeStopped"}},W="No record was read.",Ht={excludedByUser:"Left out as asked.",notFound:"The org has no object of this name.",chatter:"Chatter posts, comments and feeds are left out: Salesforce brings a post back only with what it was posted on.",history:"History is left out: it is the org's own trace of changes.",sharing:"Sharing is left out: the org keeps it itself.",changeEvent:"Change events are left out.",unsupportedKind:"Left out: neither the recycle bin nor an update reaches this kind of object as it reaches a record.",customSetting:"Custom settings are left out unless you pick them as custom settings: they are configuration, which a rewind sets back.",notCustomSetting:"Picked as a custom setting: the org has no custom setting of this name.",files:"Documents of the Documents tab are left out: they are shared content kept in folders, as setup is.",heldWithFiles:"Held with its file (ContentDocument): Salesforce neither deletes nor brings back a file's version on its own, and reads the links of a file through the records they tie it to.",setup:"Users, permissions and setup are left out, and so are the org's own logs and jobs.",platformCreated:"Left out: Salesforce alone creates its records, such as approvals, Einstein insights, Data.com clean info and invoices, and no permission lets a user create one.",metadata:"Left out: it is metadata, which a checkpoint doesn't hold.",notWritable:"Left out: the user SandForge connects as may not create, edit and delete its records.",notDescribed:"Left out: the org would not describe it.",noSystemModstamp:"Left out: it has no SystemModstamp, so nothing would tell a record changed since.",noRecycleBin:"Left out: the org deletes its records for good, with no recycle bin, so nothing would tell one deleted since, nor bring it back.",unreadable:"Left out: the org refuses to read it whole.",noViewAll:"Without View All Data and Modify All Data, an object is held only with View All and Modify All on it, and the user SandForge connects as has neither on this one: a record they cannot see would read as deleted since.",noModifyAll:"Without View All Data and Modify All Data, an object is held only with View All and Modify All on it, and the user SandForge connects as has View All on this one, not Modify All: a rewind could not put back what others changed.",activities:"Without View All Data and Modify All Data, tasks and events are left out: Salesforce has no View All for activities, and a private one linked to no record stays out of sight.",catalog:"Without View All Data and Modify All Data, products and price books are left out: Salesforce has no View All or Modify All for them.",filesNotProven:"Without View All Data and Modify All Data, files are left out: nothing proves the user sees every file.",settingNotProven:"Without View All Data and Modify All Data, custom settings are left out: no permission on an object proves the user sees and writes every row.",parentNotSeen:"Without View All Data and Modify All Data, an object with no permissions of its own is held only when the user has View All and Modify All on every record it hangs from, which is not proven here."};function bt(e){let t=Ht[e.reason],n=e.detail===void 0?t:`${t.replace(/\.$/,"")} (${e.detail}).`;return{objectApiName:e.objectApiName,code:e.reason,reason:pt(n),...e.detail===void 0?{}:{detail:pt(e.detail)}}}function Kt(e,t,n){return{objectApiName:e,code:"pastTheLimit",records:t,limit:n,reason:t>B?`${e} has ${t} records, more than any checkpoint holds of one object (${B}): left out of the checkpoint, and a rewind to it does not touch ${e}. Data Export, in Setup, or a Bulk API query keeps a copy of it.`:`${e} has ${t} records, past the checkpoint's limit of ${n} for one object: left out of the checkpoint, as part of it would be taken for all of it.`}}function Jt(e,t){let n=t;for(;;){let o=e.filter(s=>s<=Math.min(n,B)).reduce((s,r)=>s+r,0);if(o<=n)return n;n=o}}function pt(e){return e.length<=ut?e:`${e.slice(0,ut-1)}\u2026`}function kt(e,t){return{code:"RUN_WRITING",message:`${t.operation==="take"?`A checkpoint of ${e} is being taken`:t.operation==="rewind"?`A rewind is writing to ${e}`:t.operation==="undo"?`An undo is writing to ${e}`:t.operation==="empty"?`An emptying of its objects is writing to ${e}`:`SandForge is deleting checkpoints of ${e}`} (process ${t.pid} on ${t.host}): take the checkpoint once it has ended. ${W}`}}function wt(e){return typeof e!="object"||e===null?void 0:typeof e.errorCode=="string"?v(e):void 0}function _(e,t){return e instanceof Q||e instanceof Te||e instanceof D||t?.aborted===!0}var Qt=V({sobjects:fe(be)}).loose();function M(e){return e.toLowerCase()===ke.toLowerCase()}function Xt(e,t,n){if(e===void 0)return{why:`the org lists no ${L}`};let o=t.get(e);if(o===void 0)return{why:n.get(e)??"it was not described"};let r=o.fields.find(d=>d.name.toLowerCase()==="linkedentityid")?.referenceTo??[];return r.length===0?{why:"its describe names no record a link ties a file to"}:{linkable:new Set(r.map(d=>d.toLowerCase()))}}async function se(e,t,n){let o=new Map,s=new Map,r=0,d=await Promise.allSettled(n.map(p=>t.describe(p)));for(let[p,i]of d.entries()){let c=n[p],l;if(i.status==="fulfilled"&&"body"in i.value)l=i.value.body;else{if(i.status==="rejected"&&i.reason instanceof Q)throw i.reason;r++;try{l=await e.request({method:"GET",url:`/services/data/v${e.version}/sobjects/${F(c)}/describe`})}catch(h){let a=wt(h);if(a===void 0)throw new Error(`The org did not answer the describe of ${c}: ${v(h)}`);s.set(c,a);continue}}let u=He.safeParse(l);u.success?o.set(c,u.data):s.set(c,"its describe does not read as one")}return{describes:o,errors:s,alone:r}}async function yt(e,t,n){let o=Qt.parse(await e.describeGlobal()),s=await e.toolingObjects?.()??[],r=ye(o.sobjects,{mode:n.mode,...n.objects?{objects:n.objects}:{},...n.excluded?{excluded:n.excluded}:{},...n.customSettings?{customSettings:n.customSettings}:{}},s),d=r.candidates.some(M),p=d?o.sobjects.find(m=>m.name.toLowerCase()===L.toLowerCase())?.name:void 0,i=p===void 0?r.candidates:[...r.candidates,p],{describes:c,errors:l,alone:u}=await se(e,t,i),h,a;if(d){let m=Xt(p,c,l);"linkable"in m?h=m.linkable:a=m.why,p!==void 0&&c.delete(p)}let g=Ae(r,c,l);if(a!==void 0){let m=g.objects.find(({objectApiName:C})=>M(C));m!==void 0&&(g=J(g,new Map([[m.objectApiName,`its links to records, ${L}, could not be described: ${a}`]])))}let w=await je(async m=>(await e.query(m)).records),A=new Map(o.sobjects.map(m=>[m.name,ft(m)])),S=o.sobjects.filter(we),f=new Set(S.map(m=>m.name)),k=[...c.values()],y=[];for(let m of g.objects){let C=c.get(m.objectApiName);C&&y.push({scoped:m,label:A.get(m.objectApiName)??m.objectApiName,describe:C,capture:await Ke(C,k,{viewsEncryptedData:w}),...f.has(m.objectApiName)?{customSetting:K(C)}:{}})}return{described:i.length,describedAlone:u,objects:y,leftOut:g.leftOut,addedToPicked:r.addedToPicked,...h!==void 0&&y.some(({scoped:m})=>M(m.objectApiName))?{linkable:h}:{},settings:S.map(m=>({objectApiName:m.name,label:ft(m)}))}}function ft(e){let t=e.label;return typeof t=="string"&&t!==""?t:e.name}async function Yt(e,t,n,o){let s=await ee(t,n.map(({capture:i})=>({objectApiName:i.objectApiName,readMode:i.readMode})),o),r=new Map,d=new Map,p=0;for(let[i,c]of s.entries()){let{objectApiName:l,readMode:u}=n[i].capture;if("count"in c){r.set(l,c.count);continue}p++;let h=Qe(l,u);try{let a=await e.query(h.soql,{scanAll:h.scanAll});if(typeof a.totalSize!="number")throw new Error("The org gave no count of its records.");r.set(l,a.totalSize)}catch(a){let g=wt(a);if(g===void 0)throw new Error(`The org did not count the records of ${l}: ${v(a)}`);d.set(l,g)}}return{counts:r,refused:d,alone:p}}function At(e,t){return t?.has(e.toLowerCase())===!0&&!M(e)}async function qt(e,t,n,o,s){let r=[];for(let{objectApiName:i,records:c}of t){let l=F(i);r.push({objectApiName:l,soql:`SELECT COUNT() FROM ${l} WHERE IsDeleted = true AND SystemModstamp < ${Z(o)}`,scanAll:!0,counts:"inBin"}),c!==0&&(r.push({objectApiName:l,soql:`SELECT COUNT() FROM ${l} WHERE SystemModstamp >= ${Je(o)}`,scanAll:!0,counts:"stampedSince"}),At(l,n)&&r.push({...et(l),counts:"links"}))}let d=await Ye(e,r,()=>{},s),p=new Map;return d.forEach((i,c)=>{let{objectApiName:l,counts:u}=r[c],h=i.read?i.totalSize:void 0,a=p.get(l)??{};u==="links"?a.links=h??null:h!==void 0&&(a[u]=h),p.set(l,a)}),{asked:r.length,of:p}}function St({scoped:e,capture:t,customSetting:n,access:o},s,r,d){return{objectApiName:e.objectApiName,records:s,inBin:r,readOrder:e.readOrder,readMode:t.readMode,undeletable:t.undeletable,cascadeParents:t.cascadeParents,restrictParents:t.restrictParents,fingerprint:d,fields:t.fields,leftOutFields:t.leftOutFields,...n!==void 0?{customSetting:n}:{},...o!==void 0?{access:o}:{}}}function Ot(e){return{personAccounts:rt(e.map(({describe:t})=>t)),catalog:at(e.map(({scoped:t})=>t.objectApiName))}}function Zt(e){let t=e?.orgType==="Sandbox"||e?.orgType==="Scratch";return Oe(Ce(t)).defaultQueryLimit}async function Ct(e,t,n,o,s,r,d,p=Tt){let i=n.maxTotal??Gt;if(!Number.isInteger(i)||i<1)throw new RangeError(`Not a number of records: ${i}`);let c=Math.min(i,B),{counts:l,refused:u,alone:h}=await Yt(e,t,o.objects,d),a=J({mode:n.mode,objects:o.objects.map(({scoped:b})=>b),leftOut:o.leftOut,packages:[]},u),g=new Map(o.objects.map(b=>[b.scoped.objectApiName,b])),w=a.leftOut.map(bt),A=[];for(let b of a.objects){let O=g.get(b.objectApiName),P=l.get(b.objectApiName);if(!(O===void 0||P===void 0)){if(P>c){w.push(Kt(b.objectApiName,P,c));continue}A.push({...O,scoped:{...b,readOrder:A.length},records:P,otherGroups:Be(b.objectApiName,O.capture.fields,O.capture.readMode),recount:{}})}}let S=A.some(({scoped:b})=>M(b.objectApiName))?o.linkable:void 0,f=await qt(t,A.map(({scoped:b,records:O})=>({objectApiName:b.objectApiName,records:O})),S,r,d);for(let b of A)b.recount=f.of.get(b.scoped.objectApiName)??{};w.sort((b,O)=>b.objectApiName<O.objectApiName?-1:b.objectApiName>O.objectApiName?1:0);let k={};for(let{scoped:b,describe:O}of A)k[b.objectApiName]=De(O.fields);let y=en(p,We({described:o.described,describedAlone:o.describedAlone,counted:o.objects.length,countedAlone:h,recounted:f.asked,objects:A.map(b=>({records:b.records,otherGroups:b.otherGroups,...b.recount,entry:St(b,b.records,0,k[b.scoped.objectApiName].digest)})),pageRows:Zt(n.registered),leftOut:w,printsBytes:(await $e(k)).length,annexCalls:ct(Ot(A))})),m={...y,apiRequestsLeft:s.remaining},C={objects:A,leftOut:w,estimate:m,objectLimit:c,prints:k,...S!==void 0?{linkable:S}:{}};if(y.records>i){let b=[...A.map(O=>O.records),...w.flatMap(O=>O.code==="pastTheLimit"?[O.records??0]:[])];return{...C,refusal:{code:"TOO_MANY_RECORDS",message:`The objects this checkpoint would keep hold ${y.records} records in ${n.orgName}, past its limit of ${i}: pick fewer objects. ${W}`,holdingLimit:Jt(b,y.records)}}}let R=_e("take",y.apiRequests,s,n.orgName);return R===void 0?C:{...C,refusal:R}}function jt(e){return{query:t=>e.query(t),queryMore:t=>e.queryMore(t)}}var Tt={guard:0,scope:0};function en(e,t){if(e.guard+e.scope===0)return t;let n=t.requestsByPhase;return{...t,apiRequests:t.apiRequests+e.guard+e.scope,...n!==void 0?{requestsByPhase:{...n,guard:n.guard+e.guard,scope:n.scope+e.scope}}:{}}}function tn(e){let t=[...e.mode==="picked"?e.objects??[]:[],...Array.isArray(e.customSettings)?e.customSettings:[]];return new Set(t.map(n=>n.toLowerCase()))}function nn(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}async function Rt(e,t,n,o,s,r){if(s.kind==="org")return{scope:{...o,objects:o.objects.map(f=>({...f,access:"org"}))},reads:Tt};let d=o.objects.map(({scoped:f})=>f.objectApiName),p={grants:s.objects,describes:o.objects.map(({describe:f})=>f),customSettings:o.objects.filter(({customSetting:f})=>f!==void 0).map(({scoped:f})=>f.objectApiName)},i=nt(d,p),c=[],l=0;if(i.length>0)try{let f=await se(e,t,i);c=[...f.describes.values()],l=Math.ceil(i.length/Re)+f.alone}catch(f){if(_(f,r))throw f}let u=ot(d,{...p,describes:[...p.describes,...c]}),h=tn(n),a=[],g=[...o.leftOut],w=[];for(let f of o.objects){let k=f.scoped.objectApiName,y=u.get(k);if(y!==void 0&&"access"in y){a.push({...f,access:y.access});continue}let m={objectApiName:k,reason:y?.reason??"noViewAll",...y?.detail!==void 0?{detail:y.detail}:{}};g.push(m),h.has(k.toLowerCase())&&n.unprovenLeftOut!==!0&&w.push(m)}let A=new Set(a.map(({scoped:f})=>f.objectApiName)),S={scope:{...o,objects:a,leftOut:g,addedToPicked:o.addedToPicked.filter(f=>A.has(f))},reads:{guard:s.requests,scope:l}};if(w.length>0){let f=w.length===1;return{...S,refusal:{code:"PERMISSIONS",message:`${n.username} doesn't have View All Data and Modify All Data, and the checkpoint can't hold ${nn(w.map(k=>k.objectApiName))}, asked for by name. ${w.map(k=>`${k.objectApiName}: ${bt(k).reason}`).join(" ")} Leave ${f?"it":"them"} out, or give the user View All Data and Modify All Data. ${W}`}}}return a.length===0&&o.objects.length>0?{...S,refusal:{code:"PERMISSIONS",message:`${n.username} doesn't have View All Data and Modify All Data, nor View All and Modify All on any object this checkpoint would hold: without them, a checkpoint holds only the objects its user sees and puts back whole. Give the user View All and Modify All on the objects to hold, or View All Data and Modify All Data. `+W}}:S}function on(e){return e.objects.map(({scoped:t,label:n,capture:o,records:s,customSetting:r,access:d})=>({objectApiName:t.objectApiName,label:n,...t.namespace!==void 0?{namespace:t.namespace}:{},records:s,undeletable:o.undeletable,leftOutFields:o.leftOutFields,...r!==void 0?{customSetting:r}:{},...d!==void 0?{access:d}:{}}))}function Nt(e){let t=e.customSettings;return t!==void 0&&(t==="all"||t.length>0)}async function sn(e,t,n,o,s){let r=new Map(o.objects.map(u=>[u.scoped.objectApiName,u])),d=n.settings.filter(({objectApiName:u})=>!r.has(u)),p=new Map;if(d.length>0)try{({describes:p}=await se(e,t,d.map(({objectApiName:u})=>u)))}catch(u){if(_(u,s))throw u}let i=d.filter(({objectApiName:u})=>p.has(u)),c=await ee(t,i.map(({objectApiName:u})=>({objectApiName:u,readMode:"query"})),s),l=new Map;return c.forEach((u,h)=>{"count"in u&&l.set(i[h].objectApiName,u.count)}),n.settings.map(({objectApiName:u,label:h})=>{let a=r.get(u);if(a?.customSetting!==void 0)return{objectApiName:u,label:h,kind:a.customSetting,records:a.records};let g=p.get(u),w=l.get(u);return{objectApiName:u,label:h,...g!==void 0?{kind:K(g)}:{},...w!==void 0?{records:w}:{}}})}var rn={records:0,apiRequests:0,apiRequestsLeft:0,seconds:0,bytes:0};async function Yn(e,t){let n={mode:t.mode,objects:[],leftOut:[],estimate:rn},o=await te(jt(e.org),{act:"take",orgName:t.orgName,registered:t.registered,username:t.username,customSettings:Nt(t)},{userId:()=>e.org.userId()});if(!o.allowed)return{...n,refusal:o.refusal};let s=e.store.heldBy(o.org.id),r=s===void 0?await e.runWriting?.(o.org.id):void 0,d=X(e.org,e.signal);try{let p=await q(e.org,t.orgName),i=await Rt(e.org,d,t,await yt(e.org,d,t),o.grants,e.signal),{scope:c}=i,l=await e.org.serverTime(),u=await Ct(e.org,d,t,c,p,l,e.signal,i.reads),h={mode:t.mode,objects:on(u),leftOut:u.leftOut,estimate:u.estimate,files:{held:u.objects.some(({scoped:g})=>M(g.objectApiName)),queryAllFiles:o.queryAllFiles,addedToPicked:c.addedToPicked},customSettings:await sn(e.org,d,c,u,e.signal)},a=s!==void 0?kt(t.orgName,s):r!==void 0?{code:"RUN_WRITING",message:r}:i.refusal??u.refusal;return a===void 0?h:{...h,refusal:a}}catch(p){throw _(p,e.signal)?new D:p}}function an(e){let t=e.requestsSent?()=>e.requestsSent?.()??0:void 0,n={guard:0,scope:0,start:0,counts:0,bin:0,snapshot:0,stability:0},o="guard",s=t?.()??0,r=()=>{if(!t)return;let d=t();n[o]+=d-s,s=d};return{enter(d){r(),o=d},requests(){return t?(r(),{total:Object.values(n).reduce((p,i)=>p+i,0),byPhase:{...n}}):void 0}}}async function cn(e,t){if(t.edition!==void 0)return t.edition;let o=(await e.query("SELECT OrganizationType FROM Organization LIMIT 1")).records[0]?.OrganizationType;if(typeof o!="string"||o==="")throw new Error("The org did not say its edition (Organization.OrganizationType).");return o}var dn="Automated Process";async function ln(e){let n=(await e.query("SELECT Id, Name FROM User WHERE UserType = 'AutomatedProcess'")).records.filter(s=>typeof s.Id=="string"),o=n.find(s=>s.Name===dn);return o!==void 0?o.Id:n.length===1?n[0].Id:void 0}function Dt(e){let t=new Date(Date.parse(e)).toISOString();return`${t.slice(0,10)} ${t.slice(11,16)} UTC`}function mt(e,t){return e.split(he).join(Dt(t))}function ne(e){let t=Se(e);return t===null?Number.NaN:Date.parse(t)}function Mt(e){return typeof e=="string"&&e.length>=15?e.slice(0,15):void 0}async function un(e,t){let n=new Set;for await(let o of x(Y(e,t))){let s=Mt(o.Id);s!==void 0&&n.add(s)}return n}async function pn(e,t,n,o,s,r){let d={changed:0,deleted:0,created:0};if(!o.live&&!o.deleted)return d;let p=await xe.read(e,t,n);if(o.live)for await(let i of x(o.live.file)){let c=ne(i.SystemModstamp);if(!(c<=r))continue;let l=p.stampOf(i.Id);l===void 0?d.created++:l!==c&&d.changed++}if(o.deleted){let i;for await(let c of x(o.deleted.file)){if(!(ne(c.SystemModstamp)<=r))continue;if(p.has(c.Id)){d.deleted++;continue}if(!(ne(c.CreatedDate)<s))continue;i??=await un(e,n);let l=Mt(c.Id);l!==void 0&&!i.has(l)&&d.deleted++}}return d}async function Pt(e){let t=0;for(let n of await It(e,{withFileTypes:!0})){let o=oe(e,n.name);n.isDirectory()?t+=await Pt(o):n.isFile()&&(t+=(await ht(o)).size)}return t}async function fn(e,t){let n=await Pt(e.dir)-(await ht(e.checkpointFile)).size,o=r=>Buffer.byteLength(`${JSON.stringify({...t,bytes:r},null,2)}
8
8
  `,"utf8"),s=n+o(n);return s=n+o(s),s}function mn(e){let t=e.snapshotsFile,n=new Ue({getData:()=>xt(t)?JSON.parse(Bt(t,"utf8")):{},setData:o=>Wt(t,JSON.stringify(o,null,2),{encoding:"utf8",mode:384})});return n.initialize(),n}var gn=V({organizationId:pe().optional()}).loose();async function hn(e,t,n,o,s){let r=mn(e),d=0,p={log:n.handler.log,orgManager:n.handler.orgManager,orgRegistry:n.handler.orgRegistry,configStore:r,broker:{postToWebview:c=>{if(c.type!=="operation:progress")return;let l=c.payload;typeof l.percentage=="number"&&typeof l.currentStep=="string"&&s(l.percentage,l.currentStep)}},services:{getSandforgeSetting:(c,l)=>c==="backup.maxRecordsPerObject"?o:l},nextId:()=>`${e.checkpointId}-${++d}`},i=new Ge(p);return i.setBackupRecordStore(new Ve(t)),await i.swept(),{handler:i,config:r}}function bn(e,t){return e.slice(0,15)===t.slice(0,15)}async function qn(e,t){let{org:n,store:o,signal:s}=e,r=e.now??(()=>new Date),d=me.parse([...t.ignoredFields??[]]),p=t.name===void 0?void 0:$.parse(t.name),i=t.nameWithDate;i!==void 0&&$.parse(mt(i,r().toISOString()));let c=t.customSettings==="all"?[]:t.customSettings??[];for(let y of[...t.objects??[],...t.excluded??[],...c])F(y);let l=t.beforeRun===void 0?void 0:ge.parse(t.beforeRun),u=t.keepDays??Me;I(r(),u);let h=(y,m,C=0,R=0)=>e.onProgress?.({percentage:Math.round(y),processedObjects:C,totalObjects:R,step:m});h(0,`Checking ${t.orgName}`);let a=an(n),g=await te(jt(n),{act:"take",orgName:t.orgName,registered:t.registered,username:t.username,customSettings:Nt(t)},{userId:()=>n.userId()});if(!g.allowed)return{taken:!1,refusal:g.refusal};let w=g.org.id,A=ve("ck",r()),S=o.lock(w,"take",A);if("busy"in S)return{taken:!1,refusal:kt(t.orgName,S.busy)};let f,k;try{let y=await e.runWriting?.(w);if(y!==void 0)return{taken:!1,refusal:{code:"RUN_WRITING",message:y}};let m=X(n,s),C=await cn(n,g.org),R=await q(n,t.orgName);h(2,`Reading the objects of ${t.orgName}`),a.enter("scope");let b=await Rt(n,m,t,await yt(n,m,t),g.grants,s);if(b.refusal!==void 0)return{taken:!1,refusal:b.refusal};let{scope:O}=b;a.enter("start");let P=await n.userId(),ie=await ln(n),N=await n.serverTime();h(8,`Counting the records of ${O.objects.length} objects`),a.enter("counts");let T=await Ct(n,m,t,O,R,N,s,b.reads);if(T.refusal!==void 0)return{taken:!1,refusal:T.refusal};if(T.objects.length===0)throw new Error(`None of the objects asked for can be kept in a checkpoint of ${t.orgName}: ${T.leftOut.map(j=>`${j.objectApiName}: ${j.reason}`).join(" ")||"there are none."}`);if(s?.aborted)throw new D;f=await o.create(w,A);let E=`snapshot-${A}`;k={version:1,checkpointId:A,name:p??(i!==void 0?$.parse(mt(i,N)):Dt(N)),org:{organizationId:w,...t.alias!==void 0?{alias:t.alias}:{},username:t.username,instanceUrl:t.instanceUrl,isSandbox:g.org.sandbox,organizationType:C,tier:g.tier,...t.scratchExpiresAt!==void 0?{scratchExpiresAt:t.scratchExpiresAt}:{},...R.dataStorageMaxMB!==void 0?{dataStorageMaxMB:R.dataStorageMaxMB}:{},...t.registered?.staging===!0&&g.org.sandbox?{staging:!0}:{}},takenBy:{userId:P,...ie!==void 0?{automatedProcessUserId:ie}:{},viewAllData:g.grants.kind==="org"||g.grants.viewAllData,modifyAllData:g.grants.kind==="org"||g.grants.modifyAllData,queryAllFiles:g.queryAllFiles},readFrom:N,takenAt:N,scope:{mode:t.mode,leftOut:T.leftOut},objects:[],ignoredFields:d,snapshotId:E,movedWhileTaken:{changed:0,deleted:0,created:0},bytes:0,expiresAt:I(r(),u),status:"taking",takenOn:{host:_t(),pid:process.pid},...l!==void 0?{beforeRun:l}:{}},await o.write(k),h(12,"Reading the recycle bin as it was at the checkpoint"),a.enter("bin");let vt=await qe(m,T.objects.map(({scoped:j})=>({...Xe(j.objectApiName,N),file:Y(f,j.objectApiName)})),s),re=new Map;for(let j of vt){if(!j.read)throw new Error(`The recycle bin of ${j.objectApiName} could not be read whole: ${j.reason}`);re.set(j.objectApiName,j.rows)}a.enter("snapshot");let{records:Et,files:ae}=await kn(f,E,T,t,e,w,m,h);h(88,`Reading the record types, users and queues ${t.orgName} names`);let $t=await wn(f,E,T,m,w,s);h(89,"Reading the time on the org"),a.enter("stability");let ce=await n.serverTime();h(90,`Checking what changed in ${t.orgName} while it was read`);let{movedWhileTaken:Ft,notChecked:Lt}=await yn(f,E,T,m,N,ce,s),{prints:de}=T;await o.writeFingerprints(f,de);let G=T.objects.map(j=>{let z=j.scoped.objectApiName;return St(j,Et.get(z)??0,re.get(z)??0,de[z].digest)});if(s?.aborted)throw new D;let le={...k,takenAt:ce,objects:G,movedWhileTaken:Ft,bytes:0,expiresAt:I(r(),u),status:"ready",...ae!==void 0?{files:ae}:{},replayAnnex:$t},U={...le,bytes:await fn(f,le)};await o.write(U),h(100,`Checkpoint '${U.name}' taken`,G.length,G.length);let ue=a.requests();return{taken:!0,checkpoint:U,notChecked:Lt,...ue!==void 0?{requests:ue}:{},estimate:T.estimate}}catch(y){throw f!==void 0&&await An(o,f,k,e),_(y,s)?new D:y}finally{S.lock.release()}}async function kn(e,t,n,o,s,r,d,p){let i=n.objects.filter(a=>a.records>0),c=new Map,l=(s.snapshotFiles??Vt)(e.dir);if(i.length>0){let a=Math.max(Ut,n.objectLimit),{handler:g,config:w}=await hn(e,l,s,a,(k,y)=>p(15+k*.65,y)),A=await g.backupForPipeline({operationId:t,orgId:o.orgId,objects:i.map(({scoped:k})=>k.objectApiName),fields:new Map(i.map(({scoped:k,capture:y})=>[k.objectApiName,y.fields])),scanAll:i.filter(({capture:k})=>k.readMode==="scanAllLive").map(({scoped:k})=>k.objectApiName),origin:"checkpoint",failWhenTruncated:!0,onConnection:k=>s.org.countAlso?.(k)},s.signal),S=gn.safeParse(w.get(`backup:${t}`)),f=S.success?S.data.organizationId:void 0;if(f===void 0||!bn(f,r))throw new Error(`The snapshot was read from ${f===void 0?"an org that did not say which it is":`another org (${f})`}, not from ${o.orgName}: it is not kept.`);for(let k of A.objects)c.set(k.objectApiName,k.recordCount)}p(82,"Indexing the snapshot",0,n.objects.length);for(let[a,{scoped:g}]of n.objects.entries()){let w=g.objectApiName,A=c.get(w)??0;c.has(w)||(await Pe(oe(e.dir,"backups")),await l.writeFile(Le(e,t,w),""),c.set(w,0));let S=await Ie(e,t,w);if(S.rows!==A)throw new Ee("damaged",`The snapshot of ${w} holds ${S.rows} records where its read kept ${A}: it is not kept.`);p(82+6*(a+1)/n.objects.length,`Indexed ${w}`,a+1,n.objects.length)}let u=n.objects.find(({scoped:a})=>M(a.objectApiName));if(u===void 0||n.linkable===void 0)return{records:c};p(88,"Reading the links of files to the records read");let h=await tt({reader:d,folder:e,snapshotId:t,linked:n.objects.map(({scoped:a})=>a.objectApiName).filter(a=>(c.get(a)??0)>0&&At(a,n.linkable)),documentsInSnapshot:(c.get(u.scoped.objectApiName)??0)>0,...s.signal!==void 0?{signal:s.signal}:{}});return{records:c,files:h}}async function wn(e,t,n,o,s,r){let d=await it(e,t,n.objects.map(({scoped:i,describe:c,capture:l})=>({objectApiName:i.objectApiName,userLookups:st(c,l.fields)}))),p=await dt({reader:o,organizationId:s,users:d,...Ot(n.objects),...r!==void 0?{signal:r}:{}});return lt(e,p)}async function yn(e,t,n,o,s,r,d){let p=oe(e.dir,zt),i={changed:0,deleted:0,created:0},c=[];try{let l=await Ze(o,n.objects.map(({capture:a})=>({objectApiName:a.objectApiName,readMode:a.readMode,held:!1})),s,p,d),u=Date.parse(Z(s)),h=Date.parse(r);for(let a of l){if("unread"in a){c.push({objectApiName:a.objectApiName,reason:a.unread});continue}if(!a.moved)continue;let g=await pn(e,t,a.objectApiName,a,u,h);i.changed+=g.changed,i.deleted+=g.deleted,i.created+=g.created}}finally{await gt(p,{recursive:!0,force:!0})}return{movedWhileTaken:i,notChecked:c}}async function An(e,t,n,o){try{n!==void 0&&await e.write({...n,status:"failed"})}catch(s){o.handler.log(`[WARN] checkpoint ${t.checkpointId}: not marked failed: ${v(s)}`)}try{await gt(t.dir,{recursive:!0,force:!0})}catch(s){o.handler.log(`[WARN] checkpoint ${t.checkpointId}: what its take wrote was not removed: ${v(s)}`)}}export{Gt as a,B as b,Xn as c,D as d,Kt as e,Jt as f,Yn as g,qn as h};
@@ -0,0 +1,7 @@
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{$ as b,Aa as C,Ba as D,Ca as E,Da as F,Ea as G,Fa as H,Ga as I,Ha as J,Ia as K,Ja as L,Ka as M,La as N,Ma as O,Na as P,Oa as Q,Pa as R,_ as a,aa as c,ba as d,ca as e,da as f,ea as g,fa as h,ga as i,ha as j,ia as k,ja as l,ka as m,la as n,ma as o,na as p,oa as q,pa as r,qa as s,ra as t,sa as u,ta as v,ua as w,va as x,wa as y,xa as z,ya as A,za as B}from"./chunk-KB4ZHM4Q.mjs";import"./chunk-23SEDORH.mjs";import"./chunk-W6PN6TJG.mjs";import"./chunk-3Q353S2R.mjs";import"./chunk-RHNTHGNU.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-Q7TLC3I2.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-D4GF4FAB.mjs";import"./chunk-CVHNXJH3.mjs";import"./chunk-TQ2TQHTT.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-M6K34KGF.mjs";import"./chunk-TNT27RBG.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-S42RBRH2.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{m as ASSIGNMENT_RULES_SOQL,h as AUTOMATION_READ_MOST,b as CONDITIONS_BOUND,f as CONDITION_REQUESTS_BOUND,c as DEFINITIONS_BOUND,g as DEFINITION_REQUESTS_BOUND,n as DUPLICATE_RULES_SOQL,i as FLOWS_SOQL,k as PROCESSES_SOQL,d as TOOLING_QUERIES_PER_REQUEST,e as TOOLING_RETRIEVES_PER_REQUEST,j as TRIGGERS_SOQL,N as TargetAutomationReader,o as USER_PERMISSIONS_SOQL,l as WORKFLOW_RULES_SOQL,a as answerOf,R as automationLines,p as conditionSoql,z as customObjectIdsSoql,Q as customPermissionsByIdSoql,A as customPermissionsSoql,G as decisionChecks,F as fieldsRequiredFilled,L as inFlight,H as messagesOf,M as objectsTheRunWrites,I as pathsOf,J as permissionKey,C as permissionSetSizesSoql,B as permissionSetsHoldingSoql,D as permissionsNamed,y as processObjectsSoql,O as readBypassGrants,w as readInComposites,x as ruleDefinitionSoql,P as setCustomPermissionsSoql,E as switchesNamed,v as targetAutomationQueries,s as toolingAnswersOf,q as toolingCompositeBody,t as toolingRecordsOf,r as toolingRetrieveBody,u as toolingRetrievesOver,K as unreadPartOf};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a,b,c,d,e,f,g,h}from"./chunk-KKS2KFBT.mjs";import"./chunk-OTJH6AEA.mjs";import"./chunk-AHUGG3WU.mjs";import"./chunk-FVLFO2S6.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-MJD6CPZZ.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{d as ARTICLE_OBJECT,b as CASE_STATUS_BY_LABEL_SOQL,a as CASE_STATUS_SOQL,g as prepareScenario,c as readScenarioCaseStatus,f as scenarioCasePicklists,e as scenarioKnowledge,h as toolingQueryAll};
7
+ import{a,b,c,d,e,f,g,h}from"./chunk-QKEKG2LD.mjs";import"./chunk-KAZS5Z6W.mjs";import"./chunk-FITPY3L4.mjs";import"./chunk-BBRWFKS5.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-JAEDM4SI.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{d as ARTICLE_OBJECT,b as CASE_STATUS_BY_LABEL_SOQL,a as CASE_STATUS_SOQL,g as prepareScenario,c as readScenarioCaseStatus,f as scenarioCasePicklists,e as scenarioKnowledge,h as toolingQueryAll};
@@ -4,6 +4,6 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{c as N,e as C,f as F}from"./chunk-Y7YUNRKK.mjs";import{d as I,z as P}from"./chunk-N2HYG3BL.mjs";import{b as O}from"./chunk-TQ2TQHTT.mjs";import{ma as $,ta as _}from"./chunk-6QSHWIZI.mjs";import{b as u,e as m,f as M,h as R,k as l,l as i,o as A,s as k,u as z,v as S,z as E}from"./chunk-WZQEK4WT.mjs";import{createHash as K,randomBytes as q}from"node:crypto";import{createReadStream as re}from"node:fs";import{chmod as ne,copyFile as oe,open as ae,readFile as G,readdir as H,rename as j,rm as w,stat as U}from"node:fs/promises";import{join as h}from"node:path";var X=1440*6e4,se="forge-samples",Q="forge-runs",B="sample.json",W="the run of this sample",ie=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,V=/^[A-Za-z0-9_-]{1,128}$/,f=class extends Error{constructor(e,r){super(r);this.refusal=e;this.name="SamplePlanError"}refusal};function x(n){return h(n,se)}function ce(n,t){if(!V.test(t))throw new f("otherSetup","Not the fingerprint of a setup of a run.");return h(x(n),t)}function v(n,t){return h(n,Q,`${t.replace(/[^A-Za-z0-9_-]/g,"_")}.sample`)}var p=u().regex(/^[A-Za-z][A-Za-z0-9_]*$/),s=m().int().nonnegative(),le=i({window:i({field:z(["CreatedDate","LastModifiedDate"]),from:u().optional(),to:u().optional(),lastDays:m().int().positive().optional()}).optional(),notWindowed:l(p).optional(),where:l(i({objectApiName:p,where:u()})).optional(),strata:l(i({objectApiName:p,field:u(),values:l(i({value:A([u(),M(),R()]),label:u().optional(),roots:s,kept:s})),more:s.optional()})).optional()}),pe=i({seed:m().int().min(0),draw:$,floor:s,parents:_,children:A([S("all"),m().int().min(1)]),share:m().min(0).max(1),budget:i({bytes:m().nonnegative(),remainingMB:m().optional(),maxMB:m().optional(),share:m().optional(),roundingMB:m().optional(),automationMB:m().optional(),withinMB:m().optional(),maxTotal:m().optional(),limitedBy:z(["storage","within","maxTotal","targetRequests","bulkBatches","sourceRequests","heavyRoots","whole","draw"])}),rows:s,storageBytes:m().nonnegative(),objects:l(i({objectApiName:p,sourceRows:s,kept:s,roots:s,below:s,asParents:s,whole:S(!0).optional(),childrenCut:l(i({field:u(),rows:s})).optional(),rootsInTheSource:s.optional(),rootsInTheDraw:s.optional()})),whole:l(i({objectApiName:p,why:z(["referenceData","catalog","smallParent","asked"])})),heavyRoots:l(i({objectApiName:p,id:u().regex(ie),rows:s,relation:i({objectApiName:p,field:u()})})),dropped:l(i({objectApiName:p,rows:s,reason:z(["noParentInSource","outsideFilter","excludedObject","withoutParent","heldBack","recordTypeNotInTarget"])})),leftEmpty:l(i({objectApiName:p,field:u(),rows:s})),noRecordDrawn:l(i({objectApiName:p,sourceRows:s,noRootInTheDraw:S(!0).optional()})),roots:le.optional(),partialMasters:l(i({objectApiName:p,details:p,field:u(),kept:s.optional(),sourceRows:s.optional(),asParents:s.optional()})).optional(),planRequests:i({source:s}),newestByIds:l(p).optional(),oldestByIds:l(p).optional()}),ue=i({personAccounts:k(p,s),byThePlatform:l(i({objectApiName:p,inPlan:s,beyond:s}))}),T=i({version:S(1),sourceOrgId:u().min(1),fingerprint:u().regex(V),drawnAt:E.datetime(),drawnBy:z(["run","dryRun"]),sha256:u().regex(/^[0-9a-f]{64}$/),objects:l(i({objectApiName:p,count:m().int().positive(),sha256:u().regex(/^[0-9a-f]{64}$/)})),sample:pe,newestByIds:l(p).optional(),oldestByIds:l(p).optional(),counts:ue.optional()});async function Z(n){let t=K("sha256");for await(let e of re(n))t.update(e);return t.digest("hex")}function L(n){let t=K("sha256"),e=[...n].sort((r,o)=>r.objectApiName<o.objectApiName?-1:r.objectApiName>o.objectApiName?1:0);for(let{objectApiName:r,count:o,sha256:a}of e)t.update(`${r} ${o} ${a}
7
+ import{c as N,e as C,f as F}from"./chunk-NED4MBIM.mjs";import{d as I,z as P}from"./chunk-KGU4SVIT.mjs";import{b as O}from"./chunk-TQ2TQHTT.mjs";import{ma as $,ta as _}from"./chunk-PMWAFDUB.mjs";import{b as u,e as m,f as M,h as R,k as l,l as i,o as A,s as k,u as z,v as S,z as E}from"./chunk-WZQEK4WT.mjs";import{createHash as K,randomBytes as q}from"node:crypto";import{createReadStream as re}from"node:fs";import{chmod as ne,copyFile as oe,open as ae,readFile as G,readdir as H,rename as j,rm as w,stat as U}from"node:fs/promises";import{join as h}from"node:path";var X=1440*6e4,se="forge-samples",Q="forge-runs",B="sample.json",W="the run of this sample",ie=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,V=/^[A-Za-z0-9_-]{1,128}$/,f=class extends Error{constructor(e,r){super(r);this.refusal=e;this.name="SamplePlanError"}refusal};function x(n){return h(n,se)}function ce(n,t){if(!V.test(t))throw new f("otherSetup","Not the fingerprint of a setup of a run.");return h(x(n),t)}function v(n,t){return h(n,Q,`${t.replace(/[^A-Za-z0-9_-]/g,"_")}.sample`)}var p=u().regex(/^[A-Za-z][A-Za-z0-9_]*$/),s=m().int().nonnegative(),le=i({window:i({field:z(["CreatedDate","LastModifiedDate"]),from:u().optional(),to:u().optional(),lastDays:m().int().positive().optional()}).optional(),notWindowed:l(p).optional(),where:l(i({objectApiName:p,where:u()})).optional(),strata:l(i({objectApiName:p,field:u(),values:l(i({value:A([u(),M(),R()]),label:u().optional(),roots:s,kept:s})),more:s.optional()})).optional()}),pe=i({seed:m().int().min(0),draw:$,floor:s,parents:_,children:A([S("all"),m().int().min(1)]),share:m().min(0).max(1),budget:i({bytes:m().nonnegative(),remainingMB:m().optional(),maxMB:m().optional(),share:m().optional(),roundingMB:m().optional(),automationMB:m().optional(),withinMB:m().optional(),maxTotal:m().optional(),limitedBy:z(["storage","within","maxTotal","targetRequests","bulkBatches","sourceRequests","heavyRoots","whole","draw"])}),rows:s,storageBytes:m().nonnegative(),objects:l(i({objectApiName:p,sourceRows:s,kept:s,roots:s,below:s,asParents:s,whole:S(!0).optional(),childrenCut:l(i({field:u(),rows:s})).optional(),rootsInTheSource:s.optional(),rootsInTheDraw:s.optional()})),whole:l(i({objectApiName:p,why:z(["referenceData","catalog","smallParent","asked"])})),heavyRoots:l(i({objectApiName:p,id:u().regex(ie),rows:s,relation:i({objectApiName:p,field:u()})})),dropped:l(i({objectApiName:p,rows:s,reason:z(["noParentInSource","outsideFilter","excludedObject","withoutParent","heldBack","recordTypeNotInTarget"])})),leftEmpty:l(i({objectApiName:p,field:u(),rows:s})),noRecordDrawn:l(i({objectApiName:p,sourceRows:s,noRootInTheDraw:S(!0).optional()})),roots:le.optional(),partialMasters:l(i({objectApiName:p,details:p,field:u(),kept:s.optional(),sourceRows:s.optional(),asParents:s.optional()})).optional(),planRequests:i({source:s}),newestByIds:l(p).optional(),oldestByIds:l(p).optional()}),ue=i({personAccounts:k(p,s),byThePlatform:l(i({objectApiName:p,inPlan:s,beyond:s}))}),T=i({version:S(1),sourceOrgId:u().min(1),fingerprint:u().regex(V),drawnAt:E.datetime(),drawnBy:z(["run","dryRun"]),sha256:u().regex(/^[0-9a-f]{64}$/),objects:l(i({objectApiName:p,count:m().int().positive(),sha256:u().regex(/^[0-9a-f]{64}$/)})),sample:pe,newestByIds:l(p).optional(),oldestByIds:l(p).optional(),counts:ue.optional()});async function Z(n){let t=K("sha256");for await(let e of re(n))t.update(e);return t.digest("hex")}function L(n){let t=K("sha256"),e=[...n].sort((r,o)=>r.objectApiName<o.objectApiName?-1:r.objectApiName>o.objectApiName?1:0);for(let{objectApiName:r,count:o,sha256:a}of e)t.update(`${r} ${o} ${a}
8
8
  `);return t.digest("hex")}async function me(n,t){let e=await ae(n,"wx",I);try{await e.writeFile(t,"utf8"),await e.sync()}finally{await e.close()}}function D(n){let t=n?.code;return t==="ENOENT"||t==="ENOTDIR"}var y=class n{constructor(t,e,r){this.dir=t;this.manifest=e;this.spool=r}dir;manifest;spool;get sha256(){return this.manifest.sha256}get count(){return this.spool.count}countOf(t){return this.manifest.objects.find(e=>e.objectApiName===t)?.count??0}ageMs(t){return t.getTime()-Date.parse(this.manifest.drawnAt)}get place(){return{path:this.dir,sha256:this.manifest.sha256,drawnAt:this.manifest.drawnAt,drawnBy:this.manifest.drawnBy}}async*ids(t,e={}){let r=Math.max(1,Math.floor(e.size??2e3)),o=e.after,a=[];for await(let c of this.spool.pages(t,r))for(let d of c)o!==void 0&&O(d,o)<=0||(a.push(d),a.length>=r&&(yield a,a=[]));a.length>0&&(yield a)}static async open(t,e={}){let r;try{r=JSON.parse(await G(h(t,B),"utf8"))}catch(d){throw D(d)?new f("gone","The plan of this sample is no longer on this machine."):new f("changed","The plan of this sample does not read as one.")}let o=T.safeParse(r);if(!o.success)throw new f("changed","The plan of this sample does not read as one.");let a=o.data,c;try{c=await F.open(t,W)}catch{throw new f("changed","The ids of this sample are not as they were written.")}if(await n.holdToManifest(t,a,c),e.sourceOrgId!==void 0&&e.sourceOrgId!==a.sourceOrgId)throw new f("otherOrg","This plan was drawn of another org.");if(e.fingerprint!==void 0&&e.fingerprint!==a.fingerprint)throw new f("otherSetup","This plan was drawn for another setup of the run.");if(e.sha256!==void 0&&e.sha256!==a.sha256)throw new f("otherSha","This is not the plan the run was drawn with.");return new n(t,a,c)}static async holdToManifest(t,e,r){let o=()=>new f("changed","The ids of this sample are not as they were written."),a=r.objects.filter(c=>c.count>0);if(a.length!==e.objects.length)throw o();for(let c of e.objects){let d=a.find(b=>b.objectApiName===c.objectApiName);if(!d||d.count!==c.count)throw o();let g;try{g=await Z(N(t,c.objectApiName))}catch{throw o()}if(g!==c.sha256)throw o()}if(L(e.objects)!==e.sha256)throw o()}static async keep(t,e){let r=`${t}.${process.pid}-${q(4).toString("hex")}.tmp`;try{await P(r);let o=new C(r,W);for(let{objectApiName:g,ids:b}of e.ids){let ee=[...b].sort(O);for(let te of ee)await o.add(g,te)}let a=await o.finish(),c=[];for(let{objectApiName:g,count:b}of a.objects)b!==0&&c.push({objectApiName:g,count:b,sha256:await Z(N(r,g))});let d={version:1,sourceOrgId:e.sourceOrgId,fingerprint:e.fingerprint,drawnAt:e.drawnAt.toISOString(),drawnBy:e.drawnBy,sha256:L(c),objects:c,sample:e.sample,...e.newestByIds!==void 0&&e.newestByIds.length>0?{newestByIds:[...e.newestByIds]}:{},...e.oldestByIds!==void 0&&e.oldestByIds.length>0?{oldestByIds:[...e.oldestByIds]}:{},...e.counts?{counts:e.counts}:{}};T.parse(d),await me(h(r,B),`${JSON.stringify(d)}
9
- `),await w(t,{recursive:!0,force:!0}),await j(r,t)}catch(o){throw await w(r,{recursive:!0,force:!0}),o}return n.open(t)}};function Pe(n,t){return y.keep(n,t)}async function je(n,t,e){let r;try{r=await y.open(ce(n,t),{fingerprint:t})}catch(o){if(o instanceof f)return;throw o}return r.ageMs(e)>=X?"tooOld":r}async function Ae(n,t,e){let r=v(t,e);return await P(h(t,Q)),await w(r,{recursive:!0,force:!0}),await j(n.dir,r),y.open(r,{sha256:n.sha256})}async function Ie(n,t,e){let r=v(n,t);return!await J(r)||await J(e)?!1:(await P(x(n)),await j(r,e),!0)}async function Ne(n,t,e){let r=v(t,e);return await Y(n.dir,r),y.open(r,{sha256:n.sha256})}async function Oe(n,t,e){let r=await y.open(n,{sha256:e});await Y(r.dir,t);try{return await y.open(t,{sha256:e})}catch(o){throw await w(t,{recursive:!0,force:!0}),o}}async function Y(n,t){let e=`${t}.${process.pid}-${q(4).toString("hex")}.tmp`;try{await P(e);for(let r of await H(n))await oe(h(n,r),h(e,r)),await ne(h(e,r),I);await w(t,{recursive:!0,force:!0}),await j(e,t)}catch(r){throw await w(e,{recursive:!0,force:!0}),r}}async function J(n){try{return await U(n),!0}catch(t){if(D(t))return!1;throw t}}async function Be(n){await w(n,{recursive:!0,force:!0})}async function Te(n,t){let e=x(n),r;try{r=await H(e)}catch(a){if(D(a))return 0;throw a}let o=0;for(let a of r){let c=h(e,a),d;try{let g=T.parse(JSON.parse(await G(h(c,B),"utf8")));d=Date.parse(g.drawnAt)}catch{d=(await U(c)).mtimeMs}t.getTime()-d<X||(await w(c,{recursive:!0,force:!0}),o++)}return o}export{X as a,f as b,ce as c,v as d,y as e,Pe as f,je as g,Ae as h,Ie as i,Ne as j,Oe as k,Be as l,Te as m};
9
+ `),await w(t,{recursive:!0,force:!0}),await j(r,t)}catch(o){throw await w(r,{recursive:!0,force:!0}),o}return n.open(t)}};function Pe(n,t){return y.keep(n,t)}async function je(n,t,e){let r;try{r=await y.open(ce(n,t),{fingerprint:t})}catch(o){if(o instanceof f)return;throw o}return r.ageMs(e)>=X?"tooOld":r}async function Ae(n,t,e){let r=v(t,e);return await P(h(t,Q)),await w(r,{recursive:!0,force:!0}),await j(n.dir,r),y.open(r,{sha256:n.sha256})}async function Ie(n,t,e){let r=v(n,t);return!await J(r)||await J(e)?!1:(await P(x(n)),await j(r,e),!0)}async function Ne(n,t,e){let r=v(t,e);return await Y(n.dir,r),y.open(r,{sha256:n.sha256})}async function Oe(n,t,e){let r=await y.open(n,{sha256:e});await Y(r.dir,t);try{return await y.open(t,{sha256:e})}catch(o){throw await w(t,{recursive:!0,force:!0}),o}}async function Y(n,t){let e=`${t}.${process.pid}-${q(4).toString("hex")}.tmp`;try{await P(e);for(let r of await H(n))await oe(h(n,r),h(e,r)),await ne(h(e,r),I);await w(t,{recursive:!0,force:!0}),await j(e,t)}catch(r){throw await w(e,{recursive:!0,force:!0}),r}}async function J(n){try{return await U(n),!0}catch(t){if(D(t))return!1;throw t}}async function Be(n){await w(n,{recursive:!0,force:!0})}async function Te(n,t){let e=x(n),r;try{r=await H(e)}catch(a){if(D(a))return[];throw a}let o=[];for(let a of r){let c=h(e,a),d;try{let g=T.parse(JSON.parse(await G(h(c,B),"utf8")));d=Date.parse(g.drawnAt)}catch{d=(await U(c)).mtimeMs}t.getTime()-d<X||(await w(c,{recursive:!0,force:!0}),o.push(a))}return o}export{X as a,f as b,ce as c,v as d,y as e,Pe as f,je as g,Ae as h,Ie as i,Ne as j,Oe as k,Be as l,Te as m};