sandforge 1.82.0 → 1.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{chunk-JLZRZL5E.mjs → chunk-262TP6UU.mjs} +1 -1
- package/lib/{chunk-Z42PHCVZ.mjs → chunk-27BBEGUD.mjs} +1 -1
- package/lib/{chunk-YGJF55VJ.mjs → chunk-2ADSD5WK.mjs} +1 -1
- package/lib/{chunk-KIMQQ6JQ.mjs → chunk-2GSMHGIV.mjs} +1 -1
- package/lib/chunk-2K5BYZQM.mjs +8 -0
- package/lib/{chunk-DJCGURW7.mjs → chunk-2KTGDYUH.mjs} +1 -1
- package/lib/{chunk-YAJQS3OL.mjs → chunk-2N73W63D.mjs} +1 -1
- package/lib/{chunk-LXDSRP2W.mjs → chunk-2R6GFNKF.mjs} +1 -1
- package/lib/{chunk-VZVICK7Q.mjs → chunk-2WMKJVD2.mjs} +1 -1
- package/lib/{chunk-CV47FDQW.mjs → chunk-36Y225OM.mjs} +1 -1
- package/lib/{chunk-3C2ZZIFN.mjs → chunk-3CM7LAPE.mjs} +1 -1
- package/lib/{chunk-HIHCYMSL.mjs → chunk-3OVTKRS4.mjs} +1 -1
- package/lib/{chunk-XFU3HRUV.mjs → chunk-3V4YH5KO.mjs} +1 -1
- package/lib/{chunk-XO5FBOQF.mjs → chunk-446GBKAC.mjs} +1 -1
- package/lib/{chunk-ZUOPC4W2.mjs → chunk-4GCYGQXD.mjs} +1 -1
- package/lib/{chunk-GCGHHN4K.mjs → chunk-4V3QO7HF.mjs} +1 -1
- package/lib/{chunk-VZT4E2OJ.mjs → chunk-4X5D3MSV.mjs} +1 -1
- package/lib/{chunk-P55MKIZX.mjs → chunk-5OGNK3JP.mjs} +1 -1
- package/lib/{chunk-3MGMNK3Q.mjs → chunk-6KOUYHEY.mjs} +1 -1
- package/lib/chunk-6QSHWIZI.mjs +48 -0
- package/lib/chunk-6VOQFISN.mjs +7 -0
- package/lib/{chunk-VYOYXTCU.mjs → chunk-6YC2ELCU.mjs} +1 -1
- package/lib/chunk-77IVKH7R.mjs +7 -0
- package/lib/{chunk-JKT5YAQ2.mjs → chunk-77MZRBWX.mjs} +1 -1
- package/lib/{chunk-PR74GYVI.mjs → chunk-7BQMBXKX.mjs} +1 -1
- package/lib/{chunk-SZGGFST2.mjs → chunk-7DPHZWA4.mjs} +1 -1
- package/lib/chunk-7V2UYZ6S.mjs +7 -0
- package/lib/{chunk-HKUWHVI7.mjs → chunk-7WSQ65WG.mjs} +1 -1
- package/lib/{chunk-LHU6CPGE.mjs → chunk-7ZBDACVG.mjs} +1 -1
- package/lib/{chunk-WT3SCUHS.mjs → chunk-AG24QMSY.mjs} +1 -1
- package/lib/{chunk-A65ADTCR.mjs → chunk-AHUGG3WU.mjs} +1 -1
- package/lib/{chunk-ZXFL2MSN.mjs → chunk-ALBY5SOH.mjs} +1 -1
- package/lib/chunk-AXFD2OH6.mjs +7 -0
- package/lib/{chunk-JESRFE2Z.mjs → chunk-BH76USTQ.mjs} +1 -1
- package/lib/{chunk-DBBPDSFN.mjs → chunk-BPHTA6KP.mjs} +1 -1
- package/lib/{chunk-3SKLBRPL.mjs → chunk-BT43WSOS.mjs} +1 -1
- package/lib/{chunk-32EUNQT6.mjs → chunk-BVZ5H3N4.mjs} +1 -1
- package/lib/{chunk-PWVDNN2C.mjs → chunk-C6RKM4BB.mjs} +1 -1
- package/lib/{chunk-27Z76O2O.mjs → chunk-CDWZGQAJ.mjs} +1 -1
- package/lib/chunk-CGZGL6VT.mjs +7 -0
- package/lib/{chunk-P63WJMXQ.mjs → chunk-CN5HGFG4.mjs} +1 -1
- package/lib/{chunk-Y4TDVDP2.mjs → chunk-CQAFVEKP.mjs} +1 -1
- package/lib/{chunk-G2JR3F63.mjs → chunk-CTPLYUXA.mjs} +1 -1
- package/lib/chunk-CXKZ6TYV.mjs +9 -0
- package/lib/{chunk-FKK5YBGZ.mjs → chunk-D6JT4PAB.mjs} +1 -1
- package/lib/{chunk-3CX7GPCR.mjs → chunk-D7XUNWWU.mjs} +1 -1
- package/lib/{chunk-PPHVWUFY.mjs → chunk-DB5RVDC5.mjs} +1 -1
- package/lib/{chunk-LAUOSXMN.mjs → chunk-DIGUC7S4.mjs} +1 -1
- package/lib/{chunk-6GQUZ4IP.mjs → chunk-DKDKCGXV.mjs} +1 -1
- package/lib/chunk-DMT5SCO3.mjs +7 -0
- package/lib/{chunk-KKOA62S4.mjs → chunk-DNQKVCUV.mjs} +4 -3
- package/lib/{chunk-3XG25GTF.mjs → chunk-DSR2MSBH.mjs} +1 -1
- package/lib/{chunk-ZHIZY3ZC.mjs → chunk-E3RQ575Y.mjs} +1 -1
- package/lib/{chunk-SAMWHL22.mjs → chunk-EOQON3E5.mjs} +1 -1
- package/lib/{chunk-2JZGCCPG.mjs → chunk-ETNQHIDI.mjs} +1 -1
- package/lib/chunk-F5SBGJWW.mjs +7 -0
- package/lib/chunk-FBXH4VRQ.mjs +7 -0
- package/lib/chunk-FKCIGJOI.mjs +15 -0
- package/lib/{chunk-NWOI25WY.mjs → chunk-FVLFO2S6.mjs} +1 -1
- package/lib/{chunk-MKTXJCXN.mjs → chunk-FYWNSMOZ.mjs} +1 -1
- package/lib/{chunk-52EXDVPN.mjs → chunk-GEEWPTV5.mjs} +1 -1
- package/lib/{chunk-XSKPYGMT.mjs → chunk-GLN4PI5P.mjs} +1 -1
- package/lib/{chunk-DWMRIWV5.mjs → chunk-GT5ZKU6V.mjs} +1 -1
- package/lib/chunk-GTRU5AV5.mjs +7 -0
- package/lib/chunk-H33DVU3D.mjs +7 -0
- package/lib/{chunk-YAIIRFKJ.mjs → chunk-HQZUQXDC.mjs} +1 -1
- package/lib/{chunk-MUEQRIK7.mjs → chunk-HVX2AFYW.mjs} +1 -1
- package/lib/chunk-I3ZO76LL.mjs +21 -0
- package/lib/{chunk-7WSLT5VX.mjs → chunk-I5C4O3VA.mjs} +1 -1
- package/lib/{chunk-6VSZNZHH.mjs → chunk-IHGYJZZ2.mjs} +1 -1
- package/lib/{chunk-DIS254AN.mjs → chunk-ISA2NYJV.mjs} +1 -1
- package/lib/{chunk-GGUOIDWP.mjs → chunk-ISAUCWYK.mjs} +1 -1
- package/lib/{chunk-ZUTUYBNW.mjs → chunk-ISOSTAJR.mjs} +1 -1
- package/lib/chunk-IXIY6Q4M.mjs +7 -0
- package/lib/{chunk-2UU42PTD.mjs → chunk-J3TIHLWG.mjs} +1 -1
- package/lib/{chunk-GGNUACTY.mjs → chunk-JAV6F6OA.mjs} +1 -1
- package/lib/chunk-JBWJ6UEZ.mjs +7 -0
- package/lib/{chunk-C2N2TNEU.mjs → chunk-JH4ZTVQN.mjs} +1 -1
- package/lib/{chunk-FOIWWK7G.mjs → chunk-JIPT5FUD.mjs} +1 -1
- package/lib/{chunk-7EYQYZJP.mjs → chunk-JREKJO3D.mjs} +1 -1
- package/lib/{chunk-VQJMP3DC.mjs → chunk-JUOQUG7U.mjs} +1 -1
- package/lib/chunk-JYUMD357.mjs +7 -0
- package/lib/{chunk-KP5G6FUC.mjs → chunk-K7G3W7XH.mjs} +1 -1
- package/lib/{chunk-T7WREYA5.mjs → chunk-KKS2KFBT.mjs} +1 -1
- package/lib/{chunk-TMA34QMA.mjs → chunk-KWAVSZ2B.mjs} +1 -1
- package/lib/{chunk-H4JUYUSL.mjs → chunk-KXUOHACP.mjs} +1 -1
- package/lib/{chunk-STRMWSIQ.mjs → chunk-L3I6DAHX.mjs} +1 -1
- package/lib/{chunk-TCBAE65A.mjs → chunk-L47JCNP3.mjs} +1 -1
- package/lib/{chunk-5K2I2DMP.mjs → chunk-L4MSL4U7.mjs} +1 -1
- package/lib/chunk-L4RJX7DG.mjs +7 -0
- package/lib/{chunk-47UHTN3Q.mjs → chunk-L6CLN664.mjs} +1 -1
- package/lib/chunk-LI2XNV7F.mjs +7 -0
- package/lib/chunk-LP2D3JJP.mjs +7 -0
- package/lib/{chunk-KJYEQHYP.mjs → chunk-LWES2KZE.mjs} +1 -1
- package/lib/{chunk-3HEMJTAP.mjs → chunk-LYOGCIYD.mjs} +2 -2
- package/lib/{chunk-VPDEJGPS.mjs → chunk-MJD6CPZZ.mjs} +1 -1
- package/lib/{chunk-SNEOKYV7.mjs → chunk-MTM4KG3T.mjs} +1 -1
- package/lib/{chunk-J24TIGSI.mjs → chunk-N2HYG3BL.mjs} +1 -1
- package/lib/chunk-N5UIE4IR.mjs +7 -0
- package/lib/{chunk-YMDFF657.mjs → chunk-NDFFIJL5.mjs} +1 -1
- package/lib/{chunk-WOOUISSO.mjs → chunk-NFEBX75O.mjs} +1 -1
- package/lib/{chunk-ZUBBEP75.mjs → chunk-NNV7IGM7.mjs} +1 -1
- package/lib/{chunk-Q3DY7TO2.mjs → chunk-NS6ONPWL.mjs} +1 -1
- package/lib/{chunk-IVZJSDJD.mjs → chunk-O7GCCRPW.mjs} +1 -1
- package/lib/{chunk-A7JJWOLT.mjs → chunk-OO24ZYYJ.mjs} +1 -1
- package/lib/chunk-OOIDCHBQ.mjs +9 -0
- package/lib/{chunk-AUS6NFLZ.mjs → chunk-OS5GE52G.mjs} +1 -1
- package/lib/chunk-OS6HFJ7L.mjs +7 -0
- package/lib/{chunk-V3R45ZWT.mjs → chunk-OTJH6AEA.mjs} +1 -1
- package/lib/{chunk-PBE44M2Y.mjs → chunk-OUU47Y7A.mjs} +1 -1
- package/lib/{chunk-BN33LVPQ.mjs → chunk-P6WRYJN3.mjs} +1 -1
- package/lib/{chunk-JJITOWZK.mjs → chunk-PDRXM5WN.mjs} +1 -1
- package/lib/{chunk-RYRMUPMY.mjs → chunk-PGRY365W.mjs} +1 -1
- package/lib/chunk-Q4PPI3KG.mjs +7 -0
- package/lib/chunk-QFTF2PGS.mjs +21 -0
- package/lib/chunk-QKJXIY6L.mjs +7 -0
- package/lib/{chunk-PYRZFUVU.mjs → chunk-QLRWU3MB.mjs} +1 -1
- package/lib/chunk-QO4MPHZD.mjs +7 -0
- package/lib/chunk-QP3JLFIO.mjs +7 -0
- package/lib/{chunk-NLB3RGIY.mjs → chunk-QQDZQCO2.mjs} +1 -1
- package/lib/{chunk-7CVDVBEE.mjs → chunk-QXB6U3ZP.mjs} +1 -1
- package/lib/chunk-R3OM3X4L.mjs +8 -0
- package/lib/chunk-R7GKMAT4.mjs +7 -0
- package/lib/{chunk-YT22LMF7.mjs → chunk-RVCPQVKM.mjs} +1 -1
- package/lib/{chunk-TWV4A5RK.mjs → chunk-RZKJQOOC.mjs} +1 -1
- package/lib/chunk-S4PRKKGC.mjs +8 -0
- package/lib/{chunk-JH27IKCO.mjs → chunk-SX6QWYCQ.mjs} +1 -1
- package/lib/{chunk-UHFLKP26.mjs → chunk-T36DZJPH.mjs} +1 -1
- package/lib/{chunk-CZLJZQCS.mjs → chunk-T7DDS4UQ.mjs} +1 -1
- package/lib/chunk-TCEXCHXR.mjs +7 -0
- package/lib/chunk-TMIESDE5.mjs +7 -0
- package/lib/chunk-TQJ5NPRC.mjs +7 -0
- package/lib/chunk-TUPZY2QJ.mjs +7 -0
- package/lib/{chunk-GBGHJTPC.mjs → chunk-U2CTKIPE.mjs} +1 -1
- package/lib/{chunk-3HROD5RE.mjs → chunk-U4YFYSF3.mjs} +1 -1
- package/lib/{chunk-Q6SXNKV2.mjs → chunk-UIR77ZJD.mjs} +1 -1
- package/lib/{chunk-FA4ZKDCU.mjs → chunk-UOHZW2L4.mjs} +1 -1
- package/lib/{chunk-7PY3VQP3.mjs → chunk-VXZ5PTOM.mjs} +1 -1
- package/lib/{chunk-7LKI7OAS.mjs → chunk-VZLJZEV2.mjs} +1 -1
- package/lib/{chunk-YH4DYI6D.mjs → chunk-W3BQGMTR.mjs} +1 -1
- package/lib/{chunk-CELEBWEZ.mjs → chunk-WABXKL4N.mjs} +1 -1
- package/lib/{chunk-EEFUE2ES.mjs → chunk-WAYQLQAD.mjs} +1 -1
- package/lib/{chunk-RCYEBY42.mjs → chunk-WBELLGNE.mjs} +1 -1
- package/lib/{chunk-SFGZFB4F.mjs → chunk-WJAZ5LHL.mjs} +1 -1
- package/lib/{chunk-JQZTMFO7.mjs → chunk-WXU6ZJIV.mjs} +1 -1
- package/lib/{chunk-GJ6SZVHT.mjs → chunk-WZN36ACK.mjs} +1 -1
- package/lib/{chunk-XU25YA46.mjs → chunk-X2XZQ434.mjs} +1 -1
- package/lib/{chunk-QAPVKPEC.mjs → chunk-X4HZD5U2.mjs} +1 -1
- package/lib/chunk-X6XNTOGO.mjs +7 -0
- package/lib/{chunk-XK5W7BVE.mjs → chunk-XAMMIPZ4.mjs} +1 -1
- package/lib/{chunk-DT3T7FRD.mjs → chunk-XAUQXYPW.mjs} +1 -1
- package/lib/{chunk-C3LNYAVJ.mjs → chunk-XCJUNX63.mjs} +1 -1
- package/lib/chunk-XJICAOAQ.mjs +7 -0
- package/lib/{chunk-CBL42DUU.mjs → chunk-XKFHTBAB.mjs} +1 -1
- package/lib/{chunk-O2PUGRNW.mjs → chunk-XMQ5R6TC.mjs} +1 -1
- package/lib/chunk-XPXEQKLR.mjs +7 -0
- package/lib/{chunk-6KP6WETK.mjs → chunk-Y7YUNRKK.mjs} +1 -1
- package/lib/{chunk-WSUKC2U3.mjs → chunk-YBZIDW6W.mjs} +1 -1
- package/lib/{chunk-RTWYLOCA.mjs → chunk-YEVB7LVK.mjs} +1 -1
- package/lib/{chunk-L4INJ5TZ.mjs → chunk-Z3MGN42K.mjs} +1 -1
- package/lib/{chunk-EOFO3PHS.mjs → chunk-ZB5E7NHU.mjs} +1 -1
- package/lib/chunk-ZCOSME6P.mjs +7 -0
- package/lib/{chunk-HFUDCNU5.mjs → chunk-ZOSESZ22.mjs} +1 -1
- package/lib/chunk-ZTHC42X6.mjs +7 -0
- package/lib/{chunk-XZISAZA6.mjs → chunk-ZXOUWHYE.mjs} +1 -1
- package/lib/sandforge-autopilot.mjs +1 -1
- package/lib/sandforge-backup.mjs +1 -1
- package/lib/sandforge-checkpoint.mjs +1 -1
- package/lib/sandforge-cleanup.mjs +1 -1
- package/lib/sandforge-clone.mjs +1 -1
- package/lib/sandforge-compare.mjs +1 -1
- package/lib/sandforge-dataops.mjs +1 -1
- package/lib/sandforge-empty.mjs +4 -4
- package/lib/sandforge-env.mjs +98 -99
- package/lib/sandforge-frozen.mjs +1 -1
- package/lib/sandforge-mcp.mjs +2 -2
- package/lib/sandforge-monitor.mjs +1 -1
- package/lib/sandforge-pipeline.mjs +1 -1
- package/lib/sandforge-seed.mjs +1 -1
- package/lib/sandforge-sync.mjs +1 -1
- package/lib/sandforge-users.mjs +21 -23
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/lib/chunk-42BFLWHR.mjs +0 -7
- package/lib/chunk-466F37VD.mjs +0 -7
- package/lib/chunk-7SDZR6SR.mjs +0 -7
- package/lib/chunk-BMTNTBBM.mjs +0 -7
- package/lib/chunk-CCEH7L53.mjs +0 -7
- package/lib/chunk-DIL62SUN.mjs +0 -7
- package/lib/chunk-FZF23M6R.mjs +0 -7
- package/lib/chunk-GHPR5UVV.mjs +0 -7
- package/lib/chunk-HQQVANWQ.mjs +0 -20
- package/lib/chunk-IRZJU2PG.mjs +0 -22
- package/lib/chunk-ISSP2FZ5.mjs +0 -7
- package/lib/chunk-JFNLKHY6.mjs +0 -8
- package/lib/chunk-O4BROUGM.mjs +0 -7
- package/lib/chunk-PE435FVH.mjs +0 -15
- package/lib/chunk-RLWB7F26.mjs +0 -7
- package/lib/chunk-WEMLDUQA.mjs +0 -7
- package/lib/chunk-ZQO5PDX5.mjs +0 -48
|
@@ -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 k,b as N,d as q,f as C,g as u,i as D,k as R,l as z}from"./chunk-TCEXCHXR.mjs";import{a as b,b as S,d as I,e as v}from"./chunk-4GCYGQXD.mjs";import{c as P}from"./chunk-WXU6ZJIV.mjs";import{Aa as x,ia as $,oc as y}from"./chunk-R3OM3X4L.mjs";import{b as U}from"./chunk-CA5NAXSU.mjs";import{Od as E,_c as T,ib as w,pb as h,qb as A}from"./chunk-6QSHWIZI.mjs";var F="AUTOMATION_NOT_ACCEPTED";async function M(e,s){let t=0,r;try{r=await b({query:(i=>(t+=1,e.query(i)))})}catch(i){return{kind:"untyped",err:i,typingRequests:t}}if(S(r))return{kind:"production",typed:r,typingRequests:t};let n=q(e),o=await n.identity();return u(o.organizationId)!==u(r.id)?{kind:"otherSession",sessionOrganizationId:o.organizationId,typed:r,typingRequests:t}:{kind:"reached",org:n,organization:{organizationId:r.id,kind:s.scratch?"scratch":r.sandbox?"sandbox":"developer",...s.alias!==void 0?{alias:s.alias}:{},username:o.username},typed:r,typingRequests:t}}var O="No user was read or written.";function p(e,s){return{allowed:!1,refusal:{code:"PRODUCTION",message:`${e} is a production org, or cannot be told from one: ${s}. SandForge sets up the users of a sandbox, a scratch org or a Developer Edition org, and reads nothing of a production org's: nothing lifts this. ${O}`}}}async function pe(e,s){let{orgName:t,registered:r}=s;if(r===void 0)return p(t,"SandForge has no record of what kind of org it is");if(!T(r))return p(t,"SandForge has it registered as a production org");let n=await M(e,{alias:t,scratch:r.orgType==="Scratch"});switch(n.kind){case"untyped":{let o=I(n.err);return o===void 0?p(t,`it did not say what org it is (${U(n.err)})`):{allowed:!1,refusal:{code:"ORG_UNTYPED",cause:o,message:`${v(t,n.err,o)} SandForge sets up the users of no org it cannot tell from a production one. ${O}`}}}case"production":return p(t,n.typed.edition?`its Organization record says IsSandbox false, edition ${n.typed.edition}`:"its Organization record says IsSandbox false, and no edition");case"otherSession":return{allowed:!1,refusal:{code:"OTHER_SESSION",message:`The session SandForge holds for ${t} is of ${n.sessionOrganizationId}, and its Organization record says ${n.typed.id}: reconnect it on the Organizations page. ${O}`}};case"reached":return{allowed:!0,org:n.org,organization:n.organization,typingRequests:n.typingRequests}}}var H={before:"before save",after:"after save",beforeAndAfter:"before and after save"},j={flows:"the flows",triggers:"the Apex triggers",processes:"the Process Builder processes",workflowRules:"the workflow rules"};function V(e,s){return e==="flow"?`flow "${s}"`:e==="process"?`process "${s}"`:e==="workflowRule"?`workflow rule "${s}"`:`Apex trigger ${s}`}function B(e){return`${e.objectApiName}: ${V(e.kind,e.name)} (${H[e.when]})`}function K(e){return j[e]??e}async function X(e,s,t){if(t.length===0)return{kind:"none"};try{return{kind:"read",automation:await new x($(async()=>e)).read(s,t)}}catch(r){return{kind:"unread",reason:U(r)}}}function L(e){return e.kind==="read"?E(e.automation,"update"):[]}function Y(e){return h.includes(e)}function Q(e){if(e.kind==="none")return;if(e.kind==="unread")return{fired:[],notDeduced:!0};let s=L(e).filter(r=>r.name!=="").slice(0,A).map(({kind:r,name:n,objectApiName:o,when:i})=>({kind:r,name:n.slice(0,255),objectApiName:o,when:i})),t=[...new Set(y(e.automation).map(({part:r})=>r).filter(Y))];return{fired:s,...t.length>0?{unread:t}:{}}}function J(e,s,t,r,n="flags"){if(r||e.kind==="none")return;let o=n==="page"?`Nothing was written. Accept it on the page to write all the same, or turn that automation off in ${s} first.`:`Nothing was written. Add --accept-automation to write all the same (accept: { automation: true } on the users resource of sandforge.yaml), or turn that automation off in ${s} first.`,i=Q(e);if(e.kind==="unread")return{code:F,message:`What ${s} runs as ${t} could not be read (${e.reason}), so what fires is not known. ${o}`,...i!==void 0?{automation:i}:{}};let f=L(e),c=y(e.automation);if(f.length===0&&c.length===0)return;let a=[];f.length>0&&a.push(`${s} runs automation as ${t}: ${f.map(B).join("; ")}.`);for(let{part:d,reason:g}of c)a.push(`${K(d)} of ${s} could not be read (${g}), so what fires as ${t} is not known.`);return a.push(o),{code:F,message:a.join(" "),...i!==void 0?{automation:i}:{}}}function Z(e){return e.kind==="read"?e.automation.requests:0}function ee(e){let s=e.users.some(r=>r.writes.profileId!==void 0||r.writes.isActive!==void 0||r.writes.email!==void 0),t=e.users.some(r=>r.writes.isFrozen!==void 0);return[...s?["User"]:[],...t?["UserLogin"]:[]]}function ge(e){let s=e.users.some(r=>r.after.isActive!==r.applied.before.isActive||u(r.after.profileId)!==u(r.applied.before.profileId)),t=e.users.some(r=>r.after.isFrozen!==r.applied.before.isFrozen);return[...s?["User"]:[],...t?["UserLogin"]:[]]}function re(e){let{reading:s}=e;return"unread"in s?"unread":s.level==="all"?"open":"closed"}async function me(e){let s=await D(e.org,e.users,{now:e.now??new Date,...e.previous?{previous:e.previous}:{}}),t={...e.previous?{previous:e.previous}:{},acceptUserEmails:e.acceptUserEmails,acceptEmails:e.acceptEmails},r=R(s,e.users,t),n;r.emailsToPeople>0&&(n=await P(e.conn),t={...t,deliverability:re(n)},r=R(s,e.users,t));let o=await X(e.conn,e.orgName,ee(r)),i=J(o,e.orgName,"users are written",e.acceptAutomation,e.voice);return{state:s,plan:r,options:t,...n?{deliverability:n}:{},automation:o,...i?{automationRefusal:i}:{},outsideRequests:(n?.requests??0)+Z(o)}}function Ue(e,s,t){let r=z(e.plan,s,t+e.state.requests),n=[...r.refusals??[],...e.automationRefusal?[e.automationRefusal]:[]];return{...r,...n.length>0?{refusals:n}:{}}}var _="Id, Username, Email, IsActive, Profile.Name",W="UserType = 'Standard'",te=200;function l(e){return typeof e=="string"&&e!==""?e:void 0}function G(e,s){let t=l(e.Id),r=l(e.Username);if(t===void 0||r===void 0)return;let n=l(e.Profile?.Name),o=l(e.Email);return{userId:t,username:r,...n!==void 0?{profile:n}:{},address:o!==void 0&&C(o)!==void 0?"invalid":"valid",active:e.IsActive===!0,frozen:s.has(u(t))}}function se(e,s){if(e.active!==s.active)return e.active?-1:1;let t=e.username.toLowerCase(),r=s.username.toLowerCase();return t<r?-1:t>r?1:0}async function ye(e,s={}){let t=e.requests(),r=u(s.connectedUserId??(await e.identity()).userId),n=await e.query(`SELECT ${_} FROM User WHERE ${W} AND (IsActive = false OR Email LIKE '%.invalid')`),o=new Set((await e.query("SELECT UserId FROM UserLogin WHERE IsFrozen = true")).flatMap(a=>{let d=l(a.UserId);return d!==void 0?[u(d)]:[]})),i=new Map;for(let a of n){let d=G(a,o);d!==void 0&&i.set(u(d.userId),d)}let f=[...o].filter(a=>!i.has(a)&&a!==r);for(let a of k(f,te)){let d=await e.query(`SELECT ${_} FROM User WHERE ${W} AND Id IN ${N(a)}`);for(let g of d){let m=G(g,o);m!==void 0&&i.set(u(m.userId),m)}}i.delete(r);let c=[...i.values()].sort(se);return{users:c.slice(0,w),total:c.length,requests:e.requests()-t}}export{F as a,M as b,pe as c,B as d,K as e,X as f,L as g,Q as h,J as i,Z as j,ee as k,ge as l,re as m,me as n,Ue as o,ye as p};
|
|
@@ -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-X4HZD5U2.mjs";import"./chunk-NS6ONPWL.mjs";import"./chunk-DSR2MSBH.mjs";import"./chunk-YYZL7UGV.mjs";import"./chunk-54HYHHVL.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-YBZIDW6W.mjs";import"./chunk-R3OM3X4L.mjs";import"./chunk-77IVKH7R.mjs";import"./chunk-2WMKJVD2.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-VXZ5PTOM.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-SU65Z2BA.mjs";import"./chunk-HF6LAK3G.mjs";import"./chunk-ZOSESZ22.mjs";import"./chunk-TQ2TQHTT.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-Z3MGN42K.mjs";import"./chunk-2GSMHGIV.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-ISOSTAJR.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{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{m as d}from"./chunk-JBWJ6UEZ.mjs";var r=".my.salesforce.com",o=/^[a-z0-9-]+--[a-z0-9]+$/,s="scratch";function c(n){if(n===void 0||n==="")return;let e;try{e=new URL(n).hostname.toLowerCase()}catch{return}return e.endsWith(r)&&e.length>r.length?e:void 0}function t(n){if(n===void 0||!n.endsWith(r))return;let e=n.slice(0,-r.length).split(".");return e.every(i=>i!=="")?e:void 0}function a(n){return t(n)?.slice(1).includes(s)===!0}function f(n){let e=t(n);if(e===void 0||e.length>2||a(n))return;let[i]=e;return i!==void 0&&o.test(i)?i:void 0}function g(n,e){return t(n)?.[0]===e}function l(n,e){return n.kind!=="sandbox"||e.kind!=="sandbox"||n.host===void 0||f(e.host)===void 0||n.organizationId.slice(0,15)===e.organizationId.slice(0,15)?!1:d({tier:"sandbox",organizationId:n.organizationId,username:n.username??"",instanceUrl:`https://${n.host}`},{name:e.organizationId,organizationId:e.organizationId,instanceUrl:`https://${e.host??""}`})==="myDomain"}export{c as a,a as b,f as c,g as d,l as e};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{g as v}from"./chunk-
|
|
7
|
+
import{g as v}from"./chunk-Z3MGN42K.mjs";var x=!0;function D(t){let e=new Map;for(let n of t){let r=n.SobjectType;if(typeof r!="string"||r==="")continue;let o=r.toLowerCase(),c=e.get(o)??{viewAll:!1,modifyAll:!1};e.set(o,{viewAll:c.viewAll||n.PermissionsViewAllRecords===!0,modifyAll:c.modifyAll||n.PermissionsModifyAllRecords===!0})}return e}function E(t){return[...t.values()].some(e=>e.modifyAll)}var I=new Set(["task","event"]),M=new Set(["product2","pricebook2","pricebookentry"]),N=new Set(["user","group"]);function L(t){let e=[];for(let n of t.fields){if(n.type!=="reference")continue;let r=(n.referenceTo??[]).filter(o=>!N.has(o.toLowerCase()));r.length>0&&e.push({field:n.name,targets:r})}return e}function R(t,e){if(I.has(t))return"activities";if(M.has(t))return"catalog";if(t===v.toLowerCase())return"filesNotProven";if(e.has(t))return"settingNotProven"}function G(t,e){let n=j(e.describes),r=k(e.customSettings),o=new Map;for(let c of t){let f=c.toLowerCase();if(R(f,r)!==void 0||e.grants.has(f))continue;let u=n.get(f);if(u!==void 0)for(let{targets:p}of L(u)){if(p.length!==1)continue;let s=p[0],i=s.toLowerCase();!n.has(i)&&!o.has(i)&&o.set(i,s)}}return[...o.values()]}function j(t){return new Map([...t].map(e=>[e.name.toLowerCase(),e]))}function k(t){return new Set([...t??[]].map(e=>e.toLowerCase()))}function P(t,e,n){return(t.childRelationships??[]).some(r=>r.cascadeDelete===!0&&r.childSObject.toLowerCase()===e&&r.field.toLowerCase()===n.toLowerCase())}function $(t,e,n={}){let r=n.byParent??x,o=j(e.describes),c=k(e.customSettings),f=new Map,u=(s,i)=>{let d=s.toLowerCase(),C=f.get(d);if(C!==void 0)return C;let m=R(d,c);if(m!==void 0)return{reason:m};let h=e.grants.get(d);if(h!==void 0)return h.modifyAll?{access:"object"}:{reason:h.viewAll?"noModifyAll":"noViewAll"};if(!r)return{reason:"parentNotSeen",detail:"held through its parents is not proven"};let A=o.get(d);if(A===void 0)return{reason:"parentNotSeen",detail:"it could not be described"};let w=[];for(let{field:l,targets:a}of L(A)){let b=a.filter(y=>!o.has(y.toLowerCase())),g=a.filter(y=>{let S=o.get(y.toLowerCase());return S!==void 0&&P(S,d,l)});if(a.length>1){if(g.length>0||b.length>0)return{reason:"parentNotSeen",detail:`${l} may name a record of ${a.join(", ")}`};continue}if(b.length>0)return{reason:"parentNotSeen",detail:`${b[0]}, which ${l} names, could not be described`};g.length>0&&w.push({field:l,parent:g[0]})}if(w.length===0)return{reason:"parentNotSeen",detail:"it hangs from no record whose delete takes it along"};let O=new Set([...i,d]);for(let{field:l,parent:a}of w){let b=a.toLowerCase(),g=O.has(b)?void 0:u(a,O);if(g===void 0||!("access"in g))return{reason:"parentNotSeen",detail:`${a}, which ${l} names, is not held whole`}}return{access:"parent"}},p=new Map;for(let s of t){let i=u(s,new Set);f.set(s.toLowerCase(),i),p.set(s,i)}return p}export{D as a,E as b,G as c,$ as d};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a,b,c,d}from"./chunk-
|
|
7
|
+
import{a,b,c,d}from"./chunk-C6RKM4BB.mjs";import"./chunk-IHGYJZZ2.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as StepCancelledError,d as StepExecutor,b as delayMs,c as waitedWords};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a}from"./chunk-
|
|
7
|
+
import{a}from"./chunk-KWAVSZ2B.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as TransformPipeline};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a,b}from"./chunk-
|
|
7
|
+
import{a,b}from"./chunk-GLN4PI5P.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as DataPlanBuilder,b as resolveInsertOrder};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a as j,c as M}from"./chunk-INIT2UKJ.mjs";import{d as K}from"./chunk-KIMQQ6JQ.mjs";import{a as T,h as N}from"./chunk-TZE3Y7IQ.mjs";import{Ac as $,Bc as F,mc as z,nc as J,oc as Q,rc as C,sc as v,zc as H}from"./chunk-ZQO5PDX5.mjs";var ee="Id = NULL",B="no parent in cache and not the root",Y=class{build(t){let n=this.buildMeasured(t);return{...n,statements:_(n.statements,t.node.objectApiName,t.selectFields)}}buildMeasured(t){let n=N(t.node.objectApiName),o=k(M(t.selectFields)),r=t.extraWhere?` AND (${t.extraWhere})`:"",i=t.extraWhere?" + extra filter":"",l=`SELECT ${o} FROM ${n} WHERE `,u=t.node.objectApiName===t.rootObjectApiName&&!t.under;if(u&&!(t.rootReadAgain&&t.cache.has(t.node.objectApiName))){if(t.rootRecordIds!==void 0)return{statements:L({prefix:l,suffix:r,wrap:!1,objectApiName:t.node.objectApiName},[{field:"Id",ids:t.rootRecordIds}]),scoped:t.rootRecordIds.size>0,scope:"root",reason:`${t.rootRecordIds.size} root records${i}`,parentObjectsUsed:[t.rootObjectApiName],scopeIdCount:t.rootRecordIds.size,byIdCount:0};let b=T(t.rootRecordId??"");return{statements:[`${l}Id = '${b}'${r}`],scoped:!0,scope:"root",reason:`root record${i}`,parentObjectsUsed:[t.rootObjectApiName],scopeIdCount:1,byIdCount:0}}let d=t.under?void 0:t.cache.get(t.node.objectApiName),s=d?.size??0,a=d&&s>0?L({prefix:l,suffix:r,wrap:!1,objectApiName:t.node.objectApiName},[{field:"Id",ids:d}]):[],h=`${s} ID(s) cached from earlier wave`,f={statements:a,scoped:!0,scope:"self-cached",reason:`${h}${i}`,parentObjectsUsed:[],scopeIdCount:s,byIdCount:a.length};if(s>0&&(!t.everyEdge||u))return f;let g=[],I=[],y=0;for(let b of t.edges){if(b.targetObject!==t.node.objectApiName||t.under&&!t.under.has(b.sourceObject)||b.sourceObject===b.targetObject)continue;let O=t.fromAboveOnly||t.catalog?.has(b.sourceObject)?t.cache.reachedOf(b.sourceObject):t.cache.scopeOf(b.sourceObject);if(!O||O.size===0)continue;let S=t.fields.filter(c=>c.type==="reference"&&c.referenceTo.includes(b.sourceObject));if(S.length!==0){for(let c of S)g.push({field:N(c.name),ids:O});I.includes(b.sourceObject)||(I.push(b.sourceObject),y+=O.size)}}let R=[];for(let b of t.fields){if(b.type!=="reference"||b.nillable!==!1)continue;let O=new Set;for(let S of b.referenceTo){if(!t.readObjects?.has(S))continue;let c=t.catalog?.has(S)===!0;if(c&&!t.cache.isRead(S))continue;let m=c?t.cache.scopeOf(S):t.cache.get(S);if(m)for(let p of m)O.add(p)}O.size!==0&&R.push({field:N(b.name),ids:O})}let x=R.length>0?" + required parents in scope":"";if(g.length===0)return s>0?f:{statements:[`${l}${ee}`],scoped:!1,scope:"unscoped",reason:B,parentObjectsUsed:[],scopeIdCount:0,byIdCount:1};let w=Z({prefix:l,extraSuffix:r,objectApiName:t.node.objectApiName},g,R),A=`via ${I.join(", ")}${i}${x}`;return s===0?{statements:w,scoped:!0,scope:"parent-fk",reason:A,parentObjectsUsed:I,scopeIdCount:y,byIdCount:0}:{statements:[...a,...w],scoped:!0,scope:"self-and-parent-fk",reason:`${h}, and ${A}`,parentObjectsUsed:I,scopeIdCount:s+y,byIdCount:a.length}}buildJoining(t){let n=N(t.objectApiName),r=`SELECT ${k(M(t.selectFields))} FROM ${n} WHERE `,i=t.extraWhere?` AND (${t.extraWhere})`:"";return _(Z({prefix:r,extraSuffix:i,objectApiName:t.objectApiName},[{field:N(t.split.field),ids:t.split.ids}],[{field:N(t.whole.field),ids:t.whole.ids}]),t.objectApiName,t.selectFields)}buildById(t){let n=N(t.objectApiName);return _(L({prefix:`SELECT ${k(M(t.selectFields))} FROM ${n} WHERE `,suffix:t.extraWhere?` AND (${t.extraWhere})`:"",wrap:!1,objectApiName:t.objectApiName},[{field:"Id",ids:t.ids}]),t.objectApiName,t.selectFields)}};function k(e){return e.length===0?"Id":e.map(t=>N(t)).join(", ")}function _(e,t,n){let o=N(t),r=`SELECT ${k(M(n))} FROM ${o} `,i=`SELECT ${k(n)} FROM ${o} `;return r===i?[...e]:e.map(l=>l.startsWith(r)?i+l.slice(r.length):l)}var te=500;function W(e,t){let n=[...t].map(o=>`'${T(o)}'`).join(", ");return` AND (${e.field} IN (${n}))`}function ne(e,t){if(e.field!==t.field)return!1;for(let n of e.ids)if(!t.ids.has(n))return!1;return!0}function oe(e,t,n){let o=j(W(e,[])),r=j(", "),i=[],l=[],u=o;for(let d of e.ids){let s=j(`'${T(d)}'`);if(l.length>0&&u+r+s>t&&(i.push(l),l=[],u=o),l.length===0&&o+s>t)throw X(n);u+=(l.length>0?r:0)+s,l.push(d)}return l.length>0&&i.push(l),i}function re(e,t,n){let o=[""];for(let r of e){let i=oe(r,t/e.length,n);o=o.flatMap(l=>i.map(u=>l+W(r,u)))}return o}function Z(e,t,n){let o=(d,s)=>L({prefix:e.prefix,suffix:d,wrap:d!=="",objectApiName:e.objectApiName},s),r=n.map(d=>W(d,d.ids)).join(""),i=14e3-j(`${e.prefix}()${e.extraSuffix}`);if(j(r)<=i/2)return o(`${r}${e.extraSuffix}`,t);let l=new Map;for(let d of t){let s=n.filter(f=>!ne(d,f)),a=s.map(f=>f.field).join("|"),h=l.get(a)??{needed:s,clauses:[]};h.clauses.push(d),l.set(a,h)}let u=[];for(let d of l.values())for(let s of re(d.needed,i/2,e.objectApiName))u.push(...o(`${s}${e.extraSuffix}`,d.clauses));return u}function X(e){return new Error(`Scoped clone for ${e}: its filter leaves a Salesforce query URI no room for a single record Id. Shorten the filter on this object and run it again.`)}function L(e,t){let n=e.wrap?"(":"",o=e.wrap?")":"",r=j(e.prefix+n+o+e.suffix),i=j(", "),l=j(" OR "),u=[],d=[],s=r,a=0,h=()=>{let f=d.map(g=>`${g.field} IN (${g.values.join(", ")})`).join(" OR ");u.push(`${e.prefix}${n}${f}${o}${e.suffix}`),d=[],s=r,a=0};for(let f of t){let g=j(`${f.field} IN ()`),I=!1;for(let y of f.ids){let R=`'${T(y)}'`,x=j(R),w=I?i+x:(d.length>0?l:0)+g+x,A=s+w>14e3||a>=te;if(d.length>0&&A&&(h(),I=!1,w=g+x),d.length===0&&s+w>14e3)throw X(e.objectApiName);I?d[d.length-1].values.push(R):(d.push({field:f.field,values:[R]}),I=!0),s+=w,a++}}return d.length>0&&h(),u}var G="Product2",U=[C,G,$,F,v,"ProductCategory","ProductCatalog"],Ne=new Set(U);function je(e,t){return z(e,t.name,t.nillable)||e===C&&t.name===H}function xe(e,t=new Set){let n=new Set(e.nodes.map(o=>o.objectApiName));return new Set(U.filter(o=>!n.has(o)&&!t.has(o)))}function we(e,t){return e.nodes.some(n=>n.included&&t.has(n.objectApiName))?{...e,nodes:e.nodes.map(n=>n.included&&t.has(n.objectApiName)?{...n,included:!1}:n)}:e}function se(e,t,n){if(t.length<2)return t;let o=e.slice(0,3),r=t.find(i=>n.get(i)===o);return r!==void 0?[r]:t.filter(i=>!n.has(i))}function Ae(e,t){let n=q(e);return t?he(n,t):n}function Ee(e,t,n){let o=U.flatMap(f=>t.filter(({node:g})=>g.objectApiName===f)),r=new Set(o.flatMap(({fieldInfos:f})=>f.flatMap(g=>g.isReference?g.referenceTo??[]:[]))),i=new Map,l=new Map,u=(f,g,I)=>{let y=f.get(g);y?y.push(I):f.set(g,[I])};for(let{sourceObject:f,targetObject:g}of n)u(i,g,f),u(l,f,g);let d=[],s=new Set,a=[...e],h=a.filter(f=>r.has(f.objectApiName));for(;h.length>0;){for(let f of h)s.add(f.objectApiName),d.push(f);a=a.filter(f=>!s.has(f.objectApiName)),h=a.filter(({objectApiName:f})=>(i.get(f)??[]).some(g=>s.has(g))||(l.get(f)??[]).some(g=>s.has(g)))}return[...a,...o.map(({node:f})=>f),...d]}function V(e){return e.settable!==!1}function Ce(e,t){let n=!1,o=e.edges.map(r=>{let i=(t.get(r.targetObject)??[]).filter(s=>s.isReference&&(s.referenceTo??[]).includes(r.sourceObject));if(i.length===0)return r;let l=i.some(s=>J(s)),u=i.some(s=>Q(s));if(l===V(r)&&u===(r.insertOnly===!0))return r;n=!0;let d={...r};return l?delete d.settable:d.settable=!1,u?d.insertOnly=!0:delete d.insertOnly,d});return n?{...e,edges:o}:e}function Fe(e,t=[]){let n=e.edges.filter(V),o=[...n.filter(c=>c.required===!0),...t],r=n.filter(c=>c.insertOnly===!0&&c.required!==!0);if(o.length===0&&r.length===0)return q(e,n);let i=new Set(e.nodes.map(c=>c.objectApiName)),l=q(e,n),u=new Map(l.map((c,m)=>[c.objectApiName,m])),d=new Map,s=new Map,a=new Map,h=(c,m,p)=>{let E=c.get(m)??new Set;E.add(p),c.set(m,E)};for(let c of o){let{sourceObject:m,targetObject:p}=c;m===p||!i.has(m)||!i.has(p)||(h(d,p,m),h(s,m,p))}for(let c of n){let{sourceObject:m,targetObject:p}=c;m===p||!i.has(m)||!i.has(p)||d.get(p)?.has(m)||h(a,p,m)}let f=new Map;for(let[c,m]of a)for(let p of m)h(f,p,c);let g=new Map,I=new Map;for(let{sourceObject:c,targetObject:m}of r)c===m||!i.has(c)||!i.has(m)||d.get(m)?.has(c)||(h(g,m,c),h(I,c,m));let y=new Map,R=new Map,x=new Map;for(let c of i)y.set(c,d.get(c)?.size??0),R.set(c,g.get(c)?.size??0),x.set(c,a.get(c)?.size??0);let w=(c,m)=>{for(let p of[R,x,u]){let E=p.get(c)??0,D=p.get(m)??0;if(E!==D)return E<D}return!1},A=new Set([...i].filter(c=>y.get(c)===0)),b=new Map(e.nodes.map(c=>[c.objectApiName,c])),O=[],S=new Set;for(;A.size>0;){let c;for(let p of A)(c===void 0||w(p,c))&&(c=p);if(c===void 0)break;A.delete(c),S.add(c);let m=b.get(c);m&&O.push(m);for(let p of s.get(c)??[]){let E=(y.get(p)??1)-1;y.set(p,E),E===0&&!S.has(p)&&A.add(p)}for(let p of I.get(c)??[])R.set(p,(R.get(p)??1)-1);for(let p of f.get(c)??[])x.set(p,(x.get(p)??1)-1)}for(let c of e.nodes)S.has(c.objectApiName)||O.push(c);return O}function $e(e,t){return[[G,F],[$,F],[G,C],[$,C],[F,C],[v,C],...t.map(o=>[C,o])].filter(([o,r])=>o!==r&&e.has(o)&&e.has(r)).map(([o,r])=>({sourceObject:o,targetObject:r,relationshipName:`${o}Before${r}`,type:"lookup",required:!0}))}var ie=new Set(["Id","Name","CurrencyIsoCode","IsPersonAccount","IsActive","Status","IsWhat","IsInvitee","Response","RespondedDate",...Object.values(K).flat()]);function de(e,t){let n=new Set(t??[]);return e.filter(o=>o.queryable&&(!n.has(o.name)||o.isReference||ie.has(o.name))).map(o=>o.name)}var ce=2;function ae(e,t){let n=Array.from({length:t.length+1},(o,r)=>r);for(let o=1;o<=e.length;o++){let r=[o];for(let i=1;i<=t.length;i++)r[i]=Math.min(n[i]+1,r[i-1]+1,n[i-1]+(e[o-1]===t[i-1]?0:1));n=r}return n[t.length]}function le(e,t){let n=e.toLowerCase(),o;for(let r of t){let i=ae(n,r.toLowerCase());i<=ce&&i<n.length&&(!o||i<o.edits)&&(o={name:r,edits:i})}return o?.name}function Te(e,t,n){let o={},r=[];for(let[i,l]of Object.entries(e)){let u=t.find(a=>a.toLowerCase()===i.toLowerCase())??i,d=n(u),s=o[u]??=[];for(let a of l){let h=d?.find(g=>g.toLowerCase()===a.toLowerCase());if(h===void 0&&d!==null){let g=d===void 0?void 0:le(a,d);r.push({objectApiName:u,field:a,missing:d===void 0?"object":"field",...g!==void 0?{nearest:g}:{}})}let f=h??a;s.includes(f)||s.push(f)}}return{exclusions:o,unmatched:r}}function Me(e){let t=de(e.fieldInfos,e.fieldsLeftOut);t.length===0&&t.push("Id");let n,o=0,r=[],i=!1,l=!!e.rootRecordId||e.rootRecordIds!==void 0;if(e.scopedBuilder&&e.scopeCache&&e.rootObjectApiName&&l&&e.node.objectApiName===F&&e.node.objectApiName!==e.rootObjectApiName&&e.catalog?.has(F)){let d=ge(e.scopedBuilder,e.scopeCache,t,e.extraWhere);if(!d)return{kind:"skip",reason:B};n=d,o=n.length}else if(e.scopedBuilder&&e.scopeCache&&e.rootObjectApiName&&l){let d=e.fieldInfos.filter(a=>a.isReference).map(a=>({name:a.name,type:"reference",referenceTo:a.referenceTo??[],nillable:a.nillable})),s=e.scopedBuilder.build({node:e.node,fields:d,selectFields:t,edges:e.edges,cache:e.scopeCache,rootObjectApiName:e.rootObjectApiName,...e.rootRecordIds!==void 0?{rootRecordIds:e.rootRecordIds}:{rootRecordId:e.rootRecordId},extraWhere:e.extraWhere,everyEdge:!0,readObjects:e.readObjects,catalog:e.catalog,rootReadAgain:e.rootReadAgain,under:e.under});if(!s.scoped)return{kind:"skip",reason:s.reason};n=s.statements,o=s.byIdCount,i=s.scope==="root"&&e.rootRecordIds!==void 0,e.rootRecordIds!==void 0&&(s.scope==="parent-fk"||s.scope==="self-and-parent-fk")&&(r=s.parentObjectsUsed)}else{let d=[...e.extraWhere?[`(${e.extraWhere})`]:[],...e.inIdOrder?.afterId!==void 0?[`Id > ${ue(e.inIdOrder.afterId)}`]:[]],s=d.length>0?` WHERE ${d.join(" AND ")}`:"",a=e.inIdOrder?" ORDER BY Id":"";n=[`SELECT ${t.join(", ")} FROM ${N(e.node.objectApiName)}${s}${a}`]}let u={...o>0?{byIdCount:o}:{},...r.length>0?{readUnder:[...r]}:{}};if(!i&&e.maxRecordsPerObject&&e.maxRecordsPerObject>0){let d=Math.floor(e.maxRecordsPerObject);if(d>0)return fe(n,d,u)}return{kind:"query",statements:n,...u}}function fe(e,t,n={}){return{kind:"query",statements:e.map(o=>`${o} LIMIT ${t+1}`),limit:t,...n}}function ue(e){if(!/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/.test(e))throw new Error(`Not a record id to resume after: ${JSON.stringify(e.slice(0,40))}`);return`'${e}'`}function ge(e,t,n,o){let r=t.scopeOf(G),i=t.scopeOf($);if(!(!r||r.size===0||!i||i.size===0))return e.buildJoining({objectApiName:F,selectFields:n,split:{field:"Product2Id",ids:r},whole:{field:"ProductSellingModelId",ids:i},extraWhere:o})}function ke(e){return(e.byIdCount??0)<e.statements.length}async function Le(e,t,n,o){let r=e.byIdCount??0,i=e.limit,l=s=>{if(i===void 0||s.length<=i)return s;for(let a of s.slice(i))typeof a.Id=="string"&&n?.delete(a.Id);return o?.(),s.slice(0,i)};if(e.statements.length===1){let s=await t(e.statements[0]);if(n&&r===0)for(let a of s)typeof a.Id=="string"&&n.add(a.Id);return l(s)}let u=[],d=new Set;for(let[s,a]of e.statements.entries())for(let h of await t(a)){let f=h.Id;if(typeof f=="string"){if(n&&s>=r&&n.add(f),d.has(f))continue;d.add(f)}if(u.push(h),i!==void 0&&u.length>i)return l(u)}return u}function pe(e,t,n,{settle:o=!0}={}){let r=[];for(let i of n){let l=i.Id;typeof l=="string"&&l&&r.push(l)}o?e.addRead(t,r):e.add(t,r)}function Ge(e,t,n,o,r={}){pe(e,t,n,r);let i=r.keyPrefixes??new Map,l=o.filter(u=>u.isReference&&u.referenceTo&&u.referenceTo.length>0);for(let u of l){let d=u.referenceTo??[];for(let s of n){let a=s[u.name];if(!(typeof a!="string"||!a))for(let h of se(a,d,i))e.add(h,[a])}}}function he(e,t){let n=e.findIndex(l=>l.objectApiName===t);if(n<0)throw new Error(`Cannot run scoped clone with root "${t}" missing from the graph. The root node was excluded or filtered out \u2014 re-include it before executing.`);let o=e[n];if(!o.included)throw o.status==="error"?new Error(`Cannot run scoped clone: root "${t}" could not be measured during discovery (${o.errors[0]??"unknown discovery error"}), and nothing was read or written. Run discovery again once the org answers for it; if it refuses again, the user the clone reads as may not read ${t}: start from a record the user can read.`):new Error(`Cannot run scoped clone with root "${t}" excluded: the clone starts from its record, and the records that point at it would be written without it. Include it again, or clone from a query instead of a record.`);if(n===0)return e;let r=[...e],[i]=r.splice(n,1);return r.unshift(i),r}function q(e,t){let n=t??e.edges,o=new Map;for(let s of e.nodes)o.set(s.objectApiName,s);let r=new Map,i=new Map;for(let s of e.nodes)r.set(s.objectApiName,0);for(let s of n){r.has(s.targetObject)&&r.set(s.targetObject,(r.get(s.targetObject)??0)+1);let a=i.get(s.sourceObject);a?a.push(s.targetObject):i.set(s.sourceObject,[s.targetObject])}let l=[];for(let[s,a]of r)a===0&&l.push(s);let u=[],d=new Set;for(;l.length>0;){let s=l.shift();if(d.has(s))continue;d.add(s);let a=o.get(s);a&&u.push(a);let h=i.get(s);if(h){for(let f of h)if(r.has(f)){let g=(r.get(f)??1)-1;r.set(f,g),g===0&&!d.has(f)&&l.push(f)}}}for(let s of e.nodes)d.has(s.objectApiName)||u.push(s);return u}export{B as a,Y as b,te as c,G as d,U as e,Ne as f,je as g,xe as h,we as i,se as j,Ae as k,Ee as l,V as m,Ce as n,Fe as o,$e as p,de as q,Te as r,Me as s,fe as t,ke as u,Le as v,pe as w,Ge as x};
|
|
7
|
+
import{a as j,c as M}from"./chunk-INIT2UKJ.mjs";import{d as K}from"./chunk-2GSMHGIV.mjs";import{a as T,h as N}from"./chunk-TZE3Y7IQ.mjs";import{Ac as J,Bc as Q,Ec as C,Fc as v,Mc as H,Nc as $,Oc as F,zc as z}from"./chunk-6QSHWIZI.mjs";var ee="Id = NULL",B="no parent in cache and not the root",Y=class{build(t){let n=this.buildMeasured(t);return{...n,statements:_(n.statements,t.node.objectApiName,t.selectFields)}}buildMeasured(t){let n=N(t.node.objectApiName),o=k(M(t.selectFields)),r=t.extraWhere?` AND (${t.extraWhere})`:"",i=t.extraWhere?" + extra filter":"",l=`SELECT ${o} FROM ${n} WHERE `,u=t.node.objectApiName===t.rootObjectApiName&&!t.under;if(u&&!(t.rootReadAgain&&t.cache.has(t.node.objectApiName))){if(t.rootRecordIds!==void 0)return{statements:L({prefix:l,suffix:r,wrap:!1,objectApiName:t.node.objectApiName},[{field:"Id",ids:t.rootRecordIds}]),scoped:t.rootRecordIds.size>0,scope:"root",reason:`${t.rootRecordIds.size} root records${i}`,parentObjectsUsed:[t.rootObjectApiName],scopeIdCount:t.rootRecordIds.size,byIdCount:0};let b=T(t.rootRecordId??"");return{statements:[`${l}Id = '${b}'${r}`],scoped:!0,scope:"root",reason:`root record${i}`,parentObjectsUsed:[t.rootObjectApiName],scopeIdCount:1,byIdCount:0}}let d=t.under?void 0:t.cache.get(t.node.objectApiName),s=d?.size??0,a=d&&s>0?L({prefix:l,suffix:r,wrap:!1,objectApiName:t.node.objectApiName},[{field:"Id",ids:d}]):[],h=`${s} ID(s) cached from earlier wave`,f={statements:a,scoped:!0,scope:"self-cached",reason:`${h}${i}`,parentObjectsUsed:[],scopeIdCount:s,byIdCount:a.length};if(s>0&&(!t.everyEdge||u))return f;let g=[],I=[],y=0;for(let b of t.edges){if(b.targetObject!==t.node.objectApiName||t.under&&!t.under.has(b.sourceObject)||b.sourceObject===b.targetObject)continue;let O=t.fromAboveOnly||t.catalog?.has(b.sourceObject)?t.cache.reachedOf(b.sourceObject):t.cache.scopeOf(b.sourceObject);if(!O||O.size===0)continue;let S=t.fields.filter(c=>c.type==="reference"&&c.referenceTo.includes(b.sourceObject));if(S.length!==0){for(let c of S)g.push({field:N(c.name),ids:O});I.includes(b.sourceObject)||(I.push(b.sourceObject),y+=O.size)}}let R=[];for(let b of t.fields){if(b.type!=="reference"||b.nillable!==!1)continue;let O=new Set;for(let S of b.referenceTo){if(!t.readObjects?.has(S))continue;let c=t.catalog?.has(S)===!0;if(c&&!t.cache.isRead(S))continue;let m=c?t.cache.scopeOf(S):t.cache.get(S);if(m)for(let p of m)O.add(p)}O.size!==0&&R.push({field:N(b.name),ids:O})}let x=R.length>0?" + required parents in scope":"";if(g.length===0)return s>0?f:{statements:[`${l}${ee}`],scoped:!1,scope:"unscoped",reason:B,parentObjectsUsed:[],scopeIdCount:0,byIdCount:1};let w=Z({prefix:l,extraSuffix:r,objectApiName:t.node.objectApiName},g,R),A=`via ${I.join(", ")}${i}${x}`;return s===0?{statements:w,scoped:!0,scope:"parent-fk",reason:A,parentObjectsUsed:I,scopeIdCount:y,byIdCount:0}:{statements:[...a,...w],scoped:!0,scope:"self-and-parent-fk",reason:`${h}, and ${A}`,parentObjectsUsed:I,scopeIdCount:s+y,byIdCount:a.length}}buildJoining(t){let n=N(t.objectApiName),r=`SELECT ${k(M(t.selectFields))} FROM ${n} WHERE `,i=t.extraWhere?` AND (${t.extraWhere})`:"";return _(Z({prefix:r,extraSuffix:i,objectApiName:t.objectApiName},[{field:N(t.split.field),ids:t.split.ids}],[{field:N(t.whole.field),ids:t.whole.ids}]),t.objectApiName,t.selectFields)}buildById(t){let n=N(t.objectApiName);return _(L({prefix:`SELECT ${k(M(t.selectFields))} FROM ${n} WHERE `,suffix:t.extraWhere?` AND (${t.extraWhere})`:"",wrap:!1,objectApiName:t.objectApiName},[{field:"Id",ids:t.ids}]),t.objectApiName,t.selectFields)}};function k(e){return e.length===0?"Id":e.map(t=>N(t)).join(", ")}function _(e,t,n){let o=N(t),r=`SELECT ${k(M(n))} FROM ${o} `,i=`SELECT ${k(n)} FROM ${o} `;return r===i?[...e]:e.map(l=>l.startsWith(r)?i+l.slice(r.length):l)}var te=500;function W(e,t){let n=[...t].map(o=>`'${T(o)}'`).join(", ");return` AND (${e.field} IN (${n}))`}function ne(e,t){if(e.field!==t.field)return!1;for(let n of e.ids)if(!t.ids.has(n))return!1;return!0}function oe(e,t,n){let o=j(W(e,[])),r=j(", "),i=[],l=[],u=o;for(let d of e.ids){let s=j(`'${T(d)}'`);if(l.length>0&&u+r+s>t&&(i.push(l),l=[],u=o),l.length===0&&o+s>t)throw X(n);u+=(l.length>0?r:0)+s,l.push(d)}return l.length>0&&i.push(l),i}function re(e,t,n){let o=[""];for(let r of e){let i=oe(r,t/e.length,n);o=o.flatMap(l=>i.map(u=>l+W(r,u)))}return o}function Z(e,t,n){let o=(d,s)=>L({prefix:e.prefix,suffix:d,wrap:d!=="",objectApiName:e.objectApiName},s),r=n.map(d=>W(d,d.ids)).join(""),i=14e3-j(`${e.prefix}()${e.extraSuffix}`);if(j(r)<=i/2)return o(`${r}${e.extraSuffix}`,t);let l=new Map;for(let d of t){let s=n.filter(f=>!ne(d,f)),a=s.map(f=>f.field).join("|"),h=l.get(a)??{needed:s,clauses:[]};h.clauses.push(d),l.set(a,h)}let u=[];for(let d of l.values())for(let s of re(d.needed,i/2,e.objectApiName))u.push(...o(`${s}${e.extraSuffix}`,d.clauses));return u}function X(e){return new Error(`Scoped clone for ${e}: its filter leaves a Salesforce query URI no room for a single record Id. Shorten the filter on this object and run it again.`)}function L(e,t){let n=e.wrap?"(":"",o=e.wrap?")":"",r=j(e.prefix+n+o+e.suffix),i=j(", "),l=j(" OR "),u=[],d=[],s=r,a=0,h=()=>{let f=d.map(g=>`${g.field} IN (${g.values.join(", ")})`).join(" OR ");u.push(`${e.prefix}${n}${f}${o}${e.suffix}`),d=[],s=r,a=0};for(let f of t){let g=j(`${f.field} IN ()`),I=!1;for(let y of f.ids){let R=`'${T(y)}'`,x=j(R),w=I?i+x:(d.length>0?l:0)+g+x,A=s+w>14e3||a>=te;if(d.length>0&&A&&(h(),I=!1,w=g+x),d.length===0&&s+w>14e3)throw X(e.objectApiName);I?d[d.length-1].values.push(R):(d.push({field:f.field,values:[R]}),I=!0),s+=w,a++}}return d.length>0&&h(),u}var G="Product2",U=[C,G,$,F,v,"ProductCategory","ProductCatalog"],Ne=new Set(U);function je(e,t){return z(e,t.name,t.nillable)||e===C&&t.name===H}function xe(e,t=new Set){let n=new Set(e.nodes.map(o=>o.objectApiName));return new Set(U.filter(o=>!n.has(o)&&!t.has(o)))}function we(e,t){return e.nodes.some(n=>n.included&&t.has(n.objectApiName))?{...e,nodes:e.nodes.map(n=>n.included&&t.has(n.objectApiName)?{...n,included:!1}:n)}:e}function se(e,t,n){if(t.length<2)return t;let o=e.slice(0,3),r=t.find(i=>n.get(i)===o);return r!==void 0?[r]:t.filter(i=>!n.has(i))}function Ae(e,t){let n=q(e);return t?he(n,t):n}function Ee(e,t,n){let o=U.flatMap(f=>t.filter(({node:g})=>g.objectApiName===f)),r=new Set(o.flatMap(({fieldInfos:f})=>f.flatMap(g=>g.isReference?g.referenceTo??[]:[]))),i=new Map,l=new Map,u=(f,g,I)=>{let y=f.get(g);y?y.push(I):f.set(g,[I])};for(let{sourceObject:f,targetObject:g}of n)u(i,g,f),u(l,f,g);let d=[],s=new Set,a=[...e],h=a.filter(f=>r.has(f.objectApiName));for(;h.length>0;){for(let f of h)s.add(f.objectApiName),d.push(f);a=a.filter(f=>!s.has(f.objectApiName)),h=a.filter(({objectApiName:f})=>(i.get(f)??[]).some(g=>s.has(g))||(l.get(f)??[]).some(g=>s.has(g)))}return[...a,...o.map(({node:f})=>f),...d]}function V(e){return e.settable!==!1}function Ce(e,t){let n=!1,o=e.edges.map(r=>{let i=(t.get(r.targetObject)??[]).filter(s=>s.isReference&&(s.referenceTo??[]).includes(r.sourceObject));if(i.length===0)return r;let l=i.some(s=>J(s)),u=i.some(s=>Q(s));if(l===V(r)&&u===(r.insertOnly===!0))return r;n=!0;let d={...r};return l?delete d.settable:d.settable=!1,u?d.insertOnly=!0:delete d.insertOnly,d});return n?{...e,edges:o}:e}function Fe(e,t=[]){let n=e.edges.filter(V),o=[...n.filter(c=>c.required===!0),...t],r=n.filter(c=>c.insertOnly===!0&&c.required!==!0);if(o.length===0&&r.length===0)return q(e,n);let i=new Set(e.nodes.map(c=>c.objectApiName)),l=q(e,n),u=new Map(l.map((c,m)=>[c.objectApiName,m])),d=new Map,s=new Map,a=new Map,h=(c,m,p)=>{let E=c.get(m)??new Set;E.add(p),c.set(m,E)};for(let c of o){let{sourceObject:m,targetObject:p}=c;m===p||!i.has(m)||!i.has(p)||(h(d,p,m),h(s,m,p))}for(let c of n){let{sourceObject:m,targetObject:p}=c;m===p||!i.has(m)||!i.has(p)||d.get(p)?.has(m)||h(a,p,m)}let f=new Map;for(let[c,m]of a)for(let p of m)h(f,p,c);let g=new Map,I=new Map;for(let{sourceObject:c,targetObject:m}of r)c===m||!i.has(c)||!i.has(m)||d.get(m)?.has(c)||(h(g,m,c),h(I,c,m));let y=new Map,R=new Map,x=new Map;for(let c of i)y.set(c,d.get(c)?.size??0),R.set(c,g.get(c)?.size??0),x.set(c,a.get(c)?.size??0);let w=(c,m)=>{for(let p of[R,x,u]){let E=p.get(c)??0,D=p.get(m)??0;if(E!==D)return E<D}return!1},A=new Set([...i].filter(c=>y.get(c)===0)),b=new Map(e.nodes.map(c=>[c.objectApiName,c])),O=[],S=new Set;for(;A.size>0;){let c;for(let p of A)(c===void 0||w(p,c))&&(c=p);if(c===void 0)break;A.delete(c),S.add(c);let m=b.get(c);m&&O.push(m);for(let p of s.get(c)??[]){let E=(y.get(p)??1)-1;y.set(p,E),E===0&&!S.has(p)&&A.add(p)}for(let p of I.get(c)??[])R.set(p,(R.get(p)??1)-1);for(let p of f.get(c)??[])x.set(p,(x.get(p)??1)-1)}for(let c of e.nodes)S.has(c.objectApiName)||O.push(c);return O}function $e(e,t){return[[G,F],[$,F],[G,C],[$,C],[F,C],[v,C],...t.map(o=>[C,o])].filter(([o,r])=>o!==r&&e.has(o)&&e.has(r)).map(([o,r])=>({sourceObject:o,targetObject:r,relationshipName:`${o}Before${r}`,type:"lookup",required:!0}))}var ie=new Set(["Id","Name","CurrencyIsoCode","IsPersonAccount","IsActive","Status","IsWhat","IsInvitee","Response","RespondedDate",...Object.values(K).flat()]);function de(e,t){let n=new Set(t??[]);return e.filter(o=>o.queryable&&(!n.has(o.name)||o.isReference||ie.has(o.name))).map(o=>o.name)}var ce=2;function ae(e,t){let n=Array.from({length:t.length+1},(o,r)=>r);for(let o=1;o<=e.length;o++){let r=[o];for(let i=1;i<=t.length;i++)r[i]=Math.min(n[i]+1,r[i-1]+1,n[i-1]+(e[o-1]===t[i-1]?0:1));n=r}return n[t.length]}function le(e,t){let n=e.toLowerCase(),o;for(let r of t){let i=ae(n,r.toLowerCase());i<=ce&&i<n.length&&(!o||i<o.edits)&&(o={name:r,edits:i})}return o?.name}function Te(e,t,n){let o={},r=[];for(let[i,l]of Object.entries(e)){let u=t.find(a=>a.toLowerCase()===i.toLowerCase())??i,d=n(u),s=o[u]??=[];for(let a of l){let h=d?.find(g=>g.toLowerCase()===a.toLowerCase());if(h===void 0&&d!==null){let g=d===void 0?void 0:le(a,d);r.push({objectApiName:u,field:a,missing:d===void 0?"object":"field",...g!==void 0?{nearest:g}:{}})}let f=h??a;s.includes(f)||s.push(f)}}return{exclusions:o,unmatched:r}}function Me(e){let t=de(e.fieldInfos,e.fieldsLeftOut);t.length===0&&t.push("Id");let n,o=0,r=[],i=!1,l=!!e.rootRecordId||e.rootRecordIds!==void 0;if(e.scopedBuilder&&e.scopeCache&&e.rootObjectApiName&&l&&e.node.objectApiName===F&&e.node.objectApiName!==e.rootObjectApiName&&e.catalog?.has(F)){let d=ge(e.scopedBuilder,e.scopeCache,t,e.extraWhere);if(!d)return{kind:"skip",reason:B};n=d,o=n.length}else if(e.scopedBuilder&&e.scopeCache&&e.rootObjectApiName&&l){let d=e.fieldInfos.filter(a=>a.isReference).map(a=>({name:a.name,type:"reference",referenceTo:a.referenceTo??[],nillable:a.nillable})),s=e.scopedBuilder.build({node:e.node,fields:d,selectFields:t,edges:e.edges,cache:e.scopeCache,rootObjectApiName:e.rootObjectApiName,...e.rootRecordIds!==void 0?{rootRecordIds:e.rootRecordIds}:{rootRecordId:e.rootRecordId},extraWhere:e.extraWhere,everyEdge:!0,readObjects:e.readObjects,catalog:e.catalog,rootReadAgain:e.rootReadAgain,under:e.under});if(!s.scoped)return{kind:"skip",reason:s.reason};n=s.statements,o=s.byIdCount,i=s.scope==="root"&&e.rootRecordIds!==void 0,e.rootRecordIds!==void 0&&(s.scope==="parent-fk"||s.scope==="self-and-parent-fk")&&(r=s.parentObjectsUsed)}else{let d=[...e.extraWhere?[`(${e.extraWhere})`]:[],...e.inIdOrder?.afterId!==void 0?[`Id > ${ue(e.inIdOrder.afterId)}`]:[]],s=d.length>0?` WHERE ${d.join(" AND ")}`:"",a=e.inIdOrder?" ORDER BY Id":"";n=[`SELECT ${t.join(", ")} FROM ${N(e.node.objectApiName)}${s}${a}`]}let u={...o>0?{byIdCount:o}:{},...r.length>0?{readUnder:[...r]}:{}};if(!i&&e.maxRecordsPerObject&&e.maxRecordsPerObject>0){let d=Math.floor(e.maxRecordsPerObject);if(d>0)return fe(n,d,u)}return{kind:"query",statements:n,...u}}function fe(e,t,n={}){return{kind:"query",statements:e.map(o=>`${o} LIMIT ${t+1}`),limit:t,...n}}function ue(e){if(!/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/.test(e))throw new Error(`Not a record id to resume after: ${JSON.stringify(e.slice(0,40))}`);return`'${e}'`}function ge(e,t,n,o){let r=t.scopeOf(G),i=t.scopeOf($);if(!(!r||r.size===0||!i||i.size===0))return e.buildJoining({objectApiName:F,selectFields:n,split:{field:"Product2Id",ids:r},whole:{field:"ProductSellingModelId",ids:i},extraWhere:o})}function ke(e){return(e.byIdCount??0)<e.statements.length}async function Le(e,t,n,o){let r=e.byIdCount??0,i=e.limit,l=s=>{if(i===void 0||s.length<=i)return s;for(let a of s.slice(i))typeof a.Id=="string"&&n?.delete(a.Id);return o?.(),s.slice(0,i)};if(e.statements.length===1){let s=await t(e.statements[0]);if(n&&r===0)for(let a of s)typeof a.Id=="string"&&n.add(a.Id);return l(s)}let u=[],d=new Set;for(let[s,a]of e.statements.entries())for(let h of await t(a)){let f=h.Id;if(typeof f=="string"){if(n&&s>=r&&n.add(f),d.has(f))continue;d.add(f)}if(u.push(h),i!==void 0&&u.length>i)return l(u)}return u}function pe(e,t,n,{settle:o=!0}={}){let r=[];for(let i of n){let l=i.Id;typeof l=="string"&&l&&r.push(l)}o?e.addRead(t,r):e.add(t,r)}function Ge(e,t,n,o,r={}){pe(e,t,n,r);let i=r.keyPrefixes??new Map,l=o.filter(u=>u.isReference&&u.referenceTo&&u.referenceTo.length>0);for(let u of l){let d=u.referenceTo??[];for(let s of n){let a=s[u.name];if(!(typeof a!="string"||!a))for(let h of se(a,d,i))e.add(h,[a])}}}function he(e,t){let n=e.findIndex(l=>l.objectApiName===t);if(n<0)throw new Error(`Cannot run scoped clone with root "${t}" missing from the graph. The root node was excluded or filtered out \u2014 re-include it before executing.`);let o=e[n];if(!o.included)throw o.status==="error"?new Error(`Cannot run scoped clone: root "${t}" could not be measured during discovery (${o.errors[0]??"unknown discovery error"}), and nothing was read or written. Run discovery again once the org answers for it; if it refuses again, the user the clone reads as may not read ${t}: start from a record the user can read.`):new Error(`Cannot run scoped clone with root "${t}" excluded: the clone starts from its record, and the records that point at it would be written without it. Include it again, or clone from a query instead of a record.`);if(n===0)return e;let r=[...e],[i]=r.splice(n,1);return r.unshift(i),r}function q(e,t){let n=t??e.edges,o=new Map;for(let s of e.nodes)o.set(s.objectApiName,s);let r=new Map,i=new Map;for(let s of e.nodes)r.set(s.objectApiName,0);for(let s of n){r.has(s.targetObject)&&r.set(s.targetObject,(r.get(s.targetObject)??0)+1);let a=i.get(s.sourceObject);a?a.push(s.targetObject):i.set(s.sourceObject,[s.targetObject])}let l=[];for(let[s,a]of r)a===0&&l.push(s);let u=[],d=new Set;for(;l.length>0;){let s=l.shift();if(d.has(s))continue;d.add(s);let a=o.get(s);a&&u.push(a);let h=i.get(s);if(h){for(let f of h)if(r.has(f)){let g=(r.get(f)??1)-1;r.set(f,g),g===0&&!d.has(f)&&l.push(f)}}}for(let s of e.nodes)d.has(s.objectApiName)||u.push(s);return u}export{B as a,Y as b,te as c,G as d,U as e,Ne as f,je as g,xe as h,we as i,se as j,Ae as k,Ee as l,V as m,Ce as n,Fe as o,$e as p,de as q,Te as r,Me as s,fe as t,ke as u,Le as v,pe as w,Ge as x};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a,b,c,d,e,f,g,h,i}from"./chunk-
|
|
7
|
+
import{a,b,c,d,e,f,g,h,i}from"./chunk-KXUOHACP.mjs";import"./chunk-27BBEGUD.mjs";import"./chunk-OTJH6AEA.mjs";import"./chunk-FVLFO2S6.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-77MZRBWX.mjs";import"./chunk-BT43WSOS.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SCENARIO_PACK_FILE_SUFFIX,b as SCENARIO_PACK_SEARCH,i as findScenarioPack,e as findScenarioPackFiles,f as listScenarioPacks,c as nodeScenarioPackFiles,d as readScenarioPackText,h as saveScenarioPack,g as scenarioPackText};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{y as he}from"./chunk-SZGGFST2.mjs";import{v as le,x as F}from"./chunk-IRZJU2PG.mjs";import{i as ce,j as x,k as de,l as pe}from"./chunk-Y4TDVDP2.mjs";import{e as C,i as ae,k as D,l as se}from"./chunk-5K2I2DMP.mjs";import{d as j,f as oe,xb as re,yb as ie}from"./chunk-3HEMJTAP.mjs";import{c as ne}from"./chunk-QROPNEGY.mjs";import{a as v}from"./chunk-SCKUIE3R.mjs";import{$a as J}from"./chunk-ISSP2FZ5.mjs";import{L as te,e as X,k as Q,z as ee}from"./chunk-J24TIGSI.mjs";import{mc as S}from"./chunk-JFNLKHY6.mjs";import{Ra as Z,cb as V}from"./chunk-ZQO5PDX5.mjs";import{existsSync as $e,readFileSync as ve}from"node:fs";import{hostname as be}from"node:os";import{join as ge,resolve as T}from"node:path";var Ae=["--custom-settings","--mask","--keep-contact-points","--no-real-data"],Ee=["--objects","--exclude-object","--owners","--owner-map","--link","--replay-config"],Ie=["--again","--accept-emails","--max-records",...j.switches,...j.values],Oe=["--preview","--sweep","--sweep-list",...re,"--include-changed"],Ne=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,A=/^00D[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,me=e=>Z.safeParse(e).success,Se={ownerMap:"--owner-map",objects:"--objects",excluded:"--exclude-object",link:"--link"};function Rt(e,t){let n=c=>e.includes(c),o=c=>{let p=[];for(let w=1;w<e.length;w++){if(e[w]!==c)continue;let $=e[w+1];if($===void 0||$.startsWith("--"))return t(`${c} wants a value.`);p.push($),w++}return p},r=c=>{let p=o(c);return p.length>1&&t(`${c} is given ${p.length} times: give it once.`),p[0]},s=c=>{let p=r(c);if(p!==void 0)return/^\d{1,15}$/.test(p)||t(`${c} takes a whole number, not "${p}".`),Number(p)},d=["--dry-run","--verify","--remove"].filter(n);d.length>1&&t(`Give one of --dry-run, --verify and --remove, not ${d.join(" and ")}. Nothing was run.`);let i=n("--dry-run")?"dryRun":n("--verify")?"verify":n("--remove")?"remove":"replay",a=c=>c.filter(n);if(i==="verify"||i==="remove"){let c=a([...Ae,...Ee]);c.length>0&&t(`${c.join(", ")} ${c.length===1?"is a choice":"are choices"} of a replay and its dry run: --verify reads the choices its last replay was made with, and --remove takes back what it wrote. Nothing was run.`);let p=a(Ie);p.length>0&&t(`${p.join(", ")} goes with a replay or its dry run, not with --${i}. Nothing was run.`)}if(i!=="remove"){let c=a(Oe);c.length>0&&t(`${c.join(", ")} goes with --remove. Nothing was run.`)}n("--sweep")&&n("--sweep-list")&&t("--sweep deletes and --sweep-list only lists: give one of them. Nothing was run."),n("--preview")&&n("--sweep-list")&&t("--preview deletes nothing, and --sweep-list lists what a sweep would take: give --preview without it, or with --sweep. Nothing was run.");let u=ie(e);if("refusal"in u&&t(`${u.refusal} Nothing was run.`),i==="verify"){let c=a(["--mute-automation","--accept-automation"]);c.length>0&&t(`${c.join(", ")} goes with a replay or its removal: a verification only reads. Nothing was run.`)}let m=r("--checkpoint"),f=r("--file");if(m===void 0&&f===void 0)return t("replay needs --checkpoint <id|name> (list names them) or --file <.sfcheckpoint>. Run with --help.");m!==void 0&&f!==void 0&&t("Give --checkpoint or --file, not both. Nothing was run.");let h=r("--from");if(h!==void 0&&m===void 0&&t("--from goes with --checkpoint <name>: it names the org the checkpoint was taken of."),m!==void 0&&!me(m)&&h===void 0&&t(`--checkpoint '${m}' is not a checkpoint's id: a name names one of an org's checkpoints, so give --from <alias|username|00D\u2026>, the org it was taken of, or its id ("${v("checkpoint")} list" names them). Nothing was run.`),f===void 0){let c=a(["--key-env","--keep-days"]);c.length>0&&t(`${c.join(" and ")} goes with --file. Nothing was run.`)}let k=r("--target")??t("replay needs --target <alias>, the org the checkpoint's records go into. Run with --help."),R=o("--objects").flatMap(c=>c.split(",").map(p=>p.trim()).filter(p=>p!=="")),g=o("--exclude-object");for(let[c,p]of[["--objects",R],["--exclude-object",g]]){let w=p.find($=>!Ne.test($));w!==void 0&&t(`${c} takes objects' API names, not "${w}".`)}let E=c=>c.filter((p,w)=>c.findIndex($=>$.toLowerCase()===p.toLowerCase())===w),I=r("--owners")??"same";I!=="same"&&I!=="me"&&t(`--owners takes same or me, not "${I}".`);let we=o("--link").map(c=>{let p=/^([A-Za-z][A-Za-z0-9_]*)=([A-Za-z0-9_,]+)$/.exec(c);return p?{objectApiName:p[1],fields:p[2].split(",").filter(w=>w!=="")}:t(`--link takes Object=Field or Object=Field,Field \u2014 the fields a record of the other org is found by \u2014, not "${c}".`)}),O=r("--owner-map"),Y=O!==void 0?ye("--owner-map",O,t):void 0,Re={owners:I,...Y!==void 0?{ownerMap:Y}:{},customSettings:n("--custom-settings"),mask:n("--mask"),contactPoints:n("--keep-contact-points")?"kept":"neutralized",objects:E(R),excluded:E(g),link:we,...n("--no-real-data")?{noRealData:!0}:{}},P=V.safeParse(Re);if(!P.success){let c=P.error.issues[0],p=String(c?.path[0]??"");return t(`${Se[p]??p}: ${c?.message??"not read"}. Nothing was run.`)}let K=P.data,N=r("--replay-config"),H=N!==void 0?Ce(N,K,t):void 0,_=s("--max-records");_===0&&t('--max-records takes a whole number of 1 or more, not "0". Nothing was run.');let G=Fe(r("--key-env"),t),q=oe(e);return{action:i,...m!==void 0?{checkpoint:m}:{},...h!==void 0?{from:h}:{},...f!==void 0?{file:T(f)}:{},...G!==void 0?{keyEnv:G}:{},keepDays:s("--keep-days")??X,target:k,choices:K,...O!==void 0?{ownerMapFile:T(O)}:{},...H!==void 0?{config:H}:{},...N!==void 0?{configFile:T(N)}:{},again:n("--again"),muteAutomation:n("--mute-automation"),acceptAutomation:n("--accept-automation"),acceptEmails:n("--accept-emails"),...q!==void 0?{checkpointFirst:q}:{},..._!==void 0?{maxRecords:_}:{},preview:n("--preview"),sweep:n("--sweep"),sweepList:n("--sweep-list"),...u,includeChanged:n("--include-changed"),yes:n("--yes")}}function $t(e,t){let n=e.flatMap((r,s)=>r==="--target"?[e[s+1]]:[]);n.length>1&&t(`--target is given ${n.length} times: give it once.`);let o=n[0];return o!==void 0?{target:o}:{}}function ye(e,t,n){try{return JSON.parse(ve(t,"utf8"))}catch(o){return n(`${e}: ${t} does not read as JSON (${o instanceof Error?o.message:String(o)}). Nothing was run.`)}}function Ce(e,t,n){let o=ye("--replay-config",e,n),r=J.safeParse({targetOrgId:"command-line",replay:{organizationId:"00D000000000000AAA",checkpointId:"ck-20000101-000000-0000",choices:t,config:o}});if(!r.success){let s=r.error.issues[0],d=(s?.path??[]).slice(2).join(".");return n(`--replay-config: ${d!==""?`${d}: `:""}${s?.message??"not read"}. It takes the load\u2019s part of a Frozen project\u2019s configuration: requiredFieldDefaults, requiredLookupPlaceholders, picklistRules, defaultPicklistRule, identityKeys, undeletableObjects, duplicateErrorPatterns, mockDetection, protectedOrgIds. Nothing was run.`)}return o}function Fe(e,t){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||C(e)!==void 0?t("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}var ze="cli-store.json";function W(e,t){return t?ge(e,".replays"):ce()}var y=class extends Error{constructor(n,o=1){super(n.message);this.refusal=n;this.code=o;this.name="ReplayStop"}refusal;code};function ke(e){try{return new x({root:e})}catch(t){throw new y({code:"STORE_REFUSED",message:`The replays cannot be kept in ${e}: ${t instanceof Error?t.message:String(t)} Name a store outside any repository with --store <folder>. Nothing was read or written.`})}}function B(e,t){let n=D(e);if(!$e(n))return;let o=te({root:n,...t!==void 0?{locksDir:t}:{}});return"store"in o?o.store:void 0}function z(e){return/^[\w./:@+-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function vt(e,t){return`${v("checkpoint")} replay --file ${z(e)} --target ${t}`}function L(e,t,n){return`${v("checkpoint")} replay --checkpoint ${e} --target ${t}`+(n!==void 0?` --store ${z(n)}`:"")}var l=e=>e.toLocaleString("en-US");function b(e){let t=new Date(Date.parse(e)).toISOString();return`${t.slice(0,10)} ${t.slice(11,16)} UTC`}function M(e,t=8){return e.length<=t?e.join(", "):`${e.slice(0,t).join(", ")} and ${l(e.length-t)} more`}function Le(e){return{run:"replay",done:"replayed",source:e,recordedIn:"for this checkpoint on this machine",remove:"--remove",module:"replay",again:"again",againSubject:{purge:"replayAgain",sweep:"replayAgainSweep"},maybeMasks:"the checkpoint does not say whether its take read them unmasked, so they may hold the masks a user without View Encrypted Data reads, such as ****1234"}}var Pe={fileContentNotKept:()=>"a checkpoint keeps no file's content",notInTarget:(e,t)=>`${t} has no such object: deploy it there, or leave it out (--exclude-object ${e})`,notCreateable:(e,t)=>`${t} lets no one create its records`,excluded:()=>"left out as asked"},_e={objectNotReplayed:e=>`the checkpoint holds the records it names and does not replay them: add ${e.split(".")[0]}'s target with --objects`,objectNotHeld:(e,t)=>`the checkpoint does not hold what it names, and ${t} has no record of that Id`,userNotInTarget:(e,t)=>`${t} has no active standard user for it`},fe={requiredLookupMissing:"a required lookup names a record neither replayed nor in the other org",parentRefused:"a parent of theirs is refused, and no orphan is written",personAccountsUnsupported:"the other org has not turned person accounts on",inactiveCurrency:"their currency is not active in the other org",recordTypeUnavailable:"their record type is one the user who replays may not create"};function je(e){return`${Object.hasOwn(fe,e.reason)?fe[e.reason]:e.reason}${e.path?`: ${e.path}`:""}`}var De={byName:"found by its name",byId:"found by its Id",default:"the other org's default for the user who replays"};function xe(e){let{summary:t}=e,n=e.target.name,o=[],{records:r}=t;r.linkedById>0&&o.push(`${l(r.linkedById)} record(s) ${n} holds under the same Id \u2014 a sandbox copied from the same production \u2014: linked, not changed`),r.linkedByKey>0&&o.push(`${l(r.linkedByKey)} record(s) found in ${n} by the fields --link names: linked, not created`);let s=t.owners,d=[s.reasons.notInTarget>0?`their user is not in ${n}: ${l(s.reasons.notInTarget)}`:"",s.reasons.inactive>0?`their user is inactive in ${n}: ${l(s.reasons.inactive)}`:"",s.reasons.queueMissing>0?`their queue is not in ${n}: ${l(s.reasons.queueMissing)}`:""].filter(Boolean);o.push(`owners: ${l(s.kept)} kept, ${l(s.toRunningUser)} to the user who replays`+(d.length>0?` \u2014 ${d.join("; ")}`:""));for(let i of t.recordTypes)o.push(`record type ${i.object}.${i.recordType}: ${De[i.outcome]} \u2014 ${l(i.records)} record(s)`);for(let i of t.refused)o.push(`refused before anything is written: ${i.object} ${l(i.records)} \u2014 `+je(i));for(let i of t.notReplayed)o.push(`not replayed: ${i.object} ${l(i.records)} \u2014 `+Pe[i.reason](i.object,n));e.filesLeft.length>0&&o.push(`${l(e.filesLeft.length)} file(s) left where they were, a checkpoint keeping no file's content:`,...e.filesLeft.map(i=>` ${i.objectApiName}${i.name!==void 0?` '${i.name}'`:""}`));for(let i of t.lookupsEmptied)o.push(`${i.field}: emptied on ${l(i.records)} record(s) \u2014 `+_e[i.reason](i.field,n));for(let i of t.fieldsNotInTarget)o.push(`${i.object}: ${M(i.fields)} left out \u2014 ${n} does not have them`);t.customSettings&&o.push(`custom settings: ${l(t.customSettings.inserted)} row(s) set up, ${l(t.customSettings.alreadyThere)} already in ${n}, kept as they are`);for(let i of t.currencies.refused)o.push(`${i.code}: ${l(i.records)} record(s) refused \u2014 the currency is not active in ${n}: activate it there, or leave those records out`);if(t.currencies.singleCurrencyTarget&&o.push(`${n} has one currency: amounts are kept as they are, in its currency`),t.standardPricebook==="deduced"?o.push("standard price book: told from the price book entries, the checkpoint naming none"):t.standardPricebook==="ambiguous"&&o.push("standard price book: the price book entries do not tell which it was, and those that need it are refused"),t.masked.fields.length>0&&o.push(`masked: ${M(t.masked.fields)}`),(t.masked.unmaskedFreeText??[]).length>0&&o.push(`not masked, free text the masking does not read: ${M(t.masked.unmaskedFreeText??[])}`),o.push(t.contactPoints==="neutralized"?"emails and phone numbers made unreachable (.invalid, numbers that ring nobody); --keep-contact-points keeps them":"emails and phone numbers kept as they are: they reach the people they name"),(t.archivedActivities??0)>0&&o.push(`${l(t.archivedActivities??0)} archived task(s) and event(s) replayed, which ${n} holds live`),t.degraded.length>0&&o.push((e.checkpoint.annex?`its take could not read ${t.degraded.join(", ")}`:"taken before SandForge 1.81, it keeps no record types, users, queues nor standard price book")+`: the records they name get what ${n} gives them, each said above`),o.push("created and modified dates and users are the replay's own: the platform sets them"),e.storage){let{storage:i}=e;o.push(`data storage: about ${S(i.estimateMB)} MB of the ${S(i.remainingMB)} MB ${n} has left of ${S(i.maxMB)} MB`)}return o}var Te=new Set(["REPLAY_SAME_ORG","REPLAY_REAL_DATA","REPLAY_COPY_UNKNOWN","REPLAY_TOO_MANY","REPLAY_NOTHING","REPLAY_CHECKPOINT_UNUSABLE","REPLAY_NO_PILOT","CHECKPOINT_NOT_FOUND","OWNER_MAP_INACTIVE","OWNER_MAP_UNKNOWN","GUARD_REFUSED","NO_LOAD","TARGET_REFRESHED","LOAD_REMOVED","LOAD_STOPPED"]);function Me(e){let t=String(e.type??""),n=e.payload?.code;if(!(!t.endsWith(":error")||typeof n!="string")&&Te.has(n))return{code:n,message:String(e.payload?.message??"")}}function Ue(e,t,n,o={}){switch(e){case"TARGET_REFRESHED":if(/dataset/i.test(t))return`${n} was refreshed after the last replay: the records it created went with the refresh. Replay the checkpoint again, then verify.`;break;case"LOAD_REMOVED":{let r=/removal of (\S+) took part/.exec(t);if(r)return`The removal of ${r[1]} took part of the records the last replay created and left ${l(Number(o.left??0))} in ${n}: a verification would read the ones it took as missing. Remove what is left (--remove), or replay again (--again), which purges or finds it again; then verify.`;let s=/removed on (\S+?)\.(?:\s|$)/.exec(t);return`The records the last replay created were removed${s?` on ${s[1]}`:""}. Replay the checkpoint again, then verify.`}case"LOAD_STOPPED":return"The last replay stopped part way \u2014 it was cancelled, or failed once it had written \u2014 and wrote no counting contract: a verification would judge it by the one before. Replay it again (--again), which purges or finds again what the stopped replay wrote, or take it back (--remove); then verify.";case"NO_LOAD":if(/dataset|\bsas\b/i.test(t))return`No replay of this checkpoint into ${n} is recorded on this machine: nothing names the records to verify. Replay it there, then verify.`;break;case"MAX_RECORDS":{let r=/insert (\d+) record\(s\), more than the (\d+)/.exec(t);if(r)return`This replay would create ${l(Number(r[1]))} record(s), more than the ${l(Number(r[2]))} it may: nothing was written. The checkpoint's records or ${n} changed since that count was taken: run its dry run again, and replay with the count it gives (--max-records).`;break}case"REPLACE_LEAVES_RECORDS":{let r=/would leave (\d+) of their records in the org — (.*?): loaded again/.exec(t);if(r)return`Taking back what the replays before created in ${n} would leave ${r[1]} of their records there \u2014 ${r[2]}: replayed again, the checkpoint's records would stand beside them. Nothing was written. Take the replay back first (--remove; --include-changed takes too what was changed since, and what was added under it since), then replay it again.`;break}case"GUARD_REFUSED":if(o.guard==="non-sandbox")return`A replay goes into a sandbox, a scratch org or a Developer Edition org, never into a production org nor a sandbox marked Staging, which hold real data: ${n} is ${o.tier==="staging"?"a sandbox marked Staging":"a production org"}. Nothing was read or written.`;break}return/dataset/i.test(t)?t.replace(/frozen-dataset load/gi,"replay").replace(/the frozen dataset/gi,"the checkpoint").replace(/the dataset/gi,"the checkpoint").replace(/datasets?/gi,"checkpoint"):t}async function bt(e,t){let n=ke(W(t.storeRoot,t.storeNamed)),o=B(t.storeRoot,t.locksDir);o!==void 0&&await Ye(o,t.say);let r=e.file!==void 0?await qe(e,t):await Ke(e,t,n),s=n.folderOf(r.organizationId,r.checkpointId);await ee(n.root);let d={checkpoints:()=>[t.store,...[B(t.storeRoot,t.locksDir)].filter(f=>f!==void 0)],replays:n},i=t.storeNamed?t.storeRoot:void 0,a=L(r.checkpointId,e.target,i),u=r.name!==void 0?`checkpoint '${r.name}'`:`checkpoint ${r.checkpointId}`,m={request:{organizationId:r.organizationId,checkpointId:r.checkpointId,choices:e.choices,...e.config!==void 0?{config:e.config}:{}},stores:d,folder:s,auditStore:ge(n.root,ze),words:Le(u),refusalOf:Me,reword:(f,h,k)=>Ue(f,h,e.target,k),lines:(f,h)=>Qe(f,h,{asked:e,chosen:r,again:a}),question:f=>`Replay ${u} into ${e.target}, creating ${l(Be(f))} record(s) there${e.again?" once what its replays before created there is purged":""}?`,dryRunEnd:f=>f.length>0?[]:[`To replay it: ${a}${et(e)}`],answer:(f,h)=>nt(f,h,{asked:e,chosen:r,again:a})};await he(We(e,t.json),m)}function Be(e){return e.perObject.reduce((t,n)=>t+n.toInsert,0)}function We(e,t){return{step:e.action==="verify"?"verify":e.action==="remove"?"remove":"load",target:e.target,pilot:!1,reload:e.again,dryRun:e.action==="dryRun",writeEncrypted:!1,muteAutomation:e.muteAutomation,acceptAutomation:e.acceptAutomation,...e.checkpointFirst!==void 0?{checkpointFirst:e.checkpointFirst}:{},includeChanged:e.includeChanged,acceptEmails:e.acceptEmails,sweep:e.sweep,sweepList:e.sweepList,...e.sweepLate?{sweepLate:!0}:{},...e.sweepUntied?{sweepUntied:!0}:{},preview:e.preview,...e.maxRecords!==void 0?{maxTotal:e.maxRecords}:{},yes:e.yes,json:t}}async function Ye(e,t){let n=await e.sweep().catch(()=>{});for(let o of n?.checkpoints??[])t(`deleted the checkpoint '${o.name}' (${o.checkpointId}) of a file received, kept until ${b(o.expiresAt)}: its replays stay, and still take back with --remove`)}async function Ke(e,t,n){let o=e.checkpoint??"",r=B(t.storeRoot,t.locksDir),s=new Set,d=[...await t.listAll(),...await r?.list()??[]].filter(h=>{let k=`${h.organizationId.slice(0,15)}/${h.checkpointId}`;return s.has(k)?!1:(s.add(k),!0)}),i=h=>({organizationId:h.organizationId,checkpointId:h.checkpointId,...h.checkpoint?{name:h.checkpoint.name}:{},of:Ge(h)}),a=e.from;if(me(o)){let h=d.filter(g=>g.checkpointId===o&&(a===void 0||!A.test(a)||ue(g.organizationId,a)));if(h.length===1)return i(h[0]);let k=(await n.list({checkpointId:o})).filter(g=>a===void 0||!A.test(a)||ue(g.sourceOrganizationId,a)),R=[...new Set(k.map(g=>g.sourceOrganizationId))];if(h.length===0&&R.length===1){let g=k[0];return{organizationId:g.sourceOrganizationId,checkpointId:o,...g.checkpointName!==void 0?{name:g.checkpointName}:{}}}if(h.length+R.length>1){let g=[...new Set([...h.map(E=>E.organizationId),...R])];throw new y({code:"AMBIGUOUS",message:`Checkpoints of ${g.length} orgs have the id ${o}: name the org it was taken of with --from (${g.join(", ")}). Nothing was run.`},2)}throw new y({code:"NOT_FOUND",message:`No checkpoint ${o} is kept on this machine, nor a replay of it. `+He(t.storeNamed)})}let u=a??"",m=t.checkpointsOf(d,u,A.test(u)?u:void 0),f=t.resolve(d,m,o,u);if("entry"in f)return i(f.entry);throw"ambiguous"in f?new y({code:"AMBIGUOUS",message:f.ambiguous},2):new y({code:"NOT_FOUND",message:f.none})}function ue(e,t){return e.slice(0,15)===t.slice(0,15)}function He(e){return`"${v("checkpoint")} list" names the checkpoints kept, and "${v("checkpoint")} replays" the replays.${e?"":" One kept in another folder is read with --store <folder>."} A file a teammate sent replays with --file <.sfcheckpoint>.`}function Ge(e){let t=e.checkpoint?.org;if(t===void 0)return;let n=t.alias??t.username;return e.why==="refreshed"?`${n} before its refresh${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}`:e.why==="scratchExpired"?`${n}, a scratch org expired since`:n}async function qe(e,t){let n=e.file??"",o=await ae(n);if("refusal"in o)throw new y(o.refusal);let{header:r}=o.read;t.say(`the file holds checkpoint ${r.checkpointId} of org ${r.organizationId}, taken ${b(r.takenAt)}: ${l(r.records)} record(s) of ${l(r.objects)} object(s), exported by SandForge ${r.sandforgeVersion}`);let s={organizationId:r.organizationId,checkpointId:r.checkpointId,file:{path:n,header:r}};if(e.action==="remove")return s;if(e.action!=="verify"){let u=Ze(r,e);if(u!==void 0)throw new y(u)}let d=e.keyEnv!==void 0?Ve(e.keyEnv):await Je(),i=await se({storeRoot:t.storeRoot,...t.locksDir!==void 0?{locksDir:t.locksDir}:{},file:n,key:d,keepDays:e.keepDays,takenOn:{host:be(),pid:process.pid}});if(!i.imported)throw new y(i.refusal);let{checkpoint:a}=i;return t.say(i.outcome==="imported"?`kept checkpoint '${a.name}' of the file on this machine, apart from those it rewinds, to replay it: ${D(t.storeRoot)}, `+(a.expiresAt===null?"until it is deleted":`until ${b(a.expiresAt)} (--keep-days)`):`checkpoint '${a.name}' of the file is kept on this machine already, the same`),{...s,name:a.name,of:a.org.alias??a.org.username}}function Ze(e,t){if(t.choices.mask)return;let n=le({tier:e.orgTier,...e.dataStorageMaxMB!==void 0?{dataStorageMaxMB:e.dataStorageMaxMB}:{},...e.staging?{staging:!0}:{}}),o=`The file holds checkpoint ${e.checkpointId}`;if(n.kind==="real")return{code:"REPLAY_REAL_DATA",message:`${o} of ${n.why==="staging"?"a sandbox marked Staging":`a Partial Copy or Full sandbox, by its data storage (${l(n.dataStorageMaxMB??0)} MB)`}, which may hold real data: it goes into another org masked only. To replay it into ${t.target}, ${F.mask}. Its key was not read, and nothing was kept, read or written.`};if(n.kind==="unknown"&&t.choices.noRealData!==!0)return{code:"REPLAY_COPY_UNKNOWN",message:`${o} of a sandbox, and does not say which: made before SandForge 1.81, it keeps no data storage, and a Partial Copy or a Full sandbox holds production\u2019s records. To replay it into ${t.target}, ${F.mask}, or ${F.noRealData}. Its key was not read, and nothing was kept, read or written.`}}function Ve(e){let t=process.env[e];if(t===void 0||t.trim()==="")throw new y({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let n=C(t);if(n===void 0)throw new y({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return n}async function Je(){let e=await ne("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new y({code:"DECLINED",message:"No key was typed. Nothing was run."});let t=C(e);if(t===void 0)throw new y({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was run."});return t}function Xe(e){let t=e.payload?.replay;return typeof t=="object"&&t!==null?t:void 0}function Qe(e,t,n){let o=Xe(e);if(o===void 0)return t;let{again:r}=n,s=o.target.name,d=o.filesLeft.length>0?` ${l(o.filesLeft.length)} file(s) are not replayed: a checkpoint keeps no file's content.`:"";if(e.type==="frozen:load:preview:response"){let i=n.chosen.of??o.checkpoint.alias??o.checkpoint.organizationId;return[`A replay of checkpoint '${o.checkpoint.name}' (of ${i}, taken ${b(o.checkpoint.takenAt)}) into ${s} would create copies of ${l(o.summary.records.toCreate)} of its records there, parents first, with new Ids; nothing ${s} holds is changed or deleted.${d}`,...t,...xe(o)]}return e.type==="frozen:load:response"?[...t,`To take it back: ${r} --remove`]:t}function et(e){let{choices:t}=e,n=e.checkpointFirst;return[t.objects.length>0?` --objects ${t.objects.join(",")}`:"",...t.excluded.map(o=>` --exclude-object ${o}`),t.owners!=="same"?` --owners ${t.owners}`:"",e.ownerMapFile!==void 0?` --owner-map ${z(e.ownerMapFile)}`:"",...t.link.map(o=>` --link ${o.objectApiName}=${o.fields.join(",")}`),t.customSettings?" --custom-settings":"",t.mask?" --mask":"",t.contactPoints==="kept"?" --keep-contact-points":"",t.noRealData?" --no-real-data":"",e.configFile!==void 0?` --replay-config ${z(e.configFile)}`:"",e.again?" --again":"",e.muteAutomation?" --mute-automation":"",e.acceptAutomation?" --accept-automation":"",e.acceptEmails?" --accept-emails":"",n!==void 0?" --checkpoint-first":"",n?.keepDays!==void 0?` --checkpoint-keep-days ${n.keepDays}`:"",...(n?.excluded??[]).map(o=>` --checkpoint-exclude-object ${o}`),e.maxRecords!==void 0?` --max-records ${e.maxRecords}`:""].join("")}function U(e,t){return e.filter(n=>n.type===t).at(-1)?.payload}var tt=new Set(["tool","step","posted","dataset","checkpoint"]);function nt(e,t,n){let{asked:o,chosen:r,again:s}=n,d=U(e.posted,"frozen:load:preview:response"),i=U(e.posted,"frozen:load:response"),a=i?.replay??d?.replay,u=d?.plan,m=i?.report,f=U(e.posted,"frozen:remove:response")?.result,h=Object.fromEntries(Object.entries(e).filter(([g])=>!tt.has(g))),k=e.checkpoint,R=a?.target.organizationId??t.targetOrgId;return{command:"replay",action:o.action,dryRun:o.action==="dryRun",checkpoint:a?{id:a.checkpoint.checkpointId,name:a.checkpoint.name,organizationId:a.checkpoint.organizationId,takenAt:a.checkpoint.takenAt,tier:a.checkpoint.tier,annex:a.checkpoint.annex}:{id:r.checkpointId,...r.name!==void 0?{name:r.name}:{},organizationId:r.organizationId},target:{alias:o.target,...R!==void 0?{organizationId:Q(R)}:{}},...o.action==="replay"||o.action==="dryRun"?{choices:a?.choices??o.choices}:{},...r.file?{file:r.file.path}:{},...u?{plan:u}:{},...a?{replay:{...a.summary,filesLeft:a.filesLeft,...a.storage?{storage:a.storage}:{},requests:a.requests}}:{},...m?{result:m}:{},...f!==void 0?{removal:f}:{},...h,...k?{checkpointFirst:k}:{},removeWith:`${s} --remove`,...t.refused?{refused:t.refused}:{},...t.ended?{ended:t.ended}:{},exit:t.exit}}function ot(e,t){return{checkpointId:e.checkpointId,...e.checkpointName!==void 0?{checkpointName:e.checkpointName}:{},sourceOrganizationId:e.sourceOrganizationId,...e.takenAt!==void 0?{takenAt:e.takenAt}:{},target:e.target,...e.choices!==void 0?{choices:e.choices}:{},...e.replayedAt!==void 0?{replayedAt:e.replayedAt}:{},inPlace:e.inPlace,inPlaceByObject:e.inPlaceByObject,...e.removed?{removed:!0}:{},removeWith:`${L(e.checkpointId,e.target.name??"<alias>",t)} --remove`}}function rt(e,t,n,o){return e.length===0?[`No replay${n!==void 0?` into ${n}`:""} is kept in ${t}.`]:e.flatMap(r=>{let s=r.target.name??r.target.organizationId,d=r.inPlaceByObject.map(i=>`${i.objectApiName} ${l(i.records)}`).join(", ");return[`${r.checkpointId} ${r.checkpointName!==void 0?`'${r.checkpointName}' `:""}of ${r.sourceOrganizationId}${r.takenAt!==void 0?`, taken ${b(r.takenAt)}`:""} into ${s} (${r.target.organizationId})`+(r.replayedAt!==void 0?` replayed ${b(r.replayedAt)}`:""),r.inPlace>0?` ${l(r.inPlace)} record(s) in place: ${d}`:r.removed?" removed: none of its records is left there":" none of its records is left there",...r.inPlace>0?[` to take it back: ${L(r.checkpointId,r.target.name??"<alias>",o)} --remove`]:[]]})}async function At(e,t){let n=ke(W(t.storeRoot,t.storeNamed)),o=await n.list(e!==void 0&&A.test(e)?{targetOrganizationId:e}:{}),r=e!==void 0&&!A.test(e)?o.filter(d=>d.target.name===e):o,s=t.storeNamed?t.storeRoot:void 0;for(let d of rt(r,n.root,e,s))t.say(d);t.answerJson(r.map(d=>ot(d,s)))}async function Et(e,t){let n;try{n=new x({root:W(t.storeRoot,t.storeNamed)})}catch{return{lines:[],entries:[]}}let o=t.storeNamed?t.storeRoot:void 0,r=[],s=[];for(let d of e){let i=await n.replaysOf(d.organizationId,d.checkpointId).catch(()=>[]),a=pe(i);if(a!==void 0){r.push(` ${a}`);for(let u of de(i))r.push(` to take it back: ${L(u.checkpointId,u.target.name??"<alias>",o)} --remove`),s.push(u)}}return{lines:r,entries:s}}export{Rt as a,$t as b,y as c,vt as d,L as e,je as f,bt as g,ot as h,At as i,Et as j};
|
|
7
|
+
import{y as he}from"./chunk-7DPHZWA4.mjs";import{i as ce,j as x,k as de,l as pe}from"./chunk-CQAFVEKP.mjs";import{l as le,n as F}from"./chunk-JBWJ6UEZ.mjs";import{e as C,i as ae,k as D,l as se}from"./chunk-L4MSL4U7.mjs";import{d as j,f as oe,xb as re,yb as ie}from"./chunk-LYOGCIYD.mjs";import{c as ne}from"./chunk-QROPNEGY.mjs";import{a as v}from"./chunk-SCKUIE3R.mjs";import{$a as J}from"./chunk-AXFD2OH6.mjs";import{L as te,e as X,k as Q,z as ee}from"./chunk-N2HYG3BL.mjs";import{gc as S}from"./chunk-R3OM3X4L.mjs";import{Ra as Z,cb as V}from"./chunk-6QSHWIZI.mjs";import{existsSync as $e,readFileSync as ve}from"node:fs";import{hostname as be}from"node:os";import{join as ge,resolve as T}from"node:path";var Ae=["--custom-settings","--mask","--keep-contact-points","--no-real-data"],Ee=["--objects","--exclude-object","--owners","--owner-map","--link","--replay-config"],Ie=["--again","--accept-emails","--max-records",...j.switches,...j.values],Oe=["--preview","--sweep","--sweep-list",...re,"--include-changed"],Ne=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,A=/^00D[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,me=e=>Z.safeParse(e).success,Se={ownerMap:"--owner-map",objects:"--objects",excluded:"--exclude-object",link:"--link"};function Rt(e,t){let n=c=>e.includes(c),o=c=>{let p=[];for(let w=1;w<e.length;w++){if(e[w]!==c)continue;let $=e[w+1];if($===void 0||$.startsWith("--"))return t(`${c} wants a value.`);p.push($),w++}return p},r=c=>{let p=o(c);return p.length>1&&t(`${c} is given ${p.length} times: give it once.`),p[0]},s=c=>{let p=r(c);if(p!==void 0)return/^\d{1,15}$/.test(p)||t(`${c} takes a whole number, not "${p}".`),Number(p)},d=["--dry-run","--verify","--remove"].filter(n);d.length>1&&t(`Give one of --dry-run, --verify and --remove, not ${d.join(" and ")}. Nothing was run.`);let i=n("--dry-run")?"dryRun":n("--verify")?"verify":n("--remove")?"remove":"replay",a=c=>c.filter(n);if(i==="verify"||i==="remove"){let c=a([...Ae,...Ee]);c.length>0&&t(`${c.join(", ")} ${c.length===1?"is a choice":"are choices"} of a replay and its dry run: --verify reads the choices its last replay was made with, and --remove takes back what it wrote. Nothing was run.`);let p=a(Ie);p.length>0&&t(`${p.join(", ")} goes with a replay or its dry run, not with --${i}. Nothing was run.`)}if(i!=="remove"){let c=a(Oe);c.length>0&&t(`${c.join(", ")} goes with --remove. Nothing was run.`)}n("--sweep")&&n("--sweep-list")&&t("--sweep deletes and --sweep-list only lists: give one of them. Nothing was run."),n("--preview")&&n("--sweep-list")&&t("--preview deletes nothing, and --sweep-list lists what a sweep would take: give --preview without it, or with --sweep. Nothing was run.");let u=ie(e);if("refusal"in u&&t(`${u.refusal} Nothing was run.`),i==="verify"){let c=a(["--mute-automation","--accept-automation"]);c.length>0&&t(`${c.join(", ")} goes with a replay or its removal: a verification only reads. Nothing was run.`)}let m=r("--checkpoint"),f=r("--file");if(m===void 0&&f===void 0)return t("replay needs --checkpoint <id|name> (list names them) or --file <.sfcheckpoint>. Run with --help.");m!==void 0&&f!==void 0&&t("Give --checkpoint or --file, not both. Nothing was run.");let h=r("--from");if(h!==void 0&&m===void 0&&t("--from goes with --checkpoint <name>: it names the org the checkpoint was taken of."),m!==void 0&&!me(m)&&h===void 0&&t(`--checkpoint '${m}' is not a checkpoint's id: a name names one of an org's checkpoints, so give --from <alias|username|00D\u2026>, the org it was taken of, or its id ("${v("checkpoint")} list" names them). Nothing was run.`),f===void 0){let c=a(["--key-env","--keep-days"]);c.length>0&&t(`${c.join(" and ")} goes with --file. Nothing was run.`)}let k=r("--target")??t("replay needs --target <alias>, the org the checkpoint's records go into. Run with --help."),R=o("--objects").flatMap(c=>c.split(",").map(p=>p.trim()).filter(p=>p!=="")),g=o("--exclude-object");for(let[c,p]of[["--objects",R],["--exclude-object",g]]){let w=p.find($=>!Ne.test($));w!==void 0&&t(`${c} takes objects' API names, not "${w}".`)}let E=c=>c.filter((p,w)=>c.findIndex($=>$.toLowerCase()===p.toLowerCase())===w),I=r("--owners")??"same";I!=="same"&&I!=="me"&&t(`--owners takes same or me, not "${I}".`);let we=o("--link").map(c=>{let p=/^([A-Za-z][A-Za-z0-9_]*)=([A-Za-z0-9_,]+)$/.exec(c);return p?{objectApiName:p[1],fields:p[2].split(",").filter(w=>w!=="")}:t(`--link takes Object=Field or Object=Field,Field \u2014 the fields a record of the other org is found by \u2014, not "${c}".`)}),O=r("--owner-map"),Y=O!==void 0?ye("--owner-map",O,t):void 0,Re={owners:I,...Y!==void 0?{ownerMap:Y}:{},customSettings:n("--custom-settings"),mask:n("--mask"),contactPoints:n("--keep-contact-points")?"kept":"neutralized",objects:E(R),excluded:E(g),link:we,...n("--no-real-data")?{noRealData:!0}:{}},P=V.safeParse(Re);if(!P.success){let c=P.error.issues[0],p=String(c?.path[0]??"");return t(`${Se[p]??p}: ${c?.message??"not read"}. Nothing was run.`)}let K=P.data,N=r("--replay-config"),H=N!==void 0?Ce(N,K,t):void 0,_=s("--max-records");_===0&&t('--max-records takes a whole number of 1 or more, not "0". Nothing was run.');let G=Fe(r("--key-env"),t),q=oe(e);return{action:i,...m!==void 0?{checkpoint:m}:{},...h!==void 0?{from:h}:{},...f!==void 0?{file:T(f)}:{},...G!==void 0?{keyEnv:G}:{},keepDays:s("--keep-days")??X,target:k,choices:K,...O!==void 0?{ownerMapFile:T(O)}:{},...H!==void 0?{config:H}:{},...N!==void 0?{configFile:T(N)}:{},again:n("--again"),muteAutomation:n("--mute-automation"),acceptAutomation:n("--accept-automation"),acceptEmails:n("--accept-emails"),...q!==void 0?{checkpointFirst:q}:{},..._!==void 0?{maxRecords:_}:{},preview:n("--preview"),sweep:n("--sweep"),sweepList:n("--sweep-list"),...u,includeChanged:n("--include-changed"),yes:n("--yes")}}function $t(e,t){let n=e.flatMap((r,s)=>r==="--target"?[e[s+1]]:[]);n.length>1&&t(`--target is given ${n.length} times: give it once.`);let o=n[0];return o!==void 0?{target:o}:{}}function ye(e,t,n){try{return JSON.parse(ve(t,"utf8"))}catch(o){return n(`${e}: ${t} does not read as JSON (${o instanceof Error?o.message:String(o)}). Nothing was run.`)}}function Ce(e,t,n){let o=ye("--replay-config",e,n),r=J.safeParse({targetOrgId:"command-line",replay:{organizationId:"00D000000000000AAA",checkpointId:"ck-20000101-000000-0000",choices:t,config:o}});if(!r.success){let s=r.error.issues[0],d=(s?.path??[]).slice(2).join(".");return n(`--replay-config: ${d!==""?`${d}: `:""}${s?.message??"not read"}. It takes the load\u2019s part of a Frozen project\u2019s configuration: requiredFieldDefaults, requiredLookupPlaceholders, picklistRules, defaultPicklistRule, identityKeys, undeletableObjects, duplicateErrorPatterns, mockDetection, protectedOrgIds. Nothing was run.`)}return o}function Fe(e,t){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||C(e)!==void 0?t("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}var ze="cli-store.json";function W(e,t){return t?ge(e,".replays"):ce()}var y=class extends Error{constructor(n,o=1){super(n.message);this.refusal=n;this.code=o;this.name="ReplayStop"}refusal;code};function ke(e){try{return new x({root:e})}catch(t){throw new y({code:"STORE_REFUSED",message:`The replays cannot be kept in ${e}: ${t instanceof Error?t.message:String(t)} Name a store outside any repository with --store <folder>. Nothing was read or written.`})}}function B(e,t){let n=D(e);if(!$e(n))return;let o=te({root:n,...t!==void 0?{locksDir:t}:{}});return"store"in o?o.store:void 0}function z(e){return/^[\w./:@+-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function vt(e,t){return`${v("checkpoint")} replay --file ${z(e)} --target ${t}`}function L(e,t,n){return`${v("checkpoint")} replay --checkpoint ${e} --target ${t}`+(n!==void 0?` --store ${z(n)}`:"")}var l=e=>e.toLocaleString("en-US");function b(e){let t=new Date(Date.parse(e)).toISOString();return`${t.slice(0,10)} ${t.slice(11,16)} UTC`}function M(e,t=8){return e.length<=t?e.join(", "):`${e.slice(0,t).join(", ")} and ${l(e.length-t)} more`}function Le(e){return{run:"replay",done:"replayed",source:e,recordedIn:"for this checkpoint on this machine",remove:"--remove",module:"replay",again:"again",againSubject:{purge:"replayAgain",sweep:"replayAgainSweep"},maybeMasks:"the checkpoint does not say whether its take read them unmasked, so they may hold the masks a user without View Encrypted Data reads, such as ****1234"}}var Pe={fileContentNotKept:()=>"a checkpoint keeps no file's content",notInTarget:(e,t)=>`${t} has no such object: deploy it there, or leave it out (--exclude-object ${e})`,notCreateable:(e,t)=>`${t} lets no one create its records`,excluded:()=>"left out as asked"},_e={objectNotReplayed:e=>`the checkpoint holds the records it names and does not replay them: add ${e.split(".")[0]}'s target with --objects`,objectNotHeld:(e,t)=>`the checkpoint does not hold what it names, and ${t} has no record of that Id`,userNotInTarget:(e,t)=>`${t} has no active standard user for it`},fe={requiredLookupMissing:"a required lookup names a record neither replayed nor in the other org",parentRefused:"a parent of theirs is refused, and no orphan is written",personAccountsUnsupported:"the other org has not turned person accounts on",inactiveCurrency:"their currency is not active in the other org",recordTypeUnavailable:"their record type is one the user who replays may not create"};function je(e){return`${Object.hasOwn(fe,e.reason)?fe[e.reason]:e.reason}${e.path?`: ${e.path}`:""}`}var De={byName:"found by its name",byId:"found by its Id",default:"the other org's default for the user who replays"};function xe(e){let{summary:t}=e,n=e.target.name,o=[],{records:r}=t;r.linkedById>0&&o.push(`${l(r.linkedById)} record(s) ${n} holds under the same Id \u2014 a sandbox copied from the same production \u2014: linked, not changed`),r.linkedByKey>0&&o.push(`${l(r.linkedByKey)} record(s) found in ${n} by the fields --link names: linked, not created`);let s=t.owners,d=[s.reasons.notInTarget>0?`their user is not in ${n}: ${l(s.reasons.notInTarget)}`:"",s.reasons.inactive>0?`their user is inactive in ${n}: ${l(s.reasons.inactive)}`:"",s.reasons.queueMissing>0?`their queue is not in ${n}: ${l(s.reasons.queueMissing)}`:""].filter(Boolean);o.push(`owners: ${l(s.kept)} kept, ${l(s.toRunningUser)} to the user who replays`+(d.length>0?` \u2014 ${d.join("; ")}`:""));for(let i of t.recordTypes)o.push(`record type ${i.object}.${i.recordType}: ${De[i.outcome]} \u2014 ${l(i.records)} record(s)`);for(let i of t.refused)o.push(`refused before anything is written: ${i.object} ${l(i.records)} \u2014 `+je(i));for(let i of t.notReplayed)o.push(`not replayed: ${i.object} ${l(i.records)} \u2014 `+Pe[i.reason](i.object,n));e.filesLeft.length>0&&o.push(`${l(e.filesLeft.length)} file(s) left where they were, a checkpoint keeping no file's content:`,...e.filesLeft.map(i=>` ${i.objectApiName}${i.name!==void 0?` '${i.name}'`:""}`));for(let i of t.lookupsEmptied)o.push(`${i.field}: emptied on ${l(i.records)} record(s) \u2014 `+_e[i.reason](i.field,n));for(let i of t.fieldsNotInTarget)o.push(`${i.object}: ${M(i.fields)} left out \u2014 ${n} does not have them`);t.customSettings&&o.push(`custom settings: ${l(t.customSettings.inserted)} row(s) set up, ${l(t.customSettings.alreadyThere)} already in ${n}, kept as they are`);for(let i of t.currencies.refused)o.push(`${i.code}: ${l(i.records)} record(s) refused \u2014 the currency is not active in ${n}: activate it there, or leave those records out`);if(t.currencies.singleCurrencyTarget&&o.push(`${n} has one currency: amounts are kept as they are, in its currency`),t.standardPricebook==="deduced"?o.push("standard price book: told from the price book entries, the checkpoint naming none"):t.standardPricebook==="ambiguous"&&o.push("standard price book: the price book entries do not tell which it was, and those that need it are refused"),t.masked.fields.length>0&&o.push(`masked: ${M(t.masked.fields)}`),(t.masked.unmaskedFreeText??[]).length>0&&o.push(`not masked, free text the masking does not read: ${M(t.masked.unmaskedFreeText??[])}`),o.push(t.contactPoints==="neutralized"?"emails and phone numbers made unreachable (.invalid, numbers that ring nobody); --keep-contact-points keeps them":"emails and phone numbers kept as they are: they reach the people they name"),(t.archivedActivities??0)>0&&o.push(`${l(t.archivedActivities??0)} archived task(s) and event(s) replayed, which ${n} holds live`),t.degraded.length>0&&o.push((e.checkpoint.annex?`its take could not read ${t.degraded.join(", ")}`:"taken before SandForge 1.81, it keeps no record types, users, queues nor standard price book")+`: the records they name get what ${n} gives them, each said above`),o.push("created and modified dates and users are the replay's own: the platform sets them"),e.storage){let{storage:i}=e;o.push(`data storage: about ${S(i.estimateMB)} MB of the ${S(i.remainingMB)} MB ${n} has left of ${S(i.maxMB)} MB`)}return o}var Te=new Set(["REPLAY_SAME_ORG","REPLAY_REAL_DATA","REPLAY_COPY_UNKNOWN","REPLAY_TOO_MANY","REPLAY_NOTHING","REPLAY_CHECKPOINT_UNUSABLE","REPLAY_NO_PILOT","CHECKPOINT_NOT_FOUND","OWNER_MAP_INACTIVE","OWNER_MAP_UNKNOWN","GUARD_REFUSED","NO_LOAD","TARGET_REFRESHED","LOAD_REMOVED","LOAD_STOPPED"]);function Me(e){let t=String(e.type??""),n=e.payload?.code;if(!(!t.endsWith(":error")||typeof n!="string")&&Te.has(n))return{code:n,message:String(e.payload?.message??"")}}function Ue(e,t,n,o={}){switch(e){case"TARGET_REFRESHED":if(/dataset/i.test(t))return`${n} was refreshed after the last replay: the records it created went with the refresh. Replay the checkpoint again, then verify.`;break;case"LOAD_REMOVED":{let r=/removal of (\S+) took part/.exec(t);if(r)return`The removal of ${r[1]} took part of the records the last replay created and left ${l(Number(o.left??0))} in ${n}: a verification would read the ones it took as missing. Remove what is left (--remove), or replay again (--again), which purges or finds it again; then verify.`;let s=/removed on (\S+?)\.(?:\s|$)/.exec(t);return`The records the last replay created were removed${s?` on ${s[1]}`:""}. Replay the checkpoint again, then verify.`}case"LOAD_STOPPED":return"The last replay stopped part way \u2014 it was cancelled, or failed once it had written \u2014 and wrote no counting contract: a verification would judge it by the one before. Replay it again (--again), which purges or finds again what the stopped replay wrote, or take it back (--remove); then verify.";case"NO_LOAD":if(/dataset|\bsas\b/i.test(t))return`No replay of this checkpoint into ${n} is recorded on this machine: nothing names the records to verify. Replay it there, then verify.`;break;case"MAX_RECORDS":{let r=/insert (\d+) record\(s\), more than the (\d+)/.exec(t);if(r)return`This replay would create ${l(Number(r[1]))} record(s), more than the ${l(Number(r[2]))} it may: nothing was written. The checkpoint's records or ${n} changed since that count was taken: run its dry run again, and replay with the count it gives (--max-records).`;break}case"REPLACE_LEAVES_RECORDS":{let r=/would leave (\d+) of their records in the org — (.*?): loaded again/.exec(t);if(r)return`Taking back what the replays before created in ${n} would leave ${r[1]} of their records there \u2014 ${r[2]}: replayed again, the checkpoint's records would stand beside them. Nothing was written. Take the replay back first (--remove; --include-changed takes too what was changed since, and what was added under it since), then replay it again.`;break}case"GUARD_REFUSED":if(o.guard==="non-sandbox")return`A replay goes into a sandbox, a scratch org or a Developer Edition org, never into a production org nor a sandbox marked Staging, which hold real data: ${n} is ${o.tier==="staging"?"a sandbox marked Staging":"a production org"}. Nothing was read or written.`;break}return/dataset/i.test(t)?t.replace(/frozen-dataset load/gi,"replay").replace(/the frozen dataset/gi,"the checkpoint").replace(/the dataset/gi,"the checkpoint").replace(/datasets?/gi,"checkpoint"):t}async function bt(e,t){let n=ke(W(t.storeRoot,t.storeNamed)),o=B(t.storeRoot,t.locksDir);o!==void 0&&await Ye(o,t.say);let r=e.file!==void 0?await qe(e,t):await Ke(e,t,n),s=n.folderOf(r.organizationId,r.checkpointId);await ee(n.root);let d={checkpoints:()=>[t.store,...[B(t.storeRoot,t.locksDir)].filter(f=>f!==void 0)],replays:n},i=t.storeNamed?t.storeRoot:void 0,a=L(r.checkpointId,e.target,i),u=r.name!==void 0?`checkpoint '${r.name}'`:`checkpoint ${r.checkpointId}`,m={request:{organizationId:r.organizationId,checkpointId:r.checkpointId,choices:e.choices,...e.config!==void 0?{config:e.config}:{}},stores:d,folder:s,auditStore:ge(n.root,ze),words:Le(u),refusalOf:Me,reword:(f,h,k)=>Ue(f,h,e.target,k),lines:(f,h)=>Qe(f,h,{asked:e,chosen:r,again:a}),question:f=>`Replay ${u} into ${e.target}, creating ${l(Be(f))} record(s) there${e.again?" once what its replays before created there is purged":""}?`,dryRunEnd:f=>f.length>0?[]:[`To replay it: ${a}${et(e)}`],answer:(f,h)=>nt(f,h,{asked:e,chosen:r,again:a})};await he(We(e,t.json),m)}function Be(e){return e.perObject.reduce((t,n)=>t+n.toInsert,0)}function We(e,t){return{step:e.action==="verify"?"verify":e.action==="remove"?"remove":"load",target:e.target,pilot:!1,reload:e.again,dryRun:e.action==="dryRun",writeEncrypted:!1,muteAutomation:e.muteAutomation,acceptAutomation:e.acceptAutomation,...e.checkpointFirst!==void 0?{checkpointFirst:e.checkpointFirst}:{},includeChanged:e.includeChanged,acceptEmails:e.acceptEmails,sweep:e.sweep,sweepList:e.sweepList,...e.sweepLate?{sweepLate:!0}:{},...e.sweepUntied?{sweepUntied:!0}:{},preview:e.preview,...e.maxRecords!==void 0?{maxTotal:e.maxRecords}:{},yes:e.yes,json:t}}async function Ye(e,t){let n=await e.sweep().catch(()=>{});for(let o of n?.checkpoints??[])t(`deleted the checkpoint '${o.name}' (${o.checkpointId}) of a file received, kept until ${b(o.expiresAt)}: its replays stay, and still take back with --remove`)}async function Ke(e,t,n){let o=e.checkpoint??"",r=B(t.storeRoot,t.locksDir),s=new Set,d=[...await t.listAll(),...await r?.list()??[]].filter(h=>{let k=`${h.organizationId.slice(0,15)}/${h.checkpointId}`;return s.has(k)?!1:(s.add(k),!0)}),i=h=>({organizationId:h.organizationId,checkpointId:h.checkpointId,...h.checkpoint?{name:h.checkpoint.name}:{},of:Ge(h)}),a=e.from;if(me(o)){let h=d.filter(g=>g.checkpointId===o&&(a===void 0||!A.test(a)||ue(g.organizationId,a)));if(h.length===1)return i(h[0]);let k=(await n.list({checkpointId:o})).filter(g=>a===void 0||!A.test(a)||ue(g.sourceOrganizationId,a)),R=[...new Set(k.map(g=>g.sourceOrganizationId))];if(h.length===0&&R.length===1){let g=k[0];return{organizationId:g.sourceOrganizationId,checkpointId:o,...g.checkpointName!==void 0?{name:g.checkpointName}:{}}}if(h.length+R.length>1){let g=[...new Set([...h.map(E=>E.organizationId),...R])];throw new y({code:"AMBIGUOUS",message:`Checkpoints of ${g.length} orgs have the id ${o}: name the org it was taken of with --from (${g.join(", ")}). Nothing was run.`},2)}throw new y({code:"NOT_FOUND",message:`No checkpoint ${o} is kept on this machine, nor a replay of it. `+He(t.storeNamed)})}let u=a??"",m=t.checkpointsOf(d,u,A.test(u)?u:void 0),f=t.resolve(d,m,o,u);if("entry"in f)return i(f.entry);throw"ambiguous"in f?new y({code:"AMBIGUOUS",message:f.ambiguous},2):new y({code:"NOT_FOUND",message:f.none})}function ue(e,t){return e.slice(0,15)===t.slice(0,15)}function He(e){return`"${v("checkpoint")} list" names the checkpoints kept, and "${v("checkpoint")} replays" the replays.${e?"":" One kept in another folder is read with --store <folder>."} A file a teammate sent replays with --file <.sfcheckpoint>.`}function Ge(e){let t=e.checkpoint?.org;if(t===void 0)return;let n=t.alias??t.username;return e.why==="refreshed"?`${n} before its refresh${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}`:e.why==="scratchExpired"?`${n}, a scratch org expired since`:n}async function qe(e,t){let n=e.file??"",o=await ae(n);if("refusal"in o)throw new y(o.refusal);let{header:r}=o.read;t.say(`the file holds checkpoint ${r.checkpointId} of org ${r.organizationId}, taken ${b(r.takenAt)}: ${l(r.records)} record(s) of ${l(r.objects)} object(s), exported by SandForge ${r.sandforgeVersion}`);let s={organizationId:r.organizationId,checkpointId:r.checkpointId,file:{path:n,header:r}};if(e.action==="remove")return s;if(e.action!=="verify"){let u=Ze(r,e);if(u!==void 0)throw new y(u)}let d=e.keyEnv!==void 0?Ve(e.keyEnv):await Je(),i=await se({storeRoot:t.storeRoot,...t.locksDir!==void 0?{locksDir:t.locksDir}:{},file:n,key:d,keepDays:e.keepDays,takenOn:{host:be(),pid:process.pid}});if(!i.imported)throw new y(i.refusal);let{checkpoint:a}=i;return t.say(i.outcome==="imported"?`kept checkpoint '${a.name}' of the file on this machine, apart from those it rewinds, to replay it: ${D(t.storeRoot)}, `+(a.expiresAt===null?"until it is deleted":`until ${b(a.expiresAt)} (--keep-days)`):`checkpoint '${a.name}' of the file is kept on this machine already, the same`),{...s,name:a.name,of:a.org.alias??a.org.username}}function Ze(e,t){if(t.choices.mask)return;let n=le({tier:e.orgTier,...e.dataStorageMaxMB!==void 0?{dataStorageMaxMB:e.dataStorageMaxMB}:{},...e.staging?{staging:!0}:{}}),o=`The file holds checkpoint ${e.checkpointId}`;if(n.kind==="real")return{code:"REPLAY_REAL_DATA",message:`${o} of ${n.why==="staging"?"a sandbox marked Staging":`a Partial Copy or Full sandbox, by its data storage (${l(n.dataStorageMaxMB??0)} MB)`}, which may hold real data: it goes into another org masked only. To replay it into ${t.target}, ${F.mask}. Its key was not read, and nothing was kept, read or written.`};if(n.kind==="unknown"&&t.choices.noRealData!==!0)return{code:"REPLAY_COPY_UNKNOWN",message:`${o} of a sandbox, and does not say which: made before SandForge 1.81, it keeps no data storage, and a Partial Copy or a Full sandbox holds production\u2019s records. To replay it into ${t.target}, ${F.mask}, or ${F.noRealData}. Its key was not read, and nothing was kept, read or written.`}}function Ve(e){let t=process.env[e];if(t===void 0||t.trim()==="")throw new y({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let n=C(t);if(n===void 0)throw new y({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return n}async function Je(){let e=await ne("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new y({code:"DECLINED",message:"No key was typed. Nothing was run."});let t=C(e);if(t===void 0)throw new y({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was run."});return t}function Xe(e){let t=e.payload?.replay;return typeof t=="object"&&t!==null?t:void 0}function Qe(e,t,n){let o=Xe(e);if(o===void 0)return t;let{again:r}=n,s=o.target.name,d=o.filesLeft.length>0?` ${l(o.filesLeft.length)} file(s) are not replayed: a checkpoint keeps no file's content.`:"";if(e.type==="frozen:load:preview:response"){let i=n.chosen.of??o.checkpoint.alias??o.checkpoint.organizationId;return[`A replay of checkpoint '${o.checkpoint.name}' (of ${i}, taken ${b(o.checkpoint.takenAt)}) into ${s} would create copies of ${l(o.summary.records.toCreate)} of its records there, parents first, with new Ids; nothing ${s} holds is changed or deleted.${d}`,...t,...xe(o)]}return e.type==="frozen:load:response"?[...t,`To take it back: ${r} --remove`]:t}function et(e){let{choices:t}=e,n=e.checkpointFirst;return[t.objects.length>0?` --objects ${t.objects.join(",")}`:"",...t.excluded.map(o=>` --exclude-object ${o}`),t.owners!=="same"?` --owners ${t.owners}`:"",e.ownerMapFile!==void 0?` --owner-map ${z(e.ownerMapFile)}`:"",...t.link.map(o=>` --link ${o.objectApiName}=${o.fields.join(",")}`),t.customSettings?" --custom-settings":"",t.mask?" --mask":"",t.contactPoints==="kept"?" --keep-contact-points":"",t.noRealData?" --no-real-data":"",e.configFile!==void 0?` --replay-config ${z(e.configFile)}`:"",e.again?" --again":"",e.muteAutomation?" --mute-automation":"",e.acceptAutomation?" --accept-automation":"",e.acceptEmails?" --accept-emails":"",n!==void 0?" --checkpoint-first":"",n?.keepDays!==void 0?` --checkpoint-keep-days ${n.keepDays}`:"",...(n?.excluded??[]).map(o=>` --checkpoint-exclude-object ${o}`),e.maxRecords!==void 0?` --max-records ${e.maxRecords}`:""].join("")}function U(e,t){return e.filter(n=>n.type===t).at(-1)?.payload}var tt=new Set(["tool","step","posted","dataset","checkpoint"]);function nt(e,t,n){let{asked:o,chosen:r,again:s}=n,d=U(e.posted,"frozen:load:preview:response"),i=U(e.posted,"frozen:load:response"),a=i?.replay??d?.replay,u=d?.plan,m=i?.report,f=U(e.posted,"frozen:remove:response")?.result,h=Object.fromEntries(Object.entries(e).filter(([g])=>!tt.has(g))),k=e.checkpoint,R=a?.target.organizationId??t.targetOrgId;return{command:"replay",action:o.action,dryRun:o.action==="dryRun",checkpoint:a?{id:a.checkpoint.checkpointId,name:a.checkpoint.name,organizationId:a.checkpoint.organizationId,takenAt:a.checkpoint.takenAt,tier:a.checkpoint.tier,annex:a.checkpoint.annex}:{id:r.checkpointId,...r.name!==void 0?{name:r.name}:{},organizationId:r.organizationId},target:{alias:o.target,...R!==void 0?{organizationId:Q(R)}:{}},...o.action==="replay"||o.action==="dryRun"?{choices:a?.choices??o.choices}:{},...r.file?{file:r.file.path}:{},...u?{plan:u}:{},...a?{replay:{...a.summary,filesLeft:a.filesLeft,...a.storage?{storage:a.storage}:{},requests:a.requests}}:{},...m?{result:m}:{},...f!==void 0?{removal:f}:{},...h,...k?{checkpointFirst:k}:{},removeWith:`${s} --remove`,...t.refused?{refused:t.refused}:{},...t.ended?{ended:t.ended}:{},exit:t.exit}}function ot(e,t){return{checkpointId:e.checkpointId,...e.checkpointName!==void 0?{checkpointName:e.checkpointName}:{},sourceOrganizationId:e.sourceOrganizationId,...e.takenAt!==void 0?{takenAt:e.takenAt}:{},target:e.target,...e.choices!==void 0?{choices:e.choices}:{},...e.replayedAt!==void 0?{replayedAt:e.replayedAt}:{},inPlace:e.inPlace,inPlaceByObject:e.inPlaceByObject,...e.removed?{removed:!0}:{},removeWith:`${L(e.checkpointId,e.target.name??"<alias>",t)} --remove`}}function rt(e,t,n,o){return e.length===0?[`No replay${n!==void 0?` into ${n}`:""} is kept in ${t}.`]:e.flatMap(r=>{let s=r.target.name??r.target.organizationId,d=r.inPlaceByObject.map(i=>`${i.objectApiName} ${l(i.records)}`).join(", ");return[`${r.checkpointId} ${r.checkpointName!==void 0?`'${r.checkpointName}' `:""}of ${r.sourceOrganizationId}${r.takenAt!==void 0?`, taken ${b(r.takenAt)}`:""} into ${s} (${r.target.organizationId})`+(r.replayedAt!==void 0?` replayed ${b(r.replayedAt)}`:""),r.inPlace>0?` ${l(r.inPlace)} record(s) in place: ${d}`:r.removed?" removed: none of its records is left there":" none of its records is left there",...r.inPlace>0?[` to take it back: ${L(r.checkpointId,r.target.name??"<alias>",o)} --remove`]:[]]})}async function At(e,t){let n=ke(W(t.storeRoot,t.storeNamed)),o=await n.list(e!==void 0&&A.test(e)?{targetOrganizationId:e}:{}),r=e!==void 0&&!A.test(e)?o.filter(d=>d.target.name===e):o,s=t.storeNamed?t.storeRoot:void 0;for(let d of rt(r,n.root,e,s))t.say(d);t.answerJson(r.map(d=>ot(d,s)))}async function Et(e,t){let n;try{n=new x({root:W(t.storeRoot,t.storeNamed)})}catch{return{lines:[],entries:[]}}let o=t.storeNamed?t.storeRoot:void 0,r=[],s=[];for(let d of e){let i=await n.replaysOf(d.organizationId,d.checkpointId).catch(()=>[]),a=pe(i);if(a!==void 0){r.push(` ${a}`);for(let u of de(i))r.push(` to take it back: ${L(u.checkpointId,u.target.name??"<alias>",o)} --remove`),s.push(u)}}return{lines:r,entries:s}}export{Rt as a,$t as b,y as c,vt as d,L as e,je as f,bt as g,ot as h,At as i,Et as j};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{h as a,i as b,j as c,k as d,l as e}from"./chunk-
|
|
7
|
+
import{h as a,i as b,j as c,k as d,l as e}from"./chunk-CQAFVEKP.mjs";import"./chunk-PDRXM5WN.mjs";import"./chunk-UV74P4H2.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-N2HYG3BL.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-ISOSTAJR.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as REPLAY_RECORD_FILE,c as ReplayStore,b as defaultReplayStoreRoot,d as replaysInPlace,e as replaysInPlaceWords};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{b as c,j as o,k as d}from"./chunk-
|
|
7
|
+
import{b as c,j as o,k as d}from"./chunk-OUU47Y7A.mjs";import{b as i}from"./chunk-CA5NAXSU.mjs";import{o as a}from"./chunk-6QSHWIZI.mjs";var u=6e4,g=class{tokenCache=new Map;sfdxBridge;setSfdxBridge(e){this.sfdxBridge=e}async authenticate(e){switch(e.method){case"oauth_web":return this.authenticateOAuth(e);case"oauth_device":return{success:!1,error:"OAuth device flow handled via DeviceLogin and SfdxBridge.loginWithRefreshToken()"};case"jwt":return this.authenticateJwt(e);case"usernamePassword":return this.authenticateUsernamePassword(e);case"sfdx_import":return this.importFromSfdx(e.username);default:return{success:!1,error:`Unsupported auth method: ${e.method}`}}}buildConnectionConfig(e,r){return{loginUrl:e.loginUrl,clientId:e.clientId,clientSecret:e.clientSecret,accessToken:r.accessToken,refreshToken:r.refreshToken,instanceUrl:r.instanceUrl,username:e.username}}async validateConnection(e,r){let t=await o({accessToken:e,instanceUrl:r}),{identity:s,orgResult:h}=await c(t,async()=>({identity:await t.identity(),orgResult:await t.query(`SELECT Id, Name, OrganizationType, IsSandbox FROM Organization LIMIT ${a.singleRecord}`)})),n=h.records[0];return{userId:s.user_id,username:s.username,displayName:s.display_name,orgId:n.Id,orgName:n.Name,orgType:n.OrganizationType,isSandbox:n.IsSandbox}}isTokenValid(e){let r=this.tokenCache.get(e);return r?Date.now()<r.expiresAt:!1}cacheToken(e,r,t){this.tokenCache.set(e,{token:r,expiresAt:Date.now()+t})}getCachedToken(e){let r=this.tokenCache.get(e);if(!r||Date.now()>=r.expiresAt){this.tokenCache.delete(e);return}return r.token}clearTokenCache(e){this.tokenCache.delete(e)}clearAllTokens(){this.tokenCache.clear()}async authenticateOAuth(e){return{success:!1,error:"OAuth handled via SfdxBridge.loginWeb()"}}async authenticateJwt(e){return{success:!1,error:"JWT handled via SfdxBridge.loginJwt()"}}async authenticateUsernamePassword(e){if(!e.username||!e.password)return{success:!1,error:"Username and password are required"};try{let r=await o({loginUrl:e.loginUrl}),t=await d(r.login(e.username,e.password+(e.securityToken??"")),u,`${new URL(e.loginUrl).host} did not answer within ${u/1e3} s: check that this machine reaches it, through its proxy if it has one`);return{success:!0,accessToken:r.accessToken??void 0,instanceUrl:r.instanceUrl,userId:t.id,orgId:t.organizationId}}catch(r){return{success:!1,error:`Login failed: ${i(r)}`}}}async importFromSfdx(e){if(!this.sfdxBridge)return{success:!1,error:"SFDX bridge not configured"};if(!e)return{success:!1,error:"An SFDX import needs the username of the org to import"};try{let r=await this.sfdxBridge.findOrg(e);return r?{success:!0,accessToken:r.credentials.accessToken,instanceUrl:r.credentials.instanceUrl,orgId:r.org.orgId}:{success:!1,error:`No connected org for ${e} found in SF CLI`}}catch(r){return{success:!1,error:`SFDX import failed: ${i(r)}`}}}};export{g as a};
|
|
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{H as p,d as u,k as d,z as h}from"./chunk-
|
|
7
|
+
import{H as p,d as u,k as d,z as h}from"./chunk-N2HYG3BL.mjs";import{b as c}from"./chunk-CA5NAXSU.mjs";import{db as a}from"./chunk-6QSHWIZI.mjs";import{randomBytes as E}from"node:crypto";import{open as k,readFile as b,rename as I,rm as T}from"node:fs/promises";import{dirname as l,join as m}from"node:path";var f="rewinds.ndjson",C=400,O=200;function P(e,n){return m(e,d(n),f)}function R(e){return m(l(e.dir),f)}async function y(e,n,t,i={maxLines:C,keptLines:O}){if(d(t.organizationId)!==n.organizationId)throw new p("invalid","A rewind is kept in its org\u2019s ledger, under its lock.");let r=a.safeParse(t);if(!r.success)throw new p("invalid","A line of the rewind ledger does not parse.");await h(l(e));let o=await w(e),x=o!==""&&!o.endsWith(`
|
|
8
8
|
`)?`
|
|
9
9
|
`:"",s=await k(e,"a",u);try{await s.writeFile(`${x}${JSON.stringify(r.data)}
|
|
10
10
|
`,"utf8"),await s.sync()}finally{await s.close()}L(o).length+1>i.maxLines&&await A(e,i.keptLines)}async function A(e,n){let t=L(await w(e)).slice(-n),i=`${e}.${process.pid}-${E(4).toString("hex")}.tmp`,r=await k(i,"wx",u);try{try{await r.writeFile(t.map(o=>`${o}
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a as v}from"./chunk-SRPWW4A2.mjs";import"./chunk-4TLYUZD5.mjs";import{
|
|
7
|
+
import{a as v}from"./chunk-SRPWW4A2.mjs";import"./chunk-4TLYUZD5.mjs";import{ic as D}from"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";function x(e){return{async retrieve(n){return{id:(await e.metadata.retrieve(n)).id}},checkRetrieveStatus:n=>e.metadata.checkRetrieveStatus(n),async deploy(n,t){return{id:(await e.metadata.deploy(n,t)).id}},checkDeployStatus:(n,t)=>e.metadata.checkDeployStatus(n,t)}}var N={pollMs:3e3,retrieveTimeoutMs:D.retrieve*6e4,deployTimeoutMs:D.deploy*6e4,sleep:e=>new Promise(n=>setTimeout(n,e)),now:Date.now},b=class extends Error{constructor(t,o,s,a){super(t==="deployment"?`Deployment ${o} was still ${s} after ${a} min; it goes on in the target org, and Setup \u203A Deployment Status follows it.`:`Retrieval ${o} was still ${s} after ${a} min; nothing was deployed.`);this.kind=t;this.asyncId=o;this.status=s;this.name="DeploymentStillRunning"}kind;asyncId;status};function d(e,n){return`${e}\0${k(n)}`}function k(e){try{return decodeURIComponent(e)}catch{return e}}function g(e){return e==null?[]:Array.isArray(e)?e:[e]}function R(e){return e===!0||e==="true"}function h(e){if(e==null||e==="")return;let n=Number(e);return Number.isFinite(n)?n:void 0}var P=/^Entity of type '(.+?)' named '(.+)' cannot be found$/;async function M(e,n,t,o){let s=new Map;for(let{componentType:i,fullName:m}of t)s.set(i,[...s.get(i)??[],m]);let a={apiVersion:Number(n),singlePackage:!0,unpackaged:{objectPermissions:[],types:[...s].map(([i,m])=>({members:m,name:i})),version:n}},{id:p}=await e.retrieve(a),u=o.now();for(;;){let i=await e.checkRetrieveStatus(p);if(i.done){if(i.success===!1||i.status==="Failed")throw new Error(`Retrieval ${p} from the source failed: ${i.errorMessage??i.status??"no reason given"}`);return i}if(o.now()-u>=o.retrieveTimeoutMs)throw new b("retrieval",p,i.status??"running",Math.round(o.retrieveTimeoutMs/6e4));await o.sleep(o.pollMs)}}async function I(e,n,t,o={}){let s=o.waiting??N;o.onProgress?.({step:"retrieve",done:0,total:t.length});let a=await M(e,n,t,s),p=new Map(t.map(l=>[d(l.componentType,l.fullName),l])),u=new Map,i=[];for(let l of g(a.messages)){let f=l.problem??"",T=P.exec(f),y=T?p.get(d(T[1],T[2])):void 0;y?u.set(d(y.componentType,y.fullName),{...y,problem:f}):f&&i.push(l.fileName?`${l.fileName}: ${f}`:f)}let m=t.filter(l=>!u.has(d(l.componentType,l.fullName))),r=a;m.length===0?r={...a,zipFile:""}:u.size>0&&(r=await M(e,n,m,s)),o.onProgress?.({step:"retrieve",done:m.length,total:t.length});let c=g(r.fileProperties).filter(l=>v(l)).map(l=>p.get(d(l.type??"",l.fullName??""))).filter(l=>l!==void 0);return{zipFile:r.zipFile??"",retrieved:m,missing:[...u.values()],managed:c,problems:i}}function A(e,n,t){return{allowMissingFiles:!1,autoUpdatePackage:!1,checkOnly:e,ignoreWarnings:!1,performRetrieve:!1,purgeOnDelete:!1,rollbackOnError:!0,...n==="RunSpecifiedTests"?{runTests:[...t]}:{},singlePackage:!0,testLevel:n}}async function E(e,n,t,o={}){let s=o.waiting??N,{id:a}=await e.deploy(n,t),p=s.now();for(;;){let u=await e.checkDeployStatus(a,!1);if(u.done)return e.checkDeployStatus(a,!0);if(o.onProgress?.(w(u)),s.now()-p>=s.deployTimeoutMs)throw new b("deployment",a,u.status??"running",Math.round(s.deployTimeoutMs/6e4));await s.sleep(s.pollMs)}}function w(e){let n=e.numberTestsTotal??0,t=e.numberComponentsTotal??0,o=(e.numberComponentsDeployed??0)+(e.numberComponentErrors??0);return n>0&&o>=t?{step:"tests",done:(e.numberTestsCompleted??0)+(e.numberTestErrors??0),total:n}:{step:"components",done:o,total:t}}function C(e){let n=/line (\d+), column \d+/.exec(e??"");return n?Number(n[1]):void 0}function O(e){let n=h(e.lineNumber),t=h(e.columnNumber),o=e.problemType==="Warning"||e.problemType==="Error"?e.problemType:void 0,s={componentType:e.componentType??"",fullName:e.fullName??"",...e.fileName?{fileName:e.fileName}:{}};if(!R(e.success))return{...s,outcome:"failed",...e.problem?{problem:e.problem}:{},...o?{problemType:o}:{},...n!==void 0?{line:n}:{},...t!==void 0?{column:t}:{}};let a=R(e.created)?"created":R(e.changed)?"changed":"unchanged";return{...s,outcome:a}}function $(e,n,t){let o=e?.details??void 0,s=new Map,a=[...g(o?.componentFailures),...g(o?.componentSuccesses)];for(let r of a){if(!r.componentType&&r.fullName==="package.xml")continue;let c=O(r),l=d(c.componentType,c.fullName);s.has(l)||s.set(l,c)}let p=n.missing.map(r=>({componentType:r.componentType,fullName:r.fullName,outcome:"not_retrieved",...r.problem?{problem:r.problem}:{}})),u=o?.runTestResult??void 0,i=g(u?.failures).map(r=>{let c=C(r.stackTrace);return{className:r.name??"",...r.methodName?{methodName:r.methodName}:{},message:r.message??"",...r.stackTrace?{stackTrace:r.stackTrace}:{},...c!==void 0?{line:c}:{}}}),m=g(u?.codeCoverageWarnings).map(r=>r.name?`${r.name}: ${r.message??""}`:r.message??"").filter(r=>r!=="");return{...e?.id?{deployId:e.id}:{},checkOnly:t.checkOnly,status:e?.status??"NotStarted",success:e?.success===!0&&n.missing.length===0,...e?.errorMessage?{errorMessage:e.errorMessage}:{},sourceOrgId:t.sourceOrgId,targetOrgId:t.targetOrgId,testLevel:t.testLevel,runTests:[...t.runTests],components:[...s.values(),...p],counts:{componentsTotal:e?.numberComponentsTotal??0,componentsDeployed:e?.numberComponentsDeployed??0,componentErrors:e?.numberComponentErrors??0,testsTotal:e?.numberTestsTotal??0,testsCompleted:e?.numberTestsCompleted??0,testErrors:e?.numberTestErrors??0},testFailures:i,coverageWarnings:m,...n.problems.length>0?{retrieveProblems:[...n.problems]}:{},...e?.startDate?{startedAt:e.startDate}:{},...e?.completedDate?{completedAt:e.completedDate}:{}}}export{N as DEFAULT_WAITING,b as DeploymentStillRunning,A as deployOptions,E as deployPackage,$ as deploymentReport,x as metadataApiOf,I as retrieveComponents};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{Zb as P,bc as v,ec as S}from"./chunk-R3OM3X4L.mjs";import{a as A,b as E}from"./chunk-VV3B6IC3.mjs";import{b as R}from"./chunk-CA5NAXSU.mjs";import{Rd as m,be as h,ee as c}from"./chunk-6QSHWIZI.mjs";import{b,f,k as w,l as p}from"./chunk-WZQEK4WT.mjs";var k="Messaging.reserveSingleEmailCapacity(1);",M="System.NoAccessException: The organization is not permitted to send email",x=`/tooling/executeAnonymous?anonymousBody=${encodeURIComponent(k)}`,I=`/query?q=${encodeURIComponent("SELECT PermissionsEmailSingle FROM UserPermissionAccess")}`,L=3e4,$=p({compiled:f(),success:f(),compileProblem:b().nullish(),exceptionMessage:b().nullish()}).loose(),O=p({records:w(p({PermissionsEmailSingle:f().optional()}).loose())}).loose(),V={reading:{unread:"SandForge runs no Apex in a production org"},requests:0};function U(e){return e%1e3===0?`${e/1e3} s`:`${e} ms`}function T(e,n){return e instanceof A?`the org did not answer within ${U(n)}`:`the org refused it: ${R(e)}`}function _(e){let n=$.safeParse(e);if(!n.success)return{unread:"its answer is not one anonymous Apex gives"};let{compiled:t,success:s,compileProblem:r,exceptionMessage:i}=n.data;if(!t)return{unread:`it did not compile${r?`: ${r}`:""}`};if(s)return{level:"all"};let a=i?.trim();return a===M?{refused:!0}:{unread:a?`the org answered: ${a}`:"it failed, and the org did not say why"}}async function Y(e,n={}){let t=n.timeoutMs??L,s=u=>new E(t).withTimeout("forge:deliverability",()=>e.request({method:"GET",url:u})),r;try{r=await s(x)}catch(u){return{reading:{unread:T(u,t)},requests:1}}let i=_(r);if(!("refused"in i))return{reading:i,requests:1};let a="so the org's refusal does not say how it is set",d;try{d=await s(I)}catch(u){return{reading:{unread:`whether the user the run writes as may send email could not be read (${T(u,t)}), ${a}`},requests:2}}let l=O.safeParse(d),o=l.success?l.data.records[0]?.PermissionsEmailSingle:void 0;return o===!0?{reading:{level:"withheld"},requests:2}:{reading:{unread:o===!1?`the user the run writes as may not send email (Send Email), ${a}`:`the org did not say whether the user the run writes as may send email, ${a}`},requests:2}}async function F(e){let n=m(e.running,{applyAssignmentRules:e.applyAssignmentRules,writes:e.writes}),t=P(e.running.automation.unread??[],{applyAssignmentRules:e.applyAssignmentRules===!0}),s=t!==void 0?{sendersUnread:t}:{};if(n.length===0&&t===void 0)return{senders:n};let r;try{r=await e.read()}catch(i){r={reading:{unread:R(i)},requests:1}}return{senders:n,...s,read:r}}function N(e,n={}){let t=i=>`${i.objectApiName}\0${i.kind}\0${i.name}`,s=m(c(e,void 0,n.writes),n),r=new Set(m(c(e,h(e,n.writes),n.writes),n).map(t));return s.filter(i=>!r.has(t(i)))}function q(e,n){let t=new Set([...n.assigned,...n.held]);return{assign:e.assign.filter(s=>t.has(s.permissionSet))}}var z=["flows","processes","workflowRules"];async function Q(e){let{plan:n,writes:t,applyAssignmentRules:s,read:r,target:i,run:a}=e,d=typeof r.unread=="string"?void 0:r,l=s===!0?{applyAssignmentRules:s}:{},o=await F({running:d?c(d,n,t):{automation:{objects:[],unread:z.map(y=>({part:y,reason:String(r.unread)}))},firing:[]},...l,writes:t,read:e.readDeliverability}),u=e.mayMute===!0&&n===void 0&&d!==void 0&&o.senders.length>0?N(d,{...l,writes:t}):[],g=o.read?.reading;return{ofRun:o,gate:v({senders:o.senders,...o.sendersUnread!==void 0?{sendersUnread:o.sendersUnread}:{},...g!==void 0?{reading:g}:{},accepted:e.accepted,target:i,run:a,muteQuiets:u,keepsAddresses:e.keepsAddresses===!0}),afterLease:(y,D)=>{if(!(n===void 0||d===void 0))return S({planned:o.senders,held:m(c(d,q(n,y),t),{...l,writes:t}),...g!==void 0?{reading:g}:{},accepted:D,target:i,run:a})}}}export{L as a,V as b,Y as c,F as d,N as e,q as f,Q as g};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a as R}from"./chunk-CE6ZDGBB.mjs";import{F as g,G as u,K as w,N as m,O as I,P as k}from"./chunk-
|
|
7
|
+
import{a as R}from"./chunk-CE6ZDGBB.mjs";import{F as g,G as u,K as w,N as m,O as I,P as k}from"./chunk-2GSMHGIV.mjs";import{b as h}from"./chunk-CA5NAXSU.mjs";import{g as T}from"./chunk-ISOSTAJR.mjs";import{vc as y}from"./chunk-6QSHWIZI.mjs";var b="Opportunity",v=new Set(["Id","OpportunityId",u,"IsPrimary"]),O=200,l=s=>s.slice(0,15);function S(s){return`The contact roles the platform wrote with the run's opportunities were not looked up, so written as generated: an opportunity may hold the role of its contact twice. ${s}`}var P=class{constructor(e){this.deps=e}deps;sentWith=new Map;untold;linkedIds=[];said;unread;alike=0;opportunitiesWritten(e,d){let r=t=>{let n=t?.[u];return typeof n=="string"&&n!==""?n:void 0},o=d.rows&&(d.rows.length===e.length||d.stopped)?d.rows:void 0;if(!o){d.successIds.length>0&&e.some(t=>r(t))&&(this.untold??="The opportunities' insert did not say which record each id it answered is.");return}o.forEach((t,n)=>{let a=r(e[n]);if(!(!t.id||a===void 0)){if(t.unmatched){this.untold??="The opportunities' insert did not say which record each id it answered is.";return}this.sentWith.set(l(t.id),a)}})}async link(e){if(e.length>0&&this.untold!==void 0&&(this.unread??=this.untold),this.sentWith.size===0||e.length===0)return new Map;let d=e.map(i=>({OpportunityId:i.OpportunityId,[u]:i[u],IsPrimary:i.IsPrimary})),r=i=>this.sentWith.get(l(i)),o=this.deps.readTarget;if(!o)return W(d,r)&&(this.unread??="This run cannot read the target."),new Map;let t;try{t=await k(o,d,r,A(e))}catch(i){return this.unread??=h(i),new Map}let{found:n,alike:a}=t;this.alike+=a.length;for(let i of[...n.keys(),...a])this.sentWith.delete(l(String(e[i].OpportunityId)));return n.size>0&&await this.give(e,n),n}async give(e,d){let r=this.said??={records:0,given:0},o=[];for(let[n,a]of d){let i=String(a.Id);this.linkedIds.push(i),r.records++;let p=Object.entries(e[n]??{}).filter(([f,c])=>!v.has(f)&&c!==null&&c!==void 0&&String(a[f]??"")!==String(c));p.length>0&&o.push({Id:i,...Object.fromEntries(p)})}if(o.length===0)return;let t=n=>{r.refusal??=n};if(!this.deps.update)return t("This run cannot update the target.");for(let n=0;n<o.length;n+=O){if(this.deps.stopped())return t("The run was stopped before they were given them.");let a=o.slice(n,n+O),i;try{i=await this.deps.update(this.deps.orgId,g,a)}catch(p){t(h(p));continue}a.forEach((p,f)=>{let c=i[f];c?.success?r.given++:t(c?.error??"The org gave no answer for it.")})}}resultOf(e){return e!==g?{linkedIds:[],notes:[]}:{linkedIds:this.linkedIds,...this.said?{writtenByThePlatform:{...this.said}}:{},notes:[...this.unread!==void 0?[S(this.unread)]:[],...this.alike>0?[m(this.alike,"generated")]:[]]}}};function A(s){return[...new Set(s.flatMap(e=>Object.keys(e)))].filter(e=>!v.has(e))}function W(s,e){return s.some(d=>{let r=d.OpportunityId,o=d[u];if(typeof r!="string"||typeof o!="string")return!1;let t=e(r);return t!==void 0&&l(t)===l(o)})}function j(){let s=new Map,e=0;return{inserted(d,r,o){d===b&&r.forEach((t,n)=>{let a=t[u],i=o[n];i!==void 0&&typeof a=="string"&&a!==""&&s.set(i,a)})},readTarget:async d=>{let r=w(d);if(!r)throw new Error("A dry run reads nothing else of the target here.");let o=new Date().toISOString();return r.opportunities.flatMap(t=>{let n=s.get(t);return n===void 0?[]:[I({...Object.fromEntries(r.fields.map(a=>[a,null])),Id:`dry-role-${e++}`,OpportunityId:t,[u]:n,...r.fields.includes("IsPrimary")?{IsPrimary:!0}:{}},o)]})},update:async(d,r,o)=>o.map(()=>({success:!0}))}}function _(s){if(s)return`${s.records} record(s) linked to the contact role the platform wrote with their opportunity, for its contact, not written; ${s.given} given the fields the seed generated for ${s.given===1?"it":"them"}`+(s.refusal!==void 0?`, the others left as the platform wrote them (${s.refusal}).`:".")}function B(s){return{readTarget:e=>R(s,e),update:async(e,d,r)=>{let o=await s.sobject(d).update(r,{allOrNone:!1,headers:y()}),t=Array.isArray(o)?o:[o];return r.map((n,a)=>{let i=t[a];return i?.success===!0?{success:!0}:{success:!1,error:(i?.errors??[]).length>0?T(i?.errors):"The org gave no answer for it."}})}}}export{b as a,S as b,P as c,j as d,_ as e,B as f};
|
|
@@ -4,6 +4,6 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{J as H}from"./chunk-7SDZR6SR.mjs";import{b as R,c as de,d as _}from"./chunk-VPDEJGPS.mjs";import{i as ae}from"./chunk-INIT2UKJ.mjs";import{h as Y}from"./chunk-TZE3Y7IQ.mjs";import{b as F}from"./chunk-CA5NAXSU.mjs";var ke=5,Ie=100;function m(n){return n.slice(0,15)}function N(n){return n==null||n===""}var ce=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;function Re(n,e){if(N(n)||N(e))return N(n)&&N(e);if(typeof n=="number"||typeof e=="number")return Number(n)===Number(e);if(typeof n=="string"&&typeof e=="string"){if(n===e)return!0;if(ce.test(n)&&ce.test(e)){let s=Date.parse(n);return Number.isFinite(s)&&s===Date.parse(e)}return!1}return JSON.stringify(n)===JSON.stringify(e)}function Ae(n){let e;return()=>(e??=(async()=>{try{let s=await n.userId?.();return typeof s=="string"&&s!==""?m(s):void 0}catch{return}})(),e)}async function fe(n){let e=Date.now();try{let s=Date.parse(await n.serverTime());return Number.isFinite(s)?s-(e+Date.now())/2:0}catch{return 0}}async function Oe(n,e){let s=Date.parse(e??"");return Number.isFinite(s)?s+await fe(n)+H:Number.NEGATIVE_INFINITY}var ve=1e3;function Se(n){let e=Date.parse(n);return Number.isFinite(e)?e-ve:Number.NEGATIVE_INFINITY}function Pe(n,e){let s=Object.hasOwn(n,e)?n[e]:[];return new Map(s.filter(o=>o.toLowerCase()!=="id").map(o=>[o.toLowerCase(),o]))}var Ee={INACTIVE_OWNER_OR_USER:"OwnerId"};function je(n,e){let s=new Set;for(let r of n.errors??[]){if(typeof r=="string")continue;if(Array.isArray(r.fields))for(let g of r.fields)typeof g=="string"&&s.add(g);let c=r.statusCode!==void 0?Ee[r.statusCode]:void 0;c!==void 0&&(!Array.isArray(r.fields)||r.fields.length===0)&&s.add(c)}let o=new Map(Object.keys(e).map(r=>[r.toLowerCase(),r]));return[...s].flatMap(r=>{let c=o.get(r.toLowerCase());return c!==void 0&&c!=="Id"?[c]:[]})}function Fe(n,e){let s=Array.isArray(n)?n:[n];return Array.from({length:e},(o,r)=>s[r]??{success:!1})}function Q(n){let e=n.errors?.[0];if(e===void 0)return{words:"The org gave no reason."};if(typeof e=="string")return{words:e};let s=e.statusCode,o=e.message??"";return{...s?{code:s}:{},words:s&&o?`${s}: ${o}`:s||o}}function C(n,{fields:e,why:s}){return`${e.map(o=>`${n}.${o}`).join(", ")}: the value from before is no longer taken (${s}) \u2014 left as the run wrote it`}async function Le(n,e,s){let o=new Set;try{for(let r of _(s)){let c=await n.query(`SELECT Id FROM ${e} WHERE Id IN (${r})`);for(let g of c.records)typeof g.Id=="string"&&o.add(m(g.Id))}}catch(r){return{unread:F(r)}}return{live:o}}var Z=class{result;said=new Set;constructor(e,s){this.result={objectApiName:e,planned:s,restored:0,keptChanged:0,alreadyGone:0,refused:0,notKept:0,reasons:[]}}without(){this.result.restoredWithout=(this.result.restoredWithout??0)+1}reason(e){this.said.has(e)||this.said.size>=ke||(this.said.add(e),this.result.reasons.push(e))}};async function Qe(n){let{org:e,plan:s}=n,o=[],r=[],c={},g=!1,u=!1;if(s.length===0)return{objects:o,left:r,wrote:g,cancelled:u,stamps:c};let A=n.changedAfter!==void 0?Se(n.changedAfter):await Oe(e,n.lastWriteAt),w=new Map(Object.entries(n.stamps??{}).map(([b,x])=>[m(b),Date.parse(x)])),L=n.ownWriters&&n.ownWriters.length>0?new Set(n.ownWriters.map(m)):void 0,T=n.stampsFor,he=Ae(e);for(let{objectApiName:b,backup:x,ids:D}of s){let l=new Z(b,D.length);o.push(l.result);let W=n.unkept?.find(t=>t.objectApiName===b);if(W&&W.fields.length>0&&l.reason(`${W.fields.map(t=>`${b}.${t}`).join(", ")}: not kept, encrypted \u2014 the run's user cannot view encrypted data, and read their values from before masked; left as the run wrote them`),u||n.signal?.aborted){u=!0,l.result.notReached=D.length,r.push(...D);continue}let G=Y(b),k=new Map(D.map(t=>[m(t),t])),U=n.fields?Pe(n.fields,b):void 0,v=new Map,q=new Set;try{let t=await n.backups.batches(x,b,R);for await(let i of t??[])for(let a of i){if(typeof a.Id!="string"||!k.has(m(a.Id)))continue;let d=v.get(m(a.Id))??{};for(let[h,f]of Object.entries(a)){if(h==="Id")continue;let p=U?U.get(h.toLowerCase()):h;p!==void 0&&!(p in d)&&(d[p]=f)}if(U&&Object.keys(d).length===0){q.add(m(a.Id));continue}v.set(m(a.Id),d)}}catch(t){l.reason(`The values from before the run could not be read: ${F(t)}`),v.clear(),q.clear()}let ee=[...q].filter(t=>!v.has(t)).length;ee>0&&l.reason(`${ee} ${b} record(s) hold no value of a field that may be written back now: left as they are`);for(let t of[...k.keys()])v.has(t)||(l.result.notKept++,k.delete(t));if(k.size===0)continue;let te=new Set;for(let t of v.values())for(let i of Object.keys(t))te.add(Y(i));let ne=["Id","LastModifiedDate",...L?["LastModifiedById"]:[],...te],pe=ne.length>Ie?R/4:R,J=new Map,ye=async t=>{if(n.signal?.aborted)throw new B;return(await e.query(t)).records};try{for(let t of _([...k.values()],pe)){let i=await ae(`SELECT ${ne.join(", ")} FROM ${G} WHERE Id IN (${t})`,ye,{stamp:"LastModifiedDate"});for(let a of i)typeof a.Id=="string"&&J.set(m(a.Id),a)}}catch(t){if(t instanceof B){u=!0,l.result.notReached=k.size,r.push(...k.values());continue}l.result.refused+=k.size,l.reason(F(t)),r.push(...k.values());continue}let $=[],re=new Set,me=T?Date.now()+await fe(e)-H:0;for(let[t,i]of k){let a=J.get(t);if(!a){l.result.alreadyGone++,n.counted?.(i,"alreadyGone");continue}let d=Date.parse(String(a.LastModifiedDate??"")),h=a.LastModifiedById,f=d<=A||d<=(w.get(t)??Number.NaN)||L!==void 0&&typeof h=="string"&&L.has(m(h));if(!f&&!n.includeChanged){l.result.keptChanged++,r.push(i);continue}let p=v.get(t)??{},y={Id:a.Id};for(let[I,O]of Object.entries(p))Re(O,a[I])||(y[I]=N(O)?null:O);if(Object.keys(y).length===1){l.result.restored++,n.counted?.(i,"restored"),f&&T?.(i)&&typeof a.LastModifiedDate=="string"&&(c[a.Id]=a.LastModifiedDate);continue}$.push(y),f&&T?.(i)&&re.add(i)}let P=[],S=[],E=(t,i)=>{l.result.refused++,l.reason(i),r.push(k.get(m(t.Id))??t.Id)},K=t=>{l.result.restored++,n.counted?.(k.get(m(t.Id))??t.Id,"restored")},we=t=>{l.result.alreadyGone++,n.counted?.(k.get(m(t.Id))??t.Id,"alreadyGone")},se=t=>{u=!0,l.result.notReached=(l.result.notReached??0)+t.length,r.push(...t.map(i=>k.get(m(i.Id))??i.Id))},oe=(t,i,a,d)=>{let h=Object.keys(t).filter(y=>y!=="Id"&&!i.includes(y));if(h.length>0){let y={Id:t.Id};for(let I of h)y[I]=t[I];P.push({record:y,leftOut:a});return}if(a.length===0){K(t);return}let[f,...p]=a;d?(l.without(),l.reason(C(b,f))):E(t,C(b,f));for(let y of p)l.reason(C(b,y))},z=async t=>{try{return g=!0,Fe(await e.update(b,[...t]),t.length)}catch(i){let a=F(i);return t.map(()=>({success:!1,errors:[a]}))}},be=async t=>{let i=n.keep;if(!i)return!0;let a=t.map(d=>{let h=J.get(m(d.Id))??{},f={Id:d.Id};for(let p of Object.keys(d))p!=="Id"&&(f[p]=h[p]??null);return f});try{return await i(b,a),!0}catch(d){let h=`What these ${t.length} ${b} record(s) hold now could not be kept before they were written (${F(d)}), so none of them was written: nothing is written over that cannot be put back.`;for(let f of t)E(f,h);return!1}};for(let t=0;t<$.length;t+=R){let i=$.slice(t,t+R);if(n.signal?.aborted){u=!0;let d=$.slice(t);l.result.notReached=(l.result.notReached??0)+d.length,r.push(...d.map(h=>k.get(m(h.Id))??h.Id));break}if(!await be(i))continue;(await z(i)).forEach((d,h)=>{let f=i[h];if(d.success===!0){K(f);return}let p=Q(d),y=je(d,f);if(p.code==="ENTITY_IS_DELETED"&&y.length===0){S.push({record:f,why:p.words});return}let I=Object.keys(f).filter(O=>O!=="Id"&&!y.includes(O));if(y.length>0&&I.length>0){let O={Id:f.Id};for(let ie of I)O[ie]=f[ie];P.push({record:O,leftOut:[{fields:y,why:p.words}]});return}E(f,p.words)})}let j=[];if(S.length>0&&n.signal?.aborted)se(S.map(({record:t})=>t));else if(S.length>0){let t=await Le(e,G,S.map(({record:i})=>i.Id));t.unread!==void 0&&l.reason(`Whether ${S.length} ${b} record(s) refused as deleted are still in the org could not be read (${t.unread}): left to be given back again`);for(let{record:i,why:a}of S){if(t.unread!==void 0){E(i,a);continue}if(!t.live.has(m(i.Id))){we(i);continue}let d=Object.keys(i).filter(h=>h!=="Id"&&de(i[h]));d.length===0?E(i,a):d.length===1?oe(i,d,[{fields:d,why:a}],!1):j.push({record:i,lookups:d,given:[],refusedAlone:[]})}}let V=j.length>0;for(let t=0;V&&j.some(({lookups:i})=>i.length>t);t++){let i=j.filter(({lookups:a})=>a.length>t);for(let a=0;a<i.length;a+=R){if(n.signal?.aborted){se(j.map(({record:f})=>f)),V=!1;break}let d=i.slice(a,a+R);(await z(d.map(({record:f,lookups:p})=>({Id:f.Id,[p[t]]:f[p[t]]})))).forEach((f,p)=>{let y=d[p],I=y.lookups[t];f.success===!0?y.given.push(I):y.refusedAlone.push({field:I,why:Q(f).words})})}}for(let t of V?j:[]){let i=new Map;for(let{field:a,why:d}of t.refusedAlone)i.set(d,[...i.get(d)??[],a]);oe(t.record,t.lookups,[...i].map(([a,d])=>({fields:d,why:a})),t.given.length>0)}for(let t=0;t<P.length;t+=R){let i=P.slice(t,t+R);if(n.signal?.aborted){u=!0,l.result.notReached=(l.result.notReached??0)+P.length-t,r.push(...P.slice(t).map(({record:d})=>k.get(m(d.Id))??d.Id));break}(await z(i.map(({record:d})=>d))).forEach((d,h)=>{let{record:f,leftOut:p}=i[h];if(d.success===!0){if(p.length===0){K(f);return}l.without();for(let y of p)l.reason(C(b,y));return}E(f,Q(d).words)})}Object.assign(c,await Ne(e,G,[...re],me,he))}return{objects:o,left:r,wrote:g,cancelled:u,stamps:c}}async function Ne(n,e,s,o,r){let c={};if(s.length===0)return c;let g=await r();if(g===void 0)return c;for(let u of _(s)){let A;try{A=(await n.query(`SELECT Id, LastModifiedDate, LastModifiedById FROM ${e} WHERE Id IN (${u})`)).records}catch{continue}for(let w of A)typeof w.Id=="string"&&typeof w.LastModifiedDate=="string"&&typeof w.LastModifiedById=="string"&&m(w.LastModifiedById)===g&&Date.parse(w.LastModifiedDate)>=o&&(c[w.Id]=w.LastModifiedDate)}return c}var B=class extends Error{};function Ze(n,e,s=[]){let o=n.map(r=>({...r}));for(let r of s){if(r.undeleted+r.refused===0)continue;let c=o.find(g=>g.objectApiName===r.objectApiName);c?(c.created+=r.undeleted,c.failed+=r.refused):o.push({objectApiName:r.objectApiName,created:r.undeleted,updated:0,deleted:0,failed:r.refused})}for(let r of e){let c=r.restored+(r.restoredWithout??0);if(c+r.refused===0)continue;let g=o.find(u=>u.objectApiName===r.objectApiName);g?(g.updated+=c,g.failed+=r.refused):o.push({objectApiName:r.objectApiName,created:0,updated:c,deleted:0,failed:r.refused})}return o}import{createReadStream as Me}from"node:fs";import{access as De,appendFile as $e,mkdir as _e,readFile as Ce,readdir as Be,rm as Te,stat as xe,writeFile as We}from"node:fs/promises";import*as M from"node:path";import{createInterface as Ge}from"node:readline";var ue=384,Ue=448;function rt(n){return{storagePath:n,readFile:e=>Ce(e,"utf8"),writeFile:(e,s)=>We(e,s,{encoding:"utf8",mode:ue}),appendFile:(e,s)=>$e(e,s,{encoding:"utf8",mode:ue}),exists:e=>De(e).then(()=>!0,()=>!1),readLines:e=>Je(e),mkdir:async e=>{await _e(e,{recursive:!0,mode:Ue})},rm:e=>Te(e,{force:!0}),listFiles:e=>qe(e)}}async function qe(n){let e;try{e=await Be(n,{withFileTypes:!0})}catch(o){if(o.code==="ENOENT")return[];throw o}let s=[];for(let o of e){if(!o.isFile())continue;let r=await xe(M.join(n,o.name)).catch(()=>{});r&&s.push({name:o.name,modifiedMs:r.mtimeMs})}return s}async function*Je(n){let e=Me(n,{encoding:"utf8"}),s=Ge({input:e,crlfDelay:1/0});try{for await(let o of s)yield o}finally{s.close(),e.destroy()}}function X(n){return n.replace(/[^A-Za-z0-9_-]/g,"_")}function le(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}var ge=class{constructor(e){this.deps=e;this.dir=M.join(e.storagePath,"backups")}deps;dir;get directory(){return this.dir}filePath(e,s,o="lines"){let r=`${X(e)}__${X(s)}`;return M.join(this.dir,`${r}.${o==="lines"?"ndjson":"json"}`)}async begin(e,s){await this.deps.mkdir(this.dir).catch(()=>{}),await this.deps.writeFile(this.filePath(e,s),"")}async append(e,s,o){if(o.length===0)return;let r=o.map(c=>JSON.stringify(c)).join(`
|
|
7
|
+
import{I as H}from"./chunk-IXIY6Q4M.mjs";import{b as R,c as de,d as _}from"./chunk-MJD6CPZZ.mjs";import{i as ae}from"./chunk-INIT2UKJ.mjs";import{h as Y}from"./chunk-TZE3Y7IQ.mjs";import{b as F}from"./chunk-CA5NAXSU.mjs";var ke=5,Ie=100;function m(n){return n.slice(0,15)}function N(n){return n==null||n===""}var ce=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;function Re(n,e){if(N(n)||N(e))return N(n)&&N(e);if(typeof n=="number"||typeof e=="number")return Number(n)===Number(e);if(typeof n=="string"&&typeof e=="string"){if(n===e)return!0;if(ce.test(n)&&ce.test(e)){let s=Date.parse(n);return Number.isFinite(s)&&s===Date.parse(e)}return!1}return JSON.stringify(n)===JSON.stringify(e)}function Ae(n){let e;return()=>(e??=(async()=>{try{let s=await n.userId?.();return typeof s=="string"&&s!==""?m(s):void 0}catch{return}})(),e)}async function fe(n){let e=Date.now();try{let s=Date.parse(await n.serverTime());return Number.isFinite(s)?s-(e+Date.now())/2:0}catch{return 0}}async function Oe(n,e){let s=Date.parse(e??"");return Number.isFinite(s)?s+await fe(n)+H:Number.NEGATIVE_INFINITY}var ve=1e3;function Se(n){let e=Date.parse(n);return Number.isFinite(e)?e-ve:Number.NEGATIVE_INFINITY}function Pe(n,e){let s=Object.hasOwn(n,e)?n[e]:[];return new Map(s.filter(o=>o.toLowerCase()!=="id").map(o=>[o.toLowerCase(),o]))}var Ee={INACTIVE_OWNER_OR_USER:"OwnerId"};function je(n,e){let s=new Set;for(let r of n.errors??[]){if(typeof r=="string")continue;if(Array.isArray(r.fields))for(let g of r.fields)typeof g=="string"&&s.add(g);let c=r.statusCode!==void 0?Ee[r.statusCode]:void 0;c!==void 0&&(!Array.isArray(r.fields)||r.fields.length===0)&&s.add(c)}let o=new Map(Object.keys(e).map(r=>[r.toLowerCase(),r]));return[...s].flatMap(r=>{let c=o.get(r.toLowerCase());return c!==void 0&&c!=="Id"?[c]:[]})}function Fe(n,e){let s=Array.isArray(n)?n:[n];return Array.from({length:e},(o,r)=>s[r]??{success:!1})}function Q(n){let e=n.errors?.[0];if(e===void 0)return{words:"The org gave no reason."};if(typeof e=="string")return{words:e};let s=e.statusCode,o=e.message??"";return{...s?{code:s}:{},words:s&&o?`${s}: ${o}`:s||o}}function C(n,{fields:e,why:s}){return`${e.map(o=>`${n}.${o}`).join(", ")}: the value from before is no longer taken (${s}) \u2014 left as the run wrote it`}async function Le(n,e,s){let o=new Set;try{for(let r of _(s)){let c=await n.query(`SELECT Id FROM ${e} WHERE Id IN (${r})`);for(let g of c.records)typeof g.Id=="string"&&o.add(m(g.Id))}}catch(r){return{unread:F(r)}}return{live:o}}var Z=class{result;said=new Set;constructor(e,s){this.result={objectApiName:e,planned:s,restored:0,keptChanged:0,alreadyGone:0,refused:0,notKept:0,reasons:[]}}without(){this.result.restoredWithout=(this.result.restoredWithout??0)+1}reason(e){this.said.has(e)||this.said.size>=ke||(this.said.add(e),this.result.reasons.push(e))}};async function Qe(n){let{org:e,plan:s}=n,o=[],r=[],c={},g=!1,u=!1;if(s.length===0)return{objects:o,left:r,wrote:g,cancelled:u,stamps:c};let A=n.changedAfter!==void 0?Se(n.changedAfter):await Oe(e,n.lastWriteAt),w=new Map(Object.entries(n.stamps??{}).map(([b,x])=>[m(b),Date.parse(x)])),L=n.ownWriters&&n.ownWriters.length>0?new Set(n.ownWriters.map(m)):void 0,T=n.stampsFor,he=Ae(e);for(let{objectApiName:b,backup:x,ids:D}of s){let l=new Z(b,D.length);o.push(l.result);let W=n.unkept?.find(t=>t.objectApiName===b);if(W&&W.fields.length>0&&l.reason(`${W.fields.map(t=>`${b}.${t}`).join(", ")}: not kept, encrypted \u2014 the run's user cannot view encrypted data, and read their values from before masked; left as the run wrote them`),u||n.signal?.aborted){u=!0,l.result.notReached=D.length,r.push(...D);continue}let G=Y(b),k=new Map(D.map(t=>[m(t),t])),U=n.fields?Pe(n.fields,b):void 0,v=new Map,q=new Set;try{let t=await n.backups.batches(x,b,R);for await(let i of t??[])for(let a of i){if(typeof a.Id!="string"||!k.has(m(a.Id)))continue;let d=v.get(m(a.Id))??{};for(let[h,f]of Object.entries(a)){if(h==="Id")continue;let p=U?U.get(h.toLowerCase()):h;p!==void 0&&!(p in d)&&(d[p]=f)}if(U&&Object.keys(d).length===0){q.add(m(a.Id));continue}v.set(m(a.Id),d)}}catch(t){l.reason(`The values from before the run could not be read: ${F(t)}`),v.clear(),q.clear()}let ee=[...q].filter(t=>!v.has(t)).length;ee>0&&l.reason(`${ee} ${b} record(s) hold no value of a field that may be written back now: left as they are`);for(let t of[...k.keys()])v.has(t)||(l.result.notKept++,k.delete(t));if(k.size===0)continue;let te=new Set;for(let t of v.values())for(let i of Object.keys(t))te.add(Y(i));let ne=["Id","LastModifiedDate",...L?["LastModifiedById"]:[],...te],pe=ne.length>Ie?R/4:R,J=new Map,ye=async t=>{if(n.signal?.aborted)throw new B;return(await e.query(t)).records};try{for(let t of _([...k.values()],pe)){let i=await ae(`SELECT ${ne.join(", ")} FROM ${G} WHERE Id IN (${t})`,ye,{stamp:"LastModifiedDate"});for(let a of i)typeof a.Id=="string"&&J.set(m(a.Id),a)}}catch(t){if(t instanceof B){u=!0,l.result.notReached=k.size,r.push(...k.values());continue}l.result.refused+=k.size,l.reason(F(t)),r.push(...k.values());continue}let $=[],re=new Set,me=T?Date.now()+await fe(e)-H:0;for(let[t,i]of k){let a=J.get(t);if(!a){l.result.alreadyGone++,n.counted?.(i,"alreadyGone");continue}let d=Date.parse(String(a.LastModifiedDate??"")),h=a.LastModifiedById,f=d<=A||d<=(w.get(t)??Number.NaN)||L!==void 0&&typeof h=="string"&&L.has(m(h));if(!f&&!n.includeChanged){l.result.keptChanged++,r.push(i);continue}let p=v.get(t)??{},y={Id:a.Id};for(let[I,O]of Object.entries(p))Re(O,a[I])||(y[I]=N(O)?null:O);if(Object.keys(y).length===1){l.result.restored++,n.counted?.(i,"restored"),f&&T?.(i)&&typeof a.LastModifiedDate=="string"&&(c[a.Id]=a.LastModifiedDate);continue}$.push(y),f&&T?.(i)&&re.add(i)}let P=[],S=[],E=(t,i)=>{l.result.refused++,l.reason(i),r.push(k.get(m(t.Id))??t.Id)},K=t=>{l.result.restored++,n.counted?.(k.get(m(t.Id))??t.Id,"restored")},we=t=>{l.result.alreadyGone++,n.counted?.(k.get(m(t.Id))??t.Id,"alreadyGone")},se=t=>{u=!0,l.result.notReached=(l.result.notReached??0)+t.length,r.push(...t.map(i=>k.get(m(i.Id))??i.Id))},oe=(t,i,a,d)=>{let h=Object.keys(t).filter(y=>y!=="Id"&&!i.includes(y));if(h.length>0){let y={Id:t.Id};for(let I of h)y[I]=t[I];P.push({record:y,leftOut:a});return}if(a.length===0){K(t);return}let[f,...p]=a;d?(l.without(),l.reason(C(b,f))):E(t,C(b,f));for(let y of p)l.reason(C(b,y))},z=async t=>{try{return g=!0,Fe(await e.update(b,[...t]),t.length)}catch(i){let a=F(i);return t.map(()=>({success:!1,errors:[a]}))}},be=async t=>{let i=n.keep;if(!i)return!0;let a=t.map(d=>{let h=J.get(m(d.Id))??{},f={Id:d.Id};for(let p of Object.keys(d))p!=="Id"&&(f[p]=h[p]??null);return f});try{return await i(b,a),!0}catch(d){let h=`What these ${t.length} ${b} record(s) hold now could not be kept before they were written (${F(d)}), so none of them was written: nothing is written over that cannot be put back.`;for(let f of t)E(f,h);return!1}};for(let t=0;t<$.length;t+=R){let i=$.slice(t,t+R);if(n.signal?.aborted){u=!0;let d=$.slice(t);l.result.notReached=(l.result.notReached??0)+d.length,r.push(...d.map(h=>k.get(m(h.Id))??h.Id));break}if(!await be(i))continue;(await z(i)).forEach((d,h)=>{let f=i[h];if(d.success===!0){K(f);return}let p=Q(d),y=je(d,f);if(p.code==="ENTITY_IS_DELETED"&&y.length===0){S.push({record:f,why:p.words});return}let I=Object.keys(f).filter(O=>O!=="Id"&&!y.includes(O));if(y.length>0&&I.length>0){let O={Id:f.Id};for(let ie of I)O[ie]=f[ie];P.push({record:O,leftOut:[{fields:y,why:p.words}]});return}E(f,p.words)})}let j=[];if(S.length>0&&n.signal?.aborted)se(S.map(({record:t})=>t));else if(S.length>0){let t=await Le(e,G,S.map(({record:i})=>i.Id));t.unread!==void 0&&l.reason(`Whether ${S.length} ${b} record(s) refused as deleted are still in the org could not be read (${t.unread}): left to be given back again`);for(let{record:i,why:a}of S){if(t.unread!==void 0){E(i,a);continue}if(!t.live.has(m(i.Id))){we(i);continue}let d=Object.keys(i).filter(h=>h!=="Id"&&de(i[h]));d.length===0?E(i,a):d.length===1?oe(i,d,[{fields:d,why:a}],!1):j.push({record:i,lookups:d,given:[],refusedAlone:[]})}}let V=j.length>0;for(let t=0;V&&j.some(({lookups:i})=>i.length>t);t++){let i=j.filter(({lookups:a})=>a.length>t);for(let a=0;a<i.length;a+=R){if(n.signal?.aborted){se(j.map(({record:f})=>f)),V=!1;break}let d=i.slice(a,a+R);(await z(d.map(({record:f,lookups:p})=>({Id:f.Id,[p[t]]:f[p[t]]})))).forEach((f,p)=>{let y=d[p],I=y.lookups[t];f.success===!0?y.given.push(I):y.refusedAlone.push({field:I,why:Q(f).words})})}}for(let t of V?j:[]){let i=new Map;for(let{field:a,why:d}of t.refusedAlone)i.set(d,[...i.get(d)??[],a]);oe(t.record,t.lookups,[...i].map(([a,d])=>({fields:d,why:a})),t.given.length>0)}for(let t=0;t<P.length;t+=R){let i=P.slice(t,t+R);if(n.signal?.aborted){u=!0,l.result.notReached=(l.result.notReached??0)+P.length-t,r.push(...P.slice(t).map(({record:d})=>k.get(m(d.Id))??d.Id));break}(await z(i.map(({record:d})=>d))).forEach((d,h)=>{let{record:f,leftOut:p}=i[h];if(d.success===!0){if(p.length===0){K(f);return}l.without();for(let y of p)l.reason(C(b,y));return}E(f,Q(d).words)})}Object.assign(c,await Ne(e,G,[...re],me,he))}return{objects:o,left:r,wrote:g,cancelled:u,stamps:c}}async function Ne(n,e,s,o,r){let c={};if(s.length===0)return c;let g=await r();if(g===void 0)return c;for(let u of _(s)){let A;try{A=(await n.query(`SELECT Id, LastModifiedDate, LastModifiedById FROM ${e} WHERE Id IN (${u})`)).records}catch{continue}for(let w of A)typeof w.Id=="string"&&typeof w.LastModifiedDate=="string"&&typeof w.LastModifiedById=="string"&&m(w.LastModifiedById)===g&&Date.parse(w.LastModifiedDate)>=o&&(c[w.Id]=w.LastModifiedDate)}return c}var B=class extends Error{};function Ze(n,e,s=[]){let o=n.map(r=>({...r}));for(let r of s){if(r.undeleted+r.refused===0)continue;let c=o.find(g=>g.objectApiName===r.objectApiName);c?(c.created+=r.undeleted,c.failed+=r.refused):o.push({objectApiName:r.objectApiName,created:r.undeleted,updated:0,deleted:0,failed:r.refused})}for(let r of e){let c=r.restored+(r.restoredWithout??0);if(c+r.refused===0)continue;let g=o.find(u=>u.objectApiName===r.objectApiName);g?(g.updated+=c,g.failed+=r.refused):o.push({objectApiName:r.objectApiName,created:0,updated:c,deleted:0,failed:r.refused})}return o}import{createReadStream as Me}from"node:fs";import{access as De,appendFile as $e,mkdir as _e,readFile as Ce,readdir as Be,rm as Te,stat as xe,writeFile as We}from"node:fs/promises";import*as M from"node:path";import{createInterface as Ge}from"node:readline";var ue=384,Ue=448;function rt(n){return{storagePath:n,readFile:e=>Ce(e,"utf8"),writeFile:(e,s)=>We(e,s,{encoding:"utf8",mode:ue}),appendFile:(e,s)=>$e(e,s,{encoding:"utf8",mode:ue}),exists:e=>De(e).then(()=>!0,()=>!1),readLines:e=>Je(e),mkdir:async e=>{await _e(e,{recursive:!0,mode:Ue})},rm:e=>Te(e,{force:!0}),listFiles:e=>qe(e)}}async function qe(n){let e;try{e=await Be(n,{withFileTypes:!0})}catch(o){if(o.code==="ENOENT")return[];throw o}let s=[];for(let o of e){if(!o.isFile())continue;let r=await xe(M.join(n,o.name)).catch(()=>{});r&&s.push({name:o.name,modifiedMs:r.mtimeMs})}return s}async function*Je(n){let e=Me(n,{encoding:"utf8"}),s=Ge({input:e,crlfDelay:1/0});try{for await(let o of s)yield o}finally{s.close(),e.destroy()}}function X(n){return n.replace(/[^A-Za-z0-9_-]/g,"_")}function le(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}var ge=class{constructor(e){this.deps=e;this.dir=M.join(e.storagePath,"backups")}deps;dir;get directory(){return this.dir}filePath(e,s,o="lines"){let r=`${X(e)}__${X(s)}`;return M.join(this.dir,`${r}.${o==="lines"?"ndjson":"json"}`)}async begin(e,s){await this.deps.mkdir(this.dir).catch(()=>{}),await this.deps.writeFile(this.filePath(e,s),"")}async append(e,s,o){if(o.length===0)return;let r=o.map(c=>JSON.stringify(c)).join(`
|
|
8
8
|
`);await this.deps.appendFile(this.filePath(e,s),`${r}
|
|
9
9
|
`)}async batches(e,s,o){let r=this.filePath(e,s);if(await this.deps.exists(r))return{[Symbol.asyncIterator]:()=>this.readLineBatches(r,s,o)};let c=this.filePath(e,s,"array");return await this.deps.exists(c)?{[Symbol.asyncIterator]:()=>this.readArrayBatches(c,s,o)}:null}async*readLineBatches(e,s,o){let r=[],c=0;for await(let g of this.deps.readLines(e)){if(c+=1,g.trim()==="")continue;let u;try{u=JSON.parse(g)}catch{u=void 0}if(!le(u))throw new Error(`The backup of ${s} is damaged at line ${c} of its file: it holds no record there.`);r.push(u),r.length===o&&(yield r,r=[])}r.length>0&&(yield r)}async*readArrayBatches(e,s,o){let r=JSON.parse(await this.deps.readFile(e));if(!Array.isArray(r)||!r.every(le))throw new Error(`The backup of ${s} is damaged: its file holds no records.`);for(let c=0;c<r.length;c+=o)yield r.slice(c,c+o)}async delete(e,s){await this.deps.rm(this.filePath(e,s)).catch(()=>{}),await this.deps.rm(this.filePath(e,s,"array")).catch(()=>{})}async sweep(e,s,o){let r=[...e].map(u=>`${X(u)}__`),c=new Map;for(let u of await this.deps.listFiles(this.dir)){if(!/\.(?:ndjson|json)$/.test(u.name))continue;let A=u.name.indexOf("__");if(A<=0||r.some(L=>u.name.startsWith(L)))continue;let w=u.name.slice(0,A);c.set(w,[...c.get(w)??[],u])}let g=[];for(let u of c.values()){let A=Math.max(...u.map(w=>w.modifiedMs));if(!(o-A<s))for(let w of u)await this.deps.rm(M.join(this.dir,w.name)).then(()=>g.push(w.name),()=>{})}return g}};export{Re as a,Ae as b,fe as c,Oe as d,Qe as e,Ne as f,Ze as g,rt as h,ge as i};
|