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,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"./chunk-QP3JLFIO.mjs";import"./chunk-CXKZ6TYV.mjs";import"./chunk-UV74P4H2.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{p as ObservedUsersRunStore,c as RECOVERY_CATEGORY,h as USERS_RUN_NOT_FOUND,i as USERS_RUN_REPLACED,a as awaitingAddressesOf,m as changingUsersOf,k as choicesKeyOf,l as planSignatureOf,f as readSavedTesters,d as recoveryTestersKey,b as recoveryUsersOf,j as replacedRunOf,g as saveTesters,e as savedTestersSchema,o as usersAuditObjectsOf,n as usersDoneOf};
|
|
@@ -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 M,i as T}from"./chunk-
|
|
7
|
+
import{h as M,i as T}from"./chunk-QLRWU3MB.mjs";import{p as b}from"./chunk-ICIYL45C.mjs";import{Ec as _,Fc as h,Gc as p,Hc as R,Lc as C,Mc as S,Pc as k}from"./chunk-6QSHWIZI.mjs";async function Y(r,e){try{let[c,i]=await Promise.all([r(R),e(R)]),d=c[0]?.Id,a=i[0]?.Id;return typeof d=="string"&&typeof a=="string"?{source:d,target:a}:void 0}catch{return}}function v(r,e){return r===h||e.some(c=>typeof c[p]=="string")}var K=[p,C,S];function A(r,e,c,i,d=()=>!1){let a={...e,standsFor:new Map,standardFirst:0,standardMatched:!1,prices:[],leftIn:new Map};if(!c)return a;let o=e.records.map((t,s)=>s),m=t=>({records:t.map(s=>e.records[s]),sources:t.map(s=>e.sources[s]),sourceIds:t.map(s=>e.sourceIds[s])});if(r===h){let t=o.filter(s=>e.sourceIds[s]!==c.source);return t.length===o.length?a:{...m(t),standsFor:new Map,standardFirst:0,standardMatched:!0,prices:[],leftIn:new Map}}if(r!==_)return a;let l=o,I=new Map,P=new Map,O=[];if(i){let{target:t}=i,s=e.sources.filter(n=>!K.some(f=>{let u=n[f];return typeof u=="string"&&u!==""&&d(u)})),E=n=>t.active.has(n)?n:b(void 0,t)?.to,g=M({prices:s,standardBookId:c.source,sellingModels:s.some(n=>typeof n[S]=="string"),writtenIn:E,active:t.active},[]),B=new Set(g.standsFor.keys());l=o.filter(n=>{let f=e.sourceIds[n];return f===void 0||!B.has(f)});let D=new Map(s.map(n=>[n.Id,n[k]]));for(let[n,f]of g.standsFor){I.set(n,f);let u=D.get(n),w=typeof u=="string"?E(u):void 0;typeof u=="string"&&w!==void 0&&P.set(n,{from:u,to:w})}O=T(g.said)}let y=t=>e.sources[t][p]===c.source,F=[...l.filter(y),...l.filter(t=>!y(t))];return{...m(F),standsFor:I,standardFirst:l.filter(y).length,standardMatched:!1,prices:O,leftIn:P}}function Q(r,e){let c=r.prices.map(i=>({...i}));for(let i of e){let d=r.leftIn.get(i),a=d&&(c.find(o=>o.from===d.from&&o.to===d.to&&o.how==="replaced"&&!o.forLines)??c.find(o=>o.from===d.from&&o.to===d.to&&o.how==="replaced"));a&&a.prices--}return c.filter(i=>i.prices>0)}function q(r,e){return e===1?`1 ${r} record held back, not sent: read in a currency the target org does not hold active, it stands for the source's own price of its product and price book in the currency written, which this run did not write.`:`${e} ${r} records held back, not sent: read in a currency the target org does not hold active, they stand for the source's own prices of their product and price book in the currency written, which this run did not write.`}var H="The standard price book is matched to the target org's, never written.";function $(r,e){return e.prices.length===0&&!e.standardMatched?r:{...r,...e.prices.length>0?{pricesSettled:[...e.prices]}:{},...e.standardMatched?{standardPricebookMatched:!0}:{}}}export{Y as a,v as b,A as c,Q as d,q as e,H as f,$ as g};
|
|
@@ -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{b as I}from"./chunk-CA5NAXSU.mjs";import{dd as u,s as A}from"./chunk-6QSHWIZI.mjs";import{createHash as E}from"node:crypto";var b="lineage:runs",h="lineage";function y(t){let e=t.objects.filter(i=>i.records>0);if(e.length===0)return null;let o="source",r="target",n=[{id:o,type:"source",label:t.source.label,origin:t.source.origin,...t.source.orgId?{orgId:t.source.orgId}:{}}],a=[];for(let i of e){let d=`object:${i.objectApiName}`;n.push({id:d,type:"object",label:i.objectApiName,objectApiName:i.objectApiName,recordCount:i.records}),a.push({sourceId:o,targetId:d}),a.push({sourceId:d,targetId:r,recordCount:i.records})}return n.push({id:r,type:"destination",label:t.target.label,orgId:t.target.orgId,origin:"org"}),{nodes:n,edges:a,operationId:t.operationId,generatedAt:t.generatedAt,module:t.module,action:t.action}}var c=class{constructor(e,o=100){this.configStore=e;this.limit=o}configStore;limit;save(e){let o=this.read().filter(r=>r.operationId!==e.operationId);o.push(e),this.configStore.set(b,o.slice(-this.limit),h)}get(e){let o=this.read();return e===void 0?o[o.length-1]??null:o.find(r=>r.operationId===e)??null}runs(){return this.read().reverse().map(e=>({operationId:e.operationId,generatedAt:e.generatedAt,...e.module?{module:e.module}:{},...e.action?{action:e.action}:{},...R(e)}))}read(){let e=this.configStore.get(b);return Array.isArray(e)?e.filter(S):[]}};function R(t){let e=t.nodes.find(o=>o.type==="destination");return e?{targetLabel:e.label}:{}}function S(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.operationId=="string"&&typeof e.generatedAt=="string"&&Array.isArray(e.nodes)&&Array.isArray(e.edges)}var j=100,L="audit:trail",O="audit",l=class{constructor(e,o=A){this.configStore=e;this.limit=o}configStore;limit;append(e){let o=this.read();o.push(e),this.configStore.set(L,o.slice(-this.limit),O)}list(e={}){let o=this.read().reverse(),r=o.filter(i=>(e.module===void 0||i.module===e.module)&&(e.orgId===void 0||i.orgId===e.orgId)),n=e.offset??0,a=e.limit??j;return{entries:r.slice(n,n+a),total:r.length,offset:n,facets:x(o)}}read(){let e=this.configStore.get(L);return Array.isArray(e)?e.filter(D):[]}};function x(t){let e=new Set,o=new Map;for(let r of t)e.add(r.module),r.orgId!==void 0&&!o.has(r.orgId)&&o.set(r.orgId,r.orgAlias);return{modules:[...e].sort(),orgs:[...o].map(([r,n])=>n?{orgId:r,orgAlias:n}:{orgId:r})}}function D(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.action=="string"&&typeof e.module=="string"&&typeof e.timestamp=="string"}var w="ABORTED_BEFORE_START";function v(t){let e=t?.trim().toLowerCase();if(e)return`sha256:${E("sha256").update(e).digest("hex").slice(0,12)}`}function P(t,e,o=new Date){try{let r=t.services?.getSandforgeSetting?.("safety.auditLogging",!0)!==!1;if(!r&&e.outcome==="stopped"&&e.code===void 0)return;let n=o.toISOString(),a=t.orgManager.getOrg(e.orgId),i=a?u(a):void 0,d=v(a?.username),s=e.source?.origin==="org"?e.source.orgId:void 0,f=s!==void 0?t.orgManager.getOrg(s):void 0,g=f?u(f):void 0,p=e.objects??[];if(new l(t.configStore).append({id:crypto.randomUUID(),action:e.action,module:e.module,orgId:e.orgId,...i?{orgAlias:i}:{},...s!==void 0?{sourceOrgId:s}:{},...g?{sourceOrgAlias:g}:{},operationId:e.operationId,outcome:e.outcome,...r&&e.guard?{guard:e.guard}:{},objects:[...p],...e.leftBy?{leftBy:e.leftBy}:{},...d?{userId:d}:{},...e.context?{context:e.context}:{},...e.verdict?{verdict:e.verdict}:{},...e.muted?{muted:e.muted}:{},...e.checkpointId?{checkpointId:e.checkpointId}:{},...e.beforeRun?{beforeRun:{...e.beforeRun}}:{},...e.fit?{fit:{...e.fit}}:{},details:{...e.details,...e.code?{code:e.code}:{}},timestamp:n}),!e.source)return;let m=y({operationId:e.operationId,module:e.module,action:e.action,source:e.source.origin==="org"?{origin:"org",orgId:e.source.orgId,label:g??e.source.orgId}:{origin:e.source.origin,label:e.source.label??""},target:{label:i??e.orgId,orgId:e.orgId},objects:C(p,e.carried),generatedAt:n});m&&new c(t.configStore).save(m)}catch(r){t.log(`[WARN] audit trail: run ${e.operationId} was not recorded \u2014 ${I(r)}`)}}function C(t,e){return e?Object.entries(e).map(([o,r])=>({objectApiName:o,records:r})):t.map(o=>({objectApiName:o.objectApiName,records:o.created+o.updated+(o.upserted??0)}))}function F(t){return{objectApiName:t,created:0,updated:0,deleted:0,failed:0}}export{c as a,l as b,w as c,v as d,P as e,F as f};
|
|
@@ -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 S,i as g,j as m,v as R}from"./chunk-
|
|
7
|
+
import{h as S,i as g,j as m,v as R}from"./chunk-BT43WSOS.mjs";var y=20,v="seed-runs",l="sandforge-seed",h=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function O(s,e){let t=s.finishedAt??new Date().toISOString();return{runId:s.runId,configId:l,configName:l,sourceOrgId:s.targetOrgId,targetOrgId:s.targetOrgId,startedAt:s.startedAt??t,end:{at:t,status:s.status},lastWrittenAt:t,created:s.objectResults.filter(d=>d.createdIds.length>0).map(d=>({objectApiName:d.objectApiName,ids:[...d.createdIds]})),...s.runUserId!==void 0&&h.test(s.runUserId)?{runUserId:s.runUserId}:{},...e?{removal:e}:{}}}function N(s,e){return new I(S(s,v,e))}var I=class{constructor(e,t=y){this.runs=e;this.max=t}runs;max;recorder(e){let t=this.runs.recorder({runId:e.runId,configId:l,configName:l,sourceOrgId:e.sourceOrgId??e.targetOrgId,targetOrgId:e.targetOrgId,...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.origin!==void 0?{origin:e.origin}:{},...e.pipeline!==void 0?{pipeline:{name:e.pipeline.name.slice(0,m)}}:{},...e.targetOrganizationId!==void 0?{targetOrganizationId:e.targetOrganizationId}:{},...e.targetAlias!==void 0?{targetAlias:e.targetAlias}:{},...e.runUserId!==void 0&&h.test(e.runUserId)?{runUserId:e.runUserId}:{}}),d=new Set,u=n=>{let i=n.filter(r=>!d.has(r.slice(0,15)));for(let r of i)d.add(r.slice(0,15));return i},a=(n,i)=>{for(let r=0;r<n.length;r+=g)i(n.slice(r,r+g))},f=(n,i,r)=>a(u(i),o=>t.note(n,o,r)),c=new Map,p=!1;return{runId:e.runId,note:(n,i)=>f(n,i),sending:(n,i,r)=>{r?.job!==void 0?c.set(n,r.job):c.delete(n),t.sending?.(n,i,r)},answered:(n,i)=>{c.delete(n);let r=u(i);t.answered?.(n,r.slice(0,g)),a(r.slice(g),o=>t.note(n,o))},wroteAgain:(n,i)=>a(i.filter(r=>d.has(r.slice(0,15))),r=>t.note(n,r)),checkpoint:n=>t.checkpoint?.(n),runUser:n=>{p||t.runUser?.(n)},end:async n=>{let i=n.finishedAt??new Date().toISOString();for(let{objectApiName:o,createdIds:A}of n.objectResults)f(o,A,i);if(d.size===0&&c.size===0){p=!0,await t.flush(),await this.runs.forget(e.runId);return}await t.end({status:n.status,...n.cancelled?{cancelled:!0}:{},at:i});let r=await t.flush();if(r!==void 0)throw new Error(r);await this.keepTheLatest()}}}record(e){let t=e.startedAt??e.finishedAt;return this.recorder({runId:e.runId,targetOrgId:e.targetOrgId,...t!==void 0?{startedAt:t}:{},...e.runUserId!==void 0?{runUserId:e.runUserId}:{}}).end(e)}async keepTheLatest(){let e=(await this.runs.list()).filter(R),t=e.length-this.max;for(let d of[...e].reverse()){if(t<=0)return;await this.runs.forget(d.runId),t--}}pathOf(e){return this.runs.pathOf(e)}get storagePath(){return this.runs.storagePath}get(e){return this.runs.get(e)}list(){return this.runs.list()}answerInFlight(e,t,d,u,a){return this.runs.answerInFlight(e,t,d,u,a)}async updateRemoval(e,t){await this.runs.get(e)&&await this.runs.updateRemoval(e,t)}};export{y as a,v as b,O as c,N as d,I 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{a as c}from"./chunk-
|
|
7
|
+
import{a as c}from"./chunk-KWAVSZ2B.mjs";var p=class{apply(n,r,t=[]){return m(n,r,t)}applyAddOns(n,r){let t={...n};for(let o of r)(!(o.fieldApiName in t)||o.overwriteExisting)&&(t[o.fieldApiName]=o.value);return t}},g=new Set(["direct","rename","transform","add_on"]),i=e=>e.toLowerCase();function S(e){return new Set(e.filter(n=>n.type!=="exclude").map(n=>i(n.targetField)))}function w(e,n=[]){let r=new Set(n.map(i));for(let t of e)(g.has(t.type)||t.type==="exclude")&&r.add(i(t.sourceField)),r.add(i(t.targetField));return r}var y=new c;function m(e,n,r=[]){if(n.length===0&&r.length===0)return{...e};let t=new Set(r.map(i)),o=Object.fromEntries(Object.entries(e).filter(([s])=>!t.has(i(s)))),d=w(n,r),l=Object.fromEntries(Object.entries(o).filter(([s])=>!d.has(i(s))));for(let s of n){let u=R(o,s);u!==void 0&&(l[s.targetField]=u)}return l}function a(e,n){if(n in e)return e[n];let r=i(n),t=Object.keys(e).find(o=>i(o)===r);return t===void 0?void 0:e[t]}var f=Symbol("exclude");function R(e,n){let r=F[n.type],t=r(e,n);if(!(t===f||t===void 0))return n.transformRules&&n.transformRules.length>0?y.transform(t,n.transformRules):t}var F={direct:(e,n)=>a(e,n.sourceField),rename:(e,n)=>a(e,n.sourceField),transform:(e,n)=>a(e,n.sourceField),constant:(e,n)=>n.targetField?n.sourceField:void 0,formula:(e,n)=>k(e,n.sourceField),exclude:()=>f,add_on:(e,n)=>a(e,n.sourceField)};function k(e,n){return/\{(\w+)\}/g.test(n)?n.replace(/\{(\w+)\}/g,(t,o)=>{let d=e[o];return d!=null?String(d):""}):e[n]}export{p as a,g as b,S as c,w as d,m as e};
|
|
@@ -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{q as Nt}from"./chunk-
|
|
7
|
+
import{q as Nt}from"./chunk-DIGUC7S4.mjs";import{a as It}from"./chunk-4V3QO7HF.mjs";import{a as _t,b as pe,c as Bt,e as Ut,f as Pe,g as Wt,h as Gt,i as qt,j as Vt,k as he,l as me,m as Kt}from"./chunk-I3ZO76LL.mjs";import{e as xt,g as Mt}from"./chunk-CQAFVEKP.mjs";import{f as Dt,h as Pt}from"./chunk-PDRXM5WN.mjs";import{a as Ht}from"./chunk-TW3N6W5Z.mjs";import{Db as Lt,Wa as oe,c as je,d as Le,e as bt,f as At,h as $t,i as Ne,j as kt,k as Rt,l as St,lb as Ie,m as Ot,mb as Tt,pb as De,q as Ft,qb as fe,sb as zt,tb as ne,xb as Ct,yb as jt}from"./chunk-LYOGCIYD.mjs";import{a as te,d as gt,j as Ce}from"./chunk-BNKT3R3F.mjs";import{a as yt,b as vt}from"./chunk-QROPNEGY.mjs";import{b as de,e as at}from"./chunk-BZ24IAP5.mjs";import{a as ke}from"./chunk-SCKUIE3R.mjs";import{c as ee,d as ue}from"./chunk-6FARZYMJ.mjs";import{b as le}from"./chunk-AXFD2OH6.mjs";import{m as wt}from"./chunk-5OGNK3JP.mjs";import{d as ut}from"./chunk-T63U4OZJ.mjs";import{a as Ee,c as Fe,d as Te,j as Z}from"./chunk-7WSQ65WG.mjs";import{b as st,c as Se}from"./chunk-7ZBDACVG.mjs";import{Cc as ht,Dc as mt,_a as ze,bb as ce,eb as ct,fb as ft,gc as J,nc as pt}from"./chunk-R3OM3X4L.mjs";import{q as lt}from"./chunk-2WMKJVD2.mjs";import{b as rt,f as it,g as dt,h as Et}from"./chunk-LCDPCUXS.mjs";import{E as Oe}from"./chunk-2GSMHGIV.mjs";import{Wc as et,Wd as tt,Xd as Re,Yd as ie,Zd as ot,ee as nt}from"./chunk-6QSHWIZI.mjs";import{existsSync as _e,mkdirSync as mo,readdirSync as go,readFileSync as ve}from"node:fs";import{dirname as wo,join as G}from"node:path";import{homedir as yo}from"node:os";var vo=`sandforge frozen \u2014 build and replay a Frozen Dataset, without the editor.
|
|
8
8
|
|
|
9
9
|
Usage:
|
|
10
10
|
npx sandforge frozen <step> --config <file> [options]
|
|
@@ -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{Hb as h,Kb as D,Lb as R,dd as O}from"./chunk-6QSHWIZI.mjs";function P(t,f){return t.previousOrganizationId??(t.organizationId===void 0?f?.(t.orgId):void 0)??t.detectedAt}function x(t){let f=(i,s)=>{let o=R.safeParse(t.configStore.get(D(i,P(s,t.organizationIdOf))));return o.success&&o.data.finishedAt!==void 0};return{progressOf(i){let s=t.orgOf(i);if(s?.orgType!=="Sandbox")return;let[o]=t.refreshesOf(i);if(!(o===void 0||f(i,o)))return{orgId:i,alias:O(s,s.username),detectedAt:o.detectedAt,done:0,total:h}}}}var b=3e4;function A(t){let f=x(t),i=t.ttlMs??b,s=t.now??(()=>Date.now()),o=new Map,g=new Map,a=new Map,u=new Set,l=new Set,p=()=>{for(let e of[...l])try{e()}catch(r){t.log?.(`[recovery] a listener of the progress failed: ${String(r)}`)}},v=(e,r)=>{if(u.has(e))return;let n=g.get(e);if(n!==void 0&&s()-n<i)return;let c=a.get(e)??0;u.add(e),t.statusOf(e).then(d=>{if(u.delete(e),g.delete(e),(a.get(e)??0)!==c){v(e,r);return}let S=o.get(e),m=S!==void 0&&S.detectedAt===r.detectedAt?S:r;if(d===void 0){o.delete(e);return}o.set(e,{...d,detectedAt:r.detectedAt,at:s()}),(m.done!==d.done||m.total!==d.total)&&p()},d=>{u.delete(e),g.set(e,s()),t.log?.(`[recovery] the steps of ${e} could not be deduced: ${d instanceof Error?d.message:String(d)}`)})};return{progressOf(e){let r=f.progressOf(e);if(r===void 0)return;let n=o.get(e),c=n!==void 0&&n.detectedAt===r.detectedAt;return(!c||s()-n.at>=i)&&v(e,r),c?{...r,done:n.done,total:n.total}:r},onDidChange(e){return l.add(e),{dispose:()=>l.delete(e)}},invalidate(e){let r=e!==void 0?[e]:[...o.keys()];for(let n of r){a.set(n,(a.get(n)??0)+1),g.delete(n);let c=o.get(n);c!==void 0&&o.set(n,{...c,at:Number.NEGATIVE_INFINITY})}p()}}}export{P as a,A as b};
|
|
@@ -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{a as we,b as ye}from"./chunk-
|
|
7
|
+
import{a as we,b as ye}from"./chunk-4GCYGQXD.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{be as fe,ce as K,de as ge,ge as Q,he as me,ie as he,je as pe,vc as le}from"./chunk-6QSHWIZI.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
8
|
${t}
|
|
9
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};
|
|
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
|
|
|
4
4
|
const require = __sandforgeRequire(import.meta.url);
|
|
5
5
|
const __filename = __sandforgePath(import.meta.url);
|
|
6
6
|
const __dirname = __sandforgeDirname(__filename);
|
|
7
|
-
import{i as g,n as p,o as m}from"./chunk-
|
|
7
|
+
import{i as g,n as p,o as m}from"./chunk-OUU47Y7A.mjs";import{a as b,b as I}from"./chunk-MS4FJDFD.mjs";import{c as w}from"./chunk-LCDPCUXS.mjs";import{bd as l,p as d,q as u}from"./chunk-6QSHWIZI.mjs";import{A as c}from"./chunk-WZQEK4WT.mjs";import{d as f}from"./chunk-NTOVCTRS.mjs";var a=class extends Error{constructor(t,r){super(`${r} Nothing was read from ${t}.`);this.alias=t;this.reason=r;this.name="SfSessionError",this.stack=this.message}alias;reason},$=c.object({name:c.string().optional(),message:c.string().optional()}).loose();function h(e){if(typeof e!="string")return;let n=e.replace(/\u001b\[[0-9;]*m/g,""),t=n.indexOf("{");if(t!==-1)try{let r=$.safeParse(JSON.parse(n.slice(t)));return r.success?r.data:void 0}catch{return}}function C(e,n=process.platform){let t=typeof e=="object"&&e!==null?e:{};return t.code==="ENOENT"?!0:n==="win32"&&(t.status===9009||/is not recognized as an internal or external command/i.test(String(t.stderr??"")))}function S(e,n,t=process.platform){if(C(n,t))return new a(e,`${d} SandForge reads each org through the Salesforce CLI: install it with "npm install -g @salesforce/cli" (${u}), sign in to the org with "sf org login web --alias ${e}", and run again.`);let r=typeof n=="object"&&n!==null?n:{},o=h(r.stdout)??h(r.stderr);if(o?.name==="NamedOrgNotFoundError"||/^No authorization information found for /.test(o?.message??""))return new a(e,`sf does not know ${e}: "sf org list" names the orgs it knows; "sf org login web --alias ${e}" adds it (in a CI job, "sf org login jwt" or "sf org login sfdx-url").`);let s=typeof r.stderr=="string"?r.stderr.split(/\r?\n/).find(y=>y.trim()!==""):void 0,i=o?.message?.trim()||s?.trim()||(n instanceof Error?n.message:String(n));return new a(e,`sf could not show ${e}: ${i}`)}var k=f(I()),x=f(b());import{execFileSync as E}from"node:child_process";function T(e){try{return E("sf",["org","display","--target-org",e,"--json"],{encoding:"utf8",maxBuffer:50*1024*1024,shell:process.platform==="win32"})}catch(n){throw S(e,n)}}async function A(e,n=m){if(!w.test(e))throw new Error(`Invalid SF org alias: "${e}" (an alias or a username: letters, digits, _ . @ + and -, not starting with . @ + or -)`);let t=T(e),r=JSON.parse(t),o=r.result;if(typeof o?.devHubId=="string"&&o.devHubId!==""){let i=typeof o.expirationDate=="string"?l({orgType:"Scratch",metadata:{expirationDate:o.expirationDate}},new Date().toISOString().slice(0,10)):void 0;if(i!==void 0||o.status==="Deleted")throw new Error(`The scratch org '${e}' ${i!==void 0?`expired on ${i}`:"is deleted"}: Salesforce deletes a scratch org when it expires, and no sign-in brings it back. Create a new one ("sf org create scratch") and give its alias.`)}if(!r.result?.instanceUrl)throw new Error(`sf org display did not return a usable session for alias '${e}'.`);let s=await n(e);if(!p(s.accessToken))throw new Error(`The Salesforce CLI showed no usable access token for alias '${e}'. Sign in again with "sf org login web --alias ${e}" where a browser opens; in a CI job, with "sf org login jwt --alias ${e}" (a client id, a key file and a username) or "sf org login sfdx-url --alias ${e} --sfdx-url-file <file>" (see ci-examples/README.md).`);return{alias:e,username:r.result.username??"",instanceUrl:s.instanceUrl??r.result.instanceUrl,accessToken:s.accessToken,...typeof r.result.devHubId=="string"&&r.result.devHubId!==""?{scratch:!0}:{}}}function H(e,n=process.env){let t=g(e.instanceUrl,n),r=new k.default.Connection({instanceUrl:e.instanceUrl,accessToken:e.accessToken,version:"66.0",...t!==void 0?{httpProxy:t}:{}});return t===void 0&&(r._transport=new x.HttpProxyTransport("")),r}export{a,A as b,H as c};
|
|
@@ -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{m as a,n as b,o as c,p as d,q as e,r as f,s as g}from"./chunk-
|
|
7
|
+
import{m as a,n as b,o as c,p as d,q as e,r as f,s as g}from"./chunk-GEEWPTV5.mjs";import"./chunk-GMY5427L.mjs";import"./chunk-TEIBWMJM.mjs";import"./chunk-BWWQXU2B.mjs";import"./chunk-T63U4OZJ.mjs";import"./chunk-M6P5ZZLE.mjs";import"./chunk-YBZIDW6W.mjs";import"./chunk-4TLYUZD5.mjs";import"./chunk-HFSBDM7B.mjs";import"./chunk-OHEOJISY.mjs";import"./chunk-2GSMHGIV.mjs";import"./chunk-TZE3Y7IQ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-ISOSTAJR.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-ICIYL45C.mjs";import"./chunk-7BQMBXKX.mjs";import"./chunk-KWAVSZ2B.mjs";import"./chunk-6QSHWIZI.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as DataSync,f as MAX_RESULT_REFUSALS_PER_OBJECT,g as buildObjectResult,d as linkedRecordOf,c as notReachedOf,b as unsetOf,e as withCurrencies};
|
|
@@ -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 S,d as z}from"./chunk-
|
|
7
|
+
import{b as S,d as z}from"./chunk-MJD6CPZZ.mjs";import{h as I}from"./chunk-TZE3Y7IQ.mjs";import{b as h}from"./chunk-CA5NAXSU.mjs";import{vc as R}from"./chunk-6QSHWIZI.mjs";import{b as f,e as b,f as y,i as A,k,l as m,o as K}from"./chunk-WZQEK4WT.mjs";var w="Knowledge__kav",j="CaseArticle",T="Case",P="Summary",B=255,D=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,L=m({name:f(),type:f(),length:b().optional(),extraTypeInfo:f().nullish(),htmlFormatted:y().optional(),createable:y().optional()}).loose(),F=m({fields:k(A())}).loose();function M(e){if(!(e.type!=="textarea"||e.createable!==!0))return e.name===P?"summary":e.extraTypeInfo==="richtextarea"||e.htmlFormatted===!0?"richText":(e.length??0)>B?"longText":void 0}var O={richText:0,longText:1,summary:2};function G(e){let r=F.safeParse(e);if(!r.success)return[];let o=[];for(let t of r.data.fields){let n=L.safeParse(t);if(!n.success)continue;let d=M(n.data);d===void 0||typeof n.data.length!="number"||o.push({name:n.data.name,length:n.data.length,kind:d})}return o.sort((t,n)=>O[t.kind]-O[n.kind]||n.length-t.length||t.name.localeCompare(n.name))}function U(e){return{articleBodyField:e.name,articleBodyLength:e.length,...e.kind==="richText"?{articleBodyHtml:!0}:{}}}var x=m({success:y(),errors:k(K([m({statusCode:f().optional(),message:f().optional()}).loose(),f()])).optional()}).loose();function $(e){let r=x.safeParse(e),o=r.success?r.data.errors?.[0]:void 0;return o===void 0?"The org gave no reason.":typeof o=="string"?o:[o.statusCode,o.message].filter(Boolean).join(": ")||"The org gave no reason."}function N(e){let r=x.safeParse(e);return r.success&&r.data.success}function C(e){return e.slice(0,15)}function X(e){return async({ids:r,results:o})=>{let t=r.get(w)??new Map;if(t.size===0)return{skipped:o.find(u=>u.objectApiName===w)?.errors[0]??`The run wrote no ${w} article, so none was published or linked.`};let n={};return e.plan.publish&&(n.publish=await _(e,t)),e.plan.links.length>0&&(n.links=await v(e,t,r.get(T)??new Map)),n}}async function _(e,r){let o={asked:r.size,done:0,notDone:[]};for(let[t,n]of r){if(e.signal?.aborted){o.notDone.push({key:t,reason:"Left a draft: the run was stopped before it was published."});continue}if(!D.test(n)){o.notDone.push({key:t,reason:`Left a draft: ${n} is not a record id.`});continue}try{await e.org.request({method:"PATCH",url:`/knowledgeManagement/articleVersions/masterVersions/${n}`,body:JSON.stringify({publishStatus:"Online"}),headers:{"Content-Type":"application/json"}}),o.done++}catch(d){o.notDone.push({key:t,reason:`Left a draft: ${h(d)}`})}finally{e.journal?.wroteAgain(w,[n])}}return o}async function v(e,r,o){let t={asked:e.plan.links.length,done:0,notDone:[]},n,d;try{n=await q(e.org,[...r.values()])}catch(s){n=new Map,d=h(s)}let u=[],c=(s,a)=>{t.notDone.push({key:s,reason:`Not linked: ${a}.`})};for(let{caseKey:s,articleKey:a}of e.plan.links){let l=o.get(s),g=r.get(a);if(l===void 0){c(s,"its case was not written");continue}if(g===void 0){c(s,`its article ${a} was not written`);continue}let i=n.get(C(g));if(i===void 0){c(s,`the article of ${a} could not be read back`+(d?` (${d})`:": the org no longer holds its version"));continue}u.push({caseKey:s,caseId:l,articleId:i,versionId:g})}for(let s=0;s<u.length;s+=S){let a=u.slice(s,s+S);if(e.signal?.aborted){for(let{caseKey:i}of a)t.notDone.push({key:i,reason:"Not linked: the run was stopped before it."});continue}let l;try{l=await e.org.sobject(j).create(a.map(({caseId:i,articleId:p})=>({CaseId:i,KnowledgeArticleId:p})),{headers:R()})}catch(i){let p=`Not linked: ${h(i)}`;for(let{caseKey:E}of a)t.notDone.push({key:E,reason:p});l=[]}finally{e.journal?.wroteAgain(T,a.map(({caseId:i})=>i)),e.journal?.wroteAgain(w,[...new Set(a.map(({versionId:i})=>i))])}let g=Array.isArray(l)?l:[l];g.length!==0&&a.forEach(({caseKey:i},p)=>{N(g[p])?t.done++:t.notDone.push({key:i,reason:`Not linked: ${$(g[p])}`})})}return t}async function q(e,r){let o=I(w),t=new Map;for(let n of z(r)){let d=await e.query(`SELECT Id, KnowledgeArticleId FROM ${o} WHERE Id IN (${n})`);for(let u of d.records){let c=u;typeof c?.Id=="string"&&typeof c.KnowledgeArticleId=="string"&&t.set(C(c.Id),c.KnowledgeArticleId)}}return t}export{w as a,G as b,U as c,X 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 as N}from"./chunk-
|
|
7
|
+
import{a as N}from"./chunk-EOQON3E5.mjs";import{a as j,h as D}from"./chunk-TZE3Y7IQ.mjs";import{b as J}from"./chunk-CA5NAXSU.mjs";function se(e){return`sync-before-${e.replace(/[^A-Za-z0-9-]+/g,"-")}`.slice(0,200)}var oe=1e3;function he(e){let o=se(e.runId),d=new Map,a=e.everyMs??oe,g=()=>(e.now?.()??new Date).getTime(),S,I=Number.NEGATIVE_INFINITY,k,E=!1,R=h=>{if(S===void 0)return;let t=[...d].map(([l,c])=>({objectApiName:l,recordCount:c,truncated:!1}));e.meta.set(`backup:${o}`,{operationId:o,orgId:e.orgId,...e.organizationId!==void 0?{organizationId:e.organizationId}:{},objects:t,partial:h,timestamp:S,totalRecords:t.reduce((l,c)=>l+c.recordCount,0),origin:"sync",runId:e.runId},"backups")},z=()=>{if(E)return;let h=I+a-g();if(h<=0){k!==void 0&&clearTimeout(k),k=void 0,I=g(),R(!0);return}k??=setTimeout(()=>{if(k=void 0,!E){I=g();try{R(!0)}catch{}}},h),k.unref?.()};return{id:o,keep:async(h,t)=>{t.length!==0&&(d.has(h)||(S??=(e.now?.()??new Date).toISOString(),d.set(h,0),R(!0),await e.files.begin(o,h)),await e.files.append(o,h,t),d.set(h,(d.get(h)??0)+t.length),z())},close:()=>{E=!0,k!==void 0&&clearTimeout(k),k=void 0,R(!1)}}}var F=200,de=["LastModifiedDate","LastModifiedById"],ee=100,te=4e3,ae=20,ne=255;function ce(e=ne){return 2*Math.max(0,e)+2}function ke(e,o){let d=o===void 0||o.creatable.size+4>ee;if(e.toLowerCase()==="id")return{characters:ae,wide:d};let a=o?.fields?.find(g=>g.name.toLowerCase()===e.toLowerCase());return a&&["double","int","long","currency","percent"].includes(a.type??"")?{characters:(a.precision??a.digits??18)+2,wide:d}:{characters:ce(a?.length??ne),wide:d}}function fe(e){let o=e.wide?F/4:F,d=Math.floor((te+2)/(Math.max(1,e.characters)+2));return Math.max(1,Math.min(o,d))}function me(e,o){let d=fe(o),a=e.reduce((g,S)=>g+Math.ceil(Math.max(0,S)/d),0);return a>0?a+1:0}function u(e){return e.slice(0,15)}function U(e,o){if(typeof e=="number"&&Number.isFinite(e))return`#${e}`;if(!(typeof e!="string"||e===""))return o?u(e):e.toLowerCase()}function ue(e){return typeof e=="number"?String(e):`'${j(String(e))}'`}function ge(e,o){let d=[],a=[],g=0;for(let S of e){let I=ue(S);a.length>0&&(a.length>=o||g+I.length>te)&&(d.push(a),a=[],g=0),a.push(I),g+=I.length+2}return a.length>0&&d.push(a),d}function le(e,o,d){return`What these ${o} ${e} record(s) would write over in the target could not be read and kept first (${J(d)}), so none of them was written: a run writes over nothing it cannot put back.`}function Se(e){let o=new Map,d=new Map,a=new Set,g=new Map,S=new Map,I=new Map,k=new Map,E=new Map,R=new Map,z=t=>{let l=e.describe,c=e.viewsEncrypted;if(!l||!c)return Promise.resolve(new Set);let y=I.get(t);return y||(y=l(t).then(async f=>{let m=(f.fields??[]).filter(M=>M.type===N).map(M=>M.name);return m.length>0&&!await c()?new Set(m):new Set},()=>new Set),I.set(t,y)),y},h=t=>{let l=e.describe;if(!l)return Promise.resolve(new Set);let c=S.get(t);return c||(c=l(t).then(y=>new Set((y.fields??[]).filter(f=>f.type==="base64"||f.queryable===!1).map(f=>f.name)),()=>new Set),S.set(t,c)),c};return{before:async(t,l,c,y)=>{if(g.delete(t),l!=="update"&&l!=="upsert"||c.length===0)return;let f=l==="update"?"Id":y??"Id",m=f==="Id";try{D(t),D(f);let M=await h(t),p=await z(t),v=new Set,O=new Set,T=new Map;for(let n of c){let i=U(n[f],m);i!==void 0&&!T.has(i)&&T.set(i,n[f]);for(let[r,s]of Object.entries(n))if(!(r==="Id"||r===f||r==="attributes")&&!M.has(r)&&!(typeof s=="object"&&s!==null)){if(p.has(r)){O.add(r);continue}v.add(D(r))}}if(T.size===0||v.size===0&&O.size===0)return;let x=["Id",...m?[]:[f],...v],V=[...x,...de.filter(n=>!x.includes(n))],re=V.length>ee?F/4:F,$=new Map,P=R.get(t)===!1?x:V;for(let n of ge([...T.values()],re)){let i=s=>`SELECT ${s.join(", ")} FROM ${t} WHERE ${f} IN (${n.join(", ")})`,r;try{r=await e.query(i(P))}catch(s){if(P===x)throw s;P=x,R.set(t,!1),r=await e.query(i(P))}for(let s of r){let w=U(m?s.Id:s[f],m);w===void 0||typeof s.Id!="string"||$.set(w,[...$.get(w)??[],s])}}let K=o.get(t)??new Map,_=[],B=new Map,C=new Map,G=new Map;for(let n of c){let i=U(n[f],m),r=i===void 0?void 0:$.get(i),s=r?.length===1?r[0]:void 0,w=s?.Id;if(_.push(w),!s||w===void 0||a.has(u(w)))continue;typeof s.LastModifiedDate=="string"&&G.set(u(w),{id:w,at:s.LastModifiedDate,...typeof s.LastModifiedById=="string"?{by:s.LastModifiedById}:{}});let ie=K.get(u(w)),q=B.get(u(w))??{Id:w},Q=C.get(u(w))??new Set;for(let b of Object.keys(n))!v.has(b)||ie?.has(b)||b in q||(q[b]=s[b]??null,Q.add(b));Q.size!==0&&(B.set(u(w),q),C.set(u(w),Q))}if(O.size>0&&_.some(n=>n!==void 0&&!a.has(u(n)))){let n=k.get(t)??new Set,i=[...O].filter(r=>!n.has(r));if(i.length>0){for(let r of i)n.add(r);k.set(t,n),e.recorder.unkept?.(t,i)}}if(B.size===0){g.set(t,{reaches:_,named:[],added:new Map});return}let X=[...B.values()],L=d.get(t)??new Map,Y=X.flatMap(n=>{let i=L.get(u(n.Id)),r=Object.entries(n).filter(([s])=>s==="Id"||!i?.has(s));return r.length>1?[Object.fromEntries(r)]:[]});Y.length>0&&await e.backup.keep(t,Y);for(let n of Y){let i=L.get(u(n.Id))??new Set;for(let r of Object.keys(n))r!=="Id"&&i.add(r);L.set(u(n.Id),i)}d.set(t,L);let A=X.map(n=>n.Id),W=E.get(t)??new Set,H=[];for(let n of A){let i=u(n);if(W.has(i))continue;W.add(i);let r=G.get(i);r&&H.push(r)}E.set(t,W),H.length>0?e.recorder.overwriting?.(t,e.backup.id,A,H):e.recorder.overwriting?.(t,e.backup.id,A);let Z=await e.recorder.flush();if(Z!==void 0)throw new Error(`the run's file could not be written: ${Z}`);for(let[n,i]of C){let r=K.get(n)??new Set;for(let s of i)r.add(s);K.set(n,r)}o.set(t,K),g.set(t,{reaches:_,named:A,added:C});return}catch(M){return le(t,c.length,M)}},answered:(t,l,c)=>{if(l==="insert"||l==="upsert")for(let p of c)p.success&&typeof p.id=="string"&&p.id!==""&&(l==="insert"||p.created===!0)&&a.add(u(p.id));let y=g.get(t);if(g.delete(t),!y||y.named.length===0)return;let f=new Set;c.forEach((p,v)=>{let O=y.reaches[v];O!==void 0&&p.success&&p.created!==!0&&f.add(u(O))});let m=y.named.filter(p=>!f.has(u(p))),M=o.get(t);for(let p of m){let v=M?.get(u(p));for(let O of y.added.get(u(p))??[])v?.delete(O)}e.recorder.overwrote?.(t,m)}}}export{se as a,he as b,ae as c,ce as d,ke as e,me as f,Se as g};
|
|
@@ -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{b as ie,c as se,d as Vt,e as Jt,f as be}from"./chunk-X2XZQ434.mjs";import{a as Zt,e as Xt}from"./chunk-XMQ5R6TC.mjs";import{I as re,O as Ue,a as Kt}from"./chunk-IXIY6Q4M.mjs";import{f as Le,p as ge,s as Be,u as Yt,w as $e}from"./chunk-BT43WSOS.mjs";import{b as me,d as ue}from"./chunk-MJD6CPZZ.mjs";import{c as qt}from"./chunk-OUU47Y7A.mjs";import{G as Ht}from"./chunk-ZXOUWHYE.mjs";import{c as Wt}from"./chunk-Z3MGN42K.mjs";import{c as Gt,e as Fe,g as Me,h as pe}from"./chunk-TZE3Y7IQ.mjs";import{a as $t,b as V}from"./chunk-CA5NAXSU.mjs";import{C as dt,D as pt,E as mt,Ea as zt,F as ut,Fa as St,J as gt,K as bt,Ka as ae,L as ft,La as Ae,M as yt,N as ht,Pa as M,Qa as xt,Ra as F,Sa as Ee,Sb as Rt,Ta as It,Ua as kt,Va as Ce,Wa as Te,Xa as _e,cb as Ne,dd as Nt,fb as jt,gb as Pt,hb as Ot,hc as wt,jc as vt,kc as At,n as rt,nc as Et,nd as Dt,oc as Ct,od as Ft,pc as Tt,pd as Mt,qe as Lt,rd as Ut,re as Bt,s as we,sd as De,t as it,u as st,v as ct,w as ne,wc as _t,y as lt,z as ve}from"./chunk-6QSHWIZI.mjs";import{b as a,c as Oe,e as g,f as r,g as et,i as D,k as c,l as o,m as tt,o as de,p as Re,s as x,u as w,v,w as ot,x as nt,y as G,z as at}from"./chunk-WZQEK4WT.mjs";function sa(e,t,n){return async s=>{let d=s.map(f=>`${f.objectApiName} (${f.records})`).join(", ");e.log(`[WARN] ${n}: the user may not delete ${d} in the target: those records stay`);let p=e.infraServices?.confirmRemovalLeavingUndeletable;if(!p)return!0;let u=e.orgManager.getOrg(t);return p({org:Nt(u,t),objects:s})}}var Qt={code:"NOT_INITIALIZED",message:"Production Guard is not initialized \u2014 infrastructure services missing"};function ca(){return Object.assign(new Error(Qt.message),{code:Qt.code})}var qe={blocked:"GUARD_BLOCKED",declined:"GUARD_DECLINED"};function la(e){return Object.assign(new Error(`Operation blocked by Production Guard: ${e}`),{code:qe.blocked})}function da(e){return e instanceof Error&&e.code===qe.blocked?qe.blocked:void 0}function Bo(e){return e.robustness??zt}function pa(e){return e.bulkManager??new Kt(Bo(e).bulk.maxConcurrentJobs)}var $o={"sync:schedule":"sync:schedule:","sync:pipeline":"sync:pipeline:","seed:pipeline":"seed:pipeline:","offline-replay":"offline-replay-"};function ma(e,t,n){return{id:`${$o[e]}${t}`,type:n,timestamp:Date.now()}}function ua(e,t,n,s){return{id:e.nextId(),type:n,timestamp:Date.now(),correlationId:t.id,payload:s}}function ga(e,t,n,s,d={}){let p=t==="error"?null:d.autoDismissMs===void 0?5e3:d.autoDismissMs,u={id:e.nextId(),type:"notification",timestamp:Date.now(),payload:{level:t,title:n,message:s,...p===null?{}:{autoDismissMs:p},...d.actions?{actions:d.actions}:{},...d.code?{code:d.code}:{}}};e.broker.postToWebview(u),e.log(`[TX] notification: ${n}`)}function ba(e,t,n,s){let d={id:e.nextId(),type:"operation:started",timestamp:Date.now(),payload:{operationId:t,module:n,description:s}};e.broker.postToWebview(d)}function fa(e,t,n,s,d,p){let u={id:e.nextId(),type:"operation:progress",timestamp:Date.now(),payload:{operationId:t,percentage:n,processedRecords:s,totalRecords:d,currentStep:p}};e.broker.postToWebview(u)}function ya(e,t,n){let s={id:e.nextId(),type:"operation:completed",timestamp:Date.now(),payload:{operationId:t,result:n}};e.broker.postToWebview(s)}var qo=Symbol("sandforge.uncorrelated");function eo(e,t,n,s,d,p={}){let u=V(d),f=d instanceof qt?d:void 0,k=qo in s,E=p.code??f?.code??"UNKNOWN";k||Ko(e.broker,u,E),e.log(`[ERR] ${t}: ${u}${k?` (uncorrelated: ${String(s.reason)})`:""}`);let O={id:e.nextId(),type:n,timestamp:Date.now(),...k?{}:{correlationId:s.id},payload:{message:u,code:E,retryable:p.retryable??!1,...f?{orgId:f.orgId}:{},...p.extraPayload}};e.broker.postToWebview(O),e.log(`[TX] ${n}: ${u}`)}function ha(e,t){let n={id:e.nextId(),type:t.type,timestamp:Date.now(),payload:t.payload};e.broker.postToWebview(n)}function za(e){let t=e?.getSandforgeSetting;if(!(!t||!t("grappe.enabled",!1)))return{enabled:!0,autoActivateThreshold:t("grappe.autoActivateThreshold",1e4),maxWorkers:rt.maxWorkers,grappeSize:t("grappe.grappeSize",5e3),strategy:"round_robin",backPressure:{enabled:!1,maxQueueDepth:3,highWaterMark:80,lowWaterMark:60,strategy:"pause",monitoringInterval:5e3},checkpointing:!0,isolationLevel:"per_grappe"}}function Sa(e){let t=new Set(e.map(s=>s.batchSize)),[n]=t;return{...e.length>0?{objectName:e.map(s=>s.objectApiName).join(", ")}:{},...t.size===1&&n!==void 0?{batchSize:n}:{}}}function xa(e,t,n,s,d={}){let p={id:e.nextId(),type:"operation:failed",timestamp:Date.now(),payload:{operationId:t,error:n,retryable:s,...d.extraPayload}};e.broker.postToWebview(p),d.authored!==!0&&Zo(e,n,d.context)}var Go=[/^Operation cancelled by user\b/,/^Operation blocked by Production Guard: /,/^Production Guard is not initialized\b/,/^Duplicate operation: /,/^A backup or rollback operation is already running for org /,/^Object describe not available for '/,/^CRUD_FLS_DENIED: /,/^CRUD\/FLS check failed for /,/^No backup found for operation /,/^Backup \S+ was taken from org /,/^Restore not run: /,/^Pipeline failed$/,/^Pipeline did not start: /,/^Pipeline ran out of time: /,/^Org not found: /,/^No credentials for org /,/^Invalid username format: /];function Wo(e){return Go.some(t=>t.test(e))}var to=1e4,Ge=new WeakMap;function Ko(e,t,n){let s=De(t,{code:n});if(!s?.actionKey)return;let d=Ge.get(e)??new Map,p=Date.now();for(let[u,f]of d)p-f>to&&d.delete(u);d.set(s.code,p),Ge.set(e,d)}function Ho(e,t){let n=Ge.get(e)?.get(t);return n!==void 0&&Date.now()-n<=to}function Zo(e,t,n={}){if(!(e.broker.panelCount>0)||Wo(t))return;let d=$t(t,Ut)??"UNKNOWN",p=De(t,{code:d});if(p?.actionKey){if(Ho(e.broker,p.code))return;e.broker.showFixSuggestion({source:"catalogue",code:p.code,actionKey:p.actionKey});return}let u=e.errorResolver;u&&u.resolveError({errorCode:d,message:t},n).then(f=>{e.broker.showFixSuggestion({source:"model",text:Xo(f)})}).catch(f=>{e.log?.(`[ERR] operation:failed resolution: ${V(f)}`)})}function Xo(e){return e.suggestions[0]?.description||e.explanation}import{isAbsolute as tn}from"node:path";var i=a().min(1).max(128),l=a().regex(/^[A-Za-z][A-Za-z0-9_]*$/,"Invalid Salesforce API name").max(80),so=c(l).max(300),m=a().min(1).max(200),J=a().max(2e3).refine(Fe,{message:Me}),on=a().refine(Gt,{message:"ORDER BY clause must list only field names with optional ASC/DESC and NULLS FIRST/LAST (no LIMIT, OFFSET, FOR UPDATE or subquery)."}),y=100,co=1e4,B=o({keepDays:g().int().min(ve.min).max(ve.max).optional(),excluded:c(l).max(y).refine(e=>new Set(e).size===e.length,"An object is left out twice").optional()}).strict(),he={sweepLate:r().optional(),sweepUntied:r().optional()};function nn(e){return Wt(e)}function an(e,t='turn on "Copy the files of these records"'){return _t(e)?`Sync copies files with the records they hang on, not as an object of their own: "${e}" keeps its content in a file body. Remove it from this configuration and ${t} instead; the sync was not started.`:`Sync does not copy "${e}": no copy writes it \u2014 users and their access, metadata, a record's history, feed or sharing rows, and the records the platform keeps for itself are not data a copy carries. Remove it from this configuration; the sync was not started.`}var rn=w(gt,{error:e=>e.input==="manual"?"Manual conflict review is not available for a sync run: no run shows its conflicts to anyone before it writes. Pick source wins, target wins, newest wins or merge \u2014 target wins keeps every value the target holds where the two orgs differ. The sync was not started.":`Conflict strategy "${String(e.input)}" is not one a sync run acts on: pick source wins, target wins, newest wins or merge. The sync was not started.`}),sn=bt.extend({objectApiName:l.refine(e=>!nn(e),{error:e=>an(String(e.input))}),externalIdField:nt(e=>typeof e=="string"&&e.trim()===""?void 0:e,l.optional()),where:J.optional(),orderBy:on.optional(),batchSize:g().int().positive().max(co).optional()}).strip().refine(e=>e.operation!=="upsert"||(e.externalIdField??"Id").toLowerCase()!=="id",{path:["externalIdField"],error:e=>`An upsert of "${String(e.input.objectApiName)}" needs an External ID field: matching on Id cannot work, because the id belongs to the source org and the target has never issued it. Name an External ID field both orgs share, or set the operation to insert. The sync was not started.`}).superRefine((e,t)=>{let n=Ft([e]);n.length!==0&&t.addIssue({code:G.custom,message:`${Mt(n)} The sync was not started.`,params:{unreadablePatterns:n}})});function oo(e){return et({error:()=>`Sync does not run Apex: remove "${e}" from this configuration. The sync was not started so the script cannot be skipped without you knowing.`}).optional()}var Ke=ft.extend({id:m.optional(),sourceOrgId:i,targetOrgId:i,objects:c(sn).min(1).max(y),conflictStrategy:rn,createdAt:a().max(40).optional(),updatedAt:a().max(40).optional(),preScript:oo("preScript"),postScript:oo("postScript"),dryRun:v(!1,{error:()=>'A sync configuration cannot ask for a dry run: remove "dryRun" from it. A run of it writes to the target org; to see what it would write, simulate it from the Sync page. The run was not started, so it cannot write while you believed it was only reporting.'}).optional()}).strip().superRefine((e,t)=>{e.direction==="target_to_source"&&t.addIssue({code:G.custom,path:["direction"],message:'Sync writes source to target only: direction "target_to_source" is not supported. Swap the source and target orgs to copy the other way. The sync was not started, so it cannot write into the org you meant to read from.'}),e.mode!=="full"&&e.mode!=="delta"&&t.addIssue({code:G.custom,path:["mode"],message:`Sync runs a full or a delta sync only: mode "${e.mode}" is not implemented. Set mode to "full" or "delta". The sync was not started, so it cannot replay the whole object set while you believed it was reading changes only.`}),e.mode==="delta"&&e.objects.forEach((n,s)=>{n.operation==="upsert"||n.operation==="update"||t.addIssue({code:G.custom,path:["objects",s,"operation"],message:`A delta sync writes ${n.objectApiName} again for every record it reads twice, and ${n.operation} would ${n.operation==="insert"?"create a second copy":"delete a record already gone"}. Write it by upsert on an External ID, or by update, or run the configuration in full. The sync was not started.`})}),e.propagateDeletes===!0&&(e.mode!=="delta"?t.addIssue({code:G.custom,path:["propagateDeletes"],message:'Deletions are carried by a delta sync only, which knows since when to look for them: set mode to "delta", or turn deletions off. The sync was not started.'}):e.objects.forEach((n,s)=>{if(n.operation!=="upsert"&&n.operation!=="update")return;let d=Ht(n);"refused"in d&&t.addIssue({code:G.custom,path:["objects",s],message:`${d.refused} Turn deletions off, or carry a source field onto the key. The sync was not started.`})}))}),Ea=o({suggestedName:a().min(1).max(255).refine(e=>!e.includes("/")&&!e.includes("\\"),"suggestedName must not contain a path"),content:a().max(32*1024*1024),extensions:c(a().regex(/^[A-Za-z0-9]+$/)).max(8).optional()}),Ca=o({config:Ke,muteAutomation:r().optional(),checkpointFirst:B.optional()}),Ta=o({config:Ke,checkpointFirst:B.optional()}),_a=o({operationId:m}),Na=o({config:Ke}),Da=o({id:m}),Fa=o({orgId:i,targetOrgId:i.optional()}),Ma=o({sourceOrgId:i,targetOrgId:i,objectApiName:l}),lo=w(["source_wins","target_wins","newest_wins","manual","merge"]),cn=Re("kind",[o({kind:v("id")}),o({kind:v("externalId"),field:l}),o({kind:v("syncConfig"),configId:m})]),Ua=o({sourceOrgId:i,targetOrgId:i,watchedObjects:c(l).min(1).max(y),apply:c(o({objectApiName:l,match:cn,applyDeletes:r()})).max(y),conflictStrategy:lo,flushIntervalMs:g().int().min(50).max(6e4),maxBatchSize:g().int().min(1).max(200),keepContactPoints:r().optional()}).refine(e=>e.apply.every(t=>e.watchedObjects.includes(t.objectApiName)),{message:"Every applied object must be watched.",path:["apply"]}),La=o({sessionId:a().max(200)}),Ba=o({sourceOrgId:i,targetOrgId:i}),$a=o({conflictId:a().min(1).max(500),eventReplayId:g().optional(),resolution:lo,fieldResolutions:x(a(),o({value:D(),source:w(["source","target","manual"])})).optional()}),qa=o({entryId:m}),Ga=o({runId:m}),Wa=o({realtime:v(!0).optional()}).optional(),Ka=o({sourceOrgId:i,targetOrgId:i,objects:c(l).max(y),configId:m.optional()}),Ha=o({runId:m,includeChanged:r().optional(),sweep:r().optional(),again:r().optional(),muteAutomation:r().optional(),...he}),Za=o({runId:m}),Xa=o({runId:m,again:r().optional(),sweptObjects:so.optional()}),Ya=o({runId:m}),Va=o({runId:m,includeChanged:r().optional(),sweep:r().optional(),again:r().optional(),muteAutomation:r().optional(),...he}),Ja=o({runId:m}),Qa=o({format:w(["csv","json"]),entryIds:c(m).max(500).optional()}),ln=o({id:m,name:a().min(1).max(200),configId:m,cron:a().min(1).max(100),timezone:a().min(1).max(100),enabled:r(),maxRetries:g().int().min(0).max(10),notifyOnComplete:r(),notifyOnFailure:r(),createdAt:a().max(40),updatedAt:a().max(40),version:g().int().positive()}).strip(),er=o({schedule:ln}),tr=o({scheduleId:m,enabled:r()}),or=o({scheduleId:m}),dn=dt.extend({objectApiName:l,recordCount:g().int().positive().max(ne),batchSize:g().int().positive().max(co).optional()}).loose(),pn=pt.extend({childObject:l,lookupField:l,parentObject:l}).superRefine((e,t)=>{e.parents.kind==="existing"&&e.parents.where!==void 0&&!Fe(e.parents.where)&&t.addIssue({code:G.custom,path:["parents","where"],message:Me})}),mn=mt.extend({objects:c(dn).min(1).max(y),relations:c(pn).max(y).optional()}).loose().superRefine(ut),nr=o({orgId:i,template:mn,muteAutomation:r().optional(),checkpointFirst:B.optional(),fit:o({share:g().gt(0).max(1),withinMB:g().positive().max(1e6).optional(),before:g().int().positive().max(ne*y)}).strict().optional(),locale:a().regex(/^[a-z]{2,3}(?:_[A-Za-z0-9]{2,4}){0,2}$/).optional(),dryRun:r().optional()}),ar=o({orgId:i}),rr=o({orgId:i,objects:c(l).min(1).max(y),publishes:r().optional()}).strict(),ir=o({orgId:i,objectApiName:l}),sr=o({id:m}),cr=o({template:x(a(),D())}),lr=o({description:a().max(1e4)}),dr=o({}).strict(),pr=o({orgId:i,pack:ae,seed:Ae.shape.seed,articleBodyField:l.optional()}).strict(),mr=o({orgId:i,pack:ae,options:Ae,locale:a().regex(/^[a-z]{2,3}(?:_[A-Za-z0-9]{2,4}){0,2}$/).optional(),muteAutomation:r().optional(),checkpointFirst:B.optional()}).strict(),ur=o({orgId:i}).strict(),gr=o({pack:ae,overwrite:r().optional()}).strict(),br=o({runId:m,choice:Rt,overwrite:r().optional()}).strict(),un=131072,gn=o({objectApiName:l,whereClause:J.optional()}).loose(),fr=o({sourceOrgId:i}),yr=o({sourceOrgId:i,targetOrgId:i,objects:c(gn).min(1).max(y),upsert:r().optional(),externalIdField:l.optional(),previewId:m.optional(),keepContactPoints:r().optional(),checkpointFirst:B.optional()}).refine(e=>!e.upsert||e.externalIdField!==void 0,{message:"externalIdField is required when upsert is true",path:["externalIdField"]}),bn=o({csvHeader:a().min(1).max(500),sfFieldApiName:a().max(80),sfFieldType:a().max(40),sfFieldLength:g().int().positive().nullable()}).loose(),hr=o({orgId:i,objectApiName:l,records:c(x(a(),a().max(un))).min(1).max(st),columnMappings:c(bn).min(1).max(ct),externalIdField:l.optional(),checkpointFirst:B.optional()}),zr=o({orgId:i,objects:c(l).min(1).max(y),wheres:x(l,J).optional(),slices:r().optional()}).refine(e=>Object.keys(e.wheres??{}).every(t=>e.objects.some(n=>n.toLowerCase()===t.toLowerCase())),{message:"A filter names an object the backup reads: give it in objects",path:["wheres"]}),Sr=o({orgId:i}),xr=o({orgId:i,templateId:a().min(1).max(200).optional()}),Ir=o({orgId:i,operationId:a().min(1).max(200)}),kr=o({orgId:i,operationIds:c(a().min(1).max(200)).min(1).max(1e3).optional()}),W={acceptAutomation:r().optional(),acceptEmails:r().optional(),muteAutomation:r().optional()},X={fromPage:v(!0).optional()},jr=o({orgId:i,operationId:m,rewriteAll:r().optional(),includeChanged:r().optional(),slices:c(g().int().positive()).min(1).max(lt*y).optional(),...W,...X}),Pr=o({orgId:i,act:w(["masking","restore","cleanup"]),objects:c(o({objectApiName:l,records:g().int().min(0)})).max(y),erasure:r().optional(),...W,...X}),He={objects:c(l).min(1).max(y).optional(),where:J.optional()},Ze=e=>e.where===void 0||e.where.trim()===""||e.objects?.length===1,Xe={message:"A WHERE clause filters the rows of one object: name exactly one in objects",path:["where"]},Or=o({orgId:i,templateId:m,...He,resumeFrom:m.optional(),snapshot:r().optional(),slices:r().optional(),maxRequests:g().int().positive().max(1e9).optional(),abandon:r().optional(),...W,...X}).refine(Ze,Xe).refine(e=>!(e.snapshot===!0&&e.resumeFrom!==void 0&&e.slices!==!0),{message:"A resume takes no snapshot: the run it resumes has written over some of its rows",path:["snapshot"]}).refine(e=>!(e.slices===!0&&e.snapshot===!1),{message:"A run in slices backs each slice up before it masks it: it cannot keep no snapshot",path:["slices"]}).refine(e=>e.maxRequests===void 0||e.slices===!0,{message:"A bound on requests stops a run in slices between two of them: give slices too",path:["maxRequests"]}).refine(e=>e.abandon!==!0||e.resumeFrom===void 0&&e.snapshot!==!0&&e.maxRequests===void 0,{message:"Giving up a set of slices masks nothing: it takes no resume, snapshot or bound",path:["abandon"]}),Rr=o({orgId:i,templateId:m,...He,slices:r().optional()}).refine(Ze,Xe),wr=o({orgId:i,templateId:m,...He}).refine(Ze,Xe),vr=o({name:a().trim().min(1).max(jt),rules:c(Ot).min(1).max(Pt).refine(e=>new Set(e.map(t=>t.fieldPattern.toLowerCase())).size===e.length,"A field has two rules")}),Ar=o({templateId:m}),Er=o({orgId:i,objectNames:c(l).min(1).max(y)}),Cr=o({orgId:i,objects:c(o({objectApiName:l,duplicateKey:l.optional()})).min(1).max(10).refine(e=>new Set(e.map(t=>t.objectApiName.toLowerCase())).size===e.length,{message:"Each object may be named once per scan"}),staleDays:g().int().min(1).max(3650)}),po=c(l).min(1).max(10).refine(e=>new Set(e.map(t=>t.toLowerCase())).size===e.length,{message:"Each object may be named once per request"}),Tr=o({orgId:i,objects:po}),_r=o({orgId:i,objects:po,requestId:Oe().optional(),email:a().trim().refine(Ct,"Not an email address").optional(),name:a().refine(Tt,"Not a name").optional(),phone:a().refine(Et,"Not a phone number").optional()}).refine(e=>e.email!==void 0||e.name!==void 0||e.phone!==void 0,{message:"A search needs an email address, a name or a phone number"}),fn=o({orgId:i,requestId:Oe()}),ze=a().regex(/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,"Not a record Id"),Nr=o({runId:m,recordId:ze}).strict(),Dr=fn.extend({mode:w(["anonymize","delete"]),records:c(o({objectApiName:l,ids:c(ze).min(1).max(200)})).min(1).max(10).refine(e=>new Set(e.map(t=>t.objectApiName.toLowerCase())).size===e.length,{message:"Each object may be named once per request"}),dryRun:r(),...W}),yn=Re("kind",[o({kind:v("stale"),days:g().int().min(1).max(3650)}),o({kind:v("orphans"),fieldApiName:l}),o({kind:v("duplicates"),keyField:l})]),mo=o({orgId:i,objectApiName:l,recommendation:yn}),Fr=mo.extend({after:o({skip:g().int().nonnegative().max(1e8),id:ze.optional(),modified:a().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:?\d{2})$/).optional()}).strict().optional()}),Mr=mo.extend({dryRun:r(),...W,...X}),We=2e3,uo={mode:w(["objects","org"]),objects:c(l).min(1).max(We).optional(),excluded:c(l).max(We).optional(),customSettings:r().optional(),files:r().optional(),managedPackages:r().optional(),unrestorable:r().optional()},hn=o(uo).strict().refine(e=>e.mode==="objects"==(e.objects!==void 0),{message:"The objects picked are named in objects mode, and only there"}),Ur=o({orgId:i,...uo,objects:c(l).max(We).optional()}).strict().refine(e=>e.mode==="objects"==(e.objects!==void 0),{message:"The objects picked are named in objects mode, and only there"}),Lr=o({orgId:i,request:hn,deleteMode:w(["recycle","hard"]),checkpointFirst:r().optional(),acceptNoUndo:r().optional(),acceptPeopleActive:r().optional(),...W,...X}),Br=o({orgId:i,previewId:m.optional(),resumeRunId:a().regex(/^em-\d{8}-\d{6}-[a-z0-9]{4}$/).optional(),acceptNoUndo:r().optional(),acceptPeopleActive:r().optional(),checkpointFirst:r().optional(),...W,...X}).refine(e=>e.previewId===void 0!=(e.resumeRunId===void 0),{message:"An emptying acts on a simulation, or takes up a run: one of them"}),$r=o({operationId:m}),qr=o({orgId:i,runId:a().regex(/^em-\d{8}-\d{6}-[a-z0-9]{4}$/),...W,...X}),Gr=o({orgId:i}),Wr=o({orgId:i}).strict(),Kr=o({alertId:m}),go=o({sourceOrgId:i,targetOrgId:i}),Hr=go.extend({types:c(a().min(1).max(80)).min(1).max(50),includeManaged:r().optional()}),zn=o({componentType:w(At),fullName:a().min(1).max(400).regex(/^[^\u0000-\u001f\u007f]+$/,"A component name holds no control character")}),Zr=go.extend({components:c(zn).min(1).max(500).refine(e=>new Set(e.map(t=>`${t.componentType}:${t.fullName}`)).size===e.length,{message:"Each component may be named once per deployment"}),testLevel:w(wt),runTests:c(a().max(255).regex(vt,"Not an Apex class name")).max(100).optional()}).refine(e=>e.sourceOrgId!==e.targetOrgId,{message:"The source and the target are the same org",path:["targetOrgId"]}).refine(e=>e.testLevel!=="RunSpecifiedTests"||(e.runTests?.length??0)>0,{message:"RunSpecifiedTests names at least one test class",path:["runTests"]}),Xr=o({validationId:a().regex(/^0Af[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,"Not a deployment id"),targetOrgId:i}).strict(),Sn=a().regex(/^\d+\.\d+\.\d+$/,"Invalid semver"),ye=a().regex(/^[A-Za-z][A-Za-z0-9_]*\.[A-Za-z][A-Za-z0-9_]*$/,"Expected an Object.field key").max(170),xn=o({name:a().min(1).max(80),label:a().min(1).max(200),filterField:l,valuesSoql:a().min(1).max(4e3)}),In=o({name:a().min(1).max(80),label:a().min(1).max(200),whereFragment:J}),no=de([o({action:v("clear")}),o({action:v("replace"),value:a().max(255)})]),bo=o({rootObject:l,axes:c(xn).max(20),edgeCases:c(In).max(50),budgetMaxRecords:g().int().positive().max(1e5).optional(),candidatesPerCombination:g().int().positive().max(20).optional(),expectedObjects:c(l).max(100).optional(),maxNodes:g().int().min(10).max(500).optional(),excludedObjects:c(l).max(200).optional(),excludedFields:x(l,c(l).max(500)).optional(),sasDir:a().min(1).max(500).optional(),datasetDir:a().min(1).max(500).optional(),rulesFilePath:a().min(1).max(500).optional(),datasetVersion:Sn.optional(),protectedOrgIds:c(i).max(50).optional(),identityKeys:x(l,c(l).min(1).max(10)).optional(),undeletableObjects:x(l,l).optional(),requiredLookupPlaceholders:x(ye,o({name:a().min(1).max(200),recordTypeDeveloperName:a().min(1).max(97).optional(),targetObjectApiName:l.optional()})).optional(),requiredFieldDefaults:x(ye,D()).optional(),picklistRules:x(ye,no).optional(),defaultPicklistRule:no.optional(),duplicateErrorPatterns:c(a().min(1).max(200)).max(50).optional(),mockDetection:o({metadataTypeApiName:l,isMockedFieldApiName:l}).optional(),mandatoryLookups:x(l,c(l).min(1).max(50)).optional(),presenceKeys:x(l,l).optional()}),Yr=o({config:bo}),Vr=o({sourceOrgId:i}),Jr=o({fields:c(ye).min(1).max(2e3)}),Qr=o({sourceOrgId:i,author:a().min(1).max(120).optional()}),ce=o({organizationId:kt,checkpointId:F}).strict(),kn=bo.pick({requiredFieldDefaults:!0,requiredLookupPlaceholders:!0,picklistRules:!0,defaultPicklistRule:!0,identityKeys:!0,undeletableObjects:!0,duplicateErrorPatterns:!0,mockDetection:!0,protectedOrgIds:!0}).strict(),fo=ce.extend({choices:Ne,config:kn.optional(),confirmStaging:a().min(1).max(255).optional()}).strict(),jn=fo.extend({choices:Ne.optional()}).strict(),ti=o({targetOrgId:i,replay:fo.optional(),pilot:r().optional(),reload:r().optional(),writeEncrypted:r().optional(),maxRecords:g().int().positive().max(1e6).optional(),muteAutomation:r().optional(),checkpointFirst:B.optional(),sweep:r().optional(),...he,includeChanged:r().optional(),acceptEmails:r().optional(),acceptAutomation:r().optional(),goneFirst:c(ze).max(1e6).optional()}),Pn=o({targetOrgId:i}),oi=Pn.extend({replay:jn.optional()}),ni=o({targetOrgId:i,loadedAt:a().min(1).max(64),includeChanged:r().optional(),sweep:r().optional(),...he,muteAutomation:r().optional(),replay:ce.optional()}),ai=o({targetOrgId:i,loadedAt:a().min(1).max(64),reload:r().optional(),replay:ce.optional()}),ri=o({targetOrgId:i,loadedAt:a().min(1).max(64),sweptObjects:so.optional(),reload:r().optional(),replay:ce.optional()}),ii=o({targetOrgId:i,loadedAt:a().min(1).max(64),includeChanged:r().optional(),replay:ce.optional()}),yo=1e3,ho=3650,On=200,Z=c(l).min(1).max(yo).refine(e=>new Set(e).size===e.length,"An object is named twice");function zo(e){return e.mode==="picked"?e.objects!==void 0:e.objects===void 0}var So=de([v("all"),c(l.refine(e=>e.toLowerCase().endsWith("__c"),"A custom setting's API name ends in __c")).min(1).max(yo).refine(e=>new Set(e.map(t=>t.toLowerCase())).size===e.length,"A custom setting is named twice")]),xo={path:["objects"],message:'Name the objects with "picked", and none with "everything"'},si=o({orgId:i.optional()}).optional(),Rn=1e6,Io=g().int().min(1).max(Rn),ci=o({orgId:i,mode:_e,objects:Z.optional(),excluded:Z.optional(),customSettings:So.optional(),maxTotal:Io.optional()}).refine(zo,xo),li=o({orgId:i,name:Te,mode:_e,objects:Z.optional(),excluded:Z.optional(),customSettings:So.optional(),maxTotal:Io.optional(),keepDays:g().int().min(0).max(ho),ignoredFields:Ce.optional()}).refine(zo,xo),di=o({checkpointId:F,objects:Z.optional(),muteAutomation:r().optional(),acceptOutside:r().optional()}),pi=o({checkpointId:F,previewId:Ee,objects:Z.optional(),acceptAutomation:r(),muteAutomation:r().optional(),acceptEmails:r().optional(),acceptNoUndo:r(),acceptRecreate:r(),acceptOutside:r(),acceptUnseen:r(),fromPage:v(!0).optional()}),mi=o({checkpointId:F,previewId:Ee,objects:Z,acceptOutside:r()}),ui=o({checkpointId:F}),wn=200,gi=o({token:m,orgId:i,key:a().min(1).max(wn),keepDays:g().int().min(0).max(ho)}),bi=o({checkpointId:F,rewindId:It,acceptAutomation:r(),muteAutomation:r().optional(),acceptEmails:r().optional(),fromPage:v(!0).optional()}),fi=o({checkpointIds:c(F).min(1).max(On).refine(e=>new Set(e).size===e.length,"A checkpoint is named twice")}),yi=o({checkpointId:F,keep:r()}),hi=o({checkpointId:F,name:Te}),zi=o({checkpointId:F,fields:Ce}),vn=500,Si=o({orgIds:c(i).min(1).max(vn).refine(e=>new Set(e).size===e.length,"An org is named twice").optional()}).strict().optional(),xi=o({sourceOrgId:i,targetOrgId:i,includeStandardObjects:r()}),Ii=o({sourceOrgId:i,objectApiNames:c(l).min(1).max(it)}),ki=o({sourceOrgId:i,targetOrgId:i,selectedObjects:c(l).max(y),includeStandardObjects:r(),maxDepth:g().int().min(1).max(10).optional(),maxObjects:g().int().min(1).max(500).optional()}),ji=o({complianceFramework:ht,objectFilters:x(a(),J).optional(),overrides:c(o({objectApiName:l,fieldApiName:l,method:de([yt,v("skip")])})).max(500).optional()}),Pi=o({grappeThreshold:g().int().nonnegative(),keepContactPoints:r().optional(),muteAutomation:r().optional(),checkpointFirst:B.optional()}),Oi=o({mode:o({share:v(!0).optional(),caps:x(l,g().int().min(1).max(ne)).refine(e=>Object.keys(e).length<=y,"Too many caps").optional(),all:g().int().min(1).max(ne).optional(),withinMB:g().positive().max(1e6).optional()}).strict().refine(e=>e.share===!0||e.caps!==void 0||e.all!==void 0,"Fit by share, by caps, or both"),muteAutomation:r().optional(),checkpointFirst:B.optional()}),Ri=o({objectApiName:l}),wi=o({orgId:i.optional(),sourceOrgId:i.optional(),alreadySelected:c(l).max(y).optional()}).loose(),vi=o({orgId:i.optional(),sourceOrgId:i.optional(),objectApiName:l.optional(),alreadySelected:c(l).max(y).optional(),selectedObjects:c(l).max(y).optional(),availableObjects:c(l).max(500).optional()}).loose(),Ai=o({sourceOrgId:i,targetOrgId:i.optional(),selectedObjects:c(l).min(1).max(y),parentObjects:c(l).max(y).optional()}).loose(),An=St.extend({sourceOrgId:i,targetOrgId:i,selectedObjects:c(l).min(1).max(y),parentObjects:c(l).max(y).default([])}).loose(),Ei=o({config:An.optional(),sourceOrgId:i.optional(),targetOrgId:i.optional(),selectedObjects:c(l).min(1).max(y).optional(),parentObjects:c(l).max(y).optional()}).loose(),En=a().min(1).max(5e4),Ci=o({conversationId:m,message:a().max(5e4)}),Ti=o({title:a().min(1).max(300)}),_i=o({conversationId:m}),Ni=o({apiKey:a().min(1).max(500),errorResolution:r().optional()}),Di=o({enabled:r().optional(),errorResolution:r().optional()}),Fi=o({orgId:i,objectName:l,sampleSize:g().int().positive().max(1e4).optional()}),Mi=o({orgId:i,prompt:a().trim().min(1).max(2e3).optional(),soql:a().trim().min(1).max(2e4).optional()}).refine(e=>e.prompt===void 0!=(e.soql===void 0),{message:"Send a prompt to draft from or a query to check, not both and not neither"}),Ui=o({description:En,orgIds:c(i).max(50).optional()}),Li=o({requestId:m}),fe=c(a().min(1).max(M.picklistValue)).max(M.picklistValues),ao={label:a().max(M.agentLabel).optional(),description:a().max(M.agentDescription).optional()},Bi=o({text:a().trim().min(1).max(M.text),language:ae.shape.language,casePicklists:o({Status:fe.optional(),Origin:fe.optional(),Priority:fe.optional(),Type:fe.optional()}).optional(),agent:o({topics:c(o({name:a().min(1).max(M.agentName),...ao,actions:c(o({name:a().min(1).max(M.agentName),...ao})).max(M.agentActions)})).max(M.agentTopics)}).optional(),draft:xt.optional(),maskOnly:r().optional()}),$i=o({filePath:a().min(1).max(2e3)}),qi=o({name:a().max(200),config:x(a(),D())}),Gi=o({operationId:m.optional(),executionId:m.optional(),objectName:a().min(1).max(200).optional()}).loose(),Wi=o({policyId:m}),Ki=o({policy:x(a(),D())}),Hi=o({policyId:m,orgId:i}),Zi=o({module:a().min(1).max(50).optional(),orgId:i.optional(),offset:g().int().min(0).max(we).optional(),limit:g().int().min(1).max(we).optional()}).optional(),Xi=o({operationId:m.optional()}).optional(),Cn=w(["syncMappings","forgePlans","pipelines","anonymizationTemplates"]),Yi=o({categories:c(Cn).min(1).max(50)}),Vi=o({json:a().min(1).max(5e6),overwrite:r()}),Ji=o({json:a().min(1).max(5e6)}),Qi=o({orgId:a().max(128),authMethod:a().min(1).max(50),alias:a().max(100).optional(),loginUrl:a().max(500).optional(),username:a().max(300).optional(),password:a().max(500).optional(),securityToken:a().max(100).optional(),clientId:a().max(256).optional(),jwtKeyFile:a().max(4096).optional()}).loose(),ko=a().trim().max(100).regex(/^[\w.-]*$/,"an alias is letters, digits, dots, dashes and underscores").optional(),Tn=a().trim().min(1,"the username is required").max(80).regex(/^[\w.@+-]+$/,"a username is written like an email address"),jo=a().trim().min(1,"the consumer key is required").max(256).regex(/^[A-Za-z0-9._-]+={0,2}$/,"a consumer key is letters, digits, dots, dashes and underscores"),_n=a().trim().min(1,"the private key file is required").max(4096).regex(/^[^\u0000-\u001f\u007f]+$/,"the private key file path holds a control character").refine(e=>tn(e),"give the private key file as an absolute path"),es=o({alias:ko,loginUrl:a().max(500).optional(),username:Tn,clientId:jo,jwtKeyFile:_n}).loose(),ts=o({alias:ko,loginUrl:a().max(500).optional(),clientId:jo}).loose(),os=o({requestId:m}),ns=o({orgId:i}),as=o({orgId:i}),rs=o({orgId:i}).strict(),is=o({orgId:i,alias:a().trim().min(1).max(100),color:a().regex(/^#[0-9A-Fa-f]{6}$/),tags:c(a().trim().min(1).max(50)).max(20),staging:r().optional()}),ss=o({key:a().min(1).max(200),value:D()}),cs=o({enabled:r()}),ls=o({lng:w(["en","fr","de","es","ja","pt-BR"])}),ds=o({targetOrgId:i,sourceOrgId:i.optional()}),ps=o({moduleId:a().min(1).max(64),route:a().min(1).max(64),overlay:r()}),ms=o({moduleId:a().min(1).max(64)}),Nn=80,Dn=ot(e=>Lt(e)||Bt(e)||typeof e=="string"&&e.trim()!==""&&e.length<=Nn,{message:"Not a pipeline step type"}),Fn=o({pipeline:o({name:a().min(1).max(200),steps:c(o({type:Dn,config:x(a(),D()).default({})}).loose()).max(200),variables:c(x(a(),D())).max(200).default([]),triggers:c(x(a(),D())).max(50).default([])}).loose(),variables:x(a(),a().max(2e3)).optional(),dryRun:r().optional()}),Mn=tt({since:at.datetime({offset:!0}),runner:w(["cron","taskScheduler","githubActions"]),file:a().min(1).max(255).refine(e=>!/[\\/]/.test(e),"The file's name, without its folder"),digest:a().regex(/^sha256:[0-9a-f]{64}$/,"Not a digest: sha256: and 64 hex digits")}),us=Fn.shape.pipeline.extend({id:a().min(1).max(200),runsOutside:Mn.optional()}),gs=o({pipelineId:m}),bs=o({id:a().max(200),config:x(a(),D())}),fs=o({id:m}),ys=o({operationId:m,stepId:m,decision:w(["approved","rejected"])}),Un=255,Po={pipelineId:m,stepId:m},hs=o({pipelineId:m}),zs=o({...Po,typed:a().min(1).max(Un)}),Ss=o(Po),xs=o({category:a().max(100).optional(),query:a().max(500).optional()}).loose().optional(),Is=o({templateId:m});function Ln(e){return e.issues.slice(0,3).map(t=>`${t.path.join(".")||"(root)"}: ${t.message}`).join("; ")}function Bn(e){let t=e.issues.map(n=>n.code==="custom"?n.params?.unreadablePatterns:void 0);return t.every(n=>n!==void 0)?t.flat():void 0}function ks(e,t,n,s){let d=e.safeParse(t.payload);if(!d.success){let p=Ln(d.error),u=Bn(d.error);return eo(s,t.type,n,t,new Error(`Invalid payload \u2014 ${p}`),u?{code:Dt,extraPayload:{rules:u}}:{code:"INVALID_PAYLOAD"}),null}return d.data}var $n=5;function Se(e){return e.slice(0,15)}function qn(e){let t=e.errors?.[0];if(t===void 0)return"The org gave no reason.";if(typeof t=="string")return t;let n=t.statusCode??"",s=t.message??"";return n&&s?`${n}: ${s}`:n||s||"The org gave no reason."}function Oo(e){let t=new Set;for(let n of e){let s=n.Id;typeof s=="string"&&t.add(Se(s))}return t}async function Ro(e){let t=[],n=[],s={},d=!1,p=!1,u=e.stampsFor,f=ie(e.org),k=e.org.serverTime?.bind(e.org),E=u&&k?Date.now()+await se({serverTime:k})-re:Number.NaN;for(let{objectApiName:O,ids:A}of e.plan){let I={objectApiName:O,planned:A.length,undeleted:0,alreadyBack:0,goneForGood:0,refused:0,reasons:[]};t.push(I);let z=_=>{I.reasons.length<$n&&!I.reasons.includes(_)&&I.reasons.push(_)},R=pe(O);for(let _=0;_<A.length;_+=me){let C=A.slice(_,_+me);if(p||e.signal?.aborted){p=!0,I.notReached=(I.notReached??0)+C.length,n.push(...C);continue}let[ee]=ue(C,me),K,te;try{K=Oo((await e.org.queryDeleted(`SELECT Id FROM ${R} WHERE Id IN (${ee}) AND IsDeleted = true`)).records),te=Oo((await e.org.query(`SELECT Id FROM ${R} WHERE Id IN (${ee})`)).records)}catch(j){I.refused+=C.length,z(`The recycle bin could not be read: ${V(j)}`),n.push(...C);continue}let h=C.filter(j=>K.has(Se(j)));for(let j of C)K.has(Se(j))||(te.has(Se(j))?I.alreadyBack++:I.goneForGood++);if(h.length===0)continue;let U;try{d=!0;let j=await e.undelete(h),T=Array.isArray(j)?j:[j];U=h.map((H,oe)=>T[oe]??{success:!1})}catch(j){let T=V(j);U=h.map(()=>({success:!1,errors:[T]}))}let Y=[];U.forEach((j,T)=>{if(j.success===!0){I.undeleted++,u?.(h[T])&&Y.push(h[T]);return}I.refused++,z(qn(j)),n.push(h[T])}),Y.length>0&&Number.isFinite(E)&&Object.assign(s,await be(e.org,R,Y,E,f))}}return{objects:t,left:n,wrote:d,cancelled:p,stamps:s}}function wo(e){return e.refused+e.goneForGood+(e.notReached??0)}async function Gn(e,t,n,s){let d=new Map(Object.entries(s).map(([u,f])=>[u.slice(0,15),Date.parse(f)])),p=new Set;for(let{objectApiName:u,ids:f}of t){let k=pe(u);for(let E of ue(f)){let O;try{O=(await e.query(`SELECT Id, LastModifiedDate FROM ${k} WHERE Id IN (${E})`)).records}catch{continue}for(let A of O){if(typeof A.Id!="string")continue;let I=A.Id.slice(0,15),z=Date.parse(String(A.LastModifiedDate??""));(z<=n||z<=(d.get(I)??Number.NaN))&&p.add(I)}}}return p}function vo(e){let t=Date.parse(e.startedAt),n=Date.parse(e.lastWrittenAt??e.end?.at??"");return Number.isFinite(n)?{runRecordedAt:new Date(n),...Number.isFinite(t)?{runDurationMs:Math.max(0,n-t)}:{}}:{}}function Wn(e){return e.filter(t=>t.deleted+t.alreadyGone>0).map(t=>t.objectApiName)}async function Ms(e){let{run:t,includeChanged:n}=e,s=e.again===!0,d=ge(t,s),p=d.reduce((b,S)=>b+S.ids.length,0),u=Be(t),f=u.reduce((b,S)=>b+S.ids.length,0),k=Yt(t),E=k.reduce((b,S)=>b+S.ids.length,0),O=[],A=e.backups,I=e.undelete;k.length>0&&!I&&O.push(`The ${E} record(s) the run deleted could not be brought back from the recycle bin here: the next removal offers them again.`),u.length>0&&!A&&O.push(`The values from before the run of ${f} record(s) it wrote over could not be read here: they were not put back, and the next removal offers them again.`);let z,R,_={},C=(e.earlierRuns??[]).map(b=>({runId:b.runId,keys:new Set([...ge(b),...Be(b)].flatMap(({ids:S})=>S.map(L=>L.slice(0,15))))})),ee=b=>C.some(({keys:S})=>S.has(b.slice(0,15))),K=e.sweep,te=u.length>0&&A||k.length>0&&I||K?async b=>{if(k.length>0&&I){let N=u.length>0&&A?await Gn(e.org,u,await Vt(e.org,xe(t)),t.removal?.removalStamps??{}):void 0,q=N?Date.now()+await se(e.org)-re:0;if(R=await Ro({org:e.org,plan:k,undelete:I,...C.length>0?{stampsFor:ee}:{},...e.signal?{signal:e.signal}:{}}),N&&R.wrote){let P=ie(e.org);for(let{objectApiName:Pe,ids:Mo}of u){let Uo=Mo.filter(Lo=>N.has(Lo.slice(0,15)));Object.assign(_,await be(e.org,Pe,Uo,q,P))}}if(R.cancelled||e.signal?.aborted)return R.wrote}if(u.length>0&&A){let N={...t.removal?.removalStamps,..._};z=await Jt({org:e.org,plan:u,backups:A,...xe(t)!==void 0?{lastWriteAt:xe(t)}:{},includeChanged:n,...Object.keys(N).length>0?{stamps:N}:{},...t.unkept?{unkept:t.unkept}:{},...C.length>0?{stampsFor:ee}:{},...e.signal?{signal:e.signal}:{}})}let S=(R?.wrote??!1)||(z?.wrote??!1);if(z?.cancelled||e.signal?.aborted)return S;let L=K?await K(b):!1;return S||L}:void 0,h=await Ue(e.org,d,{...vo(t),...t.removal?.removalStamps?{removalStamps:t.removal.removalStamps}:{},...t.removal?.removalSpans?{removalSpans:t.removal.removalSpans}:{},includeChanged:n,...te?{sweep:te}:{},...e.afterRemoval?{afterRemoval:e.afterRemoval}:{},...e.automationMade?{automationMade:e.automationMade}:{},...e.runUserId?{runUserId:e.runUserId}:{},...e.onUndeletable?{onUndeletable:e.onUndeletable}:{},...e.beforeFirstWrite?{beforeFirstWrite:e.beforeFirstWrite}:{},signal:e.signal,onProgress:e.onProgress}),U=new Date().toISOString();if(h.stoppedForUndeletable)return{result:{runId:t.runId,status:"cancelled",includeChanged:n,objects:[],finishedAt:U},planned:p,plannedBack:f,plannedUndelete:E,notes:[],stoppedForUndeletable:!0};let Y=s?void 0:t.removal?.undo?.removedAt,j={runId:t.runId,status:Zn(Xn(Zt(h.objects,h.cancelled),h.objects,z),h.objects,z,R),includeChanged:n,objects:h.objects,finishedAt:U,...Y?{leftBy:Y}:{},...z&&z.objects.length>0?{restored:z.objects}:{},...R&&R.objects.length>0?{undeleted:R.objects}:{}},T=Xt(j,p,t.removal?.undo,s),H=new Set(h.gone),oe=H.size>0||s&&T?d.flatMap(({ids:b})=>b.filter(S=>!H.has(S))):void 0,Je={..._,...h.stamps},Qe=Object.keys(Je).length>0,No=z?.objects.some(b=>b.restored+(b.restoredWithout??0)>0)===!0,Do=R!==void 0&&!R.cancelled;if(T||Qe||h.span||oe||z||R)try{await e.store.updateRemoval(t.runId,b=>({...b,...T?{undo:T}:{},...Qe?{removalStamps:{...b.removalStamps,...Je}}:{},...h.span?{removalSpans:[...b.removalSpans??[],h.span]}:{},...oe?{removalLeft:oe}:{},...z?{restoreLeft:z.left}:{},...No?{restoredAt:U}:{},...R?{undeleteLeft:R.left}:{},...Do?{undeletedAt:U}:{}}))}catch(b){O.push(`What this removal did could not be kept (${b instanceof Error?b.message:String(b)}): the next removal of the run may set out to take records already gone.`)}let Fo=Object.keys(z?.stamps??{}).length>0?await Kn(e.org,t,e.earlierRuns??[]):new Map,ke=[];for(let{runId:b,keys:S}of C){let L=Fo.get(b),N=Object.fromEntries(Object.entries({...R?.stamps,...z?.stamps}).filter(([P])=>S.has(P.slice(0,15))&&!L?.has(P.slice(0,15)))),q=Object.keys(N).length;if(q!==0)try{await e.store.updateRemoval(b,P=>({...P,removalStamps:{...P.removalStamps,...N},...h.span?{removalSpans:[...P.removalSpans??[],h.span]}:{}})),ke.push({runId:b,records:q})}catch(P){O.push(`What this removal gave back of ${q} record(s) the run ${b} wrote too could not be kept on it (${P instanceof Error?P.message:String(P)}): its removal reads them as changed since it.`)}}let le=e.configs;if(le&&H.size>0&&le.isSaved(t.configId)){let b={sourceOrgId:t.sourceOrgId,targetOrgId:$e(t)};try{let S=d.filter(P=>Le.includes(P.objectApiName)).flatMap(({ids:P})=>P.filter(Pe=>H.has(Pe))),L=le.forgetFiles(t.configId,b,S),N=Wn(h.objects).filter(P=>!Le.includes(P)),q=le.markRemoved(t.configId,b,[...new Set([...N,...L.map(P=>P.objectApiName)])],U);j={...j,...q.length>0?{readWhole:q}:{},...L.length>0?{filesForgotten:L.length}:{}}}catch(S){O.push(`The configuration could not be told what this removal took (${S instanceof Error?S.message:String(S)}): run it full next time.`)}}let je;if(e.links&&H.size>0)try{je=await e.links.forget(t.configId,{sourceOrgId:t.sourceOrgId,targetOrgId:$e(t)},[...H])}catch(b){O.push(`Which records of the target this removal took could not be forgotten (${b instanceof Error?b.message:String(b)}): a later run of the configuration may point a lookup at one of them.`)}return{result:j,planned:p,plannedBack:f,plannedUndelete:E,notes:O,...je?{linksForgotten:je}:{},...ke.length>0?{earlierStamped:ke}:{},...h.duplicateSets?{duplicateSets:h.duplicateSets}:{}}}async function Us(e){let{run:t}=e,n=ge(t);return{outcome:await Ue(e.org,n,{...vo(t),...t.removal?.removalStamps?{removalStamps:t.removal.removalStamps}:{},...t.removal?.removalSpans?{removalSpans:t.removal.removalSpans}:{},includeChanged:e.includeChanged,...e.runUserId?{runUserId:e.runUserId}:{},previewOnly:!0,...e.signal?{signal:e.signal}:{}}),planned:n.reduce((d,p)=>d+p.ids.length,0)}}async function Kn(e,t,n){let s=new Map,d=Object.entries(t.heldBefore??{});if(d.length===0||n.length===0)return s;let p=await ie(e)(),u=await se(e);for(let f of n){let k=Date.parse(xe(f)??""),E=Number.isFinite(k)?k+u+re:Number.NEGATIVE_INFINITY,O=new Set;for(let[A,{at:I,by:z}]of d)Date.parse(I)>E&&(p!==void 0&&z!==void 0&&z.slice(0,15)===p||O.add(A));O.size>0&&s.set(f.runId,O)}return s}function xe(e){return e.lastWriteAt??e.lastWrittenAt??e.end?.at}function Hn(e){return e.keptChanged+e.refused+e.notKept+(e.notReached??0)+(e.restoredWithout??0)}function Zn(e,t,n,s){if(!s||e==="cancelled")return e;if(s.cancelled)return"cancelled";let d=s.objects.some(u=>wo(u)>0);if(e==="success"&&!d)return"success";let p=t.some(u=>u.deleted>0)||(n?.objects??[]).some(u=>u.restored>0)||s.objects.some(u=>u.undeleted>0);return e==="partial"||p?"partial":"failure"}function Xn(e,t,n){if(!n||e==="cancelled")return e;if(n.cancelled)return"cancelled";let s=n.objects.some(p=>Hn(p)>0);return e==="success"&&!s?"success":t.some(p=>p.deleted>0)||n.objects.some(p=>p.restored+(p.restoredWithout??0)>0)?"partial":"failure"}function Bs(e){let t=e?.getSandforgeSetting?.("backup.maxAgeDays",30);return typeof t=="number"&&Number.isFinite(t)&&t>0?t:0}function $s(e,t,n){let s=[],d=0,p=Number.POSITIVE_INFINITY;for(let u of e){let f=t(u.backup);if(!f){d+=u.ids.length;continue}s.push(u);let k=Date.parse(f.timestamp??"");n>0&&Number.isFinite(k)&&(p=Math.min(p,k+n*864e5))}return{kept:s,notKept:d,...Number.isFinite(p)?{keptUntil:new Date(p).toISOString()}:{}}}var Ye="backupSet:",Yn="backups",Ve=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,Q=a().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/),$=g().int().nonnegative(),Vn=o({index:g().int().positive(),afterId:a().regex(Ve).optional(),lastId:a().regex(Ve).optional(),rows:$,snapshotId:a().min(1).max(240),takenAt:Q.optional(),readSince:Q.optional(),state:w(["pending","snapshotted","masking","masked","restored"]),masked:$,refused:$,deletedSince:$,nothingToMask:$,unanswered:$.optional(),late:v(!0).optional(),sizeUsed:g().int().positive(),lateLeft:$.optional(),lateOf:g().int().positive().optional(),lateAfterId:a().regex(Ve).optional(),restoredAt:Q.optional()}),Jn=o({objectApiName:a().min(1).max(255),where:a().max(2e3).optional(),select:a().max(1e5).optional(),done:r(),tailLeft:$.optional(),slices:c(Vn)}),Ao=o({setId:a().min(1).max(200),kind:w(["masking","backup"]),orgId:a().min(1).max(200),organizationId:a().max(18).optional(),templateId:a().min(1).max(200).optional(),fingerprint:a().regex(/^[0-9a-f]{64}$/).optional(),size:g().int().positive(),state:w(["open","done","abandoned"]),startedAt:Q,serverStartedAt:Q.optional(),lastActivityAt:Q,requestsSpent:$,keyCheck:a().regex(/^[0-9a-f]{16}$/).optional(),objects:c(Jn)});function Gs(e,t){return`${e}-s${String(t).padStart(4,"0")}`}function Ie(e){return e.objects.flatMap(t=>t.slices).sort((t,n)=>t.index-n.index)}function Ws(e){return Ie(e).reduce((t,n)=>Math.max(t,n.index),0)+1}function Co(e){return e.state==="masked"||e.state==="snapshotted"||e.state==="restored"}function Qn(e){return Ie(e).reduce((t,n)=>t+n.rows,0)}function To(e,t,n){return{index:t.index,objectApiName:e,snapshotId:t.snapshotId,rows:t.rows,masked:t.masked,refused:t.refused,deletedSince:t.deletedSince,nothingToMask:t.nothingToMask,state:t.state,...t.late?{late:!0}:{},...t.sizeUsed<n?{sizeUsed:t.sizeUsed}:{},...t.restoredAt?{restoredAt:t.restoredAt}:{}}}function ea(e){return e.objects.reduce((t,n)=>t+(n.tailLeft??0)+n.slices.reduce((s,d)=>s+(d.lateLeft??0),0),0)}function Ks(e,t){return{setId:e.setId,size:e.size,state:e.state,objects:e.objects.map(n=>({objectApiName:n.objectApiName,slices:n.slices.map(s=>To(n.objectApiName,s,e.size))})),lateRecords:ea(e),requestsSpent:t.requestsSpent,...t.stoppedOnBudget?{stoppedOnBudget:!0}:{},slicesLeft:e.objects.some(n=>!n.done||n.slices.some(s=>!Co(s)))}}function ta(e){return e.kind==="backup"&&e.state==="open"?"partial":e.state}function Hs(e){let t=Object.fromEntries(e.objects.flatMap(n=>n.where?[[n.objectApiName,n.where]]:[]));return{setId:e.setId,orgId:e.orgId,kind:e.kind,state:ta(e),startedAt:e.startedAt,lastActivityAt:e.lastActivityAt,size:e.size,totalRecords:Qn(e),...e.templateId?{templateId:e.templateId}:{},slices:e.objects.flatMap(n=>n.slices.map(s=>To(n.objectApiName,s,e.size))),...Object.keys(t).length>0?{wheres:t}:{}}}function Zs(e){let t=Ie(e);return{setId:e.setId,savedAt:e.lastActivityAt,done:t.filter(Co).length,total:t.length,state:e.state,size:e.size}}var Eo=class{constructor(t){this.configStore=t}configStore;get(t){let n=Ao.safeParse(this.configStore.get(this.key(t)));return n.success&&n.data.setId===t?n.data:void 0}save(t){this.configStore.set(this.key(t.setId),Ao.parse(t),Yn)}delete(t){this.configStore.delete(this.key(t))}list(t){return this.configStore.getKeysByPrefix(Ye).map(n=>this.get(n.slice(Ye.length))).filter(n=>n!==void 0).filter(n=>t===void 0||n.orgId===t)}openFor(t,n){return this.list(t).find(s=>s.kind==="masking"&&s.state==="open"&&s.templateId===n)}ofSnapshot(t){return this.list().find(n=>Ie(n).some(s=>s.snapshotId===t))}key(t){return`${Ye}${t}`}};async function Ys(e,t){let n=e.check(t);if(!n.allowed)return{check:n,decision:"refused"};if(!await e.confirmIfNeeded(n,t.orgTier))return{check:n,decision:"declined"};let d=n.requiresConfirmation&&e.canAskForConfirmation===!0;return{check:n,decision:d?"confirmed":"allowed"}}var _o={allowed:0,confirmed:1,declined:2,refused:3};function Vs(e,t){return e===void 0||_o[t]>_o[e]?t:e}export{sa as a,Qt as b,ca as c,qe as d,la as e,da as f,Bo as g,pa as h,ma as i,ua as j,ga as k,ba as l,fa as m,ya as n,eo as o,ha as p,za as q,Sa as r,xa as s,i as t,l as u,so as v,B as w,nn as x,an as y,Ke as z,Ea as A,Ca as B,Ta as C,_a as D,Na as E,Da as F,Fa as G,Ma as H,Ua as I,La as J,Ba as K,$a as L,qa as M,Ga as N,Wa as O,Ka as P,Ha as Q,Za as R,Xa as S,Ya as T,Va as U,Ja as V,Qa as W,er as X,tr as Y,or as Z,mn as _,nr as $,ar as aa,rr as ba,ir as ca,sr as da,cr as ea,lr as fa,dr as ga,pr as ha,mr as ia,ur as ja,gr as ka,br as la,fr as ma,yr as na,hr as oa,zr as pa,Sr as qa,xr as ra,Ir as sa,kr as ta,jr as ua,Pr as va,Or as wa,Rr as xa,wr as ya,vr as za,Ar as Aa,Er as Ba,Cr as Ca,Tr as Da,_r as Ea,fn as Fa,Nr as Ga,Dr as Ha,Fr as Ia,Mr as Ja,Ur as Ka,Lr as La,Br as Ma,$r as Na,qr as Oa,Gr as Pa,Wr as Qa,Kr as Ra,go as Sa,Hr as Ta,Zr as Ua,Xr as Va,bo as Wa,Yr as Xa,Vr as Ya,Jr as Za,Qr as _a,ti as $a,oi as ab,ni as bb,ai as cb,ri as db,ii as eb,si as fb,ci as gb,li as hb,di as ib,pi as jb,mi as kb,ui as lb,gi as mb,bi as nb,fi as ob,yi as pb,hi as qb,zi as rb,Si as sb,xi as tb,Ii as ub,ki as vb,ji as wb,Pi as xb,Oi as yb,Ri as zb,wi as Ab,vi as Bb,Ai as Cb,Ei as Db,Ci as Eb,Ti as Fb,_i as Gb,Ni as Hb,Di as Ib,Fi as Jb,Mi as Kb,Ui as Lb,Li as Mb,Bi as Nb,$i as Ob,qi as Pb,Gi as Qb,Wi as Rb,Ki as Sb,Hi as Tb,Zi as Ub,Xi as Vb,Yi as Wb,Vi as Xb,Ji as Yb,Qi as Zb,es as _b,ts as $b,os as ac,ns as bc,as as cc,rs as dc,is as ec,ss as fc,cs as gc,ls as hc,ds as ic,Fn as jc,Mn as kc,us as lc,gs as mc,bs as nc,fs as oc,ys as pc,hs as qc,zs as rc,Ss as sc,xs as tc,Is as uc,Ln as vc,ks as wc,Ro as xc,Ms as yc,Us as zc,xe as Ac,Zn as Bc,Xn as Cc,Ys as Dc,Vs as Ec,Bs as Fc,$s as Gc,Gs as Hc,Ie as Ic,Ws as Jc,Co as Kc,ea as Lc,Ks as Mc,ta as Nc,Hs as Oc,Zs as Pc,Eo as Qc};
|
|
@@ -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{e as ds,f as cs}from"./chunk-
|
|
7
|
+
import{e as ds,f as cs}from"./chunk-XKFHTBAB.mjs";import{a as es,b as ts,c as ye,d as ns,e as ss,f as rt,g as rs,h as is,i as os,j as as}from"./chunk-FYWNSMOZ.mjs";import{i as ls,l as us}from"./chunk-WBELLGNE.mjs";import{c as Yn}from"./chunk-OS5GE52G.mjs";import{b as Vn}from"./chunk-BPHTA6KP.mjs";import{a as jt,b as Gn,c as we,d as Lt,e as Nt,f as Jn,g as Kn,m as Hn}from"./chunk-NDFFIJL5.mjs";import{d as Pt,f as Ce,l as At,n as tt}from"./chunk-RVCPQVKM.mjs";import{a as Xn,b as Qn}from"./chunk-ALBY5SOH.mjs";import{Bc as bn,Cc as Rn,xc as Ze}from"./chunk-AXFD2OH6.mjs";import{a as wn,b as mn,c as yn,e as Ye,f as kn,h as Wn,i as _n}from"./chunk-X2XZQ434.mjs";import{a as It,d as In,f as On,h as Pn,j as An,k as jn,l as Xe,m as Ln,p as Nn,q as Bn}from"./chunk-4X5D3MSV.mjs";import{A as $n,B as zn,a as hn,v as Dn,w as Mn,z as Un}from"./chunk-XMQ5R6TC.mjs";import{I as vt,J as fn,M as pn,O as Ve}from"./chunk-IXIY6Q4M.mjs";import{a as Rt,b as un}from"./chunk-54HYHHVL.mjs";import{l as gn}from"./chunk-BT43WSOS.mjs";import{B as nt,E as xn,F as st,i as Me,j as Ot,l as Se,p as Ne,q as Tn,r as et,z as qn}from"./chunk-EOQON3E5.mjs";import{b as E,e as Be,g as En}from"./chunk-Y7YUNRKK.mjs";import{A as $e,H,N as Fn,d as Qe,g as Cn,x as Ue,y as je,z as Le}from"./chunk-N2HYG3BL.mjs";import{b as St,d as Sn}from"./chunk-7WSQ65WG.mjs";import{b as Y,d as ge,e as ln}from"./chunk-MJD6CPZZ.mjs";import{c as vn}from"./chunk-WXU6ZJIV.mjs";import{$b as Zn}from"./chunk-R3OM3X4L.mjs";import{i as He}from"./chunk-INIT2UKJ.mjs";import{E as cn}from"./chunk-ZXOUWHYE.mjs";import{g as Ae,h as ne,i as an,q as dn}from"./chunk-Z3MGN42K.mjs";import{da as Ke,ja as rn,ka as on}from"./chunk-2GSMHGIV.mjs";import{h as de}from"./chunk-TZE3Y7IQ.mjs";import{b as Q}from"./chunk-CA5NAXSU.mjs";import{Nd as sn,Ra as Qt,Ta as Je,Ua as en,Uc as nn,Vd as kt,Yd as bt,vc as tn}from"./chunk-6QSHWIZI.mjs";import{b as X,e as Yt,f as De,i as yt,k as le,l as _,o as Ge,p as Zt,u as Pe,v as Z,z as Xt}from"./chunk-WZQEK4WT.mjs";import{randomBytes as Us}from"node:crypto";import{rm as $s}from"node:fs/promises";import{join as zs}from"node:path";var ar=5,dr="005",cr=new Set(["001"]),Bt="Kept: a file's link to a user is never removed, and Salesforce refuses to remove its owner's ('FIELD_INTEGRITY_EXCEPTION').",it="Its sharing type stays as it is: Salesforce doesn't change the sharing type of a file's link to an account ('The sharing type cannot be updated because updates are not currently supported for the linked Entity type').";function ue(){return{done:0,already:0,refused:0,notSent:0,notReached:0,reasons:[],left:[],made:[],cancelled:!1}}function Fe(i,e){i.done+=e.done,i.already+=e.already,i.refused+=e.refused,i.notSent+=e.notSent,i.notReached+=e.notReached;for(let t of e.reasons)ot(i.reasons,t);i.left.push(...e.left),i.made.push(...e.made),i.cancelled||=e.cancelled}function ot(i,e){i.length<ar&&!i.includes(e)&&i.push(e)}var lr=_({success:De(),id:X().nullish(),errors:le(Ge([X(),_({statusCode:X().optional(),message:X().optional()}).loose()])).optional()}).loose();function ur(i,e){let t=Array.isArray(i)?i:[i];return Array.from({length:e},(n,s)=>{let r=lr.safeParse(t[s]);if(!r.success)return{success:!1,words:"The org gave no answer for it."};let{success:a,id:o,errors:d}=r.data,c=(d??[])[0],p=typeof c=="object"?c.statusCode:void 0,f=(d??[]).map(u=>typeof u=="string"?u:[u.statusCode,u.message].filter(l=>l).join(": ")).filter(u=>u!=="").join("; ");return{success:a,...typeof o=="string"?{id:o}:{},...p!==void 0?{code:p}:{},...f!==""?{words:f}:{}}})}function fr(i){let e=[];for(let t=0;t<i.length;t+=Y)e.push(i.slice(t,t+Y));return e}async function Ct(i,e,t,n){let s=ue();for(let r of fr(i)){if(s.cancelled||e.stopped?.()===!0){s.cancelled=!0,s.notReached+=r.length;for(let d of r)s.left.push({id:d.Id,reason:"Not reached: stopped."});continue}await e.before?.(r);let a=ur(await t(r),r.length),o={done:[],made:[],left:[]};r.forEach((d,c)=>{let p=a[c],f=n(p);if(f==="done"){s.done++,o.done.push(d),p.id!==void 0&&o.made.push({from:d.Id,id:p.id});return}if(o.left.push(d.Id),f==="already"){s.already++;return}let u=p.words??"The org gave no reason.";s.refused++,ot(s.reasons,u),s.left.push({id:d.Id,reason:u})}),s.made.push(...o.made),await e.after?.(o)}return s}function ps(i,e,t,n){let s=[];for(let r of i){if(!e(r)){s.push(r);continue}n.notSent++,ot(n.reasons,t),n.left.push({id:r.Id,reason:t})}return s}async function at(i,e,t={}){let n=ue(),s=ps(e,a=>a.LinkedEntityId?.startsWith(dr)===!0,Bt,n),r=await Ct(s,t,a=>i.destroy(ne,a.map(o=>o.Id)),a=>a.success?"done":a.code==="ENTITY_IS_DELETED"||a.code==="NOT_FOUND"?"already":"refused");return Fe(r,n),r}async function dt(i,e,t={},n=s=>s){return Ct(e,t,s=>i.create(ne,s.map(r=>({ContentDocumentId:n(r.ContentDocumentId),LinkedEntityId:n(r.LinkedEntityId),ShareType:r.ShareType,Visibility:r.Visibility}))),s=>s.success&&s.id!==void 0?"done":s.code==="DUPLICATE_VALUE"?"already":"refused")}async function ct(i,e,t={}){let n=d=>cr.has(d.LinkedEntityId.slice(0,3)),s=ue(),r=new Map,a=ps(e,d=>d.Visibility===d.now.Visibility&&n(d),it,s);for(let d of a){let c=d.ShareType!==d.now.ShareType&&!n(d);d.ShareType!==d.now.ShareType&&n(d)&&ot(s.reasons,it),r.set(d.Id,{Id:d.Id,...c?{ShareType:d.ShareType}:{},...d.Visibility!==d.now.Visibility?{Visibility:d.Visibility}:{}})}let o=await Ct(a,t,d=>i.update(ne,d.map(c=>r.get(c.Id)??{Id:c.Id})),d=>d.success?"done":d.code==="ENTITY_IS_DELETED"?"already":"refused");return Fe(s,o),s}import{randomBytes as ks}from"node:crypto";import{closeSync as pr,createReadStream as bs,fsyncSync as hr,openSync as gr,readFileSync as wr,renameSync as mr,writeSync as yr}from"node:fs";import{open as ut,readdir as Rs,rm as vs,stat as kr,truncate as Ss}from"node:fs/promises";import{dirname as Is,join as ee}from"node:path";import{createInterface as Os}from"node:readline";var Te="journal.ndjson",br="before.json",J=2e3,Ps=X().regex(/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,"Not a record id"),Tt=X().regex(/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,"Not a User Id"),be=X().regex(/^[A-Za-z][A-Za-z0-9_]*$/,"Not an API name").max(80),V=Xt.datetime({offset:!0}),ae=le(Ps).min(1).max(J),As=Yt().int().positive(),js=_({kind:Z("head"),version:Z(1),rewindId:Je,checkpointId:Qt,organizationId:en,startedAt:V,userId:Tt,automatedProcessUserId:Tt.optional(),backup:X().min(1).max(200),at:V}),Rr=_({kind:Z("resumed"),startedAt:V,userId:Tt,at:V}),vr=_({kind:Pe(["bringingBack","withParent","givingBack"]),objectApiName:be,ids:ae,parents:ae.optional(),carriers:Z(!0).optional(),at:V}),Sr=_({kind:Z("bringBackLeft"),objectApiName:be,ids:ae,at:V}),Ir=_({kind:Z("recreating"),objectApiName:be,ids:ae,at:V}),Or=_({kind:Z("recreated"),objectApiName:be,ids:ae,from:ae,at:V}),Pr=_({kind:Pe(["deleting","deleteLeft"]),step:As,objectApiName:be,ids:ae,at:V}),Ar=_({kind:Z("heldInPlace"),objectApiName:be,by:le(be).min(1).max(100),ids:ae,at:V}),jr=_({kind:Z("beforeParent"),objectApiName:be,ids:ae,parents:ae,at:V}),Lr=_({kind:Z("deleted"),step:As,at:V}),Nr=_({kind:Z("removal"),state:yt(),at:V}),Br=_({kind:Z("unlinking"),links:le(we).min(1).max(J),at:V}),Cr=_({kind:Pe(["unlinkLeft","linksUpdateLeft"]),ids:ae,at:V}),Fr=_({kind:Z("relinked"),ids:ae,from:ae,at:V}),Ls=we.pick({Id:!0,LinkedEntityId:!0,ShareType:!0,Visibility:!0}),Tr=_({kind:Z("linksUpdating"),links:le(Ls).min(1).max(J),at:V}),Er=_({kind:Z("linksUndone"),part:Pe(["reinserted","removed","shared"]),ids:ae,at:V}),Dr=_({kind:Z("wrote"),at:V}),Mr=_({kind:Z("end"),at:V}),Ur=_({kind:Z("undo"),state:yt(),status:Pe(["success","partial","failure","cancelled"]),at:V}),$r=Zt("kind",[js,Rr,vr,Sr,Ar,jr,Ir,Or,Pr,Lr,Nr,Br,Cr,Fr,Tr,Er,Dr,Mr,Ur]),zr=new Set(["bringingBack","withParent","bringBackLeft","givingBack","recreating","recreated","deleting","deleteLeft","deleted","removal","unlinking","unlinkLeft","relinked","linksUpdating","linksUpdateLeft","wrote"]);async function Et(i){let e;try{e=await ut(i,"r"),await e.sync()}catch{}finally{await e?.close().catch(()=>{})}}async function Ut(i,e){let t=await ut(i,"a",Qe);try{await t.appendFile(e,"utf8"),await t.sync()}finally{await t.close()}}function Wr(i,e){let t=`${i}.${process.pid}-${ks(4).toString("hex")}.tmp`,n=Buffer.from(e,"utf8"),s=gr(t,"wx",Qe);try{for(let r=0;r<n.length;)r+=yr(s,n,r,n.length-r);hr(s)}finally{pr(s)}mr(t,i)}function _r(i){let e=[];try{let n=JSON.parse(wr(i,"utf8"));Array.isArray(n.openings)&&(e=n.openings)}catch{}let t=e.length;return{set:(n,s)=>{e[t]=s,Wr(i,`${JSON.stringify({version:1,openings:e})}
|
|
8
8
|
`)}}}function W(i){return i.slice(0,15)}function pe(i){let e=[];for(let t=0;t<i.length;t+=J)e.push(i.slice(t,t+J));return e}async function*qr(i){if(!fn(i)){for(let{objectApiName:e,ids:t}of i)t.length>0&&(yield{objectApiName:e,ids:[...t]});return}for(let{objectApiName:e}of i.objects)for await(let t of i.pages(e))t.length>0&&(yield{objectApiName:e,ids:[...t]})}var lt=class i{constructor(e,t,n,s,r,a){this.dir=t;this.resumed=n;this.handle=s;this.step=r;this.now=a;this.rewindId=e.rewindId,this.backup=e.backup;let o=new Set,d=new _n({...Wn(t),appendFile:async(p,f)=>{await Ut(p,f),o.has(p)||(o.add(p),await Et(Is(p)))}}),c={begin:()=>Le(ee(t,"backups")),append:(p,f,u)=>d.append(p,f,u)};if(this.kept=Qn({runId:e.rewindId,orgId:e.organizationId,organizationId:e.organizationId,files:c,meta:_r(ee(t,br)),now:a}),this.kept.id!==e.backup)throw new H("damaged","The rewind\u2019s journal names another backup of its values than the one they are kept in.");this.values=d,this.keep=async(p,f)=>{await this.kept.keep(p,f);let u=f.flatMap(l=>typeof l.Id=="string"?[l.Id]:[]);for(let l of pe(u))await this.append({kind:"givingBack",objectApiName:p,ids:l})}}dir;resumed;handle;step;now;keep;values;queue=Promise.resolve();closed=!1;openStep;kept;rewindId;backup;static async opened(e,t,n,s,r){let a=await ut(ee(e,Te),"a",Qe);try{return new i(t,e,n,a,s,r)}catch(o){throw await a.close(),o}}append(e){if(this.closed)return Promise.reject(new Error("The rewind\u2019s journal is closed."));let t=`${JSON.stringify({...e,at:this.now().toISOString()})}
|
|
9
9
|
`,n=this.queue.then(async()=>{await this.handle.appendFile(t,"utf8"),await this.handle.sync()});return this.queue=n.catch(()=>{}),n}async appendIds(e,t,n,s=!1){for(let r of pe(n))await this.append({kind:e,objectApiName:t,ids:r,...s?{carriers:s}:{}})}bringingBack(e,t,n={}){let s=new Map;for(let{objectApiName:r,ids:a}of e){let[o]=a;o!==void 0&&s.set(o.slice(0,3),r)}return async r=>{let a=new Set(r.map(d=>s.get(d.slice(0,3)))),[o]=[...a];if(a.size!==1||o===void 0)throw new Error("These records are not of the plan the journal names: none was sent.");return await this.appendIds("bringingBack",o,r,n.carriers===!0),t(r)}}async withParent(e,t,n,s={}){let r=s.carriers===!0;if(n===void 0){await this.appendIds("withParent",e,t,r);return}if(n.length!==t.length)throw new Error("Each record that comes back with a parent is named beside that parent.");for(let a=0;a<t.length;a+=J)await this.append({kind:"withParent",objectApiName:e,ids:t.slice(a,a+J),parents:n.slice(a,a+J),...r?{carriers:r}:{}})}async bringBackLeft(e,t){for(let n of pe(t))await this.append({kind:"bringBackLeft",objectApiName:e,ids:n})}async heldInPlace(e,t,n){if(t.length!==0)for(let s of pe(n))await this.append({kind:"heldInPlace",objectApiName:e,by:[...t],ids:s})}async beforeParent(e,t){for(let n=0;n<t.length;n+=J){let s=t.slice(n,n+J);await this.append({kind:"beforeParent",objectApiName:e,ids:s.map(({id:r})=>r),parents:s.map(({parent:r})=>r)})}}async recreating(e,t){for(let n of pe(t))await this.append({kind:"recreating",objectApiName:e,ids:n})}async recreated(e,t){for(let n=0;n<t.length;n+=J){let s=t.slice(n,n+J);await this.append({kind:"recreated",objectApiName:e,ids:s.map(({id:r})=>r),from:s.map(({from:r})=>r)})}}async deleting(e){let t=++this.step;this.openStep=t;for await(let{objectApiName:n,ids:s}of qr(e))for(let r of pe(s))await this.append({kind:"deleting",step:t,objectApiName:n,ids:r})}async deleted(e){let t=this.openStep;if(t===void 0)throw new Error("No removal was named to the journal before it.");for await(let{objectApiName:n,ids:s}of e.left())for(let r of pe(s))await this.append({kind:"deleteLeft",step:t,objectApiName:n,ids:r});await this.append({kind:"deleted",step:t}),this.openStep=void 0}async removal(e){let t={...e.removalStamps&&Object.keys(e.removalStamps).length>0?{removalStamps:e.removalStamps}:{},...e.removalSpans&&e.removalSpans.length>0?{removalSpans:e.removalSpans}:{}};Object.keys(t).length!==0&&await this.append({kind:"removal",state:{version:1,...t}})}async unlinking(e){for(let t=0;t<e.length;t+=J)await this.append({kind:"unlinking",links:e.slice(t,t+J)})}async unlinkLeft(e){for(let t of pe(e))await this.append({kind:"unlinkLeft",ids:t})}async relinked(e){for(let t=0;t<e.length;t+=J){let n=e.slice(t,t+J);await this.append({kind:"relinked",ids:n.map(({id:s})=>s),from:n.map(({from:s})=>s)})}}async linksUpdating(e){for(let t=0;t<e.length;t+=J){let n=e.slice(t,t+J).map(s=>({Id:s.Id,LinkedEntityId:s.LinkedEntityId,ShareType:s.ShareType,Visibility:s.Visibility}));await this.append({kind:"linksUpdating",links:n})}}async linksUpdateLeft(e){for(let t of pe(e))await this.append({kind:"linksUpdateLeft",ids:t})}async linksUndone(e,t){for(let n of pe(t))await this.append({kind:"linksUndone",part:e,ids:n})}async wrote(){await this.append({kind:"wrote"})}async end(){await this.append({kind:"end"})}async undone(e,t){await this.append({kind:"undo",state:{version:1,...e},status:t})}async read(){return await this.queue,Ns(ee(this.dir,Te))}async facts(){return await this.queue,Gr(ee(this.dir,Te))}async close(){if(!this.closed){this.closed=!0;try{this.kept.close()}catch{}await this.queue,await this.handle.close()}}};async function ke(i,e){let t=(await kr(i)).size,n=t===0;if(t>0){let p=await ut(i,"r");try{let f=Buffer.alloc(1);await p.read(f,0,1,t-1),n=f[0]===10}finally{await p.close()}}let s=0,r=0,a=async p=>{r+=Buffer.byteLength(p,"utf8")+1;let f;try{f=JSON.parse(p)}catch{f=void 0}let u=$r.safeParse(f);if(!u.success)throw new H("damaged",`The rewind\u2019s journal is damaged at line ${s+1}: it is not used.`);xr(u.data),s++,await e(u.data)},o=bs(i,{encoding:"utf8"}),d=Os({input:o,crlfDelay:1/0}),c;try{for await(let p of d)c!==void 0&&await a(c),c=p}finally{d.close(),o.destroy()}return c!==void 0&&n&&await a(c),{count:s,whole:r,size:t}}function xr(i){if(i.kind==="relinked"&&i.from.length!==i.ids.length)throw new H("damaged","The rewind\u2019s journal names links inserted again without the links they stand for.");if(i.kind==="recreated"&&i.from.length!==i.ids.length)throw new H("damaged","The rewind\u2019s journal names records made again without the Ids they had.");if(i.kind==="beforeParent"&&i.parents.length!==i.ids.length)throw new H("damaged","The rewind\u2019s journal names records deleted before a parent without their parent.");if((i.kind==="withParent"||i.kind==="bringingBack")&&i.parents!==void 0&&i.parents.length!==i.ids.length)throw new H("damaged","The rewind\u2019s journal names records that came back with a parent without it.")}var he=class{byObject=new Map;add(e,t){let n=this.byObject.get(e)??new Map;for(let s of t)n.has(W(s))||n.set(W(s),s);this.byObject.set(e,n)}drop(e,t){let n=this.byObject.get(e);if(n)for(let s of t)n.delete(W(s))}list(e=()=>!0){return[...this.byObject].flatMap(([t,n])=>{let s=[...n].filter(([r])=>e(r)).map(([,r])=>r);return s.length>0?[{objectApiName:t,ids:s}]:[]})}keys(){return new Set([...this.byObject.values()].flatMap(e=>[...e.keys()]))}};function hs(i){let e={};for(let t of i)e={...e,...t,...t.removalStamps||e.removalStamps?{removalStamps:{...e.removalStamps,...t.removalStamps}}:{},...t.removalSpans||e.removalSpans?{removalSpans:[...e.removalSpans??[],...t.removalSpans??[]]}:{}};return e}function gs(i){let e=gn(i);if(e===void 0)throw new H("damaged","The rewind\u2019s journal holds a state it cannot read.");return e}var ze=class{head;step=0;passes=[];rewindStates=[];undoStates=[];undos=[];lastWrite=Number.NEGATIVE_INFINITY;endedAt;line(e){if(this.head===void 0){if(e.kind!=="head")throw new H("damaged","The rewind\u2019s journal does not begin with its head.");this.head=e,this.passes=[{startedAt:e.startedAt,userId:e.userId}];return}switch(zr.has(e.kind)&&(this.lastWrite=Math.max(this.lastWrite,Date.parse(e.at))),"step"in e&&(this.step=Math.max(this.step,e.step)),e.kind){case"head":throw new H("damaged","The rewind\u2019s journal has two heads.");case"resumed":this.passes.push({startedAt:e.startedAt,userId:e.userId});break;case"removal":this.rewindStates.push(gs(e.state));break;case"end":this.endedAt=e.at;break;case"undo":this.undoStates.push(gs(e.state)),this.undos.push({status:e.status,at:e.at});break;default:break}}result(){let e=this.head;if(e===void 0)throw new H("damaged","The rewind\u2019s journal does not begin with its head.");return{head:{rewindId:e.rewindId,checkpointId:e.checkpointId,organizationId:e.organizationId,startedAt:e.startedAt,userId:e.userId,...e.automatedProcessUserId!==void 0?{automatedProcessUserId:e.automatedProcessUserId}:{},backup:e.backup},passes:this.passes,...Number.isFinite(this.lastWrite)?{lastWriteAt:new Date(this.lastWrite).toISOString()}:{},...this.endedAt!==void 0?{endedAt:this.endedAt}:{},rewind:hs(this.rewindStates),undo:hs(this.undoStates),undos:this.undos}}},Dt=class{broughtBack=new he;recreated=new he;carriers=new he;carried=new Map;givenBack=new he;held=new he;heldBy=new Map;beforeParent=[];withParents=new Map;steps=new Map;stepOf(e){let t=this.steps.get(e);return t||(t={deleting:new he,left:new Set,answered:!1},this.steps.set(e,t)),t}line(e){switch(e.kind){case"bringingBack":case"withParent":this.broughtBack.add(e.objectApiName,e.ids),e.carriers===!0&&e.kind==="bringingBack"&&this.carriers.add(e.objectApiName,e.ids),e.parents?.forEach((t,n)=>{let s=e.ids[n],r=e.carriers===!0?this.carried:this.withParents;r.has(W(s))||r.set(W(s),{objectApiName:e.objectApiName,id:s,parent:t})});break;case"bringBackLeft":this.broughtBack.drop(e.objectApiName,e.ids),this.carriers.drop(e.objectApiName,e.ids);for(let t of e.ids)this.withParents.delete(W(t)),this.carried.delete(W(t));break;case"givingBack":this.givenBack.add(e.objectApiName,e.ids);break;case"recreated":this.recreated.add(e.objectApiName,e.ids);break;case"heldInPlace":{this.held.add(e.objectApiName,e.ids);let t=this.heldBy.get(e.objectApiName)??new Set;for(let n of e.by)t.add(n);this.heldBy.set(e.objectApiName,t);break}case"beforeParent":e.ids.forEach((t,n)=>{this.beforeParent.push({objectApiName:e.objectApiName,id:t,parent:e.parents[n]})});break;case"deleting":this.stepOf(e.step).deleting.add(e.objectApiName,e.ids);break;case"deleteLeft":for(let t of e.ids)this.stepOf(e.step).left.add(W(t));break;case"deleted":this.stepOf(e.step).answered=!0;break;default:break}}result(){let e=new he;for(let{deleting:u,left:l,answered:h}of this.steps.values())for(let{objectApiName:g,ids:w}of u.list(y=>!h||!l.has(y)))e.add(g,w);let t=this.held.list().map(({objectApiName:u,ids:l})=>({objectApiName:u,ids:l,by:[...this.heldBy.get(u)??[]]})),n=e.keys(),s=new Set([...this.steps.values()].flatMap(({deleting:u})=>[...u.keys()])),r=new he;for(let{objectApiName:u,id:l,parent:h}of this.beforeParent){let g=W(h);n.has(W(l))&&(n.has(g)||!s.has(g))&&r.add(u,[l])}let a=r.list(),o=u=>{let l=new Map;for(let{objectApiName:h,id:g,parent:w}of u){let y=l.get(h)??{objectApiName:h,ids:[],parents:[]};y.ids.push(g),y.parents.push(w),l.set(h,y)}return[...l.values()]},d=o(this.withParents.values()),c=o(this.carried.values()),p=this.carriers.list(),f=this.recreated.list();return{broughtBack:this.broughtBack.list(),deleted:e.list(),givenBack:this.givenBack.list(),...t.length>0?{heldInPlace:t}:{},...a.length>0?{deletedBeforeParent:a}:{},...d.length>0?{withParents:d}:{},...f.length>0?{recreated:f}:{},...p.length>0?{carriers:p}:{},...c.length>0?{carried:c}:{}}}};async function Ns(i){let e=new ze,t=new Dt;try{await ke(i,n=>{e.line(n),t.line(n)})}catch(n){throw n instanceof H?n:new H("notFound","No journal of this rewind is kept.")}return{...e.result(),did:t.result()}}async function Gr(i){let e=new ze;try{await ke(i,t=>e.line(t))}catch(t){throw t instanceof H?t:new H("notFound","No journal of this rewind is kept.")}return e.result()}function Jr(i,e,t){if(i.head.rewindId!==t||i.head.checkpointId!==e.checkpointId||i.head.organizationId.slice(0,15)!==e.organizationId.slice(0,15))throw new H("damaged","The rewind\u2019s journal names another rewind, checkpoint or org than its folder.")}async function wo(i,e){let t=await We(i,e);if(!t)throw new H("notFound","No journal of this rewind is kept.");return Ns(t.file)}function Bs(i,e){if(i.organizationId.slice(0,15)!==e.organizationId.slice(0,15))throw new H("invalid","A rewind\u2019s journal is written under its org\u2019s lock.")}async function We(i,e){let t=je(i,e),n=ee(t,Te),s=new ze,r;try{r=await ke(n,o=>s.line(o))}catch(o){if(o instanceof H)throw o;return}if(r.count===0||s.head===void 0)return;let a=s.result();return Jr(a,i,e),{dir:t,file:n,head:s.head,step:s.step,whole:r.whole,size:r.size,facts:a}}async function Cs(i,e){return i.whole<i.size&&await Ss(i.file,i.whole),lt.opened(i.dir,i.head,!0,i.step,e)}var ws=18;async function Kr(i){let e;try{e=(await Rs(i.rewindsDir,{withFileTypes:!0})).filter(n=>n.isDirectory()&&Je.safeParse(n.name).success).map(n=>n.name).sort().reverse()}catch{return[]}let[t]=e;return t===void 0?[]:e.filter(n=>n.slice(0,ws)===t.slice(0,ws))}async function Fs(i){let{folder:e}=i;Bs(i.lock,e);let t=i.now??(()=>new Date),n;for(let d of await Kr(e)){let c=await We(e,d);if(!c){n??=d;continue}if(c.facts.endedAt!==void 0||c.facts.undos.length>0)continue;let p=await Cs(c,t);try{await p.append({kind:"resumed",startedAt:i.startedAt,userId:i.userId})}catch(f){throw await p.close(),f}return p}let s=n??$e("rw",t()),r=je(e,s);await Le(r),await Le(ee(r,"backups")),await Ss(ee(r,Te),0).catch(()=>{});let a=js.safeParse({kind:"head",version:1,rewindId:s,checkpointId:e.checkpointId,organizationId:e.organizationId,startedAt:i.startedAt,userId:i.userId,...i.automatedProcessUserId!==void 0?{automatedProcessUserId:i.automatedProcessUserId}:{},backup:Xn(s),at:t().toISOString()});if(!a.success)throw new H("invalid",`Not a rewind to journal: ${a.error.message}`);let o=await lt.opened(r,a.data,!1,0,t);try{await o.append(a.data),await Et(r),await Et(e.rewindsDir)}catch(d){throw await o.close(),d}return o}async function Ts(i,e,t,n=()=>new Date){Bs(t,i);let s=await We(i,e);if(!s)throw new H("notFound","No journal of this rewind is kept.");return Cs(s,n)}async function Es(i,e,t){let n=await i.checkpointsOf(e.organizationId),s=Fn(n),r=[],a=[...n].sort((o,d)=>o.folder.checkpointId<d.folder.checkpointId?-1:1);for(let{folder:o,checkpoint:d}of a){if(d===void 0)continue;let c;try{c=(await Rs(o.rewindsDir,{withFileTypes:!0})).filter(f=>f.isDirectory()&&Je.safeParse(f.name).success).map(f=>f.name).sort()}catch{continue}let p=(f,u)=>u?.checkpointId===o.checkpointId&&u.rewindId===f;for(let f of c){if(p(f,t)||p(f,s))continue;let u=await We(o,f).catch(()=>{});u===void 0||u.facts.endedAt===void 0&&u.facts.undos.length===0||(await vs(je(o,f),{recursive:!0,force:!0}),r.push({checkpointId:o.checkpointId,name:d.name,rewindId:f}))}}return r}var Mt=class i{constructor(e,t,n){this.dir=e;this.objects=t;this.keys=n}dir;objects;keys;get count(){return this.objects.reduce((e,t)=>e+t.count,0)}static async written(e,t){await Le(e);let n=new E,s=new Map,r=new Map,a=async o=>{let d=r.get(o)??[];d.length!==0&&(await Ut(ms(e,o),d.join("")),r.set(o,[]))};await t(async(o,{id:d,parent:c})=>{if(!n.add(d))return;s.set(o,(s.get(o)??0)+1);let p=r.get(o)??[];p.push(`${d} ${c}
|
|
10
10
|
`),r.set(o,p),p.length>=J&&await a(o)});for(let o of s.keys())await a(o);return new i(e,[...s].map(([o,d])=>({objectApiName:o,count:d})),n)}async*pages(e,t=J){if(!this.objects.some(a=>a.objectApiName===e))return;let n=bs(ms(this.dir,e),{encoding:"utf8"}),s=Os({input:n,crlfDelay:1/0}),r=[];try{for await(let a of s){let[o,d]=a.split(" ");o===void 0||d===void 0||(r.push({id:o,parent:d}),r.length>=t&&(yield r,r=[]))}}finally{s.close(),n.destroy()}r.length>0&&(yield r)}};function ms(i,e){return ee(i,`${nn(e)}.pairs`)}async function Ft(i,e,t){return e.length>0&&(await Le(Is(i)),await Ut(i,e.map(n=>`${JSON.stringify(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 P,b as $}from"./chunk-
|
|
7
|
+
import{a as P,b as $}from"./chunk-U2CTKIPE.mjs";import{a as O,b,d as E,e as D}from"./chunk-4GCYGQXD.mjs";import{b as S}from"./chunk-CA5NAXSU.mjs";import{A as m,_c as R}from"./chunk-6QSHWIZI.mjs";var y=[{field:"PermissionsViewAllData",label:"View All Data"},{field:"PermissionsModifyAllData",label:"Modify All Data"}],I="PermissionsQueryAllFiles",T="PermissionsCustomizeApplication",d="No record was read or written.";function c(e,t){return{allowed:!1,refusal:{code:e,message:t}}}function w(e,t){return c("PRODUCTION",`${e} is a production org, or cannot be told from one: ${t}. Checkpoints are for sandboxes, scratch orgs and Developer Edition orgs: SandForge never takes a checkpoint of, or rewinds, a production org. ${d}`)}function N(e){return e.edition?`its Organization record says IsSandbox false, edition ${e.edition}`:"its Organization record says IsSandbox false, and no edition"}function j(e,t){return e.slice(0,15)===t.slice(0,15)}function V(e,t){return e.orgType==="Scratch"?"scratch":t.sandbox?"sandbox":"developer"}var z={take:"A checkpoint needs a user with View All Data and Modify All Data: a rewind to it must",preview:"A preview needs a user with View All Data and Modify All Data: a record the user cannot see would read as deleted since, and the rewind it shows must",rewind:"Rewind needs a user with View All Data and Modify All Data: it must",undo:"Undo needs a user with View All Data and Modify All Data: it must",import:"An import needs a user with View All Data and Modify All Data: SandForge never keeps on this machine records its user could not see in the org, and a rewind to it must"},F={take:"Leave the custom settings out of the checkpoint, or give the user Customize Application.",preview:"This checkpoint holds custom settings: give the user Customize Application.",rewind:"This checkpoint holds custom settings: give the user Customize Application.",undo:"This checkpoint holds custom settings: give the user Customize Application.",import:"This checkpoint holds custom settings: give the user Customize Application."};function x(e){return c("PERMISSIONS",`${e.username} needs Customize Application to keep and rewind custom settings, and doesn't have it: View All Custom Settings lets a user read them, never write them. ${F[e.act]} ${d}`)}async function _(e,t){let r=[...y.map(n=>n.field),...t?[T]:[]],i=async n=>(await e.query(`SELECT ${n.join(", ")} FROM UserPermissionAccess`)).records[0],o;try{o=await i([...r,I])}catch{try{o=await i(r)}catch(n){return{unread:n instanceof Error?n.message:String(n)}}}return{missing:y.filter(n=>o?.[n.field]!==!0).map(n=>n.label),viewAllData:o?.PermissionsViewAllData===!0,modifyAllData:o?.PermissionsModifyAllData===!0,queryAllFiles:o?.[I]===!0,customizeApplication:o?.[T]===!0}}var q=/^005[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,L=/^0PG[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/,M="SobjectType, PermissionsViewAllRecords, PermissionsModifyAllRecords";async function A(e,t){let r=await e.query(t),i=1,o=[...r.records];for(;!r.done;){let n=r.nextRecordsUrl;if(n===void 0||e.queryMore===void 0)throw new Error(`the org answered ${o.length} rows of ${r.totalSize}, and no next page`);r=await e.queryMore(n),i++,o.push(...r.records)}return{rows:o,requests:i}}async function U(e,t){let r=0;try{let i=await t();if(r++,!q.test(i))throw new Error(`the org named the user ${JSON.stringify(i)}`);let o=await A(e,`SELECT ${M} FROM ObjectPermissions WHERE ParentId IN (SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = '${i}' AND PermissionSetGroupId = null)`);r+=o.requests;let n=await A(e,`SELECT PermissionSetGroupId FROM PermissionSetAssignment WHERE AssigneeId = '${i}' AND PermissionSetGroupId != null`);r+=n.requests;let l=[...new Set(n.rows.map(a=>a.PermissionSetGroupId).filter(a=>typeof a=="string"&&L.test(a)))],s=[...o.rows];if(l.length>0){let a=await A(e,`SELECT ${M} FROM ObjectPermissions WHERE Parent.PermissionSetGroupId IN (${l.map(u=>`'${u}'`).join(", ")})`);r+=a.requests,s.push(...a.rows)}return{grants:P(s),requests:r}}catch(i){return{unread:S(i)}}}var v={take:"A checkpoint needs a user with View All Data and Modify All Data, or with View All and Modify All on each object it holds: a rewind to it must see and put back what everyone changed there.",preview:"A preview needs a user with View All Data and Modify All Data, or with View All and Modify All on each object it reads: a record the user cannot see would read as deleted since.",rewind:"Rewind needs a user with View All Data and Modify All Data, or with View All and Modify All on each object it puts back: it must see and put back what everyone changed there.",undo:"Undo needs a user with View All Data and Modify All Data, or with View All and Modify All on each object it takes back: it must see and put back what everyone changed there."};async function Y(e,t,r={}){let{orgName:i,registered:o}=t;if(o===void 0)return w(i,"SandForge has no record of what kind of org it is");if(!R(o))return w(i,"SandForge has it registered as a production org");let n;try{n=await O(e)}catch(p){let C=E(p);if(C!==void 0)return c("ORG_UNTYPED",`${D(i,p,C)} SandForge takes a checkpoint of no org it cannot tell from a production one. ${d}`);let G=p instanceof Error?p.message:String(p);return w(i,`it did not say what org it is (${G})`)}if(b(n))return w(i,N(n));if(t.act!=="take"&&!j(n.id,t.organizationId))return c("OTHER_ORG",t.act==="import"?`${i} is another org than the one this file holds a checkpoint of: it is imported for the org it was taken of alone, under any alias of it. ${m} Replay the file in ${i} instead. Nothing was imported.`:`${i} is another org than the one this checkpoint was taken of: its Organization Id has changed, as a sandbox's does when it is refreshed. This checkpoint is of the org before it, and no longer rewinds. ${m} `+d);let l=t.customSettings===!0,s=await _(e,l),a=`${z[t.act]} see and put back what everyone changed.`;if("unread"in s)return c("PERMISSIONS",`${a} SandForge could not read whether ${t.username} has them (${s.unread}), and takes an org that will not say for a user who has neither. `+d);let u=s.missing.length===y.length?"them":s.missing.join(" and "),g=t.act,f=g==="import"?void 0:r.userId;if(s.missing.length>0&&f===void 0)return c("PERMISSIONS",`${a} ${t.username} doesn't have ${u}. ${d}`);if(l&&!s.customizeApplication)return x(t);let k={allowed:!0,org:n,tier:V(o,n),queryAllFiles:s.queryAllFiles};if(s.missing.length===0||f===void 0||g==="import")return{...k,grants:{kind:"org"}};let h=await U(e,f);return"unread"in h?c("PERMISSIONS",`${v[g]} ${t.username} doesn't have ${u}, and SandForge could not read which objects they have View All and Modify All on (${h.unread}). View Setup and Configuration lets a user read their own permissions; with View All Data and Modify All Data, nothing needs reading. `+d):$(h.grants)?{...k,grants:{kind:"perObject",viewAllData:s.viewAllData,modifyAllData:s.modifyAllData,objects:h.grants,requests:h.requests}}:c("PERMISSIONS",`${v[g]} ${t.username} doesn't have ${u}, nor View All and Modify All on any object. Give the user View All and Modify All on the objects to hold, or View All Data and Modify All Data. ${d}`)}export{U as a,Y as b};
|
|
@@ -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 le}from"./chunk-TUACWKIH.mjs";import{Ra as ce,Ya as de,
|
|
7
|
+
import{a as le}from"./chunk-TUACWKIH.mjs";import{Ra as ce,Ya as de,zd as ue}from"./chunk-6QSHWIZI.mjs";import{b as k,e as I,k as b,l as p,r as ae,s as oe,u as V,v as E}from"./chunk-WZQEK4WT.mjs";import{appendFile as Be,mkdir as Te,readFile as Je,readdir as $e,rename as Ue,rm as We,stat as He,writeFile as Ze}from"node:fs/promises";import*as M from"node:path";import{appendFile as ke,mkdir as Re,readFile as je,readdir as xe,rename as Oe,rm as Ie,stat as Ae,writeFile as Fe}from"node:fs/promises";import*as $ from"node:path";var Ne="sync-links",Me=2e5,_e=16*1024*1024,J=k().regex(/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/),Y=k().min(1).max(200),Ee=p({s:Y,t:Y,o:k().regex(/^[A-Za-z][A-Za-z0-9_]{0,79}$/),p:b(ae([J,J])).max(5e4),l:E(!0).optional()}),De=p({s:Y,t:Y,f:b(J).max(1e6)});function T(i){return i.slice(0,15)}function Ke(i){return i.replace(/[^A-Za-z0-9_-]/g,"_")}function Ce(i){try{return JSON.parse(i)}catch{return}}function Le(i){let e=new Map;for(let t of i.split(`
|
|
8
8
|
`)){if(t.trim()==="")continue;let n=Ce(t),r=Ee.safeParse(n);if(r.success){let{s:y,t:R,o:C,p:P,l:D}=r.data;for(let[_,K]of P){let c=`${y}|${R}|${T(_)}`;e.delete(c),e.set(c,{s:y,t:R,o:C,source:_,target:K,...D===!0?{linked:!0}:{}})}continue}let s=De.safeParse(n);if(!s.success)continue;let{s:o,t:f,f:a}=s.data,g=new Set(a.map(T));for(let[y,R]of e)R.s===o&&R.t===f&&g.has(T(R.target))&&e.delete(y)}return e}function ht(i){return new H({storagePath:i,readFile:e=>je(e,"utf8"),writeFile:(e,t)=>Fe(e,t,"utf8"),appendFile:(e,t)=>ke(e,t,"utf8"),rename:(e,t)=>Oe(e,t),mkdir:async e=>{await Re(e,{recursive:!0})},rm:e=>Ie(e,{force:!0}),listFiles:async e=>{let t;try{t=await xe(e)}catch(r){if(r.code==="ENOENT")return[];throw r}let n=[];for(let r of t){let s=await Ae($.join(e,r)).catch(()=>{});s?.isFile()&&n.push({name:r,size:s.size})}return n}})}var H=class{constructor(e){this.deps=e;this.dir=$.join(e.storagePath,Ne),this.maxPairs=e.maxPairs??Me,this.compactBytes=e.compactBytes??_e}deps;dir;maxPairs;compactBytes;queue=Promise.resolve();fileOf(e){return $.join(this.dir,`${Ke(e)}.ndjson`)}inTurn(e){let t=this.queue.then(e);return this.queue=t.catch(()=>{}),t}async read(e){let t;try{t=await this.deps.readFile(this.fileOf(e))}catch(n){if(n?.code==="ENOENT")return new Map;throw n}return Le(t)}async load(e,t){await this.queue;let n=new Map;for(let r of(await this.read(e)).values())r.s===t.sourceOrgId&&r.t===t.targetOrgId&&n.set(T(r.source),r.target);return n}async linked(e,t){await this.queue;let n=new Set;for(let r of(await this.read(e)).values())r.linked&&r.s===t.sourceOrgId&&r.t===t.targetOrgId&&n.add(T(r.source));return n}record(e,t,n,r,s=!1){let o=r.filter(([f,a])=>J.safeParse(f).success&&J.safeParse(a).success);return o.length===0?Promise.resolve():this.inTurn(async()=>{await this.deps.mkdir(this.dir);let f=this.fileOf(e);for(let a=0;a<o.length;a+=5e4){let g={s:t.sourceOrgId,t:t.targetOrgId,o:n,p:o.slice(a,a+5e4),...s?{l:!0}:{}};await this.deps.appendFile(f,`${JSON.stringify(g)}
|
|
9
9
|
`)}await this.keepWithinBounds(e)})}forget(e,t,n){let r=new Set(n.filter(s=>J.safeParse(s).success).map(T));return r.size===0?Promise.resolve(0):this.inTurn(async()=>{let s=0,o=[];for(let a of(await this.read(e)).values())a.s!==t.sourceOrgId||a.t!==t.targetOrgId||r.has(T(a.target))&&(s++,o.push(a.target));if(s===0)return 0;let f={s:t.sourceOrgId,t:t.targetOrgId,f:[...new Set(o)]};return await this.deps.appendFile(this.fileOf(e),`${JSON.stringify(f)}
|
|
10
10
|
`),await this.keepWithinBounds(e),s})}delete(e){return this.inTurn(()=>this.deps.rm(this.fileOf(e)))}async keepWithinBounds(e){let t=this.fileOf(e),n=$.basename(t);if(((await this.deps.listFiles(this.dir)).find(a=>a.name===n)?.size??0)<=this.compactBytes)return;let s=[...(await this.read(e)).values()].slice(-this.maxPairs),o=[];for(let a of s){let g=o[o.length-1];if(g?.s===a.s&&g.t===a.t&&g.o===a.o&&g.l===a.linked&&g.p.length<5e4){g.p.push([a.source,a.target]);continue}o.push({s:a.s,t:a.t,o:a.o,p:[[a.source,a.target]],...a.linked?{l:!0}:{}})}let f=`${t}.${process.pid}.tmp`;await this.deps.writeFile(f,o.map(a=>`${JSON.stringify(a)}
|