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,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 Ce}from"./chunk-GMY5427L.mjs";import{h as Re,i as be,j as Se,k as ke,n as Te,o as Fe}from"./chunk-TEIBWMJM.mjs";import{c as Oe}from"./chunk-BWWQXU2B.mjs";import{f as he,i as me,o as we}from"./chunk-UIUPPEFB.mjs";import{a as z,l as ie,o as ae,q as de,t as ce,u as ue,v as le}from"./chunk-ICIYL45C.mjs";import{b as ye,e as ge}from"./chunk-ZUA5BNAO.mjs";import{b as fe,c as q,m as pe}from"./chunk-HFSBDM7B.mjs";import{d as K}from"./chunk-OHEOJISY.mjs";import{G as se,q as te,s as ne,t as re,u as oe}from"./chunk-55LQD3Y3.mjs";import{b as ee}from"./chunk-CA5NAXSU.mjs";import{Lc as B,tc as X}from"./chunk-DPYTG6DM.mjs";var H=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function b(t){return t.slice(0,15)}var We=class{constructor(e=new Map){this.earlier=e}earlier;written=new Map;refused=new Map;deleted=new Set;ownersRefused=new Set;contactsSentWith=new Map;noteSentWithContact(e,n){this.contactsSentWith.set(b(e),n)}contactSentWith(e){return this.contactsSentWith.get(b(e))}roleLinkedFor(e){this.contactsSentWith.delete(b(e))}get sentWithAContact(){return this.contactsSentWith.size>0}noteOwnerRefused(e){this.ownersRefused.add(b(e))}isOwnerRefused(e){return this.ownersRefused.has(b(e))}noteDeleted(e){for(let n of e)this.deleted.add(b(n))}standing(e){return e!==void 0&&this.deleted.has(b(e))?void 0:e}noteMatched(e,n){this.noteWritten(e,n)}noteWritten(e,n){this.written.set(b(e),n),this.refused.delete(b(e))}noteRefused(e,n){this.written.has(b(e))||this.refused.set(b(e),n)}targetOf(e){return this.standing(this.written.get(b(e)))??this.standing(this.earlier.get(b(e)))}refusedObjectOf(e){if(this.standing(this.earlier.get(b(e)))===void 0)return this.refused.get(b(e))}};function Ae(t,e,n){if(e.length===0||!n.some(o=>!o.master))return;let r={};for(let o of e)r[o]=(r[o]??0)+1;let s=Se(be(n));return{objectApiName:t,rows:e.length,why:r,...s?{predicted:s}:{}}}function Ie(t,e){return q(t,e?.target??[])}function Y(t){switch(t.operation){case"insert":return null;case"upsert":return t.externalIdField??"Id";case"update":case"delete":return"Id"}}function ze(t,e,n,r,s){let o=ge(t,e);for(let i of n)(!(i.fieldApiName in o)||i.overwriteExisting)&&(o[i.fieldApiName]=i.value);if(!r)return o;let a={};for(let i of Object.keys(o))i!=="attributes"&&(r.has(i)||i===s)&&(a[i]=o[i]);return a}function ve(t,e){return`${t} ${e} record${t===1?"":"s"}`}function Ue(t,e,n){let r=a=>e.find(i=>b(i.recordTypeId)===b(a)),s=t;if(!r(t)&&n){let a=n.mappings.find(i=>b(i.sourceId)===b(t));if(!a){let i=n.source.find(c=>b(c.id)===b(t)),y=i?(n.target??[]).filter(c=>c.sobjectType===i.sobjectType&&c.developerName===i.developerName):[];return{unmapped:i?K(i):"",namesakes:y.map(K)}}s=a.targetId}let o=q(e.filter(a=>b(a.recordTypeId)===b(s)),n?.target??[])[0];return o&&!o.available&&!o.master?{unavailable:o}:o?{sent:s,info:o}:{sent:s}}function Ge(t,e,n){if(t?.personAccounts===!1)return!0;if(!n)return!1;let r=e??Te(t?.recordTypes);return r!==void 0&&!n.has(b(r))}function Le(t,e,n){return{group:`parent:${e}:${n}`,reason:`PARENT_REFUSED: the ${n} record its ${e} names was refused in this run.`,say:r=>`PARENT_REFUSED: ${ve(r,t)} held back, not sent: the ${n} record their ${e} names was refused in this run, and written without it they would stand without their ${n}.`}}function Ee(t){let{config:e,records:n,target:r,run:s}=t,o=e.objectApiName,a=Y(e),i=r?.recordTypes??[],y=r?.references??new Set,c={payloads:[],sentAt:[],settled:[],held:[],deferred:[],deferredAcross:[],notes:[],currencies:[],withoutRecordType:new Map},h=new Map,m=new Map,T=(d,l,g,k)=>{c.held.push({index:d,reason:g}),h.delete(d);let I=m.get(l);I?I.count++:m.set(l,{count:1,say:k})},w=e.operation==="insert"||e.operation==="upsert",W=w&&i.some(d=>!d.master),f=new Map;s&&w&&s.sources.forEach((d,l)=>{let g=d?.Id;typeof g=="string"&&H.test(g)&&f.set(b(g),l)});let v=new Set([...s&&w?s.later??[]:[]].map(d=>d.toLowerCase())),R=new Set(v.size===0?[]:(r?.fields??[]).flatMap(d=>d.isReference&&(d.referenceTo??[]).some(l=>v.has(l.toLowerCase()))&&!(d.nillable===!1&&d.defaultedOnCreate!==!0)?[d.name]:[]));n.forEach((d,l)=>{let g=ze(d,e.fieldMappings,e.addOnFields,r?.creatable??null,a);if(e.operation==="delete"){h.set(l,{payload:g,settled:new Set});return}let k=new Set;if(s)for(let p of Object.keys(g)){let C=g[p];if(p==="RecordTypeId"||!y.has(p)||typeof C!="string"||!H.test(C))continue;if(f.has(b(C))){delete g[p],c.deferred.push({index:l,field:p,parent:C});continue}let _=s.links.targetOf(C);if(_){g[p]=_,k.add(p);continue}let M=s.links.refusedObjectOf(C);if(M===void 0){R.has(p)&&(delete g[p],c.deferredAcross.push({index:l,field:p,parent:C}));continue}let G=Le(o,p,M);T(l,G.group,G.reason,G.say);return}let I=g.RecordTypeId,E,j=Oe(I);if(j)delete g.RecordTypeId;else if(typeof I=="string"&&H.test(I)){let p=Ue(I,i,s?.recordTypes);if("unmapped"in p){let C=p.unmapped,_=p.namesakes.length>0?` The target org's ${p.namesakes.join(" and ")} carries its DeveloperName under another namespace, and a record type is mapped to one of the same namespace only.`:"";T(l,`unmapped:${C}`,"RECORD_TYPE_UNMAPPED: its record type has no counterpart in the target org.",M=>`RECORD_TYPE_UNMAPPED: ${ve(M,o)} held back, not sent: `+(C?`their record type ${C} has no active ${o} record type of that API name in the target org.${_} Create or activate record type ${C} on ${o} in the target org.`:"their record type is inactive in the source org, and has no counterpart in the target org."));return}if("unavailable"in p){let C=p.unavailable;T(l,`unavailable:${C.recordTypeId}`,`RECORD_TYPE_UNAVAILABLE: record type ${C.developerName} is closed to the running user in the target org.`,_=>`${pe({objectApiName:o,recordTypeId:C.recordTypeId,developerName:C.developerName,name:C.name,inactive:!C.active,recordCount:_})} Held back, not sent.`);return}g.RecordTypeId=p.sent,E=p.sent,p.info&&k.add("RecordTypeId")}let $=s?.sources[l]??d;if(re($)){let p=oe($,Ge(r,E,s?.recordTypes?.personTypes));for(let C of Object.keys(g))B(o,C,p)&&delete g[C]}else for(let p of Object.keys(g))B(o,p,"business")&&delete g[p];W&&!("RecordTypeId"in g)&&c.withoutRecordType.set(l,j?"masterInSource":"notRead"),h.set(l,{payload:g,settled:k})});let L=!0;for(;L;){L=!1;for(let{index:d,field:l,parent:g}of c.deferred){let k=f.get(b(g));if(!h.has(d)||k===void 0||h.has(k)||s?.links.targetOf(g)!==void 0)continue;let I=Le(o,l,o);T(d,I.group,I.reason,I.say),L=!0}}c.deferred=c.deferred.filter(({index:d})=>h.has(d)),c.deferredAcross=c.deferredAcross.filter(({index:d})=>h.has(d));for(let d of[...c.withoutRecordType.keys()])h.has(d)||c.withoutRecordType.delete(d);c.held.sort((d,l)=>d.index-l.index);let S=e.operation==="delete"?void 0:s?.currencies,O=r?.creatable.has(z)===!0,u=!O&&(s?.currencyChangesById?.size??0)>0&&r?.fields?.some(d=>d.name===z)===!0,F=S&&(O||u)?ae(r?.fields??[]):void 0,P=[...r?.references??[]],A=new le;for(let[d,{payload:l,settled:g}]of[...h].sort(([k],[I])=>k-I)){for(let k of X(o,l))delete l[k];if(S&&F){let k=s?.sources[d]??n[d],I=k?.[z],E=O?de(l,{read:I,currencyFields:F,ratesOn:ie(o,k)},S):ue(l,{read:I,parent:k?ce(o,k,P,$=>s?.currencyChangesById?.get($)):void 0,currencyFields:F},S);A.add(o,E);let j=k?.Id;E&&typeof j=="string"&&s?.currencyChangesById?.set(j,E)}c.payloads.push(l),c.sentAt.push(d),c.settled.push(g)}return c.notes=[...m.values()].map(({count:d,say:l})=>l(d)),c.currencies=A.list(),c}function V(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:void 0}function Be(t){let e=V(t.length),n=V(t.precision),r=V(t.digits);return{name:t.name,queryable:t.queryable!==!1,createable:t.createable===!0,isReference:t.type==="reference",...t.type!==void 0?{type:t.type}:{},...e!==void 0?{length:e}:{},...t.nillable!==void 0?{nillable:t.nillable}:{},...t.defaultedOnCreate!==void 0?{defaultedOnCreate:t.defaultedOnCreate}:{},...t.calculated===!0?{calculated:!0}:{},...n!==void 0?{precision:n}:{},...n!==void 0&&typeof t.scale=="number"&&t.scale>=0?{scale:t.scale}:{},...r!==void 0?{digits:r}:{},...t.unique===!0?{unique:!0}:{},...t.referenceTo?{referenceTo:[...t.referenceTo]}:{}}}function yt(t){let e=t.fields.filter(r=>r.createable===!0),n=t.fields.some(r=>typeof r.idLookup=="boolean");return{creatable:new Set(e.map(r=>r.name)),references:new Set(e.filter(r=>r.type==="reference").map(r=>r.name)),...typeof t.createable=="boolean"?{objectCreateable:t.createable}:{},...typeof t.updateable=="boolean"?{objectUpdateable:t.updateable}:{},recordTypes:fe(t.recordTypeInfos),...t.name===te?{personAccounts:t.fields.some(r=>r.name===ne)}:{},fields:t.fields.map(Be),...n?{upsertKeys:new Set(t.fields.filter(r=>r.externalId===!0||r.idLookup===!0).map(r=>r.name.toLowerCase()))}:{}}}function Z(t,e,n){switch(e){case"notInTarget":return`Object is not in the target org, or the user the run writes as cannot see it: ${t}. None of its records were sent.`;case"notCreateable":return`Object is not createable on target org: the user the run writes as may not create ${t} records there. None of its records were sent.`;case"notUpdateable":return`Object is not updateable on target org: the user the run writes as may not edit ${t} records there. None of its records were sent.`;case"unread":return`The target org did not describe ${t}${n?` (${n})`:""}, so what it takes could not be told and none of its records were sent.`;case"notAKey":return`The upsert of ${t} matches on ${n??"a field"}, which the target org does not match an upsert on: it takes an External ID field, the Id, or a field its describe marks idLookup. None of its records were sent.`}}function gt(t,e){let n=t.externalIdField?.trim().toLowerCase();if(t.operation!=="upsert"||!n)return t;let r=e.fields?.find(s=>s.name.toLowerCase()===n)?.name;return r===void 0?t:{...t,externalIdField:r}}function ht(t,e){if(t.operation==="delete"||t.query===void 0)return t;let n=Ce(t.query);if(!("list"in n))return t;let r=new Set([...n.list,t.externalIdField??"",...t.fieldMappings.filter(o=>ye.has(o.type)).map(o=>o.sourceField)].map(o=>o.toLowerCase())),s=[...e.creatable].filter(o=>!r.has(o.toLowerCase()));return s.length===0?t:{...t,excludedFields:[...new Set([...t.excludedFields??[],...s])]}}async function Pe(t,e,n,r){let s;try{s=await t(e)}catch(c){if(n==="delete")return{notAsked:!0};let h=Fe(c)?"notInTarget":"unread";return{refused:{why:h,message:Z(e,h,ee(c))}}}let o=n==="insert"||n==="upsert",a=n==="update"||n==="upsert",i=o&&s.objectCreateable===!1?"notCreateable":a&&s.objectUpdateable===!1?"notUpdateable":void 0;if(i)return{refused:{why:i,message:Z(e,i)},target:s};let y=r?.trim()||"Id";return n==="upsert"&&s.upsertKeys&&!s.upsertKeys.has(y.toLowerCase())?{refused:{why:"notAKey",message:Z(e,"notAKey",y),key:y},target:s}:{target:s}}function Rt(t){return t.keepContactPoints===!0?void 0:new Re}function Ot(t,e){if(!t)return e?{neutralized:!1,fields:[],values:0}:void 0;let n=t.report();return n.values>0?n:void 0}function xe(t,e,n,r,s){let o=s?n.filter(i=>i.name!==s):n,a=t.forObject(e,o);if(a)for(let i of r)a(i)}var x=class extends Error{constructor(n,r=[],s=[],o=[],a){super(r.length===0?`The write of ${n} was cancelled before any of its records was written.`:`The write of ${n} was cancelled after ${r.length} of its records were sent.`);this.objectApiName=n;this.written=r;this.notes=s;this.lookupsLeftOut=o;this.writtenWithoutFields=a;this.name="WriteCancelledError"}objectApiName;written;notes;lookupsLeftOut;writtenWithoutFields};var Ne=class{deps;constructor(e){this.deps=e}async sync(e,n,r){let{outcomes:s,notes:o,currencies:a,lookupsLeftOut:i,writtenWithoutFields:y}=await this.write(e,n,r);return Je(Qe(e.objectApiName,e.operation,s,o,i,y),a)}updateRecords(e,n,r){return this.executeOperation(e,"update",n,r)}async write(e,n,r){let s=null;if(this.deps.describeTargetFields){let u=await Pe(this.deps.describeTargetFields,e.objectApiName,e.operation,e.externalIdField);if("refused"in u){let F=n.map(()=>({success:!1,errors:[u.refused.message]}));return r&&$e(e,F,r),{outcomes:F,notes:[],currencies:[],lookupsLeftOut:[]}}"target"in u&&u.target.creatable.size>0&&(s=u.target)}let o=Ee({config:e,records:n,target:s,run:r}),a=r?r.contactPoints:this.deps.contactPoints;a&&s?.fields&&xe(a,e.objectApiName,s.fields,o.payloads,e.externalIdField);let i=He(o.payloads,o.settled,r),y=new Map(o.held.map(({index:u,reason:F})=>[u,F])),c=u=>{let F=[],P=0;for(let A=0;A<n.length;A++){let d=y.get(A);if(d!==void 0){F.push({success:!1,errors:[d],heldBack:!0});continue}if(P>=u.length)break;F.push(u[P++])}return F},h,m=o.sentAt.filter(u=>u<(r?.standardFirst??0)).length,T=u=>this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField);try{h=o.payloads.length===0&&n.length>0?[]:m>0&&m<o.payloads.length?await Ve(e.objectApiName,T,o.payloads.slice(0,m),o.payloads.slice(m)):await T(o.payloads)}catch(u){if(!(u instanceof x))throw u;let F=je(i,u.written),P=c(u.written);throw De(e,o.withoutRecordType,P,s,r),new x(e.objectApiName,P,[...o.notes,...u.notes],[...F?[F]:[],...u.lookupsLeftOut,...Q(U([...o.deferred,...o.deferredAcross],P))],u.writtenWithoutFields)}let w=await this.retryRefused(e,o.payloads,h,s?.references??null,o.settled);if(r)for(let u of w.ownersRefused)r.links.noteOwnerRefused(u);let W=c(w.outcomes);De(e,o.withoutRecordType,W,s,r);let f=je(i,w.outcomes),v=[...o.notes,...w.notes],R=[...f?[f]:[],...w.lookupsLeftOut],{writtenWithoutFields:L}=w,S=U(o.deferredAcross,W),O=0;if(w.cancelled)throw new x(e.objectApiName,W,v,[...R,...Q([...U(o.deferred,W),...S])],L);if(r){$e(e,W,r),Ze(e,o.payloads,w.outcomes,r.links);let u=await this.setLookups(e,U(o.deferred,W),r.links,!1);if(R.push(...u.leftOut),O=u.unset,u.cancelled)throw new x(e.objectApiName,W,v,[...R,...Q(S)],L)}return{outcomes:W,notes:v,currencies:o.currencies,lookupsLeftOut:R,...L?{writtenWithoutFields:L}:{},...S.length>0?{lookupsToSet:S}:{},...O>0?{lookupsUnset:O}:{}}}async setLookups(e,n,r,s){let o=e.objectApiName,a=new Map,i=new Map,y=new D;for(let{id:f,field:v,parent:R}of n){let L=r.targetOf(R),S=L!==void 0?a:s&&r.refusedObjectOf(R)===void 0?i:void 0;if(!S){y.add(f,v);continue}let O=S.get(f)??{Id:f};O[v]=L??R,S.set(f,O)}let c=new D,h=new D,m=new D,T=new D,w=!1;for(let f of[[...a.values()],[...i.values()]]){if(f.length===0)continue;if(w){for(let R of f)T.addRow(R);continue}let v;try{v=await this.executeOperation(o,"update",f,e.batchSize)}catch(R){if(!(R instanceof x)){let L=R instanceof Error?R.message:String(R);for(let S of f)m.addRow(S,L);continue}v=R.written,w=!0}f.forEach((R,L)=>{let S=v[L];S===void 0?T.addRow(R):S.success?c.addRow(R):S.errors.some(O=>J(O))?h.addRow(R):m.addRow(R,S.errors[0])})}let W=[y,h,m,T];return{...c.records>0?{set:{records:c.records,fields:c.fields()}}:{},leftOut:[y.leftOut("parentRefused"),h.leftOut("notInTarget"),m.leftOut("notSet"),T.leftOut("notReached")].flatMap(f=>f?[f]:[]),unset:new Set(W.flatMap(f=>[...f.recordIds])).size,cancelled:w}}async retryRefused(e,n,r,s,o){let a=Y(e)??void 0,i=[...r],y=[...n],c=n.map(()=>new Set),h=n.map(()=>[]),m=n.map(()=>[]),T=[],w,W=new Set;for(let S=0;S<2&&!w;S++){let O=[],u=[],F=[];if(i.forEach((A,d)=>{if(A.success)return;let l=y[d],g=o[d]??new Set;if(A.errors.some(E=>J(E))){let E=n[d]?.[N];if(typeof E=="string"&&!g.has(N)&&(A.errorDetails??[]).some(p=>J(p.statusCode)&&p.fields.includes(N))&&W.add(E),c[d].has("lookup")||!s||s.size===0)return;let j={},$=!1;for(let p of Object.keys(l)){if(s.has(p)&&!g.has(p)&&l[p]!==null&&l[p]!==void 0){$=!0;continue}j[p]=l[p]}if(!$)return;O.push(d),u.push(j),F.push(null);return}if(c[d].has("fields"))return;let k=he(A.errorDetails,l,a);if(!k||k.some(({field:E})=>g.has(E)))return;let I=new Set(k.map(({field:E})=>E));O.push(d),u.push(Object.fromEntries(Object.entries(l).filter(([E])=>!I.has(E)))),F.push(k)}),O.length===0)break;let P;try{P=await this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField)}catch(A){if(!(A instanceof x)){T.push(...Ye(O,y,u,F,A));break}P=A.written,w=A}P.forEach((A,d)=>{let l=O[d],g=F[d];c[l].add(g===null?"lookup":"fields"),g===null?h[l].push(...Object.keys(y[l]).filter(k=>!(k in u[d]))):m[l].push(...g),y[l]=u[d],i[l]=A})}let f=new Set,v=0,R,L=new Set(W);return i.forEach((S,O)=>{if(!(!S.success||c[O].size===0)){if(h[O].length>0){v++;for(let F of h[O])f.add(F);let u=n[O]?.[N];typeof u=="string"&&h[O].length===1&&h[O][0]===N&&L.add(u)}m[O].length>0&&(R=me(R,{rows:1,fields:m[O].map(u=>({...u,rows:1}))}))}}),{outcomes:i,notes:[...T,...w?.notes??[]],...R?{writtenWithoutFields:R}:{},cancelled:w!==void 0,ownersRefused:[...L],lookupsLeftOut:[...v>0?[{records:v,fields:[...f].sort(),reason:"notInTarget"}]:[],...w?.lookupsLeftOut??[]]}}async executeOperation(e,n,r,s,o){if(this.deps.crudFlsGuard){let a=r.length>0?Object.keys(r[0]):[],i=await this.deps.crudFlsGuard.checkCrudAndFls(e,n,a);if(!i.allowed)throw new Error(`CRUD/FLS check failed for ${n} on ${e}: ${i.reason}`)}switch(n){case"insert":return this.deps.insert(e,r,s);case"update":return this.deps.update(e,r,s);case"upsert":return this.deps.upsert(e,o??"Id",r,s);case"delete":{let a=r.map(i=>i.Id).filter(i=>typeof i=="string");return this.deps.delete(e,a,s)}}}},Ke=["INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","INVALID_CROSS_REFERENCE_KEY"],qe=/cross[- ]reference id|r[ée]f[ée]rence crois[ée]e/i;function J(t){return Ke.some(e=>t.includes(e))||qe.test(t)}var N="OwnerId";function He(t,e,n){let r=new Set;return n&&t.forEach((s,o)=>{let a=s[N];typeof a!="string"||e[o]?.has(N)||n.links.isOwnerRefused(a)&&(delete s[N],r.add(o))}),r}function je(t,e){let n=0;for(let r of t)e[r]?.success&&n++;if(n!==0)return{records:n,fields:[N],reason:"ownerRefusedEarlier"}}function Ye(t,e,n,r,s){let o=s instanceof Error?s.message:String(s),a=new Set,i=new Set,y=0;return r.forEach((c,h)=>{if(c===null){y++;let m=n[h];for(let T of Object.keys(e[t[h]]))T in m||a.add(T)}else for(let{field:m}of c)i.add(m)}),[...y>0?[`${y} record(s) the target refused for a lookup it does not have could not be written again without ${[...a].sort().join(", ")}: ${o}`]:[],...i.size>0?[`${t.length-y} record(s) the target refused on fields it named could not be written again without ${[...i].sort().join(", ")}: ${o}`]:[]]}var D=class{ids=new Set;named=new Set;said;add(e,n){this.ids.add(e),this.named.add(n)}addRow(e,n){let r=String(e.Id);for(let s of Object.keys(e))s!=="Id"&&this.add(r,s);n!==void 0&&n!==""&&(this.said??=n)}get records(){return this.ids.size}get recordIds(){return this.ids}fields(){return[...this.named].sort()}leftOut(e){if(this.ids.size!==0)return{records:this.ids.size,fields:this.fields(),reason:e,...this.said!==void 0?{refusal:this.said}:{}}}};function U(t,e){return t.flatMap(({index:n,field:r,parent:s})=>{let o=e[n];return o?.success&&typeof o.id=="string"&&o.id!==""?[{id:o.id,field:r,parent:s}]:[]})}function vt(t){return new Set(t.map(({id:e})=>e)).size}function Q(t){let e=new D;for(let{id:r,field:s}of t)e.add(r,s);let n=e.leftOut("notReached");return n?[n]:[]}function Me(t,e){if(!(e.success||t!=="insert"&&t!=="upsert"))return e.existingId!==void 0&&e.existingId!==""?e.existingId:void 0}async function Ve(t,e,n,r){let s=await e(n);try{return[...s,...await e(r)]}catch(o){throw o instanceof x?new x(t,[...s,...o.written],o.notes,o.lookupsLeftOut,o.writtenWithoutFields):o}}function De(t,e,n,r,s){if(!s?.createdWithoutRecordType||e.size===0)return;let o=[],a=[];for(let[c,h]of e){let m=n[c];!m?.success||typeof m.id!="string"||m.id===""||t.operation!=="insert"&&m.created!==!0||(o.push(h),a.length<ke&&a.push(m.id))}let i=Ie(s.recordTypesUnderTheLease??r?.recordTypes??[],s.recordTypes),y=Ae(t.objectApiName,o,i);y&&s.createdWithoutRecordType.set(t.objectApiName,{given:y,types:i,ids:a})}function Ze(t,e,n,r){t.objectApiName==="Opportunity"&&(t.operation!=="insert"&&t.operation!=="upsert"||e.forEach((s,o)=>{let a=n[o],i=s[se];!a?.success||typeof a.id!="string"||a.id===""||t.operation!=="insert"&&a.created!==!0||typeof i=="string"&&i!==""&&r.noteSentWithContact(a.id,i)}))}function $e(t,e,n){if(t.operation==="delete")return;let r=t.operation==="insert"||t.operation==="upsert";e.forEach((s,o)=>{let a=n.sources[o]?.Id;if(typeof a!="string"||a==="")return;let i=Me(t.operation,s);s.success&&typeof s.id=="string"&&s.id!==""?n.links.noteWritten(a,s.id):i!==void 0?n.links.noteWritten(a,i):!s.success&&r&&n.links.noteRefused(a,t.objectApiName)})}function Je(t,e){return e.length>0?{...t,currenciesReplaced:[...e]}:t}var _e=1e3;function Qe(t,e,n,r=[],s=[],o){let a=0,i=0,y=0,c,h=[],m=0,T={created:0,updated:0},w={rows:0,written:0,stillLocked:0};for(let f of n)f.lockResends!==void 0&&(w.rows++,f.success?w.written++:we(f.errors,f.errorDetails)&&w.stillLocked++),f.success?(a++,f.created===!0?T.created++:f.created===!1&&T.updated++):Me(e,f)!==void 0?(y++,c??=f.errors[0]):(i++,!f.heldBack&&m++<_e&&h.push(...f.errors));let W=Math.max(0,m-_e);return{objectApiName:t,operation:e,processed:n.length,success:a,failed:i,skipped:y,conflictCount:0,errors:[...h,...r],...y>0?{linkedToExisting:{records:y,...c?{refusal:c}:{}}}:{},...s.length>0?{lookupsLeftOut:[...s]}:{},...o?{writtenWithoutFields:o}:{},...w.rows>0?{sentAgainForALock:w}:{},...W>0?{refusalsDropped:W}:{},...e==="upsert"?{upsertSplit:T}:{}}}export{We as a,Ae as b,Ie as c,Ee as d,yt as e,gt as f,ht as g,Pe as h,Rt as i,Ot as j,xe as k,x as l,Ne as m,vt as n,Q as o,Me as p,Je as q,_e as r,Qe as s};
7
+ import{a as Ce}from"./chunk-GMY5427L.mjs";import{h as Re,i as be,j as Se,k as ke,n as Te,o as Fe}from"./chunk-TEIBWMJM.mjs";import{c as Oe}from"./chunk-BWWQXU2B.mjs";import{f as he,i as me,o as we}from"./chunk-YBZIDW6W.mjs";import{b as fe,c as q,m as pe}from"./chunk-HFSBDM7B.mjs";import{d as K}from"./chunk-OHEOJISY.mjs";import{G as se,q as te,s as ne,t as re,u as oe}from"./chunk-2GSMHGIV.mjs";import{b as ee}from"./chunk-CA5NAXSU.mjs";import{a as z,l as ie,o as ae,q as de,t as ce,u as ue,v as le}from"./chunk-ICIYL45C.mjs";import{b as ye,e as ge}from"./chunk-7BQMBXKX.mjs";import{Sc as X,id as B}from"./chunk-6QSHWIZI.mjs";var H=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function b(t){return t.slice(0,15)}var We=class{constructor(e=new Map){this.earlier=e}earlier;written=new Map;refused=new Map;deleted=new Set;ownersRefused=new Set;contactsSentWith=new Map;noteSentWithContact(e,n){this.contactsSentWith.set(b(e),n)}contactSentWith(e){return this.contactsSentWith.get(b(e))}roleLinkedFor(e){this.contactsSentWith.delete(b(e))}get sentWithAContact(){return this.contactsSentWith.size>0}noteOwnerRefused(e){this.ownersRefused.add(b(e))}isOwnerRefused(e){return this.ownersRefused.has(b(e))}noteDeleted(e){for(let n of e)this.deleted.add(b(n))}standing(e){return e!==void 0&&this.deleted.has(b(e))?void 0:e}noteMatched(e,n){this.noteWritten(e,n)}noteWritten(e,n){this.written.set(b(e),n),this.refused.delete(b(e))}noteRefused(e,n){this.written.has(b(e))||this.refused.set(b(e),n)}targetOf(e){return this.standing(this.written.get(b(e)))??this.standing(this.earlier.get(b(e)))}refusedObjectOf(e){if(this.standing(this.earlier.get(b(e)))===void 0)return this.refused.get(b(e))}};function Ae(t,e,n){if(e.length===0||!n.some(o=>!o.master))return;let r={};for(let o of e)r[o]=(r[o]??0)+1;let s=Se(be(n));return{objectApiName:t,rows:e.length,why:r,...s?{predicted:s}:{}}}function Ie(t,e){return q(t,e?.target??[])}function Y(t){switch(t.operation){case"insert":return null;case"upsert":return t.externalIdField??"Id";case"update":case"delete":return"Id"}}function ze(t,e,n,r,s){let o=ge(t,e);for(let i of n)(!(i.fieldApiName in o)||i.overwriteExisting)&&(o[i.fieldApiName]=i.value);if(!r)return o;let a={};for(let i of Object.keys(o))i!=="attributes"&&(r.has(i)||i===s)&&(a[i]=o[i]);return a}function ve(t,e){return`${t} ${e} record${t===1?"":"s"}`}function Ue(t,e,n){let r=a=>e.find(i=>b(i.recordTypeId)===b(a)),s=t;if(!r(t)&&n){let a=n.mappings.find(i=>b(i.sourceId)===b(t));if(!a){let i=n.source.find(c=>b(c.id)===b(t)),y=i?(n.target??[]).filter(c=>c.sobjectType===i.sobjectType&&c.developerName===i.developerName):[];return{unmapped:i?K(i):"",namesakes:y.map(K)}}s=a.targetId}let o=q(e.filter(a=>b(a.recordTypeId)===b(s)),n?.target??[])[0];return o&&!o.available&&!o.master?{unavailable:o}:o?{sent:s,info:o}:{sent:s}}function Ge(t,e,n){if(t?.personAccounts===!1)return!0;if(!n)return!1;let r=e??Te(t?.recordTypes);return r!==void 0&&!n.has(b(r))}function Le(t,e,n){return{group:`parent:${e}:${n}`,reason:`PARENT_REFUSED: the ${n} record its ${e} names was refused in this run.`,say:r=>`PARENT_REFUSED: ${ve(r,t)} held back, not sent: the ${n} record their ${e} names was refused in this run, and written without it they would stand without their ${n}.`}}function Ee(t){let{config:e,records:n,target:r,run:s}=t,o=e.objectApiName,a=Y(e),i=r?.recordTypes??[],y=r?.references??new Set,c={payloads:[],sentAt:[],settled:[],held:[],deferred:[],deferredAcross:[],notes:[],currencies:[],withoutRecordType:new Map},h=new Map,m=new Map,T=(d,l,g,k)=>{c.held.push({index:d,reason:g}),h.delete(d);let I=m.get(l);I?I.count++:m.set(l,{count:1,say:k})},w=e.operation==="insert"||e.operation==="upsert",W=w&&i.some(d=>!d.master),f=new Map;s&&w&&s.sources.forEach((d,l)=>{let g=d?.Id;typeof g=="string"&&H.test(g)&&f.set(b(g),l)});let v=new Set([...s&&w?s.later??[]:[]].map(d=>d.toLowerCase())),R=new Set(v.size===0?[]:(r?.fields??[]).flatMap(d=>d.isReference&&(d.referenceTo??[]).some(l=>v.has(l.toLowerCase()))&&!(d.nillable===!1&&d.defaultedOnCreate!==!0)?[d.name]:[]));n.forEach((d,l)=>{let g=ze(d,e.fieldMappings,e.addOnFields,r?.creatable??null,a);if(e.operation==="delete"){h.set(l,{payload:g,settled:new Set});return}let k=new Set;if(s)for(let p of Object.keys(g)){let C=g[p];if(p==="RecordTypeId"||!y.has(p)||typeof C!="string"||!H.test(C))continue;if(f.has(b(C))){delete g[p],c.deferred.push({index:l,field:p,parent:C});continue}let _=s.links.targetOf(C);if(_){g[p]=_,k.add(p);continue}let M=s.links.refusedObjectOf(C);if(M===void 0){R.has(p)&&(delete g[p],c.deferredAcross.push({index:l,field:p,parent:C}));continue}let G=Le(o,p,M);T(l,G.group,G.reason,G.say);return}let I=g.RecordTypeId,E,j=Oe(I);if(j)delete g.RecordTypeId;else if(typeof I=="string"&&H.test(I)){let p=Ue(I,i,s?.recordTypes);if("unmapped"in p){let C=p.unmapped,_=p.namesakes.length>0?` The target org's ${p.namesakes.join(" and ")} carries its DeveloperName under another namespace, and a record type is mapped to one of the same namespace only.`:"";T(l,`unmapped:${C}`,"RECORD_TYPE_UNMAPPED: its record type has no counterpart in the target org.",M=>`RECORD_TYPE_UNMAPPED: ${ve(M,o)} held back, not sent: `+(C?`their record type ${C} has no active ${o} record type of that API name in the target org.${_} Create or activate record type ${C} on ${o} in the target org.`:"their record type is inactive in the source org, and has no counterpart in the target org."));return}if("unavailable"in p){let C=p.unavailable;T(l,`unavailable:${C.recordTypeId}`,`RECORD_TYPE_UNAVAILABLE: record type ${C.developerName} is closed to the running user in the target org.`,_=>`${pe({objectApiName:o,recordTypeId:C.recordTypeId,developerName:C.developerName,name:C.name,inactive:!C.active,recordCount:_})} Held back, not sent.`);return}g.RecordTypeId=p.sent,E=p.sent,p.info&&k.add("RecordTypeId")}let $=s?.sources[l]??d;if(re($)){let p=oe($,Ge(r,E,s?.recordTypes?.personTypes));for(let C of Object.keys(g))B(o,C,p)&&delete g[C]}else for(let p of Object.keys(g))B(o,p,"business")&&delete g[p];W&&!("RecordTypeId"in g)&&c.withoutRecordType.set(l,j?"masterInSource":"notRead"),h.set(l,{payload:g,settled:k})});let L=!0;for(;L;){L=!1;for(let{index:d,field:l,parent:g}of c.deferred){let k=f.get(b(g));if(!h.has(d)||k===void 0||h.has(k)||s?.links.targetOf(g)!==void 0)continue;let I=Le(o,l,o);T(d,I.group,I.reason,I.say),L=!0}}c.deferred=c.deferred.filter(({index:d})=>h.has(d)),c.deferredAcross=c.deferredAcross.filter(({index:d})=>h.has(d));for(let d of[...c.withoutRecordType.keys()])h.has(d)||c.withoutRecordType.delete(d);c.held.sort((d,l)=>d.index-l.index);let S=e.operation==="delete"?void 0:s?.currencies,O=r?.creatable.has(z)===!0,u=!O&&(s?.currencyChangesById?.size??0)>0&&r?.fields?.some(d=>d.name===z)===!0,F=S&&(O||u)?ae(r?.fields??[]):void 0,P=[...r?.references??[]],A=new le;for(let[d,{payload:l,settled:g}]of[...h].sort(([k],[I])=>k-I)){for(let k of X(o,l))delete l[k];if(S&&F){let k=s?.sources[d]??n[d],I=k?.[z],E=O?de(l,{read:I,currencyFields:F,ratesOn:ie(o,k)},S):ue(l,{read:I,parent:k?ce(o,k,P,$=>s?.currencyChangesById?.get($)):void 0,currencyFields:F},S);A.add(o,E);let j=k?.Id;E&&typeof j=="string"&&s?.currencyChangesById?.set(j,E)}c.payloads.push(l),c.sentAt.push(d),c.settled.push(g)}return c.notes=[...m.values()].map(({count:d,say:l})=>l(d)),c.currencies=A.list(),c}function V(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:void 0}function Be(t){let e=V(t.length),n=V(t.precision),r=V(t.digits);return{name:t.name,queryable:t.queryable!==!1,createable:t.createable===!0,isReference:t.type==="reference",...t.type!==void 0?{type:t.type}:{},...e!==void 0?{length:e}:{},...t.nillable!==void 0?{nillable:t.nillable}:{},...t.defaultedOnCreate!==void 0?{defaultedOnCreate:t.defaultedOnCreate}:{},...t.calculated===!0?{calculated:!0}:{},...n!==void 0?{precision:n}:{},...n!==void 0&&typeof t.scale=="number"&&t.scale>=0?{scale:t.scale}:{},...r!==void 0?{digits:r}:{},...t.unique===!0?{unique:!0}:{},...t.referenceTo?{referenceTo:[...t.referenceTo]}:{}}}function yt(t){let e=t.fields.filter(r=>r.createable===!0),n=t.fields.some(r=>typeof r.idLookup=="boolean");return{creatable:new Set(e.map(r=>r.name)),references:new Set(e.filter(r=>r.type==="reference").map(r=>r.name)),...typeof t.createable=="boolean"?{objectCreateable:t.createable}:{},...typeof t.updateable=="boolean"?{objectUpdateable:t.updateable}:{},recordTypes:fe(t.recordTypeInfos),...t.name===te?{personAccounts:t.fields.some(r=>r.name===ne)}:{},fields:t.fields.map(Be),...n?{upsertKeys:new Set(t.fields.filter(r=>r.externalId===!0||r.idLookup===!0).map(r=>r.name.toLowerCase()))}:{}}}function Z(t,e,n){switch(e){case"notInTarget":return`Object is not in the target org, or the user the run writes as cannot see it: ${t}. None of its records were sent.`;case"notCreateable":return`Object is not createable on target org: the user the run writes as may not create ${t} records there. None of its records were sent.`;case"notUpdateable":return`Object is not updateable on target org: the user the run writes as may not edit ${t} records there. None of its records were sent.`;case"unread":return`The target org did not describe ${t}${n?` (${n})`:""}, so what it takes could not be told and none of its records were sent.`;case"notAKey":return`The upsert of ${t} matches on ${n??"a field"}, which the target org does not match an upsert on: it takes an External ID field, the Id, or a field its describe marks idLookup. None of its records were sent.`}}function gt(t,e){let n=t.externalIdField?.trim().toLowerCase();if(t.operation!=="upsert"||!n)return t;let r=e.fields?.find(s=>s.name.toLowerCase()===n)?.name;return r===void 0?t:{...t,externalIdField:r}}function ht(t,e){if(t.operation==="delete"||t.query===void 0)return t;let n=Ce(t.query);if(!("list"in n))return t;let r=new Set([...n.list,t.externalIdField??"",...t.fieldMappings.filter(o=>ye.has(o.type)).map(o=>o.sourceField)].map(o=>o.toLowerCase())),s=[...e.creatable].filter(o=>!r.has(o.toLowerCase()));return s.length===0?t:{...t,excludedFields:[...new Set([...t.excludedFields??[],...s])]}}async function Pe(t,e,n,r){let s;try{s=await t(e)}catch(c){if(n==="delete")return{notAsked:!0};let h=Fe(c)?"notInTarget":"unread";return{refused:{why:h,message:Z(e,h,ee(c))}}}let o=n==="insert"||n==="upsert",a=n==="update"||n==="upsert",i=o&&s.objectCreateable===!1?"notCreateable":a&&s.objectUpdateable===!1?"notUpdateable":void 0;if(i)return{refused:{why:i,message:Z(e,i)},target:s};let y=r?.trim()||"Id";return n==="upsert"&&s.upsertKeys&&!s.upsertKeys.has(y.toLowerCase())?{refused:{why:"notAKey",message:Z(e,"notAKey",y),key:y},target:s}:{target:s}}function Rt(t){return t.keepContactPoints===!0?void 0:new Re}function Ot(t,e){if(!t)return e?{neutralized:!1,fields:[],values:0}:void 0;let n=t.report();return n.values>0?n:void 0}function xe(t,e,n,r,s){let o=s?n.filter(i=>i.name!==s):n,a=t.forObject(e,o);if(a)for(let i of r)a(i)}var x=class extends Error{constructor(n,r=[],s=[],o=[],a){super(r.length===0?`The write of ${n} was cancelled before any of its records was written.`:`The write of ${n} was cancelled after ${r.length} of its records were sent.`);this.objectApiName=n;this.written=r;this.notes=s;this.lookupsLeftOut=o;this.writtenWithoutFields=a;this.name="WriteCancelledError"}objectApiName;written;notes;lookupsLeftOut;writtenWithoutFields};var Ne=class{deps;constructor(e){this.deps=e}async sync(e,n,r){let{outcomes:s,notes:o,currencies:a,lookupsLeftOut:i,writtenWithoutFields:y}=await this.write(e,n,r);return Je(Qe(e.objectApiName,e.operation,s,o,i,y),a)}updateRecords(e,n,r){return this.executeOperation(e,"update",n,r)}async write(e,n,r){let s=null;if(this.deps.describeTargetFields){let u=await Pe(this.deps.describeTargetFields,e.objectApiName,e.operation,e.externalIdField);if("refused"in u){let F=n.map(()=>({success:!1,errors:[u.refused.message]}));return r&&$e(e,F,r),{outcomes:F,notes:[],currencies:[],lookupsLeftOut:[]}}"target"in u&&u.target.creatable.size>0&&(s=u.target)}let o=Ee({config:e,records:n,target:s,run:r}),a=r?r.contactPoints:this.deps.contactPoints;a&&s?.fields&&xe(a,e.objectApiName,s.fields,o.payloads,e.externalIdField);let i=He(o.payloads,o.settled,r),y=new Map(o.held.map(({index:u,reason:F})=>[u,F])),c=u=>{let F=[],P=0;for(let A=0;A<n.length;A++){let d=y.get(A);if(d!==void 0){F.push({success:!1,errors:[d],heldBack:!0});continue}if(P>=u.length)break;F.push(u[P++])}return F},h,m=o.sentAt.filter(u=>u<(r?.standardFirst??0)).length,T=u=>this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField);try{h=o.payloads.length===0&&n.length>0?[]:m>0&&m<o.payloads.length?await Ve(e.objectApiName,T,o.payloads.slice(0,m),o.payloads.slice(m)):await T(o.payloads)}catch(u){if(!(u instanceof x))throw u;let F=je(i,u.written),P=c(u.written);throw De(e,o.withoutRecordType,P,s,r),new x(e.objectApiName,P,[...o.notes,...u.notes],[...F?[F]:[],...u.lookupsLeftOut,...Q(U([...o.deferred,...o.deferredAcross],P))],u.writtenWithoutFields)}let w=await this.retryRefused(e,o.payloads,h,s?.references??null,o.settled);if(r)for(let u of w.ownersRefused)r.links.noteOwnerRefused(u);let W=c(w.outcomes);De(e,o.withoutRecordType,W,s,r);let f=je(i,w.outcomes),v=[...o.notes,...w.notes],R=[...f?[f]:[],...w.lookupsLeftOut],{writtenWithoutFields:L}=w,S=U(o.deferredAcross,W),O=0;if(w.cancelled)throw new x(e.objectApiName,W,v,[...R,...Q([...U(o.deferred,W),...S])],L);if(r){$e(e,W,r),Ze(e,o.payloads,w.outcomes,r.links);let u=await this.setLookups(e,U(o.deferred,W),r.links,!1);if(R.push(...u.leftOut),O=u.unset,u.cancelled)throw new x(e.objectApiName,W,v,[...R,...Q(S)],L)}return{outcomes:W,notes:v,currencies:o.currencies,lookupsLeftOut:R,...L?{writtenWithoutFields:L}:{},...S.length>0?{lookupsToSet:S}:{},...O>0?{lookupsUnset:O}:{}}}async setLookups(e,n,r,s){let o=e.objectApiName,a=new Map,i=new Map,y=new D;for(let{id:f,field:v,parent:R}of n){let L=r.targetOf(R),S=L!==void 0?a:s&&r.refusedObjectOf(R)===void 0?i:void 0;if(!S){y.add(f,v);continue}let O=S.get(f)??{Id:f};O[v]=L??R,S.set(f,O)}let c=new D,h=new D,m=new D,T=new D,w=!1;for(let f of[[...a.values()],[...i.values()]]){if(f.length===0)continue;if(w){for(let R of f)T.addRow(R);continue}let v;try{v=await this.executeOperation(o,"update",f,e.batchSize)}catch(R){if(!(R instanceof x)){let L=R instanceof Error?R.message:String(R);for(let S of f)m.addRow(S,L);continue}v=R.written,w=!0}f.forEach((R,L)=>{let S=v[L];S===void 0?T.addRow(R):S.success?c.addRow(R):S.errors.some(O=>J(O))?h.addRow(R):m.addRow(R,S.errors[0])})}let W=[y,h,m,T];return{...c.records>0?{set:{records:c.records,fields:c.fields()}}:{},leftOut:[y.leftOut("parentRefused"),h.leftOut("notInTarget"),m.leftOut("notSet"),T.leftOut("notReached")].flatMap(f=>f?[f]:[]),unset:new Set(W.flatMap(f=>[...f.recordIds])).size,cancelled:w}}async retryRefused(e,n,r,s,o){let a=Y(e)??void 0,i=[...r],y=[...n],c=n.map(()=>new Set),h=n.map(()=>[]),m=n.map(()=>[]),T=[],w,W=new Set;for(let S=0;S<2&&!w;S++){let O=[],u=[],F=[];if(i.forEach((A,d)=>{if(A.success)return;let l=y[d],g=o[d]??new Set;if(A.errors.some(E=>J(E))){let E=n[d]?.[N];if(typeof E=="string"&&!g.has(N)&&(A.errorDetails??[]).some(p=>J(p.statusCode)&&p.fields.includes(N))&&W.add(E),c[d].has("lookup")||!s||s.size===0)return;let j={},$=!1;for(let p of Object.keys(l)){if(s.has(p)&&!g.has(p)&&l[p]!==null&&l[p]!==void 0){$=!0;continue}j[p]=l[p]}if(!$)return;O.push(d),u.push(j),F.push(null);return}if(c[d].has("fields"))return;let k=he(A.errorDetails,l,a);if(!k||k.some(({field:E})=>g.has(E)))return;let I=new Set(k.map(({field:E})=>E));O.push(d),u.push(Object.fromEntries(Object.entries(l).filter(([E])=>!I.has(E)))),F.push(k)}),O.length===0)break;let P;try{P=await this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField)}catch(A){if(!(A instanceof x)){T.push(...Ye(O,y,u,F,A));break}P=A.written,w=A}P.forEach((A,d)=>{let l=O[d],g=F[d];c[l].add(g===null?"lookup":"fields"),g===null?h[l].push(...Object.keys(y[l]).filter(k=>!(k in u[d]))):m[l].push(...g),y[l]=u[d],i[l]=A})}let f=new Set,v=0,R,L=new Set(W);return i.forEach((S,O)=>{if(!(!S.success||c[O].size===0)){if(h[O].length>0){v++;for(let F of h[O])f.add(F);let u=n[O]?.[N];typeof u=="string"&&h[O].length===1&&h[O][0]===N&&L.add(u)}m[O].length>0&&(R=me(R,{rows:1,fields:m[O].map(u=>({...u,rows:1}))}))}}),{outcomes:i,notes:[...T,...w?.notes??[]],...R?{writtenWithoutFields:R}:{},cancelled:w!==void 0,ownersRefused:[...L],lookupsLeftOut:[...v>0?[{records:v,fields:[...f].sort(),reason:"notInTarget"}]:[],...w?.lookupsLeftOut??[]]}}async executeOperation(e,n,r,s,o){if(this.deps.crudFlsGuard){let a=r.length>0?Object.keys(r[0]):[],i=await this.deps.crudFlsGuard.checkCrudAndFls(e,n,a);if(!i.allowed)throw new Error(`CRUD/FLS check failed for ${n} on ${e}: ${i.reason}`)}switch(n){case"insert":return this.deps.insert(e,r,s);case"update":return this.deps.update(e,r,s);case"upsert":return this.deps.upsert(e,o??"Id",r,s);case"delete":{let a=r.map(i=>i.Id).filter(i=>typeof i=="string");return this.deps.delete(e,a,s)}}}},Ke=["INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","INVALID_CROSS_REFERENCE_KEY"],qe=/cross[- ]reference id|r[ée]f[ée]rence crois[ée]e/i;function J(t){return Ke.some(e=>t.includes(e))||qe.test(t)}var N="OwnerId";function He(t,e,n){let r=new Set;return n&&t.forEach((s,o)=>{let a=s[N];typeof a!="string"||e[o]?.has(N)||n.links.isOwnerRefused(a)&&(delete s[N],r.add(o))}),r}function je(t,e){let n=0;for(let r of t)e[r]?.success&&n++;if(n!==0)return{records:n,fields:[N],reason:"ownerRefusedEarlier"}}function Ye(t,e,n,r,s){let o=s instanceof Error?s.message:String(s),a=new Set,i=new Set,y=0;return r.forEach((c,h)=>{if(c===null){y++;let m=n[h];for(let T of Object.keys(e[t[h]]))T in m||a.add(T)}else for(let{field:m}of c)i.add(m)}),[...y>0?[`${y} record(s) the target refused for a lookup it does not have could not be written again without ${[...a].sort().join(", ")}: ${o}`]:[],...i.size>0?[`${t.length-y} record(s) the target refused on fields it named could not be written again without ${[...i].sort().join(", ")}: ${o}`]:[]]}var D=class{ids=new Set;named=new Set;said;add(e,n){this.ids.add(e),this.named.add(n)}addRow(e,n){let r=String(e.Id);for(let s of Object.keys(e))s!=="Id"&&this.add(r,s);n!==void 0&&n!==""&&(this.said??=n)}get records(){return this.ids.size}get recordIds(){return this.ids}fields(){return[...this.named].sort()}leftOut(e){if(this.ids.size!==0)return{records:this.ids.size,fields:this.fields(),reason:e,...this.said!==void 0?{refusal:this.said}:{}}}};function U(t,e){return t.flatMap(({index:n,field:r,parent:s})=>{let o=e[n];return o?.success&&typeof o.id=="string"&&o.id!==""?[{id:o.id,field:r,parent:s}]:[]})}function vt(t){return new Set(t.map(({id:e})=>e)).size}function Q(t){let e=new D;for(let{id:r,field:s}of t)e.add(r,s);let n=e.leftOut("notReached");return n?[n]:[]}function Me(t,e){if(!(e.success||t!=="insert"&&t!=="upsert"))return e.existingId!==void 0&&e.existingId!==""?e.existingId:void 0}async function Ve(t,e,n,r){let s=await e(n);try{return[...s,...await e(r)]}catch(o){throw o instanceof x?new x(t,[...s,...o.written],o.notes,o.lookupsLeftOut,o.writtenWithoutFields):o}}function De(t,e,n,r,s){if(!s?.createdWithoutRecordType||e.size===0)return;let o=[],a=[];for(let[c,h]of e){let m=n[c];!m?.success||typeof m.id!="string"||m.id===""||t.operation!=="insert"&&m.created!==!0||(o.push(h),a.length<ke&&a.push(m.id))}let i=Ie(s.recordTypesUnderTheLease??r?.recordTypes??[],s.recordTypes),y=Ae(t.objectApiName,o,i);y&&s.createdWithoutRecordType.set(t.objectApiName,{given:y,types:i,ids:a})}function Ze(t,e,n,r){t.objectApiName==="Opportunity"&&(t.operation!=="insert"&&t.operation!=="upsert"||e.forEach((s,o)=>{let a=n[o],i=s[se];!a?.success||typeof a.id!="string"||a.id===""||t.operation!=="insert"&&a.created!==!0||typeof i=="string"&&i!==""&&r.noteSentWithContact(a.id,i)}))}function $e(t,e,n){if(t.operation==="delete")return;let r=t.operation==="insert"||t.operation==="upsert";e.forEach((s,o)=>{let a=n.sources[o]?.Id;if(typeof a!="string"||a==="")return;let i=Me(t.operation,s);s.success&&typeof s.id=="string"&&s.id!==""?n.links.noteWritten(a,s.id):i!==void 0?n.links.noteWritten(a,i):!s.success&&r&&n.links.noteRefused(a,t.objectApiName)})}function Je(t,e){return e.length>0?{...t,currenciesReplaced:[...e]}:t}var _e=1e3;function Qe(t,e,n,r=[],s=[],o){let a=0,i=0,y=0,c,h=[],m=0,T={created:0,updated:0},w={rows:0,written:0,stillLocked:0};for(let f of n)f.lockResends!==void 0&&(w.rows++,f.success?w.written++:we(f.errors,f.errorDetails)&&w.stillLocked++),f.success?(a++,f.created===!0?T.created++:f.created===!1&&T.updated++):Me(e,f)!==void 0?(y++,c??=f.errors[0]):(i++,!f.heldBack&&m++<_e&&h.push(...f.errors));let W=Math.max(0,m-_e);return{objectApiName:t,operation:e,processed:n.length,success:a,failed:i,skipped:y,conflictCount:0,errors:[...h,...r],...y>0?{linkedToExisting:{records:y,...c?{refusal:c}:{}}}:{},...s.length>0?{lookupsLeftOut:[...s]}:{},...o?{writtenWithoutFields:o}:{},...w.rows>0?{sentAgainForALock:w}:{},...W>0?{refusalsDropped:W}:{},...e==="upsert"?{upsertSplit:T}:{}}}export{We as a,Ae as b,Ie as c,Ee as d,yt as e,gt as f,ht as g,Pe as h,Rt as i,Ot as j,xe as k,x as l,Ne as m,vt as n,Q as o,Me as p,Je as q,_e as r,Qe as s};
@@ -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 u,j as f}from"./chunk-DPYTG6DM.mjs";var p=1e4,g=150,m=200,l=class{build(o){let t=o.relations??[],c=j(o.objects,t),i=S(c),r=b(c),n=r*g,s=i>p;return{objects:c.map(a=>({objectApiName:a.objectApiName,recordCount:a.recordCount,sampleRecords:C(a,3,u(a.objectApiName,t)),dependsOn:f(a,t)})),totalRecords:i,estimatedApiCalls:r,estimatedDuration:n,grappeRecommended:s}}};function S(e){return e.reduce((o,t)=>o+t.recordCount,0)}function b(e){return e.reduce((o,t)=>{let c=t.batchSize>0?t.batchSize:m;return o+Math.ceil(t.recordCount/c)},0)}function C(e,o,t){let c=Math.min(o,e.recordCount),i=[];for(let r=0;r<c;r++){let n={};for(let d of e.fieldRules)n[d.fieldApiName]=R(d,r);let s=e.rows?.[r];s&&(Object.assign(n,s.values),t?.distribution.mode==="byKey"&&s.parentKey!==void 0&&(n[t.lookupField]=`[key:${s.parentKey}]`)),i.push(n)}return i}function R(e,o){switch(e.ruleType){case"static":return e.config.staticValue??null;case"sequence":{let t=e.config.sequenceStart??1,c=e.config.sequenceStep??1;return`${e.config.sequencePrefix??""}${t+o*c}`}case"picklist_random":return e.config.picklistValues&&e.config.picklistValues.length>0?e.config.picklistValues[o%e.config.picklistValues.length]:null;case"reference":return`[ref:${e.config.referenceObject??"unknown"}]`;case"faker":return`[faker:${e.config.fakerMethod??"lorem"}]`;case"ai_generate":return`[ai:${e.config.aiPrompt??"generated"}]`;case"random":return`sample_${o}`;case"formula":return`[formula:${e.config.formula??""}]`;case"regex":return`[regex:${e.config.regexPattern??""}]`;case"from_csv":return`[csv:${e.config.csvColumn??""}]`;default:return null}}function j(e,o=[]){let t=new Map;for(let n of e)t.set(n.objectApiName,n);let c=new Set,i=[];function r(n){if(c.has(n))return;c.add(n);let s=t.get(n);if(!s)return;let d=f(s,o);for(let a of d)r(a);i.push(s)}for(let n of e)r(n.objectApiName);return i}export{l as a,j as b};
7
+ import{i as u,j as f}from"./chunk-6QSHWIZI.mjs";var p=1e4,g=150,m=200,l=class{build(o){let t=o.relations??[],c=j(o.objects,t),i=S(c),r=b(c),n=r*g,s=i>p;return{objects:c.map(a=>({objectApiName:a.objectApiName,recordCount:a.recordCount,sampleRecords:C(a,3,u(a.objectApiName,t)),dependsOn:f(a,t)})),totalRecords:i,estimatedApiCalls:r,estimatedDuration:n,grappeRecommended:s}}};function S(e){return e.reduce((o,t)=>o+t.recordCount,0)}function b(e){return e.reduce((o,t)=>{let c=t.batchSize>0?t.batchSize:m;return o+Math.ceil(t.recordCount/c)},0)}function C(e,o,t){let c=Math.min(o,e.recordCount),i=[];for(let r=0;r<c;r++){let n={};for(let d of e.fieldRules)n[d.fieldApiName]=R(d,r);let s=e.rows?.[r];s&&(Object.assign(n,s.values),t?.distribution.mode==="byKey"&&s.parentKey!==void 0&&(n[t.lookupField]=`[key:${s.parentKey}]`)),i.push(n)}return i}function R(e,o){switch(e.ruleType){case"static":return e.config.staticValue??null;case"sequence":{let t=e.config.sequenceStart??1,c=e.config.sequenceStep??1;return`${e.config.sequencePrefix??""}${t+o*c}`}case"picklist_random":return e.config.picklistValues&&e.config.picklistValues.length>0?e.config.picklistValues[o%e.config.picklistValues.length]:null;case"reference":return`[ref:${e.config.referenceObject??"unknown"}]`;case"faker":return`[faker:${e.config.fakerMethod??"lorem"}]`;case"ai_generate":return`[ai:${e.config.aiPrompt??"generated"}]`;case"random":return`sample_${o}`;case"formula":return`[formula:${e.config.formula??""}]`;case"regex":return`[regex:${e.config.regexPattern??""}]`;case"from_csv":return`[csv:${e.config.csvColumn??""}]`;default:return null}}function j(e,o=[]){let t=new Map;for(let n of e)t.set(n.objectApiName,n);let c=new Set,i=[];function r(n){if(c.has(n))return;c.add(n);let s=t.get(n);if(!s)return;let d=f(s,o);for(let a of d)r(a);i.push(s)}for(let n of e)r(n.objectApiName);return i}export{l 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,h,i,j,k,l,m}from"./chunk-6CDIIFNX.mjs";import"./chunk-E2YJVSX6.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-3B5H24ZG.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-DPYTG6DM.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{c as LEDGER_KEPT_LINES,b as LEDGER_MAX_LINES,i as OrgClockWatch,a as REWIND_LEDGER_FILE,f as appendToRewindLedger,l as noteRewindEnded,m as noteRewindUndone,g as readRewindLedger,h as readRewindLedgers,k as rewindEndedRecord,e as rewindLedgerBeside,d as rewindLedgerFileOf,j as rewindTotalsOf};
7
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-WBELLGNE.mjs";import"./chunk-N2HYG3BL.mjs";import"./chunk-PC247GKX.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{c as LEDGER_KEPT_LINES,b as LEDGER_MAX_LINES,i as OrgClockWatch,a as REWIND_LEDGER_FILE,f as appendToRewindLedger,l as noteRewindEnded,m as noteRewindUndone,g as readRewindLedger,h as readRewindLedgers,k as rewindEndedRecord,e as rewindLedgerBeside,d as rewindLedgerFileOf,j as rewindTotalsOf};
@@ -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}from"./chunk-OS5GE52G.mjs";import"./chunk-BPHTA6KP.mjs";import"./chunk-U2CTKIPE.mjs";import"./chunk-NDFFIJL5.mjs";import"./chunk-I5C4O3VA.mjs";import"./chunk-RVCPQVKM.mjs";import"./chunk-FKCIGJOI.mjs";import"./chunk-C6RKM4BB.mjs";import"./chunk-IHGYJZZ2.mjs";import"./chunk-XCA5AONB.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-WB2RIVO3.mjs";import"./chunk-AXFD2OH6.mjs";import"./chunk-X2XZQ434.mjs";import"./chunk-CE6ZDGBB.mjs";import"./chunk-O7GCCRPW.mjs";import"./chunk-4X5D3MSV.mjs";import"./chunk-BOGNK4LV.mjs";import"./chunk-XMQ5R6TC.mjs";import"./chunk-IXIY6Q4M.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-54HYHHVL.mjs";import"./chunk-QIRO4HTE.mjs";import"./chunk-BT43WSOS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-EOQON3E5.mjs";import"./chunk-Y7YUNRKK.mjs";import"./chunk-4JKR4PTZ.mjs";import"./chunk-N2HYG3BL.mjs";import"./chunk-7WSQ65WG.mjs";import"./chunk-MJD6CPZZ.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-OUU47Y7A.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-4TLYUZD5.mjs";import"./chunk-VXZ5PTOM.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-ZOSESZ22.mjs";import"./chunk-ZXOUWHYE.mjs";import"./chunk-TQ2TQHTT.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.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-ICIYL45C.mjs";import"./chunk-7BQMBXKX.mjs";import"./chunk-KWAVSZ2B.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{d as CheckpointTakeStopped,a as DEFAULT_MAX_TOTAL,b as OBJECT_ROWS_MAX,f as holdingLimit,e as pastTheLimit,g as scopeCheckpoint,h as takeCheckpoint,c as takeOrgOf};
@@ -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 b,b as S}from"./chunk-VV3B6IC3.mjs";import{b as A}from"./chunk-CA5NAXSU.mjs";import{b as w,f as R,i as x,k as $,l as E,s as O}from"./chunk-WZQEK4WT.mjs";var z=3e4,M=5,P=300,U=E({records:$(O(w(),x())),done:R(),nextRecordsUrl:w().optional()}).loose();function p(n,e=z){let r=(n instanceof b?`the org did not answer within ${Math.round(e/1e3)} s`:`the org refused it: ${A(n)}`).replace(/\s+/g," ").trim();return r.length>P?`${r.slice(0,P-1)}\u2026`:r}var C=class{constructor(e,o={}){this.transport=e;this.timeoutMs=o.timeoutMs??z}transport;sent=0;timeoutMs;get requests(){return this.sent}get timeout(){return this.timeoutMs}async get(e){return this.sent++,new S(this.timeoutMs).withTimeout("env:audit",()=>this.transport.request({method:"GET",url:e}))}asTransport(){return{request:e=>this.get(e.url)}}async query(e,o={}){let r=o.maxPages??M,d=o.tooling===!0?"/tooling/query":"/query",s=N(await this.get(`${d}?q=${encodeURIComponent(e)}`)),i=[...s.records],t=1;for(;!s.done&&s.nextRecordsUrl!==void 0&&t<r&&s.nextRecordsUrl.startsWith("/services/data/");)s=N(await this.get(s.nextRecordsUrl)),i.push(...s.records),t++;return{records:i,truncated:!s.done}}};function N(n){let e=U.safeParse(n);if(!e.success)throw new Error("its answer is not one a query gives");return e.data}function m(n,e){if(e in n)return n[e];let o=e.toLowerCase();for(let r of Object.keys(n))if(r.toLowerCase()===o)return n[r]}function f(n,e){let o=m(n,e);return typeof o=="string"&&o.trim()!==""?o:void 0}function v(n,e){let o=m(n,e);return typeof o=="boolean"?o:void 0}function X(n){if(typeof n!="string")return;let e=Date.parse(n.replace(/([+-]\d\d)(\d\d)$/,"$1:$2"));return Number.isFinite(e)?new Date(e).toISOString():void 0}var q="login.salesforce.com",H=/^([a-z0-9](?:[a-z0-9-]*[a-z0-9])?)--([a-z0-9]+)\.sandbox\.my\.salesforce\.com$/,D=/^[a-z][a-z0-9+.-]*:\/\/[^\s/?#@]+(?:\/[^\s?#]*)?$/,I=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/,J={listed:"a production host the file lists",myDomain:"production's My Domain",lightning:"production's Lightning host",site:"production's sites host",login:"where production orgs sign in"},K={namedCredential:"Named Credential",remoteSite:"Remote Site",field:"Field"};function W(n,e=[]){let o=[],r=(i,t)=>{let a=i.toLowerCase().replace(/\.$/,"");o.some(c=>c.host===a)||o.push({host:a,why:t})},d=n!==void 0?H.exec(n.toLowerCase()):null,s;if(d?.[1]!==void 0){let i=d[1];r(`${i}.my.salesforce.com`,"myDomain"),r(`${i}.lightning.force.com`,"lightning"),r(`${i}.my.site.com`,"site")}else s=n===void 0?"the org's host is not known: production's own hosts are not deduced":`${n} is no sandbox's host of the form <domain>--<sandbox>.sandbox.my.salesforce.com: production's own hosts are not deduced`;r(q,"login");for(let i of e)r(i,"listed");return{hosts:o,...s!==void 0?{notDeduced:s}:{}}}function j(n){let e;try{e=new URL(n.trim())}catch{return}let o=e.hostname.toLowerCase().replace(/\.$/,"");if(!I.test(o))return;let r=e.protocol.replace(/:$/,"").toLowerCase(),d=e.port!==""?`${o}:${e.port}`:o,s=e.pathname.startsWith("/")?e.pathname:"/",i=`${r}://${d}${s}`;if(D.test(i))return{url:i,host:o};let t=`${r}://${d}/`;return D.test(t)?{url:t,host:o}:void 0}function k(n){let e=[];for(let o of n){let r=o.indexOf(".");if(r<=0)continue;let d=o.slice(0,r),s=o.slice(r+1),i=e.find(t=>t.object.toLowerCase()===d.toLowerCase());i===void 0?e.push({object:d,fields:[s]}):i.fields.some(t=>t.toLowerCase()===s.toLowerCase())||i.fields.push(s)}return e}var T=/^[A-Za-z][A-Za-z0-9_]*$/;function Q(n=[]){return 2+k(n).length}async function V(n,e){let o=W(e.host,e.productionHosts??[]),r=[],d=[],s=t=>`${t}: more than the pages read were there, and those past them were not read`;try{let t=await n.query("SELECT DeveloperName, Endpoint FROM NamedCredential",{tooling:!0});for(let a of t.records){let c=f(a,"DeveloperName"),u=f(a,"Endpoint");c!==void 0&&u!==void 0&&r.push({source:"namedCredential",name:c,raw:u})}t.truncated&&d.push(s("Named Credentials"))}catch(t){d.push(`Named Credentials: ${p(t,n.timeout)}`)}try{let t=await n.query("SELECT SiteName, EndpointUrl, IsActive FROM RemoteProxy",{tooling:!0});for(let a of t.records){let c=f(a,"SiteName"),u=f(a,"EndpointUrl");v(a,"IsActive")!==!1&&c!==void 0&&u!==void 0&&r.push({source:"remoteSite",name:c,raw:u})}t.truncated&&d.push(s("Remote Sites"))}catch(t){d.push(`Remote Sites: ${p(t,n.timeout)}`)}for(let{object:t,fields:a}of k(e.fields??[])){if(!T.test(t)||!a.every(l=>T.test(l)))continue;let c=t.toLowerCase().endsWith("__mdt"),u=c?"DeveloperName":"Name",L=c?["DeveloperName",...a]:["Id","Name",...a];try{let l=await n.query(`SELECT ${L.join(", ")} FROM ${t}`,{maxPages:1});for(let h of l.records){let _=f(h,u)??f(h,"Id")??"?";for(let y of a){let g=m(h,y);typeof g!="string"||g.trim()===""||r.push({source:"field",name:`${t}.${_}.${y}`,raw:g})}}l.truncated&&d.push(`${t}: more records than one page were there, and those past it were not read \u2014 a Custom Setting holds a few: is it one?`)}catch(l){d.push(`${t}: ${p(l,n.timeout)}`)}}let i=[];for(let t of r){let a=j(t.raw);if(a===void 0)continue;let c=o.hosts.find(u=>u.host===a.host);c!==void 0&&i.push({source:t.source,name:t.name.slice(0,400),url:a.url,host:a.host,why:c.why})}return{productionHosts:o.hosts.map(t=>t.host),found:i,...o.notDeduced!==void 0?{notDeduced:o.notDeduced}:{},...d.length>0?{unread:d.join("; ").slice(0,2e3)}:{}}}export{p as a,C as b,f as c,v as d,X as e,J as f,K as g,Q as h,V 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{c as I}from"./chunk-UNDIBZWG.mjs";import{a as N,b as O}from"./chunk-CA5NAXSU.mjs";import{b as l,n as m}from"./chunk-WZQEK4WT.mjs";var V="tooling",M={GenAiPlannerDefinition:["Id","DeveloperName","MasterLabel"],GenAiPlannerFunctionDef:["PlannerId","Plugin"],GenAiPluginDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPluginFunctionDef:["PluginId","Function"],GenAiFunctionDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPlannerAttrDefinition:["ParentId","DeveloperName","ParameterName"]},_="DeveloperName",y=200,j="This org has no Agentforce agent: the records this run wrote stay, usable as they are. Create an agent in Setup > Agentforce Agents, then write the test file from this run.",v="This org has no Agentforce, which takes a Salesforce license: it has no GenAiPlannerDefinition, the object that lists its agents. The records this run wrote stay, usable as they are.",g=l().nullish().transform(n=>n==null||n===""?void 0:n),z={GenAiPlannerDefinition:m({Id:l().min(1),DeveloperName:l().min(1),MasterLabel:g}),GenAiPlannerFunctionDef:m({PlannerId:l().min(1),Plugin:g}),GenAiPluginDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPluginFunctionDef:m({PluginId:l().min(1),Function:g}),GenAiFunctionDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPlannerAttrDefinition:m({ParentId:l().min(1),DeveloperName:l().min(1),ParameterName:g})},D=class extends Error{constructor(t,d,s){super(s);this.object=t;this.code=d;this.name="CatalogRefusal"}object;code};async function W(n){try{let e=await E(n,"GenAiPlannerDefinition");if(e.length===0)return{kind:"no-agent",reason:"none",message:j};let t=e.map(a=>a.Id),d=await A(n,"GenAiPlannerFunctionDef","PlannerId",t),s=await A(n,"GenAiPlannerAttrDefinition","ParentId",t),o=await A(n,"GenAiPluginDefinition","Id",d.map(a=>a.Plugin)),i=await A(n,"GenAiPluginFunctionDef","PluginId",o.map(a=>a.Id)),r=await A(n,"GenAiFunctionDefinition","Id",i.map(a=>a.Function)),f=G(o),L=G(r),T=a=>{let u=R(i.filter(p=>b(p.PluginId,a)).map(p=>p.Function),L);return{actions:u.items,unnamedActions:u.unnamed}};return{kind:"agents",catalog:{agents:e.map(a=>{let u=R(d.filter(c=>b(c.PlannerId,a.Id)).map(c=>c.Plugin),f),p=u.items.map((c,x)=>{let w=u.rows[x];return w?{...c,...T(w.Id)}:{...c,actions:[],unnamedActions:0}});return{id:a.Id,name:a.DeveloperName,...a.MasterLabel!==void 0?{label:a.MasterLabel}:{},topics:p,unnamedTopics:u.unnamed,variables:s.filter(c=>b(c.ParentId,a.Id)).map(c=>({name:c.DeveloperName,...c.ParameterName!==void 0?{parameterName:c.ParameterName}:{}}))}}).sort((a,u)=>C(a.name,u.name))}}}catch(e){if(!(e instanceof D))throw e;return e.object==="GenAiPlannerDefinition"&&e.code==="INVALID_TYPE"?{kind:"no-agent",reason:"no-agentforce",message:v}:{kind:"unreadable",object:e.object,message:`The org would not read ${e.object}: ${e.message}`}}}function H(n,e){return n.agents.find(t=>t.name===e)}function Z(n,e){return n.topics.find(t=>t.name===e)?.actions.map(t=>t.name)??[]}var h=["Off_Topic"];function B(n){return n.topics.find(e=>h.includes(e.name)||h.includes(e.localName??""))?.name}function U(n,e){return n.variables.some(t=>t.name===e||t.parameterName===e)}async function E(n,e,t){let d=`SELECT ${M[e].join(", ")} FROM ${e}${t?` WHERE ${t}`:""}`,s;try{s=await n(d)}catch(i){let r=O(i);throw new D(e,k(i)??N(r),r)}let o=z[e];return s.map(i=>{let r=o.safeParse(i);if(!r.success){let f=r.error.issues[0];throw new D(e,void 0,`a row has no ${f.path.join(".")} the catalog can read (${f.message})`)}return r.data})}async function A(n,e,t,d){let s=[...new Set(d.filter(i=>i!==void 0&&I(i)))],o=[];for(let i=0;i<s.length;i+=y){let r=s.slice(i,i+y).map(f=>`'${f}'`);o.push(...await E(n,e,`${t} IN (${r.join(", ")})`))}return o}function k(n){if(typeof n!="object"||n===null)return;let{errorCode:e,name:t}=n;if(typeof e=="string"&&e!=="")return e;if(typeof t=="string"&&/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(t))return t}function P(n){return n.slice(0,15)}function b(n,e){return P(n)===P(e)}function G(n){return new Map(n.map(e=>[P(e.Id),e]))}function R(n,e){let t=new Map,d=0;for(let o of n){if(o===void 0)continue;if(!I(o)){t.has(o)||t.set(o,{item:{name:o,described:!1}});continue}let i=e.get(P(o));if(!i){d++;continue}let r=i[_];t.has(r)||t.set(r,{row:i,item:{name:r,...i.LocalDeveloperName!==void 0?{localName:i.LocalDeveloperName}:{},...i.MasterLabel!==void 0?{label:i.MasterLabel}:{},...i.Description!==void 0?{description:i.Description}:{},described:!0}})}let s=[...t.values()].sort((o,i)=>C(o.item.name,i.item.name));return{items:s.map(o=>o.item),rows:s.map(o=>o.row),unnamed:d}}function C(n,e){return n<e?-1:n>e?1:0}export{V as a,M as b,_ as c,j as d,v as e,W as f,H as g,Z as h,h as i,B as j,U as k};
7
+ import{a as N,b as O}from"./chunk-CA5NAXSU.mjs";import{c as I}from"./chunk-UNDIBZWG.mjs";import{b as l,n as m}from"./chunk-WZQEK4WT.mjs";var V="tooling",M={GenAiPlannerDefinition:["Id","DeveloperName","MasterLabel"],GenAiPlannerFunctionDef:["PlannerId","Plugin"],GenAiPluginDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPluginFunctionDef:["PluginId","Function"],GenAiFunctionDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPlannerAttrDefinition:["ParentId","DeveloperName","ParameterName"]},_="DeveloperName",y=200,j="This org has no Agentforce agent: the records this run wrote stay, usable as they are. Create an agent in Setup > Agentforce Agents, then write the test file from this run.",v="This org has no Agentforce, which takes a Salesforce license: it has no GenAiPlannerDefinition, the object that lists its agents. The records this run wrote stay, usable as they are.",g=l().nullish().transform(n=>n==null||n===""?void 0:n),z={GenAiPlannerDefinition:m({Id:l().min(1),DeveloperName:l().min(1),MasterLabel:g}),GenAiPlannerFunctionDef:m({PlannerId:l().min(1),Plugin:g}),GenAiPluginDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPluginFunctionDef:m({PluginId:l().min(1),Function:g}),GenAiFunctionDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPlannerAttrDefinition:m({ParentId:l().min(1),DeveloperName:l().min(1),ParameterName:g})},D=class extends Error{constructor(t,d,s){super(s);this.object=t;this.code=d;this.name="CatalogRefusal"}object;code};async function W(n){try{let e=await E(n,"GenAiPlannerDefinition");if(e.length===0)return{kind:"no-agent",reason:"none",message:j};let t=e.map(a=>a.Id),d=await A(n,"GenAiPlannerFunctionDef","PlannerId",t),s=await A(n,"GenAiPlannerAttrDefinition","ParentId",t),o=await A(n,"GenAiPluginDefinition","Id",d.map(a=>a.Plugin)),i=await A(n,"GenAiPluginFunctionDef","PluginId",o.map(a=>a.Id)),r=await A(n,"GenAiFunctionDefinition","Id",i.map(a=>a.Function)),f=G(o),L=G(r),T=a=>{let u=R(i.filter(p=>b(p.PluginId,a)).map(p=>p.Function),L);return{actions:u.items,unnamedActions:u.unnamed}};return{kind:"agents",catalog:{agents:e.map(a=>{let u=R(d.filter(c=>b(c.PlannerId,a.Id)).map(c=>c.Plugin),f),p=u.items.map((c,x)=>{let w=u.rows[x];return w?{...c,...T(w.Id)}:{...c,actions:[],unnamedActions:0}});return{id:a.Id,name:a.DeveloperName,...a.MasterLabel!==void 0?{label:a.MasterLabel}:{},topics:p,unnamedTopics:u.unnamed,variables:s.filter(c=>b(c.ParentId,a.Id)).map(c=>({name:c.DeveloperName,...c.ParameterName!==void 0?{parameterName:c.ParameterName}:{}}))}}).sort((a,u)=>C(a.name,u.name))}}}catch(e){if(!(e instanceof D))throw e;return e.object==="GenAiPlannerDefinition"&&e.code==="INVALID_TYPE"?{kind:"no-agent",reason:"no-agentforce",message:v}:{kind:"unreadable",object:e.object,message:`The org would not read ${e.object}: ${e.message}`}}}function H(n,e){return n.agents.find(t=>t.name===e)}function Z(n,e){return n.topics.find(t=>t.name===e)?.actions.map(t=>t.name)??[]}var h=["Off_Topic"];function B(n){return n.topics.find(e=>h.includes(e.name)||h.includes(e.localName??""))?.name}function U(n,e){return n.variables.some(t=>t.name===e||t.parameterName===e)}async function E(n,e,t){let d=`SELECT ${M[e].join(", ")} FROM ${e}${t?` WHERE ${t}`:""}`,s;try{s=await n(d)}catch(i){let r=O(i);throw new D(e,k(i)??N(r),r)}let o=z[e];return s.map(i=>{let r=o.safeParse(i);if(!r.success){let f=r.error.issues[0];throw new D(e,void 0,`a row has no ${f.path.join(".")} the catalog can read (${f.message})`)}return r.data})}async function A(n,e,t,d){let s=[...new Set(d.filter(i=>i!==void 0&&I(i)))],o=[];for(let i=0;i<s.length;i+=y){let r=s.slice(i,i+y).map(f=>`'${f}'`);o.push(...await E(n,e,`${t} IN (${r.join(", ")})`))}return o}function k(n){if(typeof n!="object"||n===null)return;let{errorCode:e,name:t}=n;if(typeof e=="string"&&e!=="")return e;if(typeof t=="string"&&/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(t))return t}function P(n){return n.slice(0,15)}function b(n,e){return P(n)===P(e)}function G(n){return new Map(n.map(e=>[P(e.Id),e]))}function R(n,e){let t=new Map,d=0;for(let o of n){if(o===void 0)continue;if(!I(o)){t.has(o)||t.set(o,{item:{name:o,described:!1}});continue}let i=e.get(P(o));if(!i){d++;continue}let r=i[_];t.has(r)||t.set(r,{row:i,item:{name:r,...i.LocalDeveloperName!==void 0?{localName:i.LocalDeveloperName}:{},...i.MasterLabel!==void 0?{label:i.MasterLabel}:{},...i.Description!==void 0?{description:i.Description}:{},described:!0}})}let s=[...t.values()].sort((o,i)=>C(o.item.name,i.item.name));return{items:s.map(o=>o.item),rows:s.map(o=>o.row),unnamed:d}}function C(n,e){return n<e?-1:n>e?1:0}export{V as a,M as b,_ as c,j as d,v as e,W as f,H as g,Z as h,h as i,B as j,U as k};
@@ -4,5 +4,5 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{b as $e}from"./chunk-OXKZ4Y3B.mjs";import{a as We}from"./chunk-M6P5ZZLE.mjs";import{c as ke,d as Ge}from"./chunk-SW2NUKQL.mjs";import{d as _e,z as Le}from"./chunk-E2YJVSX6.mjs";import{a as k}from"./chunk-4TLYUZD5.mjs";import{a as re}from"./chunk-PPGDAUEQ.mjs";import{a as Me}from"./chunk-VV3B6IC3.mjs";import{m as qe}from"./chunk-CULAOP3U.mjs";import{a as De}from"./chunk-SU65Z2BA.mjs";import{b as xe}from"./chunk-EADHKH3A.mjs";import{a as Te,h as q}from"./chunk-TZE3Y7IQ.mjs";import{a as H,c as Ae,g as oe,j as Pe,n as Ne}from"./chunk-EAFLDSQ2.mjs";import{a as je,b as x}from"./chunk-CA5NAXSU.mjs";import{ac as Z,bc as ee,ca as Ie,cc as te,ja as Fe,wa as ve,za as ue}from"./chunk-DPYTG6DM.mjs";import{b as Ce,e as Ee,i as Re,k as Se,l as de}from"./chunk-WZQEK4WT.mjs";import{appendFile as tt}from"node:fs/promises";var fe=new Set(["Task","Event"]),rt=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,ot="an emptying";function nt(t){let e=q(t.objectApiName),o=fe.has(t.objectApiName),r=[...t.filter!==void 0&&t.filter.trim()!==""?[`(${t.filter})`]:[],...o?["IsDeleted = false"]:[]];return{soql:`SELECT Id FROM ${e}${r.length>0?` WHERE ${r.join(" AND ")}`:""}`,scanAll:o}}async function zt(t,e,o,r={}){let n=()=>r.signal?.aborted===!0,c=[];await Le(e);for(let a of o){let{soql:d,scanAll:u}=nt(a),m={objectApiName:a.objectApiName,count:0};if(c.push(m),n())return{stopped:!0,read:c};let R=ke(e,a.objectApiName),i=!0,h=0,b=await t.query(d,{scanAll:u});for(;;){let S=b.records.map(y=>{let C=y.Id;if(typeof C!="string"||!rt.test(C))throw new Error(`The org answered a ${a.objectApiName} row with no record id: its ids are not read.`);return C});if((S.length>0||i)&&(await tt(R,S.map(y=>`${y}
7
+ import{b as $e}from"./chunk-NS6ONPWL.mjs";import{a as We}from"./chunk-M6P5ZZLE.mjs";import{c as ke,d as Ge}from"./chunk-Y7YUNRKK.mjs";import{d as _e,z as Le}from"./chunk-N2HYG3BL.mjs";import{a as re}from"./chunk-PPGDAUEQ.mjs";import{a as Me}from"./chunk-VV3B6IC3.mjs";import{a as k}from"./chunk-4TLYUZD5.mjs";import{m as qe}from"./chunk-VXZ5PTOM.mjs";import{a as De}from"./chunk-SU65Z2BA.mjs";import{b as xe}from"./chunk-EADHKH3A.mjs";import{a as H,c as Ae,g as oe,j as Pe,n as Ne}from"./chunk-Z3MGN42K.mjs";import{a as Te,h as q}from"./chunk-TZE3Y7IQ.mjs";import{a as je,b as x}from"./chunk-CA5NAXSU.mjs";import{Ac as ee,Bc as te,ca as Ie,ja as Fe,wa as ve,za as ue,zc as Z}from"./chunk-6QSHWIZI.mjs";import{b as Ce,e as Ee,i as Re,k as Se,l as de}from"./chunk-WZQEK4WT.mjs";import{appendFile as tt}from"node:fs/promises";var fe=new Set(["Task","Event"]),rt=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,ot="an emptying";function nt(t){let e=q(t.objectApiName),o=fe.has(t.objectApiName),r=[...t.filter!==void 0&&t.filter.trim()!==""?[`(${t.filter})`]:[],...o?["IsDeleted = false"]:[]];return{soql:`SELECT Id FROM ${e}${r.length>0?` WHERE ${r.join(" AND ")}`:""}`,scanAll:o}}async function zt(t,e,o,r={}){let n=()=>r.signal?.aborted===!0,c=[];await Le(e);for(let a of o){let{soql:d,scanAll:u}=nt(a),m={objectApiName:a.objectApiName,count:0};if(c.push(m),n())return{stopped:!0,read:c};let R=ke(e,a.objectApiName),i=!0,h=0,b=await t.query(d,{scanAll:u});for(;;){let S=b.records.map(y=>{let C=y.Id;if(typeof C!="string"||!rt.test(C))throw new Error(`The org answered a ${a.objectApiName} row with no record id: its ids are not read.`);return C});if((S.length>0||i)&&(await tt(R,S.map(y=>`${y}
8
8
  `).join(""),{encoding:"utf8",mode:_e,flag:i?"w":"a"}),i=!1),m.count+=S.length,r.onPage?.(a.objectApiName,m.count),h=S.length===0?h+1:0,b.done||!b.nextRecordsUrl)break;if(h>=xe)throw new Error(`The org kept answering empty pages of ${a.objectApiName} without saying it was done: ${m.count} id(s) read, the rest not.`);if(n())return{stopped:!0,read:c};b=await t.queryMore(b.nextRecordsUrl)}}return{stopped:!1,spool:await Ge(e,c,ot)}}function ne(t,e,o){return e.nillable!==!1||e.referenceTo.length!==1?!1:e.isMasterDetail||(o??[]).some(r=>r.isCascadeDelete&&r.childSObject===t&&r.field===e.name)}var V=.001,ge=.01,st=50,it=5,at=2,ct=4;function lt(t){return t.level===0||t.recordCount>0||t.status==="error"||t.recordCountUnknown===!0}function Be(t){return t.inputMode==="record"&&typeof t.recordId=="string"&&t.recordId!==""}function pe(t){if(!Fe(t)||t.inputMode!=="soql")return;let e=Ie(t.soqlQuery??"");return e?{where:e.where,limit:e.limit}:void 0}function dt(t,e,o){let r=[];o===0&&Be(t)&&r.push(`Id = '${Te(t.recordId??"")}'`);let n=o===0?pe(t):void 0;n?.where&&r.push(`(${n.where})`);let c=t.objectSoqlFilters?.[e];return c&&r.push(`(${c})`),`SELECT COUNT() FROM ${q(e)}${r.length>0?` WHERE ${r.join(" AND ")}`:""}`}var me=typeof setImmediate=="function"?()=>new Promise(t=>setImmediate(t)):()=>new Promise(t=>setTimeout(t,0)),A=class extends Error{constructor(){super("Discovery cancelled"),this.name="DiscoveryCancelled"}};function M(t,e){return e?e.aborted?Promise.reject(new A):new Promise((o,r)=>{let n=()=>r(new A);e.addEventListener("abort",n,{once:!0}),t().then(c=>{e.removeEventListener("abort",n),o(c)},c=>{e.removeEventListener("abort",n),r(c)})}):t()}function ut(t){return t.fieldCount>0||t.piiFields.length>0}function ft(t,e){if(t.type!=="master-detail")return t;let o=(e.get(t.targetObject)?.fields??[]).filter(n=>n.referenceTo.includes(t.sourceObject)),r=e.get(t.sourceObject)?.childRelationships;return o.some(n=>ne(t.targetObject,n,r))?t:{...t,type:"lookup"}}function Y(){return{nodes:[],edges:[],totalRecords:0,estimatedSizeMB:0,estimatedDurationSeconds:0,truncated:!1}}var Ue=class{deps;constructor(e){this.deps=e}async discover(e,o){if(e.inputMode==="org"||e.depth==="all")return ze(this.deps,e,o);let r=o?.signal;if(r?.aborted)return Y();o?.onProgress?.({phase:"resolving-root",discoveredCount:0,queueRemaining:1});let n=Date.now(),c;try{c=await this.resolveRootObject(e,r)}catch(g){if(g instanceof A)return Y();throw g}let a=Date.now();a-n>2e3&&k.warn(`[forge-discover] resolveRootObject took ${a-n}ms (cold path, consider verifying describeGlobal cache state)`);let d=this.resolveMaxDepth(e),u=o?.maxNodes??st,m=u,R=u*at,i=new Set,h=[],b=u*ct,S=0,y=0,C=new Set,I=[],$=new Map,N=new Map,L=()=>S+y+w.length<m&&I.length+y+w.length<b,W=(g,j)=>{i.has(g)||h.push([g,j]),i.add(g)},D=g=>{i.delete(g)&&(h=h.filter(([j])=>j!==g))},U=new Map,B=(g,j,P,F)=>{if(H(g.sourceObject)||H(g.targetObject)||g.sourceObject===g.targetObject)return;let s=`${g.sourceObject}|${g.targetObject}`,l=U.get(s)??new Map;(P!==void 0||!l.has(j))&&l.set(j,{settable:P,insertOnly:F}),U.set(s,l);let p=$.get(s);if(!p){$.set(s,g);return}let f=g.type==="master-detail"&&p.type==="lookup"?g:p,v=p.required===!0||g.required===!0;$.set(s,v?{...f,required:v}:f)},w=[[c,0]];for(C.add(c);w.length>0&&!r?.aborted;){await me();let g=m-S;if(g<=0)break;let j=Math.min(6,g,w.length),P=w.splice(0,j),F=await Promise.all(P.map(async([s,l])=>{let p,f=!1,v=dt(e,s,l);try{let[E,Q]=await Promise.all([M(()=>this.deps.describeObject(e.sourceOrgId,s,r),r),M(()=>this.deps.queryCount(e.sourceOrgId,v,r),r).catch(_=>{if(_ instanceof A)throw _;return p=x(_),f=se(_),-1})]);return{objectName:s,depth:l,describe:E,recordCount:Q,countError:p,countRefused:f}}catch(E){return E instanceof A||r?.aborted?{objectName:s,depth:l,describe:null,recordCount:-1,cancelled:!0}:{objectName:s,depth:l,describe:null,recordCount:-1,describeError:x(E)}}}));y=F.length;for(let s of F){if(y--,s.cancelled)continue;let{objectName:l,depth:p,describe:f,recordCount:v,countError:E,countRefused:Q,describeError:_}=s;if(!f){I.push({objectApiName:l,recordCount:0,fieldCount:0,status:"error",progress:0,included:!1,piiFields:[],anonymizeFields:[],level:p,successCount:0,failureCount:0,errors:[`Describe unavailable: ${_??"unknown error"}`],createableFieldCount:0,estimatedSizeMB:0,estimatedApiCalls:0,batchStrategy:"auto"}),S++,o?.onProgress?.({phase:"object",objectApiName:l,discoveredCount:I.length,queueRemaining:w.length});continue}N.set(l,f);let ie=v<0,ae=ie&&Q!==!0,ce=ie&&!ae,le=p===0?pe(e)?.limit:void 0,J=ie?0:typeof le=="number"&&Number.isFinite(le)?Math.min(v,le):v,Je=p===0&&(Be(e)||pe(e)!==void 0),be=this.deps.detectPII(f.fields),Ke=f.fields.filter(O=>O.type!=="id").length,Oe={objectApiName:l,...f.label?{label:f.label}:{},recordCount:J,...ae?{recordCountUnknown:!0}:{},fieldCount:f.fields.length,status:ce?"error":"idle",progress:0,included:ce?!1:ae||Je||!e.skipEmpty||J>0,piiFields:be,anonymizeFields:e.anonymizePII?be:[],level:p,successCount:0,failureCount:0,errors:ce?[`Record count unavailable: ${E??"unknown error"}`]:[],createableFieldCount:Ke,estimatedSizeMB:J*V,estimatedApiCalls:Math.ceil(J/200),batchStrategy:"auto"};I.push(Oe);let ye=lt(Oe);if(ye&&S++,p<d&&ye){for(let O of f.fields){if(O.referenceTo.length===0)continue;let we=ee(O),K=we&&Z(l,O.name,O.nillable),Ze=te(O);for(let T of O.referenceTo){B({sourceObject:T,targetObject:l,relationshipName:O.relationshipName??O.name,type:O.isMasterDetail?"master-detail":"lookup",required:K},O.name,we,Ze);let et=i.has(T);(!C.has(T)||K&&et)&&!H(T)&&(L()?(C.add(T),D(T),K?w.unshift([T,p+1]):w.push([T,p+1])):K&&m<R?(C.add(T),D(T),m++,w.unshift([T,p+1])):(C.add(T),W(T,p+1)))}}for(let O of f.childRelationships)B({sourceObject:l,targetObject:O.childSObject,relationshipName:O.relationshipName,type:O.isCascadeDelete?"master-detail":"lookup"},O.field,void 0,void 0),!C.has(O.childSObject)&&!H(O.childSObject)&&(C.add(O.childSObject),L()?w.push([O.childSObject,p+1]):W(O.childSObject,p+1))}o?.onProgress?.({phase:"object",objectApiName:l,discoveredCount:I.length,queueRemaining:w.length})}for(;h.length>0&&L();){let[s,l]=h.shift();i.delete(s),w.push([s,l])}}let z=I.reduce((g,j)=>g+j.recordCount,0),G=[...$].map(([g,j])=>{let P=[...U.get(g)?.values()??[]],F=ft(j,N);return P.length>0&&P.every(s=>s.settable===!1)&&(F={...F,settable:!1}),P.some(s=>s.insertOnly===!0)&&(F={...F,insertOnly:!0}),F});return{nodes:I,edges:G,totalRecords:z,estimatedSizeMB:z*V,estimatedDurationSeconds:z*ge,truncated:h.length>0}}personalFields(e){return this.deps.detectPII(e)}async readPersonalFields(e,o,r){let n=e.nodes.filter(a=>!ut(a)&&a.status!=="error"),c=new Map;for(let a=0;a<n.length&&!r?.aborted;a+=6)await Promise.all(n.slice(a,a+6).map(async({objectApiName:d})=>{try{let u=await this.deps.describeObject(o.sourceOrgId,d,r),m=this.deps.detectPII(u.fields);m.length>0&&c.set(d,m)}catch(u){k.warn(`[forge] personal fields of ${d} not read: ${x(u)}`)}}));return c.size===0?e:{...e,nodes:e.nodes.map(a=>{let d=c.get(a.objectApiName);return d?{...a,piiFields:d,anonymizeFields:o.anonymizePII?[...d]:[]}:a})}}async resolveRootObject(e,o){if(e.inputMode==="record"&&e.recordId){let r=e.recordId.substring(0,3),c=(await M(()=>this.deps.describeGlobal(e.sourceOrgId,o),o)).find(a=>a.keyPrefix===r);if(!c)throw new Error(`No object found for record ID prefix "${r}". The ID may not belong to any accessible object in this org.`);return c.name}if(e.inputMode==="soql"&&e.soqlQuery)return pt(e.soqlQuery);throw new Error(`Cannot resolve root object for inputMode "${e.inputMode}". Provide a valid recordId (for "record" mode) or soqlQuery (for "soql" mode).`)}resolveMaxDepth(e){switch(e.depth){case"direct":return 1;case"full":return it;case"custom":return Math.max(1,Math.min(10,e.customDepth??3));case"all":throw new Error("A clone of the whole org is discovered without a walk (WholeOrgDiscovery)")}}};function pt(t){let e=t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/--[^\n]*/g,"");for(let r=0;r<32;r++){let n=e.replace(/\([^()]*\)/g,"");if(n===e)break;e=n}let o=/\bFROM\s+(\w+)/i.exec(e);if(!o)throw new Error('Could not parse object name from SOQL query. Ensure the query uses standard "SELECT ... FROM ObjectName" syntax.');return q(o[1])}var gt={clone:"write",empty:"delete"},mt=["settings","definition"],ht=new Set(["contentworkspace"]);function bt(t){if(t.name.includes("__"))return!1;let e=t.name.toLowerCase();return ht.has(e)||mt.some(o=>e.endsWith(o))?!0:t.createable===!1&&e!==oe.toLowerCase()}function Ot(t,e){return t.objectApiName<e.objectApiName?-1:t.objectApiName>e.objectApiName?1:0}function yt(t,e,o,r={}){let n=Ne(t,{mode:"everything",access:gt[o],...r.excluded!==void 0?{excluded:r.excluded}:{},...r.customSettings!==void 0?{customSettings:r.customSettings}:{}},e),c=new Map(t.map(u=>[u.name.toLowerCase(),u])),a=[],d=[];for(let u of n.candidates){let m=c.get(u.toLowerCase());m!==void 0&&bt(m)?d.push({objectApiName:u,reason:"configuration"}):a.push(u)}return d.length===0?n:{...n,candidates:a,leftOut:[...n.leftOut,...d].sort(Ot)}}var wt=new Set([oe,Pe].map(t=>t.toLowerCase())),Qe="withTheirRecords",Ct="noLayout";function Et(t){switch(t){case"configuration":return{reason:"setup"};case"chatter":case"history":case"sharing":case"changeEvent":case"unsupportedKind":case"customSetting":case"files":case"setup":case"platformCreated":case"metadata":case"notWritable":case"excludedByUser":return{reason:t};case"heldWithFiles":return{reason:"files",detail:Qe};case"notFound":case"notCustomSetting":return{reason:"missingInTarget"}}}function Rt(t){switch(t){case"platform":return{reason:"platformCreated"};case"setup":return{reason:"setup"};case"feature":case"parent":return{reason:"notWritable",detail:t};case"user":return{reason:"notWritable"}}}function St(t){if(t.createable!==!0||t.queryable!==!0)return;let e=t.updateable===!0,o=t.deletable===!0;if(!(e&&o))return!e&&!o?{reason:"createOnly"}:{reason:"createOnly",detail:e?Ft:It}}var It="noEdit",Ft="noDelete";function vt(t,e){return t.objectApiName<e.objectApiName?-1:t.objectApiName>e.objectApiName?1:0}function He(t,e,o,r={}){let n=yt(e,o,"clone",r),c=new Map(t.map(i=>[i.name.toLowerCase(),i])),a=new Map(e.map(i=>[i.name.toLowerCase(),i])),d=[],u=[],m=new Set,R=(i,h,b)=>{m.add(i.toLowerCase()),u.push({objectApiName:i,reason:h,...b!==void 0?{detail:b}:{}})};for(let i of t)a.has(i.name.toLowerCase())||R(i.name,"missingInTarget");for(let i of n.leftOut){let h=i.objectApiName.toLowerCase(),b=c.get(h);if(!b||m.has(h))continue;let S=a.get(h),y=Et(i.reason),C=h!==oe.toLowerCase();y.reason==="notWritable"&&C&&S?.createable!==!0&&r.createFacts&&(y=Rt(We(b.name,r.createFacts))),y.reason==="notWritable"&&C&&S&&(y=St(S)??y);let I=i.reason==="setup"&&S?.layoutable===!1&&!Ae(i.objectApiName);R(b.name,y.reason,I?Ct:y.detail??i.detail)}for(let i of n.candidates){let h=i.toLowerCase(),b=c.get(h);b&&(b.queryable!==!0?R(b.name,"notQueryable"):wt.has(h)?R(b.name,"files",Qe):d.push(b.name))}return d.sort(),u.sort(vt),{candidates:d,leftOut:u}}var he=1950,Xe=2e4,jt=1e6,Dt=18,Tt=200,At=new Set(["QUERY_TIMEOUT","OPERATION_TOO_LARGE","REQUEST_LIMIT_EXCEEDED","REQUEST_RUNNING_TOO_LONG","SERVER_UNAVAILABLE","UNKNOWN_EXCEPTION"]);function se(t){if(t instanceof Me||De(t))return!1;let e=je(x(t));return e===void 0?!1:!At.has(e)&&!e.startsWith("ERROR_HTTP_")}function Pt(t,e){let o=fe.has(t),r=[...e?[`(${e})`]:[],...o?["IsDeleted = false"]:[]];return{soql:`SELECT COUNT() FROM ${q(t)}${r.length>0?` WHERE ${r.join(" AND ")}`:""}`,all:o}}async function Ve(t,e){let o=0,r=!1,n=()=>r,c=async()=>{for(;!r&&o<t.length;){let a=o++;try{await e(t[a],a,n)}catch(d){throw r=!0,d}}};await Promise.all(Array.from({length:Math.min(6,t.length)},c))}async function Nt(t,e){try{return await t()}catch(o){if(o instanceof A||re(o)||se(o))throw o;return k.warn(`[forge-discover] whole org: describe of ${e} unanswered, asked again: ${x(o)}`),t()}}function Ye(t){if(!(t<=ue))throw new Error(`The source org lists ${t} objects a clone of the whole org leaves out, more than the ${ue} one graph says. Nothing was written. Clone the org in parts instead: a run from a record or from a query for each part.`)}var xt=de({name:Ce().min(1),count:Ee().int().nonnegative()});function Mt(t){let e=de({sObjects:Se(Re())}).safeParse(t);if(!e.success)return;let o=new Map;for(let r of e.data.sObjects){let n=xt.safeParse(r);n.success&&o.set(n.data.name,n.data.count)}return o}function _t(t){let e=new Map;for(let[o,r]of t)for(let n of r.fields){if(n.referenceTo.length===0)continue;let c=ee(n),a=c&&Z(o,n.name,n.nillable),d=te(n);for(let u of n.referenceTo){if(u===o||!t.has(u))continue;let m=`${u}|${o}`,R={sourceObject:u,targetObject:o,relationshipName:n.relationshipName??n.name,type:ne(o,n,t.get(u)?.childRelationships)?"master-detail":"lookup",required:a},i=e.get(m);if(!i){e.set(m,{edge:R,noneSettable:!c,insertOnly:d});continue}let h=R.type==="master-detail"&&i.edge.type==="lookup"?R:i.edge;i.edge={...h,required:i.edge.required===!0||a},i.noneSettable=i.noneSettable&&!c,i.insertOnly=i.insertOnly||d}}return[...e.values()].map(({edge:o,noneSettable:r,insertOnly:n})=>({...o,...r?{settable:!1}:{},...n?{insertOnly:!0}:{}}))}function Lt(t,e){let o=e.filter(qe),r=$e(t,o).reverse(),n=new Map;r.forEach((d,u)=>{for(let m of d)n.set(m,u)});let c=new Map;for(let d of o){let u=c.get(d.targetObject)??[];u.push(d.sourceObject),c.set(d.targetObject,u)}let a=r.map(()=>0);return r.forEach((d,u)=>{for(let m of d)for(let R of c.get(m)??[]){let i=n.get(R);i!==void 0&&i!==u&&(a[u]=Math.max(a[u],a[i]+1))}}),new Map(t.map(d=>[d,Math.min(Dt,1+a[n.get(d)??0])]))}async function ze(t,e,o){let r=ve(e);if(r!==void 0)throw new Error(r);let n=o?.signal;if(n?.aborted)return Y();try{return await kt(t,e,o)}catch(c){if(c instanceof A||n?.aborted)return Y();throw c}}async function kt(t,e,o){let r=o?.signal,n=s=>o?.onProgress?.(s),c=Date.now(),a=s=>l=>{if(l instanceof A)throw l;return k.warn(`[forge-discover] whole org: ${x(l)}`),s},{toolingObjects:d,recordCounts:u,createFacts:m}=t;n({phase:"listing",discoveredCount:0,queueRemaining:0});let[R,i,h,b,S]=await Promise.all([M(()=>t.describeGlobal(e.sourceOrgId,r),r),M(()=>t.describeGlobal(e.targetOrgId,r),r),d?M(()=>d(e.targetOrgId,r),r).catch(a([])):Promise.resolve([]),m?M(()=>m(e.targetOrgId),r).catch(a(void 0)):Promise.resolve(void 0),u?M(()=>u(e.sourceOrgId,r),r).catch(a(void 0)):Promise.resolve(void 0)]),y=Mt(S),C=e.excludedObjects??[],{candidates:I,leftOut:$}=He(R,i,h,{...b?{createFacts:b}:{},...C.length>0?{excluded:C}:{}}),N=[...$];Ye(N.length);let L=I.map(()=>{}),W=0;n({phase:"counting",discoveredCount:0,queueRemaining:I.length,total:I.length}),await Ve(I,async(s,l,p)=>{let f=y?.get(s),v=e.objectSoqlFilters?.[s];if(f!==void 0&&f>jt&&!v)L[l]={objectApiName:s,rows:f,approximate:!0};else try{let{soql:E,all:Q}=Pt(s,v),_=await M(()=>t.queryCount(e.sourceOrgId,E,r,Q?{all:!0}:void 0),r);if(p())return;_>0?L[l]={objectApiName:s,rows:_}:N.push({objectApiName:s,reason:"empty"})}catch(E){if(E instanceof A||re(E))throw E;if(p())return;se(E)?N.push({objectApiName:s,reason:"unreadable",detail:x(E)}):(k.warn(`[forge-discover] whole org: ${s} not counted, kept: ${x(E)}`),L[l]=f!==void 0&&f>0&&!v?{objectApiName:s,rows:f,approximate:!0}:{objectApiName:s,rows:0,unknown:!0})}W++,n({phase:"counting",objectApiName:s,discoveredCount:W,queueRemaining:I.length-W,total:I.length})});let D=L.filter(s=>s!==void 0);if(D.length>he)throw new Error(`The source org holds records in ${D.length} objects a clone of the whole org would take, more than the ${he} one run writes. Nothing was written. Leave ${D.length-he} of them out or more, or clone the org in parts instead: a run from a record or from a query for each part.`);let U=D.map(()=>{}),B=0;n({phase:"describing",discoveredCount:0,queueRemaining:D.length,total:D.length}),await Ve(D,async({objectApiName:s},l,p)=>{try{let f=await Nt(()=>M(()=>t.describeObject(e.sourceOrgId,s,r),r),s);if(p())return;U[l]=f}catch(f){if(f instanceof A||re(f))throw f;if(p())return;N.push({objectApiName:s,reason:"notDescribed",detail:x(f)})}B++,n({phase:"describing",objectApiName:s,discoveredCount:B,queueRemaining:D.length-B,total:D.length})}),await me();let w=new Map,z=new Map;D.forEach((s,l)=>{let p=U[l];p&&(w.set(s.objectApiName,p),z.set(s.objectApiName,s))});let G=_t(w);if(G.length>Xe)throw new Error(`The ${w.size} objects of the source org a clone of the whole org would take relate ${G.length} pairs of objects, more than the ${Xe} one run writes in order. Nothing was written. Clone the org in parts instead: a run from a record or from a query for each part.`);let g=[...w.keys()],j=Lt(g,G),P=g.map(s=>{let l=w.get(s),p=z.get(s),f=p.rows,v=t.detectPII(l.fields);return{objectApiName:s,...l.label?{label:l.label}:{},recordCount:f,...p.approximate?{recordCountApproximate:!0}:{},...p.unknown?{recordCountUnknown:!0}:{},fieldCount:l.fields.length,status:"idle",progress:0,included:!0,piiFields:v,anonymizeFields:e.anonymizePII?[...v]:[],level:j.get(s)??1,successCount:0,failureCount:0,errors:[],createableFieldCount:l.fields.filter(E=>E.type!=="id").length,estimatedSizeMB:f*V,estimatedApiCalls:Math.ceil(f/Tt),batchStrategy:"auto"}});Ye(N.length);let F=P.reduce((s,l)=>s+l.recordCount,0);return N.sort((s,l)=>s.objectApiName<l.objectApiName?-1:s.objectApiName>l.objectApiName?1:0),k.info(`[forge-discover] whole org: ${P.length} object(s), ${G.length} relation(s), ${N.length} left out, ${F} record(s), in ${Date.now()-c}ms`),{nodes:P,edges:G,totalRecords:F,estimatedSizeMB:F*V,estimatedDurationSeconds:F*ge,truncated:!1,leftOut:N}}export{fe as a,ot as b,zt as c,ne as d,st as e,it as f,at as g,lt as h,ut as i,Ue as j,yt as k,he as l,Xe as m,se as n,Ve as o,Mt as p,ze as q};
@@ -4,6 +4,6 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{Ic as m,Nc as l,Qc as p}from"./chunk-CAFUNR6D.mjs";import{mkdirSync as $,statSync as A}from"node:fs";import{homedir as k}from"node:os";import{join as g,resolve as x}from"node:path";var y=448;function D(e=process.env){return S("backups",e)}function S(e,r=process.env){let t=r.SANDFORGE_JOURNAL_DIR,n=t!==void 0&&t.trim()!==""?x(t):g(k(),".sandforge");return g(n,e)}var w={mkdir:(e,r)=>{$(e,r)},stat:e=>A(e),...typeof process.getuid=="function"?{uid:()=>process.getuid?.()??-1}:{}};function I(e,r=w){try{r.mkdir(e,{recursive:!0,mode:y});let t=r.stat(e);if(!t.isDirectory())return`The store ${e} is not a folder.`;let n=r.uid?.();return n!==void 0&&t.uid!==n?`The store ${e} belongs to another user, who can read its snapshots and change them: name a folder of your own with --store.`:void 0}catch(t){return`The store ${e} could not be made: ${t instanceof Error?t.message:String(t)}`}}function B(e){if(e!==void 0)return/^\d{1,5}$/.test(e)||(process.stderr.write(`Not a number of days: "${e}"
7
+ import{Ic as m,Nc as l,Qc as p}from"./chunk-AXFD2OH6.mjs";import{mkdirSync as $,statSync as A}from"node:fs";import{homedir as k}from"node:os";import{join as g,resolve as x}from"node:path";var y=448;function D(e=process.env){return S("backups",e)}function S(e,r=process.env){let t=r.SANDFORGE_JOURNAL_DIR,n=t!==void 0&&t.trim()!==""?x(t):g(k(),".sandforge");return g(n,e)}var w={mkdir:(e,r)=>{$(e,r)},stat:e=>A(e),...typeof process.getuid=="function"?{uid:()=>process.getuid?.()??-1}:{}};function I(e,r=w){try{r.mkdir(e,{recursive:!0,mode:y});let t=r.stat(e);if(!t.isDirectory())return`The store ${e} is not a folder.`;let n=r.uid?.();return n!==void 0&&t.uid!==n?`The store ${e} belongs to another user, who can read its snapshots and change them: name a folder of your own with --store.`:void 0}catch(t){return`The store ${e} could not be made: ${t instanceof Error?t.message:String(t)}`}}function B(e){if(e!==void 0)return/^\d{1,5}$/.test(e)||(process.stderr.write(`Not a number of days: "${e}"
8
8
  `),process.exit(2)),Number(e)}function E(e,r){return e.flatMap((t,n)=>t===r&&n+1<e.length?[e[n+1]??""]:[])}function F(e){let r=[];for(let t of e){/^[1-9]\d{0,5}(,[1-9]\d{0,5})*$/.test(t)||(process.stderr.write(`Not a slice's number: "${t}". Give --slice 2, or --slice 1,3.
9
9
  `),process.exit(2));for(let n of t.split(",").map(Number))r.includes(n)||r.push(n)}return r.sort((t,n)=>t-n)}function C(e){return(r,t)=>r==="backup.maxRecordsPerObject"&&e.maxRecords!==void 0?e.maxRecords:r==="backup.maxAgeDays"&&e.maxAgeDays!==void 0?e.maxAgeDays:t}function M(e){let r=`removed snapshot ${e.operationId}${e.takenAt!==void 0?`, taken ${e.takenAt}`:""}: past the retention of ${e.days} day(s) (--max-age-days, 0 keeps them all)`;return e.syncRunId!==void 0?`${r}. It held what the Sync run ${e.syncRunId||"(unknown)"} wrote over: removing that run with sandforge sync --remove no longer puts those values back`:r}var j=1440*6e4;function _(e,r,t={}){let n=e.get(`backup:${r}`);if(n){let o=(n.objects??[]).map(s=>({objectApiName:s.objectApiName,records:s.recordCount??0}));return{words:n.origin==="slice"&&n.setId!==void 0?`slice ${n.slice?.index??"?"} of set ${n.setId}`:`snapshot ${r}`,objects:o,totalRecords:n.totalRecords??o.reduce((s,f)=>s+f.records,0)}}let a=new p(e).get(r);if(!a)return;let c=a.objects.flatMap(o=>o.slices.filter(s=>s.state!=="pending").map(s=>({objectApiName:o.objectApiName,slice:s}))),i=t.slices,d=i?c.filter(o=>i.includes(o.slice.index)):t.rewriteAll===!0?c:c.filter(o=>o.slice.restoredAt===void 0),u=[];for(let{objectApiName:o,slice:s}of d){let f=u.find(h=>h.objectApiName===o);f?f.records+=s.rows:u.push({objectApiName:o,records:s.rows})}let b=i?`slice(s) ${i.join(", ")}`:t.rewriteAll===!0?"every slice":`the ${d.length} slice(s) not put back yet`;return{words:`set ${r} (${b}, of ${c.length})`,objects:u,totalRecords:u.reduce((o,s)=>o+s.records,0)}}function L(e){let r=e.slices;return Array.isArray(r)?r.map(t=>t.skipped===!0?` slice ${t.index} ${t.objectApiName} put back before, not read again (--slice or --rewrite-all puts it back again)`:` slice ${t.index} ${t.objectApiName} put back ${t.restored} refused ${t.failed} unchanged ${t.unchanged}`):[]}function P(e){return new p(e).list()}function N(e,r){let t=Date.parse(e.lastActivityAt);if(!(r<=0||!Number.isFinite(t)))return new Date(t+r*j).toISOString().slice(0,10)}function J(e,r){let t=m(e),n=t.reduce((i,d)=>i+d.rows,0),a=e.objects.map(i=>`${i.objectApiName}${i.where!==void 0?` (where ${i.where})`:""}`).join(", "),c=N(e,r);return`${e.setId} ${e.startedAt} ${e.orgId} ${a} ${t.length} slice(s) of up to ${e.size} ${n} record(s) ${e.kind}, ${l(e)} `+(c!==void 0?`expires ${c}`:"kept (--max-age-days 0)")}export{D as a,S as b,I as c,B as d,E as e,F as f,C as g,M as h,_ as i,L as j,P as k,N as l,J as m};