sandforge 1.81.0 → 1.82.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/README.md +48 -0
- package/bin/sandforge-users.mjs +12 -0
- package/lib/{chunk-C4YGSK6W.mjs → chunk-27Z76O2O.mjs} +1 -1
- package/lib/{chunk-TKQQVB2D.mjs → chunk-2JZGCCPG.mjs} +1 -1
- package/lib/{chunk-TPHXRHOA.mjs → chunk-2UU42PTD.mjs} +1 -1
- package/lib/{chunk-ZWZXQTAK.mjs → chunk-32EUNQT6.mjs} +14 -14
- package/lib/{chunk-HYOOJVR6.mjs → chunk-3C2ZZIFN.mjs} +1 -1
- package/lib/{chunk-AELFEK3G.mjs → chunk-3CX7GPCR.mjs} +1 -1
- package/lib/{chunk-YJEXE6HZ.mjs → chunk-3HEMJTAP.mjs} +2 -2
- package/lib/{chunk-DQR5NDMI.mjs → chunk-3HROD5RE.mjs} +1 -1
- package/lib/{chunk-D7P7DTWL.mjs → chunk-3MGMNK3Q.mjs} +1 -1
- package/lib/{chunk-MNITSYI2.mjs → chunk-3SKLBRPL.mjs} +1 -1
- package/lib/{chunk-MAHZMPMZ.mjs → chunk-3XG25GTF.mjs} +1 -1
- package/lib/{chunk-N7J6NJQ6.mjs → chunk-42BFLWHR.mjs} +1 -1
- package/lib/chunk-466F37VD.mjs +7 -0
- package/lib/chunk-47UHTN3Q.mjs +7 -0
- package/lib/{chunk-DHGPDSXS.mjs → chunk-52EXDVPN.mjs} +1 -1
- package/lib/{chunk-5344TZBT.mjs → chunk-5K2I2DMP.mjs} +1 -1
- package/lib/{chunk-2OZG6GRW.mjs → chunk-6GQUZ4IP.mjs} +1 -1
- package/lib/{chunk-SW2NUKQL.mjs → chunk-6KP6WETK.mjs} +1 -1
- package/lib/{chunk-FSZTXLNW.mjs → chunk-6VSZNZHH.mjs} +1 -1
- package/lib/{chunk-6NADW3OI.mjs → chunk-7CVDVBEE.mjs} +1 -1
- package/lib/{chunk-67CC7RAE.mjs → chunk-7EYQYZJP.mjs} +1 -1
- package/lib/{chunk-IBURU7T7.mjs → chunk-7LKI7OAS.mjs} +1 -1
- package/lib/{chunk-CULAOP3U.mjs → chunk-7PY3VQP3.mjs} +1 -1
- package/lib/chunk-7SDZR6SR.mjs +7 -0
- package/lib/{chunk-V4RKM4QZ.mjs → chunk-7WSLT5VX.mjs} +1 -1
- package/lib/chunk-A32ISQ6M.mjs +28 -0
- package/lib/{chunk-K77NR3UK.mjs → chunk-A65ADTCR.mjs} +1 -1
- package/lib/chunk-A7JJWOLT.mjs +7 -0
- package/lib/{chunk-MWLFFVQV.mjs → chunk-AUS6NFLZ.mjs} +1 -1
- package/lib/{chunk-NWPQF5XR.mjs → chunk-BMTNTBBM.mjs} +1 -1
- package/lib/{chunk-FTA5LOVX.mjs → chunk-BN33LVPQ.mjs} +1 -1
- package/lib/chunk-BNKT3R3F.mjs +7 -0
- package/lib/{chunk-WM5JI4JI.mjs → chunk-C2N2TNEU.mjs} +1 -1
- package/lib/{chunk-5UT2ZBGF.mjs → chunk-C3LNYAVJ.mjs} +1 -1
- package/lib/{chunk-GYKNCYES.mjs → chunk-CBL42DUU.mjs} +1 -1
- package/lib/{chunk-W2AAGIZF.mjs → chunk-CCEH7L53.mjs} +1 -1
- package/lib/{chunk-WWTXRWNZ.mjs → chunk-CELEBWEZ.mjs} +1 -1
- package/lib/{chunk-D62KWDDT.mjs → chunk-CV47FDQW.mjs} +1 -1
- package/lib/{chunk-AJPSGVMD.mjs → chunk-CZLJZQCS.mjs} +1 -1
- package/lib/{chunk-YIGFYZQY.mjs → chunk-DBBPDSFN.mjs} +1 -1
- package/lib/{chunk-T5VAULLQ.mjs → chunk-DIL62SUN.mjs} +1 -1
- package/lib/chunk-DIS254AN.mjs +7 -0
- package/lib/{chunk-GK7VEYFM.mjs → chunk-DJCGURW7.mjs} +1 -1
- package/lib/{chunk-MHW6DV6T.mjs → chunk-DT3T7FRD.mjs} +1 -1
- package/lib/{chunk-PYUEHBA6.mjs → chunk-DWMRIWV5.mjs} +1 -1
- package/lib/{chunk-E2OBAWSH.mjs → chunk-EEFUE2ES.mjs} +1 -1
- package/lib/{chunk-MKNAZPOT.mjs → chunk-EOFO3PHS.mjs} +1 -1
- package/lib/{chunk-UUSLTW5V.mjs → chunk-FA4ZKDCU.mjs} +1 -1
- package/lib/{chunk-DHIW4IO5.mjs → chunk-FKK5YBGZ.mjs} +1 -1
- package/lib/{chunk-BZFIOZS3.mjs → chunk-FOIWWK7G.mjs} +1 -1
- package/lib/chunk-FZF23M6R.mjs +7 -0
- package/lib/{chunk-XIZ5LMQM.mjs → chunk-G2JR3F63.mjs} +1 -1
- package/lib/{chunk-2Z54GB6X.mjs → chunk-GBGHJTPC.mjs} +1 -1
- package/lib/{chunk-2NAIUKVL.mjs → chunk-GCGHHN4K.mjs} +1 -1
- package/lib/{chunk-TQM2XJ27.mjs → chunk-GGNUACTY.mjs} +1 -1
- package/lib/{chunk-2IB7I3IQ.mjs → chunk-GGUOIDWP.mjs} +1 -1
- package/lib/chunk-GHPR5UVV.mjs +7 -0
- package/lib/{chunk-YHIOS2PU.mjs → chunk-GJ6SZVHT.mjs} +1 -1
- package/lib/{chunk-WI4HYWV6.mjs → chunk-H4JUYUSL.mjs} +1 -1
- package/lib/{chunk-5WGA5CZB.mjs → chunk-H4OBZIX3.mjs} +1 -1
- package/lib/{chunk-KRNFVAGC.mjs → chunk-HFUDCNU5.mjs} +1 -1
- package/lib/{chunk-OIIL4NVI.mjs → chunk-HIHCYMSL.mjs} +1 -1
- package/lib/chunk-HKUWHVI7.mjs +9 -0
- package/lib/chunk-HQQVANWQ.mjs +20 -0
- package/lib/{chunk-V2QO6KOE.mjs → chunk-IRZJU2PG.mjs} +14 -11
- package/lib/{chunk-CAFUNR6D.mjs → chunk-ISSP2FZ5.mjs} +1 -1
- package/lib/{chunk-OEHVAJAB.mjs → chunk-IVZJSDJD.mjs} +1 -1
- package/lib/{chunk-E2YJVSX6.mjs → chunk-J24TIGSI.mjs} +1 -1
- package/lib/{chunk-YCSFP6ER.mjs → chunk-JESRFE2Z.mjs} +1 -1
- package/lib/{chunk-KOQV4WXC.mjs → chunk-JFNLKHY6.mjs} +2 -2
- package/lib/{chunk-NJ3EOEHS.mjs → chunk-JH27IKCO.mjs} +1 -1
- package/lib/{chunk-DXOXLUZA.mjs → chunk-JJITOWZK.mjs} +1 -1
- package/lib/{chunk-KNIRA333.mjs → chunk-JKT5YAQ2.mjs} +1 -1
- package/lib/{chunk-J6G23RUI.mjs → chunk-JLZRZL5E.mjs} +1 -1
- package/lib/{chunk-6FMLW7PH.mjs → chunk-JPEVIXNH.mjs} +1 -1
- package/lib/{chunk-6IGEASOF.mjs → chunk-JQZTMFO7.mjs} +1 -1
- package/lib/{chunk-55LQD3Y3.mjs → chunk-KIMQQ6JQ.mjs} +1 -1
- package/lib/{chunk-EH5YUA5W.mjs → chunk-KJYEQHYP.mjs} +1 -1
- package/lib/chunk-KKOA62S4.mjs +474 -0
- package/lib/{chunk-56MPPWLA.mjs → chunk-KP5G6FUC.mjs} +1 -1
- package/lib/{chunk-EAFLDSQ2.mjs → chunk-L4INJ5TZ.mjs} +1 -1
- package/lib/{chunk-MO3N5XVV.mjs → chunk-LAUOSXMN.mjs} +2 -2
- package/lib/{chunk-HVC5CYIB.mjs → chunk-LHU6CPGE.mjs} +1 -1
- package/lib/{chunk-7PK5QDQI.mjs → chunk-LXDSRP2W.mjs} +1 -1
- package/lib/{chunk-YOGMP72T.mjs → chunk-MKTXJCXN.mjs} +1 -1
- package/lib/{chunk-VSU74RQ3.mjs → chunk-MUEQRIK7.mjs} +1 -1
- package/lib/{chunk-UCHAZ4ZU.mjs → chunk-NLB3RGIY.mjs} +1 -1
- package/lib/{chunk-OVOLG3AL.mjs → chunk-NWOI25WY.mjs} +1 -1
- package/lib/{chunk-6SEDOIO3.mjs → chunk-O2PUGRNW.mjs} +1 -1
- package/lib/chunk-O4BROUGM.mjs +7 -0
- package/lib/{chunk-KGYXLSQ5.mjs → chunk-P55MKIZX.mjs} +1 -1
- package/lib/{chunk-KE2PGD6C.mjs → chunk-P63WJMXQ.mjs} +1 -1
- package/lib/chunk-PBE44M2Y.mjs +7 -0
- package/lib/{chunk-OMZJ37JI.mjs → chunk-PE435FVH.mjs} +2 -2
- package/lib/{chunk-GR3NGDVM.mjs → chunk-PPHVWUFY.mjs} +1 -1
- package/lib/{chunk-ZUA5BNAO.mjs → chunk-PR74GYVI.mjs} +1 -1
- package/lib/{chunk-43K2C6H2.mjs → chunk-PWVDNN2C.mjs} +1 -1
- package/lib/{chunk-DMBR24CK.mjs → chunk-PYRZFUVU.mjs} +1 -1
- package/lib/{chunk-OXKZ4Y3B.mjs → chunk-Q3DY7TO2.mjs} +1 -1
- package/lib/{chunk-EOSEMFPU.mjs → chunk-Q6SXNKV2.mjs} +1 -1
- package/lib/chunk-QAPVKPEC.mjs +7 -0
- package/lib/chunk-QROPNEGY.mjs +14 -0
- package/lib/{chunk-6CDIIFNX.mjs → chunk-RCYEBY42.mjs} +1 -1
- package/lib/chunk-RLWB7F26.mjs +7 -0
- package/lib/{chunk-X2ZVSQ54.mjs → chunk-RTWYLOCA.mjs} +1 -1
- package/lib/chunk-RYRMUPMY.mjs +7 -0
- package/lib/{chunk-ETT5GP4P.mjs → chunk-SAMWHL22.mjs} +1 -1
- package/lib/{chunk-LO527YLT.mjs → chunk-SFGZFB4F.mjs} +1 -1
- package/lib/{chunk-33ZX3A56.mjs → chunk-SNEOKYV7.mjs} +1 -1
- package/lib/{chunk-GTIXJCGS.mjs → chunk-STRMWSIQ.mjs} +1 -1
- package/lib/{chunk-OQQHNYR7.mjs → chunk-SZGGFST2.mjs} +2 -2
- package/lib/{chunk-OU5W7SCB.mjs → chunk-T7WREYA5.mjs} +1 -1
- package/lib/{chunk-FLNLG43R.mjs → chunk-TCBAE65A.mjs} +1 -1
- package/lib/{chunk-RKALOKAU.mjs → chunk-TMA34QMA.mjs} +1 -1
- package/lib/{chunk-WEZLXE34.mjs → chunk-TWV4A5RK.mjs} +1 -1
- package/lib/{chunk-ONMBSACW.mjs → chunk-UHFLKP26.mjs} +1 -1
- package/lib/chunk-UV74P4H2.mjs +7 -0
- package/lib/{chunk-HYBH5PFM.mjs → chunk-V3R45ZWT.mjs} +1 -1
- package/lib/{chunk-BNO5GIJ6.mjs → chunk-VPDEJGPS.mjs} +1 -1
- package/lib/{chunk-3AOKLIVE.mjs → chunk-VQJMP3DC.mjs} +1 -1
- package/lib/{chunk-742SSN7I.mjs → chunk-VYOYXTCU.mjs} +1 -1
- package/lib/{chunk-GWRKS3AL.mjs → chunk-VZT4E2OJ.mjs} +1 -1
- package/lib/{chunk-2OIRJEYE.mjs → chunk-VZVICK7Q.mjs} +1 -1
- package/lib/chunk-WEMLDUQA.mjs +7 -0
- package/lib/{chunk-FDGFUEK3.mjs → chunk-WOOUISSO.mjs} +1 -1
- package/lib/{chunk-UIUPPEFB.mjs → chunk-WSUKC2U3.mjs} +1 -1
- package/lib/{chunk-XC2QKQT5.mjs → chunk-WT3SCUHS.mjs} +1 -1
- package/lib/{chunk-UT27HXE7.mjs → chunk-XFU3HRUV.mjs} +1 -1
- package/lib/{chunk-5VQNKDFU.mjs → chunk-XK5W7BVE.mjs} +1 -1
- package/lib/{chunk-OZNLOV4U.mjs → chunk-XO5FBOQF.mjs} +1 -1
- package/lib/{chunk-FSDO4DJA.mjs → chunk-XSKPYGMT.mjs} +1 -1
- package/lib/{chunk-AITNZWLB.mjs → chunk-XU25YA46.mjs} +1 -1
- package/lib/{chunk-XEB6HZ34.mjs → chunk-XZISAZA6.mjs} +1 -1
- package/lib/chunk-Y4TDVDP2.mjs +13 -0
- package/lib/{chunk-4L7FBOJS.mjs → chunk-YAIIRFKJ.mjs} +1 -1
- package/lib/{chunk-T3PLRQ2T.mjs → chunk-YAJQS3OL.mjs} +1 -1
- package/lib/{chunk-Y5ZCPY36.mjs → chunk-YGJF55VJ.mjs} +1 -1
- package/lib/chunk-YH4DYI6D.mjs +7 -0
- package/lib/{chunk-R6TF26V4.mjs → chunk-YMDFF657.mjs} +1 -1
- package/lib/{chunk-JU2XEKEO.mjs → chunk-YT22LMF7.mjs} +1 -1
- package/lib/{chunk-NWVVCZUK.mjs → chunk-Z42PHCVZ.mjs} +1 -1
- package/lib/{chunk-O6ADMP36.mjs → chunk-ZHIZY3ZC.mjs} +1 -1
- package/lib/chunk-ZQO5PDX5.mjs +48 -0
- package/lib/{chunk-QXLZINZB.mjs → chunk-ZUBBEP75.mjs} +1 -1
- package/lib/{chunk-SQGP46QS.mjs → chunk-ZUOPC4W2.mjs} +1 -1
- package/lib/{chunk-3B5H24ZG.mjs → chunk-ZUTUYBNW.mjs} +1 -1
- package/lib/{chunk-K55LH4ZQ.mjs → chunk-ZXFL2MSN.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 +1 -1
- package/lib/sandforge-env.mjs +185 -139
- package/lib/sandforge-frozen.mjs +1 -1
- package/lib/sandforge-mcp.mjs +14 -14
- 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 +157 -0
- package/lib/sandforge.mjs +1 -22
- package/lib/sf/sandforge/autopilot.mjs +20 -0
- package/lib/sf/sandforge/backup.mjs +20 -0
- package/lib/sf/sandforge/checkpoint.mjs +20 -0
- package/lib/sf/sandforge/cleanup.mjs +20 -0
- package/lib/sf/sandforge/clone.mjs +20 -0
- package/lib/sf/sandforge/compare.mjs +20 -0
- package/lib/sf/sandforge/dataops.mjs +20 -0
- package/lib/sf/sandforge/empty.mjs +20 -0
- package/lib/sf/sandforge/env.mjs +20 -0
- package/lib/sf/sandforge/frozen.mjs +20 -0
- package/lib/sf/sandforge/hardis-commands.mjs +20 -0
- package/lib/sf/sandforge/index.mjs +20 -0
- package/lib/sf/sandforge/mcp.mjs +20 -0
- package/lib/sf/sandforge/monitor.mjs +20 -0
- package/lib/sf/sandforge/pipeline.mjs +20 -0
- package/lib/sf/sandforge/seed.mjs +20 -0
- package/lib/sf/sandforge/sync.mjs +20 -0
- package/lib/sf/sandforge/users.mjs +20 -0
- package/lib/sfHelpHook.mjs +7 -0
- package/lib/sfPlugin.mjs +11 -0
- package/oclif.manifest.json +1 -0
- package/package.json +17 -3
- package/lib/chunk-2ZMGVBLW.mjs +0 -7
- package/lib/chunk-5C5XEVZN.mjs +0 -11
- package/lib/chunk-5CKWGZX4.mjs +0 -9
- package/lib/chunk-5ZKCLBTN.mjs +0 -474
- package/lib/chunk-7DALDJMO.mjs +0 -7
- package/lib/chunk-DPYTG6DM.mjs +0 -48
- package/lib/chunk-G4VXPS3A.mjs +0 -7
- package/lib/chunk-GF247DA7.mjs +0 -7
- package/lib/chunk-IKGHRYCN.mjs +0 -7
- package/lib/chunk-IM2XA6JI.mjs +0 -7
- package/lib/chunk-K5HV4YRO.mjs +0 -7
- package/lib/chunk-N6HHNR6J.mjs +0 -7
- package/lib/chunk-O7DAFE6M.mjs +0 -14
- package/lib/chunk-R2BJWO5N.mjs +0 -20
- package/lib/chunk-T26C576X.mjs +0 -9
- package/lib/chunk-V473C7LY.mjs +0 -7
- package/lib/chunk-WD47PGUS.mjs +0 -10
- package/lib/chunk-XC54KKKC.mjs +0 -7
- package/lib/chunk-XGKSSCW7.mjs +0 -7
- package/lib/chunk-ZWCRWF7E.mjs +0 -7
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{g as v}from"./chunk-
|
|
7
|
+
import{g as v}from"./chunk-L4INJ5TZ.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{l as i}from"./chunk-
|
|
7
|
+
import{l as i}from"./chunk-O2PUGRNW.mjs";function u(o,t){let n=e=>e==="production"?`${t} is taken for a production org, and this command writes to none`:void 0;return new i({requestConfirmation:(e,d)=>{let r=n(d);return r===void 0?Promise.resolve(!0):(o(`refused: ${r} (${e})`),Promise.resolve(!1))},declinesWithoutAsking:n})}export{u as a};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{ke as c}from"./chunk-ZQO5PDX5.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";var y=[{type:"seed",label:"Seed Data",description:"Seed an org with a template saved on the Seed page or shipped with SandForge, never a production org; its records are taken back from Seed\u2019s Recent runs",category:"data",icon:"database",configSchema:{orgId:{type:"string"},templateId:{type:"string"}}},{type:"sync",label:"Sync Data",description:"Run a Sync configuration saved on the Sync page; a target Production Guard asks about, a production org or a sandbox marked Staging, needs an Approval step before it",category:"data",icon:"sync",configSchema:{configId:{type:"string"}}},{type:"backup",label:"Backup",description:"Take a DataOps snapshot of the listed objects into local storage",category:"data",icon:"archive",configSchema:{orgId:{type:"string"},objects:{type:"array"}}},{type:"restore",label:"Restore",description:"Restore data from a previous backup snapshot",category:"data",icon:"history",configSchema:{backupId:{type:"string"}}},{type:"anonymize",label:"Anonymize",description:"Mask an org with a DataOps template, after a snapshot of the values it writes over, never a production org",category:"data",icon:"shield",configSchema:{orgId:{type:"string"},templateId:{type:"string"},object:{type:"string",optional:!0},where:{type:"string",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1}}},{type:"delete",label:"Delete",description:"Delete records matching specified criteria",category:"data",icon:"trash",configSchema:{objectName:{type:"string"},where:{type:"string"}}},{type:"checkpoint",label:"Checkpoint",description:"Take a checkpoint of a sandbox, a scratch org or a Developer Edition org, kept on this machine",category:"data",icon:"bookmark",configSchema:{orgId:{type:"string"},mode:{type:"string",default:"everything"},objects:{type:"array",optional:!0},excluded:{type:"array",optional:!0},name:{type:"string",optional:!0},keepDays:{type:"number",default:c},maxTotal:{type:"number",optional:!0},ignoredFields:{type:"array",optional:!0}}},{type:"rewind",label:"Rewind",description:"Put an org back to a checkpoint kept on this machine, once confirmed by typing the org\u2019s alias, at most maxRecords records",category:"data",icon:"history",configSchema:{orgId:{type:"string"},checkpointId:{type:"string"},objects:{type:"array",optional:!0},acceptAutomation:{type:"boolean",default:!1},acceptEmails:{type:"boolean",default:!1},muteAutomation:{type:"boolean",default:!1},acceptNoUndo:{type:"boolean",default:!1},acceptRecreate:{type:"boolean",default:!1},acceptOutside:{type:"boolean",default:!1},acceptUnseen:{type:"boolean",default:!1},maxRecords:{type:"number",required:!0},refuseWhenActive:{type:"boolean",default:!0}}},{type:"compare",label:"Compare Orgs",description:"Compare the metadata of two orgs, as the Compare page does",category:"quality",icon:"git-compare",configSchema:{sourceOrgId:{type:"string"},targetOrgId:{type:"string"},types:{type:"array"}}},{type:"precheck",label:"Pre-check",description:"Read an org\u2019s API usage, storage, error logs or failed jobs as the Monitor does; the run stops on a critical reading",category:"quality",icon:"check-circle",configSchema:{orgId:{type:"string"},checks:{type:"array"}}},{type:"condition",label:"Condition",description:"Branch pipeline execution based on conditions",category:"control",icon:"git-branch",configSchema:{field:{type:"string"},operator:{type:"string"},value:{type:"string"}}},{type:"delay",label:"Delay",description:"Wait for a specified duration before continuing",category:"control",icon:"clock",configSchema:{durationMs:{type:"number"}}},{type:"approval",label:"Approval",description:"Pauses the run until someone approves it in VS Code; a rejection, or no answer in time, stops it",category:"control",icon:"user-check",configSchema:{message:{type:"string"},timeoutMinutes:{type:"number"}}},{type:"notification",label:"Notification",description:"Shows its message as a VS Code notification",category:"notification",icon:"bell",configSchema:{message:{type:"string"}}}],p=class{registry;constructor(){this.registry=new Map(y.map(e=>[e.type,e]))}getStepTypes(){return[...this.registry.values()]}getStepType(e){return this.registry.get(e)}getDefaultConfig(e){let r=this.registry.get(e);if(!r)return{};let o={};for(let[t,a]of Object.entries(r.configSchema)){let n=a;if(!(n.optional===!0||n.required===!0)){if("default"in n){o[t]=n.default;continue}switch(n.type){case"string":o[t]="";break;case"number":o[t]=0;break;case"array":o[t]=[];break;case"boolean":o[t]=!1;break;default:o[t]=null}}}return o}validateStepConfig(e,r){let o=this.registry.get(e);if(!o)return[`Unknown step type: ${e}`];let t=[];for(let[a,n]of Object.entries(o.configSchema)){let l=n,i=r[a],s=l.type;i!=null&&(s==="array"&&!Array.isArray(i)?t.push(`Field "${a}" must be an array`):s==="string"&&typeof i!="string"?t.push(`Field "${a}" must be a string`):s==="number"&&typeof i!="number"?t.push(`Field "${a}" must be a number`):s==="boolean"&&typeof i!="boolean"&&t.push(`Field "${a}" must be a boolean`))}return t}getStepCategories(){let e=new Set;for(let r of this.registry.values())e.add(r.category);return[...e]}};export{p as StepLibrary};
|
|
@@ -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-6GQUZ4IP.mjs";import"./chunk-ZQO5PDX5.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SeedValidator};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire as __sandforgeRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __sandforgePath } from 'node:url';
|
|
3
|
+
import { dirname as __sandforgeDirname } from 'node:path';
|
|
4
|
+
const require = __sandforgeRequire(import.meta.url);
|
|
5
|
+
const __filename = __sandforgePath(import.meta.url);
|
|
6
|
+
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
+
import{f as a,g as b,h as c,i as d,j as e,k as f,l as g}from"./chunk-MKTXJCXN.mjs";import"./chunk-GBGHJTPC.mjs";import"./chunk-YMDFF657.mjs";import"./chunk-YT22LMF7.mjs";import"./chunk-66NMFCWX.mjs";import"./chunk-XU25YA46.mjs";import"./chunk-7SDZR6SR.mjs";import"./chunk-54HYHHVL.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-SAMWHL22.mjs";import"./chunk-6KP6WETK.mjs";import"./chunk-4JKR4PTZ.mjs";import"./chunk-J24TIGSI.mjs";import"./chunk-VPDEJGPS.mjs";import"./chunk-5LFSFYFJ.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-INIT2UKJ.mjs";import"./chunk-HFUDCNU5.mjs";import"./chunk-XZISAZA6.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-PC247GKX.mjs";import"./chunk-EADHKH3A.mjs";import"./chunk-L4INJ5TZ.mjs";import"./chunk-KIMQQ6JQ.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-ZUTUYBNW.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-ICIYL45C.mjs";import"./chunk-PR74GYVI.mjs";import"./chunk-TMA34QMA.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-ZQO5PDX5.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{d as diffOfPicked,b as heldInPlaceReason,g as planSelection,c as rewindPlan,a as rewindWriters,f as selectionPlanOf,e as snapshotRowsOf};
|
|
@@ -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-KIMQQ6JQ.mjs";import{b as h}from"./chunk-CA5NAXSU.mjs";import{g as T}from"./chunk-ZUTUYBNW.mjs";import{ic as y}from"./chunk-ZQO5PDX5.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,5 +4,5 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{c as u}from"./chunk-
|
|
7
|
+
import{c as u}from"./chunk-Z42PHCVZ.mjs";import{Ka as d,Rb as f}from"./chunk-ZQO5PDX5.mjs";import{mkdir as h,readdir as g,readFile as m,rename as w,writeFile as S}from"node:fs/promises";import*as c from"node:path";var k=".sandforge-scenario.json",P={depth:3,files:50},y=new Set(["node_modules","dist","out","coverage"]),E=10;function O(){return{list:async r=>{try{return(await g(r,{withFileTypes:!0})).map(e=>({name:e.name,folder:e.isDirectory()}))}catch(t){let e=t.code;if(e==="ENOENT"||e==="ENOTDIR"||e==="EACCES")return[];throw t}},readFile:r=>m(r,"utf8"),writeNew:async(r,t)=>{await h(c.dirname(r),{recursive:!0});try{return await S(r,t,{encoding:"utf8",flag:"wx"}),!0}catch(e){if(e.code==="EEXIST")return!1;throw e}},replace:async(r,t)=>{let e=`${r}.${process.pid}.tmp`;await S(e,t,"utf8"),await w(e,r)}}}function x(r){let t;try{t=JSON.parse(r)}catch{return{issues:["The file is not JSON"]}}let e=d.safeParse(t);return e.success?{pack:e.data}:{issues:e.error.issues.slice(0,E).map(n=>`${n.path.join(".")||"the file"}: ${n.message}`)}}async function F(r,t){let e=[],n=async(a,o,i)=>{let p=[...await r.list(o)].sort((s,l)=>s.name.localeCompare(l.name));for(let s of p){if(e.length>=P.files)return;let l=c.join(o,s.name);s.folder?i<P.depth&&!v(s.name)&&await n(a,l,i+1):s.name.endsWith(k)&&e.push({path:l,relativePath:c.relative(a,l).split(c.sep).join("/")})}};for(let a of t)await n(a,a,0);return e}function v(r){return r.startsWith(".")||y.has(r)}async function N(r,t){let e=f.map(n=>({source:"built-in",pack:n}));for(let n of await F(r,t)){let a;try{a=await r.readFile(n.path)}catch{e.push({source:"workspace",...n,issues:["The file could not be read"]});continue}let o=x(a);e.push({source:"workspace",...n,...o})}return e}function A(r){return`${JSON.stringify(r,null,2)}
|
|
8
8
|
`}async function T(r,t,e,n=!1){let a=t[0];if(a===void 0)return{kind:"no-workspace"};let o=d.parse(e),i=`${o.id}${k}`,p=c.join(a,i),s=A(o);if(n)await r.replace(p,s);else if(!await r.writeNew(p,s))return{kind:"exists",path:p,relativePath:i};return{kind:"saved",path:p,relativePath:i}}async function b(r,t,e,n){let a=i=>i.id===e&&u(i)===n,o=f.find(a);if(o)return o;for(let i of await N(r,t))if(i.source==="workspace"&&"pack"in i&&a(i.pack))return i.pack}export{k as a,P as b,O as c,x as d,F as e,N as f,A as g,T as h,b as i};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{a as N,b as O}from"./chunk-CA5NAXSU.mjs";import{c as I}from"./chunk-UNDIBZWG.mjs";import{b as l,n as m}from"./chunk-WZQEK4WT.mjs";var V="tooling",M={GenAiPlannerDefinition:["Id","DeveloperName","MasterLabel"],GenAiPlannerFunctionDef:["PlannerId","Plugin"],GenAiPluginDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPluginFunctionDef:["PluginId","Function"],GenAiFunctionDefinition:["Id","DeveloperName","LocalDeveloperName","MasterLabel","Description"],GenAiPlannerAttrDefinition:["ParentId","DeveloperName","ParameterName"]},_="DeveloperName",y=200,j="This org has no Agentforce agent: the records this run wrote stay, usable as they are. Create an agent in Setup > Agentforce Agents, then write the test file from this run.",v="This org has no Agentforce, which takes a Salesforce license: it has no GenAiPlannerDefinition, the object that lists its agents. The records this run wrote stay, usable as they are.",g=l().nullish().transform(n=>n==null||n===""?void 0:n),z={GenAiPlannerDefinition:m({Id:l().min(1),DeveloperName:l().min(1),MasterLabel:g}),GenAiPlannerFunctionDef:m({PlannerId:l().min(1),Plugin:g}),GenAiPluginDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPluginFunctionDef:m({PluginId:l().min(1),Function:g}),GenAiFunctionDefinition:m({Id:l().min(1),DeveloperName:l().min(1),LocalDeveloperName:g,MasterLabel:g,Description:g}),GenAiPlannerAttrDefinition:m({ParentId:l().min(1),DeveloperName:l().min(1),ParameterName:g})},D=class extends Error{constructor(t,d,s){super(s);this.object=t;this.code=d;this.name="CatalogRefusal"}object;code};async function W(n){try{let e=await E(n,"GenAiPlannerDefinition");if(e.length===0)return{kind:"no-agent",reason:"none",message:j};let t=e.map(a=>a.Id),d=await A(n,"GenAiPlannerFunctionDef","PlannerId",t),s=await A(n,"GenAiPlannerAttrDefinition","ParentId",t),o=await A(n,"GenAiPluginDefinition","Id",d.map(a=>a.Plugin)),i=await A(n,"GenAiPluginFunctionDef","PluginId",o.map(a=>a.Id)),r=await A(n,"GenAiFunctionDefinition","Id",i.map(a=>a.Function)),f=G(o),L=G(r),T=a=>{let u=R(i.filter(p=>b(p.PluginId,a)).map(p=>p.Function),L);return{actions:u.items,unnamedActions:u.unnamed}};return{kind:"agents",catalog:{agents:e.map(a=>{let u=R(d.filter(c=>b(c.PlannerId,a.Id)).map(c=>c.Plugin),f),p=u.items.map((c,x)=>{let w=u.rows[x];return w?{...c,...T(w.Id)}:{...c,actions:[],unnamedActions:0}});return{id:a.Id,name:a.DeveloperName,...a.MasterLabel!==void 0?{label:a.MasterLabel}:{},topics:p,unnamedTopics:u.unnamed,variables:s.filter(c=>b(c.ParentId,a.Id)).map(c=>({name:c.DeveloperName,...c.ParameterName!==void 0?{parameterName:c.ParameterName}:{}}))}}).sort((a,u)=>C(a.name,u.name))}}}catch(e){if(!(e instanceof D))throw e;return e.object==="GenAiPlannerDefinition"&&e.code==="INVALID_TYPE"?{kind:"no-agent",reason:"no-agentforce",message:v}:{kind:"unreadable",object:e.object,message:`The org would not read ${e.object}: ${e.message}`}}}function H(n,e){return n.agents.find(t=>t.name===e)}function Z(n,e){return n.topics.find(t=>t.name===e)?.actions.map(t=>t.name)??[]}var h=["Off_Topic"];function B(n){return n.topics.find(e=>h.includes(e.name)||h.includes(e.localName??""))?.name}function U(n,e){return n.variables.some(t=>t.name===e||t.parameterName===e)}async function E(n,e,t){let d=`SELECT ${M[e].join(", ")} FROM ${e}${t?` WHERE ${t}`:""}`,s;try{s=await n(d)}catch(i){let r=O(i);throw new D(e,k(i)??N(r),r)}let o=z[e];return s.map(i=>{let r=o.safeParse(i);if(!r.success){let f=r.error.issues[0];throw new D(e,void 0,`a row has no ${f.path.join(".")} the catalog can read (${f.message})`)}return r.data})}async function A(n,e,t,d){let s=[...new Set(d.filter(i=>i!==void 0&&I(i)))],o=[];for(let i=0;i<s.length;i+=y){let r=s.slice(i,i+y).map(f=>`'${f}'`);o.push(...await E(n,e,`${t} IN (${r.join(", ")})`))}return o}function k(n){if(typeof n!="object"||n===null)return;let{errorCode:e,name:t}=n;if(typeof e=="string"&&e!=="")return e;if(typeof t=="string"&&/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(t))return t}function P(n){return n.slice(0,15)}function b(n,e){return P(n)===P(e)}function G(n){return new Map(n.map(e=>[P(e.Id),e]))}function R(n,e){let t=new Map,d=0;for(let o of n){if(o===void 0)continue;if(!I(o)){t.has(o)||t.set(o,{item:{name:o,described:!1}});continue}let i=e.get(P(o));if(!i){d++;continue}let r=i[_];t.has(r)||t.set(r,{row:i,item:{name:r,...i.LocalDeveloperName!==void 0?{localName:i.LocalDeveloperName}:{},...i.MasterLabel!==void 0?{label:i.MasterLabel}:{},...i.Description!==void 0?{description:i.Description}:{},described:!0}})}let s=[...t.values()].sort((o,i)=>C(o.item.name,i.item.name));return{items:s.map(o=>o.item),rows:s.map(o=>o.row),unnamed:d}}function C(n,e){return n<e?-1:n>e?1:0}export{V as a,M as b,_ as c,j as d,v as e,W as f,H as g,Z as h,h as i,B as j,U as k};
|
|
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{a as _}from"./chunk-
|
|
7
|
+
import{a as _}from"./chunk-ZUTUYBNW.mjs";import{k as S}from"./chunk-ZQO5PDX5.mjs";var x="#N/A";function I(e,t,r){let n=[],o=new Map,a=t.map(u=>{let m=new Map;for(let[b,h]of D(e,u)){let p=b.toLowerCase(),i=o.get(p);i===void 0&&(i=n.push(b)-1,o.set(p,i)),m.set(i,$(h))}return m}).map(u=>n.map((m,b)=>u.get(b)??"")),l=[n.map(C).join(",")];for(let u of a)l.push(u.length===1&&u[0]===""?'""':u.map(C).join(","));return{text:`${l.join(`
|
|
8
8
|
`)}
|
|
9
9
|
`,columns:n,rows:a,identity:U(e,n,r)}}function y(e,t,r){let n=r==="exact"?E:A;return JSON.stringify(t.map(o=>n(e[o]??"")))}function ue(e){let t=new Map,r=new Set;return e.rows.forEach((n,o)=>{let c=y(n,e.identity,"canonical"),a=t.get(c);a===void 0?t.set(c,o):(r.add(a),r.add(o))}),r}function ie(e){let t=[];for(let[r,n]of e){let o=A(n);o!==""&&t.push(`${r.toLowerCase()}${o}`)}return t.sort().join("")}function J(e,t){return e.map(r=>{let n=t[r];return typeof n=="string"?n:n==null?"":String(n)})}function D(e,t){if(e==="delete"||e==="hardDelete")return[["Id",t.Id]];let r=[];for(let[n,o]of Object.entries(t))n==="attributes"||n==="type"||e==="insert"&&n.toLowerCase()==="id"||O(n,o,r);return r}function O(e,t,r){if(!N(t)){r.push([e,t]);return}for(let[n,o]of Object.entries(t))n!=="attributes"&&O(`${e}.${n}`,o,r)}function N(e){if(e===null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function $(e){return e===void 0?"":e===null?x:typeof e=="string"?e:e instanceof Date?Number.isNaN(e.getTime())?"":e.toISOString():typeof e=="object"?JSON.stringify(e):String(e)}function C(e){return/[",\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e}function U(e,t,r){let n=e==="insert"?void 0:e==="upsert"?r:"Id",o=n===void 0?-1:t.findIndex(c=>c.toLowerCase()===n.toLowerCase());return o>=0?[o]:t.map((c,a)=>a)}function E(e){return e===x?"":e.replace(/\r\n?/g,`
|
|
10
10
|
`)}var T=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/,v=/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function A(e){let t=E(e),r=t.toLowerCase();if(r==="true"||r==="false")return r;if(T.test(t))return String(Number(t));let n=v.exec(t);if(n){let o=t.includes("T")&&n[1]===void 0,c=Date.parse(o?`${t}Z`:t);if(!Number.isNaN(c))return`@${c}`}return _(t)??t}var F="No result returned by Bulk API job",K="Record not processed by Bulk API job",B=10,w=5e3;function H(e){if(e===!0||e==="true")return!0;if(e===!1||e==="false")return!1}function z(e,t,r){let n=t.rows.length,o=[],c=[],a=0,l=[],u=new Array(n).fill(!1),m=(i,s,g)=>{s>=0&&s<n&&!u[s]?(u[s]=!0,o.push({recordIndex:s,id:i,success:!0,...g!==void 0?{created:g}:{}})):(a++,i!==void 0&&c.push(i))},b=(i,s,g)=>{s>=0&&s<n&&!u[s]?(u[s]=!0,o.push({recordIndex:s,success:!1,error:i,...g?{state:g}:{}})):l.push(i)},h=r?` (${r})`:"";if(Array.isArray(e))e.forEach((i,s)=>{i.success?m(i.id,s):b(i.errors?.join(", ")??"Unknown error",s)});else{let i=[];for(let f of e.successfulResults??[]){let k=typeof f.sf__Id=="string"?f.sf__Id:void 0,R=H(f.sf__Created);i.push({row:f,settle:d=>m(k,d,R),orphan:()=>m(k,-1)})}for(let f of e.failedResults??[]){let k=typeof f.sf__Error=="string"&&f.sf__Error.length>0?f.sf__Error:"Unknown error";i.push({row:f,settle:R=>b(k,R),orphan:()=>b(k,-1)})}let s=e.unprocessedRecords;for(let f of Array.isArray(s)?s:[]){let k=`${K}${h}`;i.push({row:f,settle:R=>b(k,R,"unprocessed"),orphan:()=>b(k,-1)})}let g=i;for(let f of["exact","canonical"])g.length>0&&(g=W(f,g,t,u));for(let f of g)f.orphan()}let p=`${F}${h}${Z(c,l)}`;for(let i=0;i<n;i++)u[i]||b(p,i,"no-result");return o.sort((i,s)=>i.recordIndex-s.recordIndex),{outcomes:o,unattributedSuccessIds:c,unattributedSuccesses:a,unattributedFailures:l}}function W(e,t,r,n){let o=new Map;r.rows.forEach((a,l)=>{if(n[l])return;let u=y(a,r.identity,e),m=o.get(u);m?m.push(l):o.set(u,[l])});let c=[];for(let a of t){let l=y(J(r.columns,a.row),r.identity,e),u=o.get(l)?.shift();u===void 0?c.push(a):a.settle(u)}return c}function Z(e,t){let r=[];if(e.length>0){let n=e.slice(0,B).join(", "),o=e.length>B?` and ${e.length-B} more`:"";r.push(`wrote ${e.length} record(s) no row was matched to: ${n}${o}`)}return t.length>0&&r.push(`did not write ${t.length} row(s) no row was matched to, the first for: ${t[0]}`),r.length>0?`; the job ${r.join("; it ")}`:""}function V(e){let t;try{t=e.id}catch{return}return typeof t=="string"&&/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/.test(t)?t:void 0}function q(e){if(e.state!=="JobComplete")return e.errorMessage||`job ${e.state}`}async function X(e){try{await e.abort()}catch{}}var P=class{threshold;constructor(t=S.REST_API_BATCH_SIZE){this.threshold=t}shouldUseBulkApi(t){return t>this.threshold}getThreshold(){return this.threshold}async executeBulk(t,r,n,o,c){if(!t.bulkManager.canStartNewJob())throw new Error("Maximum concurrent bulk jobs reached");let a=I(n,o,c),l=t.connection.bulk2.createJob({operation:n,object:r,...c?{externalIdFieldName:c}:{}}),u=l.id??`bulk-${crypto.randomUUID()}`,m={id:u,operation:n,object:r,state:"UploadComplete",numberRecordsProcessed:0,numberRecordsFailed:0,totalProcessingTime:0,createdDate:new Date().toISOString()};t.bulkManager.registerJob(m);try{await l.open();let b=V(l);b!==void 0&&t.onOpened?.(b);let h=0;if(t.signal?.aborted||(await l.uploadData(a.text),h=o.length),t.signal?.aborted)return await X(l),t.bulkManager.updateJobState(u,"Aborted"),{totalRecords:h,successCount:0,failureCount:0,failures:[],jobId:u,usedBulkApi:!0,successIds:[],outcomes:[],aborted:!0};await l.close();let p=await l.check();for(let d=0;p.state==="InProgress"||p.state==="UploadComplete";d++){t.bulkManager.updateJobState(u,p.state),t.onProgress?.(p.numberRecordsProcessed??0,o.length);let M=t.pollIntervalMs?.(d)??w;await new Promise(j=>setTimeout(j,M)),p=await l.check()}let i=await l.getAllResults(),s=z(i,a,q(p)),g=s.outcomes.filter(d=>!d.success).map(d=>({recordIndex:d.recordIndex,error:d.error??"Unknown error"}));for(let d of s.unattributedFailures)g.push({recordIndex:-1,error:d});let f=s.outcomes.filter(d=>d.success&&d.id!==void 0).map(d=>d.id).concat(s.unattributedSuccessIds),k=s.outcomes.filter(d=>d.success).length+s.unattributedSuccessIds.length,R=p.state==="JobComplete"?"JobComplete":"Failed";return t.bulkManager.updateJobState(u,R),t.bulkManager.updateJobCounts(u,p.numberRecordsProcessed??o.length,g.length),{totalRecords:o.length,successCount:k,failureCount:g.length,failures:g,jobId:u,usedBulkApi:!0,successIds:f,outcomes:s.outcomes,...s.unattributedSuccessIds.length>0?{unmatchedIds:s.unattributedSuccessIds}:{},...s.unattributedSuccesses>0?{unmatchedWrites:s.unattributedSuccesses}:{}}}catch(b){throw t.bulkManager.updateJobState(u,"Failed"),b}}};var G=3,Q=3,Y=24,ee=750,L=()=>w,be=e=>[5e3,1e4,2e4][e]??3e4,te=60;function ne(e){return Q+e.stateReads+(e.resultReads??G)}function re(e,t="delete"){let r=t==="save"?te:ee;return Y+Math.max(0,e)/r}function oe(e,t=L,r="delete"){let n=re(e,r)*1e3,o=0,c=0;for(;o<n;)o+=Math.max(1,t(c)),c++;return 1+c}function ge(e){return ne({stateReads:oe(e,L,"save")})}export{I as a,ue as b,ie as c,z as d,V as e,q as f,X as g,P as h,G as i,be as j,ne as k,re as l,oe as m,ge as n};
|
|
@@ -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 je,b as Ne,c as Pe,d as Fe,k as We,l as xe,o as Le,q as _e}from"./chunk-
|
|
7
|
+
import{a as je,b as Ne,c as Pe,d as Fe,k as We,l as xe,o as Le,q as _e}from"./chunk-JESRFE2Z.mjs";import{e as Me}from"./chunk-CBL42DUU.mjs";import{b as De,f as Te}from"./chunk-MKTXJCXN.mjs";import{m as Be}from"./chunk-RCYEBY42.mjs";import{b as ve}from"./chunk-DBBPDSFN.mjs";import{i as he,j as we,k as ke,l as ye,m as be,p as Re,q as Ae}from"./chunk-VZT4E2OJ.mjs";import{A as Ie,B as $e,y as Se,z as Ue}from"./chunk-O2PUGRNW.mjs";import{C as ge}from"./chunk-7SDZR6SR.mjs";import{a as le,b as fe}from"./chunk-54HYHHVL.mjs";import{i as Oe,j as Ce}from"./chunk-SAMWHL22.mjs";import{b as pe}from"./chunk-HKUWHVI7.mjs";import{b as ue,d as ce}from"./chunk-VPDEJGPS.mjs";import{c as me}from"./chunk-JQZTMFO7.mjs";import{fc as Ee}from"./chunk-JFNLKHY6.mjs";import{g as L,h as _,q as de}from"./chunk-L4INJ5TZ.mjs";import{b as x}from"./chunk-CA5NAXSU.mjs";import{Ad as se,Id as W}from"./chunk-ZQO5PDX5.mjs";var C=class extends Error{constructor(){super("The undo was stopped before it wrote anything to the org."),this.name="UndoStopped"}},z="No record was written.",Je="accept that it runs to undo the rewind all the same";function ze(e){return e.slice(0,15)}function Ke(e){return{query:n=>e.query(n),queryMore:n=>e.queryMore(n)}}function Ye(e,n,t){if(e.kind==="org")return;let a=e.userKey;if(n.users.some(i=>i.slice(0,15)!==a))return{code:"PERMISSIONS",message:`This rewind was made as another user than ${t}: what it deleted is that user's deletion in the recycle bin, which Salesforce brings back only for a user with View All Data and Modify All Data. Undo it as the user it was made as, or as a user with View All Data and Modify All Data. ${z}`};let r=n.objects.flatMap(i=>{let l=e.notHeld.get(i);return l===void 0?[]:[`${i}: ${l}`]});if(r.length!==0)return{code:"PERMISSIONS",message:`Undo takes back what the rewind did to objects ${t} no longer holds whole (${r.join("; ")}), and does not stop part way: an undo left part way could not be offered again. Undo it once the user has View All and Modify All on them again, or as a user with View All Data and Modify All Data. ${z}`}}function Qe(e,n){return{undone:!1,refusal:{code:e,message:n}}}function Xe(e,n){return{code:"RUN_WRITING",message:`${n.operation==="take"?`A checkpoint of ${e} is being taken`:n.operation==="rewind"?`A rewind is writing to ${e}`:n.operation==="undo"?`An undo is writing to ${e}`:`SandForge is deleting checkpoints of ${e}`} (process ${n.pid} on ${n.host}): undo the rewind once it has ended. No record was read or written.`}}function Ze(e,n,t,a){let r=W(n,t),i=[...new Set(r.map(b=>b.objectApiName))],l=(t.setToDraft??[]).length>0?", sets an order back to Draft":"",h=r.length>0?`${Me(r)} flow(s), trigger(s) or rule(s) of ${i.join(", ")} run as the undo brings records back, gives them their values back${l} or sends them back to the recycle bin`:"what runs as the undo writes could not all be read, so automation may run";return{code:"AUTOMATION",message:`${e}: ${h}. ${ke("undo",a)}Undo refused; ${Je}. ${z}`}}async function et(e,n){let t=0,a=0;for await(let r of n.bringBack.pages(L)){t+=r.length;for(let i of ce(r,ue)){let l=await e.queryDeleted(`SELECT Id, ContentSize FROM ${L} WHERE Id IN (${i}) AND IsDeleted = true`);for(let h of l.records)typeof h.ContentSize=="number"&&(a+=h.ContentSize)}}return{files:t,bytes:a}}function tt(e,n){return e.status==="cancelled"||e.status==="failure"?e.status:n.some(t=>t.reason==="changedDuringRewind")?"unstable":e.status}function nt(e,n){return e.map(t=>{let a=Object.keys(t.by).filter(i=>!n.has(ze(i)));if(a.length===0)return{objectApiName:t.objectApiName,reason:"automation",count:t.count,ids:[...t.ids]};let r=a.length===1&&a[0]!=="unknown"?a[0]:void 0;return{objectApiName:t.objectApiName,reason:"changedDuringRewind",...r!==void 0?{by:r}:{},count:t.count,ids:[...t.ids]}})}async function Ot(e,n){let{checkpoint:t,folder:a,orgName:r,rewindId:i}=n,l=e.signal,h=()=>l?.aborted===!0,b=(U,k)=>e.onProgress?.({percentage:U,step:k}),c=_e(e.org,e.undelete),T,S=await ve(Ke(c.org),{act:"undo",orgName:r,registered:n.registered,username:n.username,organizationId:t.org.organizationId,customSettings:de(t)},{userId:async()=>T=await c.org.userId()});if(!S.allowed)return{undone:!1,refusal:S.refusal};let R=e.store.lock(t.org.organizationId,"undo",t.checkpointId);if("busy"in R)return{undone:!1,refusal:Xe(r,R.busy)};try{let U=await e.runWriting?.(S.org.id);if(U!==void 0)return Qe("RUN_WRITING",U);let k=await Ue(c.org,r);if(h())throw new C;b(5,"Reading what the rewind did");let g=await Ne(a,i,t.objects),G=Pe(g),M=g.goesWithParent.objects,Ge=g.remade.keys.size>0?"Sending back to the recycle bin what the rewind brought back, and deleting again what it made again":"Sending back to the recycle bin what the rewind brought back",A=o=>o.filter(u=>u.count>0).map(u=>u.objectApiName),j=g.links,q=o=>o>0?[_]:[],N=g.remade.objects.filter(({objectApiName:o,count:u})=>u>0&&ge([o]).length>0),m={bringBack:A(g.bringBack.objects),giveBack:[...A(g.giveBack.objects),...q(j?.share.count??0)],...N.length>0?{setToDraft:A(N)}:{},delete:[...new Set([...A(M),...A(g.remove.objects),...q(j?.remove.count??0)])],...(j?.reinsert.count??0)>0?{recreate:[_]}:{}},H;try{H=await et(c.org,g)}finally{await g.dispose()}let V=$e("undo",H,k.fileStorage?.remaining,r);if(V)return{undone:!1,refusal:V};let w=[...new Set([...m.bringBack??[],...m.giveBack??[],...m.setToDraft??[],...m.delete??[],...m.recreate??[]])],P;try{P=await De({grants:S.grants,...T!==void 0?{userId:T}:{},username:n.username,checkpoint:t,reader:Ce(c.org,l)})}catch(o){throw o instanceof Oe||h()?new C:o}if(P.kind==="perObject"){let o=await je(a,i),u=Ye(P,{users:o.passes.map(f=>f.userId),objects:w},n.username);if(u)return{undone:!1,refusal:u}}let d;if(w.length>0&&e.readAutomation){try{d=await e.readAutomation(w)}catch(o){d=Le(w,x(o))}c.add(d.requests)}let I=d,y=w.length>0?await We(e.mute,d,m):{},$="refusal"in y?y:void 0,J="refusal"in y?void 0:y.mute;y.automation&&(d=y.automation);let v=$?$.plan:J?.plan,K=n.acceptEmails===!0,p=w.length>0&&I?await Re({act:"undo",orgName:r,automation:I,steps:m,...v?{plan:v}:{},accepted:K,mayMute:e.mute===void 0&&n.canMute===!0,read:()=>me(c.org)}):void 0,Y=he(G,M,N),Q=d?we(Y,d):void 0,O=$?[$.refusal]:[];d&&!n.acceptAutomation&&(W(d,m).length>0||se(d.unread)||Q!==void 0)&&O.push(Ze(r,d,m,Q));let X=Se({objects:t.objects,rewound:G,along:M,automationRequests:0}),Z=Ee(p?.ofRun),ee=Ie("undo",{run:c.used()-(Z.deliverability??0)+X.apiRequests,...Z},k,r);w.length>0&&ee&&O.push(ee);let te=d?be("undo",ye(Y,d,k.emails),r):void 0;w.length>0&&te&&O.push(te),p?.refusal&&O.push(p.refusal);let[ne,...oe]=O;if(ne)return{undone:!1,refusal:ne,...oe.length>0?{alsoRefused:oe}:{}};if(h())throw new C;let qe=await c.org.userId(),He=new Set(Te(t.takenBy,qe).map(ze));b(20,"Bringing back what the rewind deleted and giving back what it wrote over");let B,E;try{E=await xe(J,`undo ${t.checkpointId} ${i}`,o=>{let u=o&&v&&I&&p?Ae({act:"undo",orgName:r,automation:I,steps:m,plan:v,held:o.outcome,planned:p.ofRun.senders,...p.ofRun.read?{reading:p.ofRun.read.reading}:{},accepted:K}):void 0;return u?Promise.resolve({relit:u}):Fe({folder:a,rewindId:i,lock:R.lock,objects:t.objects,org:c.org,undelete:c.undelete,splitting:le(fe(k.remaining,c.used()+X.apiRequests)),...l?{signal:l}:{},...e.onUndeletable?{onUndeletable:e.onUndeletable}:{},onProgress:(f,ae,Ve)=>b(20+Math.round(70*f/Math.max(ae,1)),`${Ge}: ${Ve} ${f} / ${ae}`)})},o=>{B=o})}catch(o){if(!pe(o))throw o;return{undone:!1,refusal:{code:"MUTE",message:`${o.message} No record was written.`}}}if("relit"in E)return{undone:!1,refusal:E.relit};let s=E,re=nt(s.residual,He),D=tt(s,re),F=[...s.notes];if(D!=="cancelled"&&D!=="failure"){let o=(e.now??(()=>new Date))().toISOString();try{await e.store.update(t.checkpointId,f=>f.lastRewind?.rewindId===i?{...f,lastRewind:{...f.lastRewind,undoneAt:o}}:f)}catch(f){F.push(`The checkpoint could not be told the rewind was undone (${x(f)}): its list may still offer to undo it.`)}let u=await Be({folder:a,lock:R.lock,checkpoint:t,rewindId:i,status:D,undoneAt:o});u!==void 0&&F.push(u)}let ie=c.used();return{undone:!0,result:{checkpointId:t.checkpointId,rewindId:i,status:D,deleted:s.deleted,...s.remade?{remade:s.remade}:{},...s.carriedAlone?{carriedAlone:s.carriedAlone}:{},...s.wentAlong?{wentAlong:s.wentAlong}:{},restored:s.restored,undeleted:s.undeleted,...s.files?{files:s.files}:{},residual:re,passes:1,apiRequests:{used:ie,leftToday:Math.max(0,k.remaining-ie)},finishedAt:s.finishedAt,...B?{mutedAutomation:B}:{}},notes:F,...p?.gate.audit!==void 0?{deliverability:p.gate.audit}:{}}}finally{R.lock.release()}}export{C as a,Je as b,Ot as c};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 we,b as ye}from"./chunk-ZUOPC4W2.mjs";import{a as Me,b as Se}from"./chunk-PC247GKX.mjs";import{b as I}from"./chunk-CA5NAXSU.mjs";import{a as X,b as ke,c as Ae}from"./chunk-TUACWKIH.mjs";import{Qd as fe,Rd as K,Sd as ge,Vd as Q,Wd as me,Xd as he,Yd as pe,ic as le}from"./chunk-ZQO5PDX5.mjs";import{b as F,e as ue,k as z,l as j,v as ce,z as W}from"./chunk-WZQEK4WT.mjs";import{randomUUID as qe}from"node:crypto";import{hostname as He,homedir as Je,uptime as We}from"node:os";import{mkdir as Be,readFile as be,readdir as Ye,rename as _e,writeFile as Ge}from"node:fs/promises";import{dirname as ee,join as ne}from"node:path";function Ee(e){let t=e,n=typeof t?.errorCode=="string"?t.errorCode:typeof t?.name=="string"?t.name:void 0;return{success:!1,errors:[{...n?{statusCode:n}:{},message:I(e)}]}}function Pe(e){return(Array.isArray(e)?e[0]:e)??{success:!1,errors:[{message:"the org answered nothing"}]}}function Dt(e){return{typeOrg:()=>we(e),query:async t=>({records:(await e.query(t)).records}),identity:async()=>{let t=await e.identity();return{user_id:t.user_id,organization_id:t.organization_id}},createAssignment:async t=>e.sobject("PermissionSetAssignment").create(t,{headers:le()}).then(Pe,Ee),deleteAssignment:async t=>e.sobject("PermissionSetAssignment").destroy(t).then(Pe,Ee)}}var x=class extends Error{constructor(n){super(n.message);this.refusal=n;this.name="MuteRefusedError"}refusal;get code(){return this.refusal.code}};function Ze(e){return e instanceof x||e instanceof Error&&e.name==="MuteRefusedError"&&"refusal"in e}var Ve=60,Ke=5*6e4,Qe=3e4,Xe=6e4,et=200,tt=448,nt=384,Z=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,C=F().regex(Z),st=j({id:C,permissionSetId:C,permissionSet:F().min(1).max(255)}),rt=j({runId:F().min(1).max(255),host:F().min(1).max(255),pid:ue().int().nonnegative(),hostStartedAt:W.datetime({offset:!0}),acquiredAt:W.datetime({offset:!0}),endsAt:W.datetime({offset:!0}),needs:z(C),assigning:z(C),created:z(st)}),Le=j({version:ce(1),organizationId:C,userId:C,leases:z(rt)}),ot=j(Me),at=Se(e=>{let t=ot.safeParse(e);return t.success?t.data:void 0});function ve(e=process.env,t=Je()){let n=e.SANDFORGE_MUTE_LEASES_DIR;return n!==void 0&&n.trim()!==""?n:ne(t,".sandforge","mute-leases")}function it(e,t,n){if(!Z.test(t)||!Z.test(n))throw new Error("A mute lease is journaled under an org id and a user id.");return ne(e,`${t.slice(0,15)}-${n.slice(0,15)}.json`)}var Ne={host:He(),pid:X.pid,startedAt:X.startedAt},dt=6e4,_=new Set;function xe(e,t,n){return`${e}
|
|
8
|
+
${t}
|
|
9
|
+
${n}`}function ut(e,t,n,s={}){let r=s.now?.()??Date.now();if(!(Date.parse(e.endsAt)>r)||e.assigning.length>0)return!1;if(e.host!==n.host)return!0;if(e.pid===n.pid&&e.hostStartedAt===n.startedAt)return _.has(xe(t,e.runId,e.acquiredAt));let i=s.bootedAt?.()??Date.now()-We()*1e3,c=Date.parse(e.hostStartedAt);return Number.isFinite(c)&&c<i-dt?!1:(s.isAlive??Ae)(e.pid)}var ct=e=>new Promise(t=>setTimeout(t,e));function B(e,t,n){let s=n?.code;return new Error(`The journal of the mute leases in ${ee(e)} could not be ${t}${typeof s=="string"?` (${s})`:""}: the user SandForge runs as must read and write that folder, or SANDFORGE_MUTE_LEASES_DIR name another, the same for every run that mutes the org.`)}function lt(e,t){let n=Date.parse(e.acquiredAt);return{pid:e.pid,host:e.host,here:e.host===t.host,until:new Date((Number.isFinite(n)?n:Date.now())+ke).toISOString()}}function Ce(e){return"A run locks it only while it takes, renews or ends a lease of the same org and user, but "+(e.here?`a lock its process could not remove holds until that process has ended, ${e.until} at the latest.`:`a lock a process of another machine could not remove holds until ${e.until}.`)}function ft(e){return`nothing was assigned. ${Ce(e)} Run again in a moment, or end process ${e.pid} and run again should none of its runs be muting this org.`}async function Y(e,t,n,s,r=ft,i=Xe){let c=n.self??Ne,g={self:c,...n.checks?{checks:n.checks}:{}},h=Date.now()+i;for(await Be(ee(e),{recursive:!0,mode:tt}).catch(u=>{throw B(e,"made",u)});;){let u;try{u=at.acquire(`${e}.lock`,a=>a,g)}catch(a){throw B(e,"locked",a)}if("lock"in u)try{let a=await gt(e,t).catch(l=>{throw B(e,"read",l)});return await s(a,async l=>{let p=`${e}.${process.pid}-${qe()}.tmp`;try{await Ge(p,JSON.stringify(l,null,2),{encoding:"utf8",mode:nt}),await _e(p,e)}catch(w){throw B(e,"written",w)}})}finally{u.lock.release()}if(Date.now()>h){let a=lt(u.busy,c);throw new x({code:"MUTE_FAILED",message:`The journal of the mute leases in ${ee(e)} stayed locked for a minute by process ${a.pid} on ${a.host}: ${r(a)}`})}await ct(et)}}async function gt(e,t){let n={version:1,...t,leases:[]},s;try{s=await be(e,"utf8")}catch(r){if(r.code==="ENOENT")return n;throw r}try{let r=Le.safeParse(JSON.parse(s));if(r.success)return r.data}catch{}return await _e(e,`${e}.${Date.now()}.unreadable`).catch(()=>{}),n}var mt=new Set(["ENTITY_IS_DELETED","INVALID_CROSS_REFERENCE_KEY","NOT_FOUND"]);async function G(e,t,n,s){let r=t.leases.filter(a=>a!==n&&s(a)),i=[...n.created],c=new Set,g=n.assigning[0];if(g!==void 0){let a=new Set(t.leases.flatMap(l=>l===n?[]:l.created.map(p=>p.id))),A=await e.query(`SELECT Id, PermissionSetId, PermissionSet.Name FROM PermissionSetAssignment WHERE AssigneeId = '${t.userId}' AND PermissionSetId IN ('${g}')`).then(l=>l.records).catch(()=>[]);for(let l of A){let p=typeof l.Id=="string"?l.Id:void 0,w=typeof l.PermissionSetId=="string"?l.PermissionSetId:void 0;if(!p||!w||a.has(p)||i.some(v=>v.id===p))continue;let O=l.PermissionSet;i.push({id:p,permissionSetId:w,permissionSet:typeof O?.Name=="string"?O.Name:w}),c.add(p)}}let h={removed:[],passed:[],left:[],found:[]};for(let a of i){let A=r.find(w=>w.needs.includes(a.permissionSetId));if(A){A.created.some(w=>w.id===a.id)||A.created.push(a),h.passed.push(a);continue}let l=await e.deleteAssignment(a.id),p=l.errors?.[0]?.statusCode??l.errors?.[0]?.errorCode;l.success||p!==void 0&&mt.has(p)?(h.removed.push(a),c.has(a.id)&&h.found.push(a)):h.left.push({...a,why:l.errors?.[0]?.message??p??"the org refused the delete"})}let u=t.leases.indexOf(n);return h.left.length===0?t.leases.splice(u,1):t.leases[u]={...n,endsAt:new Date(0).toISOString(),needs:[],assigning:[],created:h.left.map(({id:a,permissionSetId:A,permissionSet:l})=>({id:a,permissionSetId:A,permissionSet:l}))},h}function L(e){return e.map(t=>t.permissionSet)}function $e(e,t){let n=r=>L(r).join(", "),s=[];return e.removed.length>0&&s.push(`What this run had assigned was taken back: ${n(e.removed)}.`),e.passed.length>0&&s.push(`${n(e.passed)} stays assigned for another run that mutes this org as the same user${t?", which takes it back as it ends":""}.`),e.left.length>0&&s.push(`${e.left.map(r=>`${r.permissionSet} (${r.why})`).join(", ")} could not be taken back${t?": the next run that mutes this org takes it back":""}.`),s}function Ie(e,t){return`The journal still names this run's lease: this process tries again while it runs, and releases the lease once the journal can be written; the next run that mutes this org from another process releases it at the latest once process ${e} has ended.`+(t?` Until it is released, and before ${t.until}, a run of another process that ends may leave what it holds of ${t.sets.join(", ")} assigned for that lease, which the release takes back.`:"")}function De(e){let t=e.length===1?"it":"them";return`found assigned to the user the run writes as for a run whose process ended as it assigned ${t}; found by user and set, not by id: had an admin assigned ${t} to that user since, theirs went with ${t}`}async function ht(e,t,n){let s=[];for(let r of[...t.leases])n(r)||s.push(...(await G(e,t,r,n)).found);return s}async function pt(e){let t;try{t=(await e.query("SELECT PermissionsAssignPermissionSets, PermissionsManageUsers FROM UserPermissionAccess")).records[0]}catch(n){return`the org would not say whether the user the run writes as may assign permission sets (${I(n)})`}if(!(t?.PermissionsAssignPermissionSets===!0||t?.PermissionsManageUsers===!0))return"the user the run writes as cannot assign permission sets (neither Assign Permission Sets nor Manage Users)"}function Re(e){let t=e.indexOf("__");return t>0&&!e.slice(t+2).includes("__")?{namespace:e.slice(0,t),developerName:e.slice(t+2)}:{namespace:"",developerName:e}}var Oe=/^[A-Za-z][A-Za-z0-9_]*$/;async function wt(e,t){let s=t.map(Re).filter(c=>Oe.test(c.developerName)&&(!c.namespace||Oe.test(c.namespace)));if(s.length===0)return new Map;let r=await e.query("SELECT Id, Name, NamespacePrefix FROM PermissionSet WHERE Name IN ("+[...new Set(s.map(c=>`'${c.developerName}'`))].join(", ")+")"),i=new Map;for(let c of t){let{namespace:g,developerName:h}=Re(c),u=r.records.find(a=>String(a.Name??"").toLowerCase()===h.toLowerCase()&&String(a.NamespacePrefix??"").toLowerCase()===g.toLowerCase());typeof u?.Id=="string"&&i.set(c,u.Id)}return i}async function Te(e,t,n){if(n.length===0)return new Map;let s=await e.query(`SELECT Id, PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = '${t}' AND PermissionSetId IN (${n.map(i=>`'${i}'`).join(", ")})`),r=new Map;for(let i of s.records){let c=i.PermissionSetId,g=i.Id;typeof c=="string"&&typeof g=="string"&&r.set(c,g)}return r}function te(e,t,n){return{state:t,assigned:[],held:[],permissions:K(e),silenced:e.silenced.map(s=>({...s})),stillRan:e.stillRuns.map(s=>({...s})),...e.assign.length>0?{alsoLifted:(e.alsoLifts??[]).map(s=>({...s}))}:{},...e.liftsUnread?{liftsUnread:e.liftsUnread.map(s=>({...s}))}:{},...n?{reason:n}:{}}}var Ue="nothing found can be muted: no flow, process or workflow rule the run fires has a bypass a permission set of the target holds; the run goes on as without the option";async function yt(e,t,n={}){let s,r;try{let u=await e.typeOrg();s=ye(u),r=u.id}catch(u){return{refused:{code:"MUTE_PRODUCTION",message:`The target did not say what org it is (${I(u)}), and its automation is muted on no org that cannot be told from a production one. Nothing was assigned.`}}}if(s)return{refused:{code:"MUTE_PRODUCTION",message:"The target is a production org: its automation is never muted there, whatever the setting says. Nothing was assigned; run without the option."}};let{plan:i,automation:c,planned:g}=Mt(t,n.writes);if(i.assign.length===0)return{plan:i,automation:t,planned:g,acquire:async()=>({outcome:g,release:async()=>g})};let h=await pt(e);return h!==void 0?{refused:{code:"MUTE_NO_RIGHT",message:`The target's automation cannot be muted: ${h}. Nothing was assigned: run it without muting the target's automation, or have that user given Assign Permission Sets.`}}:(Fe.set(i,await At(n.dir??ve(),r)),{plan:i,automation:c,planned:g,acquire:u=>St(e,i,u,n)})}var Fe=new WeakMap,kt=/^[A-Za-z0-9]{15}-[A-Za-z0-9]{15}\.json$/;async function At(e,t){if(!Z.test(t))return 0;let n=`${t.slice(0,15)}-`,s;try{s=await Ye(e)}catch{return 0}let r=0;for(let i of s)if(!(!i.startsWith(n)||!kt.test(i)))try{let c=Le.safeParse(JSON.parse(await be(ne(e,i),"utf8")));if(!c.success)continue;for(let g of c.data.leases)r+=(g.assigning.length>0?1:0)+g.created.length}catch{}return r}function Mt(e,t){let n=fe(e,t);return n.assign.length===0?{plan:n,automation:e,planned:te(n,"nothing",Ue)}:{plan:n,automation:ge(e,K(n)),planned:te(n,"planned")}}async function St(e,t,n,s={}){let r=s.self??Ne,i=()=>s.checks?.now?.()??Date.now(),c=s.minutes??Ve,g=o=>{throw new x({code:"MUTE_FAILED",message:o})},h=await e.identity().catch(o=>g(`The target would not say who the run writes as (${I(o)}).`)),u={organizationId:h.organization_id,userId:h.user_id},a=it(s.dir??ve(),u.organizationId,u.userId),A=t.assign.map(o=>o.permissionSet),l=await wt(e,A).catch(o=>g(`The permission sets to assign could not be read (${I(o)}).`)),p=A.filter(o=>!l.has(o));p.length>0&&g(`The target holds no permission set ${p.join(", ")}: nothing was assigned.`);let w=A.map(o=>l.get(o)),O=new Map(A.map(o=>[l.get(o),o])),v=o=>ut(o,a,r,s.checks),D=new Date(i()).toISOString(),N=xe(a,n,D),se=!1,re=w.map(o=>O.get(o)),ze=s.retryEveryMs??Qe,q,oe=(o,y)=>{if(q!==void 0)return;let d=new Set(o.map(m=>m.id)),k=!1,M=()=>clearInterval(q);q=setInterval(()=>{k||(k=!0,Y(a,u,s,async(m,H)=>{let P=m.leases.find(R=>R.runId===n&&R.acquiredAt===D);if(P){P.assigning=[],P.created=[...P.created,...y.filter(b=>!P.created.some(J=>J.id===b.id))].filter(b=>!d.has(b.id));let R=await G(e,m,P,v);for(let b of R.removed)d.add(b.id);await H(m)}M()},void 0,0).catch(()=>{}).finally(()=>{k=!1}))},ze),q.unref?.()},U=await Y(a,u,s,async(o,y)=>{let d=L(await ht(e,o,v)),k=await Te(e,u.userId,w),M=w.filter(f=>!k.has(f)),m={runId:n,host:r.host,pid:r.pid,hostStartedAt:r.startedAt,acquiredAt:D,endsAt:new Date(i()+c*6e4).toISOString(),needs:w,assigning:[...M],created:[]};o.leases.push(m),_.add(N),await y(o),se=!0;let H=[...m.assigning],P=()=>y(o).then(()=>{H=[...m.assigning]},f=>I(f)),R=async f=>{m.assigning=[];let E=await G(e,o,m,v);_.delete(N);let S=await P();S!==void 0&&oe(E.removed,[...E.passed,...E.left]);let $=S!==void 0&&H.length===0?{sets:re,until:m.endsAt}:void 0,de=$e(E,S===void 0);return g([f,...S!==void 0&&S!==f?[S]:[],...de.length>0?de:["Nothing was assigned."],...S!==void 0&&(E.passed.length>0||E.left.length>0||$)?[Ie(r.pid,$)]:[],...d.length>0?[`Taking its lease, the run took back ${d.join(", ")}, ${De(d)}.`]:[]].join(" "))};for(let f of M){let E=await e.createAssignment({AssigneeId:u.userId,PermissionSetId:f});if(m.assigning=m.assigning.filter($=>$!==f),E.success&&E.id){m.created.push({id:E.id,permissionSetId:f,permissionSet:O.get(f)});let $=await P();if($!==void 0)return R($);continue}let S=E.errors?.[0];if((S?.statusCode??S?.errorCode)==="DUPLICATE_VALUE"){let $=await P();if($!==void 0)return R($);continue}return R(`${O.get(f)} could not be assigned to the user the run writes as: ${S?.message??S?.statusCode??"the org refused it"}.`)}let b=await Te(e,u.userId,w).catch(()=>new Map),J=w.filter(f=>!b.has(f));if(J.length>0)return R(`Read back, the user the run writes as does not hold ${J.map(f=>O.get(f)).join(", ")}.`);let je=new Set(m.created.map(f=>f.permissionSetId));return{endsAt:m.endsAt,assigned:m.created.map(f=>f.permissionSet),held:w.filter(f=>!je.has(f)).map(f=>O.get(f)),found:d}}).catch(o=>{if(_.delete(N),Ze(o))throw o;return g(`${I(o)}${se?"":" Nothing was assigned."}`)}),T={...te(t,"muted"),assigned:U.assigned,held:U.held,leaseEndsAt:U.endsAt,...U.found.length>0?{tookBackOfEnded:U.found}:{}},ae=s.renewEveryMs??Ke,V=ae>0?setInterval(()=>{Y(a,u,s,async(o,y)=>{let d=o.leases.find(M=>M.runId===n&&M.acquiredAt===D);if(!d||!_.has(N))return;let k=new Date(i()+c*6e4).toISOString();d.endsAt=k,await y(o),T.leaseEndsAt=k}).catch(()=>{})},ae):void 0;V?.unref?.();let ie;return{outcome:T,release:()=>(ie??=(async()=>{V&&clearInterval(V);let o={};try{await Y(a,u,s,async(d,k)=>{let M=d.leases.find(m=>m.runId===n&&m.acquiredAt===D);_.delete(N),M&&(o.done=await G(e,d,M,v),await k(d))},d=>`nothing was taken back. ${Ce(d)} Should none of its runs be muting this org, end process ${d.pid}`);let y=o.done?.left??[];return{...T,released:y.length===0,takenBack:L(o.done?.removed??[]),...o.done&&o.done.passed.length>0?{passed:L(o.done.passed)}:{},...y.length>0?{notTakenBack:L(y),reason:`${y.map(d=>`${d.permissionSet} (${d.why})`).join(", ")} could not be taken back: the lease ends at ${T.leaseEndsAt}, and the next run that mutes this org releases it`}:{}}}catch(y){_.delete(N);let d=o.done;if(oe(d?.removed??[],d?[...d.passed,...d.left]:[]),d!==void 0){let k=T.leaseEndsAt,M=k!==void 0&&Date.parse(k)>i()?{sets:re,until:k}:void 0;return{...T,released:!1,takenBack:L(d.removed),notTakenBack:L([...d.passed,...d.left]),reason:[I(y),...$e({...d,removed:[]},!1),Ie(r.pid,M)].join(" ")}}return{...T,released:!1,takenBack:[],reason:`the assignments could not be taken back (${I(y)}): this process tries again while it runs, and takes them back once it can use the journal; past ${T.leaseEndsAt}, or once process ${r.pid} has ended, the next run that mutes this org releases the lease`}}})(),ie)}}var Et=2,Pt=3;function $t(e){return!e||e.assign.length===0?0:Et+Pt+2*e.assign.length+(Fe.get(e)??0)}function Ut(e){let t=$t(e);return t>0?{mute:t}:{}}function It(e){return{state:"nothing",assigned:[],held:[],permissions:[],silenced:[],stillRan:[],reason:`nothing can be muted: ${e}; the run goes on as without the option`}}function Ft(e){return e?{mutedAutomation:e.muted,...e.plan?{mutePlan:e.plan}:{}}:{}}async function zt(e,t,n={}){if(typeof t.unread=="string")return{automation:void 0,muted:It(`the target's automation could not be read (${t.unread})`)};let s=await yt(await e(),t,n);if("refused"in s)throw new x(s.refused);return{automation:s.automation,...s.plan.assign.length>0?{prepared:s}:{},muted:s.planned,plan:s.plan}}function jt(e){let t=e?.mutedAutomation;return t!==null&&typeof t=="object"?t:void 0}function qt(e,t){let n=[];e.state==="nothing"?n.push(`mute: ${e.reason??Ue}`):e.state==="planned"?n.push(`mute: planned, ${e.permissions.length>0?`the permission set(s) holding ${e.permissions.join(", ")}`:"nothing"} for the user it writes as in ${t}, for the run alone; nothing is assigned yet`):n.push(`mute: ${e.assigned.length>0?`assigned ${e.assigned.join(", ")}`:"assigned nothing"}${e.held.length>0?`; ${e.held.join(", ")} held already`:""} to the user the run writes as in ${t}, for the run alone`),e.tookBackOfEnded&&e.tookBackOfEnded.length>0&&n.push(` taken back before the run: ${e.tookBackOfEnded.join(", ")}, `+De(e.tookBackOfEnded));for(let r of e.silenced)n.push(` silenced: ${Q(r)} (bypass ${r.permission})`);for(let r of e.stillRan)n.push(` still runs: ${Q(r)} (${me(r.why)})`);for(let r of e.alsoLifted??[])n.push(` also lifts: ${he(r)}`);for(let r of e.liftsUnread??[])n.push(` ${pe(r)}`);let s=e.takenBack??(e.released===!0?e.assigned:[]);if(s.length>0&&n.push(` taken back: ${s.join(", ")}, as the run ended`),e.passed&&e.passed.length>0&&n.push(` stays assigned: ${e.passed.join(", ")}, for another run that mutes ${t} as the same user, which takes ${e.passed.length===1?"it":"them"} back as it ends`),e.released===!1){let r=e.notTakenBack!==void 0&&e.notTakenBack.length===0;n.push(` ${r?"lease not released":"not taken back"}: ${e.reason??"the assignments stay until the lease ends"}`)}return n}export{Dt as a,Ze as b,yt as c,Mt as d,$t as e,Ut as f,Ft as g,zt as h,jt as i,qt as j};
|