@ppdostudio/ppdo-cli 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +22 -3
  3. package/THIRD-PARTY-NOTICES +1 -0
  4. package/dist/bin.js +2 -2
  5. package/dist/chunks/{ado-XAHQWYNQ.js → ado-OTSVKTOE.js} +6 -6
  6. package/dist/chunks/{api-KN24TLH6.js → api-IRGGH5DJ.js} +1 -1
  7. package/dist/chunks/{api-7RAWLIQV.js → api-TZJXGWWQ.js} +1 -1
  8. package/dist/chunks/{auth-VZSJMSMF.js → auth-7CDWOYJE.js} +1 -1
  9. package/dist/chunks/{azCli-AEZK2RBQ.js → azCli-UEDQHRLP.js} +1 -1
  10. package/dist/chunks/batch-LKWCBKAB.js +2 -0
  11. package/dist/chunks/{build-LSQEAEFK.js → build-PBPXO3GJ.js} +1 -1
  12. package/dist/chunks/bulk-NY5XX752.js +2 -0
  13. package/dist/chunks/chunk-2IUXH534.js +2 -0
  14. package/dist/chunks/{chunk-STWQDANK.js → chunk-3L7657R3.js} +1 -1
  15. package/dist/chunks/{chunk-MGZDEW3X.js → chunk-46KBBWEH.js} +1 -1
  16. package/dist/chunks/{chunk-B4FPKDMH.js → chunk-6NBCHK6X.js} +1 -1
  17. package/dist/chunks/chunk-6VLFO5FJ.js +7 -0
  18. package/dist/chunks/{chunk-BCAXUZIO.js → chunk-B3TJ3RJN.js} +1 -1
  19. package/dist/chunks/chunk-BG2OIOSN.js +2 -0
  20. package/dist/chunks/{chunk-MZEUD7ET.js → chunk-BWOEIEFY.js} +1 -1
  21. package/dist/chunks/chunk-ELSYHAYC.js +2 -0
  22. package/dist/chunks/chunk-FOEBNCSD.js +3 -0
  23. package/dist/chunks/{chunk-TM3M633T.js → chunk-GLU4X7PT.js} +2 -2
  24. package/dist/chunks/{chunk-HIW2K6OP.js → chunk-GQLXEQVQ.js} +1 -1
  25. package/dist/chunks/{chunk-4KP27OCL.js → chunk-GY6BUIDP.js} +1 -1
  26. package/dist/chunks/chunk-HJQJ77F2.js +3 -0
  27. package/dist/chunks/chunk-I7MHI5CU.js +151 -0
  28. package/dist/chunks/chunk-ITP35SAY.js +2 -0
  29. package/dist/chunks/{chunk-LL4XQ3L7.js → chunk-J67P6QFC.js} +2 -2
  30. package/dist/chunks/{chunk-WNQERCOO.js → chunk-KBZI5UDL.js} +1 -1
  31. package/dist/chunks/chunk-MNGA7IHQ.js +4 -0
  32. package/dist/chunks/{chunk-MK6QZ4ES.js → chunk-P4IFCLVF.js} +1 -1
  33. package/dist/chunks/chunk-Q2RD4TRK.js +2 -0
  34. package/dist/chunks/chunk-S6NK6GX2.js +5 -0
  35. package/dist/chunks/chunk-SWXCK5C2.js +2 -0
  36. package/dist/chunks/chunk-T4IH34D7.js +2 -0
  37. package/dist/chunks/{chunk-WMDKJRDC.js → chunk-TCLZ4XM6.js} +1 -1
  38. package/dist/chunks/chunk-VC7ADQ6E.js +2 -0
  39. package/dist/chunks/{chunk-I3TMFYRJ.js → chunk-XUHLW6B2.js} +1 -1
  40. package/dist/chunks/{commands-GRWX32IX.js → commands-EOUU353W.js} +1 -1
  41. package/dist/chunks/component-JCIJQELN.js +2 -0
  42. package/dist/chunks/{config-UKI5TBH5.js → config-WV3NZGTI.js} +1 -1
  43. package/dist/chunks/connection-L6CUFUPJ.js +2 -0
  44. package/dist/chunks/connref-IT6K56UT.js +2 -0
  45. package/dist/chunks/convert-ILMJ2HHN.js +5 -0
  46. package/dist/chunks/customizations-AX7ZSXCK.js +2 -0
  47. package/dist/chunks/data-UWOV3LBO.js +5 -0
  48. package/dist/chunks/dependency-V4ZJIWQL.js +3 -0
  49. package/dist/chunks/{discovery-IWAWXXWF.js → discovery-PSGWFMJH.js} +1 -1
  50. package/dist/chunks/{dv-C45WDXRG.js → dv-SD5LTNZJ.js} +109 -48
  51. package/dist/chunks/{env-GL5ZPAZI.js → env-6RZCHQUC.js} +2 -2
  52. package/dist/chunks/environment-IBLJHUAL.js +2 -0
  53. package/dist/chunks/{environments-VZWNFJYE.js → environments-3P2I4QUC.js} +1 -1
  54. package/dist/chunks/envvar-KJ2TUZGJ.js +2 -0
  55. package/dist/chunks/fanout-2WQYFUWL.js +2 -0
  56. package/dist/chunks/{fetchxml-FWUQZP4M.js → fetchxml-M6EOF7N6.js} +1 -1
  57. package/dist/chunks/functions-NILMLS4R.js +2 -0
  58. package/dist/chunks/{graph-OK24IOUV.js → graph-NO2OT2TL.js} +1 -1
  59. package/dist/chunks/{group-TLGLTTUG.js → group-ISSJ4H2A.js} +2 -2
  60. package/dist/chunks/history-JPMLQDJI.js +2 -0
  61. package/dist/chunks/{identity-SRTOEQVC.js → identity-SBQNHSBF.js} +1 -1
  62. package/dist/chunks/init-X2VEK4T2.js +2 -0
  63. package/dist/chunks/jobs-XC7EYPBP.js +2 -0
  64. package/dist/chunks/lifecycle-2F7MF6EP.js +2 -0
  65. package/dist/chunks/{main-HOYSLMHZ.js → main-J3O5YMIY.js} +2 -2
  66. package/dist/chunks/metadata-NZFQIAAG.js +2 -0
  67. package/dist/chunks/metadataCreate-XSHK32TR.js +2 -0
  68. package/dist/chunks/{msalUser-3PBGT655.js → msalUser-KC75VDVV.js} +1 -1
  69. package/dist/chunks/names-N5JRXO33.js +2 -0
  70. package/dist/chunks/{pat-KGOBISLG.js → pat-PCMOZYM5.js} +1 -1
  71. package/dist/chunks/{pipelines-62CVDRXV.js → pipelines-OCHSIQ2E.js} +1 -1
  72. package/dist/chunks/pluginRegister-LEVZNDZN.js +4 -0
  73. package/dist/chunks/{plugins-SBMDFXVA.js → plugins-TEME2R77.js} +1 -1
  74. package/dist/chunks/{policies-BZR5437X.js → policies-EWCANNBE.js} +1 -1
  75. package/dist/chunks/{pools-I4NVR67Z.js → pools-54KMEL5D.js} +1 -1
  76. package/dist/chunks/process-KR7LIXZB.js +2 -0
  77. package/dist/chunks/{projects-GXIQO7HV.js → projects-LPVDFLPC.js} +1 -1
  78. package/dist/chunks/{provider-FN7TXWRE.js → provider-D7DMMAS6.js} +1 -1
  79. package/dist/chunks/{prs-F2EVQJRV.js → prs-C4EKGJWA.js} +1 -1
  80. package/dist/chunks/records-C4RLQXFK.js +2 -0
  81. package/dist/chunks/{run-LNEOCXZA.js → run-27MYTWHY.js} +1 -1
  82. package/dist/chunks/{run-SB4QN5Q4.js → run-46PEJS3S.js} +1 -1
  83. package/dist/chunks/{run-ICS4FNZA.js → run-7L6W2YWJ.js} +1 -1
  84. package/dist/chunks/run-CD3ZOB5V.js +4 -0
  85. package/dist/chunks/{run-APD3TRCW.js → run-EUNN6OZO.js} +1 -1
  86. package/dist/chunks/{run-H2OLE76P.js → run-JDNEQMJC.js} +1 -1
  87. package/dist/chunks/{run-G2MVOV3C.js → run-T3IIJ7SK.js} +1 -1
  88. package/dist/chunks/{run-XRPU3YZF.js → run-ZHIDOKQH.js} +1 -1
  89. package/dist/chunks/{runtime-MIU5CS5B.js → runtime-FJJPTBEE.js} +1 -1
  90. package/dist/chunks/security-SBIAK6QD.js +2 -0
  91. package/dist/chunks/{service-4VHAPTA6.js → service-4N3YP4Z7.js} +1 -1
  92. package/dist/chunks/{service-RFKOKM72.js → service-HASXLUGE.js} +1 -1
  93. package/dist/chunks/{services-4BORTJPM.js → services-C6G4XRXR.js} +1 -1
  94. package/dist/chunks/{skills-6O2GSTU4.js → skills-FW4F3EIW.js} +1 -1
  95. package/dist/chunks/solution-CNBNIS7Z.js +2 -0
  96. package/dist/chunks/solutionExport-Y524HMGN.js +2 -0
  97. package/dist/chunks/{solutionfiles-VWZHFZZ6.js → solutionfiles-2TP3Y2RW.js} +1 -1
  98. package/dist/chunks/{spn-2RZJLCML.js → spn-YSYMDTOI.js} +1 -1
  99. package/dist/chunks/{users-JIBQKPYA.js → users-Q7BJKBPP.js} +1 -1
  100. package/dist/chunks/{vargroups-Q2KG7LHR.js → vargroups-GNZBODVJ.js} +1 -1
  101. package/dist/chunks/{whoami-V54TCLT5.js → whoami-6G6UFTNS.js} +1 -1
  102. package/dist/chunks/{workitems-UG5O3EGB.js → workitems-2IOGD3EL.js} +1 -1
  103. package/package.json +7 -3
  104. package/schema/reference-data.schema.json +192 -0
  105. package/skills/ppdo-cli/SKILL.md +1 -0
  106. package/skills/ppdo-cli-data/SKILL.md +669 -0
  107. package/skills/ppdo-cli-dataverse/SKILL.md +6 -0
  108. package/skills/ppdo-cli-plugins/PluginRegistration.cs +229 -0
  109. package/skills/ppdo-cli-plugins/SKILL.md +95 -0
  110. package/skills/ppdo-cli-plugins/reference.md +72 -0
  111. package/dist/chunks/batch-EZPKLWEI.js +0 -4
  112. package/dist/chunks/bulk-7FZCDH5U.js +0 -2
  113. package/dist/chunks/chunk-5SBBTR3Y.js +0 -2
  114. package/dist/chunks/chunk-BODUSF3V.js +0 -2
  115. package/dist/chunks/chunk-DVQ7OYIJ.js +0 -2
  116. package/dist/chunks/chunk-KBQYSAJX.js +0 -2
  117. package/dist/chunks/chunk-OXZG44O5.js +0 -2
  118. package/dist/chunks/chunk-PYTSDUPY.js +0 -2
  119. package/dist/chunks/chunk-RC5VPVGC.js +0 -2
  120. package/dist/chunks/chunk-TXVNEV3M.js +0 -3
  121. package/dist/chunks/component-TCL43QXZ.js +0 -2
  122. package/dist/chunks/connection-QNXMJGHZ.js +0 -2
  123. package/dist/chunks/connref-U3CMQ64O.js +0 -2
  124. package/dist/chunks/customizations-VNEASPWI.js +0 -7
  125. package/dist/chunks/dependency-U6OQA5PS.js +0 -3
  126. package/dist/chunks/environment-FPS4AFM5.js +0 -2
  127. package/dist/chunks/envvar-52V6K6LF.js +0 -2
  128. package/dist/chunks/fanout-Q3656CCP.js +0 -2
  129. package/dist/chunks/functions-SNCK2IYV.js +0 -2
  130. package/dist/chunks/history-67SQS54S.js +0 -2
  131. package/dist/chunks/jobs-2ZPBDDHT.js +0 -2
  132. package/dist/chunks/lifecycle-OJRM7K2I.js +0 -2
  133. package/dist/chunks/metadata-WYVJ7NP7.js +0 -2
  134. package/dist/chunks/metadataCreate-PBA3KH3A.js +0 -2
  135. package/dist/chunks/names-ZRM6SAYU.js +0 -2
  136. package/dist/chunks/process-WS76WV3T.js +0 -2
  137. package/dist/chunks/records-7IQET422.js +0 -2
  138. package/dist/chunks/run-KP2SNX2A.js +0 -3
  139. package/dist/chunks/security-RC3EI7CZ.js +0 -2
  140. package/dist/chunks/solution-3WUUDYF3.js +0 -2
  141. package/dist/chunks/solutionExport-GTBTHG2D.js +0 -2
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{c as m,i as y}from"./chunk-MBNUMAAZ.js";import{a as C,c as O,d as B}from"./chunk-LB7WNZVK.js";import{d as N}from"./chunk-4KP27OCL.js";import{c as T,f as _,g as b,m as x}from"./chunk-H4OY4EFC.js";import{a as S}from"./chunk-TQLZ3TRU.js";import{e as D}from"./chunk-S4KF5Z3S.js";import{a as A,b as h,c as s,g as d}from"./chunk-WXOTXJNG.js";import{createHash as Y}from"node:crypto";import{readdirSync as F}from"node:fs";var J=/^[A-Za-z0-9]{40,128}$/,U={"X-TFS-FedAuthRedirect":"Suppress"},q=7,Z=864e5,v=e=>Y("sha256").update(e,"utf8").digest("hex"),k=(e,t)=>(e??"").toLowerCase()===(t??"").toLowerCase();function a(e){return e.patEnv?`set ${e.patEnv} to a valid PAT for ${e.organization}`:`run: ppdo-cli auth login ${e.name}`}function z(e){return`the PAT for '${e.name}' was rejected: it may be expired or revoked, lack a scope this command needs, or be for another organization; ${a(e)}`}function w(e,t){let n;try{n=_(y(e.name),{requireEncryption:t})}catch(i){throw i instanceof A?new s(`the stored PAT for '${e.name}' can't be used: ${i.message}`,{hint:a(e)}):new s(`the stored PAT for '${e.name}' can't be read`,{hint:a(e)})}if(!n)return null;let r;try{r=JSON.parse(n.toString("utf8"))}catch{throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`})}let o=r;if(typeof o!="object"||o===null||typeof o.fingerprint!="string"||typeof o.organization!="string")throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`});return o}function R(e,t){return k(e.organization,t.organization)&&m(e.username)===m(t.username??"")}function E(e,t,n){let r=e.trim();if(!J.test(r))throw new s(`the value from ${n} for '${t.name}' is not an Azure DevOps PAT`,{hint:a(t)});return r}function V(e){if(!e)return null;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim()),n=t?new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))):null;if(!t||!n||n.getUTCMonth()!==Number(t[2])-1||n.getUTCDate()!==Number(t[3]))throw new h(`--expires '${e}' is not a date`,{hint:"the PAT's expiry date, as YYYY-MM-DD"});return`${t[1]}-${t[2]}-${t[3]}`}function W(e,t){if(!t?.expires)return;let r=Date.parse(t.expires+"T23:59:59Z")-Date.now();if(r<0)throw new s(`the PAT for '${e.name}' expired on ${t.expires}`,{hint:`create a new one, then ${a(e)}`});r<q*Z&&D(`warning: the PAT for '${e.name}' expires on ${t.expires}`)}function G(e){if(e.method!=="pat")throw new h(`identity '${e.name}' doesn't use a PAT`);if(e.patEnv){let r=process.env[e.patEnv];if(!r)throw new s(`${e.patEnv} is not set, so identity '${e.name}' has no PAT`,{hint:a(e)});let o=E(r,e,e.patEnv),i=w(e,!1),p=i&&i.source==="env"&&R(i,e)&&i.fingerprint===v(o)?i:null;return{value:o,source:`env:${e.patEnv}`,record:p}}let t=w(e,!0);if(!t||t.source!=="store"||typeof t.pat!="string")throw new s(`identity '${e.name}' has no stored PAT`,{hint:a(e)});if(!R(t,e))throw new s(`the stored PAT for '${e.name}' was for another organization or account`,{hint:a(e)});let n=E(t.pat,e,"the store");if(t.fingerprint!==v(n))throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`});return{value:n,source:"store",record:t}}function j(e){return"Basic "+Buffer.from(":"+e,"utf8").toString("base64")}function I(e,t){if(t.name!=="devops")throw new h(`identity '${e.name}' uses a PAT, which reaches Azure DevOps only, not ${t.name}`,{hint:"use an identity that signs in with Entra for this service"});let n=t.org??"";if(!k(n,e.organization))throw new d(`refusing to send the PAT for '${e.name}' to organization '${n}'`,{hint:`identity '${e.name}' is for organization '${e.organization}' only`,service:"devops"})}async function L(e,t,n){let{DevOps:r}=await import("./service-4VHAPTA6.js"),o={header:async(c,M)=>(I(e,M),j(t)),hint:z(e),extraHeaders:()=>U},i={dryRun:!1,timeout:n.timeout,emit:c=>n.emit(c),log:c=>n.log(c)},f=await new N(new r({org:e.organization}),i,o).request("GET","_apis/connectionData",{params:[["connectOptions","none"],["lastChangeId","-1"],["lastChangeId64","-1"],["api-version","7.1-preview"]]}),u=(f.isJson?f.json():null)?.authenticatedUser??null,g=(u?.properties??null)?.Account??null,l=typeof g?.$value=="string"?g.$value:"";if(!l)throw new s(`Azure DevOps didn't accept the PAT for '${e.name}' as an account`,{hint:z(e)});if(m(l)!==m(e.username??""))throw new s(`the PAT belongs to ${l}, but identity '${e.name}' expects ${e.username}`,{hint:`create the PAT while signed in as ${e.username}, or fix the identity's --username`});return{user:l,userId:typeof u?.id=="string"?u.id:null}}function X(e,t,n){let r;try{r=F(S()).filter(o=>/^pat\..+\.bin$/.test(o))}catch{return null}for(let o of n)if(!(o.name===e.name||o.method!=="pat"||!r.includes(`pat.${o.name}.bin`)))try{let i=w(o,o.patEnv===null);if(i&&i.fingerprint===t&&!k(i.organization,e.organization))return o.name}catch{}return null}async function ce(e,t){let n=t.io;if(t.deviceCode)throw new h(`identity '${e.name}' uses a PAT: --device-code doesn't apply`);if(e.patEnv)throw new h(`identity '${e.name}' reads its PAT from ${e.patEnv}, so there is nothing to store`,{hint:`set ${e.patEnv}; ppdo-cli confirms the PAT the first time it is used`});if(!C(n))throw new d(`storing a PAT for '${e.name}' needs a person at a terminal`,{hint:"ask the user to run this command themselves in a terminal"});let r=V(t.expires??null),o=(n??{stderr:process.stderr}).stderr,i=(t.usedBy??[]).map(c=>`${c.name} (${c.mode})`).join(", ")||"no environments yet";o.write(`Storing an Azure DevOps PAT for identity '${e.name}' (${e.username}).
2
+ import{c as m,i as y}from"./chunk-MBNUMAAZ.js";import{a as C,c as O,d as B}from"./chunk-LB7WNZVK.js";import{d as N}from"./chunk-GY6BUIDP.js";import{c as T,f as _,g as b,m as x}from"./chunk-H4OY4EFC.js";import{a as S}from"./chunk-TQLZ3TRU.js";import{e as D}from"./chunk-S4KF5Z3S.js";import{a as A,b as h,c as s,g as d}from"./chunk-WXOTXJNG.js";import{createHash as Y}from"node:crypto";import{readdirSync as F}from"node:fs";var J=/^[A-Za-z0-9]{40,128}$/,U={"X-TFS-FedAuthRedirect":"Suppress"},q=7,Z=864e5,v=e=>Y("sha256").update(e,"utf8").digest("hex"),k=(e,t)=>(e??"").toLowerCase()===(t??"").toLowerCase();function a(e){return e.patEnv?`set ${e.patEnv} to a valid PAT for ${e.organization}`:`run: ppdo-cli auth login ${e.name}`}function z(e){return`the PAT for '${e.name}' was rejected: it may be expired or revoked, lack a scope this command needs, or be for another organization; ${a(e)}`}function w(e,t){let n;try{n=_(y(e.name),{requireEncryption:t})}catch(i){throw i instanceof A?new s(`the stored PAT for '${e.name}' can't be used: ${i.message}`,{hint:a(e)}):new s(`the stored PAT for '${e.name}' can't be read`,{hint:a(e)})}if(!n)return null;let r;try{r=JSON.parse(n.toString("utf8"))}catch{throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`})}let o=r;if(typeof o!="object"||o===null||typeof o.fingerprint!="string"||typeof o.organization!="string")throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`});return o}function R(e,t){return k(e.organization,t.organization)&&m(e.username)===m(t.username??"")}function E(e,t,n){let r=e.trim();if(!J.test(r))throw new s(`the value from ${n} for '${t.name}' is not an Azure DevOps PAT`,{hint:a(t)});return r}function V(e){if(!e)return null;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim()),n=t?new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))):null;if(!t||!n||n.getUTCMonth()!==Number(t[2])-1||n.getUTCDate()!==Number(t[3]))throw new h(`--expires '${e}' is not a date`,{hint:"the PAT's expiry date, as YYYY-MM-DD"});return`${t[1]}-${t[2]}-${t[3]}`}function W(e,t){if(!t?.expires)return;let r=Date.parse(t.expires+"T23:59:59Z")-Date.now();if(r<0)throw new s(`the PAT for '${e.name}' expired on ${t.expires}`,{hint:`create a new one, then ${a(e)}`});r<q*Z&&D(`warning: the PAT for '${e.name}' expires on ${t.expires}`)}function G(e){if(e.method!=="pat")throw new h(`identity '${e.name}' doesn't use a PAT`);if(e.patEnv){let r=process.env[e.patEnv];if(!r)throw new s(`${e.patEnv} is not set, so identity '${e.name}' has no PAT`,{hint:a(e)});let o=E(r,e,e.patEnv),i=w(e,!1),p=i&&i.source==="env"&&R(i,e)&&i.fingerprint===v(o)?i:null;return{value:o,source:`env:${e.patEnv}`,record:p}}let t=w(e,!0);if(!t||t.source!=="store"||typeof t.pat!="string")throw new s(`identity '${e.name}' has no stored PAT`,{hint:a(e)});if(!R(t,e))throw new s(`the stored PAT for '${e.name}' was for another organization or account`,{hint:a(e)});let n=E(t.pat,e,"the store");if(t.fingerprint!==v(n))throw new s(`the stored PAT for '${e.name}' can't be read`,{hint:`delete it and ${a(e)}`});return{value:n,source:"store",record:t}}function j(e){return"Basic "+Buffer.from(":"+e,"utf8").toString("base64")}function I(e,t){if(t.name!=="devops")throw new h(`identity '${e.name}' uses a PAT, which reaches Azure DevOps only, not ${t.name}`,{hint:"use an identity that signs in with Entra for this service"});let n=t.org??"";if(!k(n,e.organization))throw new d(`refusing to send the PAT for '${e.name}' to organization '${n}'`,{hint:`identity '${e.name}' is for organization '${e.organization}' only`,service:"devops"})}async function L(e,t,n){let{DevOps:r}=await import("./service-4N3YP4Z7.js"),o={header:async(c,M)=>(I(e,M),j(t)),hint:z(e),extraHeaders:()=>U},i={dryRun:!1,timeout:n.timeout,emit:c=>n.emit(c),log:c=>n.log(c)},f=await new N(new r({org:e.organization}),i,o).request("GET","_apis/connectionData",{params:[["connectOptions","none"],["lastChangeId","-1"],["lastChangeId64","-1"],["api-version","7.1-preview"]]}),u=(f.isJson?f.json():null)?.authenticatedUser??null,g=(u?.properties??null)?.Account??null,l=typeof g?.$value=="string"?g.$value:"";if(!l)throw new s(`Azure DevOps didn't accept the PAT for '${e.name}' as an account`,{hint:z(e)});if(m(l)!==m(e.username??""))throw new s(`the PAT belongs to ${l}, but identity '${e.name}' expects ${e.username}`,{hint:`create the PAT while signed in as ${e.username}, or fix the identity's --username`});return{user:l,userId:typeof u?.id=="string"?u.id:null}}function X(e,t,n){let r;try{r=F(S()).filter(o=>/^pat\..+\.bin$/.test(o))}catch{return null}for(let o of n)if(!(o.name===e.name||o.method!=="pat"||!r.includes(`pat.${o.name}.bin`)))try{let i=w(o,o.patEnv===null);if(i&&i.fingerprint===t&&!k(i.organization,e.organization))return o.name}catch{}return null}async function ce(e,t){let n=t.io;if(t.deviceCode)throw new h(`identity '${e.name}' uses a PAT: --device-code doesn't apply`);if(e.patEnv)throw new h(`identity '${e.name}' reads its PAT from ${e.patEnv}, so there is nothing to store`,{hint:`set ${e.patEnv}; ppdo-cli confirms the PAT the first time it is used`});if(!C(n))throw new d(`storing a PAT for '${e.name}' needs a person at a terminal`,{hint:"ask the user to run this command themselves in a terminal"});let r=V(t.expires??null),o=(n??{stderr:process.stderr}).stderr,i=(t.usedBy??[]).map(c=>`${c.name} (${c.mode})`).join(", ")||"no environments yet";o.write(`Storing an Azure DevOps PAT for identity '${e.name}' (${e.username}).
3
3
  It will be sent to https://dev.azure.com/${e.organization}/ only, for: ${i}.
4
4
  Use a PAT for this one organization, with the fewest scopes you need and a short expiry.
5
5
  `);let p=E(await B("PAT (input hidden): ",n),e,"the prompt"),f=v(p),$=X(e,f,t.identities??[]);if($)throw new d(`this PAT is also stored for identity '${$}', which is for another organization`,{hint:'it is probably an "All accessible organizations" PAT: create one for this organization only'});let u=T();if(u==="none")throw new A("refusing to store a PAT unencrypted: DPAPI is not available",{hint:`install the optional dependency @azure/msal-node-extensions, or use an environment variable: ppdo-cli identity update ${e.name} --pat-env <VAR>`});let P=await L(e,p,t.rt);if(u==="file-permissions"&&await O(`This computer has no OS encryption ppdo-cli can use, so the PAT is stored protected by file
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{G as v,b as W,c as H,d as J,e as $,f as i,g as U,h as y,i as T,k as S,n as L,s as V,t as f,u as m,v as d,x as Y,z as h}from"./chunk-BG2OIOSN.js";import{a as B,b as A,d as _,e as P,f as z,h as j,i as D}from"./chunk-FOEBNCSD.js";import{b as G}from"./chunk-2IUXH534.js";import{e as F}from"./chunk-S4KF5Z3S.js";import{b as I,d as E,j as C}from"./chunk-WXOTXJNG.js";var Z={owner:0,access:1,"aad-group":2,"aad-office":3},K=new Map(Object.entries(Z).map(([e,a])=>[a,e])),re=["Create","Read","Write","Delete","Append","AppendTo","Assign","Share"],ee="name,teamtype,azureactivedirectoryobjectid,membershiptype,isdefault,_businessunitid_value,_administratorid_value,description,teamid",Q="name,ismanaged,_businessunitid_value,_parentrootroleid_value,roleid";function M(){return Y(`odata.include-annotations="${W}"`)}function ce(e){return e.service.origin}function te(e){return typeof e=="number"&&K.has(e)?K.get(e):e===void 0?null:e}async function N(e,a,t){let n="fullname,domainname,isdisabled,_businessunitid_value,azureactivedirectoryobjectid,accessmode,systemuserid";t.toLowerCase()==="me"&&(t=d(await m(e,a,"GET","WhoAmI")).UserId);let s=A(t)?`systemuserid eq ${_(t)}`:`domainname eq ${P(t)}`,r=y(d(await m(e,a,"GET","systemusers",{params:[["$select",n],["$filter",s]],headers:M()})).value);if(!r.length)throw new E(`no user '${t}'`,{service:"dataverse",hint:"use me, a user id, or a sign-in name"});return r[0]}async function k(e,a,t){let n=A(t)?`teamid eq ${_(t)}`:`name eq ${P(t)}`,s=y(d(await m(e,a,"GET","teams",{params:[["$select",ee],["$filter",n]],headers:M()})).value);if(!s.length)throw new E(`no team '${t}'`,{service:"dataverse",hint:"run: ppdo-cli dv team list --name '*<part>*'"});if(s.length>1)throw new I(`${s.length} teams are named '${t}'; use an id`,{hint:s.map(r=>r.teamid).join(", ")});return s[0]}async function ae(e,a,t,n=null){if(A(t)){let o=d(await m(e,a,"GET",`roles(${_(t)})`,{params:[["$select",Q]]}));if(!n||i(o,"_businessunitid_value")===n)return o;t=o.name}let s=`name eq ${P(t)} and `+(n?`_businessunitid_value eq ${n}`:"_parentroleid_value eq null"),r=y(d(await m(e,a,"GET","roles",{params:[["$select",Q],["$filter",s]]})).value);if(!r.length)throw new E(`no role '${t}'`+(n?" in that business unit":""),{service:"dataverse",hint:"run: ppdo-cli dv role list --name '*<part>*'"});return r[0]}function q(e,a){return $(i(e,`${a}${H}`),i(e,a))}function ne(e){let a=i(e,"teamtype");return T({name:i(e,"name"),type:te(a),business_unit:q(e,"_businessunitid_value"),default:J(i(e,"isdefault"))?e.isdefault:null,entra_group:i(e,"azureactivedirectoryobjectid"),membership:a===2||a===3?q(e,"membershiptype"):null,id:i(e,"teamid")})}async function fe(e){let a=e.args,t=await f(e);G(e,t,"GET","teams",null);let n=[],s=v(a.type);s&&n.push(`teamtype eq ${Z[s]}`);let r=v(a.name);r&&n.push(D("name",r));let o=[["$select",ee],["$orderby","name"]];n.length&&o.push(["$filter",n.join(" and ")]);let[c]=await h(e,t,"teams",o,M(),L(a),"teams");await e.emit(c.map(ne))}async function O(e,a,t){let[n]=await h(e,a,`teams(${t})/teamroles_association`,[["$select","name"]],null,null);return S(n.map(s=>i(s,"name")),s=>s)}async function ye(e){let a=await f(e),t=await k(e,a,String(e.args.team)),[n]=await h(e,a,`teams(${t.teamid})/teammembership_association`,[["$select","fullname,domainname"],["$orderby","fullname"]],null,L(e.args),"members");await e.emit(T({...ne(t),description:i(t,"description"),roles:await O(e,a,t.teamid),members:n.map(s=>({name:i(s,"fullname"),upn:i(s,"domainname")}))}))}async function ie(e,a){let t=e.args,n=await f(e);G(e,n,a?"POST":"DELETE","teams",Buffer.from("{}"));let[s,r]=await n.lookups(async()=>{let c=await k(e,n,String(t.team));return[c,await ae(e,n,String(t.role),i(c,"_businessunitid_value"))]}),o=`teams(${s.teamid})/teamroles_association`;if(a){let c={"@odata.id":`${ce(n)}/api/data/v9.2/roles(${r.roleid})`};await m(e,n,"POST",`${o}/$ref`,{body:Buffer.from(C(c),"utf8")})}else await m(e,n,"DELETE",`${o}(${r.roleid})/$ref`);await e.emit({team:i(s,"name"),role:i(r,"name"),roles:await O(e,n,s.teamid)})}function Re(e){return ie(e,!0)}function $e(e){return ie(e,!1)}var X=["Basic","Local","Deep","Global"];async function se(e,a,t,n,s,r=m){if(n){let l=d(await r(e,a,"GET",`EntityDefinitions(LogicalName='${n}')`,{params:[["$select","SchemaName"]]})).SchemaName,p={};for(let R of re){let g=t.filter(u=>String(i(u,"PrivilegeName")??"").toLowerCase()===`prv${R}${l}`.toLowerCase()).map(u=>i(u,"Depth")),w="none";if(g.length){w=g[0];for(let u of g.slice(1))X.indexOf(u)>X.indexOf(w)&&(w=u)}p[R.toLowerCase()]=w}return{table:n,access:p}}let o=L(e.args),c=S(t.map(l=>({privilege:i(l,"PrivilegeName"),depth:i(l,"Depth")})),l=>l.privilege||"");return o!==null&&c.length>o&&(F(`showing the first ${o} of ${c.length} ${s}; pass --table <name>, --limit n or --all`),c=c.slice(0,o)),{total:t.length,privileges:c}}async function he(e){let a=e.args,t=await f(e);G(e,t,"GET","roles",null);let n=v(a.name),s=["_parentroleid_value eq null",...n?[D("name",n)]:[]],[r]=await h(e,t,"roles",[["$select","name,ismanaged,modifiedon,roleid"],["$filter",s.join(" and ")],["$orderby","name"]],null,L(a),"roles");await e.emit(r.map(o=>({name:i(o,"name"),managed:i(o,"ismanaged"),modified:i(o,"modifiedon"),id:i(o,"roleid")})))}async function ve(e){let a=e.args,t=await f(e),n=await ae(e,t,String(a.role)),[s,r]=j("RetrieveRolePrivilegesRole",[["RoleId",n.roleid]]),o=y(d(await m(e,t,"GET",s,{params:r})).RolePrivileges);await e.emit({name:n.name,managed:i(n,"ismanaged"),id:n.roleid,...await se(e,t,o,v(a.table),"privileges")})}async function be(e){let a=await f(e),t=await N(e,a,String(e.args.user)),n=t.systemuserid,[s]=await h(e,a,`systemusers(${n})/systemuserroles_association`,[["$select","name"]],null,null),[r]=await h(e,a,`systemusers(${n})/teammembership_association`,[["$select","name,teamtype,isdefault,teamid"]],null,null),o=[];for(let c of S(r,l=>String(i(l,"name")||"").toLowerCase()))o.push({name:i(c,"name"),type:te(i(c,"teamtype")),roles:await O(e,a,c.teamid)});await e.emit(T({name:i(t,"fullname"),upn:i(t,"domainname"),business_unit:q(t,"_businessunitid_value"),disabled:i(t,"isdisabled"),access_mode:q(t,"accessmode"),entra_object_id:i(t,"azureactivedirectoryobjectid"),id:n,roles:S(s.map(c=>i(c,"name")),c=>c),teams:o}))}async function _e(e){let a=await f(e),t=await N(e,a,String(e.args.user)),n=y(d(await m(e,a,"GET",`systemusers(${t.systemuserid})/Microsoft.Dynamics.CRM.RetrieveUserPrivileges`)).RolePrivileges);await e.emit({user:$(i(t,"domainname"),i(t,"fullname")),id:t.systemuserid,...await se(e,a,n,v(e.args.table),"privileges")})}async function le(e,a,t){B(t,"entity set name");let n=y(d(await m(e,a,"GET","EntityDefinitions",{params:[["$select","LogicalName"],["$filter",`EntitySetName eq ${P(t)}`]]})).value);if(!n.length)throw new E(`no table with entity set '${t}'`,{service:"dataverse",hint:"use the plural entity set name, e.g. accounts"});return n[0].LogicalName}function oe(e){return(e||"").split(",").map(a=>z(a)).filter(a=>a&&a!=="None").map(a=>a.replace(/Access$/,"").toLowerCase())}async function Ee(e){let a=e.args;V(a,{user:"--user",team:"--team"},!0,"dv access origin");let t=String(a.entityset),n=await f(e),s=await le(e,n,t),r=_(String(a.id)),o,c,l,p=v(a.user);if(p){let b=await N(e,n,p);[o,c,l]=[b.systemuserid,$(i(b,"domainname"),i(b,"fullname")),"systemusers"]}else{let b=await k(e,n,String(a.team));[o,c,l]=[b.teamid,i(b,"name"),"teams"]}let[R,g]=j("RetrieveAccessOrigin",[["ObjectId",r],["LogicalName",s],["PrincipalId",o]],new Set(["LogicalName"])),w=i(d(await m(e,n,"GET",R,{params:g})),"Response"),u=C({"@odata.id":`${t}(${r})`}),x=i(d(await m(e,n,"GET",`${l}(${o})/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@t)`,{params:[["@t",u]]})),"AccessRights");await e.emit({record:`${t}(${r})`,principal:c,rights:oe(x),origin:w})}async function Pe(e){let a=e.args,t=String(a.entityset),n=await f(e);B(t,"entity set name");let s=_(String(a.id)),r=C({"@odata.id":`${t}(${s})`}),o=y(d(await m(e,n,"GET","RetrieveSharedPrincipalsAndAccess(Target=@t)",{params:[["@t",r]]})).PrincipalAccesses),c=[];for(let l of o){let p=U(i(l,"Principal")),R=String(i(p,"@odata.type")||""),g=R.slice(R.lastIndexOf(".")+1),w=$($(i(p,"ownerid"),i(p,"teamid")),i(p,"systemuserid")),u=null;try{if(g==="team")u=i(await k(e,n,w),"name");else if(g==="systemuser"){let x=await N(e,n,w);u=$(i(x,"domainname"),i(x,"fullname"))}}catch{}c.push(T({principal:u,type:g==="systemuser"?"user":g,id:w,rights:oe(i(l,"AccessMask"))}))}await e.emit(c)}export{Z as a,K as b,re as c,N as d,k as e,ae as f,fe as g,ye as h,Re as i,$e as j,se as k,he as l,ve as m,be as n,_e as o,le as p,oe as q,Ee as r,Pe as s};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as d}from"./chunk-J4R6QXW7.js";import{b as l}from"./chunk-WXOTXJNG.js";var A=/^[A-Za-z_][A-Za-z0-9_]{0,127}\n?$/,m=/^[A-Za-z_][A-Za-z0-9_.]{0,255}\n?$/,w=/^\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}?\n?$/,h=/^-?\d+(\.\d+)?\n?$/;function g(t,s="name",n=!1){if(!(n?m:A).test(t||""))throw new l(`invalid ${s} '${t??"None"}'`,{hint:"use the logical/entity set name: letters, digits, '_'"});return t}function p(t){return w.test(t)}function x(t,s){let n=0,r=t.length;for(;n<r&&s.includes(t[n]);)n++;for(;r>n&&s.includes(t[r-1]);)r--;return t.slice(n,r)}function $(t){return x(t,"{}").toLowerCase()}function u(t){return"'"+t.split("'").join("''")+"'"}function _(t,s){return s?t:p(t)?$(t):u(t)}function a(t){return x(t,`
3
+ \r\v\f`)}function R(t){if(t=a(t),p(t))return`(${$(t)})`;let s=[];for(let n of E(t)){let r=!1,e,i,c=n.indexOf(":="),o=n.indexOf("=");if(c>=0)e=n.slice(0,c),i=n.slice(c+2),r=!0;else if(o>=0)e=n.slice(0,o),i=n.slice(o+1);else throw new l(`invalid key '${t}'`,{hint:"use a GUID, name=value, or name:=123 for numbers"});if(g(a(e),"key attribute"),r&&!h.test(a(i))&&!p(a(i)))throw new l(`'${e}:=${i}' must be a number or GUID`,{hint:`use ${e}=${i} for text`});s.push(`${a(e)}=${_(r?a(i):i,r)}`)}return"("+s.join(",")+")"}var y=/^\s*[A-Za-z_][A-Za-z0-9_]*\s*:?=/;function E(t){let s=[],n="";for(let r of t.split(","))n&&y.test(r)?(s.push(n),n=r):n=n?`${n},${r}`:r;return n&&s.push(n),s}function I(t,s){return g(t,"entity set name"),t+d(R(s),"(),'=:")}function b(t,s=!1){if(s)return u(t);let n=a(t);if(n.slice(0,1)===""||"[{".includes(n.slice(0,1)))try{return JSON.parse(n),n}catch{}return n==="true"||n==="false"||n==="null"||h.test(n)?n:p(n)?$(n):n.startsWith("Microsoft.Dynamics.CRM.")&&n.includes("'")?n:u(t)}function U(t,s,n=new Set){if(g(t,"function name",!0),!s.length)return[`${t}()`,[]];let r=[],e=[];return s.forEach(([i,c],o)=>{g(i,"parameter name"),r.push(`${i}=@p${o+1}`),e.push([`@p${o+1}`,b(c,n.has(i))])}),[`${t}(${r.join(",")})`,e]}function Z(t,s){for(let f of t.split("/"))g(f,"column name");let n=a(s);if(!n.includes("*"))return`${t} eq ${u(n)}`;let r=n.split("*"),e=r[0],i=r[r.length-1],c=r.slice(1,-1).filter(f=>f),o=[];e&&o.push(`startswith(${t},${u(e)})`),i&&o.push(`endswith(${t},${u(i)})`);for(let f of c)o.push(`contains(${t},${u(f)})`);return o.join(" and ")||`${t} ne null`}export{g as a,p as b,x as c,$ as d,u as e,a as f,I as g,U as h,Z as i};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a as e,b as n,c as o}from"./chunk-S4KF5Z3S.js";var i=class{args;sink;configPromise;formatPromise;constructor(r,t=null){this.args=r,this.sink=t}get verbose(){return!!this.args.verbose}get dryRun(){return!!this.args.dryRun}get timeout(){let r=this.args.timeout;return typeof r=="number"?r:void 0}config(){return this.configPromise??=import("./config-UKI5TBH5.js").then(({Config:r})=>r.load())}format(){return this.formatPromise??=this.resolveFormat()}async resolveFormat(){if(this.sink!==null)return"json";let r=this.args.output;return typeof r=="string"&&r?e(r):e(null,(await this.config()).output)}async emit(r){if(this.sink!==null){this.sink.push(r);return}await n(r,await this.format())}async emitStream(r){if(this.sink!==null){let t=[];for await(let s of r)t.push(s);return this.sink.push(t),t.length}return o(r,await this.format())}log(r){this.verbose&&process.stderr.write(r+`
3
- `)}async client(r){let{clientFor:t}=await import("./services-4BORTJPM.js");return t(this,r)}};export{i as a};
2
+ import{a as e,b as n,c as o}from"./chunk-S4KF5Z3S.js";var i=class{args;sink;configPromise;formatPromise;constructor(r,t=null){this.args=r,this.sink=t}get verbose(){return!!this.args.verbose}get dryRun(){return!!this.args.dryRun}get timeout(){let r=this.args.timeout;return typeof r=="number"?r:void 0}config(){return this.configPromise??=import("./config-WV3NZGTI.js").then(({Config:r})=>r.load())}format(){return this.formatPromise??=this.resolveFormat()}async resolveFormat(){if(this.sink!==null)return"json";let r=this.args.output;return typeof r=="string"&&r?e(r):e(null,(await this.config()).output)}async emit(r){if(this.sink!==null){this.sink.push(r);return}await n(r,await this.format())}async emitStream(r){if(this.sink!==null){let t=[];for await(let s of r)t.push(s);return this.sink.push(t),t.length}return o(r,await this.format())}log(r){this.verbose&&process.stderr.write(r+`
3
+ `)}async client(r){let{clientFor:t}=await import("./services-C6G4XRXR.js");return t(this,r)}};export{i as a};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{s as d,u as c}from"./chunk-STWQDANK.js";import{b as h}from"./chunk-LB7WNZVK.js";import{b as m,g as a}from"./chunk-WXOTXJNG.js";async function w(e,i,n={stdin:process.stdin,stderr:process.stderr}){if(!(n.stdin.isTTY&&n.stderr.isTTY))throw new a(`changing '${e}' needs a person: ${i.join("; ")}`,{hint:"ask the user to run this command themselves in a terminal"});if(n.stderr.write(`This widens what agents can change:
2
+ import{s as d,u as c}from"./chunk-3L7657R3.js";import{b as h}from"./chunk-LB7WNZVK.js";import{b as m,g as a}from"./chunk-WXOTXJNG.js";async function w(e,i,n={stdin:process.stdin,stderr:process.stderr}){if(!(n.stdin.isTTY&&n.stderr.isTTY))throw new a(`changing '${e}' needs a person: ${i.join("; ")}`,{hint:"ask the user to run this command themselves in a terminal"});if(n.stderr.write(`This widens what agents can change:
3
3
  `+i.map(r=>` - ${r}
4
4
  `).join("")+`Type '${e}' to confirm: `),(await h(n.stdin)).trim()!==e)throw new a("not confirmed; nothing was changed")}async function b(e,i,n){let r=await d.load(),o=r.clone();await i(o),o.validate();let s=c(r,o);return s.length&&await w(e,s,n),d.edit(async t=>{let f=t.clone(),g=await i(t);if(t.validate(),c(f,t).some(l=>!s.includes(l)))throw new m("the config changed while confirming; run the command again");return g})}export{b as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a as se,e as P}from"./chunk-J4R6QXW7.js";import{a as ne}from"./chunk-5SBBTR3Y.js";import{a as ee}from"./chunk-WMDKJRDC.js";import{i as re}from"./chunk-H4OY4EFC.js";import{a as te}from"./chunk-TQLZ3TRU.js";import{a as O,c as L,d as X,e as V,f as K,g as Z,h as Q}from"./chunk-WXOTXJNG.js";import{execFileSync as Te}from"node:child_process";import{createWriteStream as xe,mkdirSync as Se,readdirSync as ve,readFileSync as G,statSync as be}from"node:fs";import F from"node:http";import U from"node:https";import{pipeline as _e}from"node:stream/promises";import J from"node:tls";import{dirname as Ce,join as ge,resolve as Ae}from"node:path";var Oe=`ppdo-cli/${ee}`,$e=new Set([429,502,503,504]),B=new Set(["GET","HEAD","PUT","DELETE","OPTIONS"]),oe=60,Le=2,I=6,Ne=300,M=class{constructor(e,t,n,s,i,o=null){this.status=e;this.reason=t;this.headers=n;this.body=s;this.url=i;this.savedTo=o}header(e){return this.headers[e.toLowerCase()]??null}get text(){return this.body.toString("utf8")}json(){return this.body.length?JSON.parse(this.body.toString("utf8")):null}get isJson(){return(this.header("content-type")??"").includes("json")}},D,H="";function ie(r){return r.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g)??[]}function ke(){let r=[],e=process.env.SSL_CERT_FILE;if(e)try{r.push(...ie(G(e,"latin1")))}catch{}let t=process.env.SSL_CERT_DIR;if(t)for(let n of t.split(process.platform==="win32"?";":":")){let s=[];try{s=ve(n)}catch{continue}for(let i of s)try{let o=ge(n,i);be(o).isFile()&&r.push(...ie(G(o,"latin1")))}catch{}}return r}function Ue(){let r=J;if(typeof r.getCACertificates!="function")return H="this Node cannot read the OS certificate store",null;let e=new Set;for(let t of["default","system"])try{for(let n of r.getCACertificates(t))e.add(n.trim())}catch(n){t==="system"&&(H=`cannot read the OS certificate store (${n.message})`)}for(let t of ke())e.add(t.trim());return[...e]}function He(){if(D===void 0){let r=Ue();try{D=r?J.createSecureContext({ca:r}):null}catch(e){H=`cannot load the certificate roots (${e.message})`,D=null}}return D??void 0}function Pe(){let r="behind TLS inspection? the proxy's root CA must be in the OS store, or set SSL_CERT_FILE";return H?`${r}; ${H}: set NODE_USE_SYSTEM_CA=1`:r}var Ie=new Set(["UNABLE_TO_VERIFY_LEAF_SIGNATURE","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","SELF_SIGNED_CERT_IN_CHAIN","DEPTH_ZERO_SELF_SIGNED_CERT","CERT_HAS_EXPIRED","CERT_NOT_YET_VALID","CERT_UNTRUSTED","CERT_REVOKED","CERT_SIGNATURE_FAILURE","CERT_CHAIN_TOO_LONG","HOSTNAME_MISMATCH"]);function me(r){let e=r,t=typeof e?.code=="string"?e.code:"";return Ie.has(t)||t.startsWith("ERR_SSL_")||t.startsWith("ERR_TLS_")||e?.library==="SSL routines"}var De="HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",C;function Fe(r){let e={};for(let t of r.split(/\r?\n/)){let n=/^\s+(\S(?:.*?\S)?)\s+(REG_[A-Z_]+)(?:\s+(.*))?$/.exec(t);if(!n)continue;let[,s="",i="",o=""]=n;e[s]=i==="REG_DWORD"||i==="REG_QWORD"?String(parseInt(o.trim(),16)||0):o.trim()}return e}function Me(r){if(!Number(r.ProxyEnable??"0"))return[{},[]];let e=r.ProxyServer??"",t=r.ProxyOverride??"",n={};if(e.includes("="))for(let s of e.split(";")){let i=s.indexOf("=");i>=0&&(n[s.slice(0,i).trim().toLowerCase()]=s.slice(i+1).trim())}else e&&(n={http:e,https:e});return[n,t.split(";").map(s=>s.trim()).filter(s=>s)]}var qe=3600;function ye(){return ge(te(),"proxy-registry.json")}function Ge(){try{let r=JSON.parse(G(ye(),"utf8"));return typeof r.checked!="number"||Date.now()/1e3-r.checked>qe||r.checked>Date.now()/1e3+60||typeof r.proxies!="object"||r.proxies===null||!Array.isArray(r.override)?null:[r.proxies,r.override.map(String)]}catch{return null}}function Ee(){let r="";try{r=Te("reg.exe",["query",De],{encoding:"utf8",windowsHide:!0,timeout:5e3,stdio:["ignore","pipe","ignore"]})}catch{r=""}let e=Me(Fe(r));try{re(ye(),JSON.stringify({checked:Math.trunc(Date.now()/1e3),proxies:e[0],override:e[1]}))}catch{}return e}function Be(){if(process.platform!=="win32")return[{},[]];if(C)return C.value;let r=Ge();return C=r?{value:r,cached:!0}:{value:Ee(),cached:!1},C.value}function ze(){if(process.platform!=="win32"||!C?.cached)return!1;let r=JSON.stringify(C.value);return C={value:Ee(),cached:!1},JSON.stringify(C.value)!==r}function je(r,e){let t="";for(let n=0;n<e.length;n++){let s=e[n];if(s==="*")t+=".*";else if(s==="?")t+=".";else if(s==="["){let i=e.indexOf("]",n+2);if(i<0)t+="\\[";else{let o=e.slice(n+1,i).replace(/\\/g,"\\\\");o.startsWith("!")?o="^"+o.slice(1):o.startsWith("^")&&(o="\\"+o),t+=`[${o}]`,n=i}}else t+=s.replace(/[.+^${}()|\\/]/g,"\\$&")}return new RegExp(`^${t}$`,"s").test(r)}function ae(r,e){r=r.toLowerCase();for(let t of e)if(t=t.toLowerCase(),t==="<local>"){if(!r.includes("."))return!0}else{if(t==="*"||je(r,t))return!0;if(t.startsWith(".")&&r.endsWith(t))return!0;if(r===t||r.endsWith("."+t.replace(/^[*.]+/,"")))return!0}return!1}function ue(r,e){let t=process.env,n=t.NO_PROXY||t.no_proxy||"";if(n&&ae(e,n.split(",").map(o=>o.trim()).filter(o=>o)))return null;for(let o of[`${r.toUpperCase()}_PROXY`,`${r}_proxy`]){let a=t[o];if(a)return a}let[s,i]=Be();return!Object.keys(s).length||ae(e,i)?null:s[r]||s.http||null}function ce(r){return new URL(r.includes("://")?r:"http://"+r)}function Re(r){if(!r.username)return{};let e=`${decodeURIComponent(r.username)}:${decodeURIComponent(r.password)}`;return{"Proxy-Authorization":"Basic "+Buffer.from(e,"utf8").toString("base64")}}var z=class extends Error{code="EPROXY"},N=class extends Error{code="ETIMEDOUT"};function We(r,e,t,n,s){return new Promise((i,o)=>{let a=`${e.includes(":")?`[${e}]`:e}:${t}`,c=r.protocol==="https:",y={host:r.hostname.replace(/^\[|\]$/g,""),port:Number(r.port)||(c?443:80),method:"CONNECT",path:a,headers:{Host:a,...Re(r)},agent:!1,...c&&s?{secureContext:s}:{}},p=(c?U:F).request(y),d=!1,T=m=>{d||(d=!0,p.destroy(),o(m))};p.setTimeout(n,()=>T(new N(`proxy ${r.host} timed out`))),p.once("connect",(m,h,u)=>{if(!d){if(m.statusCode===200){d=!0,p.setTimeout(0),u.length&&h.unshift(u),i(h);return}h.destroy(),T(new z(`Tunnel connection failed: ${m.statusCode} ${m.statusMessage??""}`.trim()))}}),p.once("error",T),p.end()})}var j=class extends U.Agent{constructor(t,n){super(n);this.proxy=t}createConnection(t,n){let s=String(t.host??t.hostname??"localhost"),i=Number(t.port)||443,o=typeof t.timeout=="number"&&t.timeout>0?t.timeout:6e4;We(this.proxy,s,i,o,this.options.secureContext).then(a=>{let c=J.connect({...t,socket:a});n?.(null,c)},a=>n?.(a,void 0))}},Ye=new Set(["ECONNRESET","EPIPE","ECONNABORTED"]),W=class{timeout;agents=new Map;constructor(e=60){this.timeout=e}agent(e,t){let n=`${e} ${t?.href??""}`,s=this.agents.get(n);if(!s){let i=e==="https"||t?.protocol==="https:"?He():void 0,o={keepAlive:!0,...i?{secureContext:i}:{}};e==="https"&&t?s=new j(t,o):e==="https"||t?.protocol==="https:"?s=new U.Agent(o):s=new F.Agent({keepAlive:!0}),this.agents.set(n,s)}return s}async request(e,t,n={},s=null,i={}){let o=new URL(t),a=P(t),c=o.protocol==="http:"?"http":"https",y=o.hostname.replace(/^\[|\]$/g,""),p=Number(o.port)||(c==="https"?443:80),d=a.path||"/";a.query&&(d+="?"+a.query);let T={"User-Agent":Oe,"Accept-Encoding":"identity",...n},m=Math.max(1,Math.round((i.timeout??this.timeout)*1e3)),h=ue(c,y),u=h?ce(h):null,E=!1;for(let v=1;;v++)try{return await this.once(e,t,c,y,p,d,T,s,m,u,i.saveTo??null)}catch(R){let w=R;if(w.reused&&v===1&&Ye.has(w.code??""))continue;if(!E&&typeof w.code=="string"&&!me(w)&&(E=!0,ze())){let f=ue(c,y);if(f!==h){h=f,u=f?ce(f):null;continue}}throw R}}once(e,t,n,s,i,o,a,c,y,p,d){return new Promise((T,m)=>{let h,u;if(p&&n==="http"){let f=p.protocol==="https:";u=f?U:F,h={host:p.hostname.replace(/^\[|\]$/g,""),port:Number(p.port)||(f?443:80),path:`http://${s}:${i}${o}`,headers:{Host:i===80?s:`${s}:${i}`,...a,...Re(p)}}}else u=n==="https"?U:F,h={host:s,port:i,path:o,headers:a};h.method=e,h.agent=this.agent(n,p),h.timeout=y;let E=!1,v=!1,R=u.request(h),w=f=>{if(E)return;E=!0;let x=v?new N(`timed out after ${y} ms`):f;x.reused=R.reusedSocket,R.destroy(),m(x)};R.on("timeout",()=>{v=!0,R.destroy(new N("timeout"))}),R.on("error",w),R.on("response",f=>{let x={},$=f.rawHeaders;for(let S=0;S+1<$.length;S+=2){let _=$[S].toLowerCase(),k=$[S+1];x[_]=_ in x?`${x[_]}, ${k}`:k}let A=f.statusCode??0,g=f.statusMessage??"";if(f.on("error",w),f.on("aborted",()=>w(Object.assign(new Error("aborted"),{code:"ECONNRESET"}))),d&&A>=200&&A<300){let S=Ae(d);try{Se(Ce(S),{recursive:!0})}catch(_){w(_);return}_e(f,xe(d)).then(()=>{E||(E=!0,T(new M(A,g,x,Buffer.alloc(0),t,d)))},_=>w(_));return}let l=[];f.on("data",S=>l.push(S)),f.on("end",()=>{E||(E=!0,T(new M(A,g,x,Buffer.concat(l),t)))})}),c&&c.length?R.end(Buffer.from(c.buffer,c.byteOffset,c.byteLength)):R.end()})}close(){for(let e of this.agents.values())e.destroy();this.agents.clear()}},Je;function Xe(){return Je??=new W}function le(r,e=Date.now()){if(!r)return null;let t=r.trim();if(/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i.test(t))return Math.max(0,Number(t));if(!/[A-Za-z]{3}/.test(t))return null;let n=Date.parse(/GMT|UTC|[+-]\d{4}$/.test(t)?t:t+" GMT");return Number.isNaN(n)?null:Math.max(0,(n-e)/1e3)}function Ve(r,e){return $e.has(e)?e===429||B.has(r.toUpperCase()):!1}function de(r,e=30){return Math.random()*Math.min(e,2**r)}var Ke=new Set(["authorization","proxy-authorization","cookie","set-cookie"]);function Ze(r){let e={};for(let[t,n]of Object.entries(r))e[t]=Ke.has(t.toLowerCase())?"<redacted>":n;return e}var Y=class extends O{constructor(e="dry run"){super(e,{exitCode:0})}},fe=class{defaultHeaders(){return{Accept:"application/json"}}requestId(e){return null}error(e){return Qe(this.name,e,null,null)}authTrap(e){return null}};function Qe(r,e,t,n,s=null,i=null){let o=e.status,a=n||`HTTP ${o} ${e.reason}`.trim();o===403&&i===null&&(i="signed in, but this account lacks permission for the request");let c={service:r,status:o};switch(t&&(c.code=t),s&&(c.requestId=s),i!==null&&(c.hint=i),o){case 401:return new L(a,c);case 403:return new Q(a,c);case 404:return new X(a,c);case 409:case 412:return new K(a,c);case 429:return new V(a,c);default:return new O(a,c)}}var et=["login.microsoftonline.com","login.windows.net","login.live.com"],tt="run: ppdo-cli auth login <identity>";function rt(r){return{header:async e=>"Bearer "+await r(e)}}var q=r=>new Promise(e=>setTimeout(e,Math.max(0,r*1e3))),b=()=>performance.now()/1e3,nt=":/?#[]@!$&'()*+,;=%~",he=class{service;rt;authorizer;http;target=null;identity=null;cached=null;notBefore=0;inLookups=!1;also=[];constructor(e,t,n,s=Xe()){this.service=e,this.rt=t,this.authorizer=n===null?null:typeof n=="function"?rt(n):n,this.http=s}async lookups(e,t=[]){this.inLookups=!0,this.also=t.map(n=>n.toLowerCase());try{return await e()}finally{this.inLookups=!1,this.also=[]}}async request(e,t,n={}){e=e.toUpperCase();let s=se(this.service.url(t,n.params??null),nt);if(!this.service.allowed(s)){let a="";try{a=new URL(s).hostname}catch{a=P(s).netloc}throw new Z(`refusing to send a ${this.service.name} token to ${a||"None"}`,{hint:"absolute URLs must belong to the environment's own host or organization",service:this.service.name})}let i={...this.service.defaultHeaders(),...n.headers??{}},o=n.body??null;return o!==null&&!Object.keys(i).some(a=>a.toLowerCase()==="content-type")&&(i["Content-Type"]="application/json"),this.rt.dryRun&&!(this.inLookups&&this.isRead(e,s))&&await this.dryRun(e,s,i,o),this.send(e,s,i,o,n.saveTo??null,n.check??!0)}async*paginate(e,t){let n=0,s=await this.request("GET",e,{params:t.params??null,headers:t.headers??null}),i=t.limit??null;for(;;){for(let a of t.items(s))if(yield a,n++,i!==null&&n>=i)return;let o=t.nextLink(s);if(!o)return;s=await this.request("GET",o,{headers:t.headers??null})}}isRead(e,t){if(e==="GET"||e==="HEAD")return!0;if(e!=="POST")return!1;let n=P(t).path.replace(/\/+$/,""),s=n.slice(n.lastIndexOf("/")+1).toLowerCase();return this.also.includes(s)||ne(this.service.name,t)}async dryRun(e,t,n,s){let i=null;if(s!==null){let o=Buffer.from(s).toString("utf8");try{i=JSON.parse(o)}catch{i=o}}throw await this.rt.emit({dry_run:!0,method:e,url:t,headers:Ze(n),body:i}),new Y("dry run")}async authHeader(e=!1){return this.authorizer===null?"":((e||this.cached===null||this.cached.service!==this.service)&&(this.cached={service:this.service,header:await this.authorizer.header(e,this.service)}),this.cached.header)}async send(e,t,n,s,i,o){let a=this.service.name,c=this.authorizer?.hint??tt,y=b()+(this.rt.timeout||Ne),p=!1,d=0,T=0,m=t,h=!0,u;for(;;){d++;let E=this.notBefore-b();E>0&&(this.rt.log(`throttle: waiting ${E.toFixed(1)}s (Retry-After from an earlier response)`),await q(E));let v={...n};h&&this.authorizer!==null&&(v.Authorization=await this.authHeader(),Object.assign(v,this.authorizer.extraHeaders?.()??{}));let R=b();this.rt.log(`-> ${e} ${m}`);let w=pe(m);try{u=await this.http.request(e,m,v,s,{timeout:Math.min(120,Math.max(5,y-b())),saveTo:i})}catch(g){let l=g;if(l instanceof O)throw l;if(l instanceof N||l.code==="ETIMEDOUT"){if(B.has(e)&&d<I&&b()<y){this.rt.log(` timeout (${l.message}); retrying`);continue}throw new O(`request timed out: ${e} ${m}`,{service:a})}if(me(l))throw new O(`TLS error talking to ${w}: ${l.message}`,{service:a,hint:Pe()});if(typeof l.code!="string")throw g;let S=l.code==="ENOTFOUND"||l.code==="EAI_AGAIN"||l.code==="EAI_FAIL";if((l.code==="ECONNREFUSED"||B.has(e))&&!S&&d<I&&b()<y){let k=de(d);this.rt.log(` connection error (${l.message}); retrying in ${k.toFixed(1)}s`),await q(k);continue}throw new O(`cannot reach ${w}: ${l.message}`,{service:a,hint:"check the network, proxy (HTTPS_PROXY) and the URL"})}let f=(b()-R)*1e3,x=this.service.requestId(u);this.rt.log(`<- ${u.status} ${u.reason} (${f.toFixed(0)} ms)`+(x?` request-id=${x}`:""));let $=le(u.header("retry-after"));$&&u.status<400&&(this.notBefore=b()+Math.min($,oe));let A=this.service.authTrap(u);if(A)throw new L(A,{service:a,status:u.status,hint:c});if(u.status===401&&h&&this.authorizer!==null){let g=u.header("www-authenticate")??"";if(g.includes("insufficient_claims")||g.includes("claims="))throw new L("the service requires a fresh sign-in (claims challenge)",{service:a,status:401,hint:c});if(!p){p=!0,this.rt.log(" 401: refreshing the token once"),await this.authHeader(!0);continue}if(this.authorizer.hint)throw new L(`${a} rejected the credential (401)`,{service:a,status:401,hint:c})}if(u.status>=300&&u.status<400&&u.status!==304){let g=u.header("location");if(!g)break;try{g=new URL(g,m).toString()}catch{break}let l=pe(g);if(et.includes(l)||g.includes("_signin"))throw new L("the service redirected to a sign-in page (token rejected)",{service:a,status:u.status,hint:c});if(T++,T>5||e!=="GET"&&e!=="HEAD")break;m=g,h=!1,this.rt.log(` redirect to ${l} (without Authorization)`);continue}if(Ve(e,u.status)&&d<I){let g=le(u.header("retry-after")),l=g!==null?Math.min(g,oe):u.status===429?Le:de(d);if(b()+l<y){this.rt.log(` ${u.status}: retrying in ${l.toFixed(1)}s (attempt ${d}/${I})`),await q(l);continue}}break}if(o&&u.status>=400)throw this.service.error(u);return u}};function pe(r){try{return new URL(r).hostname}catch{return""}}export{Xe as a,fe as b,Qe as c,he as d};
2
+ import{a as se,e as P}from"./chunk-J4R6QXW7.js";import{a as ne}from"./chunk-2IUXH534.js";import{a as ee}from"./chunk-TCLZ4XM6.js";import{i as re}from"./chunk-H4OY4EFC.js";import{a as te}from"./chunk-TQLZ3TRU.js";import{a as O,c as L,d as X,e as V,f as K,g as Z,h as Q}from"./chunk-WXOTXJNG.js";import{execFileSync as Te}from"node:child_process";import{createWriteStream as xe,mkdirSync as Se,readdirSync as ve,readFileSync as G,statSync as be}from"node:fs";import F from"node:http";import U from"node:https";import{pipeline as _e}from"node:stream/promises";import J from"node:tls";import{dirname as Ce,join as ge,resolve as Ae}from"node:path";var Oe=`ppdo-cli/${ee}`,$e=new Set([429,502,503,504]),B=new Set(["GET","HEAD","PUT","DELETE","OPTIONS"]),oe=60,Le=2,I=6,Ne=300,M=class{constructor(e,t,n,s,i,o=null){this.status=e;this.reason=t;this.headers=n;this.body=s;this.url=i;this.savedTo=o}header(e){return this.headers[e.toLowerCase()]??null}get text(){return this.body.toString("utf8")}json(){return this.body.length?JSON.parse(this.body.toString("utf8")):null}get isJson(){return(this.header("content-type")??"").includes("json")}},D,H="";function ie(r){return r.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/g)??[]}function ke(){let r=[],e=process.env.SSL_CERT_FILE;if(e)try{r.push(...ie(G(e,"latin1")))}catch{}let t=process.env.SSL_CERT_DIR;if(t)for(let n of t.split(process.platform==="win32"?";":":")){let s=[];try{s=ve(n)}catch{continue}for(let i of s)try{let o=ge(n,i);be(o).isFile()&&r.push(...ie(G(o,"latin1")))}catch{}}return r}function Ue(){let r=J;if(typeof r.getCACertificates!="function")return H="this Node cannot read the OS certificate store",null;let e=new Set;for(let t of["default","system"])try{for(let n of r.getCACertificates(t))e.add(n.trim())}catch(n){t==="system"&&(H=`cannot read the OS certificate store (${n.message})`)}for(let t of ke())e.add(t.trim());return[...e]}function He(){if(D===void 0){let r=Ue();try{D=r?J.createSecureContext({ca:r}):null}catch(e){H=`cannot load the certificate roots (${e.message})`,D=null}}return D??void 0}function Pe(){let r="behind TLS inspection? the proxy's root CA must be in the OS store, or set SSL_CERT_FILE";return H?`${r}; ${H}: set NODE_USE_SYSTEM_CA=1`:r}var Ie=new Set(["UNABLE_TO_VERIFY_LEAF_SIGNATURE","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","SELF_SIGNED_CERT_IN_CHAIN","DEPTH_ZERO_SELF_SIGNED_CERT","CERT_HAS_EXPIRED","CERT_NOT_YET_VALID","CERT_UNTRUSTED","CERT_REVOKED","CERT_SIGNATURE_FAILURE","CERT_CHAIN_TOO_LONG","HOSTNAME_MISMATCH"]);function me(r){let e=r,t=typeof e?.code=="string"?e.code:"";return Ie.has(t)||t.startsWith("ERR_SSL_")||t.startsWith("ERR_TLS_")||e?.library==="SSL routines"}var De="HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",C;function Fe(r){let e={};for(let t of r.split(/\r?\n/)){let n=/^\s+(\S(?:.*?\S)?)\s+(REG_[A-Z_]+)(?:\s+(.*))?$/.exec(t);if(!n)continue;let[,s="",i="",o=""]=n;e[s]=i==="REG_DWORD"||i==="REG_QWORD"?String(parseInt(o.trim(),16)||0):o.trim()}return e}function Me(r){if(!Number(r.ProxyEnable??"0"))return[{},[]];let e=r.ProxyServer??"",t=r.ProxyOverride??"",n={};if(e.includes("="))for(let s of e.split(";")){let i=s.indexOf("=");i>=0&&(n[s.slice(0,i).trim().toLowerCase()]=s.slice(i+1).trim())}else e&&(n={http:e,https:e});return[n,t.split(";").map(s=>s.trim()).filter(s=>s)]}var qe=3600;function ye(){return ge(te(),"proxy-registry.json")}function Ge(){try{let r=JSON.parse(G(ye(),"utf8"));return typeof r.checked!="number"||Date.now()/1e3-r.checked>qe||r.checked>Date.now()/1e3+60||typeof r.proxies!="object"||r.proxies===null||!Array.isArray(r.override)?null:[r.proxies,r.override.map(String)]}catch{return null}}function Ee(){let r="";try{r=Te("reg.exe",["query",De],{encoding:"utf8",windowsHide:!0,timeout:5e3,stdio:["ignore","pipe","ignore"]})}catch{r=""}let e=Me(Fe(r));try{re(ye(),JSON.stringify({checked:Math.trunc(Date.now()/1e3),proxies:e[0],override:e[1]}))}catch{}return e}function Be(){if(process.platform!=="win32")return[{},[]];if(C)return C.value;let r=Ge();return C=r?{value:r,cached:!0}:{value:Ee(),cached:!1},C.value}function ze(){if(process.platform!=="win32"||!C?.cached)return!1;let r=JSON.stringify(C.value);return C={value:Ee(),cached:!1},JSON.stringify(C.value)!==r}function je(r,e){let t="";for(let n=0;n<e.length;n++){let s=e[n];if(s==="*")t+=".*";else if(s==="?")t+=".";else if(s==="["){let i=e.indexOf("]",n+2);if(i<0)t+="\\[";else{let o=e.slice(n+1,i).replace(/\\/g,"\\\\");o.startsWith("!")?o="^"+o.slice(1):o.startsWith("^")&&(o="\\"+o),t+=`[${o}]`,n=i}}else t+=s.replace(/[.+^${}()|\\/]/g,"\\$&")}return new RegExp(`^${t}$`,"s").test(r)}function ae(r,e){r=r.toLowerCase();for(let t of e)if(t=t.toLowerCase(),t==="<local>"){if(!r.includes("."))return!0}else{if(t==="*"||je(r,t))return!0;if(t.startsWith(".")&&r.endsWith(t))return!0;if(r===t||r.endsWith("."+t.replace(/^[*.]+/,"")))return!0}return!1}function ue(r,e){let t=process.env,n=t.NO_PROXY||t.no_proxy||"";if(n&&ae(e,n.split(",").map(o=>o.trim()).filter(o=>o)))return null;for(let o of[`${r.toUpperCase()}_PROXY`,`${r}_proxy`]){let a=t[o];if(a)return a}let[s,i]=Be();return!Object.keys(s).length||ae(e,i)?null:s[r]||s.http||null}function ce(r){return new URL(r.includes("://")?r:"http://"+r)}function Re(r){if(!r.username)return{};let e=`${decodeURIComponent(r.username)}:${decodeURIComponent(r.password)}`;return{"Proxy-Authorization":"Basic "+Buffer.from(e,"utf8").toString("base64")}}var z=class extends Error{code="EPROXY"},N=class extends Error{code="ETIMEDOUT"};function We(r,e,t,n,s){return new Promise((i,o)=>{let a=`${e.includes(":")?`[${e}]`:e}:${t}`,c=r.protocol==="https:",y={host:r.hostname.replace(/^\[|\]$/g,""),port:Number(r.port)||(c?443:80),method:"CONNECT",path:a,headers:{Host:a,...Re(r)},agent:!1,...c&&s?{secureContext:s}:{}},p=(c?U:F).request(y),d=!1,T=m=>{d||(d=!0,p.destroy(),o(m))};p.setTimeout(n,()=>T(new N(`proxy ${r.host} timed out`))),p.once("connect",(m,h,u)=>{if(!d){if(m.statusCode===200){d=!0,p.setTimeout(0),u.length&&h.unshift(u),i(h);return}h.destroy(),T(new z(`Tunnel connection failed: ${m.statusCode} ${m.statusMessage??""}`.trim()))}}),p.once("error",T),p.end()})}var j=class extends U.Agent{constructor(t,n){super(n);this.proxy=t}createConnection(t,n){let s=String(t.host??t.hostname??"localhost"),i=Number(t.port)||443,o=typeof t.timeout=="number"&&t.timeout>0?t.timeout:6e4;We(this.proxy,s,i,o,this.options.secureContext).then(a=>{let c=J.connect({...t,socket:a});n?.(null,c)},a=>n?.(a,void 0))}},Ye=new Set(["ECONNRESET","EPIPE","ECONNABORTED"]),W=class{timeout;agents=new Map;constructor(e=60){this.timeout=e}agent(e,t){let n=`${e} ${t?.href??""}`,s=this.agents.get(n);if(!s){let i=e==="https"||t?.protocol==="https:"?He():void 0,o={keepAlive:!0,...i?{secureContext:i}:{}};e==="https"&&t?s=new j(t,o):e==="https"||t?.protocol==="https:"?s=new U.Agent(o):s=new F.Agent({keepAlive:!0}),this.agents.set(n,s)}return s}async request(e,t,n={},s=null,i={}){let o=new URL(t),a=P(t),c=o.protocol==="http:"?"http":"https",y=o.hostname.replace(/^\[|\]$/g,""),p=Number(o.port)||(c==="https"?443:80),d=a.path||"/";a.query&&(d+="?"+a.query);let T={"User-Agent":Oe,"Accept-Encoding":"identity",...n},m=Math.max(1,Math.round((i.timeout??this.timeout)*1e3)),h=ue(c,y),u=h?ce(h):null,E=!1;for(let v=1;;v++)try{return await this.once(e,t,c,y,p,d,T,s,m,u,i.saveTo??null)}catch(R){let w=R;if(w.reused&&v===1&&Ye.has(w.code??""))continue;if(!E&&typeof w.code=="string"&&!me(w)&&(E=!0,ze())){let f=ue(c,y);if(f!==h){h=f,u=f?ce(f):null;continue}}throw R}}once(e,t,n,s,i,o,a,c,y,p,d){return new Promise((T,m)=>{let h,u;if(p&&n==="http"){let f=p.protocol==="https:";u=f?U:F,h={host:p.hostname.replace(/^\[|\]$/g,""),port:Number(p.port)||(f?443:80),path:`http://${s}:${i}${o}`,headers:{Host:i===80?s:`${s}:${i}`,...a,...Re(p)}}}else u=n==="https"?U:F,h={host:s,port:i,path:o,headers:a};h.method=e,h.agent=this.agent(n,p),h.timeout=y;let E=!1,v=!1,R=u.request(h),w=f=>{if(E)return;E=!0;let x=v?new N(`timed out after ${y} ms`):f;x.reused=R.reusedSocket,R.destroy(),m(x)};R.on("timeout",()=>{v=!0,R.destroy(new N("timeout"))}),R.on("error",w),R.on("response",f=>{let x={},$=f.rawHeaders;for(let S=0;S+1<$.length;S+=2){let _=$[S].toLowerCase(),k=$[S+1];x[_]=_ in x?`${x[_]}, ${k}`:k}let A=f.statusCode??0,g=f.statusMessage??"";if(f.on("error",w),f.on("aborted",()=>w(Object.assign(new Error("aborted"),{code:"ECONNRESET"}))),d&&A>=200&&A<300){let S=Ae(d);try{Se(Ce(S),{recursive:!0})}catch(_){w(_);return}_e(f,xe(d)).then(()=>{E||(E=!0,T(new M(A,g,x,Buffer.alloc(0),t,d)))},_=>w(_));return}let l=[];f.on("data",S=>l.push(S)),f.on("end",()=>{E||(E=!0,T(new M(A,g,x,Buffer.concat(l),t)))})}),c&&c.length?R.end(Buffer.from(c.buffer,c.byteOffset,c.byteLength)):R.end()})}close(){for(let e of this.agents.values())e.destroy();this.agents.clear()}},Je;function Xe(){return Je??=new W}function le(r,e=Date.now()){if(!r)return null;let t=r.trim();if(/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i.test(t))return Math.max(0,Number(t));if(!/[A-Za-z]{3}/.test(t))return null;let n=Date.parse(/GMT|UTC|[+-]\d{4}$/.test(t)?t:t+" GMT");return Number.isNaN(n)?null:Math.max(0,(n-e)/1e3)}function Ve(r,e){return $e.has(e)?e===429||B.has(r.toUpperCase()):!1}function de(r,e=30){return Math.random()*Math.min(e,2**r)}var Ke=new Set(["authorization","proxy-authorization","cookie","set-cookie"]);function Ze(r){let e={};for(let[t,n]of Object.entries(r))e[t]=Ke.has(t.toLowerCase())?"<redacted>":n;return e}var Y=class extends O{constructor(e="dry run"){super(e,{exitCode:0})}},fe=class{defaultHeaders(){return{Accept:"application/json"}}requestId(e){return null}error(e){return Qe(this.name,e,null,null)}authTrap(e){return null}};function Qe(r,e,t,n,s=null,i=null){let o=e.status,a=n||`HTTP ${o} ${e.reason}`.trim();o===403&&i===null&&(i="signed in, but this account lacks permission for the request");let c={service:r,status:o};switch(t&&(c.code=t),s&&(c.requestId=s),i!==null&&(c.hint=i),o){case 401:return new L(a,c);case 403:return new Q(a,c);case 404:return new X(a,c);case 409:case 412:return new K(a,c);case 429:return new V(a,c);default:return new O(a,c)}}var et=["login.microsoftonline.com","login.windows.net","login.live.com"],tt="run: ppdo-cli auth login <identity>";function rt(r){return{header:async e=>"Bearer "+await r(e)}}var q=r=>new Promise(e=>setTimeout(e,Math.max(0,r*1e3))),b=()=>performance.now()/1e3,nt=":/?#[]@!$&'()*+,;=%~",he=class{service;rt;authorizer;http;target=null;identity=null;cached=null;notBefore=0;inLookups=!1;also=[];constructor(e,t,n,s=Xe()){this.service=e,this.rt=t,this.authorizer=n===null?null:typeof n=="function"?rt(n):n,this.http=s}async lookups(e,t=[]){this.inLookups=!0,this.also=t.map(n=>n.toLowerCase());try{return await e()}finally{this.inLookups=!1,this.also=[]}}async request(e,t,n={}){e=e.toUpperCase();let s=se(this.service.url(t,n.params??null),nt);if(!this.service.allowed(s)){let a="";try{a=new URL(s).hostname}catch{a=P(s).netloc}throw new Z(`refusing to send a ${this.service.name} token to ${a||"None"}`,{hint:"absolute URLs must belong to the environment's own host or organization",service:this.service.name})}let i={...this.service.defaultHeaders(),...n.headers??{}},o=n.body??null;return o!==null&&!Object.keys(i).some(a=>a.toLowerCase()==="content-type")&&(i["Content-Type"]="application/json"),this.rt.dryRun&&!(this.inLookups&&this.isRead(e,s))&&await this.dryRun(e,s,i,o),this.send(e,s,i,o,n.saveTo??null,n.check??!0)}async*paginate(e,t){let n=0,s=await this.request("GET",e,{params:t.params??null,headers:t.headers??null}),i=t.limit??null;for(;;){for(let a of t.items(s))if(yield a,n++,i!==null&&n>=i)return;let o=t.nextLink(s);if(!o)return;s=await this.request("GET",o,{headers:t.headers??null})}}isRead(e,t){if(e==="GET"||e==="HEAD")return!0;if(e!=="POST")return!1;let n=P(t).path.replace(/\/+$/,""),s=n.slice(n.lastIndexOf("/")+1).toLowerCase();return this.also.includes(s)||ne(this.service.name,t)}async dryRun(e,t,n,s){let i=null;if(s!==null){let o=Buffer.from(s).toString("utf8");try{i=JSON.parse(o)}catch{i=o}}throw await this.rt.emit({dry_run:!0,method:e,url:t,headers:Ze(n),body:i}),new Y("dry run")}async authHeader(e=!1){return this.authorizer===null?"":((e||this.cached===null||this.cached.service!==this.service)&&(this.cached={service:this.service,header:await this.authorizer.header(e,this.service)}),this.cached.header)}async send(e,t,n,s,i,o){let a=this.service.name,c=this.authorizer?.hint??tt,y=b()+(this.rt.timeout||Ne),p=!1,d=0,T=0,m=t,h=!0,u;for(;;){d++;let E=this.notBefore-b();E>0&&(this.rt.log(`throttle: waiting ${E.toFixed(1)}s (Retry-After from an earlier response)`),await q(E));let v={...n};h&&this.authorizer!==null&&(v.Authorization=await this.authHeader(),Object.assign(v,this.authorizer.extraHeaders?.()??{}));let R=b();this.rt.log(`-> ${e} ${m}`);let w=pe(m);try{u=await this.http.request(e,m,v,s,{timeout:Math.min(120,Math.max(5,y-b())),saveTo:i})}catch(g){let l=g;if(l instanceof O)throw l;if(l instanceof N||l.code==="ETIMEDOUT"){if(B.has(e)&&d<I&&b()<y){this.rt.log(` timeout (${l.message}); retrying`);continue}throw new O(`request timed out: ${e} ${m}`,{service:a})}if(me(l))throw new O(`TLS error talking to ${w}: ${l.message}`,{service:a,hint:Pe()});if(typeof l.code!="string")throw g;let S=l.code==="ENOTFOUND"||l.code==="EAI_AGAIN"||l.code==="EAI_FAIL";if((l.code==="ECONNREFUSED"||B.has(e))&&!S&&d<I&&b()<y){let k=de(d);this.rt.log(` connection error (${l.message}); retrying in ${k.toFixed(1)}s`),await q(k);continue}throw new O(`cannot reach ${w}: ${l.message}`,{service:a,hint:"check the network, proxy (HTTPS_PROXY) and the URL"})}let f=(b()-R)*1e3,x=this.service.requestId(u);this.rt.log(`<- ${u.status} ${u.reason} (${f.toFixed(0)} ms)`+(x?` request-id=${x}`:""));let $=le(u.header("retry-after"));$&&u.status<400&&(this.notBefore=b()+Math.min($,oe));let A=this.service.authTrap(u);if(A)throw new L(A,{service:a,status:u.status,hint:c});if(u.status===401&&h&&this.authorizer!==null){let g=u.header("www-authenticate")??"";if(g.includes("insufficient_claims")||g.includes("claims="))throw new L("the service requires a fresh sign-in (claims challenge)",{service:a,status:401,hint:c});if(!p){p=!0,this.rt.log(" 401: refreshing the token once"),await this.authHeader(!0);continue}if(this.authorizer.hint)throw new L(`${a} rejected the credential (401)`,{service:a,status:401,hint:c})}if(u.status>=300&&u.status<400&&u.status!==304){let g=u.header("location");if(!g)break;try{g=new URL(g,m).toString()}catch{break}let l=pe(g);if(et.includes(l)||g.includes("_signin"))throw new L("the service redirected to a sign-in page (token rejected)",{service:a,status:u.status,hint:c});if(T++,T>5||e!=="GET"&&e!=="HEAD")break;m=g,h=!1,this.rt.log(` redirect to ${l} (without Authorization)`);continue}if(Ve(e,u.status)&&d<I){let g=le(u.header("retry-after")),l=g!==null?Math.min(g,oe):u.status===429?Le:de(d);if(b()+l<y){this.rt.log(` ${u.status}: retrying in ${l.toFixed(1)}s (attempt ${d}/${I})`),await q(l);continue}}break}if(o&&u.status>=400)throw this.service.error(u);return u}};function pe(r){try{return new URL(r).hostname}catch{return""}}export{Xe as a,fe as b,Qe as c,he as d};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{_ as M,a as p,ba as k,c as h,i as y,m as b,o as v}from"./chunk-I7MHI5CU.js";import{existsSync as C,mkdirSync as x,writeFileSync as I}from"node:fs";import{join as m}from"node:path";var T="# yaml-language-server: $schema=https://raw.githubusercontent.com/PPDOStudio/ppdo-cli-release/main/schema/reference-data.schema.json";function S(n,r){let a=t=>t.kind!=="other"&&t.kind!=="guid"&&t.attributeType!=="PartyList"&&!t.attributeOf&&(t.kind==="file"||t.kind==="image"||t.validForCreate||t.validForUpdate),i=[],s=t=>{!r.includes(t)&&!i.includes(t)&&i.push(t)};n.primaryName&&s(n.primaryName);let l=[...n.columns.values()].filter(t=>t.custom&&a(t)).map(t=>t.name).sort();for(let t of l)s(t);return[...n.columns.values()].some(t=>t.attributeType==="Money")&&n.columns.has("transactioncurrencyid")&&s("transactioncurrencyid"),n.columns.has("statecode")&&s("statecode"),n.columns.has("statuscode")&&s("statuscode"),i}function A(n,r,a){let i=[["version",new y("1")],["table",n.table]];return r&&i.push(["match",r]),i.push(["columns",a]),T+`
3
+ `+v(new b(i))}async function j(n,r,a){let i=a.filter(e=>!k.test(e));if(i.length)throw p("usage",`--table: '${i[0]}' is not a logical name`);let s=m(r,"schema"),l={folder:r,added:[],existing:[],lookups:[]},t=[];for(let e of[...new Set(a)]){if(C(m(s,`${e}.yaml`))){l.existing.push(e);continue}let o=await M(n,e,null);if(!o)throw h("not_found",`the environment has no table '${e}'`);t.push(o)}let w=e=>C(m(s,`${e}.yaml`))||t.some(o=>o.table===e);x(s,{recursive:!0});for(let e of t){let o=e.keys.length?e.keys[0].filter(u=>e.columns.has(u)&&u!==e.primaryId):[],c=[...o,...S(e,[e.primaryId,...o])],f=`schema/${e.table}.yaml`;I(m(r,f),A(e,null,c),"utf8"),l.added.push({table:e.table,file:f,match:[e.primaryId],columns:c.length});for(let u of c){let d=e.columns.get(u);if(d.kind==="lookup")for(let g of d.targets)w(g)||l.lookups.push({table:e.table,column:u,target:g,note:"not in the schema: the data file has the GUID of the target; if the GUID is different in a target environment, give it in an overlay"})}}return l}export{T as a,S as b,A as c,j as d};