sandforge 0.0.0-stage → 1.79.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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -2
  3. package/THIRD-PARTY-NOTICES.md +1624 -0
  4. package/bin/sandforge-autopilot.mjs +12 -0
  5. package/bin/sandforge-backup.mjs +12 -0
  6. package/bin/sandforge-checkpoint.mjs +12 -0
  7. package/bin/sandforge-cleanup.mjs +12 -0
  8. package/bin/sandforge-clone.mjs +12 -0
  9. package/bin/sandforge-compare.mjs +12 -0
  10. package/bin/sandforge-dataops.mjs +12 -0
  11. package/bin/sandforge-empty.mjs +12 -0
  12. package/bin/sandforge-env.mjs +12 -0
  13. package/bin/sandforge-frozen.mjs +12 -0
  14. package/bin/sandforge-mcp.mjs +12 -0
  15. package/bin/sandforge-monitor.mjs +12 -0
  16. package/bin/sandforge-seed.mjs +12 -0
  17. package/bin/sandforge-sync.mjs +12 -0
  18. package/bin/sandforge.mjs +12 -0
  19. package/lib/catalogue.en.json +1 -0
  20. package/lib/chunk-2BVTCNWA.mjs +7 -0
  21. package/lib/chunk-2S5OMIIA.mjs +7 -0
  22. package/lib/chunk-2YIV2OB2.mjs +7 -0
  23. package/lib/chunk-342FN7AO.mjs +9 -0
  24. package/lib/chunk-36U7IQ6Y.mjs +25 -0
  25. package/lib/chunk-3CA767QB.mjs +7 -0
  26. package/lib/chunk-3DCUADVK.mjs +7 -0
  27. package/lib/chunk-3F5YMM2F.mjs +7 -0
  28. package/lib/chunk-3OHPD72J.mjs +9 -0
  29. package/lib/chunk-3RYLICRX.mjs +7 -0
  30. package/lib/chunk-3SRXFZSD.mjs +7 -0
  31. package/lib/chunk-42RER7V4.mjs +14 -0
  32. package/lib/chunk-4GL773D5.mjs +7 -0
  33. package/lib/chunk-4HFRHFGQ.mjs +7 -0
  34. package/lib/chunk-4HW535YJ.mjs +7 -0
  35. package/lib/chunk-4NAHW2D3.mjs +7 -0
  36. package/lib/chunk-4SNDMJP2.mjs +7 -0
  37. package/lib/chunk-4TLYUZD5.mjs +7 -0
  38. package/lib/chunk-4U6NXJNL.mjs +7 -0
  39. package/lib/chunk-4XZ5YT5O.mjs +7 -0
  40. package/lib/chunk-55HEMHEG.mjs +7 -0
  41. package/lib/chunk-57VHUYNG.mjs +10 -0
  42. package/lib/chunk-5AJRHRXA.mjs +20 -0
  43. package/lib/chunk-5CD257T7.mjs +7 -0
  44. package/lib/chunk-5HMAPZBV.mjs +7 -0
  45. package/lib/chunk-5LFSFYFJ.mjs +7 -0
  46. package/lib/chunk-5MMXFWPD.mjs +7 -0
  47. package/lib/chunk-5O6JOMHS.mjs +13 -0
  48. package/lib/chunk-5P4PHJRL.mjs +9 -0
  49. package/lib/chunk-5QKTYCWE.mjs +11 -0
  50. package/lib/chunk-66NMFCWX.mjs +7 -0
  51. package/lib/chunk-6EBMEGZB.mjs +7 -0
  52. package/lib/chunk-6LAXTAVN.mjs +7 -0
  53. package/lib/chunk-6MUEPV7M.mjs +9 -0
  54. package/lib/chunk-6QSM2WIH.mjs +10 -0
  55. package/lib/chunk-75ADZS6B.mjs +7 -0
  56. package/lib/chunk-7EANH5PY.mjs +68 -0
  57. package/lib/chunk-7F54PZUS.mjs +7 -0
  58. package/lib/chunk-7UQD6V6F.mjs +7 -0
  59. package/lib/chunk-AAVJ5XVX.mjs +7 -0
  60. package/lib/chunk-ALJVEUUS.mjs +7 -0
  61. package/lib/chunk-ALUFROGA.mjs +7 -0
  62. package/lib/chunk-AR7BE5O2.mjs +7 -0
  63. package/lib/chunk-AUTM6H6Z.mjs +7 -0
  64. package/lib/chunk-AV5SWEHP.mjs +9 -0
  65. package/lib/chunk-B45CNPUX.mjs +47 -0
  66. package/lib/chunk-BILZ3SSR.mjs +7 -0
  67. package/lib/chunk-BN7A4GRQ.mjs +7 -0
  68. package/lib/chunk-BOGNK4LV.mjs +7 -0
  69. package/lib/chunk-BS5T3MOQ.mjs +7 -0
  70. package/lib/chunk-BZ24IAP5.mjs +7 -0
  71. package/lib/chunk-CA5NAXSU.mjs +7 -0
  72. package/lib/chunk-CE6ZDGBB.mjs +7 -0
  73. package/lib/chunk-CGWXQX75.mjs +7 -0
  74. package/lib/chunk-CHCHAE4B.mjs +7 -0
  75. package/lib/chunk-D3QRXG63.mjs +787 -0
  76. package/lib/chunk-DBFJB2B6.mjs +7 -0
  77. package/lib/chunk-DLDX6RRC.mjs +7 -0
  78. package/lib/chunk-EADHKH3A.mjs +7 -0
  79. package/lib/chunk-EEVVGGM6.mjs +7 -0
  80. package/lib/chunk-ENLBYECD.mjs +7 -0
  81. package/lib/chunk-EQF2IJS2.mjs +11 -0
  82. package/lib/chunk-EQOQASDQ.mjs +7 -0
  83. package/lib/chunk-F2424IKX.mjs +7 -0
  84. package/lib/chunk-F74IHMGL.mjs +7 -0
  85. package/lib/chunk-FOVVHGEP.mjs +7 -0
  86. package/lib/chunk-FQBRBBY4.mjs +7 -0
  87. package/lib/chunk-FQGHL7GR.mjs +259 -0
  88. package/lib/chunk-GAM726CK.mjs +7 -0
  89. package/lib/chunk-GCOB7K5N.mjs +7 -0
  90. package/lib/chunk-GMY5427L.mjs +7 -0
  91. package/lib/chunk-GNC27UEU.mjs +7 -0
  92. package/lib/chunk-H2PJNIYJ.mjs +7 -0
  93. package/lib/chunk-H45UXY6G.mjs +7 -0
  94. package/lib/chunk-HCIDVIOW.mjs +7 -0
  95. package/lib/chunk-HF6LAK3G.mjs +7 -0
  96. package/lib/chunk-HJC7AIBK.mjs +7 -0
  97. package/lib/chunk-HJKM3E56.mjs +7 -0
  98. package/lib/chunk-HTJ5OGP5.mjs +7 -0
  99. package/lib/chunk-HUMEKZT5.mjs +8 -0
  100. package/lib/chunk-HV2MXMGI.mjs +7 -0
  101. package/lib/chunk-HXS7ORUF.mjs +11 -0
  102. package/lib/chunk-I3JKJTLO.mjs +110 -0
  103. package/lib/chunk-I7O6C2B5.mjs +8 -0
  104. package/lib/chunk-IAZB4WIL.mjs +7 -0
  105. package/lib/chunk-IC2C2GOF.mjs +8 -0
  106. package/lib/chunk-IEYG5ATY.mjs +7 -0
  107. package/lib/chunk-INIQ23K6.mjs +7 -0
  108. package/lib/chunk-INIT2UKJ.mjs +7 -0
  109. package/lib/chunk-J7HVXMSW.mjs +7 -0
  110. package/lib/chunk-JVL444U5.mjs +7 -0
  111. package/lib/chunk-K22PA4XL.mjs +7 -0
  112. package/lib/chunk-K2FBZIXY.mjs +7 -0
  113. package/lib/chunk-KLX67VPL.mjs +7 -0
  114. package/lib/chunk-L776PUMV.mjs +7 -0
  115. package/lib/chunk-LQ4DRFUH.mjs +9 -0
  116. package/lib/chunk-LRFAIUN7.mjs +7 -0
  117. package/lib/chunk-LV6G4XTK.mjs +7 -0
  118. package/lib/chunk-M6P5ZZLE.mjs +7 -0
  119. package/lib/chunk-MTMH6H2A.mjs +8 -0
  120. package/lib/chunk-MYTIL2JD.mjs +10 -0
  121. package/lib/chunk-NEVXIGR6.mjs +10 -0
  122. package/lib/chunk-NGSMZZDA.mjs +7 -0
  123. package/lib/chunk-NHWE66K5.mjs +7 -0
  124. package/lib/chunk-NM4MDLK4.mjs +7 -0
  125. package/lib/chunk-NTDN2JQZ.mjs +19 -0
  126. package/lib/chunk-NTOVCTRS.mjs +7 -0
  127. package/lib/chunk-NZ5ZZLKS.mjs +7 -0
  128. package/lib/chunk-OQOZAPCI.mjs +7 -0
  129. package/lib/chunk-OTWRDD6L.mjs +7 -0
  130. package/lib/chunk-P2PJYWGQ.mjs +7 -0
  131. package/lib/chunk-P42X3B4D.mjs +7 -0
  132. package/lib/chunk-P7GSGFJO.mjs +7 -0
  133. package/lib/chunk-PA3MKJVH.mjs +7 -0
  134. package/lib/chunk-PBI4BYWW.mjs +7 -0
  135. package/lib/chunk-PNCONNFJ.mjs +10 -0
  136. package/lib/chunk-PTTHSSQO.mjs +7 -0
  137. package/lib/chunk-PUOX4NBJ.mjs +8 -0
  138. package/lib/chunk-PZTSVQSF.mjs +7 -0
  139. package/lib/chunk-QPF6C5MX.mjs +7 -0
  140. package/lib/chunk-QQZZMKU3.mjs +7 -0
  141. package/lib/chunk-QROPNEGY.mjs +14 -0
  142. package/lib/chunk-QRV2OSIS.mjs +7 -0
  143. package/lib/chunk-QSRAEUGZ.mjs +7 -0
  144. package/lib/chunk-QWT2C74M.mjs +7 -0
  145. package/lib/chunk-RAAANPPG.mjs +7 -0
  146. package/lib/chunk-RACDTRZA.mjs +7 -0
  147. package/lib/chunk-RFEO2KAN.mjs +7 -0
  148. package/lib/chunk-RH3N2H7P.mjs +7 -0
  149. package/lib/chunk-RSWDYIHY.mjs +37 -0
  150. package/lib/chunk-RSYICMZG.mjs +8 -0
  151. package/lib/chunk-SAR5622P.mjs +7 -0
  152. package/lib/chunk-SBIMVCXT.mjs +101 -0
  153. package/lib/chunk-SCKUIE3R.mjs +7 -0
  154. package/lib/chunk-SFURUNJM.mjs +7 -0
  155. package/lib/chunk-SIOZXPFG.mjs +7 -0
  156. package/lib/chunk-SRPWW4A2.mjs +10 -0
  157. package/lib/chunk-SRQDABQ2.mjs +15 -0
  158. package/lib/chunk-SVS6UMDU.mjs +323 -0
  159. package/lib/chunk-T63U4OZJ.mjs +7 -0
  160. package/lib/chunk-TBZMC2VV.mjs +11 -0
  161. package/lib/chunk-TEOLMRDO.mjs +7 -0
  162. package/lib/chunk-TLH7AD35.mjs +7 -0
  163. package/lib/chunk-TNXUU6W7.mjs +14 -0
  164. package/lib/chunk-TQX3PURV.mjs +7 -0
  165. package/lib/chunk-TUACWKIH.mjs +7 -0
  166. package/lib/chunk-TW3N6W5Z.mjs +7 -0
  167. package/lib/chunk-TYYOBZMU.mjs +10 -0
  168. package/lib/chunk-TZE3Y7IQ.mjs +7 -0
  169. package/lib/chunk-UNDIBZWG.mjs +7 -0
  170. package/lib/chunk-VGW4MXXZ.mjs +7 -0
  171. package/lib/chunk-VHI54FBK.mjs +441 -0
  172. package/lib/chunk-VXHDBYMI.mjs +7 -0
  173. package/lib/chunk-W7KFAY55.mjs +7 -0
  174. package/lib/chunk-WFEB5X4U.mjs +8 -0
  175. package/lib/chunk-WIO4XO4F.mjs +7 -0
  176. package/lib/chunk-WJY54JO7.mjs +13 -0
  177. package/lib/chunk-WR2GIKWE.mjs +7 -0
  178. package/lib/chunk-WRU5FJFC.mjs +7 -0
  179. package/lib/chunk-X2PY6MWZ.mjs +7 -0
  180. package/lib/chunk-X65MT4W3.mjs +7 -0
  181. package/lib/chunk-XBG5SP6Q.mjs +7 -0
  182. package/lib/chunk-XCA5AONB.mjs +7 -0
  183. package/lib/chunk-XEFDB2R4.mjs +7 -0
  184. package/lib/chunk-XETCPL7E.mjs +7 -0
  185. package/lib/chunk-Y5CGXLUB.mjs +7 -0
  186. package/lib/chunk-Y6J6QFI2.mjs +7 -0
  187. package/lib/chunk-YAZO75G2.mjs +8 -0
  188. package/lib/chunk-YBU4Z4QV.mjs +7 -0
  189. package/lib/chunk-YMJVMFPY.mjs +7 -0
  190. package/lib/chunk-YPSRZRIT.mjs +7 -0
  191. package/lib/chunk-YS4G22C2.mjs +7 -0
  192. package/lib/chunk-YW2SBL4Z.mjs +7 -0
  193. package/lib/chunk-YYZL7UGV.mjs +7 -0
  194. package/lib/chunk-Z7X534S4.mjs +10 -0
  195. package/lib/chunk-ZE6HKRR4.mjs +9 -0
  196. package/lib/chunk-ZHJP7L3K.mjs +7 -0
  197. package/lib/chunk-ZJKCWBRJ.mjs +7 -0
  198. package/lib/chunk-ZLZRU6MO.mjs +7 -0
  199. package/lib/chunk-ZOVSMN5C.mjs +7 -0
  200. package/lib/chunk-ZPYJPGDK.mjs +7 -0
  201. package/lib/chunk-ZQOZ4EFW.mjs +7 -0
  202. package/lib/chunk-ZUTYVST5.mjs +7 -0
  203. package/lib/chunk-ZXH4MBWP.mjs +7 -0
  204. package/lib/chunk-ZYEE34WO.mjs +7 -0
  205. package/lib/sandforge-autopilot.mjs +157 -0
  206. package/lib/sandforge-backup.mjs +99 -0
  207. package/lib/sandforge-checkpoint.mjs +353 -0
  208. package/lib/sandforge-cleanup.mjs +56 -0
  209. package/lib/sandforge-clone.mjs +7 -0
  210. package/lib/sandforge-compare.mjs +54 -0
  211. package/lib/sandforge-dataops.mjs +7 -0
  212. package/lib/sandforge-empty.mjs +140 -0
  213. package/lib/sandforge-env.mjs +355 -0
  214. package/lib/sandforge-frozen.mjs +263 -0
  215. package/lib/sandforge-mcp.mjs +40 -0
  216. package/lib/sandforge-monitor.mjs +43 -0
  217. package/lib/sandforge-seed.mjs +7 -0
  218. package/lib/sandforge-sync.mjs +7 -0
  219. package/lib/sandforge.mjs +28 -0
  220. package/package.json +52 -4
@@ -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{p as ne,q as De}from"./chunk-ENLBYECD.mjs";import{D as Fe,V as Ne,xa as Ie}from"./chunk-ZLZRU6MO.mjs";import{a as _e,b as Me}from"./chunk-HF6LAK3G.mjs";import{j as xe,k as ve,l as Ce,m as $e,n as je}from"./chunk-PNCONNFJ.mjs";import{D as $,Z as Te,b as C,ca as Pe,p as W,q as G,s as re}from"./chunk-CGWXQX75.mjs";import{b as R}from"./chunk-CA5NAXSU.mjs";import{Hc as be,Jc as ye,Lc as ee,Mc as we,Oc as x,Pc as Re,Qc as te,Sc as L,Xc as Ae,Yc as Ee,_c as Se,bc as Z,bd as v,hd as Be,jd as Oe,kd as ke,l as pe,r as he}from"./chunk-B45CNPUX.mjs";import{b as Q,e as w,f as D,k as fe,l as b}from"./chunk-7EANH5PY.mjs";import{createHash as vt}from"node:crypto";var Le="lineage:runs",Tt="lineage";function We(e){let t=e.objects.filter(i=>i.records>0);if(t.length===0)return null;let r="source",n="target",o=[{id:r,type:"source",label:e.source.label,origin:e.source.origin,...e.source.orgId?{orgId:e.source.orgId}:{}}],s=[];for(let i of t){let u=`object:${i.objectApiName}`;o.push({id:u,type:"object",label:i.objectApiName,objectApiName:i.objectApiName,recordCount:i.records}),s.push({sourceId:r,targetId:u}),s.push({sourceId:u,targetId:n,recordCount:i.records})}return o.push({id:n,type:"destination",label:e.target.label,orgId:e.target.orgId,origin:"org"}),{nodes:o,edges:s,operationId:e.operationId,generatedAt:e.generatedAt,module:e.module,action:e.action}}var U=class{constructor(t,r=100){this.configStore=t;this.limit=r}configStore;limit;save(t){let r=this.read().filter(n=>n.operationId!==t.operationId);r.push(t),this.configStore.set(Le,r.slice(-this.limit),Tt)}get(t){let r=this.read();return t===void 0?r[r.length-1]??null:r.find(n=>n.operationId===t)??null}runs(){return this.read().reverse().map(t=>({operationId:t.operationId,generatedAt:t.generatedAt,...t.module?{module:t.module}:{},...t.action?{action:t.action}:{},...Pt(t)}))}read(){let t=this.configStore.get(Le);return Array.isArray(t)?t.filter(xt):[]}};function Pt(e){let t=e.nodes.find(r=>r.type==="destination");return t?{targetLabel:t.label}:{}}function xt(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.operationId=="string"&&typeof t.generatedAt=="string"&&Array.isArray(t.nodes)&&Array.isArray(t.edges)}var Ct=100,Ge="audit:trail",$t="audit",oe=class{constructor(t,r=he){this.configStore=t;this.limit=r}configStore;limit;append(t){let r=this.read();r.push(t),this.configStore.set(Ge,r.slice(-this.limit),$t)}list(t={}){let r=this.read().reverse(),n=r.filter(i=>(t.module===void 0||i.module===t.module)&&(t.orgId===void 0||i.orgId===t.orgId)),o=t.offset??0,s=t.limit??Ct;return{entries:n.slice(o,o+s),total:n.length,offset:o,facets:jt(r)}}read(){let t=this.configStore.get(Ge);return Array.isArray(t)?t.filter(Ft):[]}};function jt(e){let t=new Set,r=new Map;for(let n of e)t.add(n.module),n.orgId!==void 0&&!r.has(n.orgId)&&r.set(n.orgId,n.orgAlias);return{modules:[...t].sort(),orgs:[...r].map(([n,o])=>o?{orgId:n,orgAlias:o}:{orgId:n})}}function Ft(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.id=="string"&&typeof t.action=="string"&&typeof t.module=="string"&&typeof t.timestamp=="string"}var Ln="ABORTED_BEFORE_START";function _t(e){let t=e?.trim().toLowerCase();if(t)return`sha256:${vt("sha256").update(t).digest("hex").slice(0,12)}`}function Wn(e,t,r=new Date){try{let n=e.services?.getSandforgeSetting?.("safety.auditLogging",!0)!==!1;if(!n&&t.outcome==="stopped"&&t.code===void 0)return;let o=r.toISOString(),s=e.orgManager.getOrg(t.orgId),i=s?Z(s):void 0,u=_t(s?.username),a=t.source?.origin==="org"?t.source.orgId:void 0,d=a!==void 0?e.orgManager.getOrg(a):void 0,l=d?Z(d):void 0,c=t.objects??[];if(new oe(e.configStore).append({id:crypto.randomUUID(),action:t.action,module:t.module,orgId:t.orgId,...i?{orgAlias:i}:{},...a!==void 0?{sourceOrgId:a}:{},...l?{sourceOrgAlias:l}:{},operationId:t.operationId,outcome:t.outcome,...n&&t.guard?{guard:t.guard}:{},objects:[...c],...t.leftBy?{leftBy:t.leftBy}:{},...u?{userId:u}:{},...t.context?{context:t.context}:{},...t.verdict?{verdict:t.verdict}:{},...t.muted?{muted:t.muted}:{},...t.checkpointId?{checkpointId:t.checkpointId}:{},...t.beforeRun?{beforeRun:{...t.beforeRun}}:{},...t.fit?{fit:{...t.fit}}:{},details:{...t.details,...t.code?{code:t.code}:{}},timestamp:o}),!t.source)return;let g=We({operationId:t.operationId,module:t.module,action:t.action,source:t.source.origin==="org"?{origin:"org",orgId:t.source.orgId,label:l??t.source.orgId}:{origin:t.source.origin,label:t.source.label??""},target:{label:i??t.orgId,orgId:t.orgId},objects:Mt(c,t.carried),generatedAt:o});g&&new U(e.configStore).save(g)}catch(n){e.log(`[WARN] audit trail: run ${t.operationId} was not recorded \u2014 ${R(n)}`)}}function Mt(e,t){return t?Object.entries(t).map(([r,n])=>({objectApiName:r,records:n})):e.map(r=>({objectApiName:r.objectApiName,records:r.created+r.updated+(r.upserted??0)}))}function Ue(e){return{objectApiName:e,created:0,updated:0,deleted:0,failed:0}}var Nt="__pass2__";function qe(e){let t=e.errors??[],r=t.some(s=>s.skipped===!0),n=t.some(s=>s.objectApiName===Nt&&s.failedCount>0);return e.failedCount===0&&e.failedReads.length===0&&!r&&!n?"success":e.successCount+e.updatedCount+e.linkedCount+(e.wouldInsertCount??0)>0?"partial":"failure"}function Un(e,t,r){return{forgeId:`forge-${Date.now()}`,status:r.status,graph:t,duration:Date.now()-r.startedAt,timestamp:new Date().toISOString(),idRemapCount:e.remapCount,idRemapTable:e.remapTable,idRemapExisting:e.existingSourceIds,...e.withTheirRecordSourceIds?{idRemapWithTheirRecord:e.withTheirRecordSourceIds}:{},...e.withTheirRecordCount!==void 0&&e.withTheirRecordCount>0?{withTheirRecordCount:e.withTheirRecordCount}:{},...e.linkedToCreatedCount!==void 0&&e.linkedToCreatedCount>0?{linkedToCreatedCount:e.linkedToCreatedCount}:{},createdCount:e.successCount,...e.updatedCount>0?{updatedCount:e.updatedCount}:{},linkedExistingCount:e.linkedCount,existingRecords:e.existingRecords,idRemapByObject:e.remapByObject,idRemapCreated:e.createdByObject,readByObject:e.readByObject,failedReads:e.failedReads,errors:e.errors,truncatedObjects:e.truncatedObjects,...e.cappedObjects?{cappedObjects:e.cappedObjects}:{},...e.files?{files:e.files}:{},...e.fileContentFieldsLeftOut?{fileContentFieldsLeftOut:e.fileContentFieldsLeftOut}:{},...e.encryptedFieldsLeftOut?{encryptedFieldsLeftOut:e.encryptedFieldsLeftOut}:{},...e.picklistValuesChanged?{picklistValuesChanged:e.picklistValuesChanged}:{},...e.currenciesReplaced?{currenciesReplaced:e.currenciesReplaced}:{},...e.recordTypesGiven?{recordTypesGiven:e.recordTypesGiven}:{},...e.writtenWithoutFields?{writtenWithoutFields:e.writtenWithoutFields}:{},...e.lookupsLeftEmptyByFilter?{lookupsLeftEmptyByFilter:e.lookupsLeftEmptyByFilter}:{},...e.contactPoints?{contactPoints:e.contactPoints}:{},...e.writtenBetween?{writtenBetween:e.writtenBetween}:{},...e.apiCalls!==void 0?{apiCalls:e.apiCalls}:{},...e.dryRun?{dryRun:!0,wouldInsertCount:e.wouldInsertCount}:{},...e.gaps?{gaps:e.gaps}:{},...e.decisionsApplied?{decisionsApplied:e.decisionsApplied}:{},...e.mayHaveBeenWritten?{mayHaveBeenWritten:e.mayHaveBeenWritten}:{},...e.remapInJournal?{remapInJournal:!0}:{},...e.sample?{sample:e.sample}:{}}}var ze="RUN_CANCELLED";function Vn(e){return{idRemapByObject:e.remapByObject,errors:e.errors,notSentByObject:e.notSentByObject,writtenWithoutFields:e.writtenWithoutFields,mayHaveBeenWritten:e.mayHaveBeenWritten}}function Kn(e){let t=new Map,r=n=>{let o=t.get(n)??Ue(n);return t.set(n,o),o};for(let n of e.idRemapByObject??[]){let o=r(n.objectApiName);o.created+=n.created,o.updated+=n.updated??0}for(let n of e.errors??[]){if(n.objectApiName.startsWith("__")||n.referenceData===!0||n.stage==="scope"&&n.failedCount===0&&n.skipped!==!0)continue;let o=r(n.objectApiName);o.failed+=n.failedCount,n.skipped===!0&&(o.skipped=n.failedCount>0?"counted":"uncounted")}for(let n of e.notSentByObject??[]){let o=r(n.objectApiName);o.notSent=(o.notSent??0)+n.notSent}for(let n of e.writtenWithoutFields??[]){let o=r(n.objectApiName);o.writtenWithoutFields=(o.writtenWithoutFields??0)+n.rows}for(let{objectApiName:n,sourceIds:o}of e.mayHaveBeenWritten??[]){let s=r(n);s.mayHaveBeenWritten=(s.mayHaveBeenWritten??0)+o.length}return[...t.values()]}function Xn(e,t){return t.some(n=>n.created+n.updated>0)?"cancelled":(e?qe(e):"success")==="success"?"stopped":"cancelled"}function Yn(e){return e?{details:{contactPoints:e.neutralized?"neutralized":"kept",contactPointFields:e.fields.length,contactPointValues:e.values}}:{}}function Jn(e){return Object.fromEntries((e.idRemapByObject??[]).map(t=>[t.objectApiName,t.created+t.linked+(t.updated??0)]))}var j=class extends Error{operation;timeoutMs;constructor(t,r){super(`Operation "${t}" timed out after ${r}ms`),this.name="TimeoutError",this.operation=t,this.timeoutMs=r}},q=class{defaultTimeoutMs;constructor(t=3e4){this.defaultTimeoutMs=t}async withTimeout(t,r,n){let o=n??this.defaultTimeoutMs,s=new AbortController;return new Promise((i,u)=>{let a=setTimeout(()=>{s.abort(),u(new j(t,o))},o);r(s.signal).then(d=>{clearTimeout(a),i(d)},d=>{clearTimeout(a),u(d)})})}getDefaultTimeout(){return this.defaultTimeoutMs}};var lo=2e3,co=1e4,Dt=Be;function mo(e,t,r=Dt){let n=t!==void 0&&t>0?Math.floor(t):void 0;return n!==void 0&&n<=r?[]:e.nodes.filter(o=>o.included&&o.recordCountUnknown!==!0).map(o=>({objectApiName:o.objectApiName,rows:n===void 0?o.recordCount:Math.min(o.recordCount,n)})).filter(o=>o.rows>r).sort((o,s)=>s.rows-o.rows)}var tt=.8,N=1024,H=2*N,rt=4*N,Lt=8*N,Wt=1*N,Gt=4*N,Ut=255,qt=/__kav$/i,zt=new Map([C,W,G,"Campaign","CampaignMember"].map(e=>[e.toLowerCase(),e]));function V(e){return zt.get(e.toLowerCase())??e}function He(e,t=0){let r=0;for(let n of Object.values(e))typeof n=="string"&&n.length>t&&(r+=Buffer.byteLength(n,"utf8"));return r}function ie(e,t){let r=V(e);return r===C?He(t):r===W?re(t)?rt:H:r===G&&re(t)?0:r==="Campaign"?Lt:r==="CampaignMember"?Wt:qt.test(e)?Gt+He(t,Ut):H}function Ht(e,t){let r=Math.min(t.personAccounts??0,t.rows),n=t.rows-r,o=V(e);return o===W?n*H+r*rt:o===G?n*H:n*ie(e,{})}function Vt(e){let t=e.map(({objectApiName:m,rows:f,counted:p,mayAdd:h=0,mayBeByThePlatform:O})=>{let E={rows:h,storageBytes:h*ie(m,{}),...h>0?{mayAdd:h}:{},...O&&O.rows>0?{mayBeByThePlatform:O}:{}};return p?{objectApiName:m,...E,rows:p.rows+E.rows,storageBytes:Ht(m,p)+E.storageBytes}:{objectApiName:m,...E,rows:f.length+E.rows,storageBytes:f.reduce((J,kt)=>J+ie(m,kt),0)+E.storageBytes}}).filter(({rows:m})=>m>0).sort((m,f)=>f.rows-m.rows||m.objectApiName.localeCompare(f.objectApiName)),r=e.reduce((m,f)=>m+(f.leftOut?.writtenBefore??0),0),n=e.filter(m=>(m.leftOut?.heldBack??0)>0).map(({objectApiName:m,leftOut:f})=>({objectApiName:m,rows:f?.heldBack??0})),o=e.filter(m=>(m.leftOut?.byThePlatform??0)>0).map(({objectApiName:m,leftOut:f})=>({objectApiName:m,rows:f?.byThePlatform??0})),s=e.flatMap(({objectApiName:m,leftOut:f})=>f?.linkedByValue&&f.linkedByValue.rows>0?[{objectApiName:m,...f.linkedByValue}]:[]),i=m=>e.filter(f=>(f.leftOut?.[m]??0)>0).map(({objectApiName:f,leftOut:p})=>({objectApiName:f,rows:p?.[m]??0})),u=i("recordTypeNotInTarget"),a=i("withoutParent"),d=i("noParentInSource"),l=i("outsideFilter"),c=i("linkedToTarget"),g=i("currencyReplaced");return{objects:t,totalRows:t.reduce((m,f)=>m+f.rows,0),storageBytes:t.reduce((m,f)=>m+f.storageBytes,0),...r>0||n.length>0||u.length>0||o.length>0||s.length>0||a.length>0||d.length>0||l.length>0||c.length>0||g.length>0?{leftOut:{writtenBefore:r,heldBack:n,...u.length>0?{recordTypeNotInTarget:u}:{},...o.length>0?{byThePlatform:o}:{},...s.length>0?{linkedByValue:s}:{},...a.length>0?{withoutParent:a}:{},...d.length>0?{noParentInSource:d}:{},...l.length>0?{outsideFilter:l}:{},...c.length>0?{linkedToTarget:c}:{},...g.length>0?{currencyReplaced:g}:{}}}:{}}}function go(e){return JSON.stringify([e.sourceOrgId,e.targetOrgId,e.inputMode,e.recordId??null,e.soqlQuery??null,e.templateId??null,e.aiPrompt??null])}var Kt=16,Ve=class{kept=new Map;note(t,r,n=Date.now()){this.kept.delete(t),this.kept.set(t,{at:n,total:r.totalRows,objects:r.objects.map(({objectApiName:o,rows:s})=>({objectApiName:o,rows:s}))});for(let o of this.kept.keys()){if(this.kept.size<=Kt)break;this.kept.delete(o)}}of(t){return this.kept.get(t)}},Xt=500;function Yt(e,t){return e>2*t||e-t>Xt}function fo(e,t,r=Date.now()){return{minutesBefore:Math.max(1,Math.ceil((r-e.at)/6e4)),total:e.total,objects:e.objects.map(({objectApiName:n,rows:o})=>({objectApiName:n,rows:o})),...Yt(t,e.total)?{farAbove:!0}:{}}}function po(e){let t=e.objects.reduce((r,n)=>r+(n.mayAdd??0),0);return t>0?{pricesForLines:t}:{}}function ho(e){let t=e.objects.find(r=>r.mayBeByThePlatform)?.mayBeByThePlatform;return!t||t.rows<=0?{}:{rolesMayBeByThePlatform:{rows:t.rows,...t.before===!0?{before:!0}:{}}}}var z=b({Max:w(),Remaining:w()}).loose(),Jt=b({DataStorageMB:z,DailyApiRequests:z.optional(),DailyBulkApiBatches:z.optional(),FileStorageMB:z.optional()}).loose(),Qt=b({DailyApiRequests:b({Max:w(),Remaining:w()}).loose()}).loose(),Zt="the org does not tell this user its daily API requests";function nt(e,t,r){if(e!==null&&typeof e=="object"&&!(t in e))throw new Error(r)}async function er(e){let t=await e.request({method:"GET",url:"/limits"});nt(t,"DataStorageMB",pe);let r=Jt.parse(t);return{maxMB:r.DataStorageMB.Max,remainingMB:r.DataStorageMB.Remaining,...r.DailyApiRequests?{dailyApiRequests:{max:r.DailyApiRequests.Max,remaining:r.DailyApiRequests.Remaining}}:{},...r.DailyBulkApiBatches?{dailyBulkApiBatches:{max:r.DailyBulkApiBatches.Max,remaining:r.DailyBulkApiBatches.Remaining}}:{},...r.FileStorageMB?{fileStorage:{maxMB:r.FileStorageMB.Max,remainingMB:r.FileStorageMB.Remaining}}:{}}}async function Ke(e){let t=await e.request({method:"GET",url:"/limits"});nt(t,"DailyApiRequests",Zt);let r=Qt.parse(t);return{max:r.DailyApiRequests.Max,remaining:r.DailyApiRequests.Remaining}}var ae=200,ot=2e3,tr=.1;function rr(e){return e.reduce((t,{rows:r,bulk:n,readRows:o,perCall:s})=>{let i=Math.min(ae,Math.max(1,s??ae)),u=r<=0?0:n?je(r):Math.ceil(r/i),a=o&&o>0?Math.ceil(o/ot):0;return t+u+a},0)}var le=["checkpoint","mute","readBack","deliverability","fit"],nr={checkpoint:"for the checkpoint taken first",mute:"to assign and take back the permission sets that mute the target's automation",readBack:"to read back the record types the target gave",deliverability:"to read whether the target delivers its emails",fit:"to fit the run to the storage"};function or(e){return le.reduce((t,r)=>t+Math.max(0,e[r]??0),e.run)}function sr(e){return le.some(t=>(e[t]??0)>0)?{...e}:void 0}function se(e,t){let r=typeof e=="number"?void 0:sr(e),n=typeof e=="number"?e:or(e),o=r?{parts:r}:{};if(!t)return{verdict:"unread",estimate:n,unread:"the limits the org answered list no DailyApiRequests",...o};if("unread"in t)return{verdict:"unread",estimate:n,unread:t.unread,...o};let{max:s,remaining:i}=t;return{verdict:n>i?"exceeds":i-n<tr*s?"near":"fits",estimate:n,max:s,remaining:i,...o}}function ir(e){if(!e)return"";let t=le.filter(r=>(e[r]??0)>0).map((r,n)=>`${e[r]}${n===0?" of them":""} ${nr[r]}`);return t.length>0?` (${t.join(", ")})`:""}var F="API_BUDGET_EXCEEDED";function ar(e,t){if(e.verdict==="exceeds")return`The run takes about ${e.estimate} API requests${ir(e.parts)}, and ${t} has ${e.remaining} of its ${e.max} daily requests left: it would stop part way through, its records refused with REQUEST_LIMIT_EXCEEDED. Run it once the org has requests to spare \u2014 the limit is counted over the last 24 hours \u2014 or write fewer records. Nothing was written.`}function ur(e){return e.verdict==="near"?{apiRequests:{estimate:e.estimate,remaining:e.remaining,max:e.max,...e.parts?{parts:{...e.parts}}:{}}}:{}}var K="CHECKPOINT_REFUSED";function dr(e){return e?{checkpoint:e.estimate.apiRequests}:{}}function lr(e){let t=e?.refusal;if(t!==void 0)return{code:K,message:ne(t),refusal:t}}var cr="The run was stopped while it took the checkpoint first: nothing of it was kept, and nothing was written.";async function bo(e){let t;try{t=await e()}catch(r){return{stop:{code:K,message:De(r)}}}return t.taken?{checkpoint:t.checkpoint}:"stopped"in t?{stop:{code:ze,message:cr}}:{stop:{code:K,message:ne(t.refusal),refusal:t.refusal}}}var Xe=1e4,mr=1e4,gr=.01;function fr(e,t,r){return t<2e3||_e.has(e)||(r??Me).has(e)}function X(e,t,r){if(t<=0)return{jobs:[],rest:0};if(fr(e,t,r.restOnly))return{jobs:[],rest:t};let n=[];for(let o=t;o>0;o-=Xe){let s=Math.min(o,Xe);if(s<2e3)return{jobs:n,rest:s};n.push(s)}return{jobs:n,rest:0}}function pr(e){return ve({stateReads:$e(e,xe,"save")})}function hr(e,t,r){let{jobs:n,rest:o}=X(e,t,r);return n.reduce((s,i)=>s+pr(i),0)+Math.ceil(o/ae)}var br=4,yr=3;function wr(e){let t=new Set(e.updatedAfterInsert??[]),r=new Map((e.plan.leftOut?.linkedByValue??[]).map(({objectApiName:a,rows:d})=>[a,d])),n=[...e.plan.objects.map(({objectApiName:a,rows:d})=>({objectApiName:a,rows:d+(r.get(a)??0)})),...[...r].filter(([a])=>!e.plan.objects.some(d=>d.objectApiName===a)).map(([a,d])=>({objectApiName:a,rows:d}))],o=e.plan.objects.filter(({objectApiName:a})=>t.has(a)).map(({objectApiName:a,rows:d})=>({objectApiName:a,rows:d})),{bulk:s}=e,i=e.files!==void 0&&e.files>0?e.files:0,u=s?br*n.filter(({rows:a})=>a>0).length:0;return{run:(s?[...n,...o].reduce((a,{objectApiName:d,rows:l})=>a+hr(d,l,s),0):rr([...n,...o]))+i+u+Math.max(0,e.sentBefore??0),...dr(e.checkpoint),...e.mute!==void 0&&e.mute>0?{mute:e.mute}:{},...e.readBack!==void 0&&e.readBack>0?{readBack:e.readBack}:{},...e.deliverability!==void 0&&e.deliverability>0?{deliverability:e.deliverability}:{}}}var Rr=200;function Ar(e){let t={...e.measures.restOnly?{restOnly:e.measures.restOnly}:{}},r=new Set(e.updatedAfterInsert??[]),n=e.plan.objects.map(({objectApiName:u,rows:a})=>({objectApiName:u,rows:a,writes:X(u,a,t),updates:r.has(u)?X(u,a,t):void 0})),o=n.flatMap(({writes:u,updates:a})=>a?[u,a]:[u]),s=e.measures.files,i=s&&"count"in s&&s.count>0?s.count:0;return{objects:n.map(({objectApiName:u,rows:a,writes:d})=>({objectApiName:u,rows:a,jobs:d.jobs.length})),sourceRequests:(e.measures.sourceReads??n.reduce((u,{rows:a})=>u+Math.ceil(Math.max(0,a)/ot),0)+i+Math.ceil(i/Rr))+yr*n.filter(({rows:u})=>u>0).length+(e.sourceSentBefore===void 0?Math.max(0,e.measures.heldReads??0):Math.max(0,e.sourceSentBefore)),bulkBatches:o.reduce((u,{jobs:a})=>u+a.reduce((d,l)=>d+Math.ceil(l/mr),0),0),durationSeconds:o.reduce((u,{jobs:a,rest:d})=>u+a.reduce((l,c)=>l+Ce(c,"save"),0)+d*gr,0),restObjects:n.filter(({rows:u,writes:a})=>u>0&&a.jobs.length===0).map(({objectApiName:u})=>u)}}var Er="the limits the org answered list no DailyBulkApiBatches";function Sr(e,t){if(e.verdict==="exceeds")return`The run writes through Bulk API jobs that take about ${e.estimate} of the daily Bulk API batches, and ${t} has ${e.remaining} of its ${e.max} left: its jobs would be refused part way through. Run it once the org has batches to spare \u2014 the limit is counted over the last 24 hours, and Bulk API 1.0 shares it \u2014 or leave objects out. Nothing was written.`}function Br(e,t){if(e.verdict==="exceeds")return`The run reads the source records in about ${e.estimate} API requests, and ${t} has ${e.remaining} of its ${e.max} daily requests left: the reads would stop part way through, and the org's own integrations with them. Run it once the org has requests to spare \u2014 the limit is counted over the last 24 hours \u2014 or leave objects out. Nothing was written.`}function Or(e,t){if(e.verdict==="exceeds")return`The files to copy take about ${P(e.estimateMB)} MB of file storage, and ${t} has ${e.remainingMB} MB left of ${e.maxMB} MB: leave out the objects whose files take it, turn the copy of files off on Review, or free file storage in ${t}. Nothing was written.`}function kr(e,t){return`A clone of the whole org reads a few objects whole, and ${e.map(({objectApiName:n,rows:o})=>`${n} (${o} rows)`).join(", ")} ${e.length===1?"holds":"hold"} more than the ${t} rows of one object the sandforge.forge.maxRecordsPerObject setting lets a run hold at once: raise the setting or leave the object out on Review. Nothing was written.`}var Tr=200;function Pr(e){if(!e||e.length===0)return;let t=Math.min(...e.map(n=>n.bound)),r=e.map(({objectApiName:n,rows:o})=>({objectApiName:n,rows:o}));return{code:"READ_BOUND_EXCEEDED",message:kr(r,t),readBound:{bound:t,objects:r.slice(0,Tr)}}}var st="FILES_UNREAD",it="FILE_STORAGE_UNREAD";function xr(e,t,r){if(!e)return{};if("unmeasured"in e)return{files:{unmeasured:!0},stop:{code:st,message:`The source would neither sum nor list its files, so what they take of the file storage ${r} has left is not known: turn the copy of files off on Review, or run it again once the source answers. Nothing was written.`}};if(e.count<=0)return{};let n=at({storageBytes:e.bytes},"unread"in t?t:t.fileStorage??{unread:"the limits the org answered list no FileStorageMB"});if(n.verdict==="unread")return{files:{count:e.count,check:n},stop:{code:it,message:`The file storage ${r} has left could not be read (${n.unread}), so the ${e.count} files to copy could not be checked against it: turn the copy of files off on Review, or run it again once the org answers. Nothing was written.`}};let o=Or(n,r);return{files:{count:e.count,check:n},...o!==void 0&&n.verdict==="exceeds"?{stop:{code:"STORAGE_EXCEEDED",message:o,storage:{estimateMB:Number(P(n.estimateMB)),remainingMB:n.remainingMB,kind:"files"}}}:{}}}function vr(e){let t=e.wholeOrg,r=t?.measures.files,n=se(wr({...e,...t?{bulk:t.measures.restOnly?{restOnly:t.measures.restOnly}:{},...r&&"count"in r?{files:r.count}:{}}:{}}),e.budget),o=ar(n,e.target),s=[],i=lr(e.checkpoint);i&&s.push(i),o!==void 0&&s.push({code:F,message:o,...t&&n.verdict==="exceeds"?{api:{kind:"requests",org:"target",estimate:n.estimate,remaining:n.remaining}}:{}});let u;if(t){let c=Ar({...e,measures:t.measures,...t.sourceSentBefore!==void 0?{sourceSentBefore:t.sourceSentBefore}:{}}),g=c.bulkBatches>0?se(c.bulkBatches,t.bulkBatches??{unread:Er}):void 0,m=g&&Sr(g,e.target);m!==void 0&&g?.verdict==="exceeds"&&s.push({code:F,message:m,api:{kind:"bulkBatches",org:"target",estimate:g.estimate,remaining:g.remaining}});let f=se(c.sourceRequests,t.sourceBudget),p=Br(f,t.source);p!==void 0&&f.verdict==="exceeds"&&s.push({code:F,message:p,api:{kind:"requests",org:"source",estimate:f.estimate,remaining:f.remaining}}),u={source:f,...g?{bulkBatches:g}:{},cost:c}}let[a,...d]=s,l=d.filter(c=>c.code===F);return{api:n,...a?{stop:a}:{},...t&&l.length>0?{alsoRefused:l}:{},...u?{wholeOrg:u}:{},asks:e.checkpoint!==void 0||t!==void 0,confirmation:{...ur(n),...e.checkpoint?{checkpoint:e.checkpoint}:{}}}}function at(e,t,r=0){let n=Math.max(0,r),o=e.storageBytes+n,s=o/1048576,i=n>0?{automationMB:n/1048576}:{};if("unread"in t)return{verdict:"unread",estimateMB:s,unread:t.unread,...i};let{maxMB:u,remainingMB:a}=t;return{verdict:o>a*1048576?"exceeds":o>tt*a*1048576?"near":"fits",estimateMB:s,maxMB:u,remainingMB:a,...i}}function Cr(e,t){if(!t||t.length===0)return 0;let r=new Map;for(let{objectApiName:n,bytes:o}of t)r.set(n,(r.get(n)??0)+Math.max(0,o));return e.objects.reduce((n,{objectApiName:o,rows:s})=>n+s*(r.get(o)??0),0)}function ut(e){return`about ${P(e.estimateMB)} MB of data storage`+(e.automationMB!==void 0&&e.automationMB>0?`, about ${P(e.automationMB)} MB of it for what the target's automation creates under them`:"")}function $r(e,t){let r=Vt(e),n=t.emailTextBytes,o=e.some(i=>V(i.objectApiName)===C&&i.counted);if(n===void 0||!Number.isFinite(n)||!o)return r;let s=r.objects.map(i=>V(i.objectApiName)===C?{...i,storageBytes:i.storageBytes+Math.max(0,n)}:i);return{...r,objects:s,storageBytes:s.reduce((i,u)=>i+u.storageBytes,0)}}function jr(e,t,r){return e.flatMap(({objectApiName:n,included:o,piiFields:s,anonymizeFields:i})=>{if(!o||!t.has(n))return[];let u=new Set(r?i:[]),a=s.filter(d=>!u.has(d));return a.length>0?[{objectApiName:n,fields:a}]:[]})}function Fr(e){let t=e.leftOut??[],r=new Set(t.map(({objectApiName:s})=>s)),n=[...t,...e.nodes.filter(s=>s.leftOutByUser===!0&&!r.has(s.objectApiName)).map(({objectApiName:s})=>({objectApiName:s,reason:"excludedByUser"}))],o=new Map;for(let{reason:s}of n)o.set(s,(o.get(s)??0)+1);return{objects:n,counts:[...o].map(([s,i])=>({reason:s,count:i})).sort((s,i)=>i.count-s.count||s.reason.localeCompare(i.reason))}}var _r=2;async function yo(e){let t=h=>({unread:R(h)}),r=$r(e.objects,e.measures),n=await er(e.target.limits).catch(t),o="unread"in n?await Ke(e.target.limits).catch(t):n.dailyApiRequests,s=await Ke(e.source.limits).catch(t),i=at(r,n,Cr(r,e.automation)),u=pn(i,e.target.org),a=e.sample?Wr({sample:e.sample,storage:n,target:e.target.org}):void 0,d=xr(e.measures.files,n,e.target.org),l=e.sentBefore?.(),c=vr({plan:r,...e.updatedAfterInsert?{updatedAfterInsert:e.updatedAfterInsert}:{},...e.readBack!==void 0?{readBack:e.readBack}:{},...e.checkpoint?{checkpoint:e.checkpoint}:{},...e.mute!==void 0?{mute:e.mute}:{},deliverability:e.deliverability??_r,...l?{sentBefore:l.target}:{},budget:o,target:e.target.org,wholeOrg:{measures:e.measures,bulkBatches:"unread"in n?n:n.dailyBulkApiBatches,sourceBudget:s,source:e.source.org,...l?.source!==void 0?{sourceSentBefore:l.source}:{}}}),g=[Pr(e.measures.readWholeOver),a,a===void 0&&u!==void 0&&i.verdict==="exceeds"?{code:"STORAGE_EXCEEDED",message:`${u} Nothing was written.`,storage:{estimateMB:Number(P(i.estimateMB)),remainingMB:i.remainingMB}}:void 0,d.stop,c.stop,...c.alsoRefused??[]].filter(h=>h!==void 0),m=e.measures.restOnly?{restOnly:e.measures.restOnly}:{},f=new Set(r.objects.map(({objectApiName:h})=>h)),{wholeOrg:p}=c;return{wouldInsert:r.objects.map(({objectApiName:h,rows:O})=>{let{jobs:E,rest:J}=X(h,O,m);return{objectApiName:h,rows:O,jobs:E.length,byRest:J}}),totalRows:r.totalRows,targetRequests:c.api,sourceRequests:p.source,...p.bulkBatches?{bulkBatches:p.bulkBatches}:{},storage:i,...d.files?{files:d.files}:{},durationSeconds:p.cost.durationSeconds,leftOut:{...Fr(e.graph),...r.leftOut?{rows:r.leftOut}:{}},personalAsIs:jr(e.graph.nodes,f,e.anonymizePII),wouldBeRefused:g,...e.sample?{sample:e.sample}:{}}}var Mr="SAMPLE_STORAGE_UNREAD",dt="SAMPLE_CANNOT_FIT",Nr="SAMPLE_TOO_LARGE",lt="SAMPLE_PLAN_MISMATCH",ue="SAMPLE_PLAN_GONE";function Ir(e){let{storage:t,bounds:r,target:n}=e;if("unread"in t&&!(r.withinMB!==void 0||r.maxTotal!==void 0))return{code:Mr,message:`The data storage ${n} has left could not be read (${t.unread}), and a sample is fitted to it: there is nothing to hold it to. Give the most it may take (--fit-within <MB>) or the most records (--max-total <n>), or run it again once the org answers. Nothing was written.`}}function Dr(e,t){if(e.remainingMB===void 0||e.share===void 0)return;let r=Math.max(0,t.remainingMB-(e.roundingMB??0));return Math.floor(e.share*r*1048576)}function Lr(e){let{sample:t,storage:r,target:n}=e,o=Dr(t.budget,r);if(o===void 0||t.storageBytes<=o)return;let s=Et(t.storageBytes/1048576,o/1048576),i=P(t.budget.bytes/1048576);return{code:"STORAGE_EXCEEDED",message:`The sample was fitted to ${i} MB of the data storage ${n} had left (${t.budget.remainingMB} MB), and ${n} now says ${r.remainingMB} MB left, which holds ${s.bound} MB of a sample: the sample takes about ${s.over} MB. Simulate again \u2014 run the dry run again \u2014 to draw a sample that fits: a run never cuts its sample short. Nothing was written.`,storage:{estimateMB:Number(s.over),remainingMB:r.remainingMB},sample:{fittedMB:Number(i),holdsMB:Number(s.bound)}}}function Wr(e){let{sample:t,storage:r,target:n}=e;return"unread"in r?Ir({storage:r,bounds:t.budget,target:n}):Lr({sample:t,storage:r,target:n})}var Gr=new Set(["gone","changed","otherOrg","otherSetup","otherSha"]),Ur={changed:"is no longer as its dry run wrote it: its ids changed since",otherOrg:"was drawn of another org than the source",otherSetup:"was drawn for another setup of the run \u2014 other flags, filters, objects or options of the sample",otherSha:"is not the plan its dry run printed"};function qr(e,t){return t==="resume"?{code:ue,message:`The plan of the sample this run resumes ${e==="gone"?"is no longer on this machine":"is no longer as it was written"}: the records it was to write cannot be taken up after where it stopped (--resume). Remove what it wrote (--remove), or run the clone again without --resume to draw a new sample. Nothing was written.`,sample:{plan:e}}:e==="gone"?{code:ue,message:'No plan of a sample is at the path given to --fit-plan: give the folder its dry run printed ("sample plan: \u2026"), within a day of it, or leave --fit-plan out to draw a new sample. Nothing was written.',sample:{plan:e}}:{code:lt,message:`The plan given to --fit-plan ${Ur[e]}: run the dry run again with the flags of this run, and replay the plan it prints. Nothing was written.`,sample:{plan:e}}}var zr=new Set([Nr,dt,ue,lt]),Hr=20;function wo(e,t){if(e instanceof Error){if(e.name==="SampleRefusedError"){let{code:r,heaviest:n,sample:o}=e;if(typeof r!="string"||!zr.has(r))return;let s=Array.isArray(n)?n.flatMap(a=>{let d=a?.objectApiName;return typeof d=="string"?[d]:[]}):[],i=ke({code:r,sample:o})?.sample??{},u={...i,...r===dt&&i.heaviest===void 0&&s.length>0?{heaviest:s.slice(0,Hr)}:{}};return B.of({code:r,message:e.message,...Object.keys(u).length>0?{sample:u}:{}})}if(e.name==="SamplePlanError"&&t!=="draw"){let{refusal:r}=e;return typeof r!="string"||!Gr.has(r)?void 0:B.of(qr(r,t))}}}var Vr=b({SingleEmail:b({Max:w(),Remaining:w()}).loose().optional(),DailyWorkflowEmails:b({Max:w(),Remaining:w()}).loose().optional()}).loose();async function Ro(e){let t=Vr.parse(await e.request({method:"GET",url:"/limits"})),r={};for(let n of["SingleEmail","DailyWorkflowEmails"]){let o=t[n];o&&(r[n]={max:o.Max,remaining:o.Remaining})}return r}var Kr=15;function ct(e){let t=e.SingleEmail;return t!==void 0&&t.max<=Kr}function Xr(e){return ct(e)&&e.DailyWorkflowEmails!==void 0}function Yr(e,t,r=!1){let n=e.map(u=>({...u,sentBy:[...u.sentBy]})),o=(u,a)=>{let d=n.find(l=>l.objectApiName===u.objectApiName&&l.limit===a);if(!d){let l={...u,limit:a,sentBy:[...u.sentBy]};return n.push(l),l}d.perRecord+=u.perRecord;for(let l of u.sentBy)d.sentBy.includes(l)||d.sentBy.push(l);return d},s=e.filter(u=>u.limit==="SingleEmail"),i=e.filter(u=>u.limit==="DailyWorkflowEmails");if(r)for(let u of s)o(u,"DailyWorkflowEmails");if(t)for(let u of i)o(u,"SingleEmail").alertsAmong=!0;return n}function mt(e){let t=new Map(e.objects.map(r=>[r.objectApiName,{rows:r.rows,byThePlatform:0}]));for(let{objectApiName:r,rows:n}of e.leftOut?.byThePlatform??[]){let o=t.get(r)??{rows:0,byThePlatform:0};t.set(r,{rows:o.rows+n,byThePlatform:o.byThePlatform+n})}return t}function ce(e){return new Set([...mt(e)].flatMap(([t,{rows:r}])=>r>0?[t]:[]))}function Jr(e,t,r){let n=mt(e),o=new Map;for(let i of t){let{rows:u,byThePlatform:a}=n.get(i.objectApiName)??{rows:0,byThePlatform:0};if(u===0)continue;let d=o.get(i.limit)??{limit:i.limit,objects:[],emails:0,verdict:"fits"};d.objects.push({objectApiName:i.objectApiName,rows:u,perRecord:i.perRecord,sentBy:i.sentBy,...a>0?{byThePlatform:a}:{}}),d.emails+=u*i.perRecord,o.set(i.limit,d)}let s=Y(r)?r.unread:void 0;return[...o.values()].map(i=>{if(s!==void 0||Y(r))return{...i,verdict:"unread",unread:s};let u=r[i.limit];return u?{...i,verdict:i.emails>u.remaining?"exceeds":"fits",remaining:u.remaining,max:u.max}:{...i,verdict:"unread",unread:`the org's limits list no ${i.limit}`}})}function Y(e){return typeof e.unread=="string"}function Qr(e,t,r){let n=!Y(r)&&ct(r),o=!Y(r)&&Xr(r),s=Jr(e,Yr(t,n,o),r);if(!n)return s;let i=ce(e);return t.some(a=>a.limit==="DailyWorkflowEmails"&&i.has(a.objectApiName))?s.map(a=>a.limit==="SingleEmail"?{...a,alertsCounted:!0}:a):s}async function Ao(e){if(e.plan.totalRows===0||e.objects.length===0)return{checks:[]};let t;try{t=await e.readAutomation(e.objects)}catch(i){return{checks:[],unread:`the target's automation: ${R(i)}`}}let r=en(t,Zr(e.plan)),n=r!==void 0?{unread:r}:{},o=we(t);if(o.length===0)return{checks:[],...n};let s=await e.readLimits().catch(i=>({unread:R(i)}));return{checks:Qr(e.plan,o,s),...n}}function Zr(e){let t=ce(e);return(r,n)=>n==="insert"&&t.has(r)}function en(e,t,r="the target's"){let n=[gt(e.unread,r),nn(e,t)].filter(o=>o!==void 0).join("; ");return n!==""?n:void 0}var tn={flows:"flows",processes:"processes",workflowRules:"workflow rules"};function gt(e,t){let r=e.flatMap(({part:n,reason:o})=>{let s=tn[n];return s!==void 0?[`${t} ${s}: ${o}`]:[]});return r.length>0?r.join("; "):void 0}var k=10;function rn(e){if(e.condition!=="unreadable")return;let t=e.apiName.indexOf("__");return t>0?e.apiName.slice(0,t):void 0}function nn(e,t){let r=e.objects.flatMap(o=>{let i=[...new Set(be(o).filter(a=>t(o.objectApiName,a.write)).flatMap(a=>a.fired).flatMap(({flow:a,keptQuiet:d})=>a!==void 0&&d!==!0&&a.condition!=="read"&&a.timing!=="beforeSave"?[a]:[]))].map(a=>{let d=rn(a);return d!==void 0?`${a.label} (package ${d}, whose flows the org lets no one read)`:a.label});if(i.length===0)return[];let u=i.length>k?` and ${i.length-k} more`:"";return[{count:i.length,words:`${i.slice(0,k).join(", ")}${u} on ${o.objectApiName}`}]});return r.length===0?void 0:`the definition${r.reduce((o,{count:s})=>o+s,0)===1?"":"s"} of ${r.map(({words:o})=>o).join("; ")}`}function Eo(e){return{limit:e.limit,emails:e.emails,remaining:e.remaining??0,max:e.max??0,objects:e.objects.map(({objectApiName:t,perRecord:r})=>({objectApiName:t,perRecord:r})),...e.alertsCounted?{alertsCounted:!0}:{}}}function So(e){return{limit:e.limit,emails:e.emails,unread:e.unread??""}}var on={SingleEmail:{one:"single email",more:"single emails"},DailyWorkflowEmails:{one:"workflow email",more:"workflow emails"}};function ft(e,t){let r=on[t];return`${e} ${e===1?r.one:r.more}`}function sn(e,t){return e.alertsCounted?`, its email alerts among them: ${t} counts them against its single emails, as a Developer Edition does`:""}function Bo(e,t){let r=e.filter(o=>o.verdict==="exceeds");if(r.length===0)return;let n=r.map(o=>`about ${ft(o.emails,o.limit)}`+(o.alertsCounted?" (its email alerts among them, as a Developer Edition counts them)":"")+`, ${o.remaining??0} of ${o.max??0} left today`).join("; ");return`The target's automation would make ${t} send ${n}: past them, each record whose flow fails in the save is refused (CANNOT_EXECUTE_FLOW_TRIGGER), and the org's own emails stop for the rest of the day. Assign the user a bypass that keeps what sends quiet, or write fewer records.`}function Oo(e,t){return e.map(r=>{let n=r.objects.map(s=>`${s.perRecord} per ${s.objectApiName}, by ${s.sentBy.join(", ")}`+(s.byThePlatform?`; ${s.byThePlatform} ${s.objectApiName} written by the platform with ${$(s.objectApiName)}, whose flows run all the same`:"")).join("; "),o=` emails: these records make ${t} send about ${ft(r.emails,r.limit)} (${n})`+sn(r,t);return r.verdict==="unread"?`${o}; what it has left today could not be read (${r.unread??""})`:r.verdict==="fits"?`${o}; it has ${r.remaining??"?"} of ${r.max??"?"} left today`:`${o}, more than the ${r.remaining??"?"} of ${r.max??"?"} it has left today: past them the action fails, and a record whose flow fails in the save is refused (CANNOT_EXECUTE_FLOW_TRIGGER). A bypass that keeps the flow quiet, or a smaller run, avoids it`})}var pt="EMAILS_NOT_ACCEPTED";function ht(e,t={}){let r=[gt(e,"the target's"),...t.applyAssignmentRules===!0?e.filter(({part:n})=>n==="assignmentRules").map(({reason:n})=>`the target's assignment rules: ${n}`):[]].filter(n=>n!==void 0);return r.length>0?r.join("; "):void 0}function ko(e){return"requests"in e&&typeof e.requests=="number"?Math.max(0,e.requests):Ne}function To(e){let t=e?.read?.requests??0;return t>0?{deliverability:t}:{}}var bt={clone:{run:"this clone",allTheSame:"to clone all the same"},sync:{run:"this sync",allTheSame:"to sync all the same"},seed:{run:"this seed",allTheSame:"to seed all the same"},autopilot:{run:"this Autopilot run",allTheSame:"to run it all the same"},rewind:{run:"this rewind",allTheSame:"to rewind all the same"},undo:{run:"this undo",allTheSame:"to undo all the same"},masking:{run:"this masking",allTheSame:"to mask all the same"},restore:{run:"this restore",allTheSame:"to restore all the same"},cleanup:{run:"this cleanup",allTheSame:"to delete all the same"},empty:{run:"this emptying",allTheSame:"to empty all the same"},load:{run:"this load",allTheSame:"to load all the same"}},an={flow:"flow",process:"process",workflowRule:"workflow rule",assignmentRule:"assignment rule"},un={email:"",notRead:" (its definition was not read)",assignment:" (applied: it can mail the owner it assigns)"};function yt(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function _(e){let t=new Map;for(let r of e){let n=t.get(r.objectApiName)??[];n.push(`${an[r.kind]} "${r.name}"${un[r.why]}`),t.set(r.objectApiName,n)}return[...t].map(([r,n])=>{let o=n.length>k?[...n.slice(0,k),`${n.length-k} more`]:n;return`${yt(o)} on ${r}`}).join("; ")}var Ye="read with one line of anonymous Apex that sends nothing";function wt(e){return"level"in e&&e.level==="withheld"}function dn(e){return"unread"in e?`deliverability: not read (${e.unread}) \u2014 the run is refused without --accept-emails, as on All email`:e.level==="all"?`deliverability: All email \u2014 the emails of what still runs go out (${Ye})`:`deliverability: System email only or No access \u2014 none of the emails its flows, processes, workflow rules and Apex send goes out, and the org still counts them against its daily email limits (${Ye})`}function ln(e,t){let{run:r,allTheSame:n}=bt[e.run],{target:o}=e,s=_(e.senders),i=e.sendersUnread,u=s!==""?`what still runs as ${r} writes its records sends some: ${s}`+(i!==void 0?`; what could not be read may send more (${i})`:""):`what runs as ${r} writes its records could not all be read (${i??""}), so it may send some`,a=[];"unread"in t?a.push(`Whether ${o} delivers the emails its automation sends could not be read (${t.unread}), and ${u}.`,`Nothing was written. Add --accept-emails ${n}, or check Setup > Deliverability: on System email only or No access, none of them goes out.`):a.push(`${o} delivers every email its automation sends (Setup > Deliverability: All email), and ${u}.`,e.keepsAddresses===!0?`They go to the addresses the records and the alerts name: those of the records ${r} writes, as they hold them, the records' owners, the records already in ${o}, and an address an alert names.`:`They go to the addresses the records and the alerts name: those ${r} writes are under .invalid, but not the records' owners, the records already in ${o}, nor an address an alert names.`,`Nothing was written. Add --accept-emails ${n}, set the org's deliverability to System email only, or turn off what sends them.`);let d=e.muteQuiets??[];if(d.length>0){let l=new Set(d.map(g=>`${g.objectApiName}\0${g.kind}\0${g.name}`)),c=e.senders.filter(g=>!l.has(`${g.objectApiName}\0${g.kind}\0${g.name}`));a.push(`--mute-automation keeps quiet ${_(d)}, which ${d.length===1?"tests":"test"} a bypass a permission set of ${o} holds`+(c.length>0?`; it cannot quiet ${_(c)}.`:"."))}return a.join(" ")}function Rt(e){if(e.senders.length===0&&e.sendersUnread===void 0)return{verdict:"nothingSends",confirmation:{}};let t=e.reading??{unread:"the run did not read it"},r={reading:t,senders:[...e.senders],...e.sendersUnread!==void 0?{sendersUnread:e.sendersUnread}:{}},n=dn(t);return wt(t)?{verdict:"withheld",deliverability:r,confirmation:{},line:n,audit:"withheld"}:{verdict:"asks",deliverability:r,confirmation:{deliverability:e.keepsAddresses===!0?{...r,keepsAddresses:!0}:r},...e.accepted?{}:{stop:{code:pt,message:ln(e,t)}},line:n,audit:"unread"in t?"unread":"all"}}function Po(e,t){let r=ce(t);return e.filter(n=>!r.has(n.objectApiName))}function xo(e){if(e.length===0)return;let t=[...new Set(e.map(r=>r.objectApiName))];return` emails: ${_(e)} send nothing: the run writes no ${yt(t)} record. A real run is refused all the same, and names them: it asks before it reads which records it writes`}function At(e){let t=a=>`${a.objectApiName}\0${a.kind}\0${a.name}`,r=new Set(e.planned.map(t)),n=e.held.filter(a=>!r.has(t(a)));if(n.length===0||e.accepted)return;let o=e.reading;if(o!==void 0&&wt(o))return;let{run:s,allTheSame:i}=bt[e.run],u=o===void 0?`whether ${e.target} delivers them was not read, as nothing that sends one was to run`:"unread"in o?`whether ${e.target} delivers them could not be read (${o.unread})`:`${e.target} delivers every one of them (All email)`;return{code:pt,relit:n,message:`The mute's lease does not hold every permission set it was to assign, and what they were to keep quiet still runs for ${s}: ${_(n)} may send emails, and ${u}. The run's question did not ask about them. Nothing was written. Add --accept-emails ${i}, or run it again once the lease can assign them.`}}function vo(e){return e.verdict==="unread"?{estimateMB:e.estimateMB,unread:e.unread}:{estimateMB:e.estimateMB,maxMB:e.maxMB,remainingMB:e.remainingMB,near:e.verdict==="near"}}function P(e){return de(e,e<10?2:1)}function de(e,t){if(e<=0)return"0";let r=10**t;return(Math.ceil(e*r-1e-9)/r).toString()}function Et(e,t){let r={over:e<10?2:1,bound:t<10?2:1};for(;;){let n={over:de(e,r.over),bound:de(t,r.bound)},o=Math.max(r.over,r.bound);if(Number(n.over)>Number(n.bound)||o>=6)return n;r={over:o+1,bound:o+1}}}function St(e){return e.map(({objectApiName:t,kind:r,name:n})=>({objectApiName:t,kind:r,name:n}))}function cn(e){return St(ee(e,"insert"))}function mn(e,t){let r=new Set(t);return St(ee(e,"update",n=>r.has(n)))}var Bt=["lookups","statuses","invitees","retry","upsert"];function Co(e,t={}){let r=Ie(e,t.leftOut),n=new Set(r),o=new Map,s=(l,c)=>{if(!n.has(l))return;let g=o.get(l)??new Set;g.add(c),o.set(l,g)},i=e.edges.filter(l=>Fe(l)&&n.has(l.sourceObject)&&n.has(l.targetObject)),u=new Map;for(let{sourceObject:l,targetObject:c}of i)l!==c&&u.set(l,[...u.get(l)??[],c]);let a=(l,c)=>{let g=new Set([l]),m=[l];for(let f=m.shift();f!==void 0;f=m.shift())for(let p of u.get(f)??[]){if(p===c)return!0;g.has(p)||(g.add(p),m.push(p))}return!1},d=i.filter(l=>l.required!==!0&&l.insertOnly!==!0);for(let{sourceObject:l,targetObject:c}of d)(l===c||a(c,l))&&s(c,"lookups");for(let l of Object.keys(Pe))s(l,"statuses");for(let l of Object.keys(Te))s(l,"invitees");if(t.retry===!0)for(let{sourceObject:l,targetObject:c}of d)l!==c&&s(c,"retry");if(t.upsert===!0)for(let l of r)s(l,"upsert");return r.flatMap(l=>{let c=o.get(l);return c?[{objectApiName:l,steps:Bt.filter(g=>c.has(g))}]:[]})}function gn(e){let t=new Set(e.flatMap(r=>r.steps));return Bt.filter(r=>t.has(r))}function $o(e,t=[]){let r=new Set(t);return Re(e,(n,o)=>o==="insert"||o==="update"&&r.has(n))}function jo(e,t,r){let n=new Set(ye(e).map(i=>i.toLowerCase())),o=t.filter(i=>!n.has(i.toLowerCase())),s=Ae(e,o);return o.map(i=>{let u=s.find(d=>d.permission.toLowerCase()===i.toLowerCase()),a=u?.permissionSet?.name;return{permission:i,...a?{permissionSet:a}:{},others:u?.others.map(d=>d.name)??[],...u&&!a?{noneHolds:!0}:{},...a&&r?.alias&&r.username?{command:Ee(a,r.alias,r.username)}:{}}})}function fn(e){return e==="flows"||e==="triggers"||e==="processes"||e==="workflowRules"||e==="automation"}function I(e){return e.unread.flatMap(({part:t,reason:r})=>fn(t)?[{part:t,reason:r}]:[])}var Fo="OWNER_MAP_INACTIVE",_o="OWNER_MAP_UNKNOWN",B=class e extends Error{code;storage;ceiling;reason;api;readBound;sample;constructor(t,r,n,o,s,i){super(r),this.name="ForgeRunGateError",this.code=t,n&&(this.storage=n),o!==void 0&&(this.ceiling=o),s!==void 0&&(this.reason=s),i?.api&&(this.api=i.api),i?.readBound&&(this.readBound=i.readBound),i?.sample&&(this.sample=i.sample)}static of(t){return new e(t.code,t.message,t.storage,void 0,t.refusal?.code,{...t.api?{api:t.api}:{},...t.readBound?{readBound:t.readBound}:{},...t.sample?{sample:t.sample}:{}})}get stop(){if(Oe(this.code))return{code:this.code,...this.storage?{storage:this.storage}:{},...this.ceiling!==void 0?{ceiling:this.ceiling}:{},...this.reason!==void 0&&this.code===K?{reason:this.reason}:{},...this.api&&this.code===F?{api:this.api}:{},...this.readBound&&this.code==="READ_BOUND_EXCEEDED"?{readBound:this.readBound}:{},...this.sample?{sample:this.sample}:{}}}};function Mo(e){return e instanceof B||e instanceof Error&&e.name==="ForgeRunGateError"&&typeof e.code=="string"}var Je="FILE_STORAGE_EXCEEDED";function No(e){if(!(e instanceof Error)||e.name!=="ForgeFilesRefusedError")return;let{code:t,storage:r}=e;if(t===st||t===it)return new B(t,e.message);let n=r?.neededBytes,o=r?.remainingBytes;if(t!==Je||typeof n!="number"||typeof o!="number"||!Number.isFinite(n)||!Number.isFinite(o))return;let s=o/1048576;return new B(Je,e.message,{estimateMB:Number(Et(n/1048576,s).over),remainingMB:s,kind:"files"})}function pn(e,t){if(e.verdict==="exceeds")return`The records to write take ${ut(e)}, and ${t} has ${e.remainingMB} MB left of ${e.maxMB} MB: leave objects out, lower the records per object, or free data storage in ${t}.`}var Qe=10;function Io(e,t,r){let n=[`write gate: ${e.totalRows} record(s) to write to ${r}, ${ut(t)}`];for(let s of e.objects.slice(0,Qe))n.push(` ${s.objectApiName.padEnd(42)}${String(s.rows).padStart(8)}`);let o=e.objects.slice(Qe);if(o.length>0){let s=o.reduce((i,u)=>i+u.rows,0);n.push(` and ${o.length} more object(s), ${s} record(s)`)}for(let{objectApiName:s,mayAdd:i}of e.objects)i!==void 0&&n.push(` counted in: up to ${i} ${s} record(s) the run may read as it writes them, a price in the currency of the record its lines belong to, the source's own beside the one read`);for(let{objectApiName:s,mayBeByThePlatform:i}of e.objects)i!==void 0&&n.push(` counted in: up to ${i.rows} ${s} record(s) the platform `+(i.before===!0?`may have written with ${$(s)}, in the run this one takes up`:`may write itself with ${$(s)}`)+", which the run then links to and does not send");return n.push(...hn(e.leftOut)),t.verdict==="unread"?(n.push(` the data storage ${r} has left could not be read (${t.unread}): whether the records fit is not known`),n):(n.push(` data storage of ${r}: ${t.remainingMB} MB left of ${t.maxMB} MB`),t.verdict==="near"&&n.push(` that is more than ${Math.round(tt*100)} % of what ${r} has left: Salesforce counts storage a while after a load, so less may be left than it says`),n)}function hn(e){if(!e)return[];let t=[];e.writtenBefore>0&&t.push(` not counted: ${e.writtenBefore} record(s) the run it retries or resumes wrote, which it links to and does not write again`);for(let{objectApiName:r,rows:n}of e.heldBack)t.push(` not counted: ${r}, ${n} record(s), held back for a record type closed to the user the run writes as`);for(let{objectApiName:r,rows:n}of e.recordTypeNotInTarget??[])t.push(` not counted: ${r}, ${n} record(s), held back for a record type the target has none of, which it would refuse`);for(let{objectApiName:r,rows:n}of e.withoutParent??[])t.push(` not counted: ${r}, ${n} record(s) held back with a record they cannot be written without, held back itself`);for(let{objectApiName:r,rows:n}of e.noParentInSource??[])t.push(` not counted: ${r}, ${n} record(s) left aside: a lookup they may not leave empty names a record the source does not hold, which no copy can write`);for(let{objectApiName:r,rows:n}of e.outsideFilter??[])t.push(` not counted: ${r}, ${n} record(s) left aside: a lookup they may not leave empty names a record outside its object's filter, which the run does not copy`);for(let{objectApiName:r,rows:n}of e.byThePlatform??[])t.push(` not counted: ${r}, ${n} record(s) written by the platform with ${$(r)}, which the run links to and does not send`);for(let{objectApiName:r,rows:n,fields:o}of e.linkedByValue??[])t.push(` not counted: ${r}, ${n} record(s) the target holds under the same ${o.join(", ")}, which the run links to and does not create`);for(let{objectApiName:r,rows:n}of e.linkedToTarget??[])t.push(` not counted: ${r}, ${n} record(s), the standard price book: linked to the target's own, never written`);for(let{objectApiName:r,rows:n}of e.currencyReplaced??[])t.push(` not counted: ${r}, ${n} record(s) in a currency the target lacks, replaced by the source's own price in the currency written, for the same product and price book`);return t}var bn={flow:e=>`flow "${e}" runs before a record is deleted, and can refuse the delete`,trigger:e=>`Apex trigger ${e} runs on a delete, and can refuse it`,packageTrigger:e=>`Apex trigger ${e}, installed by a managed package, runs on a delete and can refuse it; no one in the org can change it`,lock:()=>"once activated, a record locks the records under it, which a removal then takes only with it, or once it is back in Draft"},yn=["flows","triggers"];function Do(e,t,r=[],n="--remove"){let o=yn.filter(i=>r.some(u=>u.part===i)),s=o.length===0?[]:[` ${o.map(i=>A[i]).join(" and ")} could not be read: whether one refuses the removal is not known`];if(e.length===0&&o.length===0)return[`reversibility: nothing found in ${t} that refuses a removal of this run's records (no flow before a delete, no Apex trigger on one, no record that locks past Draft)`];if(e.length===0){let i=[...o.includes("flows")?[]:["no flow before a delete"],...o.includes("triggers")?[]:["no Apex trigger on a delete"],"no record that locks past Draft"];return[`reversibility: nothing found in ${t} that refuses a removal of this run's records in what could be read (${i.join(", ")})`,...s]}return[`reversibility: a removal of this run's records (${n}) may be refused in ${t}:`,...e.map(({objectApiName:i,kind:u,name:a})=>` ${i}: ${bn[u](a??"")}`),...s]}var A={flows:"the flows",triggers:"the Apex triggers",processes:"the Process Builder processes",workflowRules:"the workflow rules",automation:"the automation"};function S({kind:e,name:t}){return e==="flow"?`flow "${t}"`:e==="process"?`process "${t}"`:e==="workflowRule"?`workflow rule "${t}"`:`Apex trigger ${t}`}var wn={lookups:"a lookup filled in once its record exists",statuses:"an order or a contract given back its status after it went in as a draft",invitees:"an event's invitee given its answer",retry:"a lookup the run it retries left empty filled in",upsert:"a record the target holds written over by --upsert"};function T(e){return e.map(t=>`${t.objectApiName}: ${S(t)}`).join("; ")}function me(e,t,r){return e.flatMap(n=>{if(n.command){let o=n.others.length>0?`; ${n.others.join(", ")} hold${n.others.length===1?"s":""} it too`:"";return[`${n.permissionSet} is the smallest permission set of ${t} that holds ${n.permission}${o}. Assigned to the user ${r} writes as, it keeps quiet what ${n.permission} excludes: ${n.command}`]}return n.noneHolds?[`No permission set of ${t} holds ${n.permission}: an admin creates one that includes it, and assigns it to the user ${r} writes as.`]:[]})}function ge(e,t,r){let n=[...new Set(e.flatMap(o=>o.permissionSet??[]))];return!r||n.length===0?[]:[`With --mute-automation, the ${t} assigns ${n.join(", ")} to the user it writes as for the ${t} alone, under a lease, and what ${n.length===1?"it keeps":"they keep"} quiet does not fire.`]}function Lo(e,t,r={}){let n=r.updated??[],o=cn(e),s=mn(e,n.map(d=>d.objectApiName)),i=I(e);if(o.length===0&&s.length===0&&i.length===0)return;let u=[];if(o.length>0&&u.push(`${t} runs automation on the records this clone inserts: ${T(o)}.`),s.length>0){let d=gn(n.filter(l=>s.some(c=>c.objectApiName===l.objectApiName))).map(l=>wn[l]);u.push(`${t} runs automation as this clone updates records it inserted (${d.join("; ")}): ${T(s)}.`)}let a=n.length>0?"inserts and updates":"inserts";for(let{part:d,reason:l}of i)u.push(`${A[d][0].toUpperCase()}${A[d].slice(1)} of ${t} could not be read (${l}), so what fires as the clone ${a} is not known.`);return u.push(...me(r.assign??[],t,"the clone")),u.push(...ge(r.assign??[],"clone",r.mayMute===!0)),u.push(`Nothing was written. Add --accept-automation to clone all the same, or turn that automation off in ${t} first.`),u.join(" ")}function Wo(e,t,r={}){let n=te(e,r.drafted??[]),o=I(e);if(n.length===0&&o.length===0)return;let s=[],i=n.filter(a=>a.write==="update"),u=n.filter(a=>a.write==="delete");if(u.length>0){let a=u.map(d=>`${d.objectApiName}: ${S(d)} (${M[d.when]})`);s.push(`${t} runs automation on the records this removal deletes: ${a.join("; ")}.`)}i.length>0&&s.push(`${t} runs automation as this removal sets activated records back to Draft, the only way the platform deletes them: ${T(i)}.`);for(let{part:a,reason:d}of o)s.push(`${A[a][0].toUpperCase()}${A[a].slice(1)} of ${t} could not be read (${d}), so what fires as the removal deletes is not known.`);return s.push(...me(r.assign??[],t,"the removal")),s.push(...ge(r.assign??[],"removal",r.mayMute===!0)),s.push(`Nothing was deleted. Add --accept-automation to remove all the same, or turn that automation off in ${t} first.`),s.join(" ")}var M={before:"before delete",after:"after delete",beforeAndAfter:"before and after delete"};function Go(e,t,r,n){let o=[`removal automation: what ${t} runs as the removal takes the records back`];for(let i of te(e,n))o.push(i.write==="delete"?` ${i.objectApiName}: ${M[i.when]}: ${S(i)}`:` ${i.objectApiName}: set back to Draft before its delete: ${S(i)}`);let s=I(e);o.length===1&&s.length===0&&o.push(` nothing fires on the ${r} object(s) it deletes records of`);for(let{part:i,reason:u}of s)o.push(` ${A[i]} could not be read: ${u}`);return o}var Rn={bringBack:"brought back from the recycle bin",recreate:"made again with a new Id",giveBack:"given back its values from before the run",setToDraft:"set back to Draft before its delete"};function Uo(e,t,r,n="removal",o){let s=I(e),i=(u,a)=>{let d=[An[a](t)];for(let l of L(e,u))d.push(l.step==="delete"?` ${l.objectApiName}: ${M[l.when]}: ${S(l)}`:` ${l.objectApiName}: ${Rn[l.step]}: ${S(l)}`);if(d.length===1&&s.length===0){let l=new Set(Object.values(u).flat()).size,c=a==="reloadSweep"?"deletes":"writes";d.push(` nothing fires on the ${l} object(s) it ${c} records of`)}return d};return[...i(r,n),...o?i(o,"reloadSweep"):[],...s.map(({part:u,reason:a})=>` ${A[u]} could not be read: ${a}`)]}var An={removal:e=>`removal automation: what ${e} runs as the removal takes the run back`,reload:e=>`reload automation: what ${e} runs as the reload purges what earlier loads created`,reloadSweep:e=>`reload automation: what ${e} runs as the reload's sweep deletes what the target's automation made for the loads it replaces`};function qo(e,t,r){let n=L(e,r.steps),o=r.sweep?L(e,r.sweep):[],s=I(e);if(n.length===0&&o.length===0&&s.length===0)return;let i=d=>n.filter(l=>l.step===d),u=Ze[r.subject??"removal"],a=[];if(i("bringBack").length>0&&a.push(`${t} runs automation as ${u.this} brings back from the recycle bin what the run deleted: ${T(i("bringBack"))}.`),i("giveBack").length>0&&a.push(`${t} runs automation as ${u.this} gives the records the run wrote over their values from before it: ${T(i("giveBack"))}.`),i("setToDraft").length>0&&a.push(`${t} runs automation as ${u.this} sets activated records back to Draft, the only way the platform deletes them: ${T(i("setToDraft"))}.`),i("delete").length>0){let d=i("delete").map(l=>`${l.objectApiName}: ${S(l)} (${M[l.when]})`);a.push(`${t} runs automation on the records ${u.this} deletes: ${d.join("; ")}.`)}if(o.length>0){let d=o.map(l=>`${l.objectApiName}: ${S(l)} (${M[l.when]})`);a.push(`${t} runs automation on the records ${Ze.reloadSweep.this} deletes: ${d.join("; ")}.`)}for(let{part:d,reason:l}of s)a.push(`${A[d][0].toUpperCase()}${A[d].slice(1)} of ${t} could not be read (${l}), so what fires as ${u.the} writes is not known.`);return a.push(...me(r.assign??[],t,u.who)),a.push(...ge(r.assign??[],u.run,r.mayMute===!0)),a.push(`Nothing was written or deleted. Add --accept-automation to ${u.verb} all the same, or turn that automation off in ${t} first.`),a.join(" ")}var Ze={removal:{this:"this removal",the:"the removal",who:"the removal",run:"removal",verb:"remove"},reload:{this:"this reload's purge",the:"the reload's purge",who:"the reload",run:"reload",verb:"reload"},reloadSweep:{this:"this reload's sweep",the:"the reload's sweep",who:"the reload",run:"reload",verb:"reload"}};var En="Messaging.reserveSingleEmailCapacity(1);",Sn="System.NoAccessException: The organization is not permitted to send email",Bn=`/tooling/executeAnonymous?anonymousBody=${encodeURIComponent(En)}`,On=`/query?q=${encodeURIComponent("SELECT PermissionsEmailSingle FROM UserPermissionAccess")}`,kn=3e4,Tn=b({compiled:D(),success:D(),compileProblem:Q().nullish(),exceptionMessage:Q().nullish()}).loose(),Pn=b({records:fe(b({PermissionsEmailSingle:D().optional()}).loose())}).loose(),Yo={reading:{unread:"SandForge runs no Apex in a production org"},requests:0};function xn(e){return e%1e3===0?`${e/1e3} s`:`${e} ms`}function Ot(e,t){return e instanceof j?`the org did not answer within ${xn(t)}`:`the org refused it: ${R(e)}`}function vn(e){let t=Tn.safeParse(e);if(!t.success)return{unread:"its answer is not one anonymous Apex gives"};let{compiled:r,success:n,compileProblem:o,exceptionMessage:s}=t.data;if(!r)return{unread:`it did not compile${o?`: ${o}`:""}`};if(n)return{level:"all"};let i=s?.trim();return i===Sn?{refused:!0}:{unread:i?`the org answered: ${i}`:"it failed, and the org did not say why"}}async function Jo(e,t={}){let r=t.timeoutMs??kn,n=l=>new q(r).withTimeout("forge:deliverability",()=>e.request({method:"GET",url:l})),o;try{o=await n(Bn)}catch(l){return{reading:{unread:Ot(l,r)},requests:1}}let s=vn(o);if(!("refused"in s))return{reading:s,requests:1};let i="so the org's refusal does not say how it is set",u;try{u=await n(On)}catch(l){return{reading:{unread:`whether the user the run writes as may send email could not be read (${Ot(l,r)}), ${i}`},requests:2}}let a=Pn.safeParse(u),d=a.success?a.data.records[0]?.PermissionsEmailSingle:void 0;return d===!0?{reading:{level:"withheld"},requests:2}:{reading:{unread:d===!1?`the user the run writes as may not send email (Send Email), ${i}`:`the org did not say whether the user the run writes as may send email, ${i}`},requests:2}}async function Cn(e){let t=x(e.running,{applyAssignmentRules:e.applyAssignmentRules,writes:e.writes}),r=ht(e.running.automation.unread??[],{applyAssignmentRules:e.applyAssignmentRules===!0}),n=r!==void 0?{sendersUnread:r}:{};if(t.length===0&&r===void 0)return{senders:t};let o;try{o=await e.read()}catch(s){o={reading:{unread:R(s)},requests:1}}return{senders:t,...n,read:o}}function $n(e,t={}){let r=s=>`${s.objectApiName}\0${s.kind}\0${s.name}`,n=x(v(e,void 0,t.writes),t),o=new Set(x(v(e,Se(e,t.writes),t.writes),t).map(r));return n.filter(s=>!o.has(r(s)))}function jn(e,t){let r=new Set([...t.assigned,...t.held]);return{assign:e.assign.filter(n=>r.has(n.permissionSet))}}var Fn=["flows","processes","workflowRules"];async function Qo(e){let{plan:t,writes:r,applyAssignmentRules:n,read:o,target:s,run:i}=e,u=typeof o.unread=="string"?void 0:o,a=n===!0?{applyAssignmentRules:n}:{},d=await Cn({running:u?v(u,t,r):{automation:{objects:[],unread:Fn.map(g=>({part:g,reason:String(o.unread)}))},firing:[]},...a,writes:r,read:e.readDeliverability}),l=e.mayMute===!0&&t===void 0&&u!==void 0&&d.senders.length>0?$n(u,{...a,writes:r}):[],c=d.read?.reading;return{ofRun:d,gate:Rt({senders:d.senders,...d.sendersUnread!==void 0?{sendersUnread:d.sendersUnread}:{},...c!==void 0?{reading:c}:{},accepted:e.accepted,target:s,run:i,muteQuiets:l,keepsAddresses:e.keepsAddresses===!0}),afterLease:(g,m)=>{if(!(t===void 0||u===void 0))return At({planned:d.senders,held:x(v(u,jn(t,g),r),{...a,writes:r}),...c!==void 0?{reading:c}:{},accepted:m,target:s,run:i})}}}export{U as a,oe as b,Ln as c,_t as d,Wn as e,Ue as f,qe as g,Un as h,ze as i,Vn as j,Kn as k,Xn as l,Yn as m,Jn as n,j as o,q as p,kn as q,Yo as r,Jo as s,Cn as t,$n as u,jn as v,Qo as w,lo as x,co as y,Dt as z,mo as A,tt as B,ie as C,Ht as D,Vt as E,go as F,Ve as G,fo as H,po as I,ho as J,er as K,Ke as L,tr as M,rr as N,se as O,F as P,ar as Q,ur as R,K as S,dr as T,lr as U,cr as V,bo as W,Pr as X,xr as Y,vr as Z,at as _,Cr as $,ut as aa,$r as ba,jr as ca,Fr as da,yo as ea,lt as fa,ue as ga,Ir as ha,Wr as ia,wo as ja,Ro as ka,ct as la,Xr as ma,Yr as na,Jr as oa,Qr as pa,Ao as qa,Zr as ra,en as sa,Eo as ta,So as ua,ft as va,Bo as wa,Oo as xa,pt as ya,ht as za,ko as Aa,To as Ba,dn as Ca,Rt as Da,Po as Ea,xo as Fa,At as Ga,vo as Ha,P as Ia,Et as Ja,cn as Ka,mn as La,Co as Ma,gn as Na,$o as Oa,jo as Pa,I as Qa,Fo as Ra,_o as Sa,B as Ta,Mo as Ua,No as Va,pn as Wa,Io as Xa,Do as Ya,me as Za,Lo as _a,Wo as $a,Go as ab,Uo as bb,qo as cb};
@@ -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{c as z,d as v,f as A,j as k,k as c,l as R}from"./chunk-FQGHL7GR.mjs";import{eb as f}from"./chunk-B45CNPUX.mjs";var L={en_US:[{city:"New York",state:"New York",country:"United States",zipCode:"10001"},{city:"Los Angeles",state:"California",country:"United States",zipCode:"90001"},{city:"Chicago",state:"Illinois",country:"United States",zipCode:"60601"},{city:"Houston",state:"Texas",country:"United States",zipCode:"77001"},{city:"Phoenix",state:"Arizona",country:"United States",zipCode:"85001"},{city:"Philadelphia",state:"Pennsylvania",country:"United States",zipCode:"19101"},{city:"San Antonio",state:"Texas",country:"United States",zipCode:"78201"},{city:"San Diego",state:"California",country:"United States",zipCode:"92101"},{city:"Dallas",state:"Texas",country:"United States",zipCode:"75201"},{city:"Austin",state:"Texas",country:"United States",zipCode:"78701"}],fr_FR:[{city:"Paris",state:"Ile-de-France",country:"France",zipCode:"75001"},{city:"Lyon",state:"Auvergne-Rhone-Alpes",country:"France",zipCode:"69001"},{city:"Marseille",state:"Provence-Alpes-Cote d'Azur",country:"France",zipCode:"13001"},{city:"Toulouse",state:"Occitanie",country:"France",zipCode:"31000"},{city:"Nice",state:"Provence-Alpes-Cote d'Azur",country:"France",zipCode:"06000"},{city:"Bordeaux",state:"Nouvelle-Aquitaine",country:"France",zipCode:"33000"},{city:"Strasbourg",state:"Grand Est",country:"France",zipCode:"67000"},{city:"Nantes",state:"Pays de la Loire",country:"France",zipCode:"44000"},{city:"Lille",state:"Hauts-de-France",country:"France",zipCode:"59000"},{city:"Rennes",state:"Bretagne",country:"France",zipCode:"35000"}],de_DE:[{city:"Berlin",state:"Berlin",country:"Germany",zipCode:"10115"},{city:"Munich",state:"Bavaria",country:"Germany",zipCode:"80331"},{city:"Hamburg",state:"Hamburg",country:"Germany",zipCode:"20095"},{city:"Frankfurt",state:"Hesse",country:"Germany",zipCode:"60311"},{city:"Cologne",state:"North Rhine-Westphalia",country:"Germany",zipCode:"50667"},{city:"Stuttgart",state:"Baden-Wurttemberg",country:"Germany",zipCode:"70173"},{city:"Dusseldorf",state:"North Rhine-Westphalia",country:"Germany",zipCode:"40213"},{city:"Leipzig",state:"Saxony",country:"Germany",zipCode:"04109"},{city:"Dresden",state:"Saxony",country:"Germany",zipCode:"01067"},{city:"Hannover",state:"Lower Saxony",country:"Germany",zipCode:"30159"}],es_ES:[{city:"Madrid",state:"Comunidad de Madrid",country:"Spain",zipCode:"28001"},{city:"Barcelona",state:"Catalonia",country:"Spain",zipCode:"08001"},{city:"Valencia",state:"Comunitat Valenciana",country:"Spain",zipCode:"46001"},{city:"Seville",state:"Andalusia",country:"Spain",zipCode:"41001"},{city:"Zaragoza",state:"Aragon",country:"Spain",zipCode:"50001"},{city:"Malaga",state:"Andalusia",country:"Spain",zipCode:"29001"},{city:"Bilbao",state:"Basque Country",country:"Spain",zipCode:"48001"},{city:"Murcia",state:"Region de Murcia",country:"Spain",zipCode:"30001"},{city:"Palma",state:"Balearic Islands",country:"Spain",zipCode:"07001"},{city:"Granada",state:"Andalusia",country:"Spain",zipCode:"18001"}],ja_JP:[{city:"Tokyo",state:"Tokyo",country:"Japan",zipCode:"100-0001"},{city:"Osaka",state:"Osaka",country:"Japan",zipCode:"530-0001"},{city:"Yokohama",state:"Kanagawa",country:"Japan",zipCode:"220-0011"},{city:"Nagoya",state:"Aichi",country:"Japan",zipCode:"450-0001"},{city:"Sapporo",state:"Hokkaido",country:"Japan",zipCode:"060-0001"},{city:"Fukuoka",state:"Fukuoka",country:"Japan",zipCode:"810-0001"},{city:"Kobe",state:"Hyogo",country:"Japan",zipCode:"650-0001"},{city:"Kyoto",state:"Kyoto",country:"Japan",zipCode:"600-8001"},{city:"Sendai",state:"Miyagi",country:"Japan",zipCode:"980-0001"},{city:"Hiroshima",state:"Hiroshima",country:"Japan",zipCode:"730-0001"}],pt_BR:[{city:"Sao Paulo",state:"Sao Paulo",country:"Brazil",zipCode:"01000-000"},{city:"Rio de Janeiro",state:"Rio de Janeiro",country:"Brazil",zipCode:"20000-000"},{city:"Brasilia",state:"Distrito Federal",country:"Brazil",zipCode:"70000-000"},{city:"Salvador",state:"Bahia",country:"Brazil",zipCode:"40000-000"},{city:"Fortaleza",state:"Ceara",country:"Brazil",zipCode:"60000-000"},{city:"Belo Horizonte",state:"Minas Gerais",country:"Brazil",zipCode:"30000-000"},{city:"Manaus",state:"Amazonas",country:"Brazil",zipCode:"69000-000"},{city:"Curitiba",state:"Parana",country:"Brazil",zipCode:"80000-000"},{city:"Recife",state:"Pernambuco",country:"Brazil",zipCode:"50000-000"},{city:"Porto Alegre",state:"Rio Grande do Sul",country:"Brazil",zipCode:"90000-000"}]},B={en:"en_US",fr:"fr_FR",de:"de_DE",es:"es_ES",ja:"ja_JP",pt:"pt_BR"};function l(i){if(i in L)return i;let e=i.split("_")[0].toLowerCase();return B[e]??"en_US"}var u=class{tuples;resolvedLocale;constructor(e){this.resolvedLocale=l(e??"en_US"),this.tuples=L[this.resolvedLocale]}getAddress(e){return this.tuples[e%this.tuples.length]}getCity(e){return this.getAddress(e).city}getState(e){return this.getAddress(e).state}getCountry(e){return this.getAddress(e).country}getZipCode(e){return this.getAddress(e).zipCode}getLocaleData(){return c(this.resolvedLocale)}};var F={en_US:"US",fr_FR:"FR",de_DE:"DE",es_ES:"ES",ja_JP:"JP",pt_BR:"BR"},$={fr_FR:{country:"FR",bbanLength:23},de_DE:{country:"DE",bbanLength:18},es_ES:{country:"ES",bbanLength:20},en_US:{country:"DE",bbanLength:18},ja_JP:{country:"DE",bbanLength:18},pt_BR:{country:"DE",bbanLength:18}},w="ABCDEFGHIJKLMNPQRSTUVWXYZ",T=["Ergonomic","Handcrafted","Refined","Sleek","Rustic","Compact","Modular","Insulated"],E=["Steel","Wooden","Cotton","Granite","Rubber","Leather","Ceramic"],_=["Chair","Table","Lamp","Keyboard","Backpack","Bottle","Headphones","Gloves","Bench"],M=["Senior","Lead","Junior","Principal","Associate","Chief"],P=["Marketing","Operations","Finance","Sales","Product","Customer Success"],U=["Manager","Analyst","Coordinator","Specialist","Director","Consultant"],G=["Adaptive","Integrated","Customer-focused","Scalable","Secure"],O=["cloud-based","real-time","data-driven","modular","global"],I=["platform","solution","workflow","service","framework","network"],J=["daily use at home or in the office","long days on the move","teams that need something that lasts","small spaces","outdoor work in any weather"],H=["Unable to log in","Invoice discrepancy","Password reset email not received","Order arrived damaged","Request for a refund","Cannot update billing address","Shipment delayed","Error when exporting a report","Product not working as described","Question about my contract","Charged twice for one order","Need help with installation","Account locked after failed logins","Wrong item delivered","Request: edit several records at once","App crashes on startup","Items missing from my order","Cannot download my invoice","Change of delivery address","Warranty claim","Slow since the last update","Question about my subscription renewal","Data not syncing between devices","Cancel my order","Upgrade to a higher plan"],x=["Asked the customer for a screenshot of the error.","Reproduced the issue on our side.","Escalated to the second-level team.","Sent the customer a workaround.","Customer confirmed the fix works.","Waiting for the customer's reply.","Refund approved and processed.","Replacement shipped today.","Called the customer, no answer; left a voicemail.","Linked to a known issue, a fix is planned.","Updated the customer's address on file.","Shared the knowledge article on this topic.","Closed after the customer confirmed.","Reset the account; login works again.","Checked the logs, nothing unusual found."],j=1440*60*1e3,V=365,Y=120,W=30,N=20,K=65,b=class{locale;localeData;geoGenerator;usernameToken=crypto.randomUUID().replace(/-/g,"").slice(0,8);random;today;companyDecks=new Map;companiesDealt=new Map;constructor(e,t={}){this.locale=e??"en_US",this.localeData=c(this.locale),this.geoGenerator=new u(this.locale),this.random=t.random??Math.random,this.today=t.today??(()=>new Date)}setLocale(e){this.locale=e,this.localeData=c(e),this.geoGenerator=new u(e)}generate(e,t,r=0){if(t<=0||e.length===0)return[];let a=[],o=e.filter(n=>f(n.config.fakerMethod??"lorem")==="phone");for(let n=r;n<r+t;n++){let d={},m=new Map,C=(s,p)=>{let y=m.get(s);if(y!==void 0)return y%p;let D=this.below(p);return m.set(s,D),D};for(let s of e){let p=o.indexOf(s),y=p>=0?n*o.length+p:n;d[s.fieldApiName]=this.generateFieldValue(s,y,C)}a.push(d)}return a}dateOf(e){return e==="pastDate"?this.pastDate():this.futureDate()}below(e){return Math.min(e-1,Math.floor(this.random()*e))}pick(e){return e[this.below(e.length)]}generateFieldValue(e,t,r){let a=e.config.fakerMethod??"lorem",o={min:e.config.minValue??0,max:e.config.maxValue??1e3},n=e.config.fakerLocale;if(n&&n!==this.locale){let d=this.locale,m=this.localeData,C=this.geoGenerator;this.locale=n,this.localeData=c(n),this.geoGenerator=new u(n);let s=this.generateByMethodInstance(a,t,o,r);return this.locale=d,this.localeData=m,this.geoGenerator=C,s}return this.generateByMethodInstance(a,t,o,r)}generateByMethodInstance(e,t,r,a){let o=f(e);if(!o)return Z(e);let n=()=>a("geo",1e4);switch(o){case"name":return`${this.firstName(a)} ${this.lastName(a)}`;case"firstName":return this.firstName(a);case"lastName":return this.lastName(a);case"jobTitle":return`${this.pick(M)} ${this.pick(P)} ${this.pick(U)}`;case"email":return this.generateEmail(t,a);case"username":return this.generateUsername(t,a);case"nickname":return this.generateNickname(t,a);case"phone":return this.generatePhone(t);case"address":return`${this.streetAddress()}, ${this.geoGenerator.getCity(n())}`;case"streetAddress":return this.streetAddress();case"city":return this.geoGenerator.getCity(n());case"country":return this.geoGenerator.getCountry(n());case"state":return this.geoGenerator.getState(n());case"company":return this.generateCompany();case"catchPhrase":return`${this.pick(G)} ${this.pick(O)} `+this.pick(I);case"date":case"pastDate":return this.pastDate();case"futureDate":return this.futureDate();case"futureDateTime":return this.futureDateTime();case"birthdate":return this.birthdate();case"number":case"integer":return Math.floor(r.min+this.random()*(r.max-r.min+1));case"float":return Math.round((r.min+this.random()*(r.max-r.min))*100)/100;case"boolean":return t%2===0;case"lorem":case"sentence":return g(t);case"paragraph":return q(t);case"caseSubject":return this.pick(H);case"caseComment":return this.pick(x);case"uuid":return this.uuid();case"url":return`https://example.com/resource/${t}`;case"zipCode":return this.geoGenerator.getZipCode(n());case"productName":return this.productName(a);case"productDescription":return`${this.productName(a)}, made for ${this.pick(J)}.`;case"iban":return this.generateIban(t);case"bic":return this.generateBic(t)}}firstName(e){let t=this.localeData.firstNames;return t[e("first",t.length)]}lastName(e){let t=this.localeData.lastNames;return t[e("last",t.length)]}generateEmail(e,t){let r=this.localeData.emailDomains[e%this.localeData.emailDomains.length];return`${h(this.firstName(t))}.${h(this.lastName(t))}${e}@${r}`}generateUsername(e,t){let r=h(this.firstName(t)),a=h(this.lastName(t)),o=this.localeData.emailDomains[e%this.localeData.emailDomains.length];return`${r}.${a}.${this.usernameToken}${e}@${o}`}generateNickname(e,t){return`${h(this.firstName(t)).slice(0,20)}.${this.usernameToken}${e}`}generatePhone(e){return k(this.locale,e)}streetAddress(){let{names:e,format:t}=z[l(this.locale)];return t.replace("{street}",this.pick(e)).replace("{n}",String(1+this.below(199))).replace("{m}",String(1+this.below(9)))}generateCompany(){let e=l(this.locale),t=A[e].companies.length,r=this.companyDecks.get(e);if(!r||r.length!==t){r=Array.from({length:t},(o,n)=>n);for(let o=r.length-1;o>0;o--){let n=this.below(o+1);[r[o],r[n]]=[r[n],r[o]]}this.companyDecks.set(e,r)}let a=this.companiesDealt.get(e)??0;return this.companiesDealt.set(e,a+1),v(e,r[a%r.length],Math.floor(a/r.length))}productName(e){let t=T[e("productAdjective",T.length)],r=E[e("productMaterial",E.length)],a=_[e("product",_.length)];return`${t} ${r} ${a}`}pastDate(){return S(this.daysFromToday(-(1+this.below(V))))}futureDate(){return S(this.daysFromToday(1+this.below(Y)))}futureDateTime(){let e=this.daysFromToday(1+this.below(W));return e.setUTCHours(8+this.below(9),this.below(2)*30,0,0),e.toISOString()}birthdate(){let e=(K-N)*365;return S(this.daysFromToday(-(N*365+this.below(e))))}daysFromToday(e){return new Date(this.today().getTime()+e*j)}uuid(){let e=Array.from({length:32},()=>this.below(16).toString(16));e[12]="4",e[16]=(this.below(16)&3|8).toString(16);let t=e.join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}generateIban(e){let t=$[l(this.locale)],r=R("#".repeat(t.bbanLength),e);return`${t.country}${X(t.country,r)}${r}`}generateBic(e){let t=Array.from({length:4},(a,o)=>String.fromCharCode(65+(e*5+o*7+3)%26)).join(""),r=Array.from({length:2},(a,o)=>w[(e*3+o*11+2)%w.length]).join("");return`${t}${F[l(this.locale)]}${r}XXX`}};function oe(i,e,t,r,a){let o=new b(r,a),n={fieldApiName:"temp",ruleType:"faker",config:{fakerMethod:i,minValue:t.min,maxValue:t.max}};return o.generate([n],e+1)[e]?.temp}function S(i){return i.toISOString().split("T")[0]}function h(i){return i.normalize("NFD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z]/g,"")}function X(i,e){let t=`${e}${i}00`.replace(/[A-Z]/g,a=>String(a.charCodeAt(0)-55)),r=0;for(let a of t)r=(r*10+Number(a))%97;return String(98-r).padStart(2,"0")}function Z(i){throw new Error(`Faker method "${i}" is not implemented: choose a method SandForge generates, or remove it from the field rule.`)}function g(i){let e=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit"],t=i%e.length,r=[];for(let a=0;a<6;a++)r.push(e[(t+a)%e.length]);return r.join(" ")+"."}function q(i){return[g(i),g(i+1),g(i+2)].join(" ")}export{b as a,oe as b};
@@ -0,0 +1,8 @@
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{c as u}from"./chunk-PUOX4NBJ.mjs";import{cb as f,ka as d}from"./chunk-B45CNPUX.mjs";import{mkdir as h,readdir as g,readFile as m,rename as w,writeFile as S}from"node:fs/promises";import*as c from"node:path";var k=".sandforge-scenario.json",P={depth:3,files:50},y=new Set(["node_modules","dist","out","coverage"]),E=10;function O(){return{list:async r=>{try{return(await g(r,{withFileTypes:!0})).map(e=>({name:e.name,folder:e.isDirectory()}))}catch(t){let e=t.code;if(e==="ENOENT"||e==="ENOTDIR"||e==="EACCES")return[];throw t}},readFile:r=>m(r,"utf8"),writeNew:async(r,t)=>{await h(c.dirname(r),{recursive:!0});try{return await S(r,t,{encoding:"utf8",flag:"wx"}),!0}catch(e){if(e.code==="EEXIST")return!1;throw e}},replace:async(r,t)=>{let e=`${r}.${process.pid}.tmp`;await S(e,t,"utf8"),await w(e,r)}}}function x(r){let t;try{t=JSON.parse(r)}catch{return{issues:["The file is not JSON"]}}let e=d.safeParse(t);return e.success?{pack:e.data}:{issues:e.error.issues.slice(0,E).map(n=>`${n.path.join(".")||"the file"}: ${n.message}`)}}async function F(r,t){let e=[],n=async(a,o,i)=>{let p=[...await r.list(o)].sort((s,l)=>s.name.localeCompare(l.name));for(let s of p){if(e.length>=P.files)return;let l=c.join(o,s.name);s.folder?i<P.depth&&!v(s.name)&&await n(a,l,i+1):s.name.endsWith(k)&&e.push({path:l,relativePath:c.relative(a,l).split(c.sep).join("/")})}};for(let a of t)await n(a,a,0);return e}function v(r){return r.startsWith(".")||y.has(r)}async function N(r,t){let e=f.map(n=>({source:"built-in",pack:n}));for(let n of await F(r,t)){let a;try{a=await r.readFile(n.path)}catch{e.push({source:"workspace",...n,issues:["The file could not be read"]});continue}let o=x(a);e.push({source:"workspace",...n,...o})}return e}function A(r){return`${JSON.stringify(r,null,2)}
8
+ `}async function T(r,t,e,n=!1){let a=t[0];if(a===void 0)return{kind:"no-workspace"};let o=d.parse(e),i=`${o.id}${k}`,p=c.join(a,i),s=A(o);if(n)await r.replace(p,s);else if(!await r.writeNew(p,s))return{kind:"exists",path:p,relativePath:i};return{kind:"saved",path:p,relativePath:i}}async function b(r,t,e,n){let a=i=>i.id===e&&u(i)===n,o=f.find(a);if(o)return o;for(let i of await N(r,t))if(i.source==="workspace"&&"pack"in i&&a(i.pack))return i.pack}export{k as a,P as b,O as c,x as d,F as e,N as f,A as g,T as h,b as i};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{d as R,g as b}from"./chunk-GCOB7K5N.mjs";import{b as l,e as f,f as y,l as g}from"./chunk-7EANH5PY.mjs";var N="RECORD_TYPE_UNAVAILABLE",h="RECORD_TYPE_UNMAPPED",A=g({recordTypeId:l().regex(/^[A-Za-z0-9]{15}([A-Za-z0-9]{3})?$/),developerName:l().min(1).optional(),name:l().optional(),available:y(),active:y().optional(),master:y().optional(),defaultRecordTypeMapping:y().optional()}).loose();function w(e){if(!Array.isArray(e))return[];let r=[];for(let t of e){let n=A.safeParse(t);if(!n.success)continue;let o=n.data,c=o.name??o.developerName??o.recordTypeId;r.push({recordTypeId:o.recordTypeId,developerName:o.master===!0?"Master":o.developerName??c,name:c,available:o.available,active:o.active??!0,master:o.master??!1,defaultRecordTypeMapping:o.defaultRecordTypeMapping??!1})}return r}function p(e){return e.slice(0,15)}function E(e,r){if(r.length===0)return[...e];let t=new Map(r.map(n=>[p(n.id),n]));return e.map(n=>{let o=t.get(p(n.recordTypeId));return o?{...n,developerName:R(o),namespacePrefix:o.namespacePrefix??null}:n})}function z(e){let r=e.namespacePrefix;if(r===void 0)return b(e.developerName);let t=r?`${r}__`:"";return{namespacePrefix:r,developerName:e.developerName.startsWith(t)?e.developerName.slice(t.length):e.developerName}}function O(e,r,t){if(t.length===0)return[];let n=new Map;for(let o of r){let c=o.RecordTypeId;typeof c!="string"||c.length<15||n.set(c,(n.get(c)??0)+1)}return I(e,n,t)}function I(e,r,t){if(t.length===0)return[];let n=new Map(t.map(c=>[p(c.recordTypeId),c])),o=new Map;for(let[c,i]of r){if(c.length<15||i<=0)continue;let a=n.get(p(c));if(!a||a.available||a.master)continue;let d=o.get(a.recordTypeId);d?d.recordCount+=i:o.set(a.recordTypeId,{objectApiName:e,recordTypeId:a.recordTypeId,developerName:a.developerName,name:a.name,inactive:!a.active,recordCount:i})}return[...o.values()].sort((c,i)=>c.developerName.localeCompare(i.developerName))}var $=/^012000000000000(AAA)?$/;function _(e,r,t,n){if(t.length===0)return[];let o=new Set(t.map(a=>p(a.recordTypeId))),c=new Map(n.map(a=>[p(a.recordTypeId),a])),i=new Map;for(let[a,d]of r){if(a.length<15||d<=0||$.test(a))continue;let u=p(a);if(o.has(u))continue;let T=i.get(u);if(T){T.recordCount+=d;continue}let s=c.get(u);i.set(u,{objectApiName:e,recordTypeId:a,developerName:s?.developerName??a,name:s?.name??s?.developerName??a,inactive:!1,recordCount:d,unmapped:!0,...s&&!s.active?{inactiveInSource:!0}:{}})}return[...i.values()].sort((a,d)=>a.developerName.localeCompare(d.developerName))}function k(e){return`SELECT RecordTypeId, COUNT(Id) n FROM ${e} GROUP BY RecordTypeId`}var U=g({RecordTypeId:l().nullable(),n:f().int().nonnegative()}).loose();function j(e){let r=new Map;for(let[t,n]of M(e))t&&r.set(t,n);return r}function M(e){let r=new Map;if(!Array.isArray(e))return r;for(let t of e){let n=U.safeParse(t);if(!n.success)continue;let o=n.data.RecordTypeId||null;r.set(o,(r.get(o)??0)+n.data.n)}return r}function S(e,r){let t=e.RecordTypeId;return typeof t=="string"&&r.some(n=>p(n.recordTypeId)===p(t))}function m(e){return`${e.recordCount} ${e.objectApiName} record${e.recordCount===1?"":"s"}`}function v(e){return e.name&&e.name!==e.developerName?`${e.developerName} (${e.name})`:e.developerName}function x(e){let r=e.recordCount===1?"uses":"use";return e.unmapped&&e.inactiveInSource?`${m(e)} ${r} record type ${v(e)}, which is inactive in the source org: no record type of the target org is mapped to it. Map it to one the running user has on ${e.objectApiName}.`:e.unmapped?`${m(e)} ${r} record type ${v(e)}, which has no active ${e.objectApiName} record type of that API name in the target org. Create or activate record type ${e.developerName} on ${e.objectApiName} in the target org, or map it to one the running user has.`:e.inactive?`${m(e)} ${r} record type ${v(e)}, which is inactive in the target org. Activate record type ${e.developerName} on ${e.objectApiName} in the target org, or map it to an active one the running user has.`:`${m(e)} ${r} record type ${v(e)}, which the running user cannot use in the target org. Give the running user access to record type ${e.developerName} on ${e.objectApiName}, or map it to one they have.`}function D(e){return`${e.unmapped?h:N}: ${x(e)}`}export{N as a,w as b,E as c,z as d,O as e,I as f,_ as g,k as h,j as i,M as j,S as k,x as l,D as m};
@@ -0,0 +1,13 @@
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{E as k,d as I,l as H,m as W,n as K}from"./chunk-NEVXIGR6.mjs";import{C as at}from"./chunk-HJC7AIBK.mjs";import{a as J}from"./chunk-SIOZXPFG.mjs";import{b as N,l as j}from"./chunk-7EANH5PY.mjs";import{createReadStream as $t}from"node:fs";import{appendFile as Ut,stat as jt,writeFile as Jt}from"node:fs/promises";import{StringDecoder as Ht}from"node:string_decoder";import{promisify as dt}from"node:util";import{createGunzip as Wt,gunzip as Kt,gzip as Gt}from"node:zlib";var Yt=dt(Gt),Zt=dt(Kt),Xt=64*1024,Vt=".gz",Qt=6,A=10,ft=4,ut=Buffer.from("SF","latin1"),Y=8,F=6+Y,Z=A+F,X=Z+2+8;function B(s){return`${s}${Vt}`}async function qt(s){let t=await Yt(s,{level:Qt});if(t[3]!==0)throw new Error("zlib wrote a gzip header with flags set");let e=Buffer.from(t.subarray(0,A));e[3]=ft;let n=Buffer.alloc(F);return n.writeUInt16LE(F-2,0),ut.copy(n,2),n.writeUInt16LE(Y,4),n.writeUInt32LE(t.length+F,6),n.writeUInt32LE(s.length,10),Buffer.concat([e,n,t.subarray(A)])}function ht(s){if(s.length<Z||s[0]!==31||s[1]!==139||s[2]!==8||s[3]!==ft||s.readUInt16LE(A)!==F-2||!s.subarray(A+2,A+4).equals(ut)||s.readUInt16LE(A+4)!==Y)return;let t=s.readUInt32LE(A+6),e=s.readUInt32LE(A+10);return t>=X&&e>0?{total:t,raw:e}:void 0}function te(s,t=Xt){let e=[],n=0,r=0;for(;r<s.length;){let i=s.indexOf(10,r),o=i<0?s.length:i+1;o-n>t&&r>n&&(e.push(s.subarray(n,r)),n=r),r=o,r-n>=t&&(e.push(s.subarray(n,r)),n=r)}return r>n&&e.push(s.subarray(n,r)),e}async function ct(s){let t=te(Buffer.from(s,"utf8"));return Buffer.concat(await Promise.all(t.map(e=>qt(e))))}function T(s){return s.endsWith(".ndjson")}function _e(s){let t=new Map,e=(n,r)=>{let i=r(t.get(n)??Promise.resolve());return t.set(n,i),i.then(()=>{t.get(n)===i&&t.delete(n)},()=>{}),i};return{...s,writeFile:(n,r)=>{if(!T(n))return s.writeFile(n,r);let i=B(n);return e(i,o=>o.catch(()=>{}).then(async()=>{let a=r===""?Buffer.alloc(0):await ct(r);await Jt(i,a,{mode:I})}))},appendFile:(n,r)=>{if(!T(n))return s.appendFile(n,r);let i=B(n);return e(i,o=>o.then(async()=>{r!==""&&await Ut(i,await ct(r),{mode:I})}))},exists:n=>s.exists(T(n)?B(n):n),rm:n=>s.rm(T(n)?B(n):n),readLines:n=>T(n)?ee(B(n)):s.readLines(n)}}async function*ee(s){if((await jt(s)).size===0)return;let t=$t(s),e=Wt(),n=o=>{e.destroy(o)};t.on("error",n),t.pipe(e);let r=new Ht("utf8"),i="";try{for await(let o of e){let a=(i+r.write(o)).split(`
8
+ `);i=a.pop()??"",yield*a}i+=r.end(),i!==""&&(yield i)}finally{t.off("error",n),t.destroy(),e.destroy()}}async function G(s,t,e){let n=Buffer.alloc(e),r=0;for(;r<e;){let{bytesRead:i}=await s.read(n,r,e-r,t+r);if(i===0)break;r+=i}return r===e?n:n.subarray(0,r)}async function lt(s,t,e,n){let r;try{r=await Zt(s,{maxOutputLength:t.raw})}catch{throw n(`holds a block that does not inflate at byte ${e}`)}if(r.length!==t.raw)throw n(`holds a block at byte ${e} that inflates to other than its header says`);return r}async function pt(s,t,e,n){let r=await G(s,t,e);if(r.length<e)throw n(`is cut short at byte ${t+r.length}`);let i=ht(r);if(i===void 0)throw n(`holds no block where its index says, at byte ${t}`);if(i.total!==e)throw n(`holds another block than its index says at byte ${t}`);return lt(r,i,t,n)}async function*gt(s,t,e){for(let n=0;n<t;){let r=ht(await G(s,n,Math.min(Z,t-n)));if(r===void 0)throw e(`holds no block at byte ${n}`);if(r.total>t-n)throw e(`is cut short: its block at byte ${n} ends past the file's end`);let i=await G(s,n,r.total);yield{at:n,total:r.total,lines:await lt(i,r,n,e)},n+=r.total}}function*mt(s){let t=0;for(;t<s.length;){let e=s.indexOf(10,t),n=e<0?s.length:e;yield{at:t,length:n-t},t=n+1}}import{randomBytes as Se}from"node:crypto";import{open as C,readFile as it,rename as xe,rm as ke,stat as Ae}from"node:fs/promises";import{dirname as Ft,join as Be}from"node:path";import{closeSync as ne,fstatSync as re,openSync as ie,readSync as se,writeSync as oe}from"node:fs";function Ue(s){let t=ie(s,"a+"),e=re(t).size;return{size:()=>e,append:n=>{let r=Buffer.from(n,"utf8"),i=0;for(;i<r.length;)i+=oe(t,r,i);e+=r.length},read:(n,r)=>{let i=Buffer.alloc(r),o=0;for(;o<r;){let a=se(t,i,o,r-o,n+o);if(a===0)break;o+=a}return i.subarray(0,o)},close:()=>ne(t)}}function yt(s,t){return t===void 0?s:`${s}/${t}`}var wt=/^[A-Za-z][A-Za-z0-9]*$/,bt=/^[0-9a-f]{64}$/,x=1,O=2,z=3,S=4,ae={created:x,existing:O,updated:z},St={[x]:"created",[O]:"existing",[z]:"updated"},xt={[x]:"c",[O]:"e",[z]:"u",[S]:"i"},V={c:x,e:O,u:z,i:S},ce="x",de="a",fe="j",Ot="d",Q="n",P="t",kt="found",ue="found-owed";function je(s,t,e,n){return JSON.stringify([Ot,s,t,e,n])}function Je(s){if(!s.startsWith(`["${Ot}"`))return;let t;try{t=JSON.parse(s)}catch{return}if(!Array.isArray(t))return;let[,,,e,n]=t;if(!(typeof e!="string"||!Number.isFinite(Date.parse(e)))&&!(typeof n!="string"||!Number.isFinite(Date.parse(n))))return{orgAt:e,at:n}}function he(s,t=!1){return JSON.stringify([t?"w":"o",s.objectApiName,s.newId,s.sourceId??"",s.fieldName,s.sourceRefId,s.insertOnly?1:0])}var le=1024*1024,pe=1024*1024,ge=2e4,me=2e4,ye=.6,we=3;function g(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function y(s){let t=2538058380;for(let e=0;e<s.length;e++)t=Math.imul(t^s.charCodeAt(e),1540483477),t^=t>>>15;return t>>>0}var v=class{constructor(t){this.keyAt=t}keyAt;capacity=1024;used=0;h1=new Uint32Array(this.capacity);h2=new Uint32Array(this.capacity);at=new Float64Array(this.capacity);len=new Uint16Array(this.capacity);code=new Uint8Array(this.capacity);get size(){return this.used}get slots(){return this.capacity}find(t,e,n,r){let i=this.capacity-1,o=n&i;for(;;){let a=this.at[o];if(a===0)return~o;if(this.h1[o]===e&&this.h2[o]===n&&(r===a-1||this.keyAt(a-1,this.len[o])===t))return o;o=o+1&i}}offsetOf(t){return this.at[t]-1}lengthOf(t){return this.len[t]}codeOf(t){return this.code[t]}put(t,e,n,r,i,o){let a=t;t<0&&(this.used+1>this.capacity*ye?(this.grow(),a=this.freeSlotFor(n)):a=~t,this.used++,this.h1[a]=e,this.h2[a]=n),this.at[a]=r+1,this.len[a]=i,this.code[a]=o}freeSlotFor(t){let e=this.capacity-1,n=t&e;for(;this.at[n]!==0;)n=n+1&e;return n}grow(){let{h1:t,h2:e,at:n,len:r,code:i}=this;this.capacity*=2,this.h1=new Uint32Array(this.capacity),this.h2=new Uint32Array(this.capacity),this.at=new Float64Array(this.capacity),this.len=new Uint16Array(this.capacity),this.code=new Uint8Array(this.capacity);for(let o=0;o<n.length;o++){if(n[o]===0)continue;let a=this.freeSlotFor(e[o]);this.h1[a]=t[o],this.h2[a]=e[o],this.at[a]=n[o],this.len[a]=r[o],this.code[a]=i[o]}}};function At(s){return s?s[0]==="p"&&s.length>=3?tt(String(s[1]),String(s[2])):s[0]==="g"&&s.length>=3?et(String(s[2])):s[0]===P&&s.length>=2?q(String(s[1])):"":""}function q(s){return`t\0${s}`}function tt(s,t){return`p\0${s}\0${t}`}function et(s){return`g\0${s}`}function*be(s){let t=s.size(),e=0,n=Buffer.alloc(0),r=0;for(;e<t;){let i=s.read(e,Math.min(pe,t-e));if(i.length===0)break;e+=i.length;let o=n.length>0?Buffer.concat([n,i]):i,a=0;for(;;){let d=o.indexOf(10,a);if(d<0)break;d>a&&(yield{offset:r+a,length:d-a,text:o.toString("utf8",a,d)}),a=d+1}n=o.subarray(a),r+=a}}var Bt=class s{constructor(t){this.file=t;this.index=new v((e,n)=>this.idOfLine(e,n)),this.marks=new v((e,n)=>At(w(this.lineAt(e,n)))),this.createdTargets=new v((e,n)=>{let r=w(this.lineAt(e,n));return r?M(String(r[2]??"")):""})}file;index;cache=new Map;pending=[];pendingBytes=0;flushQueued=!1;partStart=Number.POSITIVE_INFINITY;parts=0;mappedCount=0;counts=new Map;earlierByObject=new Map;earlierPastCheckpoint=new Map;checkpointsByObject=new Map;owedCount=0;statuses=new Map;given=new Map;marks;createdTargets;createdUnattributedKeys=new Set;readsHeld=[];withTheirRecordMarked=0;callsSent=0;foundAfterStop=new Set;foundOwingUntold=new Set;plan;static open(t){let e=new s(t);return e.readWhatIsThere(),e}get partCount(){return this.parts}get resumes(){return this.checkpointsByObject.size>0||this.earlierByObject.size>0||this.owedCount>0}get earlierMapped(){return this.partStart===Number.POSITIVE_INFINITY?this.mappedCount:this.mappedBeforePart}mappedBeforePart=0;beginPart(t){this.flush(),this.mappedBeforePart=this.mappedCount,this.withTheirRecordMarked=0,this.partStart=this.file.size(),this.write({part:{n:this.parts,startedAt:t.toISOString()}}),this.parts++,this.flush()}nameSamplePlan(t){if(!bt.test(t.sha256))throw new Error("Not the SHA-256 of a plan.");this.write({sample:{dir:t.dir,sha256:t.sha256}}),this.plan={dir:t.dir,sha256:t.sha256},this.flush()}get samplePlan(){return this.plan?{...this.plan}:void 0}setMapping(t,e,n,r){let i=ae[t],o=g(e),a=y(e),d=this.cache.get(e),u=this.index.find(e,o,a,d?.at),h=u>=0&&this.index.codeOf(u)!==S;h&&this.uncount(e,u,d);let c=JSON.stringify([xt[i],e,n,r??""]),f=this.write(c);if(this.index.put(u,o,a,f,Buffer.byteLength(c),i),i===x&&this.indexCreated(n,f,Buffer.byteLength(c)),h||this.mappedCount++,r){let l=this.countsOf(r);i===x?l.created++:i===O?l.linked++:l.updated++}this.remember(e,{at:f,code:i,targetId:n,objectApiName:r??""})}uncount(t,e,n){let r=this.index.offsetOf(e);if(r<this.partStart)return;let i=this.index.codeOf(e),o=n?.at===r?n:this.recordAt(t,e),a=o?.objectApiName?this.counts.get(o.objectApiName):void 0;a&&(i===x?a.created--:i===O?a.linked--:a.updated--)}countsOf(t){let e=this.counts.get(t);return e||(e={created:0,linked:0,updated:0},this.counts.set(t,e)),e}mapping(t){let e=this.lookUp(t);if(!(!e||e.code===S))return{kind:St[e.code],sourceId:t,targetId:e.targetId,...e.objectApiName?{objectApiName:e.objectApiName}:{},earlier:e.at<this.partStart}}createdTarget(t){let e=M(t);if(this.createdUnattributedKeys.has(e))return!0;if(this.createdTargets.size===0)return!1;let n=this.createdTargets.find(e,g(e),y(e));if(n<0)return!1;let r=this.createdTargets.offsetOf(n),i=w(this.lineAt(r,this.createdTargets.lengthOf(n)));if(!i)return!1;let o=String(i[1]),a=this.index.find(o,g(o),y(o));return a>=0&&this.index.offsetOf(a)===r&&this.index.codeOf(a)===x}indexCreated(t,e,n){let r=M(t);if(!r)return;let i=g(r),o=y(r);this.createdTargets.put(this.createdTargets.find(r,i,o),i,o,e,n,x)}targetOf(t){let e=this.lookUp(t);return e&&e.code!==S?e.targetId:void 0}get mappedSize(){return this.mappedCount}countsByObject(){let t=[];for(let[e,{created:n,linked:r,updated:i}]of this.counts)n+r+i!==0&&t.push(i>0?{objectApiName:e,created:n,linked:r,updated:i}:{objectApiName:e,created:n,linked:r});return t}linkedToCreatedCount(){let t=0;for(let c of this.counts.values())t+=c.linked;if(t===0)return 0;let e=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart,n=(c,f)=>{let l=w(this.lineAt(c,f));return l?String(l[2]).slice(0,15):""},r=(c,f)=>{if(c.offset<e)return;let l=V[String(f[0])];if(l===void 0||l===S||!f[3])return;let p=String(f[1]),m=this.index.find(p,g(p),y(p),c.offset);return m>=0&&this.index.offsetOf(m)===c.offset?l:void 0},i=(c,f,l)=>{let p=g(f),m=y(f);c.put(c.find(f,p,m),p,m,l.offset,l.length,0)},o=(c,f)=>c.size>0&&c.find(f,g(f),y(f))>=0,a=new v(n);for(let c of this.lines()){if(!c.text.startsWith('["'))continue;let f=w(c.text);!f||r(c,f)!==O||this.markedWithTheirRecord(String(f[1]))||i(a,String(f[2]).slice(0,15),c)}if(a.size===0)return 0;let d=new v(n),u=new Set;for(let c of this.lines()){if(!c.text.startsWith('["')||c.offset<e)continue;let f=w(c.text);if(!f)continue;if(f[0]===Q&&Array.isArray(f[2])){for(let p of f[2]){let m=String(p).slice(0,15);o(a,m)&&u.add(m)}continue}if(r(c,f)!==x)continue;let l=String(f[2]).slice(0,15);o(a,l)&&i(d,l,c)}if(d.size===0&&u.size===0)return 0;let h=0;for(let c of this.lines()){if(!c.text.startsWith('["'))continue;let f=w(c.text);if(!f||r(c,f)!==O||this.markedWithTheirRecord(String(f[1])))continue;let l=String(f[2]).slice(0,15);(o(d,l)||u.has(l))&&h++}return h}earlierRecordsOf(t,e=!1){return(e?this.earlierPastCheckpoint:this.earlierByObject).get(t)??0}*mappings(){for(let t of this.lines()){if(!t.text.startsWith('["'))continue;let e=w(t.text);if(!e)continue;let n=V[String(e[0])];if(n===void 0||n===S)continue;let r=String(e[1]),i=this.index.find(r,g(r),y(r),t.offset);if(i<0||this.index.offsetOf(i)!==t.offset)continue;let o=String(e[3]??"");yield{kind:St[n],sourceId:r,targetId:String(e[2]),...o?{objectApiName:o}:{},earlier:t.offset<this.partStart}}}noteRead(t){this.readsHeld.push(t),this.readsHeld.length>=me&&this.settleReads()}settleReads(){let t=this.readsHeld;this.readsHeld=[];for(let e of t){let n=g(e),r=y(e),i=this.index.find(e,n,r,this.cache.get(e)?.at);if(i>=0)continue;let o=JSON.stringify([xt[S],e]),a=this.write(o);this.index.put(i,n,r,a,Buffer.byteLength(o),S)}}wasRead(t){return this.readsHeld.includes(t)?!0:this.index.find(t,g(t),y(t),this.cache.get(t)?.at)>=0}checkpoint(t,e,n){if(n!==void 0&&!wt.test(n))throw new Error(`Not the name of a pass: ${JSON.stringify(n.slice(0,40))}`);this.settleReads(),this.write({at:{object:t,...n!==void 0?{pass:n}:{},...e}}),this.checkpointsByObject.set(yt(t,n),{...e}),this.flush()}checkpoints(){return new Map(this.checkpointsByObject)}owe(t,e=!1){this.owedCount++,this.write(he(t,e))}get owed(){return this.owedCount}*owedPages(t){let e=[];for(let n of this.lines()){if(!n.text.startsWith('["o"')&&!n.text.startsWith('["w"'))continue;let r=w(n.text);if(!r||r.length<7)continue;let[i,o,a,d,u,h,c]=r;e.push({update:{objectApiName:String(o),newId:String(a),sourceId:d?String(d):void 0,fieldName:String(u),sourceRefId:String(h),...c===1?{insertOnly:!0}:{}},toRowWrittenBefore:i==="w"}),e.length>=t&&(yield e,e=[])}e.length>0&&(yield e)}patched(t,e){this.mark(JSON.stringify(["p",t,e]),tt(t,e))}wasPatched(t,e){return this.hasMark(tt(t,e))}mark(t,e){let n=g(e),r=y(e),i=this.marks.find(e,n,r),o=this.write(t);this.marks.put(i,n,r,o,Buffer.byteLength(t),0)}hasMark(t){return this.marks.size>0&&this.marks.find(t,g(t),y(t))>=0}owedLeftByEarlierParts(){let t=new Set;for(let n of this.lines()){if(n.offset>=this.partStart)break;if(!n.text.startsWith('["p"'))continue;let r=w(n.text);r&&r.length>=3&&t.add(`${String(r[1])}\0${String(r[2])}`)}let e=[];for(let n of this.lines()){if(n.offset>=this.partStart)break;if(!n.text.startsWith('["o"'))continue;let r=w(n.text);if(!r||r.length<7)continue;let[,i,o,a,d,u,h]=r;t.has(`${String(o)}\0${String(d)}`)||e.push({objectApiName:String(i),newId:String(o),sourceId:a?String(a):void 0,fieldName:String(d),sourceRefId:String(u),...h===1?{insertOnly:!0}:{}})}return e}oweStatus(t,e,n){this.write(JSON.stringify(["s",t,e,n])),this.tallyStatus({objectApiName:t,id:e,status:n})}tallyStatus(t){let e=this.statuses.get(t.objectApiName);e||(e={count:0,samples:[]},this.statuses.set(t.objectApiName,e)),e.count++,e.samples.length<we&&e.samples.push(t)}gaveStatus(t,e){this.statusGiven(e)||(this.mark(JSON.stringify(["g",t,e]),et(e)),this.given.set(t,(this.given.get(t)??0)+1))}statusGiven(t){return this.hasMark(et(t))}statusesOwed(){let t=new Map;for(let[e,n]of this.statuses){let r=n.count-(this.given.get(e)??0);r<=0||t.set(e,{count:r,samples:n.samples.filter(({id:i})=>!this.statusGiven(i))})}return t}*statusLines(){for(let t of this.lines()){if(!t.text.startsWith('["s"'))continue;let e=w(t.text);!e||e.length<4||(yield{objectApiName:String(e[1]),id:String(e[2]),status:String(e[3])})}}withTheirRecord(t){let e=q(t),n=g(e),r=y(e),i=this.marks.find(e,n,r),o=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart;if(i>=0&&this.marks.offsetOf(i)>=o)return;let a=JSON.stringify([P,t]),d=this.write(a);this.marks.put(i,n,r,d,Buffer.byteLength(a),0),this.withTheirRecordMarked++}get withTheirRecordCount(){return this.withTheirRecordMarked}markedWithTheirRecord(t){if(this.withTheirRecordMarked===0)return!1;let e=q(t),n=this.marks.find(e,g(e),y(e)),r=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart;return n>=0&&this.marks.offsetOf(n)>=r}*withTheirRecordIds(){if(this.withTheirRecordMarked!==0)for(let t of this.lines()){if(t.offset<this.partStart||!t.text.startsWith(`["${P}"`))continue;let e=w(t.text);e&&e.length>=2&&(yield String(e[1]))}}sent(t,e,n,r=new Date,i){this.callsSent++;let o=`${Math.max(0,this.parts-1)}.${this.callsSent}`;return this.write(JSON.stringify([ce,o,t,r.toISOString(),e,n.map(({sourceId:a,fingerprint:d,externalKey:u,jobKey:h})=>i!==void 0&&u!==void 0?[a,d,u]:h!==void 0?[a,d,"",h]:[a,d]),n.flatMap(({owes:a},d)=>(a??[]).map(({field:u,sourceRefId:h,insertOnly:c})=>[d,u,h,c?1:0])),...i!==void 0?[i]:[]])),this.flush(),o}answered(t){this.write(JSON.stringify([de,t]))}jobOpened(t,e){this.write(JSON.stringify([fe,t,e])),this.flush()}createdUnattributed(t,e){if(e.length!==0){this.write(JSON.stringify([Q,t,[...e]]));for(let n of e)this.createdUnattributedKeys.add(M(n))}}wasFoundAfterStop(t){return this.foundAfterStop.has(t)}owesUntold(t){return this.foundOwingUntold.has(t)}flush(){if(this.pending.length===0)return;let t=this.pending.join("");this.pending=[],this.pendingBytes=0,this.file.append(t)}close(){this.settleReads(),this.flush(),this.file.close()}write(t){let e=typeof t=="string"?t:JSON.stringify(t),n=this.file.size()+this.pendingBytes,r=`${e}
9
+ `;return this.pending.push(r),this.pendingBytes+=Buffer.byteLength(r),this.pendingBytes>=le?this.flush():this.flushQueued||(this.flushQueued=!0,queueMicrotask(()=>{this.flushQueued=!1,this.flush()})),n}lineAt(t,e){return t+e>this.file.size()&&this.flush(),this.file.read(t,e).toString("utf8")}idOfLine(t,e){let n=w(this.lineAt(t,e));return n?String(n[1]):""}lookUp(t){let e=this.cache.get(t);if(e)return this.cache.delete(t),this.cache.set(t,e),e;let n=this.index.find(t,g(t),y(t));if(n<0)return;let r=this.recordAt(t,n);return r&&this.remember(t,r),r}recordAt(t,e){let n=this.index.offsetOf(e),r=w(this.lineAt(n,this.index.lengthOf(e)));if(!(!r||String(r[1])!==t))return{at:n,code:this.index.codeOf(e),targetId:String(r[2]??""),objectApiName:String(r[3]??"")}}remember(t,e){if(this.cache.delete(t),this.cache.set(t,e),this.cache.size>ge){let n=this.cache.keys().next().value;n!==void 0&&this.cache.delete(n)}}*lines(){this.flush(),yield*be(this.file)}readWhatIsThere(){for(let t of this.lines()){if(t.text.startsWith('["')){let n=w(t.text);n&&this.readRegistration(t,n);continue}let e;try{e=JSON.parse(t.text)}catch{continue}if(!(typeof e!="object"||e===null)){if("part"in e)this.parts++;else if("sample"in e){let n=e.sample;if(typeof n!="object"||n===null)continue;let{dir:r,sha256:i}=n;if(typeof r!="string"||r===""||typeof i!="string"||!bt.test(i))continue;this.plan={dir:r,sha256:i}}else if("at"in e){let n=e.at;if(typeof n!="object"||n===null)continue;let{object:r,pass:i,lastId:o,read:a,done:d}=n;if(typeof r!="string"||typeof o!="string"||typeof a!="number"||i!==void 0&&(typeof i!="string"||!wt.test(i)))continue;this.checkpointsByObject.set(yt(r,i),{lastId:o,read:a,...d===!0?{done:d}:{}}),i===void 0&&this.earlierPastCheckpoint.delete(r)}}}}readRegistration(t,e){let n=String(e[0]);if(n==="o"||n==="w"){this.owedCount++;return}if(n==="s"){e.length>=4&&this.tallyStatus({objectApiName:String(e[1]),id:String(e[2]),status:String(e[3])});return}if(n==="p"||n==="g"||n===P){let c=At(e);if(!c)return;let f=g(c),l=y(c),p=this.marks.find(c,f,l);if(n==="g"&&p<0){let m=String(e[1]);this.given.set(m,(this.given.get(m)??0)+1)}this.marks.put(p,f,l,t.offset,t.length,0);return}if(n===Q){if(Array.isArray(e[2]))for(let c of e[2])this.createdUnattributedKeys.add(M(String(c)));return}let r=V[n];if(r===void 0)return;let i=String(e[1]);r===x&&(e[4]===kt||e[4]===ue)&&(this.foundAfterStop.add(i),e[4]===kt&&this.foundOwingUntold.add(i));let o=g(i),a=y(i),d=this.index.find(i,o,a),u=d>=0&&this.index.codeOf(d)!==S;if(r===S&&d>=0||(this.index.put(d,o,a,t.offset,t.length,r),r===S))return;r===x&&this.indexCreated(String(e[2]??""),t.offset,t.length),u||this.mappedCount++;let h=String(e[3]??"");h&&(this.earlierByObject.set(h,(this.earlierByObject.get(h)??0)+1),this.earlierPastCheckpoint.set(h,(this.earlierPastCheckpoint.get(h)??0)+1))}};function M(s){return s.slice(0,15)}function w(s){try{let t=JSON.parse(s);return Array.isArray(t)?t:void 0}catch{return}}var Et=2e3,b=15,nt=b,E=nt+8,st={format:1,head:Buffer.from("SFCKIDX1","latin1"),lengthAt:E+8,rowBytes:E+8+4},Mt={format:2,head:Buffer.from("SFCKIDX2","latin1"),memberBytesAt:E+8,lineAt:E+12,lengthAt:E+16,rowBytes:E+20},Lt={1:st,2:Mt},L=st.head.length,Rt=1<<20,Oe=500,R=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,Ee=/^[A-Za-z0-9]{15}$/,ot=/^[A-Za-z][A-Za-z0-9_]*$/;function tn(s,t){return L+s*Lt[t].rowBytes}function It(s){return s.replace(/[^A-Za-z0-9_-]/g,"_")}function Ct(s,t,e){if(!ot.test(e)||e.length>80)throw new k("invalid","Not a Salesforce API name");return Be(s.dir,"backups",`${It(t)}__${It(e)}.ndjson`)}var D=class{constructor(t,e){this.layout=t;this.rowBytes=t.rowBytes,this.bytes=e??Buffer.alloc(this.rowBytes*1024),this.size=e?e.length/this.rowBytes:0}layout;bytes;rowBytes;size;push(t,e,n){let r=this.size*this.rowBytes;if(r+this.rowBytes>this.bytes.length){let d=Buffer.alloc(Math.max(this.bytes.length*2,this.rowBytes*1024));this.bytes.copy(d,0,0,r),this.bytes=d}let{memberBytesAt:i,lineAt:o,lengthAt:a}=this.layout;return this.bytes.write(t,r,b,"latin1"),this.bytes.writeDoubleLE(e,r+nt),this.bytes.writeDoubleLE(n.offset,r+E),i!==void 0&&this.bytes.writeUInt32LE(n.memberBytes??0,r+i),o!==void 0&&this.bytes.writeUInt32LE(n.line??0,r+o),this.bytes.writeUInt32LE(n.length,r+a),this.size++}keyAt(t){let e=t*this.rowBytes;return this.bytes.toString("latin1",e,e+b)}holds(t,e){let n=t*this.rowBytes;for(let r=0;r<b;r++)if(this.bytes[n+r]!==e.charCodeAt(r))return!1;return!0}stampAt(t){return this.bytes.readDoubleLE(t*this.rowBytes+nt)}offsetAt(t){return this.bytes.readDoubleLE(t*this.rowBytes+E)}memberBytesAt(t){let e=this.layout.memberBytesAt;return e===void 0?0:this.bytes.readUInt32LE(t*this.rowBytes+e)}lineAt(t){let e=this.layout.lineAt;return e===void 0?0:this.bytes.readUInt32LE(t*this.rowBytes+e)}lengthAt(t){return this.bytes.readUInt32LE(t*this.rowBytes+this.layout.lengthAt)}before(t,e){return this.offsetAt(t)-this.offsetAt(e)||this.lineAt(t)-this.lineAt(e)}wellFormed(t){let e=this.stampAt(t),n=this.offsetAt(t);return Ee.test(this.keyAt(t))&&Number.isFinite(e)&&Number.isSafeInteger(n)&&n>=0&&this.lengthAt(t)>0&&(this.layout.format===1||this.memberBytesAt(t)>=X)}written(){return this.bytes.subarray(0,this.size*this.rowBytes)}},$=class{constructor(t,e){this.rows=t;let n=1024;for(;n<e*2;)n*=2;this.slots=new Uint32Array(n)}rows;slots;used=0;find(t){let e=this.slots.length-1;for(let n=g(t)&e;;n=n+1&e){let r=this.slots[n];if(r===0)return-1;if(this.rows.holds(r-1,t))return r-1}}add(t){let e=this.rows.keyAt(t),n=this.find(e);return n>=0?n:((this.used+1)*2>this.slots.length&&this.grow(),this.place(t,e),this.used++,-1)}place(t,e){let n=this.slots.length-1,r=g(e)&n;for(;this.slots[r]!==0;)r=r+1&n;this.slots[r]=t+1}grow(){let t=this.slots;this.slots=new Uint32Array(t.length*2);for(let e of t)e!==0&&this.place(e-1,this.rows.keyAt(e-1))}};async function U(s,t){try{return await C(s,"r")}catch(e){throw e.code!=="ENOENT"?e:new k("damaged",`The checkpoint\u2019s snapshot of ${t} is not on this machine.`)}}async function*Pt(s,t){let e=await U(s,t);try{let n=Buffer.alloc(Rt),r=Buffer.alloc(0),i=0,o=0,a=0;for(;;){let{bytesRead:d}=await e.read(n,0,Rt,o);if(d===0)break;o+=d;let u=r.length>0?Buffer.concat([r,n.subarray(0,d)]):n.subarray(0,d),h=0;for(let c=u.indexOf(10);c>=0;c=u.indexOf(10,h))a++,c>h&&(yield{number:a,offset:i+h,length:c-h,text:u.toString("utf8",h,c)}),h=c+1;r=Buffer.from(u.subarray(h)),i+=h}r.length>0&&(yield{number:a+1,offset:i,length:r.length,text:r.toString("utf8")})}finally{await e.close()}}async function*Re(s,t,e){let n=await U(s,t);try{let r=0;for await(let i of gt(n,(await n.stat()).size,e))for(let o of mt(i.lines))r++,o.length!==0&&(yield{number:r,offset:i.at,memberBytes:i.total,line:o.at,length:o.length,text:i.lines.toString("utf8",o.at,o.at+o.length)})}finally{await n.close()}}async function Ie(s){try{return await Ae(s),!0}catch(t){if(t.code==="ENOENT")return!1;throw t}}function zt(s){let t=at(s);return t===null?Number.NaN:Date.parse(t)}function _(s){let t;try{t=JSON.parse(s)}catch{return}return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:void 0}async function ve(s,t){let e=`${s}.${process.pid}-${Se(4).toString("hex")}.tmp`,n=await C(e,"wx",I);try{try{await n.writeFile(t),await n.sync()}finally{await n.close()}await xe(e,s)}catch(r){throw await ke(e,{force:!0}),r}}async function en(s,t,e){let n=Ct(s,t,e),r=B(n),i=await Ie(r)?2:1,o=H(s,e),a=new D(Lt[i]),d=new $(a,0),u=(f,l)=>new k("damaged",`The snapshot of ${e} holds ${l} at line ${f} of its file: it cannot be indexed.`),h=i===2?Re(r,e,f=>new k("damaged",`The snapshot of ${e} ${f}: it cannot be indexed.`)):Pt(n,e);for await(let f of h){let l=_(f.text);if(!l)throw u(f.number,"no record");let p=l.Id;if(typeof p!="string"||!R.test(p))throw u(f.number,"a record without its Id");let m=zt(l.SystemModstamp);if(!Number.isFinite(m))throw u(f.number,`record ${p} without its SystemModstamp`);let Dt=a.push(p.slice(0,b),m,f);if(d.add(Dt)>=0)throw u(f.number,`record ${p} a second time`)}let c=Buffer.concat([a.layout.head,a.written()]);return await ve(o,c),{rows:a.size,bytes:c.length}}var Ne=j({objectApiName:N().regex(ot).max(80),from:N().regex(R),to:N().regex(R)});async function _t(s){let t;try{t=await C(s,"r"),await t.sync()}catch{}finally{await t?.close().catch(()=>{})}}var rt=class s{constructor(t,e){this.current=t;this.original=e}current;original;static none=new s(new Map,new Map);static of(t){let e=new Map;for(let{from:r,to:i}of t)e.set(r.slice(0,b),i);let n=new Map;for(let[r,i]of e)n.set(i.slice(0,b),r);return new s(e,n)}static async read(t){let e;try{e=await it(W(t),"utf8")}catch(i){if(i.code==="ENOENT")return s.none;throw i}let n=e.split(`
10
+ `).slice(0,-1),r=[];for(let[i,o]of n.entries()){if(o==="")continue;let a;try{a=JSON.parse(o)}catch{a=void 0}let d=Ne.safeParse(a);if(!d.success)throw new k("damaged",`The checkpoint\u2019s list of the records a rewind made again is damaged at line ${i+1}.`);r.push(d.data)}return s.of(r)}static async add(t,e){if(e.length===0)return;let n=W(t),r=e.map(({objectApiName:a,from:d,to:u})=>`${JSON.stringify({objectApiName:a,from:d,to:u})}
11
+ `).join(""),i=await C(n,"a",I),o=!1;try{o=(await i.stat()).size===0,await i.appendFile(r,"utf8"),await i.sync()}finally{await i.close()}o&&await _t(Ft(n))}get empty(){return this.current.size===0}currentOf(t){return this.current.get(t)}originalOf(t){return this.original.get(t)}retired(t){return typeof t=="string"&&R.test(t)&&this.current.has(t.slice(0,b))}remapped(t){return typeof t!="string"||!R.test(t)?t:this.current.get(t.slice(0,b))??t}rowAsNow(t){if(this.empty)return t;let e={...t};for(let[n,r]of Object.entries(t)){if(n==="attributes")continue;let i=this.remapped(r);i!==r&&(e[n]=i)}return e}},Te=j({objectApiName:N().regex(ot).max(80),id:N().regex(R)}),vt=class s{constructor(t){this.held=t}held;static none=new s(new Set);static async read(t){let e;try{e=await it(K(t),"utf8")}catch(r){if(r.code==="ENOENT")return s.none;throw r}let n=new Set;for(let r of e.split(`
12
+ `)){if(r==="")continue;let i;try{i=JSON.parse(r)}catch{continue}let o=Te.safeParse(i);o.success&&n.add(o.data.id.slice(0,b))}return new s(n)}static async add(t,e,n){if(n.length===0)return;let r=K(t),i=n.map(d=>`${JSON.stringify({objectApiName:e,id:d})}
13
+ `).join(""),o=await C(r,"a",I),a=!1;try{a=(await o.stat()).size===0,await o.appendFile(i,"utf8"),await o.sync()}finally{await o.close()}a&&await _t(Ft(r))}has(t){return this.held.has(t.slice(0,b))}keys(){return this.held.values()}},Nt=class s{constructor(t,e,n,r,i,o,a){this.objectApiName=t;this.snapshotId=e;this.snapshotFile=n;this.rows=r;this.byKey=i;this.recreated=o;this.extent=a}objectApiName;snapshotId;snapshotFile;rows;byKey;recreated;extent;static async read(t,e,n,r){let i=H(t,n),o=p=>new k("damaged",`The checkpoint\u2019s index of ${n} ${p}.`),a;try{a=await it(i)}catch(p){throw p.code==="ENOENT"?o("is not on this machine"):p}let d=[st,Mt].find(({head:p})=>a.length>=L&&a.subarray(0,L).equals(p));if(d===void 0||(a.length-L)%d.rowBytes!==0)throw o("is not an index of its snapshot");let u=Ct(t,e,n),h=d.format===2?B(u):u,c=new D(d,a.subarray(L)),f=new $(c,c.size),l=0;for(let p=0;p<c.size;p++){if(!c.wellFormed(p))throw o(`is damaged at row ${p+1}`);if(f.add(p)>=0)throw o(`holds record ${c.keyAt(p)} twice`);d.format===2&&(l=Math.max(l,c.offsetAt(p)+c.memberBytesAt(p)))}return new s(n,e,h,c,f,r??await rt.read(t),l)}get format(){return this.rows.layout.format}get size(){return this.rows.size}rowOf(t){if(typeof t!="string"||!R.test(t))return-1;let e=t.slice(0,b),n=this.recreated.originalOf(e);return n!==void 0?this.byKey.find(n):this.recreated.retired(t)?-1:this.byKey.find(e)}retired(t){return this.recreated.retired(t)&&this.byKey.find(String(t).slice(0,b))>=0}snapshotIdOf(t){let e=this.rowOf(t);if(e<0)return t;let n=this.rows.keyAt(e);return J(n)??n}has(t){return this.rowOf(t)>=0}stampOf(t){let e=this.rowOf(t);return e<0?void 0:this.rows.stampAt(e)}idAt(t){let e=this.rows.keyAt(t);return this.recreated.currentOf(e)??J(e)??e}chunk(t){if(t.length>Et)throw new RangeError(`A chunk of the snapshot reads ${Et} records at most; ${t.length} were asked.`);let e=new Set;for(let r of t){let i=this.rowOf(r);i>=0&&e.add(i)}let n=[...e].sort((r,i)=>this.rows.before(r,i));return{batches:async(r,i,o)=>{if(r!==this.snapshotId||i!==this.objectApiName)return null;let a=o>=1?Math.floor(o):1;return{[Symbol.asyncIterator]:()=>this.rowsAt(n,a)}}}}async*records(){if(this.size===0)return;if(this.format===2){let e=function*(n){for(let r=0;r<n;r++)yield r};for await(let n of this.compressedRowsAt(e(this.size),Oe))yield*n;return}let t=0;for await(let e of Pt(this.snapshotFile,this.objectApiName)){let n=_(e.text);if(t>=this.size)throw this.moreThanIndexed();if(!n||!this.isRowOf(t,n))throw this.notWhereIndexed(t);yield this.recreated.rowAsNow(n),t++}if(t<this.size)throw this.notWhereIndexed(t)}notWhereIndexed(t){return new k("damaged",`The checkpoint\u2019s snapshot of ${this.objectApiName} does not hold record ${this.idAt(t)} where its index says: the file changed since the checkpoint was taken.`)}moreThanIndexed(){return new k("damaged",`The checkpoint\u2019s snapshot of ${this.objectApiName} holds more records than its index: the file changed since the checkpoint was taken.`)}async*rowsAt(t,e){if(t.length===0)return;if(this.format===2){yield*this.compressedRowsAt(t,e);return}let n=await U(this.snapshotFile,this.objectApiName);try{let r=Buffer.alloc(0),i=[];for(let o of t){let a=this.rows.lengthAt(o),d=this.rows.offsetAt(o);r.length<a&&(r=Buffer.alloc(Math.max(a,r.length*2)));let u=0;for(;u<a;){let{bytesRead:c}=await n.read(r,u,a-u,d+u);if(c===0)break;u+=c}let h=u===a?_(r.toString("utf8",0,a)):void 0;if(!h||!this.isRowOf(o,h))throw this.notWhereIndexed(o);i.push(this.recreated.rowAsNow(h)),i.length===e&&(yield i,i=[])}i.length>0&&(yield i)}finally{await n.close()}}async*compressedRowsAt(t,e){let n=i=>new k("damaged",`The checkpoint\u2019s snapshot of ${this.objectApiName} ${i}: the file changed since the checkpoint was taken.`),r=await U(this.snapshotFile,this.objectApiName);try{let i=(await r.stat()).size;if(i!==this.extent)throw n(`takes ${i} bytes where its index says ${this.extent}`);let o=-1,a=0,d=Buffer.alloc(0),u=[];for(let h of t){let c=this.rows.offsetAt(h);(c!==o||this.rows.memberBytesAt(h)!==a)&&(a=this.rows.memberBytesAt(h),d=await pt(r,c,a,n),o=c);let f=this.rows.lineAt(h),l=f+this.rows.lengthAt(h),m=l<=d.length&&(f===0||d[f-1]===10)&&(l===d.length||d[l]===10)?_(d.toString("utf8",f,l)):void 0;if(!m||!this.isRowOf(h,m))throw this.notWhereIndexed(h);u.push(this.recreated.rowAsNow(m)),u.length===e&&(yield u,u=[])}u.length>0&&(yield u)}finally{await r.close()}}isRowOf(t,e){let n=e.Id;return typeof n=="string"&&R.test(n)&&this.rows.holds(t,n.slice(0,b))&&zt(e.SystemModstamp)===this.rows.stampAt(t)}},Tt=class{constructor(t){this.index=t;this.marked=new Uint8Array(Math.ceil(t.size/8))}index;marked;found=0;mark(t){let e=this.index.rowOf(t);if(e<0)return!1;let n=1<<(e&7),r=e>>>3;return(this.marked[r]&n)===0&&(this.marked[r]|=n,this.found++),!0}get count(){return this.index.size-this.found}*ids(){for(let t=0;t<this.index.size;t++)(this.marked[t>>>3]&1<<(t&7))===0&&(yield this.index.idAt(t))}};export{_e as a,Ue as b,yt as c,ce as d,de as e,fe as f,Ot as g,Q as h,P as i,kt as j,ue as k,je as l,Je as m,he as n,g as o,y as p,v as q,be as r,Bt as s,Et as t,tn as u,Ct as v,en as w,rt as x,vt as y,Nt as z,Tt as A};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a as c}from"./chunk-DBFJB2B6.mjs";var u=new Set(["string","textarea","email","phone","url","encryptedstring","picklist","multipicklist","combobox","date","datetime","int","long","double","currency","percent"]),f=new Set(["string","textarea","email","phone","url","encryptedstring"]),p=["FirstName","MiddleName","LastName"];function k(e){return e==null?!1:typeof e!="string"||e.trim()!==""}function l(e){return u.has(e.type)}function m(e){return f.has(e.type)}var b={name_pattern:"name",type_analysis:"type",content_pattern:"content"};function D(e){return{apiName:e.name,label:e.label,type:e.type}}function F(e){return e.createable===!0||e.updateable===!0}function h(e,n){let i=e.filter(F).map(r=>r.name);return n.map(r=>{let d={};for(let a of i)d[a]=r[a];return d})}function _(e,n,i,r){let d=i.filter(l),a=new Map(d.map(t=>[t.name,t]));return e.detectPII(n,d.map(D),r&&r.length>0?h(d,r):void 0).piiFields.flatMap(t=>{let o=a.get(t.fieldApiName);return o?[{field:o,classification:t.classification,detectedBy:b[t.detectionMethod],pattern:t.pattern??t.detectionMethod}]:[]})}function y(e){if(e.filterable===!0){if(e.type==="email")return"email";if(e.type==="phone")return"phone";if(e.type==="string"){if(/email(?:__c)?$/i.test(e.name))return"email";if(/phone(?:__c)?$/i.test(e.name))return"phone"}}}function P(e){return e.fields.find(n=>n.nameField===!0&&n.filterable===!0&&n.autoNumber!==!0&&(n.type==="string"||n.type==="textarea"))}function M(e){let n=[];for(let r of e.fields){let d=y(r);d&&n.push({field:r,kind:d})}let i=P(e);return i&&n.push({field:i,kind:"name"}),n}function E(e){let n=e.fields.find(i=>i.nameField===!0&&i.autoNumber!==!0);return n&&n.updateable===!0&&m(n)?[n]:e.fields.filter(i=>p.includes(i.name))}function g(e){return c[e.name]!==void 0?"fake":e.nillable===!0?"nullify":"fake"}var x=new Set(["email_content","ssn_content"]);function N(e,n){let i=new Set,r=[],d=n.filter(t=>t.detectedBy!=="content"||x.has(t.pattern));for(let t of[...d.map(o=>o.field),...E(e)])i.has(t.name)||!l(t)||t.calculated===!0||t.autoNumber===!0||(i.add(t.name),r.push(t));let a=[],s=[];for(let t of r)t.updateable===!0?a.push({field:t,method:g(t)}):s.push(t);return{fields:a,kept:s}}export{k as a,l as b,m as c,F as d,_ as e,y as f,P as g,M as h,g as i,N as j};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a as Fe}from"./chunk-GMY5427L.mjs";import{h as we,i as Oe,j as be,k as Se,n as ke,o as Te}from"./chunk-XETCPL7E.mjs";import{c as Re}from"./chunk-K2FBZIXY.mjs";import{f as he,i as me}from"./chunk-3F5YMM2F.mjs";import{a as z,k as ie,n as ae,p as de,s as ce,t as ue,u as le}from"./chunk-ZUTYVST5.mjs";import{b as ye,e as ge}from"./chunk-55HEMHEG.mjs";import{b as fe,c as q,m as pe}from"./chunk-WIO4XO4F.mjs";import{d as K}from"./chunk-GCOB7K5N.mjs";import{F as se,p as te,r as ne,s as re,t as oe}from"./chunk-CGWXQX75.mjs";import{b as ee}from"./chunk-CA5NAXSU.mjs";import{Rb as X,fc as B}from"./chunk-B45CNPUX.mjs";var H=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function R(t){return t.slice(0,15)}var Ce=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(R(e),n)}contactSentWith(e){return this.contactsSentWith.get(R(e))}roleLinkedFor(e){this.contactsSentWith.delete(R(e))}get sentWithAContact(){return this.contactsSentWith.size>0}noteOwnerRefused(e){this.ownersRefused.add(R(e))}isOwnerRefused(e){return this.ownersRefused.has(R(e))}noteDeleted(e){for(let n of e)this.deleted.add(R(n))}standing(e){return e!==void 0&&this.deleted.has(R(e))?void 0:e}noteMatched(e,n){this.noteWritten(e,n)}noteWritten(e,n){this.written.set(R(e),n),this.refused.delete(R(e))}noteRefused(e,n){this.written.has(R(e))||this.refused.set(R(e),n)}targetOf(e){return this.standing(this.written.get(R(e)))??this.standing(this.earlier.get(R(e)))}refusedObjectOf(e){if(this.standing(this.earlier.get(R(e)))===void 0)return this.refused.get(R(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=be(Oe(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 Me(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 Le(t,e){return`${t} ${e} record${t===1?"":"s"}`}function ze(t,e,n){let r=a=>e.find(i=>R(i.recordTypeId)===R(a)),s=t;if(!r(t)&&n){let a=n.mappings.find(i=>R(i.sourceId)===R(t));if(!a){let i=n.source.find(c=>R(c.id)===R(t)),p=i?(n.target??[]).filter(c=>c.sobjectType===i.sobjectType&&c.developerName===i.developerName):[];return{unmapped:i?K(i):"",namesakes:p.map(K)}}s=a.targetId}let o=q(e.filter(a=>R(a.recordTypeId)===R(s)),n?.target??[])[0];return o&&!o.available&&!o.master?{unavailable:o}:o?{sent:s,info:o}:{sent:s}}function Ue(t,e,n){if(t?.personAccounts===!1)return!0;if(!n)return!1;let r=e??ke(t?.recordTypes);return r!==void 0&&!n.has(R(r))}function We(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: ${Le(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 ve(t){let{config:e,records:n,target:r,run:s}=t,o=e.objectApiName,a=Y(e),i=r?.recordTypes??[],p=r?.references??new Set,c={payloads:[],sentAt:[],settled:[],held:[],deferred:[],deferredAcross:[],notes:[],currencies:[],withoutRecordType:new Map},g=new Map,h=new Map,F=(d,l,y,k)=>{c.held.push({index:d,reason:y}),g.delete(d);let L=h.get(l);L?L.count++:h.set(l,{count:1,say:k})},O=e.operation==="insert"||e.operation==="upsert",T=O&&i.some(d=>!d.master),b=new Map;s&&O&&s.sources.forEach((d,l)=>{let y=d?.Id;typeof y=="string"&&H.test(y)&&b.set(R(y),l)});let v=new Set([...s&&O?s.later??[]:[]].map(d=>d.toLowerCase())),m=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 y=Me(d,e.fieldMappings,e.addOnFields,r?.creatable??null,a);if(e.operation==="delete"){g.set(l,{payload:y,settled:new Set});return}let k=new Set;if(s)for(let f of Object.keys(y)){let W=y[f];if(f==="RecordTypeId"||!p.has(f)||typeof W!="string"||!H.test(W))continue;if(b.has(R(W))){delete y[f],c.deferred.push({index:l,field:f,parent:W});continue}let _=s.links.targetOf(W);if(_){y[f]=_,k.add(f);continue}let M=s.links.refusedObjectOf(W);if(M===void 0){m.has(f)&&(delete y[f],c.deferredAcross.push({index:l,field:f,parent:W}));continue}let G=We(o,f,M);F(l,G.group,G.reason,G.say);return}let L=y.RecordTypeId,E,j=Re(L);if(j)delete y.RecordTypeId;else if(typeof L=="string"&&H.test(L)){let f=ze(L,i,s?.recordTypes);if("unmapped"in f){let W=f.unmapped,_=f.namesakes.length>0?` The target org's ${f.namesakes.join(" and ")} carries its DeveloperName under another namespace, and a record type is mapped to one of the same namespace only.`:"";F(l,`unmapped:${W}`,"RECORD_TYPE_UNMAPPED: its record type has no counterpart in the target org.",M=>`RECORD_TYPE_UNMAPPED: ${Le(M,o)} held back, not sent: `+(W?`their record type ${W} has no active ${o} record type of that API name in the target org.${_} Create or activate record type ${W} 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 f){let W=f.unavailable;F(l,`unavailable:${W.recordTypeId}`,`RECORD_TYPE_UNAVAILABLE: record type ${W.developerName} is closed to the running user in the target org.`,_=>`${pe({objectApiName:o,recordTypeId:W.recordTypeId,developerName:W.developerName,name:W.name,inactive:!W.active,recordCount:_})} Held back, not sent.`);return}y.RecordTypeId=f.sent,E=f.sent,f.info&&k.add("RecordTypeId")}let $=s?.sources[l]??d;if(re($)){let f=oe($,Ue(r,E,s?.recordTypes?.personTypes));for(let W of Object.keys(y))B(o,W,f)&&delete y[W]}else for(let f of Object.keys(y))B(o,f,"business")&&delete y[f];T&&!("RecordTypeId"in y)&&c.withoutRecordType.set(l,j?"masterInSource":"notRead"),g.set(l,{payload:y,settled:k})});let A=!0;for(;A;){A=!1;for(let{index:d,field:l,parent:y}of c.deferred){let k=b.get(R(y));if(!g.has(d)||k===void 0||g.has(k)||s?.links.targetOf(y)!==void 0)continue;let L=We(o,l,o);F(d,L.group,L.reason,L.say),A=!0}}c.deferred=c.deferred.filter(({index:d})=>g.has(d)),c.deferredAcross=c.deferredAcross.filter(({index:d})=>g.has(d));for(let d of[...c.withoutRecordType.keys()])g.has(d)||c.withoutRecordType.delete(d);c.held.sort((d,l)=>d.index-l.index);let S=e.operation==="delete"?void 0:s?.currencies,w=r?.creatable.has(z)===!0,u=!w&&(s?.currencyChangesById?.size??0)>0&&r?.fields?.some(d=>d.name===z)===!0,C=S&&(w||u)?ae(r?.fields??[]):void 0,P=[...r?.references??[]],I=new le;for(let[d,{payload:l,settled:y}]of[...g].sort(([k],[L])=>k-L)){for(let k of X(o,l))delete l[k];if(S&&C){let k=s?.sources[d]??n[d],L=k?.[z],E=w?de(l,{read:L,currencyFields:C,ratesOn:ie(o,k)},S):ue(l,{read:L,parent:k?ce(o,k,P,$=>s?.currencyChangesById?.get($)):void 0,currencyFields:C},S);I.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(y)}return c.notes=[...h.values()].map(({count:d,say:l})=>l(d)),c.currencies=I.list(),c}function V(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:void 0}function Ge(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 pt(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(Ge),...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 yt(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 gt(t,e){if(t.operation==="delete"||t.query===void 0)return t;let n=Fe(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 Ee(t,e,n,r){let s;try{s=await t(e)}catch(c){if(n==="delete")return{notAsked:!0};let g=Te(c)?"notInTarget":"unread";return{refused:{why:g,message:Z(e,g,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 p=r?.trim()||"Id";return n==="upsert"&&s.upsertKeys&&!s.upsertKeys.has(p.toLowerCase())?{refused:{why:"notAKey",message:Z(e,"notAKey",p),key:p},target:s}:{target:s}}function wt(t){return t.keepContactPoints===!0?void 0:new we}function Rt(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 Pe(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 xe=class{deps;constructor(e){this.deps=e}async sync(e,n,r){let{outcomes:s,notes:o,currencies:a,lookupsLeftOut:i,writtenWithoutFields:p}=await this.write(e,n,r);return Ze(Je(e.objectApiName,e.operation,s,o,i,p),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 Ee(this.deps.describeTargetFields,e.objectApiName,e.operation,e.externalIdField);if("refused"in u){let C=n.map(()=>({success:!1,errors:[u.refused.message]}));return r&&De(e,C,r),{outcomes:C,notes:[],currencies:[],lookupsLeftOut:[]}}"target"in u&&u.target.creatable.size>0&&(s=u.target)}let o=ve({config:e,records:n,target:s,run:r}),a=r?r.contactPoints:this.deps.contactPoints;a&&s?.fields&&Pe(a,e.objectApiName,s.fields,o.payloads,e.externalIdField);let i=qe(o.payloads,o.settled,r),p=new Map(o.held.map(({index:u,reason:C})=>[u,C])),c=u=>{let C=[],P=0;for(let I=0;I<n.length;I++){let d=p.get(I);if(d!==void 0){C.push({success:!1,errors:[d],heldBack:!0});continue}if(P>=u.length)break;C.push(u[P++])}return C},g,h=o.sentAt.filter(u=>u<(r?.standardFirst??0)).length,F=u=>this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField);try{g=o.payloads.length===0&&n.length>0?[]:h>0&&h<o.payloads.length?await Ye(e.objectApiName,F,o.payloads.slice(0,h),o.payloads.slice(h)):await F(o.payloads)}catch(u){if(!(u instanceof x))throw u;let C=Ne(i,u.written),P=c(u.written);throw je(e,o.withoutRecordType,P,s,r),new x(e.objectApiName,P,[...o.notes,...u.notes],[...C?[C]:[],...u.lookupsLeftOut,...Q(U([...o.deferred,...o.deferredAcross],P))],u.writtenWithoutFields)}let O=await this.retryRefused(e,o.payloads,g,s?.references??null,o.settled);if(r)for(let u of O.ownersRefused)r.links.noteOwnerRefused(u);let T=c(O.outcomes);je(e,o.withoutRecordType,T,s,r);let b=Ne(i,O.outcomes),v=[...o.notes,...O.notes],m=[...b?[b]:[],...O.lookupsLeftOut],{writtenWithoutFields:A}=O,S=U(o.deferredAcross,T),w=0;if(O.cancelled)throw new x(e.objectApiName,T,v,[...m,...Q([...U(o.deferred,T),...S])],A);if(r){De(e,T,r),Ve(e,o.payloads,O.outcomes,r.links);let u=await this.setLookups(e,U(o.deferred,T),r.links,!1);if(m.push(...u.leftOut),w=u.unset,u.cancelled)throw new x(e.objectApiName,T,v,[...m,...Q(S)],A)}return{outcomes:T,notes:v,currencies:o.currencies,lookupsLeftOut:m,...A?{writtenWithoutFields:A}:{},...S.length>0?{lookupsToSet:S}:{},...w>0?{lookupsUnset:w}:{}}}async setLookups(e,n,r,s){let o=e.objectApiName,a=new Map,i=new Map,p=new D;for(let{id:b,field:v,parent:m}of n){let A=r.targetOf(m),S=A!==void 0?a:s&&r.refusedObjectOf(m)===void 0?i:void 0;if(!S){p.add(b,v);continue}let w=S.get(b)??{Id:b};w[v]=A??m,S.set(b,w)}let c=new D,g=new D,h=new D,F=new D,O=!1;for(let b of[[...a.values()],[...i.values()]]){if(b.length===0)continue;if(O){for(let m of b)F.addRow(m);continue}let v;try{v=await this.executeOperation(o,"update",b,e.batchSize)}catch(m){if(!(m instanceof x)){let A=m instanceof Error?m.message:String(m);for(let S of b)h.addRow(S,A);continue}v=m.written,O=!0}b.forEach((m,A)=>{let S=v[A];S===void 0?F.addRow(m):S.success?c.addRow(m):S.errors.some(w=>J(w))?g.addRow(m):h.addRow(m,S.errors[0])})}let T=[p,g,h,F];return{...c.records>0?{set:{records:c.records,fields:c.fields()}}:{},leftOut:[p.leftOut("parentRefused"),g.leftOut("notInTarget"),h.leftOut("notSet"),F.leftOut("notReached")].flatMap(b=>b?[b]:[]),unset:new Set(T.flatMap(b=>[...b.recordIds])).size,cancelled:O}}async retryRefused(e,n,r,s,o){let a=Y(e)??void 0,i=[...r],p=[...n],c=n.map(()=>new Set),g=n.map(()=>[]),h=n.map(()=>[]),F=[],O,T=new Set;for(let S=0;S<2&&!O;S++){let w=[],u=[],C=[];if(i.forEach((I,d)=>{if(I.success)return;let l=p[d],y=o[d]??new Set;if(I.errors.some(E=>J(E))){let E=n[d]?.[N];if(typeof E=="string"&&!y.has(N)&&(I.errorDetails??[]).some(f=>J(f.statusCode)&&f.fields.includes(N))&&T.add(E),c[d].has("lookup")||!s||s.size===0)return;let j={},$=!1;for(let f of Object.keys(l)){if(s.has(f)&&!y.has(f)&&l[f]!==null&&l[f]!==void 0){$=!0;continue}j[f]=l[f]}if(!$)return;w.push(d),u.push(j),C.push(null);return}if(c[d].has("fields"))return;let k=he(I.errorDetails,l,a);if(!k||k.some(({field:E})=>y.has(E)))return;let L=new Set(k.map(({field:E})=>E));w.push(d),u.push(Object.fromEntries(Object.entries(l).filter(([E])=>!L.has(E)))),C.push(k)}),w.length===0)break;let P;try{P=await this.executeOperation(e.objectApiName,e.operation,u,e.batchSize,e.externalIdField)}catch(I){if(!(I instanceof x)){F.push(...He(w,p,u,C,I));break}P=I.written,O=I}P.forEach((I,d)=>{let l=w[d],y=C[d];c[l].add(y===null?"lookup":"fields"),y===null?g[l].push(...Object.keys(p[l]).filter(k=>!(k in u[d]))):h[l].push(...y),p[l]=u[d],i[l]=I})}let b=new Set,v=0,m,A=new Set(T);return i.forEach((S,w)=>{if(!(!S.success||c[w].size===0)){if(g[w].length>0){v++;for(let C of g[w])b.add(C);let u=n[w]?.[N];typeof u=="string"&&g[w].length===1&&g[w][0]===N&&A.add(u)}h[w].length>0&&(m=me(m,{rows:1,fields:h[w].map(u=>({...u,rows:1}))}))}}),{outcomes:i,notes:[...F,...O?.notes??[]],...m?{writtenWithoutFields:m}:{},cancelled:O!==void 0,ownersRefused:[...A],lookupsLeftOut:[...v>0?[{records:v,fields:[...b].sort(),reason:"notInTarget"}]:[],...O?.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)}}}},Be=["INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","INVALID_CROSS_REFERENCE_KEY"],Ke=/cross[- ]reference id|r[ée]f[ée]rence crois[ée]e/i;function J(t){return Be.some(e=>t.includes(e))||Ke.test(t)}var N="OwnerId";function qe(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 Ne(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 He(t,e,n,r,s){let o=s instanceof Error?s.message:String(s),a=new Set,i=new Set,p=0;return r.forEach((c,g)=>{if(c===null){p++;let h=n[g];for(let F of Object.keys(e[t[g]]))F in h||a.add(F)}else for(let{field:h}of c)i.add(h)}),[...p>0?[`${p} 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-p} 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 It(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 _e(t,e){if(!(e.success||t!=="insert"&&t!=="upsert"))return e.existingId!==void 0&&e.existingId!==""?e.existingId:void 0}async function Ye(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 je(t,e,n,r,s){if(!s?.createdWithoutRecordType||e.size===0)return;let o=[],a=[];for(let[c,g]of e){let h=n[c];!h?.success||typeof h.id!="string"||h.id===""||t.operation!=="insert"&&h.created!==!0||(o.push(g),a.length<Se&&a.push(h.id))}let i=Ie(s.recordTypesUnderTheLease??r?.recordTypes??[],s.recordTypes),p=Ae(t.objectApiName,o,i);p&&s.createdWithoutRecordType.set(t.objectApiName,{given:p,types:i,ids:a})}function Ve(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 De(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=_e(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 Ze(t,e){return e.length>0?{...t,currenciesReplaced:[...e]}:t}var $e=1e3;function Je(t,e,n,r=[],s=[],o){let a=0,i=0,p=0,c,g=[],h=0,F={created:0,updated:0};for(let T of n)T.success?(a++,T.created===!0?F.created++:T.created===!1&&F.updated++):_e(e,T)!==void 0?(p++,c??=T.errors[0]):(i++,!T.heldBack&&h++<$e&&g.push(...T.errors));let O=Math.max(0,h-$e);return{objectApiName:t,operation:e,processed:n.length,success:a,failed:i,skipped:p,conflictCount:0,errors:[...g,...r],...p>0?{linkedToExisting:{records:p,...c?{refusal:c}:{}}}:{},...s.length>0?{lookupsLeftOut:[...s]}:{},...o?{writtenWithoutFields:o}:{},...O>0?{refusalsDropped:O}:{},...e==="upsert"?{upsertSplit:F}:{}}}export{Ce as a,Ae as b,Ie as c,ve as d,pt as e,yt as f,gt as g,Ee as h,wt as i,Rt as j,Pe as k,x as l,xe as m,It as n,Q as o,_e as p,Ze as q,$e as r,Je as s};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r}from"./chunk-FQBRBBY4.mjs";import"./chunk-F74IHMGL.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-Y5CGXLUB.mjs";import"./chunk-3F5YMM2F.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-SAR5622P.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-ZLZRU6MO.mjs";import"./chunk-WIO4XO4F.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-GCOB7K5N.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-PNCONNFJ.mjs";import"./chunk-CGWXQX75.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-SIOZXPFG.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-B45CNPUX.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-NTOVCTRS.mjs";export{h as ACTIVE_DUPLICATE_RULES_SOQL,a as FORMULAS_BOUND,c as FORMULAS_IN_COMPOSITES_BOUND,b as FORMULA_REQUESTS_BOUND,o as TargetGapReader,i as bypassesOf,j as callsEstimateOf,f as fieldLabelsSoql,p as gapAnsweredBy,d as gapFieldOf,r as gapLines,q as gapsWithAnswers,l as readActiveValidationRules,m as readValidationRuleBypasses,k as toolingQueriesOver,n as toolingValidationRules,g as validationFormulaSoql,e as validationRulesSoql};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s}from"./chunk-ENLBYECD.mjs";import"./chunk-PA3MKJVH.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-B45CNPUX.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-NTOVCTRS.mjs";export{r as BEFORE_RUN_DELETED_WORDS,e as BEFORE_RUN_DISK_ROOM,a as WRITE_PATH_STEPS,j as beforeRunAskedOf,f as beforeRunDiskRefusal,d as beforeRunEstimateOf,q as beforeRunFailedWords,i as beforeRunKeepDaysOf,h as beforeRunNameOf,l as beforeRunOutcomeOf,s as beforeRunProgressWords,p as beforeRunRefusedWords,c as beforeRunScopeOf,k as beforeRunTakenOf,g as freeBytesOf,m as scopeBeforeRun,o as settleBeforeRun,n as takeBeforeRun,b as writePathOrderDefects};
@@ -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}from"./chunk-5HMAPZBV.mjs";import"./chunk-B45CNPUX.mjs";import"./chunk-7EANH5PY.mjs";import"./chunk-NTOVCTRS.mjs";export{a as describedFieldsOf,b as requiredForAccountKinds};
@@ -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
+ var i=class{runs=new Map;async during(n,e){if(n===void 0)return e();this.runs.set(n,(this.runs.get(n)??0)+1);try{return await e()}finally{let t=(this.runs.get(n)??1)-1;t>0?this.runs.set(n,t):this.runs.delete(n)}}has(n){return this.runs.has(n)}};function r(s,n){let e="payload"in s?s.payload:void 0;if(typeof e!="object"||e===null)return;let t=e[n];return typeof t=="string"&&t!==""?t:void 0}export{i as a,r as b};