sandforge 1.81.0 → 1.83.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 (240) hide show
  1. package/README.md +48 -0
  2. package/bin/sandforge-users.mjs +12 -0
  3. package/lib/{chunk-J6G23RUI.mjs → chunk-262TP6UU.mjs} +1 -1
  4. package/lib/{chunk-NWVVCZUK.mjs → chunk-27BBEGUD.mjs} +1 -1
  5. package/lib/{chunk-Y5ZCPY36.mjs → chunk-2ADSD5WK.mjs} +1 -1
  6. package/lib/{chunk-55LQD3Y3.mjs → chunk-2GSMHGIV.mjs} +1 -1
  7. package/lib/chunk-2K5BYZQM.mjs +8 -0
  8. package/lib/{chunk-GK7VEYFM.mjs → chunk-2KTGDYUH.mjs} +1 -1
  9. package/lib/{chunk-T3PLRQ2T.mjs → chunk-2N73W63D.mjs} +1 -1
  10. package/lib/{chunk-7PK5QDQI.mjs → chunk-2R6GFNKF.mjs} +1 -1
  11. package/lib/{chunk-2OIRJEYE.mjs → chunk-2WMKJVD2.mjs} +1 -1
  12. package/lib/{chunk-D62KWDDT.mjs → chunk-36Y225OM.mjs} +1 -1
  13. package/lib/{chunk-HYOOJVR6.mjs → chunk-3CM7LAPE.mjs} +1 -1
  14. package/lib/{chunk-OIIL4NVI.mjs → chunk-3OVTKRS4.mjs} +1 -1
  15. package/lib/{chunk-UT27HXE7.mjs → chunk-3V4YH5KO.mjs} +1 -1
  16. package/lib/{chunk-OZNLOV4U.mjs → chunk-446GBKAC.mjs} +1 -1
  17. package/lib/{chunk-SQGP46QS.mjs → chunk-4GCYGQXD.mjs} +1 -1
  18. package/lib/{chunk-2NAIUKVL.mjs → chunk-4V3QO7HF.mjs} +1 -1
  19. package/lib/{chunk-GWRKS3AL.mjs → chunk-4X5D3MSV.mjs} +1 -1
  20. package/lib/{chunk-KGYXLSQ5.mjs → chunk-5OGNK3JP.mjs} +1 -1
  21. package/lib/{chunk-D7P7DTWL.mjs → chunk-6KOUYHEY.mjs} +1 -1
  22. package/lib/chunk-6QSHWIZI.mjs +48 -0
  23. package/lib/chunk-6VOQFISN.mjs +7 -0
  24. package/lib/{chunk-742SSN7I.mjs → chunk-6YC2ELCU.mjs} +1 -1
  25. package/lib/chunk-77IVKH7R.mjs +7 -0
  26. package/lib/{chunk-KNIRA333.mjs → chunk-77MZRBWX.mjs} +1 -1
  27. package/lib/{chunk-ZUA5BNAO.mjs → chunk-7BQMBXKX.mjs} +1 -1
  28. package/lib/{chunk-OQQHNYR7.mjs → chunk-7DPHZWA4.mjs} +2 -2
  29. package/lib/chunk-7V2UYZ6S.mjs +7 -0
  30. package/lib/chunk-7WSQ65WG.mjs +9 -0
  31. package/lib/{chunk-HVC5CYIB.mjs → chunk-7ZBDACVG.mjs} +1 -1
  32. package/lib/chunk-A32ISQ6M.mjs +28 -0
  33. package/lib/{chunk-XC2QKQT5.mjs → chunk-AG24QMSY.mjs} +1 -1
  34. package/lib/{chunk-K77NR3UK.mjs → chunk-AHUGG3WU.mjs} +1 -1
  35. package/lib/{chunk-K55LH4ZQ.mjs → chunk-ALBY5SOH.mjs} +1 -1
  36. package/lib/chunk-AXFD2OH6.mjs +7 -0
  37. package/lib/{chunk-YCSFP6ER.mjs → chunk-BH76USTQ.mjs} +1 -1
  38. package/lib/chunk-BNKT3R3F.mjs +7 -0
  39. package/lib/{chunk-YIGFYZQY.mjs → chunk-BPHTA6KP.mjs} +1 -1
  40. package/lib/{chunk-MNITSYI2.mjs → chunk-BT43WSOS.mjs} +1 -1
  41. package/lib/{chunk-ZWZXQTAK.mjs → chunk-BVZ5H3N4.mjs} +14 -14
  42. package/lib/{chunk-43K2C6H2.mjs → chunk-C6RKM4BB.mjs} +1 -1
  43. package/lib/{chunk-C4YGSK6W.mjs → chunk-CDWZGQAJ.mjs} +1 -1
  44. package/lib/chunk-CGZGL6VT.mjs +7 -0
  45. package/lib/{chunk-KE2PGD6C.mjs → chunk-CN5HGFG4.mjs} +1 -1
  46. package/lib/chunk-CQAFVEKP.mjs +13 -0
  47. package/lib/{chunk-XIZ5LMQM.mjs → chunk-CTPLYUXA.mjs} +1 -1
  48. package/lib/chunk-CXKZ6TYV.mjs +9 -0
  49. package/lib/{chunk-DHIW4IO5.mjs → chunk-D6JT4PAB.mjs} +1 -1
  50. package/lib/{chunk-AELFEK3G.mjs → chunk-D7XUNWWU.mjs} +1 -1
  51. package/lib/{chunk-GR3NGDVM.mjs → chunk-DB5RVDC5.mjs} +1 -1
  52. package/lib/{chunk-MO3N5XVV.mjs → chunk-DIGUC7S4.mjs} +2 -2
  53. package/lib/{chunk-2OZG6GRW.mjs → chunk-DKDKCGXV.mjs} +1 -1
  54. package/lib/chunk-DMT5SCO3.mjs +7 -0
  55. package/lib/chunk-DNQKVCUV.mjs +475 -0
  56. package/lib/{chunk-MAHZMPMZ.mjs → chunk-DSR2MSBH.mjs} +1 -1
  57. package/lib/{chunk-O6ADMP36.mjs → chunk-E3RQ575Y.mjs} +1 -1
  58. package/lib/{chunk-ETT5GP4P.mjs → chunk-EOQON3E5.mjs} +1 -1
  59. package/lib/{chunk-TKQQVB2D.mjs → chunk-ETNQHIDI.mjs} +1 -1
  60. package/lib/chunk-F5SBGJWW.mjs +7 -0
  61. package/lib/chunk-FBXH4VRQ.mjs +7 -0
  62. package/lib/chunk-FKCIGJOI.mjs +15 -0
  63. package/lib/{chunk-OVOLG3AL.mjs → chunk-FVLFO2S6.mjs} +1 -1
  64. package/lib/{chunk-YOGMP72T.mjs → chunk-FYWNSMOZ.mjs} +1 -1
  65. package/lib/{chunk-DHGPDSXS.mjs → chunk-GEEWPTV5.mjs} +1 -1
  66. package/lib/{chunk-FSDO4DJA.mjs → chunk-GLN4PI5P.mjs} +1 -1
  67. package/lib/{chunk-PYUEHBA6.mjs → chunk-GT5ZKU6V.mjs} +1 -1
  68. package/lib/chunk-GTRU5AV5.mjs +7 -0
  69. package/lib/chunk-H33DVU3D.mjs +7 -0
  70. package/lib/{chunk-5WGA5CZB.mjs → chunk-H4OBZIX3.mjs} +1 -1
  71. package/lib/{chunk-4L7FBOJS.mjs → chunk-HQZUQXDC.mjs} +1 -1
  72. package/lib/{chunk-VSU74RQ3.mjs → chunk-HVX2AFYW.mjs} +1 -1
  73. package/lib/chunk-I3ZO76LL.mjs +21 -0
  74. package/lib/{chunk-V4RKM4QZ.mjs → chunk-I5C4O3VA.mjs} +1 -1
  75. package/lib/{chunk-FSZTXLNW.mjs → chunk-IHGYJZZ2.mjs} +1 -1
  76. package/lib/chunk-ISA2NYJV.mjs +7 -0
  77. package/lib/{chunk-2IB7I3IQ.mjs → chunk-ISAUCWYK.mjs} +1 -1
  78. package/lib/{chunk-3B5H24ZG.mjs → chunk-ISOSTAJR.mjs} +1 -1
  79. package/lib/chunk-IXIY6Q4M.mjs +7 -0
  80. package/lib/{chunk-TPHXRHOA.mjs → chunk-J3TIHLWG.mjs} +1 -1
  81. package/lib/{chunk-TQM2XJ27.mjs → chunk-JAV6F6OA.mjs} +1 -1
  82. package/lib/chunk-JBWJ6UEZ.mjs +7 -0
  83. package/lib/{chunk-WM5JI4JI.mjs → chunk-JH4ZTVQN.mjs} +1 -1
  84. package/lib/{chunk-BZFIOZS3.mjs → chunk-JIPT5FUD.mjs} +1 -1
  85. package/lib/{chunk-6FMLW7PH.mjs → chunk-JPEVIXNH.mjs} +1 -1
  86. package/lib/{chunk-67CC7RAE.mjs → chunk-JREKJO3D.mjs} +1 -1
  87. package/lib/{chunk-3AOKLIVE.mjs → chunk-JUOQUG7U.mjs} +1 -1
  88. package/lib/chunk-JYUMD357.mjs +7 -0
  89. package/lib/{chunk-56MPPWLA.mjs → chunk-K7G3W7XH.mjs} +1 -1
  90. package/lib/{chunk-OU5W7SCB.mjs → chunk-KKS2KFBT.mjs} +1 -1
  91. package/lib/{chunk-RKALOKAU.mjs → chunk-KWAVSZ2B.mjs} +1 -1
  92. package/lib/{chunk-WI4HYWV6.mjs → chunk-KXUOHACP.mjs} +1 -1
  93. package/lib/{chunk-GTIXJCGS.mjs → chunk-L3I6DAHX.mjs} +1 -1
  94. package/lib/{chunk-FLNLG43R.mjs → chunk-L47JCNP3.mjs} +1 -1
  95. package/lib/{chunk-5344TZBT.mjs → chunk-L4MSL4U7.mjs} +1 -1
  96. package/lib/chunk-L4RJX7DG.mjs +7 -0
  97. package/lib/chunk-L6CLN664.mjs +7 -0
  98. package/lib/chunk-LI2XNV7F.mjs +7 -0
  99. package/lib/chunk-LP2D3JJP.mjs +7 -0
  100. package/lib/{chunk-EH5YUA5W.mjs → chunk-LWES2KZE.mjs} +1 -1
  101. package/lib/{chunk-YJEXE6HZ.mjs → chunk-LYOGCIYD.mjs} +2 -2
  102. package/lib/{chunk-BNO5GIJ6.mjs → chunk-MJD6CPZZ.mjs} +1 -1
  103. package/lib/{chunk-33ZX3A56.mjs → chunk-MTM4KG3T.mjs} +1 -1
  104. package/lib/{chunk-E2YJVSX6.mjs → chunk-N2HYG3BL.mjs} +1 -1
  105. package/lib/chunk-N5UIE4IR.mjs +7 -0
  106. package/lib/{chunk-R6TF26V4.mjs → chunk-NDFFIJL5.mjs} +1 -1
  107. package/lib/{chunk-FDGFUEK3.mjs → chunk-NFEBX75O.mjs} +1 -1
  108. package/lib/{chunk-QXLZINZB.mjs → chunk-NNV7IGM7.mjs} +1 -1
  109. package/lib/{chunk-OXKZ4Y3B.mjs → chunk-NS6ONPWL.mjs} +1 -1
  110. package/lib/{chunk-OEHVAJAB.mjs → chunk-O7GCCRPW.mjs} +1 -1
  111. package/lib/chunk-OO24ZYYJ.mjs +7 -0
  112. package/lib/chunk-OOIDCHBQ.mjs +9 -0
  113. package/lib/{chunk-MWLFFVQV.mjs → chunk-OS5GE52G.mjs} +1 -1
  114. package/lib/chunk-OS6HFJ7L.mjs +7 -0
  115. package/lib/{chunk-HYBH5PFM.mjs → chunk-OTJH6AEA.mjs} +1 -1
  116. package/lib/chunk-OUU47Y7A.mjs +7 -0
  117. package/lib/{chunk-FTA5LOVX.mjs → chunk-P6WRYJN3.mjs} +1 -1
  118. package/lib/{chunk-DXOXLUZA.mjs → chunk-PDRXM5WN.mjs} +1 -1
  119. package/lib/chunk-PGRY365W.mjs +7 -0
  120. package/lib/chunk-Q4PPI3KG.mjs +7 -0
  121. package/lib/chunk-QFTF2PGS.mjs +21 -0
  122. package/lib/chunk-QKJXIY6L.mjs +7 -0
  123. package/lib/{chunk-DMBR24CK.mjs → chunk-QLRWU3MB.mjs} +1 -1
  124. package/lib/chunk-QO4MPHZD.mjs +7 -0
  125. package/lib/chunk-QP3JLFIO.mjs +7 -0
  126. package/lib/{chunk-UCHAZ4ZU.mjs → chunk-QQDZQCO2.mjs} +1 -1
  127. package/lib/chunk-QROPNEGY.mjs +14 -0
  128. package/lib/{chunk-6NADW3OI.mjs → chunk-QXB6U3ZP.mjs} +1 -1
  129. package/lib/chunk-R3OM3X4L.mjs +8 -0
  130. package/lib/chunk-R7GKMAT4.mjs +7 -0
  131. package/lib/{chunk-JU2XEKEO.mjs → chunk-RVCPQVKM.mjs} +1 -1
  132. package/lib/{chunk-WEZLXE34.mjs → chunk-RZKJQOOC.mjs} +1 -1
  133. package/lib/chunk-S4PRKKGC.mjs +8 -0
  134. package/lib/{chunk-NJ3EOEHS.mjs → chunk-SX6QWYCQ.mjs} +1 -1
  135. package/lib/{chunk-ONMBSACW.mjs → chunk-T36DZJPH.mjs} +1 -1
  136. package/lib/{chunk-AJPSGVMD.mjs → chunk-T7DDS4UQ.mjs} +1 -1
  137. package/lib/chunk-TCEXCHXR.mjs +7 -0
  138. package/lib/chunk-TMIESDE5.mjs +7 -0
  139. package/lib/chunk-TQJ5NPRC.mjs +7 -0
  140. package/lib/chunk-TUPZY2QJ.mjs +7 -0
  141. package/lib/{chunk-2Z54GB6X.mjs → chunk-U2CTKIPE.mjs} +1 -1
  142. package/lib/{chunk-DQR5NDMI.mjs → chunk-U4YFYSF3.mjs} +1 -1
  143. package/lib/{chunk-EOSEMFPU.mjs → chunk-UIR77ZJD.mjs} +1 -1
  144. package/lib/{chunk-UUSLTW5V.mjs → chunk-UOHZW2L4.mjs} +1 -1
  145. package/lib/chunk-UV74P4H2.mjs +7 -0
  146. package/lib/{chunk-CULAOP3U.mjs → chunk-VXZ5PTOM.mjs} +1 -1
  147. package/lib/{chunk-IBURU7T7.mjs → chunk-VZLJZEV2.mjs} +1 -1
  148. package/lib/chunk-W3BQGMTR.mjs +7 -0
  149. package/lib/{chunk-WWTXRWNZ.mjs → chunk-WABXKL4N.mjs} +1 -1
  150. package/lib/{chunk-E2OBAWSH.mjs → chunk-WAYQLQAD.mjs} +1 -1
  151. package/lib/{chunk-6CDIIFNX.mjs → chunk-WBELLGNE.mjs} +1 -1
  152. package/lib/{chunk-LO527YLT.mjs → chunk-WJAZ5LHL.mjs} +1 -1
  153. package/lib/{chunk-6IGEASOF.mjs → chunk-WXU6ZJIV.mjs} +1 -1
  154. package/lib/{chunk-YHIOS2PU.mjs → chunk-WZN36ACK.mjs} +1 -1
  155. package/lib/{chunk-AITNZWLB.mjs → chunk-X2XZQ434.mjs} +1 -1
  156. package/lib/chunk-X4HZD5U2.mjs +7 -0
  157. package/lib/chunk-X6XNTOGO.mjs +7 -0
  158. package/lib/{chunk-5VQNKDFU.mjs → chunk-XAMMIPZ4.mjs} +1 -1
  159. package/lib/{chunk-MHW6DV6T.mjs → chunk-XAUQXYPW.mjs} +1 -1
  160. package/lib/{chunk-5UT2ZBGF.mjs → chunk-XCJUNX63.mjs} +1 -1
  161. package/lib/chunk-XJICAOAQ.mjs +7 -0
  162. package/lib/{chunk-GYKNCYES.mjs → chunk-XKFHTBAB.mjs} +1 -1
  163. package/lib/{chunk-6SEDOIO3.mjs → chunk-XMQ5R6TC.mjs} +1 -1
  164. package/lib/chunk-XPXEQKLR.mjs +7 -0
  165. package/lib/{chunk-SW2NUKQL.mjs → chunk-Y7YUNRKK.mjs} +1 -1
  166. package/lib/{chunk-UIUPPEFB.mjs → chunk-YBZIDW6W.mjs} +1 -1
  167. package/lib/{chunk-X2ZVSQ54.mjs → chunk-YEVB7LVK.mjs} +1 -1
  168. package/lib/{chunk-EAFLDSQ2.mjs → chunk-Z3MGN42K.mjs} +1 -1
  169. package/lib/{chunk-MKNAZPOT.mjs → chunk-ZB5E7NHU.mjs} +1 -1
  170. package/lib/chunk-ZCOSME6P.mjs +7 -0
  171. package/lib/{chunk-KRNFVAGC.mjs → chunk-ZOSESZ22.mjs} +1 -1
  172. package/lib/chunk-ZTHC42X6.mjs +7 -0
  173. package/lib/{chunk-XEB6HZ34.mjs → chunk-ZXOUWHYE.mjs} +1 -1
  174. package/lib/sandforge-autopilot.mjs +1 -1
  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 +1 -1
  180. package/lib/sandforge-dataops.mjs +1 -1
  181. package/lib/sandforge-empty.mjs +4 -4
  182. package/lib/sandforge-env.mjs +184 -139
  183. package/lib/sandforge-frozen.mjs +1 -1
  184. package/lib/sandforge-mcp.mjs +14 -14
  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 +155 -0
  190. package/lib/sandforge.mjs +1 -22
  191. package/lib/sf/sandforge/autopilot.mjs +20 -0
  192. package/lib/sf/sandforge/backup.mjs +20 -0
  193. package/lib/sf/sandforge/checkpoint.mjs +20 -0
  194. package/lib/sf/sandforge/cleanup.mjs +20 -0
  195. package/lib/sf/sandforge/clone.mjs +20 -0
  196. package/lib/sf/sandforge/compare.mjs +20 -0
  197. package/lib/sf/sandforge/dataops.mjs +20 -0
  198. package/lib/sf/sandforge/empty.mjs +20 -0
  199. package/lib/sf/sandforge/env.mjs +20 -0
  200. package/lib/sf/sandforge/frozen.mjs +20 -0
  201. package/lib/sf/sandforge/hardis-commands.mjs +20 -0
  202. package/lib/sf/sandforge/index.mjs +20 -0
  203. package/lib/sf/sandforge/mcp.mjs +20 -0
  204. package/lib/sf/sandforge/monitor.mjs +20 -0
  205. package/lib/sf/sandforge/pipeline.mjs +20 -0
  206. package/lib/sf/sandforge/seed.mjs +20 -0
  207. package/lib/sf/sandforge/sync.mjs +20 -0
  208. package/lib/sf/sandforge/users.mjs +20 -0
  209. package/lib/sfHelpHook.mjs +7 -0
  210. package/lib/sfPlugin.mjs +11 -0
  211. package/oclif.manifest.json +1 -0
  212. package/package.json +17 -3
  213. package/lib/chunk-2ZMGVBLW.mjs +0 -7
  214. package/lib/chunk-5C5XEVZN.mjs +0 -11
  215. package/lib/chunk-5CKWGZX4.mjs +0 -9
  216. package/lib/chunk-5ZKCLBTN.mjs +0 -474
  217. package/lib/chunk-7DALDJMO.mjs +0 -7
  218. package/lib/chunk-CAFUNR6D.mjs +0 -7
  219. package/lib/chunk-DPYTG6DM.mjs +0 -48
  220. package/lib/chunk-G4VXPS3A.mjs +0 -7
  221. package/lib/chunk-GF247DA7.mjs +0 -7
  222. package/lib/chunk-IKGHRYCN.mjs +0 -7
  223. package/lib/chunk-IM2XA6JI.mjs +0 -7
  224. package/lib/chunk-K5HV4YRO.mjs +0 -7
  225. package/lib/chunk-KOQV4WXC.mjs +0 -8
  226. package/lib/chunk-N6HHNR6J.mjs +0 -7
  227. package/lib/chunk-N7J6NJQ6.mjs +0 -7
  228. package/lib/chunk-NWPQF5XR.mjs +0 -7
  229. package/lib/chunk-O7DAFE6M.mjs +0 -14
  230. package/lib/chunk-OMZJ37JI.mjs +0 -15
  231. package/lib/chunk-R2BJWO5N.mjs +0 -20
  232. package/lib/chunk-T26C576X.mjs +0 -9
  233. package/lib/chunk-T5VAULLQ.mjs +0 -7
  234. package/lib/chunk-V2QO6KOE.mjs +0 -19
  235. package/lib/chunk-V473C7LY.mjs +0 -7
  236. package/lib/chunk-W2AAGIZF.mjs +0 -7
  237. package/lib/chunk-WD47PGUS.mjs +0 -10
  238. package/lib/chunk-XC54KKKC.mjs +0 -7
  239. package/lib/chunk-XGKSSCW7.mjs +0 -7
  240. package/lib/chunk-ZWCRWF7E.mjs +0 -7
@@ -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{e as C,f as I}from"./chunk-JU2XEKEO.mjs";import{e as T,r as S,z as O}from"./chunk-ETT5GP4P.mjs";import{H as A,d as P,r as b}from"./chunk-E2YJVSX6.mjs";import{a as u}from"./chunk-3B5H24ZG.mjs";import{b as w}from"./chunk-CA5NAXSU.mjs";import{_a as h}from"./chunk-DPYTG6DM.mjs";import{b as i,f as R,l as m}from"./chunk-WZQEK4WT.mjs";import{randomBytes as q}from"node:crypto";import{open as U,readFile as F,rename as $,rm as M}from"node:fs/promises";import{promisify as N}from"node:util";import{gunzip as L,gzip as _}from"node:zlib";var D=N(_),Q=N(L),G=200,E="005",j="User",z="Group",H=new Set(["Pricebook2","PricebookEntry"]);function Re(e,n){let t=new Set(n);return e.fields.filter(o=>t.has(o.name)&&!C.includes(o.name)&&o.type==="reference"&&o.createable===!0&&(o.referenceTo??[]).some(r=>r===j||r===z)).map(o=>o.name)}async function Ae(e,n,t){let o=new Set;for(let{objectApiName:r,userLookups:s}of t){if(s.length===0)continue;let c=await S.read(e,n,r);for await(let l of c.records())for(let y of s){let a=l[y];if(typeof a!="string")continue;let p=u(a,E);p!==void 0&&o.add(p)}}return[...o].sort()}function ke(e){for(let n of e)if((n.name==="Account"||n.name==="Contact")&&n.fields.some(t=>t.name===I))return!0;return!1}function be(e){for(let n of e)if(H.has(n))return!0;return!1}function J(e){return e.map(n=>{if(u(n,E)!==n)throw new Error(`Not a user id: ${n}`);return`'${n}'`}).join(", ")}function W(e,n){let t=[];for(let o=0;o<e.length;o+=n)t.push(e.slice(o,o+n));return t}function B(e,n){return[...v(e),...W(n,G).map(t=>({part:"users",objectApiName:j,soql:`SELECT Id, Username, Name, IsActive, UserType FROM User WHERE Id IN (${J(t)})`,scanAll:!1}))]}function v(e){let n=[{part:"recordTypes",objectApiName:"RecordType",soql:`SELECT Id, SobjectType, DeveloperName, NamespacePrefix, Name, IsActive${e.personAccounts?", IsPersonType":""} FROM RecordType`,scanAll:!1},{part:"queues",of:"groups",objectApiName:z,soql:"SELECT Id, DeveloperName, Name FROM Group WHERE Type = 'Queue'",scanAll:!1},{part:"queues",of:"objects",objectApiName:"QueueSobject",soql:"SELECT QueueId, SobjectType FROM QueueSobject",scanAll:!1}];return e.catalog&&n.push({part:"standardPricebook",objectApiName:"Pricebook2",soql:"SELECT Id FROM Pricebook2 WHERE IsStandard = true LIMIT 1",scanAll:!1}),n}function xe(e){return Math.ceil((v(e).length+1)/T)}var K=m({Id:i(),SobjectType:i(),DeveloperName:i(),NamespacePrefix:i().nullish(),Name:i(),IsActive:R(),IsPersonType:R().nullish()}).loose(),X=m({Id:i(),DeveloperName:i(),Name:i().nullish()}).loose(),V=m({QueueId:i(),SobjectType:i()}).loose(),Y=m({Id:i(),Username:i(),Name:i().nullish(),IsActive:R(),UserType:i()}).loose(),f="the org answered with rows this SandForge does not read";function Z(e,n){let t=[];for(let o of e){let r=K.safeParse(o);if(!r.success)return{unread:f};let s=r.data;t.push({id:u(s.Id)??s.Id,sobjectType:s.SobjectType,developerName:s.DeveloperName,...s.NamespacePrefix?{namespacePrefix:s.NamespacePrefix}:{},name:s.Name,isActive:s.IsActive,...n&&typeof s.IsPersonType=="boolean"?{isPersonType:s.IsPersonType}:{}})}return{rows:t.sort((o,r)=>x(`${o.sobjectType}.${o.developerName}`,`${r.sobjectType}.${r.developerName}`))}}function ee(e,n){let t=new Map;for(let r of n){let s=V.safeParse(r);if(!s.success)return{unread:f};let c=s.data.QueueId.slice(0,15);t.set(c,[...t.get(c)??[],s.data.SobjectType])}let o=[];for(let r of e){let s=X.safeParse(r);if(!s.success)return{unread:f};let c=s.data;o.push({id:u(c.Id)??c.Id,developerName:c.DeveloperName,name:c.Name??"",sobjectTypes:[...t.get(c.Id.slice(0,15))??[]].sort()})}return{rows:o.sort((r,s)=>x(r.developerName,s.developerName))}}function ne(e){let n=[];for(let t of e){let o=Y.safeParse(t);if(!o.success)return{unread:f};let r=o.data;n.push({id:u(r.Id)??r.Id,username:r.Username,name:r.Name??"",isActive:r.IsActive,userType:r.UserType})}return{rows:n.sort((t,o)=>x(t.id,o.id))}}async function we(e){let n=B(e,e.users),t=n.map(()=>[]),o=await O(e.reader,n,(a,p)=>{t[a].push(...p)},e.signal),r=new Map;o.forEach((a,p)=>{let{part:d}=n[p];!a.read&&!r.has(d)&&r.set(d,a.reason)});let s=(a,p)=>n.flatMap((d,g)=>d.part===a&&(p===void 0||d.of===p)?t[g]:[]),c={version:1,organizationId:u(e.organizationId)??e.organizationId,recordTypes:[],users:[],queues:[],unread:[]},l=(a,p,d)=>{let g=r.get(a);if(g!==void 0){c.unread.push({part:a,reason:oe(g)});return}let k=p();"unread"in k?c.unread.push({part:a,reason:k.unread}):d(k.rows)};l("recordTypes",()=>Z(s("recordTypes"),e.personAccounts),a=>{c.recordTypes=a}),l("queues",()=>ee(s("queues","groups"),s("queues","objects")),a=>{c.queues=a}),e.catalog&&l("standardPricebook",()=>{let[a]=s("standardPricebook"),p=typeof a?.Id=="string"?u(a.Id,"01s"):void 0;return a!==void 0&&p===void 0?{unread:f}:{rows:p}},a=>{a!==void 0&&(c.standardPricebookId=a)}),l("users",()=>ne(s("users")),a=>{c.users=a});let y=h.safeParse(c);return y.success?y.data:re(c,y.error.issues)}function re(e,n){let t=new Set;for(let r of n){let[s]=r.path;(s==="recordTypes"||s==="users"||s==="queues")&&t.add(s),s==="standardPricebookId"&&t.add("standardPricebook")}let o={...e,unread:[...e.unread]};for(let r of t)r==="recordTypes"&&(o.recordTypes=[]),r==="users"&&(o.users=[]),r==="queues"&&(o.queues=[]),r==="standardPricebook"&&delete o.standardPricebookId,o.unread.push({part:r,reason:f});return h.parse(o)}function x(e,n){return e<n?-1:e>n?1:0}function oe(e){let n=e.trim()===""?"the org gave no reason":e.trim();return n.length<=500?n:`${n.slice(0,499)}\u2026`}function te(e){let n=[...new Set(e.unread.map(t=>t.part))];return{recordTypes:e.recordTypes.length,users:e.users.length,queues:e.queues.length,standardPricebook:e.standardPricebookId!==void 0,...n.length>0?{unread:n}:{}}}async function Te(e,n){let t=h.safeParse(n);if(!t.success)throw new A("invalid",`Not a replay annex: ${t.error.message}`);let o=b(e),r=`${o}.${process.pid}-${q(4).toString("hex")}.tmp`,s=await U(r,"wx",P);try{try{await s.writeFile(await D(`${JSON.stringify(t.data)}
7
+ import{e as C,f as I}from"./chunk-RVCPQVKM.mjs";import{e as T,r as S,z as O}from"./chunk-EOQON3E5.mjs";import{H as A,d as P,r as b}from"./chunk-N2HYG3BL.mjs";import{b as w}from"./chunk-CA5NAXSU.mjs";import{a as u}from"./chunk-ISOSTAJR.mjs";import{_a as h}from"./chunk-6QSHWIZI.mjs";import{b as i,f as R,l as m}from"./chunk-WZQEK4WT.mjs";import{randomBytes as q}from"node:crypto";import{open as U,readFile as F,rename as $,rm as M}from"node:fs/promises";import{promisify as N}from"node:util";import{gunzip as L,gzip as _}from"node:zlib";var D=N(_),Q=N(L),G=200,E="005",j="User",z="Group",H=new Set(["Pricebook2","PricebookEntry"]);function Re(e,n){let t=new Set(n);return e.fields.filter(o=>t.has(o.name)&&!C.includes(o.name)&&o.type==="reference"&&o.createable===!0&&(o.referenceTo??[]).some(r=>r===j||r===z)).map(o=>o.name)}async function Ae(e,n,t){let o=new Set;for(let{objectApiName:r,userLookups:s}of t){if(s.length===0)continue;let c=await S.read(e,n,r);for await(let l of c.records())for(let y of s){let a=l[y];if(typeof a!="string")continue;let p=u(a,E);p!==void 0&&o.add(p)}}return[...o].sort()}function ke(e){for(let n of e)if((n.name==="Account"||n.name==="Contact")&&n.fields.some(t=>t.name===I))return!0;return!1}function be(e){for(let n of e)if(H.has(n))return!0;return!1}function J(e){return e.map(n=>{if(u(n,E)!==n)throw new Error(`Not a user id: ${n}`);return`'${n}'`}).join(", ")}function W(e,n){let t=[];for(let o=0;o<e.length;o+=n)t.push(e.slice(o,o+n));return t}function B(e,n){return[...v(e),...W(n,G).map(t=>({part:"users",objectApiName:j,soql:`SELECT Id, Username, Name, IsActive, UserType FROM User WHERE Id IN (${J(t)})`,scanAll:!1}))]}function v(e){let n=[{part:"recordTypes",objectApiName:"RecordType",soql:`SELECT Id, SobjectType, DeveloperName, NamespacePrefix, Name, IsActive${e.personAccounts?", IsPersonType":""} FROM RecordType`,scanAll:!1},{part:"queues",of:"groups",objectApiName:z,soql:"SELECT Id, DeveloperName, Name FROM Group WHERE Type = 'Queue'",scanAll:!1},{part:"queues",of:"objects",objectApiName:"QueueSobject",soql:"SELECT QueueId, SobjectType FROM QueueSobject",scanAll:!1}];return e.catalog&&n.push({part:"standardPricebook",objectApiName:"Pricebook2",soql:"SELECT Id FROM Pricebook2 WHERE IsStandard = true LIMIT 1",scanAll:!1}),n}function xe(e){return Math.ceil((v(e).length+1)/T)}var K=m({Id:i(),SobjectType:i(),DeveloperName:i(),NamespacePrefix:i().nullish(),Name:i(),IsActive:R(),IsPersonType:R().nullish()}).loose(),X=m({Id:i(),DeveloperName:i(),Name:i().nullish()}).loose(),V=m({QueueId:i(),SobjectType:i()}).loose(),Y=m({Id:i(),Username:i(),Name:i().nullish(),IsActive:R(),UserType:i()}).loose(),f="the org answered with rows this SandForge does not read";function Z(e,n){let t=[];for(let o of e){let r=K.safeParse(o);if(!r.success)return{unread:f};let s=r.data;t.push({id:u(s.Id)??s.Id,sobjectType:s.SobjectType,developerName:s.DeveloperName,...s.NamespacePrefix?{namespacePrefix:s.NamespacePrefix}:{},name:s.Name,isActive:s.IsActive,...n&&typeof s.IsPersonType=="boolean"?{isPersonType:s.IsPersonType}:{}})}return{rows:t.sort((o,r)=>x(`${o.sobjectType}.${o.developerName}`,`${r.sobjectType}.${r.developerName}`))}}function ee(e,n){let t=new Map;for(let r of n){let s=V.safeParse(r);if(!s.success)return{unread:f};let c=s.data.QueueId.slice(0,15);t.set(c,[...t.get(c)??[],s.data.SobjectType])}let o=[];for(let r of e){let s=X.safeParse(r);if(!s.success)return{unread:f};let c=s.data;o.push({id:u(c.Id)??c.Id,developerName:c.DeveloperName,name:c.Name??"",sobjectTypes:[...t.get(c.Id.slice(0,15))??[]].sort()})}return{rows:o.sort((r,s)=>x(r.developerName,s.developerName))}}function ne(e){let n=[];for(let t of e){let o=Y.safeParse(t);if(!o.success)return{unread:f};let r=o.data;n.push({id:u(r.Id)??r.Id,username:r.Username,name:r.Name??"",isActive:r.IsActive,userType:r.UserType})}return{rows:n.sort((t,o)=>x(t.id,o.id))}}async function we(e){let n=B(e,e.users),t=n.map(()=>[]),o=await O(e.reader,n,(a,p)=>{t[a].push(...p)},e.signal),r=new Map;o.forEach((a,p)=>{let{part:d}=n[p];!a.read&&!r.has(d)&&r.set(d,a.reason)});let s=(a,p)=>n.flatMap((d,g)=>d.part===a&&(p===void 0||d.of===p)?t[g]:[]),c={version:1,organizationId:u(e.organizationId)??e.organizationId,recordTypes:[],users:[],queues:[],unread:[]},l=(a,p,d)=>{let g=r.get(a);if(g!==void 0){c.unread.push({part:a,reason:oe(g)});return}let k=p();"unread"in k?c.unread.push({part:a,reason:k.unread}):d(k.rows)};l("recordTypes",()=>Z(s("recordTypes"),e.personAccounts),a=>{c.recordTypes=a}),l("queues",()=>ee(s("queues","groups"),s("queues","objects")),a=>{c.queues=a}),e.catalog&&l("standardPricebook",()=>{let[a]=s("standardPricebook"),p=typeof a?.Id=="string"?u(a.Id,"01s"):void 0;return a!==void 0&&p===void 0?{unread:f}:{rows:p}},a=>{a!==void 0&&(c.standardPricebookId=a)}),l("users",()=>ne(s("users")),a=>{c.users=a});let y=h.safeParse(c);return y.success?y.data:re(c,y.error.issues)}function re(e,n){let t=new Set;for(let r of n){let[s]=r.path;(s==="recordTypes"||s==="users"||s==="queues")&&t.add(s),s==="standardPricebookId"&&t.add("standardPricebook")}let o={...e,unread:[...e.unread]};for(let r of t)r==="recordTypes"&&(o.recordTypes=[]),r==="users"&&(o.users=[]),r==="queues"&&(o.queues=[]),r==="standardPricebook"&&delete o.standardPricebookId,o.unread.push({part:r,reason:f});return h.parse(o)}function x(e,n){return e<n?-1:e>n?1:0}function oe(e){let n=e.trim()===""?"the org gave no reason":e.trim();return n.length<=500?n:`${n.slice(0,499)}\u2026`}function te(e){let n=[...new Set(e.unread.map(t=>t.part))];return{recordTypes:e.recordTypes.length,users:e.users.length,queues:e.queues.length,standardPricebook:e.standardPricebookId!==void 0,...n.length>0?{unread:n}:{}}}async function Te(e,n){let t=h.safeParse(n);if(!t.success)throw new A("invalid",`Not a replay annex: ${t.error.message}`);let o=b(e),r=`${o}.${process.pid}-${q(4).toString("hex")}.tmp`,s=await U(r,"wx",P);try{try{await s.writeFile(await D(`${JSON.stringify(t.data)}
8
8
  `)),await s.sync()}finally{await s.close()}await $(r,o)}catch(c){throw await M(r,{force:!0}),c}return te(t.data)}async function Pe(e){let n;try{n=await F(b(e))}catch(r){if(r.code==="ENOENT")return;throw r}let t;try{t=JSON.parse((await Q(n)).toString("utf8"))}catch(r){throw new A("damaged",`The checkpoint\u2019s replay annex cannot be read: ${w(r)}`)}let o=h.safeParse(t);if(!o.success)throw new A("damaged","The checkpoint\u2019s replay annex does not parse");return o.data}export{Re as a,Ae as b,ke as c,be as d,xe as e,we as f,te as g,Te as h,Pe as i};
@@ -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{Nd as s,Od as d}from"./chunk-DPYTG6DM.mjs";function c(l,e){return l.type==="condition"&&e.status==="completed"&&e.output?.conditionMet===!1}var f=class{evaluate(e,n){return d(e,n)}check(e){return s(e)}evaluateGroup(e,n){return e.length===0?!0:e.some(t=>t.logicalGroup==="or")?e.some(t=>this.evaluate(t,n)):e.every(t=>this.evaluate(t,n))}getNextStep(e,n){if(n.status==="completed")return c(e,n)?e.onFailure:e.onSuccess;if(n.status==="failed")return e.onFailure}endsRun(e,n){return c(e,n)&&!e.onFailure}findBranch(e,n,o){let t=new Map(e.map(r=>[r.id,r])),u=[],a=new Set,i=n,p=t.get(i);if(!p)return u;for(i=o?p.onSuccess:p.onFailure;i&&!a.has(i);){a.add(i);let r=t.get(i);if(!r)break;u.push(r),i=o?r.onSuccess:r.onFailure}return u}};export{f as a};
7
+ import{ke as s,le as d}from"./chunk-6QSHWIZI.mjs";function c(l,e){return l.type==="condition"&&e.status==="completed"&&e.output?.conditionMet===!1}var f=class{evaluate(e,n){return d(e,n)}check(e){return s(e)}evaluateGroup(e,n){return e.length===0?!0:e.some(t=>t.logicalGroup==="or")?e.some(t=>this.evaluate(t,n)):e.every(t=>this.evaluate(t,n))}getNextStep(e,n){if(n.status==="completed")return c(e,n)?e.onFailure:e.onSuccess;if(n.status==="failed")return e.onFailure}endsRun(e,n){return c(e,n)&&!e.onFailure}findBranch(e,n,o){let t=new Map(e.map(r=>[r.id,r])),u=[],a=new Set,i=n,p=t.get(i);if(!p)return u;for(i=o?p.onSuccess:p.onFailure;i&&!a.has(i);){a.add(i);let r=t.get(i);if(!r)break;u.push(r),i=o?r.onSuccess:r.onFailure}return u}};export{f as a};
@@ -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{l as a,m as b,n as c,o as d,p as e,q as f}from"./chunk-HQZUQXDC.mjs";import"./chunk-NS6ONPWL.mjs";import"./chunk-DSR2MSBH.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-54HYHHVL.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-YBZIDW6W.mjs";import"./chunk-Y7YUNRKK.mjs";import"./chunk-4JKR4PTZ.mjs";import"./chunk-N2HYG3BL.mjs";import"./chunk-PPGDAUEQ.mjs";import"./chunk-VV3B6IC3.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-VXZ5PTOM.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-ZOSESZ22.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-Z3MGN42K.mjs";import"./chunk-2GSMHGIV.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.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{a as WHOLE_ORG_MAX_NODES,b as WHOLE_ORG_MAX_PAIRS,f as discoverWholeOrg,d as eachInPool,e as recordCountsOf,c as refusedByTheOrg};
@@ -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}from"./chunk-2OZG6GRW.mjs";import"./chunk-DPYTG6DM.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SeedValidator};
7
+ import{a}from"./chunk-DKDKCGXV.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SeedValidator};
@@ -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 S,b as k}from"./chunk-UNDIBZWG.mjs";import{Tb as m,Ub as z,Vb as E,Wb as h}from"./chunk-DPYTG6DM.mjs";import{b as c,f as g,i as f,k as l,l as d}from"./chunk-WZQEK4WT.mjs";var D=/\bid\.?\s*:\s*([A-Za-z0-9]{18}|[A-Za-z0-9]{15})(?![A-Za-z0-9])/i;function x(e,s){let t;if(/^[A-Za-z0-9]{15}$/.test(e))t=S(e);else if(k(e))t=e;else return;if(!(s&&!t.startsWith(s)))return t}function v(e){return D.exec(e)?.[1]}var R=d({statusCode:c().optional(),errorCode:c().optional(),message:c().optional(),fields:l(f()).optional(),duplicateResult:f().optional()}).loose(),p="UNKNOWN_ERROR";function y(e){if(typeof e=="string")return{statusCode:p,message:e,fields:[]};let s=R.safeParse(e);return s.success?{statusCode:s.data.statusCode??s.data.errorCode??p,message:s.data.message??"",fields:(s.data.fields??[]).filter(t=>typeof t=="string")}:{statusCode:p,message:"Unknown error",fields:[]}}var _=/^([A-Z][A-Z0-9_]*):([\s\S]*):([A-Za-z0-9_]+(?: [A-Za-z0-9_]+)*)? ?--$/;function M(e){let s=e.trim();if(!s.endsWith("--")||s.slice(0,-2).includes("--"))return;let t=_.exec(s);if(t)return{statusCode:t[1],message:t[2],fields:t[3]===void 0?[]:t[3].split(" ")}}var b=d({matchResults:l(d({entityType:c().optional(),matchRecords:l(d({record:d({Id:c().optional(),attributes:d({type:c().optional()}).loose().optional()}).loose().optional()}).loose()).optional()}).loose()).optional()}).loose(),I=d({id:c().nullish(),success:g(),created:g().optional(),errors:l(f()).optional()}).loose();function P(e){return e.statusCode===p?e.message:`${e.statusCode}: ${e.message}`}function A(e){if(typeof e=="string")return e;let s=R.safeParse(e);if(!s.success)return"Unknown error";let t=s.data.statusCode??s.data.errorCode,n=s.data.message??"",r=t?`${t}: ${n}`:n,i=(s.data.fields??[]).filter(a=>typeof a=="string");if(i.length===0)return r;let o=`[${i.join(", ")}]`;return r.includes(o)?r:r?`${r} ${o}`:o}var C=5;function T(e){let s=(e??[]).map(r=>A(r)).filter(r=>r!==""&&r!=="Unknown error");if(s.length===0)return"Unknown insert error";let t=s.slice(0,C).join("; "),n=s.length-C;return n>0?`${t} (and ${n} more)`:t}function O(e,s){let t=R.safeParse(e);if(!t.success)return[];if((t.data.statusCode??t.data.errorCode)!==m)return[];let n=b.safeParse(t.data.duplicateResult);if(!n.success)return[];let r=[];for(let i of n.data.matchResults??[])for(let{record:o}of i.matchRecords??[]){let a=[i.entityType,o?.attributes?.type].filter(u=>typeof u=="string");a.length===0||a.some(u=>u!==s)||o?.Id&&r.push(o.Id)}return r}function w(e,s){let t=I.safeParse(e);if(!t.success){let i="Salesforce returned a save result of an unexpected shape";return{id:"",success:!1,errors:[i],errorDetails:[y(i)]}}let n=t.data.errors??[],r=n.flatMap(i=>O(i,s));return{id:t.data.id??"",success:t.data.success,...t.data.created!==void 0?{created:t.data.created}:{},errors:n.map(A),errorDetails:n.map(y),...r.length>0?{duplicateMatchIds:r}:{}}}function Z(e,s){return(Array.isArray(e)?e:[e]).map(t=>w(t,s))}function L(e,s){if(e.success||e.errors.length===0)return{kind:"none"};let t=o=>h(o)||z(o);if(!e.errors.every(t))return{kind:"none"};let n=new Set,r=!1;for(let o of e.errors){if(!o.includes(E))continue;let a=v(o),u=a?x(a,s):void 0;u?n.add(u):r=!0}let i=e.duplicateMatchIds??[];e.errors.some(o=>o.includes(m))&&i.length===0&&(r=!0);for(let o of i){let a=x(o,s);a?n.add(a):r=!0}return r||n.size!==1?{kind:"unidentified"}:{kind:"linked",id:[...n][0]}}export{x as a,p as b,y as c,M as d,P as e,A as f,T as g,O as h,w as i,Z as j,L as k};
7
+ import{a as S,b as k}from"./chunk-UNDIBZWG.mjs";import{qc as m,rc as z,sc as E,tc as h}from"./chunk-6QSHWIZI.mjs";import{b as c,f as g,i as f,k as l,l as d}from"./chunk-WZQEK4WT.mjs";var D=/\bid\.?\s*:\s*([A-Za-z0-9]{18}|[A-Za-z0-9]{15})(?![A-Za-z0-9])/i;function x(e,s){let t;if(/^[A-Za-z0-9]{15}$/.test(e))t=S(e);else if(k(e))t=e;else return;if(!(s&&!t.startsWith(s)))return t}function v(e){return D.exec(e)?.[1]}var R=d({statusCode:c().optional(),errorCode:c().optional(),message:c().optional(),fields:l(f()).optional(),duplicateResult:f().optional()}).loose(),p="UNKNOWN_ERROR";function y(e){if(typeof e=="string")return{statusCode:p,message:e,fields:[]};let s=R.safeParse(e);return s.success?{statusCode:s.data.statusCode??s.data.errorCode??p,message:s.data.message??"",fields:(s.data.fields??[]).filter(t=>typeof t=="string")}:{statusCode:p,message:"Unknown error",fields:[]}}var _=/^([A-Z][A-Z0-9_]*):([\s\S]*):([A-Za-z0-9_]+(?: [A-Za-z0-9_]+)*)? ?--$/;function M(e){let s=e.trim();if(!s.endsWith("--")||s.slice(0,-2).includes("--"))return;let t=_.exec(s);if(t)return{statusCode:t[1],message:t[2],fields:t[3]===void 0?[]:t[3].split(" ")}}var b=d({matchResults:l(d({entityType:c().optional(),matchRecords:l(d({record:d({Id:c().optional(),attributes:d({type:c().optional()}).loose().optional()}).loose().optional()}).loose()).optional()}).loose()).optional()}).loose(),I=d({id:c().nullish(),success:g(),created:g().optional(),errors:l(f()).optional()}).loose();function P(e){return e.statusCode===p?e.message:`${e.statusCode}: ${e.message}`}function A(e){if(typeof e=="string")return e;let s=R.safeParse(e);if(!s.success)return"Unknown error";let t=s.data.statusCode??s.data.errorCode,n=s.data.message??"",r=t?`${t}: ${n}`:n,i=(s.data.fields??[]).filter(a=>typeof a=="string");if(i.length===0)return r;let o=`[${i.join(", ")}]`;return r.includes(o)?r:r?`${r} ${o}`:o}var C=5;function T(e){let s=(e??[]).map(r=>A(r)).filter(r=>r!==""&&r!=="Unknown error");if(s.length===0)return"Unknown insert error";let t=s.slice(0,C).join("; "),n=s.length-C;return n>0?`${t} (and ${n} more)`:t}function O(e,s){let t=R.safeParse(e);if(!t.success)return[];if((t.data.statusCode??t.data.errorCode)!==m)return[];let n=b.safeParse(t.data.duplicateResult);if(!n.success)return[];let r=[];for(let i of n.data.matchResults??[])for(let{record:o}of i.matchRecords??[]){let a=[i.entityType,o?.attributes?.type].filter(u=>typeof u=="string");a.length===0||a.some(u=>u!==s)||o?.Id&&r.push(o.Id)}return r}function w(e,s){let t=I.safeParse(e);if(!t.success){let i="Salesforce returned a save result of an unexpected shape";return{id:"",success:!1,errors:[i],errorDetails:[y(i)]}}let n=t.data.errors??[],r=n.flatMap(i=>O(i,s));return{id:t.data.id??"",success:t.data.success,...t.data.created!==void 0?{created:t.data.created}:{},errors:n.map(A),errorDetails:n.map(y),...r.length>0?{duplicateMatchIds:r}:{}}}function Z(e,s){return(Array.isArray(e)?e:[e]).map(t=>w(t,s))}function L(e,s){if(e.success||e.errors.length===0)return{kind:"none"};let t=o=>h(o)||z(o);if(!e.errors.every(t))return{kind:"none"};let n=new Set,r=!1;for(let o of e.errors){if(!o.includes(E))continue;let a=v(o),u=a?x(a,s):void 0;u?n.add(u):r=!0}let i=e.duplicateMatchIds??[];e.errors.some(o=>o.includes(m))&&i.length===0&&(r=!0);for(let o of i){let a=x(o,s);a?n.add(a):r=!0}return r||n.size!==1?{kind:"unidentified"}:{kind:"linked",id:[...n][0]}}export{x as a,p as b,y as c,M as d,P as e,A as f,T as g,O as h,w as i,Z as j,L as k};
@@ -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 jt,d as Tt,e as _t,g as Bt,h as xt,i as Ft,j as Ut,k as et}from"./chunk-54HYHHVL.mjs";import{a as Ce,b as z,d as H,e as vt,f as Xe,h as L}from"./chunk-MJD6CPZZ.mjs";import{e as $t,h as Ht,i as Jt}from"./chunk-ZOSESZ22.mjs";import{da as me,e as te,ea as Ze,ga as pe,ja as Pe}from"./chunk-2GSMHGIV.mjs";import{h as j}from"./chunk-TZE3Y7IQ.mjs";import{b as C}from"./chunk-CA5NAXSU.mjs";import{Dc as Nt,Ec as X,Ic as Ee,Lc as ge,Mc as Ge,Oc as Ye,Pc as Mt,qd as Lt,yc as Ct}from"./chunk-6QSHWIZI.mjs";import{b as x,e as Qe,f as M,i as Et,k as ae,l as Z,o as Ie,s as Pt}from"./chunk-WZQEK4WT.mjs";var Ne=class{activeJobs=new Map;maxConcurrentJobs;maxCompletedJobs=50;constructor(t=5){this.maxConcurrentJobs=t}registerJob(t){this.activeJobs.set(t.id,t)}updateJobState(t,e){let n=this.activeJobs.get(t);return n?(n.state=e,(e==="JobComplete"||e==="Failed"||e==="Aborted")&&this.purgeCompletedJobs(),!0):!1}updateJobCounts(t,e,n){let o=this.activeJobs.get(t);return o?(o.numberRecordsProcessed=e,o.numberRecordsFailed=n,!0):!1}updateTotalRecords(t,e){let n=this.activeJobs.get(t);return n?(n.totalRecords=e,!0):!1}getJob(t){return this.activeJobs.get(t)}getActiveJobs(){return Array.from(this.activeJobs.values()).filter(t=>t.state==="UploadComplete"||t.state==="InProgress")}getCompletedJobs(){return Array.from(this.activeJobs.values()).filter(t=>t.state==="JobComplete"||t.state==="Failed"||t.state==="Aborted")}canStartNewJob(){return this.getActiveJobs().length<this.maxConcurrentJobs}removeJob(t){return this.activeJobs.delete(t)}get totalJobs(){return this.activeJobs.size}purgeCompletedJobs(){let t=Array.from(this.activeJobs.entries()).filter(([,e])=>["JobComplete","Failed","Aborted"].includes(e.state));if(t.length>this.maxCompletedJobs){let e=t.slice(0,t.length-this.maxCompletedJobs);for(let[n]of e)this.activeJobs.delete(n)}}clear(){this.activeJobs.clear()}};function xn(r,t){let e=et(r,t);if(e.state==="Open")throw new Error(`Bulk API job ${r||"(no id)"} is still open after its close was sent`);return{state:e.state,...e.numberRecordsProcessed!==void 0?{numberRecordsProcessed:e.numberRecordsProcessed}:{},...e.errorMessage?{errorMessage:e.errorMessage}:{}}}function Me(r){return{bulk2:{createJob:t=>{let e=r.bulk2.createJob(t);return{get id(){return e.id},open:async()=>{await e.open()},uploadData:n=>e.uploadData(n),close:()=>e.close(),abort:()=>e.abort(),check:async()=>xn($t(e)??"",await e.check()),getAllResults:()=>e.getAllResults()}},job:(t,{id:e})=>{let n=r.bulk2.job(t,{id:e});return{check:async()=>et(e,await n.check()),getSuccessfulResults:()=>n.getSuccessfulResults(),getAllResults:()=>n.getAllResults(),abort:()=>n.abort()}}}}}var qt=100,zt=2e3,Un=20,$n=20,Hn=Z({name:x(),label:x(),type:x(),createable:M().optional(),updateable:M().optional(),nillable:M().optional(),defaultedOnCreate:M().optional(),aggregatable:M().optional(),groupable:M().optional(),filterable:M().optional(),nameField:M().optional(),autoNumber:M().optional(),calculated:M().optional(),referenceTo:ae(x()).optional()}).loose(),ee=Z({name:x(),label:x(),queryable:M().optional(),updateable:M().optional(),deletable:M().optional(),fields:ae(Hn),childRelationships:ae(Z({childSObject:x(),field:x(),cascadeDelete:M().optional(),restrictedDelete:M().optional()}).loose()).optional()}).loose(),Jn=Pt(x(),Et()),qn=Z({k:Ie([x(),Qe(),M()]).nullable(),n:Qe().int().nonnegative()}).loose();function zn(r){return(r.createable===!0||r.updateable===!0)&&r.type!=="boolean"}function Xr(r){return r.groupable===!0&&(zn(r)||r.nameField===!0)}function Wn(r,t){return t.createable===!0&&t.nillable===!1&&t.defaultedOnCreate!==!0||Ct(r,t.name)}function Le(r,t,e){let n=C(e);r.some(o=>o.check===t&&o.message===n)||r.push({check:t,message:n})}async function eo(r,t,e,n){let o=new Map,s=[],a=[],i=(f,u)=>{s.push({fieldApiName:f.name,label:f.label,reason:u})},d=e.filter(f=>f.aggregatable===!0),l=e.filter(f=>f.aggregatable!==!0&&f.filterable===!0);for(let f of e)f.aggregatable!==!0&&f.filterable!==!0&&i(f,"not-countable");if(n===0)for(let f of[...d,...l])o.set(f.name,0);else{for(let f=0;f<d.length;f+=qt){let u=d.slice(f,f+qt);try{let g=u.map(R=>`COUNT(${j(R.name)})`).join(", "),m=await r.query(`SELECT ${g} FROM ${t}`),h=Jn.parse(m.records[0]??{});u.forEach((R,b)=>{let w=h[`expr${b}`];if(typeof w!="number")throw new Error(`The org answered no count for ${t}.${R.name}.`);o.set(R.name,w)})}catch(g){Le(a,"fill",g);for(let m of u)o.delete(m.name),i(m,"refused")}}for(let[f,u]of l.entries()){if(f>=$n){i(u,"query-budget");continue}try{let g=await r.query(`SELECT COUNT() FROM ${t} WHERE ${j(u.name)} != null`);o.set(u.name,g.totalSize)}catch(g){Le(a,"fill",g),i(u,"refused")}}}return{fields:e.filter(f=>o.has(f.name)).map(f=>({fieldApiName:f.name,label:f.label,filled:o.get(f.name)??0,required:Wn(t,f)})).sort((f,u)=>f.filled-u.filled||f.fieldApiName.localeCompare(u.fieldApiName)),unmeasured:s,errors:a}}async function to(r,t,e,n,o){let s=[],a=n?e.find(d=>d.name.toLowerCase()===n.toLowerCase()):e.find(d=>d.name==="Email")??e.find(d=>d.nameField===!0);if(!a)return n&&s.push({check:"duplicates",message:`${t} has no field ${n} the org can group records by.`}),{duplicates:null,errors:s};let i={keyField:a.name,keyLabel:a.label,groups:[],groupCount:0,recordCount:0,truncated:!1};if(o===0)return{duplicates:i,errors:s};try{let d=await Vn(r,t,a.name),l=d.rows.map(c=>({value:String(c.value),count:c.count}));return{duplicates:{...i,groups:l.slice(0,Un),groupCount:l.length,recordCount:l.reduce((c,f)=>c+f.count,0),truncated:d.truncated},errors:s}}catch(d){return Le(s,"duplicates",d),{duplicates:null,errors:s}}}async function Vn(r,t,e){let n=j(e),o=await r.query(`SELECT ${n} k, COUNT(Id) n FROM ${t} WHERE ${n} != null GROUP BY ${n} HAVING COUNT(Id) > 1 ORDER BY COUNT(Id) DESC LIMIT ${zt}`),s=[];for(let a of o.records){let i=qn.safeParse(a);!i.success||i.data.k===null||s.push({value:i.data.k,count:i.data.n})}return{rows:s,truncated:o.records.length>=zt}}async function no(r,t,e,n,o){let s=[];if(!e.some(a=>a.name==="LastModifiedDate"&&a.filterable===!0))return{stale:null,errors:s};if(o===0)return{stale:{days:n,records:0},errors:s};try{let a=await r.query(`SELECT COUNT() FROM ${t} WHERE LastModifiedDate < LAST_N_DAYS:${n}`);return{stale:{days:n,records:a.totalSize},errors:s}}catch(a){return Le(s,"stale",a),{stale:null,errors:s}}}var tt=1e4,je=5e4,Wt="DELETE_FAILED",nt="UNABLE_TO_LOCK_ROW",Vt=3,Kn=2e3,Kt="FEATURENOTENABLED",rt="ContentVersion",Qt="ContentDocument",ot=new Set([rt,Qt]);async function he(r,t,e,n,o="delete"){let s=!1,a={},i=0,d=0,l=(g,m)=>(d+=g,m()),c={bulk2:{createJob:g=>{let m=r.bulk2.createJob(g);return{get id(){return m.id},open:()=>l(1,()=>m.open()),uploadData:h=>l(1,()=>m.uploadData(h)),close:async()=>{await l(1,()=>m.close()),s=!0},abort:()=>l(1,()=>m.abort()),check:async()=>{let h=await l(1,()=>m.check());return a={state:h.state,message:h.errorMessage},h},getAllResults:async()=>{let h=await l(Jt,()=>m.getAllResults());return i=Array.isArray(h)?h.length:(h.successfulResults?.length??0)+(h.failedResults?.length??0),h}}}}},f;try{f=await new Ht().executeBulk({connection:c,bulkManager:new Ne(1),...n?{signal:n}:{}},t,o,e.map(g=>({Id:g})))}catch(g){if(!s){let m=g?.errorCode;return{kind:"untouched",reason:C(g),...typeof m=="string"&&m!==""?{code:m}:{},requests:d}}throw g}if(f.aborted)return{kind:"aborted",requests:d};if(a.state!=="JobComplete"&&i===0)return{kind:"untouched",reason:a.message||`job ${a.state??"not complete"}`,requests:d};let u=new Map(f.outcomes.map(g=>[g.recordIndex,g]));return{kind:"answered",requests:d,rows:e.map((g,m)=>{let h=u.get(m);return h?.success?{success:!0}:{success:!1,error:h?.error??"The job gave no result for it."}})}}function po(r,t){let e=Me(r);return{...Ce(r,t),queryDeleted:async n=>({records:(await r.query(n,{scanAll:!0})).records}),bulkDestroy:(n,o,s)=>he(e,n,o,s),bulkHardDestroy:(n,o,s)=>he(e,n,o,s,"hardDelete")}}var st=Z({success:M(),errors:ae(Ie([Z({statusCode:x().optional(),errorCode:x().optional(),message:x().optional()}).loose(),x()])).optional()}).loose();function ne(r){return r.slice(0,15)}function ve(r){return typeof r=="string"?void 0:r.statusCode??r.errorCode}function it(r){if(typeof r=="string")return r;let t=ve(r),e=r.message??"";return t&&e?`${t}: ${e}`:t||e||"The org gave no reason."}function de(r){return async t=>(await r.query(t)).records.filter(n=>typeof n=="object"&&n!==null)}function Qn(r){return new Promise(t=>setTimeout(t,r))}function Gn(r){let t=Kn*2**r;return Math.floor(t/2+Math.random()*(t/2))}async function Gt(r,t,e,n){let o=[...e];for(let s=0;s<Vt;s++){let a=o.flatMap((d,l)=>d.kind==="refused"&&d.locked===!0?[l]:[]);if(a.length===0||n.stopped?.()===!0||(await(n.wait??Qn)(Gn(s)),n.stopped?.()===!0))break;let i=await t(a.map(d=>r[d]));if(i===void 0)break;a.forEach((d,l)=>{let c=i[l];c&&(o[d]={...c,lockResends:s+1})})}return o}async function at(r,t,e,n={}){if(t===rt)return rr(r,e,n);let o=s=>Yn(r,t,s);return Gt(e,o,await o(e),n)}async function Yn(r,t,e){let n;try{n=await r.destroy(t,[...e])}catch(s){let a=C(s);return e.map(()=>({kind:"refused",reason:a,dependency:!1}))}let o=Array.isArray(n)?n:[n];return e.map((s,a)=>{let i=st.safeParse(o[a]);if(i.success&&i.data.success)return{kind:"deleted"};let d=i.success?i.data.errors??[]:[];if(d.some(c=>ve(c)==="ENTITY_IS_DELETED"))return{kind:"gone"};let l=d.length>0&&d.every(c=>ve(c)===nt);return{kind:"refused",reason:d.length>0?it(d[0]):"The org gave no reason.",dependency:d.some(c=>ve(c)===Wt),...l?{locked:!0}:{}}})}async function Zn(r,t,e,n="recycle",o={}){let s=n==="hard"?r.bulkHardDestroy?.bind(r):r.bulkDestroy?.bind(r);if(s===void 0)return n==="hard"?{hardRefused:Xn}:"untouched";let a=async d=>{let l;try{l=await s(t,d,o.signal)}catch(f){let u=C(f);return d.map(()=>({kind:"refused",reason:u,dependency:!1}))}if(l.kind==="aborted")return"aborted";if(l.kind==="untouched"){if(n!=="hard")return"untouched";if(l.code===Kt)return{hardRefused:er(l.reason)};let f=`Not deleted for good: the job was not handed over \u2014 ${l.reason}`;return d.map(()=>({kind:"refused",reason:f,dependency:!1}))}let{rows:c}=l;return d.map((f,u)=>{let g=c[u];if(g?.success===!0)return{kind:"deleted"};let{code:m,message:h}=nr(g?.error??"");return m==="ENTITY_IS_DELETED"?{kind:"gone"}:{kind:"refused",reason:m&&h?`${m}: ${h}`:g?.error||m||h||"The org gave no reason.",dependency:m===Wt,...m===nt?{locked:!0}:{}}})},i=await a(e);return Array.isArray(i)?Gt(e,async d=>{let l=await a(d);return Array.isArray(l)?l:void 0},i,o):i}var Xn="Records cannot be deleted for good through this connection: nothing was sent.";function er(r){return`The user SandForge connects as may not delete records for good in this org: Salesforce refused the job before it held a record (${Kt}: ${r}). Nothing was deleted for good, and nothing was sent to the recycle bin instead.`}var tr="A file is never deleted for good: that takes a Bulk API job, which no file was ever sent by. Not sent.";function nr(r){let t=/^([A-Z][A-Z0-9_]*):([\s\S]*?)(?::(?:--|[\w.,]+))?$/.exec(r.trim());return t?{code:t[1],message:t[2].trim()}:{message:r.trim()}}async function rr(r,t,e){let n;try{n=await L(r,rt,["ContentDocumentId"],t)}catch(d){let l=C(d);return t.map(()=>({kind:"refused",reason:l,dependency:!1}))}let o=new Map;for(let d of n)typeof d.Id=="string"&&typeof d.ContentDocumentId=="string"&&o.set(ne(d.Id),d.ContentDocumentId);let s=[...new Set(o.values())],a=s.length>0?await at(r,Qt,s,e):[],i=new Map(s.map((d,l)=>[d,a[l]]));return t.map(d=>{let l=o.get(ne(d));return l===void 0?{kind:"gone"}:i.get(l)??{kind:"refused",reason:"The org gave no answer for its document.",dependency:!1}})}function Yt(r){let t=[];for(let e=0;e<r.length;e+=z)t.push({ids:r.slice(e,e+z),byJob:!1});return t}function Zt(r,t,e,n="recycle"){return ot.has(t)?!1:n==="hard"||r.bulkDestroy!==void 0&&e>=tt}async function or(r,t,e,n="recycle"){let o=[],s=!ot.has(t)&&(n==="hard"||r.bulkDestroy!==void 0),a=d=>{if(d.length===0)return;if(!s||n!=="hard"&&d.length<tt){o.push(...Yt(d));return}let l=Math.ceil(d.length/Math.ceil(d.length/je));for(let c=0;c<d.length;c+=l)o.push({ids:d.slice(c,c+l),byJob:!0})};if(!Ee(t)||e.length===0)return a(e),o;let i=new Set;try{i=new Set([...await pe(de(r),e)].map(ne))}catch{}return a(e.filter(d=>!i.has(ne(d)))),a(e.filter(d=>i.has(ne(d)))),o}function Xt(r){return{objectApiName:r,op:"delete"}}async function en(r,t,e,n,o){let s={stopped:o.stopped,...o.wait?{wait:o.wait}:{}},{stopped:a}=await Ut(e,{key:Xt(t),sizes:n.sizes,allowance:n.allowance,beforeEachSend:()=>o.stopped()?"stop":void 0,send:async i=>({answers:await at(r,t,i,s)}),limited:i=>i?.kind==="refused"?Lt([i.reason]):void 0,settle:(i,d,l,c)=>{let f=[],u=[];i.forEach((g,m)=>{if(l.has(m))return;let h=d[m]??{kind:"refused",reason:"The org gave no answer for it.",dependency:!1},R=c.get(m);f.push(g),u.push(R!==void 0&&h.kind==="refused"?{...h,dependency:!1,limit:R}:h)}),f.length>0&&o.settle(f,u)}});return a!==void 0}function dt(r,t){let e=Xt(r),n=t.sizes.report(e);if(!n)return[];let o=[];return n.rows+n.alone+n.notSplit+n.keptWhole>0&&o.push(Bt(n)),n.notSplit>0&&o.push(xt(n.notSplit,Ft(t.allowance,e),"removal")),n.keptWhole>0?o.push(_t):n.alone>0&&o.push(Tt),o}function tn(r){let t=0,e=0,n=0,o=0;for(let a of r)t++,a==="deleted"?e++:a==="gone"?n++:o++;if(t===0)return[];let s=[e>0?`${e} deleted`:"",n>0?`${n} already gone`:"",o>0?`${o} still refused`:""].filter(Boolean);return[`The org could not lock ${t} record(s) (${nt}), each sent again up to ${Vt} times, a wait before each: ${s.join(", ")}.`]}async function nn(r,t,e,n){let o=n.mode??"recycle";if(o==="hard"&&ot.has(t))return e.length>0&&n.settle(e,e.map(()=>({kind:"refused",reason:tr,dependency:!1}))),{stopped:!1};let s=n.wait?{wait:n.wait}:{},a=await or(r,t,e,o);for(let i=a.shift();i!==void 0;i=a.shift()){let{ids:d,byJob:l}=i;if(n.stopped())return{stopped:!0};if(await n.prepare?.(d),!l){if(await en(r,t,d,n.splitting,{stopped:n.stopped,settle:n.settle,...s}))return{stopped:!0};continue}let c=await Zn(r,t,d,o,{stopped:n.stopped,...s,...n.signal?{signal:n.signal}:{}});if(c==="aborted")return{stopped:!0};if(c==="untouched"){a.unshift(...Yt(d));continue}if(!Array.isArray(c))return{stopped:!0,hardRefused:c.hardRefused};n.settle(d,c)}return{stopped:!1}}async function rn(r,t){for(let e=0,n=!0;n;e++){n=!1;for(let o of r){let s=t.idsOf(o,e);if(s.length===0)continue;if(t.stopped())return!0;let a=t.deleted(o);if(await t.send(o,s,e))return!0;t.deleted(o)>a&&(n=!0)}}return!1}async function Te(r,t){let e=new Set(t.map(a=>a.objectApiName)),n=new Map;for(let{objectApiName:a}of t){let i;try{i=(ee.parse(await r.describe(a)).childRelationships??[]).map(l=>l.childSObject)}catch{continue}for(let d of i){if(d===a||!e.has(d))continue;let l=n.get(d)??new Set;l.add(a),n.set(d,l)}}let o=[...t],s=[];for(;o.length>0;){let a=o.findIndex(i=>!o.some(d=>d!==i&&n.get(d.objectApiName)?.has(i.objectApiName)));s.push(...o.splice(a>=0?a:0,1))}return s}async function ct(r,t,e){if(r.length===0)return{gone:[],unchecked:[]};let n;try{n=await t(r)}catch(a){return{gone:[],unchecked:[...r],failure:C(a)}}let o=new Set(n.map(a=>ne(String(a.Id)))),s=r.filter(a=>!o.has(ne(a)));return{gone:s.filter(e),unchecked:s.filter(a=>!e(a))}}function sr(r){return r.filter(t=>me[t]!==void 0&&!Ze.has(t))}async function lt(r,t,e,n,o,s){let a=de(r),i=[];for(let{objectApiName:d}of t){let l=me[d];if(!l||Ze.has(d))continue;let c;for await(let f of e.pages(d)){let u=f.filter(w=>n(d,w));if(u.length===0)continue;if(o())return{drafted:i,cancelled:!0};c??=await Pe(a,l);let g=c,m=g?.draft;if(!g||!m)break;let h=await s(d,u),R;try{R=await L(r,d,["Status"],u)}catch{continue}let b=R.filter(w=>typeof w.Id=="string"&&!h.has(w.Id.slice(0,15))).filter(w=>{let k=g.categoryOf.get(String(w.Status));return k!==void 0&&k!=="Draft"}).map(w=>({objectApiName:d,id:String(w.Id),draft:m,status:String(w.Status)}));for(let w=0;w<b.length;w+=z){if(o())return{drafted:i,cancelled:!0};let k=b.slice(w,w+z);i.push(...k);try{await r.update(d,k.map(({id:I})=>({Id:I,Status:m})))}catch{}}}}return{drafted:i,cancelled:!1}}function So(r,t,e,n){if(e)return`${r} ${e.id}: ${t}`;let o=n.filter(s=>s.objectApiName===r).map(s=>`${s.id} (${s.status})`);return o.length>0?`${r}: ${t} Set to Draft, with the status each had: ${o.join(", ")}.`:`${r}: ${t}`}async function on(r,t,e){let n=[...new Set(t.map(o=>o.objectApiName))];for(let o of n){let s=t.filter(c=>c.objectApiName===o),a=new Map(s.map(c=>[c.id.slice(0,15),c])),i=s.map(c=>c.id),d;try{d=await L(r,o,["Status"],i)}catch(c){e.note(o,`Status set to ${s[0].draft} for the delete, and not read back to be restored: ${C(c)}`,!0);continue}let l=d.flatMap(c=>{let f=typeof c.Id=="string"?a.get(c.Id.slice(0,15)):void 0;return f&&c.Status===f.draft?[f]:[]});for(let c=0;c<l.length;c+=z){let f=l.slice(c,c+z),u;try{u=await r.update(o,f.map(({id:m,status:h})=>({Id:m,Status:h})))}catch(m){u=f.map(()=>({success:!1,errors:[C(m)]}))}let g=Array.isArray(u)?u:[u];f.forEach(({draft:m,status:h},R)=>{let b=st.safeParse(g[R]);if(b.success&&b.data.success){e.note(o,`Status set to ${m} for the delete, then back to ${h}.`,!1,f[R]);return}let w=b.success?b.data.errors??[]:[],k=w.length>0?it(w[0]):"The org gave no reason.";e.note(o,`Status set to ${m} for the delete, and left there: the org refused ${h} back \u2014 ${k}`,!0,f[R])})}}}var le="DuplicateRecordSet",ir="DuplicateRecordItem",_e=2e3,ar=999,dr=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function T(r){return r.slice(0,15)}function sn(r){return new Date(r).toISOString().replace(/\.\d{3}Z$/,"Z")}function ut(r){return typeof r=="string"?Date.parse(r):Number.NaN}async function an(r,t){return(await cr(r,t)).map(e=>({id:e.id,modified:lr(e,t)}))}async function cr(r,t){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||!dr.test(t.user))return[];let e;try{let l=await r.query(`SELECT Id, CreatedDate, LastModifiedDate, LastModifiedById FROM ${le} WHERE CreatedDate >= ${sn(t.start-2e3)} AND CreatedDate <= ${sn(t.end+6e4)} LIMIT ${_e}`);if(l.records.length>=_e)return[];e=l.records.filter(c=>typeof c=="object"&&c!==null)}catch{return[]}let n=e.flatMap(l=>typeof l.Id=="string"?[l.Id]:[]);if(n.length===0)return[];let o=new Map,s=new Map,a=new Map;try{for(let l of H(n)){let c=await r.query(`SELECT Id, RecordId, DuplicateRecordSetId, CreatedDate FROM ${ir} WHERE DuplicateRecordSetId IN (${l}) LIMIT ${_e}`);if(c.records.length>=_e)return[];for(let f of c.records){let u=f??{},g=u.DuplicateRecordSetId,m=u.RecordId;if(typeof g!="string")continue;let h=ut(u.CreatedDate);if(Number.isFinite(h)&&!(h<=(a.get(T(g))??Number.NaN))&&a.set(T(g),h),typeof m!="string"||!t.has(T(m))){let R=o.get(T(g))??new Set;R.add(typeof m=="string"?T(m):`item ${String(u.Id)}`),o.set(T(g),R)}else s.set(T(g),[...s.get(T(g))??[],T(m)])}}}catch{return[]}let i=T(t.user),d=(l,c)=>{let f=o.get(l)?.size??0;return s.has(l)?f<=1:f===0&&typeof c=="string"&&T(c)===i};return e.flatMap(l=>typeof l.Id=="string"&&d(T(l.Id),l.LastModifiedById)?[{id:l.Id,created:ut(l.CreatedDate),modified:ut(l.LastModifiedDate),...typeof l.LastModifiedById=="string"?{modifiedBy:l.LastModifiedById}:{},names:s.get(T(l.Id))??[],...a.has(T(l.Id))?{itemsMade:a.get(T(l.Id))}:{}}]:[])}function lr(r,t){if((r.modifiedBy!==void 0?T(r.modifiedBy):"")===T(t.user)&&r.modified<=t.end+6e4)return Math.min(r.modified,t.end);let n=t.end+6e4;return r.names.length>0&&r.created<=n&&r.modified<=n&&(r.modified===r.created||r.modified<=(r.itemsMade??Number.NaN)+ar)?Math.min(r.modified,t.end):r.modified}async function dn(r,t,e,n="recycle"){let o=j(t),s=new Set;try{for(let a of H(e)){let i=await r.queryDeleted(`SELECT Id FROM ${o} WHERE Id IN (${a}) AND IsDeleted = true`);for(let d of i.records){let l=d?.Id;typeof l=="string"&&s.add(l.slice(0,15))}}}catch(a){return{error:C(a)}}return{deleted:s,inBin:n!=="hard"}}var ur=/__kav$/i;function ye(r){return ur.test(r)}function ln(r){return r.replace(/v$/i,"")}var ft="Kept: its article holds a version the run did not write \u2014 a draft begun on it, or a version published since \u2014 which deleting the article would take with it. A removal that takes what changed since the run takes it too.",fr={statusCode:"ENTITY_IS_DELETED",message:"The version is no longer in the org: it went with its article."},cn=" AND IsLatestVersion = false AND PublishStatus = 'Archived'",gr="An article version is deleted through its article, over REST.",mr={success:!1,errors:[{message:"The org gave no reason."}]};function J(r){return r.slice(0,15)}function un(r,t){let e=r.bulkDestroy?.bind(r);return{query:n=>r.query(n),queryDeleted:n=>r.queryDeleted(n),update:(n,o)=>r.update(n,o),serverTime:()=>r.serverTime(),userId:()=>r.userId(),describeGlobal:()=>r.describeGlobal(),describe:n=>ye(n)?pr(r,n):r.describe(n),destroy:(n,o)=>ye(n)?hr(r,n,o,t):r.destroy(n,o),...e?{bulkDestroy:(n,o,s)=>ye(n)?Promise.resolve({kind:"untouched",reason:gr,requests:0}):e(n,o,s)}:{}}}async function pr(r,t){let e=await r.describe(t);if(typeof e!="object"||e===null)return e;let n;try{n=(await r.describe(ln(t)))?.deletable}catch{n=void 0}let o={...e};return delete o.deletable,typeof n=="boolean"?{...o,deletable:n}:o}async function fn(r,t,e){let n=j(t),o=new Map,s=new Map,a=(d,l)=>{for(let c of d){let f=c;if(typeof f?.Id!="string"||typeof f.KnowledgeArticleId!="string")continue;l?.set(J(f.Id),f.KnowledgeArticleId);let u=J(f.KnowledgeArticleId),g=s.get(u)??new Set;g.add(J(f.Id)),s.set(u,g)}};for(let d of["",cn])for(let l of H(e)){let c=await r.query(`SELECT Id, KnowledgeArticleId FROM ${n} WHERE Id IN (${l})${d}`);a(c.records,o)}let i=[...new Set(o.values())];for(let d of["",cn])for(let l of H(i)){let c=await r.query(`SELECT Id, KnowledgeArticleId FROM ${n} WHERE KnowledgeArticleId IN (${l})${d}`);a(c.records)}return{articleOf:o,versions:s}}function gn({articleOf:r,versions:t},e,n){if(n.includeChanged)return new Set;let o=new Set(e.map(J)),s=a=>[...t.get(a)??[]].some(i=>!o.has(i));return new Set([...r.values()].map(J).filter(s))}async function mn(r,t,e,n){let o=await fn(r,t,e),s=gn(o,e,n);return new Set(e.map(J).filter(a=>{let i=o.articleOf.get(a);return i!==void 0&&s.has(J(i))}))}async function hr(r,t,e,n){let o=await fn(r,t,e),{articleOf:s}=o,a=[...new Set(s.values())],i=gn(o,e,n),d=a.filter(c=>!i.has(J(c))),l=new Map;if(d.length>0){let c;try{c=await r.destroy(ln(t),d)}catch(u){let g=C(u);c=d.map(()=>({success:!1,errors:[{message:g}]}))}let f=Array.isArray(c)?c:[c];d.forEach((u,g)=>l.set(J(u),f[g]))}return e.map(c=>{let f=s.get(J(c));return f===void 0?{success:!1,errors:[fr]}:i.has(J(f))?{success:!1,errors:[{message:ft}]}:l.get(J(f))??mr})}var xe="Quote",Re="QuoteLineItem",be="Opportunity",we="OpportunityLineItem",pn=2e3;function yr(r){return r.slice(0,15)}function hn(r){return typeof r=="string"?Date.parse(r):Number.NaN}function F(r,t){let e=r[t];return typeof e=="string"&&e!==""?yr(e):void 0}function mt(r,t){return r.has(t)||r.otherParts?.has(t)===!0}function br(r,t){let e=new Set,n=new Set;for(let g of r.syncing){let m=F(g,"Id"),h=F(g,"SyncedQuoteId");!m||!h||!mt(t,m)||!t.has(h)||(e.add(h),n.add(m))}if(e.size===0)return[];let o=r.quoteLines.filter(g=>{let m=F(g,"QuoteId");return m!==void 0&&e.has(m)&&F(g,"Id")!==void 0}),s=r.opportunityLines.filter(g=>{let m=F(g,"OpportunityId");return m!==void 0&&n.has(m)&&F(g,"Id")!==void 0}),a=g=>F(g,"CreatedById"),i=(g,m)=>{let h=F(g,"Id");if(!h||mt(t,h)||!m)return!1;let R=t.user??a(m),b=hn(g.CreatedDate);return R!==void 0&&a(g)===R&&b>=t.start&&b<=t.end},d=g=>({id:String(g.Id),modified:hn(g.LastModifiedDate)}),l=new Map(s.flatMap(g=>{let m=F(g,"Id");return m&&t.has(m)?[[m,g]]:[]})),c=new Map;for(let g of o){let m=F(g,"Id"),h=F(g,"OpportunityLineItemId");m&&h&&t.has(m)&&!c.has(h)&&c.set(h,g)}let f=o.filter(g=>{let m=F(g,"OpportunityLineItemId");return i(g,m?l.get(m):void 0)}).map(d),u=s.filter(g=>{let m=F(g,"Id");return i(g,m?c.get(m):void 0)}).map(d);return[...f.length>0?[{objectApiName:Re,copies:f}]:[],...u.length>0?[{objectApiName:we,copies:u}]:[]]}function yn(r,t=[]){let e=new Set(r),n=e.has(be)||new Set(t).has(be);if(!e.has(xe)||!n)return[];let o=e.has(Re),s=e.has(we);return o===s?[]:[o?we:Re]}async function gt(r,t,e,n,o){let s=e.map(j).join(", "),a=[];for(let i of H(o)){let d=await r.query(`SELECT ${s} FROM ${j(t)} WHERE ${j(n)} IN (${i}) LIMIT ${pn}`);if(d.records.length>=pn)throw new Error(`More ${t} records than one read takes.`);for(let l of d.records)typeof l=="object"&&l!==null&&a.push(l)}return a}async function bn(r,t,e,n){let o=n.has(Re)||n.has(we),s=n.has(be)||t.otherParts?.objects.has(be)===!0;if(e.length===0||!s||!o)return[];try{let i=(await gt(r,be,["Id","SyncedQuoteId"],"SyncedQuoteId",e)).filter(c=>{let f=F(c,"Id");return f!==void 0&&mt(t,f)});if(i.length===0)return[];let d=await gt(r,Re,["Id","QuoteId","OpportunityLineItemId","CreatedById","CreatedDate","LastModifiedDate"],"QuoteId",[...new Set(i.map(c=>String(c.SyncedQuoteId)))]),l=await gt(r,we,["Id","OpportunityId","CreatedById","CreatedDate","LastModifiedDate"],"OpportunityId",i.map(c=>String(c.Id)));return br({syncing:i,quoteLines:d,opportunityLines:l},t)}catch{return[]}}var Rr=5,Se=4,Fe=2e3,wr=4,He=[["CreatedDate","LastModifiedDate","CreatedById","LastModifiedById"],["CreatedDate","LastModifiedDate","CreatedById"],["SystemModstamp"],[]],ht=1e4,Sr="005",Rn="ContentDocumentLink",kr="ContentDocument",Or="ContentVersion",Ar=5;function Je(r){let t=new Set(r.flatMap(n=>n.ids.map(y))),e=new Map;for(let{objectApiName:n,ids:o}of r)e.set(n,[...e.get(n)??[],...o]);return{objects:[...e].map(([n,o])=>({objectApiName:n,count:o.length})),pages:async function*(n){let o=e.get(n);o&&o.length>0&&(yield o)},has:n=>t.has(n)}}function re(r){return!Array.isArray(r)}function Zo(r){return re(r)?r.objects.reduce((t,e)=>t+e.count,0):r.reduce((t,e)=>t+e.ids.length,0)}function Xo(r){return(re(r)?r.objects:r).map(t=>t.objectApiName)}var qe=class{bits=new Uint8Array(0);add(t){let e=t>>3;if(e>=this.bits.length){let n=new Uint8Array(Math.max(e+1,this.bits.length*2,64));n.set(this.bits),this.bits=n}this.bits[e]|=1<<(t&7)}has(t){let e=t>>3;return e<this.bits.length&&(this.bits[e]&1<<(t&7))!==0}},yt=class{dates=new Float64Array(0);set(t,e){if(t>=this.dates.length){let n=new Float64Array(Math.max(t+1,this.dates.length*2,64)).fill(Number.NaN);n.set(this.dates),this.dates=n}this.dates[t]=e}at(t){return t<this.dates.length?this.dates[t]:Number.NaN}latestWithin(t,e){let n=Number.NaN;for(let o of this.dates)o>=t&&o<=e&&!(o<=n)&&(n=o);return n}};function ue(r,t){return typeof r=="string"&&t.has(y(r))}var wn=[{created:"CreatedDate",modified:"LastModifiedDate"},{modified:"SystemModstamp"}],pt={ContentDocumentLink:{ends:["ContentDocumentId","LinkedEntityId"],cameWithRun:(r,t)=>{let e=r.LinkedEntityId;return ue(r.ContentDocumentId,t)&&(ue(e,t)||typeof e=="string"&&e.startsWith(Sr))}},DuplicateRecordItem:{ends:["RecordId"],cameWithRun:(r,t)=>ue(r.RecordId,t)},ContentVersion:{ends:["ContentDocumentId"],cameWithRun:(r,t)=>ue(r.ContentDocumentId,t)},[te.objectApiName]:{ends:[te.parent,te.field],cameWithRun:(r,t)=>r[te.field]===te.value&&ue(r[te.parent],t)}};function es(r,t){return{...Ce(r,t),serverTime:async()=>(await r.soap.getServerTimestamp()).timestamp,userId:async()=>(await r.soap.getUserInfo()).userId,queryDeleted:async e=>({records:(await r.query(e,{scanAll:!0})).records}),bulkDestroy:(e,n,o)=>he(Me(r),e,n,o)}}function bt(r,t,e){let n=new Map;for(let o of r??[]){let s=St(o.span,[],e);if(Number.isFinite(s.end))for(let a of o[t]??[]){let i=y(a);s.end<=(n.get(i)?.end??Number.NEGATIVE_INFINITY)||n.set(i,s)}}return n}function Dr(r=[],t=[]){if(r.length===0&&t.length===0)return;let e=[...r.map(({plan:n})=>re(n)?n:Je(n)),Je(t)];return{has:n=>e.some(o=>o.has(n))}}function Ir(r=[],t=[]){return new Set([...r.map(({plan:e})=>re(e)?e.objects:e),t].flat().map(e=>e.objectApiName))}function Dn(r,t){return new Map([...bt(r,"wrote",t)].map(([e,{end:n}])=>[e,n]))}function In(r,t){return`The user SandForge connects as may not delete ${r} records in this org: the ${t} record(s) of the run stay, and were not sent.`}function Rt(r,t){return`Not visible: ${r} record(s) found neither in the org nor in its recycle bin, as the user the removal runs as sees them \u2014 out of that user's sight, or deleted for good \u2014 are not counted as removed`+(t?` (the recycle bin could not be read: ${t})`:".")}function Sn(r,t,e){for(let o of r){let s=o.deleted+o.alreadyGone+o.keptChanged+o.keptDependents+o.refused+(o.notVisible??0);o.planned>s&&(o.notReached=o.planned-s)}let n=new Set(r.map(o=>o.objectApiName));for(let{objectApiName:o,count:s}of t)s===0||n.has(o)||(n.add(o),r.push({...new ke(o,s,e(o)).result,notReached:s}));return r}var ts={objects:[],cancelled:!1,gone:[],stamps:{},left:async function*(){}};function y(r){return r.slice(0,15)}function Er(r){return r?.errorCode==="INVALID_FIELD"||/no such column/i.test(C(r))}function Pr(r,t){let e=/no such column '(\w+)'/i.exec(C(r))?.[1],n=He.findIndex((o,s)=>s>t&&(e===void 0||!o.includes(e)));return n===-1?He.length:n}function N(r){return typeof r=="string"?Date.parse(r):Number.NaN}function En(){return{modified:new yt,missing:new Set,firstCreated:Number.NaN,lastCreated:Number.NaN,binned:new Set}}var ke=class{result;notes=[];refused=new Map;unread;held=[];goneAt=new qe;goneLater=new Set;deletedLater=new Set;notVisible=0;notVisibleNote;secondTry=new Set;filesLeft=new Map;automationHeld=new Map;automationHeldAfter=new Set;automationHeldAlong=new Set;tookAlong=new Map;cameAlong=new Map;limitNotes=[];lockResent=new Map;constructor(t,e,n=0){this.result={objectApiName:t,planned:e,deleted:0,alreadyGone:0,keptChanged:0,keptDependents:0,refused:0,heldBy:[],...n>0?{platformCopies:n}:{},unchecked:[],reasons:[]}}note(t){this.notes.includes(t)||this.notes.push(t)}isGone(t,e){return this.goneAt.has(e)||this.goneLater.has(y(t))}waiting(){return[...[...this.refused].filter(([,t])=>t.dependency).map(([t])=>t),...this.held]}refusedSent(){return[...this.refused].filter(([,t])=>t.sent).map(([t])=>t)}refusedToSendAgain(){return[...this.refused].filter(([,t])=>t.sent&&t.limit!==!0).map(([t])=>t)}secondTryNote(){if(this.secondTry.size===0)return[];let t=0,e=0,n=0,o=0;for(let a of this.secondTry){let i=y(a);this.deletedLater.has(i)?t++:this.goneLater.has(i)?e++:this.refused.has(a)?o++:n++}return[`Refused at first, sent again once the rest had gone: ${[t>0?`${t} deleted`:"",e>0?`${e} already gone`:"",n>0?`${n} kept for records that stay`:"",o>0?`${o} refused again`:""].filter(Boolean).join(", ")}.`]}settle(){this.result.keptDependents=this.held.length,this.result.refused=this.refused.size+(this.unread?.count??0),this.notVisible>0&&(this.result.notVisible=this.notVisible),this.held.length===0&&(this.result.heldBy=[]);let t=this.held.flatMap(s=>{let a=this.automationHeld.get(y(s));return a?[a]:[]}),e=this.held.filter(s=>{let a=y(s);return this.automationHeld.has(a)&&this.automationHeldAfter.has(a)}).length,n=this.held.filter(s=>{let a=y(s);return this.automationHeld.has(a)&&this.automationHeldAlong.has(a)}).length;t.length>0?(this.result.heldByAutomation=t.length,e>0?this.result.heldByAutomationAfterRun=e:delete this.result.heldByAutomationAfterRun,n>0?this.result.heldByAutomationAlong=n:delete this.result.heldByAutomationAlong,this.result.automationHolders=[...new Set(t.flatMap(s=>[...s]))]):(delete this.result.heldByAutomation,delete this.result.heldByAutomationAfterRun,delete this.result.heldByAutomationAlong,delete this.result.automationHolders);let o=[...this.notVisibleNote?[this.notVisibleNote]:[],...this.notes,...this.limitNotes,...tn(this.lockResent.values()),...this.secondTryNote(),...this.unread?[this.unread.reason]:[],...[...this.refused.values()].map(s=>s.reason)];return this.result.reasons=[...new Set(o)].slice(0,Rr),this.filesLeft.size>0&&(this.result.filesLeft={count:this.filesLeft.size,names:[...this.filesLeft.values()].slice(0,Ar)}),this.tookAlong.size>0&&(this.result.tookAlong={count:this.tookAlong.size,objects:[...new Set(this.tookAlong.values())]}),this.cameAlong.size>0&&(this.result.cameAlong={count:this.cameAlong.size,objects:[...new Set(this.cameAlong.values())]}),this.result}};async function ns(r,t,e){let n=re(t)?t:Je(t),o=n,s=o.objects.reduce((p,S)=>p+S.count,0),a=new Map,i=p=>a.get(p)??0,d=()=>e.signal?.aborted===!0,l=e.splitting??jt(),c=()=>({objects:Sn([],o.objects,i),cancelled:!0,gone:[],stamps:{},left:()=>An(n)}),f=new Map,u=new Map;for(let{objectApiName:p}of o.objects){let S=En();f.set(p,S);let O=0;for await(let A of o.pages(p)){if(d())return c();let v=A[0];v!==void 0&&!u.has(v.slice(0,3))&&u.set(v.slice(0,3),p);let E=O;if(O+=A.length,S.error!==void 0)continue;let D=await Tr(r,p,A,E,S);if(S.error!==void 0||D.length===0)continue;if(d())return c();let B=await dn(r,p,D);if("error"in B)S.binError=B.error;else for(let q of B.deleted)S.binned.add(q)}}let g=new Map,m=!1,h=r.bulkDestroy?.bind(r),R={query:p=>r.query(p),destroy:(p,S)=>(m=!0,r.destroy(p,S)),...h?{bulkDestroy:(p,S)=>(m=!0,h(p,S,e.signal))}:{},update:(p,S)=>(m=!0,r.update(p,S)),serverTime:()=>r.serverTime(),userId:()=>r.userId(),queryDeleted:p=>r.queryDeleted(p),describeGlobal:()=>r.describeGlobal(),describe:p=>{let S=g.get(p);return S||(S=r.describe(p),g.set(p,S)),S}},b=un(R,{includeChanged:e.includeChanged}),w=await Te(b,o.objects),k=await vr(b,w,(p,S)=>S-(f.get(p)?.missing.size??0)),I=new Set(k.map(p=>p.objectApiName));if(k.length>0&&e.onUndeletable&&e.previewOnly!==!0){if(d())return c();if(!await e.onUndeletable(k))return{...c(),objects:[],undeletable:k,stoppedForUndeletable:!0}}let[P,_]=await Promise.all([xr(b),e.previewOnly===!0?void 0:Fr(b)]),{start:G,end:K}=St(e,f.values(),P.aheadMs);if(d())return c();let oe=Dr(e.otherParts,e.otherPartRecords),ze=Ir(e.otherParts,e.otherPartRecords),Ae=await _r(b,o,{start:G,end:K,...e.runUserId?{user:y(e.runUserId)}:{},...oe?{otherParts:{has:p=>oe.has(p),objects:ze}}:{},undeletable:I,snapshots:f}),We=[];if(e.runUserId&&e.alongAccepted!==!0){let p=await an(b,{has:S=>o.has(S),start:G,end:K,user:e.runUserId});if(p.length>0&&!o.objects.some(S=>S.objectApiName===le)&&await Pn(b,le)){Ae.push({objectApiName:le,copies:p});for(let S of p)We.push(S.id)}}if(Ae.length>0){o=await Br(o,Ae,f,u);for(let{objectApiName:p,copies:S}of Ae)a.set(p,S.length);s=o.objects.reduce((p,S)=>p+S.count,0),w=await Te(b,o.objects)}let Ln=new Map(Object.entries(e.removalStamps??{}).map(([p,S])=>[y(p),N(S)])),vn=Dn(e.laterParts,P.aheadMs),se=new Set;for(let{objectApiName:p}of o.objects){let S=f.get(p);if(!S||S.error!==void 0)continue;let O=0;for await(let A of o.pages(p))for(let v of A){let E=S.modified.at(O++),D=y(v);if(S.missing.has(D))continue;E<=K||E<=(Ln.get(D)??Number.NaN)||E<=(vn.get(D)??Number.NaN)||se.add(D)}}if(e.previewOnly===!0){if(d())return c();let p=new Set,S=await Nr(b,o,w,{snapshots:f,changed:se,undeletable:I,includeChanged:e.includeChanged,stopped:d,copiesOf:i,...e.previewHeld===!0?{held:{notSent:p,check:new Oe(b,{runRecords:o,reached:{has:()=>!1},stays:O=>p.has(O),runStart:G,runEnd:K,removalStart:P.start,removalUser:void 0,earlierRemovals:(e.removalSpans??[]).map(O=>({start:N(O.first),end:N(O.last),user:y(O.userId)})),includeChanged:e.includeChanged,previewing:!0,...e.goesWithParent?{goesWithParent:e.goesWithParent}:{},...e.goesWithParentReadBelow?{goesWithParentReadBelow:!0}:{},...e.alongAccepted?{alongAccepted:e.alongAccepted}:{},...e.runUserId?{runUser:y(e.runUserId)}:{},...e.laterParts?{linkedLater:bt(e.laterParts,"linked",P.aheadMs)}:{},...oe?{otherPartRecords:oe,otherPartObjects:ze}:{}})}}:{}});return S?{...k.length>0?{undeletable:k}:{},objects:[],cancelled:!1,gone:[],stamps:{},left:()=>An(n),preview:S}:c()}let kt=await jr(b,e.otherParts??[],P.aheadMs,d);if(!kt)return c();let Ot=new Set,jn={has:p=>o.has(p)&&Ot.has(u.get(p.slice(0,3))??"")},Ve=new Oe(b,{runRecords:o,reached:jn,stays:p=>se.has(p)&&!e.includeChanged,runStart:G,runEnd:K,removalStart:P.start,removalUser:_,earlierRemovals:(e.removalSpans??[]).map(p=>({start:N(p.first),end:N(p.last),user:y(p.userId)})),includeChanged:e.includeChanged,...e.goesWithParent?{goesWithParent:e.goesWithParent}:{},...e.goesWithParentReadBelow?{goesWithParentReadBelow:!0}:{},...e.alongAccepted?{alongAccepted:e.alongAccepted}:{},...e.alongToDraft?{alongToDraft:e.alongToDraft}:{},...e.runUserId?{runUser:y(e.runUserId)}:{},...e.automationMade?{automationMade:Mn(e.automationMade)}:{},...e.laterParts?{linkedLater:bt(e.laterParts,"linked",P.aheadMs)}:{},...oe?{otherPartRecords:oe,otherPartObjects:ze}:{}});if(d())return c();await e.beforeFirstWrite?.(),e.sweep&&await e.sweep(l)&&(m=!0);let Y=[],At=p=>Y.find(S=>S.result.objectApiName===p);async function*Ke(p,S,O){for(let{objectApiName:A}of S){let v=At(A),E=0;for await(let D of p.pages(A)){let B=D.filter(q=>O(A,q,v?.isGone(q,E++)===!0));B.length>0&&(yield{objectApiName:A,ids:B})}}}let Tn=()=>Ke(o,w,(p,S,O)=>{let A=f.get(p),v=y(S);return A?.modifiedColumn==="LastModifiedDate"&&!A.missing.has(v)&&!se.has(v)&&!O}),De=[],$=async p=>{await on(b,De,{note:(D,B,q)=>{let U=At(D);if(!U){if(!q)return;let W=o.objects.find(V=>V.objectApiName===D);U=new ke(D,W?.count??0,i(D)),Y.push(U)}U.note(B)}});let S=m?await kn(b,Tn(),{start:P.start,user:_}):{},O=[];if(m)for(let D of kt)O.push(await kn(b,D.unchanged(),{start:P.start,user:_}));let A=m?Ur(P,_):void 0,v=[];if(!re(t))for await(let{ids:D}of Ke(n,w,(B,q,U)=>U))for(let B of D)v.push(B);for(let D of Y)D.limitNotes=dt(D.result.objectApiName,l);let E=Y.map(D=>D.settle());return{...k.length>0?{undeletable:k}:{},objects:p?Sn(E,w,i):E,cancelled:p,gone:v,left:()=>Ke(n,n.objects,(D,B,q)=>!q),stamps:S,...A?{span:A}:{},...O.length>0?{otherPartStamps:O}:{},...We.length>0?{duplicateSets:We}:{}}};if(d())return m?$(!0):c();let Dt=async(p,S)=>(await Ve.heldAmong(p,S)).held,It=await lt(b,w,o,(p,S)=>{let O=y(S),A=f.get(p);return A!==void 0&&A.error===void 0&&!I.has(p)&&!A.missing.has(O)&&!(se.has(O)&&!e.includeChanged)},d,Dt);if(De=It.drafted,It.cancelled)return $(!0);if(e.alongToDraft){let p=await lt(b,e.alongToDraft.objects,e.alongToDraft,()=>!0,d,Dt);if(De=[...De,...p.drafted],p.cancelled)return $(!0)}let Q=0;for(let{objectApiName:p,count:S}of w){if(d())return $(!0);let O=new ke(p,S,i(p));Y.push(O),Ot.add(p);let A=f.get(p);if(!A||A.error!==void 0){O.unread={reason:A?.error??"The org gave no reason.",count:S},Q+=S,e.onProgress?.(Q,s,p);continue}if(I.has(p)){let U=0,W=0;for await(let V of o.pages(p))for(let ie of V){let fe=y(ie),Bn=U++;A.missing.has(fe)?A.binned.has(fe)?(O.result.alreadyGone++,O.goneAt.add(Bn)):O.notVisible++:W++}O.notVisible>0&&(O.notVisibleNote=Rt(O.notVisible,A.binError)),W>0&&(O.unread={reason:In(p,W),count:W}),Q+=S,e.onProgress?.(Q,s,p);continue}let v=Zt(b,p,S),E=[],D=new Map,B=async()=>{let U=E,W=D;return E=[],D=new Map,On(b,Ve,O,U,{stopped:d,splitting:l,placeOf:W,onDeleted:V=>{Q+=V,e.onProgress?.(Q,s,p)},onHeld:V=>{Q+=V,e.onProgress?.(Q,s,p)}})},q=0;for await(let U of o.pages(p)){if(d())return $(!0);let W=E.length;for(let V of U){let ie=y(V),fe=q++;A.missing.has(ie)?A.binned.has(ie)?(O.result.alreadyGone++,O.goneAt.add(fe)):O.notVisible++:se.has(ie)&&!e.includeChanged?O.result.keptChanged++:(E.push(V),D.set(ie,fe))}if(O.notVisible>0&&(O.notVisibleNote=Rt(O.notVisible,A.binError)),Q+=U.length-(E.length-W),!(v&&E.length<je)&&await B())return $(!0)}if(v&&E.length>0&&(d()||await B()))return $(!0)}let _n=Y.some(p=>p.result.deleted>0);if(await rn(Y,{stopped:d,idsOf:(p,S)=>{if(S>0)return p.waiting();let O=p.refusedToSendAgain();return O.length>0||_n?[...O,...p.held]:[]},send:async(p,S,O)=>{let A=new Set(O===0?p.refusedToSendAgain():[]),v=await On(b,Ve,p,S,{stopped:d,splitting:l,onSent:E=>{for(let D of E)A.has(D)&&p.secondTry.add(D)}});for(let E of p.held)A.has(E)&&p.secondTry.add(E);return v},deleted:p=>p.result.deleted}))return $(!0);if(e.afterRemoval){if(d())return $(!0);await e.afterRemoval(l)&&(m=!0)}for(let p of Y){if(d())return $(!0);await Lr(b,p,f.get(p.result.objectApiName))}return $(!1)}async function Cr(r,t,e,n,o){let{changed:s,includeChanged:a}=o,i=[];for await(let d of t.pages(e))for(let l of d){let c=y(l);!n.has(c)&&(a||!s.has(c))&&i.push(l)}try{return{kept:await mn(r,e,i,{includeChanged:a})}}catch(d){return{kept:new Set,unread:C(d)}}}async function Nr(r,t,e,n){let o=[],s=new Set,a=new Set;for(let{objectApiName:i,count:d}of e){let l=n.copiesOf(i),c={objectApiName:i,planned:d,toDelete:0,alreadyGone:0,changedSince:0,keptChanged:0,changedBy:{},undeletable:0,notVisible:0,unread:0,...l>0?{platformCopies:l}:{},reasons:[]};o.push(c);let f=n.snapshots.get(i);if(!f||f.error!==void 0){if(c.unread=d,c.reasons.push(f?.error??"The org gave no reason."),n.held)for await(let R of t.pages(i))for(let b of R)n.held.notSent.add(y(b));continue}let u=ye(i)&&!n.undeletable.has(i)?await Cr(r,t,i,f.missing,n):void 0,g=[],m=[],h=R=>{n.held?.notSent.add(R)};for await(let R of t.pages(i))for(let b of R){let w=y(b);f.missing.has(w)?f.binned.has(w)?c.alreadyGone++:c.notVisible++:n.undeletable.has(i)?(c.undeletable++,h(w)):u?.unread!==void 0?(c.unread++,h(w)):n.changed.has(w)?(c.changedSince++,g.push(b),n.includeChanged?(c.toDelete++,m.push(b)):(c.keptChanged++,h(w))):u?.kept.has(w)?(c.changedSince++,c.keptChanged++,h(w)):(c.toDelete++,m.push(b))}if(n.held&&m.length>0){if(n.stopped())return;let R=await n.held.check.heldAmong(i,m),b=m.filter(k=>R.held.has(y(k)));if(b.length>0){c.toDelete-=b.length,c.keptDependents=b.length,c.heldBy=[...R.holders];for(let I of b)n.held.notSent.add(y(I));let k=b.filter(I=>R.byAutomation.has(y(I)));k.length>0&&(c.heldByAutomation=k.length)}let w=new Map;for(let k of m)if(!R.held.has(y(k)))for(let[I,P]of R.cameAlong.get(y(k))??[])a.has(I)||(a.add(I),w.set(I,P));w.size>0&&(c.cameAlong={count:w.size,objects:[...new Set(w.values())]}),R.reason!==void 0&&c.reasons.push(R.reason),R.unchecked.size>0&&c.reasons.push(`Not checked: what hangs from them through ${[...R.unchecked].join(", ")}, which the org deletes along but does not let be read by the record it hangs from.`)}if(u?.unread!==void 0?c.reasons.push(`Its articles could not be read: ${u.unread}`):u!==void 0&&u.kept.size>0&&c.reasons.push(ft),c.notVisible>0&&c.reasons.push(Rt(c.notVisible,f.binError)),c.undeletable>0&&c.reasons.push(In(i,c.undeletable)),!(g.length===0||f.modifiedColumn!=="LastModifiedDate")){if(n.stopped())return;try{let R=await L(r,i,["LastModifiedById"],g,Se);for(let b of R){let w=b.LastModifiedById;typeof w!="string"||w===""||(c.changedBy[w]=(c.changedBy[w]??0)+1,s.add(w))}}catch(R){c.reasons.push(`Who changed them since the run could not be read: ${C(R)}`)}}}if(!n.stopped())return{objects:o,userNames:await Mr(r,[...s])}}async function Mr(r,t){let e={};if(t.length===0)return e;try{for(let n of await L(r,"User",["Name"],[...t].sort()))typeof n.Id=="string"&&typeof n.Name=="string"&&(e[n.Id]=n.Name)}catch{}return e}async function Lr(r,t,e){let{gone:n,unchecked:o,failure:s}=await ct(t.refusedSent(),a=>L(r,t.result.objectApiName,[],a),a=>e!==void 0&&e.error===void 0&&!e.missing.has(y(a)));for(let a of n)t.refused.delete(a),t.goneLater.add(y(a)),t.result.alreadyGone++;o.length>0&&t.note(`Not checked: ${o.length} refused record(s) could not be read back once the rest had gone, to tell whether a parent deleted after them took them along`+(s?` \u2014 ${s}`:"."))}function rs(r,t=[],e={}){return[...new Set([...r,...yn(r,t),...e.userKept===!0&&r.length>0?[le]:[]])]}async function vr(r,t,e){let n=[];for(let{objectApiName:o,count:s}of t){if(o===Or||s===0)continue;let a=e(o,s);if(a!==0)try{let i=ee.safeParse(await r.describe(o));i.success&&i.data.deletable===!1&&n.push({objectApiName:o,records:a})}catch{}}return n}async function kn(r,t,e){let n={},{start:o,user:s}=e;if(s===void 0||!Number.isFinite(o))return n;for await(let{objectApiName:a,ids:i}of t){let d;try{d=await L(r,a,["LastModifiedDate","LastModifiedById"],i)}catch{continue}for(let l of d)typeof l.Id=="string"&&typeof l.LastModifiedDate=="string"&&typeof l.LastModifiedById=="string"&&y(l.LastModifiedById)===s&&N(l.LastModifiedDate)>=o&&(n[l.Id]=l.LastModifiedDate)}return n}async function jr(r,t,e,n){let o=[];for(let s of t){let a=re(s.plan)?s.plan:Je(s.plan),{end:i}=St(s.span,[],e),d=new Map(Object.entries(s.removalStamps??{}).map(([f,u])=>[y(f),N(u)])),l=Dn(s.laterParts,e),c=new Map;if(Number.isFinite(i))for(let{objectApiName:f}of a.objects){let u=new qe,g=0,m=!1;for await(let h of a.pages(f)){if(n())return;let R=g;if(g+=h.length,m)continue;let b;try{b=await L(r,f,["LastModifiedDate"],h,Se)}catch{m=!0;continue}let w=new Map;for(let k of b)typeof k.Id=="string"&&w.set(y(k.Id),N(k.LastModifiedDate));h.forEach((k,I)=>{let P=y(k),_=w.get(P);_!==void 0&&(_<=i||_<=(d.get(P)??Number.NaN)||_<=(l.get(P)??Number.NaN))&&u.add(R+I)})}m||c.set(f,u)}o.push({unchanged:async function*(){for(let{objectApiName:f}of a.objects){let u=c.get(f);if(!u)continue;let g=0;for await(let m of a.pages(f)){let h=m.filter(()=>u.has(g++));h.length>0&&(yield{objectApiName:f,ids:h})}}}})}return o}async function On(r,t,e,n,o){let{objectApiName:s}=e.result,a=await t.heldAmong(s,n);a.reason!==void 0&&e.note(a.reason);for(let u of a.unchecked)e.result.unchecked.includes(u)||e.result.unchecked.push(u);let i=n.filter(u=>a.held.has(y(u)));if(o.placeOf){for(let u of i)e.held.push(u);e.result.heldBy=[...new Set([...e.result.heldBy,...a.holders])]}else e.held=i,e.result.heldBy=[...a.holders];for(let u of i)e.refused.delete(u);for(let u of n){let g=y(u),m=a.byAutomation.get(g);m?e.automationHeld.set(g,m):e.automationHeld.delete(g),m&&a.automationAfter.has(g)?e.automationHeldAfter.add(g):e.automationHeldAfter.delete(g),m&&a.automationAlong.has(g)?e.automationHeldAlong.add(g):e.automationHeldAlong.delete(g)}o.onHeld?.(i.length);let d=n.filter(u=>!a.held.has(y(u))),l=new Map,c=(u,g)=>{u.forEach((m,h)=>{let R=g[h],b=y(m);if((R.lockResends!==void 0||e.lockResent.has(b))&&e.lockResent.set(b,R.kind),R.kind==="refused"){e.refused.set(m,{reason:R.reason,dependency:R.dependency,sent:!0,...R.limit?{limit:!0}:{}});return}e.refused.delete(m);let w=o.placeOf?.get(b);if(w!==void 0?e.goneAt.add(w):e.goneLater.add(b),R.kind==="deleted"){e.result.deleted++,w===void 0&&e.deletedLater.add(b);for(let k of l.get(b)??[])e.filesLeft.set(k.key,k.name);for(let[k,I]of a.along.get(b)??[])e.tookAlong.set(k,I);for(let[k,I]of a.cameAlong.get(b)??[])e.cameAlong.set(k,I)}else e.result.alreadyGone++}),o.onSent?.(u),o.onDeleted?.(u.length)},{stopped:f}=await nn(r,s,d,{stopped:o.stopped,splitting:o.splitting,prepare:async u=>{l=await t.filesOn(u)},settle:c});return f}async function Tr(r,t,e,n,o){let s,a=o.modifiedColumn?wn.filter(({modified:i})=>i===o.modifiedColumn):wn;for(let{created:i,modified:d}of a)try{let c=await L(r,t,i?[i,d]:[d],e,Se),f=new Map;for(let g of c)typeof g.Id=="string"&&f.set(y(g.Id),N(g[d])),i&&(o.firstCreated=Cn(o.firstCreated,N(g[i])),o.lastCreated=wt(o.lastCreated,N(g[i])));o.modifiedColumn=d;let u=[];return e.forEach((g,m)=>{let h=y(g),R=f.get(h);R===void 0&&(o.missing.add(h),u.push(g)),o.modified.set(n+m,R??Number.NaN)}),u}catch(l){s??=C(l)}return o.error=s,o.modifiedColumn=void 0,[]}async function*An(r){for(let{objectApiName:t}of r.objects)for await(let e of r.pages(t))e.length>0&&(yield{objectApiName:t,ids:[...e]})}async function _r(r,t,e){let n=new Set(t.objects.filter(i=>i.count>0).map(i=>i.objectApiName));if(!n.has(xe))return[];let o=[];for await(let i of t.pages(xe))o.push(...i);let s=await bn(r,{has:i=>t.has(i),start:e.start,end:e.end,...e.user!==void 0?{user:e.user}:{},...e.otherParts?{otherParts:e.otherParts}:{}},o,n),a=[];for(let i of s){let{objectApiName:d}=i;if(e.undeletable.has(d))continue;let l=e.snapshots.get(d);if(l){if(l.error!==void 0||l.modifiedColumn!=="LastModifiedDate")continue}else if(!await Pn(r,d))continue;a.push(i)}return a}async function Pn(r,t){try{let e=ee.safeParse(await r.describe(t));return e.success&&e.data.deletable!==!1}catch{return!1}}async function Br(r,t,e,n){let o=new Map(t.map(({objectApiName:i,copies:d})=>[i,d])),s=new Set(t.flatMap(({copies:i})=>i.map(d=>y(d.id)))),a=r.objects.map(i=>{let d=o.get(i.objectApiName);return d?{objectApiName:i.objectApiName,count:i.count+d.length}:i});for(let[i,d]of o){r.objects.some(u=>u.objectApiName===i)||a.push({objectApiName:i,count:d.length});let l=e.get(i);l||(l={...En(),modifiedColumn:"LastModifiedDate"},e.set(i,l));let c=0;for await(let u of r.pages(i))c+=u.length;for(let u of d)l.modified.set(c++,u.modified);let f=d[0]?.id.slice(0,3);f!==void 0&&!n.has(f)&&n.set(f,i)}return{objects:a,pages:async function*(i){yield*r.pages(i);let d=o.get(i);d&&d.length>0&&(yield d.map(l=>l.id))},has:i=>r.has(i)||s.has(i)}}async function xr(r){let t=Date.now(),e=Number.NaN;try{e=N(await r.serverTime())}catch{}return Number.isFinite(e)?{start:Math.floor(e/1e3)*1e3,aheadMs:e-(t+Date.now())/2}:{start:Number.POSITIVE_INFINITY,aheadMs:Number.NaN}}async function Fr(r){try{let t=await r.userId();return typeof t=="string"&&t!==""?y(t):void 0}catch{return}}function Ur(r,t){if(!(t===void 0||!Number.isFinite(r.start)))return{first:new Date(r.start).toISOString(),last:new Date(Date.now()+r.aheadMs+ht).toISOString(),userId:t}}function Cn(r,t){return Number.isNaN(r)||t<r?t:r}function wt(r,t){return Number.isNaN(r)||t>r?t:r}var Nn=999;function $r(r,t,e){let n=Number.NaN;for(let o of r)o.lastCreated>=t&&o.lastCreated<=e&&(n=wt(n,o.lastCreated)),n=wt(n,o.modified.latestWithin(t,e));return n}function St(r,t,e){let n=Hr(r,t,e),o=(r.writtenUntil?.getTime()??Number.NaN)+Nn;return Number.isFinite(n.end)&&o>n.end?{...n,end:o}:n}function Hr(r,t,e){let n=[...t],o=Number.NaN;for(let l of n)o=Cn(o,l.firstCreated);let s=r.runDurationMs??0,a=(r.runRecordedAt?.getTime()??Number.NaN)+e;if(r.runEndedAt===void 0&&Number.isFinite(a)){let l=a-s-ht,c=a+ht,f=r.endedByItsWrites===!0?$r(n,l,c):Number.NaN;return{start:r.runStartedAt?.getTime()??(o>l?o:l),end:Number.isFinite(f)?Math.min(f+Nn,c):c}}let i=r.runStartedAt?.getTime()??o,d=r.runEndedAt?.getTime()??i+s;return{start:i,end:d}}function Mn(r){let t=new Set,e=-1;return{has:n=>(r.size!==e&&(t=new Set([...r].map(y)),e=r.size),t.has(n))}}function os(r,t){let e=new Oe(r,{runRecords:t.runRecords,reached:{has:()=>!1},stays:()=>!1,runStart:t.runStart,runEnd:t.runEnd,removalStart:Number.POSITIVE_INFINITY,removalUser:void 0,earlierRemovals:(t.removalSpans??[]).map(n=>({start:N(n.first),end:N(n.last),user:y(n.userId)})),includeChanged:t.includeChanged,automationMade:Mn(t.taken),...t.runUserId?{runUser:y(t.runUserId)}:{}});return async(n,o)=>{let s=await e.heldAmong(n,o,1);return{held:s.held,holders:[...s.holders],...s.reason!==void 0?{reason:s.reason}:{}}}}var Ue="IsPersonAccount";function Jr(r,t){return{holding:new Set([...r.holding,...t.holding]),automation:[...r.automation,...t.automation],along:[...r.along,...t.along],goes:[...r.goes,...t.goes],unchecked:r.unchecked||t.unchecked}}var qr=50;function $e(r,t){return JSON.stringify(t.map(e=>r[e]??null))}var Oe=class{constructor(t,e){this.org=t;this.context=e}org;context;worked;statuses=new Map;lockedUnder=new Map;files=new Map;datesKept=new Map;cascadeEnds=new Map;async heldAmong(t,e,n=0){let o={held:new Set,holders:new Set,otherwise:new Set,mayBeAutomation:[],byAutomation:new Map,automationAfter:new Set,automationAlong:new Set,along:new Map,cameAlong:new Map,unchecked:new Set};if(e.length===0)return o;let s;try{let u=ee.parse(await this.org.describe(t)),g=await this.workedObjects(),m=t==="Account"&&u.fields.some(h=>h.name===Ue);s=(u.childRelationships??[]).filter(h=>(h.cascadeDelete===!0||h.restrictedDelete===!0)&&g.has(h.childSObject)).map(h=>({childSObject:h.childSObject,field:h.field,restricted:h.cascadeDelete!==!0,...m&&h.childSObject==="Contact"&&h.field==="AccountId"?{personContacts:!0}:{}}))}catch(u){return o.reason=C(u),e.forEach(g=>this.hold(o,y(g))),o}let a=[];for(let u=0;u<e.length;u+=z)a.push(e.slice(u,u+z));let i=a.length>1?await Xe(s.map(u=>()=>this.anyPointing(u)),Se):s.map(()=>!0),d=s.filter((u,g)=>i[g]).flatMap(u=>a.map(g=>async()=>({relationship:u,...await this.holdingIn(u,g)}))),l=o.mayBeAutomation,c=new Map;for(let{relationship:u,holding:g,unchecked:m,automation:h,along:R,goes:b}of await Xe(d,Se)){m&&o.unchecked.add(u.childSObject),(g.size>0||h.length>0)&&o.holders.add(u.childSObject),g.forEach(w=>this.hold(o,w));for(let w of h)o.held.add(y(w.parent));l.push(...h);for(let{parent:w,key:k}of R){let I=o.along.get(w)??new Map;I.set(k,u.childSObject),o.along.set(w,I)}b.length>0&&c.set(u.childSObject,[...c.get(u.childSObject)??[],...b])}if(await this.heldBelow(c,o,n),n>0)return o;this.context.previewing!==!0&&await this.lockedPastDraft(t,e,o),Ee(t)&&await this.standardPricesHeld(e,o),t===Ye&&await this.sellingModelOptionsHeld(e,o),this.context.alongAccepted!==!0&&await this.automationHeldBelow(l,o);let f=await this.byAutomationOnly(t,l,o.otherwise);return o.byAutomation=f.objects,o.automationAfter=f.after,o.automationAlong=f.along,o}hold(t,e){t.held.add(e),t.otherwise.add(e)}async heldBelow(t,e,n){let o=(s,a,i,d)=>{let l=s.get(a)??new Map;l.set(i,d),s.set(a,l)};for(let[s,a]of t){let i=[...new Set(a.map(l=>l.id))],d=n+1<wr?await this.heldAmong(s,i,n+1):void 0;for(let{parent:l,id:c,came:f}of a){let u=y(c);if(!d||d.held.has(u)){this.hold(e,l),e.holders.add(s),d?.holders.forEach(g=>e.holders.add(g));continue}f&&o(e.cameAlong,l,u,s);for(let[g,m]of d.along.get(u)??[])o(e.along,l,g,m);for(let[g,m]of d.cameAlong.get(u)??[])o(e.cameAlong,l,g,m)}d?.unchecked.forEach(l=>e.unchecked.add(l))}}async automationHeldBelow(t,e){let n=new Map;for(let o of t)e.otherwise.has(y(o.parent))||n.set(o.object,[...n.get(o.object)??[],o]);for(let[o,s]of n){let a=await this.heldAmong(o,[...new Set(s.map(i=>i.id))],1);for(let i of s){let d=y(i.id),l=a.mayBeAutomation.some(c=>y(c.parent)===d&&c.creator!==i.creator);!a.otherwise.has(d)&&!l||(this.hold(e,y(i.parent)),a.holders.forEach(c=>e.holders.add(c)))}a.unchecked.forEach(i=>e.unchecked.add(i))}}async byAutomationOnly(t,e,n){let o=new Map,s=new Set,a=e.filter(f=>!n.has(y(f.parent)));if(a.length===0)return{objects:o,after:s,along:new Set};let i;try{let f=await L(this.org,t,["CreatedDate","CreatedById"],[...new Set(a.map(u=>u.parent))]);i=new Map(f.flatMap(u=>typeof u.Id=="string"?[[y(u.Id),u]]:[]))}catch{return{objects:o,after:s,along:new Set}}let d=new Set,l=new Set;for(let f of a){let u=y(f.parent),g=i.get(u),m=N(g?.CreatedDate),h=g?.CreatedById,R=this.context.runUser??(typeof h=="string"?y(h):void 0),b=f.created-m;if(!(R!==void 0&&f.creator===R&&b>=-2e3&&b<=6e4)){d.add(u);continue}let k=o.get(u)??new Set;k.add(f.object),o.set(u,k),f.created>this.context.runEnd&&s.add(u),f.along||l.add(u)}for(let f of d)o.delete(f),s.delete(f);let c=new Set([...o.keys()].filter(f=>!l.has(f)));return{objects:o,after:s,along:c}}async holdingIn(t,e){let n=j(t.childSObject),o=j(t.field),[s]=H(e,e.length),a=new Set(["Id",o,...pt[n]?.ends??[],...t.personContacts?[Ue]:[]]),i=this.datesKept.get(n)??0;for(;i<He.length;){let d=He[i],l;try{l=await this.org.query(`SELECT ${[...a,...d].join(", ")} FROM ${n} WHERE ${o} IN (${s}) LIMIT ${Fe}`)}catch(R){Er(R)?(i=Pr(R,i),this.datesKept.set(n,i)):i++;continue}if(l.records.length>=Fe){if(e.length>1){let R=Math.ceil(e.length/2);return Jr(await this.holdingIn(t,e.slice(0,R)),await this.holdingIn(t,e.slice(R)))}return{holding:new Set(e.map(y)),automation:[],along:[],goes:[],unchecked:!1}}let c=new Set,f=[],u=[],g=[],m=new Map;for(let R of l.records){if(typeof R!="object"||R===null)continue;let b=R,w=b[t.field];if(typeof w!="string"||typeof b.Id!="string"||(n===Rn&&o==="LinkedEntityId"&&this.noteFile(b),this.lockedUnder.get(y(b.Id))===y(w)))continue;let k={onlyIncluded:!1};if(!this.stays(b,n,t.restricted,t.personContacts,k)){if(k.onlyIncluded&&u.push({parent:y(w),key:y(b.Id)}),n!==Rn&&this.goesAlongUnread(b)){let _=!(pt[n]?.cameWithRun(b,this.context.runRecords)===!0||t.personContacts===!0&&b[Ue]===!0)&&!k.onlyIncluded&&k.byRemoval!==!0&&this.context.goesWithParent?.(b,this.context.runEnd)!==!0;g.push({parent:y(w),id:b.Id,came:_})}continue}let I=this.mayBeAutomation(b);if(I){let P={parent:w,id:b.Id,object:n,along:!t.restricted,...I};f.push(P),t.restricted&&m.set(b.Id,P)}else c.add(y(w))}let h=await this.ofOtherParts(n,[...m.keys()]);for(let[R,b]of m)h.has(y(R))&&(f.splice(f.indexOf(b),1),c.add(y(b.parent)));return{holding:c,automation:f,along:u,goes:g,unchecked:!1}}return{holding:new Set,automation:[],along:[],goes:[],unchecked:!t.restricted}}goesAlongUnread(t){let e=y(t.Id),{runRecords:n,otherPartRecords:o,automationMade:s,goesWithParent:a,runEnd:i}=this.context;return this.context.alongAccepted!==!0&&!n.has(e)&&o?.has(e)!==!0&&s?.has(e)!==!0&&(this.context.goesWithParentReadBelow===!0||a?.(t,i)!==!0)}async ofOtherParts(t,e){let n=new Set,{otherPartRecords:o,otherPartObjects:s,runRecords:a}=this.context;if(e.length===0||!o||!s)return n;let i=this.cascadeEnds.get(t);i||(i=(async()=>{let c=new Set;for(let f of s)try{let u=ee.parse(await this.org.describe(f));for(let g of u.childRelationships??[])g.childSObject===t&&g.cascadeDelete===!0&&c.add(g.field)}catch{}return[...c]})(),this.cascadeEnds.set(t,i));let d=await i;if(d.length===0)return n;let l;try{l=await L(this.org,t,d,e)}catch{return n}for(let c of l){if(typeof c.Id!="string")continue;let f=d.flatMap(u=>{let g=c[u];return typeof g=="string"?[y(g)]:[]});f.some(u=>a.has(u))||f.some(u=>o.has(u))&&n.add(y(c.Id))}return n}mayBeAutomation(t){let{runRecords:e,runStart:n,runEnd:o,runUser:s,otherPartRecords:a}=this.context;if(typeof t.Id!="string"||e.has(y(t.Id))||a?.has(y(t.Id))===!0||typeof t.CreatedById!="string")return;let i=y(t.CreatedById);if(s!==void 0&&i!==s)return;let d=N(t.CreatedDate);if(!(d>=n-2e3&&d<=o+6e4))return;let l=N(t.LastModifiedDate),c=typeof t.LastModifiedById=="string"?y(t.LastModifiedById):void 0;if(!(l>o&&c!==void 0&&c!==i))return{created:d,creator:i}}async anyPointing(t){try{let e=j(t.childSObject),n=j(t.field);return(await this.org.query(`SELECT Id FROM ${e} WHERE ${n} != null LIMIT 1`)).records.length>0}catch{return!0}}noteFile(t){let e=t.LinkedEntityId,n=t.ContentDocumentId;if(typeof e!="string"||typeof n!="string"||ue(n,this.context.runRecords))return;let o=this.files.get(y(e))??new Set;o.add(n),this.files.set(y(e),o)}async filesOn(t){let e=new Map;for(let s of t){let a=this.files.get(y(s));a&&a.size>0&&e.set(y(s),[...a])}let n=[...new Set([...e.values()].flat())];if(n.length===0)return new Map;let o=new Map;try{for(let s of await L(this.org,kr,["Title"],n))typeof s.Id=="string"&&typeof s.Title=="string"&&s.Title!==""&&o.set(y(s.Id),s.Title)}catch{}return new Map([...e].map(([s,a])=>[s,a.map(i=>({key:y(i),name:o.get(y(i))??i}))]))}async lockedPastDraft(t,e,n){for(let[o,s]of Object.entries(Nt)){let a=s.find(u=>u.object===t)?.lookup,i=me[o];if(!a||!i)continue;let d=await this.statusCategoriesOf(i);if(!d)continue;let l,c;try{l=await L(this.org,t,[a],e);let u=[...new Set(l.map(g=>g[a]).filter(g=>typeof g=="string"))];c=u.length>0?await L(this.org,o,["Status"],u):[]}catch{continue}let f=new Set(c.filter(u=>{let g=d.categoryOf.get(String(u.Status));return g!==void 0&&g!=="Draft"}).map(u=>y(String(u.Id))));for(let u of l){let g=u[a];typeof u.Id!="string"||typeof g!="string"||f.has(y(g))&&(this.hold(n,y(u.Id)),n.holders.add(o),this.lockedUnder.set(y(u.Id),y(g)))}}}statusCategoriesOf(t){let e=this.statuses.get(t);return e||(e=Pe(de(this.org),t),this.statuses.set(t,e)),e}async standardPricesHeld(t,e){try{let n=de(this.org),o=[...await pe(n,t)];if(o.length===0)return;let s=await this.priceKeyFields(),a=await L(this.org,X,s,o),i=await this.pricesOfProducts(a,s),d=i.flatMap(u=>typeof u.Id=="string"?[u.Id]:[]),l=new Set([...await pe(n,d)].map(y)),c=new Set(t.map(y)),f=new Set;for(let u of i){if(typeof u.Id!="string")continue;let g=y(u.Id);if(l.has(g))continue;(c.has(g)?e.held.has(g):this.stays(u,X,!0))&&f.add($e(u,s))}for(let u of a)typeof u.Id!="string"||!f.has($e(u,s))||(this.hold(e,y(u.Id)),e.holders.add(X))}catch{}}async sellingModelOptionsHeld(t,e){let n=[ge,Ge];try{let o=await L(this.org,Ye,n,t),s=await this.pricesOfProducts(o,[...n,"IsActive"]),a=new Set(s.filter(i=>typeof i.Id=="string"&&i.IsActive===!0&&this.stays(i,X,!0)).map(i=>$e(i,n)));for(let i of o)typeof i.Id!="string"||!a.has($e(i,n))||(this.hold(e,y(i.Id)),e.holders.add(X))}catch{}}async priceKeyFields(){let t=ee.parse(await this.org.describe(X)),e=new Set(t.fields.map(n=>n.name));return[ge,...[Ge,Mt].filter(n=>e.has(n))]}async pricesOfProducts(t,e){let n=[...new Set(t.map(a=>a[ge]).filter(a=>typeof a=="string"))],o=[...new Set(["Id",...e])].map(j).join(", "),s=[];for(let a of H(n,qr)){let i=await this.org.query(`SELECT ${o} FROM ${X} WHERE ${ge} IN (${a}) LIMIT ${Fe}`);if(i.records.length>=Fe)throw new Error("More prices than one read takes.");for(let d of i.records)typeof d=="object"&&d!==null&&s.push(d)}return s}stays(t,e,n=!1,o=!1,s){let a=y(t.Id),{runRecords:i,reached:d,runStart:l,runEnd:c,removalStart:f,removalUser:u,earlierRemovals:g,includeChanged:m}=this.context;if(i.has(a))return d.has(a)||this.context.stays(a);if(n)return!0;if(this.context.automationMade?.has(a)===!0||this.context.goesWithParent?.(t,c)===!0||this.context.alongToDraft?.has(a)===!0||pt[e]?.cameWithRun(t,i))return!1;if(o&&t[Ue]===!0)return!(N(t.LastModifiedDate??t.SystemModstamp)<=c)&&!m;let h="CreatedDate"in t?"CreatedDate":"SystemModstamp"in t?"SystemModstamp":void 0;if(!h)return!0;let R=N(t[h]),b=N(h==="CreatedDate"?t.LastModifiedDate:t.SystemModstamp);if(!(R>=l))return!0;let w=this.context.linkedLater?.get(a);if(w&&(R<=c||R>=w.start)&&b<=w.end)return!1;let k=typeof t.CreatedById=="string"?y(t.CreatedById):void 0,I=(_,G)=>_!==void 0&&(_===u&&G>=f||g.some(K=>_===K.user&&G>=K.start&&G<=K.end));if(I(k,R))return s&&(s.byRemoval=!0),!1;if(b<=c)return!1;let P=typeof t.LastModifiedById=="string"?y(t.LastModifiedById):void 0;return R<=c&&I(P,b)?!1:(m&&s&&(s.onlyIncluded=!0),!m)}workedObjects(){return this.worked??=vt(this.org),this.worked}};export{Ne as a,zt as b,Un as c,$n as d,ee as e,zn as f,Xr as g,eo as h,to as i,Vn as j,no as k,Me as l,tt as m,je as n,he as o,po as p,at as q,Xn as r,tr as s,Zt as t,en as u,dt as v,tn as w,nn as x,rn as y,Te as z,ct as A,sr as B,lt as C,So as D,on as E,bn as F,le as G,cr as H,ht as I,re as J,Zo as K,Xo as L,es as M,ts as N,ns as O,rs as P,os as Q};
@@ -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 n,b as p,h as a}from"./chunk-BWWQXU2B.mjs";import{a as o}from"./chunk-EADHKH3A.mjs";import{q as d}from"./chunk-55LQD3Y3.mjs";var R=`SELECT Id FROM RecordType WHERE SobjectType = '${d}' AND IsPersonType = true`;async function S(i,t){let[y,c]=await Promise.all([o(i,n).then(({records:e})=>p(e)),o(t,n).then(({records:e})=>p(e))]),r;try{let{records:e}=await o(t,R);r=new Set(e.flatMap(s=>typeof s.Id=="string"?[s.Id.slice(0,15)]:[]))}catch{r=void 0}return{mappings:new a().buildMapping(y,c),source:y,target:c,...r?{personTypes:r}:{}}}export{S as a};
7
+ import{a as n,b as p,h as a}from"./chunk-BWWQXU2B.mjs";import{a as o}from"./chunk-EADHKH3A.mjs";import{q as d}from"./chunk-2GSMHGIV.mjs";var R=`SELECT Id FROM RecordType WHERE SobjectType = '${d}' AND IsPersonType = true`;async function S(i,t){let[y,c]=await Promise.all([o(i,n).then(({records:e})=>p(e)),o(t,n).then(({records:e})=>p(e))]),r;try{let{records:e}=await o(t,R);r=new Set(e.flatMap(s=>typeof s.Id=="string"?[s.Id.slice(0,15)]:[]))}catch{r=void 0}return{mappings:new a().buildMapping(y,c),source:y,target:c,...r?{personTypes:r}:{}}}export{S 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{_d as c}from"./chunk-DPYTG6DM.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";var y=[{type:"seed",label:"Seed Data",description:"Seed an org with a template saved on the Seed page or shipped with SandForge, never a production org; its records are taken back from Seed\u2019s Recent runs",category:"data",icon:"database",configSchema:{orgId:{type:"string"},templateId:{type:"string"}}},{type:"sync",label:"Sync Data",description:"Run a Sync configuration saved on the Sync page; a target Production Guard asks about, a production org or a sandbox marked Staging, needs an Approval step before it",category:"data",icon:"sync",configSchema:{configId:{type:"string"}}},{type:"backup",label:"Backup",description:"Take a DataOps snapshot of the listed objects into local storage",category:"data",icon:"archive",configSchema:{orgId:{type:"string"},objects:{type:"array"}}},{type:"restore",label:"Restore",description:"Restore data from a previous backup snapshot",category:"data",icon:"history",configSchema:{backupId:{type:"string"}}},{type:"anonymize",label:"Anonymize",description:"Mask an org with a DataOps template, after a snapshot of the values it writes over, never a production org",category:"data",icon:"shield",configSchema:{orgId:{type:"string"},templateId:{type:"string"},object:{type:"string",optional:!0},where:{type:"string",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1}}},{type:"delete",label:"Delete",description:"Delete records matching specified criteria",category:"data",icon:"trash",configSchema:{objectName:{type:"string"},where:{type:"string"}}},{type:"checkpoint",label:"Checkpoint",description:"Take a checkpoint of a sandbox, a scratch org or a Developer Edition org, kept on this machine",category:"data",icon:"bookmark",configSchema:{orgId:{type:"string"},mode:{type:"string",default:"everything"},objects:{type:"array",optional:!0},excluded:{type:"array",optional:!0},name:{type:"string",optional:!0},keepDays:{type:"number",default:c},maxTotal:{type:"number",optional:!0},ignoredFields:{type:"array",optional:!0}}},{type:"rewind",label:"Rewind",description:"Put an org back to a checkpoint kept on this machine, once confirmed by typing the org\u2019s alias, at most maxRecords records",category:"data",icon:"history",configSchema:{orgId:{type:"string"},checkpointId:{type:"string"},objects:{type:"array",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1},acceptNoUndo:{type:"boolean",default:!1},acceptRecreate:{type:"boolean",default:!1},acceptOutside:{type:"boolean",default:!1},acceptUnseen:{type:"boolean",default:!1},maxRecords:{type:"number",required:!0},refuseWhenActive:{type:"boolean",default:!0}}},{type:"compare",label:"Compare Orgs",description:"Compare the metadata of two orgs, as the Compare page does",category:"quality",icon:"git-compare",configSchema:{sourceOrgId:{type:"string"},targetOrgId:{type:"string"},types:{type:"array"}}},{type:"precheck",label:"Pre-check",description:"Read an org\u2019s API usage, storage, error logs or failed jobs as the Monitor does; the run stops on a critical reading",category:"quality",icon:"check-circle",configSchema:{orgId:{type:"string"},checks:{type:"array"}}},{type:"condition",label:"Condition",description:"Branch pipeline execution based on conditions",category:"control",icon:"git-branch",configSchema:{field:{type:"string"},operator:{type:"string"},value:{type:"string"}}},{type:"delay",label:"Delay",description:"Wait for a specified duration before continuing",category:"control",icon:"clock",configSchema:{durationMs:{type:"number"}}},{type:"approval",label:"Approval",description:"Pauses the run until someone approves it in VS Code; a rejection, or no answer in time, stops it",category:"control",icon:"user-check",configSchema:{message:{type:"string"},timeoutMinutes:{type:"number"}}},{type:"notification",label:"Notification",description:"Shows its message as a VS Code notification",category:"notification",icon:"bell",configSchema:{message:{type:"string"}}}],p=class{registry;constructor(){this.registry=new Map(y.map(e=>[e.type,e]))}getStepTypes(){return[...this.registry.values()]}getStepType(e){return this.registry.get(e)}getDefaultConfig(e){let r=this.registry.get(e);if(!r)return{};let o={};for(let[t,a]of Object.entries(r.configSchema)){let n=a;if(!(n.optional===!0||n.required===!0)){if("default"in n){o[t]=n.default;continue}switch(n.type){case"string":o[t]="";break;case"number":o[t]=0;break;case"array":o[t]=[];break;case"boolean":o[t]=!1;break;default:o[t]=null}}}return o}validateStepConfig(e,r){let o=this.registry.get(e);if(!o)return[`Unknown step type: ${e}`];let t=[];for(let[a,n]of Object.entries(o.configSchema)){let l=n,i=r[a],s=l.type;i!=null&&(s==="array"&&!Array.isArray(i)?t.push(`Field "${a}" must be an array`):s==="string"&&typeof i!="string"?t.push(`Field "${a}" must be a string`):s==="number"&&typeof i!="number"?t.push(`Field "${a}" must be a number`):s==="boolean"&&typeof i!="boolean"&&t.push(`Field "${a}" must be a boolean`))}return t}getStepCategories(){let e=new Set;for(let r of this.registry.values())e.add(r.category);return[...e]}};export{p as StepLibrary};
7
+ import{xe as c}from"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";var y=[{type:"seed",label:"Seed Data",description:"Seed an org with a template saved on the Seed page or shipped with SandForge, never a production org; its records are taken back from Seed\u2019s Recent runs",category:"data",icon:"database",configSchema:{orgId:{type:"string"},templateId:{type:"string"}}},{type:"sync",label:"Sync Data",description:"Run a Sync configuration saved on the Sync page; a target Production Guard asks about, a production org or a sandbox marked Staging, needs an Approval step before it",category:"data",icon:"sync",configSchema:{configId:{type:"string"}}},{type:"backup",label:"Backup",description:"Take a DataOps snapshot of the listed objects into local storage",category:"data",icon:"archive",configSchema:{orgId:{type:"string"},objects:{type:"array"}}},{type:"restore",label:"Restore",description:"Restore data from a previous backup snapshot",category:"data",icon:"history",configSchema:{backupId:{type:"string"}}},{type:"anonymize",label:"Anonymize",description:"Mask an org with a DataOps template, after a snapshot of the values it writes over, never a production org",category:"data",icon:"shield",configSchema:{orgId:{type:"string"},templateId:{type:"string"},object:{type:"string",optional:!0},where:{type:"string",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1}}},{type:"delete",label:"Delete",description:"Delete records matching specified criteria",category:"data",icon:"trash",configSchema:{objectName:{type:"string"},where:{type:"string"}}},{type:"checkpoint",label:"Checkpoint",description:"Take a checkpoint of a sandbox, a scratch org or a Developer Edition org, kept on this machine",category:"data",icon:"bookmark",configSchema:{orgId:{type:"string"},mode:{type:"string",default:"everything"},objects:{type:"array",optional:!0},excluded:{type:"array",optional:!0},name:{type:"string",optional:!0},keepDays:{type:"number",default:c},maxTotal:{type:"number",optional:!0},ignoredFields:{type:"array",optional:!0}}},{type:"rewind",label:"Rewind",description:"Put an org back to a checkpoint kept on this machine, once confirmed by typing the org\u2019s alias, at most maxRecords records",category:"data",icon:"history",configSchema:{orgId:{type:"string"},checkpointId:{type:"string"},objects:{type:"array",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1},acceptNoUndo:{type:"boolean",default:!1},acceptRecreate:{type:"boolean",default:!1},acceptOutside:{type:"boolean",default:!1},acceptUnseen:{type:"boolean",default:!1},maxRecords:{type:"number",required:!0},refuseWhenActive:{type:"boolean",default:!0}}},{type:"compare",label:"Compare Orgs",description:"Compare the metadata of two orgs, as the Compare page does",category:"quality",icon:"git-compare",configSchema:{sourceOrgId:{type:"string"},targetOrgId:{type:"string"},types:{type:"array"}}},{type:"precheck",label:"Pre-check",description:"Read an org\u2019s API usage, storage, error logs or failed jobs as the Monitor does; the run stops on a critical reading",category:"quality",icon:"check-circle",configSchema:{orgId:{type:"string"},checks:{type:"array"}}},{type:"condition",label:"Condition",description:"Branch pipeline execution based on conditions",category:"control",icon:"git-branch",configSchema:{field:{type:"string"},operator:{type:"string"},value:{type:"string"}}},{type:"delay",label:"Delay",description:"Wait for a specified duration before continuing",category:"control",icon:"clock",configSchema:{durationMs:{type:"number"}}},{type:"approval",label:"Approval",description:"Pauses the run until someone approves it in VS Code; a rejection, or no answer in time, stops it",category:"control",icon:"user-check",configSchema:{message:{type:"string"},timeoutMinutes:{type:"number"}}},{type:"notification",label:"Notification",description:"Shows its message as a VS Code notification",category:"notification",icon:"bell",configSchema:{message:{type:"string"}}}],p=class{registry;constructor(){this.registry=new Map(y.map(e=>[e.type,e]))}getStepTypes(){return[...this.registry.values()]}getStepType(e){return this.registry.get(e)}getDefaultConfig(e){let r=this.registry.get(e);if(!r)return{};let o={};for(let[t,a]of Object.entries(r.configSchema)){let n=a;if(!(n.optional===!0||n.required===!0)){if("default"in n){o[t]=n.default;continue}switch(n.type){case"string":o[t]="";break;case"number":o[t]=0;break;case"array":o[t]=[];break;case"boolean":o[t]=!1;break;default:o[t]=null}}}return o}validateStepConfig(e,r){let o=this.registry.get(e);if(!o)return[`Unknown step type: ${e}`];let t=[];for(let[a,n]of Object.entries(o.configSchema)){let l=n,i=r[a],s=l.type;i!=null&&(s==="array"&&!Array.isArray(i)?t.push(`Field "${a}" must be an array`):s==="string"&&typeof i!="string"?t.push(`Field "${a}" must be a string`):s==="number"&&typeof i!="number"?t.push(`Field "${a}" must be a number`):s==="boolean"&&typeof i!="boolean"&&t.push(`Field "${a}" must be a boolean`))}return t}getStepCategories(){let e=new Set;for(let r of this.registry.values())e.add(r.category);return[...e]}};export{p as StepLibrary};
@@ -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 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};
@@ -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{i as d}from"./chunk-T3PLRQ2T.mjs";import{i as s,j as c}from"./chunk-NWVVCZUK.mjs";import{access as p}from"node:fs/promises";import*as l from"node:path";var u="sfdx-project.json";async function w(n,e=g){for(let t of n)if(await e(l.join(t,u)))return{kind:"dx",dir:t};let r=n[0];return r===void 0?{kind:"none"}:{kind:"folder",dir:r}}async function g(n){try{return await p(n),!0}catch{return!1}}async function S(n,e){if(e.project.kind==="none")return{kind:"unavailable",reason:"no-workspace",message:"Open a folder in VS Code: the test file is written into it."};let r=await c(n.sidecar,e.storagePath,e.runId);if(r.kind==="absent")return{kind:"unavailable",reason:"no-companion",message:"This run kept no companion file: it was not seeded from a scenario, or it wrote no open case for a test to be about."};if(r.kind==="invalid")return{kind:"unavailable",reason:"companion-invalid",message:r.message};let{sidecar:t}=r,o=await e.findPack(t.packId,t.packFingerprint);if(!o)return{kind:"unavailable",reason:"pack-not-found",message:`The scenario ${t.packId} this run was seeded from is no longer in the workspace as it was: its tests would be about subjects and addresses no record of the run holds.`};let i=await e.readCatalog();if(i.kind==="no-agent")return{kind:"no-agent",reason:i.reason,message:i.message};if(i.kind==="unreadable")return{kind:"unavailable",reason:"catalog-unreadable",message:i.message};let a=await d(n.spec,{sidecar:t,pack:o,catalog:i.catalog,choice:e.choice,projectDir:e.project.dir,alias:e.alias,...e.overwrite!==void 0?{overwrite:e.overwrite}:{}});if(a.kind==="refused")return a;if(a.kind==="exists")return{kind:"exists",path:a.path,specPath:a.specPath};await s(n.sidecar,e.storagePath,a.sidecar).catch(()=>{});let f=e.project.kind==="dx";return{kind:"written",path:a.path,specPath:a.specPath,apiName:a.apiName,...f?{commands:{create:a.commands.create.line,run:a.commands.run.line}}:{notDxProject:!0},leftOut:a.leftOut}}export{u as a,w as b,S as c};
7
+ import{i as d}from"./chunk-2N73W63D.mjs";import{i as s,j as c}from"./chunk-27BBEGUD.mjs";import{access as p}from"node:fs/promises";import*as l from"node:path";var u="sfdx-project.json";async function w(n,e=g){for(let t of n)if(await e(l.join(t,u)))return{kind:"dx",dir:t};let r=n[0];return r===void 0?{kind:"none"}:{kind:"folder",dir:r}}async function g(n){try{return await p(n),!0}catch{return!1}}async function S(n,e){if(e.project.kind==="none")return{kind:"unavailable",reason:"no-workspace",message:"Open a folder in VS Code: the test file is written into it."};let r=await c(n.sidecar,e.storagePath,e.runId);if(r.kind==="absent")return{kind:"unavailable",reason:"no-companion",message:"This run kept no companion file: it was not seeded from a scenario, or it wrote no open case for a test to be about."};if(r.kind==="invalid")return{kind:"unavailable",reason:"companion-invalid",message:r.message};let{sidecar:t}=r,o=await e.findPack(t.packId,t.packFingerprint);if(!o)return{kind:"unavailable",reason:"pack-not-found",message:`The scenario ${t.packId} this run was seeded from is no longer in the workspace as it was: its tests would be about subjects and addresses no record of the run holds.`};let i=await e.readCatalog();if(i.kind==="no-agent")return{kind:"no-agent",reason:i.reason,message:i.message};if(i.kind==="unreadable")return{kind:"unavailable",reason:"catalog-unreadable",message:i.message};let a=await d(n.spec,{sidecar:t,pack:o,catalog:i.catalog,choice:e.choice,projectDir:e.project.dir,alias:e.alias,...e.overwrite!==void 0?{overwrite:e.overwrite}:{}});if(a.kind==="refused")return a;if(a.kind==="exists")return{kind:"exists",path:a.path,specPath:a.specPath};await s(n.sidecar,e.storagePath,a.sidecar).catch(()=>{});let f=e.project.kind==="dx";return{kind:"written",path:a.path,specPath:a.specPath,apiName:a.apiName,...f?{commands:{create:a.commands.create.line,run:a.commands.run.line}}:{notDxProject:!0},leftOut:a.leftOut}}export{u as a,w as b,S as c};
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a as _e}from"./chunk-TW3N6W5Z.mjs";import{a as Le,b as Ee,c as Te,d as De}from"./chunk-5GBO4KD5.mjs";import{a as ye,j as $e,l as M}from"./chunk-O7DAFE6M.mjs";import{b as G,e as H}from"./chunk-BZ24IAP5.mjs";import{a as U}from"./chunk-SCKUIE3R.mjs";import{c as J}from"./chunk-6FARZYMJ.mjs";import{a as Me}from"./chunk-E2OBAWSH.mjs";import{f as pe,j as Q,k as T,m as ge,n as _,o as D,p as we}from"./chunk-OMZJ37JI.mjs";import{a as Se,c as je,d as xe,e as Re,f as Ce,g as Oe,h as Ie,i as Pe,j as Ne}from"./chunk-VSU74RQ3.mjs";import{Qc as fe,za as le}from"./chunk-CAFUNR6D.mjs";import{h as be,i as ke}from"./chunk-AITNZWLB.mjs";import{m as ve}from"./chunk-KGYXLSQ5.mjs";import{l as me}from"./chunk-6SEDOIO3.mjs";import{h as he}from"./chunk-MNITSYI2.mjs";import{b as oe}from"./chunk-HVC5CYIB.mjs";import{b as ne,c as re,e as ae,f as ie,h as Ae}from"./chunk-LCDPCUXS.mjs";import{q as ue}from"./chunk-55LQD3Y3.mjs";import{e as de,g as ce}from"./chunk-TZE3Y7IQ.mjs";import{Jc as se,xc as te,y as W}from"./chunk-DPYTG6DM.mjs";import{readFileSync as Xe}from"node:fs";import{basename as Ke,join as Ve}from"node:path";var Ze=`sandforge dataops \u2014 mask an org's records, and put them back, without the editor.
7
+ import{a as _e}from"./chunk-TW3N6W5Z.mjs";import{a as Le,b as Ee,c as Te,d as De}from"./chunk-5GBO4KD5.mjs";import{a as ye,j as $e}from"./chunk-BNKT3R3F.mjs";import{a as M}from"./chunk-QROPNEGY.mjs";import{b as G,e as H}from"./chunk-BZ24IAP5.mjs";import{a as U}from"./chunk-SCKUIE3R.mjs";import{c as J}from"./chunk-6FARZYMJ.mjs";import{a as Me}from"./chunk-WAYQLQAD.mjs";import{f as pe,j as Q,k as T,m as ge,n as _,o as D,p as we}from"./chunk-FKCIGJOI.mjs";import{a as Se,c as je,d as xe,e as Re,f as Ce,g as Oe,h as Ie,i as Pe,j as Ne}from"./chunk-HVX2AFYW.mjs";import{Qc as fe,za as le}from"./chunk-AXFD2OH6.mjs";import{h as be,i as ke}from"./chunk-X2XZQ434.mjs";import{m as ve}from"./chunk-5OGNK3JP.mjs";import{l as me}from"./chunk-XMQ5R6TC.mjs";import{h as he}from"./chunk-BT43WSOS.mjs";import{b as oe}from"./chunk-7ZBDACVG.mjs";import{b as ne,c as re,e as ae,f as ie,h as Ae}from"./chunk-LCDPCUXS.mjs";import{q as ue}from"./chunk-2GSMHGIV.mjs";import{e as de,g as ce}from"./chunk-TZE3Y7IQ.mjs";import{Wc as te,gd as se,y as W}from"./chunk-6QSHWIZI.mjs";import{readFileSync as Xe}from"node:fs";import{basename as Ke,join as Ve}from"node:path";var Ze=`sandforge dataops \u2014 mask an org's records, and put them back, without the editor.
8
8
 
9
9
  Usage:
10
10
  npx sandforge dataops anonymize \\
@@ -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,i,j,k}from"./chunk-5WGA5CZB.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as AGENT_CATALOG_API,b as AGENT_CATALOG_FIELDS,c as AGENT_TEST_NAME_FIELD,i as GUARD_TOPIC_NAMES,e as NO_AGENTFORCE_MESSAGE,d as NO_AGENT_MESSAGE,g as agentNamed,k as declaresVariable,h as proposedActions,j as proposedGuardTopic,f as readAgentCatalog};
7
+ import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-H4OBZIX3.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as AGENT_CATALOG_API,b as AGENT_CATALOG_FIELDS,c as AGENT_TEST_NAME_FIELD,i as GUARD_TOPIC_NAMES,e as NO_AGENTFORCE_MESSAGE,d as NO_AGENT_MESSAGE,g as agentNamed,k as declaresVariable,h as proposedActions,j as proposedGuardTopic,f as readAgentCatalog};
@@ -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{j as c}from"./chunk-DPYTG6DM.mjs";var a=/__kav$/i,d="Campaign";function u(e){return a.test(e)?"Salesforce Knowledge is not turned on in it: tick Knowledge User on your user (Setup > Users), then enable it in Setup > Knowledge Settings":void 0}var b="a campaign needs the Marketing User box ticked on the user, in Setup > Users",f=/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/;function m(e){let n,t;return async s=>{n??=e.describeGlobal().then(o=>new Map(o.sobjects.map(i=>[i.name.toLowerCase(),i.createable===!0])));let r=(await n).get(s.toLowerCase());if(r===void 0){let o=u(s);return{access:"absent",...o?{reason:o}:{}}}return s===d&&(t??=l(e),!r||!await t)?{access:"readOnly",reason:b}:r?{access:"createable"}:{access:"readOnly"}}}async function j(e,n){let t=new Set;for(let{objectApiName:s,optional:r}of e.objects)if(r===!0)try{(await n(s)).access!=="createable"&&t.add(s)}catch{}if(t.size===0)return e;for(let s=!0;s;){s=!1;for(let r of e.objects)t.has(r.objectApiName)||c(r,e.relations).some(o=>t.has(o))&&(t.add(r.objectApiName),s=!0)}return{...e,objects:e.objects.filter(s=>!t.has(s.objectApiName)),...e.relations?{relations:e.relations.filter(({childObject:s,parentObject:r})=>!t.has(s)&&!t.has(r))}:{}}}async function l(e){try{let{user_id:n}=await e.identity();return f.test(n)?(await e.query(`SELECT UserPermissionsMarketingUser FROM User WHERE Id = '${n}'`)).records[0]?.UserPermissionsMarketingUser!==!1:!0}catch{return!0}}export{m as a,j as b};
7
+ import{j as c}from"./chunk-6QSHWIZI.mjs";var a=/__kav$/i,d="Campaign";function u(e){return a.test(e)?"Salesforce Knowledge is not turned on in it: tick Knowledge User on your user (Setup > Users), then enable it in Setup > Knowledge Settings":void 0}var b="a campaign needs the Marketing User box ticked on the user, in Setup > Users",f=/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/;function m(e){let n,t;return async s=>{n??=e.describeGlobal().then(o=>new Map(o.sobjects.map(i=>[i.name.toLowerCase(),i.createable===!0])));let r=(await n).get(s.toLowerCase());if(r===void 0){let o=u(s);return{access:"absent",...o?{reason:o}:{}}}return s===d&&(t??=l(e),!r||!await t)?{access:"readOnly",reason:b}:r?{access:"createable"}:{access:"readOnly"}}}async function j(e,n){let t=new Set;for(let{objectApiName:s,optional:r}of e.objects)if(r===!0)try{(await n(s)).access!=="createable"&&t.add(s)}catch{}if(t.size===0)return e;for(let s=!0;s;){s=!1;for(let r of e.objects)t.has(r.objectApiName)||c(r,e.relations).some(o=>t.has(o))&&(t.add(r.objectApiName),s=!0)}return{...e,objects:e.objects.filter(s=>!t.has(s.objectApiName)),...e.relations?{relations:e.relations.filter(({childObject:s,parentObject:r})=>!t.has(s)&&!t.has(r))}:{}}}async function l(e){try{let{user_id:n}=await e.identity();return f.test(n)?(await e.query(`SELECT UserPermissionsMarketingUser FROM User WHERE Id = '${n}'`)).records[0]?.UserPermissionsMarketingUser!==!1:!0}catch{return!0}}export{m as a,j as b};
@@ -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-DHIW4IO5.mjs";import"./chunk-E2YJVSX6.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-3B5H24ZG.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-DPYTG6DM.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-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};
@@ -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-TMIESDE5.mjs";import"./chunk-TCEXCHXR.mjs";import"./chunk-4GCYGQXD.mjs";import"./chunk-WXU6ZJIV.mjs";import"./chunk-R3OM3X4L.mjs";import"./chunk-77IVKH7R.mjs";import"./chunk-2WMKJVD2.mjs";import"./chunk-PPGDAUEQ.mjs";import"./chunk-VV3B6IC3.mjs";import"./chunk-VXZ5PTOM.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-ZOSESZ22.mjs";import"./chunk-TQ2TQHTT.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-Z3MGN42K.mjs";import"./chunk-2GSMHGIV.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-ISOSTAJR.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-6QSHWIZI.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,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{Ib as o,Lc as d}from"./chunk-DPYTG6DM.mjs";var u=new Set(["picklist","multipicklist"]);function c(a){return(a.picklistValues??[]).filter(s=>s.active!==!1&&typeof s.value=="string"&&s.value!=="").map(s=>s.value)}function m(a){let s=new Map,r=i=>{let t=s.get(i);return t||(t=a(i),s.set(i,t)),t};return{async createable(i){let{fields:t}=await r(i);return new Set(t.filter(e=>e.createable===!0).map(e=>e.name))},async visible(i){let{fields:t}=await r(i);return new Set(t.map(e=>e.name))},async computed(i){let{fields:t}=await r(i);return new Set(t.filter(e=>e.calculated===!0||e.autoNumber===!0).map(e=>e.name))},async picklistValues(i){let{fields:t}=await r(i),e=new Map;for(let n of t){if(!u.has(n.type??""))continue;let l=c(n);l.length>0&&e.set(n.name,l)}return e},async keyPrefix(i){let{keyPrefix:t}=await r(i);return typeof t=="string"&&t.length===3?t:void 0},async lengths(i){let{fields:t}=await r(i);return new Map(t.flatMap(e=>typeof e.length=="number"&&e.length>0?[[e.name,e.length]]:[]))},async unset(i){let{fields:t}=await r(i),e=n=>n.type==="reference"||(n.referenceTo??[]).length>0;return{empty:new Set(t.filter(n=>e(n)&&n.nillable===!0&&n.defaultedOnCreate!==!0).map(n=>n.name)),filled:new Set(t.filter(n=>n.nillable===!1||n.defaultedOnCreate===!0).map(n=>n.name))}},async required(i){let{fields:t}=await r(i);return t.filter(e=>e.createable===!0&&e.nillable===!1&&e.defaultedOnCreate!==!0&&(e.referenceTo??[]).length===0).map(e=>({fieldApiName:e.name,type:e.type??"string",picklistValues:c(e),referenceTo:[],length:e.length??0,integerDigits:o({...e,type:e.type??"string"}),objectApiName:i,required:!0}))}}}function p(a,s){return async r=>(await a.required(r)).filter(i=>!d(r,i.fieldApiName,s.includes(r)?"person":"business"))}export{m as a,p as b};
7
+ import{fc as o,id as d}from"./chunk-6QSHWIZI.mjs";var u=new Set(["picklist","multipicklist"]);function c(a){return(a.picklistValues??[]).filter(s=>s.active!==!1&&typeof s.value=="string"&&s.value!=="").map(s=>s.value)}function m(a){let s=new Map,r=i=>{let t=s.get(i);return t||(t=a(i),s.set(i,t)),t};return{async createable(i){let{fields:t}=await r(i);return new Set(t.filter(e=>e.createable===!0).map(e=>e.name))},async visible(i){let{fields:t}=await r(i);return new Set(t.map(e=>e.name))},async computed(i){let{fields:t}=await r(i);return new Set(t.filter(e=>e.calculated===!0||e.autoNumber===!0).map(e=>e.name))},async picklistValues(i){let{fields:t}=await r(i),e=new Map;for(let n of t){if(!u.has(n.type??""))continue;let l=c(n);l.length>0&&e.set(n.name,l)}return e},async keyPrefix(i){let{keyPrefix:t}=await r(i);return typeof t=="string"&&t.length===3?t:void 0},async lengths(i){let{fields:t}=await r(i);return new Map(t.flatMap(e=>typeof e.length=="number"&&e.length>0?[[e.name,e.length]]:[]))},async unset(i){let{fields:t}=await r(i),e=n=>n.type==="reference"||(n.referenceTo??[]).length>0;return{empty:new Set(t.filter(n=>e(n)&&n.nillable===!0&&n.defaultedOnCreate!==!0).map(n=>n.name)),filled:new Set(t.filter(n=>n.nillable===!1||n.defaultedOnCreate===!0).map(n=>n.name))}},async required(i){let{fields:t}=await r(i);return t.filter(e=>e.createable===!0&&e.nillable===!1&&e.defaultedOnCreate!==!0&&(e.referenceTo??[]).length===0).map(e=>({fieldApiName:e.name,type:e.type??"string",picklistValues:c(e),referenceTo:[],length:e.length??0,integerDigits:o({...e,type:e.type??"string"}),objectApiName:i,required:!0}))}}}function p(a,s){return async r=>(await a.required(r)).filter(i=>!d(r,i.fieldApiName,s.includes(r)?"person":"business"))}export{m as a,p as b};
@@ -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 y,b as g}from"./chunk-HYBH5PFM.mjs";import{a as S,b as f,c as p}from"./chunk-K77NR3UK.mjs";import{b as u}from"./chunk-CA5NAXSU.mjs";import{Ha as d}from"./chunk-DPYTG6DM.mjs";var h="SELECT ApiName, MasterLabel, IsClosed, IsDefault, SortOrder FROM CaseStatus ORDER BY SortOrder",w="SELECT MasterLabel, IsClosed, IsDefault, SortOrder FROM CaseStatus ORDER BY SortOrder",A="Closed";async function k(a){let e;try{e=await a(h)}catch{try{e=await a(w)}catch(t){return m(`the org would not read its case statuses: ${u(t)}`)}}let r=e.flatMap(t=>{let n=b(t.ApiName)??b(t.MasterLabel);return n===void 0?[]:[{value:n,closed:t.IsClosed===!0,isDefault:t.IsDefault===!0}]}),o=r.filter(t=>!t.closed),i=r.filter(t=>t.closed);return o.length===0||i.length===0?m(o.length===0?"the org has no case status that leaves a case open":"the org has no case status that closes a case"):{open:(o.find(t=>t.isDefault)??o[0]).value,closed:(i.find(t=>t.value===A)??i[0]).value,from:"org"}}function m(a){return{...d.caseStatus,from:"default",reason:a}}function b(a){return typeof a=="string"&&a.trim()!==""?a:void 0}var c=S;async function E(a,e){let r;try{r=await a(c)}catch{r={access:"createable"}}if(r.access==="absent")return{available:!1,reason:r.reason??`the org has no ${c}`};if(r.access==="readOnly")return{available:!1,reason:r.reason??`the user this seed runs as may read ${c} and not create it`};try{return{available:!0,bodyFields:f(await e(c))}}catch{return{available:!0,bodyFields:[]}}}var P=["Status","Origin","Priority","Type"];async function T(a){let e;try{e=(await a("Case")).fields}catch{return}let r={};for(let o of P){let t=(e.find(n=>n.name===o)?.picklistValues??[]).filter(n=>n.active!==!1).map(n=>n.value);t.length>0&&(r[o]=t)}return r}function v(a,e){let r=e.knowledge.available?e.knowledge.bodyFields:[],o=r.map(s=>s.name),i=e.articleBodyField===void 0?r[0]:r.find(s=>s.name===e.articleBodyField);if(e.articleBodyField!==void 0&&i===void 0)return{issues:[`options.articleBodyField: ${e.articleBodyField} is not a field of ${c} this org lets a body be written to`+(o.length>0?` (${o.join(", ")})`:"")]};let t=e.knowledge.available?{available:!0,bodyFields:o}:e.knowledge,n={seed:e.seed??d.seed,caseStatus:{open:e.caseStatus.open,closed:e.caseStatus.closed},...i!==void 0?p(i):{}},l;try{l=g(a,n)}catch(s){if(s instanceof y)return{issues:s.issues};throw s}return{preparation:{options:n,objects:[...l.template.objects].sort((s,C)=>s.insertOrder-C.insertOrder).map(s=>({objectApiName:s.objectApiName,recordCount:s.recordCount,...s.optional===!0?{optional:!0}:{}})),tests:l.tests.length,caseStatusFrom:e.caseStatus.from==="org"?{from:"org"}:{from:"default",reason:e.caseStatus.reason},knowledge:t}}}function D(a){return async e=>{let r=await a.query(e),o=[...r.records];for(;!r.done&&r.nextRecordsUrl;)r=await a.queryMore(r.nextRecordsUrl),o.push(...r.records);return o}}export{h as a,w as b,k as c,c as d,E as e,T as f,v as g,D as h};
7
+ import{a as y,b as g}from"./chunk-OTJH6AEA.mjs";import{a as S,b as f,c as p}from"./chunk-AHUGG3WU.mjs";import{b as u}from"./chunk-CA5NAXSU.mjs";import{Ha as d}from"./chunk-6QSHWIZI.mjs";var h="SELECT ApiName, MasterLabel, IsClosed, IsDefault, SortOrder FROM CaseStatus ORDER BY SortOrder",w="SELECT MasterLabel, IsClosed, IsDefault, SortOrder FROM CaseStatus ORDER BY SortOrder",A="Closed";async function k(a){let e;try{e=await a(h)}catch{try{e=await a(w)}catch(t){return m(`the org would not read its case statuses: ${u(t)}`)}}let r=e.flatMap(t=>{let n=b(t.ApiName)??b(t.MasterLabel);return n===void 0?[]:[{value:n,closed:t.IsClosed===!0,isDefault:t.IsDefault===!0}]}),o=r.filter(t=>!t.closed),i=r.filter(t=>t.closed);return o.length===0||i.length===0?m(o.length===0?"the org has no case status that leaves a case open":"the org has no case status that closes a case"):{open:(o.find(t=>t.isDefault)??o[0]).value,closed:(i.find(t=>t.value===A)??i[0]).value,from:"org"}}function m(a){return{...d.caseStatus,from:"default",reason:a}}function b(a){return typeof a=="string"&&a.trim()!==""?a:void 0}var c=S;async function E(a,e){let r;try{r=await a(c)}catch{r={access:"createable"}}if(r.access==="absent")return{available:!1,reason:r.reason??`the org has no ${c}`};if(r.access==="readOnly")return{available:!1,reason:r.reason??`the user this seed runs as may read ${c} and not create it`};try{return{available:!0,bodyFields:f(await e(c))}}catch{return{available:!0,bodyFields:[]}}}var P=["Status","Origin","Priority","Type"];async function T(a){let e;try{e=(await a("Case")).fields}catch{return}let r={};for(let o of P){let t=(e.find(n=>n.name===o)?.picklistValues??[]).filter(n=>n.active!==!1).map(n=>n.value);t.length>0&&(r[o]=t)}return r}function v(a,e){let r=e.knowledge.available?e.knowledge.bodyFields:[],o=r.map(s=>s.name),i=e.articleBodyField===void 0?r[0]:r.find(s=>s.name===e.articleBodyField);if(e.articleBodyField!==void 0&&i===void 0)return{issues:[`options.articleBodyField: ${e.articleBodyField} is not a field of ${c} this org lets a body be written to`+(o.length>0?` (${o.join(", ")})`:"")]};let t=e.knowledge.available?{available:!0,bodyFields:o}:e.knowledge,n={seed:e.seed??d.seed,caseStatus:{open:e.caseStatus.open,closed:e.caseStatus.closed},...i!==void 0?p(i):{}},l;try{l=g(a,n)}catch(s){if(s instanceof y)return{issues:s.issues};throw s}return{preparation:{options:n,objects:[...l.template.objects].sort((s,C)=>s.insertOrder-C.insertOrder).map(s=>({objectApiName:s.objectApiName,recordCount:s.recordCount,...s.optional===!0?{optional:!0}:{}})),tests:l.tests.length,caseStatusFrom:e.caseStatus.from==="org"?{from:"org"}:{from:"default",reason:e.caseStatus.reason},knowledge:t}}}function D(a){return async e=>{let r=await a.query(e),o=[...r.records];for(;!r.done&&r.nextRecordsUrl;)r=await a.queryMore(r.nextRecordsUrl),o.push(...r.records);return o}}export{h as a,w as b,k as c,c as d,E as e,T as f,v as g,D as h};
@@ -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{Oc as c,Pc as l,Rc as d,Sc as m}from"./chunk-DPYTG6DM.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-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};
@@ -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{c as u}from"./chunk-NWVVCZUK.mjs";import{Fb as f,Ka as d}from"./chunk-DPYTG6DM.mjs";import{mkdir as h,readdir as g,readFile as m,rename as w,writeFile as S}from"node:fs/promises";import*as c from"node:path";var k=".sandforge-scenario.json",P={depth:3,files:50},y=new Set(["node_modules","dist","out","coverage"]),E=10;function O(){return{list:async r=>{try{return(await g(r,{withFileTypes:!0})).map(e=>({name:e.name,folder:e.isDirectory()}))}catch(t){let e=t.code;if(e==="ENOENT"||e==="ENOTDIR"||e==="EACCES")return[];throw t}},readFile:r=>m(r,"utf8"),writeNew:async(r,t)=>{await h(c.dirname(r),{recursive:!0});try{return await S(r,t,{encoding:"utf8",flag:"wx"}),!0}catch(e){if(e.code==="EEXIST")return!1;throw e}},replace:async(r,t)=>{let e=`${r}.${process.pid}.tmp`;await S(e,t,"utf8"),await w(e,r)}}}function x(r){let t;try{t=JSON.parse(r)}catch{return{issues:["The file is not JSON"]}}let e=d.safeParse(t);return e.success?{pack:e.data}:{issues:e.error.issues.slice(0,E).map(n=>`${n.path.join(".")||"the file"}: ${n.message}`)}}async function F(r,t){let e=[],n=async(a,o,i)=>{let p=[...await r.list(o)].sort((s,l)=>s.name.localeCompare(l.name));for(let s of p){if(e.length>=P.files)return;let l=c.join(o,s.name);s.folder?i<P.depth&&!v(s.name)&&await n(a,l,i+1):s.name.endsWith(k)&&e.push({path:l,relativePath:c.relative(a,l).split(c.sep).join("/")})}};for(let a of t)await n(a,a,0);return e}function v(r){return r.startsWith(".")||y.has(r)}async function N(r,t){let e=f.map(n=>({source:"built-in",pack:n}));for(let n of await F(r,t)){let a;try{a=await r.readFile(n.path)}catch{e.push({source:"workspace",...n,issues:["The file could not be read"]});continue}let o=x(a);e.push({source:"workspace",...n,...o})}return e}function A(r){return`${JSON.stringify(r,null,2)}
7
+ import{c as u}from"./chunk-27BBEGUD.mjs";import{Ka as d,cc as f}from"./chunk-6QSHWIZI.mjs";import{mkdir as h,readdir as g,readFile as m,rename as w,writeFile as S}from"node:fs/promises";import*as c from"node:path";var k=".sandforge-scenario.json",P={depth:3,files:50},y=new Set(["node_modules","dist","out","coverage"]),E=10;function O(){return{list:async r=>{try{return(await g(r,{withFileTypes:!0})).map(e=>({name:e.name,folder:e.isDirectory()}))}catch(t){let e=t.code;if(e==="ENOENT"||e==="ENOTDIR"||e==="EACCES")return[];throw t}},readFile:r=>m(r,"utf8"),writeNew:async(r,t)=>{await h(c.dirname(r),{recursive:!0});try{return await S(r,t,{encoding:"utf8",flag:"wx"}),!0}catch(e){if(e.code==="EEXIST")return!1;throw e}},replace:async(r,t)=>{let e=`${r}.${process.pid}.tmp`;await S(e,t,"utf8"),await w(e,r)}}}function x(r){let t;try{t=JSON.parse(r)}catch{return{issues:["The file is not JSON"]}}let e=d.safeParse(t);return e.success?{pack:e.data}:{issues:e.error.issues.slice(0,E).map(n=>`${n.path.join(".")||"the file"}: ${n.message}`)}}async function F(r,t){let e=[],n=async(a,o,i)=>{let p=[...await r.list(o)].sort((s,l)=>s.name.localeCompare(l.name));for(let s of p){if(e.length>=P.files)return;let l=c.join(o,s.name);s.folder?i<P.depth&&!v(s.name)&&await n(a,l,i+1):s.name.endsWith(k)&&e.push({path:l,relativePath:c.relative(a,l).split(c.sep).join("/")})}};for(let a of t)await n(a,a,0);return e}function v(r){return r.startsWith(".")||y.has(r)}async function N(r,t){let e=f.map(n=>({source:"built-in",pack:n}));for(let n of await F(r,t)){let a;try{a=await r.readFile(n.path)}catch{e.push({source:"workspace",...n,issues:["The file could not be read"]});continue}let o=x(a);e.push({source:"workspace",...n,...o})}return e}function A(r){return`${JSON.stringify(r,null,2)}
8
8
  `}async function T(r,t,e,n=!1){let a=t[0];if(a===void 0)return{kind:"no-workspace"};let o=d.parse(e),i=`${o.id}${k}`,p=c.join(a,i),s=A(o);if(n)await r.replace(p,s);else if(!await r.writeNew(p,s))return{kind:"exists",path:p,relativePath:i};return{kind:"saved",path:p,relativePath:i}}async function b(r,t,e,n){let a=i=>i.id===e&&u(i)===n,o=f.find(a);if(o)return o;for(let i of await N(r,t))if(i.source==="workspace"&&"pack"in i&&a(i.pack))return i.pack}export{k as a,P as b,O as c,x as d,F as e,N as f,A as g,T as h,b as i};
@@ -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}from"./chunk-ZUA5BNAO.mjs";import"./chunk-RKALOKAU.mjs";import"./chunk-DPYTG6DM.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as FieldMappingService,b as MOVES_ITS_SOURCE,e as mapFields,c as mappedTargets,d as notSentAsRead};
7
+ import{a,b,c,d,e}from"./chunk-7BQMBXKX.mjs";import"./chunk-KWAVSZ2B.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as FieldMappingService,b as MOVES_ITS_SOURCE,e as mapFields,c as mappedTargets,d as notSentAsRead};
@@ -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,i,j}from"./chunk-T3PLRQ2T.mjs";import"./chunk-5WGA5CZB.mjs";import"./chunk-NWVVCZUK.mjs";import"./chunk-HYBH5PFM.mjs";import"./chunk-OVOLG3AL.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-KNIRA333.mjs";import"./chunk-MNITSYI2.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-DPYTG6DM.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{b as AGENT_TEST_RUN_WAIT_MINUTES,a as AGENT_TEST_SPECS_DIR,e as agentTestApiName,f as agentTestCommands,d as agentTestSpecFileName,c as agentTestSpecYaml,g as nodeAgentTestSpecFiles,h as writeAgentTestSpec,i as writeScenarioTestSpec,j as yamlOf};
7
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-2N73W63D.mjs";import"./chunk-27BBEGUD.mjs";import"./chunk-H4OBZIX3.mjs";import"./chunk-OTJH6AEA.mjs";import"./chunk-FVLFO2S6.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-77MZRBWX.mjs";import"./chunk-BT43WSOS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{b as AGENT_TEST_RUN_WAIT_MINUTES,a as AGENT_TEST_SPECS_DIR,e as agentTestApiName,f as agentTestCommands,d as agentTestSpecFileName,c as agentTestSpecYaml,g as nodeAgentTestSpecFiles,h as writeAgentTestSpec,i as writeScenarioTestSpec,j as yamlOf};
@@ -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{g as ae,i as V}from"./chunk-V4RKM4QZ.mjs";import{m as oe,o as ie}from"./chunk-ETT5GP4P.mjs";import{B as q,H as ee,I as te,J as ne,L as re,d as M,k as B,s as W,t as E,u as Z,v as z,w as Q,z as j}from"./chunk-E2YJVSX6.mjs";import{$a as J,ab as U,bb as D}from"./chunk-DPYTG6DM.mjs";import{b as N,e as K,m as F,v as L}from"./chunk-WZQEK4WT.mjs";import{createCipheriv as Se,createDecipheriv as Ce,createHash as m,hkdfSync as Te,randomBytes as C,timingSafeEqual as Pe}from"node:crypto";import{createReadStream as He}from"node:fs";import{lstat as se,open as _,rename as _e,rm as $e,statfs as Ne}from"node:fs/promises";import{basename as de,dirname as le,join as ue}from"node:path";import{Readable as pe}from"node:stream";import{pipeline as ye}from"node:stream/promises";import{createGunzip as Ke,createGzip as Fe}from"node:zlib";var bt=".sfcheckpoint",De=1024*1024,Me=new Set([1]),ze=new Set([1,2]),$=32,O=16,je=4096,Ve=1024,Xe=64*1024*1024,me=2**32,ge="sandforge-checkpoint/1 block key",we="sandforge-checkpoint/1 key check",X="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",Ye=Math.ceil($*8/5),g="Nothing was imported.";function Bt(){return C($)}function At(n){if(n.length!==$)throw new RangeError("Not a key of a checkpoint file");let e="",t=0,r=0;for(let o of n)for(t=(t<<8|o)&65535,r+=8;r>=5;)e+=X[t>>>r-5&31],r-=5;return r>0&&(e+=X[t<<5-r&31]),(e.match(/.{1,4}/g)??[]).join("-")}function Et(n){let e=n.replace(/[\s-]/g,"").toUpperCase();if(e.length!==Ye||!/^[A-Z2-7]+$/.test(e))return;let t=Buffer.alloc($),r=0,o=0,i=0;for(let a of e)r=(r<<5|X.indexOf(a))&65535,o+=5,o>=8&&(t[i++]=r>>>o-8&255,o-=8);if((r&(1<<o)-1)===0)return t}function T(n,e,t,r){return Buffer.from(Te("sha256",n,e,t,r))}function ke(n,e){let t=Buffer.alloc(12);return n.copy(t,0),t.writeUInt32BE(e,8),t}function be(n,e,t){let r=Buffer.alloc(37);return n.copy(r,0),r.writeUInt32BE(e,32),r[36]=t?1:0,r}function Ge(n,e,t,r){let o=Se("aes-256-gcm",n.blockKey,ke(n.prefix,e),{authTagLength:O});return o.setAAD(be(n.headerHash,e,t)),Buffer.concat([o.update(r),o.final(),o.getAuthTag()])}function Le(n,e,t,r){let o=Ce("aes-256-gcm",n.blockKey,ke(n.prefix,e),{authTagLength:O});o.setAAD(be(n.headerHash,e,t)),o.setAuthTag(r.subarray(r.length-O));try{let i=o.update(r.subarray(0,r.length-O));return Buffer.concat([i,o.final()])}catch{return}}var P=class extends Error{constructor(t){super(t.message);this.refusal=t;this.name="ImportRefused"}refusal};function f(n){return new P({code:"IMPORT_DAMAGED",message:`This checkpoint file ${n}: it was changed or damaged after it was exported. ${g}`})}var I=class extends Error{constructor(t,r){super(r);this.code=t;this.name="CheckpointExportError"}code};function Je(n){return{...H(n,Be),org:H(n.org,Ae)}}var Be=["lastRewind","takenOn","expiresAt","bytes","importedFrom"],Ae=["alias"];function H(n,e){return Object.fromEntries(Object.entries(n).filter(([t])=>!e.includes(t)))}async function*Ee(n,e){if(e===0)return;let t=0;for await(let r of He(n,{start:0,end:e-1})){let o=r;t+=o.length,yield o}if(t!==e)throw new I("EXPORT_CHANGED",`${de(n)} of the checkpoint shrank while it was exported: export it again.`)}async function xe(n,e){let t=m("sha256");for await(let r of Ee(n,e))t.update(r);return t.digest("hex")}async function xt(n){let{folder:e,checkpoint:t,out:r,key:o}=n,i=n.chunkBytes??De;if(await se(r).catch(()=>{}))throw new I("EXPORT_EXISTS",`${r} is there already: name another file, or move that one away first.`);let a=Buffer.from(`${JSON.stringify(Je(t))}
7
+ import{g as ae,i as V}from"./chunk-I5C4O3VA.mjs";import{m as oe,o as ie}from"./chunk-EOQON3E5.mjs";import{B as q,H as ee,I as te,J as ne,L as re,d as M,k as B,s as W,t as E,u as Z,v as z,w as Q,z as j}from"./chunk-N2HYG3BL.mjs";import{$a as J,ab as U,bb as D}from"./chunk-6QSHWIZI.mjs";import{b as N,e as K,m as F,v as L}from"./chunk-WZQEK4WT.mjs";import{createCipheriv as Se,createDecipheriv as Ce,createHash as m,hkdfSync as Te,randomBytes as C,timingSafeEqual as Pe}from"node:crypto";import{createReadStream as He}from"node:fs";import{lstat as se,open as _,rename as _e,rm as $e,statfs as Ne}from"node:fs/promises";import{basename as de,dirname as le,join as ue}from"node:path";import{Readable as pe}from"node:stream";import{pipeline as ye}from"node:stream/promises";import{createGunzip as Ke,createGzip as Fe}from"node:zlib";var bt=".sfcheckpoint",De=1024*1024,Me=new Set([1]),ze=new Set([1,2]),$=32,O=16,je=4096,Ve=1024,Xe=64*1024*1024,me=2**32,ge="sandforge-checkpoint/1 block key",we="sandforge-checkpoint/1 key check",X="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",Ye=Math.ceil($*8/5),g="Nothing was imported.";function Bt(){return C($)}function At(n){if(n.length!==$)throw new RangeError("Not a key of a checkpoint file");let e="",t=0,r=0;for(let o of n)for(t=(t<<8|o)&65535,r+=8;r>=5;)e+=X[t>>>r-5&31],r-=5;return r>0&&(e+=X[t<<5-r&31]),(e.match(/.{1,4}/g)??[]).join("-")}function Et(n){let e=n.replace(/[\s-]/g,"").toUpperCase();if(e.length!==Ye||!/^[A-Z2-7]+$/.test(e))return;let t=Buffer.alloc($),r=0,o=0,i=0;for(let a of e)r=(r<<5|X.indexOf(a))&65535,o+=5,o>=8&&(t[i++]=r>>>o-8&255,o-=8);if((r&(1<<o)-1)===0)return t}function T(n,e,t,r){return Buffer.from(Te("sha256",n,e,t,r))}function ke(n,e){let t=Buffer.alloc(12);return n.copy(t,0),t.writeUInt32BE(e,8),t}function be(n,e,t){let r=Buffer.alloc(37);return n.copy(r,0),r.writeUInt32BE(e,32),r[36]=t?1:0,r}function Ge(n,e,t,r){let o=Se("aes-256-gcm",n.blockKey,ke(n.prefix,e),{authTagLength:O});return o.setAAD(be(n.headerHash,e,t)),Buffer.concat([o.update(r),o.final(),o.getAuthTag()])}function Le(n,e,t,r){let o=Ce("aes-256-gcm",n.blockKey,ke(n.prefix,e),{authTagLength:O});o.setAAD(be(n.headerHash,e,t)),o.setAuthTag(r.subarray(r.length-O));try{let i=o.update(r.subarray(0,r.length-O));return Buffer.concat([i,o.final()])}catch{return}}var P=class extends Error{constructor(t){super(t.message);this.refusal=t;this.name="ImportRefused"}refusal};function f(n){return new P({code:"IMPORT_DAMAGED",message:`This checkpoint file ${n}: it was changed or damaged after it was exported. ${g}`})}var I=class extends Error{constructor(t,r){super(r);this.code=t;this.name="CheckpointExportError"}code};function Je(n){return{...H(n,Be),org:H(n.org,Ae)}}var Be=["lastRewind","takenOn","expiresAt","bytes","importedFrom"],Ae=["alias"];function H(n,e){return Object.fromEntries(Object.entries(n).filter(([t])=>!e.includes(t)))}async function*Ee(n,e){if(e===0)return;let t=0;for await(let r of He(n,{start:0,end:e-1})){let o=r;t+=o.length,yield o}if(t!==e)throw new I("EXPORT_CHANGED",`${de(n)} of the checkpoint shrank while it was exported: export it again.`)}async function xe(n,e){let t=m("sha256");for await(let r of Ee(n,e))t.update(r);return t.digest("hex")}async function xt(n){let{folder:e,checkpoint:t,out:r,key:o}=n,i=n.chunkBytes??De;if(await se(r).catch(()=>{}))throw new I("EXPORT_EXISTS",`${r} is there already: name another file, or move that one away first.`);let a=Buffer.from(`${JSON.stringify(Je(t))}
8
8
  `,"utf8"),s=[{path:E,bytes:a.length,sha256:m("sha256").update(a).digest("hex"),content:a}];for(let u of await z(e))u.path!==E&&s.push({...u,sha256:await xe(u.file,u.bytes)});let h=s.some(u=>u.path===W);h&&await V(e);let c=C(32),d=C(8),{dataStorageMaxMB:l,staging:p}=t.org,v={format:"sandforge-checkpoint",formatVersion:h?2:1,checkpointFormat:1,sandforgeVersion:n.sandforgeVersion,organizationId:B(t.org.organizationId),orgTier:t.org.tier,...l!==void 0?{dataStorageMaxMB:l}:{},...p===!0?{staging:p}:{},checkpointId:t.checkpointId,takenAt:t.takenAt,records:Ie(t),objects:t.objects.length,files:s.length,bytes:s.reduce((u,b)=>u+b.bytes,0),cipher:"aes-256-gcm",kdf:"hkdf-sha256",salt:c.toString("hex"),noncePrefix:d.toString("hex"),keyCheck:T(o,c,we,16).toString("hex"),chunkBytes:i},R=Buffer.from(`${JSON.stringify(D.parse(v))}
9
9
  `),w={blockKey:T(o,c,ge,32),prefix:d,headerHash:m("sha256").update(R).digest()},S=ue(le(r),`.${de(r)}.${process.pid}-${C(4).toString("hex")}.tmp`),y=m("sha256"),k=0,A=await _(S,"wx",M);try{try{let u=async b=>{y.update(b),k+=b.length,await Oe(A,b)};await u(R),await ye(pe.from(Ue(s)),Fe({level:6}),async b=>{await We(b,i,w,u)}),await A.sync()}finally{await A.close()}if(await se(r).catch(()=>{}))throw new I("EXPORT_EXISTS",`${r} appeared while the checkpoint was exported: name another file.`);await _e(S,r)}catch(u){throw await $e(S,{force:!0}),u}return{header:v,bytes:k,sha256:y.digest("hex")}}async function Oe(n,e){for(let t=0;t<e.length;){let{bytesWritten:r}=await n.write(e,t,e.length-t);t+=r}}function Ie(n){return n.objects.reduce((e,t)=>e+t.records,0)}async function*Ue(n){for(let e of n){let{path:t,bytes:r,sha256:o}=e;if(yield Buffer.from(`${JSON.stringify({path:t,bytes:r,sha256:o})}
10
10
  `,"utf8"),e.content!==void 0){yield e.content;continue}let i=m("sha256");for await(let a of Ee(e.file??"",r))i.update(a),yield a;if(i.digest("hex")!==o)throw new I("EXPORT_CHANGED",`${t} of the checkpoint changed while it was exported: export it again.`)}yield Buffer.from(`${JSON.stringify({end:!0,files:n.length})}
@@ -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 R,b,c as L,f as T,g as f,i as $,k as q,l as D}from"./chunk-TCEXCHXR.mjs";async function B(s){let i=s.now??(()=>new Date),o=await $(s.org,s.users,{now:i(),...s.previous?{previous:s.previous}:{}}),h=q(o,s.users,{...s.previous?{previous:s.previous}:{},...s.acceptUserEmails!==void 0?{acceptUserEmails:s.acceptUserEmails}:{},...s.deliverability!==void 0?{deliverability:s.deliverability}:{},...s.acceptEmails!==void 0?{acceptEmails:s.acceptEmails}:{}});return{state:o,plan:h,answer:D(h,s.organization,o.requests)}}function F(s,i){let o=s.changes.find(i);if(!o)throw new Error(`No change of ${s.username} for this write`);return o}function k(s,i){let o=s?.errors[0];return{code:o?.code??"NO_ANSWER",message:L(o?.message??"the org answered nothing for it",i)}}var K=new Set(["ENTITY_IS_DELETED","NOT_FOUND","INVALID_CROSS_REFERENCE_KEY"]);function _(s){let{target:i}=s.planned;return{isActive:i.isActive!==void 0?s.standing.isActive:s.before.isActive,isFrozen:i.isFrozen!==void 0?s.standing.isFrozen:s.before.isFrozen,profileId:i.profileId!==void 0?s.standing.profileId:s.before.profileId}}function V(s){let i=_(s);return s.accesses.length>0||i.isActive!==s.before.isActive||i.isFrozen!==s.before.isFrozen||f(i.profileId)!==f(s.before.profileId)}function H(s){let i=s.found.permissionSetAssignments.length>0||s.found.groupMembers.length>0?{found:s.found}:{};return{username:s.planned.username,userId:s.userId,before:s.before,done:s.done,created:{permissionSetAssignments:s.accesses.filter(o=>o.what!=="group").map(o=>o.id),groupMembers:s.accesses.filter(o=>o.what==="group").map(o=>o.id)},...i,...s.address!==void 0?{address:s.address}:{},...s.refused.length>0?{refused:s.refused}:{}}}async function ee(s){let{org:i,store:o,signal:h}=s,y=s.now??(()=>new Date),E=i.requests(),{state:A,plan:P,answer:a}=await B(s);if(P.refusals.length>0)return{kind:"refused",plan:a};if(f(A.connected.organizationId)!==f(s.organization.organizationId))throw new Error(`The connection is to ${A.connected.organizationId}, not to ${s.organization.organizationId}: nothing was written`);let c=P.users.flatMap(e=>e.userId!==void 0&&e.current!==void 0&&e.before!==void 0?[{planned:e,userId:e.userId,before:e.before,standing:{...e.current},done:[],refused:[],accesses:[...e.carried,...e.writes.unassign,...e.writes.leave],found:{permissionSetAssignments:[...e.found.permissionSetAssignments],groupMembers:[...e.found.groupMembers]},...e.address!==void 0?{address:e.address}:{}}]:[]),l=c.map(e=>e.planned.username),d=0,g=y().toISOString(),v=(e,r)=>({...s.previous?{replaces:s.previous.run}:{},status:e,startedAt:g,...r?{endedAt:y().toISOString()}:{},emailsToPeople:d,users:c.filter(n=>n.planned.inFile||V(n)).map(n=>({applied:H(n),after:_(n),accesses:n.accesses,inFile:n.planned.inFile}))}),W=(e,r,n)=>({version:1,organizationId:A.connected.organizationId,run:e,...v(r,n)}),M=(await o.begin(A.connected.organizationId,v("running",!1))).run,C=new Set,z=async(e,r,n,p,u)=>{if(e.length===0)return;let t=await i.update(p,e.map(r));e.forEach((m,w)=>{let I=F(m.planned,n);t[w]?.success===!0?(u(m),m.done.push(I)):m.refused.push({change:I,...k(t[w],l)})})},x=[()=>z(c.filter(e=>e.planned.writes.profileId!==void 0),e=>({Id:e.userId,ProfileId:e.planned.writes.profileId}),e=>e.what==="profile","User",e=>{e.standing.profileId=e.planned.writes.profileId??e.standing.profileId}),async()=>{for(let e of[!1,!0])await z(c.filter(r=>r.planned.writes.isActive===e),r=>({Id:r.userId,IsActive:e}),r=>r.what==="active","User",r=>{r.standing.isActive=e})},()=>z(c.filter(e=>e.planned.writes.isFrozen!==void 0),e=>({Id:e.planned.writes.loginId??"",IsFrozen:e.planned.writes.isFrozen}),e=>e.what==="frozen","UserLogin",e=>{e.standing.isFrozen=e.planned.writes.isFrozen??e.standing.isFrozen}),async()=>{let e=c.flatMap(r=>r.planned.writes.assign.map(n=>({one:r,assign:n})));if(e.length>0){let r=await i.create("PermissionSetAssignment",e.map(({one:n,assign:p})=>p.what==="permissionSet"?{AssigneeId:n.userId,PermissionSetId:p.setId}:{AssigneeId:n.userId,PermissionSetGroupId:p.setId}));e.forEach(({one:n,assign:p},u)=>{let t=r[u],m=F(n.planned,w=>w.what===p.what&&w.name===p.name&&w.to==="added");t?.success===!0&&t.id!==void 0?(n.accesses.push({id:t.id,what:p.what,name:p.name}),n.done.push(m)):t?.errors[0]?.code==="DUPLICATE_VALUE"?C.add(n):n.refused.push({change:m,...k(t,l)})})}await N("PermissionSetAssignment",r=>r.planned.writes.unassign)},async()=>{let e=c.filter(r=>r.planned.writes.join.length>0);if(e.length>0){let r=new Map;for(let p of R(e.map(u=>u.userId),200)){let u=await i.query(`SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE UserOrGroupId IN ${b(p)}`);for(let t of u)r.set(`${f(String(t.UserOrGroupId))}:${f(String(t.GroupId))}`,String(t.Id))}let n=e.flatMap(p=>p.planned.writes.join.flatMap(u=>{let t=r.get(`${f(p.userId)}:${f(u.groupId)}`);return t!==void 0?(p.found.groupMembers.push(t),[]):[{one:p,join:u}]}));if(n.length>0){let p=new Set([...r.values()].map(f)),u=await i.create("GroupMember",n.map(({one:t,join:m})=>({GroupId:m.groupId,UserOrGroupId:t.userId})));n.forEach(({one:t,join:m},w)=>{let I=u[w],O=F(t.planned,U=>U.what==="group"&&U.name===m.name&&U.to==="added");if(I?.success===!0&&I.id!==void 0){if(p.has(f(I.id))){t.found.groupMembers.push(I.id);return}t.accesses.push({id:I.id,what:"group",name:m.name,type:m.type}),t.done.push(O)}else t.refused.push({change:O,...k(I,l)})})}}await N("GroupMember",r=>r.planned.writes.leave)},()=>z(c.filter(e=>e.planned.writes.email!==void 0),e=>({Id:e.userId,Email:e.planned.writes.email}),e=>e.what==="email","User",e=>{d+=1,e.address="awaiting"})];async function N(e,r){let n=c.flatMap(u=>r(u).map(t=>({one:u,access:t})));if(n.length===0)return;let p=await i.destroy(e,n.map(({access:u})=>u.id));n.forEach(({one:u,access:t},m)=>{let w=p[m],I=F(u.planned,U=>U.what===t.what&&"name"in U&&U.name===t.name&&U.to==="removed"),O=w?.errors.some(U=>K.has(U.code))===!0;w?.success===!0||O?(u.accesses=u.accesses.filter(U=>U.id!==t.id),w?.success===!0&&u.done.push(I)):u.refused.push({change:I,...k(w,l)})})}let S="success";for(let e of x){if(h?.aborted){S="cancelled";break}await e(),await o.write(W(M,"running",!1))}S!=="cancelled"&&await Y(i,c,C),S!=="cancelled"&&c.some(e=>e.refused.length>0)&&(S="partial");let G=W(M,S,!0);return await o.write(G),{kind:"applied",answer:{org:s.organization,run:M,status:S,users:c.map(H),emailsToPeople:d,apiRequests:i.requests()-E},record:G}}async function Y(s,i,o){let h=i.filter(a=>a.planned.writes.profileId!==void 0||a.planned.writes.isActive!==void 0||a.planned.writes.isFrozen!==void 0||a.planned.writes.email!==void 0),y=new Map(i.map(a=>[f(a.userId),a])),E=(a,c)=>{let l=a.done.findIndex(g=>g.what===c);if(l<0)return;let[d]=a.done.splice(l,1);a.refused.push({change:d,code:"NOT_HELD",message:"the org answered success, and its read after the run holds the user otherwise"})};for(let a of R(h.map(c=>c.userId),200)){let c=await s.query(`SELECT Id, Email, IsActive, ProfileId FROM User WHERE Id IN ${b(a)}`);for(let l of c){let d=y.get(f(String(l.Id)));if(!d)continue;let g=l.IsActive===!0,v=String(l.ProfileId);d.planned.writes.isActive!==void 0&&g!==d.standing.isActive&&E(d,"active"),d.planned.writes.profileId!==void 0&&f(v)!==f(d.standing.profileId)&&E(d,"profile"),d.standing.isActive=g,d.standing.profileId=v,d.address==="awaiting"&&typeof l.Email=="string"&&T(l.Email)===void 0&&(d.address="restored")}}let A=h.filter(a=>a.planned.writes.isFrozen!==void 0);for(let a of R(A.map(c=>c.userId),200)){let c=await s.query(`SELECT Id, UserId, IsFrozen FROM UserLogin WHERE UserId IN ${b(a)}`);for(let l of c){let d=y.get(f(String(l.UserId)));if(!d)continue;let g=l.IsFrozen===!0;g!==d.standing.isFrozen&&E(d,"frozen"),d.standing.isFrozen=g}}if(o.size===0)return;let P=await s.query(`SELECT Id, AssigneeId, PermissionSetId, PermissionSetGroupId FROM PermissionSetAssignment WHERE AssigneeId IN ${b([...o].map(a=>a.userId))}`);for(let a of o)for(let c of a.planned.writes.assign){let l=P.find(g=>f(String(g.AssigneeId))===f(a.userId)&&f(String((c.what==="permissionSet"?g.PermissionSetId:g.PermissionSetGroupId)??""))===f(c.setId)),d=l?String(l.Id):void 0;d!==void 0&&!a.accesses.some(g=>f(g.id)===f(d))&&!a.found.permissionSetAssignments.includes(d)&&a.found.permissionSetAssignments.push(d)}}export{B as a,ee as b};