@ppdostudio/ppdo-cli 1.0.0-beta.0 → 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 (172) hide show
  1. package/CHANGELOG.md +96 -54
  2. package/LICENSE +114 -114
  3. package/README.md +381 -331
  4. package/THIRD-PARTY-NOTICES +1 -0
  5. package/dist/bin.js +2 -2
  6. package/dist/chunks/{ado-NLCWVIVQ.js → ado-OTSVKTOE.js} +6 -6
  7. package/dist/chunks/{api-YKKPVMTX.js → api-IRGGH5DJ.js} +1 -1
  8. package/dist/chunks/{api-T5SWGOFX.js → api-TZJXGWWQ.js} +1 -1
  9. package/dist/chunks/auth-7CDWOYJE.js +6 -0
  10. package/dist/chunks/azCli-UEDQHRLP.js +2 -0
  11. package/dist/chunks/batch-LKWCBKAB.js +2 -0
  12. package/dist/chunks/{build-XDCWMEEL.js → build-PBPXO3GJ.js} +3 -3
  13. package/dist/chunks/bulk-NY5XX752.js +2 -0
  14. package/dist/chunks/chunk-2IUXH534.js +2 -0
  15. package/dist/chunks/chunk-3L7657R3.js +5 -0
  16. package/dist/chunks/{chunk-5KZDCOFA.js → chunk-46KBBWEH.js} +1 -1
  17. package/dist/chunks/chunk-6NBCHK6X.js +2 -0
  18. package/dist/chunks/chunk-6VLFO5FJ.js +7 -0
  19. package/dist/chunks/chunk-B3TJ3RJN.js +2 -0
  20. package/dist/chunks/chunk-BG2OIOSN.js +2 -0
  21. package/dist/chunks/chunk-BWOEIEFY.js +6 -0
  22. package/dist/chunks/chunk-ELSYHAYC.js +2 -0
  23. package/dist/chunks/chunk-FOEBNCSD.js +3 -0
  24. package/dist/chunks/{chunk-XL7E7LX5.js → chunk-GLU4X7PT.js} +2 -2
  25. package/dist/chunks/chunk-GQLXEQVQ.js +4 -0
  26. package/dist/chunks/chunk-GY6BUIDP.js +2 -0
  27. package/dist/chunks/chunk-H4OY4EFC.js +3 -0
  28. package/dist/chunks/chunk-HJQJ77F2.js +3 -0
  29. package/dist/chunks/chunk-I7MHI5CU.js +151 -0
  30. package/dist/chunks/chunk-ITP35SAY.js +2 -0
  31. package/dist/chunks/{chunk-J777TCSE.js → chunk-J67P6QFC.js} +2 -2
  32. package/dist/chunks/{chunk-NNHEYYF5.js → chunk-KBZI5UDL.js} +1 -1
  33. package/dist/chunks/chunk-LB7WNZVK.js +5 -0
  34. package/dist/chunks/chunk-MBNUMAAZ.js +2 -0
  35. package/dist/chunks/chunk-MNGA7IHQ.js +4 -0
  36. package/dist/chunks/chunk-P4IFCLVF.js +2 -0
  37. package/dist/chunks/chunk-Q2RD4TRK.js +2 -0
  38. package/dist/chunks/chunk-S6NK6GX2.js +5 -0
  39. package/dist/chunks/chunk-SWXCK5C2.js +2 -0
  40. package/dist/chunks/chunk-T4IH34D7.js +2 -0
  41. package/dist/chunks/{chunk-HLE2WURE.js → chunk-TADCW6ZI.js} +1 -1
  42. package/dist/chunks/{chunk-UYDBLVAM.js → chunk-TCLZ4XM6.js} +1 -1
  43. package/dist/chunks/chunk-VC7ADQ6E.js +2 -0
  44. package/dist/chunks/{chunk-GT52BRS2.js → chunk-XUHLW6B2.js} +18 -18
  45. package/dist/chunks/{commands-GHYN6GZT.js → commands-EOUU353W.js} +1 -1
  46. package/dist/chunks/component-JCIJQELN.js +2 -0
  47. package/dist/chunks/config-WV3NZGTI.js +2 -0
  48. package/dist/chunks/connection-L6CUFUPJ.js +2 -0
  49. package/dist/chunks/connref-IT6K56UT.js +2 -0
  50. package/dist/chunks/convert-ILMJ2HHN.js +5 -0
  51. package/dist/chunks/customizations-AX7ZSXCK.js +2 -0
  52. package/dist/chunks/data-UWOV3LBO.js +5 -0
  53. package/dist/chunks/dependency-V4ZJIWQL.js +3 -0
  54. package/dist/chunks/{discovery-XXVLVHD6.js → discovery-PSGWFMJH.js} +1 -1
  55. package/dist/chunks/{dv-3OESFBNW.js → dv-SD5LTNZJ.js} +109 -48
  56. package/dist/chunks/{env-MZPI3UA2.js → env-6RZCHQUC.js} +2 -2
  57. package/dist/chunks/environment-IBLJHUAL.js +2 -0
  58. package/dist/chunks/{environments-WMBLSAQF.js → environments-3P2I4QUC.js} +1 -1
  59. package/dist/chunks/envvar-KJ2TUZGJ.js +2 -0
  60. package/dist/chunks/fanout-2WQYFUWL.js +2 -0
  61. package/dist/chunks/{fetchxml-ONTNTA6Z.js → fetchxml-M6EOF7N6.js} +1 -1
  62. package/dist/chunks/functions-NILMLS4R.js +2 -0
  63. package/dist/chunks/{graph-JI23YQB5.js → graph-NO2OT2TL.js} +1 -1
  64. package/dist/chunks/{group-DKEPSVRV.js → group-ISSJ4H2A.js} +2 -2
  65. package/dist/chunks/history-JPMLQDJI.js +2 -0
  66. package/dist/chunks/identity-SBQNHSBF.js +2 -0
  67. package/dist/chunks/init-X2VEK4T2.js +2 -0
  68. package/dist/chunks/jobs-XC7EYPBP.js +2 -0
  69. package/dist/chunks/lifecycle-2F7MF6EP.js +2 -0
  70. package/dist/chunks/{main-ZVIKC3VA.js → main-J3O5YMIY.js} +2 -2
  71. package/dist/chunks/metadata-NZFQIAAG.js +2 -0
  72. package/dist/chunks/metadataCreate-XSHK32TR.js +2 -0
  73. package/dist/chunks/msalUser-KC75VDVV.js +2 -0
  74. package/dist/chunks/names-N5JRXO33.js +2 -0
  75. package/dist/chunks/{pack-2UDE25IY.js → pack-3OYGV36R.js} +1 -1
  76. package/dist/chunks/pat-PCMOZYM5.js +2 -0
  77. package/dist/chunks/{pipelines-O3OYNCHT.js → pipelines-OCHSIQ2E.js} +1 -1
  78. package/dist/chunks/pluginRegister-LEVZNDZN.js +4 -0
  79. package/dist/chunks/{plugins-EUDJ7QIS.js → plugins-TEME2R77.js} +1 -1
  80. package/dist/chunks/{policies-KVPQVUHS.js → policies-EWCANNBE.js} +1 -1
  81. package/dist/chunks/{pools-7H2L4QJC.js → pools-54KMEL5D.js} +1 -1
  82. package/dist/chunks/process-KR7LIXZB.js +2 -0
  83. package/dist/chunks/{projects-BHG2B4IX.js → projects-LPVDFLPC.js} +1 -1
  84. package/dist/chunks/protect-X2J7LU7X.js +2 -0
  85. package/dist/chunks/provider-D7DMMAS6.js +2 -0
  86. package/dist/chunks/{prs-NOXIZ7AT.js → prs-C4EKGJWA.js} +1 -1
  87. package/dist/chunks/records-C4RLQXFK.js +2 -0
  88. package/dist/chunks/{run-BXFENCN6.js → run-27MYTWHY.js} +1 -1
  89. package/dist/chunks/run-46PEJS3S.js +2 -0
  90. package/dist/chunks/run-7L6W2YWJ.js +3 -0
  91. package/dist/chunks/run-CD3ZOB5V.js +4 -0
  92. package/dist/chunks/run-EUNN6OZO.js +2 -0
  93. package/dist/chunks/{run-JYU5BTWN.js → run-JDNEQMJC.js} +1 -1
  94. package/dist/chunks/{run-MGLIIM7Z.js → run-T3IIJ7SK.js} +1 -1
  95. package/dist/chunks/run-ZHIDOKQH.js +2 -0
  96. package/dist/chunks/{runtime-VOF7XYXW.js → runtime-FJJPTBEE.js} +1 -1
  97. package/dist/chunks/security-SBIAK6QD.js +2 -0
  98. package/dist/chunks/{service-V2TQEEID.js → service-4N3YP4Z7.js} +1 -1
  99. package/dist/chunks/{service-4PIAYFYF.js → service-HASXLUGE.js} +1 -1
  100. package/dist/chunks/services-C6G4XRXR.js +2 -0
  101. package/dist/chunks/{skills-GD6Z6P3R.js → skills-FW4F3EIW.js} +1 -1
  102. package/dist/chunks/solution-CNBNIS7Z.js +2 -0
  103. package/dist/chunks/solutionExport-Y524HMGN.js +2 -0
  104. package/dist/chunks/{solutionfiles-P223QW2J.js → solutionfiles-2TP3Y2RW.js} +1 -1
  105. package/dist/chunks/spn-YSYMDTOI.js +2 -0
  106. package/dist/chunks/tokenCache-TQFT6LAD.js +2 -0
  107. package/dist/chunks/{unpack-XZLTBUGC.js → unpack-HUH7OJMP.js} +1 -1
  108. package/dist/chunks/{users-KFAPPGF4.js → users-Q7BJKBPP.js} +1 -1
  109. package/dist/chunks/{vargroups-33EZAHGZ.js → vargroups-GNZBODVJ.js} +1 -1
  110. package/dist/chunks/{whoami-ULK5UMZV.js → whoami-6G6UFTNS.js} +1 -1
  111. package/dist/chunks/{workitems-YGES6KKN.js → workitems-2IOGD3EL.js} +1 -1
  112. package/package.json +61 -57
  113. package/schema/ppdo-cli.schema.json +16 -4
  114. package/schema/reference-data.schema.json +192 -0
  115. package/skills/ppdo-cli/SKILL.md +2 -1
  116. package/skills/ppdo-cli-data/SKILL.md +669 -0
  117. package/skills/ppdo-cli-dataverse/SKILL.md +6 -0
  118. package/skills/ppdo-cli-plugins/PluginRegistration.cs +229 -0
  119. package/skills/ppdo-cli-plugins/SKILL.md +95 -0
  120. package/skills/ppdo-cli-plugins/reference.md +72 -0
  121. package/dist/chunks/auth-IP7AOWSF.js +0 -6
  122. package/dist/chunks/azCli-T67ZMIC3.js +0 -2
  123. package/dist/chunks/batch-GCXLGQET.js +0 -4
  124. package/dist/chunks/bulk-5QO343HO.js +0 -2
  125. package/dist/chunks/chunk-3C3GSN3J.js +0 -2
  126. package/dist/chunks/chunk-4S5ETLH4.js +0 -2
  127. package/dist/chunks/chunk-5SBBTR3Y.js +0 -2
  128. package/dist/chunks/chunk-5UOZCXQF.js +0 -5
  129. package/dist/chunks/chunk-BWZ6HZXM.js +0 -2
  130. package/dist/chunks/chunk-JGLUQBCK.js +0 -2
  131. package/dist/chunks/chunk-MME53RWW.js +0 -4
  132. package/dist/chunks/chunk-OP6EXLWQ.js +0 -5
  133. package/dist/chunks/chunk-PDFXH652.js +0 -2
  134. package/dist/chunks/chunk-QE4DELWW.js +0 -2
  135. package/dist/chunks/chunk-RHQP7X6H.js +0 -3
  136. package/dist/chunks/chunk-UKKSN4F7.js +0 -3
  137. package/dist/chunks/chunk-UWFDJKOJ.js +0 -2
  138. package/dist/chunks/chunk-WXCLWAE2.js +0 -2
  139. package/dist/chunks/chunk-X7VWUI6N.js +0 -2
  140. package/dist/chunks/component-PAASRIK6.js +0 -2
  141. package/dist/chunks/config-JN3I5EII.js +0 -2
  142. package/dist/chunks/connection-IWFELK5W.js +0 -2
  143. package/dist/chunks/connref-ZDY7JYK5.js +0 -2
  144. package/dist/chunks/customizations-IE2KO275.js +0 -7
  145. package/dist/chunks/dependency-EFDSIKSN.js +0 -3
  146. package/dist/chunks/environment-NUQHU74A.js +0 -2
  147. package/dist/chunks/envvar-YN35IDWJ.js +0 -2
  148. package/dist/chunks/fanout-DUP5CD5X.js +0 -2
  149. package/dist/chunks/functions-K5TYRB2C.js +0 -2
  150. package/dist/chunks/history-SNSJRV6B.js +0 -2
  151. package/dist/chunks/identity-OW4WCDOA.js +0 -2
  152. package/dist/chunks/jobs-PXNJFWWF.js +0 -2
  153. package/dist/chunks/lifecycle-7RMWV26J.js +0 -2
  154. package/dist/chunks/metadata-74WGGOV5.js +0 -2
  155. package/dist/chunks/metadataCreate-W3NDI5FB.js +0 -2
  156. package/dist/chunks/msalUser-JRNX5HPO.js +0 -2
  157. package/dist/chunks/names-SFYZQY6Q.js +0 -2
  158. package/dist/chunks/process-G7LCTGKS.js +0 -2
  159. package/dist/chunks/protect-WZO3MAHF.js +0 -2
  160. package/dist/chunks/provider-VXRAQRN2.js +0 -2
  161. package/dist/chunks/records-TN7ZKUJ7.js +0 -2
  162. package/dist/chunks/run-F6H4QCWR.js +0 -2
  163. package/dist/chunks/run-HBQCSGYY.js +0 -3
  164. package/dist/chunks/run-MHM3GTGH.js +0 -2
  165. package/dist/chunks/run-SRQPP6N3.js +0 -3
  166. package/dist/chunks/run-ZNDSC7LR.js +0 -2
  167. package/dist/chunks/security-FLEAZ4EA.js +0 -2
  168. package/dist/chunks/services-B6V4VVX5.js +0 -2
  169. package/dist/chunks/solution-HF57MP27.js +0 -2
  170. package/dist/chunks/solutionExport-TLGHMUM5.js +0 -2
  171. package/dist/chunks/spn-AIUWML5R.js +0 -2
  172. package/dist/chunks/tokenCache-3LMJRUTI.js +0 -2
@@ -23,3 +23,4 @@ lodash.once 4.1.1 MIT https://github.com/lodash/lodash
23
23
  ms 2.1.3 MIT https://github.com/vercel/ms
24
24
  safe-buffer 5.2.1 MIT https://github.com/feross/safe-buffer
25
25
  semver 7.8.6 ISC https://github.com/npm/node-semver
26
+ yaml 2.9.1 ISC https://github.com/eemeli/yaml
package/dist/bin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
3
- import{a as t}from"./chunks/chunk-UYDBLVAM.js";import{a as e,k as s}from"./chunks/chunk-WXOTXJNG.js";import"./chunks/chunk-ZHHVG47C.js";import d from"node:module";d.enableCompileCache?.();async function a(){let o=process.argv.slice(2);if(o.length===1&&(o[0]==="--version"||o[0]==="-V")){process.stdout.write(`ppdo-cli ${t}
4
- `),process.exitCode=0;return}let{main:n}=await import("./chunks/main-ZVIKC3VA.js");process.once("SIGINT",()=>{process.stderr.write(`{"error":"interrupted"}
3
+ import{a as t}from"./chunks/chunk-TCLZ4XM6.js";import{a as e,k as s}from"./chunks/chunk-WXOTXJNG.js";import"./chunks/chunk-ZHHVG47C.js";import d from"node:module";d.enableCompileCache?.();async function a(){let o=process.argv.slice(2);if(o.length===1&&(o[0]==="--version"||o[0]==="-V")){process.stdout.write(`ppdo-cli ${t}
4
+ `),process.exitCode=0;return}let{main:n}=await import("./chunks/main-J3O5YMIY.js");process.once("SIGINT",()=>{process.stderr.write(`{"error":"interrupted"}
5
5
  `),process.exit(130)}),process.stdout.on("error",r=>{r.code==="EPIPE"&&process.exit(0),s(new e(`cannot write to stdout: ${r.message}`)),process.exit(1)}),process.exitCode=await n(o)}a();
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a as z}from"./chunk-MTF66YXU.js";import{d as P,e as r,i as d,j as l,k as j,l as S,n as U,o as m,q as E,r as o}from"./chunk-BALEFXOL.js";import{b as O}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";var N=100;function p(a){return a.addOption(new r("--limit <n>",`return at most n items (default ${N})`).argParser(d)).option("--all","no cap")}function T(a){let t=a;for(;t.parent;)t=t.parent;return t}function f(a,t,e=!1){return a.hook("preAction",(s,i)=>{let G=T(i).rawArgs??[],L=w=>G.findIndex(y=>y===w||y.startsWith(w+"=")),v=t.filter(w=>i.getOptionValueSource(E(w.replace(/^--/,"")))==="cli").sort((w,y)=>L(w)-L(y)),x=`run: ${[T(i).name(),...U(i)].join(" ")} --help`;if(v.length>1)throw new O(`argument ${v[1]}: not allowed with argument ${v[0]}`,{hint:x});if(e&&!v.length)throw new O(`one of the arguments ${t.join(" ")} is required`,{hint:x})}),a}var n=(a,t)=>async e=>t(await a())(e);var $=()=>import("./users-KFAPPGF4.js"),b=()=>import("./vargroups-33EZAHGZ.js"),k=()=>import("./environments-WMBLSAQF.js"),q=()=>import("./pools-7H2L4QJC.js");function A(a){o(m(a,"user","users and groups in the organization"),"get","R","a user by email, UPN or full display name",{description:`a user by email, UPN or full display name ('me' for the signed-in account)
2
+ import{d as P,e as r,i as d,j as l,k as j,l as S,n as U,o as m,q as E,r as o}from"./chunk-BALEFXOL.js";import{a as z}from"./chunk-MTF66YXU.js";import{b as O}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";var N=100;function p(a){return a.addOption(new r("--limit <n>",`return at most n items (default ${N})`).argParser(d)).option("--all","no cap")}function T(a){let t=a;for(;t.parent;)t=t.parent;return t}function f(a,t,e=!1){return a.hook("preAction",(s,i)=>{let G=T(i).rawArgs??[],L=w=>G.findIndex(y=>y===w||y.startsWith(w+"=")),v=t.filter(w=>i.getOptionValueSource(E(w.replace(/^--/,"")))==="cli").sort((w,y)=>L(w)-L(y)),x=`run: ${[T(i).name(),...U(i)].join(" ")} --help`;if(v.length>1)throw new O(`argument ${v[1]}: not allowed with argument ${v[0]}`,{hint:x});if(e&&!v.length)throw new O(`one of the arguments ${t.join(" ")} is required`,{hint:x})}),a}var n=(a,t)=>async e=>t(await a())(e);var $=()=>import("./users-Q7BJKBPP.js"),b=()=>import("./vargroups-GNZBODVJ.js"),k=()=>import("./environments-3P2I4QUC.js"),q=()=>import("./pools-54KMEL5D.js");function A(a){o(m(a,"user","users and groups in the organization"),"get","R","a user by email, UPN or full display name",{description:`a user by email, UPN or full display name ('me' for the signed-in account)
3
3
 
4
4
  Returns id, name, upn, mail, descriptor (the subject descriptor), active, kind (User or
5
5
  Group) and object_id (Entra). Matching is exact: part of a name finds nobody.`}).argument("<email|upn|name|me>").argKey("email|upn|name|me","who").handler(n($,i=>i.getUser));let t=m(a,"vargroup","variable groups (secret values are never shown)");p(o(t,"list","R","variable groups in the project").option("--name <pattern>","name filter; a trailing * is a wildcard")).handler(n(b,i=>i.list)),o(t,"get","R","one variable group").argument("<group>","variable group id or name").argKey("group","vargroup").handler(n(b,i=>i.getGroup)),o(t,"create","W","create a variable group",{description:`create a variable group
@@ -14,7 +14,7 @@ Without it, a run that deploys to the environment waits for someone to permit it
14
14
 
15
15
  From the pool's job requests: wait = queued until an agent was assigned; run = assigned
16
16
  until finished; peak = most jobs running at the same time. --top adds the pipelines that
17
- used the pool most.`}).argument("<pool>","pool id or name").option("--since <when>","30m, 12h, 7d, 2w or a date (default 7d)").addOption(new r("--limit <n>","job requests to read (default 5000)").argParser(d)).addOption(new r("--top <n>","busiest pipelines to show (default 5)").argParser(d)).handler(n(q,i=>i.usage))}var u=()=>import("./pipelines-O3OYNCHT.js"),Q=["succeeded","partiallySucceeded","failed","canceled"],Y="manual, individualCI, batchedCI, schedule, scheduleForced, pullRequest, resourceTrigger, buildCompletion, triggered, userCreated, validateShelveset, checkInShelveset";function C(a){let t=m(a,"pipeline","pipelines: list, inspect, run");p(o(t,"list","R","pipelines in the project").option("--folder <path>","only pipelines in this folder")).handler(n(u,s=>s.list)),o(t,"get","R","one pipeline").argument("<pipeline>","pipeline id, name or URL").handler(n(u,s=>s.getPipeline)),f(o(t,"run","W","queue a run",{description:`--param sets YAML parameters (templateParameters); --variable sets runtime variables.
17
+ used the pool most.`}).argument("<pool>","pool id or name").option("--since <when>","30m, 12h, 7d, 2w or a date (default 7d)").addOption(new r("--limit <n>","job requests to read (default 5000)").argParser(d)).addOption(new r("--top <n>","busiest pipelines to show (default 5)").argParser(d)).handler(n(q,i=>i.usage))}var u=()=>import("./pipelines-OCHSIQ2E.js"),Q=["succeeded","partiallySucceeded","failed","canceled"],Y="manual, individualCI, batchedCI, schedule, scheduleForced, pullRequest, resourceTrigger, buildCompletion, triggered, userCreated, validateShelveset, checkInShelveset";function C(a){let t=m(a,"pipeline","pipelines: list, inspect, run");p(o(t,"list","R","pipelines in the project").option("--folder <path>","only pipelines in this folder")).handler(n(u,s=>s.list)),o(t,"get","R","one pipeline").argument("<pipeline>","pipeline id, name or URL").handler(n(u,s=>s.getPipeline)),f(o(t,"run","W","queue a run",{description:`--param sets YAML parameters (templateParameters); --variable sets runtime variables.
18
18
  Example: ppdo-cli ado pipeline run deploy --branch main --param env=test --wait --logs-on-failure`}).argument("<pipeline>","pipeline id, name or URL").option("--branch <ref>","branch to run (default: the pipeline's default)").option("--param <k=v>","YAML parameter (repeatable)",l).option("--variable <k=v>","runtime variable (repeatable)",l).option("--wait","wait for the run; non-zero exit unless it succeeds").option("--logs-on-failure","with --wait: include failed steps' log tails").option("--skip-stage <stage>[,<stage>...]","stages not to run").option("--only-stage <stage>[,<stage>...]","run only these stages"),["--skip-stage","--only-stage"]).handler(n(u,s=>s.runPipeline)),o(t,"stages","R","the stages a run would have, from the expanded YAML",{description:`the stages a run would have, from the expanded YAML
19
19
 
20
20
  Uses a preview run (nothing is queued), so templates and parameters are applied.
@@ -24,7 +24,7 @@ Stage names are what --skip-stage, --only-stage and run retry --stage take.`}).a
24
24
  --tail is given) and prints the files instead of the logs.`}).argument("<run>","run id or its dev.azure.com URL").option("--failed-only").option("--step <name>","steps whose name contains this text").addOption(new r("--tail <n>","last n lines per step (default 100, or all with --save; 0 = all)").argParser(d)).option("--timestamps","keep each line's timestamp").option("--save <dir>","write one .log file per step to this folder").handler(n(u,s=>s.logs)),o(e,"retry","W","re-run failed or canceled stages of a finished run",{description:`re-run failed or canceled stages of a finished run
25
25
 
26
26
  Without --stage, every failed or canceled stage. Only the failed jobs in a stage run again
27
- unless --all-jobs.`}).argument("<run>","run id or its dev.azure.com URL").option("--stage <stage>[,<stage>...]","stage names or display names").option("--all-jobs","re-run every job in the stage, not only failed ones").option("--wait","wait for the run; non-zero exit unless it succeeds").option("--logs-on-failure","with --wait: include failed steps' log tails").handler(n(u,s=>s.retry)),o(e,"cancel","W","cancel a run").argument("<run>","run id or its dev.azure.com URL").handler(n(u,s=>s.cancel))}var g=()=>import("./projects-BHG2B4IX.js"),F=()=>import("./policies-KVPQVUHS.js"),R=`<ref> is a branch (default: the repo's default branch), a tag as refs/tags/<name>, or a full
27
+ unless --all-jobs.`}).argument("<run>","run id or its dev.azure.com URL").option("--stage <stage>[,<stage>...]","stage names or display names").option("--all-jobs","re-run every job in the stage, not only failed ones").option("--wait","wait for the run; non-zero exit unless it succeeds").option("--logs-on-failure","with --wait: include failed steps' log tails").handler(n(u,s=>s.retry)),o(e,"cancel","W","cancel a run").argument("<run>","run id or its dev.azure.com URL").handler(n(u,s=>s.cancel))}var g=()=>import("./projects-LPVDFLPC.js"),F=()=>import("./policies-EWCANNBE.js"),R=`<ref> is a branch (default: the repo's default branch), a tag as refs/tags/<name>, or a full
28
28
  40-character commit SHA. Paths start at the repo root, with or without a leading /.`;function M(a){p(o(m(a,"project","projects"),"list","R","projects in the organization")).handler(n(g,e=>e.projects));let t=m(a,"repo","Git repositories");p(o(t,"list","R","repositories in the project")).handler(n(g,e=>e.repos)),o(t,"get","R","one repository").argument("<name>","repository name or id").handler(n(g,e=>e.repo)),o(t,"file","R","a file's content at a branch, tag or commit",{description:`a file's content at a branch, tag or commit
29
29
 
30
30
  JSON output carries the content as text; -o table or tsv prints it raw. A binary file needs
@@ -53,7 +53,7 @@ and behind (commits <target> has that <base> doesn't, and the reverse) and merge
53
53
  Each has its id, type, required (blocking) or optional, enabled, branches (main, release/*,
54
54
  or (default branch)) or none for a push restriction on the whole repository, all_repos for
55
55
  a project-wide policy, and settings. --branch lists only the policies that apply to that
56
- branch, including project-wide ones.`}).argument("<repo>","repository name or id").option("--branch <branch>","only the policies that apply to this branch").handler(n(F,e=>e.repoPolicies))}var h=()=>import("./prs-NOXIZ7AT.js"),K=()=>import("./policies-KVPQVUHS.js"),J=["merge","squash","rebase","rebase-merge"],B=["active","pending","fixed","wont-fix","closed","by-design"];function W(a){return a.addOption(new r("--merge-strategy <strategy>","merge is a no-fast-forward merge").choices(J)).option("--delete-source-branch").option("--transition-work-items","move linked work items to their next state").option("--message <text|@file>","merge commit message").option("--conflict-authorship-commits","merge option: author conflict resolutions as their own commits").option("--no-renames","merge option: don't detect renames")}function H(a){let t=m(a,"pr","pull requests");p(o(t,"list","R","pull requests in the project (newest first)").option("--repo <name>").addOption(new r("--status <status>").choices(["active","completed","abandoned","all"]).default("active")).option("--creator <me|upn>").option("--reviewer <me|upn>").option("--source <branch>","only PRs from this branch").option("--target <branch>","only PRs into this branch")).handler(n(h,e=>e.list)),o(t,"get","R","pull request details, reviewers and status").argument("<pr>","PR id or its dev.azure.com URL").handler(n(h,e=>e.getOne)),o(t,"diff","R","changes in a pull request (unified diff, or --stat)").argument("<pr>","PR id or its dev.azure.com URL").option("--file <path>","only this file").option("--stat","list changed files only").addOption(new r("-U, --unified <n>","context lines (default 3)").argParser(d)).handler(n(h,e=>e.diff)),o(t,"checks","R","how each branch policy stands on a pull request",{description:`how each branch policy stands on a pull request
56
+ branch, including project-wide ones.`}).argument("<repo>","repository name or id").option("--branch <branch>","only the policies that apply to this branch").handler(n(F,e=>e.repoPolicies))}var h=()=>import("./prs-C4EKGJWA.js"),K=()=>import("./policies-EWCANNBE.js"),J=["merge","squash","rebase","rebase-merge"],B=["active","pending","fixed","wont-fix","closed","by-design"];function W(a){return a.addOption(new r("--merge-strategy <strategy>","merge is a no-fast-forward merge").choices(J)).option("--delete-source-branch").option("--transition-work-items","move linked work items to their next state").option("--message <text|@file>","merge commit message").option("--conflict-authorship-commits","merge option: author conflict resolutions as their own commits").option("--no-renames","merge option: don't detect renames")}function H(a){let t=m(a,"pr","pull requests");p(o(t,"list","R","pull requests in the project (newest first)").option("--repo <name>").addOption(new r("--status <status>").choices(["active","completed","abandoned","all"]).default("active")).option("--creator <me|upn>").option("--reviewer <me|upn>").option("--source <branch>","only PRs from this branch").option("--target <branch>","only PRs into this branch")).handler(n(h,e=>e.list)),o(t,"get","R","pull request details, reviewers and status").argument("<pr>","PR id or its dev.azure.com URL").handler(n(h,e=>e.getOne)),o(t,"diff","R","changes in a pull request (unified diff, or --stat)").argument("<pr>","PR id or its dev.azure.com URL").option("--file <path>","only this file").option("--stat","list changed files only").addOption(new r("-U, --unified <n>","context lines (default 3)").argParser(d)).handler(n(h,e=>e.diff)),o(t,"checks","R","how each branch policy stands on a pull request",{description:`how each branch policy stands on a pull request
57
57
 
58
58
  Each has its policy id (what pr auto-complete --ignore-policy takes for an optional one),
59
59
  type, required, status (approved, queued, running, rejected or broken) and blocks: true when
@@ -63,7 +63,7 @@ Options the PR already has are kept unless given. Policies must pass first; ther
63
63
  bypass. --ignore-policy names optional policies (configuration ids) not to wait for.`}).argument("<pr>","PR id or its dev.azure.com URL").option("--off","turn auto-complete off")).option("--ignore-policy <id>[,<id>...]","optional policy configuration ids not to wait for").handler(n(h,e=>e.autoComplete)),W(o(t,"complete","W","complete (merge) a pull request now",{description:`complete (merge) a pull request now
64
64
 
65
65
  Never bypasses branch policies: if a required policy isn't passing, it stops with exit 8.
66
- Options the PR already has are kept unless given.`}).argument("<pr>","PR id or its dev.azure.com URL")).handler(n(h,e=>e.complete))}var c=()=>import("./workitems-YGES6KKN.js"),_=a=>`${a}
66
+ Options the PR already has are kept unless given.`}).argument("<pr>","PR id or its dev.azure.com URL")).handler(n(h,e=>e.complete))}var c=()=>import("./workitems-2IOGD3EL.js"),_=a=>`${a}
67
67
 
68
68
  Long-text fields (Description, Repro Steps, Acceptance Criteria, History, custom
69
69
  HTML fields) are written as Markdown; --html writes HTML. A field takes the format
@@ -100,4 +100,4 @@ Examples:
100
100
  ppdo-cli ado api GET _apis/projects
101
101
  ppdo-cli ado api GET {project}/_apis/build/builds --param '$top=5'
102
102
  ppdo-cli ado api GET _apis/graph/users --host vssps
103
- ppdo-cli ado api POST {project}/_apis/wit/wiql --body @query.json`).addArgument(S(j)).argument("<path>").option("--body <@file|-|json>","request body: @file, - for stdin, or inline JSON").option("--header <k:v>","extra header (repeatable)",l).option("--param <k=v>","query parameter (repeatable)",l).option("--api-version <v>","default 7.1").addOption(new r("--host <host>","DevOps host (default: core = dev.azure.com)").choices(z).default("core")).option("--paginate","follow continuation tokens; items are the output").addOption(new r("--limit <n>","stop after n items (with --paginate)").argParser(d)).option("--save <file>","write the response body to a file").handler(async e=>(await import("./api-T5SWGOFX.js")).api(e)),M(t),C(t),H(t),D(t),A(t)}export{Se as register};
103
+ ppdo-cli ado api POST {project}/_apis/wit/wiql --body @query.json`).addArgument(S(j)).argument("<path>").option("--body <@file|-|json>","request body: @file, - for stdin, or inline JSON").option("--header <k:v>","extra header (repeatable)",l).option("--param <k=v>","query parameter (repeatable)",l).option("--api-version <v>","default 7.1").addOption(new r("--host <host>","DevOps host (default: core = dev.azure.com)").choices(z).default("core")).option("--paginate","follow continuation tokens; items are the output").addOption(new r("--limit <n>","stop after n items (with --paginate)").argParser(d)).option("--save <file>","write the response body to a file").handler(async e=>(await import("./api-TZJXGWWQ.js")).api(e)),M(t),C(t),H(t),D(t),A(t)}export{Se as register};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a,b,c,d,e}from"./chunk-J777TCSE.js";import"./chunk-UCTMKA2J.js";import"./chunk-BALEFXOL.js";import"./chunk-5SBBTR3Y.js";import"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";export{e as api,c as checkJsonBody,d as emitResponse,b as forbiddenHeaders,a as headerDict};
2
+ import{a,b,c,d,e}from"./chunk-J67P6QFC.js";import"./chunk-UCTMKA2J.js";import"./chunk-BALEFXOL.js";import"./chunk-2IUXH534.js";import"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";export{e as api,c as checkJsonBody,d as emitResponse,b as forbiddenHeaders,a as headerDict};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a as V,b as j,c as P,d as R}from"./chunk-J777TCSE.js";import"./chunk-UCTMKA2J.js";import{w,y as h}from"./chunk-BALEFXOL.js";import{b as k}from"./chunk-5SBBTR3Y.js";import{e as g}from"./chunk-S4KF5Z3S.js";import{a as y,b as v}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";function x(n){return/_apis\/wit\/workitems\/(\$|%24)?[^/?]+\/?(\?|$)/i.test(n)}async function C(n,e,o){let{DevOps:r}=await import("./service-V2TQEEID.js"),s=await n.client("devops"),c=s.target.env;return s.service=new r({org:c.org,project:c.project},e,o),s}async function I(n){let e=n.args,o=String(e.method),r=String(e.path),s=typeof e.apiVersion=="string"&&e.apiVersion?e.apiVersion:null,c=typeof e.limit=="number"?e.limit:null,a=V(e.header);j(a);let m=h(typeof e.body=="string"?e.body:null);m!==null&&!Object.keys(a).some(t=>t.toLowerCase()==="content-type")&&(P(m,a),(o==="POST"||o==="PATCH")&&x(r)&&(a["Content-Type"]="application/json-patch+json"));let d=await C(n,typeof e.host=="string"?e.host:"core",s);k(n,d,o,r,m);let u=w(e.param,"--param");if(e.paginate&&o!=="GET")throw new v("--paginate only applies to GET");let f=await import("./service-V2TQEEID.js"),l=async()=>{if(e.paginate){let i=d.paginate(r,{params:u,headers:a,limit:c,nextLink:f.nextUrl,items:f.items});return{kind:"stream",first:await i.next(),stream:i}}let t=typeof e.save=="string"?e.save:null;return{kind:"resp",resp:await d.request(o,r,{params:u,headers:a,body:m,saveTo:t})}},p;try{p=await l()}catch(t){if(!(t instanceof y)||t.code!=="VssInvalidPreviewVersionException"||s)throw t;let i=d.service;i.apiVersion=i.apiVersion+"-preview",g(`note: this endpoint needs a preview api-version; retried with ${i.apiVersion}`),p=await l()}if(p.kind==="stream"){let{first:t,stream:i}=p;async function*b(){t.done||(yield t.value),yield*i}await n.emitStream(b());return}await R(n,p.resp,!1)}export{I as api,x as isWorkItemPath};
2
+ import{a as V,b as j,c as P,d as R}from"./chunk-J67P6QFC.js";import"./chunk-UCTMKA2J.js";import{w,y as h}from"./chunk-BALEFXOL.js";import{b as k}from"./chunk-2IUXH534.js";import{e as g}from"./chunk-S4KF5Z3S.js";import{a as y,b as v}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";function x(n){return/_apis\/wit\/workitems\/(\$|%24)?[^/?]+\/?(\?|$)/i.test(n)}async function C(n,e,o){let{DevOps:r}=await import("./service-4N3YP4Z7.js"),s=await n.client("devops"),c=s.target.env;return s.service=new r({org:c.org,project:c.project},e,o),s}async function I(n){let e=n.args,o=String(e.method),r=String(e.path),s=typeof e.apiVersion=="string"&&e.apiVersion?e.apiVersion:null,c=typeof e.limit=="number"?e.limit:null,a=V(e.header);j(a);let m=h(typeof e.body=="string"?e.body:null);m!==null&&!Object.keys(a).some(t=>t.toLowerCase()==="content-type")&&(P(m,a),(o==="POST"||o==="PATCH")&&x(r)&&(a["Content-Type"]="application/json-patch+json"));let d=await C(n,typeof e.host=="string"?e.host:"core",s);k(n,d,o,r,m);let u=w(e.param,"--param");if(e.paginate&&o!=="GET")throw new v("--paginate only applies to GET");let f=await import("./service-4N3YP4Z7.js"),l=async()=>{if(e.paginate){let i=d.paginate(r,{params:u,headers:a,limit:c,nextLink:f.nextUrl,items:f.items});return{kind:"stream",first:await i.next(),stream:i}}let t=typeof e.save=="string"?e.save:null;return{kind:"resp",resp:await d.request(o,r,{params:u,headers:a,body:m,saveTo:t})}},p;try{p=await l()}catch(t){if(!(t instanceof y)||t.code!=="VssInvalidPreviewVersionException"||s)throw t;let i=d.service;i.apiVersion=i.apiVersion+"-preview",g(`note: this endpoint needs a preview api-version; retried with ${i.apiVersion}`),p=await l()}if(p.kind==="stream"){let{first:t,stream:i}=p;async function*b(){t.done||(yield t.value),yield*i}await n.emitStream(b());return}await R(n,p.resp,!1)}export{I as api,x as isWorkItemPath};
@@ -0,0 +1,6 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{e as o,o as a,r as t}from"./chunk-BALEFXOL.js";import"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";var s=["dv","dataverse","ado","devops"];function p(d){let n=a(d,"auth","sign in, sign out, tokens"),i=()=>import("./run-7L6W2YWJ.js");t(n,"login","L","interactive sign-in for an identity",{description:`ppdo-cli auth login <identity> sign in one identity
3
+ ppdo-cli auth login --service ado sign in the identity the default DevOps environment uses
4
+ ppdo-cli auth login --env <name> sign in the identity that environment's group uses
5
+ ppdo-cli auth login sign in every identity the default environments need that
6
+ has no valid session`}).argument("[identity]").argKey("identity","name").addOption(new o("--service <service>").choices(s)).option("--device-code","use the device code flow this time").option("--expires <date>","pat only: the PAT's expiry date (YYYY-MM-DD), to be warned before it ends").handler(async e=>(await i()).login(e)),t(n,"logout","L","delete an identity's token caches").argument("[identity]").argKey("identity","name").option("--all","every identity").handler(async e=>(await i()).logout(e)),t(n,"status","L","sign-in state and cached tokens per identity").argument("[identity]").argKey("identity","name").handler(async e=>(await i()).status(e)),t(n,"token","L","print an access token for scripts (curl, PowerShell)").addOption(new o("--service <service>").choices(s)).option("--scope <scope>","any other resource scope, e.g. https://graph.microsoft.com/.default").option("--show","print even when stdout is a terminal").handler(async e=>(await i()).token(e))}export{p as register};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as g}from"./chunk-B3TJ3RJN.js";import"./chunk-XUHLW6B2.js";import{a as d}from"./chunk-P4IFCLVF.js";import"./chunk-3L7657R3.js";import{b as l}from"./chunk-MBNUMAAZ.js";import"./chunk-LB7WNZVK.js";import"./chunk-GY6BUIDP.js";import"./chunk-J4R6QXW7.js";import"./chunk-2IUXH534.js";import"./chunk-TCLZ4XM6.js";import"./chunk-H4OY4EFC.js";import"./chunk-TQLZ3TRU.js";import"./chunk-S4KF5Z3S.js";import{b as m,c as p}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";import{execFile as x}from"node:child_process";import{statSync as h}from"node:fs";import{delimiter as E,extname as b,join as y}from"node:path";var v=12e4;function A(t){let n=d();return t.configDir&&(n.AZURE_CONFIG_DIR=g(t.configDir)),n}function w(t){return`run: ${t.configDir?`AZURE_CONFIG_DIR=${t.configDir} `:""}az login --tenant ${t.tenant}`}function I(t){let n=process.platform==="win32"?(process.env.PATHEXT||".COM;.EXE;.BAT;.CMD").split(";").filter(o=>o):[""];for(let o of(process.env.PATH||"").split(E))if(o)for(let i of b(t)?[""]:n){let e=y(o,t+i);try{if(h(e).isFile())return e}catch{}}return null}function _(t,n,o){let i=t,e=n,s=!1;if(process.platform==="win32"&&/\.(cmd|bat)$/i.test(t)){for(let r of[t,...n])if(/["%\r\n]/.test(r))throw new m(`cannot pass '${r}' to az safely`);i=process.env.ComSpec||"cmd.exe",e=["/d","/s","/c",`"${[t,...n].map(r=>`"${r}"`).join(" ")}"`],s=!0}return new Promise(r=>{x(i,e,{env:o,timeout:v,windowsHide:!0,windowsVerbatimArguments:s,maxBuffer:16<<20},(c,a,u)=>{let f=c;r({code:f?typeof f.code=="number"?f.code:1:0,stdout:String(a),stderr:String(u),timedOut:!!f?.killed})})})}async function D(t,n){let o=I("az");if(!o)throw new m("method 'az_cli' needs the Azure CLI on PATH",{hint:"install it, or use --method browser"});let i=["account","get-access-token","--scope",n,"--output","json"];t.tenant&&i.push("--tenant",t.tenant);let e=await _(o,i,A(t));if(e.timedOut)throw new p("az account get-access-token timed out",{hint:w(t)});if(e.code!==0){let a=e.stderr.split(/\r?\n/).map(u=>u.trim()).find(u=>u)??"az failed";throw new p(`az could not get a token for identity '${t.name}': ${a}`,{hint:w(t)})}let s=JSON.parse(e.stdout),r=s.accessToken,c=s.expires_on;if(c==null){let a=l(r)?.exp;c=typeof a=="number"?a:Date.now()/1e3+300}return[r,Number(c),s.tenant??null]}export{v as AZ_TIMEOUT_MS,D as acquire,w as loginHint,I as which};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a,b,c,d,e,f}from"./chunk-MNGA7IHQ.js";import"./chunk-KBZI5UDL.js";import"./chunk-GY6BUIDP.js";import"./chunk-J4R6QXW7.js";import"./chunk-2IUXH534.js";import"./chunk-TCLZ4XM6.js";import"./chunk-H4OY4EFC.js";import"./chunk-TQLZ3TRU.js";import"./chunk-S4KF5Z3S.js";import"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";export{b as RawJson,a as WRITE_METHODS,d as build,f as distribute,c as noResponse,e as parse};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{a as y,b as S,d as X,e as F}from"./chunk-JEAIFLEN.js";import{a as L}from"./chunk-JAGU2NM5.js";import{Y as m,ca as b}from"./chunk-TZSB4PR7.js";import{b as k,g as v}from"./chunk-ZNJ4DRCA.js";import{e as A,o as O,p as C,q as T,t as $}from"./chunk-WIA546AL.js";import"./chunk-ZHHVG47C.js";import{spawnSync as E}from"node:child_process";import{existsSync as B,readdirSync as D,readFileSync as M,statSync as x}from"node:fs";import*as p from"node:path";function U(i){let t=C(i),o=p.dirname(i),s=[];for(let n of X(t,"ProjectReference")){let r=n.get("Include");r&&s.push(S(o,r))}let e=F(t,"SolutionPackageMapFilePath");return{package_type:F(t,"SolutionPackageType"),map_file:e?S(o,e):null,references:s}}function I(i){let t=process.platform==="win32"?(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";"):[""];for(let o of(process.env.PATH??"").split(p.delimiter))if(o)for(let s of t){let e=p.join(o,i+s.toLowerCase());try{if(x(e).isFile())return e}catch{}}return null}function _(){let i=I("dotnet");if(i===null)throw new m("building the project's references needs the .NET SDK (dotnet) on PATH");return i}function G(i,t,o,s){if(!B(i))throw new m(`the referenced project ${i} doesn't exist`);let n=["msbuild",i,"-nologo",`-t:${o?"Build;GetProjectOutputPath":"GetProjectOutputPath"}`,`-p:Configuration=${t}`,"-getTargetResult:GetProjectOutputPath"];o&&n.splice(2,0,"-restore"),s(`${o?"building":"reading"} ${p.basename(i)} (${t})`);let r=E(_(),n,{encoding:"utf8",stdio:["ignore","pipe","pipe"],maxBuffer:256*1024*1024});if(r.error)throw r.error;let c=r.stdout??"",u=r.stderr??"",l=c.trim(),f=null;try{f=l.includes("{")?JSON.parse(l.slice(l.indexOf("{"))):null}catch{f=null}let d=f?.TargetResults?.GetProjectOutputPath??{};if(r.status!==0||d.Result!=="Success"){let a=(c+`
3
- `+u).split(/\r\n|\r|\n/).filter(w=>w.toLowerCase().includes("error")),g=[...new Set(a.slice(0,5).map(w=>w.trim()))].join("; ")||l.slice(-500)||"no output";throw new m(`building ${i} failed: ${g}`)}let h=[];for(let a of d.Items??[]){let g=a.FullPath||a.Identity||"",w=a.PowerAppsComponentType||"";if(!w)throw new m(`${i} gives output ${g} without a PowerAppsComponentType (only PCF and plug-in projects can be referenced)`);h.push([g,w])}return h}function R(i){let t=[],o=s=>{let e;try{e=D(s,{withFileTypes:!0})}catch{return}e.sort((n,r)=>b(n.name.toUpperCase(),r.name.toUpperCase()));for(let n of e)n.isDirectory()||t.push(y(s,n.name));for(let n of e)n.isDirectory()&&o(y(s,n.name))};return o(i),t}function H(i,t){return R(i).find(o=>p.basename(o).toLowerCase()===t.toLowerCase())??null}function N(i,t){return p.relative(t,i).split(p.sep).join("/")}var j=class{constructor(t){this.root=t}files=new Map;solution=null;sol(){return this.solution??=T(p.join(this.root,"Other","Solution.xml"))}exists(t){let o=t.toLowerCase();if([...this.files.keys()].some(s=>s.toLowerCase()===o))return!0;try{return x(p.join(this.root,...t.split("/"))).isFile()}catch{return!1}}result(){let t=new Map(this.files);return this.solution!==null&&t.set("Other/Solution.xml",$(this.solution)),t}addControls(t){let o=!1;try{o=x(t).isDirectory()}catch{o=!1}if(!o)throw new m(`the PCF project's output folder ${t} doesn't exist; build it first`);let s=null,e=this.sol().root.element("SolutionManifest"),n=e!==null?e.element("Publisher"):null;n!==null&&n.element("CustomizationPrefix")!==null&&(s=n.element("CustomizationPrefix").value);let r=[],c=D(t,{withFileTypes:!0}).sort((u,l)=>b(u.name.toUpperCase(),l.name.toUpperCase()));for(let u of c){if(!u.isDirectory())continue;let l=y(t,u.name),f=H(l,"ControlManifest.xml");if(f===null)throw new m(`ControlManifest.xml not found for the control in ${l}`);let d=C(f).element("control");if(d===null||!d.get("namespace")||!d.get("constructor"))throw new m(`${f} has no control namespace and constructor`);let h=`${d.get("namespace")}.${d.get("constructor")}`,a=s?`${s}_${h}`:h,g=`Controls/${a}`;for(let P of R(l))this.files.set(`${g}/${N(P,l)}`,new Uint8Array(M(P)));let w=`${g}/ControlManifest.xml.data.xml`;if(!this.exists(w)){let P="/"+k(g,N(f,l));this.files.set(w,$(O(Buffer.from(`<CustomControl><Name>${a}</Name><FileName>${P}</FileName></CustomControl>`,"utf8"))))}this.addRoot("66",a),r.push(a)}return r}addRoot(t,o){let s=this.sol().root.element("SolutionManifest"),e=s!==null?s.element("RootComponents"):null;if(e===null)throw new m("Other/Solution.xml has no RootComponents");let n=e.elements("RootComponent");if(n.some(a=>a.get("type")===t&&a.get("schemaName")===o))return;let r=new A("RootComponent",[["type",t],["schemaName",o],["behavior","0"]],null,{empty:!0,ns:e.ns,scope:e.scope});r.parent=e;let c=a=>{let g=(a.get("type")??"").trim();return g&&/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(g)?Number(g):NaN},u=Number(t),l=n.filter(a=>c(a)===u),f=n.filter(a=>c(a)>u),d=n.filter(a=>c(a)<u),h;l.length?h=e.kids.indexOf(l[l.length-1])+1:f.length?h=e.kids.indexOf(f[0]):d.length?h=e.kids.indexOf(d[d.length-1])+1:h=e.kids.length,e.kids.splice(h,0,r),e.empty=!1}addPlugin(t){let o=!1;try{o=x(t).isFile()}catch{o=!1}if(!o)throw new m(`the plug-in project's output ${t} doesn't exist; build it first`);let s=new Uint8Array(M(t)),e=L(s);if(e===null)throw new m(`${t} is not a .NET assembly`);let n=y(this.root,"PluginAssemblies");for(let r of R(n)){if(!r.toLowerCase().endsWith("dll.data.xml"))continue;let c=C(r);if((c.get("FullName")??"").toLowerCase()!==e.toLowerCase())continue;let u=c.element("FileName"),l=(u!==null?u.value:"")||"",f=N(r.slice(0,-9),this.root);return l&&(f=v(l.replaceAll("\\","/"))),this.files.set(f,s),f}throw new m(`no plug-in assembly in ${n} is registered as ${e}; the assembly's name, version and key must match a PluginAssemblies/**/*.dll.data.xml`)}};function Y(i,t,o,s=!0,e=n=>process.stderr.write(n+`
4
- `)){let n=new j(t),r=[];for(let c of U(i).references)for(let[u,l]of G(c,o,s,e))if(l.toLowerCase()==="pcf")r.push({project:c,type:"pcf",controls:n.addControls(u)});else if(l.toLowerCase()==="plugin")r.push({project:c,type:"plugin",assembly:n.addPlugin(u)});else throw new m(`${c}: component type ${l} is not supported (only Pcf and Plugin)`);return[n.result(),r]}export{j as Overlay,Y as buildProject,G as buildReference,U as settings};
2
+ import{a as M}from"./chunk-JAGU2NM5.js";import{a as y,b as S,d as L,e as F}from"./chunk-JEAIFLEN.js";import{Y as m,ca as b}from"./chunk-TZSB4PR7.js";import{b as k,g as A}from"./chunk-ZNJ4DRCA.js";import{e as O,o as T,p as C,q as X,t as $}from"./chunk-WIA546AL.js";import{a as v}from"./chunk-P4IFCLVF.js";import"./chunk-3L7657R3.js";import"./chunk-TQLZ3TRU.js";import"./chunk-S4KF5Z3S.js";import"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";import{spawnSync as B}from"node:child_process";import{existsSync as U,readdirSync as D,readFileSync as E,statSync as x}from"node:fs";import*as p from"node:path";function I(i){let t=C(i),o=p.dirname(i),s=[];for(let n of L(t,"ProjectReference")){let r=n.get("Include");r&&s.push(S(o,r))}let e=F(t,"SolutionPackageMapFilePath");return{package_type:F(t,"SolutionPackageType"),map_file:e?S(o,e):null,references:s}}function _(i){let t=process.platform==="win32"?(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";"):[""];for(let o of(process.env.PATH??"").split(p.delimiter))if(o)for(let s of t){let e=p.join(o,i+s.toLowerCase());try{if(x(e).isFile())return e}catch{}}return null}function G(){let i=_("dotnet");if(i===null)throw new m("building the project's references needs the .NET SDK (dotnet) on PATH");return i}function H(i,t,o,s){if(!U(i))throw new m(`the referenced project ${i} doesn't exist`);let n=["msbuild",i,"-nologo",`-t:${o?"Build;GetProjectOutputPath":"GetProjectOutputPath"}`,`-p:Configuration=${t}`,"-getTargetResult:GetProjectOutputPath"];o&&n.splice(2,0,"-restore"),s(`${o?"building":"reading"} ${p.basename(i)} (${t})`);let r=B(G(),n,{encoding:"utf8",stdio:["ignore","pipe","pipe"],env:v(),maxBuffer:256*1024*1024});if(r.error)throw r.error;let c=r.stdout??"",u=r.stderr??"",l=c.trim(),f=null;try{f=l.includes("{")?JSON.parse(l.slice(l.indexOf("{"))):null}catch{f=null}let d=f?.TargetResults?.GetProjectOutputPath??{};if(r.status!==0||d.Result!=="Success"){let a=(c+`
3
+ `+u).split(/\r\n|\r|\n/).filter(w=>w.toLowerCase().includes("error")),g=[...new Set(a.slice(0,5).map(w=>w.trim()))].join("; ")||l.slice(-500)||"no output";throw new m(`building ${i} failed: ${g}`)}let h=[];for(let a of d.Items??[]){let g=a.FullPath||a.Identity||"",w=a.PowerAppsComponentType||"";if(!w)throw new m(`${i} gives output ${g} without a PowerAppsComponentType (only PCF and plug-in projects can be referenced)`);h.push([g,w])}return h}function R(i){let t=[],o=s=>{let e;try{e=D(s,{withFileTypes:!0})}catch{return}e.sort((n,r)=>b(n.name.toUpperCase(),r.name.toUpperCase()));for(let n of e)n.isDirectory()||t.push(y(s,n.name));for(let n of e)n.isDirectory()&&o(y(s,n.name))};return o(i),t}function z(i,t){return R(i).find(o=>p.basename(o).toLowerCase()===t.toLowerCase())??null}function N(i,t){return p.relative(t,i).split(p.sep).join("/")}var j=class{constructor(t){this.root=t}files=new Map;solution=null;sol(){return this.solution??=X(p.join(this.root,"Other","Solution.xml"))}exists(t){let o=t.toLowerCase();if([...this.files.keys()].some(s=>s.toLowerCase()===o))return!0;try{return x(p.join(this.root,...t.split("/"))).isFile()}catch{return!1}}result(){let t=new Map(this.files);return this.solution!==null&&t.set("Other/Solution.xml",$(this.solution)),t}addControls(t){let o=!1;try{o=x(t).isDirectory()}catch{o=!1}if(!o)throw new m(`the PCF project's output folder ${t} doesn't exist; build it first`);let s=null,e=this.sol().root.element("SolutionManifest"),n=e!==null?e.element("Publisher"):null;n!==null&&n.element("CustomizationPrefix")!==null&&(s=n.element("CustomizationPrefix").value);let r=[],c=D(t,{withFileTypes:!0}).sort((u,l)=>b(u.name.toUpperCase(),l.name.toUpperCase()));for(let u of c){if(!u.isDirectory())continue;let l=y(t,u.name),f=z(l,"ControlManifest.xml");if(f===null)throw new m(`ControlManifest.xml not found for the control in ${l}`);let d=C(f).element("control");if(d===null||!d.get("namespace")||!d.get("constructor"))throw new m(`${f} has no control namespace and constructor`);let h=`${d.get("namespace")}.${d.get("constructor")}`,a=s?`${s}_${h}`:h,g=`Controls/${a}`;for(let P of R(l))this.files.set(`${g}/${N(P,l)}`,new Uint8Array(E(P)));let w=`${g}/ControlManifest.xml.data.xml`;if(!this.exists(w)){let P="/"+k(g,N(f,l));this.files.set(w,$(T(Buffer.from(`<CustomControl><Name>${a}</Name><FileName>${P}</FileName></CustomControl>`,"utf8"))))}this.addRoot("66",a),r.push(a)}return r}addRoot(t,o){let s=this.sol().root.element("SolutionManifest"),e=s!==null?s.element("RootComponents"):null;if(e===null)throw new m("Other/Solution.xml has no RootComponents");let n=e.elements("RootComponent");if(n.some(a=>a.get("type")===t&&a.get("schemaName")===o))return;let r=new O("RootComponent",[["type",t],["schemaName",o],["behavior","0"]],null,{empty:!0,ns:e.ns,scope:e.scope});r.parent=e;let c=a=>{let g=(a.get("type")??"").trim();return g&&/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(g)?Number(g):NaN},u=Number(t),l=n.filter(a=>c(a)===u),f=n.filter(a=>c(a)>u),d=n.filter(a=>c(a)<u),h;l.length?h=e.kids.indexOf(l[l.length-1])+1:f.length?h=e.kids.indexOf(f[0]):d.length?h=e.kids.indexOf(d[d.length-1])+1:h=e.kids.length,e.kids.splice(h,0,r),e.empty=!1}addPlugin(t){let o=!1;try{o=x(t).isFile()}catch{o=!1}if(!o)throw new m(`the plug-in project's output ${t} doesn't exist; build it first`);let s=new Uint8Array(E(t)),e=M(s);if(e===null)throw new m(`${t} is not a .NET assembly`);let n=y(this.root,"PluginAssemblies");for(let r of R(n)){if(!r.toLowerCase().endsWith("dll.data.xml"))continue;let c=C(r);if((c.get("FullName")??"").toLowerCase()!==e.toLowerCase())continue;let u=c.element("FileName"),l=(u!==null?u.value:"")||"",f=N(r.slice(0,-9),this.root);return l&&(f=A(l.replaceAll("\\","/"))),this.files.set(f,s),f}throw new m(`no plug-in assembly in ${n} is registered as ${e}; the assembly's name, version and key must match a PluginAssemblies/**/*.dll.data.xml`)}};function tt(i,t,o,s=!0,e=n=>process.stderr.write(n+`
4
+ `)){let n=new j(t),r=[];for(let c of I(i).references)for(let[u,l]of H(c,o,s,e))if(l.toLowerCase()==="pcf")r.push({project:c,type:"pcf",controls:n.addControls(u)});else if(l.toLowerCase()==="plugin")r.push({project:c,type:"plugin",assembly:n.addPlugin(u)});else throw new m(`${c}: component type ${l} is not supported (only Pcf and Plugin)`);return[n.result(),r]}export{j as Overlay,tt as buildProject,H as buildReference,I as settings};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as W}from"./chunk-SWXCK5C2.js";import{p as O}from"./chunk-ELSYHAYC.js";import{D as Z,F,G as B,H as V,d as m,f as w,g as _,h as R,i as z,t as S,u as p,v as P}from"./chunk-BG2OIOSN.js";import{a as T}from"./chunk-UCTMKA2J.js";import{a as k,b as x,d as H,e as A,f as U,g as v}from"./chunk-FOEBNCSD.js";import{b as M}from"./chunk-KBZI5UDL.js";import{y as J}from"./chunk-BALEFXOL.js";import"./chunk-GY6BUIDP.js";import"./chunk-J4R6QXW7.js";import{b as j}from"./chunk-2IUXH534.js";import"./chunk-TCLZ4XM6.js";import"./chunk-H4OY4EFC.js";import"./chunk-TQLZ3TRU.js";import"./chunk-S4KF5Z3S.js";import{a as E,b as f,d as G,j as D}from"./chunk-WXOTXJNG.js";import"./chunk-ZHHVG47C.js";var K=/^([A-Za-z_][A-Za-z0-9_]*)\((.+)\)\n?$/;function tt(t){let n=F(J(t).toString("utf8")).trim(),e;if(n.startsWith("["))try{e=T(n)}catch(r){throw new f(`--body is not valid JSON: ${r.message}`)}else{let r=[];W(n).forEach((i,a)=>{if(i.trim())try{r.push(T(i))}catch(s){throw new f(`line ${a+1}: not JSON (${s.message})`)}}),e=r}let o=r=>typeof r=="object"&&r!==null&&!Array.isArray(r);if(!Array.isArray(e)||!e.length||!e.every(o))throw new f("--body needs one JSON object per row");return e}function et(t){return typeof t=="boolean"?t?"true":"false":typeof t=="number"?String(t):A(String(t))}function nt(t,n,e,o,r){return t.map((i,a)=>{let s=a+1,l,d;if(e&&e.length){let c=e.filter(u=>i[u]===null||i[u]===void 0||i[u]==="");if(c.length)throw new f(`row ${s} has no value for ${c.join(", ")}`);l=`${n}(`+e.map(u=>`${u}=${et(i[u])}`).join(",")+")",d=Object.fromEntries(Object.entries(i).filter(([u])=>!e.includes(u)))}else{let c=i[o];if(!x(m(c)?String(c):""))throw new f(`row ${s} has no ${o}`,{hint:"pass --key <columns> to match on an alternate key"});l=`${n}(${H(String(c))})`,d=Object.fromEntries(Object.entries(i).filter(([u])=>u!==o))}return{method:"PATCH",path:`${l}?$select=${o}`,body:d,headers:{Prefer:"return=representation",...r}}})}var rt={201:"created",200:"updated",204:"updated"};async function Q(t,n,e){let o=await p(t,n,"GET",`EntityDefinitions(LogicalName='${e}')`,{params:[["$select","PrimaryIdAttribute"]]}),r=P(o).PrimaryIdAttribute;if(r===void 0)throw new E("'PrimaryIdAttribute'");return r}async function pt(t){let n=t.args,e=k(B(n.entityset),"entity set name"),o=tt(String(n.body)),r=m(n.key)?String(n.key).split(",").map(c=>c.trim()).filter(c=>c):null,i=await S(t),a=await i.lookups(async()=>Q(t,i,await O(t,i,e))),s=nt(o,e,r,a,Z(t,i)),l=[];for await(let[c,u,N]of V(t,i,s,!1,!!n.continueOnError))for(let h=0;h<u.length;h++){let q=c+h,y=N[h],C=o[q],$=w(y,"status"),b={row:q+1,key:r&&r.length?Object.fromEntries(r.map(L=>[L,C[L]??null])):w(C,a),status:m($)?$:null,action:rt[$]??null},g=w(y,"body"),I=typeof g=="object"&&g!==null&&!Array.isArray(g);I&&m(g[a])&&(b.id=g[a]),I&&"error"in g?b.error=M(w(_(g.error),"message"))??null:(m(y.error)||!m($))&&(b.error=m(y.error)?y.error:"not run (an earlier row failed)"),l.push(z(b))}await t.emit(l);let d=l.filter(c=>"error"in c||(c.status||0)>=400);if(d.length)throw new E(`${d.length} of ${l.length} rows failed or didn't run`,{service:"dataverse",hint:"see each row's error"+(n.continueOnError?"":"; --continue-on-error keeps going after a failure")})}function X(t,n){let e=K.exec(U(n));if(!e)throw new f(`'${n}' is not a record reference`,{hint:"e.g. contacts(<id>) or contacts(name=value)"});let o=e[2].replace(/=\s*'((?:[^']|'')*)'/g,(i,a)=>"="+a.split("''").join("'"));return`${t.service.origin}/api/data/v9.2/${v(e[1],o)}`}async function ot(t,n,e){let o=e.indexOf("/api/data/v9.2/"),r=e.slice(0,o),i=e.slice(o+15),a=K.exec(i);if(x(a[2]))return e;let s=a[1],l=await Q(t,n,await O(t,n,s)),d=P(await p(t,n,"GET",i,{params:[["$select",l]]}))[l];if(d===void 0)throw new E(`'${l}'`);return`${r}/api/data/v9.2/${s}(${d})`}async function Y(t,n,e,o){k(o,"navigation property");let r=await O(t,n,e),i=`EntityDefinitions(LogicalName='${r}')`,a=A(o),s=async(u,N)=>P(await p(t,n,"GET",`${i}/${u}`,{params:[["$select","SchemaName"],["$filter",N]]})),l=await s("ManyToOneRelationships",`ReferencingEntityNavigationPropertyName eq ${a}`);if(R(l.value).length)return!0;let d=await s("OneToManyRelationships",`ReferencedEntityNavigationPropertyName eq ${a}`),c=await s("ManyToManyRelationships",`Entity1NavigationPropertyName eq ${a} or Entity2NavigationPropertyName eq ${a}`);if(R(d.value).length||R(c.value).length)return!1;throw new G(`${r} has no navigation property '${o}'`,{service:"dataverse",hint:`run: ppdo-cli dv metadata get ${r} --relationships`})}async function yt(t){let n=t.args,e=await S(t),o=v(String(n.entityset),String(n.id));j(t,e,"POST",o,Buffer.from("{}"));let r=X(e,String(n.target)),i=String(n.navigation),a=await e.lookups(()=>Y(t,e,String(n.entityset),i)),s=Buffer.from(D({"@odata.id":r}),"utf8");await p(t,e,a?"PUT":"POST",`${o}/${i}/$ref`,{body:s}),await t.emit({record:o,navigation:i,target:r.slice(r.indexOf("/v9.2/")+6),linked:!0})}async function wt(t){let n=t.args,e=await S(t),o=v(String(n.entityset),String(n.id));j(t,e,"DELETE",o,null);let r=String(n.navigation),i=await e.lookups(()=>Y(t,e,String(n.entityset),r)),a=B(n.target);if(i)await p(t,e,"DELETE",`${o}/${r}/$ref`);else{if(!a)throw new f(`${r} is a collection: name the record to unlink, e.g. contacts(<id>)`);let s=X(e,a),l=await e.lookups(()=>ot(t,e,s));await p(t,e,"DELETE",`${o}/${r}/$ref`,{params:[["$id",l]]})}await t.emit({record:o,navigation:r,target:a,unlinked:!0})}export{yt as associate,wt as disassociate,et as literal,tt as readRows,X as targetUrl,pt as upsert,nt as upsertRequests};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{g as u}from"./chunk-WXOTXJNG.js";var c=["GET","HEAD"],d={dataverse:["exportsolution","exportsolutionasync","downloadsolutionexportdata"],devops:["_apis/wit/wiql","_apis/wit/workitemsbatch"]},E=/_apis\/pipelines\/\d+\/preview$/,m=/^(GET|HEAD|POST|PATCH|PUT|DELETE|MERGE)[ \t\n\r\f\v]+[^ \t\n\r\f\v]+[ \t\n\r\f\v]+HTTP\/1\.[01][ \t\n\r\f\v]*$/gim;function f(e){return!e||!e.length?[]:[...(typeof e=="string"?e:Buffer.from(e).toString("latin1")).matchAll(m)].map(r=>r[1].toUpperCase())}function g(e){let t;if(e.includes("://")){let r=/^[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/?#]*([^?#]*)/.exec(e);t=r?r[1]??"":""}else t=e.split("?",1)[0]??"";return t.replace(/^\/+|\/+$/g,"").toLowerCase()}function p(e){return g(e).endsWith("$batch")}function h(e,t){let r=g(t);if(e==="dataverse"){let n=r.slice(r.lastIndexOf("/")+1);return n=n.replace(/\(.*\)$/,""),n=n.slice(n.lastIndexOf(".")+1),(d.dataverse??[]).includes(n)}return e==="devops"&&E.test(r)?!0:(d[e]??[]).some(n=>r.endsWith(n))}function v(e,t,r,n,i,o){if(n=n.toUpperCase(),t==="V")return n!=="DELETE"?`a request of class V must be a DELETE, not ${n}`:e==="read-only"?"this request writes; mode is 'read-only'":null;if(t==="D"&&e!=="full")return`this command deletes; mode is '${e}' (needs 'full')`;if(t==="W"&&e==="read-only")return"this command writes; mode is 'read-only'";if(e==="full"||c.includes(n))return null;if(e==="read-write")return n==="DELETE"?"DELETE needs mode 'full' (current: 'read-write')":p(i)&&f(o).includes("DELETE")?"this $batch contains a DELETE part; needs mode 'full'":null;if(n==="POST"){if(p(i)){let a=f(o),s=a.filter(l=>!c.includes(l));return a.length&&!s.length?null:s.length?`this $batch contains a ${s[0]} part; mode is 'read-only'`:"cannot read the $batch parts; mode is 'read-only'"}if(h(r,i))return null}return`${n} is not allowed in mode 'read-only'`}function $(e,t,r,n,i,o){let a=o||(typeof e.args._cls=="string"?e.args._cls:"M"),s=t.target,l=v(s.mode,a,t.service.name,r,n,i);if(l)throw new u(`blocked: ${l}`,{service:t.service.name,hint:w(s)})}function w(e){if(e.app){let t=e.mode==="read-write"?"full":"read-write (full to delete)";return`this runs as an app with --mode ${e.mode}; pass --mode ${t} if the change is intended`}return`stop and ask the user: environment '${e.env.name}' is in group '${e.group.name}' (${e.mode}); only they can change that`}export{h as a,$ as b,w as c};
@@ -0,0 +1,5 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{b as w}from"./chunk-TQLZ3TRU.js";import{e as R}from"./chunk-S4KF5Z3S.js";import{b as a}from"./chunk-WXOTXJNG.js";import{existsSync as M,readFileSync as W,realpathSync as Y,statSync as q}from"node:fs";import{basename as K,dirname as T,join as f,resolve as Q}from"node:path";var X=/^[a-z0-9][a-z0-9_-]*$/,A=["broker","browser","device_code","az_cli","spn","pat"],O=["read-only","read-write","full"],nn={"read-only":0,"read-write":1,full:2},I=["dataverse","devops"],wn={dv:"dataverse",dataverse:"dataverse",ado:"devops",devops:"devops"},h={dataverse:"Dataverse",devops:"DevOps"},z={dataverse:"PPDEVOPS_DATAVERSE",devops:"PPDEVOPS_DEVOPS"},N=".ppdo-cli.json",tn="config.toml",F=".ppdevops.toml",en="PPDEVOPS_CLIENT_SECRET",on="04b07795-8ddb-461a-bbee-02f9e1bf7b46",k=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,48}[A-Za-z0-9])?$/,rn=/^[A-Za-z_][A-Za-z0-9_]*$/;function yn(i,n){if(!X.test(i??""))throw new a(`invalid ${n} name '${i}'`,{hint:"use lowercase letters, digits, '-' and '_' (start with a letter or digit)"});return i}function g(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function d(i,n){let t=i[n];return typeof t=="string"?t:null}var C=[["tenant","tenant"],["username","username"],["method","method"],["client_id","clientId"],["config_dir","configDir"],["secret_env","secretEnv"],["certificate","certificate"],["organization","organization"],["pat_env","patEnv"]],y=class i{name;tenant;username;method;clientId;configDir;secretEnv;certificate;organization;patEnv;ephemeral=!1;constructor(n,t){this.name=n,this.tenant=t.tenant,this.username=t.username??null,this.method=t.method,this.clientId=t.clientId??null,this.configDir=t.configDir??null,this.secretEnv=t.secretEnv??null,this.certificate=t.certificate??null,this.organization=t.organization??null,this.patEnv=t.patEnv??null}get effectiveClientId(){return this.clientId||on}account(){return JSON.stringify(C.map(([,n])=>this[n]))}toDict(){let n={};for(let[t,o]of C)this[o]!==null&&this[o]!==""&&(n[t]=this[o]);return n}static fromDict(n,t){return new i(n,{tenant:d(t,"tenant")??"",username:d(t,"username"),method:d(t,"method")??"browser",clientId:d(t,"client_id"),configDir:d(t,"config_dir"),secretEnv:d(t,"secret_env"),certificate:d(t,"certificate"),organization:d(t,"organization"),patEnv:d(t,"pat_env")})}clone(){let n=new i(this.name,this);return n.ephemeral=this.ephemeral,n}},$=class i{name;identity;mode;constructor(n,t=null,o="read-only"){this.name=n,this.identity=t,this.mode=o}clone(){return new i(this.name,this.identity,this.mode)}},m=class i{name;group;service;url;org;project;constructor(n,t,o,e={}){this.name=n,this.group=t,this.service=o,this.url=e.url??null,this.org=e.org??null,this.project=e.project??null}get endpoint(){return this.service==="dataverse"?this.url??"":[this.org,this.project].filter(n=>n).join("/")}spec(){return this.service==="dataverse"?{url:this.url}:{org:this.org,project:this.project}}toDict(){return{[this.service]:this.endpoint}}static fromDict(n,t,o){let e=d(o,"dataverse");if(e!==null)return new i(n,t,"dataverse",{url:e});let r=d(o,"devops");if(r!==null){let s=r.indexOf("/"),c=s<0?r:r.slice(0,s),l=s<0?"":r.slice(s+1);return new i(n,t,"devops",{org:c,project:l||null})}throw new a(`environment '${n}' in group '${t}' needs 'dataverse = "<url>"' or 'devops = "<org>/<project>"'`)}clone(){return new i(this.name,this.group,this.service,this)}};function x(i){return i?i instanceof Map?new Map(i):new Map(Object.entries(i)):new Map}function U(i){if(!g(i))return i;let n={};for(let[t,o]of Object.entries(i))o!=null&&(n[t]=U(o));return n}function V(i){let n;try{n=W(i)}catch(e){if(e.code==="ENOENT")return null;throw e}let t;try{t=new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{throw new a(`cannot read ${i}: not valid UTF-8`,{hint:"fix or delete the file"})}let o;try{o=JSON.parse(t)}catch(e){throw new a(`cannot read ${i}: ${e.message}`,{hint:"fix or delete the file"})}if(!g(o))throw new a(`cannot read ${i}: expected a JSON object`,{hint:"fix or delete the file"});return o}var L=new Set;function G(i,n){L.has(i)||(L.add(i),R(`ignored ${i}: ppdo-cli now reads ${K(i)===F?N:"config.json"}; ${n}`))}function S(i,n,t){let o=i[n];if(o==null)return{};if(!g(o))throw new a(`cannot read ${t}: '${n}' must be an object`,{hint:"fix or delete the file"});return o}var j=class i{identities;groups;environments;current;output;schema;path;constructor(n={}){this.identities=x(n.identities),this.groups=x(n.groups),this.environments=x(n.environments),this.current={...n.current??{}},this.output=n.output??null,this.schema=n.schema??null,this.path=n.path??null}static async load(n=w()){let t=V(n);if(t)return i.fromData(t,n);let o=f(T(n),tn);return D(o)&&G(o,"set up again with ppdo-cli identity add, group add and env add"),new i({path:n})}static fromData(n,t=null){let o=t??"the config",e=new Map,r=new Map;for(let[u,p]of Object.entries(S(n,"groups",o))){let b=g(p)?p:{};e.set(u,new $(u,d(b,"identity"),d(b,"mode")??"read-only"));for(let[v,P]of Object.entries(S(b,"environments",o))){if(r.has(v))throw new a(`environment '${v}' is in more than one group`,{hint:`fix ${o}`});r.set(v,m.fromDict(v,u,g(P)?P:{}))}}let s=new Map;for(let[u,p]of Object.entries(S(n,"identities",o)))s.set(u,y.fromDict(u,g(p)?p:{}));let c={};for(let u of I){let p=d(n,`current-${u}`);p&&(c[u]=p)}let l=new i({identities:s,groups:e,environments:r,current:c,output:d(n,"output"),schema:d(n,"$schema"),path:t});return l.checkFile(o),l}checkFile(n){let t={hint:`fix ${n}`};for(let e of this.identities.values())if(!A.includes(e.method))throw new a(`identity '${e.name}' has method '${e.method}'; use one of: ${A.join(", ")}`,t);for(let e of this.groups.values())if(!O.includes(e.mode))throw new a(`group '${e.name}' has mode '${e.mode}'; use one of: ${O.join(", ")}`,t);let o=new Map;for(let e of this.environments.values()){let r=`${e.service}
3
+ ${e.endpoint.toLowerCase()}`,s=o.get(r);if(s!==void 0)throw new a(`${e.endpoint} is both environment '${s}' and '${e.name}'`,{hint:`an environment belongs to one group, so it has one account and one mode; keep one of them in ${n}`});o.set(r,e.name)}this.checkPat(n)}checkPat(n){let t=n?`fix ${n}`:"a PAT identity is for one Azure DevOps organization: see ppdo-cli identity show <name>",o=n?`; fix ${n}`:"";for(let e of this.identities.values()){let r=`identity '${e.name}'`;if(e.method!=="pat"){if(e.organization!==null||e.patEnv!==null)throw new a(`${r}: 'organization' and 'pat_env' are for method 'pat' only`,{hint:t});continue}if(!e.organization||!k.test(e.organization))throw new a(`${r} (method 'pat') needs 'organization': an Azure DevOps organization name`,{hint:t});if(!e.username)throw new a(`${r} (method 'pat') needs 'username': the account the PAT belongs to`,{hint:t});if(e.clientId!==null||e.configDir!==null||e.secretEnv!==null||e.certificate!==null)throw new a(`${r}: 'client_id', 'config_dir', 'secret_env' and 'certificate' don't apply to method 'pat'`,{hint:t});if(e.patEnv!==null&&!rn.test(e.patEnv))throw new a(`${r}: 'pat_env' must be an environment variable name`,{hint:t})}for(let e of this.groups.values()){let r=e.identity?this.identities.get(e.identity):void 0;if(!r||r.method!=="pat")continue;let s=(r.organization??"").toLowerCase();for(let c of this.members(e.name)){if(c.service!=="devops")throw new a(`group '${e.name}' uses PAT identity '${r.name}', so it can't hold Dataverse environment '${c.name}'`,{hint:"a PAT reaches Azure DevOps only: put the environment in a group with another identity"+o});if(!c.org||!k.test(c.org)||c.org.toLowerCase()!==s)throw new a(`group '${e.name}' uses PAT identity '${r.name}' for organization '${r.organization}', so it can't hold '${c.name}' (${c.endpoint})`,{hint:"a PAT is for one organization: use another group and identity for this one"+o})}}}toDict(){let n={};for(let e of this.groups.values()){let r={identity:e.identity,mode:e.mode},s={};for(let c of this.members(e.name))s[c.name]=c.toDict();Object.keys(s).length&&(r.environments=s),n[e.name]=r}let t={};for(let[e,r]of this.identities)t[e]=r.toDict();let o={$schema:this.schema};for(let e of I)o[`current-${e}`]=this.current[e]??null;return o.output=this.output,o.identities=t,o.groups=n,o}async dumps(){let n=U(this.toDict());for(let t of["identities","groups"])g(n[t])&&!Object.keys(n[t]).length&&delete n[t];return JSON.stringify(n,null,2)+`
4
+ `}async save(){let{atomicWrite:n}=await import("./protect-X2J7LU7X.js");n(this.path??w(),await this.dumps())}static async edit(n){let{withFileLock:t}=await import("./protect-X2J7LU7X.js"),o=w();return t(o,async()=>{let e=await i.load(o),r=await n(e);return await e.save(),r})}clone(){let n=t=>new Map([...t].map(([o,e])=>[o,e.clone()]));return new i({identities:n(this.identities),groups:n(this.groups),environments:n(this.environments),current:this.current,output:this.output,schema:this.schema,path:this.path})}validate(){let n=new Map;for(let t of this.environments.values()){this.group(t.group);let o=`${t.service}
5
+ ${t.endpoint.toLowerCase()}`,e=n.get(o);if(e!==void 0)throw new a(`${t.endpoint} is already environment '${e}'`,{hint:`an environment belongs to one group; move it instead: ppdo-cli env move ${e} --to <group>`});n.set(o,t.name)}for(let t of this.groups.values())t.identity&&this.identity(t.identity);this.checkPat(null)}identity(n){let t=this.identities.get(n);if(!t)throw new a(`no identity named '${n}'`,{hint:"run: ppdo-cli identity list"});return t}group(n){let t=this.groups.get(n);if(!t)throw new a(`no group named '${n}'`,{hint:"run: ppdo-cli group list"});return t}environment(n){let t=this.environments.get(n);if(!t)throw new a(`no environment named '${n}'`,{hint:"run: ppdo-cli env list"});return t}members(n){return[...this.environments.values()].filter(t=>t.group===n)}};function _(i){let n=new Map;for(let t of i.environments.values()){let o=i.groups.get(t.group),e=o&&o.identity?i.identities.get(o.identity):void 0;if(!o||!e)continue;let r=JSON.stringify([t.service,t.endpoint.toLowerCase(),e.account()]),s=nn[o.mode]??0;s>=(n.get(r)?.[0]??-1)&&n.set(r,[s,t.name])}return n}function $n(i,n){let t=_(i),o=[];for(let[e,[r,s]]of _(n))if(r>(t.get(e)?.[0]??0)){let c=n.environment(s),l=n.group(c.group),u=n.identity(l.identity??""),p=l.mode==="full"?"write and delete":"write";o.push(`agents could ${p} in '${s}' (${c.endpoint}) as ${u.username||u.name} (group '${l.name}', ${l.mode})`)}return o}function J(i){let n=Q(i??process.cwd());try{return Y(n)}catch{return n}}function Z(i){let n=[i];for(let t=T(i);t!==n[n.length-1];t=T(t))n.push(t);return n}function D(i){try{return q(i).isFile()}catch{return!1}}async function sn(i){let n=Z(J(i)),t=n.findIndex(e=>M(f(e,".git"))),o=t>=0?n.slice(0,t+1):n.slice(0,1);for(let e of o){let r=f(e,N);if(!D(r)){let l=f(e,F);D(l)&&G(l,"pin again with ppdo-cli env pin <env>");continue}let s;try{s=V(r)}catch(l){throw l instanceof a?new a(l.message):l}if(!s)continue;let c={};for(let l of I){let u=s[l];typeof u=="string"&&u&&(c[l]=u)}if(Object.keys(c).length)return[c,r]}return null}function En(i){for(let n of Z(J(i)))if(M(f(n,".git")))return n;return null}var E=class{env;group;source;app;constructor(n,t,o,e=!1){this.env=n,this.group=t,this.source=o,this.app=e}get mode(){return this.group.mode}};function B(i){return!!i&&i.includes("://")}function an(i){return`run: ppdo-cli env list --service ${i==="devops"?"ado":"dv"}`}async function bn(i,n,t){let[o,e]=await H(i,n,t);if(B(o))throw new a(`'${o}' is a URL; a URL target needs --client-id and --tenant`,{hint:"or pass an environment name (see ppdo-cli env list)"});let r=i.environment(o);if(r.service!==n)throw new a(`environment '${o}' is a ${h[r.service]} environment, not ${h[n]}`,{hint:an(n)});return new E(r,i.group(r.group),e)}async function H(i,n,t){let o,e="",r=process.env[z[n]];if(t)[o,e]=[t,"flag"];else if(r)[o,e]=[r,`env ${z[n]}`];else{let s=await sn();s&&s[0][n]?[o,e]=[s[0][n],`file ${s[1]}`]:i.current[n]&&([o,e]=[i.current[n],`global current-${n}`])}if(!o)throw new a(`no ${h[n]} environment selected`,{hint:"pass --env <name>, or run: ppdo-cli env use <name> (see ppdo-cli env list)"});return[o,e]}var cn=[["clientId","--client-id"],["tenant","--tenant"],["certificate","--certificate"],["mode","--mode"]];function xn(i){let n=cn.filter(([t])=>i[t]);if(!n.length)return!1;if(!n.some(([t])=>t==="clientId")){let t=n.map(([,o])=>o).join(", ");throw new a(`${t} ${n.length===1?"applies":"apply"} only with --client-id`,{hint:"a configured environment's mode comes from its group (ppdo-cli group list)"})}if(!i.tenant)throw new a("--client-id needs --tenant <id|domain>");if(i.identity)throw new a("use --identity or --client-id, not both");return!0}function ln(i){let n=String(i.clientId).trim(),t=i.certificate?String(i.certificate):null,o=new y(`app:${n}`,{tenant:String(i.tenant).trim(),username:null,method:"spn",clientId:n,secretEnv:t?null:en,certificate:t});return o.ephemeral=!0,o}function un(i){if(!i.includes("://"))return null;let n;try{n=new URL(i.trim())}catch{throw new a(`'${i}' is not a dev.azure.com URL`)}let t=n.hostname.toLowerCase(),o=n.pathname.split("/").filter(c=>c).map(c=>decodeURIComponent(c)),e,r;if(t==="dev.azure.com"&&o.length)e=o[0]??"",r=o.slice(1);else if(t.endsWith(".visualstudio.com"))e=t.split(".")[0]??"",r=o,r[0]?.toLowerCase()==="defaultcollection"&&(r=r.slice(1));else throw new a(`'${i}' is not a dev.azure.com URL`);let s=r[0];return[e,s&&!s.startsWith("_")?s:null]}function dn(i,n){if(i==="dataverse"){let r=pn(n);return new m(r.slice(r.indexOf("://")+3),"app","dataverse",{url:r})}let t=un(n);if(!t)throw new a(`'${n}' is not a dev.azure.com URL`);let[o,e]=t;return new m([o,e].filter(r=>r).join("/"),"app","devops",{org:o,project:e})}async function Sn(i,n,t){let o=typeof t.env=="string"?t.env:null,[e,r]=await H(i,n,o),s;if(B(e))s=dn(n,e);else if(s=i.environment(e),s.service!==n)throw new a(`environment '${e}' is a ${h[s.service]} environment, not ${h[n]}`);let c=new $("app",null,typeof t.mode=="string"&&t.mode?t.mode:"read-only");return[new E(s,c,r,!0),ln(t)]}function Tn(i,n,t){if(t)return[i.identity(t),"flag"];let o=process.env.PPDEVOPS_IDENTITY;if(o)return[i.identity(o),"env PPDEVOPS_IDENTITY"];let e=n.group.identity;if(!e)throw new a(`group '${n.group.name}' has no identity`,{hint:`run: ppdo-cli group update ${n.group.name} --identity <name>`});return[i.identity(e),`group ${n.group.name}`]}function pn(i){let n=i.trim();n.includes("://")||(n="https://"+n);let t=null;try{t=new URL(n)}catch{t=null}if(!t||t.protocol!=="https:"||!t.hostname)throw new a(`invalid Dataverse URL '${n}'`,{hint:"use https://<org>.crm.dynamics.com"});return`https://${t.hostname.toLowerCase()}`}export{X as a,A as b,O as c,nn as d,I as e,wn as f,h as g,z as h,N as i,en as j,on as k,k as l,rn as m,yn as n,y as o,$ as p,m as q,V as r,j as s,_ as t,$n as u,sn as v,En as w,E as x,B as y,bn as z,xn as A,ln as B,un as C,dn as D,Sn as E,Tn as F,pn as G};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
- import{c as K}from"./chunk-BWZ6HZXM.js";import{y as P}from"./chunk-BALEFXOL.js";import{a as R,b as U,e as J}from"./chunk-J4R6QXW7.js";import{b as v}from"./chunk-5SBBTR3Y.js";import{e as $}from"./chunk-S4KF5Z3S.js";import{a as E,b as h,j as L}from"./chunk-WXOTXJNG.js";var C=class{constructor(e,t){this.a=e;this.b=t;t.forEach((i,o)=>{let s=this.b2j.get(i);s?s.push(o):this.b2j.set(i,[o])});let r=t.length;if(r>=200){let i=Math.floor(r/100)+1;for(let[o,s]of[...this.b2j])s.length>i&&this.b2j.delete(o)}}b2j=new Map;findLongestMatch(e,t,r,i){let{a:o,b:s}=this,u=e,c=r,l=0,a=new Map;for(let f=e;f<t;f++){let p=new Map;for(let d of this.b2j.get(o[f])??[]){if(d<r)continue;if(d>=i)break;let m=(a.get(d-1)??0)+1;p.set(d,m),m>l&&(u=f-m+1,c=d-m+1,l=m)}a=p}for(;u>e&&c>r&&o[u-1]===s[c-1];)u--,c--,l++;for(;u+l<t&&c+l<i&&o[u+l]===s[c+l];)l++;return[u,c,l]}matchingBlocks(){let e=this.a.length,t=this.b.length,r=[[0,e,0,t]],i=[];for(;r.length;){let[l,a,f,p]=r.pop(),d=this.findLongestMatch(l,a,f,p),[m,g,x]=d;x&&(i.push(d),l<m&&f<g&&r.push([l,m,f,g]),m+x<a&&g+x<p&&r.push([m+x,a,g+x,p]))}i.sort((l,a)=>l[0]-a[0]||l[1]-a[1]||l[2]-a[2]);let[o,s,u]=[0,0,0],c=[];for(let[l,a,f]of i)o+u===l&&s+u===a?u+=f:(u&&c.push([o,s,u]),[o,s,u]=[l,a,f]);return u&&c.push([o,s,u]),c.push([e,t,0]),c}opcodes(){let e=0,t=0,r=[];for(let[i,o,s]of this.matchingBlocks()){let u=e<i&&t<o?"replace":e<i?"delete":t<o?"insert":"";u&&r.push([u,e,i,t,o]),e=i+s,t=o+s,s&&r.push(["equal",i,e,o,t])}return r}groupedOpcodes(e=3){let t=this.opcodes();t.length||(t=[["equal",0,1,0,1]]);let r=t[0];if(r[0]==="equal"){let[c,l,a,f,p]=r;t[0]=[c,Math.max(l,a-e),a,Math.max(f,p-e),p]}let i=t[t.length-1];if(i[0]==="equal"){let[c,l,a,f,p]=i;t[t.length-1]=[c,l,Math.min(a,l+e),f,Math.min(p,f+e)]}let o=e+e,s=[],u=[];for(let c of t){let[l,a,f,p,d]=c;l==="equal"&&f-a>o&&(u.push([l,a,Math.min(f,a+e),p,Math.min(d,p+e)]),s.push(u),u=[],a=Math.max(a,f-e),p=Math.max(p,d-e)),u.push([l,a,f,p,d])}return u.length&&!(u.length===1&&u[0][0]==="equal")&&s.push(u),s}};function D(n,e){let t=n+1,r=e-n;return r===1?String(t):(r||(t-=1),`${t},${r}`)}function _(n,e,t,r,i=3){let o=[],s=!1;for(let u of new C(n,e).groupedOpcodes(i)){s||(s=!0,o.push(`--- ${t}
2
+ import{y as P}from"./chunk-BALEFXOL.js";import{c as K}from"./chunk-6NBCHK6X.js";import{a as R,b as U,e as J}from"./chunk-J4R6QXW7.js";import{b as v}from"./chunk-2IUXH534.js";import{e as $}from"./chunk-S4KF5Z3S.js";import{a as E,b as h,j as L}from"./chunk-WXOTXJNG.js";var C=class{constructor(e,t){this.a=e;this.b=t;t.forEach((i,o)=>{let s=this.b2j.get(i);s?s.push(o):this.b2j.set(i,[o])});let r=t.length;if(r>=200){let i=Math.floor(r/100)+1;for(let[o,s]of[...this.b2j])s.length>i&&this.b2j.delete(o)}}b2j=new Map;findLongestMatch(e,t,r,i){let{a:o,b:s}=this,u=e,c=r,l=0,a=new Map;for(let f=e;f<t;f++){let p=new Map;for(let d of this.b2j.get(o[f])??[]){if(d<r)continue;if(d>=i)break;let m=(a.get(d-1)??0)+1;p.set(d,m),m>l&&(u=f-m+1,c=d-m+1,l=m)}a=p}for(;u>e&&c>r&&o[u-1]===s[c-1];)u--,c--,l++;for(;u+l<t&&c+l<i&&o[u+l]===s[c+l];)l++;return[u,c,l]}matchingBlocks(){let e=this.a.length,t=this.b.length,r=[[0,e,0,t]],i=[];for(;r.length;){let[l,a,f,p]=r.pop(),d=this.findLongestMatch(l,a,f,p),[m,g,x]=d;x&&(i.push(d),l<m&&f<g&&r.push([l,m,f,g]),m+x<a&&g+x<p&&r.push([m+x,a,g+x,p]))}i.sort((l,a)=>l[0]-a[0]||l[1]-a[1]||l[2]-a[2]);let[o,s,u]=[0,0,0],c=[];for(let[l,a,f]of i)o+u===l&&s+u===a?u+=f:(u&&c.push([o,s,u]),[o,s,u]=[l,a,f]);return u&&c.push([o,s,u]),c.push([e,t,0]),c}opcodes(){let e=0,t=0,r=[];for(let[i,o,s]of this.matchingBlocks()){let u=e<i&&t<o?"replace":e<i?"delete":t<o?"insert":"";u&&r.push([u,e,i,t,o]),e=i+s,t=o+s,s&&r.push(["equal",i,e,o,t])}return r}groupedOpcodes(e=3){let t=this.opcodes();t.length||(t=[["equal",0,1,0,1]]);let r=t[0];if(r[0]==="equal"){let[c,l,a,f,p]=r;t[0]=[c,Math.max(l,a-e),a,Math.max(f,p-e),p]}let i=t[t.length-1];if(i[0]==="equal"){let[c,l,a,f,p]=i;t[t.length-1]=[c,l,Math.min(a,l+e),f,Math.min(p,f+e)]}let o=e+e,s=[],u=[];for(let c of t){let[l,a,f,p,d]=c;l==="equal"&&f-a>o&&(u.push([l,a,Math.min(f,a+e),p,Math.min(d,p+e)]),s.push(u),u=[],a=Math.max(a,f-e),p=Math.max(p,d-e)),u.push([l,a,f,p,d])}return u.length&&!(u.length===1&&u[0][0]==="equal")&&s.push(u),s}};function D(n,e){let t=n+1,r=e-n;return r===1?String(t):(r||(t-=1),`${t},${r}`)}function _(n,e,t,r,i=3){let o=[],s=!1;for(let u of new C(n,e).groupedOpcodes(i)){s||(s=!0,o.push(`--- ${t}
3
3
  `,`+++ ${r}
4
4
  `));let c=u[0],l=u[u.length-1];o.push(`@@ -${D(c[1],l[2])} +${D(c[3],l[4])} @@
5
5
  `);for(let[a,f,p,d,m]of u){if(a==="equal"){for(let g of n.slice(f,p))o.push(" "+g);continue}if(a==="replace"||a==="delete")for(let g of n.slice(f,p))o.push("-"+g);if(a==="replace"||a==="insert")for(let g of e.slice(d,m))o.push("+"+g)}}return o.join("")}var S=[10,11,12,13,28,29,30,133,8232,8233].map(n=>String.fromCharCode(n)).join(""),G=new RegExp(`[^${S}]*(?:\\r\\n|[${S}]|$)`,"g");function O(n){let e=[];for(let t of n.matchAll(G)){if(t[0]===""){if((t.index??0)>=n.length)break;continue}e.push(t[0])}return e}function wn(n){return O(n).map(e=>e.replace(new RegExp(`(?:\\r\\n|[${S}])$`),""))}function Y(n){return n.replace(/[.*+?^${}()|[\]\\/]/g,"\\$&")}var N=new Map;function Z(n){let e=N.get(n);if(e)return e;let t="",r=!1,i=0,o=n.length;for(;i<o;){let u=n[i];if(i++,u==="*"){r||(t+="[\\s\\S]*"),r=!0;continue}if(r=!1,u==="?")t+="[\\s\\S]";else if(u==="["){let c=i;for(c<o&&n[c]==="!"&&c++,c<o&&n[c]==="]"&&c++;c<o&&n[c]!=="]";)c++;if(c>=o)t+="\\[";else{let l=n.slice(i,c).replace(/\\/g,"\\\\");i=c+1,l?l==="!"?t+="[\\s\\S]":(l[0]==="!"?l="^"+l.slice(1):(l[0]==="^"||l[0]==="[")&&(l="\\"+l),t+=`[${l.replace(/\]/g,"\\]")}]`):t+="(?!)"}}else t+=Y(u)}let s=new RegExp(`^${t}$`,"u");return N.set(n,s),s}function xn(n,e){try{return Z(e).test(n)}catch{return n===e}}var Q={run:[/[?&]buildId=(\d+)/i],pr:[/\/pullrequests?\/(\d+)/i],wi:[/\/_workitems\/edit\/(\d+)/i,/\/workitems\/(\d+)/i],pipeline:[/[?&]definitionId=(\d+)/i,/\/_apis\/pipelines\/(\d+)/i,/\/_apis\/build\/definitions\/(\d+)/i]},X={run:"run",pr:"PR",wi:"work item",pipeline:"pipeline"};function nn(n){let e=n.slice(n.lastIndexOf("@")+1);return e.startsWith("[")?e=e.slice(1,e.indexOf("]")<0?void 0:e.indexOf("]")):e.includes(":")&&(e=e.slice(0,e.indexOf(":"))),e.toLowerCase()}function en(n){if(!n.includes("://"))return null;let e=J(n.trim()),t=nn(e.netloc),r=e.path.split("/").filter(c=>c).map(c=>U(c)),i,o;if(t==="dev.azure.com"&&r.length)i=r[0],o=r.slice(1);else if(t.endsWith(".visualstudio.com"))i=t.split(".",1)[0],o=r,o.length&&o[0].toLowerCase()==="defaultcollection"&&(o=o.slice(1));else throw new h(`'${n}' is not a dev.azure.com URL`);let s=o[0],u=s!==void 0&&!s.startsWith("_")?s:null;return[i,u]}function q(n,e,t){let r=e?en(n):null;if(!r||!e)return;let[i,o]=r,s=e.service,u=i.toLowerCase()===s.org.toLowerCase(),c=t==="wi"||!o||!s.project||o.toLowerCase()===s.project.toLowerCase();if(!(u&&c)){let l=o?`${i}/${o}`:i,a=e.target.env.name;throw new h(`that URL is for ${l}, but environment '${a}' is ${s.org}/${s.project??""}`.replace(/\/+$/,""),{hint:`pass --env with the environment for ${l} (ppdo-cli env list)`})}}function T(n,e,t){let r=String(n).trim();if(/^\d+$/.test(r))return parseInt(r,10);for(let i of Q[e]??[]){let o=i.exec(r);if(o)return q(r,t,e),parseInt(o[1],10)}throw new h(`expected a ${X[e]??e} id or its dev.azure.com URL, got '${r}'`)}function z(n,e,t){let r=[];for(let i of n??[])for(let o of String(i).split(","))o.trim()&&r.push(T(o,e,t));return[...new Set(r)]}function F(n,e){let t=n.trim();if(/^[0-9a-fA-F]{40}$/.test(t))return t.toLowerCase();if(/^[0-9a-fA-F]{7,39}$/.test(t))throw new h(`'${t}' is a short SHA; Azure DevOps needs all 40 characters`,{hint:"use git rev-parse <sha>, or paste the commit's URL"});let r=/\/commits?\/([0-9a-fA-F]{40})/.exec(t);if(r)return q(t,e,"commit"),r[1].toLowerCase();throw new h(`expected a commit SHA or its dev.azure.com URL, got '${t}'`)}var rn=100;function k(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function w(n){return n==null||n===!1||n===0||n===""?!1:Array.isArray(n)?n.length>0:k(n)?Object.keys(n).length>0:!0}function A(...n){for(let e of n)if(w(e))return e;return n[n.length-1]}function on(n,e){return k(n)?n[e]??null:null}function I(n){return k(n)&&w(n)?n:{}}function sn(n){return Array.isArray(n)?n:[]}function y(n){return typeof n=="string"?n:n==null?null:String(n)}function Tn(n,e=[]){let t={};for(let[r,i]of Object.entries(n))i!=null&&(e.some(o=>o===i||Array.isArray(o)&&Array.isArray(i)&&!o.length&&!i.length)||(t[r]=i));return t}function b(n){return n==null?"None":n===!0?"True":n===!1?"False":String(n)}function An(n){return/^\d+$/.test(n)}function un(n,e){let t=typeof n=="boolean"?Number(n):n,r=typeof e=="boolean"?Number(e):e;return t===r?0:t==null?-1:r==null?1:t<r?-1:1}function In(n,e,t=!1){let r=n.map((i,o)=>({r:i,i:o,k:[e(i)].flat()}));return r.sort((i,o)=>{for(let s=0;s<Math.max(i.k.length,o.k.length);s++){let u=un(i.k[s],o.k[s]);if(u)return t?-u:u}return i.i-o.i}),r.map(i=>i.r)}function Mn(n){let e=Math.floor(n),t=n-e;return t>.5?e+1:t<.5||e%2===0?e:e+1}function Bn(n){if(Number.isInteger(n*4)&&!Number.isInteger(n*2)){let e=Math.floor(n*10)/10,t=Math.ceil(n*10)/10;return Math.round(e*10)%2===0?e:t}return Number(n.toFixed(1))}function W(n){let e=new Error(n);return e.name="ValueError",e}function En(n){if(!/^\s*[+-]?\d+\s*$/.test(n))throw W(`invalid literal for int() with base 10: '${n}'`);return parseInt(n,10)}function ln(n){if(n.all)return null;let e=n.limit;return typeof e=="number"&&e>0?e:rn}function Ln(n,e,t){let r=ln(e);return r!==null&&n.length>r?($(`showing the first ${r} ${t}; pass --limit n or --all for more`),n.slice(0,r)):n}function Pn(n,e,t){e&&$(`showing the first ${n} ${t}; pass --limit n or --all for more`)}async function Un(n){return n.client("devops")}function M(n){return n.service}function B(n){return n?{service:M(n),target:n.target}:null}function Jn(n,e,t){return T(n,e,B(t))}function Kn(n,e,t){return z(n,e,B(t))}function Dn(n,e){return F(n,B(e))}function V(n){let e=M(n).project;if(!e)throw new h("this command needs a DevOps environment with a project",{hint:"ask the user to set one: ppdo-cli env update <name> --devops-project <project>"});return R(e)}async function j(n,e,t,r,i={}){v(n,e,t,r,i.body??null,i.cls??null);let o=()=>e.request(t,r,{params:i.params??null,headers:i.headers??null,body:i.body??null,check:i.check??!0,saveTo:i.saveTo??null});try{return await o()}catch(s){let u=M(e);if(!(s instanceof E)||s.code!=="VssInvalidPreviewVersionException"||u.apiVersion.includes("-preview"))throw s;return u.apiVersion+="-preview",n.log(` preview-only endpoint; retrying with api-version=${u.apiVersion}`),o()}}async function cn(n,e,t,r=null,i={}){let o=(await j(n,e,"GET",t,{...i,params:r})).json();return w(o)?o:{}}function an(n){let e=n.json();return w(e)?e:{}}function Nn(n){return Buffer.from(fn(n),"utf8")}function fn(n){return L(n)}async function _n(n,e,t){return v(n,e,"PATCH","_apis",Buffer.from("{}")),e.lookups(t)}function pn(n){return k(n)?sn(n.value):Array.isArray(n)?n:[]}async function qn(n,e,t){let r=await cn(n,e,`${V(e)}/_apis/git/repositories/${R(t)}`);return String(r.id)}async function zn(n,e){let t=an(await j(n,e,"GET","_apis/connectionData",{params:[["api-version","7.1-preview"]]})),r=I(t.authenticatedUser);return{id:y(r.id),name:y(r.providerDisplayName)}}async function Fn(n,e,t){let r=e.service,i=e.target.env;e.service=new K({org:i.org,project:i.project},"vssps","7.1");try{let o=await j(n,e,"GET","_apis/identities",{params:[...t,["queryMembership","None"]]});return pn(o.json())}finally{e.service=r}}function Hn(n){if(!w(n))return null;let e=n;return y(A(e.uniqueName,e.displayName)??null)}function Wn(n){let e=y(n);return e&&e.startsWith("refs/heads/")?e.slice(11):e}function Vn(n){return n.startsWith("refs/")?n:`refs/heads/${n}`}function Gn(n){if(/^[A-Za-z]:[\\/]/.test(n))throw new h(`'${n}' looks like a Windows path (Git Bash rewrites arguments that start with /)`,{hint:"drop the leading /, or set MSYS_NO_PATHCONV=1"});return n}var dn=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),mn=new TextDecoder("utf-8",{fatal:!0});function gn(n){try{return dn.decode(n)}catch{return null}}function hn(n){try{return mn.decode(n)}catch{return null}}async function H(n,e,t,r){if(!w(r))return[];let i=await j(n,e,"GET",`${V(e)}/_apis/git/repositories/${t}/blobs/${b(r)}`,{params:[["$format","octetStream"]],headers:{Accept:"application/octet-stream"}}),o=gn(i.body);return o===null?[`<binary file>
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as b,b as k}from"./chunk-MTF66YXU.js";import{b as j,c as x}from"./chunk-GY6BUIDP.js";import{a as l,b as p,c as h,d as g,e as u,f as m,g as f}from"./chunk-J4R6QXW7.js";import{b as v,h as w}from"./chunk-WXOTXJNG.js";var A="499b84ac-1321-427f-aa17-267ca6975798",C="7.1";function y(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}var S=class extends j{name="devops";org;project;hostKey;apiVersion;constructor(e,n="core",t){super(),this.org=e.org??"",this.project=e.project??null,this.hostKey=n,this.apiVersion=t||C}scope(){return A+"/.default"}base(){return`https://${this.hostKey==="core"?"dev.azure.com":`${this.hostKey}.dev.azure.com`}/${l(this.org)}/`}expand(e){if(e.includes("{project}")){if(!this.project)throw new v("the path uses {project} but the environment has no DevOps project",{hint:"ask the user to set one: ppdo-cli env update <name> --devops-project <project>"});e=e.split("{project}").join(l(this.project))}return e}url(e,n){e=this.expand(e);let t=e.includes("://")?e:this.base()+e.replace(/^\/+/,""),r=u(t),i=[...g(r.query),...n??[]],s=f(t).host||r.netloc.toLowerCase();return!(r.path.includes("/_odata/")||s==="analytics.dev.azure.com")&&!i.some(([d])=>d.toLowerCase()==="api-version")&&i.push(["api-version",this.apiVersion]),m({...r,query:h(i,"$'(),/:@*"),fragment:""})}allowed(e){let n=f(e);if(n.scheme!=="https"||!n.host)return!1;let t=this.org.toLowerCase();if(!t)return!1;if(new Set(["dev.azure.com",...b.filter(s=>s!=="core").map(s=>`${s}.dev.azure.com`)]).has(n.host)){let s=(n.path.replace(/^\/+/,"").split("/",1)[0]??"").toLowerCase();if(s!==t&&s!==l(t).toLowerCase())return!1;let c=u(e).path.replace(/^\/+/,"").split("/");for(let d of c){let a=p(d);if(a==="."||a===".."||a.includes("/")||a.includes("\\"))return!1}return p(c[0]??"").toLowerCase()===t}return new Set([`${t}.visualstudio.com`,...k.map(s=>`${t}.${s}.visualstudio.com`)]).has(n.host)}requestId(e){return e.header("activityid")||e.header("x-vss-e2eid")}authTrap(e){let n=e.header("content-type")??"";return e.status===203||e.status>=200&&e.status<300&&n.includes("text/html")&&e.body.subarray(0,2e3).toString("latin1").toLowerCase().includes("<html")?"Azure DevOps returned a sign-in page instead of data (the token was rejected)":null}error(e){let n=null,t=null,r=null;if(e.body.length)try{let i=e.json(),s=y(i)?i:{};t=typeof s.message=="string"?s.message:null,n=typeof s.typeKey=="string"&&s.typeKey||(s.errorCode?String(s.errorCode):null)||null}catch{t=e.text.trim().slice(0,300)||null}if(t&&t.includes("TF401444"))r="a service principal must be added to the organization first: Organization settings > Users > Add users, with an access level and project permissions";else if(e.status===401||t&&t.includes("TF400813"))r="this account isn't a member of the organization, or the token is for another tenant";else if(e.status===404)r="404 also means 'no permission to see it' in Azure DevOps";else if(n==="WorkItemTrackingFieldDefinitionNotFoundException")r="use the field's reference name (e.g. Microsoft.VSTS.Common.Priority) or a System field name";else if(n==="GitPullRequestUpdateRejectedByPolicyException")r="a branch policy isn't passing yet (approvals, builds, linked work items): ppdo-cli ado pr checks <pr> shows which; get it passing, don't bypass it";else if(n==="TestPatchOperationFailedException")r="the work item changed after ppdo-cli read it; run the command again";else if(n==="VssInvalidPreviewVersionException")r="this endpoint is preview-only: pass --api-version <version>-preview";else if(t&&t.includes("VS403664")){let i=this.requestId(e);return new w(t,{service:this.name,status:e.status,...n?{code:n}:{},...i?{requestId:i}:{},hint:"only a comment's author can edit or delete it"})}return x(this.name,e,n,t,this.requestId(e),r)}};function O(o){let e=o.header("x-ms-continuationtoken");if(e){let t=u(o.url),r=g(t.query).filter(([i])=>i!=="continuationToken");return r.push(["continuationToken",e]),m({...t,query:h(r),fragment:""})}let n=o.isJson?o.json():null;return y(n)&&n["@odata.nextLink"]?String(n["@odata.nextLink"]):null}function T(o){let e=o.isJson?o.json():null;return y(e)&&Array.isArray(e.value)?e.value:Array.isArray(e)?e:e!=null?[e]:[]}export{A as a,C as b,S as c,O as d,T as e};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ var C=class extends Error{},I=class{tag;attrib;text=null;tail=null;children=[];constructor(t,r){this.tag=t,this.attrib=r??new Map}get(t,r=null){return this.attrib.has(t)?this.attrib.get(t):r}set(t,r){this.attrib.set(t,r)}[Symbol.iterator](){return this.children[Symbol.iterator]()}find(t){return this.findall(t)[0]??null}findall(t){let r=[this];for(let i of t.split("/")){let w=[];for(let l of r)for(let c of l.children)(i==="*"||c.tag===i)&&w.push(c);r=w}return r}*iter(t){(t===void 0||this.tag===t)&&(yield this);for(let r of this.children)yield*r.iter(t)}},S={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function W(f){return f===" "||f===" "||f===`
3
+ `||f==="\r"}function $(f){return f!==void 0&&(/[A-Za-z0-9_.:-]/.test(f)||f.charCodeAt(0)>=183)}function N(f){let t=f.replace(/\r\n?/g,`
4
+ `),r=t.length,i=(e,g)=>{let n=t.slice(0,Math.min(g,r)),d=n.split(`
5
+ `).length,o=g-(n.lastIndexOf(`
6
+ `)+1);throw new C(`${e}: line ${d}, column ${o}`)},w=(e,g,n)=>{let d="";for(let o=0;o<e.length;o++){let p=e[o];if(p==="&"){let m=e.indexOf(";",o+1);m<0&&i("not well-formed (invalid token)",g+o);let x=e.slice(o+1,m);if(x.startsWith("#")){let b=x[1]==="x"?parseInt(x.slice(2),16):parseInt(x.slice(1),10);Number.isFinite(b)||i("not well-formed (invalid token)",g+o),d+=String.fromCodePoint(b)}else x in S?d+=S[x]:i("undefined entity",g+o);o=m}else p==="<"&&n?i("not well-formed (invalid token)",g+o):n&&(p===" "||p===`
7
+ `)?d+=" ":d+=p}return d},l=[],c=[new Map],u=null,a=null,v=!1,M=e=>{e&&a!==null&&(v?a.tail=(a.tail??"")+e:a.text=(a.text??"")+e)},y=(e,g,n)=>{let d=e.indexOf(":");if(d>0){let p=g.get(e.slice(0,d));return p!==void 0?`{${p}}${e.slice(d+1)}`:e}if(n)return e;let o=g.get("");return o?`{${o}}${e}`:e},h=0;if(t.startsWith("<?xml")){let e=t.indexOf("?>");e<0&&i("unclosed token",0),h=e+2}for(;h<r;){let e=t.indexOf("<",h),g=e<0?r:e;if(g>h){let s=t.slice(h,g);l.length?M(w(s,h,!1)):s.trim()&&i(u?"junk after document element":"syntax error",h+s.search(/\S/))}if(e<0)break;if(!l.length&&u&&!t.startsWith("<!--",e)&&!t.startsWith("<?",e)&&i("junk after document element",e),t.startsWith("<!--",e)){let s=t.indexOf("-->",e+4);s<0&&i("unclosed token",e),h=s+3;continue}if(t.startsWith("<![CDATA[",e)){let s=t.indexOf("]]>",e+9);s<0&&i("unclosed CDATA section",e),l.length||i("syntax error",e),M(t.slice(e+9,s)),h=s+3;continue}if(t.startsWith("<?",e)){let s=t.indexOf("?>",e+2);s<0&&i("unclosed token",e),h=s+2;continue}if(t.startsWith("<!",e)&&i("not well-formed (invalid token)",e),t[e+1]==="/"){let s=e+2;for(;s<r&&$(t[s]);)s++;let k=t.slice(e+2,s);for(;s<r&&W(t[s]);)s++;s>=r&&i("unclosed token",e),t[s]!==">"&&i("not well-formed (invalid token)",s);let E=l[l.length-1];(!E||E.tag!==y(k,c[c.length-1],!1))&&i("mismatched tag",e+2),a=l.pop(),v=!0,c.pop(),h=s+1;continue}let n=e+1;for((!$(t[n])||/[0-9.\-]/.test(t[n]))&&i("not well-formed (invalid token)",n);n<r&&$(t[n]);)n++;let d=t.slice(e+1,n),o=[],p=!1;for(;;){let s=n;for(;n<r&&W(t[n]);)n++;if(n>=r&&i("unclosed token",e),t[n]===">"){n++;break}if(t[n]==="/"){t[n+1]!==">"&&i("not well-formed (invalid token)",n),p=!0,n+=2;break}(n===s||!$(t[n]))&&i("not well-formed (invalid token)",n);let k=n;for(;n<r&&$(t[n]);)n++;let E=t.slice(k,n);for(;n<r&&W(t[n]);)n++;for(t[n]!=="="&&i("not well-formed (invalid token)",n),n++;n<r&&W(t[n]);)n++;let A=t[n];A!=='"'&&A!=="'"&&i("not well-formed (invalid token)",n);let O=t.indexOf(A,n+1);O<0&&i("unclosed token",e),o.some(([D])=>D===E)&&i("duplicate attribute",k),o.push([E,w(t.slice(n+1,O),n+1,!0)]),n=O+1}let m=c[c.length-1];if(o.some(([s])=>s==="xmlns"||s.startsWith("xmlns:"))){m=new Map(m);for(let[s,k]of o)s==="xmlns"?m.set("",k):s.startsWith("xmlns:")&&m.set(s.slice(6),k)}let x=new Map;for(let[s,k]of o)s!=="xmlns"&&!s.startsWith("xmlns:")&&x.set(y(s,m,!0),k);let b=new I(y(d,m,!1),x);l.length?l[l.length-1].children.push(b):u===null?u=b:i("junk after document element",e),a=b,v=!1,p?v=!0:(l.push(b),c.push(m)),h=n}return(l.length||u===null)&&i("no element found",r),u}function j(f){return f.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function T(f){return f.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\r/g,"&#13;").replace(/\n/g,"&#10;").replace(/\t/g,"&#09;")}function z(f){let t=new Map,r=l=>{if(!l.startsWith("{"))return l;let c=l.indexOf("}"),u=l.slice(1,c),a=t.get(u);return a===void 0&&(a=`ns${t.size}`,t.set(u,a)),`${a}:${l.slice(c+1)}`};for(let l of f.iter()){r(l.tag);for(let c of l.attrib.keys())r(c)}let i=[],w=(l,c)=>{if(i.push("<"+r(l.tag)),c)for(let[u,a]of[...t].sort((v,M)=>v[1]<M[1]?-1:1))i.push(` xmlns:${a}="${T(u)}"`);for(let[u,a]of l.attrib)i.push(` ${r(u)}="${T(a)}"`);if(l.text||l.children.length){i.push(">"),l.text&&i.push(j(l.text));for(let u of l.children)w(u,!1);i.push(`</${r(l.tag)}>`)}else i.push(" />");l.tail&&!c&&i.push(j(l.tail))};return w(f,!0),i.join("")}export{C as a,N as b,z as c};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as F,b as N,c as H,j as M}from"./chunk-XUHLW6B2.js";import{a as K,b as _,e as O}from"./chunk-MBNUMAAZ.js";import{d as D}from"./chunk-LB7WNZVK.js";import{a as P,b as E,c as B}from"./chunk-WXOTXJNG.js";import{createHash as Z,createPrivateKey as ye}from"node:crypto";import{existsSync as ve,readFileSync as Q,statSync as xe}from"node:fs";import{createDecipheriv as ee,createHash as Y,createPrivateKey as X,pbkdf2Sync as te,X509Certificate as ne}from"node:crypto";var l=class extends Error{};function S(e,n){if(n+2>e.length)throw new l("truncated DER");let r=e[n];if((r&31)===31)throw new l("unsupported DER tag");let t=n+1,o=e[t++];if(o===128){let a=t;for(;;){if(t+2>e.length)throw new l("truncated BER");if(e[t]===0&&e[t+1]===0)return{tag:r,value:e.subarray(a,t),end:t+2};t=S(e,t).end}}let c=o;if(o&128){let a=o&127;if(a>4)throw new l("DER length too long");c=0;for(let f=0;f<a;f++)c=c*256+e[t++]}if(t+c>e.length)throw new l("truncated DER");return{tag:r,value:e.subarray(t,t+c),end:t+c}}function u(e){let n=[];for(let r=0;r<e.value.length;){let t=S(e.value,r);n.push(t),r=t.end}return n}function C(e){return S(e,0)}function d(e,n,r){let t=e[n];if(!t)throw new l(`missing ${r}`);return t}function y(e){if(e.tag===4)return e.value;if(e.tag===36)return Buffer.concat(u(e).map(y));throw new l("expected an OCTET STRING")}function b(e){if(e.tag!==160)throw new l("expected [0]");return d(u(e),0,"[0] content")}function x(e){if(e.tag!==6)throw new l("expected an OID");let n=e.value,r=[],t=0;for(let o=0;o<n.length;o++)t=t*128+(n[o]&127),n[o]&128||(r.length?r.push(t):r.push(t<80?Math.floor(t/40):2,t<80?t%40:t-80),t=0);return r.join(".")}function G(e){if(e.tag!==2)throw new l("expected an INTEGER");let n=0;for(let r of e.value)n=n*256+r;return n}var j="1.2.840.113549.1.7.1",re="1.2.840.113549.1.7.6",oe="1.2.840.113549.1.12.10.1.1",ce="1.2.840.113549.1.12.10.1.2",se="1.2.840.113549.1.12.10.1.3",ie="1.2.840.113549.1.9.22.1",ae="1.2.840.113549.1.9.21",fe="1.2.840.113549.1.5.13",le="1.2.840.113549.1.5.12",ue="1.2.840.113549.1.12.1.3",L="1.2.840.113549.1.12.1.4",pe="1.2.840.113549.1.12.1.5",de="1.2.840.113549.1.12.1.6",he={"1.2.840.113549.2.7":"sha1","1.2.840.113549.2.8":"sha224","1.2.840.113549.2.9":"sha256","1.2.840.113549.2.10":"sha384","1.2.840.113549.2.11":"sha512"},ge={"2.16.840.1.101.3.4.1.2":["aes-128-cbc",16],"2.16.840.1.101.3.4.1.22":["aes-192-cbc",24],"2.16.840.1.101.3.4.1.42":["aes-256-cbc",32],"1.2.840.113549.3.7":["des-ede3-cbc",24]};function W(e,n,r,t,o){let f=h=>{if(!h.length)return Buffer.alloc(0);let m=Buffer.alloc(64*Math.ceil(h.length/64));for(let p=0;p<m.length;p++)m[p]=h[p%h.length];return m},s=Buffer.alloc(64,r),i=Buffer.concat([f(n),f(e)]),g=[],w=0;for(;w<o;){let h=Y("sha1").update(s).update(i).digest();for(let p=1;p<t;p++)h=Y("sha1").update(h).digest();if(g.push(h),w+=20,w>=o)break;let m=Buffer.alloc(64);for(let p=0;p<64;p++)m[p]=h[p%20];for(let p=0;p<i.length;p+=64){let k=1;for(let v=63;v>=0;v--){let T=i[p+v]+m[v]+k;i[p+v]=T&255,k=T>>8}}}return Buffer.concat(g).subarray(0,o)}var we=[Buffer.from([0,0]),Buffer.alloc(0)];function J(e,n,r,t){let o=ee(e,n,r);return Buffer.concat([o.update(t),o.final()])}function q(e,n,r){let t=u(e),o=x(d(t,0,"algorithm")),c=t[1],a=[];if(o===fe&&c){let[s,i]=u(c);if(!s||!i)throw new l("bad PBES2 parameters");let g=u(s);if(x(d(g,0,"KDF"))!==le)throw new l("unsupported key derivation");let w=u(d(g,1,"PBKDF2 parameters")),h=y(d(w,0,"salt")),m=G(d(w,1,"iterations")),p="sha1";for(let A of w.slice(2))A.tag===48&&(p=he[x(d(u(A),0,"PRF"))]??"");if(!p)throw new l("unsupported PRF");let k=u(i),v=ge[x(d(k,0,"cipher"))];if(!v)throw new l("unsupported cipher");let T=y(d(k,1,"IV"));a.push(()=>J(v[0],te(Buffer.alloc(0),h,m,v[1],p),T,n))}else if((o===ue||o===L)&&c){let s=u(c),i=y(d(s,0,"salt")),g=G(d(s,1,"iterations"));for(let w of we)a.push(()=>{let h=W(w,i,1,g,24);return o===L&&(h=Buffer.concat([h.subarray(0,16),h.subarray(0,8)])),J("des-ede3-cbc",h,W(w,i,2,g,8),n)})}else throw o===de||o===pe?new l("it uses RC2 encryption, which Node cannot decrypt"):new l(`unsupported encryption ${o}`);let f;for(let s of a)try{let i=s();return r(i),i}catch(i){f=i}throw new l(`cannot decrypt it without a password (${f?.message??"no key"})`)}function I(e){let n=e[2];if(!n||n.tag!==49)return null;for(let r of u(n)){let[t,o]=u(r);if(t&&o&&x(t)===ae){let c=u(o)[0];if(c)return y(c).toString("hex")}}return null}function U(e,n){for(let r of u(C(e))){let t=u(r),o=x(d(t,0,"bag type")),c=b(d(t,1,"bag value"));if(o===oe)n.keys.push({der:me(c),id:I(t)});else if(o===ce){let[a,f]=u(c);if(!a||!f)throw new l("bad shrouded key bag");let s=q(a,y(f),i=>{X({key:i,format:"der",type:"pkcs8"})});n.keys.push({der:s,id:I(t)})}else if(o===se){let a=u(c);if(x(d(a,0,"certificate type"))!==ie)continue;n.certs.push({der:y(b(d(a,1,"certificate"))),id:I(t)})}}}function me(e){let n=e.value.length,r;if(n<128)r=[e.tag,n];else{let t=[];for(let o=n;o>0;o=Math.floor(o/256))t.unshift(o&255);r=[e.tag,128|t.length,...t]}return Buffer.concat([Buffer.from(r),e.value])}function V(e){let n=u(C(e)),r=u(d(n,1,"authSafe"));if(x(d(r,0,"content type"))!==j)throw new l("it is signed, not password-protected");let t={keys:[],certs:[]};for(let f of u(C(y(b(d(r,1,"content")))))){let s=u(f),i=x(d(s,0,"content type"));if(i===j)U(y(b(d(s,1,"content"))),t);else if(i===re){let g=u(b(d(s,1,"content"))),w=u(d(g,1,"encrypted content info")),h=d(w,1,"algorithm"),m=w[2];if(!m)continue;let p=m.tag===160?Buffer.concat(u(m).map(y)):m.value;U(q(h,p,k=>{u(C(k))}),t)}}let o=t.keys[0];if(!o)throw new l("it has no private key");if(!t.certs.length)throw new l("it has no certificate");let c=X({key:o.der,format:"der",type:"pkcs8"}),a=o.id&&t.certs.find(f=>f.id===o.id)||t.certs.find(f=>{try{return new ne(f.der).checkPrivateKey(c)}catch{return!1}})||t.certs[0];return{privateKey:c.export({type:"pkcs8",format:"pem"}).toString(),certificate:a.der}}var $=new Map,R=new Map,z={7000215:"the client secret is wrong: check {where}",7000222:"the client secret has expired: create a new one on the app registration and update {where}",700016:"no app with this client id in tenant '{tenant}': check --client-id and --tenant",90002:"tenant '{tenant}' was not found: check --tenant",700027:"the certificate is not registered on the app, or its key doesn't match"};function ke(e){return e.certificate?e.certificate:e.secretEnv||"the secret"}function Ee(e){let n=e.replace(/\$(\w+)|\$\{([^}]*)\}/g,(r,t,o)=>process.env[t??o]??r);if(process.platform==="win32"&&(n=n.replace(/%([^%]+)%/g,(r,t)=>process.env[t]??r)),n==="~"||n.startsWith("~/")||n.startsWith("~\\")){let r=process.env.USERPROFILE||process.env.HOME||"";r&&(n=r+n.slice(1))}return n}var Be=/-----BEGIN ([A-Z ]+)-----[\s\S]+?-----END \1-----/g;function be(e){e=Ee(e);let n=e.toLowerCase();if(n.endsWith(".pfx")||n.endsWith(".p12")){if(!ve(e)||!xe(e).isFile())throw new E(`cannot read certificate ${e}: no such file`);let s;try{s=V(Q(e))}catch(i){let g=i instanceof Error?i.message:String(i);throw new E(`cannot read certificate ${e}: ${g}`,{hint:i instanceof l?"export it again without a password, or convert it to PEM: openssl pkcs12 -in <pfx> -nodes -out <pem>":void 0})}return{privateKey:s.privateKey,thumbprint:Z("sha1").update(s.certificate).digest("hex")}}let r;try{let s=Q(e);if(s.some(i=>i>127))throw new Error("'ascii' codec can't decode the file");r=s.toString("ascii")}catch(s){let i=s,g=i.code==="ENOENT"?`[Errno 2] No such file or directory: '${e}'`:i.message;throw new E(`cannot read certificate ${e}: ${g}`)}let t=new Map;for(let s of r.matchAll(Be))t.set(s[1],s[0]);let o=t.get("CERTIFICATE"),c=[...t].find(([s])=>s.endsWith("PRIVATE KEY")&&!s.includes("ENCRYPTED"))?.[1];if(!o||!c){let s=c?"the certificate":"an unencrypted private key";throw new E(`${e} has no ${s}`,{hint:"the PEM file needs both the private key and the certificate"})}let a=Buffer.from(o.replace(/-----[A-Z ]+-----/g,"").replace(/\s+/g,""),"base64"),f;try{f=ye(c).export({type:"pkcs8",format:"pem"}).toString()}catch(s){throw new E(`cannot read certificate ${e}: ${s.message}`)}return{privateKey:f,thumbprint:Z("sha1").update(a).digest("hex")}}async function Te(e){let n=JSON.stringify([e.clientId,e.tenant,e.certificate]),r=e.ephemeral?R.get(n):void 0;if(r!==void 0)return r;let t;if(e.certificate)t=be(e.certificate);else{let o=process.env[e.secretEnv||""]||"";if(!o&&e.ephemeral&&process.stdin.isTTY&&process.stderr.isTTY&&(o=await D(`Client secret for app ${e.clientId}: `)),!o)throw new B(`no client secret for app ${e.clientId}`,{hint:`set ${e.secretEnv}, or pass --certificate <pem|pfx>`});t=o}return e.ephemeral&&R.set(n,t),t}function Ce(e,n){if(e instanceof P)throw e;let r=e instanceof F?e:N();if(r)throw new P(`cannot reach login.microsoftonline.com: ${r.message}`,{hint:"check the network and proxy (HTTPS_PROXY)"});let t=M(e);if(!t)throw e;if(!(e.name==="ServerError"||t.codes.length>0)){let f=(t.description.split(/\r?\n/)[0]??"").split(". ")[0];throw new B(`cannot sign in as app ${n.clientId}: ${f}`,{hint:"check --tenant, and --certificate if given"})}let c=t.codes.find(f=>f in z),a=(c!==void 0?z[c]:"check --client-id, --tenant and the secret or certificate").replace("{where}",ke(n)).replace("{tenant}",n.tenant);throw new B(`sign-in as app ${n.clientId} failed: ${t.description}`,{code:t.error,hint:a})}async function Pe(e,n){let r=await Te(e),t=await import("./dist-ILNYGTM2.js"),o;try{o=await new t.ConfidentialClientApplication({auth:{clientId:e.clientId??"",authority:`https://login.microsoftonline.com/${e.tenant}`,...typeof r=="string"?{clientSecret:r}:{clientCertificate:r}},system:{networkClient:new H}}).acquireTokenByClientCredential({scopes:[n]})}catch(a){Ce(a,e)}if(!o?.accessToken)throw new B(`sign-in as app ${e.clientId} failed: no token returned`,{hint:"check --client-id, --tenant and the secret or certificate"});let c=o.expiresOn?o.expiresOn.getTime()/1e3:Date.now()/1e3;return[o.accessToken,c]}async function He(e,n,r,t){let o=JSON.stringify([e.clientId,e.tenant,n]),c=$.get(o);if(c&&!r&&c[1]-Date.now()/1e3>120)return t(` token: process (${e.name})`),c[0];t(` token: client credentials (${e.name}${r?", forced":""})`);let[a,f]=await Pe(e,n);return Ie(e,_(a)),$.set(o,[a,f]),a}function Ie(e,n){O(e.name,null,K(e.tenant)?e.tenant:null,n);let r=n?.appid||n?.azp;if(typeof r=="string"&&r&&r.toLowerCase()!==(e.clientId??"").toLowerCase())throw new B(`the token is for app ${r}, expected ${e.clientId}`)}function Me(){$.clear(),R.clear()}export{Ee as a,be as b,Te as c,Pe as d,He as e,Ie as f,Me as g};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
2
+ import{a as j}from"./chunk-UCTMKA2J.js";import{b as $,d as C,f as P}from"./chunk-FOEBNCSD.js";import{b as A,e as x,i as S,y as B}from"./chunk-BALEFXOL.js";import{b as T,c as O}from"./chunk-2IUXH534.js";import{e as R}from"./chunk-S4KF5Z3S.js";import{b as m,g as k}from"./chunk-WXOTXJNG.js";var h=100,L=5e3,nn="OData.Community.Display.V1.FormattedValue",en="@OData.Community.Display.V1.FormattedValue";function w(n){return n==null||n===!1||n===0||n===""||Number.isNaN(n)?!1:Array.isArray(n)?n.length>0:n instanceof Map||n instanceof Set?n.size>0:typeof n=="object"?Object.keys(n).length>0:!0}function tn(n,e){return w(n)?n:e}function K(n,e){if(typeof n!="object"||n===null||Array.isArray(n))return null;let t=n[e];return t===void 0?null:t}function M(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&w(n)?n:{}}function E(n){return Array.isArray(n)?n:[]}function rn(n){let e={};for(let[t,r]of Object.entries(n))r!=null&&(e[t]=r);return e}function on(n){let e={};for(let[t,r]of Object.entries(n))r!=null&&r!==""&&(e[t]=r);return e}function I(n,e){if(Array.isArray(n)&&Array.isArray(e)){for(let s=0;s<Math.min(n.length,e.length);s++){let o=I(n[s],e[s]);if(o)return o}return n.length-e.length}if(typeof n=="string"&&typeof e=="string"){let s=[...n],o=[...e];for(let i=0;i<Math.min(s.length,o.length);i++){let u=s[i].codePointAt(0)-o[i].codePointAt(0);if(u)return u}return s.length-o.length}let t=Number(n),r=Number(e);return t<r?-1:t>r?1:0}function U(n,e,t=!1){let r=[...n];return r.sort((s,o)=>(t?-1:1)*I(e(s),e(o))),r}function sn(n){return[...new Set(n)]}function un(n){return n.addOption(new x("--limit <n>",`return at most n rows (default ${h})`).argParser(S)).option("--all","return every row (no cap)")}function ln(n){if(n.all)return null;let e=n.limit;return typeof e=="number"&&e>0?e:h}var N={sync:"CustomSync",async:"CustomAsync",all:"CustomSync,CustomAsync"};function z(n,e,t){let r=new x(n,e);return r.argParser(D(t)),r}function D(n){return e=>{if(!n.includes(e))throw new A(`invalid choice: '${e}' (choose from ${n.join(", ")})`);return e}}function an(n){return n.addOption(z("--bypass-plugins <sync|async|all>","skip custom synchronous and/or asynchronous logic (plugins, classic workflows; not cloud flows); needs a full-mode group",Object.keys(N))).option("--bypass-step <step-id>[,...]","skip only these plugin steps")}function cn(n,e=!1,t="request body: @file.json, - for stdin, or inline JSON"){return e?n.requiredOption("--body <@file|-|json>",t):n.option("--body <@file|-|json>",t)}function fn(n,e,t=!1,r=null){let s=r?{hint:`run: ppdo-cli ${r} --help`}:{},o=Object.keys(e).filter(i=>n[i]!==void 0&&n[i]!==!1&&n[i]!==null);if(o.length>1)throw new m(`argument ${e[o[1]]}: not allowed with argument ${e[o[0]]}`,s);if(t&&!o.length)throw new m(`one of the arguments ${Object.values(e).join(" ")} is required`,s)}function dn(n){return n.client("dataverse")}function pn(n,e,t,r,s={}){return T(n,e,t,r,s.body??null,s.cls??null),e.request(t,r,{params:s.params??null,headers:s.headers??null,body:s.body??null,saveTo:s.saveTo??null,check:s.check??!0})}function F(n){return M(n.json())}function yn(n){return Buffer.from(JSON.stringify(n),"utf8")}function gn(...n){let e=n.filter(t=>!!t);return e.length?{Prefer:e.join(", ")}:{}}async function*G(n,e,t=null,r=null){let{nextLink:s}=await import("./service-HASXLUGE.js"),o=await n.request("GET",e,{params:t,headers:r});for(;;){yield o;let i=s(o);if(!i)return;o=await n.request("GET",i,{headers:r})}}async function q(n,e,t,r=null,s=null,o=h,i="rows"){let u=[],c={},l=!1,f=o?Math.min(L,o+1):L,y={...s??{}},g=y.Prefer;(g??"").includes("maxpagesize")||(y.Prefer=[g,`odata.maxpagesize=${f}`].filter(a=>a).join(", "));for await(let a of G(e,t,r,y)){let d=F(a);if(!w(c)){c={};for(let[p,b]of Object.entries(d))p!=="value"&&(c[p]=b)}for(let p of E(d.value)){if(o!==null&&u.length>=o){l=!0;break}u.push(p)}if(l)break;if(o!==null&&u.length>=o){l="@odata.nextLink"in d;break}}return l&&R(`showing the first ${o} ${i}; pass --limit n or --all for more`),[u,c]}async function mn(n,e,t,r,s,o,i=null,u=h,c="rows",l=null){if(s===null)return(await q(n,e,t,o,i,u,c))[0];let f=[],y=o.find(([a])=>a==="$filter")?.[1]??null,g=o.filter(([a])=>a!=="$filter"&&a!=="$orderby");for(let a=0;a<s.length;a+=50){let d="("+s.slice(a,a+50).map(p=>`${r} eq ${p}`).join(" or ")+")";y&&(d+=` and (${y})`),f=f.concat((await q(n,e,t,[...g,["$filter",d]],i,null,c))[0])}return l&&(f=U(f,l)),u!==null&&f.length>u&&(R(`showing the first ${u} ${c}; pass --limit n or --all for more`),f=f.slice(0,u)),f}function wn(n){let e=n.header("odata-entityid")||"",t=/\(([0-9a-fA-F-]{36})\)\s*$/.exec(e);return t?t[1]:null}function hn(n){if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let e=M(n.UserLocalizedLabel);if(w(e.Label))return e.Label;for(let t of E(n.LocalizedLabels))if(w(K(t,"Label")))return t.Label}return null}function bn(n,e){let t=n.args,r={},s=t.bypassPlugins;typeof s=="string"&&s&&(r["MSCRM.BypassBusinessLogicExecution"]=N[s]);let o=t.bypassStep;if(typeof o=="string"&&o){let u=o.split(",").map(l=>P(l)).filter(l=>l),c=u.filter(l=>!$(l));if(c.length)throw new m(`--bypass-step takes plugin step ids, got '${c[0]}'`);r["MSCRM.BypassBusinessLogicExecutionStepIds"]=u.map(l=>C(l)).join(",")}let i=e.target;if(Object.keys(r).length&&i.mode!=="full")throw new k(`blocked: skipping plugins needs mode 'full'; mode is '${i.mode}'`,{service:"dataverse",hint:O(i)});return r}async function xn(n,e=!1){if(n==null){if(e)throw new m("--body is required");return null}let t=B(String(n));try{j(V(t.toString("utf8")))}catch(r){throw new m(`--body is not valid JSON: ${r.message}`,{hint:"pass a file with --body @file.json"})}return t}var J="\uFEFF";function V(n){return n.startsWith(J)?n.slice(1):n}function Rn(n){return typeof n=="string"?n:null}var H=1e3;async function*Tn(n,e,t,r,s){let o=await import("./batch-LKWCBKAB.js"),i=e.service.origin;for(let u=0;u<t.length;u+=H){let c=t.slice(u,u+H),[l,f,y]=o.build(c,i,r),g=Buffer.from(f,"utf8");T(n,e,"POST","$batch",g);let a={"Content-Type":`multipart/mixed; boundary=${l}`};s&&(a.Prefer="odata.continue-on-error");let d=await e.request("POST","$batch",{headers:a,body:g,check:!1});if(d.status>=400&&!(d.header("content-type")||"").includes("multipart"))throw e.service.error(d);let p=/boundary=([^\s;]+)/.exec(d.header("content-type")||""),b=p?o.parse(d.text,p[1]):[];yield[u,c,o.distribute(y,b,c.length)]}}export{L as a,nn as b,en as c,w as d,tn as e,K as f,M as g,E as h,rn as i,on as j,U as k,sn as l,un as m,ln as n,z as o,D as p,an as q,cn as r,fn as s,dn as t,pn as u,F as v,yn as w,gn as x,G as y,q as z,mn as A,wn as B,hn as C,bn as D,xn as E,V as F,Rn as G,Tn as H};
@@ -0,0 +1,6 @@
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-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
+ It will be sent to https://dev.azure.com/${e.organization}/ only, for: ${i}.
4
+ Use a PAT for this one organization, with the fewest scopes you need and a short expiry.
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
6
+ permissions only (readable by anything running as you). Type 'yes' to store it: `,"storing a PAT",n)!=="yes")throw new d("not stored",{hint:`or set an environment variable: ppdo-cli identity update ${e.name} --pat-env <VAR>`});let g={pat:p,source:"store",organization:e.organization??"",username:e.username??"",verified_user:P.user,verified_at:Math.trunc(Date.now()/1e3),expires:r,fingerprint:f},l=y(e.name);return await x(l,async()=>b(l,Buffer.from(JSON.stringify(g),"utf8"),{requireEncryption:!0})),{identity:e.name,status:"signed in",account:P.user,organization:e.organization,method:"pat",protection:u,...r?{expires:r}:{}}}function ue(e){let t={organization:e.organization,source:e.patEnv?`env:${e.patEnv}`:"store"};e.patEnv?t.present=!!process.env[e.patEnv]:t.protection=T();let n;try{n=w(e,!e.patEnv)}catch(i){return{...t,signed_in:!1,error:i.message,hint:a(e)}}let r=!!(n&&R(n,e)&&(e.patEnv?n.source==="env":n.source==="store")),o=!!(n?.expires&&Date.parse(n.expires+"T23:59:59Z")<Date.now());return{...t,signed_in:r&&!o&&(e.patEnv?t.present===!0:!0),account:r?n?.verified_user??null:null,verified_at:r?n?.verified_at??null:null,expires:r?n?.expires??null:null,...o?{expired:!0}:{}}}function le(e){return`https://dev.azure.com/${e.organization}/_usersSettings/tokens`}var H=class{constructor(t,n){this.ident=t;this.rt=n;this.hint=z(t)}hint;resolved=null;extraHeaders(){return U}async check(t){I(this.ident,t)}async header(t,n){return I(this.ident,n),(t||this.resolved===null)&&(this.resolved=await this.load()),j(this.resolved.value)}async load(){let t=G(this.ident);if(W(this.ident,t.record),t.record)return t;let n=await L(this.ident,t.value,this.rt),r={source:"env",organization:this.ident.organization??"",username:this.ident.username??"",verified_user:n.user,verified_at:Math.trunc(Date.now()/1e3),expires:null,fingerprint:v(t.value)},o=y(this.ident.name);return await x(o,async()=>b(o,Buffer.from(JSON.stringify(r),"utf8"))),{...t,record:r}}};export{z as a,V as b,G as c,ce as d,ue as e,le as f,H as g};
@@ -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-JN3I5EII.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-B6V4VVX5.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};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
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
+ `+i.map(r=>` - ${r}
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};
@@ -0,0 +1,2 @@
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-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{e as y}from"./chunk-S4KF5Z3S.js";import{a}from"./chunk-WXOTXJNG.js";import{createRequire as $}from"node:module";import{chmodSync as I,closeSync as m,fsyncSync as M,linkSync as U,mkdirSync as N,openSync as v,readFileSync as f,renameSync as D,statSync as J,unlinkSync as u,writeSync as T}from"node:fs";import{hostname as _}from"node:os";import{basename as q,dirname as g,join as O}from"node:path";var w=Buffer.from("PPD1","ascii"),C=Buffer.from("PPP1","ascii"),x=Buffer.from("ppdo-cli token cache","ascii"),B="CurrentUser",d="run: ppdo-cli auth login <identity>",s,p="",E=!1;function P(){if(s!==void 0)return s;if(process.platform!=="win32")return p="DPAPI is Windows only",s=null;try{let n=$(import.meta.url),e=n.resolve("@azure/msal-node-extensions/package.json"),t=n(O(g(e),"bin",process.arch,"dpapi.node"));if(typeof t.protectData!="function"||typeof t.unprotectData!="function")throw new Error("dpapi.node has no protectData/unprotectData");s=t}catch(n){p=n instanceof Error?n.message.split(`
3
+ `)[0]??n.message:String(n),s=null}return s}function ot(n){s=n,E=!1}function L(n,e,t){try{let r=e?t.protectData(n,x,B):t.unprotectData(n,x,B);return Buffer.from(r.buffer,r.byteOffset,r.byteLength)}catch(r){let o=r instanceof Error?r.message:String(r);throw new a(`DPAPI ${e?"encrypt":"decrypt"} failed (${o})`,{hint:`the cache may belong to another user or machine; ${d}`})}}function it(){return process.platform!=="win32"?"file-permissions":P()?"dpapi":"none"}function R(n,e={}){if(process.platform==="win32"){let t=P();if(t)return Buffer.concat([w,L(n,!0,t)]);if(e.requireEncryption)throw new a(`refusing to store it unencrypted: DPAPI is not available (${p})`,{hint:"install the optional dependency @azure/msal-node-extensions, or name an environment variable instead"});E||(E=!0,y(`token caches are stored unencrypted: DPAPI is not available (${p}); install the optional dependency @azure/msal-node-extensions to encrypt them`))}return Buffer.concat([C,n])}function z(n,e={}){let t=Buffer.from(n.buffer,n.byteOffset,n.byteLength);if(e.requireEncryption&&process.platform==="win32"&&!t.subarray(0,4).equals(w))throw new a("refusing a stored secret that is not encrypted",{hint:`delete it and ${d}`});if(t.subarray(0,4).equals(w)){let r=P();if(!r)throw new a(`cannot decrypt the cache: DPAPI is not available (${p})`,{hint:`install @azure/msal-node-extensions, or ${d}`});return L(t.subarray(4),!1,r)}if(t.subarray(0,4).equals(C))return Buffer.from(t.subarray(4));throw new a("unrecognised cache file format",{hint:`delete it and ${d}`})}function at(n,e={}){let t;try{t=f(n)}catch(r){if(r.code==="ENOENT")return null;throw r}return z(t,e)}function st(n,e,t={}){G(n,R(e,t))}var F=new Int32Array(new SharedArrayBuffer(4));function k(n){Atomics.wait(F,0,0,n)}function S(){return`${process.pid}.${Date.now().toString(36)}.${Math.random().toString(36).slice(2,10)}`}function l(n){let e=n.code;return e==="EPERM"||e==="EACCES"||e==="EBUSY"}function G(n,e){let t=g(n);N(t,{recursive:!0});let r=typeof e=="string"?Buffer.from(e,"utf8"):e,o=O(t,`${q(n)}.${S()}.tmp`),c=v(o,"wx",384);try{try{let i=0;for(;i<r.byteLength;)i+=T(c,r,i,r.byteLength-i);M(c)}finally{m(c)}process.platform!=="win32"&&I(o,384);for(let i=0;;i++)try{D(o,n);break}catch(b){if(!l(b)||i===39)throw b;k(25)}}catch(i){try{u(o)}catch{}throw i}}var X=600*1e3,j=5,H=50,W=1e3,Y;function A(){return Y??=process.platform==="win32"&&process.env.COMPUTERNAME||_()}function K(n){try{let e=JSON.parse(n);return typeof e.pid=="number"&&typeof e.host=="string"?e:null}catch{return null}}function Q(n){try{return process.kill(n,0),!0}catch(e){return e.code==="EPERM"}}var h=class{lockPath;token=S();deadline;wait=j;lastStaleCheck=-1/0;constructor(e,t){this.lockPath=e+".lock",this.deadline=performance.now()+t*1e3,N(g(this.lockPath),{recursive:!0})}poll(){if(this.tryCreate())return 0;let e=performance.now();if(e-this.lastStaleCheck>=W){this.lastStaleCheck=e;let r=this.staleContent();if(r!==null&&(this.breakStale(r),this.tryCreate()))return 0}if(e>this.deadline)throw new a(`timed out waiting for lock ${this.lockPath}`,{hint:"another ppdo-cli process is busy; retry"});let t=this.wait;return this.wait=Math.min(this.wait*2,H),t}tryCreate(){let e;try{e=v(this.lockPath,"wx",384)}catch(t){if(t.code==="EEXIST"||l(t))return!1;throw t}try{let t={pid:process.pid,host:A(),token:this.token};T(e,JSON.stringify(t))}catch(t){throw m(e),u(this.lockPath),t}return m(e),!0}staleContent(){let e,t;try{t=J(this.lockPath).mtimeMs,e=f(this.lockPath,"utf8")}catch(o){if(o.code==="ENOENT"||l(o))return null;throw o}let r=K(e);return r&&r.host===A()&&r.pid!==process.pid&&!Q(r.pid)||Date.now()-t>X?e:null}breakStale(e){let t=`${this.lockPath}.${S()}.stale`;try{D(this.lockPath,t)}catch(o){if(o.code==="ENOENT"||l(o))return;throw o}let r="";try{r=f(t,"utf8")}catch(o){if(o.code!=="ENOENT")throw o}try{if(r!==e)try{U(t,this.lockPath)}catch(o){if(o.code!=="EEXIST")throw o}}finally{u(t)}}release(){for(let e=0;;e++)try{if(!f(this.lockPath,"utf8").includes(this.token))return;u(this.lockPath);return}catch(t){if(t.code==="ENOENT")return;if(!l(t)||e===39){y(`could not remove lock ${this.lockPath}: ${t.message}`);return}k(25)}}};function ct(n,e,t=30){let r=new h(n,t);for(let o=r.poll();o>0;o=r.poll())k(o);try{return e()}finally{r.release()}}async function lt(n,e,t=30){let r=new h(n,t);for(let o=r.poll();o>0;o=r.poll())await new Promise(c=>setTimeout(c,o));try{return await e()}finally{r.release()}}export{P as a,ot as b,it as c,R as d,z as e,at as f,st as g,k as h,G as i,X as j,A as k,ct as l,lt as m};
@@ -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};